@parcha/agentrun-serve 0.1.0-beta.61 → 0.1.0-beta.63

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 (228) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +128 -20
  3. package/dist/adapters.js +4 -2
  4. package/dist/agent-delete.d.ts +3 -3
  5. package/dist/agent-delete.js +50 -4
  6. package/dist/api-only.d.ts +4 -0
  7. package/dist/api-only.js +5 -1
  8. package/dist/archil-settings.d.ts +9 -0
  9. package/dist/archil-settings.js +8 -1
  10. package/dist/bash-read-only.d.ts +3 -0
  11. package/dist/bash-read-only.js +6 -3
  12. package/dist/chatgpt-plan.d.ts +33 -8
  13. package/dist/chatgpt-plan.js +141 -24
  14. package/dist/claude-login.d.ts +12 -5
  15. package/dist/claude-login.js +28 -3
  16. package/dist/cli.js +19 -8
  17. package/dist/composio-triggers.d.ts +9 -3
  18. package/dist/computers.d.ts +3 -0
  19. package/dist/computers.js +2 -1
  20. package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
  21. package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
  22. package/dist/console/assets/share-CjBJ_rxP.js +6 -0
  23. package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/cut-pool.d.ts +14 -0
  27. package/dist/cut-pool.js +98 -0
  28. package/dist/cut-worker.d.ts +14 -0
  29. package/dist/cut-worker.js +16 -0
  30. package/dist/decisions.d.ts +4 -0
  31. package/dist/decisions.js +9 -1
  32. package/dist/env-switch.d.ts +3 -0
  33. package/dist/env-switch.js +3 -0
  34. package/dist/harness-opencode/adapter.d.ts +3 -1
  35. package/dist/harness-opencode/adapter.js +6 -2
  36. package/dist/harness-opencode/harness.d.ts +4 -0
  37. package/dist/harness-opencode/harness.js +6 -1
  38. package/dist/harness-table.d.ts +7 -0
  39. package/dist/harness-table.js +6 -3
  40. package/dist/host-tools.d.ts +18 -3
  41. package/dist/host-tools.js +27 -4
  42. package/dist/import.d.ts +8 -1
  43. package/dist/import.js +36 -5
  44. package/dist/key-check.js +22 -8
  45. package/dist/learn/ledger.d.ts +37 -16
  46. package/dist/learn/ledger.js +56 -24
  47. package/dist/learn/promote.d.ts +4 -1
  48. package/dist/learned-nodes.d.ts +2 -1
  49. package/dist/learned-nodes.js +2 -1
  50. package/dist/learning-cost.d.ts +5 -3
  51. package/dist/learning-model.js +7 -5
  52. package/dist/learning-work.d.ts +69 -0
  53. package/dist/learning-work.js +148 -0
  54. package/dist/mcp-gateway.d.ts +24 -0
  55. package/dist/mcp-gateway.js +97 -8
  56. package/dist/mcp-servers-store.d.ts +7 -10
  57. package/dist/mcp-servers-store.js +15 -9
  58. package/dist/native/cli.js +5 -1
  59. package/dist/ollama-provider.d.ts +10 -3
  60. package/dist/ollama-provider.js +17 -7
  61. package/dist/openapi.js +51 -20
  62. package/dist/otel/tracer.d.ts +6 -3
  63. package/dist/otel/tracer.js +24 -6
  64. package/dist/page.d.ts +7 -0
  65. package/dist/page.js +17 -4
  66. package/dist/place.d.ts +25 -9
  67. package/dist/place.js +37 -11
  68. package/dist/print.d.ts +3 -2
  69. package/dist/print.js +8 -6
  70. package/dist/run-export.js +7 -4
  71. package/dist/run-launch.d.ts +6 -1
  72. package/dist/run-launch.js +26 -6
  73. package/dist/run-model-key.d.ts +2 -1
  74. package/dist/run-model-key.js +2 -1
  75. package/dist/run-reads-over-store.d.ts +7 -0
  76. package/dist/run-reads-over-store.js +32 -4
  77. package/dist/run-view.js +9 -3
  78. package/dist/runnable.d.ts +6 -3
  79. package/dist/runnable.js +21 -11
  80. package/dist/runner/adapter-loop.js +95 -28
  81. package/dist/runner/adapter-run-spec.d.ts +20 -4
  82. package/dist/runner/adapter-run-spec.js +64 -30
  83. package/dist/runner/adapters/index.d.ts +6 -0
  84. package/dist/runner/adapters/index.js +5 -1
  85. package/dist/runner/adapters/pi.d.ts +42 -3
  86. package/dist/runner/adapters/pi.js +114 -13
  87. package/dist/runner/audit.d.ts +8 -2
  88. package/dist/runner/audit.js +34 -18
  89. package/dist/runner/book-cut.d.ts +6 -0
  90. package/dist/runner/book-cut.js +38 -0
  91. package/dist/runner/claim-secrets.d.ts +12 -5
  92. package/dist/runner/claim-secrets.js +28 -12
  93. package/dist/runner/cli-run-spec.d.ts +0 -2
  94. package/dist/runner/cli-run-spec.js +54 -25
  95. package/dist/runner/dispatch.js +2 -0
  96. package/dist/runner/harness-loops.d.ts +5 -0
  97. package/dist/runner/harness-loops.js +4 -1
  98. package/dist/runner/held.d.ts +6 -3
  99. package/dist/runner/learned-first.d.ts +5 -0
  100. package/dist/runner/learned-first.js +1 -1
  101. package/dist/runner/learning-end.d.ts +15 -8
  102. package/dist/runner/learning-end.js +23 -7
  103. package/dist/runner/live-ticker.js +3 -1
  104. package/dist/runner/loop-contract.d.ts +8 -1
  105. package/dist/runner/main.js +2 -0
  106. package/dist/runner/mcp-run.d.ts +5 -0
  107. package/dist/runner/mcp-run.js +18 -0
  108. package/dist/runner/meta-tools.js +4 -4
  109. package/dist/runner/metrics.d.ts +4 -2
  110. package/dist/runner/metrics.js +5 -3
  111. package/dist/runner/model-route.d.ts +4 -0
  112. package/dist/runner/model-route.js +1 -1
  113. package/dist/runner/native-loop.js +2 -2
  114. package/dist/runner/pr-checkout.d.ts +12 -0
  115. package/dist/runner/pr-checkout.js +21 -2
  116. package/dist/runner/promotion.d.ts +9 -2
  117. package/dist/runner/promotion.js +79 -28
  118. package/dist/runner/reflect-hook.d.ts +7 -0
  119. package/dist/runner/reflect-hook.js +2 -1
  120. package/dist/runner/run-child-host.d.ts +10 -6
  121. package/dist/runner/run-child-host.js +65 -41
  122. package/dist/runner/run-child.js +2 -0
  123. package/dist/runner/runner.d.ts +9 -0
  124. package/dist/runner/runner.js +158 -25
  125. package/dist/runner/store-port.d.ts +4 -1
  126. package/dist/runner/workflow-calls.d.ts +4 -3
  127. package/dist/runner/workflow-calls.js +41 -12
  128. package/dist/runner/workflow-first.js +4 -3
  129. package/dist/runner/workflow-loop.js +13 -1
  130. package/dist/runner/workflow-spec.js +1 -1
  131. package/dist/secret-cut.d.ts +4 -0
  132. package/dist/secret-cut.js +1 -1
  133. package/dist/secret-rules.d.ts +2 -1
  134. package/dist/secret-rules.js +88 -24
  135. package/dist/server.d.ts +10 -1
  136. package/dist/server.js +131 -44
  137. package/dist/share-host.d.ts +111 -0
  138. package/dist/share-host.js +669 -0
  139. package/dist/store/schema.d.ts +4 -3
  140. package/dist/store/schema.js +4 -3
  141. package/dist/store/seal.d.ts +8 -2
  142. package/dist/store/seal.js +13 -2
  143. package/dist/store/sqlite/learning-rows.js +2 -1
  144. package/dist/store/sqlite/run-patch.js +4 -4
  145. package/dist/store/sqlite/store.js +28 -4
  146. package/dist/store/store.d.ts +5 -0
  147. package/dist/store-reads/analytics.d.ts +15 -0
  148. package/dist/store-reads/analytics.js +17 -0
  149. package/dist/store-reads/journal.d.ts +2 -0
  150. package/dist/store-reads/journal.js +1 -1
  151. package/dist/store-reads/learning.d.ts +4 -3
  152. package/dist/store-reads/learning.js +62 -18
  153. package/dist/store-view.d.ts +3 -0
  154. package/dist/store-view.js +18 -1
  155. package/dist/suggestions.js +32 -3
  156. package/dist/templates.d.ts +3 -1
  157. package/dist/templates.js +7 -3
  158. package/dist/tool-gate.d.ts +25 -9
  159. package/dist/tool-gate.js +58 -19
  160. package/dist/tool-list.d.ts +4 -0
  161. package/dist/tool-list.js +4 -0
  162. package/dist/tool-plane.d.ts +1 -0
  163. package/dist/tool-plane.js +6 -2
  164. package/dist/tools.js +2 -2
  165. package/dist/trigger-composio.js +1 -1
  166. package/dist/webhooks.d.ts +3 -0
  167. package/dist/webhooks.js +5 -0
  168. package/dist/workspace/archil-claim.d.ts +7 -3
  169. package/dist/workspace/archil-claim.js +13 -5
  170. package/dist/workspace/archil-mount-credential.d.ts +6 -0
  171. package/dist/workspace/archil-mount-credential.js +11 -0
  172. package/dist/workspace/attach.js +22 -5
  173. package/dist/workspace/computer-deps.d.ts +5 -3
  174. package/dist/workspace/computer-deps.js +11 -9
  175. package/dist/workspace/computer-for-claim.d.ts +6 -2
  176. package/dist/workspace/computer-for-claim.js +43 -12
  177. package/dist/workspace/computer-janitor.d.ts +7 -4
  178. package/dist/workspace/computer-janitor.js +7 -4
  179. package/dist/workspace/computer-kept.d.ts +7 -1
  180. package/dist/workspace/computer-kept.js +7 -1
  181. package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
  182. package/dist/workspace/mount-revoke-left.d.ts +16 -4
  183. package/dist/workspace/mount-revoke-left.js +42 -22
  184. package/dist/workspace/resolve-computer.d.ts +11 -5
  185. package/dist/workspace/resolve-computer.js +22 -13
  186. package/dist/workspace/run-end-computers.js +1 -1
  187. package/dist/workspace/run-tools.d.ts +10 -3
  188. package/dist/workspace/run-tools.js +5 -4
  189. package/dist/wrapped.d.ts +29 -2
  190. package/dist/wrapped.js +20 -3
  191. package/launcher/agentrun-serve +1 -1
  192. package/package.json +12 -12
  193. package/templates/kyb/agent.md +7 -1
  194. package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
  195. package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
  196. package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
  197. package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
  198. package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
  199. package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
  200. package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
  201. package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
  202. package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
  203. package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
  204. package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
  205. package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
  206. package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
  207. package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
  208. package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
  209. package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
  210. package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
  211. package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
  212. package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
  213. package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
  214. package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
  215. package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
  216. package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
  217. package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
  218. package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
  219. package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
  220. package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
  221. package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
  222. package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
  223. package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
  224. package/templates/kyb/kyb.schema.json +2 -2
  225. package/templates/kyb/rules/SANCTIONS.md +82 -13
  226. package/dist/console/assets/index-BnZV3lvW.js +0 -639
  227. package/dist/console/assets/share-B1o5mJ56.js +0 -6
  228. /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
