@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59

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 (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
package/dist/server.js CHANGED
@@ -33,12 +33,13 @@ import { createServer } from "node:http";
33
33
  import proxyaddr from "proxy-addr";
34
34
  import { API_ONLY_HOOKED_KINDS, apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerSkipped, servedApiOnly } from "./api-only.js";
35
35
  import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
36
- import { holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
36
+ import { composioOutsideNamespaceServers, holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
37
37
  import { declaredKeys, keysOwed, keysOwedRefusal, runKeysOf, runKeysTriggerSkipped, undeclaredKeys, withCarried } from "./run-keys.js";
38
38
  import { capacityOverStore, capacityWindowOf } from "./capacity.js";
39
39
  import { carriedFields } from "./answer-json.js";
40
40
  import { dirname, join, relative, resolve, sep } from "node:path";
41
41
  import { pathToFileURL } from "node:url";
42
+ import { isDeepStrictEqual } from "node:util";
42
43
  import { Worker } from "node:worker_threads";
43
44
  import { once } from "node:events";
44
45
  import { existsSync } from "node:fs";
@@ -50,7 +51,7 @@ import { uuidv7 } from "./ids.js";
50
51
  import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, definitionOf, etagOf, externalKey, getAgent, listAgents, makeRevision, ownedElsewhere, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
51
52
  import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
52
53
  import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
53
- import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV } from "./web-run.js";
54
+ import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV, withHeld } from "./web-run.js";
54
55
  import { FAUX_MONID_ENV, MONID_KEY_ENV, monidReads, pinMonid, PRICED_BY_USAGE } from "./monid.js";
55
56
  import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
56
57
  import { ApiError, invalid, sentence, unsupported } from "./errors.js";
@@ -106,7 +107,9 @@ import { agentPointers, cutHanded, handedSecretValues, launchValuesOf, RETIRED_M
106
107
  import { runCutValues } from "./run-cut.js";
107
108
  import { readLaunchBody } from "./run-launch.js";
108
109
  import { modelKeyMisfit, modelKeyOf, modelKeyRequired, noServerKeyFor, runModelOrigin, serverKeyMissing } from "./run-model-key.js";
110
+ import { exportReadsOverStore } from "./run-export-store.js";
109
111
  import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
112
+ import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
110
113
  import { triggerTargets } from "./trigger-targets.js";
111
114
  import { labelFilter, labelsIssues } from "./run-labels.js";
112
115
  import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
@@ -122,7 +125,7 @@ import { keepGrade } from "./runner/feedback-round.js";
122
125
  import { gradeRow, notAuditableOf } from "./runner/audit.js";
123
126
  import { namedDisksOf } from "./learn/learning-of.js";
124
127
  import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
125
- import { auditLoopOf, COMPILE_AFTER_MAX } from "./learning-setting.js";
128
+ import { auditLoopOf, COMPILE_AFTER_MAX, holdsReservedKey, RESERVED_SEGMENT } from "./learning-setting.js";
126
129
  import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
127
130
  import { championOf, forgetRunCopies, GRADE_SOURCES, gradeView, LABEL_MAX, promotionsOf, promotionsShown, servingOf, servingStateOf, shownDeep } from "./learn/promote.js";
128
131
  import { workflowNodesOf } from "./learn/workflow-nodes.js";
@@ -133,7 +136,7 @@ import { REDACTED } from "./secret-cut.js";
133
136
  // The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
134
137
  const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
135
138
  import { runLines } from "./usage-lines.js";
136
- import { boxesByDefault, boxesLog, enabledBoxes, placeOffers, withNetworks } from "./place-offers.js";
139
+ import { boxesByDefault, boxesLog, DOCKER_NO_SOCKET, enabledBoxes, LOCAL_BOXES, placeOffers, withNetworks } from "./place-offers.js";
137
140
  import { dockerComputerRefusal, dockerPathsOf, FAUX_MOUNTINFO_ENV, remoteDockerOnce } from "./box-paths.js";
138
141
  import { dockerDaemonCheck } from "./docker-daemon.js";
139
142
  import { hostAddressesOnce, noHostAddresses, retryHostAddresses, unionOf } from "./docker-host-addresses.js";
@@ -144,7 +147,7 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
144
147
  import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
145
148
  import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
146
149
  import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
147
- import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, homeOf, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
150
+ import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
148
151
  import { ClaudeSignIns } from "./claude-sign-in.js";
149
152
  import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
150
153
  import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
@@ -152,7 +155,7 @@ import { recordDataRoot } from "./runner/disk-free.js";
152
155
  import { recordRunEnv, runFacingNames } from "./runner/runner-check.js";
153
156
  import { DRAIN_TIMEOUT } from "./runner/beside.js";
154
157
  import { runnerName } from "./runner/runner.js";
155
- import { analyticsFilter, analyticsView, statsView } from "./stats.js";
158
+ import { analyticsFilter, analyticsView, statsView, utcOf } from "./stats.js";
156
159
  import { loggedReads, within, WRAPPED_WAIT_MS, wrappedView } from "./wrapped.js";
157
160
  import { joinedBasis } from "./runner/metrics.js";
158
161
  import { unifiedUsage } from "./unified-usage.js";
@@ -167,7 +170,8 @@ import { SIGN_INS_DIR, vendorsOver } from "./sign-ins.js";
167
170
  import { signInsOverStore } from "./sign-ins-store.js";
168
171
  import { boundTool, MCP_AUTH_TYPES, marked, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
169
172
  import { composioEnvKey, composioMadeKey, composioPerRun } from "./composio-made.js";
170
- import { COMPOSIO_PER_RUN, composioForget, composioNote, composioSave, composioToolkits, composioTools } from "./composio-preset.js";
173
+ import { ownersComposioUsers, ownersUser } from "./composio-owners.js";
174
+ import { COMPOSIO_PER_RUN, composioForget, composioNote, composioSave, composioTokenUser, composioToolkits, composioTools } from "./composio-preset.js";
171
175
  import { ComposioTriggers, composioNoPublicUrl } from "./composio-triggers.js";
172
176
  import { loopbackWords, mcpServersOverStore } from "./mcp-servers-store.js";
173
177
  import { MCP_ALLOW_LOOPBACK_ENV, startSwitches, WEBHOOK_PRIVATE_TARGETS_ENV } from "./start-switches.js";
@@ -202,7 +206,7 @@ import { hereOf, Marketplace, marketplaceUrlOf } from "./marketplace.js";
202
206
  import { templateInstallLink, templateLink, templatesLink } from "./console-links.js";
203
207
  import { GITHUB_HOSTS, IMPORT_LIMITS } from "./template-source.js";
204
208
  import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, inputSchemaOf, isObject, stable, unknownFields } from "./validate.js";
205
- import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
209
+ import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, DEFAULT_BROWSER_VENDOR, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
206
210
  import { wakeAnsweredBySetting } from "./settings-wake.js";
207
211
  import { toolSettingsOverStore } from "./tool-settings-store.js";
208
212
  import { readApprovers, writeApprovers } from "./server-approvers.js";
@@ -215,7 +219,7 @@ import { heldRoute, holdIssues, runComputerRead } from "./computer-held-routes.j
215
219
  import { COMPUTER_ROUTES, computerHoldOf, computerRoute, runComputerKind } from "./computer-routes.js";
216
220
  import { runOver } from "./computer-commands.js";
217
221
  import { mintViewerCredential, VIEWER_PARAM, viewerCookie, viewerCredentialFor, viewerCredentialKey, viewerCredentialOf } from "./viewer-credential.js";
218
- import { ATTACH_PATH, AttachHub, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
222
+ import { ATTACH_PATH, AttachHub, containerSigns, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
219
223
  import { dockerDaemonOf } from "@parcha/agentrun-computer/docker";
220
224
  import { createAttachRoutes, liveRelays, pairedView } from "./computer-attach.js";
221
225
  import { pairedRefusal, withPaired } from "./workspace/attached-computers.js";
@@ -268,6 +272,14 @@ const MAX_WAIT_MS = 25_000;
268
272
  const HANDED_FIXED = ["revision", "hold", "hold_minutes"];
269
273
  /** How often the server fails the runs still queued while no runner here can take them (runner/presence.ts). */
270
274
  const REFUSED_SWEEP_MS = 2_000;
275
+ /** How long the server's stop waits for a ChatGPT sign-in it cancelled to end (ChatGPTPlan.close): one past its code's
276
+ * exchange saves its row before the store closes; one OpenAI holds longer does not hold the stop. */
277
+ const PLAN_CLOSE_MS = 2_000;
278
+ /** The ChatGPT sign-ins `plan` cancels, ended, or `ms` gone. */
279
+ const planClosed = (plan, ms) => {
280
+ let timer;
281
+ return Promise.race([plan.close(), new Promise((done) => (timer = setTimeout(done, ms)))]).finally(() => clearTimeout(timer));
282
+ };
271
283
  const PAGE_ROWS = 500;
272
284
  const FILE_LIST_CAP = 2_000;
273
285
  /** Where the stop's lines go (ServeOptions.notice). Best-effort: a notice that throws never stops a close or a start. */
@@ -371,6 +383,7 @@ export const ROUTES = [
371
383
  { method: "PUT", pattern: /^\/agents\/([^/]+)\/definition$/, name: "updateDefinition" },
372
384
  { method: "GET", pattern: /^\/agents\/([^/]+)\/revisions$/, name: "listRevisions" },
373
385
  { method: "GET", pattern: /^\/agents\/([^/]+)\/package$/, name: "getAgentPackage" },
386
+ { method: "GET", pattern: /^\/agents\/([^/]+)\/revisions\/([^/]+)\/skills$/, name: "getRevisionSkills" },
374
387
  { method: "POST", pattern: /^\/agents\/([^/]+)\/current$/, name: "setCurrent" },
375
388
  { method: "POST", pattern: /^\/agents\/([^/]+)\/archive$/, name: "archiveAgent" },
376
389
  { method: "POST", pattern: /^\/agents\/([^/]+)\/unarchive$/, name: "unarchiveAgent" },
@@ -404,6 +417,8 @@ export const ROUTES = [
404
417
  { method: "GET", pattern: /^\/runs\/([^/]+)\/trace$/, name: "getRunTrace" },
405
418
  // A run's usage lines (run-usage.ts): by meter, model, charger and provider, each with its quantity and its cost.
406
419
  { method: "GET", pattern: /^\/runs\/([^/]+)\/usage$/, name: "getRunUsage" },
420
+ // A run's share bundle (run-export.ts): an ended run as one agentrun.share/1 document, every string cut by the scrubber.
421
+ { method: "GET", pattern: /^\/runs\/([^/]+)\/export$/, name: "getRunExport" },
407
422
  { method: "POST", pattern: /^\/workflows\/validate$/, name: "validateWorkflow" },
408
423
  { method: "POST", pattern: /^\/runs\/([^/]+)\/pause$/, name: "pauseRun" },
409
424
  { method: "POST", pattern: /^\/runs\/([^/]+)\/resume$/, name: "resumeRun" },
@@ -618,7 +633,7 @@ async function keptBrowserOf(store, runId) {
618
633
  const kept = plane ? keptVendor(plane).browser : undefined;
619
634
  if (kept !== undefined)
620
635
  return kept;
621
- return granted ? "browserbase" : undefined;
636
+ return granted ? DEFAULT_BROWSER_VENDOR : undefined;
622
637
  }
623
638
  /** keptBrowserOf's answer for a run whose browser is its agent's browser computer. */
624
639
  const ON_COMPUTER = Symbol("the agent's browser computer");
@@ -718,7 +733,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
718
733
  const memory = hostMemory();
719
734
  // The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
720
735
  const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
721
- const tools = toolsView(env, toolSettings, noBoxReason(boxes), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
736
+ const tools = toolsView(env, toolSettings, noBoxReason(boxes, enabledBoxes(env)), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
722
737
  const browser = tools.find((tool) => tool.name === "browser");
723
738
  return {
724
739
  backend: "local",
@@ -781,7 +796,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
781
796
  thinking: [...THINKING_LEVELS],
782
797
  /** The browser a run's `browser` tool drives: the vendor it resolves to under the server's settings when the tool is
783
798
  * available here (tools[]), a browser provider's id (tool-plane.ts BROWSER_VENDOR_IDS), else none. */
784
- browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved : "browserbase"))(browser.resolves?.[DEFAULT_HARNESS]) : "none",
799
+ browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved : DEFAULT_BROWSER_VENDOR))(browser.resolves?.[DEFAULT_HARNESS]) : "none",
785
800
  /** A tool setting's `permission` (definition.tool_settings, /v2/settings/tools): allow, ask or deny, which the tool
786
801
  * gate holds every tool call to (tool-gate.ts); an ask is answered at POST /runs/{id}/approvals/{approval_id}. */
787
802
  tool_permissions: true,
@@ -1135,7 +1150,7 @@ async function startHolding(options, data, checked, stops) {
1135
1150
  // process of its own made is relayed to that runner's attach listener the same way (dial-relay.ts).
1136
1151
  const reach = liveReachOf(process.env, seal.key);
1137
1152
  // A runner in a process of its own that relays its dials (dial-relay.ts): one whose attach listener said it is there
1138
- // within PRESENCE_STALE_MS on the store's clock (liveRelays), at a host this server dials.
1153
+ // within RUNNER_STALE_MS on the store's clock (liveRelays), at a host this server dials.
1139
1154
  const relayedNow = async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined);
1140
1155
  const attachLog = (event, fields) => (log ? log(logLine(event, fields)) : void process.stderr.write(`agentrun-serve: ${logLine(event, fields)}\n`));
1141
1156
  const attach = createAttachRoutes({
@@ -1201,11 +1216,20 @@ async function startHolding(options, data, checked, stops) {
1201
1216
  const fields = { count: offList.length, servers: offList.join(","), line: `runs that grant these per_run MCP servers the API token saved are refused, nothing sent, until ${API_ONLY_MCP_ORIGINS_ENV} lists their origin` };
1202
1217
  log ? log(logLine("api_only_mcp_off_list", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_mcp_off_list", fields)}\n`);
1203
1218
  }
1219
+ // And the Composio servers the token saved before its users were namespaced, which may call as the owner's user: refused
1220
+ // at every claim (composioOutsideNamespace) until deleted. Their names alone, never a user or an address.
1221
+ const outside = options.apiOnly ? await composioOutsideNamespaceServers(store) : [];
1222
+ if (outside.length) {
1223
+ const fields = { count: outside.length, servers: outside.join(","), line: "runs that grant these Composio servers the API token saved before its Composio users were namespaced are refused, nothing sent: delete each, then save it again" };
1224
+ log ? log(logLine("api_only_composio_outside_namespace", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_composio_outside_namespace", fields)}\n`);
1225
+ }
1204
1226
  const mcpServers = mcpServersOverStore(store, own(withSecrets(base, "own")), VERSION);
1205
1227
  if (options.githubMcpOrigin)
1206
1228
  mcpServers.appOrigin = options.githubMcpOrigin;
1207
1229
  if (options.composioMcpOrigin)
1208
1230
  mcpServers.composioOrigin = options.composioMcpOrigin;
1231
+ if (options.composioControl)
1232
+ mcpServers.composioControl = options.composioControl;
1209
1233
  mcpServers.standIns = options.mcpStandIns === true;
1210
1234
  // The saved MCP servers' metadata (their addresses and the tools they list), a snapshot the checks read in step (which
1211
1235
  // servers are saved, a workflow's grants, the template apply): the server is the one writer of these rows (a save,
@@ -1247,11 +1271,13 @@ async function startHolding(options, data, checked, stops) {
1247
1271
  // where it is signed in. A sign-in, a sign-out or an expiry it sees makes the reading again, as a key's save does.
1248
1272
  const plan = new ChatGPTPlan({ store, sealKey: seal.key, log: (fields) => (log ? log(logLine("chatgpt", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("chatgpt", fields)}\n`)), changed: () => keysChanged() });
1249
1273
  await plan.load();
1250
- stops.push(async () => void plan.close());
1274
+ stops.push(() => planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS));
1251
1275
  // Claude Code's login on this machine (claude-login.ts): env carries where it is while the owner has it on, so
1252
1276
  // claude-agent's model checks see a model without a key. Unset, its switch follows the listen address: there on
1253
1277
  // loopback, off past it. A setting kept where the mode is now off or refused goes first.
1254
1278
  const loginOff = claudeLoginSwitchedOff(base, options.host ?? DEFAULT_HOST);
1279
+ // The routes' gate and capabilities' features.claude_login, from one rule (claude-login.ts claudeLoginServed).
1280
+ const loginServed = claudeLoginServed(loginOff, options.apiOnly === true);
1255
1281
  // The API keys made in the console (api-keys.ts), read once here: this process is the store's one server, so the keys
1256
1282
  // it holds are the store's. No value is kept, so none joins the server's secrets: a key in a text is cut by its shape
1257
1283
  // (redact/match.ts).
@@ -1270,15 +1296,18 @@ async function startHolding(options, data, checked, stops) {
1270
1296
  // since keys are made and revoked while the server runs, and the login's turn-on takes the keys' turn (oneOwnerDeps).
1271
1297
  const oneOwner = oneOwnerDeps({ apiOnly: options.apiOnly === true, tokens: tokens.length, keysDormant: options.harnessSignIn === true }, apiKeys);
1272
1298
  /** Why this server makes no API key now, in words; undefined when it does. The one-owner rule from its other side: a
1273
- * recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's. */
1299
+ * recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's. A
1300
+ * login kept while its folders are refused (the view's `refused`) counts as on: a mended folder brings it back with
1301
+ * no turn-on, so a key made meanwhile would open the person's plan to an app. Its turn-off removes it, and a key then. */
1274
1302
  const apiKeysRefused = async () => options.harnessSignIn ? HARNESS_SIGN_IN_REFUSES_API_KEYS : (await claudeLoginSetting(store.settings)) ? LOGIN_REFUSES_API_KEYS : undefined;
1275
1303
  // Making a key, revoking one and turning the login on each take a turn (ApiKeys.inTurn; the login's is taken in
1276
1304
  // turnOnClaudeLogin, through oneOwnerDeps' `turn`), one at a time: each decides by what the others left once their writes
1277
1305
  // landed or were undone, never by a key taken out for a removal that then fails.
1278
1306
  // The sign-in this server starts, kept for this process (claude-sign-in.ts). Its queue is the one way the login's
1279
- // setting changes, the drop here included. A server whose user owns no home for the login (homeOf) drops it too.
1307
+ // setting changes, the drop here included. A server whose user may not use the saved login's folders (its home, or
1308
+ // those its env gives this machine's login: loginRefused) keeps it, refused in words, and logs why.
1280
1309
  const claudeSignIns = new ClaudeSignIns({ limitMs: options.claudeSignInLimitMs });
1281
- await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused() ?? homeOf(base).refused, (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
1310
+ await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused(), base, (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
1282
1311
  // The status checks' folders a server killed mid-check left in the temporary folder, each with a copy of the account
1283
1312
  // file (the harness's sweepClaudeStatusFolders): this user's alone, and only once the check has ended by the end it
1284
1313
  // wrote in its folder, so a check another server on this host runs now stays. Where the mode is there, as status
@@ -1309,7 +1338,7 @@ async function startHolding(options, data, checked, stops) {
1309
1338
  const isolation = await runIsolationOf(base, 1, () => { }).then(runIsolationName, () => "process");
1310
1339
  // The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
1311
1340
  // option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
1312
- const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets };
1341
+ const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
1313
1342
  // harness_keys.kept from the store's snapshot, made again at each key's save or removal (harnessKeysChanged's probe).
1314
1343
  const compose = (runnerShell) => {
1315
1344
  const made = askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
@@ -1435,31 +1464,121 @@ async function startHolding(options, data, checked, stops) {
1435
1464
  * key's save does. A sign-in this server starts opens a browser on its machine, so only where the console is on
1436
1465
  * loopback here; it is kept for this process (claudeSignIns, above), and one still waiting is ended at the stop. */
1437
1466
  stops.push(async () => claudeSignIns.close());
1438
- const loginDeps = () => ({
1439
- signIns: claudeSignIns,
1440
- settings: store.settings,
1441
- data,
1442
- env: base,
1443
- pinned: async () => claudeCliIn(installDirOf(data, LOGIN_HARNESS), (await import("@parcha/agentrun-harness-claude")).claudeAgentPlatform()),
1444
- // `refused` and `turn`: the keys are counted when the refusal is asked (inside the turn-on's turn, the keys' own).
1445
- ...oneOwner,
1446
- sameMachine: isLoopback(host) && !options.publicUrl,
1447
- claude: () => import("@parcha/agentrun-harness-claude"),
1448
- saved: (login) => {
1449
- claudeLogin = login;
1450
- },
1451
- changed: keysChanged,
1452
- });
1467
+ // The latest hand-over of the login (a turn on or off, or a refresh), until env, needs and the offers are made from
1468
+ // it. It never fails: a failed reading is answered to the request that handed the login over, as a key's save is.
1469
+ let handing = Promise.resolve();
1470
+ // Which the latest hand-over was (`why`: a refresh's or a turn on's or off's), whether its reading is still going
1471
+ // (`out`), and whether it failed (`failed`): the login held is then one env, needs and the offers were not made from,
1472
+ // and the next refresh hands it over again, though it finds it unchanged.
1473
+ let handed = { n: 0, why: "turn", out: false, failed: false };
1474
+ /** The server's login replaced by `login`, then env, needs and the offers made again from it (keysChanged). */
1475
+ const handOver = (login, why) => {
1476
+ claudeLogin = login;
1477
+ const mine = { n: handed.n + 1, why, out: true, failed: false };
1478
+ handed = mine;
1479
+ const made = keysChanged();
1480
+ // Only the latest hand-over's end counts: an earlier one that ends after it says nothing of the login held.
1481
+ const ended = (failed) => void (handed === mine && (handed = { ...mine, out: false, failed }));
1482
+ handing = made.then(() => ended(false), () => ended(true));
1483
+ return made;
1484
+ };
1485
+ const loginDeps = () => {
1486
+ // A turn hands the login over inside its turn (`saved`) and waits for the reading after it (`changed`), outside the
1487
+ // turn, so a sign-in pressed meanwhile never waits on it; a refresh asked meanwhile waits for it (`handing`).
1488
+ let made = Promise.resolve();
1489
+ return {
1490
+ signIns: claudeSignIns,
1491
+ settings: store.settings,
1492
+ data,
1493
+ env: base,
1494
+ pinned: async () => claudeCliIn(installDirOf(data, LOGIN_HARNESS), (await import("@parcha/agentrun-harness-claude")).claudeAgentPlatform()),
1495
+ // `refused` and `turn`: the keys are counted when the refusal is asked (inside the turn-on's turn, the keys' own).
1496
+ ...oneOwner,
1497
+ sameMachine: isLoopback(host) && !options.publicUrl,
1498
+ claude: () => import("@parcha/agentrun-harness-claude"),
1499
+ saved: (login) => {
1500
+ made = handOver(login, "turn");
1501
+ },
1502
+ changed: () => made,
1503
+ };
1504
+ };
1505
+ // The refresh asked and not yet started: a request that asks for one meanwhile shares it, since its look at the
1506
+ // folders comes after that request asked. It answers the hand-over it waited for (handed.n).
1507
+ let asked;
1508
+ // How many times a request looks at the login's folders (loginNow) before it gives up on a login that keeps changing.
1509
+ const LOGIN_ROUNDS = 3;
1510
+ /** One look at the login's folders (loginNow), and the wait for the latest hand-over's reading after it: answers which
1511
+ * hand-over that was, once its reading has ended. */
1512
+ const refreshOnce = () => {
1513
+ if (asked)
1514
+ return asked;
1515
+ if (claudeSignIns.busy)
1516
+ log?.(logLine("claude_login_wait", { why: "queue" }));
1517
+ asked = claudeSignIns
1518
+ .serial(async () => {
1519
+ asked = undefined;
1520
+ const login = loginOf(await claudeLoginSetting(store.settings), data, base);
1521
+ if (!isDeepStrictEqual(login, claudeLogin) || handed.failed)
1522
+ return { made: handOver(login, "refresh"), n: handed.n };
1523
+ if (handed.out)
1524
+ log?.(logLine("claude_login_wait", { why: handed.why }));
1525
+ return { made: handing, n: handed.n };
1526
+ })
1527
+ .then(async ({ made, n }) => {
1528
+ await made;
1529
+ return n;
1530
+ });
1531
+ return asked;
1532
+ };
1533
+ /** The login runs here go on, as its folders are now (loginOf, one look at them), handed over where it differs from
1534
+ * the one held. The held one is the start's or the last turn's, and a folder mended with a chmod since (or refused
1535
+ * since) changes it with no turn: a run's check, a save's, a template's plan or apply (prepareApply) and capabilities
1536
+ * ask this first, so they agree with the Settings view, which looks at the folders itself (loginAt). It answers once env,
1537
+ * needs and the offers are made from the login it found, so no request sees a new login with the offers made before
1538
+ * it. The look and the hand-over are one turn on the sign-ins' queue, the one way the setting changes, so a turn on or
1539
+ * off asked meanwhile lands before the look or after the hand-over, never between them. The reading after the
1540
+ * hand-over (keysChanged) goes on outside the queue, as a turn on's or off's does, so a sign-in, a turn on or off and
1541
+ * the server's stop never wait on its probe of the offers; where a turn off lands during it, the turn off's own
1542
+ * reading overtakes it (keysChanged's latest probe stands). Every refresh then waits for the latest hand-over's
1543
+ * reading, its own or another's (a turn's, or another refresh's). A refresh that finds the login as held, where the
1544
+ * latest reading failed, hands it over again, so a failed reading is made again by the next request, never left. The
1545
+ * log says when a refresh waits: for its turn (why=queue), or for another's reading (why=refresh or why=turn).
1546
+ * A reading that ends is not always one the offers were made by: a later hand-over (a turn on or off asked meanwhile)
1547
+ * may have started a probe that dropped its own, or another's reading it waited for failed. So once its wait ends, a
1548
+ * request goes on only where the hand-over it waited for is still the latest and did not fail; else it looks again
1549
+ * (refreshOnce), which waits for the later one or hands a failed one over again. A reading its own hand-over started
1550
+ * that fails is answered to it. A probe with no hand-over (a key's save, a harness key's, a new Ollama listing) can
1551
+ * drop the hand-over's too, and then fail or still be out: the hand-over is still the latest and did not fail, yet the
1552
+ * offers held were made before it. So the request also goes on only where the offers held are made from the inputs
1553
+ * now (offersMadeFrom); where not, it makes them as a key's save does (keysChanged: it waits for the probe out of
1554
+ * these inputs, or probes itself, and a probe of its own that fails is answered to it). It looks at most LOGIN_ROUNDS
1555
+ * times, then is refused (unavailable, retryable), so turns that keep coming never hold it for ever. */
1556
+ const loginNow = async () => {
1557
+ if (loginOff !== undefined)
1558
+ return;
1559
+ for (let round = 1;; round++) {
1560
+ const n = await refreshOnce();
1561
+ const latest = () => handed.n === n && !handed.failed;
1562
+ if (latest() && !offersMadeFrom(offersInputs(env)))
1563
+ await keysChanged();
1564
+ if (latest() && offersMadeFrom(offersInputs(env)))
1565
+ return;
1566
+ if (round >= LOGIN_ROUNDS)
1567
+ throw new ApiError("unavailable", `Claude Code's login on this machine was handed over again, or the offers made from it failed, each time this request waited for them, ${LOGIN_ROUNDS} times: ask again.`);
1568
+ }
1569
+ };
1453
1570
  // The boxes a place may name, read once from the computers runs execute on (place-offers.ts): AGENTRUN_BOXES lists
1454
- // them, docker alone when it is not set; docker by its probe, daytona and modal by their providers' keys, read as a
1455
- // run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's answer, and nothing asks Docker.
1571
+ // them, the local box (Docker's) alone when it is not set; the local box by Docker's probe, a vendor's by its
1572
+ // provider's required keys, read as a run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's
1573
+ // answer, and nothing asks Docker.
1456
1574
  const fauxDocker = Boolean(options.faux) && options.fauxDocker === true;
1457
- // A faux server's probe is on a host, as its Docker paths are below, so a test reads the same words in a container;
1458
- // `probeContainer` sets it for a test of a real one.
1575
+ // Where the probe takes this server to be is its own marks (place-offers.ts containerOf), faux or not, so a faux server
1576
+ // in AgentRun's image (the deploy walk's) says the image's words; `probeContainer` pins it for a test.
1459
1577
  // The probe names Docker's architecture too, which says which computerd build a Docker computer binds (below).
1460
1578
  let dockerArch;
1461
- const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } : options.faux ? { container: { inside: false } } : {}) });
1462
- const docker = found.some((offer) => offer.id === "docker" && offer.available);
1579
+ const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } : {}) });
1580
+ // Docker answers here: the local box (on this machine's container engine) is available.
1581
+ const docker = found.some((offer) => LOCAL_BOXES.includes(offer.id) && offer.available);
1463
1582
  // Under --faux, the mountinfo a test gives (fauxMountinfo, or FAUX_MOUNTINFO_ENV in the process's own environment, which
1464
1583
  // `env` leaves out: a server under test in a container names its own /proc/self/mountinfo there); with none, a faux
1465
1584
  // server is on a host.
@@ -1559,7 +1678,9 @@ async function startHolding(options, data, checked, stops) {
1559
1678
  }
1560
1679
  else if (box?.available)
1561
1680
  return { up: true };
1562
- return { up: false, absent: false, reason: box?.reason ?? `${provider} is not a box this server has` };
1681
+ // A container with no Docker socket at the start had no daemon there, as Settings → Computers words none
1682
+ // (noDockerWords, the vendors that fit each kind): not the start's words, which point at that very page.
1683
+ return { up: false, absent: box?.reason === DOCKER_NO_SOCKET, reason: box?.reason ?? `${provider} is not a box this server has` };
1563
1684
  };
1564
1685
  let computerRoutes;
1565
1686
  // The programs a provider runs on this machine (the phone's adb), looked for on PATH once, at the start, as the boxes
@@ -1579,8 +1700,10 @@ async function startHolding(options, data, checked, stops) {
1579
1700
  : {
1580
1701
  hostWhy,
1581
1702
  kinds: { SETTING_KINDS, PROVIDERS: COMPUTER_PROVIDERS, servingRefusals },
1582
- // The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own.
1583
- factories: computerProviderFactories(computerProviderMakers(), (id) => storeLedger(store.computerLedger, id)),
1703
+ // The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own, each given the
1704
+ // server's values of the host variables its descriptor reads (Docker's PATH, HOME and DOCKER_HOST, for its test and
1705
+ // an agent computer's release).
1706
+ factories: computerProviderFactories(computerProviderMakers({ env: process.env }), (id) => storeLedger(store.computerLedger, id)),
1584
1707
  answers: dockerAnswers,
1585
1708
  }),
1586
1709
  }));
@@ -2066,6 +2189,7 @@ async function startHolding(options, data, checked, stops) {
2066
2189
  const servedTimelineDeps = { serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses };
2067
2190
  const timelines = runTimelines({
2068
2191
  context: ctx,
2192
+ ...(options.timelinePollMs !== undefined ? { pollMs: options.timelinePollMs } : {}),
2069
2193
  // The run's rows as served (run-timeline-served.ts), by its one cut (run-cut.ts, read for each page: a secret rotated
2070
2194
  // or saved since is cut at once), the set its view's words, title and error are cut of: each secret this server never
2071
2195
  // shows and each browser sign-in pointer the run was handed; its decision rows among them, its error rows in the
@@ -2076,15 +2200,10 @@ async function startHolding(options, data, checked, stops) {
2076
2200
  // A live run's model requests sent and not answered (in-flight.ts), from its booking's records in its journal.
2077
2201
  inFlight: async (forStore, runId, context) => modelsInFlight(await runEntries(forStore, runId, context)),
2078
2202
  });
2079
- /** `text` as a message to run `runId` is written: cut of `handed` (what the message itself hands) and of what the run
2080
- * holds now (its turn's end erases those, and a read after it could no longer cut them). A run whose seal doesn't
2081
- * open here (its seal key changed or is missing, or what was sealed is damaged or lost) takes no message: 409
2082
- * not_continuable, reason withheld (WITHHELD_MESSAGE), and nothing is written, since what it can't read it can't
2083
- * cut, and a message written uncut would show those values once the run's end lets its reads go uncut-withheld.
2084
- * Read inside the turn that writes the message (runWrite), never before it: a message written first in that turn
2085
- * (one that hands a new key) is in the seal read here, so a message that says that key without handing it is cut of
2086
- * it too. Both writers of a message read it: a person's (sendMessage) and a trigger's (trigger-targets.ts
2087
- * message_run, which skips with those words). */
2203
+ /** `text`, a person's words written into run `runId`, cut of `handed` and of what the run holds now, read inside runWrite:
2204
+ * a message (sendMessage, and a trigger's message_run) and an approval's note (answerApproval). A seal that doesn't
2205
+ * open here refuses the words (409 not_continuable, reason withheld, WITHHELD_MESSAGE) and nothing is written: unread
2206
+ * values can't be cut. */
2088
2207
  async function cutHeld(runId, text, handed = []) {
2089
2208
  const held = launchValuesOf(sealKey, runId, (await store.runs.launch(runId)).sealed);
2090
2209
  if (held === "unreadable")
@@ -3130,6 +3249,8 @@ async function startHolding(options, data, checked, stops) {
3130
3249
  await launchNative(native);
3131
3250
  return;
3132
3251
  }
3252
+ // Claude Code's login as its folders are now, before the checks read env and the offers made with it.
3253
+ await loginNow();
3133
3254
  const shape = { ...shapeOf(revision), place, ...(revision.body.place ? {} : { unnamed: true }) };
3134
3255
  // An agentic revision's MCP tools are checked as its save pinned them (its pin, never the server's listing now), for
3135
3256
  // a server still saved here; a granted tool its pin does not hold is said first, with how to pin it.
@@ -3305,6 +3426,7 @@ async function startHolding(options, data, checked, stops) {
3305
3426
  }
3306
3427
  if (cliLearningOf(body) || sdkOf(body))
3307
3428
  return { warnings: [], stamp: {} };
3429
+ await loginNow();
3308
3430
  // A workflow's own issues, as POST /workflows/validate lists them (workflowIssues: the DSL's checks, the durable
3309
3431
  // runner's refusal), refuse its save before anything is written, each at its path under definition.workflow. Asked
3310
3432
  // with no tools list: its run binds every tool its call nodes name whether `tools` lists it or not (tools.ts
@@ -3585,6 +3707,9 @@ async function startHolding(options, data, checked, stops) {
3585
3707
  const had = onto ? await store.triggers.list(onto.agent.id) : [];
3586
3708
  if (onto && !plan && options.templateApplyRead)
3587
3709
  await options.templateApplyRead(onto.agent.id);
3710
+ // Claude Code's login as its folders are now, before the choice, the harness and the model are read from env and the
3711
+ // offers made with it.
3712
+ await loginNow();
3588
3713
  // A model choice's own keys are needed as the package's are: missing, the apply is refused and nothing is made. Under
3589
3714
  // the run-keys setting, a tool key is each run's to carry (run-keys.ts): its agent is made, the warning says so, and a
3590
3715
  // run that does not carry it is refused. A model key is still the server's, and so is monid's: the agent's monid tools
@@ -3936,6 +4061,9 @@ async function startHolding(options, data, checked, stops) {
3936
4061
  * tunnel's own port, say); else, with no Host, its own. Links made outside a request (the owner's, the webhooks') are
3937
4062
  * at the public URL or the server's own address. */
3938
4063
  const linkOrigin = (req) => (options.publicUrl ?? (req.headers.host ? ownOrigin(req) : url)).replace(/\/+$/, "");
4064
+ /** Who hands a run's launch secrets: the API token (every caller on an API-only server; elsewhere a request with an
4065
+ * Authorization header that may not write a secret), or the owner's session. */
4066
+ const handedBy = (req) => (options.apiOnly || (req.headers.authorization !== undefined && !mayHoldSecrets(req)) ? "token" : "owner");
3939
4067
  /** A run body's launch secrets taken out of it, before anything else reads the body: `mcp_auth`, the credentials a run's
3940
4068
  * caller hands its per_run MCP servers for this run alone (mcp-probe.ts mcpAuthOf), and `model_key`, the run's own model
3941
4069
  * key (run-model-key.ts), such as a LiteLLM virtual key minted for it. They never reach the run's saved body, its
@@ -3946,8 +4074,10 @@ async function startHolding(options, data, checked, stops) {
3946
4074
  * the model key must be text, else 422, nothing written. A retry its key already answered replays that answer even
3947
4075
  * when the server has since changed or gone, since it does no new work. `keys`, the run's own tool keys (run-keys.ts),
3948
4076
  * go the same way: each a tool key name to its value as text, else 422 by name, never with the value; whether the
3949
- * run's revision reads each is its start's check (prepareLaunch), by name alone. */
3950
- function handedLaunchSecrets(body) {
4077
+ * run's revision reads each is its start's check (prepareLaunch), by name alone. `by`: who hands them (handedBy). A
4078
+ * per-run Composio binding is sealed with it, and the token's binding of a Composio user the owner connects here
4079
+ * (composio-owners.ts, read at this check) is 422 at its composio_user_id, nothing written. */
4080
+ function handedLaunchSecrets(body, by) {
3951
4081
  if (body.mcp_auth === undefined && body.model_key === undefined && body.keys === undefined)
3952
4082
  return { body, handed: async () => ({}) };
3953
4083
  const { mcp_auth, model_key, keys: given, ...rest } = body;
@@ -3955,6 +4085,7 @@ async function startHolding(options, data, checked, stops) {
3955
4085
  const issues = [];
3956
4086
  const mcp = mcp_auth === undefined ? undefined : mcpAuthOf(mcp_auth, issues);
3957
4087
  const auth = {};
4088
+ let owners;
3958
4089
  for (const [server, entry] of Object.entries(mcp ?? {})) {
3959
4090
  const row = await getMcpServer(store, server);
3960
4091
  const field = `mcp_auth.${server}`;
@@ -3965,10 +4096,18 @@ async function startHolding(options, data, checked, stops) {
3965
4096
  // A per-run Composio server takes a binding (its key is its own); a per_run server takes headers; no other takes either.
3966
4097
  const perRunComposio = composioPerRun(row, await store.settings.get(composioMadeKey(server)));
3967
4098
  if ("composio" in entry) {
3968
- if (perRunComposio)
3969
- auth[server] = { composio: entry.composio, origin: new URL(row.url).origin };
3970
- else
4099
+ // A token's binding never calls as a user the owner calls as here (composio-owners.ts), one refusal per profile: on
4100
+ // API-only, where every caller is the token, McpServersOverStore.tokenBinding (which also checks a named account
4101
+ // is listed under the user); on the full profile, the token's binding here. The owner's session binds any user.
4102
+ const refused = perRunComposio && options.apiOnly ? await mcpServers.tokenBinding(server, row, entry.composio, field, options.composioControl ?? {}, stopping.signal) : undefined;
4103
+ if (!perRunComposio)
3971
4104
  issues.push({ field, reason: "not_an_option", message: `The MCP server ${server} is not a per-run Composio server: only one saved through the Composio preset with user_id "${COMPOSIO_PER_RUN}" takes a Composio account from a run.` });
4105
+ else if (refused)
4106
+ issues.push(refused);
4107
+ else if (!options.apiOnly && by === "token" && ownersUser((owners ??= await ownersComposioUsers(store)), entry.composio.user_id))
4108
+ issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is a Composio user the owner connects on this install: a run the API token starts or messages binds its own person's Composio user, never the owner's." });
4109
+ else
4110
+ auth[server] = { composio: { ...entry.composio, by }, origin: new URL(row.url).origin };
3972
4111
  }
3973
4112
  else if (row.auth === "per_run")
3974
4113
  auth[server] = { headers: entry.headers, origin: new URL(row.url).origin };
@@ -4002,7 +4141,7 @@ async function startHolding(options, data, checked, stops) {
4002
4141
  throw misfit(why);
4003
4142
  }
4004
4143
  else if (serverKeyMissing(env, target))
4005
- throw modelKeyRequired(false);
4144
+ throw modelKeyRequired(false, env);
4006
4145
  const origin = runModelOrigin(env);
4007
4146
  return sealRunLaunch(sealKey, runId, { ...(handed.mcp ? { mcp: handed.mcp } : {}), ...(handed.model !== undefined && origin ? { model: { key: handed.model, origin } } : {}), ...(handed.keys ? { keys: handed.keys } : {}) });
4008
4147
  };
@@ -4049,7 +4188,7 @@ async function startHolding(options, data, checked, stops) {
4049
4188
  const model = handed.model !== undefined && origin ? { key: handed.model, origin } : held.model;
4050
4189
  const keys = handed.keys ?? held.keys;
4051
4190
  if (!model && needsKey)
4052
- throw modelKeyRequired(true);
4191
+ throw modelKeyRequired(true, env);
4053
4192
  const unpaid = owed.length && revision ? keysOwed(revision, env, Object.keys(keys ?? {})) : [];
4054
4193
  if (unpaid.length)
4055
4194
  throw keysOwedRefusal(unpaid);
@@ -4061,7 +4200,7 @@ async function startHolding(options, data, checked, stops) {
4061
4200
  }
4062
4201
  async function createRun(req, agentId) {
4063
4202
  const entry = await needRunnableAgent(agentId);
4064
- const { body, handed } = handedLaunchSecrets(await bodyOf(req));
4203
+ const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
4065
4204
  // The host's run for a firing the launch hook handed it: the firing's own run, under the firing's key (a second start
4066
4205
  // answers that run), started by the trigger's target policy as a firing here starts one (its cap, which the host's may
4067
4206
  // lower, its effort when it sets one, its previous result, its trigger, origin and title), with the host's body and
@@ -4108,7 +4247,7 @@ async function startHolding(options, data, checked, stops) {
4108
4247
  * Its first run makes the agent, a version's first run its revision; a later run of the version reuses both
4109
4248
  * (runs-over-store startInline). The answer is POST /agents/{agent_id}/runs' own: 202 and the run. */
4110
4249
  async function createInlineRun(req) {
4111
- const { body, handed } = handedLaunchSecrets(await bodyOf(req));
4250
+ const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
4112
4251
  if (isObject(body.definition) && body.definition.cli_learning !== undefined)
4113
4252
  throw new ApiError("input_invalid", "CLI learning references are registered only through /cli-learning/connections on the source machine.");
4114
4253
  if (isObject(body.definition) && body.definition.native !== undefined)
@@ -4256,7 +4395,39 @@ async function startHolding(options, data, checked, stops) {
4256
4395
  throw new ApiError("bad_request", "source is one source's name (claude-code, codex, ...), or live; once");
4257
4396
  return given[0];
4258
4397
  }
4259
- async function runsPage(url, filter, origin, source) {
4398
+ /** GET /runs' `from` and `to`, each once: ISO instants with a zone (the server reads no time zone of its own), the window
4399
+ * [from, to) of the runs' starts, in ms. Either one alone; a `from` after `to` is 400, one equal to it an empty window. */
4400
+ function windowParams(url) {
4401
+ const instant = (name) => {
4402
+ const given = url.searchParams.getAll(name);
4403
+ if (given.length === 0)
4404
+ return undefined;
4405
+ // As the analytics' bounds read (stats.ts utcOf): an RFC 3339 date-time that exists, to the ms.
4406
+ const iso = given.length === 1 ? utcOf(given[0]) : undefined;
4407
+ if (iso === undefined)
4408
+ throw new ApiError("bad_request", `${name} is one RFC 3339 date-time with its zone (2026-11-01T00:00:00Z, or an offset such as +01:00), to the millisecond; once`);
4409
+ return Date.parse(iso);
4410
+ };
4411
+ const from = instant("from"), to = instant("to");
4412
+ if (from !== undefined && to !== undefined && from > to)
4413
+ throw new ApiError("bad_request", "from is at or before to: the window [from, to) of the runs' starts");
4414
+ return { ...(from !== undefined ? { startedFrom: from } : {}), ...(to !== undefined ? { startedBefore: to } : {}) };
4415
+ }
4416
+ /** GET /runs' `model`, once: a model as a run's metrics name it, `provider/model`. */
4417
+ function modelParam(url) {
4418
+ const given = url.searchParams.getAll("model");
4419
+ if (given.length === 0)
4420
+ return undefined;
4421
+ if (given.length > 1 || !/^[^\u0000-\u001f\u007f]{1,256}$/.test(given[0]))
4422
+ throw new ApiError("bad_request", "model is one model as a run's metrics name it (provider/model); once");
4423
+ return given[0];
4424
+ }
4425
+ /** GET /runs' own filters: `source`, the window (`from`, `to`) and `model`. */
4426
+ function runsOnly(url) {
4427
+ const source = sourceParam(url), model = modelParam(url);
4428
+ return { ...(source !== undefined ? { source } : {}), ...windowParams(url), ...(model !== undefined ? { model } : {}) };
4429
+ }
4430
+ async function runsPage(url, filter, origin, only = {}) {
4260
4431
  const limit = limitOf(url.searchParams.get("limit"));
4261
4432
  const offset = cursorOf(url.searchParams.get("cursor"));
4262
4433
  const status = url.searchParams.get("status");
@@ -4273,7 +4444,7 @@ async function startHolding(options, data, checked, stops) {
4273
4444
  // ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
4274
4445
  // journals. An audit's shadow run is no row of the list (learn/audit.ts): it is read by id, and its cost is its served
4275
4446
  // run's. A run's archive is its own or its agent's.
4276
- const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...(source !== undefined ? { source } : {}), archived };
4447
+ const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...only, archived };
4277
4448
  // A listing is built by the server's lister (run-listing.ts) once per change, so a list finds it current. One that is
4278
4449
  // behind (a write landed since, or the lister has not reached it since the store was upgraded) is built here, written
4279
4450
  // back, and shown as built: for a status filter, first every run still going whose listing is behind (its row's
@@ -4766,6 +4937,7 @@ async function startHolding(options, data, checked, stops) {
4766
4937
  const found = matching.find((r) => r.method === req.method || (req.method === "HEAD" && r.method === "GET"));
4767
4938
  if (!found)
4768
4939
  throw new ApiError("method_not_allowed", `${req.method} is not a method of ${path}`, {}, { allow: [...new Set(matching.map((r) => r.method))].join(", ") });
4940
+ // On API-only, a login route never gets here: the API-only gate refused it before routing.
4769
4941
  if (CLAUDE_LOGIN_ROUTES.has(found.name) && loginOff)
4770
4942
  throw new ApiError("not_found", claudeLoginRouteOff(found.name, loginOff));
4771
4943
  if (found.name === "getCapabilities") {
@@ -4775,6 +4947,7 @@ async function startHolding(options, data, checked, stops) {
4775
4947
  const runnerShell = shellTools(await shellOf({ kind: "none" }));
4776
4948
  await planNow();
4777
4949
  await ollamaNow();
4950
+ await loginNow();
4778
4951
  const answer = forCaller(runnerShell.size ? compose(runnerShell) : caps, byOwnerSession(req));
4779
4952
  // features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
4780
4953
  // runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
@@ -4785,11 +4958,15 @@ async function startHolding(options, data, checked, stops) {
4785
4958
  const state = await store.schemaState?.().catch(() => undefined);
4786
4959
  const storeSchema = state ? { store_schema: { version: state.version, runner_floor: state.runnerFloor, known: state.known } } : {};
4787
4960
  // features.harness_keys.kept names which harness ids still have keys stored: the owner's session or a holder of
4788
- // the server's token reads it; a caller with neither (this route answers before any bearer check) reads none.
4961
+ // the server's token reads it; a caller with neither (this route answers before any bearer check) reads none. A
4962
+ // bearer this server does not take still gets the answer, and the auth_failed line any other route writes for it.
4789
4963
  const keptShown = byOwnerSession(req) || bearer(req.headers.authorization, req);
4964
+ if (!keptShown && req.headers.authorization !== undefined)
4965
+ authFailed(`/v2${path}`, "wrong_token");
4790
4966
  const keptCap = { ...answer.features.harness_keys, kept: keptShown ? answer.features.harness_keys.kept : [] };
4967
+ // tools[].held: the server's keyless holds on each web tool now (web-run.ts withHeld), never cached.
4791
4968
  // features.api_keys.routes: false on an API-only server, which serves none of the keys' routes and reads no key.
4792
- return send(res, 200, { ...answer, ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, harness_keys: keptCap, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: !loginOff && !options.apiOnly, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
4969
+ return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, harness_keys: keptCap, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: loginServed, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
4793
4970
  }
4794
4971
  if (found.name === "getOpenapi")
4795
4972
  return send(res, 200, servedOpenapi(openapi, ownerCookieName(req)));
@@ -5331,6 +5508,17 @@ async function startHolding(options, data, checked, stops) {
5331
5508
  const page = all.slice(offset, offset + limit).map((row) => revisionView(entry.agent, row));
5332
5509
  return send(res, 200, { revisions: page, next_cursor: nextCursor(offset + limit, all.length) });
5333
5510
  }
5511
+ case "getRevisionSkills": {
5512
+ // Only the named revision is needed: the full agent view and numbered history load every skill bundle.
5513
+ if (!ID.test(id) || !await store.agents.get(id))
5514
+ throw new ApiError("not_found", `no agent ${id}`);
5515
+ const selected = await store.agents.revision(decodeURIComponent(second));
5516
+ if (!selected || selected.agentId !== id)
5517
+ throw new ApiError("not_found", "no such revision for this agent");
5518
+ // The complete immutable file map is needed before replacing skills in a definition edit. Native discovery
5519
+ // metadata is separate: this read never follows a connection to its source machine or filesystem.
5520
+ return send(res, 200, { revision: selected.id, skills: selected.skills ?? {} });
5521
+ }
5334
5522
  case "getAgentPackage": {
5335
5523
  const entry = await needAgent(id);
5336
5524
  const { agent, revision } = entry;
@@ -5470,7 +5658,7 @@ async function startHolding(options, data, checked, stops) {
5470
5658
  case "listAllRuns": {
5471
5659
  const agent = url.searchParams.get("agent") ?? undefined;
5472
5660
  const revision = url.searchParams.get("revision") ?? undefined;
5473
- return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req), sourceParam(url)));
5661
+ return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req), runsOnly(url)));
5474
5662
  }
5475
5663
  case "getRun": {
5476
5664
  const run = await runRead(id, linkOrigin(req));
@@ -5487,7 +5675,7 @@ async function startHolding(options, data, checked, stops) {
5487
5675
  const run = await needRun(id);
5488
5676
  if (run.kind === "workflow")
5489
5677
  throw unsupported("messages.steer_workflow_runs", "A workflow run takes no messages here: its workflow runs to its end, or a cancel ends it.");
5490
- const { body, handed } = handedLaunchSecrets(await bodyOf(req));
5678
+ const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
5491
5679
  const answer = await idempotent(req, `/runs/${id}/messages`, body, async () => {
5492
5680
  const secrets = await handed();
5493
5681
  const seal = await messageSeal(run, secrets);
@@ -5570,7 +5758,9 @@ async function startHolding(options, data, checked, stops) {
5570
5758
  issues.push({ field: "note", reason: "wrong_type", message: "note is a string of at most 2000 characters" });
5571
5759
  if (issues.length)
5572
5760
  throw invalid(issues);
5573
- await approve(store, run, decodeURIComponent(second), body.decision, typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined, body.confirm_destructive === true);
5761
+ // A note is cut as a message is, in the turn that writes it (cutHeld): refused when the seal does not open here.
5762
+ const note = typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined;
5763
+ await runWrite(run.agentId, run.id, async () => approve(store, run, decodeURIComponent(second), body.decision, note === undefined ? undefined : await cutHeld(run.id, note), body.confirm_destructive === true));
5574
5764
  res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
5575
5765
  return void res.end();
5576
5766
  }
@@ -5586,6 +5776,8 @@ async function startHolding(options, data, checked, stops) {
5586
5776
  throw invalid([{ field: "correct", reason: body.correct === undefined ? "missing" : "wrong_type", message: "correct is true or false: whether the run's answer was right" }]);
5587
5777
  if (body.expected !== undefined && !isObject(body.expected))
5588
5778
  throw invalid([{ field: "expected", reason: "wrong_type", message: "expected is an object: the fields a right answer's JSON holds" }]);
5779
+ if (holdsReservedKey(body.expected))
5780
+ throw invalid([{ field: "expected", reason: "not_allowed", message: `expected holds no key named ${RESERVED_SEGMENT}, at any depth` }]);
5589
5781
  if (body.source !== undefined && !GRADE_SOURCES.includes(body.source))
5590
5782
  throw invalid([{ field: "source", reason: "not_an_option", message: `source is one of ${GRADE_SOURCES.join(", ")}` }]);
5591
5783
  if (body.label !== undefined && (typeof body.label !== "string" || body.label.length > LABEL_MAX))
@@ -5616,7 +5808,7 @@ async function startHolding(options, data, checked, stops) {
5616
5808
  // A grade of a run its learned workflow answered alone is an audit row too (runner/audit.ts gradeRow): the hold rule
5617
5809
  // reads it with the shadows'. A row not written now is logged, never the grade refused.
5618
5810
  const said = (line) => log?.(logLine("audit", { run: row.id, said: line }));
5619
- await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, folder: () => learningFolderOf(data, row.agentId), shown: () => learningShown(row.agentId), log: said }, row, grade.correct).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
5811
+ await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, folder: () => learningFolderOf(data, row.agentId), shown: () => learningShown(row.agentId), log: said }, row, grade.correct, grade.expected).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
5620
5812
  return graded;
5621
5813
  });
5622
5814
  // Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
@@ -5659,7 +5851,14 @@ async function startHolding(options, data, checked, stops) {
5659
5851
  },
5660
5852
  computer: () => (viewed ? { kind: viewed } : computerOf(kept, env, family, own)),
5661
5853
  session: (kind) => sessionIn(kind, entries, run.terminal || (parked && kind !== "browser")),
5662
- lapsed: async (kind) => (parked ? lapsedOf(kind, await readKept(store.settings, run.id).catch(() => undefined), Date.now()) : undefined),
5854
+ // The keep's `until` is on the store's clock (computer-kept.ts Kept.until), so its lapse is judged on it; a
5855
+ // clock or a row that can't be read says nothing.
5856
+ lapsed: async (kind) => {
5857
+ if (!parked)
5858
+ return undefined;
5859
+ const at = await store.sealedKeys.clock().catch(() => undefined);
5860
+ return at === undefined ? undefined : lapsedOf(kind, await readKept(store.settings, run.id).catch(() => undefined), at);
5861
+ },
5663
5862
  hold: () => hold,
5664
5863
  // A going run's browser let go while it waited for its person: the Screen tab says so, with when. One settings
5665
5864
  // row (browser-wait-ended.ts), never the run's journal: this is read on every Screen poll.
@@ -5856,6 +6055,26 @@ async function startHolding(options, data, checked, stops) {
5856
6055
  // or where its figure is not its booking's.
5857
6056
  // Names through the run's cut, and a withheld run refused (403), as its trace is.
5858
6057
  return send(res, 200, await servedRunUsage({ serverSecrets, signIns, sealKey }, store, id));
6058
+ case "getRunExport": {
6059
+ await needRun(id);
6060
+ const restore = restoreIdsOf(url);
6061
+ const viewDeps = viewDepsFor(ownOriginOf());
6062
+ let bundle;
6063
+ try {
6064
+ bundle = await runExport(id, exportReadsOverStore(store, id, { view: viewDeps, timeline: servedTimelineDeps, runReads: runReadsDeps, cut: { serverSecrets, signIns, sealKey } }, ctx), { restore, version: VERSION, ...(options.shareScrub ? { scrub: options.shareScrub } : {}) });
6065
+ }
6066
+ catch (error) {
6067
+ if (error instanceof ApiError)
6068
+ throw error;
6069
+ // Fails closed: a scrub that failed, a read-back that found a value, or anything else that threw while the
6070
+ // bundle was made. Not one byte of it: a 500 with an empty body. The log names why, never a word of the run.
6071
+ log?.(logLine("export_failed", { run: id, why: error instanceof ExportFailed ? error.message : error?.name ?? "error" }));
6072
+ res.writeHead(500, { "cache-control": "no-store", "content-length": "0" });
6073
+ return void res.end();
6074
+ }
6075
+ res.writeHead(200, { "content-type": "application/json", "cache-control": "no-store", "x-content-type-options": "nosniff", "content-length": String(Buffer.byteLength(bundle.body)) });
6076
+ return void res.end(bundle.body);
6077
+ }
5859
6078
  case "getRunTrace":
5860
6079
  await needRun(id);
5861
6080
  // The run's spans over its served Timeline rows and its journal (run-trace.ts): cut by the run's one cut, as its
@@ -6089,7 +6308,8 @@ async function startHolding(options, data, checked, stops) {
6089
6308
  case "getMcpServer":
6090
6309
  return send(res, 200, await mcpServers.get(id));
6091
6310
  case "previewMcpServer":
6092
- return send(res, 200, await mcpServers.preview(await bodyOf(req), stopping.signal));
6311
+ // The API token's preview, as the gate reads a token's save: a server it saved is previewed at its shown address.
6312
+ return send(res, 200, await mcpServers.preview(await bodyOf(req), stopping.signal, req.headers.authorization !== undefined && !mayHoldSecrets(req)));
6093
6313
  case "saveMcpServer": {
6094
6314
  const body = await bodyOf(req);
6095
6315
  const preset = await mcpServers.composioPreset(id);
@@ -6124,10 +6344,18 @@ async function startHolding(options, data, checked, stops) {
6124
6344
  return send(res, 200, over.note ? { ...saved, composio: over.note } : saved);
6125
6345
  }
6126
6346
  // Composio makes the managed MCP server; what is kept is the ordinary MCP save, so the key is a sealed header.
6127
- case "listComposioTools":
6128
- return send(res, 200, await composioTools(await bodyOf(req), options.composioControl ?? {}, stopping.signal), { "cache-control": "no-store" });
6129
- case "listComposioToolkits":
6130
- return send(res, 200, await composioToolkits(await bodyOf(req), options.composioControl ?? {}, stopping.signal), { "cache-control": "no-store" });
6347
+ // A listing stops at Composio when the console stops asking (Cancel, a key edit: the response closes), or the server
6348
+ // stops.
6349
+ case "listComposioTools": {
6350
+ const done = new AbortController();
6351
+ res.once("close", () => done.abort());
6352
+ return send(res, 200, await composioTools(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
6353
+ }
6354
+ case "listComposioToolkits": {
6355
+ const done = new AbortController();
6356
+ res.once("close", () => done.abort());
6357
+ return send(res, 200, await composioToolkits(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
6358
+ }
6131
6359
  case "saveComposioServer": {
6132
6360
  // The name is checked before Composio is called: a refused name leaves nothing made there.
6133
6361
  mcpNameOf(id);
@@ -6139,11 +6367,13 @@ async function startHolding(options, data, checked, stops) {
6139
6367
  // server, in the delete's words, checked in its project's turn before the row is written. An API-only server's token
6140
6368
  // saves one that names its key by api_key_env (the secret-write gate), and over a saved server only one it saved
6141
6369
  // (mcp-secret-writes.ts tokenWriteOverRefused), landing only while the row still has the credential the gate read
6142
- // (secretSeen) and the token's mark. The body names no address or headers (composioSave refuses them).
6370
+ // (secretSeen) and the token's mark. The token's save stands on no auth config or ACTIVE account that no server it
6371
+ // saved holds (tokenStandsOn, tokenAccountOn), as a Composio user in its own namespace (composioTokenUser). The body
6372
+ // names no address or headers (composioSave refuses them).
6143
6373
  const answer = await inComposioTurn(async () => {
6144
6374
  const over = {};
6145
6375
  const guard = { turn: (work) => composioTriggers.inTurnOf(id, work), inUse: () => composioTriggers.inUse(id, SAVE_AFTER_TRIGGERS) };
6146
- const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url);
6376
+ const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url, byToken ? (config) => mcpServers.tokenStandsOn(config) : undefined, byToken ? (user, account) => mcpServers.tokenAccountOn(user, account) : undefined, byToken ? composioTokenUser : undefined);
6147
6377
  await refreshMcpMeta();
6148
6378
  return over.dropped ? { ...saved, composio: await composioLeft(id, over.dropped) } : saved;
6149
6379
  });
@@ -6158,7 +6388,7 @@ async function startHolding(options, data, checked, stops) {
6158
6388
  case "deleteComposioSubscription":
6159
6389
  return send(res, 200, await composioTriggers.forget(id), { "cache-control": "no-store" });
6160
6390
  case "refreshMcpServer": {
6161
- const refreshed = await mcpServers.refresh(id, stopping.signal, options.composioControl ?? {});
6391
+ const refreshed = await mcpServers.refresh(id, stopping.signal);
6162
6392
  await refreshMcpMeta();
6163
6393
  return send(res, 200, refreshed);
6164
6394
  }
@@ -6883,7 +7113,7 @@ async function startHolding(options, data, checked, stops) {
6883
7113
  names = loopbackNames(host, options.allowHosts, options.publicUrl);
6884
7114
  // An address of every interface is reached on this machine at its loopback one.
6885
7115
  const url = urlOf(server, host);
6886
- owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port));
7116
+ owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port, { container: () => containerSigns() !== undefined }));
6887
7117
  webhooks.attach(options.publicUrl ?? url);
6888
7118
  slack.attach(options.publicUrl ?? url);
6889
7119
  // A local install is the one server an MCP server's URL may be on loopback for (anywhere else, loopback is this machine's
@@ -7209,8 +7439,9 @@ async function startHolding(options, data, checked, stops) {
7209
7439
  closing = true;
7210
7440
  stopping.abort();
7211
7441
  clearInterval(localSourceTimer);
7212
- // Cancel a pending ChatGPT callback without signing out or changing the saved credential (not waited for).
7213
- void plan.close();
7442
+ // Cancel a pending ChatGPT callback without signing out or changing the saved credential. One past its code's
7443
+ // exchange is waited for a short while (planClosed), so its row lands before the store closes.
7444
+ const planStopped = planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS);
7214
7445
  // The CLI's sign-in still waiting for its browser ends with the server, which forgets it: left running, its CLI would
7215
7446
  // keep the browser's callback port from the next server's sign-in. Awaited until its process is gone.
7216
7447
  const signInStopped = claudeSignIns.close();
@@ -7235,6 +7466,7 @@ async function startHolding(options, data, checked, stops) {
7235
7466
  await schemaSealed;
7236
7467
  await installStopped;
7237
7468
  await signInStopped;
7469
+ await planStopped;
7238
7470
  await observationStopped;
7239
7471
  await localSourceSweep;
7240
7472
  // The ends' follower stops before the webhooks it feeds and the store it reads.