@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
package/dist/openapi.js CHANGED
@@ -25,7 +25,7 @@ import { ATTEMPTS_KEPT, MESSAGE_TYPES, WEBHOOK_EVENTS } from "./webhooks.js";
25
25
  import { DEFAULT_SCHEME, SCHEME_NAMES, SIGNATURE_SCHEMES } from "./trigger-signatures.js";
26
26
  import { HOOK_BODY_MS } from "./push-handler.js";
27
27
  import { CATCHUP_WINDOW_S, DUE_KEPT, MAX_ACTIVE_RUNS, SEEN_KEPT, FAILURES_TO_PAUSE, FIRING_STATUSES, PAYLOAD_KEPT_BYTES, HISTORY_KEPT, MAX_EVERY_S, SOURCE_KINDS, TARGET_KINDS } from "./triggers.js";
28
- import { DEFINITION_FIELDS, EXTERNAL_NAME, MODEL_REF, NOT_KEPT } from "./validate.js";
28
+ import { DEFINITION_FIELDS, EXTERNAL_NAME, MAX_TOOL_CALLS, MODEL_REF, NOT_KEPT } from "./validate.js";
29
29
  import { GRADER_TYPES, MODEL_TIERS, PARAMETER_TYPES } from "./templates.js";
30
30
  import { NOT_SET_UP } from "./runnable.js";
31
31
  import { APPROVAL_ROW, ARGS_PREVIEW_BYTES, MAX_PIN_ARGS, MAX_PIN_CHOICES, PERMISSIONS } from "./tool-gate.js";
@@ -432,7 +432,8 @@ const LEARNING_NOTE_REQUIRED = closed({
432
432
  const RETIRED = closed({
433
433
  at: { type: "string", format: "date-time", description: "When: the commit that retired it." },
434
434
  by: { enum: ["person", "run"], description: "`person`: its owner, in the console or with POST .../retire (the time of that retire; an edit since moves it not); `run`: anything else that set it." },
435
- }, "When and by whom it was retired; absent unless `status` is `retired`. POST .../restore makes it active again.");
435
+ from: { enum: ["active", "pending"], description: "The status POST .../restore gives it back, as its retire recorded it (`retired_from` in its front matter): `active`, or `pending`, waiting for its owner's OK again, so a retire and a restore never skip that OK. One whose retire recorded none reads `pending`." },
436
+ }, "When and by whom it was retired, and what its restore gives back; absent unless `status` is `retired`. POST .../restore puts it back in the status it had before its retire (`from`).");
436
437
  /** The newest change to a note, skill or draft, from the newest commit on its file. */
