Ask forms
Overview
A suggested question is one line of text a user can send with one tap. An ask form is the same idea for the questions that need answers first: a chip with a form glyph, a short sheet above the composer, and a message rendered from what the user filled in. The message it sends is an ordinary user message. That is the design decision the whole feature rests on — it is why forms work with every CLI adapter without any of them learning a new shape, and why the transcript reads the same whether a line was typed or filled in. Everything below is about keeping that true without making it a place where things get lost. Forms are configured per agent and ride the ordinary agent PATCH; seecrewship agent for the command and the JSON.
A worked example ships with the demo data: crewship seed gives Casey, the
Marketing Assistant, an Investigate a missing inquiry form — the
submission ID, the expected destination, what happened, and an optional
screenshot. Render it with crewship agent ask-preview casey check-form,
or read it at cmd/crewship/seeddata/askforms/casey.json.
What a submission produces
Two things, not one:- The message. The template with
{{placeholders}}substituted, sent as the user. Plus the attachment block, if files were attached. - The submission envelope. Metadata carried with that message — never inside it:
submission_id is the part that matters most. Before it, the only handle a
submission had was the text it rendered to, and text is not an identity: two
identical submissions collided, and a reload lost the association entirely.
Files appear in field_attachment_ids and nowhere else, so one upload can
never look like the answer to two different questions.
The values under
field_attachment_ids are the agent-visible paths the upload
returns today. When canonical attachment identity lands they become opaque
att_… ids and the shape does not change — which is why the field is named
for identity rather than for paths.metadata field. There is no new
table, no migration, and a message written before any of this reads back
unchanged.
Field types
text · textarea · number · money · date · month · select ·
multiselect · checkbox · file · photo
The list is open. A type this console has never heard of renders as a text
input rather than as nothing, which is what lets a newer server offer a field
type without a coordinated frontend release.
With one exception, and it fails closed. A type whose name says the value
is a secret — password, api_key, client_secret, otp, private_key, and
anything else containing secret, password, token, credential, oauth,
cvv, or the whole words key, pin, otp, totp, ssn, pwd, auth —
is refused:
- when the form is saved.
crewship agent update --ask-formsand the console’s editor both reject it, naming the field. This is the actual guarantee: the server can never ship a type the console would mishandle. - when the form is opened, for a definition stored before this rule existed. The field renders no input at all, and the form cannot be submitted while it is there.
- and _, at most 32 characters.
Anything else is refused for the same reason: if the two renderers cannot agree
on what it is, neither should guess.
Constraints
A field may carrymin, max, pattern and multiple. What min/max mean
depends on the field:
A dash means the constraint is refused when the form is saved. That is
deliberate: a rule the submit path would not check must not be storable, or the
author is told a lie about what their form guarantees. So is
min above max,
and a pattern that does not compile.
pattern is anchored at both ends: CZ[0-9]{8} does not accept
xxCZ25788001xx. Go’s regular-expression engine checks it when the form is
saved and when an answer is submitted. The browser never executes an author’s
pattern, including while showing the message preview. A pattern accepted by
Go can still cause pathological backtracking in a browser’s native engine.
The browser checks inexpensive constraints such as required fields and bounds.
The server checks the answers with the same validator as CLI preview before
saving a form submission. It uses the current form definition of the chat’s
agent, rather than a definition supplied by the browser. Pattern errors come
back from the server; the sheet stays open with its answers and attachments.
Every field refusal names the field by its label:
crewship agent ask-preview applies the same rules to --var answers and
prints the same sentences, because a preview that renders a message the chat
would refuse is not a preview.
Go-only syntax such as (?i) is enforced on submission, including for forms
whose patterns an older browser silently skipped. A legacy stored pattern
that Go cannot compile is still not enforced; new or updated definitions with
such a pattern are rejected when saved. A missing, changed or stale form and
malformed submission metadata are refused before the message is saved. Plain
chat messages without form submission metadata remain ordinary messages.
An empty optional answer is never a violation — only required speaks to
emptiness — so min: 3 does not make a field mandatory.
Versioning a form
version is the author’s own revision number, optional and 1 when absent. It
is copied into every submission envelope, so a transcript written last month
can still be read against the questionnaire that produced it. Bump it when you
change what the form asks for; the definition moves, the answers do not.
Where each rule is enforced
The existing chat submission path recognizes the
ask_submission metadata and
validates it before saving. A form submission is still an ordinary user message
for the agent; no separate validation endpoint is needed. The envelope must name
a current form/version, its values must pass internal/askforms.ValidateAnswers,
and its rendered text and attachment block must agree with those values. The
server rebuilds the stored envelope from the trusted definition.
The browser keeps the inexpensive checks in lib/ask-validate.ts; it never runs
an author’s pattern. Pattern errors are delivered privately to the sender as
ask_submission_error, with submission_id and ask_errors (field, code,
message). Successful persistence is acknowledged by user_message with the
matching ask_submission_id. The form stays open until that acknowledgement.
A disconnect or timeout is an unconfirmed delivery: check the conversation before
sending again; it does not automatically retry. Restricted text-only chats do not
support ask envelopes and refuse them before sending.
testdata/ask-field-types.json pins the common inexpensive checks across the two
languages. testdata/ask-patterns.json pins Go/CLI and server submission matching,
including legacy patterns; browser tests check safe deferral to the server.
Troubleshooting
“This agent’s stored ask forms are not valid.” A definition in the column breaks a rule the validator now enforces — most often a field type that names a secret. The whole column is refused rather than half of it; fix the definition and re-save withcrewship agent update --ask-forms @forms.json.
A field shows an explanation instead of an input. Its type failed closed.
The form cannot be submitted until whoever configured it removes the field.
No via <form> badge on a message. The badge comes from the submission
envelope; a message typed by hand has none, and neither does one sent from a
different device before the envelope was carried.