@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60

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 (474) hide show
  1. package/CHANGELOG.md +402 -1
  2. package/README.md +516 -190
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agent-delete.d.ts +6 -9
  8. package/dist/agent-delete.js +5 -3
  9. package/dist/agent-package.js +11 -1
  10. package/dist/agents-store.js +1 -1
  11. package/dist/answer-text.d.ts +3 -0
  12. package/dist/answer-text.js +22 -0
  13. package/dist/api-only.d.ts +2 -2
  14. package/dist/api-only.js +3 -3
  15. package/dist/archil-routes.d.ts +4 -1
  16. package/dist/archil-routes.js +15 -12
  17. package/dist/archil-settings.d.ts +18 -8
  18. package/dist/archil-settings.js +35 -17
  19. package/dist/attach-conformance.js +5 -4
  20. package/dist/box-paths.d.ts +3 -2
  21. package/dist/box-paths.js +5 -4
  22. package/dist/browser-computer.d.ts +3 -8
  23. package/dist/browser-computer.js +12 -35
  24. package/dist/browser-cost.js +94 -20
  25. package/dist/capacity.d.ts +1 -1
  26. package/dist/capacity.js +3 -3
  27. package/dist/chatgpt-plan.d.ts +7 -0
  28. package/dist/chatgpt-plan.js +35 -11
  29. package/dist/claude-login-token.d.ts +20 -11
  30. package/dist/claude-login-token.js +175 -107
  31. package/dist/claude-login.d.ts +124 -33
  32. package/dist/claude-login.js +562 -85
  33. package/dist/claude-sign-in.d.ts +3 -0
  34. package/dist/claude-sign-in.js +10 -1
  35. package/dist/cli-learning/connections.js +1 -1
  36. package/dist/cli.js +323 -292
  37. package/dist/composio-made.d.ts +1 -6
  38. package/dist/composio-made.js +1 -6
  39. package/dist/composio-owners.d.ts +26 -0
  40. package/dist/composio-owners.js +36 -0
  41. package/dist/composio-preset.d.ts +56 -23
  42. package/dist/composio-preset.js +173 -77
  43. package/dist/composio-triggers.d.ts +4 -4
  44. package/dist/composio-triggers.js +6 -7
  45. package/dist/compute-cost.js +11 -2
  46. package/dist/computer-attach.d.ts +6 -3
  47. package/dist/computer-attach.js +41 -29
  48. package/dist/computer-held-routes.d.ts +1 -1
  49. package/dist/computer-held-routes.js +9 -4
  50. package/dist/computer-keys.d.ts +11 -1
  51. package/dist/computer-keys.js +26 -1
  52. package/dist/computer-record.js +3 -1
  53. package/dist/computer-view.d.ts +5 -3
  54. package/dist/computer-view.js +10 -6
  55. package/dist/computer-viewer.js +36 -7
  56. package/dist/computers.d.ts +2 -1
  57. package/dist/computers.js +6 -3
  58. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  59. package/dist/console/assets/backend-QnwGVBeU.js +166 -0
  60. package/dist/console/assets/index-DZi-muIj.js +629 -0
  61. package/dist/console/assets/share-pz61zIn9.js +6 -0
  62. package/dist/console/assets/styles-CcceGcu2.js +291 -0
  63. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  64. package/dist/console/index.html +4 -3
  65. package/dist/console/share.html +17 -0
  66. package/dist/decisions.d.ts +17 -7
  67. package/dist/decisions.js +41 -15
  68. package/dist/dial-relay.js +10 -4
  69. package/dist/docker-daemon.js +4 -5
  70. package/dist/docker-host-addresses.js +29 -11
  71. package/dist/email/account.d.ts +6 -0
  72. package/dist/email/account.js +6 -0
  73. package/dist/email/authentication.d.ts +21 -0
  74. package/dist/email/authentication.js +106 -0
  75. package/dist/email/email-faux.d.ts +11 -2
  76. package/dist/email/email-faux.js +21 -5
  77. package/dist/email/mail.d.ts +25 -0
  78. package/dist/email/mail.js +58 -2
  79. package/dist/email/names.js +2 -2
  80. package/dist/email/tools.d.ts +9 -4
  81. package/dist/email/tools.js +95 -13
  82. package/dist/env-switch.d.ts +12 -2
  83. package/dist/env-switch.js +23 -3
  84. package/dist/errors.d.ts +1 -0
  85. package/dist/errors.js +2 -0
  86. package/dist/factory-activity.d.ts +68 -0
  87. package/dist/factory-activity.js +153 -0
  88. package/dist/factory-runs.d.ts +11 -0
  89. package/dist/factory-runs.js +52 -0
  90. package/dist/fal-price.d.ts +11 -1
  91. package/dist/fal-price.js +33 -0
  92. package/dist/faux-computers.js +1 -1
  93. package/dist/filed-answer.d.ts +2 -2
  94. package/dist/filed-answer.js +2 -2
  95. package/dist/filed-tool.d.ts +32 -0
  96. package/dist/filed-tool.js +122 -0
  97. package/dist/graph-served.d.ts +10 -5
  98. package/dist/graph-served.js +40 -10
  99. package/dist/handed-values.js +1 -2
  100. package/dist/harness-check.d.ts +2 -1
  101. package/dist/harness-check.js +45 -12
  102. package/dist/harness-keys.d.ts +1 -2
  103. package/dist/harness-keys.js +10 -8
  104. package/dist/harness-opencode/facts.js +2 -0
  105. package/dist/harness-recipe-entry.d.ts +9 -3
  106. package/dist/harness-recipe-entry.js +18 -9
  107. package/dist/harness-recipe.d.ts +21 -0
  108. package/dist/harness-recipe.js +25 -3
  109. package/dist/harness-table.d.ts +12 -0
  110. package/dist/harness-table.js +21 -6
  111. package/dist/harness.js +6 -2
  112. package/dist/helper-env.d.ts +4 -1
  113. package/dist/helper-env.js +4 -1
  114. package/dist/host-check.d.ts +2 -3
  115. package/dist/host-check.js +13 -7
  116. package/dist/hosted-search.js +1 -1
  117. package/dist/import-worker.js +2 -2
  118. package/dist/import.d.ts +20 -8
  119. package/dist/import.js +448 -187
  120. package/dist/key-refusal.d.ts +14 -2
  121. package/dist/key-refusal.js +97 -33
  122. package/dist/learn/audit.d.ts +28 -27
  123. package/dist/learn/audit.js +87 -62
  124. package/dist/learn/check.js +1 -1
  125. package/dist/learn/commit.d.ts +35 -43
  126. package/dist/learn/commit.js +62 -270
  127. package/dist/learn/compile.d.ts +9 -6
  128. package/dist/learn/compile.js +51 -28
  129. package/dist/learn/corrections.js +1 -1
  130. package/dist/learn/delete.d.ts +5 -12
  131. package/dist/learn/delete.js +17 -30
  132. package/dist/learn/field-check.d.ts +111 -0
  133. package/dist/learn/field-check.js +174 -0
  134. package/dist/learn/forget-run.d.ts +16 -0
  135. package/dist/learn/forget-run.js +53 -0
  136. package/dist/learn/index.js +1 -1
  137. package/dist/learn/learning-of.d.ts +0 -4
  138. package/dist/learn/learning-of.js +0 -5
  139. package/dist/learn/ledger.d.ts +32 -29
  140. package/dist/learn/ledger.js +26 -19
  141. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  142. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  143. package/dist/learn/legacy/place.d.ts +16 -0
  144. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  145. package/dist/learn/legacy/scrub.d.ts +28 -0
  146. package/dist/learn/legacy/scrub.js +258 -0
  147. package/dist/learn/promote.d.ts +119 -102
  148. package/dist/learn/promote.js +119 -262
  149. package/dist/learn/reset-ledger.d.ts +18 -0
  150. package/dist/learn/reset-ledger.js +14 -0
  151. package/dist/learn/rows.d.ts +186 -0
  152. package/dist/learn/rows.js +376 -0
  153. package/dist/learn/secrets.d.ts +4 -0
  154. package/dist/learn/secrets.js +12 -0
  155. package/dist/learn/workflow-draft.d.ts +4 -1
  156. package/dist/learn/workflow-draft.js +12 -2
  157. package/dist/learned-nodes.d.ts +8 -5
  158. package/dist/learned-nodes.js +8 -5
  159. package/dist/learned-workflow.d.ts +2 -1
  160. package/dist/learned-workflow.js +13 -10
  161. package/dist/learning-cost.d.ts +25 -8
  162. package/dist/learning-cost.js +23 -8
  163. package/dist/learning-reset.d.ts +1 -1
  164. package/dist/learning-reset.js +9 -11
  165. package/dist/learning-routes.d.ts +60 -81
  166. package/dist/learning-routes.js +187 -360
  167. package/dist/learning-setting.d.ts +6 -0
  168. package/dist/learning-setting.js +11 -1
  169. package/dist/learning-words.d.ts +2 -0
  170. package/dist/learning-words.js +2 -0
  171. package/dist/learning.d.ts +18 -24
  172. package/dist/learning.js +35 -66
  173. package/dist/listen-first.d.ts +5 -4
  174. package/dist/listen-first.js +4 -5
  175. package/dist/live-reach.d.ts +7 -0
  176. package/dist/live-reach.js +7 -0
  177. package/dist/mcp-api-only-origins.d.ts +15 -0
  178. package/dist/mcp-api-only-origins.js +40 -0
  179. package/dist/mcp-gateway.d.ts +22 -2
  180. package/dist/mcp-gateway.js +85 -11
  181. package/dist/mcp-oauth.d.ts +1 -1
  182. package/dist/mcp-oauth.js +3 -2
  183. package/dist/mcp-probe.d.ts +3 -0
  184. package/dist/mcp-probe.js +3 -0
  185. package/dist/mcp-resources.d.ts +1 -1
  186. package/dist/mcp-secret-writes.d.ts +24 -2
  187. package/dist/mcp-secret-writes.js +30 -2
  188. package/dist/mcp-servers-store.d.ts +52 -14
  189. package/dist/mcp-servers-store.js +165 -61
  190. package/dist/mcp-sources.d.ts +1 -2
  191. package/dist/mcp-sources.js +1 -2
  192. package/dist/mcp-store.d.ts +5 -5
  193. package/dist/mcp-store.js +3 -3
  194. package/dist/mcp.js +1 -1
  195. package/dist/model-gateway.d.ts +1 -1
  196. package/dist/model-gateway.js +20 -36
  197. package/dist/native/discovery.d.ts +6 -0
  198. package/dist/native/discovery.js +14 -1
  199. package/dist/native/remote.d.ts +5 -0
  200. package/dist/native/remote.js +16 -0
  201. package/dist/native/runtime.js +3 -2
  202. package/dist/observation/observer.d.ts +6 -6
  203. package/dist/ollama-provider.d.ts +23 -9
  204. package/dist/ollama-provider.js +49 -20
  205. package/dist/openapi.js +290 -79
  206. package/dist/otel/genai.d.ts +83 -7
  207. package/dist/otel/genai.js +69 -9
  208. package/dist/otel/tracer.d.ts +42 -13
  209. package/dist/otel/tracer.js +241 -56
  210. package/dist/page.d.ts +7 -1
  211. package/dist/page.js +76 -22
  212. package/dist/paid-calls.d.ts +6 -4
  213. package/dist/paid-calls.js +15 -7
  214. package/dist/place-offers.d.ts +58 -34
  215. package/dist/place-offers.js +96 -54
  216. package/dist/place.d.ts +41 -20
  217. package/dist/place.js +97 -47
  218. package/dist/print.js +1 -1
  219. package/dist/provider.d.ts +3 -2
  220. package/dist/provider.js +17 -8
  221. package/dist/purged-workflow.d.ts +0 -33
  222. package/dist/purged-workflow.js +3 -71
  223. package/dist/redact/match.d.ts +42 -9
  224. package/dist/redact/match.js +356 -54
  225. package/dist/run-census.d.ts +1 -1
  226. package/dist/run-census.js +4 -5
  227. package/dist/run-cut.js +4 -5
  228. package/dist/run-export-store.d.ts +15 -0
  229. package/dist/run-export-store.js +30 -0
  230. package/dist/run-export.d.ts +139 -0
  231. package/dist/run-export.js +379 -0
  232. package/dist/run-file-cut.d.ts +5 -0
  233. package/dist/run-file-cut.js +13 -0
  234. package/dist/run-launch.d.ts +3 -3
  235. package/dist/run-launch.js +16 -3
  236. package/dist/run-learning-served.d.ts +3 -3
  237. package/dist/run-learning-served.js +1 -1
  238. package/dist/run-listing.d.ts +1 -1
  239. package/dist/run-model-key.d.ts +15 -6
  240. package/dist/run-model-key.js +30 -31
  241. package/dist/run-reads-over-store.js +4 -4
  242. package/dist/run-secrets.js +3 -5
  243. package/dist/run-timeline-served.d.ts +1 -1
  244. package/dist/run-timeline-served.js +8 -5
  245. package/dist/runnable.js +26 -9
  246. package/dist/runner/adapter-loop.d.ts +35 -18
  247. package/dist/runner/adapter-loop.js +94 -47
  248. package/dist/runner/adapter-run-spec.d.ts +14 -1
  249. package/dist/runner/adapter-run-spec.js +73 -46
  250. package/dist/runner/adapters/pi.js +4 -2
  251. package/dist/runner/audit.d.ts +10 -9
  252. package/dist/runner/audit.js +64 -67
  253. package/dist/runner/beside.js +5 -6
  254. package/dist/runner/claim-secrets.d.ts +10 -3
  255. package/dist/runner/claim-secrets.js +29 -13
  256. package/dist/runner/cli-run-spec.d.ts +18 -0
  257. package/dist/runner/cli-run-spec.js +87 -58
  258. package/dist/runner/compare-end.d.ts +2 -3
  259. package/dist/runner/compare-end.js +30 -11
  260. package/dist/runner/conformance/harness.js +2 -3
  261. package/dist/runner/conformance/subject.d.ts +4 -1
  262. package/dist/runner/disk-free.d.ts +15 -4
  263. package/dist/runner/disk-free.js +25 -7
  264. package/dist/runner/feedback-round.d.ts +1 -1
  265. package/dist/runner/feedback-round.js +2 -2
  266. package/dist/runner/harness-loops.js +3 -4
  267. package/dist/runner/held.d.ts +5 -12
  268. package/dist/runner/held.js +0 -25
  269. package/dist/runner/journal-kinds.d.ts +8 -2
  270. package/dist/runner/journal-kinds.js +23 -5
  271. package/dist/runner/learned-first.d.ts +0 -2
  272. package/dist/runner/learned-first.js +23 -7
  273. package/dist/runner/learning-end.d.ts +14 -24
  274. package/dist/runner/learning-end.js +52 -94
  275. package/dist/runner/learning-seed.d.ts +13 -16
  276. package/dist/runner/learning-seed.js +13 -23
  277. package/dist/runner/live-ticker.js +7 -5
  278. package/dist/runner/loop-contract.d.ts +0 -2
  279. package/dist/runner/loop.d.ts +7 -0
  280. package/dist/runner/loop.js +1 -0
  281. package/dist/runner/main.js +13 -12
  282. package/dist/runner/mcp-claim.js +21 -5
  283. package/dist/runner/mcp-run.d.ts +4 -0
  284. package/dist/runner/mcp-run.js +2 -0
  285. package/dist/runner/meta-tools.js +3 -2
  286. package/dist/runner/metrics.d.ts +7 -0
  287. package/dist/runner/metrics.js +19 -0
  288. package/dist/runner/model-route.d.ts +10 -7
  289. package/dist/runner/model-route.js +79 -15
  290. package/dist/runner/native-loop.js +12 -11
  291. package/dist/runner/presence.d.ts +1 -4
  292. package/dist/runner/presence.js +6 -8
  293. package/dist/runner/promotion.d.ts +39 -36
  294. package/dist/runner/promotion.js +168 -112
  295. package/dist/runner/redact.d.ts +3 -1
  296. package/dist/runner/redact.js +5 -3
  297. package/dist/runner/reflect-hook.d.ts +2 -2
  298. package/dist/runner/reflect-hook.js +4 -1
  299. package/dist/runner/responses-fetch.d.ts +36 -0
  300. package/dist/runner/responses-fetch.js +511 -0
  301. package/dist/runner/run-child-host.d.ts +21 -14
  302. package/dist/runner/run-child-host.js +187 -141
  303. package/dist/runner/run-child.js +11 -4
  304. package/dist/runner/runner-check.js +5 -1
  305. package/dist/runner/runner.d.ts +3 -4
  306. package/dist/runner/runner.js +13 -9
  307. package/dist/runner/sdk-loop.js +10 -12
  308. package/dist/runner/spec-holds.d.ts +8 -1
  309. package/dist/runner/spec-holds.js +9 -4
  310. package/dist/runner/workflow-calls.d.ts +9 -0
  311. package/dist/runner/workflow-calls.js +150 -0
  312. package/dist/runner/workflow-first.d.ts +120 -32
  313. package/dist/runner/workflow-first.js +218 -94
  314. package/dist/runner/workflow-spec.js +1 -1
  315. package/dist/runs-over-store.js +8 -7
  316. package/dist/save-once.d.ts +14 -0
  317. package/dist/save-once.js +31 -0
  318. package/dist/scrub-command.d.ts +34 -31
  319. package/dist/scrub-command.js +116 -147
  320. package/dist/sdk/check.d.ts +1 -4
  321. package/dist/sdk/check.js +2 -3
  322. package/dist/sdk/runs.d.ts +26 -7
  323. package/dist/sdk/runs.js +194 -78
  324. package/dist/seal-key.js +4 -4
  325. package/dist/secret-cut.d.ts +3 -0
  326. package/dist/secret-cut.js +7 -1
  327. package/dist/secret-rules.d.ts +8 -1
  328. package/dist/secret-rules.js +482 -53
  329. package/dist/secrets.d.ts +55 -9
  330. package/dist/secrets.js +345 -21
  331. package/dist/server-fs.d.ts +1 -1
  332. package/dist/server-fs.js +1 -1
  333. package/dist/server-keys.d.ts +10 -3
  334. package/dist/server-keys.js +16 -3
  335. package/dist/server-secrets-store.js +2 -4
  336. package/dist/server.d.ts +30 -18
  337. package/dist/server.js +520 -238
  338. package/dist/share-context.d.ts +22 -0
  339. package/dist/share-context.js +76 -0
  340. package/dist/shell-lex.d.ts +105 -0
  341. package/dist/shell-lex.js +646 -0
  342. package/dist/sign-ins-store.d.ts +5 -7
  343. package/dist/sign-ins-store.js +12 -16
  344. package/dist/sign-ins.d.ts +7 -11
  345. package/dist/sign-ins.js +40 -41
  346. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  347. package/dist/source-sync/auxiliary.js +2 -2
  348. package/dist/start-switches.d.ts +6 -5
  349. package/dist/start-switches.js +8 -4
  350. package/dist/stats.d.ts +5 -1
  351. package/dist/stats.js +1 -1
  352. package/dist/store/agent-body.js +2 -2
  353. package/dist/store/dialect.d.ts +4 -0
  354. package/dist/store/dialect.js +1 -0
  355. package/dist/store/index.d.ts +2 -2
  356. package/dist/store/index.js +1 -1
  357. package/dist/store/mcp-record-keys.d.ts +10 -0
  358. package/dist/store/mcp-record-keys.js +13 -0
  359. package/dist/store/postgres/dialect.js +2 -0
  360. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  361. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  362. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  363. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  364. package/dist/store/postgres/store.js +4 -0
  365. package/dist/store/schema.d.ts +60 -11
  366. package/dist/store/schema.js +147 -17
  367. package/dist/store/seal.d.ts +4 -1
  368. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  369. package/dist/store/sqlite/learning-rows.js +559 -0
  370. package/dist/store/sqlite/run-launch.d.ts +3 -10
  371. package/dist/store/sqlite/run-launch.js +12 -23
  372. package/dist/store/sqlite/run-patch.d.ts +17 -10
  373. package/dist/store/sqlite/run-patch.js +50 -13
  374. package/dist/store/sqlite/store.d.ts +9 -0
  375. package/dist/store/sqlite/store.js +194 -46
  376. package/dist/store/store-schema.js +3 -4
  377. package/dist/store/store.d.ts +286 -38
  378. package/dist/store/store.js +27 -11
  379. package/dist/store-reads/analytics.d.ts +2 -1
  380. package/dist/store-reads/analytics.js +7 -5
  381. package/dist/store-reads/journal.d.ts +33 -3
  382. package/dist/store-reads/journal.js +99 -4
  383. package/dist/store-reads/learning.d.ts +50 -45
  384. package/dist/store-reads/learning.js +153 -116
  385. package/dist/store-reads/loop.js +1 -1
  386. package/dist/store-reads/stats.d.ts +2 -2
  387. package/dist/store-reads/stats.js +13 -7
  388. package/dist/store-view.d.ts +24 -2
  389. package/dist/store-view.js +49 -17
  390. package/dist/suggestions.d.ts +1 -1
  391. package/dist/suggestions.js +29 -13
  392. package/dist/template-eval.d.ts +72 -9
  393. package/dist/template-eval.js +358 -64
  394. package/dist/templates.d.ts +10 -2
  395. package/dist/templates.js +31 -4
  396. package/dist/timeline/labels.d.ts +1 -1
  397. package/dist/timeline/labels.js +4 -3
  398. package/dist/timeline/timeline.d.ts +23 -11
  399. package/dist/timeline/timeline.js +115 -31
  400. package/dist/timeline/web-calls.d.ts +8 -6
  401. package/dist/timeline/web-calls.js +10 -6
  402. package/dist/tool-gate.d.ts +13 -1
  403. package/dist/tool-gate.js +43 -3
  404. package/dist/tool-keys-store.js +2 -4
  405. package/dist/tool-keys.d.ts +11 -0
  406. package/dist/tool-keys.js +16 -0
  407. package/dist/tool-plane.d.ts +54 -13
  408. package/dist/tool-plane.js +103 -32
  409. package/dist/tools.d.ts +5 -1
  410. package/dist/tools.js +7 -7
  411. package/dist/trigger-email.js +12 -6
  412. package/dist/triggers.d.ts +15 -34
  413. package/dist/triggers.js +119 -126
  414. package/dist/validate.d.ts +8 -1
  415. package/dist/validate.js +163 -23
  416. package/dist/web-fake.d.ts +2 -1
  417. package/dist/web-fake.js +8 -6
  418. package/dist/web-fetch.d.ts +8 -6
  419. package/dist/web-fetch.js +13 -11
  420. package/dist/web-holds.d.ts +34 -0
  421. package/dist/web-holds.js +89 -0
  422. package/dist/web-run.d.ts +32 -5
  423. package/dist/web-run.js +76 -28
  424. package/dist/web-save.js +23 -12
  425. package/dist/web-search.js +14 -25
  426. package/dist/wires.d.ts +4 -3
  427. package/dist/wires.js +5 -4
  428. package/dist/workspace/archil-claim.d.ts +12 -5
  429. package/dist/workspace/archil-claim.js +45 -5
  430. package/dist/workspace/archil-exec.js +1 -1
  431. package/dist/workspace/archil.d.ts +1 -1
  432. package/dist/workspace/archil.js +1 -1
  433. package/dist/workspace/attach.js +52 -19
  434. package/dist/workspace/attached-computers.d.ts +6 -2
  435. package/dist/workspace/attached-computers.js +5 -4
  436. package/dist/workspace/computer-deps.d.ts +23 -6
  437. package/dist/workspace/computer-deps.js +38 -18
  438. package/dist/workspace/computer-for-claim.d.ts +21 -4
  439. package/dist/workspace/computer-for-claim.js +160 -54
  440. package/dist/workspace/computer-intervals.d.ts +2 -0
  441. package/dist/workspace/computer-intervals.js +1 -1
  442. package/dist/workspace/computer-janitor.d.ts +48 -14
  443. package/dist/workspace/computer-janitor.js +153 -44
  444. package/dist/workspace/computer-kept.d.ts +158 -32
  445. package/dist/workspace/computer-kept.js +288 -63
  446. package/dist/workspace/computer-providers.d.ts +19 -4
  447. package/dist/workspace/computer-providers.js +40 -6
  448. package/dist/workspace/index.d.ts +2 -3
  449. package/dist/workspace/index.js +2 -3
  450. package/dist/workspace/local.js +41 -1
  451. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  452. package/dist/workspace/mount-revoke-left.js +72 -0
  453. package/dist/workspace/paired-route.js +4 -5
  454. package/dist/workspace/paths.d.ts +0 -4
  455. package/dist/workspace/paths.js +0 -6
  456. package/dist/workspace/resolve-computer.d.ts +5 -2
  457. package/dist/workspace/resolve-computer.js +9 -3
  458. package/dist/workspace/run-end-computers.d.ts +11 -5
  459. package/dist/workspace/run-end-computers.js +153 -28
  460. package/dist/workspace/run-tools.d.ts +22 -3
  461. package/dist/workspace/run-tools.js +17 -5
  462. package/dist/workspace/run-workspace.d.ts +14 -1
  463. package/dist/workspace/run-workspace.js +34 -1
  464. package/dist/workspace/workspace.d.ts +7 -1
  465. package/dist/workspace/workspace.js +1 -1
  466. package/package.json +13 -14
  467. package/skills/agentrun-serve/SKILL.md +5 -2
  468. package/templates/README.md +22 -6
  469. package/templates/TOOLS.md +46 -0
  470. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  471. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  472. package/dist/console/assets/index-DPh29cyz.js +0 -747
  473. package/dist/workspace/learning-workspace.d.ts +0 -24
  474. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -31,6 +31,9 @@ import { CALENDAR_EVENTS } from "./calendar/names.js";
