@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.38

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 (568) hide show
  1. package/CHANGELOG.md +452 -0
  2. package/README.md +311 -142
  3. package/dist/agent-rows.d.ts +1 -1
  4. package/dist/agents-store.d.ts +35 -3
  5. package/dist/agents-store.js +39 -14
  6. package/dist/answer-json.d.ts +34 -1
  7. package/dist/answer-json.js +91 -9
  8. package/dist/api-only.d.ts +1 -1
  9. package/dist/api-only.js +2 -2
  10. package/dist/attach-conformance-cli.d.ts +1 -0
  11. package/dist/attach-conformance-cli.js +18 -0
  12. package/dist/attach-conformance.d.ts +25 -0
  13. package/dist/attach-conformance.js +343 -0
  14. package/dist/browser-cost.d.ts +1 -1
  15. package/dist/browser-cost.js +52 -93
  16. package/dist/browser-live.d.ts +20 -8
  17. package/dist/browser-live.js +50 -27
  18. package/dist/cap.d.ts +0 -407
  19. package/dist/cap.js +4 -1028
  20. package/dist/catalog.d.ts +1 -12
  21. package/dist/catalog.js +4 -34
  22. package/dist/cli.js +13 -4
  23. package/dist/composio-preset.d.ts +53 -0
  24. package/dist/composio-preset.js +221 -0
  25. package/dist/computer-attach.d.ts +125 -0
  26. package/dist/computer-attach.js +330 -0
  27. package/dist/computer-calls.d.ts +60 -0
  28. package/dist/computer-calls.js +209 -0
  29. package/dist/computer-channel.d.ts +57 -0
  30. package/dist/computer-channel.js +115 -0
  31. package/dist/computer-commands.d.ts +1 -1
  32. package/dist/computer-held-routes.d.ts +35 -0
  33. package/dist/computer-held-routes.js +106 -0
  34. package/dist/computer-held.d.ts +48 -0
  35. package/dist/computer-held.js +87 -0
  36. package/dist/computer-keys.d.ts +21 -1
  37. package/dist/computer-keys.js +53 -11
  38. package/dist/computer-live.d.ts +165 -0
  39. package/dist/computer-live.js +655 -0
  40. package/dist/computer-setting.d.ts +15 -2
  41. package/dist/computer-setting.js +20 -4
  42. package/dist/computer-view.d.ts +14 -0
  43. package/dist/computer-view.js +51 -3
  44. package/dist/computer-viewer.d.ts +6 -0
  45. package/dist/computer-viewer.js +311 -0
  46. package/dist/computers.d.ts +37 -8
  47. package/dist/computers.js +62 -14
  48. package/dist/console/assets/index-CjqQirbo.css +1 -0
  49. package/dist/console/assets/index-b6-XY5A9.js +576 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/console-links.d.ts +2 -0
  52. package/dist/console-links.js +3 -0
  53. package/dist/decisions.js +4 -0
  54. package/dist/faux-computers.d.ts +9 -20
  55. package/dist/faux-computers.js +56 -26
  56. package/dist/github-connection.d.ts +10 -2
  57. package/dist/github-connection.js +65 -2
  58. package/dist/github-faux.js +1 -1
  59. package/dist/graph-view.d.ts +1 -1
  60. package/dist/harness-opencode/adapter.js +7 -3
  61. package/dist/harness-opencode/facts.js +0 -2
  62. package/dist/harness-opencode/host/policy.d.ts +2 -5
  63. package/dist/harness-opencode/host/policy.js +8 -32
  64. package/dist/harness-table.d.ts +0 -2
  65. package/dist/harness-table.js +0 -2
  66. package/dist/harness.d.ts +1 -0
  67. package/dist/harness.js +35 -1
  68. package/dist/host-tools.d.ts +2 -6
  69. package/dist/host-tools.js +7 -10
  70. package/dist/hosted-search.d.ts +5 -6
  71. package/dist/hosted-search.js +2 -28
  72. package/dist/import-sources.d.ts +10 -0
  73. package/dist/import-sources.js +44 -2
  74. package/dist/import.d.ts +3 -3
  75. package/dist/import.js +37 -6
  76. package/dist/key-words.d.ts +3 -2
  77. package/dist/key-words.js +4 -2
  78. package/dist/learn/check.d.ts +10 -2
  79. package/dist/learn/check.js +13 -5
  80. package/dist/learn/commit.d.ts +14 -2
  81. package/dist/learn/commit.js +23 -9
  82. package/dist/learn/compile.d.ts +243 -0
  83. package/dist/learn/compile.js +471 -0
  84. package/dist/learn/folder.d.ts +6 -0
  85. package/dist/learn/folder.js +4 -1
  86. package/dist/learn/general.d.ts +69 -0
  87. package/dist/learn/general.js +75 -0
  88. package/dist/learn/grade.d.ts +5 -1
  89. package/dist/learn/grade.js +29 -7
  90. package/dist/learn/notes.d.ts +8 -0
  91. package/dist/learn/notes.js +18 -0
  92. package/dist/learn/promote.d.ts +253 -0
  93. package/dist/learn/promote.js +428 -0
  94. package/dist/learn/refit.d.ts +39 -0
  95. package/dist/learn/refit.js +236 -0
  96. package/dist/learn/reflect.d.ts +9 -20
  97. package/dist/learn/reflect.js +18 -125
  98. package/dist/learn/replay-calls.d.ts +63 -0
  99. package/dist/learn/replay-calls.js +158 -0
  100. package/dist/learn/skills.d.ts +50 -14
  101. package/dist/learn/skills.js +183 -47
  102. package/dist/learn/workflow-nodes.d.ts +15 -0
  103. package/dist/learn/workflow-nodes.js +44 -0
  104. package/dist/learned-nodes.d.ts +50 -2
  105. package/dist/learned-nodes.js +41 -2
  106. package/dist/learned-workflow.d.ts +43 -3
  107. package/dist/learned-workflow.js +170 -28
  108. package/dist/learning-batch.d.ts +283 -0
  109. package/dist/learning-batch.js +574 -0
  110. package/dist/learning-cost.d.ts +18 -6
  111. package/dist/learning-cost.js +15 -7
  112. package/dist/learning-evals.d.ts +33 -0
  113. package/dist/learning-evals.js +98 -0
  114. package/dist/learning-routes.d.ts +37 -2
  115. package/dist/learning-routes.js +52 -8
  116. package/dist/learning-words.d.ts +13 -0
  117. package/dist/learning-words.js +13 -0
  118. package/dist/learning.d.ts +55 -17
  119. package/dist/learning.js +91 -48
  120. package/dist/live/stream.js +6 -3
  121. package/dist/live/translate.d.ts +4 -3
  122. package/dist/live/translate.js +8 -4
  123. package/dist/live-reach.d.ts +37 -0
  124. package/dist/live-reach.js +62 -0
  125. package/dist/llm.js +0 -3
  126. package/dist/mcp-gateway.d.ts +21 -20
  127. package/dist/mcp-gateway.js +76 -55
  128. package/dist/mcp-oauth.d.ts +62 -7
  129. package/dist/mcp-oauth.js +134 -19
  130. package/dist/mcp-pin-first.d.ts +37 -0
  131. package/dist/mcp-pin-first.js +107 -0
  132. package/dist/mcp-private-hosts.d.ts +4 -4
  133. package/dist/mcp-private-hosts.js +20 -12
  134. package/dist/mcp-probe.d.ts +27 -11
  135. package/dist/mcp-probe.js +60 -42
  136. package/dist/mcp-secret-writes.js +4 -0
  137. package/dist/mcp-servers-store.d.ts +115 -25
  138. package/dist/mcp-servers-store.js +241 -43
  139. package/dist/mcp-sources.d.ts +39 -0
  140. package/dist/mcp-sources.js +74 -0
  141. package/dist/mcp-store.d.ts +21 -4
  142. package/dist/mcp-store.js +33 -8
  143. package/dist/mcp-wire.d.ts +22 -0
  144. package/dist/mcp-wire.js +36 -0
  145. package/dist/mcp.js +3 -3
  146. package/dist/meta-tool-names.d.ts +1 -0
  147. package/dist/meta-tool-names.js +3 -0
  148. package/dist/model-form.d.ts +26 -0
  149. package/dist/model-form.js +80 -0
  150. package/dist/model.d.ts +13 -0
  151. package/dist/model.js +69 -25
  152. package/dist/monid.d.ts +51 -25
  153. package/dist/monid.js +226 -140
  154. package/dist/openapi.js +694 -59
  155. package/dist/page.d.ts +18 -0
  156. package/dist/page.js +48 -20
  157. package/dist/paid-calls.d.ts +26 -29
  158. package/dist/paid-calls.js +46 -102
  159. package/dist/place-offers.d.ts +2 -3
  160. package/dist/place-offers.js +3 -7
  161. package/dist/place.js +1 -2
  162. package/dist/print.d.ts +15 -1
  163. package/dist/print.js +14 -3
  164. package/dist/propose.d.ts +10 -1
  165. package/dist/propose.js +30 -10
  166. package/dist/provider.js +12 -4
  167. package/dist/reflect-range.d.ts +8 -1
  168. package/dist/reflect-range.js +3 -2
  169. package/dist/rows.d.ts +5 -3
  170. package/dist/rows.js +15 -4
  171. package/dist/run-launch.d.ts +27 -2
  172. package/dist/run-launch.js +15 -4
  173. package/dist/run-learning-served.d.ts +13 -2
  174. package/dist/run-manifest.d.ts +5 -0
  175. package/dist/run-manifest.js +20 -0
  176. package/dist/run-reads-over-store.d.ts +1 -1
  177. package/dist/run-repo.d.ts +20 -0
  178. package/dist/run-repo.js +63 -0
  179. package/dist/run-secrets.js +2 -3
  180. package/dist/run-timeline-served.d.ts +1 -1
  181. package/dist/run-timeline-served.js +5 -2
  182. package/dist/run-view.d.ts +19 -8
  183. package/dist/run-view.js +62 -26
  184. package/dist/runnable.d.ts +0 -3
  185. package/dist/runnable.js +37 -29
  186. package/dist/runner/adapter-loop.d.ts +47 -17
  187. package/dist/runner/adapter-loop.js +1427 -303
  188. package/dist/runner/adapter-run-spec.d.ts +23 -9
  189. package/dist/runner/adapter-run-spec.js +162 -56
  190. package/dist/runner/adapters/pi-computer.d.ts +9 -0
  191. package/dist/runner/adapters/pi-computer.js +51 -0
  192. package/dist/runner/adapters/pi.d.ts +25 -11
  193. package/dist/runner/adapters/pi.js +168 -45
  194. package/dist/runner/beside.d.ts +7 -3
  195. package/dist/runner/beside.js +21 -11
  196. package/dist/runner/claim-secrets.d.ts +4 -0
  197. package/dist/runner/claim-secrets.js +6 -1
  198. package/dist/runner/cli-run-spec.d.ts +20 -3
  199. package/dist/runner/cli-run-spec.js +174 -64
  200. package/dist/runner/commands.d.ts +3 -1
  201. package/dist/runner/commands.js +28 -3
  202. package/dist/runner/computer-channel.d.ts +34 -0
  203. package/dist/runner/computer-channel.js +62 -0
  204. package/dist/runner/conformance/harness.d.ts +3 -0
  205. package/dist/runner/conformance/harness.js +224 -17
  206. package/dist/runner/conformance/subject.d.ts +12 -5
  207. package/dist/runner/dispatch.js +3 -0
  208. package/dist/runner/end-of-run.d.ts +23 -12
  209. package/dist/runner/end-of-run.js +41 -16
  210. package/dist/runner/feedback-round.d.ts +52 -0
  211. package/dist/runner/feedback-round.js +79 -0
  212. package/dist/runner/github-app.d.ts +2 -1
  213. package/dist/runner/github-app.js +4 -2
  214. package/dist/runner/harness-loops.js +15 -1
  215. package/dist/runner/held-run.d.ts +65 -0
  216. package/dist/runner/held-run.js +158 -0
  217. package/dist/runner/journal-kinds.d.ts +44 -7
  218. package/dist/runner/journal-kinds.js +29 -0
  219. package/dist/runner/journal-reader.d.ts +5 -4
  220. package/dist/runner/journal-reader.js +12 -10
  221. package/dist/runner/learning-ask.d.ts +7 -1
  222. package/dist/runner/learning-ask.js +21 -6
  223. package/dist/runner/learning-dispatch.d.ts +22 -0
  224. package/dist/runner/learning-dispatch.js +77 -10
  225. package/dist/runner/learning-end.d.ts +69 -13
  226. package/dist/runner/learning-end.js +340 -87
  227. package/dist/runner/learning-factory.d.ts +1 -1
  228. package/dist/runner/learning-factory.js +11 -5
  229. package/dist/runner/learning-loop.d.ts +86 -8
  230. package/dist/runner/learning-loop.js +178 -23
  231. package/dist/runner/learning-seed.d.ts +11 -0
  232. package/dist/runner/learning-seed.js +27 -0
  233. package/dist/runner/live-ticker.js +1 -0
  234. package/dist/runner/loop-contract.d.ts +26 -3
  235. package/dist/runner/loop.d.ts +21 -2
  236. package/dist/runner/loop.js +23 -2
  237. package/dist/runner/main.d.ts +13 -1
  238. package/dist/runner/main.js +27 -5
  239. package/dist/runner/mcp-claim.d.ts +15 -8
  240. package/dist/runner/mcp-claim.js +176 -71
  241. package/dist/runner/mcp-github.js +1 -1
  242. package/dist/runner/mcp-run.d.ts +21 -57
  243. package/dist/runner/mcp-run.js +25 -85
  244. package/dist/runner/meta-tools.d.ts +37 -0
  245. package/dist/runner/meta-tools.js +268 -0
  246. package/dist/runner/metrics.d.ts +11 -2
  247. package/dist/runner/metrics.js +26 -5
  248. package/dist/runner/model-route.js +12 -3
  249. package/dist/runner/monid-run.d.ts +16 -0
  250. package/dist/runner/monid-run.js +96 -0
  251. package/dist/runner/pr-checkout.d.ts +1 -0
  252. package/dist/runner/pr-checkout.js +1 -1
  253. package/dist/runner/promotion.d.ts +80 -0
  254. package/dist/runner/promotion.js +562 -0
  255. package/dist/runner/reflect-hook.d.ts +46 -13
  256. package/dist/runner/reflect-hook.js +149 -48
  257. package/dist/runner/runner.d.ts +26 -0
  258. package/dist/runner/runner.js +208 -17
  259. package/dist/runner/scratch-sweep.d.ts +13 -0
  260. package/dist/runner/scratch-sweep.js +62 -0
  261. package/dist/runner/sessions.d.ts +9 -4
  262. package/dist/runner/sessions.js +5 -1
  263. package/dist/runner/step-guard.d.ts +62 -0
  264. package/dist/runner/step-guard.js +93 -0
  265. package/dist/runner/store-port.d.ts +4 -2
  266. package/dist/runner/store-secrets.js +4 -3
  267. package/dist/runner/subagent.d.ts +0 -3
  268. package/dist/runner/subagent.js +10 -13
  269. package/dist/runner/workflow-first.d.ts +216 -0
  270. package/dist/runner/workflow-first.js +303 -0
  271. package/dist/runner/workflow-host.d.ts +6 -1
  272. package/dist/runner/workflow-host.js +1 -1
  273. package/dist/runner/workflow-loop.d.ts +1 -1
  274. package/dist/runner/workflow-loop.js +17 -10
  275. package/dist/runner/workflow-spec.d.ts +15 -2
  276. package/dist/runner/workflow-spec.js +63 -23
  277. package/dist/runs-over-store.d.ts +17 -3
  278. package/dist/runs-over-store.js +59 -20
  279. package/dist/seal-key.js +3 -3
  280. package/dist/sealed-settings-store.d.ts +5 -2
  281. package/dist/sealed-settings-store.js +10 -4
  282. package/dist/secret-writes.d.ts +5 -4
  283. package/dist/secret-writes.js +5 -4
  284. package/dist/server-secrets-store.d.ts +4 -3
  285. package/dist/server-secrets-store.js +15 -9
  286. package/dist/server-secrets.js +3 -2
  287. package/dist/server.d.ts +119 -18
  288. package/dist/server.js +841 -202
  289. package/dist/settings-wake.d.ts +23 -0
  290. package/dist/settings-wake.js +65 -0
  291. package/dist/standard-webhooks.d.ts +4 -1
  292. package/dist/standard-webhooks.js +8 -4
  293. package/dist/store/agent-body.d.ts +14 -3
  294. package/dist/store/agent-body.js +14 -10
  295. package/dist/store/command-wake.d.ts +13 -0
  296. package/dist/store/command-wake.js +37 -0
  297. package/dist/store/dialect.d.ts +6 -0
  298. package/dist/store/dialect.js +5 -0
  299. package/dist/store/index.d.ts +1 -1
  300. package/dist/store/journal/storage.d.ts +3 -2
  301. package/dist/store/journal/storage.js +13 -5
  302. package/dist/store/postgres/connection.js +3 -1
  303. package/dist/store/postgres/dialect.js +4 -0
  304. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  305. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  306. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  307. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  308. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  309. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  310. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  311. package/dist/store/schema.d.ts +10 -1
  312. package/dist/store/schema.js +104 -15
  313. package/dist/store/sqlite/connection.d.ts +2 -2
  314. package/dist/store/sqlite/connection.js +2 -2
  315. package/dist/store/sqlite/run-patch.d.ts +7 -5
  316. package/dist/store/sqlite/run-patch.js +45 -18
  317. package/dist/store/sqlite/store.js +331 -72
  318. package/dist/store/store.d.ts +312 -21
  319. package/dist/store/store.js +12 -1
  320. package/dist/store-reads/cap.d.ts +1 -1
  321. package/dist/store-reads/cap.js +8 -1
  322. package/dist/store-reads/decisions.d.ts +2 -2
  323. package/dist/store-reads/decisions.js +1 -1
  324. package/dist/store-reads/import-summary.d.ts +1 -1
  325. package/dist/store-reads/journal.d.ts +30 -5
  326. package/dist/store-reads/journal.js +128 -56
  327. package/dist/store-reads/learning.d.ts +114 -12
  328. package/dist/store-reads/learning.js +238 -48
  329. package/dist/store-reads/loop.d.ts +61 -0
  330. package/dist/store-reads/loop.js +111 -0
  331. package/dist/store-reads/runs.d.ts +1 -1
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-view.d.ts +6 -0
  334. package/dist/store-view.js +59 -26
  335. package/dist/template-eval.d.ts +18 -9
  336. package/dist/template-eval.js +95 -68
  337. package/dist/template-github-permissions.d.ts +24 -10
  338. package/dist/template-github-permissions.js +36 -15
  339. package/dist/template-import.d.ts +31 -0
  340. package/dist/template-import.js +121 -0
  341. package/dist/template-source.d.ts +51 -0
  342. package/dist/template-source.js +371 -0
  343. package/dist/templates.d.ts +218 -46
  344. package/dist/templates.js +493 -181
  345. package/dist/timeline/computer.d.ts +48 -0
  346. package/dist/timeline/computer.js +169 -0
  347. package/dist/timeline/index.d.ts +4 -3
  348. package/dist/timeline/index.js +4 -3
  349. package/dist/timeline/labels.d.ts +6 -2
  350. package/dist/timeline/labels.js +93 -2
  351. package/dist/timeline/origin.d.ts +19 -5
  352. package/dist/timeline/origin.js +11 -4
  353. package/dist/timeline/timeline.d.ts +22 -1
  354. package/dist/timeline/timeline.js +34 -18
  355. package/dist/timeline/util.d.ts +4 -0
  356. package/dist/timeline/util.js +14 -0
  357. package/dist/tool-gate.d.ts +84 -50
  358. package/dist/tool-gate.js +179 -101
  359. package/dist/tool-keys.d.ts +4 -1
  360. package/dist/tool-keys.js +8 -3
  361. package/dist/tool-list.d.ts +26 -0
  362. package/dist/tool-list.js +43 -0
  363. package/dist/tool-names.d.ts +71 -0
  364. package/dist/tool-names.js +99 -0
  365. package/dist/tool-plane.d.ts +33 -27
  366. package/dist/tool-plane.js +72 -39
  367. package/dist/tools.d.ts +32 -7
  368. package/dist/tools.js +37 -24
  369. package/dist/trigger-adapter.d.ts +4 -0
  370. package/dist/trigger-secrets-shown.d.ts +2 -2
  371. package/dist/trigger-secrets-shown.js +1 -1
  372. package/dist/trigger-signatures.d.ts +25 -6
  373. package/dist/trigger-signatures.js +41 -7
  374. package/dist/trigger-targets.d.ts +2 -0
  375. package/dist/trigger-targets.js +1 -0
  376. package/dist/trigger-webhook.js +5 -2
  377. package/dist/triggers.d.ts +7 -3
  378. package/dist/triggers.js +35 -5
  379. package/dist/turns.js +16 -1
  380. package/dist/validate.d.ts +15 -7
  381. package/dist/validate.js +102 -45
  382. package/dist/web-fetch.d.ts +2 -8
  383. package/dist/web-fetch.js +2 -22
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +145 -102
  387. package/dist/webhooks.js +559 -322
  388. package/dist/workflow/decisions.d.ts +1 -1
  389. package/dist/workflow/node-runner.d.ts +2 -1
  390. package/dist/workflow/node.d.ts +2 -1
  391. package/dist/workflow/node.js +3 -1
  392. package/dist/workflow/pi-versions.d.ts +23 -0
  393. package/dist/workflow/pi-versions.js +57 -0
  394. package/dist/workflow/record-tool.d.ts +2 -1
  395. package/dist/workflow/store.d.ts +1 -1
  396. package/dist/workflow/task.js +3 -2
  397. package/dist/workflow-run.d.ts +1 -1
  398. package/dist/workspace/attached-computers.d.ts +41 -0
  399. package/dist/workspace/attached-computers.js +114 -0
  400. package/dist/workspace/computer-deps.d.ts +19 -9
  401. package/dist/workspace/computer-deps.js +24 -9
  402. package/dist/workspace/computer-for-claim.d.ts +23 -8
  403. package/dist/workspace/computer-for-claim.js +92 -33
  404. package/dist/workspace/computer-hold.d.ts +11 -27
  405. package/dist/workspace/computer-hold.js +41 -55
  406. package/dist/workspace/computer-ledger.d.ts +3 -1
  407. package/dist/workspace/computer-ledger.js +4 -0
  408. package/dist/workspace/computer-mcp.d.ts +25 -0
  409. package/dist/workspace/computer-mcp.js +41 -0
  410. package/dist/workspace/computer-ports.d.ts +4 -13
  411. package/dist/workspace/computer-ports.js +4 -107
  412. package/dist/workspace/computer-script.d.ts +53 -0
  413. package/dist/workspace/computer-script.js +172 -0
  414. package/dist/workspace/executors.d.ts +1 -1
  415. package/dist/workspace/index.d.ts +4 -2
  416. package/dist/workspace/index.js +3 -1
  417. package/dist/workspace/kind-skills/desktop/SKILL.md +132 -84
  418. package/dist/workspace/kind-skills/phone/SKILL.md +104 -85
  419. package/dist/workspace/local.js +2 -2
  420. package/dist/workspace/resolve-computer.d.ts +24 -1
  421. package/dist/workspace/resolve-computer.js +40 -16
  422. package/dist/workspace/run-tools.d.ts +56 -21
  423. package/dist/workspace/run-tools.js +55 -34
  424. package/dist/wrap-up.d.ts +21 -0
  425. package/dist/wrap-up.js +21 -0
  426. package/launcher/agentrun-serve +4 -2
  427. package/package.json +19 -16
  428. package/templates/README.md +111 -45
  429. package/templates/code-review/agent.md +30 -14
  430. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  431. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  432. package/templates/code-review/evals/injection/case.yaml +2 -1
  433. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  434. package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
  435. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  436. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  437. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  438. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  439. package/templates/code-review/evals/null-name/case.yaml +2 -1
  440. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  441. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  442. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  443. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  444. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  445. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  446. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  447. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  448. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  449. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  450. package/templates/code-review/evals/re-review/case.yaml +2 -1
  451. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  452. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  453. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  454. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  455. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  456. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  457. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  458. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  459. package/templates/code-review/skills/review/DEEP.md +3 -2
  460. package/templates/code-review/skills/review/REVIEWER.md +3 -2
  461. package/templates/code-review/skills/review/SKILL.md +4 -3
  462. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  463. package/templates/inbound-lead/agent.md +26 -16
  464. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  465. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  466. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  467. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  468. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  469. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  470. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  471. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  472. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  473. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  474. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  475. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  476. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  477. package/templates/kyb/agent.md +15 -5
  478. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  479. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  480. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  481. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  482. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  483. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  484. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  485. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  486. package/templates/kyb/kyb.schema.json +8 -7
  487. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  488. package/templates/market-monitor/agent.md +19 -12
  489. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  490. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  491. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  492. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  493. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  494. package/templates/release-notes/agent.md +32 -10
  495. package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
  496. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  497. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  498. package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
  499. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  500. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  501. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  502. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  503. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  504. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  505. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  506. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  507. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  508. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  509. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  510. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  511. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  512. package/templates/release-notes/notes.schema.json +1 -1
  513. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  514. package/dist/console/assets/index-BI4Byidu.js +0 -550
  515. package/dist/console/assets/index-C19gUF2n.css +0 -1
  516. package/dist/run-db.d.ts +0 -53
  517. package/dist/run-db.js +0 -116
  518. package/dist/tool-blurbs.d.ts +0 -4
  519. package/dist/tool-blurbs.js +0 -28
  520. package/dist/tool-budget.d.ts +0 -26
  521. package/dist/tool-budget.js +0 -56
  522. package/dist/workflow/readers.d.ts +0 -36
  523. package/dist/workflow/readers.js +0 -145
  524. package/dist/workflow/wal.d.ts +0 -11
  525. package/dist/workflow/wal.js +0 -106
  526. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  527. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  528. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  529. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  530. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  531. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  532. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  533. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  534. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  535. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  536. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  537. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  538. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  539. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  540. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  541. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  542. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  543. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  544. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  545. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  546. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  547. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  548. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  549. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  550. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  551. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  552. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  553. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  554. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  555. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  556. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  557. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  558. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  559. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  560. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  561. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  562. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  563. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  564. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  565. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  566. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  567. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  568. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -0,0 +1,236 @@
