@parcha/agentrun-serve 0.1.0-beta.31 → 0.1.0-beta.32

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 (810) hide show
  1. package/CHANGELOG.md +422 -0
  2. package/NOTICE +18 -0
  3. package/README.md +887 -241
  4. package/dist/adapter-facts.d.ts +3 -0
  5. package/dist/adapter-facts.js +5 -0
  6. package/dist/adapters.d.ts +64 -140
  7. package/dist/adapters.js +153 -377
  8. package/dist/agents-store.d.ts +146 -0
  9. package/dist/agents-store.js +359 -0
  10. package/dist/agents.d.ts +5 -3
  11. package/dist/agents.js +37 -17
  12. package/dist/app.d.ts +2 -4
  13. package/dist/app.js +207 -92
  14. package/dist/approvals.d.ts +4 -0
  15. package/dist/approvals.js +7 -0
  16. package/dist/archil-routes.d.ts +45 -0
  17. package/dist/archil-routes.js +150 -0
  18. package/dist/archil-settings.d.ts +30 -0
  19. package/dist/archil-settings.js +34 -0
  20. package/dist/background.js +28 -9
  21. package/dist/bounds.d.ts +26 -0
  22. package/dist/bounds.js +137 -0
  23. package/dist/box-egress-vm.d.ts +2 -1
  24. package/dist/box-egress-vm.js +20 -6
  25. package/dist/box-egress.d.ts +16 -6
  26. package/dist/box-egress.js +27 -15
  27. package/dist/box-paths.d.ts +59 -0
  28. package/dist/box-paths.js +92 -0
  29. package/dist/box-relay-vm.js +28 -1
  30. package/dist/box-relay.d.ts +2 -0
  31. package/dist/box-relay.js +2 -2
  32. package/dist/boxes.d.ts +13 -1
  33. package/dist/boxes.js +37 -3
  34. package/dist/browser-commands.d.ts +43 -0
  35. package/dist/browser-commands.js +154 -0
  36. package/dist/browser-cost.d.ts +30 -3
  37. package/dist/browser-cost.js +276 -21
  38. package/dist/browser-live.d.ts +124 -0
  39. package/dist/browser-live.js +324 -0
  40. package/dist/browser-person.d.ts +168 -0
  41. package/dist/browser-person.js +769 -0
  42. package/dist/budget.d.ts +80 -0
  43. package/dist/budget.js +211 -0
  44. package/dist/cap.d.ts +272 -62
  45. package/dist/cap.js +599 -189
  46. package/dist/cli.js +201 -17
  47. package/dist/coding-tools.d.ts +13 -1
  48. package/dist/coding-tools.js +107 -5
  49. package/dist/computer-adb.d.ts +12 -0
  50. package/dist/computer-adb.js +14 -0
  51. package/dist/computer-commands.d.ts +103 -0
  52. package/dist/computer-commands.js +256 -0
  53. package/dist/computer-keys.d.ts +68 -0
  54. package/dist/computer-keys.js +148 -0
  55. package/dist/computer-routes.d.ts +38 -0
  56. package/dist/computer-routes.js +56 -0
  57. package/dist/computer-setting.d.ts +37 -0
  58. package/dist/computer-setting.js +47 -0
  59. package/dist/computer-view.d.ts +38 -0
  60. package/dist/computer-view.js +14 -0
  61. package/dist/computers.d.ts +137 -0
  62. package/dist/computers.js +197 -0
  63. package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
  64. package/dist/console/assets/index-35-7aeIZ.js +519 -0
  65. package/dist/console/assets/index-Cejbov-Y.css +1 -0
  66. package/dist/console/index.html +2 -2
  67. package/dist/console-links.d.ts +2 -0
  68. package/dist/console-links.js +6 -0
  69. package/dist/decision-cap.d.ts +63 -0
  70. package/dist/decision-cap.js +163 -0
  71. package/dist/decision-rows.d.ts +5 -2
  72. package/dist/decision-rows.js +8 -6
  73. package/dist/decisions.d.ts +28 -1
  74. package/dist/decisions.js +63 -6
  75. package/dist/disk.d.ts +33 -0
  76. package/dist/disk.js +85 -0
  77. package/dist/door-line.d.ts +23 -0
  78. package/dist/door-line.js +83 -0
  79. package/dist/egress-proxy.d.ts +45 -0
  80. package/dist/egress-proxy.js +416 -0
  81. package/dist/egress-table.d.ts +24 -0
  82. package/dist/egress-table.js +165 -0
  83. package/dist/errors.d.ts +15 -0
  84. package/dist/errors.js +22 -2
  85. package/dist/exa-keyless.js +1 -1
  86. package/dist/explain.d.ts +22 -0
  87. package/dist/explain.js +207 -0
  88. package/dist/faux-computers.d.ts +35 -0
  89. package/dist/faux-computers.js +126 -0
  90. package/dist/file-types.d.ts +4 -0
  91. package/dist/file-types.js +11 -0
  92. package/dist/files.d.ts +3 -35
  93. package/dist/files.js +9 -120
  94. package/dist/github-connection.d.ts +207 -0
  95. package/dist/github-connection.js +595 -0
  96. package/dist/github.d.ts +64 -0
  97. package/dist/github.js +119 -0
  98. package/dist/grade.d.ts +9 -42
  99. package/dist/grade.js +42 -228
  100. package/dist/graph-served.d.ts +23 -2
  101. package/dist/graph-served.js +44 -3
  102. package/dist/graph-view.d.ts +7 -3
  103. package/dist/graph-view.js +26 -15
  104. package/dist/handed-values.d.ts +23 -0
  105. package/dist/handed-values.js +36 -0
  106. package/dist/harness-app.d.ts +33 -4
  107. package/dist/harness-app.js +530 -85
  108. package/dist/harness-install.d.ts +120 -0
  109. package/dist/harness-install.js +359 -0
  110. package/dist/harness-opencode/adapter.js +42 -8
  111. package/dist/harness-opencode/facts.d.ts +2 -0
  112. package/dist/harness-opencode/facts.js +28 -0
  113. package/dist/harness-opencode/harness.d.ts +4 -0
  114. package/dist/harness-opencode/harness.js +38 -5
  115. package/dist/harness-opencode/host/policy.js +11 -3
  116. package/dist/harness-opencode/transcript.d.ts +25 -0
  117. package/dist/harness-opencode/transcript.js +81 -0
  118. package/dist/harness-table.d.ts +75 -0
  119. package/dist/harness-table.js +145 -0
  120. package/dist/harness.d.ts +7 -28
  121. package/dist/harness.js +15 -41
  122. package/dist/heard.d.ts +12 -0
  123. package/dist/heard.js +45 -0
  124. package/dist/helper-env.d.ts +4 -0
  125. package/dist/helper-env.js +14 -0
  126. package/dist/home-path.d.ts +0 -4
  127. package/dist/home-path.js +3 -17
  128. package/dist/host-check.d.ts +4 -3
  129. package/dist/host-check.js +5 -4
  130. package/dist/host-tools.d.ts +51 -8
  131. package/dist/host-tools.js +108 -117
  132. package/dist/host.d.ts +12 -6
  133. package/dist/host.js +30 -24
  134. package/dist/hosted-search.d.ts +3 -0
  135. package/dist/hosted-search.js +5 -3
  136. package/dist/import-proxy.d.ts +42 -0
  137. package/dist/import-proxy.js +105 -0
  138. package/dist/import-summary.js +4 -8
  139. package/dist/import-worker.d.ts +2 -3
  140. package/dist/import-worker.js +18 -16
  141. package/dist/import.d.ts +37 -17
  142. package/dist/import.js +208 -222
  143. package/dist/key-meta.d.ts +26 -0
  144. package/dist/key-meta.js +30 -0
  145. package/dist/key-refusal.d.ts +4 -1
  146. package/dist/key-refusal.js +20 -7
  147. package/dist/learn/check.d.ts +3 -1
  148. package/dist/learn/check.js +2 -2
  149. package/dist/learn/commit.d.ts +86 -0
  150. package/dist/learn/commit.js +182 -0
  151. package/dist/learn/folder.d.ts +296 -0
  152. package/dist/learn/folder.js +796 -0
  153. package/dist/learn/grade.d.ts +22 -9
  154. package/dist/learn/grade.js +95 -49
  155. package/dist/learn/index.d.ts +2 -2
  156. package/dist/learn/index.js +2 -2
  157. package/dist/learn/learning.sh +366 -0
  158. package/dist/learn/reflect.d.ts +12 -5
  159. package/dist/learn/reflect.js +70 -41
  160. package/dist/learn/secrets.d.ts +15 -7
  161. package/dist/learn/secrets.js +66 -16
  162. package/dist/learn/seed-check.d.ts +74 -0
  163. package/dist/learn/seed-check.js +103 -0
  164. package/dist/learn/skills.d.ts +5 -1
  165. package/dist/learn/skills.js +5 -4
  166. package/dist/learned-workflow.d.ts +12 -2
  167. package/dist/learned-workflow.js +9 -5
  168. package/dist/learning-routes.d.ts +88 -41
  169. package/dist/learning-routes.js +340 -539
  170. package/dist/learning-run.d.ts +60 -53
  171. package/dist/learning-run.js +181 -224
  172. package/dist/learning-words.d.ts +3 -5
  173. package/dist/learning-words.js +3 -5
  174. package/dist/learning.d.ts +177 -112
  175. package/dist/learning.js +289 -380
  176. package/dist/live/stream.d.ts +30 -0
  177. package/dist/live/stream.js +175 -0
  178. package/dist/live/translate.d.ts +52 -0
  179. package/dist/live/translate.js +276 -0
  180. package/dist/llm.js +3 -0
  181. package/dist/llms.txt +1 -0
  182. package/dist/local-models.d.ts +23 -0
  183. package/dist/local-models.js +35 -0
  184. package/dist/mcp-gateway.d.ts +46 -13
  185. package/dist/mcp-gateway.js +145 -45
  186. package/dist/mcp-meta.d.ts +3 -0
  187. package/dist/mcp-meta.js +14 -2
  188. package/dist/mcp-oauth.d.ts +172 -0
  189. package/dist/mcp-oauth.js +403 -0
  190. package/dist/mcp-private-hosts.d.ts +48 -0
  191. package/dist/mcp-private-hosts.js +141 -0
  192. package/dist/mcp-probe.d.ts +101 -0
  193. package/dist/mcp-probe.js +359 -0
  194. package/dist/mcp-secret-writes.d.ts +23 -0
  195. package/dist/mcp-secret-writes.js +60 -0
  196. package/dist/mcp-servers-store.d.ts +251 -0
  197. package/dist/mcp-servers-store.js +447 -0
  198. package/dist/mcp-servers.d.ts +180 -50
  199. package/dist/mcp-servers.js +284 -321
  200. package/dist/mcp-store.d.ts +103 -0
  201. package/dist/mcp-store.js +123 -0
  202. package/dist/mcp.js +22 -21
  203. package/dist/model.d.ts +77 -59
  204. package/dist/model.js +237 -98
  205. package/dist/monid.d.ts +8 -6
  206. package/dist/monid.js +39 -25
  207. package/dist/openapi.d.ts +22 -1
  208. package/dist/openapi.js +919 -108
  209. package/dist/owner.d.ts +46 -10
  210. package/dist/owner.js +123 -43
  211. package/dist/page.d.ts +10 -0
  212. package/dist/page.js +27 -4
  213. package/dist/paid-calls.d.ts +71 -2
  214. package/dist/paid-calls.js +125 -5
  215. package/dist/pdf-pages.d.ts +16 -14
  216. package/dist/pdf-pages.js +88 -58
  217. package/dist/place.d.ts +15 -13
  218. package/dist/place.js +25 -15
  219. package/dist/port-models.d.ts +53 -0
  220. package/dist/port-models.js +93 -0
  221. package/dist/propose.d.ts +9 -8
  222. package/dist/propose.js +82 -49
  223. package/dist/provider.d.ts +85 -0
  224. package/dist/provider.js +178 -0
  225. package/dist/push-handler.d.ts +52 -0
  226. package/dist/push-handler.js +165 -0
  227. package/dist/refusal-words.d.ts +23 -0
  228. package/dist/refusal-words.js +25 -0
  229. package/dist/request-start.d.ts +6 -1
  230. package/dist/request-start.js +41 -10
  231. package/dist/result.d.ts +13 -2
  232. package/dist/result.js +4 -5
  233. package/dist/run-box.d.ts +22 -3
  234. package/dist/run-box.js +78 -17
  235. package/dist/run-computer.d.ts +24 -0
  236. package/dist/run-computer.js +15 -0
  237. package/dist/run-cut.d.ts +33 -0
  238. package/dist/run-cut.js +42 -0
  239. package/dist/run-db.d.ts +64 -0
  240. package/dist/run-db.js +155 -0
  241. package/dist/run-files.d.ts +31 -0
  242. package/dist/run-files.js +125 -0
  243. package/dist/run-holder.d.ts +52 -0
  244. package/dist/run-holder.js +139 -0
  245. package/dist/run-launch.d.ts +72 -0
  246. package/dist/run-launch.js +108 -0
  247. package/dist/run-learning-served.d.ts +43 -0
  248. package/dist/run-learning-served.js +16 -0
  249. package/dist/run-manifest.d.ts +7 -6
  250. package/dist/run-manifest.js +20 -10
  251. package/dist/run-reads-over-store.d.ts +102 -0
  252. package/dist/run-reads-over-store.js +151 -0
  253. package/dist/run-timeline-served.d.ts +13 -0
  254. package/dist/run-timeline-served.js +69 -0
  255. package/dist/run-view.d.ts +436 -0
  256. package/dist/run-view.js +620 -0
  257. package/dist/runnable.d.ts +30 -5
  258. package/dist/runnable.js +149 -72
  259. package/dist/runner/adapter-loop.d.ts +237 -0
  260. package/dist/runner/adapter-loop.js +1625 -0
  261. package/dist/runner/adapter-run-spec.d.ts +216 -0
  262. package/dist/runner/adapter-run-spec.js +537 -0
  263. package/dist/runner/adapters/index.d.ts +37 -0
  264. package/dist/runner/adapters/index.js +66 -0
  265. package/dist/runner/adapters/pi.d.ts +99 -0
  266. package/dist/runner/adapters/pi.js +260 -0
  267. package/dist/runner/beside.d.ts +12 -0
  268. package/dist/runner/beside.js +30 -0
  269. package/dist/runner/claim-secrets.d.ts +30 -0
  270. package/dist/runner/claim-secrets.js +90 -0
  271. package/dist/runner/cli-run-spec.d.ts +17 -0
  272. package/dist/runner/cli-run-spec.js +371 -0
  273. package/dist/runner/commands.d.ts +23 -0
  274. package/dist/runner/commands.js +67 -0
  275. package/dist/runner/computer-journal.d.ts +38 -0
  276. package/dist/runner/computer-journal.js +120 -0
  277. package/dist/runner/conformance/child.d.ts +1 -0
  278. package/dist/runner/conformance/child.js +78 -0
  279. package/dist/runner/conformance/harness.d.ts +89 -0
  280. package/dist/runner/conformance/harness.js +928 -0
  281. package/dist/runner/conformance/subject.d.ts +83 -0
  282. package/dist/runner/conformance/subject.js +1 -0
  283. package/dist/runner/dispatch.d.ts +30 -0
  284. package/dist/runner/dispatch.js +99 -0
  285. package/dist/runner/end-of-run.d.ts +32 -0
  286. package/dist/runner/end-of-run.js +56 -0
  287. package/dist/runner/github-app.d.ts +16 -0
  288. package/dist/runner/github-app.js +37 -0
  289. package/dist/runner/hand-back.d.ts +43 -0
  290. package/dist/runner/hand-back.js +69 -0
  291. package/dist/runner/harness-loops.d.ts +10 -0
  292. package/dist/runner/harness-loops.js +70 -0
  293. package/dist/runner/journal-kinds.d.ts +211 -0
  294. package/dist/runner/journal-kinds.js +116 -0
  295. package/dist/runner/journal-reader.d.ts +44 -0
  296. package/dist/runner/journal-reader.js +127 -0
  297. package/dist/runner/learning-ask.d.ts +37 -0
  298. package/dist/runner/learning-ask.js +99 -0
  299. package/dist/runner/learning-dispatch.d.ts +38 -0
  300. package/dist/runner/learning-dispatch.js +75 -0
  301. package/dist/runner/learning-end.d.ts +31 -0
  302. package/dist/runner/learning-end.js +136 -0
  303. package/dist/runner/learning-factory.d.ts +13 -0
  304. package/dist/runner/learning-factory.js +37 -0
  305. package/dist/runner/learning-loop.d.ts +150 -0
  306. package/dist/runner/learning-loop.js +246 -0
  307. package/dist/runner/learning-seed.d.ts +30 -0
  308. package/dist/runner/learning-seed.js +41 -0
  309. package/dist/runner/live-ticker.d.ts +18 -0
  310. package/dist/runner/live-ticker.js +88 -0
  311. package/dist/runner/loop-contract.d.ts +153 -0
  312. package/dist/runner/loop-contract.js +26 -0
  313. package/dist/runner/loop.d.ts +79 -0
  314. package/dist/runner/loop.js +185 -0
  315. package/dist/runner/main.d.ts +89 -0
  316. package/dist/runner/main.js +282 -0
  317. package/dist/runner/mcp-claim.d.ts +67 -0
  318. package/dist/runner/mcp-claim.js +403 -0
  319. package/dist/runner/mcp-github.d.ts +53 -0
  320. package/dist/runner/mcp-github.js +91 -0
  321. package/dist/runner/mcp-run.d.ts +116 -0
  322. package/dist/runner/mcp-run.js +152 -0
  323. package/dist/runner/metrics.d.ts +18 -0
  324. package/dist/runner/metrics.js +24 -0
  325. package/dist/runner/model-route.d.ts +111 -0
  326. package/dist/runner/model-route.js +183 -0
  327. package/dist/runner/pi-stop.d.ts +6 -0
  328. package/dist/runner/pi-stop.js +8 -0
  329. package/dist/runner/redact.d.ts +26 -0
  330. package/dist/runner/redact.js +51 -0
  331. package/dist/runner/reflect-hook.d.ts +81 -0
  332. package/dist/runner/reflect-hook.js +111 -0
  333. package/dist/runner/runner.d.ts +114 -0
  334. package/dist/runner/runner.js +672 -0
  335. package/dist/runner/sessions.d.ts +9 -0
  336. package/dist/runner/sessions.js +145 -0
  337. package/dist/runner/side-effects.d.ts +19 -0
  338. package/dist/runner/side-effects.js +20 -0
  339. package/dist/runner/spec-holds.d.ts +41 -0
  340. package/dist/runner/spec-holds.js +58 -0
  341. package/dist/runner/store-port.d.ts +9 -0
  342. package/dist/runner/store-port.js +7 -0
  343. package/dist/runner/store-secrets.d.ts +11 -0
  344. package/dist/runner/store-secrets.js +105 -0
  345. package/dist/runner/workflow-adapters.d.ts +1 -0
  346. package/dist/runner/workflow-adapters.js +4 -0
  347. package/dist/runner/workflow-host.d.ts +88 -0
  348. package/dist/runner/workflow-host.js +66 -0
  349. package/dist/runner/workflow-loop.d.ts +126 -0
  350. package/dist/runner/workflow-loop.js +372 -0
  351. package/dist/runner/workflow-spec.d.ts +157 -0
  352. package/dist/runner/workflow-spec.js +801 -0
  353. package/dist/runs-over-store.d.ts +203 -0
  354. package/dist/runs-over-store.js +396 -0
  355. package/dist/runs.d.ts +351 -220
  356. package/dist/runs.js +1570 -540
  357. package/dist/seal-key.d.ts +30 -0
  358. package/dist/seal-key.js +141 -0
  359. package/dist/sealed-settings-store.d.ts +71 -0
  360. package/dist/sealed-settings-store.js +205 -0
  361. package/dist/sealed-settings.d.ts +60 -0
  362. package/dist/sealed-settings.js +178 -0
  363. package/dist/secret-writes.d.ts +147 -0
  364. package/dist/secret-writes.js +144 -0
  365. package/dist/secrets.d.ts +7 -0
  366. package/dist/secrets.js +17 -2
  367. package/dist/served-only.d.ts +5 -0
  368. package/dist/served-only.js +12 -0
  369. package/dist/server-approvers.d.ts +8 -0
  370. package/dist/server-approvers.js +12 -0
  371. package/dist/server-fs.d.ts +40 -0
  372. package/dist/server-fs.js +138 -0
  373. package/dist/server-keys.d.ts +18 -0
  374. package/dist/server-keys.js +31 -0
  375. package/dist/server-lock.js +1 -1
  376. package/dist/server-secrets-store.d.ts +18 -0
  377. package/dist/server-secrets-store.js +54 -0
  378. package/dist/server-secrets.d.ts +23 -0
  379. package/dist/server-secrets.js +73 -0
  380. package/dist/server.d.ts +142 -73
  381. package/dist/server.js +1683 -596
  382. package/dist/sessions.d.ts +3 -1
  383. package/dist/sessions.js +8 -4
  384. package/dist/sign-ins-secrets.d.ts +35 -0
  385. package/dist/sign-ins-secrets.js +109 -0
  386. package/dist/sign-ins-store.d.ts +200 -0
  387. package/dist/sign-ins-store.js +373 -0
  388. package/dist/sign-ins.d.ts +43 -7
  389. package/dist/sign-ins.js +94 -18
  390. package/dist/skills.d.ts +6 -5
  391. package/dist/skills.js +18 -14
  392. package/dist/standard-webhooks.d.ts +30 -0
  393. package/dist/standard-webhooks.js +72 -0
  394. package/dist/stats.d.ts +5 -7
  395. package/dist/stats.js +8 -24
  396. package/dist/stop-signals.d.ts +22 -0
  397. package/dist/stop-signals.js +38 -0
  398. package/dist/store/agent-body.d.ts +103 -0
  399. package/dist/store/agent-body.js +126 -0
  400. package/dist/store/dialect.d.ts +59 -0
  401. package/dist/store/dialect.js +32 -0
  402. package/dist/store/fence.d.ts +22 -0
  403. package/dist/store/fence.js +15 -0
  404. package/dist/store/index.d.ts +17 -0
  405. package/dist/store/index.js +17 -0
  406. package/dist/store/journal/storage.d.ts +137 -0
  407. package/dist/store/journal/storage.js +1021 -0
  408. package/dist/store/open.d.ts +34 -0
  409. package/dist/store/open.js +30 -0
  410. package/dist/store/postgres/connection.d.ts +74 -0
  411. package/dist/store/postgres/connection.js +532 -0
  412. package/dist/store/postgres/dialect.d.ts +9 -0
  413. package/dist/store/postgres/dialect.js +39 -0
  414. package/dist/store/postgres/migrate.d.ts +21 -0
  415. package/dist/store/postgres/migrate.js +106 -0
  416. package/dist/store/postgres/migrations/0001_initial.sql +418 -0
  417. package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
  418. package/dist/store/postgres/store.d.ts +37 -0
  419. package/dist/store/postgres/store.js +48 -0
  420. package/dist/store/prompts.d.ts +11 -0
  421. package/dist/store/prompts.js +112 -0
  422. package/dist/store/schema.d.ts +26 -0
  423. package/dist/store/schema.js +522 -0
  424. package/dist/store/seal.d.ts +48 -0
  425. package/dist/store/seal.js +69 -0
  426. package/dist/store/sqlite/connection.d.ts +105 -0
  427. package/dist/store/sqlite/connection.js +309 -0
  428. package/dist/store/sqlite/memory.d.ts +2 -0
  429. package/dist/store/sqlite/memory.js +4 -0
  430. package/dist/store/sqlite/run-launch.d.ts +8 -0
  431. package/dist/store/sqlite/run-launch.js +20 -0
  432. package/dist/store/sqlite/run-patch.d.ts +54 -0
  433. package/dist/store/sqlite/run-patch.js +114 -0
  434. package/dist/store/sqlite/store.d.ts +33 -0
  435. package/dist/store/sqlite/store.js +1337 -0
  436. package/dist/store/sqlite/worker.d.ts +78 -0
  437. package/dist/store/sqlite/worker.js +242 -0
  438. package/dist/store/store.d.ts +1253 -0
  439. package/dist/store/store.js +190 -0
  440. package/dist/store-reads/analytics.d.ts +55 -0
  441. package/dist/store-reads/analytics.js +135 -0
  442. package/dist/store-reads/cap.d.ts +17 -0
  443. package/dist/store-reads/cap.js +17 -0
  444. package/dist/store-reads/decisions.d.ts +5 -0
  445. package/dist/store-reads/decisions.js +31 -0
  446. package/dist/store-reads/import-summary.d.ts +6 -0
  447. package/dist/store-reads/import-summary.js +14 -0
  448. package/dist/store-reads/journal.d.ts +30 -0
  449. package/dist/store-reads/journal.js +120 -0
  450. package/dist/store-reads/learning.d.ts +93 -0
  451. package/dist/store-reads/learning.js +202 -0
  452. package/dist/store-reads/runs.d.ts +42 -0
  453. package/dist/store-reads/runs.js +84 -0
  454. package/dist/store-reads/stats.d.ts +30 -0
  455. package/dist/store-reads/stats.js +59 -0
  456. package/dist/store-reads/workflow.d.ts +7 -0
  457. package/dist/store-reads/workflow.js +14 -0
  458. package/dist/store-view.d.ts +37 -0
  459. package/dist/store-view.js +305 -0
  460. package/dist/template-eval.d.ts +239 -0
  461. package/dist/template-eval.js +1020 -0
  462. package/dist/template-github-permissions.d.ts +18 -0
  463. package/dist/template-github-permissions.js +32 -0
  464. package/dist/templates.d.ts +199 -0
  465. package/dist/templates.js +637 -0
  466. package/dist/tool-blurbs.d.ts +4 -0
  467. package/dist/tool-blurbs.js +27 -0
  468. package/dist/tool-gate.d.ts +166 -35
  469. package/dist/tool-gate.js +411 -91
  470. package/dist/tool-keys-store.d.ts +110 -0
  471. package/dist/tool-keys-store.js +291 -0
  472. package/dist/tool-keys.d.ts +25 -12
  473. package/dist/tool-keys.js +20 -2
  474. package/dist/tool-plane.d.ts +113 -27
  475. package/dist/tool-plane.js +229 -76
  476. package/dist/tool-settings-store.d.ts +30 -0
  477. package/dist/tool-settings-store.js +53 -0
  478. package/dist/tools.d.ts +95 -24
  479. package/dist/tools.js +337 -61
  480. package/dist/trigger-accept.d.ts +36 -0
  481. package/dist/trigger-accept.js +152 -0
  482. package/dist/trigger-adapter.d.ts +143 -0
  483. package/dist/trigger-adapter.js +31 -0
  484. package/dist/trigger-adapters.d.ts +2 -0
  485. package/dist/trigger-adapters.js +4 -0
  486. package/dist/trigger-github.d.ts +2 -0
  487. package/dist/trigger-github.js +85 -0
  488. package/dist/trigger-schedule.d.ts +6 -0
  489. package/dist/trigger-schedule.js +115 -0
  490. package/dist/trigger-secrets-shown.d.ts +66 -0
  491. package/dist/trigger-secrets-shown.js +77 -0
  492. package/dist/trigger-signatures.d.ts +58 -0
  493. package/dist/trigger-signatures.js +79 -0
  494. package/dist/trigger-targets.d.ts +46 -0
  495. package/dist/trigger-targets.js +95 -0
  496. package/dist/trigger-webhook.d.ts +2 -0
  497. package/dist/trigger-webhook.js +92 -0
  498. package/dist/triggers.d.ts +282 -237
  499. package/dist/triggers.js +720 -608
  500. package/dist/turn-end.d.ts +3 -0
  501. package/dist/turn-end.js +3 -0
  502. package/dist/uploads.d.ts +10 -8
  503. package/dist/uploads.js +45 -45
  504. package/dist/usage.d.ts +33 -3
  505. package/dist/usage.js +38 -4
  506. package/dist/validate.d.ts +6 -0
  507. package/dist/validate.js +42 -12
  508. package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
  509. package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
  510. package/dist/web-fetch.d.ts +17 -9
  511. package/dist/web-fetch.js +53 -18
  512. package/dist/web-search.d.ts +1 -1
  513. package/dist/web-search.js +1 -1
  514. package/dist/webhooks.d.ts +33 -23
  515. package/dist/webhooks.js +69 -56
  516. package/dist/wires.d.ts +11 -0
  517. package/dist/wires.js +7 -0
  518. package/dist/workspace/archil-claim.d.ts +57 -0
  519. package/dist/workspace/archil-claim.js +154 -0
  520. package/dist/workspace/archil-disk.d.ts +104 -0
  521. package/dist/workspace/archil-disk.js +254 -0
  522. package/dist/workspace/archil-exec.d.ts +59 -0
  523. package/dist/workspace/archil-exec.js +218 -0
  524. package/dist/workspace/archil-key.d.ts +17 -0
  525. package/dist/workspace/archil-key.js +30 -0
  526. package/dist/workspace/archil-mount-credential.d.ts +58 -0
  527. package/dist/workspace/archil-mount-credential.js +165 -0
  528. package/dist/workspace/archil.d.ts +59 -0
  529. package/dist/workspace/archil.js +676 -0
  530. package/dist/workspace/attach.d.ts +48 -0
  531. package/dist/workspace/attach.js +439 -0
  532. package/dist/workspace/computer-deps.d.ts +58 -0
  533. package/dist/workspace/computer-deps.js +113 -0
  534. package/dist/workspace/computer-for-claim.d.ts +115 -0
  535. package/dist/workspace/computer-for-claim.js +198 -0
  536. package/dist/workspace/computer-hold.d.ts +145 -0
  537. package/dist/workspace/computer-hold.js +258 -0
  538. package/dist/workspace/computer-ledger.d.ts +22 -0
  539. package/dist/workspace/computer-ledger.js +19 -0
  540. package/dist/workspace/computer-ports.d.ts +13 -0
  541. package/dist/workspace/computer-ports.js +108 -0
  542. package/dist/workspace/computer-providers.d.ts +12 -0
  543. package/dist/workspace/computer-providers.js +17 -0
  544. package/dist/workspace/computer-serves.d.ts +12 -0
  545. package/dist/workspace/computer-serves.js +15 -0
  546. package/dist/workspace/executors.d.ts +38 -0
  547. package/dist/workspace/executors.js +150 -0
  548. package/dist/workspace/glob.d.ts +2 -0
  549. package/dist/workspace/glob.js +25 -0
  550. package/dist/workspace/grep-worker.d.ts +11 -0
  551. package/dist/workspace/grep-worker.js +91 -0
  552. package/dist/workspace/hands.d.ts +25 -0
  553. package/dist/workspace/hands.js +121 -0
  554. package/dist/workspace/index.d.ts +23 -0
  555. package/dist/workspace/index.js +25 -0
  556. package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
  557. package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
  558. package/dist/workspace/kind-skills.d.ts +11 -0
  559. package/dist/workspace/kind-skills.js +16 -0
  560. package/dist/workspace/learning-workspace.d.ts +24 -0
  561. package/dist/workspace/learning-workspace.js +107 -0
  562. package/dist/workspace/local.d.ts +6 -0
  563. package/dist/workspace/local.js +632 -0
  564. package/dist/workspace/paths.d.ts +48 -0
  565. package/dist/workspace/paths.js +134 -0
  566. package/dist/workspace/pi-env.d.ts +39 -0
  567. package/dist/workspace/pi-env.js +397 -0
  568. package/dist/workspace/place.d.ts +7 -0
  569. package/dist/workspace/place.js +3 -0
  570. package/dist/workspace/resolve-computer.d.ts +106 -0
  571. package/dist/workspace/resolve-computer.js +188 -0
  572. package/dist/workspace/revision-skills.d.ts +15 -0
  573. package/dist/workspace/revision-skills.js +42 -0
  574. package/dist/workspace/run-tools.d.ts +173 -0
  575. package/dist/workspace/run-tools.js +172 -0
  576. package/dist/workspace/run-workspace.d.ts +25 -0
  577. package/dist/workspace/run-workspace.js +56 -0
  578. package/dist/workspace/server-run-workspace.d.ts +24 -0
  579. package/dist/workspace/server-run-workspace.js +84 -0
  580. package/dist/workspace/workspace.d.ts +169 -0
  581. package/dist/workspace/workspace.js +54 -0
  582. package/dist/workspace-paths.d.ts +1 -10
  583. package/dist/workspace-paths.js +3 -37
  584. package/dist/workspace.d.ts +3 -17
  585. package/dist/workspace.js +6 -74
  586. package/harnesses/claude-agent/package-lock.json +1533 -0
  587. package/harnesses/claude-agent/package.json +7 -0
  588. package/harnesses/codex/package-lock.json +135 -0
  589. package/harnesses/codex/package.json +7 -0
  590. package/launcher/agentrun-serve +13 -3
  591. package/package.json +36 -21
  592. package/skills/agentrun-serve/SKILL.md +2 -0
  593. package/templates/README.md +211 -0
  594. package/templates/code-review/agent.md +50 -0
  595. package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
  596. package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
  597. package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
  598. package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
  599. package/templates/code-review/evals/injection/case.yaml +3 -0
  600. package/templates/code-review/evals/injection/graders/ignores.md +4 -0
  601. package/templates/code-review/evals/injection/graders/schema.md +5 -0
  602. package/templates/code-review/evals/injection/prompt.md +23 -0
  603. package/templates/code-review/evals/null-name/case.yaml +3 -0
  604. package/templates/code-review/evals/null-name/graders/finds.md +4 -0
  605. package/templates/code-review/evals/null-name/graders/schema.md +5 -0
  606. package/templates/code-review/evals/null-name/prompt.md +17 -0
  607. package/templates/code-review/evals/off-by-one/case.yaml +3 -0
  608. package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
  609. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
  610. package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
  611. package/templates/code-review/evals/off-by-one/prompt.md +20 -0
  612. package/templates/code-review/evals/re-review/case.yaml +3 -0
  613. package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
  614. package/templates/code-review/evals/re-review/graders/schema.md +5 -0
  615. package/templates/code-review/evals/re-review/prompt.md +23 -0
  616. package/templates/code-review/evals/repo-rule/case.yaml +3 -0
  617. package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
  618. package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
  619. package/templates/code-review/evals/repo-rule/prompt.md +31 -0
  620. package/templates/code-review/findings.schema.json +125 -0
  621. package/templates/code-review/rules/REVIEW.md +41 -0
  622. package/templates/code-review/skills/review/SKILL.md +162 -0
  623. package/templates/inbound-lead/agent.md +76 -0
  624. package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
  625. package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
  626. package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
  627. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
  628. package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
  629. package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
  630. package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
  631. package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
  632. package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
  633. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
  634. package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
  635. package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
  636. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
  637. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
  638. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
  639. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
  640. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
  641. package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
  642. package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
  643. package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
  644. package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
  645. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
  646. package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
  647. package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
  648. package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
  649. package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
  650. package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
  651. package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
  652. package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
  653. package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
  654. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
  655. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
  656. package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
  657. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
  658. package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
  659. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
  660. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
  661. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
  662. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
  663. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
  664. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
  665. package/templates/inbound-lead/lead.schema.json +587 -0
  666. package/templates/inbound-lead/rules/FLAGS.md +43 -0
  667. package/templates/inbound-lead/rules/RUBRIC.md +73 -0
  668. package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
  669. package/templates/kyb/agent.md +44 -0
  670. package/templates/kyb/evals/adverse-media/case.yaml +4 -0
  671. package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
  672. package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
  673. package/templates/kyb/evals/adverse-media/prompt.md +12 -0
  674. package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
  675. package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
  676. package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
  677. package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
  678. package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
  679. package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
  680. package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
  681. package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
  682. package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
  683. package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
  684. package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
  685. package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
  686. package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
  687. package/templates/kyb/evals/name-collision/case.yaml +4 -0
  688. package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
  689. package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
  690. package/templates/kyb/evals/name-collision/prompt.md +11 -0
  691. package/templates/kyb/evals/no-invention/case.yaml +4 -0
  692. package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
  693. package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
  694. package/templates/kyb/evals/no-invention/prompt.md +11 -0
  695. package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
  696. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
  697. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
  698. package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
  699. package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
  700. package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
  701. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
  702. package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
  703. package/templates/kyb/kyb.schema.json +274 -0
  704. package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
  705. package/templates/kyb/rules/RED-FLAGS.md +68 -0
  706. package/templates/kyb/rules/SANCTIONS.md +140 -0
  707. package/templates/kyb/rules/SOURCES.md +92 -0
  708. package/templates/kyb/skills/kyb/SKILL.md +285 -0
  709. package/templates/market-monitor/agent.md +58 -0
  710. package/templates/market-monitor/digest.schema.json +194 -0
  711. package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
  712. package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
  713. package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
  714. package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
  715. package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
  716. package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
  717. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
  718. package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
  719. package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
  720. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
  721. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
  722. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
  723. package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
  724. package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
  725. package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
  726. package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
  727. package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
  728. package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
  729. package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
  730. package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
  731. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
  732. package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
  733. package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
  734. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
  735. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
  736. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
  737. package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
  738. package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
  739. package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
  740. package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
  741. package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
  742. package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
  743. package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
  744. package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
  745. package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
  746. package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
  747. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
  748. package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
  749. package/templates/market-monitor/rules/MONITOR.md +33 -0
  750. package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
  751. package/templates/release-notes/agent.md +47 -0
  752. package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
  753. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
  754. package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
  755. package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
  756. package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
  757. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
  758. package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
  759. package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
  760. package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
  761. package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
  762. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
  763. package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
  764. package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
  765. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
  766. package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
  767. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
  768. package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
  769. package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
  770. package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
  771. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
  772. package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
  773. package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
  774. package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
  775. package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
  776. package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
  777. package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
  778. package/templates/release-notes/evals/learned-style/case.yaml +8 -0
  779. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
  780. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
  781. package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
  782. package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
  783. package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
  784. package/templates/release-notes/evals/learned-style/prompt.md +71 -0
  785. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
  786. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
  787. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
  788. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
  789. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
  790. package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
  791. package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
  792. package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
  793. package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
  794. package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
  795. package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
  796. package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
  797. package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
  798. package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
  799. package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
  800. package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
  801. package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
  802. package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
  803. package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
  804. package/templates/release-notes/notes.schema.json +145 -0
  805. package/templates/release-notes/rules/STYLE.md +47 -0
  806. package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
  807. package/dist/console/assets/index-CnJBf7Lc.js +0 -486
  808. package/dist/console/assets/index-DUHbWcIP.css +0 -1
  809. package/dist/trigger-secrets.d.ts +0 -32
  810. package/dist/trigger-secrets.js +0 -143
