@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36

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 (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  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 +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -1,21 +1,18 @@
1
1
  // The runner's side of a github_app MCP server (runner/mcp-github.ts): the server's GitHub App, read from the store at each
2
- // claim, bound into the mint the claim step calls, with the run's repository. The App's id and private key are the rows the
3
- // server sealed in trigger_settings (adapter "github", scope "server", AAD trigger_settings|github|server|<field>, as
4
- // sealed-settings-store.ts writes them), opened here with the runner's seal key and held only in the bound mint's closure.
2
+ // claim and again before each mint, bound into the mint the claim step calls, with the run's repository. The App's id and
3
+ // private key are the rows the server sealed in trigger_settings (adapter "github", scope "server", AAD
4
+ // trigger_settings|github|server|<field>, as sealed-settings-store.ts writes them), opened here with the runner's seal key.
5
5
  // No App (never connected, disconnected, or rows that do not open under this key): no access, and such a server's calls
6
- // are refused in words (GITHUB_UNUSABLE.noAccess).
6
+ // are refused in words (GITHUB_UNUSABLE.noAccess). An App disconnected or replaced while a run holds a token: its next
7
+ // mint is refused as disconnected, and the claim step drops and revokes the token it holds.
7
8
  import { unseal } from "../sealing.js";
8
- import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubTargetOf, mintInstallationToken } from "../github.js";
9
+ import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubCall, githubTargetOf, mintInstallationToken } from "../github.js";
9
10
  import { isObject } from "../validate.js";
10
11
  const ADAPTER = "github";
11
12
  const aad = (field) => `trigger_settings|${ADAPTER}|${GITHUB_SCOPE}|${field}`;
12
- /** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
13
- * server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
14
- * with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
15
- * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it. */
16
- export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now } = {}) {
17
- if (!sealKey)
18
- return undefined;
13
+ /** The server's App as the store holds it now, opened with `sealKey`: its id and private key, or undefined when there is none
14
+ * this key opens. */
15
+ async function appOf(store, sealKey) {
19
16
  const rows = (await store.triggerSettings.get(ADAPTER)).filter((row) => row.scope === GITHUB_SCOPE);
20
17
  const open = (field) => {
21
18
  const row = rows.find((r) => r.field === field);
@@ -30,8 +27,42 @@ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB
30
27
  };
31
28
  const appId = open(GITHUB_FIELDS.appId);
32
29
  const pem = open(GITHUB_FIELDS.privateKey);
33
- if (!appId || !pem)
30
+ return appId && pem ? { appId, pem } : undefined;
31
+ }
32
+ /** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
33
+ * server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
34
+ * with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
35
+ * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
36
+ * `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
37
+ * the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
38
+ * joins the run's redactor (its `cut`), the first and every one after. */
39
+ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold } = {}) {
40
+ if (!sealKey)
41
+ return undefined;
42
+ const app = await appOf(store, sealKey);
43
+ if (!app)
34
44
  return undefined;
35
- const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput);
36
- return { api, mint: (to) => mintInstallationToken(api, appId, pem, to, now()), target };
45
+ const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput, { payload: fromGitHub });
46
+ return {
47
+ api,
48
+ target,
49
+ // The App read again before each mint: one disconnected or replaced since the claim makes no token for this run.
50
+ mint: async (to, permissions) => {
51
+ // A read that fails throws on: the step's github_failed path keeps the token held until it expires, never a disconnect.
52
+ const still = await appOf(store, sealKey);
53
+ if (!still || still.appId !== app.appId || still.pem !== app.pem)
54
+ return { ok: false, reason: "disconnected", message: "the GitHub App was disconnected or replaced on this server" };
55
+ const minted = await mintInstallationToken(api, app.appId, app.pem, to, now(), permissions);
56
+ if (minted.ok)
57
+ hold?.([minted.token]);
58
+ return minted;
59
+ },
60
+ // Before each call: the App as the store holds it now, the same id and key, or the run's token stops.
61
+ same: async () => {
62
+ const still = await appOf(store, sealKey);
63
+ return Boolean(still && still.appId === app.appId && still.pem === app.pem);
64
+ },
65
+ // An installation token revokes itself (DELETE /installation/token, the token its own credential): no App needed.
66
+ revoke: async (token) => void (await githubCall(api, "/installation/token", { method: "DELETE", jwt: token }).catch(() => undefined)),
67
+ };
37
68
  }
@@ -2,7 +2,12 @@ import type { RunLaunch } from "../run-launch.js";
2
2
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
3
3
  import { type GradeRouteAsk } from "./learning-dispatch.js";
