clearotron 0.7.0 → 0.8.0-beta.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.
Files changed (98) hide show
  1. package/THIRD-PARTY-NOTICES.md +71 -2
  2. package/build-info.json +2 -2
  3. package/demo/multi-country-focus-search/run/common-law-grid.json +1 -1
  4. package/docs/CLIENT-MCP.md +17 -0
  5. package/docs/assets/README.md +19 -3
  6. package/docs/assets/portal-clearance-report.jpg +0 -0
  7. package/docs/assets/portal-conflict-landscape.jpg +0 -0
  8. package/docs/assets/portal-new-clearance.png +0 -0
  9. package/driver/CHANGELOG.md +48 -0
  10. package/driver/config-inventory.mjs +15 -2
  11. package/driver/dev-portal.mjs +2 -0
  12. package/driver/effort-model.mjs +34 -4
  13. package/driver/engine/CONTRACT.md +8 -0
  14. package/driver/engine/anthropic-agent.mjs +74 -16
  15. package/driver/engine/jx-turn.mjs +11 -3
  16. package/driver/engine/openai-agent.mjs +33 -7
  17. package/driver/engine/run-choices.mjs +28 -7
  18. package/driver/engine/speed.mjs +107 -0
  19. package/driver/enqueue-schema.mjs +8 -0
  20. package/driver/enqueue.mjs +14 -2
  21. package/driver/jx-units.mjs +2 -2
  22. package/driver/jx.mjs +1 -1
  23. package/driver/knockout-plain-language.mjs +96 -0
  24. package/driver/ladder/attempt-record.mjs +14 -2
  25. package/driver/ladder/dispatch.mjs +2 -2
  26. package/driver/ladder/form-repair.mjs +1 -1
  27. package/driver/ladder/stage.mjs +7 -1
  28. package/driver/mark-logos.mjs +6 -1
  29. package/driver/order-receipt.mjs +184 -0
  30. package/driver/package.json +4 -1
  31. package/driver/picture-shrink-worker.mjs +21 -0
  32. package/driver/picture-thumbnail.mjs +132 -0
  33. package/driver/pipeline-knockout.mjs +14 -0
  34. package/driver/portal-confirmation.mjs +3 -0
  35. package/driver/portal-report.mjs +44 -1
  36. package/driver/portal-routes/run.mjs +19 -9
  37. package/driver/portal-runs.mjs +118 -63
  38. package/driver/portal-service.mjs +17 -2
  39. package/driver/predelivery-lint.mjs +3 -3
  40. package/driver/progress.mjs +33 -5
  41. package/driver/publish/column-queries.mjs +86 -0
  42. package/driver/publish/index.mjs +4 -4
  43. package/driver/publish/knockout.mjs +35 -8
  44. package/driver/publish/page-shell.mjs +5 -1
  45. package/driver/publish/read-document.mjs +3 -0
  46. package/driver/publish/render-knockout.mjs +61 -16
  47. package/driver/publish/render.mjs +171 -30
  48. package/driver/publish/search-depth.mjs +45 -1
  49. package/driver/publish/strings.mjs +23 -0
  50. package/driver/publish/templates/report.css +73 -0
  51. package/driver/research-answers.mjs +17 -6
  52. package/driver/research-checks.mjs +22 -4
  53. package/driver/research-records.mjs +81 -0
  54. package/driver/run-quote.mjs +3 -0
  55. package/driver/run-speed.mjs +89 -0
  56. package/driver/runner.mjs +50 -21
  57. package/driver/saved-register-pages.mjs +23 -22
  58. package/driver/stage-freshness.mjs +5 -0
  59. package/driver/stages.mjs +2 -2
  60. package/driver/steps/open-run.mjs +12 -1
  61. package/driver/suite-census.json +199 -37
  62. package/driver/tokens.mjs +3 -0
  63. package/driver/urgent-count.mjs +54 -0
  64. package/driver/usage-ledger.mjs +8 -2
  65. package/driver/web-pictures.mjs +532 -0
  66. package/mcp-server/CHANGELOG.md +16 -0
  67. package/mcp-server/lib/document-reads.mjs +28 -0
  68. package/mcp-server/lib/events.mjs +21 -12
  69. package/mcp-server/lib/findings.mjs +2 -1
  70. package/mcp-server/lib/knockout.mjs +3 -2
  71. package/mcp-server/lib/ops.mjs +103 -6
  72. package/mcp-server/lib/options.mjs +4 -0
  73. package/mcp-server/lib/plan.mjs +38 -4
  74. package/mcp-server/lib/result-shapes.mjs +66 -0
  75. package/mcp-server/lib/runs.mjs +46 -44
  76. package/mcp-server/lib/urgent.mjs +29 -0
  77. package/mcp-server/package.json +1 -1
  78. package/mcp-server/result-shapes.json +2978 -0
  79. package/mcp-server/server.mjs +67 -14
  80. package/package.json +4 -1
  81. package/portal-ui/dist/assets/{index-qNDhqCw9.js → index-DEkVU2FD.js} +1909 -766
  82. package/portal-ui/dist/assets/{index-CxAkJXIT.css → index-W6SAoDkS.css} +238 -1
  83. package/portal-ui/dist/index.html +2 -2
  84. package/portal-ui/package.json +1 -1
  85. package/providers/jx/src/turn-envelope.mjs +3 -1
  86. package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
  87. package/providers/oauth-mcp-bridge/package.json +1 -1
  88. package/providers/signa/src/core.js +54 -12
  89. package/scripts/README.md +3 -0
  90. package/scripts/e2e-first-time.mjs +2 -2
  91. package/scripts/mint-result-shapes.mjs +199 -0
  92. package/scripts/readme-pictures.mjs +227 -0
  93. package/scripts/render-check.mjs +4 -1
  94. package/scripts/report-sections-render-check.mjs +191 -0
  95. package/scripts/settings-render-check.mjs +68 -11
  96. package/shared/brand.mjs +8 -0
  97. package/skills/clearotron-account/SKILL.md +24 -0
  98. package/skills/clearotron-ops/SKILL.md +23 -9
@@ -9,13 +9,13 @@ file rather than a courtesy.
9
9
  production tree; `--check` fails when it no longer matches. Development dependencies are excluded:
10
10
  they are not distributed, so they carry no obligation for anyone who installs this.
11
11
 
12
- 176 packages.
12
+ 179 packages.
13
13
 