1
+ import { PROMOTE_BAR, SOFT_ESCALATE_THRESHOLD, softEscalatesOf, walkGuards } from "./promote.js";
2
+ import { workflowNodes } from "./workflow-nodes.js";
3
+ /** A switch set off: the guard or the escalate never hands back. Never a threshold the DSL takes (one is in (0, 1)). */
4
+ export const OFF = 0;
5
+ export const FIT_MIN_ROWS = 30;
6
+ /** The lowest and highest threshold a refit writes: the DSL takes a threshold in (0, 1), exclusive. */
7
+ export const THRESHOLD_MIN = 0.001;
8
+ export const THRESHOLD_MAX = 0.999;
9
+ export const FIT_MIN_WRONG = 5;
10
+ const sigmoid = (z) => 1 / (1 + Math.exp(-z));
11
+ const round = (value, places = 4) => Math.round(value * 10 ** places) / 10 ** places;
12
+ /** A logistic fit of y over x (Newton's method with a small ridge, so separable rows stay finite): weights and bias. */
13
+ export function fitLogistic(xs, ys, ridge = 1e-2) {
14
+ const d = xs[0]?.length ?? 0;
15
+ let beta = new Array(d + 1).fill(0);
16
+ for (let iter = 0; iter < 50; iter++) {
17
+ const grad = new Array(d + 1).fill(0);
18
+ const hess = Array.from({ length: d + 1 }, () => new Array(d + 1).fill(0));
19
+ xs.forEach((x, i) => {
20
+ const row = [1, ...x];
21
+ const p = sigmoid(row.reduce((sum, v, j) => sum + v * beta[j], 0));
22
+ const err = (ys[i] ? 1 : 0) - p;
23
+ for (let j = 0; j <= d; j++) {
24
+ grad[j] += err * row[j];
25
+ for (let k = 0; k <= d; k++)
26
+ hess[j][k] += p * (1 - p) * row[j] * row[k];
27
+ }
28
+ });
29
+ for (let j = 1; j <= d; j++) {
30
+ grad[j] -= ridge * beta[j];
31
+ hess[j][j] += ridge;
32
+ }
33
+ const step = solve(hess, grad);
34
+ if (!step)
35
+ break;
36
+ beta = beta.map((v, j) => v + step[j]);
37
+ if (Math.max(...step.map(Math.abs)) < 1e-8)
38
+ break;
39
+ }
40
+ return { w: beta.slice(1).map((v) => round(v, 6)), b: round(beta[0], 6) };
41
+ }
42
+ /** a·x = b by Gaussian elimination with partial pivoting; undefined when singular. */
43
+ function solve(a, b) {
44
+ const n = b.length;
45
+ const m = a.map((row, i) => [...row, b[i]]);
46
+ for (let col = 0; col < n; col++) {
47
+ let pivot = col;
48
+ for (let r = col + 1; r < n; r++)
49
+ if (Math.abs(m[r][col]) > Math.abs(m[pivot][col]))
50
+ pivot = r;
51
+ if (Math.abs(m[pivot][col]) < 1e-12)
52
+ return undefined;
53
+ [m[col], m[pivot]] = [m[pivot], m[col]];
54
+ for (let r = 0; r < n; r++) {
55
+ if (r === col)
56
+ continue;
57
+ const f = m[r][col] / m[col][col];
58
+ for (let c = col; c <= n; c++)
59
+ m[r][c] -= f * m[col][c];
60
+ }
61
+ }
62
+ return m.map((row, i) => row[n] / row[i]);
63
+ }
64
+ /** The rows' accuracies with p read through `pOf` and each step held to `thresholds`: a row any guard of hands back on
65
+ * takes the agent's answer; one that answered alone, its grade. A row that did not answer alone because a guard handed
66
+ * it back (one of its guards escalated) and that no guard would hand back at `thresholds` would have answered with an
67
+ * answer nobody read: counted wrong, so a threshold never comes down past hand-backs with no evidence of what the
68
+ * workflow says there. One that did not answer for another reason (a step failed, an escalate node) takes the agent's
69
+ * answer at every threshold. A switch OFF never hands back, a missing p or not. */
70
+ function scoreAt(rows, pOf, thresholds) {
71
+ let [wf, agent, handed] = [0, 0, 0];
72
+ for (const row of rows) {
73
+ agent += row.agentCorrect;
74
+ const under = row.guards.some((guard) => {
75
+ const at = thresholds.get(guard.node) ?? guard.threshold;
76
+ if (at === OFF)
77
+ return false;
78
+ const p = pOf(guard);
79
+ return p === null || p < at;
80
+ });
81
+ const known = row.answered && row.wfCorrect !== null;
82
+ if (under || (!known && !row.guards.some((guard) => guard.escalated))) {
83
+ handed += 1;
84
+ wf += row.agentCorrect;
85
+ }
86
+ else if (known && row.wfCorrect)
87
+ wf += 1;
88
+ }
89
+ const n = rows.length || 1;
90
+ return { wf_acc: wf / n, agent_acc: agent / n, handed_back: handed };
91
+ }
92
+ /** How good one raise is, compared first to last: any accuracy gained before none; then accuracy per input handed back
93
+ * (a gain that hands back nothing first); then the fewest handed back. A raise that gains nothing ranks by its loss. */
94
+ const raiseRank = (gain, added) => (gain > 1e-12 ? [1, added > 0 ? gain / added : Number.POSITIVE_INFINITY, -added] : [0, gain, -added]);
95
+ const rankAbove = (a, b) => {
96
+ for (let i = 0; i < a.length; i++)
97
+ if (a[i] !== b[i])
98
+ return a[i] > b[i];
99
+ return false;
100
+ };
101
+ /** The escalates of `doc` a refit may switch off: each a replay records (softEscalatesOf) that is a step of a chain with
102
+ * a step that is no escalate, so the chain keeps a step once they are dropped. */
103
+ function switchableEscalates(doc) {
104
+ const soft = softEscalatesOf(doc);
105
+ const out = new Set();
106
+ for (const { node, prefix } of workflowNodes(doc)) {
107
+ if (node.node !== "chain" || !Array.isArray(node.steps))
108
+ continue;
109
+ const steps = node.steps;
110
+ if (!steps.some((step) => step?.node !== "escalate"))
111
+ continue;
112
+ for (const step of steps)
113
+ if (step?.node === "escalate" && soft.has(`${prefix}${step.label}`))
114
+ out.add(`${prefix}${step.label}`);
115
+ }
116
+ return out;
117
+ }
118
+ /** The workflow `text`'s guards, and the escalates its replay recorded, refit over `rows` (`now`: the fit's fitted_at). A
119
+ * guard whose step no row reached keeps what it has, and so does an escalate no row recorded. Nothing changes (no
120
+ * `text`) when every guard keeps its threshold and fit and every escalate stays. */
121
+ export function refitGuards(text, rows, now) {
122
+ let doc;
123
+ try {
124
+ doc = JSON.parse(text);
125
+ }
126
+ catch {
127
+ return { guards: [], n: rows.length, agent_acc: 0, wf_acc: 0, delta: 0, handed_back: 0 };
128
+ }
129
+ const guards = [];
130
+ walkGuards(doc, (label, guard, node) => guards.push({ label, guard, node }));
131
+ const recorded = new Set(rows.flatMap((row) => row.guards.filter((g) => g.signal === "escalate").map((g) => g.node)));
132
+ const escalates = [...switchableEscalates(doc)].filter((label) => recorded.has(label));
133
+ const fits = new Map();
134
+ for (const { label, guard } of guards) {
135
+ if (guard.signal !== "both" || fits.has(label))
136
+ continue;
137
+ const data = rows.flatMap((row) => {
138
+ const one = row.guards.find((g) => g.node === label);
139
+ return one && typeof one.self === "number" && typeof one.jev === "number" && row.answered && row.wfCorrect !== null ? [{ x: [one.self, one.jev], y: row.wfCorrect }] : [];
140
+ });
141
+ if (data.length < FIT_MIN_ROWS || data.filter(({ y }) => !y).length < FIT_MIN_WRONG)
142
+ continue;
143
+ fits.set(label, { ...fitLogistic(data.map(({ x }) => x), data.map(({ y }) => y)), n: data.length, fitted_at: now });
144
+ }
145
+ // A step's p as the guard would read it with its new fit (the row's own p when no new fit).
146
+ const pOf = (row) => {
147
+ const fit = fits.get(row.node);
148
+ if (!fit)
149
+ return row.p;
150
+ if (typeof row.self !== "number" || typeof row.jev !== "number")
151
+ return null;
152
+ return sigmoid(fit.b + fit.w[0] * row.self + fit.w[1] * row.jev);
153
+ };
154
+ const was = new Map(guards.map(({ label, guard }) => [label, typeof guard.threshold === "number" ? guard.threshold : OFF]));
155
+ const thresholds = new Map([...was, ...escalates.map((label) => [label, SOFT_ESCALATE_THRESHOLD])]);
156
+ const agentAcc = scoreAt(rows, pOf, thresholds).agent_acc;
157
+ const meets = (at) => scoreAt(rows, pOf, at).wf_acc >= agentAcc - PROMOTE_BAR - 1e-9;
158
+ // Each guard's candidates: OFF (hands back nothing), THRESHOLD_MIN (nothing but a missing p or one under it), each p its
159
+ // rows read within the DSL's range, its own threshold, and THRESHOLD_MAX; a step no row reached keeps its own. Each
160
+ // recorded escalate's: off or on.
161
+ const candidatesOf = new Map(escalates.map((label) => [label, [OFF, SOFT_ESCALATE_THRESHOLD]]));
162
+ for (const [label, own] of was) {
163
+ const seen = rows.flatMap((row) => row.guards.filter((g) => g.node === label).map(pOf)).filter((p) => p !== null);
164
+ const at = (p) => Math.min(THRESHOLD_MAX, Math.max(THRESHOLD_MIN, round(p, 6)));
165
+ if (seen.length)
166
+ candidatesOf.set(label, [...new Set([OFF, THRESHOLD_MIN, ...seen.map(at), ...(own > 0 && own < 1 ? [own] : []), THRESHOLD_MAX])].sort((a, b) => a - b));
167
+ }
168
+ const kept = new Map(thresholds);
169
+ // Up from the bottom: while the bar is not met, the one raise (a guard to a higher candidate) that buys the most accuracy
170
+ // per input it hands back. Taking the steps in order instead traps the refit: the first step alone meets the bar only by
171
+ // handing back every input, and the step whose guard tells right from wrong is then never raised.
172
+ for (const [label, candidates] of candidatesOf)
173
+ thresholds.set(label, candidates[0]);
174
+ for (let now = scoreAt(rows, pOf, thresholds); !meets(thresholds);) {
175
+ let best;
176
+ for (const [label, candidates] of candidatesOf) {
177
+ for (const at of candidates.filter((c) => c > thresholds.get(label))) {
178
+ const next = scoreAt(rows, pOf, new Map([...thresholds, [label, at]]));
179
+ const rank = raiseRank(next.wf_acc - now.wf_acc, next.handed_back - now.handed_back);
180
+ if (!best || rankAbove(rank, best.rank))
181
+ best = { label, at, rank, next };
182
+ }
183
+ }
184
+ if (!best)
185
+ break;
186
+ thresholds.set(best.label, best.at);
187
+ now = best.next;
188
+ }
189
+ if (!meets(thresholds))
190
+ for (const [label, at] of kept)
191
+ thresholds.set(label, at);
192
+ // Then down: each step in turn, twice over, the lowest threshold (the fewest hand-backs) that keeps the bar, the others held.
193
+ for (let pass = 0; pass < 2; pass++) {
194
+ for (const [label, candidates] of candidatesOf) {
195
+ const found = candidates.find((candidate) => candidate <= thresholds.get(label) && meets(new Map([...thresholds, [label, candidate]])));
196
+ if (found !== undefined)
197
+ thresholds.set(label, found);
198
+ }
199
+ }
200
+ const changed = [];
201
+ for (const { label, guard, node } of guards) {
202
+ const threshold = thresholds.get(label);
203
+ const fit = fits.get(label);
204
+ if (threshold === was.get(label) && !fit)
205
+ continue;
206
+ if (threshold === OFF) {
207
+ delete node.guard;
208
+ changed.push({ node: label, was: was.get(label), threshold: null });
209
+ continue;
210
+ }
211
+ guard.threshold = threshold;
212
+ if (fit)
213
+ guard.fit = fit;
214
+ if (!changed.some((one) => one.node === label))
215
+ changed.push({ node: label, was: was.get(label), threshold, ...(fit ? { fit } : {}) });
216
+ }
217
+ const off = new Set(escalates.filter((label) => thresholds.get(label) === OFF));
218
+ if (off.size) {
219
+ for (const { node, prefix } of workflowNodes(doc)) {
220
+ if (node.node === "chain" && Array.isArray(node.steps))
221
+ node.steps = node.steps.filter((step) => !(step?.node === "escalate" && off.has(`${prefix}${step.label}`)));
222
+ }
223
+ for (const label of off)
224
+ changed.push({ node: label, was: null, threshold: null, escalate: true });
225
+ }
226
+ const score = scoreAt(rows, pOf, thresholds);
227
+ return {
228
+ ...(changed.length ? { text: JSON.stringify(doc) } : {}),
229
+ guards: changed,
230
+ n: rows.length,
231
+ agent_acc: round(score.agent_acc),
232
+ wf_acc: round(score.wf_acc),
233
+ delta: round(score.wf_acc - score.agent_acc),
234
+ handed_back: score.handed_back,
235
+ };
236
+ }
@@ -4,34 +4,23 @@ export declare const NOTE_BLOCK = "note";
4
4
  * with four backticks so a ``` line inside does not close it. */
5
5
  export declare const SKILL_BLOCK = "skill";
6
6
  export declare const WORKFLOW_BLOCK = "workflow";
7
- /** How many earlier runs of an agent a learned skill has been given to before the host asks for its job as a workflow
8
- * draft (`draftFor`): a run proposes one only when it thinks to, and few do. */
9
- export declare const DRAFT_AFTER_RUNS = 3;
7
+ /** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
8
+ * follow-up opened it again from, so only what came since is new. */
9
+ export declare const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
10
10
  /** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
11
11
  * where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
12
- * is how many notes are active in it, so how many lines the index has left. `tools`, the tools a workflow draft's
13
- * call nodes may run (tools.ts learnedWorkflowTools): none when not given. Its model nodes name none. `draftFor`, the
14
- * learned skills the run was given that have served DRAFT_AFTER_RUNS earlier runs with no learned workflow of their
15
- * name: the prompt gains one line asking for that job as a workflow draft. None when not given. `described`, with a
16
- * draft asked for: what each of `tools` takes and gives a call node, in the server's own words (tools.ts ToolEntry
17
- * summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
18
- * spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
19
- * for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
20
- * workflow draft, and asks for none (`draftFor` and `described` are not said). */
12
+ * is how many notes are active in it, so how many lines the index has left. The turn keeps notes and a skill; a job
13
+ * that repeats is compiled into a learned workflow by the compile turn (learn/compile.ts), never drafted here. `later`,
14
+ * a later round's (a follow-up opened the run again after it looked back): the prompt says so (LATER_LOOK) after its
15
+ * first line. */
21
16
  export declare function reflectPrompt(options: {
22
17
  dir: string;
23
18
  active: number;
24
- tools?: readonly string[];
25
- draftFor?: readonly string[];
26
- described?: readonly {
27
- readonly name: string;
28
- readonly does: string;
29
- }[];
30
- workflows?: boolean;
19
+ later?: boolean;
31
20
  }): string;
32
21
  /** The end-of-run turn asked again, once, when the parser refused its answer: why, in the parser's own words (`detail`,
33
22
  * parseReflection's), and the whole answer again in the format. */
34
- export declare function reflectAgain(detail: string, workflows?: false): string;
23
+ export declare function reflectAgain(detail: string): string;
35
24
  /** The end-of-run turn asked again, once, when the checks left a workflow draft out because its dry run failed: which
36
25
  * draft, in the host's own words, and why (`detail`, the check's words, made from the draft's own text: a step's label,
37
26
  * a path) inside a data fence alone, cleaned of control and format characters and capped, its token one the detail
@@ -1,12 +1,11 @@
1
1
  // What a host asks of an agent once its run has answered or failed: one more turn in the same session, in which the agent
2
- // answers with the notes it would keep, and a skill or a workflow draft when the work repeats, as text in a strict
3
- // format, and uses no tool. The host parses the answer (parseReflection), checks what it gives (check.ts), a grader
2
+ // answers with the notes it would keep, and a skill when the work repeats, as text in a strict format, and uses no tool
3
+ // (a workflow is the compile turn's, learn/compile.ts, whose answer this parser reads too). The host parses the answer (parseReflection), checks what it gives (check.ts), a grader
4
4
  // judges it (grade.ts), and the host merges it, rebuilding the index; the agent never writes the folder, and nothing it
5
5
  // wrote during the task counts. The same on every harness: every model writes markdown, and no tool is needed.
6
6
  import { createHash } from "node:crypto";
7
7
  import { CAPS } from "./check.js";
8
8
  import { INDEX_FILE, INDEX_LINES } from "./notes.js";
9
- import { LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
10
9
  /** Control and invisible characters: none may reach the prompt through a value the host puts in it. */
11
10
  const UNSEEN = /[\p{Cc}\p{Cf}]/u;
12
11
  /** The info word that opens a note's block in the answer: ```note <file>. */
