@halonicjs/testing 0.1.0 → 0.1.1

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 (153) 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/index.d.ts +1 -0
  6. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  7. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  8. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  9. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  10. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  11. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  12. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  13. package/dist/adapters/integration-kit/src/host.js +1 -0
  14. package/dist/adapters/integration-kit/src/index.d.ts +3 -1
  15. package/dist/adapters/integration-kit/src/index.js +1 -0
  16. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  17. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  18. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  19. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  20. package/dist/adapters/integration-kit/src/loader.d.ts +29 -2
  21. package/dist/adapters/integration-kit/src/loader.js +44 -12
  22. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  23. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  24. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  25. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  26. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  27. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  28. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  29. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  30. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  31. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  32. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  33. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  34. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  35. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  36. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  37. package/dist/core/events/src/blocked-sites.js +89 -0
  38. package/dist/core/events/src/index.d.ts +5 -1
  39. package/dist/core/events/src/index.js +3 -0
  40. package/dist/core/events/src/run-basics.d.ts +30 -7
  41. package/dist/core/events/src/run-event.d.ts +49 -5
  42. package/dist/core/events/src/run-reads.d.ts +25 -0
  43. package/dist/core/events/src/run-reads.js +44 -0
  44. package/dist/core/events/src/run-sends.d.ts +47 -0
  45. package/dist/core/events/src/run-sends.js +68 -0
  46. package/dist/core/events/src/summarize.js +5 -1
  47. package/dist/core/events/src/timeline-entry.js +1 -0
  48. package/dist/core/format/src/index.d.ts +7 -5
  49. package/dist/core/format/src/index.js +5 -3
  50. package/dist/core/format/src/integration/index.d.ts +3 -2
  51. package/dist/core/format/src/integration/index.js +2 -1
  52. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  53. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  54. package/dist/core/format/src/kinds/agent/schema.js +2 -2
  55. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  56. package/dist/core/format/src/kinds/connector/kind.js +99 -0
  57. package/dist/core/format/src/kinds/connector/schema.d.ts +24 -0
  58. package/dist/core/format/src/kinds/connector/schema.js +53 -2
  59. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  60. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  61. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  62. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  63. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  64. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  65. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  66. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  67. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  68. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  69. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  70. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  71. package/dist/core/format/src/kinds/integration/schema.js +132 -6
  72. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
  73. package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
  74. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  75. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  76. package/dist/core/format/src/kinds/plugin/checks.js +7 -1
  77. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  78. package/dist/core/format/src/kinds/plugin/schema.js +2 -2
  79. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  80. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  81. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  82. package/dist/core/format/src/kinds/routine/schema.d.ts +10 -0
  83. package/dist/core/format/src/kinds/routine/schema.js +23 -1
  84. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  85. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  86. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  87. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  88. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  89. package/dist/core/format/src/kinds/workspace/schema.js +1 -1
  90. package/dist/core/format/src/shared/fields.d.ts +3 -6
  91. package/dist/core/format/src/shared/fields.js +33 -13
  92. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  93. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  94. package/dist/core/ports/src/blob-store.d.ts +12 -0
  95. package/dist/core/ports/src/blob-store.js +22 -0
  96. package/dist/core/ports/src/connector-client.d.ts +48 -4
  97. package/dist/core/ports/src/connector-client.js +17 -0
  98. package/dist/core/ports/src/definition-store.d.ts +23 -2
  99. package/dist/core/ports/src/harness-bridge-server.d.ts +12 -3
  100. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  101. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  102. package/dist/core/ports/src/harness.d.ts +46 -13
  103. package/dist/core/ports/src/harness.js +1 -1
  104. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  105. package/dist/core/ports/src/host-settings-store.js +106 -0
  106. package/dist/core/ports/src/index.d.ts +18 -10
  107. package/dist/core/ports/src/index.js +15 -7
  108. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  109. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  110. package/dist/core/ports/src/integration.d.ts +71 -7
  111. package/dist/core/ports/src/integration.js +22 -4
  112. package/dist/core/ports/src/llm-provider.d.ts +3 -1
  113. package/dist/core/ports/src/llm-provider.js +3 -0
  114. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  115. package/dist/core/ports/src/port-versions.d.ts +7 -4
  116. package/dist/core/ports/src/port-versions.js +6 -0
  117. package/dist/core/ports/src/program-probe.d.ts +25 -2
  118. package/dist/core/ports/src/program-probe.js +1 -1
  119. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  120. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  121. package/dist/core/ports/src/record-store.d.ts +17 -0
  122. package/dist/core/ports/src/record-store.js +70 -0
  123. package/dist/core/ports/src/run-executor.d.ts +5 -4
  124. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  125. package/dist/core/ports/src/run-target-not-found.js +41 -0
  126. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  127. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  128. package/dist/core/ports/src/sandbox.d.ts +130 -13
  129. package/dist/core/ports/src/sandbox.js +38 -2
  130. package/dist/core/ports/src/secrets.d.ts +73 -0
  131. package/dist/core/ports/src/secrets.js +56 -0
  132. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  133. package/dist/core/ports/src/tool-approval-store.js +59 -0
  134. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  135. package/dist/core/ports/src/vcs-status.js +90 -0
  136. package/dist/core/std/src/amount.d.ts +13 -0
  137. package/dist/core/std/src/amount.js +22 -0
  138. package/dist/core/std/src/hidden-characters.d.ts +19 -0
  139. package/dist/core/std/src/hidden-characters.js +54 -0
  140. package/dist/core/std/src/index.d.ts +5 -0
  141. package/dist/core/std/src/index.js +5 -0
  142. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  143. package/dist/core/std/src/public-suffixes.generated.js +10429 -0
  144. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  145. package/dist/core/std/src/registrable-domain.js +62 -0
  146. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  147. package/dist/core/std/src/secret-variable-name.js +34 -0
  148. package/dist/core/std/src/site-name.d.ts +35 -0
  149. package/dist/core/std/src/site-name.js +111 -0
  150. package/dist/core/std/src/url-host.d.ts +35 -0
  151. package/dist/core/std/src/url-host.js +170 -0
  152. package/dist/testing/integration/src/load.js +3 -1
  153. package/package.json +2 -2
