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

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 (404) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +393 -118
  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/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/api-only.d.ts +2 -4
  11. package/dist/api-only.js +2 -4
  12. package/dist/attach-conformance.js +5 -4
  13. package/dist/box-paths.d.ts +7 -5
  14. package/dist/box-paths.js +12 -8
  15. package/dist/browser-computer.d.ts +3 -8
  16. package/dist/browser-computer.js +12 -35
  17. package/dist/browser-cost.js +94 -20
  18. package/dist/capacity.d.ts +1 -1
  19. package/dist/capacity.js +3 -3
  20. package/dist/chatgpt-plan.d.ts +5 -0
  21. package/dist/chatgpt-plan.js +25 -11
  22. package/dist/claude-login-token.d.ts +121 -0
  23. package/dist/claude-login-token.js +797 -0
  24. package/dist/claude-login.d.ts +119 -34
  25. package/dist/claude-login.js +551 -79
  26. package/dist/claude-sign-in.d.ts +3 -0
  27. package/dist/claude-sign-in.js +10 -1
  28. package/dist/cli.js +325 -328
  29. package/dist/composio-made.d.ts +1 -6
  30. package/dist/composio-made.js +1 -6
  31. package/dist/composio-owners.d.ts +26 -0
  32. package/dist/composio-owners.js +36 -0
  33. package/dist/composio-preset.d.ts +56 -23
  34. package/dist/composio-preset.js +173 -77
  35. package/dist/composio-triggers.d.ts +4 -4
  36. package/dist/composio-triggers.js +6 -7
  37. package/dist/compute-cost.js +11 -2
  38. package/dist/computer-attach.d.ts +40 -19
  39. package/dist/computer-attach.js +326 -62
  40. package/dist/computer-held-routes.d.ts +1 -1
  41. package/dist/computer-held-routes.js +9 -4
  42. package/dist/computer-keys.d.ts +11 -1
  43. package/dist/computer-keys.js +26 -1
  44. package/dist/computer-record.js +3 -1
  45. package/dist/computer-view.d.ts +5 -3
  46. package/dist/computer-view.js +10 -6
  47. package/dist/computer-viewer.js +36 -7
  48. package/dist/computers.d.ts +12 -11
  49. package/dist/computers.js +11 -8
  50. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  51. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  52. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  53. package/dist/console/assets/share-L84tlUDW.js +6 -0
  54. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  55. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  56. package/dist/console/index.html +4 -3
  57. package/dist/console/share.html +17 -0
  58. package/dist/decisions.d.ts +17 -7
  59. package/dist/decisions.js +41 -15
  60. package/dist/dial-relay.d.ts +25 -4
  61. package/dist/dial-relay.js +139 -5
  62. package/dist/docker-daemon.js +4 -5
  63. package/dist/docker-host-addresses.js +29 -11
  64. package/dist/email/account.d.ts +6 -0
  65. package/dist/email/account.js +6 -0
  66. package/dist/email/authentication.d.ts +21 -0
  67. package/dist/email/authentication.js +106 -0
  68. package/dist/email/email-faux.d.ts +11 -2
  69. package/dist/email/email-faux.js +21 -5
  70. package/dist/email/mail.d.ts +25 -0
  71. package/dist/email/mail.js +58 -2
  72. package/dist/email/names.js +2 -2
  73. package/dist/email/tools.d.ts +9 -4
  74. package/dist/email/tools.js +95 -13
  75. package/dist/env-switch.d.ts +13 -5
  76. package/dist/env-switch.js +24 -6
  77. package/dist/errors.d.ts +1 -0
  78. package/dist/errors.js +2 -0
  79. package/dist/fal-price.d.ts +12 -4
  80. package/dist/fal-price.js +110 -26
  81. package/dist/faux-computers.js +1 -1
  82. package/dist/filed-answer.d.ts +2 -2
  83. package/dist/filed-answer.js +2 -2
  84. package/dist/graph-served.d.ts +10 -5
  85. package/dist/graph-served.js +40 -10
  86. package/dist/handed-values.js +1 -2
  87. package/dist/harness-check.d.ts +2 -1
  88. package/dist/harness-check.js +45 -12
  89. package/dist/harness-keys.js +9 -6
  90. package/dist/harness-opencode/facts.js +2 -0
  91. package/dist/harness-recipe-entry.d.ts +9 -3
  92. package/dist/harness-recipe-entry.js +18 -9
  93. package/dist/harness-recipe.d.ts +21 -0
  94. package/dist/harness-recipe.js +25 -3
  95. package/dist/harness-table.d.ts +8 -0
  96. package/dist/harness-table.js +17 -6
  97. package/dist/helper-env.d.ts +4 -1
  98. package/dist/helper-env.js +4 -1
  99. package/dist/host-check.d.ts +2 -3
  100. package/dist/host-check.js +13 -7
  101. package/dist/hosted-search.js +1 -1
  102. package/dist/import.d.ts +11 -8
  103. package/dist/import.js +437 -186
  104. package/dist/key-refusal.d.ts +9 -2
  105. package/dist/key-refusal.js +86 -32
  106. package/dist/learn/audit.d.ts +8 -5
  107. package/dist/learn/audit.js +15 -7
  108. package/dist/learn/compile.d.ts +5 -2
  109. package/dist/learn/compile.js +45 -21
  110. package/dist/learn/field-check.d.ts +111 -0
  111. package/dist/learn/field-check.js +174 -0
  112. package/dist/learn/ledger.d.ts +173 -0
  113. package/dist/learn/ledger.js +225 -0
  114. package/dist/learn/promote.d.ts +82 -39
  115. package/dist/learn/promote.js +61 -66
  116. package/dist/learn/secrets.d.ts +4 -0
  117. package/dist/learn/secrets.js +12 -0
  118. package/dist/learned-nodes.d.ts +8 -5
  119. package/dist/learned-nodes.js +8 -5
  120. package/dist/learned-workflow.d.ts +2 -1
  121. package/dist/learned-workflow.js +13 -10
  122. package/dist/learning-cost.d.ts +40 -21
  123. package/dist/learning-cost.js +30 -21
  124. package/dist/learning-setting.d.ts +6 -0
  125. package/dist/learning-setting.js +11 -1
  126. package/dist/listen-first.d.ts +5 -4
  127. package/dist/listen-first.js +4 -5
  128. package/dist/live-reach.d.ts +9 -0
  129. package/dist/live-reach.js +9 -0
  130. package/dist/mcp-api-only-origins.d.ts +23 -3
  131. package/dist/mcp-api-only-origins.js +57 -17
  132. package/dist/mcp-gateway.d.ts +16 -2
  133. package/dist/mcp-gateway.js +41 -3
  134. package/dist/mcp-oauth.d.ts +1 -1
  135. package/dist/mcp-oauth.js +3 -2
  136. package/dist/mcp-probe.d.ts +3 -0
  137. package/dist/mcp-probe.js +3 -0
  138. package/dist/mcp-secret-writes.d.ts +24 -2
  139. package/dist/mcp-secret-writes.js +30 -2
  140. package/dist/mcp-servers-store.d.ts +52 -14
  141. package/dist/mcp-servers-store.js +165 -61
  142. package/dist/mcp-sources.d.ts +1 -2
  143. package/dist/mcp-sources.js +1 -2
  144. package/dist/mcp-store.d.ts +5 -5
  145. package/dist/mcp-store.js +3 -3
  146. package/dist/mcp.js +1 -1
  147. package/dist/micro.d.ts +2 -0
  148. package/dist/micro.js +2 -0
  149. package/dist/model-gateway.d.ts +1 -1
  150. package/dist/model-gateway.js +20 -36
  151. package/dist/model.d.ts +5 -4
  152. package/dist/model.js +7 -6
  153. package/dist/monid.d.ts +14 -1
  154. package/dist/monid.js +103 -26
  155. package/dist/ollama-provider.d.ts +23 -9
  156. package/dist/ollama-provider.js +49 -20
  157. package/dist/openapi.js +234 -61
  158. package/dist/otel/genai.d.ts +83 -7
  159. package/dist/otel/genai.js +69 -9
  160. package/dist/otel/tracer.d.ts +42 -13
  161. package/dist/otel/tracer.js +241 -56
  162. package/dist/page.d.ts +7 -1
  163. package/dist/page.js +76 -22
  164. package/dist/paid-calls.d.ts +6 -4
  165. package/dist/paid-calls.js +15 -7
  166. package/dist/place-offers.d.ts +59 -34
  167. package/dist/place-offers.js +100 -58
  168. package/dist/place.d.ts +13 -14
  169. package/dist/place.js +56 -41
  170. package/dist/print.js +1 -1
  171. package/dist/provider.d.ts +5 -4
  172. package/dist/provider.js +26 -13
  173. package/dist/redact/match.d.ts +27 -9
  174. package/dist/redact/match.js +266 -57
  175. package/dist/run-census.d.ts +1 -1
  176. package/dist/run-census.js +4 -5
  177. package/dist/run-cut.js +4 -5
  178. package/dist/run-export-store.d.ts +15 -0
  179. package/dist/run-export-store.js +30 -0
  180. package/dist/run-export.d.ts +139 -0
  181. package/dist/run-export.js +379 -0
  182. package/dist/run-file-cut.d.ts +5 -0
  183. package/dist/run-file-cut.js +13 -0
  184. package/dist/run-launch.js +16 -3
  185. package/dist/run-learning-served.d.ts +2 -2
  186. package/dist/run-model-key.d.ts +15 -6
  187. package/dist/run-model-key.js +30 -31
  188. package/dist/run-reads-over-store.js +4 -4
  189. package/dist/run-secrets.js +3 -5
  190. package/dist/run-timeline-served.js +3 -1
  191. package/dist/run-view.d.ts +1 -2
  192. package/dist/run-view.js +2 -1
  193. package/dist/runnable.js +2 -2
  194. package/dist/runner/adapter-loop.d.ts +35 -18
  195. package/dist/runner/adapter-loop.js +97 -63
  196. package/dist/runner/adapter-run-spec.d.ts +34 -14
  197. package/dist/runner/adapter-run-spec.js +120 -75
  198. package/dist/runner/adapters/pi.js +4 -2
  199. package/dist/runner/audit.d.ts +8 -5
  200. package/dist/runner/audit.js +37 -17
  201. package/dist/runner/beside.d.ts +9 -2
  202. package/dist/runner/beside.js +29 -13
  203. package/dist/runner/claim-secrets.d.ts +27 -18
  204. package/dist/runner/claim-secrets.js +61 -47
  205. package/dist/runner/cli-run-spec.d.ts +18 -0
  206. package/dist/runner/cli-run-spec.js +93 -46
  207. package/dist/runner/compare-end.d.ts +2 -1
  208. package/dist/runner/compare-end.js +25 -10
  209. package/dist/runner/conformance/harness.js +2 -3
  210. package/dist/runner/conformance/subject.d.ts +4 -1
  211. package/dist/runner/harness-loops.js +3 -3
  212. package/dist/runner/held.d.ts +19 -4
  213. package/dist/runner/journal-kinds.d.ts +4 -1
  214. package/dist/runner/journal-kinds.js +22 -4
  215. package/dist/runner/learned-first.js +20 -4
  216. package/dist/runner/learning-end.d.ts +2 -8
  217. package/dist/runner/learning-end.js +11 -19
  218. package/dist/runner/live-ticker.js +7 -5
  219. package/dist/runner/loop-contract.d.ts +0 -2
  220. package/dist/runner/loop.d.ts +7 -0
  221. package/dist/runner/loop.js +1 -0
  222. package/dist/runner/main.d.ts +11 -6
  223. package/dist/runner/main.js +24 -18
  224. package/dist/runner/mcp-claim.js +24 -7
  225. package/dist/runner/mcp-run.d.ts +3 -6
  226. package/dist/runner/mcp-run.js +3 -4
  227. package/dist/runner/meta-tools.js +3 -2
  228. package/dist/runner/metrics.d.ts +7 -0
  229. package/dist/runner/metrics.js +19 -0
  230. package/dist/runner/model-route.d.ts +10 -7
  231. package/dist/runner/model-route.js +79 -15
  232. package/dist/runner/native-loop.js +10 -8
  233. package/dist/runner/presence.d.ts +11 -4
  234. package/dist/runner/presence.js +11 -6
  235. package/dist/runner/promotion.d.ts +25 -13
  236. package/dist/runner/promotion.js +125 -50
  237. package/dist/runner/redact.d.ts +3 -1
  238. package/dist/runner/redact.js +5 -3
  239. package/dist/runner/reflect-hook.js +1 -1
  240. package/dist/runner/responses-fetch.d.ts +36 -0
  241. package/dist/runner/responses-fetch.js +511 -0
  242. package/dist/runner/run-child-host.d.ts +38 -12
  243. package/dist/runner/run-child-host.js +231 -83
  244. package/dist/runner/run-child.js +11 -4
  245. package/dist/runner/runner-check.js +5 -1
  246. package/dist/runner/runner.d.ts +5 -3
  247. package/dist/runner/runner.js +14 -10
  248. package/dist/runner/save-slots.js +2 -1
  249. package/dist/runner/sdk-loop.js +8 -8
  250. package/dist/runner/spec-holds.d.ts +8 -1
  251. package/dist/runner/spec-holds.js +9 -4
  252. package/dist/runner/subagent.d.ts +11 -0
  253. package/dist/runner/subagent.js +17 -3
  254. package/dist/runner/workflow-calls.d.ts +9 -0
  255. package/dist/runner/workflow-calls.js +150 -0
  256. package/dist/runner/workflow-first.d.ts +138 -37
  257. package/dist/runner/workflow-first.js +230 -99
  258. package/dist/runner/workflow-spec.js +2 -2
  259. package/dist/runs-over-store.js +8 -7
  260. package/dist/save-once.d.ts +14 -0
  261. package/dist/save-once.js +31 -0
  262. package/dist/scrub-command.d.ts +34 -31
  263. package/dist/scrub-command.js +116 -147
  264. package/dist/sdk/runs.d.ts +6 -0
  265. package/dist/sdk/runs.js +89 -10
  266. package/dist/seal-key.js +4 -4
  267. package/dist/secret-cut.d.ts +3 -0
  268. package/dist/secret-cut.js +7 -1
  269. package/dist/secret-rules.d.ts +8 -1
  270. package/dist/secret-rules.js +482 -53
  271. package/dist/secrets.d.ts +51 -9
  272. package/dist/secrets.js +311 -21
  273. package/dist/server-keys.d.ts +4 -3
  274. package/dist/server-keys.js +4 -3
  275. package/dist/server-secrets-store.js +2 -4
  276. package/dist/server.d.ts +33 -10
  277. package/dist/server.js +454 -136
  278. package/dist/share-context.d.ts +22 -0
  279. package/dist/share-context.js +76 -0
  280. package/dist/shell-lex.d.ts +105 -0
  281. package/dist/shell-lex.js +646 -0
  282. package/dist/sign-ins-store.d.ts +5 -7
  283. package/dist/sign-ins-store.js +12 -16
  284. package/dist/sign-ins.d.ts +7 -11
  285. package/dist/sign-ins.js +40 -41
  286. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  287. package/dist/slots.d.ts +9 -0
  288. package/dist/slots.js +45 -0
  289. package/dist/start-switches.d.ts +6 -5
  290. package/dist/start-switches.js +8 -4
  291. package/dist/stats.d.ts +5 -1
  292. package/dist/stats.js +1 -1
  293. package/dist/store/agent-body.js +2 -2
  294. package/dist/store/dialect.d.ts +4 -0
  295. package/dist/store/dialect.js +1 -0
  296. package/dist/store/index.d.ts +2 -2
  297. package/dist/store/index.js +1 -1
  298. package/dist/store/mcp-record-keys.d.ts +10 -0
  299. package/dist/store/mcp-record-keys.js +13 -0
  300. package/dist/store/postgres/dialect.js +2 -0
  301. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  302. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  303. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  304. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  305. package/dist/store/postgres/store.js +4 -0
  306. package/dist/store/schema.d.ts +44 -4
  307. package/dist/store/schema.js +111 -11
  308. package/dist/store/seal.d.ts +4 -1
  309. package/dist/store/sqlite/run-launch.d.ts +3 -10
  310. package/dist/store/sqlite/run-launch.js +12 -23
  311. package/dist/store/sqlite/run-patch.d.ts +19 -2
  312. package/dist/store/sqlite/run-patch.js +67 -2
  313. package/dist/store/sqlite/store.d.ts +3 -0
  314. package/dist/store/sqlite/store.js +177 -32
  315. package/dist/store/store-schema.js +3 -4
  316. package/dist/store/store.d.ts +74 -25
  317. package/dist/store/store.js +14 -11
  318. package/dist/store-reads/analytics.d.ts +2 -1
  319. package/dist/store-reads/analytics.js +7 -5
  320. package/dist/store-reads/learning.d.ts +102 -136
  321. package/dist/store-reads/learning.js +251 -302
  322. package/dist/store-reads/stats.d.ts +2 -2
  323. package/dist/store-reads/stats.js +13 -7
  324. package/dist/store-view.js +10 -7
  325. package/dist/suggestions.d.ts +1 -1
  326. package/dist/suggestions.js +29 -13
  327. package/dist/template-eval.d.ts +91 -9
  328. package/dist/template-eval.js +448 -105
  329. package/dist/template-import.d.ts +0 -10
  330. package/dist/template-import.js +5 -10
  331. package/dist/timeline/labels.d.ts +1 -1
  332. package/dist/timeline/labels.js +4 -3
  333. package/dist/timeline/timeline.d.ts +23 -11
  334. package/dist/timeline/timeline.js +115 -31
  335. package/dist/timeline/web-calls.d.ts +14 -14
  336. package/dist/timeline/web-calls.js +18 -30
  337. package/dist/tool-gate.d.ts +13 -1
  338. package/dist/tool-gate.js +43 -3
  339. package/dist/tool-keys-store.js +2 -4
  340. package/dist/tool-keys.d.ts +11 -0
  341. package/dist/tool-keys.js +16 -0
  342. package/dist/tool-plane.d.ts +50 -11
  343. package/dist/tool-plane.js +94 -30
  344. package/dist/tools.d.ts +5 -1
  345. package/dist/tools.js +7 -7
  346. package/dist/trigger-email.js +12 -6
  347. package/dist/triggers.d.ts +15 -34
  348. package/dist/triggers.js +119 -126
  349. package/dist/validate.d.ts +8 -1
  350. package/dist/validate.js +163 -23
  351. package/dist/web-fake.d.ts +2 -1
  352. package/dist/web-fake.js +8 -6
  353. package/dist/web-fetch.d.ts +8 -6
  354. package/dist/web-fetch.js +13 -11
  355. package/dist/web-holds.d.ts +32 -0
  356. package/dist/web-holds.js +86 -0
  357. package/dist/web-run.d.ts +32 -5
  358. package/dist/web-run.js +75 -28
  359. package/dist/web-save.d.ts +4 -9
  360. package/dist/web-save.js +27 -55
  361. package/dist/web-search.js +14 -25
  362. package/dist/wires.d.ts +4 -3
  363. package/dist/wires.js +5 -4
  364. package/dist/workspace/archil-claim.d.ts +12 -5
  365. package/dist/workspace/archil-claim.js +45 -5
  366. package/dist/workspace/attach.js +52 -19
  367. package/dist/workspace/attached-computers.d.ts +38 -11
  368. package/dist/workspace/attached-computers.js +81 -16
  369. package/dist/workspace/computer-deps.d.ts +29 -7
  370. package/dist/workspace/computer-deps.js +36 -18
  371. package/dist/workspace/computer-for-claim.d.ts +21 -4
  372. package/dist/workspace/computer-for-claim.js +166 -57
  373. package/dist/workspace/computer-intervals.d.ts +2 -0
  374. package/dist/workspace/computer-intervals.js +1 -1
  375. package/dist/workspace/computer-janitor.d.ts +48 -14
  376. package/dist/workspace/computer-janitor.js +153 -44
  377. package/dist/workspace/computer-kept.d.ts +158 -32
  378. package/dist/workspace/computer-kept.js +288 -63
  379. package/dist/workspace/computer-providers.d.ts +8 -3
  380. package/dist/workspace/computer-providers.js +12 -5
  381. package/dist/workspace/index.d.ts +1 -1
  382. package/dist/workspace/index.js +1 -1
  383. package/dist/workspace/local.js +41 -1
  384. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  385. package/dist/workspace/mount-revoke-left.js +72 -0
  386. package/dist/workspace/paired-route.d.ts +91 -0
  387. package/dist/workspace/paired-route.js +152 -0
  388. package/dist/workspace/resolve-computer.d.ts +5 -2
  389. package/dist/workspace/resolve-computer.js +9 -3
  390. package/dist/workspace/run-end-computers.d.ts +11 -5
  391. package/dist/workspace/run-end-computers.js +153 -28
  392. package/dist/workspace/run-tools.d.ts +22 -3
  393. package/dist/workspace/run-tools.js +17 -5
  394. package/dist/workspace/run-workspace.d.ts +14 -1
  395. package/dist/workspace/run-workspace.js +34 -1
  396. package/dist/workspace/workspace.d.ts +6 -0
  397. package/dist/wrapped.d.ts +8 -2
  398. package/dist/wrapped.js +21 -6
  399. package/package.json +12 -13
  400. package/skills/agentrun-serve/SKILL.md +5 -2
  401. package/templates/README.md +25 -9
  402. package/dist/console/assets/backend-DVhHzJX2.js +0 -166
  403. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  404. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -22,6 +22,7 @@ import { CAP_REFUSED, CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_O
22
22
  import { raiseFollowUpId } from "../run-view.js";
23
23
  import { durableWait } from "../workflow/pi-versions.js";
24
24
  import { genAiTracing } from "../otel/tracer.js";
25
+ import { tracedAgent, tracedEvent, tracedModel } from "../otel/genai.js";
25
26
  /** The root entries a claim writes before its turn, whatever the run's turns are (its session's key, a phase row, a
26
27
  * takeover's note, its computer's hold, the learning seed it laid, the computer it made): read past when a claim asks
27
28
  * whether the run's root ends on its end (a fresh reopen). */
@@ -45,7 +46,7 @@ import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
45
46
  import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
46
47
  import { ADAPTER_API } from "../turn-end.js";
47
48
  import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
48
- import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
49
+ import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, REAL_TIMER, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
49
50
  import { outputMiss, outputRetryWords } from "../answer-json.js";
50
51
  import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
51
52
  import { isComputerCommand, journalHold } from "./computer-journal.js";
@@ -67,23 +68,10 @@ import { Fenced } from "../store/index.js";
67
68
  import { answerAsServed } from "../answer-json.js";
68
69
  import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
69
70
  import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
71
+ import { LEARNED_NODES } from "../learned-nodes.js";
70
72
  import { warnHoldShort } from "../print.js";
71
73
  import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
72
74
  import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
73
- /** What a session's requests were charged (sessionSpendOf's figures of those answered, a crash's cut one at its hold among
74
- * them), never one still in flight at its hold. Null: one charged has no figure. */
75
- function chargedOf(records) {
76
- const read = sessionSpendOf(records);
77
- let usd = 0;
78
- for (const figure of read.figures) {
79
- if (!read.answered.has(figure.turn))
80
- continue;
81
- if (figure.usd === null)
82
- return null;
83
- usd += figure.usd;
84
- }
85
- return usd;
86
- }
87
75
  /** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
88
76
  * and the harness's next call runs it. */
89
77
  export const OWN_TOOL_RELEASED = "Allowed after it waited; the agent's own tool runs it on its next call.";
@@ -840,11 +828,11 @@ function adapterLoop(specOf, options, deps) {
840
828
  * input's user entry left as pi writes it (its submission, which a re-claim answers from, unchanged), so the Timeline
841
829
  * shows the next user entry with exactly this text as "AgentRun: …". Once per follow-up: the marker names its request
842
830
  * id, and a re-claim that finds one under it writes none (a second would stay open, and could take a person's later
843
- * message of the same words for the server's). A CLI's run records its follow-up through its own record, which carries
844
- * the origin itself. */
831
+ * message of the same words for the server's). A CLI's run records its follow-up in its own record, written here with
832
+ * the origin (once under its request id, as the output retry's is), since the CLI's session keeps no user entry. */
845
833
  const markServerFollowUp = async (theHarness, theRoot, text, requestId) => {
846
834
  if (cliRecord)
847
- return;
835
+ return await cliRecord.followUp(text, requestId, CAP_RAISED_ORIGIN);
848
836
  const marked = (await entriesOf(gate.journal, theRoot.id, context)).some((entry) => entry.kind === MESSAGE_ORIGIN && entry.data?.requestId === requestId);
849
837
  if (marked)
850
838
  return;
@@ -1359,7 +1347,7 @@ function adapterLoop(specOf, options, deps) {
1359
1347
  };
1360
1348
  /** run(claim), its trace ended with it: every span still open ends, with the claim's failure where it failed, handed to
1361
1349
  * the exporter, which sends it in the background (tracer.ts: the claim's end never waits on a collector, and never
1362
- * throws). */
1350
+ * throws). In a run's own process the end is posted to its runner, which exports; neither side flushes for it. */
1363
1351
  async function traced(claim) {
1364
1352
  try {
1365
1353
  const end = await run(claim);
@@ -1569,8 +1557,10 @@ function adapterLoop(specOf, options, deps) {
1569
1557
  }
1570
1558
  // The run's trace, from its claim's start, once its spec says what runs (a restart's spec changes nothing of it).
1571
1559
  // The tracing is made long before (as the loop is): waited for only on the rare claim whose spec beat it.
1572
- trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt, mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined });
1573
- trace?.known({ runId: claim.runId, harness: spec.adapter.id, ...(spec.facts?.wire === "plan" ? { plan: true } : {}), ...spec.trace });
1560
+ trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt });
1561
+ // Its agent, as the spec read it from the store, cut by the runner's redactor and of every secret shape (tracedAgent).
1562
+ const { agent, ...route } = spec.trace ?? {};
1563
+ trace?.known({ runId: claim.runId, ...(agent ? { agent: tracedAgent(agent, deps.redact) } : {}), harness: spec.adapter.id, ...(spec.facts?.wire === "plan" ? { plan: true } : {}), ...route });
1574
1564
  mcp = spec.mcp;
1575
1565
  specNow = spec;
1576
1566
  specKnown = true;
@@ -1661,13 +1651,14 @@ function adapterLoop(specOf, options, deps) {
1661
1651
  for (const key of await sessions.keys()) {
1662
1652
  if (key === spec.session.key)
1663
1653
  continue;
1664
- const spent = settled ? chargedOf(await sessions.read(key)) : sessionSpendOf(await sessions.read(key)).spentUsd;
1654
+ const read = sessionSpendOf(await sessions.read(key));
1655
+ const spent = settled ? read.chargedUsd : read.spentUsd;
1665
1656
  if (spent === null)
1666
1657
  return undefined;
1667
1658
  others += spent;
1668
1659
  }
1669
1660
  if (settled) {
1670
- const own = chargedOf(await sessions.read(spec.session.key));
1661
+ const own = sessionSpendOf(await sessions.read(spec.session.key)).chargedUsd;
1671
1662
  return own === null ? undefined : overCapEnd(others + own, cap);
1672
1663
  }
1673
1664
  // Its model session read as the cap reads it (the kernel's overCapOf: a request cut by a crash at its hold plus its
@@ -1874,9 +1865,16 @@ function adapterLoop(specOf, options, deps) {
1874
1865
  return reserveOf(requestFigures(asked));
1875
1866
  };
1876
1867
  let bookingNow;
1877
- // The replaced computer's note (spec.computerNote), until a request carrying it is answered. It goes before the
1878
- // wrap-up: one note per request, so the wrap-up waits a request.
1879
- let computerWords = spec.computerNote;
1868
+ // The computer's notes, in order, each until a request carrying it is answered: the replaced computer's
1869
+ // (spec.computerNote), then where the run's files are (spec.computerFilesNote), unless a COMPUTER_NOTE row marked
1870
+ // `files` says an earlier claim told it. One note per request: the replaced computer's goes before the wrap-up, so
1871
+ // the wrap-up waits a request; the files note goes after a wrap-up that is due, so it never holds one back.
1872
+ const filesTold = spec.computerFilesNote !== undefined && (await entriesOf(gate.journal, wrapUpRoot.id, context))
1873
+ .some((entry) => entry.kind === COMPUTER_NOTE && entry.data?.files === true);
1874
+ const computerNotes = [
1875
+ ...(spec.computerNote !== undefined ? [{ words: spec.computerNote }] : []),
1876
+ ...(spec.computerFilesNote !== undefined && !filesTold ? [{ words: spec.computerFilesNote, files: true }] : []),
1877
+ ];
1880
1878
  // The server's note a request carries (the replaced computer's, else the cap's wrap-up; `cap` says the wrap-up's
1881
1879
  // figures), one request at a time: from its take until that request's admission ends, then, admitted carrying it
1882
1880
  // (`turn`), until that request ends. Told once that request is answered (afterRequest); given back for the next
@@ -1889,7 +1887,8 @@ function adapterLoop(specOf, options, deps) {
1889
1887
  const takeNote = (model, asked) => {
1890
1888
  if (carried && (carried.turn !== undefined || Date.now() - carried.at < WRAP_UP_OFFER_MS))
1891
1889
  return undefined;
1892
- const note = computerWords !== undefined && !reflecting ? { words: computerWords } : wrapUpNote(model, asked);
1890
+ const first = reflecting ? undefined : computerNotes[0];
1891
+ const note = first !== undefined && !first.files ? first : (wrapUpNote(model, asked) ?? first);
1893
1892
  carried = note ? { ...note, at: Date.now() } : undefined;
1894
1893
  return note?.words;
1895
1894
  };
@@ -1907,10 +1906,11 @@ function adapterLoop(specOf, options, deps) {
1907
1906
  what = "the free-limit wrap-up's row";
1908
1907
  }
1909
1908
  else if (told.cap === undefined) {
1910
- computerWords = undefined;
1909
+ if (computerNotes[0]?.words === told.words)
1910
+ computerNotes.shift();
1911
1911
  kind = COMPUTER_NOTE;
1912
- data = { words: rowWords(told.words) };
1913
- what = "the replaced computer's note row";
1912
+ data = { words: rowWords(told.words), ...(told.files ? { files: true } : {}) };
1913
+ what = told.files ? "the computer files note's row" : "the replaced computer's note row";
1914
1914
  }
1915
1915
  else {
1916
1916
  const { leftUsd, capUsd } = told.cap;
@@ -2195,8 +2195,9 @@ function adapterLoop(specOf, options, deps) {
2195
2195
  },
2196
2196
  });
2197
2197
  // A call a stop cut answers whatever its tool said of the abort: it ends interrupted, never as its outcome.
2198
+ // A nesting tool that ended at a refused nested call (a script stopped there) ends refused, as that call did.
2198
2199
  if (record)
2199
- await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.isError ? "failed" : "done", answer.text);
2200
+ await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.refused && answer.isError ? "refused" : answer.isError ? "failed" : "done", answer.text);
2200
2201
  // A CLI's question to the person (a turn-ending tool's call, answered): its turn is cut at its next request,
2201
2202
  // as pi's ends here (TurnCut). Any other call's end after it lets the turn go on.
2202
2203
  if (record && endsTurn(tool.name) && !answer.isError && !stopAbort.signal.aborted)
@@ -2296,8 +2297,16 @@ function adapterLoop(specOf, options, deps) {
2296
2297
  carried = undefined;
2297
2298
  }
2298
2299
  unbooked += 1;
2299
- if (ticket && trace && request.paid === undefined)
2300
- chats.set(ticket.turn, trace.request(request.model, request.route));
2300
+ // Its chat span names the model asked only when the run knows it (a route's model, or one its price table names by
2301
+ // that same id: a CLI's table prices every id as the session's model, so a priced id alone proves nothing, and a
2302
+ // body's model is the client's words), else its route's model; whichever, cut (genai.ts tracedModel).
2303
+ if (ticket && trace && request.paid === undefined) {
2304
+ const traced = specNow?.trace;
2305
+ const routed = request.route === undefined ? traced?.model : traced?.routes?.get(request.route)?.model;
2306
+ const known = (asked) => asked === traced?.model || [...(traced?.routes?.values() ?? [])].some((via) => via.model === asked) || specNow?.runCap.modelOf(asked)?.id === asked;
2307
+ const model = tracedModel(request.model, { known, ...(routed ? { routed } : {}), ...(deps.redact ? { redact: deps.redact } : {}) });
2308
+ chats.set(ticket.turn, trace.request(model, request.route));
2309
+ }
2301
2310
  // The conversation that asked, as its client named it (pi's, one of several asking at once): whose answer reads
2302
2311
  // this request's booking (bookedCost).
2303
2312
  const conversation = request.conversation;
@@ -2471,7 +2480,7 @@ function adapterLoop(specOf, options, deps) {
2471
2480
  // Every harness's events reach its trace first (its tool calls, a plan harness's turns), with a record or without.
2472
2481
  const recorded = record ? onEvent(record) : undefined;
2473
2482
  const traceAnd = (event) => {
2474
- trace?.event(event);
2483
+ trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, ...(deps.redact ? { redact: deps.redact } : {}) }));
2475
2484
  recorded?.(event);
