@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
@@ -207,17 +207,7 @@ export async function agentLearningOverStore(store, agentId) {
207
207
  }
208
208
  return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null) };
209
209
  }
210
- /** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
211
- * agentic runs that ended (ended, stopped or failed), oldest first, each run that does a job numbered from 1 (a replay
212
- * none: the bill's numbering), with its own cost and what learning added for it (runCostOf over its row's cost and its
213
- * learning's spend, learningSpendOf), the path it took and the learned workflow it ran (its run record's, pathOfRow), the
214
- * revision of that workflow (metrics.workflow_digest) and whether an audit's shadow ran for it; and what
215
- * the series shows (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left
216
- * out. A run that learns whose record names no path (its end's patch was late or failed, or no runner wrote its end) is
217
- * left out too and counted (`unknown_path_runs`): its path and cost are not known, never `agent` at $0. `limit`: the
218
- * latest runs shown, each keeping its number; the summary is over every run; `bill` is the owner's bill over all of
219
- * them (billOf, with the revision ledger: agentLedgerOf). */
220
- export async function agentCostOverStore(store, agentId, limit = Infinity) {
210
+ export async function agentCostOverStore(store, agentId, limit = Infinity, refused) {
221
211
  const kinds = new Map();
222
212
  const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
223
213
  // Every run's launch and learning in a few reads (agentRecordsOf), never a read a run.
@@ -248,12 +238,13 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
248
238
  // shows `needs_revision` with its two numbers, so the page and the launch's decision agree.
249
239
  const workflows = workflowCostsOf(await pastRunsOverStore(store, agentId, new Map(runs.map((run) => [run.run_id, run.total_usd])), records));
250
240
  const promotions = await promotionsOf(store.settings, agentId);
251
- const replay = servingReplayOf(promotions, runs);
241
+ const skip = refused ? await refused(agentId, promotions) : undefined;
242
+ const replay = servingReplayOf(promotions, runs, skip);
252
243
  // The owner's bill: booked $, every run of the series (billOf), from the series' first run on a served path (the
253
244
  // summary's takeover: read from the run rows by their place, as the promotion feed is trimmed and its oldest record need
254
245
  // not be the first promotion), and each revision's compile and check over the served runs that carry it: runs on no
255
246
  // named disk alone, as a run on one learns nothing and serves nothing (learn/learning-of.ts).
256
- const ledger = await agentLedgerOf(records, promotions, listed.filter((run) => run.disk === null), await resetLedgerOf(store.settings, agentId));
247
+ const ledger = await agentLedgerOf(records, promotions, listed.filter((run) => run.disk === null), await resetLedgerOf(store.settings, agentId), skip);
257
248
  const summary = costSummary(runs, replay);
258
249
  const booked = billOf(runs, summary);
259
250
  // What no run carries is the booked total less every run's all-in (A8), so a revision whose records aged out of the
@@ -316,7 +307,7 @@ function allInV2Of(run, compiles, shares) {
316
307
  }
317
308
  /** The agent's revision ledger (revisionLedgerOf) over `listed` (its runs, as runs.list read them): its ended runs that do
318
309
  * a job or check one (no shadow, no imported or archived run), and the compile turns their rounds asked, by run. */
319
- async function agentLedgerOf(records, promotions, listed, reset) {
310
+ async function agentLedgerOf(records, promotions, listed, reset, refused) {
320
311
  const rows = listed.filter((one) => FINAL_STATES.includes(one.state) && !one.importedFrom && one.archivedAt === null && !isShadowRun(one.id));
321
312
  const compiles = new Map();
322
313
  for (const row of rows) {
@@ -324,7 +315,7 @@ async function agentLedgerOf(records, promotions, listed, reset) {
324
315
  if (asked.length)
325
316
  compiles.set(row.id, asked);
326
317
  }
327
- return { ...revisionLedgerOf(promotions, rows, [...compiles.values()].flat(), reset), compiles };
318
+ return { ...revisionLedgerOf(promotions, rows, [...compiles.values()].flat(), reset, refused), compiles };
328
319
  }
329
320
  /** Each revision of the agent's learned workflows (one per workflow and digest its promotion records name, in the order
330
321
  * they were first recorded) with its learning spend, and what its served runs carry of it (amortize), over `rows`: the
@@ -336,8 +327,9 @@ async function agentLedgerOf(records, promotions, listed, reset) {
336
327
  * (the bill's unattributed does). It is spread over its first K served runs (`workflow` or `handed_back` of its workflow
337
328
  * at its digest), K its check's compile_after; `state` from its newest record. A revision an earlier reset of the agent's
338
329
  * learning deleted (`reset`, learn/promote.ts keepResetLedger) is one too, first, stopped, at the K it was kept with,
339
- * unless the records name it again. */
340
- export function revisionLedgerOf(records, rows, compiles = [], reset = []) {
330
+ * unless the records name it again. Serving is the champion's (championOf), skipping what `refused` names (the purge
331
+ * gate's), so a purged run's revision is never said to serve. */
332
+ export function revisionLedgerOf(records, rows, compiles = [], reset = [], refused) {
341
333
  const ordered = [...rows].sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
342
334
  const newest = new Map();
343
335
  for (const record of records)
@@ -352,7 +344,7 @@ export function revisionLedgerOf(records, rows, compiles = [], reset = []) {
352
344
  };
353
345
  const revisions = [
354
346
  ...reset.filter((one) => !newest.has(`${one.workflow}\0${one.digest}`)).map((one) => spendOf(one.workflow, one.digest, one.k ?? COMPILE_AFTER_DEFAULT, "stopped")),
355
- ...[...newest.values()].map((record) => spendOf(record.workflow, record.digest, record.check?.compile_after ?? COMPILE_AFTER_DEFAULT, record.decided === "replaying" ? "checking" : championOf(records, record.workflow)?.digest === record.digest ? "serving" : "stopped")),
347
+ ...[...newest.values()].map((record) => spendOf(record.workflow, record.digest, record.check?.compile_after ?? COMPILE_AFTER_DEFAULT, record.decided === "replaying" ? "checking" : championOf(records, record.workflow, refused)?.digest === record.digest ? "serving" : "stopped")),
356
348
  ];
357
349
  const served = ordered.flatMap((row) => {
358
350
  const at = revisionOfRow(row);
@@ -369,8 +361,8 @@ export function revisionLedgerOf(records, rows, compiles = [], reset = []) {
369
361
  * spend is on the runs it serves, so its `learning_usd` and `all_in_usd` are 0, and the sum of every run's `all_in_usd`
370
362
  * and the bill's `unattributed_usd` is the booked total. While the run is at work `usd` is `rowUsd` and the rest null;
371
363
  * null while unknown (its shadow still at work, a compile's or a check's cost unknown), never $0. Undefined for an
372
- * unknown run. */
373
- export async function runAllInOverStore(store, runId, rowUsd) {
364
+ * unknown run. Its revision's champion skips what `refused` names of the agent's promotion records (agentCostOverStore). */
365
+ export async function runAllInOverStore(store, runId, rowUsd, refused) {
374
366
  const run = await store.runs.get(runId);
375
367
  if (!run)
376
368
  return undefined;
@@ -389,7 +381,9 @@ export async function runAllInOverStore(store, runId, rowUsd) {
389
381
  if (path !== null && SERVED_PATHS.includes(path) && revisionOfRow(run)) {
390
382
  // Over the agent's runs on no named disk, as the cost page's ledger reads (learn/learning-of.ts).
391
383
  const listed = (await store.runs.list({ agentId: run.agentId, disk: null })).filter((one) => one.agentId === run.agentId);
392
- shares = (await agentLedgerOf(await agentRecordsOf(store, run.agentId, listed), await promotionsOf(store.settings, run.agentId), listed, await resetLedgerOf(store.settings, run.agentId))).shares;
384
+ const promotions = await promotionsOf(store.settings, run.agentId);
385
+ const skip = refused ? await refused(run.agentId, promotions) : undefined;
386
+ shares = (await agentLedgerOf(await agentRecordsOf(store, run.agentId, listed), promotions, listed, await resetLedgerOf(store.settings, run.agentId), skip)).shares;
393
387
  }
394
388
  const figures = { run_id: run.id, ...cost };
395
389
  const compiles = await compilesOf(store, run.id);
@@ -399,10 +393,10 @@ export async function runAllInOverStore(store, runId, rowUsd) {
399
393
  * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's check numbers
400
394
  * (the share of the inputs it ran on that said what the agent said, against the agent's own 100%). `cleared`: it passed
401
395
  * (a champion is promoted), with the agreement check it passed (`agreed` of `alone`, its bar `agree_min`). Null when no run was served, nothing serves now (held, or never promoted), or it was promoted
402
- * on no input (a dry run). */
403
- export function servingReplayOf(records, runs) {
396
+ * on no input (a dry run). The champion skips what `refused` names (the purge gate's). */
397
+ export function servingReplayOf(records, runs, refused) {
404
398
  const name = runs.findLast((run) => (run.path === "workflow" || run.path === "handed_back") && run.workflow !== null)?.workflow;
405
- const check = name ? championOf(records, name)?.check : undefined;
399
+ const check = name ? championOf(records, name, refused)?.check : undefined;
406
400
  if (!check?.n)
407
401
  return null;
408
402
  const agreed = check.agreed ?? 0, alone = check.alone ?? 0;
@@ -106,11 +106,6 @@ interface StoreRun {
106
106
  /** What the run's decisions booked (their own session, metrics.ts bookedSpend), undefined when it booked none: the run's cost
107
107
  * adds it to its usage row's, as the timeline adds their receipts. */
108
108
  readonly decisions: BookedSpend | undefined;
109
- /** Its model requests billed to a ChatGPT plan (metrics.ts planSpend), undefined when it made none. */
110
- readonly plan: {
111
- readonly requests: number;
112
- readonly tokens: number;
113
- } | undefined;
114
109
  /** What its model requests booked (metrics.ts bookedSpend "model": every session but its paid tools' and its
115
110
  * decisions'): their tokens and how they were priced, for its cost's `tokens` and `basis`. */
116
111
  readonly model: BookedSpend;
@@ -22,7 +22,7 @@ import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, active
22
22
  import { reflects } from "./reflect-range.js";
23
23
  import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
24
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";
25
+ import { bookedDecisionsOf, bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, runCostOf, storedBasisOf } from "./runner/metrics.js";
26
26
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
27
27
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
28
28
  import { laidOf, pathViewOf, roundsOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
@@ -259,7 +259,7 @@ async function storeRunIn(store, runId, deps, cut, since) {
259
259
  const terminal = row.state !== "running";
260
260
  // Its structured answer, from the final answer as the journal keeps it: never the served text, which a held value
261
261
  // (a number among them) or a long answer's cut would have changed, so a block that meets the schema reads as written.
262
- const rawAnswer = outputSchema !== undefined && terminal ? answerOf(await runTimeline(store, runId, context, { settled: true, caps: { text: Number.POSITIVE_INFINITY } })) : null;
262
+ const rawAnswer = outputSchema !== undefined && terminal ? answerOf(await runTimeline(store, runId, context, { settled: true, caps: { text: Number.POSITIVE_INFINITY } }, records)) : null;
263
263
  const structured = outputSchema !== undefined && terminal ? (rawAnswer !== null ? structuredAnswer(rawAnswer, outputSchema) : { why: "the run gave no final answer" }) : undefined;
264
264
  // The timeline, then the waiting row a run asking a question shows (withAsks), as the file path's rows carried it, so a
265
265
  // run waiting on a question reads the same status and pending.
@@ -267,7 +267,9 @@ async function storeRunIn(store, runId, deps, cut, since) {
267
267
  // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far. One
268
268
  // looking back is still going: its look-back's rows come yet.
269
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));
270
+ // Rendered from the records read above, so its usage row and the cost's `plan` (bookedSpend over the same entries) are
271
+ // of one read.
272
+ const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions, records), timelineOptions, wholeAnswerFor(values), since));
271
273
  const revisions = await store.agents.revisions(row.agent);
272
274
  const version = revisions.findIndex((r) => r.id === row.revision) + 1;
273
275
  const ended = await runLearningEnd(store, runId);
@@ -407,8 +409,6 @@ async function storeRunIn(store, runId, deps, cut, since) {
407
409
  // What its decisions booked (their own session, never on the usage row, which counts its model requests and paid tools).
408
410
  const booked = bookedSpend(records.entries, "decisions");
409
411
  const decisions = booked.requests ? booked : undefined;
410
- const onPlan = planSpend(records.entries);
411
- const plan = onPlan.requests ? onPlan : undefined;
412
412
  const model = bookedSpend(records.entries, "model");
413
413
  // An ended run's booking by the one rule its end stored its cost by (metrics.ts runCostOf), read in the same snapshot as
414
414
  // its state: its so-far figures beside a stored unknown (costOfView reads the figure itself from the stored column). A
@@ -422,7 +422,7 @@ async function storeRunIn(store, runId, deps, cut, since) {
422
422
  const endSaidCost = endCost && !lookingBack ? endSaid !== undefined : false;
423
423
  const endUnread = !lookingBack && bookedCost !== undefined && !endCost && endSaid === null;
424
424
  const heal = lookingBack ? undefined : healOf(endCost, runRow);
425
- 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, windDown, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
425
+ 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, model, windDown, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
426
426
  }
427
427
  /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
428
428
  * the end a run looking back keeps), its cost as read. */
@@ -481,8 +481,9 @@ function costOfView(run) {
481
481
  const upper = words.upper_bound ? { upper_bound: true } : undefined;
482
482
  // A request billed to a person's plan costs no dollars, however it ended (the kernel's turnCostOf): every reader counts it
483
483
  // $0, so it is in no unpriced count; what it used on the plan is said beside the figure, and which plan: a run on the
484
- // login's harness was on Claude Code's login (claude-login.ts), any other on the ChatGPT sign-in.
485
- const plan = run.plan;
484
+ // login's harness was on Claude Code's login (claude-login.ts), any other on the ChatGPT sign-in. Read with its model
485
+ // requests (bookedSpend "model"): a request booked twice is one, as it is one request.
486
+ const plan = run.model.plan.requests ? run.model.plan : undefined;
486
487
  const on = run.harness === LOGIN_HARNESS ? "claude_code" : "chatgpt";
487
488
  // Beside its figure: while it is unknown, what is known so far; at $0 with every model request on a free model (and no
488
489
  // decision of its own), that it is free.
@@ -164,6 +164,12 @@ export type ToolCall = {
164
164
  result?: string | null;
165
165
  arguments?: Json;
166
166
  };
167
+ /** A file a run left in its work folder: its path, its size in bytes and, for a text file read whole, its text. */
168
+ export type FinalFile = {
169
+ path: string;
170
+ bytes: number;
171
+ text?: string;
172
+ };
167
173
  /** What a run left, for its graders. */
168
174
  export type RunRecord = {
169
175
  /** The run's final answer, or "" when it has none. */
@@ -174,6 +180,9 @@ export type RunRecord = {
174
180
  mcpCalls: ToolCall[];
175
181
  /** The paths of its files, from its work folder. */
176
182
  files: string[];
183
+ /** Its work folder's files as it left them, for its llm graders (finalFilesOf): each text file with its whole `text`,
184
+ * any other (media, a binary, one past what was read) with its size alone. */
185
+ finalFiles?: FinalFile[];
177
186
  /** The clock it ran on, its case's `now`; absent, the real one. */
178
187
  now?: string;
179
188
  /** Its fake mailbox after it, for a case with `email` (eval-mailbox.ts). */
@@ -200,8 +209,8 @@ export declare function gradeDeterministic(grader: Exclude<Grader, {
200
209
  * carries a grader for it. Undefined for a package with no output schema. */
201
210
  export declare function outputVerdict(pkg: Package, result: unknown): GraderResult | undefined;
202
211
  /** The input a grader run gets for an llm grader: the rubric, the clock the run ran on when its case set one (the grader's
203
- * own run is on the real clock), the run's input, its answer (its target field marked when the grader names one), its
204
- * calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
212
+ * own run is on the real clock), the run's input, its answer (its target field marked when the grader names one), the
213
+ * files it left (fitFiles: whole ahead of its calls, which are cut first), its calls and, for a run that searched or fetched, the link check of its cited links (link-check.ts). Never another grader, the case's description or anything the case expects. */
205
214
  export declare function graderInput(grader: Extract<Grader, {
206
215
  type: "llm";
207
216
  }>, input: string, run: RunRecord, max?: number): string;
@@ -217,6 +226,11 @@ export declare function fitCalls(lines: readonly {
217
226
  result: string;
218
227
  tool?: string;
219
228
  }[], room: number, what?: string): string;
229
+ /** A run's final files in at most `room` characters: each text file in a <file> block, whole when they all fit; else each
230
+ * text past a length L keeps its head and tail with its middle cut and marked, L the longest that fits (so the largest
231
+ * is cut first); else every text left out. A file with no text (media, a binary, one past what was read) is named with
232
+ * its size on a last line, cut to the room when even that passes it. */
233
+ export declare function fitFiles(files: readonly FinalFile[], room: number): string;
220
234
  /** A grader run's answer read as its verdict: the last json block's (else the last JSON object's) {pass, reason}. */
221
235
  export declare function verdictOf(answer: string): {
222
236
  pass: boolean;
@@ -234,19 +248,48 @@ export declare function startFake(name: string, fixture: McpFixture): Promise<Fa
234
248
  type Answered = {
235
249
  status: number;
236
250
  body: unknown;
251
+ headers?: Headers;
237
252
  };
238
- /** `statusOnly`: the answer's status alone, its body cancelled unread (a file's existence, never its bytes). `signal`: the
239
- * request and the read of its body stop when it aborts, and the call rejects. */
253
+ /** `statusOnly`: the answer's status alone, its body cancelled unread (a file's existence, never its bytes). `text`: its
254
+ * body as the text it is, never parsed (a file's bytes: a JSON file's text, as it was written), with the answer's headers.
255
+ * `signal`: the request and the read of its body stop when it aborts, and the call rejects. */
240
256
  export type Api = (method: string, path: string, body?: unknown, headers?: Record<string, string>, options?: {
241
257
  statusOnly?: true;
258
+ text?: true;
242
259
  signal?: AbortSignal;
243
260
  }) => Promise<Answered>;
261
+ /** A client of the v2 API at `baseUrl` (ending in /v2) with `token`. */
262
+ export declare function apiOf(baseUrl: string, token: string): Api;
263
+ /** How long the run read that asks whether a runner holds a queued run may take. */
264
+ export declare const CLAIM_READ_TIMEOUT_MS = 10000;
244
265
  /** A run's tool calls, each named as a grader names it: the gate's own rule (RunGate.enter), its settings key, but a
245
266
  * shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
246
267
  * call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
247
268
  * under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
248
269
  * its output's head as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
249
270
  export declare function callsOf(rows: readonly Json[], harness: string, toolkits?: Readonly<Record<string, string>>): ToolCall[];
271
+ /** A file of a run's work folder as its listing names it: its size, its type (null for an extension the server does not
272
+ * type) and whether the server could read it. */
273
+ export type Listed = {
274
+ path: string;
275
+ bytes: number;
276
+ type: string | null;
277
+ unreadable: boolean;
278
+ };
279
+ /** How long one read of a run's final file may take, its body included: a server that stalls mid-file leaves that file's
280
+ * text out, and the eval goes on. */
281
+ export declare const FILE_READ_TIMEOUT_MS = 10000;
282
+ /** How long all of a run's final file reads may take together: past it, the files not yet read are listed by size alone. */
283
+ export declare const FILE_READS_TIMEOUT_MS = 30000;
284
+ /** A run's final files for its llm graders: each text file's whole text, read smallest first while the texts read stay
285
+ * within GRADER_PROMPT_MAX UTF-8 bytes in all (one grader input holds that many characters, and a character is at least
286
+ * a byte), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
287
+ * secrets (`?cut=run`, run-reads-over-store.ts cutRunFile): every value its timeline's calls are cut of, and every secret
288
+ * shape, is "[redacted]" in the text a grader sees. An answer without the cut's mark (`x-agentrun-cut: run`: a server
289
+ * that doesn't know the cut and would serve the raw bytes) leaves the text out. A read that fails, is refused (403, 413,
290
+ * 415), takes longer than `readTimeoutMs`, or would pass the budget leaves that file's text out, never the grade, and
291
+ * the files after it are still read; past FILE_READS_TIMEOUT_MS in all, the rest are left out. In the listing's order. */
292
+ export declare function finalFilesOf(api: Api, runId: string, listed: readonly Listed[], signal?: AbortSignal, readTimeoutMs?: number): Promise<FinalFile[]>;
250
293
  /** How long a run's metrics read may take before the run is reported without them. */
251
294
  export declare const METRICS_TIMEOUT_MS = 10000;
252
295
  /** The metrics of the one run `agentId` made (RunMetrics), from GET /stats?agent=; null when the server kept none (the run
@@ -279,6 +322,8 @@ export type EvalOptions = {
279
322
  runTimeoutMs?: number;
280
323
  /** How long one run may stay queued with no runner taking it (default QUEUE_TIMEOUT_MS). */
281
324
  queueTimeoutMs?: number;
325
+ /** How long one read of a run's final file may take, its body included (default FILE_READ_TIMEOUT_MS). */
326
+ fileReadTimeoutMs?: number;
282
327
  /** Told each step as one line (the CLI's stderr). */
283
328
  log?: (line: string) => void;
284
329
  /** Stops the eval: the run in progress is cancelled, what the eval made is cleaned up as at its end, and the eval