@@ -0,0 +1,18 @@
1
+ /** The address a provider type calls when its YAML has no `baseUrl`, for the types that have a usual one. */
2
+ const defaultBaseUrls = {
3
+ openai: "https://api.openai.com/v1",
4
+ ollama: "http://localhost:11434/v1",
5
+ lmstudio: "http://localhost:1234/v1",
6
+ };
7
+ /**
8
+ * The address a provider of this type calls when it sets no `baseUrl`, or
9
+ * undefined when the type has no usual address. The adapters' presets and
10
+ * the cost rules both read this one table, so they can't drift apart.
11
+ *
12
+ * @example
13
+ * defaultBaseUrl("ollama"); // "http://localhost:11434/v1"
14
+ * defaultBaseUrl("openai-compatible"); // undefined
15
+ */
16
+ export function defaultBaseUrl(type) {
17
+ return Object.hasOwn(defaultBaseUrls, type) ? defaultBaseUrls[type] : undefined;
18
+ }
@@ -60,3 +60,20 @@ export declare function foldRecords(changes: readonly RecordChange[]): Map<strin
60
60
  * no `by`. Adapters write this in place of the collection's log.
61
61
  */
62
62
  export declare function compactedChanges(collection: string, changes: readonly RecordChange[]): RecordChange[];
63
+ /** Writes changes as record log lines: one JSON change per line, each ending in a line break. */
64
+ export declare function formatRecordLines(changes: readonly RecordChange[]): string;
65
+ /**
66
+ * Reads a collection log's whole lines back into changes. Every line must
67
+ * hold a change to this collection: one for another collection means the
68
+ * file was copied or renamed by hand. Pass only whole lines, each ending in
69
+ * a line break: a torn last line, from a crash or an append still being
70
+ * written, is the adapter's to leave out first.
71
+ *
72
+ * @param lines - the log's whole lines, or `""` for an empty log
73
+ * @param collection - the collection the log belongs to
74
+ * @param file - the log's name or path, for the error message
75
+ * @returns the changes, oldest first
76
+ * @throws RangeError when the text doesn't end in a line break
77
+ * @throws Error naming the file and line when a line is broken
78
+ */
79
+ export declare function parseRecordLines(lines: string, collection: string, file: string): RecordChange[];
@@ -36,3 +36,73 @@ export function compactedChanges(collection, changes) {
36
36
  values: record.values,
37
37
  }));
