@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
@@ -17,7 +17,11 @@ export interface KeptProposal {
17
17
  readonly status: string;
18
18
  readonly detail?: string;
19
19
  }>>;
20
+ /** The skill of each draft's name as the folder held it at the seed, which the grader is shown beside the draft. */
21
+ readonly drafted?: readonly NoteText[];
20
22
  readonly asked?: readonly string[];
23
+ /** Why each draft waits for its owner's OK whatever the grade (the learning end's: skills.ts unpricedCalls). */
24
+ readonly held?: Readonly<Record<string, readonly string[]>>;
21
25
  readonly triggered?: readonly {
22
26
  readonly source: string;
23
27
  readonly text: string;
@@ -31,6 +35,12 @@ export interface GradeMain {
31
35
  readonly active: readonly IndexEntry[];
32
36
  readonly superseded: readonly NoteText[];
33
37
  readonly graded: Readonly<Record<string, string>>;
38
+ /** The proposal's notes named like a note main holds, left out of the grade and settled alone (learn/commit.ts
39
+ * readMain): `same` when main's note says its rule, else `taken`. */
40
+ readonly taken?: readonly {
41
+ readonly path: string;
42
+ readonly reason: "same" | "taken";
43
+ }[];
34
44
  }
35
45
  export type Problem = {
36
46
  readonly rule: string;
@@ -50,12 +60,24 @@ export interface MergeChange {
50
60
  readonly graded: Readonly<Record<string, string>>;
51
61
  /** The run's seed: a skill's or a draft's file not on main as it was on it is a conflict, never written over. */
52
62
  readonly seed?: string;
63
+ /** New notes written over main's note of the same name, each superseding it by name (takenOnMain). */
64
+ readonly replace?: readonly string[];
65
+ /** Each skill re-filed as a note, retired on main in the same write (its SKILL.md, and the note that replaces it). */
66
+ readonly retire?: readonly {
67
+ readonly skill: string;
68
+ readonly note: string;
69
+ }[];
53
70
  }
54
71
  export type LearningCommitResult = {
55
72
  readonly ok: true;
56
73
  readonly main: string;
57
74
  readonly commit: string;
58
75
  readonly files: readonly string[];
76
+ readonly left?: readonly {
77
+ readonly path: string;
78
+ readonly reason: "same" | "taken";
79
+ }[];
80
+ readonly already?: true;
59
81
  } | {
60
82
  readonly ok: false;
61
83
  readonly reason: "conflict" | "refused";
@@ -102,6 +124,15 @@ export interface LearningLoopDeps {
102
124
  }>;
103
125
  /** The folder's one write. */
104
126
  commit(ws: unknown, change: MergeChange): Promise<LearningCommitResult>;
127
+ /** The texts main holds at these note paths (learn/commit.ts mainTexts): a note the merge keeps whose name main
128
+ * already holds is settled alone (takenOnMain). */
129
+ mainTexts(ws: unknown, paths: readonly string[]): Promise<Readonly<Record<string, string>>>;
130
+ /** Run `runId`'s merge, when it is on main already (learn/folder.ts readRunDiff: its diff file, named by the run as its
131
+ * commit's Run-Id trailer names it; a resume after its commit, before its end was recorded): the texts its own commit
132
+ * holds at these note paths, as that merge saved them, whatever main says of them since. Undefined when it is not. */
133
+ merged(ws: unknown, runId: string, paths: readonly string[]): Promise<{
134
+ readonly texts: Readonly<Record<string, string>>;
135
+ } | undefined>;
105
136
  /** The clock (epoch ms), for a parked run's wake. */
106
137
  now?(): number;
107
138
  }
@@ -123,14 +154,33 @@ export type DroppedData = {
123
154
  readonly usd?: number | null;
124
155
  readonly tokens?: Tokens | null;
125
156
  };
157
+ /** `verdict`: each item's final decision once the merge settled it (takenOnMain's and the commit's left-out notes dropped,
158
+ * with their words), which the run's learning end reads in place of the grade's (store-reads/learning.ts). */
126
159
  export type MergedData = {
127
160
  readonly source: string;
128
161
  readonly main: string;
129
162
  readonly commit: string;
130
163
  readonly files: readonly string[];
131
164
  readonly detail: string;
165
+ readonly verdict: Verdict;
132
166
  };
133
- /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds. */
167
+ /** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
168
+ * and the rest of what the run learned merges. */
169
+ export declare const NOTE_NAME_TAKEN: (name: string) => string;
170
+ /** The why of a skill re-filed as a note whose file this run's own kept note (or another re-filed skill) takes: the run's
171
+ * own stands, and the skill is not written over it. */
172
+ export declare const NOTE_NAME_IN_RUN: (name: string) => string;
173
+ export declare function takenOnMain(proposal: Pick<KeptProposal, "notes">, verdict: Verdict, onMain: Readonly<Record<string, string>>): {
174
+ verdict: Verdict;
175
+ replace: string[];
176
+ graded: Record<string, string>;
177
+ };
178
+ /** `verdict` with one item per file a kept note is written as, within the run: the files the run's own kept notes are,
179
+ * then each re-filed skill's as it is kept; a re-filed skill whose note file one of those takes is left out, saying so
180
+ * (NOTE_NAME_IN_RUN). The merge (takenOnMain) and its resume (resumedOf, from the saved grade) settle it the one way. */
181
+ export declare function oneItemAFile(proposal: Pick<KeptProposal, "notes">, verdict: Verdict): Verdict;
182
+ /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds; a skill its
183
+ * item re-filed (`note`: a standing rule for every reply) is kept as that note instead, never as a skill. */
134
184
  export declare function keptOf(proposal: KeptProposal, verdict: Verdict): KeptProposal;
135
185
  /** The merge of `merging` (what the verdict kept), the one rule learningCommit's merge is made by: each note with
136
186
  * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
@@ -150,6 +200,30 @@ export declare function learnedOf(merging: KeptProposal, verdict: Verdict): {
150
200
  skills: LearnedFile[];
151
201
  workflows: LearnedFile[];
152
202
  };
203
+ /** `merging` and `verdict` once the merge left out `left` (learn/commit.ts LeftNote): each note it left out is no longer
204
+ * merged, and its item is dropped, unsaid when its rule is held already (SAME_NOTE), else saying its name is taken. */
205
+ export declare function leftOf(merging: KeptProposal, verdict: Verdict, left: readonly {
206
+ readonly path: string;
207
+ readonly reason: "same" | "taken";
208
+ }[]): {
209
+ merging: KeptProposal;
210
+ verdict: Verdict;
211
+ };
212
+ /** What a merge already on main settled (learn/commit.ts: its files, and `left`, the new notes it did not write): each
213
+ * note the grade kept is kept when the merge wrote it, its path changed and main holding its rule there now (`onMain`,
214
+ * the texts main holds at the kept notes' paths), else left out, saying why as takenOnMain said it (`taken`, its
215
+ * verdict after main was read), or by main's text there (the same rule, or a name it holds with another), else as the
216
+ * commit does. Skills and drafts as the grade kept them. */
217
+ export declare function resumedOf(proposal: KeptProposal, graded: Verdict, taken: Verdict, result: {
218
+ readonly files: readonly string[];
219
+ readonly left?: readonly {
220
+ readonly path: string;
221
+ readonly reason: "same" | "taken";
222
+ }[];
223
+ }, onMain: Readonly<Record<string, string>>): {
224
+ merging: KeptProposal;
225
+ verdict: Verdict;
226
+ };
153
227
  /** The skills and drafts a proposal names, by their item's file: what a merge the grader refused loses (notKept). */
154
228
  export declare const lostOf: (proposal: KeptProposal) => LearnedFile[];
155
229
  export declare function createLearningLoop(learning: LearningLoopDeps): (deps: LoopDeps) => Loop;
@@ -14,9 +14,10 @@
14
14
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
15
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
16
  import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
17
- import { mergedNote, parseNoteFile } from "../learn/notes.js";
17
+ import { mergedNote, parseNoteFile, ruleOf } from "../learn/notes.js";
18
18
  import { learnedPlace } from "../learn/skills.js";
19
- import { notKept, said, STOPPED } from "../learning-words.js";
19
+ import { blobOid } from "../learn/folder.js";
20
+ import { notKept, SAME_NOTE, said, STOPPED } from "../learning-words.js";
20
21
  import { journalEntries } from "./journal-reader.js";
21
22
  import { KINDS } from "./journal-kinds.js";
22
23
  /** The grader's bounds, as the server's grade had them (grade.ts): one ask, its answer cut at GRADE_MAX_TOKENS. */
@@ -32,28 +33,117 @@ const itemOf = (file) => {
32
33
  const place = learnedPlace(file);
33
34
  return place?.kind === "readme" ? `workflows/${place.name}/workflow.json` : file;
34
35
  };
35
- /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds. */
36
+ /** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
37
+ * and the rest of what the run learned merges. */
38
+ export const NOTE_NAME_TAKEN = (name) => `A note named ${name} was added since this run started, or was there already; this one wasn't kept.`;
39
+ /** The why of a skill re-filed as a note whose file this run's own kept note (or another re-filed skill) takes: the run's
40
+ * own stands, and the skill is not written over it. */
41
+ export const NOTE_NAME_IN_RUN = (name) => `This run also kept a note named ${name}, so the rule was not re-filed over it.`;
42
+ /** What `verdict` merges once each note it keeps (a new note's, or a skill's re-filed as one: its item's `note`) is set
43
+ * beside the run's other kept notes and what main holds at that file (`onMain`, by path), one item at a time, never a
44
+ * refusal of the whole merge. One file is one item's: a skill re-filed as a note whose file the run's own kept note
45
+ * (or an earlier re-filed skill) takes is dropped, saying so (NOTE_NAME_IN_RUN), so one text is written and the item
46
+ * that holds it is the one whose hold it keeps. Against main: a note main holds the same is no change, dropped unsaid
47
+ * (SAME_NOTE); one whose own front matter supersedes the note of its name is a modification, written over it
48
+ * (`replace`, main's blob in `graded`, so a change since is a conflict); any other is dropped, saying so
49
+ * (NOTE_NAME_TAKEN), and main's note stands. No suffixed name: it would hold the same rule twice. A rule another note
50
+ * holds is the merge's own to settle, against the main it commits on (learn/commit.ts mergeOf). Merge when the grader
51
+ * said so and it still keeps an item. */
52
+ /** Whether `held`, the note main holds at `file`, says the same rule as `text`: their bodies, whitespace and case aside
53
+ * (notes.ts ruleOf), as readMain and the merge's own settle (learn/commit.ts) read it, whatever their front matter. A
54
+ * text that is no note is the same only when it is the same text. */
55
+ /** The rule a re-filed note says (notes.ts ruleOf), "" when its text is no note: what the merge checks main still holds
56
+ * before it retires the skill that note replaces. */
57
+ const ruleOfText = (file, text) => {
58
+ const note = parseNoteFile(file, text);
59
+ return Array.isArray(note) ? "" : ruleOf(note.body);
60
+ };
61
+ const sameRule = (file, held, text) => {
62
+ const [theirs, ours] = [parseNoteFile(file, held), parseNoteFile(file, text)];
63
+ return !Array.isArray(theirs) && !Array.isArray(ours) ? ruleOf(theirs.body) === ruleOf(ours.body) : held === text;
64
+ };
65
+ export function takenOnMain(proposal, verdict, onMain) {
66
+ const texts = new Map(proposal.notes.map(({ file, text }) => [file, text]));
67
+ const replace = [];
68
+ const graded = {};
69
+ const items = oneItemAFile(proposal, verdict).items.map((item) => {
70
+ const note = item.note ?? (texts.has(item.file) ? { file: item.file, text: texts.get(item.file) } : undefined);
71
+ const held = item.keep && note ? onMain[note.file] : undefined;
72
+ if (!note || held === undefined)
73
+ return item;
74
+ const identical = held === note.text || held === mergedNote(note.text, { origin: item.origin ?? "run", ...(item.pending ? { pending: true } : {}) });
75
+ const parsed = parseNoteFile(note.file, note.text);
76
+ // One that supersedes the note of its own name and is not the very text main holds: a modification, written over it.
77
+ if (!identical && !item.note && !Array.isArray(parsed) && parsed.supersedes.includes(note.file)) {
78
+ replace.push(note.file);
79
+ graded[note.file] = blobOid(held);
80
+ return item;
81
+ }
82
+ // Else the same rule an active note of main keeps (whatever its front matter, case or spacing) is no change, dropped
83
+ // unsaid, and a skill re-filed as it retired (mergeChangeOf); a retired or superseded note of that rule keeps it out
84
+ // of every run, so it is a name main holds, and nothing is retired: the rule never vanishes. Any other is a name main
85
+ // holds with another rule.
86
+ const theirs = parseNoteFile(note.file, held);
87
+ const same = !Array.isArray(theirs) && theirs.status === "active" && (identical || sameRule(note.file, held, note.text));
88
+ return { file: item.file, keep: false, question: "Duplicate", why: same ? SAME_NOTE : NOTE_NAME_TAKEN(note.file.replace(/\.md$/, "")), ...(item.note ? { note: item.note } : {}) };
89
+ });
90
+ return { verdict: { ...verdict, items, merge: verdict.merge && items.some((item) => item.keep) }, replace, graded };
91
+ }
92
+ /** `verdict` with one item per file a kept note is written as, within the run: the files the run's own kept notes are,
93
+ * then each re-filed skill's as it is kept; a re-filed skill whose note file one of those takes is left out, saying so
94
+ * (NOTE_NAME_IN_RUN). The merge (takenOnMain) and its resume (resumedOf, from the saved grade) settle it the one way. */
95
+ export function oneItemAFile(proposal, verdict) {
96
+ const own = new Set(proposal.notes.map(({ file }) => file));
97
+ const claimed = new Set(verdict.items.filter((item) => item.keep && !item.note && own.has(item.file)).map((item) => item.file));
98
+ const items = verdict.items.map((item) => {
99
+ if (!item.keep || !item.note)
100
+ return item;
101
+ if (claimed.has(item.note.file))
102
+ return { file: item.file, keep: false, question: "Duplicate", why: NOTE_NAME_IN_RUN(item.note.file.replace(/\.md$/, "")) };
103
+ claimed.add(item.note.file);
104
+ return item;
105
+ });
106
+ return { ...verdict, items, merge: verdict.merge && items.some((item) => item.keep) };
107
+ }
108
+ /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds; a skill its
109
+ * item re-filed (`note`: a standing rule for every reply) is kept as that note instead, never as a skill. */
36
110
  export function keptOf(proposal, verdict) {
37
111
  if (!verdict.items.length)
38
112
  return proposal;
39
- const kept = new Set(verdict.items.filter((item) => item.keep).map((item) => item.file));
40
- return { ...proposal, notes: proposal.notes.filter(({ file }) => kept.has(file)), files: (proposal.files ?? []).filter(({ file }) => kept.has(itemOf(file))) };
113
+ const kept = new Set(verdict.items.filter((item) => item.keep && !item.note).map((item) => item.file));
114
+ const refiled = verdict.items.flatMap((item) => (item.keep && item.note ? [item.note] : []));
115
+ return { ...proposal, notes: [...proposal.notes.filter(({ file }) => kept.has(file)), ...refiled], files: (proposal.files ?? []).filter(({ file }) => kept.has(itemOf(file))) };
41
116
  }
117
+ /** Each item the verdict keeps by the file it is merged as: a re-filed skill's item by its note's file too. A dropped
118
+ * item names no file it merges as; of two kept items for one file (takenOnMain lets none through), the held one stands,
119
+ * so a hold is never lost to the order of the items. */
120
+ const itemsByFile = (verdict) => {
121
+ const byFile = new Map();
122
+ for (const item of verdict.items.filter((one) => one.keep)) {
123
+ for (const file of [item.file, ...(item.note ? [item.note.file] : [])])
124
+ if (!byFile.get(file)?.pending)
125
+ byFile.set(file, item);
126
+ }
127
+ return byFile;
128
+ };
42
129
  /** The merge of `merging` (what the verdict kept), the one rule learningCommit's merge is made by: each note with
43
130
  * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
44
131
  * is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
45
132
  * README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict. */
46
133
  export function mergeChangeOf(runId, merging, verdict, graded) {
47
- const judged = new Map(verdict.items.map((item) => [item.file, item]));
134
+ const judged = itemsByFile(verdict);
48
135
  const notes = merging.notes.map(({ file, text }) => ({ path: file, text: mergedNote(text, { origin: judged.get(file)?.origin ?? "run" }) }));
49
136
  const files = (merging.files ?? []).map(({ file, text }) => ({ path: file, text }));
50
137
  const held = [
51
138
  ...merging.notes.filter(({ file }) => judged.get(file)?.pending === true).map(({ file }) => file),
52
139
  ...files.filter(({ path }) => learnedPlace(path)?.kind !== "workflow" && judged.get(itemOf(path))?.pending === true).map(({ path }) => path),
53
140
  ];
141
+ // Each skill re-filed as a note is retired on main in the same write (learn/commit.ts mergeOf): a kept one, and one
142
+ // main already holds the same rule of as a note (dropped unsaid), so no old skill stays served beside its note.
143
+ const retire = verdict.items.flatMap((item) => (item.note && (item.keep || item.why === SAME_NOTE) && learnedPlace(item.file)?.kind === "skill" ? [{ skill: item.file, note: item.note.file, rule: ruleOfText(item.note.file, item.note.text) }] : []));
54
144
  return {
55
145
  kind: "merge", runId, reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
56
- ...(held.length ? { held } : {}), graded, ...(merging.seed ? { seed: merging.seed } : {}),
146
+ ...(held.length ? { held } : {}), graded, ...(merging.seed ? { seed: merging.seed } : {}), ...(retire.length ? { retire } : {}),
57
147
  };
58
148
  }
59
149
  /** What a merge of `merging` learned, as the server's grade named it on the run (learning-run.ts grade): the notes it
@@ -61,7 +151,7 @@ export function mergeChangeOf(runId, merging, verdict, graded) {
61
151
  * drafts, each pending when it waits. The merge's words and the reader of a run's learning end (store-reads/learning.ts)
62
152
  * both name it so. */
63
153
  export function learnedOf(merging, verdict) {
64
- const waiting = new Set(verdict.items.filter((item) => item.pending).map((item) => item.file));
154
+ const waiting = new Set(verdict.items.filter((item) => item.pending).flatMap((item) => [item.file, ...(item.note ? [item.note.file] : [])]));
65
155
  const notes = merging.notes.flatMap(({ file, text }) => {
66
156
  const note = parseNoteFile(file, text);
67
157
  return Array.isArray(note) ? [] : [{ file, name: note.name, supersedes: note.supersedes }];
@@ -78,9 +168,55 @@ export function learnedOf(merging, verdict) {
78
168
  * the checks left out (the kept row's `left`). */
79
169
  function mergedWords(merging, verdict, checked) {
80
170
  const { learned, pending, skills, workflows } = learnedOf(merging, verdict);
81
- const left = verdict.items.filter((item) => !item.keep).map((item) => ({ why: item.why }));
171
+ // A re-filed rule main already holds the same is no change: never said.
172
+ const left = verdict.items.filter((item) => !item.keep && item.why !== SAME_NOTE).map((item) => ({ why: item.why }));
82
173
  return said.merged(learned, pending, [...skills, ...workflows], left, checked);
83
174
  }
175
+ /** `merging` and `verdict` once the merge left out `left` (learn/commit.ts LeftNote): each note it left out is no longer
176
+ * merged, and its item is dropped, unsaid when its rule is held already (SAME_NOTE), else saying its name is taken. */
177
+ export function leftOf(merging, verdict, left) {
178
+ if (!left.length)
179
+ return { merging, verdict };
180
+ const why = new Map(left.map(({ path, reason }) => [path, reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(path.replace(/\.md$/, ""))]));
181
+ const items = verdict.items.map((item) => {
182
+ const file = item.note?.file ?? item.file;
183
+ return item.keep && why.has(file) ? { file: item.file, keep: false, question: "Duplicate", why: why.get(file), ...(item.note ? { note: item.note } : {}) } : item;
184
+ });
185
+ return { merging: { ...merging, notes: merging.notes.filter(({ file }) => !why.has(file)) }, verdict: { ...verdict, items } };
186
+ }
187
+ /** What a merge already on main settled (learn/commit.ts: its files, and `left`, the new notes it did not write): each
188
+ * note the grade kept is kept when the merge wrote it, its path changed and main holding its rule there now (`onMain`,
189
+ * the texts main holds at the kept notes' paths), else left out, saying why as takenOnMain said it (`taken`, its
190
+ * verdict after main was read), or by main's text there (the same rule, or a name it holds with another), else as the
191
+ * commit does. Skills and drafts as the grade kept them. */
192
+ export function resumedOf(proposal, graded, taken, result, onMain) {
193
+ const written = new Set(result.files);
194
+ const texts = new Map(proposal.notes.map(({ file, text }) => [file, text]));
195
+ const said = new Map((result.left ?? []).map(({ path, reason }) => [path, reason]));
196
+ const notes = new Set(proposal.notes.map(({ file }) => file));
197
+ // One item per file, as the first attempt's takenOnMain settled it: the saved grade keeps both a run's note and a skill
198
+ // re-filed as a note of its file, and only one of them was written.
199
+ const settled = oneItemAFile(proposal, graded);
200
+ const items = settled.items.map((item, i) => {
201
+ const file = item.note?.file ?? item.file;
202
+ if (!item.keep || !(item.note || notes.has(file)))
203
+ return item;
204
+ // Saved: the merge changed its path and main holds its rule there now (`onMain`, read after the merge). A path the
205
+ // merge changed for another reason (a note it marked superseded) holds another rule, and saves no item of its own.
206
+ const text = item.note?.text ?? texts.get(file);
207
+ const held = onMain[file];
208
+ if (written.has(file) && (held === undefined || text === undefined || sameRule(file, held, text)))
209
+ return item;
210
+ const before = taken.items[i];
211
+ if (before && !before.keep && before.why !== SAME_NOTE)
212
+ return before;
213
+ const same = held !== undefined && text !== undefined ? sameRule(file, held, text) : said.get(file) !== "taken";
214
+ const why = same ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, ""));
215
+ return { file: item.file, keep: false, question: "Duplicate", why, ...(item.note ? { note: item.note } : {}) };
216
+ });
217
+ const verdict = { ...settled, items };
218
+ return { merging: keptOf(proposal, verdict), verdict };
219
+ }
84
220
  /** The skills and drafts a proposal names, by their item's file: what a merge the grader refused loses (notKept). */
85
221
  export const lostOf = (proposal) => (proposal.files ?? []).flatMap(({ file }) => {
86
222
  const place = learnedPlace(file);
@@ -90,12 +226,17 @@ export function createLearningLoop(learning) {
90
226
  return (deps) => {
91
227
  let stopped = null;
92
228
  const now = learning.now ?? Date.now;
229
+ /** Aborted by a person's stop (a stop row): the grade's request is cut at once, never left running past it, while the
230
+ * claim's signal stays whole so the stopped end is still written. */
231
+ const stopAsk = new AbortController();
93
232
  return {
94
233
  async command(_command) {
95
234
  return { refused: "a learning run takes no messages or answers" };
96
235
  },
97
236
  async stop(reason) {
98
237
  stopped = reason;
238
+ if (reason.kind === "command")
239
+ stopAsk.abort(new Error("the run was stopped"));
99
240
  },
100
241
  async start(claim) {
101
242
  const context = withAbortSignal(deps.signal, BACKGROUND_CONTEXT);
@@ -167,10 +308,20 @@ export function createLearningLoop(learning) {
167
308
  await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: said.stale(main.problems), problems: main.problems }, "ended");
168
309
  return { state: "ended" };
169
310
  }
170
- const items = gradedItems(proposal.notes, (proposal.files ?? []));
311
+ // A note named like one main holds now is settled alone, out of the grade (readMain's `taken`); the rest is
312
+ // graded. Nothing left to grade keeps nothing.
313
+ const taken = new Map((main.taken ?? []).map(({ path, reason }) => [path, reason]));
314
+ const grading = proposal.notes.filter(({ file }) => !taken.has(file));
315
+ const settledItems = [...taken].map(([file, reason]) => ({ file, keep: false, question: "Duplicate", why: reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, "")) }));
316
+ if (!grading.length && !proposal.files?.length) {
317
+ const verdict = { merge: false, reason: "Every new note is named like one the agent holds now.", items: settledItems };
318
+ await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)) }, "ended");
319
+ return { state: "ended" };
320
+ }
321
+ const items = gradedItems(grading, (proposal.files ?? []));
171
322
  const prompt = gradePrompt({
172
- run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded: main.superseded, proposed: proposal.notes,
173
- ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}),
323
+ run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded: main.superseded, proposed: grading,
324
+ ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.drafted?.length ? { drafted: proposal.drafted } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}), ...(proposal.held ? { held: proposal.held } : {}),
174
325
  });
