@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
@@ -1,7 +1,7 @@
1
1
  import type { HostTool, SessionMcp } from "@parcha/agentrun-kernel";
2
2
  import type { Harness } from "@earendil-works/pi-durable";
3
3
  import { type McpGatewayOptions } from "../mcp-gateway.js";
4
- import type { OAuthNetwork } from "../mcp-oauth.js";
4
+ import { type OAuthNetwork } from "../mcp-oauth.js";
5
5
  import type { Store, TriggerSettings } from "../store/index.js";
6
6
  import { type ApprovalPrice } from "../tool-gate.js";
7
7
  import { type AnswerData } from "./journal-kinds.js";
@@ -35,6 +35,9 @@ export interface McpForClaimOptions {
35
35
  /** A test's fake GitHub MCP origin, handed to the claim step (mcpClaim's githubMcpOrigin): for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP
36
36
  * (github.ts GITHUB_MCP_ORIGIN). */
37
37
  readonly githubMcpOrigin?: string;
38
+ /** Whether this runner may reach an MCP server whose URL is on loopback (AdapterSpecDeps.mcpLoopback): only a runner
39
+ * beside a local-install server is. Absent, never. */
40
+ readonly loopback?: boolean;
38
41
  /** For tests: the authorization servers' network, a refresh's bound, the gateway's upstream fetch and bounds, and the
39
42
  * timer a github_app token's refresh is armed on. */
40
43
  readonly network?: OAuthNetwork;
@@ -48,6 +51,8 @@ export interface McpForClaimOptions {
48
51
  connectMs?: number;
49
52
  };
50
53
  readonly githubTimer?: GithubTimer;
54
+ /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
55
+ readonly hold?: (values: string[]) => void;
51
56
  }
52
57
  /** A call as the loop's gate is asked about it: the tool by its catalog name. */
53
58
  export type McpGateCall = {
@@ -75,9 +80,6 @@ export interface ClaimMcp {
75
80
  * sent; or parked, answered the gate's waiting words marked parked, nothing sent), then its host tool from `wrapped`,
76
81
  * as the loop wrapped it. */
77
82
  session(wrapped: ReadonlyMap<string, HostTool>, gate: (call: McpGateCall) => Promise<McpGateAnswer>): SessionMcp;
78
- /** The credential values the gateway's calls in flight hold, for a redaction: each call's for as long as it is out,
79
- * with any token refreshed while it was; none when idle. */
80
- redactions(): string[];
81
83
  /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed), then the claim
82
84
  * confirmed: before a resumed loop's next model request. */
83
85
  fresh(): Promise<void>;
@@ -1,7 +1,9 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { wireName } from "../catalog.js";
3
3
  import { mcpGateway, noCallId } from "../mcp-gateway.js";
4
- import { argsPreview, mcpToolName, resumeText, RESUME_PREFIX, waitingText } from "../tool-gate.js";
4
+ import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
5
+ import { privateOAuthHosts } from "../mcp-private-hosts.js";
6
+ import { argsPreview, mcpToolName, RESUME_GO_ON, resumeText, RESUME_PREFIX, waitingText } from "../tool-gate.js";
5
7
  import { deniedText } from "./loop-contract.js";
6
8
  import { STOPPED_WHILE_WAITING } from "../refusal-words.js";
7
9
  import { endedAnswer, KINDS } from "./journal-kinds.js";
@@ -26,9 +28,11 @@ export async function mcpForClaim(options) {
26
28
  signal: held.signal,
27
29
  ...(options.bounds ? { bounds: options.bounds } : {}),
28
30
  ...(options.network ? { network: options.network } : {}),
31
+ ...(options.loopback ? { loopback: true } : {}),
29
32
  ...(githubApp ? { githubApp } : {}),
30
33
  ...(options.githubMcpOrigin ? { githubMcpOrigin: options.githubMcpOrigin } : {}),
31
34
  ...(options.githubTimer ? { githubTimer: options.githubTimer } : {}),
35
+ ...(options.hold ? { hold: options.hold } : {}),
32
36
  });
33
37
  }
34
38
  catch (error) {
@@ -40,9 +44,19 @@ export async function mcpForClaim(options) {
40
44
  held.abort();
41
45
  return undefined;
42
46
  }
47
+ const network = options.network ?? systemNetwork;
43
48
  const gateway = mcpGateway({
44
49
  pin,
45
50
  credentials: step.credentials,
51
+ // Each request's address checked as the server checks it at a save (mcp-oauth.ts mcpServerAt), with the owner's
52
+ // private-network hosts read now, and dialled at the address checked: a name that resolves somewhere private since the
53
+ // save, or a host the owner no longer allows, is refused unsent. A URL on loopback is reached only by a runner told
54
+ // so by the local-install server beside it, in its own process (options.loopback): never by what a store says, so
55
+ // one host's local install never opens loopback for another host's runner on a shared store.
56
+ reach: async (url, signal) => {
57
+ const at = await mcpServerAt(new URL(url), signal, network, { allowed: await privateOAuthHosts(options.store), loopback: options.loopback === true });
58
+ return "refused" in at ? { refused: at.refused } : { send: dialAt(network, at.address, options.fetch ?? fetch) };
59
+ },
46
60
  beforeCall: step.beforeCall,
47
61
  work: options.work,
48
62
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
@@ -100,7 +114,6 @@ export async function mcpForClaim(options) {
100
114
  return said(result.text, result.isError === true);
101
115
  },
102
116
  }),
103
- redactions: () => gateway.heldValues(),
104
117
  fresh: () => step.fresh(),
105
118
  release: () => held.abort(),
106
119
  };