31
31
  import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
32
32
  import { builtinHarness } from "./harness-table.js";
33
33
  import { CALLS_PAGE_ROWS, webShownOf } from "./timeline/index.js";
34
+ /** The rows a calls=whole timeline page holds at most, the page size this eval reads with: learn-bench reads its steps'
35
+ * timelines the same way. */
36
+ export { CALLS_PAGE_ROWS };
34
37
  import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
35
38
  import { webFixtureOf } from "./web-fake.js";
36
39
  import { WEB_FETCH_TOOL } from "./web-fetch.js";
@@ -41,6 +44,7 @@ import { instantOf } from "./trigger-adapter.js";
41
44
  import { applyBodyOf, compiled, filledPins, filledSource, onServerName, onServers, packageView, readPackage } from "./templates.js";
42
45
  import { INPUTS_DIR } from "./uploads.js";
43
46
  import { inputIssues, inputSchemaOf, isObject, MODEL_REF } from "./validate.js";
47
+ import { RUN_FILE_CUT_MAX } from "./run-files.js";
44
48
  /** What a grader run is told, whatever the rubric: blind, strict, and its verdict as one JSON block. */
45
49
  export const GRADER_INSTRUCTIONS = `You grade one run of an AI agent against one rubric. You see the rubric, the task the agent was given, its answer, and the tool calls it made; nothing else, and nothing else matters.
46
50
 
@@ -53,8 +57,10 @@ End your reply with exactly one fenced json block and nothing after it:
53
57
  /** Each grader run's cap, in dollars. */
54
58
  export const GRADER_CAP_USD = 0.5;
55
59
  /** The most characters an llm grader's prompt takes (about 30k tokens, under GRADER_CAP_USD at $15 per million input
56
- * tokens): past it, its calls and a fake MCP server's calls share what is left, each list cut in proportion to its
57
- * size, the middle of the longest results (or arguments) first, then the middle calls (fitCalls). The rubric, the task
60
+ * tokens): past it, the final files take room first, never so much that the calls' arguments get less than half of it,
61
+ * the tool state's texts left out before a file of the run's own is cut (fitFiles); its calls and a fake MCP server's
62
+ * calls share what is left, each list cut in proportion to its size and the fake's given at least half, the middle of
63
+ * the longest results (or arguments) first, then the middle calls (fitCalls), and a <cuts> note counts it all. The rubric, the task
58
64
  * and the answer are never cut: they are what the grader judges, so a prompt can pass the cap by what they hold alone,
59
65
  * and then the calls are cut to a note that says so. */
60
66
  export const GRADER_PROMPT_MAX = 120_000;
@@ -73,7 +79,7 @@ const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning",
73
79
  const GRADER_FIELDS = {
74
80
  llm: ["type", "target"],
75
81
  regex: ["type", "pattern", "flags", "expect", "target"],
76
- tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "args"],
82
+ tool_used: ["type", "tool", "tools", "expect", "count", "at_least", "at_most", "args", "args_file"],
77
83
  file_exists: ["type", "path"],
78
84
  mailbox: ["type", "message_id", "in", "not_in"],
79
85
  handed: ["type", "expect", "dropped"],
@@ -275,14 +281,34 @@ function graderOfType(p, file, text, bad) {
275
281
  if (atLeast !== undefined && !(Number.isSafeInteger(atLeast) && atLeast >= 1))
276
282
  return bad(`${file}: at_least is a whole number of calls, 1 or more`), undefined;
277
283
  if (atLeast !== undefined && count !== undefined)
278
- return bad(`${file}: count is an exact number of calls and at_least a least one: give one, not both`), undefined;
284
+ return bad(`${file}: count is an exact number of calls and at_least a lower bound: give one, not both`), undefined;
279
285
  if (atLeast !== undefined && expect === "not_called")
280
286
  bad(`${file}: expect not_called and at_least ${atLeast} say different things`);
287
+ // at_most: that many matching calls or fewer, and at least one (expect: called, as at_least), or at least at_least
288
+ // when both are given. None is expect: not_called's to say, so at_most is 1 or more.
289
+ const atMost = data.at_most;
290
+ if (atMost !== undefined && !(Number.isSafeInteger(atMost) && atMost >= 1))
291
+ return bad(`${file}: at_most is a whole number of calls, 1 or more (for none, say expect: not_called)`), undefined;
292
+ if (atMost !== undefined && count !== undefined)
293
+ return bad(`${file}: count is an exact number of calls and at_most an upper bound: give one, not both`), undefined;
294
+ if (atMost !== undefined && expect === "not_called")
295
+ bad(`${file}: expect not_called and at_most ${atMost} say different things`);
296
+ if (atMost !== undefined && atLeast !== undefined && atLeast > atMost)
297
+ bad(`${file}: at_least ${atLeast} and at_most ${atMost} leave no number of calls to pass`);
281
298
  // Any call's arguments are known: a faked MCP tool's from its fake's log, any other's from the run's timeline read
282
- // with calls=whole (each string through the run's redaction and cut at CAPS.text).
299
+ // with calls=whole (each string through the run's redaction and cut at CALL_RESULT_CHARS).
283
300
  if (data.args !== undefined && !isObject(data.args))
284
301
  bad(`${file}: args is a mapping of the arguments a call must carry`);
285
- return { file, type, tools: tools, expect, ...(count !== undefined ? { count: count } : {}), ...(atLeast !== undefined ? { atLeast: atLeast } : {}), ...(isObject(data.args) ? { args: data.args } : {}) };
302
+ // args_file: a file the run writes, a JSON list of argument objects, each carried by its own call (the values a run
303
+ // computes, which a grader can't hold as literals). Its number of calls is the list's length, or count.
304
+ const argsFile = data.args_file;
305
+ if (argsFile !== undefined && (typeof argsFile !== "string" || !argsFile.trim() || argsFile.startsWith("/") || argsFile.split("/").includes("..")))
306
+ return bad(`${file}: args_file names a path in the run's work folder`), undefined;
307
+ if (argsFile !== undefined && expect === "not_called")
308
+ bad(`${file}: args_file lists the calls the run sends, and expect not_called says it sends none`);
309
+ if (argsFile !== undefined && (atLeast !== undefined || atMost !== undefined))
310
+ bad(`${file}: args_file's calls number its list's length (or count): at_least and at_most don't apply`);
311
+ return { file, type, tools: tools, expect, ...(count !== undefined ? { count: count } : {}), ...(atLeast !== undefined ? { atLeast: atLeast } : {}), ...(atMost !== undefined ? { atMost: atMost } : {}), ...(isObject(data.args) ? { args: data.args } : {}), ...(typeof argsFile === "string" ? { argsFile } : {}) };
286
312
  }
