@halonicjs/testing 0.1.0 → 0.1.2

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/NOTICE +4 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  4. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  5. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  6. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  7. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  8. package/dist/adapters/http-kit/src/index.js +2 -0
  9. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  10. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  11. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  13. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  15. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  16. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  17. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  18. package/dist/adapters/integration-kit/src/host.js +1 -0
  19. package/dist/adapters/integration-kit/src/index.d.ts +5 -2
  20. package/dist/adapters/integration-kit/src/index.js +2 -0
  21. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  22. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  23. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  24. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  25. package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
  26. package/dist/adapters/integration-kit/src/loader.js +36 -21
  27. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  28. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  29. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  30. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  31. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  32. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  33. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  34. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  35. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  36. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  37. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  38. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  39. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  40. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  41. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  42. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  43. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  44. package/dist/core/events/src/blocked-sites.js +89 -0
  45. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  46. package/dist/core/events/src/connector-listing-failed.js +1 -0
  47. package/dist/core/events/src/home-path.d.ts +4 -1
  48. package/dist/core/events/src/home-path.js +14 -3
  49. package/dist/core/events/src/index.d.ts +8 -2
  50. package/dist/core/events/src/index.js +5 -0
  51. package/dist/core/events/src/provider-notes.d.ts +16 -0
  52. package/dist/core/events/src/provider-notes.js +24 -0
  53. package/dist/core/events/src/run-basics.d.ts +131 -10
  54. package/dist/core/events/src/run-event.d.ts +120 -11
  55. package/dist/core/events/src/run-reads.d.ts +25 -0
  56. package/dist/core/events/src/run-reads.js +44 -0
  57. package/dist/core/events/src/run-sends.d.ts +47 -0
  58. package/dist/core/events/src/run-sends.js +68 -0
  59. package/dist/core/events/src/run-summary.d.ts +11 -1
  60. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  61. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  62. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  63. package/dist/core/events/src/sandbox-opened.js +13 -3
  64. package/dist/core/events/src/summarize.js +8 -1
  65. package/dist/core/events/src/timeline-entry.js +1 -0
  66. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  67. package/dist/core/events/src/tool-failure-cause.js +66 -0
  68. package/dist/core/format/src/index.d.ts +9 -6
  69. package/dist/core/format/src/index.js +7 -3
  70. package/dist/core/format/src/integration/index.d.ts +3 -2
  71. package/dist/core/format/src/integration/index.js +2 -1
  72. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  73. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  74. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  75. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  76. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  77. package/dist/core/format/src/kinds/agent/schema.js +5 -2
  78. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  79. package/dist/core/format/src/kinds/connector/kind.js +122 -2
  80. package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
  81. package/dist/core/format/src/kinds/connector/schema.js +71 -2
  82. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  83. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  84. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  85. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  86. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  87. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  88. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  89. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  90. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  91. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  92. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  93. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  94. package/dist/core/format/src/kinds/integration/schema.js +133 -7
  95. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
  96. package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
  97. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  98. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  99. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  100. package/dist/core/format/src/kinds/plugin/checks.js +24 -6
  101. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  102. package/dist/core/format/src/kinds/plugin/schema.js +26 -6
  103. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  104. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  105. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  106. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  107. package/dist/core/format/src/kinds/provider/types.js +22 -0
  108. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  109. package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
  110. package/dist/core/format/src/kinds/routine/schema.js +42 -14
  111. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  112. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  113. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  114. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  115. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  116. package/dist/core/format/src/kinds/workspace/schema.js +6 -5
  117. package/dist/core/format/src/parse-file.js +3 -1
  118. package/dist/core/format/src/shared/fields.d.ts +12 -8
  119. package/dist/core/format/src/shared/fields.js +48 -19
  120. package/dist/core/format/src/shared/guard.d.ts +8 -0
  121. package/dist/core/format/src/shared/guard.js +50 -1
  122. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  123. package/dist/core/format/src/shared/missing-keys.js +110 -0
  124. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  125. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  126. package/dist/core/ports/src/blob-store.d.ts +12 -0
  127. package/dist/core/ports/src/blob-store.js +22 -0
  128. package/dist/core/ports/src/chat.d.ts +8 -0
  129. package/dist/core/ports/src/connector-client.d.ts +48 -4
  130. package/dist/core/ports/src/connector-client.js +17 -0
  131. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  132. package/dist/core/ports/src/connector-start-failure.js +32 -0
  133. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  134. package/dist/core/ports/src/connector-tool-error.js +40 -0
  135. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  136. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  137. package/dist/core/ports/src/definition-store.d.ts +36 -5
  138. package/dist/core/ports/src/definition-store.js +1 -1
  139. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  140. package/dist/core/ports/src/deploy-target.js +2 -0
  141. package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
  142. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  143. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  144. package/dist/core/ports/src/harness.d.ts +79 -15
  145. package/dist/core/ports/src/harness.js +1 -1
  146. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  147. package/dist/core/ports/src/host-settings-store.js +106 -0
  148. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  149. package/dist/core/ports/src/host-too-old.js +27 -0
  150. package/dist/core/ports/src/index.d.ts +32 -13
  151. package/dist/core/ports/src/index.js +28 -8
  152. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  153. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  154. package/dist/core/ports/src/integration.d.ts +71 -7
  155. package/dist/core/ports/src/integration.js +22 -4
  156. package/dist/core/ports/src/llm-provider.d.ts +39 -6
  157. package/dist/core/ports/src/llm-provider.js +46 -3
  158. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  159. package/dist/core/ports/src/pairing-codes.js +336 -0
  160. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  161. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  162. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  163. package/dist/core/ports/src/port-versions.d.ts +13 -6
  164. package/dist/core/ports/src/port-versions.js +14 -0
  165. package/dist/core/ports/src/program-probe.d.ts +25 -2
  166. package/dist/core/ports/src/program-probe.js +1 -1
  167. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  168. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  169. package/dist/core/ports/src/record-store.d.ts +17 -0
  170. package/dist/core/ports/src/record-store.js +70 -0
  171. package/dist/core/ports/src/remote-control.d.ts +159 -0
  172. package/dist/core/ports/src/remote-control.js +26 -0
  173. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  174. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  175. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  176. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  177. package/dist/core/ports/src/run-executor.d.ts +44 -7
  178. package/dist/core/ports/src/run-executor.js +1 -1
  179. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  180. package/dist/core/ports/src/run-target-not-found.js +41 -0
  181. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  182. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  183. package/dist/core/ports/src/sandbox.d.ts +149 -13
  184. package/dist/core/ports/src/sandbox.js +52 -2
  185. package/dist/core/ports/src/secrets.d.ts +105 -1
  186. package/dist/core/ports/src/secrets.js +75 -2
  187. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  188. package/dist/core/ports/src/tool-approval-store.js +59 -0
  189. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  190. package/dist/core/ports/src/tunnel-provider.js +65 -0
  191. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  192. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  193. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  194. package/dist/core/ports/src/vcs-status.js +90 -0
  195. package/dist/core/ports/src/vcs.d.ts +30 -0
  196. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  197. package/dist/core/schema-kit/src/builders.js +5 -0
  198. package/dist/core/std/src/amount.d.ts +13 -0
  199. package/dist/core/std/src/amount.js +22 -0
  200. package/dist/core/std/src/hidden-characters.d.ts +28 -0
  201. package/dist/core/std/src/hidden-characters.js +72 -0
  202. package/dist/core/std/src/index.d.ts +7 -0
  203. package/dist/core/std/src/index.js +7 -0
  204. package/dist/core/std/src/path-overlap.d.ts +22 -0
  205. package/dist/core/std/src/path-overlap.js +57 -0
  206. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  207. package/dist/core/std/src/public-suffixes.generated.js +10428 -0
  208. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  209. package/dist/core/std/src/registrable-domain.js +62 -0
  210. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  211. package/dist/core/std/src/secret-variable-name.js +34 -0
  212. package/dist/core/std/src/site-name.d.ts +35 -0
  213. package/dist/core/std/src/site-name.js +111 -0
  214. package/dist/core/std/src/url-host.d.ts +35 -0
  215. package/dist/core/std/src/url-host.js +170 -0
  216. package/dist/core/std/src/word-diff.d.ts +28 -0
  217. package/dist/core/std/src/word-diff.js +77 -0
  218. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  219. package/dist/core/yaml/src/edit-data.js +62 -3
  220. package/dist/core/yaml/src/edit.d.ts +7 -0
  221. package/dist/core/yaml/src/edit.js +34 -3
  222. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  223. package/dist/core/yaml/src/splice-node.js +10 -0
  224. package/dist/core/yaml/src/splice.js +20 -10
  225. package/dist/testing/integration/src/checks.d.ts +5 -3
  226. package/dist/testing/integration/src/checks.js +31 -3
  227. package/dist/testing/integration/src/load.js +3 -1
  228. package/package.json +9 -2