38
38
  }
39
+ // A collection's log file rules, which every adapter that keeps records as
40
+ // files applies: the CLI's `FileRecordStore` in `fs-node` and the desktop
41
+ // app's store in `fs-tauri`, whose shell writes the same files. Bytes stay
42
+ // with the adapters: each finds the log's whole lines and decodes them its
43
+ // own way, then reads them here.
44
+ const recordOps = new Set(["add", "update", "remove", "seed"]);
45
+ /** Writes changes as record log lines: one JSON change per line, each ending in a line break. */
46
+ export function formatRecordLines(changes) {
47
+ return changes.map((change) => `${JSON.stringify(change)}\n`).join("");
48
+ }
49
+ /**
50
+ * Reads a collection log's whole lines back into changes. Every line must
51
+ * hold a change to this collection: one for another collection means the
52
+ * file was copied or renamed by hand. Pass only whole lines, each ending in
53
+ * a line break: a torn last line, from a crash or an append still being
54
+ * written, is the adapter's to leave out first.
55
+ *
56
+ * @param lines - the log's whole lines, or `""` for an empty log
57
+ * @param collection - the collection the log belongs to
58
+ * @param file - the log's name or path, for the error message
59
+ * @returns the changes, oldest first
60
+ * @throws RangeError when the text doesn't end in a line break
61
+ * @throws Error naming the file and line when a line is broken
62
+ */
63
+ export function parseRecordLines(lines, collection, file) {
64
+ if (lines === "") {
65
+ return [];
66
+ }
67
+ if (!lines.endsWith("\n")) {
68
+ throw new RangeError(`Only whole lines of record log ${JSON.stringify(file)} can be read.`);
69
+ }
70
+ return lines
71
+ .slice(0, -1)
72
+ .split("\n")
73
+ .map((line, index) => parseRecordLine(line, index + 1, collection, file));
74
+ }
75
+ function parseRecordLine(line, number, collection, file) {
76
+ const broken = (why) => new Error(`Broken record log ${JSON.stringify(file)}, line ${number}: ${why}`);
77
+ let parsed;
78
+ try {
79
+ parsed = JSON.parse(line);
80
+ }
81
+ catch {
82
+ throw broken("it is not JSON.");
83
+ }
84
+ if (!isRecordChange(parsed)) {
85
+ throw broken("it is not a record change.");
86
+ }
87
+ if (parsed.collection !== collection) {
88
+ throw broken(`it holds a change to another collection, ${JSON.stringify(parsed.collection)}.`);
89
+ }
90
+ return parsed;
91
+ }
92
+ /** Whether a parsed line has the fields of a {@link RecordChange}, with the types the port gives them. */
93
+ function isRecordChange(value) {
94
+ if (!isPlainObject(value)) {
95
+ return false;
96
+ }
97
+ const { at, collection, id, op, values, by } = value;
98
+ return (typeof at === "string" &&
99
+ typeof collection === "string" &&
100
+ typeof id === "string" &&
101
+ typeof op === "string" &&
102
+ recordOps.has(op) &&
103
+ (values === null || isPlainObject(values)) &&
104
+ (by === undefined || isPlainObject(by)));
105
+ }
106
+ function isPlainObject(value) {
107
+ return typeof value === "object" && value !== null && !Array.isArray(value);
108
+ }
@@ -32,8 +32,8 @@ export interface StartRunRequest {
32
32
  * Which version of the workspace the run reads, as the caller loaded it:
33
33
  * the live version, with its commit and date, or the saved files. It goes
34
34
  * on `run.started`, and the run's child runs record it too. Not recorded
35
- * when absent. The executor doesn't check it against `definitionsOf`, so
36
- * the caller passes the version of the files it gives the run.
35
+ * when absent. The local executor passes it to `definitionsOf`, so the
36
+ * host gives the run that version's files; it doesn't check them against it.
37
37
  */
38
38
  version?: RunVersion;
39
39
  /**
@@ -217,14 +217,15 @@ export interface RunExecutor {
217
217
  /**
218
218
  * Starts a workflow run, or returns the existing one for a repeated `runId`.
219
219
  *
220
- * @throws when the hub or workflow doesn't exist or the input is refused
220
+ * @throws RunTargetNotFound when the hub or workflow doesn't exist
221
+ * @throws when the input is refused
221
222
  */
222
223
  start(request: StartRunRequest): Promise<RunSummary>;
223
224
  /**
224
225
  * Starts a run of one agent; its workflow id is "agent:<agentId>". A
225
226
  * repeated `runId` returns the existing run.
226
227
  *
227
- * @throws when the hub or agent doesn't exist
228
+ * @throws RunTargetNotFound when the hub or agent doesn't exist
228
229
  */
229
230
  startAgent(request: StartAgentRequest): Promise<RunSummary>;
230
231
  /**
@@ -0,0 +1,34 @@
1
+ /** What a run was asked to start does not exist: a hub, a workflow in a hub, or an agent in a hub. */
2
+ export type RunTargetKind = "hub" | "workflow" | "agent";
3
+ /**
4
+ * What {@link RunExecutor.start} and `startAgent` throw when the hub, the
5
+ * workflow or the agent the request names doesn't exist (requirement
6
+ * `ports.run-target-not-found`). A caller that answers a person, such as the
7
+ * host's run routes, can then tell a wrong name from a real failure.
8
+ *
9
+ * It is a `RangeError`, as the lookups threw before. Check for it with
10
+ * {@link isRunTargetNotFound}, not `instanceof`: an executor may be built
11
+ * against its own copy of this package.
12
+ *
13
+ * @example
14
+ * throw new RunTargetNotFound("workflow", "tidy", 'The hub "billing" has no workflow "tidy".');
15
+ */
16
+ export declare class RunTargetNotFound extends RangeError {
17
+ readonly name = "RunTargetNotFound";
18
+ /** Which kind of thing is missing. */
19
+ readonly kind: RunTargetKind;
20
+ /** The id the request named. */
21
+ readonly id: string;
22
+ /**
23
+ * @param kind - which kind of thing is missing
24
+ * @param id - the id the request named
25
+ * @param message - safe to log; the host doesn't send it to a client
26
+ */
27
+ constructor(kind: RunTargetKind, id: string, message: string);
28
+ }
29
+ /**
30
+ * Whether `value` is a {@link RunTargetNotFound}: an `Error` named
31
+ * "RunTargetNotFound" with a known `kind` and an `id`. It works across
32
+ * copies of this package, where `instanceof` doesn't.
33
+ */
34
+ export declare function isRunTargetNotFound(value: unknown): value is RunTargetNotFound;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * What {@link RunExecutor.start} and `startAgent` throw when the hub, the
3
+ * workflow or the agent the request names doesn't exist (requirement
4
+ * `ports.run-target-not-found`). A caller that answers a person, such as the
5
+ * host's run routes, can then tell a wrong name from a real failure.
6
+ *
7
+ * It is a `RangeError`, as the lookups threw before. Check for it with
8
+ * {@link isRunTargetNotFound}, not `instanceof`: an executor may be built
9
+ * against its own copy of this package.
10
+ *
11
+ * @example
12
+ * throw new RunTargetNotFound("workflow", "tidy", 'The hub "billing" has no workflow "tidy".');
13
+ */
14
+ export class RunTargetNotFound extends RangeError {
15
+ name = "RunTargetNotFound";
16
+ /** Which kind of thing is missing. */
17
+ kind;
18
+ /** The id the request named. */
19
+ id;
20
+ /**
21
+ * @param kind - which kind of thing is missing
22
+ * @param id - the id the request named
23
+ * @param message - safe to log; the host doesn't send it to a client
24
+ */
25
+ constructor(kind, id, message) {
26
+ super(message);
27
+ this.kind = kind;
28
+ this.id = id;
29
+ }
30
+ }
31
+ /**
32
+ * Whether `value` is a {@link RunTargetNotFound}: an `Error` named
33
+ * "RunTargetNotFound" with a known `kind` and an `id`. It works across
34
+ * copies of this package, where `instanceof` doesn't.
35
+ */
36
+ export function isRunTargetNotFound(value) {
37
+ if (!(value instanceof Error) || value.name !== "RunTargetNotFound")
38
+ return false;
39
+ const { kind, id } = value;
40
+ return (kind === "hub" || kind === "workflow" || kind === "agent") && typeof id === "string";
41
+ }
@@ -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,6 +79,8 @@ 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}.
62
84
  */