4
4
  import type { GraderRoute } from "./learning-ask.js";
5
- import type { LoopFactory } from "./loop-contract.js";
5
+ import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
6
+ /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
7
+ * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
8
+ export declare class NeverFits extends ClaimRefused {
9
+ name: string;
10
+ }
6
11
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
7
12
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
8
13
  export declare function resolveRunnerLoop(deps: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
@@ -1,3 +1,13 @@
1
+ // The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
2
+ // and the harness its launch names. The runner holds one dispatch loop (dispatch.ts) for every run; at the claim the
3
+ // dispatch reads the launch and asks this switch for the run's inner loop:
4
+ // - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
5
+ // harness is pi), so the revision is read here to tell it from an agentic pi run;
6
+ // - a built-in learning run (its launch names harness "learning") runs on the learning loop;
7
+ // - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch);
8
+ // - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
9
+ // - anything else fails the run in words (the dispatch's UnknownHarness).
10
+ import { hostMemory, neverFits } from "../host.js";
1
11
  import { resolveHarness } from "./adapters/index.js";
2
12
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
3
13
  import { createAdapterLoop } from "./adapter-loop.js";
@@ -5,8 +15,14 @@ import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
5
15
  import { createDispatchLoop } from "./dispatch.js";
6
16
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
7
17
  import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
18
+ import { ClaimRefused } from "./loop-contract.js";
8
19
  import { createWorkflowLoop, isWorkflowRevision } from "./workflow-loop.js";
9
20
  import { workflowSpecOf } from "./workflow-spec.js";
21
+ /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
22
+ * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
23
+ export class NeverFits extends ClaimRefused {
24
+ name = "NeverFits";
25
+ }
10
26
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
11
27
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
12
28
  export function resolveRunnerLoop(deps) {
@@ -49,13 +65,20 @@ export function resolveRunnerLoop(deps) {
49
65
  // runs the pi spec (adapterRunSpecFromLaunch). A harness with no entry is unknown here: the dispatch fails it in words.
50
66
  const runner = resolveHarness(harness);
51
67
  if (runner) {
68
+ // A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
69
+ // fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
70
+ // started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
71
+ // the host's memory and its OOM kill would take every run on it.
72
+ const tooBig = neverFits(harness, hostMemory());
73
+ if (tooBig)
74
+ throw new NeverFits(tooBig);
52
75
  // A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
53
76
  // where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
54
77
  // path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
55
78
  // run that does not learn supplies none. The same for the pi and the CLI spec.
56
79
  return createAdapterLoop((claim, adapterRun) => runner.record === "loop"
57
80
  ? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
58
- : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim));
81
+ : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim), deps.modelRetry ?? {});
59
82
  }
60
83
  return undefined;
61
84
  };
@@ -1,4 +1,6 @@
1
1
  import type { MessageOrigin } from "../timeline/index.js";
2
+ /** The session (sessions.ts journalSessions) a workflow run's call nodes log their effects on (KINDS.nodeEffect). */
3
+ export declare const NODE_LOG_SESSION = "node-log";
2
4
  /** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
3
5
  * sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
4
6
  * other. */
