driverkit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTROLS.md +578 -0
- package/README.md +104 -2
- package/dist/agent/backend.d.ts +69 -0
- package/dist/agent/backend.d.ts.map +1 -0
- package/dist/agent/backend.js +130 -0
- package/dist/agent/backend.js.map +1 -0
- package/dist/agent/control.d.ts +148 -0
- package/dist/agent/control.d.ts.map +1 -0
- package/dist/agent/control.js +342 -0
- package/dist/agent/control.js.map +1 -0
- package/dist/agent/index.d.ts +9 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.d.ts.map +1 -0
- package/dist/agent/loop.js +824 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/render.d.ts +173 -0
- package/dist/agent/render.d.ts.map +1 -0
- package/dist/agent/render.js +425 -0
- package/dist/agent/render.js.map +1 -0
- package/dist/agent/tools.d.ts +138 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +622 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/types.d.ts +566 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +32 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/browser/budget.d.ts +92 -0
- package/dist/browser/budget.d.ts.map +1 -0
- package/dist/browser/budget.js +151 -0
- package/dist/browser/budget.js.map +1 -0
- package/dist/browser/connect.d.ts +368 -0
- package/dist/browser/connect.d.ts.map +1 -0
- package/dist/browser/connect.js +1038 -0
- package/dist/browser/connect.js.map +1 -0
- package/dist/browser/elsewhere.d.ts +89 -0
- package/dist/browser/elsewhere.d.ts.map +1 -0
- package/dist/browser/elsewhere.js +91 -0
- package/dist/browser/elsewhere.js.map +1 -0
- package/dist/browser/frames.d.ts +85 -0
- package/dist/browser/frames.d.ts.map +1 -0
- package/dist/browser/frames.js +11 -0
- package/dist/browser/frames.js.map +1 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +9 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/check/check.d.ts +171 -0
- package/dist/check/check.d.ts.map +1 -0
- package/dist/check/check.js +666 -0
- package/dist/check/check.js.map +1 -0
- package/dist/check/index.d.ts +3 -0
- package/dist/check/index.d.ts.map +1 -0
- package/dist/check/index.js +2 -0
- package/dist/check/index.js.map +1 -0
- package/dist/check/types.d.ts +149 -0
- package/dist/check/types.d.ts.map +1 -0
- package/dist/check/types.js +29 -0
- package/dist/check/types.js.map +1 -0
- package/dist/controls/controls.d.ts +198 -0
- package/dist/controls/controls.d.ts.map +1 -0
- package/dist/controls/controls.js +742 -0
- package/dist/controls/controls.js.map +1 -0
- package/dist/controls/dom.d.ts +108 -0
- package/dist/controls/dom.d.ts.map +1 -0
- package/dist/controls/dom.js +56 -0
- package/dist/controls/dom.js.map +1 -0
- package/dist/controls/index.d.ts +26 -0
- package/dist/controls/index.d.ts.map +1 -0
- package/dist/controls/index.js +23 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/controls/rows.d.ts +66 -0
- package/dist/controls/rows.d.ts.map +1 -0
- package/dist/controls/rows.js +127 -0
- package/dist/controls/rows.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry.d.ts +192 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +2799 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/types.d.ts +2468 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +19 -0
- package/dist/core/types.js.map +1 -0
- package/dist/otel/index.d.ts +122 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +157 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/react/index.d.ts +191 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +547 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/runtime.d.ts +95 -0
- package/dist/react/runtime.d.ts.map +1 -0
- package/dist/react/runtime.js +54 -0
- package/dist/react/runtime.js.map +1 -0
- package/dist/react/store.d.ts +333 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +695 -0
- package/dist/react/store.js.map +1 -0
- package/dist/relay/auth.d.ts +244 -0
- package/dist/relay/auth.d.ts.map +1 -0
- package/dist/relay/auth.js +391 -0
- package/dist/relay/auth.js.map +1 -0
- package/dist/relay/frames.d.ts +141 -0
- package/dist/relay/frames.d.ts.map +1 -0
- package/dist/relay/frames.js +20 -0
- package/dist/relay/frames.js.map +1 -0
- package/dist/relay/index.d.ts +8 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/index.js +4 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/relay.d.ts +277 -0
- package/dist/relay/relay.d.ts.map +1 -0
- package/dist/relay/relay.js +1026 -0
- package/dist/relay/relay.js.map +1 -0
- package/dist/relay/serve.d.ts +33 -0
- package/dist/relay/serve.d.ts.map +1 -0
- package/dist/relay/serve.js +86 -0
- package/dist/relay/serve.js.map +1 -0
- package/dist/widget/chat.d.ts +290 -0
- package/dist/widget/chat.d.ts.map +1 -0
- package/dist/widget/chat.js +486 -0
- package/dist/widget/chat.js.map +1 -0
- package/dist/widget/css.d.ts +49 -0
- package/dist/widget/css.d.ts.map +1 -0
- package/dist/widget/css.js +532 -0
- package/dist/widget/css.js.map +1 -0
- package/dist/widget/dom.d.ts +143 -0
- package/dist/widget/dom.d.ts.map +1 -0
- package/dist/widget/dom.js +27 -0
- package/dist/widget/dom.js.map +1 -0
- package/dist/widget/highlight.d.ts +64 -0
- package/dist/widget/highlight.d.ts.map +1 -0
- package/dist/widget/highlight.js +136 -0
- package/dist/widget/highlight.js.map +1 -0
- package/dist/widget/index.d.ts +9 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +20 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/position.d.ts +166 -0
- package/dist/widget/position.d.ts.map +1 -0
- package/dist/widget/position.js +497 -0
- package/dist/widget/position.js.map +1 -0
- package/dist/widget/settings.d.ts +116 -0
- package/dist/widget/settings.d.ts.map +1 -0
- package/dist/widget/settings.js +117 -0
- package/dist/widget/settings.js.map +1 -0
- package/dist/widget/widget.d.ts +442 -0
- package/dist/widget/widget.d.ts.map +1 -0
- package/dist/widget/widget.js +2005 -0
- package/dist/widget/widget.js.map +1 -0
- package/package.json +153 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA2BH,MAAM,OAAO,GAAG,SAAkB,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IAClD,OAAO;IACP,cAAc;IACd,cAAc;IACd,cAAc;IACd,WAAW;IACX,OAAO;IACP,aAAa;IACb,eAAe;IACf,SAAS;IACT,kBAAkB;IAClB,+DAA+D;IAC/D,EAAE;IACF,6EAA6E;IAC7E,6EAA6E;IAC7E,uEAAuE;IACvE,+DAA+D;IAC/D,0EAA0E;IAC1E,6EAA6E;IAC7E,gBAAgB;IAChB,EAAE;IACF,2EAA2E;IAC3E,4EAA4E;IAC5E,wEAAwE;IACxE,wEAAwE;IACxE,0EAA0E;IAC1E,oEAAoE;IACpE,qCAAqC;IACrC,kBAAkB;IAClB,kBAAkB;IAClB,wEAAwE;IACxE,sEAAsE;IACtE,WAAW;IACX,EAAE;IACF,iEAAiE;IACjE,0EAA0E;IAC1E,2EAA2E;IAC3E,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,uCAAuC;IACvC,YAAY;IACZ,4EAA4E;IAC5E,mDAAmD;IACnD,EAAE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AAC,CAAC,CAAC,CAAC,CAAC;QAC3D,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,qEAAqE;QACrE,wEAAwE;QACxE,yEAAyE;QACzE,sEAAsE;QACtE,2EAA2E;QAC3E,gBAAgB;QAChB,EAAE;QACF,0EAA0E;QAC1E,2EAA2E;QAC3E,0EAA0E;QAC1E,uEAAuE;QACvE,sEAAsE;QACtE,2EAA2E;QAC3E,0EAA0E;QAC1E,0BAA0B;QAC1B,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/**\n * driverkit/core — the registry.\n *\n * One function, `mount`, and one invariant: every way of driving the app goes\n * through `call`. The in-page chatbot calls it directly, the relay calls it\n * after a websocket frame arrives, a test calls it with no transport at all.\n * There is deliberately no second path, because a second path is a second set\n * of validation and staleness rules and one of the two will be the wrong one.\n *\n * The core renders nothing and imports nothing. No React, no model SDK, no\n * websocket. Those live in sibling packages so an app that only wants to be\n * drivable from outside does not pull a UI into its bundle.\n */\n\nimport type {\n Approval,\n ApprovalHook,\n ApprovalRequest,\n ArgSpec,\n AskAnswer,\n AuditEvent,\n AuditHook,\n CallOptions,\n Driver,\n DriverApproval,\n ElsewhereChannel,\n ElsewhereNotice,\n Manifest,\n MountOptions,\n Refusal,\n Report,\n Result,\n Scalar,\n ScreenSpec,\n Snapshot,\n Verb,\n VerbContext,\n} from \"./types.ts\";\n\nconst REFUSAL = \"refusal\" as const;\n\n/**\n * The slugs an app may not use as a refusal of its own, or as a verb name.\n *\n * PROTOCOL.md's reserved list, in code, because a list that lives only in prose\n * is a list nothing checks. Seven come from the core itself, three from the\n * relay and three from the approval gate, and they have one property in common:\n * each says something about WHERE a call stopped, not about the app's rules. An\n * app that refuses with `timeout` has taken away an agent's only way to tell\n * \"the app said no, phrase it differently\" from \"your call never landed,\n * reconnect or pick another tab\" — and an agent that cannot tell those apart\n * will retry a commit that may already have run.\n *\n * `wrong-screen` is the newest, and the only one that was ever an app's own. An\n * app with six screens wrote the check by hand and had to invent a word for it;\n * the next app would have picked `not-on-this-screen`, and an agent that had\n * learned one would not recognise the other. The slug says where a call\n * stopped — you are not there — so it belongs here with the rest, and\n * `Verb.screen` with `CallOptions.screen` is how an app now gets the check for\n * nothing. An app that was refusing it by hand is told so at mount; see below.\n */\nexport const RESERVED_REFUSALS: readonly string[] = [\n \"stale\",\n \"wrong-screen\",\n \"unknown-verb\",\n \"bad-argument\",\n \"unmounted\",\n \"threw\",\n \"no-such-tab\",\n \"tab-went-away\",\n \"timeout\",\n \"declined-by-user\",\n // The two the approval gate added when it moved into the core.\n //\n // `approval-pending` says a call arrived while this driver was waiting for a\n // person to answer a question about another one. It is a refusal rather than\n // a queue on purpose: the call an agent is most likely to make in that\n // window is the Approve button of the dialog that is asking it\n // (webmachinelearning/webmcp#288), and the second most likely is the same\n // commit again, to race the dialog. Both are answered \"not while somebody is\n // being asked\".\n //\n // `approval-timeout` is NOT the relay's `timeout` and must never be folded\n // into it. The relay's means the call was accepted and no answer came back,\n // so the outcome is UNKNOWN and a commit may already have run; this one\n // means nobody answered the question, so the verb was never reached and\n // nothing changed. The two call for opposite next moves — read the screen\n // before touching anything, versus ask again — which is exactly why\n // PROTOCOL.md reserves slugs at all.\n \"approval-pending\",\n \"approval-timeout\",\n // The one the plan token added, and it is a WHAT YOU ARE ACTING ON slug\n // rather than a WHERE YOU ARE one, which is why it is not folded into\n // `stale`.\n //\n // `stale` says the screen moved and the fix is to read it again.\n // `stale-plan` says the SELECTION is not the one whose count was read and\n // approved, and the fix is strictly larger: run the `describe` again, read\n // the new count, check it is still the number the person asked for, and only\n // then commit. An agent told `stale` re-reads and carries straight on, which\n // is exactly the move that accepts 3,418 rows after a person approved 3,412.\n // Two different repairs, so two slugs.\n \"stale-plan\",\n // The one the cost ceiling added, and it is a WHAT IT COST slug rather than\n // a WHERE YOU ARE or a WHAT YOU ARE ACTING ON one.\n //\n // Every other slug on this list describes something an agent can repair.\n // `budget-spent` is the only one whose honest hint is \"do not try again\" —\n // the ceiling was declared by whoever mounted the app, it does not reset, and\n // the only thing that moves it is a person changing `MountOptions.budget`. It\n // is reserved for the usual reason: an app that refused `budget-spent` on a\n // business rule would be telling an agent to stop forever over something it\n // could have phrased differently.\n //\n // ONE SLUG FOR BOTH CEILINGS, and the ladder is why. Two slugs earn their\n // place when two repairs differ — `stale` versus `stale-plan` is the live\n // example on this list. The call budget and the commit budget end in the\n // identical repair, which is no repair: stop, and tell the person. So the\n // slug is one and the HINT names which ceiling, with both numbers.\n \"budget-spent\",\n // The one cross-tab staleness added, and it is a WHAT YOU ARE ACTING ON slug\n // like `stale` and `stale-plan` rather than a new kind of thing.\n //\n // It is the only slug on this list that the core originates from something it\n // was TOLD rather than something it can see. Every other staleness check\n // compares two values out of `visible()`; this one fires because another\n // driver of the same app said a commit landed, which is a fact no value in\n // this tab can carry. See `MountOptions.elsewhere`.\n //\n // WHY NOT `stale`. `stale` means \"the number you echoed is not the number on\n // screen, read again\", and re-reading is a repair that WORKS. Here the number\n // on screen matches and is wrong, so an agent told `stale` would re-read,\n // get the same rev, believe itself current and commit — which is the silent\n // failure this exists to end, re-created by reusing the slug. The repair is\n // different and much larger: this tab's copy of the data is behind and only\n // the app refreshing fixes it.\n \"changed-elsewhere\",\n // The three the question verb added. All three say WHY NOBODY ANSWERED, which\n // is a fourth kind of thing on this list — not where the call stopped, not\n // what it was acting on, not what it cost — and the reason there are three of\n // them rather than one is the reason there are two of `stale` and\n // `stale-plan`: the repairs differ.\n //\n // `ask-unanswered` — the question was put in front of somebody and no answer\n // came back. The channel works and this question went unanswered, so asking\n // once more, or asking something shorter, is a move that can succeed. **The\n // verb did not run and nothing changed**, exactly as with `approval-timeout`,\n // and for the same reason that slug is not the relay's `timeout`: nobody is\n // in any doubt about what happened.\n //\n // `nobody-to-ask` — there is no person on this path at all: a cron run, a\n // test harness, an app that declared no way to ask. Every further question is\n // wasted, so the repair is strictly larger — decide from what is known, or\n // stop and say what is missing. An agent told `ask-unanswered` for this will\n // ask again into an empty room until something else stops it, which is why\n // folding the two would be the same mistake as folding `stale` into\n // `stale-plan`.\n //\n // `asks-spent` — the app's question allowance is gone, so this one was never\n // put. Deliberately NOT `budget-spent`, and this is the one departure from\n // \"one slug for both ceilings\" a few lines up. That rule's own justification\n // is that the call ceiling and the commit ceiling \"end in the identical\n // repair, which is no repair: stop, and tell the person\" — and a spent\n // question allowance ends in a real one: say in your answer what you would\n // have asked. It also must not be `budget-spent` because `drive` ends the\n // whole run on that slug, which would mean an agent that asked one question\n // too many could no longer finish the sentence it was asking about.\n \"ask-unanswered\",\n \"nobody-to-ask\",\n \"asks-spent\",\n];\n\nconst RESERVED = new Set(RESERVED_REFUSALS);\n\n/** Spelled once. The core originates this slug from two checks and names it in\n * a third message, and three string literals is how the three come to\n * disagree. */\nconst WRONG_SCREEN = \"wrong-screen\";\n\n/** Spelled once, for the same reason `WRONG_SCREEN` is. `driverkit/agent`\n * exports its own `DECLINED` with the same value: that one is the slug the\n * in-page loop's own gate emits and it predates this, and the string is\n * PROTOCOL.md's rather than either file's. */\nconst DECLINED = \"declined-by-user\";\nconst APPROVAL_PENDING = \"approval-pending\";\nconst APPROVAL_TIMEOUT = \"approval-timeout\";\nconst STALE_PLAN = \"stale-plan\";\nconst BUDGET_SPENT = \"budget-spent\";\nconst CHANGED_ELSEWHERE = \"changed-elsewhere\";\nconst ASK_UNANSWERED = \"ask-unanswered\";\nconst NOBODY_TO_ASK = \"nobody-to-ask\";\nconst ASKS_SPENT = \"asks-spent\";\n\n/** What a `stale-plan` refusal tells an agent to do when it HAD a plan and the\n * plan is no longer good. Spelled once because four of the five reasons end in\n * this same repair, and four copies is how three of them come to say something\n * slightly different. It is the pairing rule, stated as the fix. */\nconst PLAN_REPAIR =\n \"Run the app's `describe` verb again, read the `count` it reports, check it is still the \" +\n \"number the person asked for, and call this with the `plan` that describe hands back. Do \" +\n \"not re-send this one.\";\n\n/**\n * The repair for the fifth reason: no plan was presented at all.\n *\n * A SEPARATE SENTENCE, and the separation is the whole point of this constant\n * existing. \"The plan you had is out of date\" and \"you brought no plan\" are\n * different mistakes with different fixes, and the first one's fix is actively\n * dangerous as an answer to the second.\n *\n * An eval found it. \"Accept the selected contacts\" with nothing selected was\n * answered `stale-plan` — correctly, since the check is before the verb body —\n * with a hint that said run the describe again. With an empty selection the\n * only describe that mints a non-empty plan is one that INVENTS a selection,\n * so the hint was pointing at improvising in the one situation where\n * improvising is most expensive. The same eval watched an agent improvise its\n * way to a bulk decline of 403 rows, so this is not a theoretical reading of\n * the sentence.\n *\n * So this one says to go and count the rows the PERSON asked about, and says\n * out loud that picking a selection to give the call something to act on is\n * the wrong move. The empty case gets that said twice, from `checkPlan`.\n */\nconst PLAN_MISSING_REPAIR =\n \"Run the app's `describe` verb for the rows the person actually asked about, read the \" +\n \"`count` it reports, and call this with the `plan` it hands back. If you cannot tell which \" +\n \"rows they meant, or the app has no verb that selects them, say so and ask — do NOT select \" +\n \"something near enough to give this call a plan to run on.\";\n\n/** The token's own prefix and version, so a token from a future shape of this\n * can be told from a corrupt one. Opaque to everybody but `mount()`. */\nconst PLAN_PREFIX = \"dkp1\";\n\n/** Counts mounted drivers, only so each one's plan salt differs from the last.\n * Module-level because two drivers in one page must not agree. */\nlet planSeq = 0;\n\n/** Counts mounted drivers, only so each one can tell its own cross-tab notices\n * from a sibling's. Module-level for the reason `planSeq` is: two drivers in\n * one page must not agree, and two drivers in one page is exactly the case a\n * test of this feature sets up. */\nlet elsewhereSeq = 0;\n\nconst DECLINED_HINT =\n \"A person was asked to approve this and said no. Do not retry it, do not try another verb \" +\n \"that does the same thing, and do not press a control that does it — the answer was about \" +\n \"the action and not about how you asked. Say what you were about to do and ask what they \" +\n \"would like instead.\";\n\nconst PENDING_HINT =\n \"this app is waiting for a person to approve something, so it is not taking calls. Nothing \" +\n \"ran. Wait for the answer and read the screen; in particular, pressing an approve or confirm \" +\n \"control yourself is not a way to answer the question, and that is why this is refused.\";\n\n/**\n * What stands in for a `sensitive` argument's value in an audit record.\n *\n * Fixed rather than configurable, and exported rather than private. A marker\n * an app can change is a marker that the person reading somebody else's log\n * cannot recognise, and a marker nobody can import is one every test and every\n * sink spells out by hand and eventually spells differently. See\n * `ArgSpec.sensitive`.\n */\nexport const REDACTED = \"[redacted]\";\n\n/**\n * A verb's `screen` as a list, whatever shape the app declared it in.\n *\n * One string and `[\"one-string\"]` mean the same thing to every check in here,\n * and the alternative — `Array.isArray` at each of the three places that reads\n * the field — is how two of the three come to disagree about the one-element\n * case. The declared shape is still what goes in the manifest and in the\n * fingerprint; this is only for deciding and for phrasing.\n */\nfunction screensOf(screen: string | string[]): string[] {\n return Array.isArray(screen) ? screen : [screen];\n}\n\n/**\n * `a`, `b` and `c` — for a hint a person and a model both read.\n *\n * It reads naturally for one as well as for several, which is the point: the\n * refusal for a verb on one screen must not acquire a comma or the word \"and\"\n * because the field can now hold a list. One screen phrases exactly as it did\n * before this field could be an array.\n */\nfunction naming(screens: string[]): string {\n const quoted = screens.map((s) => `\\`${s}\\``);\n if (quoted.length <= 1) return quoted.join(\"\");\n return `${quoted.slice(0, -1).join(\", \")} and ${quoted[quoted.length - 1]}`;\n}\n\n/**\n * Say so once, and keep running.\n *\n * Deliberately not a throw. An undeclared refusal slug is discovered while a\n * verb is refusing — the path an app takes when it is working correctly and\n * merely saying no — and turning that into an exception would take a live app\n * down over a documentation mistake. Silence is not the alternative: `refuses`\n * is documented as checked, and a check nobody can observe is the bug this\n * exists to fix.\n *\n * Deduped per message, so a model looping on one refused verb cannot turn this\n * into a console flood. Deduping rather than a build flag is also how this\n * stays dev-shaped in a package with no build step and no `process.env` to\n * read: a correct app prints nothing, ever, and an incorrect one prints once.\n */\nconst warned = new Set<string>();\n\nfunction warn(message: string): void {\n if (warned.has(message)) return;\n warned.add(message);\n if (typeof console !== \"undefined\" && typeof console.warn === \"function\") {\n console.warn(`driverkit: ${message}`);\n }\n}\n\n/**\n * The reserved navigation verb, and the two names that go with it.\n *\n * Reserved in the weak sense and on purpose: `goto` is NOT in\n * `RESERVED_REFUSALS`, so an app may still declare a verb of its own by that\n * name and the core leaves it alone. The reserved refusal slugs are reserved\n * strictly because an app that refuses `timeout` takes away a distinction an\n * agent cannot recover; a verb named `goto` takes nothing away from anybody —\n * it either navigates, which is what the name says, or the author has a reason\n * the core cannot see. The same rule as the `rev` and `screen` arguments\n * `driverkit/agent` hoists into every tool schema: the app's meaning wins\n * over ours.\n *\n * What \"reserved\" buys is one name instead of one per app. Before this, every\n * multi-screen app wrote its own navigation verb — `go`, `navigate`,\n * `open-screen`, `route-to` — and an agent that had learned one did not\n * recognise the next, which is the same argument that made `wrong-screen` a\n * reserved refusal rather than a word each app invents.\n */\nconst GOTO = \"goto\";\n\n/** The name of `goto`'s one always-present argument. Spelled once: it is\n * checked against every screen's own argument names and named in the refusal,\n * and three string literals is how the three come to disagree. */\nconst GOTO_SCREEN_ARG = \"screen\";\n\n/** The one refusal the core itself originates from `goto`. Not reserved — it\n * is a fact about the call and not about where the call stopped — and\n * deliberately not declared in `goto.refuses`; see the verb. */\nconst BAD_SCREEN_ARG = \"bad-screen-argument\";\n\n/**\n * `goto`'s description, which every agent reads in the cached half.\n *\n * Here rather than in `driverkit/agent` and `mcp_core.py`, which is where\n * every other piece of tool prose lives, because this verb is the core's own:\n * the two renderers describe what an APP declared, and a sentence about a verb\n * the core implements written twice in two languages is a sentence that\n * drifts. The screens themselves are not listed in here — they are rendered\n * into the system prompt and the MCP server instructions from\n * `Manifest.screens`, next to the flows — so this text says what the verb does\n * and where the map is, and the `oneOf` on its argument carries the ids.\n */\nconst GOTO_DESCRIBE =\n \"go to one of this app's screens, the way clicking its own navigation does. Pass the \" +\n \"screen's id; your instructions list every screen this app has, what each one is for, \" +\n \"and which ones need an argument of their own — a screen that shows one record needs to \" +\n \"be told which record. Refused as `bad-screen-argument` when a screen's own argument is \" +\n \"missing or the wrong type, and the app may refuse it for its own reasons, such as a \" +\n \"screen this person is not allowed to open.\";\n\n/**\n * The reserved question verb.\n *\n * Reserved in the same WEAK sense `goto` is, and the same rule decides it: an\n * app that declares its own verb named `ask` keeps it and the core adds\n * nothing, because the app's meaning wins over ours. What \"reserved\" buys is\n * one name instead of one per app — `ask`, `ask-user`, `clarify`, `check-with-\n * me`, none of which the next agent recognises — which is the argument that\n * made `goto` reserved and `wrong-screen` a reserved refusal.\n *\n * It is NOT in `RESERVED_REFUSALS`, so a verb may be named this. The three\n * slugs the mechanism added are, for the usual reason: an app that refused\n * `nobody-to-ask` on a business rule would be telling an agent to stop asking\n * for the rest of a run over something it could have phrased differently.\n */\nconst ASK = \"ask\";\n\n/** The name of `ask`'s one argument. Spelled once: it is named in the schema,\n * in two refusals and in the record. */\nconst ASK_QUESTION_ARG = \"question\";\n\n/**\n * How long a question waits for an answer when the app did not say.\n *\n * **45 seconds, and the number is chosen against the relay's 60.** See\n * `MountOptions.askTimeout`: a question that outlives the transport's deadline\n * converts \"nobody answered\", which is a fact the agent can act on, into the\n * relay's `timeout`, which PROTOCOL.md defines as outcome unknown. Of the two\n * errors, firing late is the expensive one here — the opposite way round from\n * `approvalTimeout`, which waits forever because a lapsed approval DENIES a\n * commit and a lapsed question denies nothing.\n *\n * Exported so the two numbers can be reasoned about together rather than being\n * two literals in two packages.\n */\nconst DEFAULT_ASK_TIMEOUT_MS = 45_000;\n\nexport { ASK, ASK_QUESTION_ARG, DEFAULT_ASK_TIMEOUT_MS };\n\n/**\n * `ask`'s description, which every agent reads in the cached half.\n *\n * Here rather than in `driverkit/agent` and `mcp_core.py` for the reason\n * `GOTO_DESCRIBE` is: this verb is the core's own, the two renderers describe\n * what an APP declared, and a sentence about a core verb written twice in two\n * languages is a sentence that drifts.\n *\n * THREE THINGS IT HAS TO SAY, and the third is the one the whole mechanism\n * stands on. What the verb is for: an instruction you cannot carry out without\n * guessing. What the three refusals mean, since the difference between \"nobody\n * answered\" and \"there is nobody\" decides whether asking again is worth a turn.\n * And that **an answer is not an approval** — because the single most likely\n * misuse of this verb is to ask \"shall I accept these 3,412?\", read a yes, and\n * treat it as the consent the approval gate exists to collect. The core refuses\n * that structurally, and a model that has been told so does not spend a turn\n * discovering it.\n */\nconst ASK_DESCRIBE =\n \"ask the person a question and get their answer back as this call's result. For an \" +\n \"instruction you cannot carry out without guessing — two records match the name they \" +\n \"gave, nothing is selected and you do not know which rows they meant, the company they \" +\n \"named does not exist. Asking is better than guessing and far better than acting on a \" +\n \"guess.\\n\\n\" +\n \"It is not free and it is not unlimited: each question costs the person's attention, the \" +\n \"app may cap how many you get, and nothing else runs while one is open. So ask once, ask \" +\n \"the narrowest question that unblocks you, and put everything you already know into it — \" +\n \"`which Ada Duarte did you mean: the one at Acme or the one at Initech?` rather than \" +\n \"`which one?`.\\n\\n\" +\n \"**An answer is not permission.** A commit still goes to whoever approves commits in this \" +\n \"app, whatever the person told you here, and a `yes` to a question of yours authorises \" +\n \"nothing — so do not ask for approval with this, and do not report a commit as approved \" +\n \"because an answer sounded like a yes.\\n\\n\" +\n \"Refused as `ask-unanswered` when the question was put and nobody answered: the question \" +\n \"was seen by nobody who replied, nothing in the app changed, and asking again later or \" +\n \"more briefly may work. Refused as `nobody-to-ask` when there is no person on this run at \" +\n \"all — a scheduled job, a test — in which case stop asking: say what you need and what you \" +\n \"could not decide. Refused as `asks-spent` when the app's question allowance is gone, \" +\n \"which means the same thing for the rest of this run.\";\n\n/**\n * The documented size budgets, in characters.\n *\n * NOT arbitrary, and not a limit for its own sake. Apple's app skills ship\n * with exactly this pair — a description of at most 1024 characters on one\n * line, and a body of at most 10,000 — and a budget is worth copying because\n * of what the absence of one does: `instructions` had no documented bound, so\n * the honest answer to \"how much may I write?\" was \"nobody has said\", and the\n * field drifted toward being a README. Everything here is in the cached prefix\n * of every session of every user, which is exactly why it is cheap and exactly\n * why it is tempting: the cost is real, it is just paid once and invisibly, so\n * a number is the only thing that makes anybody weigh it. The second cost is\n * the one a budget really guards: text in the prefix competes with the verb\n * list for a model's attention, and a thousand words about the app is a\n * thousand words read instead of the tool that commits data.\n *\n * `describe` is one line because it is a label a model chooses on, not a\n * paragraph it reasons from — selection between flows is made on the\n * description and not on the individual steps, which is the finding this whole\n * field is shaped by.\n *\n * New fields throw when they exceed these; `instructions`, which predates\n * having a budget at all, warns. See `mount`.\n */\nexport const SIZE_LIMITS = {\n /** `FlowSpec.describe` and `ScreenSpec.describe`: one line, at most this.\n * Also `FlowStep.skipWhen`, which is a one-line condition for the same\n * reason — it is read beside the step, not reasoned from. */\n describe: 1024,\n /** A whole flow's steps — every `section`, `verb`, `hint` and `skipWhen`\n * together. Everything rendered into the prefix counts, so moving a sentence\n * out of a `hint` and into a `skipWhen` buys no room. */\n body: 10_000,\n /** `MountOptions.instructions`. Warned about rather than refused. */\n instructions: 10_000,\n} as const;\n\n/**\n * RFC 6570 simple string expansion, and nothing else.\n *\n * `\"#/companies/{slug}\"` with `{ slug: \"acme-industrial\" }` becomes\n * `\"#/companies/acme-industrial\"`. A variable with no value expands to\n * nothing, which is the spec's own rule for an undefined variable.\n *\n * WHY A HAND-ROLLED SUBSET RATHER THAN THE LIBRARY. `uri-templates` is in the\n * repository and is used in the tests as the oracle this is checked against,\n * but the core promises zero runtime dependencies, and that promise is not\n * decoration: the worked example loads these very `.ts` files into a browser\n * through a type-stripper with no bundler and no `node_modules`, so one bare\n * `import \"uri-templates\"` in here stops the demo from running at all. The\n * SYNTAX is the spec's, which is the part that matters — an author can hand\n * the same template to any RFC 6570 implementation, and a template is never\n * rewritten to suit us — and a route is level 1, so what the core implements\n * is the level a route needs. The same argument as `ArgSpec` being a hand-\n * rolled subset of JSON Schema.\n *\n * Expansion is percent-encoding of everything outside RFC 3986's unreserved\n * set, which is `encodeURIComponent` plus the five characters it leaves alone.\n * A slug with a slash in it must not silently become another path segment.\n */\nfunction expand(template: string, args: Record<string, Scalar>): string {\n return template.replace(/\\{([^{}]+)\\}/g, (_whole, name: string) => {\n const value = args[name];\n if (value === undefined || value === null) return \"\";\n return encodeURIComponent(String(value)).replace(\n /[!'()*]/g,\n (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n });\n}\n\n/**\n * A twelve-character hash of a string. Not cryptographic and does not need to\n * be; see `fingerprint`, which this was lifted out of unchanged so that the\n * plan token and the manifest version cannot drift into two hashes.\n */\nfunction hash12(shape: string): string {\n let h1 = 0x811c9dc5;\n let h2 = 0x01000193;\n for (let i = 0; i < shape.length; i++) {\n const c = shape.charCodeAt(i);\n h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;\n h2 = Math.imul(h2 + c, 0x85ebca6b) >>> 0;\n }\n return (h1.toString(16).padStart(8, \"0\") + h2.toString(16).padStart(8, \"0\")).slice(0, 12);\n}\n\n/**\n * An identity for a set of row ids, for `Snapshot.selectionId`.\n *\n * Exported, and that is the point of it existing rather than being left to\n * each app. The core mints the plan token so an app cannot get the token's\n * binding wrong; this is the other half of the same argument, because an app\n * hand-rolling the identity can get it wrong in exactly the way that matters —\n * a hash over `selected.join(\",\")` is order-DEPENDENT, so clicking two rows in\n * the other order reads as a different selection and every commit is refused,\n * and a hash over the count alone reads as the same selection when one row has\n * been swapped for another, which is the failure the identity exists to catch.\n *\n * Order-independent, so the same membership gives the same string however it\n * was built. The size is folded in as well, so an empty selection is distinct\n * from one whose hashes happen to cancel.\n *\n * One pass over the ids, which is cheap for the hundreds an on-screen selection\n * holds. An app whose selection runs to tens of thousands should keep a running\n * value instead and not call this inside `visible()`, which runs on every call.\n */\nexport function selectionId(ids: Iterable<string>): string {\n let xor = 0;\n let sum = 0;\n let n = 0;\n for (const id of ids) {\n let h = 0x811c9dc5;\n for (let i = 0; i < id.length; i++) h = Math.imul(h ^ id.charCodeAt(i), 0x01000193) >>> 0;\n xor = (xor ^ h) >>> 0;\n sum = (sum + h) >>> 0;\n n += 1;\n }\n return `${n.toString(36)}-${xor.toString(16).padStart(8, \"0\")}${sum.toString(16).padStart(8, \"0\")}`;\n}\n\n/** Build the value a verb returns to decline. Exported because app code\n * sometimes wants to refuse from a helper rather than inline. */\nexport function refusal(reason: string, hint?: string): Refusal {\n return { __driverkit: REFUSAL, reason, ...(hint === undefined ? {} : { hint }) };\n}\n\nfunction isRefusal(v: unknown): v is Refusal {\n return typeof v === \"object\" && v !== null && (v as Refusal).__driverkit === REFUSAL;\n}\n\n/**\n * Validate one argument against its spec.\n *\n * Returns a reason string, or null when the value is acceptable. Kept separate\n * from `call` so the failure messages can be unit-tested without mounting\n * anything, and so they read the same whether the caller was a chatbot or a\n * relay frame — a model that learns one phrasing of \"bad argument\" should not\n * meet a different phrasing depending on how it connected.\n */\nexport function checkArg(name: string, spec: ArgSpec, value: Scalar | undefined): string | null {\n if (value === undefined || value === null) {\n return spec.optional ? null : `missing argument \\`${name}\\``;\n }\n if (typeof value !== spec.type) {\n return `argument \\`${name}\\` wants a ${spec.type}, got ${typeof value}`;\n }\n if (spec.oneOf && !spec.oneOf.includes(value)) {\n // The accepted values are listed rather than counted. An agent that is\n // told \"invalid value\" has to guess again; one that is told the set can\n // fix the call on the next turn without another read.\n return `argument \\`${name}\\` must be one of ${spec.oneOf.map((v) => JSON.stringify(v)).join(\", \")}`;\n }\n return null;\n}\n\n/**\n * Make an app drivable.\n *\n * ```ts\n * const driver = mount({\n * app: \"Contacts\",\n * verbs: [\n * { name: \"open\", kind: \"read\", describe: \"open one contact\",\n * args: { id: { type: \"string\", describe: \"contact id\" } },\n * run: ({ id }) => router.push(`/contacts/${id}`) },\n *\n * // A describe/commit pair. The predicate is resolved inside the app,\n * // where the rows already are, so selecting a thousand contacts is one\n * // call and not a thousand -- and the count comes back before anything\n * // irreversible happens.\n * { name: \"select-where\", kind: \"describe\", describe: \"select every contact matching a filter\",\n * args: { where: { type: \"string\", describe: \"e.g. company=Acme\" } },\n * run: ({ where }) => store.select(where) },\n * // `consumes` is the half that makes the count a guarantee rather than\n * // advice: this cannot be called bare, only with the `plan` token the\n * // describe above handed back, so the set it touches is provably the set\n * // that was counted. See `Verb.consumes`.\n * { name: \"accept-selected\", kind: \"commit\", consumes: \"plan\",\n * describe: \"accept the current selection\",\n * refuses: [\"nothing-selected\"],\n * run: (_, ctx) => store.selected.length ? api.accept(store.selected)\n * : ctx.refuse(\"nothing-selected\") },\n * ],\n * visible: () => ({ where: \"contacts\", rev: store.rev, rows: store.onScreen(),\n * selectionId: selectionId(store.selected) }),\n * });\n * ```\n *\n * Nothing above is specific to a framework or a kind of app. `run` bodies call\n * whatever the app already has -- a store action, an API client, or, in an app\n * with neither, a click on a button the author marked themselves. That last\n * case is four lines the app writes -- the README shows them -- and the\n * library ships no reader for it, because a reader is a guess at a data shape\n * and guessing shapes is the thing this library exists not to do.\n */\nexport function mount(options: MountOptions): Driver {\n const verbs = new Map<string, Verb<any>>();\n let live = true;\n /** How to stop listening on `MountOptions.elsewhere`, if the channel gave us\n * one. Held here rather than beside the channel because `unmount` is at the\n * bottom of the file and a subscription nothing unsubscribes is a leak per\n * mounted driver -- which in a hot-reloading dev server is one per save. */\n let unlisten: (() => void) | undefined;\n\n // Thrown at mount, where a typo costs one stack trace at startup, and never\n // on a call path. A misspelt policy — `approve: \"unnattended\"`, or a truthy\n // object somebody meant as options — must not degrade to \"no policy\n // declared\": that is the one failure mode where the app believes it has a\n // gate and has not got one, which is worse than having no gate knowingly.\n const declared = options.approve;\n if (declared !== undefined && typeof declared !== \"function\" && declared !== \"unattended\") {\n throw new Error(\n `driverkit: \\`approve\\` must be a function or the string \"unattended\"; got ` +\n `${JSON.stringify(declared)}. A function is asked before every commit; \"unattended\" ` +\n `says out loud that commits on this driver run with nobody in front of them.`,\n );\n }\n const approveFn: ApprovalHook | undefined =\n typeof declared === \"function\" ? declared : undefined;\n /** What the app itself said, for all time. `connect()` reads this one. */\n const declaredPolicy: NonNullable<DriverApproval[\"declared\"]> =\n approveFn !== undefined ? \"hook\" : declared === \"unattended\" ? \"unattended\" : \"none\";\n\n /**\n * An approver installed after mount, by a dialog that lives in the page.\n *\n * `DriverApproval.adopt` carries the argument; this is the mechanism, and it\n * is two variables because releasing has to be safe. The hook is what the\n * gate calls; the token is who owns it, so a disposer handed out earlier\n * cannot unhook whoever adopted after it — which is the shape every\n * \"unsubscribe twice\" bug has.\n *\n * Only ever set when the app declared nothing. An app with its own `hook` is\n * already asked on every path, and `unattended` is an app saying commits\n * here run with nobody watching; installing a dialog over either of those\n * would be the library overruling a sentence somebody wrote.\n */\n let adopted: ApprovalHook | undefined;\n let adoptedBy: object | undefined;\n\n /** Who is asked right now, which is what a record has to say. See\n * `DriverApproval.policy`: `adopted` is deliberately not `hook`. */\n function policyNow(): DriverApproval[\"policy\"] {\n if (approveFn !== undefined) return \"hook\";\n if (declared === \"unattended\") return \"unattended\";\n return adopted !== undefined ? \"adopted\" : \"none\";\n }\n\n /**\n * Where the records go, or nowhere.\n *\n * Read once, into a `const`, because an app that passes no hook has to behave\n * byte-identically to one mounted before audit existed -- and the test for\n * that is `onAudit === undefined`, checked once per call rather than a field\n * lookup on an options object somebody might mutate afterwards. Not validated\n * at mount the way `approve` is: a misspelt policy makes an app believe it has\n * a gate it has not got, which is a safety claim, while a hook that is not a\n * function throws on the first call and is caught by `record` -- reported, the\n * call unaffected. The asymmetry is the point.\n */\n const onAudit: AuditHook | undefined = options.onAudit;\n\n /**\n * The verb an approval is open for, or null.\n *\n * The whole of point 3's strongest layer, and it is three lines because it\n * has to be: while this is set, `call()` refuses everything. It closes the\n * bypass for ANY approval UI rather than for ours — a host's own modal gets\n * it through `hold` — and it does not depend on an author remembering to\n * mark their Approve button with an attribute, which is the failure mode of\n * every opt-out mechanism. The gated call's own `run` is not blocked,\n * because the core clears this before it runs.\n */\n let pending: { verb: string; question: boolean } | null = null;\n\n // ---- the cost ceiling ---------------------------------------------------\n //\n // Two counters and a validation. `MountOptions.budget` carries the argument\n // for what is bounded and what was rejected; what is here is the mechanism.\n //\n // Validated at mount for the reason the approval policy is: a budget of 0 or\n // -1 means the app is never drivable, which nobody means, and discovering it\n // as `budget-spent` on the very first call is the one shape where an author\n // believes they configured a ceiling and have in fact configured a wall.\n const budget = options.budget;\n if (budget !== undefined) {\n for (const field of [\"calls\", \"commits\", \"asks\"] as const) {\n const limit = budget[field];\n if (limit === undefined) continue;\n if (!Number.isInteger(limit) || limit < 1) {\n throw new Error(\n `driverkit: \\`budget.${field}\\` is ${JSON.stringify(limit)}; it must be a positive ` +\n `integer, or absent to mean no ceiling. A budget of ${JSON.stringify(limit)} is not ` +\n `a tight ceiling, it is an app that refuses its first call — and it would do that ` +\n `with a \\`budget-spent\\` hint, which reads as a runaway rather than as a typo.`,\n );\n }\n }\n }\n /** Every `call()` that got past the approval lock, refused ones included.\n * Kept whether or not a ceiling was declared: `Driver.budget` reports it\n * either way, and a number somebody debugging a chatty app can read is\n * worth two increments. */\n let callsUsed = 0;\n /** `commit` verbs that actually reached `run`. */\n let commitsUsed = 0;\n /** Questions that actually reached a person. A question refused for a spent\n * allowance, or one the app answered `{ nobody: true }` to, is not counted:\n * neither took anybody's attention, which is the thing this number bounds. */\n let asksUsed = 0;\n /** When this allowance began, for `Budget.window`. `Date.now()` here means\n * \"this mount started one\", and a record read back below replaces it with\n * the moment the allowance it belongs to actually started. */\n let budgetSince = budget?.store === undefined ? 0 : Date.now();\n /**\n * Why the ceiling can no longer be kept, or null while it can be.\n *\n * The fail-closed flag, and the asymmetry it encodes is deliberate: a\n * transcript that cannot be stored costs a conversation, and a budget that\n * cannot be stored costs whatever an agent in a loop spends between now and\n * somebody noticing. So a store that cannot be read, or that throws on a\n * write, stops the AGENT — every later call is refused `budget-spent` with\n * this sentence in the hint — and does not stop the app, which the person at\n * the keyboard goes on using exactly as before.\n *\n * A string rather than a boolean because the two causes need different\n * sentences. \"I could not read your allowance\" is usually a private window\n * and is nobody's bug; \"I could not write it down\" is usually a full quota\n * and is the one where somebody has to act.\n */\n let budgetBroken: string | null = null;\n\n /**\n * Whether this driver is keeping its allowance in a store at all.\n *\n * A `store` with no ceiling declared enforces nothing: an app that passed one\n * and set neither `calls` nor `commits` has asked for nothing to be enforced,\n * and refusing its calls because its storage is blocked would be a ceiling\n * invented out of a field that set none.\n */\n const budgetKept =\n budget?.store !== undefined &&\n (budget.calls !== undefined || budget.commits !== undefined || budget.asks !== undefined);\n\n /**\n * Pull the stored allowance into the counters, taking the HIGHER figure.\n *\n * **Called at mount and again before every charge, and the re-read is what\n * makes \"one app, one ceiling\" true rather than aspirational.** Two tabs open\n * at once each hold their own copy of the counters, so a mount-time read\n * alone gave each of them the whole allowance — two tabs, two ceilings, which\n * is the reload bypass wearing a different hat. A tab that charges has to\n * look at what the others have spent.\n *\n * **Higher wins, never lower.** `localStorage` has no compare-and-swap, so\n * two tabs charging in the same millisecond can lose one increment — an\n * off-by-one, bounded, and vastly better than an off-by-a-factor-of-tabs. But\n * a read that answered with a SMALLER figure, from a tab that was behind or a\n * record somebody edited, must never hand an allowance back; `Math.max` is\n * the whole of that guarantee.\n *\n * `Number.isInteger` and `Math.max(0, ...)` because this came off a store the\n * person sitting there can edit. Tampering is explicitly out of scope — see\n * `Budget.store`, it is a cost control and not a security boundary — but a\n * negative or fractional figure is the one input that would make the ceiling\n * comparison never fire at all, and that is worth one guard.\n */\n function syncSpend(): void {\n if (!budgetKept || budgetBroken !== null) return;\n const read = budget!.store!.load();\n if (!read.ok) {\n budgetBroken =\n \"the stored record of this app's spend ceiling could not be read, so there is no way \" +\n \"to tell how much of the allowance is already spent. Rather than assume none of it is, \" +\n \"this driver refuses every call: an unreadable ceiling that let calls through would be \" +\n \"no ceiling at all. The app itself still works normally for the person at the keyboard.\";\n return;\n }\n if (read.spent === null) return;\n const record = read.spent;\n // Two reasons to throw a record away, both host-held and neither reachable\n // by the agent. See `Budget.epoch` and `Budget.window`.\n if ((record.epoch ?? undefined) !== budget!.epoch) return;\n if (budget!.window !== undefined && Date.now() - record.since >= budget!.window) return;\n if (Number.isInteger(record.calls)) callsUsed = Math.max(callsUsed, record.calls);\n if (Number.isInteger(record.commits)) commitsUsed = Math.max(commitsUsed, record.commits);\n // Absent on a record written before questions were counted, which is read\n // as 0 rather than as a reason to throw the record away: see\n // `BudgetRecord.asks`. The other two numbers in it are still true, and\n // discarding an allowance because a field was added would hand every app\n // with a store a fresh ceiling on upgrade.\n if (Number.isInteger(record.asks)) asksUsed = Math.max(asksUsed, record.asks!);\n if (Number.isFinite(record.since)) budgetSince = record.since;\n }\n\n /**\n * Write the counters down, and fail closed if that cannot be done.\n *\n * Called after each increment rather than on an interval or at unload. The\n * event this exists for is a page that goes away without warning — a reload,\n * a crash, a `goto` — so any scheme that batches is a scheme that loses\n * exactly the calls it was built to remember.\n *\n * The throw is caught HERE and not left to the caller, because the call it is\n * about has already happened: the verb ran, the data moved, and failing the\n * `Result` now would tell an agent nothing happened when something did. What\n * a failed write changes is the FUTURE — from here on nothing is allowed,\n * because nothing more can be accounted for.\n */\n function rememberSpend(): void {\n if (!budgetKept || budgetBroken !== null) return;\n try {\n budget!.store!.save({\n calls: callsUsed,\n commits: commitsUsed,\n // Written whatever the app declared, like the two above, so that adding\n // `budget.asks` later does not have to treat every existing record as\n // having asked nothing since the epoch.\n asks: asksUsed,\n since: budgetSince,\n ...(budget!.epoch === undefined ? {} : { epoch: budget!.epoch }),\n });\n } catch {\n budgetBroken =\n \"this app's spend ceiling could not be written down — storage is full, or blocked — so \" +\n \"from here on there is no way to carry the count across a page load. Rather than let \" +\n \"an uncounted call through, this driver refuses every later one. The app itself still \" +\n \"works normally for the person at the keyboard; somebody has to free up storage or \" +\n \"lift the ceiling.\";\n }\n }\n\n // At mount, so `Driver.budget` reports the true figure to a panel before a\n // single call is made -- a settings view that said \"0 of 200\" on a page whose\n // allowance was half spent would be the panel lying about the one number it\n // is there to show.\n syncSpend();\n\n for (const verb of options.verbs as Verb<any>[]) {\n if (verbs.has(verb.name)) {\n // Thrown, not refused: two verbs sharing a name is a programming error\n // that makes one of them permanently unreachable, and it should fail at\n // mount rather than silently shadow on the first call.\n throw new Error(`driverkit: two verbs are both named \\`${verb.name}\\``);\n }\n\n // Thrown at mount for the same reason the duplicate name above is: both are\n // static facts about the verb surface, both make the app permanently\n // ambiguous to every agent that reads the manifest, and mount runs at\n // startup rather than on a refusal path — so failing here costs a developer\n // one stack trace and costs a running app nothing. The call-time check\n // below, which can only fire while an app is refusing, is a warning\n // instead; see `warn`.\n if (RESERVED.has(verb.name)) {\n throw new Error(\n `driverkit: a verb may not be named \\`${verb.name}\\`: that is a reserved refusal slug ` +\n `(${RESERVED_REFUSALS.join(\", \")}). An agent could not tell a refusal from this verb ` +\n `apart from a refusal about it.`,\n );\n }\n\n // Thrown at mount, the way a duplicate name is, and for the same reason: it\n // is a static fact about the surface that makes the verb permanently\n // uncallable. `screen: []` says the verb works on no screen at all, which\n // no author means — it is what a `.filter()` over a list of screens\n // produces when the list was empty, or what a config file hands over when\n // a key is missing. The author who meant \"anywhere\" leaves the field out,\n // and that is said here rather than guessed at, because guessing either\n // way is wrong: treating it as \"anywhere\" silently makes a scoped verb\n // global, and treating it as \"nowhere\" leaves a verb in everybody's cached\n // prefix that can only ever be refused.\n if (Array.isArray(verb.screen) && verb.screen.length === 0) {\n throw new Error(\n `driverkit: the verb \\`${verb.name}\\` declares \\`screen: []\\`, which says it works on ` +\n `no screen at all. Omit \\`screen\\` to mean \"anywhere\", or name the screens it works ` +\n `on.`,\n );\n }\n\n // THE ONE KIND AN APP MAY NOT DECLARE, and this throw is the structural\n // half of \"a question is not consent\".\n //\n // Every other kind is a claim about what the app's own code does, and the\n // app is the only thing that can make it. `ask` is a claim about a PERSON,\n // and the core is the only thing that can make it good: it owns the lock\n // that stops the agent acting while a question is open, the deadline that\n // keeps \"nobody answered\" a fact rather than the relay's unknown outcome,\n // the allowance, and the audit row. A verb wearing the kind with none of\n // those behind it would be a question nothing counted and nothing locked --\n // and the first thing anybody would build with it is a confirmation\n // dialog, whose yes would then be the one thing `MountOptions.approve`\n // exists to be asked for. So the kind is the core's and the hook is the\n // app's; see `MountOptions.ask`.\n //\n // Thrown rather than warned because it is a safety claim being made\n // falsely, which is the same grounds the misspelt `approve` policy throws\n // on. Additive, because no app can already be declaring it: it was not a\n // value of `VerbKind` until this feature, so nothing that compiles today\n // can hit this.\n if (verb.kind === ASK) {\n throw new Error(\n `driverkit: the verb \\`${verb.name}\\` declares \\`kind: \"ask\"\\`, which only the core ` +\n `may mint. A question has to be locked, deadlined, counted against ` +\n `\\`budget.asks\\` and recorded, and none of that can be true of a verb body — a ` +\n `verb wearing this kind would be a question nothing counted, and a \"yes\" to it ` +\n `would look like the approval \\`approve\\` exists to collect. Pass ` +\n `\\`ask: ({ question }) => …\\` to \\`mount()\\` and the core offers the \\`ask\\` verb ` +\n `itself; declare this verb with the kind it really has, or leave \\`kind\\` off.`,\n );\n }\n\n // Thrown at mount, like the two above, and for the same reason: it is a\n // static fact about the surface that an agent reads from the manifest and\n // caches. `consumes` on anything but a `commit` is an authoring mistake\n // with a cost that is easy to miss -- a `describe` that demands a token\n // makes the pairing circular, because the only thing that can mint one is\n // a `describe`, and a `read` that demands one teaches an agent to go and\n // fetch a receipt before it is allowed to look at anything. A token is a\n // claim about data that is about to move; a verb that has promised no data\n // moves has nothing to make the claim about.\n //\n // A misspelt value is caught here too. `consumes: \"plans\"` would otherwise\n // be falsy to no check and truthy to the fingerprint, so the app would\n // believe it had the guarantee, the version would have moved, and every\n // commit would run bare -- the one failure mode worth a stack trace at\n // startup.\n if (verb.consumes !== undefined) {\n if (verb.consumes !== \"plan\") {\n throw new Error(\n `driverkit: the verb \\`${verb.name}\\` declares \\`consumes: ` +\n `${JSON.stringify(verb.consumes)}\\`; the only value is \"plan\". A verb that asks ` +\n `for something the core does not mint would run with no check at all, which is ` +\n `the one outcome worse than not asking.`,\n );\n }\n if (verb.kind !== \"commit\") {\n throw new Error(\n `driverkit: the verb \\`${verb.name}\\` declares \\`consumes: \"plan\"\\` and ` +\n `${verb.kind ? `\\`kind: \"${verb.kind}\"\\`` : \"no `kind`\"}. A plan token is the ` +\n `receipt for a count that a \\`describe\\` reported, so only a \\`commit\\` can ` +\n `consume one: a \\`describe\\` that demanded one could never be called, since a ` +\n `\\`describe\\` is the only thing that mints them.`,\n );\n }\n }\n\n for (const slug of verb.refuses ?? []) {\n if (RESERVED.has(slug)) {\n throw new Error(\n `driverkit: the verb \\`${verb.name}\\` declares the reserved refusal \\`${slug}\\` ` +\n `(reserved: ${RESERVED_REFUSALS.join(\", \")}). Reserved slugs say where a call ` +\n `stopped, not what your app decided; pick a name from your own vocabulary.` +\n // Named, because this is the one reserved slug an app may already\n // be using: it was an app's invention before it was the core's, and\n // an author who hits this wants the replacement rather than a rule.\n // At mount, where it costs one stack trace at startup, and never on\n // a refusal path.\n (slug === WRONG_SCREEN\n ? ` \\`${WRONG_SCREEN}\\` is now the core's: put \\`screen: \"<the screen this verb ` +\n `is on>\"\\` on the verb, give \\`Snapshot.screen\\` the screen that is live, and ` +\n `the refusal — naming both screens — comes back without this guard.`\n : \"\"),\n );\n }\n }\n\n verbs.set(verb.name, verb);\n }\n\n // ---- the app's map, and the one verb the core implements ---------------\n //\n // After the verb loop, because the reserved `goto` is a verb like any other\n // and has to be checked for a collision against the app's own; before the\n // manifest, because it has to appear in it. See `ScreenSpec`.\n const screens = options.screens ?? [];\n const byScreen = new Map<string, ScreenSpec>();\n\n /** The union of every screen's declared args, hoisted onto `goto`.\n *\n * A verb takes `Record<string, Scalar>` — no nested objects, because an\n * argument that cannot survive JSON cannot cross the relay — so `goto`\n * cannot take `{ screen, args: {...} }`. The arguments are flattened\n * instead: every name any screen declares becomes one optional argument of\n * `goto`, which keeps the schema static and cacheable, and the core checks\n * the ones THIS screen needs at call time. Optional in the schema because\n * whether an argument is required depends on which screen was asked for,\n * and a schema that said otherwise would make a client reject\n * `goto(\"contacts\")` for want of a contact id. */\n const screenArgs: Record<string, ArgSpec> = {};\n\n for (const screen of screens) {\n if (typeof screen.id !== \"string\" || screen.id === \"\") {\n throw new Error(\n `driverkit: a screen in \\`screens\\` has no \\`id\\`. The id is the string ` +\n `\\`Verb.screen\\` and \\`Snapshot.screen\\` are compared against, so a screen without ` +\n `one cannot be matched, navigated to or refused.`,\n );\n }\n if (byScreen.has(screen.id)) {\n // Thrown at mount, like a duplicate verb name, and for the same reason:\n // two screens with one id makes one of them permanently unreachable, and\n // the app's map — the thing an agent caches — is ambiguous about which.\n throw new Error(`driverkit: two screens are both named \\`${screen.id}\\``);\n }\n if (screen.describe !== undefined && screen.describe.length > SIZE_LIMITS.describe) {\n throw new Error(\n `driverkit: the screen \\`${screen.id}\\` has a \\`describe\\` of ` +\n `${screen.describe.length} characters; the budget is ${SIZE_LIMITS.describe}. ` +\n `See \\`SIZE_LIMITS\\`: this text is in the cached prefix of every session of every ` +\n `user, so a paragraph here is a paragraph everybody pays to carry.`,\n );\n }\n byScreen.set(screen.id, screen);\n\n for (const [argName, spec] of Object.entries(screen.args ?? {})) {\n if (argName === GOTO_SCREEN_ARG) {\n throw new Error(\n `driverkit: the screen \\`${screen.id}\\` declares an argument named ` +\n `\\`${GOTO_SCREEN_ARG}\\`, which is the name \\`goto\\` uses for the screen itself. ` +\n `Rename it — \\`id\\` or \\`slug\\` is usually what it is.`,\n );\n }\n const already = screenArgs[argName];\n if (already && JSON.stringify(already) !== JSON.stringify({ ...spec, optional: true })) {\n // Thrown rather than resolved in favour of one of them. The two specs\n // become one optional argument of `goto`, so disagreeing describes\n // would put one screen's sentence on the other screen's argument, and\n // disagreeing types would make one of the two screens impossible to\n // reach with a value the schema accepts.\n throw new Error(\n `driverkit: two screens declare the argument \\`${argName}\\` differently, and ` +\n `\\`goto\\` has one argument of that name for all of them. Give them the same ` +\n `\\`type\\`, \\`describe\\` and \\`oneOf\\`, or name them apart.`,\n );\n }\n // Optional, always: see `screenArgs`. The spec is otherwise the app's\n // own, `oneOf` included, so a wrong value is refused with the accepted\n // set listed.\n screenArgs[argName] = { ...spec, optional: true };\n }\n }\n\n if (screens.length && options.navigate === undefined) {\n // Said once, not thrown. Publishing a map and no way to walk it is a\n // legitimate thing to do — an agent that knows the screens exist and what\n // their addresses look like knows more than one that does not — but it is\n // the less likely of the two readings, and a `goto` that silently did not\n // appear is a bad half-hour. Refusing to mount would be worse: the map is\n // additive and useful on its own.\n warn(\n \"`screens` was declared without `navigate`, so the reserved `goto` verb is not \" +\n \"offered: the core has no router and cannot navigate on its own. Pass \" +\n \"`navigate: ({ screen, args, url }) => …` to get `goto`, or ignore this if the map \" +\n \"is all you wanted.\",\n );\n }\n\n if (screens.length && options.navigate !== undefined && verbs.has(GOTO)) {\n // The app claimed the name, so the app keeps it. The same rule as the\n // `rev` and `screen` arguments `driverkit/agent` hoists into every tool\n // schema: an app that declared its own wins, because the app's meaning\n // wins over ours. Said once all the same, because the author who hits this\n // is likelier to have two navigation verbs by accident than on purpose.\n warn(\n \"`screens` and `navigate` were both declared and this app also declares its own verb \" +\n \"named `goto`, so the core's reserved one is not added and `navigate` is never \" +\n \"called. The app's verb wins; drop one of the two.\",\n );\n }\n\n if (screens.length && options.navigate !== undefined && !verbs.has(GOTO)) {\n const navigate = options.navigate;\n const ids = [...byScreen.keys()];\n verbs.set(GOTO, {\n name: GOTO,\n // A `read` by the ladder's own definition, which is what the reworded\n // `read` comment was reworded for: `goto` changes no data and reports no\n // count, and what it does do — move the person's screen out from under\n // them — is what `read` now says out loud a read may do. A fourth kind\n // for navigation was the alternative and it was refused there: the three\n // kinds are a ladder of what a wrong call COSTS you, and a wrong\n // navigation costs exactly what a wrong read costs, which is that the\n // person has to look somewhere else.\n kind: \"read\",\n describe: GOTO_DESCRIBE,\n args: {\n [GOTO_SCREEN_ARG]: {\n type: \"string\",\n describe:\n \"the screen's id. Your instructions list every screen this app has and what \" +\n \"each one is for.\",\n // The accepted set, in the schema. Static — these are the names of\n // the app's screens, which are the same for every user forever — so\n // it is cacheable, and an id that is not one of them is refused by\n // the core's own argument check WITH THE WHOLE LIST in the reason,\n // which is a fix the model can make on its next turn without a read.\n oneOf: ids,\n },\n ...screenArgs,\n },\n // No `refuses`, and that is deliberate rather than an omission. Most of\n // what `goto` can say no to belongs to the app: the navigate hook is\n // where \"you may not open that screen\" and \"there is no such record\"\n // are said, in the app's own vocabulary, which the core cannot\n // enumerate. Declaring a partial list would turn `refuses` from\n // documentation into a check that warns at an app for refusing\n // correctly. The one slug the core itself originates is named in the\n // description instead.\n run: async (args: Record<string, Scalar>, ctx: VerbContext) => {\n const id = String(args[GOTO_SCREEN_ARG]);\n const screen = byScreen.get(id);\n if (!screen) {\n // Reached only if `oneOf` was bypassed -- a hand-written caller, or\n // a future core that stops checking. Named rather than left to\n // throw.\n return ctx.refuse(\n BAD_SCREEN_ARG,\n `no screen named \\`${id}\\`. This app has: ${ids.join(\", \")}.`,\n );\n }\n const supplied: Record<string, Scalar> = {};\n for (const [argName, spec] of Object.entries(screen.args ?? {})) {\n const value = args[argName];\n const reason = checkArg(argName, spec, value);\n if (reason) {\n // The screen is named as well as the argument. \"missing argument\n // `slug`\" on a verb that takes six optional arguments does not say\n // which screen wanted it, and the agent's next guess is another\n // refused call.\n return ctx.refuse(\n BAD_SCREEN_ARG,\n `the \\`${id}\\` screen needs its own arguments and ${reason}`,\n );\n }\n if (value !== undefined && value !== null) supplied[argName] = value;\n }\n const url = screen.url === undefined ? undefined : expand(screen.url, supplied);\n return navigate(\n { screen: id, args: supplied, ...(url === undefined ? {} : { url }) },\n ctx,\n );\n },\n });\n }\n\n // ---- the one question the core implements ------------------------------\n //\n // Added exactly as `goto` is: after the app's own verbs so a collision can be\n // seen, before the manifest because it has to appear in it, and only when the\n // app supplied the one function the core cannot write. See `MountOptions.ask`.\n //\n // The whole of the mechanism's behaviour is in `decide()`, not in the `run`\n // below. That is not an accident of where it fitted: the lock, the deadline,\n // the allowance and the `waitedMs` the record needs are all things `call()`\n // owns and a verb body cannot see. What `run` is for is the dead placeholder\n // underneath -- see the comment on it.\n const askFn = options.ask;\n if (askFn !== undefined && typeof askFn !== \"function\") {\n // Thrown at mount for the reason a misspelt `approve` is: an app that\n // believes it can ask and cannot has a verb in everybody's cached prefix\n // that only ever refuses, and the author finds out from a model's\n // transcript rather than from a stack trace.\n throw new Error(\n `driverkit: \\`ask\\` must be a function; got ${JSON.stringify(askFn)}. It is handed ` +\n `\\`{ question }\\` and returns the person's words, \\`{ answered: false }\\` when nobody ` +\n `replied, or \\`{ nobody: true }\\` when there is nobody on this path.`,\n );\n }\n if (askFn !== undefined && verbs.has(ASK)) {\n // The app claimed the name, so the app keeps it -- the `goto` rule, and the\n // `rev`/`screen` argument rule one layer up: the app's meaning wins over\n // ours. Said once all the same, because an author with two ways to ask the\n // same person the same thing has one of them by accident.\n warn(\n \"`ask` was declared and this app also declares its own verb named `ask`, so the \" +\n \"core's reserved one is not added and the `ask` hook is never called. The app's \" +\n \"verb wins; drop one of the two. Note that an app's own ask verb is gated, \" +\n \"counted and recorded as an ordinary verb and gets none of what the core's does: \" +\n \"no lock while the question is open, no deadline, no `budget.asks`.\",\n );\n }\n /** Whether the core's own `ask` is the verb under that name, so `decide` can\n * tell it from an app's verb that happens to be called the same thing. An\n * identity check and not a name check, because the name is the thing an app\n * is allowed to take. */\n let coreAsk: Verb<any> | undefined;\n if (askFn !== undefined && !verbs.has(ASK)) {\n coreAsk = {\n name: ASK,\n kind: ASK,\n describe: ASK_DESCRIBE,\n // No `refuses`. The three slugs this verb can come back with are all\n // reserved, and `refuses` may not name a reserved slug -- which is the\n // right answer rather than an awkward one: they say where the question\n // stopped and not what the app decided, so they belong in the reserved\n // list and are named in the description instead. The same shape as\n // `goto`, whose one core refusal is also described rather than declared.\n args: {\n [ASK_QUESTION_ARG]: {\n type: \"string\",\n describe:\n \"what to ask, in your own words, as one short question. Put everything you \" +\n \"already know into it so the person can answer in a word.\",\n },\n },\n /**\n * The dead placeholder, and it is load-bearing.\n *\n * Lifted straight from the pattern that works elsewhere: a tool whose\n * body returns a plain, honest \"no response was recorded for this\", so\n * that if the mechanism above it is ever skipped the model is told the\n * truth instead of reading an `ok` for a question nobody saw. `decide()`\n * answers every `ask` before `run` is reached, so **this should be\n * unreachable** — which is exactly why it has to say something a model\n * can act on rather than throw or return nothing.\n *\n * It refuses rather than reporting, because `ok — …` is the shape an\n * ANSWER has and a placeholder that borrowed it would be a fabricated\n * answer. `nobody-to-ask` is the honest slug: no question was put to\n * anybody.\n */\n run: (_args: Record<string, Scalar>, ctx: VerbContext) =>\n ctx.refuse(\n NOBODY_TO_ASK,\n \"no question was put to anybody: this app offers the `ask` verb and the call did \" +\n \"not reach the person. Nothing in the app changed and no answer was recorded. \" +\n \"Do not treat this as a reply, and do not ask again — say what you needed to \" +\n \"know and what you could not decide without it.\",\n ),\n };\n verbs.set(ASK, coreAsk);\n }\n\n // ---- the app's recipes --------------------------------------------------\n const flows = options.flows ?? [];\n const flowIds = new Set<string>();\n for (const flow of flows) {\n if (typeof flow.id !== \"string\" || flow.id === \"\") {\n throw new Error(\"driverkit: a flow in `flows` has no `id`\");\n }\n if (flowIds.has(flow.id)) {\n throw new Error(`driverkit: two flows are both named \\`${flow.id}\\``);\n }\n flowIds.add(flow.id);\n if (typeof flow.describe !== \"string\" || flow.describe === \"\") {\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` has no \\`describe\\`. It is the field a model ` +\n `chooses a flow on — the selection is made on the description and not on the ` +\n `individual steps — so a flow without one is a flow nothing will pick.`,\n );\n }\n if (flow.describe.length > SIZE_LIMITS.describe || /[\\n\\r]/.test(flow.describe)) {\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` must have a one-line \\`describe\\` of at most ` +\n `${SIZE_LIMITS.describe} characters (got ${flow.describe.length}` +\n `${/[\\n\\r]/.test(flow.describe) ? \", with a line break\" : \"\"}). See \\`SIZE_LIMITS\\`.`,\n );\n }\n if (!Array.isArray(flow.steps) || flow.steps.length === 0) {\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` has no \\`steps\\`. A flow with no steps is a ` +\n `sentence, and \\`instructions\\` is where a sentence goes.`,\n );\n }\n // `skipWhen` is in the sum because it is rendered into the same cached\n // prefix as the hint it was lifted out of. A flow that moved a sentence\n // from one field to the other must not be able to grow a budget by doing\n // it.\n const body = flow.steps\n .map((s) => `${s.section ?? \"\"}${s.verb}${s.hint}${s.skipWhen ?? \"\"}`)\n .join(\"\");\n if (body.length > SIZE_LIMITS.body) {\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` has ${body.length} characters of steps; the ` +\n `budget is ${SIZE_LIMITS.body}. See \\`SIZE_LIMITS\\`.`,\n );\n }\n for (const step of flow.steps) {\n // Thrown at mount, the way a duplicate verb name is. A recipe citing a\n // verb nobody implemented is a dead end whose only symptom is an agent\n // halfway through a job meeting `unknown-verb` -- after the navigation\n // and before the commit, which is the worst place to find out. Checked\n // against the map AFTER `goto` was added to it, so a flow may name the\n // reserved verb like any other.\n if (!verbs.has(step.verb)) {\n const known = [...verbs.keys()].sort().join(\", \");\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` names the verb \\`${step.verb}\\`, which this ` +\n `app does not have. known: ${known}. A flow is a recipe an agent reads and ` +\n `follows with real verbs, so a step naming one that does not exist is a dead ` +\n `end it would find halfway through the job.`,\n );\n }\n if (typeof step.hint !== \"string\" || step.hint === \"\") {\n throw new Error(\n `driverkit: the step \\`${step.verb}\\` of the flow \\`${flow.id}\\` has no \\`hint\\`. ` +\n `The verb's own \\`describe\\` already says what the verb does; the hint is what ` +\n `to do with it here, which is the part that makes this a recipe.`,\n );\n }\n // An empty `skipWhen` is the one that has to be caught, because the field\n // being PRESENT is what makes a step optional: a step marked skippable\n // with no stated condition tells a model it may drop a step whenever it\n // likes, which is the opposite of what an author who typed the field\n // meant. The length and the newline are the `describe` rule, for the\n // `describe` reason -- it is a one-line condition rendered beside the\n // step, not a paragraph to reason from.\n if (step.skipWhen !== undefined) {\n if (typeof step.skipWhen !== \"string\" || step.skipWhen === \"\") {\n throw new Error(\n `driverkit: the step \\`${step.verb}\\` of the flow \\`${flow.id}\\` has an empty ` +\n `\\`skipWhen\\`. Present means this step may be skipped, so the field has to say ` +\n `WHEN — \"the person already named the company\". A skippable step with no ` +\n `condition is an invitation to drop it for no reason.`,\n );\n }\n if (step.skipWhen.length > SIZE_LIMITS.describe || /[\\n\\r]/.test(step.skipWhen)) {\n throw new Error(\n `driverkit: the \\`skipWhen\\` on the step \\`${step.verb}\\` of the flow ` +\n `\\`${flow.id}\\` must be one line of at most ${SIZE_LIMITS.describe} characters ` +\n `(got ${step.skipWhen.length}` +\n `${/[\\n\\r]/.test(step.skipWhen) ? \", with a line break\" : \"\"}). ` +\n `See \\`SIZE_LIMITS\\`.`,\n );\n }\n }\n }\n\n // THE ONE PIECE OF DATA FLOW BETWEEN STEPS, CHECKED WHERE IT CAN BE SEEN.\n //\n // A `commit` that declares `consumes: \"plan\"` can only be called with the\n // token a `describe` returned beside its count. So a flow that reaches such\n // a step without an earlier `describe` step is a recipe whose only possible\n // ending is `stale-plan`: the agent follows it, arrives at the commit with\n // no token, and is refused -- after the navigation and before anything\n // moves, which is the same worst moment a step naming a missing verb is\n // found at, and the same reason this throws rather than waits.\n //\n // Statically visible and therefore the core's job: the step order is fixed,\n // the verbs' `kind` and `consumes` are declared, and nothing per-user is\n // involved. It is also the whole of what a flow can honestly say about\n // values crossing steps -- see the note under `FlowStep` for why there is\n // no `from: \"step2.slug\"` to go with it.\n //\n // It throws on `flows`, which is new, by the rule stated at the\n // `instructions` budget above: a new throw on an old field would break an\n // app that mounted yesterday, and a new one cannot have mounted yet.\n let minted: string | undefined;\n for (const step of flow.steps) {\n const verb = verbs.get(step.verb)!;\n if (verb.consumes === \"plan\" && minted === undefined) {\n throw new Error(\n `driverkit: the flow \\`${flow.id}\\` reaches \\`${step.verb}\\`, which consumes a ` +\n `plan, with no earlier \\`describe\\` step to mint one. A plan token comes from ` +\n `the \\`describe\\` verb that counted the selection, so an agent following this ` +\n `recipe arrives at the commit with nothing to pass and is refused ` +\n `\\`stale-plan\\`. Put the counting step in the flow.`,\n );\n }\n if (verb.kind === \"describe\") minted = step.verb;\n }\n }\n\n if (options.instructions && options.instructions.length > SIZE_LIMITS.instructions) {\n // Warned and not thrown, which is the one inconsistency in here and it is\n // deliberate. `instructions` existed before it had a budget, so an app\n // that mounted yesterday with a very long briefing must still mount today:\n // a new throw on an old field is exactly the kind of change the additive\n // rule forbids. `screens` and `flows` are new, nothing can already be over\n // their budget, and so they throw.\n warn(\n `\\`instructions\\` is ${options.instructions.length} characters; the documented budget ` +\n `is ${SIZE_LIMITS.instructions}. It is sent in the cached prefix of every session, ` +\n `so the cost is paid once per person rather than once per turn — but a briefing ` +\n `this long is competing with the verbs for the model's attention. See \\`SIZE_LIMITS\\`.`,\n );\n }\n\n // ALL OR NONE, said once at mount.\n //\n // An eval found the hole this exists to name. The worked example declared\n // `consumes: \"plan\"` on `accept-selected` and left `decline-selected` bare,\n // and an agent asked for a job the app could not do improvised its way to the\n // bare one: 403 rows changed status with no count read and nothing gated. The\n // verb an agent reaches for when it is off its intended path is the\n // least-declared one, so a guarantee is only as strong as its weakest\n // sibling.\n //\n // WHY A WARNING AND NOT A THROW. Because adopting this field one verb at a\n // time is a legitimate state to be in for the length of an afternoon, and an\n // app that cannot mount halfway through its own migration is an app whose\n // author reverts the first half. The author who is told, once, at startup, in\n // the words of the two verbs involved, fixes it; a throw would be a change\n // that breaks an app for declaring a safety field on one verb, which teaches\n // the opposite lesson.\n //\n // WHAT IT CAN AND CANNOT SEE. The signal is a `commit` with NO ARGUMENTS: a\n // verb that takes nothing can only be acting on ambient state, which is the\n // selection or the open record, which is the thing a plan is a receipt for.\n // Deliberately narrow. `set-setting(name, value)` names what it changes and\n // must not be nagged about; `set-status(status)`, which changes the one record\n // whose screen is open, has an argument and will NOT be caught — a false\n // negative that is accepted on purpose, because the honest alternative is\n // warning about every commit with an argument, which is a warning on\n // everything and therefore a warning on nothing. The rule in `Verb.consumes`\n // is the thing to remember; this catches the shape that bit us.\n const consuming = [...verbs.values()].filter((v) => v.consumes === \"plan\");\n if (consuming.length) {\n const bare = [...verbs.values()].filter(\n (v) => v.kind === \"commit\" && v.consumes === undefined && v.args === undefined,\n );\n if (bare.length) {\n warn(\n `\\`${consuming[0]!.name}\\` consumes a plan but ${bare.map((v) => `\\`${v.name}\\``).join(\", \")} ` +\n `${bare.length > 1 ? \"are commits\" : \"is a commit\"} that takes no arguments and asks ` +\n `for no plan. A commit with no arguments acts on the selection, so an agent that ` +\n `wants to move rows without a counted plan will use that one — which makes the ` +\n `check on \\`${consuming[0]!.name}\\` advisory. Declare \\`consumes: \"plan\"\\` on every ` +\n `commit that acts on the selection, or on none of them.`,\n );\n }\n }\n\n // Computed once. The manifest is the half that gets cached by whoever is\n // driving, so it must not vary call to call; deriving it lazily on every\n // read would invite someone to fold `visible()` into it.\n const manifest: Manifest = {\n version: fingerprint(options.app, verbs, options.instructions, options.screens, options.flows),\n app: options.app,\n // The app's own briefing, in the half that is cached once. Omitted rather\n // than sent as an empty string, so an app that passes nothing produces the\n // manifest it produced before this field existed -- byte for byte, which\n // is what the fingerprint hashes.\n ...(options.instructions ? { instructions: options.instructions } : {}),\n verbs: [...verbs.values()].map((v) => ({\n name: v.name,\n describe: v.describe,\n ...(v.kind ? { kind: v.kind } : {}),\n // Copied through untouched and never read by anything in here. `at` is a\n // hint for whoever is drawing the run, not a way to find an element; see\n // `Verb.at`.\n ...(v.at ? { at: v.at } : {}),\n // `screen` IS read in here, by `call` below, and it is still copied for\n // the same reason `kind` is: the manifest is the only description of this\n // verb an agent gets, and \"works only on the companies list\" is a fact it\n // should read in the cached half rather than discover by being refused.\n //\n // Copied in the shape the app declared, a string staying a string rather\n // than being normalised to a one-element array. Every client reading\n // `verbs[].screen` today reads it as a string, and normalising would move\n // every single-screen app's manifest -- and its fingerprint -- for a\n // change that app did not make.\n ...(v.screen ? { screen: v.screen } : {}),\n ...(v.reversible ? { reversible: v.reversible } : {}),\n // Copied for the reason `screen` is, and more urgently: `screen` tells an\n // agent WHERE a verb can be called and this tells it HOW. A client that\n // did not see this renders a tool with no `plan` property and no sentence\n // about the pairing, so the model calls the commit bare and is refused\n // every time, with nothing in the half it cached to explain the fix.\n ...(v.consumes ? { consumes: v.consumes } : {}),\n ...(v.args ? { args: v.args } : {}),\n ...(v.refuses ? { refuses: v.refuses } : {}),\n })),\n // The map and the recipes, copied through as declared. Both omitted\n // entirely when the app declared neither, so the manifest of an app that\n // uses neither is the document it was before these fields existed -- byte\n // for byte, which is what the fingerprint hashes and what every stored\n // `Manifest.version` out there was computed from.\n ...(options.screens ? { screens: options.screens } : {}),\n ...(options.flows ? { flows: options.flows } : {}),\n };\n\n // ---- what another tab did ----------------------------------------------\n //\n // Six lines of state and a sentence, and the sentence is the point: see\n // `ElsewhereChannel` for the hole, and `MountOptions.elsewhere` for what this\n // does and does not buy.\n\n const channel: ElsewhereChannel | undefined = options.elsewhere;\n\n /** This driver's identity on the channel, so it can ignore its own notices.\n * A `BroadcastChannel` does not echo to the sender, but a websocket relay\n * fanning out to every subscriber does, and a channel that poisoned the tab\n * that committed would refuse the second half of every two-step job. */\n const elsewhereId = `dke${(elsewhereSeq += 1)}.${Math.random().toString(36).slice(2)}`;\n\n /**\n * The notice this driver is sitting on, or null.\n *\n * `at` is the `rev` this app was showing when the notice arrived, and it is\n * the whole expiry rule: the notice is outstanding for exactly as long as\n * this app's own `rev` has not moved. One notice, not a list — a second\n * commit elsewhere while the first is still outstanding tells an agent\n * nothing new, and the repair is the same one.\n */\n let elsewhere: { verb: string; at: number } | null = null;\n\n /** Said to the model, in the snapshot's own `note`, for as long as the notice\n * stands. The one sentence that turns a silent lie into a visible one. */\n const elsewhereNote = (verb: string): string =>\n `WARNING: another tab of this app committed \\`${verb}\\` after this screen was read, so ` +\n `the rows and the rev above may be out of date even though the rev has not moved. ` +\n `A commit here is refused as \\`changed-elsewhere\\` until this tab refreshes.`;\n\n /**\n * `visible()`, plus the notice if there is one.\n *\n * EVERY read goes through here -- `driver.snapshot()`, the snapshot on every\n * `Result`, the one an approval hook is handed, the one `connect()` pushes to\n * the relay -- because a warning that reached some of those and not others\n * would be a guarantee that holds on one path, which is the defect\n * `MountOptions.approve` was moved into the core to fix.\n *\n * Carried in `note`, which is already \"anything else the agent needs and the\n * rows cannot carry\", and which BOTH renderers already print. The\n * alternatives were a new field on `Snapshot` -- app-published, and this is\n * the core speaking, not the app -- or a second channel to the model that\n * only one of the two renderers knew about.\n *\n * The app's own `note` is kept and appended to, never replaced: the app may\n * be saying something the person needs and this is not more important than\n * that.\n *\n * The clear lives here rather than in a timer because this is the only place\n * the core learns what `rev` is now. An app that never reads is an app\n * nothing is being driven in.\n */\n function read(): Snapshot {\n const snap = options.visible();\n if (elsewhere === null) return snap;\n if (snap.rev !== elsewhere.at) {\n elsewhere = null;\n return snap;\n }\n const sentence = elsewhereNote(elsewhere.verb);\n return { ...snap, note: snap.note ? `${snap.note} ${sentence}` : sentence };\n }\n\n if (channel !== undefined) {\n const stop = channel.listen((notice: ElsewhereNotice) => {\n // Its own notice, or a malformed one. Dropped rather than warned about:\n // a channel shared with a future version of this library may carry\n // frames this one does not understand, and taking a driver out of service\n // over one is how a forward-compatible addition becomes an outage.\n if (!notice || typeof notice.verb !== \"string\" || notice.from === elsewhereId) return;\n if (!live) return;\n // `options.visible()` and not `read()`: this is where `at` is set, so\n // reading through the annotator would be asking what the note says in\n // order to decide what the note says.\n let now: number;\n try {\n now = options.visible().rev;\n } catch {\n // `visible()` threw outside a call, which is an app bug the core\n // cannot report to anybody here. The notice is kept against a rev\n // nothing can equal, so it stands until a successful read clears it --\n // the safe direction.\n now = Number.NaN;\n }\n elsewhere = { verb: notice.verb, at: now };\n });\n if (typeof stop === \"function\") unlisten = stop;\n }\n\n /**\n * Tell the other tabs a commit landed here.\n *\n * POSTED AFTER `run`, and only for a `commit`, and not when the verb refused.\n * Each of those three is a decision:\n *\n * - after rather than before, because a notice sent first is a claim about a\n * change that has not happened yet, and the sibling tab would clear it on\n * its next `rev` move -- possibly before the write landed;\n * - `commit` only, because `read` and `describe` promise no data moves and\n * announcing them would refuse every commit in every other tab for every\n * read anybody did, which is a warning on everything;\n * - not on an app refusal, because the app saying no means nothing moved.\n * A verb that THREW does get announced: it may have changed half a\n * selection, which is the same reason the plan token is burned on\n * entering `run` rather than on returning from it.\n */\n function announce(name: string): void {\n if (channel === undefined) return;\n try {\n channel.post({ verb: name, from: elsewhereId });\n } catch (err) {\n // A commit that already happened is not turned into a failure because\n // the announcement could not go out. Said once, in the app author's\n // console, because a channel that never delivers makes the whole check\n // silently absent -- which is the one thing this feature must not be.\n warn(\n `the \\`elsewhere\\` channel threw while announcing \\`${name}\\` ` +\n `(${err instanceof Error ? err.message : String(err)}), so other tabs of this app ` +\n `were not told. The commit itself ran.`,\n );\n }\n }\n\n\n // ---- the plan token ----------------------------------------------------\n //\n // One record per plan this driver has minted and not yet retired. The whole\n // mechanism is nine lines of state and it is worth saying what each piece is\n // load-bearing for.\n\n /** What a minted plan claimed, so a later commit can be checked against it\n * rather than against a hash that only proves the token's provenance. */\n interface Plan {\n /** The `describe` that minted it. Named back in the refusal, so an agent\n * told its plan is stale is told which call to make again. */\n verb: string;\n /** The `rev` the count was taken at. Named back in a refusal, and now ONLY\n * that: the expiry rule is `plansGoodAt`, which starts here and may be\n * carried forward over a read-only move. A carried plan still reports the\n * rev it was taken at, because that is the call the agent made and the\n * one it would have to make again. */\n rev: number;\n /** `Snapshot.selectionId` at that moment, or undefined in an app that does\n * not publish one. */\n selection?: string;\n /** The number the agent was shown and a person may have approved. Half of\n * the two numbers a `stale-plan` hint names. */\n count: number;\n /** Set when a commit has run on it. A plan is good for ONE commit. */\n used: boolean;\n }\n\n /**\n * A per-driver salt, folded into every token's hash.\n *\n * Two things make this necessary rather than decorative. Without it, two\n * drivers mounted from the same verb table and driven through the same calls\n * mint the SAME token string — the bound fields are identical — so a plan\n * from one app would be honoured by another, which is a receipt that proves\n * nothing about where it came from. And with the formula sitting in this file\n * in plain sight, an agent that wanted to skip the describe could compute a\n * token for itself; a salt it has never seen is what stops that being a\n * three-line bypass of the whole mechanism.\n *\n * `Math.random` rather than a crypto import, because the core has no\n * dependencies and this is not a security boundary: the thing on the other\n * end is a confused agent, not an attacker with the page's own privileges,\n * and anything that could read this variable could already call the verb.\n */\n const planSalt = `${(planSeq += 1)}.${Math.random().toString(36).slice(2)}`;\n\n const plans = new Map<string, Plan>();\n /** The `rev` every record in `plans` was minted at, which is what keeps the\n * map to one rev's worth: it is cleared the moment a newer one mints. Not\n * the expiry check -- that is `plansGoodAt` -- so this stays the honest\n * answer to \"when was this counted\" and goes on bounding the memory. */\n let plansAt = -1;\n /**\n * The `rev` the outstanding plans are still good AT, which starts equal to\n * `plansAt` and is the only thing `checkPlan` compares against.\n *\n * THE DEFECT THIS SPLITS IN TWO. `Snapshot.rev` means \"the snapshot\n * changed\", and a read-only navigation genuinely changes the snapshot: the\n * person is looking at a different screen. So one number was answering two\n * questions. `stale` asks \"is what you were looking at still what is on\n * screen?\" -- and navigation really does invalidate that, which is why the\n * `stale` check still compares the raw `rev` and is untouched here. A plan\n * token asks \"is the selection you counted still the selection?\" -- and\n * navigation does not touch that at all. Conflating them priced the\n * double-check above the blind commit: `select-where` then `goto` then\n * `accept-selected` was refused `stale-plan` although nothing about the\n * selection had moved, so the cheap path was to commit without re-reading.\n * The whole mechanism exists to make an agent read the number before it\n * moves 3,412 rows, and teaching it that looking first costs two extra calls\n * teaches exactly the wrong habit.\n *\n * WHAT CARRIES IT FORWARD, and every clause is a safety condition rather\n * than a convenience; see the carry in `call()`. A verb that DECLARED\n * `kind: \"read\"` -- the kind whose own documentation says \"changes no data\n * and reports no count. It may still move what the person is looking at:\n * navigation is a read\" -- that moved `rev`, while the app publishes a\n * `Snapshot.selectionId` and that string is unchanged across the call.\n *\n * WHAT DOES NOT. An app that publishes no `selectionId` carries nothing and\n * behaves exactly as it did before this existed: its token still dies on the\n * first `rev` move of any kind. That is the fail-safe direction and it is the\n * reason this was done with `selectionId` rather than with a second counter\n * an author has to remember to bump -- an author who forgot the counter would\n * get a token that never expires, which is the 3,412-row bug. A `commit`\n * carries nothing, since a commit is the thing a plan is a receipt against. A\n * verb with no declared `kind` carries nothing, because an absent `kind`\n * makes no safety claim in either direction. And a `rev` that moved with no\n * verb behind it at all -- a websocket landing between two calls -- carries\n * nothing, because the plan was already dead by the time the next verb\n * started: the carry requires that the plans were still good at the rev the\n * read STARTED from.\n */\n let plansGoodAt = -1;\n /**\n * The `Snapshot.selectionId` the outstanding plans were minted against, or\n * undefined in an app that publishes none.\n *\n * Driver-level rather than per-plan because every outstanding plan shares it:\n * `mint` clears the map whenever `rev` moves, so the map only ever holds\n * plans taken at one rev, and one rev is one selection. It is kept separately\n * from the plans all the same, so the carry can be decided when the map is\n * empty and without picking an arbitrary entry out of it.\n */\n let plansSelection: string | undefined;\n let planCount = 0;\n\n /**\n * Whether this app uses plans at all, decided once, statically.\n *\n * An app with no `consumes` verb gets no tokens minted, so its `describe`\n * verbs return exactly the `Result` they returned before this existed —\n * byte for byte, which matters because that result is rendered into a\n * transcript and asserted on. Minting unconditionally would put a `plan`\n * field, and a line of rendered text, into every app in the world for a\n * feature none of them had asked for.\n */\n const usesPlans = [...verbs.values()].some((v) => v.consumes === \"plan\");\n\n /** How large a selection says it is, as the screen reports it.\n *\n * `selectedCount` first and `selected.length` only as a fallback, which is\n * the order those two fields document: `selected` is by design just the ids\n * on screen, so reading it first would report 20 for a selection of 3,412\n * and the `stale-plan` hint would name a number nobody was ever shown. */\n const sizeOf = (s: Snapshot): number | undefined =>\n s.selectedCount ?? (s.selected ? s.selected.length : undefined);\n\n /**\n * Mint a token for the selection a `describe` just left behind.\n *\n * The token is opaque to everybody but this driver, and it carries its `rev`\n * in clear on purpose: a plan is retired the moment a newer one is minted, so\n * a token that is no longer in the map must still be able to say whether it\n * was a plan from two revs ago — which is a useful refusal naming both\n * numbers — or a string that was never a plan at all. The hash is over every\n * bound field, so a token cannot be edited into a claim about another verb,\n * another rev or another selection.\n */\n function mint(verb: string, after: Snapshot, count: number): string {\n if (after.rev !== plansAt) {\n plans.clear();\n plansAt = after.rev;\n }\n // Reset on every mint, carried plans included. A fresh describe is a fresh\n // count, so whatever a previous plan had been carried to is irrelevant from\n // here; and the clear above means a carried plan from an older rev is\n // retired by this mint exactly as it was before the carry existed.\n plansGoodAt = after.rev;\n plansSelection = after.selectionId;\n // A guard, not a policy. An app whose `rev` never moves could mint without\n // limit, and this driver may live for the life of a tab. The oldest goes,\n // and an agent holding it is refused `stale-plan` -- which is the right\n // answer for a plan that is some thousands of describes old.\n if (plans.size >= 64) {\n const oldest = plans.keys().next().value;\n if (oldest !== undefined) plans.delete(oldest);\n }\n planCount += 1;\n const n = planCount;\n const bound = JSON.stringify([planSalt, verb, after.rev, after.selectionId ?? null, count, n]);\n const token = `${PLAN_PREFIX}.${after.rev}.${n}.${hash12(bound)}`;\n plans.set(token, {\n verb,\n rev: after.rev,\n ...(after.selectionId === undefined ? {} : { selection: after.selectionId }),\n count,\n used: false,\n });\n return token;\n }\n\n /** The `rev` a token says it was minted at, or null when it is not a token\n * this core could have produced. Only ever used to phrase a refusal. */\n function revOf(token: string): number | null {\n const parts = token.split(\".\");\n if (parts.length !== 4 || parts[0] !== PLAN_PREFIX) return null;\n const rev = Number(parts[1]);\n return Number.isSafeInteger(rev) ? rev : null;\n }\n\n /**\n * The five ways a plan can fail, and the hint for each.\n *\n * Returns the hint to refuse with, or null to allow. Every branch names the\n * same repair — see `PLAN_REPAIR` — and the branches differ only in what they\n * say went wrong, because \"your plan is stale\" with no account of how is a\n * dead end in exactly the way a bare `wrong-screen` was.\n */\n function checkPlan(name: string, token: string | undefined, before: Snapshot): string | null {\n if (token === undefined || token === \"\") {\n const empty = sizeOf(before) === 0;\n return (\n `\\`${name}\\` acts on the current selection, so it may only be called with the ` +\n `\\`plan\\` token from the \\`describe\\` verb that counted it. You sent none, so nothing ` +\n `ran: without one, the number you read and the rows that move are two different ` +\n `claims.` +\n // Said when the app reports an empty selection, because this is the\n // case where the generic advice reads as an instruction to go and find\n // something to act on. Only when the app actually counts -- an absent\n // `selectedCount` means \"I do not count\", and \"nothing is selected\" is\n // not a thing to assert from a missing field.\n (empty\n ? ` Nothing is selected right now, so there is no count for a plan to be taken on` +\n ` and nothing for this verb to do.`\n : \"\") +\n ` ${PLAN_MISSING_REPAIR}`\n );\n }\n\n const plan = plans.get(token);\n if (!plan) {\n const was = revOf(token);\n if (was !== null && was !== before.rev) {\n // The common case, and the one the whole feature is about: the agent\n // is holding a receipt from before something moved.\n return (\n `that plan was taken at rev ${was} and the screen is now at rev ${before.rev}, so ` +\n `the selection it counted is not the selection on screen. ${PLAN_REPAIR}`\n );\n }\n return (\n `\\`${token}\\` is not a plan this app has outstanding — it was never minted here, or it ` +\n `has been superseded by a later one. Nothing ran. ${PLAN_REPAIR}`\n );\n }\n\n // BOTH NUMBERS, in every refusal about a plan this driver actually minted,\n // the way `wrong-screen` names both screens. \"Your plan is stale\" sends a\n // model back to re-read and work out what changed; \"you were shown 3,412\n // and the selection is now 3,418\" is a sentence it can say to the person\n // who approved the first number, which is the whole job. Appended to each\n // reason rather than built into one, so each branch still says what went\n // wrong as well as by how much.\n const now = sizeOf(before);\n const both =\n ` You were shown ${plan.count}; the selection is now ` +\n `${now === undefined ? \"not counted by the app\" : String(now)}.`;\n\n if (plan.used) {\n // Single use, and the refusal says so rather than saying \"stale\", because\n // an agent told \"stale\" will re-read and try the same token again.\n return (\n `that plan has already been used by a commit. A plan is good for one commit, so that a ` +\n `count a person approved once cannot be acted on twice.${both} ${PLAN_REPAIR}`\n );\n }\n\n // `plansGoodAt` and not `plan.rev`, which is the whole of the fix. The two\n // are the same number until a read-only move carries them apart, and they\n // are compared here rather than in `call()` so that the one refusal still\n // names the rev the count was actually taken at.\n if (plansGoodAt !== before.rev) {\n return (\n `that plan was taken at rev ${plan.rev} and the screen is now at rev ${before.rev}, so ` +\n `the selection it counted is not the selection on screen.${both} ${PLAN_REPAIR}`\n );\n }\n\n // The case `rev` alone cannot catch: an app that changed its selection\n // without moving its `rev`.\n if (plan.selection !== undefined && plan.selection !== before.selectionId) {\n return (\n `that plan named a different selection from the one on screen now.${both} ` +\n `${PLAN_REPAIR}`\n );\n }\n\n if (plan.selection === undefined) {\n // Said once, not refused, and it is the honest disclosure of how strong\n // this check actually is in this app. The verb asked for a plan, the app\n // publishes no `selectionId`, so the token binds the `rev` and the count\n // and nothing else -- which catches every change the app bumps its `rev`\n // for and no change it makes quietly. Refusing instead would break an\n // app that adopted `consumes` before `selectionId`; saying nothing would\n // let the weaker check be mistaken for the stronger one. See `warn`.\n warn(\n `the verb \\`${name}\\` consumes a plan but \\`visible()\\` returns no \\`selectionId\\`, so ` +\n `the token can only bind the \\`rev\\` and the count. A selection that changes without ` +\n `moving \\`rev\\` will not be caught. Fill in \\`Snapshot.selectionId\\` — ` +\n `\\`selectionId(ids)\\` from this package is the one to use.`,\n );\n }\n\n return null;\n }\n\n /** The manifest entry for a verb, which is what an approval hook is handed.\n * Built from the manifest rather than from the `Verb` so a gate reads the\n * declared facts and cannot reach `run`; see `ApprovalRequest`. */\n const entries = new Map(manifest.verbs.map((v) => [v.name, v] as const));\n\n const ctx: VerbContext = { refuse: refusal };\n\n /**\n * Ask, and turn the three answers into the three outcomes.\n *\n * Returns null to allow, or the refusal to send back. The lock is taken for\n * the duration and released in a `finally`: a hook that throws must not\n * leave a driver that refuses every later call, and it must not be read as\n * consent either — a failed ask is a no, which is the rule\n * `onBeforeCommit` already had and the only safe way round it is a person.\n */\n async function askApproval(\n ask: ApprovalHook,\n name: string,\n args: Record<string, Scalar>,\n before: Snapshot,\n trail: Trail,\n ): Promise<Result | null> {\n const req: ApprovalRequest = { name, args, verb: entries.get(name)!, snapshot: before };\n const was = pending;\n pending = { verb: name, question: false };\n // The one wait in this file that is a PERSON rather than the app, and\n // therefore the one worth timing separately. Read only when a record is\n // going to be built -- an app with no `onAudit` reads no clock here, the\n // same promise `call` already makes.\n const askedAt = onAudit === undefined ? 0 : Date.now();\n let decision: Approval;\n try {\n decision = await deadline<Approval>(ask(req), { timedOut: true }, options.approvalTimeout);\n } catch (err) {\n decision = `the approval could not be asked for (${\n err instanceof Error ? err.message : String(err)\n }), and a failed ask is a no, never a yes`;\n } finally {\n pending = was;\n // In the `finally`, so EVERY exit is timed: a yes, a no, a deadline, and\n // a hook that threw. A person who spent two minutes and then declined is\n // exactly as interesting to an auditor as one who spent two minutes and\n // approved, and a figure recorded only on the happy path is one that\n // vanishes from the records somebody is most likely to be reading.\n if (onAudit !== undefined) trail.waitedMs = Math.max(0, Date.now() - askedAt);\n }\n\n // The answer, written down as one of four words before it is turned into a\n // refusal. Four and not three because `declined` and `not-asked` are the\n // two an audit reader must never confuse -- one is a person refusing, the\n // other is a gate that was not there -- and a hook that THREW is recorded\n // as `declined`, deliberately, because that is the decision the core made\n // from it: a failed ask is a no.\n if (decision === undefined || decision === true) {\n trail.approval = \"allowed\";\n return null;\n }\n // Read through one probe rather than narrowed member by member, because\n // the two object answers have no field in common and the next one will not\n // either: a gate answers in the shapes it needs, and the core's job is to\n // recognise them without caring what else is on the object.\n const shape =\n typeof decision === \"object\" && decision !== null\n ? (decision as { timedOut?: unknown; asked?: unknown; hint?: unknown })\n : undefined;\n // Allowed the call, and nobody was asked. The ONE answer that allows\n // without claiming consent, and it is here so the panel's dialog can let a\n // small reversible commit past -- or let everything past when the person\n // has switched confirmations off -- without the record saying a person\n // said yes. `trail.approval` stays `not-asked`, which it already is, and\n // `policy` says there was a gate that chose not to ask. See `Approval`.\n if (shape?.asked === false) {\n // Nobody was asked, so there was no wait -- and `waitedMs` promises that\n // its absence means no question was open. The gate returned in no time\n // at all, which is indistinguishable from an instant answer by the\n // clock; `asked: false` is the one thing that tells them apart, so it is\n // what the field is cleared on.\n delete trail.waitedMs;\n return null;\n }\n trail.approval = shape?.timedOut === true ? \"timed-out\" : \"declined\";\n if (decision === false) return no(DECLINED, DECLINED_HINT, read());\n if (typeof decision === \"string\") return no(DECLINED, decision, read());\n if (shape?.timedOut === true) {\n return no(\n APPROVAL_TIMEOUT,\n (typeof shape.hint === \"string\" ? shape.hint : undefined) ??\n `\\`${name}\\` needed a person's approval and nobody answered. **The verb did not ` +\n `run and nothing changed** — this is not the relay's \\`timeout\\`, which means the ` +\n `outcome is unknown. Ask the person, then call it again.`,\n read(),\n );\n }\n // An answer the core does not recognise is a denial. Reading an unknown\n // shape as consent is how a refactor of a hook's return type silently\n // removes the gate, and the cost of being wrong the other way is one\n // refused commit.\n warn(\n `the \\`approve\\` hook answered with ${JSON.stringify(decision)}, which is not an ` +\n `approval. Treated as a refusal. Return true, false, a reason, ` +\n `{ timedOut: true }, or { asked: false }.`,\n );\n return no(\n DECLINED,\n \"the app's approval hook answered with something that is not a decision, so this was \" +\n \"not allowed. That is a bug in the app rather than in your call.\",\n read(),\n );\n }\n\n /**\n * Put the agent's question to the person, and answer the agent honestly.\n *\n * THE FIVE THINGS THIS OWNS, none of which a verb body could:\n *\n * 1. **The lock.** `pending` is held for as long as the question is open, so\n * every other call on this driver -- from this agent or another one over\n * the relay -- is refused `approval-pending`. An agent that could carry\n * on acting while somebody is mid-decision is an agent acting on a screen\n * the person is about to change, and over the relay it is two agents, one\n * of which asked.\n * 2. **The deadline.** `MountOptions.askTimeout`, defaulting to 45 seconds,\n * which is under the relay's 60. That is what keeps \"nobody answered\" a\n * FACT rather than the relay's `timeout`, which means outcome unknown.\n * 3. **The allowance.** `budget.asks`, checked before the question is put\n * and charged only when it actually reached somebody.\n * 4. **The record.** `trail.waitedMs`, written on every exit, which is the\n * field that tells an auditor a question was genuinely put and for how\n * long it stood. See `AuditEvent`.\n * 5. **Keeping nothing.** The answer is turned into this call's `Result` and\n * is not stored anywhere. That is the whole of \"a question is not\n * consent\": there is no remembered yes for a later commit to consult, so\n * the separation is structural rather than a policy somebody could\n * relax. `ApprovalRequest` has no field that could carry one.\n *\n * It is called from `decide` rather than from `run` because four of those\n * five are things `call()` owns, and because the fifth is only true if the\n * answer never leaves this function.\n */\n async function putQuestion(\n args: Record<string, Scalar>,\n before: Snapshot,\n trail: Trail,\n ): Promise<Result> {\n const question = String(args[ASK_QUESTION_ARG] ?? \"\").trim();\n // An empty question after trimming. `checkArg` has already refused a\n // missing or non-string one, so what is left is whitespace -- which would\n // put a blank box in front of somebody and is the one argument error worth\n // catching here rather than passing on.\n if (question === \"\") {\n return no(\n \"bad-argument\",\n `\\`${ASK_QUESTION_ARG}\\` is blank. Ask something: the person sees this text and ` +\n `nothing else, so a blank question is a box they cannot answer.`,\n before,\n );\n }\n // Bounded, and refused rather than truncated. `SIZE_LIMITS.describe` is the\n // library's one-line budget and a question is a one-line thing; truncating\n // would put half a question in front of somebody, which reads as the whole\n // of a different question. An agent that needs a paragraph has not worked\n // out what it does not know.\n if (question.length > SIZE_LIMITS.describe) {\n return no(\n \"bad-argument\",\n `that question is ${question.length} characters and the limit is ` +\n `${SIZE_LIMITS.describe}. Ask the narrowest question that unblocks you, in one ` +\n `line: a wall of text in front of somebody is a question they will dismiss. Say ` +\n `the rest in your final answer.`,\n before,\n );\n }\n\n // The allowance, BEFORE the question is put and before the lock is taken.\n // The order matters for the same reason the commit ceiling sits one line\n // above the approval gate: nobody is interrupted for a call that was\n // already going to be refused.\n if (budget?.asks !== undefined && asksUsed >= budget.asks) {\n return no(\n ASKS_SPENT,\n `this app allows ${budget.asks} question${budget.asks === 1 ? \"\" : \"s\"} per mounted ` +\n `session and all ${budget.asks} have been asked, so this one was not put to ` +\n `anybody. It does not refill, and no further question will reach them. **The rest ` +\n `of the app still works**: this is a ceiling on the person's attention, not on ` +\n `your calls. Carry on with what you can decide, and in your final answer say ` +\n `exactly what you would have asked and what you could not settle without it.`,\n before,\n );\n }\n\n const was = pending;\n pending = { verb: ASK, question: true };\n // Read only when a record is going to be built, the promise `call` and\n // `askApproval` both already make: an app with no `onAudit` reads no clock.\n const askedAt = onAudit === undefined ? 0 : Date.now();\n let answer: AskAnswer;\n try {\n answer = await askDeadline(askFn!({ question }), options.askTimeout);\n } catch (err) {\n // A question UI that throws must not take the app down, and must not be\n // read as an answer. The precedent is `ApprovalHook`, where a failed ask\n // is a no; here a failed ask is an UNANSWERED question and emphatically\n // not `nobody-to-ask` -- a broken panel is not evidence that nobody is\n // sitting there, and saying it is would tell an agent to stop asking for\n // the rest of the run over one exception. The message is folded in\n // because the author reading the transcript is the one who can fix it.\n answer = { answered: false };\n warn(\n `the \\`ask\\` hook threw, so the question was treated as unanswered: ` +\n `${err instanceof Error ? err.message : String(err)}. A failed ask is an ` +\n `unanswered question, never an answer and never a claim that nobody is there.`,\n );\n } finally {\n pending = was;\n // In the `finally`, so EVERY exit is timed -- an answer, a silence, a\n // deadline, a hook that threw. A question somebody read for two minutes\n // and then ignored is exactly as interesting to an auditor as one they\n // answered, and a figure recorded only on the happy path vanishes from\n // the records somebody is most likely to be reading. The one exit that\n // deliberately does NOT get a figure is `{ nobody: true }`, below: see\n // `AuditEvent`, where the presence of `waitedMs` is what says a question\n // reached somebody.\n if (onAudit !== undefined) trail.waitedMs = Math.max(0, Date.now() - askedAt);\n }\n\n const shape =\n typeof answer === \"object\" && answer !== null\n ? (answer as { answered?: unknown; nobody?: unknown })\n : undefined;\n\n // Nobody is there. The question was never put, so nothing is charged and\n // the record carries no wait: both of those are the honest reading, and\n // both are what tell this apart from a question that stood in front of\n // somebody for 45 seconds.\n if (shape?.nobody === true) {\n delete trail.waitedMs;\n return no(\n NOBODY_TO_ASK,\n \"there is nobody to ask on this run: this app is being driven with no person in \" +\n \"front of it. The question was not put to anybody, nothing in the app changed, \" +\n \"and no later question will reach them either — so stop asking. Decide from what \" +\n \"you already know if you honestly can, and if you cannot, say what you needed to \" +\n \"know and what you could not settle without it.\",\n before,\n );\n }\n\n // Charged here and nowhere else: the question reached somebody, whether or\n // not they answered. A question that sat in front of a person and was\n // ignored has spent their attention as surely as one they replied to, and a\n // counter that only counted replies would never fire on the agent that\n // interrupts somebody who has stopped reading it.\n asksUsed++;\n rememberSpend();\n\n if (typeof answer === \"string\" && answer.trim() !== \"\") {\n // THE ANSWER IS THE RESULT, which is the one structural thing about this\n // feature worth saying twice. It rides in `Report.note`, so it renders\n // through `ok — …` exactly as every other verb's note does and no\n // renderer in either language needed a line for it. A side channel --\n // another field on `Result`, a block in the snapshot -- would have been a\n // second place a model has to learn to look, and would have put a\n // person's words somewhere this core could keep them.\n //\n // Attributed, because `ok — yes, the one at Acme` is indistinguishable\n // from the app reporting something. The quotes and the words \"the person\n // answered\" are the core saying whose sentence this is, and they are the\n // core's words rather than the app's for the reason `ASK_DESCRIBE` is\n // here: a sentence written twice in two languages is a sentence that\n // drifts.\n //\n // The answer itself is passed through verbatim and never parsed. Nothing\n // in here looks for \"yes\": a core that classified an answer would be one\n // step from a core that acted on the classification, which is the\n // approval bypass this whole design is shaped against.\n const said = answer.trim();\n return {\n ok: true,\n note: `the person answered: \"${said}\"`,\n snapshot: read(),\n };\n }\n\n // Everything else is an unanswered question, including an answer shape this\n // core does not recognise and an empty string. The same rule `Approval`\n // applies to an unknown shape, pointed the other way: there the safe\n // reading of a shape nobody recognises is a DENIAL, and here it is that\n // nobody spoke. Reading it as an answer would put words in a person's mouth\n // and let a model act on them, which is strictly the worse of the two\n // mistakes.\n if (shape?.answered !== false) {\n warn(\n `the \\`ask\\` hook answered with ${JSON.stringify(answer)}, which is not an answer. ` +\n `Treated as unanswered. Return the person's words as a string, ` +\n `{ answered: false }, or { nobody: true }.`,\n );\n }\n return no(\n ASK_UNANSWERED,\n \"the question was put to the person and no answer came back — they closed it, walked \" +\n \"away, or it stood too long. **Nothing in the app changed and the verb did not \" +\n \"run**; this is not the transport `timeout`, where nobody knows what happened. Do \" +\n \"not invent an answer and do not act on what you were going to ask about. You may \" +\n \"ask once more, shorter, if it is genuinely the one thing in the way; otherwise say \" +\n \"what you needed to know and stop.\",\n before,\n );\n }\n\n /**\n * What `decide` writes down as it goes, for the record `call` emits after.\n *\n * It exists because of one rule: the record must not be a second source of\n * truth about what happened. Most of an `AuditEvent` is read straight off the\n * `Result` that is about to be returned, so it cannot disagree with it — but\n * four facts are decided inside `decide` and are gone by the time it returns.\n * The `rev` and `screen` the call RAN AGAINST, which on a successful commit\n * are not the ones in the result's snapshot; the approval answer, which the\n * gate alone knows; and the two plan tokens. Each is written down by the step\n * that decides it, which is the alternative to re-deriving it afterwards from\n * a second reading of the app.\n */\n interface Trail {\n rev?: number;\n screen?: string;\n approval: AuditEvent[\"approval\"];\n plan?: string;\n minted?: string;\n /** Milliseconds a question was open, when one was. Written by\n * `askApproval`, which is the one place in here that waits on a person, so\n * the record cannot disagree with it. See `AuditEvent.waitedMs`. */\n waitedMs?: number;\n }\n\n /**\n * Hand one record to the app's hook, and survive the hook.\n *\n * NOT AWAITED, and not deadlined. See `MountOptions.onAudit`: an approval is\n * asked before the decision and its answer IS the decision, so it has to be\n * waited for; a record is emitted after the outcome is settled and, for a\n * commit, after the data has moved, so waiting on the sink can only delay the\n * agent and failing the call would make a broken logging backend into a\n * broken app. A thrown error — synchronous or from the promise — is reported\n * once rather than swallowed, because a record that vanished in silence is\n * the one failure an audit trail cannot survive.\n */\n function record(\n name: string,\n args: Record<string, Scalar>,\n opts: CallOptions,\n trail: Trail,\n result: Result,\n started: number,\n ): void {\n // The DECLARED facts, from the manifest entry, exactly as the approval hook\n // is handed them: a record of what the app claimed about this verb, and no\n // reach into `run`.\n const entry = entries.get(name);\n const shown: Record<string, Scalar> = {};\n const redacted: string[] = [];\n for (const [key, value] of Object.entries(args)) {\n // Declared `sensitive`, so the value is replaced HERE -- before the hook,\n // which is the boundary a record is most likely to leave the box\n // across -- and the field is named, so `\"[redacted]\"` can never be read\n // as a string the agent actually sent. See `ArgSpec.sensitive`.\n if (entry?.args?.[key]?.sensitive === true) {\n shown[key] = REDACTED;\n redacted.push(key);\n } else {\n shown[key] = value;\n }\n }\n\n const at = Date.now();\n const event: AuditEvent = {\n at,\n ms: at - started,\n // Approval-inclusive `ms`, and the human share of it beside rather than\n // taken out of it. See `AuditEvent.waitedMs`: \"41 seconds, 38 of them\n // waiting\" answers both questions an auditor has and the sum alone\n // answers neither.\n ...(trail.waitedMs === undefined ? {} : { waitedMs: trail.waitedMs }),\n app: options.app,\n verb: name,\n args: shown,\n // The rev the call ran against, falling back to the one in the result's\n // own snapshot for the three refusals that answer before `visible()` is\n // read for comparison -- unmounted, approval-pending, unknown-verb. For\n // those the two are the same read, so this is not a guess.\n rev: trail.rev ?? result.snapshot.rev,\n ok: result.ok,\n approval: trail.approval,\n // Read now, not captured at mount: a page that acquires a gate halfway\n // through its life has records on both sides of that, and both are true.\n policy: policyNow(),\n };\n const screen = trail.screen ?? result.snapshot.screen;\n if (screen !== undefined) event.screen = screen;\n if (entry?.kind !== undefined) event.kind = entry.kind;\n if (entry?.reversible !== undefined) event.reversible = entry.reversible;\n if (redacted.length > 0) event.redacted = redacted;\n if (opts.rev !== undefined || opts.screen !== undefined) {\n event.claimed = {\n ...(opts.rev === undefined ? {} : { rev: opts.rev }),\n ...(opts.screen === undefined ? {} : { screen: opts.screen }),\n };\n }\n if (result.ok) {\n if (result.count !== undefined) event.count = result.count;\n } else {\n event.refused = result.refused;\n }\n if (trail.plan !== undefined) event.plan = trail.plan;\n if (trail.minted !== undefined) event.minted = trail.minted;\n\n try {\n const answered = onAudit!(event);\n if (answered !== undefined && typeof (answered as Promise<void>).then === \"function\") {\n void (answered as Promise<void>).catch((err: unknown) => audited(name, err));\n }\n } catch (err) {\n audited(name, err);\n }\n }\n\n /** Said out loud, once per distinct message, when a record did not get out. */\n function audited(name: string, err: unknown): void {\n warn(\n `the \\`onAudit\\` hook threw on \\`${name}\\`, so that call's audit record was lost: ` +\n `${err instanceof Error ? err.message : String(err)}. The call itself was unaffected — ` +\n `a record is emitted after the outcome is decided, so there is nothing left to refuse — ` +\n `but a record that vanishes in silence is the one failure an audit trail cannot survive.`,\n );\n }\n\n /**\n * `decide`, and then the record of what it decided.\n *\n * The split is what makes the record impossible to disagree with the\n * `Result`: there is one `Result` object, `decide` produced it at whichever\n * of its dozen exits applied, and the event is built from THAT object rather\n * than from a second look at the app. A per-exit emit would have been a dozen\n * places to forget one.\n *\n * With no hook this is the function it was before audit existed, plus one\n * object literal and one comparison: no clock is read and no record is built.\n */\n async function call(\n name: string,\n args: Record<string, Scalar> = {},\n opts: CallOptions = {},\n ): Promise<Result> {\n const trail: Trail = { approval: \"not-asked\" };\n const started = onAudit === undefined ? 0 : Date.now();\n const result = await decide(name, args, opts, trail);\n if (onAudit !== undefined) record(name, args, opts, trail, result, started);\n return result;\n }\n\n async function decide(\n name: string,\n args: Record<string, Scalar>,\n opts: CallOptions,\n trail: Trail,\n ): Promise<Result> {\n if (!live) return no(\"unmounted\", \"this driver was unmounted\", read());\n\n // BEFORE the verb is even looked up, and that order is the point. This is\n // not a fact about the call, it is a fact about the app: somebody is being\n // asked a question and nothing else runs until they answer. Checking it\n // after the lookup would answer `unknown-verb` to a call made during an\n // approval, which is a true statement about the wrong thing.\n //\n // It is also what makes point 4 structural rather than hopeful: the second\n // call for a verb whose approval is open cannot race the dialog, because\n // it is refused here — including when it is the same verb, and including\n // when it is the gate's own Approve button arriving as a `press`.\n if (pending !== null) {\n // One slug for both kinds of open question, and a different sentence.\n //\n // The slug is `approval-pending` either way because to the AGENT the two\n // are the same fact and call for the same move: nothing ran, somebody is\n // being asked something, wait. A second slug would be a second word for\n // one repair, which is what `RESERVED_REFUSALS` keeps refusing to add.\n //\n // The hint differs because the two are not the same thing to the PERSON\n // reading a transcript, and because the hazard the approval wording\n // exists for -- an agent pressing the Approve button of the dialog that\n // is asking it -- is not what a question is about. An agent told\n // \"`accept-selected` is waiting to be approved\" while what is actually\n // on screen is \"which Ada Duarte did you mean?\" has been told something\n // false about its own app.\n return no(\n APPROVAL_PENDING,\n pending.question\n ? `this app has put a question of yours to the person and is waiting for their ` +\n `answer, so it is not taking calls. Nothing ran. Wait for the answer: it comes ` +\n `back as the result of the \\`${ASK}\\` call you already made, and asking again ` +\n `will not reach them any sooner.`\n : `\\`${pending.verb}\\` is waiting to be approved, so ${PENDING_HINT}`,\n read(),\n );\n }\n\n // AFTER the approval lock and BEFORE the verb lookup, and both halves of\n // that position are decisions.\n //\n // After the lock, because a call refused `approval-pending` reached nothing\n // and must not be charged for: a confused agent polling while a person\n // reads a dialog would otherwise eat the whole ceiling without a single\n // verb running, and the ceiling is for spend, not for impatience.\n //\n // Before the lookup, because a spent budget is the widest true thing there\n // is to say about this call. Every other check in here answers \"this\n // particular call is wrong, here is the repair\"; this one answers \"nothing\n // will work again, and no repair exists at this end\". Answering\n // `unknown-verb` to a call made past the ceiling would send an agent off to\n // find a verb name that was never the problem — which is the same ordering\n // argument `wrong-screen` is above `stale` for, taken one step further out.\n //\n // Charged for whatever happens next, refusals included. See `Budget`: an\n // agent looping on `bad-argument` is the runaway this field exists for, and\n // a counter that only counted successful calls would watch it spin.\n // Before the counter comparison, because when the ceiling cannot be\n // accounted for there is no counter worth comparing. Same slug as a spent\n // ceiling on purpose: to the agent the two are the same fact — nothing more\n // will run here and no repair exists at this end — and `drive` already\n // treats `budget-spent` as an ending rather than as a mistake to retry.\n // The hint is what differs, and it is the hint a human reads.\n // What the other tabs have spent, before this tab decides it has room. See\n // `syncSpend`: without this, two tabs open at once are two ceilings.\n syncSpend();\n if (budgetBroken !== null) {\n return no(BUDGET_SPENT, budgetBroken, read());\n }\n\n if (budget?.calls !== undefined && callsUsed >= budget.calls) {\n return no(\n BUDGET_SPENT,\n `this app allows ${budget.calls} verb call${budget.calls === 1 ? \"\" : \"s\"} per mounted ` +\n `session and all ${budget.calls} are spent, so \\`${name}\\` was not run. This is a ` +\n `ceiling the app set, not a rate limit: it does not refill, and waiting or retrying ` +\n `will not change it. Stop, and say what you had got through and what is left — ` +\n `somebody has to decide whether to raise it.`,\n read(),\n );\n }\n callsUsed++;\n rememberSpend();\n\n const verb = verbs.get(name);\n if (!verb) {\n // The known names are listed. An outside agent may be holding a manifest\n // from a previous version of the app, and the list is how it finds out\n // what moved without a second round trip.\n const known = [...verbs.keys()].sort().join(\", \");\n return no(\"unknown-verb\", `no verb named \\`${name}\\`. known: ${known}`, read());\n }\n\n const before = read();\n // Written down HERE, at the one read every check below compares against, so\n // the record says what the call ran against and not what the screen looked\n // like afterwards. On a successful bulk commit those are different revs,\n // and the one worth keeping is this one: it is the rev the count was taken\n // at and the rev a person approved.\n trail.rev = before.rev;\n if (before.screen !== undefined) trail.screen = before.screen;\n // Read HERE and kept, because the carry below needs it and the `read()`\n // that produces `after` is where a lapsed notice is cleared. A read-only\n // move clears the notice as a side effect -- a known weakness of `rev`,\n // documented on `MountOptions.elsewhere` -- so asking afterwards would\n // always answer no, and a plan would be carried across a navigation in a\n // tab the core had just been told was behind. See the carry.\n const behind = elsewhere !== null;\n\n // WHICH SCREEN comes before WHICH REV, which comes before the arguments.\n // Each check describes a wider mistake than the next, and the widest one is\n // the useful answer: if the agent is not on the screen it thinks it is,\n // then the rev and the arguments both describe something it never saw, and\n // answering \"the number moved\" sends it to re-read a screen when what it\n // needs is to navigate back. A `next-page` that lands on another company's\n // contact list and answers `ok` is the live bug this ordering exists to\n // make impossible.\n //\n // Both screen checks are skipped when the app does not fill in\n // `Snapshot.screen`. There is nothing to compare against, and inventing a\n // comparison -- treating absent as \"not that one\" -- would refuse every\n // screen-scoped verb in an app that simply has not adopted the field.\n if (opts.screen !== undefined && before.screen !== undefined && opts.screen !== before.screen) {\n return no(\n WRONG_SCREEN,\n `you believed you were on the \\`${opts.screen}\\` screen but the app is on ` +\n `\\`${before.screen}\\`; read the screen again before acting on it`,\n before,\n );\n }\n\n if (verb.screen !== undefined) {\n const wants = screensOf(verb.screen);\n if (before.screen === undefined) {\n // Said once, not refused. The app declared a verb→screen mapping and no\n // live screen, so the check it asked for cannot run -- which is a\n // mistake in the app rather than in the call, and refusing a verb an\n // author believes they scoped correctly would break a working app over\n // a missing field. See `warn`.\n warn(\n `the verb \\`${name}\\` names ${wants.length > 1 ? \"the screens\" : \"the screen\"} ` +\n `${naming(wants)} but \\`visible()\\` returns no \\`screen\\`, so the check cannot run. ` +\n `Fill in \\`Snapshot.screen\\` with the id of the screen that is live, or drop ` +\n `\\`screen\\` from the verb.`,\n );\n } else if (!wants.includes(before.screen)) {\n // ALL the screens are named, the live one and every one the verb works\n // on. `wrong-screen` on its own is a dead end: an agent that is told no\n // and not told where to go has to guess, and the guess is another\n // refused call. Naming only one of several would be a subtler version\n // of the same dead end -- it would send an agent to the contacts list\n // when the company screen it is two clicks from would have done. The\n // verb that navigates is the app's and cannot be named from here, which\n // is what `Manifest.instructions` is for.\n return no(\n WRONG_SCREEN,\n `you are on the \\`${before.screen}\\` screen; \\`${name}\\` works on the ` +\n `${naming(wants)} ${wants.length > 1 ? \"screens\" : \"screen\"}. Go ` +\n `${wants.length > 1 ? \"to one of those\" : \"there\"} first, then call it again.`,\n before,\n );\n }\n }\n\n // WHAT ANOTHER TAB DID comes after WHICH SCREEN and above every staleness\n // check, including `stale-plan`, and the ladder's own rule is why.\n //\n // The ladder is widest first, because the widest answer's repair subsumes\n // the narrower ones'. This is the widest staleness there is: `stale` says\n // the rev moved, `stale-plan` says the selection moved, and both are\n // repaired by reading this tab again -- which is exactly the repair that\n // DOES NOT WORK here, because what moved is the data behind a tab whose\n // `rev` is unchanged. Answering `stale` or `stale-plan` first would hand an\n // agent a repair that appears to succeed and leaves it believing it is\n // current: it reads again, gets the same rev, and commits. That is the\n // silent failure this check exists to end, so it has to be answered before\n // either of them.\n //\n // ONLY A `commit`, and that is the one real judgement in here. A `read` or\n // a `describe` in a tab that is behind still returns the rows the person is\n // actually looking at, and its snapshot now says in words that they may be\n // behind -- see `read()`. Refusing those as well would make a tab whose app\n // does not refetch completely undrivable, and would do it by sending an\n // agent round a loop: refused, read again, same rev, refused. A commit is\n // the one call whose cost is not paid back by reading again, which is the\n // same line `MountOptions.approve` draws for the same reason.\n //\n // WHATEVER `rev` THE AGENT CLAIMED, including none. `rev` and `screen` are\n // checks an agent opts out of by making no claim, because an agent that\n // claims nothing has at least not claimed something false. This is not of\n // that kind: it is not a claim being checked, it is the core knowing the\n // data moved. `consumes: \"plan\"` already makes the same exception for the\n // same reason -- a guarantee a caller can decline is not a guarantee.\n // `before` was produced by `read()` above, which is where a notice whose rev\n // has moved on is cleared. So a non-null `elsewhere` here has already been\n // checked against the live rev, and calling `read()` again in this\n // condition would be asking the question that answers itself -- and would\n // null the field between the two halves of the `&&`.\n if (verb.kind === \"commit\" && elsewhere !== null) {\n return no(\n CHANGED_ELSEWHERE,\n `another tab of this app committed \\`${elsewhere.verb}\\` after this screen was read. ` +\n `This tab is at rev ${elsewhere.at} and has not moved, so its rows -- and any count ` +\n `taken from them -- may describe data that has already changed. Reading this screen ` +\n `again will NOT fix that: the rev will be the same and it will still be behind. ` +\n `Say what happened and let the person refresh the page or switch to the tab that ` +\n `made the change; do not retry this commit here.`,\n before,\n );\n }\n\n // WHICH SELECTION comes after WHICH SCREEN and BEFORE WHICH REV, and this\n // is the one ordering decision in `call()` that is not obvious, so here is\n // the argument.\n //\n // The ladder is by how WIDE the mistake is, widest first, because the\n // widest answer is the one whose repair subsumes the others'. A wrong\n // screen is still the widest: a plan taken on another screen is a claim\n // about a selection the agent was never looking at, so there is nothing\n // useful to say about it until it is standing in the right place.\n //\n // But `stale-plan` is WIDER than `stale`, and that is why it goes above it\n // rather than below. The two overlap on everything that moves the\n // selection -- and where they do, the repairs are not the same size.\n //\n // They are no longer nested the way this comment once claimed. A read-only\n // move is `stale` and is NOT `stale-plan`: the screen the agent echoed is\n // not the screen on display, and the selection it counted is still the\n // selection, so the narrower answer is the true one and it is the one that\n // comes back. See `plansGoodAt`. The ordering is unchanged, because where\n // both apply the plan is still the wider mistake. `stale` says \"read\n // again\", and an\n // agent that reads again and carries on is the agent that accepts 3,418\n // rows after a person approved 3,412. `stale-plan` says \"run the describe\n // again, read the new count, check it, then commit\", which is the repair\n // that actually fixes a moved selection. Answering the narrower one first\n // would hand back the cheaper instruction for the more expensive mistake.\n //\n // It is also before the argument check for the reason `rev` is: a commit\n // whose selection has moved is not a commit whose arguments are worth\n // discussing. And it is before the approval gate, which is last, so nobody\n // is ever asked to approve a commit that was already going to be refused.\n if (verb.consumes === \"plan\") {\n // Recorded BEFORE the check and whatever the check says. A token that was\n // refused is the interesting one: it is how an audit reader finds the\n // agent that tried to spend a receipt for a count that had moved.\n if (opts.plan !== undefined && opts.plan !== \"\") trail.plan = opts.plan;\n const stale = checkPlan(name, opts.plan, before);\n if (stale) return no(STALE_PLAN, stale, before);\n }\n\n // Staleness is checked BEFORE arguments, and that order is deliberate. If\n // the screen has moved on, the arguments describe a row the agent never\n // saw, so complaining about their shape would be answering the wrong\n // question -- and the fix is the same either way: read again.\n if (opts.rev !== undefined && opts.rev !== before.rev) {\n return no(\n \"stale\",\n `you acted on rev ${opts.rev} but the screen is at rev ${before.rev}; read again`,\n before,\n );\n }\n\n if (verb.args) {\n for (const [argName, spec] of Object.entries(verb.args)) {\n const reason = checkArg(argName, spec, args[argName]);\n if (reason) return no(\"bad-argument\", reason, before);\n }\n }\n\n // THE QUESTION, and it is answered here rather than by `verb.run` below.\n //\n // After the argument check, so a question with no text is `bad-argument`\n // like every other malformed call. Before the commit ceiling and the\n // approval gate, which cannot apply: an `ask` is not a `commit`, and that\n // is the first of the several reasons an answer cannot be consent.\n //\n // `verb === coreAsk` is an IDENTITY check and not a name check, because the\n // name is the one thing an app is allowed to take -- an app with its own\n // verb called `ask` falls straight through to `run` and is an ordinary\n // verb, which is what the warning at mount says out loud.\n if (coreAsk !== undefined && verb === coreAsk) {\n return await putQuestion(args, before, trail);\n }\n\n // LAST of the checks and immediately before `run`, which is the only place\n // it can go. Asking a person about a call that is about to be refused for\n // a stale rev, a wrong screen or a missing argument is asking them to\n // approve something that was never going to happen — and the second time\n // that happens they stop reading the question.\n //\n // The commit ceiling is checked HERE, one line above the gate, and the\n // order is the gate's own argument reused: nobody is asked to approve a\n // commit that was already going to be refused. It is also the last check\n // before `run`, which is where a bound on data moved belongs — a commit\n // refused for a stale plan did not move anything and must not be charged\n // for one.\n if (verb.kind === \"commit\" && budget?.commits !== undefined && commitsUsed >= budget.commits) {\n return no(\n BUDGET_SPENT,\n `this app allows ${budget.commits} commit${budget.commits === 1 ? \"\" : \"s\"} per mounted ` +\n `session and all ${budget.commits} have run, so \\`${name}\\` was not run and no data ` +\n `moved. Reads and describes may still work; it is commits that are spent. This ` +\n `ceiling does not refill — stop, and say which commits went through.`,\n before,\n );\n }\n\n // The app's own hook if it declared one, otherwise whatever the page\n // installed through `adopt`, otherwise nothing. Read HERE and not at\n // mount, because a panel can be mounted after the driver is and the\n // commits that arrive after it must go through it -- that is the whole of\n // what adoption buys, and a captured `const` would have made the first\n // page load the only one that counted.\n const approver = approveFn ?? adopted;\n if (verb.kind === \"commit\" && approver !== undefined) {\n const refused = await askApproval(approver, name, args, before, trail);\n if (refused) return refused;\n }\n\n // Charged on ENTERING `run`, beside the plan token and for the same reason:\n // a commit that changes half a selection and then throws has moved data,\n // and a counter that only counted clean returns would not know it.\n if (verb.kind === \"commit\") {\n commitsUsed++;\n rememberSpend();\n }\n\n // Burned HERE, between the last check and `run`, and the position is the\n // decision rather than an accident of where it fitted.\n //\n // A plan is single-use. Terraform's model is a saved plan that performs\n // exactly the steps it holds, and replaying one that has already been\n // applied is the double-apply; here it is the double-accept, which is the\n // single most expensive thing an agent can do with a bulk verb. The count\n // was shown once and approved once, so it buys one commit.\n //\n // Burned on ENTERING `run` rather than on a successful return, so a verb\n // that changes half a selection and then throws cannot have its token\n // re-presented. And burned AFTER the approval gate, not before, so a commit\n // that a person declined -- or that lapsed with nobody answering -- leaves\n // the token alive: nothing moved, the count is still the count, and making\n // somebody re-run the describe because they hesitated is how a gate teaches\n // people to stop reading it.\n if (verb.consumes === \"plan\" && opts.plan !== undefined) {\n const spent = plans.get(opts.plan);\n if (spent) spent.used = true;\n }\n\n let outcome: void | Refusal | Report;\n try {\n outcome = await verb.run(args, ctx);\n } catch (err) {\n // Announced, because a commit that threw may have moved half a selection\n // -- the same reason the plan token is burned on entering `run`. The\n // other tabs are told something changed and the agent is told the call\n // failed, and both of those are true at once.\n if (verb.kind === \"commit\") announce(name);\n // An app bug is reported as a failed call rather than allowed to\n // propagate. The alternative kills the websocket pump in the relay, and\n // a driver that dies on one bad verb takes every other verb with it.\n return no(\n \"threw\",\n `the verb \\`${name}\\` threw: ${err instanceof Error ? err.message : String(err)}`,\n read(),\n );\n }\n\n if (isRefusal(outcome)) {\n if (RESERVED.has(outcome.reason)) {\n // Reported as `threw` rather than passed through, and rather than\n // raised. Passing it through is the bug: the agent now reads `timeout`\n // from a call that landed and answered, and the reserved list stops\n // meaning anything. Raising would be worse — this is reached only while\n // a working app is saying no, and killing the run over a slug turns a\n // declined commit into a dead panel. `threw` is already the core's word\n // for \"the app's own code is broken\", which is exactly what this is,\n // and it leaves the reserved slugs saying only what they are for.\n warn(\n `the verb \\`${name}\\` refused with the reserved slug \\`${outcome.reason}\\`; ` +\n `reported as \\`threw\\`. Reserved: ${RESERVED_REFUSALS.join(\", \")}.`,\n );\n return no(\n \"threw\",\n `the verb \\`${name}\\` refused with \\`${outcome.reason}\\`, which is a reserved slug and ` +\n `not an app refusal. This is a bug in the app, not something to retry differently.`,\n read(),\n );\n }\n\n // Declaring `refuses` opts the verb into the check; leaving it absent\n // makes no claim, the same way an absent `kind` makes no safety claim.\n // Warning on every app that never filled the field in would be a warning\n // on everything and therefore a warning on nothing.\n if (verb.refuses && !verb.refuses.includes(outcome.reason)) {\n warn(\n `the verb \\`${name}\\` refused with \\`${outcome.reason}\\`, which is not in its declared ` +\n `refuses [${verb.refuses.join(\", \")}]. The manifest is the only description of this ` +\n `verb an agent gets, and an undeclared refusal is one it cannot plan around.`,\n );\n }\n\n return no(outcome.reason, outcome.hint, read());\n }\n\n // Read again after running, not before: the point of returning a snapshot\n // is to show what the call did.\n //\n // `count` is forwarded with `?? undefined` rather than a truthiness check,\n // because a `describe` verb that matched nothing must report `0` and not\n // silently become \"I do not count\" — those are different answers, and the\n // difference decides whether a commit should follow.\n // Before `read()`, so the snapshot this call returns is the one the OTHER\n // tabs are being warned about -- and after the refusal branches above, so\n // an app that said no has announced nothing. A driver ignores its own\n // notice, so this does not annotate the result below.\n if (verb.kind === \"commit\") announce(name);\n\n const after = read();\n\n // THE CARRY. A read-only move does not spend a plan.\n //\n // `Snapshot.rev` answers two questions and only one of them is the plan's;\n // see `plansGoodAt` for the argument and for why this is gated on\n // `selectionId` rather than on a second counter. What is left here is the\n // list of conditions, each of which is the safe direction of one choice:\n //\n // - `usesPlans` and a non-empty map: nothing to carry otherwise, and an\n // app with no consuming verb must not grow a line of behaviour it never\n // asked for.\n // - `kind === \"read\"`, read from the DECLARATION. `describe` is excluded\n // because it is the kind that changes what is selected -- and one that\n // counted has just minted a fresh plan anyway, which retires this one.\n // `commit` is excluded because it is the thing a plan is a receipt\n // against. An absent `kind` is excluded because it makes no claim.\n // - `before.rev === plansGoodAt`: the plans were still good when this\n // verb STARTED. A `rev` that had already moved for some other reason --\n // a websocket between two calls -- has already killed them, and a read\n // must not resurrect a plan by walking past the rev that buried it.\n // - `after.rev !== before.rev`: there is a move to forgive at all.\n // - `!behind`: no `changed-elsewhere` notice stands. The notice says this\n // tab's data may be stale at a `rev` that has not moved, and carrying a\n // plan over a navigation that silently cleared it would turn one extra\n // describe into none.\n // - a defined `selectionId`, unchanged across the call. This is the whole\n // guarantee: the plan counted a selection, and the app is saying that\n // the selection is the same one. An app that publishes nothing here\n // carries nothing and keeps the behaviour it has always had, which is\n // the fail-safe an un-adopted app needs -- and the core already warns\n // that author once, at their first plan check.\n if (\n usesPlans &&\n verb.kind === \"read\" &&\n plans.size > 0 &&\n before.rev === plansGoodAt &&\n after.rev !== before.rev &&\n !behind &&\n after.selectionId !== undefined &&\n after.selectionId === plansSelection\n ) {\n plansGoodAt = after.rev;\n }\n\n // The mint, and everything about when it happens is load-bearing.\n //\n // AFTER `run`, from the snapshot the call left behind, because the whole\n // claim is about the selection that now exists and not the one that did a\n // moment ago.\n //\n // Only on a `describe`, and only on one that reported a `count`. Those two\n // conditions are the same condition said twice: `describe` is the kind that\n // promises a pending count, and a `count` is the number a commit decision\n // turns on. A `read` leaves nothing pending and a `commit` has already\n // moved the data, so a token from either would be a receipt for a decision\n // nobody is about to make.\n //\n // Only in an app that has a verb consuming them, which is what keeps this\n // additive: every `describe` in every app written before this returns the\n // exact `Result` it returned before, with no `plan` field and no extra line\n // in anything that renders it.\n //\n // `count` is forwarded with `!== undefined` rather than a truthiness check,\n // because a `describe` verb that matched nothing must report `0` and not\n // silently become \"I do not count\" — those are different answers, and the\n // difference decides whether a commit should follow. A plan is minted for a\n // count of `0` for the same reason: \"commit on nothing\" is a decision an\n // agent can make, and it should be made against a receipt like any other.\n const counted = outcome && outcome.count !== undefined ? outcome.count : undefined;\n const plan =\n usesPlans && verb.kind === \"describe\" && counted !== undefined\n ? mint(name, after, counted)\n : undefined;\n // The other half of the join. The event carrying this as `minted` is the\n // one that reported the count; the event carrying the same string as `plan`\n // is the commit that spent it. Together they are the answer to \"3,412 rows\n // were counted here, approved here, and moved here\", which is the question\n // the whole record exists for and the one no single event can answer.\n if (plan !== undefined) trail.minted = plan;\n\n return {\n ok: true,\n ...(counted === undefined ? {} : { count: counted }),\n ...(outcome && outcome.note !== undefined ? { note: outcome.note } : {}),\n ...(plan === undefined ? {} : { plan }),\n snapshot: after,\n };\n }\n\n function no(refused: string, hint: string | undefined, snapshot: Snapshot): Result {\n return { ok: false, refused, ...(hint === undefined ? {} : { hint }), snapshot };\n }\n\n return {\n manifest: () => manifest,\n snapshot: read,\n call,\n approval: {\n // A getter, because this one moves: `none` before a panel mounts and\n // `adopted` after. A snapshotted value would have made every record on\n // the page agree with whichever answer was true when `mount()` returned.\n get policy() {\n return policyNow();\n },\n declared: declaredPolicy,\n /**\n * Hand the gate to a dialog in the page, if nobody else has it.\n *\n * `DriverApproval.adopt` carries the whole argument. What is here is the\n * order of the two refusals, and it is the order on purpose: an app that\n * declared anything wins silently, because `approve: (req) =>\n * panel.approve(req)` is the documented wiring and warning about the\n * recommended arrangement is how a library teaches people to ignore its\n * console. A SECOND adopter is told out loud, because that one is\n * somebody's mistake and the symptom -- a dialog appearing in the other\n * panel -- is otherwise unreadable.\n */\n adopt: (hook: ApprovalHook): (() => void) | null => {\n if (typeof hook !== \"function\") {\n warn(\n `\\`approval.adopt\\` was handed ${JSON.stringify(hook)}, which is not a function, ` +\n `so nothing was installed and commits on this driver are gated by whatever ` +\n `\\`approve\\` the app declared.`,\n );\n return null;\n }\n if (declared !== undefined) return null;\n if (adopted !== undefined) {\n warn(\n `a second approval dialog tried to adopt \\`${options.app}\\` and was refused: the ` +\n `first one keeps the gate, because two gates for one commit is two dialogs. ` +\n `Commits will be confirmed in whichever panel adopted first — including commits ` +\n `started from this one. Mount one panel per driver, or declare the gate yourself ` +\n `with \\`approve\\` so that every panel asks through it.`,\n );\n return null;\n }\n const token = {};\n adopted = hook;\n adoptedBy = token;\n return () => {\n // Only its own. A disposer that fired late and unhooked whoever\n // adopted after it would leave the live panel's dialog silently\n // bypassed, which is this whole change running backwards.\n if (adoptedBy !== token) return;\n adopted = undefined;\n adoptedBy = undefined;\n };\n },\n // Offered whatever the policy is, including `\"none\"`. The widget's\n // in-page dialog is an approval UI on a driver that may well have\n // declared nothing, and it needs the lock exactly as much as the core's\n // own hook does: the agent it is asking is not the only agent that can\n // reach this driver.\n hold: async <T>(verb: string, ask: () => Promise<T>): Promise<T> => {\n const was = pending;\n // `question: false`: this is the lock for an approval UI, which is what\n // `hold` is documented as being for. The core's own question verb takes\n // the lock through `putQuestion`, which sets the other flag.\n pending = { verb, question: false };\n try {\n return await ask();\n } finally {\n pending = was;\n }\n },\n },\n // Offered whether or not a ceiling was declared, so a panel renders one\n // shape. A fresh object per read: handing out a live one would let a UI\n // mutate the app's own accounting.\n budget: () => ({\n calls: { used: callsUsed, ...(budget?.calls === undefined ? {} : { limit: budget.calls }) },\n commits: {\n used: commitsUsed,\n ...(budget?.commits === undefined ? {} : { limit: budget.commits }),\n },\n asks: { used: asksUsed, ...(budget?.asks === undefined ? {} : { limit: budget.asks }) },\n }),\n unmount: () => {\n live = false;\n // Before `live` could matter again: a channel implementation that holds a\n // `BroadcastChannel` open keeps this driver's listener -- and through the\n // closure, this driver -- alive for the life of the page.\n const stop = unlisten;\n unlisten = undefined;\n try {\n stop?.();\n } catch (err) {\n warn(\n `the \\`elsewhere\\` channel threw on unmount ` +\n `(${err instanceof Error ? err.message : String(err)}); the driver is unmounted ` +\n `either way.`,\n );\n }\n },\n };\n}\n\n/**\n * `promise`, or `{ timedOut: true }` after `ms`.\n *\n * Absent or non-positive `ms` waits forever, which is `MountOptions.approvalTimeout`'s\n * documented default: a deadline that denies while somebody is still reading\n * the rows teaches them the dialog is a race. The timer is always cleared, so\n * a hook that answers in time does not hold a Node process open for the rest\n * of the deadline.\n */\nfunction deadline<T>(promise: T | Promise<T>, lapsed: T, ms?: number): Promise<T> {\n if (ms === undefined || !(ms > 0)) return Promise.resolve(promise);\n let timer: ReturnType<typeof setTimeout> | undefined;\n const lapse = new Promise<T>((resolve) => {\n // Deliberately NOT unref'd, and that is not an oversight. `unref` says the\n // timer is not work worth staying alive for -- true right up until the hook\n // never answers. Then the timer is the ONLY pending thing, the event loop\n // concludes it has nothing to do, and the process tears down with the\n // deadline unfired: the one case this helper exists for. In a test runner\n // that surfaced as every later test in the file being CANCELLED rather than\n // failing, which is a far harder symptom to read than a held process.\n // `clearTimeout` in `finally` already buys what `unref` was reaching for.\n timer = setTimeout(() => resolve(lapsed), ms);\n });\n return Promise.race([Promise.resolve(promise), lapse]).finally(() => {\n if (timer !== undefined) clearTimeout(timer);\n });\n}\n\n/**\n * `promise`, or an unanswered question after `ms` -- **defaulting to 45\n * seconds, unlike the approval deadline above, which defaults to forever.**\n *\n * The same timer, a different default, and the inversion is the whole point of\n * this wrapper existing rather than the call site passing a number. Waiting\n * forever on an approval is right because a lapse there DENIES a commit while\n * somebody is still reading; waiting forever on a question is wrong twice over:\n * a lapse denies nothing, and a question that outlives the relay's 60-second\n * deadline turns \"nobody answered\" into the relay's `timeout`, which means\n * nobody knows. Of the two errors, firing late is the expensive one here.\n *\n * The lapse value is `{ answered: false }` and not a `timedOut` shape of its\n * own, because an agent has no use for the difference: a question nobody\n * answered inside the deadline and a question the app reported unanswered are\n * the same fact and the same repair. `AskAnswer` therefore has three values and\n * not four. A non-positive `ms` waits forever, for the app that is only ever\n * driven in-page.\n */\nfunction askDeadline(\n promise: AskAnswer | Promise<AskAnswer>,\n ms?: number,\n): Promise<AskAnswer> {\n return deadline<AskAnswer>(promise, { answered: false }, ms ?? DEFAULT_ASK_TIMEOUT_MS);\n}\n\n/**\n * A short, stable hash of the verb surface.\n *\n * Only the parts an agent can observe go in: names, descriptions, argument\n * shapes, refusals. Not `run`, because reimplementing a verb's body without\n * changing its interface must not invalidate anybody's cached manifest.\n *\n * Not cryptographic and does not need to be. It answers one question -- \"is\n * the copy I cached still the current one\" -- and a collision costs a stale\n * manifest, not a security property.\n */\nfunction fingerprint(\n app: string,\n verbs: Map<string, Verb<any>>,\n instructions?: string,\n screens?: readonly unknown[],\n flows?: readonly unknown[],\n): string {\n // `kind` is in here on purpose. A verb reclassified from `describe` to\n // `commit` has not changed its name or its arguments, so without this the\n // fingerprint would not move and every agent holding a cached manifest would\n // go on believing an irreversible verb is free to try.\n //\n // So is `at`, for the weaker but real version of the same reason: it is part\n // of what a cached manifest claims about the surface, and a UI holding the\n // old copy would outline an element the verb no longer touches.\n //\n // `screen` and `reversible` are in for the strong version of it. Moving a\n // verb to another screen changes where a cached copy says it works, and so\n // does GIVING IT A SECOND ONE -- a verb that now also works on a company's\n // contact list is a verb whose cached description was wrong about where it\n // can be called. Dropping `reversible` from a commit changes whether an agent\n // was told there is a way back -- which is the same class of mistake as a\n // reclassified `kind`.\n //\n // The DECLARED shape is hashed, so `\"contacts\"` and `[\"contacts\"]` give\n // different versions. That is not a wart: they are different bytes in the\n // manifest, a client caching the manifest would see a different document, and\n // a fingerprint that hid the difference would be claiming two cached copies\n // are interchangeable when they do not read the same. So is `instructions`: it is rendered straight into the\n // system prompt, so an agent holding the old manifest is briefed with the\n // app's old words.\n //\n // All three are APPENDED, and only when the app actually used them, so the\n // shape of an app that uses none is the exact string it was before these\n // fields existed. That is not neatness: every stored `Manifest.version` out\n // there was computed from the old string, and an upgrade of this library that\n // silently moved every app's version would tell every agent its cached\n // manifest had gone stale when nothing about the app had changed at all.\n //\n // `consumes` is in for the strongest version of the same reason, and it is\n // the one case where a cached copy being wrong costs a round trip every time:\n // a verb that has started requiring a plan token cannot be called bare any\n // more, so an agent holding the old manifest calls it the old way and is\n // refused `stale-plan` on every attempt, with nothing in its cached\n // description to explain why. Dropping `consumes` is the dangerous direction\n // of the same move -- a commit that USED to demand a receipt and no longer\n // does -- which is the same class of mistake as dropping `reversible`.\n const extras = (v: Verb<any>): Array<Record<string, unknown>> => {\n const e: Record<string, unknown> = {};\n if (v.screen) e.screen = v.screen;\n if (v.reversible) e.reversible = v.reversible;\n if (v.consumes) e.consumes = v.consumes;\n return Object.keys(e).length ? [e] : [];\n };\n\n const shape = JSON.stringify([\n app,\n [...verbs.values()]\n .map((v) => [\n v.name,\n v.describe,\n v.kind ?? null,\n v.at ?? null,\n v.args ?? null,\n v.refuses ?? null,\n ...extras(v),\n ])\n .sort((a, b) => String(a[0]).localeCompare(String(b[0]))),\n ...(instructions ? [instructions] : []),\n // Appended last and only when present, by the same rule as the three\n // above: an app that declares neither hashes the exact string it hashed\n // before these fields existed. Tagged rather than bare, because they are\n // appended at the position `instructions` occupies when an app has no\n // briefing, and two different claims about an app must not be able to hash\n // to one shape.\n //\n // `screens` is in here for the reason `screen` on a verb is: it is what a\n // cached copy claims about where this app can be driven, and a screen that\n // gained a url template or had its sentence rewritten is a screen a model\n // was briefed about in the app's old words. `flows` is in here for the\n // reason `instructions` is -- it is rendered straight into the cached\n // system prompt -- with one extra edge: a flow names verbs, so an app that\n // renames one leaves every cached copy holding a recipe that cites a verb\n // which no longer exists.\n ...(screens ? [{ screens }] : []),\n ...(flows ? [{ flows }] : []),\n ]);\n return hash12(shape);\n}\n"]}
|