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

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 (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -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 +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. 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,8 +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
  };
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));
144
151
  /** 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
152
  * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
146
153
  * (notesView); never its time. */
@@ -160,35 +167,34 @@ export const PROPOSAL = "learning-proposal.json";
160
167
  export const LEARNING_PIN = "learning.json";
161
168
  /** Where a run finds its agent's notes: in its work, a copy the run may read and nothing reads back. */
162
169
  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
170
  /** Where a run keeps the learned workflows its pin names, whole: in the run's directory, beside its pin, never in its
167
171
  * work, so nothing the run does changes what its `learned_workflow` tool runs. */
168
172
  export const LEARNED_WORKFLOWS_FILE = "learned-workflows.json";
169
173
  /** The most bytes the `learned_workflow` tool's description gives its workflows, each one's line (workflowLine)
170
174
  * together: every harness sends the description with each request, so it never grows with what an agent learned. */
171
175
  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");
176
+ /** A learned workflow's line in the `learned_workflow` tool's description: its name, its input's fields (inputFields;
177
+ * none for a workflow whose input names no schema) and what its README says it does. One line: the tool's own line says
178
+ * once that `*` marks a required field. */
179
+ export const workflowLine = ({ name, description, workflow }) => {
180
+ const fields = inputFields(workflow);
181
+ return `- ${name}${fields ? ` ${fields}` : ""}: ${description || "(no description)"}`;
182
+ };
174
183
  /** The most of a field's description a workflow's input line carries. */
175
184
  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) {
185
+ /** A workflow's input as its line in learned_workflow's description says it: its input schema, compact (compactSchema),
186
+ * so a call names the fields the workflow takes; none for a workflow whose input names no schema. */
187
+ function inputFields(workflow) {
179
188
  let doc;
180
189
  try {
181
190
  doc = workflow ? JSON.parse(workflow) : undefined;
182
191
  }
183
192
  catch {
184
- return [];
193
+ return undefined;
185
194
  }
186
195
  const id = doc?.input?.schemaId;
187
196
  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)" : ""}`];
197
+ return schema ? compactSchema(schema, doc?.schemas ?? {}, 0, definitionsOf(schema)) : undefined;
192
198
  }
193
199
  /** A schema's own inline definitions (`definitions`, `$defs`), which its `#/definitions/` references read first. */
