@parcha/agentrun-serve 0.1.0-beta.45 → 0.1.0-beta.47

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 (256) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/NOTICE +4 -0
  3. package/README.md +283 -47
  4. package/dist/acp-package.d.ts +35 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +5 -2
  7. package/dist/adapter-facts.js +6 -3
  8. package/dist/adapters.d.ts +7 -0
  9. package/dist/adapters.js +39 -0
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/api-only.d.ts +7 -10
  13. package/dist/api-only.js +7 -10
  14. package/dist/archil-routes.js +2 -1
  15. package/dist/cap.js +12 -2
  16. package/dist/chatgpt-plan.js +2 -1
  17. package/dist/cli.js +119 -44
  18. package/dist/composio-made.d.ts +19 -2
  19. package/dist/composio-made.js +17 -5
  20. package/dist/composio-preset.d.ts +42 -7
  21. package/dist/composio-preset.js +106 -70
  22. package/dist/composio-triggers.d.ts +9 -4
  23. package/dist/composio-triggers.js +20 -13
  24. package/dist/computer-attach.d.ts +11 -10
  25. package/dist/computer-attach.js +13 -14
  26. package/dist/computer-commands.d.ts +3 -0
  27. package/dist/computer-commands.js +3 -2
  28. package/dist/computer-lost.d.ts +4 -0
  29. package/dist/computer-lost.js +8 -3
  30. package/dist/computer-setting.d.ts +2 -0
  31. package/dist/computer-setting.js +2 -0
  32. package/dist/computers.d.ts +9 -75
  33. package/dist/computers.js +20 -66
  34. package/dist/console/assets/index-BBFzAxLB.js +715 -0
  35. package/dist/console/assets/index-BRi-Rgq6.css +1 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/cost-heal.d.ts +13 -0
  38. package/dist/cost-heal.js +27 -0
  39. package/dist/dial-relay.d.ts +6 -2
  40. package/dist/dial-relay.js +9 -12
  41. package/dist/email/routes.js +2 -1
  42. package/dist/errors.d.ts +2 -0
  43. package/dist/errors.js +5 -0
  44. package/dist/exa-keyless.d.ts +1 -1
  45. package/dist/exa-keyless.js +1 -1
  46. package/dist/faux-computers.d.ts +2 -3
  47. package/dist/faux-computers.js +9 -31
  48. package/dist/github-connection.js +2 -1
  49. package/dist/harness-archive.d.ts +19 -2
  50. package/dist/harness-archive.js +49 -15
  51. package/dist/harness-check.d.ts +73 -0
  52. package/dist/harness-check.js +489 -0
  53. package/dist/harness-cursor.d.ts +45 -0
  54. package/dist/harness-cursor.js +121 -0
  55. package/dist/harness-recipe.d.ts +127 -0
  56. package/dist/harness-recipe.js +357 -0
  57. package/dist/harness-table.d.ts +12 -0
  58. package/dist/harness-table.js +62 -2
  59. package/dist/harness.d.ts +2 -0
  60. package/dist/harness.js +3 -2
  61. package/dist/host-check.d.ts +6 -0
  62. package/dist/host-check.js +14 -0
  63. package/dist/host.d.ts +10 -3
  64. package/dist/host.js +17 -3
  65. package/dist/import-sources.d.ts +2 -0
  66. package/dist/import-sources.js +2 -0
  67. package/dist/import-summary.d.ts +15 -5
  68. package/dist/import-summary.js +24 -8
  69. package/dist/import.d.ts +34 -4
  70. package/dist/import.js +134 -32
  71. package/dist/key-refusal.d.ts +1 -0
  72. package/dist/key-refusal.js +8 -3
  73. package/dist/key-words.d.ts +1 -1
  74. package/dist/key-words.js +4 -4
  75. package/dist/learn/check.d.ts +3 -0
  76. package/dist/learn/check.js +31 -20
  77. package/dist/learn/compile.js +11 -4
  78. package/dist/learn/promote.d.ts +77 -4
  79. package/dist/learn/promote.js +123 -2
  80. package/dist/learned-nodes.d.ts +4 -3
  81. package/dist/learned-workflow.js +4 -1
  82. package/dist/learning-cost.d.ts +6 -16
  83. package/dist/learning-cost.js +6 -12
  84. package/dist/learning-setting.d.ts +17 -6
  85. package/dist/learning-setting.js +41 -5
  86. package/dist/learning-words.d.ts +2 -0
  87. package/dist/learning-words.js +1 -1
  88. package/dist/listen-first.d.ts +10 -0
  89. package/dist/listen-first.js +25 -1
  90. package/dist/llms.txt +1 -1
  91. package/dist/mcp-gateway.d.ts +2 -1
  92. package/dist/mcp-gateway.js +31 -15
  93. package/dist/mcp-probe.d.ts +18 -6
  94. package/dist/mcp-probe.js +41 -8
  95. package/dist/mcp-secret-writes.d.ts +8 -0
  96. package/dist/mcp-secret-writes.js +104 -4
  97. package/dist/mcp-servers-store.d.ts +11 -5
  98. package/dist/mcp-servers-store.js +46 -20
  99. package/dist/model-form.d.ts +2 -1
  100. package/dist/model-form.js +22 -8
  101. package/dist/model-gateway.d.ts +113 -0
  102. package/dist/model-gateway.js +433 -0
  103. package/dist/model.d.ts +2 -1
  104. package/dist/model.js +9 -7
  105. package/dist/monid.js +1 -1
  106. package/dist/native/binding.d.ts +4 -0
  107. package/dist/native/binding.js +9 -0
  108. package/dist/native/cli.d.ts +3 -2
  109. package/dist/native/cli.js +6 -5
  110. package/dist/openapi.d.ts +2 -0
  111. package/dist/openapi.js +326 -41
  112. package/dist/owner.d.ts +4 -2
  113. package/dist/owner.js +10 -4
  114. package/dist/page.d.ts +8 -0
  115. package/dist/page.js +9 -1
  116. package/dist/port-models.js +17 -10
  117. package/dist/provider.d.ts +3 -3
  118. package/dist/provider.js +12 -3
  119. package/dist/public-address.d.ts +28 -0
  120. package/dist/public-address.js +62 -0
  121. package/dist/run-launch.d.ts +1 -1
  122. package/dist/run-launch.js +1 -1
  123. package/dist/run-secrets.d.ts +3 -2
  124. package/dist/run-secrets.js +6 -4
  125. package/dist/runner/adapter-loop.d.ts +10 -7
  126. package/dist/runner/adapter-loop.js +57 -22
  127. package/dist/runner/adapter-run-spec.d.ts +12 -0
  128. package/dist/runner/adapter-run-spec.js +40 -6
  129. package/dist/runner/adapters/index.js +16 -0
  130. package/dist/runner/adapters/pi.d.ts +5 -2
  131. package/dist/runner/adapters/pi.js +7 -4
  132. package/dist/runner/audit.d.ts +7 -0
  133. package/dist/runner/audit.js +24 -6
  134. package/dist/runner/claim-secrets.js +5 -1
  135. package/dist/runner/cli-run-spec.js +15 -7
  136. package/dist/runner/compare-end.d.ts +43 -0
  137. package/dist/runner/compare-end.js +95 -0
  138. package/dist/runner/computer-journal.d.ts +3 -0
  139. package/dist/runner/computer-journal.js +22 -2
  140. package/dist/runner/conformance/harness.js +19 -8
  141. package/dist/runner/conformance/subject.d.ts +6 -0
  142. package/dist/runner/harness-loops.d.ts +6 -1
  143. package/dist/runner/harness-loops.js +94 -54
  144. package/dist/runner/held.d.ts +5 -4
  145. package/dist/runner/journal-kinds.d.ts +4 -1
  146. package/dist/runner/journal-kinds.js +3 -0
  147. package/dist/runner/loop-contract.d.ts +10 -0
  148. package/dist/runner/main.d.ts +5 -5
  149. package/dist/runner/main.js +81 -11
  150. package/dist/runner/mcp-claim.js +40 -12
  151. package/dist/runner/metrics.d.ts +26 -0
  152. package/dist/runner/metrics.js +44 -1
  153. package/dist/runner/presence.d.ts +41 -0
  154. package/dist/runner/presence.js +89 -0
  155. package/dist/runner/promotion.d.ts +10 -3
  156. package/dist/runner/promotion.js +42 -21
  157. package/dist/runner/run-child-host.js +52 -14
  158. package/dist/runner/runner.d.ts +5 -0
  159. package/dist/runner/runner.js +8 -0
  160. package/dist/runner/store-port.d.ts +3 -0
  161. package/dist/runner/store-secrets.js +19 -7
  162. package/dist/runner/workflow-first.d.ts +5 -2
  163. package/dist/runner/workflow-first.js +6 -3
  164. package/dist/runs-over-store.d.ts +6 -2
  165. package/dist/runs-over-store.js +14 -4
  166. package/dist/sdk/runs.d.ts +1 -1
  167. package/dist/sdk/runs.js +6 -1
  168. package/dist/sdk/schema.js +1 -1
  169. package/dist/secret-writes.d.ts +16 -3
  170. package/dist/secret-writes.js +28 -3
  171. package/dist/server-secrets-store.js +5 -0
  172. package/dist/server.d.ts +31 -2
  173. package/dist/server.js +326 -53
  174. package/dist/sign-ins-secrets.js +4 -1
  175. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  176. package/dist/slack-url.d.ts +5 -0
  177. package/dist/slack-url.js +11 -0
  178. package/dist/slack.d.ts +107 -0
  179. package/dist/slack.js +292 -0
  180. package/dist/start-switches.d.ts +28 -0
  181. package/dist/start-switches.js +37 -0
  182. package/dist/stats.d.ts +1 -1
  183. package/dist/stats.js +2 -1
  184. package/dist/stop-signals.d.ts +11 -0
  185. package/dist/stop-signals.js +22 -0
  186. package/dist/store/agent-body.d.ts +1 -1
  187. package/dist/store/agent-body.js +2 -2
  188. package/dist/store/index.d.ts +3 -3
  189. package/dist/store/index.js +1 -1
  190. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  191. package/dist/store/postgres/store.d.ts +1 -1
  192. package/dist/store/postgres/store.js +4 -2
  193. package/dist/store/schema.d.ts +13 -5
  194. package/dist/store/schema.js +20 -11
  195. package/dist/store/seal.d.ts +16 -4
  196. package/dist/store/sqlite/store.d.ts +1 -1
  197. package/dist/store/sqlite/store.js +106 -27
  198. package/dist/store/store.d.ts +75 -23
  199. package/dist/store/store.js +11 -0
  200. package/dist/store-reads/analytics.js +3 -2
  201. package/dist/store-reads/cap.d.ts +7 -0
  202. package/dist/store-reads/cap.js +11 -1
  203. package/dist/store-reads/journal.js +27 -1
  204. package/dist/store-reads/learning.d.ts +23 -2
  205. package/dist/store-reads/learning.js +29 -8
  206. package/dist/store-reads/runs.d.ts +9 -0
  207. package/dist/store-reads/runs.js +19 -6
  208. package/dist/store-reads/stats.d.ts +4 -1
  209. package/dist/store-reads/stats.js +15 -6
  210. package/dist/store-view.d.ts +123 -14
  211. package/dist/store-view.js +154 -21
  212. package/dist/telemetry.d.ts +7 -7
  213. package/dist/telemetry.js +38 -15
  214. package/dist/templates.d.ts +6 -3
  215. package/dist/templates.js +38 -3
  216. package/dist/timeline/timeline.js +18 -0
  217. package/dist/tool-keys-store.js +2 -2
  218. package/dist/tool-keys.js +2 -1
  219. package/dist/tool-plane.js +2 -2
  220. package/dist/trigger-adapter.d.ts +3 -4
  221. package/dist/trigger-adapter.js +2 -2
  222. package/dist/trigger-composio.js +3 -3
  223. package/dist/trigger-email.js +0 -2
  224. package/dist/trigger-feed.js +0 -2
  225. package/dist/trigger-schedule.js +3 -0
  226. package/dist/trigger-secrets-shown.d.ts +6 -3
  227. package/dist/trigger-secrets-shown.js +22 -13
  228. package/dist/trigger-targets.d.ts +1 -1
  229. package/dist/trigger-targets.js +19 -8
  230. package/dist/triggers.d.ts +7 -3
  231. package/dist/triggers.js +2 -1
  232. package/dist/webhooks.d.ts +85 -9
  233. package/dist/webhooks.js +129 -46
  234. package/dist/wires.d.ts +6 -1
  235. package/dist/wires.js +5 -0
  236. package/dist/workspace/attach.d.ts +3 -2
  237. package/dist/workspace/attach.js +2 -1
  238. package/dist/workspace/attached-computers.d.ts +6 -8
  239. package/dist/workspace/attached-computers.js +27 -24
  240. package/dist/workspace/computer-deps.d.ts +2 -3
  241. package/dist/workspace/computer-deps.js +3 -6
  242. package/dist/workspace/computer-for-claim.js +72 -96
  243. package/dist/workspace/computer-kept.d.ts +0 -7
  244. package/dist/workspace/computer-kept.js +0 -17
  245. package/dist/workspace/resolve-computer.d.ts +18 -14
  246. package/dist/workspace/resolve-computer.js +47 -60
  247. package/dist/workspace/synced-folder.d.ts +20 -15
  248. package/dist/workspace/synced-folder.js +33 -43
  249. package/launcher/agentrun-serve +4 -1
  250. package/package.json +10 -10
  251. package/skills/agentrun-serve/SKILL.md +11 -0
  252. package/templates/README.md +1 -1
  253. package/templates/inbound-lead/agent.md +2 -1
  254. package/templates/kyb/agent.md +2 -1
  255. package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
  256. package/dist/console/assets/index-DaFsZuzQ.css +0 -1
