@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.40

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 (423) hide show
  1. package/CHANGELOG.md +455 -0
  2. package/README.md +376 -125
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-B8Zn1Iqn.css +1 -0
  37. package/dist/console/assets/index-Jbxjcmdp.js +705 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +83 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +15 -0
  46. package/dist/email/answer.js +217 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +373 -0
  53. package/dist/email/names.d.ts +50 -0
  54. package/dist/email/names.js +74 -0
  55. package/dist/email/routes.d.ts +10 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +27 -0
  58. package/dist/email/tools.js +562 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +12 -4
  93. package/dist/learn/compile.js +57 -20
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +130 -64
  97. package/dist/learn/promote.js +113 -202
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +35 -8
  109. package/dist/learning-cost.js +27 -9
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +39 -2
  118. package/dist/local-models.js +49 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +2 -1
  164. package/dist/openapi.js +404 -93
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +10 -2
  170. package/dist/port-models.js +6 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +14 -0
  180. package/dist/refusal-words.js +16 -2
  181. package/dist/run-launch.d.ts +12 -1
  182. package/dist/run-launch.js +13 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +44 -38
  191. package/dist/run-view.js +93 -56
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +48 -13
  195. package/dist/runner/adapter-loop.js +691 -254
  196. package/dist/runner/adapter-run-spec.d.ts +38 -12
  197. package/dist/runner/adapter-run-spec.js +175 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +95 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +59 -13
  217. package/dist/runner/journal-kinds.js +48 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +14 -3
  237. package/dist/runner/model-route.js +155 -19
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +76 -10
  243. package/dist/runner/promotion.js +476 -154
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +568 -137
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/dialect.d.ts +3 -0
  278. package/dist/store/dialect.js +1 -0
  279. package/dist/store/index.d.ts +1 -1
  280. package/dist/store/native-command-owner.d.ts +10 -0
  281. package/dist/store/native-command-owner.js +47 -0
  282. package/dist/store/postgres/connection.d.ts +11 -5
  283. package/dist/store/postgres/connection.js +44 -17
  284. package/dist/store/postgres/dialect.js +5 -0
  285. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  286. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  287. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  288. package/dist/store/postgres/store.d.ts +7 -3
  289. package/dist/store/postgres/store.js +4 -0
  290. package/dist/store/schema.d.ts +7 -0
  291. package/dist/store/schema.js +20 -1
  292. package/dist/store/sqlite/connection.js +72 -8
  293. package/dist/store/sqlite/run-launch.d.ts +11 -0
  294. package/dist/store/sqlite/run-launch.js +8 -0
  295. package/dist/store/sqlite/run-patch.d.ts +8 -1
  296. package/dist/store/sqlite/run-patch.js +14 -3
  297. package/dist/store/sqlite/store.js +170 -34
  298. package/dist/store/sqlite/worker.d.ts +2 -0
  299. package/dist/store/sqlite/worker.js +13 -10
  300. package/dist/store/store.d.ts +67 -7
  301. package/dist/store-reads/analytics.d.ts +7 -7
  302. package/dist/store-reads/analytics.js +23 -5
  303. package/dist/store-reads/cap.js +8 -6
  304. package/dist/store-reads/journal.d.ts +5 -0
  305. package/dist/store-reads/journal.js +85 -41
  306. package/dist/store-reads/learning.d.ts +115 -18
  307. package/dist/store-reads/learning.js +170 -68
  308. package/dist/store-reads/runs.d.ts +5 -0
  309. package/dist/store-reads/runs.js +3 -2
  310. package/dist/store-view.js +75 -21
  311. package/dist/template-eval.d.ts +73 -11
  312. package/dist/template-eval.js +535 -75
  313. package/dist/templates.d.ts +84 -21
  314. package/dist/templates.js +254 -47
  315. package/dist/text-urls.d.ts +38 -0
  316. package/dist/text-urls.js +170 -0
  317. package/dist/timeline/index.d.ts +3 -2
  318. package/dist/timeline/index.js +3 -2
  319. package/dist/timeline/labels.d.ts +5 -2
  320. package/dist/timeline/labels.js +29 -6
  321. package/dist/timeline/origin.d.ts +1 -1
  322. package/dist/timeline/origin.js +2 -2
  323. package/dist/timeline/render-text.js +1 -1
  324. package/dist/timeline/timeline.d.ts +66 -4
  325. package/dist/timeline/timeline.js +160 -30
  326. package/dist/timeline/util.d.ts +5 -0
  327. package/dist/timeline/util.js +44 -8
  328. package/dist/timeline/web-calls.d.ts +17 -0
  329. package/dist/timeline/web-calls.js +106 -0
  330. package/dist/tool-gate.d.ts +46 -44
  331. package/dist/tool-gate.js +101 -92
  332. package/dist/tool-list.d.ts +4 -1
  333. package/dist/tool-list.js +8 -1
  334. package/dist/tool-names.d.ts +18 -13
  335. package/dist/tool-names.js +19 -17
  336. package/dist/tool-plane.d.ts +17 -13
  337. package/dist/tool-plane.js +12 -5
  338. package/dist/tools.d.ts +57 -16
  339. package/dist/tools.js +33 -28
  340. package/dist/trigger-adapter.d.ts +56 -5
  341. package/dist/trigger-adapter.js +6 -0
  342. package/dist/trigger-adapters.js +3 -1
  343. package/dist/trigger-composio.d.ts +10 -0
  344. package/dist/trigger-composio.js +122 -0
  345. package/dist/trigger-email.d.ts +4 -0
  346. package/dist/trigger-email.js +181 -0
  347. package/dist/trigger-signatures.d.ts +6 -10
  348. package/dist/trigger-signatures.js +16 -16
  349. package/dist/trigger-targets.d.ts +1 -1
  350. package/dist/trigger-targets.js +4 -3
  351. package/dist/trigger-webhook.js +6 -4
  352. package/dist/triggers.d.ts +105 -8
  353. package/dist/triggers.js +286 -62
  354. package/dist/uploads.d.ts +9 -0
  355. package/dist/uploads.js +27 -0
  356. package/dist/validate.js +1 -7
  357. package/dist/web-fake.d.ts +56 -0
  358. package/dist/web-fake.js +102 -0
  359. package/dist/web-fetch-direct.d.ts +3 -0
  360. package/dist/web-fetch-direct.js +4 -1
  361. package/dist/web-fetch.d.ts +5 -1
  362. package/dist/web-fetch.js +8 -31
  363. package/dist/web-search.d.ts +51 -2
  364. package/dist/web-search.js +116 -18
  365. package/dist/webhooks.d.ts +2 -1
  366. package/dist/webhooks.js +5 -1
  367. package/dist/workflow/decision-recovery.js +5 -2
  368. package/dist/workflow/decisions.d.ts +7 -0
  369. package/dist/workflow/node-runner.js +10 -2
  370. package/dist/workspace/archil-claim.d.ts +3 -0
  371. package/dist/workspace/archil-claim.js +9 -2
  372. package/dist/workspace/computer-deps.d.ts +22 -9
  373. package/dist/workspace/computer-deps.js +78 -37
  374. package/dist/workspace/computer-for-claim.d.ts +54 -4
  375. package/dist/workspace/computer-for-claim.js +179 -39
  376. package/dist/workspace/computer-janitor.d.ts +10 -3
  377. package/dist/workspace/computer-janitor.js +96 -29
  378. package/dist/workspace/computer-kept.d.ts +82 -0
  379. package/dist/workspace/computer-kept.js +147 -0
  380. package/dist/workspace/computer-mcp.js +4 -3
  381. package/dist/workspace/computer-ports.d.ts +23 -3
  382. package/dist/workspace/computer-ports.js +115 -5
  383. package/dist/workspace/index.d.ts +1 -2
  384. package/dist/workspace/index.js +1 -2
  385. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  386. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  387. package/dist/workspace/resolve-computer.d.ts +15 -3
  388. package/dist/workspace/resolve-computer.js +10 -7
  389. package/dist/workspace/revision-skills.d.ts +6 -2
  390. package/dist/workspace/revision-skills.js +12 -5
  391. package/dist/workspace/run-end-computers.d.ts +30 -0
  392. package/dist/workspace/run-end-computers.js +137 -0
  393. package/dist/workspace/run-tools.d.ts +28 -29
  394. package/dist/workspace/run-tools.js +29 -30
  395. package/dist/wrap-up.d.ts +19 -5
  396. package/dist/wrap-up.js +31 -4
  397. package/package.json +13 -9
  398. package/skills/agentrun-serve/SKILL.md +248 -10
  399. package/templates/README.md +117 -23
  400. package/templates/TOOLS.md +168 -0
  401. package/templates/code-review/agent.md +18 -4
  402. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  404. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  405. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  406. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  407. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  408. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  409. package/templates/code-review/skills/review/DEEP.md +2 -2
  410. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  411. package/templates/code-review/skills/review/SKILL.md +7 -3
  412. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  413. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  414. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  415. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  416. package/dist/console/assets/index-CjqQirbo.css +0 -1
  417. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  418. package/dist/host-calls.d.ts +0 -20
  419. package/dist/host-calls.js +0 -12
  420. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  421. package/dist/runner/adapters/pi-computer.js +0 -51
  422. package/dist/workspace/computer-script.d.ts +0 -53
  423. package/dist/workspace/computer-script.js +0 -172
