@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.57

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 (275) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +201 -52
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +17 -5
  11. package/dist/api-only.js +34 -8
  12. package/dist/browser-hold.d.ts +23 -0
  13. package/dist/browser-hold.js +48 -0
  14. package/dist/browser-person.d.ts +3 -0
  15. package/dist/browser-person.js +4 -1
  16. package/dist/chatgpt-plan.d.ts +18 -8
  17. package/dist/chatgpt-plan.js +91 -34
  18. package/dist/claude-login.d.ts +74 -16
  19. package/dist/claude-login.js +215 -56
  20. package/dist/claude-sign-in.d.ts +17 -6
  21. package/dist/claude-sign-in.js +42 -39
  22. package/dist/cli.js +63 -6
  23. package/dist/composio-made.d.ts +4 -0
  24. package/dist/composio-made.js +4 -0
  25. package/dist/composio-preset.d.ts +43 -2
  26. package/dist/composio-preset.js +92 -4
  27. package/dist/computer-held-routes.d.ts +5 -4
  28. package/dist/computer-held-routes.js +29 -8
  29. package/dist/computer-held.d.ts +6 -1
  30. package/dist/computer-held.js +14 -0
  31. package/dist/computer-record.js +4 -2
  32. package/dist/computer-viewer.js +4 -1
  33. package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
  34. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  35. package/dist/console/assets/index-okP-y8PK.js +747 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/decisions.d.ts +1 -1
  38. package/dist/decisions.js +1 -1
  39. package/dist/docker-host-addresses.d.ts +22 -11
  40. package/dist/docker-host-addresses.js +38 -26
  41. package/dist/env-switch.d.ts +10 -0
  42. package/dist/env-switch.js +33 -2
  43. package/dist/errors.d.ts +1 -0
  44. package/dist/errors.js +2 -0
  45. package/dist/fal-price.d.ts +58 -20
  46. package/dist/fal-price.js +341 -82
  47. package/dist/handed-values.d.ts +43 -1
  48. package/dist/handed-values.js +119 -2
  49. package/dist/harness-archive.d.ts +13 -10
  50. package/dist/harness-archive.js +60 -34
  51. package/dist/harness-check.d.ts +3 -1
  52. package/dist/harness-check.js +25 -46
  53. package/dist/harness-keys.d.ts +73 -27
  54. package/dist/harness-keys.js +194 -61
  55. package/dist/harness-recipe-entry.d.ts +8 -7
  56. package/dist/harness-recipe-entry.js +21 -32
  57. package/dist/harness-recipe.d.ts +38 -25
  58. package/dist/harness-recipe.js +49 -36
  59. package/dist/harness-sign-in.js +12 -23
  60. package/dist/harness-table.d.ts +10 -3
  61. package/dist/harness-table.js +26 -21
  62. package/dist/harness.d.ts +1 -0
  63. package/dist/harness.js +17 -5
  64. package/dist/hosted-search.d.ts +1 -1
  65. package/dist/hosted-search.js +1 -2
  66. package/dist/import-worker.d.ts +4 -2
  67. package/dist/import-worker.js +9 -2
  68. package/dist/in-flight.d.ts +26 -0
  69. package/dist/in-flight.js +52 -0
  70. package/dist/key-refusal.d.ts +9 -4
  71. package/dist/key-refusal.js +107 -25
  72. package/dist/learn/secrets.d.ts +13 -3
  73. package/dist/learn/secrets.js +118 -17
  74. package/dist/learning-cost.d.ts +6 -3
  75. package/dist/learning-cost.js +4 -2
  76. package/dist/link-check.js +1 -1
  77. package/dist/llms.txt +1 -1
  78. package/dist/marketplace.d.ts +77 -0
  79. package/dist/marketplace.js +224 -0
  80. package/dist/mcp-api-only-origins.d.ts +30 -0
  81. package/dist/mcp-api-only-origins.js +57 -0
  82. package/dist/mcp-gateway.d.ts +7 -5
  83. package/dist/mcp-gateway.js +9 -12
  84. package/dist/mcp-secret-writes.js +5 -3
  85. package/dist/mcp-servers-store.d.ts +28 -6
  86. package/dist/mcp-servers-store.js +53 -4
  87. package/dist/media-duration.d.ts +3 -0
  88. package/dist/media-duration.js +90 -9
  89. package/dist/model-form.d.ts +5 -4
  90. package/dist/model-form.js +11 -7
  91. package/dist/model.d.ts +5 -2
  92. package/dist/model.js +9 -5
  93. package/dist/ollama-provider.d.ts +7 -1
  94. package/dist/ollama-provider.js +14 -2
  95. package/dist/openapi.js +178 -27
  96. package/dist/otel/genai.d.ts +65 -0
  97. package/dist/otel/genai.js +116 -0
  98. package/dist/otel/tracer.d.ts +55 -0
  99. package/dist/otel/tracer.js +308 -0
  100. package/dist/page.d.ts +2 -0
  101. package/dist/page.js +3 -1
  102. package/dist/paid-calls.d.ts +1 -32
  103. package/dist/paid-calls.js +4 -39
  104. package/dist/provider.d.ts +9 -0
  105. package/dist/provider.js +50 -3
  106. package/dist/redact/match.d.ts +30 -3
  107. package/dist/redact/match.js +422 -41
  108. package/dist/refusal-words.d.ts +11 -0
  109. package/dist/refusal-words.js +11 -0
  110. package/dist/run-census.d.ts +67 -0
  111. package/dist/run-census.js +240 -0
  112. package/dist/run-computer.d.ts +6 -3
  113. package/dist/run-computer.js +4 -1
  114. package/dist/run-cut.d.ts +15 -6
  115. package/dist/run-cut.js +30 -9
  116. package/dist/run-files.d.ts +3 -0
  117. package/dist/run-files.js +3 -0
  118. package/dist/run-launch.d.ts +12 -1
  119. package/dist/run-launch.js +9 -10
  120. package/dist/run-learning-served.d.ts +2 -0
  121. package/dist/run-model-key.d.ts +8 -0
  122. package/dist/run-model-key.js +31 -1
  123. package/dist/run-reads-over-store.d.ts +24 -6
  124. package/dist/run-reads-over-store.js +67 -23
  125. package/dist/run-recordings.d.ts +5 -1
  126. package/dist/run-recordings.js +39 -14
  127. package/dist/run-timeline-served.d.ts +2 -0
  128. package/dist/run-timeline-served.js +2 -2
  129. package/dist/run-usage.d.ts +1 -0
  130. package/dist/runnable.d.ts +10 -1
  131. package/dist/runnable.js +20 -8
  132. package/dist/runner/adapter-loop.d.ts +11 -0
  133. package/dist/runner/adapter-loop.js +55 -10
  134. package/dist/runner/adapter-run-spec.d.ts +45 -8
  135. package/dist/runner/adapter-run-spec.js +150 -28
  136. package/dist/runner/adapters/pi.js +25 -3
  137. package/dist/runner/beside.js +4 -3
  138. package/dist/runner/big-writes.js +1 -10
  139. package/dist/runner/claim-secrets.d.ts +18 -3
  140. package/dist/runner/claim-secrets.js +35 -6
  141. package/dist/runner/cli-run-spec.d.ts +6 -0
  142. package/dist/runner/cli-run-spec.js +82 -35
  143. package/dist/runner/computer-journal.d.ts +9 -1
  144. package/dist/runner/computer-journal.js +26 -0
  145. package/dist/runner/conformance/harness.js +1 -1
  146. package/dist/runner/feedback-round.js +3 -0
  147. package/dist/runner/harness-loops.d.ts +6 -5
  148. package/dist/runner/harness-loops.js +7 -7
  149. package/dist/runner/held.d.ts +11 -5
  150. package/dist/runner/journal-kinds.d.ts +5 -0
  151. package/dist/runner/journal-kinds.js +5 -0
  152. package/dist/runner/main.js +7 -2
  153. package/dist/runner/mcp-claim.js +30 -3
  154. package/dist/runner/mcp-run.d.ts +12 -0
  155. package/dist/runner/mcp-run.js +12 -5
  156. package/dist/runner/model-route.d.ts +17 -0
  157. package/dist/runner/model-route.js +120 -2
  158. package/dist/runner/run-child-host.d.ts +3 -0
  159. package/dist/runner/run-child-host.js +69 -28
  160. package/dist/runner/run-child.js +5 -2
  161. package/dist/runner/runner.d.ts +14 -3
  162. package/dist/runner/runner.js +129 -33
  163. package/dist/runner/store-port.d.ts +1 -1
  164. package/dist/runner/store-secrets.d.ts +6 -0
  165. package/dist/runner/store-secrets.js +49 -7
  166. package/dist/runner/subagent.js +4 -40
  167. package/dist/runner/workflow-first.d.ts +11 -4
  168. package/dist/runner/workflow-first.js +14 -8
  169. package/dist/runner/workflow-spec.js +3 -2
  170. package/dist/runs-over-store.d.ts +15 -6
  171. package/dist/runs-over-store.js +33 -21
  172. package/dist/scrub-command.d.ts +73 -0
  173. package/dist/scrub-command.js +307 -0
  174. package/dist/secret-cut.d.ts +73 -0
  175. package/dist/secret-cut.js +291 -4
  176. package/dist/secret-rules.d.ts +143 -0
  177. package/dist/secret-rules.js +2564 -0
  178. package/dist/secrets.d.ts +7 -0
  179. package/dist/secrets.js +20 -0
  180. package/dist/server-keys.d.ts +20 -0
  181. package/dist/server-keys.js +25 -6
  182. package/dist/server.d.ts +52 -11
  183. package/dist/server.js +345 -118
  184. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  185. package/dist/store/index.d.ts +1 -1
  186. package/dist/store/index.js +1 -1
  187. package/dist/store/journal/storage.js +1 -1
  188. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  189. package/dist/store/schema.d.ts +6 -0
  190. package/dist/store/schema.js +11 -1
  191. package/dist/store/seal.d.ts +6 -1
  192. package/dist/store/seal.js +5 -3
  193. package/dist/store/sqlite/run-launch.d.ts +9 -1
  194. package/dist/store/sqlite/run-launch.js +24 -13
  195. package/dist/store/sqlite/run-patch.d.ts +1 -1
  196. package/dist/store/sqlite/run-patch.js +13 -4
  197. package/dist/store/sqlite/store.js +34 -4
  198. package/dist/store/store.d.ts +43 -2
  199. package/dist/store/store.js +20 -0
  200. package/dist/store-reads/learning.d.ts +6 -3
  201. package/dist/store-reads/learning.js +22 -7
  202. package/dist/store-view.d.ts +3 -0
  203. package/dist/store-view.js +3 -3
  204. package/dist/suggestions.js +3 -2
  205. package/dist/template-eval.d.ts +20 -9
  206. package/dist/template-eval.js +115 -33
  207. package/dist/template-import.d.ts +10 -0
  208. package/dist/template-import.js +16 -7
  209. package/dist/templates.d.ts +10 -2
  210. package/dist/templates.js +28 -8
  211. package/dist/timeline/labels.d.ts +6 -4
  212. package/dist/timeline/labels.js +18 -6
  213. package/dist/timeline/timeline.d.ts +5 -0
  214. package/dist/timeline/timeline.js +14 -8
  215. package/dist/timeline/util.js +1 -1
  216. package/dist/timeline/web-calls.d.ts +26 -9
  217. package/dist/timeline/web-calls.js +124 -37
  218. package/dist/tool-gate.d.ts +42 -3
  219. package/dist/tool-gate.js +66 -5
  220. package/dist/tool-keys-store.d.ts +2 -4
  221. package/dist/tool-keys-store.js +5 -21
  222. package/dist/tool-keys.d.ts +2 -2
  223. package/dist/tool-keys.js +2 -2
  224. package/dist/tool-list.js +1 -1
  225. package/dist/tool-plane.d.ts +2 -2
  226. package/dist/tool-plane.js +35 -33
  227. package/dist/tools.js +13 -7
  228. package/dist/trigger-targets.d.ts +4 -0
  229. package/dist/trigger-targets.js +9 -2
  230. package/dist/triggers.d.ts +67 -4
  231. package/dist/triggers.js +171 -22
  232. package/dist/until.d.ts +3 -0
  233. package/dist/until.js +11 -0
  234. package/dist/web-fake.d.ts +1 -3
  235. package/dist/web-fake.js +7 -18
  236. package/dist/web-fetch.d.ts +6 -72
  237. package/dist/web-fetch.js +11 -265
  238. package/dist/web-run.d.ts +31 -0
  239. package/dist/web-run.js +90 -0
  240. package/dist/web-save.d.ts +6 -4
  241. package/dist/web-save.js +9 -12
  242. package/dist/web-search.d.ts +9 -127
  243. package/dist/web-search.js +23 -259
  244. package/dist/wires.d.ts +13 -0
  245. package/dist/wires.js +11 -0
  246. package/dist/workflow-run.d.ts +5 -4
  247. package/dist/workflow-run.js +5 -4
  248. package/dist/workspace/computer-deps.d.ts +2 -1
  249. package/dist/workspace/computer-deps.js +9 -2
  250. package/dist/workspace/computer-for-claim.d.ts +12 -1
  251. package/dist/workspace/computer-for-claim.js +77 -8
  252. package/dist/workspace/computer-kept.d.ts +3 -0
  253. package/dist/workspace/computer-kept.js +11 -2
  254. package/dist/workspace/index.d.ts +1 -1
  255. package/dist/workspace/index.js +1 -1
  256. package/dist/workspace/kind-skills.d.ts +4 -0
  257. package/dist/workspace/kind-skills.js +9 -0
  258. package/dist/workspace/synced-folder.js +3 -4
  259. package/dist/wrapped.d.ts +13 -5
  260. package/dist/wrapped.js +52 -26
  261. package/package.json +17 -11
  262. package/skills/agentrun-serve/SKILL.md +4 -0
  263. package/templates/README.md +30 -8
  264. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  265. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  266. package/dist/exa-keyless.d.ts +0 -34
  267. package/dist/exa-keyless.js +0 -118
  268. package/dist/firecrawl-keyless.d.ts +0 -41
  269. package/dist/firecrawl-keyless.js +0 -152
  270. package/dist/keyless-mcp.d.ts +0 -36
  271. package/dist/keyless-mcp.js +0 -127
  272. package/dist/text-urls.d.ts +0 -38
  273. package/dist/text-urls.js +0 -170
  274. package/dist/web-fetch-direct.d.ts +0 -119
  275. package/dist/web-fetch-direct.js +0 -190
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import { REPEAT_MS, stopOnce, stopOnSignals } from "./stop-signals.js";
14
14
  import { resetPassword } from "./owner.js";
