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

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 (410) hide show
  1. package/CHANGELOG.md +418 -0
  2. package/README.md +325 -124
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  37. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +84 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +10 -0
  46. package/dist/email/answer.js +182 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +380 -0
  53. package/dist/email/names.d.ts +20 -0
  54. package/dist/email/names.js +40 -0
  55. package/dist/email/routes.d.ts +9 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +20 -0
  58. package/dist/email/tools.js +517 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +9 -2
  93. package/dist/learn/compile.js +52 -16
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +106 -51
  97. package/dist/learn/promote.js +82 -189
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +26 -8
  109. package/dist/learning-cost.js +17 -7
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +33 -2
  118. package/dist/local-models.js +43 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +1 -0
  164. package/dist/openapi.js +394 -85
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +7 -2
  170. package/dist/port-models.js +5 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +11 -0
  180. package/dist/refusal-words.js +13 -2
  181. package/dist/run-launch.d.ts +10 -1
  182. package/dist/run-launch.js +11 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +42 -35
  191. package/dist/run-view.js +79 -44
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +42 -11
  195. package/dist/runner/adapter-loop.js +651 -247
  196. package/dist/runner/adapter-run-spec.d.ts +37 -12
  197. package/dist/runner/adapter-run-spec.js +139 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +94 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +37 -13
  217. package/dist/runner/journal-kinds.js +9 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +12 -3
  237. package/dist/runner/model-route.js +139 -18
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +74 -8
  243. package/dist/runner/promotion.js +365 -124
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +554 -130
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/index.d.ts +1 -1
  278. package/dist/store/native-command-owner.d.ts +10 -0
  279. package/dist/store/native-command-owner.js +47 -0
  280. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  281. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  282. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  283. package/dist/store/postgres/store.js +3 -0
  284. package/dist/store/schema.d.ts +7 -0
  285. package/dist/store/schema.js +20 -1
  286. package/dist/store/sqlite/run-patch.d.ts +8 -1
  287. package/dist/store/sqlite/run-patch.js +14 -3
  288. package/dist/store/sqlite/store.js +133 -18
  289. package/dist/store/store.d.ts +52 -7
  290. package/dist/store-reads/analytics.d.ts +7 -7
  291. package/dist/store-reads/analytics.js +23 -5
  292. package/dist/store-reads/cap.js +8 -6
  293. package/dist/store-reads/journal.d.ts +5 -0
  294. package/dist/store-reads/journal.js +85 -41
  295. package/dist/store-reads/learning.d.ts +85 -5
  296. package/dist/store-reads/learning.js +45 -17
  297. package/dist/store-reads/runs.d.ts +5 -0
  298. package/dist/store-reads/runs.js +3 -2
  299. package/dist/store-view.js +75 -21
  300. package/dist/template-eval.d.ts +73 -11
  301. package/dist/template-eval.js +535 -75
  302. package/dist/templates.d.ts +70 -20
  303. package/dist/templates.js +191 -34
  304. package/dist/text-urls.d.ts +38 -0
  305. package/dist/text-urls.js +170 -0
  306. package/dist/timeline/index.d.ts +3 -2
  307. package/dist/timeline/index.js +3 -2
  308. package/dist/timeline/labels.d.ts +5 -2
  309. package/dist/timeline/labels.js +29 -6
  310. package/dist/timeline/origin.d.ts +1 -1
  311. package/dist/timeline/origin.js +2 -2
  312. package/dist/timeline/render-text.js +1 -1
  313. package/dist/timeline/timeline.d.ts +66 -4
  314. package/dist/timeline/timeline.js +160 -30
  315. package/dist/timeline/util.d.ts +5 -0
  316. package/dist/timeline/util.js +44 -8
  317. package/dist/timeline/web-calls.d.ts +17 -0
  318. package/dist/timeline/web-calls.js +106 -0
  319. package/dist/tool-gate.d.ts +42 -42
  320. package/dist/tool-gate.js +97 -91
  321. package/dist/tool-list.d.ts +4 -1
  322. package/dist/tool-list.js +8 -1
  323. package/dist/tool-names.d.ts +18 -13
  324. package/dist/tool-names.js +19 -17
  325. package/dist/tool-plane.d.ts +17 -13
  326. package/dist/tool-plane.js +12 -5
  327. package/dist/tools.d.ts +44 -16
  328. package/dist/tools.js +28 -28
  329. package/dist/trigger-adapter.d.ts +85 -5
  330. package/dist/trigger-adapter.js +6 -0
  331. package/dist/trigger-adapters.js +3 -1
  332. package/dist/trigger-composio.d.ts +10 -0
  333. package/dist/trigger-composio.js +122 -0
  334. package/dist/trigger-email.d.ts +4 -0
  335. package/dist/trigger-email.js +228 -0
  336. package/dist/trigger-signatures.d.ts +6 -10
  337. package/dist/trigger-signatures.js +16 -16
  338. package/dist/trigger-targets.d.ts +1 -1
  339. package/dist/trigger-targets.js +4 -3
  340. package/dist/trigger-webhook.js +6 -4
  341. package/dist/triggers.d.ts +94 -9
  342. package/dist/triggers.js +263 -62
  343. package/dist/uploads.d.ts +9 -0
  344. package/dist/uploads.js +27 -0
  345. package/dist/validate.js +1 -7
  346. package/dist/web-fake.d.ts +56 -0
  347. package/dist/web-fake.js +102 -0
  348. package/dist/web-fetch-direct.d.ts +3 -0
  349. package/dist/web-fetch-direct.js +4 -1
  350. package/dist/web-fetch.d.ts +5 -1
  351. package/dist/web-fetch.js +8 -31
  352. package/dist/web-search.d.ts +51 -2
  353. package/dist/web-search.js +116 -18
  354. package/dist/webhooks.d.ts +2 -1
  355. package/dist/webhooks.js +5 -1
  356. package/dist/workflow/node-runner.js +10 -2
  357. package/dist/workspace/archil-claim.d.ts +3 -0
  358. package/dist/workspace/archil-claim.js +9 -2
  359. package/dist/workspace/computer-deps.d.ts +22 -9
  360. package/dist/workspace/computer-deps.js +78 -37
  361. package/dist/workspace/computer-for-claim.d.ts +54 -4
  362. package/dist/workspace/computer-for-claim.js +179 -39
  363. package/dist/workspace/computer-janitor.d.ts +10 -3
  364. package/dist/workspace/computer-janitor.js +96 -29
  365. package/dist/workspace/computer-kept.d.ts +82 -0
  366. package/dist/workspace/computer-kept.js +147 -0
  367. package/dist/workspace/computer-mcp.js +4 -3
  368. package/dist/workspace/computer-ports.d.ts +23 -3
  369. package/dist/workspace/computer-ports.js +115 -5
  370. package/dist/workspace/index.d.ts +1 -2
  371. package/dist/workspace/index.js +1 -2
  372. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  373. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  374. package/dist/workspace/resolve-computer.d.ts +15 -3
  375. package/dist/workspace/resolve-computer.js +10 -7
  376. package/dist/workspace/revision-skills.d.ts +6 -2
  377. package/dist/workspace/revision-skills.js +12 -5
  378. package/dist/workspace/run-end-computers.d.ts +30 -0
  379. package/dist/workspace/run-end-computers.js +137 -0
  380. package/dist/workspace/run-tools.d.ts +28 -29
  381. package/dist/workspace/run-tools.js +29 -30
  382. package/dist/wrap-up.d.ts +19 -5
  383. package/dist/wrap-up.js +31 -4
  384. package/package.json +13 -9
  385. package/skills/agentrun-serve/SKILL.md +248 -10
  386. package/templates/README.md +117 -23
  387. package/templates/TOOLS.md +168 -0
  388. package/templates/code-review/agent.md +18 -4
  389. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  390. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  391. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  392. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  393. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  394. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  395. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  396. package/templates/code-review/skills/review/DEEP.md +2 -2
  397. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  398. package/templates/code-review/skills/review/SKILL.md +7 -3
  399. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  400. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  401. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  402. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  403. package/dist/console/assets/index-CjqQirbo.css +0 -1
  404. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  405. package/dist/host-calls.d.ts +0 -20
  406. package/dist/host-calls.js +0 -12
  407. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  408. package/dist/runner/adapters/pi-computer.js +0 -51
  409. package/dist/workspace/computer-script.d.ts +0 -53
  410. package/dist/workspace/computer-script.js +0 -172