@@ -1,65 +1,68 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
3
- import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
3
+ import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
4
4
  import { inspectWorkflow } from "@parcha/agentrun-dsl";
5
5
  import { decisionProvidersIn } from "../decisions.js";
6
6
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
7
7
  import { runnerLiveOf } from "../live-reach.js";
8
8
  import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes } from "../model.js";
9
- import { firstMessage, inputMessage } from "../run-manifest.js";
9
+ import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
10
10
  import { learningStartOf, seedFailed } from "../run-launch.js";
11
11
  import { isWebHostTool } from "../tool-list.js";
12
- import { deniedText, mcpServersOf, noApproverText, runGate } from "../tool-gate.js";
12
+ import { ASKED_BECAUSE } from "../refusal-words.js";
13
+ import { deniedText, noApproverText, runGate } from "../tool-gate.js";
13
14
  import { DECISION_PROVIDER_KEYS, loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
14
15
  import { readApprovers } from "../server-approvers.js";
15
16
  import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
16
17
  import { hostToolOf } from "../host-tools.js";
17
18
  import { WEB_SEARCH_TOOL } from "../web-search.js";
18
- import { environmentLine } from "../environment.js";
19
+ import { webCut } from "../timeline/web-calls.js";
20
+ import { environmentLine, runZone } from "../environment.js";
19
21
  import { effortGuidance } from "../effort-guidance.js";
20
22
  import { outputContract } from "../answer-json.js";
21
23
  import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
22
24
  import { laidOf, layLearningSeed } from "./learning-seed.js";
23
25
  import { learningWorkspace } from "../learn/folder.js";
24
26
  import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
25
- import { learnedAskFits, learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpTools, learnedWorkflowTool } from "../learned-workflow.js";
27
+ import { learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpCalls, learnedWorkflowTool } from "../learned-workflow.js";
26
28
  import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
27
29
  import { promptOf, readsFiles } from "../skills.js";
28
30
  import { openRunWorkspace } from "../workspace/run-workspace.js";
29
31
  import { layOwnSkills } from "../workspace/revision-skills.js";
30
32
  import { COMPUTER_ROOT, runFolder } from "../workspace/paths.js";
31
33
  import { runTools, withKindTools } from "../workspace/run-tools.js";
32
- import { copyRunFiles } from "../uploads.js";
34
+ import { placeRunInputs } from "../uploads.js";
33
35
  import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
34
36
  import { UNREADABLE_SIGN_IN } from "../run-view.js";
35
37
  import { durableWait } from "../workflow/pi-versions.js";
36
38
  import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
37
- import { mcpForClaim } from "./mcp-run.js";
39
+ import { catalogSessionNames, mcpForClaim } from "./mcp-run.js";
38
40
  import { hostLifecycle } from "./adapter-loop.js";
39
41
  import { piAdapter } from "./adapters/pi.js";
40
- import { computerCodemode } from "./adapters/pi-computer.js";
41
42
  import { agentEntriesOf } from "./loop.js";
42
43
  import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
43
- import { wireName } from "../catalog.js";
44
44
  import { ClaimRefused } from "./loop-contract.js";
45
- import { bookedSpend, cliRunMetrics, runEndCost, runMetrics } from "./metrics.js";
45
+ import { bookedSpend, cliRunMetrics, endCostOf, runCostOf, runMetrics } from "./metrics.js";
46
46
  import { journalEntries } from "./journal-reader.js";
47
- import { piShaped } from "../store-reads/journal.js";
47
+ import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
48
48
  import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid } from "./promotion.js";