@@ -159,5 +172,5 @@ export async function parkedFollowUp(mcp, options) {
159
172
  texts.push(resumeText({ tool: call.tool, call_id: call.callId }, argsPreview(call.args), answer.approved ? "allow" : "deny", { text: result.text, isError: result.isError === true }));
160
173
  callIds.push(call.callId);
161
174
  }
162
- return texts.length ? { text: texts.join("\n\n"), callIds } : undefined;
175
+ return texts.length ? { text: `${texts.join("\n\n")}\n\n${RESUME_GO_ON}`, callIds } : undefined;
163
176
  }
@@ -25,8 +25,21 @@ export type BookedSpend = {
25
25
  * or with no runner.turn yet (in flight, or cut off by a crash before its answer was booked), makes the sum unknown
26
26
  * (null), its known part kept, as sessionSpendOf counts it. A CLI harness's own record carries no per-request cost, nor do
27
27
  * a workflow's model nodes (pi-ai's $0 for a model it has no price for): their model requests' cost is this, the
28
- * booking's. */
29
- export declare function bookedSpend(entries: readonly EntryLike[], which: "model" | "paid" | "decisions"): BookedSpend;
28
+ * booking's. `side`: of the model requests, those booked as side calls (another model than the session's, or the host's
29
+ * own, as a learned workflow's node is: the proxy's `side`/`host`), which no answer of a pi run carries. */
30
+ export declare function bookedSpend(entries: readonly EntryLike[], which: "model" | "paid" | "decisions" | "side"): BookedSpend;
31
+ /** An agent run's cost as its end commit stores it: its model requests' (`model`), its paid tool calls' (`paid`, the
32
+ * run's ledger.paid) and its decisions' (`decisions`, a learned workflow's decision nodes, LS-07: bookedSpend over
33
+ * their own session's records, so one that reported no cost is unknown, never the cap's hold for it), summed; null (unknown) when any of them is. Never a known figure that leaves an unknown part out. */
34
+ export declare function runEndCost(parts: {
35
+ readonly model: number | null;
36
+ readonly paid: number | null;
37
+ readonly decisions: number | null;
38
+ }): number | null;
39
+ /** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
40
+ * its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
41
+ * past its model proxy) spent what no booking read: its cost is unknown, never $0. */
42
+ export declare function cliModelWorked(entries: readonly EntryLike[]): boolean;
30
43
  /** Whether a run's record carries no cost of its own, so its usage row and its live spend are its booking's: a CLI
31
44
  * harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
32
45
  * booking (adapters/pi.ts afterResponse). */
@@ -32,14 +32,18 @@ function sessionConversations(entries) {
32
32
  * or with no runner.turn yet (in flight, or cut off by a crash before its answer was booked), makes the sum unknown
33
33
  * (null), its known part kept, as sessionSpendOf counts it. A CLI harness's own record carries no per-request cost, nor do
34
34
  * a workflow's model nodes (pi-ai's $0 for a model it has no price for): their model requests' cost is this, the
35
- * booking's. */
35
+ * booking's. `side`: of the model requests, those booked as side calls (another model than the session's, or the host's
36
+ * own, as a learned workflow's node is: the proxy's `side`/`host`), which no answer of a pi run carries. */
36
37
  export function bookedSpend(entries, which) {
37
38
  const keyed = sessionConversations(entries);
38
39
  const paidConv = keyed.get(TOOL_SESSION);
39
40
  const decisionsConv = keyed.get(DECISION_SESSION);
40
41
  const conv = (e) => Number(e.conversationId);
41
- const chosen = (e) => (which === "paid" ? conv(e) === paidConv : which === "decisions" ? conv(e) === decisionsConv : conv(e) !== paidConv && conv(e) !== decisionsConv);
42
42
  const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
43
+ const model = (e) => conv(e) !== paidConv && conv(e) !== decisionsConv;
44
+ // The side calls among the model requests: each request that says so, by its conversation and turn.
45
+ const sides = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request && model(e) && (e.data?.side === true || typeof e.data?.host === "string")).map(turnOf));
46
+ const chosen = (e) => (which === "paid" ? conv(e) === paidConv : which === "decisions" ? conv(e) === decisionsConv : which === "side" ? model(e) && sides.has(turnOf(e)) : model(e));
43
47
  const answered = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.turn && chosen(e)).map(turnOf));
44
48
  // The model each request was sent on, by its turn (its runner.request's `model`).
45
49
  const sentOn = new Map(entries.filter((e) => e.kind === RUNNER_RECORDS.request && chosen(e)).map((e) => [turnOf(e), e.data?.model]));
@@ -86,6 +90,21 @@ export function bookedSpend(entries, which) {
86
90
  }
87
91
  return { usd: unpriced ? null : known, known, unpriced, requests, unmetered, models, tokens };
88
92
  }
93
+ /** An agent run's cost as its end commit stores it: its model requests' (`model`), its paid tool calls' (`paid`, the
94
+ * run's ledger.paid) and its decisions' (`decisions`, a learned workflow's decision nodes, LS-07: bookedSpend over
95
+ * their own session's records, so one that reported no cost is unknown, never the cap's hold for it), summed; null (unknown) when any of them is. Never a known figure that leaves an unknown part out. */
96
+ export function runEndCost(parts) {
97
+ return parts.model === null || parts.paid === null || parts.decisions === null ? null : parts.model + parts.paid + parts.decisions;
98
+ }
99
+ /** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
100
+ * its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
101
+ * past its model proxy) spent what no booking read: its cost is unknown, never $0. */
102
+ export function cliModelWorked(entries) {
103
+ return entries.some((e) => {
104
+ const role = e.data?.role;
105
+ return e.kind === KINDS.callStart || ((e.kind === KINDS.message || e.kind === KINDS.endOfRunTurn) && role === "model");
106
+ });
107
+ }
89
108
  /** Whether a run's record carries no cost of its own, so its usage row and its live spend are its booking's: a CLI
90
109
  * harness's record (`cli`), or a workflow's (its model nodes' answers carry pi-ai's $0). A pi run's answers carry their
91
110
  * booking (adapters/pi.ts afterResponse). */