63
85
  export type SandboxCheck = {
64
86
  ok: true;
@@ -68,6 +90,39 @@ export type SandboxCheck = {
68
90
  ok: false;
69
91
  reason: SandboxUnavailableReason;
70
92
  missing: string[];
93
+ fix?: SandboxFix;
94
+ };
95
+ /**
96
+ * Every package manager a {@link SandboxFix} can name: `apt` (Debian,
97
+ * Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
98
+ * (Homebrew on macOS). The list is closed, and a new one is a port change.
99
+ */
100
+ export declare const sandboxPackageManagers: readonly ["apt", "dnf", "pacman", "zypper", "brew"];
101
+ /** A package manager a {@link SandboxFix} can name: one of {@link sandboxPackageManagers}. */
102
+ export type SandboxPackageManager = (typeof sandboxPackageManagers)[number];
103
+ /**
104
+ * What fixes a refused {@link SandboxCheck} on this machine, as data and
105
+ * never as words or a command line: Studio and the CLI word it. It is advice
106
+ * to show the person. No caller runs it or asks for administrator rights on
107
+ * its own; offering to run it is a new flow that needs the board's approval
108
+ * (docs/adr/2026-11-12-sandbox-check-fix-data.md).
109
+ *
110
+ * - `install`: install every package in `packages` with `packageManager`,
111
+ * as one command. `packageManager` is `null` when the machine has none
112
+ * that Halonic knows; then Studio names the packages only.
113
+ * - `apparmor-profile`: write `profile` to `path` and load it, which lets
114
+ * `program`, and only it, create user namespaces. The machine-wide setting
115
+ * stays on.
116
+ */
117
+ export type SandboxFix = {
118
+ kind: "install";
119
+ packageManager: SandboxPackageManager | null;
120
+ packages: string[];
121
+ } | {
122
+ kind: "apparmor-profile";
123
+ program: string;
124
+ path: string;
125
+ profile: string;
71
126
  };
72
127
  /**
73
128
  * What a program in the sandbox may reach. Halonic builds it from the
@@ -93,8 +148,23 @@ export interface SandboxProfile {
93
148
  settingsFolder: string | null;
94
149
  /** Paths the program may read but not change, such as the workspace's definition files. */
95
150
  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. */
151
+ /**
152
+ * Paths the program may not read or write, such as SSH keys and Halonic's
153
+ * own data. Wins over every other list, except that a path in
154
+ * {@link reopenedPaths} may be read again.
155
+ */
97
156
  deniedPaths: string[];
157
+ /**
158
+ * Paths inside a denied path that the program may read again, such as a
159
+ * run's own folders in Halonic's denied data folder. A writable folder
160
+ * inside a denied path must be listed here too; it stays writable. Each
161
+ * path must exist when the session opens, must lie inside a path of
162
+ * {@link deniedPaths}, and must not hold a writable folder (list the
163
+ * entries around that folder instead). An adapter refuses a profile that
164
+ * breaks one of these rules. Absent means none, so a profile that drops it
165
+ * can only deny more.
166
+ */
167
+ reopenedPaths?: string[] | undefined;
98
168
  /**
99
169
  * The only environment variables the program gets, by name and value. The
100
170
  * host's own environment is never passed on.
@@ -104,23 +174,52 @@ export interface SandboxProfile {
104
174
  network: SandboxNetwork;
105
175
  /** How long the whole run may last, in milliseconds, counted from {@link Sandbox.open}. */
106
176
  timeLimitMs: number;
177
+ /**
178
+ * Whether the program may ask the operating system's key store for a
179
+ * stored secret. `denied` for code nobody reviewed, such as a local
180
+ * integration (attack case A36). Left out, it may, because an agent can
181
+ * keep its own sign-in in the macOS Keychain. With `denied`, the fence on
182
+ * macOS refuses the Keychain's Mach services. On Linux the Secret Service
183
+ * is a D-Bus socket, so hide its folder in {@link deniedPaths}. On Windows
184
+ * no adapter can fence the Credential Manager yet.
185
+ */
186
+ keyStore?: "allowed" | "denied";
107
187
  }