@@ -0,0 +1,68 @@
1
+ /** Version of the {@link SandboxSettingStore} port. A breaking change bumps it and comes with an ADR. */
2
+ export declare const sandboxSettingStoreVersion = 1;
3
+ /** Every sandbox backend Halonic knows, by id. A new backend is a new entry here. */
4
+ export declare const sandboxBackendIds: readonly ["srt", "srt-wsl", "mxc", "docker-sbx", "cloud"];
5
+ /** A sandbox backend: one of {@link sandboxBackendIds}. */
6
+ export type SandboxBackendId = (typeof sandboxBackendIds)[number];
7
+ /**
8
+ * The person's choice of sandbox: a backend, or to continue without one.
9
+ * "Not chosen yet" is no record, which is `null` from the store.
10
+ *
11
+ * @example
12
+ * const setting: SandboxSetting = { backend: "srt-wsl", chosenAt: "2026-11-13T09:00:00.000Z" };
13
+ * const without: SandboxSetting = {
14
+ * backend: "none",
15
+ * chosenAt: "2026-11-13T09:00:00.000Z",
16
+ * appVersion: "0.1.0",
17
+ * };
18
+ */
19
+ export type SandboxSetting = {
20
+ /** The backend the person chose. */
21
+ backend: SandboxBackendId;
22
+ /** When the person chose, as ISO text. */
23
+ chosenAt: string;
24
+ } | {
25
+ /** The person chose to continue without a sandbox. */
26
+ backend: "none";
27
+ /** When the person chose, as ISO text. */
28
+ chosenAt: string;
29
+ /** The Halonic version that was running when they chose. */
30
+ appVersion: string;
31
+ };
32
+ /**
33
+ * The person's sandbox choice for this computer and this operating system
34
+ * user (requirement `ports.sandbox-setting-store`), in the user's profile:
35
+ * the profile folder for the CLI and `serve`, the app data folder for the
36
+ * desktop app, memory for tests and the browser demo. **Never inside a
37
+ * workspace**, so an agent that edits the workspace can't change the
38
+ * sandbox it runs in. It replaces the earlier MXC `on`/`off` setting.
39
+ *
40
+ * The port only stores the choice. `SandboxChoiceService` in `core/app`
41
+ * reads it and decides what runs. Only a person makes a choice: no tool the
42
+ * model can call reaches this store.
43
+ *
44
+ * A saved choice that exists but can't be read makes `get` throw, never
45
+ * return `null`: `null` means the onboarding hasn't run, and the caller must
46
+ * not take a damaged choice for that. `remove` still deletes it, and `save`
47
+ * still replaces it.
48
+ */
49
+ export interface SandboxSettingStore {
50
+ /** The saved choice, or `null` when none is saved. */
51
+ get(): Promise<SandboxSetting | null>;
52
+ /** Saves a choice, replacing any saved before. */
53
+ save(setting: SandboxSetting): Promise<void>;
54
+ /** Deletes the choice, even one that can't be read. Removing a choice that isn't there is not an error. */
55
+ remove(): Promise<void>;
56
+ }
57
+ /**
58
+ * Whether `value`, as read back from a store, is a valid choice: exactly the
59
+ * fields of a {@link SandboxSetting}, each text, and a backend that is
60
+ * {@link sandboxBackendIds} or `"none"`. Anything else is a damaged or
61
+ * hand-edited choice and must never pick a sandbox. Every adapter checks
62
+ * what it reads with this, and `SandboxChoiceService` in `core/app` checks
63
+ * what an adapter gives back with it again.
64
+ *
65
+ * @example
66
+ * isSandboxSetting(JSON.parse(text)); // false for `{ backend: "docker", chosenAt }`
67
+ */
68
+ export declare function isSandboxSetting(value: unknown): value is SandboxSetting;
@@ -0,0 +1,33 @@
1
+ /** Version of the {@link SandboxSettingStore} port. A breaking change bumps it and comes with an ADR. */
2
+ export const sandboxSettingStoreVersion = 1;
3
+ /** Every sandbox backend Halonic knows, by id. A new backend is a new entry here. */
4
+ export const sandboxBackendIds = ["srt", "srt-wsl", "mxc", "docker-sbx", "cloud"];
5
+ const backendFields = ["backend", "chosenAt"];
6
+ const noneFields = ["backend", "chosenAt", "appVersion"];
7
+ /**
8
+ * Whether `value`, as read back from a store, is a valid choice: exactly the
9
+ * fields of a {@link SandboxSetting}, each text, and a backend that is
10
+ * {@link sandboxBackendIds} or `"none"`. Anything else is a damaged or
11
+ * hand-edited choice and must never pick a sandbox. Every adapter checks
12
+ * what it reads with this, and `SandboxChoiceService` in `core/app` checks
13
+ * what an adapter gives back with it again.
14
+ *
15
+ * @example
16
+ * isSandboxSetting(JSON.parse(text)); // false for `{ backend: "docker", chosenAt }`
17
+ */
18
+ export function isSandboxSetting(value) {
19
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
20
+ return false;
21
+ }
22
+ const record = value;
23
+ const backend = record["backend"];
24
+ if (backend === "none")
25
+ return hasExactlyTextFields(record, noneFields);
26
+ return (typeof backend === "string" &&
27
+ sandboxBackendIds.includes(backend) &&
28
+ hasExactlyTextFields(record, backendFields));
29
+ }
30
+ function hasExactlyTextFields(record, fields) {
31
+ return (Object.keys(record).length === fields.length &&
32
+ fields.every((field) => Object.hasOwn(record, field) && typeof record[field] === "string"));
33
+ }
@@ -9,8 +9,14 @@
9
9
  * but its listed sites (docs/adr/2026-11-10-sandbox-optional-bridge.md).