287
313
  case "file_exists":
288
314
  if (typeof data.path !== "string" || !data.path.trim() || data.path.startsWith("/") || data.path.split("/").includes(".."))
@@ -634,6 +660,40 @@ const same = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical
634
660
  const canonical = (value) => (Array.isArray(value) ? value.map(canonical) : isObject(value) ? Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])])) : value);
635
661
  /** Whether `call` carries `args`: each key's value equal, an object's compared as a subset in turn. */
636
662
  const carries = (call, args) => (isObject(args) ? isObject(call) && Object.entries(args).every(([key, value]) => Object.hasOwn(call, key) && carries(call[key], value)) : same(call, args));
663
+ /** What the run's cut writes in place of a secret's span in a file it serves (handed-values.ts). */
664
+ const CUT_MARK = "[redacted]";
665
+ /** Whether `text` is `entry` with each CUT_MARK standing for one character or more of it. A scan from the left, each
666
+ * part between marks placed at its first fit: linear in the text, so no list the run wrote can make it backtrack. */
667
+ const cutMatches = (text, entry) => {
668
+ const parts = entry.split(CUT_MARK);
669
+ const first = parts[0], last = parts[parts.length - 1];
670
+ if (!text.startsWith(first))
671
+ return false;
672
+ let at = first.length;
673
+ for (const part of parts.slice(1, -1)) {
674
+ const found = text.indexOf(part, at + 1);
675
+ if (found < 0)
676
+ return false;
677
+ at = found + part.length;
678
+ }
679
+ return text.length - last.length >= at + 1 && text.endsWith(last);
680
+ };
681
+ /** `same` for a value read under the run's cut: equal throughout, but a string of `entry` holding CUT_MARK is matched by
682
+ * cutMatches. Arrays and the objects inside them are whole, keys and length alike, as `same` compares them. */
683
+ const sameCut = (call, entry) => {
684
+ if (Array.isArray(entry))
685
+ return Array.isArray(call) && call.length === entry.length && entry.every((value, i) => sameCut(call[i], value));
686
+ if (isObject(entry))
687
+ return isObject(call) && Object.keys(call).length === Object.keys(entry).length && Object.entries(entry).every(([key, value]) => Object.hasOwn(call, key) && sameCut(call[key], value));
688
+ if (typeof entry === "string" && entry.includes(CUT_MARK))
689
+ return typeof call === "string" && cutMatches(call, entry);
690
+ return same(call, entry);
691
+ };
692
+ /** carries for an args_file entry, which is read under the run's cut while a fake's calls are whole: objects as subsets
693
+ * and everything else equal, as `carries`, except that a string of the entry holding CUT_MARK carries a call's string
694
+ * where each mark stands for one character or more (sameCut). So a call that sent a held secret still carries the entry
695
+ * that names it cut. Nothing of the call's value is said. */
696
+ const carriesCut = (call, entry) => isObject(entry) ? isObject(call) && Object.entries(entry).every(([key, value]) => Object.hasOwn(call, key) && carriesCut(call[key], value)) : sameCut(call, entry);
637
697
  /** Whether `fixture`'s tool answers `args` with one of its answers (the first whose `when` matches), else its default. */
