@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.50

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 (170) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +236 -26
  3. package/dist/agent-delete.d.ts +36 -12
  4. package/dist/agent-delete.js +213 -30
  5. package/dist/agents-store.d.ts +6 -2
  6. package/dist/agents-store.js +18 -5
  7. package/dist/agents.d.ts +8 -1
  8. package/dist/agents.js +14 -4
  9. package/dist/answer-json.d.ts +2 -2
  10. package/dist/answer-json.js +3 -4
  11. package/dist/api-only.d.ts +7 -10
  12. package/dist/api-only.js +9 -11
  13. package/dist/archil-routes.d.ts +1 -1
  14. package/dist/archil-routes.js +4 -3
  15. package/dist/browser-sessions.d.ts +56 -0
  16. package/dist/browser-sessions.js +117 -0
  17. package/dist/compute-cost.d.ts +101 -0
  18. package/dist/compute-cost.js +250 -0
  19. package/dist/computer-routes.d.ts +4 -15
  20. package/dist/computer-routes.js +6 -10
  21. package/dist/console/assets/index-D0mr9wfZ.css +1 -0
  22. package/dist/console/assets/index-D7G6o-1E.js +720 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/errors.d.ts +4 -1
  25. package/dist/errors.js +15 -5
  26. package/dist/eval-previous.d.ts +52 -0
  27. package/dist/eval-previous.js +164 -0
  28. package/dist/file-types.d.ts +2 -0
  29. package/dist/file-types.js +3 -1
  30. package/dist/harness.js +2 -1
  31. package/dist/import.js +4 -3
  32. package/dist/learn/check.d.ts +16 -4
  33. package/dist/learn/check.js +30 -26
  34. package/dist/learn/promote.d.ts +7 -1
  35. package/dist/learn/promote.js +47 -0
  36. package/dist/learn/repick.d.ts +43 -0
  37. package/dist/learn/repick.js +202 -0
  38. package/dist/learn/workflow-draft.d.ts +4 -0
  39. package/dist/learn/workflow-draft.js +10 -7
  40. package/dist/learned-workflow.d.ts +2 -0
  41. package/dist/learned-workflow.js +19 -2
  42. package/dist/learning-setting.d.ts +13 -0
  43. package/dist/learning-setting.js +23 -1
  44. package/dist/llms.txt +1 -1
  45. package/dist/openapi.js +180 -14
  46. package/dist/paid-calls.d.ts +17 -7
  47. package/dist/paid-calls.js +15 -9
  48. package/dist/run-launch.d.ts +2 -2
  49. package/dist/run-launch.js +2 -1
  50. package/dist/run-learning-served.d.ts +1 -1
  51. package/dist/run-timeline-served.js +5 -3
  52. package/dist/run-usage.d.ts +125 -0
  53. package/dist/run-usage.js +394 -0
  54. package/dist/runner/adapter-loop.d.ts +4 -0
  55. package/dist/runner/adapter-loop.js +66 -21
  56. package/dist/runner/adapter-run-spec.d.ts +8 -3
  57. package/dist/runner/adapter-run-spec.js +13 -6
  58. package/dist/runner/big-writes.d.ts +33 -0
  59. package/dist/runner/big-writes.js +105 -0
  60. package/dist/runner/cli-run-spec.js +14 -6
  61. package/dist/runner/conformance/harness.d.ts +2 -0
  62. package/dist/runner/conformance/harness.js +18 -4
  63. package/dist/runner/feedback-round.d.ts +29 -1
  64. package/dist/runner/feedback-round.js +54 -3
  65. package/dist/runner/held.d.ts +4 -1
  66. package/dist/runner/journal-kinds.d.ts +3 -1
  67. package/dist/runner/learning-end.js +54 -18
  68. package/dist/runner/loop-contract.d.ts +3 -0
  69. package/dist/runner/metrics.d.ts +4 -0
  70. package/dist/runner/metrics.js +9 -0
  71. package/dist/runner/monid-run.js +2 -2
  72. package/dist/runner/promotion.js +8 -2
  73. package/dist/runner/reflect-hook.js +3 -2
  74. package/dist/runner/run-child-host.d.ts +15 -2
  75. package/dist/runner/run-child-host.js +24 -8
  76. package/dist/runner/run-child.js +3 -0
  77. package/dist/runner/save-slots.d.ts +9 -0
  78. package/dist/runner/save-slots.js +91 -0
  79. package/dist/runs-over-store.d.ts +3 -2
  80. package/dist/runs-over-store.js +9 -7
  81. package/dist/sdk/runs.d.ts +3 -4
  82. package/dist/sdk/runs.js +10 -7
  83. package/dist/sdk/runtimes.d.ts +19 -0
  84. package/dist/sdk/runtimes.js +23 -0
  85. package/dist/sdk/schema.d.ts +14 -8
  86. package/dist/sdk/schema.js +18 -6
  87. package/dist/server.d.ts +7 -3
  88. package/dist/server.js +223 -100
  89. package/dist/store/agent-body.d.ts +2 -3
  90. package/dist/store/agent-body.js +3 -2
  91. package/dist/store/index.d.ts +2 -2
  92. package/dist/store/index.js +1 -1
  93. package/dist/store/journal/storage.js +1 -1
  94. package/dist/store/open.d.ts +1 -1
  95. package/dist/store/open.js +1 -1
  96. package/dist/store/postgres/migrations/0021_purged.sql +13 -0
  97. package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
  98. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  99. package/dist/store/schema.d.ts +20 -1
  100. package/dist/store/schema.js +60 -5
  101. package/dist/store/sqlite/connection.d.ts +4 -1
  102. package/dist/store/sqlite/connection.js +5 -0
  103. package/dist/store/sqlite/run-patch.d.ts +8 -3
  104. package/dist/store/sqlite/run-patch.js +15 -7
  105. package/dist/store/sqlite/store.d.ts +2 -1
  106. package/dist/store/sqlite/store.js +279 -68
  107. package/dist/store/sqlite/worker.d.ts +9 -0
  108. package/dist/store/sqlite/worker.js +18 -1
  109. package/dist/store/store.d.ts +149 -9
  110. package/dist/store/store.js +63 -0
  111. package/dist/store-reads/analytics.js +2 -1
  112. package/dist/store-reads/cap.d.ts +17 -7
  113. package/dist/store-reads/cap.js +54 -4
  114. package/dist/store-reads/decisions.d.ts +21 -0
  115. package/dist/store-reads/decisions.js +22 -0
  116. package/dist/store-reads/journal.d.ts +8 -2
  117. package/dist/store-reads/journal.js +27 -8
  118. package/dist/store-reads/learning.d.ts +1 -1
  119. package/dist/store-reads/learning.js +5 -2
  120. package/dist/store-reads/runs.js +2 -0
  121. package/dist/store-reads/stats.js +4 -2
  122. package/dist/store-view.d.ts +12 -1
  123. package/dist/store-view.js +98 -38
  124. package/dist/template-eval.d.ts +15 -1
  125. package/dist/template-eval.js +92 -13
  126. package/dist/templates.d.ts +1 -1
  127. package/dist/templates.js +4 -3
  128. package/dist/timeline/labels.js +17 -0
  129. package/dist/tool-list.js +1 -0
  130. package/dist/tools.d.ts +6 -2
  131. package/dist/tools.js +22 -1
  132. package/dist/trigger-targets.d.ts +28 -9
  133. package/dist/trigger-targets.js +19 -16
  134. package/dist/triggers.d.ts +2 -1
  135. package/dist/triggers.js +5 -2
  136. package/dist/validate.d.ts +4 -2
  137. package/dist/validate.js +13 -3
  138. package/dist/viewer-credential.d.ts +3 -4
  139. package/dist/viewer-credential.js +6 -4
  140. package/dist/web-fake.d.ts +25 -0
  141. package/dist/web-fake.js +38 -1
  142. package/dist/web-save.d.ts +75 -0
  143. package/dist/web-save.js +235 -0
  144. package/dist/workspace/archil-claim.d.ts +5 -2
  145. package/dist/workspace/archil-claim.js +5 -2
  146. package/dist/workspace/archil-disk.d.ts +10 -1
  147. package/dist/workspace/archil-disk.js +19 -1
  148. package/dist/workspace/archil.d.ts +3 -0
  149. package/dist/workspace/archil.js +101 -16
  150. package/dist/workspace/computer-for-claim.d.ts +19 -1
  151. package/dist/workspace/computer-for-claim.js +88 -20
  152. package/dist/workspace/computer-intervals.d.ts +26 -0
  153. package/dist/workspace/computer-intervals.js +58 -0
  154. package/dist/workspace/computer-janitor.d.ts +7 -3
  155. package/dist/workspace/computer-janitor.js +14 -6
  156. package/dist/workspace/computer-kept.d.ts +7 -2
  157. package/dist/workspace/computer-kept.js +9 -2
  158. package/dist/workspace/pieced.d.ts +14 -0
  159. package/dist/workspace/pieced.js +23 -0
  160. package/dist/workspace/resolve-computer.d.ts +7 -4
  161. package/dist/workspace/resolve-computer.js +21 -32
  162. package/dist/workspace/run-disk.js +32 -12
  163. package/dist/workspace/run-end-computers.d.ts +1 -0
  164. package/dist/workspace/run-end-computers.js +4 -1
  165. package/dist/workspace/run-workspace.d.ts +1 -1
  166. package/dist/workspace/run-workspace.js +11 -6
  167. package/package.json +10 -10
  168. package/templates/README.md +36 -7
  169. package/dist/console/assets/index-CTGegcKt.css +0 -1
  170. package/dist/console/assets/index-D1Se6mgG.js +0 -715