package/dist/server.js CHANGED
@@ -32,7 +32,7 @@ import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile } from
32
32
  import { createServer } from "node:http";
33
33
  import proxyaddr from "proxy-addr";
34
34
  import { apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerEdit, apiOnlyTriggerSkipped, apiOnlyTurnsOn, servedApiOnly } from "./api-only.js";
35
- import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
35
+ import { API_ONLY_ENV, API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
36
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";
@@ -110,6 +110,7 @@ import { modelKeyMisfit, modelKeyOf, modelKeyRequired, noServerKeyFor, runModelO
110
110
  import { exportReadsOverStore } from "./run-export-store.js";
111
111
  import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
112
112
  import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
113
+ import { shareHost } from "./share-host.js";
113
114
  import { triggerTargets } from "./trigger-targets.js";
114
115
  import { labelFilter, labelsIssues } from "./run-labels.js";
115
116
  import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
@@ -234,7 +235,8 @@ import { noAccount, openAccount } from "./email/account.js";
234
235
  import { emailRoute } from "./email/routes.js";
235
236
  import { addressForms, openCalendar } from "./calendar/address.js";
236
237
  import { calendarRoute } from "./calendar/routes.js";
237
- import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode, loadArchilSettings, runDiskKept, runDiskKey } from "./archil-settings.js";
238
+ import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode, loadArchilSettings, noExecRegionOf, noExecWords, runDiskKept, runDiskKey } from "./archil-settings.js";
239
+ import { learningWorkKey } from "./learning-work.js";
238
240
  import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
239
241
  import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
240
242
  import { runningComputers } from "./computers-running.js";
@@ -728,16 +730,20 @@ export function forCaller(caps, ownerSession) {
728
730
  }