@@ -15,38 +14,26 @@ export const NOTE_BLOCK = "note";
15
14
  * with four backticks so a ``` line inside does not close it. */
16
15
  export const SKILL_BLOCK = "skill";
17
16
  export const WORKFLOW_BLOCK = "workflow";
18
- /** How many earlier runs of an agent a learned skill has been given to before the host asks for its job as a workflow
19
- * draft (`draftFor`): a run proposes one only when it thinks to, and few do. */
20
- export const DRAFT_AFTER_RUNS = 3;
21
- /** A tool's name as the prompt may print it: a table tool's, or an MCP tool's a learned workflow may run (skills.ts
22
- * LEARNED_MCP_TOOL). */
23
- const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
24
- const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
17
+ /** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
18
+ * follow-up opened it again from, so only what came since is new. */
19
+ export const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
25
20
  /** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
26
21
  * where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
27
- * is how many notes are active in it, so how many lines the index has left. `tools`, the tools a workflow draft's
28
- * call nodes may run (tools.ts learnedWorkflowTools): none when not given. Its model nodes name none. `draftFor`, the
29
- * learned skills the run was given that have served DRAFT_AFTER_RUNS earlier runs with no learned workflow of their
30
- * name: the prompt gains one line asking for that job as a workflow draft. None when not given. `described`, with a
31
- * draft asked for: what each of `tools` takes and gives a call node, in the server's own words (tools.ts ToolEntry
32
- * summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
33
- * spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
34
- * for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
35
- * workflow draft, and asks for none (`draftFor` and `described` are not said). */
22
+ * is how many notes are active in it, so how many lines the index has left. The turn keeps notes and a skill; a job
23
+ * that repeats is compiled into a learned workflow by the compile turn (learn/compile.ts), never drafted here. `later`,
24
+ * a later round's (a follow-up opened the run again after it looked back): the prompt says so (LATER_LOOK) after its
25
+ * first line. */
36
26
  export function reflectPrompt(options) {
37
- const { dir, active, tools = [], draftFor = [], described = [], workflows = true } = options;
27
+ const { dir, active, later = false } = options;
38
28
  if (typeof dir !== "string" || dir === "" || dir.startsWith("/") || UNSEEN.test(dir))
39
29
  throw new Error("the directory must be a path relative to the run's workspace, with no control or unseen characters");
40
30
  if (!Number.isSafeInteger(active) || active < 0)
41
31
  throw new Error("the count of active notes must be a whole number, 0 or more");
42
- if (!Array.isArray(tools) || tools.some((tool) => typeof tool !== "string" || !printable(tool)))
43
- throw new Error("each tool must be a tool's name");
44
- if (!Array.isArray(draftFor) || draftFor.some((name) => typeof name !== "string" || !SKILL_NAME.test(name)))
45
- throw new Error("each skill a draft is asked for must be a skill's name");
46
32
  const left = Math.max(0, INDEX_LINES - active);
47
33
  return [
48
34
  "The task is done. Before the run ends, say what this run taught you that will help in later runs, if anything.",
49
35
  "",
36
+ ...(later ? [LATER_LOOK, ""] : []),
50
37
  "Look back over the whole conversation: what the user asked, anything they asked you to remember (even if you said you",
51
38
  "saved it), what you tried, and what worked. Only what you answer now is kept: files you wrote during the task are not.",
52
39
  "Use no tool in this turn.",
@@ -85,29 +72,17 @@ export function reflectPrompt(options) {
85
72
  "site, a source or a seller, or names where money or data goes.",
86
73
  "What `# Learned` in your instructions, and this message, say about learning itself is not a lesson: never put it in a note or a skill, nor the sentence you say when you keep something.",