15
15
  import { banner } from "./print.js";
16
16
  import { parseTokens } from "./api-token.js";
17
- import { API_ONLY_ENV, RUN_KEYS_ENV, switchFrom } from "./env-switch.js";
17
+ import { API_ONLY_ENV, API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV, switchFrom } from "./env-switch.js";
18
18
  import { harnessModulesOf, harnessRecipesOf } from "./harness-table.js";
19
19
  import { hookOrigin, LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV, launchHookFrom } from "./trigger-launch-hook.js";
20
20
  import { surviveClosedPipes } from "./closed-pipes.js";
@@ -32,6 +32,7 @@ installEnvProxy();
32
32
  const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--no-runner] [--harness-module MODULE ...] [--harness-recipe FILE ...] [--harness-sign-in]
33
33
  agentrun-serve reset-password [--data DIR]
34
34
  agentrun-serve validate-template DIR
35
+ agentrun-serve check-upload < BODY.json
35
36
  agentrun-serve install-harness goose|cursor [--data DIR]
36
37
  agentrun-serve install-harness --recipe FILE [--data DIR]
37
38
  agentrun-serve sign-in-harness --recipe FILE [--data DIR]
@@ -45,6 +46,7 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
45
46
  agentrun-serve runner --check --heartbeat --data DIR [--name NAME]
