ADR 0049 — What the agent link and the gateway need for the Studio Assistant
Status: proposed (2026-11-14). Design: canvas row Assistant (AssistantAsk, Assistant, AssistantRun, AssistantDone, AssistantFailed, AssistantRights, AssistantDrawer). Studio side: studio/docs/design/specs/assistant.md. Extends ADR 0005 (AI surface) and ADR 0033 (agent command line); closes docs/studio.md §10 items 1, 3, 5, 11, 12.
Context
The Studio Assistant (phase 12, docs/studio.md §7.8) is a chat with the agent link (links/agent): ask streams the model’s lines and its reads, the task list follows tasks/* ~val, Reject and Cancel work. The boards show more than the broker can give today:
| Board shows | Broker today |
|---|---|
| The plan with every step, its arguments, level, check result and the model’s why | The plan is in the task’s ~state document; the gateway has no op that reads documents (ws.rs: meta, children, list, subscribe, history, set, invoke, check) |
| Approve signs one token per ticked step with the user’s rights | approve {approvals} wants one human ptok per request key, signed by the approver; a gateway user has no key. The action itself is level config |
| Unticked steps are left out | approve refuses unless every step that needs approval has a token (missing approval for …) |
The assistant asks back with choice cards (AssistantAsk) | No tool for asking the user, no state for it, no answer |
WAIT / EXPECT steps (the plan proves itself) | Agent plans hold set/invoke only; wait/expect exist only in wyrm_mcp::gw::Step (plans of wyrm-agent run / MCP plan_run) |
| Run card with the current step and its answer | ~val of a task is {state}; per-step results are only in ~state |
| Try Slave ID 4, Undo the plan, Make a plan for 2 units | Every ask starts from nothing |
@ modbus/tcp-line2 chips, the Explorer drawer about the selection | ask {task} takes text only |
| Today 182 k of 1 M tokens, API key set · never shown | The budget used is internal; secret names are not readable |
| A warning on a step (Slave ID 3 was used by ahu-old) with fixes | propose returns ok or an error, nothing in between |
Decision
- Documents through the gateway. A gateway op
doc {key, suffix}(suffix∈~state,~def) answers a node’s document with the rights ofliston that node (the agent’stasksfolder isrestricted, so the asker or a config caller). Studio reads a task’s record with it after every state change. - Approvals through the gateway. On
invoke(<agent>/tasks/<id>, approve, {steps: [i…]})from a user, the gateway reads the task’s plan (op 1), mints one user token per listed step for that step’s key and level, exactly asadd_flow_proofsdoes for flow deploys, and refuses (before anything is sent) when the user’s grants do not reach a step. The token’ssubis the user, so the agent’s “approver = signer” check holds. Callers outside the gateway keep sendingapprovals. - Approve at the step’s level.
approvebecomes levelwriteon the task; what a person may approve is decided by the tokens (a token atconfigfor aconfigstep). An engineer withconfigondownstream/modbus/**approves a Modbus plan withoutconfigon the agent link. - Partial approval.
approveaccepts a subset: the steps without a token are markedskipped(log lineskipped by <sub>), never run; a step the model markedafter: [n]is skipped when a step it depends on is.proposetakesafter(default: the previous step on the same key prefix). Approval tokens are keyed by step index (approvals: {"<i>": ptok}), not by request key, so two steps on one key both work; the key form stays accepted. - Asking back. A model tool
ask_user {question, options: [{id, label, detail}], multiple?, free_text?}(≤ 3 questions per turn, ≤ 6 options each, options must name things the model read). The task goes to a new stateawaiting_answer(wire_enum!row in the task states; Studio maps it).tasks/<id>/~act/answer {answers: {<question>: [<option id>] | text}}(levelwrite, asker or config) resumes the model with the answers.~statecarriesquestions[]. - Proof steps. Agent plans take the steps of
wyrm_mcp::gw::Step:wait {key, timeout_s},expect {key, equals | min/max | changes, timeout_s},sleep. They need no approval (read). The plan format of~state.plan[]becomes thewyrm-agent runformat, so Save as a plan is the plan as it stands. - Progress in
~val. A task’s public~valbecomes{state, step, of, last}(last={n, ok, text}of the latest finished step), published at each step.~statekeeps per-stepresult(ok | failed | skipped, text, time). - Checks and warnings on proposed steps.
proposeanswers{ok, check, warn?}:check=now(checked against the live tree) orat_run(depends on an earlier step);warn= text the model must show (a slave id in use, a value at a limit). Studio drawswarnon the step; the model offers fixes as anask_user. - Follow-up asks and context.
ask {task, parent?, context?: [key…]}:parenthands the model the parent task’s ask, plan and results (a retry, an undo, the same for more rows);contextare keys the person attached (@chips, the Explorer selection), read first and within the asker’s rights. Undo is a follow-up ask the model plans like any other; nothing is reversed automatically. - What it may do, readable. The agent root shows
budget_used_today(u64, read).sys/links/<id>showssecrets(names only, levelconfig), so Studio can say set / not set forapi_key_ref(docs/studio.md§10 item 12).
Rules added when it was built (2026-11-14)
The decisions above stand. These rules make them safe; items 2, 3 and 7 are narrower than their first wording.
- The gateway signs only what it read (§2). The plan is the one the agent link stores: the gateway reads
tasks/<id>/~stateitself, with the user’s own token. The client sends{steps: [n…], plan: <hash>}and nothing else of a step. Withapprovalsin the arguments the caller brings its own tokens and the gateway adds nothing. - An approval is for the plan the user saw (§2). The plan’s hash is the SHA-256 (hex) of the canonical CBOR of
~state.plan, each step withoutapproval,check,warn,model_warn,reason,result(model_warnsince the amendment of 2026-11-14). Studio makes it from the plan it shows, the gateway from the plan it reads (never from~state.plan_hash, which it only compares), the link from the plan it holds.approve {plan}is refused when they differ (invalid_parameter, “read it again”). - One token, one step (§2). A token’s subject is the user; its single grant is exactly the step’s request key (
<node>/~set,<node>/~act/<action>);maxis the level the step needs, not the user’s level;argsis the SHA-256 of the step’s request body (spec 04), so it is good for those arguments only;jtiis fresh (single use);expis 5 min. The step’s node must be a plain key of the task’s site: no wildcard, no~segment. - An approval does not wait (§2). A token is made when the person approves and is spent when its step is sent; its life stays short (5 min from the gateway; spec 04 allows at most 15 min and one use). No token is made for later and none is made longer. So the agent link takes no step that needs a person into a plan when the waits before it (
wait/expecttimeouts,sleep) add up to more than 240 s:proposeanswers the model with the reason. Andapproveis refused (invalid_parameter, the task keeps waiting) when a token cannot outlive the waits before its step, among the steps that run, plus 30 s. The person leaves that step out and asks for the rest as a follow-up (§9) when the plan is done; it is approved then. A step that is still late (slow requests before it) fails closed: the target refuses the dead token and the run stops. - Only a person, only an agent link (§2). The gateway signs approvals for a person’s own session alone: a session of an MCP client (
/mcp, ADR 0041) is refused, and the Claude connector (wyrm-mcp --gateway) never sendsapprovefor a task. The level ofapproveiswrite, so the connector’sallow_configswitch would not have stopped aconfigstep. And it signs only forwy/<this site>/downstream/<link>/tasks/<id>where<link>has the driveragentin the broker’s registry (Gateway::set_agent_links, told at every router build): a link that only serves a plan-shaped~stategets no token of the user. - A person is told by the login, not by the transport (§2, 2026-11-14). The gateway treats a session as a person’s only when its frames come over
/api/ws(not the/mcppipe) AND its login method is a person’s:Amr::is_person=PasswordorDevice, an exhaustivematch(OAuth and any later method are not a person until written there). The same helper decides the approve gate,POST /api/ws-ticketand the/api/wsupgrade (403,permission_denied,code: person_required) and every step-up check indevices.rs. It tells how a session was made, not who drives it: a password session that a tool uses (wyrm-mcp --gateway --user) is still a person’s, and that connector’s refusal to sendapprovestays its own rule. - The meta of
approve(§2).approvedeclaresapprovals(not required),stepsandplan, so a client that checks arguments against~metatakes both forms.stepswithoutapprovalsthat reaches the link itself is refused: no gateway signed it. - Never beyond the user’s grants (§2). The gateway checks every named step against the user’s grants before it signs. If one fails, the whole call is refused before anything is sent, and the answer names the step and the right:
step 3 needs config on wy/…/~act/deploy; you have write. The refusal is in the audit (Denied, opapprove); a signed approval is too (approve, the request keys, the count left out). - Who approves (§3).
approveiswriteon the task, so the caller may be a stranger to the task. The asker, or a caller withconfigon the link, decides for the task: a step that needs no human runs with the agent’s key, as it would without an approval. Anybody else decides only for what they sign: every step that changes something needs their own token (the steps the agent would run with its own key too); a step without it isskipped, with the steps that need it, and nothing runs with the agent’s key on their word. So an engineer withconfigondownstream/modbus/**approves a Modbus plan withwriteon the agent link, by signing its steps. - Proof steps (§6) read with the agent’s reader, inside
allowed_prefixes, and take no token. A step on a node that an earlier step makes ischeck: at_run: taken atwrite, and checked against the live~metawhen it runs; a node that then asks for more, or for other arguments, stops the step before it is sent. - The public
~valholds no text (§7).~valis read by anyone who may read the link; the record is restricted. Solastis{n, ok, result}withresultone ofok,failed,skipped: not{n, ok, text}. The text of a result, the value read and the node key are in~state.plan[n].result {status, message, time}, which Studio reads throughdoc. - Asking back (§5). A restart ends a task that waits for an answer (
interrupted by restart), as it ends planning: the model’s turns are in memory.answeris a stream likeask; theaskstream ends withawaiting_answer. - Follow-ups (§9).
parentmust be a task the caller asked, or the caller hasconfigon the link. Acontextkey must be inside what the agent may read and inside what the asker may read (authof the caller’s token). The asker’s rights are read as every evaluator reads grants (spec 04): the first grant that touches the key decides (Caller::perm_on,wyrm_core::ptok::level_on), so anonebefore a wider grant keeps the value out of the model’s prompt. - Secret names (§10) are the action
sys/links/<id>▸secrets(levelconfig, names only), not a value: a~valis read atread. - Task states are the agent link’s own table (
TaskState,wire_enum!, by name in~val.state); they are not inspec/. The gateway’s frame protocol is documented incrates/wyrm-gateway/src/ws.rsanddocs/broker.md; nospec/text changed.
Amendment (2026-11-14): what the model offers next, a replaced plan, fixes on a step
Studio built specs/assistant.md §2 steps 1–4 and found three cards without data: the ways out of a stopped run and the Same for more units? rows (and the second button of the Explorer drawer), the old plan shown as replaced, and the fixes in a step’s warning. The owner delegated the design (ADR 0029). One tool, three record fields and one rule close them; no spec/ text changed.
1. Suggestions. A model tool suggest {label, detail?, changes?, step?, rows?: [{path, label, detail?}]} adds one entry to the task’s record: ~state.suggestions[] = {id, label, detail, changes, step?, rows?: [{key, label, detail}]}.
- It is what the person may ask next: a way out of a run that stopped, the same change for more nodes (
rows, one per node), a fix for the warning of plan stepstep, the drawer’s second button.changesis the model’s count of the changes it would take (0: nothing changes): the tag on the tile, nothing more. - A suggestion is data and runs nothing. The link never acts on one, and the gateway never reads one. A person who picks it sends a follow-up
ask {parent, task, context?}(§9) whose text is what they saw on the card (label,detail, the labels of the ticked rows) and whosecontextis the keys of the ticked rows. What that changes is a new plan, checked as any plan and approved step by step with the person’s own tokens (§2–4). - Bounded. At most 8 suggestions in a task at a time, 16 rows each (the
contextlimit ofask),label≤ 80 bytes,detail≤ 300 bytes (longer text is cut),changes≤ 50.stepmust be a step of the plan so far. - Inside the asker’s rights. A row names a plain node key of the task’s site that the agent may read (
allowed_prefixes,pub/**) and that the asker of the task may read (Caller::perm_on(<node>/~val)over the person’s grants that the token carries asauth, spec 04). Fail closed: the rights are known only from a token withauth(a token without it means unknown rights, and the row is refused, as the flow engine refuses sources), they are kept in memory only (after a restart of the link nobody’s rights are known), and they hold only until that token’sexp. The asker’s own lateranswerorapproveon the task renews them (their newer token); a call of somebody else does not. So a row of a planning turn after a long wait, or of a review after a restart, is refused, and the model offers the way out without rows. Any other row refuses the whole suggestion to the model.ask {context}needsauthin the same way (permission_denied). The follow-upaskchecks itscontextagainst its own caller again. The follow-upaskchecks itscontextagainst its own caller again. - Texts stay in the record. The public
~valgainssuggestions(their count, absent at 0) and no word of them. Studio reads them throughdocwith the reader’s rights. - After a run stopped. The model has no turn in a task that ended, so a run that stops at a step (a step failed; not a reject, a cancel or a restart) gets one: a review, at most
review_turnsLLM calls (param, default 4, 0 = none), with the read tools andsuggestonly. Nopropose, noask_user: nothing is planned and nobody is asked. The model gets the task’s ask, plan with results and error, reads why, and offers ways out. The task staysfailedand itserrorstays the run’s;~valand~stateshowreviewing: truewhile the turn runs; the model’s last words are~state.review(≤ 600 bytes). The turn spends the daily budget like planning; without budget or model it is skipped with a log line.cancel(asker or config) whilereviewingends the turn:reviewinggoes, noreview, the task staysfailedwith the run’s error. A task removed to make room (eviction) ends its review with it. - Suggestions follow the plan they were made for. A task that fails (a stopped run, reject, cancel, replaced, restart) drops what planning offered; after a stopped run the review’s ways out take their place. A task that is
donekeeps them: the Same for more units? table of the result card.
2. A replaced plan. ask {parent} where the parent waits for a person (awaiting_approval or awaiting_answer) takes the parent’s place: under the same lock that creates the new task, the parent goes to failed with error: "replaced by <id>" and the field replaced_by: <id>, in ~state and in the public ~val (a task id the link made, no text). No new state: failed is already how a plan ends that will not run (reject, cancel), so every reader of states stays right.
approveon a replaced task is refused withinvalid_parameter(0x23),task was replaced by <id>: … approve that task. The gateway refuses the same way from the record it reads, before it signs anything.answer,rejectandcancelare refused as for any task that ended.- A parent that is
planning,running,doneorfailedis not touched: a follow-up of it replaces nothing (a run goes on untilcancel; an undo of a done task is a new plan beside it). - If the follow-up fails while planning, the parent stays replaced: the person asks again (the failed follow-up or the old task as
parent). An old plan that came back after another one was asked for could be approved by mistake. - The mark is in the stored record, so it holds after a restart.
3. Fixes on a step. §8 said warn is text and fixes are an ask_user. Two things were missing: only the link could warn (a value at a limit), and nothing tied a fix to a step. Now propose takes warn (≤ 300 bytes), kept in the step’s own field model_warn: warn stays the link’s own finding (a value at a limit), so a reader always tells the link’s words from the model’s, and Studio shows model_warn as the model’s (a different label or style, never as a check of the link). A fix is a suggestion with step: n. Studio draws the suggestions of step n in that step’s warning box. A fix is picked like any suggestion: a follow-up ask {parent}, which replaces the waiting plan (rule 2) with a plan the person approves. So the plan with its warning can be approved as it is, or a fix picked, as the board Assistant shows; the spec’s “each fix = answer” does not hold (an answer exists only in awaiting_answer, where nothing can be approved). warn and model_warn stay outside the plan’s hash (UNHASHED in the link and the gateway, planUnhashed in wyrm_client). A client that still hashes model_warn makes another hash, and its approval is refused (“read it again”): it fails closed.
Old records and old clients. The three fields live in the record’s plan bytes beside questions, parent and context (store schema 1 unchanged); a record without them reads as no suggestions, not replaced, no review (test a_task_written_before_the_suggestions_still_loads, fixed bytes). A link of the version before reads the new records too (an ADR 0048 rollback): it skips the keys it does not know, and a replaced task is failed for it as well. A client that does not know the fields ignores them.
Which card shows which suggestions (specs/assistant.md §6): a PlanStepCard those with step = its number while the task is awaiting_approval; the ResultCard of a done task those with rows; the StoppedCard all of them with review; the Explorer drawer’s second button the first one without step. While the task is awaiting_approval, that button shows the suggestion’s detail as a draft to copy and sends no ask: a follow-up ask {parent} would replace the plan the person still means to approve (rule 2). After the task has ended, it is a follow-up ask like any way out. Picking a fix tile does replace the waiting plan, and the tile says so.
Tests: links/agent/tests/agent.rs a_stopped_run_gets_ways_out_and_a_step_gets_fixes, a_suggestion_is_bounded_and_inside_the_askers_rights, a_follow_up_replaces_a_task_that_waits_for_a_person; crates/wyrm-gateway a_replaced_plan_is_not_signed_and_suggestions_are_read_through_doc and the unit test of approve::Plan::select; dart/wyrm_client/test/agent_test.dart.
Amendment 2 (2026-11-14): what the model found
Studio built specs/assistant.md §2 step 6 and found one more card without data: the rows of What I found in the Explorer drawer (board AssistantDrawer). The model’s findings were only its text. The owner delegated the design (ADR 0029). One tool, one record field and one count close it; no spec/ text changed.
- A model tool
found {path, label, detail?}adds one row to the task’s record:~state.findings[] = {key, label, detail}. It is in the planning turns and in the turn after a stopped run (both only read). One row per node, in the order the model noted them. - The model’s words, no verdict.
labelanddetailare model text: a client shows them as plain text, never as a link, a check or a button. A row carries no mark good or bad. The board’s ✓ and ✕ are drawn by the client from the node’s live value (its quality), read with the viewer’s own rights; without a value the row has no mark. So a mark is never the model’s claim. - Bounded. At most 12 findings in a task;
label≤ 80 bytes,detail≤ 300 bytes (longer text is cut, the…inside the bound; the same for suggestions). One row per node: a second finding on a node replaces the words of its row in place (same order, same count), so the turn after a run corrects what planning noted instead of keeping a stale good. - Inside the asker’s rights, as the rows of a suggestion. The key is a plain node key of the task’s site (no wildcard, no
~segment) that the agent may read (allowed_prefixes,pub/**) and that the asker may read (Caller::perm_on(<node>/~val)≥readover the grants of their token’sauth). Fail closed: unknown rights (a token withoutauth, a restart) or rights past their token’sexprefuse the finding, and the model is told to note none (not to put the node into its answer). The same rule as amendment 1. - Why rows are missing. Each refusal is counted in
~state.findings_refused{rights_unknown | rights_expired | outside_rights | limit | invalid: <count>}: fixed words, no model text. Studio says from it why rows are missing. The rights last as long as the asker’s last call on the task (ask, their ownanswerorapprove): 5 min from the gateway (PTOK_TTL). Nothing renews them on its own (no rights-renewal code, by design), so findings are refused asrights_expiredwhen (1) the turn after a stopped run starts after another person approved the plan (the run’s end starts it, not a person, and that approval does not renew the asker’s rights), or (2) the run took more than about 5 min after the approval. - Texts stay in the record. The public
~valgainsfindings(their count, absent at 0) and no word of them, so a reader of~vallearns that the record changed, not what it says. Studio reads them throughdocwith the reader’s rights. - They stay. A finding says what was read, not what to do: unlike suggestions, findings are kept when the task fails (reject, cancel, replaced, a stopped run). They are no part of the plan and not in its hash.
- Old records.
findingslives in the record’splanbytes beside the fields of amendment 1 (store schema 1 unchanged). A record without it reads as no findings (testa_task_written_before_the_findings_still_loads, fixed bytes of the richest record of the version before). A link of the version before skips the key. The gateway is not touched:docpasses the record through, and no gateway code reads findings.
Tests: links/agent/tests/agent.rs findings_are_bounded_inside_the_askers_rights_and_stay; store unit tests; dart/wyrm_client/test/agent_test.dart (TaskFinding, findingCount).
Consequences
- One gateway op (
doc), one gateway rewrite ofapprove(like flow proofs), and agent link changes instore.rs(task schema:questions,after, per-stepresult; old tasks read with defaults) andlib.rs(ask_user,answer,awaiting_answer,wait/expect,~valprogress). docs/studio.md§10 items 1, 3, 5, 11, 12 close when this is built; §7.8’s “built now” paragraph is replaced bystudio/docs/design/specs/assistant.md.- e2e: ask → ask_user → answer → plan → partial approve (one step skipped, its dependant skipped) → wait/expect → done; approve refused for a user without the level;
docrefused withoutlist.
Not decided here
- Approvals through the gateway for a task on a downstream site. The gateway knows the agent links of its own site only, so
approve {steps}there is refused; Studio must lock Approve with that reason when the viewed site is not the gateway’s own. Open: the downstream broker tells its agent links upward, or the user’s gateway asks the downstream gateway to sign. - A second model for the Assistant (Claude through the user’s own connector, ADR 0041, instead of the agent link’s API key). The Studio screens stay the same; only who writes the plan changes.
- Generated views in the chat (A2UI,
specs/genui-views.md): a later card type.