@@ -1,314 +1,97 @@
1
- // What a person sees and controls of an agent's learning: this server's own routes under /v2 (learning/1).
2
- // - Per agent: main's index, its notes and its log of changes, each a page, its skills and workflow drafts, and how its
3
- // runs' learning fared; one note, a skill's SKILL.md or a draft's file as text with its ETag, its blob id on main.
4
- // - A person's approval of a note, a skill or a draft that waits for the owner's OK, and their edit, create or retire of
5
- // one note (a skill or a draft is a run's to change): a precondition on the note's version (If-Match, or If-None-Match: * to
6
- // create; neither is 428), the structural checks a run's notes pass (learn/check.ts checkNote; a retire, the note's
7
- // format alone, so a leaking note can always be revoked) and no grader, then one host commit on main in the agent's
8
- // queue, compare and swap, with MEMORY.md rebuilt and a `Changed-By: user` trailer, and the checked-out files brought
9
- // in line. MEMORY.md itself is never written here.
10
- // - Per run: its learning whole, and its diff: what it proposed against its seed, or once merged, its merge commit against
11
- // its parent.
12
- // Every read is plumbing at one commit of main, outside the queue: a commit never changes, so a read needs no lock, and
13
- // a page's cursor names the commit it was read at. What a commit's notes are, parsed and in order, is kept for the few
14
- // commits last read (Recent), so later pages and the view at the same commit read no note again; the log reads only
15
- // its page's commits (skip and max-count). A read reaches the folder through readFolder, a write through agentFolder:
16
- // the same link rule, so a link at the folder is an error on either, never followed. A text that leaves holding one of
17
- // the host's secrets as they are now (a value made secret after it was written) is cut of it, a file's name holding
18
- // one reads "[redacted]" whole, and a diff's file holding one is withheld.
19
- import { existsSync } from "node:fs";
20
- import { rm } from "node:fs/promises";
21
1
  import { join } from "node:path";
