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

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 (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -1,28 +1,35 @@
1
- // The runner process: `agentrun-serve runner --data D [--loops N] [--name N]` (cli.ts, through the server's launcher, the
1
+ // The runner process: `agentrun-serve runner --data D [--loops N] [--drain-timeout D] [--name N]` (cli.ts, through the server's launcher, the
2
2
  // same bin and Node, its secrets over the launcher's pipe). A long-lived process of its own, beside the server, with its
3
3
  // own connection to the store (in the data directory, or the Postgres AGENTRUN_STORE_URL names). It never sets the store up: a store whose schema it does not know
4
4
  // (or one the server has not set up yet) is refused before any run is claimed. Once it can claim it says so in one line,
5
5
  // `Runner <name> ready: store <kind> schema v<N>, <N> loops`; from then it writes its heartbeat (runner-<name>.alive under
6
6
  // the data directory) as its loop turns, which `agentrun-serve runner --check --data D [--name N]` reads without a store
7
- // connection. SIGTERM or SIGINT closes it: every loop stopped where it can resume and its run handed back at once for
8
- // another runner (a loop that never stops is given up when its claim would run out, and its run is claimable when its
9
- // lease lapses); then 0. Bad arguments exit 2, a store schema it does not know 3, anything else 1.
10
- import { mkdirSync, statSync, utimesSync, writeFileSync } from "node:fs";
11
- import { join } from "node:path";
7
+ // connection. It holds at most --loops runs at once (default AGENTRUN_MAX_RUNS, else as many pi runs as this host's
8
+ // memory holds: the server's --max-runs default, host.ts maxRunsOf). SIGTERM or SIGINT closes it: each busy run finishes
9
+ // its turn for up to --drain-timeout (default AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT), then every loop left is stopped where it can resume
10
+ // and its run handed back for another runner (a loop that never stops is given up when its claim would run out, and its
11
+ // run is claimable when its lease lapses); then 0. Bad arguments exit 2, a store schema it does not know 3, anything else 1.
12
+ // An error nothing handles exits 1 at once, said with its stack (lastResort).
13
+ import { mkdirSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
14
+ import { join, resolve } from "node:path";
12
15
  import { dockerPathsForRuns } from "../box-paths.js";
13
16
  import { hostAddressesOnce } from "../docker-host-addresses.js";
14
17
  import { HARNESS_TABLE_ENV } from "../harness-table.js";
15
- import { FAUX_PREFIX } from "../model.js";
18
+ import { maxRunsOf } from "../host.js";
19
+ import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
20
+ import { durationMs } from "../print.js";
16
21
  import { bootSealKey } from "../seal-key.js";
17
22
  import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
18
23
  import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
19
24
  import { SCHEMA_VERSION } from "../store/schema.js";
20
25
  import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
21
26
  import { computerDepsFrom } from "../workspace/computer-deps.js";
27
+ import { startJanitor } from "../workspace/computer-janitor.js";
22
28
  import { createDispatchLoop } from "./dispatch.js";
23
29
  import { resolveRunnerLoop } from "./harness-loops.js";
24
30
  import { routeOf } from "./model-route.js";
25
- import { RUNNER_LOOPS, RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
31
+ import { runnerMemory } from "./memory-claim.js";
32
+ import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
26
33
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
27
34
  /** A store this runner cannot use, or arguments it cannot take, in words a person starting it can act on. */
28
35
  export class RunnerRefused extends Error {
@@ -102,7 +109,7 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
102
109
  env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
103
110
  computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
104
111
  };
105
- return createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) });
112
+ return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
106
113
  }
107
114
  /** Where runner `name` writes its heartbeat in `dataDir`. */
108
115
  export const heartbeatFile = (dataDir, name) => join(dataDir, `runner-${name.replace(/[^A-Za-z0-9._:-]/g, "_")}.alive`);
