@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
@@ -3,10 +3,12 @@
3
3
  // once at the run's start. A spec builder gives the adapter loop `endOfRun: learningEndOfRun(launch, deps)`. Each of the
4
4
  // hook's reads is the server's own rule, over the store in place of the run's directory:
5
5
  // - whether it looks back (learning-run.ts reflectSkip): its cap and its spend so far, read as its view reads them;
6
- // - its prompt's facts: how many notes its seed held (launch seedNotes) and the tools a workflow draft may name
7
- // (learning-run.ts draftTools);
6
+ // - its prompt's facts: how many notes its seed held (launch seedNotes), the tools a workflow draft may name
7
+ // (learning-run.ts draftTools), and the learned skill whose job it asks for as a workflow draft (draftForOf);
8
8
  // - what the person said in the run and a trigger's input (heard.ts Hearing over its entries, the end-of-run turn's
9
9
  // own left out), as learning-run.ts turnOf reads them;
10
+ // - whether the job gave nothing new to look back on (onlyLearnedWorkflows over its timeline): a run whose only tool
11
+ // work was its learned workflows, each answering, is not asked;
10
12
  // - the checks: propose.ts proposeRun against the seed it started from, the server's one rule, which keeps the
11
13
  // proposal the hook stores beside the run's end (learning_proposals);
12
14
  // - what the run must never learn (learning-run.ts refused, the server's serverSecrets as far as the runner reads
@@ -21,16 +23,23 @@ import { mkdtemp, readFile, rm } from "node:fs/promises";
21
23
  import { tmpdir } from "node:os";
22
24
  import { join } from "node:path";
23
25
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
26
+ import { isMessageRow } from "../timeline/index.js";
24
27
  import { Hearing } from "../heard.js";
28
+ import { readSnapshot } from "../learn/folder.js";
29
+ import { DRAFT_AFTER_RUNS } from "../learn/reflect.js";
30
+ import { SKILL_NAME } from "../learn/skills.js";
25
31
  import { handedValuesOf } from "../handed-values.js";
26
32
  import { MIN_SECRET } from "../learn/secrets.js";
27
- import { gradeModelOf, PROPOSAL } from "../learning.js";
28
- import { reflects } from "../learning-run.js";
33
+ import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
34
+ import { LEARNING_LABEL, PROPOSAL } from "../learning.js";
35
+ import { reflects } from "../reflect-range.js";
29
36
  import { said, STOPPED } from "../learning-words.js";
30
37
  import { proposeRun } from "../propose.js";
31
- import { learningStartOf } from "../run-launch.js";
38
+ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
32
39
  import { costOf } from "../run-view.js";
40
+ import { readApprovers } from "../server-approvers.js";
33
41
  import { runEntries, runReflect, runTimeline } from "../store-reads/journal.js";
42
+ import { capNowOf } from "./journal-kinds.js";
34
43
  import { createReflectHook } from "./reflect-hook.js";
35
44
  import { runnerSecrets } from "./redact.js";
36
45
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
@@ -40,16 +49,26 @@ export function learningEndOfRun(launch, deps) {
40
49
  if (!start)
41
50
  return undefined;
42
51
  const env = deps.env ?? process.env;
43
- const gradeModel = deps.gradeModel ?? gradeModelOf(env);
44
- const capUsd = launch.maxCostUsd;
52
+ // The grade model the server named at the run's start (its learning start's), none: the agent's own grades it.
53
+ const gradeModel = start.gradeModel;
45
54
  const hookFor = (runId) => createReflectHook({
46
55
  // reflectSkip's facts: a run its cap stopped has no room left, and one whose spend is unknown under a cap cannot be
47
- // 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`.
48
58
  facts: async (runId) => {
49
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));
50
61
  return { learns: true, costUsd, ...(capUsd !== undefined ? { capUsd, capReached: costUsd !== null && costUsd >= capUsd } : {}) };
51
62
  },
52
- promptFacts: async (runId) => ({ active: start.seedNotes ?? start.given.length, tools: (await draftTools(deps, runId)).tools }),
63
+ nothingNew: async (runId) => onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
64
+ // A draft asked for or not never stops the turn: a count that can't be read asks for none.
65
+ promptFacts: async (runId, agentId) => {
66
+ const { tools } = await draftTools(deps, runId);
67
+ const draftFor = await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
68
+ // With a draft asked for, what each tool its call nodes may run takes and gives, in the server's own words.
69
+ const described = draftFor.length ? await describedOf(tools, deps.store) : [];
70
+ return { active: start.seedNotes ?? start.given.length, tools, draftFor, described };
71
+ },
53
72
  asked: async (runId) => {
54
73
  const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
55
74
  const hearing = new Hearing();
@@ -85,42 +104,194 @@ export function learningEndOfRun(launch, deps) {
85
104
  ...(gradeModel ? { gradeModel } : {}),
86
105
  });
87
106
  return async (input) => {
88
- // A seed that could not be read (no seedNotes, no commit): the server dropped its learning at the start, and the run
89
- // was never asked to look back.
90
- if (start.seed === null && start.seedNotes === undefined) {
91
- return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "seed_failed", detail: said.stopped(STOPPED.notCopied) } } }] };
107
+ // No seed, no end-of-run turn (seedFailed): a run that started from no commit of main has nothing to propose against,
108
+ // so it is never asked to look back (no model request). Why, as its start recorded it: a folder that could not be
109
+ // read, or a start that could not be made from it; a start that records none names no reason.
110
+ if (seedFailed(start)) {
111
+ const failed = start.seedFailed;
112
+ const why = failed === "unreadable" ? STOPPED.unreadable : failed === "not_copied" ? STOPPED.notCopied : STOPPED.noSeed;
113
+ return { also: [{ table: "learning_proposals", row: { turn: null, proposal: { state: "dropped", reason: "seed_failed", detail: said.stopped(why) } } }] };
92
114
  }
