@parcha/agentrun-serve 0.1.0-beta.37 → 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 (399) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/README.md +155 -92
  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/browser-cost.js +52 -93
  11. package/dist/cap.d.ts +0 -390
  12. package/dist/cap.js +4 -937
  13. package/dist/catalog.js +1 -1
  14. package/dist/composio-preset.d.ts +17 -0
  15. package/dist/composio-preset.js +43 -1
  16. package/dist/computer-calls.d.ts +36 -24
  17. package/dist/computer-calls.js +110 -27
  18. package/dist/computer-live.d.ts +5 -0
  19. package/dist/computer-live.js +12 -0
  20. package/dist/computer-setting.d.ts +15 -2
  21. package/dist/computer-setting.js +20 -4
  22. package/dist/computer-view.d.ts +3 -2
  23. package/dist/computer-view.js +5 -4
  24. package/dist/computer-viewer.js +26 -12
  25. package/dist/computers.d.ts +4 -1
  26. package/dist/computers.js +12 -6
  27. package/dist/console/assets/index-CjqQirbo.css +1 -0
  28. package/dist/console/assets/index-b6-XY5A9.js +576 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/console-links.d.ts +2 -0
  31. package/dist/console-links.js +3 -0
  32. package/dist/decisions.js +4 -0
  33. package/dist/faux-computers.js +4 -2
  34. package/dist/harness-opencode/adapter.js +7 -3
  35. package/dist/harness-opencode/facts.js +0 -2
  36. package/dist/harness-opencode/host/policy.d.ts +2 -5
  37. package/dist/harness-opencode/host/policy.js +8 -32
  38. package/dist/harness-table.d.ts +0 -2
  39. package/dist/harness-table.js +0 -2
  40. package/dist/host-tools.d.ts +1 -5
  41. package/dist/host-tools.js +7 -10
  42. package/dist/hosted-search.d.ts +0 -2
  43. package/dist/hosted-search.js +0 -21
  44. package/dist/key-words.d.ts +3 -2
  45. package/dist/key-words.js +4 -2
  46. package/dist/learn/check.d.ts +6 -1
  47. package/dist/learn/check.js +12 -4
  48. package/dist/learn/commit.d.ts +10 -0
  49. package/dist/learn/commit.js +18 -4
  50. package/dist/learn/compile.d.ts +243 -0
  51. package/dist/learn/compile.js +471 -0
  52. package/dist/learn/general.d.ts +3 -0
  53. package/dist/learn/general.js +4 -2
  54. package/dist/learn/grade.d.ts +1 -1
  55. package/dist/learn/grade.js +7 -6
  56. package/dist/learn/notes.d.ts +8 -0
  57. package/dist/learn/notes.js +18 -0
  58. package/dist/learn/promote.d.ts +253 -0
  59. package/dist/learn/promote.js +428 -0
  60. package/dist/learn/refit.d.ts +39 -0
  61. package/dist/learn/refit.js +236 -0
  62. package/dist/learn/reflect.d.ts +5 -25
  63. package/dist/learn/reflect.js +14 -131
  64. package/dist/learn/replay-calls.d.ts +63 -0
  65. package/dist/learn/replay-calls.js +158 -0
  66. package/dist/learn/skills.d.ts +17 -9
  67. package/dist/learn/skills.js +132 -42
  68. package/dist/learn/workflow-nodes.d.ts +15 -0
  69. package/dist/learn/workflow-nodes.js +44 -0
  70. package/dist/learned-nodes.d.ts +50 -2
  71. package/dist/learned-nodes.js +41 -2
  72. package/dist/learned-workflow.d.ts +19 -3
  73. package/dist/learned-workflow.js +105 -26
  74. package/dist/learning-batch.d.ts +2 -2
  75. package/dist/learning-batch.js +1 -1
  76. package/dist/learning-cost.d.ts +18 -6
  77. package/dist/learning-cost.js +15 -7
  78. package/dist/learning-routes.d.ts +14 -2
  79. package/dist/learning-routes.js +14 -3
  80. package/dist/learning-words.d.ts +7 -0
  81. package/dist/learning-words.js +7 -0
  82. package/dist/learning.d.ts +31 -6
  83. package/dist/learning.js +7 -4
  84. package/dist/llm.js +0 -3
  85. package/dist/mcp-gateway.d.ts +12 -20
  86. package/dist/mcp-gateway.js +16 -44
  87. package/dist/mcp-oauth.d.ts +5 -0
  88. package/dist/mcp-oauth.js +1 -1
  89. package/dist/mcp-pin-first.d.ts +37 -0
  90. package/dist/mcp-pin-first.js +107 -0
  91. package/dist/mcp-probe.d.ts +8 -9
  92. package/dist/mcp-probe.js +16 -33
  93. package/dist/mcp-servers-store.d.ts +89 -22
  94. package/dist/mcp-servers-store.js +131 -25
  95. package/dist/mcp-sources.d.ts +39 -0
  96. package/dist/mcp-sources.js +74 -0
  97. package/dist/mcp-store.d.ts +11 -0
  98. package/dist/mcp-store.js +16 -2
  99. package/dist/mcp-wire.d.ts +22 -0
  100. package/dist/mcp-wire.js +36 -0
  101. package/dist/mcp.js +3 -3
  102. package/dist/meta-tool-names.d.ts +1 -0
  103. package/dist/meta-tool-names.js +3 -0
  104. package/dist/model.d.ts +13 -0
  105. package/dist/model.js +46 -15
  106. package/dist/monid.d.ts +51 -25
  107. package/dist/monid.js +226 -140
  108. package/dist/openapi.js +336 -66
  109. package/dist/paid-calls.d.ts +26 -29
  110. package/dist/paid-calls.js +46 -102
  111. package/dist/propose.d.ts +7 -1
  112. package/dist/propose.js +18 -6
  113. package/dist/provider.js +9 -2
  114. package/dist/reflect-range.js +2 -1
  115. package/dist/rows.d.ts +5 -3
  116. package/dist/rows.js +15 -4
  117. package/dist/run-launch.d.ts +13 -0
  118. package/dist/run-launch.js +6 -0
  119. package/dist/run-learning-served.d.ts +13 -2
  120. package/dist/run-manifest.d.ts +5 -0
  121. package/dist/run-manifest.js +20 -0
  122. package/dist/run-secrets.js +2 -3
  123. package/dist/run-timeline-served.js +5 -2
  124. package/dist/run-view.d.ts +17 -6
  125. package/dist/run-view.js +51 -22
  126. package/dist/runnable.d.ts +0 -3
  127. package/dist/runnable.js +37 -29
  128. package/dist/runner/adapter-loop.d.ts +24 -10
  129. package/dist/runner/adapter-loop.js +852 -314
  130. package/dist/runner/adapter-run-spec.d.ts +12 -6
  131. package/dist/runner/adapter-run-spec.js +97 -46
  132. package/dist/runner/adapters/pi-computer.d.ts +3 -1
  133. package/dist/runner/adapters/pi-computer.js +13 -5
  134. package/dist/runner/adapters/pi.d.ts +16 -7
  135. package/dist/runner/adapters/pi.js +94 -33
  136. package/dist/runner/cli-run-spec.js +67 -27
  137. package/dist/runner/computer-channel.js +2 -1
  138. package/dist/runner/conformance/harness.d.ts +3 -0
  139. package/dist/runner/conformance/harness.js +145 -4
  140. package/dist/runner/conformance/subject.d.ts +11 -4
  141. package/dist/runner/end-of-run.d.ts +6 -5
  142. package/dist/runner/end-of-run.js +9 -6
  143. package/dist/runner/feedback-round.d.ts +52 -0
  144. package/dist/runner/feedback-round.js +79 -0
  145. package/dist/runner/journal-kinds.d.ts +24 -6
  146. package/dist/runner/journal-kinds.js +15 -0
  147. package/dist/runner/learning-end.d.ts +54 -19
  148. package/dist/runner/learning-end.js +272 -99
  149. package/dist/runner/learning-loop.d.ts +19 -1
  150. package/dist/runner/learning-loop.js +5 -2
  151. package/dist/runner/learning-seed.d.ts +4 -0
  152. package/dist/runner/learning-seed.js +14 -0
  153. package/dist/runner/loop-contract.d.ts +19 -3
  154. package/dist/runner/loop.d.ts +16 -1
  155. package/dist/runner/loop.js +21 -1
  156. package/dist/runner/mcp-claim.d.ts +5 -1
  157. package/dist/runner/mcp-claim.js +66 -50
  158. package/dist/runner/mcp-run.d.ts +16 -52
  159. package/dist/runner/mcp-run.js +12 -84
  160. package/dist/runner/meta-tools.d.ts +37 -0
  161. package/dist/runner/meta-tools.js +268 -0
  162. package/dist/runner/metrics.js +14 -3
  163. package/dist/runner/model-route.js +12 -3
  164. package/dist/runner/monid-run.d.ts +16 -0
  165. package/dist/runner/monid-run.js +96 -0
  166. package/dist/runner/promotion.d.ts +80 -0
  167. package/dist/runner/promotion.js +562 -0
  168. package/dist/runner/reflect-hook.d.ts +36 -21
  169. package/dist/runner/reflect-hook.js +138 -49
  170. package/dist/runner/runner.js +26 -4
  171. package/dist/runner/sessions.d.ts +8 -3
  172. package/dist/runner/sessions.js +5 -1
  173. package/dist/runner/step-guard.d.ts +62 -0
  174. package/dist/runner/step-guard.js +93 -0
  175. package/dist/runner/subagent.d.ts +0 -3
  176. package/dist/runner/subagent.js +7 -12
  177. package/dist/runner/workflow-first.d.ts +216 -0
  178. package/dist/runner/workflow-first.js +303 -0
  179. package/dist/runner/workflow-loop.js +17 -10
  180. package/dist/runner/workflow-spec.d.ts +1 -0
  181. package/dist/runner/workflow-spec.js +7 -3
  182. package/dist/runs-over-store.d.ts +11 -2
  183. package/dist/runs-over-store.js +21 -11
  184. package/dist/server.d.ts +88 -16
  185. package/dist/server.js +380 -87
  186. package/dist/settings-wake.d.ts +8 -6
  187. package/dist/settings-wake.js +13 -7
  188. package/dist/store/agent-body.d.ts +14 -3
  189. package/dist/store/agent-body.js +14 -10
  190. package/dist/store/command-wake.d.ts +3 -2
  191. package/dist/store/command-wake.js +4 -4
  192. package/dist/store/postgres/connection.js +3 -1
  193. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  194. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  195. package/dist/store/schema.d.ts +9 -0
  196. package/dist/store/schema.js +28 -8
  197. package/dist/store/sqlite/connection.d.ts +2 -2
  198. package/dist/store/sqlite/connection.js +2 -2
  199. package/dist/store/sqlite/run-patch.js +19 -7
  200. package/dist/store/sqlite/store.js +59 -18
  201. package/dist/store/store.d.ts +46 -14
  202. package/dist/store-reads/journal.d.ts +25 -1
  203. package/dist/store-reads/journal.js +63 -49
  204. package/dist/store-reads/learning.d.ts +101 -15
  205. package/dist/store-reads/learning.js +195 -61
  206. package/dist/store-reads/loop.d.ts +61 -0
  207. package/dist/store-reads/loop.js +111 -0
  208. package/dist/store-view.d.ts +3 -2
  209. package/dist/store-view.js +35 -17
  210. package/dist/template-eval.d.ts +18 -9
  211. package/dist/template-eval.js +91 -66
  212. package/dist/template-github-permissions.d.ts +2 -2
  213. package/dist/template-github-permissions.js +2 -1
  214. package/dist/template-import.d.ts +31 -0
  215. package/dist/template-import.js +121 -0
  216. package/dist/template-source.d.ts +51 -0
  217. package/dist/template-source.js +371 -0
  218. package/dist/templates.d.ts +218 -46
  219. package/dist/templates.js +493 -181
  220. package/dist/timeline/computer.d.ts +48 -0
  221. package/dist/timeline/computer.js +169 -0
  222. package/dist/timeline/index.d.ts +4 -3
  223. package/dist/timeline/index.js +4 -3
  224. package/dist/timeline/labels.d.ts +6 -2
  225. package/dist/timeline/labels.js +93 -2
  226. package/dist/timeline/origin.d.ts +19 -5
  227. package/dist/timeline/origin.js +11 -4
  228. package/dist/timeline/timeline.d.ts +11 -17
  229. package/dist/timeline/timeline.js +24 -9
  230. package/dist/tool-gate.d.ts +73 -46
  231. package/dist/tool-gate.js +133 -66
  232. package/dist/tool-keys.d.ts +4 -1
  233. package/dist/tool-keys.js +8 -3
  234. package/dist/tool-list.d.ts +26 -0
  235. package/dist/tool-list.js +43 -0
  236. package/dist/tool-names.d.ts +71 -0
  237. package/dist/tool-names.js +99 -0
  238. package/dist/tool-plane.d.ts +29 -27
  239. package/dist/tool-plane.js +65 -37
  240. package/dist/tools.d.ts +22 -6
  241. package/dist/tools.js +24 -20
  242. package/dist/validate.d.ts +15 -7
  243. package/dist/validate.js +91 -44
  244. package/dist/web-fetch.d.ts +1 -7
  245. package/dist/web-fetch.js +2 -22
  246. package/dist/workspace/computer-deps.d.ts +3 -0
  247. package/dist/workspace/computer-deps.js +5 -2
  248. package/dist/workspace/computer-for-claim.d.ts +6 -0
  249. package/dist/workspace/computer-for-claim.js +32 -14
  250. package/dist/workspace/computer-hold.js +7 -1
  251. package/dist/workspace/computer-script.d.ts +23 -7
  252. package/dist/workspace/computer-script.js +48 -14
  253. package/dist/workspace/index.d.ts +2 -2
  254. package/dist/workspace/index.js +1 -1
  255. package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
  256. package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
  257. package/dist/workspace/local.js +2 -2
  258. package/dist/workspace/resolve-computer.d.ts +21 -1
  259. package/dist/workspace/resolve-computer.js +32 -14
  260. package/dist/workspace/run-tools.d.ts +28 -10
  261. package/dist/workspace/run-tools.js +39 -11
  262. package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
  263. package/dist/wrap-up.js +21 -0
  264. package/launcher/agentrun-serve +4 -2
  265. package/package.json +9 -9
  266. package/templates/README.md +111 -45
  267. package/templates/code-review/agent.md +30 -14
  268. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  269. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  270. package/templates/code-review/evals/injection/case.yaml +2 -1
  271. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  272. package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
  273. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  274. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  275. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  276. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  277. package/templates/code-review/evals/null-name/case.yaml +2 -1
  278. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  279. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  280. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  281. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  282. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  283. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  284. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  285. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  286. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  287. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  288. package/templates/code-review/evals/re-review/case.yaml +2 -1
  289. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  290. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  291. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  292. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  293. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  294. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  295. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  296. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  297. package/templates/code-review/skills/review/DEEP.md +3 -2
  298. package/templates/code-review/skills/review/REVIEWER.md +3 -2
  299. package/templates/code-review/skills/review/SKILL.md +4 -3
  300. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  301. package/templates/inbound-lead/agent.md +26 -16
  302. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  303. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  304. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  305. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  306. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  307. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  308. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  309. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  310. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  311. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  312. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  313. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  314. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  315. package/templates/kyb/agent.md +15 -5
  316. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  317. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  318. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  319. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  320. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  321. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  322. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  323. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  324. package/templates/kyb/kyb.schema.json +8 -7
  325. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  326. package/templates/market-monitor/agent.md +19 -12
  327. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  328. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  329. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  330. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  331. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  332. package/templates/release-notes/agent.md +32 -10
  333. package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
  334. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  335. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  336. package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
  337. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  338. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  339. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  340. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  341. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  342. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  343. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  344. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  345. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  346. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  347. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  348. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  349. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  350. package/templates/release-notes/notes.schema.json +1 -1
  351. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  352. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  353. package/dist/console/assets/index-DRN62V5v.css +0 -1
  354. package/dist/tool-blurbs.d.ts +0 -4
  355. package/dist/tool-blurbs.js +0 -28
  356. package/dist/tool-budget.js +0 -62
  357. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  358. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  359. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  360. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  361. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  362. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  363. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  364. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  365. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  366. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  367. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  368. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  369. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  370. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  371. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  372. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  373. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  374. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  375. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  376. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  377. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  378. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  379. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  380. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  381. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  382. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  383. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  384. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  385. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  386. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  387. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  388. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  389. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  390. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  391. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  392. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  393. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  394. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  395. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  396. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  397. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  398. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  399. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -1,8 +1,47 @@