2476
2485
  };
2477
2486
  const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: bridgeGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
@@ -2749,13 +2758,6 @@ function adapterLoop(specOf, options, deps) {
2749
2758
  memo: async (_key, value) => (typeof value === "function" ? value() : value),
2750
2759
  });
2751
2760
  const serveFirst = async (first) => {
2752
- // The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
2753
- // cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
2754
- const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
2755
- if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
2756
- return undefined;
2757
- const { nests: _nests, ...plain } = bare;
2758
- const learned = hosted(plain);
2759
2761
  const [on, theRoot, theGate] = [harness, root, gate];
2760
2762
  const args = { name: first.name, input: first.input };
2761
2763
  const call = { callId: WORKFLOW_FIRST_CALL, tool: LEARNED_WORKFLOW_TOOL, args };
@@ -2779,9 +2781,17 @@ function adapterLoop(specOf, options, deps) {
2779
2781
  if (kept?.outcome === "answered")
2780
2782
  return { outcome: "answered", text: ended?.output ?? "" };
2781
2783
  // Handed back on an earlier claim whose handback never reached the agent (the session is still new): sent now, in
2782
- // the words that claim would have sent (its why included).
2784
+ // the words that claim would have sent (its why included), with or without the tool now (the money rule may have
2785
+ // taken the workflow off it since: workflow-first.ts toolStopsOf).
2783
2786
  if (kept)
2784
2787
  return job(ended ? taken(recorded(ended)).text : "");
2788
+ // The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
2789
+ // cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
2790
+ const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
2791
+ if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
2792
+ return undefined;
2793
+ const { nests: _nests, ...plain } = bare;
2794
+ const learned = hosted(plain);
2785
2795
  if (!ended) {
2786
2796
  // A deny before anything is written leaves the run its agent's, as if the workflow were not there.
2787
2797
  const before = await spec.gate?.({ callId: call.callId, tool: call.tool, args });
@@ -2793,6 +2803,8 @@ function adapterLoop(specOf, options, deps) {
2793
2803
  await rec.person(spec.input);
2794
2804
  }
2795
2805
  let answer;
2806
+ // Refused at its gate, on this claim or the one before: it ran nothing.
2807
+ let refused = ended?.status === "refused";
2796
2808
  if (ended)
2797
2809
  answer = recorded(ended);
2798
2810
  else {
@@ -2807,6 +2819,7 @@ function adapterLoop(specOf, options, deps) {
2807
2819
  else
2808
2820
  await rec.refused(WORKFLOW_FIRST_CALL, LEARNED_WORKFLOW_TOOL, args, false, verdict.deny);
2809
2821
  answer = { text: verdict.deny, isError: true };
2822
+ refused = true;
2810
2823
  }
2811
2824
  else {
2812
2825
  // A CLI's record takes the call's start and end inside the wrapper; pi's step record here.
@@ -2823,9 +2836,14 @@ function adapterLoop(specOf, options, deps) {
2823
2836
  answer = taken(answer);
2824
2837
  const outcome = answer.isError ? "handed_back" : "answered";
2825
2838
  const data = { workflow: first.name, digest: first.digest, ...(first.promotion !== undefined ? { promotion: first.promotion } : {}), revision: first.revision, call: WORKFLOW_FIRST_CALL, outcome };
2839
+ // A call refused at its gate keeps its record as one the tool refused does (learned-nodes.ts LEARNED_NODES
2840
+ // `refused`): no workflow ran it, so the money rule charges none and the run names none.
2841
+ const refusal = refused ? { call: WORKFLOW_FIRST_CALL, workflow: first.name, digest: first.digest, caller: "platform", nodes: [], ended: "failed", refused: true } : undefined;
2826
2842
  await on.commit(async (tx) => {
2827
2843
  if (outcome === "answered")
2828
2844
  await tx.appendEntry(theRoot.id, { kind: KINDS.message, data: { role: "model", text: answer.text, at: now() } });
2845
+ if (refusal)
2846
+ await tx.appendEntry(theRoot.id, { kind: LEARNED_NODES, data: refusal });
2829
2847
  await tx.appendEntry(theRoot.id, { kind: WORKFLOW_FIRST, data: data });
2830
2848
  }, context);
2831
2849
  return outcome === "answered" ? { outcome, text: answer.text } : job(answer.text);
@@ -2835,9 +2853,10 @@ function adapterLoop(specOf, options, deps) {
2835
2853
  // under way (the handback sent) never runs it again.
2836
2854
  let served;
2837
2855
  // A workflow this run already served or handed back on an earlier claim (its end on the root): recovered whatever the
2838
- // money rule says now, so a crash before the handback never makes the agent redo finished work.
2839
- const keptFirst = spec.workflowFirst || !spec.workflowRevise || followedUp || firstUnplaced || session.state !== "new" ? undefined : findData(await entriesOf(gate.journal, root.id, context), WORKFLOW_FIRST, () => true);
2840
- const recovered = keptFirst && keptFirst.outcome !== "needs_revision" ? { name: keptFirst.workflow, digest: keptFirst.digest, revision: keptFirst.revision, input: {}, ...(spec.workflowRevise?.outputSchema !== undefined ? { outputSchema: spec.workflowRevise.outputSchema } : {}) } : undefined;
2856
+ // money rule says now (its stop, or its fail-closed read of an unreadable past), so a crash before the handback never
2857
+ // makes the agent redo finished work. Only a run that learns keeps one.
2858
+ const keptFirst = spec.workflowFirst || !spec.learningLaid || followedUp || firstUnplaced || session.state !== "new" ? undefined : findData(await entriesOf(gate.journal, root.id, context), WORKFLOW_FIRST, () => true);
2859
+ const recovered = keptFirst && keptFirst.outcome !== "needs_revision" ? { name: keptFirst.workflow, digest: keptFirst.digest, revision: keptFirst.revision, input: {}, ...(spec.outputSchema !== undefined ? { outputSchema: spec.outputSchema } : {}) } : undefined;
2841
2860
  const firstToServe = spec.workflowFirst ?? recovered;
2842
2861
  // A fitting workflow the money rule stopped: why, on the root, once for the run, as the agent takes it.
2843
2862
  if (spec.workflowRevise && !followedUp && !firstUnplaced && session.state === "new") {
@@ -3229,7 +3248,7 @@ function adapterLoop(specOf, options, deps) {
3229
3248
  return { deny: wrapUpDeny };
3230
3249
  // A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
3231
3250
  const replayed = call.replayed === true;
3232
- const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf })) ?? "allow";
3251
+ const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf, approved: approvedOf })) ?? "allow";
3233
3252
  // An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape), or
3234
3253
  // with the reason a call its setting allows asks anyway (`because`).
3235
3254
  const shown = typeof given === "object" && "ask" in given ? given.ask : undefined;
@@ -3423,6 +3442,17 @@ function adapterLoop(specOf, options, deps) {
3423
3442
  async function ranOf(tool) {
3424
3443
  return toolCalls(await agentEntriesOf(gate.journal, context), tool);
3425
3444
  }
3445
+ /** Whether a person approved the call `callId`, as answerOf reads it: its answer in the journal stands; else the
3446
+ * approve or deny for it among the claim's commands (read once they are all with the loop, deps.delivered), which
3447
+ * answerOf takes next. */
3448
+ async function approvedOf(callId) {
3449
+ const conversation = await harness.root(context);
3450
+ const known = findData(await entriesOf(gate.journal, conversation.id, context), KINDS.answer, (data) => data.callId === callId);
3451
+ if (known)
3452
+ return known.approved;
3453
+ await (deps.delivered ?? Promise.resolve());
3454
+ return inbox.find((command) => (command.kind === "approve" || command.kind === "deny") && approvalOf(command) === callId)?.kind === "approve";
3455
+ }
3426
3456
  async function askStands(callId) {
3427
3457
  standing ??= (async () => {
3428
3458
  const conversation = await harness.root(context);
@@ -3563,10 +3593,10 @@ function adapterLoop(specOf, options, deps) {
3563
3593
  return turnOfRequest(on, conversation, last.requestId);
3564
3594
  }
3565
3595
  /** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
3566
- * root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf). Kept with
3567
- * its time, now, which it answers; with no step to ask, nothing is kept. */
3596
+ * root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (its spec's endOfRun).
3597
+ * Kept with its time, now, which it answers; with no step to ask, nothing is kept. */
3568
3598
  async function keepJobEnd(on, conversation, spec, data, failedWith) {
3569
- if (!stepOf(spec))
3599
+ if (!spec.endOfRun)
3570
3600
  return undefined;
3571
3601
  const kept = jobEndOf(data, failedWith, now());
3572
3602
  await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
@@ -3740,9 +3770,7 @@ function adapterLoop(specOf, options, deps) {
3740
3770
  return kept && typeof kept === "object" && !Array.isArray(kept) ? kept : undefined;
3741
3771
  };
3742
3772
  }
3743
- /** The run's end-of-run step: its spec's (AdapterRunSpec.endOfRun) when it has one, else the loop's deps'. */
3744
- const stepOf = (spec) => spec.endOfRun ?? deps.endOfRun;
3745
- /** The end-of-run step (stepOf: the spec's, else LoopDeps.endOfRun), asked once: the rows to stage with the end; `stopped` when a person's stop
3773
+ /** The end-of-run step (its spec's endOfRun; none without one), asked once: the rows to stage with the end; `stopped` when a person's stop
3746
3774
  * came during it; `interrupted` when the claim was lost or the runner is closing (no end is written, and the next claim
3747
3775
  * asks it again). A step that throws on its own writes the end without rows: the run's end never waits on it. `over`:
3748
3776
  * the claim's overCap, read after each turn the step asks (askEndOfRun). */
@@ -3754,7 +3782,7 @@ function adapterLoop(specOf, options, deps) {
3754
3782
  return { kind: "interrupted" };
3755
3783
  return undefined;
3756
3784
  };
3757
- const step = stepOf(spec);
3785
+ const step = spec.endOfRun;
3758
3786
  if (!step)
3759
3787
  return { kind: "rows", also: [] };
3760
3788
  if (!spec.agentId)
@@ -3780,11 +3808,11 @@ function adapterLoop(specOf, options, deps) {
3780
3808
  return cut() ?? (console.warn(`[runner] ${claim.runId}: its end-of-run step failed: ${said(error)}`), { kind: "rows", also: [] });
3781
3809
  }
3782
3810
  }
3783
- /** What a run cut before it could look back keeps beside its end (LoopDeps.endOfRun with `cut`, never asking): a
3811
+ /** What a run cut before it could look back keeps beside its end (its spec's endOfRun with `cut`, never asking): a
3784
3812
  * person's stop, before or during the end-of-run turn, or a fault. Bounded (CUT_STEP_MS): a step that reads a stalled
3785
3813
  * store, or throws, keeps nothing, and the end is never held up by it. */
3786
3814
  async function cutRows(claim, spec, cut) {
3787
- const step = stepOf(spec);
3815
+ const step = spec.endOfRun;
3788
3816
  if (!step || !spec.agentId)
3789
3817
  return [];
3790
3818
  const refuse = () => Promise.reject(new Error("a cut run's end-of-run step asks nothing"));
@@ -3899,9 +3927,9 @@ function adapterLoop(specOf, options, deps) {
3899
3927
  const spec = specNow;
3900
3928
  if (!spec?.endPatch && !spec?.endCost)
3901
3929
  return {};
3930
+ const bound = spec.endPatchTimer ?? REAL_TIMER;
3902
3931
  let timer;
3903
- const boundMs = spec.endPatchMs ?? END_PATCH_MS;
3904
- const late = new Promise((resolve) => (timer = setTimeout(() => resolve("late"), boundMs)));
3932
+ const late = new Promise((resolve) => (timer = bound.setTimeout(() => resolve("late"), END_PATCH_MS)));
3905
3933
  // The cost, read apart (AdapterRunSpec.endCost): a patch whose metrics run late or fail never takes it with them. A
3906
3934
  // read that fails is read again within the same bound (END_COST_TRIES): the stored cost is every reader's answer
3907
3935
  // (the list, the view, usage), so a null there is kept only when the booking could not be read at all.
@@ -3909,7 +3937,7 @@ function adapterLoop(specOf, options, deps) {
3909
3937
  const cost = endCost
3910
3938
  ? readAgain(endCost, late, (error, tries, last) => console.warn(last ? `[runner] its end's cost failed ${tries} times, last: ${said(error)}; the end is written with its cost unknown` : `[runner] its end's cost failed: ${said(error)}; read again`)).then((answer) => {
3911
3939
  if (answer === "late")
3912
- console.warn(`[runner] its end's cost gave no answer within ${boundMs / 1000} s; the end is written with its cost unknown`);
3940
+ console.warn(`[runner] its end's cost gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its cost unknown`);
3913
3941
  return answer === "late" || answer === "failed" ? { costUsd: null, costUpperBound: false } : answer;
3914
3942
  })
3915
3943
  : undefined;
@@ -3919,7 +3947,7 @@ function adapterLoop(specOf, options, deps) {
3919
3947
  try {
3920
3948
  const patch = await Promise.race([spec.endPatch(data), late]);
3921
3949
  if (patch === "late") {
3922
- console.warn(`[runner] its end's patch gave no answer within ${boundMs / 1000} s; the end is written with its ${cost ? "metrics" : "cost and metrics"} unknown`);
3950
+ console.warn(`[runner] its end's patch gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its ${cost ? "metrics" : "cost and metrics"} unknown`);
3923
3951
  return END_PATCH_UNKNOWN;
3924
3952
  }
3925
3953
  return patch ?? {};
@@ -3934,7 +3962,7 @@ function adapterLoop(specOf, options, deps) {
3934
3962
  return read ? { ...patch, ...read } : patch;
3935
3963
  }
3936
3964
  finally {
3937
- clearTimeout(timer);
3965
+ bound.clearTimeout(timer);
3938
3966
  }
3939
3967
  }
3940
3968
  /** The run parked at its cap: its pending budget as an agentrun.budget entry, in one commit with the run parked in the
@@ -4035,12 +4063,18 @@ function adapterLoop(specOf, options, deps) {
4035
4063
  }
4036
4064
  /** At a park for `cause`, before its seal: a pass whose spec keeps its computer (AdapterRunSpec.keptWords) has it kept
4037
4065
  * for the resume at its release (closeSession), once the run's timeline says so, for the person deciding; its owner's
4038
- * live view is closed saying the cause. A write that fails (the fence's refusal: a lost claim, whose run a later claim
4039
- * may hold already) keeps nothing: the computer goes as at the run's end. */
4066
+ * live view is closed saying the cause. The keep's row is written first (AdapterRunSpec.keep), under the claim's
4067
+ * fence: a park that keeps nothing (another runner's row still there, a write that failed, a claim that lost the run
4068
+ * and so writes nothing) says nothing of a keep, and its computer goes as at
4069
+ * the run's end. A commit that fails (the fence's refusal: a lost claim, whose run a later claim may hold already)
4070
+ * keeps nothing either: the computer goes as at the run's end, and its row with it. */
4040
4071
  async function keepAtPark(on, cause) {
4041
- const summary = specNow?.keptWords;
4072
+ const summary = specNow?.keptWords?.();
4042
4073
  if (!summary)
4043
4074
  return;
4075
+ const keep = specNow?.keep;
4076
+ if (keep && !(await keep().catch(() => false)))
4077
+ return;
4044
4078
  parkedNow = await on.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary, at: Date.now() } }), context).then(() => cause, () => undefined);
4045
4079
  }
4046
4080
  /** The run's pause at its cap: its agentrun.budget entry, in one commit with the run parked in the cap's words. */
@@ -20,6 +20,7 @@ import { type ClaimModelKey } from "./claim-secrets.js";
20
20
  import { type ClaimMcp } from "./mcp-run.js";
21
21
  import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
22
22
  import { type RunnerHarness } from "./adapters/index.js";
23
+ import { type BoundTimer } from "./loop.js";
23
24
  import { type SubagentTier } from "./subagent.js";
24
25
  import { type Claim, type Journal } from "./loop-contract.js";
25
26
  import type { ReplayCalls } from "../learn/replay-calls.js";
@@ -67,6 +68,8 @@ export interface ClaimComputer {
67
68
  release(): Promise<void>;
68
69
  /** The release at the run's park, which keeps the computer it `keeps` (computer-for-claim.ts ClaimComputer.park). */
69
70
  park?(): Promise<boolean>;
71
+ /** The park's keep written before the run's timeline says it (computer-for-claim.ts ClaimComputer.keepRow). */
72
+ keepRow?(): Promise<boolean>;
70
73
  }
71
74
  /** The one shared claim-time computer every spec takes (computer-for-claim.ts), passed in by the runner: the composer's
72
75
  * (workspace/computer-deps.ts computerDepsFrom), or a test's stand-in. */
@@ -102,6 +105,9 @@ export interface AdapterSpecDeps {
102
105
  readonly log?: (message: string) => void;
103
106
  /** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
104
107
  readonly gradeBound?: () => AbortSignal;
108
+ /** For tests: the timer a native or SDK run's end arms its bound on (END_PATCH_MS, loop.ts) while it waits on its cost
109
+ * and metrics read, as the adapter loop's spec.endPatchTimer. Default: the real one (REAL_TIMER). */
110
+ readonly endPatchTimer?: BoundTimer;
105
111
  /** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
106
112
  * The runner gives it; a test gives its own. */
107
113
  readonly computerForClaim: ComputerForClaim;
@@ -159,6 +165,9 @@ export interface AdapterSpecDeps {
159
165
  * on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
160
166
  * it; absent, MODEL_RETRY and MODEL_STREAM. */
161
167
  readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
168
+ /** The runs' GenAI tracing (AdapterLoopOptions.tracing): in a run's own process, the one posted to its runner
169
+ * (run-child.ts); absent, this process's own. */
170
+ readonly tracing?: AdapterLoopOptions["tracing"];
162
171
  /** web_save's download slots (ToolHost.saveSlots): in a run's own process, its runner's (run-child.ts). */
163
172
  readonly saveSlots?: SaveSlots;
164
173
  }
@@ -200,23 +209,30 @@ export declare function modelRetryOf(routes: Iterable<Pick<ModelRoute, "like">>)
200
209
  * translates its model's requests (its own `fetch`) is named by its upstream's host (ModelRoute.upstreamOrigin), never
201
210
  * its proxy's placeholder origin; one whose upstream is unknown names no host. */
202
211
  export declare const traceOfRoute: (route: ModelRoute) => import("../otel/genai.js").RouteTrace;
203
- /** The model a replay run's or an audit shadow's grader runs on (graderRouteOf): the revision's modelTiers.fast, else
204
- * `env`'s fast tier (AGENT_MODEL_FAST); undefined when there is neither, or the revision names agree_on (no grader). */
205
- export declare function graderModelOf(body: {
206
- readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
207
- readonly learning?: unknown;
208
- }, env: NodeJS.ProcessEnv): string | undefined;
209
- /** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
210
- * modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
211
- * provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
212
- * holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone; in a run's own
213
- * process its runner hands it the fast model's provider's keys alone (run-child-host.ts savedModelKeys, graderModelOf). A
214
- * run with its own model key carries that key, and no saved key is read. Undefined when there is no fast model, the
215
- * revision names agree_on, or no route can be made (logged: the pair is then compared whole). */
212
+ /** A replay run's or an audit shadow's grader route (runner/compare-end.ts): on the fast tier routedSubagentTiers names
213
+ * (the revision's modelTiers.fast, else AGENT_MODEL_FAST), on pi's wires, when its revision names no agree_on. Its route
214
+ * reads the saved key of that tier's model alone (subagentTierKeys), held by the run's redactors, on the route's env
215
+ * alone; in a run's own process its runner hands it that tier's model's key (run-child-host.ts subagentTierKeys). A run
216
+ * with its own model key carries that key, and no saved key is read. Undefined, with nothing read, when
217
+ * there is no fast tier or the revision names agree_on; undefined when no route can be made (logged: the pair is then
218
+ * compared whole). */
216
219
  export declare function graderRouteOf(body: {
217
220
  readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
218
221
  readonly learning?: unknown;
219
222
  }, keyed: boolean, runKey: ClaimModelKey | undefined, claimed: NodeJS.ProcessEnv, cut: HeldRedact, log: (line: string) => void, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, holds?: readonly HeldRedact[], claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<ModelRoute | undefined>;
223
+ /** A subagent run's tier routes (runner/subagent.ts): each tier routedSubagentTiers names, on its model (the revision's
224
+ * modelTiers, else the host's tier variable), under its own key (subagentRoute), on a route of its own. A tier's model may
225
+ * be another provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's
226
+ * model): so the routes read the saved model keys of those tiers' models alone (subagentTierKeys), held by the run's
227
+ * redactor, on the routes' env alone, never the run's tools (toolEnv). A run with its own model key carries that key,
228
+ * and no saved key is read. A tier no route can be made for here is in `why`, cut, and no failure of the run: a call on
229
+ * it answers why. */
230
+ export declare function subagentTierRoutes(body: {
231
+ readonly modelTiers?: Readonly<Partial<Record<SubagentTier, string>>>;
232
+ }, keyed: boolean, runKey: ClaimModelKey | undefined, toolEnv: NodeJS.ProcessEnv, cut: HeldRedact, deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "env" | "routeOf">, claim?: Pick<Claim, "runId" | "turn" | "attempt">): Promise<{
233
+ readonly routes: Map<string, ModelRoute>;
234
+ readonly why: Map<SubagentTier, string>;
235
+ }>;
220
236
  /** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
221
237
  * revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
222
238
  * when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
@@ -250,7 +266,8 @@ export declare function modelAskOf(pinned: {
250
266
  * The run's computer once off for the run (RunGate.computerOff): a call of its tools is refused before any settings read.
251
267
  * `turnedOff`: an earlier claim turned it off (computer-journal.ts computerTurnedOff), so this claim's gate starts off.
252
268
  * `onComputerOff`: told the computer's kind, and awaited, when this claim's first deny of a call of its tools turns it off,
253
- * for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too.
269
+ * for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too. The gate's
270
+ * `computerOff` says whether it is off now, so a park lets it go instead of keeping it (spec-holds.ts Held.computerOff).
254
271
  */
255
272
  /** The run's tool permissions as a learned workflow's call nodes are held to them (learned-workflow.ts policy, denyFrom,
256
273
  * refresh): the same gate as the run's own calls, its settings read again from the store before each call node. */
@@ -262,6 +279,7 @@ export type RunPermissions = {
262
279
  export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
263
280
  kind: string;
264
281
  body: {
282
+ tools?: readonly string[];
265
283
  toolSettings?: unknown;
266
284
  harness?: string;
267
285
  approvals?: Approvals;
@@ -276,6 +294,8 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
276
294
  readonly permissions: RunPermissions;
277
295
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
278
296
  readonly askedOn: (host: ToolHost) => void;
297
+ readonly computerOff: () => boolean; /** Whether the run can write a file now, as its gate decides a save_as (RunGate.writeBar): what its files note and computer_screenshot's save_as are offered by. */
298
+ readonly writes: () => boolean;
279
299
  }>;
280
300
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
281
301
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */