@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51

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 (216) hide show
  1. package/CHANGELOG.md +173 -9
  2. package/README.md +246 -39
  3. package/dist/agent-delete.d.ts +3 -2
  4. package/dist/agent-delete.js +29 -4
  5. package/dist/agents-store.js +7 -3
  6. package/dist/api-only.d.ts +8 -10
  7. package/dist/api-only.js +11 -12
  8. package/dist/capacity.d.ts +50 -0
  9. package/dist/capacity.js +49 -0
  10. package/dist/cli-learning/claude-wire.d.ts +41 -0
  11. package/dist/cli-learning/claude-wire.js +258 -0
  12. package/dist/cli-learning/cli.d.ts +11 -0
  13. package/dist/cli-learning/cli.js +241 -0
  14. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  15. package/dist/cli-learning/codex-worktree.js +119 -0
  16. package/dist/cli-learning/connections.d.ts +62 -0
  17. package/dist/cli-learning/connections.js +87 -0
  18. package/dist/cli-learning/entry.d.ts +1 -0
  19. package/dist/cli-learning/entry.js +4 -0
  20. package/dist/cli-learning/evidence.d.ts +78 -0
  21. package/dist/cli-learning/evidence.js +492 -0
  22. package/dist/cli-learning/hook.d.ts +33 -0
  23. package/dist/cli-learning/hook.js +544 -0
  24. package/dist/cli-learning/install.d.ts +33 -0
  25. package/dist/cli-learning/install.js +335 -0
  26. package/dist/cli-learning/observation-proof.d.ts +14 -0
  27. package/dist/cli-learning/observation-proof.js +10 -0
  28. package/dist/cli-learning/policy.d.ts +48 -0
  29. package/dist/cli-learning/policy.js +363 -0
  30. package/dist/cli-learning/schema.d.ts +16 -0
  31. package/dist/cli-learning/schema.js +27 -0
  32. package/dist/cli-learning/state.d.ts +23 -0
  33. package/dist/cli-learning/state.js +61 -0
  34. package/dist/cli.js +24 -2
  35. package/dist/compute-cost.d.ts +101 -0
  36. package/dist/compute-cost.js +250 -0
  37. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  38. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/email/email-faux.d.ts +3 -1
  41. package/dist/email/email-faux.js +3 -2
  42. package/dist/email/routes.js +22 -12
  43. package/dist/eval-previous.d.ts +52 -0
  44. package/dist/eval-previous.js +164 -0
  45. package/dist/file-types.d.ts +2 -0
  46. package/dist/file-types.js +3 -1
  47. package/dist/harness-install.d.ts +6 -2
  48. package/dist/harness-install.js +40 -8
  49. package/dist/harness.d.ts +1 -1
  50. package/dist/harness.js +3 -2
  51. package/dist/learn/check.d.ts +8 -5
  52. package/dist/learn/check.js +25 -24
  53. package/dist/learn/repick.d.ts +22 -13
  54. package/dist/learn/repick.js +57 -56
  55. package/dist/learn/secrets.js +14 -3
  56. package/dist/learn/workflow-draft.d.ts +4 -0
  57. package/dist/learn/workflow-draft.js +10 -7
  58. package/dist/learned-workflow.js +8 -8
  59. package/dist/learning-setting.js +2 -2
  60. package/dist/learning-words.d.ts +1 -1
  61. package/dist/learning-words.js +1 -1
  62. package/dist/mcp-pin-first.js +2 -1
  63. package/dist/mcp-private-hosts.d.ts +24 -3
  64. package/dist/mcp-private-hosts.js +53 -3
  65. package/dist/model-gateway.d.ts +2 -0
  66. package/dist/model-gateway.js +3 -1
  67. package/dist/native/runtimes.d.ts +2 -0
  68. package/dist/native/runtimes.js +2 -0
  69. package/dist/observation/learning.d.ts +32 -0
  70. package/dist/observation/learning.js +66 -0
  71. package/dist/observation/observer.d.ts +8 -1
  72. package/dist/observation/observer.js +89 -9
  73. package/dist/observation/schema.js +12 -4
  74. package/dist/observation/usage-identity.d.ts +9 -0
  75. package/dist/observation/usage-identity.js +11 -0
  76. package/dist/openapi.js +113 -29
  77. package/dist/paid-calls.d.ts +13 -6
  78. package/dist/paid-calls.js +14 -8
  79. package/dist/run-launch.d.ts +16 -2
  80. package/dist/run-launch.js +6 -1
  81. package/dist/run-timeline-served.js +5 -3
  82. package/dist/run-usage.d.ts +23 -8
  83. package/dist/run-usage.js +100 -18
  84. package/dist/run-view.d.ts +2 -0
  85. package/dist/run-view.js +12 -7
  86. package/dist/runner/adapter-loop.d.ts +4 -0
  87. package/dist/runner/adapter-loop.js +44 -27
  88. package/dist/runner/adapter-run-spec.d.ts +8 -3
  89. package/dist/runner/adapter-run-spec.js +15 -8
  90. package/dist/runner/beside.d.ts +13 -0
  91. package/dist/runner/beside.js +27 -8
  92. package/dist/runner/big-writes.d.ts +33 -0
  93. package/dist/runner/big-writes.js +105 -0
  94. package/dist/runner/cli-run-spec.js +16 -8
  95. package/dist/runner/disk-free.d.ts +44 -0
  96. package/dist/runner/disk-free.js +96 -0
  97. package/dist/runner/feedback-round.d.ts +12 -8
  98. package/dist/runner/feedback-round.js +16 -30
  99. package/dist/runner/harness-loops.js +3 -1
  100. package/dist/runner/held.d.ts +4 -1
  101. package/dist/runner/journal-kinds.d.ts +1 -1
  102. package/dist/runner/learning-end.js +13 -4
  103. package/dist/runner/main.d.ts +17 -6
  104. package/dist/runner/main.js +187 -45
  105. package/dist/runner/metrics.d.ts +4 -0
  106. package/dist/runner/metrics.js +9 -0
  107. package/dist/runner/presence.d.ts +11 -2
  108. package/dist/runner/presence.js +31 -3
  109. package/dist/runner/run-child-host.d.ts +27 -17
  110. package/dist/runner/run-child-host.js +70 -116
  111. package/dist/runner/run-child.js +3 -0
  112. package/dist/runner/run-errors.js +2 -0
  113. package/dist/runner/runner-check.d.ts +51 -0
  114. package/dist/runner/runner-check.js +206 -0
  115. package/dist/runner/runner-metrics.d.ts +19 -0
  116. package/dist/runner/runner-metrics.js +49 -0
  117. package/dist/runner/runner.d.ts +37 -0
  118. package/dist/runner/runner.js +43 -3
  119. package/dist/runner/save-slots.d.ts +9 -0
  120. package/dist/runner/save-slots.js +91 -0
  121. package/dist/runner/sdk-loop.js +34 -22
  122. package/dist/runs-over-store.d.ts +8 -1
  123. package/dist/runs-over-store.js +57 -9
  124. package/dist/sdk/runs.d.ts +25 -6
  125. package/dist/sdk/runs.js +107 -35
  126. package/dist/sdk/runtimes.d.ts +19 -0
  127. package/dist/sdk/runtimes.js +23 -0
  128. package/dist/sdk/schema.d.ts +14 -8
  129. package/dist/sdk/schema.js +18 -6
  130. package/dist/server.d.ts +7 -0
  131. package/dist/server.js +151 -28
  132. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  133. package/dist/start-switches.js +2 -0
  134. package/dist/stats.d.ts +4 -0
  135. package/dist/stats.js +1 -1
  136. package/dist/store/agent-body.d.ts +13 -2
  137. package/dist/store/agent-body.js +19 -4
  138. package/dist/store/dialect.d.ts +2 -0
  139. package/dist/store/dialect.js +1 -0
  140. package/dist/store/index.d.ts +3 -3
  141. package/dist/store/index.js +2 -2
  142. package/dist/store/postgres/connection.d.ts +5 -2
  143. package/dist/store/postgres/connection.js +19 -7
  144. package/dist/store/postgres/dialect.js +1 -0
  145. package/dist/store/postgres/migrate.d.ts +30 -0
  146. package/dist/store/postgres/migrate.js +72 -5
  147. package/dist/store/postgres/migration-lint.d.ts +8 -0
  148. package/dist/store/postgres/migration-lint.js +119 -0
  149. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  150. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  151. package/dist/store/postgres/store.d.ts +8 -3
  152. package/dist/store/postgres/store.js +31 -11
  153. package/dist/store/schema.d.ts +26 -4
  154. package/dist/store/schema.js +45 -4
  155. package/dist/store/sqlite/connection.d.ts +3 -3
  156. package/dist/store/sqlite/connection.js +3 -3
  157. package/dist/store/sqlite/run-launch.d.ts +9 -1
  158. package/dist/store/sqlite/run-launch.js +44 -0
  159. package/dist/store/sqlite/store.d.ts +19 -4
  160. package/dist/store/sqlite/store.js +180 -93
  161. package/dist/store/store-schema.d.ts +34 -0
  162. package/dist/store/store-schema.js +125 -0
  163. package/dist/store/store.d.ts +61 -2
  164. package/dist/store/store.js +13 -0
  165. package/dist/store-reads/analytics.d.ts +3 -2
  166. package/dist/store-reads/analytics.js +20 -8
  167. package/dist/store-reads/cap.d.ts +9 -5
  168. package/dist/store-reads/cap.js +28 -2
  169. package/dist/store-reads/decisions.d.ts +21 -0
  170. package/dist/store-reads/decisions.js +22 -0
  171. package/dist/store-reads/journal.d.ts +8 -2
  172. package/dist/store-reads/journal.js +27 -8
  173. package/dist/store-view.d.ts +9 -4
  174. package/dist/store-view.js +48 -25
  175. package/dist/template-eval.d.ts +15 -1
  176. package/dist/template-eval.js +92 -13
  177. package/dist/templates.d.ts +4 -3
  178. package/dist/templates.js +4 -3
  179. package/dist/timeline/labels.js +17 -0
  180. package/dist/tool-gate.d.ts +4 -2
  181. package/dist/tool-list.js +1 -0
  182. package/dist/tools.d.ts +6 -2
  183. package/dist/tools.js +13 -1
  184. package/dist/trigger-targets.d.ts +21 -5
  185. package/dist/trigger-targets.js +13 -10
  186. package/dist/unified-usage.d.ts +24 -0
  187. package/dist/unified-usage.js +400 -0
  188. package/dist/uploads-archil.d.ts +100 -0
  189. package/dist/uploads-archil.js +430 -0
  190. package/dist/uploads.d.ts +55 -1
  191. package/dist/uploads.js +185 -98
  192. package/dist/validate.js +1 -1
  193. package/dist/web-fake.d.ts +25 -0
  194. package/dist/web-fake.js +38 -1
  195. package/dist/web-save.d.ts +75 -0
  196. package/dist/web-save.js +235 -0
  197. package/dist/workspace/archil-claim.d.ts +5 -2
  198. package/dist/workspace/archil-claim.js +5 -2
  199. package/dist/workspace/archil-disk.d.ts +11 -1
  200. package/dist/workspace/archil-disk.js +43 -10
  201. package/dist/workspace/archil.d.ts +3 -0
  202. package/dist/workspace/archil.js +102 -16
  203. package/dist/workspace/computer-for-claim.d.ts +14 -0
  204. package/dist/workspace/computer-for-claim.js +46 -7
  205. package/dist/workspace/computer-intervals.d.ts +9 -3
  206. package/dist/workspace/computer-intervals.js +17 -8
  207. package/dist/workspace/pieced.d.ts +14 -0
  208. package/dist/workspace/pieced.js +23 -0
  209. package/dist/workspace/run-disk.js +32 -12
  210. package/dist/workspace/run-workspace.d.ts +1 -1
  211. package/dist/workspace/run-workspace.js +11 -6
  212. package/package.json +10 -10
  213. package/skills/agentrun-serve/SKILL.md +52 -7
  214. package/templates/README.md +36 -7
  215. package/dist/console/assets/index-Bzn4eUYF.js +0 -715
  216. package/dist/console/assets/index-CR2ZGei1.css +0 -1