87
74
  "",
88
- ...(workflows ? [
89
- "## Skills and workflow drafts, only when the work repeats",
90
- "",
91
- "When this run did, to the end, a job this agent will be asked to do again, you may also keep one skill and one",
92
- "workflow draft for that job. Most runs keep neither. Neither holds this case's data: each is about the job, not the one case.",
93
- ] : [
94
- "## Skills, only when the work repeats",
95
- "",
96
- "When this run did, to the end, a job this agent will be asked to do again, you may also keep one skill for that job.",
97
- "Most runs keep none. It holds none of this case's data: it is about the job, not the one case.",
98
- "Keep no workflow draft: this agent learns notes and skills alone.",
99
- ]),
75
+ "## Skills, only when the work repeats",
76
+ "",
77
+ "When this run did, to the end, a job this agent will be asked to do again, you may also keep one skill for that job.",
78
+ "Most runs keep none. It holds none of this case's data: it is about the job, not the one case.",
100
79
  "Steps the person asks you to follow every time a task comes back are a skill, not a note: keep them as the skill, in",
101
80
  "their words and with the exact output format they gave, and do not repeat them in a note.",
102
81
  "A job you keep a skill for needs no note beside it.",
103
82
  "A rule for every reply applies whatever the job is. Keep it as a note, which every later run reads. Steps or a format",