@@ -55,6 +55,9 @@ export interface ModelRoute {
55
55
  readonly fetch?: typeof fetch;
56
56
  /** The catalog's cost of the model, tiers included: what the cap prices a request at before it leaves. */
57
57
  readonly cost?: RouteCost;
58
+ /** True when serve has no price for the model (runModels' `unpriced`): `cost` is then a placeholder of zeros, which the
59
+ * cap never reads as a price (capModelOf: price unknown, never $0). */
60
+ readonly unpriced?: boolean;
58
61
  /** The model's most output tokens (its catalog ceiling): the cap's output bound, null when the catalog names none. */
59
62
  readonly outputCeiling?: number | null;
60
63
  }
@@ -33,7 +33,10 @@ export async function routeOf(model, env = process.env, tier = "default", wires
33
33
  const chosen = await chooseModel(env, model, tier);
34
34
  if ("why" in chosen)
35
35
  throw new Error(chosen.why);
36
- const { models, unpriced } = await runModels(env, tier === "default" ? model : undefined, [tier]);
36
+ // A tier's own model, when one is named (a subagent's model_tiers), is the one registered, at the tier's price: a gateway
37
+ // lists only the models it is given, so the host's model for the tier in its place would leave this one unknown.
38
+ const named = tier !== "default" && typeof model === "string" ? { [tier]: model } : {};
39
+ const { models, unpriced } = await runModels(env, tier === "default" ? model : undefined, [tier], undefined, named);
37
40
  const target = models.getModel(chosen.model.provider, chosen.model.modelId);
38
41
  if (!target)
39
42
  throw new Error(`no model ${chosen.model.provider}/${chosen.model.modelId} here`);
@@ -43,7 +46,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
43
46
  // What the model takes as input and its input limits, on every wire: pi's session sends a model that takes no images
44
47
  // pi-ai's placeholder in place of one, and pi's read holds an image to the model's limits (port-models.ts sessionModel).
45
48
  const sees = { ...(target.input ? { input: target.input } : {}), ...(target.inputLimits ? { inputLimits: target.inputLimits } : {}) };
46
- const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, outputCeiling: target.maxTokens ?? null, like: sees };
49
+ const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
47
50
  // An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
