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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/CHANGELOG.md +211 -1
  2. package/NOTICE +4 -0
  3. package/README.md +350 -53
  4. package/dist/acp-package.d.ts +53 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +3 -4
  7. package/dist/adapter-facts.js +4 -4
  8. package/dist/adapters.d.ts +3 -5
  9. package/dist/adapters.js +1 -31
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/answer-json.d.ts +10 -0
  13. package/dist/answer-json.js +24 -0
  14. package/dist/api-only.d.ts +11 -11
  15. package/dist/api-only.js +16 -11
  16. package/dist/archil-routes.js +2 -1
  17. package/dist/browser-live.d.ts +9 -4
  18. package/dist/browser-live.js +18 -5
  19. package/dist/cap.js +10 -2
  20. package/dist/chatgpt-plan.js +2 -1
  21. package/dist/cli.js +109 -41
  22. package/dist/composio-made.d.ts +19 -2
  23. package/dist/composio-made.js +17 -5
  24. package/dist/composio-preset.d.ts +42 -7
  25. package/dist/composio-preset.js +106 -70
  26. package/dist/composio-triggers.d.ts +9 -4
  27. package/dist/composio-triggers.js +20 -13
  28. package/dist/computer-attach.d.ts +11 -10
  29. package/dist/computer-attach.js +13 -14
  30. package/dist/computer-commands.d.ts +3 -0
  31. package/dist/computer-commands.js +3 -2
  32. package/dist/computer-lost.d.ts +4 -0
  33. package/dist/computer-lost.js +8 -3
  34. package/dist/computer-routes.d.ts +8 -5
  35. package/dist/computer-routes.js +7 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +2 -0
  38. package/dist/computers.d.ts +14 -76
  39. package/dist/computers.js +24 -68
  40. package/dist/conformance.d.ts +4 -0
  41. package/dist/conformance.js +6 -0
  42. package/dist/console/assets/index-CTGegcKt.css +1 -0
  43. package/dist/console/assets/index-D1Se6mgG.js +715 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/cost-heal.d.ts +13 -0
  46. package/dist/cost-heal.js +27 -0
  47. package/dist/dial-relay.d.ts +6 -2
  48. package/dist/dial-relay.js +9 -12
  49. package/dist/email/routes.js +2 -1
  50. package/dist/errors.d.ts +2 -0
  51. package/dist/errors.js +5 -0
  52. package/dist/exa-keyless.d.ts +1 -1
  53. package/dist/exa-keyless.js +1 -1
  54. package/dist/faux-computers.d.ts +2 -3
  55. package/dist/faux-computers.js +9 -31
  56. package/dist/github-connection.js +2 -1
  57. package/dist/harness-archive.d.ts +19 -2
  58. package/dist/harness-archive.js +49 -15
  59. package/dist/harness-check.d.ts +75 -0
  60. package/dist/harness-check.js +518 -0
  61. package/dist/harness-cursor.d.ts +28 -0
  62. package/dist/harness-cursor.js +42 -0
  63. package/dist/harness-goose.d.ts +4 -29
  64. package/dist/harness-goose.js +6 -86
  65. package/dist/harness-module.d.ts +4 -0
  66. package/dist/harness-module.js +1 -0
  67. package/dist/harness-owned.d.ts +52 -0
  68. package/dist/harness-owned.js +92 -0
  69. package/dist/harness-recipe.d.ts +127 -0
  70. package/dist/harness-recipe.js +335 -0
  71. package/dist/harness-table.d.ts +120 -5
  72. package/dist/harness-table.js +280 -6
  73. package/dist/harness.d.ts +2 -0
  74. package/dist/harness.js +5 -4
  75. package/dist/host-check.d.ts +6 -0
  76. package/dist/host-check.js +14 -0
  77. package/dist/host.d.ts +10 -3
  78. package/dist/host.js +17 -3
  79. package/dist/import-sources.d.ts +2 -0
  80. package/dist/import-sources.js +2 -0
  81. package/dist/import-summary.d.ts +15 -5
  82. package/dist/import-summary.js +24 -8
  83. package/dist/import.d.ts +24 -4
  84. package/dist/import.js +108 -26
  85. package/dist/key-refusal.d.ts +3 -1
  86. package/dist/key-refusal.js +26 -5
  87. package/dist/key-words.d.ts +1 -1
  88. package/dist/key-words.js +4 -4
  89. package/dist/learn/check.d.ts +3 -0
  90. package/dist/learn/check.js +31 -20
  91. package/dist/learn/compile.js +12 -5
  92. package/dist/learn/promote.d.ts +80 -2
  93. package/dist/learn/promote.js +95 -3
  94. package/dist/learn/secrets.d.ts +4 -0
  95. package/dist/learn/secrets.js +23 -0
  96. package/dist/learned-nodes.d.ts +4 -3
  97. package/dist/learned-workflow.js +4 -1
  98. package/dist/learning-cost.d.ts +6 -16
  99. package/dist/learning-cost.js +6 -12
  100. package/dist/learning-model.d.ts +18 -0
  101. package/dist/learning-model.js +77 -0
  102. package/dist/learning-words.d.ts +2 -0
  103. package/dist/learning-words.js +1 -1
  104. package/dist/listen-first.d.ts +10 -0
  105. package/dist/listen-first.js +25 -1
  106. package/dist/llms.txt +2 -1
  107. package/dist/mcp-gateway.d.ts +2 -1
  108. package/dist/mcp-gateway.js +31 -15
  109. package/dist/mcp-probe.d.ts +18 -6
  110. package/dist/mcp-probe.js +41 -8
  111. package/dist/mcp-secret-writes.d.ts +8 -0
  112. package/dist/mcp-secret-writes.js +104 -4
  113. package/dist/mcp-servers-store.d.ts +11 -5
  114. package/dist/mcp-servers-store.js +46 -20
  115. package/dist/model-form.d.ts +2 -1
  116. package/dist/model-form.js +30 -16
  117. package/dist/model-gateway.d.ts +113 -0
  118. package/dist/model-gateway.js +433 -0
  119. package/dist/model.d.ts +5 -3
  120. package/dist/model.js +26 -18
  121. package/dist/monid.js +1 -1
  122. package/dist/native/binding.d.ts +4 -0
  123. package/dist/native/binding.js +9 -0
  124. package/dist/native/cli.d.ts +3 -2
  125. package/dist/native/cli.js +6 -5
  126. package/dist/openapi.d.ts +2 -0
  127. package/dist/openapi.js +356 -43
  128. package/dist/owner.d.ts +4 -2
  129. package/dist/owner.js +10 -4
  130. package/dist/page.d.ts +9 -0
  131. package/dist/page.js +10 -2
  132. package/dist/port-models.js +17 -10
  133. package/dist/provider.d.ts +3 -3
  134. package/dist/provider.js +12 -3
  135. package/dist/public-address.d.ts +28 -0
  136. package/dist/public-address.js +62 -0
  137. package/dist/run-launch.d.ts +1 -1
  138. package/dist/run-launch.js +1 -1
  139. package/dist/run-secrets.d.ts +3 -2
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-trace.js +6 -3
  142. package/dist/runner/adapter-loop.d.ts +14 -8
  143. package/dist/runner/adapter-loop.js +58 -24
  144. package/dist/runner/adapter-run-spec.d.ts +15 -2
  145. package/dist/runner/adapter-run-spec.js +48 -10
  146. package/dist/runner/adapters/index.d.ts +4 -2
  147. package/dist/runner/adapters/index.js +6 -26
  148. package/dist/runner/adapters/pi.d.ts +5 -2
  149. package/dist/runner/adapters/pi.js +7 -4
  150. package/dist/runner/audit.d.ts +7 -0
  151. package/dist/runner/audit.js +15 -6
  152. package/dist/runner/claim-secrets.js +5 -1
  153. package/dist/runner/cli-run-spec.js +22 -10
  154. package/dist/runner/compare-end.d.ts +43 -0
  155. package/dist/runner/compare-end.js +95 -0
  156. package/dist/runner/computer-journal.d.ts +3 -0
  157. package/dist/runner/computer-journal.js +22 -2
  158. package/dist/runner/conformance/host-tools.d.ts +4 -0
  159. package/dist/runner/conformance/host-tools.js +14 -0
  160. package/dist/runner/harness-loops.d.ts +6 -1
  161. package/dist/runner/harness-loops.js +94 -54
  162. package/dist/runner/held.d.ts +5 -4
  163. package/dist/runner/journal-kinds.d.ts +4 -1
  164. package/dist/runner/journal-kinds.js +3 -0
  165. package/dist/runner/loop-contract.d.ts +10 -0
  166. package/dist/runner/main.d.ts +5 -5
  167. package/dist/runner/main.js +62 -11
  168. package/dist/runner/mcp-claim.js +40 -12
  169. package/dist/runner/meta-tools.js +4 -2
  170. package/dist/runner/metrics.d.ts +26 -0
  171. package/dist/runner/metrics.js +44 -1
  172. package/dist/runner/presence.d.ts +44 -0
  173. package/dist/runner/presence.js +96 -0
  174. package/dist/runner/promotion.d.ts +70 -7
  175. package/dist/runner/promotion.js +178 -28
  176. package/dist/runner/run-child-host.js +40 -10
  177. package/dist/runner/runner.d.ts +5 -0
  178. package/dist/runner/runner.js +8 -0
  179. package/dist/runner/sdk-loop.js +25 -1
  180. package/dist/runner/store-port.d.ts +3 -0
  181. package/dist/runner/store-secrets.js +19 -7
  182. package/dist/runner/workflow-first.d.ts +5 -2
  183. package/dist/runner/workflow-first.js +6 -3
  184. package/dist/runner/workflow-spec.js +3 -2
  185. package/dist/runs-over-store.d.ts +7 -2
  186. package/dist/runs-over-store.js +12 -4
  187. package/dist/sdk/check.d.ts +31 -0
  188. package/dist/sdk/check.js +58 -0
  189. package/dist/sdk/runs.d.ts +11 -3
  190. package/dist/sdk/runs.js +90 -15
  191. package/dist/sdk/schema.js +12 -4
  192. package/dist/secret-writes.d.ts +16 -3
  193. package/dist/secret-writes.js +28 -3
  194. package/dist/server-secrets-store.js +5 -0
  195. package/dist/server.d.ts +34 -2
  196. package/dist/server.js +437 -90
  197. package/dist/sign-ins-secrets.js +4 -1
  198. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  199. package/dist/slack-url.d.ts +5 -0
  200. package/dist/slack-url.js +11 -0
  201. package/dist/slack.d.ts +107 -0
  202. package/dist/slack.js +292 -0
  203. package/dist/start-switches.d.ts +28 -0
  204. package/dist/start-switches.js +37 -0
  205. package/dist/stats.d.ts +1 -1
  206. package/dist/stats.js +2 -1
  207. package/dist/stop-signals.d.ts +11 -0
  208. package/dist/stop-signals.js +22 -0
  209. package/dist/store/agent-body.d.ts +1 -1
  210. package/dist/store/agent-body.js +2 -2
  211. package/dist/store/index.d.ts +3 -3
  212. package/dist/store/index.js +1 -1
  213. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  214. package/dist/store/postgres/store.d.ts +1 -1
  215. package/dist/store/postgres/store.js +4 -2
  216. package/dist/store/schema.d.ts +13 -5
  217. package/dist/store/schema.js +20 -11
  218. package/dist/store/seal.d.ts +16 -4
  219. package/dist/store/sqlite/store.d.ts +1 -1
  220. package/dist/store/sqlite/store.js +112 -28
  221. package/dist/store/store.d.ts +78 -24
  222. package/dist/store/store.js +11 -0
  223. package/dist/store-reads/analytics.js +3 -2
  224. package/dist/store-reads/cap.d.ts +7 -0
  225. package/dist/store-reads/cap.js +11 -1
  226. package/dist/store-reads/journal.js +27 -1
  227. package/dist/store-reads/learning.d.ts +23 -2
  228. package/dist/store-reads/learning.js +29 -8
  229. package/dist/store-reads/runs.d.ts +9 -0
  230. package/dist/store-reads/runs.js +19 -6
  231. package/dist/store-reads/stats.d.ts +4 -1
  232. package/dist/store-reads/stats.js +15 -6
  233. package/dist/store-view.d.ts +125 -14
  234. package/dist/store-view.js +156 -21
  235. package/dist/telemetry.d.ts +7 -7
  236. package/dist/telemetry.js +38 -15
  237. package/dist/template-eval.js +5 -2
  238. package/dist/template-github-permissions.d.ts +5 -1
  239. package/dist/template-github-permissions.js +7 -3
  240. package/dist/timeline/index.d.ts +1 -1
  241. package/dist/timeline/index.js +1 -1
  242. package/dist/timeline/timeline.d.ts +8 -0
  243. package/dist/timeline/timeline.js +30 -0
  244. package/dist/tool-gate.d.ts +8 -4
  245. package/dist/tool-gate.js +6 -7
  246. package/dist/tool-keys-store.js +2 -2
  247. package/dist/tool-keys.js +2 -1
  248. package/dist/tool-plane.d.ts +4 -0
  249. package/dist/tool-plane.js +12 -12
  250. package/dist/trigger-adapter.d.ts +3 -4
  251. package/dist/trigger-adapter.js +2 -2
  252. package/dist/trigger-composio.js +3 -3
  253. package/dist/trigger-email.js +0 -2
  254. package/dist/trigger-feed.js +0 -2
  255. package/dist/trigger-schedule.js +3 -0
  256. package/dist/trigger-secrets-shown.d.ts +6 -3
  257. package/dist/trigger-secrets-shown.js +22 -13
  258. package/dist/trigger-targets.d.ts +12 -3
  259. package/dist/trigger-targets.js +90 -10
  260. package/dist/triggers.d.ts +2 -2
  261. package/dist/validate.js +5 -1
  262. package/dist/viewer-credential.d.ts +25 -0
  263. package/dist/viewer-credential.js +51 -0
  264. package/dist/webhooks.d.ts +82 -8
  265. package/dist/webhooks.js +128 -45
  266. package/dist/wires.d.ts +6 -1
  267. package/dist/wires.js +5 -0
  268. package/dist/workspace/attach.d.ts +3 -2
  269. package/dist/workspace/attach.js +2 -1
  270. package/dist/workspace/attached-computers.d.ts +6 -8
  271. package/dist/workspace/attached-computers.js +27 -24
  272. package/dist/workspace/computer-deps.d.ts +2 -3
  273. package/dist/workspace/computer-deps.js +3 -6
  274. package/dist/workspace/computer-for-claim.js +72 -96
  275. package/dist/workspace/computer-kept.d.ts +0 -7
  276. package/dist/workspace/computer-kept.js +0 -17
  277. package/dist/workspace/resolve-computer.d.ts +23 -14
  278. package/dist/workspace/resolve-computer.js +66 -61
  279. package/dist/workspace/synced-folder.d.ts +20 -15
  280. package/dist/workspace/synced-folder.js +33 -43
  281. package/launcher/agentrun-serve +4 -1
  282. package/package.json +18 -10
  283. package/skills/agentrun-serve/SKILL.md +11 -0
  284. package/templates/README.md +1 -1
  285. package/templates/code-review/agent.md +2 -3
  286. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  287. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  288. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  289. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  290. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  291. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  292. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -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
  },