@@ -1,3 +1,4 @@
1
+ import { cliPolicyOf } from "./sdk/runs.js";
1
2
  // A run's served view, built from the one store (design 2.1): the same object GET /runs/{id} answered from the per-run
2
3
  // files, now composed from the store's row (store-reads/runs.ts), its journal (store-reads/journal.ts) and its learning end
3
4
  // (store-reads/learning.ts), fed through the run view's pure functions (run-view.ts) so the figures and words a person or a
@@ -20,13 +21,14 @@ import { learningStartOf, seedFailed } from "./run-launch.js";
20
21
  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
22
  import { reflects } from "./reflect-range.js";
22
23
  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";
24
+ import { booksDecisions, decisionsOverStore, parallelChargedDecisions } from "./store-reads/decisions.js";
25
+ import { bookedDecisionsOf, bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
24
26
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
25
27
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
26
28
  import { laidOf, pathViewOf, roundsOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
27
29
  import { inReflect, reflectRanges } from "./runner/end-of-run.js";
28
30
  import { correctionCount } from "./learn/corrections.js";
29
- import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
31
+ import { forgetServedAnswers, isCliRecord, servedSince, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
30
32
  import { costOfRun, readRun, runReadState } from "./store-reads/runs.js";
31
33
  import { feedbackOf, keptEndOf } from "./runner/feedback-round.js";
32
34
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
@@ -56,10 +58,11 @@ const iso = (ms) => new Date(ms).toISOString();
56
58
  /** 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`),
57
59
  * the digest of the values it was redacted of (`key`) and what that gave (`out`), so a second view of the same text and
58
60
  * values reads nothing again (main's runs.ts servedOnce: a console polls a run's view, and an answer or an input can be
59
- * large). Newest SERVED_KEPT slots of each store. */
61
+ * large). Newest SERVED_KEPT slots of each store. What a read made is kept only while no run's text was forgotten since
62
+ * `since` (servedSince, taken before the read began), so a read a purge overtook never keeps the purged text. */
60
63
  const servedByStore = new WeakMap();
61
64
  const SERVED_KEPT = 64;
62
- function keptOnce(store, slot, input, values, make) {
65
+ function keptOnce(store, slot, input, values, since, make) {
63
66
  let served = servedByStore.get(store.origin);
64
67
  if (!served)
65
68
  servedByStore.set(store.origin, (served = new Map()));
@@ -68,6 +71,8 @@ function keptOnce(store, slot, input, values, make) {
68
71
  if (last && last.key === key && last.input === input)
69
72
  return last.out;
70
73
  const out = make();
74
+ if (servedSince(store) !== since)
75
+ return out;
71
76
  served.delete(slot);
72
77
  served.set(slot, { input, key, out });
73
78
  for (const oldest of served.keys()) {
@@ -77,11 +82,21 @@ function keptOnce(store, slot, input, values, make) {
77
82
  }
78
83
  return out;
79
84
  }
85
+ /** Run `runId`'s text dropped from what the readers of `store` last served: its view's slots (its answer's, its input's)
86
+ * and its whole answer rows (store-reads/journal.ts forgetServedAnswers), so a purged or deleted run's text stays in no
87
+ * memory of this process (agent-delete.ts). What it dropped, by slot and key. */
88
+ export function forgetServed(store, runId) {
89
+ const served = servedByStore.get(store.origin);
90
+ const dropped = [`answer ${runId}`, `input ${runId}`].filter((slot) => served?.has(slot));
91
+ for (const slot of dropped)
92
+ served.delete(slot);
93
+ return [...dropped, ...forgetServedAnswers(store, runId)];
94
+ }
80
95
  /** A run's answer as served: redactedAnswer's, once per answer and held value set. */
81
- const servedOnce = (store, runId, input, values) => keptOnce(store, `answer ${runId}`, input, values, () => redactedAnswer(input, values));
96
+ const servedOnce = (store, runId, input, values, since) => keptOnce(store, `answer ${runId}`, input, values, since, () => redactedAnswer(input, values));
82
97
  /** Whether a run's input is served (store-view's `input`): only when the cut a run's words get (redactedOutput) leaves it
83
98
  * exactly as given, so "Run again" never sends an altered task. Read once per input and held value set. */
84
- const inputWhole = (store, runId, input, values) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, () => isDeepStrictEqual(redactedOutput(input, values), input));
99
+ const inputWhole = (store, runId, input, values, since) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, since, () => isDeepStrictEqual(redactedOutput(input, values), input));
85
100
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
86
101
  * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
87
102
  * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
@@ -153,8 +168,11 @@ export function standsOnPerson(approvals, entries, commands) {
153
168
  * journal, live tick and commands) is made in one snapshot of the store (Store.snapshot), so the view is of one moment: a
154
169
  * 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
155
170
  * (the run's cut, which reads the agent's sign-ins, and the learning statuses of its folder) is read outside the snapshot,
156
- * before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. */
171
+ * before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. `since`
172
+ * is what the run's text was forgotten as before anything was read (servedSince): what the read made of that text is
173
+ * kept only while it is the same (keptOnce, wholeAnswers), so a read a purge overtook keeps none of it. */
157
174
  async function storeRunOf(store, runId, deps) {
175
+ const since = servedSince(store);
158
176
  // The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
159
177
  // run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
160
178
  // was handed (rowShown's choke point). The snapshot renders under it, so it is read first, and read again after: the cut
@@ -166,17 +184,17 @@ async function storeRunOf(store, runId, deps) {
166
184
  };
167
185
  if (!(await store.runs.get(runId)))
168
186
  return undefined;
169
- const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut)));
187
+ const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut, since)));
170
188
  // An ended run whose end stored its cost unknown while its booking is priced: its store is healed now, after the