188
+ /**
189
+ * Where the program reaches the Halonic bridge.
190
+ *
191
+ * - `loopback`: a port on this computer's loopback, `host` being `127.0.0.1`,
192
+ * `::1` or `localhost`. The program dials it as it is.
193
+ * - `socket`: the bridge serves a Unix socket at `socketPath`, an absolute
194
+ * path, and the program calls it by `name`, a host name that never
195
+ * resolves, such as `bridge.halonic.invalid`. The sandbox's own proxy,
196
+ * outside the fence, sends requests for that name, on port 80 only, to the
197
+ * socket, so no port is open to anything else on the computer. The program
198
+ * never opens the socket itself.
199
+ */
200
+ export type SandboxBridge = {
201
+ kind: "loopback";
202
+ host: string;
203
+ port: number;
204
+ } | {
205
+ kind: "socket";
206
+ name: string;
207
+ socketPath: string;
208
+ };
108
209
  /** The network a {@link SandboxProfile} allows. */
109
210
  export interface SandboxNetwork {
110
211
  /**
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.
212
+ * The Halonic bridge: the one address on this computer the program can
213
+ * reach. An adapter rejects, when {@link Sandbox.open} is called, a
214
+ * `loopback` bridge whose host is not a loopback address, and a bridge kind
215
+ * it can't serve.
114
216
  *
115
217
  * `null` means no bridge: the program reaches no loopback address at all,
116
218
  * only the allowed sites. The integration runner uses it, because it talks
117
219
  * to Halonic over its standard input and output, not the network. The field
118
220
  * is never optional, so leaving it out can't mean "the whole network".
119
221
  */
120
- bridge: {
121
- host: string;
122
- port: number;
123
- } | null;
222
+ bridge: SandboxBridge | null;
124
223
  /**
125
224
  * Further sites, by host name such as "registry.npmjs.org" or with a
126
225
  * leading "*." for every subdomain. Empty by default.
@@ -133,7 +232,25 @@ export interface SandboxCommand {
133
232
  program: string;
134
233
  /** Its arguments, passed as they are, never through a shell. */
135
234
  args: string[];
136
- /** Where it starts: the working folder or a folder inside it. Absent means the working folder. */
235
+ /**
236
+ * Where it starts, read against the working folder. Absent means the
237
+ * working folder. It must lie, where it really is through symbolic links,
238
+ * inside the working folder or inside a path of
239
+ * {@link SandboxProfile.readOnlyPaths}, and not inside a path of
240
+ * {@link SandboxProfile.deniedPaths} unless that part is reopened.
241
+ * {@link SandboxSession.start} throws on any other folder (HAL-6884).
242
+ *
243
+ * A folder in a read-only path stays read-only: a workspace connector
244
+ * starts where its script and `node_modules` are, but writes only to the
245
+ * working and temp folders. A program that writes next to its script fails
246
+ * there, such as `uv run` making `.venv`; the caller points it elsewhere,
247
+ * as with `UV_PROJECT_ENVIRONMENT`.
248
+ *
249
+ * The fence's own write rules for tool settings and git hooks in folders
250
+ * nested in the working folder, such as `sub/.claude/`, follow the start
251
+ * folder. Only start outside the working folder when that working folder
252
+ * is thrown away when the session closes, as a connector's own is.
253
+ */
137
254
  cwd?: string;
138
255
  }
139
256
  /** How a started program ended. */
@@ -239,7 +356,7 @@ export interface Sandbox {
239
356
  * Opens a session for one run. Cancelling the run, by aborting `signal`,
240
357
  * closes the session.
241
358
  *
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
359
+ * @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
360
  */
244
361
  open(profile: SandboxProfile, options?: {
245
362
  signal?: AbortSignal;
@@ -9,26 +9,62 @@
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 package manager a {@link SandboxFix} can name: `apt` (Debian,
67
+ * Ubuntu), `dnf` (Fedora), `pacman` (Arch), `zypper` (openSUSE) and `brew`
68
+ * (Homebrew on macOS). The list is closed, and a new one is a port change.
69
+ */
70
+ export const sandboxPackageManagers = ["apt", "dnf", "pacman", "zypper", "brew"];