@@ -66,14 +66,20 @@ export type WholeAnswer = {
66
66
  };
67
67
  /** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
68
68
  export declare const wholeAnswerFor: (values: readonly string[]) => WholeAnswer;
69
+ export declare const servedSince: (store: Store) => number;
70
+ /** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers): a purged or deleted
71
+ * run's text kept in no memory of this process (store-view.ts forgetServed). Counted (servedSince), so no read begun
72
+ * before it keeps what it read. The keys it dropped. */
73
+ export declare function forgetServedAnswers(store: Store, runId: string): string[];
69
74
  /** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
70
75
  * cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
71
76
  * shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
72
77
  * "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
73
78
  * from the journal, settled as the rows were, with no text cap and none
74
79
  * of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
75
- * of it and never cuts. Every other row is as it was. */
76
- export declare function wholeAnswers(store: Store, runId: string, context: Context, rows: TimelineEvent[], options: TimelineOptions, whole: WholeAnswer): Promise<TimelineEvent[]>;
80
+ * of it and never cuts. Every other row is as it was. What it read is kept only while no run's text was forgotten since
81
+ * `since` (servedSince, taken before the read began). */
82
+ export declare function wholeAnswers(store: Store, runId: string, context: Context, rows: TimelineEvent[], options: TimelineOptions, whole: WholeAnswer, since: number): Promise<TimelineEvent[]>;
77
83
  /** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
78
84
  * user entry noted in log order, its origin read by the same matcher. */
79
85
  export declare function runHearing(store: Store, runId: string, context: Context): Promise<Hearing>;