46
47
  agentrun-serve store-schema [--data DIR]
47
48
  agentrun-serve store-schema --build
49
+ agentrun-serve scrub RUN [--data DIR] [--json]
48
50
  agentrun-serve native discover|connect --project PATH [--runtime claude-code|codex] [--agent NAME|--profile NAME] [--url URL] [--data DIR] [--no-sync]
49
51
 
50
52
  --data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
@@ -113,8 +115,14 @@ AGENTRUN_TELEMETRY=0 (or DO_NOT_TRACK=1) turns off the anonymous usage counts (d
113
115
  version, the platform and how many runs as a range, never prompts, files or keys. Off in CI, under a test runner and under --faux too;
114
116
  AGENTRUN_TELEMETRY=debug prints each event on stderr and sends none.
115
117
 
118
+ AGENTRUN_MARKETPLACE=off stops the console listing marketplace.agentrun.ai's templates beside this server's own (the list
119
+ is read only when a page asks for it, kept 5 minutes); an https address reads that site's list instead. Under --faux it
120
+ is off unless set to an address.
121
+
116
122
  AGENTRUN_API_ONLY=1 serves the run API alone, for a server behind its caller's backend (the routes in api-only.ts; every
117
- other address is a 404, and there are no accounts).
123
+ other address is a 404, and there are no accounts). With it, AGENTRUN_API_ONLY_MCP_ORIGINS (comma-separated origins, such
124
+ as https://mcp.example.com) lets the token save a per_run MCP server at one of those origins (PUT
125
+ /v2/settings/mcp-servers/NAME); unset, that save is a 404. A loopback origin also needs AGENTRUN_MCP_ALLOW_LOOPBACK=1.
118
126
 
119
127
  AGENTRUN_LAUNCH_HOOK_URL with AGENTRUN_LAUNCH_HOOK_SECRET (a whsec_ secret): each trigger firing that would start a run
120
128
  is POSTed to that URL, signed as Standard Webhooks, and the host starts the run through the API; this server starts
@@ -149,6 +157,14 @@ nothing (no lock, no migration). The store is the server's: AGENTRUN_STORE_URL's
149
157
  once read, 1 when the store could not be read, 2 for bad arguments. --build reads no store and prints only the versions
150
158
  this build knows. A running server says the same in GET /v2/capabilities (store_schema).
151
159
 