171
189
  // snapshot (which may not write), so every reader of the stored cost (the list, /stats, /usage, the learning bill)
172
190
  // reads the figure this read shows. One conditional write (Runs.healCost); a failure is said and the next read tries again.
173
191
  if (run?.heal)
174
192
  await healStoredCost(store, runId, run.heal);
175
193
  if (!run?.shownEnd || !holdsForOk(run.shownEnd) || !deps.statuses)
176
- return run && { ...run, learningEnd: run.shownEnd };
194
+ return run && { ...run, learningEnd: run.shownEnd, since };
177
195
  // What the learning end held for its owner's OK reads as it stands now on its agent's folder's main (learning.ts
178
196
  // currentLearning); its record stays as the merge wrote it.
179
- return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)) };
197
+ return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)), since };
180
198
  }
181
199
  /** Heals run `runId`'s stored unknown cost to the figure its booking gives (Runs.healCost), at the end it was read at.
182
200
  * True when written; false when another write got there first, or when the write failed (said, never thrown: a read
@@ -204,16 +222,15 @@ async function lookingBackOf(stored, entries, commands) {
204
222
  const kept = keptEndOf(entries, rows);
205
223
  return kept !== undefined && !rows.some(waitingMessage) ? kept : undefined;
206
224
  }
207
- /** The end run `runId` keeps while it looks back after its job ended, as every reader serves it (lookingBackOf), else
208
- * undefined: a run that reads ended while it is still learning from that end. */
209
- export async function lookingBackEnd(store, runId) {
210
- const stored = await store.runs.get(runId);
211
- if (stored?.state !== "running")
225
+ /** The end run `stored` (its row as the caller read it) keeps while it looks back after its job ended, as every reader
226
+ * serves it (lookingBackOf), else undefined: a run that reads ended while it is still learning from that end. */
227
+ export async function lookingBackEnd(store, stored) {
228
+ if (stored.state !== "running")
212
229
  return undefined;
213
- return lookingBackOf(stored, (await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT)).entries, () => store.commands(runId, 0));
230
+ return lookingBackOf(stored, (await journalRecords(store.readJournal(stored.id), BACKGROUND_CONTEXT)).entries, () => store.commands(stored.id, 0));
214
231
  }