175
326
  // What the grade spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
176
327
  // added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
@@ -178,10 +329,13 @@ export function createLearningLoop(learning) {
178
329
  let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
179
330
  // `again`: what the grade is told after its last answer, below the same prompt.
180
331
  const ask = async (again) => {
332
+ // Stopped before this ask: nothing is sent, so nothing of it is spent (what it spent stays as it was).
333
+ if (stopAsk.signal.aborted)
334
+ throw stopAsk.signal.reason;
181
335
  const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
182
336
  let answer;
183
337
  try {
184
- answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
338
+ 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() });
185
339
  }
186
340
  catch (error) {
187
341
  usd = null;
@@ -195,15 +349,15 @@ export function createLearningLoop(learning) {
195
349
  };
196
350
  let verdict;
197
351
  try {
198
- verdict = parseVerdict(await ask(), items);
352
+ verdict = parseVerdict(await ask(), items, proposal.held);
199
353
  // An answer the host cannot read is asked once more, as the server's grade did.
200
354
  if (verdict.reason === UNREADABLE_REASON && !verdict.items.length)
201
- verdict = parseVerdict(await ask(), items);
355
+ verdict = parseVerdict(await ask(), items, proposal.held);
202
356
  // One that kept every item and said no merge contradicts itself: asked once more, the contradiction named. A
203
357
  // second contradiction stands as no merge, said in the host's words as twice (learning-words.ts notKept); a
204
358
  // contradiction after an unreadable answer is one, and is said so.
205
359
  else if (verdict.reason === CONTRADICTED_REASON) {
206
- const again = parseVerdict(await ask(CONTRADICTION_ASK), items);
360
+ const again = parseVerdict(await ask(CONTRADICTION_ASK), items, proposal.held);
207
361
  verdict = again.reason === CONTRADICTED_REASON ? { ...again, reason: CONTRADICTED_TWICE_REASON } : again;
208
362
  }
209
363
  }
@@ -217,6 +371,8 @@ export function createLearningLoop(learning) {
217
371
  void error;
218
372
  return { state: "ended" };
219
373
  }
374
+ if (settledItems.length)
375
+ verdict = { ...verdict, items: [...verdict.items, ...settledItems] };
220
376
  graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
221
377
  spend = usd;
222
378
  await append(KINDS.learningGraded, graded);
@@ -226,15 +382,52 @@ export function createLearningLoop(learning) {
226
382
  const halt = await halted();
227
383
  if (halt)
228
384
  return halt;
229
- if (!graded.verdict.merge) {
230
- await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(graded.verdict, lostOf(proposal)) }, "ended");
385
+ // Each note it keeps whose file main already holds (another run merged one by that name since, or a skill
386
+ // re-filed as one) is settled alone (takenOnMain): never written over unless it supersedes it, and never a
387
+ // refusal of everything else the run learned. Not when this run's own merge is on main already (the runner
388
+ // stopped after its commit, before it recorded it): the notes there are that merge's, never "already there", so
389
+ // the grade's verdict goes to the commit, which answers with that merge, and each item is settled by the text that
390
+ // merge's own commit holds at its file (resumedOf: its rule there, not only a changed path, and never main's
391
+ // text now, which a person may have edited since).
392
+ const notePaths = graded.verdict.items.flatMap((item) => (!item.keep ? [] : item.note ? [item.note.file] : proposal.notes.some(({ file }) => file === item.file) ? [item.file] : []));
393
+ let onMain = {};
394
+ let already = false;
395
+ try {
396
+ const merge = await learning.merged(ws, source.runId, notePaths);
397
+ already = merge !== undefined;
398
+ onMain = merge ? merge.texts : notePaths.length ? await learning.mainTexts(ws, notePaths) : {};
399
+ }
400
+ catch (error) {
401
+ // Main could not be read: parked as for a write that could not reach the folder, tried again after a backoff.
402
+ await append(KINDS.learningUnavailable, { source: source.runId, error: error?.message ?? String(error) }, "parked");
403
+ return { state: "parked", wakeAt: now() + UNAVAILABLE_BACKOFF_MS[Math.min(unavailable, UNAVAILABLE_BACKOFF_MS.length - 1)] };
404
+ }
405
+ const taken = already ? { verdict: oneItemAFile(proposal, graded.verdict), replace: [], graded: {} } : takenOnMain(proposal, graded.verdict, onMain);
406
+ const verdict = taken.verdict;
407
+ const merging = keptOf(proposal, verdict);
408
+ const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded });
409
+ // Nothing new left to merge: dropped, unless the grader kept a re-filed skill whose rule main already holds as a
410
+ // note (takenOnMain's SAME_NOTE). Its old SKILL.md is still retired (mergeChangeOf's retire), in a write of that
411
+ // alone, so no old skill stays served beside the note.
412
+ if (!verdict.merge && !(graded.verdict.merge && change.retire?.length)) {
413
+ await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)) }, "ended");
231
414
  return { state: "ended" };