160
+ \`agentrun-serve scrub RUN\` counts what a share of run RUN would cut, read from the data directory's store: an imported
161
+ session or a run this server ran, the server stopped or running. It reads the text a share would carry (the run's title,
162
+ result, error and review, its Timeline as served, a workflow's graph, its agent's name), each cut as the server serves it,
163
+ and counts the scrubber's cuts in it by rule and by kind, then says how many cuts a share would make and how many of them
164
+ you could restore. It prints counts only, never a value or any piece of one; --json prints the same as JSON. It writes
165
+ nothing. Exit 0 once counted, 1 when the run is withheld (its held values can't be read here: nothing is counted), 2 for
166
+ bad arguments or a run the store does not hold.
167
+
152
168
  \`agentrun-serve eval-template DIR\` runs a template package's eval cases (all, or each --case) as real runs of its agent
153
169
  and grades each run with the case's graders (templates/README.md, "Running the evals"). By default on a server of its
154
170
  own in this process, over a temp data directory removed at the end, so it never touches your server; --server URL runs
@@ -229,12 +245,12 @@ if (process.argv[2] === "install-harness") {
229
245
  const data = resolve(values.data ?? defaultData());
230
246
  try {
231
247
  const { recipe, file } = loadRecipe(values.recipe);
232
- const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "the binary's sha256 is checked" };
248
+ const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "its files are checked" };
233
249
  const { version, installed, binary, pinnedBy } = await installRecipe(recipe, file, data, { onStep: (step) => console.error(`${recipe.label}: ${said[step]}`) });
234
- const held = { recipe: "the recipe's pin", "first-seen": "the first sha256 an earlier install recorded", recorded: "its sha256 recorded now, as the first one; a later binary that differs is refused" }[pinnedBy];
250
+ const held = { recipe: "the recipe's tree pin", "first-seen": "the tree an earlier install recorded", recorded: "their tree recorded now, as the first one; a later binary or file beside it that differs is refused" }[pinnedBy];
235
251
  console.log(installed === "already"
236
- ? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned binary is there, so nothing was downloaded; held to ${held}).`
237
- : `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary held to ${held}). Check it with: ${recipeCheckLine(file, data)} --model PROVIDER/MODEL`);
252
+ ? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned files are there, so nothing was downloaded; held to ${held}).`
253
+ : `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary and every file beside it held to ${held}). Check it with: ${recipeCheckLine(file, data)} --model PROVIDER/MODEL`);
238
254
  process.exit(0);
239
255
  }
240
256
  catch (error) {
@@ -330,6 +346,39 @@ if (process.argv[2] === "check-harness") {
330
346
  console.log(`report: ${file}`);
331
347
  process.exit(report.ok ? 0 : 1);
332
348
  }
349
+ // An upload's body ({files}, as `agentrun deploy` sends POST /v2/templates/import) read from stdin and checked by the
350
+ // import's own check (template-import.ts checkUpload), storing nothing: the package's name and sha as one JSON line and
351
+ // 0, or each reason the import would refuse it, a line each, and 1; 2 when stdin is not JSON. Nothing in it runs. Stdin
352
+ // is decoded once, whole: a character split between two of its chunks reads back as itself.
353
+ if (process.argv[2] === "check-upload") {
354
+ const { checkUpload } = await import("./template-import.js");
355
+ const { ApiError } = await import("./errors.js");
356
+ parseArgs({ args: process.argv.slice(3), options: { data: { type: "string" } } });
357
+ const chunks = [];
358
+ for await (const chunk of process.stdin)
359
+ chunks.push(chunk);
360
+ let body;
361
+ try {
362
+ body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
363
+ }
364
+ catch {
365
+ console.error("agentrun-serve check-upload reads an upload's body, {files}, as JSON on stdin.");
366
+ process.exit(2);
367
+ }
368
+ try {
369
+ const { pkg } = checkUpload(typeof body === "object" && body !== null ? body.files : undefined);
370
+ console.log(JSON.stringify({ valid: true, name: pkg.name, sha: pkg.origin.sha }));
371
+ process.exit(0);
372
+ }
373
+ catch (error) {
374
+ if (!(error instanceof ApiError))
375
+ throw error;
376
+ const reasons = error.extra.fields?.map((field) => field.message) ?? [];
377
+ for (const reason of reasons.length ? reasons : [error.message])
378
+ console.error(reason);
379
+ process.exit(1);
380
+ }
381
+ }
333
382
  // A template package folder checked by the one validator the server runs on the packages it ships (templates.ts): what
334
383
  // it holds as one JSON line and 0, or each problem and 1. Nothing in the package runs.
335
384
  if (process.argv[2] === "validate-template") {
@@ -445,6 +494,10 @@ if (process.argv[2] === "store-schema") {
445
494
  const { storeSchemaMain } = await import("./store/store-schema.js");
446
495
  process.exit(await storeSchemaMain(process.argv.slice(3), defaultData(), USAGE));
447
496
  }
497
+ if (process.argv[2] === "scrub") {
498
+ const { scrubMain } = await import("./scrub-command.js");
499
+ process.exit(await scrubMain(process.argv.slice(3), commandUsage));
500
+ }
448
501
  if (process.argv[2] === "import") {
449
502
  const { importCommand } = await import("./import.js");
450
503
  process.exit(await importCommand(process.argv.slice(3), USAGE));
@@ -539,11 +592,14 @@ process.on("SIGINT", signalled);
539
592
  process.on("SIGTERM", signalled);
540
593
  // AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
541
594
  // AGENTRUN_RUN_KEYS=1: each run brings the tool keys this server does not hold (run-keys.ts), read the same way.
595
+ // AGENTRUN_API_ONLY_MCP_ORIGINS: the MCP origins its token may save a per_run server at (api-only.ts), read with it alone.
542
596
  let apiOnly;
543
597
  let runKeys;
598
+ let apiOnlyMcpOrigins;
544
599
  try {
545
600
  apiOnly = switchFrom(API_ONLY_ENV);
546
601
  runKeys = switchFrom(RUN_KEYS_ENV);
602
+ apiOnlyMcpOrigins = apiOnly ? apiOnlyMcpOriginsFrom(process.env[API_ONLY_MCP_ORIGINS_ENV]) : [];
547
603
  }
548
604
  catch (error) {
549
605
  console.error(`${error.message}\n\n${USAGE}`);
@@ -602,6 +658,7 @@ try {
602
658
  // The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
603
659
  ...(publicUrl ? { publicUrl } : {}),
604
660
  ...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}), ...(launchHook ? { launchHook } : {}), ...(runKeys ? { runKeys } : {}),
661
+ ...(apiOnlyMcpOrigins.length ? { apiOnlyMcpOrigins } : {}),
605
662
  // The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
606
663
  ...(trustedProxies.length ? { trustedProxies } : {}),
607
664
  // A local install only as its operator says, never inferred: an MCP server on loopback is refused without it.
@@ -40,6 +40,10 @@ export type Thing = {
40
40
  };
41
41
  /** The store.settings key a server's record lives under. */
42
42
  export declare const composioMadeKey: (name: string) => string;
43
+ /** The store.settings key a server's account, as its last refresh read it at Composio, lives under: `{of, user, toolkit,
44
+ * auth_config, state, labels?, checked_at}`, bound to the server row (`of`) and to what it was read for, so a save over
45
+ * the server as another user, toolkit or auth config shows none until the next refresh. No id, no token. */
46
+ export declare const composioAccountKey: (name: string) => string;
43
47
  /** The settings value a record is stored as, bound to the server row it was written for. */
44
48
  export declare const storedMade: (made: ComposioMade, row: {
45
49
  createdAt: number;
@@ -19,6 +19,10 @@ export const COMPOSIO_KEY_ENV = "COMPOSIO_API_KEY";
19
19
  export const COMPOSIO_ORIGIN = "https://backend.composio.dev";
20
20
  /** The store.settings key a server's record lives under. */
21
21
  export const composioMadeKey = (name) => `mcp.composio/${name}`;
22
+ /** The store.settings key a server's account, as its last refresh read it at Composio, lives under: `{of, user, toolkit,
23
+ * auth_config, state, labels?, checked_at}`, bound to the server row (`of`) and to what it was read for, so a save over
24
+ * the server as another user, toolkit or auth config shows none until the next refresh. No id, no token. */
25
+ export const composioAccountKey = (name) => `mcp.composio-account/${name}`;
22
26
  /** The settings value a record is stored as, bound to the server row it was written for. */
23
27
  export const storedMade = (made, row) => ({ ...made, of: row.createdAt });
24
28
  const ID = /^[A-Za-z0-9_.-]{1,128}$/;
@@ -29,17 +29,57 @@ export type ComposioTool = {
29
29
  };
30
30
  /** A Composio call (asking): its JSON answer, or the refusal in words that name its step. */
31
31
  export type Ask = (step: string, method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, missing?: string | InputIssue) => Promise<Json>;
32
+ /** The bytes a run of calls (asking) may still read of Composio's answers, and the most it may read in all. */
33
+ type Budget = {
34
+ left: number;
35
+ readonly of: number;
36
+ };
32
37
  /** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
33
38
  * value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
34
39
  * with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
35
- * toolkit it has not, or the refusal on another field. */
36
- export declare function asking(control: ComposioControl, key: string, signal: AbortSignal | undefined, outcome?: string, sealed?: readonly string[]): Ask;
40
+ * toolkit it has not, or the refusal on another field. `budget`: the bytes its calls may read of Composio's answers, in
41
+ * all; past it, the call is refused in words. */
42
+ export declare function asking(control: ComposioControl, key: string, signal: AbortSignal | undefined, outcome?: string, sealed?: readonly string[], budget?: Budget): Ask;
37
43
  /** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
38
44
  export declare function composioTools(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
39
45
  toolkit: string;
40
46
  no_auth: boolean;
41
47
  tools: ComposioTool[];
42
48
  }>;
49
+ /** A toolkit Composio offers, as the console's toolkit picker shows it: its slug and its name. */
50
+ export type ComposioToolkit = {
51
+ slug: string;
52
+ name: string;
53
+ };
54
+ /** POST /settings/mcp-servers/composio/toolkits: the toolkits Composio offers, every page (at most MAX_TOOLKIT_PAGES and
55
+ * MAX_TOOLKIT_BYTES in all; a cursor it names a second time ends the list), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its name. Stores nothing. */
56
+ export declare function composioToolkits(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
57
+ toolkits: ComposioToolkit[];
58
+ }>;
59
+ /** Whether a saved Composio server's account is connected, as a refresh last read it at Composio: `connected`, an ACTIVE
60
+ * account under its auth config; `pending`, only one its connect link started and not yet finished; `expired`, only an
61
+ * expired one; `none`, no account (or only failed or inactive ones); `unknown`, Composio didn't answer. */
62
+ export type ComposioAccountState = "connected" | "pending" | "expired" | "none" | "unknown";
63
+ export declare const COMPOSIO_ACCOUNT_STATES: readonly ComposioAccountState[];
64
+ /** `labels`: each connected account's own label, for the owner to tell which account it is: the alias the owner gave it,
65
+ * else the name Composio shows for it (`state.val.displayName`), else the word id Composio gave it. Never its id (which
66
+ * a run's binding names), and nothing else of its state, which holds its tokens. */
67
+ export type ComposioAccount = {
68
+ state: ComposioAccountState;
69
+ labels?: string[];
70
+ };
71
+ /** `value` as a label: one line of text, cut to MAX_LABEL; none when empty or shaped as an account's id. */
72
+ export declare function accountLabel(value: unknown): string | undefined;
73
+ /** The account of a saved Composio server's user for its toolkit, under its auth config (the one its MCP server serves),
74
+ * as Composio lists it now: never one it answers as another user's (an account with no user_id, which Composio's docs
75
+ * say it will stop answering, is taken as the user asked for). `unknown`, unasked, for a user that is no one
76
+ * Composio user (empty, which Composio reads as every user). A per-run server is never asked (checkAccount, made.per_run);
77
+ * one saved before that mode for a user literally named "per_run" is that user's. */
78
+ export declare function composioAccount(ask: Ask, of: {
79
+ user: string;
80
+ toolkit: string;
81
+ auth_config: string;
82
+ }): Promise<ComposioAccount>;
43
83
  /** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
44
84
  * has none for it yet. */
45
85
  export declare function managedConfig(ask: Ask, toolkit: string): Promise<string | undefined>;
@@ -106,3 +146,4 @@ export declare function composioForget(control: ComposioControl, key: string, id
106
146
  removed: boolean;
107
147
  note: string;
108
148
  }>;
149
+ export {};
@@ -44,12 +44,34 @@ const MAX_TOOLS = 500;
44
44
  const MAX_SLUG = 128;
45
45
  const WAIT_MS = 20_000;
46
46
  const text = (value) => (typeof value === "string" ? value : "");
47
+ const OVER = Symbol("over budget");
48
+ /** `res`'s body as text: with a budget, read only while it lasts, its bytes taken from it (OVER thrown once it runs out). */
49
+ async function answerOf(res, budget) {
50
+ if (!budget)
51
+ return res.text();
52
+ const reader = res.body?.getReader();
53
+ if (!reader)
54
+ return "";
55
+ const parts = [];
56
+ for (;;) {
57
+ const { done, value } = await reader.read();
58
+ if (done)
59
+ return Buffer.concat(parts).toString("utf8");
60
+ budget.left -= value.byteLength;
61
+ if (budget.left < 0) {
62
+ await reader.cancel().catch(() => undefined);
63
+ throw OVER;
64
+ }
65
+ parts.push(value);
66
+ }
67
+ }
47
68
  const issue = (field, reason, message) => ({ field, reason, message });
48
69
  /** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
49
70
  * value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
50
71
  * with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
51
- * toolkit it has not, or the refusal on another field. */
52
- export function asking(control, key, signal, outcome = "nothing was saved", sealed = []) {
72
+ * toolkit it has not, or the refusal on another field. `budget`: the bytes its calls may read of Composio's answers, in
73
+ * all; past it, the call is refused in words. */
74
+ export function asking(control, key, signal, outcome = "nothing was saved", sealed = [], budget) {
53
75
  const base = (control.baseUrl ?? BASE).replace(/\/+$/, "");
54
76
  const send = control.fetch ?? fetch;
55
77
  // Composio's words may quote what it was sent, as sent, JSON-escaped or percent-encoded. With a sealed value in play
@@ -68,9 +90,11 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
68
90
  headers: { "x-api-key": key, accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
69
91
  ...(body === undefined ? {} : { body: JSON.stringify(body) }),
70
92
  });
71
- raw = await res.text();
93
+ raw = await answerOf(res, budget);
72
94
  }
73
- catch {
95
+ catch (error) {
96
+ if (error === OVER && budget)
97
+ throw new ApiError("upstream_failed", `Composio's answers while ${step} were over ${budget.of / (1024 * 1024)} MiB: ${outcome}.`);
74
98
  throw new ApiError("upstream_failed", `Composio did not answer while ${step}: ${outcome}.`);