49
49
  import { laidFor, pathMetrics, servedOf, workflowFirstOf } from "./workflow-first.js";
50
50
  import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
51
51
  import { specBuilt } from "./spec-holds.js";
52
52
  import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
53
53
  import { loadArchilSettings } from "../archil-settings.js";
54
- import { computerReadyWords, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
54
+ import { settingOfDefinition } from "../computer-setting.js";
55
+ import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
56
+ import { hadComputer } from "./computer-journal.js";
55
57
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
58
+ import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
56
59
  import { heldSpecOf } from "./held-run.js";
57
60
  import { loopComputerOf } from "./computer-channel.js";
58
61
  import { githubAppAccess } from "./github-app.js";
59
62
  import { prCheckoutForClaim } from "./pr-checkout.js";
60
63
  import { holdStored, storeSecrets } from "./store-secrets.js";
61
64
  import { bashPolicyOf } from "../bash-read-only.js";
62
- import { monidForClaim, monidSessionNames, withMonid } from "./monid-run.js";
65
+ import { monidForClaim, withMonid } from "./monid-run.js";
63
66
  /** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
64
67
  export const PI_WIRES = Object.freeze(["anthropic-messages", "openai-responses"]);
65
68
  /** The browser's catalog name (tools.ts TOOLS.browser). */
@@ -75,6 +78,9 @@ export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger
75
78
  * model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
76
79
  * overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
77
80
  export function capModelOf(route) {
81
+ // A ChatGPT plan's route is billed to the plan: the one plan rule (planCapModel), a CLI's plan model's too.
82
+ if (route.provider.plan)
83
+ return planCapModel(route.model, route.provider.api, route.outputCeiling ?? null);
78
84
  // A model serve has no price for carries placeholder zeros: the cap reads it as unknown (null), never as $0.
79
85
  const cost = route.unpriced ? undefined : route.cost;
80
86
  const price = cost
@@ -101,67 +107,82 @@ const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
101
107
  export function modelAskOf(pinned, ref) {
102
108
  return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
103
109
  }
104
- export async function adapterRunGate(store, claim, revision, root, shell, mcpServers = [], options = {}) {
110
+ export async function adapterRunGate(store, claim, revision, root, shell, options = {}) {
105
111
  let current = await storeSettings(store);
106
112
  const approvers = await readApprovers(store.settings);
107
113
  // A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
108
114
  const folder = typeof root === "string" ? root : COMPUTER_ROOT;
109
115
  // Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
110
- // default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused. The run's MCP servers
111
- // (mcpServersOf its grants), so a harness naming an MCP tool its own way (OpenCode's `<server>_<tool>`) is held to that
112
- // tool's settings, never to a table tool's of the same shape.
116
+ // default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
113
117
  // An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
114
- // pi's code mode on a desktop or a phone (pi-computer.ts) owns the name `codemode` there: held to the kind's setting.
115
- const where = { root: folder, work: folder, mcpServers, ...(options.computerCodemode ? { computerCodemode: true } : {}), ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}) };
118
+ const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}) };
116
119
  const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
117
- // A script's computer calls (computer_script, pi's code mode) run on the run's computer, a desktop that mounts no folder
118
- // too: decided as on a computer, so its shell.run and processes.start follow bash's one setting alike. The run's own
119
- // host tools keep `gate`, where its bash is (Archil's exec, or none).
120
- const onComputer = runGate({ ...where, computer: true }, claim.runId, revision, () => current, approvers);
121
120
  // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
122
121
  let learned = [];
