@parcha/agentrun-serve 0.1.0-beta.47 → 0.1.0-beta.48

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 (110) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +84 -14
  3. package/dist/acp-package.d.ts +24 -6
  4. package/dist/adapter-facts.d.ts +0 -4
  5. package/dist/adapter-facts.js +1 -4
  6. package/dist/adapters.d.ts +3 -12
  7. package/dist/adapters.js +1 -70
  8. package/dist/answer-json.d.ts +10 -0
  9. package/dist/answer-json.js +24 -0
  10. package/dist/api-only.d.ts +5 -2
  11. package/dist/api-only.js +10 -2
  12. package/dist/browser-live.d.ts +9 -4
  13. package/dist/browser-live.js +18 -5
  14. package/dist/cap.js +7 -9
  15. package/dist/cli.js +6 -6
  16. package/dist/computer-routes.d.ts +8 -5
  17. package/dist/computer-routes.js +7 -5
  18. package/dist/computers.d.ts +6 -2
  19. package/dist/computers.js +4 -2
  20. package/dist/conformance.d.ts +4 -0
  21. package/dist/conformance.js +6 -0
  22. package/dist/console/assets/index-CTGegcKt.css +1 -0
  23. package/dist/console/assets/{index-BBFzAxLB.js → index-D1Se6mgG.js} +165 -165
  24. package/dist/console/index.html +2 -2
  25. package/dist/harness-check.d.ts +3 -1
  26. package/dist/harness-check.js +99 -70
  27. package/dist/harness-cursor.d.ts +10 -27
  28. package/dist/harness-cursor.js +5 -84
  29. package/dist/harness-goose.d.ts +4 -29
  30. package/dist/harness-goose.js +6 -86
  31. package/dist/harness-module.d.ts +4 -0
  32. package/dist/harness-module.js +1 -0
  33. package/dist/harness-owned.d.ts +52 -0
  34. package/dist/harness-owned.js +92 -0
  35. package/dist/harness-recipe.js +2 -24
  36. package/dist/harness-table.d.ts +109 -6
  37. package/dist/harness-table.js +242 -28
  38. package/dist/harness.js +2 -2
  39. package/dist/key-refusal.d.ts +2 -1
  40. package/dist/key-refusal.js +18 -2
  41. package/dist/learn/promote.d.ts +11 -0
  42. package/dist/learn/secrets.d.ts +4 -0
  43. package/dist/learn/secrets.js +23 -0
  44. package/dist/learning-model.d.ts +18 -0
  45. package/dist/learning-model.js +77 -0
  46. package/dist/llms.txt +1 -0
  47. package/dist/model-form.js +12 -12
  48. package/dist/model.d.ts +5 -4
  49. package/dist/model.js +19 -13
  50. package/dist/openapi.js +35 -5
  51. package/dist/page.d.ts +1 -0
  52. package/dist/page.js +1 -1
  53. package/dist/run-secrets.d.ts +2 -2
  54. package/dist/run-secrets.js +6 -5
  55. package/dist/run-trace.js +6 -3
  56. package/dist/runner/adapter-loop.d.ts +4 -1
  57. package/dist/runner/adapter-loop.js +1 -2
  58. package/dist/runner/adapter-run-spec.d.ts +3 -2
  59. package/dist/runner/adapter-run-spec.js +8 -4
  60. package/dist/runner/adapters/index.d.ts +4 -2
  61. package/dist/runner/adapters/index.js +6 -42
  62. package/dist/runner/cli-run-spec.js +10 -6
  63. package/dist/runner/conformance/host-tools.d.ts +4 -0
  64. package/dist/runner/conformance/host-tools.js +14 -0
  65. package/dist/runner/meta-tools.js +4 -2
  66. package/dist/runner/presence.d.ts +3 -0
  67. package/dist/runner/presence.js +19 -12
  68. package/dist/runner/promotion.d.ts +62 -4
  69. package/dist/runner/promotion.js +146 -15
  70. package/dist/runner/sdk-loop.js +25 -1
  71. package/dist/runner/workflow-spec.js +3 -2
  72. package/dist/runs-over-store.d.ts +2 -1
  73. package/dist/runs-over-store.js +2 -4
  74. package/dist/sdk/check.d.ts +31 -0
  75. package/dist/sdk/check.js +58 -0
  76. package/dist/sdk/runs.d.ts +10 -2
  77. package/dist/sdk/runs.js +87 -17
  78. package/dist/sdk/schema.js +11 -3
  79. package/dist/server.d.ts +3 -0
  80. package/dist/server.js +116 -40
  81. package/dist/store/sqlite/store.js +35 -30
  82. package/dist/store/store.d.ts +20 -18
  83. package/dist/store-view.d.ts +5 -3
  84. package/dist/store-view.js +9 -7
  85. package/dist/template-eval.js +5 -2
  86. package/dist/template-github-permissions.d.ts +5 -1
  87. package/dist/template-github-permissions.js +7 -3
  88. package/dist/timeline/index.d.ts +1 -1
  89. package/dist/timeline/index.js +1 -1
  90. package/dist/timeline/timeline.d.ts +8 -0
  91. package/dist/timeline/timeline.js +18 -6
  92. package/dist/tool-gate.d.ts +8 -4
  93. package/dist/tool-gate.js +6 -7
  94. package/dist/tool-plane.d.ts +4 -0
  95. package/dist/tool-plane.js +10 -10
  96. package/dist/trigger-targets.d.ts +11 -2
  97. package/dist/trigger-targets.js +71 -2
  98. package/dist/validate.js +5 -1
  99. package/dist/viewer-credential.d.ts +25 -0
  100. package/dist/viewer-credential.js +51 -0
  101. package/dist/workspace/resolve-computer.d.ts +5 -0
  102. package/dist/workspace/resolve-computer.js +19 -1
  103. package/package.json +18 -10
  104. package/templates/code-review/agent.md +2 -3
  105. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  106. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  107. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  108. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  109. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  110. package/dist/console/assets/index-BRi-Rgq6.css +0 -1
@@ -1,8 +1,8 @@
1
1
  // The models a person is offered to pick for each harness, in the exact form that harness takes, and the words a refusal
2
2
  // uses when a model is named in a form it does not take. One list, served in capabilities (`harnesses[].models`) and read
3
3
  // by the console's Model picker, so the picker, the save's refusal and a run's refusal never name different forms.
4
- // A leaf of model.ts and provider.ts (it reads their tables only when called, never as it loads).
5
- import { adapterFactsOf } from "./adapter-facts.js";
4
+ // A leaf of model.ts, provider.ts and harness-table.ts (it reads their tables only when called, never as it loads).
5
+ import { factsOf } from "./harness-table.js";
6
6
  import { FAUX_ENV, MODEL_KEYS } from "./model.js";
7
7
  import { openRouterName } from "./provider.js";
8
8
  import { wireOf } from "./wires.js";
@@ -20,10 +20,10 @@ export const PICKABLE = Object.freeze([
20
20
  { vendor: "openai", ids: Object.freeze(["gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"]) },
21
21
  { vendor: "particle", ids: Object.freeze(["particle-1"]) },
22
22
  ]);
