@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.44

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 (141) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/README.md +213 -24
  3. package/dist/cli.js +42 -8
  4. package/dist/composio-preset.d.ts +4 -3
  5. package/dist/composio-preset.js +12 -4
  6. package/dist/composio-triggers.d.ts +20 -2
  7. package/dist/composio-triggers.js +183 -17
  8. package/dist/computer-lost.d.ts +11 -0
  9. package/dist/computer-lost.js +19 -0
  10. package/dist/computer-record.d.ts +10 -2
  11. package/dist/computer-record.js +50 -18
  12. package/dist/computer-setting.d.ts +1 -0
  13. package/dist/computer-setting.js +2 -2
  14. package/dist/console/assets/index-BUktRvS-.css +1 -0
  15. package/dist/console/assets/index-nB9kTfIN.js +711 -0
  16. package/dist/console/index.html +2 -2
  17. package/dist/errors.d.ts +1 -0
  18. package/dist/errors.js +3 -0
  19. package/dist/harness-table.d.ts +51 -3
  20. package/dist/harness-table.js +101 -13
  21. package/dist/harness.d.ts +18 -1
  22. package/dist/harness.js +21 -9
  23. package/dist/host.d.ts +12 -10
  24. package/dist/host.js +18 -16
  25. package/dist/import-worker.d.ts +3 -0
  26. package/dist/import-worker.js +7 -5
  27. package/dist/import.d.ts +22 -1
  28. package/dist/import.js +141 -28
  29. package/dist/learn/check.d.ts +3 -0
  30. package/dist/learn/check.js +1 -1
  31. package/dist/learn/compile.js +1 -1
  32. package/dist/learn/delete.d.ts +17 -0
  33. package/dist/learn/delete.js +44 -0
  34. package/dist/learn/promote.d.ts +7 -1
  35. package/dist/learn/promote.js +8 -4
  36. package/dist/learn/skills.d.ts +4 -0
  37. package/dist/learn/skills.js +17 -1
  38. package/dist/learn/workflow-nodes.d.ts +22 -1
  39. package/dist/learn/workflow-nodes.js +28 -9
  40. package/dist/learning-cost.d.ts +100 -0
  41. package/dist/learning-cost.js +116 -1
  42. package/dist/learning-evals.d.ts +2 -0
  43. package/dist/learning-evals.js +4 -3
  44. package/dist/learning-routes.d.ts +8 -0
  45. package/dist/learning-routes.js +17 -0
  46. package/dist/learning.d.ts +1 -1
  47. package/dist/listen-first.d.ts +30 -0
  48. package/dist/listen-first.js +115 -0
  49. package/dist/llms.txt +2 -1
  50. package/dist/mcp-servers-store.d.ts +12 -12
  51. package/dist/model.d.ts +8 -4
  52. package/dist/model.js +16 -8
  53. package/dist/openapi.js +115 -39
  54. package/dist/owner.d.ts +8 -0
  55. package/dist/owner.js +11 -0
  56. package/dist/paid-calls.d.ts +6 -0
  57. package/dist/paid-calls.js +11 -1
  58. package/dist/place.d.ts +8 -3
  59. package/dist/place.js +13 -9
  60. package/dist/provider.js +15 -1
  61. package/dist/run-learning-served.d.ts +1 -1
  62. package/dist/run-model-key.d.ts +64 -0
  63. package/dist/run-model-key.js +147 -0
  64. package/dist/runner/adapter-loop.d.ts +6 -0
  65. package/dist/runner/adapter-loop.js +9 -2
  66. package/dist/runner/adapter-run-spec.d.ts +6 -3
  67. package/dist/runner/adapter-run-spec.js +70 -23
  68. package/dist/runner/adapters/index.d.ts +4 -2
  69. package/dist/runner/adapters/index.js +13 -4
  70. package/dist/runner/audit.d.ts +4 -0
  71. package/dist/runner/audit.js +15 -4
  72. package/dist/runner/beside.d.ts +2 -1
  73. package/dist/runner/beside.js +5 -2
  74. package/dist/runner/claim-secrets.d.ts +49 -0
  75. package/dist/runner/claim-secrets.js +110 -1
  76. package/dist/runner/cli-run-spec.d.ts +2 -1
  77. package/dist/runner/cli-run-spec.js +32 -13
  78. package/dist/runner/commands.d.ts +3 -6
  79. package/dist/runner/feedback-round.d.ts +3 -2
  80. package/dist/runner/feedback-round.js +7 -3
  81. package/dist/runner/harness-loops.js +30 -8
  82. package/dist/runner/journal-kinds.d.ts +5 -0
  83. package/dist/runner/learning-end.d.ts +3 -0
  84. package/dist/runner/learning-end.js +4 -0
  85. package/dist/runner/loop-contract.d.ts +6 -0
  86. package/dist/runner/loop-contract.js +4 -0
  87. package/dist/runner/loop.js +6 -2
  88. package/dist/runner/main.d.ts +1 -0
  89. package/dist/runner/main.js +24 -7
  90. package/dist/runner/memory-claim.d.ts +9 -6
  91. package/dist/runner/memory-claim.js +12 -9
  92. package/dist/runner/promotion.d.ts +5 -0
  93. package/dist/runner/promotion.js +46 -7
  94. package/dist/runner/reflect-hook.d.ts +4 -0
  95. package/dist/runner/reflect-hook.js +22 -3
  96. package/dist/runner/runner.js +57 -4
  97. package/dist/runner/store-secrets.js +9 -5
  98. package/dist/runner/workflow-spec.js +10 -2
  99. package/dist/runs-over-store.d.ts +5 -4
  100. package/dist/runs-over-store.js +13 -3
  101. package/dist/sdk/workflows.d.ts +1 -1
  102. package/dist/server.d.ts +64 -50
  103. package/dist/server.js +457 -120
  104. package/dist/store/index.d.ts +2 -2
  105. package/dist/store/index.js +1 -1
  106. package/dist/store/seal.d.ts +20 -2
  107. package/dist/store/seal.js +24 -8
  108. package/dist/store/sqlite/run-launch.d.ts +4 -1
  109. package/dist/store/sqlite/run-launch.js +12 -0
  110. package/dist/store/sqlite/store.d.ts +3 -2
  111. package/dist/store/sqlite/store.js +118 -16
  112. package/dist/store/store.d.ts +38 -3
  113. package/dist/store-reads/analytics.js +11 -1
  114. package/dist/store-reads/learning.d.ts +41 -2
  115. package/dist/store-reads/learning.js +158 -5
  116. package/dist/store-reads/stats.js +13 -3
  117. package/dist/store-view.d.ts +5 -1
  118. package/dist/store-view.js +12 -11
  119. package/dist/telemetry.d.ts +59 -0
  120. package/dist/telemetry.js +153 -0
  121. package/dist/tool-keys-store.d.ts +1 -1
  122. package/dist/tool-keys.d.ts +2 -2
  123. package/dist/tool-plane.d.ts +12 -12
  124. package/dist/tools.d.ts +11 -11
  125. package/dist/tools.js +18 -5
  126. package/dist/trigger-adapter.d.ts +3 -0
  127. package/dist/trigger-adapters.d.ts +4 -0
  128. package/dist/trigger-adapters.js +13 -0
  129. package/dist/trigger-composio.d.ts +58 -1
  130. package/dist/trigger-composio.js +160 -6
  131. package/dist/triggers.d.ts +4 -0
  132. package/dist/triggers.js +22 -3
  133. package/dist/validate.d.ts +11 -7
  134. package/dist/validate.js +8 -7
  135. package/dist/workspace/computer-for-claim.d.ts +15 -5
  136. package/dist/workspace/computer-for-claim.js +228 -32
  137. package/dist/workspace/resolve-computer.d.ts +8 -2
  138. package/dist/workspace/resolve-computer.js +1 -1
  139. package/package.json +10 -9
  140. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  141. package/dist/console/assets/index-Bz6IWncl.js +0 -711