122
+ // The host the run's tools bind through, once the spec has made it (askedOn): a tool's own ask reads it.
123
+ let host;
124
+ // A tool's own ask counts its calls (AskContext.ran): the journal's, run to a good end, and the calls of it this gate let
125
+ // through in this claim that have no result yet (reserved, by tool), so calls made at once never all read the same
126
+ // count. Its calls are asked about one at a time (asking, a chain by tool): the count read and the reservation with
127
+ // nothing between. A reserved call whose result is in the journal leaves it: counted there, or its slot freed (an
128
+ // error, a deny). A new claim's gate starts with none: what finished is the journal's.
129
+ const reserved = new Map();
130
+ const asking = new Map();
131
+ const counted = (ran) => async (tool) => {
132
+ const calls = await ran(tool);
133
+ const held = reserved.get(tool);
134
+ for (const id of held ?? [])
135
+ if (calls.ran.has(id) || calls.ended.has(id))
136
+ held.delete(id);
137
+ return calls.ran.size + calls.unnamed + (held?.size ?? 0);
138
+ };
139
+ const askedOne = (call, asks, made, ran) => {
140
+ const turn = (asking.get(call.tool) ?? Promise.resolve()).then(async () => {
141
+ const because = await asks((call.args ?? {}), { host: made, ran: counted(ran) });
142
+ if (because === undefined && call.callId)
143
+ reserved.set(call.tool, (reserved.get(call.tool) ?? new Set()).add(call.callId));
144
+ return because;
145
+ });
146
+ asking.set(call.tool, turn.catch(() => undefined));
147
+ return turn;
148
+ };
123
149
  const decide = async (call, options = {}) => {
124
150
  current = await storeSettings(store);
125
151
  const decision = await gate.decide(call.tool, call.args, options);
126
- // A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings, decided for the whole call
127
- // before any node runs, never mid-run: one set to deny refuses the call in the gate's words, nothing sent; one set to
128
- // ask asks for the call, up front, on the run's one card (a running workflow can't park mid-call: it is never run
129
- // again after a crash), and the person's allow lets that call's MCP nodes run, and only that call's.
130
- // Checked whether the learned_workflow call is itself allowed or asked: a workflow that can't run is never put to a
131
- // person.
152
+ // A call its setting allows that its tool asks about itself (ToolEntry.asks: email_send past its cap, or to someone
153
+ // outside the run's thread): put to a person with the tool's reason on its card, whatever the setting; where no one
154
+ // can approve, refused in those words. No tool's name is read here: the reason is the tool's.
155
+ const asksOf = decision === "allow" && host && options.ran ? toolOf(call.tool)?.asks : undefined;
156
+ const because = asksOf ? await askedOne(call, asksOf, host, options.ran) : undefined;
157
+ if (because !== undefined)
158
+ return approvers ? { ask: { [ASKED_BECAUSE]: because } } : { deny: noApproverText(gate.askedAs(call.tool, call.args), options.replayed ? "unknown" : "no", because) };
159
+ // A learned workflow's MCP nodes are the run's own MCP calls, held to the same settings: one set to deny refuses the
160
+ // whole call in the gate's words before any node runs, nothing sent; the actions set to ask are put to a person on the
161
+ // call's one card, up front, each with its arguments' shape (learnedAskShown), and the person's allow passes the
162
+ // calls nested in this one of the tools that card named (adapter-loop.ts preIntentGate), and no other. Each MCP call
163
+ // is still asked at the gate as itself as it runs (its pins, a deny set since). Checked whether the learned_workflow
164
+ // call is itself allowed or asked: a workflow that can't run is never put to a person.
132
165
  if (call.tool !== LEARNED_WORKFLOW_TOOL || typeof decision === "object")
133
166
  return decision;
134
- const tools = await mcpOf(call.args);
167
+ const actions = await mcpOf(call.args);
135
168
  const refused = (why) => ({ deny: `The learned workflow ${String(call.args.name)} was not run: ${why}` });
136
- const denied = tools.find((tool) => gate.policy(tool) === "deny");
169
+ const denied = actions.find(({ tool }) => gate.policy(tool) === "deny");
137
170
  if (denied)
138
- return refused(deniedText(denied, undefined, gate.denyFrom(denied)));
139
- const asks = tools.filter((tool) => gate.policy(tool) === "ask");
171
+ return refused(deniedText(denied.tool, undefined, gate.denyFrom(denied.tool)));
172
+ const asks = actions.filter(({ tool }) => gate.policy(tool) === "ask");
140
173
  // An ask no one can answer (the server's accounts off) is refused at once in the gate's words, never parked.
141
174
  if (asks.length && !approvers)
142
- return refused(noApproverText(asks[0], "no"));
143
- // A card that could not name every MCP tool the person would approve (past its preview's bound) is never shown: the
144
- // call is refused, so no allow covers a tool its approver did not see.
145
- if (asks.length && !learnedAskFits(asks))
146
- return refused(`its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.`);
147
- return asks.length ? "ask" : decision;
175
+ return refused(noApproverText(asks[0].tool, "no"));
176
+ return asks.length ? { ask: learnedAskShown(asks) } : decision;
148
177
  };
149
- /** The MCP tools the learned workflow a learned_workflow call names can call; none for another call or workflow. */
178
+ /** The MCP actions the learned workflow a learned_workflow call names can call; none for another call or workflow. */
150
179
  const mcpOf = async (args) => {
151
180
  const flow = learned.find((one) => one.name === args?.name);
152
- return flow ? learnedMcpTools(flow.workflow) : [];
181
+ return flow ? learnedMcpCalls(flow.workflow) : [];
153
182
  };
154
183
  // An ask is named as main's pending approval is (RunGate.askedAs: its settings key), beside the decision, which is
155
184
  // unchanged. The permissions are the learned workflow's (main's toolGate.policy and denyFrom), over the same settings.
156
- const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); }, decide: (tool, args) => gate.decide(tool, args) };
157
- // What a learned_workflow call's card shows beside its own input: every MCP tool set to ask that the workflow can call,
158
- // and that their arguments are decided while it runs, so the person sees what they approve.
159
- const askedFor = async (tool, args) => {
160
- if (tool !== LEARNED_WORKFLOW_TOOL)
161
- return undefined;
162
- const asks = (await mcpOf(args)).filter((one) => gate.policy(one) === "ask");
163
- return asks.length ? learnedAskShown(asks) : undefined;
164
- };
185
+ const permissions = { policy: (tool) => gate.policy(tool), denyFrom: (tool) => gate.denyFrom(tool), refresh: async () => { current = await storeSettings(store); } };
165
186
  // A tool's setting now, read from the store as each call's is (SessionIO.permission: Codex's live search, which runs
166
187
  // inside a model request, is offered only while it says allow). A read that fails is a deny, never the last good read's
167
188
  // allow: a deny saved since may be in what did not read, and no call reaches the gate to say otherwise.
@@ -169,12 +190,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, mcpSer
169
190
  current = await storeSettings(store);
170
191
  return current.unreadable ? "deny" : gate.policy(tool);
171
192
  };
