@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
@@ -22,14 +22,49 @@ export function learnedPlace(path) {
22
22
  }
23
23
  /** Whether `name` is a good name for a folder of `kind`. */
24
24
  export const learnedName = (kind, name) => (kind === "skill" ? SKILL_NAME : WORKFLOW_NAME).test(name);
25
- /** A SKILL.md's or a draft README's front matter: its lines, where it closes (the index of its closing `\n---\n`, in
26
- * `lf`, the text with LF line ends) and each key's value, a folded or literal block value read as one line. A string
27
- * is why there is none. */
25
+ /** Where a SKILL.md's or a draft README's front matter closes in `lf` (its text with LF line ends): the index of the
26
+ * `\n` before its closing `---` line, the last line or not; -1 when it has none. */
27
+ const closeOf = (lf) => {
28
+ const close = /\n---(?:\n|$)/.exec(lf.slice(3));
29
+ return close ? 3 + close.index : -1;
30
+ };
31
+ /** YAML's double-quoted escapes, each to what it reads as (`\\x`, `\\u` and `\\U` take hex digits apart). */
32
+ const ESCAPES = { "0": "\0", a: "\x07", b: "\b", t: "\t", "\t": "\t", n: "\n", v: "\v", f: "\f", r: "\r", e: "\x1b", " ": " ", '"': '"', "/": "/", "\\": "\\", N: "\u0085", _: "\u00a0", L: "\u2028", P: "\u2029" };
33
+ /** A scalar's value as YAML reads it: a double-quoted one with its escapes decoded (JSON's, which servedSkill writes,
34
+ * and YAML's own), a single-quoted one with each `''` one `'`, a plain one as it is. So reading what servedSkill wrote
35
+ * gives back the very value it quoted, and serving a skill again writes the same text (OpenCode serves a laid skill
36
+ * again): never an escape quoted twice. Undefined, never a throw, for a double-quoted value with an escape that does
37
+ * not decode cleanly (one YAML has not, a code point past U+10FFFF, a `\\` that ends it): what another reader makes of
38
+ * it is not known, so its front matter reads no way. The decoded value is the one every check reads (frontValues). */
39
+ function unquote(raw) {
40
+ const value = raw.trim();
41
+ if (value.length >= 2 && value.startsWith("'") && value.endsWith("'"))
42
+ return value.slice(1, -1).replace(/''/g, "'");
43
+ if (!(value.length >= 2 && value.startsWith('"') && value.endsWith('"')))
44
+ return value;
45
+ let clean = true;
46
+ const decoded = value.slice(1, -1).replace(/\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|[\s\S]?)/g, (whole, code) => {
47
+ if (code.length > 1) {
48
+ const point = Number.parseInt(code.slice(1), 16);
49
+ if (point > 0x10ffff)
50
+ return (clean = false), whole;
51
+ return String.fromCodePoint(point);
52
+ }
53
+ const one = ESCAPES[code];
54
+ if (one === undefined)
55
+ clean = false;
56
+ return one ?? whole;
57
+ });
58
+ return clean ? decoded : undefined;
59
+ }
60
+ /** A SKILL.md's or a draft README's front matter, as the host edits it: its lines, where it closes (closeOf, in `lf`,
61
+ * the text with LF line ends) and each key's value, a folded or literal block value read as one line. A string is why
62
+ * there is none. What it says of itself (its keys, its status) is frontMatter's to read, never this. */
28
63
  function frontOf(text) {
29
64
  const lf = text.replace(/\r\n/g, "\n");
30
65
  if (!lf.startsWith("---\n"))
31
66
  return "it does not start with front matter";
32
- const end = lf.indexOf("\n---\n", 3);
67
+ const end = closeOf(lf);
33
68
  if (end < 0)
34
69
  return "its front matter is not closed";
35
70
  const lines = lf.slice(4, end).split("\n");
@@ -54,68 +89,216 @@ function frontOf(text) {
54
89
  return words.join(" ").trim();
55
90
  if (words.length && !/^["']/.test(own))
56
91
  return [own, ...words].join(" ").trim();
57
- return own.replace(/^(["'])(.*)\1$/, "$2").trim();
92
+ return unquote(own)?.trim();
58
93
  };
59
94
  return { lf, end, value };
60
95
  }
61
- /** The keys a SKILL.md's or a draft README's front matter sets, in order (each line at its left edge that names one);
62
- * undefined for a text with no front matter. */
63
- export function frontKeys(text) {
64
- const front = frontOf(text);
65
- if (typeof front === "string")
96
+ /** Why a front matter does not read one way, by frontMatter: the words a refusal says. */
97
+ export const UNCLEAR_FRONT = "its front matter does not read one way: each line a `key: value` at its left edge, a comment, or a line of the value above it";
98
+ /** A SKILL.md's or a draft README's front matter, read one way, as the one reader of what it says of itself (its keys,
99
+ * its name, its description, its status): each key to its value in order, or undefined when it does not read one way,
100
+ * since another reader (a harness's YAML) could then read a key, a status among them, this one does not. It reads one
101
+ * way when it starts the text (`---`), closes on a `---` line (the last line or not), and each line between is blank,
102
+ * a comment at its left edge, `key: value` at its left edge (a key set once), or a line of the value above it: any
103
+ * indented line under a `key:` with nothing after it (its nested value, a mapping or a list among them), an indented
104
+ * line of a `>` or `|` block, or of a plain value that wraps (one that reads as no key of its own), an indented comment
105
+ * under a plain value being no part of it. A quoted value is read as YAML reads it (unquote: its escapes decoded); a
106
+ * nested, block or wrapped value's lines are joined by one space. Anything else (an indented first line, an indented
107
+ * `key:` under a value, a list at the left edge, a key set twice, a YAML explicit key `? key`, which every writer here
108
+ * would have to edit in its own form) reads no way. */
109
+ export function frontMatter(text) {
110
+ const lf = text.replace(/\r\n/g, "\n");
111
+ if (!lf.startsWith("---\n"))
112
+ return undefined;
113
+ const end = closeOf(lf);
114
+ if (end < 0)
66
115
  return undefined;
67
- return front.lf.slice(4, front.end).split("\n").flatMap((line) => /^([^\s#:][^:]*):/.exec(line)?.[1] ?? []).map((key) => key.trim());
116
+ const front = new Map();
117
+ const add = (key, more) => front.set(key, `${front.get(key)} ${more.trim()}`.trim());
118
+ // The key whose `>`/`|` block, or nested value (a `key:` with nothing after it), the next indented lines are; the key
119
+ // whose plain value they wrap; a quoted value still open, its lines so far (quotedValue folds them).
120
+ let block;
121
+ let plain;
122
+ let quoting;
123
+ for (const line of lf.slice(4, end).split("\n")) {
124
+ const indented = /^\s+\S/.test(line);
125
+ if (quoting) {
126
+ // A quoted value's next line: indented, or blank (a line break of its own); one at the left edge reads no way.
127
+ if (line.trim() !== "" && !indented)
128
+ return undefined;
129
+ quoting.lines.push(line);
130
+ if (!closedQuote(quoting.lines.map((one) => one.trim()).join(" ")))
131
+ continue;
132
+ const read = unquote(foldQuoted(quoting.lines));
133
+ if (read === undefined)
134
+ return undefined;
135
+ front.set(quoting.key, read);
136
+ quoting = undefined;
137
+ continue;
138
+ }
139
+ if (block !== undefined && (indented || line.trim() === "")) {
140
+ if (line.trim())
141
+ add(block, line);
142
+ continue;
143
+ }
144
+ block = undefined;
145
+ if (line.trim() === "" || line.startsWith("#"))
146
+ continue;
147
+ // An indented comment under a plain value is no part of it, and the value may wrap on after it.
148
+ if (indented && plain !== undefined && /^\s+#/.test(line))
149
+ continue;
150
+ if (indented) {
151
+ // A wrapped plain value's line, never one that reads as a key, a list item or a comment of its own.
152
+ if (plain === undefined || /^\s+(?:#|-\s|\?\s|[^\s]*:(?:\s|$))/.test(line) || /:\s/.test(line))
153
+ return undefined;
154
+ add(plain, line);
155
+ continue;
156
+ }
157
+ plain = undefined;
158
+ const pair = /^([A-Za-z_][\w-]*):(?:\s+(.*))?$/.exec(line);
159
+ if (!pair || front.has(pair[1]))
160
+ return undefined;
161
+ const value = (pair[2] ?? "").trim();
162
+ if (!value || /^[>|][-+]?$/.test(value)) {
163
+ block = pair[1];
164
+ front.set(block, "");
165
+ }
166
+ else if (/^["']/.test(value) && !closedQuote(value)) {
167
+ // A quoted value that runs on past its line: read once it closes, its lines folded as YAML folds them.
168
+ quoting = { key: pair[1], lines: [value] };
169
+ }
170
+ else {
171
+ // A quoted value whose escapes do not decode cleanly reads no way.
172
+ const read = unquote(value);
173
+ if (read === undefined)
174
+ return undefined;
175
+ front.set(pair[1], read);
176
+ if (!/^["']/.test(value))
177
+ plain = pair[1];
178
+ }
179
+ }
180
+ // A quoted value never closed reads no way.
181
+ return quoting ? undefined : front;
182
+ }
183
+ /** Whether `value`, a quoted scalar's text from its opening quote, closes: it ends with its quote, a double quote not
184
+ * escaped (an even run of backslashes before it), a single quote not one of a doubled pair (`''`, an odd run). */
185
+ function closedQuote(value) {
186
+ const quote = value[0];
187
+ if ((quote !== '"' && quote !== "'") || value.length < 2 || !value.endsWith(quote))
188
+ return false;
189
+ const inner = value.slice(1);
190
+ if (quote === '"')
191
+ return (/(\\*)"$/.exec(inner)[1].length % 2) === 0;
192
+ return (/('+)$/.exec(inner)[1].length % 2) === 1;
193
+ }
194
+ /** A quoted scalar's `lines` (its first, from the opening quote, then the next ones as written) as one, folded as YAML
195
+ * folds a flow scalar: each line's surrounding white space dropped, each line break one space, each blank line a line
196
+ * break, and in a double-quoted one a break after a `\` none at all. unquote reads the result. */
197
+ function foldQuoted(lines) {
198
+ let out = lines[0].trimEnd();
199
+ let blanks = 0;
200
+ for (const line of lines.slice(1)) {
201
+ const part = line.trim();
202
+ if (part === "") {
203
+ blanks += 1;
204
+ continue;
205
+ }
206
+ if (blanks)
207
+ out += "\n".repeat(blanks);
208
+ else if (out.startsWith('"') && /(?<!\\)(\\\\)*\\$/.test(out))
209
+ out = out.slice(0, -1);
210
+ else
211
+ out += " ";
212
+ out += part;
213
+ blanks = 0;
214
+ }
215
+ return out;
216
+ }
217
+ /** Every value a SKILL.md's or a draft README's front matter holds, as YAML reads it (frontMatter: escapes decoded):
218
+ * what a check for secrets reads beside the text as stored, since the decoded value is the one a harness is served
219
+ * (servedSkill). None for a text whose front matter does not read one way. */
220
+ export function frontValues(text) {
221
+ return [...(frontMatter(text)?.values() ?? [])];
222
+ }
223
+ /** The keys a SKILL.md's or a draft README's front matter sets, in order (frontMatter's); undefined for a text whose
224
+ * front matter does not read one way. */
225
+ export function frontKeys(text) {
226
+ const front = frontMatter(text);
227
+ return front ? [...front.keys()] : undefined;
68
228
  }
69
229
  /** The front matter keys a learned skill or draft README may hold: what a skill is (its name and when to use it). Claude
70
230
  * Code reads directives from more (hooks, allowed-tools, context, agent, model, ...): a hook is a shell command its CLI
71
231
  * runs. `status` is the host's (a held one). */
72
232
  export const LEARNED_KEYS = ["name", "description"];
73
- /** `text`, a learned skill's SKILL.md, as a run is given it: front matter with its name and its description alone,
74
- * written again whatever else its file holds (servedSkill is the one door a learned skill reaches a harness by), then its
75
- * body as it is. A text with no front matter is as it is. */
233
+ /** `text`, a learned skill's SKILL.md, as a run is given it: front matter with its name and its description alone, as
234
+ * the one reader reads them (frontMatter), each quoted as JSON writes it, which every YAML reads back as that very
235
+ * string (never null, a boolean, a number or a date), written again whatever else its file holds (servedSkill is the
236
+ * one door a learned skill reaches a harness by), then its body as it is. A text with no front matter, or one whose front
237
+ * matter reads no way, is as it is: never served with its fields emptied. A learned one of those is never active, so
238
+ * never given; a revision's own is the harness's to check, as its author wrote it. */
76
239
  export function servedSkill(text) {
77
- const front = frontOf(text);
78
- if (typeof front === "string")
240
+ const opened = frontOf(text);
241
+ if (typeof opened === "string")
242
+ return text;
243
+ const front = frontMatter(text);
244
+ if (!front)
79
245
  return text;
80
- const description = front.value("description") ?? "";
81
- // Quoted only where YAML would read it as more than one plain line of text.
82
- const plain = /^[^\s\-?:,[\]{}#&*!|>'"%@`][^\n]*$/.test(description) && !/: |\s#|:$/.test(description);
83
- const lines = [`name: ${front.value("name") ?? ""}`, `description: ${plain ? description : JSON.stringify(description)}`];
84
- return `---\n${lines.join("\n")}\n---\n${front.lf.slice(front.end + 5)}`;
246
+ const lines = [`name: ${JSON.stringify(front.get("name") ?? "")}`, `description: ${JSON.stringify(front.get("description") ?? "")}`];
247
+ return `---\n${lines.join("\n")}\n---\n${opened.lf.slice(opened.end + 5)}`;
85
248
  }
249
+ /** Skills as a harness that loads them through servedSkill is handed them (OpenCode, adapters.ts opencodeOf): each
250
+ * SKILL.md as servedSkill writes it, its other files as they are. Its table entry's check and the learned skills' room
251
+ * (learning.ts chooseSkills) read this same form, so a set the check takes is never one that grew past its limit after. */
252
+ export const servedSkills = (skills) => skills.map((skill) => ({ ...skill, files: { ...skill.files, ...(skill.files["SKILL.md"] === undefined ? {} : { "SKILL.md": servedSkill(skill.files["SKILL.md"]) }) } }));
86
253
  /** Why a `SKILL.md` for the skill `name`, or a draft's `README.md` for the workflow `name`, is out of shape; empty when
87
254
  * it is not. Its front matter names the folder's name and a description. */
88
255
  export function skillProblems(text, name) {
89
- const front = frontOf(text);
90
- if (typeof front === "string")
91
- return [front];
256
+ const opened = frontOf(text);
257
+ if (typeof opened === "string")
258
+ return [opened];
259
+ const front = frontMatter(text);
260
+ if (!front)
261
+ return [UNCLEAR_FRONT];
92
262
  const out = [];
93
- if (front.value("name") !== name)
263
+ if (front.get("name") !== name)
94
264
  out.push(`name is not the folder's name, ${name}`);
95
- if (!front.value("description"))
265
+ if (!front.get("description"))
96
266
  out.push("description is missing or empty");
97
267
  return out;
98
268
  }
99
- /** A SKILL.md's or a draft README's front matter as a reader shows it: its name, description and status, each absent
100
- * when it is not there; undefined for a text with no front matter. */
269
+ /** A SKILL.md's or a draft README's front matter as a reader shows it (frontMatter): its name, description and status,
270
+ * each absent when it is not there; undefined for a text whose front matter does not read one way. */
101
271
  export function learnedFront(text) {
102
- const front = frontOf(text);
103
- if (typeof front === "string")
272
+ const front = frontMatter(text);
273
+ if (!front)
104
274
  return undefined;
105
- const [name, description, status] = ["name", "description", "status"].map((key) => front.value(key));
275
+ const [name, description, status] = ["name", "description", "status"].map((key) => front.get(key));
106
276
  return { ...(name === undefined ? {} : { name }), ...(description === undefined ? {} : { description }), ...(status === undefined ? {} : { status }) };
107
277
  }
108
- /** Whether a SKILL.md or a draft's README.md sets `status`, which only the host does (`held`). */
109
- export const setsStatus = (text) => {
110
- const front = frontOf(text);
111
- return typeof front !== "string" && front.value("status") !== undefined;
112
- };
278
+ /** Whether a SKILL.md or a draft's README.md sets `status`, which only the host does (`held`) (frontMatter). */
279
+ export const setsStatus = (text) => frontMatter(text)?.has("status") ?? false;
113
280
  /** A skill or a draft the grader held for its owner's OK: its SKILL.md, or its draft's README.md, says `status:
114
- * pending`. No run is given a held skill or workflow until a person approves it. */
115
- export const isHeld = (text) => {
116
- const front = frontOf(text);
117
- return typeof front !== "string" && front.value("status") === "pending";
118
- };
281
+ * pending` (learnedStatus). No run is given a held skill or workflow until a person approves it. */
282
+ export const isHeld = (text) => learnedStatus(text) === "pending";
283
+ /** Whether `text`'s status, when it sets one, is one plain line, `status: <value>` with nothing of it on the lines after
284
+ * (no quoted value that runs on, no block, no wrapped line): the only status the host's writers (released,
285
+ * retiredLearned), which take the `status:` line out whole, can edit. One set any other way reads unclear (learnedStatus:
286
+ * retired), never held or active, and no writer edits it, so a write never leaves part of it behind. The host writes
287
+ * only one-line statuses (held, retiredLearned). */
288
+ export const statusOnOneLine = (text) => onOneLine(text, "status");
289
+ /** Whether `key`, when the front matter sets it, is one plain line (`key: <value>`, nothing of it on the lines after):
290
+ * statusOnOneLine's rule, for each key the host's writers take out whole (`status`, `retired_from`). */
291
+ function onOneLine(text, key) {
292
+ const front = frontMatter(text);
293
+ if (!front?.has(key))
294
+ return true;
295
+ const lf = text.replace(/\r\n/g, "\n");
296
+ const own = lf.slice(4, closeOf(lf)).split("\n").find((line) => line.startsWith(`${key}:`))?.slice(key.length + 1).trim() ?? "";
297
+ if (!own || /^[>|]/.test(own) || (/^["']/.test(own) && !closedQuote(own)))
298
+ return false;
299
+ // A plain value that wraps onto the next lines reads longer than its own line.
300
+ return unquote(own) === front.get(key);
301
+ }
119
302
  /** `text`, a SKILL.md or a draft's README.md, as the host merges one the grader held for its owner's OK: `status:
120
303
  * pending` last in its front matter, with LF line ends. Throws on a text with no front matter, which the checker never
121
304
  * passes. */
@@ -126,41 +309,348 @@ export function held(text) {
126
309
  return `${front.lf.slice(0, front.end)}\nstatus: pending${front.lf.slice(front.end)}`;
127
310
  }
128
311
  /** `text`, a held SKILL.md or draft README.md, as the host leaves it when its owner approves it: its front matter with
129
- * no `status` line, so it is given to every later run. Throws on a text with no front matter. */
312
+ * no `status` or `retired_from` line, so it is given to every later run. Throws on a text with no front matter. */
130
313
  export function released(text) {
131
314
  const front = frontOf(text);
132
315
  if (typeof front === "string")
133
316
  throw new Error(`it cannot be approved: ${front}`);
134
- const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
135
- return `---\n${kept.join("\n")}${front.lf.slice(front.end)}`;
317
+ // Its status and retired_from are taken out whole, so each must be one plain line; what is left reads back active, or
318
+ // the write fails: never an OK over a skill no run is given.
319
+ if (!statusOnOneLine(text) || !onOneLine(text, "retired_from"))
320
+ throw new Error("it cannot be approved: its status is not one plain line");
321
+ const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:") && !line.startsWith("retired_from:"));
322
+ const out = `---\n${kept.join("\n")}${front.lf.slice(front.end)}`;
323
+ if (learnedStatus(out) !== "active")
324
+ throw new Error(`it cannot be approved: its status would read ${learnedStatus(out)}`);
325
+ return out;
326
+ }
327
+ /** The status a retired SKILL.md or draft README.md goes back to when a person restores it (`retired_from`, which its
328
+ * retire recorded), read by the one reader (frontMatter: its quoting, its one-line rule): `active` only when it reads
329
+ * `active` one way, on one plain line; `pending` otherwise, a retire that recorded none or one that reads unclear among
330
+ * them (fail closed: only an approval makes a skill or a draft active). */
331
+ export function retiredFrom(text) {
332
+ return onOneLine(text, "retired_from") && frontMatter(text)?.get("retired_from") === "active" ? "active" : "pending";
136
333
  }
137
- /** What a SKILL.md or a draft's README.md says of itself: `pending` while it waits for its owner's OK, `retired` once a
138
- * person retired it, else `active`. A run is given only an active one. */
334
+ /** Whether a retired SKILL.md or draft README.md can be restored by the host's writer: its front matter reads one way
335
+ * (frontMatter), and its `status` and `retired_from` are each one plain line, the only ones the writer takes out whole.
336
+ * One that is not is refused until it is written so (a restore never edits half a value). */
337
+ export const restorable = (text) => frontMatter(text) !== undefined && statusOnOneLine(text) && onOneLine(text, "retired_from");
338
+ /** `text`, a retired SKILL.md or draft README.md, as the host leaves it when a person restores it: back in the status its
339
+ * retire recorded (retiredFrom), active, or waiting for its owner's OK. Throws on a text whose front matter does not read
340
+ * one way, or whose status is not one plain line (released). */
341
+ export const restoredLearned = (text) => (retiredFrom(text) === "active" ? released(text) : held(released(text)));
342
+ /** What a SKILL.md or a draft's README.md says of itself, the one reader of it (frontMatter), the server's and, through
343
+ * the folder's snapshot, the console's: `pending` while it waits for its owner's OK, `retired` once a person retired
344
+ * it, `active` when it sets no status or `active`. A front matter that does not read one way, or a status that is none
345
+ * of these, is `retired`: never active, since another reader could read it as held or retired; no run is given it, and
346
+ * a restore refuses it until it reads one way. A run is given only an active one. */
139
347
  export function learnedStatus(text) {
140
- const front = frontOf(text);
141
- const status = typeof front === "string" ? undefined : front.value("status");
142
- return status === "pending" ? "pending" : status === "retired" ? "retired" : "active";
348
+ const front = frontMatter(text);
349
+ if (!front)
350
+ return "retired";
351
+ if (!statusOnOneLine(text))
352
+ return "retired";
353
+ const status = front.get("status") ?? "active";
354
+ return status === "active" || status === "pending" ? status : "retired";
143
355
  }
144
- /** `text`, a SKILL.md or a draft's README.md, as a person's retire leaves it: `status: retired` last in its front matter
145
- * (any status line before it dropped), so no later run is given it. Throws on a text with no front matter. */
356
+ /** `text`, a SKILL.md or a draft's README.md, as a person's retire leaves it: `status: retired` and `retired_from`, the
357
+ * status it had (active, or pending while it waited for its owner's OK), last in its front matter (any such lines before
358
+ * them dropped), so no later run is given it and its restore gives that status back. Throws on a text with no front
359
+ * matter. */
146
360
  export function retiredLearned(text) {
147
361
  const front = frontOf(text);
148
362
  if (typeof front === "string")
149
363
  throw new Error(`it cannot be retired: ${front}`);
150
- const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
151
- return `---\n${[...kept, "status: retired"].join("\n")}${front.lf.slice(front.end)}`;
364
+ if (!statusOnOneLine(text) || !onOneLine(text, "retired_from"))
365
+ throw new Error("it cannot be retired: its status is not one plain line");
366
+ // What it goes back to on a restore: active only when it reads active now; anything else (held, or a text read as
367
+ // retired already) is held again (fail closed).
368
+ const from = learnedStatus(text) === "active" ? "active" : "pending";
369
+ const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:") && !line.startsWith("retired_from:"));
370
+ const out = `---\n${[...kept, "status: retired", `retired_from: ${from}`].join("\n")}${front.lf.slice(front.end)}`;
371
+ if (!frontMatter(out) || learnedStatus(out) !== "retired" || retiredFrom(out) !== from)
372
+ throw new Error("it cannot be retired: its front matter would not read retired");
373
+ return out;
152
374
  }
153
375
  /** A draft's `README.md` as the host writes it, from the workflow's name and the one-line description its block gives. */
154
- export const readmeOf = (name, description) => `---\nname: ${name}\ndescription: ${description}\n---\n`;
376
+ export const readmeOf = (name, description) => `---\nname: ${name}\n${frontLine("description", description)}\n---\n`;
377
+ /** `key: value` as a front matter line the one reader (frontMatter) reads back as `value`: plain when it does, else
378
+ * quoted as JSON writes it, whose escapes frontMatter decodes. A value the block quoted (`"\"a\" plus"`) is written
379
+ * quoted again, never as a plain line that reads another way or no way. */
380
+ function frontLine(key, value) {
381
+ const plain = `${key}: ${value}`;
382
+ return frontMatter(`---\n${plain}\n---\n`)?.get(key) === value ? plain : `${key}: ${JSON.stringify(value)}`;
383
+ }
155
384
  /** A workflow block's two files: its `description:` front matter written as the draft's README.md (readmeOf), and the
156
385
  * JSON after it as its workflow.json. A block with no front matter, or none that says what the draft is for, gives a
157
- * README with no description, which the checker refuses; what the JSON holds is the checker's to judge. */
386
+ * README with no description, which the checker refuses; what the JSON holds is the checker's to judge. `example`, its
387
+ * `example:` front matter line as written (the run's own input to the workflow, one JSON object): what its dry run runs
388
+ * on (draftDryRun), and never a file's: the README holds its name and description alone, so the run's input, which can
389
+ * be a customer's data, is never kept in the learning folder. */
158
390
  export function draftFiles(name, block) {
159
391
  const front = frontOf(block);
160
392
  if (typeof front === "string")
161
393
  return { json: block, readme: readmeOf(name, "") };
162
394
  const description = (front.value("description") ?? "").replace(/\s+/g, " ").trim();
163
- return { json: front.lf.slice(front.end + "\n---\n".length), readme: readmeOf(name, description) };
395
+ const example = front.value("example")?.trim();
396
+ return { json: front.lf.slice(front.end + "\n---\n".length), readme: readmeOf(name, description), ...(example ? { example } : {}) };
397
+ }
398
+ /** The words a draft that failed its dry run is left out with, before why: a re-ask reads them (reflect-hook.ts). */
399
+ export const DRY_RUN_FAILED = "its dry run failed";
400
+ /** The most synthetic steps a draft's dry run takes before it stops, as not run. */
401
+ const DRY_RUN_STEPS = 2_000;
402
+ /** The longest a draft's dry run may take, by the clock, before it stops, as not run: a backstop behind the steps and the
403
+ * static bounds (the DSL reads its signal at each step). */
404
+ const DRY_RUN_MS = 10_000;
405
+ /** The code runner a dry run hands every code node to: it refuses each. Given a runner, the DSL validates with
406
+ * executeCode: false (a code node's expression is parsed, never evaluated or probed) and never compiles or calls a code
407
+ * body in this process; with none, it evaluates every code node's expression and runs its body here, at validation and
408
+ * at run time. A learned draft holds no code node (draftProblems refuses it before any dry run): this holds even when
409
+ * one is handed here anyway. */
410
+ const refuseCode = async (node) => {
411
+ throw new Error(`the code node "${node.label}" is never run: a learned draft holds no code node`);
412
+ };
413
+ /** The most of a value a draft's dry run may synthesize from one of its schemas (the DSL's synthesizeInstance builds
414
+ * each in the host, before any step it counts): an array's minItems and a string's minLength each, and the values and
415
+ * string characters the schema's whole synthesized instance holds. Past any of them the draft is refused statically
416
+ * (draftProblems), and a dry run handed one anyway stands down as not run before anything is built (draftDryRun). */
417
+ export const SYNTH_MIN_ITEMS = 100;
418
+ export const SYNTH_MIN_LENGTH = 1_000;
419
+ export const SYNTH_VALUES = 2_000;
420
+ export const SYNTH_CHARS = 64_000;
421
+ /** The depth past which the DSL's synthesis stops (synthesizeInstance: null past 12). */
422
+ const SYNTH_DEPTH = 12;
423
+ /** A literal's values and string characters (a const, an enum's first), as the value it is. */
424
+ const literalSize = (value) => value === null || typeof value !== "object"
425
+ ? { values: 1, chars: typeof value === "string" ? value.length : 0 }
426
+ : Object.values(value).map(literalSize).reduce((a, b) => ({ values: a.values + b.values, chars: a.chars + b.chars }), { values: 1, chars: 0 });
427
+ /** What the DSL's synthesizeInstance would build of `schema` at `depth`, counted without building it: its values and its
428
+ * strings' characters. It reads the schema as synthesis does (a $ref to its definitions, a const or an enum's first, an
429
+ * anyOf's first non-null branch, a oneOf's first, an object's every property, an array of max(1, minItems) items, a
430
+ * string of max(1, minLength) characters, nothing past depth 12), and counts an array's items once, times its length,
431
+ * each (schema, depth) once (`seen`), so the count itself is bounded by the schema's size. */
432
+ function synthesized(schema, definitions, depth, seen) {
433
+ if (depth > SYNTH_DEPTH || !schema || typeof schema !== "object")
434
+ return { values: 1, chars: 0 };
435
+ const known = seen.get(schema)?.get(depth);
436
+ if (known)
437
+ return known;
438
+ const spec = schema;
439
+ const of = (sub) => synthesized(sub, definitions, depth + 1, seen);
440
+ let out = { values: 1, chars: 0 };
441
+ const type = Array.isArray(spec.type) ? spec.type[0] : spec.type;
442
+ if (typeof spec.$ref === "string") {
443
+ const match = /^#\/definitions\/(.+)$/.exec(spec.$ref);
444
+ if (match && definitions[match[1]])
445
+ out = of(definitions[match[1]]);
446
+ }
447
+ else if (spec.const !== undefined || (Array.isArray(spec.enum) && spec.enum.length)) {
448
+ // The literal itself, as written in the draft (so bounded by its size).
449
+ out = literalSize(spec.const !== undefined ? spec.const : spec.enum[0]);
450
+ }
451
+ else if (Array.isArray(spec.anyOf) && spec.anyOf.length) {
452
+ out = of(spec.anyOf.find((branch) => branch?.type !== "null") ?? spec.anyOf[0]);
453
+ }
454
+ else if (Array.isArray(spec.oneOf) && spec.oneOf.length) {
455
+ out = of(spec.oneOf[0]);
456
+ }
457
+ else if (type === "object" || (!type && spec.properties)) {
458
+ for (const property of Object.values(spec.properties || {})) {
459
+ const one = of(property);
460
+ out = { values: out.values + one.values, chars: out.chars + one.chars };
461
+ }
462
+ }
463
+ else if (type === "array") {
464
+ if (spec.maxItems !== 0 && spec.items) {
465
+ const length = Math.max(1, Number.isInteger(spec.minItems) ? spec.minItems : 1);
466
+ const item = of(spec.items);
467
+ out = { values: 1 + length * item.values, chars: length * item.chars };
468
+ }
469
+ }
470
+ else if (type === "string") {
471
+ if (spec.maxLength !== 0)
472
+ out = { values: 1, chars: Math.max(1, Number.isInteger(spec.minLength) ? spec.minLength : 1) };
473
+ }
474
+ let atDepth = seen.get(schema);
475
+ if (!atDepth)
476
+ seen.set(schema, (atDepth = new Map()));
477
+ atDepth.set(depth, out);
478
+ return out;
479
+ }
480
+ /** What the DSL's synthesizeInstance would build of `schema` over `definitions`, counted without building it. */
481
+ export const synthesizedSize = (schema, definitions = {}) => synthesized(schema, definitions, 0, new Map());
482
+ const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
483
+ /** The nodes directly inside `node`, as the DSL reads them (recovery/execution-path.ts childrenOf): a chain's steps, a
484
+ * parallel's branches, a map's or a loop's body, a route's branch bodies. A composed workflow node's child is a
485
+ * workflow, walked as one (eachWorkflow). Only these are node positions: an object anywhere else (a schema, a const, a
486
+ * step's literal value) is data, never a node, whatever keys it holds. */
487
+ function childNodes(node) {
488
+ switch (node.node) {
489
+ case "chain": return Array.isArray(node.steps) ? node.steps : [];
490
+ case "parallel": return Array.isArray(node.branches) ? node.branches : [];
491
+ case "map":
492
+ case "loop": return [node.body];
493
+ case "route": return isRecord(node.branches) ? Object.values(node.branches).map((branch) => (isRecord(branch) ? branch.body : undefined)) : [];
494
+ default: return [];
495
+ }
496
+ }
497
+ /** Each workflow in `doc` (the draft's own, then each composed workflow node's child, at any depth), each with the loops
498
+ * around it (their maxIters multiplied), and each node of it at a node position with the loops around that node. */
499
+ function eachWorkflow(doc, visit) {
500
+ const walkNode = (value, around) => {
501
+ if (!isRecord(value))
502
+ return;
503
+ const within = visit.node ? visit.node(value, around) : around;
504
+ if (value.node === "workflow")
505
+ return walkWorkflow(value.workflow, within);
506
+ for (const child of childNodes(value))
507
+ walkNode(child, within);
508
+ };
509
+ const walkWorkflow = (value, around) => {
510
+ if (!isRecord(value))
511
+ return;
512
+ visit.workflow?.(value);
513
+ walkNode(value.root, around);
514
+ };
515
+ walkWorkflow(doc, 1);
516
+ }
517
+ /** Every workflow in `doc` with its schemas: the draft's own and each composed workflow node's child, at any depth. */
518
+ function workflowsOf(doc) {
519
+ const out = [];
520
+ eachWorkflow(doc, { workflow: (workflow) => out.push(workflow) });
521
+ return out;
522
+ }
523
+ /** The keywords whose values are schemas, by shape: a map of them, a list of them, or one (a list too, for items). Every
524
+ * other keyword's value (const, enum, default, examples, a title) is data, never a schema. */
525
+ const SCHEMA_MAPS = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"];
526
+ const SCHEMA_LISTS = ["anyOf", "oneOf", "allOf", "prefixItems"];
527
+ const SCHEMA_ONES = ["items", "additionalItems", "additionalProperties", "contains", "not", "if", "then", "else", "propertyNames", "unevaluatedItems", "unevaluatedProperties"];
528
+ /** Each schema in `schema`, itself first, at schema positions only (each once). */
529
+ function eachSchema(schema, visit, seen = new Set()) {
530
+ if (!isRecord(schema) || seen.has(schema))
531
+ return;
532
+ seen.add(schema);
533
+ visit(schema);
534
+ for (const key of SCHEMA_MAPS)
535
+ if (isRecord(schema[key]))
536
+ for (const sub of Object.values(schema[key]))
537
+ eachSchema(sub, visit, seen);
538
+ for (const key of SCHEMA_LISTS)
539
+ if (Array.isArray(schema[key]))
540
+ for (const sub of schema[key])
541
+ eachSchema(sub, visit, seen);
542
+ for (const key of SCHEMA_ONES)
543
+ for (const sub of Array.isArray(schema[key]) ? schema[key] : [schema[key]])
544
+ eachSchema(sub, visit, seen);
545
+ }
546
+ /** The most iterations one loop of a learned draft may run (its maxIters), and the most nested loops may run together
547
+ * (their maxIters multiplied, outermost to innermost). A loop's iterations are work the dry run does in the host whether
548
+ * or not its body asks a model (an empty map, a predicate), so they are bounded here, not only by the dry run's steps. */
549
+ export const LEARNED_MAX_ITERS = 50;
550
+ export const LEARNED_LOOP_ITERS = 1_000;
551
+ /** Why `doc`'s loops could run too long: a loop whose maxIters is past LEARNED_MAX_ITERS, or nested loops whose maxIters
552
+ * multiply past LEARNED_LOOP_ITERS, a composed workflow node's child's included. Read from the JSON alone, at node
553
+ * positions only (eachWorkflow): a literal shaped like a loop is data. */
554
+ export function loopProblems(doc) {
555
+ const problems = [];
556
+ eachWorkflow(doc, {
557
+ node: (node, around) => {
558
+ if (node.node !== "loop")
559
+ return around;
560
+ const iters = typeof node.maxIters === "number" ? node.maxIters : 0;
561
+ const label = JSON.stringify(String(node.label ?? "").slice(0, 64));
562
+ const within = around * iters;
563
+ if (iters > LEARNED_MAX_ITERS)
564
+ problems.push(`its loop ${label} runs up to maxIters ${iters} times (the most is ${LEARNED_MAX_ITERS})`);
565
+ else if (within > LEARNED_LOOP_ITERS)
566
+ problems.push(`its loop ${label} and the loops around it run up to ${within} times together, their maxIters multiplied (the most is ${LEARNED_LOOP_ITERS})`);
567
+ return within;
568
+ },
569
+ });
570
+ return problems;
571
+ }
572
+ /** Why a dry run of `doc` would build too much in the host: a schema whose minItems or minLength is past its cap, or
573
+ * whose synthesized instance holds more values or characters than SYNTH_VALUES or SYNTH_CHARS. Empty when none. Each
574
+ * schema is counted as the dry run reads it, after the same resolution (`dsl.resolveSchemaForWorkflow`), so a `$ref` a
575
+ * schema's own (even empty) definitions would hide is counted as the dry run fills it in. Building nothing. */
576
+ export function synthesisProblems(doc, dsl) {
577
+ const problems = [];
578
+ for (const workflow of workflowsOf(doc)) {
579
+ const schemas = workflow.schemas && typeof workflow.schemas === "object" ? workflow.schemas : {};
580
+ for (const [id, raw] of Object.entries(schemas)) {
581
+ // One count per schema: a `$ref` resolves against that schema's own definitions.
582
+ const seen = new Map();
583
+ let schema;
584
+ try {
585
+ schema = raw && typeof raw === "object" ? dsl.resolveSchemaForWorkflow({ schemas }, raw) : raw;
586
+ }
587
+ catch (error) {
588
+ problems.push(`its schema ${JSON.stringify(id.slice(0, 64))} could not be resolved as its dry run would: ${String(error?.message ?? error).slice(0, 200)}`);
589
+ continue;
590
+ }
591
+ // Each cap, on each schema in the schema (eachSchema: schema positions only; a literal that holds the keyword is
592
+ // data).
593
+ const caps = new Set();
594
+ eachSchema(schema, (spec) => {
595
+ if (typeof spec.minItems === "number" && spec.minItems > SYNTH_MIN_ITEMS)
596
+ caps.add(`minItems ${spec.minItems} (the most is ${SYNTH_MIN_ITEMS})`);
597
+ if (typeof spec.minLength === "number" && spec.minLength > SYNTH_MIN_LENGTH)
598
+ caps.add(`minLength ${spec.minLength} (the most is ${SYNTH_MIN_LENGTH})`);
599
+ });
600
+ const definitions = schema?.definitions ?? schemas;
601
+ const size = synthesized(schema, definitions, 0, seen);
602
+ if (size.values > SYNTH_VALUES)
603
+ caps.add(`${size.values > 1e12 ? "over a trillion" : size.values} values (the most is ${SYNTH_VALUES})`);
604
+ if (size.chars > SYNTH_CHARS)
605
+ caps.add(`${size.chars > 1e12 ? "over a trillion" : size.chars} characters (the most is ${SYNTH_CHARS})`);
606
+ if (caps.size)
607
+ problems.push(`its schema ${JSON.stringify(id.slice(0, 64))} would have its dry run synthesize too large a value: ${[...caps].join(", ")}`);
608
+ }
609
+ }
610
+ return problems;
611
+ }
612
+ /** A draft's workflow.json `json` dry-run by the workflow DSL (dryRunWorkflow) on `example` (its block's `example:`
613
+ * line, one JSON object), else on an input synthesized from its input schema. Every model, Jev and tool-call answer is
614
+ * synthesized from the node's output schema: no request is sent, nothing is paid, no tool runs, and no code it holds
615
+ * runs in this process (refuseCode). Only a draft the static checks pass is dry-run (propose.ts). It checks the wiring
616
+ * at run time (the state each step reads, its output's path and schema), never the answers. */
617
+ export async function draftDryRun(dsl, json, example) {
618
+ let doc;
619
+ let input;
620
+ try {
621
+ doc = JSON.parse(json);
622
+ }
623
+ catch {
624
+ return { status: "failed", detail: `${DRY_RUN_FAILED}: it does not parse as JSON` };
625
+ }
626
+ if (example !== undefined) {
627
+ let given;
628
+ try {
629
+ given = JSON.parse(example);
630
+ }
631
+ catch {
632
+ given = undefined;
633
+ }
634
+ if (typeof given !== "object" || given === null || Array.isArray(given))
635
+ return { status: "failed", detail: `${DRY_RUN_FAILED}: its example: line is not one JSON object` };
636
+ input = given;
637
+ }
638
+ // Nothing is synthesized or looped past the bounds: a draft whose schemas would build too much, or whose loops could run
639
+ // too long, stands down here before the DSL runs any of it (the static checks refuse it first; this holds for a draft
640
+ // handed here anyway).
641
+ const tooLarge = [...synthesisProblems(doc, dsl), ...loopProblems(doc)];
642
+ if (tooLarge.length)
643
+ return { status: "not_run", detail: tooLarge.join("; ").slice(0, 300) };
644
+ let result;
645
+ try {
646
+ result = await dsl.dryRunWorkflow(doc, { ...(input ? { input } : {}), maxSteps: DRY_RUN_STEPS, runCode: refuseCode, signal: AbortSignal.timeout(DRY_RUN_MS) });
647
+ }
648
+ catch (error) {
649
+ return { status: "failed", detail: `${DRY_RUN_FAILED}: ${String(error?.message ?? error).slice(0, 300)}` };
650
+ }
651
+ if (result.ok)
652
+ return result.status === "passed" ? { status: "passed" } : { status: "not_run", detail: (result.skipped ?? []).join("; ").slice(0, 300) || "a check could not run" };
653
+ return { status: "failed", detail: `${DRY_RUN_FAILED}${result.stage ? ` at "${result.stage.slice(0, 64)}"` : ""}: ${result.problems.join("; ").slice(0, 300)}` };
164
654
  }
165
655
  /** The refusal for a draft that names a tool when the host gave no tool list: the check fails closed. */
166
656
  export const NO_TOOL_LIST = "no tool list was given, so a draft that names a tool is refused";
@@ -208,6 +698,97 @@ const gatedNodes = (dsl, doc, gated, deniedBy) => dsl.inspectWorkflow(doc).nodes
208
698
  : `This workflow's call node calls ${tool}, which is set to ask, and a workflow's call node can't wait for an approval: set it to allow for this agent.`;
209
699
  return [{ rule: "workflow", detail: `${words} (the call node at ${node.path})` }];
210
700
  });
701
+ /** An MCP tool a learned workflow's call node may run, by its address (`via: "tool"`, `tool: "mcp:<server>/<tool>"`,
702
+ * LS-07): its server's name as a server is named (mcp-probe.ts MCP_SERVER_NAME) and one tool's name in MCP's own
703
+ * charset, never a wildcard. The one rule for it: the tools a draft may name (tools.ts learnedWorkflowTools), the
704
+ * end-of-run prompt that prints them (reflect.ts), and what the grader is told of a draft (grade.ts). */
705
+ export const LEARNED_MCP_TOOL = /^mcp:[a-z][a-z0-9-]{0,31}\/[A-Za-z0-9_][A-Za-z0-9._-]{0,127}$/;
706
+ /** The MCP tools a draft's call nodes run, each once, in the order they come (LS-07): every call node in `doc`, nested
707
+ * ones too, whose tool is an MCP tool's address. Read from the JSON as it is, for the grader's words; never a check. */
708
+ export function draftMcpTools(doc) {
709
+ const found = new Set();
710
+ for (const node of callNodes(doc))
711
+ if (node.via === "tool" && typeof node.tool === "string" && LEARNED_MCP_TOOL.test(node.tool))
712
+ found.add(node.tool);
713
+ return [...found];
714
+ }
715
+ /** Every call node of `doc` (a parsed workflow.json), in document order: only the workflow's node positions, as the
716
+ * DSL's inspection visits them (its root, a chain's steps, a parallel's branches, a map's and a loop's body, a route's
717
+ * branches' bodies, a nested workflow's root), never an object in a call's args, a schema or any other data, however
718
+ * it is shaped. Walked with a stack of its own, never the call stack, so no draft's nesting can throw here. */
719
+ function callNodes(doc) {
720
+ const out = [];
721
+ const asNode = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : undefined);
722
+ const stack = [asNode(doc)?.root];
723
+ while (stack.length) {
724
+ const node = asNode(stack.pop());
725
+ if (!node)
726
+ continue;
727
+ if (node.node === "call")
728
+ out.push(node);
729
+ const children = node.node === "chain" && Array.isArray(node.steps) ? node.steps
730
+ : node.node === "parallel" && Array.isArray(node.branches) ? node.branches
731
+ : (node.node === "map" || node.node === "loop") ? [node.body]
732
+ : node.node === "route" && asNode(node.branches) ? Object.values(node.branches).map((branch) => asNode(branch)?.body)
733
+ : node.node === "workflow" ? [asNode(node.workflow)?.root]
734
+ : [];
735
+ for (let i = children.length - 1; i >= 0; i--)
736
+ stack.push(children[i]);
737
+ }
738
+ return out;
739
+ }
740
+ /** The call nodes of a learned workflow (`doc`, its parsed workflow.json, nested ones too) whose tool is an MCP tool
741
+ * (LEARNED_MCP_TOOL) that `priceOf` gives no price for (mcp-probe.ts McpPrices: none declared). Such a tool runs "not
742
+ * metered", outside the run's cost and cap (mcp-gateway.ts), so a learned workflow that calls one unattended waits for
743
+ * its owner's OK whatever the grade (LS-07): a structural fact, held in code. Each step once, in order. */
744
+ export function unpricedCalls(doc, priceOf) {
745
+ return callNodes(doc).flatMap((node) => {
746
+ if (node.via !== "tool" || typeof node.tool !== "string" || !LEARNED_MCP_TOOL.test(node.tool) || priceOf(node.tool) !== undefined)
747
+ return [];
748
+ const [server, tool] = node.tool.slice("mcp:".length).split("/");
749
+ return [{ label: typeof node.label === "string" ? node.label : "(unnamed)", tool, server }];
750
+ });
751
+ }
752
+ /** Why a learned workflow that calls `call` waits for its owner's OK, in a person's words. */
753
+ export const unpricedLine = (call) => `its step ${call.label} calls ${call.tool} on ${call.server}, which has no price here, so it runs outside the run's cost and cap`;
754
+ /** Every string a learned workflow's workflow.json decodes to, each object's keys too, as JSON.parse reads them (its
755
+ * escapes decoded: what draftProblems and a learned call's run read, and a model node is given). Text a scan of the
756
+ * stored JSON misses, spelled in \u escapes, is there as it will be read. None for a text that does not parse (the
757
+ * checks refuse it as no workflow). */
758
+ export function decodedStrings(json) {
759
+ let doc;
760
+ try {
761
+ doc = JSON.parse(json);
762
+ }
763
+ catch {
764
+ return [];
765
+ }
766
+ // Walked with a stack of its own, never the call stack, and no deeper than DECODED_DEPTH: a draft nested past any
767
+ // workflow (thousands of arrays in a few KB) is refused on its own (check.ts), never a throw that takes its siblings.
768
+ const out = [];
769
+ const stack = [[doc, 0]];
770
+ while (stack.length) {
771
+ const [value, depth] = stack.pop();
772
+ if (typeof value === "string") {
773
+ out.push(value);
774
+ continue;
775
+ }
776
+ if (!value || typeof value !== "object")
777
+ continue;
778
+ if (depth >= DECODED_DEPTH)
779
+ return "too_deep";
780
+ if (Array.isArray(value))
781
+ for (let i = value.length - 1; i >= 0; i--)
782
+ stack.push([value[i], depth + 1]);
783
+ else
784
+ for (const [key, child] of Object.entries(value).reverse())
785
+ stack.push([child, depth + 1], [key, depth + 1]);
786
+ }
787
+ return out;
788
+ }
789
+ /** How deep a learned workflow's JSON may nest (decodedStrings): far past any workflow the DSL writes, a node's schemas
790
+ * included, and short of what a walk of it could not bound. */
791
+ export const DECODED_DEPTH = 100;
211
792
  /** The most turns a learned workflow's model node runs (learned-workflow.ts hands its runner this cap): an agent node
212
793
  * that asks for more is refused at learn time and before a call, never when it comes up after earlier nodes spent. */
213
794
  export const LEARNED_MAX_TURNS = 8;
@@ -240,13 +821,7 @@ const issuesOf = (dsl, doc, tools) => {
240
821
  const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
241
822
  return valid.ok ? [] : valid.issues;
242
823
  };
243
- /** Why `workflows/<name>/workflow.json` is not a draft the host can run; empty when it is. The DSL's own
244
- * `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
245
- * and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
246
- * apply_patch) is never on the list. A model node that names any tool is refused (MODEL_NODE_TOOLS), and a node the
247
- * learned runner cannot run (LEARNED_NODES: a judge's). With no list it
248
- * fails closed: a draft the DSL refuses only once given an empty list names a tool. */
249
- export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}) {
824
+ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask) {
250
825
  let doc;
251
826
  try {
252
827
  doc = JSON.parse(text);
@@ -262,12 +837,17 @@ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}) {
262
837
  return issues.slice(0, 5).map((issue) => ({ rule: "workflow", detail: `the workflow DSL refuses it: ${issue.code} at ${issue.path || "/"}: ${issue.message.slice(0, 200)}` }));
263
838
  let out;
264
839
  try {
265
- out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy)];
840
+ out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
266
841
  // A learned workflow answers the value at its output's path: one that names none would answer its whole state, which
267
842
  // fails its output schema when the call ends, after every node spent.
268
843
  const path = doc?.output?.path;
269
844
  if (typeof path !== "string" || !path)
270
845
  out.push({ rule: "workflow", detail: LEARNED_OUTPUT_PATH });
846
+ // Its MCP tools set to ask, on one approval card per learned call (#2424): a card that can't name them all is refused
847
+ // at the gate at every call, so the draft is refused here, in the gate's words.
848
+ const asks = ask ? draftMcpTools(doc).filter((tool) => ask.asked.includes(tool)) : [];
849
+ if (ask && asks.length && !ask.fits(asks))
850
+ out.push({ rule: "workflow", detail: `its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.` });
271
851
  // A composed workflow node's child too: its output is the value at its own output.path, or it fails the same way.
272
852
  for (const node of dsl.inspectWorkflow(doc).nodes) {
273
853
  if (node.kind !== "workflow")