729
731
  /** The capabilities document from offers already resolved, under the server's learning switch, tool settings and box
730
732
  * offers: cheap, made again after each key or tool-settings write with the offers the server holds; and `needs` as
731
- * needsOf says it for a revision that names no model (null when it runs). `runnerShell`: the sandbox-only tools a run
732
- * on the runner has a shell for here (tools.ts shellTools; bash in Mode 2), available with no box. `switched`: the two
733
- * start-time switches the server takes as options (switchedOnBy reads them from `env`, as the CLI sets them). */
734
- function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, learning_model }, toolSettings, boxes, refused = {}, runnerShell, isolation = "process", switched = switchedOnBy(env)) {
733
+ * needsOf says it for a revision that names no model (null when it runs). `runner`: where a revision that names no
734
+ * place has its shell (place.ts RunnerShell): on the runner, whose sandbox-only tools (tools.ts shellTools; bash in
735
+ * Mode 2) are available with no box; on a Mode 2 region with no serverless exec, nowhere, so they are unavailable,
736
+ * saying why, Docker answering or not. `switched`: the two start-time switches the server takes as options
737
+ * (switchedOnBy reads them from `env`, as the CLI sets them). */
738
+ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, learning_model }, toolSettings, boxes, refused = {}, runner = false, isolation = "process", switched = switchedOnBy(env)) {
739
+ const runnerShell = runner === true ? shellTools("local") : new Set();
740
+ const noBox = typeof runner === "object" ? `${noExecWords(runner.noExec)}, so a run with no computer has no shell, and the docker box can't mount Archil: give the agent a sandbox computer (a box), or leave bash out of its tools` : noBoxReason(boxes, enabledBoxes(env));
735
741
  const models = { ...modelSource(env), ready: needs === null, needs, priced };
736
742
  // Both limits apply: the cap on the count, and the memory each run reserves (host.ts).
737
743
  const memory = hostMemory();
738
744
  // The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
739
745
  const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
740
- const tools = toolsView(env, toolSettings, noBoxReason(boxes, enabledBoxes(env)), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
746
+ const tools = toolsView(env, toolSettings, noBox, refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
741
747
  const browser = tools.find((tool) => tool.name === "browser");
742
748
  return {
743
749
  backend: "local",
@@ -757,7 +763,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
757
763
  harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
758
764
  /** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
759
765
  * and whether this server has each box. */
760
- places: placesOf(boxes, boxAllowOf(env), !!runnerShell?.size),
766
+ places: placesOf(boxes, boxAllowOf(env), runner),
761
767
  models,
762
768
  learning_model,
763
769
  /** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
@@ -942,6 +948,14 @@ export async function startServe(options) {
942
948
  // API-only: no console, so no owner to sign in to it (and no setup code printed for a page that is refused).
943
949
  if (options.apiOnly)
944
950
  options = { ...options, accounts: false, openSetup: false };
951
+ // The share host: no console, owner or runner either, and its share URLs on its public address alone.
952
+ if (options.shareHost) {
953
+ if (options.apiOnly)
954
+ throw new Error(`a server is a share host (--share-host) or API-only (${API_ONLY_ENV}=1), not both`);
955
+ if (!options.publicUrl && !isLoopback(options.host ?? DEFAULT_HOST))
956
+ throw new Error("a share host on an address other than loopback names its shares' address in AGENTRUN_PUBLIC_URL (the origin people open its /r/ links at): a request's Host header never names it");
957
+ options = { ...options, accounts: false, openSetup: false, runnerApart: true };
958
+ }
945
959
  // A harness table module is the server's to name, from `harnessTable` alone, for itself and its runs: one in its own
946
960
  // environment (an operator's export, a leftover) never loads, wherever the server reads its environment.
947
961
  delete process.env[HARNESS_TABLE_ENV];
@@ -1359,7 +1373,7 @@ async function startHolding(options, data, checked, stops) {
1359
1373
  // The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
1360
1374
  // option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
1361
1375
  const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
1362
- const compose = (runnerShell) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
1376
+ const compose = (runner = false) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runner, isolation, switched));
1363
1377
  const recompose = () => void (caps = compose());
1364
1378
  // What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
1365
1379
  let offersFrom;
@@ -1612,8 +1626,12 @@ async function startHolding(options, data, checked, stops) {
1612
1626
  for (let round = 1;; round++) {
1613
1627
  const n = await refreshOnce();
1614
1628
  const latest = () => handed.n === n && !handed.failed;
1615
- if (latest() && !offersMadeFrom(offersInputs(env)))
1629
+ // The inputs moved on with no key changed (a new Ollama listing, the login): what a revision that names no model
1630
+ // needs is made again from them first, as ollamaNow does, or the offers come back with a default it never read.
1631
+ if (latest() && !offersMadeFrom(offersInputs(env))) {
1632
+ await needsNow();
1616
1633
  await offersNow();
1634
+ }
1617
1635
  if (latest() && offersMadeFrom(offersInputs(env)))
1618
1636
  return;
1619
1637
  if (round >= LOGIN_ROUNDS)
@@ -1742,7 +1760,7 @@ async function startHolding(options, data, checked, stops) {
1742
1760
  const computersOf = () => (computerRoutes ??= createComputerRoutes({
1743
1761
  // A provider's key set where the server starts is one of its secrets, held off process.env (secrets.ts): read by name
1744
1762
  // from what the server was started with, as computerReady below reads it.
1745
- store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), env: withSecrets(process.env, "own"),
1763
+ store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), noExec: () => noExecNow(), env: withSecrets(process.env, "own"),
1746
1764
  // Each with its route (who holds it, on which runner, and why a route was refused), and online while relayed.
1747
1765
  paired: { rows: () => store.pairedComputers.list(), viewOf: async (row, serves, runsRefused) => pairedView(row, attachHub, serves, runsRefused, await readRoute(store.settings, row.id), attach.relayedTo(row.id) !== undefined) },
1748
1766
  runnerApart: options.runnerApart === true,
@@ -1769,6 +1787,9 @@ async function startHolding(options, data, checked, stops) {
1769
1787
  * provider's program is on this machine is hostWhy's, read at the start. */
1770
1788
  /** The server's folder mode now: 2 when the owner's Archil settings are saved (the run's folder on the disk), else 1. */
1771
1789
  const modeNow = async () => ((await folderModeOf(store, process.env)()) === "disk" ? 2 : 1);
1790
+ /** In Mode 2, this server's Archil region now where it has no serverless exec (archil-settings.ts noExecRegionOf), read
1791
+ * as the claim reads it (the environment's settings, else the saved ones); else undefined. */
1792
+ const noExecNow = async () => noExecRegionOf(await loadArchilSettings(store, process.env));
1772
1793
  /** The registry a run's claim resolves against (claimKinds), as its runner composes it. */
1773
1794
  const claimRegistry = () => claimKinds(options.faux ? { faux: fauxOf() } : {});
1774
1795
  /** A key as the runner reads it: the secrets this process was started with (withSecrets "own"), else the saved one. */
@@ -1785,18 +1806,39 @@ async function startHolding(options, data, checked, stops) {
1785
1806
  };
1786
1807
  /** Where a run of an agent with computer `setting` has its shell here now (resolve-computer.ts runShellOf, in the
1787
1808
  * folder mode of now, over the registry the claim reads): what runnable.ts lets a sandbox-only tool on the runner by,
1788
- * and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec. */
1789
- const shellOf = async (setting) => runShellOf(setting, await modeNow(), await registryHere(setting.provider === undefined ? claimRegistry() : withPaired(claimRegistry(), await store.pairedComputers.list()), runnerKeys()));
1809
+ * and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec, where the
1810
+ * server's Archil region has it (noExecNow). */
1811
+ const shellOf = async (setting) => runShellOf(setting, await modeNow(), await registryHere(setting.provider === undefined ? claimRegistry() : withPaired(claimRegistry(), await store.pairedComputers.list()), runnerKeys()), await noExecNow());
1812
+ /** Where a revision that names no place has a shell now, besides a box (place.ts RunnerShell): on the runner where a
1813
+ * run with no computer has one here (shellOf); else, in Mode 2 on a region with no exec, nowhere (Docker's box can't
1814
+ * mount Archil), naming the region; else (Mode 1) in Docker's box. */
1815
+ const runnerShellNow = async () => {
1816
+ if ((await shellOf({ kind: "none" })) === "local")
1817
+ return true;
1818
+ const noExec = await noExecNow();
1819
+ return noExec === undefined ? false : { noExec };
1820
+ };
1790
1821
  /** The shell this server can give a template's agent now (templates.ts pickComputer's `shell`), by the rules a run
1791
1822
  * has it by (shellOf): Archil's serverless exec on the runner in Mode 2 (bash alone); else the box a new agent is saved
1792
1823
  * with (Docker), where it answers now (computerReady asks the daemon, not the start's offers: a Docker stopped since
1793
1824
  * is no shell), whose shell runs the shell tools; else none, and why. A package that needs programs (`sandbox`) asks
1794
1825
  * for a sandbox alone, whose box a run checks for them: Archil's exec is none, so in Mode 2 it is told why no sandbox
1795
- * answers (the Docker box can't mount Archil's workspaces), never given the exec. */
1826
+ * answers (the Docker box can't mount Archil's workspaces), never given the exec. In Mode 2 on a region with no
1827
+ * serverless exec there is no exec: the first sandbox of the registry that answers here now and mounts the run's
1828
+ * folder (a vendor's, on Archil), so a template's agent has its shell and its checkout; else none, saying why and the fix. */
1796
1829
  const shellHere = async (wants = {}) => {
1797
1830
  const exec = (await shellOf({ kind: "none" })) === "local";
1798
1831
  if (exec && !wants.sandbox)
1799
1832
  return { computer: { kind: "none" }, tools: [...shellTools("local")], words: "Archil's serverless exec" };
1833
+ const noExec = exec ? undefined : await noExecNow();
1834
+ if (noExec !== undefined) {
1835
+ for (const entry of claimRegistry().PROVIDERS) {
1836
+ const computer = { kind: "sandbox", provider: entry.id };
1837
+ if ((await shellOf(computer)) === "computer" && "ok" in (await computerReady(computer)))
1838
+ return { computer, tools: [...shellTools("computer")], words: `the ${entry.id} sandbox` };
1839
+ }
1840
+ return { none: `this server has no shell to give an agent now: ${noExecWords(noExec)}, the docker box can't mount Archil, and no sandbox that mounts it is set up`, fix: "Give the agent a sandbox computer (a box) to run bash, or leave bash out of its tools." };
1841
+ }
1800
1842
  const fresh = newAgentPlace(boxOffers);
1801
1843
  let why = "why" in fresh ? fresh.why : "it is not set up";
1802
1844
  if ("place" in fresh && fresh.place.mode === "sandbox") {
@@ -1838,7 +1880,7 @@ async function startHolding(options, data, checked, stops) {
1838
1880
  /** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
1839
1881
  * job's (its compile turn is learning's), null while unknown; what learning spent for it
1840
1882
  * (`learning_usd`) and the two (`all_in_usd`), with what makes up `learning_usd` (`compile_usd`, `followup_usd`,
1841
- * `shadow_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
1883
+ * `shadow_usd`, `check_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
1842
1884
  * A cost known only as a bound keeps its bound, and all-in is unknown.
1843
1885
  * `tools_usd`: the part of `usd` its paid tool calls cost (store-view.ts toolsUsdOverStore). */
1844
1886
  const allInViewOf = async (runId, view) => {
@@ -1849,8 +1891,8 @@ async function startHolding(options, data, checked, stops) {
1849
1891
  return {};
1850
1892
  // A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
1851
1893
  // gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
1852
- const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
1853
- return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } };
1894
+ const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd } = all;
1895
+ return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd } };
1854
1896
  };
1855
1897
  // The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
1856
1898
  // the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
@@ -1916,7 +1958,10 @@ async function startHolding(options, data, checked, stops) {
1916
1958
  });
1917
1959
  // The outbound webhook's secret, as it stands (set by a PUT, gone with a DELETE), and each it held before.
1918
1960
  stops.push(() => webhooks.close());
1919
- await webhooks.load();
1961
+ // A share host sends no message: a data folder it reuses may hold a webhook, a Slack URL and messages left queued, about
1962
+ // runs it neither runs nor answers for. Its outboxes are never read, so nothing is resumed or sent; their saved secrets
1963
+ // are, so they stay held values its uploads are scrubbed with.
1964
+ await (options.shareHost ? webhooks.readSecrets() : webhooks.load());
1920
1965
  // Where an earlier version kept the webhook: no longer read.
1921
1966
  if (existsSync(join(data, WEBHOOK_FILE)))
1922
1967
  log?.(logLine("webhook", { condition: "webhook_left_over", file: join(data, WEBHOOK_FILE), effect: "not read: the webhook is kept in the store now; set it again with PUT /v2/settings/webhook" }));
@@ -1932,7 +1977,7 @@ async function startHolding(options, data, checked, stops) {
1932
1977
  serverSecrets: () => serverSecrets(),
1933
1978
  });
1934
1979
  stops.push(() => slack.close());
1935
- await slack.load();
1980
+ await (options.shareHost ? slack.readSecrets() : slack.load());
1936
1981
  secretStores.add("slack", () => slack.urlForms());
1937
1982
  const uploads = new Uploads(join(data, UPLOADS_DIR));
1938
1983
  // Under the data directory's lock and before this server answers anything, so no PUT of its own is in flight: an upload
@@ -2098,8 +2143,10 @@ async function startHolding(options, data, checked, stops) {
2098
2143
  }).finally(() => { localSourceBusy = false; });
2099
2144
  return localSourceSweep;
2100
2145
  };