104
83
  "for one kind of job, named by when it applies (\"whenever I ask for a weekly summary\", \"when you open a PR\"), are a",
105
84
  "skill. A note holds its own lesson: never repeat another note's rule in it, so a retired rule stays retired.",
106
- ...(workflows ? [
107
- "A job that runs end to end as model and tool-call steps, from a defined input to a defined output, is a workflow draft,",
108
- "and so is one the person asks you to keep as a workflow; its steps may also be a skill.",
109
- ...(draftFor.length ? [draftAsk(draftFor), ...describedLines(described, tools)] : []),
110
- ] : []),
85
+ "Keep no workflow here: when the job repeats, the host may ask for it as a workflow in a turn of its own, from your notes.",
111
86
  "",
112
87
  `A skill is how to do the job, step by step, as a SKILL.md: front matter with its \`name\` (lowercase letters, digits`,
113
88
  "and single dashes) and a `description` of when to use it, then the steps. Open its block with four backticks, so a",
@@ -121,52 +96,12 @@ export function reflectPrompt(options) {
121
96
  "---",
122
97
  "1. Open the store's policies page first.",
123
98
  "````",
124
- "",
125
- ...(workflows ? [
126
- "A workflow draft does the job as one workflow DSL document: front matter with one line that says what it does and",
127
- "when to use it, then the JSON. It uses model and tool-call nodes only: no judge, pick or sift node, no code node, no shell or",
128
- `executor call. Its model nodes name no tool. ${tools.length ? `Its call nodes may run only these tools: ${tools.join(", ")}.` : "It has no call node on a tool."} At most ${CAPS.file} bytes of JSON.`,
129
- "To change a draft you were given, give it again whole under its name.",
130
- "Its schemas are declared once under `schemas`, and `input` and `output` name one each by `schemaId`, never a schema",
131
- "written in place.",
132
- "Give its front matter an `example:` line too: one JSON object on one line, the input this run would have given it.",
133
- "The host dry-runs the draft on it before it is kept (no model or tool is called) and never keeps the example.",
134
- "",
135
- `\`\`\`\`${WORKFLOW_BLOCK} find-policies`,
136
- "---",
137
- "description: Finds a store's refund policy from its public pages; use when a case asks for it",
138
- `example: ${JSON.stringify(tools.includes("web_fetch") ? { url: "https://shop.example/policies" } : { text: "Refunds are accepted within 30 days of delivery." })}`,
139
- "---",
140
- JSON.stringify(exampleDraft(tools.includes("web_fetch"))),
141
- "````",
142
- ] : []),
143
99
  ].join("\n");
