@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37

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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -14,6 +14,12 @@ export class ClaimRefused extends Error {
14
14
  export function endedBy(cancel) {
15
15
  return cancel ? "cancelled" : "stopped by a person";
16
16
  }
17
+ /** The run's end on a person's stop or a cancel, as every loop and the runner write it: state 'stopped', words that say
18
+ * which (endedBy), and the outcome the store tells them apart by: 'stopped' (the turn is over, never the run, as main's
19
+ * stop leaves a run: a message reopens it) or 'cancelled' (over for good). */
20
+ export function stopEnd(cancel) {
21
+ return { state: "stopped", summary: endedBy(cancel), outcome: cancel ? "cancelled" : "stopped" };
22
+ }
17
23
  /** The refusal a denied call's model reads: serve's own words for a call a person denied (refusal-words.ts refusedText,
18
24
  * one copy with the tool gate's), the person's note with it. Asked before its intent, the call never ran. */
19
25
  export function deniedText(tool, note) {
@@ -1,5 +1,5 @@
1
- import type { Context } from "@earendil-works/chord";
2
- import type { ConversationId, EntryRecord, StorageWrite } from "@earendil-works/pi-durable";
1
+ import type { Context } from "@earendil-works/chord/context";
2
+ import { type ConversationId, type EntryRecord, type StorageWrite } from "@earendil-works/pi-durable";
3
3
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
4
4
  import { type Command, type HeldState, type Journal, type LoopDeps } from "./loop-contract.js";
5
5
  import type { Staged } from "../store/store.js";
@@ -29,6 +29,10 @@ type Expected = {
29
29
  readonly run?: Staged["run"];
30
30
  readonly also?: Staged["also"];
31
31
  readonly take?: readonly number[];
32
+ readonly answer?: {
33
+ readonly command: number;
34
+ readonly value: unknown;
35
+ };
32
36
  };
33
37
  /**
34
38
  * The run's journal with the loop's staging matched to commits. stage() replaces what was staged, so the loop never
@@ -75,5 +79,9 @@ export declare function cutLast(entries: readonly EntryRecord[]): string | undef
75
79
  export declare function restartLimited(entries: readonly EntryRecord[]): string | undefined;
76
80
  /** The root conversation's entries, oldest first. */
77
81
  export declare function entriesOf(journal: Journal, conversationId: ConversationId, context: Context): Promise<EntryRecord[]>;
82
+ /** The entries of the run's agent conversations, in log order: its root's and each one a task of the run owns (a
83
+ * subagent's: runner/subagent.ts), never the loop's own session records. What a run's end reads its metrics and cost
84
+ * from, so a child's requests count as the run's. */
85
+ export declare function agentEntriesOf(journal: Journal, context: Context): Promise<EntryRecord[]>;
78
86
  export declare function findData<T>(entries: readonly EntryRecord[], kind: string, test: (data: T) => boolean): T | undefined;
79
87
  export {};
@@ -1,3 +1,4 @@
1
+ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
1
2
  import { KINDS } from "./journal-kinds.js";
2
3
  import { cutAtLimit } from "./loop-contract.js";
3
4
  import { PI_STOP } from "./pi-stop.js";
@@ -93,7 +94,8 @@ function merge(all) {
93
94
  // call where that record's batch was refused.
94
95
  const effect = all.find(({ expected }) => expected.run !== undefined || (expected.also ?? []).length > 0)?.at.id;
95
96
  // Each take keyed to the record its expectation matched: the store writes it only with that record's batch.
96
- const take = all.flatMap(({ expected, at }) => (expected.take ?? []).map((command) => ({ command, effect: at.id })));
97
+ // An answer is a value for one of the expectation's own take ids: it rides on that StagedTake.
98
+ const take = all.flatMap(({ expected, at }) => (expected.take ?? []).map((command) => (expected.answer?.command === command ? { command, effect: at.id, answer: expected.answer.value } : { command, effect: at.id })));
97
99
  return { ...(run ? { run } : {}), ...(also.length ? { also } : {}), ...(effect !== undefined && (run || also.length) ? { effect } : {}), ...(take.length ? { take } : {}) };
98
100
  }
99
101
  /** Whether `batches` write an entry of `kind` whose data `test` accepts. */
@@ -177,6 +179,25 @@ export async function entriesOf(journal, conversationId, context) {
177
179
  cursor = page.next;
178
180
  }
179
181
  }
182
+ /** The entries of the run's agent conversations, in log order: its root's and each one a task of the run owns (a
183
+ * subagent's: runner/subagent.ts), never the loop's own session records. What a run's end reads its metrics and cost
184
+ * from, so a child's requests count as the run's. */
185
+ export async function agentEntriesOf(journal, context) {
186
+ const ids = [];
187
+ for (let cursor = undefined;;) {
188
+ const page = await journal.scanConversations({ order: "ascending" }, 500, cursor, context);
189
+ for (const record of page.items)
190
+ if (Number(record.id) === Number(ROOT_CONVERSATION_ID) || record.owner !== undefined)
191
+ ids.push(record.id);
192
+ if (page.next === undefined)
193
+ break;
194
+ cursor = page.next;
195
+ }
196
+ const out = [];
197
+ for (const id of ids)
198
+ out.push(...(await entriesOf(journal, id, context)));
199
+ return out.sort((a, b) => Number(a.id) - Number(b.id));
200
+ }
180
201
  export function findData(entries, kind, test) {
181
202
  for (const entry of entries)
182
203
  if (entry.kind === kind && test(entry.data))
@@ -1,5 +1,6 @@
1
1
  import { type Store } from "../store/index.js";
2
- import { type ComputerDeps } from "../workspace/computer-deps.js";
2
+ import { type KeyEnv } from "../key-meta.js";
3
+ import { type ComputerDeps, type ComputerDepsOptions } from "../workspace/computer-deps.js";
3
4
  import type { LoopFactory } from "./loop-contract.js";
4
5
  import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
5
6
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
@@ -61,6 +62,17 @@ export declare function openRunnerStore(dataDir: string, env: NodeJS.ProcessEnv,
61
62
  * but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
62
63
  * a spread of the object or a spawn given it carries none. */
63
64
  export declare function runEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
65
+ /** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
66
+ * of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
67
+ * runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
68
+ * provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
69
+ * --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
70
+ * reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
71
+ export declare const runnerComputers: (store: Store, env: KeyEnv, sealKey: Buffer, own?: Pick<ComputerDepsOptions, "kinds" | "load" | "dockerPaths" | "hostAddresses" | "hostWhy" | "hub">) => {
72
+ computerForClaim: typeof import("../workspace/computer-deps.js").claimComputer;
73
+ computerDeps: ComputerDeps;
74
+ factories: import("../computer-keys.js").ProviderFactories;
75
+ };
64
76
  /** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
65
77
  * process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
66
78
  * run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
@@ -12,23 +12,32 @@
12
12
  // An error nothing handles exits 1 at once, said with its stack (lastResort).
13
13
  import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
14
14
  import { join, resolve } from "node:path";
15
+ import { PROVIDERS } from "@parcha/agentrun-computer";
16
+ import { ArchilSettingsEnvInvalid, archilSettingsFromEnv } from "../archil-settings.js";
15
17
  import { dockerPathsForRuns } from "../box-paths.js";
18
+ import { hostCommandRefusals } from "../computers.js";
16
19
  import { hostAddressesOnce } from "../docker-host-addresses.js";
20
+ import { claimInstallsStopped } from "../harness-install.js";
17
21
  import { HARNESS_TABLE_ENV } from "../harness-table.js";
18
22
  import { maxRunsOf } from "../host.js";
19
23
  import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
20
- import { durationMs } from "../print.js";
24
+ import { durationMs, runLine } from "../print.js";
21
25
  import { bootSealKey } from "../seal-key.js";
22
26
  import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
23
27
  import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
24
28
  import { SCHEMA_VERSION } from "../store/schema.js";
25
29
  import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
30
+ import { claimViewOpener } from "../computer-live.js";
31
+ import { runnerLiveOf } from "../live-reach.js";
32
+ import { envValue } from "../key-meta.js";
33
+ import { fauxComputers } from "../faux-computers.js";
26
34
  import { computerDepsFrom } from "../workspace/computer-deps.js";
27
35
  import { startJanitor } from "../workspace/computer-janitor.js";
28
36
  import { createDispatchLoop } from "./dispatch.js";
29
37
  import { resolveRunnerLoop } from "./harness-loops.js";
30
38
  import { routeOf } from "./model-route.js";
31
39
  import { runnerMemory } from "./memory-claim.js";
40
+ import { sweepEndedScratch } from "./scratch-sweep.js";
32
41
  import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
33
42
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
34
43
  /** A store this runner cannot use, or arguments it cannot take, in words a person starting it can act on. */
@@ -80,6 +89,15 @@ export function runEnv(env = process.env) {
80
89
  }
81
90
  return out;
82
91
  }
92
+ /** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
93
+ * of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
94
+ * runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
95
+ * provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
96
+ * --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
97
+ * reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
98
+ export const runnerComputers = (store, env, sealKey, own = {}) =>
99
+ // A runner on another host than its server (AGENTRUN_RUNNER_LIVE_HOST): its viewers answer there (live-reach.ts).
100
+ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runnerLiveOf(env, sealKey)), ...(envValue(env, FAUX_ENV) ? { faux: fauxComputers() } : {}), ...own });
83
101
  /** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
84
102
  * process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
85
103
  * run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
@@ -101,13 +119,17 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
101
119
  if (!sealKey)
102
120
  throw new RunnerRefused(`A runner needs the server's seal key (${SEAL_KEY_ENV}): start it through the server's launcher, which hands it over.`);
103
121
  const runs = runEnv(env);
104
- // The run's computer at its claim, composed once (workspace/computer-deps.ts): none for the runner's place, a box's
105
- // computer by the agent's setting, its keys read from the run environment first, then the store's sealed rows; a
106
- // Docker computer's mounts by where this process's Docker has the data directory (box-paths.ts), read once.
107
- const computers = computerDepsFrom({ env: runs, store, sealKey, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
122
+ // The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
123
+ // agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
124
+ // mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
125
+ // view opened with it.
126
+ const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
108
127
  const deps = {
109
128
  env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
110
129
  computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
130
+ // A run's log lines (a learning run's skipped generality check, a sweep that failed) on the runner's stderr, as its
131
+ // warnings are.
132
+ log: (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`),
111
133
  };
112
134
  return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
113
135
  }
@@ -173,6 +195,8 @@ export async function startRunnerProcess(options) {
173
195
  // warnings, said where the runner says its others (warn: stderr unless a test gives its own).
174
196
  if (options.janitor && typeof parts !== "function")
175
197
  janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
198
+ // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
199
+ await sweepEndedScratch(store, options.dataDir, { log: warn });
176
200
  runner = startRunner({
177
201
  store,
178
202
  createLoop,
@@ -199,6 +223,8 @@ export async function startRunnerProcess(options) {
199
223
  close: () => (closing ??= (async () => {
200
224
  // The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
201
225
  await Promise.all([janitor?.close(), runner.close()]);
226
+ // A first-use install its claims started, stopped as they let go: its npm ends before this process can.
227
+ await claimInstallsStopped();
202
228
  await store.close();
203
229
  held.release();
204
230
  })()),
@@ -327,6 +353,8 @@ function said(name, event) {
327
353
  return `Runner ${name} released ${event.runId} (${event.end})`;
328
354
  if (event.type === "claim-lost")
329
355
  return `Runner ${name} lost its claim on ${event.runId} (${event.why})`;
356
+ if (event.type === "started" || event.type === "ended")
357
+ return runLine(event);
330
358
  return undefined;
331
359
  }
332
360
  /** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
@@ -364,9 +392,13 @@ export async function runnerMain(argv, given = process.env, hooks = {}) {
364
392
  let holds;
365
393
  try {
366
394
  holds = runnerHolds(args, env);
395
+ // The Archil settings an operator sets, read by every run's claim here as the server reads them (archil-settings.ts):
396
+ // one of the region and S3 URL without the other, or a value the server would refuse, stops this start as it stops
397
+ // the server's.
398
+ archilSettingsFromEnv(env);
367
399
  }
368
400
  catch (error) {
369
- if (!(error instanceof RunnerRefused))
401
+ if (!(error instanceof RunnerRefused) && !(error instanceof ArchilSettingsEnvInvalid))
370
402
  throw error;
371
403
  console.error(`agentrun-serve runner: ${error.message}`);
372
404
  return 2;
@@ -27,12 +27,20 @@ export interface McpClaimOptions {
27
27
  now?: () => number;
28
28
  /** The authorization servers' network (mcp-oauth.ts). */
29
29
  network?: OAuthNetwork;
30
+ /** Whether this runner may reach a loopback address (McpForClaimOptions.loopback): a refresh's request to a loopback
31
+ * authorization server is sent only then. Absent, never. */
32
+ loopback?: boolean;
30
33
  /** For a github_app server (auth github_app, nothing sealed): the server's GitHub App mint and the run's repository
31
34
  * (runner/mcp-github.ts). None: such a server's calls are refused in words. */
32
35
  githubApp?: GithubAppAccess;
33
36
  /** For tests only (no environment or CLI flag maps onto it): the one origin a github_app server may have, a fake for
34
37
  * GitHub's hosted MCP (GITHUB_MCP_ORIGIN). */
35
38
  githubMcpOrigin?: string;
39
+ /** The run's redactors (runner/redact.ts, the spec's `cut`): every credential value this step hands the gateway (each
40
+ * header's value and a Bearer's bare token: a saved one, a refreshed OAuth token, a minted GitHub App token, a per_run
41
+ * server's handed one at the claim and at each fresh()) is held by them as it is handed over, before any call carries
42
+ * it. None: the gateway's per-call scrub alone. */
43
+ hold?: (values: string[]) => void;
36
44
  /** For tests: the timer a github_app token's refresh and expiry are armed on. */
37
45
  githubTimer?: GithubTimer;
38
46
  /** For tests: the timer a wait on another claim's refresh lease, and its next read of the row, are armed on. */
@@ -46,15 +54,14 @@ export interface McpClaimStep {
46
54
  /** Each pinned server's URL now, with its headers or why they can't be used: the run's gateway's `credentials`, which
47
55
  * it reads at every request, so a refresh or a removal here reaches a gateway already built. */
48
56
  readonly credentials: McpCredentials;
49
- /** Every credential value held, for the redaction set. */
50
- readonly secrets: ReadonlySet<string>;
51
57
  /** Refresh what has expired, and open the credentials again; then confirm the claim. Before a resumed loop's next
52
58
  * model request. */
53
59
  fresh(): Promise<void>;
54
60
  /** Drop every credential held: the loop ended, or the claim is lost. */
55
61
  release(): void;
56
- /** Before each call of `server` (the gateway's beforeCall): a github_app token whose App was disconnected or replaced
57
- * since it was minted is dropped, revoked, and the call refused in words. */
62
+ /** Before each call of `server` (the gateway's beforeCall): its row stamp read (opened again when it changed or its
63
+ * access token near its end refreshed behind the call while still valid, waited on once run out; its entry dropped when it is no longer saved), then a github_app token
64
+ * whose App was disconnected or replaced since it was minted is dropped, revoked, and the call refused in words. */
58
65
  beforeCall(server: string, signal: AbortSignal): Promise<void>;
59
66
  }
60
67
  /** The MCP step of `options.claim`: its pin made or read and checked, its credentials opened (refreshed as due). */
@@ -9,12 +9,20 @@
9
9
  // At every claim the pin is checked again: a pinned tool that is a meta tool now refuses the claim in words, nothing sent.
10
10
  //
11
11
  // The credentials. The pinned servers' credentials are unsealed (store/seal.ts openMcpCredential) into this step's
12
- // memory only: handed to the run's gateway, never written to the journal, a command row, the timeline or a log line. The
13
- // redaction set is fed from the same map. Both are dropped at release(), at the loop's end, or when the claim's signal
14
- // aborts. A credential that can't be used gives its server's calls a reason (mcp-probe.ts UNUSABLE) and they are refused
15
- // unsent: sealed under another key or for another origin than its row's url (damaged), a sign-in refused or expired
16
- // (signedOut), a refresh that got no answer (silent), an address the check refuses (blocked). A runner never starts
17
- // without the seal key (seal-key.ts bootSealKey), so a claim always has one.
12
+ // memory only: handed to the run's gateway, never written to the journal, a command row, the timeline or a log line.
13
+ // Every value handed over (a header's, a bearer's token alone, an access token refreshed mid-claim, a github_app token
14
+ // minted or minted again) is held by the run's redactors (`hold`) at that moment, through the one place an entry is
15
+ // made, so a log line or error text the run writes is cut of it as the gateway's own scrub cuts a call's answer. The
16
+ // entries are dropped at release(), at the loop's end, or when the claim's signal aborts. A credential that can't be
17
+ // used gives its server's calls a reason (mcp-probe.ts UNUSABLE) and they are refused unsent: sealed under another key
18
+ // or for another origin than its row's url (damaged), a sign-in refused or expired (signedOut), a refresh that got no
19
+ // answer (silent), an address the check refuses (blocked). A runner never starts without the seal key
20
+ // (seal-key.ts bootSealKey), so a claim always has one.
21
+ //
22
+ // A per_run server keeps no credential: the run's caller hands one with the run or a message (mcp_auth), sealed in the
23
+ // run's launch row for the run's life (store/seal.ts sealRunMcpAuth) and erased by the write that ends it. Each fresh()
24
+ // opens it again, so a message's new credential reaches the run's next model request; a run handed none gets its calls
25
+ // refused unsent (UNUSABLE.perRunMissing).
18
26
  //
19
27
  // fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
20
28
  // expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
@@ -30,19 +38,29 @@
30
38
  // authorization server may already have spent the old refresh token. A token still valid but near its expiry is
31
39
  // used at once and refreshed behind it, never holding the claim. After any awaited refresh the claim's epoch is
32
40
  // confirmed again: a claim lost meanwhile is Fenced, and the loop never starts.
41
+ //
42
+ // check(). Before each call leaves (the gateway's `before`), the server's row stamp is read (store.mcp.stamp: its url,
43
+ // auth, credential_changed_at and its token's end by the store's clock; no tools, no sealed bytes): a server removed
44
+ // since loses its entry, so the call is refused unsent; a credential replaced or a server moved since is opened again, so
45
+ // the next call sends the new one (or is refused for the move); and an OAuth access token within REFRESH_MARGIN_MS of its
46
+ // end is refreshed through open's lease path: behind the call while the token is still valid (the call goes at once on
47
+ // it), waited on only when it has run out. Concurrent calls to one server share one such open.
33
48
  import { randomUUID } from "node:crypto";
34
49
  import { EndpointRefused, REFRESH_REQUEST_MS, refreshed, refused, RequestUnsent, systemNetwork } from "../mcp-oauth.js";
35
50
  import { mcpPinOf } from "../mcp-gateway.js";
36
51
  import { META_REASON, metaToolOf } from "../mcp-meta.js";
37
- import { boundTool } from "../mcp-probe.js";
52
+ import { boundTool, credentialInQuery, credentialInQueryWords, shownUrl } from "../mcp-probe.js";
38
53
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
39
54
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "../github.js";
40
55
  import { githubTokens } from "./mcp-github.js";
41
56
  import { ClaimRefused } from "./loop-contract.js";
42
57
  import { REFRESH_MARGIN_MS, UNKNOWN_EXPIRY_MS, UNUSABLE } from "../mcp-probe.js";
43
58
  import { tokenLeftOf } from "../mcp-probe.js";
44
- import { openMcpCredential, sealMcpCredential } from "../store/seal.js";
59
+ import { openMcpCredential, openRunMcpAuth, sealMcpCredential } from "../store/seal.js";
45
60
  import { Fenced, MCP_REFRESH_CALL_MS } from "../store/index.js";
61
+ /** Every credential value of `headers`: each header's value, and its token alone with any one-word scheme taken off
62
+ * (`Bearer `), which a server may echo bare (as the gateway's scrub cuts them). */
63
+ const credentialValues = (headers) => Object.values(headers).flatMap((value) => [value, value.replace(/^[A-Za-z][A-Za-z0-9_-]*\s+(?=\S+$)/, "")]);
46
64
  /** Whether two sealed credentials are the same bytes (none equals none). */
47
65
  const sameSealed = (a, b) => (a === null || b === null ? a === b : Buffer.from(a).equals(Buffer.from(b)));
48
66
  /** A claim the MCP step refused, in the words a person reads: nothing was sent. */
@@ -65,10 +83,18 @@ export async function mcpClaim(options) {
65
83
  const holder = `${claim.runId}@${claim.epoch}:${randomUUID()}`;
66
84
  const pin = await pinOf(options);
67
85
  const credentials = Object.create(null);
68
- const secrets = new Set();
69
86
  // Refreshes started behind a token still valid: stopped at release.
70
87
  const behind = new AbortController();
71
88
  let released = false;
89
+ /** What each pinned server's entry was opened from (its row's url, auth and credential time, and an OAuth token's end
90
+ * on this claim's clock), which check() compares the row's stamp with. */
91
+ const stamps = new Map();
92
+ /** The servers check() found removed: nothing (a github_app token's refresh among it) puts their entry back. */
93
+ const gone = new Set();
94
+ /** The opens check() started, by server: concurrent calls share one. */
95
+ const reopening = new Map();
96
+ // Servers whose refresh behind a still-valid token is going: one at a time per server from this claim.
97
+ const behindGoing = new Set();
72
98
  // A github_app server's installation token: minted at each claim, refreshed mid-run, held here only.
73
99
  const github = githubTokens(options.githubApp, { now, ...(options.githubTimer ? { arm: options.githubTimer } : {}) });
74
100
  const release = () => {
@@ -77,7 +103,6 @@ export async function mcpClaim(options) {
77
103
  github.release();
78
104
  for (const name of Object.keys(credentials))
79
105
  delete credentials[name];
80
- secrets.clear();
81
106
  };
82
107
  signal.addEventListener("abort", release, { once: true });
83
108
  /** The OAuth token set refreshed at its authorization server, bounded: the new set, or why not. One request is sent per
@@ -90,7 +115,7 @@ export async function mcpClaim(options) {
90
115
  if (!set.tokens.refresh_token)
91
116
  return { refused: true };
92
117
  const call = AbortSignal.timeout(callMs);
93
- const reach = { allowed: await privateOAuthHosts(store) };
118
+ const reach = { allowed: await privateOAuthHosts(store), loopback: options.loopback === true };
94
119
  for (let tried = 0; tried < tries && !call.aborted; tried++) {
95
120
  // Every try before this one provably never left: nothing is spent.
96
121
  if (stop.aborted)
@@ -149,27 +174,36 @@ export async function mcpClaim(options) {
149
174
  return kept;
150
175
  };
151
176
  /** One pinned server's credential, opened, refreshed when due (awaited for an expired token; behind it for one near
152
- * its expiry). `again`: a row another claim's refresh left, opened as it is, never refreshed from here once more. */
177
+ * its expiry, at the claim and before a call alike). `again`: a row another claim's refresh left,
178
+ * opened as it is, never refreshed from here once more. */
153
179
  const open = async (name, pinnedUrl, again) => {
154
180
  const row = again ?? (await store.mcp.server(name));
155
181
  // Forgotten since the pin: its entry goes (an earlier open's URL and headers with it), so the gateway finds no URL
156
182
  // for it and refuses its calls unsent.
157
183
  if (!row) {
184
+ stamps.delete(name);
158
185
  delete credentials[name];
159
186
  return { awaited: false };
160
187
  }
188
+ gone.delete(name);
189
+ stamps.set(name, { url: row.url, auth: row.auth, changedAt: row.credentialChangedAt });
161
190
  const entry = (extra) => {
162
- if (released)
191
+ // Held by the run's redactor before anything else: a value opened is a value to cut, sent or not.
192
+ if (extra.headers)
193
+ options.hold?.(credentialValues(extra.headers));
194
+ if (released || gone.has(name))
163
195
  return;
164
196
  // Headers go only to the URL the run was pinned to: a server moved since is refused per call by the gateway.
165
197
  credentials[name] = { url: row.url, ...(extra.unopened ? { unopened: extra.unopened } : extra.headers && row.url === pinnedUrl ? { headers: extra.headers } : {}) };
166
- for (const value of Object.values(extra.headers ?? {}))
167
- secrets.add(value);
168
198
  };
169
199
  // A GitHub App's server keeps no credential: its token is minted for this run (awaited, so the claim is confirmed
170
200
  // after it), kept fresh mid-run, and never stored.
171
201
  if (row.auth === "github_app")
172
202
  return await github.open(name, entry), { awaited: true };
203
+ // A per_run server keeps none either: its credential is the one the run's caller handed it (mcp_auth), sealed in the
204
+ // run's launch, read again at every fresh() so a message's new one reaches the run's next request.
205
+ if (row.auth === "per_run")
206
+ return entry(await perRun(name, row.url)), { awaited: false };
173
207
  if (row.sealed === null)
174
208
  return entry({}), { awaited: false };
175
209
  // A seal problem first: no refresh is ever sent for a credential this runner cannot open.
@@ -191,6 +225,22 @@ export async function mcpClaim(options) {
191
225
  const readAt = now();
192
226
  const end = set.expires_at ? Date.parse(set.expires_at) : Date.parse(set.obtained_at) + UNKNOWN_EXPIRY_MS;
193
227
  const left = () => (row.tokenLeftMs === null ? end - now() : row.tokenLeftMs - (now() - readAt));
228
+ // The token's end as the store stamped it, for the per-call check: another claim's refresh moves it (stamp.tokenUntil).
229
+ // Read with the sealed set in the one row (never a second query): a refresh between two reads would pair the old token
230
+ // with the new token's end, and the old one would be sent past its expiry.
231
+ const until = row.tokenUntil;
232
+ stamps.set(name, { url: row.url, auth: row.auth, changedAt: row.credentialChangedAt, end: readAt + left(), until });
233
+ /** The refresh's outcome, put only while the server's stamp is still the credential this open read: a later open
234
+ * that read another one (the owner signed in again or replaced it, another claim's refresh moved its token) set the
235
+ * entry from that row, and a refresh of the old one that ends after it (failed past the old token's end, say) never
236
+ * writes over it. A later open of the same credential (a fresh(), a call's check) leaves it this refresh's to put. */
237
+ const settledEntry = (extra) => {
238
+ const now_ = stamps.get(name);
239
+ if (now_ && now_.url === row.url && now_.auth === row.auth && now_.changedAt === row.credentialChangedAt && now_.until === until)
240
+ entry(extra);
241
+ else if (extra.headers)
242
+ options.hold?.(credentialValues(extra.headers));
243
+ };
194
244
  if (left() > REFRESH_MARGIN_MS)
195
245
  return entry({ headers: bearer(set) }), { awaited: false };
196
246
  // Another claim's refresh left this row and it is still due: never refreshed from here once more.
@@ -240,7 +290,7 @@ export async function mcpClaim(options) {
240
290
  if ("blocked" in got) {
241
291
  await store.mcp.releaseRefresh(name, holder).catch(() => undefined);
242
292
  if (left() <= 0)
243
- entry({ unopened: `${UNUSABLE.blocked}: ${got.blocked}` });
293
+ settledEntry({ unopened: `${UNUSABLE.blocked}: ${got.blocked}` });
244
294
  return;
245
295
  }
246
296
  if ("set" in got) {
@@ -248,7 +298,7 @@ export async function mcpClaim(options) {
248
298
  // spent the old refresh token, so the new set is the only one any claim can use. The write is the server's row,
249
299
  // not the run's; entry() hands it to this step only while it is held.
250
300
  if (await keep(lease.row, { type: "oauth", set: got.set }))
251
- return entry({ headers: bearer(got.set) });
301
+ return settledEntry({ headers: bearer(got.set) });
252
302
  if (stop.aborted || released)
253
303
  return;
254
304
  // The credential changed while it refreshed (a newer set, an owner's save): use the row as it is now.
@@ -259,7 +309,7 @@ export async function mcpClaim(options) {
259
309
  // The sign-in is over: kept as expired, so no later claim tries the refresh token again. A credential changed
260
310
  // meanwhile is the one to use.
261
311
  if (await keep(lease.row, { ...oauth, expired: true }))
262
- return entry({ unopened: UNUSABLE.signedOut });
312
+ return settledEntry({ unopened: UNUSABLE.signedOut });
263
313
  if (stop.aborted || released)
264
314
  return;
265
315
  return void (await takeLeft(await store.mcp.server(name)));
@@ -271,7 +321,7 @@ export async function mcpClaim(options) {
271
321
  if (!("held" in got))
272
322
  await store.mcp.releaseRefresh(name, holder).catch(() => undefined);
273
323
  if (left() <= 0)
274
- entry({ unopened: UNUSABLE.silent });
324
+ settledEntry({ unopened: UNUSABLE.silent });
275
325
  }
276
326
  finally {
277
327
  // The lease is let go (kept, released, or left to lapse on a failed write): the claims waiting on it read the row.
@@ -279,17 +329,39 @@ export async function mcpClaim(options) {
279
329
  }
280
330
  };
281
331
  if (left() > 0) {
282
- // Still valid: used at once, refreshed behind it.
332
+ // Still valid: used at once, refreshed behind it (one at a time per server from this claim: a call that finds one
333
+ // going starts none), so an authorization server that is slow or down never holds a call whose token still works.
283
334
  entry({ headers: bearer(set) });
284
- void settle(AbortSignal.any([signal, behind.signal])).catch(() => undefined);
335
+ if (!behindGoing.has(name)) {
336
+ behindGoing.add(name);
337
+ void settle(AbortSignal.any([signal, behind.signal])).catch(() => undefined).finally(() => behindGoing.delete(name));
338
+ }
285
339
  return { awaited: false };
286
340
  }
341
+ // Run out: the refresh is waited on, bounded by its call's deadline.
287
342
  await settle(signal);
288
343
  return { awaited: true };
289
344
  };
345
+ /** The run's handed MCP credentials, opened from its launch: read once per fresh() (perRunRead), not once per server. */
346
+ let perRunRead;
347
+ /** A per_run server's headers for this run, from its launch; or why there are none. Only for the origin its url had
348
+ * when they were handed: a server moved since gets none. */
349
+ const perRun = async (name, url) => {
350
+ perRunRead ??= store.runs.launch(claim.runId).then((launch) => openRunMcpAuth(sealKey, claim.runId, launch.sealed));
351
+ const handed = await perRunRead;
352
+ if (handed === undefined)
353
+ return { unopened: UNUSABLE.damaged };
354
+ const given = Object.hasOwn(handed, name) ? handed[name] : undefined;
355
+ if (!given)
356
+ return { unopened: UNUSABLE.perRunMissing };
357
+ if (given.origin !== new URL(url).origin)
358
+ return { unopened: UNUSABLE.damaged };
359
+ return { headers: { ...given.headers } };
360
+ };
290
361
  const fresh = async () => {
291
362
  if (!pin || released)
292
363
  return;
364
+ perRunRead = undefined;
293
365
  let awaited = false;
294
366
  for (const [name, pinned] of Object.entries(pin))
295
367
  if ((await open(name, pinned.url)).awaited)
@@ -298,21 +370,66 @@ export async function mcpClaim(options) {
298
370
  if (awaited)
299
371
  await confirm(store, claim);
300
372
  };
373
+ const check = async (name) => {
374
+ if (!pin || released || !Object.hasOwn(pin, name))
375
+ return;
376
+ const stamp = await store.mcp.stamp(name);
377
+ if (released)
378
+ return;
379
+ if (!stamp) {
380
+ // Removed since: its entry goes, so its calls are refused unsent; nothing puts it back.
381
+ gone.add(name);
382
+ stamps.delete(name);
383
+ delete credentials[name];
384
+ return;
385
+ }
386
+ const was = stamps.get(name);
387
+ const changed = !was || gone.has(name) || was.url !== stamp.url || was.auth !== stamp.auth || was.changedAt !== stamp.credentialChangedAt;
388
+ // The token's end by the store's clock (tokenLeftMs), else as this claim opened it.
389
+ const left = stamp.tokenLeftMs ?? (was?.end !== undefined ? was.end - now() : null);
390
+ // And whether the row still holds the token this claim opened: another claim's refresh moves the row's token end (not
391
+ // its credential's change time), so the row has a fresh token while this claim holds the one about to expire.
392
+ const moved = stamp.auth === "oauth" && was?.until !== undefined && stamp.tokenUntil !== was.until;
393
+ // An entry that did not open (a refresh that failed or never answered, a sign-in that expired) is read again only when
394
+ // the row changed (the owner signed in again or replaced it) or another claim moved its token: never refreshed once
395
+ // more on its own, since a refresh that left may already have spent the refresh token.
396
+ const unopened = credentials[name]?.unopened !== undefined;
397
+ const due = moved || (!unopened && stamp.auth === "oauth" && left !== null && left <= REFRESH_MARGIN_MS);
398
+ if (!changed && !due)
399
+ return;
400
+ let going = reopening.get(name);
401
+ if (!going) {
402
+ going = open(name, pin[name].url).finally(() => reopening.delete(name));
403
+ reopening.set(name, going);
404
+ }
405
+ await going;
406
+ };
301
407
  await fresh();
408
+ // Before each call (the gateway's beforeCall; a throw refuses the call unsent): the server's
409
+ // row stamp first (removed: dropped and refused; changed: opened again; an access token near its end: refreshed under
410
+ // the lease, behind the call while still valid, waited on once run out), then a github_app token's App (disconnected or replaced since the mint: dropped and refused).
302
411
  const beforeCall = async (server, signal) => {
303
412
  signal.throwIfAborted();
413
+ if (released)
414
+ return;
415
+ await check(server);
304
416
  if (!released)
305
417
  await github.check(server);
306
418
  };
307
- return { pin, credentials, secrets, fresh, release, beforeCall };
419
+ return { pin, credentials, fresh, release, beforeCall };
308
420
  }
309
421
  /** The run's pin: read, and checked against the meta tools known now; or made at its first claim and written once. */
310
422
  async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN }) {
311
423
  // A github_app server anywhere but GitHub's hosted MCP ends the run here, before any token is minted or anything sent:
312
424
  // the App's tokens go to GitHub alone (github.ts githubMcpUrl, the one check).
313
425
  const offGithub = (server, url, auth) => {
426
+ // A URL with a credential in its query (a row saved before the save refused one) ends the run before it is pinned or
427
+ // anything sent; the URL is never named, its credential with it.
428
+ const inQuery = credentialInQuery(url);
429
+ if (inQuery)
430
+ throw new McpClaimRefused(`The MCP server ${server} can't be used: ${credentialInQueryWords(inQuery)} Nothing was sent.`);
314
431
  if (auth === "github_app" && !githubMcpUrl(url, githubMcpOrigin))
315
- throw new McpClaimRefused(`The MCP server ${server} (${url}) can't be used: ${GITHUB_MCP_ONLY}. Nothing was sent.`);
432
+ throw new McpClaimRefused(`The MCP server ${server} (${shownUrl(url)}) can't be used: ${GITHUB_MCP_ONLY}. Nothing was sent.`);
316
433
  };
317
434
  const stored = await store.mcp.pin(claim.runId);
318
435
  if (stored) {
@@ -1,8 +1,10 @@
1
- /** The App's answer for one repository: a token and when it expires (ms), or why not. */
1
+ import type { GithubPermissions } from "../github.js";
2
+ /** The App's answer for one repository: a token and when it expires (ms), or why not. `permissions` narrows the token
3
+ * below the App's own (a checkout's: contents read alone). */
2
4
  export type GithubAppMint = (target: {
3
5
  installation?: number;
4
6
  repo: string;
5
- }) => Promise<{
7
+ }, permissions?: GithubPermissions) => Promise<{
6
8
  ok: true;
7
9
  token: string;
8
10
  expires_at: number;
@@ -1,16 +1,9 @@
1
- // A github_app MCP server's credential for one run (the runner's MCP claim step, runner/mcp-claim.ts): an installation
2
- // token the server's GitHub App mints (github.ts mintInstallationToken, given here as `mint`, its App id and key bound by
3
- // the runner), narrowed to the run's repository. It is minted at every launch (each claim), held in the step's memory
4
- // only (never sealed into mcp_servers, the journal or run_live: it lasts an hour and is minted again at will), joins the
5
- // redaction set, and is minted again with REFRESH_BEFORE_MS left, mid-run, so a long run's calls never carry an expired
6
- // token. A token that could not be renewed answers its calls in words once it expires, never a crash. One claim per run
7
- // mints for itself: there is no stored token to share, so no refresh lease.
8
1
  /** How long before its expiry a token is minted again: GitHub's tokens last an hour, so at 55 minutes. */
9
2
  export const REFRESH_BEFORE_MS = 5 * 60_000;
10
3
  /** Why a github_app server's calls are refused unsent, in the words the gateway gives the model. */
11
4
  export const GITHUB_UNUSABLE = {
12
5
  noAccess: "this server has no GitHub App set up for its runs (Settings → GitHub)",
13
- noRepo: "this run names no GitHub repository, so the GitHub App has no repository to make a token for",
6
+ noRepo: "this run names no GitHub repository, so the GitHub App has no repository to make a token for. The server is connected: start the run with a repository (`repo` in the start body, or https://github.com/<owner>/<repo> in its first message), or bind the agent to one repository with a GitHub trigger",
14
7
  notInstalled: (repo) => `the GitHub App is not installed on ${repo}: install it from Settings → GitHub`,
15
8
  failed: (message) => `GitHub did not make a token for this run (${message})`,
16
9
  expired: (message) => `its GitHub App token expired and a new one could not be made (${message})`,