215
- /** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
216
- async function storeRunIn(store, runId, deps, cut) {
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) {
217
234
  const context = BACKGROUND_CONTEXT;
218
235
  const read = await readRun(store, runId, context);
219
236
  if (!read)
@@ -250,7 +267,7 @@ async function storeRunIn(store, runId, deps, cut) {
250
267
  // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far. One
251
268
  // looking back is still going: its look-back's rows come yet.
252
269
  const timelineOptions = { settled: terminal && !lookingBack, ended: terminal && !lookingBack, redact: (text) => redacted(text, values) };
253
- const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
270
+ const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values), since));
254
271
  const revisions = await store.agents.revisions(row.agent);
255
272
  const version = revisions.findIndex((r) => r.id === row.revision) + 1;
256
273
  const ended = await runLearningEnd(store, runId);
@@ -265,7 +282,9 @@ async function storeRunIn(store, runId, deps, cut) {
265
282
  // (runReflect). progressAt reads the latest tick, so a working run's last_progress_at advances as today.
266
283
  const sdkCompletion = records.entries.findLast(entry => entry.kind === "agentrun.sdk.completion")?.data;
267
284
  const sdkSession = records.entries.findLast(entry => entry.kind === "agentrun.sdk.session")?.data;
268
- 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;
286
+ const cliCompletion = records.entries.findLast(entry => entry.kind === "agentrun.cli.completion")?.data;
287
+ const cli_learning = launch?.cli_learning ? { runtime: launch.cli_learning.runtime, session_id: launch.cli_learning.session_id, turn_id: launch.cli_learning.turn_id, model: cliCompletion?.model ?? launch.cli_learning.model ?? null, learning_revision: launch.learning?.seed ?? null, seed_observed: cliCompletion?.seed_observed ?? false, policy_complete: cliPolicyOf(launch, cliCompletion)?.complete ?? false, evidence_complete: cliCompletion?.evidence_complete ?? false, usage: cliCompletion?.usage ?? null } : undefined;
269
288
  const nativeConfiguration = records.entries.findLast(e => e.kind === "agentrun.native.configuration")?.data;
270
289
  const nativeEvents = records.entries.filter(e => e.kind === "agentrun.native.usage").map(e => e.data);
271
290
  const reflectRange = (await runReflect(store, runId, context));
@@ -399,7 +418,7 @@ async function storeRunIn(store, runId, deps, cut) {
399
418
  const endSaidCost = endCost && !lookingBack ? endSaid !== undefined : false;
400
419
  const endUnread = !lookingBack && bookedCost !== undefined && !endCost && endSaid === null;
401
420
  const heal = lookingBack ? undefined : healOf(endCost, runRow);
402
- 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 } : {}) };
421
+ return { ...(cli_learning ? { cli_learning } : {}), ...(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 } : {}) };
403
422
  }
404
423
  /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
405
424
  * the end a run looking back keeps), its cost as read. */
@@ -471,7 +490,7 @@ function costOfView(run) {
471
490
  }
472
491
  /** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
473
492
  * paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
474
- * time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
493
+ * 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
475
494
  * learning's as that turn's model requests are (runCostOf). A part of `usd`, never added to it; 0 with none. Null when
476
495
  * one's charge is unknown (charged an unknown amount, cut, or still out) or counted at its hold; while the run is at work
477
496
  * (not ended, stopped or failed), as its `usd` is the view's snapshot and a paid call booked after it would be read here
@@ -487,7 +506,9 @@ export async function toolsUsdOverStore(store, runId) {
487
506
  return null;
488
507
  const records = await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT);
489
508
  const turns = reflectRanges(records.submissions ?? [], records.entries);
490
- const words = costWordsOf([bookedSpend(records.entries.filter((entry) => !inReflect(turns, Number(entry.id))), "paid")]);
509
+ const entries = records.entries.filter((entry) => !inReflect(turns, Number(entry.id)));
510
+ const parallel = booksDecisions(entries) ? parallelChargedDecisions(await decisionsOverStore(store, runId, BACKGROUND_CONTEXT)) : new Set();
511
+ const words = costWordsOf([bookedSpend(entries, "paid"), ...(parallel.size ? [bookedDecisionsOf(entries, parallel)] : [])]);
491
512
  return words.upper_bound ? null : words.usd;
492
513
  }
493
514
  /** How a run's cost was reached (metrics.ts CostBasis): by how its model requests were priced, as its booking says, while
@@ -572,7 +593,7 @@ async function viewOfRun(store, runId, deps, run, read) {
572
593
  const shownWords = (text) => withoutLoopback(redacted(text, values));
573
594
  // The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
574
595
  // was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
575
- const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values) : text);
596
+ const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values, run.since) : text);
576
597
  const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
577
598
  // A workflow run's output, as its end kept it; an agentic run's, its final answer's structured part when its agent has
578
599
  // an output schema and the answer's last fenced json block meets it (storeRunOf's `structured`), else none. Served as
@@ -619,6 +640,7 @@ async function viewOfRun(store, runId, deps, run, read) {
619
640
  // A run looking back reads its job's end, and is settled only once its look-back's end is in.
620
641
  const settled = terminal && ended && !run.lookingBack;
621
642
  return {
643
+ ...(run.cli_learning && !unshown ? { cli_learning: redactedOutput(run.cli_learning, values) } : {}),
622
644
  ...(run.sdk && !unshown ? { sdk: redactedOutput(run.sdk, values) } : {}),
623
645
  ...(run.native && !unshown ? { native: redactedOutput(run.native, values) } : {}),
624
646
  run_id: row.id,
@@ -636,7 +658,7 @@ async function viewOfRun(store, runId, deps, run, read) {
636
658
  // The input the run was started with, as its launch keeps it, whole (never the first message the timeline caps): what
637
659
  // "Run again" sends again. Null when the cut a run's words get would change it (inputWhole: a held value, a long run
638
660
  // with no whitespace), for a withheld run, and for one whose launch holds no input object.
639
- input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values) ? launch?.input : null,
661
+ input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values, run.since) ? launch?.input : null,
640
662
  file_ids: [...(launch?.files ?? [])],
641
663
  place: launch?.place ?? { mode: "runner" },
642
664
  // 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
@@ -686,6 +708,7 @@ export function summaryOfView(view) {
686
708
  const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels, learning } = view;
687
709
  return {
688
710
  run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title,
711
+ ...(view.cli_learning ? { cli_learning: view.cli_learning } : {}),
689
712
  ...(view.sdk ? { sdk: view.sdk } : {}),
690
713
  ...(view.native ? { native: view.native } : {}),
691
714
  ...(effort ? { effort } : {}),
@@ -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;
@@ -23,6 +23,7 @@ import { shownUrl } from "./mcp-probe.js";
23
23
  import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, monidNameOf, parseToolName } from "./tool-names.js";
24
24
  import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailboxVerdict, seed, seededFaux, snapshot } from "./eval-mailbox.js";
25
25
  import { caseFeeds, feedFixtureOf } from "./eval-feed.js";
26
+ import { HANDED_KINDS, handedPrevious, handedVerdict, previousFixtureOf, seedPrevious } from "./eval-previous.js";
26
27
  import { EMAIL_TOOLS } from "./email/names.js";
27
28
  import { CALENDAR_EVENTS } from "./calendar/names.js";
28
29
  import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
@@ -31,6 +32,7 @@ import { webShownOf } from "./timeline/index.js";
31
32
  import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
32
33
  import { webFixtureOf } from "./web-fake.js";
33
34
  import { WEB_FETCH_TOOL } from "./web-fetch.js";
35
+ import { WEB_SAVE_TOOL } from "./web-save.js";
34
36
  import { WEB_SEARCH_TOOL } from "./web-search.js";
35
37
  import { dayIn, serverZone } from "./environment.js";
36
38
  import { instantOf } from "./trigger-adapter.js";
@@ -65,13 +67,14 @@ export const EVAL_HARNESSES = "agentrun-eval-harnesses";
65
67
  export const ON_DATA_WITH_SERVER = "--on-data is the data folder of the eval's own server, and --server names another server: give one of them";
66
68
  const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
67
69
  const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
68
- const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed"];
70
+ const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed", "previous"];
69
71
  const GRADER_FIELDS = {
70
72
  llm: ["type", "target"],
71
73
  regex: ["type", "pattern", "flags", "expect", "target"],
72
74
  tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "args"],
73
75
  file_exists: ["type", "path"],
74
76
  mailbox: ["type", "message_id", "in", "not_in"],
77
+ handed: ["type", "expect", "dropped"],
75
78
  };
76
79
  /** A target: a field of the answer's JSON, dotted for a nested one. */
