mirror of
https://github.com/GabrielVidal1/ask-form.git
synced 2026-12-01 10:07:27 +01:00
`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>
13 KiB
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),upgradeand 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) andskill export --claude-ai.cmd/ask-form-relay: the relay (machineandkeycommands).internal/form(spec, answers, markdown; the form file:doc.goreads YAML or JSON into the flat field array,yaml.gois 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 inregistry.go, registration keys and the ephemeral machines they register inkeys.go, with the landing'sPOST /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 previewserves the examples with it viaserver.PreviewHandler).internal/server/snapshot.go: the page kept of each form that closes (<data>/snapshots/<id>.html,store/snapshots.go), written at close and bySnapshotSweep, read atGET /v1/forms/{id}/snapshot.internal/server/answers.go: the respondent'sGET /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(--hostedwiring). - 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 byinternal/mcp(tools, form shapes and outcomes),internal/accounts(Config.SignedIn), the cloud server's events (cloudEventsincmd/ask-form-relay/hosted.go) andinternal/relay/stats.go(page/download hits, the owner's/_relay/v1/statsand/metrics). Never a form's text, id, answers or an address: a new counter keeps to labels from a fixed set (stats.Keycleans them;Appbuckets 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.jsonand zipped byskill.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 viaassets.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 byskill.ClaudeAIZipwithreference.md= the main skill's body).npm/+scripts/npm-packages.sh/npm-publish.sh: the npm packages (ask-formlauncher +ask-form-<os>-<arch>), published byrelease.yml(trusted publishing, elseNPM_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.txtintodist/).- CI (
.github/workflows/ci.yml): gofmt, vet,go test -race,make dist. Releasing: push avX.Y.Ztag;release.ymlbuilds, attests and publishes the GitHub release thatinstall.sh,ask-form upgradeand 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.jsonly 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 withOrigin: null, same-origin included. The POST guard isfromThisPage(internal/server/security.go):nullpasses whenSec-Fetch-Site: same-originvouches for it. Refusing everynullbroke 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>, beforePageCSS; its logo/name via thebrandtemplate; frames getBrand.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 withheadneeds aBrand pageBrandfield. - html blocks and mockups stay script-free (frame CSP with one pinned hash). A
widgetfield's frame is the single exception (internal/server/widget.go:script-src 'unsafe-inline', still no network); don't widen it, and keepwidget.jsaccepting 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'scolor-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 throughs.render(frame-ancestors opened to the origins, no X-Frame-Options,<html data-embed>on aSec-Fetch-Dest: iframeload), their cookies throughs.setCookie(partitioned in a frame) and frames' CSP throughs.ancestors. Examples and the not-found page stay unframeable (renderPage). Theask-form:page/ask-form:thememessages are a contract with embedders (the ai-agent hub): extend, don't rename. - A snapshot is the
fieldtemplate again with.Snapset (thesnapshotpage inpages.html, built byreadOnlyPage): secrets a length, files a list, and with.Inlinetoo frames getsrcdocinstead ofsrc, pictures data: URIs. A new field type needs its snapshot look too (andanswerValues, 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 liveanswerspage (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 printat the end of app.css,beforeprint/afterprintin app.js): what only paper shows (.print-options,.print-scale,.print-if, …) is markup with thehiddenattribute 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 (notdisplay: 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'spage.pdf()(it firesbeforeprint) 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'slangis 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"}}; Goi18n.T(lang, …); the page scriptstr("…", {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:TestCatalogueCompletefails otherwise, and a script string also goes injsKeys. Another language = one file likefr.go(catalogue, plural rule, date) plusexamples/*/spec.<lang>.yaml. The relay serves/fr/examplesfromspec.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.gochecks each renders. Its French twinspec.fr.yamlkeeps 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.jsonstill 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, beforePOST /v1/forms: sections become each field'sgroup, a section'sintroa markdown block, itsshowIfAND-ed into its fields'. The server, the relay, stored forms and MCP never see YAML, so a new CLI works with an olderserve. 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 (textKeysindoc.go: a new text key goes there); errors carry the line. MCP'screate_formstill takes the JSON array. - The landing page is a React + Vite app in
landing/app/(GSAP, lucide,@gabvdl/uifrom public npm forPhonePreview/ProgressiveText). Its build inlanding/dist/is committed, so the relay and CI build with Go alone: after editingapp/, runnpm ci && npm run buildthere and commitdist/with it. The build prerenders the page (it reads without JS) and the relay servesdist/assets/*at/assets/under ascript-src 'self'CSP. The demo's examples (app/src/examples/data.tsx) mirrorexamples/. It exists in English (/) and French (/fr,landing.PageFR): every word is inapp/src/copy/{en,fr}.tsxandexamples/data{,.fr}.tsx(the French one mirrorsspec.fr.yaml), so a copy change touches both. The build prerendersdist/index.htmlanddist/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/relayprints the tunnel latency CSV.- Testing upgrades without GitHub:
ASK_FORM_UPDATE_URLpoints the updater andinstall.shat any server laid out like a GitHub repo's releases.