14
14
  > **Declared but NOT INSTALLED, so not distributed and not attributed below:** `@cfworker/json-schema`.
15
15
  > npm lists these with no version and no path — an unmet or optional peer. Recorded because a name
16
16
  > silently missing from this file reads the same as one that was never declared.
17
17
 
18
- > **Declaring a licence but shipping no licence file:** `binary@0.3.0`, `chainsaw@0.1.0`, `isarray@1.0.0`, `saxes@5.0.1`.
18
+ > **Declaring a licence but shipping no licence file:** `binary@0.3.0`, `chainsaw@0.1.0`, `isarray@1.0.0`, `omggif@1.0.10`, `saxes@5.0.1`.
19
19
  > The declaration is reproduced below; there is no notice text to reproduce with it.
20
20
 
21
21
  ---
@@ -2811,6 +2811,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2811
2811
  SOFTWARE.
2812
2812
  ```
2813
2813
 
2814
+ ## jpeg-js@0.4.4
2815
+
2816
+ - **Licence declared:** `BSD-3-Clause`
2817
+ - **Repository:** https://github.com/eugeneware/jpeg-js
2818
+ - **Licence file:** `LICENSE`
2819
+
2820
+ ```
2821
+ Copyright (c) 2014, Eugene Ware
2822
+ All rights reserved.
2823
+
2824
+ Redistribution and use in source and binary forms, with or without
2825
+ modification, are permitted provided that the following conditions are met:
2826
+
2827
+ 1. Redistributions of source code must retain the above copyright
2828
+ notice, this list of conditions and the following disclaimer.
2829
+ 2. Redistributions in binary form must reproduce the above copyright
2830
+ notice, this list of conditions and the following disclaimer in the
2831
+ documentation and/or other materials provided with the distribution.
2832
+ 3. Neither the name of Eugene Ware nor the names of its contributors
2833
+ may be used to endorse or promote products derived from this software
2834
+ without specific prior written permission.
2835
+
2836
+ THIS SOFTWARE IS PROVIDED BY EUGENE WARE ''AS IS'' AND ANY
2837
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2838
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2839
+ DISCLAIMED. IN NO EVENT SHALL EUGENE WARE BE LIABLE FOR ANY
2840
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2841
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2842
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2843
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2844
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2845
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2846
+ ```
2847
+
2814
2848
  ## json-schema-traverse@1.0.0
2815
2849
 
2816
2850
  - **Licence declared:** `MIT`
@@ -4699,6 +4733,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4699
4733
  SOFTWARE.
4700
4734
  ```
4701
4735
 
4736
+ ## omggif@1.0.10
4737
+
4738
+ - **Licence declared:** `MIT`
4739
+ - **Repository:** https://github.com/deanm/omggif
4740
+ - **Licence file:** none shipped
4741
+
4702
4742
  ## on-finished@2.4.1
4703
4743
 
4704
4744
  - **Licence declared:** `MIT`
@@ -4925,6 +4965,35 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4925
4965
  SOFTWARE.