232
415
  }
233
- const merging = keptOf(proposal, graded.verdict);
234
- const result = await learning.commit(ws, mergeChangeOf(source.runId, merging, graded.verdict, graded.graded));
416
+ const result = await learning.commit(ws, taken.replace.length ? { ...change, replace: taken.replace } : change);
235
417
  if (result.ok) {
236
- const detail = mergedWords(merging, graded.verdict, checked);
237
- await append(KINDS.learningMerged, { source: source.runId, main: result.main, commit: result.commit, files: result.files, detail }, "ended");
418
+ // What the merge left out against the main it committed on (a rule a note holds, a name one holds), each
419
+ // item alone: said as takenOnMain says it, and nothing of it learned.
420
+ // A merge already on main (a resume after its commit): what it wrote is what its files say, so each note is
421
+ // settled by the files: one written is kept as the grade kept it, one not written is left out (as takenOnMain
422
+ // or the commit says why).
423
+ const settled = result.already ? resumedOf(proposal, graded.verdict, verdict, result, onMain) : leftOf(merging, verdict, result.left ?? []);
424
+ if (!settled.verdict.items.some((item) => item.keep) && !result.files.length) {
425
+ await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(settled.verdict, lostOf(proposal)) }, "ended");
426
+ return { state: "ended" };
427
+ }
428
+ // A write that retired a skill alone learned nothing new: said so.
429
+ const detail = mergedWords(settled.merging, settled.verdict, checked) || said.empty;
430
+ await append(KINDS.learningMerged, { source: source.runId, main: result.main, commit: result.commit, files: result.files, detail, verdict: settled.verdict }, "ended");
238
431
  return { state: "ended" };
