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

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
@@ -6,7 +6,7 @@
6
6
  import { createHash } from "node:crypto";
7
7
  import { CAPS } from "./check.js";
8
8
  import { INDEX_FILE, INDEX_LINES } from "./notes.js";
9
- import { LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
9
+ import { draftDecisionProviders, LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
10
10
  /** Control and invisible characters: none may reach the prompt through a value the host puts in it. */
11
11
  const UNSEEN = /[\p{Cc}\p{Cf}]/u;
12
12
  /** The info word that opens a note's block in the answer: ```note <file>. */
@@ -22,6 +22,9 @@ export const DRAFT_AFTER_RUNS = 3;
22
22
  * LEARNED_MCP_TOOL). */
23
23
  const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
24
24
  const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
25
+ /** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
26
+ * follow-up opened it again from, so only what came since is new. */
27
+ export const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
25
28
  /** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
26
29
  * where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
27
30
  * is how many notes are active in it, so how many lines the index has left. `tools`, the tools a workflow draft's
@@ -32,9 +35,13 @@ const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
32
35
  * summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
33
36
  * spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
34
37
  * for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
35
- * workflow draft, and asks for none (`draftFor` and `described` are not said). */
38
+ * workflow draft, and asks for none (`draftFor` and `described` are not said). `decisions`, the run's decision providers
39
+ * (skills.ts DraftDecisions, the one the draft check reads): with a provider it has (draftDecisionProviders), a draft may
40
+ * use judge, pick and sift nodes; without, the prompt bans them as it always did. `later`, a later round's (a follow-up
41
+ * opened the run again after it looked back): the prompt says so (LATER_LOOK) after its first line. */
36
42
  export function reflectPrompt(options) {
37
- const { dir, active, tools = [], draftFor = [], described = [], workflows = true } = options;
43
+ const { dir, active, tools = [], draftFor = [], described = [], workflows = true, decisions, later = false } = options;
44
+ const judges = draftDecisionProviders(decisions).length > 0;
38
45
  if (typeof dir !== "string" || dir === "" || dir.startsWith("/") || UNSEEN.test(dir))
39
46
  throw new Error("the directory must be a path relative to the run's workspace, with no control or unseen characters");
40
47
  if (!Number.isSafeInteger(active) || active < 0)
@@ -47,6 +54,7 @@ export function reflectPrompt(options) {
47
54
  return [
48
55
  "The task is done. Before the run ends, say what this run taught you that will help in later runs, if anything.",
49
56
  "",
57
+ ...(later ? [LATER_LOOK, ""] : []),
50
58
  "Look back over the whole conversation: what the user asked, anything they asked you to remember (even if you said you",
51
59
  "saved it), what you tried, and what worked. Only what you answer now is kept: files you wrote during the task are not.",
52
60
  "Use no tool in this turn.",
@@ -124,7 +132,9 @@ export function reflectPrompt(options) {
124
132
  "",
125
133
  ...(workflows ? [
126
134
  "A workflow draft does the job as one workflow DSL document: front matter with one line that says what it does and",
127
- "when to use it, then the JSON. It uses model and tool-call nodes only: no judge, pick or sift node, no code node, no shell or",
135
+ "when to use it, then the JSON. " + (judges
136
+ ? "It uses model and tool-call nodes, and may use judge (answers a question about a value), pick (chooses one of several options) and sift (keeps the items that pass a test) nodes, which run on this run's decision provider under its cap and tool policy; no code node, no shell or"
137
+ : "It uses model and tool-call nodes only: no judge, pick or sift node, no code node, no shell or"),
128
138
  `executor call. Its model nodes name no tool. ${tools.length ? `Its call nodes may run only these tools: ${tools.join(", ")}.` : "It has no call node on a tool."} At most ${CAPS.file} bytes of JSON.`,
129
139
  "To change a draft you were given, give it again whole under its name.",
130
140
  "Its schemas are declared once under `schemas`, and `input` and `output` name one each by `schemaId`, never a schema",
@@ -193,9 +193,36 @@ export declare const MODEL_NODE_TOOLS = "a learned workflow's model node runs wi
193
193
  /** What a learned draft whose output names no path is refused with. */
194
194
  export declare const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
195
195
  /** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
196
- * runNode and runEffect alone): a judge, pick or sift node, a route by question, a verify or an ask needs a decision
197
- * provider (runJudge) a run is not given. Refused at learn time and before a call runs any node, never after. */
198
- export declare const LEARNED_NODES = "a learned workflow runs model and tool-call nodes";
196
+ * runNode, runEffect, and runJudge only when the run has decision providers): a judge, pick or sift node, a route by
197
+ * question, a verify or an ask on a run with none. Refused at learn time and before a call runs any node, never after. */
198
+ export declare const LEARNED_NODES = "a learned workflow runs model and tool-call nodes, and decision nodes on a run with decision providers";
199
+ /** A learned draft's decisions as its check reads them (LS-07): the decision providers the run has (by id, the DSL's
200
+ * DecisionProvider each, decisions.ts decisionProvidersIn over its keys) and the one a node that names none is asked
201
+ * of; `gated`, the provider ids the run's gate does not allow (by its setting, the provider's bare id as its settings
202
+ * key: tool-plane.ts DECISION_PROVIDER_KEYS), of which deny alone refuses, and `deniedBy`, where each deny was set. With none, a decision node
203
+ * is refused (LEARNED_NODES). */
204
+ export type DraftDecisions = {
205
+ readonly providers: Readonly<Record<string, unknown>>;
206
+ readonly default: string;
207
+ readonly gated?: Readonly<Record<string, string>>;
208
+ readonly deniedBy?: Readonly<Record<string, SettingFrom>>;
209
+ };
210
+ /** The providers a draft's decision node may name on this run, by id, as the check reads them (unrunnableNodes: the run's
211
+ * providers; gatedDecisions: deny alone refuses one). None when the run has no `decisions`, so a decision node is
212
+ * refused (LEARNED_NODES): the one place the rule is read, for the check and for what the reflect prompt allows. */
213
+ export declare const draftDecisionProviders: (decisions: DraftDecisions | undefined) => string[];
214
+ /** Each decision a draft asks, by the node that asks it (the DSL's inspection lists each node and its pointer, a composed
215
+ * workflow's inner ones too): its kind, its pointer and its provider's id, the one it names or else `fallback`, the
216
+ * run's default. A judge, pick or sift node; a route by question (not by value); a loop's or an escalate's ask
217
+ * predicate; a model node's verify (asked of the default). */
218
+ export declare function decisionsAsked(dsl: Pick<DraftReader, "inspectWorkflow">, doc: unknown, fallback: string): {
219
+ kind: string;
220
+ path: string;
221
+ provider: string;
222
+ }[];
223
+ /** What a decision node asking `provider` is refused with when the run's gate denies it, worded as a call node's tool is
224
+ * (gatedNodes), with the node's place. */
225
+ export declare const deniedDecisionWords: (provider: string, from: SettingFrom | undefined, kind: string, path: string) => string;
199
226
  /** Where a deny was set (tool-gate.ts SettingFrom), and its words (tool-gate.ts denyPlace), kept here so the learn
200
227
  * module needs no import of the gate. */
201
228
  type SettingFrom = "agent" | "server" | "default";
@@ -236,7 +263,8 @@ export declare const LEARNED_MAX_TURNS = 8;
236
263
  * `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
237
264
  * and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
238
265
  * apply_patch) is never on the list. A model node that names any tool is refused (MODEL_NODE_TOOLS), and a node the
239
- * learned runner cannot run (LEARNED_NODES: a judge's). With no list it
266
+ * learned runner cannot run (LEARNED_NODES: a judge's on a run with no `decisions`; with them, one whose provider the run
267
+ * lacks or its gate holds to ask or deny). With no list it
240
268
  * fails closed: a draft the DSL refuses only once given an empty list names a tool. */
241
269
  /** The MCP tools set to ask a learned call would ask its approver about (`asked`, learnedDraftTools), and whether a card
242
270
  * names them all (`fits`: learned-workflow.ts learnedAskFits, the gate's own rule, handed in so it is never copied). */
@@ -244,5 +272,5 @@ export type DraftAsk = {
244
272
  readonly asked: readonly string[];
245
273
  readonly fits: (asks: readonly string[]) => boolean;
246
274
  };
247
- export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, ask?: DraftAsk): DraftProblem[];
275
+ export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, ask?: DraftAsk, decisions?: DraftDecisions): DraftProblem[];
248
276
  export {};
@@ -685,9 +685,52 @@ const toolingNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node)
685
685
  /** What a learned draft whose output names no path is refused with. */
686
686
  export const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
687
687
  /** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
688
- * runNode and runEffect alone): a judge, pick or sift node, a route by question, a verify or an ask needs a decision
689
- * provider (runJudge) a run is not given. Refused at learn time and before a call runs any node, never after. */
690
- export const LEARNED_NODES = "a learned workflow runs model and tool-call nodes";
688
+ * runNode, runEffect, and runJudge only when the run has decision providers): a judge, pick or sift node, a route by
689
+ * question, a verify or an ask on a run with none. Refused at learn time and before a call runs any node, never after. */
690
+ export const LEARNED_NODES = "a learned workflow runs model and tool-call nodes, and decision nodes on a run with decision providers";
691
+ /** The providers a draft's decision node may name on this run, by id, as the check reads them (unrunnableNodes: the run's
692
+ * providers; gatedDecisions: deny alone refuses one). None when the run has no `decisions`, so a decision node is
693
+ * refused (LEARNED_NODES): the one place the rule is read, for the check and for what the reflect prompt allows. */
694
+ export const draftDecisionProviders = (decisions) => decisions ? Object.keys(decisions.providers).filter((id) => !Object.hasOwn(decisions.gated ?? {}, id) || decisions.gated[id] !== "deny") : [];
695
+ /** Each decision a draft asks, by the node that asks it (the DSL's inspection lists each node and its pointer, a composed
696
+ * workflow's inner ones too): its kind, its pointer and its provider's id, the one it names or else `fallback`, the
697
+ * run's default. A judge, pick or sift node; a route by question (not by value); a loop's or an escalate's ask
698
+ * predicate; a model node's verify (asked of the default). */
699
+ export function decisionsAsked(dsl, doc, fallback) {
700
+ return dsl.inspectWorkflow(doc).nodes.flatMap((node) => {
701
+ const fields = at(doc, node.path) ?? {};
702
+ const named = (choice) => {
703
+ const provider = choice?.provider;
704
+ return typeof provider === "string" ? provider : fallback;
705
+ };
706
+ const asked = (choice) => [{ kind: node.kind, path: node.path, provider: named(choice) }];
707
+ if (node.kind === "judge" || node.kind === "pick" || node.kind === "sift")
708
+ return asked(fields);
709
+ if (node.kind === "route" && typeof fields.valuePath !== "string")
710
+ return asked(fields);
711
+ if (node.kind === "loop" && fields.until?.predicate === "ask")
712
+ return asked(fields.until);
713
+ if (node.kind === "escalate" && fields.when?.predicate === "ask")
714
+ return asked(fields.when);
715
+ if (fields.verify && typeof fields.verify === "object")
716
+ return [{ kind: node.kind, path: node.path, provider: fallback }];
717
+ return [];
718
+ });
719
+ }
720
+ /** What a decision node asking `provider` is refused with when the run's gate denies it, worded as a call node's tool is
721
+ * (gatedNodes), with the node's place. */
722
+ export const deniedDecisionWords = (provider, from, kind, path) => `This workflow's decision node asks ${provider}, which is set to deny ${denyPlace(from)}. (the ${kind} node at ${path})`;
723
+ /** A draft's decision nodes whose provider the run's gate denies (`decisions.gated`): deny alone refuses, as the runner
724
+ * hands a claim a provider's keys while its gate's policy is not deny (a provider is a settings key that is allow or
725
+ * deny; a gate that reads no setting of it answers ask, which refuses nothing here). */
726
+ const gatedDecisions = (dsl, doc, decisions) => {
727
+ if (!decisions?.gated)
728
+ return [];
729
+ return decisionsAsked(dsl, doc, decisions.default).flatMap(({ kind, path, provider }) => {
730
+ const setting = Object.hasOwn(decisions.gated, provider) ? decisions.gated[provider] : undefined;
731
+ return setting === "deny" ? [{ rule: "workflow", detail: deniedDecisionWords(provider, decisions.deniedBy?.[provider], kind, path) }] : [];
732
+ });
733
+ };
691
734
  const denyPlace = (from = "server") => (from === "agent" ? "for this agent" : from === "default" ? "by default" : "on this server");
692
735
  /** A draft's call nodes that call a tool in `gated` (by name, what the gate holds it to: ask or deny), a composed
693
736
  * workflow node's inner ones too (the DSL's inspection lists them, by their pointer under it): the run would park on it
@@ -813,9 +856,12 @@ const longNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node) =>
813
856
  });
814
857
  /** The node the learned runner cannot run, as the DSL's own check says it (assertWorkflowCapabilities, which runWorkflow
815
858
  * makes before any node runs) with the runner's deps: none when it can run every one. */
816
- const unrunnableNodes = (dsl, doc) => {
859
+ const unrunnableNodes = (dsl, doc, decisions) => {
817
860
  const workflow = dsl.desugarWorkflow(doc);
818
- const runner = { runNode: async () => ({}), runEffect: async () => ({}) };
861
+ // With the run's decision providers, a decision node is runnable when its provider is one of them and answers what it
862
+ // asks (the DSL's checkDecisionProviders): the same registry the call's judge is built on.
863
+ const judging = decisions ? { runJudge: async () => ({}), decisionProviders: { providers: decisions.providers, default: decisions.default } } : {};
864
+ const runner = { runNode: async () => ({}), runEffect: async () => ({}), ...judging };
819
865
  try {
820
866
  dsl.assertWorkflowCapabilities(workflow.root, runner, workflow);
821
867
  return [];
@@ -828,7 +874,7 @@ const issuesOf = (dsl, doc, tools) => {
828
874
  const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
829
875
  return valid.ok ? [] : valid.issues;
830
876
  };
831
- export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask) {
877
+ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask, decisions) {
832
878
  let doc;
833
879
  try {
834
880
  doc = JSON.parse(text);
@@ -844,7 +890,7 @@ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask)
844
890
  return issues.slice(0, 5).map((issue) => ({ rule: "workflow", detail: `the workflow DSL refuses it: ${issue.code} at ${issue.path || "/"}: ${issue.message.slice(0, 200)}` }));
845
891
  let out;
846
892
  try {
847
- out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
893
+ out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc, decisions), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...gatedDecisions(dsl, doc, decisions), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
848
894
  // A learned workflow answers the value at its output's path: one that names none would answer its whole state, which
849
895
  // fails its output schema when the call ends, after every node spent.
850
896
  const path = doc?.output?.path;
@@ -6,6 +6,11 @@ import { type Ledger } from "./paid-calls.js";
6
6
  import type { Plane } from "./tool-plane.js";
7
7
  import { type SettingFrom } from "./tool-gate.js";
8
8
  import type { Complete } from "./llm.js";
9
+ import type { SearchOn } from "./web-search.js";
10
+ import type { Workspace } from "./workspace/workspace.js";
11
+ import type { DecisionProvider } from "@parcha/agentrun-dsl";
12
+ import type { Refusal } from "@parcha/agentrun-kernel";
13
+ import type { RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
9
14
  /** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
10
15
  export declare const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
11
16
  /** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
@@ -61,6 +66,9 @@ export type LearnedWorkflowRun = {
61
66
  modelName?(tier: string | undefined): string | undefined;
62
67
  /** The `llm` tool's completion, for a call node that names it. */
63
68
  complete?: Complete;
69
+ /** The run's models a call node's native web_search goes through (EffectRun.search): on the runner, the session's
70
+ * port. */
71
+ search?: SearchOn;
64
72
  /** The run's gate's permission of a tool now (tool-gate.ts RunGate policy): a call node's tool set to ask or deny is
65
73
  * refused before any node runs, and asked again as each call node runs, a composed workflow's inner ones too, so one
66
74
  * set to either since the call began is refused there, never run. Required: a learned workflow never runs a tool
@@ -73,6 +81,22 @@ export type LearnedWorkflowRun = {
73
81
  * each call node runs, before `policy` is asked: a tool set to deny since the call began is then refused. None: the
74
82
  * gate reads its settings live (main's process). */
75
83
  refresh?: () => Promise<void>;
84
+ /** The run's own Workspace (on the runner: its local folder in Mode 1, its folder on the run's disk in Mode 2), which
85
+ * a decision node's images are read through. Absent: the local folder at `work`. */
86
+ workspace?: Workspace;
87
+ /** The run's decisions (LS-07): its decision providers (decisions.ts decisionProvidersIn over the run's keys) and the
88
+ * one a node that names none is asked of; `book`, the run's decisions on its one cap (the adapter loop's
89
+ * ledger.decisions: DECISION_SESSION); `pause`, the run's pause on a refusal of that cap (ledger.pause), so its next
90
+ * request is refused in the cap's words and the run parks there. None: a decision node is refused before any node
91
+ * runs. */
92
+ decisions?: {
93
+ readonly providers: {
94
+ readonly providers: Readonly<Record<string, DecisionProvider>>;
95
+ readonly default: string;
96
+ };
97
+ readonly book: RunDecisions;
98
+ readonly pause?: (refusal: Refusal) => Promise<void>;
99
+ };
76
100
  /** The run's MCP tools by catalog name (`mcp:<server>/<tool>`): those the claim's pin holds, which its revision grants.
77
101
  * A call node may name one of these; it runs through the run's own MCP, as the loop wrapped it (host-calls.ts). */
78
102
  mcpTools?: readonly string[];
@@ -12,6 +12,13 @@
12
12
  // its paid requests booked under the tool's call (paid-calls.ts), each node's under a call of its own; web_search
13
13
  // where it resolves native on the provider's hosted search through the run's models (hosted-search.ts), on a harness
14
14
  // whose own search it is too (harness-app.ts gives that harness no host tool of the name).
15
+ // - a decision node (judge, pick, sift, a route by question, an ask predicate, a verify: LS-07), on a run handed its
16
+ // decisions (`run.decisions`: its decision providers on its own keys, and the adapter loop's ledger.decisions on
17
+ // the run's one cap), asked of the provider it names, else the run's default, held to the run's gate under that
18
+ // provider's bare id (tool-plane.ts DECISION_PROVIDER_KEYS: allow or deny), refused only on deny; each admitted on the run's cap before it is sent, priced as a
19
+ // workflow agent's decision is (runner/workflow-spec.ts decisionJudge), settled at what it charged, and one the cap
20
+ // has no room for never sent, the run paused on the cap's refusal (ledger.pause). A run handed none runs no
21
+ // decision node: the check refuses it before any node runs.
15
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:
16
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
17
24
  // `learned_workflow`); on another harness the session's model proxy, under a side key (port-models.ts): the harness's
@@ -23,6 +30,8 @@ import { registerLabel, registerOutcome } from "./timeline/index.js";
23
30
  import { sideRequests } from "./cap.js";
24
31
  import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
25
32
  import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
33
+ import { decisionsAsked, deniedDecisionWords } from "./learn/skills.js";
34
+ import { DEFAULT_DECISION_PROVIDER } from "./decisions.js";
26
35
  import { workflowLine } from "./learning.js";
27
36
  import { ledgerOf } from "./paid-calls.js";
28
37
  import { PORT_PROVIDER } from "./port-models.js";
@@ -259,10 +268,11 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
259
268
  deniedBy[name] = run.denyFrom(name);
260
269
  }
261
270
  }
262
- const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy);
271
+ const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy, undefined, decisionsOf(run, dsl, flow.workflow));
263
272
  if (problems.length)
264
273
  return refuse(problems.map(({ detail }) => detail).join("; "));
265
274
  const doc = JSON.parse(flow.workflow);
275
+ const runJudge = run.decisions ? await learnedJudge(run, run.decisions) : undefined;
266
276
  // The host runner loads @earendil-works/pi-coding-agent and pi-agent-core, serve's own dependencies (package.json).
267
277
  const { createPiHostRunner } = await import("./workflow/host-session.js");
268
278
  const runners = new Map();
@@ -337,7 +347,7 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
337
347
  throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
338
348
  // 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.
339
349
  const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
340
- return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
350
+ return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...(run.search ? { search: run.search } : {}), ...booked });
341
351
  };
342
352
  // Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
343
353
  const onEvent = (event) => {
@@ -348,7 +358,8 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
348
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 });
349
359
  };
