@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
package/dist/learning.js CHANGED
@@ -4,19 +4,19 @@
4
4
  // git with main checked out, so any reader sees its files, reached through its Workspace (learningWorkspace). Every
5
5
  // write to main is one exec of the learning script (learn/folder.ts: a run's merge, a person's write, the first commit),
6
6
  // which also writes `.agentrun/snapshot.json`, what the routes read. A run's seed is the script's read too (seedFrom over
7
- // learn/seed-check.ts readSeed): no git runs in this process for it. The host-git reads left below (git, readBlobs,
8
- // readSeed, agentFolder) are propose.ts's alone, until it reads the seed through the folder too.
7
+ // learn/seed-check.ts readSeed): no git runs in this process.
9
8
  //
10
9
  // When a run of such an agent is made the server makes the folder if it is absent (the script's init: one host commit
11
10
  // on main, holding an empty `MEMORY.md`), and reads main's commit through the script, never the working tree. It copies that commit's
12
11
  // index and active notes into the run's `work/.learning/` and pins the commit in the run's directory (`learning.json`),
13
- // with what the run reads under `# Learned` (learnedOf): each active note whole while they fit the server's learning
14
- // budget, else the index and the notes changed last, whole, while they fit; every text cut of the server's secrets, the
12
+ // with what the run reads under `# Learned` (learnedParts): each active note whole while they fit the server's learning
13
+ // budget, else what its note selector picks (byRelevance: the notes that bear on the run's input whole, a line for each
14
+ // of the rest); every text cut of the server's secrets, the
15
15
  // copy's too. The run's process reads that pin (withLearned, for app.ts) and never runs git, so it may run anywhere its
16
- // directory is. When the run ends the server asks it one more turn, which answers with the notes
17
- // it would keep (learning-run.ts). As the run settles, before anything can open it again, that answer is kept in the
18
- // run's directory (`learning-turn.json`); its notes are checked from there (propose.ts), graded and merged into main
19
- // (grade.ts). The copy in the run's work is only for reading: nothing the run writes there is ever kept.
16
+ // directory is. When the run ends the runner asks it one more turn, which answers with the notes it would keep
17
+ // (runner/learning-end.ts, reflect-hook.ts); its notes are checked (propose.ts), then graded and merged into main by the
18
+ // runner's learning run (runner/learning-loop.ts). The copy in the run's work is only for reading: nothing the run
19
+ // writes there is ever kept.
20
20
  //
21
21
  // The skills the agent wrote are in the folder too, one folder each under `skills/` (SKILLS_DIR). A run
22
22
  // gets those of its commit beside its revision's own, in `work/.agents/skills/`, read as its notes are: a
@@ -27,18 +27,18 @@
27
27
  //
28
28
  // The host never follows a symbolic link into the folder (learn/folder.ts learningWorkspace, and the script): a link at
29
29
  // the agent's home, at its `learning/` or at `learning/.git`, or a `MEMORY.md` that is one when the script writes it, is
30
- // refused, and the run starts with nothing learned. Its proposal's check (agentFolder) refuses one the same way, and a
31
- // link there drops what the run learned. A person's reads and writes (learning-routes.ts) check it the same
30
+ // refused, and the run starts with nothing learned. Its proposal's check reads the folder the same way, and a link
31
+ // there drops what the run learned. A person's reads and writes (learning-routes.ts) check it the same
32
32
  // way (learn/folder.ts learningWorkspace), and a link there is an error.
33
- import { spawn } from "node:child_process";
34
- import { lstat, mkdir, readFile, rm } from "node:fs/promises";
35
- import { dirname, join, posix, relative } from "node:path";
33
+ import { lstat, readFile, rm } from "node:fs/promises";
34
+ import { join, posix } from "node:path";
36
35
  import { SKILL_BYTES } from "@parcha/agentrun-kernel";