437
438
  const LAST_CHANGE = closed({
438
439
  kind: { enum: ["approved", "edited", "created", "retired", "restored", "learned", "superseded"], description: "What the change was: a person's approval, edit, creation, retire or restore (named by its commit), `superseded`, a note a person's approval or restore of another superseded, or `learned`, a run's merge." },
@@ -453,7 +454,7 @@ const LEARNING_COUNTS = closed({
453
454
  }, "How the agent's runs that tried to learn fared, archived runs left out: GET /stats' `learning` with `agent`, less `runs`, counted as it counts them, from the runs this server holds and its learning ledger, no run's files opened.");
454
455
  /** One side of an agent's impact (learning-run.ts learningImpact). */
455
456
  const IMPACT_SIDE = (side) => closed({
456
- runs: { ...COUNT, description: side === "before" ? "The completed runs that started before the agent's first note." : "The completed runs that started from at least one active note." },
457
+ runs: { ...COUNT, description: side === "before" ? "The completed runs that started before the agent's first learned item (a note, a skill or a workflow)." : "The completed runs that started from at least one learned item: an active note, a learned skill they were offered, or a learned workflow their learned_workflow tool could run." },
457
458
  median_duration_s: { type: "number", minimum: 0, description: "Their median time to the answer, in seconds to a tenth: from the run's start to the moment its job's answer was final, before it looks back (a run that does not look back: to its end)." },
458
459
  median_cost_usd: { type: ["number", "null"], minimum: 0, description: "The median of the job's own cost, without its end-of-run turn, over the `cost_runs` whose cost is known, rounded to 1e-6; null when none is." },
459
460
  cost_runs: { ...COUNT, description: "Of `runs`, those whose job's cost is known: the ones `median_cost_usd` is the median of." },
@@ -488,7 +489,7 @@ const AGENT_LEARNING = closed({
488
489
  counts: LEARNING_COUNTS,
489
490
  impact: {
490
491
  oneOf: [closed({ before: IMPACT_SIDE("before"), after: IMPACT_SIDE("after") }), { type: "null" }],
491
- description: "What learning changed for the agent: its completed agentic runs that started from at least one active note (`after`) against those that started before its first note (`before`: before the earlier of its first merge and the start of its first run that started from a note, so a person's first note counts too). A later run with learning off, or seeded with no note (every note retired), an imported and an archived run are on neither side. Null unless both sides count 2 runs or more: say it \"on N runs\", N `after.runs`. Read from the runs' rows and the learning ledger, no run's files opened.",
492
+ description: "What learning changed for the agent: its completed agentic runs that started from at least one learned item, an active note, a learned skill they were offered or a learned workflow they could run (`after`), against those that started before its first item (`before`: before the earlier of its first merge and the start of its first run that started from one, so a person's first note counts too). A later run with learning off, or seeded with no item (every note, skill and workflow retired), an imported and an archived run are on neither side. Null unless both sides count 2 runs or more: say it \"on N runs\", N `after.runs`. Read from the runs' rows and the learning ledger, no run's files opened.",
492
493
  "x-agentrun-serve": "learning/2",
493
494
  },
494
495
  });
@@ -601,7 +602,8 @@ const COMPUTER_PROVIDER = closedWith({
601
602
  }, {
602
603
  why: { type: "string", description: "Why it is not ready, in words naming the setting to fill." },
603
604
  gpu: { ...COMPUTER_PROVIDER_GPU, description: "A sandbox provider's GPUs, where it declares them: the choices an agent's `computer.gpu` names." },
604
- network: { type: "string", description: "For a vendor-hosted computer, what this server's allow-list (AGENTRUN_BOX_ALLOW) means for it, in words: one with no network has none (\"no network, so this server's allow-list isn't offered\"); one on the vendor's own network is open (\"the vendor's own network; this server's allow-list doesn't apply\"). Absent where the allow-list applies (Docker)." },
605
+ network: { type: "string", description: "For a vendor-hosted computer, what this server's allow-list (AGENTRUN_BOX_ALLOW) means for it, in words: one with no network has none (\"no network, so this server's allow-list isn't offered\"); one on an open network is open (\"an open network (the vendor's own, or public addresses from this machine); this server's allow-list doesn't apply\"). Absent where the allow-list applies (Docker), or where it depends on the image a provider's configurations name." },
606
+ images: { type: "array", items: { type: "string" }, description: "The images the provider offers for the kind, as an agent's `computer.image` names them (Orgo's desktop: `linux`, `windows`); the kind's default first when it is one of them. Absent when it offers none to choose." },
605
607
  });
606
608
  /** GET /computers' answer (computers.ts view). */
607
609
  const COMPUTERS_VIEW = closed({
@@ -641,7 +643,7 @@ const ARCHIL_VIEW = closedWith({
641
643
  diskId: { type: "string" },
642
644
  region: { type: "string" },
643
645
  s3Url: { type: "string", format: "uri" },
644
- image: { type: "string", description: "The exec image, pinned by digest (`<name>@sha256:<64 hex>`); absent, Archil's default." },
646
+ image: { type: "string", description: "The exec image, pinned by digest (`<name>@sha256:<64 hex>`); absent, serve's default (`buildpack-deps:trixie-scm` pinned by digest, git 2.47)." },
645
647
  });
646
648
  const COMPUTER_MARK = { "x-agentrun-serve": "computer/1" };
647
649
  const ARCHIL_MARK = { "x-agentrun-serve": "archil/1" };
@@ -777,7 +779,7 @@ const TEMPLATE = closed({
777
779
  },
778
780
  parameters: { type: "object", additionalProperties: TEMPLATE_PARAMETER, description: "What apply takes in `parameters`, by name, put where the package writes `${parameters.<name>}`." },
779
781
  secrets: { type: "array", items: { type: "string" }, description: "The keys this server must have, by variable name (a saved key counts), before apply makes anything." },
780
- budget: { type: ["object", "null"], additionalProperties: false, required: ["per_run_usd"], properties: { per_run_usd: { type: "number" } }, description: "Each run's spend cap, the agent's max_cost_usd. Required of a package with triggers." },
782
+ budget: { type: ["object", "null"], additionalProperties: false, minProperties: 1, properties: { per_run_usd: { type: "number" }, tool_calls: { type: "integer", minimum: 1 } }, description: "Each run's limits: per_run_usd, its spend cap (the agent's max_cost_usd), required of a package with triggers; tool_calls, the tool calls each of its conversations may make (the agent's max_tool_calls)." },
781
783
  learning: { type: "boolean" },
782
784
  approvals_default: { enum: ["ask", "never"], description: "What the package recommends for the agent's approvals: `ask`, the agent asks its person before a tool runs; `never`, it runs unattended (a template whose job runs on triggers). Deny settings and pins hold either way: a pinned write can only go where its pin says." },
783
785
  triggers: { type: "array", items: { type: "object" }, description: "The triggers apply makes on its agent: POST /triggers bodies with no agent_id, placeholders unfilled." },
@@ -822,6 +824,10 @@ const RUN_LEARNING = {
822
824
  problems: { type: "array", items: PROBLEM, description: "The checker's, when the reason is `checker`; otherwise, the items the checks left out while the rest went on to the grader (on a merge, a grader's drop or a grade that failed)." },
823
825
  cost_usd: closed({ grade: { type: ["number", "null"], description: "The grade's, outside the run (GET /usage's `learning` meter); null before a grade ran, or when its cost is unknown. The end-of-run turn's cost is in the run's own totals." } }),
824
826
  tokens: closed({ grade: { oneOf: [closed({ input: COUNT, cache_read: COUNT, cache_write: COUNT, output: COUNT }), { type: "null" }], description: "The grade's tokens; `input` excludes cached input." } }),
827
+ used: closed({
828
+ skills: { type: "array", items: closed({ name: { type: "string" }, read: { type: "boolean" } }), description: "Each learned skill the run was offered, and whether its job read the skill's SKILL.md (a read of `.agents/skills/<name>/SKILL.md`, read_skill_file on it, or a harness's own Skill tool on it; the end-of-run turn's reads not counted). A name holding one of the host's secrets reads `[redacted]`." },
829
+ workflows: { type: "array", items: closed({ name: { type: "string" }, calls: COUNT, failed: COUNT }), description: "Each learned workflow the run's job called (`learned_workflow`), by the name its calls gave: how many calls, and how many of them failed. A name holding one of the host's secrets reads `[redacted]`." },
830
+ }, "What the run's job did with the learned skills and workflows it was offered, apart from `skills` and `workflows`, the ones it learned."),
825
831
  }, LEARNING_NOTES),
826
832
  { type: "null" },
827
833
  ],
@@ -925,13 +931,23 @@ const LEARNING_EXTENSIONS = {
925
931
  },
926
932
  "/agents/{agent_id}/learning/files/{file}/restore": {
927
933
  post: {
928
- operationId: "restoreLearningFile", tags: ["agents"], summary: "Restore a retired note, skill or workflow draft: active again for the next run",
929
- description: "A retired note is made active, a skill (its SKILL.md) or a workflow draft (its README.md) is given to every later run again, in one commit on main (`learning: restored by a person: <file>`, Changed-By: user) with MEMORY.md rebuilt. The text is checked again as a new note or skill is (a secret's shape, the host's own values, a hidden character, its format), so a value a retire took out of every run never comes back: such a note stays retired, and the answer names the rule, never the value. Only a retired one is restored (else 400). The owner's password session alone, as an approval.",
934
+ operationId: "restoreLearningFile", tags: ["agents"], summary: "Restore a retired note, skill or workflow draft to the status it had before its retire",
935
+ description: "A retired note, skill (its SKILL.md) or workflow draft (its README.md) goes back to the status its retire recorded (`retired.from`): active, given to every later run again, or waiting for its owner's OK again (a retire that recorded none restores it waiting): a restore is never an approval. In one commit on main (`learning: restored by a person: <file>`, Changed-By: user) with MEMORY.md rebuilt. The text is checked again as a new note or skill is (a secret's shape, the host's own values, a hidden character, its format), so a value a retire took out of every run never comes back: such a note stays retired, and the answer names the rule, never the value. Only a retired one is restored (else 400). The owner's password session alone, as an approval.",
930
936
  security: [{ ownerSession: [] }],
931
937
  requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, maxProperties: 0 } } } },
932
938
  parameters: [AGENT_ID, NOTE_PARAM, IF_MATCH], responses: { "200": NOTE_TEXT("The note, restored."), ...WRITE_ERRORS }, ...MARK,
933
939
  },
934
940
  },
941
+ "/agents/{agent_id}/learning/workflows/{name}/promote": {
942
+ post: {
943
+ operationId: "promoteLearnedWorkflow", tags: ["agents"], summary: "Make a learned workflow an agent of its own: a workflow agent that runs with no agent loop",
944
+ description: "Makes a new agent, as POST /agents makes one, whose revision is a workflow revision of the learned workflow's `workflow.json`: its runs run the workflow's nodes alone, with no agentic turn around them, and its output is the workflow's. Only an active workflow is made an agent: one that waits for its owner's OK, or that a person retired, is 409 `learned_not_active`, and nothing is made. Its files are checked again as a restore checks them (a secret's shape, the host's own values as they are now, a hidden character), and its workflow as the learning checker checks a run's draft against the agent's tools and its gate (the DSL's validation with no code run, no code node, no shell or executor call, no call node on a tool the agent does not have or that is set to ask or deny): any of those is 400 `bad_request` with `problems`, and nothing is made. Then the checks every workflow revision's save makes (422 by field, or 409 `agent_not_runnable`). The new agent's tools are the ones its call nodes call, and it keeps the source agent's policy as it is now (its own `tool_settings`, its `approvals`, its default cap `max_cost_usd` and `cap_mode`), never more. Its name is `name`, else the workflow's own; its id is the workflow's name, with `-2`, `-3` and on past an agent's id or name already here. The learned workflow stays in the folder, unchanged. With Idempotency-Key, a retry answers the agent the first request made. Only the owner, signed in with their password, makes one: the console's password session alone, from this server's own origin with a JSON body, as an approval; every token is 403 `forbidden`. " + SIGN_IN_WITHHELD,
945
+ security: [{ ownerSession: [] }],
946
+ parameters: [AGENT_ID, { name: "name", in: "path", required: true, description: "The learned workflow's folder name, `workflows/<name>/`: lowercase letters, digits, dashes and underscores.", schema: { type: "string" } }, ref("parameters/IdempotencyKey")],
947
+ requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { name: { type: "string", minLength: 1, maxLength: 200, description: "The new agent's name; absent, the workflow's own." } } } } } },
948
+ responses: { "201": { description: "The new agent, with what this host still lacks for it to run (`warnings`).", headers: { Location: ref("headers/Location"), "Idempotent-Replayed": ref("headers/IdempotentReplayed") }, content: { "application/json": { schema: ref("schemas/Agent") } } }, ...errors(400, 401, 403, 404, 409, 422, 429, 500) }, ...MARK,
949
+ },
950
+ },
935
951
  "/runs/{run_id}/learning": {
936
952
  get: {
937
953
  operationId: "getRunLearning", tags: ["runs"], summary: "The run's learning whole: its seed, merge, verdict, problems and cost",
@@ -1423,7 +1439,7 @@ const EXTENSIONS = {
1423
1439
  "/integrations/github/connect": {
1424
1440
  post: {
1425
1441
  operationId: "connectGitHub", tags: ["local"], summary: "Start Connect GitHub: the app-manifest form the console posts to GitHub",
1426
- description: "GitHub's app-manifest flow, which makes the server's one GitHub App. Answers the form the console auto-submits: `action` (GitHub's new-App page, under `org` when given, with `state` on it) and `manifest` (a field of that form, as JSON): a name GitHub lets the person edit, the server's public URL, its hook `/v2/hooks/github`, its callback and its setup URL, the App's permissions (pull requests write, contents, metadata and issues read) and events (pull_request, issue_comment). `state` is random, used once, good for an hour, and bound to the browser that started it by a cookie on the callback's path; GitHub reads it from `action`'s URL, and the form posts only `manifest`. 409 github_no_public_url (\"GitHub can't reach this server: set its public URL first\") with no public URL (AGENTRUN_PUBLIC_URL); 409 github_already_connected (\"This server already has a GitHub App. Disconnect it first.\"); 409 github_wrong_origin (\"Open this server at <public URL> to connect GitHub.\", `details.public_url` that URL, for the console's link) when the request came to another address than the public URL, where GitHub sends the browser back: nothing is started.",
1442
+ description: "GitHub's app-manifest flow, which makes the server's one GitHub App. Answers the form the console auto-submits: `action` (GitHub's new-App page, under `org` when given, with `state` on it) and `manifest` (a field of that form, as JSON): a name GitHub lets the person edit, the server's public URL, its hook `/v2/hooks/github`, its callback and its setup URL, the App's permissions (pull requests write, contents, metadata and issues read) and events (pull_request, issue_comment, release). `state` is random, used once, good for an hour, and bound to the browser that started it by a cookie on the callback's path; GitHub reads it from `action`'s URL, and the form posts only `manifest`. 409 github_no_public_url (\"GitHub can't reach this server: set its public URL first\") with no public URL (AGENTRUN_PUBLIC_URL); 409 github_already_connected (\"This server already has a GitHub App. Disconnect it first.\"); 409 github_wrong_origin (\"Open this server at <public URL> to connect GitHub.\", `details.public_url` that URL, for the console's link) when the request came to another address than the public URL, where GitHub sends the browser back: nothing is started.",
1427
1443
  requestBody: { required: false, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { org: { type: "string", pattern: "^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$", description: "The GitHub organization to make the App under; absent, the signed-in GitHub user." } } } } } },
1428
1444
  responses: { "200": json(closed({ action: { type: "string", format: "uri" }, manifest: { type: "object", description: "GitHub's app manifest, posted as the form's `manifest` field." }, state: { type: "string" } }), "The form to post to GitHub."), ...errors(400, 401, 409, 415, 422, 429, 500) },
1429
1445
  ...GITHUB_MARK,
@@ -1952,6 +1968,12 @@ const FIELD_EXTENSIONS = {
1952
1968
  description: "On a trigger's row (`origin` `trigger`) alone: the trigger whose input the row is, so a client labels it by its source without reading its summary. Absent on every other row.",
1953
1969
  "x-agentrun-serve": "origin/1",
1954
1970
  },
1971
+ learned_nodes: {
1972
+ type: "array",
1973
+ items: { type: "object", additionalProperties: false, required: ["label", "kind", "status", "duration_ms"], properties: { label: { type: "string" }, kind: { type: "string", description: "The node's kind, as the workflow DSL names it (`extract`, `agent`, `call`, ...)." }, status: { type: "string", description: "How the node ended: `ok`, `failed` or `escalated`. Why a node failed is never shown: its text may hold part of a secret." }, duration_ms: { type: "number" } } },
1974
+ description: "On a learned workflow call's `tool_result` row alone (`tool_name` learned_workflow): each of the workflow's nodes that ran, in the order they ended, at most 64. Absent on every other row.",
1975
+ "x-agentrun-serve": "learnednodes/1",
1976
+ },
1955
1977
  learning: {
1956
1978
  ...closed({ state: { enum: [...LEARNING_STATES] }, reason: LEARNING_REASON, detail: { type: ["string", "null"] } }),
1957
1979
  description: `On a row of kind \`learning\` alone, labelled \`${LEARNING_LABEL}\`: where the run's learning ended (proposed, merged or dropped, \`seed_failed\` included), and why: one row, changed in place as it moves. Its \`summary\` and \`text\` are its \`detail\` (Run.learning.detail), in a person's words. The rows of the run's end-of-run turn are labelled \`${LEARNING_LABEL}\` too, its message and answer included, and are never the run's answer.`,
@@ -1981,14 +2003,16 @@ const FIELD_EXTENSIONS = {
1981
2003
  properties: {
1982
2004
  kind: { enum: ["none", "sandbox", "desktop", "phone", "browser"] },
1983
2005
  provider: { type: "string", description: "The provider that serves the kind, from GET /computers. Absent for `none`." },
2006
+ image: { type: "string", minLength: 1, description: "The image the computer starts from: one the provider offers for the kind (GET /computers lists them as the provider's `images`), such as Orgo's `windows` desktop. Absent, the kind's default. One the provider does not offer saves with a warning naming the ones it does, and its runs are refused at their start in the same words. Absent for `none`." },
1984
2007
  gpu: COMPUTER_GPU,
1985
2008
  },
1986
- description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, and a sandbox's GPUs. `place` is its v2 view where it can say it: `{kind: none}` is `place {mode: runner}`, `{kind: sandbox, provider: X}` is `place {mode: sandbox, box: X}`; a desktop, phone or browser computer leaves the run's folder on the runner, so its place reads runner. Writing either sets both, and both given must agree (422). Absent on a create, the server's default (as `place`); an edit that names neither keeps the agent's.",
2009
+ description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, the image it starts from, and a sandbox's GPUs. `place` is its v2 view where it can say it: `{kind: none}` is `place {mode: runner}`, `{kind: sandbox, provider: X}` is `place {mode: sandbox, box: X}`; a desktop, phone or browser computer leaves the run's folder on the runner, so its place reads runner. Writing either sets both, and both given must agree (422). Absent on a create, the server's default (as `place`); an edit that names neither keeps the agent's.",
1987
2010
  "x-agentrun-serve": "computer/1",
1988
2011
  },
1989
2012
  tool_settings: { ...AGENT_TOOL_SETTINGS, description: "The agent's own tool settings (web_search's, web_fetch's and browser's provider, any tool's permission, an MCP server's wildcard mcp:<server>/*, an MCP tool's pin, bash's policy), over the server's (GET /settings/tools), except a deny set on the server, which is absolute: the tool is refused on this server whatever this agent sets; absent, the server's. A pin is not over the server's: both hold. A grant in tools names the capability, never a provider.", "x-agentrun-serve": "providers/1" },
1990
2013
  approvals: { enum: ["ask", "never"], default: "ask", description: "Whether the agent's runs ask a person or run unattended. `ask`, the default: a tool set to ask parks the run for an approval, as its tool settings say. `never`: the agent runs unattended, and each tool that would ask is allowed instead, decided by the tool gate at each call, so a tool granted later and an MCP tool (`mcp:<server>/<tool>`, which asks by default) are covered on every harness. It never lifts a deny, whether set on this server or in the agent's own tool_settings, nor a pin, nor anything else the gate refuses before it decides between running and asking. A workflow's call node on a tool set to ask runs under `never`. Absent on a request: ask. An edit that leaves it out asks, so no edit makes an agent unattended by saying nothing. Every answer names it.", "x-agentrun-serve": "unattended/1" },
1991
2014
  learning: { type: "boolean", default: false, description: "Whether an agentic revision's runs learn: each starts from what its agent has learned, its notes in its instructions under `# Learned` (each whole within the server's learning budget, else the index and the notes changed last, whole) and in `.learning/` in its working directory, and once it answers or fails is asked one more turn to add notes there, which are checked, graded and merged. Kept when a definition says so, true or false; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
2015
+ max_tool_calls: { type: "integer", minimum: 0, maximum: MAX_TOOL_CALLS, description: "An agentic revision's tool-call budget, on pi: the tool calls each conversation of its runs may make (the run's own, and each one a tool opens, counted apart). Past it, every call is refused before it runs with words that tell the model to answer now from what it has; that refusal is not counted, and the run is never ended by it. Counted from the conversation's journal, so a restart or a moved claim keeps the count. Above 0 sets it, 0 clears it, and an edit that leaves it out keeps the agent's. On another harness it is refused: 422 `definition.max_tool_calls` at the save. A template's `budget.tool_calls` sets it at apply.", "x-agentrun-serve": "toolbudget/1" },
1992
2016
  cap_mode: { ...CAP_MODE, description: `The cap mode of each run of this agent that has a cap and names none of its own. ${CAP_MODE.description} An edit that leaves it out keeps the agent's. An agentic definition's or a workflow's alike.` },
1993
2017
  },
1994
2018
  AgentCreate: {
@@ -2570,8 +2594,8 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
2570
2594
  timelineKind.enum = [...timelineKind.enum, APPROVAL_ROW];
2571
2595
  fields.push(`TimelineKind.${APPROVAL_ROW}`);
2572
2596
  }
2573
- // A run's learning row (runs.ts) beside the contract's row kinds, and GET /usage's `learning` meter (usage.ts): what a
2574
- // run's grade spends on this server, outside any run.
2597
+ // A run's learning row beside the contract's row kinds, and GET /usage's `learning` meter: what a run's grade spends
2598
+ // on this server, outside any run.
2575
2599
  for (const [name, value] of [["TimelineKind", "learning"], ["Meter", "learning"]]) {
2576
2600
  const schema = schemas[name];
2577
2601
  if (!Array.isArray(schema.enum) || schema.enum.includes(value))
@@ -175,7 +175,7 @@ export async function paidStep(paid, call, fee, run, chargeOf, pause) {
175
175
  async function paidOn(paid, call, fee, send, chargeOf) {
176
176
  const id = `${call}#${(paidSeq += 1)}`;
177
177
  try {
178
- await paid.admit({ id, name: fee.name, holdUsd: fee.usd, basis: fee.basis, call, chargedBy: fee.by });
178
+ await paid.admit({ id, name: fee.name, tool: fee.tool, holdUsd: fee.usd, basis: fee.basis, call, chargedBy: fee.by });
179
179
  }
180
180
  catch (error) {
181
181
  await pauseOn(error);
package/dist/pause.d.ts CHANGED
@@ -1,11 +1,5 @@
1
- export declare const RUN_PAUSED = "paused";
2
- export declare const NODE_LOG = "nodes.jsonl";
3
- export declare const LIVE_VIEW = "live.json";
4
- export declare const pausedIn: (root: string) => boolean;
5
- /** `fn`, waiting before each call while the run at `root` is paused. A cancel, or the call's own signal aborting, lets
6
- * the call go to meet its abort. */
7
- export declare function gated<P, R>(root: string, fn: (params: P) => Promise<R>): (params: P) => Promise<R>;
8
- /** One line of the node log. `path` is the execution path; `item` the map item's index, null outside a map. */
1
+ /** One line of the node log (the runner's KINDS.nodeEffect entries). `path` is the execution path; `item` the map item's
2
+ * index, null outside a map. */
9
3
  export type NodeLine = {
10
4
  t: "node.start" | "node.end";
11
5
  path: string;
@@ -34,8 +28,6 @@ export type NodeLine = {
34
28
  error_truncated?: boolean;
35
29
  at: string;
36
30
  };
37
- /** The node log of the run at `root`, in order; a torn last line is left out. */
38
- export declare function readNodeLog(root: string): Promise<NodeLine[]>;
39
31
  /** The llm calls the node log says answered, in order: a run's `llmRead` counts them, and its cost reads the rest. */
40
32
  export declare const llmAnswers: (lines: readonly NodeLine[]) => {
41
33
  t: "effect.end";
@@ -55,14 +47,5 @@ export type LiveView = {
55
47
  pin: Record<string, unknown>;
56
48
  receipts: Array<Record<string, unknown>>;
57
49
  };
58
- /** The run's live view writer: `receipts` are the ones earlier processes recorded; `driver` is handed over once the
59
- * workflow's driver is open. It rewrites `live.json` every 300 ms while something changed, and once more at `stop`. */
60
- export declare function liveView(root: string, receipts: Array<Record<string, unknown>>): {
61
- driver(next: {
62
- pinJson(): string;
63
- }): void;
64
- receipt(receipt: Record<string, unknown>): void;
65
- stop(): void;
66
- };
67
50
  /** The live view of the run at `root`; undefined when its process wrote none, or it does not parse. */
68
51
  export declare function readLiveView(root: string): Promise<LiveView | undefined>;
package/dist/pause.js CHANGED
@@ -1,82 +1,13 @@
1
- // A workflow run's pause and its node log, both files in the run's directory beside serve.json.
1
+ // A workflow run's node log and live view, as the graph reads them.
2
2
  //
3
- // Pause: POST /v2/runs/{id}/pause writes the mark `paused`; resume removes it. The run's process gates each node's start,
4
- // each model call and each decision on it: what is in flight finishes, and nothing new starts while the mark is there.
5
- // The gate sits before the durable admission of a call and before a call node's deadline is armed, so a node waiting at
6
- // it was never booked and a kill while paused interrupts nothing. Being a file, a pause outlives the server and the run's
7
- // process.
3
+ // Node log: one line per node start and end and per call's start and end with its input and output (the runner's
4
+ // KINDS.nodeEffect entries), so GET /v2/runs/{id}/graph shows timings and call I/O while the run goes.
8
5
  //
9
- // Node log: `nodes.jsonl`, one JSON line per node start and end and per call's start and end with its input and output,
10
- // appended by the run's process as they happen, so GET /v2/runs/{id}/graph shows timings and call I/O while the run goes.
11
- //
12
- // Live view: `live.json`, the driver's frame and the run's decision receipts, rewritten whole by the run's process when
13
- // they change. The run's process holds its store exclusively (pi-durable-disk's exclusive profile: no other connection
14
- // reads it until the process exits), so this file is what GET /v2/runs/{id}/graph reads while the run goes.
15
- import { existsSync, renameSync, writeFileSync } from "node:fs";
6
+ // Live view: `live.json`, the driver's frame and the run's decision receipts, as GET /v2/runs/{id}/graph reads it.
16
7
  import { join } from "node:path";
17
- import { RUN_CANCELLED } from "./files.js";
18
- export const RUN_PAUSED = "paused";
19
- export const NODE_LOG = "nodes.jsonl";
20
- export const LIVE_VIEW = "live.json";
21
- const LIVE_MS = 300;
22
- const POLL_MS = 250;
23
- export const pausedIn = (root) => existsSync(join(root, RUN_PAUSED));
24
- /** `fn`, waiting before each call while the run at `root` is paused. A cancel, or the call's own signal aborting, lets
25
- * the call go to meet its abort. */
26
- export function gated(root, fn) {
27
- return async (params) => {
28
- const signal = params?.signal instanceof AbortSignal ? params.signal : undefined;
29
- while (pausedIn(root) && !existsSync(join(root, RUN_CANCELLED)) && !signal?.aborted)
30
- await new Promise((resolve) => setTimeout(resolve, POLL_MS));
31
- return fn(params);
32
- };
33
- }
34
- /** The node log of the run at `root`, in order; a torn last line is left out. */
35
- export async function readNodeLog(root) {
36
- const { readFile } = await import("node:fs/promises");
37
- const text = await readFile(join(root, NODE_LOG), "utf8").catch(() => "");
38
- const out = [];
39
- for (const line of text.split("\n")) {
40
- if (!line)
41
- continue;
42
- try {
43
- out.push(JSON.parse(line));
44
- }
45
- catch { }
46
- }
47
- return out;
48
- }
8
+ const LIVE_VIEW = "live.json";
49
9
  /** The llm calls the node log says answered, in order: a run's `llmRead` counts them, and its cost reads the rest. */
50
10
  export const llmAnswers = (lines) => lines.filter((line) => line.t === "effect.end" && line.tool === "llm" && line.status === "done");
51
- /** The run's live view writer: `receipts` are the ones earlier processes recorded; `driver` is handed over once the
52
- * workflow's driver is open. It rewrites `live.json` every 300 ms while something changed, and once more at `stop`. */
53
- export function liveView(root, receipts) {
54
- let driver;
55
- let last = "";
56
- const file = join(root, LIVE_VIEW);
57
- const write = () => {
58
- if (!driver)
59
- return;
60
- try {
61
- const text = `{"at":${JSON.stringify(new Date().toISOString())},"receipts":${JSON.stringify(receipts)},"pin":${driver.pinJson()}}`;
62
- // The time is left out of the comparison: an unchanged view is not written again.
63
- const same = text.slice(text.indexOf(',"receipts":'));
64
- if (same === last)
65
- return;
66
- writeFileSync(`${file}.tmp`, text, { mode: 0o600 });
67
- renameSync(`${file}.tmp`, file);
68
- last = same;
69
- }
70
- catch { }
71
- };
72
- const timer = setInterval(write, LIVE_MS);
73
- timer.unref();
74
- return {
75
- driver(next) { driver = next; write(); },
76
- receipt(receipt) { receipts.push(receipt); },
77
- stop() { clearInterval(timer); write(); },
78
- };
79
- }
80
11
  /** The live view of the run at `root`; undefined when its process wrote none, or it does not parse. */
81
12
  export async function readLiveView(root) {
82
13
  const { readFile } = await import("node:fs/promises");
@@ -3,6 +3,9 @@ import { createProvider } from "@earendil-works/pi-ai/models";
3
3
  import type { SessionPort } from "@parcha/agentrun-kernel";
4
4
  /** The provider id the port's one model is listed under. */
5
5
  export declare const PORT_PROVIDER = "agentrun-session";
6
+ /** The provider id a tier's port model is listed under (tieredModels): the run's model of that tier, on a proxy of its
7
+ * own beside the session's (AdapterSession.port's `tier`). */
8
+ export declare const tierProvider: (tier: string) => string;
6
9
  /** Where pi-ai's client of `api` is pointed to reach a session's proxy at `url`: Anthropic's SDK adds /v1/messages to its
7
10
  * base; OpenAI's adds /responses to a base that holds /v1. The one rule for the port's models and pi's own (runner
8
11
  * adapters/pi.ts). */
@@ -48,6 +51,10 @@ export type PortModels = {
48
51
  completeSimple(model: Model<Api>, context: Context, options?: SimpleStreamOptions): Promise<AssistantMessage>;
49
52
  };
50
53
  /** Models over `port` (the session's, read at each request: undefined until a drive has attached a proxy, and anew for
51
- * each drive), one model named by any provider and id: the session's own. `like`: the catalog's entry for the model the
52
- * run is priced by, whose reasoning, limits and price the port's model takes. */
53
- export declare function portModels(port: () => SessionPort | undefined, like?: Partial<Model<Api>>): Promise<PortModels>;
54
+ * each drive), one model named by any provider and id: the session's own, listed under `provider`. `like`: the
55
+ * catalog's entry for the model the run is priced by, whose reasoning, limits and price the port's model takes. */
56
+ export declare function portModels(port: () => SessionPort | undefined, like?: Partial<Model<Api>>, provider?: string): Promise<PortModels>;
57
+ /** Port models of several ports as one registry (learned-workflow.ts takes one): each listed under its own provider id
58
+ * (PORT_PROVIDER for the session's, tierProvider(tier) for a tier's), a model's request sent through the port it came
59
+ * from. */
60
+ export declare function tieredModels(byProvider: ReadonlyMap<string, PortModels>): PortModels;
@@ -3,6 +3,9 @@ import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.l
3
3
  import { createProvider } from "@earendil-works/pi-ai/models";
4
4
  /** The provider id the port's one model is listed under. */
5
5
  export const PORT_PROVIDER = "agentrun-session";
6
+ /** The provider id a tier's port model is listed under (tieredModels): the run's model of that tier, on a proxy of its
7
+ * own beside the session's (AdapterSession.port's `tier`). */
8
+ export const tierProvider = (tier) => `${PORT_PROVIDER}-${tier}`;
6
9
  /** Where pi-ai's client of `api` is pointed to reach a session's proxy at `url`: Anthropic's SDK adds /v1/messages to its
7
10
  * base; OpenAI's adds /responses to a base that holds /v1. The one rule for the port's models and pi's own (runner
8
11
  * adapters/pi.ts). */
@@ -43,9 +46,9 @@ export function sessionProvider(api, proxy, model, options) {
43
46
  });
44
47
  }
45
48
  /** Models over `port` (the session's, read at each request: undefined until a drive has attached a proxy, and anew for
46
- * each drive), one model named by any provider and id: the session's own. `like`: the catalog's entry for the model the
47
- * run is priced by, whose reasoning, limits and price the port's model takes. */
48
- export async function portModels(port, like) {
49
+ * each drive), one model named by any provider and id: the session's own, listed under `provider`. `like`: the
50
+ * catalog's entry for the model the run is priced by, whose reasoning, limits and price the port's model takes. */
51
+ export async function portModels(port, like, provider = PORT_PROVIDER) {
49
52
  const [{ createModels, createProvider }, { anthropicMessagesApi }, { openAIResponsesApi }] = await Promise.all([
50
53
  import("@earendil-works/pi-ai/models"),
51
54
  import("@earendil-works/pi-ai/api/anthropic-messages.lazy"),
@@ -64,15 +67,15 @@ export async function portModels(port, like) {
64
67
  // The side key as the proxy reads a key (a bearer token), and no beta header pi-ai would add of its own: the session's
65
68
  // policy admits the betas its harness sends, and these requests need none.
66
69
  const headers = { authorization: `Bearer ${now.key}`, ...(now.api === "anthropic-messages" ? { "anthropic-beta": null } : {}) };
67
- const model = sessionModel(now.api, now.url, now.model, { provider: PORT_PROVIDER, headers, ...(like ? { like } : {}), reasoning: true });
70
+ const model = sessionModel(now.api, now.url, now.model, { provider, headers, ...(like ? { like } : {}), reasoning: true });
68
71
  const models = createModels({});
69
72
  models.setProvider(createProvider({
70
- id: PORT_PROVIDER, baseUrl,
73
+ id: provider, baseUrl,
71
74
  auth: { apiKey: { name: "the session's side key", resolve: async () => ({ auth: { apiKey: now.key }, source: "session" }) } },
72
75
  models: [model],
73
76
  api: now.api === "anthropic-messages" ? anthropicMessagesApi() : openAIResponsesApi(),
74
77
  }));
75
- built = { at, models, model: models.getModel(PORT_PROVIDER, now.model) };
78
+ built = { at, models, model: models.getModel(provider, now.model) };
76
79
  return built;
77
80
  };
78
81
  const registry = (model) => {
@@ -91,3 +94,20 @@ export async function portModels(port, like) {
91
94
  completeSimple: (model, context, options) => registry(model).completeSimple(model, context, options),
92
95
  };
93
96
  }
97
+ /** Port models of several ports as one registry (learned-workflow.ts takes one): each listed under its own provider id
98
+ * (PORT_PROVIDER for the session's, tierProvider(tier) for a tier's), a model's request sent through the port it came
99
+ * from. */
100
+ export function tieredModels(byProvider) {
101
+ const of = (model) => {
102
+ const port = byProvider.get(model.provider);
103
+ if (!port)
104
+ throw new Error(`no port of the run lists the model ${model.provider}/${model.id}`);
105
+ return port;
106
+ };
107
+ return {
108
+ getModel: (provider, id) => byProvider.get(provider)?.getModel(provider, id),
109
+ getModels: () => [...byProvider.values()].flatMap((port) => port.getModels()),
110
+ streamSimple: (model, context, options) => of(model).streamSimple(model, context, options),
111
+ completeSimple: (model, context, options) => of(model).completeSimple(model, context, options),
112
+ };
113
+ }
package/dist/propose.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { DraftAsk } from "./learn/skills.js";
1
2
  import { type Problem } from "./learn/index.js";
2
3
  import { type Turn } from "./learning.js";
3
4
  import type { Workspace } from "./workspace/index.js";
@@ -38,4 +39,5 @@ export declare const proposeRun: (input: {
38
39
  tools?: readonly string[];
39
40
  gated?: Readonly<Record<string, string>>;
40
41
  deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
42
+ ask?: DraftAsk;
41
43
  }) => Promise<Proposed>;
package/dist/propose.js CHANGED
@@ -1,12 +1,3 @@
1
- // Learning, after a run: the notes its end-of-run turn answered with, and a skill or a workflow draft beside them, are read
2
- // by the host (learn/reflect.ts parseReflection), checked against the commit the run started from (learn/check.ts
3
- // checkProposal), and kept as its proposal (`learning-proposal.json`, in the directory the caller gives), or dropped. The
4
- // answer is what the runner's end-of-run turn read from the run's store (runner/learning-end.ts), never the run's work;
5
- // and no file the run wrote is read at all, in `.learning/` or anywhere. The seed is
6
- // read from the agent's learning folder through its Workspace, as the reflect hook's check reads it (learn/seed-check.ts):
7
- // the snapshot and its bodies when main is the seed (no exec), else one read-only exec of the learning script at that
8
- // commit. Nothing is written to git here, and nothing is written at all before the checks pass: what they refuse (a
9
- // note holding a secret among them) is never kept anywhere.
10
1
  import { join } from "node:path";
11
2
  import { checkProposal, draftDryRun, draftFiles, NOTE_BLOCK, unstorable, parseReflection, redactSecrets, shortMessage, SKILL_BLOCK, SKILLS_DIR, WORKFLOW_BLOCK, WORKFLOWS_DIR } from "./learn/index.js";
12
3
  import { folderAt, readLearning, readSnapshot } from "./learn/folder.js";
@@ -129,7 +120,7 @@ export const proposeRun = async (input) => {
129
120
  return { state: "dropped", reason: "checker", problems: leaky };
130
121
  // A skill or a draft whose seed text has a status is a person's call (retired, or waiting for their OK): never changed.
131
122
  const dryRuns = {};
132
- const check = (some) => checkProposal({ base, changes: some, refuseValues: input.refuse, ...(kept.length ? { kept } : {}), ...(input.outcome === undefined ? {} : { outcome: input.outcome }), ...(input.tools ? { tools: input.tools } : {}), ...(input.gated ? { gated: input.gated } : {}), ...(input.deniedBy ? { deniedBy: input.deniedBy } : {}), ...(dsl ? { dsl, dryRuns } : {}) });
123
+ const check = (some) => checkProposal({ base, changes: some, refuseValues: input.refuse, ...(kept.length ? { kept } : {}), ...(input.outcome === undefined ? {} : { outcome: input.outcome }), ...(input.tools ? { tools: input.tools } : {}), ...(input.gated ? { gated: input.gated } : {}), ...(input.deniedBy ? { deniedBy: input.deniedBy } : {}), ...(input.ask ? { ask: input.ask } : {}), ...(dsl ? { dsl, dryRuns } : {}) });
133
124
  // The static checks first, every one (validateWorkflow with executeCode: false, draftProblems' refusal of code nodes,
134
125
  // caps, secrets): a draft they refuse is never dry-run, nor is any when they refuse the answer whole. Then each draft
135
126
  // left is dry-run on its example, else on a synthesized input (learn/skills.ts draftDryRun): every model and tool
@@ -44,9 +44,10 @@ export interface RunLaunch {
44
44
  * # Learned text to lay into the prompt for those notes (what the old layLearned laid), within the learning budget; and
45
45
  * `seedNotes`, the count of all notes in the seed before the budget picked `given` (present with a read seed; absent when
46
46
  * the seed could not be read); `skills`, the names of the learned skills the seed offers the run (each active one that
47
- * fits a run's skill budget at all; its claim lays them), absent when none; `gradeModel`, the model the server names
48
- * to grade what the run proposes (learning.ts gradeModelOf: --grade-model, else AGENTRUN_SERVE_GRADE_MODEL, else
49
- * AGENT_MODEL_STRONG), absent when it names none and the agent's own grades it; and `seedFailed`, why it starts with
47
+ * fits a run's skill budget at all; its claim lays them), absent when none; `workflows`, the names of the learned
48
+ * workflows the seed offers its learned_workflow tool (chooseWorkflows), absent when none; `gradeModel`, the model the
49
+ * server names to grade what the run proposes (learning.ts gradeModelOf: --grade-model, else AGENTRUN_SERVE_GRADE_MODEL,
50
+ * else AGENT_MODEL_STRONG), absent when it names none and the agent's own grades it; and `seedFailed`, why it starts with
50
51
  * nothing learned when it does (SeedFailed). Absent when the run does not learn. */
51
52
  readonly learning?: {
52
53
  readonly given: readonly {
@@ -57,6 +58,7 @@ export interface RunLaunch {
57
58
  readonly section: string;
58
59
  readonly seedNotes?: number;
59
60
  readonly skills?: readonly string[];
61
+ readonly workflows?: readonly string[];
60
62
  readonly gradeModel?: string;
61
63
  readonly seedFailed?: SeedFailed;
62
64
  };
@@ -56,23 +56,24 @@ export function launchBody(launch) {
56
56
  ...(launch.boxAllow !== undefined ? { box_allow: launch.boxAllow } : {}),
57
57
  ...(launch.boxAllowSet ? { box_allow_set: true } : {}),
58
58
  ...(launch.files?.length ? { files: launch.files } : {}),
59
- ...(launch.learning ? { learning: { given: launch.learning.given.map((note) => ({ file: note.file, name: note.name })), seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.seedNotes !== undefined ? { seedNotes: launch.learning.seedNotes } : {}), ...(launch.learning.skills?.length ? { skills: [...launch.learning.skills] } : {}), ...(launch.learning.gradeModel ? { gradeModel: launch.learning.gradeModel } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}) } } : {}),
59
+ ...(launch.learning ? { learning: { given: launch.learning.given.map((note) => ({ file: note.file, name: note.name })), seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.seedNotes !== undefined ? { seedNotes: launch.learning.seedNotes } : {}), ...(launch.learning.skills?.length ? { skills: [...launch.learning.skills] } : {}), ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.gradeModel ? { gradeModel: launch.learning.gradeModel } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}) } } : {}),
60
60
  ...(launch.trigger ? { trigger: launch.trigger } : {}),
61
61
  ...(launch.inputOrigin ? { input_origin: launch.inputOrigin } : {}),
62
62
  ...(launch.followUp ? { follow_up: true } : {}),
63
63
  };
64
64
  }
65
65
  /** The learning start a launch body names, as read back: its given notes (each {file, name}), its seed sha, its # Learned
66
- * section text, the learned skills it was offered, its grade model and why its seed failed, or undefined when the body
67
- * names none (a run that does not learn). */
66
+ * section text, the learned skills and workflows it was offered, its grade model and why its seed failed, or undefined
67
+ * when the body names none (a run that does not learn). */
68
68
  function readLearning(value) {
69
69
  if (!isObject(value))
70
70
  return undefined;
71
71
  const given = Array.isArray(value.given) ? value.given.flatMap((note) => (isObject(note) && typeof note.file === "string" && typeof note.name === "string" ? [{ file: note.file, name: note.name }] : [])) : [];
72
72
  const seed = typeof value.seed === "string" ? value.seed : null;
73
73
  const section = typeof value.section === "string" ? value.section : "";
74
- const skills = Array.isArray(value.skills) ? value.skills.filter((name) => typeof name === "string") : [];
75
- return { given, seed, section, ...(typeof value.seedNotes === "number" ? { seedNotes: value.seedNotes } : {}), ...(skills.length ? { skills } : {}), ...(typeof value.gradeModel === "string" && value.gradeModel !== "" ? { gradeModel: value.gradeModel } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}) };
74
+ const names = (list) => (Array.isArray(list) ? list.filter((name) => typeof name === "string") : []);
75
+ const [skills, workflows] = [names(value.skills), names(value.workflows)];
76
+ return { given, seed, section, ...(typeof value.seedNotes === "number" ? { seedNotes: value.seedNotes } : {}), ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...(typeof value.gradeModel === "string" && value.gradeModel !== "" ? { gradeModel: value.gradeModel } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}) };
76
77
  }
77
78
  /** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
78
79
  * undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
@@ -36,6 +36,17 @@ export declare function servedRunLearning(deps: {
36
36
  tokens: {
37
37
  grade: import("./learning.js").Tokens | null;
38
38
  };
39
+ used: {
40
+ skills: {
41
+ name: string;
42
+ read: boolean;
43
+ }[];
44
+ workflows: {
45
+ name: string;
46
+ calls: number;
47
+ failed: number;
48
+ }[];
49
+ };
39
50
  given?: import("./learning.js").NoteUsed[];
40
51
  read?: import("./learning.js").NoteUsed[];
41
52
  learned?: import("./learning.js").NoteLearned[];
@@ -3,6 +3,7 @@ import type { TimelineEvent } from "./timeline/index.js";
3
3
  import type { IncomingMessage, ServerResponse } from "node:http";
4
4
  import { type Page } from "./rows.js";
5
5
  import { type FileView } from "./run-files.js";
6
+ import type { RunStated } from "./store-view.js";
6
7
  import { type Store } from "./store/index.js";
7
8
  import type { Workspace } from "./workspace/index.js";
8
9
  /** The most files a list answers with (server.ts FILE_LIST_CAP). */
@@ -23,8 +24,9 @@ export interface RunReadsDeps {
23
24
  liveViewer?(runId: string): Promise<{
24
25
  viewer: string;
25
26
  } | undefined>;
26
- /** The run's v2 view as the store serves it (viewOverStore): its status, kind, revision and times, for the graph. */
27
- runView(store: RunReadsStore, runId: string): Promise<Record<string, unknown> | undefined>;
27
+ /** The run's facts (store-view.ts factsOverStore): its status, kind, revision, times and whether it is withheld, for the
28
+ * graph, with no word of the run served, so a graph read redacts nothing outside its own cached parts. */
29
+ runFacts(store: RunReadsStore, runId: string): Promise<RunStated | undefined>;
28
30
  /** Whether the run's served output is withheld: its browser sign-in can't be read, so nothing it said is shown
29
31
  * (store-view's `unshown`). The graph refuses when it is, as the route did. */
30
32
  withheld(store: RunReadsStore, runId: string): Promise<boolean>;
@@ -68,17 +68,19 @@ const graphParts = new PartCache(GRAPH_CACHE_BYTES);
68
68
  * runGraph, the store path). An agentic run has none (404, the route's words); a run whose output is withheld is refused
69
69
  * (403 WITHHELD_SIGN_IN), as the route refused it, before anything of it is served. */
70
70
  export async function runGraphView(store, runId, deps) {
71
- const view = await deps.runView(store, runId);
72
- if (!view)
71
+ // The run's facts, never its served view: the view serves the run's words (its output, its title), each a redaction
72
+ // pass on every read, and the graph needs none of them. Its own parts are redacted once per held set (servedGraphView).
73
+ const facts = await deps.runFacts(store, runId);
74
+ if (!facts)
73
75
  throw new ApiError("not_found", `There is no run ${runId}.`);
74
- if (view.kind !== "workflow")
76
+ if (facts.kind !== "workflow")
75
77
  throw new ApiError("not_found", `the run ${runId} is an agentic run; only a workflow run has a graph`);
76
- if (await deps.withheld(store, runId))
78
+ if (facts.unshown)
77
79
  throw new ApiError("forbidden", WITHHELD_SIGN_IN);
78
- const revision = await store.agents.revision(String(view.revision));
80
+ const revision = await store.agents.revision(facts.revision);
79
81
  const workflow = revision?.body?.workflow;
80
- const status = String(view.status);
81
- const ended = view.ended_at !== null;
82
+ const status = facts.status;
83
+ const ended = facts.endedAt !== null;
82
84
  const launch = await store.runs.launch(runId).then((row) => readLaunchBody(row.body), (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
83
85
  // The run's model-node cost from its rows once it ended (0 before), as the old graph read it from run.rows: a workflow's
84
86
  // usage row is its booking's (store-reads/journal.ts bookedUsage), its model nodes', its `llm` calls' and its paid
@@ -92,7 +94,7 @@ export async function runGraphView(store, runId, deps) {
92
94
  if (cut === "unreadable")
93
95
  throw new ApiError("forbidden", WITHHELD_SIGN_IN);
94
96
  return servedGraphView(await runGraph({
95
- run: { id: runId, agent: String(view.agent_id), revision: String(view.revision), status, paused: status === "paused", startedAt: String(view.created_at), endedAt: view.ended_at },
97
+ run: { id: runId, agent: facts.agentId, revision: facts.revision, status, paused: status === "paused", startedAt: facts.createdAt, endedAt: facts.endedAt },
96
98
  ended,
97
99
  workflow,
98
100
  // No run directory now: the store and a context carry the journal the graph reads.