@@ -426,14 +426,31 @@ export const wholeAnswerFor = (values) => ({
426
426
  * entry's, whose words never change. Kept by store, the newest ANSWERS_KEPT of each. */
427
427
  const answersServed = new WeakMap();
428
428
  const ANSWERS_KEPT = 32;
429
+ /** How many times the readers of each store were told to forget a run's text (forgetServedAnswers). A read takes it
430
+ * before it reads anything (servedSince) and keeps what it made only while it is the same, so a read begun before a
431
+ * purge, which may still hold the purged run's text, never puts that text back once the purge dropped it. */
432
+ const forgetsOf = new WeakMap();
433
+ export const servedSince = (store) => forgetsOf.get(store.origin) ?? 0;
434
+ /** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers): a purged or deleted
435
+ * run's text kept in no memory of this process (store-view.ts forgetServed). Counted (servedSince), so no read begun
436
+ * before it keeps what it read. The keys it dropped. */
437
+ export function forgetServedAnswers(store, runId) {
438
+ forgetsOf.set(store.origin, servedSince(store) + 1);
439
+ const kept = answersServed.get(store.origin);
440
+ const dropped = [...(kept?.keys() ?? [])].filter((key) => key.startsWith(`${runId}\0`));
441
+ for (const key of dropped)
442
+ kept.delete(key);
443
+ return dropped;
444
+ }
429
445
  /** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
430
446
  * cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
431
447
  * shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
432
448
  * "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
433
449
  * from the journal, settled as the rows were, with no text cap and none
434
450
  * of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
435
- * of it and never cuts. Every other row is as it was. */
436
- export async function wholeAnswers(store, runId, context, rows, options, whole) {
451
+ * of it and never cuts. Every other row is as it was. What it read is kept only while no run's text was forgotten since
452
+ * `since` (servedSince, taken before the read began). */
453
+ export async function wholeAnswers(store, runId, context, rows, options, whole, since) {
437
454
  // The rows' redactor gives exactly "[redacted]" for a text whose head it read was all held or secret-shaped values: the
438
455
  // rest of the answer is past what it read, so that row is read again too.
439
456
  const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
@@ -461,12 +478,14 @@ export async function wholeAnswers(store, runId, context, rows, options, whole)
461
478
  continue;
462
479
  }
463
480
  served = whole.serve(text);
464
- kept.delete(key);
465
- kept.set(key, served);
466
- for (const oldest of kept.keys()) {
467
- if (kept.size <= ANSWERS_KEPT)
468
- break;
469
- kept.delete(oldest);
481
+ if (servedSince(store) === since) {
482
+ kept.delete(key);
483
+ kept.set(key, served);
484
+ for (const oldest of kept.keys()) {
485
+ if (kept.size <= ANSWERS_KEPT)
486
+ break;
487
+ kept.delete(oldest);
488
+ }
470
489
  }
471
490
  }
472
491
  out.push({ ...row, text: served });
@@ -308,7 +308,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
308
308
  feedback_status: "running" | "ended" | "not_run" | null;
309
309
  source: "feedback" | "eval";
310
310
  graded_at: string;
311
- path: "agent" | "workflow" | "replay" | "handed_back" | "audit";
311
+ path: "agent" | "workflow" | "replay" | "audit" | "handed_back";
312
312
  workflow_digest: string | null;
313
313
  feedback: "correction" | null;
314
314
  run_id: string;
@@ -116,9 +116,12 @@ export async function learningCountsOverStore(store, filter, records) {
116
116
  const out = { runs: 0, merged: 0, dropped: {}, in_progress: 0 };
117
117
  const agentArchived = new Map();
118
118
  const workflow = new Map();
119
- const listed = await store.runs.list(filter.agent !== undefined ? { agentId: filter.agent } : {});
119
+ // Purged runs too: a tombstone keeps how its learning ended (PurgeKept.learning), which these counts read as before.
120
+ const listed = await store.runs.list({ purged: true, ...(filter.agent !== undefined ? { agentId: filter.agent } : {}) });
120
121
  const byAgent = new Map();
121
122
  for (const run of listed) {
123
+ if (run.purgedAt !== null)
124
+ continue;
122
125
  const runs = byAgent.get(run.agentId);
123
126
  if (runs)
124
127
  runs.push(run);
@@ -147,7 +150,7 @@ export async function learningCountsOverStore(store, filter, records) {
147
150
  workflow.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow");
148
151
  if (workflow.get(run.revisionId))
149
152
  continue;
150
- const learning = await runLearningEnd(store, run.id, undefined, await recordsOf(run.agentId));
153
+ const learning = run.purgedAt !== null ? run.metrics?.purged?.learning : await runLearningEnd(store, run.id, undefined, await recordsOf(run.agentId));
151
154
  // A reason this server does not give is not counted.
152
155
  if (!learning || (learning.reason !== null && !LEARNING_REASONS.includes(learning.reason)))
153
156
  continue;
@@ -76,7 +76,9 @@ function joins(store, context) {
76
76
  /** The runs, newest first; `agent`, `revision` and `labels` (every one held) narrow it. Archived runs are listed too (the
77
77
  * server filters them), with the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
78
78
  export async function listRuns(store, filter, context) {
79
+ // Purged runs too: /usage sums their cost from their tombstones, as before their purge.
79
80
  const runs = await store.runs.list({
81
+ purged: true,
80
82
  ...(filter.agent !== undefined ? { agentId: filter.agent } : {}),
81
83
  ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}),
82
84
  ...(filter.labels !== undefined ? { labels: filter.labels } : {}),
@@ -5,7 +5,8 @@ const RUN_STATES = ["running", "completed", "failed", "stopped", "escalated"];
5
5
  const emptyCounts = () => ({ total: 0, running: 0, completed: 0, failed: 0, stopped: 0, escalated: 0 });
6
6
  /** Every agent, by name then id (the old order), with its archive and name. */
7
7
  async function allAgents(store) {
8
- const [live, archived] = await Promise.all([store.agents.list({ archived: false }), store.agents.list({ archived: true })]);
8
+ // A purged agent (an archived one's tombstone) still counts, as its runs' cost does.
9
+ const [live, archived] = await Promise.all([store.agents.list({ archived: false, purged: true }), store.agents.list({ archived: true, purged: true })]);
9
10
  return [...live.map((a) => ({ id: a.id, name: a.name, archived: false })), ...archived.map((a) => ({ id: a.id, name: a.name, archived: true }))].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
10
11
  }
11
12
  /** The store's counts and cost sums (the old AgentStoreReader.stats), from A's run rows and agents: one pass over the
@@ -13,7 +14,8 @@ async function allAgents(store) {
13
14
  export async function stats(store) {
14
15
  const agents = await allAgents(store);
15
16
  const archivedAgent = new Set(agents.filter((a) => a.archived).map((a) => a.id));
16
- const runs = await store.runs.list({});
17
+ // A purged run's tombstone keeps its state and cost: every count and sum reads it as before its purge.
18
+ const runs = await store.runs.list({ purged: true });
17
19
  // Per agent, the runs whose own archive is null (shown) and the count whose own archive is set (hidden).
18
20
  const shown = new Map();
19
21
  const hidden = new Map();
@@ -5,6 +5,7 @@ import { type Pending, type RunMoment, type RunView, type SignInReader, type Sta
5
5
  import { type BookedSpend, type RunCost } from "./runner/metrics.js";
6
6
  import { type EndData } from "./runner/journal-kinds.js";
7
7
  import { type RunReadState, readRun } from "./store-reads/runs.js";
8
+ import { type KeptEnd } from "./runner/feedback-round.js";
8
9
  import type { PendingAsk } from "./browser-person.js";
9
10
  import { type Approvals } from "./approvals.js";
10
11
  import { type KeptListing, type RunListing, type RunRow, type Store } from "./store/store.js";
@@ -38,6 +39,10 @@ export declare const settledStatusOf: (state: RunReadState) => Status | undefine
38
39
  * that withheld the run for a sign-in it could not read back (listingOverStore), and the lister's build that failed
39
40
  * (run-listing.ts). */
40
41
  export declare const LISTING_RETRY_MS = 30000;
42
+ /** Run `runId`'s text dropped from what the readers of `store` last served: its view's slots (its answer's, its input's)
43
+ * and its whole answer rows (store-reads/journal.ts forgetServedAnswers), so a purged or deleted run's text stays in no
44
+ * memory of this process (agent-delete.ts). What it dropped, by slot and key. */
45
+ export declare function forgetServed(store: Store, runId: string): string[];
41
46
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
42
47
  * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
43
48
  * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
@@ -124,6 +129,9 @@ interface StoreRun {
124
129
  readonly costUsd: number;
125
130
  readonly costUpperBound: boolean;
126
131
  };
132
+ /** The run looks back after its job's end (`row` and `runRow` read as that end): nothing of it is settled until the
133
+ * look-back's own end is in (poll_after_ms 1000, the timeline not final). */
134
+ readonly lookingBack?: true;
127
135
  }
128
136
  /** Whether the run's turn stands on a person: a tool call asked for their approval with no answer in its journal (the
129
137
  * view's `approvals`, asksOf), or a browser or desktop hand-over neither answered in its journal nor by a hand-back row.
@@ -139,9 +147,12 @@ export declare function standsOnPerson(approvals: ReadonlyMap<string, {
139
147
  * True when written; false when another write got there first, or when the write failed (said, never thrown: a read
140
148
  * never fails on its heal, and the next read or start sweep writes it again). */
141
149
  export declare function healStoredCost(store: Store, runId: string, heal: NonNullable<StoreRun["heal"]>): Promise<boolean>;
150
+ /** The end run `runId` keeps while it looks back after its job ended, as every reader serves it (lookingBackOf), else
151
+ * undefined: a run that reads ended while it is still learning from that end. */
152
+ export declare function lookingBackEnd(store: Store, runId: string): Promise<KeptEnd | undefined>;
142
153
  /** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
143
154
  * paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
144
- * time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
155
+ * time) and the decisions Parallel charged on its own API (store-reads/decisions.ts chargedByParallel), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
145
156
  * learning's as that turn's model requests are (runCostOf). A part of `usd`, never added to it; 0 with none. Null when
146
157
  * one's charge is unknown (charged an unknown amount, cut, or still out) or counted at its hold; while the run is at work
147
158
  * (not ended, stopped or failed), as its `usd` is the view's snapshot and a paid call booked after it would be read here
@@ -20,14 +20,16 @@ import { learningStartOf, seedFailed } from "./run-launch.js";
20
20
  import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
21
21
  import { reflects } from "./reflect-range.js";
22
22
  import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
23
- import { bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
23
+ import { booksDecisions, decisionsOverStore, parallelChargedDecisions } from "./store-reads/decisions.js";
24
+ import { bookedDecisionsOf, bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
24
25
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
25
26
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
26
27
  import { laidOf, pathViewOf, roundsOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
27
28
  import { inReflect, reflectRanges } from "./runner/end-of-run.js";
28
29
  import { correctionCount } from "./learn/corrections.js";
29
- import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
30
- import { costOfRun, readRun } from "./store-reads/runs.js";
30
+ import { forgetServedAnswers, isCliRecord, servedSince, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
31
+ import { costOfRun, readRun, runReadState } from "./store-reads/runs.js";
32
+ import { feedbackOf, keptEndOf } from "./runner/feedback-round.js";
31
33
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
32
34
  import { Turns } from "./turns.js";
33
35
  import { harnessOfBody } from "./harness.js";
@@ -55,10 +57,11 @@ const iso = (ms) => new Date(ms).toISOString();
55
57
  /** What a view last made of a run's text, by store and slot (a run's answer, or its input): the text it read (`input`),
56
58
  * the digest of the values it was redacted of (`key`) and what that gave (`out`), so a second view of the same text and
57
59
  * values reads nothing again (main's runs.ts servedOnce: a console polls a run's view, and an answer or an input can be
58
- * large). Newest SERVED_KEPT slots of each store. */
60
+ * large). Newest SERVED_KEPT slots of each store. What a read made is kept only while no run's text was forgotten since
61
+ * `since` (servedSince, taken before the read began), so a read a purge overtook never keeps the purged text. */
59
62
  const servedByStore = new WeakMap();
60
63
  const SERVED_KEPT = 64;
61
- function keptOnce(store, slot, input, values, make) {
64
+ function keptOnce(store, slot, input, values, since, make) {
62
65
  let served = servedByStore.get(store.origin);
63
66
  if (!served)
64
67
  servedByStore.set(store.origin, (served = new Map()));
@@ -67,6 +70,8 @@ function keptOnce(store, slot, input, values, make) {
67
70
  if (last && last.key === key && last.input === input)
68
71
  return last.out;
69
72
  const out = make();
73
+ if (servedSince(store) !== since)
74
+ return out;
70
75
  served.delete(slot);
71
76
  served.set(slot, { input, key, out });
72
77
  for (const oldest of served.keys()) {
@@ -76,11 +81,21 @@ function keptOnce(store, slot, input, values, make) {
76
81
  }
77
82
  return out;
78
83
  }
84
+ /** Run `runId`'s text dropped from what the readers of `store` last served: its view's slots (its answer's, its input's)
85
+ * and its whole answer rows (store-reads/journal.ts forgetServedAnswers), so a purged or deleted run's text stays in no
86
+ * memory of this process (agent-delete.ts). What it dropped, by slot and key. */
87
+ export function forgetServed(store, runId) {
88
+ const served = servedByStore.get(store.origin);
89
+ const dropped = [`answer ${runId}`, `input ${runId}`].filter((slot) => served?.has(slot));
90
+ for (const slot of dropped)
91
+ served.delete(slot);
92
+ return [...dropped, ...forgetServedAnswers(store, runId)];
93
+ }
79
94
  /** A run's answer as served: redactedAnswer's, once per answer and held value set. */
80
- const servedOnce = (store, runId, input, values) => keptOnce(store, `answer ${runId}`, input, values, () => redactedAnswer(input, values));
95
+ const servedOnce = (store, runId, input, values, since) => keptOnce(store, `answer ${runId}`, input, values, since, () => redactedAnswer(input, values));
81
96
  /** Whether a run's input is served (store-view's `input`): only when the cut a run's words get (redactedOutput) leaves it
82
97
  * exactly as given, so "Run again" never sends an altered task. Read once per input and held value set. */
83
- const inputWhole = (store, runId, input, values) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, () => isDeepStrictEqual(redactedOutput(input, values), input));
98
+ const inputWhole = (store, runId, input, values, since) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, since, () => isDeepStrictEqual(redactedOutput(input, values), input));
84
99
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
85
100
  * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
86
101
  * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
@@ -152,8 +167,11 @@ export function standsOnPerson(approvals, entries, commands) {
152
167
  * journal, live tick and commands) is made in one snapshot of the store (Store.snapshot), so the view is of one moment: a
153
168
  * runner's commit that lands while it is built is in all of it or in none. What is read through the server's own handles
154
169
  * (the run's cut, which reads the agent's sign-ins, and the learning statuses of its folder) is read outside the snapshot,
155
- * before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. */
170
+ * before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. `since`
171
+ * is what the run's text was forgotten as before anything was read (servedSince): what the read made of that text is
172
+ * kept only while it is the same (keptOnce, wholeAnswers), so a read a purge overtook keeps none of it. */
156
173
  async function storeRunOf(store, runId, deps) {
174
+ const since = servedSince(store);
157
175
  // The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
158
176
  // run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
159
177
  // was handed (rowShown's choke point). The snapshot renders under it, so it is read first, and read again after: the cut
@@ -165,17 +183,17 @@ async function storeRunOf(store, runId, deps) {
165
183
  };
166
184
  if (!(await store.runs.get(runId)))
167
185
  return undefined;
168
- const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut)));
186
+ const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut, since)));
169
187
  // An ended run whose end stored its cost unknown while its booking is priced: its store is healed now, after the
170
188
  // snapshot (which may not write), so every reader of the stored cost (the list, /stats, /usage, the learning bill)
171
189
  // reads the figure this read shows. One conditional write (Runs.healCost); a failure is said and the next read tries again.
172
190
  if (run?.heal)
173
191
  await healStoredCost(store, runId, run.heal);
174
192
  if (!run?.shownEnd || !holdsForOk(run.shownEnd) || !deps.statuses)
175
- return run && { ...run, learningEnd: run.shownEnd };
193
+ return run && { ...run, learningEnd: run.shownEnd, since };
176
194
  // What the learning end held for its owner's OK reads as it stands now on its agent's folder's main (learning.ts
177
195
  // currentLearning); its record stays as the merge wrote it.
178
- return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)) };
196
+ return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)), since };
179
197
  }