@@ -20,7 +22,7 @@ export declare const KINDS: {
20
22
  * a call nor a message, so the reader passes over it. */
21
23
  readonly messageSending: "agentrun.message.sending";
22
24
  /** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
23
- * the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
25
+ * the Timeline's attribution (the timeline reads a host's user entry's own origin). The model
24
26
  * reads it as any message. */
25
27
  readonly input: "agentrun.input";
26
28
  /** A tool call the gate asked a person about: the run parks on it. */
@@ -47,11 +49,28 @@ export declare const KINDS: {
47
49
  /** The resume of a paused workflow run (a `resume` row), taken: the workflow goes on from its journal. Neither a call nor
48
50
  * a message, so the reader passes over it. */
49
51
  readonly resume: "agentrun.resume";
52
+ /** A paid call the cap refused for room, kept at its refusal (the Refusal): its pause lands at the model's next request
53
+ * (adapter-loop.ts pauseFor), and a claim lost before that restores it from here (pendingPauseOf). No run patch, and
54
+ * neither a call nor a message, so the reader passes over it. */
55
+ readonly pausePending: "agentrun.pause.pending";
56
+ /** A workflow call node's effect, as it starts and as it ends (pause.ts NodeLine: its path, item, tool, label, input,
57
+ * then its status and output or error), on the run's node-log session (NODE_LOG_SESSION): the run's graph lists its
58
+ * effects from these. Written as the effect runs, never for one the driver answers from its receipt. */
59
+ readonly nodeEffect: "agentrun.node.effect";
50
60
  /** A CLI run's end-of-run turn (the loop's record): its prompt (`role: "person"`) and its answer (`role: "model"`, the
51
61
  * text in `model` as pi's answer carries it), the entry and the answer of the submission its request id names, the
52
62
  * same submission pi's adapter writes, so the step reads both alike. Neither a call nor a message: the reader passes
53
63
  * over it, and the turn is never on the run's visible record. */
54
64
  readonly endOfRunTurn: "agentrun.end-of-run.turn";
65
+ /** What a learning run's claim laid of its seed: the learned skills it was given (`skills`, by name) and the learned
66
+ * workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
67
+ * what the run was given. Neither a call nor a message. */
68
+ readonly learningLaid: "agentrun.learning.laid";
69
+ /** A workflow run's model node's execution, as the runner kept it before running it (workflow-spec.ts onModelNode):
70
+ * `{ path, tier?, model }`, its execution path, the tier it asked for (absent for none) and the model id the run's route
71
+ * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
72
+ * call nor a message. */
73
+ readonly nodeModel: "agentrun.node.model";
55
74
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
56
75
  readonly learningGraded: "agentrun.learning.graded";
57
76
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -107,6 +126,13 @@ export interface RaiseData {
107
126
  readonly capUsd: number;
108
127
  readonly takes: readonly number[];
109
128
  }
129
+ /** The cap a run is held to now, from its journal: its newest raise's (a KINDS.raise entry above 0), else its launch's;
130
+ * none for a run launched with no cap. The one figure every reader of the run's cap takes: each request's admission
131
+ * (adapter-loop.ts capNow), the run's view, and its end-of-run look back (learning-end.ts). */
132
+ export declare function capNowOf(launchCapUsd: number | undefined, entries: readonly {
133
+ readonly kind: string;
134
+ readonly data?: unknown;
135
+ }[]): number | undefined;
110
136
  /** What a run parked at its cap waits on (the kernel cap's parkOf): its cap, what the cap counted as taken, the least the
111
137
  * refused request needs, the least cap that sends it and the raise offered, in the run's money units (dollars). */
112
138
  export interface BudgetData {
@@ -123,6 +149,9 @@ export interface BudgetData {
123
149
  };
124
150
  /** The cap's words, as the run row's summary says them. */
125
151
  readonly words: string;
152
+ /** A workflow run's: the label of the node whose step waits at the cap, null when it is not known. Absent on an agentic
153
+ * run's pause. */
154
+ readonly node?: string | null;
126
155
  }
127
156
  export interface CallStartData {
128
157
  readonly callId: string;
@@ -130,9 +159,15 @@ export interface CallStartData {
130
159
  readonly input: unknown;
131
160
  /** May run again after a crash (it changes nothing outside the run): the tool registry's own flag. */
132
161
  readonly replaySafe: boolean;
133
- /** Written as the call reached its gate through a CLI's own MCP client, before any answer: nothing is sent until its
134
- * agentrun.call.sent mark (KINDS.callSent). */
162
+ /** Written as the call reached its gate through a CLI's own MCP client, or its tool bridge's gate asked about it, before
163
+ * any answer: nothing is sent until its agentrun.call.sent mark (KINDS.callSent). */
135
164
  readonly parked?: true;
165
+ /** Parked in its CLI's tool bridge (adapter-loop.ts bridgeGate), not at an MCP door: the bridge holds the call and hands
166
+ * the CLI nothing while it waits, so no waiting result shows for it (store-reads/journal.ts piShaped), as on pi. */
167
+ readonly bridge?: true;
168
+ /** The harness's working directory (a CLI's), which an absolute path in `input` is built from: the run's rows name a
169
+ * path under it by its name in the workspace (store-reads/journal.ts runTimeline). */
170
+ readonly cwd?: string;
136
171
  /** When it was written (ms, the loop's clock): the Timeline dates the call's row by it. */
137
172
  readonly at?: number;
138
173
  }
@@ -216,15 +251,26 @@ export declare function withdrawnAnswers(entries: readonly {
216
251
  export interface EndData {
217
252
  readonly state: "ended" | "stopped" | "failed";
218
253
  readonly summary?: string;
219
- /** How an ended run ended, set only for an escalation (the store's RunOutcome). */
220
- readonly outcome?: "completed" | "escalated";
221
- /** What the run cost, as its end knows it. */
222
- readonly costUsd?: number;
254
+ /** How the run ended beside its state (the store's RunOutcome): an escalation's 'escalated'; a stopped end's 'stopped'
255
+ * (a person's stop: the turn is over, not the run) or 'cancelled' (stopEnd). */
256
+ readonly outcome?: "completed" | "escalated" | "stopped" | "cancelled";
257
+ /** What the run cost, as its end knows it: null when unknown, which clears a cost an earlier end of the run stored (a
258
+ * follow-up's end). Absent: the stored cost is left as it is. */
259
+ readonly costUsd?: number | null;
223
260
  /** The run's metrics (the old StoredMetrics JSON). */
224
261
  readonly metrics?: unknown;
225
262
  /** A completed workflow run's output: the value at its workflow's output path (readWorkflowRun's `output`, null when it
226
263
  * has none), kept at its end as main's server kept it on the run (runs.ts workflowEnd), and served as result.output. */
227
264
  readonly output?: unknown;
265
+ /** An escalated workflow run's review (outcome escalated): why it waits for a person, as its escalate node said it. */
266
+ readonly review?: EndReview;
267
+ }
268
+ /** An escalated workflow run's review as its end keeps it: the escalation's kind, the escalate node's label (else the node
269
+ * it escalated at), and its summary (else the run's). Served as the run's `review`, `at` its end. */
270
+ export interface EndReview {
271
+ readonly kind: string | null;
272
+ readonly node: string | null;
273
+ readonly reason: string;
228
274
  }
229
275
  export interface SessionKeyData {
230
276
  readonly key: string;
@@ -1,4 +1,6 @@
1
1
  import { INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
2
+ /** The session (sessions.ts journalSessions) a workflow run's call nodes log their effects on (KINDS.nodeEffect). */
3
+ export const NODE_LOG_SESSION = "node-log";
2
4
  /** The phase row before a message a CLI run sends again (adapter-loop.ts CliRecord.sending): its runner was lost after
3
5
  * sending it, before the message was recorded, so the model may read it twice, and the turn it starts is paid like any
4
6
  * other. */
@@ -20,7 +22,7 @@ export const KINDS = {
20
22
  * a call nor a message, so the reader passes over it. */
21
23
  messageSending: "agentrun.message.sending",
22
24
  /** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
23
- * the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
25
+ * the Timeline's attribution (the timeline reads a host's user entry's own origin). The model
24
26
  * reads it as any message. */
25
27
  input: "agentrun.input",
26
28
  /** A tool call the gate asked a person about: the run parks on it. */
@@ -47,11 +49,28 @@ export const KINDS = {
47
49
  /** The resume of a paused workflow run (a `resume` row), taken: the workflow goes on from its journal. Neither a call nor
48
50
  * a message, so the reader passes over it. */
49
51
  resume: "agentrun.resume",
52
+ /** A paid call the cap refused for room, kept at its refusal (the Refusal): its pause lands at the model's next request
53
+ * (adapter-loop.ts pauseFor), and a claim lost before that restores it from here (pendingPauseOf). No run patch, and
54
+ * neither a call nor a message, so the reader passes over it. */
55
+ pausePending: "agentrun.pause.pending",
56
+ /** A workflow call node's effect, as it starts and as it ends (pause.ts NodeLine: its path, item, tool, label, input,
57
+ * then its status and output or error), on the run's node-log session (NODE_LOG_SESSION): the run's graph lists its
58
+ * effects from these. Written as the effect runs, never for one the driver answers from its receipt. */
59
+ nodeEffect: "agentrun.node.effect",
50
60
  /** A CLI run's end-of-run turn (the loop's record): its prompt (`role: "person"`) and its answer (`role: "model"`, the
51
61
  * text in `model` as pi's answer carries it), the entry and the answer of the submission its request id names, the
52
62
  * same submission pi's adapter writes, so the step reads both alike. Neither a call nor a message: the reader passes
53
63
  * over it, and the turn is never on the run's visible record. */
54
64
  endOfRunTurn: "agentrun.end-of-run.turn",
65
+ /** What a learning run's claim laid of its seed: the learned skills it was given (`skills`, by name) and the learned
66
+ * workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
67
+ * what the run was given. Neither a call nor a message. */
68
+ learningLaid: "agentrun.learning.laid",
69
+ /** A workflow run's model node's execution, as the runner kept it before running it (workflow-spec.ts onModelNode):
70
+ * `{ path, tier?, model }`, its execution path, the tier it asked for (absent for none) and the model id the run's route
71
+ * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
72
+ * call nor a message. */
73
+ nodeModel: "agentrun.node.model",
55
74
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
56
75
  learningGraded: "agentrun.learning.graded",
57
76
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -79,6 +98,15 @@ export const ASK_PERSON_WAITING = "Waiting for your reply";
79
98
  export const HANDOVER_WAITING = "Waiting for you in the browser";
80
99
  /** The summaries of a run held in its claim while it waits on its person: the server tells run.needs_input by them. */
81
100
  export const HELD_WAITS = new Set([ASK_PERSON_WAITING, HANDOVER_WAITING]);
101
+ /** The cap a run is held to now, from its journal: its newest raise's (a KINDS.raise entry above 0), else its launch's;
102
+ * none for a run launched with no cap. The one figure every reader of the run's cap takes: each request's admission
103
+ * (adapter-loop.ts capNow), the run's view, and its end-of-run look back (learning-end.ts). */
104
+ export function capNowOf(launchCapUsd, entries) {
105
+ if (launchCapUsd === undefined)
106
+ return undefined;
107
+ const raised = entries.findLast((entry) => entry.kind === KINDS.raise && typeof entry.data?.capUsd === "number" && entry.data.capUsd > 0);
108
+ return raised ? raised.data.capUsd : launchCapUsd;
109
+ }
82
110
  /** What a call that already ended answers when it is asked for again (a parked call's resume, a CLI's re-issue of its id):
83
111
  * its recorded output; for one a crash cut with none, the kernel's words for an outcome not known (INTERRUPTED_TEXT);
84
112
  * else that `tool`'s call ended so. An error unless it ended done. */
@@ -1,5 +1,6 @@
1
1
  import { type TimelineEvent } from "../timeline/index.js";
2
2
  import { type LearningFolder } from "../learn/folder.js";
3
+ import type { RunPath } from "../learning-cost.js";
3
4
  import { type RunLaunch } from "../run-launch.js";
4
5
  import { type SignInReader } from "../run-view.js";
5
6
  import type { Store } from "../store/store.js";
@@ -28,11 +29,25 @@ export interface LearningEndDeps {
28
29
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
29
30
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
30
31
  export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
32
+ /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
33
+ * A harness that names it another way reads as another tool, so its run is asked as before. */
34
+ export declare const LEARNED_NAMES: ReadonlySet<string>;
31
35
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
32
36
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
33
37
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
34
38
  * came in. Anything else is asked its end-of-run turn. */
35
39
  export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
40
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
41
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
42
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
43
+ * otherwise, `agent` when it called none. */
44
+ export declare function runPathOf(rows: readonly TimelineEvent[]): RunPath;
45
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
46
+ * or null when it called none by a name. */
47
+ export declare function workflowNameOf(calls: readonly {
48
+ tool: string;
49
+ args: Record<string, unknown>;
50
+ }[]): string | null;
36
51
  /** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
37
52
  * no repeated job. */
38
53
  export declare const DRAFT_SCAN_RUNS = 200;
@@ -37,7 +37,9 @@ import { said, STOPPED } from "../learning-words.js";
37
37
  import { proposeRun } from "../propose.js";
38
38
  import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
39
39
  import { costOf } from "../run-view.js";
40
+ import { readApprovers } from "../server-approvers.js";
40
41
  import { runEntries, runReflect, runTimeline } from "../store-reads/journal.js";
42
+ import { capNowOf } from "./journal-kinds.js";
41
43
  import { createReflectHook } from "./reflect-hook.js";
42
44
  import { runnerSecrets } from "./redact.js";
43
45
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
@@ -49,22 +51,24 @@ export function learningEndOfRun(launch, deps) {
49
51
  const env = deps.env ?? process.env;
50
52
  // The grade model the server named at the run's start (its learning start's), none: the agent's own grades it.
51
53
  const gradeModel = start.gradeModel;
52
- const capUsd = launch.maxCostUsd;
53
54
  const hookFor = (runId) => createReflectHook({
54
55
  // reflectSkip's facts: a run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be
55
- // kept within it. A person's stop comes to the hook as its `cut`.
56
+ // kept within it. The cap is the run's now (capNowOf: its newest raise's, else its launch's), the one its requests
57
+ // were admitted under, never the launch's alone. A person's stop comes to the hook as its `cut`.
56
58
  facts: async (runId) => {
57
59
  const costUsd = costOf(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false }));
60
+ const capUsd = launch.maxCostUsd === undefined ? undefined : capNowOf(launch.maxCostUsd, await runEntries(deps.store, runId, BACKGROUND_CONTEXT));
58
61
  return { learns: true, costUsd, ...(capUsd !== undefined ? { capUsd, capReached: costUsd !== null && costUsd >= capUsd } : {}) };
59
62
  },
60
63
  nothingNew: async (runId) => onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
61
64
  // A draft asked for or not never stops the turn: a count that can't be read asks for none.
62
65
  promptFacts: async (runId, agentId) => {
63
66
  const { tools } = await draftTools(deps, runId);
64
- const draftFor = await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
67
+ // A notes run (`learning: "notes"`) is asked for no workflow draft, and its prompt describes none.
68
+ const draftFor = start.notesOnly ? [] : await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
65
69
  // With a draft asked for, what each tool its call nodes may run takes and gives, in the server's own words.
66
- const described = draftFor.length ? await describedOf(tools) : [];
67
- return { active: start.seedNotes ?? start.given.length, tools, draftFor, described };
70
+ const described = draftFor.length ? await describedOf(tools, deps.store) : [];
71
+ return { active: start.seedNotes ?? start.given.length, tools, draftFor, described, ...(start.notesOnly ? { workflows: false } : {}) };
68
72
  },
69
73
  asked: async (runId) => {
70
74
  const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
@@ -94,7 +98,7 @@ export function learningEndOfRun(launch, deps) {
94
98
  check: async ({ runId, agentId, turn, outcome, refuse }) => {
95
99
  if (start.seed === null)
96
100
  throw new Error("the run's learning start names no commit of main to propose against");
97
- return checkedOf(deps, { runId, agentId, seed: start.seed, turn, outcome, refuse });
101
+ return checkedOf(deps, { runId, agentId, seed: start.seed, turn, outcome, refuse, ...(start.notesOnly ? { workflows: false } : {}) });
98
102
  },
99
103
  // The learning run's id, one per run: a replayed end queues the same one (the store adds it once).
100
104
  newRunId: () => `${runId}-learning`,
@@ -114,7 +118,7 @@ export function learningEndOfRun(launch, deps) {
114
118
  }
115
119
  /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
116
120
  * A harness that names it another way reads as another tool, so its run is asked as before. */
117
- const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
121
+ export const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
118
122
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
119
123
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
120
124
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
@@ -134,14 +138,94 @@ export function onlyLearnedWorkflows(rows) {
134
138
  const answered = new Set(results.filter((row) => !row.parent_tool_use_id).map((row) => row.tool_use_id));
135
139
  return calls.every((row) => answered.has(row.tool_use_id));
136
140
  }
141
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
142
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
143
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
144
+ * otherwise, `agent` when it called none. */
145
+ export function runPathOf(rows) {
146
+ const ran = rows.some((row) => row.agent_label !== LEARNING_LABEL && row.kind === "tool_use" && !row.parent_tool_use_id && LEARNED_NAMES.has(row.tool_name ?? ""));
147
+ if (!ran)
148
+ return "agent";
149
+ return onlyLearnedWorkflows(rows) ? "workflow" : "handed_back";
150
+ }
151
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
152
+ * or null when it called none by a name. */
153
+ export function workflowNameOf(calls) {
154
+ for (let i = calls.length - 1; i >= 0; i--) {
155
+ const call = calls[i];
156
+ if (LEARNED_NAMES.has(call.tool) && typeof call.args.name === "string")
157
+ return call.args.name;
158
+ }
159
+ return null;
160
+ }
161
+ /** Why each draft of `proposal` waits for its owner's OK whatever the grade: its steps calling an MCP tool with no
162
+ * declared price (skills.ts unpricedCalls), by its workflow.json's path, from the prices each server's row keeps
163
+ * (mcp-probe.ts McpPrices). A server the store can't read gives no price: held. */
164
+ async function heldOf(store, proposal) {
165
+ const files = (proposal?.files ?? []).filter((one) => typeof one?.file === "string" && one.file.endsWith("/workflow.json") && typeof one.text === "string");
166
+ const { draftMcpTools, unpricedCalls, unpricedLine } = await import("../learn/skills.js");
167
+ const rows = new Map();
168
+ const priced = new Map();
169
+ const held = {};
170
+ for (const { file, text } of files) {
171
+ let doc;
172
+ try {
173
+ doc = JSON.parse(text);
174
+ }
175
+ catch {
176
+ continue;
177
+ }
178
+ // Every MCP tool its call nodes run, as the workflow's own read reads them (draftMcpTools over the parsed JSON: an
179
+ // escaped "\/" is a slash there), its price read first (unpricedCalls asks synchronously).
180
+ for (const name of draftMcpTools(doc)) {
181
+ const [server, tool] = name.slice("mcp:".length).split("/");
182
+ if (!rows.has(server))
183
+ rows.set(server, store.mcp.server(server).catch(() => undefined));
184
+ const price = (await rows.get(server))?.prices?.[tool];
185
+ priced.set(name, typeof price === "number" && Number.isFinite(price) ? price : undefined);
186
+ }
187
+ const lines = unpricedCalls(doc, (tool) => priced.get(tool)).map(unpricedLine);
188
+ if (lines.length)
189
+ held[file] = lines;
190
+ }
191
+ return held;
192
+ }
193
+ /** The tools each saved MCP server lists now, by the server's name (none for one not saved, or a store that can't be
194
+ * read): what a wildcard grant names (tools.ts mcpGrantsListed). */
195
+ async function mcpListedOf(store) {
196
+ const rows = await store.mcp.servers().catch(() => []);
197
+ const byName = new Map(rows.map((row) => [row.name, (row.tools ?? []).flatMap((tool) => (typeof tool?.name === "string" ? [tool.name] : []))]));
198
+ return (server) => byName.get(server) ?? [];
199
+ }
137
200
  /** What each of `tools` takes and gives a workflow's call node, in the server's own words for it (tools.ts ToolEntry's
138
- * summary): the draft ask's `describe`. */
139
- async function describedOf(tools) {
201
+ * summary): the draft ask's `describe`. An MCP tool (`mcp:<server>/<tool>`, LS-07) is described by its server's listing
202
+ * as the store keeps it: what it does, the schema it takes and, when it lists one, the one it gives (reflect.ts cuts
203
+ * each line to its cap). A server or a tool the store does not list is described by none. */
204
+ async function describedOf(tools, store) {
140
205
  const { toolOf } = await import("../tools.js");
141
- return tools.flatMap((name) => {
142
- const does = toolOf(name)?.summary;
143
- return does ? [{ name, does }] : [];
144
- });
206
+ const listed = new Map();
207
+ const out = [];
208
+ for (const name of tools) {
209
+ const mcp = /^mcp:([^/]+)\/(.+)$/.exec(name);
210
+ if (!mcp) {
211
+ const does = toolOf(name)?.summary;
212
+ if (does)
213
+ out.push({ name, does });
214
+ continue;
215
+ }
216
+ const server = mcp[1];
217
+ const tool = mcp[2];
218
+ if (!listed.has(server))
219
+ listed.set(server, store.mcp.server(server).catch(() => undefined));
220
+ const row = await listed.get(server);
221
+ const entry = (row?.tools ?? []).find((one) => one?.name === tool);
222
+ if (!entry)
223
+ continue;
224
+ const said = typeof entry.description === "string" && entry.description.trim() ? entry.description.trim() : typeof entry.title === "string" ? entry.title.trim() : "";
225
+ const does = [said ? `${said.replace(/[.\s]+$/, "")}.` : "", `Takes ${JSON.stringify(entry.input_schema ?? {})}.`, entry.output_schema !== undefined ? `Gives ${JSON.stringify(entry.output_schema)}.` : ""].filter(Boolean).join(" ");
226
+ out.push({ name, does });
227
+ }
228
+ return out;
145
229
  }
146
230
  /** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
147
231
  * no repeated job. */
@@ -201,28 +285,34 @@ async function draftTools(deps, runId) {
201
285
  const run = await deps.store.runs.get(runId);
202
286
  const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
203
287
  if (revision?.kind !== "agentic")
204
- return { tools: [], gated: {} };
288
+ return { tools: [], gated: {}, deniedBy: {}, asked: [] };
205
289
  const body = revision.body;
206
- const [{ learnedDraftTools }, { permissionFrom }, { loadToolSettings }] = await Promise.all([import("../tools.js"), import("../tool-gate.js"), import("../tool-plane.js")]);
290
+ const [{ learnedDraftTools, mcpGrantsListed }, { permissionFrom }, { loadToolSettings }] = await Promise.all([import("../tools.js"), import("../tool-gate.js"), import("../tool-plane.js")]);
207
291
  // The server's settings from the one store, as the run's gate reads them: a stored row that does not read carries
208
292
  // SETTINGS_UNREAD, which permissionFrom honours (no ask is lifted over a deny the row may hold).
209
293
  const server = (await loadToolSettings(deps.store)).settings;
210
294
  const agent = (body.toolSettings ?? {});
211
295
  const approvals = body.approvals === "never" ? "never" : "ask";
212
- const { tools, gated } = learnedDraftTools(body.tools ?? [], (name) => permissionFrom(name, server, agent, approvals).permission, undefined, (name) => permissionFrom(name, server, agent, approvals).from);
213
- return { tools, gated };
296
+ // A server's wildcard grant read as the tools its server lists now (tools.ts mcpGrantsListed, LS-07).
297
+ const granted = (body.tools ?? []).some((name) => /^mcp:[^/]+\/\*$/.test(name)) ? mcpGrantsListed(body.tools ?? [], await mcpListedOf(deps.store)) : (body.tools ?? []);
298
+ // `deniedBy`: where each deny was set (the agent's tool settings, the server's, a default), which a left-out draft's
299
+ // words name.
300
+ const { tools, gated, deniedBy, asked } = learnedDraftTools(granted, (name) => permissionFrom(name, server, agent, approvals).permission, undefined, (name) => permissionFrom(name, server, agent, approvals).from, { mcp: true, approvers: await readApprovers(deps.store.settings) });
301
+ return { tools, gated, deniedBy, asked };
214
302
  }
215
303
  /** proposeRun's checks over the turn, against seed `seed`, in a directory of the step's own: the proposal it keeps there
216
304
  * is read back for the hook to store with the run's end, and the directory is removed. */
217
305
  async function checkedOf(deps, input) {
218
306
  const runDir = await mkdtemp(join(tmpdir(), "agentrun-learning-end-"));
219
307
  try {
220
- const { tools, gated } = await draftTools(deps, input.runId);
308
+ const { tools, gated, deniedBy, asked } = await draftTools(deps, input.runId);
309
+ // #2424's card rule (learnedAskFits): a draft whose ask-set MCP tools would not all show on its approval card is refused.
310
+ const { learnedAskFits } = await import("../learned-workflow.js");
221
311
  const turn = { answer: input.turn.answer, asked: [...input.turn.asked], ...(input.turn.triggered?.length ? { triggered: input.turn.triggered.map((one) => ({ ...one })) } : {}) };
222
312
  const folder = deps.learningFolder(input.agentId);
223
313
  let proposed;
224
314
  try {
225
- proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}) });
315
+ proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ask: { asked, fits: learnedAskFits }, ...(input.workflows === false ? { workflows: false } : {}) });
226
316
  }
227
317
  finally {
228
318
  await folder.end();
@@ -230,7 +320,10 @@ async function checkedOf(deps, input) {
230
320
  if (proposed.state !== "proposed")
231
321
  return proposed;
232
322
  const proposal = JSON.parse(await readFile(join(runDir, PROPOSAL), "utf8"));
233
- return { ...proposed, proposal };
323
+ // A draft calling an MCP tool with no declared price waits for its owner's OK whatever the grade (LS-07): held here,
324
+ // from the prices the store keeps now, and said to the grader.
325
+ const held = await heldOf(deps.store, proposal);
326
+ return { ...proposed, proposal: Object.keys(held).length ? { ...proposal, held } : proposal };
234
327
  }
235
328
  finally {
236
329
  await rm(runDir, { recursive: true, force: true });
@@ -6,8 +6,10 @@
6
6
  // (passed in by the runner's wiring);
7
7
  // folder the agent's learning folder in the server's data (learn/folder.ts learningWorkspace), ended after each run;
8
8
  // readMain main as the grader reads it, from the folder's snapshot (learn/commit.ts readMain);
9
- // commit the folder's one write (learn/commit.ts learningCommit).
10
- import { learningCommit, readMain } from "../learn/commit.js";
9
+ // commit the folder's one write (learn/commit.ts learningCommit);
10
+ // merged the run's merge when it is on main already, with the texts its own commit holds (learn/commit.ts mergedAt),
11
+ // for a resume after its commit.
12
+ import { learningCommit, mainTexts, mergedAt, readMain } from "../learn/commit.js";
11
13
  import { learningWorkspace } from "../learn/folder.js";
12
14
  import { createLearningLoop } from "./learning-loop.js";
13
15
  /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
@@ -32,6 +34,8 @@ export function learningLoopFactory(deps) {
32
34
  folder: (agentId) => learningWorkspace({ mode: "local", agentId, data: deps.data, ...(deps.log ? { log: deps.log } : {}) }),
33
35
  readMain: async (ws, proposal) => (await readMain(ws, { notes: proposal.notes })),
34
36
  commit: async (ws, change) => (await learningCommit(ws, change)),
37
+ mainTexts: (ws, paths) => mainTexts(ws, paths),
38
+ merged: (ws, runId, paths) => mergedAt(ws, runId, paths),
35
39
  ...(deps.now ? { now: deps.now } : {}),
36
40
  });
37
41
  }