93
115
  return hookFor(input.runId)(input);
94
116
  };
95
117
  }
118
+ /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
119
+ * A harness that names it another way reads as another tool, so its run is asked as before. */
120
+ const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
121
+ /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
122
+ * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
123
+ * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
124
+ * came in. Anything else is asked its end-of-run turn. */
125
+ export function onlyLearnedWorkflows(rows) {
126
+ const own = rows.filter((row) => row.agent_label !== LEARNING_LABEL);
127
+ if (own.some((row) => row.kind === "error" || row.kind === "tool_approval_requested" || row.kind === "waiting"))
128
+ return false;
129
+ if (own.filter(isMessageRow).length !== 1)
130
+ return false;
131
+ const calls = own.filter((row) => row.kind === "tool_use" && !row.parent_tool_use_id);
132
+ if (!calls.length || calls.some((row) => !LEARNED_NAMES.has(row.tool_name ?? "")))
133
+ return false;
134
+ const results = own.filter((row) => row.kind === "tool_result");
135
+ if (results.some((row) => row.tool_status !== "success"))
136
+ return false;
137
+ const answered = new Set(results.filter((row) => !row.parent_tool_use_id).map((row) => row.tool_use_id));
138
+ return calls.every((row) => answered.has(row.tool_use_id));
139
+ }
140
+ /** Why each draft of `proposal` waits for its owner's OK whatever the grade: its steps calling an MCP tool with no
141
+ * declared price (skills.ts unpricedCalls), by its workflow.json's path, from the prices each server's row keeps
142
+ * (mcp-probe.ts McpPrices). A server the store can't read gives no price: held. */
143
+ async function heldOf(store, proposal) {
144
+ const files = (proposal?.files ?? []).filter((one) => typeof one?.file === "string" && one.file.endsWith("/workflow.json") && typeof one.text === "string");
145
+ const { draftMcpTools, unpricedCalls, unpricedLine } = await import("../learn/skills.js");
146
+ const rows = new Map();
147
+ const priced = new Map();
148
+ const held = {};
149
+ for (const { file, text } of files) {
150
+ let doc;
151
+ try {
152
+ doc = JSON.parse(text);
153
+ }
154
+ catch {
155
+ continue;
156
+ }
157
+ // Every MCP tool its call nodes run, as the workflow's own read reads them (draftMcpTools over the parsed JSON: an
158
+ // escaped "\/" is a slash there), its price read first (unpricedCalls asks synchronously).
159
+ for (const name of draftMcpTools(doc)) {
160
+ const [server, tool] = name.slice("mcp:".length).split("/");
161
+ if (!rows.has(server))
162
+ rows.set(server, store.mcp.server(server).catch(() => undefined));
163
+ const price = (await rows.get(server))?.prices?.[tool];
164
+ priced.set(name, typeof price === "number" && Number.isFinite(price) ? price : undefined);
165
+ }
166
+ const lines = unpricedCalls(doc, (tool) => priced.get(tool)).map(unpricedLine);
167
+ if (lines.length)
168
+ held[file] = lines;
169
+ }
170
+ return held;
171
+ }
172
+ /** 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
173
+ * read): what a wildcard grant names (tools.ts mcpGrantsListed). */
174
+ async function mcpListedOf(store) {
175
+ const rows = await store.mcp.servers().catch(() => []);
176
+ const byName = new Map(rows.map((row) => [row.name, (row.tools ?? []).flatMap((tool) => (typeof tool?.name === "string" ? [tool.name] : []))]));
177
+ return (server) => byName.get(server) ?? [];
178
+ }
179
+ /** What each of `tools` takes and gives a workflow's call node, in the server's own words for it (tools.ts ToolEntry's
180
+ * summary): the draft ask's `describe`. An MCP tool (`mcp:<server>/<tool>`, LS-07) is described by its server's listing
181
+ * as the store keeps it: what it does, the schema it takes and, when it lists one, the one it gives (reflect.ts cuts
182
+ * each line to its cap). A server or a tool the store does not list is described by none. */
183
+ async function describedOf(tools, store) {
184
+ const { toolOf } = await import("../tools.js");
185
+ const listed = new Map();
186
+ const out = [];
187
+ for (const name of tools) {
188
+ const mcp = /^mcp:([^/]+)\/(.+)$/.exec(name);
189
+ if (!mcp) {
190
+ const does = toolOf(name)?.summary;
191
+ if (does)
192
+ out.push({ name, does });
193
+ continue;
194
+ }
195
+ const server = mcp[1];
196
+ const tool = mcp[2];
197
+ if (!listed.has(server))
198
+ listed.set(server, store.mcp.server(server).catch(() => undefined));
199
+ const row = await listed.get(server);
200
+ const entry = (row?.tools ?? []).find((one) => one?.name === tool);
201
+ if (!entry)
202
+ continue;
203
+ const said = typeof entry.description === "string" && entry.description.trim() ? entry.description.trim() : typeof entry.title === "string" ? entry.title.trim() : "";
204
+ 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(" ");
205
+ out.push({ name, does });
206
+ }
207
+ return out;
208
+ }
209
+ /** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
210
+ * no repeated job. */
211
+ export const DRAFT_SCAN_RUNS = 200;
212
+ /** The learned skill whose job the end-of-run turn asks for as a workflow draft: of the skills run `runId` was offered
213
+ * (its launch's learning start), the first in the seed's order (the one changed last first) offered to DRAFT_AFTER_RUNS
214
+ * or more runs of agent `agentId` started before it (each run's launch says what it was offered; its latest
215
+ * DRAFT_SCAN_RUNS runs are read newest first, those after `runId` in that order counted, only until every skill has its
216
+ * count), with no learned workflow of its name on the agent's main, active or waiting for
217
+ * its owner's OK (the folder's snapshot). One at most: a turn keeps one workflow draft. None when no skill qualifies, or
218
+ * when the folder can't be read: a read that fails asks for nothing, never a draft that may be there already. */
219
+ export async function draftForOf(deps, agentId, runId, offered) {
220
+ // Only a skill's name reaches the prompt (reflectPrompt refuses anything else).
221
+ const served = new Map(offered.filter((name) => SKILL_NAME.test(name)).map((name) => [name, 0]));
222
+ if (!served.size)
223
+ return [];
224
+ // The list is newest first: only the runs after the ending one in it started before it, and count. A run started
225
+ // later (a long job's newer runs) never does, and an ending run past the latest DRAFT_SCAN_RUNS + 1 counts none.
226
+ let earlier = false;
227
+ for (const run of await deps.store.runs.list({ agentId, limit: DRAFT_SCAN_RUNS + 1 })) {
228
+ if (run.id === runId) {
229
+ earlier = true;
230
+ continue;
231
+ }
232
+ if (!earlier || run.agentId !== agentId)
233
+ continue;
234
+ const row = await deps.store.runs.launch(run.id).catch(() => undefined);
235
+ const launch = row ? readLaunchBody(row.body) : undefined;
236
+ for (const name of (launch && learningStartOf(launch)?.skills) ?? [])
237
+ if (served.has(name))
238
+ served.set(name, served.get(name) + 1);
239
+ // Enough runs read once every skill has served its count.
240
+ if ([...served.values()].every((count) => count >= DRAFT_AFTER_RUNS))
241
+ break;
242
+ }
243
+ const due = [...served].filter(([, count]) => count >= DRAFT_AFTER_RUNS);
244
+ if (!due.length)
245
+ return [];
246
+ let drafted;
247
+ const folder = deps.learningFolder(agentId);
248
+ try {
249
+ const snapshot = await readSnapshot(folder.workspace);
250
+ drafted = new Set((snapshot?.workflows ?? []).filter(({ status }) => status === "active" || status === "pending").map(({ name }) => name));
251
+ }
252
+ catch {
253
+ return [];
254
+ }
255
+ finally {
256
+ await folder.end().catch(() => undefined);
257
+ }
258
+ const open = due.find(([name]) => !drafted.has(name));
259
+ return open ? [open[0]] : [];
260
+ }
96
261
  /** The tools a workflow draft may name (learning-run.ts draftTools): the revision's own, as its run's gate reads them
97
262
  * with the server's settings (from the store) and the agent's; none for a workflow revision. */
