@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.30

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 (152) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/README.md +564 -97
  3. package/dist/adapters.d.ts +35 -6
  4. package/dist/adapters.js +152 -26
  5. package/dist/agents.d.ts +11 -5
  6. package/dist/agents.js +16 -10
  7. package/dist/app.js +80 -20
  8. package/dist/background.d.ts +28 -0
  9. package/dist/background.js +376 -0
  10. package/dist/box-egress.d.ts +98 -0
  11. package/dist/box-egress.js +259 -0
  12. package/dist/box-image.d.ts +1 -1
  13. package/dist/box-image.js +9 -7
  14. package/dist/box-relay-vm.d.ts +80 -0
  15. package/dist/box-relay-vm.js +389 -0
  16. package/dist/box-relay.d.ts +8 -5
  17. package/dist/box-relay.js +14 -9
  18. package/dist/boxes.d.ts +21 -3
  19. package/dist/boxes.js +14 -7
  20. package/dist/browser-cost.d.ts +41 -0
  21. package/dist/browser-cost.js +158 -0
  22. package/dist/cap.d.ts +129 -21
  23. package/dist/cap.js +338 -67
  24. package/dist/coding-tools.d.ts +7 -3
  25. package/dist/coding-tools.js +16 -10
  26. package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
  27. package/dist/console/assets/index-34jfpIbQ.js +481 -0
  28. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/content-filter.d.ts +7 -0
  31. package/dist/content-filter.js +23 -0
  32. package/dist/decision-rows.d.ts +11 -3
  33. package/dist/decision-rows.js +18 -11
  34. package/dist/errors.d.ts +2 -0
  35. package/dist/errors.js +5 -2
  36. package/dist/files.d.ts +6 -1
  37. package/dist/files.js +7 -2
  38. package/dist/grade.d.ts +7 -10
  39. package/dist/grade.js +31 -51
  40. package/dist/graph-served.d.ts +23 -0
  41. package/dist/graph-served.js +75 -0
  42. package/dist/graph-view.d.ts +7 -5
  43. package/dist/graph-view.js +10 -3
  44. package/dist/harness-app.d.ts +4 -2
  45. package/dist/harness-app.js +101 -19
  46. package/dist/harness-opencode/adapter.d.ts +45 -0
  47. package/dist/harness-opencode/adapter.js +272 -0
  48. package/dist/harness-opencode/binary.d.ts +18 -0
  49. package/dist/harness-opencode/binary.js +87 -0
  50. package/dist/harness-opencode/config.d.ts +24 -0
  51. package/dist/harness-opencode/config.js +61 -0
  52. package/dist/harness-opencode/harness.d.ts +77 -0
  53. package/dist/harness-opencode/harness.js +620 -0
  54. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  55. package/dist/harness-opencode/host/mcp.js +208 -0
  56. package/dist/harness-opencode/host/policy.d.ts +71 -0
  57. package/dist/harness-opencode/host/policy.js +419 -0
  58. package/dist/harness-opencode/host/server.d.ts +55 -0
  59. package/dist/harness-opencode/host/server.js +165 -0
  60. package/dist/harness-opencode/index.d.ts +9 -0
  61. package/dist/harness-opencode/index.js +6 -0
  62. package/dist/harness-opencode/verify.d.ts +32 -0
  63. package/dist/harness-opencode/verify.js +75 -0
  64. package/dist/harness-opencode/versions.d.ts +33 -0
  65. package/dist/harness-opencode/versions.js +64 -0
  66. package/dist/harness.d.ts +4 -1
  67. package/dist/harness.js +5 -2
  68. package/dist/host-tools.d.ts +12 -2
  69. package/dist/host-tools.js +26 -12
  70. package/dist/host.js +6 -2
  71. package/dist/hosted-search.js +5 -1
  72. package/dist/import.d.ts +2 -2
  73. package/dist/import.js +4 -3
  74. package/dist/key-check.d.ts +3 -2
  75. package/dist/key-check.js +7 -3
  76. package/dist/key-refusal.js +8 -4
  77. package/dist/learn/check.d.ts +10 -1
  78. package/dist/learn/check.js +19 -1
  79. package/dist/learn/grade.d.ts +3 -2
  80. package/dist/learn/grade.js +25 -13
  81. package/dist/learn/index.d.ts +2 -2
  82. package/dist/learn/index.js +2 -2
  83. package/dist/learn/notes.js +2 -1
  84. package/dist/learn/reflect.d.ts +2 -2
  85. package/dist/learn/reflect.js +51 -5
  86. package/dist/learn/secrets.js +28 -8
  87. package/dist/learn/skills.d.ts +17 -4
  88. package/dist/learn/skills.js +79 -6
  89. package/dist/learned-workflow.d.ts +59 -0
  90. package/dist/learned-workflow.js +191 -0
  91. package/dist/learning-run.d.ts +7 -5
  92. package/dist/learning-run.js +45 -23
  93. package/dist/learning-words.d.ts +6 -3
  94. package/dist/learning-words.js +8 -5
  95. package/dist/learning.d.ts +44 -3
  96. package/dist/learning.js +148 -3
  97. package/dist/mcp-servers.d.ts +7 -4
  98. package/dist/mcp-servers.js +5 -0
  99. package/dist/mcp.js +5 -5
  100. package/dist/model.d.ts +13 -11
  101. package/dist/model.js +11 -10
  102. package/dist/openapi/agentrun-v2.openapi.json +1 -0
  103. package/dist/openapi.js +358 -48
  104. package/dist/paid-calls.d.ts +5 -1
  105. package/dist/paid-calls.js +1 -1
  106. package/dist/pause.d.ts +2 -0
  107. package/dist/place.d.ts +27 -4
  108. package/dist/place.js +42 -10
  109. package/dist/propose.d.ts +2 -0
  110. package/dist/propose.js +38 -8
  111. package/dist/request-start.d.ts +12 -4
  112. package/dist/request-start.js +139 -15
  113. package/dist/run-box.d.ts +56 -4
  114. package/dist/run-box.js +173 -23
  115. package/dist/runnable.d.ts +5 -2
  116. package/dist/runnable.js +12 -4
  117. package/dist/runs.d.ts +258 -36
  118. package/dist/runs.js +830 -89
  119. package/dist/secrets.d.ts +12 -0
  120. package/dist/secrets.js +18 -0
  121. package/dist/server.d.ts +131 -35
  122. package/dist/server.js +467 -105
  123. package/dist/sign-ins.d.ts +99 -0
  124. package/dist/sign-ins.js +288 -0
  125. package/dist/skills.d.ts +16 -4
  126. package/dist/skills.js +35 -7
  127. package/dist/stats.d.ts +7 -2
  128. package/dist/stats.js +28 -7
  129. package/dist/tool-gate.d.ts +266 -0
  130. package/dist/tool-gate.js +554 -0
  131. package/dist/tool-keys.d.ts +46 -10
  132. package/dist/tool-keys.js +44 -2
  133. package/dist/tool-plane.d.ts +112 -27
  134. package/dist/tool-plane.js +205 -47
  135. package/dist/tools.d.ts +69 -14
  136. package/dist/tools.js +143 -24
  137. package/dist/trigger-secrets.d.ts +32 -0
  138. package/dist/trigger-secrets.js +143 -0
  139. package/dist/triggers.d.ts +439 -0
  140. package/dist/triggers.js +863 -0
  141. package/dist/turn-end.d.ts +3 -2
  142. package/dist/turn-end.js +3 -2
  143. package/dist/usage-lines.d.ts +26 -0
  144. package/dist/usage-lines.js +28 -0
  145. package/dist/validate.d.ts +2 -0
  146. package/dist/validate.js +11 -2
  147. package/dist/webhooks.d.ts +11 -4
  148. package/dist/webhooks.js +17 -1
  149. package/launcher/agentrun-serve +1 -1
  150. package/package.json +19 -13
  151. package/dist/console/assets/index-BN7oVcO4.js +0 -445
  152. package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/learning.js CHANGED