77
80
  const TARGET = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$/;
@@ -81,7 +84,7 @@ const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule each fake MCP server li
81
84
  /** A host name on this machine: a case with fake MCP servers needs a server here, which reaches them on loopback. */
82
85
  const LOOPBACK_HOST = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule a server on this machine reaches the fakes
83
86
  /** A case's fields that the eval's own runner alone binds (EvalFakes), each with what it does: a named server refuses them. */
84
- const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["calendar", "calendar fakes the server's calendar"], ["feed", "feed fakes the package's feeds"]];
87
+ const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["calendar", "calendar fakes the server's calendar"], ["feed", "feed fakes the package's feeds"], ["previous", "previous seeds the case's earlier runs in the server's store"]];
85
88
  /** A case's run input: its prompt's body as content (none when empty), then its typed fields. */
86
89
  export const runInput = (content, fields) => ({ ...(content ? { content } : {}), ...fields });
87
90
  /** Cases that do not check: every problem, each naming its file. */
@@ -267,6 +270,18 @@ function graderOfType(p, file, text, bad) {
267
270
  return bad(`${file}: a mailbox grader says where the message is (in) or is not (not_in)`), undefined;
268
271
  return { file, type, messageId: data.message_id, ...(typeof data.in === "string" ? { in: data.in } : {}), notIn: notIn };
269
272
  }
273
+ case "handed": {
274
+ // What a previous case's run was handed after its message (eval-previous.ts handedPrevious): its kind, and for carried
275
+ // fields how many first entries each carried array gave up.
276
+ if (!HANDED_KINDS.includes(data.expect))
277
+ return bad(`${file}: expect is ${HANDED_KINDS.slice(0, -1).join(", ")} or ${HANDED_KINDS.at(-1)}`), undefined;
278
+ const dropped = data.dropped;
279
+ if (dropped !== undefined && !(isObject(dropped) && Object.values(dropped).every((n) => Number.isSafeInteger(n) && n >= 0)))
280
+ return bad(`${file}: dropped is a mapping of a carried array's field to how many of its first entries were dropped, 0 or more`), undefined;
281
+ if (dropped !== undefined && data.expect !== "carried")
282
+ return bad(`${file}: dropped counts a carried array's entries, and expect is ${String(data.expect)}, not carried`), undefined;
283
+ return { file, type, expect: data.expect, ...(isObject(dropped) ? { dropped: dropped } : {}) };
284
+ }
270
285
  }
271
286
  return undefined;
272
287
  }