98
263
  async function draftTools(deps, runId) {
99
264
  const run = await deps.store.runs.get(runId);
100
265
  const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
101
266
  if (revision?.kind !== "agentic")
102
- return { tools: [], gated: {} };
267
+ return { tools: [], gated: {}, deniedBy: {}, asked: [] };
103
268
  const body = revision.body;
104
- const [{ learnedDraftTools }, { permissionFrom }, { loadToolSettings }] = await Promise.all([import("../tools.js"), import("../tool-gate.js"), import("../tool-plane.js")]);
269
+ const [{ learnedDraftTools, mcpGrantsListed }, { permissionFrom }, { loadToolSettings }] = await Promise.all([import("../tools.js"), import("../tool-gate.js"), import("../tool-plane.js")]);
105
270
  // The server's settings from the one store, as the run's gate reads them: a stored row that does not read carries
106
271
  // SETTINGS_UNREAD, which permissionFrom honours (no ask is lifted over a deny the row may hold).
107
272
  const server = (await loadToolSettings(deps.store)).settings;
108
273
  const agent = (body.toolSettings ?? {});
109
274
  const approvals = body.approvals === "never" ? "never" : "ask";
110
- const { tools, gated } = learnedDraftTools(body.tools ?? [], (name) => permissionFrom(name, server, agent, approvals).permission, undefined, (name) => permissionFrom(name, server, agent, approvals).from);
111
- return { tools, gated };
275
+ // A server's wildcard grant read as the tools its server lists now (tools.ts mcpGrantsListed, LS-07).
276
+ const granted = (body.tools ?? []).some((name) => /^mcp:[^/]+\/\*$/.test(name)) ? mcpGrantsListed(body.tools ?? [], await mcpListedOf(deps.store)) : (body.tools ?? []);
277
+ // `deniedBy`: where each deny was set (the agent's tool settings, the server's, a default), which a left-out draft's
278
+ // words name.
279
+ 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) });
280
+ return { tools, gated, deniedBy, asked };
112
281
  }
