@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +84 -16
  3. package/dist/adapters.d.ts +3 -0
  4. package/dist/adapters.js +7 -0
  5. package/dist/agent-rows.d.ts +1 -0
  6. package/dist/agents-store.js +17 -2
  7. package/dist/archil-settings.d.ts +11 -1
  8. package/dist/archil-settings.js +10 -0
  9. package/dist/bash-read-only.d.ts +13 -0
  10. package/dist/bash-read-only.js +77 -0
  11. package/dist/browser-cost.d.ts +2 -2
  12. package/dist/browser-cost.js +6 -4
  13. package/dist/budget.d.ts +0 -5
  14. package/dist/budget.js +0 -5
  15. package/dist/cap.d.ts +6 -3
  16. package/dist/cap.js +7 -4
  17. package/dist/cli.js +32 -5
  18. package/dist/computer-keys.d.ts +20 -10
  19. package/dist/computer-keys.js +36 -57
  20. package/dist/computer-setting.d.ts +6 -5
  21. package/dist/computer-setting.js +54 -26
  22. package/dist/computers.d.ts +9 -4
  23. package/dist/computers.js +4 -2
  24. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  25. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  26. package/dist/console/index.html +2 -2
  27. package/dist/content-filter.d.ts +7 -0
  28. package/dist/content-filter.js +23 -0
  29. package/dist/decision-cap.d.ts +7 -29
  30. package/dist/decision-cap.js +3 -94
  31. package/dist/errors.d.ts +1 -0
  32. package/dist/errors.js +3 -0
  33. package/dist/explain.js +3 -1
  34. package/dist/github-connection.js +25 -7
  35. package/dist/github-faux.d.ts +26 -0
  36. package/dist/github-faux.js +76 -0
  37. package/dist/github.d.ts +6 -2
  38. package/dist/github.js +5 -3
  39. package/dist/graph-served.d.ts +5 -3
  40. package/dist/graph-served.js +14 -6
  41. package/dist/graph-view.js +5 -2
  42. package/dist/harness-opencode/harness.js +0 -1
  43. package/dist/harness-opencode/host/policy.js +2 -2
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/learn/check.d.ts +3 -1
  47. package/dist/learn/check.js +3 -3
  48. package/dist/learn/folder.d.ts +6 -3
  49. package/dist/learn/folder.js +7 -16
  50. package/dist/learn/grade.d.ts +4 -1
  51. package/dist/learn/grade.js +43 -5
  52. package/dist/learn/index.d.ts +2 -2
  53. package/dist/learn/index.js +2 -2
  54. package/dist/learn/learning.sh +1 -14
  55. package/dist/learn/notes.d.ts +14 -3
  56. package/dist/learn/notes.js +16 -6
  57. package/dist/learn/reflect.js +5 -3
  58. package/dist/learn/skills.d.ts +48 -5
  59. package/dist/learn/skills.js +97 -21
  60. package/dist/learned-nodes.d.ts +14 -0
  61. package/dist/learned-nodes.js +8 -0
  62. package/dist/learned-workflow.d.ts +9 -5
  63. package/dist/learned-workflow.js +53 -9
  64. package/dist/learning-routes.d.ts +41 -0
  65. package/dist/learning-routes.js +94 -26
  66. package/dist/learning-run.d.ts +7 -5
  67. package/dist/learning-run.js +9 -6
  68. package/dist/learning.d.ts +0 -22
  69. package/dist/learning.js +0 -16
  70. package/dist/llm.d.ts +4 -1
  71. package/dist/llm.js +4 -2
  72. package/dist/mcp-gateway.d.ts +6 -0
  73. package/dist/mcp-gateway.js +11 -1
  74. package/dist/mcp-servers-store.d.ts +12 -12
  75. package/dist/model.d.ts +3 -0
  76. package/dist/model.js +8 -0
  77. package/dist/openapi.js +37 -13
  78. package/dist/paid-calls.js +1 -1
  79. package/dist/pause.d.ts +2 -19
  80. package/dist/pause.js +5 -74
  81. package/dist/port-models.d.ts +10 -3
  82. package/dist/port-models.js +26 -6
  83. package/dist/propose.d.ts +2 -0
  84. package/dist/propose.js +1 -10
  85. package/dist/run-launch.d.ts +5 -3
  86. package/dist/run-launch.js +6 -5
  87. package/dist/run-learning-served.d.ts +11 -0
  88. package/dist/run-reads-over-store.d.ts +4 -2
  89. package/dist/run-reads-over-store.js +10 -8
  90. package/dist/run-timeline-served.js +12 -2
  91. package/dist/run-view.d.ts +30 -14
  92. package/dist/run-view.js +60 -32
  93. package/dist/runnable.d.ts +4 -1
  94. package/dist/runnable.js +14 -2
  95. package/dist/runner/adapter-loop.d.ts +30 -4
  96. package/dist/runner/adapter-loop.js +253 -29
  97. package/dist/runner/adapter-run-spec.d.ts +21 -0
  98. package/dist/runner/adapter-run-spec.js +104 -28
  99. package/dist/runner/adapters/pi.d.ts +29 -1
  100. package/dist/runner/adapters/pi.js +95 -23
  101. package/dist/runner/beside.d.ts +8 -0
  102. package/dist/runner/beside.js +18 -0
  103. package/dist/runner/claim-secrets.d.ts +6 -0
  104. package/dist/runner/claim-secrets.js +15 -1
  105. package/dist/runner/cli-run-spec.d.ts +3 -0
  106. package/dist/runner/cli-run-spec.js +123 -34
  107. package/dist/runner/conformance/harness.d.ts +1 -0
  108. package/dist/runner/conformance/harness.js +5 -5
  109. package/dist/runner/github-app.d.ts +7 -2
  110. package/dist/runner/github-app.js +46 -15
  111. package/dist/runner/harness-loops.d.ts +6 -1
  112. package/dist/runner/harness-loops.js +23 -0
  113. package/dist/runner/journal-kinds.d.ts +38 -2
  114. package/dist/runner/journal-kinds.js +23 -0
  115. package/dist/runner/learning-end.js +88 -16
  116. package/dist/runner/learning-loop.d.ts +2 -0
  117. package/dist/runner/learning-loop.js +13 -5
  118. package/dist/runner/learning-seed.d.ts +6 -0
  119. package/dist/runner/learning-seed.js +6 -0
  120. package/dist/runner/loop-contract.d.ts +4 -0
  121. package/dist/runner/main.d.ts +9 -4
  122. package/dist/runner/main.js +26 -11
  123. package/dist/runner/mcp-claim.d.ts +3 -0
  124. package/dist/runner/mcp-claim.js +6 -1
  125. package/dist/runner/mcp-github.d.ts +11 -2
  126. package/dist/runner/mcp-github.js +55 -4
  127. package/dist/runner/mcp-run.js +1 -0
  128. package/dist/runner/metrics.d.ts +14 -1
  129. package/dist/runner/metrics.js +72 -1
  130. package/dist/runner/model-route.d.ts +3 -0
  131. package/dist/runner/model-route.js +1 -1
  132. package/dist/runner/runner.js +90 -8
  133. package/dist/runner/spec-holds.d.ts +7 -2
  134. package/dist/runner/spec-holds.js +4 -3
  135. package/dist/runner/workflow-host.d.ts +7 -2
  136. package/dist/runner/workflow-host.js +3 -1
  137. package/dist/runner/workflow-loop.d.ts +4 -1
  138. package/dist/runner/workflow-loop.js +8 -2
  139. package/dist/runner/workflow-spec.d.ts +3 -0
  140. package/dist/runner/workflow-spec.js +156 -78
  141. package/dist/runs-over-store.d.ts +7 -1
  142. package/dist/runs-over-store.js +42 -11
  143. package/dist/seal-key.d.ts +0 -2
  144. package/dist/seal-key.js +0 -2
  145. package/dist/server-lock.js +4 -5
  146. package/dist/server.d.ts +21 -18
  147. package/dist/server.js +183 -34
  148. package/dist/stop-signals.d.ts +4 -2
  149. package/dist/stop-signals.js +5 -3
  150. package/dist/store/agent-body.d.ts +5 -1
  151. package/dist/store/agent-body.js +11 -5
  152. package/dist/store/deadline.d.ts +18 -0
  153. package/dist/store/deadline.js +45 -0
  154. package/dist/store/postgres/connection.d.ts +4 -0
  155. package/dist/store/postgres/connection.js +55 -9
  156. package/dist/store/sqlite/connection.js +3 -38
  157. package/dist/store-reads/journal.js +39 -4
  158. package/dist/store-reads/learning.d.ts +58 -2
  159. package/dist/store-reads/learning.js +172 -7
  160. package/dist/store-view.d.ts +15 -1
  161. package/dist/store-view.js +45 -12
  162. package/dist/templates.d.ts +9 -4
  163. package/dist/templates.js +14 -9
  164. package/dist/timeline/timeline.d.ts +8 -0
  165. package/dist/tool-budget.d.ts +18 -0
  166. package/dist/tool-budget.js +50 -0
  167. package/dist/tool-gate.d.ts +6 -2
  168. package/dist/tool-gate.js +8 -5
  169. package/dist/tool-plane.d.ts +9 -10
  170. package/dist/tools.d.ts +37 -7
  171. package/dist/tools.js +73 -12
  172. package/dist/uploads.d.ts +28 -5
  173. package/dist/uploads.js +82 -9
  174. package/dist/usage.d.ts +1 -47
  175. package/dist/usage.js +3 -82
  176. package/dist/validate.d.ts +2 -0
  177. package/dist/validate.js +11 -1
  178. package/dist/workspace/archil-claim.d.ts +2 -2
  179. package/dist/workspace/archil-claim.js +4 -3
  180. package/dist/workspace/archil-disk.d.ts +10 -1
  181. package/dist/workspace/archil-disk.js +4 -0
  182. package/dist/workspace/archil-exec.d.ts +12 -2
  183. package/dist/workspace/archil-exec.js +16 -0
  184. package/dist/workspace/archil.d.ts +2 -2
  185. package/dist/workspace/archil.js +25 -5
  186. package/dist/workspace/attach.js +2 -0
  187. package/dist/workspace/computer-deps.d.ts +9 -10
  188. package/dist/workspace/computer-deps.js +53 -40
  189. package/dist/workspace/computer-for-claim.d.ts +5 -3
  190. package/dist/workspace/computer-for-claim.js +28 -16
  191. package/dist/workspace/computer-ledger.d.ts +1 -8
  192. package/dist/workspace/computer-ledger.js +0 -3
  193. package/dist/workspace/computer-providers.d.ts +5 -3
  194. package/dist/workspace/computer-providers.js +11 -9
  195. package/dist/workspace/hands.d.ts +5 -2
  196. package/dist/workspace/hands.js +4 -3
  197. package/dist/workspace/index.d.ts +3 -3
  198. package/dist/workspace/index.js +1 -1
  199. package/dist/workspace/local.d.ts +3 -0
  200. package/dist/workspace/local.js +9 -0
  201. package/dist/workspace/paths.js +3 -2
  202. package/dist/workspace/pi-env.d.ts +4 -0
  203. package/dist/workspace/pi-env.js +3 -2
  204. package/dist/workspace/resolve-computer.d.ts +8 -3
  205. package/dist/workspace/resolve-computer.js +28 -11
  206. package/dist/workspace/run-tools.d.ts +2 -0
  207. package/dist/workspace/run-tools.js +9 -3
  208. package/dist/workspace/workspace.d.ts +5 -0
  209. package/dist/workspace.d.ts +0 -3
  210. package/dist/workspace.js +1 -14
  211. package/package.json +14 -14
  212. package/skills/agentrun-serve/SKILL.md +1 -1
  213. package/templates/README.md +2 -2
  214. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  215. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  216. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  217. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  218. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  219. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  220. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  221. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  222. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  223. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  224. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  225. package/templates/release-notes/agent.md +11 -0
  226. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  227. package/dist/console/assets/index-opTN5Naq.css +0 -1