37
- import { INDEX_FILE, loadedIndex, NOTE_FILE, parseNoteFile, redactSecrets, secretShapes, servedSkill, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
38
- import { DISK_DIR } from "@parcha/pi-durable-agent";
36
+ import { bm25, queryOf } from "./learn/relevance.js";
37
+ import { decodedStrings, frontMatter, INDEX_BYTES, INDEX_FILE, INDEX_LINES, learnedStatus, loadedIndex, NOTE_FILE, parseNoteFile, learnedSecretShapes, redactLearned, servedSkill, servedSkills, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
39
38
  import { learningInit, learningWorkspace, readSnapshot } from "./learn/folder.js";
40
39
  import { readSeed as readFolderSeed } from "./learn/seed-check.js";
41
40
  import { agentFolderOf, serialBy, writeDurable } from "./files.js";
41
+ import { withoutLoopbackAddresses } from "./key-refusal.js";
42
42
  import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
43
43
  import { isObject } from "./validate.js";
44
44
  import { isWorkspaceError, WorkspaceError, workspaceAt } from "./workspace/index.js";
@@ -53,7 +53,7 @@ export function learningOf(env, given) {
53
53
  throw new Error(`learning is on or off (--learning, ${LEARNING_ENV}), not ${value}`);
54
54
  return value;
55
55
  }
56
- /** How much of what a run learned its instructions hold under `# Learned` by default, in UTF-8 bytes (learnedOf): its
56
+ /** How much of what a run learned its instructions hold under `# Learned` by default, in UTF-8 bytes (learnedParts): its
57
57
  * notes whole while they fit, else the index and the notes changed last, whole, while they fit. */
58
58
  export const LEARNING_BUDGET = 8000;
59
59
  export const LEARNING_BUDGET_ENV = "AGENTRUN_SERVE_LEARNING_BUDGET";
@@ -68,7 +68,7 @@ export function learningBudgetOf(env, given) {
68
68
  }
69
69
  /** Where a run's learning stands (its `learning`, runs.ts): `seeded` once it starts from what its agent learned,
70
70
  * `reflecting` while its end-of-run turn runs and until what it answered is checked, `proposed` once that passed the
71
- * checks and is kept in the run's directory (propose.ts), `merged` once it is on main (grade.ts), or `dropped` with a
71
+ * checks and is kept (propose.ts), `merged` once it is on main (runner/learning-loop.ts), or `dropped` with a
72
72
  * reason from the closed list. A learning fault never refuses a run: it starts with nothing learned, `seed_failed`. */
73
73
  export const LEARNING_STATES = ["seeded", "reflecting", "proposed", "merged", "dropped"];
74
74
  export const LEARNING_REASONS = ["seed_failed", "no_budget", "unknown_cost", "cancelled", "crashed", "reflect_timeout", "reflect_failed", "empty", "unparsed", "propose_failed", "checker", "grader", "grade_failed"];
@@ -76,21 +76,25 @@ export const NO_TOKENS = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
76
76
  /** The variable that names the grader's model, as `--grade-model` does. */
77
77
  export const GRADE_MODEL_ENV = "AGENTRUN_SERVE_GRADE_MODEL";
78
78
  /** The model this server grades on, by name: `given` (`--grade-model`), else GRADE_MODEL_ENV, else its strong tier
79
- * (AGENT_MODEL_STRONG); undefined when it names none, and each run is graded on its agent's own model (grade.ts). A
79
+ * (AGENT_MODEL_STRONG); undefined when it names none, and each run is graded on its agent's own model (runner/learning-loop.ts). A
80
80
  * name is a model as the strong tier takes one: sent as it is to a gateway, a provider/model-id otherwise. */
81
81
  export const gradeModelOf = (env, given) => given || env[GRADE_MODEL_ENV] || env.AGENT_MODEL_STRONG || undefined;
82
- /** What a run's learning keeps whatever its learning does after: what it read, how many notes it started from, and its
83
- * answer's time and its costs (learning-run.ts setLearning). */
84
- export const KEPT_LEARNING = ["given", "read", "seed_notes", "answered_at", "job_cost_usd", "look_back_usd"];
85
82
  /** What a name holding a secret reads: learn/secrets.ts redactSecrets' mark, the name's whole, never a part of it. */
86
83
  const REDACTED = "[redacted]";
87
84
  /** The host's secrets as a reader cuts them: a text holding a value or a shape is cut of it (whole when long:
88
- * learn/secrets.ts redactSecrets), and a file's name holding one reads REDACTED whole, not a name of the folder's (its
89
- * route still answers the real name, to a caller who knows it); any other text or name is shown as it is. */
90
- export function secretsShown(values) {
85
+ * learn/secrets.ts redactLearned, a bank's numbers too), and a file's name holding one reads REDACTED whole, not a name of the folder's (its
86
+ * route still answers the real name, to a caller who knows it); any other text or name is shown as it is. A text served
87
+ * has no loopback address, the address alone (key-refusal.ts withoutLoopbackAddresses, the pattern a run's words share,
88
+ * run-view.ts shownOf): the host's own, never a person's; a run error's `url:` tail is no rule of a note's, a patch's or a
89
+ * workflow.json's, so their label, line ends and JSON stay. `local`: kept, for what a run itself is given (its .learning/ notes, runner/learning-seed.ts, and its
90
+ * # Learned section, server.ts's learning start), where an address on the run's own machine is the note's to give. */
91
+ export function secretsShown(values, { local = false } = {}) {
91
92
  const matches = valueMatcher(values);
92
- const holds = (text) => matches(text) || secretShapes(text).length > 0;
93
- return { holds, text: (text) => (holds(text) ? redactSecrets(text, values) : text), name: (name) => (holds(name) ? REDACTED : name) };
93
+ // Every shape learning refuses, a bank's numbers beside their words too (learnedSecretShapes): a name or a text refused
94
+ // for one never shows it here, though a run's own view may show its user an account number.
95
+ const holds = (text) => matches(text) || learnedSecretShapes(text).length > 0;
96
+ const cut = (text) => (holds(text) ? redactLearned(text, values) : text);
97
+ return { holds, text: local ? cut : (text) => withoutLoopbackAddresses(cut(text)), name: (name) => (holds(name) ? REDACTED : name) };
94
98
  }
95
99
  const isText = (value) => typeof value === "string";
96
100
  /** The notes a run read and learned, as a view or a list shows them, each name cut of the host's secrets (`shown`):
@@ -139,12 +143,11 @@ export const detailShown = (learning, shown, max = DETAIL_MAX) => {
139
143
  * read, learned and holds for the owner's OK (notesView). */
140
144
  export const learningView = (learning, shown, settled) => {
141
145
  const { state, reason, at } = learning;
142
- return { state, reason, detail: detailShown(learning, shown), at, ...notesView(learning, shown, settled) };
146
+ return { state, reason: reasonShown(reason, shown), detail: detailShown(learning, shown), at, ...notesView(learning, shown, settled) };
143
147
  };
144
- /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
145
- * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
146
- * (notesView); never its time. */
147
- export const shortLearning = (learning, shown, settled) => (learning ? shortOf(learningView(learning, shown, settled)) : null);
148
+ /** A learning's `reason` as it is served: one of its words as the server writes them, read back from a kept row, which is
149
+ * untrusted, so cut of the host's secrets as every text is. */
150
+ export const reasonShown = (reason, shown) => (typeof reason === "string" ? shown.text(reason) : (reason ?? null));
148
151
  /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
149
152
  export function shortOf({ state, reason, detail, at: _, ...notes }) {
150
153
  return { state, reason, detail: detail === null ? null : short(detail, LIST_DETAIL), ...notes };
@@ -160,35 +163,34 @@ export const PROPOSAL = "learning-proposal.json";
160
163
  export const LEARNING_PIN = "learning.json";
161
164
  /** Where a run finds its agent's notes: in its work, a copy the run may read and nothing reads back. */
162
165
  export const LEARNED_DIR = ".learning";
163
- /** What the run's end-of-run turn answered, and what the user said in the run, kept in the run's directory as the run
164
- * settles (learning-run.ts beforeSettle), where the host alone reads it: what propose.ts checks. */
165
- export const LEARNING_TURN = "learning-turn.json";
166
166
  /** Where a run keeps the learned workflows its pin names, whole: in the run's directory, beside its pin, never in its
167
167
  * work, so nothing the run does changes what its `learned_workflow` tool runs. */
168
168
  export const LEARNED_WORKFLOWS_FILE = "learned-workflows.json";
169
169
  /** The most bytes the `learned_workflow` tool's description gives its workflows, each one's line (workflowLine)
170
170
  * together: every harness sends the description with each request, so it never grows with what an agent learned. */
171
171
  export const LEARNED_WORKFLOWS_BUDGET = 8 * 1024;
172
- /** A learned workflow's line in the `learned_workflow` tool's description: its name, and what its README says it does. */
173
- export const workflowLine = ({ name, description, workflow }) => [`- ${name}: ${description || "(no description)"}`, ...inputLine(workflow)].join("\n");
172
+ /** A learned workflow's line in the `learned_workflow` tool's description: its name, its input's fields (inputFields;
173
+ * none for a workflow whose input names no schema) and what its README says it does. One line: the tool's own line says
174
+ * once that `*` marks a required field. */
175
+ export const workflowLine = ({ name, description, workflow }) => {
176
+ const fields = inputFields(workflow);
177
+ return `- ${name}${fields ? ` ${fields}` : ""}: ${description || "(no description)"}`;
178
+ };
174
179
  /** The most of a field's description a workflow's input line carries. */
175
180
  const FIELD_DESCRIPTION = 60;
176
- /** A workflow's input as its line in learned_workflow's description says it: its input schema, compact (inputSchema), on
177
- * a line of its own, so a call names the fields the workflow takes; none for a workflow whose input names no schema. */
178
- function inputLine(workflow) {
181
+ /** A workflow's input as its line in learned_workflow's description says it: its input schema, compact (compactSchema),
182
+ * so a call names the fields the workflow takes; none for a workflow whose input names no schema. */
183
+ function inputFields(workflow) {
179
184
  let doc;
180
185
  try {
181
186
  doc = workflow ? JSON.parse(workflow) : undefined;
182
187
  }
183
188
  catch {
184
- return [];
189
+ return undefined;
185
190
  }
186
191
  const id = doc?.input?.schemaId;
187
192
  const schema = typeof id === "string" ? doc?.schemas?.[id] : undefined;
188
- if (!schema)
189
- return [];
190
- const shown = compactSchema(schema, doc?.schemas ?? {}, 0, definitionsOf(schema));
191
- return [` input: ${shown}${shown.includes("*") ? " (* required)" : ""}`];
193
+ return schema ? compactSchema(schema, doc?.schemas ?? {}, 0, definitionsOf(schema)) : undefined;
192
194
  }
193
195
  /** A schema's own inline definitions (`definitions`, `$defs`), which its `#/definitions/` references read first. */
194
196
  const definitionsOf = (schema) => {
@@ -236,114 +238,9 @@ const RUN_SKILLS = [".agents", "skills"];
236
238
  const SKILL_NAME = /^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$/;
237
239
  /** A file's path inside a learned skill, as every adapter takes one (agentrun-kernel skillProblems). */
238
240
  const SKILL_FILE_PATH = /^(?:[A-Za-z0-9_][A-Za-z0-9._-]{0,99}\/){0,4}[A-Za-z0-9_][A-Za-z0-9._-]{0,99}$/;
239
- /** A file main holds over this is not read: a note is short, and the index is read only so far (loadedIndex). */
240
- const FILE_CAP = 1 << 20;
241
- const IDENTITY = { name: "agentrun-serve", email: "serve@agentrun.invalid" };
242
- /** How long one git call may take before it is killed: a hung call would hold its agent's queue. */
243
- const GIT_TIMEOUT_MS = 60_000;
244
241
  /** The agent's learning folder: `learning/` in its folder on the disk, which only the host writes. The folder is files.ts
245
- * agentFolderOf (pi-durable-agent agentDiskDir), so two ids that differ only in case never share one. */
242
+ * agentFolderOf (server-fs.ts agentDiskDir), so two ids that differ only in case never share one. */
246
243
  export const learningRepo = (data, agentId) => join(agentFolderOf(data, agentId), "learning");
247
- /** Makes `dir` where it is absent: a plain `mkdir`, never recursive (which would follow a link on the way). One that is
248
- * there, whatever it is, is left for the check after. */
249
- async function makeDir(dir) {
250
- try {
251
- await mkdir(dir, { mode: 0o700 });
252
- }
253
- catch (error) {
254
- if (error.code === "EEXIST")
255
- return;
256
- throw error;
257
- }
258
- await learningTestHooks.afterMkdir?.(dir);
259
- }
260
- /** Throws when `path` is a symbolic link or not a directory, by `lstat`, which never follows one. A missing one passes
261
- * when `absent` says it may be. What it throws names `path` in the data directory, never where a link points. */
262
- async function refuseLink(data, path, absent = false) {
263
- let stats;
264
- try {
265
- stats = await lstat(path);
266
- }
267
- catch (error) {
268
- if (absent && error.code === "ENOENT")
269
- return;
270
- throw error;
271
- }
272
- if (stats.isSymbolicLink())
273
- throw new Error(`${relative(data, path)} is a symbolic link, and the host never follows one into a learning folder`);
274
- if (!stats.isDirectory())
275
- throw new Error(`${relative(data, path)} is not a directory`);
276
- }
277
- /** The agent's learning folder, each level checked by `lstat`: its home, its `learning/` and, once there, `.git`. None
278
- * may be a symbolic link or anything but a directory, or the host's git would read from, and write to, where the link
279
- * points. `make`: the home and the folder are made where absent first, one level at a time, each checked after it is
280
- * made (agentFolder); without it nothing is made and a missing level passes. */
281
- async function checkedFolder(data, agentId, make) {
282
- const home = agentFolderOf(data, agentId);
283
- const repo = learningRepo(data, agentId);
284
- if (make) {
285
- await makeDir(join(data, DISK_DIR));
286
- await makeDir(dirname(home));
287
- }
288
- for (const dir of [home, repo]) {
289
- if (make)
290
- await makeDir(dir);
291
- await refuseLink(data, dir, !make);
292
- }
293
- await refuseLink(data, join(repo, ".git"), true);
294
- return repo;
295
- }
296
- /** The agent's learning folder, its home and the folder made where absent (checkedFolder). A link swapped in for a part
297
- * just made is caught by the check after. `<data>/disk/agents` is the operator's, as the data directory is. Every write into
298
- * the folder goes through it, in the agent's queue: before a run's seed reads or makes
299
- * the repository, before its end-of-run turn reads its seed again (seedAt), before its proposal is checked against it
300
- * (propose.ts), before its grade reads main and its merge writes it (grade.ts), and before a person's edit, create,
301
- * retire, approve or restore (learning-routes.ts). A refusal throws: a run about to start starts with nothing
302
- * learned (seed_failed), a run that ended drops what it learned (reflect_failed, propose_failed or grade_failed), and
303
- * a person's write is an error. */
304
- export const agentFolder = (data, agentId) => checkedFolder(data, agentId, true);
305
- /** Before every command: a `-c` flag wins over the repository's own config. No hook or fsmonitor runs, no replace ref
306
- * is read, a commit is never signed (which would run a program), and no transport runs, so nothing is fetched lazily.
307
- * No optional lock is taken (GIT_OPTIONAL_LOCKS), so a read never writes. */
308
- const SAFE = ["--no-replace-objects", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-c", "commit.gpgSign=false", "-c", "protocol.allow=never"];
309
- /** Every call's environment, built from nothing: no system or global config (so no template or hooks folder named
310
- * there), no HOME, no prompt, the host's identity, and the repository named outright, never looked for. */
311
- const gitEnv = (gitDir) => ({
312
- PATH: process.env.PATH ?? "/usr/bin:/bin",
313
- GIT_CONFIG_NOSYSTEM: "1",
314
- GIT_CONFIG_GLOBAL: "/dev/null",
315
- GIT_ATTR_NOSYSTEM: "1",
316
- GIT_NO_REPLACE_OBJECTS: "1",
317
- GIT_NO_LAZY_FETCH: "1",
318
- GIT_OPTIONAL_LOCKS: "0",
319
- GIT_TERMINAL_PROMPT: "0",
320
- LC_ALL: "C",
321
- GIT_AUTHOR_NAME: IDENTITY.name,
322
- GIT_AUTHOR_EMAIL: IDENTITY.email,
323
- GIT_COMMITTER_NAME: IDENTITY.name,
324
- GIT_COMMITTER_EMAIL: IDENTITY.email,
325
- ...(gitDir ? { GIT_DIR: gitDir } : {}),
326
- });
327
- /** One git call on `repo` (none for `init`), from `cwd`: its stdout, or a rejection naming the command and its stderr.
328
- * `env` adds to the call's environment (a temporary index, a work tree named outright). */
329
- export function git(cwd, repo, args, input = "", env = {}) {
330
- learningTestHooks.git?.(args);
331
- return new Promise((resolve, reject) => {
332
- const child = spawn("git", [...SAFE, ...args], { cwd, env: { ...gitEnv(repo && join(repo, ".git")), ...env }, stdio: ["pipe", "pipe", "pipe"], timeout: GIT_TIMEOUT_MS });
333
- const out = [];
334
- const err = [];
335
- child.stdout.on("data", (chunk) => out.push(chunk));
336
- child.stderr.on("data", (chunk) => err.push(chunk));
337
- child.stdin.on("error", () => undefined);
338
- child.once("error", reject);
339
- child.once("close", (code, signal) => {
340
- if (code === 0)
341
- return resolve(Buffer.concat(out));
342
- reject(new Error(`git ${args[0]} failed (${signal ?? code}): ${Buffer.concat(err).toString("utf8").trim().slice(0, 500)}`));
343
- });
344
- child.stdin.end(input);
345
- });
346
- }
347
244
  const queues = new Map();
348
245
  /** Runs `work` once every call queued before it on the agent's folder has finished: one at a time per agent, in this
349
246
  * process. Everything that touches an agent's folder goes through it, so two runs made at once never both make it. */
@@ -354,68 +251,6 @@ function queued(key, work) {
354
251
  /** Agent `agentId`'s learning folder (learn/folder.ts learningWorkspace), in this server's place: Mode 1's local folder
355
252
  * under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
356
253
  export const learningFolderOf = (data, agentId) => learningWorkspace({ mode: "local", agentId, data });
357
- /** The blobs `oids` hold, in order, read in one `cat-file --batch`. One git cannot read throws. */
358
- export async function readBlobs(cwd, repo, oids) {
359
- if (!oids.length)
360
- return [];
361
- const out = await git(cwd, repo, ["cat-file", "--batch"], oids.map((oid) => `${oid}\n`).join(""));
362
- const blobs = [];
363
- let at = 0;
364
- for (const oid of oids) {
365
- const end = out.indexOf(10, at);
366
- const [named, type, size] = out.subarray(at, end < 0 ? at : end).toString("utf8").split(" ");
367
- if (end < 0 || named !== oid || type !== "blob")
368
- throw new Error(`git cat-file could not read ${oid}`);
369
- blobs.push(out.subarray(end + 1, end + 1 + Number(size)));
370
- at = end + 2 + Number(size);
371
- }
372
- return blobs;
373
- }
374
- const utf8 = new TextDecoder("utf-8", { fatal: true });
375
- /** What commit `sha` holds for a run, read with plumbing: its index and its active notes, the `.md` files at its top.
376
- * Only a regular file (mode 100644) under FILE_CAP, in UTF-8, is read, and only a note in shape (learn/notes.ts
377
- * parseNoteFile); anything else is named in `skipped`. Only an active note is a run's: a pending, superseded or retired
378
- * one is not, and nothing serves it (learnedOf, layLearned). A read git fails (an
379
- * object missing, a timeout) throws. */
380
- export async function readSeed(cwd, repo, sha) {
381
- const seed = { sha, notes: {}, files: [], skipped: [] };
382
- const listed = (await git(cwd, repo, ["ls-tree", "-l", "-z", sha])).toString("utf8").split("\0").filter(Boolean);
383
- const wanted = [];
384
- for (const entry of listed) {
385
- const tab = entry.indexOf("\t");
386
- const [mode, type, oid, size] = entry.slice(0, tab).split(/\s+/);
387
- const path = entry.slice(tab + 1);
388
- seed.files.push(path);
389
- if (!path.endsWith(".md"))
390
- continue;
391
- if (path !== INDEX_FILE && !NOTE_FILE.test(path))
392
- seed.skipped.push(`${path} (not a note's file name)`);
393
- else if (mode !== "100644" || type !== "blob" || !oid)
394
- seed.skipped.push(`${path} (mode ${mode})`);
395
- else if (Number(size) > FILE_CAP)
396
- seed.skipped.push(`${path} (over ${FILE_CAP} bytes)`);
397
- else
398
- wanted.push({ path, oid });
399
- }
400
- const blobs = await readBlobs(cwd, repo, wanted.map(({ oid }) => oid));
401
- wanted.forEach(({ path }, i) => {
402
- let text;
403
- try {
404
- text = utf8.decode(blobs[i]);
405
- }
406
- catch {
407
- return void seed.skipped.push(`${path} (not UTF-8)`);
408
- }
409
- if (path === INDEX_FILE)
410
- return void (seed.index = text);
411
- const note = parseNoteFile(path, text);
412
- if (Array.isArray(note))
413
- seed.skipped.push(`${path} (${note.join("; ")})`);
414
- else if (note.status === "active")
415
- seed.notes[path] = text;
416
- });
417
- return seed;
418
- }
419
254
  /** A run's seed from the folder's read at `commit` (`read`): its index, its notes the one changed last first, its
420
255
  * skills grouped by folder, the one changed last first, each with its files while it could fit a run's budget at all
421
256
  * (LEARNED_SKILLS_BUDGET), else held by its size alone, and its active learned workflows by name. A path that is none (a file deeper than the folder's top, a
@@ -457,23 +292,26 @@ export async function seedFrom(commit, read, { order, warn } = {}) {
457
292
  seed.files = [...new Set([...(seed.index === undefined ? [] : [INDEX_FILE]), ...Object.keys(seed.notes), ...got.held, ...(skills.size ? [SKILLS_DIR] : [])])];
458
293
  seed.skills = [...skills.keys()].sort(by(skillAt)).map((name) => {
459
294
  const files = skills.get(name);
460
- const bytes = Object.values(files).reduce((sum, text) => sum + Buffer.byteLength(text, "utf8"), 0);
295
+ // What the run is given, counted as given: a SKILL.md as servedSkill writes it (its name and description alone, each
296
+ // quoted where YAML needs it), which can be a few bytes more than the blob, every other file as it is.
297
+ const bytes = Object.entries(files).reduce((sum, [path, text]) => sum + Buffer.byteLength(path === "SKILL.md" ? servedSkill(text) : text, "utf8"), 0);
461
298
  return bytes > LEARNED_SKILLS_BUDGET ? { name, bytes } : { name, bytes, files };
462
299
  });
463
300
  // The active learned workflows, by name, each with its workflow.json whole. The read gives an active one's README.md
464
- // and workflow.json; its front matter is read again here: one that does not read one way (readmeFront) could hold a
465
- // status another reader sees, so it is never read as active, and is named in `skipped`.
301
+ // and workflow.json; its front matter is read again here, by the one reader of a learned item's status
302
+ // (learn/skills.ts frontMatter): one that does not read one way could hold a status another reader sees, so it is
303
+ // never read as active, and is named in `skipped`.
466
304
  seed.workflows = [];
467
305
  for (const name of [...flows.keys()].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))) {
468
306
  const { "README.md": readme, "workflow.json": workflow } = flows.get(name);
469
307
  if (readme === undefined || workflow === undefined)
470
308
  continue;
471
- const front = readmeFront(readme);
309
+ const front = frontMatter(readme);
472
310
  if (!front) {
473
311
  seed.skipped.push(`${WORKFLOWS_DIR}/${name} (its README.md's front matter does not read one way)`);
474
312
  continue;
475
313
  }
476
- if ((front.get("status") ?? "active") !== "active")
314
+ if (learnedStatus(readme) !== "active")
477
315
  continue;
478
316
  seed.workflows.push({ name, description: front.get("description") ?? "", workflow });
479
317
  }
@@ -487,41 +325,6 @@ export const readerOf = (ws) => async (commit) => {
487
325
  };
488
326
  /** The places a seed can't read from its files alone, from the folder's snapshot: each note's and each skill's. */
489
327
  const orderOf = (snapshot) => snapshot ? { notes: snapshot.notes.map(({ file, order }) => ({ file, order })), skills: snapshot.skills.map(({ name, order }) => ({ name, order })) } : undefined;
490
- /** A learned workflow README's front matter, each key to its value (quotes dropped; a `>` or `|` value's indented lines
491
- * joined by spaces), or undefined when it does not read one way: no front matter, none closed (`---` on a line of its
492
- * own, the last line or not), a line that is neither a key at its left edge, a comment, blank, nor a line of a `>` or
493
- * `|` value, or a key set twice. */
494
- export function readmeFront(text) {
495
- const lf = text.replace(/\r\n/g, "\n");
496
- if (!lf.startsWith("---\n"))
497
- return undefined;
498
- const close = /\n---(?:\n|$)/.exec(lf.slice(3));
499
- if (!close)
500
- return undefined;
501
- const front = new Map();
502
- let block;
503
- for (const line of lf.slice(4, 3 + close.index).split("\n")) {
504
- if (block !== undefined && (/^\s+\S/.test(line) || line.trim() === "")) {
505
- if (line.trim())
506
- front.set(block, `${front.get(block)} ${line.trim()}`.trim());
507
- continue;
508
- }
509
- block = undefined;
510
- if (line.trim() === "" || line.startsWith("#"))
511
- continue;
512
- const pair = /^([A-Za-z_][\w-]*):(?:\s+(.*))?$/.exec(line);
513
- if (!pair || front.has(pair[1]))
514
- return undefined;
515
- const value = (pair[2] ?? "").trim();
516
- if (/^[>|][-+]?$/.test(value)) {
517
- block = pair[1];
518
- front.set(block, "");
519
- }
520
- else
521
- front.set(pair[1], value.replace(/^(["'])(.*)\1$/, "$2"));
522
- }
523
- return front;
524
- }
525
328
  /** The seed of a run of agent `agentId` about to be made: main's commit, the folder made first when it is absent (the
526
329
  * learning script's init), and what main holds for a run (seedFrom over the folder's read): its index, its active
527
330
  * notes the one changed last first, its active skills, and its active learned workflows. A skill the read refused is
@@ -560,25 +363,6 @@ export const activeOf = (seed) => Object.entries(seed.notes).flatMap(([file, tex
560
363
  * learned files are written, once its pin is in place, before what its end-of-run turn wrote is checked, as a run that
561
364
  * learns opens again for a follow-up, and as each git call starts (its arguments). */
562
365
  export const learningTestHooks = {};
563
- /** As the run in `runDir` settles after its end-of-run turn ended, before it reads ended and before a follow-up can
564
- * open it again: what the turn answered and what the user said, kept whole in `<run dir>/learning-turn.json`, so
565
- * nothing the run does after its end reaches what is checked. One already there stays (a server that went after it
566
- * was written). Throws when the write fails. */
567
- export async function keepTurn(runDir, turn) {
568
- const file = join(runDir, LEARNING_TURN);
569
- if (await lstat(file).then(() => true, (error) => (error.code === "ENOENT" ? false : Promise.reject(error))))
570
- return;
571
- await writeDurable(file, `${JSON.stringify(turn)}\n`);
572
- }
573
- /** The turn a run's directory keeps (keepTurn). One that is not there, or out of shape, throws. */
574
- export async function readTurn(runDir) {
575
- const turn = JSON.parse(await readFile(join(runDir, LEARNING_TURN), "utf8"));
576
- const triggered = isObject(turn) ? turn.triggered : undefined;
577
- const triggeredOk = triggered === undefined || (Array.isArray(triggered) && triggered.every((one) => isObject(one) && typeof one.source === "string" && typeof one.text === "string"));
578
- if (!isObject(turn) || typeof turn.answer !== "string" || !Array.isArray(turn.asked) || !turn.asked.every((message) => typeof message === "string") || !triggeredOk)
579
- throw new Error(`the run's ${LEARNING_TURN} is not a turn`);
580
- return turn;
581
- }
582
366
  /** `text` cut of the host's secrets (`shown`) a line at a time: the index, which may be longer than a whole text is
583
367
  * read (learn/secrets.ts PRINT_MAX). */
584
368
  const linesShown = (text, shown) => text.split("\n").map(shown.text).join("\n");
@@ -619,55 +403,125 @@ export async function layLearned(work, seed, shown) {
619
403
  for (const [file, text] of files)
620
404
  await work.write(`${LEARNED_DIR}/${file}`, text);
621
405
  }
406
+ /** All of `candidates` fit whole: every note within the budget, and an index that names no note main does not hold. */
407
+ const allFit = ({ notes, indexComplete, budget }) => indexComplete && notes.reduce((sum, { bytes }) => sum + bytes, 0) <= budget;
408
+ /** The selector by recency: every note whole while all fit the budget and the index names no note main does not hold
409
+ * whole; else the index, then the newest notes that fit what it leaves, each whole. */
410
+ export const byRecency = (candidates) => {
411
+ const { notes, indexBytes, budget } = candidates;
412
+ if (allFit(candidates))
413
+ return { whole: notes.map(({ note }) => note), index: false };
414
+ let left = budget - indexBytes;
415
+ return { whole: notes.filter(({ bytes }) => bytes <= left && ((left -= bytes), true)).map(({ note }) => note), index: true };
416
+ };
417
+ /** The default selector, by relevance, past the budget: while the notes fit it, recency's choice (byRecency). Else each
418
+ * note is scored against the run's input (learn/relevance.ts: BM25 over its name, description and body, a code
419
+ * review's changed paths' words weighed PATH_WEIGHT; no model call), and the run reads the notes that bear on it most
420
+ * whole, in score order, while they fit, then one rule line for each of the rest, best first, in place of the index; the lines count toward the
421
+ * budget before the whole notes, as the index did, and no more of them than a run reads of the index (loadedIndex). An
422
+ * input with no word any note holds reads by recency. */
423
+ export const byRelevance = (candidates, run) => {
424
+ // Within the budget, nothing changes: recency's choice (every note whole, or the index where it names a note main lacks).
425
+ if (candidates.notes.reduce((sum, { bytes }) => sum + bytes, 0) <= candidates.budget)
426
+ return byRecency(candidates, run);
427
+ const { notes, budget } = candidates;
428
+ const scores = bm25(notes.map(({ note }) => note), queryOf(run.input));
429
+ if (!scores.some((score) => score > 0))
430
+ return byRecency(candidates, run);
431
+ // Best first; a tie keeps recency (the candidates' order).
432
+ const ranked = notes.map((candidate, i) => ({ ...candidate, score: scores[i], at: i })).sort((a, b) => b.score - a.score || a.at - b.at);
433
+ // The lines of the rest, as the index was read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES.
434
+ const linesOf = (whole) => {
435
+ let bytes = 0;
436
+ return ranked.filter(({ note }) => !whole.has(note)).slice(0, INDEX_LINES).filter(({ lineBytes }) => (bytes += lineBytes) <= INDEX_BYTES);
437
+ };
438
+ const lineBytesOf = (whole) => linesOf(whole).reduce((sum, { lineBytes }) => sum + lineBytes, 0);
439
+ // Promoted whole, best first, while the whole notes and the lines served of the rest fit: the room kept for lines is
440
+ // only what is served of them (past INDEX_LINES or INDEX_BYTES a line is never served), never every note's.
441
+ const whole = new Set();
442
+ let wholeBytes = 0;
443
+ for (const { note, bytes, score } of ranked) {
444
+ if (score <= 0)
445
+ break;
446
+ whole.add(note);
447
+ if (wholeBytes + bytes + lineBytesOf(whole) <= budget)
448
+ wholeBytes += bytes;
449
+ else
450
+ whole.delete(note);
451
+ }
452
+ return { whole: ranked.filter(({ note }) => whole.has(note)).map(({ note }) => note), index: false, lines: linesOf(whole).map(({ note }) => note) };
453
+ };
622
454
  /** The lines before what a run learned, under `# Learned` after LEARNS, and the one that names `.learning/` to an agent
623
455
  * that can read it. */
624
456
  const KEPT = "Follow a note when it applies to what you are doing.";
625
457
  const WHOLE_INTRO = `What you learned in earlier runs: each note whole, newest first. ${KEPT}`;
626
458
  const SOME_INTRO = `What you learned in earlier runs: the index, one line per note, then the newest notes whole. ${KEPT}`;
627
459
  const INDEX_INTRO = `What you learned in earlier runs, one line per note. ${KEPT}`;
460
+ const LINES_INTRO = `What you learned in earlier runs: the notes that bear most on this run whole, then one line for each of the rest. ${KEPT}`;
628
461
  const READ_LINE = `The notes not given whole here are files in \`${LEARNED_DIR}/\` in your working directory: open one with the read tool when it applies.`;
629
462
  const oneLine = (text) => text.replace(/\s+/g, " ").trim();
463
+ /** A note as one rule line: its name and file, then its description, cut of the host's secrets. */
464
+ const ruleLine = (note, shown) => `- ${shown.text(oneLine(note.name))} (${shown.name(note.file)}): ${shown.text(oneLine(note.description))}`;
630
465
  /** A note as a run reads it whole: its name and file, its description, then its body, each cut of the host's secrets. */
631
466
  const wholeNote = (note, shown) => [`## ${shown.text(oneLine(note.name))} (${shown.name(note.file)})`, shown.text(oneLine(note.description)), shown.text(note.body.trim())].filter(Boolean).join("\n\n");
632
- /** What a run of `seed` reads under `# Learned`, the same for every harness, or undefined when it learned nothing. Only
633
- * active notes are served: a pending, superseded or retired one is never there, whole or in the index, nor counted
634
- * toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its active notes, newest
635
- * first (`seed.recent`, else by name): each whole while all fit `budget`, the UTF-8 bytes of
636
- * what follows the first paragraph. Past it, or when the index names a note main does not hold whole: the index as a
637
- * run loads it (learn/notes.ts loadedIndex, the first 200 lines and no more than 25 KB, past the budget when it is
638
- * larger), then the newest notes that fit what is left, each whole, and the rest named only in the index; an agent
639
- * with the read tool is told they are in `.learning/`, one without is not. Every text is cut of the host's secrets. */
640
- export function learnedOf(seed, options) {
641
- return learnedParts(seed, options).section;
642
- }
643
- /** The notes a run's # Learned section names (learnedOf): each given whole, and each an index line names by its file;
644
- * every active note when all are given whole. A run "was given" these; whether it applied one is not measured. */
645
- export function givenOf(seed, options) {
646
- return learnedParts(seed, options).given.map(({ file, name }) => ({ file, name }));
647
- }
648
- function learnedParts(seed, options) {
649
- const { budget, read, shown } = options;
467
+ /** What a run of `seed` reads under `# Learned` (`section`, the same for every harness, undefined when it learned
468
+ * nothing) and the notes that names (`given`), from one choice of the selector, so the section and the given notes never
469
+ * come from two choices. Only active notes are served: a pending, superseded or retired one is never there, whole or in
470
+ * the index, nor counted toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its
471
+ * active notes, newest first (`seed.recent`, else by name), each whole while all fit `budget`; past it, the selector's
472
+ * choice (byRelevance by default). An agent with the read tool is told the rest are in `.learning/`, one without is not.
473
+ * Every text is cut of the host's secrets. A run "was given" `given`; of them, it "read" those whose file it opened
474
+ * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. */
475
+ export function learnedParts(seed, options) {
476
+ const { budget, read, shown, select = byRelevance, run = {} } = options;
650
477
  const active = new Map(activeOf(seed).map((note) => [note.file, note]));
651
478
  const notes = (seed.recent ?? [...active.keys()].sort()).flatMap((file) => active.get(file) ?? []);
652
479
  const index = servedIndex(seed);
653
480
  const lines = index === undefined ? [] : loadedIndex(index).split("\n").filter((entry) => entry.trim() !== "");
654
481
  if (!notes.length && !lines.length)
655
482
  return { section: undefined, given: [] };
656
- const blocks = notes.map((note) => wholeNote(note, shown));
483
+ const blocks = new Map(notes.map((note) => [note, wholeNote(note, shown)]));
657
484
  // Each part's bytes, and the blank line before it.
658
485
  const size = (text) => Buffer.byteLength(text) + 2;
659
- // Each line's first link, in any spelling (`./x.md` is x.md: linkedFiles, as servedIndex reads it), names an active note.
660
- const named = lines.every((entry) => active.has(linkedFiles(entry)[0] ?? ""));
661
- if (named && blocks.reduce((sum, block) => sum + size(block), 0) <= budget)
662
- return { section: [WHOLE_INTRO, ...blocks].join("\n\n"), given: notes };
663
486
  const shownIndex = lines.map(shown.text).join("\n");
664
- let left = budget - (shownIndex ? size(shownIndex) : 0);
665
- const kept = notes.map((note, i) => ({ note, block: blocks[i] })).filter(({ block }) => size(block) <= left && ((left -= size(block)), true));
666
- const whole = kept.map(({ block }) => block);
487
+ // Which notes the run reads whole, and whether it reads the index (the selector's one choice). Each line's first link,
488
+ // in any spelling (`./x.md` is x.md: linkedFiles, as servedIndex reads it), names an active note when indexComplete.
489
+ const choice = select({
490
+ notes: notes.map((note) => ({ note, bytes: size(blocks.get(note)), lineBytes: Buffer.byteLength(ruleLine(note, shown)) + 1 })),
491
+ indexBytes: shownIndex ? size(shownIndex) : 0,
492
+ indexComplete: lines.every((entry) => active.has(linkedFiles(entry)[0] ?? "")),
493
+ budget,
494
+ }, run);
495
+ const chosen = new Set(choice.whole);
496
+ const whole = choice.whole.filter((note) => blocks.has(note)).map((note) => blocks.get(note));
497
+ // Rule lines in place of the index: the whole notes first, then a line for each of the rest the selector names.
498
+ if (choice.lines) {
499
+ // The whole section fits the budget, its intro, blank lines and read-tool line counted: while it does not, the last
500
+ // whole note goes to the head of the lines (what the selector ranked best of the rest), the lines capped again as the
501
+ // index is read. Lines alone may pass the budget, as the index may.
502
+ const wholeNotes = choice.whole.filter((note) => blocks.has(note));
503
+ // The lines as the index is read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES, each line
504
+ // and its newline counted. Applied again after every demotion, so a note demoted to a line never takes them past it.
505
+ const capped = (list) => {
506
+ let bytes = 0;
507
+ return list.slice(0, INDEX_LINES).filter((note) => (bytes += Buffer.byteLength(ruleLine(note, shown)) + 1) <= INDEX_BYTES);
508
+ };
509
+ let lined = capped(choice.lines.filter((note) => blocks.has(note) && !chosen.has(note)));
510
+ const render = () => [LINES_INTRO, ...wholeNotes.map((note) => blocks.get(note)), lined.map((note) => ruleLine(note, shown)).join("\n"), ...(read && lined.length ? [READ_LINE] : [])].filter(Boolean).join("\n\n");
511
+ let section = render();
512
+ while (Buffer.byteLength(section) > budget && wholeNotes.length) {
513
+ lined = capped([wholeNotes.pop(), ...lined]);
514
+ section = render();
515
+ }
516
+ const served = new Set([...wholeNotes, ...lined]);
517
+ return { section, given: notes.filter((note) => served.has(note)) };
518
+ }
519
+ if (!choice.index)
520
+ return { section: [WHOLE_INTRO, ...whole].join("\n\n"), given: notes.filter((note) => chosen.has(note)) };
667
521
  // Given: each note whole here, and each the index names by its file, by any of a line's links (a hand-edited line may
668
522
  // name more than one; linkedFiles, as servedIndex reads them).
669
523
  const indexed = new Set(lines.flatMap((entry) => linkedFiles(entry).filter((file) => active.has(file))));
670
- const given = notes.filter((note) => indexed.has(note.file) || kept.some((k) => k.note === note));
524
+ const given = notes.filter((note) => indexed.has(note.file) || chosen.has(note));
671
525
  return { section: [whole.length ? SOME_INTRO : INDEX_INTRO, shownIndex, ...(read && whole.length < notes.length ? [READ_LINE] : []), ...whole].filter(Boolean).join("\n\n"), given };
672
526
  }
673
527
  /** The run's skills folder, `.agents/skills`, as its Workspace names it. */
@@ -718,14 +572,18 @@ export async function takeSkills(work, names) {
718
572
  /** The learned skills' names a pin's `skills` hold, each once. */
719
573
  const namesIn = (files) => [...new Set((files ?? []).map((path) => path.split("/")[0]))];
720
574
  /** Which of `seed`'s learned skills a run gets, in `work`, in the seed's order: each whole while they fit their budget,
721
- * LEARNED_SKILLS_BUDGET and never more than the revision's `own` skill files (by their bytes in `work`) leave of
722
- * SKILL_BYTES. One named like a folder of the revision's skills, or like anything already in `work/.agents/skills/`, is
723
- * the revision's, and not the run's; one that does not fit, or holds a host secret (`shown`), is left out. */
575
+ * LEARNED_SKILLS_BUDGET and never more than the revision's `own` skill files leave of SKILL_BYTES, sized in each form a
576
+ * harness is handed them, the larger: as they are in `work` (claude-agent, codex) and as servedSkills writes them
577
+ * (OpenCode, whose check reads that form). One named like a folder of the revision's skills, or like anything already in `work/.agents/skills/`, is
578
+ * the revision's, and not the run's; one that does not fit, or holds a host secret (`shown`) as stored or as laid, is
579
+ * left out. */
724
580
  export async function chooseSkills(work, seed, own, shown) {
725
581
  if (!seed.skills?.length)
726
582
  return { taken: [], left: [] };
727
- let ownBytes = 0;
583
+ let stored = 0;
728
584
  const folders = new Map();
585
+ // Each skill's SKILL.md as stored, the one file servedSkills changes; every other file is served as it is.
586
+ const skillMds = [];
729
587
  for (const path of own) {
730
588
  const at = `${SKILLS_PATH}/${path}`;
731
589
  const dir = posix.dirname(at);
@@ -734,9 +592,14 @@ export async function chooseSkills(work, seed, own, shown) {
734
592
  const entry = (await folders.get(dir)).find((one) => one.name === posix.basename(at) && one.kind === "file");
735
593
  if (!entry)
736
594
  throw new WorkspaceError("NOT_FOUND", `the revision's skill file ${at} is not in the run's work`, { path: at });
737
- ownBytes += entry.size;
595
+ stored += entry.size;
596
+ const [name, ...rest] = path.split("/");
597
+ if (rest.join("/") === "SKILL.md")
598
+ skillMds.push({ name: name, files: { "SKILL.md": Buffer.from(await work.read(at)).toString("utf8") } });
738
599
  }
739
- let room = Math.max(0, Math.min(LEARNED_SKILLS_BUDGET, SKILL_BYTES - ownBytes));
600
+ const mdBytes = (skills) => skills.reduce((sum, skill) => sum + Buffer.byteLength(skill.files["SKILL.md"], "utf8"), 0);
601
+ const served = stored - mdBytes(skillMds) + mdBytes(servedSkills(skillMds));
602
+ let room = Math.max(0, Math.min(LEARNED_SKILLS_BUDGET, SKILL_BYTES - Math.max(stored, served)));
740
603
  const owned = new Set(namesIn(own));
741
604
  const there = await runSkillNames(work);
742
605
  const taken = [];
@@ -744,7 +607,9 @@ export async function chooseSkills(work, seed, own, shown) {
744
607
  for (const skill of seed.skills) {
745
608
  if (owned.has(skill.name) || there.has(skill.name))
746
609
  continue;
747
- const secret = shown.holds(skill.name) || Object.entries(skill.files ?? {}).some(([path, text]) => shown.holds(path) || shown.holds(text));
610
+ // Each file as stored and as laid: a SKILL.md is laid as servedSkill writes it, its front matter's values decoded
611
+ // (a held secret spelled in escapes reads as the secret there), so that text is what is checked too.
612
+ const secret = shown.holds(skill.name) || Object.entries(skill.files ?? {}).some(([path, text]) => shown.holds(path) || shown.holds(text) || (path === "SKILL.md" && shown.holds(servedSkill(text))));
748
613
  if (!skill.files || secret || skill.bytes > room) {
749
614
  left.push(shown.name(skill.name));
750
615
  continue;
@@ -754,6 +619,9 @@ export async function chooseSkills(work, seed, own, shown) {
754
619
  }
755
620
  return { taken, left };
756
621
  }
622
+ /** Whether a learned workflow's decoded strings (decodedStrings) hold a host secret, or can't be read past the bound:
623
+ * either way it is never chosen. */
624
+ const readsHeld = (decoded, shown) => decoded === "too_deep" || decoded.some(shown.holds);
757
625
  /** Which of `seed`'s learned workflows a run may run (its `learned_workflow` tool), in the seed's order: each while its
758
626
  * line (workflowLine) fits what is left of the tool's description budget (LEARNED_WORKFLOWS_BUDGET). One that does not,
759
627
  * or holds a host secret (`shown`), is left out and named in `left`, but for one whose name is itself a secret, never
@@ -763,7 +631,8 @@ export function chooseWorkflows(seed, shown) {
763
631
  const left = [];
764
632
  let room = LEARNED_WORKFLOWS_BUDGET;
765
633
  for (const flow of seed.workflows ?? []) {
766
- if (shown.holds(flow.workflow) || shown.holds(flow.description) || shown.holds(flow.name)) {
634
+ // Its JSON read as JSON reads it too (decodedStrings: its escapes decoded, as its learned call's run reads it).
635
+ if (shown.holds(flow.workflow) || shown.holds(flow.description) || shown.holds(flow.name) || readsHeld(decodedStrings(flow.workflow), shown)) {
767
636
  // Named, but for a name that is itself a secret.
768
637
  if (!shown.holds(flow.name))
769
638
  left.push(flow.name);
@@ -779,14 +648,13 @@ export function chooseWorkflows(seed, shown) {
779
648
  }
780
649
  /** Writes `seed` into the run just made in `runDir`, its files through the run's Workspace (`work`): the index and each
781
650
  * active note into `.learning/`, made fresh (whatever was there goes), then the pin, with what the run reads under
782
- * `# Learned` (learnedOf) and the learned skills it gets beside the revision's `own` skill files (chooseSkills), then
651
+ * `# Learned` (learnedParts) and the learned skills it gets beside the revision's `own` skill files (chooseSkills), then
783
652
  * those skills, last, into `.agents/skills/`. A write that fails leaves no `.learning/`, no learned skill and no pin,
784
653
  * and throws. */
785
654
  export async function pinSeed(runDir, work, seed, options) {
786
655
  const pinFile = join(runDir, LEARNING_PIN);
787
656
  const made = [];
788
657
  try {
789
- await learningTestHooks.beforePin?.(runDir);
790
658
  await layLearned(work, seed, options.shown);
791
659
  const { section, given } = learnedParts(seed, options);
792
660
  const { taken, left } = await chooseSkills(work, seed, options.own ?? [], options.shown);
@@ -896,15 +764,3 @@ export async function withLearned(runDir, given, instructions, own = []) {
896
764
  skills: [...own, ...learned.filter((path) => whole.has(path.split("/")[0]))],
897
765
  };
898
766
  }
899
- /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
900
- * names none. A file that is not the list the pin names throws. */
901
- export async function pinnedWorkflows(runDir, pin) {
902
- const names = pin?.workflows ?? [];
903
- if (!names.length)
904
- return [];
905
- const kept = JSON.parse(await readFile(join(runDir, LEARNED_WORKFLOWS_FILE), "utf8"));
906
- const ok = (entry) => isObject(entry) && typeof entry.name === "string" && typeof entry.description === "string" && typeof entry.workflow === "string";
907
- if (!Array.isArray(kept) || !kept.every(ok) || kept.map(({ name }) => name).join("\n") !== names.join("\n"))
908
- throw new Error(`the run's ${LEARNED_WORKFLOWS_FILE} is not the workflows its pin names`);
909
- return kept;
910
- }