638
698
  export function fakeAnswer(fixture, tool, args) {
639
699
  const spec = fixture.tools[tool];
@@ -734,17 +794,23 @@ export function gradeDeterministic(grader, run, faked) {
734
794
  return { pass, reason: pass ? `the run's work folder holds ${grader.path}` : `the run's work folder has no ${grader.path}${run.files.length ? ` (it holds ${run.files.slice(0, 10).join(", ")}${run.files.length > 10 ? ", ..." : ""})` : " (it holds no file)"}` };
735
795
  }
736
796
  case "tool_used": {
737
- // A faked MCP tool's calls are its fake's log (each call that reached it, whole); any other tool's, the timeline's,
738
- // its arguments as the run's redaction shows them (callsOf).
797
+ // A faked MCP tool's calls are its fake's log (each call that reached it, whole: fakeLog, never shown); any other
798
+ // tool's, the timeline's, its arguments as the run's redaction shows them (callsOf).
739
799
  const calls = grader.tools.flatMap((tool) => {
740
800
  const server = mcpNameOf(tool)?.server;
741
- const from = server !== undefined && faked.includes(server) ? run.mcpCalls : run.calls;
801
+ const from = server !== undefined && faked.includes(server) ? run.fakeLog : run.calls;
742
802
  return from.filter((call) => call.tool === tool && (!grader.args || carries(call.arguments, grader.args)));
743
803
  });
744
804
  const what = `${grader.tools.join(" or ")}${grader.args ? ` with ${JSON.stringify(grader.args)}` : ""}`;
745
805
  const said = `${calls.length} call${calls.length === 1 ? "" : "s"} of ${what}`;
806
+ if (grader.argsFile !== undefined)
807
+ return argsFileVerdict(grader.argsFile, run.argsFiles?.[grader.argsFile], calls, said, grader.count);
746
808
  if (grader.count !== undefined)
747
809
  return { pass: calls.length === grader.count, reason: `${said}; the grader expects exactly ${grader.count}` };
810
+ if (grader.atMost !== undefined) {
811
+ const least = grader.atLeast ?? 1;
812
+ return { pass: calls.length >= least && calls.length <= grader.atMost, reason: `${said}; the grader expects at least ${grader.atLeast ?? "one"} and at most ${grader.atMost}` };
813
+ }
748
814
  if (grader.atLeast !== undefined)
749
815
  return { pass: calls.length >= grader.atLeast, reason: `${said}; the grader expects at least ${grader.atLeast}` };
750
816
  const pass = grader.expect === "called" ? calls.length > 0 : calls.length === 0;
@@ -756,6 +822,49 @@ export function gradeDeterministic(grader, run, faked) {
756
822
  return handedVerdict(run.handed, grader.expect, grader.dropped);
757
823
  }
758
824
  }
825
+ /** A tool_used grader's verdict on its args_file: each listed argument object carried (carries) by its own call of
826
+ * `calls` (the grader's tools, its `args` kept), no call standing for two entries, and as many calls as the list has
827
+ * entries (or `count`). The entries are given calls by a maximum matching, so one call that carries two entries counts
828
+ * for one of them, whatever order they are listed in. */
829
+ export function argsFileVerdict(path, file, calls, said, count) {
830
+ if (file === undefined || "why" in file)
831
+ return { pass: false, reason: `the run's ${path} could not be read${file ? `: ${file.why}` : ""}` };
832
+ let entries;
833
+ try {
834
+ entries = JSON.parse(file.text);
835
+ }
836
+ catch (error) {
837
+ return { pass: false, reason: `the run's ${path} is not JSON: ${error.message}` };
838
+ }
839
+ if (!Array.isArray(entries))
840
+ return { pass: false, reason: `the run's ${path} is not a list of argument objects` };
841
+ const odd = entries.findIndex((entry) => !isObject(entry));
842
+ if (odd >= 0)
843
+ return { pass: false, reason: `entry ${odd + 1} of the run's ${path} is not an argument object` };
844
+ // Kuhn's augmenting paths: owner[c] is the entry call c stands for.
845
+ const carriers = entries.map((entry) => calls.flatMap((call, c) => (carriesCut(call.arguments, entry) ? [c] : [])));
846
+ const owner = new Array(calls.length).fill(-1);
847
+ const give = (e, seen) => carriers[e].some((c) => {
848
+ if (seen.has(c))
849
+ return false;
850
+ seen.add(c);
851
+ if (owner[c] === -1 || give(owner[c], seen))
852
+ return (owner[c] = e), true;
853
+ return false;
854
+ });
855
+ const unmatched = entries.flatMap((_, e) => (give(e, new Set()) ? [] : [e]));
856
+ const head = (e) => { const text = JSON.stringify(entries[e]); return text.length > 200 ? `${text.slice(0, 200)}...` : text; };
857
+ if (unmatched.length) {
858
+ const e = unmatched[0];
859
+ const why = carriers[e].length ? `every call that carries it stands for another entry` : `no call carries it`;
860
+ return { pass: false, reason: `${said}; ${unmatched.length} of the ${entries.length} entries in the run's ${path} have no call of their own: entry ${e + 1} (${head(e)}): ${why}` };
861
+ }
862
+ const expected = count ?? entries.length;
863
+ const each = `each of the ${entries.length} entries in the run's ${path} is carried by its own call`;
864
+ if (calls.length !== expected)
865
+ return { pass: false, reason: `${said}; ${each}, and the grader expects exactly ${expected} call${expected === 1 ? "" : "s"}` };
866
+ return { pass: true, reason: `${said}; ${each}` };
867
+ }
759
868
  /** The output check of a completed run of a package that declares `output`, beside its case's graders: the server's own
760
869
  * verdict (`result.output_error`, why the answer still missed the schema after the runner's one retry), so no case
761
870
  * carries a grader for it. Undefined for a package with no output schema. */
@@ -782,37 +891,156 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
782
891
  ...(run.mailbox ? [`<mailbox-after untrusted>\nThe run's email account was a fake mailbox (layout ${run.mailbox.after.layout}). What the run left in it:\n${mailboxText(run.mailbox.after)}\n</mailbox-after>`] : []),
783
892
  ];