@@ -147,8 +154,10 @@ export async function startRunnerProcess(options) {
147
154
  const warn = options.warn ?? ((message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`));
148
155
  const env = options.env ?? process.env;
149
156
  const { store, kind, schema } = await openRunnerStore(options.dataDir, env, warn, options.storeUrl);
157
+ const memory = options.memory ?? runnerMemory(store);
150
158
  let runner;
151
159
  let seal;
160
+ let janitor;
152
161
  try {
153
162
  // The server's seal key, booted the one way the server boots it (seal-key.ts): the one handed over, else the one in
154
163
  // this data directory, checked against what the store records. A runner on a store whose secrets another key sealed
@@ -158,17 +167,25 @@ export async function startRunnerProcess(options) {
158
167
  const name = options.name ?? runnerName();
159
168
  const made = options.createLoop ?? ofStore((opened, sealKey) => runnerLoop(opened, options.dataDir, undefined, sealKey));
160
169
  // A factory of the store (marked by ofStore) is given the store; a loop factory is used as is.
161
- const createLoop = isStoreFactory(made) ? made(store, seal.key) : made;
170
+ const parts = isStoreFactory(made) ? made(store, seal.key) : made;
171
+ const createLoop = typeof parts === "function" ? parts : parts.createLoop;
172
+ // The janitor sweeps with the computers the loop composed, never a second composition. Its lines are the runner's
173
+ // warnings, said where the runner says its others (warn: stderr unless a test gives its own).
174
+ if (options.janitor && typeof parts !== "function")
175
+ janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
162
176
  runner = startRunner({
163
177
  store,
164
178
  createLoop,
165
179
  name,
166
180
  ...(options.loops ? { loops: options.loops } : {}),
181
+ ...(options.drainMs ? { drainMs: options.drainMs } : {}),
182
+ memory,
167
183
  ...(options.onEvent ? { onEvent: options.onEvent } : {}),
168
184
  onBeat: heartbeat(options.dataDir, name, options.now ?? Date.now),
169
185
  });
170
186
  }
171
187
  catch (error) {
188
+ await janitor?.close();
172
189
  seal?.release();
173
190
  await store.close();
174
191
  throw error;
@@ -178,8 +195,10 @@ export async function startRunnerProcess(options) {
178
195
  return {
179
196
  runner,
180
197
  store: { kind, schema },
198
+ memoryMib: memory.budgetMib,
181
199
  close: () => (closing ??= (async () => {
182
- await runner.close();
200
+ // The janitor's sweep is cut and waited for on its own bound, beside the runner's close, never before it.
201
+ await Promise.all([janitor?.close(), runner.close()]);
183
202
  await store.close();
184
203
  held.release();
185
204
  })()),
@@ -192,17 +211,51 @@ export function ofStore(make) {
192
211
  return make;
193
212
  }
194
213
  const isStoreFactory = (made) => storeFactories.has(made);
195
- /** The runner process's arguments: `--data D [--loops N] [--name N]`, or `--check --data D [--name N]`. Each option with
196
- * a value is also taken as `--option=value` (the bin hands a data directory that starts with "-" so, never read as an
197
- * option); an empty one is refused like a missing one. */
214
+ /** How long a runner process lets each busy run finish its turn on SIGTERM, unless --drain-timeout or
215
+ * AGENTRUN_DRAIN_TIMEOUT says: the image's server drain (its CMD's --drain-timeout 6s), so a runner beside a --no-runner
216
+ * server drains as the server's own runner would.
217
+ * BOUND: this drain plus the stuck-loop stop after it (runner.ts runnerCloseBoundMs: the claim's lease less its margin,
218
+ * 30 s - 5 s = 25 s) is 6 + 25 = 31 s, inside deploy/compose.yaml's 35 s stop_grace_period for its runners
219
+ * (runner-beside-flags.test.mjs pins it). Raise this default only with that grace. */
220
+ export const RUNNER_DRAIN_TIMEOUT = "6s";
221
+ /** The environment's drain for a runner process when --drain-timeout gives none. */
222
+ export const RUNNER_DRAIN_ENV = "AGENTRUN_DRAIN_TIMEOUT";
223
+ /** What a runner process holds, from its arguments and `env`: --loops, else the server's --max-runs default
224
+ * (AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds; maxRunsOf); --drain-timeout, else
225
+ * AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT. A bad AGENTRUN_MAX_RUNS or AGENTRUN_DRAIN_TIMEOUT is RunnerRefused. */
226
+ export function runnerHolds(args, env) {
227
+ let loops = args.loops;
228
+ if (loops === undefined) {
229
+ try {
230
+ loops = maxRunsOf(env);
231
+ }
232
+ catch (error) {
233
+ throw new RunnerRefused(error.message);
234
+ }
235
+ }
236
+ let drainMs = args.drainMs;
237
+ if (drainMs === undefined) {
238
+ const given = env[RUNNER_DRAIN_ENV];
239
+ drainMs = durationMs(given || RUNNER_DRAIN_TIMEOUT);
240
+ if (drainMs === undefined)
241
+ throw new RunnerRefused(`${RUNNER_DRAIN_ENV} is a duration such as 6s, 500ms or 1m, not ${JSON.stringify(given)}`);
242
+ }
243
+ return { loops, drainMs };
244
+ }
245
+ /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
246
+ * [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
247
+ * with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
248
+ * test switch, as the server's own --faux; the only way a runner loads one. */
198
249
  export function runnerArgs(argv) {
199
250
  let dataDir;
200
251
  let loops;
252
+ let drainMs;
201
253
  let name;
254
+ let faux;
202
255
  let check = false;
203
256
  for (let i = 0; i < argv.length; i++) {
204
257
  const given = argv[i];
205
- const equals = /^(--(?:data|loops|name))=(.*)$/s.exec(given);
258
+ const equals = /^(--(?:data|loops|drain-timeout|name|faux))=(.*)$/s.exec(given);
206
259
  const arg = equals ? equals[1] : given;
207
260
  const value = () => {
208
261
  const next = equals ? equals[2] : argv[++i];
@@ -218,16 +271,24 @@ export function runnerArgs(argv) {
218
271
  if (!Number.isSafeInteger(loops) || loops < 1)
219
272
  throw new RunnerRefused(`--loops is a whole number of runs above zero, not ${JSON.stringify(text)}`);
220
273
  }
274
+ else if (arg === "--drain-timeout") {
275
+ const text = value();
276
+ drainMs = durationMs(text);
277
+ if (drainMs === undefined)
278
+ throw new RunnerRefused(`--drain-timeout is a duration such as 6s, 500ms or 1m, not ${JSON.stringify(text)}`);
279
+ }
221
280
  else if (arg === "--name")
222
281
  name = value();
282
+ else if (arg === "--faux")
283
+ faux = value();
223
284
  else if (arg === "--check")
224
285
  check = true;
225
286
  else
226
- throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--name N], or --check --data D [--name N]`);
287
+ throw new RunnerRefused(`unknown argument ${JSON.stringify(arg)}: a runner takes --data D [--loops N] [--drain-timeout D] [--name N] [--faux M], or --check --data D [--name N]`);
227
288
  }
228
289
  if (!dataDir)
229
290
  throw new RunnerRefused("a runner needs its data directory: --data D");
230
- return { dataDir, ...(loops === undefined ? {} : { loops }), ...(name === undefined ? {} : { name }), ...(check ? { check: true } : {}) };
291
+ return { dataDir, ...(loops === undefined ? {} : { loops }), ...(drainMs === undefined ? {} : { drainMs }), ...(name === undefined ? {} : { name }), ...(faux === undefined ? {} : { faux }), ...(check ? { check: true } : {}) };
231
292
  }