10
10
  * 5: strength `none` and the fence proof `off`, for the launcher that starts
11
11
  * programs without a fence (docs/adr/2026-11-11-sandbox-without-fence.md).
12
+ * 6: reason codes for setup, WSL, company policy and sign-in, and `windows`
13
+ * narrowed to a backend with no Windows mode
14
+ * (docs/adr/2026-11-11-pluggable-sandbox-layer.md).
15
+ * 7: {@link SandboxNetwork.bridge} says its kind: a loopback port, or a name
16
+ * the sandbox's proxy serves on a Unix socket
17
+ * (docs/adr/2026-11-11-sandbox-bridge-on-a-socket.md).
12
18
  */
13
- export declare const sandboxVersion = 5;
19
+ export declare const sandboxVersion = 7;
14
20
  /**
15
21
  * How files reach the sandbox. `shared`: the program sees the same folders as
16
22
  * Halonic, so nothing is copied (a sandbox on this computer). `copied`: the
@@ -38,14 +44,28 @@ export interface SandboxCapabilities {
38
44
  * the CLI turn each one into the words a person reads and the fix; the
39
45
  * adapter never words it.
40
46
  *
41
- * - `windows`: plain Windows, outside WSL2.
47
+ * - `windows`: this backend has no Windows mode, so it can't run on Windows at all.
42
48
  * - `container`: Halonic itself runs inside a container (such as Docker), which won't nest the fence.
49
+ * - `not-supported`: this edition or build of the operating system can't run the backend, such as Windows older than 10 2004.
50
+ * - `blocked-by-policy`: a company policy blocks the backend, such as a WSL group policy or Docker's admin settings.
51
+ * - `virtualisation-off`: hardware virtualisation is off, or a VM has no nested virtualisation.
52
+ * - `wsl-missing`: WSL isn't installed, which needs an administrator.
53
+ * - `restart-needed`: WSL is installed, but Windows must restart first.
54
+ * - `distro-missing`: WSL works, but Halonic's own distro isn't imported (no administrator needed).
55
+ * - `setup-conflict`: the machine-wide setup belongs to another program, or is set up another way.
56
+ * - `setup-needed`: the one-time administrator setup isn't done, or was done by another release of the backend.
43
57
  * - `user-namespaces-restricted`: the system doesn't let programs create user namespaces, as Ubuntu 24.04 does by default.
44
58
  * - `bubblewrap-missing`: bubblewrap (`bwrap`) is not installed.
45
59
  * - `linux-tools-missing`: `socat` or ripgrep (`rg`), which srt starts next to bubblewrap, is not installed.
60
+ * - `ripgrep-missing`: ripgrep (`rg`), which srt starts next to Seatbelt on macOS, is not installed.
61
+ * - `sign-in-needed`: the backend needs an account sign-in.
46
62
  * - `other`: none of the above; `SandboxCheck.missing` says what.
63
+ *
64
+ * The order is the order of the fixes: what Halonic can't fix comes before
65
+ * what an administrator can, and that before what the person can do in one
66
+ * step.
47
67
  */