350
360
  try {
351
- const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...(signal ? { signal } : {}) });
361
+ 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 } : {}) });
352
363
  if (result.status !== "complete")
353
364
  return refuse(`it ended ${result.status}`);
354
365
  return { text: learnedText(learnedOutput(result.output)), isError: false, nodes };
@@ -359,3 +370,55 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
359
370
  return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true, nodes };
360
371
  }
361
372
  }
373
+ /** The draft check's decisions for `run` (learn/skills.ts DraftDecisions): its providers, and the gate's setting of each
374
+ * provider `text` asks (its bare id as the settings key) where it is not allow, with where a deny was set. A run handed
375
+ * no decisions (its claim was handed no key: none named, or each denied) has no provider, so a decision node is refused
376
+ * in the gate's words when its provider is denied, else as one the host does not have; never asked. */
377
+ function decisionsOf(run, dsl, text) {
378
+ const providers = run.decisions?.providers ?? { providers: {}, default: DEFAULT_DECISION_PROVIDER };
379
+ const gated = {};
380
+ // A deny comes from a layer or the default, never from approvals (learnedDraftTools' rule).
381
+ const deniedBy = {};
382
+ let doc;
383
+ try {
384
+ doc = JSON.parse(text);
385
+ }
386
+ catch {
387
+ return { providers: providers.providers, default: providers.default };
388
+ }
389
+ for (const { provider } of decisionsAsked(dsl, doc, providers.default)) {
390
+ const setting = run.policy(provider);
391
+ if (setting === "allow")
392
+ continue;
393
+ gated[provider] = setting;
394
+ if (setting === "deny")
395
+ deniedBy[provider] = run.denyFrom(provider);
396
+ }
397
+ return { providers: providers.providers, default: providers.default, gated, deniedBy };
398
+ }
399
+ /** A learned workflow's judge (the DSL's runJudge) for `run`: its providers' judge (judgeFromProviders), each decision
400
+ * first held to the run's gate as it is asked (a provider set to deny since the call began is refused, never sent, as
401
+ * a call node's tool is at its effect; deny alone refuses, the rule the runner hands a claim its keys by), then admitted on the run's one cap and settled at what it charged
402
+ * (decisionJudge, as a workflow agent's decision is). A refusal of the cap pauses the run (`decisions.pause`): the
403
+ * decision node fails with the cap's words, and nothing is sent. */
404
+ async function learnedJudge(run, decisions) {
405
+ const [{ judgeFromProviders }, { decisionJudge }, { imageLoader }] = await Promise.all([import("@parcha/agentrun-dsl"), import("./runner/workflow-spec.js"), import("./pdf-pages.js")]);
406
+ // A decision node's images (a page drawn by pdf_pages, a screenshot, an upload) are read through the run's own Workspace
407
+ // (Mode 2: its folder on the run's disk, never the runner's local path), as a workflow agent's are (pdf-pages.ts
408
+ // imageLoader).
409
+ const inner = judgeFromProviders({ providers: decisions.providers.providers, default: decisions.providers.default, loadImage: imageLoader(run.workspace ?? run.work) });
410
+ const capped = decisionJudge(inner, {
411
+ getCap: () => decisions.book,
412
+ providers: decisions.providers,
413
+ park: (refusal) => {
414
+ void decisions.pause?.({ refuse: refusal.message, forGood: refusal.forGood, code: "spend_cap_reached", ...(refusal.figures ? { figures: refusal.figures } : {}) });
415
+ },
416
+ });
417
+ return (async (params) => {
418
+ const provider = params.provider ?? decisions.providers.default;
419
+ await run.refresh?.();
420
+ if (run.policy(provider) === "deny")
421
+ throw new Error(deniedDecisionWords(provider, run.denyFrom(provider), "decision", params.label));
422
+ return capped(params);
423
+ });
424
+ }