172
- // A script's computer call, held as the tool it is (computer-script.ts HELD_AS), with the settings read from the store now.
173
- const script = async (tool, args) => {
174
- current = await storeSettings(store);
175
- return onComputer.decide(tool, args);
176
- };
177
- return Object.assign(decide, { askedAs: (tool) => gate.askedAs(tool), askedFor, permissions, permission, script, learn: (flows) => void (learned = flows) });
193
+ return Object.assign(decide, { askedAs: (tool, args) => gate.askedAs(tool, args), permissions, permission, learn: (flows) => void (learned = flows), askedOn: (made) => void (host = made) });
178
194
  }
179
195
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
180
196
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
@@ -237,9 +253,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
237
253
  : await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
238
254
  holds.hold({ ws });
239
255
  // The run's uploaded files, copied into its work/inputs/ before the first turn, from what its start held for it, once
240
- // per run (uploads.ts copyRunFiles); a copy that fails ends the run failed, saying why.
241
- if (launch.files?.length)
242
- await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
256
+ // per run (uploads.ts copyRunFiles), and its opening message saved beside them as inputs/message.md (placeRunInputs);
257
+ // a copy that fails ends the run failed, saying why.
258
+ await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
243
259
  // The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
244
260
  // turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
245
261
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
@@ -258,23 +274,29 @@ async function adapterSpec(launch, run, deps, claim, holds) {
258
274
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
259
275
  // Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
260
276
  // when the computer cannot be had: the run fails in its words.
261
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
277
+ const claimSignal = run.stopped ?? run.signal;
278
+ const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place }, deps.store,
262
279
  // revokeMount removes the run's Archil mount credential when the computer is released (and if a start fails after a mint);
263
280
  // the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent. What
264
281
  // became of the agent's own computer (a persistent setting) is said on the run's timeline.
265
- { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
282
+ // A person's stop ends the claim's waits at once: a first image pull or registration (Agent37's runs minutes) among them.
283
+ // Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer): a later
284
+ // claim's is a new one whatever ended the earlier claim (a lost runner, a server's stop, a park past its keep). The
285
+ // computer a park kept, attached again, brings its mount credential with it (inheritMount): none is minted.
286
+ { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, hadComputer: () => hadComputer(deps.journal(claim), context), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
266
287
  // The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
267
288
  // (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
268
289
  // A desktop's or a phone's hold (the person's take-over) wraps its ports: a call made while the person holds it waits,
269
290
  // and the agent's hand-over (computer_request_handoff) asks the person through it.
270
291
  holds.hold({ computer });
271
- const loopComputer = loopComputerOf(computer.computer, computer.held);
292
+ const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
272
293
  const heldComputer = heldSpecOf(launch, loopComputer);
273
294
  // Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv).
274
295
  const bashPolicy = bashPolicyOf(body.toolSettings);
275
- // pi's codemode is its script tool (codeMode): a code-only computer lists no computer_script beside it, and a
276
- // tools-only one gets no codemode (tools.computer is absent then).
277
- const tools = await runTools(ws.workspace, computer.computer, { mode, context, codeMode: true, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }) });
296
+ // The computer's tools are the run's own host tools, as on every harness: the host's codemode (meta-tools.ts) calls them
297
+ // as `tools.<name>`, each a nested call, gated and recorded as the model's own call is. A computer that replaced an
298
+ // earlier claim's holds its acts to what it showed.
299
+ const tools = await runTools(ws.workspace, computer.computer, { mode, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
278
300
  holds.hold({ tools });
279
301
  // The run's model route: its model through routeOf (NEVER re-resolved — the launch's model, pinned at start), the catalog
280
302
  // price with tiers for the cap, and the proxy's price (pi-ai calculateCost, tiered).
@@ -291,6 +313,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
291
313
  // saved in Settings → Model keys runs the next run with no restart (withModelKeys).
292
314
  const modelEnv = withModelKeys(deps.env, toolEnv);
293
315
  const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
316
+ await planBeforeRun(modelEnv, route.provider.plan ? { provider: PLAN_PROVIDER } : undefined);
294
317
  // The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
295
318
  // lay chose the workflows, below): read when the session opens (pi.ts options.tiers), each on a proxy of its own.
296
319
  const tierRoutes = new Map();
@@ -302,9 +325,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
302
325
  // (adapter-loop waitInClaim, the browser's personWait below). It stays out of this session's host tools: a CLI
303
326
  // harness gets the same tool as a host tool (cli-run-spec.ts), whose turn the loop cuts at the question.
304
327
  // - the browser's durable extension, when the run gets one (bindNonHandTools, below, before the session opens).
305
- // - pi's code mode, with a desktop or a phone (pi-computer.ts): the `codemode` tool beside the run's own, its scripts
306
- // with `computer` bound on the run's held port.
307
- const native = [...(granted.includes(ASK_TOOL) ? [defineExtension({ name: "ask_person", tools: [askPerson] })] : []), ...(tools.computer ? [computerCodemode(tools.computer)] : [])];
328
+ const native = granted.includes(ASK_TOOL) ? [defineExtension({ name: "ask_person", tools: [askPerson] })] : [];
308
329
  // pi-native tools in the session's own extension (PiAdapterOptions.tools): the subagent tool, pushed below.
309
330
  const piTools = [];
310
331
  // A run granted subagent (runner/subagent.ts): the model of each of its tiers, the revision's own (modelTiers) else the
@@ -357,10 +378,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
357
378
  // The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
358
379
  // the same path), for its path checks; it reads nothing in it.
359
380
  // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
360
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted), { computerCodemode: Boolean(tools.computer), ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}) });
361
- // What a script's shell and files are held to: this gate's settings, decided as on the run's computer (gate.script), so a
362
- // denied bash or write holds inside computer_script and codemode.
363
- tools.computer?.guard.install(gate.script);
381
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {});
364
382
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
365
383
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
366
384
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -378,9 +396,10 @@ async function adapterSpec(launch, run, deps, claim, holds) {
378
396
  const tierRoute = tierRoutes.get(by);
379
397
  return tierRoute && tierRoute.model === id ? capModelOf(tierRoute) : undefined;
380
398
  },
