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

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 (256) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/NOTICE +4 -0
  3. package/README.md +283 -47
  4. package/dist/acp-package.d.ts +35 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +5 -2
  7. package/dist/adapter-facts.js +6 -3
  8. package/dist/adapters.d.ts +7 -0
  9. package/dist/adapters.js +39 -0
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/api-only.d.ts +7 -10
  13. package/dist/api-only.js +7 -10
  14. package/dist/archil-routes.js +2 -1
  15. package/dist/cap.js +12 -2
  16. package/dist/chatgpt-plan.js +2 -1
  17. package/dist/cli.js +119 -44
  18. package/dist/composio-made.d.ts +19 -2
  19. package/dist/composio-made.js +17 -5
  20. package/dist/composio-preset.d.ts +42 -7
  21. package/dist/composio-preset.js +106 -70
  22. package/dist/composio-triggers.d.ts +9 -4
  23. package/dist/composio-triggers.js +20 -13
  24. package/dist/computer-attach.d.ts +11 -10
  25. package/dist/computer-attach.js +13 -14
  26. package/dist/computer-commands.d.ts +3 -0
  27. package/dist/computer-commands.js +3 -2
  28. package/dist/computer-lost.d.ts +4 -0
  29. package/dist/computer-lost.js +8 -3
  30. package/dist/computer-setting.d.ts +2 -0
  31. package/dist/computer-setting.js +2 -0
  32. package/dist/computers.d.ts +9 -75
  33. package/dist/computers.js +20 -66
  34. package/dist/console/assets/index-BBFzAxLB.js +715 -0
  35. package/dist/console/assets/index-BRi-Rgq6.css +1 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/cost-heal.d.ts +13 -0
  38. package/dist/cost-heal.js +27 -0
  39. package/dist/dial-relay.d.ts +6 -2
  40. package/dist/dial-relay.js +9 -12
  41. package/dist/email/routes.js +2 -1
  42. package/dist/errors.d.ts +2 -0
  43. package/dist/errors.js +5 -0
  44. package/dist/exa-keyless.d.ts +1 -1
  45. package/dist/exa-keyless.js +1 -1
  46. package/dist/faux-computers.d.ts +2 -3
  47. package/dist/faux-computers.js +9 -31
  48. package/dist/github-connection.js +2 -1
  49. package/dist/harness-archive.d.ts +19 -2
  50. package/dist/harness-archive.js +49 -15
  51. package/dist/harness-check.d.ts +73 -0
  52. package/dist/harness-check.js +489 -0
  53. package/dist/harness-cursor.d.ts +45 -0
  54. package/dist/harness-cursor.js +121 -0
  55. package/dist/harness-recipe.d.ts +127 -0
  56. package/dist/harness-recipe.js +357 -0
  57. package/dist/harness-table.d.ts +12 -0
  58. package/dist/harness-table.js +62 -2
  59. package/dist/harness.d.ts +2 -0
  60. package/dist/harness.js +3 -2
  61. package/dist/host-check.d.ts +6 -0
  62. package/dist/host-check.js +14 -0
  63. package/dist/host.d.ts +10 -3
  64. package/dist/host.js +17 -3
  65. package/dist/import-sources.d.ts +2 -0
  66. package/dist/import-sources.js +2 -0
  67. package/dist/import-summary.d.ts +15 -5
  68. package/dist/import-summary.js +24 -8
  69. package/dist/import.d.ts +34 -4
  70. package/dist/import.js +134 -32
  71. package/dist/key-refusal.d.ts +1 -0
  72. package/dist/key-refusal.js +8 -3
  73. package/dist/key-words.d.ts +1 -1
  74. package/dist/key-words.js +4 -4
  75. package/dist/learn/check.d.ts +3 -0
  76. package/dist/learn/check.js +31 -20
  77. package/dist/learn/compile.js +11 -4
  78. package/dist/learn/promote.d.ts +77 -4
  79. package/dist/learn/promote.js +123 -2
  80. package/dist/learned-nodes.d.ts +4 -3
  81. package/dist/learned-workflow.js +4 -1
  82. package/dist/learning-cost.d.ts +6 -16
  83. package/dist/learning-cost.js +6 -12
  84. package/dist/learning-setting.d.ts +17 -6
  85. package/dist/learning-setting.js +41 -5
  86. package/dist/learning-words.d.ts +2 -0
  87. package/dist/learning-words.js +1 -1
  88. package/dist/listen-first.d.ts +10 -0
  89. package/dist/listen-first.js +25 -1
  90. package/dist/llms.txt +1 -1
  91. package/dist/mcp-gateway.d.ts +2 -1
  92. package/dist/mcp-gateway.js +31 -15
  93. package/dist/mcp-probe.d.ts +18 -6
  94. package/dist/mcp-probe.js +41 -8
  95. package/dist/mcp-secret-writes.d.ts +8 -0
  96. package/dist/mcp-secret-writes.js +104 -4
  97. package/dist/mcp-servers-store.d.ts +11 -5
  98. package/dist/mcp-servers-store.js +46 -20
  99. package/dist/model-form.d.ts +2 -1
  100. package/dist/model-form.js +22 -8
  101. package/dist/model-gateway.d.ts +113 -0
  102. package/dist/model-gateway.js +433 -0
  103. package/dist/model.d.ts +2 -1
  104. package/dist/model.js +9 -7
  105. package/dist/monid.js +1 -1
  106. package/dist/native/binding.d.ts +4 -0
  107. package/dist/native/binding.js +9 -0
  108. package/dist/native/cli.d.ts +3 -2
  109. package/dist/native/cli.js +6 -5
  110. package/dist/openapi.d.ts +2 -0
  111. package/dist/openapi.js +326 -41
  112. package/dist/owner.d.ts +4 -2
  113. package/dist/owner.js +10 -4
  114. package/dist/page.d.ts +8 -0
  115. package/dist/page.js +9 -1
  116. package/dist/port-models.js +17 -10
  117. package/dist/provider.d.ts +3 -3
  118. package/dist/provider.js +12 -3
  119. package/dist/public-address.d.ts +28 -0
  120. package/dist/public-address.js +62 -0
  121. package/dist/run-launch.d.ts +1 -1
  122. package/dist/run-launch.js +1 -1
  123. package/dist/run-secrets.d.ts +3 -2
  124. package/dist/run-secrets.js +6 -4
  125. package/dist/runner/adapter-loop.d.ts +10 -7
  126. package/dist/runner/adapter-loop.js +57 -22
  127. package/dist/runner/adapter-run-spec.d.ts +12 -0
  128. package/dist/runner/adapter-run-spec.js +40 -6
  129. package/dist/runner/adapters/index.js +16 -0
  130. package/dist/runner/adapters/pi.d.ts +5 -2
  131. package/dist/runner/adapters/pi.js +7 -4
  132. package/dist/runner/audit.d.ts +7 -0
  133. package/dist/runner/audit.js +24 -6
  134. package/dist/runner/claim-secrets.js +5 -1
  135. package/dist/runner/cli-run-spec.js +15 -7
  136. package/dist/runner/compare-end.d.ts +43 -0
  137. package/dist/runner/compare-end.js +95 -0
  138. package/dist/runner/computer-journal.d.ts +3 -0
  139. package/dist/runner/computer-journal.js +22 -2
  140. package/dist/runner/conformance/harness.js +19 -8
  141. package/dist/runner/conformance/subject.d.ts +6 -0
  142. package/dist/runner/harness-loops.d.ts +6 -1
  143. package/dist/runner/harness-loops.js +94 -54
  144. package/dist/runner/held.d.ts +5 -4
  145. package/dist/runner/journal-kinds.d.ts +4 -1
  146. package/dist/runner/journal-kinds.js +3 -0
  147. package/dist/runner/loop-contract.d.ts +10 -0
  148. package/dist/runner/main.d.ts +5 -5
  149. package/dist/runner/main.js +81 -11
  150. package/dist/runner/mcp-claim.js +40 -12
  151. package/dist/runner/metrics.d.ts +26 -0
  152. package/dist/runner/metrics.js +44 -1
  153. package/dist/runner/presence.d.ts +41 -0
  154. package/dist/runner/presence.js +89 -0
  155. package/dist/runner/promotion.d.ts +10 -3
  156. package/dist/runner/promotion.js +42 -21
  157. package/dist/runner/run-child-host.js +52 -14
  158. package/dist/runner/runner.d.ts +5 -0
  159. package/dist/runner/runner.js +8 -0
  160. package/dist/runner/store-port.d.ts +3 -0
  161. package/dist/runner/store-secrets.js +19 -7
  162. package/dist/runner/workflow-first.d.ts +5 -2
  163. package/dist/runner/workflow-first.js +6 -3
  164. package/dist/runs-over-store.d.ts +6 -2
  165. package/dist/runs-over-store.js +14 -4
  166. package/dist/sdk/runs.d.ts +1 -1
  167. package/dist/sdk/runs.js +6 -1
  168. package/dist/sdk/schema.js +1 -1
  169. package/dist/secret-writes.d.ts +16 -3
  170. package/dist/secret-writes.js +28 -3
  171. package/dist/server-secrets-store.js +5 -0
  172. package/dist/server.d.ts +31 -2
  173. package/dist/server.js +326 -53
  174. package/dist/sign-ins-secrets.js +4 -1
  175. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  176. package/dist/slack-url.d.ts +5 -0
  177. package/dist/slack-url.js +11 -0
  178. package/dist/slack.d.ts +107 -0
  179. package/dist/slack.js +292 -0
  180. package/dist/start-switches.d.ts +28 -0
  181. package/dist/start-switches.js +37 -0
  182. package/dist/stats.d.ts +1 -1
  183. package/dist/stats.js +2 -1
  184. package/dist/stop-signals.d.ts +11 -0
  185. package/dist/stop-signals.js +22 -0
  186. package/dist/store/agent-body.d.ts +1 -1
  187. package/dist/store/agent-body.js +2 -2
  188. package/dist/store/index.d.ts +3 -3
  189. package/dist/store/index.js +1 -1
  190. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  191. package/dist/store/postgres/store.d.ts +1 -1
  192. package/dist/store/postgres/store.js +4 -2
  193. package/dist/store/schema.d.ts +13 -5
  194. package/dist/store/schema.js +20 -11
  195. package/dist/store/seal.d.ts +16 -4
  196. package/dist/store/sqlite/store.d.ts +1 -1
  197. package/dist/store/sqlite/store.js +106 -27
  198. package/dist/store/store.d.ts +75 -23
  199. package/dist/store/store.js +11 -0
  200. package/dist/store-reads/analytics.js +3 -2
  201. package/dist/store-reads/cap.d.ts +7 -0
  202. package/dist/store-reads/cap.js +11 -1
  203. package/dist/store-reads/journal.js +27 -1
  204. package/dist/store-reads/learning.d.ts +23 -2
  205. package/dist/store-reads/learning.js +29 -8
  206. package/dist/store-reads/runs.d.ts +9 -0
  207. package/dist/store-reads/runs.js +19 -6
  208. package/dist/store-reads/stats.d.ts +4 -1
  209. package/dist/store-reads/stats.js +15 -6
  210. package/dist/store-view.d.ts +123 -14
  211. package/dist/store-view.js +154 -21
  212. package/dist/telemetry.d.ts +7 -7
  213. package/dist/telemetry.js +38 -15
  214. package/dist/templates.d.ts +6 -3
  215. package/dist/templates.js +38 -3
  216. package/dist/timeline/timeline.js +18 -0
  217. package/dist/tool-keys-store.js +2 -2
  218. package/dist/tool-keys.js +2 -1
  219. package/dist/tool-plane.js +2 -2
  220. package/dist/trigger-adapter.d.ts +3 -4
  221. package/dist/trigger-adapter.js +2 -2
  222. package/dist/trigger-composio.js +3 -3
  223. package/dist/trigger-email.js +0 -2
  224. package/dist/trigger-feed.js +0 -2
  225. package/dist/trigger-schedule.js +3 -0
  226. package/dist/trigger-secrets-shown.d.ts +6 -3
  227. package/dist/trigger-secrets-shown.js +22 -13
  228. package/dist/trigger-targets.d.ts +1 -1
  229. package/dist/trigger-targets.js +19 -8
  230. package/dist/triggers.d.ts +7 -3
  231. package/dist/triggers.js +2 -1
  232. package/dist/webhooks.d.ts +85 -9
  233. package/dist/webhooks.js +129 -46
  234. package/dist/wires.d.ts +6 -1
  235. package/dist/wires.js +5 -0
  236. package/dist/workspace/attach.d.ts +3 -2
  237. package/dist/workspace/attach.js +2 -1
  238. package/dist/workspace/attached-computers.d.ts +6 -8
  239. package/dist/workspace/attached-computers.js +27 -24
  240. package/dist/workspace/computer-deps.d.ts +2 -3
  241. package/dist/workspace/computer-deps.js +3 -6
  242. package/dist/workspace/computer-for-claim.js +72 -96
  243. package/dist/workspace/computer-kept.d.ts +0 -7
  244. package/dist/workspace/computer-kept.js +0 -17
  245. package/dist/workspace/resolve-computer.d.ts +18 -14
  246. package/dist/workspace/resolve-computer.js +47 -60
  247. package/dist/workspace/synced-folder.d.ts +20 -15
  248. package/dist/workspace/synced-folder.js +33 -43
  249. package/launcher/agentrun-serve +4 -1
  250. package/package.json +10 -10
  251. package/skills/agentrun-serve/SKILL.md +11 -0
  252. package/templates/README.md +1 -1
  253. package/templates/inbound-lead/agent.md +2 -1
  254. package/templates/kyb/agent.md +2 -1
  255. package/dist/console/assets/index-3O2Yl6hZ.js +0 -701
  256. package/dist/console/assets/index-DaFsZuzQ.css +0 -1