2101
- const localSourceTimer = setInterval(() => void sweepLocalSources(), 30_000);
2102
- localSourceTimer.unref();
2146
+ // A share host publishes no agent's sources: a reused folder's agent with source sync on would get new revisions there,
2147
+ // and the host answers none of the routes that show or stop that sync.
2148
+ const localSourceTimer = options.shareHost ? undefined : setInterval(() => void sweepLocalSources(), 30_000);
2149
+ localSourceTimer?.unref();
2103
2150
  // As close() does: aborted first, so a sync in flight stops instead of being waited out.
2104
2151
  stops.unshift(async () => {
2105
2152
  stopping.abort();
@@ -2219,6 +2266,7 @@ async function startHolding(options, data, checked, stops) {
2219
2266
  context: ctx,
2220
2267
  sealKey,
2221
2268
  liveViewer: (runId) => liveViewerLink(store, sealKey, runId, answers(runId)),
2269
+ ...(options.cutMs !== undefined ? { cutMs: options.cutMs } : {}),
2222
2270
  };
2223
2271
  // The run timeline reader over the store (run-reads-over-store runTimelines): one change-numbered RowLog per run, synced
2224
2272
  // from its journal (store-reads) on each read, its view (viewOverStore) for status/state/cost and whether it is final.
@@ -2297,6 +2345,19 @@ async function startHolding(options, data, checked, stops) {
2297
2345
  keyUsed.set(req, key);
2298
2346
  return started || key !== undefined;
2299
2347
  };
2348
+ // The share host's routes (share-host.ts), with its own store under DIR/shares: a token's id owns each share, and the
2349
+ // values it holds (its keys, its tokens) refuse an upload that carries one.
2350
+ const shareRoute = options.shareHost ? shareHost({
2351
+ data,
2352
+ who: (req) => (bearer(req.headers.authorization, req) ? tokenUsed.get(req) : undefined),
2353
+ authFailed,
2354
+ held: () => [...serverSecrets(), ...tokens.map((entry) => entry.token)],
2355
+ // AGENTRUN_PUBLIC_URL, else (a loopback start alone, as the start checked) the address this server listens at.
2356
+ origin: () => options.publicUrl ?? urlOf(server, host),
2357
+ console: options.console,
2358
+ version: VERSION,
2359
+ ...(options.shareScrub ? { scrub: options.shareScrub } : {}),
2360
+ }) : undefined;
2300
2361
  // Answered keys are kept in the data directory for the retention capabilities state, and written before the answer
2301
2362
  // is sent, so a client that retries after a restart gets the first answer back.
2302
2363
  // A key's fingerprint is an HMAC of its request's body (stable JSON) under a key derived from the server's seal key:
@@ -2369,6 +2430,10 @@ async function startHolding(options, data, checked, stops) {
2369
2430
  // A saved key is read by name from here, past the checks that refuse a start and before any run (a recovered one too)
2370
2431
  // is launched: each launch hands over what is saved then. One server in a process reads them: the last started.
2371
2432
  await probe("start");
2433
+ // What a stop left in the ChatGPT sign-in's row (a sign-in saved, its models unlisted or the sign-in it replaced not
2434
+ // yet revoked) is settled now, out of the start's way, once the first offers are made: models it lists make them
2435
+ // again (keysChanged). The server's alone: a runner's reader never settles.
2436
+ plan.settleLeft();
2372
2437
  // Under faux, a key the server starts with is checked only against a check's own fake (fauxBrowserbase,
2373
2438
  // fauxMonidCheck, fauxKernel): the fakes the runs use (monid, Parallel, Jev) see the runs' calls alone, and a key with no check fake
2374
2439
  // is not checked.
@@ -2651,10 +2716,14 @@ async function startHolding(options, data, checked, stops) {
2651
2716
  stops.push(async () => triggers.close());
2652
2717
  // The firing loop runs against the server's own opened store: due firings start their runs through the run write half,
2653
2718
  // times missed while it was down are recorded, and the timer is armed for the next. (A test may inject its own store.)
2654
- void triggers.start().catch((error) => void process.stderr.write(`agentrun-serve: the triggers' start: ${error.message}\n`));
2655
- // The App's installations repaired from GitHub's own, once, as the server starts: events missed while it was down. It
2656
- // never rejects, and close (or a start that fails) aborts it and waits for it before it closes.
2657
- void githubConnect.reconcile((detail) => triggers.turnOff("github", detail), { force: true });
2719
+ // A share host runs none of them: a data folder it reuses may hold enabled schedules and feeds, whose runs it can
2720
+ // neither run nor answer for, and it reads no GitHub installation.
2721
+ if (!options.shareHost) {
2722
+ void triggers.start().catch((error) => void process.stderr.write(`agentrun-serve: the triggers' start: ${error.message}\n`));
2723
+ // The App's installations repaired from GitHub's own, once, as the server starts: events missed while it was down.
2724
+ // It never rejects, and close (or a start that fails) aborts it and waits for it before it closes.
2725
+ void githubConnect.reconcile((detail) => triggers.turnOff("github", detail), { force: true });
2726
+ }
2658
2727
  // Setup's import of this machine's sessions: offered by a server on this machine only (no public address, listening
2659
2728
  // on loopback), counted once (a listing, no transcript kept), run once, each on a worker thread (import-worker.ts) so
2660
2729
  // a busy store's wait and the sessions' parsing never hold up a request.
@@ -3063,13 +3132,16 @@ async function startHolding(options, data, checked, stops) {
3063
3132
  // The run's folder (its work and what sits beside it), its scratch and its native context, on this machine.
3064
3133
  for (const folder of [dirname(runFolder(data, agentId, runId)), scratchFolder(data, agentId, runId), join(data, "native-context", runId)])
3065
3134
  await rm(folder, { recursive: true, force: true });
3066
- // Its settings: an SDK run's row, its browser wait's end and take, the Archil disk it resolved to. Its kept computer's row
3067
- // (workspace/computer-kept.ts) is left to the janitor, which deletes the computer of a run no longer there and then
3068
- // the row: removed here, the computer would have nothing left to reach it.
3135
+ // Its settings: an SDK run's row, its browser wait's end and take, the Archil disk it resolved to, the learning work it
3136
+ // started (learning-work.ts: child run ids; each child keeps its own row, one still going cancelled with its sealed
3137
+ // key copy erased before this, agent-delete.ts endLearningWork).
3138
+ // Its kept computer's row (workspace/computer-kept.ts) is left to the janitor, which deletes the computer of a run no
3139
+ // longer there and then the row: removed here, the computer would have nothing left to reach it.
3069
3140
  await store.settings.remove(sdkRunKey(runId));
3070
3141
  await store.settings.remove(waitEndedKey(runId));
3071
3142
  await store.settings.remove(browserHoldKey(runId));
3072
3143
  await store.settings.remove(runDiskKey(runId));
3144
+ await store.settings.remove(learningWorkKey(runId));
3073
3145
  await forgetKept("run", runId);
3074
3146
  },
3075
3147
  forgetAgent: async (agentId) => {
@@ -3319,7 +3391,7 @@ async function startHolding(options, data, checked, stops) {
3319
3391
  if (owed.length)
3320
3392
  throw keysOwedRefusal(owed);
3321
3393
  // Claude Code's login on this machine is a runner place's alone: a sandbox run is checked for a key, as it runs.
3322
- const blockers = await blockersOf(withCarried(envAtPlace(env, shape.place), carried), shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, monid, decisionPrice: price });
3394
+ const blockers = await blockersOf(withCarried(envAtPlace(env, shape.place), carried), shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, monid, decisionPrice: price });
3323
3395
  if (!blockers.length)
3324
3396
  return;
3325
3397
  // An agent refused for its model in a box while its harness runs on the login at the runner, on a model the login
@@ -3354,8 +3426,9 @@ async function startHolding(options, data, checked, stops) {
3354
3426
  throw new ApiError("agent_not_runnable", message, { fields, details: { adapters: [...new Set(blockers.flatMap((b) => (b.adapter ? [b.adapter] : [])))], unbound, missing, code: blockers.some((b) => b.codeNodes || b.shell), ...(tier ? { tier } : {}), ...(Object.keys(decisions).length ? { decisions } : {}), ...(denied.length ? { denied } : {}), ...(asks.length ? { asks } : {}), ...named } });
3355
3427
  }
3356
3428
  /** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with, in the
3357
- * folder mode of now (Mode 2, where the runner's shell is Archil's exec: the runner, never Docker's box). */
3358
- const fallbackPlace = async (kind, tools) => defaultPlaceOf(kind, tools, boxOffers, toolOf, (await modeNow()) === 2);
3429
+ * folder mode of now (Mode 2: the runner, never Docker's box, which can't mount Archil; on a region with no exec its
3430
+ * shell tools are refused there, runnerShellNow). */
3431
+ const fallbackPlace = async (kind, tools) => defaultPlaceOf(kind, tools, boxOffers, toolOf, await runnerShellNow());
3359
3432
  /** What a save of `revision` pins of the MCP tools it grants (an agentic revision's: a workflow's nodes bind none): each
3360
3433
  * granted server listed once, now, with its saved credential (McpServersOverStore.pinListing), as `tools` each server's
3361
3434
  * listing in the harnesses' shape for the save's checks (blockersOf's `mcp`), and `pin` making the pin from them. A server
@@ -3468,14 +3541,14 @@ async function startHolding(options, data, checked, stops) {
3468
3541
  const listing = await mcpListingOf(revision, previous?.mcpPin);
3469
3542
  const mcp = listing.tools;
3470
3543
  const { monid, warnings: usage = [] } = (await monidPinOf(revision, previous)) ?? {};
3471
- const blockers = await blockersOf(envAtPlace(env, shape.place), shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, offers, mcp, monid });
3544
+ const blockers = await blockersOf(envAtPlace(env, shape.place), shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid });
3472
3545
  // An agent's default cap caps each run started without one of its own, and a web tool resolves by the cap: what a cap
3473
3546
  // alone keeps from running under the definition's own picks, whatever this host's settings, would keep every such run
3474
3547
  // from running, so the save is refused, not each run (claude-agent's or codex's own search, picked, under a cap).
3475
3548
  if ((body.maxCostUsd ?? 0) > 0) {
3476
3549
  const key = (b) => `${b.field}\n${b.message}`;
3477
- const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp, monid })).map(key));
3478
- const capped = await blockersOf(env, shape, {}, { capped: true, capUsd: body.maxCostUsd, boxes: boxOffers, computerReady, shellOf, offers, mcp, monid, decisionPrice });
3550
+ const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid })).map(key));
3551
+ const capped = await blockersOf(env, shape, {}, { capped: true, capUsd: body.maxCostUsd, boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid, decisionPrice });
3479
3552
  // A model with no price (`unpriced`) is a setting this host fixes (AGENT_MODEL_PRICE): a warning, as it is; the
3480
3553
  // agent saves and updates, and only a run under the cap is refused (409). So is a cap below what the model needs for
3481
3554
  // one more step and an answer (`short`): the agent saves, and its runs wrap up at their first tool call. A tool's
@@ -3500,14 +3573,17 @@ async function startHolding(options, data, checked, stops) {
3500
3573
  * (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
3501
3574
  * and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
3502
3575
  * runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
3503
- * noBoxRefusal). On Mode 2 it saves for the runner, as it always did. Native, CLI-learning and SDK agents run elsewhere. */
3576
+ * noBoxRefusal). On Mode 2 it saves for the runner, as it always did, except on an Archil region with no serverless
3577
+ * exec, where one that names a shell tool is refused, naming a sandbox computer, Docker answering or not
3578
+ * (runnerShellNow); one that names no tools saves on the runner with none (defaultToolsAt). Native,
3579
+ * CLI-learning and SDK agents run elsewhere. */
3504
3580
  async function noPlaceOf(revision, toolsUnnamed) {
3505
3581
  const body = revision.body;
3506
3582
  if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
3507
3583
  return undefined;
3508
3584
  if (body.place !== undefined || body.computer !== undefined)
3509
3585
  return undefined;
3510
- return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, (await shellOf({ kind: "none" })) === "local");
3586
+ return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, await runnerShellNow());
3511
3587
  }
3512
3588
  /** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
3513
3589
  * cannot be pinned refuses the save (422). Undefined when it grants none. */
@@ -3834,14 +3910,15 @@ async function startHolding(options, data, checked, stops) {
3834
3910
  // agent has by its name is left as it is, never removed. One left on still fires, so its skip says so and how to stop it.
3835
3911
  const hooked = options.launchHook !== undefined;
3836
3912
  const hostless = new Map(made.triggers.flatMap((trigger, i) => {
3837
- const skip = (options.apiOnly ? apiOnlyTriggerSkipped(pkg.name, trigger, hooked) : undefined) ?? runKeysTriggerSkipped(pkg.name, trigger, brought, hooked);
3913
+ const apiOnlySkip = options.apiOnly ? apiOnlyTriggerSkipped(pkg.name, trigger, hooked) : undefined;
3914
+ const skip = apiOnlySkip ?? runKeysTriggerSkipped(pkg.name, trigger, brought, hooked);
3838
3915
  if (!skip)
3839
3916
  return [];
3840
3917
  const keptOn = had.find((row) => row.enabled && row.name === String(trigger.name).trim());
3841
3918
  // Under the run-keys setting the kept one's firings bring no keys. One that starts a run of this revision is refused
3842
3919
  // for the keys it owes, but the kept trigger's target is not checked here: a message_run trigger whose run is pinned
3843
3920
  // to an earlier revision that owes no keys still messages it, and that run may spend. So the warning promises no refusal.
3844
- const kept = options.apiOnly
3921
+ const kept = apiOnlySkip
3845
3922
  ? `is kept as it was, and still fires: PATCH /v2/triggers/${keptOn?.id} with {"enabled": false} turns it off`
3846
3923
  : `is kept as it was and still fires until you turn it off (PATCH /v2/triggers/${keptOn?.id} with {"enabled": false}): a firing that would start a run of this revision is refused 409 for the keys it owes, but one aimed at a run of an earlier revision that owes none still reaches that run, which may spend`;
3847
3924
  return [[i, keptOn ? { ...skip, message: `${skip.message} The agent's trigger ${keptOn.id} of that name ${kept}.` } : skip]];
@@ -5031,12 +5108,13 @@ async function startHolding(options, data, checked, stops) {
5031
5108
  if (found.name === "getCapabilities") {
5032
5109
  // features.computers: the computer kinds this server offers now (computers.ts), read at each answer, since turning
5033
5110
  // Archil on or off, or saving a key, changes them. So does a shell on the runner (bash on Archil's serverless exec
5034
- // in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box.
5035
- const runnerShell = shellTools(await shellOf({ kind: "none" }));
5111
+ // in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box; and
5112
+ // so does a Mode 2 region with no exec, where there is none and Docker's box is no default (runnerShellNow).
5113
+ const runner = await runnerShellNow();
5036
5114
  await planNow();
5037
5115
  await ollamaNow();
5038
5116
  await loginNow();
5039
- const answer = forCaller(runnerShell.size ? compose(runnerShell) : caps, byOwnerSession(req));
5117
+ const answer = forCaller(runner !== false ? compose(runner) : caps, byOwnerSession(req));
5040
5118
  // features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
5041
5119
  // runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
5042
5120
  // (runner/presence.ts); null while one can, or none is there yet.
@@ -6253,7 +6331,7 @@ async function startHolding(options, data, checked, stops) {
6253
6331
  if (!read)
6254
6332
  throw new ApiError("unavailable", `This machine's session history for ${year} is still being read: ask again in a few seconds.`, { retry_after_ms: 5_000 });
6255
6333
  const analytics = await analyticsOverStore(store, { from: new Date(year, 0, 1).toISOString(), to: new Date(year + 1, 0, 1).toISOString() });
6256
- return send(res, 200, wrappedView(read.wrapped, analytics.bySource.filter((g) => g.source !== "live").map((g) => ({ source: g.source, runs: g.runs })), read.unread));
6334
+ return send(res, 200, wrappedView(read.wrapped, analytics.bySource.filter((g) => g.source !== "live").map((g) => ({ source: g.source, runs: g.runs })), read.unread, analytics.cache));
6257
6335
  }
6258
6336
  case "getStats": {
6259
6337
  const filter = analyticsFilter(url);
@@ -7100,6 +7178,10 @@ async function startHolding(options, data, checked, stops) {
7100
7178
  }
7101
7179
  // Routed on the path as sent: a parsed URL folds `..` and `%2E%2E` segments away, and a file path must see them.
7102
7180
  const raw = (req.url ?? "/").split("?")[0];
7181
+ // The share host (share-host.ts): /r/ alone, before the page, the owner's routes, the MCP endpoint, the token-less
7182
+ // hooks or the token check read anything of the request; every other address is its 404.
7183
+ if (shareRoute)
7184
+ return void shareRoute(req, res, raw).catch(fail);
7103
7185
  // API-only (api-only.ts): any address but the run routes is refused here, before the page, the owner's routes, the
7104
7186
  // MCP endpoint, the token-less hooks or the token check read anything of the request.
7105
7187
  if (options.apiOnly && !servedApiOnly(ROUTES, req.method, raw, apiOnlyMcpOrigins.length > 0))
@@ -7141,6 +7223,9 @@ async function startHolding(options, data, checked, stops) {
7141
7223
  // away. Its name alone, on any port, as the HTTP routes check it.
7142
7224
  if (names && !names.has(hostName(req.headers.host) ?? ""))
7143
7225
  return deny("403 Forbidden");
7226
+ // A share host takes no upgrade: it has no live view, computer or paired machine.
7227
+ if (options.shareHost)
7228
+ return deny("404 Not Found");
7144
7229
  // API-only: paired computers are the console's (Settings), and refused with it, whose tokens the attach socket takes as
7145
7230
  // unknown there (machinesOnly). A run's hosted machine that dials still reaches it, and a run's computer live view takes
7146
7231
  // its viewer credential (below); a browser's live view stays the console's.
@@ -7538,7 +7623,9 @@ async function startHolding(options, data, checked, stops) {
7538
7623
  if (!closing && (letGo(row) || stopRow(row)) && !(await tellWait(row).catch((error) => (sayUnread(row.id, error.message), false))))
7539
7624
  waitsLeft.add(row.id);
7540
7625
  };
7541
- followChanges();
7626
+ // Nor does a share host follow the runs' changes: it tells no one of a run's end or wait.
7627
+ if (!options.shareHost)
7628
+ followChanges();
7542
7629
  const setupUrl = owner && !owner.hasPassword() ? owner.setupLink() : undefined;
7543
7630
  /** The server's stop: once (`close` keeps its promise). */
7544
7631
  let stopped;
@@ -7627,7 +7714,7 @@ async function startHolding(options, data, checked, stops) {
7627
7714
  tokenMade: stored?.made ?? false,
7628
7715
  ...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
7629
7716
  ...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
7630
- boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), (await shellOf({ kind: "none" })) === "local"),
7717
+ boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), await runnerShellNow()),
7631
7718
  attachHub,
7632
7719
  beside,
7633
7720
  dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
@@ -0,0 +1,111 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import { type CutScrub } from "./run-export.js";
3
+ export { SHARE_HOST_CSP } from "./page.js";
4
+ /** Where everything a share host serves lives. */
5
+ export declare const SHARE_ROOT = "/r/";
6
+ /** The share host's API. */
7
+ export declare const SHARE_API = "/r/v2/";
8
+ /** The most shares one token keeps: a delete makes room. No share expires. */
9
+ export declare const SHARE_QUOTA = 100;
10
+ /** The most reads one upload's per-string scrub makes, a distinct string once per context it stands under (a file's
11
+ * path, a call's command): each is a scrub of its own (about 0.1 ms), so past it the upload is 413 before any is read.
12
+ * With the body's cap it bounds what one upload asks of the scrubber: the whole body once, and at most this many reads,
13
+ * each of a string with a place of its own in the body, so together no more than the body; each context's command is
14
+ * read once (screenShare). */
15
+ export declare const SHARE_STRINGS = 50000;
16
+ /** The rule ids of Jev's cuts (Scrubber beta 3; "jev" until its id is fixed). A share host never runs Jev (it holds no
17
+ * model key), so a restored record of one names a value the host can't find: it is not checked, and counted in the
18
+ * answer, never refused. The value itself is scrubbed as every other, and a hit there needs its own record. */
19
+ export declare const SHARE_JEV_RULES: ReadonlySet<string>;
20
+ /** The most bytes an upload's body may hold: the export's document cap, and room for nothing else. */
21
+ export declare const SHARE_BODY_BYTES: number;
22
+ /** A share's id: 128 bits of randomness in base32 (lowercase, no padding). The URL is the capability. */
23
+ export declare const SHARE_ID: RegExp;
24
+ /** The share host's API, by method, path and name. Nothing else under /r/v2/ is served. */
25
+ export declare const SHARE_HOST_ROUTES: readonly {
26
+ method: string;
27
+ path: string;
28
+ pattern: RegExp;
29
+ name: string;
30
+ }[];
31
+ /** A new share id: 16 random bytes as 26 base32 letters. */
32
+ export declare function newShareId(): string;
33
+ /** `text` read as a share bundle the host takes, or a 400 that says why (never quoting a value of it): canonical JSON (the
34
+ * bytes the export writes: what is hashed, scanned and stored is one text), `agentrun.share/1`, the export's closed keys
35
+ * at every level it fixes (the run's allowlist, agent, source, files, omitted, cuts, restored; rows and the graph are
36
+ * the served shapes, read by the scrubber whole), its caps on files, each file's size and digest, and the document's
37
+ * sha256. */
38
+ export declare function checkShareBundle(text: string): {
39
+ sha256: string;
40
+ };
41
+ /** The scrubber over a bundle as a host reads it, refusing (422, counts by rule id, never a value or where) unless every
42
+ * value it finds is a declared restore.
43
+ *
44
+ * Strict at its core: the scrubber in cut mode with `held` over the whole body, and again over every string value alone
45
+ * (as the export cut them: each at its pointer, so a value a string's own context gives away is found though its JSON
46
+ * escaping hides it from the whole-body read). A scrub that fails or throws is `scrub_failed`. The one exception is a
47
+ * filter over those hits: a hit of one string is excused when the scrubber's table says its kind restores (label,
48
+ * personal, jev; never format, held or dump) AND one `restored` record names it exactly (at, rule, start, end); a hit of
49
+ * the whole body is excused when it lies in one string and overlaps an excused hit there of its rule. Any hit left is
50
+ * `scrub_found`; a `restored` record that excuses no hit (a stale or edited bundle) is `restored_unmatched`, unless its
51
+ * rule is Jev's (SHARE_JEV_RULES), which the host never runs: that one is counted in `unchecked`, by rule, and taken.
52
+ * The kind a record says is never read. More than `strings` reads (each distinct string once per context it stands
53
+ * under) is 413 before any scrub. The cut text is
54
+ * never used: the host stores what was sent or nothing. */
55
+ export declare function screenShare(text: string, held: readonly string[], cutPass?: CutScrub, strings?: number): Promise<{
56
+ unchecked: Record<string, number>;
57
+ }>;
58
+ /** What the host keeps of a share beside its bytes. `deleted_at` marks one its owner deleted: its bytes are gone, and its
59
+ * page answers 410. */
60
+ export type ShareMeta = {
61
+ id: string;
62
+ sha256: string;
63
+ token_id: string;
64
+ created_at: string;
65
+ bytes: number;
66
+ deleted_at?: string;
67
+ };
68
+ /** The shares of one host, in files under `dir`, written to a temp file and renamed, 0600 in 0700 folders. Kept in
69
+ * memory once read: this process is the folder's one writer. */
70
+ export declare class ShareStore {
71
+ readonly dir: string;
72
+ private index;
73
+ private queue;
74
+ constructor(dir: string);
75
+ private all;
76
+ /** One write at a time: a quota is read and a share made in one step. */
77
+ private serial;
78
+ get(id: string): Promise<ShareMeta | undefined>;
79
+ /** The live shares `tokenId` made, oldest first. */
80
+ list(tokenId: string): Promise<ShareMeta[]>;
81
+ /** A 403 when `tokenId` keeps its quota of shares already. */
82
+ roomFor(tokenId: string, quota: number): Promise<void>;
83
+ /** Stores `body` as a new share of `tokenId`, the quota checked again inside the write. */
84
+ create(tokenId: string, body: string, sha256: string, quota: number): Promise<ShareMeta>;
85
+ /** The stored bytes of live share `id`. */
86
+ bytes(id: string): Promise<Buffer>;
87
+ /** Deletes share `id` of `tokenId`: its bytes go, its meta stays as the tombstone its page's 410 reads. */
88
+ delete(id: string, tokenId: string): Promise<void>;
89
+ }
90
+ export interface ShareHostDeps {
91
+ /** The server's data folder: shares live in its `shares/`. */
92
+ readonly data: string;
93
+ /** The id of the token an Authorization header carries (api-token.ts bearerCheck), else undefined. */
94
+ who(req: IncomingMessage): string | undefined;
95
+ /** A refused credential, for the server's log line. */
96
+ authFailed?(route: string, reason: string): void;
97
+ /** The values this host holds (its own keys and tokens): a bundle that holds one is refused. */
98
+ held(): readonly string[];
99
+ /** The origin a share's URL is on: AGENTRUN_PUBLIC_URL, else the server's own address. Never a request's Host. */
100
+ origin(): string;
101
+ /** The console's build (share.html and its assets); the one beside the server when undefined. */
102
+ console: string | undefined;
103
+ version: string;
104
+ /** The scrubber in cut mode, or a test's stand-in. */
105
+ scrub?: CutScrub;
106
+ quota?: number;
107
+ /** The most distinct strings an upload may hold (SHARE_STRINGS), for a test. */
108
+ strings?: number;
109
+ }
110
+ /** The share host's answer to every request, under /r/ or not: `fail` renders a refusal (server.ts's envelope). */
111
+ export declare function shareHost(deps: ShareHostDeps): (req: IncomingMessage, res: ServerResponse, raw: string) => Promise<void>;