@@ -285,16 +285,19 @@ export const isHeld = (text) => learnedStatus(text) === "pending";
285
285
  * retiredLearned), which take the `status:` line out whole, can edit. One set any other way reads unclear (learnedStatus:
286
286
  * retired), never held or active, and no writer edits it, so a write never leaves part of it behind. The host writes
287
287
  * only one-line statuses (held, retiredLearned). */
288
- export function statusOnOneLine(text) {
288
+ export const statusOnOneLine = (text) => onOneLine(text, "status");
289
+ /** Whether `key`, when the front matter sets it, is one plain line (`key: <value>`, nothing of it on the lines after):
290
+ * statusOnOneLine's rule, for each key the host's writers take out whole (`status`, `retired_from`). */
291
+ function onOneLine(text, key) {
289
292
  const front = frontMatter(text);
290
- if (!front?.has("status"))
293
+ if (!front?.has(key))
291
294
  return true;
292
295
  const lf = text.replace(/\r\n/g, "\n");
293
- const own = lf.slice(4, closeOf(lf)).split("\n").find((line) => line.startsWith("status:"))?.slice("status:".length).trim() ?? "";
296
+ const own = lf.slice(4, closeOf(lf)).split("\n").find((line) => line.startsWith(`${key}:`))?.slice(key.length + 1).trim() ?? "";
294
297
  if (!own || /^[>|]/.test(own) || (/^["']/.test(own) && !closedQuote(own)))
295
298
  return false;
296
299
  // A plain value that wraps onto the next lines reads longer than its own line.
297
- return unquote(own) === front.get("status");
300
+ return unquote(own) === front.get(key);
298
301
  }
299
302
  /** `text`, a SKILL.md or a draft's README.md, as the host merges one the grader held for its owner's OK: `status:
300
303
  * pending` last in its front matter, with LF line ends. Throws on a text with no front matter, which the checker never
@@ -306,20 +309,36 @@ export function held(text) {
306
309
  return `${front.lf.slice(0, front.end)}\nstatus: pending${front.lf.slice(front.end)}`;
307
310
  }
308
311
  /** `text`, a held SKILL.md or draft README.md, as the host leaves it when its owner approves it: its front matter with
309
- * no `status` line, so it is given to every later run. Throws on a text with no front matter. */
312
+ * no `status` or `retired_from` line, so it is given to every later run. Throws on a text with no front matter. */
310
313
  export function released(text) {
311
314
  const front = frontOf(text);
312
315
  if (typeof front === "string")
313
316
  throw new Error(`it cannot be approved: ${front}`);
314
- if (!statusOnOneLine(text))
317
+ // Its status and retired_from are taken out whole, so each must be one plain line; what is left reads back active, or
318
+ // the write fails: never an OK over a skill no run is given.
319
+ if (!statusOnOneLine(text) || !onOneLine(text, "retired_from"))
315
320
  throw new Error("it cannot be approved: its status is not one plain line");
316
- const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
321
+ const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:") && !line.startsWith("retired_from:"));
317
322
  const out = `---\n${kept.join("\n")}${front.lf.slice(front.end)}`;
318
- // What it leaves reads back active, or the approve fails: never an OK over a skill no run is given.
319
323
  if (learnedStatus(out) !== "active")
320
324
  throw new Error(`it cannot be approved: its status would read ${learnedStatus(out)}`);
321
325
  return out;
322
326
  }
327
+ /** The status a retired SKILL.md or draft README.md goes back to when a person restores it (`retired_from`, which its
328
+ * retire recorded), read by the one reader (frontMatter: its quoting, its one-line rule): `active` only when it reads
329
+ * `active` one way, on one plain line; `pending` otherwise, a retire that recorded none or one that reads unclear among
330
+ * them (fail closed: only an approval makes a skill or a draft active). */
331
+ export function retiredFrom(text) {
332
+ return onOneLine(text, "retired_from") && frontMatter(text)?.get("retired_from") === "active" ? "active" : "pending";
333
+ }
334
+ /** Whether a retired SKILL.md or draft README.md can be restored by the host's writer: its front matter reads one way
335
+ * (frontMatter), and its `status` and `retired_from` are each one plain line, the only ones the writer takes out whole.
336
+ * One that is not is refused until it is written so (a restore never edits half a value). */
337
+ export const restorable = (text) => frontMatter(text) !== undefined && statusOnOneLine(text) && onOneLine(text, "retired_from");
338
+ /** `text`, a retired SKILL.md or draft README.md, as the host leaves it when a person restores it: back in the status its
339
+ * retire recorded (retiredFrom), active, or waiting for its owner's OK. Throws on a text whose front matter does not read
340
+ * one way, or whose status is not one plain line (released). */
341
+ export const restoredLearned = (text) => (retiredFrom(text) === "active" ? released(text) : held(released(text)));
323
342
  /** What a SKILL.md or a draft's README.md says of itself, the one reader of it (frontMatter), the server's and, through
324
343
  * the folder's snapshot, the console's: `pending` while it waits for its owner's OK, `retired` once a person retired
325
344
  * it, `active` when it sets no status or `active`. A front matter that does not read one way, or a status that is none
@@ -334,17 +353,22 @@ export function learnedStatus(text) {
334
353
  const status = front.get("status") ?? "active";
335
354
  return status === "active" || status === "pending" ? status : "retired";
336
355
  }
337
- /** `text`, a SKILL.md or a draft's README.md, as a person's retire leaves it: `status: retired` last in its front matter
338
- * (any status line before it dropped), so no later run is given it. Throws on a text with no front matter. */
356
+ /** `text`, a SKILL.md or a draft's README.md, as a person's retire leaves it: `status: retired` and `retired_from`, the
357
+ * status it had (active, or pending while it waited for its owner's OK), last in its front matter (any such lines before
358
+ * them dropped), so no later run is given it and its restore gives that status back. Throws on a text with no front
359
+ * matter. */
339
360
  export function retiredLearned(text) {
340
361
  const front = frontOf(text);
341
362
  if (typeof front === "string")
342
363
  throw new Error(`it cannot be retired: ${front}`);
343
- if (!statusOnOneLine(text))
364
+ if (!statusOnOneLine(text) || !onOneLine(text, "retired_from"))
344
365
  throw new Error("it cannot be retired: its status is not one plain line");
345
- const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:"));
346
- const out = `---\n${[...kept, "status: retired"].join("\n")}${front.lf.slice(front.end)}`;
347
- if (!frontMatter(out) || learnedStatus(out) !== "retired")
366
+ // What it goes back to on a restore: active only when it reads active now; anything else (held, or a text read as
367
+ // retired already) is held again (fail closed).
368
+ const from = learnedStatus(text) === "active" ? "active" : "pending";
369
+ const kept = front.lf.slice(4, front.end).split("\n").filter((line) => !line.startsWith("status:") && !line.startsWith("retired_from:"));
370
+ const out = `---\n${[...kept, "status: retired", `retired_from: ${from}`].join("\n")}${front.lf.slice(front.end)}`;
371
+ if (!frontMatter(out) || learnedStatus(out) !== "retired" || retiredFrom(out) !== from)
348
372
  throw new Error("it cannot be retired: its front matter would not read retired");
349
373
  return out;
350
374
  }
@@ -674,6 +698,59 @@ const gatedNodes = (dsl, doc, gated, deniedBy) => dsl.inspectWorkflow(doc).nodes
674
698
  : `This workflow's call node calls ${tool}, which is set to ask, and a workflow's call node can't wait for an approval: set it to allow for this agent.`;
675
699
  return [{ rule: "workflow", detail: `${words} (the call node at ${node.path})` }];
676
700
  });
701
+ /** An MCP tool a learned workflow's call node may run, by its address (`via: "tool"`, `tool: "mcp:<server>/<tool>"`,
702
+ * LS-07): its server's name as a server is named (mcp-probe.ts MCP_SERVER_NAME) and one tool's name in MCP's own
703
+ * charset, never a wildcard. The one rule for it: the tools a draft may name (tools.ts learnedWorkflowTools), the
704
+ * end-of-run prompt that prints them (reflect.ts), and what the grader is told of a draft (grade.ts). */
705
+ export const LEARNED_MCP_TOOL = /^mcp:[a-z][a-z0-9-]{0,31}\/[A-Za-z0-9_][A-Za-z0-9._-]{0,127}$/;
706
+ /** The MCP tools a draft's call nodes run, each once, in the order they come (LS-07): every call node in `doc`, nested
707
+ * ones too, whose tool is an MCP tool's address. Read from the JSON as it is, for the grader's words; never a check. */
708
+ export function draftMcpTools(doc) {
709
+ const found = new Set();
710
+ for (const node of callNodes(doc))
711
+ if (node.via === "tool" && typeof node.tool === "string" && LEARNED_MCP_TOOL.test(node.tool))
712
+ found.add(node.tool);
713
+ return [...found];
714
+ }
715
+ /** Every call node of `doc` (a parsed workflow.json), in document order: only the workflow's node positions, as the
716
+ * DSL's inspection visits them (its root, a chain's steps, a parallel's branches, a map's and a loop's body, a route's
717
+ * branches' bodies, a nested workflow's root), never an object in a call's args, a schema or any other data, however
718
+ * it is shaped. Walked with a stack of its own, never the call stack, so no draft's nesting can throw here. */
719
+ function callNodes(doc) {
720
+ const out = [];
721
+ const asNode = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : undefined);
722
+ const stack = [asNode(doc)?.root];
723
+ while (stack.length) {
724
+ const node = asNode(stack.pop());
725
+ if (!node)
726
+ continue;
727
+ if (node.node === "call")
728
+ out.push(node);
729
+ const children = node.node === "chain" && Array.isArray(node.steps) ? node.steps
730
+ : node.node === "parallel" && Array.isArray(node.branches) ? node.branches
731
+ : (node.node === "map" || node.node === "loop") ? [node.body]
732
+ : node.node === "route" && asNode(node.branches) ? Object.values(node.branches).map((branch) => asNode(branch)?.body)
733
+ : node.node === "workflow" ? [asNode(node.workflow)?.root]
734
+ : [];
735
+ for (let i = children.length - 1; i >= 0; i--)
736
+ stack.push(children[i]);
737
+ }
738
+ return out;
739
+ }
740
+ /** The call nodes of a learned workflow (`doc`, its parsed workflow.json, nested ones too) whose tool is an MCP tool
741
+ * (LEARNED_MCP_TOOL) that `priceOf` gives no price for (mcp-probe.ts McpPrices: none declared). Such a tool runs "not
742
+ * metered", outside the run's cost and cap (mcp-gateway.ts), so a learned workflow that calls one unattended waits for
743
+ * its owner's OK whatever the grade (LS-07): a structural fact, held in code. Each step once, in order. */
744
+ export function unpricedCalls(doc, priceOf) {
745
+ return callNodes(doc).flatMap((node) => {
746
+ if (node.via !== "tool" || typeof node.tool !== "string" || !LEARNED_MCP_TOOL.test(node.tool) || priceOf(node.tool) !== undefined)
747
+ return [];
748
+ const [server, tool] = node.tool.slice("mcp:".length).split("/");
749
+ return [{ label: typeof node.label === "string" ? node.label : "(unnamed)", tool, server }];
750
+ });
751
+ }
752
+ /** Why a learned workflow that calls `call` waits for its owner's OK, in a person's words. */
753
+ export const unpricedLine = (call) => `its step ${call.label} calls ${call.tool} on ${call.server}, which has no price here, so it runs outside the run's cost and cap`;
677
754
  /** Every string a learned workflow's workflow.json decodes to, each object's keys too, as JSON.parse reads them (its
678
755
  * escapes decoded: what draftProblems and a learned call's run read, and a model node is given). Text a scan of the
679
756
  * stored JSON misses, spelled in \u escapes, is there as it will be read. None for a text that does not parse (the
@@ -744,13 +821,7 @@ const issuesOf = (dsl, doc, tools) => {
744
821
  const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
745
822
  return valid.ok ? [] : valid.issues;
746
823
  };
747
- /** Why `workflows/<name>/workflow.json` is not a draft the host can run; empty when it is. The DSL's own
748
- * `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
749
- * and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
750
- * apply_patch) is never on the list. A model node that names any tool is refused (MODEL_NODE_TOOLS), and a node the
751
- * learned runner cannot run (LEARNED_NODES: a judge's). With no list it
752
- * fails closed: a draft the DSL refuses only once given an empty list names a tool. */
753
- export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}) {
824
+ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask) {
754
825
  let doc;
755
826
  try {
756
827
  doc = JSON.parse(text);
@@ -772,6 +843,11 @@ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}) {
772
843
  const path = doc?.output?.path;
773
844
  if (typeof path !== "string" || !path)
774
845
  out.push({ rule: "workflow", detail: LEARNED_OUTPUT_PATH });
846
+ // Its MCP tools set to ask, on one approval card per learned call (#2424): a card that can't name them all is refused
847
+ // at the gate at every call, so the draft is refused here, in the gate's words.
848
+ const asks = ask ? draftMcpTools(doc).filter((tool) => ask.asked.includes(tool)) : [];
849
+ if (ask && asks.length && !ask.fits(asks))
850
+ out.push({ rule: "workflow", detail: `its approval card can't name all ${asks.length} MCP tools it would call that are set to ask: set some of them to allow or deny for this agent.` });
775
851
  // A composed workflow node's child too: its output is the value at its own output.path, or it fails the same way.
776
852
  for (const node of dsl.inspectWorkflow(doc).nodes) {
777
853
  if (node.kind !== "workflow")
@@ -0,0 +1,14 @@
1
+ /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes }`, its call's id, the
2
+ * workflow's name and each of its nodes that ran (LearnedNode). */
3
+ export declare const LEARNED_NODES = "agentrun.learned_nodes";
4
+ /** The most nodes a call keeps: a map over a long list runs its body once per item. */
5
+ export declare const LEARNED_NODES_MAX = 64;
6
+ /** One node of a learned workflow's run, as the DSL ended it (its `node.end` event): its label, its kind, how it ended
7
+ * (`ok`, `failed`, `escalated`) and how long it took. Never why it failed: the DSL cuts that text at 300 characters,
8
+ * which can leave the start of a secret the run's cut no longer recognizes, so none of it is kept. */
9
+ export type LearnedNode = {
10
+ readonly label: string;
11
+ readonly kind: string;
12
+ readonly status: string;
13
+ readonly duration_ms: number;
14
+ };
@@ -0,0 +1,8 @@
1
+ // What a learned_workflow call keeps of its workflow's run beside itself in the run's journal: each node that ran, as
2
+ // the workflow DSL ended it (learned-workflow.ts runLearned writes it; store-reads/journal.ts runTimeline puts it on the
3
+ // call's result row as `learned_nodes`). Its own module, so the timeline's reader needs none of the tool's imports.
4
+ /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes }`, its call's id, the
5
+ * workflow's name and each of its nodes that ran (LearnedNode). */
6
+ export const LEARNED_NODES = "agentrun.learned_nodes";
7
+ /** The most nodes a call keeps: a map over a long list runs its body once per item. */
8
+ export const LEARNED_NODES_MAX = 64;
@@ -1,4 +1,5 @@
1
1
  import { type ToolRegistration } from "@earendil-works/pi-durable";
2
+ import { type LearnedNode } from "./learned-nodes.js";
2
3
  import { type LearnedWorkflow } from "./learning.js";
3
4
  import type { ModelRef } from "./model.js";
4
5
  import { type Ledger } from "./paid-calls.js";
@@ -40,8 +41,8 @@ type RunModels = {
40
41
  completeSimple(model: never, context: never, options?: never): Promise<unknown>;
41
42
  };
42
43
  export type LearnedWorkflowRun = {
43
- /** The run's learned workflows (learning.ts chooseWorkflows): on the server those its pin names (pinnedWorkflows), on
44
- * the runner those its claim's seed lay chose (runner/learning-seed.ts). */
44
+ /** The run's learned workflows (learning.ts chooseWorkflows): those its claim's seed lay chose
45
+ * (runner/learning-seed.ts). */
45
46
  workflows: readonly LearnedWorkflow[];
46
47
  /** The tools the agent's revision grants: a workflow's call node may name only those a call node runs here
47
48
  * (tools.ts learnedWorkflowTools), and of those, none `plane` resolves unavailable. */
@@ -92,10 +93,13 @@ export declare const NODE_TOOLS_REFUSED = "a learned workflow's model node runs
92
93
  export declare const learnedWorkflowDescription: (workflows: readonly LearnedWorkflow[]) => string;
93
94
  /** The run's `learned_workflow` tool over `run.workflows`. */
94
95
  export declare function learnedWorkflowTool(run: LearnedWorkflowRun): ToolRegistration;
95
- /** `flow` run on `input` for `run`: its output as JSON, or why it did not run. Never throws, but on an abort. `ledger`:
96
- * the tool call's, which each call node's paid requests are booked under, as a call of its own within it. */
97
- export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger): Promise<{
96
+ /** `flow` run on `input` for `run`: its output as JSON, or why it did not run, and each of its nodes that ran (at most
97
+ * LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
98
+ * which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
99
+ * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
100
+ export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[]): Promise<{
98
101
  text: string;
99
102
  isError: boolean;
103
+ nodes: LearnedNode[];
100
104
  }>;
101
105
  export {};
@@ -1,6 +1,27 @@
1
- import { defineTool } from "@earendil-works/pi-durable";
1
+ // learned_workflow: a run of an agent that learned a workflow runs it as one tool call, on any harness. The tool is the
2
+ // run's when its pin names a learned workflow (learning.ts: one whose README sets no status, or `active`; a pending or
3
+ // retired one is never named), with no edit of the agent's definition; its description names each one and what it does,
4
+ // so the model needs no hint. A call checks the workflow again against the agent's own tools as its run has them (S1's
5
+ // checker, draftProblems, as at learn time: a call node on a tool the agent was not granted or its run resolves
6
+ // unavailable, a model node that names any tool, a code node or a shell or executor call is refused before any node
7
+ // runs, never after earlier ones spent), then runs it with the workflow DSL's runWorkflow:
8
+ // - a model node (agent, decide, extract, report) on the run's model of its tier, else the run's own model (the one
9
+ // model the run was made with and handed the key of: app.ts), in a fresh session of its own (agentrun-pi's host
10
+ // runner), with no tool of its own;
11
+ // - a call node `via: "tool"` on the tool table's effect, as a workflow revision's (app.ts), for a tool the agent has,
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
+ // where it resolves native on the provider's hosted search through the run's models (hosted-search.ts), on a harness
14
+ // whose own search it is too (harness-app.ts gives that harness no host tool of the name).
15
+ // 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
+ // 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
+ // `learned_workflow`); on another harness the session's model proxy, under a side key (port-models.ts): the harness's
18
+ // own policy, provider, key and price, booked on the session's records labelled `learned_workflow`. A call a crash cut
19
+ // off is never run again (`replay: "never"`): it is answered interrupted.
20
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
21
+ import { defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
2
22
  import { registerLabel, registerOutcome } from "./timeline/index.js";
3
23
  import { sideRequests } from "./cap.js";
24
+ import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
4
25
  import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
5
26
  import { workflowLine } from "./learning.js";
6
27
  import { ledgerOf } from "./paid-calls.js";
@@ -169,15 +190,31 @@ export function learnedWorkflowTool(run) {
169
190
  const flow = run.workflows.find((workflow) => workflow.name === name);
170
191
  if (!flow)
171
192
  return forModel(`No learned workflow of this agent is named ${JSON.stringify(name)}. Its workflows: ${names.join(", ")}.`, { isError: true });
172
- const said = await runLearned(run, flow, input, context?.abortSignal, ledgerOf(api, context));
193
+ const ledger = ledgerOf(api, context);
194
+ // Which of its nodes ran, kept beside the call in the run's journal (LEARNED_NODES), for its timeline row; a trace
195
+ // that can't be kept never fails the call. A call stopped part way keeps the nodes that ended before it stopped,
196
+ // written outside the stopped call's context, and still ends as a stop.
197
+ const trace = [];
198
+ const keep = (signal) => (trace.length ? api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace } })), signal).catch(() => undefined) : undefined);
199
+ let said;
200
+ try {
201
+ said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace);
202
+ }
203
+ catch (error) {
204
+ await keep(BACKGROUND_CONTEXT);
205
+ throw error;
206
+ }
207
+ await keep(context);
173
208
  return forModel(said.text, { isError: said.isError });
174
209
  },
175
210
  });
176
211
  }
177
- /** `flow` run on `input` for `run`: its output as JSON, or why it did not run. Never throws, but on an abort. `ledger`:
178
- * the tool call's, which each call node's paid requests are booked under, as a call of its own within it. */
179
- export async function runLearned(run, flow, input, signal, ledger) {
180
- const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true });
212
+ /** `flow` run on `input` for `run`: its output as JSON, or why it did not run, and each of its nodes that ran (at most
213
+ * LEARNED_NODES_MAX), none for one refused before any node ran. Never throws, but on an abort. `ledger`: the tool call's,
214
+ * which each call node's paid requests are booked under, as a call of its own within it. `nodes`: where each node is
215
+ * added as it ends, the caller's to keep when the call is aborted (and so throws) part way. */
216
+ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
217
+ const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true, nodes });
181
218
  if (!input || typeof input !== "object" || Array.isArray(input))