4926
4966
  ```
4927
4967
 
4968
+ ## pngjs@7.0.0
4969
+
4970
+ - **Licence declared:** `MIT`
4971
+ - **Repository:** git://github.com/pngjs/pngjs
4972
+ - **Licence file:** `LICENSE`
4973
+
4974
+ ```
4975
+ pngjs original work Copyright (c) 2015 Luke Page & Original Contributors
4976
+ pngjs derived work Copyright (c) 2012 Kuba Niegowski
4977
+
4978
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4979
+ of this software and associated documentation files (the "Software"), to deal
4980
+ in the Software without restriction, including without limitation the rights
4981
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4982
+ copies of the Software, and to permit persons to whom the Software is
4983
+ furnished to do so, subject to the following conditions:
4984
+
4985
+ The above copyright notice and this permission notice shall be included in
4986
+ all copies or substantial portions of the Software.
4987
+
4988
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4989
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4990
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4991
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4992
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4993
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4994
+ THE SOFTWARE.
4995
+ ```
4996
+
4928
4997
  ## process-nextick-args@2.0.1
4929
4998
 
4930
4999
  - **Licence declared:** `MIT`
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "commit": "81413aeb5f29da3351cfd2caf0a53783efd9c1be",
3
- "version": "0.7.0"
2
+ "commit": "10ba73b208425fac64c303d7f19808f07225996e",
3
+ "version": "0.8.0-beta.0"
4
4
  }
@@ -3190,7 +3190,7 @@
3190
3190
  "url": "https://qdro.com/company-qdro/VE/"
3191
3191
  },
3192
3192
  {
3193
- "title": "FDA points to liver injury with Amgen's Tavneos",
3193
+ "title": "FDA points to liver injury with Tavneos",
3194
3194
  "url": "https://pharmaphorum.com/news/fda-points-liver-injury-amgens-tavneos"
3195
3195
  },
3196
3196
  {
@@ -28,6 +28,23 @@ each its own. The ops face is never on the internet. If you are looking for the
28
28
  use, it is the Client face. The API-key door is that same client face reached with a credential instead of a
29
29
  browser login — see "The API-key door" below.
30
30
 
31
+ ## What each tool answers
32
+
33
+ Every tool lists the shape of its answer as an `outputSchema` and returns that answer as
34
+ `structuredContent`, beside the same text block as before. A host that reads only the text sees no
35
+ change. The shapes are in `mcp-server/result-shapes.json`, one entry per tool, so a change to an answer
36
+ shows in a diff of that file.
37
+
38
+ - A tool whose answer differs by session has two entries: `client` for sessions on the Client face and the
39
+ API-key door, whose answers are the scrubbed cut, and `staff` for every other session.
40
+ - The six tools that change something (`start_run`, `stop_run`, `feed_context`, `what_if_run`,
41
+ `mark_sent`, `ack_event`) add an `outcome` field that says whether it happened. A refusal answers
42
+ `outcome: "refused"`, with the refusal's sentence in `reason`.
43
+ - The six report readers (`brief`, `list_findings`, `get_finding`, `list_evidence`, `list_searches`,
44
+ `get_search_coverage`) add a `document` field naming the report document version they read, such as
45
+ `report-document/clearance-1`, or null where they read the run's own files.
46
+ - A list goes out under `items`, because a structured answer is an object.
47
+
31
48
  ## The two principals outside your staff
32
49
 
33
50
  **`user` — a run-bound report link.** A read-only token pinned to one run, no enumeration. The scope
@@ -8,9 +8,9 @@ written down here rather than left in a commit message.
8
8
  |---|---|---|
9
9
  | `clearotron-banner-light.svg` | The README masthead, light scheme | Hand-made brand source |
10
10
  | `clearotron-banner-dark.svg` | The same masthead for `prefers-color-scheme: dark` | Hand-made brand source |
11
- | `portal-clearance-report.jpg` | A finished clearance report — verdict, risk band, the four answers | Portal screenshot |
12
- | `portal-conflict-landscape.jpg` | Findings placed by mark similarity against goods proximity, with rights-holders by jurisdiction | Portal screenshot |
13
- | `portal-new-clearance.png` | The intake screen — classes, marketplaces, search depth | Portal screenshot |
11
+ | `portal-clearance-report.jpg` | A finished clearance report — verdict, risk band, the four answers | Clearotron 0.8.0, taken on its line before the first beta: `node scripts/readme-pictures.mjs` |
12
+ | `portal-conflict-landscape.jpg` | Findings placed by mark similarity against goods proximity, with rights-holders by jurisdiction | Clearotron 0.8.0, taken on its line before the first beta: `node scripts/readme-pictures.mjs` |
13
+ | `portal-new-clearance.png` | The intake screen — classes, marketplaces, search depth | Clearotron 0.8.0, taken on its line before the first beta: `node scripts/readme-pictures.mjs` |
14
14
 
15
15
  ## Two things worth knowing before changing anything here
16
16
 
@@ -23,6 +23,22 @@ quietly showing a hole.
23
23
  not produces a page whose image cannot load — a defect that shipped here once already, and one the test
24
24
  above now asserts against directly rather than leaving to review.
25
25
 
26
+ ## Retaking the three portal pictures
27
+
28
+ `portal-new-clearance.png`, `portal-clearance-report.jpg` and `portal-conflict-landscape.jpg` show the
29
+ portal, so they go stale whenever it changes. One command retakes all three from this checkout's own demo:
30
+
31
+ ```sh
32
+ npm run build:ui
33
+ node scripts/readme-pictures.mjs
34
+ ```
35
+
36
+ It starts the demo in a throwaway home, signs in, and captures New clearance, the demo's Global
37
+ preliminary search report, and that report's conflict landscape. The captures are in the light theme at
38
+ 1,332 × 778 CSS pixels and device scale 1.5. It writes over the three files here and prints the line for
39
+ the table above. Only the committed demo is on screen. Run it whenever a change alters one of those
40
+ screens or regenerates `demo/`, look at each picture before committing it, and never edit one by hand.
41
+
26
42
  ## Adding one
27
43
 
28
44
  Put the file here, embed it in the document that needs it, and add a row above. A new image **type**
@@ -1,5 +1,53 @@
1
1
  # clearotron-driver
2
2
 
3
+ ## 0.8.0-beta.0
4
+
5
+ ### Minor Changes
6
+
7
+ - New: In the portal, each full conflict card of a clearance or Knockout report has a "Copy link" control beside "Ask AI about this finding", which copies an address that opens the report at that card.
8
+ - New: On a clearance report's conflict cards, the registered logos sit in a frame labelled "Register", so a reader can tell where those pictures come from.
9
+ - New: On a clearance report's conflict chart, pointing at a dot or moving keyboard focus to it shows that conflict's mark, rating, owner and country beside it, and a screen reader hears the same.
10
+ - Fixed: On Claude, a step stopped at its time limit while still working now resumes where it was. Before, Claude refused to resume it, and the step's retry was used up on that refusal.
11
+ - New: On a wide or laptop screen, pressing a conflict number in a clearance report's verdict opens that conflict's card in a panel beside the text, so the reader keeps their place; on a laptop the report's column narrows to make room.
12
+ - Fixed: Two companies, or two organisations under Generic, that order the same mark and classes on the same day each get their search. Only the same account's repeat order is held as a duplicate, and its notice names only that account's earlier order.
13
+ - New: On a Knockout report, each register filing's card shows that filing's registered logo in a frame labelled "Register", where the run fetched one.
14
+ - Fixed: A Knockout resumed after a failed attempt now carries on from the step that failed. It used to run every step again from the reading of the order, which could frame the order differently the second time.
15
+ - Fixed: On an installation that uses Signa, a logo image the register could not serve for a moment is asked for once more, so fewer cards lose a logo to a brief outage.
16
+ - New: An order marked Urgent is quoted at 30 minutes to 1 hour for a clearance and 3 to 6 minutes for a Knockout, and counts as two searches against the account's daily and monthly allowance. Where the installation's AI service has no faster setting, the order runs at Standard and counts as one search. With one search left today, an Urgent order is refused with "1 search left today." rather than run at Standard.
17
+ - New: The Clearances list shows each company, family, name and search on its own row, on a desktop and on a phone. A name with one report has an "Open report" button, a name with several opens its latest report, and each earlier search opens its own report.
18
+
19
+ New: Find a name, then narrow the list under Filters by company, search type, sort order and company grouping. Each filter in force shows as a chip that removes it.
20
+
21
+ New: "Group names" makes a family from names in one company, and a family's menu adds names or ungroups it. Retiring a search, or every search of a name, asks first and says what moves. The Retired tab lists each retired search with Restore, and a failed search restores to Failed.
22
+ - For operators: an order retried with the id of one that was already refused, parked or finished is no longer queued a second time. `enqueue` exits 3, as it already did for an order still waiting, and prints what became of the first order: its state, the reason it was refused, and its run id. The connector's `start_run` refuses the retry and says the same.
23
+ - Fixed: "Expand all" and "Collapse all" reach every fold of a clearance or Knockout report, the register records' term lists included; the key's common-law row no longer runs its label under its count; and a PDF's folded-list header counts only the cards it prints.
24
+ - New: A running search's card on Home now lists every step by name, ticking those done and marking the one in progress, in place of a row of unlabelled bars.
25
+
26
+ New: A Global preliminary or Multi-country focus search now names its sixth step "Checking the conclusions" on Home, in the Clearances list and in its status, since neither search reads case law.
27
+ - New: Installation settings now groups its sources under Needed and Optional, so a source a search can run without no longer reads as a fault, and the common-law row says a Knockout search can still run while its key is missing.
28
+
29
+ New: A row on Installation settings that the setup wizard fixes now shows its command, with a Copy button, beside the Setup guide.
30
+ - New: New clearance folds the company's settings into one line with a "Change" button, and Which search shows the chosen search with the other three behind "All four searches"; every control is still there.
31
+
32
+ New: On an installation that cannot read a brief, New clearance no longer offers a box to write one in, so typing starts at Names to clear.
33
+ - New: New clearance has a How soon choice below Which search. Standard is chosen by default, and Urgent runs the same search on the AI fast mode setting, at increased cost, and uses 2 searches. Each option shows its turnaround and how many searches it uses, and the footer and the review show the chosen one. Where the installation's AI service has no faster setting, Urgent is shown but cannot be chosen, and says why. With one search left today, Urgent cannot be chosen either, and says "1 search left today." beside its cost.
34
+
35
+ New: The footer's Uses figure says how many searches the account has left today.
36
+ - Fixed: The README's three pictures of the portal show today's screens, taken from the demo: New clearance, a finished report, and its conflict landscape.
37
+ - New: Once a reader scrolls past a report's header, it becomes one pinned row with the section links, Ask AI, Export and a "Search history" button listing the name's other searches. Where the window is too narrow for that row, the whole header stays pinned instead.
38
+
39
+ New: The label over a report's other searches now reads "Search history", and the list tells apart two reports of one day by their time, marks the latest report and shows a search still running.
40
+ - Fixed: On an installation that uses Signa, a Knockout report's listed filings open their register record, read from the search the run already holds, so the report asks the register nothing more.
41
+ - New: When a search finishes or stops while the portal's tab is out of view, the tab's title leads with a count, such as "(1)", until the tab is looked at again.
42
+ - New: In a clearance report, the folded list of lower-rated conflicts has a "Show all" control with its count at the right of its header, and looks like a pile of cards while folded, so it is harder to miss.
43
+ - Fixed: A clearance report's list of web and marketplace names prints every name its count includes, links each one only to a web address, opening in a new tab, and no longer lists a search note as a name.
44
+ - Fixed: In the dark theme, the addresses in a clearance report's list of web and marketplace names are drawn in the page's link colour instead of dark red on the dark background.
45
+
46
+ ### Patch Changes
47
+
48
+ - Fixed: On an install that names its workspaces with its own prefix, the portal's run list now shows the searches in progress there. It used to show none of them, while the connector listed them.
49
+ - Fixed: The portal's list of retired searches shows retired searches only. It used to show every search still waiting to start as well.
50
+
3
51
  ## 0.7.0
4
52
 
5
53
  ### Minor Changes
@@ -45,7 +45,7 @@ import {
45
45
  import {
46
46
  resolveAuthMode, billingMode, billingRefusalReason, cloudName,
47
47
  } from "./engine/auth.mjs";
48
- import { billingRefusalWords } from "./run-requirements.mjs"; // — a refusal that quotes the billing word says it by name
48
+ import { billingRefusalWords, RESEARCH_ENV } from "./run-requirements.mjs"; // — a refusal that quotes the billing word says it by name; the research key a search refuses without
49
49
  import { CASELAW_BRIDGES } from "./engine/mcp/gather-config.mjs"; // — the list that decides what is spawned
50
50
  import { existsSync, readFileSync, statSync } from "node:fs";
51
51
  import { join } from "node:path";
@@ -189,6 +189,16 @@ export function engineMode(inventory, { probe = null } = {}) {
189
189
  * capability each instance either has or lacks, so it is one row naming the selected provider — or
190
190
  * naming none, which is itself a missing row and the state a fresh install is in.
191
191
  */
192
+ // ── WHICH SOURCES A SEARCH REFUSES TO RUN WITHOUT, the one answer Installation settings groups by ──────
193
+ //
194
+ // `needed` is true where at least one search refuses to start without the source, which is what the
195
+ // order door's own requirements say (run-requirements.mjs): the register, which every search reads, and
196
+ // the research key, RESEARCH_ENV, which the three clearance searches refuse without (a Knockout runs and
197
+ // says so on its report). Everything else a search runs without and discloses: the Chinese marketplace
198
+ // key and every case-law source. Read off the adapter's own credential name, so a research adapter that
199
+ // is not the one the door asks for is optional by the same rule.
200
+ const neededBySearch = (adapter) => [adapter?.credEnv, ...(adapter?.credEnvAlso ?? [])].includes(RESEARCH_ENV);
201
+
192
202
  export function providerInventory(env = process.env) {
193
203
  const rows = [];
194
204
 
@@ -206,6 +216,7 @@ export function providerInventory(env = process.env) {
206
216
  // With no provider selected there is no credential to be missing, and the thing to set is the
207
217
  // selector itself. `activeProvider` throws on an unknown id, so that case names the selector too.
208
218
  missing: register ? shown(missingCredentials(register, env)) : shown(["CLEAROTRON_DATABASE"]),
219
+ needed: true, // every search reads a register, and the order door refuses without one
209
220
  });
210
221
 
211
222
  for (const [group, label, table] of [
@@ -224,6 +235,7 @@ export function providerInventory(env = process.env) {
224
235
  known: true,
225
236
  configured: missing.length === 0,
226
237
  missing: shown(missing),
238
+ needed: neededBySearch(adapter),
227
239
  });
228
240
  }
229
241
  }
@@ -233,7 +245,8 @@ export function providerInventory(env = process.env) {
233
245
  // Appended to the SAME list, so every reader of this inventory gets them with no edit: the config
234
246
  // screen renders rows generically, the flag snapshot carries whatever this returns, and the doctor
235
247
  // reads the same function. A separate list would be the hand-kept census this issue is about.
236
- rows.push(...caseLawInventory(env));
248
+ // Every case-law source is one a search runs without: the report discloses the gap.
249
+ rows.push(...caseLawInventory(env).map((r) => ({ ...r, needed: false })));
237
250
  return rows;
238
251
  }
239
252
 
@@ -82,6 +82,8 @@ export const DEV_COCKPIT_JOB_FIELDS = Object.freeze({
82
82
  + "from its own form and writes no sidecars, so it may not claim that shape.",
83
83
  forwarderDomain: "the cockpit's assembler defaults it; a dev form has no forwarding domain to state.",
84
84
  provider: "which register vendor answers is the dev instance's own configuration, not a form field.",
85
+ urgent: "an Urgent order. The order screens and the connector carry it with its count of searches; this dev "
86
+ + "form has no such option, and a dev job that needs one is written as a job file.",
85
87
  name: "the pre-markName spelling of the search subject. The form posts `mark`.",
86
88
  use: "the pre-goods spelling of the goods description. The form posts `goods`.",
87
89
  tmp: "the pre-ref spelling of the reference number. The form posts `ref`.",
@@ -56,8 +56,17 @@
56
56
  * is 1 for every job any door will admit, so the removed term was 1 on every quote that has ever
57
57
  * been stored. No version-3 quote in any run record holds a number this table would not reproduce.
58
58
  * The bump is the shape rule being followed, not a figure being corrected.
59
+ * 6 — an Urgent order (ruling 2026-11-25): the same search on the AI service's faster setting. It counts
60
+ * as two searches against an allowance and quotes its own ruled turnaround row. No weight moved and
61
+ * the work units are untouched, because the work is the same; the count and the quote moved.
59
62
  */
60
- export const UNITS_VERSION = 5;
63
+ export const UNITS_VERSION = 6;
64
+
65
+ /**
66
+ * HOW MANY SEARCHES AN URGENT ORDER COUNTS AS (ruling 2026-11-25). One constant, read by the quote and by
67
+ * admission alike, so "uses 2" is the number shown and the number charged.
68
+ */
69
+ export const URGENT_SEARCHES = 2;
61
70
 
62
71
  // The grid-cell budgets, restated from profiles.mjs (SAFE_GRID_CELLS / DENSE_GRID_CELLS) rather than
63
72
  // imported: this module is the SERVER half of a twin whose other half is a browser bundle, and it is kept
@@ -86,6 +95,8 @@ export const DENSE_GRID_CELLS = 16;
86
95
  * offering has one toggle and the engine routes it from the territories in scope.
87
96
  * registerCounts register filing counts per name. The knockout's, and only there.
88
97
  * territories the resolved scope. Length 1 is the deep-dive increment.
98
+ * urgent the order runs on the AI service's faster setting. Not machinery: the same search,
99
+ * the same work. It moves only the count and the turnaround row.
89
100
  */
90
101
  const leversOf = (l) => ({
91
102
  pipeline: l?.pipeline === "knockout" ? "knockout" : "clearance",
@@ -93,6 +104,7 @@ const leversOf = (l) => ({
93
104
  nativeLanguage: Boolean(l?.nativeLanguage),
94
105
  registerCounts: Boolean(l?.registerCounts),
95
106
  territories: Array.isArray(l?.territories) ? l.territories : [],
107
+ urgent: l?.urgent === true,
96
108
  });
97
109
 
98
110
  /** Which pipeline these levers describe. There is no third answer: "no-search" went with the levers that
@@ -144,6 +156,13 @@ export const gridCalls = (i) => Math.ceil(variantCount(i.levers) / batchSize(i.p
144
156
  export const runCount = (i) =>
145
157
  deriveMode(i.levers) === "knockout" ? 1 : Math.max(1, Number(i.names) || 0);
146
158
 
159
+ /**
160
+ * WHAT THE ORDER COUNTS AGAINST AN ALLOWANCE: its searches, twice over when Urgent. Kept apart from
161
+ * `runCount` on purpose: `runCount` scales the WORK (`effortRaw` multiplies by it), and an Urgent search
162
+ * is the same work run faster, so folding Urgent into it would double the units and the bar.
163
+ */
164
+ export const searchesCounted = (i) => runCount(i) * (leversOf(i.levers).urgent ? URGENT_SEARCHES : 1);
165
+
147
166
  /**
148
167
  * The weights. PLACEHOLDERS — the register share is the one that moved (2026-07-21): registers carry a
149
168
  * base of 14 and 2 per class, which is what puts a clearance's register half where a client would expect
@@ -256,10 +275,15 @@ export const TURNAROUND_QUOTE = Object.freeze({
256
275
  // delivered when the ruling was made: 4-6 minutes, against 45 quoted. So 5-10 is closer to the measured
257
276
  // wall than 15 was, and a range that spans it says something a single figure cannot.
258
277
  knockout: Object.freeze({ lowHours: 5 / 60, highHours: 10 / 60 }),
278
+ // — URGENT, ONE RULED ROW PER PIPELINE (ruling 2026-11-25): 0.5 to 1 hour for a clearance, 3 to 6
279
+ // minutes for a Knockout. A row of its own, looked up like the two above: not a factor applied to them.
280
+ clearanceUrgent: Object.freeze({ lowHours: 0.5, highHours: 1 }),
281
+ knockoutUrgent: Object.freeze({ lowHours: 3 / 60, highHours: 6 / 60 }),
259
282
  });
260
283
 
261
284
  /** Which row of the table a job's levers select. The ONLY place that choice is made. */
262
- export const quoteBoundsFor = (l) => TURNAROUND_QUOTE[deriveMode(l) === "knockout" ? "knockout" : "clearance"];
285
+ export const quoteBoundsFor = (l) =>
286
+ TURNAROUND_QUOTE[`${deriveMode(l) === "knockout" ? "knockout" : "clearance"}${leversOf(l).urgent ? "Urgent" : ""}`];
263
287
 
264
288
  /**
265
289
  * The bounds for THIS job. The ruled range, and NOTHING is done to it.
@@ -315,6 +339,9 @@ export function turnaround(i) {
315
339
  const lo = Math.round(lowHours * 60), hi = Math.round(highHours * 60);
316
340
  return lo === hi ? `~${hi} min` : `${lo}–${hi} min`;
317
341
  }
342
+ // A range that starts under an hour and ends at one or more says each bound in its own unit: the Urgent
343
+ // clearance row reads "30 min–1 hour", never "0.5–1 hours".
344
+ if (lowHours < 1) return `${Math.round(lowHours * 60)} min–${fmtHours(highHours)} ${highHours === 1 ? "hour" : "hours"}`;
318
345
  if (lowHours === highHours) return `~${fmtHours(highHours)} ${highHours === 1 ? "hour" : "hours"}`;
319
346
  return `${fmtHours(lowHours)}–${fmtHours(highHours)} hours`;
320
347
  }
@@ -331,7 +358,7 @@ export function turnaround(i) {
331
358
  * `components` is the search-policy block (registerProbe / jxLanes / commonLawGrid) — the engine's own
332
359
  * statement of what the run will do, not a second opinion about it.
333
360
  */
334
- export function leversFromResolved({ pipeline, components, caseLaw = false, territories = [] } = {}) {
361
+ export function leversFromResolved({ pipeline, components, caseLaw = false, territories = [], urgent = false } = {}) {
335
362
  const c = components ?? {};
336
363
  const knockout = pipeline === "knockout";
337
364
  return {
@@ -340,6 +367,7 @@ export function leversFromResolved({ pipeline, components, caseLaw = false, terr
340
367
  nativeLanguage: Boolean(c.jxLanes),
341
368
  registerCounts: knockout && Boolean(c.registerProbe),
342
369
  territories: Array.isArray(territories) ? territories : [],
370
+ urgent: urgent === true,
343
371
  };
344
372
  }
345
373
 
@@ -356,10 +384,12 @@ export function quoteEffort(input) {
356
384
  return {
357
385
  unitsVersion: UNITS_VERSION,
358
386
  pipeline: deriveMode(i.levers),
387
+ urgent: i.levers.urgent,
359
388
  raw: Number(effortRaw(i).toFixed(4)),
360
389
  units: effortUnits(i),
361
390
  costBand: costBand(i),
362
- searches: runCount(i),
391
+ // What the order counts against an allowance, Urgent included: the number admission charges.
392
+ searches: searchesCounted(i),
363
393
  checksPerName: checksPerName(i.platforms),
364
394
  gridCalls: deriveMode(i.levers) === "knockout" ? 0 : gridCalls(i),
365
395
  turnaroundHours: turnaroundHours(i),
@@ -45,6 +45,14 @@ ladder consumes it without knowing which engine produced it ([gateway.mjs](../ga
45
45
  // null = nothing was observed, never the requested alias
46
46
  providerWire: string | null, // PROVIDER GAUGE — the program's own word for who served the turn
47
47
  // ("firstParty", "foundry"); null = not said, or said inconsistently
48
+ speed: Speed, // SPEED GAUGE — what the turn asked for beside what the program
49
+ // reported serving (engine/speed.mjs): { requested: "standard"|"fast",
50
+ // standardBecause, served, basis: "reported"|"unknown", calls, state,
51
+ // disabledReason, notice }. `requested` is what was sent: a turn asked
52
+ // for fast on a model with no faster setting sends standard, and
53
+ // `standardBecause` says so ("model-not-fast"). Claude reports each
54
+ // call's `usage.speed` and its fast_mode_state; Codex reports none, so
55
+ // served is null and basis "unknown" on every turn, fast or not
48
56
  signals: { stalled?, noProgress?, hardWall?, rateLimited?, rateLimitBasis?, resetsAt?,
49
57
  resetsAtBasis?, usageStreamed?, noStreamEvents?, thought: bool|null },
50
58
  // THINKING GAUGE — see below.
@@ -20,7 +20,8 @@ import { tmpdir } from "node:os";
20
20
  import { join, dirname } from "node:path";
21
21
  import { fileURLToPath } from "node:url";
22
22
  import { claudeTurnInstructions, FILE_OUTPUT, absolutizeSkillRefs, resolveSpawnCwd, spawnGraceMs, isRecordTool, stallMs, engineMaxBufferChars, startGovernedChild, governWatchdog, readGovernedStreams } from "./common.mjs"; // the child, its watchdog, its reader, and the stall and buffer limits both engines share
23
- import { resolveEngineProgram, resolveModel } from "../driver.config.mjs"; // — the one place that finds the program; it reads every spelling of the setting
23
+ import { resolveEngineProgram, resolveModel } from "../driver.config.mjs";
24
+ import { sessionSpeed } from "./speed.mjs"; // — whether this session's model can take the speed its run asks for // — the one place that finds the program; it reads every spelling of the setting
24
25
  import { authorityTrees } from "../authority-trees.mjs";
25
26
  import { clearEngineChild } from "./child-record.mjs"; // the shared child (startGovernedChild) writes the record; this clears it at settle
26
27
  import { engineEnv } from "./engine-env.mjs"; // — the program's environment, by list (see spawnEnv)
@@ -338,14 +339,17 @@ export const OWN_SEARCH_TOOLS = Object.freeze(["WebSearch"]);
338
339
  /** The program's tools that write a file. A result that comes back an error is a write that failed. */
339
340
  const FILE_WRITE_TOOLS = Object.freeze(["Write", "Edit", "MultiEdit", "NotebookEdit"]);
340
341
 
341
- export function buildClaudeArgs({ message, model, thinking, resumeRef, mcpConfig, allowedTools, builtinTools = null, output = FILE_OUTPUT, maxBudgetUsd, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites = null, grantDispatch = null }) {
342
+ export function buildClaudeArgs({ message, model, thinking, speed = "standard", resumeRef, mcpConfig, allowedTools, builtinTools = null, output = FILE_OUTPUT, maxBudgetUsd, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites = null, grantDispatch = null }) {
342
343
  const input = absolutizeSkillRefs(message, skillsDir, resolveSkill);
343
344
  const args = ["-p", "--output-format", "stream-json", "--verbose", "--include-partial-messages"];
344
345
  const m = claudeModel(model); if (m) args.push("--model", m);
345
346
  args.push("--effort", effortFor(thinking));
346
- // FAST MODE REMOVED (2026-06-17): the Opus `--settings {"fastMode":true}` knob ~2.5×'d subscription-billed
347
- // usage and tripped the Claude 5-hour session cap mid-run (overage org-disabled → hard 429 → every stage
348
- // nonzero_exit_1). Reverted everywhere; HIGH effort is retained on the verdict/safety stages.
347
+ // THE SPEED is a setting, not a flag: `fastMode` in the one `--settings` value below (stageSettings), the vendor's
348
+ // unattended form (https://code.claude.com/docs/en/fast-mode, "Toggle fast mode": `claude -p --settings
349
+ // '{"fastMode": true}'`, v2.1.205 or later). Every session of an Urgent run asks for it where the model sent above has
350
+ // a faster setting (engine/speed.mjs, sessionSpeed); on any other model it is not asked for, so the model stays the
351
+ // one the stage chose, and the turn's record says why it ran at standard speed.
352
+ const sp = sessionSpeed({ ordered: speed, engine: "anthropic-agent", model: m });
349
353
  // Stages WRITE their output file; acceptEdits auto-approves Write/Edit in non-interactive -p (Read is