@@ -33,7 +33,7 @@ import { constants, existsSync } from "node:fs";
33
33
  import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
34
34
  import { dirname, join, posix, relative } from "node:path";
35
35
  import { SKILL_BYTES } from "@parcha/agentrun-kernel";
36
- import { INDEX_FILE, loadedIndex, NOTE_FILE, parseNoteFile, redactSecrets, secretShapes, servedSkill, SKILLS_DIR, valueMatcher } from "./learn/index.js";
36
+ import { INDEX_FILE, loadedIndex, NOTE_FILE, parseNoteFile, redactSecrets, secretShapes, servedSkill, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
37
37
  import { homeOf, serialBy, writeDurable } from "./files.js";
38
38
  import { DETAIL_MAX, LIST_DETAIL, short, wordsOf } from "./learning-words.js";
39
39
  import { isObject } from "./validate.js";
@@ -139,6 +139,14 @@ export const LEARNED_DIR = ".learning";
139
139
  /** What the run's end-of-run turn answered, and what the user said in the run, kept in the run's directory as the run
140
140
  * settles (learning-run.ts beforeSettle), where the host alone reads it: what propose.ts checks. */
141
141
  export const LEARNING_TURN = "learning-turn.json";
142
+ /** Where a run keeps the learned workflows its pin names, whole: in the run's directory, beside its pin, never in its
143
+ * work, so nothing the run does changes what its `learned_workflow` tool runs. */
144
+ export const LEARNED_WORKFLOWS_FILE = "learned-workflows.json";
145
+ /** The most bytes the `learned_workflow` tool's description gives its workflows, each one's line (workflowLine)
146
+ * together: every harness sends the description with each request, so it never grows with what an agent learned. */
147
+ export const LEARNED_WORKFLOWS_BUDGET = 8 * 1024;
148
+ /** A learned workflow's line in the `learned_workflow` tool's description: its name, and what its README says it does. */
149
+ export const workflowLine = ({ name, description }) => `- ${name}: ${description || "(no description)"}`;
142
150
  /** The most bytes of learned skills one run gets, every file of each together. They get no more than what the
143
151
  * revision's own skills leave of the adapters' cap on a run's skills in all (SKILL_BYTES): over that cap an adapter
144
152
  * refuses the whole set, and every skill, the revision's too, would be inlined in the prompt (skills.ts splitSkills). */
@@ -467,6 +475,100 @@ export async function readSkills(cwd, repo, sha) {
467
475
  }
468
476
  return { skills, skipped };
469
477
  }