381
- ...(launch.capMode === "strict" ? { mode: "strict" } : {}),
382
399
  // What its learning runs' grades took beside it, read by every gate with its own sessions (none: it queues none).
383
400
  ...(besideOf ? { beside: besideOf } : {}),
401
+ // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
402
+ freeRequests: freeModelRequestsOf(deps.env),
384
403
  };
385
404
  // The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
386
405
  // has a cap. A park names the cap the loop holds the run to then (a raise's, else this one).
@@ -405,8 +424,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
405
424
  const start = learningStartOf(launch);
406
425
  // The revision's own skills are laid in the run's .agents/skills/ before they are read (main's server start laid them;
407
426
  // on the one store the claim does), from the revision row's texts (the body keeps only each file's SHA-256): each
408
- // folder not there yet, never over a learned skill or an earlier claim's.
409
- await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: launch.computer?.kind });
427
+ // folder not there yet, never over a learned skill or an earlier claim's. A desktop or a phone (the revision's computer
428
+ // setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
429
+ const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
410
430
  // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
411
431
  // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
412
432
  // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
@@ -440,7 +460,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
440
460
  store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
441
461
  })), revision.body.outputSchema) : {};
442
462
  // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
443
- await replayClaimed(deps.store, runRow.agentId, launch, firstChoice);
463
+ await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
444
464
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
445
465
  // answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
446
466
  const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
@@ -474,7 +494,9 @@ async function adapterSpec(launch, run, deps, claim, holds) {
474
494
  // spec builds too), on the claim's keys and the run's one ledger and redactor.
475
495
  // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
476
496
  const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
477
- const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
497
+ const fakes = deps.evalFakes?.(runRow.agentId);
498
+ const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
499
+ gate.askedOn(host);
478
500
  // The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
479
501
  // Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
480
502
  const results = new Map();
@@ -486,7 +508,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
486
508
  gate.learn(workflows);
487
509
  // The run's monid endpoints (monid-run.ts), one host tool each from its revision's pin, on the claim's keys and beside
488
510
  // its MCP tools in the loop's one catalog seam; their answers pass the run's one redactor as the other non-hand tools'.
489
- const monid = monidForClaim(body.monidPin, toolEnv, () => ws.workspace, claim.runId);
511
+ const monid = monidForClaim(revisionRow.monidPin ?? undefined, toolEnv, () => ws.workspace, claim.runId, () => launch.maxCostUsd !== undefined, fakes?.monid);
490
512
  const catalog = withMonid(mcp, monid && { ...monid, tools: monid.tools.map((tool) => answersCut(tool, cut)) });
491
513
  const nonHandTools = (await bindNonHandTools(host, revision.kind, granted, run, context, results, root, launch.plane, workflows, native, gate.permissions, tiers, catalog, () => route.model, replay)).map((tool) => answersCut(tool, cut));
492
514
  const sessionTools = [...handTools, ...nonHandTools];
@@ -498,9 +520,12 @@ async function adapterSpec(launch, run, deps, claim, holds) {
498
520
  // The one path for every harness.
499
521
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
500
522
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
501
- const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
523
+ const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills, ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
502
524
  const guidance = effortGuidance(launch.effort);
503
- const system = [environmentLine(), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line));
525
+ // The run's clock: a template eval case's (EvalFakes.now), else the real one.
526
+ const now = fakes?.now;
527
+ const zone = await runZone(deps.store, launch.inputOrigin);
528
+ const system = [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line));
504
529
  // The subagent tool, one of the session's own tools (no extension of its own): a child's tools are a subset of the
505
530
  // revision's grants (each by its session name: an MCP tool's wire name, the browser's registrations), its model the
506
531
  // agent's own or one of the tiers resolved above.