@@ -31,7 +31,8 @@ import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
31
31
  import { learningEndOfRun } from "./learning-end.js";
32
32
  import { runnerSecrets } from "./redact.js";
33
33
  import { storeSecrets } from "./store-secrets.js";
34
- import { FAUX_ENV } from "../model.js";
34
+ import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
35
+ import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
35
36
  import { FAUX_VENDOR_API_ENV } from "../tools.js";
36
37
  import { withinCarried } from "../paid-calls.js";
37
38
  import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
@@ -52,14 +53,16 @@ import { learningStartOf, seedFailed } from "../run-launch.js";
52
53
  import { messageText } from "../run-manifest.js";
53
54
  import { placeRunInputs } from "../uploads.js";
54
55
  import { withAudit } from "./audit.js";
56
+ import { compareEndOfRun } from "./compare-end.js";
55
57
  import { learnedFirst } from "./learned-first.js";
56
58
  import { workflowsAt } from "./learning-seed.js";
57
59
  import { heldMcpOf, mcpForClaim } from "./mcp-run.js";
58
60
  import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
59
61
  import { createDispatchLoop } from "./dispatch.js";
60
- import { resolveRunnerLoop } from "./harness-loops.js";
62
+ import { resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
61
63
  import { isWorkflowRevision } from "./workflow-loop.js";
62
64
  import { loginForRun } from "../claude-login.js";
65
+ import { heardComputerHold } from "./computer-journal.js";
63
66
  import { ClaimRefused } from "./loop-contract.js";
64
67
  import { Channel, ChannelClosed } from "./run-channel.js";
65
68
  import { registerRunErrors } from "./run-errors.js";
@@ -84,11 +87,19 @@ export const runIsolationName = (isolation) => isolation.kind;
84
87
  export class RunIsolationRefused extends Error {
85
88
  name = "RunIsolationRefused";
86
89
  }
90
+ /** The helper run once: its exit code and output, never a rejection. A spawn error Node throws from execFile itself
91
+ * (EPERM, say, where a platform forbids the helper's file capabilities; only EACCES, EAGAIN, EMFILE, ENFILE and ENOENT
92
+ * come to the callback) is `code` -1 with the error's words as `stderr`, so every caller reads it as the failure it is. */
87
93
  const execText = (file, args, timeoutMs) => new Promise((resolve) => {
88
- execFile(file, args, { timeout: timeoutMs, encoding: "utf8" }, (error, stdout, stderr) => {
89
- const code = error ? (typeof error.code === "number" ? (error.code) : 1) : 0;
90
- resolve({ code, stdout: String(stdout), stderr: String(stderr || (error && !stderr ? error.message : "")) });
91
- });
94
+ try {
95
+ execFile(file, args, { timeout: timeoutMs, encoding: "utf8" }, (error, stdout, stderr) => {
96
+ const code = error ? (typeof error.code === "number" ? (error.code) : 1) : 0;
97
+ resolve({ code, stdout: String(stdout), stderr: String(stderr || (error && !stderr ? error.message : "")) });
98
+ });
99
+ }
100
+ catch (error) {
101
+ resolve({ code: -1, stdout: "", stderr: error?.message ?? String(error) });
102
+ }
92
103
  });
93
104
  /** This host's isolation for `loops` runs at once, by `env` and the helper: the helper's own check that it can switch
94
105
  * (its effective set holds what it needs) decides `uid`; none installed (a local install), `process`; `same`, `process`
@@ -730,6 +741,8 @@ export function heldFor(deps, reads, cut, log) {
730
741
  runZone: () => runZone(store, launch.inputOrigin),
731
742
  liveViewerPut: (handover) => putLiveViewer(store, sealKey, claim, handover),
732
743
  liveViewerDrop: (tag) => dropLiveViewer(store, claim, tag),
744
+ // The claim's own run, whatever the process names: its view on this runner hears the change.
745
+ computerHold: async (change) => heardComputerHold(claim.runId, change, cut),
733
746
  handOn: async (from, id) => {
734
747
  if (from !== claim.runId || typeof id !== "string")
735
748
  return undefined;
@@ -791,9 +804,17 @@ export function heldFor(deps, reads, cut, log) {
791
804
  // The step as the run's spec builds it in a runner (adapter-run-spec.ts), over the runner's reads of the claim: what
792
805
  // the run must never learn is every secret this runner holds, the keys its claim handed it, every secret the server
793
806
  // keeps sealed and its sign-in's pointers, none of which the run's process is given.
794
- // A replay run or an audit's shadow run asks nothing at its end, as the run's spec says (adapter-run-spec.ts).
795
- if (launch.replay || launch.audit)
796
- return undefined;
807
+ // A replay run or an audit's shadow run learns nothing at its end, as the run's spec says (adapter-run-spec.ts): it
808
+ // compares its answer with the other one through its grader, handed in by the run's process (runner/compare-end.ts).
809
+ // This runner reads both answers and the learning ledger, which no run's process may.
810
+ if (launch.replay || launch.audit) {
811
+ const compare = compareEndOfRun(launch, { store, folder: await folderNow(), log, redact: cut });
812
+ const grade = input.grade;
813
+ const rows = compare && grade && typeof input.grader === "string"
814
+ ? await compare({ runId: claim.runId, agentId: run.agentId, claim, outcome: input.outcome === "failed" ? "failed" : "completed", ...(input.cut === undefined ? {} : { cut: "faulted" }), grader: input.grader, grade: (request) => grade(request), ask: input.ask, signal: input.signal })
815
+ : undefined;
816
+ return rows?.compared ? { also: [], compared: dataOnly(rows.compared) } : undefined;
817
+ }
797
818
  const made = await archilOf();
798
819
  // The audit's spend, skipped as the run's spec skips it (claim-secrets.ts claimSpendOff): over the claim's own key.
799
820
  const spendOff = await claimSpendOff(keys, await claimModelKey(keys, claim.runId));
@@ -969,6 +990,13 @@ export function childLoops(options) {
969
990
  });
970
991
  }
971
992
  registerRunErrors();
993
+ /** `claimed` with the saved gateway's key beside its own (the runner's reads of what the run must never keep, heldFor):
994
+ * a copy, every property as it is (its non-enumerable keys and the sign-in's reader too), the key non-enumerable. */
995
+ function withGatewayKey(claimed, key) {
996
+ const out = Object.defineProperties({}, Object.getOwnPropertyDescriptors(claimed));
997
+ Object.defineProperty(out, GATEWAY_KEY_ENV, { value: key, enumerable: false, writable: false, configurable: false });
998
+ return out;
999
+ }
972
1000
  /** The environment a run's process starts with: the runner's run environment's plain values (runEnv: its secrets are
973
1001
  * not enumerable, so none is here), no key-shaped name, and where its keys come from. */
974
1002
  function childEnv(base, keys, extra) {
@@ -1049,17 +1077,26 @@ function childLoop(options, slots, loopDeps) {
1049
1077
  if (!revisionRow)
1050
1078
  throw new Error(`run ${claim.runId}: its revision ${runRow.revisionId} is gone from the store`);
1051
1079
  const revision = { kind: revisionRow.kind, body: (revisionRow.body ?? {}) };
1080
+ // The model gateway saved in the console, read from the store now and laid over this claim's environment, as a run
1081
+ // in this process has it laid (harness-loops.ts): the run's process reads no store row of it and holds no seal key.
1082
+ const claimDeps = await withSavedGatewayDeps(deps);
1083
+ const claimEnv = claimDeps.env ?? {};
1084
+ const savedGateway = savedGatewayIn(claimEnv);
1052
1085
  // The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read.
1053
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
1086
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, launch);
1054
1087
  // With them, its revision's own model's (a launch pinned at its start to another model, a --faux start's, is still
1055
1088
  // handed its agent's model's key, as a run's own process was handed it before: run-secrets.ts secretsFor).
1056
- const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1089
+ const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1057
1090
  // A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
1058
1091
  // none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
1059
1092
  // Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
1060
1093
  const keyed = (await openRunModelKey({ store: deps.store, sealKey: deps.sealKey }, claim.runId)) !== undefined;
1061
1094
  const toProcess = keyed ? [withoutModelKeys({ ...claimed }), withoutModelKeys({ ...ofRevision })] : [claimed, ofRevision];
1062
- const handed = (name) => toProcess.map((from) => from[name]).find((value) => typeof value === "string" && value !== "");
1095
+ // The saved gateway's key, kept off the claim's tool keys (claimSecrets), is handed for the run's model routes alone,
1096
+ // read as the server's model keys are (savedModelKeys, over the claim's environment the gateway was laid over), as a
1097
+ // run in this process reads it from its environment by name; none to a run that brings its own key.
1098
+ const gatewayKey = savedGateway ? (keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }))[GATEWAY_KEY_ENV] || undefined : undefined;
1099
+ const handed = (name) => (name === GATEWAY_KEY_ENV && savedGateway ? gatewayKey : toProcess.map((from) => from[name]).find((value) => typeof value === "string" && value !== ""));
1063
1100
  const keys = encode(SECRET_NAMES.flatMap((name) => {
1064
1101
  const value = handed(name);
1065
1102
  return value === undefined ? [] : [[name, value]];
@@ -1083,7 +1120,7 @@ function childLoop(options, slots, loopDeps) {
1083
1120
  if (isolation.kind === "uid" && slot !== undefined)
1084
1121
  hold = new SlotHold(slot, isolation.helper, log);
1085
1122
  const tops = runTops(deps.data, runRow.agentId, claim.runId);
1086
- const heldSide = heldFor(deps, { claim, run: runRow, launch, revision, claimed }, cut, log);
1123
+ const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed }, cut, log);
1087
1124
  try {
1088
1125
  let extra = {};
1089
1126
  let argv = [...(options.argv ?? childArgv())];
@@ -1097,7 +1134,8 @@ function childLoop(options, slots, loopDeps) {
1097
1134
  extra = { TMPDIR: tmp, HOME: scratch };
1098
1135
  argv = [isolation.helper, "run", String(slot), "--keep-fd", "3", "--keep-fd", "4", "--", ...argv];
1099
1136
  }
1100
- const env = childEnv(deps.env, keys, extra);
1137
+ // The saved gateway's address and models go as plain variables (childEnv), and its mark says they are the saved one.
1138
+ const env = childEnv(claimEnv, keys, savedGateway ? { ...extra, [SAVED_GATEWAY_ENV]: "1" } : extra);
1101
1139
  const [program, ...rest] = argv;
1102
1140
  child = spawn(program, rest, { stdio: ["ignore", "inherit", "inherit", "pipe", "pipe"], env, detached: true });
1103
1141
  exited = new Promise((resolve) => {
@@ -3,6 +3,7 @@ import { type RunnerStore } from "./store-port.js";
3
3
  import { type RunState } from "../store/store.js";
4
4
  import { type Redact } from "./redact.js";
5
5
  import { type LiveTickerOptions } from "./live-ticker.js";
6
+ import { type Presence } from "./presence.js";
6
7
  /** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
7
8
  /** A final run's status as its end line says it: the store holds a cancel as state 'stopped' with outcome 'cancelled', so
8
9
  * the outcome tells a cancel from a person's resumable stop. */
@@ -42,6 +43,10 @@ export interface RunnerOptions {
42
43
  live?: false | LiveTickerOptions;
43
44
  /** This runner's name in the runs it claims (runs.runner). Default: host, pid and a random part. */
44
45
  name?: string;
46
+ /** Its word in the store that it is there (presence.ts), kept by its caller (runner/main.ts, whose relay says where it
47
+ * answers on the same row, under the same incarnation): used as is, never closed here. Default: one of its own,
48
+ * removed at its close. */
49
+ presence?: Presence;
45
50
  /** Most runs held at once. */
46
51
  loops?: number;
47
52
  /** How long a claim lasts unless renewed. */
@@ -24,6 +24,7 @@ import { Unanswered } from "../store/postgres/connection.js";
24
24
  import { clearWaitEnded } from "../browser-wait-ended.js";
25
25
  import { heldRedactor, processSecretRedactor } from "./redact.js";
26
26
  import { withLiveTicker } from "./live-ticker.js";
27
+ import { keepPresence } from "./presence.js";
27
28
  /** Tries of the re-read after a claim or release commit was answered Unanswered (the commit may have landed). */
28
29
  const UNKNOWN_READS = 5;
29
30
  /** Passes of the sweep after a claim answered Unanswered: the commit may still be on its way when the first read comes back
@@ -927,6 +928,9 @@ export function startRunner(options) {
927
928
  else
928
929
  poll();
929
930
  };
931
+ // Its word in the store that a runner that claims is here (presence.ts), for as long as it runs: a server reads a
932
+ // refusal left by an earlier runner as over once this is there. One its caller keeps is its caller's to close.
933
+ const presence = options.presence ? undefined : store.runners ? keepPresence(store.runners, name, null, { warn: (line) => emit({ type: "error", step: "presence", message: line }) }) : undefined;
930
934
  poll();
931
935
  commandTimer = setTimeout(deliverAll, commandPollMs);
932
936
  // A run queued in this process is claimed now (claimNow). A command written for a run this runner holds is handed on
@@ -1067,11 +1071,15 @@ export function startRunner(options) {
1067
1071
  // The live view's last tick, once every loop has ended or been given up: a draining run kept its live view to the
1068
1072
  // end of its loop.
1069
1073
  await ticker?.close();
1074
+ // It claims no more: its word that it is here goes.
1075
+ await presence?.close();
1070
1076
  },
1071
1077
  kill() {
1072
1078
  killed = true;
1073
1079
  closed = true;
1074
1080
  stopTimers();
1081
+ // A crash says nothing more: its word goes stale, as a dead runner's does.
1082
+ presence?.stop();
1075
1083
  // A crash writes nothing more: the live view's ticker stops at once, beside a new holder of its runs.
1076
1084
  ticker?.stop();
1077
1085
  },
@@ -9,6 +9,9 @@ export type RunnerStore = Pick<Store, "claim" | "renew" | "renewMany" | "release
9
9
  /** The server's settings, for the one the runner removes at a run's end (browser-wait-ended.ts). A store without it (a
10
10
  * test's) keeps none. */
11
11
  readonly settings?: Store["settings"];
12
+ /** Every runner's word that it is there (runner/presence.ts): the runner keeps its own for as long as it runs. A store
13
+ * without it (a test's) keeps none. */
14
+ readonly runners?: Store["runners"];
12
15
  };
13
16
  /** The store's fence: a write under an epoch that moved. */
14
17
  export declare function isFenced(error: unknown): boolean;
@@ -5,8 +5,8 @@
5
5
  // echoes it back. One read of the store across all its planes (store.sealedSecrets): tool, model, computer and Archil keys,
6
6
  // the email account's password alone (its row holds the account whole), and the ChatGPT sign-in's access and refresh tokens each alone, renewed by whichever process holds the store (sealed_keys); MCP credentials, their headers' values and OAuth tokens and client secret (mcp_servers), and a sign-in in
7
7
  // flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
8
- // and webhook secret among them, and the outbound webhook's signing secret, each it held before too (trigger_settings),
9
- // but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
8
+ // and webhook secret among them, the outbound webhook's signing secret and Slack's incoming-webhook URL (whole and its
9
+ // token alone, slack-url.ts), each it held before too (trigger_settings), but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
10
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
@@ -15,8 +15,10 @@ import { CHATGPT_PLAN_ROW } from "../chatgpt-plan.js";
15
15
  import { calendarRowSecrets } from "../calendar/address.js";
16
16
  import { CALENDAR_ROW } from "../calendar/names.js";
17
17
  import { accountRowSecrets, EMAIL_ACCOUNT_ROW } from "../email/account.js";
18
+ import { GATEWAY_KEY_ROW, gatewayKeyRowSecrets } from "../model-gateway.js";
18
19
  import { unseal } from "../sealing.js";
19
20
  import { besideTheStore, ServerSecrets } from "../server-secrets.js";
21
+ import { SLACK_CHANNEL, slackUrlForms } from "../slack-url.js";
20
22
  import { TRIGGER_ADAPTERS } from "../trigger-adapters.js";
21
23
  /** The keys of a sealed JSON value that hold secrets: OAuth tokens, a client's secret, a PKCE verifier. */
22
24
  const JSON_SECRETS = ["access_token", "refresh_token", "id_token", "client_secret", "verifier"];
@@ -56,8 +58,9 @@ function jsonSecrets(text) {
56
58
  return out;
57
59
  }
58
60
  /** 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": "..."}}`). */
61
+ * sealRunLaunch: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed, each per-run Composio
62
+ * binding's user and account (`{"mcp": {"<server>": {"composio": {"user_id", "connected_account_id"}}}}`), and the run's
63
+ * own model key (`{"model": {"key": "..."}}`). */
61
64
  function launchSecrets(text) {
62
65
  const out = jsonSecrets(text);
63
66
  let opened;
@@ -68,9 +71,15 @@ function launchSecrets(text) {
68
71
  return out;
69
72
  }
70
73
  const mcp = opened?.mcp;
71
- if (mcp && typeof mcp === "object")
72
- for (const entry of Object.values(mcp))
74
+ if (mcp && typeof mcp === "object") {
75
+ for (const entry of Object.values(mcp)) {
73
76
  out.push(...jsonSecrets(JSON.stringify(entry)));
77
+ const binding = entry?.composio;
78
+ for (const value of [binding?.user_id, binding?.connected_account_id])
79
+ if (typeof value === "string")
80
+ out.push(value);
81
+ }
82
+ }
74
83
  if (typeof opened?.model?.key === "string")
75
84
  out.push(opened.model.key);
76
85
  return out;
@@ -93,6 +102,9 @@ const pemForms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.t
93
102
  function secretsOf(row, plain, adapters) {
94
103
  switch (row.plane) {
95
104
  case "trigger_settings": {
105
+ // Slack's URL (live or retired): the URL whole and its token alone, as the server lists it.
106
+ if (row.where.adapter === SLACK_CHANNEL)
107
+ return { listed: slackUrlForms(plain), whole: [] };
96
108
  const spec = adapters.find((adapter) => adapter.id === row.where.adapter)?.settings?.fields[row.where.field ?? ""];
97
109
  if (spec?.public)
98
110
  return { listed: [], whole: [] };
@@ -104,7 +116,7 @@ function secretsOf(row, plain, adapters) {
104
116
  case "run_launch":
105
117
  return { listed: plain.trimStart().startsWith("{") ? launchSecrets(plain) : [plain], whole: [] };
106
118
  case "sealed_keys":
107
- return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : row.where.name === CALENDAR_ROW ? calendarRowSecrets(plain) : [plain], whole: [] };
119
+ return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : row.where.name === CALENDAR_ROW ? calendarRowSecrets(plain) : row.where.name === GATEWAY_KEY_ROW ? gatewayKeyRowSecrets(plain) : [plain], whole: [] };
108
120
  default:
109
121
  return { listed: [plain], whole: [] };
110
122
  }
@@ -3,7 +3,7 @@ import type { RunLaunch } from "../run-launch.js";
3
3
  import { COST_WINDOW, type RunPath } from "../learning-cost.js";
4
4
  export { COST_WINDOW };
5
5
  import { type LoopRow } from "../learned-nodes.js";
6
- import { type CostStop } from "../learn/promote.js";
6
+ import { type Compared, type CostStop } from "../learn/promote.js";
7
7
  import type { Skipped } from "../learn/replay-calls.js";
8
8
  /** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
9
9
  * revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
@@ -187,13 +187,16 @@ export declare function pathMetrics(launch: RunLaunch, classified: {
187
187
  not_auditable?: true;
188
188
  loops?: LoopRow[];
189
189
  replay?: ReplayMetrics;
190
- audit?: NonNullable<RunLaunch["audit"]>;
190
+ audit?: NonNullable<RunLaunch["audit"]> & {
191
+ readonly compared?: Compared;
192
+ };
191
193
  };
192
194
  /** A replay run's record (metrics.replay): the graded run it replayed and how its workflow ended there. */
193
195
  export type ReplayMetrics = {
194
196
  readonly of: string;
195
197
  readonly outcome: ReplayOutcome;
196
198
  readonly skipped?: Skipped;
199
+ readonly compared?: Compared;
197
200
  };
198
201
  /** How a replay run's workflow ended on its input: `skipped_write`, stopped at a write the graded run's recording does not
199
202
  * have (learn/replay-calls.ts SKIPPED_WRITE), never run. */
@@ -32,7 +32,7 @@ export { COST_WINDOW };
32
32
  import { KINDS } from "./journal-kinds.js";
33
33
  import { inputIssues, isObject } from "../validate.js";
34
34
  import { endedIn, loopsOf, replaySkippedIn } from "../learned-nodes.js";
35
- import { sameAnswer } from "../learn/promote.js";
35
+ import { comparedOf, sameAnswer } from "../learn/promote.js";
36
36
  /** The root entry a run served workflow-first keeps, once the workflow's call ended: which workflow, at which learned
37
37
  * revision, under which call, and how it ended. A later claim that finds it never runs the workflow again. */
38
38
  export const WORKFLOW_FIRST = "agentrun.workflow_first";
@@ -231,9 +231,12 @@ export function servedOf(entries) {
231
231
  * each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
232
232
  * and workflow from here. None for a run that does not learn. */
233
233
  export function pathMetrics(launch, classified, entries = []) {
234
+ // The grader's verdict its end-of-run step kept (runner/compare-end.ts), for a replay run and a shadow.
235
+ const compared = comparedOf(entries.findLast((entry) => entry.kind === KINDS.compared)?.data);
236
+ const verdict = compared ? { compared } : {};
234
237
  // A shadow run (runner/audit.ts): path `audit` and the run it audits, whatever it did: no learning, no money rule.
235
238
  if (launch.audit)
236
- return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } };
239
+ return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest, ...verdict } };
237
240
  if (!launch.learning)
238
241
  return {};
239
242
  const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
@@ -249,7 +252,7 @@ export function pathMetrics(launch, classified, entries = []) {
249
252
  // evidence. Skipped when a write it needed is not in the graded run's recording (learn/replay-calls.ts): never run.
250
253
  const skipped = replaySkippedIn(entries);
251
254
  const outcome = skipped ? "skipped_write" : path === "workflow" && workflow === name ? "answered" : path === "handed_back" && workflow === name && endedIn(entries, name) === "escalated" ? "handed_back" : "failed";
252
- return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, replay: { of, outcome, ...(skipped ? { skipped } : {}) } };
255
+ return { path: "replay", ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), workflow: name, workflow_digest: at, ...rows, replay: { of, outcome, ...(skipped ? { skipped } : {}), ...verdict } };
253
256
  }
254
257
  // A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
255
258
  const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
@@ -51,8 +51,9 @@ export type MessageMode = "steer" | "answer" | "follow_up";
51
51
  * run's state. `answers: false` is a trigger's message, which never answers a person: refused while the run waits on one,
52
52
  * and never a deny of an approval. The mode is the label the v2 answer reports, from the run's moment. `queue`: the steer's
53
53
  * write when it is not this run's own (a trigger's: its firing marked with it, within its bound, store.triggers.message),
54
- * which may skip it, in words. */
55
- export declare function message(store: RunsStore & Pick<Store, "agents">, moment: RunMoment, content: string, { requestId, answers, origin, queue, launchSealed, beforeSubmit }?: {
54
+ * which may skip it, in words. A runner applies every message, so while every runner here refused to claim, any message
55
+ * (a person's or a trigger's) is refused in their words first, as a start is (prepareLaunch, runner/presence.ts). */
56
+ export declare function message(store: RunsStore & Pick<Store, "agents" | "runners">, moment: RunMoment, content: string, { requestId, answers, origin, queue, launchSealed, beforeSubmit }?: {
56
57
  requestId?: string;
57
58
  answers?: boolean;
58
59
  origin?: unknown;
@@ -105,6 +106,9 @@ type StartBody = {
105
106
  export interface StartDeps {
106
107
  /** A new run id; defaults to a UUIDv7. */
107
108
  readonly newRunId?: () => string;
109
+ /** Why no runner here can take a run, in their words, while every runner there refused to claim (runner/presence.ts
110
+ * runnersRefused); undefined while one can, or none is there yet. A start is refused with it (runner_refused). */
111
+ runnersRefused?(): Promise<string | undefined>;
108
112
  /** The create body's field issues, before the agent is read (server.ts runBodyIssues). */
109
113
  runBodyIssues(body: Json): InputIssue[];
110
114
  /** The revision a run starts on (server.ts pinnedOf): the body's pin, else the agent's current; undefined when none. */
@@ -1,4 +1,4 @@
1
- import { nativeOf } from "./native/binding.js";
1
+ import { NATIVE_RUN_OVERRIDES_UNSUPPORTED, nativeOf, nativeRunOverrides } from "./native/binding.js";
2
2
  import { launchNative } from "./native/connection.js";
3
3
  // The write half of the run's server cut (design 2.1, "the runner takes every run"): the functions the v2 routes call to
4
4
  // start a run and to act on one (message, stop, raise, approve, archive), over the one store (A). The old per-run-process
@@ -29,6 +29,7 @@ import { launchBody } from "./run-launch.js";
29
29
  import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
30
30
  import { raiseFollowUpId } from "./run-view.js";
31
31
  import { sendCommand } from "./runner/commands.js";
32
+ import { runnersRefused } from "./runner/presence.js";
32
33
  import { AgentDeleting, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
33
34
  import { canonical } from "./store/agent-body.js";
34
35
  import { toolingOf } from "./tools.js";
@@ -154,8 +155,12 @@ export const resume = (store, moment) => pauseOrResume(store, moment, false);
154
155
  * run's state. `answers: false` is a trigger's message, which never answers a person: refused while the run waits on one,
155
156
  * and never a deny of an approval. The mode is the label the v2 answer reports, from the run's moment. `queue`: the steer's
156
157
  * write when it is not this run's own (a trigger's: its firing marked with it, within its bound, store.triggers.message),
157
- * which may skip it, in words. */
158
+ * which may skip it, in words. A runner applies every message, so while every runner here refused to claim, any message
159
+ * (a person's or a trigger's) is refused in their words first, as a start is (prepareLaunch, runner/presence.ts). */
158
160
  export async function message(store, moment, content, { requestId, answers = true, origin, queue, launchSealed, beforeSubmit } = {}) {
161
+ const refused = await runnersRefused(store.runners);
162
+ if (refused !== undefined)
163
+ throw new ApiError("runner_refused", refused);
159
164
  if (moment.importedSource !== undefined)
160
165
  throw importedRefusal(moment);
161
166
  const launchBody = await controlLaunchBody(store, moment.id);
@@ -562,8 +567,8 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
562
567
  const native = nativeOf(revision.body);
563
568
  if (native && !nativeOf(entry.revision?.body)?.connected)
564
569
  throw new ApiError("agent_not_runnable", "This native connection is disconnected. Reconnect its source project before starting any revision.");
565
- if (native && (body.effort !== undefined || fileIds.length || body.archil_disk !== undefined))
566
- throw new ApiError("input_invalid", "Native jobs use their original effort and project files. Run effort overrides, uploaded file_ids and Archil disks are unavailable; edit the native configuration or source project instead.");
570
+ if (native && nativeRunOverrides(body).length)
571
+ throw new ApiError("input_invalid", NATIVE_RUN_OVERRIDES_UNSUPPORTED);
567
572
  if (fileIds.length)
568
573
  await deps.readyFiles(fileIds);
569
574
  const rbody = revision.body;
@@ -575,6 +580,11 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
575
580
  const cap = typeof body.max_cost_usd === "number" ? body.max_cost_usd : rbody.maxCostUsd;
576
581
  if (capped && cap === undefined)
577
582
  throw invalid([{ field: "max_cost_usd", reason: "missing", message: "Every run a trigger starts is capped: give the trigger's target a max_cost_usd or set the agent's." }]);
583
+ // A run no runner here can claim is never taken to wait for good: refused in the runners' words, once the request reads
584
+ // right and before anything is pinned or made for it (runner/presence.ts).
585
+ const refused = await deps.runnersRefused?.();
586
+ if (refused !== undefined)
587
+ throw new ApiError("runner_refused", refused);
578
588
  const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
579
589
  // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
580
590
  // its server could not be listed, is refused with the rest (runnable).
@@ -2,7 +2,7 @@ import type { Claim, RunOrigin, Store } from "../store/store.js";
2
2
  import type { AgentEntry } from "../agents-store.js";
3
3
  import { type StartDeps } from "../runs-over-store.js";
4
4
  import { type LearnedWorkflow } from "../learning.js";
5
- export type SdkRuntime = "claude-agent-sdk" | "codex-sdk";
5
+ export type SdkRuntime = "claude-agent-sdk" | "codex-sdk" | "eve";
6
6
  export type SdkUsage = {
7
7
  input_tokens: number | null;
8
8
  output_tokens: number | null;
package/dist/sdk/runs.js CHANGED
@@ -47,7 +47,7 @@ const usageOf = (value) => {
47
47
  }
48
48
  return result;
49
49
  };
50
- export const sdkOf = (body) => isObject(body) && isObject(body.sdk) && (body.sdk.runtime === "claude-agent-sdk" || body.sdk.runtime === "codex-sdk")
50
+ export const sdkOf = (body) => isObject(body) && isObject(body.sdk) && (body.sdk.runtime === "claude-agent-sdk" || body.sdk.runtime === "codex-sdk" || body.sdk.runtime === "eve")
51
51
  ? { runtime: body.sdk.runtime }
52
52
  : undefined;
53
53
  export async function sdkInbox(store, runId) {
@@ -187,6 +187,11 @@ export class SdkRuns {
187
187
  const revisionBody = entry.revision.body;
188
188
  if (revisionBody.maxCostUsd !== undefined)
189
189
  throw new ApiError("agent_not_runnable", "AgentRun cannot enforce a spend cap on an external SDK. Configure the budget in the backend SDK and remove this managed run cap.");
190
+ // A runner keeps an SDK run's evidence and ends it: while every runner here refused to claim, the start is refused in
191
+ // their words, as any start is (prepareLaunch), before the caller holds a receipt it would run on.
192
+ const refused = await deps.runnersRefused?.();
193
+ if (refused !== undefined)
194
+ throw new ApiError("runner_refused", refused);
190
195
  const learning = await learningStartFor(deps, entry, pinned.revision, revisionBody, {
191
196
  noWorkflows: !workflow,
192
197
  ...(compile.model ? { model: compile.model } : {}),
@@ -6,7 +6,7 @@ const object = (properties, required = Object.keys(properties)) => ({
6
6
  properties,
7
7
  required,
8
8
  });
9
- export const SDK_BINDING = object({ runtime: { enum: ["claude-agent-sdk", "codex-sdk"] } });
9
+ export const SDK_BINDING = object({ runtime: { enum: ["claude-agent-sdk", "codex-sdk", "eve"] } });
10
10
  const usage = object(Object.fromEntries(["input_tokens", "output_tokens", "cache_read_tokens", "cache_write_tokens", "cost_usd"].map((key) => [
11
11
  key,
12
12
  { type: [key === "cost_usd" ? "number" : "integer", "null"], minimum: 0 },
@@ -1,6 +1,9 @@
1
1
  import type { IncomingMessage } from "node:http";
2
2
  /** The one refusal a secret write from anything but the owner's session gets (403 forbidden). */
3
3
  export declare const SECRET_WRITE_REFUSAL = "Saving, replacing or removing a secret takes the owner's signed-in session in the console; the API token can't write secrets.";
4
+ /** The refusal's words with where to finish it: the one sentence, then "Finish it in the console: <link>" when the
5
+ * operation has a console page (registerSecretPage). The same link is the error's `details.console_url`. */
6
+ export declare const secretWriteRefusal: (link?: string) => string;
4
7
  /**
5
8
  * Whether the console a launcher opened on a loopback-bound server with no accounts (no password: the browser that
6
9
  * followed the launch link, `/?launch=<code>`, its cookie a session id made at random and kept by the server, never
@@ -89,13 +92,23 @@ export declare const writesSecret: (operationId: string, body: unknown) => boole
89
92
  /** Whether this request of `operationId` writes a secret: by its body, or by what it would drop or replace in the store
90
93
  * (its plane's stored predicate). The dispatch's one check asks this. */
91
94
  export declare function writesSecretFor(operationId: string, body: unknown, request: SecretRequest): Promise<boolean>;
95
+ /** An operation's console page: a fixed path, or one built from the request's non-secret fields. */
96
+ export type SecretPage = string | ((body: unknown, request: SecretRequest) => string | Promise<string>);
97
+ /** Where in the console the owner finishes `operationIds` (each a registered secret write). */
98
+ export declare function registerSecretPage(operationIds: string | readonly string[], page: SecretPage): void;
99
+ /** Whether `operationId` names its console page. */
100
+ export declare const hasSecretPage: (operationId: string) => boolean;
101
+ /** The console page that finishes this request of `operationId`, a path from the console's root; undefined when the
102
+ * console has none for it, or the page could not be built (then the refusal carries no link). */
103
+ export declare function secretPageFor(operationId: string, body: unknown, request: SecretRequest): Promise<string | undefined>;
92
104
  type Json = Record<string, unknown>;
93
105
  /** The operations of `doc` that write a secret: their request body marks a field `x-agentrun-secret`, or the operation is
94
106
  * marked whole (a removal, which has no body). The generated CLI leaves every one of them out. */
95
107
  export declare function markedOperations(doc: Json): string[];
96
- /** The marked operations of `doc` no plane registered a predicate for (`registered`): each a route a secret could take
97
- * past the dispatch check. Empty is the only passing answer. */
98
- export declare const unguardedOperations: (doc: Json, registered: readonly string[]) => string[];
108
+ /** The marked operations of `doc` no plane registered a predicate for nor said on purpose to write no secret
109
+ * (registerNotSecretWrite: a preview's marked fields are kept nowhere): each a route a secret could take past the
110
+ * dispatch check. Empty is the only passing answer. */
111
+ export declare const unguardedOperations: (doc: Json) => string[];
99
112
  /** Where a secret came from: the environment the server starts with (which always wins, by the same name), pasted in the
100
113
  * console, or obtained by a sign-in (OAuth, Connect); null when it is not set. */
101
114
  export type SecretSource = "env" | "console" | "sign-in";
@@ -1,6 +1,9 @@
1
1
  import { byConsoleSession, byOwnerSession } from "./page.js";
2
2
  /** The one refusal a secret write from anything but the owner's session gets (403 forbidden). */
3
3
  export const SECRET_WRITE_REFUSAL = "Saving, replacing or removing a secret takes the owner's signed-in session in the console; the API token can't write secrets.";
4
+ /** The refusal's words with where to finish it: the one sentence, then "Finish it in the console: <link>" when the
5
+ * operation has a console page (registerSecretPage). The same link is the error's `details.console_url`. */
6
+ export const secretWriteRefusal = (link) => (link ? `${SECRET_WRITE_REFUSAL} Finish it in the console: ${link}` : SECRET_WRITE_REFUSAL);
4
7
  // ---- who may write a secret ------------------------------------------------------------------------------------------
5
8
  /**
6
9
  * Whether the console a launcher opened on a loopback-bound server with no accounts (no password: the browser that
@@ -77,6 +80,27 @@ export async function writesSecretFor(operationId, body, request) {
77
80
  const stored = storedPredicates.get(operationId);
78
81
  return stored ? (await stored(body, request)) === true : false;
79
82
  }
83
+ const pages = new Map();
84
+ /** Where in the console the owner finishes `operationIds` (each a registered secret write). */
85
+ export function registerSecretPage(operationIds, page) {
86
+ for (const operationId of typeof operationIds === "string" ? [operationIds] : operationIds)
87
+ pages.set(operationId, page);
88
+ }
89
+ /** Whether `operationId` names its console page. */
90
+ export const hasSecretPage = (operationId) => pages.has(operationId);
91
+ /** The console page that finishes this request of `operationId`, a path from the console's root; undefined when the
92
+ * console has none for it, or the page could not be built (then the refusal carries no link). */
93
+ export async function secretPageFor(operationId, body, request) {
94
+ const page = pages.get(operationId);
95
+ if (typeof page !== "function")
96
+ return page;
97
+ try {
98
+ return await page(body, request);
99
+ }
100
+ catch {
101
+ return undefined;
102
+ }
103
+ }
80
104
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
81
105
  /** Whether `schema` (in `doc`, its $refs followed once each) marks any field `x-agentrun-secret: true`. */
82
106
  function marksSecret(doc, schema, seen = new Set()) {
@@ -113,9 +137,10 @@ export function markedOperations(doc) {
113
137
  }
114
138
  return out;
115
139
  }
116
- /** The marked operations of `doc` no plane registered a predicate for (`registered`): each a route a secret could take
117
- * past the dispatch check. Empty is the only passing answer. */
118
- export const unguardedOperations = (doc, registered) => markedOperations(doc).filter((operationId) => !registered.includes(operationId));
140
+ /** The marked operations of `doc` no plane registered a predicate for nor said on purpose to write no secret
141
+ * (registerNotSecretWrite: a preview's marked fields are kept nowhere): each a route a secret could take past the
142
+ * dispatch check. Empty is the only passing answer. */
143
+ export const unguardedOperations = (doc) => markedOperations(doc).filter((operationId) => !registry.has(operationId) && notSecretWriteReason(operationId) === undefined);
119
144
  /** A secret's name, "<plane>:<id>": the plane and each part of its id joined with ":" (secretName("computer", provider,
120
145
  * KEY) is "computer:<provider>:<KEY>", secretName("workspace", "archil") "workspace:archil"). */
121
146
  export function secretName(plane, ...id) {
@@ -6,6 +6,7 @@
6
6
  import { sealedSettingsOverStore } from "./sealed-settings-store.js";
7
7
  import { besideTheStore } from "./server-secrets.js";
8
8
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
9
+ import { SLACK_CHANNEL, SLACK_URL_SPEC, slackUrlForms } from "./slack.js";
9
10
  import { WEBHOOK_CHANNEL, WEBHOOK_SECRET_SPEC } from "./webhooks.js";
10
11
  /** The server's own secrets over the store: what it keeps beside the store (besideTheStore), the outbound webhook's
11
12
  * signing secret and each one it held before (adapter webhook-out, retired ones too, so a secret replaced or removed stays
@@ -23,6 +24,10 @@ export async function openServerSecretsOverStore(store, data, env, adapters, say
23
24
  const webhookSettings = sealedSettingsOverStore(store, WEBHOOK_CHANNEL, WEBHOOK_SECRET_SPEC, key, (fields) => fields.condition === "trigger_setting_unopened" ? say({ condition: "unreadable", name: SEAL_KEY_ENV, data, effect: "this server's webhook secret cannot be read under this seal key, so it is not cut" }) : say(fields));
24
25
  await webhookSettings.load();
25
26
  secrets.add("webhook", () => webhookSettings.values());
27
+ // Slack's incoming-webhook URL, and each it held before (slack.ts): the URL is the credential, cut as a secret is.
28
+ const slackSettings = sealedSettingsOverStore(store, SLACK_CHANNEL, SLACK_URL_SPEC, key, (fields) => fields.condition === "trigger_setting_unopened" ? say({ condition: "unreadable", name: SEAL_KEY_ENV, data, effect: "this server's Slack URL cannot be read under this seal key, so it is not cut" }) : say(fields));
29
+ await slackSettings.load();
30
+ secrets.add("slack", () => slackSettings.values().flatMap(slackUrlForms));
26
31
  const settings = new Map();
27
32
  for (const adapter of adapters) {
28
33
  if (!adapter.settings)