180
198
  /** Heals run `runId`'s stored unknown cost to the figure its booking gives (Runs.healCost), at the end it was read at.
181
199
  * True when written; false when another write got there first, or when the write failed (said, never thrown: a read
@@ -189,15 +207,47 @@ export async function healStoredCost(store, runId, heal) {
189
207
  return false;
190
208
  }
191
209
  }
192
- /** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
193
- async function storeRunIn(store, runId, deps, cut) {
210
+ /** A person's message not taken yet: a steer that is no grade's round (feedback-round.ts feedbackOf). */
211
+ const waitingMessage = (command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body) === undefined;
212
+ /** The end run `stored` keeps while it looks back after its job ended (its end-of-run step: a fresh run's, or a grade's
213
+ * feedback round), from its root `entries` and its command rows (`commands`), else undefined. Every reader serves that
214
+ * end: completed (or as its job ended), its answer, its end time, its learning reflecting, while its runner still holds
215
+ * it. A person's message waiting (not taken yet) makes it a run going on again, as a completed run a message opens again
216
+ * reads: its end is the message's turn's to write. */
217
+ async function lookingBackOf(stored, entries, commands) {
218
+ if (stored.state !== "running")
219
+ return undefined;
220
+ const rows = await commands();
221
+ const kept = keptEndOf(entries, rows);
222
+ return kept !== undefined && !rows.some(waitingMessage) ? kept : undefined;
223
+ }
224
+ /** The end run `runId` keeps while it looks back after its job ended, as every reader serves it (lookingBackOf), else
225
+ * undefined: a run that reads ended while it is still learning from that end. */
226
+ export async function lookingBackEnd(store, runId) {
227
+ const stored = await store.runs.get(runId);
228
+ if (stored?.state !== "running")
229
+ return undefined;
230
+ return lookingBackOf(stored, (await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT)).entries, () => store.commands(runId, 0));
231
+ }
232
+ /** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut, begun at `since` (servedSince). */
233
+ async function storeRunIn(store, runId, deps, cut, since) {
194
234
  const context = BACKGROUND_CONTEXT;
195
- const row = await readRun(store, runId, context);
196
- if (!row)
235
+ const read = await readRun(store, runId, context);
236
+ if (!read)
197
237
  return undefined;
198
- const runRow = await store.runs.get(runId);
199
- if (!runRow)
238
+ const stored = await store.runs.get(runId);
239
+ if (!stored)
200
240
  return undefined;
241
+ // The run's root records (the turns it took, its asks, its ends), and its command rows, read once for what needs them:
242
+ // the end it keeps while it looks back, a stop or a cancel asked for, a hand-over's answers, the person's messages not
243
+ // yet taken.
244
+ const records = await journalRecords(store.readJournal(runId), context);
245
+ let commandRows;
246
+ const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
247
+ // A run looking back after its job ended is that end, as every reader serves it (lookingBackOf).
248
+ const lookingBack = await lookingBackOf(stored, records.entries, commandsNow);
249
+ const runRow = lookingBack ? { ...stored, state: lookingBack.state, summary: lookingBack.summary ?? null, outcome: lookingBack.outcome ?? null, endedAt: lookingBack.endedAt } : stored;
250
+ const row = lookingBack ? keptRead(read, runRow) : read;
201
251
  const launch = await launchOf(store, runId);
202
252
  const unshown = cut === "unreadable";
203
253
  const values = cut === "unreadable" ? [] : cut.values;
@@ -214,24 +264,25 @@ async function storeRunIn(store, runId, deps, cut) {
214
264
  // The timeline, then the waiting row a run asking a question shows (withAsks), as the file path's rows carried it, so a
215
265
  // run waiting on a question reads the same status and pending.
216
266
  // Its final answer whole (store-reads/journal.ts wholeAnswers), as main served a run's answer: a row's cut is no answer's.
217
- // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far.
218
- const timelineOptions = { settled: terminal, ended: terminal, redact: (text) => redacted(text, values) };
219
- const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
267
+ // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far. One
268
+ // looking back is still going: its look-back's rows come yet.
269
+ const timelineOptions = { settled: terminal && !lookingBack, ended: terminal && !lookingBack, redact: (text) => redacted(text, values) };
270
+ const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values), since));
220
271
  const revisions = await store.agents.revisions(row.agent);
