@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
@@ -4,7 +4,7 @@
4
4
  // here with its bytes; nothing the checker refuses is ever written to git. Every problem it reports is printable: its
5
5
  // path and detail are cut of the host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
6
6
  import { hiddenCharacter } from "./invisible.js";
7
- import { INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile } from "./notes.js";
7
+ import { INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile, ruleOf } from "./notes.js";
8
8
  import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
9
9
  import { draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedName, learnedPlace, setsStatus, skillProblems, WORKFLOWS_DIR } from "./skills.js";
10
10
  /** The most the host adds to a run's note as it merges it: `origin: you` and `status: pending`, a front matter line
@@ -34,6 +34,8 @@ export const CAPS = Object.freeze({
34
34
  workflows: 1,
35
35
  });
36
36
  const MODES = { "120000": "a link: never followed", "040000": "a folder: nothing in it was read" };
37
+ /** Why a draft from a run of a revision that learns notes alone (`learning: "notes"`) is left out. */
38
+ const NOTES_ONLY = "this agent learns notes and skills alone (learning: \"notes\"): it keeps no workflow draft";
37
39
  /** Why a run's path is none of what it may propose. */
38
40
  const OUTSIDE = "a run proposes notes at the folder's top, skills/<name>/SKILL.md, and workflows/<name>/ with its workflow.json and README.md";
