@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
@@ -1,5 +1,5 @@
1
- import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, frontMatter, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, statusOnOneLine, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR } from "./learn/index.js";
2
- import { beforeRetire, blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
1
+ import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR, restorable, restore, restoredLearned } from "./learn/index.js";
2
+ import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, heldOnMain, isBodyMismatch, readLearning, PATCH_CAP, readRunDiff, readSnapshot, snapshotNotes, writeLearning } from "./learn/folder.js";
3
3
  import { ApiError, invalid } from "./errors.js";
4
4
  import { detailShown, learningFolderOf, notesView, reasonShown, secretsShown, withAgentRepo } from "./learning.js";
5
5
  import { isObject } from "./validate.js";
@@ -11,7 +11,8 @@ const NOTES_PAGE = 50;
11
11
  const LOG_PAGE = 20;
12
12
  const PAGE_MAX = 200;
13
13
  /** What a retire adds to a note, on top of the note cap a retired note may fill (learn/notes.ts retire). */
14
- const RETIRED_LINE = Buffer.byteLength("status: retired\n");
14
+ /** What a retire adds to a note: its status line and the status it took it from (the longer of the two). */
15
+ const RETIRED_LINE = Buffer.byteLength("status: retired\nretired_from: pending\n");
15
16
  export { secretsShown } from "./learning.js";
16
17
  /** The few values last kept, by key, oldest dropped first: at most `entries` of them. */