350
354
  // always allowed). Gather tools (E3) ride --allowedTools so they never prompt either.
351
355
  args.push("--permission-mode", "acceptEdits");
@@ -399,8 +403,8 @@ export function buildClaudeArgs({ message, model, thinking, resumeRef, mcpConfig
399
403
  const granted = rd.grant ? runDir : null;
400
404
  if (granted) args.push("--add-dir", granted);
401
405
  const boundary = writeBoundarySettings({ skillsRoots: grantRoots, profilesDir, runDir: granted });
402
- args.push("--settings", stageSettings(boundary));
403
- return { args, input, grantNote: rd.note };
406
+ args.push("--settings", stageSettings(boundary, { fast: sp.sent === "fast" }));
407
+ return { args, input, grantNote: rd.note, speed: sp };
404
408
  }
405
409
 
406
410
  /**
@@ -416,9 +420,13 @@ export function buildClaudeArgs({ message, model, thinking, resumeRef, mcpConfig
416
420
  */
417
421
  export const READ_FENCE = Object.freeze({ blockReadsOutsideWorkingDirectories: true });
418
422
 
419
- /** The one `--settings` value a turn carries: the read fence, and the write boundary's hook when there is one. */
420
- export function stageSettings(boundary) {
421
- return JSON.stringify({ permissions: { ...READ_FENCE }, ...(boundary ? JSON.parse(boundary) : {}) });
423
+ /**
424
+ * The one `--settings` value a turn carries: the read fence, the write boundary's hook when there is one, and the faster
425
+ * speed when the turn asks for it. One value, because the program reads one `--settings`: a second would replace the
426
+ * first, and the boundary with it.
427
+ */
428
+ export function stageSettings(boundary, { fast = false } = {}) {
429
+ return JSON.stringify({ permissions: { ...READ_FENCE }, ...(boundary ? JSON.parse(boundary) : {}), ...(fast ? { fastMode: true } : {}) });
422
430
  }
423
431
 
424
432
  /**
@@ -495,9 +503,9 @@ export const anthropicAgentEngine = {
495
503
  writeBoundary: "enforced",
496
504
  // The id a turn's rows record as asked for: the tier through Claude's catalog, `opus` → `anthropic/claude-opus`.
497
505
  resolveModelId(model) { return resolveModel(model); },
498
- async runTurn({ message, model, thinking, timeoutSec, resumeRef, mcpConfig, allowedTools, builtinTools = null, output = FILE_OUTPUT, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites = null, grantDispatch = null, stallSec, progressFiles, streamFile = null } = {}) {
506
+ async runTurn({ message, model, thinking, speed = "standard", timeoutSec, resumeRef, mcpConfig, allowedTools, builtinTools = null, output = FILE_OUTPUT, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites = null, grantDispatch = null, stallSec, progressFiles, streamFile = null } = {}) {
499
507
  if (!message) throw new Error("anthropic-agent.runTurn: message is required");
500
- const { args, input, grantNote } = buildClaudeArgs({ message, model, thinking, resumeRef, mcpConfig, allowedTools, builtinTools, output, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites, grantDispatch });
508
+ const { args, input, grantNote, speed: sent } = buildClaudeArgs({ message, model, thinking, speed, resumeRef, mcpConfig, allowedTools, builtinTools, output, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites, grantDispatch });
501
509
  // the cross-check speaks. Driver stderr is what an operator reads, and it is where the other
502
510
  // drift notices in this engine already land ([ledger], [env-aliases], [queue-watch]).
503
511
  if (grantNote) process.stderr.write(`${grantNote}\n`);
@@ -521,7 +529,7 @@ export const anthropicAgentEngine = {
521
529
  const pollMs = Math.max(50, Math.min(1000, Math.floor(Math.min(STALL, NOPROG) / 2))); // tight enough for fast tests, ≤1s in prod
522
530
  return await new Promise((resolve) => {
523
531
  // The turn's state, which every phase below reads and writes (the phases follow the adapter).
524
- const st = { resolve, resumeRef, cwd, runDir, progressFiles, streamFile, args, input, t0, STALL, NOPROG, MIN_RATE, WARMUP, hardMs, pollMs };
532
+ const st = { resolve, resumeRef, cwd, runDir, progressFiles, streamFile, args, input, t0, STALL, NOPROG, MIN_RATE, WARMUP, hardMs, pollMs, speed: sent.sent, standardBecause: sent.standardBecause };
525
533
  st.settle = (code) => settle(st, code); // declared before any phase, as the hoisted function it was
526
534
  if (!spawnTurn(st)) return;
527
535
  streamState(st);
@@ -597,6 +605,13 @@ function streamState(st) {
597
605
  // and no open message is a call of its own, as it always was.
598
606
  st.perMessage = new Map();
599
607
  st.openMessage = null; st.anonMessages = 0;
608
+ // SPEED GAUGE: the speed each API call reports it was served at (`usage.speed`), by message, as the usage above is.
609
+ // Read from the program's own output, never from what the turn asked for (engine/speed.mjs).
610
+ st.speedByMessage = new Map();
611
+ st.noteSpeed = (key, u) => { if (typeof u?.speed === "string" && u.speed) st.speedByMessage.set(key, u.speed); };
612
+ st.fastInit = null; // init's fast_mode_state and fast_mode_disabled_reason: the session's start
613
+ st.fastNotice = null; // the program's own notice about fast mode (out of usage credits), first one
614
+ st.sessionInit = null; // the session's id as init states it: what a turn killed before its result resumes
600
615
  st.foldUsage = (key, u) => {
601
616
  if (!u) return;
602
617
  const was = st.perMessage.get(key);
@@ -845,6 +860,19 @@ function lineParser(st) {
845
860
  else if (ev.type === "system" && ev.subtype === "init") {
846
861
  // MODEL GAUGE — the session's configured model, the earliest wire statement of what will run.
847
862
  if (typeof ev.model === "string" && ev.model && !isCliLabel(ev.model)) st.wireModelInit ??= ev.model;
863
+ st.fastInit ??= { state: ev.fast_mode_state ?? null, reason: ev.fast_mode_disabled_reason ?? null };
864
+ // THE SESSION'S ID, as the program states it when the session opens. The result event repeats it at the end, but a
865
+ // turn stopped at its time limit never sends one, and the warm resume of a turn stopped while working needs the id
866
+ // of the session to resume: handed the stage's own key instead, the program refuses it ("requires a valid session
867
+ // ID"), and the retry is spent on the refusal (measured in testing, 2026-11-26).
868
+ if (typeof ev.session_id === "string" && ev.session_id) st.sessionInit ??= ev.session_id;
869
+ }
870
+ // THE PROGRAM'S NOTICE ABOUT FAST MODE. Out of usage credits, it retries each fast request at standard speed and says so
871
+ // "on the message stream as a `system` message with subtype `notification`" (the vendor's fast-mode page, "Handle rate
872
+ // limits"). The first such notice is kept, bounded, as the row's reason.
873
+ else if (ev.type === "system" && ev.subtype === "notification") {
874
+ const text = [ev.text, ev.message, ev.notification, ev.title].find((x) => typeof x === "string" && x) ?? "";
875
+ if (!st.fastNotice && /fast/i.test(text)) st.fastNotice = text.slice(0, 300);
848
876
  }
849
877
  else if (ev.type === "assistant") {
850
878
  // MODEL GAUGE — the model that served THIS API call. Authoritative over init (see above).
@@ -897,7 +925,9 @@ function lineParser(st) {
897
925
  st.syncOpenAsk();
898
926
  // This block's usage, folded into its own call: the largest reading wins, so a block's early count
899
927
  // never replaces the delta's running total, and a second block of the same call adds nothing twice.
900
- st.foldUsage(ev.message?.id ?? st.openMessage ?? `__assistant_${++st.anonMessages}`, mapUsage(ev.message?.usage));
928
+ const usageKey = ev.message?.id ?? st.openMessage ?? `__assistant_${++st.anonMessages}`;
929
+ st.foldUsage(usageKey, mapUsage(ev.message?.usage));
930
+ st.noteSpeed(usageKey, ev.message?.usage);
901
931
  if (!st.firstCall && ev.message?.usage) st.firstCall = mapUsage(ev.message.usage);
902
932
  st.progress();
903
933
  }
@@ -937,9 +967,10 @@ function lineParser(st) {
937
967
  if (t === "message_start") {
938
968
  st.openMessage = ev.event.message?.id ?? `__start_${++st.anonMessages}`;
939
969
  st.foldUsage(st.openMessage, mapUsage(ev.event.message?.usage));
970
+ st.noteSpeed(st.openMessage, ev.event.message?.usage);
940
971
  st.progress();
941
972
  }
942
- else if (t === "message_delta") { st.foldUsage(st.openMessage ?? "__delta_without_start", mapUsage(ev.event?.usage)); st.progress(); }
973
+ else if (t === "message_delta") { st.foldUsage(st.openMessage ?? "__delta_without_start", mapUsage(ev.event?.usage)); st.noteSpeed(st.openMessage ?? "__delta_without_start", ev.event?.usage); st.progress(); }
943
974
  else if (t === "content_block_delta" || t === "content_block_start") st.progress();
944
975
  // THINKING GAUGE (partials): the earliest tells. Any one is sufficient; belt-and-braces so a
945
976
  // display-mode or CLI-version change cannot silently blind the gauge.
@@ -1250,11 +1281,13 @@ function wireStreams(st) {
1250
1281
  // Never the requested alias, and never init's answer for a turn only the CLI answered — see the
1251
1282
  // declaration above.
1252
1283
  modelWire: st.wireModelAssistant ?? (st.answeredItself ? null : st.wireModelInit),
1284
+ // SPEED GAUGE: what the turn asked for beside what the program reported serving (speedOfClaudeTurn).
1285
+ speed: speedOfClaudeTurn({ requested: st.speed, standardBecause: st.standardBecause, result: st.resultEvent, init: st.fastInit, calls: st.speedByMessage, notice: st.fastNotice }),
1253
1286
  // PROVIDER GAUGE: the program's own word for who served the turn, read from the result's per-model
1254
1287
  // usage ("firstParty" on Anthropic's own API and "foundry" on Azure Foundry, measured 2026-09-14),
1255
1288
  // or null when the stream never said or its models disagree. Recorded, never inferred from config.
1256
1289
  providerWire: providerOf(st.resultEvent),
1257
- sessionRef: st.resultEvent?.session_id ?? st.resumeRef ?? null,
1290
+ sessionRef: st.resultEvent?.session_id ?? st.sessionInit ?? st.resumeRef ?? null,
1258
1291
  // The raw result event's total_cost_usd is a provider-side field and stays in the provider's
1259
1292
  // own stream; the tuple carries no currency (tokens-only directive 2026-07-11) — `usage` is
1260
1293
  // the telemetry.
@@ -1282,6 +1315,31 @@ function wireStreams(st) {
1282
1315
  }
1283
1316
 
1284
1317
 
1318
+ /**
1319
+ * One turn's speed record: what it asked for and what the program reported serving. PURE.
1320
+ *
1321
+ * `served` is the result's `usage.speed`, the program's word for the turn; where the result says nothing, the calls'
1322
+ * own words decide it (`mixed` when they disagree), and null where none spoke. `calls` counts the turn's API calls by
1323
+ * the speed each reported, so a run can say how many of its calls ran fast. `state` and `disabledReason`
1324
+ * are the program's `fast_mode_state` and `fast_mode_disabled_reason` (measured on 2.1.295 and 2.1.326: `on`; `off` with
1325
+ * `sdk_opt_in_required` when the turn did not ask), and `notice` its own words when it ran a fast request at standard
1326
+ * speed for want of usage credits. `standardBecause` is why a session of a fast run asked for standard (engine/speed.mjs,
1327
+ * sessionSpeed), null otherwise. Nothing here is inferred from what the turn asked for.
1328
+ */
1329
+ export function speedOfClaudeTurn({ requested = "standard", standardBecause = null, result = null, init = null, calls = new Map(), notice = null } = {}) {
1330
+ const count = { fast: 0, standard: 0, unknown: 0 };
1331
+ for (const v of calls.values()) count[v === "fast" ? "fast" : v === "standard" ? "standard" : "unknown"]++;
1332
+ const reported = typeof result?.usage?.speed === "string" && result.usage.speed ? result.usage.speed : null;
1333
+ const fromCalls = count.fast && count.standard ? "mixed" : count.fast ? "fast" : count.standard ? "standard" : null;
1334
+ const served = reported ?? fromCalls;
1335
+ return {
1336
+ requested, standardBecause: standardBecause ?? null, served, basis: served ? "reported" : "unknown", calls: count,
1337
+ state: result?.fast_mode_state ?? init?.state ?? null,
1338
+ disabledReason: result?.fast_mode_disabled_reason ?? init?.reason ?? null,
1339
+ notice: notice ?? null,
1340
+ };
1341
+ }
1342
+
1285
1343
  function errResult(t0, e, resumeRef) {
1286
1344
  return {
1287
1345
  code: 1, killed: false, wall: (Date.now() - t0) / 1000, stdout: "",