1
1
  // What a learned_workflow call keeps of its workflow's run beside itself in the run's journal: each node that ran, as
2
2
  // the workflow DSL ended it (learned-workflow.ts runLearned writes it; store-reads/journal.ts runTimeline puts it on the
3
3
  // call's result row as `learned_nodes`). Its own module, so the timeline's reader needs none of the tool's imports.
4
- /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes }`, its call's id, the
5
- * workflow's name and each of its nodes that ran (LearnedNode). */
4
+ /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards? }`, its call's id, the
5
+ * workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX) and every guard check it made
6
+ * (GuardRow, never capped: a map over more items than the trace holds keeps each); on a replay run's call that a write
7
+ * stopped (learn/replay-calls.ts: one the graded run's recording does not have), `replay_skipped: { tool, step }` too; and
8
+ * `ended`, how the workflow ended (LearnedEnded), on a call that ended (a replay run's call always keeps its entry). */
6
9
  export const LEARNED_NODES = "agentrun.learned_nodes";
7
10
  /** The most nodes a call keeps: a map over a long list runs its body once per item. */
8
11
  export const LEARNED_NODES_MAX = 64;
12
+ /** A run's guard rows, from its root entries: every guard check of every learned_workflow call (LEARNED_NODES `guards`,
13
+ * never the capped trace's), in order, each with its call's workflow. What its metrics keep as `guards`. */
14
+ export function guardsOf(entries) {
15
+ const rows = [];
16
+ for (const entry of entries) {
17
+ if (entry.kind !== LEARNED_NODES)
18
+ continue;
19
+ const data = entry.data;
20
+ if (!Array.isArray(data?.guards))
21
+ continue;
22
+ const workflow = typeof data.workflow === "string" ? data.workflow : undefined;
23
+ for (const row of data.guards)
24
+ if (row && typeof row === "object")
25
+ rows.push(workflow ? { ...row, workflow } : row);
26
+ }
27
+ return rows;
28
+ }
29
+ /** How the newest learned_workflow call of `workflow` in `entries` (its root's) ended (LEARNED_NODES `ended`), or undefined
30
+ * when no entry says. */
31
+ export function endedIn(entries, workflow) {
32
+ const data = entries.findLast((entry) => entry.kind === LEARNED_NODES && entry.data?.workflow === workflow)?.data;
33
+ return data?.ended === "complete" || data?.ended === "escalated" || data?.ended === "failed" ? data.ended : undefined;
34
+ }
35
+ /** The write that stopped a replay run's workflow, from its root entries (a LEARNED_NODES entry's `replay_skipped`: a
36
+ * write the graded run's recording does not have, learn/replay-calls.ts; `unmarked`, an MCP tool listed with no
37
+ * readOnlyHint), or undefined when none did. */
38
+ export function replaySkippedIn(entries) {
39
+ for (const entry of entries) {
40
+ if (entry.kind !== LEARNED_NODES)
41
+ continue;
42
+ const skipped = entry.data?.replay_skipped;
43
+ if (skipped && typeof skipped.tool === "string" && typeof skipped.step === "string")
44
+ return { tool: skipped.tool, step: skipped.step, ...(skipped.unmarked === true ? { unmarked: true } : {}) };
45
+ }
46
+ return undefined;
47
+ }
@@ -1,5 +1,5 @@
1
1
  import { type ToolRegistration } from "@earendil-works/pi-durable";
2
- import { type LearnedNode } from "./learned-nodes.js";
2
+ import { type GuardRow, type LearnedEnded, type LearnedNode } from "./learned-nodes.js";
3
3
  import { type LearnedWorkflow } from "./learning.js";
4
4
  import type { ModelRef } from "./model.js";
5
5
  import { type Ledger } from "./paid-calls.js";
@@ -11,6 +11,7 @@ import type { Workspace } from "./workspace/workspace.js";
11
11
  import type { DecisionProvider } from "@parcha/agentrun-dsl";
12
12
  import type { Refusal } from "@parcha/agentrun-kernel";
13
13
  import type { RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
14
+ import { type ReplayCalls } from "./learn/replay-calls.js";
14
15
  /** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
15
16
  export declare const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
16
17
  /** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
@@ -105,6 +106,10 @@ export type LearnedWorkflowRun = {
105
106
  decide?: (tool: string, args: unknown) => Promise<"allow" | "ask" | {
106
107
  deny: string;
107
108
  }>;
109
+ /** A replay run's (runner/promotion.ts): its call nodes go through the replay's rules (learn/replay-calls.ts: a read
110
+ * live through a cache seeded from the graded run's recorded calls, a write only ever answered from that recording),
111
+ * and a write the recording does not have stops the workflow there, skipped. Absent: every call node runs live. */
112
+ replay?: ReplayCalls;
108
113
  };
109
114
  /** The most characters of a learned workflow's output its answer holds, monid's bound (monid.ts CLIP): within the
110
115
  * host's result bound, which each CLI is told to pass whole (host-bounds.test). */
@@ -125,15 +130,26 @@ export declare const learnedWorkflowDescription: (workflows: readonly LearnedWor
125
130
  * field (a node's record of one field, as a last node that writes the answer gives it), so the lines its last node wrote
126
131
  * reach the model as lines; else JSON. */
127
132
  export declare function learnedOutput(output: unknown): string;
133
+ /** What a learned workflow that escalated says to whoever takes the job on: the step that handed it back and its own
134
+ * words for why, the steps it ran, and what it had found (its state's top-level fields, each whole or named by its
135
+ * size). A guard that fails is a handback, never a failure of the run: the agent finishes the job from here. */
136
+ export declare function handedBackText(name: string, escalation: {
137
+ kind: string;
138
+ stage: string;
139
+ summary: string;
140
+ label?: string;
141
+ }, state: Record<string, unknown>, nodes: readonly LearnedNode[], guards?: readonly GuardRow[]): string;
128
142
  /** The run's `learned_workflow` tool over `run.workflows`. */
129
143
  export declare function learnedWorkflowTool(run: LearnedWorkflowRun): ToolRegistration;
130
144
  /** `flow` run on `input` for `run`: its output as its tool hands it back (learnedOutput), or why it did not run, and each of its nodes that ran (at most
131
145
  * LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
132
146
  * which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
133
- * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
134
- export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[]): Promise<{
147
+ * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. `guards`: where every guard
148
+ * check is added as it is made, never capped (a map's checks past the trace's cap too), the caller's to keep likewise. */
149
+ export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[], guards?: GuardRow[]): Promise<{
135
150
  text: string;
136
151
  isError: boolean;
137
152
  nodes: LearnedNode[];
153
+ ended: LearnedEnded;
138
154
  }>;
139
155
  export {};
@@ -20,15 +20,14 @@
20
20
  // has no room for never sent, the run paused on the cap's refusal (ledger.pause). A run handed none runs no
21
21
  // decision node: the check refuses it before any node runs.
22
22
  // Each model request is a request on the run's one route, so what the workflow spends is the run's cost, under its cap:
23
- // on pi the run's models, as a side request (request-start.ts, cap.ts: marked, and costed on the run's timeline as
24
- // `learned_workflow`); on another harness the session's model proxy, under a side key (port-models.ts): the harness's
23
+ // the session's model proxy, under a side key (port-models.ts): the harness's
25
24
  // own policy, provider, key and price, booked on the session's records labelled `learned_workflow`. A call a crash cut
26
25
  // off is never run again (`replay: "never"`): it is answered interrupted.
27
26
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
28
27
  import { defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
29
28
  import { registerLabel, registerOutcome } from "./timeline/index.js";
30
- import { sideRequests } from "./cap.js";
31
29
  import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
30
+ import { guardJevOn, guardLine, rowOf, stepGuard } from "./runner/step-guard.js";
32
31
  import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
33
32
  import { decisionsAsked, deniedDecisionWords } from "./learn/skills.js";
34
33
  import { DEFAULT_DECISION_PROVIDER } from "./decisions.js";
@@ -38,8 +37,11 @@ import { PORT_PROVIDER } from "./port-models.js";
38
37
  import { forModel } from "./result.js";
39
38
  import { ARGS_PREVIEW_BYTES, deniedText } from "./tool-gate.js";
40
39
  import { allows, CALL_TOOLS, learnedDraftTools, toolOf, workflowTools } from "./tools.js";
40
+ import { isMcpName } from "./tool-names.js";
41
41
  import { hostCalls } from "./host-calls.js";
42
42
  import { workflowNodes } from "./model.js";
43
+ import { SKIPPED_WRITE, toolWord, unmarkedWords } from "./learn/replay-calls.js";
44
+ import { SOFT_ESCALATE_THRESHOLD, softEscalatesOf } from "./learn/promote.js";
43
45
  /** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
44
46
  export const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
45
47
  /** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
@@ -57,8 +59,6 @@ export const learnedAskFits = (asks) => Buffer.byteLength(JSON.stringify(learned
57
59
  * or the card named none. A tool set to ask that the card did not name (one set to ask after the card was shown) is
58
60
  * never run under that approval. */
59
61
  export const learnedApprovedTools = (card) => new Set(Array.isArray(card?.mcp_calls) ? card.mcp_calls.filter((name) => typeof name === "string") : []);
60
- /** An MCP tool's catalog name, `mcp:<server>/<tool>`: a call node that names one runs it through the run's own MCP. */
61
- const MCP_TOOL = /^mcp:[^/]+\/.+$/;
62
62
  /** The MCP tools a learned workflow's call nodes name (`via: "tool"`, `tool: "mcp:<server>/<tool>"`), each once; none for
63
63
  * one that does not read. The run's gate asks about them before the workflow's call runs (adapter-run-spec.ts). */
64
64
  export async function learnedMcpTools(workflow) {
@@ -71,7 +71,7 @@ export async function learnedMcpTools(workflow) {
71
71
  }
72
72
  const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
73
73
  try {
74
- return workflowTools(workflowNodes(doc, inspectWorkflow(doc))).calls.filter((tool) => MCP_TOOL.test(tool));
74
+ return workflowTools(workflowNodes(doc, inspectWorkflow(doc))).calls.filter((tool) => isMcpName(tool));
75
75
  }
76
76
  catch {
77
77
  return [];
@@ -173,12 +173,10 @@ export function learnedOutput(output) {
173
173
  return JSON.stringify(output ?? null);
174
174
  }
175
175
  /** One model request as a pi-ai event stream, sent through `models.completeSimple` as the run's own request, under its
176
- * cap: on pi marked and costed on the run's timeline under `learned_workflow` (sideRequests), on another harness booked
177
- * by the session's proxy, labelled by the side key it goes under. */
176
+ * cap: booked by the session's proxy, labelled by the side key it goes under. */
178
177
  async function sideStream(models, model, context, options) {
179
178
  const { createAssistantMessageEventStream } = await import("@earendil-works/pi-ai");
180
179
  const stream = createAssistantMessageEventStream();
181
- sideRequests.set(context, { label: LEARNED_WORKFLOW_TOOL, extraInputTokens: 0, maxFeeUsd: 0, feeUsd: () => 0 });
182
180
  void (async () => {
183
181
  try {
184
182
  const message = (await models.completeSimple(model, context, options));
@@ -196,13 +194,36 @@ async function sideStream(models, model, context, options) {
196
194
  })();
197
195
  return stream;
198
196
  }
197
+ /** The most of a state's fields a handback names, and the longest value it shows whole: a longer one is named by its
198
+ * size, never cut mid-value, so the run's redactor still finds a held value in what it shows. */
199
+ const HANDBACK_FIELDS = 20;
200
+ const HANDBACK_VALUE = 2_000;
201
+ /** The steps a learned workflow ran, as one line after its words: each node's label, kind and status; then the guards of
202
+ * those steps, and any check that handed back on a step past the trace's cap (`guards`: every check of the call). */
203
+ const stepsLine = (nodes, guards = []) => {
204
+ const shown = nodes.flatMap(({ guard }) => (guard ? [guard] : []));
205
+ const lines = [...shown, ...guards.filter((row) => row.escalated && !shown.includes(row))].map(guardLine);
206
+ return (nodes.length ? `\nIts steps: ${nodes.map(({ label, kind, status }) => `${label} (${kind}) ${status}`).join("; ")}.` : "") + (lines.length ? `\nIts guards: ${lines.join("; ")}.` : "");
207
+ };
208
+ /** What a learned workflow that escalated says to whoever takes the job on: the step that handed it back and its own
209
+ * words for why, the steps it ran, and what it had found (its state's top-level fields, each whole or named by its
210
+ * size). A guard that fails is a handback, never a failure of the run: the agent finishes the job from here. */
211
+ export function handedBackText(name, escalation, state, nodes, guards = []) {
212
+ const at = escalation.label ? ` at its step "${escalation.label}"` : "";
213
+ const why = escalation.summary?.trim() || escalation.kind;
214
+ const fields = Object.entries(state ?? {}).filter(([key]) => !key.startsWith("$")).slice(0, HANDBACK_FIELDS).map(([key, value]) => {
215
+ const text = typeof value === "string" ? value : JSON.stringify(value) ?? "null";
216
+ return `- ${key}: ${text.length > HANDBACK_VALUE ? `(${text.length} characters)` : text}`;
217
+ });
218
+ return [`The learned workflow ${name} handed the job back${at}: ${why}${stepsLine(nodes, guards)}`, ...(fields.length ? ["What it had:", ...fields] : [])].join("\n");
219
+ }
199
220
  /** The run's `learned_workflow` tool over `run.workflows`. */
200
221
  export function learnedWorkflowTool(run) {
201
222
  const names = run.workflows.map(({ name }) => name);
202
223
  return defineTool({
203
224
  name: LEARNED_WORKFLOW_TOOL,
204
225
  description: learnedWorkflowDescription(run.workflows),
205
- // Never run again after a crash (pi-durable's "unsafe"; a HostTool's "never": host-tools.ts REPLAY).
226
+ // Never run again after a crash (pi-durable's "unsafe"; a HostTool's "never": tool-list.ts `replay`).
206
227
  replay: "unsafe",
207
228
  parameters: {
208
229
  type: "object",
@@ -219,21 +240,31 @@ export function learnedWorkflowTool(run) {
219
240
  const flow = run.workflows.find((workflow) => workflow.name === name);
220
241
  if (!flow)
221
242
  return forModel(`No learned workflow of this agent is named ${JSON.stringify(name)}. Its workflows: ${names.join(", ")}.`, { isError: true });
222
- const ledger = ledgerOf(api, context);
223
- // Which of its nodes ran, kept beside the call in the run's journal (LEARNED_NODES), for its timeline row; a trace
224
- // that can't be kept never fails the call. A call stopped part way keeps the nodes that ended before it stopped,
243
+ const ledger = ledgerOf(api.callId);
244
+ // Which of its nodes ran, kept beside the call in the run's journal (LEARNED_NODES), for its timeline row, and every
245
+ // guard check it made (`guards`, uncapped: the run's metrics, B4's replay and refit read each); a trace that can't
246
+ // be kept never fails the call. A call stopped part way keeps the nodes and checks that ended before it stopped,
225
247
  // written outside the stopped call's context, and still ends as a stop.
226
248
  const trace = [];
227
- const keep = (signal) => (trace.length ? api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace } })), signal).catch(() => undefined) : undefined);
249
+ const guards = [];
250
+ // A replay's write the recording did not have (learn/replay-calls.ts) rides on the same entry, ran a node or not; so
251
+ // does how the workflow ended (`ended`, LearnedEnded), the one thing a replay's outcome reads (workflow-first.ts
252
+ // pathMetrics): a replay run keeps its entry whatever ran, so a refusal before any node is read as one.
253
+ const keep = (signal, ended) => {
254
+ const skipped = run.replay?.skipped;
255
+ if (!trace.length && !guards.length && !skipped && !(run.replay && ended))
256
+ return undefined;
257
+ return api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace, ...(guards.length ? { guards } : {}), ...(skipped ? { replay_skipped: skipped } : {}), ...(ended ? { ended } : {}) } })), signal).catch(() => undefined);
258
+ };
228
259
  let said;
229
260
  try {
230
- said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace);
261
+ said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace, guards);
231
262
  }
232
263
  catch (error) {
233
264
  await keep(BACKGROUND_CONTEXT);
234
265
  throw error;
235
266
  }
236
- await keep(context);
267
+ await keep(context, said.ended);
237
268
  return forModel(said.text, { isError: said.isError });
238
269
  },