48
- export declare const sandboxUnavailableReasons: readonly ["windows", "container", "user-namespaces-restricted", "bubblewrap-missing", "linux-tools-missing", "other"];
68
+ export declare const sandboxUnavailableReasons: readonly ["windows", "container", "not-supported", "blocked-by-policy", "virtualisation-off", "wsl-missing", "restart-needed", "distro-missing", "setup-conflict", "setup-needed", "user-namespaces-restricted", "bubblewrap-missing", "linux-tools-missing", "ripgrep-missing", "sign-in-needed", "other"];
49
69
  /** Why a sandbox can't start on this machine: one of {@link sandboxUnavailableReasons}. */
50
70
  export type SandboxUnavailableReason = (typeof sandboxUnavailableReasons)[number];
51
71
  /**
@@ -59,15 +79,69 @@ export type SandboxUnavailableReason = (typeof sandboxUnavailableReasons)[number
59
79
  * - `missing` says what is missing, one plain sentence each, such as
60
80
  * "bubblewrap is not installed". For logs and support, not for people:
61
81
  * Studio words the refusal from `reason`.
82
+ * - `fix`, when set, is what fixes it on this machine, as data (since
83
+ * HAL-5393; optional, so the port stays at its version). See {@link SandboxFix}.
84
+ * - `residuals`, on an `ok` check, are limits that hold on this machine only
85
+ * (HAL-5398; optional). See {@link SandboxResidual}.
62
86
  */
63
87
  export type SandboxCheck = {
64
88
  ok: true;
65
89
  reason: null;
66
90
  missing: [];
91
+ residuals?: SandboxResidual[];
67
92
  } | {
68
93
  ok: false;
69
94
  reason: SandboxUnavailableReason;
70
95
  missing: string[];
96
+ fix?: SandboxFix;
97
+ };
98
+ /**
99
+ * Every limit an `ok` check can find on this machine that isn't a fact of the backend:
100
+ *
101
+ * - `kept-roots-readable` is srt on Windows set up by another program with its
102
+ * profile read grant (or a setup that couldn't be read), so every sandboxed
103
+ * session can read the profile.
104
+ * - `docker-desktop-visible` is srt in Halonic's WSL distro where Docker
105
+ * Desktop's socket or its `/mnt/wsl/docker-desktop*` folders show (HAL-12445).
106
+ *
107
+ * The list is closed, and a new one is a port change. Readers that check a
108
+ * check's shape, such as the agent host's client, take the list from here so
109
+ * a new code reaches them too (HAL-12932).
110
+ */
111
+ export declare const sandboxResiduals: readonly ["kept-roots-readable", "docker-desktop-visible"];
112
+ /** A limit an `ok` check found on this machine: one of {@link sandboxResiduals}. */
113
+ export type SandboxResidual = (typeof sandboxResiduals)[number];
114
+ /**
115
+ * Every package manager a {@link SandboxFix} can name: `apt` (Debian,
116
+ * Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
117
+ * (Homebrew on macOS). The list is closed, and a new one is a port change.
118
+ */
119
+ export declare const sandboxPackageManagers: readonly ["apt", "dnf", "pacman", "zypper", "brew"];
120
+ /** A package manager a {@link SandboxFix} can name: one of {@link sandboxPackageManagers}. */
121
+ export type SandboxPackageManager = (typeof sandboxPackageManagers)[number];
122
+ /**
123
+ * What fixes a refused {@link SandboxCheck} on this machine, as data and
124
+ * never as words or a command line: Studio and the CLI word it. It is advice
125
+ * to show the person. No caller runs it or asks for administrator rights on
126
+ * its own; offering to run it is a new flow that needs the board's approval
127
+ * (docs/adr/2026-11-12-sandbox-check-fix-data.md).
128
+ *
129
+ * - `install`: install every package in `packages` with `packageManager`,
130
+ * as one command. `packageManager` is `null` when the machine has none
131
+ * that Halonic knows; then Studio names the packages only.
132
+ * - `apparmor-profile`: write `profile` to `path` and load it, which lets
133
+ * `program`, and only it, create user namespaces. The machine-wide setting
134
+ * stays on.
135
+ */
136
+ export type SandboxFix = {
137
+ kind: "install";
138
+ packageManager: SandboxPackageManager | null;
139
+ packages: string[];
140
+ } | {
141
+ kind: "apparmor-profile";
142
+ program: string;
143
+ path: string;
144
+ profile: string;
71
145
  };
72
146
  /**
73
147
  * What a program in the sandbox may reach. Halonic builds it from the
@@ -93,8 +167,23 @@ export interface SandboxProfile {
93
167
  settingsFolder: string | null;
94
168
  /** Paths the program may read but not change, such as the workspace's definition files. */
95
169
  readOnlyPaths: string[];
96
- /** Paths the program may not read or write, such as SSH keys and Halonic's own data. Wins over every other list. */
170
+ /**
171
+ * Paths the program may not read or write, such as SSH keys and Halonic's
172
+ * own data. Wins over every other list, except that a path in
173
+ * {@link reopenedPaths} may be read again.
174
+ */
97
175
  deniedPaths: string[];
176
+ /**
177
+ * Paths inside a denied path that the program may read again, such as a
178
+ * run's own folders in Halonic's denied data folder. A writable folder
179
+ * inside a denied path must be listed here too; it stays writable. Each
180
+ * path must exist when the session opens, must lie inside a path of
181
+ * {@link deniedPaths}, and must not hold a writable folder (list the
182
+ * entries around that folder instead). An adapter refuses a profile that
183
+ * breaks one of these rules. Absent means none, so a profile that drops it
184
+ * can only deny more.
185
+ */
186
+ reopenedPaths?: string[] | undefined;
98
187
  /**
99
188
  * The only environment variables the program gets, by name and value. The
100
189
  * host's own environment is never passed on.
@@ -104,23 +193,52 @@ export interface SandboxProfile {
104
193
  network: SandboxNetwork;
105
194
  /** How long the whole run may last, in milliseconds, counted from {@link Sandbox.open}. */