221
272
  const version = revisions.findIndex((r) => r.id === row.revision) + 1;
222
273
  const ended = await runLearningEnd(store, runId);
223
274
  // Whether a runner holds the run now, and the time of its latest change: the live tick while it runs (store.live, the
224
275
  // runner's own tick), its end once ended, its start before either.
225
276
  const [liveRow] = await store.live.read([runId]);
226
- const live = liveOf(runRow, deps.now?.() ?? Date.now());
277
+ // A run looking back is held by the runner that looks back: its claim is served as such.
278
+ const live = liveOf(stored, deps.now?.() ?? Date.now());
227
279
  const updatedAtMs = liveRow?.updatedAt ?? runRow.endedAt ?? runRow.startedAt;
228
280
  // The turns the run took, rebuilt from the journal the same way the file path's noteTurns fed Turns: the root's records
229
281
  // (a CLI session's own conversation skipped) and the input submissions, with the end-of-run turn's entries left out
230
282
  // (runReflect). progressAt reads the latest tick, so a working run's last_progress_at advances as today.
231
- const records = await journalRecords(store.readJournal(runId), context);
232
283
  const sdkCompletion = records.entries.findLast(entry => entry.kind === "agentrun.sdk.completion")?.data;
233
284
  const sdkSession = records.entries.findLast(entry => entry.kind === "agentrun.sdk.session")?.data;