194
200
  const definitionsOf = (schema) => {
@@ -236,114 +242,9 @@ const RUN_SKILLS = [".agents", "skills"];
236
242
  const SKILL_NAME = /^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$/;
237
243
  /** A file's path inside a learned skill, as every adapter takes one (agentrun-kernel skillProblems). */
238
244
  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
245
  /** 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. */
246
+ * agentFolderOf (server-fs.ts agentDiskDir), so two ids that differ only in case never share one. */
246
247
  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
248
  const queues = new Map();
348
249
  /** Runs `work` once every call queued before it on the agent's folder has finished: one at a time per agent, in this
349
250
  * process. Everything that touches an agent's folder goes through it, so two runs made at once never both make it. */
@@ -354,68 +255,6 @@ function queued(key, work) {
354
255
  /** Agent `agentId`'s learning folder (learn/folder.ts learningWorkspace), in this server's place: Mode 1's local folder
355
256
  * under `data`. The one point that names the place; its `end()` is called in a finally after every use. */
356
257
  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
258
  /** A run's seed from the folder's read at `commit` (`read`): its index, its notes the one changed last first, its
420
259
  * skills grouped by folder, the one changed last first, each with its files while it could fit a run's budget at all
421
260
  * (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 +296,26 @@ export async function seedFrom(commit, read, { order, warn } = {}) {
457
296
  seed.files = [...new Set([...(seed.index === undefined ? [] : [INDEX_FILE]), ...Object.keys(seed.notes), ...got.held, ...(skills.size ? [SKILLS_DIR] : [])])];
458
297
  seed.skills = [...skills.keys()].sort(by(skillAt)).map((name) => {
459
298
  const files = skills.get(name);
460
- const bytes = Object.values(files).reduce((sum, text) => sum + Buffer.byteLength(text, "utf8"), 0);
299
+ // What the run is given, counted as given: a SKILL.md as servedSkill writes it (its name and description alone, each
300
+ // quoted where YAML needs it), which can be a few bytes more than the blob, every other file as it is.
301
+ const bytes = Object.entries(files).reduce((sum, [path, text]) => sum + Buffer.byteLength(path === "SKILL.md" ? servedSkill(text) : text, "utf8"), 0);
461
302
  return bytes > LEARNED_SKILLS_BUDGET ? { name, bytes } : { name, bytes, files };
462
303
  });
463
304
  // 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`.
305
+ // and workflow.json; its front matter is read again here, by the one reader of a learned item's status
306
+ // (learn/skills.ts frontMatter): one that does not read one way could hold a status another reader sees, so it is
307
+ // never read as active, and is named in `skipped`.
466
308
  seed.workflows = [];
467
309
  for (const name of [...flows.keys()].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))) {
468
310
  const { "README.md": readme, "workflow.json": workflow } = flows.get(name);
469
311
  if (readme === undefined || workflow === undefined)
470
312
  continue;
471
- const front = readmeFront(readme);
313
+ const front = frontMatter(readme);
472
314
  if (!front) {
473
315
  seed.skipped.push(`${WORKFLOWS_DIR}/${name} (its README.md's front matter does not read one way)`);
474
316
  continue;
475
317
  }
476
- if ((front.get("status") ?? "active") !== "active")
318
+ if (learnedStatus(readme) !== "active")
477
319
  continue;
478
320
  seed.workflows.push({ name, description: front.get("description") ?? "", workflow });
479
321
  }
@@ -487,41 +329,6 @@ export const readerOf = (ws) => async (commit) => {
487
329
  };
488
330
  /** The places a seed can't read from its files alone, from the folder's snapshot: each note's and each skill's. */
489
331
  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
332
  /** 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
333
  * learning script's init), and what main holds for a run (seedFrom over the folder's read): its index, its active
527
334
  * notes the one changed last first, its active skills, and its active learned workflows. A skill the read refused is
@@ -560,25 +367,6 @@ export const activeOf = (seed) => Object.entries(seed.notes).flatMap(([file, tex
560
367
  * 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
368
  * learns opens again for a follow-up, and as each git call starts (its arguments). */
562
369
  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
370
  /** `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
371
  * read (learn/secrets.ts PRINT_MAX). */
584
372
  const linesShown = (text, shown) => text.split("\n").map(shown.text).join("\n");
@@ -619,55 +407,125 @@ export async function layLearned(work, seed, shown) {
619
407
  for (const [file, text] of files)
620
408
  await work.write(`${LEARNED_DIR}/${file}`, text);
621
409
  }
410
+ /** All of `candidates` fit whole: every note within the budget, and an index that names no note main does not hold. */
411
+ const allFit = ({ notes, indexComplete, budget }) => indexComplete && notes.reduce((sum, { bytes }) => sum + bytes, 0) <= budget;
412
+ /** The selector by recency: every note whole while all fit the budget and the index names no note main does not hold
413
+ * whole; else the index, then the newest notes that fit what it leaves, each whole. */
414
+ export const byRecency = (candidates) => {
415
+ const { notes, indexBytes, budget } = candidates;
416
+ if (allFit(candidates))
417
+ return { whole: notes.map(({ note }) => note), index: false };
418
+ let left = budget - indexBytes;
419
+ return { whole: notes.filter(({ bytes }) => bytes <= left && ((left -= bytes), true)).map(({ note }) => note), index: true };
420
+ };
421
+ /** The default selector, by relevance, past the budget: while the notes fit it, recency's choice (byRecency). Else each
422
+ * note is scored against the run's input (learn/relevance.ts: BM25 over its name, description and body, a code
423
+ * review's changed paths' words weighed PATH_WEIGHT; no model call), and the run reads the notes that bear on it most
424
+ * 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
425
+ * budget before the whole notes, as the index did, and no more of them than a run reads of the index (loadedIndex). An
426
+ * input with no word any note holds reads by recency. */
427
+ export const byRelevance = (candidates, run) => {
428
+ // Within the budget, nothing changes: recency's choice (every note whole, or the index where it names a note main lacks).
429
+ if (candidates.notes.reduce((sum, { bytes }) => sum + bytes, 0) <= candidates.budget)
430
+ return byRecency(candidates, run);
431
+ const { notes, budget } = candidates;
432
+ const scores = bm25(notes.map(({ note }) => note), queryOf(run.input));
433
+ if (!scores.some((score) => score > 0))
434
+ return byRecency(candidates, run);
435
+ // Best first; a tie keeps recency (the candidates' order).
436
+ const ranked = notes.map((candidate, i) => ({ ...candidate, score: scores[i], at: i })).sort((a, b) => b.score - a.score || a.at - b.at);
437
+ // The lines of the rest, as the index was read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES.
438
+ const linesOf = (whole) => {
439
+ let bytes = 0;
440
+ return ranked.filter(({ note }) => !whole.has(note)).slice(0, INDEX_LINES).filter(({ lineBytes }) => (bytes += lineBytes) <= INDEX_BYTES);
441
+ };
442
+ const lineBytesOf = (whole) => linesOf(whole).reduce((sum, { lineBytes }) => sum + lineBytes, 0);
443
+ // Promoted whole, best first, while the whole notes and the lines served of the rest fit: the room kept for lines is
444
+ // only what is served of them (past INDEX_LINES or INDEX_BYTES a line is never served), never every note's.
445
+ const whole = new Set();
446
+ let wholeBytes = 0;
447
+ for (const { note, bytes, score } of ranked) {
448
+ if (score <= 0)
449
+ break;
450
+ whole.add(note);
451
+ if (wholeBytes + bytes + lineBytesOf(whole) <= budget)
452
+ wholeBytes += bytes;
453
+ else
454
+ whole.delete(note);
455
+ }
456
+ return { whole: ranked.filter(({ note }) => whole.has(note)).map(({ note }) => note), index: false, lines: linesOf(whole).map(({ note }) => note) };
457
+ };
622
458
  /** The lines before what a run learned, under `# Learned` after LEARNS, and the one that names `.learning/` to an agent
623
459
  * that can read it. */
624
460
  const KEPT = "Follow a note when it applies to what you are doing.";
625
461
  const WHOLE_INTRO = `What you learned in earlier runs: each note whole, newest first. ${KEPT}`;
626
462
  const SOME_INTRO = `What you learned in earlier runs: the index, one line per note, then the newest notes whole. ${KEPT}`;
627
463
  const INDEX_INTRO = `What you learned in earlier runs, one line per note. ${KEPT}`;
464
+ 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
465
  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
466
  const oneLine = (text) => text.replace(/\s+/g, " ").trim();
467
+ /** A note as one rule line: its name and file, then its description, cut of the host's secrets. */
468
+ const ruleLine = (note, shown) => `- ${shown.text(oneLine(note.name))} (${shown.name(note.file)}): ${shown.text(oneLine(note.description))}`;
630
469
  /** 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
470
  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;
471
+ /** What a run of `seed` reads under `# Learned` (`section`, the same for every harness, undefined when it learned
472
+ * nothing) and the notes that names (`given`), from one choice of the selector, so the section and the given notes never
473
+ * come from two choices. Only active notes are served: a pending, superseded or retired one is never there, whole or in
474
+ * the index, nor counted toward the budget (readSeed reads active notes alone, and servedIndex drops their lines). Its
475
+ * active notes, newest first (`seed.recent`, else by name), each whole while all fit `budget`; past it, the selector's
476
+ * choice (byRelevance by default). An agent with the read tool is told the rest are in `.learning/`, one without is not.
477
+ * Every text is cut of the host's secrets. A run "was given" `given`; of them, it "read" those whose file it opened
478
+ * (store-reads/learning.ts notesReadOf). Whether it applied one given whole is not measured. */
479
+ export function learnedParts(seed, options) {
480
+ const { budget, read, shown, select = byRelevance, run = {} } = options;
650
481
  const active = new Map(activeOf(seed).map((note) => [note.file, note]));
651
482
  const notes = (seed.recent ?? [...active.keys()].sort()).flatMap((file) => active.get(file) ?? []);
652
483
  const index = servedIndex(seed);
653
484
  const lines = index === undefined ? [] : loadedIndex(index).split("\n").filter((entry) => entry.trim() !== "");
654
485
  if (!notes.length && !lines.length)
655
486
  return { section: undefined, given: [] };
656
- const blocks = notes.map((note) => wholeNote(note, shown));
487
+ const blocks = new Map(notes.map((note) => [note, wholeNote(note, shown)]));
657
488
  // Each part's bytes, and the blank line before it.
658
489
  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
490
  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);
491
+ // Which notes the run reads whole, and whether it reads the index (the selector's one choice). Each line's first link,
492
+ // in any spelling (`./x.md` is x.md: linkedFiles, as servedIndex reads it), names an active note when indexComplete.
493
+ const choice = select({
494
+ notes: notes.map((note) => ({ note, bytes: size(blocks.get(note)), lineBytes: Buffer.byteLength(ruleLine(note, shown)) + 1 })),
495
+ indexBytes: shownIndex ? size(shownIndex) : 0,
496
+ indexComplete: lines.every((entry) => active.has(linkedFiles(entry)[0] ?? "")),
497
+ budget,
498
+ }, run);
499
+ const chosen = new Set(choice.whole);
500
+ const whole = choice.whole.filter((note) => blocks.has(note)).map((note) => blocks.get(note));
501
+ // Rule lines in place of the index: the whole notes first, then a line for each of the rest the selector names.
502
+ if (choice.lines) {
503
+ // The whole section fits the budget, its intro, blank lines and read-tool line counted: while it does not, the last
504
+ // whole note goes to the head of the lines (what the selector ranked best of the rest), the lines capped again as the
505
+ // index is read. Lines alone may pass the budget, as the index may.
506
+ const wholeNotes = choice.whole.filter((note) => blocks.has(note));
507
+ // The lines as the index is read (learn/notes.ts loadedIndex): the first INDEX_LINES, within INDEX_BYTES, each line
508
+ // and its newline counted. Applied again after every demotion, so a note demoted to a line never takes them past it.
509
+ const capped = (list) => {
510
+ let bytes = 0;
511
+ return list.slice(0, INDEX_LINES).filter((note) => (bytes += Buffer.byteLength(ruleLine(note, shown)) + 1) <= INDEX_BYTES);
512
+ };
513
+ let lined = capped(choice.lines.filter((note) => blocks.has(note) && !chosen.has(note)));
514
+ 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");
515
+ let section = render();
516
+ while (Buffer.byteLength(section) > budget && wholeNotes.length) {
517
+ lined = capped([wholeNotes.pop(), ...lined]);
518
+ section = render();
519
+ }
520
+ const served = new Set([...wholeNotes, ...lined]);
521
+ return { section, given: notes.filter((note) => served.has(note)) };
522
+ }
523
+ if (!choice.index)
524
+ return { section: [WHOLE_INTRO, ...whole].join("\n\n"), given: notes.filter((note) => chosen.has(note)) };
667
525
  // 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
526
  // name more than one; linkedFiles, as servedIndex reads them).
669
527
  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));