@@ -306,8 +321,8 @@ export function readCases(dir, names) {
306
321
  const c = typeof spec === "string" ? (bad(`${at}/case.yaml: ${spec}`), {}) : isObject(spec) ? spec : (bad(`${at}/case.yaml: is not a mapping`), {});
307
322
  for (const field of unknown(c, CASE_FIELDS))
308
323
  bad(`${at}/case.yaml: no field ${field}: its fields are ${CASE_FIELDS.join(", ")}`);
309
- // An email case's run is on its trigger's input, and its prompt gives none (`email` below holds it to that).
310
- if (c.email === undefined && c.feed === undefined)
324
+ // An email, feed or previous case's run is on its trigger's input, and its prompt gives none (each holds it to that).
325
+ if (c.email === undefined && c.feed === undefined && c.previous === undefined)
311
326
  for (const issue of inputIssues(runInput(body, fields), inputSchemaOf(pkg.inputSchema)))
312
327
  bad(`${at}/prompt.md: ${issue.message}`);
313
328
  if (c.parameters !== undefined && !isObject(c.parameters))
@@ -358,8 +373,8 @@ export function readCases(dir, names) {
358
373
  if (c.web !== undefined) {
359
374
  const path = c.web === "unavailable" ? undefined : inside(root, c.web, "file");
360
375
  // Only a package that names a web tool has one: one that names no tools gets its computer's shell tools, or none.
361
- if (!pkg.tools?.includes(WEB_SEARCH_TOOL) && !pkg.tools?.includes(WEB_FETCH_TOOL))
362
- bad(`${at}/case.yaml: web fakes web_search and web_fetch, and the package's tools name neither`);
376
+ if (![WEB_SEARCH_TOOL, WEB_FETCH_TOOL, WEB_SAVE_TOOL].some((tool) => pkg.tools?.includes(tool)))
377
+ bad(`${at}/case.yaml: web fakes web_search, web_fetch and web_save, and the package's tools name none of them`);
363
378
  else if (c.web === "unavailable")
364
379
  web = "unavailable";
365
380
  else if (!path)
@@ -471,6 +486,39 @@ export function readCases(dir, names) {
471
486
  if (body || fields || f.max_cost_usd !== undefined)
472
487
  bad(`${at}/prompt.md: a feed case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
473
488
  }
489
+ // The case's previous runs: its fixture, and the package's schedule trigger its runs start from (eval-previous.ts).
490
+ let previous;
491
+ if (c.previous !== undefined) {
492
+ const path = inside(root, c.previous, "file");
493
+ let parsed;
494
+ if (c.email !== undefined || c.feed !== undefined)
495
+ bad(`${at}/case.yaml: a previous case's run is started by the package's schedule trigger: previous goes with neither email nor feed`);
496
+ if (!path)
497
+ bad(`${at}/case.yaml: previous is a previous-runs fixture file in the case (not ${JSON.stringify(c.previous)})`);
498
+ else {
499
+ try {
500
+ parsed = JSON.parse(readFileSync(join(root, path), "utf8"));
501
+ }
502
+ catch (error) {
503
+ bad(`${at}/${path}: is not JSON (${error.message})`);
504
+ }
505
+ }
506
+ const fixture = parsed === undefined ? undefined : previousFixtureOf(parsed, `${at}/${path}`, pkg.outputSchema, bad);
507
+ const kindOf = (t) => (isObject(t.source) ? t.source.kind : undefined);
508
+ const named = fixture?.trigger === undefined ? undefined : pkg.triggers.find((t) => t.name === fixture.trigger);
509
+ const starts = named ? [named] : pkg.triggers.filter((t) => kindOf(t) === "schedule");
510
+ if (!fixture)
511
+ undefined;
512
+ else if (fixture.trigger !== undefined && !named)
513
+ bad(`${at}/${path}: trigger ${fixture.trigger} is not one of the package's triggers (${pkg.triggers.map((t) => String(t.name)).join(", ") || "none"})`);
514
+ else if (starts.length !== 1 || kindOf(starts[0]) !== "schedule")
515
+ bad(`${at}/${path}: a previous case starts its run through the package's schedule trigger, and ${named ? `${fixture.trigger} is a ${String(kindOf(named))} trigger` : starts.length ? `the package has ${starts.length}: name one with trigger` : "the package has none"}`);
516
+ else
517
+ previous = { ...fixture, trigger: String(starts[0].name) };
518
+ // Its run is the trigger's, on the trigger's input and cap: the prompt gives neither.
519
+ if (body || fields || f.max_cost_usd !== undefined)
520
+ bad(`${at}/prompt.md: a previous case's run is started by the package's schedule trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
521
+ }
474
522
  let learning;
475
523
  if (c.learning !== undefined) {
476
524
  const file = inside(root, c.learning, "file");
@@ -493,6 +541,8 @@ export function readCases(dir, names) {
493
541
  const unrun = grader?.layouts?.filter((layout) => email && !email.layouts.includes(layout)) ?? [];
494
542
  if (grader?.type === "mailbox" && c.email === undefined)
495
543
  bad(`${at}/graders/${entry.name}: a mailbox grader reads the case's fake mailbox, and the case has no email`);
544
+ else if (grader?.type === "handed" && c.previous === undefined)
545
+ bad(`${at}/graders/${entry.name}: a handed grader reads what a previous case's run was handed, and the case has no previous`);
496
546
  else if (grader?.layouts && c.email === undefined)
497
547
  bad(`${at}/graders/${entry.name}: layouts grades the runs of an email case's layouts, and the case has no email`);
498
548
  else if (unrun.length)
@@ -505,7 +555,7 @@ export function readCases(dir, names) {
505
555
  cases.push({
506
556
  name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
507
557
  ...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
508
- parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), ...(learning !== undefined ? { learning } : {}), graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}),
558
+ parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), ...(learning !== undefined ? { learning } : {}), graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}), ...(previous ? { previous } : {}),
509
559
  });
510
560
  }
511
561
  if (problems.length)
@@ -642,6 +692,8 @@ export function gradeDeterministic(grader, run, faked) {
642
692
  }
643
693
  case "mailbox":
644
694
  return run.mailbox ? mailboxVerdict(run.mailbox, grader.messageId, grader.in, grader.notIn) : { pass: false, reason: "the run has no fake mailbox to read" };
695
+ case "handed":
696
+ return handedVerdict(run.handed, grader.expect, grader.dropped);
645
697
  }
646
698
  }