@@ -5,9 +5,10 @@ import { setTimeout as delay } from "node:timers/promises";
5
5
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
6
6
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
7
7
  import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
8
- import { learningFolderOf } from "../learning.js";
8
+ import { learningFolderOf, secretsShown } from "../learning.js";
9
9
  import { said, STOPPED } from "../learning-words.js";
10
10
  import { closeSdkInbox, sdkInbox } from "../sdk/runs.js";
11
+ import { settleSdkCheck } from "../sdk/check.js";
11
12
  import { runPathOverStore } from "../store-reads/learning.js";
12
13
  import { capSpendOf, learningEndOfRun } from "./learning-end.js";
13
14
  import { AskOverCap, bookedAsk } from "./sdk-ask.js";
@@ -89,6 +90,23 @@ export function createSdkLoop(launch, host, route) {
89
90
  },
90
91
  },
91
92
  }] : undefined;
93
+ // A connected agent's check settles at its run's end (sdk/check.ts), its error logged: never one that skips the
94
+ // run's own end or its learning.
95
+ const settleCheck = async (inbox, agentId) => {
96
+ try {
97
+ const agent = agentId ?? (await host.store.runs.get(claim.runId))?.agentId;
98
+ if (!agent)
99
+ return;
100
+ await settleSdkCheck({
101
+ store: host.store, agentId: agent, launch, inbox,
102
+ shown: async () => secretsShown(Object.values(await storeSecrets(host.store, host.sealKey, host.data)), { local: true }),
103
+ log: (line) => host.log?.(line),
104
+ });
105
+ }
106
+ catch (error) {
107
+ host.log?.(`workflow-first: the connected agent's check on run ${claim.runId} could not be settled (${error instanceof Error ? error.message : String(error)}); it is decided at its deadline`);
108
+ }
109
+ };
92
110
  let endPatch = END_PATCH_UNKNOWN;