784
893
  // The files the run left, ahead of its calls. A call shows a file's bytes only in its arguments or its output, each cut
785
- // where the timeline cuts it (a string of its arguments at 2,000 characters, its output at CALL_RESULT_CHARS, each
786
- // ending "..."), and a cut call reads to a grader as a run that did less than its file holds.
894
+ // where the timeline cuts it (its arguments' names and values at CALL_RESULT_CHARS in all, its output at as many), and
895
+ // a cut call reads to a grader as a run that did less than its file holds.
787
896
  const files = run.finalFiles ?? [];
788
897
  const texts = files.filter((file) => file.text !== undefined);
789
898
  // Each call with its arguments (else its input's preview), its status and its output's head; a call that names a file
790
- // shown whole says where it is.
791
- const lines = run.calls.map((call, i) => {
792
- const head = `${i + 1}. ${call.tool}${call.arguments ? ` ${JSON.stringify(call.arguments)}` : call.preview ? ` (${call.preview})` : ""}${call.status ? ` -> ${call.status}` : ""}`;
899
+ // says where it is. A string argument `held` names (a write's content that a file's text holds whole and whose head
900
+ // and tail <files> shows: shows) is cut at FILE_ARG_CHARS there, so the grader's room never holds those bytes twice.
901
+ const callsOf = (held, shown = () => true) => run.calls.map((call, i) => {
902
+ const args = call.arguments ? JSON.stringify(inFiles(call.arguments, held)) : undefined;
903
+ const tail = call.status ? ` -> ${call.status}` : "";
793
904
  const result = call.result ?? "";
794
- const named = texts.flatMap((file) => (file.name !== undefined && (head.includes(file.name) || result.includes(file.name)) ? [file.name] : [])).sort((a, b) => b.length - a.length)[0];
795
- return { head: named ? `${head} [the file ${named} is in <files>, whole unless marked cut]` : head, result, tool: call.name ?? call.tool };
905
+ const whole = `${i + 1}. ${call.tool}${args !== undefined ? ` ${args}` : call.preview ? ` (${call.preview})` : ""}${tail}`;
906
+ const named = texts.flatMap((file) => (file.name !== undefined && shown(file.name) && (whole.includes(file.name) || result.includes(file.name)) ? [file.name] : [])).sort((a, b) => b.length - a.length)[0];
907
+ const pointer = named ? ` [the file ${named} is in <files>, whole unless marked cut]` : "";
908
+ const head = (shown) => `${i + 1}. ${call.tool}${shown !== undefined ? ` ${shown}` : call.preview ? ` (${call.preview})` : ""}${tail}${pointer}`;
909
+ return { args, head, result, tool: call.name ?? call.tool };
796
910
  });
797
- // Each call a fake MCP server received, its arguments whole in its log: they are the part a cut may take.
798
- const mcpLines = run.mcpCalls.map((call, i) => ({ head: `${i + 1}. ${call.tool}`, result: JSON.stringify(call.arguments ?? {}) }));
911
+ const linesOf = (list) => list.map((call) => ({ head: call.head(call.args), result: call.result, tool: call.tool }));
912
+ // Each call a fake MCP server received, its arguments as the run's timeline shows them (RunRecord.mcpCalls, under the
913
+ // run's cut; never the fake's own log): they are the part a cut of this prompt may take.
914
+ const mcpLines = run.mcpCalls.map((call, i) => ({ head: `${i + 1}. ${call.tool}`, result: call.arguments !== undefined ? JSON.stringify(call.arguments) : (call.preview ?? "{}") }));
799
915
  const wrap = (text) => `<tool-calls untrusted>\n${text}\n</tool-calls>`;
800
916
  const wrapMcp = (text) => `<mcp-calls untrusted>\nThe calls the MCP servers received, with their arguments, in order:\n${text}\n</mcp-calls>`;
801
917
  // A run that searched or fetched: each link its answer cites, matched against its web calls' urls in code (link-check.ts).
802
918
  const links = linkCheck(run.answer, run.calls);
803
919
  const linked = links === undefined ? [] : [`<link-check untrusted>\n${links}\n</link-check>`];
804
920
  const wrapFiles = (text) => `<files untrusted>\nThe files in the run's work folder when it ended, each text file whole unless marked cut (a call below that shows one only in part shows a cut of it):\n${text}\n</files>`;
805
- const room = max - [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : []), ...(files.length ? [wrapFiles("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
806
921
  const wholeOf = (list) => list.reduce((sum, one) => sum + one.head.length + one.result.length + 3, 0);
807
- const [callsWhole, mcpWhole] = [wholeOf(lines), wholeOf(mcpLines)];
808
- // The files come first: they take what they need of the room, but no more than leaves the calls a quarter of it (or
809
- // all they need, when that is less), so a call's result is cut before a file is.
810
- const shownFiles = files.length ? fitFiles(files, Math.max(0, room - Math.min(callsWhole + mcpWhole, Math.floor(room / 4)))) : undefined;
811
- // Both call lists share the room the rest leave, each in proportion to its whole size.
812
- const left = room - (shownFiles === undefined ? 0 : shownFiles.length);
813
- const mcpRoom = callsWhole + mcpWhole <= left ? mcpWhole : Math.floor((left * mcpWhole) / Math.max(1, callsWhole + mcpWhole));
814
- const after = mcpLines.length ? [wrapMcp(fitCalls(mcpLines, mcpRoom, "argument list"))] : [];
815
- return [...before, ...(shownFiles === undefined ? [] : [wrapFiles(shownFiles)]), wrap(lines.length ? fitCalls(lines, left - mcpRoom) : "(none)"), ...linked, ...after].join("\n\n");
922
+ const headsOf = (list) => list.reduce((sum, one) => sum + one.head.length + 1, 0);
923
+ const mcpWhole = wholeOf(mcpLines);
924
+ const fixed = [...before, wrap(""), ...linked, ...(mcpLines.length ? [wrapMcp("")] : []), ...(files.length ? [wrapFiles("")] : [])].reduce((sum, part) => sum + part.length + 2, 0);
925
+ // A prompt that is cut says what was (cutsNote), at the top of the evidence, in room it keeps for that note: built once
926
+ // to count the cuts, then again with room for the note they make (a few characters more, for counts that grow).
927
+ const whole = fixed + (files.length ? fitFiles(files, Number.MAX_SAFE_INTEGER).length : 0) + wholeOf(linesOf(callsOf(() => false))) + mcpWhole;
928
+ if (whole <= max)
929
+ return build(0).text;
930
+ const first = build(0);
931
+ // Under a cap so tight the note would take more than a twentieth of it, the marks each cut leaves in place say it: the
932
+ // room goes to the evidence (a web call's url list before a summary of what was cut).
933
+ if (first.note === undefined)
934
+ return first.text;
935
+ if (first.note.length > max / 20)
936
+ return build(0, false).text;
937
+ const second = build(first.note.length + 2 + 24);
938
+ return second.text.length <= max ? second.text : build(CUTS_NOTE_ROOM + 2).text;
939
+ function build(reserve, noted = true) {
940
+ const room = max - fixed - reserve;
941
+ // The files come first: they take what they need of the room, but no more than leaves the calls a quarter of it (or
942
+ // all they need, when that is less), so a call's result is cut before a file is; and never more than leaves the calls'
943
+ // arguments half of it (or all they need): what a run sent is what a rubric checks, a file it can hold too. What the
944
+ // calls need counts each argument a file's text holds whole cut, as it is when <files> shows that file whole.
945
+ const inText = (text) => texts.some((file) => file.text !== undefined && file.text.includes(bareOf(text)));
946
+ const needLines = linesOf(callsOf(inText));
947
+ const need = wholeOf(needLines);
948
+ const argsFloor = Math.min(headsOf(needLines) + mcpWhole, Math.floor(room / 2));
949
+ const fittedFiles = files.length ? fitFilesWith(files, Math.max(0, room - Math.max(Math.min(need + mcpWhole, Math.floor(room / 4)), argsFloor))) : undefined;
950
+ const shownFiles = fittedFiles?.text;
951
+ const showing = (name) => shownFiles !== undefined && shownFiles.includes(`<file path="${name}" `);
952
+ // An argument is cut only when a file's text holds all of it and <files> as shown shows its head and tail. A write of a
953
+ // whole file <files> shows cut is cut at FILE_ARG_CHARS: its head and tail are in <files>, and its middle is cut in
954
+ // both, as the file's block marks. One whose text the cut of its file takes from there (an append in its middle, or a
955
+ // first write the appends after it push past the shown head) stays in its call, cut as fitArgs cuts it, as does a
956
+ // write a later one overwrote that shares the file's head and tail.
957
+ const calls = callsOf((text) => inText(text) && shownFiles !== undefined && shows(shownFiles, text), showing);
958
+ const lines = linesOf(calls);
959
+ const callsWhole = wholeOf(lines);
960
+ // Both call lists share the room the rest leave, each in proportion to its whole size; and the fake MCP servers' list,
961
+ // which is its calls' arguments, gets at least half of it (or all it needs), as the timeline's arguments do of theirs
962
+ // (fitArgs): a timeline's long results never take what a run sent to a fake down to a few characters each.
963
+ const left = room - (shownFiles === undefined ? 0 : shownFiles.length);
964
+ const mcpRoom = callsWhole + mcpWhole <= left ? mcpWhole : Math.max(Math.floor((left * mcpWhole) / Math.max(1, callsWhole + mcpWhole)), Math.min(mcpWhole, Math.floor(left / 2)));
965
+ const mcpFit = mcpLines.length ? fitCallsWith(mcpLines, mcpRoom, "argument list") : undefined;
966
+ // The calls' arguments take what the rest of the calls' lines (their heads' other parts and their results) leave of
967
+ // the calls' room, and when that is less than half of it, half (fitArgs): whole when the calls fit, and a call with
968
+ // long arguments never leaves the others without their results.
969
+ const callsRoom = left - mcpRoom;
970
+ const rest = callsWhole - calls.reduce((sum, call) => sum + (call.args?.length ?? 0), 0);
971
+ const kept = fitArgs(calls.map((call) => call.args), Math.max(Math.floor(callsRoom / 2), callsRoom - rest));
972
+ const fitted = kept === undefined ? lines : calls.map((call, i) => ({ head: call.head(kept[i]), result: call.result, tool: call.tool }));
973
+ const callsFit = fitted.length ? fitCallsWith(fitted, callsRoom) : undefined;
974
+ const note = cutsNote({
975
+ files: fittedFiles,
976
+ calls: callsFit && { args: kept === undefined ? 0 : kept.filter((shown, i) => shown !== calls[i].args).length, results: callsFit.cut, dropped: callsFit.dropped },
977
+ mcp: mcpFit && { args: mcpFit.cut, dropped: mcpFit.dropped },
978
+ });
979
+ return { text: [...before, ...(note && noted ? [note] : []), ...(shownFiles === undefined ? [] : [wrapFiles(shownFiles)]), wrap(callsFit ? callsFit.text : "(none)"), ...linked, ...(mcpFit ? [wrapMcp(mcpFit.text)] : [])].join("\n\n"), note };
980
+ }
981
+ }
982
+ /** The most characters the note on what a grader's input cut takes (cutsNote). */
983
+ const CUTS_NOTE_ROOM = 900;
984
+ /** What a grader's input cut, said once ahead of the evidence, so a grader reads a condition only the cut part could show
985
+ * as unseen, never as consistent: each list's cuts, counted. Undefined when nothing was cut. */
986
+ function cutsNote(cut) {
987
+ const n = (count, one) => `${count} ${count === 1 ? one : `${one}s`}`;
988
+ const of = (count, one) => `${count} ${count === 1 ? `${one}'s` : `${one}s'`}`;
989
+ const lines = [
990
+ ...(cut.files && (cut.files.cut || cut.files.out || cut.files.state) ? [`- <files>: ${[cut.files.state ? `${n(cut.files.state, "file")} of tool state (under a folder whose name starts with ".") listed by name alone` : "", cut.files.cut ? `${of(cut.files.cut, "file")} text cut in the middle` : "", cut.files.out ? `${of(cut.files.out, "file")} text left out` : ""].filter(Boolean).join("; ")}.`] : []),
991
+ ...(cut.calls && (cut.calls.args || cut.calls.results || cut.calls.dropped) ? [`- <tool-calls>: ${[cut.calls.args ? `${of(cut.calls.args, "call")} arguments cut in the middle` : "", cut.calls.results ? `${n(cut.calls.results, "result")} cut or left out` : "", cut.calls.dropped ? `${n(cut.calls.dropped, "call")} in the middle left out` : ""].filter(Boolean).join("; ")}.`] : []),
992
+ ...(cut.mcp && (cut.mcp.args || cut.mcp.dropped) ? [`- <mcp-calls>: ${[cut.mcp.args ? `${of(cut.mcp.args, "call")} arguments cut or left out` : "", cut.mcp.dropped ? `${n(cut.mcp.dropped, "call")} in the middle left out` : ""].filter(Boolean).join("; ")}.`] : []),
993
+ ];
994
+ if (!lines.length)
995
+ return undefined;
996
+ return ["<cuts>", "This input is cut to stay under its cap; each cut is marked where it is:", ...lines, "What a cut leaves out was not seen: a condition only it could show is not shown to hold.", "</cuts>"].join("\n");
997
+ }
998
+ /** How much of a write's content a grader's call line shows when a file in <files> holds it whole. */
999
+ const FILE_ARG_CHARS = 2000;
1000
+ /** A call's copy of a text with the trailing "..." where the timeline cut it at its budget left off. */
1001
+ function bareOf(text) {
1002
+ return text.endsWith("...") ? text.slice(0, -3) : text;
1003
+ }
1004
+ /** Whether `where` shows the first and last FILE_ARG_CHARS characters of a call's copy of `text` (bareOf). */
1005
+ function shows(where, text) {
1006
+ const bare = bareOf(text);
1007
+ return where.includes(bare.slice(0, FILE_ARG_CHARS)) && where.includes(bare.slice(-FILE_ARG_CHARS));
1008
+ }
1009
+ /** A call's arguments with each string past FILE_ARG_CHARS that `held` names (one a file holds and <files> shows) cut there,
1010
+ * ending "...", in a list or an object at any depth. */
1011
+ function inFiles(value, held) {
1012
+ if (typeof value === "string")
1013
+ return value.length > FILE_ARG_CHARS && held(value) ? `${value.slice(0, FILE_ARG_CHARS - 3)}...` : value;
1014
+ if (Array.isArray(value))
1015
+ return value.map((item) => inFiles(item, held));
1016
+ if (!value || typeof value !== "object")
1017
+ return value;
1018
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inFiles(item, held)]));
1019
+ }
1020
+ /** Each call's arguments (their JSON, none for a call with none) in at most `room` characters in all: undefined when they
1021
+ * fit whole; else each past a length L keeps its first two thirds and last third of L with its middle cut and marked
1022
+ * (middle), L the longest that fits, so the longest are cut first. A list no longer than L and a marker (40 characters)
1023
+ * stays whole, so a cut never takes a short list's text for a marker as long; when even L = 0 passes the room, the
1024
+ * short lists stay whole, the long ones show their marker alone, and fitCalls drops calls as it does. */
1025
+ export function fitArgs(args, room) {
1026
+ const cuts = (text, keep) => text.length > keep + 40;
1027
+ const sizeOf = (keep) => args.reduce((sum, text) => sum + (text === undefined ? 0 : cuts(text, keep) ? keep + 40 : text.length), 0);
1028
+ if (sizeOf(Number.MAX_SAFE_INTEGER) <= room)
1029
+ return undefined;
1030
+ const keep = longestKeep(sizeOf, Math.max(0, ...args.map((text) => text?.length ?? 0)), room);
1031
+ return args.map((text) => (text !== undefined && cuts(text, keep) ? middle(text, keep) : text));
1032
+ }
1033
+ /** The longest keep in [0, high] whose `size` is within `room`, else 0: `size` never falls as keep grows. */
1034
+ function longestKeep(size, high, room) {
1035
+ let [low, top] = [0, high];
1036
+ while (low < top) {
1037
+ const mid = Math.ceil((low + top) / 2);
1038
+ if (size(mid) <= room)
1039
+ low = mid;
1040
+ else
1041
+ top = mid - 1;
1042
+ }
1043
+ return low;
816
1044
  }
817
1045
  /** A grader's calls, one line each (`head`, then `: <result>`), in at most `room` characters: whole when they fit; else
818
1046
  * each result past a length L keeps its first two thirds and last third of L with its middle cut and marked, L the
@@ -822,10 +1050,16 @@ export function graderInput(grader, input, run, max = GRADER_PROMPT_MAX) {
822
1050
  * cut says so on the list's first line, so the grader knows what it does not see; `what` names what follows each head
823
1051
  * there (a fake MCP server's list cuts a call's arguments). */
824
1052
  export function fitCalls(lines, room, what = "result") {
1053
+ return fitCallsWith(lines, room, what).text;
1054
+ }
1055
+ /** fitCalls, with how many results it cut or left out (`cut`) and how many calls it dropped (`dropped`), for the note on
1056
+ * what a grader's input cut (cutsNote). */
1057
+ function fitCallsWith(lines, room, what = "result") {
825
1058
  const line = (head, result) => (result ? `${head}: ${result}` : head);
826
1059
  const whole = lines.map((one) => line(one.head, one.result)).join("\n");
827
1060
  if (whole.length <= room)
828
- return whole;
1061
+ return { text: whole, cut: 0, dropped: 0 };
1062
+ const results = lines.filter((one) => one.result).length;
829
1063
  const said = saidCut;
830
1064
  const webs = lines.map((one) => (one.tool ? webShownOf(one.tool, one.result) : undefined));
831
1065
  const LONG = said(`each long ${what} keeps its head and tail, its middle cut where marked${webs.some(Boolean) ? "; a web_search keeps every result's url, title and date, and a web_fetch its url and title, their snippets and page text cut" : ""}`);
@@ -833,22 +1067,12 @@ export function fitCalls(lines, room, what = "result") {
833
1067
  // on every result `keep` cuts.
834
1068
  const cutTo = (text, keep) => (text.length > keep ? keep + 42 : text ? text.length + 2 : 0);
835
1069
  const high = Math.max(...lines.map((one) => one.result.length));
836
- const longest = (size) => {
837
- let [low, top] = [0, high];
838
- while (low < top) {
839
- const mid = Math.ceil((low + top) / 2);
840
- if (size(mid) <= room)
841
- low = mid;
842
- else
843
- top = mid - 1;
844
- }
845
- return low;
846
- };
1070
+ const longest = (size) => longestKeep(size, high, room);
847
1071
  // A web call's line is measured as it is shown.
848
1072
  const size = (keep) => LONG.length + 1 + lines.reduce((sum, one, i) => sum + (webs[i] ? line(one.head, webs[i](keep)).length : one.head.length + cutTo(one.result, keep)) + 1, 0);
849
1073
  if (size(0) <= room) {
850
1074
  const keep = longest(size);
851
- return [LONG, ...lines.map((one, i) => line(one.head, webs[i] ? webs[i](keep) : middle(one.result, keep)))].join("\n");
1075
+ return { text: [LONG, ...lines.map((one, i) => line(one.head, webs[i] ? webs[i](keep) : middle(one.result, keep)))].join("\n"), cut: lines.filter((one) => one.result.length > keep).length, dropped: 0 };
852
1076
  }
853
1077
  // The web calls' url lists alone pass the room: every other result is left out, and each list keeps its head and tail.
854
1078
  if (webs.some(Boolean)) {
@@ -857,7 +1081,7 @@ export function fitCalls(lines, room, what = "result") {
857
1081
  const over = (keep) => OVER.length + 1 + lines.reduce((sum, one, i) => sum + one.head.length + cutTo(lists[i], keep) + 1, 0);
858
1082
  if (over(0) <= room) {
859
1083
  const keep = longest(over);
860
- return [OVER, ...lines.map((one, i) => line(one.head, lists[i] ? middle(lists[i], keep) : ""))].join("\n");
1084
+ return { text: [OVER, ...lines.map((one, i) => line(one.head, lists[i] ? middle(lists[i], keep) : ""))].join("\n"), cut: results, dropped: 0 };
861
1085
  }
862
1086
  }
863
1087
  // Not even every call's head fits: the first and last calls, as many as fit, with no result, the middle ones dropped.
@@ -875,7 +1099,9 @@ export function fitCalls(lines, room, what = "result") {
875
1099
  kept[1].unshift(heads[j--]);
876
1100
  }
877
1101
  const dropped = heads.length - kept[0].length - kept[1].length;
878
- return [said(`every ${what} is left out, and ${dropped} call${dropped === 1 ? "" : "s"} in the middle`), ...kept[0], `[... ${dropped} call${dropped === 1 ? "" : "s"} cut ...]`, ...kept[1]].join("\n");
1102
+ if (!dropped)
1103
+ return { text: [said(`every ${what} is left out`), ...kept[0], ...kept[1]].join("\n"), cut: results, dropped };
1104
+ return { text: [said(`every ${what} is left out, and ${dropped} call${dropped === 1 ? "" : "s"} in the middle`), ...kept[0], `[... ${dropped} call${dropped === 1 ? "" : "s"} cut ...]`, ...kept[1]].join("\n"), cut: results, dropped };
879
1105
  }
880
1106
  /** A cut's note, on the first line of what it cut. */
881
1107
  const saidCut = (cut) => `(Cut to keep this prompt under its cap: ${cut}.)`;
@@ -894,28 +1120,38 @@ function middle(text, keep) {
894
1120
  * its size on a last line, cut to the room when even that passes it. Each file is named by its cut name alone: one with
895
1121
  * none is in a block with no path, or counted. */
896
1122
  export function fitFiles(files, room) {
1123
+ return fitFilesWith(files, room).text;
1124
+ }
1125
+ /** Whether a final file is a tool's state, not the run's work: under a folder whose name starts with "." (the package's
1126
+ * own skills copied under `.agents/skills`, a tool's cache such as `film/.hyperframes`). A file with no name is not. */
1127
+ export function toolState(name) {
1128
+ return name !== undefined && name.split("/").slice(0, -1).some((part) => part.startsWith("."));
1129
+ }
1130
+ /** fitFiles, with how many texts it cut in the middle (`cut`) or left out (`out`), and how many of tool state (toolState)
1131
+ * it listed by name alone (`state`), for the note on what a grader's input cut (cutsNote). A run's own files come first:
1132
+ * past the room, the tool state's texts are left out before any other file is cut. */
1133
+ function fitFilesWith(files, room) {
897
1134
  const block = (file, text) => `<file${file.name === undefined ? "" : ` path="${file.name}"`} bytes="${file.bytes}">\n${text}\n</file>`;
898
- const texts = files.filter((file) => file.text !== undefined);
1135
+ const all = files.filter((file) => file.text !== undefined);
899
1136
  const others = files.filter((file) => file.text === undefined);
900
1137
  const named = others.length ? [`Not shown (not text, or past what a grader is given), by path and size in bytes: ${namesOf(others)}`] : [];
901
- const whole = [...texts.map((file) => block(file, file.text)), ...named].join("\n");
1138
+ const whole = [...all.map((file) => block(file, file.text)), ...named].join("\n");
902
1139
  if (whole.length <= room)
903
- return whole;
1140
+ return { text: whole, cut: 0, out: 0, state: 0 };
1141
+ const state = all.filter((file) => toolState(file.name));
1142
+ const texts = all.filter((file) => !toolState(file.name));
1143
+ const listed = [...named, ...(state.length ? [`Not shown (tool state: under a folder whose name starts with ".", left out before any file of the run's own is cut), by path and size in bytes: ${namesOf(state)}`] : [])];
1144
+ const own = [...texts.map((file) => block(file, file.text)), ...listed].join("\n");
1145
+ if (own.length <= room)
1146
+ return { text: own, cut: 0, out: 0, state: state.length };
904
1147
  const LONG = saidCut("each long file keeps its head and tail, its middle cut where marked");
905
- const size = (keep) => LONG.length + 1 + texts.reduce((sum, file) => sum + block(file, "").length + (file.text.length <= keep ? file.text.length : keep + 40) + 1, 0) + named.reduce((sum, line) => sum + line.length, 0);
1148
+ const size = (keep) => LONG.length + 1 + texts.reduce((sum, file) => sum + block(file, "").length + (file.text.length <= keep ? file.text.length : keep + 40) + 1, 0) + listed.reduce((sum, line) => sum + line.length + 1, 0);
906
1149
  if (texts.length && size(0) <= room) {
907
- let [low, top] = [0, Math.max(...texts.map((file) => file.text.length))];
908
- while (low < top) {
909
- const mid = Math.ceil((low + top) / 2);
910
- if (size(mid) <= room)
911
- low = mid;
912
- else
913
- top = mid - 1;
914
- }
915
- return [LONG, ...texts.map((file) => block(file, middle(file.text, low))), ...named].join("\n");
1150
+ const keep = longestKeep(size, Math.max(...texts.map((file) => file.text.length)), room);
1151
+ return { text: [LONG, ...texts.map((file) => block(file, middle(file.text, keep))), ...listed].join("\n"), cut: texts.filter((file) => file.text.length > keep).length, out: 0, state: state.length };
916
1152
  }
917
1153
  const list = [saidCut("every file's text is left out"), `By path and size in bytes: ${namesOf(files)}`].join("\n");
918
- return list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)} ...`;
1154
+ return { text: list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)} ...`, cut: 0, out: all.length, state: 0 };
919
1155
  }
920
1156
  /** Files by their cut names and sizes, "a.mp4 (9000000), b.txt (5)", and those with no name counted after them: a file is
921
1157
  * never named to a grader by anything but its cut name. */
@@ -943,7 +1179,8 @@ export function verdictOf(answer) {
943
1179
  return undefined;
944
1180
  }
945
1181
  /** A fake MCP server for `fixture` on loopback, Streamable HTTP through the official SDK, one stateless server per
946
- * request; every tool call is recorded (its gate name and arguments) and answered from the fixture. */
1182
+ * request; every tool call is recorded (its gate name and arguments) and answered from the fixture as it is written, so
1183
+ * the agent and a script it runs read the answer a real server of that shape gives (a JSON text parses as JSON). */
947
1184
  export async function startFake(name, fixture) {
948
1185
  const { createMcpHandler, fromJsonSchema, McpServer } = await import("@modelcontextprotocol/server").catch((error) => {
949
1186
  throw new Error(`a case with an mcp fixture needs @modelcontextprotocol/server installed beside agentrun-serve: ${error.message}`);
@@ -1128,6 +1365,11 @@ export async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUE
1128
1365
  const waiting = rows.findLast((row) => row.kind === "waiting");
1129
1366
  return { status, rows, waiting: typeof waiting?.summary === "string" ? waiting.summary : "it waits on a person" };
1130
1367
  }
1368
+ // A page that isn't queued shows a runner took the run: a later queued page starts no lapse from before it.
1369
+ if (status !== "queued") {
1370
+ everHeld = true;
1371
+ unheldSince = undefined;
1372
+ }
1131
1373
  if (status === "queued" && (everHeld || Date.now() - started > queueTimeoutMs) && Date.now() - askedAt >= CLAIM_READ_EVERY_MS) {
1132
1374
  askedAt = Date.now();
1133
1375
  const held = await heldNow(api, runId, deadline, signal);
@@ -1158,11 +1400,27 @@ export async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUE
1158
1400
  await sleep(250);
1159
1401
  }
1160
1402
  }
1403
+ /** The calls on the faked MCP servers `faked` that ran, as the run's timeline shows them (`calls`, from callsOf: each
1404
+ * argument through the run's redaction): each call on a faked server's tool the run did not refuse before it ran and
1405
+ * whose result row the timeline holds. A call refused (a deny, a cap, an approval never given) never reached the fake,
1406
+ * and one with no result (cut off) has no outcome to show. One that failed on its way to the fake shows, with its
1407
+ * error as its result, never as a success; a tool_used grader counts only what the fake logged (fakeLog). What an llm
1408
+ * grader's <mcp-calls> and the report's `mcp_calls` show, never the fake's own log. */
1409
+ export function mcpCallsOf(calls, faked) {
1410
+ return calls.filter((call) => !call.refused && call.status != null && faked.includes(mcpNameOf(call.tool)?.server ?? ""));
1411
+ }
1412
+ /** A run's calls for its graders and its report, from its timeline's (callsOf) and the fakes it ran against: its calls,
1413
+ * its fake MCP calls (mcpCallsOf) and the fakes' own log whole. The template eval's runs and learn-bench's steps both
1414
+ * read them here. */
1415
+ export function callRecordOf(calls, faked, fakes) {
1416
+ return { calls: [...calls], mcpCalls: mcpCallsOf(calls, faked), fakeLog: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))) };
1417
+ }
1161
1418
  /** A run's tool calls, each named as a grader names it: the gate's own rule (RunGate.enter), its settings key, but a
1162
1419
  * shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
1163
1420
  * call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
1164
1421
  * under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
1165
- * its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
1422
+ * its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews, and
1423
+ * `refused` when its result row says the run refused it before it ran (a deny, a pin, an approval never given). */
1166
1424
  export function callsOf(rows, harness, toolkits = {}) {
1167
1425
  const results = new Map(rows.filter((row) => row.kind === "tool_result" && row.tool_use_id).map((row) => [String(row.tool_use_id), row]));
1168
1426
  // The rows are a server's, read over its API: the names are the built-in harness's, the only facts known here.
@@ -1172,7 +1430,7 @@ export function callsOf(rows, harness, toolkits = {}) {
1172
1430
  const result = results.get(String(row.tool_use_id));
1173
1431
  const key = settingsKeyOf(harness, name, names);
1174
1432
  const output = typeof result?.tool_result_text === "string" ? result.tool_result_text : (result?.tool_result_preview ?? null);
1175
- return { tool: shellToolOf(name) ?? (key === undefined ? undefined : onServerName(key, toolkits)) ?? name, name, preview: row.tool_input_preview ?? null, ...(isObject(row.tool_input) ? { arguments: row.tool_input } : {}), status: result?.tool_status ?? null, result: output };
1433
+ return { tool: shellToolOf(name) ?? (key === undefined ? undefined : onServerName(key, toolkits)) ?? name, name, preview: row.tool_input_preview ?? null, ...(isObject(row.tool_input) ? { arguments: row.tool_input } : {}), status: result?.tool_status ?? null, result: output, ...(result?.refused === true ? { refused: true } : {}) };
1176
1434
  });