239
432
  }
240
433
  if (result.reason === "conflict") {
@@ -15,6 +15,8 @@ export interface LearningSeedLay {
15
15
  readonly shown: () => Promise<Shown>;
16
16
  /** One line of the run's log. */
17
17
  readonly log: (line: string) => void;
18
+ /** False for a run of a revision that says `learning: "notes"`: its notes and skills are laid, never a learned workflow. */
19
+ readonly workflows?: false;
18
20
  }
19
21
  /** What the claim laid of the run's seed: the seed it read, the learned skills' files it laid, by their paths under
20
22
  * `.agents/skills/`, for the skill list the run's harness is handed beside the revision's own, and the learned workflows
@@ -25,6 +27,12 @@ export type LaidSeed = {
25
27
  readonly skills: readonly string[];
26
28
  readonly workflows: readonly LearnedWorkflow[];
27
29
  };
30
+ /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
31
+ * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
32
+ export declare const laidOf: (laid: LaidSeed | undefined) => {
33
+ skills: string[];
34
+ workflows: string[];
35
+ };
28
36
  /** Lays the run's learning seed (see the file's head). Undefined when the seed could not be read: nothing was laid.
29
37
  * Never throws. */
30
38
  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) {
@@ -25,7 +31,7 @@ export async function layLearningSeed(lay) {
25
31
  lay.log(`its learning folder's ${path} was not read`);
26
32
  for (const name of left)
27
33
  lay.log(`starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
28
- const workflows = chooseWorkflows(seed, shown);
34
+ const workflows = lay.workflows === false ? { flows: [], left: [] } : chooseWorkflows(seed, shown);
29
35
  for (const name of workflows.left)
30
36
  lay.log(`starts without the learned workflow ${name} its agent learned: it is over what is left of the learned workflows' budget, or holds a secret`);
31
37
  return { seed, skills: taken.flatMap(({ name, files = {} }) => Object.keys(files).sort().map((path) => `${name}/${path}`)), workflows: workflows.flows };
@@ -87,6 +87,14 @@ export declare class ClaimRefused extends Error {
87
87
  }
88
88
  /** The end a person's stop or cancel writes: stopped, in words that say which. A cancel's are main's ("cancelled"). */
89
89
  export declare function endedBy(cancel: boolean | undefined): string;
90
+ /** The run's end on a person's stop or a cancel, as every loop and the runner write it: state 'stopped', words that say
91
+ * which (endedBy), and the outcome the store tells them apart by: 'stopped' (the turn is over, never the run, as main's
92
+ * stop leaves a run: a message reopens it) or 'cancelled' (over for good). */
93
+ export declare function stopEnd(cancel: boolean | undefined): {
94
+ readonly state: "stopped";
95
+ readonly summary: string;
96
+ readonly outcome: "stopped" | "cancelled";
97
+ };
90
98
  /** The refusal a denied call's model reads: serve's own words for a call a person denied (refusal-words.ts refusedText,
91
99
  * one copy with the tool gate's), the person's note with it. Asked before its intent, the call never ran. */
92
100
  export declare function deniedText(tool: string, note?: string): string;
@@ -128,6 +136,10 @@ export interface LoopDeps {
128
136
  * or at once when there were none: a resumed ask with no answer row waits for it before it parks again, so an
129
137
  * approve already on its way is never raced. Never rejects. */
130
138
  delivered?: Promise<void>;
139
+ /** Hands the run's command rows the runner has not handed on yet to command() now, not at its next poll (up to its
140
+ * command poll away), and resolves once each call returned: a turn that ends asks it before the run may end, so a
141
+ * message sent while the turn worked is answered, never refused by the run's end. Absent: nothing to hand on. */
142
+ deliverNow?: () => Promise<void>;
131
143
  /** Where the loop reports what its run shows before it is stored (a running tool, a partial answer), as it changes: a
132
144
  * reader of the newest held state (`undefined` once there is nothing held), called once per tick by the runner's live
133
145
  * ticker (runner/live-ticker.ts), never on every change, so a change costs the same however long the answer has grown.
@@ -14,6 +14,12 @@ export class ClaimRefused extends Error {
14
14
  export function endedBy(cancel) {
15
15
  return cancel ? "cancelled" : "stopped by a person";
16
16
  }
17
+ /** The run's end on a person's stop or a cancel, as every loop and the runner write it: state 'stopped', words that say
18
+ * which (endedBy), and the outcome the store tells them apart by: 'stopped' (the turn is over, never the run, as main's
19
+ * stop leaves a run: a message reopens it) or 'cancelled' (over for good). */
20
+ export function stopEnd(cancel) {
21
+ return { state: "stopped", summary: endedBy(cancel), outcome: cancel ? "cancelled" : "stopped" };
22
+ }
17
23
  /** The refusal a denied call's model reads: serve's own words for a call a person denied (refusal-words.ts refusedText,
18
24
  * one copy with the tool gate's), the person's note with it. Asked before its intent, the call never ran. */
19
25
  export function deniedText(tool, note) {
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
- import type { ConversationId, EntryRecord, StorageWrite } from "@earendil-works/pi-durable";
2
+ import { type ConversationId, type EntryRecord, type StorageWrite } from "@earendil-works/pi-durable";
3
3
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
4
4
  import { type Command, type HeldState, type Journal, type LoopDeps } from "./loop-contract.js";
5
5
  import type { Staged } from "../store/store.js";
@@ -75,5 +75,9 @@ export declare function cutLast(entries: readonly EntryRecord[]): string | undef
75
75
  export declare function restartLimited(entries: readonly EntryRecord[]): string | undefined;
76
76
  /** The root conversation's entries, oldest first. */
77
77
  export declare function entriesOf(journal: Journal, conversationId: ConversationId, context: Context): Promise<EntryRecord[]>;
78
+ /** The entries of the run's agent conversations, in log order: its root's and each one a task of the run owns (a
79
+ * subagent's: runner/subagent.ts), never the loop's own session records. What a run's end reads its metrics and cost
80
+ * from, so a child's requests count as the run's. */
81
+ export declare function agentEntriesOf(journal: Journal, context: Context): Promise<EntryRecord[]>;
78
82
  export declare function findData<T>(entries: readonly EntryRecord[], kind: string, test: (data: T) => boolean): T | undefined;
79
83
  export {};
@@ -1,3 +1,4 @@
1
+ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
1
2
  import { KINDS } from "./journal-kinds.js";
2
3
  import { cutAtLimit } from "./loop-contract.js";
3
4
  import { PI_STOP } from "./pi-stop.js";
@@ -177,6 +178,25 @@ export async function entriesOf(journal, conversationId, context) {
177
178
  cursor = page.next;
178
179
  }
179
180
  }
181
+ /** The entries of the run's agent conversations, in log order: its root's and each one a task of the run owns (a
182
+ * subagent's: runner/subagent.ts), never the loop's own session records. What a run's end reads its metrics and cost
183
+ * from, so a child's requests count as the run's. */
184
+ export async function agentEntriesOf(journal, context) {
185
+ const ids = [];
186
+ for (let cursor = undefined;;) {
187
+ const page = await journal.scanConversations({ order: "ascending" }, 500, cursor, context);
188
+ for (const record of page.items)
189
+ if (Number(record.id) === Number(ROOT_CONVERSATION_ID) || record.owner !== undefined)
190
+ ids.push(record.id);
191
+ if (page.next === undefined)
192
+ break;
193
+ cursor = page.next;
194
+ }
195
+ const out = [];
196
+ for (const id of ids)
197
+ out.push(...(await entriesOf(journal, id, context)));
198
+ return out.sort((a, b) => Number(a.id) - Number(b.id));
199
+ }
180
200
  export function findData(entries, kind, test) {
181
201
  for (const entry of entries)
182
202
  if (entry.kind === kind && test(entry.data))