@@ -508,7 +533,7 @@ async function adapterSpec(launch, run, deps, claim, holds) {
508
533
  const browserNames = native.filter((extension) => extension.name !== "ask_person").flatMap((extension) => (extension.tools ?? []).map((tool) => tool.name));
509
534
  piTools.push(subagentTool({
510
535
  granted,
511
- sessionNames: (catalog) => (catalog === BROWSER_TOOL ? browserNames : monidSessionNames(catalog, body.monidPin) ?? [wireName(catalog)]),
536
+ sessionNames: (grant) => (grant === BROWSER_TOOL ? browserNames : catalogSessionNames(catalog, grant)),
512
537
  tier: (tier) => {
513
538
  const why = tierWhy.get(tier);
514
539
  if (why !== undefined)
@@ -517,12 +542,13 @@ async function adapterSpec(launch, run, deps, claim, holds) {
517
542
  const at = tierRoutes.get(subagentRoute(tier));
518
543
  if (!at)
519
544
  return { ref: { provider: PORT_PROVIDER, modelId: route.model } };
520
- // A capped run never sends a request it cannot price: an unpriced tier refuses the call, and the run goes on.
521
- if (at.unpriced && launch.maxCostUsd !== undefined)
545
+ // A capped run never sends a request it cannot price: an unpriced tier refuses the call, and the run goes on. A
546
+ // ChatGPT plan's tier is not unpriced: it costs the run no dollars (capModelOf).
547
+ if (at.unpriced && !at.provider.plan && launch.maxCostUsd !== undefined)
522
548
  return { why: `${at.model} has no known price here, so this run's cost cap cannot hold its requests.` };
523
549
  return { ref: { provider: tierProvider(subagentRoute(tier)), modelId: at.model } };
524
550
  },
525
- preamble: environmentLine(),
551
+ preamble: environmentLine(now, zone),
526
552
  }));
527
553
  }
528
554
  // The level pi thinks at: the launch's effort (the run's own, else its revision's, else the host's), every level pi's
@@ -590,32 +616,37 @@ async function adapterSpec(launch, run, deps, claim, holds) {
590
616
  // The run's computer as the claim made it, with the person's hold on a desktop or phone: the loop shows the hold up,
591
617
  // applies a take-over and a hand-back to it, and answers the computer call channel's rows on it.
592
618
  ...(loopComputer ? { computer: loopComputer } : {}),
619
+ // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
620
+ ...(tools.computer ? { scriptComputer: tools.computer } : {}),
621
+ // A computer that replaced an earlier claim's: the model is told once, on its next request (the loop's computer note).
622
+ ...(computer.replaced ? { computerNote: computerReplacedNote(computer.replaced) } : {}),
593
623
  workRoot: root,
594
- // The end's metrics and cost, from the run's journal, as the old per-run end path read them (metrics.ts runMetrics =
595
- // runs.ts storedMetrics/costOf). A pi run adds its effort, no model (metrics.ts).
624
+ // The end's cost: its booking's, by the one rule every reader of an ended run's cost takes (metrics.ts runCostOf):
625
+ // every model request its session's proxy booked (pi's own answers and its side calls: a learned workflow's nodes,
626
+ // web_search's hosted search with its fee), its paid tool calls (a Parallel search's, a monid call's, a person's
627
+ // browser time, each booked in its own session) and its decisions (a learned workflow's decision nodes, LS-07; one
628
+ // that reported none is unknown, never the cap's hold for it). A request a cancel or a stop cut while it streamed is
629
+ // booked at no known cost (the provider may bill what it streamed), so the run's cost is unknown, never the $0 its cut
630
+ // answer carries. One cheap read, apart from the metrics below, so metrics that run late never take the cost with them.
631
+ endCost: async () => endCostOf(runCostOf((await journalEntries(deps.journal(claim), context)))),
632
+ // The end's metrics, from the run's journal, as the old per-run end path read them (metrics.ts runMetrics =
633
+ // runs.ts storedMetrics). A pi run adds its effort, no model (metrics.ts).
596
634
  endPatch: async () => {
597
635
  // The root's entries and every conversation a task of the run owns (a subagent's): a child's requests are the run's.
598
636
  const entries = await agentEntriesOf(deps.journal(claim), context);
599
637
  // The path it took and the learned revision it ran on, for a run that learns (workflow-first.ts pathMetrics), by the
600
638
  // one classifier the cost per run reads back (runPathOverStore).
601
639
  const path = pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries);
602
- // Its cost is its booking's, as a CLI run's is (metrics.ts bookedSpend, the one reader): every model request its
603
- // session's proxy booked, pi's own answers and its side calls (a learned workflow's nodes, web_search's hosted search
604
- // with its fee) alike, and its decisions (a learned workflow's decision nodes, LS-07; one that reported none is
605
- // unknown, never the cap's hold for it). A request a cancel or a stop cut while it streamed is booked at no known cost
606
- // (the provider may bill what it streamed), so the run's cost is unknown, never the $0 its cut answer carries.
607
- const all = (await journalEntries(deps.journal(claim), context));
608
- const booked = bookedSpend(all, "model");
609
- // Its paid tool calls (a Parallel search's, a monid call's, a person's browser time), booked on the run's one ledger
610
- // (each on its cap, in its own session, not on the root), are the run's cost too; any part unknown leaves the run's unknown.
611
- const total = runEndCost({ model: booked.usd, paid: run.ledger?.paid ? run.ledger.paid.spentUsd() : 0, decisions: bookedSpend(all, "decisions").usd });
612
640
  // A run its learned workflow served first: that call is on the loop's record (no pi answer carries its tokens), so its
613
641
  // metrics are its booking's, as a CLI harness's run reads them: the workflow's nodes and the agent's own after a handback.
642
+ // An MCP tool called by a hashed wire name is counted under its catalog name, as its timeline names it.
643
+ const catalog = await hashedMcpOf(deps.store, claim.runId);
614
644
  const { metrics } = servedOf(entries)
615
- ? { metrics: cliRunMetrics(piShaped(entries), booked, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}), model: launch.model ? `${launch.model.provider}/${launch.model.modelId}` : route.model }) }
616
- : runMetrics(entries, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}) });
617
- // An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
618
- return { costUsd: total, metrics: { ...metrics, ...path } };
645
+ ? { metrics: cliRunMetrics(piShaped(entries), bookedSpend((await journalEntries(deps.journal(claim), context)), "model"), { ...(launch.effort !== undefined ? { effort: launch.effort } : {}), model: launch.model ? `${launch.model.provider}/${launch.model.modelId}` : route.model, catalog }) }
646
+ : runMetrics(entries, { ...(launch.effort !== undefined ? { effort: launch.effort } : {}), catalog });
647
+ // Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
648
+ // cost an earlier end stored).
649
+ return { metrics: { ...metrics, ...path } };
619
650
  },
620
651
  // A run started with hold: true holds its computer for its owner (computer-held.ts): the loop waits for their start
621
652
  // and release, and runs their calls on it.
@@ -624,7 +655,11 @@ async function adapterSpec(launch, run, deps, claim, holds) {
624
655
  // scratch swept), its computer let go, then its Workspace's end (Mode 2 sweeps the exec spill).
625
656
  // The run's Archil mount credential is revoked at its end on every outcome, even with no computer (the computer's
626
657
  // release revokes it too; revoke is idempotent, so a second call is a no-op). A run that minted none revokes nothing.
627
- release: () => holds.release(),
658
+ // At a park, a desktop or a phone is kept for the resume instead (spec-holds.ts SpecHolds.release `parked`), its mount
659
+ // credential with it, and the run's timeline is told so.
660
+ ...(computer.keeps ? { keptWords: computerKeptWords(computer.keeps) } : {}),
661
+ release: (how) => holds.release(how),
662
+ endCheckout: () => holds.endCheckout(),
628
663
  };
629
664
  }