647
699
  /** The output check of a completed run of a package that declares `output`, beside its case's graders: the server's own
@@ -1001,7 +1053,7 @@ export async function evalTemplate(options) {
1001
1053
  throw new CaseError(options.dir, refused);
1002
1054
  // Each run's fakes, by the agent the eval made for it (runOnce), which the runner beside the server reads at the claim.
1003
1055
  const fakes = new Map();
1004
- const clock = !options.server && cases.some((one) => one.email || one.feed) ? evalClock() : undefined;
1056
+ const clock = !options.server && cases.some((one) => one.email || one.feed || one.previous) ? evalClock() : undefined;
1005
1057
  // Where the eval's own server reads each feed: the running feed case's fakes (feedRun). A feed no case routes (a feed
1006
1058
  // trigger of the package's that the eval deletes once the apply made it, read at its creation) is served nowhere: its
1007
1059
  // read is unreachable at once, never sent, so no eval reads a real feed.
@@ -1080,7 +1132,8 @@ export async function evalTemplate(options) {
1080
1132
  }
1081
1133
  // On the owner's folder, an email case's fake mailbox would replace the account its server keeps (one account, saved
1082
1134
  // and removed per run): refused before anything runs, the account as it was.
1083
- if (clock && options.data !== undefined) {
1135
+ // Only an email case saves a mailbox: a previous or feed case on the clock leaves the account alone.
1136
+ if (cases.some((one) => one.email) && options.data !== undefined) {
1084
1137
  const kept = await api("GET", "/settings/email", undefined, owner).catch(() => undefined);
1085
1138
  const address = kept?.status === 200 && isObject(kept.body) ? kept.body.address : undefined;
1086
1139
  if (typeof address === "string" || kept?.status !== 200) {
@@ -1108,8 +1161,12 @@ export async function evalTemplate(options) {
1108
1161
  const results = [];
1109
1162
  let grader;
1110
1163
  const made = { agents: [], runs: new Set(), triggers: new Set() };
1164
+ // A previous case's earlier runs are written in the eval's own server's store (eval-previous.ts seedPrevious), opened
1165
+ // beside the server as its runner opens it, once, when the first such run seeds.
1166
+ let opened;
1167
+ const store = data !== undefined && cases.some((one) => one.previous) ? () => (opened ??= import("./store/open.js").then(({ openStore }) => openStore({ dataDir: data, role: "runner" }))) : undefined;
1111
1168
  const ctx = {
1112
- api, pkg, options, made, log, fakes, feedRoutes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}),
1169
+ api, pkg, options, made, log, fakes, feedRoutes, ...(clock ? { clock } : {}), ...(owner ? { owner } : {}), ...(store ? { store } : {}),
1113
1170
  graderAgent: async () => {
1114
1171
  if (grader)
1115
1172
  return grader;
@@ -1135,6 +1192,7 @@ export async function evalTemplate(options) {
1135
1192
  if (options.server || options.data !== undefined)
1136
1193
  for (const id of made.agents)
1137
1194
  await api("POST", `/agents/${encodeURIComponent(id)}/archive`, {}).catch(() => undefined);
1195
+ await opened?.then((one) => one.close(), () => undefined);
1138
1196
  await close();
1139
1197
  if (scratch)
1140
1198
  removeTree(scratch);
@@ -1357,8 +1415,8 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
1357
1415
  // every run. Left where the run before took it, a schedule's next time is a later day each run, with no mail of the case.
1358
1416
  // A millisecond before it: a schedule's next time is strictly after the clock, so a case whose `now` is the schedule's
1359
1417
  // own time (an evening digest's 18:00) fires for that time, not the next day's.
1360
- // An email or feed case's run is its one trigger's (readCases chose it): `via`, that trigger's name.
1361
- const via = mail ? one.email.trigger : feeds ? one.feed.trigger : undefined;
1418
+ // An email, feed or previous case's run is its one trigger's (readCases chose it): `via`, that trigger's name.
1419
+ const via = mail ? one.email.trigger : feeds ? one.feed.trigger : one.previous?.trigger;
1362
1420
  if (via !== undefined && one.now !== undefined)
1363
1421
  ctx.clock?.set(instantOf(one.now) - 1);
1364
1422
  // Approvals never, for the eval's own agent only: a run that stopped at its first ask would measure nothing. The
@@ -1414,6 +1472,17 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
1414
1472
  }, fixture.message ? " (its accept rules may leave the case's message)" : "");
1415
1473
  fired = { mailbox: () => mailboxAfter(mail.faux, mail.layout, before) };
1416
1474
  }
1475
+ else if (one.previous) {
1476
+ // The case's earlier results, each a completed run of this agent that a firing of the trigger started, ended before
1477
+ // the clock's time, so the trigger's own firing hands the run the last one's (trigger-targets.ts previousResultOf).
1478
+ if (!ctx.store || !ctx.clock)
1479
+ throw new ApiFailure("a previous case's earlier runs are seeded in the eval's own server's store, and this eval has none");
1480
+ const trigger = expectOk(`reading the package's trigger ${via}`, await api("GET", `/triggers/${encodeURIComponent(kept)}`));
1481
+ const target = isObject(trigger.target) && isObject(trigger.target.input) ? trigger.target.input : {};
1482
+ const previous = await seedPrevious(await ctx.store(), one.previous, { agentId, triggerId: kept, content: typeof target.content === "string" ? target.content : "", before: ctx.clock.now() });
1483
+ runId = await triggerRun(ctx, via, agentId, kept, () => undefined, "");
1484
+ fired = { previous };
1485
+ }
1417
1486
  else {
1418
1487
  runId = await triggerRun(ctx, via, agentId, kept, () => feeds.deliver(), " (its accept rules may leave the case's item)");
1419
1488
  fired = {};
@@ -1438,6 +1507,14 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
1438
1507
  await deleteTriggers(api, made);
1439
1508
  }
1440
1509
  }
1510
+ /** What a previous case's run, its input content `content`, was handed of the last result `seeded`: that run read back as
1511
+ * the trigger reads it (its result.output and end, GET /runs/{id}), handed over as the trigger hands it (handedPrevious). */
1512
+ async function handedOf(api, content, seeded) {
1513
+ const last = seeded.at(-1);
1514
+ const read = expectOk(`reading the seeded run ${last.runId}`, await api("GET", `/runs/${last.runId}`));
1515
+ const output = isObject(read.result) ? (read.result.output ?? null) : null;
1516
+ return handedPrevious(content, last, { output, endedAt: typeof read.ended_at === "string" ? read.ended_at : null });
1517
+ }
1441
1518
  /** The started run `runId` of `agentId` waited on, read and graded; its calls on the saved servers `used` gave its needs
1442
1519
  * ({toolkit: server}) named on the package's toolkits; a run its trigger started (`fired`) graded on the input it was
1443
1520
  * given, an email run's fake mailbox read once it has ended. */
@@ -1451,6 +1528,7 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
1451
1528
  // Its metrics once it has ended (a cancelled run's end writes them too), before the eval's server can go.
1452
1529
  const metrics = await metricsOf(api, agentId, options.signal);
1453
1530
  const mailbox = fired?.mailbox ? await fired.mailbox() : undefined;
1531
+ const handed = fired?.previous ? await handedOf(api, isObject(view.input) && typeof view.input.content === "string" ? view.input.content : "", fired.previous) : undefined;
1454
1532
  stopped();
1455
1533
  const result = isObject(view.result) ? view.result : {};
1456
1534
  const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
@@ -1465,9 +1543,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
1465
1543
  })(),
1466
1544
  ...(one.now !== undefined ? { now: one.now } : {}),
1467
1545
  ...(mailbox ? { mailbox } : {}),
1546
+ ...(handed ? { handed } : {}),
1468
1547
  };
1469
1548
  stopped();
1470
- const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}) };
1549
+ const base = { run: n, agent_id: agentId, run_id: runId, status: ended.status, cost_usd: costOf(view), answer: record.answer, calls: record.calls, mcp_calls: record.mcpCalls, created_at: typeof view.created_at === "string" ? view.created_at : null, ended_at: typeof view.ended_at === "string" ? view.ended_at : null, metrics, ...(mailbox ? { mailbox_after: mailbox.after } : {}), ...(handed ? { handed_previous: handed } : {}) };
1471
1550
  // The grader's task: the input the run was given, an email or feed run's its trigger's (the payload in its tag).
1472
1551
  const task = fired ? inputMessage(view.input ?? {}) : inputMessage(runInput(one.input, one.fields));
1473
1552
  // Waiting on its person's answer (an ask_person question, a tool call's approval) is where such a run stops, and is
@@ -19,7 +19,7 @@ export declare const MANIFEST = "agent.md";
19
19
  export declare const MODEL_TIERS: Readonly<Record<string, Tier>>;