478
+ /** The workflows commit `sha` holds under WORKFLOWS_DIR, read with plumbing, by name: each a folder with a workflow.json
479
+ * and a README.md, each a regular file (mode 100644) of at most FILE_CAP bytes in UTF-8; else named in `skipped`. Only an
480
+ * active one is a run's, by the rule a skill is (readSkills): its README.md sets no status, or `active`; one held for
481
+ * its owner's OK, or retired, is left out. A symbolic link or a submodule under WORKFLOWS_DIR throws. */
482
+ export async function readWorkflows(cwd, repo, sha) {
483
+ const listed = (await git(cwd, repo, ["ls-tree", "-r", "-t", "-l", "-z", "--full-tree", sha, "--", WORKFLOWS_DIR])).toString("utf8").split("\0").filter(Boolean);
484
+ const found = new Map();
485
+ const refused = new Set();
486
+ const skipped = [];
487
+ for (const entry of listed) {
488
+ const tab = entry.indexOf("\t");
489
+ const [mode, type, oid, size] = entry.slice(0, tab).split(/\s+/);
490
+ const path = entry.slice(tab + 1);
491
+ if (path !== WORKFLOWS_DIR && !path.startsWith(`${WORKFLOWS_DIR}/`))
492
+ continue;
493
+ if (mode === "120000" || mode === "160000")
494
+ throw new Error(`the learning folder's ${path} is a ${mode === "120000" ? "symbolic link" : "submodule"}, and the host never reads one for a run`);
495
+ if (type === "tree")
496
+ continue;
497
+ const [name = "", file = "", ...more] = path.slice(WORKFLOWS_DIR.length + 1).split("/");
498
+ const why = !WORKFLOW_NAME.test(name) || more.length || (file !== "workflow.json" && file !== "README.md") ? "not a workflow's workflow.json or README.md" : mode !== "100644" || type !== "blob" || !oid ? `mode ${mode}` : Number(size) > FILE_CAP ? `over ${FILE_CAP} bytes` : undefined;
499
+ if (why) {
500
+ refused.add(name);
501
+ skipped.push(`${path} (${why})`);
502
+ }
503
+ else
504
+ (found.get(name) ?? found.set(name, {}).get(name))[file] = oid;
505
+ }
506
+ const workflows = [];
507
+ for (const [name, oids] of [...found].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
508
+ if (refused.has(name))
509
+ continue;
510
+ if (!oids["workflow.json"] || !oids["README.md"]) {
511
+ skipped.push(`${WORKFLOWS_DIR}/${name} (no ${oids["workflow.json"] ? "README.md" : "workflow.json"})`);
512
+ continue;
513
+ }
514
+ const [json, readme] = await readBlobs(cwd, repo, [oids["workflow.json"], oids["README.md"]]);
515
+ let texts;
516
+ try {
517
+ texts = [utf8.decode(json), utf8.decode(readme)];
518
+ }
519
+ catch {
520
+ skipped.push(`${WORKFLOWS_DIR}/${name} (not UTF-8)`);
521
+ continue;
522
+ }
523
+ // Its README read one way only, or not at all: one whose front matter is not closed, or holds a line that is no key
524
+ // at its left edge, could hold a status a reader other than this one sees, so it is never read as active.
525
+ const front = readmeFront(texts[1]);
526
+ if (!front) {
527
+ skipped.push(`${WORKFLOWS_DIR}/${name} (its README.md's front matter does not read one way)`);
528
+ continue;
529
+ }
530
+ const status = front.get("status");
531
+ if (status !== undefined && status !== "active")
532
+ continue;
533
+ workflows.push({ name, description: front.get("description") ?? "", workflow: texts[0] });
534
+ }
535
+ return { workflows, skipped };
536
+ }
537
+ /** A learned workflow README's front matter, each key to its value (quotes dropped; a `>` or `|` value's indented lines
538
+ * joined by spaces), or undefined when it does not read one way: no front matter, none closed (`---` on a line of its
539
+ * own, the last line or not), a line that is neither a key at its left edge, a comment, blank, nor a line of a `>` or
540
+ * `|` value, or a key set twice. */
541
+ export function readmeFront(text) {
542
+ const lf = text.replace(/\r\n/g, "\n");
543
+ if (!lf.startsWith("---\n"))
544
+ return undefined;
545
+ const close = /\n---(?:\n|$)/.exec(lf.slice(3));
546
+ if (!close)
547
+ return undefined;
548
+ const front = new Map();
549
+ let block;
550
+ for (const line of lf.slice(4, 3 + close.index).split("\n")) {
551
+ if (block !== undefined && (/^\s+\S/.test(line) || line.trim() === "")) {
552
+ if (line.trim())
553
+ front.set(block, `${front.get(block)} ${line.trim()}`.trim());
554
+ continue;
555
+ }
556
+ block = undefined;
557
+ if (line.trim() === "" || line.startsWith("#"))
558
+ continue;
559
+ const pair = /^([A-Za-z_][\w-]*):(?:\s+(.*))?$/.exec(line);
560
+ if (!pair || front.has(pair[1]))
561
+ return undefined;
562
+ const value = (pair[2] ?? "").trim();
563
+ if (/^[>|][-+]?$/.test(value)) {
564
+ block = pair[1];
565
+ front.set(block, "");
566
+ }
567
+ else
568
+ front.set(pair[1], value.replace(/^(["'])(.*)\1$/, "$2"));
569
+ }
570
+ return front;
571
+ }
470
572
  /** Each file's place in main's first-parent log from `sha`, by the newest commit that changed it: 0 for those the newest
471
573
  * commit changed, and so on, so two changes in one second keep their order. A run's notes (seedOf) and a person's view
472
574
  * of them (learning-routes.ts) are in this order, the one changed last first. */
@@ -507,6 +609,9 @@ export function seedOf(data, agentId) {
507
609
  const placeOf = (skill) => skillPlace.get(skill.name) ?? Number.POSITIVE_INFINITY;
508
610
  seed.skills = [...skills].sort((a, b) => placeOf(a) - placeOf(b) || 0);
509
611
  seed.skipped.push(...skipped);
612
+ const flows = await readWorkflows(home, repo, sha);
613
+ seed.workflows = flows.workflows;
614
+ seed.skipped.push(...flows.skipped);
510
615
  return seed;
511
616
  });
512
617
  }
@@ -707,7 +812,34 @@ export async function pinSeed(runDir, work, seed, options) {
707
812
  const section = learnedOf(seed, options);
708
813
  const { taken, left } = await chooseSkills(work, seed, options.own ?? [], options.shown);
709
814
  const skills = taken.flatMap(({ name, files = {} }) => Object.keys(files).sort().map((path) => `${name}/${path}`));
710
- const pin = { seed: seed.sha, ...(section ? { section } : {}), ...(skills.length ? { skills } : {}), ...(left.length ? { skills_left_out: left } : {}) };
815
+ // The learned workflows the run may run, whole, in its directory before the pin names them (a reopen keeps them):
816
+ // by name, each while its line fits what is left of the tool's description budget; one that does not, or holds a
817
+ // secret, is left out, and the pin names it.
818
+ const flows = [];
819
+ const flowsLeft = [];
820
+ let room = LEARNED_WORKFLOWS_BUDGET;
821
+ for (const flow of seed.workflows ?? []) {
822
+ // None, when the run is offered none (learnedWorkflowsOff): each is named, but for a name that is itself a secret.
823
+ if (options.workflowsOff !== undefined) {
824
+ if (!options.shown.holds(flow.name))
825
+ flowsLeft.push(flow.name);
826
+ continue;
827
+ }
828
+ if (options.shown.holds(flow.workflow) || options.shown.holds(flow.description) || options.shown.holds(flow.name)) {
829
+ // Named, but for a name that is itself a secret.
830
+ if (!options.shown.holds(flow.name))
831
+ flowsLeft.push(flow.name);
832
+ continue;
833
+ }
834
+ const bytes = Buffer.byteLength(`${workflowLine(flow)}\n`, "utf8");
835
+ if (bytes > room)
836
+ flowsLeft.push(flow.name);
837
+ else
838
+ (room -= bytes), flows.push(flow);
839
+ }
840
+ if (flows.length)
841
+ await writeDurable(join(runDir, LEARNED_WORKFLOWS_FILE), `${JSON.stringify(flows)}\n`);
842
+ const pin = { seed: seed.sha, ...(section ? { section } : {}), ...(skills.length ? { skills } : {}), ...(left.length ? { skills_left_out: left } : {}), ...(flows.length ? { workflows: flows.map(({ name }) => name) } : {}), ...(options.workflowsOff !== undefined && flowsLeft.length ? { workflows_off: options.workflowsOff } : {}), ...(flowsLeft.length ? { workflows_left_out: flowsLeft } : {}) };
711
843
  // The pin names the skills before they are laid: a server that goes down while they are takes them back (dropSeed).
712
844
  await writeDurable(pinFile, `${JSON.stringify(pin)}\n`);
713
845
  await laySkills(work, taken, made);
@@ -718,6 +850,7 @@ export async function pinSeed(runDir, work, seed, options) {
718
850
  // writeDurable renames the pin into place before it syncs the run's directory, so a failure there leaves the pin
719
851
  // behind: it goes too, or the run's instructions would still say what it learned, of notes it has no copy of.
720
852
  await rm(pinFile, { force: true }).catch(() => undefined);
853
+ await rm(join(runDir, LEARNED_WORKFLOWS_FILE), { force: true }).catch(() => undefined);
721
854
  await rm(dir, { recursive: true, force: true }).catch(() => undefined);
722
855
  await takeSkills(work, made).catch(() => undefined);
723
856
  throw error;
@@ -763,7 +896,7 @@ export async function readPin(runDir) {
763
896
  const pin = JSON.parse(text);
764
897
  const names = (value, shape) => value === undefined || (Array.isArray(value) && value.every((entry) => typeof entry === "string" && shape(entry)));
765
898
  const skillFile = (entry) => SKILL_NAME.test(entry.split("/")[0]) && SKILL_FILE_PATH.test(entry.slice(entry.indexOf("/") + 1)) && entry.includes("/");
766
- if (!isObject(pin) || typeof pin.seed !== "string" || (pin.section !== undefined && typeof pin.section !== "string") || (pin.learned !== undefined && typeof pin.learned !== "string") || !names(pin.skills, skillFile) || !names(pin.skills_left_out, () => true))
899
+ if (!isObject(pin) || typeof pin.seed !== "string" || (pin.section !== undefined && typeof pin.section !== "string") || (pin.learned !== undefined && typeof pin.learned !== "string") || !names(pin.skills, skillFile) || !names(pin.skills_left_out, () => true) || !names(pin.workflows, (entry) => WORKFLOW_NAME.test(entry)) || !names(pin.workflows_left_out, (entry) => WORKFLOW_NAME.test(entry)) || (pin.workflows_off !== undefined && typeof pin.workflows_off !== "string"))
767
900
  throw new Error(`the run's ${LEARNING_PIN} is not a learning pin`);
768
901
  return pin;
769
902
  }
@@ -799,3 +932,15 @@ export async function withLearned(runDir, work, instructions, own = []) {
799
932
  skills: [...own, ...learned.filter((path) => whole.has(path.split("/")[0]))],
800
933
  };
801
934
  }
935
+ /** The learned workflows a run's pin names, as its directory keeps them (LEARNED_WORKFLOWS_FILE): none when the pin
936
+ * names none. A file that is not the list the pin names throws. */
937
+ export async function pinnedWorkflows(runDir, pin) {
938
+ const names = pin?.workflows ?? [];
939
+ if (!names.length)
940
+ return [];
941
+ const kept = JSON.parse(await readFile(join(runDir, LEARNED_WORKFLOWS_FILE), "utf8"));
942
+ const ok = (entry) => isObject(entry) && typeof entry.name === "string" && typeof entry.description === "string" && typeof entry.workflow === "string";
943
+ if (!Array.isArray(kept) || !kept.every(ok) || kept.map(({ name }) => name).join("\n") !== names.join("\n"))
944
+ throw new Error(`the run's ${LEARNED_WORKFLOWS_FILE} is not the workflows its pin names`);
945
+ return kept;
946
+ }
@@ -1,5 +1,8 @@
1
1
  export declare const MCP_SERVERS_FILE = "mcp-servers.json";
2
2
  export declare const MCP_SERVER_NAME: RegExp;
3
+ /** The names AgentRun's own tools are called by, which no MCP server takes: claude-agent calls the kernel's host tools
4
+ * as `mcp__hands__<tool>`, and monid's are `monid_<tool>` (tool-gate.ts settingsKeyOf reads both as AgentRun's). */
5
+ export declare const RESERVED_MCP_NAMES: readonly string[];
3
6
  export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers"];
4
7
  export type McpTool = {
5
8
  name: string;
@@ -29,7 +32,7 @@ export declare class McpServers {
29
32
  servers: {
30
33
  auth: {
31
34
  headers?: string[] | undefined;
32
- type: "none" | "headers" | "bearer";
35
+ type: "headers" | "none" | "bearer";
33
36
  };
34
37
  credential: "unreadable" | "seal_key_missing" | "sealed" | null;
35
38
  protocol: string;
@@ -46,7 +49,7 @@ export declare class McpServers {
46
49
  get(name: string): {
47
50
  auth: {
48
51
  headers?: string[] | undefined;
49
- type: "none" | "headers" | "bearer";
52
+ type: "headers" | "none" | "bearer";
50
53
  };
51
54
  credential: "unreadable" | "seal_key_missing" | "sealed" | null;
52
55
  protocol: string;
@@ -65,7 +68,7 @@ export declare class McpServers {
65
68
  save(name: string, body: Record<string, unknown>, stop?: AbortSignal): Promise<{
66
69
  auth: {
67
70
  headers?: string[] | undefined;
68
- type: "none" | "headers" | "bearer";
71
+ type: "headers" | "none" | "bearer";
69
72
  };
70
73
  credential: "unreadable" | "seal_key_missing" | "sealed" | null;
71
74
  protocol: string;
@@ -85,7 +88,7 @@ export declare class McpServers {
85
88
  server: {
86
89
  auth: {
87
90
  headers?: string[] | undefined;
88
- type: "none" | "headers" | "bearer";
91
+ type: "headers" | "none" | "bearer";
89
92
  };
90
93
  credential: "unreadable" | "seal_key_missing" | "sealed" | null;
91
94
  protocol: string;
@@ -15,6 +15,9 @@ import { isObject, unknownFields } from "./validate.js";
15
15
  export const MCP_SERVERS_FILE = "mcp-servers.json";
16
16
  const FORMAT = "mcp-servers/1";
17
17
  export const MCP_SERVER_NAME = /^[a-z][a-z0-9-]{0,31}$/;
18
+ /** The names AgentRun's own tools are called by, which no MCP server takes: claude-agent calls the kernel's host tools
19
+ * as `mcp__hands__<tool>`, and monid's are `monid_<tool>` (tool-gate.ts settingsKeyOf reads both as AgentRun's). */
20
+ export const RESERVED_MCP_NAMES = ["hands", "monid"];
18
21
  export const MCP_AUTH_TYPES = ["none", "bearer", "headers"];
19
22
  const REQUEST_MS = 15_000;
20
23
  const PREVIEW_MS = 30_000;
@@ -76,6 +79,8 @@ export class McpServers {
76
79
  async save(name, body, stop) {
77
80
  if (!MCP_SERVER_NAME.test(name))
78
81
  throw invalid([{ field: "name", reason: "invalid", message: "A server's name is 1 to 32 lowercase letters, digits and dashes, starting with a letter (no underscores, so mcp__<server>__<tool> splits one way)." }]);
82
+ if (RESERVED_MCP_NAMES.includes(name))
83
+ throw invalid([{ field: "name", reason: "reserved", message: `'${name}' is reserved for AgentRun's own tools: a server under it would take their names and their permissions. Name the server another way.` }]);
79
84
  const { url, auth } = this.admit(body);
80
85
  if (auth.type !== "none" && !this.key)
81
86
  throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no MCP server credential: it never keeps one in the clear.`);
package/dist/mcp.js CHANGED
@@ -62,7 +62,7 @@ const AGENT_ID = { type: "string", description: "The agent's id." };
62
62
  const RUN_ID = { type: "string", description: "The run's id." };
63
63
  const DEFINITION = {
64
64
  instructions: { type: "string", description: "What the agent does and how: its system prompt." },
65
- harness: { type: "string", enum: ["pi", "claude-agent", "codex"], description: "What runs it (default pi). whoami says which this server runs." },
65
+ harness: { type: "string", enum: ["pi", "claude-agent", "codex", "opencode"], description: "What runs it (default pi). whoami says which this server runs." },
66
66
  model: { type: ["string", "null"], description: "provider/model-id. Absent, this server's default (whoami names it)." },
67
67
  thinking: { type: ["string", "null"], description: "How hard the model thinks: one of whoami's thinking levels. Absent, the model's own." },
68
68
  tools: { type: "array", items: { type: "string" }, description: "The tools it may use, by name (whoami lists them); [] for none. It writes files only with a tool like write." },
@@ -119,7 +119,7 @@ export const TOOLS = [
119
119
  },
120
120
  {
121
121
  name: "agents_revise", title: "Revise an agent", annotations: WRITE,
122
- description: "Makes the agent's next revision from its current definition with these fields changed, and any other field in definition (GET /v2/agents/{agent_id}, then PUT /v2/agents/{agent_id}/definition on that revision): fields you leave out stay; null clears model or thinking. Its next run runs the new revision. A revision saved in between is refused (precondition_failed), never overwritten. Its name and description stay as it was created.",
122
+ description: "Makes the agent's next revision from its current definition with these fields changed, and any other field in definition (GET /v2/agents/{agent_id}, then PUT /v2/agents/{agent_id}/definition on that revision): fields you leave out stay; null clears model or thinking. definition.max_cost_usd sets the agent's default spend cap of each run started without one; 0 clears it (null is refused), and a revise that leaves it out keeps it. Its next run runs the new revision. A revision saved in between is refused (precondition_failed), never overwritten. Its name and description stay as it was created.",
123
123
  inputSchema: { type: "object", required: ["agent_id"], properties: { agent_id: AGENT_ID, ...DEFINITION, note: { type: "string", description: "Optional: what this revision changes." } } },
124
124
  run: async (args, context) => {
125
125
  const agent = text(args, "agent_id");
@@ -157,7 +157,7 @@ export const TOOLS = [
157
157
  },
158
158
  {
159
159
  name: "runs_get", title: "Get a run", annotations: READ,
160
- description: "A run's status and outcome (GET /v2/runs/{run_id}), and console_url (added here), the run's page. pending is what it waits on, by kind: {kind: \"question\", question} while its status is input_required, else null. status is queued, working, input_required, completed, failed, cancelled or paused. A completed run's answer is result.final_answer (agentic) or result.output (workflow); a failed run's reason is error; cost.usd is null while unknown, never $0.",
160
+ description: "A run's status and outcome (GET /v2/runs/{run_id}), and console_url (added here), the run's page. pending is what it waits on while its status is input_required, by kind: {kind: \"question\", question} for a question it asked, {kind: \"budget\", cap_usd, spent_usd, needs_usd, suggested_cap_usd, said, at} for a run paused at its spend cap (it waits for its cap to be raised, PATCH /v2/runs/{run_id} {max_cost_usd}, which a person decides; suggested_cap_usd is a raise that resumes it; said is why), else null. status is queued, working, input_required, completed, failed, cancelled or paused. A completed run's answer is result.final_answer (agentic) or result.output (workflow); a failed run's reason is error; cost.usd is null while unknown, never $0.",
161
161
  inputSchema: { type: "object", required: ["run_id"], properties: { run_id: RUN_ID } },
162
162
  run: async (args, context) => {
163
163
  const run = text(args, "run_id");
@@ -204,7 +204,7 @@ export const TOOLS = [
204
204
  },
205
205
  {
206
206
  name: "runs_respond", title: "Answer a run", annotations: { ...WRITE, openWorldHint: true },
207
- description: "Sends an agentic run a message (POST /v2/runs/{run_id}/messages): the answer to the question it asked (its status is input_required; runs_get's pending holds the question), or a follow-up once it completed or was stopped: a fresh turn with its history (a stopped turn is not replayed). mode in the answer says which. A cancelled run takes none: 409 not_continuable, start a new run. Then poll runs_get again.",
207
+ description: "Sends an agentic run a message (POST /v2/runs/{run_id}/messages): the answer to the question it asked (its status is input_required; runs_get's pending holds the question), or a follow-up once it completed or was stopped: a fresh turn with its history (a stopped turn is not replayed). mode in the answer says which. A cancelled run takes none: 409 not_continuable, start a new run. A run paused at its spend cap (pending kind budget) takes no message: 409 budget_reached; it waits for its cap to be raised, so tell the person (console_url), never answer it. Then poll runs_get again.",
208
208
  inputSchema: { type: "object", required: ["run_id", "content"], properties: { run_id: RUN_ID, content: { type: "string", description: "The answer, or the message." } } },
209
209
  run: routed((args) => ({ method: "POST", path: `/runs/${id(text(args, "run_id"))}/messages`, body: without(args, ["run_id"]) })),
210
210
  },
@@ -215,7 +215,7 @@ export const TOOLS = [
215
215
  run: routed((args) => ({ method: "POST", path: `/runs/${id(text(args, "run_id"))}/cancel` })),
216
216
  },
217
217
  ];
218
- const INSTRUCTIONS = "Tools over this AgentRun server's agents and runs. Call whoami first. To run an agent: agents_list (or agents_create, after asking the person), then runs_start, then runs_get every few seconds until its status is completed, failed or cancelled. input_required means it asked a question (runs_get's pending, kind question): answer it with runs_respond, or leave it for the person in the console (console_url). Read its steps with runs_events and what it wrote with runs_files.";
218
+ const INSTRUCTIONS = "Tools over this AgentRun server's agents and runs. Call whoami first. To run an agent: agents_list (or agents_create, after asking the person), then runs_start, then runs_get every few seconds until its status is completed, failed or cancelled. input_required means it asked a question (runs_get's pending, kind question): answer it with runs_respond, or leave it for the person in the console (console_url). With pending kind budget the run is paused at its spend cap and waits for its cap to be raised: do not answer it (runs_respond is refused 409 budget_reached); tell the person, with its console_url. Read its steps with runs_events and what it wrote with runs_files.";
219
219
  /** A route's answer, captured: its status, headers and bytes up to `limit`. A route that writes past it is cut off
220
220
  * there (`tooBig`): a file stream stops. */
221
221
  class Answer extends Writable {
package/dist/model.d.ts CHANGED
@@ -29,11 +29,12 @@ export declare const MODEL_NODES: readonly ["agent", "decide", "extract", "repor
29
29
  /** The model providers whose key a person may save here (tool-keys.ts' `model` rows), in the order a default is taken
30
30
  * from, each with the model a run gets on its key when neither its revision nor the host names one: the provider's
31
31
  * capable everyday model, not its dearest (Claude Sonnet 5.5 and GPT-6.1 Sol, each $2 in and $10 out per million
32
- * tokens). `harnesses`: those that run on the key, pi on any model of it and the harness that is the provider's own;
33
- * OpenRouter's runs all three. `models`: a harness's own default on the key where it is not `model`. On OpenRouter:
32
+ * tokens). `harnesses`: those that run on the key, pi on any model of it and the harnesses that talk to that
33
+ * provider's own API (OpenAI's: codex and opencode); OpenRouter's runs them all. `models`: a harness's own default on the
34
+ * key where it is not `model`. On OpenRouter:
34
35
  * pi's is GPT-6 Sol on pi-ai's openrouter provider (/chat/completions, the key as a bearer token, as OpenRouter's docs
35
36
  * name it; its Anthropic models go to /v1/messages with the key in x-api-key, which the docs do not), claude-agent's
36
- * Claude Sonnet 5.5 and codex's GPT-6 Sol, each through OpenRouter's own endpoint for the harness (adapters.ts), the ids
37
+ * Claude Sonnet 5.5 and codex's and opencode's GPT-6 Sol, each through OpenRouter's own endpoint for the harness (adapters.ts), the ids
37
38
  * a live run took through OpenRouter on 2026-10-29. The row order is the order a default is taken in: a direct
38
39
  * provider's key wins over OpenRouter's. */
39
40
  export declare const MODEL_KEYS: readonly [{
@@ -41,32 +42,33 @@ export declare const MODEL_KEYS: readonly [{
41
42
  readonly label: "Anthropic";
42
43
  readonly field: "ANTHROPIC_API_KEY";
43
44
  readonly model: "anthropic/claude-sonnet-5-5";
44
- readonly harnesses: readonly ["pi" | "claude-agent" | "codex", "claude-agent"];
45
+ readonly harnesses: readonly ["pi" | "claude-agent" | "codex" | "opencode", "claude-agent"];
45
46
  }, {
46
47
  readonly id: "openai";
47
48
  readonly label: "OpenAI";
48
49
  readonly field: "OPENAI_API_KEY";
49
50
  readonly model: "openai/gpt-6.1-sol";
50
- readonly harnesses: readonly ["pi" | "claude-agent" | "codex", "codex"];
51
+ readonly harnesses: readonly ["pi" | "claude-agent" | "codex" | "opencode", "codex", "opencode"];
51
52
  }, {
52
53
  readonly id: "openrouter";
53
54
  readonly label: "OpenRouter";
54
55
  readonly field: "OPENROUTER_API_KEY";
55
56
  readonly model: "openrouter/openai/gpt-6-sol";
56
- readonly harnesses: readonly ["pi" | "claude-agent" | "codex", "claude-agent", "codex"];
57
+ readonly harnesses: readonly ["pi" | "claude-agent" | "codex" | "opencode", "claude-agent", "codex", "opencode"];
57
58
  readonly models: {
58
59
  readonly "claude-agent": "anthropic/claude-sonnet-5.5";
59
60
  readonly codex: "openai/gpt-6-sol";
61
+ readonly opencode: "openai/gpt-6-sol";
60
62
  };
61
63
  }];
62
64
  /**
63
65
  * Whether `harness` reaches its vendor's models here only through OpenRouter: OPENROUTER_API_KEY is set and none of the
64
66
  * harness's own settings is. Those win, as on a host with no OpenRouter key: the endpoint the host names
65
- * (ANTHROPIC_BASE_URL for claude-agent, which needs ANTHROPIC_API_KEY; serve's gateway AGENT_MODEL_BASE_URL for codex,
66
- * with AGENT_MODEL_API_KEY or none), then the vendor's own key (ANTHROPIC_API_KEY, OPENAI_API_KEY), then OpenRouter. An
67
+ * (ANTHROPIC_BASE_URL for claude-agent, which needs ANTHROPIC_API_KEY; serve's gateway AGENT_MODEL_BASE_URL for codex
68
+ * and opencode, which take the same route, with AGENT_MODEL_API_KEY or none), then the vendor's own key (ANTHROPIC_API_KEY, OPENAI_API_KEY), then OpenRouter. An
67
69
  * endpoint the host names never gets the OpenRouter key.
68
70
  */
69
- export declare function openRouterOnly(harness: "claude-agent" | "codex", env: NodeJS.ProcessEnv): boolean;
71
+ export declare function openRouterOnly(harness: "claude-agent" | "codex" | "opencode", env: NodeJS.ProcessEnv): boolean;
70
72
  /** Whether `harness`'s model requests for `model` (as named, `provider/model-id`; none, the host's for the harness) go
71
73
  * through OpenRouter: a model named on it (`openrouter/<vendor>/...`), or the harness's vendor reached only through it
72
74
  * (openRouterOnly). The route claudeProvider and codexProvider take (adapters.ts); a gateway (AGENT_MODEL_BASE_URL)
@@ -78,9 +80,9 @@ export declare function viaOpenRouter(env: NodeJS.ProcessEnv, harness: string, m
78
80
  * taken in is MODEL_KEYS' own. */
79
81
  export declare const ADD_A_KEY: string;
80
82
  /** Whether `harness` runs the model `id`: pi any; claude-agent an Anthropic model (`anthropic/...`, or Anthropic's on
81
- * OpenRouter, `openrouter/anthropic/...`), as it talks to an Anthropic Messages endpoint only; codex, behind a gateway
83
+ * OpenRouter, `openrouter/anthropic/...`), as it talks to an Anthropic Messages endpoint only; codex and opencode, behind a gateway
82
84
  * (AGENT_MODEL_BASE_URL), any id, which is the gateway's own string and names no provider here (team/model included),
83
- * as codex takes that gateway for its OpenAI-compatible endpoint; without one, an OpenAI model (`openai/...`, or OpenAI's
85
+ * as each takes that gateway for its OpenAI-compatible endpoint; without one, an OpenAI model (`openai/...`, or OpenAI's
84
86
  * on OpenRouter). On the faux harness every harness runs the run's model. */
85
87
  export declare function harnessRuns(env: NodeJS.ProcessEnv, id: string, harness: string): boolean;
86
88
  /** The model a revision that names none runs on with `harness`, for `tier`: the tier's own variable, else AGENT_MODEL,
package/dist/model.js CHANGED
@@ -36,25 +36,26 @@ export const MODEL_NODES = ["agent", "decide", "extract", "report"];
36
36
  /** The model providers whose key a person may save here (tool-keys.ts' `model` rows), in the order a default is taken
37
37
  * from, each with the model a run gets on its key when neither its revision nor the host names one: the provider's
38
38
  * capable everyday model, not its dearest (Claude Sonnet 5.5 and GPT-6.1 Sol, each $2 in and $10 out per million
39
- * tokens). `harnesses`: those that run on the key, pi on any model of it and the harness that is the provider's own;
40
- * OpenRouter's runs all three. `models`: a harness's own default on the key where it is not `model`. On OpenRouter:
39
+ * tokens). `harnesses`: those that run on the key, pi on any model of it and the harnesses that talk to that
40
+ * provider's own API (OpenAI's: codex and opencode); OpenRouter's runs them all. `models`: a harness's own default on the
41
+ * key where it is not `model`. On OpenRouter:
41
42
  * pi's is GPT-6 Sol on pi-ai's openrouter provider (/chat/completions, the key as a bearer token, as OpenRouter's docs
42
43
  * name it; its Anthropic models go to /v1/messages with the key in x-api-key, which the docs do not), claude-agent's
43
- * Claude Sonnet 5.5 and codex's GPT-6 Sol, each through OpenRouter's own endpoint for the harness (adapters.ts), the ids
44
+ * Claude Sonnet 5.5 and codex's and opencode's GPT-6 Sol, each through OpenRouter's own endpoint for the harness (adapters.ts), the ids
44
45
  * a live run took through OpenRouter on 2026-10-29. The row order is the order a default is taken in: a direct
45
46
  * provider's key wins over OpenRouter's. */
46
47
  export const MODEL_KEYS = [
47
48
  { id: "anthropic", label: "Anthropic", field: "ANTHROPIC_API_KEY", model: "anthropic/claude-sonnet-5-5", harnesses: [DEFAULT_HARNESS, "claude-agent"] },
48
- { id: "openai", label: "OpenAI", field: "OPENAI_API_KEY", model: "openai/gpt-6.1-sol", harnesses: [DEFAULT_HARNESS, "codex"] },
49
- { id: "openrouter", label: "OpenRouter", field: "OPENROUTER_API_KEY", model: "openrouter/openai/gpt-6-sol", harnesses: [DEFAULT_HARNESS, "claude-agent", "codex"], models: { "claude-agent": "anthropic/claude-sonnet-5.5", codex: "openai/gpt-6-sol" } },
49
+ { id: "openai", label: "OpenAI", field: "OPENAI_API_KEY", model: "openai/gpt-6.1-sol", harnesses: [DEFAULT_HARNESS, "codex", "opencode"] },
50
+ { id: "openrouter", label: "OpenRouter", field: "OPENROUTER_API_KEY", model: "openrouter/openai/gpt-6-sol", harnesses: [DEFAULT_HARNESS, "claude-agent", "codex", "opencode"], models: { "claude-agent": "anthropic/claude-sonnet-5.5", codex: "openai/gpt-6-sol", opencode: "openai/gpt-6-sol" } },
50
51
  ];
51
52
  /** `row`'s default for `harness`: its own (`models`), else the row's. */
52
53
  const rowModel = (row, harness) => row.models?.[harness] ?? row.model;
53
54
  /**
54
55
  * Whether `harness` reaches its vendor's models here only through OpenRouter: OPENROUTER_API_KEY is set and none of the
55
56
  * harness's own settings is. Those win, as on a host with no OpenRouter key: the endpoint the host names
56
- * (ANTHROPIC_BASE_URL for claude-agent, which needs ANTHROPIC_API_KEY; serve's gateway AGENT_MODEL_BASE_URL for codex,
57
- * with AGENT_MODEL_API_KEY or none), then the vendor's own key (ANTHROPIC_API_KEY, OPENAI_API_KEY), then OpenRouter. An
57
+ * (ANTHROPIC_BASE_URL for claude-agent, which needs ANTHROPIC_API_KEY; serve's gateway AGENT_MODEL_BASE_URL for codex
58
+ * and opencode, which take the same route, with AGENT_MODEL_API_KEY or none), then the vendor's own key (ANTHROPIC_API_KEY, OPENAI_API_KEY), then OpenRouter. An
58
59
  * endpoint the host names never gets the OpenRouter key.
59
60
  */
60
61
  export function openRouterOnly(harness, env) {
@@ -82,9 +83,9 @@ export const ADD_A_KEY = `add a model key in Settings → Model keys, or set ${[
82
83
  * and codex take it (adapters.ts' claudeModel and codexProvider). */
83
84
  const onOpenRouter = (id, vendor) => new RegExp(`^openrouter/${vendor}/[^/]+$`).test(id);
84
85
  /** Whether `harness` runs the model `id`: pi any; claude-agent an Anthropic model (`anthropic/...`, or Anthropic's on
85
- * OpenRouter, `openrouter/anthropic/...`), as it talks to an Anthropic Messages endpoint only; codex, behind a gateway
86
+ * OpenRouter, `openrouter/anthropic/...`), as it talks to an Anthropic Messages endpoint only; codex and opencode, behind a gateway
86
87
  * (AGENT_MODEL_BASE_URL), any id, which is the gateway's own string and names no provider here (team/model included),
87
- * as codex takes that gateway for its OpenAI-compatible endpoint; without one, an OpenAI model (`openai/...`, or OpenAI's
88
+ * as each takes that gateway for its OpenAI-compatible endpoint; without one, an OpenAI model (`openai/...`, or OpenAI's
88
89
  * on OpenRouter). On the faux harness every harness runs the run's model. */
89
90
  export function harnessRuns(env, id, harness) {
90
91
  if (harness === DEFAULT_HARNESS || env[FAUX_HARNESS_ENV])
@@ -93,7 +94,7 @@ export function harnessRuns(env, id, harness) {
93
94
  const provider = slash > 0 ? id.slice(0, slash) : undefined;
94
95
  if (harness === "claude-agent")
95
96
  return provider === "anthropic" || onOpenRouter(id, "anthropic");
96
- if (harness === "codex")
97
+ if (harness === "codex" || harness === "opencode")
97
98
  return Boolean(env.AGENT_MODEL_BASE_URL) || provider === "openai" || onOpenRouter(id, "openai");
98
99
  return true;
99
100
  }
@@ -2472,6 +2472,7 @@
2472
2472
  },
2473
2473
  "browser": {
2474
2474
  "type": "string",
2475
+ "description": "The browser a run's `browser` tool drives here: the vendor it resolves to under the server's tool settings (`browserbase` or `kernel`) when `tools[]` lists `browser` as available, else `none`.",
2475
2476
  "enum": [
2476
2477
  "browserbase",
2477
2478
  "chrome",