@@ -11,6 +11,10 @@ import { randomUUID } from "node:crypto";
11
11
  import { hostname } from "node:os";
12
12
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
13
13
  import { COMMAND_KINDS, endedReason } from "./commands.js";
14
+ import { COMPUTER_CALL } from "../computer-channel.js";
15
+ import { COMPUTER_HAND_BACK, COMPUTER_TAKE_OVER } from "../computer-commands.js";
16
+ import { HELD_COMMANDS } from "../computer-held.js";
17
+ import { HAND_BACK } from "./hand-back.js";
14
18
  import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
15
19
  import { journalEntries } from "./journal-reader.js";
16
20
  import { ClaimRefused, stopEnd } from "./loop-contract.js";
@@ -59,6 +63,9 @@ class EndNotWithdrawn extends Error {
59
63
  }
60
64
  /** The first wait after a stopped end that withdraws a call is refused; each later one doubles (RunnerOptions). */
61
65
  export const END_RETRY_BACKOFF_MS = 5_000;
66
+ /** The command rows a row that cannot be delivered yet does not hold back (runner.ts deliver), beside a stop and a cancel:
67
+ * those that act on the run's computer for its owner, so a stop that kept the computer can still let it go. */
68
+ const PASSES_A_BLOCKED_ROW = new Set([...HELD_COMMANDS, COMPUTER_CALL, HAND_BACK, COMPUTER_TAKE_OVER, COMPUTER_HAND_BACK]);
62
69
  /** The longest wait between those tries: 5 min. */