182
219
  return refuse("its input must be a JSON object");
183
220
  const dsl = await import("@parcha/agentrun-dsl");
@@ -275,15 +312,22 @@ export async function runLearned(run, flow, input, signal, ledger) {
275
312
  const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
276
313
  return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
277
314
  };
315
+ // Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
316
+ const onEvent = (event) => {
317
+ if (event.type !== "node.end" || nodes.length >= LEARNED_NODES_MAX)
318
+ return;
319
+ const detail = (event.detail ?? {});
320
+ 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 });
321
+ };
278
322
  try {
279
- const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, ...(signal ? { signal } : {}) });
323
+ const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...(signal ? { signal } : {}) });
280
324
  if (result.status !== "complete")
281
325
  return refuse(`it ended ${result.status}`);
282
- return { text: learnedText(JSON.stringify(result.output ?? null)), isError: false };
326
+ return { text: learnedText(JSON.stringify(result.output ?? null)), isError: false, nodes };
283
327
  }
284
328
  catch (error) {
285
329
  if (signal?.aborted)
286
330
  throw error;
287
- return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true };
331
+ return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true, nodes };
288
332
  }
289
333
  }
@@ -1,6 +1,8 @@
1
+ import type { DraftAsk } from "./learn/skills.js";
1
2
  import type { IncomingMessage, ServerResponse } from "node:http";