@@ -25,6 +25,9 @@
25
25
  // opens it again, so a message's new credential reaches the run's next model request; a run handed none gets its calls
26
26
  // refused unsent (UNUSABLE.perRunMissing).
27
27
  //
28
+ // A per-run Composio server (composio-made.ts composioPerRun) is bound by each run's caller ({composio_user_id,
29
+ // connected_account_id?} in mcp_auth, sealed in its launch): its entry carries them as `query` (mcp-gateway.ts).
30
+ //
28
31
  // fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
29
32
  // expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
30
33
  // only when it provably never left: a refused or unmade connection, an address check out of time; one request that left
@@ -50,6 +53,8 @@ import { randomUUID } from "node:crypto";
50
53
  import { EndpointRefused, REFRESH_REQUEST_MS, refreshed, refused, RequestUnsent, systemNetwork } from "../mcp-oauth.js";
51
54
  import { pinFirst } from "../mcp-pin-first.js";
52
55
  import { mcpNameOf } from "../tool-names.js";
56
+ import { composioMadeKey, composioPerRun } from "../composio-made.js";
57
+ import { composioRunQuery } from "../composio-preset.js";
53
58
  import { META_REASON, metaToolOf } from "../mcp-meta.js";
54
59
  import { credentialInQuery, credentialInQueryWords, shownUrl } from "../mcp-probe.js";
