Defining gates
A gate stops the run until a person decides. For the concept, see Gates.
Options
Section titled “Options”gateStage('pick-angle', { type: 'pick', title: 'Pick an angle', options: ({ outputs }) => (outputs.angles as Angle[]).map((a) => ({ id: a.id, label: a.title, detail: `${a.hook} - ${a.thesis}`, fields: { title: a.title, hook: a.hook }, // defaults for the editable fields })), editable: ['title', 'hook'], regenerate: { stage: 'angles', label: 'Suggest different angles', max: 4 },});| Option | Meaning |
|---|---|
type |
'pick' (choose one of options) or 'approve' |
title |
A string, or a function of ctx |
options(ctx) |
For pick: a list of { id, label, detail?, fields? }. An approve gate gets Approve and Reject automatically. |
editable |
Field names a person may edit when deciding |
regenerate |
Let people send an earlier stage back |
title and options can be functions of ctx, and when applies to gates as well as other stages.
Editable fields
Section titled “Editable fields”editable names the fields a person may change. The values the person actually changed arrive in ctx.gates[stageId].edits, a record of strings. The API accepts only the gate’s own fields, as strings up to 4,000 characters.
const g = ctx.gates['pick-angle'];const title = g.edits?.title?.trim() || chosen.title;Send back
Section titled “Send back”regenerate: { stage, label?, max? } lets a person send an earlier stage back with a note.
| Property | Meaning |
|---|---|
stage |
The stage to rerun. It must come earlier in the module, or defineModule throws. |
label |
The button label. Default Try again. |
max |
How many times. Default 5. The API enforces it, and the gate stops offering the button at the limit. |
When a person sends a stage back, the executor rewinds to it, keeps what it produced in ctx.history, and passes the person’s note in ctx.feedback. An agent stage gets a new submission; the gate reopens afterwards. Use both in the earlier stage’s prompt:
prompt: (ctx) => { const notes = ctx.feedback.angles ?? []; const seen = (ctx.history.angles ?? []).flat(); return anglesPrompt(ctx.input, { notes, avoid: seen });},The decision is a compare-and-set, so two simultaneous clicks send the stage back exactly once.
Decisions in code
Section titled “Decisions in code”ctx.gates[id] has choice, note, edits, by and decidedAt. For approve gates the choice is approve or reject. Rejecting ends the run as rejected; later stages never run.
Presenting a gate
Section titled “Presenting a gate”How options are laid out, which artifacts show beside them (thumbnails or a gallery), and which field titles history entries use are set in ui.gates. See Module UI.
Testing gates
Section titled “Testing gates”Pass decisions to the test harness: gates: { 'pick-angle': { choice: 'a2', edits: { title: 'Plain title' } } }. A gate with no decision fails the test with a message naming the stage and its options instead of hanging. See Testing.