232
293
  /** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
233
294
  * says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
@@ -245,6 +306,19 @@ export async function runUntilSignalled(process, signals = ["SIGTERM", "SIGINT"]
245
306
  });
246
307
  await process.close();
247
308
  }
309
+ /** The runner process's last resort (runnerMain installs it for unhandledRejection and uncaughtException): says what
310
+ * went wrong, in the runner's name with its stack, then exits 1 at once, closing nothing. A runner that went on after
311
+ * an error nothing handled could keep renewing the claim of a run whose loop is dead, and that run would hang claimed
312
+ * by a live runner. Exiting lets the claim lapse: another runner (or this one, started again) takes the run back at the
313
+ * next epoch, and the fence refuses the dead loop's late writes. The line is written to stderr synchronously
314
+ * (writeSync), so a pipe's slow reader still gets the whole stack before the exit. Exported for its test. */
315
+ export function lastResort(name, write = (line) => void writeSync(2, line), exit = (code) => process.exit(code)) {
316
+ return (reason) => {
317
+ const said = reason instanceof Error ? (reason.stack ?? `${reason.name}: ${reason.message}`) : String(reason);
318
+ write(`agentrun-serve runner: Runner ${name}: an error nothing handled, so the runner exits (its claims lapse, and are taken back): ${said}\n`);
319
+ exit(1);
320
+ };
321
+ }
248
322
  /** One line of what the runner did, in its name. */