55
60
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
@@ -193,10 +198,14 @@ export async function mcpClaim(options) {
193
198
  // Held by the run's redactor before anything else: a value opened is a value to cut, sent or not.
194
199
  if (extra.headers)
195
200
  options.hold?.(credentialValues(extra.headers));
201
+ if (extra.query)
202
+ options.hold?.(Object.values(extra.query));
196
203
  if (released || gone.has(name))
197
204
  return;
198
- // Headers go only to the URL the run was pinned to: a server moved since is refused per call by the gateway.
199
- credentials[name] = { url: row.url, ...(extra.unopened ? { unopened: extra.unopened } : extra.headers && row.url === pinnedUrl ? { headers: extra.headers } : {}) };
205
+ // Headers and a run's account go only to the URL the run was pinned to: a server moved since is refused per call by
206
+ // the gateway.
207
+ const pinned = row.url === pinnedUrl;
208
+ credentials[name] = { url: row.url, ...(extra.unopened ? { unopened: extra.unopened } : { ...(extra.headers && pinned ? { headers: extra.headers } : {}), ...(extra.query && pinned ? { query: extra.query } : {}) }) };
200
209
  };
201
210
  // A GitHub App's server keeps no credential: its token is minted for this run (awaited, so the claim is confirmed
202
211
  // after it), kept fresh mid-run, and never stored.