239
270
  });
@@ -241,9 +272,10 @@ export function learnedWorkflowTool(run) {
241
272
  /** `flow` run on `input` for `run`: its output as its tool hands it back (learnedOutput), or why it did not run, and each of its nodes that ran (at most
242
273
  * LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
243
274
  * which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
244
- * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
245
- export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
246
- const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true, nodes });
275
+ * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. `guards`: where every guard
276
+ * check is added as it is made, never capped (a map's checks past the trace's cap too), the caller's to keep likewise. */
277
+ export async function runLearned(run, flow, input, signal, ledger, nodes = [], guards = []) {
278
+ const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true, nodes, ended: "failed" });
247
279
  if (!input || typeof input !== "object" || Array.isArray(input))
248
280
  return refuse("its input must be a JSON object");
249
281
  const dsl = await import("@parcha/agentrun-dsl");
@@ -305,12 +337,12 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
305
337
  // Its own signal, which the DSL ties to the call's (a sibling's failure, a deadline, the call's stop).
306
338
  return (await runnerFor(request.tier))(request);
307
339
  };
308
- const runEffect = async ({ node, input: given, signal: own, executionPath, item }) => {
340
+ const liveEffect = async ({ node, input: given, signal: own, executionPath, item }) => {
309
341
  const tool = node.via === "tool" ? node.tool : undefined;
310
342
  // Its call id under the workflow's call: the node, its execution path, its item in a map. Its paid requests are booked
311
343
  // under it, as a call of its own.
312
344
  const callId = `${ledger?.call ?? LEARNED_WORKFLOW_TOOL}/${node.label}@${executionPath ?? ""}${item ? `#${item.index}` : ""}`;
313
- if (tool && MCP_TOOL.test(tool)) {
345
+ if (tool && isMcpName(tool)) {
314
346
  // An MCP tool of the run, through the run's own MCP as the loop wrapped it (its flush, its booking on the run's one
315
347
  // ledger, a CLI's record, the stop's abort), after the gate's rule read again now, as the harness's own call is.
316
348
  const send = (run.mcpTools ?? []).includes(tool) && run.decide ? hostCalls()?.mcp(tool) : undefined;
@@ -346,28 +378,75 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
346
378
  if (permission === "ask")
347
379
  throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
348
380
  // Its paid requests booked under the tool's call, as a call of its own: the node, its execution path, its item in a map.
349
- const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
381
+ const booked = ledger ? { ledger: { ...ledger, call: callId } } : {};
350
382
  return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...(run.search ? { search: run.search } : {}), ...booked });
351
383
  };
384
+ // A replay run's call nodes through the replay's rules (learn/replay-calls.ts); a live one runs as above, gate and all.
385
+ const replay = run.replay;
386
+ const runEffect = (request) => {
387
+ const tool = request.node.via === "tool" ? request.node.tool : undefined;
388
+ return replay && tool ? replay.call({ label: request.node.label, tool }, request.input, () => liveEffect(request)) : liveEffect(request);
389
+ };
390
+ // A replay's write with no recording stops the whole workflow there: nothing after it runs.
391
+ const stopped = replay ? (signal ? AbortSignal.any([signal, replay.stop]) : replay.stop) : signal;
392
+ const skippedWords = () => {
393
+ const skipped = replay?.skipped;
394
+ const why = skipped?.unmarked ? `${unmarkedWords([toolWord(skipped.tool)])}; the graded run's recording has no call of it with these arguments` : `a write, and the graded run's recording has no call of it with these arguments, so it ${SKIPPED_WRITE}`;
395
+ return skipped ? { text: `The learned workflow ${flow.name} was not replayed on this input: its step "${skipped.step}" calls ${skipped.tool}, ${why}. Nothing was sent.${stepsLine(nodes, guards)}`, isError: true, nodes, ended: "failed" } : undefined;
396
+ };
397
+ // Its step guards (runner/step-guard.ts): a guard's Jev is a decision of the call, on the run's decisions (its judge,
398
+ // its gate, its one cap); a run with no Jev provider has no Jev signal, so a guard that reads one hands back.
399
+ const jevProvider = run.decisions?.providers.providers.jev;
400
+ const guardStep = stepGuard(runJudge && jevProvider ? guardJevOn(runJudge, jevProvider) : undefined);
401
+ // Each guard's check by its step's execution path, as the DSL decided it: kept in `guards` at once (what the run's
402
+ // metrics read), and its node.end (the same path) puts it on the step's trace, where the timeline and a hand-back say it.
403
+ const guarded = new Map();
404
+ // A replay records each escalate that reads a judge's field instead of obeying it (learn/promote.ts softEscalatesOf):
405
+ // the workflow goes on to its answer, and the escalate's row says whether it fired, for the replay's score at the
406
+ // serving setting (it hands back when it fired) and the refit (it may be switched off). Serving obeys every escalate.
407
+ const soft = replay ? softEscalatesOf(doc) : undefined;
352
408
  // Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
353
409
  const onEvent = (event) => {
410
+ if (event.type === "escalate.evaluated") {
411
+ const detail = (event.detail ?? {});
412
+ if (detail.soft === true)
413
+ guards.push({ node: String(event.label), signal: "escalate", p: detail.fired === true ? 0 : 1, threshold: SOFT_ESCALATE_THRESHOLD, escalated: false });
414
+ return;
415
+ }
416
+ if (event.type === "guard.evaluated") {
417
+ const row = rowOf(String(event.label), event.detail);
418
+ if (row) {
419
+ guards.push(row);
420
+ guarded.set(event.executionPath ?? String(event.label), row);
421
+ }
422
+ return;
423
+ }
354
424
  if (event.type !== "node.end" || nodes.length >= LEARNED_NODES_MAX)
355
425
  return;
356
426
  const detail = (event.detail ?? {});
357
427
  const ran = typeof event.executionPath === "string" ? ranOn.get(event.executionPath) : undefined;
358
- nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0, ...ran });
428
+ const guard = guarded.get(event.executionPath ?? String(event.label));
429
+ nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0, ...ran, ...(guard ? { guard } : {}) });
359
430
  };