106
195
  timeLimitMs: number;
196
+ /**
197
+ * Whether the program may ask the operating system's key store for a
198
+ * stored secret. `denied` for code nobody reviewed, such as a local
199
+ * integration (attack case A36). Left out, it may, because an agent can
200
+ * keep its own sign-in in the macOS Keychain. With `denied`, the fence on
201
+ * macOS refuses the Keychain's Mach services. On Linux the Secret Service
202
+ * is a D-Bus socket, so hide its folder in {@link deniedPaths}. On Windows
203
+ * no adapter can fence the Credential Manager yet.
204
+ */
205
+ keyStore?: "allowed" | "denied";
107
206
  }
207
+ /**
208
+ * Where the program reaches the Halonic bridge.
209
+ *
210
+ * - `loopback`: a port on this computer's loopback, `host` being `127.0.0.1`,
211
+ * `::1` or `localhost`. The program dials it as it is.
212
+ * - `socket`: the bridge serves a Unix socket at `socketPath`, an absolute
213
+ * path, and the program calls it by `name`, a host name that never
214
+ * resolves, such as `bridge.halonic.invalid`. The sandbox's own proxy,
215
+ * outside the fence, sends requests for that name, on port 80 only, to the
216
+ * socket, so no port is open to anything else on the computer. The program
217
+ * never opens the socket itself.
218
+ */
219
+ export type SandboxBridge = {
220
+ kind: "loopback";
221
+ host: string;
222
+ port: number;
223
+ } | {
224
+ kind: "socket";
225
+ name: string;
226
+ socketPath: string;
227
+ };
108
228
  /** The network a {@link SandboxProfile} allows. */
109
229
  export interface SandboxNetwork {
110
230
  /**
111
- * The Halonic bridge: the one loopback address the program can reach. An
112
- * adapter rejects a host that is not a loopback address (`127.0.0.1`, `::1`
113
- * or `localhost`) when {@link Sandbox.open} is called.
231
+ * The Halonic bridge: the one address on this computer the program can
232
+ * reach. An adapter rejects, when {@link Sandbox.open} is called, a
233
+ * `loopback` bridge whose host is not a loopback address, and a bridge kind
234
+ * it can't serve.
114
235
  *
115
236
  * `null` means no bridge: the program reaches no loopback address at all,
116
237
  * only the allowed sites. The integration runner uses it, because it talks
117
238
  * to Halonic over its standard input and output, not the network. The field
118
239
  * is never optional, so leaving it out can't mean "the whole network".
119
240
  */
120
- bridge: {
121
- host: string;
122
- port: number;
123
- } | null;
241
+ bridge: SandboxBridge | null;
124
242
  /**
125
243
  * Further sites, by host name such as "registry.npmjs.org" or with a
126
244
  * leading "*." for every subdomain. Empty by default.
@@ -133,7 +251,25 @@ export interface SandboxCommand {
133
251
  program: string;
134
252
  /** Its arguments, passed as they are, never through a shell. */
135
253
  args: string[];
136
- /** Where it starts: the working folder or a folder inside it. Absent means the working folder. */
254
+ /**
255
+ * Where it starts, read against the working folder. Absent means the
256
+ * working folder. It must lie, where it really is through symbolic links,
257
+ * inside the working folder or inside a path of
258
+ * {@link SandboxProfile.readOnlyPaths}, and not inside a path of
259
+ * {@link SandboxProfile.deniedPaths} unless that part is reopened.
260
+ * {@link SandboxSession.start} throws on any other folder (HAL-6884).
261
+ *
262
+ * A folder in a read-only path stays read-only: a workspace connector
263
+ * starts where its script and `node_modules` are, but writes only to the
264
+ * working and temp folders. A program that writes next to its script fails
265
+ * there, such as `uv run` making `.venv`; the caller points it elsewhere,
266
+ * as with `UV_PROJECT_ENVIRONMENT`.
267
+ *
268
+ * The fence's own write rules for tool settings and git hooks in folders
269
+ * nested in the working folder, such as `sub/.claude/`, follow the start
270
+ * folder. Only start outside the working folder when that working folder
271
+ * is thrown away when the session closes, as a connector's own is.
272
+ */
137
273
  cwd?: string;
138
274
  }
139
275
  /** How a started program ended. */