113
282
  /** proposeRun's checks over the turn, against seed `seed`, in a directory of the step's own: the proposal it keeps there
114
283
  * is read back for the hook to store with the run's end, and the directory is removed. */
115
284
  async function checkedOf(deps, input) {
116
285
  const runDir = await mkdtemp(join(tmpdir(), "agentrun-learning-end-"));
117
286
  try {
118
- const { tools, gated } = await draftTools(deps, input.runId);
287
+ const { tools, gated, deniedBy, asked } = await draftTools(deps, input.runId);
288
+ // #2424's card rule (learnedAskFits): a draft whose ask-set MCP tools would not all show on its approval card is refused.
289
+ const { learnedAskFits } = await import("../learned-workflow.js");
119
290
  const turn = { answer: input.turn.answer, asked: [...input.turn.asked], ...(input.turn.triggered?.length ? { triggered: input.turn.triggered.map((one) => ({ ...one })) } : {}) };
120
291
  const folder = deps.learningFolder(input.agentId);
121
292
  let proposed;
122
293
  try {
123
- proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}) });
294
+ 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 } });
124
295
  }
125
296
  finally {
126
297
  await folder.end();
@@ -128,7 +299,10 @@ async function checkedOf(deps, input) {
128
299
  if (proposed.state !== "proposed")
129
300
  return proposed;
130
301
  const proposal = JSON.parse(await readFile(join(runDir, PROPOSAL), "utf8"));
131
- return { ...proposed, proposal };
302
+ // A draft calling an MCP tool with no declared price waits for its owner's OK whatever the grade (LS-07): held here,
303
+ // from the prices the store keeps now, and said to the grader.
304
+ const held = await heldOf(deps.store, proposal);
305
+ return { ...proposed, proposal: Object.keys(held).length ? { ...proposal, held } : proposal };
132
306
  }
133
307
  finally {
134
308
  await rm(runDir, { recursive: true, force: true });
@@ -12,7 +12,14 @@ export declare const UNAVAILABLE_BACKOFF_MS: readonly [30000, 120000, 600000, 18
12
12
  export interface KeptProposal {
13
13
  readonly notes: readonly NoteText[];
14
14
  readonly files?: readonly NoteText[];
15
+ /** Each kept draft's dry run, by its workflow.json's path (learn/skills.ts draftDryRun), which the grader is told. */
16
+ readonly dryRuns?: Readonly<Record<string, {
17
+ readonly status: string;
18
+ readonly detail?: string;
19
+ }>>;
15
20
  readonly asked?: readonly string[];
21
+ /** Why each draft waits for its owner's OK whatever the grade (the learning end's: skills.ts unpricedCalls). */
22
+ readonly held?: Readonly<Record<string, readonly string[]>>;
16
23
  readonly triggered?: readonly {
17
24
  readonly source: string;
18
25
  readonly text: string;
@@ -13,7 +13,7 @@
13
13
  // merge's call merges once.
14
14
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
15
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
- import { gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
16
+ import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
17
17
  import { mergedNote, parseNoteFile } from "../learn/notes.js";
18
18
  import { learnedPlace } from "../learn/skills.js";
19
19
  import { notKept, said, STOPPED } from "../learning-words.js";
@@ -90,27 +90,39 @@ export function createLearningLoop(learning) {
90
90
  return (deps) => {
91
91
  let stopped = null;
92
92
  const now = learning.now ?? Date.now;
93
+ /** Aborted by a person's stop (a stop row): the grade's request is cut at once, never left running past it, while the
94
+ * claim's signal stays whole so the stopped end is still written. */
95
+ const stopAsk = new AbortController();
93
96
  return {
94
97
  async command(_command) {
95
98
  return { refused: "a learning run takes no messages or answers" };
96
99
  },
97
100
  async stop(reason) {
98
101
  stopped = reason;
102
+ if (reason.kind === "command")
103
+ stopAsk.abort(new Error("the run was stopped"));
99
104
  },
100
105
  async start(claim) {
101
106
  const context = withAbortSignal(deps.signal, BACKGROUND_CONTEXT);
102
107
  const journal = deps.journal(claim);
103
108
  let rooted = false;
109
+ /** What the grade spent, as the run's learning end reads it (store-reads/learning.ts runLearningEnd): the graded
110
+ * entry's, a failed or cut grade's (null: unknown), else nothing graded, 0. Kept as the learning run's cost when it
111
+ * ends ended, failed or stopped, so what learning spent reads from the run rows alone (store learning.spend): a
112
+ * stop seen after a paid grade never hides it. */
113
+ let spend = 0;
104
114
  /** One entry on the root, committed; `end` stages the run's state with it (keyed to this entry, its effect), and
105
- * `take` the stop row it applies. */
115
+ * `take` the stop row it applies. An end that ends, fails or stops the run keeps what the grade spent as its cost. */
106
116
  const append = async (kind, data, end, take) => {
107
117
  const writes = [];
118
+ if (kind === KINDS.learningDropped && data !== null && typeof data === "object" && "usd" in data)
119
+ spend = data.usd ?? null;
108
120
  if (!rooted && !(await journal.conversation(ROOT, context)))
109
121
  writes.push({ type: "conversation", value: { id: ROOT } });
110
122
  const id = await journal.mintId();
111
123
  writes.push({ type: "entry", value: { id, conversationId: ROOT, kind, data } });
112
124
  if (end)
113
- journal.stage({ run: { state: end }, effect: id, ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
125
+ journal.stage({ run: { state: end, ...(end === "parked" ? {} : { costUsd: spend }) }, effect: id, ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
114
126
  const result = await journal.commit([writes], () => { }, context);
115
127
  if (result.stored === 0)
116
128
  throw result.refused;
@@ -152,6 +164,8 @@ export function createLearningLoop(learning) {
152
164
  const unavailable = entries.filter((entry) => entry.kind === KINDS.learningUnavailable).length;
153
165
  // The grade: once. A verdict already in the journal is the one the merge goes on.
154
166
  let graded = entries.find((entry) => entry.kind === KINDS.learningGraded)?.data;
167
+ if (graded)
168
+ spend = graded.usd;
155
169
  if (!graded) {
156
170
  const main = await learning.readMain(ws, proposal);
157
171
  if ("problems" in main) {
@@ -161,17 +175,21 @@ export function createLearningLoop(learning) {
161
175
  const items = gradedItems(proposal.notes, (proposal.files ?? []));
162
176
  const prompt = gradePrompt({
163
177
  run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded: main.superseded, proposed: proposal.notes,
164
- ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}),
178
+ ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}), ...(proposal.held ? { held: proposal.held } : {}),
165
179
  });
166
180
  // What the grade spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
167
181
  // added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
168
182
  let usd = 0;
169
183
  let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
170
- const ask = async () => {
184
+ // `again`: what the grade is told after its last answer, below the same prompt.
185
+ const ask = async (again) => {
186
+ // Stopped before this ask: nothing is sent, so nothing of it is spent (what it spent stays as it was).
187
+ if (stopAsk.signal.aborted)
188
+ throw stopAsk.signal.reason;
171
189
  const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
172
190
  let answer;
173
191
  try {
174
- answer = await learning.ask({ prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
192
+ answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
175
193
  }
176
194
  catch (error) {
177
195
  usd = null;
@@ -185,12 +203,21 @@ export function createLearningLoop(learning) {
185
203
  };
186
204
  let verdict;
187
205
  try {
188
- verdict = parseVerdict(await ask(), items);
206
+ verdict = parseVerdict(await ask(), items, proposal.held);
189
207
  // An answer the host cannot read is asked once more, as the server's grade did.
190
208
  if (verdict.reason === UNREADABLE_REASON && !verdict.items.length)
191
- verdict = parseVerdict(await ask(), items);
209
+ verdict = parseVerdict(await ask(), items, proposal.held);
210
+ // One that kept every item and said no merge contradicts itself: asked once more, the contradiction named. A
211
+ // second contradiction stands as no merge, said in the host's words as twice (learning-words.ts notKept); a
212
+ // contradiction after an unreadable answer is one, and is said so.
213
+ else if (verdict.reason === CONTRADICTED_REASON) {
214
+ const again = parseVerdict(await ask(CONTRADICTION_ASK), items, proposal.held);
215
+ verdict = again.reason === CONTRADICTED_REASON ? { ...again, reason: CONTRADICTED_TWICE_REASON } : again;
216
+ }
192
217
  }
193
218
  catch (error) {
219
+ // What the asks spent: a cut one's unknown (null), kept on a stopped run's row as on a dropped one's.
220
+ spend = usd;
194
221
  const end = await halted();
195
222
  if (end)
196
223
  return end;
@@ -199,6 +226,7 @@ export function createLearningLoop(learning) {
199
226
  return { state: "ended" };
200
227
  }
201
228
  graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
229
+ spend = usd;
202
230
  await append(KINDS.learningGraded, graded);
203
231
  // The verdict is durable before the merge, its side effect.
204
232
  await deps.flush();
@@ -25,6 +25,12 @@ export type LaidSeed = {
25
25
  readonly skills: readonly string[];
26
26
  readonly workflows: readonly LearnedWorkflow[];
27
27
  };
28
+ /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
29
+ * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
30
+ export declare const laidOf: (laid: LaidSeed | undefined) => {
31
+ skills: string[];
32
+ workflows: string[];
33
+ };
28
34
  /** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
29
35
  * Never throws. */
30
36
  export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed | undefined>;
@@ -1,5 +1,11 @@
1
1
  import { chooseSkills, chooseWorkflows, layLearned, LEARNED_DIR, laySkills, readerOf, seedFrom, takeSkills } from "../learning.js";
2
2
  const message = (error) => (error instanceof Error ? error.message : String(error));
3
+ /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
4
+ * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
5
+ export const laidOf = (laid) => ({
6
+ skills: [...new Set((laid?.skills ?? []).map((path) => path.split("/")[0]))],
7
+ workflows: (laid?.workflows ?? []).map(({ name }) => name),
8
+ });
3
9
  /** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
4
10
  * Never throws. */
5
11
  export async function layLearningSeed(lay) {
@@ -128,6 +128,10 @@ export interface LoopDeps {
128
128
  * or at once when there were none: a resumed ask with no answer row waits for it before it parks again, so an
129
129
  * approve already on its way is never raced. Never rejects. */
130
130
  delivered?: Promise<void>;
131
+ /** Hands the run's command rows the runner has not handed on yet to command() now, not at its next poll (up to its
132
+ * command poll away), and resolves once each call returned: a turn that ends asks it before the run may end, so a
133
+ * message sent while the turn worked is answered, never refused by the run's end. Absent: nothing to hand on. */
134
+ deliverNow?: () => Promise<void>;
131
135
  /** Where the loop reports what its run shows before it is stored (a running tool, a partial answer), as it changes: a
132
136
  * reader of the newest held state (`undefined` once there is nothing held), called once per tick by the runner's live
133
137
  * ticker (runner/live-ticker.ts), never on every change, so a change costs the same however long the answer has grown.
@@ -1,16 +1,25 @@
1
1
  import { type Store } from "../store/index.js";
2
+ import { type ComputerDeps } from "../workspace/computer-deps.js";
2
3
  import type { LoopFactory } from "./loop-contract.js";
3
- import { type Runner, type RunnerEvent } from "./runner.js";
4
+ import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
4
5
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
5
6
  export interface RunnerProcessOptions {
6
7
  /** The data directory (--data): the store is the store module's file in it; the runner never names it. */
7
8
  dataDir: string;
8
9
  /** Most runs held at once (--loops). */
9
10
  loops?: number;
11
+ /** How long close() lets each busy run finish its turn (--drain-timeout; RunnerOptions.drainMs). Default 0. */
12
+ drainMs?: number;
13
+ /** Its memory budget and its runs' weights (RunnerOptions.memory). Default: this host's memory, each run weighed by its
14
+ * harness (memory-claim.ts runnerMemory). */
15
+ memory?: RunnerMemory;
10
16
  /** This runner's name in the runs it claims, its lines and its heartbeat. Default runner.ts runnerName(). */
11
17
  name?: string;
12
- /** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop). */
13
- createLoop?: LoopFactory | ((store: Store, sealKey: Buffer) => LoopFactory);
18
+ /** Each claimed run's loop; default the runner's dispatch over the store (runnerLoop), with the computers it composed. */
19
+ createLoop?: LoopFactory | ((store: Store, sealKey: Buffer) => LoopFactory | RunnerParts);
20
+ /** Run the computer janitor (workspace/computer-janitor.ts) over the computers createLoop composed: at the start, then
21
+ * on its interval. Only the runner subcommand asks for it; a test that does not ask runs none. */
22
+ janitor?: boolean;
14
23
  onEvent?: (event: RunnerEvent) => void;
15
24
  /** For tests: the clock the heartbeat is written by. Default Date.now. */
16
25
  now?: () => number;
@@ -29,6 +38,9 @@ export interface RunnerProcess {
29
38
  readonly kind: string;
30
39
  readonly schema: number;
31
40
  };
41
+ /** What its runs may hold, in MiB (RunnerMemory.budgetMib): its host's memory, or its container's limit, less the
42
+ * server's own. Said once at its start, after the ready line. */
43
+ readonly memoryMib: number;
32
44
  /** Closes the runner (its loops stopped, its runs released), then its store connection. */
33
45
  close(): Promise<void>;
34
46
  }
@@ -59,7 +71,13 @@ export declare function besideRunEnv(env: NodeJS.ProcessEnv, switches: NodeJS.Pr
59
71
  * its launch (harness-loops.ts resolveRunnerLoop), with the data directory, the run environment (runEnv), the store's
60
72
  * journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
61
73
  * this process's, as it was handed or booted). Refused in words with no seal key. */
62
- export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): LoopFactory;
74
+ export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): RunnerParts;
75
+ /** A runner's loop factory with the run's computers it composed and the runs' environment: what the janitor sweeps with. */
76
+ export type RunnerParts = {
77
+ readonly createLoop: LoopFactory;
78
+ readonly computers: ComputerDeps;
79
+ readonly env: NodeJS.ProcessEnv;
80
+ };
63
81
  /** Where runner `name` writes its heartbeat in `dataDir`. */
64
82
  export declare const heartbeatFile: (dataDir: string, name: string) => string;
65
83
  /** Whether runner `name`'s heartbeat in `dataDir` is fresh: younger than twice the renew interval. */
@@ -76,21 +94,55 @@ export declare function checkRunner(options: {
76
94
  /** Opens the store as a runner and starts claiming runs. */
77
95
  export declare function startRunnerProcess(options: RunnerProcessOptions): Promise<RunnerProcess>;
78
96
  /** Marks `make` as a function of the store (startRunnerProcess gives it the store it opens). */
79
- export declare function ofStore(make: (store: Store, sealKey: Buffer) => LoopFactory): (store: Store, sealKey: Buffer) => LoopFactory;
80
- /** The runner process's arguments: `--data D [--loops N] [--name N]`, or `--check --data D [--name N]`. Each option with
81
- * a value is also taken as `--option=value` (the bin hands a data directory that starts with "-" so, never read as an
82
- * option); an empty one is refused like a missing one. */
97
+ export declare function ofStore<Made extends LoopFactory | RunnerParts>(make: (store: Store, sealKey: Buffer) => Made): (store: Store, sealKey: Buffer) => Made;
98
+ /** How long a runner process lets each busy run finish its turn on SIGTERM, unless --drain-timeout or
99
+ * AGENTRUN_DRAIN_TIMEOUT says: the image's server drain (its CMD's --drain-timeout 6s), so a runner beside a --no-runner
100
+ * server drains as the server's own runner would.
101
+ * BOUND: this drain plus the stuck-loop stop after it (runner.ts runnerCloseBoundMs: the claim's lease less its margin,
102
+ * 30 s - 5 s = 25 s) is 6 + 25 = 31 s, inside deploy/compose.yaml's 35 s stop_grace_period for its runners
103
+ * (runner-beside-flags.test.mjs pins it). Raise this default only with that grace. */
104
+ export declare const RUNNER_DRAIN_TIMEOUT = "6s";
105
+ /** The environment's drain for a runner process when --drain-timeout gives none. */
106
+ export declare const RUNNER_DRAIN_ENV = "AGENTRUN_DRAIN_TIMEOUT";
107
+ /** What a runner process holds, from its arguments and `env`: --loops, else the server's --max-runs default
108
+ * (AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds; maxRunsOf); --drain-timeout, else
109
+ * AGENTRUN_DRAIN_TIMEOUT, else RUNNER_DRAIN_TIMEOUT. A bad AGENTRUN_MAX_RUNS or AGENTRUN_DRAIN_TIMEOUT is RunnerRefused. */
110
+ export declare function runnerHolds(args: {
111
+ loops?: number;
112
+ drainMs?: number;
113
+ }, env: NodeJS.ProcessEnv): {
114
+ loops: number;
115
+ drainMs: number;
116
+ };
117
+ /** The runner process's arguments: `--data D [--loops N] [--drain-timeout D] [--name N] [--faux M]`, or `--check --data D
118
+ * [--name N]`. Each option with a value is also taken as `--option=value` (the bin hands a data directory that starts
119
+ * with "-" so, never read as an option); an empty one is refused like a missing one. `--faux`: the faux model module, a
120
+ * test switch, as the server's own --faux; the only way a runner loads one. */
83
121
  export declare function runnerArgs(argv: readonly string[]): {
84
122
  dataDir: string;
85
123
  loops?: number;
124
+ drainMs?: number;
86
125
  name?: string;
126
+ faux?: string;
87
127
  check?: true;
88
128
  };
89
129
  /** Runs until SIGTERM or SIGINT, then closes. `ready` is called once the signals are handled, never before: a line that
90
130
  * says the runner is ready (on a pipe, written at once) may bring a SIGTERM back before the next statement runs, and one
91
131
  * that came before the handlers would end the process unclosed. */
92
132
  export declare function runUntilSignalled(process: RunnerProcess, signals?: readonly NodeJS.Signals[], ready?: () => void): Promise<void>;
133
+ /** The runner process's last resort (runnerMain installs it for unhandledRejection and uncaughtException): says what
134
+ * went wrong, in the runner's name with its stack, then exits 1 at once, closing nothing. A runner that went on after
135
+ * an error nothing handled could keep renewing the claim of a run whose loop is dead, and that run would hang claimed
136
+ * by a live runner. Exiting lets the claim lapse: another runner (or this one, started again) takes the run back at the
137
+ * next epoch, and the fence refuses the dead loop's late writes. The line is written to stderr synchronously
138
+ * (writeSync), so a pipe's slow reader still gets the whole stack before the exit. Exported for its test. */
139
+ export declare function lastResort(name: string, write?: (line: string) => void, exit?: (code: number) => void): (reason: unknown) => void;
93
140
  /** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
94
141
  * set up yet); 1: anything else; 0: closed on a signal, or --check found a fresh heartbeat. AGENTRUN_RUNNER_NAME names
95
142
  * it when --name does not. */
96
- export declare function runnerMain(argv: readonly string[], env?: NodeJS.ProcessEnv): Promise<number>;
143
+ export declare function runnerMain(argv: readonly string[], given?: NodeJS.ProcessEnv, hooks?: RunnerMainHooks): Promise<number>;
144
+ /** A test's hooks into runnerMain: `started`, awaited once the runner has started claiming and before its stop handlers
145
+ * take over from the ones its start listened on (the window a stop must not fall through). */
146
+ export type RunnerMainHooks = {
147
+ readonly started?: (process: RunnerProcess) => void | Promise<void>;
148
+ };