360
431
  try {
361
432
  const judging = runJudge && run.decisions ? { runJudge, decisionProviders: run.decisions.providers } : {};
362
- const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...judging, ...(signal ? { signal } : {}) });
433
+ const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, guardStep, onEvent, ...judging, ...(soft?.size ? { softEscalate: (label) => soft.has(label) } : {}), ...(stopped ? { signal: stopped } : {}) });
434
+ const skipped = skippedWords();
435
+ if (skipped)
436
+ return skipped;
437
+ if (result.status === "escalated")
438
+ return { text: learnedText(handedBackText(flow.name, result.escalation, result.state, nodes, guards)), isError: true, nodes, ended: "escalated" };
363
439
  if (result.status !== "complete")
364
440
  return refuse(`it ended ${result.status}`);
365
- return { text: learnedText(learnedOutput(result.output)), isError: false, nodes };
441
+ return { text: learnedText(learnedOutput(result.output)), isError: false, nodes, ended: "complete" };
366
442
  }
367
443
  catch (error) {
368
444
  if (signal?.aborted)
369
445
  throw error;
370
- return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true, nodes };
446
+ const skipped = skippedWords();
447
+ if (skipped)
448
+ return skipped;
449
+ return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}${stepsLine(nodes, guards)}`, isError: true, nodes, ended: "failed" };
371
450
  }
372
451
  }
373
452
  /** The draft check's decisions for `run` (learn/skills.ts DraftDecisions): its providers, and the gate's setting of each
@@ -95,8 +95,8 @@ export type Header = {
95
95
  /** The rows' total $ (job and learning) of the rows finished, and how many of them cost nothing known. */
96
96
  spent_usd: number;
97
97
  unknown_cost_rows: number;
98
- /** Rows finished by the path their run took. */
99
- paths: Record<RunPath, number>;
98
+ /** Rows finished by the path their run took (a batch's run is never a replay run: runner/promotion.ts starts those). */
99
+ paths: Record<Exclude<RunPath, "replay">, number>;
100
100
  /** What the batch's learning kept, each name once, and the merges that touched workflows: [{row, commit, workflows}]. */
101
101
  lessons: Lessons;
102
102
  revisions: {
@@ -557,7 +557,7 @@ export class LearningBatches {
557
557
  if (row.run_id && (row.total_usd === null || row.total_usd === undefined))
558
558
  next.unknown_cost_rows++;
559
559
  spent += row.total_usd ?? 0;
560
- if (row.path)
560
+ if (row.path && row.path !== "replay")
561
561
  next.paths[row.path]++;
562
562
  for (const kind of ["notes", "skills", "workflows"])
563
563
  for (const name of row.learned?.[kind] ?? [])
@@ -1,8 +1,11 @@
1
- /** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
2
- * calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
3
- * to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
4
- * went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
5
- export declare const RUN_PATHS: readonly ["agent", "handed_back", "workflow"];
1
+ /** The path a run took: `workflow`, a learned workflow finished it alone (served first and answered, or its job's only
2
+ * tool calls were learned_workflow calls, each answering, and nothing was said after its first message: the runner's own
3
+ * rule for a run with nothing new to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a
4
+ * learned workflow ran and the agent went on (it handed back, failed, escalated, or the agent did more work after it);
5
+ * `agent`, no learned workflow ran; `replay`, a replay run deciding whether a learned workflow's new revision serves
6
+ * (runner/promotion.ts: the workflow alone on a graded run's input, at workflow cost). One classifier (store-reads/learning.ts runPathOverStore) writes it on the run's
7
+ * record at its end (metrics.path). */
8
+ export declare const RUN_PATHS: readonly ["agent", "handed_back", "workflow", "replay"];
6
9
  export type RunPath = (typeof RUN_PATHS)[number];
7
10
  /** What a run that looked back kept of its costs as it answered (runner/reflect-hook.ts: store-reads/learning.ts
8
11
  * answeredOf): when the job answered, what it had cost by then and what looking back cost after it. */
@@ -42,6 +45,9 @@ export type CostRun = {
42
45
  };
43
46
  /** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
44
47
  export declare const CHEAPER_AFTER_RUNS = 20;
48
+ /** How many of a learned workflow's newest runs served first at one version the money rule reads
49
+ * (runner/workflow-first.ts costLineOf); under that many, it serves. */
50
+ export declare const COST_WINDOW = 10;
45
51
  /** The latest runs the route answers by default, and at most. */
46
52
  export declare const COST_RUNS_DEFAULT = 1000;
47
53
  export declare const COST_RUNS_MAX = 10000;
@@ -49,7 +55,9 @@ export declare const COST_RUNS_MAX = 10000;
49
55
  * (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known;
50
56
  * `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known; and