2
3
  import { type ItemStatus, type Learning, type NoteRuns, type Shown } from "./learning.js";
3
4
  import type { Impact } from "./learning-run.js";
5
+ import { type LearnedUse } from "./store-reads/learning.js";
4
6
  import type { Store } from "./store/store.js";
5
7
  type Page<T> = {
6
8
  items: T[];
@@ -28,6 +30,7 @@ type NoteView = {
28
30
  type Retired = {
29
31
  at: string;
30
32
  by: "person" | "run";
33
+ from: "active" | "pending";
31
34
  };
32
35
  /** The newest change to a note, skill or draft (its file: the note, a SKILL.md, a draft's README.md): what it was, by
33
36
  * whom and when. A person's is named by its commit (`learning: <kind> by a person: <file>`); a run's merge is `learned`. */
@@ -141,6 +144,8 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
141
144
  draftTools?: () => Promise<{
142
145
  tools: string[];
143
146
  gated: Record<string, string>;
147
+ deniedBy?: Record<string, "agent" | "server" | "default">;
148
+ ask?: DraftAsk;
144
149
  }>;
145
150
  }): Promise<{
146
151
  status: 200 | 201;
@@ -148,6 +153,30 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
148
153
  text: string;
149
154
  etag: string;
150
155
  }>;
