@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.33

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 (163) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +78 -46
  3. package/dist/adapters.d.ts +0 -3
  4. package/dist/adapters.js +0 -7
  5. package/dist/agents.d.ts +1 -1
  6. package/dist/api-only.d.ts +14 -0
  7. package/dist/api-only.js +33 -0
  8. package/dist/archil-routes.d.ts +1 -1
  9. package/dist/box-egress-vm.d.ts +0 -8
  10. package/dist/box-egress-vm.js +0 -10
  11. package/dist/box-egress.d.ts +0 -4
  12. package/dist/box-egress.js +1 -16
  13. package/dist/box-paths.d.ts +25 -2
  14. package/dist/box-paths.js +79 -11
  15. package/dist/box-relay.d.ts +0 -11
  16. package/dist/box-relay.js +0 -20
  17. package/dist/box-settings.d.ts +46 -0
  18. package/dist/box-settings.js +107 -0
  19. package/dist/boxes.d.ts +4 -1
  20. package/dist/browser-cost.js +2 -1
  21. package/dist/browser-person.d.ts +0 -2
  22. package/dist/browser-person.js +0 -2
  23. package/dist/budget.d.ts +0 -4
  24. package/dist/budget.js +0 -7
  25. package/dist/cap.d.ts +0 -7
  26. package/dist/cap.js +0 -22
  27. package/dist/cli.js +23 -8
  28. package/dist/computers.d.ts +1 -1
  29. package/dist/console/assets/index-Dn0ngwG9.js +535 -0
  30. package/dist/console/assets/index-DvW6Aled.css +1 -0
  31. package/dist/console/index.html +2 -2
  32. package/dist/daytona-api.d.ts +0 -11
  33. package/dist/daytona-api.js +1 -82
  34. package/dist/docker-host-addresses.d.ts +37 -0
  35. package/dist/docker-host-addresses.js +110 -0
  36. package/dist/files.d.ts +0 -8
  37. package/dist/files.js +0 -17
  38. package/dist/github-connection.d.ts +1 -1
  39. package/dist/github-connection.js +1 -1
  40. package/dist/harness-install.d.ts +23 -0
  41. package/dist/harness-install.js +99 -4
  42. package/dist/harness.d.ts +4 -3
  43. package/dist/harness.js +16 -1
  44. package/dist/import.js +52 -13
  45. package/dist/learn/secrets.d.ts +2 -1
  46. package/dist/learn/secrets.js +19 -6
  47. package/dist/learned-workflow.d.ts +5 -4
  48. package/dist/learned-workflow.js +6 -3
  49. package/dist/learning-routes.d.ts +9 -46
  50. package/dist/learning-routes.js +25 -29
  51. package/dist/learning-run.d.ts +4 -231
  52. package/dist/learning-run.js +7 -651
  53. package/dist/live/translate.js +1 -1
  54. package/dist/mcp-gateway.d.ts +0 -3
  55. package/dist/mcp-gateway.js +0 -13
  56. package/dist/mcp-probe.d.ts +2 -2
  57. package/dist/mcp-probe.js +2 -2
  58. package/dist/mcp-servers-store.js +1 -1
  59. package/dist/openapi.js +3 -3
  60. package/dist/page.js +3 -1
  61. package/dist/paid-calls.js +3 -2
  62. package/dist/pause.d.ts +0 -2
  63. package/dist/pause.js +1 -8
  64. package/dist/place.d.ts +0 -5
  65. package/dist/place.js +0 -10
  66. package/dist/print.d.ts +2 -1
  67. package/dist/print.js +4 -2
  68. package/dist/run-db.d.ts +0 -2
  69. package/dist/run-db.js +0 -4
  70. package/dist/run-learning-served.d.ts +38 -0
  71. package/dist/run-learning-served.js +9 -0
  72. package/dist/run-secrets.d.ts +33 -0
  73. package/dist/run-secrets.js +53 -0
  74. package/dist/run-timeline-served.js +5 -2
  75. package/dist/run-view.d.ts +5 -9
  76. package/dist/run-view.js +4 -22
  77. package/dist/runner/adapter-loop.d.ts +8 -2
  78. package/dist/runner/adapter-loop.js +44 -12
  79. package/dist/runner/adapter-run-spec.d.ts +8 -0
  80. package/dist/runner/adapter-run-spec.js +6 -5
  81. package/dist/runner/adapters/pi.d.ts +4 -0
  82. package/dist/runner/adapters/pi.js +4 -1
  83. package/dist/runner/beside.js +19 -8
  84. package/dist/runner/claim-secrets.js +1 -1
  85. package/dist/runner/cli-run-spec.js +15 -1
  86. package/dist/runner/journal-kinds.d.ts +6 -0
  87. package/dist/runner/live-ticker.d.ts +1 -1
  88. package/dist/runner/live-ticker.js +28 -4
  89. package/dist/runner/loop-contract.d.ts +3 -2
  90. package/dist/runner/main.d.ts +11 -4
  91. package/dist/runner/main.js +39 -10
  92. package/dist/runner/mcp-claim.d.ts +1 -1
  93. package/dist/runner/mcp-claim.js +1 -1
  94. package/dist/runner/model-route.js +21 -2
  95. package/dist/runner/redact.d.ts +8 -2
  96. package/dist/runner/redact.js +11 -2
  97. package/dist/runner/workflow-spec.js +5 -9
  98. package/dist/runs-over-store.d.ts +1 -1
  99. package/dist/runs-over-store.js +16 -5
  100. package/dist/seal-key.d.ts +54 -15
  101. package/dist/seal-key.js +272 -84
  102. package/dist/sealed-settings.d.ts +2 -2
  103. package/dist/sealed-settings.js +3 -10
  104. package/dist/secrets.d.ts +2 -10
  105. package/dist/secrets.js +21 -17
  106. package/dist/server-secrets-store.js +1 -1
  107. package/dist/server-secrets.js +3 -0
  108. package/dist/server.d.ts +10 -6
  109. package/dist/server.js +89 -41
  110. package/dist/store/index.d.ts +1 -1
  111. package/dist/store/index.js +1 -1
  112. package/dist/store/open.d.ts +12 -2
  113. package/dist/store/open.js +23 -3
  114. package/dist/store/postgres/migrate.js +18 -1
  115. package/dist/store/sqlite/store.js +23 -8
  116. package/dist/store/store.d.ts +3 -0
  117. package/dist/store-reads/journal.d.ts +16 -0
  118. package/dist/store-reads/journal.js +82 -6
  119. package/dist/store-view.js +38 -5
  120. package/dist/tool-keys.d.ts +4 -3
  121. package/dist/tool-keys.js +7 -4
  122. package/dist/tools.d.ts +1 -1
  123. package/dist/tools.js +4 -1
  124. package/dist/trigger-schedule.js +2 -1
  125. package/dist/trigger-secrets-shown.js +5 -1
  126. package/dist/workspace/computer-deps.d.ts +29 -0
  127. package/dist/workspace/computer-deps.js +48 -1
  128. package/dist/workspace/computer-for-claim.d.ts +7 -3
  129. package/dist/workspace/computer-for-claim.js +1 -1
  130. package/dist/workspace/computer-providers.d.ts +6 -2
  131. package/dist/workspace/computer-providers.js +1 -1
  132. package/dist/workspace/index.d.ts +1 -1
  133. package/dist/workspace/index.js +1 -1
  134. package/dist/workspace.d.ts +0 -3
  135. package/dist/workspace.js +0 -3
  136. package/launcher/agentrun-serve +6 -33
  137. package/package.json +14 -14
  138. package/templates/inbound-lead/agent.md +1 -1
  139. package/templates/kyb/agent.md +1 -1
  140. package/dist/app.d.ts +0 -5
  141. package/dist/app.js +0 -514
  142. package/dist/bounds.d.ts +0 -26
  143. package/dist/bounds.js +0 -137
  144. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  145. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  146. package/dist/content-filter.d.ts +0 -7
  147. package/dist/content-filter.js +0 -23
  148. package/dist/disk.d.ts +0 -33
  149. package/dist/disk.js +0 -85
  150. package/dist/door-line.d.ts +0 -23
  151. package/dist/door-line.js +0 -83
  152. package/dist/harness-app.d.ts +0 -69
  153. package/dist/harness-app.js +0 -1162
  154. package/dist/request-start.d.ts +0 -27
  155. package/dist/request-start.js +0 -381
  156. package/dist/run-box.d.ts +0 -205
  157. package/dist/run-box.js +0 -661
  158. package/dist/run-holder.d.ts +0 -52
  159. package/dist/run-holder.js +0 -139
  160. package/dist/runs.d.ts +0 -1200
  161. package/dist/runs.js +0 -4103
  162. package/dist/served-only.d.ts +0 -5
  163. package/dist/served-only.js +0 -12