23
- /** The vendors whose models `harness` runs: pi any; an adapter harness, its wire's vendor; one billed to its own plan, none
24
- * of ours. */
25
- const vendorsOf = (harness) => {
26
- const facts = adapterFactsOf(harness);
23
+ /** The vendors whose models `harness` runs on `env`: pi any; an adapter harness (its facts on the table, factsOf), its
24
+ * wire's vendor; one billed to its own plan, none of ours. */
25
+ const vendorsOf = (env, harness) => {
26
+ const facts = factsOf(env, harness);
27
27
  if (!facts)
28
28
  return PICKABLE.map((p) => p.vendor);
29
29
  const settings = wireOf(facts.wire);
@@ -43,14 +43,14 @@ export function formOf(env, vendor, id) {
43
43
  export function pickerCandidates(env, harness) {
44
44
  // A harness billed to its own plan (Cursor) runs its vendor's models, listed by its vendor for its owner's key alone: its
45
45
  // entry's default is offered (harness.ts harnessOffers' default_model), and none of ours.
46
- const facts = adapterFactsOf(harness);
46
+ const facts = factsOf(env, harness);
47
47
  if (env[FAUX_ENV] || (facts && !wireOf(facts.wire)))
48
48
  return [];
49
49
  // The gateway serves the harnesses whose wire goes through it (pi, and the OpenAI Responses wire: providerFor); the
50
50
  // Anthropic Messages wire never does, so Claude is offered Anthropic's models on its own key.
51
51
  if (env.AGENT_MODEL_BASE_URL && facts?.wire !== "anthropic-messages")
52
52
  return [...new Set([env.AGENT_MODEL, env.AGENT_MODEL_FAST, env.AGENT_MODEL_STRONG].filter((id) => Boolean(id)))];
53
- const vendors = vendorsOf(harness);
53
+ const vendors = vendorsOf(env, harness);
54
54
  // Signed in to a ChatGPT plan, its models first for a harness that runs on it (`chatgpt/<model-id>`).
55
55
  const plan = PLAN_HARNESSES.includes(harness) && signedIn(env) ? (planOf(env)?.models ?? []).map((id) => `${PLAN_PROVIDER}/${id}`) : [];
56
56
  return [...plan, ...PICKABLE.filter((p) => vendors.includes(p.vendor)).flatMap((p) => p.ids.map((id) => formOf(env, p.vendor, id)))];
@@ -60,7 +60,7 @@ export function pickerCandidates(env, harness) {
60
60
  * pi with OpenRouter's key, by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
61
61
  * ids are its own) or with the faux model. */
62
62
  export async function freeCandidates(env, harness) {
63
- if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || !env.OPENROUTER_API_KEY || adapterFactsOf(harness))
63
+ if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || !env.OPENROUTER_API_KEY || factsOf(env, harness))
64
64
  return [];
65
65
  const [{ builtinModels }, { withLocalModels, isFree }] = await Promise.all([import("@earendil-works/pi-ai/providers/all"), import("./local-models.js")]);
66
66
  return withLocalModels(builtinModels()).getModels("openrouter").filter(isFree)
@@ -75,7 +75,7 @@ export function likelyModel(env, harness, given) {
75
75
  const wanted = spelled(given);
76
76
  if (!wanted)
77
77
  return undefined;
78
- const vendors = vendorsOf(harness);
78
+ const vendors = vendorsOf(env, harness);
79
79
  for (const { vendor, ids } of PICKABLE) {
80
80
  if (!vendors.includes(vendor))
81
81
  continue;
@@ -98,8 +98,8 @@ export function modelFormWhy(env, harness, named, host) {
98
98
  * either key makes one run. A harness billed to its own plan (Cursor: its wire `plan`, so no vendor of ours) takes its
99
99
  * own form, `<harness>/<model id>`, a model its vendor lists for its owner's key, like its own default. */
100
100
  export function modelShape(env, harness) {
101
- const facts = adapterFactsOf(harness);
102
- const first = PICKABLE.find((p) => vendorsOf(harness).includes(p.vendor));
101
+ const facts = factsOf(env, harness);
102
+ const first = PICKABLE.find((p) => vendorsOf(env, harness).includes(p.vendor));
103
103
  const id = first?.ids[0];
104
104
  if (!first || !id)
105
105
  return `On ${harness}, a model is ${harness}/<model id> (one ${facts?.label ?? harness} lists for your key), like ${harness}/${CURSOR_DEFAULT_MODEL}`;
package/dist/model.d.ts CHANGED
@@ -53,10 +53,11 @@ export declare const MODEL_KEYS: readonly {
53
53
  harnesses: readonly string[];
54
54
  byVendor?: Readonly<Record<string, string>>;
55
55
  }[];
56
- /** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists only once its
57
- * owner installs it (Goose: harness-table.ts hidden, listed by harnessIds) whose wire runs the row's vendor's models, or
58
- * any, on OpenRouter's. One not installed here is never named, nor one billed to its own plan (Cursor: no model key of
59
- * ours runs it). */
56
+ /** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists beyond the
57
+ * built-in ones a row names (one its owner installs, Goose: harness-table.ts hidden, listed by harnessIds; one an owner's
58
+ * harness module adds) whose wire (its facts, factsOf) runs the row's vendor's models, or any, on OpenRouter's. One not
59
+ * installed here is never named, nor a module's harness that gives no facts, nor one billed to its own plan (Cursor: no
60
+ * model key of ours runs it). */
60
61
  export declare function keyHarnesses(row: (typeof MODEL_KEYS)[number], env: NodeJS.ProcessEnv): readonly string[];
61
62
  /** What a person does when no model runs here: add a model provider's key in the console, or set one where AgentRun
62
63
  * starts (MODEL_KEYS' fields), OpenRouter's named first, as its one key runs every harness. The order a default is
package/dist/model.js CHANGED
@@ -8,11 +8,11 @@
8
8
  import { isRouter, withLocalModels } from "./local-models.js";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import { DEFAULT_HARNESS, PLAN_HARNESSES } from "./harness.js";
11
- import { builtinHarness, HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessIds, harnessOf } from "./harness-table.js";
11
+ import { builtinHarness, factsOf, HARNESS_MODULES_ENV, HARNESS_TABLE_ENV, harnessIds, harnessOf } from "./harness-table.js";
12
12
  import { gatewayBase, modelGatewayBase } from "./provider.js";
13
13
  import { modelFormWhy } from "./model-form.js";
14
14
  // Leaves, which the key rows below read as this module loads, in any import order (wires.ts, adapter-facts.ts).
15
- import { ADAPTER_FACTS, adapterFactsOf } from "./adapter-facts.js";
15
+ import { ADAPTER_FACTS } from "./adapter-facts.js";
16
16
  import { modelWire, WIRES, wireOf } from "./wires.js";
17
17
  import { authContextOf } from "./secrets.js";
18
18
  import { EXPIRED, PLAN_DEFAULT_MODEL, PLAN_ORIGIN, PLAN_PROVIDER, planOf, signedIn, SIGNED_OUT } from "./chatgpt-plan.js";
@@ -69,20 +69,26 @@ export const MODEL_KEYS = Object.freeze([
69
69
  function onVendor(vendor) {
70
70
  return [DEFAULT_HARNESS, ...ADAPTER_FACTS.filter((facts) => wireOf(facts.wire)?.vendor === vendor).map((facts) => facts.id)];
71
71
  }
72
- /** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists only once its
73
- * owner installs it (Goose: harness-table.ts hidden, listed by harnessIds) whose wire runs the row's vendor's models, or
74
- * any, on OpenRouter's. One not installed here is never named, nor one billed to its own plan (Cursor: no model key of
75
- * ours runs it). */
72
+ /** The harnesses `row`'s key runs on `env`'s server: its own (`harnesses`), then each harness this server lists beyond the
73
+ * built-in ones a row names (one its owner installs, Goose: harness-table.ts hidden, listed by harnessIds; one an owner's
74
+ * harness module adds) whose wire (its facts, factsOf) runs the row's vendor's models, or any, on OpenRouter's. One not
75
+ * installed here is never named, nor a module's harness that gives no facts, nor one billed to its own plan (Cursor: no
76
+ * model key of ours runs it). */
76
77
  export function keyHarnesses(row, env) {
77
- const installed = harnessIds(env).filter((id) => !row.harnesses.includes(id) && builtinHarness(id)?.hidden !== undefined);
78
- return [...row.harnesses, ...installed.filter((id) => {
79
- const facts = adapterFactsOf(id);
78
+ const added = harnessIds(env).filter((id) => {
79
+ if (row.harnesses.includes(id))
80
+ return false;
81
+ const builtin = builtinHarness(id);
82
+ return builtin === undefined || builtin.hidden !== undefined;
83
+ });
84
+ return [...row.harnesses, ...added.filter((id) => {
85
+ const facts = factsOf(env, id);
80
86
  return facts !== undefined && modelWire(facts.wire) && (row.id === "openrouter" || WIRES[facts.wire].vendor === row.id);
81
87
  })];
82
88
  }
83
- /** `row`'s default for `harness`: the one for its wire's vendor (`byVendor`, OpenRouter's), else the row's. */
84
- const rowModel = (row, harness) => {
85
- const facts = adapterFactsOf(harness);
89
+ /** `row`'s default for `harness` on `env`: the one for its wire's vendor (`byVendor`, OpenRouter's), else the row's. */
90
+ const rowModel = (row, harness, env) => {
91
+ const facts = factsOf(env, harness);
86
92
  const vendor = facts && wireOf(facts.wire)?.vendor;
87
93
  return (vendor ? row.byVendor?.[vendor] : undefined) ?? row.model;
88
94
  };
@@ -131,7 +137,7 @@ export function hostModel(env, tier = "default", harness = DEFAULT_HARNESS) {
131
137
  if (onClaudeLogin(env, harness))
132
138
  return LOGIN_DEFAULT_MODEL;
133
139
  const row = MODEL_KEYS.find((row) => env[row.field] && (row.harnesses.includes(harness) || keyHarnesses(row, env).includes(harness)));
134
- return row ? rowModel(row, harness) : env[DEFAULT_MODEL_ENV] || undefined;
140
+ return row ? rowModel(row, harness, env) : env[DEFAULT_MODEL_ENV] || undefined;
135
141
  }
136
142
  /** The plan's model a run that names none takes: GPT-6.1 Sol where the plan lists it, else the plan's first. */
137
143
  const planModel = (env) => {
package/dist/openapi.js CHANGED
@@ -16,6 +16,7 @@ import { ERROR_STATUS } from "./errors.js";
16
16
  import { COMPUTER_UNAVAILABLE_CODE } from "./computer-lost.js";
17
17
  import { RUNNER_REFUSED_CODE } from "./runner/presence.js";
18
18
  import { TAKE_OVER_MINUTES } from "./computer-routes.js";
19
+ import { VIEWER_CREDENTIAL_MS } from "./viewer-credential.js";
19
20
  import { HOLD_MAX_MINUTES, HOLD_MINUTES } from "./computer-held.js";
20
21
  import { CALL_MS, PROTOCOL_METHODS } from "./computer-channel.js";
21
22
  import { LAUNCH_LOST, SETUP_LOST } from "./files.js";
@@ -745,7 +746,15 @@ const LEARNED_WORKFLOW = {
745
746
  },
746
747
  "x-agentrun-serve": "learning/3",
747
748
  };
749
+ const LEARNING_MODEL = closed({
750
+ location: { enum: ["server", "native"], description: "Server model route, or the connected native runtime's existing sign-in (no copied server key required)." },
751
+ ready: { type: "boolean", description: "The required model route and credential are configured. This read makes no paid model request and does not verify provider quota or future availability." },
752
+ model: { ...NULL_STRING, description: "The resolved model for this agent, or the server default in capabilities; null when none is configured." },
753
+ needs: { enum: ["key", "model", null], description: "What must be configured: a credential for the selected model route, or a supported model. A tool or decision-provider key alone is insufficient." },
754
+ reason: { ...NULL_STRING, description: "Setup guidance when unavailable, or how native sign-in supplies the model." },
755
+ });
748
756
  const AGENT_LEARNING = closed({
757
+ learning_model: LEARNING_MODEL,
749
758
  agent: { type: "string" },
750
759
  main: { ...NULL_STRING, description: "Main's head commit; null while the agent has no learning folder (its learning was never on), when every page is empty." },
751
760
  corrections: { type: "string", description: "corrections.md on main, cut of the host's secrets: what the agent's next run is given whole under # Learned, one line per correction its owner gave. Empty when there is none. GET .../learning/corrections reads it with its ETag; PUT writes it.", "x-agentrun-serve": "learning/4" },
@@ -850,6 +859,7 @@ const COMPUTER_PROVIDER = closedWith({
850
859
  required: { type: "array", items: { type: "string" }, description: "The names of the secrets the provider needs; any other may stay unset." },
851
860
  ready: { type: "boolean", description: "Whether a run could have its computer of this kind here now: it fits this server's folder mode and every required key is saved." },
852
861
  runs_refused: PROVIDER_RUNS_REFUSED,
862
+ folder: { enum: ["bind", "archil", "sync", null], description: "The kind of the run's folder a run of an agent with this computer holds on this server now, by the rule a run's claim picks it by (this server's folder mode, and the provider's keys and image as this server has them): `bind`, a folder of this machine bound in (Mode 1: Docker); `archil`, the owner's Archil disk mounted (Mode 2, where the provider takes an Archil mount and Archil's image is in its account, and its computer of this kind does not dial this server: Modal's sandbox, and E2B's and Agent37's sandbox and desktop; Daytona's sandbox once DAYTONA_ARCHIL_EGRESS and AGENTRUN_DAYTONA_SNAPSHOT are set); `sync`, a synced folder the runner keeps on the owner's disk (Mode 2, any other computer that takes a folder, Modal's desktop among them: it dials this server, so it takes no Archil mount). Null where it holds none: a phone, a browser, a desktop whose provider takes no folder in this mode, or a sandbox this mode refuses (`why` says why). For a computer with no GPUs: `gpu.mounts` says which kinds its GPU computers take. A kind alone, never a key, an image or an address." },
853
863
  shell: CHOICE_SHELL,
854
864
  host_tools: CHOICE_HOST_TOOLS,
855
865
  }, {
@@ -1444,6 +1454,8 @@ const PROMOTION_CHECK = closedWith({
1444
1454
  skipped_tools: SKIPPED_TOOLS,
1445
1455
  disagreements: { type: "array", items: closedWith({ run: { type: "string" }, input: { type: "string", description: "The run's input, as text or JSON, cut at 1200 characters." }, agent: NULL_STRING }, { draft: { type: "string", description: "What it answered instead." }, escalated: { type: "string", description: "Why it handed the input back." }, failed: { const: true, description: "A step failed on it, or its run was still at work past the check's deadline, or never created by then." }, differs_on: { type: "string", description: "When `grader` compared it: the decision the two answers differ on, in the fast model's words, or why its verdict could not be had (\"the comparison could not be read\", \"the cap held the comparison\", or \"the comparison read an earlier answer\" when the agent's run answered again after it was compared). Cut at 1200 characters." } }), description: "On a hold: each input it did not agree on, which the agent's next run reads as data in its one recompile." },
1446
1456
  stopped: { const: true, description: "The recompile's check held it too, or there was nothing to check it on (no input of the agent's it takes, or every input skipped at a write: `n` 0, `reason` starting \"nothing to check it on\", which asks no recompile): nothing compiles again until a hold or its owner acts; the agent keeps the runs." },
1457
+ released: { type: "integer", minimum: 1, description: "A connected agent's check (`via` sdk): how many of its reserved native turns could not be its baseline (cancelled or failed, a learned workflow in the turn, redacted evidence, no shadow report, or a shadow that did not answer) and were given back to wait for the next turn the draft takes. The fifth stops it with nothing checked. Left out when none." },
1458
+ fresh_reads: { type: "integer", minimum: 1, description: "A connected agent's check (`via` sdk): how many fresh read-only calls its shadow made where the native turn's recording had no result (the host's opt-in `shadowReadFallback`). Left out when every call was answered from the recording." },
1447
1459
  });
1448
1460
  const PROMOTION = closedWith({
1449
1461
  workflow: { type: "string" },
@@ -1457,6 +1469,7 @@ const PROMOTION = closedWith({
1457
1469
  inputs: { type: "array", items: { type: "string" }, description: "On a replaying record: the graded run each of `runs` replays, in the same order. Its runs are reserved before they are created; one not created a few minutes on is created by the next claim." },
1458
1470
  replay_id: { type: "string", description: "The replay's id, on its replaying record and the one that decided it: GET .../revisions/{digest}/replays/{replay_id} reads it, whether a run's claim or its owner started it." },
1459
1471
  commit: { type: "string", description: "The learning commit whose workflow.json is this revision's text: what it serves from as the champion while a newer revision replays." },
1472
+ via: { const: "sdk", description: "A connected (SDK) agent's check, on its reservation and on the record that decides it: its one run (`runs`) is the agent's own native turn, checked by the caller's shadow, not a replay run. A `replaying` one with no `runs` waits for the next native turn the draft takes. A turn the backend never completes within an hour is one failed input. Left out for a server replay." },
1460
1473
  audit: closedWith({
1461
1474
  window: { type: "integer", minimum: 1, description: "The definition's `learning.hold_window` when it was held." },
1462
1475
  disagree: { type: "integer", minimum: 1, description: "The definition's `learning.hold_disagree` when it was held." },
@@ -1937,7 +1950,7 @@ const EXTENSIONS = {
1937
1950
  "/runs/{run_id}/computer/take-over": {
1938
1951
  post: {
1939
1952
  operationId: "takeOverRunComputer", tags: ["runs"], summary: "Take over the run's desktop or phone",
1940
- description: `The owner takes the run's desktop or phone: a row the run's runner applies. The take is \`pending\` while the agent's call in flight finishes (never cut in half), then the owner's (\`person\`); the agent's screen, input and phone calls wait meanwhile. At the hand-back a look (a screenshot, the app list) runs on the screen as the owner left it; an act (input, a tap, a swipe, typing, opening an app) is not done, and the agent is told the person had the computer and to look again. The take goes back to the agent on its own after ${TAKE_OVER_MINUTES} minutes with no input from the owner, when the live view closes, or when the computer's session ends. Taking one already pending or taken is the same answer, and writes nothing. 404 when the run has no desktop or phone; 409 \`computer_not_live\` when it is not up now. The run stays working. It takes the owner's password session in the console: never a token (403).`,
1953
+ description: `The owner takes the run's desktop or phone: a row the run's runner applies. The take is \`pending\` while the agent's call in flight finishes (never cut in half), then the owner's (\`person\`); the agent's screen, input and phone calls wait meanwhile. At the hand-back a look (a screenshot, the app list) runs on the screen as the owner left it; an act (input, a tap, a swipe, typing, opening an app) is not done, and the agent is told the person had the computer and to look again. The take goes back to the agent on its own after ${TAKE_OVER_MINUTES} minutes with no input from the owner, when the live view closes, or when the computer's session ends. Taking one already pending or taken is the same answer, and writes nothing. 404 when the run has no desktop or phone; 409 \`computer_not_live\` when it is not up now. The run stays working. It takes the owner's password session in the console: never a token (403). On an API-only server (AGENTRUN_API_ONLY=1), which has no owner, it takes the server's token, the backend's own.`,
1941
1954
  parameters: [ref("parameters/RunId")],
1942
1955
  requestBody: { required: false, content: { "application/json": { schema: closed({}) } } },
1943
1956
  responses: { "200": json(COMPUTER_ANSWER, "Who drives now: pending until the agent's call in flight ends, then the person."), ...errors(401, 403, 404, 409, 422, 429, 500) },
@@ -1947,13 +1960,29 @@ const EXTENSIONS = {
1947
1960
  "/runs/{run_id}/computer/hand-back": {
1948
1961
  post: {
1949
1962
  operationId: "handBackRunComputer", tags: ["runs"], summary: "Hand the run's computer back to the agent, or answer its ask for the owner",
1950
- description: "Every kind of computer. A desktop or a phone: when the run's agent asked for the owner (its `computer_request_handoff` tool; the run reads input_required/waiting), this answers the ask: `outcome` `done` (the default) or `cancelled`, and a take in force ends with it. Otherwise it ends the owner's take, and the agent's waiting calls go on. A browser: this answers its agent's ask as POST /runs/{run_id}/browser/hand-back does, the one answer either route gives. A row the run's runner applies; the first hand-back wins, decided at the write: a second hand-back of the same take, or one after the take went back another way (no input, the live view closed, the computer's session ended), is 409 `handoff_answered` in words; for an ask, the same answer again is that answer and a different one is 409 (`details.outcome`), as is an answer after the ask expired. 404 when the agent asked nothing and nobody took the computer. It takes the owner's password session in the console: never a token (403).",
1963
+ description: "Every kind of computer. A desktop or a phone: when the run's agent asked for the owner (its `computer_request_handoff` tool; the run reads input_required/waiting), this answers the ask: `outcome` `done` (the default) or `cancelled`, and a take in force ends with it. Otherwise it ends the owner's take, and the agent's waiting calls go on. A browser: this answers its agent's ask as POST /runs/{run_id}/browser/hand-back does, the one answer either route gives. A row the run's runner applies; the first hand-back wins, decided at the write: a second hand-back of the same take, or one after the take went back another way (no input, the live view closed, the computer's session ended), is 409 `handoff_answered` in words; for an ask, the same answer again is that answer and a different one is 409 (`details.outcome`), as is an answer after the ask expired. 404 when the agent asked nothing and nobody took the computer. It takes the owner's password session in the console: never a token (403). On an API-only server (AGENTRUN_API_ONLY=1), which has no owner, it takes the server's token, the backend's own.",
1951
1964
  parameters: [ref("parameters/RunId")],
1952
1965
  requestBody: { required: false, content: { "application/json": { schema: closedWith({}, { outcome: { enum: ["done", "cancelled"], description: "The answer to the agent's ask: `done` when the person did what it asked, `cancelled` when they will not. Absent: done." } }) } } },
1953
1966
  responses: { "200": json(COMPUTER_ANSWER, "Who drives now, and the answer the agent gets when this answered its ask."), ...errors(401, 403, 404, 409, 422, 429, 500) },
1954
1967
  "x-agentrun-serve": "computer/1",
1955
1968
  },
1956
1969
  },
1970
+ "/runs/{run_id}/computer/viewer": {
1971
+ post: {
1972
+ operationId: "createRunComputerViewer", tags: ["runs"], summary: "Mint a link to the run's live view for the backend's user",
1973
+ description: `An API-only server's (AGENTRUN_API_ONLY=1): the backend in front of it, with the server's token, asks for a link its user's browser opens, which has no owner's session here. \`url\` is on this server's public address (AGENTRUN_PUBLIC_URL; 501 \`unsupported_here\` when it is unset): the run's open viewer's page, a viewer credential in its query and the viewer's token in its fragment. The credential is bound to this run and lasts ${VIEWER_CREDENTIAL_MS / 60_000} minutes (\`expires_at\`): it opens this run's live page, its files and its WebSocket, from the public address alone (another Origin is 403), and nothing else; the page's answer keeps it in a cookie on the live view's path for its files and socket. Within it the person watches, and takes over and hands back in the viewer's own bar, as the owner's page does. The run's end (completed, failed or cancelled) revokes it on every server on the store, and closes a socket open on it; a stop (input_required) does not, since the run goes on with its next message. A socket opened in time stays open past the minutes, until the run ends. 409 \`computer_not_live\` when the run has ended or its computer has no live view open now (GET /runs/{run_id}/computer reads live once it does). On a server that is not API-only this route is 404: its owner opens the live view in the console.`,
1974
+ parameters: [ref("parameters/RunId")],
1975
+ requestBody: { required: false, content: { "application/json": { schema: closed({}) } } },
1976
+ responses: {
1977
+ "201": json(closed({
1978
+ url: { type: "string", format: "uri", description: "The link to open: `<AGENTRUN_PUBLIC_URL>/v2/runs/{run_id}/computer/live/v/<id>?viewer=<credential>#t=<token>`." },
1979
+ expires_at: { type: "string", format: "date-time", description: "When the credential stops opening the page and its socket." },
1980
+ }), "The link, and when its credential expires."),
1981
+ ...errors(401, 404, 409, 422, 429, 500, 501),
1982
+ },
1983
+ "x-agentrun-serve": "computer/1",
1984
+ },
1985
+ },
1957
1986
  "/runs/{run_id}/start": {
1958
1987
  post: {
1959
1988
  operationId: "startRun", tags: ["runs"], summary: "Start a held run's agent",
@@ -1998,7 +2027,7 @@ const EXTENSIONS = {
1998
2027
  "/runs/{run_id}/computer": {
1999
2028
  get: {
2000
2029
  operationId: "getRunComputer", tags: ["runs"], summary: "Watch the run's computer live and take it over: its viewer link, for the owner",
2001
- description: "The live view of the run's computer, one family for every kind (`browser`, `desktop`, `phone`: the run's agent's computer). `live` with `viewer`, a link on this server (`/v2/runs/{run_id}/computer/live/v/<id>#t=<token>`) to open, or frame, in the console, while a viewer is open; `none` when the run has a computer but no session is up, with `session` saying whether the run hasn't opened it, is opening it, or opened one that closed; `off` when there is no computer view here (its agent has none, its computer is a sandbox, which has no screen, or its computer resolves unavailable here), with `why` in plain words. `kind` is the run's computer, on every answer but `off`. `hold` says who drives now: `agent`; `pending`, the person's Take over waits for the agent's step; `person`. The viewer watches until its Take over, then drives until its Hand back, both in the viewer's own bar: outside a hold the run drops its input. The token is in the link's fragment alone, never in a request line, a Referer or a log; the viewer's page sends it once, in its WebSocket hello. It opens that one session's view, and drives it once taken over: it dies with the computer (its release), the run's end, or the owner's sign-out (the socket closes), and a second viewer of the same session is refused (viewer_in_use). The viewer's page is served under the link's path with `frame-ancestors 'self'`, and its WebSocket is taken only from this server's own origin (or its public address, AGENTRUN_PUBLIC_URL) with the owner's cookie. It takes the owner's password session in the console: never a token, which a run's process, an MCP client or a script may hold (403); no credential is 401. The vendors' own live-view links never leave the run's process.",
2030
+ description: "The live view of the run's computer, one family for every kind (`browser`, `desktop`, `phone`: the run's agent's computer). `live` with `viewer`, a link on this server (`/v2/runs/{run_id}/computer/live/v/<id>#t=<token>`) to open, or frame, in the console, while a viewer is open; `none` when the run has a computer but no session is up, with `session` saying whether the run hasn't opened it, is opening it, or opened one that closed; `off` when there is no computer view here (its agent has none, its computer is a sandbox, which has no screen, or its computer resolves unavailable here), with `why` in plain words. `kind` is the run's computer, on every answer but `off`. `hold` says who drives now: `agent`; `pending`, the person's Take over waits for the agent's step; `person`. The viewer watches until its Take over, then drives until its Hand back, both in the viewer's own bar: outside a hold the run drops its input. The token is in the link's fragment alone, never in a request line, a Referer or a log; the viewer's page sends it once, in its WebSocket hello. It opens that one session's view, and drives it once taken over: it dies with the computer (its release), the run's end, or the owner's sign-out (the socket closes), and a second viewer of the same session is refused (viewer_in_use). The viewer's page is served under the link's path with `frame-ancestors 'self'`, and its WebSocket is taken only from this server's own origin (or its public address, AGENTRUN_PUBLIC_URL) with the owner's cookie. It takes the owner's password session in the console: never a token, which a run's process, an MCP client or a script may hold (403); no credential is 401. On an API-only server (AGENTRUN_API_ONLY=1), which has no owner, it takes the server's token, and the link opens only with the viewer credential POST /runs/{run_id}/computer/viewer mints. The vendors' own live-view links never leave the run's process.",
2002
2031
  parameters: [ref("parameters/RunId")],
2003
2032
  responses: {
2004
2033
  "200": json({ oneOf: [closedWith({ state: { const: "off" }, hold: COMPUTER_HOLD }, { why: { type: "string", description: "Why there is no computer view here, in plain words." } }), closedWith({ state: { const: "none" }, kind: RUN_COMPUTER_KIND, hold: COMPUTER_HOLD, session: { type: "string", enum: ["unopened", "opening", "closed"], description: "Where the run's computer is, read from the run's journal: `unopened`, the run hasn't opened it so far (a browser opens at the agent's first browser step); `opening`, it is being opened now (a browser step that opens it has no result yet; a desktop or a phone from the run's start until it is up); `closed`, the run opened one, which is not up now (a parked run's desktop or phone, kept for the run's resume: the run's timeline says until when; `ended` says why when it was let go while the run waited for its person)." } }, { ended: { type: "object", additionalProperties: false, required: ["at", "why"], description: "A going run's computer let go while the run waited for its person, with none opened since: the words and when. A browser: its window (AGENTRUN_BROWSER_PERSON_WAIT_MIN) ran out, the cap ended it, or its provider ended the session, in the Timeline row's words; the next browser call, once the run goes on, opens a new one. A parked run's desktop or phone kept at its park: its 10 minutes passed (\"The desktop wasn't kept: 10 minutes passed. A new one starts when the run goes on.\"), at the time they did; the run's next claim starts a new one.", properties: { at: { type: "string", format: "date-time" }, why: { type: "string" } } } }), closed({ state: { const: "live" }, kind: RUN_COMPUTER_KIND, viewer: { type: "string", description: "The viewer's link on this server, `/v2/runs/{run_id}/computer/live/v/<id>#t=<token>`: its token in the fragment alone." }, hold: COMPUTER_HOLD })] }, "The run's live view, none open, or no computer here."),
@@ -2987,7 +3016,7 @@ const CONSOLE_URL = (what) => ({ type: "string", format: "uri", description: `Th
2987
3016
  /** The RUN_FIELDS every run's view and summary hold (runs.ts): required, beside the contract's. */
2988
3017
  export const RUN_FIELDS_SENT = ["revision", "kind", "archived_at"];
2989
3018
  /** The capabilities every answer carries beside the contract's required ones (server.ts capabilitiesWith). */
2990
- export const CAPABILITIES_SENT = ["models", "places", "tools", "learning", "switches", "harnesses"];
3019
+ export const CAPABILITIES_SENT = ["learning_model", "models", "places", "tools", "learning", "switches", "harnesses"];
2991
3020
  /** This server's own agent fields every agent answer carries (agents-store.ts agentView): required, beside the contract's. */
2992
3021
  export const AGENT_FIELDS_SENT = ["kind", "revision", "revisions", "archived_at"];
2993
3022
  /** The field every saved sign-in is sent with beside the contract's, required: `secret`, its one secret's metadata
@@ -3516,6 +3545,7 @@ const FIELD_EXTENSIONS = {
3516
3545
  warnings: { type: "array", items: ref("schemas/InputIssue"), description: "What this host still lacks for the agent to run, as a create (POST /agents) or a commit (PUT .../definition) answers it, the same shape apply's warnings take. Absent from every other answer (GET and list never send it).", "x-agentrun-serve": "warnings/1" },
3517
3546
  },
3518
3547
  Capabilities: {
3548
+ learning_model: { ...LEARNING_MODEL, "x-agentrun-serve": "learningmodel/1" },
3519
3549
  learning: {
3520
3550
  type: "object", additionalProperties: false, required: ["pending", "approve"],
3521
3551
  properties: {
@@ -3925,7 +3955,7 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
3925
3955
  }
3926
3956
  // A contract field this server takes with a meaning of its own, said on it.
3927
3957
  definition.properties.max_cost_usd = { ...definition.properties.max_cost_usd, "x-agentrun-serve-note": "The agent's default cap of each run started without a max_cost_usd of its own (a run's own wins), kept with its revision: above 0 sets it, 0 clears it (no default), and an edit that leaves the field out keeps the agent's, so leaving a field out never removes a spend limit. An agentic definition's or a workflow's alike." };
3928
- definition.properties.output_schema = { ...definition.properties.output_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's output is its workflow's): the JSON Schema its final answer's last fenced json block meets, at most 64 KiB, refused at save when it does not compile. A completed run's result.output is that block's value when it meets the schema, else null. An edit that leaves the field out keeps the agent's. A template's answer schema (its manifest's `output`) is set here at apply." };
3958
+ definition.properties.output_schema = { ...definition.properties.output_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's output is its workflow's): the JSON Schema its final answer's last fenced json block meets, at most 64 KiB, refused at save when it does not compile. A completed run's result.output is that block's value when it meets the schema, else null. An edit that leaves the field out keeps the agent's. A template's answer schema (its manifest's `output`) is set here at apply. Its `x-carried`, when given, is an array of unique names of its root `properties`, the fields of the answer a schedule trigger's next run reads back: a last completed result over 32 KiB (as 2-space JSON, in UTF-8 bytes) is handed to that run as those fields alone, read from the schema of the run that produced it. Carried arrays are kept oldest first (the template owns that order; the engine reads no dates): when the fields are over 32 KiB themselves, the largest carried array gives up its oldest entry (its first), one at a time, measured again after each (a tie: the first in `x-carried`), until they fit, and the words name each array's count dropped. A scalar or object is never cut: with no entry left to drop, none of it is handed, said so. Any other `x-carried` is refused at save (field `definition.output_schema.x-carried`)." };
3929
3959
  definition.properties.input_schema = { ...definition.properties.input_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's input is its workflow's own schema): a JSON Schema object schema (`type: object`), at most 64 KiB, refused at save when it does not compile. Every run's `input` is checked against it with the full compiler, by POST /agents/{agent_id}/runs, a trigger's start_run target (at save and when it fires) and a template's triggers, and refused 422 `input_invalid` with an issue at each path (`input.company`, `input.topics.1`). `content` is reserved: named, it is `{type: string}`; it is always taken as text (the run's message), and it stays required when the schema requires nothing else. The run's first message is `content`, then the other fields as one fenced json block under the line `Input:`. Absent: `{content: string}`. An edit that leaves the field out keeps the agent's. A template's `inputs` are set here at apply." };
3930
3960
  const runResult = schemas.RunResult;
3931
3961
  runResult.properties.output = { ...runResult.properties.output, "x-agentrun-serve-note": "A workflow run's output, as its workflow ended; an agentic run's, its final answer's last fenced json block when it meets the agent's output_schema, else null (no schema, no block, not JSON, or a value the schema refuses). The runner gives the model the schema in its instructions on every harness, and asks once more, in the same session under the same cap, when the answer misses it; output_error says why one still missed." };
package/dist/page.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare class ConsoleSessions {
20
20
  /** Whether `value` is a session this server made. */
21
21
  holds(value: string): boolean;
22
22
  }
23
+ export declare const cookiesOf: (req: IncomingMessage, name: string) => string[];
23
24
  export declare const overHttps: (req: IncomingMessage) => boolean;
24
25
  export declare const ownOrigin: (req: IncomingMessage) => string;
25
26
  export declare const isJson: (req: IncomingMessage) => boolean;
package/dist/page.js CHANGED
@@ -67,7 +67,7 @@ export class ConsoleSessions {
67
67
  }
68
68
  /** One name per port: cookies are kept per host, not per port, and another server on this machine has another token. */
69
69
  const cookieName = (req) => `agentrun-${req.socket.localPort}`;
70
- const cookiesOf = (req, name) => String(req.headers.cookie ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(`${name}=`)).map((part) => part.slice(name.length + 1));
70
+ export const cookiesOf = (req, name) => String(req.headers.cookie ?? "").split(";").map((part) => part.trim()).filter((part) => part.startsWith(`${name}=`)).map((part) => part.slice(name.length + 1));
71
71
  export const overHttps = (req) => String(req.headers["x-forwarded-proto"] ?? "").split(",")[0].trim().toLowerCase() === "https";
72
72
  export const ownOrigin = (req) => `${overHttps(req) ? "https" : "http"}://${String(req.headers.host ?? "").toLowerCase()}`;
73
73
  export const isJson = (req) => String(req.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase() === "application/json";
@@ -25,8 +25,8 @@ export declare function needsOf(revision: Revision): Promise<RunNeeds>;
25
25
  * `rows` (TOOL_KEYS) that unlocks none of the tools the run binds; and but each model key its model does not need, from
26
26
  * the host's model settings and the keys in `env`: a pi run's, its models' providers' keys or the gateway's (model.ts'
27
27
  * modelKeys: its own model, or the host's of each tier it runs); a run on an adapter's, the one key its wire's route
28
- * sends for the revision's model (adapters.ts' harnessModelKeys); and but each harness's own key (HarnessEntry.ownKeys:
29
- * Cursor's CURSOR_API_KEY) on a run of any other harness. Read at each claim, so a key saved with no restart counts at
28
+ * sends for the revision's model (adapters.ts' harnessModelKeys); and but each built-in harness's own key
29
+ * (HarnessEntry.ownKeys: Cursor's CURSOR_API_KEY) on a run of any other harness. Read at each claim, so a key saved with no restart counts at
30
30
  * the next. */
31
31
  export declare function keysFor(needs: RunNeeds, env: NodeJS.ProcessEnv, rows?: readonly KeyRow[]): string[];
32
32
  /** The secrets a run of `revision` is handed with the keys `env` holds (needsOf, then keysFor). */
@@ -3,7 +3,7 @@ import { COMPUTER_KEY_NAMES } from "./computer-keys.js";
3
3
  import { BOX_KEYS } from "./place-offers.js";
4
4
  import { providersNamed } from "./decisions.js";
5
5
  import { harnessOfBody } from "./harness.js";
6
- import { BUILTIN_OWN_KEYS, harnessOf, harnessTable } from "./harness-table.js";
6
+ import { BUILTIN_OWN_KEYS, builtinOwns, harnessOf } from "./harness-table.js";
7
7
  import { GATEWAY_KEY_ENV, llmTiers, modelKeys, nodeTiers, PROVIDER_KEYS, workflowNodes } from "./model.js";
8
8
  import { DECISION_KEYS, SECRET_NAMES } from "./secrets.js";
9
9
  import { TOOL_FIELDS, TOOL_KEYS, unlocksTool } from "./tool-keys.js";
@@ -45,16 +45,17 @@ export async function needsOf(revision) {
45
45
  * `rows` (TOOL_KEYS) that unlocks none of the tools the run binds; and but each model key its model does not need, from
46
46
  * the host's model settings and the keys in `env`: a pi run's, its models' providers' keys or the gateway's (model.ts'
47
47
  * modelKeys: its own model, or the host's of each tier it runs); a run on an adapter's, the one key its wire's route
48
- * sends for the revision's model (adapters.ts' harnessModelKeys); and but each harness's own key (HarnessEntry.ownKeys:
49
- * Cursor's CURSOR_API_KEY) on a run of any other harness. Read at each claim, so a key saved with no restart counts at
48
+ * sends for the revision's model (adapters.ts' harnessModelKeys); and but each built-in harness's own key
49
+ * (HarnessEntry.ownKeys: Cursor's CURSOR_API_KEY) on a run of any other harness. Read at each claim, so a key saved with no restart counts at
50
50
  * the next. */
51
51
  export function keysFor(needs, env, rows = TOOL_KEYS) {
52
52
  const unlocked = new Set(rows.filter((row) => row.unlocks.some((unlock) => needs.tools.some((name) => unlocksTool(unlock, name)))).flatMap((row) => row.fields));
53
53
  const scoped = scopedOf(rows);
54
54
  const entry = harnessOf(env, needs.harness);
55
55
  const model = new Set(!entry || entry.facts ? harnessModelKeys(needs.harness, env, needs.model) : needs.tiers ? modelKeys(env, undefined, needs.tiers) : modelKeys(env, needs.model));
56
- const owned = [...BUILTIN_OWN_KEYS, ...Object.values(harnessTable(env)).flatMap((each) => each.ownKeys ?? [])];
57
- return RUN_SECRETS.filter((name) => (!scoped.includes(name) || unlocked.has(name)) && (!MODEL_KEYS.includes(name) || model.has(name)) && (!owned.includes(name) || entry?.ownKeys?.includes(name) === true));
56
+ // A built-in's own key (BUILTIN_OWN_KEYS) goes to the built-in that owns it alone, by the pair (builtinOwns): an entry of
57
+ // any other id that names it in ownKeys (a module's, a test's) is never handed it, nor moves any key.
58
+ return RUN_SECRETS.filter((name) => (!scoped.includes(name) || unlocked.has(name)) && (!MODEL_KEYS.includes(name) || model.has(name)) && (!BUILTIN_OWN_KEYS.includes(name) || builtinOwns(needs.harness, name)));
58
59
  }
59
60
  /** The secrets a run of `revision` is handed with the keys `env` holds (needsOf, then keysFor). */
60
61
  export async function secretsFor(revision, rows = TOOL_KEYS, env = process.env) {
package/dist/run-trace.js CHANGED
@@ -14,6 +14,9 @@ const finite = (value) => (typeof value === "number" && Number.isFinite(value) ?
14
14
  const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
15
15
  /** A time as the rows write theirs; undefined for one no Date holds. */
16
16
  const iso = (ms) => (Math.abs(ms) <= 8.64e15 ? new Date(ms).toISOString() : undefined);
17
+ /** An amount with a sum's floating-point noise off (0.1 + 0.2 is 0.3, not 0.30000000000000004), to a millionth of a
18
+ * millionth of a dollar: far below any price, so no cost is rounded away. Every span's cost is written through it. */
19
+ const noiseOff = (usd) => Math.round(usd * 1e12) / 1e12;
17
20
  const STOP_REASONS = new Set(["stop", "length", "toolUse", "error", "aborted", "deferred", "pending"]);
18
21
  /** An answer's tokens, by the usage row's rule (timeline tokensOf): all four known, and some input unless it failed. */
19
22
  function tokensOf(usage, failed) {
@@ -104,7 +107,7 @@ export function traceSpans(rows, entries, options = {}) {
104
107
  stop_reason: typeof message.stopReason === "string" && STOP_REASONS.has(message.stopReason) ? message.stopReason : null,
105
108
  // A request cut before its end reported no final usage and no cost (the usage row counts it unknown).
106
109
  tokens: aborted ? null : tokensOf(message.usage, failed),
107
- usd: booked || aborted || total === undefined || total < 0 ? null : total, decision: false,
110
+ usd: booked || aborted || total === undefined || total < 0 ? null : noiseOff(total), decision: false,
108
111
  charged: false, not_metered: false, tool_use_id: null, input_preview: null, result_preview: null, result_size_bytes: null,
109
112
  });
110
113
  }
@@ -128,7 +131,7 @@ export function traceSpans(rows, entries, options = {}) {
128
131
  stop_reason: null,
129
132
  // A receipt keeps its input whole, with no split by cache.
130
133
  tokens: input !== undefined && output !== undefined ? { input, cache_read: 0, cache_write: 0, output } : null,
131
- usd: cost !== undefined && cost >= 0 ? cost : null, decision: true,
134
+ usd: cost !== undefined && cost >= 0 ? noiseOff(cost) : null, decision: true,
132
135
  charged: false, not_metered: false, tool_use_id: null, input_preview: null, result_preview: null, result_size_bytes: null,
133
136
  });
134
137
  });
@@ -219,7 +222,7 @@ export function traceSpans(rows, entries, options = {}) {
219
222
  at, id: nth === 0 ? `t:${key}` : `t:${key}#${nth + 1}`, kind: "tool", parent_id: parent, name: use.tool_name ?? "tool", agent_label: use.agent_label ?? null,
220
223
  started_at: iso(at) ?? use.timestamp, ended_at: over ? iso(done) ?? null : null, status,
221
224
  stop_reason: null, tokens: null,
222
- usd: charge?.charged ? (charge.unknown ? null : Math.round(charge.known * 1e12) / 1e12) : null,
225
+ usd: charge?.charged ? (charge.unknown ? null : noiseOff(charge.known)) : null,
223
226
  decision: false, charged: charge?.charged ?? false, not_metered: charge?.notMetered ?? false,
224
227
  tool_use_id: use.tool_use_id, input_preview: use.tool_input_preview ?? null,
225
228
  // A call that never ran has no result of its own: what its rows say of it is the Timeline's words, not its output.
@@ -1,5 +1,5 @@
1
1
  import { type ConversationId, type ConversationRetryPolicy, type ConversationStreamOptions, Harness, type Tx } from "@earendil-works/pi-durable";
2
- import { type AgentAdapter, type Refusal, type SessionRecord, type SessionSpec } from "@parcha/agentrun-kernel";
2
+ import { type AdapterFacts, type AgentAdapter, type Refusal, type SessionRecord, type SessionSpec } from "@parcha/agentrun-kernel";
3
3
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
4
4
  import { type BudgetData, type EndData, type ToolCalls } from "./journal-kinds.js";
5
5
  import { type MessageOrigin } from "../timeline/index.js";
@@ -79,6 +79,9 @@ export type SpecGate = ((call: ToolCall, options?: {
79
79
  /** What one claimed run's adapter loop runs. */
80
80
  export interface AdapterRunSpec {
81
81
  readonly adapter: AgentAdapter;
82
+ /** The adapter's facts on the owner's table (harness-table.ts factsOf: a module's harness's too); undefined for one with
83
+ * none. Always given: what codemode and tool search read, so a caller names them. */
84
+ readonly facts: AdapterFacts | undefined;
82
85
  readonly session: SessionSpec;
83
86
  /** The person's first message, sent once, on the run's first claim. */
84
87
  readonly input: string;
@@ -48,7 +48,6 @@ import { sideEffect } from "./side-effects.js";
48
48
  import { McpClaimRefused } from "./mcp-claim.js";
49
49
  import { CODEMODE, defersCatalog, isCatalogWire, TOOLS_CALL, TOOLS_SEARCH } from "@parcha/agentrun-kernel";
50
50
  import { metaTools } from "./meta-tools.js";
51
- import { builtinHarness } from "../harness-table.js";
52
51
  import { Fenced } from "../store/index.js";
53
52
  import { answerAsServed } from "../answer-json.js";
54
53
  import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
@@ -2050,7 +2049,7 @@ function adapterLoop(specOf, options, deps) {
2050
2049
  }
2051
2050
  },
2052
2051
  });
2053
- const facts = builtinHarness(spec.adapter.id)?.facts;
2052
+ const { facts } = spec;
2054
2053
  // tools_search, tools_call and codemode over the session's tools (meta-tools.ts), on every harness (codemode on
2055
2054
  // each but one that runs scripts of its own): what they call is called nested, each call asked about and recorded
2056
2055
  // as its own tool's. A search finds a tool whose setting is not deny; an MCP tool's setting is its catalog name's.
@@ -1,6 +1,6 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
3
- import type { HostTool, Wire } from "@parcha/agentrun-kernel";
3
+ import type { AdapterFacts, HostTool, Wire } from "@parcha/agentrun-kernel";
4
4
  import type { Approvals } from "../approvals.js";
5
5
  import type { installForClaim, installSettled } from "../harness-install.js";
6
6
  import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
@@ -228,9 +228,10 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
228
228
  harness?: string;
229
229
  approvals?: Approvals;
230
230
  };
231
- }, root: RunFiles, shell?: ShellPlace, options?: {
231
+ }, root: RunFiles, shell: ShellPlace | undefined, options: {
232
232
  readonly effectOf?: (name: string) => ToolEffect | undefined;
233
233
  readonly argumentsOf?: ArgumentsOf;
234
+ readonly facts: AdapterFacts | undefined;
234
235
  }): Promise<NonNullable<AdapterRunSpec["gate"]> & {
235
236
  readonly permissions: RunPermissions;
236
237
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
@@ -16,6 +16,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
16
16
  import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
17
17
  import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
18
18
  import { inspectWorkflow } from "@parcha/agentrun-dsl";
19
+ import { factsOf } from "../harness-table.js";
19
20
  import { decisionProvidersIn } from "../decisions.js";
20
21
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
21
22
  import { liveForRun, runnerLiveOf } from "../live-reach.js";
@@ -155,7 +156,7 @@ export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps
155
156
  export function modelAskOf(pinned, ref) {
156
157
  return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
157
158
  }
158
- export async function adapterRunGate(store, claim, revision, root, shell, options = {}) {
159
+ export async function adapterRunGate(store, claim, revision, root, shell, options) {
159
160
  let current = await storeSettings(store);
160
161
  const approvers = await readApprovers(store.settings);
161
162
  // A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
@@ -163,7 +164,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
163
164
  // Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
164
165
  // default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
165
166
  // An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
166
- const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}) };
167
+ const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}), facts: options.facts };
167
168
  const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
168
169
  // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
169
170
  let learned = [];
@@ -473,8 +474,10 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
473
474
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
474
475
  // The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
475
476
  // the same path), for its path checks; it reads nothing in it.
476
- // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
477
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {});
477
+ // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's facts
478
+ // are its entry's on the owner's table (factsOf): none for pi, nor for a module's harness on a runner of its own.
479
+ const facts = factsOf(deps.env, revision.body.harness);
480
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts });
478
481
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
479
482
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
480
483
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -677,6 +680,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
677
680
  }), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
678
681
  return {
679
682
  adapter,
683
+ facts,
680
684
  // Who keeps the run's visible record: its runner says (none: the adapter, as pi keeps its own).
681
685
  ...(runner.record ? { record: runner.record } : {}),
682
686
  session,
@@ -34,6 +34,8 @@ export interface RunnerHarness {
34
34
  /** Every harness the runner runs, by name. */
35
35
  export declare const RUNNER_HARNESSES: Readonly<Record<string, RunnerHarness>>;
36
36
  /** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
37
- * the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner). Undefined when
38
- * the table has none by that name. `env`: the run's environment (this process's when not given). */
37
+ * the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
38
+ * other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
39
+ * run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
40
+ * the run's environment (this process's when not given). */
39
41
  export declare function resolveHarness(harness: string, env?: NodeJS.ProcessEnv): RunnerHarness | undefined;
@@ -1,10 +1,7 @@
1
1
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
2
2
  import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
3
3
  import { facts as openCodeFacts } from "../../harness-opencode/facts.js";
4
- import { harnessOf } from "../../harness-table.js";
5
- import { acpPackage } from "../../acp-package.js";
6
- import { GOOSE_ID } from "../../harness-goose.js";
7
- import { CURSOR_ID } from "../../harness-cursor.js";
4
+ import { harnessOf, ON_TABLE } from "../../harness-table.js";
8
5
  import { piAdapter } from "./pi.js";
9
6
  const CLAUDE_PACKAGE = "@parcha/agentrun-harness-claude";
10
7
  const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
@@ -76,48 +73,15 @@ export const RUNNER_HARNESSES = {
76
73
  });
77
74
  },
78
75
  },
79
- // Goose, where its package is beside serve (acp-package.ts): on the binary `extra.binary` names, which its owner
80
- // installed (harness-goose.ts); a run on serve's table builds its adapter from its entry (adapters.ts gooseOf).
81
- [GOOSE_ID]: {
82
- record: "loop",
83
- adapter: async (launch, extra = {}) => {
84
- const acp = acpPackage();
85
- if (!acp)
86
- throw new Error("Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
87
- if (typeof extra.binary !== "string")
88
- throw new Error("Goose's runner adapter needs the installed binary's path (extra.binary)");
89
- return acp.gooseAdapter({
90
- model: launch.model,
91
- provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}), ...(launch.provider.auth ? { auth: launch.provider.auth } : {}) },
92
- ...(launch.price ? { price: launch.price } : {}),
93
- ...(launch.fetch ? { fetch: launch.fetch } : {}),
94
- sessionsDir: launch.sessionsDir,
95
- ...extra,
96
- });
97
- },
98
- },
99
- // Cursor, where the same package is beside serve: on the launcher `extra.binary` names, which its owner installed
100
- // (harness-cursor.ts), and its owner's key read by name from `extra.env`; billed to the owner's Cursor plan, so the
101
- // launch's provider and price are never its. A run on serve's table builds its adapter from its entry (adapters.ts
102
- // cursorOf).
103
- [CURSOR_ID]: {
104
- record: "loop",
105
- adapter: async (launch, extra = {}) => {
106
- const acp = acpPackage();
107
- if (!acp)
108
- throw new Error("Cursor's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
109
- if (typeof extra.binary !== "string")
110
- throw new Error("Cursor's runner adapter needs the installed launcher's path (extra.binary)");
111
- return acp.cursorAdapter({ sessionsDir: launch.sessionsDir, ...extra });
112
- },
113
- },
114
76
  };
115
77
  /** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
116
- * the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner). Undefined when
117
- * the table has none by that name. `env`: the run's environment (this process's when not given). */
78
+ * the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
79
+ * other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
80
+ * run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
81
+ * the run's environment (this process's when not given). */
118
82
  export function resolveHarness(harness, env = process.env) {
119
83
  const entry = harnessOf(env, harness);
120
84
  if (!entry)
121
85
  return undefined;
122
- return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : undefined);
86
+ return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : entry.facts && entry.adapter ? ON_TABLE : undefined);
123
87
  }