@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/templates.js CHANGED
@@ -749,7 +749,10 @@ export function readPackage(from, { evalFixtures = true } = {}) {
749
749
  bad(MANIFEST, learningIssue);
750
750
  if (f.approvals !== undefined && f.approvals !== "ask" && f.approvals !== "never")
751
751
  bad(MANIFEST, "approvals is ask (the agent asks its person before a tool runs) or never (it runs unattended; deny and pins still hold)");
752
- const triggers = f.triggers === undefined ? [] : Array.isArray(f.triggers) ? f.triggers : (bad(MANIFEST, "triggers is a list of POST /v2/triggers bodies"), []);
752
+ const written = f.triggers === undefined ? [] : Array.isArray(f.triggers) ? f.triggers : (bad(MANIFEST, "triggers is a list of POST /v2/triggers bodies"), []);
753
+ // A composio trigger written with no config is for an event whose config needs no field (Slack's new channel): its
754
+ // config is the empty one, as POST /v2/triggers takes it.
755
+ const triggers = written.map((trigger) => (isObject(trigger) && isObject(trigger.source) && trigger.source.kind === "composio" && trigger.source.config === undefined ? { ...trigger, source: { ...trigger.source, config: {} } } : trigger));
753
756
  const triggerNames = new Set();
754
757
  triggers.forEach((trigger, i) => {
755
758
  const target = isObject(trigger) ? trigger.target : undefined;
@@ -1294,6 +1297,7 @@ export function pickComputer(p, here) {
1294
1297
  const clash = found && found.computer.kind === "sandbox" && runnerOnly.length ? `${found.words} runs ${runnerOnly.join(", ")} nowhere` : undefined;
1295
1298
  const shell = clash ? undefined : found;
1296
1299
  const lack = "none" in here ? here.none : clash ?? "this server has none";
1300
+ const fix = ("none" in here ? here.fix : undefined) ?? COMPUTER_FIX;
1297
1301
  // A package that needs programs (its list is [shell] alone) takes a sandbox, whose box each run checks for them: a
1298
1302
  // shell that is no sandbox (Archil's serverless exec runs on the runner, whose programs no run checks) is refused.
1299
1303
  if (p.needs && !(shell && shell.computer.kind === "sandbox")) {
@@ -1303,12 +1307,12 @@ export function pickComputer(p, here) {
1303
1307
  }
1304
1308
  const entry = p.computer.find((one) => one === "none" || shell);
1305
1309
  if (!entry)
1306
- return { refused: `The ${p.name} template needs a shell, and ${lack}. Nothing was created.` };
1310
+ return { refused: `The ${p.name} template needs a shell, and ${lack}. Nothing was created.`, ...(fix === COMPUTER_FIX ? {} : { fix }) };
1307
1311
  const runs = entry === "shell" && shell ? shell.tools : [];
1308
1312
  const dropped = (p.tools ?? []).filter((tool) => toolOf(tool)?.sandboxOnly && !runs.includes(tool));
1309
1313
  const without = new Intl.ListFormat("en", { type: "conjunction" }).format(dropped);
1310
1314
  const note = entry === "none" && p.computer[0] === "shell" && !shell
1311
- ? `${lack.charAt(0).toUpperCase()}${lack.slice(1)}, so the agent was made with the template's next choice, no computer${dropped.length ? `, and without ${without}` : ""}. ${COMPUTER_FIX}`
1315
+ ? `${lack.charAt(0).toUpperCase()}${lack.slice(1)}, so the agent was made with the template's next choice, no computer${dropped.length ? `, and without ${without}` : ""}. ${fix}`
1312
1316
  : dropped.length && shell ? `The shell here is ${shell.words}, which runs ${runs.join(", ")} alone, so the agent was made without ${without}.` : null;
1313
1317
  return entry === "shell" && shell
1314
1318
  ? { entry, computer: { ...shell.computer, ...(p.needs ? { needs: [...p.needs] } : {}) }, shell: shell.words, dropped, defaults: [...shell.tools], note }
@@ -31,12 +31,14 @@ export declare function heldAs(name: string, args: unknown): {
31
31
  readonly tool: string;
32
32
  readonly args: unknown;
33
33
  } | undefined;
34
- /** Why a run can't write a file (a screenshot's save_as, a script's op held as write), or undefined where it can: "not
35
- * given", write is not among the agent's `tools` (none given, none: leaving write out is how its owner keeps it from
36
- * writing, whatever write's setting says); "denied", write's `permission` is deny; "no approver", it asks and no one can
37
- * approve (`approvers` false). The one answer the run's gate refuses by and its files note and bound tools offer by. */
38
- export type WriteBar = "not given" | "denied" | "no approver";
39
- export declare const writeBar: (tools: readonly string[] | undefined, permission: Permission, approvers: boolean) => WriteBar | undefined;
34
+ /** Why the gate refuses every call held to a tool whatever its arguments, or undefined where it may let one through:
35
+ * "not given", the tool needs `grant` among the agent's `tools` and it is not there (none given, none: leaving it out is
36
+ * how its owner keeps it, whatever its setting says); "denied", the tool's `permission` is deny; "no approver", it asks
37
+ * and no one can approve (`approvers` false); "policy", bash's policy refuses every call of it (RunGate.opBar alone).
38
+ * The one answer the run's gate refuses by and its files note and bound tools offer by. */
39
+ export type Bar = "not given" | "denied" | "policy" | "no approver";
40
+ /** Why a run can't write a file (a screenshot's save_as), or undefined where it can: barOf, write needing write. */
41
+ export declare const writeBar: (tools: readonly string[] | undefined, permission: Permission, approvers: boolean) => Bar | undefined;
40
42
  /** A session's `{name -> settings key}` map (nameMapOf). */
41
43
  export type NameMap = ReadonlyMap<string, string>;
42
44
  /** Every name a session on `harness` gives its tools, to the settings key each is held to: the shell family (bash's),
@@ -248,7 +250,7 @@ export declare class RunGate {
248
250
  runId: string;
249
251
  harness?: string;
250
252
  computer?: boolean; /** The run's computer kind (its revision's setting): the key a computer tool's refusal and ask name on a tie (kindSetting). */
251
- kind?: string; /** The tools the agent is given (its revision's `tools`): a screenshot's save_as and a script's op held as write are refused unless write is among them; none given, none (writeBar). */
253
+ kind?: string; /** The tools the agent is given (its revision's `tools`): a screenshot's save_as is refused unless write is among them, and a script's file op unless its tool is (OP_GRANTS); none given, none. */
252
254
  tools?: readonly string[];
253
255
  effectOf?: (name: string) => ToolEffect | undefined; /** The arguments each MCP tool's listing in the run's pin declares (ClaimMcp.argumentsOf), for a pinned tool's closure (pinRefusal). */
254
256
  argumentsOf?: ArgumentsOf; /** The harness's adapter facts on the owner's table (its native tools' names, nameMapOf); undefined for one with none. */
@@ -261,7 +263,19 @@ export declare class RunGate {
261
263
  /** Why this run can't write a file now (writeBar over its agent's tools, write's permission and whether anyone can
262
264
  * approve), or undefined where it can: what decide refuses a save_as or a script's write by, and what the run's files
263
265
  * note and computer_screenshot's save_as are offered by. */
264
- readonly writeBar: () => WriteBar | undefined;
266
+ readonly writeBar: () => Bar | undefined;
267
+ /** Why this run's gate refuses the computer op `op` whatever its arguments, or undefined where it may let one through:
268
+ * its grant not given (OP_GRANTS), or the tool it is held to (OP_HELD_AS) set to deny, refused by bash's policy
269
+ * whatever its arguments, or set to an ask no one can approve, in decide's order: the grant first, then the held
270
+ * tool's setting and policy as on a computer (onComputer), the gate decide asks. An op held to no tool (apps, raw
271
+ * input) is the kind's, never barred here. */
272
+ private opBar;
273
+ /** The computer ops this run's gate refuses whatever their arguments (opBar): what computer_op's op list and a
274
+ * script's `computer` declarations leave out. */
275
+ readonly opsRefused: () => readonly string[];
276
+ /** The refusal of a call (`what`, in words) that needs `tool` among the agent's tools, for an agent not given it (none
277
+ * given, none); undefined for one given it, or for a call that needs no tool (`tool` undefined). */
278
+ private notGiven;
265
279
  /** The gate's answer for one call before its intent, for a loop that parks and answers asks itself (the runner's adapter
266
280
  * loops, pi's and the CLI harnesses'): run it, ask a person, or refuse it with the words the model reads. The order:
267
281
  * the deny (with where it was set, and that nothing was sent or charged), a pin, bash's policy (policyRefusal), then
@@ -321,7 +335,9 @@ export declare class RunGate {
321
335
  private pinned;
322
336
  /** Why bash's policy refuses the call `name` (held to `key`) with `args` now, or undefined: the revision's own setting
323
337
  * (an agent's tool_settings.bash.policy), so every shell tool under every harness's name for it is held to it. A policy
324
- * this server does not know refuses every shell call (fail closed), as a pin that does not read does. */
338
+ * this server does not know refuses every shell call (fail closed), as a pin that does not read does. With no `call`,
339
+ * only what refuses every call of it whatever its arguments (opBar): an unknown policy, or a shell tool the read-only
340
+ * policy never runs (readOnlyToolReason). */
325
341
  private policyRefusal;
326
342
  private lastGood?;
327
343
  private readonly told;
package/dist/tool-gate.js CHANGED
@@ -36,7 +36,7 @@ import { asksByDefault, isToolRow, tableTools } from "./tool-list.js";
36
36
  import { CANT_BE_CALLED, computerOffText, computerOffWords, DENIED_OPENING, deniedText, NOT_RUN, RAN_UNKNOWN } from "./refusal-words.js";
37
37
  import { approvalsOf } from "./approvals.js";
38
38
  import { settingOfDefinition } from "./computer-setting.js";
39
- import { BASH_POLICIES, readOnlyReason, readOnlyText } from "./bash-read-only.js";
39
+ import { BASH_POLICIES, readOnlyReason, readOnlyText, readOnlyToolReason } from "./bash-read-only.js";
40
40
  import { formatToolName, isCatalogName, mcpNameOf, mcpToolName, monidNameOf } from "./tool-names.js";
41
41
  /** What the gate does with a tool's calls. */
42
42
  export const PERMISSIONS = ["allow", "ask", "deny"];
@@ -77,10 +77,17 @@ const KIND_TOOLS = (() => {
77
77
  })();
78
78
  /** A script's computer op (computer_op's `op`) that runs on the computer what one of the run's own tools runs, held to
79
79
  * that tool's setting: the shell is bash's, a program started to run on (processes.start) bash_background's (bash's
80
- * setting, and a read-only bash policy refuses it), a file's write is write's (and needs write among the agent's tools,
81
- * writeBar), a file's read, listing or stat is
82
- * read's. The other ops (apps, raw input) are the computer kind's, computer_op's own key (KIND_TOOLS). */
80
+ * setting, and a read-only bash policy refuses it), a file's write is write's, a file's read, listing or stat is read's
81
+ * (each needing its tool among the agent's tools first, OP_GRANTS). The other ops (apps, raw input) are the computer
82
+ * kind's, computer_op's own key (KIND_TOOLS). */
83
83
  const OP_HELD_AS = Object.freeze({ "shell.run": "bash", "processes.start": "bash_background", "files.write": "write", "files.read": "read", "files.list": "read", "files.stat": "read" });
84
+ /** The tool a computer op needs among the agent's tools (none given, none) before any setting of it is read, as the
85
+ * run's own file tools do: a file's write needs write, its read, listing or stat read. An op not here needs no grant:
86
+ * the shell's (shell.run, processes.start) follow bash's setting alone, and the others the kind's. A test holds every
87
+ * op of the kernel's files group to one (computer-op-grants.test.mjs). */
88
+ const OP_GRANTS = Object.freeze({ "files.write": "write", "files.read": "read", "files.list": "read", "files.stat": "read" });
89
+ /** The tool `op` needs among the agent's tools (OP_GRANTS), or undefined for one that needs none. */
90
+ const grantOf = (op) => (typeof op === "string" && Object.hasOwn(OP_GRANTS, op) ? OP_GRANTS[op] : undefined);
84
91
  /** The ops whose command runs in the computer's shell. */
85
92
  const SHELL_OPS = new Set(["shell.run", "processes.start"]);
86
93
  /** The tool a call of `name` with `args` is held to, with the arguments that tool's gate reads, where it is not its own:
@@ -106,12 +113,14 @@ function savedAs(name, args) {
106
113
  }
107
114
  /** What a screenshot's refusal for write's setting adds to write's own words: why write's setting holds it. */
108
115
  const SAVED_AS_WORDS = "computer_screenshot with save_as writes a file into the run's files, so write's setting holds it; a screenshot without save_as is not held to it.";
109
- export const writeBar = (tools, permission, approvers) => !tools?.includes("write") ? "not given" : permission === "deny" ? "denied" : permission === "ask" && !approvers ? "no approver" : undefined;
110
- /** The refusal of a call that writes a file (`writes`: what it does, in words; `instead`: what to do, or "") for an agent
111
- * whose tools leave write out (writeBar's "not given"). */
112
- const notGivenWriteText = (writes, instead, ran) => `${DENIED_OPENING}${writes}, and this agent is not given write, so it can't write one.${instead ? ` ${instead}` : ""} ${ran === "no" ? NOT_RUN : RAN_UNKNOWN}`;
116
+ const barOf = (grant, tools, permission, approvers) => grant !== undefined && !tools?.includes(grant) ? "not given" : permission === "deny" ? "denied" : permission === "ask" && !approvers ? "no approver" : undefined;
117
+ /** Why a run can't write a file (a screenshot's save_as), or undefined where it can: barOf, write needing write. */
118
+ export const writeBar = (tools, permission, approvers) => barOf("write", tools, permission, approvers);
119
+ /** The refusal of a call (`what`, in words) that needs `tool` among the agent's tools, for an agent not given it
120
+ * (`instead`: what to do, or ""). */
121
+ const notGivenText = (what, tool, instead, ran) => `${DENIED_OPENING}${what} needs ${tool} among this agent's tools, and this agent is not given ${tool}.${instead ? ` ${instead}` : ""} ${ran === "no" ? NOT_RUN : RAN_UNKNOWN}`;
113
122
  /** What a screenshot's save_as does, and what to do instead, in a not-given refusal. */
114
- const SAVED_AS_WRITES = ["computer_screenshot with save_as writes a file into the run's files", "Take the screenshot without save_as."];
123
+ const SAVED_AS_WRITES = ["computer_screenshot with save_as (it writes a file into the run's files)", "Take the screenshot without save_as."];
115
124
  const STRICTNESS = { allow: 0, ask: 1, deny: 2 };
116
125
  /** Every name a session on `harness` gives its tools, to the settings key each is held to: the shell family (bash's),
117
126
  * table, own and decision tools, read_skill_file (`read`), the kinds' tools (a shared one by its first kind), nativeTools,
@@ -418,6 +427,29 @@ export class RunGate {
418
427
  * approve), or undefined where it can: what decide refuses a save_as or a script's write by, and what the run's files
419
428
  * note and computer_screenshot's save_as are offered by. */
420
429
  writeBar = () => writeBar(this.where.tools, this.policy("write"), this.approvers);
430
+ /** Why this run's gate refuses the computer op `op` whatever its arguments, or undefined where it may let one through:
431
+ * its grant not given (OP_GRANTS), or the tool it is held to (OP_HELD_AS) set to deny, refused by bash's policy
432
+ * whatever its arguments, or set to an ask no one can approve, in decide's order: the grant first, then the held
433
+ * tool's setting and policy as on a computer (onComputer), the gate decide asks. An op held to no tool (apps, raw
434
+ * input) is the kind's, never barred here. */
435
+ opBar(op) {
436
+ const held = Object.hasOwn(OP_HELD_AS, op) ? OP_HELD_AS[op] : undefined;
437
+ if (held === undefined)
438
+ return undefined;
439
+ const gate = this.onComputer();
440
+ const bar = barOf(grantOf(op), this.where.tools, gate.policy(held), this.approvers);
441
+ if (bar === "not given" || bar === "denied")
442
+ return bar;
443
+ return gate.policyRefusal(gate.keyOf(held) ?? held, held) !== undefined ? "policy" : bar;
444
+ }
445
+ /** The computer ops this run's gate refuses whatever their arguments (opBar): what computer_op's op list and a
446
+ * script's `computer` declarations leave out. */
447
+ opsRefused = () => Object.keys(OP_HELD_AS).filter((op) => this.opBar(op) !== undefined);
448
+ /** The refusal of a call (`what`, in words) that needs `tool` among the agent's tools, for an agent not given it (none
449
+ * given, none); undefined for one given it, or for a call that needs no tool (`tool` undefined). */
450
+ notGiven(tool, what, instead, ran) {
451
+ return tool !== undefined && !this.where.tools?.includes(tool) ? { deny: notGivenText(what, tool, instead, ran) } : undefined;
452
+ }
421
453
  /** The gate's answer for one call before its intent, for a loop that parks and answers asks itself (the runner's adapter
422
454
  * loops, pi's and the CLI harnesses'): run it, ask a person, or refuse it with the words the model reads. The order:
423
455
  * the deny (with where it was set, and that nothing was sent or charged), a pin, bash's policy (policyRefusal), then
@@ -448,10 +480,14 @@ export class RunGate {
448
480
  const own = this.computerOwns(name);
449
481
  const held = heldAs(name, args);
450
482
  if (held && this.policy(name) !== "deny") {
451
- // An op held as write (files.write) writes a file, into the run's files on a desktop that mounts them, as save_as
452
- // does: an agent not given write is refused it first, whatever write's setting says (writeBar).
453
- if (held.tool === "write" && this.writeBar() === "not given")
454
- return { deny: notGivenWriteText(`computer_op ${args.op} writes a file`, "", ran) };
483
+ // An op that needs a tool among the agent's tools (OP_GRANTS: a file's write, read, listing or stat) is refused to
484
+ // an agent not given it first, on every computer, whatever that tool's setting says: no setting offers a tool the
485
+ // agent was not given. Past that, the held tool's own setting and bash's policy decide, a deny, a policy refusal or
486
+ // an ask no one can approve refused in its words: what opBar reads, so the offer (opsRefused) leaves out what this
487
+ // refuses whatever the arguments.
488
+ const op = args.op;
489
+ if (this.opBar(op) === "not given")
490
+ return { deny: notGivenText(`computer_op ${op}`, grantOf(op), "", ran) };
455
491
  return this.onComputer().decide(held.tool, held.args, options);
456
492
  }
457
493
  const key = this.keyOf(name) ?? name;
@@ -468,7 +504,7 @@ export class RunGate {
468
504
  const pinned = this.pinned(key, args, ran);
469
505
  if (pinned)
470
506
  return { deny: pinned.text };
471
- const policed = this.policyRefusal(key, name, args);
507
+ const policed = this.policyRefusal(key, name, { args });
472
508
  if (policed)
473
509
  return { deny: policed };
474
510
  // A screenshot saved into the run's files (save_as) is a file written as write writes one: write's setting holds it
@@ -477,8 +513,9 @@ export class RunGate {
477
513
  // offers a tool the agent was not given (write's default is allow).
478
514
  const saved = savedAs(name, args);
479
515
  if (saved) {
480
- if (this.writeBar() === "not given")
481
- return { deny: notGivenWriteText(...SAVED_AS_WRITES, ran) };
516
+ const refused = this.notGiven("write", ...SAVED_AS_WRITES, ran);
517
+ if (refused)
518
+ return refused;
482
519
  const write = await this.decide("write", saved, options);
483
520
  if (typeof write === "object")
484
521
  return { deny: `${write.deny} ${SAVED_AS_WORDS}` };
@@ -590,8 +627,10 @@ export class RunGate {
590
627
  }
591
628
  /** Why bash's policy refuses the call `name` (held to `key`) with `args` now, or undefined: the revision's own setting
592
629
  * (an agent's tool_settings.bash.policy), so every shell tool under every harness's name for it is held to it. A policy
593
- * this server does not know refuses every shell call (fail closed), as a pin that does not read does. */
594
- policyRefusal(key, name, args) {
630
+ * this server does not know refuses every shell call (fail closed), as a pin that does not read does. With no `call`,
631
+ * only what refuses every call of it whatever its arguments (opBar): an unknown policy, or a shell tool the read-only
632
+ * policy never runs (readOnlyToolReason). */
633
+ policyRefusal(key, name, call) {
595
634
  if (key !== "bash")
596
635
  return undefined;
597
636
  const policy = this.overrides.bash?.policy;
@@ -602,7 +641,7 @@ export class RunGate {
602
641
  const tool = shellToolOf(name) ?? "bash";
603
642
  if (!BASH_POLICIES.includes(policy))
604
643
  return `${tool}${CANT_BE_CALLED}this agent's bash policy ${JSON.stringify(policy).slice(0, 60)} is not one this server knows (${BASH_POLICIES.join(", ")}), so no command is let through until its tool_settings name one. ${NOT_RUN}`;
605
- const reason = readOnlyReason(tool, args, [this.where.work, COMPUTER_ROOT]);
644
+ const reason = call === undefined ? readOnlyToolReason(tool) : readOnlyReason(tool, call.args, [this.where.work, COMPUTER_ROOT]);
606
645
  return reason === undefined ? undefined : readOnlyText(tool, reason, NOT_RUN);
607
646
  }
608
647
  lastGood;
@@ -17,6 +17,10 @@ export declare const isTableTool: (name: string) => boolean;
17
17
  export declare const isAskable: (name: string) => boolean;
18
18
  /** Whether a host runs `name` on a harness other than pi: it has a replay class. */
19
19
  export declare const isHostTool: (name: string) => boolean;
20
+ /** Whether a harness other than pi may be granted `name`: a host tool, or the browser, which has no host row (a call a crash
21
+ * cut off is its custody's to reconcile, never replayed) and binds through its own binding (runner/adapter-run-spec.ts
22
+ * browserHostTools). */
23
+ export declare const adapterBinds: (name: string) => boolean;
20
24
  /** `name`'s replay class as a host runs it, or none. */
21
25
  export declare const replayOf: (name: string) => "safe" | "never" | undefined;
22
26
  /** The tools a host runs on a harness other than pi, by name. */
package/dist/tool-list.js CHANGED
@@ -40,6 +40,10 @@ export const isTableTool = (name) => rowOf(name)?.table === true;
40
40
  export const isAskable = (name) => rowOf(name)?.askable === true;
41
41
  /** Whether a host runs `name` on a harness other than pi: it has a replay class. */
42
42
  export const isHostTool = (name) => rowOf(name)?.replay !== undefined;
43
+ /** Whether a harness other than pi may be granted `name`: a host tool, or the browser, which has no host row (a call a crash
44
+ * cut off is its custody's to reconcile, never replayed) and binds through its own binding (runner/adapter-run-spec.ts
45
+ * browserHostTools). */
46
+ export const adapterBinds = (name) => isHostTool(name) || name === "browser";
43
47
  /** `name`'s replay class as a host runs it, or none. */
44
48
  export const replayOf = (name) => rowOf(name)?.replay;
45
49
  /** The tools a host runs on a harness other than pi, by name. */
@@ -374,6 +374,7 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
374
374
  blurb?: string | undefined;
375
375
  name: string;
376
376
  } | {
377
+ ceiling?: string | undefined;
377
378
  provider: string;
378
379
  provider_from: string;
379
380
  default_provider: string;
@@ -212,7 +212,8 @@ export const FIRECRAWL_FETCH = "Firecrawl's free keyless fetch, no key, the guar
212
212
  const searchesOwn = (resolves, facts) => WEB_RUNS.web_search.includes(resolves) && (resolves !== "native" || !facts?.webSearch);
213
213
  const ranksOwn = (resolves, input) => searchesOwn(resolves, input.facts);
214
214
  /** The server's settings that are a ceiling an agent's pick cannot raise: web_fetch `kernel` keeps every URL on the
215
- * server; web_search `native` keeps every query with the harness's own search, and `off` sends none. Under one, an
215
+ * server; web_search `native` sends every query to the harness's own search, and `off` sends none (Jev, where it is
216
+ * on, still sees a kernel fetch's page or a native pi search's results: web-run.ts jevWebOf). Under one, an
216
217
  * agent's pick that would send anywhere but the ceiling's own resolves as the server's setting does: a keyless third
217
218
  * party (Firecrawl, Exa), Parallel even when the agent names it, and under `off` a native search even when the agent
218
219
  * names it (ceilingOver). An operator who wants Parallel sets it server-wide; that is no ceiling. */
@@ -753,6 +754,9 @@ export function agentTools(env, settings, agent, order, shell = "computer", effe
753
754
  const pick = name;
754
755
  const own = agent.overrides?.[pick]?.provider;
755
756
  const server = settings[pick]?.provider;
756
- return { ...shown, ...gate, provider: own ?? server ?? PROVIDERS[pick][0], provider_from: own ? "agent" : server ? "server" : "default", default_provider: server ?? PROVIDERS[pick][0], resolved: plane[pick] };
757
+ // The server's setting a ceiling over the agent's own pick (ceilingOver): the pick named past it, or what the pick
758
+ // would resolve to with no server setting past it. `resolved` is then the server's, and `ceiling` says why.
759
+ const ceiling = own === undefined ? undefined : ceilingOver(pick, server, own, planeFor(env, agent, { ...settings, [pick]: { ...settings[pick], provider: undefined } })[pick]);
760
+ return { ...shown, ...gate, provider: own ?? server ?? PROVIDERS[pick][0], provider_from: own ? "agent" : server ? "server" : "default", default_provider: server ?? PROVIDERS[pick][0], resolved: plane[pick], ...(ceiling ? { ceiling } : {}) };
757
761
  });
758
762
  }
package/dist/tools.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // nothing here: a run's runner binds them from its workspace's registry (workspace/run-tools.ts), each call made on the
5
5
  // run's folder or its computer. `bash` and the background tools may be named only by an agent whose place is a box
6
6
  // (runnable.ts).
7
- import { blurbOf, isHostTool } from "./tool-list.js";
7
+ import { adapterBinds, blurbOf } from "./tool-list.js";
8
8
  import { EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileSummary, sendSummary } from "./email/names.js";
9
9
  // The email tools' timeline lines (registerLabel), registered as this module loads.
10
10
  import "./email/labels.js";
@@ -814,7 +814,7 @@ export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell =
814
814
  // Unavailable says why: a sandbox-only tool no box here can run, why none can (`noBox`); on a tool a user picks a
815
815
  // provider for, the resolutions' own words (`web_search is turned off in settings`); else the variables it needs.
816
816
  const reason = available ? undefined : refusal ?? boxless ?? (plane ? [...new Set(Object.values(plane).filter(isUnavailable).map(whyUnavailable))].join("; ") : `Needs ${keyNeeded(missing)}`);
817
- return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), ...(entry.runnerOnly ? { runner_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
817
+ return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), ...(entry.runnerOnly ? { runner_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: adapterBinds(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
818
818
  });
819
819
  // The host tools over a run's own tools (META_TOOLS): not in the table, never granted or named by a node (`meta`), listed
820
820
  // so the owner sees them and their setting (allow or deny; a deny is not offered at all).
@@ -194,7 +194,7 @@ function fieldsOf(value, bad) {
194
194
  if (typeof event !== "string" || !COMPOSIO_EVENT.test(event))
195
195
  fail("event", event === undefined ? "missing" : "invalid", "event is one of the server's toolkit's events, as Composio slugs it (GITHUB_ISSUE_ADDED_EVENT): GET /v2/settings/mcp-servers/{name}/composio/events lists them");
196
196
  if (!isObject(config) || Buffer.byteLength(JSON.stringify(config), "utf8") > CONFIG_BYTES)
197
- fail("config", config === undefined ? "missing" : "invalid", `config is the event's config, an object as its schema says (GitHub's {owner, repo}), at most ${CONFIG_BYTES} bytes as JSON`);
197
+ fail("config", config === undefined ? "missing" : "invalid", `config is the event's config, an object as its schema says (GitHub's {owner, repo}; {} for an event whose schema needs no field), at most ${CONFIG_BYTES} bytes as JSON`);
198
198
  if (instance !== undefined && !(typeof instance === "string" && INSTANCE.test(instance)))
199
199
  fail("instance_id", "invalid", "instance_id is Composio's id for the trigger's instance, set by this server");
200
200
  if (hook !== undefined && !(typeof hook === "string" && COMPOSIO_HOOK.test(hook)))
@@ -176,6 +176,9 @@ export declare class Webhooks {
176
176
  constructor(store: WebhooksStore, key: Buffer, say: (fields: Record<string, string | number>) => void, options?: WebhooksOptions,
177
177
  /** Which outbox this is: the webhook's (WEBHOOK_OUTBOUND), or another destination's over the same machinery. */
178
178
  outbound?: Outbound);
179
+ /** Reads the saved secrets alone (signingSecrets), writing nothing and sending nothing: a share host's start, which
180
+ * sends no message but still holds every value this server saved, so an upload carrying one is refused. */
181
+ readSecrets(): Promise<void>;
179
182
  /** Reads the webhook, its secret and its ledger once, and goes on with the messages an earlier server left queued, each
180
183
  * at its next try's time; a test send is tried once, so one left queued failed. Awaited once at start. */
181
184
  load(): Promise<void>;
package/dist/webhooks.js CHANGED
@@ -184,6 +184,11 @@ export class Webhooks {
184
184
  this.privateTargets = options.privateTargets ?? false;
185
185
  this.lookup = options.lookup ?? (async (host) => (await dns.lookup(host, { all: true })).map((a) => a.address));
186
186
  }
187
+ /** Reads the saved secrets alone (signingSecrets), writing nothing and sending nothing: a share host's start, which
188
+ * sends no message but still holds every value this server saved, so an upload carrying one is refused. */
189
+ async readSecrets() {
190
+ await this.secrets.load();
191
+ }
187
192
  /** Reads the webhook, its secret and its ledger once, and goes on with the messages an earlier server left queued, each
188
193
  * at its next try's time; a test send is tried once, so one left queued failed. Awaited once at start. */
189
194
  async load() {
@@ -51,6 +51,9 @@ export interface ArchilClaimOptions {
51
51
  readonly settings: RunDiskOptions["store"]["settings"] & Pick<Settings, "replaceIf">;
52
52
  };
53
53
  };
54
+ /** Where a remove the claim's end could not leave for the janitor is said (its release's, a lost claim's). Default: the
55
+ * runner's stderr. */
56
+ readonly log?: (line: string) => void;
54
57
  }
55
58
  export interface ArchilClaim {
56
59
  /** The claim's disk: its key is this step's, asked for on every call. */
@@ -69,9 +72,10 @@ export interface ArchilClaim {
69
72
  /** Takes on the credential an earlier claim of the run minted, the one in the computer that claim kept at the run's
70
73
  * park (computer-kept.ts) and this claim attached again: nothing is minted, and this claim's revoke removes it. */
71
74
  inherit(): void;
72
- /** The claim's end with its last revoke failed: the remove left for the janitor (mount-revoke-left.ts), at most once.
73
- * Nothing owed, nothing written. The release does it too, and so does a revoke that fails after the release (a lost
74
- * claim's). Never before the claim's end: until then it may mint again under its own epoch. */
75
+ /** The claim's end with its last revoke failed: the remove left for the janitor (mount-revoke-left.ts), written once; a
76
+ * write that failed is tried again by the next leave. Nothing owed, nothing written. The release does it too, and so
77
+ * does a revoke that fails after the release (a lost claim's), each saying on the log a write that failed. Never
78
+ * before the claim's end: until then it may mint again under its own epoch. */
75
79
  leave(): Promise<void>;
76
80
  /** Every value held, for the redaction set. */
77
81
  readonly secrets: ReadonlySet<string>;
@@ -19,6 +19,7 @@
19
19
  // the store's sealed keys and the seal key are handed in.
20
20
  import { ARCHIL_API_KEY_ROW, DEFAULT_ARCHIL_EXEC_IMAGE } from "../archil-settings.js";
21
21
  import { leaveMountRevoke } from "./mount-revoke-left.js";
22
+ import { stderrLog } from "./computer-intervals.js";
22
23
  import { archilApiKey } from "./archil-key.js";
23
24
  import { archilDisk, pinnedImage } from "./archil-disk.js";
24
25
  import { mintMountToken, nicknameOf, removeMountToken, removeOlderMountTokens, removeRunMountTokens } from "./archil-mount-credential.js";
@@ -127,7 +128,8 @@ export async function archilClaim(options) {
127
128
  let live;
128
129
  /** The last revoke failed: a credential of this claim may stand at Archil, its remove owed. */
129
130
  let owed = false;
130
- /** The remove left for the janitor, once written (or being written): at most one per claim. */
131
+ /** The remove left for the janitor, once written (or being written): at most one per claim. A write that failed is
132
+ * forgotten, so the next leave tries again. */
131
133
  let left;
132
134
  /** The claim's end with a remove owed: the remove left for the janitor (mount-revoke-left.ts), by this claim's epoch on
133
135
  * its disk, stamped on the store's clock. */
@@ -135,13 +137,19 @@ export async function archilClaim(options) {
135
137
  const mount = options.mount;
136
138
  if (!owed || mount === undefined)
137
139
  return Promise.resolve();
138
- left ??= options.keys.clock().then((until) => leaveMountRevoke(options.run.store.settings, mount.runId, { epoch: mount.epoch, disk: chosen.diskId, until }));
139
- return left;
140
+ const writing = (left ??= options.keys.clock().then((until) => leaveMountRevoke(options.run.store.settings, mount.runId, { epoch: mount.epoch, disk: chosen.diskId, until })));
141
+ void writing.catch(() => {
142
+ if (left === writing)
143
+ left = undefined;
144
+ });
145
+ return writing;
140
146
  };
147
+ /** A leave at the claim's end, whose failure no caller hears: said on the log, as the credential then lapses at its ttl. */
148
+ const leaveSaid = () => leave().catch((error) => (options.log ?? stderrLog)(`run ${options.mount?.runId}'s Archil mount credential remove could not be left for the janitor, so it lapses at its ttl: ${error instanceof Error ? error.message : String(error)}`));
141
149
  const release = () => {
142
150
  released = true;
143
151
  held.clear();
144
- void leave().catch(() => undefined);
152
+ void leaveSaid();
145
153
  };
146
154
  /** Removes the credential minted, by its identifier: idempotent. Then the run's users of this claim's epoch and earlier,
147
155
  * by their names, once per mint asked for: a mint whose answer was lost (Archil made the user, this claim never heard
@@ -159,7 +167,7 @@ export async function archilClaim(options) {
159
167
  owed = true;
160
168
  // After the release (a lost claim's, or a run's process's revoke its runner made last) nothing revokes again.
161
169
  if (released)
162
- await leave().catch(() => undefined);
170
+ await leaveSaid();
163
171
  throw error;
164
172
  }
165
173
  };
@@ -1,5 +1,11 @@
1
1
  /** The control plane of each Archil region, as Archil's SDK (`disk` 1.12.0, src/regions.ts) names them. */
2
2
  export declare const ARCHIL_CONTROL_URLS: Readonly<Record<string, string>>;
3
+ /** Whether each region serve knows has Archil's serverless exec (https://docs.archil.com/reference/regions): its AWS
4
+ * regions do; gcp-us-central1 doesn't, and every exec there answers "Exec is not enabled". */
5
+ export declare const ARCHIL_EXEC_REGIONS: Readonly<Record<string, boolean>>;
6
+ /** Whether region `region` has Archil's serverless exec (ARCHIL_EXEC_REGIONS). A region serve doesn't know (one given
7
+ * with its own S3 URL, a BYOC deployment) is taken to have it: Archil's own error says why where it hasn't. */
8
+ export declare const archilHasExec: (region: string) => boolean;
3
9
  /** Archil's control plane, for the account's calls (archil-disks.ts) as for a disk's. */
4
10
  export interface ArchilControlOptions {
5
11
  /** The region: it names the control plane. */
@@ -17,6 +17,17 @@ export const ARCHIL_CONTROL_URLS = Object.freeze({
17
17
  "aws-eu-west-1": "https://control.green.eu-west-1.aws.prod.archil.com",
18
18
  "gcp-us-central1": "https://control.blue.us-central1.gcp.prod.archil.com",
19
19
  });
20
+ /** Whether each region serve knows has Archil's serverless exec (https://docs.archil.com/reference/regions): its AWS
21
+ * regions do; gcp-us-central1 doesn't, and every exec there answers "Exec is not enabled". */
22
+ export const ARCHIL_EXEC_REGIONS = Object.freeze({
23
+ "aws-us-east-1": true,
24
+ "aws-us-west-2": true,
25
+ "aws-eu-west-1": true,
26
+ "gcp-us-central1": false,
27
+ });
28
+ /** Whether region `region` has Archil's serverless exec (ARCHIL_EXEC_REGIONS). A region serve doesn't know (one given
29
+ * with its own S3 URL, a BYOC deployment) is taken to have it: Archil's own error says why where it hasn't. */
30
+ export const archilHasExec = (region) => !Object.hasOwn(ARCHIL_EXEC_REGIONS, region) || ARCHIL_EXEC_REGIONS[region] === true;
20
31
  const LOOPBACK = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule names loopback hosts to allow plain http only to them, in tests
21
32
  /** Why the control plane refused, in words: its status and Archil's own message, with no secret in them. */
22
33
  export class ArchilMountCredentialError extends Error {
@@ -368,10 +368,11 @@ export function attachedWorkspace(base, computer, options = {}) {
368
368
  // once, at its end, where a caller (bash) needs the output as it comes and the end of a long one. The process is
369
369
  // read as it comes (process.read, each stream from its own offset), every byte given to onOutput and the first
370
370
  // maxOutput of each kept; at the deadline or an abort it is sent KILL (computerd's guard then ends everything it
371
- // started), and once it ends its guard kills whatever it left, so nothing it started outlives it.
371
+ // started), and once it ends its guard kills whatever it left, so nothing it started outlives it. `stdin`: the process
372
+ // starts with its stdin open, and the bytes go by process.write, in chunks, its stdin closed after the last, so they
373
+ // are never in its argv or its environment (a checkout's token, pr-checkout.ts). A program that ends without reading
374
+ // them answers as it ended: a write it no longer takes is not the call's failure, as a closed pipe's is not.
372
375
  async exec(argv, options) {
373
- if (options.stdin !== undefined)
374
- throw new WorkspaceError("REFUSED", "exec with stdin runs on the run's folder, not in a computer: a computer's exec takes no stdin");
375
376
  if (options.network !== undefined)
376
377
  throw new WorkspaceError("REFUSED", "a command in a computer has the computer's own network: its exec takes no network of its own, and nothing ran");
377
378
  const { timeoutMs, signal } = options;
@@ -383,7 +384,23 @@ export function attachedWorkspace(base, computer, options = {}) {
383
384
  if (signal?.aborted)
384
385
  throw abortError(signal);
385
386
  const { abs, rel } = at(options.cwd ?? "");
386
- const { id } = await value(call("process.start", { argv: [...argv], cwd: abs, env: { ...options.env } }), rel);
387
+ const { stdin } = options;
388
+ const { id } = await value(call("process.start", { argv: [...argv], cwd: abs, env: { ...options.env }, ...(stdin !== undefined ? { stdin: true } : {}) }), rel);
389
+ const feed = async (bytes) => {
390
+ const parts = chunks(bytes);
391
+ for (const [i, part] of parts.entries()) {
392
+ const wrote = await call("process.write", { id, data: base64(part), ...(i === parts.length - 1 ? { close: true } : {}) });
393
+ if (wrote.ok)
394
+ continue;
395
+ // computerd answers invalid once the program closed its stdin or ended (EPIPE, EIO, a closed file, "has ended",
396
+ // "stdin is closed"): the program answers as it ended. A write it did not read in time (timeout), a lost
397
+ // connection or any other failure fails the call, which kills the process (the catch below); after this
398
+ // call's own deadline or abort, that answer stands instead.
399
+ if (wrote.error.code === "invalid" || timedOut || aborted)
400
+ return;
401
+ throw new WorkspaceError(CODES[wrote.error.code] ?? "UNAVAILABLE", `${JSON.stringify(rel === "" ? "." : rel)}: the program's input could not be written: ${wrote.error.message}`, { path: rel });
402
+ }
403
+ };
387
404
  let timedOut = false;
388
405
  let aborted = false;
389
406
  let truncated = false;
@@ -422,7 +439,7 @@ export function attachedWorkspace(base, computer, options = {}) {
422
439
  };
423
440
  let exit;
424
441
  try {
425
- await Promise.all([readAll("stdout"), readAll("stderr")]);
442
+ await Promise.all([readAll("stdout"), readAll("stderr"), ...(stdin !== undefined ? [feed(stdin)] : [])]);
426
443
  exit = await value(call("process.wait", { id, timeoutMs: EXEC_EXIT_WAIT_MS }), rel);
427
444
  }
428
445
  catch (error) {
@@ -43,7 +43,7 @@ export type DockerComputerOptions = {
43
43
  };
44
44
  export declare function dockerVolumeOf(paths: DockerPaths): DockerComputerOptions | undefined;
45
45
  /** The deps computerForClaim takes once per process: all but the claim's own. */
46
- export type ComputerDeps = Omit<ComputerForClaimDeps, "mode" | "workspace" | "sealKey" | "revokeMount" | "signal">;
46
+ export type ComputerDeps = Omit<ComputerForClaimDeps, "mode" | "noExec" | "workspace" | "sealKey" | "revokeMount" | "signal">;
47
47
  export interface ComputerDepsOptions {
48
48
  /** The server's environment: a provider key named here wins over its saved one; AGENTRUN_DOCKER_IMAGE names Docker's
49
49
  * image. Passed in, never read here. */
@@ -118,8 +118,10 @@ export declare const computerStartingWords: ({ provider, kind }: Pick<ComputerSa
118
118
  * (`kept`) says it is the same; a new one after a kept one's time passed (`replaced.lapsed`) says why first, as does
119
119
  * one after a kept one pinned to a runner that was gone by the resume (`replaced.lost`, computerLostWords), or still
120
120
  * there and ending it itself (`replaced.elsewhere`, computerHeldWords), and one after the kept one's provider refused
121
- * to attach it again (`replaced.refused`, in the provider's words). Where that runner is still there, the one before
122
- * runs until its end, so the words say only that nothing on it comes with the new one, never that it is gone. */
121
+ * to attach it again (`replaced.refused`, computerRefusedWords: serve's words, never the provider's, which name host
122
+ * paths). A runner gone or still there says why first, though its provider refused too: that is why no runner that
123
+ * could reach the machine took the run. Where that runner is still there, the one before runs until its end, so the
124
+ * words say only that nothing on it comes with the new one, never that it is gone. */
123
125
  export declare const computerReadyWords: ({ provider, kind, hello, replaced, kept }: ComputerSaid) => string;
124
126
  /** The run's timeline phase as its run parks with its computer kept (ClaimComputer.keeps), such as "The desktop is kept
125
127
  * for 10 minutes while you decide." */
@@ -29,7 +29,7 @@ import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV } from "../start-switches.js
29
29
  import { readLaunchBody } from "../run-launch.js";
30
30
  import { SERVER_NOTE_LABEL } from "@parcha/agentrun-kernel/kernel/cap";
31
31
  import { computerForClaim } from "./computer-for-claim.js";
32
- import { computerHeldWords, computerLapsedWords, computerLostWords, KEEP_WORDS } from "./computer-kept.js";
32
+ import { computerHeldWords, computerLapsedWords, computerLostWords, computerRefusedWords, KEEP_WORDS } from "./computer-kept.js";
33
33
  import { storeLedger } from "./computer-ledger.js";
34
34
  import { computerProviderFactories, computerProviderMakers, providerSecretsOf } from "./computer-providers.js";
35
35
  import { aLabel, needsNetwork, noNetworkRefusal, vendorNetworkOnly } from "./resolve-computer.js";
@@ -208,20 +208,22 @@ export const computerStartingWords = ({ provider, kind }) => `Starting a ${kind}
208
208
  * (`kept`) says it is the same; a new one after a kept one's time passed (`replaced.lapsed`) says why first, as does
209
209
  * one after a kept one pinned to a runner that was gone by the resume (`replaced.lost`, computerLostWords), or still
210
210
  * there and ending it itself (`replaced.elsewhere`, computerHeldWords), and one after the kept one's provider refused
211
- * to attach it again (`replaced.refused`, in the provider's words). Where that runner is still there, the one before
212
- * runs until its end, so the words say only that nothing on it comes with the new one, never that it is gone. */
211
+ * to attach it again (`replaced.refused`, computerRefusedWords: serve's words, never the provider's, which name host
212
+ * paths). A runner gone or still there says why first, though its provider refused too: that is why no runner that
213
+ * could reach the machine took the run. Where that runner is still there, the one before runs until its end, so the
214
+ * words say only that nothing on it comes with the new one, never that it is gone. */
213
215
  export const computerReadyWords = ({ provider, kind, hello, replaced, kept }) => {
214
216
  const ready = `The ${kind} is ready: ${[OS_NAMES[hello.os] ?? hello.os, hello.osVersion].filter(Boolean).join(" ")} (${hello.arch}), from ${provider}.`;
215
217
  if (kept)
216
218
  return `${ready} It's the same ${kind}, as the wait left it.`;
217
219
  if (!replaced)
218
220
  return ready;
219
- const why = replaced.refused
220
- ? ` The ${kind} kept before could not be taken back: ${replaced.refused.replace(/[.!?]+$/, "")}.`
221
- : replaced.lost
222
- ? ` ${computerLostWords(kind)}`
223
- : replaced.elsewhere
224
- ? ` ${computerHeldWords(kind)}`
221
+ const why = replaced.lost
222
+ ? ` ${computerLostWords(kind)}`
223
+ : replaced.elsewhere
224
+ ? ` ${computerHeldWords(kind)}`
225
+ : replaced.refused
226
+ ? ` ${computerRefusedWords(kind)}`
225
227
  : replaced.lapsed
226
228
  ? ` ${computerLapsedWords(kind)}`
227
229
  : "";