@@ -974,6 +974,11 @@ class SqliteStore {
974
974
  put: async (key, value) => {
975
975
  await db.write([{ sql: "INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at", params: [key, json(value), now()] }]);
976
976
  },
977
+ putIfAbsent: async (key, value) => {
978
+ await db.write([{ sql: "INSERT INTO settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT (key) DO NOTHING", params: [key, json(value), now()] }]);
979
+ const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
980
+ return row === undefined ? undefined : JSON.parse(row.value);
981
+ },
977
982
  remove: async (key) => {
978
983
  await db.write([{ sql: "DELETE FROM settings WHERE key = ?", params: [key] }]);
979
984
  },
@@ -1040,31 +1045,41 @@ class SqliteStore {
1040
1045
  all: async () => {
1041
1046
  const out = [];
1042
1047
  const bytes = (value) => Uint8Array.from(value);
1048
+ // A row whose AAD cannot be built (a key holding the separator) was never sealed by this store's writers, which
1049
+ // build the same AAD: it is left out, never a failed read of every other.
1050
+ const add = (row) => {
1051
+ try {
1052
+ out.push(row());
1053
+ }
1054
+ catch {
1055
+ // Left out: see above.
1056
+ }
1057
+ };
1043
1058
  for (const row of await db.all("SELECT name, sealed FROM sealed_keys ORDER BY name")) {
1044
- out.push({ plane: "sealed_keys", where: { name: row.name }, aad: aadOf(sealedAt.sealedKey(row.name)), sealed: bytes(row.sealed) });
1059
+ add(() => ({ plane: "sealed_keys", where: { name: row.name }, aad: aadOf(sealedAt.sealedKey(row.name)), sealed: bytes(row.sealed) }));
1045
1060
  }
1046
1061
  for (const row of await db.all("SELECT name, sealed FROM mcp_servers WHERE sealed IS NOT NULL ORDER BY name")) {
1047
- out.push({ plane: "mcp_servers", where: { name: row.name }, aad: aadOf(sealedAt.mcpServer(row.name)), sealed: bytes(row.sealed) });
1062
+ add(() => ({ plane: "mcp_servers", where: { name: row.name }, aad: aadOf(sealedAt.mcpServer(row.name)), sealed: bytes(row.sealed) }));
1048
1063
  }
1049
1064
  for (const row of await db.all("SELECT state, sealed FROM mcp_oauth_pending ORDER BY state")) {
1050
- out.push({ plane: "mcp_oauth_pending", where: { state: row.state }, aad: aadOf(sealedAt.oauthPending(row.state)), sealed: bytes(row.sealed) });
1065
+ add(() => ({ plane: "mcp_oauth_pending", where: { state: row.state }, aad: aadOf(sealedAt.oauthPending(row.state)), sealed: bytes(row.sealed) }));
1051
1066
  }
1052
1067
  for (const row of await db.all("SELECT adapter, scope, field, sealed FROM trigger_settings ORDER BY adapter, scope, field")) {
1053
1068
  // Base64 text in this column (sealed-settings-store.ts), under the table's documented composite-key AAD.
1054
- out.push({ plane: "trigger_settings", where: { adapter: row.adapter, scope: row.scope, field: row.field }, aad: `trigger_settings|${row.adapter}|${row.scope}|${row.field}`, sealed: Uint8Array.from(Buffer.from(row.sealed, "base64")) });
1069
+ add(() => ({ plane: "trigger_settings", where: { adapter: row.adapter, scope: row.scope, field: row.field }, aad: `trigger_settings|${row.adapter}|${row.scope}|${row.field}`, sealed: Uint8Array.from(Buffer.from(row.sealed, "base64")) }));
1055
1070
  }
1056
1071
  for (const row of await db.all("SELECT agent_id, provider, pointer_sealed FROM sign_ins ORDER BY agent_id, provider")) {
1057
- out.push({ plane: "sign_ins", where: { agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) });
1072
+ add(() => ({ plane: "sign_ins", where: { agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) }));
1058
1073
  }
1059
1074
  // A tombstone keeps the pointer's sealed bytes under the live row's binding (store/seal.ts signIn).
1060
1075
  for (const row of await db.all("SELECT id, agent_id, provider, pointer_sealed FROM sign_in_tombstones ORDER BY id")) {
1061
- out.push({ plane: "sign_in_tombstones", where: { id: String(row.id), agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) });
1076
+ add(() => ({ plane: "sign_in_tombstones", where: { id: String(row.id), agentId: row.agent_id, provider: row.provider }, aad: aadOf(sealedAt.signIn(row.agent_id, row.provider)), sealed: bytes(row.pointer_sealed) }));
1062
1077
  }
1063
1078
  for (const row of await db.all("SELECT run_id, kind, tag, sealed FROM computer_viewers ORDER BY run_id, kind, tag")) {
1064
- out.push({ plane: "computer_viewers", where: { runId: row.run_id, kind: row.kind, tag: row.tag }, aad: aadOf(sealedAt.liveViewer(row.run_id, row.kind, row.tag)), sealed: bytes(row.sealed) });
1079
+ add(() => ({ plane: "computer_viewers", where: { runId: row.run_id, kind: row.kind, tag: row.tag }, aad: aadOf(sealedAt.liveViewer(row.run_id, row.kind, row.tag)), sealed: bytes(row.sealed) }));
1065
1080
  }
1066
1081
  for (const row of await db.all("SELECT run_id, sealed FROM run_launch WHERE sealed IS NOT NULL ORDER BY run_id")) {
1067
- out.push({ plane: "run_launch", where: { runId: row.run_id }, aad: aadOf({ table: "run_launch", row: row.run_id, column: "sealed" }), sealed: bytes(row.sealed) });
1082
+ add(() => ({ plane: "run_launch", where: { runId: row.run_id }, aad: aadOf({ table: "run_launch", row: row.run_id, column: "sealed" }), sealed: bytes(row.sealed) }));
1068
1083
  }
1069
1084
  return out;
1070
1085
  },
@@ -818,6 +818,9 @@ export interface Settings {
818
818
  get(key: string): Promise<unknown | undefined>;
819
819
  /** Saves `value` (JSON) under `key`, inserted or replaced in place. */
820
820
  put(key: string, value: unknown): Promise<void>;
821
+ /** Saves `value` under `key` only when the key has no row yet, in one statement, so of two processes that race the first
822
+ * wins; the value saved under it after (this one, or the one there before). */
823
+ putIfAbsent(key: string, value: unknown): Promise<unknown>;
821
824
  /** The key's row goes; a key with no row is left as it is. */
822
825
  remove(key: string): Promise<void>;
823
826
  /** Every setting, by key. */
@@ -25,6 +25,22 @@ export declare function withPaidCosts(entries: readonly EntryLike[]): EntryLike[
25
25
  * rendering existed, never a $0/unknown usage row. The end-of-run turn's rows are labelled as the server labels them
26
26
  * (learning-run.ts labelled). */
27
27
  export declare function runTimeline(store: Store, runId: string, context: Context, options?: TimelineOptions): Promise<TimelineEvent[]>;
28
+ /** How a reader serves an answer whole: its redactor over the whole text (key-refusal.ts redactedAnswer with the run's
29
+ * values), and a key for those values (their digest), so an answer is read once per held value set. */
30
+ export type WholeAnswer = {
31
+ readonly serve: (text: string) => string;
32
+ readonly key: string;
33
+ };
34
+ /** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
35
+ export declare const wholeAnswerFor: (values: readonly string[]) => WholeAnswer;
36
+ /** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
37
+ * cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
38
+ * shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
39
+ * "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
40
+ * from the journal, settled as the rows were, with no text cap and none
41
+ * of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
42
+ * of it and never cuts. Every other row is as it was. */
43
+ export declare function wholeAnswers(store: Store, runId: string, context: Context, rows: TimelineEvent[], options: TimelineOptions, whole: WholeAnswer): Promise<TimelineEvent[]>;
28
44
  /** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
29
45
  * user entry noted in log order, its origin read by the same matcher. */
30
46
  export declare function runHearing(store: Store, runId: string, context: Context): Promise<Hearing>;
@@ -1,7 +1,13 @@
1
- import { timelineOf, TOOL_COST } from "@parcha/pi-durable-agent/timeline";
1
+ // The reads the server made from a run's own database, now from A's journal (store.readJournal): a run's entries in log
2
+ // order, its timeline (the renderer unchanged), and what was said to it (its hearing). The old path read each run's
3
+ // its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
4
+ // The renderer and the hearing keep their words; only where the entries come from changes.
5
+ import { createHash } from "node:crypto";
6
+ import { CAPS, timelineOf, TOOL_COST } from "@parcha/pi-durable-agent/timeline";
2
7
  import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
3
8
  import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
4
9
  import { Hearing } from "../heard.js";
10
+ import { redactedAnswer } from "../key-refusal.js";
5
11
  import { labelled } from "../learning-run.js";
6
12
  import { reflectFrom } from "../runner/end-of-run.js";
7
13
  import { journalEntries, journalRecords } from "../runner/journal-reader.js";
@@ -30,21 +36,23 @@ export async function runReflect(store, runId, context) {
30
36
  function piShaped(entries) {
31
37
  return entries.map((entry) => {
32
38
  const data = (entry.data ?? {});
39
+ // When the record's entry was written (`at`), as pi's own message carries its timestamp: the Timeline dates the row by it.
40
+ const timestamp = typeof data.at === "number" ? { timestamp: data.at } : {};
33
41
  if (entry.kind === KINDS.message) {
34
42
  const text = typeof data.text === "string" ? data.text : "";
35
43
  if (data.role === "person")
36
- return { ...entry, kind: "pi.user", model: [{ role: "user", content: text }] };
44
+ return { ...entry, kind: "pi.user", model: [{ role: "user", content: text, ...timestamp }] };
37
45
  // A model turn's text; its stop reason is the answer's (a cut at the output limit reads "length", as pi's does).
38
46
  const stopReason = data.stopReason === "length" ? "length" : "stop";
39
- return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason, content: [{ type: "text", text }], ...(typeof data.outputTokens === "number" ? { usage: { output: data.outputTokens } } : {}) }] };
47
+ return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason, content: [{ type: "text", text }], ...(typeof data.outputTokens === "number" ? { usage: { output: data.outputTokens } } : {}), ...timestamp }] };
40
48
  }
41
49
  if (entry.kind === KINDS.callStart) {
42
- return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }] }] };
50
+ return { ...entry, kind: "pi.assistant", model: [{ role: "assistant", stopReason: "tool_use", content: [{ type: "toolCall", id: String(data.callId ?? ""), name: String(data.tool ?? "tool"), arguments: data.input ?? {} }], ...timestamp }] };
43
51
  }
