@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
@@ -14,7 +14,7 @@ export interface McpClaimOptions {
14
14
  claim: Pick<Claim, "runId" | "epoch">;
15
15
  /** The run's granted tools, by catalog name (`mcp:<server>/<tool>` among them). */
16
16
  grants: readonly string[];
17
- /** The runner's seal key (the server's): a runner never starts without one (seal-key.ts ensureSealKey). */
17
+ /** The runner's seal key (the server's): a runner never starts without one (seal-key.ts bootSealKey). */
18
18
  sealKey: Buffer;
19
19
  /** The claim's signal: aborted when the claim is lost or the runner stops. */
20
20
  signal: AbortSignal;
@@ -14,7 +14,7 @@
14
14
  // aborts. A credential that can't be used gives its server's calls a reason (mcp-probe.ts UNUSABLE) and they are refused
15
15
  // unsent: sealed under another key or for another origin than its row's url (damaged), a sign-in refused or expired
16
16
  // (signedOut), a refresh that got no answer (silent), an address the check refuses (blocked). A runner never starts
17
- // without the seal key (seal-key.ts ensureSealKey), so a claim always has one.
17
+ // without the seal key (seal-key.ts bootSealKey), so a claim always has one.
18
18
  //
19
19
  // fresh(). After the pin check and before the loop, and again on a command-row resume: an OAuth access token past its
20
20
  // expiry is refreshed, bounded (the call within MCP_REFRESH_CALL_MS; a request not yet dialled within 4 s, and tried again
@@ -145,6 +145,25 @@ export function messagesFetch(models, target, redact = keepText, upstream) {
145
145
  /** pi-ai's stop reason as Messages says it. */
146
146
  const stopReasonOf = (reason) => (reason === "toolUse" ? "tool_use" : reason === "length" ? "max_tokens" : "end_turn");
147
147
  const textOf = (content) => (typeof content === "string" ? content : (content ?? []).filter((block) => block.type === "text").map((block) => block.text ?? "").join("\n"));
148
+ /** A Messages block as pi-ai's part: a text as text, a base64 image as an image; anything else none. */
149
+ const partOf = (block) => block.type === "text" ? [{ type: "text", text: block.text ?? "" }] : block.type === "image" && block.source?.data ? [{ type: "image", data: block.source.data, mimeType: block.source.media_type ?? "image/png" }] : [];
150
+ /** A tool_result's content as pi-ai's toolResult content: its parts in order (partOf), so a screenshot a tool returned
151
+ * reaches the model, with the texts between two images joined by "\n" into one part, so a result of text alone is the
152
+ * one text it always was (textOf). A string is one text. Never empty: a result with no text or image part is one empty
153
+ * text. */
154
+ const resultOf = (content) => {
155
+ if (typeof content === "string" || content === undefined)
156
+ return [{ type: "text", text: content ?? "" }];
157
+ const parts = [];
158
+ for (const part of content.flatMap(partOf)) {
159
+ const last = parts.at(-1);
160
+ if (part.type === "text" && last?.type === "text")
161
+ parts[parts.length - 1] = { type: "text", text: `${String(last.text)}\n${String(part.text)}` };
162
+ else
163
+ parts.push(part);
164
+ }
165
+ return parts.length ? parts : [{ type: "text", text: "" }];
166
+ };
148
167
  /** A Messages request as pi-ai's context on `target`: its system prompt, tools and turns (a tool_result as its own
149
168
  * toolResult message, naming the tool its call named; `providerId` maps a call id back to the provider's). */
150
169
  function contextOf(body, target, providerId) {
@@ -166,10 +185,10 @@ function contextOf(body, target, providerId) {
166
185
  messages.push({ role: "assistant", content, api: target.api, provider: target.provider, model: target.id, usage: zero, stopReason: content.some((part) => part.type === "toolCall") ? "toolUse" : "stop", timestamp: Date.now() });
167
186
  continue;
168
187
  }
169
- const said = blocks.flatMap((block) => block.type === "text" ? [{ type: "text", text: block.text ?? "" }] : block.type === "image" && block.source?.data ? [{ type: "image", data: block.source.data, mimeType: block.source.media_type ?? "image/png" }] : []);
188
+ const said = blocks.flatMap(partOf);
170
189
  for (const block of blocks.filter((each) => each.type === "tool_result")) {
171
190
  const id = block.tool_use_id ?? "";
172
- messages.push({ role: "toolResult", toolCallId: providerId(id), toolName: named.get(id) ?? "", content: [{ type: "text", text: textOf(block.content) }], isError: block.is_error === true, timestamp: Date.now() });
191
+ messages.push({ role: "toolResult", toolCallId: providerId(id), toolName: named.get(id) ?? "", content: resultOf(block.content), isError: block.is_error === true, timestamp: Date.now() });
173
192
  }
174
193
  if (said.length)
175
194
  messages.push({ role: "user", content: said, timestamp: Date.now() });
@@ -1,5 +1,11 @@
1
- /** Text with every secret value the redactor holds cut out. */
2
- export type Redact = (text: string) => string;
1
+ /** Text with every secret value the redactor holds cut out. `heldValues()`, when the redactor knows them: every value it
2
+ * cuts, for the live ticker alone (live-ticker.ts), which must cut what is not whole text (a value still streaming, whose
3
+ * tail is held back; a number; an object's names). A redactor without it cuts text only. The values are raw secrets: only
4
+ * ever a function's answer, never a field, and the function itself is not enumerable (withHeldValues), so a redactor or
5
+ * anything holding one that is logged, put on a run or serialized shows none of them. */
6
+ export type Redact = ((text: string) => string) & {
7
+ readonly heldValues?: () => readonly string[];
8
+ };
3
9
  /** What leaves text as it is: a runner given no secrets to cut. */
4
10
  export declare const keepText: Redact;
5
11
  /** Every secret value `env` holds for the runner: the server's held secrets, the MCP credentials and every key-, token-,
@@ -6,8 +6,13 @@
6
6
  import { redactedAnswer } from "../key-refusal.js";
7
7
  import { MIN_SECRET } from "../learn/secrets.js";
8
8
  import { hostSecrets, SECRET_NAMES } from "../secrets.js";
9
+ /** `cut` answering `heldValues()`, the function defined not enumerable: JSON.stringify and util.inspect of the redactor,
10
+ * or of an object holding it, show no value it holds. */
11
+ function withHeldValues(cut, heldValues) {
12
+ return Object.defineProperty(cut, "heldValues", { value: heldValues, enumerable: false });
13
+ }
9
14
  /** What leaves text as it is: a runner given no secrets to cut. */
10
- export const keepText = (text) => text;
15
+ export const keepText = withHeldValues((text) => text, () => []);
11
16
  /** Every secret value `env` holds for the runner: the server's held secrets, the MCP credentials and every key-, token-,
12
17
  * secret- or password-named value (secrets.ts hostSecrets), and the value `env` itself gives each launcher name (a
13
18
  * runner's key comes in its env, which hostSecrets reads only for names off the launcher's list), with any `extra` a
@@ -21,7 +26,7 @@ export function secretRedactor(values) {
21
26
  const kept = [...new Set(values.filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET))];
22
27
  if (kept.length === 0)
23
28
  return keepText;
24
- return (text) => (text ? redactedAnswer(text, kept) : text);
29
+ return withHeldValues((text) => (text ? redactedAnswer(text, kept) : text), () => kept);
25
30
  }
26
31
  /** The redactor over every secret this process's environment holds (runnerSecrets): a runner's default when it is
27
32
  * handed none, so a runner started with none still cuts the keys it was started with. The one place the runner's
@@ -42,6 +47,10 @@ export function heldRedactor(base) {
42
47
  if (value.replace(/\s+/g, "").length >= MIN_SECRET)
43
48
  held.add(value);
44
49
  };
50
+ // Its values are the base's and every one held since; a base that does not know its own leaves them unknown.
51
+ const known = base.heldValues;
52
+ if (known)
53
+ withHeldValues(cut, () => [...new Set([...known(), ...held])]);
45
54
  return cut;
46
55
  }
47
56
  /** The secrets a claim opened from the store (`env`, claimSecrets' environment for the run) held by `redact`, the run's
@@ -28,14 +28,14 @@ import { forModel } from "../result.js";
28
28
  import { WEB_FETCH_TOOL } from "../web-fetch.js";
29
29
  import { runGate } from "../tool-gate.js";
30
30
  import { callNodeAskText, deniedText, modelNodeAskText } from "../refusal-words.js";
31
- import { loadToolSettings, planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
31
+ import { planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
32
32
  import { AsyncLocalStorage } from "node:async_hooks";
33
33
  import { bookedIn, parallelExtractFee, parallelSearchFee } from "../paid-calls.js";
34
34
  import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
35
35
  import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
36
36
  import { claimSecrets, withModelKeys } from "./claim-secrets.js";
37
37
  import { routeOf } from "./model-route.js";
38
- import { PI_WIRES } from "./adapter-run-spec.js";
38
+ import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
39
39
  import { policyFor } from "./adapters/pi.js";
40
40
  import { sessionProvider } from "../port-models.js";
41
41
  import { journalSessions } from "./sessions.js";
@@ -529,16 +529,12 @@ export const releaseCallHold = async () => {
529
529
  await giveBack(held);
530
530
  };
531
531
  function callPolicyOf(store, runId, claimed) {
532
- let current = { settings: {}, problems: [] };
532
+ // Nothing read yet: unread, so a policy asked before the first read fails closed too.
533
+ let current = { settings: {}, problems: [], unreadable: true };
533
534
  // Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part.
534
535
  const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, undefined, true);
535
536
  return async (tool) => {
536
- try {
537
- current = await loadToolSettings(store);
538
- }
539
- catch {
540
- // Unread: the gate holds to its last good read.
541
- }
537
+ current = await storeSettings(store);
542
538
  return { permission: gate.policy(tool), denyFrom: gate.denyFrom(tool) };
543
539
  };
544
540
  }
@@ -71,7 +71,7 @@ export type SteerCommand = {
71
71
  /** Raises the cap of an agentic or workflow run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the
72
72
  * same as its newest raise (a retry, which changes nothing). A raise command row the run's runner reads: it resumes a run
73
73
  * paused at its cap and sends its continuation, or (for a run working now) holds the raised cap from the run's next
74
- * process, as the old path did. The answer reports whether the run resumed; the runner owns the resume itself. */
74
+ * step. The answer reports whether the run resumed; the runner owns the resume itself. */
75
75
  export declare function raiseCap(store: RunsStore, moment: RunMoment, cap: number): Promise<{
76
76
  resumed: boolean;
77
77
  messageId?: string;
@@ -162,7 +162,7 @@ async function raiseRows(store, runId) {
162
162
  /** Raises the cap of an agentic or workflow run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the
163
163
  * same as its newest raise (a retry, which changes nothing). A raise command row the run's runner reads: it resumes a run
164
164
  * paused at its cap and sends its continuation, or (for a run working now) holds the raised cap from the run's next
165
- * process, as the old path did. The answer reports whether the run resumed; the runner owns the resume itself. */
165
+ * step. The answer reports whether the run resumed; the runner owns the resume itself. */
166
166
  export async function raiseCap(store, moment, cap) {
167
167
  if (moment.importedSource !== undefined)
168
168
  throw importedRefusal(moment);
@@ -179,12 +179,23 @@ export async function raiseCap(store, moment, cap) {
179
179
  }
180
180
  if (!(cap > from + CAP_TOLERANCE))
181
181
  throw invalid([{ field: "max_cost_usd", reason: "invalid", message: `A cap is only raised: name more than the run's ${money(from)}.` }]);
182
- await sendCommand(store, moment.id, { kind: "raise", body: { capUsd: cap } });
183
- // A run paused at its cap is brought back by the raise (its runner claims it and sends its continuation); a run working
184
- // now keeps the cap its process was opened with until its next one.
182
+ try {
183
+ await sendCommand(store, moment.id, { kind: "raise", body: { capUsd: cap } });
184
+ }
185
+ catch (error) {
186
+ // A run a person stopped reads waiting on its next message (its moment is not terminal), but its row takes no command
187
+ // until a message reopens it: refused in words, nothing written. (Main took the raise and held it for the run's next
188
+ // process; that waits for a stopped run's reopen here.)
189
+ if (error instanceof RunFinal && (await store.runs.get(moment.id))?.state === "stopped")
190
+ throw new ApiError("not_continuable", "This run was stopped: send it a message to go on, then raise its cap.");
191
+ throw error;
192
+ }
193
+ // A run paused at its cap is brought back by the raise (its runner claims it and sends its continuation).
185
194
  if (moment.paused)
186
195
  return { resumed: true };
187
- return { resumed: false, ...(moment.live ? { note: `The run's process keeps the ${money(from)} cap it was opened with; the ${money(cap)} cap holds from its next process.` } : {}) };
196
+ // A run its runner holds takes the raise as its next command: its next step is admitted under the raised cap (the
197
+ // runner's loop holds the run to its newest raise), and a step already under way keeps the cap it was admitted at.
198
+ return { resumed: false, ...(moment.live ? { note: `The ${money(cap)} cap holds from the run's next step; a step already under way keeps the ${money(from)} cap it was admitted at.` } : {}) };
188
199
  }
189
200
  /** The refusal for a tool call already answered, in the old runs.ts words, by how it was answered; a withdrawal by a run
190
201
  * that ended (completed or failed, `ended`) says its run ended, never that it was stopped. */
@@ -1,9 +1,19 @@
1
- export declare const SEAL_KEY_DIR = "agentrun";
1
+ import type { Store } from "./store/index.js";
2
+ /** The seal key's own directory in the data directory, and its file there. */
3
+ export declare const SEAL_KEY_DIR = "seal";
2
4
  export declare const SEAL_KEY_FILE = "seal.key";
5
+ /** The store setting that records the key's fingerprint. */
6
+ export declare const SEAL_KEY_SETTING = "seal_key";
7
+ /** The refusal of a store whose secrets another key sealed, word for word. */
8
+ export declare const SEALED_ELSEWHERE = "this store's secrets were sealed with another key; hand the server the original AGENTRUN_SEAL_KEY";
3
9
  /** The server has no seal key it can use, in words: it does not start. */
4
10
  export declare class SealKeyRefused extends Error {
5
11
  name: string;
6
12
  }
13
+ /** The key held is not the one the store's secrets were sealed with: it does not start. */
14
+ export declare class SealKeyNotTheStores extends SealKeyRefused {
15
+ name: string;
16
+ }
7
17
  /** The key, as bytes and as its base64 text; where it is kept (null when it was handed over); whether this start made it. */
8
18
  export type SealKey = {
9
19
  readonly key: Buffer;
@@ -11,20 +21,49 @@ export type SealKey = {
11
21
  readonly path: string | null;
12
22
  readonly generated: boolean;
13
23
  };
14
- /** The config home a seal key is kept under: XDG_CONFIG_HOME, else ~/.config; undefined with neither. */
15
- export declare const sealKeyHome: (env: NodeJS.ProcessEnv) => string | undefined;
16
- /**
17
- * The server's seal key: `given` (AGENTRUN_SEAL_KEY as it was handed) when set, else the one kept under `configHome`,
18
- * made there at the first start. Throws SealKeyRefused, in words, when there is none it can use: the server does not start.
19
- */
20
- export declare function ensureSealKey(given: string | undefined, { configHome }: {
21
- configHome: string | undefined;
24
+ /** A key a start booted: on this process's redaction list (secrets.ts holdSealKey) until release(), which its holder calls
25
+ * as it closes. */
26
+ export type BootedSealKey = SealKey & {
27
+ readonly release: () => void;
28
+ };
29
+ /** Where the data directory `dataDir` keeps its seal key. */
30
+ export declare const sealKeyPath: (dataDir: string) => string;
31
+ /** The key file's rules alone, with no store to check against: `given` (AGENTRUN_SEAL_KEY as it was handed) when set,
32
+ * else the one kept in `dataDir`, made there when there is none. A start never calls this by itself: bootSealKey checks
33
+ * the key against the store first, and makes one only for a store that holds no secret. */
34
+ export declare function ensureSealKey(given: string | undefined, { dataDir }: {
35
+ dataDir: string;
22
36
  }): SealKey;
37
+ /** The fingerprint the store records of `key`: an HMAC of a fixed label under it. Neither the key nor a hash of it alone. */
38
+ export declare const sealKeyFingerprint: (key: Buffer) => string;
39
+ /** The store slice the check reads and writes. */
40
+ export type SealKeyStore = Pick<Store, "settings" | "sealedSecrets">;
41
+ /** Who boots the key: the server's start makes one for a store that holds no secret and records its fingerprint, and so
42
+ * does the import, which sets a data directory up as the server does (never its dry run); a runner only reads one and
43
+ * checks it. */
44
+ export type SealKeyRole = "server" | "runner" | "import";
45
+ export interface BootSealKeyOptions {
46
+ /** AGENTRUN_SEAL_KEY as this process was handed it (secrets.ts handedSecret when this is not given). */
47
+ readonly given?: string | undefined;
48
+ /** Who boots it (SealKeyRole): "server" by default. */
49
+ readonly role?: SealKeyRole;
50
+ /** Told the start line when a key is made (stderr by default). */
51
+ readonly say?: (line: string) => void;
52
+ /** false: nothing is written (a dry run). With no key, a store that holds no secret then has none (undefined). */
53
+ readonly write?: boolean;
54
+ }
55
+ /** `env` (one withSecrets made) with `text` as its seal key, read by name and never enumerated, as withSecrets gives a
56
+ * secret: so what reads the key from it gets the one its start checked against its store. */
57
+ export declare function withSealKey(env: NodeJS.ProcessEnv, text: string): NodeJS.ProcessEnv;
23
58
  /** The line a start prints about its seal key: where it is, never the key. */
24
59
  export declare function sealKeyLine(seal: SealKey): string;
25
- /** The seal key every entry point boots the one way — the server, the runner and the `import` command all call this, so
26
- * there is one rule, not three copies: the key handed over (AGENTRUN_SEAL_KEY), else the one kept under the config home of
27
- * `env` (made at the first boot, only its path printed). A made key is held back as this process's own secret, so the
28
- * environment it reads next (withSecrets) carries it. Throws with the start message when there is none and none can be made.
29
- * `say` takes the made-key line (stderr by default). */
30
- export declare function bootSealKey(env?: NodeJS.ProcessEnv, say?: (line: string) => void): SealKey;
60
+ /** The seal key every entry point boots the one way, once its store is open: the server, a runner (beside the server or
61
+ * its own process) and the `import` command all call this, so there is one rule. The key handed over (AGENTRUN_SEAL_KEY),
62
+ * else the one in `dataDir`, checked against what `store` records of its key (refused, in words, when it is not the
63
+ * store's). The server's start makes a key in `dataDir` for a store that holds no secret and records its fingerprint; a
64
+ * runner or the import never makes or records one. The key is on this process's redaction list until release()
65
+ * (secrets.ts holdSealKey); its holder passes it on itself (withSealKey), and nothing reads it from the process by name. Throws SealKeyRefused with the start message when there is no key it can use. */
66
+ export declare function bootSealKey(store: SealKeyStore, dataDir: string, options?: BootSealKeyOptions & {
67
+ readonly write?: true;
68
+ }): Promise<BootedSealKey>;
69
+ export declare function bootSealKey(store: SealKeyStore, dataDir: string, options: BootSealKeyOptions): Promise<BootedSealKey | undefined>;