75
99
  }
76
100
  let json;
@@ -170,6 +194,70 @@ const likelySlug = (slug, slugs) => {
170
194
  const want = slug.toUpperCase();
171
195
  return slugs.find((s) => s.toUpperCase() === want);
172
196
  };
197
+ /** The most pages of the toolkit list read (PAGE each): Composio offers about a thousand. */
198
+ const MAX_TOOLKIT_PAGES = 20;
199
+ /** The most bytes of its answers the toolkit list reads, every page in all: a thousand toolkits are about one MiB. */
200
+ const MAX_TOOLKIT_BYTES = 8 * 1024 * 1024;
201
+ /** POST /settings/mcp-servers/composio/toolkits: the toolkits Composio offers, every page (at most MAX_TOOLKIT_PAGES and
202
+ * MAX_TOOLKIT_BYTES in all; a cursor it names a second time ends the list), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its name. Stores nothing. */
203
+ export async function composioToolkits(body, control, signal) {
204
+ if (!isObject(body))
205
+ throw invalid([issue("body", "invalid", "The body is {api_key}.")]);
206
+ const extra = unknownFields(body, ["api_key"]);
207
+ if (extra.length)
208
+ throw invalid(extra);
209
+ const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
210
+ if (!key || key.length > 8192)
211
+ throw invalid([issue("api_key", "missing", "Send your Composio API key.")]);
212
+ const ask = asking(control, key, signal, "no toolkit was listed", [], { left: MAX_TOOLKIT_BYTES, of: MAX_TOOLKIT_BYTES });
213
+ const found = new Map();
214
+ const seen = new Set();
215
+ let cursor;
216
+ for (let page = 0; page < MAX_TOOLKIT_PAGES; page++) {
217
+ const listed = await ask("listing the toolkits", "GET", `/api/v3/toolkits?sort_by=alphabetically&limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`);
218
+ for (const item of Array.isArray(listed.items) ? listed.items : []) {
219
+ const slug = isObject(item) ? text(item.slug).trim().toLowerCase() : "";
220
+ if (TOOLKIT.test(slug) && !found.has(slug))
221
+ found.set(slug, { slug, name: text(item.name).trim() || slug });
222
+ }
223
+ cursor = text(listed.next_cursor) || undefined;
224
+ if (!cursor || seen.has(cursor))
225
+ break;
226
+ seen.add(cursor);
227
+ }
228
+ return { toolkits: [...found.values()].sort((a, b) => a.name.localeCompare(b.name, "en", { sensitivity: "base" }) || a.slug.localeCompare(b.slug)) };
229
+ }
230
+ export const COMPOSIO_ACCOUNT_STATES = ["connected", "pending", "expired", "none", "unknown"];
231
+ /** The longest label kept, and the most labels. */
232
+ const MAX_LABEL = 120;
233
+ const MAX_LABELS = 10;
234
+ /** `value` as a label: one line of text, cut to MAX_LABEL; none when empty or shaped as an account's id. */
235
+ export function accountLabel(value) {
236
+ const line = typeof value === "string" ? value.replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, MAX_LABEL).trim() : "";
237
+ return line && !COMPOSIO_ACCOUNT_ID.test(line) ? line : undefined;
238
+ }
239
+ const labelOf = (account) => accountLabel(account.alias) ?? (isObject(account.state) && isObject(account.state.val) ? accountLabel(account.state.val.displayName) : undefined) ?? accountLabel(account.word_id);
240
+ /** The account of a saved Composio server's user for its toolkit, under its auth config (the one its MCP server serves),
241
+ * as Composio lists it now: never one it answers as another user's (an account with no user_id, which Composio's docs
242
+ * say it will stop answering, is taken as the user asked for). `unknown`, unasked, for a user that is no one
243
+ * Composio user (empty, which Composio reads as every user). A per-run server is never asked (checkAccount, made.per_run);
244
+ * one saved before that mode for a user literally named "per_run" is that user's. */
245
+ export async function composioAccount(ask, of) {
246
+ if (!COMPOSIO_USER_ID.test(of.user))
247
+ return { state: "unknown" };
248
+ const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(of.user)}&toolkit_slugs=${encodeURIComponent(of.toolkit)}&auth_config_ids=${encodeURIComponent(of.auth_config)}`);
249
+ const mine = (Array.isArray(listed.items) ? listed.items : []).filter((a) => isObject(a) && (!a.user_id || a.user_id === of.user) && isObject(a.auth_config) && a.auth_config.id === of.auth_config);
250
+ const active = mine.filter((a) => a.status === "ACTIVE");
251
+ if (active.length) {
252
+ const labels = [...new Set(active.map(labelOf).filter((label) => !!label))].slice(0, MAX_LABELS);
253
+ return { state: "connected", ...(labels.length ? { labels } : {}) };
254
+ }
255
+ if (mine.some((a) => a.status === "INITIATED" || a.status === "INITIALIZING"))
256
+ return { state: "pending" };
257
+ if (mine.some((a) => a.status === "EXPIRED"))
258
+ return { state: "expired" };
259
+ return { state: "none" };
260
+ }
173
261
  /** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
174
262
  * has none for it yet. */
175
263
  export async function managedConfig(ask, toolkit) {
@@ -18,10 +18,10 @@ export declare function heldField(store: HeldStore, runId: string, options?: Hel
18
18
  why?: string;
19
19
  } | undefined>;
20
20
  /** The run read's `computer` field (`{ computer }`, or nothing for a run with none): its revision's computer setting, else
21
- * the one its place says; taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
22
- * journal only while that computer is up); with `held` for a run that holds its computer for its owner. The journal is
21
+ * the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
22
+ * journal only while that computer is up) or its browser (browserHeld, one settings read while it is up); with `held` for a run that holds its computer for its owner. The journal is
23
23
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
24
- export declare function runComputerRead(store: HeldStore & Pick<Store, "agents">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
24
+ export declare function runComputerRead(store: HeldStore & Pick<Store, "agents" | "settings">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
25
25
  computer?: Record<string, unknown>;
26
26
  }>;
27
27
  /**
@@ -29,7 +29,8 @@ export declare function runComputerRead(store: HeldStore & Pick<Store, "agents">
29
29
  * - callRunComputer: the channel's answer (callComputer), the computer's own: `{ ok: true, value }` or `{ ok: false,
30
30
  * error }`. 422 for a method the protocol does not have.
31
31
  * - startRun, releaseRunComputer: 404 for a run that holds no computer, and for a release of one already let go; 409
32
- * computer_not_live when the hold is not where the route needs it (not up yet, already started, released).
32
+ * computer_not_live when the hold is not where the route needs it (not up yet, already started, released). A start of a
33
+ * run whose model kept it from running at its create: 409 agent_not_runnable, in its create's words (hold.refused).
33
34
  * Either: 503 when the runner took no row in time.
34
35
  */
35
36
  export declare function heldRoute(name: string, runId: string, body: unknown, store: HeldStore, options?: HeldOptions): Promise<unknown>;
@@ -9,14 +9,16 @@
9
9
  //
10
10
  // They are the owner's: the server's token or the owner's session. A run never holds the server's token (runner/main.ts
11
11
  // RUNNER_ONLY), so no run's agent reaches its own computer this way: it drives it through its tools.
12
+ import { browserHeld } from "./browser-hold.js";
12
13
  import { callComputer, callIssues, sendRow, TAKE_MS } from "./computer-channel.js";
13
14
  import { computerHoldOf, entriesOf, runOver } from "./computer-commands.js";
14
- import { COMPUTER_RELEASE, COMPUTER_START, heldIn, holdIssues } from "./computer-held.js";
15
+ import { COMPUTER_RELEASE, COMPUTER_START, heldIn, heldRefused, holdIssues } from "./computer-held.js";
15
16
  import { settingOfDefinition } from "./computer-setting.js";
16
17
  import { ApiError, invalid } from "./errors.js";
17
18
  import { runComputerField } from "./run-computer.js";
18
19
  import { readLaunchBody } from "./run-launch.js";
19
20
  import { unknownFields } from "./validate.js";
21
+ import { readKept } from "./workspace/computer-kept.js";
20
22
  export { holdIssues };
21
23
  /** The routes' names in serve's route table. */
22
24
  export const HELD_ROUTES = new Set(["startRun", "callRunComputer", "releaseRunComputer"]);
@@ -37,9 +39,17 @@ export async function heldField(store, runId, options = {}) {
37
39
  const state = read.state !== "released" && (await runOver(store, runId)) ? "released" : read.state;
38
40
  return { state, minutes: read.minutes, ...(state === "released" ? {} : { until: new Date(read.until).toISOString() }), ...(read.why ? { why: read.why } : {}) };
39
41
  }
42
+ /** Whether parked run `runId`'s computer of `kind` was let go: a park's claim releases it but for a desktop, a phone or a
43
+ * sandbox kept for the resume, until its keep's time (workspace/computer-kept.ts). A browser's is said on its own read. */
44
+ async function releasedAtPark(store, runId, kind, now) {
45
+ if (kind === "browser")
46
+ return false;
47
+ const kept = await readKept(store.settings, runId).catch(() => undefined);
48
+ return !kept || kept.kind !== kind || kept.ended === true || kept.ending === true || now >= kept.until;
49
+ }
40
50
  /** The run read's `computer` field (`{ computer }`, or nothing for a run with none): its revision's computer setting, else
41
- * the one its place says; taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
42
- * journal only while that computer is up); with `held` for a run that holds its computer for its owner. The journal is
51
+ * the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
52
+ * journal only while that computer is up) or its browser (browserHeld, one settings read while it is up); with `held` for a run that holds its computer for its owner. The journal is
43
53
  * read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
44
54
  export async function runComputerRead(store, runId, view, options = {}) {
45
55
  const run = await store.runs.get(runId);
@@ -47,14 +57,19 @@ export async function runComputerRead(store, runId, view, options = {}) {
47
57
  if (!setting)
48
58
  return {};
49
59
  const error = view.error;
50
- const read = { id: runId, status: String(view.status), ...(error && typeof error.code === "string" ? { error: { code: error.code, message: String(error.message ?? "") } } : {}) };
60
+ // A stop lets the run's computer go (the run's row is final until a follow-up queues it again); a park keeps a desktop,
61
+ // a phone or a sandbox only for its keep's time.
62
+ const released = run?.state === "stopped" || (run?.state === "parked" && (await releasedAtPark(store, runId, setting.kind, options.now?.() ?? Date.now())));
63
+ const read = { id: runId, status: String(view.status), ...(error && typeof error.code === "string" ? { error: { code: error.code, message: String(error.message ?? "") } } : {}), ...(released ? { released } : {}) };
51
64
  // The run's journal, read at most once for the whole field (the hold and `held` both read it), and only when one needs
52
65
  // it: a long run's every poll would pay for a read that grows with it.
53
66
  let journal;
54
67
  const once = { ...options, entries: () => (journal ??= entriesOf(store, runId, options)) };
55
- // Who drives: only a desktop or a phone is taken over (a sandbox or a browser never is here), and only while it is up.
68
+ // Who drives, only while the computer is up: a desktop's or a phone's hold from the run's journal; a browser's from the
69
+ // one row its live view's take keeps (browser-hold.ts); a sandbox is never taken over.
56
70
  const takeable = setting.kind === "desktop" || setting.kind === "phone";
57
- const hold = takeable && runComputerField(setting, read)?.state === "ready" ? await computerHoldOf(store, runId, once) : "agent";
71
+ const up = runComputerField(setting, read)?.state === "ready";
72
+ const hold = !up ? "agent" : takeable ? await computerHoldOf(store, runId, once) : setting.kind === "browser" && (await browserHeld(store.settings, runId)) ? "person" : "agent";
58
73
  const field = runComputerField(setting, read, (_, state) => (hold === "person" ? "taken_over" : state));
59
74
  if (!field)
60
75
  return {};
@@ -73,7 +88,8 @@ function fieldsOf(body) {
73
88
  * - callRunComputer: the channel's answer (callComputer), the computer's own: `{ ok: true, value }` or `{ ok: false,
74
89
  * error }`. 422 for a method the protocol does not have.
75
90
  * - startRun, releaseRunComputer: 404 for a run that holds no computer, and for a release of one already let go; 409
76
- * computer_not_live when the hold is not where the route needs it (not up yet, already started, released).
91
+ * computer_not_live when the hold is not where the route needs it (not up yet, already started, released). A start of a
92
+ * run whose model kept it from running at its create: 409 agent_not_runnable, in its create's words (hold.refused).
77
93
  * Either: 503 when the runner took no row in time.
78
94
  */
79
95
  export async function heldRoute(name, runId, body, store, options = {}) {
@@ -87,8 +103,13 @@ export async function heldRoute(name, runId, body, store, options = {}) {
87
103
  const issues = unknownFields(fields, []);
88
104
  if (issues.length)
89
105
  throw invalid(issues);
90
- if (!(await holdOfRun(store, runId)))
106
+ const hold = await holdOfRun(store, runId);
107
+ if (!hold)
91
108
  throw new ApiError("not_found", `run ${runId} holds no computer: a run started with hold: true holds one`);
109
+ // Its model kept it from running at its create: its agent never starts, in the words its create would have said, and
110
+ // nothing is sent, so its computer still takes calls and its release (computer-held.ts).
111
+ if (name === "startRun" && hold.refused)
112
+ throw heldRefused(hold.refused);
92
113
  const read = heldIn(await entriesOf(store, runId, options));
93
114
  const over = await runOver(store, runId);
94
115
  if (name === "releaseRunComputer" && (over || read?.state === "released"))
@@ -1,6 +1,7 @@
1
1
  import type { JournalEntry } from "./computer-commands.js";
2
2
  import type { ComputerKind } from "./computer-setting.js";
3
- import type { InputIssue } from "./errors.js";
3
+ import { ApiError, type InputIssue } from "./errors.js";
4
+ import type { HeldRefusal } from "./run-launch.js";
4
5
  /** The journal entry kind the runner commits for each change of the hold. */
5
6
  export declare const HELD_KIND = "computer.held";
6
7
  /** The command row kinds the server writes. */
@@ -21,6 +22,10 @@ export declare function holdIssues(body: Record<string, unknown>): InputIssue[];
21
22
  export declare function holdOf(body: Record<string, unknown>, kind: ComputerKind): {
22
23
  minutes: number;
23
24
  } | InputIssue | undefined;
25
+ /** The refusal of a held run whose model kept it from running when it was created (run-launch.ts hold.refused), for its
26
+ * start and every message: 409 agent_not_runnable, in the words, fields and details its create would have answered.
27
+ * Read from its launch, never checked again: a key saved since runs a new run, never this one. */
28
+ export declare const heldRefused: (refused: HeldRefusal) => ApiError;
24
29
  /** Where a held computer is. */
25
30
  export type HeldState = "waiting" | "started" | "ended" | "released";
26
31
  export declare const HELD_STATES: readonly HeldState[];
@@ -9,6 +9,15 @@
9
9
  // the run keeps its computer until the release or the lapse, then ends stopped. A cancel ends the run and lets the
10
10
  // computer go at once.
11
11
  //
12
+ // A held run's create does not refuse it for its model (no key for it here, its harness refusing it or lacking only a
13
+ // model key here, no price under a cap): a benchmark that only calls the computer and lets it go never needs one. Those words ride its launch (hold.refused),
14
+ // and its start and every message are refused in them (heldRefused), so its agent never runs; its computer still takes
15
+ // calls until the release or the lapse. On pi and on every CLI harness, its model's route chooses no model and reads no
16
+ // key: its provider is a stand-in that refuses every model request in those words, sending none (provider.ts
17
+ // heldRefusedProvider), so a host with no key for it holds the computer all the same. Its claim lays only the keys any
18
+ // claim of the run lays (its tools', a key handed with it), in a run's own process too (run-child-host.ts: no model key,
19
+ // no saved gateway key), routes no subagent tier and takes no learning step. Every other blocker still refuses the create.
20
+ //
12
21
  // Like the take-over (computer-commands.ts), it runs over the one store: the server writes command rows, the run's
13
22
  // runner applies them to the computer it holds (runner/held-run.ts), and commits what came of each to the run's journal.
14
23
  // The server reads the journal, never anything in its own memory.
@@ -20,6 +29,7 @@
20
29
  // computer.call (the channel's, computer-channel.ts): each owner call starts the hold's `minutes` again from its `at`.
21
30
  // The rows: computer_start `{}`, computer_release `{}`.
22
31
  import { CALL_KIND } from "./computer-channel.js";
32
+ import { ApiError } from "./errors.js";
23
33
  /** The journal entry kind the runner commits for each change of the hold. */
24
34
  export const HELD_KIND = "computer.held";
25
35
  /** The command row kinds the server writes. */
@@ -58,6 +68,10 @@ export function holdOf(body, kind) {
58
68
  }
59
69
  return { minutes: typeof body.hold_minutes === "number" ? body.hold_minutes : HOLD_MINUTES };
60
70
  }
71
+ /** The refusal of a held run whose model kept it from running when it was created (run-launch.ts hold.refused), for its
72
+ * start and every message: 409 agent_not_runnable, in the words, fields and details its create would have answered.
73
+ * Read from its launch, never checked again: a key saved since runs a new run, never this one. */
74
+ export const heldRefused = (refused) => new ApiError("agent_not_runnable", refused.message, { fields: [...refused.fields], details: { ...refused.details } });
61
75
  export const HELD_STATES = ["waiting", "started", "ended", "released"];
62
76
  const dataOf = (entry) => (entry.data && typeof entry.data === "object" ? entry.data : {});
63
77
  /** The run's hold, from its journal: undefined until its computer first came up held. */
@@ -71,7 +71,8 @@ const fitted = (width, height, edge) => {
71
71
  return [even(width), even(height)];
72
72
  };
73
73
  /** ffmpeg's arguments for one file: `format` frames piped in, each stamped as it is read (in ms), fitted into
74
- * width x height, H.264 at the frames' own times, a key frame every 2 s at most apart, fragmented MP4. The file is on disk
74
+ * width x height, H.264 at the frames' own times, a key frame every 2 s at most apart, fragmented MP4 whose header says
75
+ * when it started (its mvhd's creation time, which run-recordings.ts orders a run's computers by). The file is on disk
75
76
  * as it goes, a fragment at each key frame (run-recordings.ts reads it mid-run): the input is not probed (a quiet screen's
76
77
  * few frames would never fill ffmpeg's 5 MB probe), it is decoded on one thread (the PNG decoder's frame threads hold one
77
78
  * frame per core back), and each fragment is flushed as it is written. */
@@ -80,7 +81,8 @@ const argsOf = (format, width, height, path) => [
80
81
  "-probesize", "32", "-analyzeduration", "0", "-fpsprobesize", "0", "-threads", "1", "-use_wallclock_as_timestamps", "1", "-framerate", "1000", "-f", "image2pipe", "-c:v", format === "png" ? "png" : "mjpeg", "-i", "pipe:0",
81
82
  "-an", "-vf", `scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2,format=yuv420p`,
82
83
  "-fps_mode", "vfr", "-c:v", "libx264", "-preset", "veryfast", "-tune", "zerolatency", "-crf", "28",
83
- "-force_key_frames", "expr:gte(t,n_forced*2)", "-movflags", "+frag_keyframe+empty_moov+default_base_moof", "-flush_packets", "1", "-f", "mp4", "-n", path,
84
+ "-force_key_frames", "expr:gte(t,n_forced*2)", "-movflags", "+frag_keyframe+empty_moov+default_base_moof", "-flush_packets", "1",
85
+ "-metadata", `creation_time=${new Date().toISOString()}`, "-f", "mp4", "-n", path,
84
86
  ];
85
87
  /** A length in words: "2 h", "90 min", "45 s". */
86
88
  const lengthWords = (ms) => (ms >= 3_600_000 && ms % 3_600_000 === 0 ? `${ms / 3_600_000} h` : ms >= 60_000 && ms % 60_000 === 0 ? `${ms / 60_000} min` : `${Math.round(ms / 1000)} s`);
@@ -179,7 +179,8 @@ const js = `"use strict";
179
179
  ready = true; kind = m.kind; input = m.input; holding = m.held === true;
180
180
  $("phone").hidden = kind !== "phone";
181
181
  document.body.dataset.kind = kind;
182
- showHands(); setDrive(m.drive); say(""); focusScreen();
182
+ // Focus comes in only for a person who holds the computer: the page that frames the viewer keeps its own otherwise.
183
+ showHands(); setDrive(m.drive); say(""); if (holding) focusScreen();
183
184
  }
184
185
  else if (m.type === "hold") {
185
186
  holding = m.held === true;
@@ -273,6 +274,8 @@ const js = `"use strict";
273
274
  var justComposed = null;
274
275
  function onKeyDown(e) {
275
276
  justComposed = null;
277
+ // Tab is the computer's only while the person holds it; else it moves the focus on, out of the viewer.
278
+ if (e.key === "Tab" && !holding) return;
276
279
  if (e.isComposing || e.keyCode === 229 || e.key === "Dead") return;
277
280
  if ((e.ctrlKey || e.metaKey) && (e.key === "v" || e.key === "V")) return;
278
281
  e.preventDefault();