44
52
  if (entry.kind === KINDS.callEnd) {
45
53
  // A call that did not finish done is an error result, as a failed pi tool call is; its output is the result's text.
46
54
  const failed = data.status !== undefined && data.status !== "done";
47
- return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content: data.output ?? "", ...(failed ? { isError: true } : {}) }] };
55
+ return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content: data.output ?? "", ...(failed ? { isError: true } : {}), ...timestamp }] };
48
56
  }
49
57
  return entry;
50
58
  });
@@ -108,7 +116,75 @@ export async function runTimeline(store, runId, context, options = {}) {
108
116
  const entries = await runEntries(store, runId, context);
109
117
  const cli = entries.some((entry) => entry.kind === KINDS.message || entry.kind === KINDS.callStart || entry.kind === KINDS.callEnd);
110
118
  const rows = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), options).filter((row) => !cli || row.kind !== "usage");
111
- return labelled((await runReflect(store, runId, context)), rows);
119
+ return labelled((await runReflect(store, runId, context)), await datedRows(store, runId, rows));
120
+ }
121
+ /** `rows` with none dated 1970: a row the renderer found no time for (an entry of a CLI record written before its entries
122
+ * carried `at`; the store's entry rows keep no write time of their own) reads the run's start, the earliest time it can
123
+ * have, never epoch 0. Every other row is as the renderer dated it. */
124
+ async function datedRows(store, runId, rows) {
125
+ if (!rows.some((row) => Date.parse(row.timestamp) === 0))
126
+ return rows;
127
+ const run = await store.runs.get(runId);
128
+ if (!run)
129
+ return rows;
130
+ const started = new Date(run.startedAt).toISOString();
131
+ return rows.map((row) => (Date.parse(row.timestamp) === 0 ? { ...row, timestamp: started, created_at: started } : row));
132
+ }
133
+ /** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
134
+ export const wholeAnswerFor = (values) => ({
135
+ serve: (text) => redactedAnswer(text, values),
136
+ key: createHash("sha256").update(JSON.stringify([...values].sort())).digest("hex"),
137
+ });
138
+ /** What each store's readers last served of a cut answer row, by run, row and held value set: a console polls a run's
139
+ * view and its Timeline, and an answer a run was made to write can be large (main's runs.ts servedOnce). A row is an
140
+ * entry's, whose words never change. Kept by store, the newest ANSWERS_KEPT of each. */
141
+ const answersServed = new WeakMap();
142
+ const ANSWERS_KEPT = 32;
143
+ /** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
144
+ * cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
145
+ * shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
146
+ * "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
147
+ * from the journal, settled as the rows were, with no text cap and none
148
+ * of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
149
+ * of it and never cuts. Every other row is as it was. */
150
+ export async function wholeAnswers(store, runId, context, rows, options, whole) {
151
+ // The rows' redactor gives exactly "[redacted]" for a text whose head it read was all held or secret-shaped values: the
152
+ // rest of the answer is past what it read, so that row is read again too.
153
+ const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
154
+ if (!rows.some(cut))
155
+ return rows;
156
+ let kept = answersServed.get(store);
157
+ if (!kept)
158
+ answersServed.set(store, (kept = new Map()));
159
+ const keyOf = (row) => `${runId}\0${row.id}\0${whole.key}`;
160
+ let uncut;
161
+ const out = [];
162
+ for (const row of rows) {
163
+ if (!cut(row)) {
164
+ out.push(row);
165
+ continue;
166
+ }
167
+ const key = keyOf(row);
168
+ let served = kept.get(key);
169
+ if (served === undefined) {
170
+ uncut ??= new Map((await runTimeline(store, runId, context, { settled: options.settled, caps: { ...options.caps, text: Number.POSITIVE_INFINITY } })).map((one) => [one.id, one.text]));
171
+ const text = uncut.get(row.id);
172
+ if (text === undefined || text === null) {
173
+ out.push(row);
174
+ continue;
175
+ }
176
+ served = whole.serve(text);
177
+ kept.delete(key);
178
+ kept.set(key, served);
179
+ for (const oldest of kept.keys()) {
180
+ if (kept.size <= ANSWERS_KEPT)
181
+ break;
182
+ kept.delete(oldest);
183
+ }
184
+ }
185
+ out.push({ ...row, text: served });
186
+ }
187
+ return out;
112
188
  }