234
- const sdk = launch?.sdk ? { runtime: launch.sdk.runtime, model: sdkCompletion?.model ?? launch.sdk.model ?? null, session_id: sdkCompletion?.session_id ?? sdkSession?.session_id ?? null, learning_revision: launch.learning?.seed ?? null, usage: sdkCompletion?.usage ?? null } : undefined;
285
+ const sdk = launch?.sdk ? { runtime: launch.sdk.runtime, ...(launch.sdk.runtime === "external" ? { platform: launch.sdk.platform } : {}), model: sdkCompletion?.model ?? launch.sdk.model ?? null, session_id: sdkCompletion?.session_id ?? sdkSession?.session_id ?? null, learning_revision: launch.learning?.seed ?? null, usage: sdkCompletion?.usage ?? null } : undefined;
235
286
  const nativeConfiguration = records.entries.findLast(e => e.kind === "agentrun.native.configuration")?.data;
236
287
  const nativeEvents = records.entries.filter(e => e.kind === "agentrun.native.usage").map(e => e.data);
237
288
  const reflectRange = (await runReflect(store, runId, context));
@@ -250,20 +301,18 @@ async function storeRunIn(store, runId, deps, cut) {
250
301
  // (main's seeded and reflecting).
251
302
  const started = launch ? learningStartOf(launch) : undefined;
252
303
  const under = !ended && started && started.use ? usedOnly(started, terminal, iso(runRow.endedAt ?? runRow.startedAt)) : !ended && started && !seedFailed(started) ? underWay(started, laidOf(records.entries), reflectRange, iso(runRow.startedAt)) : null;
253
- const shownEnd = ended ?? under;
304
+ // A run looking back after its job's end reads reflecting from that end on, a graded one too (its last end's learning
305
+ // is the earlier round's).
306
+ const shownEnd = lookingBack && started && !started.use ? { state: "reflecting", reason: null, detail: said.reflecting, at: iso(lookingBack.endedAt) } : ended ?? under;
254
307
  const turns = new Turns();
255
308
  turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
256
- const working = live && turns.open > 0;
309
+ const working = !lookingBack && live && turns.open > 0;
257
310
  const progress = terminal || row.kind === "workflow" ? undefined : turns.progressAt();
258
311
  const lastProgressAt = progress === undefined ? null : iso(progress);
259
312
  // The tool-call approvals the run waits (or waited) on, from its journal: each call the gate parked for a person, and
260
313
  // the answers given, which the status, pending and moment views read the same as the file path read them from the run's
261
314
  // store entries.
262
315
  const approvals = asksOf(records.entries);
263
- // The run's command rows, read once for what needs them: a stop or a cancel asked for, a hand-over's answers, and the
264
- // person's messages not yet taken.
265
- let commandRows;
266
- const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
267
316
  // A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
268
317
  // stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it. A stop
269
318
  // asked for and not yet taken (stopAsked) is the mark too once nothing works: between the turn's cut and the end that
@@ -362,10 +411,18 @@ async function storeRunIn(store, runId, deps, cut) {
362
411
  const bookedCost = bookedCostOf(row, native !== undefined, records.entries);
363
412
  const endCost = bookedCost?.requests ? bookedCost : undefined;
364
413
  const endSaid = records.entries.findLast((entry) => entry.kind === KINDS.end)?.data?.costUsd;
365
- const endSaidCost = endCost ? endSaid !== undefined : false;
366
- const endUnread = bookedCost !== undefined && !endCost && endSaid === null;
367
- const heal = healOf(endCost, runRow);
368
- return { ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}) };
414
+ // A run looking back has no end of its own stored yet (its job's is kept apart): its cost is its booking so far, by the
415
+ // rule its end will store it by, and nothing is healed.
416
+ const endSaidCost = endCost && !lookingBack ? endSaid !== undefined : false;
417
+ const endUnread = !lookingBack && bookedCost !== undefined && !endCost && endSaid === null;
418
+ const heal = lookingBack ? undefined : healOf(endCost, runRow);
419
+ return { ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
420
+ }
421
+ /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
422
+ * the end a run looking back keeps), its cost as read. */
423
+ function keptRead(read, ended) {
424
+ const { endedAt: _endedAt, summary: _summary, ...rest } = read;
425
+ return { ...rest, state: runReadState(ended, read.kind), ...(ended.endedAt !== null ? { endedAt: iso(ended.endedAt) } : {}), ...(ended.summary !== null ? { summary: ended.summary } : {}) };
369
426
  }