1177
1435
  }
1178
1436
  /** Every file of a run's work folder (the files route, page by page), each with its name under the run's cut (`?cut=run`). */
@@ -1202,7 +1460,7 @@ export const FILE_READ_TIMEOUT_MS = 10_000;
1202
1460
  export const FILE_READS_TIMEOUT_MS = 30_000;
1203
1461
  /** A run's final files for its llm graders: each text file's whole text, read smallest first while the texts read stay
1204
1462
  * within GRADER_PROMPT_MAX UTF-8 bytes in all (one grader input holds that many characters, and a character is at least
1205
- * a byte), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
1463
+ * a byte), the run's own files before any of tool state (toolState), every other file by its size alone. Each is read under the run's own cut, on the server that holds its
1206
1464
  * secrets (`?cut=run`, run-reads-over-store.ts cutRunFile): every value its timeline's calls are cut of, and every secret
1207
1465
  * shape, is "[redacted]" in the text a grader sees. An answer without the cut's mark (`x-agentrun-cut: run`: a server
1208
1466
  * that doesn't know the cut and would serve the raw bytes) leaves the text out. A read that fails, is refused (403, 413,
@@ -1212,7 +1470,7 @@ export async function finalFilesOf(api, runId, listed, signal, readTimeoutMs = F
1212
1470
  const texts = new Map();
1213
1471
  let left = GRADER_PROMPT_MAX;
1214
1472
  const until = Date.now() + Math.max(FILE_READS_TIMEOUT_MS, readTimeoutMs);
1215
- for (const file of [...listed].filter((one) => !one.unreadable && (one.type === null || TEXT_TYPE.test(one.type))).sort((a, b) => a.bytes - b.bytes)) {
1473
+ for (const file of [...listed].filter((one) => !one.unreadable && (one.type === null || TEXT_TYPE.test(one.type))).sort((a, b) => Number(toolState(a.path)) - Number(toolState(b.path)) || a.bytes - b.bytes)) {
1216
1474
  if (file.bytes > left)
1217
1475
  continue;
1218
1476
  signal?.throwIfAborted();
@@ -1236,6 +1494,38 @@ export async function finalFilesOf(api, runId, listed, signal, readTimeoutMs = F
1236
1494
  // Each by its cut name alone: its path is for the reads above, never a grader.
1237
1495
  return listed.map((file) => ({ ...(file.name !== undefined ? { name: file.name } : {}), bytes: file.bytes, ...(texts.has(file.path) ? { text: texts.get(file.path) } : {}) }));
1238
1496
  }
1497
+ /** The most bytes of an args_file a tool_used grader reads: the most a cut read answers (run-files.ts). */
1498
+ export const ARGS_FILE_MAX = RUN_FILE_CUT_MAX;
1499
+ /** Each file a tool_used grader's args_file names, read whole under the run's cut (as finalFilesOf reads a file: an
1500
+ * answer without the cut's mark is refused), by its path: its text, or why there is none (absent, refused, past
1501
+ * ARGS_FILE_MAX bytes, a read that failed or took past `readTimeoutMs`). */
1502
+ export async function argsFilesOf(api, runId, paths, signal, readTimeoutMs = FILE_READ_TIMEOUT_MS) {
1503
+ const out = {};
1504
+ for (const path of new Set(paths)) {
1505
+ signal?.throwIfAborted();
1506
+ const bound = AbortSignal.timeout(readTimeoutMs);
1507
+ const read = await api("GET", `${filePath(runId, path)}?cut=run`, undefined, {}, { text: true, signal: signal ? AbortSignal.any([signal, bound]) : bound }).catch((error) => {
1508
+ if (signal?.aborted)
1509
+ throw error;
1510
+ return { error: error instanceof Error ? error.message : String(error) };
1511
+ });
1512
+ if ("error" in read)
1513
+ out[path] = { why: `the read failed (${read.error})` };
1514
+ else if (read.status === 404)
1515
+ out[path] = { why: "its work folder has no such file" };
1516
+ else if (read.status === 413)
1517
+ out[path] = { why: `it is past ${ARGS_FILE_MAX} bytes` };
1518
+ else if (read.status !== 200 || typeof read.body !== "string")
1519
+ out[path] = { why: `the server answered ${read.status}` };
1520
+ else if (read.headers?.get("x-agentrun-cut") !== "run")
1521
+ out[path] = { why: "the server did not read it under the run's cut" };
1522
+ else if (Buffer.byteLength(read.body) > ARGS_FILE_MAX)
1523
+ out[path] = { why: `it is past ${ARGS_FILE_MAX} bytes` };
1524
+ else
1525
+ out[path] = { text: read.body };
1526
+ }
1527
+ return out;
1528
+ }
1239
1529
  /** Each path a file_exists grader names that the run's work folder holds, read one by one (GET /runs/{id}/files/{path}):
1240
1530
  * the listing is capped (its `truncated`), so a file past its cap or depth is never taken for absent. Only the status
1241
1531
  * is read: the file's body is cancelled unread, whatever its size. */
