@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61

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 (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -8,7 +8,7 @@ import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
8
8
  import { wireName } from "../catalog.js";
9
9
  import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
10
10
  import { Hearing } from "../heard.js";
11
- import { redactedAnswer } from "../key-refusal.js";
11
+ import { redacted, redactedAnswer, withheldWhole } from "../key-refusal.js";
12
12
  import { LEARNED_NODES_MAX, learnedCallEntries } from "../learned-nodes.js";
13
13
  import { computerCallsOf, shownName } from "../computer-calls.js";
14
14
  import { labelled, reflects } from "../reflect-range.js";
@@ -434,17 +434,112 @@ const ANSWERS_KEPT = 32;
434
434
  * purge, which may still hold the purged run's text, never puts that text back once the purge dropped it. */
435
435
  const forgetsOf = new WeakMap();
436
436
  export const servedSince = (store) => forgetsOf.get(store.origin) ?? 0;
437
- /** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers): a purged or deleted
438
- * run's text kept in no memory of this process (store-view.ts forgetServed). Counted (servedSince), so no read begun
439
- * before it keeps what it read. The keys it dropped. */
437
+ /** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers), and its texts from what
438
+ * they last cut (rowCutsOnce): a purged or deleted run's text kept in no memory of this process (store-view.ts
439
+ * forgetServed). Counted (servedSince), so no read begun before it keeps what it read. The answer keys it dropped. */
440
440
  export function forgetServedAnswers(store, runId) {
441
441
  forgetsOf.set(store.origin, servedSince(store) + 1);
442
442
  const kept = answersServed.get(store.origin);
443
443
  const dropped = [...(kept?.keys() ?? [])].filter((key) => key.startsWith(`${runId}\0`));
444
444
  for (const key of dropped)
445
445
  kept.delete(key);
446
+ forgetCuts(store.origin, runId);
446
447
  return dropped;
447
448
  }
449
+ const cutsKept = new WeakMap();
450
+ const CUT_SETS = 16;
451
+ const CUT_BYTES = 32 * 1024 * 1024;
452
+ /** The bound in force (CUT_BYTES): a test sets a smaller one to see the oldest go. */
453
+ export const cutBudget = { bytes: CUT_BYTES };
454
+ /** What one kept text costs beyond its characters: the Map entry and the boolean or string header, as counted. */
455
+ const CUT_ENTRY = 64;
456
+ const cutCost = (slot, made) => CUT_ENTRY + 2 * (slot.length + (typeof made === "string" ? made.length : 0));
457
+ /** A cut as kept: a string copied into one of its own, unit for unit (lone surrogates as written), so it holds no
458
+ * reference to the text it was sliced from; a boolean as it is. */
459
+ const cutCopy = (made) => (typeof made === "string" ? Buffer.from(made, "utf16le").toString("utf16le") : made);
460
+ /** Run `runId`'s value sets dropped from what the readers of store `origin` last cut (cutsKept). */
461
+ function forgetCuts(origin, runId) {
462
+ const cuts = cutsKept.get(origin);
463
+ if (!cuts)
464
+ return;
465
+ for (const [set, kept] of [...cuts.sets]) {
466
+ if (!set.startsWith(`${runId}\0`))
467
+ continue;
468
+ cuts.sets.delete(set);
469
+ cuts.bytes -= kept.bytes;
470
+ }
471
+ }
472
+ /** The row redactor (`redact`) and the whole-text check (`holds`) of run `runId`'s rows under its `cut` (run-cut.ts
473
+ * runCutValues), as a reader's TimelineOptions takes them: each text cut once per cut, its values in their order and its
474
+ * census mode (cutsKept), what was cut kept only while no run's text was forgotten since `since` (servedSince, taken
475
+ * before the read began). */
476
+ export function rowCutsOnce(store, runId, cut, since) {
477
+ const origin = store.origin;
478
+ const values = cut === "unreadable" ? [] : cut.values;
479
+ const mode = cut === "unreadable" ? "unreadable" : (cut.censusDigest ?? "none");
480
+ const set = `${runId}\0${createHash("sha256").update(JSON.stringify([mode, values])).digest("hex")}`;
481
+ const once = (how, text, cut) => {
482
+ const slot = `${how}\0${createHash("sha256").update(text, "utf16le").digest("base64")}`;
483
+ const held = cutsKept.get(origin);
484
+ const heldSet = held?.sets.get(set);
485
+ const kept = heldSet?.texts.get(slot);
486
+ if (kept !== undefined) {
487
+ // Read again: the most recently used, its set and itself.
488
+ held.sets.delete(set);
489
+ held.sets.set(set, heldSet);
490
+ heldSet.texts.delete(slot);
491
+ heldSet.texts.set(slot, kept);
492
+ return kept;
493
+ }
494
+ const made = cut();
495
+ const cost = cutCost(slot, made);
496
+ if (servedSince(store) !== since || cost > cutBudget.bytes)
497
+ return made;
498
+ const keep = cutCopy(made);
499
+ let cuts = cutsKept.get(origin);
500
+ if (!cuts)
501
+ cutsKept.set(origin, (cuts = { sets: new Map(), bytes: 0 }));
502
+ const texts = cuts.sets.get(set) ?? { texts: new Map(), bytes: 0 };
503
+ cuts.sets.delete(set);
504
+ cuts.sets.set(set, texts);
505
+ texts.texts.set(slot, keep);
506
+ texts.bytes += cost;
507
+ cuts.bytes += cost;
508
+ // The least recently used go first: the set read or written longest ago, its oldest texts (this set is the newest),
509
+ // a set left empty with them, and a set past CUT_SETS whole.
510
+ for (const [oldSet, old] of cuts.sets) {
511
+ if (cuts.bytes <= cutBudget.bytes && cuts.sets.size <= CUT_SETS)
512
+ break;
513
+ if (cuts.sets.size > CUT_SETS) {
514
+ cuts.sets.delete(oldSet);
515
+ cuts.bytes -= old.bytes;
516
+ continue;
517
+ }
518
+ for (const [oldSlot, oldMade] of old.texts) {
519
+ if (cuts.bytes <= cutBudget.bytes)
520
+ break;
521
+ const freed = cutCost(oldSlot, oldMade);
522
+ old.texts.delete(oldSlot);
523
+ old.bytes -= freed;
524
+ cuts.bytes -= freed;
525
+ }
526
+ if (old.texts.size === 0)
527
+ cuts.sets.delete(oldSet);
528
+ }
529
+ return made;
530
+ };
531
+ return {
532
+ redact: (text) => once("redact", text, () => redacted(text, values)),
533
+ holds: (text) => once("holds", text, () => withheldWhole(text, values)),
534
+ };
535
+ }
536
+ /** What the readers of `store` keep of their cuts now: the bytes counted (cutBudget bounds it), the texts and the sets, and
537
+ * each kept text (its set, its slot and what was made of it), so a test can read that nothing a run wrote is kept. */
538
+ export function cutsKeptOf(store) {
539
+ const cuts = cutsKept.get(store.origin);
540
+ const kept = [...(cuts?.sets ?? [])].flatMap(([set, of]) => [...of.texts].map(([slot, made]) => ({ set, slot, made })));
541
+ return { bytes: cuts?.bytes ?? 0, texts: kept.length, sets: cuts?.sets.size ?? 0, kept };
542
+ }
448
543
  /** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
449
544
  * cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
450
545
  * shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
@@ -7,7 +7,7 @@ import { type FirstReason, type PastRuns, pathMetrics, workflowCostsOf } from ".
7
7
  import { type Reflect } from "../reflect-range.js";
8
8
  import type { EntryLike, TimelineEvent } from "../timeline/index.js";
9
9
  import type { AnalyticsFilter } from "./analytics.js";
10
- import { type CostStop, type PromotionRecord, type Refused, type ResetRevision } from "../learn/promote.js";
10
+ import { type CostStop, type PromotionRecord, type ResetRevision } from "../learn/promote.js";
11
11
  import type { LearningProposal, Store } from "../store/store.js";
12
12
  /** A run's learning end: the Learning fields its end sets. */
13
13
  export type RunLearningEnd = Learning;
@@ -74,11 +74,8 @@ export declare function agentLearningOverStore(store: Store, agentId: string): P
74
74
  * money rule (workflowCostsOf over the same figures, pastRunsOf). A run still at work, an imported or archived one and a
75
75
  * workflow revision's run are left out. A run that learns whose end named no path is left out too and counted
76
76
  * (`unknown_path_runs`): its path and cost are not known, never `agent` at $0. `limit`: the latest runs shown, each
77
- * keeping its number; the summary is over every run; `bill` is the owner's bill over all of them. Its champion skips
78
- * what `refused` names of the agent's promotion records (purged-workflow.ts refusedOf, the purge gate's), as a run's
79
- * claim does; absent, none. */
80
- export type RefusedFor = (agentId: string, records: readonly PromotionRecord[]) => Promise<Refused>;
81
- export declare function agentCostOverStore(store: Store, agentId: string, limit?: number, refused?: RefusedFor): Promise<{
77
+ * keeping its number; the summary is over every run; `bill` is the owner's bill over all of them. */
78
+ export declare function agentCostOverStore(store: Store, agentId: string, limit?: number): Promise<{
82
79
  runs: CostRun[];
83
80
  summary: CostSummary;
84
81
  total_runs: number;
@@ -89,22 +86,22 @@ export declare function agentCostOverStore(store: Store, agentId: string, limit?
89
86
  }>;
90
87
  /** The agent's ledger read over the one store and summed (learn/ledger.ts summarize): its runs (as runs.list reads
91
88
  * them), each one's ledger row and spend rows (Learning.ledger), its promotion records (the revisions' K and state,
92
- * revisionsOf, skipping what `refused` names) and its audits' shadow runs. `records`: where a run's launch and rounds
93
- * are read (the agent's at once by default, agentRecordsOf). */
94
- export declare function agentLedgerOverStore(store: Store, agentId: string, refused?: RefusedFor, records?: RunRecords): Promise<{
89
+ * revisionsOf; learning records, Learning.records) and its audits' shadow runs. `records`: where a run's launch and
90
+ * rounds are read (the agent's at once by default, agentRecordsOf). */
91
+ export declare function agentLedgerOverStore(store: Store, agentId: string, records?: RunRecords): Promise<{
95
92
  out: Summarized;
96
93
  promotions: PromotionRecord[];
97
- skip: Refused | undefined;
98
94
  listed: RunRecord[];
99
95
  }>;
100
96
  /** Each revision of the agent's learned workflows its promotion records name (one per workflow and digest, in the order
101
97
  * they were first recorded), with the served runs its spend is spread over (K, its check's compile_after) and `state`
102
- * from its newest record: `checking` while its check replays, `serving` for the champion (championOf, skipping what
103
- * `refused` names: the purge gate's, so a purged run's revision is never said to serve), else `stopped`. A revision an
104
- * earlier reset of the agent's learning deleted (`reset`, learn/promote.ts keepResetLedger) comes first, stopped, at the
98
+ * from its newest record: `checking` while its check replays, `serving` for the champion (championOf: a purged run's
99
+ * records are gone with it, so its revision is never said to serve), else `stopped`. A revision an
100
+ * earlier reset of the agent's learning deleted (`reset`, learn/promote.ts keepResetLedger), or a run's purge deleted
101
+ * while other runs still carry its spend (store/sqlite/learning-rows.ts dropRunLearning), comes first, stopped, at the
105
102
  * K it was kept with, unless the records name it again. What each one spent is the ledger's (learn/ledger.ts summarize),
106
103
  * whatever the records say. */
107
- export declare function revisionsOf(records: readonly PromotionRecord[], reset?: readonly ResetRevision[], refused?: Refused): RevisionAt[];
104
+ export declare function revisionsOf(records: readonly PromotionRecord[], reset?: readonly ResetRevision[]): RevisionAt[];
108
105
  /** A run's costs as GET /runs/{id} shows them (RunAllIn, runAllInOverStore). */
109
106
  export type RunAllIn = {
110
107
  path: RunPath | null;
@@ -120,16 +117,15 @@ export type RunAllIn = {
120
117
  * (its row's when absent); one other than its row's (an imported run's estimate, a booking where its end stored none)
121
118
  * is its job's, less its look-back. While the run is at work `usd` is `rowUsd` and the rest null; null while unknown (its shadow still at work, a compile's or
122
119
  * a check's cost unknown), never $0. Undefined for an unknown run. A served run's share is the agent's ledger's
123
- * (agentLedgerOverStore), its revision's champion skipping what `refused` names of the agent's promotion records. */
124
- export declare function runAllInOverStore(store: Store, runId: string, rowUsd?: number | null, refused?: RefusedFor): Promise<RunAllIn | undefined>;
120
+ * (agentLedgerOverStore). */
121
+ export declare function runAllInOverStore(store: Store, runId: string, rowUsd?: number | null): Promise<RunAllIn | undefined>;
125
122
  /** The check the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
126
123
  * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's check numbers
127
124
  * (the share of the inputs it answered alone that were right on every field, and the agent's share on the same inputs
128
125
  * against the same known answers: `agent_agreed`). `cleared`: the joint
129
126
  * floor's verdict as the check decided it (`check.joint`, learn/field-check.ts), which every promotion passed. Null when
130
- * no run was served, nothing serves now (held, or never promoted), or it was promoted on no input (a dry run). The
131
- * champion skips what `refused` names (the purge gate's). */
132
- export declare function servingReplayOf(records: readonly PromotionRecord[], runs: readonly CostRun[], refused?: Refused): CostReplay | null;
127
+ * no run was served, nothing serves now (held, or never promoted), or it was promoted on no input (a dry run). */
128
+ export declare function servingReplayOf(records: readonly PromotionRecord[], runs: readonly CostRun[]): CostReplay | null;
133
129
  /** Every round run `runId` kept (one a follow-up opened again is a round past its first), oldest first: none when it kept
134
130
  * no learning. The store's proposal(runId) is the newest round alone; a read of what the run's learning did or spent
135
131
  * reads them all. */
@@ -163,10 +159,11 @@ export declare const costStopOverStore: (store: Store, agentId: string) => Promi
163
159
  * new answer is the agent's, with its digest. Else, for a run its launch offered a learned workflow, its timeline
164
160
  * (runner/learning-end.ts runPathOf, the agent calling the tool itself): `workflow` when its job did only that,
165
161
  * `handed_back` when the agent went on, with the workflow it called last that ran (its call's record,
166
- * runner/workflow-calls.ts workflowCallsOf). Any other run's path is `agent`. Both read the run's rows less its feedback rounds' (withoutFeedbackRounds): a grade's
162
+ * runner/workflow-calls.ts workflowCallsOf). Any other run's path is `agent`, one whose learned calls were all refused
163
+ * included. Both read the run's rows less its feedback rounds' (withoutFeedbackRounds): a grade's
167
164
  * round never moves the path. `cut` on a hand-back a restart cut (servedOf: the workflow's call ended `interrupted`),
168
165
  * never one the workflow made itself. `entries`: the run's (runEntries), when the caller read them already. */
169
- export declare function runPathOverStore(store: Store, runId: string, started: RunLaunch["learning"], redact?: (text: string) => string, entries?: readonly EntryLike[]): Promise<{
166
+ export declare function runPathOverStore(store: Store, runId: string, started: RunLaunch["learning"], redact: (text: string) => string, entries?: readonly EntryLike[]): Promise<{
170
167
  path: RunPath;
171
168
  workflow: string | null;
172
169
  digest?: string;
@@ -178,8 +175,8 @@ export declare function runPathOverStore(store: Store, runId: string, started: R
178
175
  * classified (runPathOverStore, for a run that learns) and kept with its calls (`workflow_calls`) and why its ending
179
176
  * claim's first choice did or did not serve (`choice`, firstChoice's reason). `redact`: the run's cut, as its
180
177
  * follow-up showed a served answer. */
181
- export declare function runPathMetricsOverStore(store: Store, runId: string, launch: RunLaunch, { redact, choice }?: {
182
- readonly redact?: (text: string) => string;
178
+ export declare function runPathMetricsOverStore(store: Store, runId: string, launch: RunLaunch, { redact, choice }: {
179
+ readonly redact: (text: string) => string;
183
180
  readonly choice?: FirstReason;
184
181
  }): Promise<ReturnType<typeof pathMetrics>>;
185
182
  /** The path a run's views say it took (GET /runs/{id} and each runs list row: `path`, and `workflow`), read off its record
@@ -244,12 +241,12 @@ export declare function learnedUseOf(reflect: Pick<Reflect, "after" | "until"> |
244
241
  export declare function usedOnly(started: NonNullable<RunLaunch["learning"]>, terminal: boolean, at: string): RunLearningEnd;
245
242
  /** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
246
243
  * run's learning end (runLearningEnd) and the seed it started from as its launch records it, what it held for its
247
- * owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf, read only when it held
244
+ * owner's OK as it stands at its agent's newest save (`statuses`, learning-routes.ts statusesOf, read only when it held
248
245
  * something; none: as the merge wrote it), settled once the run is final. Null when the run kept no learning. */
249
246
  export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
250
247
  run: string;
251
248
  state: "dropped" | "merged" | "seeded" | "reflecting";
252
- reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
249
+ reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
253
250
  detail: string | null;
254
251
  at: string;
255
252
  workflows: import("../learning.js").LearnedFile[];
@@ -292,7 +289,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
292
289
  };
293
290
  run: string;
294
291
  state: "dropped" | "merged" | "seeded" | "reflecting";
295
- reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
292
+ reason: "cancelled" | "reset" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "empty" | "checker" | "use" | "purged_since_seed" | null;
296
293
  detail: string | null;
297
294
  at: string;
298
295
  workflows: import("../learning.js").LearnedFile[];
@@ -202,27 +202,35 @@ export async function agentLearningOverStore(store, agentId) {
202
202
  }
203
203
  return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null) };
204
204
  }
205
- export async function agentCostOverStore(store, agentId, limit = Infinity, refused) {
206
- const { out, promotions, skip, listed } = await agentLedgerOverStore(store, agentId, refused);
205
+ /** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): what its ledger
206
+ * says (learn/ledger.ts summarize, agentLedgerOverStore): each of its agentic runs that ended (ended, stopped or
207
+ * failed), oldest first, each run that does a job numbered from 1 (a replay none: the bill's numbering), with its own
208
+ * cost and what learning added for it, the path it took and the learned workflow it ran, the revision of that workflow
209
+ * and whether an audit's shadow ran for it; what the series shows (costSummary); and each learned workflow against the
210
+ * money rule (workflowCostsOf over the same figures, pastRunsOf). A run still at work, an imported or archived one and a
211
+ * workflow revision's run are left out. A run that learns whose end named no path is left out too and counted
212
+ * (`unknown_path_runs`): its path and cost are not known, never `agent` at $0. `limit`: the latest runs shown, each
213
+ * keeping its number; the summary is over every run; `bill` is the owner's bill over all of them. */
214
+ export async function agentCostOverStore(store, agentId, limit = Infinity) {
215
+ const { out, promotions, listed } = await agentLedgerOverStore(store, agentId);
207
216
  const { runs } = out;
208
217
  // Each learned workflow that ran first, where it stands against the money rule, over the figures this series shows: a
209
218
  // workflow over the line shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
210
219
  const workflows = workflowCostsOf(await pastRunsRead(store, agentId, out, listed));
211
- const summary = { ...out.summary, replay: servingReplayOf(promotions, runs, skip) };
220
+ const summary = { ...out.summary, replay: servingReplayOf(promotions, runs) };
212
221
  const bill = { ...out.bill, holds: holdsOf(promotions, runs) };
213
222
  return { runs: runs.slice(Math.max(0, runs.length - limit)), summary, total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: out.unknown_path_runs, workflows, bill };
214
223
  }
215
224
  /** The agent's ledger read over the one store and summed (learn/ledger.ts summarize): its runs (as runs.list reads
216
225
  * them), each one's ledger row and spend rows (Learning.ledger), its promotion records (the revisions' K and state,
217
- * revisionsOf, skipping what `refused` names) and its audits' shadow runs. `records`: where a run's launch and rounds
218
- * are read (the agent's at once by default, agentRecordsOf). */
219
- export async function agentLedgerOverStore(store, agentId, refused, records) {
226
+ * revisionsOf; learning records, Learning.records) and its audits' shadow runs. `records`: where a run's launch and
227
+ * rounds are read (the agent's at once by default, agentRecordsOf). */
228
+ export async function agentLedgerOverStore(store, agentId, records) {
220
229
  const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
221
230
  const read = await ledgerReadOf(store, agentId, listed, records ?? (await agentRecordsOf(store, agentId, listed)));
222
- const promotions = await promotionsOf(store.settings, agentId);
223
- const skip = refused ? await refused(agentId, promotions) : undefined;
224
- const revisions = revisionsOf(promotions, await resetLedgerOf(store.settings, agentId), skip);
225
- return { out: summarize({ ...read, revisions }), promotions, skip, listed };
231
+ const promotions = await promotionsOf(store.learning, agentId);
232
+ const revisions = revisionsOf(promotions, await resetLedgerOf(store.settings, agentId));
233
+ return { out: summarize({ ...read, revisions }), promotions, listed };
226
234
  }
227
235
  /** How many runs a ledger read reads at once (ledgerReadOf: a run's rounds, its launch, its revision). */
228
236
  const READS_AT_ONCE = 16;
@@ -303,12 +311,13 @@ const revisionOfRow = (row) => {
303
311
  };
304
312
  /** Each revision of the agent's learned workflows its promotion records name (one per workflow and digest, in the order
305
313
  * they were first recorded), with the served runs its spend is spread over (K, its check's compile_after) and `state`
306
- * from its newest record: `checking` while its check replays, `serving` for the champion (championOf, skipping what
307
- * `refused` names: the purge gate's, so a purged run's revision is never said to serve), else `stopped`. A revision an
308
- * earlier reset of the agent's learning deleted (`reset`, learn/promote.ts keepResetLedger) comes first, stopped, at the
314
+ * from its newest record: `checking` while its check replays, `serving` for the champion (championOf: a purged run's
315
+ * records are gone with it, so its revision is never said to serve), else `stopped`. A revision an
316
+ * earlier reset of the agent's learning deleted (`reset`, learn/promote.ts keepResetLedger), or a run's purge deleted
317
+ * while other runs still carry its spend (store/sqlite/learning-rows.ts dropRunLearning), comes first, stopped, at the
309
318
  * K it was kept with, unless the records name it again. What each one spent is the ledger's (learn/ledger.ts summarize),
310
319
  * whatever the records say. */
311
- export function revisionsOf(records, reset = [], refused) {
320
+ export function revisionsOf(records, reset = []) {
312
321
  const newest = new Map();
313
322
  for (const one of records)
314
323
  newest.set(`${one.workflow}\0${one.digest}`, one);
@@ -316,7 +325,7 @@ export function revisionsOf(records, reset = [], refused) {
316
325
  ...reset.filter((one) => !newest.has(`${one.workflow}\0${one.digest}`)).map((one) => ({ workflow: one.workflow, digest: one.digest, k: one.k ?? COMPILE_AFTER_DEFAULT, state: "stopped" })),
317
326
  ...[...newest.values()].map((one) => ({
318
327
  workflow: one.workflow, digest: one.digest, k: one.check?.compile_after ?? COMPILE_AFTER_DEFAULT,
319
- state: one.decided === "replaying" ? "checking" : championOf(records, one.workflow, refused)?.digest === one.digest ? "serving" : "stopped",
328
+ state: one.decided === "replaying" ? "checking" : championOf(records, one.workflow)?.digest === one.digest ? "serving" : "stopped",
320
329
  })),
321
330
  ];
322
331
  }
@@ -331,8 +340,8 @@ export function revisionsOf(records, reset = [], refused) {
331
340
  * (its row's when absent); one other than its row's (an imported run's estimate, a booking where its end stored none)
332
341
  * is its job's, less its look-back. While the run is at work `usd` is `rowUsd` and the rest null; null while unknown (its shadow still at work, a compile's or
333
342
  * a check's cost unknown), never $0. Undefined for an unknown run. A served run's share is the agent's ledger's
334
- * (agentLedgerOverStore), its revision's champion skipping what `refused` names of the agent's promotion records. */
335
- export async function runAllInOverStore(store, runId, rowUsd, refused) {
343
+ * (agentLedgerOverStore). */
344
+ export async function runAllInOverStore(store, runId, rowUsd) {
336
345
  const run = await store.runs.get(runId);
337
346
  if (!run)
338
347
  return undefined;
@@ -346,7 +355,7 @@ export async function runAllInOverStore(store, runId, rowUsd, refused) {
346
355
  }
347
356
  // A served run carries a share of its revision's spend: its figures are the series' own, over the agent's ledger.
348
357
  const served = path !== null && SERVED_PATHS.includes(path) && revisionOfRow(run) !== undefined;
349
- const figures = (served ? (await agentLedgerOverStore(store, run.agentId, refused)).out.figures.get(run.id) : undefined) ?? (await runFiguresOf(store, run));
358
+ const figures = (served ? (await agentLedgerOverStore(store, run.agentId)).out.figures.get(run.id) : undefined) ?? (await runFiguresOf(store, run));
350
359
  // The run's view priced it other than its row does (`rowUsd`: an imported run's catalog estimate, or its booking where
351
360
  // its end stored none): its job is that figure, as its end would have recorded it at that cost (record: less its
352
361
  // look-back), its learning's parts the ledger's.
@@ -380,11 +389,10 @@ async function runFiguresOf(store, run) {
380
389
  * (the share of the inputs it answered alone that were right on every field, and the agent's share on the same inputs
381
390
  * against the same known answers: `agent_agreed`). `cleared`: the joint
382
391
  * floor's verdict as the check decided it (`check.joint`, learn/field-check.ts), which every promotion passed. Null when
383
- * no run was served, nothing serves now (held, or never promoted), or it was promoted on no input (a dry run). The
384
- * champion skips what `refused` names (the purge gate's). */
385
- export function servingReplayOf(records, runs, refused) {
392
+ * no run was served, nothing serves now (held, or never promoted), or it was promoted on no input (a dry run). */
393
+ export function servingReplayOf(records, runs) {
386
394
  const name = runs.findLast((run) => (run.path === "workflow" || run.path === "handed_back") && run.workflow !== null)?.workflow;
387
- const check = name ? championOf(records, name, refused)?.check : undefined;
395
+ const check = name ? championOf(records, name)?.check : undefined;
388
396
  if (!check?.n)
389
397
  return null;
390
398
  const agreed = check.agreed ?? 0, alone = check.alone ?? 0;
@@ -468,7 +476,8 @@ export const costStopOverStore = async (store, agentId) => pastRunsOverStore(sto
468
476
  * new answer is the agent's, with its digest. Else, for a run its launch offered a learned workflow, its timeline
469
477
  * (runner/learning-end.ts runPathOf, the agent calling the tool itself): `workflow` when its job did only that,
470
478
  * `handed_back` when the agent went on, with the workflow it called last that ran (its call's record,
471
- * runner/workflow-calls.ts workflowCallsOf). Any other run's path is `agent`. Both read the run's rows less its feedback rounds' (withoutFeedbackRounds): a grade's
479
+ * runner/workflow-calls.ts workflowCallsOf). Any other run's path is `agent`, one whose learned calls were all refused
480
+ * included. Both read the run's rows less its feedback rounds' (withoutFeedbackRounds): a grade's
472
481
  * round never moves the path. `cut` on a hand-back a restart cut (servedOf: the workflow's call ended `interrupted`),
473
482
  * never one the workflow made itself. `entries`: the run's (runEntries), when the caller read them already. */
474
483
  export async function runPathOverStore(store, runId, started, redact, entries) {
@@ -477,7 +486,9 @@ export async function runPathOverStore(store, runId, started, redact, entries) {
477
486
  // the run is classified as the agent's own calls say.
478
487
  const calls = workflowCallsOf(entries);
479
488
  const served = calls.some((call) => call.caller === "platform" && call.outcome === "refused") ? undefined : servedOf(entries);
480
- if (!served && !started?.workflows?.length)
489
+ // A run offered no workflow, or whose every learned call was refused (none ran a node), is the agent's, whatever its
490
+ // timeline shows of the refused calls (runPathOf reads a call and the agent going on after it as a hand-back).
491
+ if (!served && (!started?.workflows?.length || (calls.length > 0 && calls.every((call) => call.outcome === "refused"))))
481
492
  return { path: "agent", workflow: null };
482
493
  // The path is who wrote the run's final answer, read on the job's own rows: a grade's feedback round asks the agent no
483
494
  // turn of the job's, so its words and its rows never change it (withoutFeedbackRounds).
@@ -488,7 +499,7 @@ export async function runPathOverStore(store, runId, started, redact, entries) {
488
499
  // The workflow's answer as it produced it (its journal's), and as a follow-up showed it to the agent (cut by the
489
500
  // runner's `redact`, adapter-loop.ts servedAnswerText): an agent that says it again leaves the path the workflow's.
490
501
  const answer = servedAnswerOf(entries)?.answer ?? "";
491
- const alone = served.outcome === "answered" && servedAnswerStands(answer, rows, redact ? redact(answer) : undefined);
502
+ const alone = served.outcome === "answered" && servedAnswerStands(answer, rows, redact(answer));
492
503
  return { path: alone ? "workflow" : "handed_back", workflow: served.workflow, ...(served.digest ? { digest: served.digest } : {}), ...(served.promotion !== undefined ? { promotion: served.promotion } : {}), ...(served.cut ? { cut: true } : {}) };
493
504
  }
494
505
  const path = runPathOf(rows);
@@ -506,7 +517,7 @@ export async function runPathOverStore(store, runId, started, redact, entries) {
506
517
  * classified (runPathOverStore, for a run that learns) and kept with its calls (`workflow_calls`) and why its ending
507
518
  * claim's first choice did or did not serve (`choice`, firstChoice's reason). `redact`: the run's cut, as its
508
519
  * follow-up showed a served answer. */
509
- export async function runPathMetricsOverStore(store, runId, launch, { redact, choice } = {}) {
520
+ export async function runPathMetricsOverStore(store, runId, launch, { redact, choice }) {
510
521
  if (!launch.learning && !launch.audit)
511
522
  return {};
512
523
  const entries = await runEntries(store, runId, BACKGROUND_CONTEXT);
@@ -638,8 +649,9 @@ export function callArgsOf(entries) {
638
649
  }
639
650
  else if (entry.kind === KINDS.callStart) {
640
651
  const data = (entry.data ?? {});
652
+ // An SDK learned_workflow start stored withheld names its workflow apart from its input (CallStartData.workflow).
641
653
  if (typeof data.callId === "string" && typeof data.tool === "string")
642
- out.set(data.callId, { tool: data.tool, args: argsOf(data.input) });
654
+ out.set(data.callId, { tool: data.tool, args: typeof data.workflow === "string" ? { name: data.workflow } : argsOf(data.input) });
643
655
  }
644
656
  }
645
657
  return out;
@@ -687,7 +699,7 @@ export function usedOnly(started, terminal, at) {
687
699
  }
688
700
  /** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
689
701
  * run's learning end (runLearningEnd) and the seed it started from as its launch records it, what it held for its
690
- * owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf, read only when it held
702
+ * owner's OK as it stands at its agent's newest save (`statuses`, learning-routes.ts statusesOf, read only when it held
691
703
  * something; none: as the merge wrote it), settled once the run is final. Null when the run kept no learning. */
692
704
  export async function runLearningOverStore(store, runId, shown, secrets, statuses) {
693
705
  const started = await learningStartOfRun(store, runId);
@@ -700,7 +712,7 @@ export async function runLearningOverStore(store, runId, shown, secrets, statuse
700
712
  return null;
701
713
  // A kept compile's promotion (learn/promote.ts), as the agent's records say now: unread, it stays undecided.
702
714
  if (end.compiled?.digest && row) {
703
- const promoted = promotedOf(await promotionsOf(store.settings, row.agentId).catch(() => []), end.compiled.workflow, end.compiled.digest);
715
+ const promoted = promotedOf(await promotionsOf(store.learning, row.agentId).catch(() => []), end.compiled.workflow, end.compiled.digest);
704
716
  if (promoted !== undefined)
705
717
  end.compiled = { ...end.compiled, promoted };
706
718
  }
@@ -711,7 +723,7 @@ export async function runLearningOverStore(store, runId, shown, secrets, statuse
711
723
  // The run's own grade (PUT /runs/{id}/grade), as its agent keeps it and the PUT answered it, with the round it opened.
712
724
  // Never its `expected` (a person's words, uncut), nor its label (not kept). Its workflow's name is cut as every other
713
725
  // learning name is (`shown.name`): a secret registered after the grade never shows here.
714
- const grade = row ? (await gradesOf(store.settings, row.agentId).catch(() => [])).find((one) => one.run === runId) : undefined;
726
+ const grade = row ? (await gradesOf(store.learning, row.agentId).catch(() => [])).find((one) => one.run === runId) : undefined;
715
727
  if (!grade)
716
728
  return body;
717
729
  const { expected: _, ...graded } = gradeView(grade);
@@ -23,7 +23,7 @@ export async function agentLoopOverStore(store, agentId) {
23
23
  const current = (await store.agents.get(agentId))?.currentRevision;
24
24
  const body = current ? (await store.agents.revision(current))?.body : undefined;
25
25
  const completed_runs = (await lastOwnRuns(store, agentId, loopOf(body?.learning).compile_after)).length;
26
- const promotions = await promotionsOf(store.settings, agentId).catch(() => []);
26
+ const promotions = await promotionsOf(store.learning, agentId).catch(() => []);
27
27
  const compiles = [];
28
28
  for (const run of ended) {
29
29
  for (const kept of await roundsOf(store, run.id).catch(() => [])) {
@@ -10,10 +10,14 @@ import type { PendingAsk } from "./browser-person.js";
10
10
  import { type Approvals } from "./approvals.js";
11
11
  import { type KeptListing, type RunListing, type RunRow, type Store } from "./store/store.js";
12
12
  import type { RecordingView } from "./run-recordings.js";
13
+ import { type FactoryActivity, type FactoryObserved } from "./factory-activity.js";
13
14
  /** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
14
15
  * one rotated is cut at once), and the agents' saved sign-ins (for the handed-pointer cut). The server passes the same it
15
16
  * passes the file path. */
16
17
  export interface ViewDeps {
18
+ /** Scoped factory lists ask for source/provenance metadata. Ordinary run reads keep their existing shape and cost.
19
+ * "kept": all of it but who observes the run now, for a listing (KeptFactory): that is read when it is listed. */
20
+ readonly factory?: boolean | "kept";
17
21
  readonly origin: string;
18
22
  readonly serverSecrets: () => string[];
19
23
  readonly signIns?: SignInReader;
@@ -27,7 +31,7 @@ export interface ViewDeps {
27
31
  * run's error names a refused key in plain words, as its Timeline's error row does. Default: this process's
28
32
  * environment (the server passes it with the keys a person saved). */
29
33
  readonly keyEnv?: () => NodeJS.ProcessEnv;
30
- /** Each learned item's status on agent `agentId`'s learning folder's main (learning-routes.ts statusesOf): what a run held
34
+ /** Each learned item's status at agent `agentId`'s newest learning save (learning-routes.ts statusesOf): what a run held
31
35
  * for its owner's OK reads as it stands there. None: as the merge wrote it. */
32
36
  readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
33
37
  /** Run `runId`'s screen recordings (run-recordings.ts recordingsOf), the run ended at `endedAt` (null: it has not). Only
@@ -55,6 +59,9 @@ export declare const answerOf: (timeline: readonly TimelineEvent[]) => string |
55
59
  /** The run read from the store: the row, its launch, its timeline, its agent's revision count for the version, its
56
60
  * learning end, and the sign-in cut it serves through. Undefined for an unknown run. */
57
61
  interface StoreRun {
62
+ readonly factory?: Omit<FactoryActivity, "controls" | "observation"> & {
63
+ readonly observation?: FactoryActivity["observation"];
64
+ };
58
65
  readonly native?: Record<string, unknown>;
59
66
  readonly sdk?: Record<string, unknown>;
60
67
  readonly cli_learning?: Record<string, unknown>;
@@ -134,6 +141,10 @@ interface StoreRun {
134
141
  * look-back's own end is in (poll_after_ms 1000, the timeline not final). */
135
142
  readonly lookingBack?: true;
136
143
  }
144
+ /** A runner holds the run's claim now: it is not in a final state, a runner is named on its row, and its lease has not run
145
+ * out (claimed_until >= now, the predicate the claimable query's `claimed_until < ?` is the negation of). `now` is the
146
+ * server's clock, so a test on a moved clock reads a fresh claim as live. */
147
+ export declare function liveOf(runRow: RunRow, now: number): boolean;
137
148
  /** Whether the run's turn stands on a person: a tool call asked for their approval with no answer in its journal (the
138
149
  * view's `approvals`, asksOf), or a browser or desktop hand-over neither answered in its journal nor by a hand-back row.
139
150
  * By the journal alone, never by the clock: a hand-over past its expiry still holds the turn until its expiry is written
@@ -164,7 +175,7 @@ export declare function lookingBackEnd(store: Store, stored: RunRow): Promise<Ke
164
175
  * and for an unknown run. */
165
176
  export declare function toolsUsdOverStore(store: Store, runId: string): Promise<number | null>;
166
177
  /** The start sweep's heal of run `runId` (cost-heal.ts): the same rule as its run read's (bookedCostOf, healOf), from its
167
- * row, its launch and its journal alone, so a sweep over many runs reads no timeline and no learning folder. True when
178
+ * row, its launch and its journal alone, so a sweep over many runs reads no timeline and no learning. True when
168
179
  * it wrote the booking's figure; a failed read or write throws, for the sweep to count. */
169
180
  export declare function healedOverStore(store: Store, runId: string): Promise<boolean>;
170
181
  /** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
@@ -182,6 +193,17 @@ export declare function summaryOfView(view: Record<string, unknown>): Record<str
182
193
  * sign-in it was handed could not be read: that read may fail only for now, and the run reads whole once it recovers);
183
194
  * and what outside the run it read (LISTING_HELD, LISTING_KEYED). Undefined for an unknown run. */
184
195
  export declare function listingOverStore(store: Store, runId: string, deps: ViewDeps): Promise<RunListing | undefined>;
196
+ /** What a listing keeps for the Agent Factory (RunListing.factory): the run's factory projection as the build's view gave
197
+ * it (`activity`: its watermark of that build's snapshot, its source, controls, last activity, GitHub work and children,
198
+ * all of which move only with a write that moves the run's mark), and who the run is observed through (`observed`), which
199
+ * a scoped list reads at each request (factory-activity.ts observationOf): a lease renewed writes nothing to the run. */
200
+ export type KeptFactory = {
201
+ readonly activity: Omit<FactoryActivity, "observation">;
202
+ readonly observed: FactoryObserved;
203
+ };
204
+ /** What `listing` keeps for the Agent Factory, cut again of the server's secrets as `listedItem` cuts its item when they
205
+ * moved since its build; undefined for a listing built before one was kept, which a scoped list builds again, once. */
206
+ export declare function keptFactory(listing: KeptListing, serverSecrets: readonly string[]): KeptFactory | undefined;
185
207
  /** Whether `listing` is cut of the server's secrets as they are now. A list builds any other again before it shows it
186
208
  * (server.ts runsPage): the run's view cuts a value whole where it holds a secret (a note's name reads [redacted]), which
187
209
  * cutting the built item again could not do. */