370
427
  /** A run's learning as the view shows it: its end from the store (what it held for the owner's OK as it reads now), in a
371
428
  * person's words cut of the host's secrets now. */
@@ -431,7 +488,7 @@ function costOfView(run) {
431
488
  }
432
489
  /** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
433
490
  * paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
434
- * time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
491
+ * time) and the decisions Parallel charged on its own API (store-reads/decisions.ts chargedByParallel), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
435
492
  * learning's as that turn's model requests are (runCostOf). A part of `usd`, never added to it; 0 with none. Null when
436
493
  * one's charge is unknown (charged an unknown amount, cut, or still out) or counted at its hold; while the run is at work
437
494
  * (not ended, stopped or failed), as its `usd` is the view's snapshot and a paid call booked after it would be read here
@@ -447,7 +504,9 @@ export async function toolsUsdOverStore(store, runId) {
447
504
  return null;
448
505
  const records = await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT);
449
506
  const turns = reflectRanges(records.submissions ?? [], records.entries);
450
- const words = costWordsOf([bookedSpend(records.entries.filter((entry) => !inReflect(turns, Number(entry.id))), "paid")]);
507
+ const entries = records.entries.filter((entry) => !inReflect(turns, Number(entry.id)));
508
+ const parallel = booksDecisions(entries) ? parallelChargedDecisions(await decisionsOverStore(store, runId, BACKGROUND_CONTEXT)) : new Set();
509
+ const words = costWordsOf([bookedSpend(entries, "paid"), ...(parallel.size ? [bookedDecisionsOf(entries, parallel)] : [])]);
451
510
  return words.upper_bound ? null : words.usd;
452
511
  }
453
512
  /** How a run's cost was reached (metrics.ts CostBasis): by how its model requests were priced, as its booking says, while
@@ -532,7 +591,7 @@ async function viewOfRun(store, runId, deps, run, read) {
532
591
  const shownWords = (text) => withoutLoopback(redacted(text, values));
533
592
  // The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
534
593
  // was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
535
- const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values) : text);
594
+ const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values, run.since) : text);
536
595
  const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
537
596
  // A workflow run's output, as its end kept it; an agentic run's, its final answer's structured part when its agent has
538
597
  // an output schema and the answer's last fenced json block meets it (storeRunOf's `structured`), else none. Served as
@@ -576,7 +635,8 @@ async function viewOfRun(store, runId, deps, run, read) {
576
635
  // it holds none of the run's words, so a withheld run says it too.
577
636
  const redactor = redactorOf(values);
578
637
  const pending = !unshown && status === "input_required" && state === "waiting" ? (approvalOf(view, redactor) ?? run.budget ?? browserPending(run.browserAsk, redactor) ?? computerPending(run.computerAsk, redactor) ?? pendingOf(run.rows)) : stoppedTurn(view, { status, state }) ? { kind: "stopped" } : null;
579
- const settled = terminal && ended;
638
+ // A run looking back reads its job's end, and is settled only once its look-back's end is in.
639
+ const settled = terminal && ended && !run.lookingBack;
580
640
  return {
581
641
  ...(run.sdk && !unshown ? { sdk: redactedOutput(run.sdk, values) } : {}),
582
642
  ...(run.native && !unshown ? { native: redactedOutput(run.native, values) } : {}),
@@ -595,7 +655,7 @@ async function viewOfRun(store, runId, deps, run, read) {
595
655
  // The input the run was started with, as its launch keeps it, whole (never the first message the timeline caps): what
596
656
  // "Run again" sends again. Null when the cut a run's words get would change it (inputWhole: a held value, a long run
597
657
  // with no whitespace), for a withheld run, and for one whose launch holds no input object.
598
- input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values) ? launch?.input : null,
658
+ input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values, run.since) ? launch?.input : null,
599
659
  file_ids: [...(launch?.files ?? [])],
600
660
  place: launch?.place ?? { mode: "runner" },
601
661
  // The runner holding the run now, when one does (a running run with a live claim): its id, the claim's count (up one each
@@ -1,5 +1,7 @@
1
1
  import { type Layout, type MailboxAfter, type MailboxFixture, type MailboxRecord } from "./eval-mailbox.js";
2
2
  import { type FeedFixture } from "./eval-feed.js";
3
+ import { type PreviousFixture } from "./eval-previous.js";
4
+ import type { PreviousHandover } from "./trigger-targets.js";
3
5
  import type { MonidFake } from "./runner/monid-run.js";
4
6
  import { type WebFake } from "./web-fake.js";
5
7
  import { type Package } from "./templates.js";
@@ -56,6 +58,11 @@ export type Grader = ({
56
58
  messageId: string;
57
59
  in?: string;
58
60
  notIn: string[];
61
+ } | {
62
+ file: string;
63
+ type: "handed";
64
+ expect: PreviousHandover["kind"];
65
+ dropped?: Record<string, number>;
59
66
  }) & {
60
67
  /** An email case's layouts this grader grades the runs of; absent, every run. */