17
18
  class Recent {
@@ -70,14 +71,16 @@ async function reading(data, agentId, read, none) {
70
71
  }
71
72
  /** A retired item's `retired`: its newest retire by a person; else, one a person made retired another way (an edit to
72
73
  * status: retired, or created so), their newest change; else (retired by none of theirs) its newest change's time. */
73
- const retiredOf = (history) => (history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" });
74
+ /** `from`: the status its restore gives back (its retire recorded it, retired_from; none recorded reads pending, as its
75
+ * restore gives it: only an approval makes an item active). */
76
+ const retiredOf = (history, from) => ({ ...(history.retire ? { at: history.retire.at, by: "person" } : history.person ? { at: history.person.at, by: "person" } : { at: history.at, by: "run" }), from: from ?? "pending" });
74
77
  /** A note as the view shows it, cut of the host's secrets: its name and the one that superseded it whole; with its
75
78
  * ETag, the one its file's GET answers, so an edit or a retire from the card names the version it shows; its last
76
79
  * change, and when and by whom it was retired on a retired one. */
77
80
  const noteView = (note, text, shown, runs) => ({
78
81
  file: shown.name(note.file), name: shown.text(note.name), description: shown.text(note.description), type: note.type, status: note.status, origin: note.origin, superseded_by: note.superseded_by === null ? null : shown.name(note.superseded_by), text: shown.text(text), etag: etagOf(note.oid), runs: { ...(runs.get(note.file) ?? { given: 0, read: 0 }) },
79
82
  ...(note.history.last ? { last_change: note.history.last } : {}),
80
- ...(note.status === "retired" ? { retired: retiredOf(note.history) } : {}),
83
+ ...(note.status === "retired" ? { retired: retiredOf(note.history, note.retired_from) } : {}),
81
84
  });
82
85
  function learnedView(item, kind, shown) {
83
86
  const file = kind === "skill" ? item.file : `${WORKFLOWS_DIR}/${item.name}/workflow.json`;
@@ -85,7 +88,7 @@ function learnedView(item, kind, shown) {
85
88
  return {
86
89
  name: shown.name(item.name), file: shown.name(file), ...(kind === "workflow" ? { readme: shown.name(item.file) } : {}), description: shown.text(item.description), status: item.status, run: item.run, bytes, etag: etagOf(item.oid),
87
90
  ...(item.history.last ? { last_change: item.history.last } : {}),
88
- ...(item.status === "retired" ? { retired: retiredOf(item.history) } : {}),
91
+ ...(item.status === "retired" ? { retired: retiredOf(item.history, item.retired_from) } : {}),
89
92
  };
90
93
  }
91
94
  /** A change on main as the log shows it, cut of the host's secrets. */
@@ -363,12 +366,20 @@ export async function writeNote(data, agentId, raw, input) {
363
366
  }
364
367
  let text = given;
365
368
  // A note that waits for its owner's OK is made active by an approval alone: an edit keeps it waiting, so one that
366
- // drops or changes its status is refused, whoever sends it.
369
+ // drops or changes its status is refused, whoever sends it. A retired note comes back by its restore alone, to the
370
+ // status its retire recorded: an edit keeps it retired and keeps that record (retired_from) as it is.
367
371
  if (given !== undefined && current) {
368
372
  const was = parseNoteFile(file, current.text);
369
373
  const now = parseNoteFile(file, given);
370
374
  if (!Array.isArray(was) && was.status === "pending" && !Array.isArray(now) && now.status !== "pending")
371
375
  throw refused([printable({ rule: "status", path: file, detail: "it waits for its owner's OK: an edit keeps status: pending, only an approval makes it active, and a retire takes it out" }, input.refuse)]);
376
+ if (!Array.isArray(was) && was.status === "retired" && !Array.isArray(now)) {
377
+ const kept = was.retired_from ?? "pending";
378
+ if (now.status !== "retired" || (now.keys.includes("retired_from") && now.retired_from !== kept))
379
+ throw refused([printable({ rule: "status", path: file, detail: `it is retired: an edit keeps status: retired and retired_from: ${kept}, and only its restore brings it back, as it was before its retire` }, input.refuse)]);
380
+ // What its retire recorded is the host's: the edit carries it, written or not.
381
+ text = retire(given, kept);
382
+ }
372
383
  }
373
384
  // Beside the note itself: what an approve marks of the notes the approved one supersedes.
374
385
  const also = new Map();
@@ -379,24 +390,24 @@ export async function writeNote(data, agentId, raw, input) {
379
390
  if (notes.get(old)?.status === "active")
380
391
  also.set(old, supersede(await body(old, noteOid(old)), file));
381
392
  };
382
- let heldBefore = false;
383
393
  if (input.restore) {
384
- // Restored, a retired note, skill or draft is active again: given to every later run. It is checked again as a
385
- // new one is (secrets' shapes, the host's values, hidden characters, its format, every file of a skill's or a
386
- // draft's folder): a retire takes a leaking one out of every run unchecked, and a restore never brings it back.
387
- // One that waited for its owner's OK before its retire is recorded as their approval too (Approved-Via).
388
- const before = await beforeRetire(ws, main, file);
389
- heldBefore = before !== undefined && (learned ? learnedStatus(before) === "pending" : ((note) => !Array.isArray(note) && note.status === "pending")(parseNoteFile(file, before)));
394
+ // Restored, a retired note, skill or draft goes back to the status its retire recorded (retired_from): active, so
395
+ // given to every later run, or waiting for its owner's OK again, so a retire and a restore never skip that OK
396
+ // (a retire that recorded none restores it waiting). It is checked again as a new one is (secrets' shapes, the
397
+ // host's values, hidden characters, its format, every file of a skill's or a draft's folder): a retire takes a
398
+ // leaking one out of every run unchecked, and a restore never brings it back. A restore is never an approval.
390
399
  if (learned) {
391
400
  const status = learnedStatus(current.text);
392
401
  const kind = learned.kind === "skill" ? "skill" : "workflow";
393
402
  if (status !== "retired")
394
403
  throw new ApiError("bad_request", `The ${kind} is not retired: it is ${status}.`);
395
- // Read as retired since its front matter reads no way, or its status is set on more than one line, which no
396
- // writer edits (learnedStatus): refused until it is written so it does.
397
- if (!frontMatter(current.text) || !statusOnOneLine(current.text))
404
+ // Read as retired since its front matter reads no way, or its status (or the retired_from its retire recorded) is
405
+ // set on more than one line, which no writer edits (learnedStatus, restorable): refused until it is written so.
406
+ if (!restorable(current.text))
398
407
  throw refused([printable({ rule: kind, path: file, detail: UNCLEAR_FRONT }, input.refuse)]);
399
- text = released(current.text);
408
+ // Back to the status its retire recorded (restoredLearned: retired_from, read by the one reader), never active
409
+ // unless it was active: a held skill or draft waits for its owner's OK again.
410
+ text = restoredLearned(current.text);
400
411
  const problems = skillProblems(text, learned.name).map((detail) => printable({ rule: kind, path: file, detail }, input.refuse));
401
412
  const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
402
413
  if (extra.length)
@@ -409,9 +420,9 @@ export async function writeNote(data, agentId, raw, input) {
409
420
  // a restore never brings back a draft no run could run.
410
421
  const draft = changes.find(({ path }) => path === `${folder}workflow.json`);
411
422
  if (learned.kind !== "skill" && draft && input.draftTools) {
412
- const { tools, gated } = await input.draftTools();
423
+ const { tools, gated, deniedBy, ask } = await input.draftTools();
413
424
  const dsl = await import("@parcha/agentrun-dsl");
414
- for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated))
425
+ for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated, deniedBy ?? {}, ask))
415
426
  problems.push(printable({ rule, path: draft.path, detail }, input.refuse));
416
427
  }
417
428
  if (problems.length)
@@ -423,12 +434,14 @@ export async function writeNote(data, agentId, raw, input) {
423
434
  throw refused(note.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
424
435
  if (note.status !== "retired")
425
436
  throw new ApiError("bad_request", `The note is not retired: it is ${note.status}.`);
426
- text = approve(current.text);
437
+ text = restore(current.text, note);
427
438
  const { problems } = checkNote(file, Buffer.from(text, "utf8"), input.refuse);
428
439
  if (problems.length)
429
440
  throw refused(problems);
430
- // What it supersedes, and is active still, is superseded now, as an approval marks it.
431
- await mark(note.supersedes);
441
+ // Back active, what it supersedes, and is active still, is superseded now, as an approval marks it; back
442
+ // waiting, it supersedes nothing until it is approved.
443
+ if (note.retired_from === "active")
444
+ await mark(note.supersedes);
432
445
  }
433
446
  }
434
447
  else if (text === undefined && learned && !input.approve) {
@@ -465,13 +478,13 @@ export async function writeNote(data, agentId, raw, input) {
465
478
  // A retire is how a person takes a note out of every later run's prompt, a leaking one above all, so it always
466
479
  // can: only the note's format is checked as retired (its front matter parses, and it fits the note cap with the
467
480
  // status line added), never a secret in its name or text. Every answer cuts those as any read does.
468
- text = retire(current.text);
481
+ text = retire(current.text, note.status === "pending" ? "pending" : "active");
469
482
  const retired = parseNoteFile(file, text);
470
483
  if (Array.isArray(retired))
471
484
  throw refused(retired.map((detail) => printable({ rule: "note", path: file, detail }, input.refuse)));
472
485
  const size = Buffer.byteLength(text);
473
486
  if (size > CAPS.note + RETIRED_LINE)
474
- throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status line a retire adds` }, input.refuse)]);
487
+ throw refused([printable({ rule: "too_large", path: file, detail: `${size} bytes as retired; the cap is ${CAPS.note}, and the status lines a retire adds` }, input.refuse)]);
475
488
  }
476
489
  if (current && text === current.text)
477
490
  return { result: { status: 200, file, text, etag: etagOf(current.oid) } };
@@ -482,7 +495,7 @@ export async function writeNote(data, agentId, raw, input) {
482
495
  const kind = input.approve ? "approved" : input.restore ? "restored" : given === undefined ? "retired" : current ? "edited" : "created";
483
496
  const change = {
484
497
  // Who approved, and how, in the trailers; the commit's own date is when. Never the note's text.
485
- by: { person: kind, file, approved: Boolean(input.approve || heldBefore) },
498
+ by: { person: kind, file, approved: Boolean(input.approve) },
486
499
  writes: [{ path: file, text: text }, { path: INDEX_FILE, text: buildIndex(after) }, ...[...also].map(([path, marked]) => ({ path, text: marked }))],
487
500
  // A create takes a name main holds nothing by, as git holds it: a file the notes leave out included.
488
501
  ...(current ? {} : { absent: [file] }),
@@ -503,6 +516,55 @@ export async function writeNote(data, agentId, raw, input) {
503
516
  }
504
517
  });
505
518
  }
519
+ /** POST /agents/{id}/learning/workflows/{name}/promote's read of the learned workflow `raw` (percent-encoded) on agent
520
+ * `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
521
+ * person retired, is 409 learned_not_active: a promotion never runs what the owner has not let every run use. Each of
522
+ * its files is checked again as a restore checks it (unstorable: a secret's shape, the host's values as they are now,
523
+ * a hidden character), and its workflow.json as the learning checker checks a run's draft against the agent's tools and
524
+ * its gate (draftProblems: the DSL's validation with no code run, no code node, no shell or executor call, no call node
525
+ * on a tool the agent does not have or the gate holds to ask or deny). Any of those is 400 with `problems`, printable.
526
+ * Reads only: the folder is never written. */
527
+ export async function promotable(data, agentId, raw, input) {
528
+ let name;
529
+ try {
530
+ name = decodeURIComponent(raw);
531
+ }
532
+ catch {
533
+ throw new ApiError("bad_request", "the workflow's name is not percent-encoded right");
534
+ }
535
+ if (!learnedName("workflow", name))
536
+ throw new ApiError("bad_request", "A learned workflow's folder is named with lowercase letters, digits, dashes and underscores.");
537
+ const found = await reading(data, agentId, async ({ snapshot, body }) => {
538
+ const item = snapshot.workflows.find((one) => one.name === name);
539
+ if (!item)
540
+ return undefined;
541
+ if (item.status !== "active")
542
+ return { item, files: [] };
543
+ return { item, files: await Promise.all(item.files.map(async ({ path, oid }) => ({ path, text: await body(path, oid) }))) };
544
+ }, () => undefined);
545
+ if (!found)
546
+ throw new ApiError("not_found", "the agent's learning folder has no such workflow on main");
547
+ const { item, files } = found;
548
+ if (item.status === "pending")
549
+ throw new ApiError("learned_not_active", "This workflow waits for your OK: approve it first. Making it an agent never skips your OK.");
550
+ if (item.status !== "active")
551
+ throw new ApiError("learned_not_active", "This workflow is retired: restore it first to make it an agent.");
552
+ const file = `${WORKFLOWS_DIR}/${name}/workflow.json`;
553
+ const json = files.find(({ path }) => path === file);
554
+ const problems = unstorable(files.map(({ path, text }) => ({ path, status: "modified", bytes: Buffer.from(text, "utf8") })), input.refuse);
555
+ if (!json)
556
+ problems.push(printable({ rule: "workflow", path: file, detail: "the workflow's folder holds no workflow.json" }, input.refuse));
557
+ const dsl = await import("@parcha/agentrun-dsl");
558
+ if (json && !problems.length) {
559
+ const { tools, gated, deniedBy } = await input.draftTools();
560
+ for (const { rule, detail } of draftProblems(dsl, json.text, tools, gated, deniedBy ?? {}))
561
+ problems.push(printable({ rule, path: file, detail }, input.refuse));
562
+ }
563
+ if (problems.length)
564
+ throw new ApiError("bad_request", `The workflow does not pass the checks: ${[...new Set(problems.map((problem) => problem.rule))].join(", ")}.`, { problems });
565
+ const workflow = JSON.parse(json.text);
566
+ return { name, description: item.description, workflow, calls: dsl.inspectWorkflow(workflow).requires.tools };
567
+ }
506
568
  /** GET /runs/{id}/learning's body, from the run's learning as it reads now, the seed it started from and whether it
507
569
  * settled: the one shape, read from the one store (store-reads/learning.ts
508
570
  * runLearningOverStore). */
@@ -525,6 +587,12 @@ export function runLearningBody(input, shown, secrets) {
525
587
  // The grade's alone: the end-of-run turn's cost is in the run's own totals.
526
588
  cost_usd: { grade: cost_usd?.grade ?? null },
527
589
  tokens: { grade: tokens?.grade ?? null },
590
+ // What the job did with the learned skills and workflows it was offered (store-reads/learning.ts learnedUseOf), apart
591
+ // from the skills and workflows it learned (notesView's), each name cut of the host's secrets as a note's is.
592
+ used: {
593
+ skills: (input.used?.skills ?? []).map(({ name, read }) => ({ name: shown.name(name), read })),
594
+ workflows: (input.used?.workflows ?? []).map(({ name, calls, failed }) => ({ name: shown.name(name), calls, failed })),
595
+ },
528
596
  };
529
597
  }
530
598
  /** `text`, an added file, as git's unified diff writes it, hunks only. */
@@ -43,8 +43,7 @@ export type Impact = {
43
43
  after: ImpactSide;
44
44
  } | null;
45
45
  /** Each note's count of runs that were given it and that read it, by its file, over runs' note files (usage.ts
46
- * notesOf, lineNotesOf): a held run's from its learning, an ended one's from its ledger line. A run counts a note
47
- * once each way. */
46
+ * notesOf). A run counts a note once each way. */
48
47
  export declare function noteRuns(runs: readonly (NoteFiles | null | undefined)[]): NoteRuns;
49
48
  /** What a run's learning tells its impact (learning-run.ts ofAgent), from memory or from its ledger line: how it
50
49
  * ended and when, how many notes it started from, when its answer was final and its costs; `grade_usd` once it ended
@@ -54,15 +53,18 @@ export type ImpactLearning = {
54
53
  reason: string | null;
55
54
  at: string;
56
55
  seed_notes?: number;
56
+ seed_skills?: number;
57
+ seed_workflows?: number;
57
58
  answered_at?: string;
58
59
  job_cost_usd?: number | null;
59
60
  look_back_usd?: number | null;
60
61
  grade_usd?: number | null;
61
62
  };
62
63
  /** What learning changed for an agent, from its run rows (`rows`) and what its runs' learning says (`learningOf`),
63
- * never a run's files. `after`: its completed agentic runs that started from at least one active note. `before`: its
64
- * completed agentic runs that started before its first note, the earlier of its first merge's end and the start of its
65
- * first run that started from a note (a person's note comes first that way); none of them could have. Each side's
64
+ * never a run's files. `after`: its completed agentic runs that started from at least one learned item: an active note,
65
+ * a learned skill it was offered or a learned workflow its learned_workflow tool could run (seededItems). `before`: its
66
+ * completed agentic runs that started before its first item, the earlier of its first merge's end and the start of its
67
+ * first run that started from one (a person's note comes first that way); none of them could have. Each side's
66
68
  * figures (sideOf, figuresOf): its time to the answer in seconds to a tenth, its job's own cost, what learning cost.
67
69
  * An imported or archived run is on neither side, nor is a later one with learning off or seeded with no note (every
68
70
  * note retired), nor one whose learning predates these figures. Null unless both sides hold 2 runs or more. */
@@ -71,8 +71,7 @@ export function learningStats(rows, filter, learningOf) {
71
71
  return out;
72
72
  }
73
73
  /** Each note's count of runs that were given it and that read it, by its file, over runs' note files (usage.ts
74
- * notesOf, lineNotesOf): a held run's from its learning, an ended one's from its ledger line. A run counts a note
75
- * once each way. */
74
+ * notesOf). A run counts a note once each way. */
76
75
  export function noteRuns(runs) {
77
76
  const out = new Map();
78
77
  for (const files of runs) {
@@ -88,6 +87,9 @@ export function noteRuns(runs) {
88
87
  }
89
88
  return out;
90
89
  }
90
+ /** How many learned items a run started from: its notes, the learned skills it was offered and the learned workflows its
91
+ * learned_workflow tool could run. */
92
+ const seededItems = (learning) => (learning?.seed_notes ?? 0) + (learning?.seed_skills ?? 0) + (learning?.seed_workflows ?? 0);
91
93
  /** The middle of `values` (the mean of the two middle ones when there is an even count); undefined for none. */
92
94
  const median = (values) => {
93
95
  if (!values.length)
@@ -123,15 +125,16 @@ function figuresOf(row, learning) {
123
125
  return { seconds: (answered - Date.parse(row.startedAt)) / 1000, cost, learning: typeof back === "number" && typeof grade === "number" ? back + grade : null };
124
126
  }
125
127
  /** What learning changed for an agent, from its run rows (`rows`) and what its runs' learning says (`learningOf`),
126
- * never a run's files. `after`: its completed agentic runs that started from at least one active note. `before`: its
127
- * completed agentic runs that started before its first note, the earlier of its first merge's end and the start of its
128
- * first run that started from a note (a person's note comes first that way); none of them could have. Each side's
128
+ * never a run's files. `after`: its completed agentic runs that started from at least one learned item: an active note,
129
+ * a learned skill it was offered or a learned workflow its learned_workflow tool could run (seededItems). `before`: its
130
+ * completed agentic runs that started before its first item, the earlier of its first merge's end and the start of its
131
+ * first run that started from one (a person's note comes first that way); none of them could have. Each side's
129
132
  * figures (sideOf, figuresOf): its time to the answer in seconds to a tenth, its job's own cost, what learning cost.
130
133
  * An imported or archived run is on neither side, nor is a later one with learning off or seeded with no note (every
131
134
  * note retired), nor one whose learning predates these figures. Null unless both sides hold 2 runs or more. */
132
135
  export function learningImpact(rows, learningOf) {
133
136
  const done = rows.filter((row) => row.kind === "agentic" && !row.importedFrom && !row.archivedAt && row.state === "completed" && row.endedAt);
134
- const after = done.filter((row) => (learningOf(row)?.seed_notes ?? 0) > 0);
137
+ const after = done.filter((row) => seededItems(learningOf(row)) > 0);
135
138
  const merges = rows.flatMap((row) => {
136
139
  const learning = learningOf(row);
137
140
  return learning?.state === "merged" ? [Date.parse(learning.at)] : [];
@@ -169,25 +169,6 @@ export declare const learningView: (learning: Learning, shown: Shown, settled: b
169
169
  /** A learning's `reason` as it is served: one of its words as the server writes them, read back from a kept row, which is
170
170
  * untrusted, so cut of the host's secrets as every text is. */
171
171
  export declare const reasonShown: (reason: Learning["reason"] | undefined, shown: Shown) => Learning["reason"];
172
- /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
173
- * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
174
- * (notesView); never its time. */
175
- export declare const shortLearning: (learning: Learning | null, shown: Shown, settled: boolean) => ({
176
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
177
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
178
- detail: string | null;
179
- } & Omit<{
180
- given?: NoteUsed[];
181
- read?: NoteUsed[];
182
- learned?: NoteLearned[];
183
- pending?: NoteUsed[];
184
- skills?: LearnedFile[];
185
- workflows?: LearnedFile[];
186
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
187
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
188
- detail: string | null;
189
- at: string;
190
- }, "at" | "reason" | "detail" | "state">) | null;
191
172
  /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
192
173
  export declare function shortOf<T extends {
193
174
  state: LearningState;
@@ -502,6 +483,3 @@ export declare function withLearned(runDir: string, given: Workspace | string, i
502
483
  instructions: string;
503
484
  skills: string[];
504
485
  }>;
505
- /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
506
- * names none. A file that is not the list the pin names throws. */
507
- export declare function pinnedWorkflows(runDir: string, pin: Pin | undefined): Promise<LearnedWorkflow[]>;
package/dist/learning.js CHANGED
@@ -148,10 +148,6 @@ export const learningView = (learning, shown, settled) => {
148
148
  /** A learning's `reason` as it is served: one of its words as the server writes them, read back from a kept row, which is
149
149
  * untrusted, so cut of the host's secrets as every text is. */
150
150
  export const reasonShown = (reason, shown) => (typeof reason === "string" ? shown.text(reason) : (reason ?? null));
151
- /** A run's learning as a list shows it: its state and reason, its detail cut of the host's secrets and then short (at
152
- * most LIST_DETAIL characters, so a secret is never cut in half and shown), and the notes it read and learned
153
- * (notesView); never its time. */
154
- export const shortLearning = (learning, shown, settled) => (learning ? shortOf(learningView(learning, shown, settled)) : null);
155
151
  /** A run's learning as its view shows it, in short for a list: all of it but its time, its detail cut short. */
156
152
  export function shortOf({ state, reason, detail, at: _, ...notes }) {
157
153
  return { state, reason, detail: detail === null ? null : short(detail, LIST_DETAIL), ...notes };
@@ -768,15 +764,3 @@ export async function withLearned(runDir, given, instructions, own = []) {
768
764
  skills: [...own, ...learned.filter((path) => whole.has(path.split("/")[0]))],
769
765
  };
770
766
  }
771
- /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
772
- * names none. A file that is not the list the pin names throws. */
773
- export async function pinnedWorkflows(runDir, pin) {
774
- const names = pin?.workflows ?? [];
775
- if (!names.length)
776
- return [];
777
- const kept = JSON.parse(await readFile(join(runDir, LEARNED_WORKFLOWS_FILE), "utf8"));
778
- const ok = (entry) => isObject(entry) && typeof entry.name === "string" && typeof entry.description === "string" && typeof entry.workflow === "string";
779
- if (!Array.isArray(kept) || !kept.every(ok) || kept.map(({ name }) => name).join("\n") !== names.join("\n"))
780
- throw new Error(`the run's ${LEARNED_WORKFLOWS_FILE} is not the workflows its pin names`);
781
- return kept;
782
- }
package/dist/llm.d.ts CHANGED
@@ -32,9 +32,12 @@ type Models = {
32
32
  errorMessage?: string;
33
33
  }>;
34
34
  };
35
- /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. */
35
+ /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. An answer names the model as `named`
36
+ * (the run's own name for it) when the pick reaches it through another provider (a runner's session proxy), else as
37
+ * `<provider>/<model id>`. */
36
38
  export declare function completer(models: Models, pick: (tier: string | undefined) => {
37
39
  provider: string;
38
40
  modelId: string;
41
+ named?: string;
39
42
  } | undefined, thinking: ModelThinkingLevel): Complete;
40
43
  export {};
package/dist/llm.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { sideRequests } from "./cap.js";
2
2
  export const LLM_TOOL = "llm";
3
3
  const MAX_PROMPT = 400_000;
4
- /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. */
4
+ /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. An answer names the model as `named`
5
+ * (the run's own name for it) when the pick reaches it through another provider (a runner's session proxy), else as
6
+ * `<provider>/<model id>`. */
5
7
  export function completer(models, pick, thinking) {
6
8
  return async (args, signal) => {
7
9
  const { prompt, system, maxTokens, tier } = args;
@@ -35,6 +37,6 @@ export function completer(models, pick, thinking) {
35
37
  const cached = (message.usage?.cacheRead ?? 0) + (message.usage?.cacheWrite ?? 0);
36
38
  const usage = message.usage ? { input_tokens: message.usage.input + cached, output_tokens: message.usage.output, cached_input_tokens: cached } : null;
37
39
  const cost = priced && typeof message.usage?.cost?.total === "number" ? message.usage.cost.total : null;
38
- return { text, model: `${ref.provider}/${ref.modelId}`, usage, cost_usd: cost };
40
+ return { text, model: ref.named ?? `${ref.provider}/${ref.modelId}`, usage, cost_usd: cost };
39
41
  };
40
42
  }
@@ -69,6 +69,12 @@ export interface McpGatewayOptions {
69
69
  };
70
70
  /** The run's commit to its store: an unpriced call's "not metered" is written on its root. */
71
71
  commit?: () => McpCommit | undefined;
72
+ /** The claim's per-call check of a server's credential (its custody stamp): awaited before each call is checked for
73
+ * sending, it may drop the credential (`credentials[server].unopened`), which the call then refuses unsent; one that
74
+ * throws (a store read failed, the call was stopped) refuses the call unsent too, in words, and the run goes on. Only
75
+ * the runner's MCP claim step passes it: a github_app token whose App was disconnected or replaced. A CLI harness's
76
+ * session proxy ends in the same call. */
77
+ beforeCall?: (server: string, signal: AbortSignal) => Promise<void>;
72
78
  }
73
79
  /** A run's journal commit. */
74
80
  export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
@@ -185,7 +185,7 @@ export function mcpGateway(options) {
185
185
  const statuses = new Map();
186
186
  const send = options.fetch ?? fetch;
187
187
  /** The credential values each call in flight took or its server's requests sent while it was out, one set per call, by
188
- * server: with liveCredentials a refresh can swap a token between a call taking its headers and a request leaving, so
188
+ * server: a refresh can swap a token between a call taking its headers and a request leaving, so
189
189
  * what its answer or error is scrubbed of is every one of them, never only the headers it took. A call's set goes when
190
190
  * the call ends, so nothing held outlives the calls that sent it. */
191
191
  const inFlight = new Map();
@@ -359,6 +359,16 @@ export function mcpGateway(options) {
359
359
  };
360
360
  /** A call the gate let go: a priced one under the run's cap and booked, an unpriced one marked not metered. */
361
361
  const sent = async (server, tool, args, callId, signal) => {
362
+ // The credential's custody checked first: one the claim drops now is refused below, unsent. A check that could not
363
+ // be made (a store read failed, the call was stopped) refuses this call unsent too, in words: never sent unchecked.
364
+ if (options.beforeCall) {
365
+ try {
366
+ await options.beforeCall(server, signal);
367
+ }
368
+ catch {
369
+ return said(`The MCP server ${server}'s credential can't be used right now: it could not be checked just now. Nothing was sent.`, true);
370
+ }
371
+ }
362
372
  const why = unsendable(server, tool);
363
373
  if (why)
364
374
  return said(why, true);
@@ -86,9 +86,9 @@ export declare class McpServersOverStore {
86
86
  credential: "unreadable" | "sealed" | "expired" | null;
87
87
  not_metered?: string[] | undefined;
88
88
  tools: {
89
- permission: "deny" | "ask" | "allow";
90
- default_permission: "deny" | "ask" | "allow";
91
- permissions: ("deny" | "ask" | "allow")[];
89
+ permission: "deny" | "allow" | "ask";
90
+ default_permission: "deny" | "allow" | "ask";
91
+ permissions: ("deny" | "allow" | "ask")[];
92
92
  name: string;
93
93
  title?: string;
94
94
  description?: string;
@@ -121,9 +121,9 @@ export declare class McpServersOverStore {
121
121
  credential: "unreadable" | "sealed" | "expired" | null;
122
122
  not_metered?: string[] | undefined;
123
123
  tools: {
124
- permission: "deny" | "ask" | "allow";
125
- default_permission: "deny" | "ask" | "allow";
126
- permissions: ("deny" | "ask" | "allow")[];
124
+ permission: "deny" | "allow" | "ask";
125
+ default_permission: "deny" | "allow" | "ask";
126
+ permissions: ("deny" | "allow" | "ask")[];
127
127
  name: string;
128
128
  title?: string;
129
129
  description?: string;
@@ -159,9 +159,9 @@ export declare class McpServersOverStore {
159
159
  credential: "unreadable" | "sealed" | "expired" | null;
160
160
  not_metered?: string[] | undefined;
161
161
  tools: {
162
- permission: "deny" | "ask" | "allow";
163
- default_permission: "deny" | "ask" | "allow";
164
- permissions: ("deny" | "ask" | "allow")[];
162
+ permission: "deny" | "allow" | "ask";
163
+ default_permission: "deny" | "allow" | "ask";
164
+ permissions: ("deny" | "allow" | "ask")[];
165
165
  name: string;
166
166
  title?: string;
167
167
  description?: string;
@@ -198,9 +198,9 @@ export declare class McpServersOverStore {
198
198
  credential: "unreadable" | "sealed" | "expired" | null;
199
199
  not_metered?: string[] | undefined;
200
200
  tools: {
201
- permission: "deny" | "ask" | "allow";
202
- default_permission: "deny" | "ask" | "allow";
203
- permissions: ("deny" | "ask" | "allow")[];
201
+ permission: "deny" | "allow" | "ask";
202
+ default_permission: "deny" | "allow" | "ask";
203
+ permissions: ("deny" | "allow" | "ask")[];
204
204
  name: string;
205
205
  title?: string;
206
206
  description?: string;
package/dist/model.d.ts CHANGED
@@ -26,6 +26,9 @@ export declare const THINKING_LEVELS: readonly ["low", "medium", "high", "xhigh"
26
26
  export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
27
27
  export declare const TIERS: readonly ["fast", "default", "strong"];
28
28
  export type Tier = (typeof TIERS)[number];
29
+ /** The model `env` names for `tier` of its own (AGENT_MODEL_FAST, AGENT_MODEL_STRONG; AGENT_MODEL for the default), or
30
+ * undefined when it names none: a tier the host has no model of, whose request runs on the run's own model. */
31
+ export declare const tierModelOf: (env: NodeJS.ProcessEnv, tier: Tier) => string | undefined;
29
32
  /** The workflow node kinds that run on a model. */
30
33
  export declare const MODEL_NODES: readonly ["agent", "decide", "extract", "report"];
31
34
  /** The model providers whose key a person may save here (tool-keys.ts' `model` rows), in the order a default is taken
package/dist/model.js CHANGED
@@ -36,6 +36,9 @@ export const EFFORTS = ["low", "medium", "high"];
36
36
  export const THINKING_LEVELS = ["low", "medium", "high", "xhigh", "max"];
37
37
  export const TIERS = ["fast", "default", "strong"];
38
38
  const TIER_ENV = { fast: "AGENT_MODEL_FAST", default: "AGENT_MODEL", strong: "AGENT_MODEL_STRONG" };
39
+ /** The model `env` names for `tier` of its own (AGENT_MODEL_FAST, AGENT_MODEL_STRONG; AGENT_MODEL for the default), or
40
+ * undefined when it names none: a tier the host has no model of, whose request runs on the run's own model. */
41
+ export const tierModelOf = (env, tier) => env[TIER_ENV[tier]] || undefined;
39
42
  /** The workflow node kinds that run on a model. */
40
43
  export const MODEL_NODES = ["agent", "decide", "extract", "report"];
41
44
  /** The model providers whose key a person may save here (tool-keys.ts' `model` rows), in the order a default is taken
@@ -314,6 +317,11 @@ export async function runModels(env, ref, tiers = ["default"], harness = DEFAULT
314
317
  const price = typeof mod.cost === "object" ? mod.cost : undefined;
315
318
  if (typeof mod.default !== "function")
316
319
  throw new Error(`the faux module ${faux} has no default export function`);
320
+ // A faux model with no price ("unknown"), as a provider that does not price it: unpriced, so the runner's route books
321
+ // its requests at no known price (null), never at the placeholder cost's $0 (model-route.ts routeOf).
322
+ if (mod.cost === "unknown")
323
+ for (const id of ids)
324
+ unpriced.add(id);
317
325
  const reply = mod.default;
318
326
  const helpers = { message: ai.fauxAssistantMessage, text: ai.fauxText, thinking: ai.fauxThinking, toolCall: ai.fauxToolCall };
319
327
  // `contextWindow` sizes the faux model's window, so a test can make a run long enough to compact; `maxTokens` its