39
41
  /** `problem` as it may be printed: its path and detail cut of `values` and of every shape learning refuses, a bank's
@@ -137,6 +139,8 @@ function learnedChecked(change, place, refused, input, add) {
137
139
  return add("file_name", place.kind === "skill" ? "a skill's name is lowercase letters, digits and single dashes, at most 64" : "a workflow's name is lowercase letters, digits, dashes and underscores, at most 64, starting with a letter or digit", path);
138
140
  if (change.status === "deleted")
139
141
  return add("deleted", "a run never deletes a skill or a workflow", path);
142
+ if (place.kind === "workflow" && input.workflows === false)
143
+ return add("workflow", NOTES_ONLY, path);
140
144
  if (change.mode !== undefined && change.mode !== "100644")
141
145
  return add("file_mode", MODES[change.mode] ?? "not a regular file: never read", path);
142
146
  const size = change.size ?? change.bytes?.length ?? 0;
@@ -153,7 +157,7 @@ function learnedChecked(change, place, refused, input, add) {
153
157
  if (place.kind === "workflow") {
154
158
  if (!input.dsl)
155
159
  throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
156
- const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy);
160
+ const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.ask);
157
161
  for (const { rule, detail } of problems)
158
162
  add(rule, detail, path);
159
163
  // A draft the checks pass whose dry run failed: its wiring breaks at run time, before any node is paid for.
@@ -224,7 +228,9 @@ export function checkProposal(input) {
224
228
  }
225
229
  const changes = given.slice(0, CAPS.changes);
226
230
  const base = new Set(input.base.files);
227
- const notes = [];
231
+ // The new notes that pass their own checks, in the answer's order. Which of them is a duplicate is settled after,
232
+ // with the merge's checks (settled below).
233
+ const candidates = [];
228
234
  const skills = [];
229
235
  const workflows = new Set();
230
236
  const added = [];
@@ -256,9 +262,9 @@ export function checkProposal(input) {
256
262
  const note = textChecked(path, change.size ?? change.bytes?.length ?? 0, change.bytes, refused, add, true);
257
263
  if (!note)
258
264
  return;
259
- if (note.keys.includes("status") || note.keys.includes("superseded_by") || note.keys.includes("origin"))
260
- return add("status", "a run never sets status, superseded_by or origin: the host does, when it merges the note or a later one supersedes it", path);
261
- notes.push(note);
265
+ if (["status", "superseded_by", "retired_from", "origin"].some((key) => note.keys.includes(key)))
266
+ return add("status", "a run never sets status, superseded_by, retired_from or origin: the host does, when it merges the note, a later one supersedes it or a person retires it", path);
267
+ candidates.push(note);
262
268
  };
263
269
  for (const change of changes)
264
270
  one(change);
@@ -280,9 +286,121 @@ export function checkProposal(input) {
280
286
  if (after.has(json) !== after.has(readme))
281
287
  add("workflow", `the folder holds ${after.has(json) ? "workflow.json" : "README.md"} without the other file`, after.has(json) ? readme : json);
282
288
  }
283
- if (!problems.length)
284
- problems.push(...mergeProblems(input.base, notes, values));
289
+ const notes = problems.length ? [] : settled(candidates);
285
290
  return { ok: problems.length === 0, problems, notes: problems.length ? [] : notes };
291
+ /** `candidates` once nothing else is wrong, settled in one order, so no note is ever lost to another's failure:
292
+ * 1. Each note alone against the base (ownProblems): what it supersedes, active there, and how many. One that fails
293
+ * is left out with its own reason.
294
+ * 2. The survivors by rule: the first of a rule holds it, the rest are its alternates. A rule the seed's active
295
+ * notes hold is held already (an alternate that supersedes its holder is an update, and holds it).
296
+ * 3. The holders' shared checks (sharedProblems): two notes superseding one note, the supersedes cap over the run,
297
+ * the index's lines, each counted in order, after the duplicates are out. A holder they refuse is left out with
298
+ * that reason, and its next alternate holds the rule in its place; then 3 again, until nothing changes (each
299
+ * round leaves one note out or more: bounded by the count).
300
+ * 4. Only then the alternates no rule needed are left out, each as the duplicate of its rule's holder.
301
+ * The notes that pass, in the answer's order. */
302
+ function settled(all) {
303
+ const survivors = all.filter((note) => {
304
+ const own = ownProblems(input.base, note);
305
+ for (const problem of own)
306
+ add(problem.rule, problem.detail, problem.path);
307
+ return own.length === 0;
308
+ });
309
+ const out = new Set();
310
+ for (;;) {
311
+ const { holders } = byRule(survivors.filter((note) => !out.has(note.file)));
312
+ const shared = sharedProblems(input.base, holders);
313
+ if (!shared.length) {
314
+ const { holders: kept, alternates } = byRule(survivors.filter((note) => !out.has(note.file)));
315
+ for (const [note, holder] of alternates)
316
+ add("duplicate", `it says what ${holder} says`, note.file);
317
+ return kept;
318
+ }
319
+ for (const problem of shared) {
320
+ add(problem.rule, problem.detail, problem.path);
321
+ out.add(problem.path);
322
+ }
323
+ }
324
+ }
325
+ /** `notes` by rule, in order: the first of a rule holds it, the rest are its alternates (each with its holder). A
326
+ * rule the seed's active notes hold is held by that note, unless the new note supersedes it (an update), or any of
327
+ * `notes` does: a note this proposal supersedes keeps no rule after it, so a copy of its rule under another name is
328
+ * no duplicate, and the rule is never left with no active note. */
329
+ function byRule(notes) {
330
+ const going = new Set(notes.flatMap((note) => note.supersedes));
331
+ const rules = new Map([...(input.base.rules ?? [])].filter(([, holder]) => !going.has(holder)));
332
+ const holders = [];
333
+ const alternates = [];
334
+ for (const note of notes) {
335
+ const rule = ruleOf(note.body);
336
+ const holder = rules.get(rule);
337
+ if (holder !== undefined && !note.supersedes.includes(holder)) {
338
+ // An update of the holder the seed has, after a copy of its rule: the update holds the rule, the copy is its
339
+ // alternate (else the update is dropped as the copy's duplicate, and the copy as the seed's, on the next pass).
340
+ const original = input.base.rules?.get(rule);
341
+ const at = holders.findIndex((one) => one.file === holder);
342
+ if (original !== undefined && holder !== original && at >= 0 && note.supersedes.includes(original)) {
343
+ // At its own place in the answer (the end of the holders so far), not the copy's: the shared checks name notes
344
+ // in answer order, so an update must not jump ahead of a note between the two.
345
+ alternates.push([holders.splice(at, 1)[0], note.file]);
346
+ holders.push(note);
347
+ rules.set(rule, note.file);
348
+ continue;
349
+ }
350
+ alternates.push([note, holder]);
351
+ continue;
352
+ }
353
+ rules.set(rule, note.file);
354
+ holders.push(note);
355
+ }
356
+ return { holders, alternates };
357
+ }
358
+ }
359
+ /** What `note` alone cannot join `base` with, needing no other note: a `supersedes` that names no active note of `base`,
360
+ * or more of them than CAPS.supersedes. */
361
+ function ownProblems(base, note) {
362
+ const active = new Set(base.active.map((one) => one.file));
363
+ const out = note.supersedes.filter((old) => !active.has(old)).map((old) => ({ rule: "supersedes", path: note.file, detail: `it supersedes ${old}, which is not an active note` }));
364
+ if (note.supersedes.length > CAPS.supersedes)
365
+ out.push({ rule: "supersedes", path: note.file, detail: `it supersedes ${note.supersedes.length} notes; the cap is ${CAPS.supersedes} a run` });
366
+ return out;
367
+ }
368
+ /** What stops the holders `notes` (one a rule, each passing ownProblems) from joining `base` together, each named by the
369
+ * note it falls on. In the answer's order: a note that supersedes one an earlier note supersedes, or that takes the
370
+ * notes superseded past CAPS.supersedes (a note named counts toward neither, so a later one that fits is kept). Then
371
+ * the index over the rest, whole (each active new note a line, each note it supersedes one fewer), so a note that frees
372
+ * lines counts wherever it stands: past INDEX_LINES, the notes that add lines are named from the answer's end until
373
+ * it fits. */
374
+ function sharedProblems(base, notes) {
375
+ const out = [];
376
+ const replaced = new Set();
377
+ const fits = [];
378
+ for (const note of notes) {
379
+ const twice = note.supersedes.find((old) => replaced.has(old));
380
+ if (twice) {
381
+ out.push({ rule: "supersedes", path: note.file, detail: `${twice} is superseded by another new note too` });
382
+ continue;
383
+ }
384
+ const would = new Set([...replaced, ...note.supersedes]);
385
+ if (would.size > CAPS.supersedes) {
386
+ out.push({ rule: "supersedes", path: note.file, detail: `with it the new notes supersede ${would.size} notes; the cap is ${CAPS.supersedes} a run` });
387
+ continue;
388
+ }
389
+ for (const old of note.supersedes)
390
+ replaced.add(old);
391
+ fits.push(note);
392
+ }
393
+ const net = (note) => (note.status === "active" ? 1 : 0) - note.supersedes.length;
394
+ let lines = base.active.length + fits.reduce((sum, note) => sum + net(note), 0);
395
+ for (const note of [...fits].reverse()) {
396
+ if (lines <= INDEX_LINES)
397
+ break;
398
+ if (net(note) <= 0)
399
+ continue;
400
+ out.push({ rule: "index_full", path: note.file, detail: `with it the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so supersede a note rather than add one` });
401
+ lines -= net(note);
402
+ }
403
+ return out;
286
404
  }