48
51
  if (chosen.model.provider === "anthropic") {
49
52
  return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
@@ -0,0 +1,60 @@
1
+ import type { Workspace } from "../workspace/workspace.js";
2
+ import type { GithubAppMint } from "./mcp-github.js";
3
+ import type { AdapterSpecDeps } from "./adapter-run-spec.js";
4
+ /** What an agent's revision keeps of its definition's `checkout` (validate.ts CHECKOUTS; `none` keeps nothing). */
5
+ export type Checkout = "pull_request";
6
+ /** The folder, in the run's own, the checkout lands in. */
7
+ export declare const CHECKOUT_DIR = "repo";
8
+ /** How long the whole checkout may take: inside Archil's exec bound, on either mode. */
9
+ export declare const CHECKOUT_MS = 295000;
10
+ /** What the checkout gives the run's claim: the line its system prompt carries, and its removal. */
11
+ export interface PrCheckout {
12
+ /** One line for the run's system prompt: where the checkout is and what it holds, or why there is none. */
13
+ readonly note: string;
14
+ /** The checkout removed from the run's folder: at the claim's release. A failure throws, for the release to log. */
15
+ end(): Promise<void>;
16
+ }
17
+ export interface PrCheckoutOptions {
18
+ /** The run's Workspace, whose exec runs the fetch. */
19
+ readonly workspace: Workspace;
20
+ /** The run's first input (its launch's): its payload tag names the pull request. */
21
+ readonly input: unknown;
22
+ /** Whether a github trigger started the run (its launch's inputOrigin): only then is its payload tag the server's own,
23
+ * and read. Anyone may write the tag's text into a run of their own. */
24
+ readonly fromGitHub?: boolean;
25
+ /** The server's GitHub App mint, when it has an App the runner can open: none, the fetch is anonymous. */
26
+ readonly mint?: GithubAppMint;
27
+ /** The token revoked at GitHub once the fetch is done: best effort, a failure leaves it to its hour. */
28
+ readonly revoke?: (token: string) => Promise<void>;
29
+ /** Each secret the checkout holds (the token, its header), handed to the run's redactor before it is used. */
30
+ readonly hold?: (secrets: readonly string[]) => void;
31
+ /** GitHub's site, where the repository is fetched from: a test's own (a folder of bare repositories, or a git server
32
+ * on loopback). Absent, https://github.com. */
33
+ readonly web?: string;
34
+ /** Ends the fetch at once: the claim's signal, aborted by a person's stop too. The checkout's removal is handed to
35
+ * `held` before the fetch starts, so a fetch cut short leaves its folder to the claim's release. */
36
+ readonly signal?: AbortSignal;
37
+ /** The checkout's removal, given the moment the fetch starts (the spec's holds), so whatever ends the claim removes it. */
38
+ readonly held?: (part: {
39
+ end(): Promise<void>;
40
+ }) => void;
41
+ readonly timeoutMs?: number;
42
+ }
43
+ /** The pull request `options.input` names, checked out in the run's folder at its head. Never throws for a checkout that
44
+ * could not be made: the run is told why, and reads the change some other way. */
45
+ export declare function prCheckout(options: PrCheckoutOptions): Promise<PrCheckout>;
46
+ /** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
47
+ * MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
48
+ * moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. */
49
+ export declare function prCheckoutForClaim(deps: Pick<AdapterSpecDeps, "store" | "sealKey" | "githubApi" | "githubWeb">, workspace: Workspace, launch: {
50
+ readonly input: unknown;
51
+ readonly repo?: string | undefined;
52
+ readonly inputOrigin?: {
53
+ readonly kind: string;
54
+ readonly source?: string;
55
+ } | undefined;
56
+ }, redact: {
57
+ hold(values: readonly string[]): void;
58
+ }, signal?: AbortSignal, held?: (part: {
59
+ end(): Promise<void>;
60
+ }) => void): Promise<PrCheckout>;
@@ -0,0 +1,176 @@
1
+ // A run's checkout of the pull request it was started for, made by the server before the first turn when the agent's
2
+ // definition says `checkout: pull_request` (a template's manifest sets it). The agent then starts with the repository at
3
+ // the pull request's head in `repo/` of its folder, its base and their merge base fetched beside it, and never holds a
4
+ // GitHub token: the fetch is the server's own, one exec on the run's Workspace (Mode 1 a process on this machine, Mode 2
5
+ // Archil's serverless exec over the run's folder), never a command of the agent's.
6
+ //
7
+ // What it reads of the run: its first message's payload tag alone (github.ts githubPullOf), which the server wrote from a
8
+ // signed GitHub delivery: the repository, the pull request's number, its head and its base. Nothing else names a
9
+ // repository to fetch.
10
+ //
11
+ // The credential: an installation token of the server's GitHub App, minted for that one repository with
12
+ // {contents: "read"} alone, handed to the exec on its stdin (Archil's: a spill file deleted on every path), turned there
13
+ // into an Authorization header in git's environment (GIT_CONFIG_COUNT), scoped to GitHub's site. It is never in argv,
14
+ // .git/config, the remote's URL, the run's folder, an env the agent's commands get, or the log (it joins the run's
15
+ // redactor). No App, or one not installed on the repository: the fetch is anonymous, which a public repository answers.
16
+ // The token is revoked once the fetch is done (GitHub's DELETE /installation/token), and is never kept.
17
+ //
18
+ // Git there reads no system or global config (no filter, textconv or fsmonitor a machine's config could attach), fetches
19
+ // no tags and no submodules, and checks out with the repository's own config alone, which this exec wrote.
20
+ //
21
+ // What the run is told: one line in its system prompt, the checkout's facts, or why there is none and that the GitHub
22
+ // tools can read the change instead. The checkout is removed when the claim lets go (spec-holds.ts), and made again by
23
+ // the next claim of the same run.
24
+ import { randomUUID } from "node:crypto";
25
+ import { GITHUB_WEB, githubPullOf } from "../github.js";
26
+ import { isObject } from "../validate.js";
27
+ import { COMMAND_MAX_MS } from "../workspace/archil-exec.js";
28
+ import { shellEnv } from "../workspace/hands.js";
29
+ import { githubAppAccess } from "./github-app.js";
30
+ /** The folder, in the run's own, the checkout lands in. */
31
+ export const CHECKOUT_DIR = "repo";
32
+ /** How long the whole checkout may take: inside Archil's exec bound, on either mode. */
33
+ export const CHECKOUT_MS = COMMAND_MAX_MS;
34
+ /** The commits each side is first fetched with, then deepened by (doubling) until the merge base is in: about 3,200
35
+ * commits back at most, past which the run is told there is no merge base and the base's diff is the two-dot one. A merge
36
+ * base found is taken only when no shallow edge lies outside its ancestry: a history cut short can show an older common
37
+ * commit (a long branch that merged an old side branch) while the path to the true merge base is cut off, so the fetch
38
+ * deepens until every edge is at or behind the merge base it found. Each fetch runs with git's auto maintenance off: a
39
+ * fetch otherwise starts a detached gc that writes into .git/objects while the checkout's removal deletes it. */
40
+ const DEPTH = 50;
41
+ const DEEPENS = 6;
42
+ /** The file in the checkout's .git naming the claim that made it: a removal takes only its own claim's checkout. */
43
+ const OWNER_FILE = "agentrun-claim";
44
+ /** The exec's script: $1 the remote's URL (no credential), $2 the head, $3 the base (or empty), $4 the folder, $5 the
45
+ * URL prefix the header is for, $6 this claim's checkout id (written to .git/${OWNER_FILE}). Its stdin's first line is
46
+ * an Authorization header, or empty for an anonymous fetch. Its exit codes name the step that failed (10 the folder, 11 the fetch, 12 the checkout); on success it prints the merge
47
+ * base, empty when none was found. */
48
+ const SCRIPT = `set -u
49
+ url=$1 head=$2 base=$3 dir=$4 scope=$5 claim=$6
50
+ IFS= read -r auth || true
51
+ export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null
52
+ if [ -n "\${auth:-}" ]; then export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.$scope.extraheader" GIT_CONFIG_VALUE_0="$auth"; fi
53
+ auth=
54
+ rm -rf "\${dir:?}"
55
+ git init -q "$dir" >/dev/null 2>&1 && cd "$dir" && printf '%s\\n' "$claim" > .git/${OWNER_FILE} && git remote add origin "$url" || exit 10
56
+ fetch() { git -c maintenance.auto=false -c gc.auto=0 fetch -q --no-tags --no-recurse-submodules origin "$@" "$head" \${base:+"$base"}; }
57
+ fetch --depth=${DEPTH} || exit 11
58
+ mb=
59
+ settled() {
60
+ [ -n "$mb" ] || return 1
61
+ [ -s .git/shallow ] || return 0
62
+ while IFS= read -r edge; do git merge-base --is-ancestor "$edge" "$mb" 2>/dev/null || return 1; done < .git/shallow
63
+ }
64
+ if [ -n "$base" ]; then
65
+ n=${DEPTH} i=0
66
+ while :; do
67
+ mb=$(git merge-base "$base" "$head" 2>/dev/null) || mb=
68
+ settled && break
69
+ [ "$i" -lt ${DEEPENS} ] || { mb=; break; }
70
+ fetch --deepen=$n || exit 11
71
+ n=$((n * 2)) i=$((i + 1))
72
+ done
73
+ fi
74
+ git update-ref refs/pr/head "$head" || exit 12
75
+ if [ -n "$base" ]; then git update-ref refs/pr/base "$base" || exit 12; fi
76
+ if [ -n "$mb" ]; then git update-ref refs/pr/merge-base "$mb" || exit 12; fi
77
+ git -c advice.detachedHead=false checkout -q --detach "$head" || exit 12
78
+ printf '%s\\n' "$mb"
79
+ `;
80
+ const noCheckout = (note) => ({ note, end: async () => { } });
81
+ /** The words of a failed exec, with the secrets cut and its last lines kept. */
82
+ const tail = (text, secrets) => {
83
+ let cut = text;
84
+ for (const secret of secrets)
85
+ cut = cut.split(secret).join("[redacted]");
86
+ const lines = cut.trim().split("\n").filter(Boolean);
87
+ return lines.slice(-3).join(" / ").slice(0, 400);
88
+ };
89
+ /** The pull request `options.input` names, checked out in the run's folder at its head. Never throws for a checkout that
90
+ * could not be made: the run is told why, and reads the change some other way. */
91
+ export async function prCheckout(options) {
92
+ const { workspace } = options;
93
+ const pull = githubPullOf(isObject(options.input) ? options.input.content : options.input, { payload: options.fromGitHub === true });
94
+ if (!pull)
95
+ return noCheckout("No checkout was made: this run was not started by a GitHub pull request event, so there is no repo/ folder. Read the change through the GitHub tools if you have them.");
96
+ const web = (options.web ?? GITHUB_WEB).replace(/\/+$/, "");
97
+ const name = `${pull.repo}#${pull.number}`;
98
+ // The token: the App's, for this repository alone, contents read alone. None (no App, not installed, GitHub said no):
99
+ // the fetch is anonymous, and the words say which, in case the repository turns out to be private.
100
+ let token;
101
+ let anonymous = "";
102
+ if (options.mint) {
103
+ try {
104
+ const got = await options.mint({ repo: pull.repo, ...(pull.installation !== undefined ? { installation: pull.installation } : {}) }, { contents: "read" });
105
+ if (got.ok)
106
+ token = got.token;
107
+ else
108
+ anonymous = got.reason === "not_installed" ? `the GitHub App is not installed on ${pull.repo}` : got.message;
109
+ }
110
+ catch (error) {
111
+ anonymous = `GitHub did not make a token (${error?.message ?? error})`;
112
+ }
113
+ }
114
+ else
115
+ anonymous = "this server has no GitHub App";
116
+ const header = token ? `Authorization: Basic ${Buffer.from(`x-access-token:${token}`, "utf8").toString("base64")}` : "";
117
+ const secrets = token ? [token, header, header.slice("Authorization: Basic ".length)] : [];
118
+ if (secrets.length)
119
+ options.hold?.(secrets);
120
+ // This claim's checkout, by an id of its own: a claim that lost its lease and lets go late removes only the folder it
121
+ // made, never the one a later claim of the run is fetching or reading (that claim's fetch replaces a stale one itself).
122
+ const claim = randomUUID();
123
+ const removal = async () => {
124
+ const result = await workspace.exec(["sh", "-c", `[ "$(cat "\${1:?}/.git/${OWNER_FILE}" 2>/dev/null)" = "$2" ] || exit 0; rm -rf -- "\${1:?}"`, "sh", CHECKOUT_DIR, claim], { env: shellEnv(), timeoutMs: CHECKOUT_MS });
125
+ if (result.code !== 0)
126
+ throw new Error(`the run's ${CHECKOUT_DIR}/ checkout could not be removed (exit ${result.code ?? result.signal}): ${tail(result.stderr, secrets)}`);
127
+ };
128
+ const failed = async (why) => {
129
+ // What a failed fetch left (a half folder) goes now: the run is told there is none.
130
+ await removal().catch(() => { });
131
+ return noCheckout(`The pull request ${name} could not be checked out (${why}), so there is no ${CHECKOUT_DIR}/ folder: read the change through the GitHub tools (its diff, and each file at the head sha ${pull.head}).`);
132
+ };
133
+ // From here a folder may exist: its removal is the claim's to run, whatever ends it.
134
+ options.held?.({ end: removal });
135
+ let result;
136
+ try {
137
+ result = await workspace.exec(["sh", "-c", SCRIPT, "sh", `${web}/${pull.repo}.git`, pull.head, pull.base ?? "", CHECKOUT_DIR, `${web}/`, claim], { env: shellEnv(), stdin: Buffer.from(`${header}\n`, "utf8"), timeoutMs: options.timeoutMs ?? CHECKOUT_MS, ...(options.signal ? { signal: options.signal } : {}) });
138
+ }
139
+ catch (error) {
140
+ // Cut short (a stop, a lost claim): the claim's release removes what the fetch made (`held`).
141
+ if (options.signal?.aborted)
142
+ throw error;
143
+ return failed(`the fetch could not run: ${tail(String(error?.message ?? error), secrets)}`);
144
+ }
145
+ finally {
146
+ // The fetch is the token's one use: it goes now, not in an hour.
147
+ if (token && options.revoke)
148
+ await options.revoke(token).catch(() => { });
149
+ }
150
+ if (result.timedOut)
151
+ return failed(`the fetch took more than ${Math.round((options.timeoutMs ?? CHECKOUT_MS) / 1000)} s`);
152
+ if (result.code !== 0) {
153
+ const step = result.code === 10 ? "its folder could not be made" : result.code === 11 ? `${web}/${pull.repo} did not give its commits${token ? "" : `, fetched with no token: ${anonymous}`}` : result.code === 12 ? "its head could not be checked out" : `git ended with ${result.code ?? result.signal}`;
154
+ const said = tail(result.stderr, secrets);
155
+ return failed(said ? `${step}: ${said}` : step);
156
+ }
157
+ const mergeBase = Buffer.from(result.stdout).toString("utf8").trim();
158
+ return { note: checkoutNote(pull, /^[0-9a-f]{40}$/.test(mergeBase) ? mergeBase : undefined), end: removal };
159
+ }
160
+ /** The line a run with a checkout is told. */
161
+ function checkoutNote(pull, mergeBase) {
162
+ const base = pull.base === undefined
163
+ ? "Its base was not named by the event, so only the head is there."
164
+ : mergeBase === undefined
165
+ ? `Its base ${pull.base} is fetched too (ref pr/base), but no merge base was found within ${DEPTH * 2 ** DEEPENS} commits: diff against pr/base.`
166
+ : `Its base ${pull.base} (ref pr/base) and their merge base ${mergeBase} (ref pr/merge-base) are fetched too: read the change with \`git diff pr/merge-base pr/head\`.`;
167
+ return `The pull request ${pull.repo}#${pull.number} is checked out in ${CHECKOUT_DIR}/, detached at its head ${pull.head} (ref pr/head), by the server before this run began. ${base} It is a shallow clone, and no credential is kept in it.`;
168
+ }
169
+ /** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
170
+ * MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
171
+ * moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. */
172
+ export async function prCheckoutForClaim(deps, workspace, launch, redact, signal, held) {
173
+ const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
174
+ const access = await githubAppAccess(deps.store, deps.sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, hold: (values) => redact.hold(values), ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
175
+ return prCheckout({ workspace, input: launch.input, fromGitHub, ...(access ? { mint: access.mint } : {}), ...(access?.revoke ? { revoke: access.revoke } : {}), hold: (secrets) => redact.hold(secrets), ...(deps.githubWeb ? { web: deps.githubWeb } : {}), ...(signal ? { signal } : {}), ...(held ? { held } : {}) });
176
+ }
@@ -1,3 +1,4 @@
1
+ import type { DraftDecisions } from "../learn/skills.js";
1
2
  import type { EndOfRunTurn } from "./loop-contract.js";
2
3
  /** How long a run's end-of-run turn may take before it is aborted and the run ends without it. */
3
4
  export declare const REFLECT_TIMEOUT_MS: number;
@@ -55,11 +56,13 @@ export interface ReflectDeps {
55
56
  readonly promptFacts: (runId: string, agentId: string) => Promise<{
56
57
  active: number;
57
58
  tools: readonly string[];
59
+ decisions?: DraftDecisions;
58
60
  draftFor?: readonly string[];
59
61
  described?: readonly {
60
62
  readonly name: string;
61
63
  readonly does: string;
62
64
  }[];
65
+ workflows?: false;
63
66
  }>;
64
67
  /** What the person said in the run, and a trigger's input, as the checks and the grader read them. */
65
68
  readonly asked: (runId: string) => Promise<{
@@ -83,6 +86,22 @@ export interface ReflectDeps {
83
86
  /** The grade model the server names (learning.ts gradeModelOf: --grade-model, AGENTRUN_SERVE_GRADE_MODEL, else
84
87
  * AGENT_MODEL_STRONG), carried on the learning run's launch; none, the agent's own model grades it, as main's. */
85
88
  readonly gradeModel?: string;
89
+ /** The cap the learning run's grade runs under, read once the turn closed (learning-end.ts gradeCapOf): what the run's
90
+ * cap leaves once everything the run spent is counted, carried on the learning run's launch as its own cap, so the
91
+ * grade never takes the run past its cap. Undefined for an uncapped run: its grade is capped by nothing. */
92
+ readonly gradeCap?: (runId: string) => Promise<number | undefined>;
93
+ /** Which end of the run this is: 1, its first (the default); an end after a follow-up opened the run again is the next
94
+ * round, asked anew (its prompt says it looked back before), kept as a proposal of its own beside the earlier rounds'
95
+ * (every row the hook gives carries it), graded and merged by a learning run of its own. */
96
+ readonly round?: number;
97
+ /** A later round's: what the round before it kept of the run's spend (its job's and its look-back's), so the follow-up's
98
+ * own share, between that look-back and this one, is kept apart (`follow_up_usd`); and whether it was asked its turn
99
+ * (`looked`: a round cut before it was asked says nothing of looking back before). */
100
+ readonly before?: {
101
+ readonly job_cost_usd?: number | null;
102
+ readonly look_back_usd?: number | null;
103
+ readonly looked?: boolean;
104
+ };
86
105
  /** The turn's deadline. Default REFLECT_TIMEOUT_MS. Its re-ask is inside it. */
87
106
  readonly deadlineMs?: number;
88
107
  /** For tests: the clock the turn's deadline is measured by. Default Date.now. */
@@ -28,9 +28,12 @@ function dryRunFailure(checked) {
28
28
  const found = problems.find((problem) => problem?.rule === "workflow" && typeof problem.path === "string" && typeof problem.detail === "string" && problem.detail.startsWith(DRY_RUN_FAILED));
29
29
  return found ? { path: found.path, detail: found.detail } : undefined;
30
30
  }
31
+ /** `rows` with round `round` on each learning row (none on a run's first, round 1). */
32
+ const roundOf = (rows, round) => !rows || round === 1 ? rows : { also: rows.also.map((row) => (row.table === "learning_proposals" || row.table === "learning_run" ? { ...row, row: { ...row.row, round } } : row)) };
31
33
  /** The end-of-run turn for runs that learn. */
32
34
  export function createReflectHook(deps) {
33
- return async (input) => {
35
+ const round = deps.round ?? 1;
36
+ const hook = async (input) => {
34
37
  const facts = await deps.facts(input.runId);
35
38
  if (!facts.learns)
36
39
  return undefined;
@@ -54,18 +57,22 @@ export function createReflectHook(deps) {
54
57
  // spend so far is the job's.
55
58
  const answeredAt = new Date(now()).toISOString();
56
59
  const job = facts.costUsd;
60
+ // A later round's: the follow-up's own spend, the run's spend now less what the round before it kept (its job's and
61
+ // its look-back's), unknown when any is.
62
+ const earlier = deps.before;
63
+ const followUp = round === 1 ? {} : { follow_up_usd: job === null || typeof earlier?.job_cost_usd !== "number" || typeof earlier.look_back_usd !== "number" ? null : Math.max(0, Math.round((job - earlier.job_cost_usd - earlier.look_back_usd) * 1e9) / 1e9) };
57
64
  // closeLearning: what looking back cost, the run's spend once the turn closed (its re-ask included) less the job's,
58
65
  // unknown when either is. Kept with every end the turn reaches from here, beside when the job answered and its cost.
59
66
  const looked = async (rows) => {
60
67
  const total = (await deps.facts(input.runId)).costUsd;
61
- const answered = { answered_at: answeredAt, job_cost_usd: job, look_back_usd: total === null || job === null ? null : Math.max(0, Math.round((total - job) * 1e9) / 1e9) };
68
+ const answered = { answered_at: answeredAt, job_cost_usd: job, look_back_usd: total === null || job === null ? null : Math.max(0, Math.round((total - job) * 1e9) / 1e9), ...followUp };
62
69
  return { also: rows.also.map((row) => (row.table === "learning_proposals" ? { ...row, row: { ...row.row, proposal: { ...row.row.proposal, ...answered } } } : row)) };
63
70
  };
64
71
  // A job that only ran its learned workflows, each answering, with nothing said after its first message, gave nothing
65
72
  // new to learn: it is not asked (no model request), and looking back cost nothing, $0 whether or not the job's own
66
73
  // cost is known. Its words are the server's own.
67
74
  if (input.outcome === "completed" && deps.nothingNew && (await deps.nothingNew(input.runId).catch(() => false))) {
68
- return { also: [droppedRow(null, "empty", said.onlyWorkflow, { answered_at: answeredAt, job_cost_usd: job, look_back_usd: 0 })] };
75
+ return { also: [droppedRow(null, "empty", said.onlyWorkflow, { answered_at: answeredAt, job_cost_usd: job, look_back_usd: 0, ...followUp })] };
69
76
  }
70
77
  // What the run must never learn, read once, before it is asked anything: a run whose list can't be read learns
71
78
  // nothing, never over a shorter one.
@@ -76,10 +83,11 @@ export function createReflectHook(deps) {
76
83
  const close = async (rows) => ({ also: (await looked({ also: rows })).also.map((row) => cutRow(row, refuse)) });
77
84
  if (read === "unreadable")
78
85
  return close([droppedRow(null, "propose_failed", said.stopped(STOPPED.refuseUnread))]);
79
- const { active, tools, draftFor, described } = await deps.promptFacts(input.runId, input.agentId);
86
+ const { active, tools, draftFor, described, decisions, workflows } = await deps.promptFacts(input.runId, input.agentId);
80
87
  const deadlineMs = deps.deadlineMs ?? REFLECT_TIMEOUT_MS;
81
88
  const started = now();
82
- const end = await input.ask(reflectPrompt({ dir: LEARNED_DIR, active, tools, ...(draftFor?.length ? { draftFor, ...(described?.length ? { described } : {}) } : {}) }), { origin: "reflect", deadlineMs });
89
+ const ask = { origin: "reflect", ...(round > 1 ? { round } : {}) };
90
+ const end = await input.ask(reflectPrompt({ dir: LEARNED_DIR, active, tools, ...(decisions ? { decisions } : {}), ...(workflows === false ? { workflows: false } : draftFor?.length ? { draftFor, ...(described?.length ? { described } : {}) } : {}), ...(round > 1 && deps.before?.looked !== false ? { later: true } : {}) }), { ...ask, deadlineMs });
83
91
  // closeLearning: how the turn ended.
84
92
  if ("timedOut" in end)
85
93
  return close([droppedRow(null, "reflect_timeout", said.stopped(STOPPED.timedOut))]);
@@ -104,7 +112,7 @@ export function createReflectHook(deps) {
104
112
  // within the turn's own deadline; a re-ask that times out or fails leaves the first answer's drop.
105
113
  if (checked.state === "dropped" && checked.reason === "unparsed") {
106
114
  const left = deadlineMs - (now() - started);
107
- const again = left > 0 ? await input.ask(reflectAgain(checked.detail), { origin: "reflect", deadlineMs: left, again: true }) : undefined;
115
+ const again = left > 0 ? await input.ask(reflectAgain(checked.detail, ...(workflows === false ? [false] : [])), { ...ask, deadlineMs: left, again: true }) : undefined;
108
116
  if (again && "ended" in again) {
109
117
  turn = turnOf(again.answer);
110
118
  checked = await checkOf(turn);
@@ -119,7 +127,7 @@ export function createReflectHook(deps) {
119
127
  // never costs a note the first answer kept). Never a third time (a turn asks again once, for either reason).
120
128
  const dry = dryRunFailure(checked);
121
129
  const left = deadlineMs - (now() - started);
122
- const again = dry && left > 0 ? await input.ask(reflectDryRun(dry.path, dry.detail), { origin: "reflect", deadlineMs: left, again: true }) : undefined;
130
+ const again = dry && left > 0 ? await input.ask(reflectDryRun(dry.path, dry.detail), { ...ask, deadlineMs: left, again: true }) : undefined;
123
131
  if (again && "ended" in again) {
124
132
  const second = turnOf(again.answer);
125
133
  const kept = await checkOf(second);
@@ -133,9 +141,13 @@ export function createReflectHook(deps) {
133
141
  const detail = checked.reason === "empty" ? said.empty : checked.reason === "unparsed" ? said.unparsed : said.checker(checked.problems);
134
142
  return close([droppedRow(turn, checked.reason, detail, checked)]);
135
143
  }
144
+ // The learning run's cap: what the run's cap leaves now its look-back is spent, read after the checks (a read that
145
+ // fails is no room, never no cap: the grade is then skipped, never run past the cap).
146
+ const capUsd = deps.gradeCap ? await deps.gradeCap(input.runId).catch(() => 0) : undefined;
136
147
  return close([
137
148
  { table: "learning_proposals", row: { turn, proposal: { ...checked, detail: said.proposed(checked.notes, checked.skills, checked.workflows) } } },
138
- { table: "learning_run", row: { id: deps.newRunId(), ...(deps.gradeModel ? { model: deps.gradeModel } : {}) } },
149
+ { table: "learning_run", row: { id: deps.newRunId(), ...(deps.gradeModel ? { model: deps.gradeModel } : {}), ...(capUsd !== undefined ? { capUsd } : {}) } },
139
150
  ]);
140
151
  };
152
+ return async (input) => roundOf(await hook(input), round);
141
153
  }
@@ -1,8 +1,15 @@
1
1
  import { type Claim, type LoopEnd, type LoopFactory } from "./loop-contract.js";
2
2
  import { type RunnerStore } from "./store-port.js";
3
+ import { type RunState } from "../store/store.js";
3
4
  import { type Redact } from "./redact.js";
4
5
  import { type LiveTickerOptions } from "./live-ticker.js";
5
6
  /** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
7
+ /** A final run's status as its end line says it: the store holds a cancel as state 'stopped' with outcome 'cancelled', so
8
+ * the outcome tells a cancel from a person's resumable stop. */
9
+ export declare const endedStatus: (run: {
10
+ state: RunState;
11
+ outcome?: string | null;
12
+ }) => RunState | "cancelled";
6
13
  export declare const RUNNER_LOOPS = 300;
7
14
  /** How long a claim lasts unless renewed, unless told (RunnerOptions.leaseMs). */
8
15
  export declare const RUNNER_LEASE_MS = 30000;
@@ -53,6 +60,10 @@ export interface RunnerOptions {
53
60
  /** The wait before a run whose loop ended interrupted on its own (no stop asked of it: its Session closed itself) is
54
61
  * claimable again; each such end of the run in a row waits twice the one before, up to 64 times this. */
55
62
  interruptBackoffMs?: number;
63
+ /** After a claim or release commit answered Unanswered (it may have landed), the wait before the first re-read of what
64
+ * this runner holds; each retry of that re-read waits twice the one before, up to UNKNOWN_READS tries, then the lease
65
+ * settles it. */
66
+ unknownBackoffMs?: number;
56
67
  /** How long a run's end waits for a command still with its loop before it writes its end; an answer after that is
57
68
  * dropped (nothing written, nothing said). */
58
69
  endWaitMs?: number;
@@ -100,6 +111,21 @@ export interface RunnerMemory {
100
111
  export type RunnerEvent = {
101
112
  type: "claimed";
102
113
  claim: Claim;
114
+ }
115
+ /** A run's start, once: its first claim (from queued). `agent` and `kind` are ids, never a secret. */
116
+ | {
117
+ type: "started";
118
+ runId: string;
119
+ agent: string;
120
+ kind: string;
121
+ }
122
+ /** A run's end, once it is final (ended, stopped, failed): its state and the cost its row holds. */
123
+ | {
124
+ type: "ended";
125
+ runId: string;
126
+ agent: string;
127
+ status: RunState | "cancelled";
128
+ costUsd: number | null;
103
129
  } | {
104
130
  type: "claim-lost";
105
131
  runId: string;