156
+ /** A learned workflow as a promotion makes it into an agent of its own: its folder's name, its README's description,
157
+ * its workflow.json parsed, and the tools its call nodes call. */
158
+ export type Promotable = {
159
+ name: string;
160
+ description: string;
161
+ workflow: Record<string, unknown>;
162
+ calls: string[];
163
+ };
164
+ /** POST /agents/{id}/learning/workflows/{name}/promote's read of the learned workflow `raw` (percent-encoded) on agent
165
+ * `agentId`'s main: an active one alone, as every later run is given it. One that waits for its owner's OK, or that a
166
+ * person retired, is 409 learned_not_active: a promotion never runs what the owner has not let every run use. Each of
167
+ * its files is checked again as a restore checks it (unstorable: a secret's shape, the host's values as they are now,
168
+ * a hidden character), and its workflow.json as the learning checker checks a run's draft against the agent's tools and
169
+ * its gate (draftProblems: the DSL's validation with no code run, no code node, no shell or executor call, no call node
170
+ * on a tool the agent does not have or the gate holds to ask or deny). Any of those is 400 with `problems`, printable.
171
+ * Reads only: the folder is never written. */
172
+ export declare function promotable(data: string, agentId: string, raw: string, input: {
173
+ refuse: readonly string[];
174
+ draftTools: () => Promise<{
175
+ tools: string[];
176
+ gated: Record<string, string>;
177
+ deniedBy?: Record<string, "agent" | "server" | "default">;
178
+ }>;
179
+ }): Promise<Promotable>;
151
180
  /** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
152
181
  * settled: the one shape, read from the one store (store-reads/learning.ts
153
182
  * runLearningOverStore). */
@@ -156,6 +185,7 @@ export declare function runLearningBody(input: {
156
185
  readonly learning: Learning;
157
186
  readonly seed: string | null;
158
187
  readonly settled: boolean;
188
+ readonly used?: LearnedUse;
159
189
  }, shown: Shown, secrets: readonly string[]): {
160
190
  seed: string | null;
161
191
  merged: string | null;
@@ -186,6 +216,17 @@ export declare function runLearningBody(input: {
186
216
  tokens: {
187
217
  grade: import("./learning.js").Tokens | null;
188
218
  };
219
+ used: {
220
+ skills: {
221
+ name: string;
222
+ read: boolean;
223
+ }[];
224
+ workflows: {
225
+ name: string;
226
+ calls: number;
227
+ failed: number;
228
+ }[];
229
+ };
189
230
  given?: import("./learning.js").NoteUsed[];
190
231
  read?: import("./learning.js").NoteUsed[];
191
232
  learned?: import("./learning.js").NoteLearned[];