@@ -6,7 +6,7 @@
6
6
  import { hiddenCharacter } from "./invisible.js";
7
7
  import { compiledLineBytes, INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile, ruleOf } from "./notes.js";
8
8
  import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
9
- import { draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedName, learnedPlace, setsStatus, skillProblems, WORKFLOWS_DIR } from "./skills.js";
9
+ import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedName, learnedPlace, setsStatus, skillProblems, WORKFLOWS_DIR } from "./skills.js";
10
10
  /** The most the host adds to a run's note as it merges it: `origin: you` and `status: pending`, a front matter line
11
11
  * each (notes.ts mergedNote). */
12
12
  const HOST_LINES = Buffer.byteLength("origin: you\nstatus: pending\n");
@@ -136,10 +136,330 @@ function decodedScanned(path, text, refused, add, deep = true) {
136
136
  }
137
137
  return found;
138
138
  }
139
+ /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
140
+ * provider, never a tier. */
141
+ const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
142
+ const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
143
+ /** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
144
+ * decide's or extract's label. */
145
+ const writeKeyOf = (node) => (node.node === "report" ? "report_markdown" : typeof node.as === "string" && node.as ? node.as : ["agent", "decide", "extract"].includes(node.node) ? node.label : undefined);
146
+ /** An item's whole state, as a map collects it when neither its resultPath nor its body's `as` picks one key: every
147
+ * write in the body is in the answer. */
148
+ const WHOLE = Symbol("whole state");
149
+ /** Why a draft's answer is not written on the agent's own model: each model node that writes the state key its
150
+ * output.path reads (its answering step) and names tier "fast", one line each, in words the compile retry acts on. A
151
+ * composed workflow node that writes it answers with its own workflow's answering step, held to the same; a map that
152
+ * writes it collects each item's result (the DSL's map: its resultPath's key in the item's state, else its body's `as`,
153
+ * else the item's whole state), so the body's step writing that is the answering one. A map body's other writes stay in
154
+ * its item and are never the answer; a loop's body writes the state around it. Legwork on fast and an answer on strong
155
+ * pass. Out of sample (H1), the same answering step on the fast model scored 8.5-9.6 points lower than on the agent's. */
156
+ export function answerTierProblems(doc) {
157
+ const problems = [];
158
+ const answered = (workflow) => {
159
+ const path = workflow?.output?.path;
160
+ if (typeof path !== "string" || !path)
161
+ return;
162
+ const walk = (node, key) => {
163
+ if (!isNode(node))
164
+ return;
165
+ const writes = key === WHOLE || writeKeyOf(node) === key;
166
+ if (node.node === "workflow")
167
+ return void (writes && answered(node.workflow));
168
+ if (node.node === "map") {
169
+ if (!writes)
170
+ return;
171
+ const result = typeof node.resultPath === "string" && node.resultPath ? node.resultPath.split(".")[0] : undefined;
172
+ const bodyAs = isNode(node.body) && typeof node.body.as === "string" && node.body.as ? node.body.as : undefined;
173
+ return walk(node.body, result ?? bodyAs ?? WHOLE);
174
+ }
175
+ if (TIERED_KINDS.has(node.node) && node.tier === "fast" && writes) {
176
+ problems.push(`the ${node.node} step ${JSON.stringify(String(node.label ?? "(no label)").slice(0, 64))} writes the answer (output.path ${JSON.stringify(path.slice(0, 64))}) on tier "fast": the answering node runs on the agent's model: drop its tier`);
177
+ }
178
+ for (const child of childNodes(node))
179
+ walk(child, key);
180
+ };
181
+ walk(workflow?.root, path.split(".")[0]);
182
+ };
183
+ answered(doc);
184
+ return problems;
185
+ }
186
+ /** The property names that make an answer carry quotes. */
187
+ const QUOTE_KEYS = new Set(["quote", "quotes"]);
188
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
189
+ const QUOTE_SITES_MAX = 8;
190
+ function quoteSite(keys) {
191
+ const lists = keys.filter((key) => key === "[]").length;
192
+ if (keys.includes("*") || lists > 1)
193
+ return { keys };
194
+ if (!lists)
195
+ return { keys, read: { path: keys } };
196
+ const at = keys.indexOf("[]");
197
+ const field = keys.slice(at + 1).join(".");
198
+ return { keys, read: field ? { path: keys.slice(0, at), field } : { path: keys.slice(0, at) } };
199
+ }
200
+ /** How deep in an answer's schema quotes are looked for: a schema nesting deeper is refused, never read in part. */
201
+ const QUOTE_SITE_DEPTH = 16;
202
+ /** Every place in `schema` (a draft's output schema, its `#/definitions/<id>` refs read from `schemas`) holding quotes: a
203
+ * `quote` or `quotes` property that is a string, a list of strings, or holds them deeper (`quotes: [{quote}]`). A quote
204
+ * key's value is read shape by shape: each `anyOf`/`oneOf` branch, and each kind a `type` list names (a string, and the
205
+ * list or record beside it), gives its own place, so `quotes: string | [{quote}]` holds quotes at `quotes` and at
206
+ * `quotes[].quote`. `allOf` members describe one value, so they are read together (the types all of them allow, the
207
+ * properties and items any of them names). A shape holding structure where no `quote` key is found (records of other
208
+ * fields) holds quotes no check reads (`*`). `over` when there are more than QUOTE_SITES_MAX places, or the schema
209
+ * nests past QUOTE_SITE_DEPTH keys or recurs (a definition met again below itself) around quotes: the places found are
210
+ * then not all of them, and the rule refuses rather than read a part as the whole. */
211
+ function quoteSitesOf(schema, schemas) {
212
+ const resolve = (node) => {
213
+ for (let hops = 0; hops < 8 && isObject(node) && typeof node.$ref === "string"; hops++) {
214
+ const ref = /^#\/definitions\/(.+)$/.exec(node.$ref)?.[1];
215
+ if (ref === undefined || !Object.hasOwn(schemas, ref))
216
+ break;
217
+ node = schemas[ref];
218
+ }
219
+ return node;
220
+ };
221
+ const sites = [];
222
+ let over = false;
223
+ const add = (keys) => {
224
+ if (sites.some((site) => site.keys.join("\u0000") === keys.join("\u0000")))
225
+ return true;
226
+ if (sites.length < QUOTE_SITES_MAX)
227
+ sites.push(quoteSite(keys));
228
+ else
229
+ over = true;
230
+ return true;
231
+ };
232
+ // The schemas the walk is inside (cycle detection, one per walk, never a value's other allOf parts, so a definition
233
+ // shared by a part and a property is still read at the property), and those of them it met again below themselves.
234
+ const around = new Set();
235
+ const recurring = new Set();
236
+ /** `schema` and its `allOf` members (theirs too, refs resolved): the parts of one value, read together. A member the
237
+ * walk is inside already recurs, read no further. */
238
+ const partsOf = (schema) => {
239
+ const parts = [];
240
+ const take = (node) => {
241
+ const part = resolve(node);
242
+ if (!isObject(part) || parts.includes(part))
243
+ return;
244
+ if (part !== schema && around.has(part))
245
+ return void recurring.add(part);
246
+ parts.push(part);
247
+ if (Array.isArray(part.allOf))
248
+ for (const inner of part.allOf)
249
+ take(inner);
250
+ };
251
+ take(schema);
252
+ return parts;
253
+ };
254
+ /** One schema for the values several parts give one key, list or map: their `allOf`. */
255
+ const together = (values) => (values.length === 1 ? values[0] : { allOf: values });
256
+ /** Walks `node` at `at`; `quoted` when it is a quote key's value (or its items, or a branch of either). Whether it
257
+ * found a place holding quotes. */
258
+ const walk = (node, at, quoted = false) => {
259
+ const schema = resolve(node);
260
+ if (over)
261
+ return false;
262
+ // A quote key's value the schema leaves open (an unresolved ref, `true`) is read as a quote.
263
+ if (!isObject(schema))
264
+ return quoted && add(at);
265
+ if (around.has(schema)) {
266
+ recurring.add(schema);
267
+ return false;
268
+ }
269
+ if (at.length > QUOTE_SITE_DEPTH) {
270
+ over = true;
271
+ return false;
272
+ }
273
+ around.add(schema);
274
+ const parts = partsOf(schema);
275
+ // The types every part allows; the other shapes an anyOf/oneOf branch allows, each read alone.
276
+ const typeLists = parts.flatMap((part) => (typeof part.type === "string" ? [[part.type]] : Array.isArray(part.type) ? [part.type] : []));
277
+ const types = typeLists.length ? typeLists.reduce((all, list) => all.filter((type) => list.includes(type))) : undefined;
278
+ const branches = parts.flatMap((part) => ["anyOf", "oneOf"].flatMap((key) => (Array.isArray(part[key]) ? part[key] : [])));
279
+ const properties = new Map();
280
+ const items = [];
281
+ const extra = [];
282
+ for (const part of parts) {
283
+ if (isObject(part.properties))
284
+ for (const [key, inner] of Object.entries(part.properties))
285
+ properties.set(key, [...(properties.get(key) ?? []), inner]);
286
+ if (part.items !== undefined)
287
+ items.push(part.items);
288
+ if (part.additionalProperties !== undefined)
289
+ extra.push(part.additionalProperties);
290
+ }
291
+ const shaped = properties.size > 0 || items.length > 0 || extra.length > 0;
292
+ // A string here: a type naming it, or no type, branch or shape at all.
293
+ let found = quoted && (types ? types.includes("string") : !branches.length && !shaped) && add(at);
294
+ const structured = !types || types.includes("array") || types.includes("object");
295
+ if (structured) {
296
+ for (const [key, values] of properties)
297
+ found = walk(together(values), [...at, key], QUOTE_KEYS.has(key)) || found;
298
+ const lists = items.filter(isObject);
299
+ if (lists.length)
300
+ found = walk(together(lists), [...at, "[]"], quoted) || found;
301
+ const maps = extra.filter(isObject);
302
+ if (maps.length)
303
+ found = walk(together(maps), [...at, "*"], quoted) || found;
304
+ }
305
+ for (const inner of branches)
306
+ found = walk(inner, at, quoted) || found;
307
+ around.delete(schema);
308
+ // A quote key's list or record holding no `quote` key and no string: its quotes are where no check reads them.
309
+ if (quoted && structured && !found && (shaped || !branches.length))
310
+ found = add([...at, "*"]);
311
+ // A schema met again below itself that holds quotes holds them at ever deeper paths, past any set of checks.
312
+ if (recurring.delete(schema) && found)
313
+ over = true;
314
+ return found;
315
+ };
316
+ walk(schema, []);
317
+ return { sites, over };
318
+ }
319
+ /** Whether a node fetches: a call node, or one with a call under it (a composed workflow's included). */
320
+ function fetches(node, depth = 0) {
321
+ if (!isNode(node) || depth > 16)
322
+ return false;
323
+ if (node.node === "call")
324
+ return true;
325
+ if (node.node === "workflow")
326
+ return fetches(node.workflow?.root, depth + 1);
327
+ return childNodes(node).some((child) => fetches(child, depth + 1));
328
+ }
329
+ /** The nodes writing the state around `root` (its chains, branches and loop bodies; a map's body writes its item's
330
+ * state and a composed workflow node its child's, so neither is walked). */
331
+ function stateWriters(root) {
332
+ const writers = [];
333
+ const walk = (node) => {
334
+ if (!isNode(node))
335
+ return;
336
+ if (typeof writeKeyOf(node) === "string")
337
+ writers.push(node);
338
+ if (node.node !== "map" && node.node !== "workflow")
339
+ for (const child of childNodes(node))
340
+ walk(child);
341
+ };
342
+ walk(root);
343
+ return writers;
344
+ }
345
+ /** Whether `key` in the state around `root` holds a page as fetched, whatever step wrote it last: some step writes it, and
346
+ * every step writing it writes a page (a model step writing a summary back to the key a call wrote spoils it). */
347
+ const holdsPage = (root, key, depth = 0) => {
348
+ const writers = stateWriters(root).filter((writer) => writeKeyOf(writer) === key);
349
+ return writers.length > 0 && writers.every((writer) => writesPage(writer, depth + 1));
350
+ };
351
+ /** Whether what a node writes is a page as fetched: a call's result; a map's when each item's result (its resultPath's
352
+ * key, else its body's `as`) holds a page its body fetched, never when it collects the item's whole state, which carries
353
+ * the state around the map too (an answer written before it included);
354
+ * a composed workflow's when its child's answer does in the child's state. A model step's summary is no page. */
355
+ function writesPage(node, depth = 0) {
356
+ if (depth > 16)
357
+ return false;
358
+ if (node.node === "call")
359
+ return true;
360
+ if (node.node === "map") {
361
+ const result = typeof node.resultPath === "string" && node.resultPath ? node.resultPath.split(".")[0] : undefined;
362
+ const bodyAs = isNode(node.body) && typeof node.body.as === "string" && node.body.as ? node.body.as : undefined;
363
+ const key = result ?? bodyAs;
364
+ return key !== undefined && holdsPage(node.body, key, depth);
365
+ }
366
+ if (node.node === "workflow") {
367
+ const child = isObject(node.workflow) ? node.workflow : {};
368
+ const path = isObject(child.output) && typeof child.output.path === "string" ? child.output.path : "";
369
+ return !!path && holdsPage(child.root, path.split(".")[0], depth);
370
+ }
371
+ return false;
372
+ }
373
+ /** The state keys around `root` holding a page as fetched (holdsPage), in the order their steps come. */
374
+ const pageKeysOf = (root) => [...new Set(stateWriters(root).map((node) => writeKeyOf(node)))].filter((key) => holdsPage(root, key));
375
+ /** Whether `node` writes `key` in the state around it (itself, or a step of its chains, branches or loop bodies). */
376
+ const writesKey = (node, key) => isNode(node) && (writeKeyOf(node) === key || (node.node !== "map" && node.node !== "workflow" && childNodes(node).some((child) => writesKey(child, key))));
377
+ /** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
378
+ * and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
379
+ * reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
380
+ * (a model's summary of a page is no page). A judge or an `ask` is never the quote check:
381
+ * H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
382
+ * quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
383
+ export function quoteCheckProblems(doc) {
384
+ return isObject(doc) ? quoteRule(doc, {}).problems : [];
385
+ }
386
+ const siteKey = (site) => site.keys.join("\u0000");
387
+ /** quoteCheckProblems for one workflow (the draft's, or a composed workflow node's child, its schemas its own else
388
+ * `schemasAround`): whether the rule applies (its answer carries quotes and it fetches pages), and why it fails. Only a
389
+ * run's path through its top-level chain is sure to pass a step: a check is an escalate on quote_missing that is a step
390
+ * of that chain after the last step writing the answer's key (a check in one route branch, or before the answer is
391
+ * written, reads no answer on another path), and each place in the answer holding quotes needs a check reading it
392
+ * (its path and field; a place no one pair reads is refused, as quote_missing reads none of it). Its pages are state keys holding a page as
393
+ * fetched (holdsPage). A composed workflow node writing the whole answer (its `as` the answer's path) whose child
394
+ * passes this rule in its own state has checked the places in the answer its child's schema declares too; the parent
395
+ * still checks any other place its own schema declares. `checked`: the places a passing workflow checked. */
396
+ function quoteRule(workflow, schemasAround, depth = 0) {
397
+ const none = { applies: false, problems: [], checked: [] };
398
+ const output = isObject(workflow.output) ? workflow.output : {};
399
+ const answerPath = typeof output.path === "string" ? output.path : "";
400
+ const schemas = isObject(workflow.schemas) ? workflow.schemas : schemasAround;
401
+ const schemaId = typeof output.schemaId === "string" ? output.schemaId : "";
402
+ if (!answerPath || !Object.hasOwn(schemas, schemaId) || depth > 8)
403
+ return none;
404
+ // Its refs read as the DSL reads them (resolveSchemaForWorkflow): the schema's own inline definitions first, then the catalog.
405
+ const answerSchema = schemas[schemaId];
406
+ const inline = isObject(answerSchema) && isObject(answerSchema.definitions) ? answerSchema.definitions : {};
407
+ const { sites: declared, over } = quoteSitesOf(answerSchema, { ...schemas, ...inline });
408
+ if ((!declared.length && !over) || !fetches(workflow.root))
409
+ return none;
410
+ if (over)
411
+ return { applies: true, checked: [], problems: [`the answer's schema (${schemaId.slice(0, 64)}) holds quotes in more than ${QUOTE_SITES_MAX} places or nests past ${QUOTE_SITE_DEPTH} keys, past what the quote check reads, and the workflow fetches pages: give the answer fewer places holding quotes, each a quote, a list of quotes or a list of records holding one`] };
412
+ const where = (site) => `${schemaId}.${site.keys.join(".").replace(/\.(\[\]|\*)/g, "$1")}`.slice(0, 120);
413
+ const pages = pageKeysOf(workflow.root);
414
+ const steps = isNode(workflow.root) && workflow.root.node === "chain" && Array.isArray(workflow.root.steps) ? workflow.root.steps : [workflow.root];
415
+ const answered = steps.findLastIndex((step) => writesKey(step, answerPath.split(".")[0]));
416
+ const writer = steps[answered];
417
+ const child = isNode(writer) && writer.node === "workflow" && isObject(writer.workflow) ? quoteRule(writer.workflow, schemas, depth + 1) : none;
418
+ const covered = child.applies && !child.problems.length && isNode(writer) && writer.as === answerPath ? child.checked : [];
419
+ const sites = declared.filter((site) => !covered.includes(siteKey(site)));
420
+ const passed = { applies: true, problems: [], checked: declared.map(siteKey) };
421
+ if (!sites.length)
422
+ return passed;
423
+ // A place no one path and field reads (quotes under two lists, in a map, in records with no quote key): quote_missing
424
+ // would read none of its quotes, so no check passes it.
425
+ const problems = sites.filter((site) => !site.read).map((site) => `the answer carries quotes (${where(site)}) in a shape no quote_missing check reads, and the workflow fetches pages: give them one it reads, a quote, a list of quotes or a list of records each holding its quote at one field`);
426
+ const readable = sites.flatMap((site) => (site.read ? [{ site, read: site.read }] : []));
427
+ if (!pages.length) {
428
+ problems.push(...readable.map(({ site }) => `the answer carries quotes (${where(site)}) and the workflow fetches pages, but no state key holds a page as fetched (a model step's summary of one is no page, a map's or a composed workflow's result included): keep the pages its call steps fetch in the state and check the quotes against them in code with a quote_missing escalate, never a judge`));
429
+ }
430
+ else {
431
+ const checks = steps.slice(answered + 1).flatMap((step) => {
432
+ if (!isNode(step) || step.node !== "escalate" || !isObject(step.when) || step.when.predicate !== "quote_missing")
433
+ return [];
434
+ const when = step.when;
435
+ return [{ label: String(step.label ?? "(no label)").slice(0, 64), path: when.path, field: when.field ?? "", pages: Array.isArray(when.pages) ? when.pages : [] }];
436
+ });
437
+ for (const { site, read } of readable) {
438
+ const path = [answerPath, ...read.path].join(".");
439
+ const field = read.field ?? "";
440
+ if (checks.some((check) => check.path === path && check.field === field))
441
+ continue;
442
+ const predicate = `{"predicate": "quote_missing", "path": ${JSON.stringify(path)}${field ? `, "field": ${JSON.stringify(field)}` : ""}, "pages": ${JSON.stringify(pages)}}`;
443
+ problems.push(`the answer carries quotes (${where(site)}) and the workflow fetches pages: check them in code, with an escalate ${predicate} as a step of its top-level chain after the step that writes the answer (pages: the state keys its call steps write), never a judge`);
444
+ }
445
+ for (const { label, pages: read } of checks)
446
+ for (const page of read) {
447
+ const head = typeof page === "string" ? page.split(".")[0] : "";
448
+ if (!pages.includes(head))
449
+ problems.push(`the quote_missing escalate ${JSON.stringify(label)} reads ${JSON.stringify(String(page).slice(0, 64))} as a page, which no call step fetched: its pages are the state keys its call steps write (${pages.join(", ")})`);
450
+ }
451
+ }
452
+ // A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
453
+ if (problems.length && child.problems.length)
454
+ return { applies: true, checked: [], problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
455
+ return problems.length ? { applies: true, problems, checked: [] } : passed;
456
+ }
139
457
  /** What a run may write of a skill or a workflow draft (`place`), by itself: a good folder name, never a deletion, a
140
458
  * regular file within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a skill's
141
459
  * front matter (skillProblems), with no `status`, which is the host's; a draft the DSL validates against `tools` with
142
- * no node that runs code (draftProblems); a README that names its folder and says what the draft is for. */
460
+ * no node that runs code (draftProblems), whose answering step runs on the agent's model (answerTierProblems), whose
461
+ * quotes of the pages it fetched are checked in code (quoteCheckProblems); a README that names its folder and says what
462
+ * the draft is for. */
143
463
  function learnedChecked(change, place, refused, input, add) {
144
464
  const { path } = change;
145
465
  nameScanned(path, refused, add);
@@ -165,7 +485,12 @@ function learnedChecked(change, place, refused, input, add) {
165
485
  if (place.kind === "workflow") {
166
486
  if (!input.dsl)
167
487
  throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
168
- const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.ask, input.decisions);
488
+ const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.decisions, input.workflowAdapters);
489
+ // A draft the DSL reads parses: its answering step is held to the agent's model, and its quote check to code.
490
+ if (!problems.length) {
491
+ const doc = JSON.parse(text);
492
+ problems.push(...[...answerTierProblems(doc), ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
493
+ }
169
494
  for (const { rule, detail } of problems)
170
495
  add(rule, detail, path);
171
496
  // A draft the checks pass whose dry run failed: its wiring breaks at run time, before any node is paid for.
@@ -71,6 +71,8 @@ export interface CompileTrace {
71
71
  * run back (answer-json.ts answerAsServed), so the workflow's final output must be that object. */
72
72
  export type CompileAsk = {
73
73
  readonly reference: string;
74
+ /** Present for a backend-owned SDK bridge, even when it declares no model or judge callback. */
75
+ readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
74
76
  readonly outputSchema?: unknown;
75
77
  readonly notes: readonly {
76
78
  readonly file: string;
@@ -142,6 +144,7 @@ export declare function learnedHost(options: {
142
144
  readonly tools: readonly string[];
143
145
  readonly judges: boolean;
144
146
  readonly jev?: boolean;
147
+ readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
145
148
  }): AuthorHostAddendum;
146
149
  /** The workflow language for the compile turn, generated: the DSL's own author contract (rendered from its vocabulary, so
147
150
  * it names exactly the kinds, fields and predicates its validator admits) with this host's addendum. */
@@ -153,14 +156,15 @@ export declare const compileReference: (dsl: {
153
156
  readonly tools: readonly string[];
154
157
  readonly judges: boolean;
155
158
  readonly jev?: boolean;
159
+ readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
156
160
  }) => string;
157
161
  /** The worked example's input, as a run gives it. */
158
162
  export declare const EXAMPLE_INPUT: {
159
163
  readonly content: "Refund request: order 1043, a $42 kettle that arrived broken, bought 9 days ago.";
160
164
  };
161
165
  /** The worked example: a whole job, input to answer, that the checks and the dry run pass (a test holds it to them).
162
- * An extract step reads the facts, a judge asks one typed question of them (with a decision provider), a decide step
163
- * answers, and an escalate step hands back a case the policy does not cover. With Jev (`jev`) each judgment step is
166
+ * An extract step reads the facts on the fast tier, a judge asks one typed question of them (with a decision provider),
167
+ * a decide step answers on the agent's own model (no tier: answerTierProblems), and an escalate step hands back a case the policy does not cover. With Jev (`jev`) each judgment step is
164
168
  * guarded on its own confidence and Jev's (`both`) and the extract step on Jev's; without, the judgment steps on their
165
169
  * own confidence alone. */
166
170
  export declare function compileExample(judges: boolean, jev?: boolean): Record<string, unknown>;
@@ -215,6 +219,7 @@ export declare function draftErrorsOf(checked: CheckedLike | undefined, name: st
215
219
  * reports none); without Jev, a guard that reads it (it would hand every case back). None when every one is there. */
216
220
  export declare function guardProblems(doc: unknown, options: {
217
221
  readonly jev: boolean;
222
+ readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
218
223
  }): string[];
219
224
  /** The record's workflow when no attempt named one. */
220
225
  export declare const UNNAMED = "(unnamed)";
@@ -232,6 +237,8 @@ export declare function compileTurn<C extends CheckedLike>(input: {
232
237
  readonly check: (answer: string) => Promise<C | undefined>;
233
238
  readonly deadlineMs?: number;
234
239
  readonly now?: () => number;
240
+ /** Already-opened secret values, used only when a stateless SDK retry repeats its own failed answer as data. */
241
+ readonly refuse?: readonly string[];
235
242
  }): Promise<{
236
243
  record?: CompiledRecord;
237
244
  kept?: {
@@ -14,7 +14,8 @@ import { createHash } from "node:crypto";
14
14
  import { childNodes, LEARNED_MAX_TURNS, frontMatter, WORKFLOW_NAME, WORKFLOWS_DIR } from "./skills.js";
15
15
  import { NOTE_BLOCK, parseReflection, SKILL_BLOCK, WORKFLOW_BLOCK } from "./reflect.js";
16
16
  import { NOTE_FILE } from "./notes.js";
17
- import { answersAlone, championOf, PROMOTE_BAR, promotionOf } from "./promote.js";
17
+ import { answersAlone, championOf, LABEL_MAX, PROMOTE_BAR, promotionOf } from "./promote.js";
18
+ import { redactSecrets } from "./secrets.js";
18
19
  /** How many active notes an agent keeps before its look-back compiles its job. */
19
20
  export const COMPILE_AFTER_NOTES = 3;
20
21
  /** How many completed runs an agent has (the ending one counted) before its look-back compiles its job. */
@@ -72,11 +73,31 @@ export const GUARD_THRESHOLD = 0.7;
72
73
  * no confidence (extract, call); without it, the step's own confidence, and no guard where there is none. */
73
74
  const guardOf = (signal) => ({ signal, threshold: GUARD_THRESHOLD });
74
75
  const guardText = (signal) => `\`"guard": {"signal": "${signal}", "threshold": ${GUARD_THRESHOLD}}\``;
76
+ /** The quote check a compiled workflow's answer gets when it quotes fetched pages (check.ts quoteCheckProblems refuses a
77
+ * draft without it): code, never a judge. */
78
+ const QUOTE_CHECK_RULE = "An answer that quotes pages a call step fetched is checked in code: an escalate on `{\"predicate\": \"quote_missing\", \"path\": \"<the answer's quotes, e.g. answer.evidence>\", \"field\": \"quote\", \"pages\": [<the keys the call steps write>]}`, a step of the top-level chain after the step that writes the answer, hands back an answer quoting text no fetched page holds. Its pages are what the calls fetched, never a model's summary of them. Never ask a judge, an `ask` or a guard whether quotes are verbatim.";
75
79
  /** This host's addendum to the DSL's author contract: the node kinds it runs, and its rules, each one the checks hold a
76
80
  * draft to (learn/skills.ts draftProblems; propose.ts). `jev`: the run can call Jev (one of its decision providers,
77
81
  * not denied), so every step is asked for a guard Jev reads. */
78
82
  export function learnedHost(options) {
79
83
  const { tools, judges } = options;
84
+ if (options.workflowAdapters !== undefined) {
85
+ const model = options.workflowAdapters.includes("runNode"), judge = options.workflowAdapters.includes("runJudge");
86
+ return {
87
+ name: "AgentRun backend SDK workflow bridge",
88
+ nodeKinds: ["chain", "call", "escalate", "map", "parallel", "loop", "route", ...(model ? ["extract", "decide", "agent"] : []), ...(judge ? ["judge", "pick", "sift"] : [])],
89
+ rules: [
90
+ "The backend explicitly invokes a saved workflow through its registered MCP bridge. Saving it never automatically runs it on later tasks.",
91
+ tools.length ? `A call node runs via tool alone and names only this allowed callback catalog: ${tools.join(", ")}. Its arguments and output schema must match that callback. Never shell or executor.` : "There is no allowed tool callback: author no call node.",
92
+ model ? "runNode is explicitly registered for tool-free model nodes. It owns model selection; name no model or tier and grant its model nodes no tools." : "This backend provides NO runNode: author no extract, decide or agent node. Never invent a model adapter.",
93
+ judge ? "runJudge is explicitly registered for decision nodes; the backend owns its implementation." : "This backend provides NO runJudge: author no judge, pick, sift, verification or model-based predicate.",
94
+ "There is no guardStep callback: author no step guard, including self, jev or both. Do not assume hosted decision or confidence machinery.",
95
+ `At most 128 static nodes. Never automatically retry a delegated tool call. An agent node uses at most ${LEARNED_MAX_TURNS} max_turns and never context fork.`,
96
+ "The workflow's declared input takes the caller's fields. output.path selects the job's actual answer in its required format; use a declared formatter callback when necessary.",
97
+ QUOTE_CHECK_RULE,
98
+ ],
99
+ };
100
+ }
80
101
  const jev = options.jev === true;
81
102
  const judgment = judges ? "decide, agent, judge, pick and sift" : "decide and agent";
82
103
  return {
@@ -88,13 +109,14 @@ export function learnedHost(options) {
88
109
  : "There is no tool for a call node to run: author no call node.",
89
110
  "A model node (extract, decide, agent) names no `tools`: it runs in a session of its own with none. Fetch with a call node.",
90
111
  `An agent node asks at most ${LEARNED_MAX_TURNS} \`max_turns\`, and never \`context: "fork"\`.`,
91
- "Give each model node `\"tier\": \"fast\"`; a step that needs the agent's own judgment names no tier, and runs on the agent's model.",
112
+ "Give each legwork model node `\"tier\": \"fast\"`. The step that writes the answer (`output.path`) names no tier: it runs on the agent's model.",
92
113
  "`input.schemaId` names a schema whose required fields are the run's own input fields, as a run is given them: then the workflow runs first on later runs, before the agent.",
93
114
  "`output.path` is required: the workflow's answer is the value there, the job's answer in the format the runs answered with.",
94
115
  jev
95
116
  ? `Give every ${judgment} step a guard ${guardText("both")}: its own confidence and one Jev check of its output against its input, read together. The step submits its confidence beside its record, so its output schema has no confidence field${judges ? "; a judge, pick or sift step reads its weakest answer" : ""}. Give every extract and call step a guard ${guardText("jev")}: it reports no confidence of its own, so Jev alone checks it. Each threshold starts at ${GUARD_THRESHOLD}; the host refits it on graded runs.`
96
117
  : `Give every ${judgment} step a guard ${guardText("self")}: the step submits its confidence beside its record, so its output schema has no confidence field${judges ? "; a judge, pick or sift step reads its weakest answer" : ""}. This run cannot call Jev: a guard reads \`self\` alone, never \`jev\` or \`both\`, and an extract or call step takes no guard.`,
97
118
  "An escalate step hands back a case the job's own rules send to a person, on a value a step wrote (`field_equals`, `in`); an unsure step is the guard's to hand back, not an escalate's.",
119
+ QUOTE_CHECK_RULE,
98
120
  ],
99
121
  };
100
122
  }
@@ -104,8 +126,8 @@ export const compileReference = (dsl, options) => dsl.authorContract({ host: lea
104
126
  /** The worked example's input, as a run gives it. */
105
127
  export const EXAMPLE_INPUT = { content: "Refund request: order 1043, a $42 kettle that arrived broken, bought 9 days ago." };
106
128
  /** The worked example: a whole job, input to answer, that the checks and the dry run pass (a test holds it to them).
107
- * An extract step reads the facts, a judge asks one typed question of them (with a decision provider), a decide step
108
- * answers, and an escalate step hands back a case the policy does not cover. With Jev (`jev`) each judgment step is
129
+ * An extract step reads the facts on the fast tier, a judge asks one typed question of them (with a decision provider),
130
+ * a decide step answers on the agent's own model (no tier: answerTierProblems), and an escalate step hands back a case the policy does not cover. With Jev (`jev`) each judgment step is
109
131
  * guarded on its own confidence and Jev's (`both`) and the extract step on Jev's; without, the judgment steps on their
110
132
  * own confidence alone. */
111
133
  export function compileExample(judges, jev = false) {
@@ -120,7 +142,7 @@ export function compileExample(judges, jev = false) {
120
142
  const steps = [
121
143
  { node: "extract", label: "facts", instructions: "Read the request: the item, its price in dollars, how many days ago it was bought, and whether it arrived damaged. Null for what it does not say.", state: { content: "{content}" }, out: "Facts", as: "facts", tier: "fast", ...facts },
122
144
  ...(judges ? [{ node: "judge", label: "policy", state: { facts: "{facts}" }, out: "Policy", as: "policy", guard }] : []),
123
- { node: "decide", label: "answer", instructions: "Decide refund, replace or decline by the refund policy, and write the reply to the customer. A request the policy does not cover is needs_review.", state: judges ? { facts: "{facts}", policy: "{policy}" } : { facts: "{facts}" }, out: "Answer", as: "answer", tier: "fast", guard },
145
+ { node: "decide", label: "answer", instructions: "Decide refund, replace or decline by the refund policy, and write the reply to the customer. A request the policy does not cover is needs_review.", state: judges ? { facts: "{facts}", policy: "{policy}" } : { facts: "{facts}" }, out: "Answer", as: "answer", guard },
124
146
  { node: "escalate", label: "review", when: { predicate: "field_equals", path: "answer.decision", value: "needs_review" }, kind: "needs_review", stage: "answer", summary: "The policy does not cover this request: {answer.reply}" },
125
147
  ];
126
148
  return { v: 2, name: "refund-request", schemas, input: { schemaId: "Request" }, output: { schemaId: "Answer", path: "answer" }, root: { node: "chain", steps } };
@@ -136,6 +158,13 @@ const exampleBlock = (judges, jev) => [
136
158
  JSON.stringify(compileExample(judges, jev)),
137
159
  "````",
138
160
  ].join("\n");
161
+ /** SDK syntax example: a delegated effect, with no implicit model or guard callback. Catalog schemas remain authoritative. */
162
+ const sdkExampleBlock = (tool) => [
163
+ `\`\`\`\`${WORKFLOW_BLOCK} read-value`, "---", "description: Read a value through the declared backend callback when requested.",
164
+ 'example: {"key":"example"}', "---",
165
+ JSON.stringify({ v: 2, name: "read-value", schemas: { Input: { type: "object", properties: { key: { type: "string" } }, required: ["key"] }, Value: { type: "object", properties: { value: { type: "string" } }, required: ["value"] } }, input: { schemaId: "Input" }, output: { schemaId: "Value", path: "result" }, root: { node: "call", label: "read", via: "tool", tool, args: { key: "{key}" }, out: "Value", as: "result", deadline_s: 30 } }),
166
+ "````",
167
+ ].join("\n");
139
168
  /** Control and format characters, made spaces in what the host fences. */
140
169
  const UNSEEN = /[\p{Cc}\p{Cf}]/gu;
141
170
  const clean = (text, max) => {
@@ -174,8 +203,6 @@ const COMPILE_OPENS = {
174
203
  export const askedForCompile = (text) => typeof text !== "string" ? false : text.startsWith(`${COMPILE_OPENS.again} (attempt `) ? "again" : text.startsWith(COMPILE_OPENS.new) || text.startsWith(`${COMPILE_OPENS.revise} \``);
175
204
  /** What a compiled workflow gives (#2412): the job's answer as the runs gave it, never a summary of it. */
176
205
  export const OUTPUT_FORMAT = "Its output is the job's answer in the output format your runs gave it, and your skill's when one gives a format: its last node writes it, and `output` names that node's state.";
177
- /** The most characters of a wrong graded answer, and of its grade's words, the revise ask shows. */
178
- const GRADED_MAX = 4_000;
179
206
  /** What the compile turn is told of the agent's output schema, shown whole after it. */
180
207
  export const SHAPE_LINE = "The workflow's final output must be this object: this agent's output schema. A run it serves answers with its output shaped to it, and an output that can't be (one field where it asks for more) hands every run back. Make the schema its `output` names this one, every field, and have its last node write the whole object: the host's dry run holds its answer to it.";
181
208
  /** The compile turn's message. */
@@ -184,11 +211,12 @@ export function compilePrompt(ask) {
184
211
  throw new Error("the workflow asked to be revised must be a workflow's name");
185
212
  const fields = fieldsOf(ask.input);
186
213
  const notes = ask.notes.map(({ file, text }) => `${file}:\n${text.trim()}`).join("\n\n");
214
+ const sdk = ask.workflowAdapters !== undefined;
187
215
  const why = ask.mode === "new"
188
216
  ? [
189
217
  COMPILE_OPENS.new,
190
218
  "This agent has done this job enough times to write it down. Compile the whole job, from the run's input to its answer, into one workflow:",
191
- "on later runs it runs first, before you, and answers alone, or ends on an escalate node and hands the case back to you with what it found.",
219
+ sdk ? "The backend explicitly invokes it through its registered MCP bridge when appropriate. It is never automatically run before later tasks." : "on later runs it runs first, before you, and answers alone, or ends on an escalate node and hands the case back to you with what it found.",
192
220
  "Do the steps the runs below took, the way they took them, keeping every rule your notes give. Name it for the job.",
193
221
  OUTPUT_FORMAT,
194
222
  ]
@@ -205,9 +233,9 @@ export function compilePrompt(ask) {
205
233
  : `Your learned workflow \`${ask.workflow}\` needs a revision.`,
206
234
  ...(ask.graded
207
235
  ? [
208
- ...fenced("its answer", clean(ask.graded.answer, GRADED_MAX)),
236
+ ...fenced("its answer", clean(ask.graded.answer, LABEL_MAX)),
209
237
  "What the reviewer said:",
210
- ...fenced("the grade", clean(ask.graded.words, GRADED_MAX)),
238
+ ...fenced("the grade", clean(ask.graded.words, LABEL_MAX)),
211
239
  `Give \`${ask.workflow}\` again whole under its name, changed so it answers cases like this one right or hands them back to you at an \`escalate\` node, keeping what it already answers right.`,
212
240
  "If no change to it would, answer `No change.` and nothing else.",
213
241
  ]
@@ -230,13 +258,13 @@ export function compilePrompt(ask) {
230
258
  ...(ask.outputSchema !== undefined ? [SHAPE_LINE, "", "```json", JSON.stringify(ask.outputSchema, null, 2), "```", ""] : []),
231
259
  "## A worked example",
232
260
  "",
233
- "A whole job: the facts read, " + (ask.judges ? "a typed question asked of them, " : "") + `the answer decided, ${ask.jev ? "each step under a guard Jev reads" : "each judgment under a guard"} that hands back an unsure step, and a case the policy does not cover handed back.`,
261
+ sdk ? "Syntax only: a delegated tool call, without an implicit model or confidence guard. Replace its arguments and schemas with the actual catalog's and the job's output format; this example grants no capability." : "A whole job: the facts read, " + (ask.judges ? "a typed question asked of them, " : "") + `the answer decided, ${ask.jev ? "each step under a guard Jev reads" : "each judgment under a guard"} that hands back an unsure step, and a case the policy does not cover handed back.`,
234
262
  "",
235
- exampleBlock(ask.judges, ask.jev === true),
263
+ sdk ? (ask.tools.length ? sdkExampleBlock(ask.tools[0]) : "There is no tool callback to illustrate. Use only the callbacks the backend explicitly registered; if they cannot express this job, keep notes and skills and no workflow.") : exampleBlock(ask.judges, ask.jev === true),
236
264
  "",
237
265
  "## This job",
238
266
  "",
239
- fields ? `This run's input has these fields: ${fields}. The workflow's input schema requires them, by these names.` : "This run's input is the message it was given.",
267
+ fields ? (sdk ? `This task was given these fields: ${fields}. Declare the input the backend must explicitly supply to the bridge; it is never automatically mapped from later tasks.` : `This run's input has these fields: ${fields}. The workflow's input schema requires them, by these names.`) : "This run's input is the message it was given.",
240
268
  ask.tools.length ? `A call node may run only these tools: ${ask.tools.join(", ")}.` : "There is no tool for a call node to run.",
241
269
  ...describedLines(ask.described ?? [], ask.tools),
242
270
  ...(ask.mode === "revise" && ask.current ? ["", `\`${ask.workflow}\` as it is now:`, ...fenced("its workflow.json", clean(ask.current, 32_000))] : []),
@@ -374,6 +402,8 @@ function nodesOf(value, out = []) {
374
402
  * judgment step with no guard; with Jev, an extract or call step with none, or one reading its own confidence (it
375
403
  * reports none); without Jev, a guard that reads it (it would hand every case back). None when every one is there. */
376
404
  export function guardProblems(doc, options) {
405
+ if (options.workflowAdapters !== undefined)
406
+ return nodesOf(doc?.root).filter(node => node.guard !== undefined).map(() => "the SDK bridge has no guardStep callback: omit step guards");
377
407
  const own = options.jev ? "both" : "self";
378
408
  const problems = [];
379
409
  for (const node of nodesOf(doc?.root)) {
@@ -409,7 +439,7 @@ function draftGuardErrorsOf(checked, name, ask) {
409
439
  catch {
410
440
  return ["guard: its workflow.json as the checks kept it could not be read for its guards"];
411
441
  }
412
- return guardProblems(doc, { jev: ask.jev === true }).slice(0, ERRORS_MAX).map((problem) => `guard: ${problem}`.slice(0, ERROR_MAX));
442
+ return guardProblems(doc, { jev: ask.jev === true, ...(ask.workflowAdapters !== undefined ? { workflowAdapters: ask.workflowAdapters } : {}) }).slice(0, ERRORS_MAX).map((problem) => `guard: ${problem}`.slice(0, ERROR_MAX));
413
443
  }
414
444
  /** The record's workflow when no attempt named one. */
415
445
  export const UNNAMED = "(unnamed)";
@@ -429,7 +459,8 @@ export async function compileTurn(input) {
429
459
  return { record: { workflow: name || UNNAMED, from_notes: [], attempts: [{ ok: false, errors }] }, draftErrors: errors };
430
460
  }
431
461
  let fromNotes = [];
432
- let prompt = compilePrompt(input.compile);
462
+ const firstPrompt = compilePrompt(input.compile);
463
+ let prompt = firstPrompt;
433
464
  for (let attempt = 1; attempt <= 1 + COMPILE_RETRIES; attempt++) {
434
465
  const left = deadline - now();
435
466
  const said = left > 0 ? await input.ask(prompt, attempt, left).catch(() => undefined) : undefined;
@@ -461,7 +492,12 @@ export async function compileTurn(input) {
461
492
  }
462
493
  }
463
494
  attempts.push({ ok: false, errors });
464
- prompt = compileAgain(errors, attempt + 1);
495
+ const again = compileAgain(errors, attempt + 1);
496
+ // Native/managed sessions retain the earlier turn. SDK booked requests are independent: every retry must carry
497
+ // the same bounded contract/catalog/notes and only its immediately preceding, redacted failed answer as data.
498
+ prompt = input.compile.workflowAdapters !== undefined
499
+ ? [again, firstPrompt, ...fenced("the previous compile answer", clean(redactSecrets(said.answer, input.refuse ?? [], Number.POSITIVE_INFINITY), 32_000))].join("\n\n")
500
+ : again;
465
501
  }
466
502
  if (!attempts.length)
467
503
  return { draftErrors: [] };
@@ -14,6 +14,9 @@ export type GradeInput = {
14
14
  /** The agent's standing instructions, as the host keeps them: the prompt holds their first GRADE_CAPS.instructions
15
15
  * characters. */
16
16
  readonly instructions?: string;
17
+ /** Native source policy must be supplied whole. A fixed larger bound accommodates layered project configuration;
18
+ * it does not change the managed instruction cap or the overall grader prompt bound. */
19
+ readonly nativeInstructions?: true;
17
20
  /** Every active note on main, as the index lists it: the prompt holds each one's index line, cut to
18
21
  * GRADE_CAPS.indexLine. */
19
22
  readonly active: readonly IndexEntry[];
@@ -61,6 +64,7 @@ export declare const GRADE_CAPS: Readonly<{
61
64
  askedTail: 300;
62
65
  askedTotal: 40000;
63
66
  }>;
67
+ export declare const NATIVE_GRADE_INSTRUCTION_BYTES = 65536;
64
68
  /** The grader's judgment of one new note: `keep` (true for a pending one too), `pending` when it waits for the user's
65
69
  * OK (a risky note, whoever's idea it was), and
66
70
  * `origin`, `you` for what the user asked in their own words, else `run`. `question` is the rubric's question it