51
57
  * `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more, else null. The
52
- * before side leaves learning out and the after side keeps it in, so the figure never flatters learning. */
58
+ * before side leaves learning out and the after side keeps it in, so the figure never flatters learning. `hand_backs`:
59
+ * of the runs a learned workflow ran first on from the takeover on (`workflow` or `handed_back`), how many handed back;
60
+ * null before a takeover. Every one is over every run, never only the latest a read lists. */
53
61
  export type CostSummary = {
54
62
  takeover: {
55
63
  n: number;
@@ -64,6 +72,10 @@ export type CostSummary = {
64
72
  mean_usd: number;
65
73
  } | null;
66
74
  times_cheaper: number | null;
75
+ hand_backs: {
76
+ ran: number;
77
+ back: number;
78
+ } | null;
67
79
  };
68
80
  export declare function costSummary(runs: readonly CostRun[]): CostSummary;
69
81
  /** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
@@ -1,15 +1,18 @@
1
1
  // An agent's cost per run, run after run (GET /agents/{id}/learning/cost): what each run of its cost, what learning added
2
2
  // for it, and the path it took, so a person sees the cost fall once a learned workflow does the job, and by how much.
3
3
  // Aggregates only: no run's input, answer or tool text. The store's reader (store-reads/learning.ts agentCostOverStore)
4
- // gives each run's figures and its path (runner/learning-end.ts runPathOf); this module sums its learning and says what the
4
+ // gives each run's figures and its path (its run record's metrics.path, store-reads/learning.ts runPathOverStore); this module sums its learning and says what the
5
5
  // series shows (costSummary), the rule the console, the CLI and the CSV all read. It imports only the errors, so the API
6
6
  // document reads its words.
7
7
  import { ApiError } from "./errors.js";
8
- /** The path a run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow
9
- * calls, each answering, and nothing was said after its first message: the runner's own rule for a run with nothing new
10
- * to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a learned workflow ran and the agent
11
- * went on (it failed, escalated, or the agent did more work after it); `agent`, no learned workflow ran. */
12
- export const RUN_PATHS = ["agent", "handed_back", "workflow"];
8
+ /** The path a run took: `workflow`, a learned workflow finished it alone (served first and answered, or its job's only
9
+ * tool calls were learned_workflow calls, each answering, and nothing was said after its first message: the runner's own
10
+ * rule for a run with nothing new to look back on, runner/learning-end.ts onlyLearnedWorkflows); `handed_back`, a
11
+ * learned workflow ran and the agent went on (it handed back, failed, escalated, or the agent did more work after it);
12
+ * `agent`, no learned workflow ran; `replay`, a replay run deciding whether a learned workflow's new revision serves
13
+ * (runner/promotion.ts: the workflow alone on a graded run's input, at workflow cost). One classifier (store-reads/learning.ts runPathOverStore) writes it on the run's
14
+ * record at its end (metrics.path). */
15
+ export const RUN_PATHS = ["agent", "handed_back", "workflow", "replay"];
13
16
  const usd = (value) => Math.round(value * 1e6) / 1e6;
14
17
  /** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
15
18
  * person asked of it after), what it kept as it answered (`looked`, none for a run that did not look back) and what its
@@ -32,6 +35,9 @@ export function runCostOf(rowUsd, looked, gradeUsd = 0) {
32
35
  }
33
36
  /** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
34
37
  export const CHEAPER_AFTER_RUNS = 20;
38
+ /** How many of a learned workflow's newest runs served first at one version the money rule reads
39
+ * (runner/workflow-first.ts costLineOf); under that many, it serves. */
40
+ export const COST_WINDOW = 10;
35
41
  /** The latest runs the route answers by default, and at most. */
36
42
  export const COST_RUNS_DEFAULT = 1000;
37
43
  export const COST_RUNS_MAX = 10_000;
@@ -41,7 +47,9 @@ export function costSummary(runs) {
41
47
  const before = mean((first < 0 ? runs : runs.slice(0, first)).flatMap((run) => (run.path === "agent" && run.cost_usd !== null ? [run.cost_usd] : [])));
42
48
  const after = first < 0 ? null : mean(runs.slice(first).flatMap((run) => (run.total_usd === null ? [] : [run.total_usd])));
43
49
  const times = before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
44
- return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times };
50
+ const ranFirst = first < 0 ? [] : runs.slice(first).filter((run) => run.path === "workflow" || run.path === "handed_back");
51
+ const handBacks = first < 0 ? null : { ran: ranFirst.length, back: ranFirst.filter((run) => run.path === "handed_back").length };
52
+ return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times, hand_backs: handBacks };
45
53
  }
46
54
  /** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
47
55
  * a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
@@ -121,6 +121,7 @@ type WorkflowRevision = {
121
121
  by: Change["by"];
122
122
  reason: string;
123
123
  text: string | null;
124
+ digest: string | null;
124
125
  };
125
126
  /** GET /agents/{id}/learning/workflows/{name}/revisions?limit=: the latest revisions of learned workflow `name` (the
126
127
  * commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
@@ -238,6 +239,17 @@ export declare function runLearningBody(input: {
238
239
  path?: string | undefined;
239
240
  rule: import("./learn/check.js").Rule;
240
241
  }[];
242
+ compiled: {
243
+ workflow: string;
244
+ from_notes: string[];
245
+ attempts: {
246
+ ok: boolean;
247
+ errors: string[];
248
+ }[];
249
+ digest: string | null;
250
+ promoted: boolean | null;
251
+ } | null;
252
+ draft_errors: string[];
241
253
  cost_usd: {
242
254
  grade: number | null;
243
255
  };
@@ -261,8 +273,8 @@ export declare function runLearningBody(input: {
261
273
  skills?: import("./learning.js").LearnedFile[];
262
274
  workflows?: import("./learning.js").LearnedFile[];
263
275
  run: string;
264
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
265
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
276
+ state: "proposed" | "dropped" | "merged" | "seeded" | "reflecting";
277
+ reason: "cancelled" | "no_budget" | "empty" | "unparsed" | "use" | "seed_failed" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
266
278
  detail: string | null;
267
279
  at: string;
268
280
  };
@@ -1,3 +1,5 @@
1
+ import { noteBytes } from "./learn/check.js";
2
+ import { createHash } from "node:crypto";
1
3
  import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR, unclearFront, restorable, restore, restoredLearned } from "./learn/index.js";
2
4
  import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotNotes, textsAt, writeLearning } from "./learn/folder.js";
3
5
  import { ApiError, invalid } from "./errors.js";
@@ -233,7 +235,10 @@ export async function workflowRevisions(data, agentId, name, query, shown) {
233
235
  const revisions = [];
234
236
  for (const change of latest) {
235
237
  const texts = await textsAt(ws, change.commit, [path]).catch((error) => { throw routeFailure(error); });
236
- revisions.push({ commit: change.commit, at: change.at, by: change.by, reason: shown.text(change.reason), text: texts?.[path] === undefined ? null : shown.text(texts[path]) });
238
+ const raw = texts?.[path];
239
+ // Its digest, read from the text as it is (workflow-first.ts workflowDigest's): the one a run's metrics and the
240
+ // promotion records name, so a revision's runs, guards and promotion are found by it.
241
+ revisions.push({ commit: change.commit, at: change.at, by: change.by, reason: shown.text(change.reason), text: raw === undefined ? null : shown.text(raw), digest: raw === undefined ? null : createHash("sha256").update(raw).digest("hex").slice(0, 16) });
237
242
  }
238
243
  return { revisions, total: touched.length, truncated: snapshot.log_more };
239
244
  }, () => undefined);
@@ -517,9 +522,9 @@ export async function writeNote(data, agentId, raw, input) {
517
522
  const retired = parseNoteFile(file, text);
518
523
  if (Array.isArray(retired))
519
524
  throw refused(retired.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
520
- const size = Buffer.byteLength(text);
525
+ const size = noteBytes(text);
521
526
  if (size > CAPS.note + RETIRED_LINE)
522
- throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status lines a retire adds` }, input.refuse)]);
527
+ throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status lines a retire adds (a compiled_into line on top)` }, input.refuse)]);
523
528
  }
524
529
  if (current && text === current.text)
525
530
  return { result: { status: 200, file, text, etag: etagOf(current.oid) } };
@@ -620,6 +625,12 @@ export function runLearningBody(input, shown, secrets) {
620
625
  verdict: verdict ? { merge: verdict.merge, reason: shown.text(verdict.reason), items: (verdict.items ?? []).map(({ file, keep, pending: waits, origin, question, why }) => ({ file: shown.name(file), keep, ...(waits ? { pending: true } : {}), ...(origin ? { origin: shown.text(origin) } : {}), ...(question ? { question: shown.text(question) } : {}), why: shown.text(why) })) } : null,
621
626
  // Each cut of the host's secrets (printable), then as every served text is (`shown`: no loopback address).
622
627
  problems: (problems ?? []).map((problem) => printable(problem, secrets)).map(({ rule, path, detail }) => ({ rule: shown.text(rule), ...(path === undefined ? {} : { path: shown.text(path) }), detail: shown.text(detail) })),
628
+ // The compile turn's record (learn/compile.ts): the workflow it wrote, the notes it absorbed and each attempt with
629
+ // what the checks refused, its kept draft's digest and whether that serves (its promotion: true, held false, null
630
+ // while undecided); null when the run compiled nothing. A draft that never passed is never silent: its
631
+ // errors are `draft_errors`. Each text cut of the host's secrets.
632
+ compiled: learning.compiled ? { workflow: shown.name(learning.compiled.workflow), from_notes: learning.compiled.from_notes.map(shown.name), attempts: learning.compiled.attempts.map(({ ok, errors }) => ({ ok, errors: errors.map((error) => shown.text(printable({ rule: "workflow", detail: error }, secrets).detail)) })), digest: learning.compiled.digest ?? null, promoted: learning.compiled.promoted ?? null } : null,
633
+ draft_errors: (learning.draft_errors ?? []).map((error) => shown.text(printable({ rule: "workflow", detail: error }, secrets).detail)),
623
634
  // The grade's alone: the end-of-run turn's cost is in the run's own totals.
624
635
  cost_usd: { grade: cost_usd?.grade ?? null },
625
636
  tokens: { grade: tokens?.grade ?? null },
@@ -36,6 +36,10 @@ export declare const said: {
36
36
  /** The end-of-run turn asked again because a workflow draft failed its dry run (learn/reflect.ts reflectDryRun), as a
37
37
  * person reads it in the timeline: never the ask, which holds the check's words. */
38
38
  askedDryRun: string;
39
+ /** The compile turn's ask (learn/compile.ts askedForCompile): the job written as a workflow, or a revision of one, or
40
+ * an attempt the checks sent back. */
41
+ askedCompile: string;
42
+ askedCompileAgain: string;
39
43
  proposed: (notes: number, skills?: number, workflows?: number) => string;
40
44
  /** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
41
45
  * waits for the owner's OK, by name; then, when the grader dropped an item and kept others (a verdict per item), its
@@ -73,6 +77,9 @@ export declare const said: {
73
77
  /** A grade under a cap whose cost can't be kept within it (its spend or the grade model's price unknown). */
74
78
  gradeUncapped: string;
75
79
  unknownCost: string;
80
+ /** A capped run whose spend under its cap is unknown once it looked back: its grade is not run (none could be kept
81
+ * within the cap), so nothing it learned is kept. */
82
+ gradeUnknownSpend: string;
76
83
  stopped: (cause: string) => string;
77
84
  };
78
85
  /** Why a verdict kept nothing, in a person's words: the grader's word on the first note it did not keep, since its
@@ -102,6 +102,10 @@ export const said = {
102
102
  /** The end-of-run turn asked again because a workflow draft failed its dry run (learn/reflect.ts reflectDryRun), as a
103
103
  * person reads it in the timeline: never the ask, which holds the check's words. */
104
104
  askedDryRun: "Looking back again: a workflow draft did not pass its dry run.",
105
+ /** The compile turn's ask (learn/compile.ts askedForCompile): the job written as a workflow, or a revision of one, or
106
+ * an attempt the checks sent back. */
107
+ askedCompile: "Writing this job as a learned workflow.",
108
+ askedCompileAgain: "Writing the workflow again: the checks sent back what they refused.",
105
109
  proposed: (notes, skills = 0, workflows = 0) => `Checking ${listed([...(notes || !(skills || workflows) ? [count(notes, "new note")] : []), ...(skills ? [count(skills, "skill")] : []), ...(workflows ? [count(workflows, "workflow")] : [])])}…`,
106
110
  /** What it learned, by name, and how many older notes they replace, and its skill and workflow by name; then what
107
111
  * waits for the owner's OK, by name; then, when the grader dropped an item and kept others (a verdict per item), its
@@ -151,6 +155,9 @@ export const said = {
151
155
  /** A grade under a cap whose cost can't be kept within it (its spend or the grade model's price unknown). */
152
156
  gradeUncapped: "Not graded: the grade's cost can't be kept under the cap.",
153
157
  unknownCost: "Skipped: this run's spend is unknown, so its budget can't cover looking back.",
158
+ /** A capped run whose spend under its cap is unknown once it looked back: its grade is not run (none could be kept
159
+ * within the cap), so nothing it learned is kept. */
160
+ gradeUnknownSpend: "Not graded: this run's spend is unknown, so its budget can't cover the grade.",
154
161
  stopped: (cause) => `Not kept: learning stopped (${cause}).`,
155
162
  };
156
163
  /** The reasons learn/grade.ts' parseVerdict gives of its own, never the grader's: an answer it could not read, and one