93
111
  // The end keeps cost and path together, under the same bound as the other loops. A failed or late read
94
112
  // leaves both unknown; the completed backend task is still completed. No read writes after this end.
@@ -161,6 +179,8 @@ export function createSdkLoop(launch, host, route) {
161
179
  partial = (partial + event.text).slice(-16_000);
162
180
  else if (event.type === "session")
163
181
  entries.push({ kind: `${MARK}.session`, data: { session_id: event.session_id } });
182
+ else if (event.type === "workflow_check")
183
+ entries.push({ kind: `${MARK}.workflow_check`, data: event });
164
184
  else if (event.type === "tool") {
165
185
  if (event.status === "started") {
166
186
  liveTools.set(event.id, { callId: event.id, name: event.name, args: event.input });
@@ -251,6 +271,7 @@ export function createSdkLoop(launch, host, route) {
251
271
  },
252
272
  },
253
273
  ]);
274
+ await settleCheck(inbox, source.agentId);
254
275
  if (result.status === "completed") {
255
276
  const end = learningEndOfRun(launch, {
256
277
  store: host.store,
@@ -422,6 +443,9 @@ export function createSdkLoop(launch, host, route) {
422
443
  const inbox = await closeSdkInbox(host.store, claim, stopped?.kind === "command" ? "cancelled" : "failed");
423
444
  if (inbox.completion && stopped?.kind !== "command")
424
445
  return { state: "interrupted" };
446
+ // No completion: a stopped or failed turn gives its check back, an expired one is its deadline.
447
+ if (!inbox.completion)
448
+ await settleCheck(inbox);
425
449
  if (stopped?.kind === "command") {
426
450
  const end = stopEnd(stopped.cancel);
427
451
  await append([{ kind: KINDS.end, data: end }], { ...end, ...endPatch }, droppedLearning(true), stopped.commandId);
@@ -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);
@@ -706,8 +706,9 @@ export const releaseCallHold = async () => {
706
706
  function callPolicyOf(store, runId, claimed) {
707
707
  // Nothing read yet: unread, so a policy asked before the first read fails closed too.
708
708
  let current = { settings: {}, problems: [], unreadable: true };
709
- // Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part.
710
- const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, true);
709
+ // Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part. A
710
+ // workflow runs on no harness's adapter, so no facts name its tools.
711
+ const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot, facts: undefined }, runId, claimed.revision, () => current, true);
711
712
  return async (tool) => {
712
713
  current = await storeSettings(store);
713
714
  return { permission: gate.policy(tool), denyFrom: gate.denyFrom(tool) };
@@ -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,10 @@ 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. prepareLaunch, which holds no store, refuses a start
111
+ * with it (runner_refused); a reader that holds the store calls refuseWhileNoRunner on its runners instead. */
112
+ runnersRefused?(): Promise<string | undefined>;
108
113
  /** The create body's field issues, before the agent is read (server.ts runBodyIssues). */
109
114
  runBodyIssues(body: Json): InputIssue[];
110
115
  /** 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 { refuseWhileNoRunner } 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,10 @@ 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
+ await refuseWhileNoRunner(store.runners);
159
162
  if (moment.importedSource !== undefined)
160
163
  throw importedRefusal(moment);
161
164
  const launchBody = await controlLaunchBody(store, moment.id);
@@ -562,8 +565,8 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
562
565
  const native = nativeOf(revision.body);
563
566
  if (native && !nativeOf(entry.revision?.body)?.connected)
564
567
  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.");
568
+ if (native && nativeRunOverrides(body).length)
569
+ throw new ApiError("input_invalid", NATIVE_RUN_OVERRIDES_UNSUPPORTED);
567
570
  if (fileIds.length)
568
571
  await deps.readyFiles(fileIds);
569
572
  const rbody = revision.body;
@@ -575,6 +578,11 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
575
578
  const cap = typeof body.max_cost_usd === "number" ? body.max_cost_usd : rbody.maxCostUsd;
576
579
  if (capped && cap === undefined)
577
580
  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." }]);
581
+ // A run no runner here can claim is never taken to wait for good: refused in the runners' words, once the request reads
582
+ // right and before anything is pinned or made for it (runner/presence.ts).
583
+ const refused = await deps.runnersRefused?.();
584
+ if (refused !== undefined)
585
+ throw new ApiError("runner_refused", refused);
578
586
  const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
579
587
  // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
580
588
  // its server could not be listed, is refused with the rest (runnable).
@@ -0,0 +1,31 @@
1
+ import type { Shown } from "../learning.js";
2
+ import type { RunLaunch } from "../run-launch.js";
3
+ import type { Store } from "../store/store.js";
4
+ import type { SdkInbox } from "./runs.js";
5
+ export type SdkWorkflowCheckEvent = {
6
+ type: "workflow_check";
7
+ id: string;
8
+ digest: string;
9
+ outcome: "answered" | "handed_back" | "failed" | "skipped_write";
10
+ answer?: string;
11
+ reason?: string;
12
+ skipped?: {
13
+ tool: string;
14
+ unmarked?: true;
15
+ };
16
+ /** Fresh read-only calls the shadow made where the native recording had no result (the client's shadowReadFallback). */
17
+ fresh_reads?: number;
18
+ };
19
+ /** Settles a connected agent's check at its run's end. The client reports execution, never its own verdict, and the
20
+ * immutable completion is the baseline. A shadow that answered or handed back on a valid native turn is one row of the
21
+ * check (decideCheck); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the
22
+ * backend never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims
23
+ * compete on the reservation. */
24
+ export declare function settleSdkCheck(deps: {
25
+ store: Store;
26
+ agentId: string;
27
+ launch: RunLaunch;
28
+ inbox: SdkInbox;
29
+ shown: () => Promise<Shown>;
30
+ log: (line: string) => void;
31
+ }): Promise<import("../learn/promote.js").Recorded | undefined>;
@@ -0,0 +1,58 @@
1
+ import { decideCheck, releaseSdkCheck, sdkCheckDeadline, sdkInputText } from "../runner/promotion.js";
2
+ import { promotionOf, promotionsOf } from "../learn/promote.js";
3
+ /** Why a completed inbox's native turn cannot be its check's baseline, or undefined when it can: a completed turn with
4
+ * complete, unredacted evidence and no learned workflow or nested call in it, whose shadow answered or handed back. */
5
+ function notBaseline(inbox, reported) {
6
+ const result = inbox.completion;
7
+ if (result.status !== "completed")
8
+ return `its native turn ${result.status === "cancelled" ? "was cancelled" : "failed"}`;
9
+ if (result.evidence_complete === false)
10
+ return "the backend reported its native turn's evidence incomplete";
11
+ if (inbox.check_redacted)
12
+ return "its native evidence held a protected value, so two different answers could agree by their placeholder";
13
+ if (inbox.batches.some((batch) => batch.events.some((event) => event.type === "tool" && (event.name === "learned_workflow" || event.parent_tool_use_id !== undefined))))
14
+ return "its native turn ran a learned workflow, so its answer is not the agent's own";
15
+ if (!reported)
16
+ return "the connected agent reported no shadow check";
17
+ if (reported.outcome === "failed")
18
+ return `its shadow did not answer (${reported.reason ?? "no reason given"})`;
19
+ if (reported.outcome === "skipped_write")
20
+ return `its shadow stopped at a write the native turn did not make (${reported.skipped?.tool ?? "a tool"})`;
21
+ return undefined;
22
+ }
23
+ /** Settles a connected agent's check at its run's end. The client reports execution, never its own verdict, and the
24
+ * immutable completion is the baseline. A shadow that answered or handed back on a valid native turn is one row of the
25
+ * check (decideCheck); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the
26
+ * backend never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims
27
+ * compete on the reservation. */
28
+ export async function settleSdkCheck(deps) {
29
+ const { inbox } = deps;
30
+ const check = inbox.learning_check;
31
+ if (!check)
32
+ return;
33
+ const record = promotionOf(await promotionsOf(deps.store.settings, deps.agentId), check.workflow.name, check.digest);
34
+ if (record?.decided !== "replaying" || record.via !== "sdk" || record.replay_id !== check.id || !record.check || record.commit !== check.revision || record.runs?.[0] !== inbox.run_id)
35
+ return;
36
+ const completion = inbox.completion;
37
+ if (!completion) {
38
+ if (inbox.closed === "expired")
39
+ return sdkCheckDeadline(deps, record);
40
+ if (inbox.closed)
41
+ return releaseSdkCheck(deps, record, inbox.closed === "cancelled" ? "its native turn was stopped before the backend completed it" : "its native turn ended before the backend completed it");
42
+ return;
43
+ }
44
+ const reported = inbox.batches.flatMap((batch) => batch.events)
45
+ .find((event) => event.type === "workflow_check" && event.id === check.id && event.digest === check.digest);
46
+ const cause = notBaseline({ ...inbox, completion }, reported);
47
+ if (cause !== undefined || !reported)
48
+ return releaseSdkCheck(deps, record, cause ?? "the connected agent reported no shadow check");
49
+ const outcomes = { answered: 0, handed_back: 0, failed: 0, skipped_write: 0 };
50
+ outcomes[reported.outcome]++;
51
+ return decideCheck(deps, check.workflow.name, check.digest, record.check, {
52
+ rows: [{ of: inbox.run_id, input: sdkInputText(deps.launch), agent: completion.answer, outcome: reported.outcome,
53
+ answer: reported.outcome === "answered" ? reported.answer ?? null : null,
54
+ ...(reported.outcome === "handed_back" ? { escalated: reported.reason ?? "The shadow workflow handed the task back." } : {}),
55
+ }], cost: null, outcomes, unstarted: 0, ...(reported.fresh_reads ? { fresh_reads: reported.fresh_reads } : {}),
56
+ exactMismatchReason: "its answer did not match the native answer exactly; connected SDK checks do not use a semantic grader, so name the fields that carry the decision (learning.agree_on) when whole-answer equality is not the intended check",
57
+ }, (was) => was?.decided === "replaying" && was.replay_id === check.id, { via: "sdk", runs: record.runs, replay_id: check.id, commit: check.revision });
58
+ }
@@ -2,7 +2,9 @@ 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
+ import type { SdkWorkflowCheckEvent } from "./check.js";
6
+ import { type SdkWorkflowCheck } from "../runner/promotion.js";
7
+ export type SdkRuntime = "claude-agent-sdk" | "codex-sdk" | "eve";
6
8
  export type SdkUsage = {
7
9
  input_tokens: number | null;
8
10
  output_tokens: number | null;
@@ -10,7 +12,7 @@ export type SdkUsage = {
10
12
  cache_write_tokens: number | null;
11
13
  cost_usd: number | null;
12
14
  };
13
- export type SdkEvent = {
15
+ export type SdkEvent = SdkWorkflowCheckEvent | {
14
16
  type: "text";
15
17
  text: string;
16
18
  } | {
@@ -42,8 +44,12 @@ export type SdkInbox = {
42
44
  sequence: number;
43
45
  events: SdkEvent[];
44
46
  }[];
45
- /** Exact approved executable workflows delivered by the start receipt. */
47
+ /** Exact promoted executable workflows delivered by the start receipt. */
46
48
  learning_workflows?: LearnedWorkflow[];
49
+ /** A compiled draft reserved for a shadow check, never supplied to the native agent. */
50
+ learning_check?: SdkWorkflowCheck;
51
+ /** Server cleaning changed evidence: two different secret-bearing answers must never agree by their placeholder. */
52
+ check_redacted?: true;
47
53
  completion?: SdkCompletion;
48
54
  /** Internal terminal admission fence. No later evidence can be newly acknowledged after this CAS wins. */
49
55
  closed?: "expired" | "failed" | "cancelled";
@@ -81,6 +87,7 @@ export declare class SdkRuns {
81
87
  console_url: string;
82
88
  token: string;
83
89
  learning: {
90
+ check?: SdkWorkflowCheck | undefined;
84
91
  enabled: boolean;
85
92
  revision: string | null;
86
93
  context: string;
@@ -93,6 +100,7 @@ export declare class SdkRuns {
93
100
  console_url: string;
94
101
  token: string;
95
102
  learning: {
103
+ check?: SdkWorkflowCheck | undefined;
96
104
  enabled: boolean;
97
105
  revision: string | null;
98
106
  context: string;