Files
gabrielvidalandClaude Opus 5.5 d880ab257f feat(form): YAML form files — sections keyed by title, fields by key, options by value
`ask-form create form.yaml` takes the whole form in one file: title,
description, lang and sections (each a page, keyed by its title), with
fields keyed by their key, options by their value and a table's columns by
their key, in the order written. A section takes an intro (markdown under
its title) and a showIf for the whole page. Plain lists of option texts and
the old lists (`key:` fields, `value:` options) are read too, and the flat
JSON field array still works byte for byte (--fields-file spec.json).

- internal/form/yaml.go: a strict YAML 1.2 subset reader, stdlib only.
  Ordered mappings (*form.Map), block and flow collections, | and >
  scalars, quotes, comments; refuses anchors, tags, ? keys, several
  documents, tab indentation and duplicate keys, with the line. Only
  true/false are booleans; a number keeps its text (json.Number).
- internal/form/doc.go: ParseDoc compiles a form file (YAML, or JSON of the
  same shape) into the flat field array: section title -> group, intro ->
  a markdown block, section showIf AND-ed into its fields'. The CLI does it
  before POST /v1/forms, so server, relay, store and MCP are unchanged and
  a new CLI works with an older serve.
- examples: spec.yaml + spec.fr.yaml replace the JSON specs (converted,
  each checked to normalise to the same fields); /spec.json still answers
  with the form compiled to JSON.
- SKILL.md, the claude.ai sandbox skill, agent-install, README and
  CLAUDE.md teach the YAML form file; a test keeps SKILL.md's YAML valid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:52:10 +01:00

13 KiB

CLAUDE.md — ask-form