63
70
  export const END_RETRY_CAP_MS = 300_000;
64
71
  /** The tries at that cap before the run ends stopped on its row alone (about an hour of retries in all; endRefused). */
@@ -270,6 +277,11 @@ export function startRunner(options) {
270
277
  delivery = (async () => {
271
278
  try {
272
279
  const rows = given ?? (await store.commands(held.claim.runId, held.cursor));
280
+ // A row whose delivery threw (its loop could not take it yet: a message whose model key cannot be read, adapter-
281
+ // loop.ts command) blocks the rows after it, which wait in order behind it, but a stop or a cancel: those still
282
+ // reach the loop, so a run is never kept turning and spending behind a row it cannot take. The cursor stays before
283
+ // the blocked row, which the next poll delivers again; the error is said once the rows are read.
284
+ let blocked;
273
285
  for (const row of rows) {
274
286
  if (held.stopping || held.ending || held.fence.lost || killed)
275
287
  break;
@@ -279,16 +291,55 @@ export function startRunner(options) {
279
291
  // The cursor moves past a row only once its delivery went through (handed to the loop, and any refusal written):
280
292
  // a delivery that throws leaves the row for the next poll, never skipped for the rest of the claim.
281
293
  if (row.takenAt !== null) {
282
- held.cursor = Math.max(held.cursor, row.id);
294
+ if (!blocked)
295
+ held.cursor = Math.max(held.cursor, row.id);
296
+ continue;
297
+ }
298
+ // A row handed on past a blocked row earlier (PASSES_A_BLOCKED_ROW) is never handed on again.
299
+ if (held.passed.has(row.id)) {
300
+ if (!blocked)
301
+ held.cursor = Math.max(held.cursor, row.id);
283
302
  continue;
284
303
  }
285
304
  if (row.kind === "stop" || row.kind === "cancel") {
286
- held.cursor = Math.max(held.cursor, row.id);
305
+ if (!blocked)
306
+ held.cursor = Math.max(held.cursor, row.id);
287
307
  stopLoop(held, { kind: "command", commandId: row.id, ...(row.kind === "cancel" ? { cancel: true } : {}) });
288
308
  // A stop that keeps the run's computer leaves the rows after it to be handed on (the loop head ends the rest).
289
309
  continue;
290
310
  }
291
- const outcome = COMMAND_KINDS.has(row.kind) ? await held.loop.command(row) : { refused: `no command is of kind ${JSON.stringify(row.kind)}` };
311
+ // Past a blocked row, the commands that act on the run's computer for its owner go on too (a release, a start,
312
+ // a call, a take-over and a hand-back): a stop that kept the computer must still be able to let it go. Each is
313
+ // handed on once (held.passed), the cursor still before the blocked row; the message itself is never handed on.
314
+ if (blocked) {
315
+ if (!PASSES_A_BLOCKED_ROW.has(row.kind) || held.passed.has(row.id))
316
+ continue;
317
+ try {
318
+ const passed = await held.loop.command(row);
319
+ // Marked handed on only once its answer is kept: a refusal whose write fails is asked of the loop again at the
320
+ // next delivery, so its caller hears it once the store answers, never a silence.
321
+ if ("refused" in passed) {
322
+ await store.take(held.claim, row.id, "refused", passed.refused);
323
+ emit({ type: "refused", runId: held.claim.runId, commandId: row.id, reason: passed.refused });
324
+ }
325
+ held.passed.add(row.id);
326
+ }
327
+ catch (error) {
328
+ if (isFenced(error) || held.sealed || killed)
329
+ throw error;
330
+ }
331
+ continue;
332
+ }
333
+ let outcome;
334
+ try {
335
+ outcome = COMMAND_KINDS.has(row.kind) ? await held.loop.command(row) : { refused: `no command is of kind ${JSON.stringify(row.kind)}` };
336
+ }
337
+ catch (error) {
338
+ if (isFenced(error) || held.sealed || killed)
339
+ throw error;
340
+ blocked = { error };
341
+ continue;
342
+ }
292
343
  if (held.sealed || killed)
293
344
  return;
294
345
  // `taken`: the loop's commit took it. `later`: left untaken for the run's next claim. Only a refusal is written here.
@@ -298,6 +349,8 @@ export function startRunner(options) {
298
349
  }
299
350
  held.cursor = Math.max(held.cursor, row.id);
300
351
  }
352
+ if (blocked)
353
+ throw blocked.error;
301
354
  }
302
355
  catch (error) {
303
356
  if (held.sealed || killed)
@@ -631,7 +684,7 @@ export function startRunner(options) {
631
684
  },
632
685
  redact,
633
686
  });
634
- const held = { claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false, deliverAgain: false, mib };
687
+ const held = { passed: new Set(), claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false, deliverAgain: false, mib };
635
688
  heldNow = held;
636
689
  // The loop's own end landed: the run is ending from here, its teardown included (no renew, no lost claim).
637
690
  ending = () => {
@@ -7,7 +7,7 @@
7
7
  // flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
8
8
  // and webhook secret among them, and the outbound webhook's signing secret, each it held before too (trigger_settings),
9
9
  // but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
10
- // part. Beside the store, what the data directory keeps where the runner shares it (server-secrets.ts besideTheStore: the
10
+ // part (a run's handed MCP credentials and its own model key). Beside the store, what the data directory keeps where the runner shares it (server-secrets.ts besideTheStore: the
11
11
  // owner's API token and the sign-in session secret). Each value in every spelling the server's list has
12
12
  // (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
13
13
  // is left out: the store never holds one in the clear, and nothing of this runner can be handed it.
@@ -55,20 +55,24 @@ function jsonSecrets(text) {
55
55
  walk(value);
56
56
  return out;
57
57
  }
58
- /** A launch's sealed JSON: its own listed values (jsonSecrets), and each handed MCP credential's headers (store/seal.ts
59
- * sealRunMcpAuth: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed. */
58
+ /** A launch's sealed JSON: its own listed values (jsonSecrets), each handed MCP credential's headers (store/seal.ts
59
+ * sealRunLaunch: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed, and the run's own model
60
+ * key (`{"model": {"key": "..."}}`). */
60
61
  function launchSecrets(text) {
61
62
  const out = jsonSecrets(text);
62
- let mcp;
63
+ let opened;
63
64
  try {
64
- mcp = JSON.parse(text)?.mcp;
65
+ opened = JSON.parse(text);
65
66
  }
66
67
  catch {
67
68
  return out;
68
69
  }
70
+ const mcp = opened?.mcp;
69
71
  if (mcp && typeof mcp === "object")
70
72
  for (const entry of Object.values(mcp))
71
73
  out.push(...jsonSecrets(JSON.stringify(entry)));
74
+ if (typeof opened?.model?.key === "string")
75
+ out.push(opened.model.key);
72
76
  return out;
73
77
  }
74
78
  /** The ChatGPT sign-in's sealed row (chatgpt-plan.ts): its access and refresh tokens, each alone, as a renewal in any
@@ -33,7 +33,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
33
33
  import { bookedIn, parallelExtractFee, parallelSearchFee } from "../paid-calls.js";
34
34
  import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
35
35
  import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
36
- import { claimSecrets, withModelKeys } from "./claim-secrets.js";
36
+ import { claimModelEnv, claimModelKey, claimSecrets, holdRunKey, keyedAtClaim, withoutModelKeys } from "./claim-secrets.js";
37
37
  import { routeOf } from "./model-route.js";
38
38
  import { capModelOf, PI_WIRES, storeSettings } from "./adapter-run-spec.js";
39
39
  import { policyFor } from "./adapters/pi.js";
@@ -163,7 +163,15 @@ export function workflowSpecOf(deps) {
163
163
  // The run's models resolve the one way the runner resolves any (routeProviderOf over routeOf), unless a test gives its
164
164
  // own: each tier's key from the runner's environment, else the one the claim opened (a key saved in
165
165
  // Settings → Model keys runs the next run with no restart).
166
- const providerOf = deps.providerOf ?? routeProviderOf(withModelKeys(deps.env ?? process.env, claimedEnv));
166
+ // A run with its own model key (model_key, sealed in its launch): every model node carries that key alone, and no model
167
+ // key is on the env its decisions and call nodes run under. A workflow run takes no message, so its key is the one
168
+ // its start handed, for the run's life.
169
+ const runKey = await claimModelKey({ store: deps.store, sealKey: deps.sealKey, env: deps.env ?? process.env }, claim.runId);
170
+ if (keyedAtClaim(runKey))
171
+ withoutModelKeys(claimedEnv);
172
+ if (runKey && run?.redact)
173
+ holdRunKey(heldRedactor(run.redact), runKey);
174
+ const providerOf = deps.providerOf ?? routeProviderOf(claimModelEnv(deps.env ?? process.env, claimedEnv, runKey));
167
175
  // Each tier's provider and cap model, resolved once; the proxies start here (before the Harness opens, since the models
168
176
  // catalog the Harness takes points at them), their hooks deferred to the booking wired at harnessReady.
169
177
  const providers = new Map();
@@ -7,7 +7,7 @@ import { type Place } from "./place.js";
7
7
  import { type RepoBinding } from "./run-repo.js";
8
8
  import { type LaunchDisk, type RunLaunch, type SeedFailed } from "./run-launch.js";
9
9
  import { type ApprovalDecision, type RunMoment } from "./run-view.js";
10
- import { type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
10
+ import { type LaunchSealed, type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
11
11
  import { type ToolSettingsMap } from "./tool-plane.js";
12
12
  import type { RunTrigger } from "./triggers.js";
13
13
  import { type Json } from "./validate.js";
@@ -59,7 +59,7 @@ export declare function message(store: RunsStore, moment: RunMoment, content: st
59
59
  queue?: (command: SteerCommand) => Promise<{
60
60
  skipped: string;
61
61
  } | void>;
62
- launchSealed?: Uint8Array;
62
+ launchSealed?: LaunchSealed;
63
63
  beforeSubmit?: (runId: string, content: string) => Promise<void> | void;
64
64
  }): Promise<{
65
65
  mode: MessageMode;
@@ -190,8 +190,9 @@ export interface StartDeps {
190
190
  * it must have a cap (a trigger's), and who its first message is from when the person did not write it. */
191
191
  export interface StartOptions {
192
192
  readonly trigger?: RunTrigger;
193
- /** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth, server.ts). */
194
- readonly sealed?: (runId: string) => Uint8Array;
193
+ /** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth and model_key, server.ts),
194
+ * given the launch the start prepared, which the sealer may refuse (a model key where the run's model takes none). */
195
+ readonly sealed?: (runId: string, launch: RunLaunch, kind: Revision["kind"]) => Uint8Array | null;
195
196
  /** The run's title when its starter names one (a trigger's: "<Source> <name>"), else it is made from its input. */
196
197
  readonly title?: string;
197
198
  readonly origin?: RunOrigin;
@@ -26,6 +26,7 @@ import { resolvePlace } from "./place.js";
26
26
  import { githubTargetOf } from "./github.js";
27
27
  import { repoOf } from "./run-repo.js";
28
28
  import { launchBody } from "./run-launch.js";
29
+ import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
29
30
  import { raiseFollowUpId } from "./run-view.js";
30
31
  import { sendCommand } from "./runner/commands.js";
31
32
  import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
@@ -215,7 +216,7 @@ export async function message(store, moment, content, { requestId, answers = tru
215
216
  * (reopenableWhere: an agentic run that completed, or that a person stopped, as the console offers a follow-up to both).
216
217
  * Any other (cancelled, failed, a workflow's, an imported or a learning run) answers 409 finished, nothing written. */
217
218
  async function steerOrReopen(store, moment, command, launchSealed) {
218
- // The message's launch secrets (its mcp_auth, sealed) ride in the same write as its steer, whichever door takes it.
219
+ // The message's launch secrets (its mcp_auth and model_key, sealed) ride in the same write as its steer, whichever door takes it.
219
220
  const sealed = launchSealed ? { launchSealed } : undefined;
220
221
  try {
221
222
  await sendCommand(store, moment.id, command, sealed);
@@ -446,10 +447,11 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
446
447
  if (entry.revision?.body?.sdk)
447
448
  throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
448
449
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
450
+ keyedOrRefused(deps, launch, revision.kind, sealed);
449
451
  const runId = (deps.newRunId ?? uuidv7)();
450
452
  try {
451
453
  const labels = labelsOf(body.labels);
452
- return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) }));
454
+ return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, revision.kind) } : {}) }));
453
455
  }