287
405
  /** The notes the active ones of `notes` supersede, each by the note that supersedes it. A note that waits for its
288
406
  * owner's OK (`status: pending`) supersedes nothing until it is approved: what it names stays active. The one rule the
@@ -26,6 +26,19 @@ export type LearningChange = {
26
26
  * it (a person retired or approved it, another run's merge changed it) is a conflict, never written over. The
27
27
  * script checks it on main as it commits. Optional, past COMMIT-API.md v1. */
28
28
  seed?: string;
29
+ /** New notes written over the note main holds by the same name: each one the run's note supersedes by its own
30
+ * name (the learning loop's takenOnMain), its blob on main in `graded`, so a change since is a conflict. Any
31
+ * other new note main holds a note by when the merge commits is left out alone (`left`, `taken`). */
32
+ replace?: string[];
33
+ /** Skills re-filed as notes (grade.ts skillAsNote): each skill's SKILL.md main holds is retired in this write, so
34
+ * no old skill stays served beside the note that replaces it; not when `note` was left out as `taken` (another
35
+ * note holds that name, so the skill's rule would be lost). Its file is checked against the run's seed as a
36
+ * skill's file the merge writes is. */
37
+ retire?: {
38
+ skill: string;
39
+ note: string;
40
+ rule: string;
41
+ }[];
29
42
  } | {
30
43
  kind: "person";
31
44
  action: "edited" | "created" | "retired" | "approved" | "restored";
@@ -43,11 +56,20 @@ export type LearningChange = {
43
56
  /** Approved-Via: console. */
44
57
  via?: "console";
45
58
  };
59
+ /** A new note a merge left out, settled against the main it commits on: `same`, a rule main's active notes (or an
60
+ * earlier note of the merge) already hold, or main's note by that name says it (no change); `taken`, main holds a note
61
+ * by that name with another rule, never written over. */
62
+ export type LeftNote = {
63
+ path: string;
64
+ reason: "same" | "taken";
65
+ };
46
66
  export type LearningCommitResult = {
47
67
  ok: true;
48
68
  main: string;
49
69
  commit: string;
50
70
  files: string[];
71
+ left?: LeftNote[];
72
+ already?: true;
51
73
  } | {
52
74
  ok: false;
53
75
  reason: "conflict";
@@ -64,23 +86,35 @@ export type LearningCommitResult = {
64
86
  /**
65
87
  * One write on the folder's main, one exec of the learning script: a run's merge or a person's write, as `change` says.
66
88
  * `ok` with the new main (its commit) and the paths the commit changed; `conflict` when an oid the caller read is
67
- * another blob on main now; `refused` when the folder as it would be is refused (a name main holds already, the index
68
- * past its lines, a note out of shape); `unavailable` when the workspace or the exec failed (retry later). A merge whose
89
+ * another blob on main now; `refused` when the folder as it would be is refused (the index past its lines, a note out
90
+ * of shape); a new note named like one main holds, or of a rule one holds, is left out alone (`left`); `unavailable` when the workspace or the exec failed (retry later). A merge whose
69
91
  * run already merged here is `ok` with the commit that holds it, and writes nothing.
70
92
  */
71
93
  export declare function learningCommit(ws: Workspace, change: LearningChange, opts?: {
72
94
  retries?: number;
73
95
  }): Promise<LearningCommitResult>;
74
- /** Main as the grader reads it (the runner's learning loop `readMain`): every active note's index
75
- * line, the whole text of each note the proposal supersedes, and the blob each of those was read at (`graded`, which
76
- * the merge checks); or `problems` when the proposal cannot join main as it is (learn/check.ts mergeProblems). From
77
- * the folder's snapshot and its bodies: no git, no exec. */
96
+ /** The texts main holds at `paths`, each a note's file, by path: one main holds no note at is not in it. From the
97
+ * folder's snapshot and its bodies: no git, no exec. What a skill the grader re-filed as a note (grade.ts skillAsNote)
98
+ * would be written over, read before its merge. */
99
+ export declare function mainTexts(ws: Workspace, paths: readonly string[]): Promise<Record<string, string>>;
100
+ /** Run `runId`'s merge on the folder, when its diff file names one (readRunDiff): the texts its own commit holds at
101
+ * `paths`, each a note's file (one it holds nothing at is not in it), read at that commit, those paths alone (textsAt:
102
+ * one read-only exec, bounded by the paths asked, never the whole folder or its log), never main's now, which a person
103
+ * may have edited since. Undefined when the run merged nothing here. */
104
+ export declare function mergedAt(ws: Workspace, runId: string, paths: readonly string[]): Promise<{
105
+ texts: Record<string, string>;
106
+ } | undefined>;
107
+ /** Main as the grader reads it (the runner's learning loop `readMain`): every active note's index line, the whole text
108
+ * of each note the proposal supersedes, and the blob each of those was read at (`graded`, which the merge checks); the
109
+ * proposal's notes named like a note main holds now, settled alone (`taken`); or `problems` when the proposal cannot
110
+ * join main as it is (learn/check.ts mergeProblems). From the folder's snapshot and its bodies: no git, no exec. */
78
111
  export declare function readMain(ws: Workspace, proposal: {
79
112
  readonly notes: readonly NoteText[];
80
113
  }): Promise<{
81
114
  active: IndexEntry[];
82
115
  superseded: NoteText[];
83
116
  graded: Record<string, string>;
117
+ taken?: LeftNote[];
84
118
  } | {
85
119
  problems: Problem[];
86
120
  }>;
@@ -4,10 +4,10 @@
4
4
  // the folder's snapshot and the bodies it names. A main that moved under it (the script's exit 3) is computed again on
5
5
  // the main that won, as long as no oid the caller read (`graded`, `ifMatch`) changed: a change it did not see is a
6
6
  // conflict, never written over. A folder with no main yet is made in the same call (the script's init first).
7
- import { isHeld, held } from "./skills.js";
8
- import { buildIndex, INDEX_FILE, INDEX_LINES, mergedNote, NOTE_FILE, parseNoteFile, supersede } from "./notes.js";
7
+ import { isHeld, held, retiredLearned } from "./skills.js";
8
+ import { buildIndex, INDEX_FILE, INDEX_LINES, mergedNote, NOTE_FILE, parseNoteFile, ruleOf, supersede } from "./notes.js";
9
9
  import { mergeProblems, supersededBy } from "./check.js";
10
- import { FolderRefused, FolderTooLarge, readLearning, readRunDiff, readSnapshot, snapshotNotes, topOf, writeLearning } from "./folder.js";
10
+ import { FolderRefused, FolderTooLarge, readLearning, readRunDiff, readSnapshot, snapshotNotes, textsAt, topOf, writeLearning } from "./folder.js";
11
11
  /** The blob `path` is on the snapshot's main: the index, a note, a learned folder's file. */
12
12
  function blobOf(snapshot, path) {
13
13
  if (!snapshot)
@@ -39,8 +39,8 @@ function heldText(path, text) {
39
39
  /**
40
40
  * One write on the folder's main, one exec of the learning script: a run's merge or a person's write, as `change` says.
41
41
  * `ok` with the new main (its commit) and the paths the commit changed; `conflict` when an oid the caller read is
42
- * another blob on main now; `refused` when the folder as it would be is refused (a name main holds already, the index
43
- * past its lines, a note out of shape); `unavailable` when the workspace or the exec failed (retry later). A merge whose
42
+ * another blob on main now; `refused` when the folder as it would be is refused (the index past its lines, a note out
43
+ * of shape); a new note named like one main holds, or of a rule one holds, is left out alone (`left`); `unavailable` when the workspace or the exec failed (retry later). A merge whose
44
44
  * run already merged here is `ok` with the commit that holds it, and writes nothing.
45
45
  */
46
46
  export async function learningCommit(ws, change, opts = {}) {
@@ -48,13 +48,23 @@ export async function learningCommit(ws, change, opts = {}) {
48
48
  if (change.kind === "merge") {
49
49
  const known = await readRunDiff(ws, change.runId);
50
50
  if (known) {
51
- return { ok: true, main: (await readSnapshot(ws))?.main ?? known.merge, commit: known.merge, files: known.files.map((file) => file.path) };
51
+ // Its merge is on main already (a retry after a crash, say): the new notes it did not write it left out, said
52
+ // again as the merge's own settle says them against main now (`taken` for a name main holds with another rule,
53
+ // else `same`), so a resumed merge says what the first said.
54
+ const written = new Set(known.files.map((file) => file.path));
55
+ const unwritten = change.files.filter(({ path }) => isNote(path) && !written.has(path));
56
+ const left = unwritten.length ? await readLearning(ws, async ({ snapshot, body }) => {
57
+ const settled = new Map((await settledNotes({ ...change, files: unwritten }, snapshot, body)).map(({ path, reason }) => [path, reason]));
58
+ return unwritten.map(({ path }) => ({ path, reason: settled.get(path) === "taken" ? "taken" : "same" }));
59
+ }) : [];
60
+ return { ok: true, main: (await readSnapshot(ws))?.main ?? known.merge, commit: known.merge, files: [...written], ...(left.length ? { left } : {}), already: true };
52
61
  }
53
62
  }
54
63
  const done = await writeLearning(ws, async ({ snapshot, body }) => (change.kind === "merge" ? mergeOf(change, snapshot, body) : personOf(change, snapshot)), opts.retries ?? 3);
55
64
  if (!("pending" in done.result))
56
65
  return done.result;
57
- return { ok: true, main: done.main, commit: done.main, files: done.snapshot?.log[0]?.commit === done.main ? done.snapshot.log[0].files : [] };
66
+ const left = done.result.left?.length ? { left: done.result.left } : {};
67
+ return { ok: true, main: done.main, commit: done.main, files: done.snapshot?.log[0]?.commit === done.main ? done.snapshot.log[0].files : [], ...left };
58
68
  }
59
69
  catch (error) {
60
70
  // The script's exit 4: a file changed since the seed is a conflict; a name held on main by a file that is no note
@@ -73,23 +83,66 @@ export async function learningCommit(ws, change, opts = {}) {
73
83
  * MEMORY.md rebuilt from what is active then. */
74
84
  async function mergeOf(change, snapshot, body) {
75
85
  const held = new Set(change.held ?? []);
86
+ const replaced = new Set(change.replace ?? []);
87
+ const left = await settledNotes(change, snapshot, body);
88
+ const leftOut = new Set(left.map(({ path }) => path));
76
89
  // Each new note as main keeps it (mergedNote): its own origin, `status: pending` when held, the run's risky mark gone.
77
90
  // A skill's SKILL.md or a draft's README.md held: `status: pending` last in its front matter.
78
- const files = new Map(change.files.map(({ path, text }) => {
91
+ const files = new Map(change.files.filter(({ path }) => !leftOut.has(path)).map(({ path, text }) => {
79
92
  if (isNote(path) && blobOf(snapshot, path) === undefined) {
80
93
  const note = parseNoteFile(path, text);
81
94
  return [path, Array.isArray(note) ? text : mergedNote(text, { origin: note.origin, pending: held.has(path) })];
82
95
  }
83
96
  return [path, held.has(path) ? heldText(path, text) : text];
84
97
  }));
98
+ // Each re-filed skill main holds, not retired, retired in this write (`retire`), unless its note was left out as taken.
99
+ const retiring = [];
100
+ // The rules main's active notes hold now, apart from the notes this merge supersedes: a skill retires only while its rule
101
+ // has an active note, the re-filed note written here or another main holds as this merge commits (a person may have
102
+ // edited or retired it since the grade read main), so the rule is never left with no active copy.
103
+ const superseding = new Set([...(change.supersede ?? []).map(({ path }) => path), ...[...files].filter(([path]) => isNote(path) && !held.has(path)).flatMap(([path, text]) => {
104
+ const one = parseNoteFile(path, text);
105
+ return Array.isArray(one) ? [] : one.supersedes;
106
+ })]);
107
+ const holding = new Set();
108
+ if (change.retire?.length) {
109
+ for (const one of snapshotNotes(snapshot).filter((note) => note.status === "active" && !superseding.has(note.file))) {
110
+ const text = parseNoteFile(one.file, await body(one.file, blobOf(snapshot, one.file)));
111
+ if (!Array.isArray(text))
112
+ holding.add(ruleOf(text.body));
113
+ }
114
+ for (const [path, text] of files) {
115
+ // A replacement written here counts held or not: a pending note retires its skill as before (the owner's OK makes it
116
+ // the rule); only one that is not written at all (left out, or gone from main) must find another holder.
117
+ const one = isNote(path) ? parseNoteFile(path, text) : undefined;
118
+ if (one && !Array.isArray(one))
119
+ holding.add(ruleOf(one.body));
120
+ }
121
+ }
122
+ for (const { skill, note, rule } of change.retire ?? []) {
123
+ if (left.some((one) => one.path === note && one.reason === "taken"))
124
+ continue;
125
+ if (!holding.has(rule))
126
+ continue;
127
+ const oid = blobOf(snapshot, skill);
128
+ const item = snapshot?.skills.find((one) => one.files.some((file) => file.path === skill));
129
+ if (oid === undefined || !item || item.status === "retired")
130
+ continue;
131
+ files.set(skill, retiredLearned(await body(skill, oid)));
132
+ retiring.push(skill);
133
+ }
134
+ // Nothing left to write: every new note is one main holds already, or a name it holds. No commit.
135
+ if (![...files.keys()].length)
136
+ return { result: { ok: true, main: snapshot?.main ?? "", commit: snapshot?.main ?? "", files: [], left } };
85
137
  const notes = snapshotNotes(snapshot);
86
138
  const active = new Set(notes.filter((note) => note.status === "active").map((note) => note.file));
87
139
  const refused = [];
88
- const fresh = [...files].filter(([path]) => isNote(path) && blobOf(snapshot, path) === undefined).flatMap(([path, text]) => {
140
+ const fresh = [...files].filter(([path]) => isNote(path) && (blobOf(snapshot, path) === undefined || replaced.has(path))).flatMap(([path, text]) => {
89
141
  const note = parseNoteFile(path, text);
90
142
  return Array.isArray(note) ? [] : [note];
91
143
  });
92
- const marks = change.supersede ?? [...supersededBy(fresh)].map(([path, by]) => ({ path, by }));
144
+ // A note written over main's by its own name supersedes that note by being it: never a mark of itself.
145
+ const marks = change.supersede ?? [...supersededBy(fresh)].filter(([path, by]) => path !== by).map(([path, by]) => ({ path, by }));
93
146
  // The verdict was on the blobs the grade read: one this merge would write (mark or replace) that is another blob on
94
147
  // main now is the caller's conflict, named by the note that would mark it. One it leaves alone (a held note marks
95
148
  // nothing) is not written over, so it stands.
@@ -117,7 +170,7 @@ async function mergeOf(change, snapshot, body) {
117
170
  // A merge adds notes and marks the ones they supersede: it never writes over another note main holds.
118
171
  if (blobOf(snapshot, path) === undefined)
119
172
  added.push(note);
120
- else if (!marks.some((one) => one.path === path))
173
+ else if (!marks.some((one) => one.path === path) && !replaced.has(path))
121
174
  refused.push({ rule: "exists", path, detail: "the folder has a note by this name" });
122
175
  }
123
176
  // mergeProblems asks of the new notes what a merge always asks: a free name, what they supersede active and named
@@ -129,15 +182,71 @@ async function mergeOf(change, snapshot, body) {
129
182
  const marked = new Set(written.map((note) => note.file));
130
183
  files.set(INDEX_FILE, buildIndex([...notes.filter((note) => !marked.has(note.file)), ...written]));
131
184
  return {
132
- result: { pending: true },
185
+ result: { pending: true, ...(left.length ? { left } : {}) },
133
186
  change: {
134
187
  by: { run: change.runId, reason: change.reason },
135
188
  writes: [...files].map(([path, text]) => ({ path, text })),
136
189
  absent: added.map((note) => note.file),
137
- ...(change.seed ? { same: change.files.filter(({ path }) => !isNote(path)).map(({ path }) => ({ commit: change.seed, path })) } : {}),
190
+ ...(change.seed ? { same: [...change.files.filter(({ path }) => !isNote(path)).map(({ path }) => path), ...retiring].map((path) => ({ commit: change.seed, path })) } : {}),
138
191
  },
139
192
  };
140
193
  }
194
+ /** Each new note of a merge settled against main as `snapshot` has it, one note at a time and never a refusal of the
195
+ * merge: a name main holds a note by (and the merge does not replace) is left out, `same` when main's note says the
196
+ * same rule, else `taken`; a rule main's active notes hold under another name, or an earlier note of this merge holds,
197
+ * is left out as `same` (notes.ts ruleOf), unless the note supersedes the note it repeats (an update). */
198
+ async function settledNotes(change, snapshot, body) {
199
+ const replaced = new Set(change.replace ?? []);
200
+ const left = [];
201
+ const newNotes = change.files.filter(({ path }) => isNote(path));
202
+ if (newNotes.length) {
203
+ // The notes this merge supersedes (its own marks, or what its new notes not held for the owner's OK supersede by
204
+ // their front matter) keep no rule after it: a copy of their rule under another name is no duplicate, so a rule is
205
+ // never left with no active note.
206
+ const held = new Set(change.held ?? []);
207
+ const going = new Set([...(change.supersede ?? []).map(({ path }) => path), ...newNotes.filter(({ path }) => !held.has(path)).flatMap(({ path, text }) => {
208
+ const note = parseNoteFile(path, text);
209
+ return Array.isArray(note) ? [] : note.supersedes;
210
+ })]);
211
+ const rules = new Map();
212
+ // Every rule main's active notes hold, whoever this merge supersedes: an update of that holder takes the rule over
213
+ // from an earlier note of this merge that repeated it, whatever their order.
214
+ const onMainRules = new Map();
215
+ for (const note of snapshotNotes(snapshot).filter((one) => one.status === "active")) {
216
+ const text = parseNoteFile(note.file, await body(note.file, blobOf(snapshot, note.file)));
217
+ if (Array.isArray(text))
218
+ continue;
219
+ onMainRules.set(ruleOf(text.body), note.file);
220
+ if (!going.has(note.file))
221
+ rules.set(ruleOf(text.body), note.file);
222
+ }
223
+ for (const { path, text } of newNotes) {
224
+ const note = parseNoteFile(path, text);
225
+ if (Array.isArray(note))
226
+ continue;
227
+ const rule = ruleOf(note.body);
228
+ const onMain = blobOf(snapshot, path);
229
+ if (onMain !== undefined && !replaced.has(path)) {
230
+ const theirs = parseNoteFile(path, await body(path, onMain));
231
+ // The same rule only when main's note keeps it active: a retired or superseded one is a name main holds.
232
+ left.push({ path, reason: !Array.isArray(theirs) && theirs.status === "active" && ruleOf(theirs.body) === rule ? "same" : "taken" });
233
+ continue;
234
+ }
235
+ const holder = rules.get(rule);
236
+ if (holder !== undefined && holder !== path && !note.supersedes.includes(holder)) {
237
+ const original = onMainRules.get(rule);
238
+ // An update of the rule's holder on main, after a copy of it: the update holds the rule, the copy is the repeat.
239
+ if (original === undefined || holder === original || !note.supersedes.includes(original) || held.has(path)) {
240
+ left.push({ path, reason: "same" });
241
+ continue;
242
+ }
243
+ left.push({ path: holder, reason: "same" });
244
+ }
245
+ rules.set(rule, path);
246
+ }
247
+ }
248
+ return left;
249
+ }
141
250
  /** A person's write on main as the snapshot has it: the file and what the action also changes, MEMORY.md rebuilt. */
142
251
  async function personOf(change, snapshot) {
143
252
  const current = blobOf(snapshot, change.file);
@@ -159,24 +268,59 @@ async function personOf(change, snapshot) {
159
268
  change: { by: { person: change.action, file: change.file, approved: change.via === "console" }, writes: [...writes, { path: INDEX_FILE, text: buildIndex(after) }], ...(change.action === "created" ? { absent: [change.file] } : {}) },
160
269
  };
161
270
  }
162
- /** Main as the grader reads it (the runner's learning loop `readMain`): every active note's index
163
- * line, the whole text of each note the proposal supersedes, and the blob each of those was read at (`graded`, which
164
- * the merge checks); or `problems` when the proposal cannot join main as it is (learn/check.ts mergeProblems). From
165
- * the folder's snapshot and its bodies: no git, no exec. */
271
+ /** The texts main holds at `paths`, each a note's file, by path: one main holds no note at is not in it. From the
272
+ * folder's snapshot and its bodies: no git, no exec. What a skill the grader re-filed as a note (grade.ts skillAsNote)
273
+ * would be written over, read before its merge. */
274
+ export async function mainTexts(ws, paths) {
275
+ if (!paths.length)
276
+ return {};
277
+ return readLearning(ws, async ({ snapshot, body }) => {
278
+ const oids = new Map((snapshot?.notes ?? []).map((note) => [note.file, note.oid]));
279
+ const held = paths.filter((path) => oids.has(path));
280
+ return Object.fromEntries(await Promise.all(held.map(async (path) => [path, await body(path, oids.get(path))])));
281
+ });
282
+ }
283
+ /** Run `runId`'s merge on the folder, when its diff file names one (readRunDiff): the texts its own commit holds at
284
+ * `paths`, each a note's file (one it holds nothing at is not in it), read at that commit, those paths alone (textsAt:
285
+ * one read-only exec, bounded by the paths asked, never the whole folder or its log), never main's now, which a person
286
+ * may have edited since. Undefined when the run merged nothing here. */
287
+ export async function mergedAt(ws, runId, paths) {
288
+ const diff = await readRunDiff(ws, runId);
289
+ if (!diff)
290
+ return undefined;
291
+ const texts = await textsAt(ws, diff.merge, paths);
292
+ if (!texts)
293
+ throw new Error(`the run's merge ${diff.merge} is not in the learning folder`);
294
+ return { texts };
295
+ }
296
+ /** Main as the grader reads it (the runner's learning loop `readMain`): every active note's index line, the whole text
297
+ * of each note the proposal supersedes, and the blob each of those was read at (`graded`, which the merge checks); the
298
+ * proposal's notes named like a note main holds now, settled alone (`taken`); or `problems` when the proposal cannot
299
+ * join main as it is (learn/check.ts mergeProblems). From the folder's snapshot and its bodies: no git, no exec. */
166
300
  export async function readMain(ws, proposal) {
167
301
  const added = proposal.notes.map(({ file, text }) => parseNoteFile(file, text));
168
302
  const bad = proposal.notes.filter((_, i) => Array.isArray(added[i])).map(({ file }) => ({ rule: "note", path: file, detail: "the proposal's note is out of shape" }));
169
303
  if (bad.length)
170
304
  return { problems: bad };
171
- const notes = added;
172
305
  return readLearning(ws, async ({ snapshot, body }) => {
173
306
  const main = snapshotNotes(snapshot);
307
+ const oids = new Map((snapshot?.notes ?? []).map((note) => [note.file, note.oid]));
308
+ // A new note named like one main holds (another run merged it since the run's seed, so the run never saw it) is
309
+ // settled alone, never a drop of the whole proposal: left out of the grade, `same` when main's note says its rule,
310
+ // else `taken`, and the rest is graded.
311
+ const taken = [];
312
+ for (const note of added) {
313
+ if (!oids.has(note.file))
314
+ continue;
315
+ const theirs = parseNoteFile(note.file, await body(note.file, oids.get(note.file)));
316
+ taken.push({ path: note.file, reason: !Array.isArray(theirs) && theirs.status === "active" && ruleOf(theirs.body) === ruleOf(note.body) ? "same" : "taken" });
317
+ }
318
+ const notes = added.filter((note) => !oids.has(note.file));
174
319
  const problems = mergeProblems({ files: topOf(snapshot), active: main.filter((note) => note.status === "active") }, notes);
175
320
  if (problems.length)
176
321
  return { problems };
177
- const oids = new Map((snapshot?.notes ?? []).map((note) => [note.file, note.oid]));
178
322
  // mergeProblems passed: each note superseded is active on main, and named once.
179
323
  const superseded = await Promise.all(notes.flatMap((note) => note.supersedes).map(async (file) => ({ file, text: await body(file, oids.get(file)) })));
180
- return { active: main.filter((note) => note.status === "active").map(({ file, name, description }) => ({ file, name, description })), superseded, graded: Object.fromEntries(superseded.map(({ file }) => [file, oids.get(file)])) };
324
+ return { active: main.filter((note) => note.status === "active").map(({ file, name, description }) => ({ file, name, description })), superseded, graded: Object.fromEntries(superseded.map(({ file }) => [file, oids.get(file)])), ...(taken.length ? { taken } : {}) };
181
325
  });
182
326
  }
@@ -34,6 +34,9 @@ export type SnapNote = {
34
34
  origin: "you" | "run";
35
35
  supersedes: string[];
36
36
  superseded_by: string | null;
37
+ /** Past SNAPSHOT.md v1, additive, on a retired note alone: the status its restore gives back (notes.ts LearnedNote
38
+ * retired_from). */
39
+ retired_from?: "active" | "pending";
37
40
  order: number;
38
41
  history: SnapHistory;
39
42
  };
@@ -47,6 +50,9 @@ export type SnapLearned = {
47
50
  file: string;
48
51
  description: string;
49
52
  status: "active" | "pending" | "retired";
53
+ /** Past SNAPSHOT.md v1, additive, on a retired skill or draft alone: the status its restore gives back (skills.ts
54
+ * retiredFrom). */
55
+ retired_from?: "active" | "pending";
50
56
  run: string | null;
51
57
  files: SnapFile[];
52
58
  oid: string;
@@ -262,10 +268,12 @@ export declare function folderAt(ws: Workspace, commit: string): Promise<{
262
268
  snapshot: Snapshot;
263
269
  blobs: ReadonlyMap<string, Buffer>;
264
270
  } | undefined>;
271
+ /** The texts `commit` holds at `paths` (each a plain path, checkPath), each read alone with one read-only exec (the
272
+ * script's show: git cat-file over each `<commit>:<path>`), never the whole tree, its blobs or its log, so the read is
273
+ * bounded by what is asked, whatever the folder holds. A path the commit holds no file at is not in it. Undefined when
274
+ * the folder has no such commit. */
275
+ export declare function textsAt(ws: Workspace, commit: string, paths: readonly string[]): Promise<Record<string, string> | undefined>;
265
276
  export declare function learningRepair(ws: Workspace): Promise<Snapshot | undefined>;
266
- /** Main's text of `path` just before the newest person's retire of it on `main`'s line, or undefined (never retired by
267
- * a person). A read through the script: git's history is not in the snapshot. */
268
- export declare function beforeRetire(ws: Workspace, main: string, path: string): Promise<string | undefined>;
269
277
  /** Whether `main` holds anything at `path`, as git stores it (any mode, any type): what the snapshot leaves out (a file
270
278
  * that is no note) included. A read through the script. */
271
279
  export declare function heldOnMain(ws: Workspace, main: string, path: string): Promise<boolean>;