630
665
  /** The host-tool ctx a non-hand tool is wrapped with (host-tools.ts hostToolOf): the run's own Harness (its commit,
@@ -699,7 +734,12 @@ export async function learnedWorkflowHostTool(opts) {
699
734
  return undefined;
700
735
  const flows = opts.workflows;
701
736
  const tiers = opts.tiers ?? new Map();
702
- const mcpTools = (opts.mcp?.tools ?? []).map((one) => opts.mcp.catalogOf(one.name)).filter((name) => typeof name === "string");
737
+ // Each MCP tool of the run by its catalog name, to the name the session's tools hold it by: what an MCP node calls,
738
+ // nested in the workflow's call.
739
+ const mcpTools = new Map((opts.mcp?.tools ?? []).flatMap((one) => {
740
+ const catalog = opts.mcp.catalogOf(one.name);
741
+ return typeof catalog === "string" ? [[catalog, one.name]] : [];
742
+ }));
703
743
  const byProvider = new Map([[PORT_PROVIDER, await opts.run.ledger.models(LEARNED_WORKFLOW_TOOL)]]);
704
744
  for (const [tier, model] of tiers)
705
745
  if ("model" in model)
@@ -718,8 +758,28 @@ export async function learnedWorkflowHostTool(opts) {
718
758
  const providers = await decisionProvidersIn(opts.env);
719
759
  const decisions = providers ? { decisions: { providers, book: opts.run.ledger.decisions, pause: (refusal) => opts.run.ledger.pause(refusal) } } : {};
720
760
  // A call node's native web_search goes through the session's port too, labelled web_search, as the run's own does.
721
- const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: tieredModels(byProvider), modelOf, search: () => opts.run.ledger.models(WEB_SEARCH_TOOL), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, decide: opts.permissions.decide, mcpTools, ...decisions, ...(opts.workspace ? { workspace: opts.workspace } : {}), ...(opts.modelName ? { modelName: opts.modelName } : {}), ...(opts.replay ? { replay: opts.replay } : {}) });
722
- return hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx) ?? undefined;
761
+ const tool = learnedWorkflowTool({ workflows: flows, granted: opts.granted, ...(opts.plane ? { plane: opts.plane } : {}), env: opts.env, work: opts.work, models: tieredModels(byProvider), modelOf, search: () => opts.run.ledger.models(WEB_SEARCH_TOOL), policy: opts.permissions.policy, denyFrom: opts.permissions.denyFrom, refresh: opts.permissions.refresh, mcpTools, nestedOf: (callId) => nestedBy.get(callId), ...decisions, ...(opts.workspace ? { workspace: opts.workspace } : {}), ...(opts.modelName ? { modelName: opts.modelName } : {}), ...(opts.replay ? { replay: opts.replay } : {}) });
762
+ const host = hostToolOf(LEARNED_WORKFLOW_TOOL, tool, opts.ctx);
763
+ if (!host)
764
+ return undefined;
765
+ // The tool nests calls (HostTool.nests): its MCP nodes are the session's tools called nested in it, which the harness
766
+ // hands each call (`nested`), each asked at the gate and recorded as its own; it runs again whole after a park or a
767
+ // crash, each node answered as it was the first time.
768
+ const nestedBy = new Map();
769
+ return {
770
+ ...host,
771
+ nests: true,
772
+ async call(args, context) {
773
+ if (context.nested)
774
+ nestedBy.set(context.callId, context.nested);
775
+ try {
776
+ return await host.call(args, context);
777
+ }
778
+ finally {
779
+ nestedBy.delete(context.callId);
780
+ }
781
+ },
782
+ };
723
783
  }
724
784
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
725
785
  * hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;
@@ -738,14 +798,16 @@ export function liveViewersOf(store, sealKey, claim, cut) {
738
798
  drop: (tag) => dropLiveViewer(store, claim, tag),
739
799
  };
740
800
  }
741
- /** `tool` with its answer's text, and a throw's message, cut by `cut` (the run's one redactor). */
801
+ /** `tool` with its answer's text, and a throw's message, cut by `cut` (the run's one redactor). A web call's answer is cut
802
+ * string by string inside its JSON (timeline/web-calls.ts webCut), so what the harness stores still parses and keeps
803
+ * its links whole for a grader's link check. */
742
804
  export function answersCut(tool, cut) {
743
805
  return {
744
806
  ...tool,
745
807
  call: async (args, context) => {
746
808
  try {
747
809
  const answer = await tool.call(args, context);
748
- return { ...answer, text: cut(answer.text) };
810
+ return { ...answer, text: webCut(tool.name, answer.text, cut) ?? cut(answer.text) };
749
811
  }
750
812
  catch (error) {
751
813
  if (error instanceof Error) {
@@ -768,7 +830,11 @@ export function answersCut(tool, cut) {
768
830
  export function buildToolHost(opts) {
769
831
  const liveAt = runnerLiveOf(opts.env, opts.sealKey);
770
832
  const { root, claim, run, life } = opts;
833
+ const { web, now, email } = opts.fakes ?? {};
771
834
  return {
835
+ ...(web ? { web } : {}),
836
+ ...(now ? { now } : {}),
837
+ ...(email ? { emailFake: email } : {}),
772
838
  // The run's directory and its per-claim environment: the hands come from runTools, so the non-hand tools get the run's
773
839
  // environment only.
774
840
  where: { root, work: root, ref: { id: claim.runId } },
@@ -798,6 +864,9 @@ export function buildToolHost(opts) {
798
864
  // What a tool files for the run's read (monid's whole answer past the model's cut) goes in the run's own Workspace, the
799
865
  // one its hands read: in Mode 2 its folder on the run's disk, never the local folder at `root`.
800
866
  workspace: opts.workspace,
867
+ // The trigger that started the run, and the agent's own settings: an email's run reads its thread alone (email/tools.ts).
868
+ ...(opts.launch?.trigger && opts.launch.inputOrigin?.kind === "trigger" ? { startedBy: { trigger: opts.launch.trigger, source: opts.launch.inputOrigin.source } } : {}),
869
+ ...(opts.toolSettings !== undefined ? { toolSettings: opts.toolSettings } : {}),
801
870
  };
802
871
  }
803
872
  /** The run's web host tools (tool-list.ts `host` rows: web_fetch, web_search, monid) as HostTool[], each bound through `host` by its