113
189
  /** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
114
190
  * user entry noted in log order, its origin read by the same matcher. */
@@ -14,7 +14,7 @@ import { reflects } from "./learning-run.js";
14
14
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
15
15
  import { KINDS } from "./runner/journal-kinds.js";
16
16
  import { notesReadOf, runLearningEnd, withNotes } from "./store-reads/learning.js";
17
- import { runReflect, runTimeline } from "./store-reads/journal.js";
17
+ import { runReflect, runTimeline, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
18
18
  import { readRun } from "./store-reads/runs.js";
19
19
  import { runCutValues, runErrorWordsOf } from "./run-cut.js";
20
20
  import { Turns } from "./turns.js";
@@ -30,6 +30,30 @@ const STATUS_OF = { completed: "completed", failed: "failed", escalated: "comple
30
30
  /** A run that has reached a last state (its view is its ended shape). */
31
31
  const TERMINAL = new Set(["completed", "failed", "cancelled"]);
32
32
  const iso = (ms) => new Date(ms).toISOString();
33
+ /** What a view last served of each run's answer, by store and run: the answer it read (`input`), the digest of the values
34
+ * it was redacted of (`key`) and what that gave (`out`), so a second view of the same answer and values reads nothing
35
+ * again (main's runs.ts servedOnce: a console polls a run's view, and an answer can be large). Newest SERVED_KEPT runs of
36
+ * each store. */
37
+ const servedByStore = new WeakMap();
38
+ const SERVED_KEPT = 32;
39
+ function servedOnce(store, runId, input, values) {
40
+ let served = servedByStore.get(store);
41
+ if (!served)
42
+ servedByStore.set(store, (served = new Map()));
43
+ const key = wholeAnswerFor(values).key;
44
+ const last = served.get(runId);
45
+ if (last && last.key === key && last.input === input)
46
+ return last.out;
47
+ const out = redactedAnswer(input, values);
48
+ served.delete(runId);
49
+ served.set(runId, { input, key, out });
50
+ for (const oldest of served.keys()) {
51
+ if (served.size <= SERVED_KEPT)
52
+ break;
53
+ served.delete(oldest);
54
+ }
55
+ return out;
56
+ }
33
57
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's. */
34
58
  const answerOf = (rows) => rows.findLast((r) => r.kind === "final_answer" && r.agent_label !== LEARNING_LABEL)?.text ?? null;
35
59
  /** A failed run's error from its row (its own words are the summary; the store keeps no code or detail apart). */
@@ -82,7 +106,9 @@ async function storeRunOf(store, runId, deps) {
82
106
  const terminal = row.state !== "running";
83
107
  // The timeline, then the waiting row a run asking a question shows (withAsks), as the file path's rows carried it, so a
84
108
  // run waiting on a question reads the same status and pending.
85
- const timeline = withAsks(await runTimeline(store, runId, context, { settled: terminal, redact: (text) => redacted(text, values) }));
109
+ // Its final answer whole (store-reads/journal.ts wholeAnswers), as main served a run's answer: a row's cut is no answer's.
110
+ const timelineOptions = { settled: terminal, redact: (text) => redacted(text, values) };
111
+ const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
86
112
  const revisions = await store.agents.revisions(row.agent);
87
113
  const version = revisions.findIndex((r) => r.id === row.revision) + 1;
88
114
  const ended = await runLearningEnd(store, runId);
@@ -115,7 +141,11 @@ async function storeRunOf(store, runId, deps) {
115
141
  // The rows a person reads: each call that waited for approval in order (held, your approval, what came of it), its
116
142
  // arguments and the person's notes through the run's redactor, as the file path's withApprovals served them.
117
143
  const rows = withApprovalRows(timeline, approvals, answers, redactorOf(values));
118
- const meta = { ...(launch?.maxCostUsd !== undefined ? { max_cost_usd: launch.maxCostUsd } : {}), ...(Object.keys(answers).length ? { approvals: answers } : {}) };
144
+ // The run's cap as it stands: its newest raise's (the agentrun.raise entries the runner's loop holds it to, adapter-loop
145
+ // capNow), else its launch's; a raise taken shows in the run's cost.cap_usd and its budget card, never the old cap.
146
+ const raisedCapUsd = records.entries.findLast((entry) => entry.kind === KINDS.raise && typeof entry.data?.capUsd === "number" && entry.data.capUsd > 0)?.data;
147
+ const capUsd = launch?.maxCostUsd === undefined ? undefined : Math.max(launch.maxCostUsd, raisedCapUsd?.capUsd ?? 0);
148
+ const meta = { ...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}), ...(Object.keys(answers).length ? { approvals: answers } : {}) };
119
149
  // The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
120
150
  // raise clears it). Read over the same meta cap and rows the card's figures and time come from.
121
151
  const budget = budgetOf(records.entries, { meta, rows, updatedAt: iso(updatedAtMs) });
@@ -191,7 +221,8 @@ function costOfView(run) {
191
221
  const stored = run.row.state === "running" ? undefined : run.runRow.costUsd;
192
222
  const usd = imported ? (stored ?? null) : costView(run.rows, stored, undefined);
193
223
  const soFar = usd === null && !imported ? soFarOf(run.rows) : undefined;
194
- const cap = run.launch?.maxCostUsd;
224
+ // The run's cap as it stands (its view's meta: the newest raise's, else the launch's).
225
+ const cap = run.view.meta.max_cost_usd;
195
226
  const bound = cap === undefined ? {} : { overshoot_bound_usd: 0 };
196
227
  return { usd, basis: "estimate", charge_state: null, cap_usd: cap ?? null, ...bound, ...(soFar ?? {}) };
197
228
  }
@@ -205,7 +236,9 @@ export async function viewOverStore(store, runId, deps) {
205
236
  const terminal = TERMINAL.has(status);
206
237
  const endedAtMs = terminal ? (runRow.endedAt ?? runRow.startedAt) : null;
207
238
  const shownWords = (text) => withoutLoopback(redacted(text, values));
208
- const servedAnswer = (text) => (text ? redactedAnswer(text, values) : text);
239
+ // The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
240
+ // was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
241
+ const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values) : text);
209
242
  const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
210
243
  // A workflow run's output, as its end kept it, served as runs.ts serves it (servedOutput): each string in it cut of the
211
244
  // values the run holds, its shape kept; none while the run's sign-in can't be read back. An agentic run has none.
@@ -63,9 +63,10 @@ export declare function unlockedBy(candidates: readonly string[], tools: readonl
63
63
  };
64
64
  /** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
65
65
  * kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
66
- * (`offers`, harness.ts' harnessOffers) or would once its key is set: one unavailable only for want of a model key
67
- * among whose `keys` is the row's (its first field). So OpenRouter's row names all three before any key is saved; a
68
- * harness not installed, off its pins or too big for this host is left out. */
66
+ * (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
67
+ * now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
68
+ * is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
69
+ * for this host is left out. */
69
70
  export declare function rowUnlocks(row: {
70
71
  kind: string;
71
72
  unlocks: readonly string[];
package/dist/tool-keys.js CHANGED
@@ -60,14 +60,17 @@ export function unlockedBy(candidates, tools, providers) {
60
60
  }
61
61
  /** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
62
62
  * kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
63
- * (`offers`, harness.ts' harnessOffers) or would once its key is set: one unavailable only for want of a model key
64
- * among whose `keys` is the row's (its first field). So OpenRouter's row names all three before any key is saved; a
65
- * harness not installed, off its pins or too big for this host is left out. */
63
+ * (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
64
+ * now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
65
+ * is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
66
+ * for this host is left out. */
66
67
  export function rowUnlocks(row, tools, providers, offers) {
67
68
  if (row.kind === "tool")
68
69
  return unlockedBy(row.unlocks, tools, providers);
69
70
  const key = row.fields?.[0];
70
- const runs = (harness) => offers.some((offer) => offer.id === harness && (offer.available || (key !== undefined && offer.keys?.includes(key) === true)));
71
+ // Where an offer knows which model keys run it (its `keys`), the row's key must be one of them, available now or not;
72
+ // else (no key runs it: pi on any, or one unavailable for another reason) whether it runs here now.
73
+ const runs = (harness) => offers.some((offer) => offer.id === harness && (offer.keys ? key !== undefined && offer.keys.includes(key) : offer.available));
71
74
  return { unlocks: [], harnesses: HARNESSES.filter((harness) => (row.harnesses ?? HARNESSES).includes(harness) && runs(harness)) };
72
75
  }
73
76
  /** The key that unlocks the tool `name` (capabilities' `tools[].key`, so a page links "needs the X key" to it), if any. */
package/dist/tools.d.ts CHANGED
@@ -251,7 +251,7 @@ export declare function toolRefusal(names: readonly string[], env: NodeJS.Proces
251
251
  * saying that. Each tool also gives its permission under the server's settings (tool-gate.ts), the owner's default
252
252
  * and the permissions it may be set to. */
253
253
  export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettingsMap, noBox?: string, refused?: Readonly<Record<string, string>>) => {
254
- providers?: ("auto" | "native" | "off" | "parallel" | "browserbase" | "kernel" | "exa-keyless" | "chrome")[] | undefined;
254
+ providers?: ("auto" | "native" | "parallel" | "browserbase" | "kernel" | "off" | "exa-keyless" | "chrome")[] | undefined;
255
255
  provider?: string | undefined;
256
256
  default_provider?: "auto" | "kernel" | undefined;
257
257
  resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", import("./tool-plane.js").Resolution> | undefined;
package/dist/tools.js CHANGED
@@ -227,7 +227,10 @@ const browserTool = {
227
227
  summary: "Drive a hosted browser, Browserbase's or Kernel's (picked in tool settings, else whichever's key the server holds): open pages, read and screenshot them, and act on them.",
228
228
  // Which vendor's keys it needs is the plane's to say (tool-plane.ts BROWSER_KEYS): neither alone is required.
229
229
  needs: [],
230
- nodes: true,
230
+ // No workflow model node takes it (#2098): the runner, where every run goes, binds the browser for an agentic run alone
231
+ // (its reconcile, its release and drain, its live view hang off that run's lifecycle). A node naming it is refused when
232
+ // its definition is saved (runnable.ts), never accepted and then failed at its run.
233
+ nodes: false,
231
234
  // Its downloads and uploads go through work/ by path (pi-browser), which a box's command could turn through a link.
232
235
  runnerOnly: true,
233
236
  bind: async (host) => {
@@ -73,8 +73,9 @@ export const schedule = {
73
73
  if (given === undefined)
74
74
  return bad("at", "invalid", "at is an RFC 3339 date-time with its offset"), undefined;
75
75
  const at = Math.floor(given / 1000) * 1000;
76
+ // In words a person reads, on the field (the console's time field; an SDK user's error), never the raw field name.
76
77
  if (at <= now)
77
- return bad("at", "invalid", "at is in the past"), undefined;
78
+ return bad("at", "invalid", `Pick a time in the future: ${second(at)} has already passed.`), undefined;
78
79
  return { kind: "schedule", at: second(at) };
79
80
  }
80
81
  issues.push(...unknownSourceFields(value, ["kind", "every_s", "start_at"]));
@@ -73,5 +73,9 @@ export function templateApplied(body, minted, shown) {
73
73
  if (!made)
74
74
  return body;
75
75
  const said = (one) => shown === "first" && minted.has(one.trigger_id) ? { ...one, signing_secret: minted.get(one.trigger_id) } : { ...one, secret_set: true, note: shown === "replay" ? TEMPLATE_SECRET_SHOWN : TRIGGER_SECRET_WORDS };
76
- return { ...body, webhook_secrets: made.map(said) };
76
+ // The answer that shows every secret drops the warnings saying it is not shown (templateTriggerSecret's): they would
77
+ // sit right above the secret they say is missing. A token's answer or a replay keeps them.
78
+ const showsAll = shown === "first" && made.every((one) => minted.has(one.trigger_id));
79
+ const warnings = showsAll && Array.isArray(body.warnings) ? { warnings: body.warnings.filter((w) => !/^triggers\.\d+\.secret$/.test(String(w.field))) } : {};
80
+ return { ...body, ...warnings, webhook_secrets: made.map(said) };
77
81
  }
@@ -1,3 +1,6 @@
1
+ import { type DockerVolume } from "@parcha/agentrun-computer";
2
+ import type { DockerPaths } from "../box-paths.js";
3
+ import { type HostRead } from "../docker-host-addresses.js";
1
4
  import type { ProviderFactories } from "../computer-keys.js";
2
5
  import type { FauxComputers } from "../faux-computers.js";
3
6
  import { type KeyEnv } from "../key-meta.js";
@@ -8,6 +11,25 @@ import type { KindRegistry } from "./resolve-computer.js";
8
11
  /** How long a run's computer lives whatever happens to the server: a bound on a leaked one, never its clean end (the old
9
12
  * box's lifetime). The clean end is the run's release. */
10
13
  export declare const COMPUTER_LIFETIME_MS: number;
14
+ /** The Docker host's own addresses, for a Docker provider whose interfaces aren't that host's (the server in a
15
+ * container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
16
+ * computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
17
+ export declare const DOCKER_HOST_ADDRESSES_ENV = "AGENTRUN_DOCKER_HOST_ADDRESSES";
18
+ /** `env`'s AGENTRUN_DOCKER_HOST_ADDRESSES: its addresses, each once; undefined when unset or empty, never one made up.
19
+ * An entry that is not an IP address throws, naming it: the server's start checks the setting, so no run meets one. */
20
+ export declare function dockerHostAddressesOf(env: KeyEnv): string[] | undefined;
21
+ /** Where the Docker provider's daemon copy goes on a server in a container: under the named volume's mount, so the
22
+ * host's Docker reaches it as that volume's subpath, as it reaches the run's folder. */
23
+ export declare const DAEMON_CACHE_IN_VOLUME = ".agentrun/computerd";
24
+ /** The Docker provider's options for a server in a container of its Docker's, its data on a named volume: the volume
25
+ * and where it is mounted here (`root`), under which the run's folder and the daemon copy are mounted as the volume's
26
+ * subpaths, and that daemon copy's place under it. Undefined on a host, or where no such volume was found (its reason
27
+ * then refuses a Docker computer before a run, box-paths.ts dockerComputerRefusal). */
28
+ export type DockerComputerOptions = {
29
+ readonly volume: DockerVolume;
30
+ readonly daemonCache: string;
31
+ };
32
+ export declare function dockerVolumeOf(paths: DockerPaths): DockerComputerOptions | undefined;
11
33
  /** The deps computerForClaim takes once per process: all but the claim's own. */
12
34
  export type ComputerDeps = Omit<ComputerForClaimDeps, "mode" | "workspace" | "sealKey" | "revokeMount" | "signal">;
13
35
  export interface ComputerDepsOptions {
@@ -22,6 +44,13 @@ export interface ComputerDepsOptions {
22
44
  readonly kinds?: KindRegistry;
23
45
  /** How a provider is built from its id and options: the package's providerFor unless given (a test's stand-in). */
24
46
  readonly load?: ProviderLoad;
47
+ /** Where this process's Docker has the data directory (box-paths.ts dockerPathsForRuns), read once when a Docker
48
+ * provider is first built: in a container with a named data volume, the provider mounts by that volume
49
+ * (dockerVolumeOf). Absent: as on a host. */
50
+ readonly dockerPaths?: () => Promise<DockerPaths>;
51
+ /** The Docker host's own addresses, read through its socket (docker-host-addresses.ts hostAddressesOnce), for a server
52
+ * in a container of its Docker's: unioned with AGENTRUN_DOCKER_HOST_ADDRESSES. Absent: the operator's alone. */
53
+ readonly hostAddresses?: () => Promise<HostRead>;
25
54
  /** Whether a provider that binds a folder of this machine answers here now (Docker), for the Mode 1 default. */
26
55
  readonly answers?: ComputerForClaimDeps["answers"];
27
56
  /** The live view's registration for a desktop or a phone (proxy-only): absent, no view is opened. */
@@ -14,8 +14,11 @@
14
14
  //
15
15
  // A key goes into the server-side provider call alone (the provider's create() options): the spec a computer is made
16
16
  // with names no key, no account key and no database or Redis credential, and carries no environment at all.
17
+ import { isIP } from "node:net";
18
+ import { posix } from "node:path";
17
19
  import { DEFAULT_DOCKER_IMAGE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, PROVIDERS, providerFor, readBackOf, servingRefusals, SETTING_KINDS } from "@parcha/agentrun-computer";
18
20
  import { DOCKER_IMAGE_ENV } from "../box-image.js";
21
+ import { unionOf } from "../docker-host-addresses.js";
19
22
  import { envValue, keyReader } from "../key-meta.js";
20
23
  import { readLaunchBody } from "../run-launch.js";
21
24
  import { computerForClaim } from "./computer-for-claim.js";
@@ -26,6 +29,31 @@ import { computerProviderFactories, computerProviderMakers } from "./computer-pr
26
29
  export const COMPUTER_LIFETIME_MS = 24 * 60 * 60_000;
27
30
  /** A computer this server cannot make here, with the code the run fails with and its words. */
28
31
  const refused = (words) => Object.assign(new Error(words), { code: "computer_unavailable" });
32
+ /** The Docker host's own addresses, for a Docker provider whose interfaces aren't that host's (the server in a
33
+ * container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
34
+ * computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
35
+ export const DOCKER_HOST_ADDRESSES_ENV = "AGENTRUN_DOCKER_HOST_ADDRESSES";
36
+ /** `env`'s AGENTRUN_DOCKER_HOST_ADDRESSES: its addresses, each once; undefined when unset or empty, never one made up.
37
+ * An entry that is not an IP address throws, naming it: the server's start checks the setting, so no run meets one. */
38
+ export function dockerHostAddressesOf(env) {
39
+ const value = envValue(env, DOCKER_HOST_ADDRESSES_ENV);
40
+ if (value === undefined)
41
+ return undefined;
42
+ const addresses = [...new Set(value.split(",").map((one) => one.trim()).filter((one) => one !== ""))];
43
+ const bad = addresses.find((one) => isIP(one) === 0);
44
+ if (bad !== undefined)
45
+ throw new Error(`${DOCKER_HOST_ADDRESSES_ENV} is a comma list of the Docker host's own IP addresses (such as 172.17.0.1): ${JSON.stringify(bad)} is not an IP address`);
46
+ return addresses.length > 0 ? addresses : undefined;
47
+ }
48
+ /** Where the Docker provider's daemon copy goes on a server in a container: under the named volume's mount, so the
49
+ * host's Docker reaches it as that volume's subpath, as it reaches the run's folder. */
50
+ export const DAEMON_CACHE_IN_VOLUME = ".agentrun/computerd";
51
+ export function dockerVolumeOf(paths) {
52
+ if (!("paths" in paths))
53
+ return undefined;
54
+ const root = paths.paths.at;
55
+ return { volume: { name: paths.paths.volume, root }, daemonCache: posix.join(root, DAEMON_CACHE_IN_VOLUME) };
56
+ }
29
57
  /** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (Docker's: the
30
58
  * owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox the package's recipe; any other provider's: its registry
31
59
  * entry's defaultImage for the kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in
@@ -95,8 +123,27 @@ export function computerDepsFrom(options) {
95
123
  // recipe's bare tag, which no registry has.
96
124
  const named = envValue(env, DOCKER_IMAGE_ENV);
97
125
  const dockerImage = named !== undefined ? { image: named } : { recipe: DOCKER_RECIPE };
126
+ // The operator's Docker host addresses (AGENTRUN_DOCKER_HOST_ADDRESSES), checked once here.
127
+ const namedAddresses = dockerHostAddressesOf(env);
128
+ // Where this process's Docker has the data, read once, when a Docker provider is first built.
129
+ let paths;
130
+ /** The Docker provider's options beside its image: for a server in a container of its Docker's, the named volume that
131
+ * holds its data and the daemon copy's place under it (dockerVolumeOf), and the Docker host's own addresses for its
132
+ * egress proxy, the union of the read through the socket (`hostAddresses`) and the operator's; on a host, the
133
+ * operator's alone (the provider reads its own interfaces). With none, none are given, and the provider refuses an
134
+ * allow-list where it isn't on the Docker host, in its words. The read is made only for a claim whose run's computer
135
+ * has an allow-list (`boxAllow`, the claim's own launch's box_allow, a list): a run launched under a list keeps it
136
+ * across a restart, whatever this process's AGENTRUN_BOX_ALLOW says now; one with none, or no claim, reads nothing.
137
+ * The read itself is once per process (`hostAddresses`). */
138
+ const dockerOptions = async (boxAllow) => {
139
+ const where = options.dockerPaths ? await (paths ??= options.dockerPaths()) : { here: true };
140
+ const volume = dockerVolumeOf(where);
141
+ const read = volume && Array.isArray(boxAllow) && options.hostAddresses ? await options.hostAddresses() : undefined;
142
+ const addresses = read ? unionOf(read, namedAddresses).addresses : (namedAddresses ?? []);
143
+ return { image: dockerImage, ...(volume ?? {}), ...(addresses.length > 0 ? { egress: { hostAddresses: addresses } } : {}) };
144
+ };
98
145
  const load = options.load ?? providerFor;
99
- const providers = computerProviderMakers({ load: (id, given) => load(id, id === "docker" ? { ...given, image: dockerImage } : given) });
146
+ const providers = computerProviderMakers({ load: async (id, given, claim) => load(id, id === "docker" ? { ...given, ...(await dockerOptions(claim?.boxAllow)) } : given) });
100
147
  const computerDeps = {
101
148
  kinds,
102
149
  providers,
@@ -30,10 +30,14 @@ export interface ComputerRun {
30
30
  readonly maxLifetimeMs?: number;
31
31
  }
32
32
  /** A provider module's create(), by provider id: its options from the saved keys, and the store's ledger for a provider
33
- * that keeps one (the phone's `ledger` option). The computer package's providers, or a test's stand-in. */
34
- export type ProviderMakers = Readonly<Partial<Record<string, (options: Record<string, string>, extras: {
33
+ * that keeps one (the phone's `ledger` option); for a claim, what its run's computer may reach (`boxAllow`, the
34
+ * launch's box_allow), which no provider option carries. The computer package's providers, or a test's stand-in. */
35
+ export type ProviderMakers = Readonly<Partial<Record<string, (options: Record<string, string>, extras: ProviderExtras) => ComputerProvider | Promise<ComputerProvider>>>>;
36
+ /** What a provider is made with beside its options: the store's ledger, and the claim's box_allow when a claim makes it. */
37
+ export type ProviderExtras = {
35
38
  readonly ledger: ProviderLedger;
36
- }) => ComputerProvider | Promise<ComputerProvider>>>>;
39
+ readonly boxAllow?: readonly string[] | "none";
40
+ };
37
41
  /** Why a live view ends: the computer was released, or the run ended. */
38
42
  export type ViewEnd = "released" | "ended";
39
43
  /** The live view of a desktop or a phone, proxy-only, as its registration (computer-live.ts
@@ -117,7 +117,7 @@ export async function computerForClaim(launch, store, deps) {
117
117
  const options = providerOptions(entry.id, keys, deps.settings ?? {}, table);
118
118
  if (!options.ok)
119
119
  throw new Error(options.error.message);
120
- const provider = await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) });
120
+ const provider = await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id), ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }) });
121
121
  // What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
122
122
  // (computer-deps.ts computerSpecOf).
123
123
  const { network: networks, maxLifetimeMs } = provider.capabilities();
@@ -1,8 +1,12 @@
1
1
  import { type ComputerProvider } from "@parcha/agentrun-computer";
2
2
  import type { ProviderFactories } from "../computer-keys.js";
3
3
  import type { ProviderMakers } from "./computer-for-claim.js";
4
- /** How a provider is built from its id and options: the computer package's providerFor, or a test's stand-in. */
5
- export type ProviderLoad = (id: string, options: Record<string, unknown>) => Promise<ComputerProvider>;
4
+ /** How a provider is built from its id and options: the computer package's providerFor, or a test's stand-in. `claim`:
5
+ * what the claim that makes it lets its run's computer reach (the launch's box_allow), absent outside a claim; never a
6
+ * provider option. */
7
+ export type ProviderLoad = (id: string, options: Record<string, unknown>, claim?: {
8
+ readonly boxAllow?: readonly string[] | "none";
9
+ }) => Promise<ComputerProvider>;
6
10
  /** Settings → Computers' factories (createComputerRoutes' `factories`, its account test) from the same makers, so serve
7
11
  * builds a provider in one place: each made with its options and `ledgerOf` its id's ledger. */
8
12
  export declare function computerProviderFactories(makers: ProviderMakers, ledgerOf: (id: string) => unknown): ProviderFactories;
@@ -12,6 +12,6 @@ export function computerProviderFactories(makers, ledgerOf) {
12
12
  export function computerProviderMakers({ load = providerFor } = {}) {
13
13
  return Object.fromEntries(providerIds.map((id) => [
14
14
  id,
15
- (options, extras) => load(id, { ...options, ...(id === "phone-harness" ? { ledger: extras.ledger } : {}) }),
15
+ (options, extras) => load(id, { ...options, ...(id === "phone-harness" ? { ledger: extras.ledger } : {}) }, extras.boxAllow === undefined ? {} : { boxAllow: extras.boxAllow }),
16
16
  ]));
17
17
  }
@@ -17,7 +17,7 @@ export { type RunBrowser, type RunComputer, type RunHold, runTools, type RunTool
17
17
  export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
18
18
  export { type ClaimSide, computerReadiness, type ComputerSetting, type ComputerSettingKind, type KindCapabilities, type KindRegistry, type LaunchedComputer, type Port, type ProviderEntry, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
19
19
  export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
20
- export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf } from "./computer-deps.js";
20
+ export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
21
21
  export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ImageWait, type OpenComputerView, type ProviderMakers, sweepComputers, type ViewEnd } from "./computer-for-claim.js";
22
22
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
23
23
  export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind } from "./kind-skills.js";
@@ -19,7 +19,7 @@ export { runTools, withKindTools } from "./run-tools.js";
19
19
  export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
20
20
  export { computerReadiness, resolveComputer, runShellOf, shellPlaceOf, } from "./resolve-computer.js";
21
21
  export { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
22
- export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf } from "./computer-deps.js";
22
+ export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
23
23
  export { computerForClaim, sweepComputers } from "./computer-for-claim.js";
24
24
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
25
25
  export { KIND_SKILLS, kindSkillOf } from "./kind-skills.js";
@@ -69,6 +69,3 @@ export declare function removeWorkFile(work: string, rel: string): Promise<void>
69
69
  /** Throws unless the kernel refuses a hard link to a file the linker cannot write (fs.protected_hardlinks = 1): with a
70
70
  * run's commands under a uid of their own, it keeps them from linking this server's files into their workspace. */
71
71
  export declare function assertHardlinkProtection(read?: () => string): void;
72
- /** Does nothing: the run's host tools file through its Workspace, and nothing copies their files into a remote box any
73
- * more. Kept only so the run's start (app.ts) compiles until its rewrite drops the call. */
74
- export declare function mirrorWrites(_work: string, _mirror: (path: string, data: string | Uint8Array) => Promise<void>): void;