454
456
  catch (error) {
455
457
  // Only another writer of the store got here first under the same origin key: its run is the one asked for.
@@ -462,6 +464,13 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
462
464
  throw error;
463
465
  }
464
466
  }
467
+ /** A start with no launch secrets (`sealed`: a trigger's firing, a learning batch's row) whose route goes to the model
468
+ * gateway, on a server that holds no key for it (run-model-key.ts serverKeyMissing): 422 model_key_required, nothing
469
+ * written, never a failure at its first model call. A start with them (the API's) is the sealer's to check. */
470
+ function keyedOrRefused(deps, launch, kind, sealed) {
471
+ if (!sealed && serverKeyMissing(deps.planeEnv(), { kind, model: launch.model, native: Boolean(launch.native) }))
472
+ throw modelKeyRequired(false);
473
+ }
465
474
  /** Writes run `runId` with `write`, its files (launch.files) held for it first (StartDeps.files): a hold that fails part
466
475
  * way, a write that fails, or one that answers another run (an origin key's run started before), lets go of the hold. */
467
476
  async function withHeldFiles(deps, runId, launch, write) {
@@ -509,6 +518,7 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
509
518
  // A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
510
519
  // one across.
511
520
  const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision) });
521
+ keyedOrRefused(deps, launch, (storedRevision ?? revision).kind, sealed);
512
522
  const runId = (deps.newRunId ?? uuidv7)();