61
68
  layouts?: Layout[];
@@ -129,6 +136,9 @@ export type EvalCase = {
129
136
  /** The case's fake feed (eval-feed.ts): each run gets fake feeds served from it, read in place of the URLs the
130
137
  * package's feed trigger names, and is started by that trigger as it would be. */
131
138
  feed?: FeedFixture;
139
+ /** The case's previous runs (eval-previous.ts): each run's agent gets them seeded as completed runs of the package's
140
+ * schedule trigger, which then starts the run as it would, handing it the last one's result. */
141
+ previous?: PreviousFixture;
132
142
  };
133
143
  /** Cases that do not check: every problem, each naming its file. */
134
144
  export declare class CaseError extends Error {
@@ -168,6 +178,8 @@ export type RunRecord = {
168
178
  now?: string;
169
179
  /** Its fake mailbox after it, for a case with `email` (eval-mailbox.ts). */
170
180
  mailbox?: MailboxRecord;
181
+ /** What it was handed of its trigger's last result after its message, for a case with `previous` (eval-previous.ts). */
182
+ handed?: PreviousHandover;
171
183
  };
172
184
  export type Verdict = {
173
185
  pass: boolean;
@@ -299,7 +311,8 @@ export type RunMetrics = {
299
311
  };
300
312
  /** `answer`, `calls`, `mcp_calls`, `created_at`, `ended_at` and `metrics`: what the run left, kept in the report so a caller scores the
301
313
  * run itself after the eval's temp server is gone (a hill climb's parser and judge, say). An email case's run carries
302
- * its fake mailbox's `layout` and what it left there (`mailbox_after`). */
314
+ * its fake mailbox's `layout` and what it left there (`mailbox_after`); a previous case's run, what it was handed of its
315
+ * trigger's last result (`handed_previous`). */
303
316
  export type RunResult = {
304
317
  run: number;
305
318
  agent_id: string | null;
@@ -317,6 +330,7 @@ export type RunResult = {
317
330
  metrics?: RunMetrics | null;
318
331
  layout?: Layout;
319
332
  mailbox_after?: MailboxAfter;
333
+ handed_previous?: PreviousHandover;
320
334
  };
321
335
  export type CaseResult = {
322
336
  name: string;