@@ -206,15 +215,20 @@ export async function mcpClaim(options) {
206
215
  // run's launch, read again at every fresh() so a message's new one reaches the run's next request.
207
216
  if (row.auth === "per_run")
208
217
  return entry(await perRun(name, row.url)), { awaited: false };
218
+ // A per-run Composio server: the run's account, or its calls refused unsent; its key is opened below as any server's.
219
+ const account = row.auth === "headers" ? await composioAccount(name, row) : undefined;
220
+ if (account && "unopened" in account)
221
+ return entry({ unopened: account.unopened }), { awaited: false };
222
+ const query = account?.query;
209
223
  if (row.sealed === null)
210
- return entry({}), { awaited: false };
224
+ return entry({ ...(query ? { query } : {}) }), { awaited: false };
211
225
  // A seal problem first: no refresh is ever sent for a credential this runner cannot open.
212
226
  const opened = openMcpRow(sealKey, row);
213
227
  if (!("credential" in opened))
214
228
  return entry(opened.unusable === "none" ? {} : { unopened: UNUSABLE.damaged }), { awaited: false };
215
229
  const credential = opened.credential;
216
230
  if (credential.type === "headers")
217
- return entry({ headers: { ...credential.headers } }), { awaited: false };
231
+ return entry({ headers: { ...credential.headers }, ...(query ? { query } : {}) }), { awaited: false };
218
232
  const oauth = credential;
219
233
  if (oauth.expired)
220
234
  return entry({ unopened: UNUSABLE.signedOut }), { awaited: false };
@@ -346,19 +360,33 @@ export async function mcpClaim(options) {
346
360
  };
347
361
  /** The run's handed MCP credentials, opened from its launch: read once per fresh() (perRunRead), not once per server. */
348
362
  let perRunRead;
349
- /** A per_run server's headers for this run, from its launch; or why there are none. Only for the origin its url had
350
- * when they were handed: a server moved since gets none. */
351
- const perRun = async (name, url) => {
363
+ /** What the run's caller handed `name` (mcp_auth, opened from its launch) when it is of `shape`; or why there is none.
364
+ * Only for the origin its url had when it was handed: a server moved since gets none. */
365
+ const handed = async (name, url, shape) => {
352
366
  perRunRead ??= store.runs.launch(claim.runId).then((launch) => openRunMcpAuth(sealKey, claim.runId, launch.sealed));
353
- const handed = await perRunRead;
354
- if (handed === undefined)
367
+ const all = await perRunRead;
368
+ if (all === undefined)
355
369
  return { unopened: UNUSABLE.damaged };
356
- const given = Object.hasOwn(handed, name) ? handed[name] : undefined;
357
- if (!given)
370
+ const given = Object.hasOwn(all, name) ? all[name] : undefined;
371
+ if (!given || !(shape in given))
358
372
  return { unopened: UNUSABLE.perRunMissing };
359
373
  if (given.origin !== new URL(url).origin)
360
374
  return { unopened: UNUSABLE.damaged };
361
- return { headers: { ...given.headers } };
375
+ return given;
376
+ };
377
+ /** A per_run server's headers for this run; or why there are none. */
378
+ const perRun = async (name, url) => {
379
+ const given = await handed(name, url, "headers");
380
+ return "unopened" in given ? given : { headers: { ...given.headers } };
381
+ };
382
+ /** A per-run Composio server's account for this run, as the query its requests add (composio-preset.ts
383
+ * composioRunQuery); or why there is none. Undefined: `row` is no per-run Composio server (its own record says so:
384
+ * composioPerRun). */
385
+ const composioAccount = async (name, row) => {
386
+ if (!composioPerRun(row, await store.settings.get(composioMadeKey(name))))
387
+ return undefined;
388
+ const given = await handed(name, row.url, "composio");
389
+ return "unopened" in given ? given : { query: composioRunQuery(given.composio) };
362
390
  };
363
391
  const fresh = async () => {
364
392
  if (!pin || released)
@@ -8,6 +8,11 @@ import { type CostParts } from "@parcha/agentrun-kernel";
8
8
  * its runner.request's model, "" for one that names none). `free`: it booked requests, every one on a free model (its
9
9
  * runner.turn's `free`: its known price $0 for every token), so its $0 says why. A reader that joins sessions, or says
10
10
  * what is known of an unknown cost, takes the parts through costOfParts, never `usd` and `known` alone. */
11
+ /** `priced`: of its requests with a known figure (a plan's aside, which cost no dollars), how many the provider or its
12
+ * gateway priced (`reported`: the proxy's reportedCostOf or usageCostOf, its runner.turn keeping the table's figure beside
13
+ * it as `tableUsd`) and how many a price table did (`estimated`: its runner.turn's `estimated`, or a cut request's hold,
14
+ * or a native or SDK task's `aggregate` booking, its harness's own figure).
15
+ * A figure that is neither ($0 for a request refused or never sent, a charge settled through the cap) counts in neither. */
11
16
  export type BookedSpend = {
12
17
  readonly usd: number | null;
13
18
  readonly known: number;
@@ -23,8 +28,28 @@ export type BookedSpend = {
23
28
  cacheRead: number;
24
29
  cacheWrite: number;
25
30
  };
31
+ readonly priced: {
32
+ readonly reported: number;
33
+ readonly estimated: number;
34
+ };
26
35
  readonly free?: true;
27
36
  };
37
+ /** How a run's cost was reached, by how its model requests were priced: `reported` when every request priced had the
38
+ * provider's or its gateway's own figure (LiteLLM's `x-litellm-response-cost`, OpenRouter's usage `cost`); `estimate`
39
+ * when any was priced from a price table (the catalog, AGENT_MODEL_PRICE, a cut request's hold); `unpriced` when no
40
+ * request was priced (none was sent, or none had a figure). The run's cost block (`cost.basis`), its stored metrics
41
+ * (`costBasis`) and the sums over runs (GET /stats, GET /usage) say it in these words. */
42
+ export declare const COST_BASES: readonly ["reported", "estimate", "unpriced"];
43
+ export type CostBasis = (typeof COST_BASES)[number];
44
+ /** The basis of a booking's model requests (bookedSpend "model"): COST_BASES. */
45
+ export declare const costBasisOf: (spend: Pick<BookedSpend, "priced">) => CostBasis;
46
+ /** The basis of a sum of costs: `estimate` when any is, else `reported` when any is, else `unpriced`. */
47
+ export declare function joinedBasis(bases: Iterable<CostBasis>): CostBasis;
48
+ /** A run's basis as its end stored it (its metrics' `costBasis`); an imported run's catalog estimate (import.ts stores
49
+ * `costBasis: "catalog"` beside `costUsdEst`, the figure store-reads/runs.ts costOfRun reads) is an `estimate`, at $0 too;
50
+ * a run that stored none (one that ended before the end stored it, a workflow's, a native, SDK or imported run's: their
51
+ * figures are the harness's) is an `estimate` when it cost anything, else `unpriced`. */
52
+ export declare function storedBasisOf(metrics: unknown, usd: number | null | undefined): CostBasis;
28
53
  /** What the run's booking (the kernel's runner.request and runner.turn records, the model proxy's own) says its requests
29
54
  * cost, over `entries`, every conversation of the run's journal: its model requests (`model`: every session but the
30
55
  * paid-tools one, TOOL_SESSION, and the decisions one, DECISION_SESSION), its paid tool calls (`paid`: the paid-tools
@@ -114,6 +139,7 @@ export declare function bookedListSpend(entries: readonly EntryLike[]): number |
114
139
  export type RunMetricsStored = RunMetrics & {
115
140
  effort?: string;
116
141
  model?: string;
142
+ costBasis?: CostBasis;
117
143
  };
118
144
  /** The run's metrics and cost from its journal `entries`. `decisions`: a workflow run's receipts (none for pi).
119
145
  * `effort`/`model`: the enrichment the old storedMetrics added. `catalog`: the run's MCP tools called by a hashed wire
@@ -13,6 +13,37 @@ import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/c
13
13
  import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
14
14
  import { anthropicModelId } from "../provider.js";
15
15
  import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
16
+ /** How a run's cost was reached, by how its model requests were priced: `reported` when every request priced had the
17
+ * provider's or its gateway's own figure (LiteLLM's `x-litellm-response-cost`, OpenRouter's usage `cost`); `estimate`
18
+ * when any was priced from a price table (the catalog, AGENT_MODEL_PRICE, a cut request's hold); `unpriced` when no
19
+ * request was priced (none was sent, or none had a figure). The run's cost block (`cost.basis`), its stored metrics
20
+ * (`costBasis`) and the sums over runs (GET /stats, GET /usage) say it in these words. */
21
+ export const COST_BASES = ["reported", "estimate", "unpriced"];
22
+ /** The basis of a booking's model requests (bookedSpend "model"): COST_BASES. */
23
+ export const costBasisOf = (spend) => (spend.priced.estimated > 0 ? "estimate" : spend.priced.reported > 0 ? "reported" : "unpriced");
24
+ /** The basis of a sum of costs: `estimate` when any is, else `reported` when any is, else `unpriced`. */
25
+ export function joinedBasis(bases) {
26
+ let reported = false;
27
+ for (const basis of bases) {
28
+ if (basis === "estimate")
29
+ return "estimate";
30
+ if (basis === "reported")
31
+ reported = true;
32
+ }
33
+ return reported ? "reported" : "unpriced";
34
+ }
35
+ /** A run's basis as its end stored it (its metrics' `costBasis`); an imported run's catalog estimate (import.ts stores
36
+ * `costBasis: "catalog"` beside `costUsdEst`, the figure store-reads/runs.ts costOfRun reads) is an `estimate`, at $0 too;
37
+ * a run that stored none (one that ended before the end stored it, a workflow's, a native, SDK or imported run's: their
38
+ * figures are the harness's) is an `estimate` when it cost anything, else `unpriced`. */
39
+ export function storedBasisOf(metrics, usd) {
40
+ const stored = metrics?.costBasis;
41
+ if (COST_BASES.includes(stored))
42
+ return stored;
43
+ if (stored === "catalog" && typeof usd === "number")
44
+ return "estimate";
45
+ return typeof usd === "number" && usd > 0 ? "estimate" : "unpriced";
46
+ }
16
47
  /** The conversation each of the run's sessions books in, by its key: the first `agentrun.session.key` entry naming it. */
17
48
  function sessionConversations(entries) {
18
49
  const out = new Map();
@@ -61,6 +92,8 @@ export function bookedSpend(entries, which) {
61
92
  let unmetered = 0;
62
93
  let free = 0;
63
94
  let atMost = 0;
95
+ let reported = 0;
96
+ let estimated = 0;
64
97
  const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
65
98
  // Each request is booked once, as the kernel's sessionSpendOf reads it: a second runner.turn of a turn already booked
66
99
  // (two bookings of one session that each read it open, a cut written twice) counts no money and no request again.
@@ -96,6 +129,16 @@ export function bookedSpend(entries, which) {
96
129
  (bounded += own.usd), (atMost += 1);
97
130
  else
98
131
  known += own.usd;
132
+ // How its figure was reached (costBasisOf): a price table's (the proxy's `estimated`, or a hold), or the provider's own
133
+ // (the proxy keeps the table's figure beside a reported one, `tableUsd`). A native or SDK task's one booking for the whole
134
+ // task (`aggregate`, native-loop.ts and sdk-loop.ts) carries its harness's own figure, an estimate. A plan's request
135
+ // costs no dollars: neither.
136
+ if (own.usd !== null && d.billing !== "plan") {
137
+ if (own.atMost || d.estimated === true || d.aggregate === true)
138
+ estimated += 1;
139
+ else if (d.tableUsd !== undefined)
140
+ reported += 1;
141
+ }
99
142
  // The booking keeps a request's usage only when it reported some (runner.ts tokensOf): one with none is unmetered.
100
143
  if (d.usage === undefined)
101
144
  unmetered += 1;
@@ -103,7 +146,7 @@ export function bookedSpend(entries, which) {
103
146
  if (typeof d.usage?.[key] === "number")
104
147
  tokens[key] += d.usage[key];
105
148
  }
106
- return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, ...(requests > 0 && free === requests ? { free: true } : {}) };
149
+ return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, priced: { reported, estimated }, ...(requests > 0 && free === requests ? { free: true } : {}) };
107
150
  }
108
151
  /** A sum of charges with its float noise rounded off, nothing more (as the decisions row rounds, decision-rows.ts): a
109
152
  * decision costs millionths of a dollar, so a sum rounded to the millionth would lose it. */
@@ -0,0 +1,41 @@
1
+ import type { Runners } from "../store/store.js";
2
+ /** How often a runner says again that it is there. */
3
+ export declare const PRESENCE_RENEW_MS = 10000;
4
+ /** How old a runner's word can be and still count: three renewals missed. */
5
+ export declare const PRESENCE_STALE_MS: number;
6
+ /** Where a runner's relay takes the dials the server relays to it (dial-relay.ts). */
7
+ export interface RelayAt {
8
+ readonly host: string;
9
+ readonly port: number;
10
+ }
11
+ /** A runner's word kept in the store until its close. */
12
+ export interface Presence {
13
+ /** The runner's process since its start, on its row: its relay's minted tokens and proofs name the same one. */
14
+ readonly incarnation: string;
15
+ /** Says on its row where its relay answers (`at`), or that it answers nowhere (null, the relay's close), and keeps that
16
+ * through every put again. Rejects when that write fails, which the renewals then try again. */
17
+ relay(at: RelayAt | null): Promise<void>;
18
+ /** Stops renewing it and removes the row (its incarnation's alone). */
19
+ close(): Promise<void>;
20
+ /** Stops renewing it and leaves the row to go stale, as a crash would. */
21
+ stop(): void;
22
+ }
23
+ /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
24
+ * again when it went (a row pruned, a store restored), never over a later process's of the same name while that one is
25
+ * live; its relay's place is written on its own row only. A write that
26
+ * fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
27
+ * runner process's one (runner/main.ts hands its relay the same), a new one by default. */
28
+ export declare function keepPresence(runners: Runners, runner: string, refused: string | null, { renewMs, warn, incarnation }?: {
29
+ renewMs?: number;
30
+ warn?: (line: string) => void;
31
+ incarnation?: string;
32
+ }): Presence;
33
+ /** Why no runner here can take a run, in the runners' own words, or undefined while one can (or none is there): the rows
34
+ * seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
35
+ export declare function runnersRefused(runners: Pick<Runners, "live">, staleMs?: number): Promise<string | undefined>;
36
+ /** The code a run fails with when no runner here could take it (its error's code, and a launch's refusal's). */
37
+ export declare const RUNNER_REFUSED_CODE = "runner_refused";
38
+ /** The summary of a queued run failed because no runner here can take it (Runs.failUnclaimed): the code, then `words`. */
39
+ export declare const refusedEnd: (words: string) => string;
40
+ /** The words of a summary refusedEnd wrote, or undefined for any other (store-view.ts errorOfRow). */
41
+ export declare const refusedEndMessage: (summary: string | null | undefined) => string | undefined;
@@ -0,0 +1,89 @@
1
+ // Each runner's word that it is there (store `runners`), and what the server makes of them: whether any runner here can take
2
+ // a run. A runner that claims keeps a row with no refusal for as long as it runs (startRunner); a runner whose run isolation
3
+ // was refused (run-child-host.ts runIsolationOf) keeps one with its words, beside a server (cli.ts, through Serve.refuseRuns)
4
+ // or in a process of its own (runner/main.ts), so a server in another process, or on another host over one Postgres, reads
5
+ // it. A runner in a process of its own with a relay (dial-relay.ts) says on the same row where its relay answers, under the
6
+ // same incarnation (runner/main.ts makes one per process), so the server relays a dial only to a runner this row says is
7
+ // there. Each row is renewed every PRESENCE_RENEW_MS and read as gone once it is PRESENCE_STALE_MS old: a runner that died
8
+ // without its close stops counting within that. While every runner still there refused, and one at least is, the server
9
+ // refuses a launch in their words (runs-over-store.ts prepareLaunch), says so in capabilities and health, and fails the
10
+ // runs still queued (server.ts). With no runner there at all (a server with --no-runner and its runner not started yet),
11
+ // it refuses nothing: runs queue for the runner to come, as before.
12
+ import { randomUUID } from "node:crypto";
13
+ /** How often a runner says again that it is there. */
14
+ export const PRESENCE_RENEW_MS = 10_000;
15
+ /** How old a runner's word can be and still count: three renewals missed. */
16
+ export const PRESENCE_STALE_MS = 3 * PRESENCE_RENEW_MS;
17
+ /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
18
+ * again when it went (a row pruned, a store restored), never over a later process's of the same name while that one is
19
+ * live; its relay's place is written on its own row only. A write that
20
+ * fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
21
+ * runner process's one (runner/main.ts hands its relay the same), a new one by default. */
22
+ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENEW_MS, warn = (_line) => { }, incarnation = randomUUID() } = {}) {
23
+ let warned = false;
24
+ const failed = (error) => {
25
+ if (warned)
26
+ return;
27
+ warned = true;
28
+ warn(`could not say in the store that runner ${runner} is there: ${error instanceof Error ? error.message : String(error)}`);
29
+ };
30
+ let at = null;
31
+ const row = () => ({ runner, incarnation, refused, host: at?.host ?? null, port: at?.port ?? null });
32
+ // Its first put takes the name over from an earlier process's row. Every write after it (a renewal's put again, the
33
+ // relay's place) touches its own row only, or puts one where no other process of the name is live (Runners
34
+ // putUnlessLive): an older process overlapping a restart never takes the later one's row back, nor clears its relay.
35
+ const again = () => runners.putUnlessLive(row(), PRESENCE_STALE_MS);
36
+ let writing = runners.put(row()).catch(failed);
37
+ const timer = setInterval(() => {
38
+ writing = writing.then(async () => {
39
+ if (!(await runners.seen(runner, incarnation)))
40
+ await again();
41
+ }).catch(failed);
42
+ }, renewMs);
43
+ timer.unref();
44
+ let stopped = false;
45
+ return {
46
+ incarnation,
47
+ relay(next) {
48
+ at = next;
49
+ // Once closed or stopped it writes nothing more: a relay's close after its presence's never puts the row back.
50
+ if (stopped)
51
+ return Promise.resolve();
52
+ // After any write in flight, so a renewal's put never lands over it with the place before.
53
+ const wrote = writing.then(async () => {
54
+ if (!(await runners.relayAt(runner, incarnation, next)))
55
+ await again();
56
+ });
57
+ writing = wrote.catch(failed);
58
+ return wrote;
59
+ },
60
+ async close() {
61
+ if (stopped)
62
+ return;
63
+ stopped = true;
64
+ clearInterval(timer);
65
+ await writing;
66
+ await runners.remove(runner, incarnation).catch(() => undefined);
67
+ },
68
+ stop() {
69
+ stopped = true;
70
+ clearInterval(timer);
71
+ },
72
+ };
73
+ }
74
+ /** Why no runner here can take a run, in the runners' own words, or undefined while one can (or none is there): the rows
75
+ * seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
76
+ export async function runnersRefused(runners, staleMs = PRESENCE_STALE_MS) {
77
+ const live = await runners.live(staleMs);
78
+ if (live.length === 0 || live.some((row) => row.refused === null))
79
+ return undefined;
80
+ const reasons = [...new Set(live.map((row) => row.refused))];
81
+ return `No runner of this server can take a run: ${reasons.join(" ")}`;
82
+ }
83
+ /** The code a run fails with when no runner here could take it (its error's code, and a launch's refusal's). */
84
+ export const RUNNER_REFUSED_CODE = "runner_refused";
85
+ const REFUSED_END = `${RUNNER_REFUSED_CODE}: `;
86
+ /** The summary of a queued run failed because no runner here can take it (Runs.failUnclaimed): the code, then `words`. */
87
+ export const refusedEnd = (words) => `${REFUSED_END}${words}`;
88
+ /** The words of a summary refusedEnd wrote, or undefined for any other (store-view.ts errorOfRow). */
89
+ export const refusedEndMessage = (summary) => typeof summary === "string" && summary.startsWith(REFUSED_END) ? summary.slice(REFUSED_END.length) : undefined;
@@ -4,7 +4,7 @@ import { type RunLaunch } from "../run-launch.js";
4
4
  import { type Store } from "../store/store.js";
5
5
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
6
6
  import { type Json } from "../validate.js";
7
- import { type CheckBar, type PromotionRecord, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
7
+ import { type CheckBar, type Compared, type PromotionRecord, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
8
  import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
9
9
  import type { LearningFolder } from "../learn/folder.js";
10
10
  import type { Shown } from "../learning.js";
@@ -85,6 +85,11 @@ export declare const promotionGate: (deps: PromotionDeps) => Promoted;
85
85
  export declare const DSL_REFUSES = "this release's workflow DSL refuses it";
86
86
  /** The words a stopped check's record starts with when it had nothing to check its draft on. */
87
87
  export declare const NOTHING_TO_CHECK = "nothing to check it on";
88
+ /** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none: only a
89
+ * check no grader compared (no agree_on, and no fast model to read the answers). */
90
+ export declare const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
91
+ /** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
92
+ export declare const differentDecisionWords: (k: number, n: number, example: string | undefined) => string;
88
93
  /** One input a check ran its draft on: the agent's run (`of`) and its input, the agent's recorded answer, and what the
89
94
  * draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
90
95
  * reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
@@ -98,10 +103,12 @@ type CheckRow = {
98
103
  readonly escalated?: string;
99
104
  readonly skipped?: Skipped;
100
105
  readonly unstarted?: true;
106
+ readonly compared?: Compared;
101
107
  };
102
108
  /** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
103
- * with the agent's recorded answer (learn/promote.ts sameAnswer), alone when it answered it with no escalate and no
104
- * failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
109
+ * with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
110
+ * when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
111
+ * when it answered it with no escalate and no failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
105
112
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
106
113
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
107
114
  * (the one write: of two claims at once, one decides). */
@@ -7,9 +7,10 @@ import { FINAL_STATES, RunFinal, StoreConstraint } from "../store/store.js";
7
7
  import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
8
8
  import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/journal.js";
9
9
  import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf, toolWord, unmarkedWords } from "../learn/replay-calls.js";
10
+ import { listed } from "../learning-words.js";
10
11
  import { isObject } from "../validate.js";
11
12
  import { agentRun, lastOwnRuns, newCompileAttempt } from "../learn/compile.js";
12
- import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, promotionOf, promotionsOf, recordPromotion, replayingOf, sameAnswer, skippedToolsOf } from "../learn/promote.js";
13
+ import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
13
14
  import { sendCommand } from "./commands.js";
14
15
  import { ClaimRefused } from "./loop-contract.js";
15
16
  import { readSnapshot } from "../learn/folder.js";
@@ -250,15 +251,12 @@ async function decide(deps, workflow, digest) {
250
251
  return startCheck(deps, workflow, digest);
251
252
  }
252
253
  /** The loop's numbers (learning-setting.ts) of the revision the claim runs: its definition's `learning`, each one it
253
- * leaves out at its default (a revision that cannot be read: every default). */
254
+ * leaves out at its default, and the answer paths its check compares on (its agree_on; none, the whole answer). A read
255
+ * that fails throws: no check is saved on defaults (a bar with no agree_on would compare the whole answer for the
256
+ * check's life); the claim's gate leaves the run to its agent and the next claim reads it again (#3182 review). */
254
257
  async function loopOfRevision(deps) {
255
- try {
256
- const revision = await deps.store.agents.revision(deps.revisionId);
257
- return loopOf(revision?.body?.learning);
258
- }
259
- catch {
260
- return loopOf(undefined);
261
- }
258
+ const revision = await deps.store.agents.revision(deps.revisionId);
259
+ return loopOf(revision?.body?.learning);
262
260
  }
263
261
  /** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
264
262
  * check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
@@ -346,7 +344,7 @@ async function startCheck(deps, workflow, digest) {
346
344
  return;
347
345
  }
348
346
  const loop = await loopOfRevision(deps);
349
- const bar = { compile_after: loop.compile_after, agree_min: loop.agree_min, alone_min: loop.alone_min, attempt: attemptOf(records, workflow.name, digest) };
347
+ const bar = { ...loop, attempt: attemptOf(records, workflow.name, digest) };
350
348
  const { inputs, looked, unfit, files } = await checkInputs(deps, workflow, { of: [], n: loop.compile_after }, auditInputsOf(records, workflow.name, digest));
351
349
  if (!inputs.length) {
352
350
  // Nothing of the agent's to check it on (a workflow landed before any run it fits): never promoted unchecked. It
@@ -368,6 +366,11 @@ async function startCheck(deps, workflow, digest) {
368
366
  }
369
367
  /** The words a stopped check's record starts with when it had nothing to check its draft on. */
370
368
  export const NOTHING_TO_CHECK = "nothing to check it on";
369
+ /** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none: only a
370
+ * check no grader compared (no agree_on, and no fast model to read the answers). */
371
+ export const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
372
+ /** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
373
+ export const differentDecisionWords = (k, n, example) => `its answers reached a different decision from the agent's on ${k} of ${n}${example ? ` (for example: ${example})` : ""}`;
371
374
  /** Stops a draft its check had nothing to run on (`why`: no input of the agent's it takes, or every input skipped at a
372
375
  * write): held, never promoted unchecked, its record `stopped` (nothing compiles again until a hold or its owner acts)
373
376
  * and naming the cause, which the compile's draft errors show (store-reads/loop.ts). It asks no recompile: a revision
@@ -419,7 +422,10 @@ async function checkRows(deps, record) {
419
422
  }
420
423
  const outcome = outcomeOf(run);
421
424
  const stoppedAt = outcome === "skipped_write" ? metricsOf(run).replay?.skipped : undefined;
425
+ // The grader's verdict on this pair, asked at the replay run's end (runner/compare-end.ts).
426
+ const compared = outcome === "answered" ? comparedOf(metricsOf(run).replay?.compared) : undefined;
422
427
  rows.push({
428
+ ...(compared ? { compared } : {}),
423
429
  of: replayed, input: inputText(launch.input), agent: await answerOf(store, replayed, context), outcome,
424
430
  answer: outcome === "answered" ? await answerOf(store, run.id, context) : null,
425
431
  ...(outcome === "handed_back" ? { escalated: (await handedBackOf(store, run.id, context)) ?? "" } : {}),
@@ -460,8 +466,9 @@ async function settleCheck(deps, workflow, digest, record) {
460
466
  return decided.record?.decided === "replaying" ? undefined : decided.record;
461
467
  }
462
468
  /** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
463
- * with the agent's recorded answer (learn/promote.ts sameAnswer), alone when it answered it with no escalate and no
464
- * failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
469
+ * with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
470
+ * when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
471
+ * when it answered it with no escalate and no failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
465
472
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
466
473
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
467
474
  * (the one write: of two claims at once, one decides). */
@@ -469,16 +476,25 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
469
476
  const now = deps.now ?? Date.now;
470
477
  const ran = read.rows.filter((row) => row.outcome !== "skipped_write");
471
478
  const alone = (row) => row.outcome === "answered";
472
- const agrees = (row) => alone(row) && sameAnswer(row.answer, row.agent);
479
+ // Compared on the bar's agree_on when it names paths (the definition's), else equal answers agree and the grader's
480
+ // verdict decides the rest; with no grader (no fast model), the whole answer.
481
+ const compared = new Map(ran.map((row) => [row, compareAnswers(row.answer, row.agent, bar.agree_on, row.compared)]));
482
+ const agrees = (row) => alone(row) && compared.get(row).same;
473
483
  const score = { n: ran.length, agreed: ran.filter(agrees).length, alone: ran.filter(alone).length };
474
484
  const ok = checkPasses(score, bar);
485
+ // The fast model that compared, when it read any input's answers.
486
+ const grader = [...compared.values()].find((one) => one.grader !== undefined)?.grader;
475
487
  // Each text is cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown).
476
488
  const shown = await deps.shown();
477
489
  const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
478
- const disagreements = ran.filter((row) => !agrees(row)).map((row) => ({
479
- run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
480
- ...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
481
- }));
490
+ const disagreements = ran.filter((row) => !agrees(row)).map((row) => {
491
+ const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
492
+ return {
493
+ run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
494
+ ...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
495
+ ...(differs ? { differs_on: cut(differs) } : {}),
496
+ };
497
+ });
482
498
  const stopped = !ok && bar.attempt === 2;
483
499
  const pct = (value) => `${(value * 100).toFixed(1)}%`;
484
500
  const shares = checkShares(score);
@@ -501,9 +517,14 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
501
517
  // and the words say none ran.
502
518
  const said = read.unstarted === score.n
503
519
  ? `none of its ${plural(score.n, "check run")} started by the check's deadline (its launch was interrupted: the server stopped after reserving it, say): nothing was checked`
504
- : `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)}), and ${score.agreed} of those said what the agent said (${pct(shares.agreement)}, the bar ${pct(bar.agree_min)})${aside ? ` (${aside})` : ""}`;
505
- const reason = ok ? `${said}: promoted` : stopped ? `${said}: held, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held; the agent's next run recompiles it once with the inputs it did not agree on`;
506
- const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}) };
520
+ : `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)}), and ${score.agreed} of those said what the agent said${bar.agree_on?.length ? ` on ${listed(bar.agree_on)}` : grader ? `, compared by the fast model (${grader})` : ""} (${pct(shares.agreement)}, the bar ${pct(bar.agree_min)})${aside ? ` (${aside})` : ""}`;
521
+ // The grader compared: how many answered alone reached another decision, with one it named. Compared whole and never
522
+ // once the same (no grader): free text two runs never repeat, most likely, so the owner is told what to set.
523
+ const differed = score.alone - score.agreed;
524
+ const example = disagreements.find((one) => one.differs_on !== undefined)?.differs_on;
525
+ const verbatim = ok || bar.agree_on?.length ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, score.alone, example)}` : "") : score.alone > 0 && score.agreed === 0 ? `; ${NEVER_WORD_FOR_WORD}` : "";
526
+ const reason = ok ? `${said}: promoted` : stopped ? `${said}: held${verbatim}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held${verbatim}; the agent's next run recompiles it once with the inputs it did not agree on`;
527
+ const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
507
528
  const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra }, still);
508
529
  if (decided.won)
509
530
  deps.log(`workflow-first: ${name} at ${digest} ${ok ? "promoted" : "held"}: ${reason}`);
@@ -767,7 +788,7 @@ export async function askReplay(ask, name, digest, inputs) {
767
788
  if (!launch.learning || launch.learning.noWorkflows)
768
789
  throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
769
790
  const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.now ? { now: ask.now } : {}) };
770
- const bar = { compile_after: loop.compile_after, agree_min: loop.agree_min, alone_min: loop.alone_min, attempt: attemptOf(records, name, digest) };
791
+ const bar = { ...loop, attempt: attemptOf(records, name, digest) };
771
792
  const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
772
793
  // Kept only while the revision's newest record is still the one read here: each record write stamps a new `at`.
773
794
  const reserved = await reserve(deps, found.workflow, digest, picked, said, (was) => was?.at === own?.at && was?.decided === own?.decided, bar);