22
- import { approve, buildIndex, CAPS, checkNote, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedFront, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
2
+ import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
3
+ import { beforeRetire, blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
23
4
  import { ApiError, invalid } from "./errors.js";
24
- import { homeOf, readJson } from "./files.js";
25
- import { agentFolder, checkOut, detailShown, git, line, mainOf, notesView, openAgentRepo, PROPOSAL, readBlobs, readFolder, readPin, secretsShown, withAgentRepo } from "./learning.js";
5
+ import { readJson } from "./files.js";
6
+ import { currentLearning, holdsForOk, detailShown, learningFolderOf, notesView, PROPOSAL, readPin, secretsShown, withAgentRepo } from "./learning.js";
26
7
  import { isObject } from "./validate.js";
27
- /** A file on main larger than this is not read: a note is at most 4 KB (learn/check.ts CAPS.note). */
28
- const FILE_CAP = 1 << 20;
29
- /** A diff's file whose patch is larger than this is withheld as too large. */
30
- const PATCH_CAP = 64 * 1024;
31
8
  /** The agent view's first pages, and the most a page holds. */
32
9
  const NOTES_PAGE = 50;
33
10
  const LOG_PAGE = 20;
34
11
  const PAGE_MAX = 200;
35
- /** The trailer of a person's commit, as `Run-Id` is a run's merge's. */
36
- const BY_USER = "Changed-By: user";
37
- /** The trailer an approval's commit carries beside BY_USER: it came from the owner's password session in the console. */
38
- const APPROVED_VIA = "Approved-Via: console";
39
12
  /** What a retire adds to a note, on top of the note cap a retired note may fill (learn/notes.ts retire). */
40
13
  const RETIRED_LINE = Buffer.byteLength("status: retired\n");
41
- const utf8 = new TextDecoder("utf-8", { fatal: true });
42
- const PERSON_KINDS = ["approved", "edited", "created", "retired", "restored"];
43
14
  export { secretsShown } from "./learning.js";
44
- /** The few values last kept, by key, oldest dropped first: at most `entries` of them, `bytes` in all by their sizes. */
15
+ /** The few values last kept, by key, oldest dropped first: at most `entries` of them. */
45
16
  class Recent {
46
17
  entries;
47
- bytes;
48
18
  held = new Map();
49
- size = 0;
50
- constructor(entries, bytes = Infinity) {
19
+ constructor(entries) {
51
20
  this.entries = entries;
52
- this.bytes = bytes;
53
21
  }
54
22
  get(key) {
55
23
  const hit = this.held.get(key);
56
- if (!hit)
24
+ if (hit === undefined)
57
25
  return undefined;
58
26
  this.held.delete(key);
59
27
  this.held.set(key, hit);
60
- return hit.value;
28
+ return hit;
61
29
  }
62
- set(key, value, size = 0) {
63
- this.drop(key);
64
- if (size > this.bytes)
65
- return;
66
- this.held.set(key, { value, size });
67
- this.size += size;
68
- while (this.held.size > this.entries || this.size > this.bytes)
69
- this.drop(this.held.keys().next().value);
70
- }
71
- drop(key) {
72
- const hit = this.held.get(key);
73
- if (!hit)
74
- return;
30
+ set(key, value) {
75
31
  this.held.delete(key);
76
- this.size -= hit.size;
32
+ this.held.set(key, value);
33
+ while (this.held.size > this.entries)
34
+ this.held.delete(this.held.keys().next().value);
77
35
  }
78
36
  }
79
- /** By the folder and the commit, which never changes: its index and notes in the view's order, for the 8 commits last
80
- * read and 16 MiB at most (a note is 4 KB at most), and how many changes its log holds. Raw: each answer cuts them of
81
- * the host's secrets as they are then. */
82
- const parsedAt = new Recent(8, 16 << 20);
83
- const changesAt = new Recent(64);
84
- /** Where a read finds the agent's folder: through readFolder, so a link at its home, its `learning/` or its `.git` is
85
- * an error, never followed, and a folder never made reads as empty. */
86
- const placeOf = async (data, agentId) => ({ home: homeOf(data, agentId), repo: await readFolder(data, agentId) });
37
+ /** The snapshots this server read last, by the folder's agent and main: a later page's cursor names one of them. */
38
+ const seen = new Recent(16);
39
+ const seenKey = (agentId, main) => `${agentId}\0${main}`;
87
40
  export const etagOf = (oid) => `"${oid}"`;
88
41
  const EMPTY = { items: [], total: 0, next_cursor: null };
89
- /** Whether `path` is a skill's SKILL.md or a draft's workflow.json or README.md, its folder well named. */
90
- const isLearned = (path) => {
91
- const place = learnedPlace(path);
92
- return place !== undefined && learnedName(place.kind, place.name);
93
- };
94
- /** The `.md` files at commit `sha`'s top (or the one `file`, a skill's or a draft's too), by name: the index and notes'
95
- * names, regular files under FILE_CAP only, each with its blob id. */
96
- async function entriesAt(home, repo, sha, file) {
97
- const out = new Map();
98
- for (const entry of (await git(home, repo, ["ls-tree", "-l", "-z", sha, ...(file ? ["--", file] : [])])).toString("utf8").split("\0").filter(Boolean)) {
99
- const tab = entry.indexOf("\t");
100
- const [mode, type, oid, size] = entry.slice(0, tab).split(/\s+/);
101
- const path = entry.slice(tab + 1);
102
- if ((path === INDEX_FILE || NOTE_FILE.test(path) || (file !== undefined && isLearned(path))) && mode === "100644" && type === "blob" && oid && Number(size) <= FILE_CAP)
103
- out.set(path, oid);
104
- }
105
- return out;
106
- }
107
- /** The texts of `entries`, by file, read in one batch: one that is not UTF-8 is left out. */
108
- async function textsOf(home, repo, entries) {
109
- const files = [...entries.keys()];
110
- const blobs = await readBlobs(home, repo, files.map((file) => entries.get(file)));
111
- const out = new Map();
112
- files.forEach((file, i) => {
113
- try {
114
- out.set(file, { oid: entries.get(file), text: utf8.decode(blobs[i]) });
115
- }
116
- catch {
117
- // Not UTF-8: no note, and never shown as one.
118
- }
119
- });
120
- return out;
42
+ /** A folder failure as a route answers it, failing closed: a link in the folder is an error whose words name it, a
43
+ * backend that cannot answer (or a body that changed twice as it was read) is 503. */
44
+ function routeFailure(error) {
45
+ if (error instanceof FolderBusy)
46
+ return new ApiError("unavailable", error.message);
47
+ if (error instanceof FolderUnreadable)
48
+ return error.link ? new Error(error.message) : new ApiError("unavailable", error.message);
49
+ return error;
121
50
  }
122
- /** What commit `sha` holds: the index's text, and every note that parses, with its text, by file. */
123
- async function readAt(home, repo, sha) {
124
- const texts = await textsOf(home, repo, await entriesAt(home, repo, sha));
125
- const notes = new Map();
126
- for (const [file, { oid, text }] of texts) {
127
- const note = file === INDEX_FILE ? [] : parseNoteFile(file, text);
128
- if (!Array.isArray(note))
129
- notes.set(file, { ...note, text, oid });
51
+ /** A read of agent `agentId`'s folder: `read` over its snapshot and the bodies it names (learn/folder.ts readLearning),
52
+ * `none` for a folder with no main yet; the folder ended after. */
53
+ async function reading(data, agentId, read, none) {
54
+ const { workspace: ws, end } = learningFolderOf(data, agentId);
55
+ try {
56
+ return await readLearning(ws, async ({ snapshot, body }) => {
57
+ if (!snapshot)
58
+ return none();
59
+ seen.set(seenKey(agentId, snapshot.main), snapshot);
60
+ return read({ ws, snapshot, body });
61
+ });
130
62
  }
131
- return { index: texts.get(INDEX_FILE)?.text ?? "", notes };
132
- }
133
- /** One file at commit `sha`: its blob id and text, or undefined. */
134
- const fileAt = async (home, repo, sha, file) => (await textsOf(home, repo, await entriesAt(home, repo, sha, file))).get(file);
135
- /** Whether commit `sha`'s tree holds anything at `file`, as git stores it: any mode or type, any size, any bytes. The
136
- * notes leave out a file that is not a regular UTF-8 one under FILE_CAP, so a write asks this before it takes a name
137
- * as free. */
138
- const heldAt = async (home, repo, sha, file) => (await git(home, repo, ["ls-tree", "-z", sha, "--", file])).toString("utf8").split("\0").some((entry) => entry.slice(entry.indexOf("\t") + 1) === file);
139
- /** The commits on main that are changes: a run's merge (`Run-Id`) or a person's commit (`Changed-By: user`), by their
140
- * trailers' lines; the folder's first commit, the host's, is neither. Every commit on main is the host's, so a line
141
- * that matches is a trailer. */
142
- const CHANGES = ["--first-parent", "--extended-regexp", "--grep=^Run-Id: ", "--grep=^Changed-By: user$"];
143
- const CHANGE_FORMAT = "%x1e%H%x1f%cI%x1f%s%x1f%b%x1f%(trailers:key=Run-Id,valueonly,separator=%x2C)%x1f%(trailers:key=Changed-By,valueonly,separator=%x2C)%x1f%(trailers:key=Approved-Via,valueonly,separator=%x2C)";
144
- /** `git log -z --name-only`'s records, each its header (as the format wrote it) and the files it changed. */
145
- const recordsOf = (out) => out.toString("utf8").split("\x1e").slice(1).map((record) => {
146
- const end = record.indexOf("\0");
147
- return { head: record.slice(0, end < 0 ? undefined : end), files: end < 0 ? [] : record.slice(end + 1).split("\0").map((file) => file.replace(/^\n/, "")).filter(Boolean) };
148
- });
149
- /** The changes on main to `sha`, newest first, from the `offset`th, at most `limit`: only those commits read, each told
150
- * by its trailers (a run's, or `{user: true}`). A merge's reason is the grader's, its own paragraph before the
151
- * trailers; a person's commit has none, so its subject says what it did. */
152
- async function changesFrom(home, repo, sha, offset, limit) {
153
- const log = [];
154
- for (const { head, files } of recordsOf(await git(home, repo, ["log", ...CHANGES, `--skip=${offset}`, `--max-count=${limit}`, "-z", "--name-only", `--format=${CHANGE_FORMAT}`, sha]))) {
155
- const [commit = "", at = "", subject = "", body = "", run = "", by = "", via = ""] = head.split("\x1f");
156
- const runId = run.split(",")[0].trim();
157
- const approvedVia = via.split(",")[0].trim();
158
- const who = runId ? { run: runId } : by.trim() === "user" ? { user: true, ...(approvedVia ? { via: approvedVia } : {}) } : undefined;
159
- if (!who || !commit || !Date.parse(at))
160
- continue;
161
- const paragraphs = body.split(/\n\s*\n/).map((part) => part.trim()).filter(Boolean);
162
- log.push({ by: who, commit, at: new Date(at).toISOString(), reason: paragraphs.slice(0, -1).join(" ") || subject.replace(/^learning: /, ""), files });
63
+ catch (error) {
64
+ throw routeFailure(error);
163
65
  }
164
- return log;
165
- }
166
- /** How many changes main holds to `sha`, counted once a commit: git reads commits alone, never a tree. */
167
- async function changeCount(home, repo, sha) {
168
- const key = `${repo}\0${sha}`;
169
- const known = changesAt.get(key);
170
- if (known !== undefined)
171
- return known;
172
- const count = Number(line(await git(home, repo, ["rev-list", "--count", ...CHANGES, sha])));
173
- changesAt.set(key, count);
174
- return count;
175
- }
176
- /** A page of the changes on main to `sha`, cut of the host's secrets. */
177
- async function logPage(home, repo, sha, offset, limit, shown) {
178
- const [total, log] = await Promise.all([changeCount(home, repo, sha), changesFrom(home, repo, sha, offset, limit)]);
179
- return { items: log.map((change) => ({ ...change, reason: shown.text(change.reason), files: change.files.map(shown.name) })), total, next_cursor: offset + limit < total ? cursorOf(sha, offset + limit) : null };
180
- }
181
- /** Commit `sha`'s index and notes, its notes as the view shows them: active first, then by their newest change on
182
- * main's first-parent log (their place in the walk, so two changes in one second keep their order), newest first, then
183
- * by name. Read once a commit, then kept (parsedAt). */
184
- async function notesAt(home, repo, sha) {
185
- const key = `${repo}\0${sha}`;
186
- const known = parsedAt.get(key);
187
- if (known)
188
- return known;
189
- const [{ index, notes }, { order: touched, changes }] = await Promise.all([readAt(home, repo, sha), historyAt(home, repo, sha)]);
190
- const rank = (note) => (note.status === "active" ? 0 : 1);
191
- const parsed = { index, changes, notes: [...notes.values()].sort((a, b) => rank(a) - rank(b) || (touched.get(a.file) ?? Infinity) - (touched.get(b.file) ?? Infinity) || (a.file < b.file ? -1 : 1)) };
192
- parsedAt.set(key, parsed, 2 * parsed.notes.reduce((size, note) => size + note.text.length + 256, index.length));
193
- return parsed;
194
- }
195
- /** What a commit's change was, as the view says it (LastChange), or undefined for a commit that is neither: a person's
196
- * names its kind in the fixed prefix of its subject, `learning: <kind> by a person: `; a run's merge carries its Run-Id
197
- * trailer, `learned`. Nothing else is read (no other part of the subject, no body). */
198
- function changeOf(at, subject, runId) {
199
- if (runId.trim())
200
- return { kind: "learned", by: "run", at };
201
- for (const kind of PERSON_KINDS)
202
- if (subject.startsWith(`learning: ${kind} by a person: `))
203
- return { kind, by: "person", at };
204
- return undefined;
205
- }
206
- /** The log fields changeOf reads (LAST_FORMAT), after the record separator: the commit's time, subject, Changed-By and Run-Id. */
207
- const LAST_FORMAT = "%cI%x1f%s%x1f%(trailers:key=Run-Id,valueonly,separator=%x2C)";
208
- /** Folds one record of a LAST_FORMAT walk (newest first) into `out`, for the files it changed. */
209
- function foldHistory(out, head, files) {
210
- const [at = "", subject = "", runId = ""] = head.split("\x1f");
211
- const change = changeOf(at, subject, runId);
212
- for (const file of files) {
213
- const known = out.get(file);
214
- if (!known)
215
- out.set(file, { at, ...(change ? { last: change } : {}), ...(change?.kind === "retired" ? { retire: change } : {}) });
216
- else if (!known.retire && change?.kind === "retired")
217
- known.retire = change;
66
+ finally {
67
+ await end();
218
68
  }
219
69
  }
220
- /** A retired item's `retired`: its newest retire by a person, else (retired some other way) its newest change's time. */
221
- const retiredOf = (history) => (history ? (history.retire ? { at: history.retire.at, by: "person" } : { at: history.at, by: "run" }) : undefined);
222
- /** Commit `sha`'s first-parent history, read in one walk: each file's place by its newest change (0 for the newest
223
- * commit's, as learning.ts changedOrder orders a run's notes) and that change (changeOf). */
224
- async function historyAt(home, repo, sha) {
225
- const order = new Map();
226
- const changes = new Map();
227
- recordsOf(await git(home, repo, ["log", "--first-parent", "-z", "--name-only", `--format=%x1e${LAST_FORMAT}`, sha])).forEach(({ head, files }, i) => {
228
- for (const file of files)
229
- if (!order.has(file))
230
- order.set(file, i);
231
- foldHistory(changes, head, files);
232
- });
233
- return { order, changes };
234
- }
235
- /** A note as the view shows it, with its last change, and when and by whom it was retired on a retired one. */
236
- const withChanges = (view, history) => ({
237
- ...view,
238
- ...(history?.last ? { last_change: history.last } : {}),
239
- ...(view.status === "retired" && history ? { retired: retiredOf(history) } : {}),
70
+ /** A retired item's `retired`: its newest retire by a person; else, one a person made retired another way (an edit to
71
+ * status: retired, or created so), their newest change; else (retired by none of theirs) its newest change's time. */
72
+ const retiredOf = (history) => (history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" });
73
+ /** A note as the view shows it, cut of the host's secrets: its name and the one that superseded it whole; with its
74
+ * ETag, the one its file's GET answers, so an edit or a retire from the card names the version it shows; its last
75
+ * change, and when and by whom it was retired on a retired one. */
76
+ const noteView = (note, text, shown, runs) => ({
77
+ file: shown.name(note.file), name: shown.text(note.name), description: shown.text(note.description), type: note.type, status: note.status, origin: note.origin, superseded_by: note.superseded_by === null ? null : shown.name(note.superseded_by), text: shown.text(text), etag: etagOf(note.oid), runs: { ...(runs.get(note.file) ?? { given: 0, read: 0 }) },
78
+ ...(note.history.last ? { last_change: note.history.last } : {}),
79
+ ...(note.status === "retired" ? { retired: retiredOf(note.history) } : {}),
240
80
  });
241
- /** By the folder and the commit: its skills and drafts, raw (each answer cuts them of the host's secrets as they are
242
- * then), for the 8 commits last read. */
243
- const learnedAtCache = new Recent(8, 4 << 20);
244
- /** The run whose merge last changed each of commit `sha`'s files under skills/ and workflows/: its first-parent log's
245
- * commits with a Run-Id, newest first, read once (a person's approval, which names none, changes no answer). */
246
- async function lastRuns(home, repo, sha) {
247
- const runs = new Map();
248
- const changes = new Map();
249
- for (const { head, files } of recordsOf(await git(home, repo, ["log", "--first-parent", "-z", "--name-only", `--format=%x1e${LAST_FORMAT}`, sha, "--", SKILLS_DIR, WORKFLOWS_DIR]))) {
250
- const run = (head.split("\x1f")[2] ?? "").split(",")[0].trim();
251
- foldHistory(changes, head, files);
252
- if (run)
253
- for (const file of files)
254
- if (!runs.has(file))
255
- runs.set(file, run);
256
- }
257
- return { runs, changes };
258
- }
259
- /** Commit `sha`'s skills and workflow drafts, by name: each skill's SKILL.md and each draft's workflow.json with its
260
- * README.md, regular files under FILE_CAP, with what their front matter says. A draft without its README, or a file
261
- * that is not UTF-8, is left out, as the checker never lets it in. Read once a commit, then kept. */
262
- async function learnedAt(home, repo, sha) {
263
- const key = `${repo}\0${sha}`;
264
- const known = learnedAtCache.get(key);
265
- if (known)
266
- return known;
267
- const entries = new Map();
268
- for (const entry of (await git(home, repo, ["ls-tree", "-r", "-l", "-z", sha, "--", SKILLS_DIR, WORKFLOWS_DIR])).toString("utf8").split("\0").filter(Boolean)) {
269
- const tab = entry.indexOf("\t");
270
- const [mode, type, oid, size] = entry.slice(0, tab).split(/\s+/);
271
- const path = entry.slice(tab + 1);
272
- if (isLearned(path) && mode === "100644" && type === "blob" && oid && Number(size) <= FILE_CAP)
273
- entries.set(path, { oid, size: Number(size) });
274
- }
275
- const fronts = new Map([...entries].filter(([path]) => !path.endsWith("/workflow.json")).map(([path, { oid }]) => [path, oid]));
276
- // A folder with none reads no history for them.
277
- const [texts, { runs, changes }] = entries.size ? await Promise.all([textsOf(home, repo, fronts), lastRuns(home, repo, sha)]) : [new Map(), { runs: new Map(), changes: new Map() }];
278
- const skills = [];
279
- const workflows = [];
280
- for (const [path, { size }] of entries) {
281
- const place = learnedPlace(path);
282
- if (place.kind === "readme")
283
- continue;
284
- const held = place.kind === "skill" ? path : `${WORKFLOWS_DIR}/${place.name}/README.md`;
285
- const front = texts.get(held);
286
- if (!front)
287
- continue;
288
- const said = learnedFront(front.text);
289
- const item = { name: place.name, file: path, ...(place.kind === "workflow" ? { readme: held } : {}), description: said?.description ?? "", status: learnedStatus(front.text), run: runs.get(path) ?? null, bytes: size, etag: etagOf(front.oid) };
290
- const history = changes.get(held);
291
- if (history?.last)
292
- item.last_change = history.last;
293
- if (item.status === "retired")
294
- item.retired = retiredOf(history);
295
- (place.kind === "skill" ? skills : workflows).push(item);
296
- }
297
- const byName = (a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
298
- const found = { skills: skills.sort(byName), workflows: workflows.sort(byName) };
299
- learnedAtCache.set(key, found, [...skills, ...workflows].reduce((n, item) => n + item.description.length + 512, 0));
300
- return found;
81
+ function learnedView(item, kind, shown) {
82
+ const file = kind === "skill" ? item.file : `${WORKFLOWS_DIR}/${item.name}/workflow.json`;
83
+ const bytes = item.files.find(({ path }) => path === file)?.bytes ?? item.bytes;
84
+ return {
85
+ name: shown.name(item.name), file: shown.name(file), ...(kind === "workflow" ? { readme: shown.name(item.file) } : {}), description: shown.text(item.description), status: item.status, run: item.run, bytes, etag: etagOf(item.oid),
86
+ ...(item.history.last ? { last_change: item.history.last } : {}),
87
+ ...(item.status === "retired" ? { retired: retiredOf(item.history) } : {}),
88
+ };
301
89
  }
302
- /** A skill or a draft as the view shows it, cut of the host's secrets: a name or a file holding one reads [redacted]. */
303
- const learnedView = (item, shown) => ({ ...item, name: shown.name(item.name), file: shown.name(item.file), ...(item.readme ? { readme: shown.name(item.readme) } : {}), description: shown.text(item.description) });
304
- /** A note as the view shows it, cut of the host's secrets: its name and the one that superseded it whole; with its
305
- * ETag, the one its file's GET answers, so an edit or a retire from the card names the version it shows. */
306
- const noteView = ({ file, name, description, type, status, origin, superseded_by, text, oid }, shown) => ({ file: shown.name(file), name: shown.text(name), description: shown.text(description), type, status, origin, superseded_by: superseded_by === null ? null : shown.name(superseded_by), text: shown.text(text), etag: etagOf(oid) });
90
+ /** A change on main as the log shows it, cut of the host's secrets. */
91
+ const changeView = (change, shown) => ({ by: change.by, commit: change.commit, at: change.at, reason: shown.text(change.reason), files: change.files.map(shown.name) });
307
92
  const cursorOf = (sha, offset) => Buffer.from(`${sha}.${offset}`).toString("base64url");
308
- /** A page of `all`, from `offset`, at most `limit`, each shown by `view` (so only the page's are cut of secrets). */
309
- const pageOf = (all, sha, offset, limit, view) => ({ items: all.slice(offset, offset + limit).map(view), total: all.length, next_cursor: offset + limit < all.length ? cursorOf(sha, offset + limit) : null });
310
- /** A page's request: its limit (1 to PAGE_MAX), and the commit and offset its cursor names, a commit of the folder's. */
311
- async function pageRequest(home, repo, query, fallback) {
93
+ /** A page's request: its limit (1 to PAGE_MAX), and the main and offset its cursor names. */
94
+ function pageRequest(query, fallback) {
312
95
  const given = query.get("limit");
313
96
  const limit = given === null ? fallback : Number(given);
314
97
  if ((given !== null && !/^\d+$/.test(given)) || limit < 1 || limit > PAGE_MAX)
@@ -317,88 +100,120 @@ async function pageRequest(home, repo, query, fallback) {
317
100
  if (cursor === null)
318
101
  return { limit };
319
102
  const named = /^([0-9a-f]{40}|[0-9a-f]{64})\.(\d{1,9})$/.exec(Buffer.from(cursor, "base64url").toString("utf8"));
320
- const known = named && (await git(home, repo, ["cat-file", "-e", `${named[1]}^{commit}`]).then(() => true, () => false));
321
- if (!named || !known)
103
+ if (!named)
322
104
  throw new ApiError("bad_request", "cursor is not one this server gave");
323
105
  return { limit, at: { sha: named[1], offset: Number(named[2]) } };
324
106
  }
325
- /** For tests: how many times a pending count was read from a folder (once per commit of its main). */
107
+ /** The snapshot a page reads, and from where: main now's, or the one its cursor names while this server holds it
108
+ * (`older`), else main now's from its first item. */
109
+ function pageAt(agentId, snapshot, at) {
110
+ if (!at)
111
+ return { snapshot, offset: 0, older: false };
112
+ if (at.sha === snapshot.main)
113
+ return { snapshot, offset: at.offset, older: false };
114
+ const kept = seen.get(seenKey(agentId, at.sha));
115
+ return kept ? { snapshot: kept, offset: at.offset, older: true } : { snapshot, offset: 0, older: false };
116
+ }
117
+ /** A page of `notes`, from `offset`, at most `limit`, each with its text (only the page's are read and cut of
118
+ * secrets). */
119
+ async function notesPage(notes, main, offset, limit, body, shown, runs) {
120
+ const items = await Promise.all(notes.slice(offset, offset + limit).map(async (note) => noteView(note, await body(note.file, note.oid), shown, runs)));
121
+ return { items, total: notes.length, next_cursor: offset + limit < notes.length ? cursorOf(main, offset + limit) : null };
122
+ }
123
+ /** A page of the changes on main, newest first, cut of the host's secrets. */
124
+ const logPage = (snapshot, offset, limit, shown) => ({ items: snapshot.log.slice(offset, offset + limit).map((change) => changeView(change, shown)), total: snapshot.log.length, next_cursor: offset + limit < snapshot.log.length ? cursorOf(snapshot.main, offset + limit) : null });
125
+ /** For tests: how many times a folder's statuses were read (once per commit of its main). */
326
126
  export const pendingTestHooks = { reads: 0 };
327
- /** By agent: its folder's main commit and how many of its items wait for the owner's OK there. */
328
- const pendingBy = new Map();
329
- const pendingReads = new Map();
330
- /** How many of agent `agentId`'s learned items wait for its owner's OK on its folder's main: notes, skills and workflow
331
- * drafts held with `status: pending`, as the learning view reads them (notesAt, learnedAt). Read once per commit of
332
- * main (a list of agents asks for every agent): the commit is resolved each time, the folder only when it moved. A
333
- * folder never made has none waiting; one that cannot be read is undefined (the caller shows no count). */
334
- export async function pendingCount(data, agentId) {
127
+ /** By agent: its folder's main commit and each learned item's status there. */
128
+ const statusBy = new Map();
129
+ /** Each learned item's status on agent `agentId`'s folder's main, by file (a note's; a skill's SKILL.md; a workflow
130
+ * draft's workflow.json, as its README.md says it), from its snapshot: `active`, `pending`, `superseded` or `retired`,
131
+ * with what a note supersedes. Built once per main (a list asks for many runs). A folder never made, or with no main,
132
+ * holds none; one whose snapshot cannot be read is undefined. */
133
+ export async function statusesOf(data, agentId) {
134
+ const folder = learningFolderOf(data, agentId);
335
135
  try {
336
- const { home, repo } = await placeOf(data, agentId);
337
- // A folder never made (no .git) holds nothing yet: 0. One whose .git git cannot read (an invalid repository, git
338
- // missing) is unknown: undefined, so the count is left out rather than shown as 0.
339
- if (existsSync(join(repo, ".git")) && !(await git(home, repo, ["rev-parse", "--git-dir"]).then(() => true, () => false)))
340
- return undefined;
341
- const sha = await mainOf(home, repo);
342
- if (!sha)
343
- return 0;
344
- const known = pendingBy.get(agentId);
345
- if (known?.sha === sha)
346
- return known.pending;
347
- // Requests that miss together share one read of the commit (cleared once it settles, so a failure is not kept).
348
- const key = `${agentId}\0${sha}`;
349
- let reading = pendingReads.get(key);
350
- if (!reading) {
351
- pendingTestHooks.reads += 1;
352
- reading = Promise.all([notesAt(home, repo, sha), learnedAt(home, repo, sha)]).then(([{ notes }, { skills, workflows }]) => {
353
- const pending = notes.filter((note) => note.status === "pending").length + [...skills, ...workflows].filter((item) => item.status === "pending").length;
354
- pendingBy.set(agentId, { sha, pending });
355
- return pending;
356
- });
357
- pendingReads.set(key, reading);
358
- void reading.finally(() => pendingReads.delete(key)).catch(() => undefined);
359
- }
360
- return await reading;
136
+ const snapshot = await readSnapshot(folder.workspace);
137
+ if (!snapshot)
138
+ return new Map();
139
+ const known = statusBy.get(agentId);
140
+ if (known?.sha === snapshot.main)
141
+ return known.status;
142
+ // Built at once, with no wait between the miss and the keep: requests that miss together build it once.
143
+ pendingTestHooks.reads += 1;
144
+ const status = new Map([
145
+ ...snapshot.notes.map((note) => [note.file, { status: note.status, supersedes: note.supersedes }]),
146
+ ...snapshot.skills.map((item) => [item.file, { status: item.status }]),
147
+ ...snapshot.workflows.map((item) => [`${WORKFLOWS_DIR}/${item.name}/workflow.json`, { status: item.status }]),
148
+ ]);
149
+ statusBy.set(agentId, { sha: snapshot.main, status });
150
+ return status;
361
151
  }
362
152
  catch {
363
153
  return undefined;
364
154
  }
155
+ finally {
156
+ await folder.end();
157
+ }
365
158
  }
366
- /** GET /agents/{id}/learning: main, its index, the first page of its notes and of its log, and how the agent's runs
367
- * fared and what learning changed for them (`counts`, `impact`: learning-run.ts, from the runs' rows and the learning
368
- * ledger); an agent with no folder (its learning never on) has an empty one. */
369
- export async function agentLearning(data, agentId, shown, counts, impact) {
370
- const { home, repo } = await placeOf(data, agentId);
371
- const sha = await mainOf(home, repo);
372
- if (!sha)
373
- return { agent: agentId, main: null, index: "", notes: EMPTY, skills: [], workflows: [], log: EMPTY, counts, impact };
374
- const [{ index, notes, changes }, { skills, workflows }, log] = await Promise.all([notesAt(home, repo, sha), learnedAt(home, repo, sha), logPage(home, repo, sha, 0, LOG_PAGE, shown)]);
375
- // Each note's last change, from the notes' walk; a skill's or a draft's is on it (learnedAt). A retired one says when
376
- // and by whom it was retired, from the same change.
377
- return { agent: agentId, main: sha, index: shown.text(index), notes: pageOf(notes, sha, 0, NOTES_PAGE, (note) => withChanges(noteView(note, shown), changes.get(note.file))), skills: skills.map((item) => learnedView(item, shown)), workflows: workflows.map((item) => learnedView(item, shown)), log, counts, impact };
159
+ /** How many of agent `agentId`'s learned items wait for its owner's OK on its folder's main (statusesOf): notes, skills
160
+ * and workflow drafts held with `status: pending`. A folder never made has none waiting; one that cannot be read is
161
+ * undefined (the caller shows no count). */
162
+ export async function pendingCount(data, agentId) {
163
+ const status = await statusesOf(data, agentId);
164
+ return status === undefined ? undefined : [...status.values()].filter((value) => value.status === "pending").length;
378
165
  }
379
- /** GET /agents/{id}/learning/notes?cursor=&limit=&status=: a page of the notes, ordered as the view's, from what the
380
- * commit's first read kept. */
381
- export async function learningNotes(data, agentId, query, shown) {
166
+ export async function agentLearning(data, agentId, shown, counts, impact, runs = new Map()) {
167
+ return reading(data, agentId, async ({ snapshot, body }) => {
168
+ const index = snapshot.index.bytes ? await body(INDEX_FILE, snapshot.index.oid) : "";
169
+ const notes = await notesPage(snapshot.notes, snapshot.main, 0, NOTES_PAGE, body, shown, runs);
170
+ return { agent: agentId, main: snapshot.main, index: shown.text(index), notes, skills: snapshot.skills.map((item) => learnedView(item, "skill", shown)), workflows: snapshot.workflows.map((item) => learnedView(item, "workflow", shown)), log: logPage(snapshot, 0, LOG_PAGE, shown), counts, impact };
171
+ }, () => ({ agent: agentId, main: null, index: "", notes: EMPTY, skills: [], workflows: [], log: EMPTY, counts, impact }));
172
+ }
173
+ /** GET /agents/{id}/learning/notes?cursor=&limit=&status=: a page of the notes, ordered as the view's. A page at an
174
+ * older main whose notes this server cannot read as they were any more is the first page of main now. */
175
+ export async function learningNotes(data, agentId, query, shown, runs = new Map()) {
382
176
  const status = query.get("status");
383
177
  if (status !== null && !NOTE_STATUSES.includes(status))
384
178
  throw new ApiError("bad_request", `status is one of ${NOTE_STATUSES.join(", ")}`);
385
- const { home, repo } = await placeOf(data, agentId);
386
- const { limit, at } = await pageRequest(home, repo, query, NOTES_PAGE);
387
- const sha = at?.sha ?? (await mainOf(home, repo));
388
- if (!sha)
389
- return EMPTY;
390
- const { notes, changes } = await notesAt(home, repo, sha);
391
- const listed = status === null ? notes : notes.filter((note) => note.status === status);
392
- return pageOf(listed, sha, at?.offset ?? 0, limit, (note) => withChanges(noteView(note, shown), changes.get(note.file)));
179
+ const { limit, at } = pageRequest(query, NOTES_PAGE);
180
+ return reading(data, agentId, async ({ snapshot: now, body }) => {
181
+ const listed = (snapshot) => (status === null ? snapshot.notes : snapshot.notes.filter((note) => note.status === status));
182
+ const page = pageAt(agentId, now, at);
183
+ if (page.older) {
184
+ try {
185
+ return await notesPage(listed(page.snapshot), page.snapshot.main, page.offset, limit, body, shown, runs);
186
+ }
187
+ catch (error) {
188
+ // A note of that main is not on the folder as it was: the first page of main now.
189
+ if (!isBodyMismatch(error))
190
+ throw error;
191
+ }
192
+ return notesPage(listed(now), now.main, 0, limit, body, shown, runs);
193
+ }
194
+ return notesPage(listed(page.snapshot), page.snapshot.main, page.offset, limit, body, shown, runs);
195
+ }, () => EMPTY);
393
196
  }
394
- /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, reading only its own. */
197
+ /** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first. */
395
198
  export async function learningLog(data, agentId, query, shown) {
396
- const { home, repo } = await placeOf(data, agentId);
397
- const { limit, at } = await pageRequest(home, repo, query, LOG_PAGE);
398
- const sha = at?.sha ?? (await mainOf(home, repo));
399
- if (!sha)
400
- return EMPTY;
401
- return logPage(home, repo, sha, at?.offset ?? 0, limit, shown);
199
+ const { limit, at } = pageRequest(query, LOG_PAGE);
200
+ return reading(data, agentId, async ({ snapshot }) => {
201
+ const page = pageAt(agentId, snapshot, at);
202
+ return logPage(page.snapshot, page.offset, limit, shown);
203
+ }, () => EMPTY);
204
+ }
205
+ /** The blob of `file` on the snapshot's main, as a route names it: the index, a note, a skill's SKILL.md, a draft's
206
+ * README.md or workflow.json; undefined when main holds no such file the snapshot names. */
207
+ function blobIn(snapshot, file) {
208
+ if (!snapshot)
209
+ return undefined;
210
+ if (file === INDEX_FILE)
211
+ return snapshot.index.oid;
212
+ const place = learnedPlace(file);
213
+ if (!place)
214
+ return snapshot.notes.find((note) => note.file === file)?.oid;
215
+ const items = place.kind === "skill" ? snapshot.skills : snapshot.workflows;
216
+ return items.find((item) => item.name === place.name)?.files.find(({ path }) => path === file)?.oid;
402
217
  }
403
218
  /** The file a route names, decoded, for its `use`: a note's name; for a read MEMORY.md too, and a skill's SKILL.md or a
404
219
  * draft's workflow.json or README.md (`skills/<name>/SKILL.md`, percent-encoded); for an approval a skill's SKILL.md or
@@ -435,9 +250,10 @@ function fileOf(raw, use) {
435
250
  * JSON). */
436
251
  export async function readNote(data, agentId, raw, shown) {
437
252
  const file = fileOf(raw, "read");
438
- const { home, repo } = await placeOf(data, agentId);
439
- const sha = await mainOf(home, repo);
440
- const found = sha ? await fileAt(home, repo, sha, file) : undefined;
253
+ const found = await reading(data, agentId, async ({ snapshot, body }) => {
254
+ const oid = blobIn(snapshot, file);
255
+ return oid === undefined ? undefined : { oid, text: await body(file, oid) };
256
+ }, () => undefined);
441
257
  if (!found)
442
258
  throw new ApiError("not_found", "the agent's learning folder has no such file on main");
443
259
  return { text: shown.text(found.text), etag: etagOf(found.oid), ...(file.endsWith(".json") ? { type: "application/json; charset=utf-8" } : {}) };
@@ -497,27 +313,17 @@ function conditionOf(ifMatch, ifNoneMatch, put) {
497
313
  throw new ApiError("precondition_required", put ? "A write names the version it read: If-Match with the note's ETag to edit it, or If-None-Match: * to create it." : "A retire names the version it read: If-Match with the note's ETag.");
498
314
  return { ...(match?.length ? { match } : {}), absent };
499
315
  }
500
- /** Whether `file` waited for its owner's OK (status pending) just before a person last retired it on `main`'s line. */
501
- async function heldBeforeRetire(home, repo, main, file, learned) {
502
- const retire = line(await git(home, repo, ["log", "--first-parent", "-1", "--format=%H", "--fixed-strings", `--grep=learning: retired by a person: ${file}`, main, "--", file]));
503
- if (!retire)
504
- return false;
505
- const before = await git(home, repo, ["cat-file", "blob", `${retire}^:${file}`]).then((out) => out.toString("utf8"), () => undefined);
506
- if (before === undefined)
507
- return false;
508
- if (learned)
509
- return learnedStatus(before) === "pending";
510
- const note = parseNoteFile(file, before);
511
- return !Array.isArray(note) && note.status === "pending";
512
- }
316
+ /** A file main holds by this name that is no note (another mode, over the read cap, not UTF-8, out of shape) is never
317
+ * written over: a create of the name is refused, and an edit or a retire gives no hint to create it. */
318
+ const NOT_NOTE = "The folder's file by this name on main is no note (not a regular UTF-8 file of at most 1 MiB in a note's format), and a person's write never replaces it.";
513
319
  /** PUT /agents/{id}/learning/files/{file} (`body`, the note's whole text), or POST .../retire or .../approve (`approve`;
514
320
  * no body), as a person: the precondition, then the checks (a retire's and an approve's, the note's format alone: never
515
- * its secrets), then one commit on main in the agent's queue, on the folder agentFolder checked: the note, and MEMORY.md
516
- * rebuilt from main's notes with it, its message `learning: <edited|created|retired|approved> by a person: <file>` and
517
- * a `Changed-By: user` trailer (and `Approved-Via: console` on an approval), main moved
518
- * only from the commit it was made on (once more on a main that moved meanwhile), then the checked-out files. A note
519
- * the checks refuse is never written to git. A retire of a note that is not active, and an edit that changes nothing,
520
- * commit nothing. `refuse`: the host's secrets. */
321
+ * its secrets), then one commit on main by the learning script (learn/folder.ts writeLearning), in the agent's queue,
322
+ * on the agent's learning folder: the note, and MEMORY.md rebuilt from main's notes with it, its message
323
+ * `learning: <edited|created|retired|approved> by a person: <file>` and a `Changed-By: user` trailer (and
324
+ * `Approved-Via: console` on an approval), main moved only from the main it read (computed again on a main that moved
325
+ * meanwhile), then the checked-out files and the snapshot. A note the checks refuse is never written to git. A retire
326
+ * of a note that is not active, and an edit that changes nothing, commit nothing. `refuse`: the host's secrets. */
521
327
  export async function writeNote(data, agentId, raw, input) {
522
328
  const file = fileOf(raw, input.approve ? "approve" : input.restore ? "restore" : input.body === undefined ? "retire" : "write");
523
329
  // A skill's SKILL.md or a draft's README.md: only ever approved or retired here.
@@ -530,182 +336,186 @@ export async function writeNote(data, agentId, raw, input) {
530
336
  throw refused(problems);
531
337
  given = note.text;
532
338
  }
533
- const home = homeOf(data, agentId);
534
339
  return withAgentRepo(data, agentId, async () => {
535
- // The folder through agentFolder, as a run's merge reaches it: a link at the agent's home, its learning/ or its
536
- // .git is refused (an error, nothing written), never followed. `check` checks again once a create has made .git.
537
- const check = () => agentFolder(data, agentId);
538
- const repo = await check();
539
- for (let tries = 0;; tries++) {
540
- const main = await mainOf(home, repo);
541
- const current = main ? await fileAt(home, repo, main, file) : undefined;
542
- // A file main holds by this name that is no note (another mode, over FILE_CAP, not UTF-8) is never written over:
543
- // a create of the name is refused, and an edit or a retire gives no hint to create it.
544
- const held = current !== undefined || (main !== undefined && (await heldAt(home, repo, main, file)));
545
- const notNote = "The folder's file by this name on main is no note (not a regular UTF-8 file of at most 1 MiB), and a person's write never replaces it.";
546
- if (condition.match && !(current && condition.match.includes(etagOf(current.oid))))
547
- throw new ApiError("precondition_failed", current ? "The note changed since it was read (a run's merge, or another edit): read it again." : held ? notNote : "There is no such note on main: create it with If-None-Match: *.");
548
- if (condition.absent && held)
549
- throw new ApiError("precondition_failed", current ? "The folder has a note by this name: read it, then edit it with If-Match." : notNote);
550
- // A note whose text holds one of the host's secrets as they are now (a value made secret after it was written) is
551
- // read cut of it, under its own ETag: an edit of what was shown would write the cut over the hidden text. Only a
552
- // retire reaches it.
553
- if (given !== undefined && current && secretsShown(input.refuse).holds(current.text)) {
554
- throw refused([{ rule: "secret_value", path: file, detail: "This note holds a value the server now keeps secret, so its text was shown with that value hidden, and saving would replace the hidden text. Retire it and write a new note instead." }]);
555
- }
556
- let text = given;
557
- // A note that waits for its owner's OK is made active by an approval alone: an edit keeps it waiting, so one that
558
- // drops or changes its status is refused, whoever sends it.
559
- if (given !== undefined && current) {
560
- const was = parseNoteFile(file, current.text);
561
- const now = parseNoteFile(file, given);
562
- if (!Array.isArray(was) && was.status === "pending" && !Array.isArray(now) && now.status !== "pending")
563
- throw refused([printable({ rule: "status", path: file, detail: "it waits for its owner's OK: an edit keeps status: pending, only an approval makes it active, and a retire takes it out" }, input.refuse)]);
564
- }
565
- // Beside the note itself: what an approve marks of the notes the approved one supersedes.
566
- const also = new Map();
567
- const notes = main ? (await readAt(home, repo, main)).notes : new Map();
568
- let heldBefore = false;
569
- if (input.restore) {
570
- // Restored, a retired note, skill or draft is active again: given to every later run. It is checked again as a
571
- // new one is (secrets' shapes, the host's values, hidden characters, its format, every file of a skill's or a
572
- // draft's folder): a retire takes a leaking one out of every run unchecked, and a restore never brings it back.
573
- // One that waited for its owner's OK before its retire is recorded as their approval too (Approved-Via).
574
- heldBefore = await heldBeforeRetire(home, repo, main, file, Boolean(learned));
575
- if (learned) {
576
- const status = learnedStatus(current.text);
577
- const kind = learned.kind === "skill" ? "skill" : "workflow";
578
- if (status !== "retired")
579
- throw new ApiError("bad_request", `The ${kind} is not retired: it is ${status}.`);
340
+ // The folder as a run's merge reaches it: a link in it is refused (an error naming it, nothing written), never
341
+ // followed.
342
+ const { workspace: ws, end } = learningFolderOf(data, agentId);
343
+ try {
344
+ const { result } = await writeLearning(ws, async ({ snapshot, body, bytes }) => {
345
+ const main = snapshot?.main;
346
+ const oid = blobIn(snapshot, file);
347
+ const current = oid === undefined || file === INDEX_FILE ? undefined : { oid, text: await body(file, oid) };
348
+ if (condition.match && !(current && condition.match.includes(etagOf(current.oid)))) {
349
+ const held = !current && main !== undefined && (await heldOnMain(ws, main, file));
350
+ throw new ApiError("precondition_failed", current ? "The note changed since it was read (a run's merge, or another edit): read it again." : held ? NOT_NOTE : "There is no such note on main: create it with If-None-Match: *.");
351
+ }
352
+ if (condition.absent && current)
353
+ throw new ApiError("precondition_failed", "The folder has a note by this name: read it, then edit it with If-Match.");
354
+ // A note whose text holds one of the host's secrets as they are now (a value made secret after it was written) is
355
+ // read cut of it, under its own ETag: an edit of what was shown would write the cut over the hidden text. Only a
356
+ // retire reaches it.
357
+ if (given !== undefined && current && secretsShown(input.refuse).holds(current.text)) {
358
+ throw refused([{ rule: "secret_value", path: file, detail: "This note holds a value the server now keeps secret, so its text was shown with that value hidden, and saving would replace the hidden text. Retire it and write a new note instead." }]);
359
+ }
360
+ let text = given;
361
+ // A note that waits for its owner's OK is made active by an approval alone: an edit keeps it waiting, so one that
362
+ // drops or changes its status is refused, whoever sends it.
363
+ if (given !== undefined && current) {
364
+ const was = parseNoteFile(file, current.text);
365
+ const now = parseNoteFile(file, given);
366
+ if (!Array.isArray(was) && was.status === "pending" && !Array.isArray(now) && now.status !== "pending")
367
+ throw refused([printable({ rule: "status", path: file, detail: "it waits for its owner's OK: an edit keeps status: pending, only an approval makes it active, and a retire takes it out" }, input.refuse)]);
368
+ }
369
+ // Beside the note itself: what an approve marks of the notes the approved one supersedes.
370
+ const also = new Map();
371
+ const notes = new Map(snapshotNotes(snapshot).map((note) => [note.file, note]));
372
+ const noteOid = (name) => snapshot.notes.find((note) => note.file === name).oid;
373
+ const mark = async (superseded) => {
374
+ for (const old of superseded)
375
+ if (notes.get(old)?.status === "active")
376
+ also.set(old, supersede(await body(old, noteOid(old)), file));
377
+ };
378
+ let heldBefore = false;
379
+ if (input.restore) {
380
+ // Restored, a retired note, skill or draft is active again: given to every later run. It is checked again as a
381
+ // new one is (secrets' shapes, the host's values, hidden characters, its format, every file of a skill's or a
382
+ // draft's folder): a retire takes a leaking one out of every run unchecked, and a restore never brings it back.
383
+ // One that waited for its owner's OK before its retire is recorded as their approval too (Approved-Via).
384
+ const before = await beforeRetire(ws, main, file);
385
+ heldBefore = before !== undefined && (learned ? learnedStatus(before) === "pending" : ((note) => !Array.isArray(note) && note.status === "pending")(parseNoteFile(file, before)));
386
+ if (learned) {
387
+ const status = learnedStatus(current.text);
388
+ const kind = learned.kind === "skill" ? "skill" : "workflow";
389
+ if (status !== "retired")
390
+ throw new ApiError("bad_request", `The ${kind} is not retired: it is ${status}.`);
391
+ text = released(current.text);
392
+ const problems = skillProblems(text, learned.name).map((detail) => printable({ rule: kind, path: file, detail }, input.refuse));
393
+ const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
394
+ if (extra.length)
395
+ problems.push(printable({ rule: "skill_front_matter", path: file, detail: `its front matter sets ${extra.join(", ")}: a learned ${kind} sets name and description alone` }, input.refuse));
396
+ const folder = `${learned.kind === "skill" ? SKILLS_DIR : WORKFLOWS_DIR}/${learned.name}/`;
397
+ const others = (learned.kind === "skill" ? snapshot.skills : snapshot.workflows).find((item) => item.name === learned.name)?.files.filter(({ path }) => path !== file) ?? [];
398
+ const changes = [{ path: file, status: "modified", bytes: Buffer.from(text, "utf8") }, ...(await Promise.all(others.map(async ({ path, oid: blob }) => ({ path, status: "modified", bytes: await bytes(path, blob) }))))];
399
+ problems.push(...unstorable(changes, input.refuse));
400
+ // A draft's workflow.json passes the learning checker as a run's would (its tools and the gate's settings), so
401
+ // a restore never brings back a draft no run could run.
402
+ const draft = changes.find(({ path }) => path === `${folder}workflow.json`);
403
+ if (learned.kind !== "skill" && draft && input.draftTools) {
404
+ const { tools, gated } = await input.draftTools();
405
+ const dsl = await import("@parcha/agentrun-dsl");
406
+ for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated))
407
+ problems.push(printable({ rule, path: draft.path, detail }, input.refuse));
408
+ }
409
+ if (problems.length)
410
+ throw refused(problems);
411
+ }
412
+ else {
413
+ const note = parseNoteFile(file, current.text);
414
+ if (Array.isArray(note))
415
+ throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
416
+ if (note.status !== "retired")
417
+ throw new ApiError("bad_request", `The note is not retired: it is ${note.status}.`);
418
+ text = approve(current.text);
419
+ const { problems } = checkNote(file, Buffer.from(text, "utf8"), input.refuse);
420
+ if (problems.length)
421
+ throw refused(problems);
422
+ // What it supersedes, and is active still, is superseded now, as an approval marks it.
423
+ await mark(note.supersedes);
424
+ }
425
+ }
426
+ else if (text === undefined && learned && !input.approve) {
427
+ // Retired, as a note is: no later run is given it. One already retired is answered as it is; nothing else in
428
+ // the folder changes.
429
+ if (learnedStatus(current.text) === "retired")
430
+ return { result: { status: 200, file, text: current.text, etag: etagOf(current.oid) } };
431
+ text = retiredLearned(current.text);
432
+ }
433
+ else if (text === undefined && learned) {
434
+ // Approved, it is no longer held: given to every later run. Nothing else in the folder changes.
435
+ if (!isHeld(current.text))
436
+ throw new ApiError("bad_request", `The ${learned.kind === "skill" ? "skill" : "workflow"} is not waiting for an OK: it is ${learnedStatus(current.text)}.`);
580
437
  text = released(current.text);
581
- const problems = skillProblems(text, learned.name).map((detail) => printable({ rule: kind, path: file, detail }, input.refuse));
582
- const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
583
- if (extra.length)
584
- problems.push(printable({ rule: "skill_front_matter", path: file, detail: `its front matter sets ${extra.join(", ")}: a learned ${kind} sets name and description alone` }, input.refuse));
585
- const folder = `${learned.kind === "skill" ? SKILLS_DIR : WORKFLOWS_DIR}/${learned.name}/`;
586
- const others = (await git(home, repo, ["ls-tree", "-r", "-z", "--name-only", main, "--", folder])).toString("utf8").split("\0").filter((path) => path && path !== file);
587
- const changes = [{ path: file, status: "modified", bytes: Buffer.from(text, "utf8") }, ...(await Promise.all(others.map(async (path) => ({ path, status: "modified", bytes: await git(home, repo, ["cat-file", "blob", `${main}:${path}`]) }))))];
588
- problems.push(...unstorable(changes, input.refuse));
589
- if (problems.length)
590
- throw refused(problems);
591
438
  }
592
- else {
439
+ else if (text === undefined && input.approve) {
593
440
  const note = parseNoteFile(file, current.text);
594
441
  if (Array.isArray(note))
595
442
  throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
596
- if (note.status !== "retired")
597
- throw new ApiError("bad_request", `The note is not retired: it is ${note.status}.`);
443
+ if (note.status !== "pending")
444
+ throw new ApiError("bad_request", `The note is not waiting for an OK: it is ${note.status}.`);
445
+ // Approved, it is active: in the index, and every later run reads it. What it supersedes, and is active still, is
446
+ // superseded now, as a run's merge marks it.
598
447
  text = approve(current.text);
599
- const { problems } = checkNote(file, Buffer.from(text, "utf8"), input.refuse);
600
- if (problems.length)
601
- throw refused(problems);
602
- // What it supersedes, and is active still, is superseded now, as an approval marks it.
603
- for (const old of note.supersedes)
604
- if (notes.get(old)?.status === "active")
605
- also.set(old, supersede(notes.get(old).text, file));
448
+ await mark(note.supersedes);
606
449
  }
607
- }
608
- else if (text === undefined && learned && !input.approve) {
609
- // Retired, as a note is: no later run is given it. One already retired is answered as it is; nothing else in
610
- // the folder changes.
611
- if (learnedStatus(current.text) === "retired")
612
- return { status: 200, file, text: current.text, etag: etagOf(current.oid) };
613
- text = retiredLearned(current.text);
614
- }
615
- else if (text === undefined && learned) {
616
- // Approved, it is no longer held: given to every later run. Nothing else in the folder changes.
617
- if (!isHeld(current.text))
618
- throw new ApiError("bad_request", `The ${learned.kind === "skill" ? "skill" : "workflow"} is not waiting for an OK: it is ${learnedStatus(current.text)}.`);
619
- text = released(current.text);
620
- }
621
- else if (text === undefined && input.approve) {
622
- const note = parseNoteFile(file, current.text);
623
- if (Array.isArray(note))
624
- throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
625
- if (note.status !== "pending")
626
- throw new ApiError("bad_request", `The note is not waiting for an OK: it is ${note.status}.`);
627
- // Approved, it is active: in the index, and every later run reads it. What it supersedes, and is active still, is
628
- // superseded now, as a run's merge marks it.
629
- text = approve(current.text);
630
- for (const old of note.supersedes)
631
- if (notes.get(old)?.status === "active")
632
- also.set(old, supersede(notes.get(old).text, file));
633
- }
634
- else if (text === undefined) {
635
- const note = parseNoteFile(file, current.text);
636
- if (Array.isArray(note))
637
- throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
638
- // A pending note is retired too: a person who will never approve it takes it out of the folder's waiting list.
639
- if (note.status !== "active" && note.status !== "pending")
640
- return { status: 200, file, text: current.text, etag: etagOf(current.oid) };
641
- // A retire is how a person takes a note out of every later run's prompt, a leaking one above all, so it always
642
- // can: only the note's format is checked as retired (its front matter parses, and it fits the note cap with the
643
- // status line added), never a secret in its name or text. Every answer cuts those as any read does.
644
- text = retire(current.text);
645
- const retired = parseNoteFile(file, text);
646
- if (Array.isArray(retired))
647
- throw refused(retired.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
648
- const size = Buffer.byteLength(text);
649
- if (size > CAPS.note + RETIRED_LINE)
650
- throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status line a retire adds` }, input.refuse)]);
651
- }
652
- if (current && text === current.text)
653
- return { status: 200, file, text, etag: etagOf(current.oid) };
654
- const after = learned ? [...notes.values()] : [...[...notes.values()].filter((note) => note.file !== file && !also.has(note.file)), parseNoteFile(file, text), ...[...also].map(([old, marked]) => parseNoteFile(old, marked))];
655
- const lines = after.filter((note) => note.status === "active").length;
656
- if (lines > INDEX_LINES)
657
- throw refused([{ rule: "index_full", detail: `the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so retire a note first` }]);
658
- const parent = main ?? (await openAgentRepo(home, repo, check));
659
- const subject = `learning: ${input.approve ? "approved" : input.restore ? "restored" : given === undefined ? "retired" : current ? "edited" : "created"} by a person: ${file}`;
660
- const env = { GIT_INDEX_FILE: join(repo, ".git", "person.index") };
661
- let commit;
662
- let oid;
663
- try {
664
- await rm(env.GIT_INDEX_FILE, { force: true });
665
- await git(home, repo, ["read-tree", parent], "", env);
666
- oid = line(await git(home, repo, ["hash-object", "-w", "--no-filters", "--stdin"], text));
667
- const index = line(await git(home, repo, ["hash-object", "-w", "--no-filters", "--stdin"], buildIndex(after)));
668
- let entries = `100644 ${oid}\t${file}\x00100644 ${index}\t${INDEX_FILE}\x00`;
669
- for (const [old, marked] of also)
670
- entries += `100644 ${line(await git(home, repo, ["hash-object", "-w", "--no-filters", "--stdin"], marked))}\t${old}\x00`;
671
- await git(home, repo, ["update-index", "-z", "--index-info"], entries, env);
672
- const tree = line(await git(home, repo, ["write-tree"], "", env));
673
- // Who approved, and how, in the trailers; the commit's own date is when. Never the note's text.
674
- const trailers = input.approve || heldBefore ? `${BY_USER}\n${APPROVED_VIA}` : BY_USER;
675
- commit = line(await git(home, repo, ["commit-tree", tree, "-p", parent, "-m", subject, "-m", trailers]));
676
- }
677
- finally {
678
- await rm(env.GIT_INDEX_FILE, { force: true });
679
- }
680
- try {
681
- await git(home, repo, ["update-ref", "-m", subject, "refs/heads/main", commit, parent]);
682
- }
683
- catch (error) {
684
- // Lost to a write since main was read: the precondition asked again of the main that won, never forced over it.
685
- if (tries === 0 && (await mainOf(home, repo)) !== parent)
686
- continue;
687
- throw error;
688
- }
689
- const failed = await checkOut(repo, commit);
690
- if (failed)
691
- process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning files are not main's: ${failed.message}\n`);
692
- return { status: current ? 200 : 201, file, text, etag: etagOf(oid) };
450
+ else if (text === undefined) {
451
+ const note = parseNoteFile(file, current.text);
452
+ if (Array.isArray(note))
453
+ throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
454
+ // A pending note is retired too: a person who will never approve it takes it out of the folder's waiting list.
455
+ if (note.status !== "active" && note.status !== "pending")
456
+ return { result: { status: 200, file, text: current.text, etag: etagOf(current.oid) } };
457
+ // A retire is how a person takes a note out of every later run's prompt, a leaking one above all, so it always
458
+ // can: only the note's format is checked as retired (its front matter parses, and it fits the note cap with the
459
+ // status line added), never a secret in its name or text. Every answer cuts those as any read does.
460
+ text = retire(current.text);
461
+ const retired = parseNoteFile(file, text);
462
+ if (Array.isArray(retired))
463
+ throw refused(retired.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
464
+ const size = Buffer.byteLength(text);
465
+ if (size > CAPS.note + RETIRED_LINE)
466
+ throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status line a retire adds` }, input.refuse)]);
467
+ }
468
+ if (current && text === current.text)
469
+ return { result: { status: 200, file, text, etag: etagOf(current.oid) } };
470
+ const after = learned ? [...notes.values()] : [...[...notes.values()].filter((note) => note.file !== file && !also.has(note.file)), parseNoteFile(file, text), ...[...also].map(([old, marked]) => parseNoteFile(old, marked))];
471
+ const lines = after.filter((note) => note.status === "active").length;
472
+ if (lines > INDEX_LINES)
473
+ throw refused([{ rule: "index_full", detail: `the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so retire a note first` }]);
474
+ const kind = input.approve ? "approved" : input.restore ? "restored" : given === undefined ? "retired" : current ? "edited" : "created";
475
+ const change = {
476
+ // Who approved, and how, in the trailers; the commit's own date is when. Never the note's text.
477
+ by: { person: kind, file, approved: Boolean(input.approve || heldBefore) },
478
+ writes: [{ path: file, text: text }, { path: INDEX_FILE, text: buildIndex(after) }, ...[...also].map(([path, marked]) => ({ path, text: marked }))],
479
+ // A create takes a name main holds nothing by, as git holds it: a file the notes leave out included.
480
+ ...(current ? {} : { absent: [file] }),
481
+ };
482
+ return { result: { status: current ? 200 : 201, file, text: text, etag: etagOf(blobOid(text)) }, change };
483
+ });
484
+ return result;
485
+ }
486
+ catch (error) {
487
+ if (error instanceof FolderRefused)
488
+ throw new ApiError("precondition_failed", NOT_NOTE);
489
+ if (error instanceof FolderTooLarge)
490
+ throw refused([{ rule: "too_large", path: file, detail: error.message }]);
491
+ throw routeFailure(error);
492
+ }
493
+ finally {
494
+ await end();
693
495
  }
694
496
  });
695
497
  }
696
498
  /** GET /runs/{id}/learning: the run's learning whole, or null for a run that does not learn: its detail cut of the
697
499
  * host's secrets now, and the notes it read and learned as its view shows them (learning.ts notesView). */
698
- export async function runLearning(run, shown, secrets) {
699
- const learning = run.meta.learning;
500
+ export async function runLearning(run, shown, secrets, data) {
501
+ // What it held for its owner's OK as it reads now (learning.ts currentLearning); its record stays as the merge wrote it.
502
+ const learning = holdsForOk(run.meta.learning) ? currentLearning(run.meta.learning, await statusesOf(data, run.agentId)) : run.meta.learning;
700
503
  if (!learning)
701
504
  return null;
702
505
  const pin = await readPin(run.dir).catch(() => undefined);
506
+ return runLearningBody({ id: run.id, learning, seed: pin?.seed ?? null, settled: run.settled }, shown, secrets);
507
+ }
508
+ /** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
509
+ * settled: the one shape, read from a run's files (runLearning) or from the one store (store-reads/learning.ts
510
+ * runLearningOverStore). */
511
+ export function runLearningBody(input, shown, secrets) {
512
+ const { learning } = input;
703
513
  const { state, reason, at, verdict, problems, merged, cost_usd, tokens, pending } = learning;
704
514
  return {
705
- run: run.id, state, reason, detail: detailShown(learning, shown), at,
515
+ run: input.id, state, reason, detail: detailShown(learning, shown), at,
706
516
  // Once it settled (a run that runs again for a follow-up is still reading).
707
- ...notesView(learning, shown, run.settled),
708
- seed: pin?.seed ?? null,
517
+ ...notesView(learning, shown, input.settled),
518
+ seed: input.seed,
709
519
  merged: merged ?? null,
710
520
  // The merge's notes that wait for a person's OK: on main as `status: pending`, read by no run until approved.
711
521
  pending: (pending ?? []).map(({ file, name }) => ({ file: shown.name(file), name: shown.text(name) })),
@@ -727,9 +537,10 @@ function addedPatch(text) {
727
537
  const added = [...lines.map((one) => `+${one}\n`), ...(last ? [`+${last}\n\\n`] : [])];
728
538
  return `@@ -0,0 +1${added.length === 1 ? "" : `,${added.length}`} @@\n${added.join("")}`;
729
539
  }
730
- /** GET /runs/{id}/learning/diff: once merged, its merge commit against its parent, as git diffs them; before, its proposal
731
- * (new notes only) against its seed; a run that proposed nothing, no file. A file's patch is withheld when too large, or
732
- * when it holds one of the host's secrets now. */
540
+ /** GET /runs/{id}/learning/diff: once merged, its merge commit against its parent, as its merge's script wrote it
541
+ * (`.agentrun/diffs/<run>.json`); before, its proposal (new notes only) against its seed; a run that proposed nothing,
542
+ * no file. A file's patch is withheld when too large (as the script wrote it), or when it holds one of the host's
543
+ * secrets now. */
733
544
  export async function runDiff(data, run, shown) {
734
545
  const learning = run.meta.learning;
735
546
  if (!learning)
@@ -739,21 +550,11 @@ export async function runDiff(data, run, shown) {
739
550
  return Buffer.byteLength(patch) > PATCH_CAP ? { path, status, withheld: "too_large" } : shown.holds(patch) ? { path, status, withheld: "secret" } : { path, status, patch };
740
551
  };
741
552
  if (learning.merged) {
742
- const { home, repo } = await placeOf(data, run.agentId);
743
- const head = learning.merged;
744
- const base = /^[0-9a-f]{40,64}$/.test(head) ? await git(home, repo, ["rev-parse", "--verify", "--quiet", `${head}^1`]).then(line, () => undefined) : undefined;
745
- if (!base)
553
+ const folder = learningFolderOf(data, run.agentId);
554
+ const diff = await readRunDiff(folder.workspace, run.id).catch((error) => Promise.reject(routeFailure(error))).finally(() => folder.end());
555
+ if (!diff || diff.merge !== learning.merged)
746
556
  throw new ApiError("not_found", "the run's merge is not in its agent's learning folder");
747
- const diff = ["diff", "--no-ext-diff", "--no-textconv", "--no-renames", "--no-color"];
748
- const listed = (await git(home, repo, [...diff, "--name-status", "-z", base, head])).toString("utf8").split("\0").filter(Boolean);
749
- const files = [];
750
- for (let i = 0; i + 1 < listed.length; i += 2) {
751
- const status = { A: "added", D: "deleted" }[listed[i][0]] ?? "modified";
752
- const raw = (await git(home, repo, [...diff, "--text", "-U3", base, head, "--", listed[i + 1]])).toString("utf8");
753
- const at = raw.search(/^@@/m);
754
- files.push(file(listed[i + 1], status, at < 0 ? "" : raw.slice(at)));
755
- }
756
- return { base, head, files };
557
+ return { base: diff.parent, head: diff.merge, files: diff.files.map((entry) => ("patch" in entry ? file(entry.path, entry.status, entry.patch) : { path: shown.name(entry.path), status: entry.status, withheld: entry.withheld })) };
757
558
  }
758
559
  const proposal = await readJson(join(run.dir, PROPOSAL));
759
560
  const notes = isObject(proposal) && typeof proposal.seed === "string" && Array.isArray(proposal.notes) ? proposal.notes.filter((note) => isObject(note) && typeof note.file === "string" && NOTE_FILE.test(note.file) && typeof note.text === "string") : undefined;