@@ -239,7 +375,7 @@ export interface Sandbox {
239
375
  * Opens a session for one run. Cancelling the run, by aborting `signal`,
240
376
  * closes the session.
241
377
  *
242
- * @throws when the sandbox doesn't work here (see {@link Sandbox.check}) or the profile can't be applied, including a bridge that is not a loopback address
378
+ * @throws when the sandbox doesn't work here (see {@link Sandbox.check}) or the profile can't be applied, including a loopback bridge whose host is not a loopback address, or a bridge kind it can't serve
243
379
  */
244
380
  open(profile: SandboxProfile, options?: {
245
381
  signal?: AbortSignal;
@@ -9,26 +9,76 @@
9
9
  * but its listed sites (docs/adr/2026-11-10-sandbox-optional-bridge.md).
10
10
  * 5: strength `none` and the fence proof `off`, for the launcher that starts
11
11
  * programs without a fence (docs/adr/2026-11-11-sandbox-without-fence.md).
12
+ * 6: reason codes for setup, WSL, company policy and sign-in, and `windows`
13
+ * narrowed to a backend with no Windows mode
14
+ * (docs/adr/2026-11-11-pluggable-sandbox-layer.md).
15
+ * 7: {@link SandboxNetwork.bridge} says its kind: a loopback port, or a name
16
+ * the sandbox's proxy serves on a Unix socket
17
+ * (docs/adr/2026-11-11-sandbox-bridge-on-a-socket.md).
12
18
  */
13
- export const sandboxVersion = 5;
19
+ export const sandboxVersion = 7;
14
20
  /**
15
21
  * Every reason a sandbox can't start on this machine. The list is closed: an
16
22
  * adapter returns only these, and a new reason is a port change. Studio and
17
23
  * the CLI turn each one into the words a person reads and the fix; the
18
24
  * adapter never words it.
19
25
  *
20
- * - `windows`: plain Windows, outside WSL2.
26
+ * - `windows`: this backend has no Windows mode, so it can't run on Windows at all.
21
27
  * - `container`: Halonic itself runs inside a container (such as Docker), which won't nest the fence.
28
+ * - `not-supported`: this edition or build of the operating system can't run the backend, such as Windows older than 10 2004.
29
+ * - `blocked-by-policy`: a company policy blocks the backend, such as a WSL group policy or Docker's admin settings.
30
+ * - `virtualisation-off`: hardware virtualisation is off, or a VM has no nested virtualisation.
31
+ * - `wsl-missing`: WSL isn't installed, which needs an administrator.
32
+ * - `restart-needed`: WSL is installed, but Windows must restart first.
33
+ * - `distro-missing`: WSL works, but Halonic's own distro isn't imported (no administrator needed).
34
+ * - `setup-conflict`: the machine-wide setup belongs to another program, or is set up another way.
35
+ * - `setup-needed`: the one-time administrator setup isn't done, or was done by another release of the backend.
22
36
  * - `user-namespaces-restricted`: the system doesn't let programs create user namespaces, as Ubuntu 24.04 does by default.
23
37
  * - `bubblewrap-missing`: bubblewrap (`bwrap`) is not installed.
24
38
  * - `linux-tools-missing`: `socat` or ripgrep (`rg`), which srt starts next to bubblewrap, is not installed.
39
+ * - `ripgrep-missing`: ripgrep (`rg`), which srt starts next to Seatbelt on macOS, is not installed.
40
+ * - `sign-in-needed`: the backend needs an account sign-in.
25
41
  * - `other`: none of the above; `SandboxCheck.missing` says what.
42
+ *
43
+ * The order is the order of the fixes: what Halonic can't fix comes before
44
+ * what an administrator can, and that before what the person can do in one
45
+ * step.
26
46
  */
27
47
  export const sandboxUnavailableReasons = [
28
48
  "windows",
29
49
  "container",
50
+ "not-supported",
51
+ "blocked-by-policy",
52
+ "virtualisation-off",
53
+ "wsl-missing",
54
+ "restart-needed",
55
+ "distro-missing",
56
+ "setup-conflict",
57
+ "setup-needed",
30
58
  "user-namespaces-restricted",
31
59
  "bubblewrap-missing",
32
60
  "linux-tools-missing",
61
+ "ripgrep-missing",
62
+ "sign-in-needed",
33
63
  "other",
34
64
  ];
65
+ /**
66
+ * Every limit an `ok` check can find on this machine that isn't a fact of the backend:
67
+ *
68
+ * - `kept-roots-readable` is srt on Windows set up by another program with its
69
+ * profile read grant (or a setup that couldn't be read), so every sandboxed
70
+ * session can read the profile.
71
+ * - `docker-desktop-visible` is srt in Halonic's WSL distro where Docker
72
+ * Desktop's socket or its `/mnt/wsl/docker-desktop*` folders show (HAL-12445).
73
+ *
74
+ * The list is closed, and a new one is a port change. Readers that check a
75
+ * check's shape, such as the agent host's client, take the list from here so
76
+ * a new code reaches them too (HAL-12932).
77
+ */
78
+ export const sandboxResiduals = ["kept-roots-readable", "docker-desktop-visible"];
79
+ /**
80
+ * Every package manager a {@link SandboxFix} can name: `apt` (Debian,
81
+ * Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
82
+ * (Homebrew on macOS). The list is closed, and a new one is a port change.
83
+ */
84
+ export const sandboxPackageManagers = ["apt", "dnf", "pacman", "zypper", "brew"];
@@ -22,9 +22,57 @@ export interface Secrets {
22
22
  * The secret's value, or `null` when it isn't configured.
23
23
  *
24
24
  * @throws RangeError when the name breaks the rule above
25
+ *
26
+ * Any error `get` throws, for this or any other reason, never holds the
27
+ * secret's value in its message or its cause, so a caller may show the
28
+ * message.
25
29
  */
26
30
  get(name: string): Promise<string | null>;
27
31
  }
32
+ /**
33
+ * The secrets a person sets and removes with `halonic secret`: {@link Secrets}
34
+ * that can also be written. A host that only reads secrets (a Worker, the
35
+ * environment) implements `Secrets` alone; only a store the person owns, such
36
+ * as a file in the profile, implements this. It follows the version of
37
+ * {@link Secrets}, which it extends without changing.
38
+ *
39
+ * The same name rule and the same matching apply: every method runs
40
+ * {@link secretKey} on a name before it touches storage, so a bad name is a
41
+ * `RangeError` that changes nothing, and `Open-AI` and `open_ai` are one secret.
42
+ * **A value never appears in an error, a log or a listing.**
43
+ */
44
+ export interface SecretStore extends Secrets {
45
+ /**
46
+ * Saves a value, replacing the one stored under the same name. The name is
47
+ * kept as it was written last, so a listing shows what the person typed.
48
+ *
49
+ * @throws RangeError when the name breaks the rule, or the value is empty or
50
+ * longer than {@link maxSecretValueLength}; the message never repeats the value
51
+ */
52
+ set(name: string, value: string): Promise<void>;
53
+ /**
54
+ * Removes a secret. Removing one that isn't stored succeeds and changes nothing.
55
+ *
56
+ * @throws RangeError when the name breaks the rule
57
+ */
58
+ remove(name: string): Promise<void>;
59
+ /** The names of the stored secrets, sorted by their `secretKey` form, and never a value. */
60
+ names(): Promise<readonly string[]>;
61
+ }
62
+ /** The longest value a {@link SecretStore} saves, in UTF-16 code units. Bounds what one secret may cost a store. */
63
+ export declare const maxSecretValueLength: number;
64
+ /**
65
+ * Checks a value before a {@link SecretStore} saves it, so every store refuses
66
+ * the same ones: an empty value (`EnvSecrets` treats it as unset, so it would
67
+ * look like no secret) and one over {@link maxSecretValueLength}.
68
+ *
69
+ * @throws RangeError; the message never repeats the value, only its length
70
+ *
71
+ * @example
72
+ * checkSecretValue("sk-live-1234"); // fine
73
+ * checkSecretValue(""); // throws a RangeError
74
+ */
75
+ export declare function checkSecretValue(value: string): void;
28
76
  /** The longest a `Secrets` or `TokenStore` name may be. */
29
77
  export declare const maxSecretNameLength = 128;
30
78
  /**
@@ -74,6 +122,12 @@ export declare function describeSecretName(name: string): string;
74
122
  * the sign-in password. Only Halonic reads them; no workspace may pick them.
75
123
  */
76
124
  export declare const halonicSecretNames: readonly string[];
125
+ /**
126
+ * The secrets only the agent host keeps, for itself: the remote host's static
127
+ * key (tunnel phase B). Like {@link halonicSecretNames}, no workspace may pick
128
+ * them, but no deployment needs them, so they aren't in that list.
129
+ */
130
+ export declare const hostSecretNames: readonly string[];
77
131
  /**
78
132
  * The prefix of a token's name in a store that also holds secrets, such as
79
133
  * the desktop keychain. A secret name with this prefix is a token, so no
@@ -82,7 +136,7 @@ export declare const halonicSecretNames: readonly string[];
82
136
  export declare const tokenNamePrefix = "halonic_token_";
83
137
  /**
84
138
  * Whether a secret name belongs to Halonic: one of {@link halonicSecretNames}
85
- * or a token name under {@link tokenNamePrefix}. Names are compared in their
139
+ * or {@link hostSecretNames}, or a token name under {@link tokenNamePrefix}. Names are compared in their
86
140
  * `secretKey` form, so `Token_Key` is `token-key`.
87
141
  *
88
142
  * @throws RangeError when the name breaks the rule of the `Secrets` port
@@ -98,6 +152,14 @@ export declare function isHalonicSecretName(name: string): boolean;
98
152
  * belongs to a plugin, so no workspace may pick it.
99
153
  */
100
154
  export declare const pluginSecretNamePrefix = "plugin__";
155
+ /**
156
+ * Comes between the plugin's id and the secret's name in a plugin's secret
157
+ * name, and ends {@link pluginSecretNamePrefix}'s share of it. `Secrets`
158
+ * takes `-` and `_` as the same character, so a single one can't tell
159
+ * `a-b` + `c` from `a` + `b-c`. Ids and secret names never hold two `-` in a
160
+ * row, so a doubled `_` can't come from either of them.
161
+ */
162
+ export declare const pluginSecretSeparator = "__";
101
163
  /**
102
164
  * Whether a secret name belongs to a plugin: it starts with
103
165
  * {@link pluginSecretNamePrefix}. Names are compared in their `secretKey`
@@ -126,3 +188,45 @@ export declare function isPluginSecretName(name: string): boolean;
126
188
  * await picks.get("plugin__weather__acme-key"); // throws a RangeError
127
189
  */
128
190
  export declare function workspaceSecrets(secrets: Secrets): Secrets;
191
+ /**
192
+ * The secrets as one plugin's backend may read them: only the names stored
193
+ * for that plugin, `plugin__<id>__<secret>` in `secretKey` form, and nothing
194
+ * else, so a plugin can't read a workspace's secret, Halonic's own or
195
+ * another plugin's. The app picks each name from the plugin's own manifest;
196
+ * this is the second check, at the place that reads.
197
+ *
198
+ * @throws RangeError from `get`, for a name that isn't one of the plugin's;
199
+ * the message never repeats the name
200
+ *
201
+ * @example
202
+ * const own = pluginSecrets(secrets, "weather");
203
+ * await own.get("plugin__weather__acme-key"); // the stored key, or null
204
+ * await own.get("openai-key"); // throws a RangeError
205
+ * await own.get("plugin__rain__acme-key"); // throws a RangeError
206
+ */
207
+ export declare function pluginSecrets(secrets: Secrets, pluginId: string): Secrets;
208
+ /** The most origins one key may be allowed to go to. A short list on purpose: each one is a place the key can leak to. */
209
+ export declare const maxAllowedOrigins = 8;
210
+ /**
211
+ * Where the keys in a {@link Secrets} store may be sent. A key has either a
212
+ * list of allowed origins, or none recorded (a key saved before origins
213
+ * existed), which the caller treats by the older rules.
214
+ *
215
+ * Names match as `secretKey` matches them. An origin is the scheme, host and
216
+ * port, as {@link originOf} writes it, and is compared as a whole string,
217
+ * never by prefix.
218
+ */
219
+ export interface KeyOrigins {
220
+ /**
221
+ * The origins the key may go to, or `undefined` when none is recorded.
222
+ * Never an empty list, and never the key.
223
+ *
224
+ * @throws RangeError when the name breaks the secret name rule
225
+ */
226
+ allowedOrigins(name: string): Promise<readonly string[] | undefined>;
227
+ }
228
+ /**
229
+ * The key origins of a host that has no list yet, so every key has none
230
+ * recorded. A host passes it on purpose, to say its key store can't hold them.
231
+ */
232
+ export declare const noKeyOrigins: KeyOrigins;
@@ -1,5 +1,26 @@
1
1
  /** Version of the {@link Secrets} port. A breaking change bumps it and comes with an ADR. */
2
2
  export const secretsVersion = 1;
3
+ /** The longest value a {@link SecretStore} saves, in UTF-16 code units. Bounds what one secret may cost a store. */
4
+ export const maxSecretValueLength = 64 * 1024;
5
+ /**
6
+ * Checks a value before a {@link SecretStore} saves it, so every store refuses
7
+ * the same ones: an empty value (`EnvSecrets` treats it as unset, so it would
8
+ * look like no secret) and one over {@link maxSecretValueLength}.
9
+ *
10
+ * @throws RangeError; the message never repeats the value, only its length
11
+ *
12
+ * @example
13
+ * checkSecretValue("sk-live-1234"); // fine
14
+ * checkSecretValue(""); // throws a RangeError
15
+ */
16
+ export function checkSecretValue(value) {
17
+ if (value === "") {
18
+ throw new RangeError("A secret's value can't be empty. Remove the secret instead.");
19
+ }
20
+ if (value.length > maxSecretValueLength) {
21
+ throw new RangeError(`A secret's value can be at most ${maxSecretValueLength} characters; this one has ${value.length}.`);
22
+ }
23
+ }
3
24
  /** The longest a `Secrets` or `TokenStore` name may be. */
4
25
  export const maxSecretNameLength = 128;
5
26
  const secretNamePattern = /^[A-Za-z][A-Za-z0-9_-]*$/;
@@ -70,17 +91,23 @@ export function describeSecretName(name) {
70
91
  * the sign-in password. Only Halonic reads them; no workspace may pick them.
71
92
  */
72
93
  export const halonicSecretNames = ["token-key", "serve-password"];
94
+ /**
95
+ * The secrets only the agent host keeps, for itself: the remote host's static
96
+ * key (tunnel phase B). Like {@link halonicSecretNames}, no workspace may pick
97
+ * them, but no deployment needs them, so they aren't in that list.
98
+ */
99
+ export const hostSecretNames = ["remote-host-key"];
73
100
  /**
74
101
  * The prefix of a token's name in a store that also holds secrets, such as
75
102
  * the desktop keychain. A secret name with this prefix is a token, so no
76
103
  * workspace may pick it.
77
104
  */
78
105
  export const tokenNamePrefix = "halonic_token_";
79
- const halonicSecretKeys = new Set(halonicSecretNames.map(secretKey));
106
+ const halonicSecretKeys = new Set([...halonicSecretNames, ...hostSecretNames].map(secretKey));
80
107
  const tokenKeyPrefix = secretKey(tokenNamePrefix);
81
108
  /**
82
109
  * Whether a secret name belongs to Halonic: one of {@link halonicSecretNames}
83
- * or a token name under {@link tokenNamePrefix}. Names are compared in their
110
+ * or {@link hostSecretNames}, or a token name under {@link tokenNamePrefix}. Names are compared in their
84
111
  * `secretKey` form, so `Token_Key` is `token-key`.
85
112
  *
86
113
  * @throws RangeError when the name breaks the rule of the `Secrets` port
@@ -99,6 +126,14 @@ export function isHalonicSecretName(name) {
99
126
  * belongs to a plugin, so no workspace may pick it.
100
127
  */
101
128
  export const pluginSecretNamePrefix = "plugin__";
129
+ /**
130
+ * Comes between the plugin's id and the secret's name in a plugin's secret
131
+ * name, and ends {@link pluginSecretNamePrefix}'s share of it. `Secrets`
132
+ * takes `-` and `_` as the same character, so a single one can't tell
133
+ * `a-b` + `c` from `a` + `b-c`. Ids and secret names never hold two `-` in a
134
+ * row, so a doubled `_` can't come from either of them.
135
+ */
136
+ export const pluginSecretSeparator = "__";
102
137
  const pluginKeyPrefix = secretKey(pluginSecretNamePrefix);
103
138
  /**
104
139
  * Whether a secret name belongs to a plugin: it starts with
@@ -142,3 +177,41 @@ export function workspaceSecrets(secrets) {
142
177
  },
143
178
  };
144
179
  }
180
+ /**
181
+ * The secrets as one plugin's backend may read them: only the names stored
182
+ * for that plugin, `plugin__<id>__<secret>` in `secretKey` form, and nothing
183
+ * else, so a plugin can't read a workspace's secret, Halonic's own or
184
+ * another plugin's. The app picks each name from the plugin's own manifest;
185
+ * this is the second check, at the place that reads.
186
+ *
187
+ * @throws RangeError from `get`, for a name that isn't one of the plugin's;
188
+ * the message never repeats the name
189
+ *
190
+ * @example
191
+ * const own = pluginSecrets(secrets, "weather");
192
+ * await own.get("plugin__weather__acme-key"); // the stored key, or null
193
+ * await own.get("openai-key"); // throws a RangeError
194
+ * await own.get("plugin__rain__acme-key"); // throws a RangeError
195
+ */
196
+ export function pluginSecrets(secrets, pluginId) {
197
+ const own = secretKey(`${pluginSecretNamePrefix}${pluginId}${pluginSecretSeparator}`);
198
+ return {
199
+ get: async (name) => {
200
+ if (!secretKey(name).startsWith(own)) {
201
+ throw new RangeError("A plugin can read only the secrets stored for it.");
202
+ }
203
+ return await secrets.get(name);
204
+ },
205
+ };
206
+ }
207
+ // The addresses a stored key may be sent to (HAL-11871, step B of HAL-11343). The key store
208
+ // keeps them next to the key; the model resolver reads them on every call.
209
+ /** The most origins one key may be allowed to go to. A short list on purpose: each one is a place the key can leak to. */
210
+ export const maxAllowedOrigins = 8;
211
+ /**
212
+ * The key origins of a host that has no list yet, so every key has none
213
+ * recorded. A host passes it on purpose, to say its key store can't hold them.
214
+ */
215
+ export const noKeyOrigins = {
216
+ allowedOrigins: async () => undefined,
217
+ };