20
20
  /** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
21
21
  * to it by the server's own verdict (template-eval.ts outputVerdict). */
22
- export declare const GRADER_TYPES: readonly ["llm", "regex", "tool_used", "file_exists", "mailbox"];
22
+ export declare const GRADER_TYPES: readonly ["llm", "regex", "tool_used", "file_exists", "mailbox", "handed"];
23
23
  /** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
24
24
  * `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
25
25
  export declare const COMPUTER_ENTRIES: readonly ["shell", "none"];
@@ -42,8 +42,9 @@ export declare const MAX_PACKAGE_FILES = 256;
42
42
  * from the agent's files' limits above. The answer's schema is given to the agent, so under evals/ too it keeps those. */
43
43
  export declare const MAX_EVAL_FILE_BYTES: number;
44
44
  /** An MCP server a package uses, by where it comes from (`source`, `toolkit`), never by the name an owner saves it under:
45
- * inside the package its tools are `mcp:<toolkit>/<tool>`. `tools`, those the agent may be granted, and `allow`, those of
46
- * them the package asks the owner to grant (a consent screen shows it, with `reason`). Neither the package nor an apply
45
+ * inside the package its tools are `mcp:<toolkit>/<tool>`. `tools`, those the agent uses and the package asks the owner to
46
+ * grant (a consent screen shows each, with `reason`), and `allow`, those of them expected to run without asking (reads);
47
+ * the rest (writes) wait for the owner's OK on each call (packageView's `asks`). Neither the package nor an apply
47
48
  * sets a permission: an apply's `grants`, the owner's ticks, grant the tools, and each call follows this server's tool settings
48
49
  * (a write asks unless the owner allowed it there, a read follows the server's Allow reads, approvals never lifts an ask). `pin`, by tool: the arguments each of its calls must carry (a value, or
49
50
  * `${parameters.<name>}`), which apply writes as the tool's pin in the agent's tool settings, so a send goes only to the
package/dist/templates.js CHANGED
@@ -37,7 +37,7 @@ export const MODEL_TIERS = { fast: "fast", balanced: "default", strong: "strong"
37
37
  const SCALAR_TYPES = ["string", "number", "integer", "boolean"];
38
38
  /** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
39
39
  * to it by the server's own verdict (template-eval.ts outputVerdict). */
40
- export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbox"];
40
+ export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbox", "handed"];
41
41
  /** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
42
42
  * `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
43
43
  export const COMPUTER_ENTRIES = ["shell", "none"];
@@ -902,9 +902,10 @@ export function readPackage(from, { evalFixtures = true } = {}) {
902
902
  const caseDoc = own.includes("case.yaml") ? parseDocument(text(`${at}/case.yaml`), { uniqueKeys: true }) : undefined;
903
903
  if (caseDoc?.errors.length)
904
904
  bad(`${at}/case.yaml`, "is not YAML");
905
- // An email or feed case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has no body.
905
+ // An email, feed or previous case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has
906
+ // no body.
906
907
  const caseJs = !!caseDoc && !caseDoc.errors.length && isObject(caseDoc.toJS()) ? caseDoc.toJS() : undefined;
907
- const triggeredCase = caseJs !== undefined && (caseJs.email !== undefined || caseJs.feed !== undefined);
908
+ const triggeredCase = caseJs !== undefined && (caseJs.email !== undefined || caseJs.feed !== undefined || caseJs.previous !== undefined);
908
909
  if (!own.includes("prompt.md"))
909
910
  bad(at, "has no prompt.md");
910
911
  else if (!triggeredCase && !front(`${at}/prompt.md`, false)?.body.trim())
@@ -81,6 +81,10 @@ export function savedPaths(tool, args, result) {
81
81
  const file = str(args.path) ?? str(args.file_path);
82
82
  return file ? [file] : [];
83
83
  }
84
+ if (tool === "web_save") {
85
+ const saved = obj(json(result.text));
86
+ return saved?.ok === true && str(saved.path) ? [str(saved.path)] : [];
87
+ }
84
88
  if (tool !== "browser_downloads")
85
89
  return [];
86
90
  const fetched = json(result.text)?.fetched;
@@ -130,6 +134,19 @@ const fetchOutcome = (result) => {
130
134
  // web_fetch answers a page, `{ok, url, status, title, text, links, refused?, error?}`.
131
135
  registerLabel("web_fetch", fetchLabel, fetchFold, { name: "Fetch web pages" });
132
136
  registerOutcome("web_fetch", fetchOutcome);
137
+ // web_save answers `{ok: true, path, bytes, content_type, url}` or `{ok: false, url, path?, refused | error}` (web-save.ts):
138
+ // the path it answered, else the one asked (a bare name under media/, as it saves one), and the host it was asked for.
139
+ const savedAt = (a, result) => {
140
+ const answered = result && str(obj(json(result.text))?.path);
141
+ const asked = str(a.path);
142
+ return answered ?? (asked ? (asked.includes("/") ? asked : `media/${asked}`) : "a file");
143
+ };
144
+ const fromHost = (a) => {
145
+ const host = URL.parse(str(a.url) ?? "")?.host;
146
+ return host ? ` from ${host}` : "";
147
+ };
148
+ registerLabel("web_save", (a, result) => `${unfetched(result) ? "Tried to save" : "Saved"} ${savedAt(a, result)}${fromHost(a)}`, { many: (n) => `Saved ${n} files from the web`, subject: (input) => input ?? undefined }, { name: "Save files from the web" });
149
+ registerOutcome("web_save", fetchOutcome);
133
150
  registerLabel("web_search", (a) => {
134
151
  const query = str(a.query);
135
152
  return query ? `Searched the web for "${cut(scrubUrls(query), 60)}"` : "Searched the web";
@@ -143,9 +143,11 @@ export type PendingApproval = {
143
143
  /** The call's arguments as text, at most ARGS_PREVIEW_BYTES. */
144
144
  args_preview: string;
145
145
  /** What the call does in words, where its tool says (email_send: "Send email to <to>, cc <cc>: <subject>" and the
146
- * text's first 300 characters), then why it asks when its setting allows it (ToolEntry.asks), redacted as its
147
- * arguments are. */
146
+ * text's first 300 characters), redacted as its arguments are. */
148
147
  summary?: string;
148
+ /** Why the call asks though its setting allows it (its tool's own ask, ToolEntry.asks), redacted as its arguments are;
149
+ * absent for a call that asks by its setting. Never among its arguments. */
150
+ asks_because?: string;
149
151
  requested_at: string;
150
152
  price?: ApprovalPrice;
151
153
  /** Present, true, when the run's pin marks the tool destructive (toolEffect): an allow of it needs confirm_destructive. */