@@ -1784,10 +2074,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
1784
2074
  const result = isObject(view.result) ? view.result : {};
1785
2075
  const harness = isObject(agent.definition) && typeof agent.definition.harness === "string" ? agent.definition.harness : "pi";
1786
2076
  const listed = await filesOf(api, runId);
2077
+ const calls = callsOf(ended.rows, harness, Object.fromEntries(Object.entries(used).map(([toolkit, server]) => [server, toolkit])));
1787
2078
  const record = {
1788
2079
  answer: typeof result.final_answer === "string" ? result.final_answer : "",
1789
- calls: callsOf(ended.rows, harness, Object.fromEntries(Object.entries(used).map(([toolkit, server]) => [server, toolkit]))),
1790
- mcpCalls: fakes.flatMap((fake) => fake.calls.map((call) => ({ ...call }))),
2080
+ ...callRecordOf(calls, Object.keys(one.mcp), fakes),
1791
2081
  files: await (async () => {
1792
2082
  const paths = listed.map((file) => file.path);
1793
2083
  const named = one.graders.flatMap((grader) => (grader.type === "file_exists" ? [grader.path] : []));
@@ -1815,6 +2105,10 @@ async function ranOnce(ctx, one, n, fakes, agent, agentId, runId, used, fired) {
1815
2105
  // The files it left, read whole for its llm graders: only a run they grade, so a case of other graders reads none.
1816
2106
  if (graded && one.graders.some((grader) => grader.type === "llm"))
1817
2107
  record.finalFiles = await finalFilesOf(api, runId, listed, options.signal, options.fileReadTimeoutMs);
2108
+ // The lists a tool_used grader's calls are matched against, read whole.
2109
+ const argsFiles = one.graders.flatMap((grader) => (grader.type === "tool_used" && grader.argsFile !== undefined ? [grader.argsFile] : []));
2110
+ if (argsFiles.length)
2111
+ record.argsFiles = await argsFilesOf(api, runId, argsFiles, options.signal, options.fileReadTimeoutMs);
1818
2112
  const graders = output ? [output] : [];
1819
2113
  for (const grader of one.graders) {
1820
2114
  stopped();