Web forms for agents: an agent creates a form, the user answers it in a browser from anywhere (https://ask-form.xyz/f/<name>_<hash>?token=…), the agent reads the answers as JSON. One Go binary (ask-form: serve, setup, upgrade and the client commands) and a relay (ask-form-relay). Stdlib only, Go 1.22+.

How an agent uses it: skill/SKILL.md (installed as the Claude Code skill by ask-form setup; ask-form skill print --body for other agents). How it works and why it's safe: docs/how-it-works.md. Running a relay of one's own: docs/self-hosting.md; its flag table and the proxy limits (poll hold, body sizes) must follow cmd/ask-form-relay and internal/relay when those change.

Layout

  • cmd/ask-form: CLI, serve, setup/uninstall (service units, skill), upgrade and the auto-upgrade loop, start (start.go: serve for one session — Claude's code sandbox — registered with a key, detached, no local listener, no self-upgrade) and skill export --claude-ai. cmd/ask-form-relay: the relay (machine and key commands).
  • internal/form (spec, answers, markdown; the form file: doc.go reads YAML or JSON into the flat field array, yaml.go is the YAML subset reader), internal/store (files), internal/server (answer pages under /f/, admin API, security), internal/tunnel (relay ⇄ machine long-poll), internal/relay (public side, machine API, open registration in registry.go, registration keys and the ephemeral machines they register in keys.go, with the landing's POST /claude-ai/skill), internal/update (releases: latest tag, download, checksum, atomic swap), internal/webhook (serve --events-url: every form event POSTed to one URL — the ai-agent hub's feed; Server.Events, AnnounceExpiries), internal/brand (the machine's look, ask-form brand: <config>/brand.json, re-read when it changes; Server.Brand; brand preview serves the examples with it via server.PreviewHandler). internal/server/snapshot.go: the page kept of each form that closes (<data>/snapshots/<id>.html, store/snapshots.go), written at close and by SnapshotSweep, read at GET /v1/forms/{id}/snapshot. internal/server/answers.go: the respondent's GET /f/{id}/answers (the closed page's "View the full form"), the same read-only page drawn live.
  • Chat apps (docs/how-it-works.md → "In chat apps"): internal/mcp (the MCP server at /mcp: JSON-RPC over Streamable HTTP, stateless; the tools and their field reference; card.html, the MCP App card), internal/accounts (OAuth 2.1 with anonymous accounts, the consent page, link codes), internal/hosted (the mcp.Backend: an account's calls to the relay's cloud forms or through the tunnel to its linked machine; the end-to-end test), internal/server/account_api.go (/_mcp/v1/: one account's forms; the cloud policy and retention), internal/server/link.go (ask-form link), internal/relay/hosted.go (cloud forms' routing, CallMachine, /_relay/v1/link), cmd/ask-form-relay/hosted.go (--hosted wiring).
  • Usage counts (docs/how-it-works.md → "Usage counts"): internal/stats (counters per day, per-account summaries under a hash, the summary, the Prometheus text), fed by internal/mcp (tools, form shapes and outcomes), internal/accounts (Config.SignedIn), the cloud server's events (cloudEvents in cmd/ask-form-relay/hosted.go) and internal/relay/stats.go (page/download hits, the owner's /_relay/v1/stats and /metrics). Never a form's text, id, answers or an address: a new counter keeps to labels from a fixed set (stats.Key cleans them; App buckets client names). plugins/ask-form/ is the Claude + ChatGPT plugin (one folder, both manifests; bump both versions on a release), listed by .claude-plugin/marketplace.json and zipped by skill.PluginZip. A tool's name, arguments and the card's messages are a contract with chat apps and the plugin's skill: change them together.
  • web/ (templates, CSS, JS, embedded), landing/ (the relay's / and /agent-install; {{ORIGIN}} and {{HOST}} are filled in by the relay), install.sh (root, embedded via assets.go, served at /install.sh), skill/, examples/ (demo forms served at /examples). skill/claude-ai.md: the skill for Claude's code sandbox (a template: relay, host, key, version; zipped by skill.ClaudeAIZip with reference.md = the main skill's body). npm/ + scripts/npm-packages.sh/npm-publish.sh: the npm packages (ask-form launcher + ask-form-<os>-<arch>), published by release.yml (trusted publishing, else NPM_TOKEN); the first publish of a new package is by hand (npm login && scripts/npm-publish.sh vX.Y.Z --trust).

Working on it

  • make test (vet + tests), make build, make install (→ ~/go/bin), make dist (every release binary + checksums.txt into dist/).
  • CI (.github/workflows/ci.yml): gofmt, vet, go test -race, make dist. Releasing: push a vX.Y.Z tag; release.yml builds, attests and publishes the GitHub release that install.sh, ask-form upgrade and the auto-upgrade read. Asset names (ask-form-<os>-<arch>, checksums.txt) are a contract with already-installed binaries: don't rename them.
  • The answer page must work with JavaScript off; web/static/app.js only adds. Strict CSP: no inline script or style (per-page CSS goes in the nonce'd <style>), no third-party assets. Never log a query string.
  • Pages are Referrer-Policy: no-referrer, so a browser's plain form submit arrives with Origin: null, same-origin included. The POST guard is fromThisPage (internal/server/security.go): null passes when Sec-Fetch-Site: same-origin vouches for it. Refusing every null broke every Send in v0.20.0 (fixed in v0.20.1, origin_test.go).
  • A brand reaches only the pages the machine renders (its CSS in the nonce'd <style>, before PageCSS; its logo/name via the brand template; frames get Brand.FrameCSS(), the tokens only). Its header layout travels in the brand CSS, not app.css: the relay serves app.css and may be older. Every page struct rendered with head needs a Brand pageBrand field.
  • html blocks and mockups stay script-free (frame CSP with one pinned hash). A widget field's frame is the single exception (internal/server/widget.go: script-src 'unsafe-inline', still no network); don't widen it, and keep widget.js accepting messages only from the field's own iframe.
  • A frame follows the page's scheme, not the OS's: app.js tells each frame the colour behind it (ask-form:backdrop {color, scheme}), the frame takes that side's tokens (frameSchemeCSS: theme + brand, data-af-scheme), keeps the page's color-scheme (a mismatch makes Chromium paint the frame's canvas opaque) and, on a dark backdrop, puts a mockup whose text it can't read on a light sheet (data-af-paper). Check a change against the corpus of past mockups (~/.local/share/ask-form/forms/*.json) in dark mode.
  • /forms/ is the old prefix: it must keep answering (links already sent).
  • Embedding (serve --embed-origins, Config.EmbedOrigins, docs/how-it-works.md → "In another app's frame"): a form's own pages go through s.render (frame-ancestors opened to the origins, no X-Frame-Options, <html data-embed> on a Sec-Fetch-Dest: iframe load), their cookies through s.setCookie (partitioned in a frame) and frames' CSP through s.ancestors. Examples and the not-found page stay unframeable (renderPage). The ask-form:page / ask-form:theme messages are a contract with embedders (the ai-agent hub): extend, don't rename.
  • A snapshot is the field template again with .Snap set (the snapshot page in pages.html, built by readOnlyPage): secrets a length, files a list, and with .Inline too frames get srcdoc instead of src, pictures data: URIs. A new field type needs its snapshot look too (and answerValues, which turns an answer back into input values), or it shows empty there. The stored page inlines app.css as this binary has it and runs no app.js: it must read right without it. The live answers page (no .Inline) loads the relay's app.css and app.js like the closed page, its own CSS (answersCSS) in the nonce'd <style>.
  • "Other…" on a select or radio is a checkbox of its own sharing the field's input name (f.<key>=__other__ next to the option), so it can be ticked with an option: the answer stays the option and the text goes under <key>.other (form.OtherKey). app.js still handles an older machine's page, where it was one more radio (or a dropdown entry) replacing the option; a second tap or Space on the picked radio clears it.
  • Print (@media print at the end of app.css, beforeprint/afterprint in app.js): what only paper shows (.print-options, .print-scale, .print-if, …) is markup with the hidden attribute that the print CSS reveals, so an older app.css never shows it; a print rule that hides a screen control guards on that markup (:has(.print-scale)) so an older machine's page keeps the control. The phone stepper keeps the other pages laid out out of sight (not display: none): their frames measure at their real width, and lazy pictures and mockups load once the page settles, so a print has them. Check a change with Playwright's page.pdf() (it fires beforeprint) from a 390 px and a 1280 px viewport.
  • Languages (internal/i18n): what a respondent reads is English (the catalogue keys) or French (fr.go); a form's lang is fixed at create (create --lang, else serve's --lang/ASK_FORM_LANG, else en) and the parts it gets by itself ("Anything else?", "Option 2") are written in it. Templates say {{t "…"}} / {{tn n "one" "other"}}; Go i18n.T(lang, …); the page scripts tr("…", {n: …}), reading the machine's catalogue from <html data-l10n> (the relay serves the scripts but never the translations: a machine's language doesn't wait on a relay). A new string needs its French entry: TestCatalogueComplete fails otherwise, and a script string also goes in jsKeys. Another language = one file like fr.go (catalogue, plural rule, date) plus examples/*/spec.<lang>.yaml. The relay serves /fr/examples from spec.fr.yaml; the not-found page stays English (same bytes for every unknown link).
  • examples/<name>/spec.yaml (+ images): adding one = a new folder plus a relay rebuild; internal/server/examples_test.go checks each renders. Its French twin spec.fr.yaml keeps every key (display blocks' names included), type, option value and condition; only the text a person reads changes (section titles too: they are text, not keys of the answers). /spec.json still answers for each, with the form compiled to JSON.
  • A form file (form.ParseDoc: YAML, or JSON of the same shape, or the old flat JSON array) is compiled to the flat field array in the CLI, before POST /v1/forms: sections become each field's group, a section's intro a markdown block, its showIf AND-ed into its fields'. The server, the relay, stored forms and MCP never see YAML, so a new CLI works with an older serve. The YAML reader is a strict subset of YAML 1.2 (stdlib only): mappings keep their order (*form.Map: sections, fields, options and columns appear as written), only true/false are booleans, a number keeps its text (json.Number) and turns back into text wherever the spec takes one (textKeys in doc.go: a new text key goes there); errors carry the line. MCP's create_form still takes the JSON array.
  • The landing page is a React + Vite app in landing/app/ (GSAP, lucide, @gabvdl/ui from public npm for PhonePreview/ProgressiveText). Its build in landing/dist/ is committed, so the relay and CI build with Go alone: after editing app/, run npm ci && npm run build there and commit dist/ with it. The build prerenders the page (it reads without JS) and the relay serves dist/assets/* at /assets/ under a script-src 'self' CSP. The demo's examples (app/src/examples/data.tsx) mirror examples/. It exists in English (/) and French (/fr, landing.PageFR): every word is in app/src/copy/{en,fr}.tsx and examples/data{,.fr}.tsx (the French one mirrors spec.fr.yaml), so a copy change touches both. The build prerenders dist/index.html and dist/fr/index.html (shared /assets/); the relay gives each page the CSP of its own inline blocks.
  • ASK_FORM_BENCH=1 go test -run TestTunnelLatency -v ./internal/relay prints the tunnel latency CSV.
  • Testing upgrades without GitHub: ASK_FORM_UPDATE_URL points the updater and install.sh at any server laid out like a GitHub repo's releases.