mirror of
https://github.com/GabrielVidal1/ask-form-orca.git
synced 2026-12-01 20:57:27 +01:00
A trusted-worker Orca plugin for ask-form. The worker polls the local `ask-form serve` admin API (loopback only, the machine's admin token) and reads agents' ask-form calls through the agent.tool.after hook: a form's link only exists in `ask-form create`'s output, and the hook also says which workspace and terminal asked. The HTML panel lists the waiting forms (the focused workspace's first) with Open, a QR code for the phone, Go to agent and Revoke, and the recently closed ones with their answers; it installs or restarts ask-form in a terminal when it is missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
5.8 KiB
JavaScript
106 lines
5.8 KiB
JavaScript
#!/usr/bin/env node
|
|
// Dev only: builds a browser preview of the Forms panel into .orca/preview/ (ignored by Git and by
|
|
// Orca), with Orca's default light and dark tokens and a stand-in `window.orca` that answers from
|
|
// fixtures. Serve the folder and open index.html?s=forms&theme=dark (s: forms, empty, missing,
|
|
// stopped). Orca itself needs none of this: it transpiles src/ as it is.
|
|
import { execFileSync } from 'node:child_process'
|
|
import { copyFileSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
const out = join(root, '.orca', 'preview')
|
|
mkdirSync(out, { recursive: true })
|
|
execFileSync(
|
|
'npx',
|
|
['-y', 'esbuild@0.24.0', 'src/panel/panel.ts', '--bundle', '--format=esm', `--outfile=${join(out, 'panel.js')}`],
|
|
{ cwd: root, stdio: 'inherit' }
|
|
)
|
|
copyFileSync(join(root, 'src/panel/panel.css'), join(out, 'panel.css'))
|
|
|
|
// Orca's default theme (src/renderer/src/assets/main.css), as frames receive it.
|
|
const tokens = {
|
|
light: {
|
|
background: '#fff', foreground: '#0a0a0a', card: '#fff', 'card-foreground': '#0a0a0a',
|
|
primary: '#171717', 'primary-foreground': '#fafafa', secondary: '#f5f5f5', 'secondary-foreground': '#171717',
|
|
muted: '#f5f5f5', 'muted-foreground': '#696969', accent: '#f5f5f5', 'accent-foreground': '#171717',
|
|
destructive: '#e40014', border: '#e5e5e5', input: '#e5e5e5', ring: '#a1a1a1', radius: '0.625rem'
|
|
},
|
|
dark: {
|
|
background: '#0a0a0a', foreground: '#f0f0f0', card: '#171717', 'card-foreground': '#f0f0f0',
|
|
primary: '#e5e5e5', 'primary-foreground': '#171717', secondary: '#262626', 'secondary-foreground': '#f0f0f0',
|
|
muted: '#262626', 'muted-foreground': '#acacac', accent: '#404040', 'accent-foreground': '#f0f0f0',
|
|
destructive: '#ff6568', border: 'rgb(255 255 255 / 0.07)', input: 'rgb(255 255 255 / 0.15)', ring: '#737373',
|
|
radius: '0.625rem'
|
|
}
|
|
}
|
|
|
|
const mock = `
|
|
const params = new URLSearchParams(location.search)
|
|
const theme = params.get('theme') === 'dark' ? 'dark' : 'light'
|
|
const TOKENS = ${JSON.stringify(tokens)}
|
|
document.documentElement.classList.add(theme)
|
|
for (const [name, value] of Object.entries(TOKENS[theme])) document.documentElement.style.setProperty('--orca-' + name, value)
|
|
const now = Date.now()
|
|
const min = 60_000
|
|
const health = { state: 'ok', version: 'v0.19.1', relay: 'connected' }
|
|
const forms = [
|
|
{ id: 'project-setup_k3f9q2', title: 'Project setup', description: 'Pick the stack, the deploy target and whether to add auth now.', status: 'pending', createdAt: now - 3 * min, expiresAt: now + 23 * 60 * min,
|
|
origin: { here: true, canFocus: true, workspace: 'login-page', branch: 'feat/login', agent: 'claude' },
|
|
url: 'http://127.0.0.1:7462/f/project-setup_k3f9q2?token=AbC123xyz', phoneUrl: 'https://ask-form.xyz/f/project-setup_k3f9q2?token=AbC123xyzAbC123xyzAbC1' },
|
|
{ id: 'data-model_8hd72k', title: 'Data model review', description: 'Two ways to store the invoices: compare the mockups.', status: 'pending', createdAt: now - 26 * min, expiresAt: now + 5 * 60 * min,
|
|
origin: { here: false, canFocus: true, workspace: 'billing', branch: 'billing-v2', agent: 'codex' },
|
|
url: 'https://ask-form.xyz/f/data-model_8hd72k?token=Zz9', phoneUrl: 'https://ask-form.xyz/f/data-model_8hd72k?token=Zz9' },
|
|
{ id: 'team-lunch_p0q1w2', title: 'Team lunch on Friday', status: 'pending', multi: true, answerCount: 4, createdAt: now - 2 * 60 * min, expiresAt: now + 30 * 60 * min },
|
|
{ id: 'babybot-times_bcvp86', title: 'Babybot: time options in the modal', status: 'submitted', createdAt: now - 70 * min, closedAt: now - 64 * min, expiresAt: 0,
|
|
origin: { here: false, canFocus: true, workspace: 'babybot', agent: 'claude' },
|
|
answers: [ { label: 'Steps', value: 'Every quarter hour' }, { label: 'First option', value: 'Now' }, { label: 'After closing', value: 'Reply in the thread' } ] },
|
|
{ id: 'api-keys_2kd9s0', title: 'API keys for the staging deploy', status: 'declined', createdAt: now - 5 * 60 * min, closedAt: now - 4 * 60 * min, expiresAt: 0,
|
|
reason: 'Use the ones already in 1Password, no new keys.' },
|
|
{ id: 'refactor-plan_ll2k3j', title: 'Refactor plan', status: 'expired', createdAt: now - 30 * 60 * min, closedAt: now - 6 * 60 * min, expiresAt: 0 }
|
|
]
|
|
const scenarios = {
|
|
forms: { health, forms, hiddenOutside: 0, updatedAt: now },
|
|
empty: { health: { ...health, relay: 'disconnected' }, forms: forms.slice(3), hiddenOutside: 2, updatedAt: now },
|
|
missing: { health: { state: 'missing' }, forms: [], hiddenOutside: 0, updatedAt: now },
|
|
stopped: { health: { state: 'stopped' }, forms: [], hiddenOutside: 0, updatedAt: now }
|
|
}
|
|
const state = scenarios[params.get('s') || 'forms'] || scenarios.forms
|
|
window.orca = {
|
|
locale: 'en',
|
|
api: { major: 1, minor: 10 },
|
|
plugin: {
|
|
async request(name) {
|
|
if (name === 'state.get' || name === 'state.refresh') return state
|
|
if (name === 'form.focusAgent') return { focused: true }
|
|
if (name === 'form.revoke') return { ok: true }
|
|
if (name === 'setup.run') return { started: false, command: 'curl -fsSL https://ask-form.xyz/install.sh | sh', message: 'Open a workspace first, or run this in any terminal:' }
|
|
throw Object.assign(new Error('unknown_method'), { code: 'unknown_method' })
|
|
},
|
|
on() { return { dispose() {} } }
|
|
},
|
|
shell: { async openExternal() { return { opened: true } } },
|
|
on() { return { dispose() {} } }
|
|
}
|
|
`
|
|
|
|
writeFileSync(
|
|
join(out, 'index.html'),
|
|
`<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Forms (preview)</title>
|
|
<link rel="stylesheet" href="panel.css" />
|
|
<script>${mock}</script>
|
|
</head>
|
|
<body>
|
|
<main id="root" aria-live="polite"></main>
|
|
<script type="module" src="panel.js"></script>
|
|
</body>
|
|
</html>
|
|
`
|
|
)
|
|
console.log(`preview: ${join(out, 'index.html')}`)
|