144
100
  }
145
- /** The most of one tool's words the draft ask's description gives it. */
146
- const DESCRIBED_MAX = 600;
147
- /** What each of `tools` takes and gives a call node, from `described` (a tool's name and its words), one line each, under
148
- * a line that says so; none when no tool of `tools` is described. */
149
- const describedLines = (described, tools) => {
150
- const lines = tools.flatMap((name) => {
151
- const does = described.find((one) => one.name === name)?.does;
152
- if (typeof does !== "string")
153
- return [];
154
- const flat = does.replace(new RegExp(UNSEEN.source, "gu"), " ").replace(/\s+/g, " ").trim().slice(0, DESCRIBED_MAX).trim();
155
- return flat ? [`- \`${name}\`: ${flat}`] : [];
156
- });
157
- return lines.length ? ["What each tool a call node may run takes and gives:", ...lines] : [];
158
- };
159
- /** The one line that asks for a workflow draft of a skill's job, by the skill's name. */
160
- const draftAsk = (names) => {
161
- const listed = names.map((name) => `\`${name}\``).join(", ");
162
- return names.length === 1
163
- ? `Your skill ${listed} has now served ${DRAFT_AFTER_RUNS} or more runs: this time, also keep its job as a workflow draft named \`${names[0]}\`, its steps as nodes, if the job runs end to end as model and tool-call steps. Its output is the job's answer in the output format the skill gives: its last node writes it, and \`output\` names that node's text.`
164
- : `Your skills ${listed} have each served ${DRAFT_AFTER_RUNS} or more runs: this time, also keep one of their jobs as a workflow draft named like its skill, its steps as nodes, if the job runs end to end as model and tool-call steps. Its output is the job's answer in the output format its skill gives: its last node writes it, and \`output\` names that node's text.`;
165
- };
166
101
  /** The end-of-run turn asked again, once, when the parser refused its answer: why, in the parser's own words (`detail`,
167
102
  * parseReflection's), and the whole answer again in the format. */