249
323
  function said(name, event) {
250
324
  if (event.type === "claimed")
@@ -258,7 +332,7 @@ function said(name, event) {
258
332
  /** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
259
333
  * set up yet); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names
260
334
  * it when --name does not. */
261
- export async function runnerMain(argv, env = process.env) {
335
+ export async function runnerMain(argv, given = process.env, hooks = {}) {
262
336
  let args;
263
337
  try {
264
338
  args = runnerArgs(argv);
@@ -269,6 +343,10 @@ export async function runnerMain(argv, env = process.env) {
269
343
  console.error(`agentrun-serve runner: ${error.message}`);
270
344
  return 2;
271
345
  }
346
+ // A test switch is this start's option alone, as on the server (server.ts withoutFaux, fauxEnvOf): one the process
347
+ // inherited (AGENTRUN_SERVE_FAUX*, the harness table, left in an operator's shell or a platform's settings) never loads
348
+ // a module or decides what a run answers. --faux sets the faux model's.
349
+ const env = { ...withoutFaux(given), ...(args.faux ? { [FAUX_ENV]: resolve(args.faux) } : {}) };
272
350
  const name = args.name ?? env.AGENTRUN_RUNNER_NAME ?? undefined;
273
351
  if (args.check) {
274
352
  if (!name) {
@@ -283,15 +361,45 @@ export async function runnerMain(argv, env = process.env) {
283
361
  console.error(`agentrun-serve runner: ${checked.why}`);
284
362
  return 1;
285
363
  }
364
+ let holds;
365
+ try {
366
+ holds = runnerHolds(args, env);
367
+ }
368
+ catch (error) {
369
+ if (!(error instanceof RunnerRefused))
370
+ throw error;
371
+ console.error(`agentrun-serve runner: ${error.message}`);
372
+ return 2;
373
+ }
286
374
  let started;
287
375
  const runnerOf = name ?? runnerName();
376
+ // The last resort, in this process only (never the library, the server's CLI or the runner beside a server): an error
377
+ // nothing handled is said with its stack, and the process exits 1 at once (lastResort: crashing is the safe failure).
378
+ const fatal = lastResort(runnerOf);
379
+ process.on("unhandledRejection", fatal);
380
+ process.on("uncaughtException", fatal);
381
+ // The stop is listened for before the start, as the server's CLI listens (cli.ts): startRunnerProcess starts claiming
382
+ // runs before it returns, so a SIGTERM or SIGINT during it (a platform's redeploy) would otherwise end the process by the
383
+ // signal itself, its claims held and a paid request in flight cut. A stop asked then is kept, and the runner closes as
384
+ // soon as its start is done, through the same close as a stop after it: its runs handed back, its store closed.
385
+ let asked = false;
386
+ const early = () => void (asked = true);
387
+ for (const signal of RUNNER_SIGNALS)
388
+ process.on(signal, early);
389
+ const unlisten = () => {
390
+ for (const signal of RUNNER_SIGNALS)
391
+ process.off(signal, early);
392
+ };
288
393
  try {
289
394
  started = await startRunnerProcess({
290
395
  dataDir: args.dataDir,
291
396
  name: runnerOf,
292
397
  env,
293
- ...(args.loops ? { loops: args.loops } : {}),
398
+ loops: holds.loops,
399
+ drainMs: holds.drainMs,
294
400
  createLoop: ofStore((store, sealKey) => runnerLoop(store, args.dataDir, env, sealKey)),
401
+ // The runner subcommand ends what a crashed runner of this server left (never under --faux).
402
+ janitor: true,
295
403
  onEvent: (event) => {
296
404
  if (event.type === "error")
297
405
  return void console.error(`Runner ${runnerOf}: ${event.step}${event.runId ? ` ${event.runId}` : ""}: ${event.message}`);
@@ -302,10 +410,26 @@ export async function runnerMain(argv, env = process.env) {
302
410
  });
303
411
  }
304
412
  catch (error) {
413
+ unlisten();
305
414
  console.error(`agentrun-serve runner: ${error?.message ?? String(error)}`);
306
415
  return error instanceof RunnerRefused && error.cause instanceof SchemaVersionUnknown ? 3 : 1;
307
416
  }
417
+ await hooks.started?.(started);
418
+ // From here the handlers below take the stop, with nothing awaited between: no signal falls in a gap.
419
+ unlisten();
420
+ if (asked) {
421
+ console.log(`Runner ${started.runner.name} stopping: a stop came during its start`);
422
+ await started.close();
423
+ return 0;
424
+ }
308
425
  // Ready is said once SIGTERM and SIGINT are handled, so a stop sent on reading it always closes the runner.
309
- await runUntilSignalled(started, ["SIGTERM", "SIGINT"], () => console.log(`Runner ${started.runner.name} ready: store ${started.store.kind} schema v${started.store.schema}, ${args.loops ?? RUNNER_LOOPS} loops`));
426
+ // Then its memory budget, a line of its own (the ready line's shape is read by deploy checks): what a container's limit
427
+ // gave it is seen where it runs.
428
+ await runUntilSignalled(started, RUNNER_SIGNALS, () => {
429
+ console.log(`Runner ${started.runner.name} ready: store ${started.store.kind} schema v${started.store.schema}, ${holds.loops} loops`);
430
+ console.log(`Runner ${started.runner.name} memory: ${started.memoryMib} MiB for runs, each weighed by its harness`);
431
+ });
310
432
  return 0;
311
433
  }
434
+ /** The signals that stop a runner process. */
435
+ const RUNNER_SIGNALS = ["SIGTERM", "SIGINT"];
@@ -53,6 +53,9 @@ export interface McpClaimStep {
53
53
  fresh(): Promise<void>;
54
54
  /** Drop every credential held: the loop ended, or the claim is lost. */
55
55
  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. */
58
+ beforeCall(server: string, signal: AbortSignal): Promise<void>;
56
59
  }
57
60
  /** The MCP step of `options.claim`: its pin made or read and checked, its credentials opened (refreshed as due). */
58
61
  export declare function mcpClaim(options: McpClaimOptions): Promise<McpClaimStep>;
@@ -39,7 +39,7 @@ import { privateOAuthHosts } from "../mcp-private-hosts.js";
39
39
  import { GITHUB_MCP_ONLY, GITHUB_MCP_ORIGIN, githubMcpUrl } from "../github.js";
40
40
  import { githubTokens } from "./mcp-github.js";
41
41
  import { ClaimRefused } from "./loop-contract.js";
42
- import { REFRESH_MARGIN_MS, UNKNOWN_EXPIRY_MS, UNUSABLE } from "../mcp-servers.js";
42
+ import { REFRESH_MARGIN_MS, UNKNOWN_EXPIRY_MS, UNUSABLE } from "../mcp-probe.js";
43
43
  import { tokenLeftOf } from "../mcp-probe.js";
44
44
  import { openMcpCredential, sealMcpCredential } from "../store/seal.js";
45
45
  import { Fenced, MCP_REFRESH_CALL_MS } from "../store/index.js";
@@ -299,7 +299,12 @@ export async function mcpClaim(options) {
299
299
  await confirm(store, claim);
300
300
  };
301
301
  await fresh();
302
- return { pin, credentials, secrets, fresh, release };
302
+ const beforeCall = async (server, signal) => {
303
+ signal.throwIfAborted();
304
+ if (!released)
305
+ await github.check(server);
306
+ };
307
+ return { pin, credentials, secrets, fresh, release, beforeCall };
303
308
  }
304
309
  /** The run's pin: read, and checked against the meta tools known now; or made at its first claim and written once. */
305
310
  async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN }) {
@@ -331,7 +336,6 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
331
336
  // The registry keeps each tool as its server listed it (input_schema); the pin holds the harnesses' shape.
332
337
  return row && { url: row.url, tools: (row.tools ?? []).map(boundTool), ...(row.prices ? { prices: row.prices } : {}) };
333
338
  },
334
- headers: () => undefined,
335
339
  });
336
340
  }
337
341
  catch (error) {
@@ -8,7 +8,7 @@ export type GithubAppMint = (target: {
8
8
  expires_at: number;
9
9
  } | {
10
10
  ok: false;
11
- reason: "not_installed" | "no_repo" | "github_failed";
11
+ reason: "not_installed" | "no_repo" | "github_failed" | "disconnected";
12
12
  message: string;
13
13
  }>;
14
14
  /** What the runner gives the step for a run's github_app servers: the bound mint, and the run's repository (from its
@@ -19,6 +19,11 @@ export interface GithubAppAccess {
19
19
  readonly installation?: number;
20
20
  readonly repo: string;
21
21
  } | undefined;
22
+ /** Revokes an installation token this access minted (best effort): one dropped at release or on a disconnect. */
23
+ readonly revoke?: (token: string) => Promise<void>;
24
+ /** Whether the App is still the one this access mints with (its id and key): read before each call, so a disconnect
25
+ * or a new App stops a run's token at its next call, not at its next mint. */
26
+ readonly same?: () => Promise<boolean>;
22
27
  }
23
28
  /** A timer the step arms: the refresh before expiry, the expiry itself. */
24
29
  export type GithubTimer = (fire: () => void, ms: number) => {
@@ -33,6 +38,7 @@ export declare const GITHUB_UNUSABLE: {
33
38
  notInstalled: (repo: string) => string;
34
39
  failed: (message: string) => string;
35
40
  expired: (message: string) => string;
41
+ disconnected: string;
36
42
  };
37
43
  type Entry = {
38
44
  headers?: Record<string, string>;
@@ -47,7 +53,10 @@ export declare function githubTokens(access: GithubAppAccess | undefined, { now,
47
53
  /** `name`'s token: the one held while it has more than REFRESH_BEFORE_MS left (a claim's fresh() again mints
48
54
  * nothing), else a new one. */
49
55
  open(name: string, put: (entry: Entry) => void): Promise<void>;
50
- /** Every token dropped and every timer stopped: the loop ended, or the claim is lost. */
56
+ /** Before a call of `name`: the token held for it, when the App it was minted under is gone or replaced, is dropped
57
+ * and revoked, and the server's calls refused in words. */
58
+ check(name: string): Promise<void>;
59
+ /** Every token dropped and revoked, and every timer stopped: the loop ended, or the claim is lost. */
51
60
  release(): void;
52
61
  };
53
62
  export {};
@@ -14,6 +14,7 @@ export const GITHUB_UNUSABLE = {
14
14
  notInstalled: (repo) => `the GitHub App is not installed on ${repo}: install it from Settings → GitHub`,
15
15
  failed: (message) => `GitHub did not make a token for this run (${message})`,
16
16
  expired: (message) => `its GitHub App token expired and a new one could not be made (${message})`,
17
+ disconnected: "the GitHub App this run's token came from was disconnected or replaced on this server (Settings → GitHub)",
17
18
  };
18
19
  const REAL_TIMER = (fire, ms) => {
19
20
  const timer = setTimeout(fire, Math.min(Math.max(0, ms), 2 ** 31 - 1));
@@ -24,12 +25,33 @@ const REAL_TIMER = (fire, ms) => {
24
25
  * hands its entry to `put`, then keeps it fresh until `release`. */
25
26
  export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {}) {
26
27
  const held = new Map();
28
+ /** The tokens a refresh replaced, by server, until they expire: a call already sent may still carry one, so it is not
29
+ * revoked at the refresh, only when its server's access ends (drop) or the run's does (release). */
30
+ const replaced = new Map();
27
31
  let released = false;
32
+ /** Each server's access epoch: a drop ends it, so a mint that was out across the drop (a refresh while check() found
33
+ * the App gone) installs nothing; its token is revoked. */
34
+ const epochs = new Map();
35
+ const epochOf = (name) => epochs.get(name) ?? 0;
28
36
  const clear = (name) => {
29
37
  for (const timer of held.get(name)?.timers ?? [])
30
38
  timer.clear();
31
39
  held.delete(name);
32
40
  };
41
+ const revoke = (token) => void access?.revoke?.(token).catch(() => undefined);
42
+ /** `name`'s tokens, the one held and every one a refresh replaced that has not expired, revoked at GitHub as they are
43
+ * dropped: never left live past its run or its App. */
44
+ const drop = (name) => {
45
+ epochs.set(name, epochOf(name) + 1);
46
+ const token = held.get(name)?.token;
47
+ clear(name);
48
+ if (token)
49
+ revoke(token);
50
+ for (const old of replaced.get(name) ?? [])
51
+ if (old.expiresAt > now())
52
+ revoke(old.token);
53
+ replaced.delete(name);
54
+ };
33
55
  /** A token minted for `name` and put; its refresh and its expiry armed. On a refresh that fails, the token held keeps
34
56
  * working until it expires, then the server's calls are refused in words. */
35
57
  const mint = async (name, put, refreshing) => {
@@ -37,6 +59,7 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
37
59
  return put({ unopened: GITHUB_UNUSABLE.noAccess });
38
60
  if (!access.target)
39
61
  return put({ unopened: GITHUB_UNUSABLE.noRepo });
62
+ const epoch = epochOf(name);
40
63
  let got;
41
64
  try {
42
65
  got = await access.mint(access.target);
@@ -44,8 +67,18 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
44
67
  catch (error) {
45
68
  got = { ok: false, reason: "github_failed", message: String(error?.message ?? error) };
46
69
  }
47
- if (released)
70
+ // A mint that came back after the run's access ended, or the server's (its token dropped meanwhile, its calls
71
+ // refused): its token is revoked at once, never held, and the refusal stands.
72
+ if (released || epochOf(name) !== epoch) {
73
+ if (got.ok)
74
+ revoke(got.token);
48
75
  return;
76
+ }
77
+ // The App disconnected or replaced since the claim: the token held stops now, revoked, never used to its expiry.
78
+ if (!got.ok && got.reason === "disconnected") {
79
+ drop(name);
80
+ return put({ unopened: GITHUB_UNUSABLE.disconnected });
81
+ }
49
82
  if (!got.ok) {
50
83
  const why = got.reason === "not_installed" ? GITHUB_UNUSABLE.notInstalled(access.target.repo) : got.reason === "no_repo" ? GITHUB_UNUSABLE.noRepo : GITHUB_UNUSABLE.failed(got.message);
51
84
  const kept = held.get(name);
@@ -64,6 +97,9 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
64
97
  clear(name);
65
98
  return put({ unopened: why });
66
99
  }
100
+ const previous = held.get(name);
101
+ if (previous && previous.token !== got.token)
102
+ replaced.set(name, [...(replaced.get(name) ?? []).filter((old) => old.expiresAt > now()), { token: previous.token, expiresAt: previous.expiresAt }]);
67
103
  clear(name);
68
104
  const entry = { token: got.token, expiresAt: got.expires_at, timers: [], put };
69
105
  held.set(name, entry);
@@ -81,11 +117,26 @@ export function githubTokens(access, { now = Date.now, arm = REAL_TIMER } = {})
81
117
  }
82
118
  await mint(name, put, false);
83
119
  },
84
- /** Every token dropped and every timer stopped: the loop ended, or the claim is lost. */
120
+ /** Before a call of `name`: the token held for it, when the App it was minted under is gone or replaced, is dropped
121
+ * and revoked, and the server's calls refused in words. */
122
+ async check(name) {
123
+ const kept = held.get(name);
124
+ // A read that fails throws on: the gateway refuses the call unsent, the token kept (fail closed, never dropped).
125
+ if (!kept || !access?.same || (await access.same()))
126
+ return;
127
+ if (released)
128
+ return;
129
+ // The App is gone or replaced: whatever is held now (a refresh may have replaced the token while the read waited)
130
+ // is dropped and revoked, and the server's calls refused, never sent on the replacement.
131
+ const now_ = held.get(name) ?? kept;
132
+ drop(name);
133
+ now_.put({ unopened: GITHUB_UNUSABLE.disconnected });
134
+ },
135
+ /** Every token dropped and revoked, and every timer stopped: the loop ended, or the claim is lost. */
85
136
  release() {
86
137
  released = true;
87
- for (const name of [...held.keys()])
88
- clear(name);
138
+ for (const name of new Set([...held.keys(), ...replaced.keys()]))
139
+ drop(name);
89
140
  },
90
141
  };
91
142
  }
@@ -103,6 +103,8 @@ export interface ParkedFollowUpOptions {
103
103
  text: string;
104
104
  isError?: boolean;
105
105
  }>;
106
+ /** A parked call refused (the person's deny, or its tool denied since): its end on the run's record, in those words. */
107
+ refused?(call: McpGateCall, text: string): Promise<void>;
106
108
  }
107
109
  /** For a harness with its own MCP client, on a claim that finds its MCP calls parked through the door: each asked call's
108
110
  * answer acted on once, as main's gate did after a person answered (tool-gate.ts): an allow runs the call through the
@@ -3,6 +3,7 @@ import { wireName } from "../catalog.js";
3
3
  import { mcpGateway, noCallId } from "../mcp-gateway.js";
4
4
  import { argsPreview, mcpToolName, resumeText, RESUME_PREFIX, waitingText } from "../tool-gate.js";
5
5
  import { deniedText } from "./loop-contract.js";
6
+ import { STOPPED_WHILE_WAITING } from "../refusal-words.js";
6
7
  import { endedAnswer, KINDS } from "./journal-kinds.js";
7
8
  import { mcpClaim } from "./mcp-claim.js";
8
9
  const said = (text, isError = false) => ({ content: [{ type: "text", text }], ...(isError ? { isError: true } : {}) });
@@ -42,7 +43,7 @@ export async function mcpForClaim(options) {
42
43
  const gateway = mcpGateway({
43
44
  pin,
44
45
  credentials: step.credentials,
45
- liveCredentials: true,
46
+ beforeCall: step.beforeCall,
46
47
  work: options.work,
47
48
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
48
49
  ...(options.fetch ? { fetch: options.fetch } : {}),
@@ -137,13 +138,23 @@ export async function parkedFollowUp(mcp, options) {
137
138
  if (answer === "park")
138
139
  return "park";
139
140
  let result;
140
- if (!answer.approved)
141
- result = { text: deniedText(call.tool, answer.note), isError: true };
141
+ if (!answer.approved) {
142
+ // A stop's withdrawal (a reopened run's parked call) reads as one; any other deny in its words.
143
+ result = { text: answer.decision === "withdrawn" ? STOPPED_WHILE_WAITING : deniedText(call.tool, answer.note), isError: true };
144
+ await options.refused?.(call, result.text);
145
+ }
142
146
  else {
143
147
  const done = ended.get(call.callId);
144
- const denied = await options.deniedNow(call);
148
+ const denied = done ? undefined : await options.deniedNow(call);
145
149
  // A call that already ended is answered from its end (endedAnswer: a crash-cut one in the kernel's words).
146
- result = done ? endedAnswer(call.tool, done) : denied !== undefined ? { text: denied, isError: true } : await options.run(call);
150
+ if (done)
151
+ result = endedAnswer(call.tool, done);
152
+ else if (denied !== undefined) {
153
+ result = { text: denied, isError: true };
154
+ await options.refused?.(call, denied);
155
+ }
156
+ else
157
+ result = await options.run(call);
147
158
  }
148
159
  texts.push(resumeText({ tool: call.tool, call_id: call.callId }, argsPreview(call.args), answer.approved ? "allow" : "deny", { text: result.text, isError: result.isError === true }));
149
160
  callIds.push(call.callId);
@@ -0,0 +1,9 @@
1
+ import type { Store } from "../store/store.js";
2
+ import type { RunnerMemory } from "./runner.js";
3
+ /** What a run launched on `harness` weighs: its table entry's run size, or a pi run's for a run on no harness of the
4
+ * table (a learning run, which runs in the runner's own process as a pi run does). */
5
+ export declare function claimMibOf(harness: string): number;
6
+ /** The runner's memory budget over `store`: `memory` bytes (default the host's, hostMemory) less the server's own, each
7
+ * waiting run weighed by the harness its launch names (store.runs.launch). A run whose launch cannot be read weighs a pi
8
+ * run: its claim fails it at once (dispatch.ts), holding nothing for long. */
9
+ export declare function runnerMemory(store: Pick<Store, "runs">, memory?: number): RunnerMemory;
@@ -0,0 +1,25 @@
1
+ // What a runner's memory holds of runs (RunnerOptions.memory): the budget is the host's memory less the server's own
2
+ // (host.ts runsMemoryMib, of the container's limit when it has one), and each waiting run weighs what a run of its
3
+ // harness reserves (its table entry's runMib: pi 128 MiB, codex 192, claude-agent 288, opencode 704). The count alone
4
+ // (--max-runs, by default as many pi runs as fit) would let a 2 GB host take 15 claude-agent runs, about 3.2 GB as
5
+ // measured, and the host's OOM kill would take every run on it; by weight it holds 6 and the rest wait queued.
6
+ import { DEFAULT_HARNESS, harnessOfBody } from "../harness.js";
7
+ import { builtinHarness } from "../harness-table.js";
8
+ import { hostMemory, runsMemoryMib } from "../host.js";
9
+ /** What a run launched on `harness` weighs: its table entry's run size, or a pi run's for a run on no harness of the
10
+ * table (a learning run, which runs in the runner's own process as a pi run does). */
11
+ export function claimMibOf(harness) {
12
+ return (builtinHarness(harness) ?? builtinHarness(DEFAULT_HARNESS)).runMib;
13
+ }
14
+ /** The runner's memory budget over `store`: `memory` bytes (default the host's, hostMemory) less the server's own, each
15
+ * waiting run weighed by the harness its launch names (store.runs.launch). A run whose launch cannot be read weighs a pi
16
+ * run: its claim fails it at once (dispatch.ts), holding nothing for long. */
17
+ export function runnerMemory(store, memory = hostMemory()) {
18
+ return {
19
+ budgetMib: runsMemoryMib(memory),
20
+ weigh: async (runIds) => new Map(await Promise.all(runIds.map(async (runId) => {
21
+ const harness = await store.runs.launch(runId).then((row) => harnessOfBody((row.body ?? {})), () => DEFAULT_HARNESS);
22
+ return [runId, claimMibOf(harness)];
23
+ }))),
24
+ };
25
+ }