513
523
  const labels = labelsOf(body.labels);
514
524
  try {
@@ -516,7 +526,7 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
516
526
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
517
527
  revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
518
528
  run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
519
- launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) },
529
+ launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, (storedRevision ?? revision).kind) } : {}) },
520
530
  }));
521
531
  }
522
532
  catch (error) {
@@ -14,7 +14,7 @@ export declare function sdkWorkflowManifest(tools: unknown, adapters: unknown):
14
14
  export declare function sdkDraftTools(manifest: readonly SdkWorkflowTool[]): {
15
15
  tools: string[];
16
16
  gated: {
17
- [k: string]: "allow" | "ask" | "deny";
17
+ [k: string]: "ask" | "allow" | "deny";
18
18
  };
19
19
  deniedBy: {
20
20
  [k: string]: "agent";
package/dist/server.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type Server } from "node:http";
1
2
  import { type ModelNeeds } from "./model.js";
2
3
  import { type HarnessCapability } from "./harness.js";
3
4
  import { type HarnessInstaller } from "./harness-install.js";
@@ -68,6 +69,9 @@ export type ServeOptions = {
68
69
  /** When the port is taken at the listen, the next one that is not, of the 100 from it: the port is found by listening,
69
70
  * so one another process takes at the same moment is passed over. Without it a taken port fails the start. */
70
71
  nextFreePort?: boolean;
72
+ /** A server already listening (listen-first.ts, the CLI's early bind), answering that it is warming: the start takes it
73
+ * over where it would have listened, and `port`, `nextFreePort` and `host` are then only what it was bound with. */
74
+ listener?: Server;
71
75
  /** A read-only directory of documents a workflow's `pdf_pages` calls read by file name (`--documents`); default
72
76
  * AGENTRUN_SERVE_DOCUMENTS. */
73
77
  documents?: string;
@@ -129,6 +133,9 @@ export type ServeOptions = {
129
133
  /** A module of harness table entries merged over the built-in ones (harness-table.ts HARNESS_TABLE_ENV): a test's
130
134
  * stand-ins for the harnesses. */
131
135
  harnessTable?: string;
136
+ /** The owner's harness modules (harness-table.ts HARNESS_MODULES_ENV): packages or paths, each exporting a
137
+ * HarnessTableModule whose entries add harnesses of their own, for this server and its runs. Never a built-in one. */
138
+ harnessModules?: readonly string[];
132
139
  /** With `faux` only: Docker answers, so docker is available, and nothing asks Docker (place-offers.ts). */
133
140
  fauxDocker?: boolean;
134
141
  /** For tests: the lock each harness's first use installs by (harness-install.ts), by harness, with the package.json it
@@ -207,8 +214,9 @@ export type ServeOptions = {
207
214
  * runner's resolver decides what a test sees. */
208
215
  webhookLookup?: (host: string) => Promise<string[]>;
209
216
  };
210
- /** The test switches a run's process gets, each module path resolved: empty outside tests. A test's in-process runner
211
- * takes the same (test/support.mjs startInProcessRunner). */
217
+ /** The switches a run's process gets, each module path resolved: the owner's harness modules (harnessModules), and the test
218
+ * switches, which are empty outside tests. A test's in-process runner takes the same (test/support.mjs
219
+ * startInProcessRunner). */
212
220
  export declare function fauxEnvOf(options: ServeOptions): NodeJS.ProcessEnv;
213
221
  /** `tokenFile` is null when `options.token` gave the token; `tokenMade` says this start made the token in it. */
214
222
  /** `setupUrl`: with accounts and no password yet, the page that sets it (with its code when setup needs one);
@@ -306,7 +314,9 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
306
314
  /** The harnesses a revision may name (`definition.harness`), whether this server runs each, and how many at once. */
307
315
  harnesses: {
308
316
  max_concurrent_runs: number;
309
- id: import("./harness.js").HarnessId;
317
+ id: string;
318
+ label: string;
319
+ promises: import("./harness-table.js").HarnessPromises;
310
320
  available: boolean;
311
321
  steer: boolean;
312
322
  reason?: string;
@@ -355,14 +365,14 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
355
365
  providers?: string[] | undefined;
356
366
  provider?: string | undefined;
357
367
  default_provider?: string | undefined;
358
- resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
359
- why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
360
- default_permission: "allow" | "ask" | "deny";
361
- permissions: ("allow" | "ask" | "deny")[];
368
+ resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", import("./tool-plane.js").Resolution> | undefined;
369
+ why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
370
+ default_permission: "ask" | "allow" | "deny";
371
+ permissions: ("ask" | "allow" | "deny")[];
362
372
  fallback_allow_reads?: true | undefined;
363
373
  allow_reads?: true | undefined;
364
- permission: "allow" | "ask" | "deny";
365
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
374
+ permission: "ask" | "allow" | "deny";
375
+ harnesses: string[];
366
376
  missing?: string[] | undefined;
367
377
  reason?: string | undefined;
368
378
  available: boolean;
@@ -374,11 +384,11 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
374
384
  name: string;
375
385
  summary: string;
376
386
  } | {
377
- default_permission: "allow" | "ask" | "deny";
378
- permissions: ("allow" | "ask" | "deny")[];
387
+ default_permission: "ask" | "allow" | "deny";
388
+ permissions: ("ask" | "allow" | "deny")[];
379
389
  fallback_allow_reads?: true | undefined;
380
390
  allow_reads?: true | undefined;
381
- permission: "allow" | "ask" | "deny";
391
+ permission: "ask" | "allow" | "deny";
382
392
  name: string;
383
393
  summary: string;
384
394
  blurb: string;
@@ -386,20 +396,20 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
386
396
  calls: boolean;
387
397
  meta: true;
388
398
  available: boolean;
389
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
399
+ harnesses: string[];
390
400
  } | {
391
401
  key: string | undefined;
392
402
  providers?: string[] | undefined;
393
403
  provider?: string | undefined;
394
404
  default_provider?: string | undefined;
395
- resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
396
- why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
397
- default_permission: "allow" | "ask" | "deny";
398
- permissions: ("allow" | "ask" | "deny")[];
405
+ resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", import("./tool-plane.js").Resolution> | undefined;
406
+ why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
407
+ default_permission: "ask" | "allow" | "deny";
408
+ permissions: ("ask" | "allow" | "deny")[];
399
409
  fallback_allow_reads?: true | undefined;
400
410
  allow_reads?: true | undefined;
401
- permission: "allow" | "ask" | "deny";
402
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
411
+ permission: "ask" | "allow" | "deny";
412
+ harnesses: string[];
403
413
  missing?: string[] | undefined;
404
414
  reason?: string | undefined;
405
415
  available: boolean;
@@ -412,11 +422,11 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
412
422
  summary: string;
413
423
  } | {
414
424
  key: string | undefined;
415
- default_permission: "allow" | "ask" | "deny";
416
- permissions: ("allow" | "ask" | "deny")[];
425
+ default_permission: "ask" | "allow" | "deny";
426
+ permissions: ("ask" | "allow" | "deny")[];
417
427
  fallback_allow_reads?: true | undefined;
418
428
  allow_reads?: true | undefined;
419
- permission: "allow" | "ask" | "deny";
429
+ permission: "ask" | "allow" | "deny";
420
430
  name: string;
421
431
  summary: string;
422
432
  blurb: string;
@@ -424,7 +434,7 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
424
434
  calls: boolean;
425
435
  meta: true;
426
436
  available: boolean;
427
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
437
+ harnesses: string[];
428
438
  })[];
429
439
  /** How this server holds its secrets (secrets.ts, the launcher), and what that does not cover. */
430
440
  secrets: {
@@ -437,7 +447,7 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
437
447
  * `models.default`, `models.strong`) with the tools it names of `node_tools`; a node that names no thinking level
438
448
  * thinks at the run's effort, or medium. */
439
449
  workflows: {
440
- nodes: ("agent" | "decide" | "extract" | "report")[];
450
+ nodes: ("agent" | "extract" | "decide" | "report")[];
441
451
  node_tools: string[];
442
452
  adapters: string[];
443
453
  decisions: {
@@ -532,12 +542,13 @@ export declare function readingOf(base: NodeJS.ProcessEnv, maxRuns: number, stor
532
542
  at_rest: string;
533
543
  };
534
544
  /** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
535
- * which always exists (seal-key.ts), so MCP credentials are always kept sealed. */
545
+ * which always exists (seal-key.ts), so MCP credentials are always kept sealed. Every harness of the table runs a
546
+ * grant (runnable.ts takes one on any), a module's among them. */
536
547
  mcp_client: {
537
548
  transports: string[];
538
549
  auth: ("headers" | "none" | "oauth" | "bearer" | "github_app" | "per_run")[];
539
550
  at_rest: string;
540
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
551
+ harnesses: string[];
541
552
  };
542
553
  /** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
543
554
  learning: "off" | "on";
@@ -611,7 +622,9 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
611
622
  /** The harnesses a revision may name (`definition.harness`), whether this server runs each, and how many at once. */
612
623
  harnesses: {
613
624
  max_concurrent_runs: number;
614
- id: import("./harness.js").HarnessId;
625
+ id: string;
626
+ label: string;
627
+ promises: import("./harness-table.js").HarnessPromises;
615
628
  available: boolean;
616
629
  steer: boolean;
617
630
  reason?: string;
@@ -660,14 +673,14 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
660
673
  providers?: string[] | undefined;
661
674
  provider?: string | undefined;
662
675
  default_provider?: string | undefined;
663
- resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
664
- why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
665
- default_permission: "allow" | "ask" | "deny";
666
- permissions: ("allow" | "ask" | "deny")[];
676
+ resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", import("./tool-plane.js").Resolution> | undefined;
677
+ why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
678
+ default_permission: "ask" | "allow" | "deny";
679
+ permissions: ("ask" | "allow" | "deny")[];
667
680
  fallback_allow_reads?: true | undefined;
668
681
  allow_reads?: true | undefined;
669
- permission: "allow" | "ask" | "deny";
670
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
682
+ permission: "ask" | "allow" | "deny";
683
+ harnesses: string[];
671
684
  missing?: string[] | undefined;
672
685
  reason?: string | undefined;
673
686
  available: boolean;
@@ -679,11 +692,11 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
679
692
  name: string;
680
693
  summary: string;
681
694
  } | {
682
- default_permission: "allow" | "ask" | "deny";
683
- permissions: ("allow" | "ask" | "deny")[];
695
+ default_permission: "ask" | "allow" | "deny";
696
+ permissions: ("ask" | "allow" | "deny")[];
684
697
  fallback_allow_reads?: true | undefined;
685
698
  allow_reads?: true | undefined;
686
- permission: "allow" | "ask" | "deny";
699
+ permission: "ask" | "allow" | "deny";
687
700
  name: string;
688
701
  summary: string;
689
702
  blurb: string;
@@ -691,20 +704,20 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
691
704
  calls: boolean;
692
705
  meta: true;
693
706
  available: boolean;
694
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
707
+ harnesses: string[];
695
708
  } | {
696
709
  key: string | undefined;
697
710
  providers?: string[] | undefined;
698
711
  provider?: string | undefined;
699
712
  default_provider?: string | undefined;
700
- resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
701
- why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
702
- default_permission: "allow" | "ask" | "deny";
703
- permissions: ("allow" | "ask" | "deny")[];
713
+ resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", import("./tool-plane.js").Resolution> | undefined;
714
+ why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
715
+ default_permission: "ask" | "allow" | "deny";
716
+ permissions: ("ask" | "allow" | "deny")[];
704
717
  fallback_allow_reads?: true | undefined;
705
718
  allow_reads?: true | undefined;
706
- permission: "allow" | "ask" | "deny";
707
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
719
+ permission: "ask" | "allow" | "deny";
720
+ harnesses: string[];
708
721
  missing?: string[] | undefined;
709
722
  reason?: string | undefined;
710
723
  available: boolean;
@@ -717,11 +730,11 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
717
730
  summary: string;
718
731
  } | {
719
732
  key: string | undefined;
720
- default_permission: "allow" | "ask" | "deny";
721
- permissions: ("allow" | "ask" | "deny")[];
733
+ default_permission: "ask" | "allow" | "deny";
734
+ permissions: ("ask" | "allow" | "deny")[];
722
735
  fallback_allow_reads?: true | undefined;
723
736
  allow_reads?: true | undefined;
724
- permission: "allow" | "ask" | "deny";
737
+ permission: "ask" | "allow" | "deny";
725
738
  name: string;
726
739
  summary: string;
727
740
  blurb: string;
@@ -729,7 +742,7 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
729
742
  calls: boolean;
730
743
  meta: true;
731
744
  available: boolean;
732
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
745
+ harnesses: string[];
733
746
  })[];
734
747
  /** How this server holds its secrets (secrets.ts, the launcher), and what that does not cover. */
735
748
  secrets: {
@@ -742,7 +755,7 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
742
755
  * `models.default`, `models.strong`) with the tools it names of `node_tools`; a node that names no thinking level
743
756
  * thinks at the run's effort, or medium. */
744
757
  workflows: {
745
- nodes: ("agent" | "decide" | "extract" | "report")[];
758
+ nodes: ("agent" | "extract" | "decide" | "report")[];
746
759
  node_tools: string[];
747
760
  adapters: string[];
748
761
  decisions: {
@@ -837,12 +850,13 @@ export declare function capabilities(env?: NodeJS.ProcessEnv, maxRuns?: number,
837
850
  at_rest: string;
838
851
  };
839
852
  /** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
840
- * which always exists (seal-key.ts), so MCP credentials are always kept sealed. */
853
+ * which always exists (seal-key.ts), so MCP credentials are always kept sealed. Every harness of the table runs a
854
+ * grant (runnable.ts takes one on any), a module's among them. */
841
855
  mcp_client: {
842
856
  transports: string[];
843
857
  auth: ("headers" | "none" | "oauth" | "bearer" | "github_app" | "per_run")[];
844
858
  at_rest: string;
845
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
859
+ harnesses: string[];
846
860
  };
847
861
  /** This server's learning switch (`--learning`): on, a run learns when its agent says `learning: true`; off, none does. */
848
862
  learning: "off" | "on";