528
+ const given = notes.filter((note) => indexed.has(note.file) || chosen.has(note));
671
529
  return { section: [whole.length ? SOME_INTRO : INDEX_INTRO, shownIndex, ...(read && whole.length < notes.length ? [READ_LINE] : []), ...whole].filter(Boolean).join("\n\n"), given };
672
530
  }
673
531
  /** The run's skills folder, `.agents/skills`, as its Workspace names it. */
@@ -718,14 +576,18 @@ export async function takeSkills(work, names) {
718
576
  /** The learned skills' names a pin's `skills` hold, each once. */
719
577
  const namesIn = (files) => [...new Set((files ?? []).map((path) => path.split("/")[0]))];
720
578
  /** 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. */
579
+ * LEARNED_SKILLS_BUDGET and never more than the revision's `own` skill files leave of SKILL_BYTES, sized in each form a
580
+ * harness is handed them, the larger: as they are in `work` (claude-agent, codex) and as servedSkills writes them
581
+ * (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
582
+ * 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
583
+ * left out. */
724
584
  export async function chooseSkills(work, seed, own, shown) {
725
585
  if (!seed.skills?.length)
726
586
  return { taken: [], left: [] };
727
- let ownBytes = 0;
587
+ let stored = 0;
728
588
  const folders = new Map();
589
+ // Each skill's SKILL.md as stored, the one file servedSkills changes; every other file is served as it is.
590
+ const skillMds = [];
729
591
  for (const path of own) {
730
592
  const at = `${SKILLS_PATH}/${path}`;
731
593
  const dir = posix.dirname(at);
@@ -734,9 +596,14 @@ export async function chooseSkills(work, seed, own, shown) {
734
596
  const entry = (await folders.get(dir)).find((one) => one.name === posix.basename(at) && one.kind === "file");
735
597
  if (!entry)
736
598
  throw new WorkspaceError("NOT_FOUND", `the revision's skill file ${at} is not in the run's work`, { path: at });
737
- ownBytes += entry.size;
599
+ stored += entry.size;
600
+ const [name, ...rest] = path.split("/");
601
+ if (rest.join("/") === "SKILL.md")
602
+ skillMds.push({ name: name, files: { "SKILL.md": Buffer.from(await work.read(at)).toString("utf8") } });
738
603
  }
739
- let room = Math.max(0, Math.min(LEARNED_SKILLS_BUDGET, SKILL_BYTES - ownBytes));
604
+ const mdBytes = (skills) => skills.reduce((sum, skill) => sum + Buffer.byteLength(skill.files["SKILL.md"], "utf8"), 0);
605
+ const served = stored - mdBytes(skillMds) + mdBytes(servedSkills(skillMds));
606
+ let room = Math.max(0, Math.min(LEARNED_SKILLS_BUDGET, SKILL_BYTES - Math.max(stored, served)));
740
607
  const owned = new Set(namesIn(own));
741
608
  const there = await runSkillNames(work);
742
609
  const taken = [];
@@ -744,7 +611,9 @@ export async function chooseSkills(work, seed, own, shown) {
744
611
  for (const skill of seed.skills) {
745
612
  if (owned.has(skill.name) || there.has(skill.name))
746
613
  continue;
747
- const secret = shown.holds(skill.name) || Object.entries(skill.files ?? {}).some(([path, text]) => shown.holds(path) || shown.holds(text));
614
+ // Each file as stored and as laid: a SKILL.md is laid as servedSkill writes it, its front matter's values decoded
615
+ // (a held secret spelled in escapes reads as the secret there), so that text is what is checked too.
616
+ 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
617
  if (!skill.files || secret || skill.bytes > room) {
749
618
  left.push(shown.name(skill.name));
750
619
  continue;
@@ -754,6 +623,9 @@ export async function chooseSkills(work, seed, own, shown) {
754
623
  }
755
624
  return { taken, left };
756
625
  }
626
+ /** Whether a learned workflow's decoded strings (decodedStrings) hold a host secret, or can't be read past the bound:
627
+ * either way it is never chosen. */
628
+ const readsHeld = (decoded, shown) => decoded === "too_deep" || decoded.some(shown.holds);
757
629
  /** Which of `seed`'s learned workflows a run may run (its `learned_workflow` tool), in the seed's order: each while its
758
630
  * line (workflowLine) fits what is left of the tool's description budget (LEARNED_WORKFLOWS_BUDGET). One that does not,
759
631
  * 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 +635,8 @@ export function chooseWorkflows(seed, shown) {
763
635
  const left = [];
764
636
  let room = LEARNED_WORKFLOWS_BUDGET;
765
637
  for (const flow of seed.workflows ?? []) {
766
- if (shown.holds(flow.workflow) || shown.holds(flow.description) || shown.holds(flow.name)) {
638
+ // Its JSON read as JSON reads it too (decodedStrings: its escapes decoded, as its learned call's run reads it).
639
+ if (shown.holds(flow.workflow) || shown.holds(flow.description) || shown.holds(flow.name) || readsHeld(decodedStrings(flow.workflow), shown)) {
767
640
  // Named, but for a name that is itself a secret.
768
641
  if (!shown.holds(flow.name))
769
642
  left.push(flow.name);
@@ -779,14 +652,13 @@ export function chooseWorkflows(seed, shown) {
779
652
  }
780
653
  /** Writes `seed` into the run just made in `runDir`, its files through the run's Workspace (`work`): the index and each
781
654
  * 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
655
+ * `# Learned` (learnedParts) and the learned skills it gets beside the revision's `own` skill files (chooseSkills), then
783
656
  * those skills, last, into `.agents/skills/`. A write that fails leaves no `.learning/`, no learned skill and no pin,
784
657
  * and throws. */
785
658
  export async function pinSeed(runDir, work, seed, options) {
786
659
  const pinFile = join(runDir, LEARNING_PIN);
787
660
  const made = [];
788
661
  try {
789
- await learningTestHooks.beforePin?.(runDir);
790
662
  await layLearned(work, seed, options.shown);
791
663
  const { section, given } = learnedParts(seed, options);
792
664
  const { taken, left } = await chooseSkills(work, seed, options.own ?? [], options.shown);