168
- export function reflectAgain(detail, workflows) {
169
- return `Your answer could not be read: ${detail}. Give the whole answer again in the format asked for above, every ${workflows === false ? "note and skill" : "note, skill and workflow"} block in it, and nothing else.`;
103
+ export function reflectAgain(detail) {
104
+ return `Your answer could not be read: ${detail}. Give the whole answer again in the format asked for above, every note and skill block in it, and nothing else.`;
170
105
  }
171
106
  /** The end-of-run turn asked again, once, when the checks left a workflow draft out because its dry run failed: which
172
107
  * draft, in the host's own words, and why (`detail`, the check's words, made from the draft's own text: a step's label,
@@ -203,48 +138,6 @@ function retryToken(file, said) {
203
138
  return token;
204
139
  }
205
140
  }
206
- /** The prompt's example workflow draft, whole: its schemas declared once, its input and output naming them by `schemaId`,
207
- * and a chain the learned runner runs (a `web_fetch` call when the agent has it, then a model node; else two model
208
- * nodes), so an agent copies a draft the DSL and the checker pass (a test validates this text). */
209
- const exampleDraft = (fetches) => fetches
210
- ? {
211
- v: 2,
212
- name: "find-policies",
213
- schemas: {
214
- Store: { type: "object", properties: { url: { type: "string" } }, required: ["url"] },
215
- Page: { type: "object", properties: { text: { type: "string" } } },
216
- Policies: { type: "object", properties: { refund: { type: "string" } }, required: ["refund"] },
217
- },
218
- input: { schemaId: "Store" },
219
- output: { schemaId: "Policies", path: "policies" },
220
- root: {
221
- node: "chain",
222
- steps: [
223
- { node: "call", label: "fetch", via: "tool", tool: "web_fetch", args: { url: "{url}" }, out: "Page", as: "page", deadline_s: 30 },
224
- { node: "extract", label: "read", instructions: "Say the store's refund policy, from the page.", out: "Policies", as: "policies" },
225
- ],
226
- },
227
- }
228
- : {
229
- // With no tool to fetch with, the job's input is the page's text itself: every step reads what it is given,
230
- // never a guess.
231
- v: 2,
232
- name: "find-policies",
233
- schemas: {
234
- Page: { type: "object", properties: { text: { type: "string" } }, required: ["text"] },
235
- Lines: { type: "object", properties: { lines: { type: "string" } }, required: ["lines"] },
236
- Policies: { type: "object", properties: { refund: { type: "string" } }, required: ["refund"] },
237
- },
238
- input: { schemaId: "Page" },
239
- output: { schemaId: "Policies", path: "policies" },
240
- root: {
241
- node: "chain",
242
- steps: [
243
- { node: "extract", label: "quote", instructions: "Copy the lines of the page's text that are about refunds.", out: "Lines", as: "lines" },
244
- { node: "extract", label: "read", instructions: "Say the store's refund policy, from those lines.", out: "Policies", as: "policies" },
245
- ],
246
- },
247
- };
248
141
  /** The longest answer read, in UTF-16 units: 8 notes at the note cap, a skill and a workflow draft at theirs, fenced,
249
142
  * with room for a few lines around them. */
250
143
  export const ANSWER_MAX = 100_000;
@@ -0,0 +1,63 @@
1
+ /** The built-in tools a call node may run that read only: they change nothing outside the run (a web page or search read,
2
+ * a document's pages drawn into the run's own work/, one model completion). Every other built-in is a write. */
3
+ export declare const READ_TOOLS: readonly string[];
4
+ /** Why a replayed input is skipped, word for word: what a PromotionRecord's reason and the replay's row say. */
5
+ export declare const SKIPPED_WRITE = "needs a write the recording doesn't have";
6
+ /** `unmarked`: an MCP tool its server lists with no readOnlyHint and not destructive. A replay treats it as a write (nothing
7
+ * says it only reads), but its skip says why: the server may only have left the hint out (the hold's reason names it). */
8
+ export type ToolClass = "read" | "write" | "unmarked";
9
+ /** Whether `tool` (a catalog name) reads or writes: an MCP tool by `annotations` (its server's listing as the run's pin
10
+ * holds it, `{}` for a tool listed with none; undefined for one not listed): read only when readOnlyHint is true and
11
+ * destructiveHint is not, unmarked when it is listed with no readOnlyHint and not destructive; a built-in by READ_TOOLS;
12
+ * else write. */
13
+ export declare function toolClassOf(tool: string, annotations?: (tool: string) => Readonly<Record<string, unknown>> | undefined): ToolClass;
14
+ /** Why replay can't run MCP tools with no readOnlyHint (bare tool names, most-skipped first): "browse, fetch_page and 2
15
+ * more have no readOnlyHint, so replay can't run them: if they only read, mark them read-only in the MCP server". */
16
+ export declare function unmarkedWords(names: readonly string[]): string;
17
+ /** A catalog name as a person reads it in a reason: an MCP tool's own name, any other whole. */
18
+ export declare const toolWord: (tool: string) => string;
19
+ /** `value` as JSON with every object's keys sorted, at every depth: two argument objects that differ only in key order
20
+ * read the same. */
21
+ export declare function canonical(value: unknown): string;
22
+ /** A call's key: the tool's wire name (a catalog name or a wire name alike) and its canonical arguments. */
23
+ export declare const callKey: (tool: string, args: unknown) => string;
24
+ /** One recorded call's answer: its text, the structured details pi kept beside it (a built-in's whole value), and whether
25
+ * it ended an error. */
26
+ export type Recorded = {
27
+ readonly text: string;
28
+ readonly details?: unknown;
29
+ readonly isError: boolean;
30
+ };
31
+ type EntryLike = {
32
+ readonly kind: string;
33
+ readonly model?: readonly unknown[];
34
+ };
35
+ /** The calls a run's journal recorded (`entries`, pi-shaped: store-reads/journal.ts piShaped for a CLI's record), by
36
+ * callKey: each call's answer, the first one when a run made the same call twice. A call refused before it ran (its
37
+ * gate's deny) recorded no answer and is left out. */
38
+ export declare function recordedCalls(entries: readonly EntryLike[]): Map<string, Recorded>;
39
+ /** The write that stopped a replay's input: its tool and step, and `unmarked` when it is an MCP tool its server listed with
40
+ * no readOnlyHint (toolClassOf). */
41
+ export type Skipped = {
42
+ readonly tool: string;
43
+ readonly step: string;
44
+ readonly unmarked?: true;
45
+ };
46
+ /** A replay's call nodes (learned-workflow.ts runLearned's `run.replay`): `call` runs each by the rules above. `skipped`:
47
+ * the write that stopped it, once one did; `stop` aborts the workflow's run there. `live`: how many reads ran live. */
48
+ export interface ReplayCalls {
49
+ call(node: {
50
+ readonly label: string;
51
+ readonly tool: string;
52
+ }, args: unknown, live: () => Promise<unknown>): Promise<unknown>;
53
+ readonly skipped: Skipped | undefined;
54
+ readonly stop: AbortSignal;
55
+ readonly live: number;
56
+ }
57
+ /** What a call node throws when its write has no recording: the replay of this input stops. */
58
+ export declare class ReplaySkipped extends Error {
59
+ name: string;
60
+ }
61
+ /** The replay's call nodes over `recorded` (recordedCalls of the graded run), each tool classed by `classOf`. */
62
+ export declare function replayCalls(recorded: ReadonlyMap<string, Recorded>, classOf: (tool: string) => ToolClass): ReplayCalls;
63
+ export {};