@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.
- package/NOTICE +4 -0
- package/README.md +1 -1
- package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
- package/dist/adapters/http-kit/src/address-checking.js +1 -0
- package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +3 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
- package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
- package/dist/adapters/integration-kit/src/declaration.js +4 -3
- package/dist/adapters/integration-kit/src/host.d.ts +7 -1
- package/dist/adapters/integration-kit/src/host.js +1 -0
- package/dist/adapters/integration-kit/src/index.d.ts +5 -2
- package/dist/adapters/integration-kit/src/index.js +2 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
- package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
- package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
- package/dist/adapters/integration-kit/src/limited-http.js +53 -10
- package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
- package/dist/adapters/integration-kit/src/loader.js +36 -21
- package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
- package/dist/adapters/integration-kit/src/own-request.js +1 -1
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
- package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
- package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
- package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
- package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
- package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
- package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/blocked-sites.d.ts +57 -0
- package/dist/core/events/src/blocked-sites.js +89 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +8 -2
- package/dist/core/events/src/index.js +5 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +131 -10
- package/dist/core/events/src/run-event.d.ts +120 -11
- package/dist/core/events/src/run-reads.d.ts +25 -0
- package/dist/core/events/src/run-reads.js +44 -0
- package/dist/core/events/src/run-sends.d.ts +47 -0
- package/dist/core/events/src/run-sends.js +68 -0
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +8 -1
- package/dist/core/events/src/timeline-entry.js +1 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +9 -6
- package/dist/core/format/src/index.js +7 -3
- package/dist/core/format/src/integration/index.d.ts +3 -2
- package/dist/core/format/src/integration/index.js +2 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +5 -2
- package/dist/core/format/src/kinds/connector/is-local.js +1 -1
- package/dist/core/format/src/kinds/connector/kind.js +122 -2
- package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
- package/dist/core/format/src/kinds/connector/schema.js +71 -2
- package/dist/core/format/src/kinds/deployments/kind.js +25 -1
- package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
- package/dist/core/format/src/kinds/deployments/schema.js +52 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
- package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
- package/dist/core/format/src/kinds/integration/host-key.js +8 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
- package/dist/core/format/src/kinds/integration/kind.js +49 -12
- package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
- package/dist/core/format/src/kinds/integration/policy.js +61 -2
- package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
- package/dist/core/format/src/kinds/integration/schema.js +133 -7
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +24 -6
- package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
- package/dist/core/format/src/kinds/plugin/schema.js +26 -6
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
- package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.js +38 -1
- package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
- package/dist/core/format/src/kinds/routine/schema.js +42 -14
- package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
- package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
- package/dist/core/format/src/kinds/workflow/schema.js +1 -1
- package/dist/core/format/src/kinds/workspace/kind.js +1 -1
- package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
- package/dist/core/format/src/kinds/workspace/schema.js +6 -5
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +12 -8
- package/dist/core/format/src/shared/fields.js +48 -19
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
- package/dist/core/ports/src/agent-runs-not-available.js +25 -0
- package/dist/core/ports/src/blob-store.d.ts +12 -0
- package/dist/core/ports/src/blob-store.js +22 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-client.d.ts +48 -4
- package/dist/core/ports/src/connector-client.js +17 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +36 -5
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
- package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
- package/dist/core/ports/src/harness-sign-in-command.js +31 -0
- package/dist/core/ports/src/harness.d.ts +79 -15
- package/dist/core/ports/src/harness.js +1 -1
- package/dist/core/ports/src/host-settings-store.d.ts +116 -0
- package/dist/core/ports/src/host-settings-store.js +106 -0
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +32 -13
- package/dist/core/ports/src/index.js +28 -8
- package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
- package/dist/core/ports/src/instruction-trust-store.js +43 -0
- package/dist/core/ports/src/integration.d.ts +71 -7
- package/dist/core/ports/src/integration.js +22 -4
- package/dist/core/ports/src/llm-provider.d.ts +39 -6
- package/dist/core/ports/src/llm-provider.js +46 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/password-hasher.d.ts +36 -20
- package/dist/core/ports/src/port-versions.d.ts +13 -6
- package/dist/core/ports/src/port-versions.js +14 -0
- package/dist/core/ports/src/program-probe.d.ts +25 -2
- package/dist/core/ports/src/program-probe.js +1 -1
- package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
- package/dist/core/ports/src/provider-default-base-url.js +18 -0
- package/dist/core/ports/src/record-store.d.ts +17 -0
- package/dist/core/ports/src/record-store.js +70 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +44 -7
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
- package/dist/core/ports/src/run-target-not-found.js +41 -0
- package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
- package/dist/core/ports/src/sandbox-setting-store.js +33 -0
- package/dist/core/ports/src/sandbox.d.ts +149 -13
- package/dist/core/ports/src/sandbox.js +52 -2
- package/dist/core/ports/src/secrets.d.ts +105 -1
- package/dist/core/ports/src/secrets.js +75 -2
- package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
- package/dist/core/ports/src/tool-approval-store.js +59 -0
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs-status.d.ts +8 -0
- package/dist/core/ports/src/vcs-status.js +90 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/amount.d.ts +13 -0
- package/dist/core/std/src/amount.js +22 -0
- package/dist/core/std/src/hidden-characters.d.ts +28 -0
- package/dist/core/std/src/hidden-characters.js +72 -0
- package/dist/core/std/src/index.d.ts +7 -0
- package/dist/core/std/src/index.js +7 -0
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
- package/dist/core/std/src/public-suffixes.generated.js +10428 -0
- package/dist/core/std/src/registrable-domain.d.ts +10 -0
- package/dist/core/std/src/registrable-domain.js +62 -0
- package/dist/core/std/src/secret-variable-name.d.ts +12 -0
- package/dist/core/std/src/secret-variable-name.js +34 -0
- package/dist/core/std/src/site-name.d.ts +35 -0
- package/dist/core/std/src/site-name.js +111 -0
- package/dist/core/std/src/url-host.d.ts +35 -0
- package/dist/core/std/src/url-host.js +170 -0
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/dist/testing/integration/src/load.js +3 -1
- package/package.json +9 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Version of the {@link ProgramProbe} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
-
export declare const programProbeVersion =
|
|
2
|
+
export declare const programProbeVersion = 2;
|
|
3
3
|
/**
|
|
4
4
|
* What asking a program something answered. `missing`: no program of that
|
|
5
5
|
* name is where Halonic looks for it. `ran`: it ran and ended, with what it
|
|
@@ -20,6 +20,26 @@ export type ProgramProbeResult = {
|
|
|
20
20
|
path: string;
|
|
21
21
|
error: string;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The program's own settings folder, for a question about one agent's
|
|
25
|
+
* settings, such as whether that agent is signed in. `variable` is the
|
|
26
|
+
* environment variable that points the program at the folder, such as
|
|
27
|
+
* "CLAUDE_CONFIG_DIR"; `path` is the folder, an absolute path.
|
|
28
|
+
*/
|
|
29
|
+
export interface ProgramSettingsFolder {
|
|
30
|
+
readonly variable: string;
|
|
31
|
+
readonly path: string;
|
|
32
|
+
}
|
|
33
|
+
/** What else a question to a program may say. */
|
|
34
|
+
export interface ProgramQuestion {
|
|
35
|
+
/**
|
|
36
|
+
* Asks the program about this settings folder instead of the person's
|
|
37
|
+
* own. A probe sets only this variable on top of what it always passes,
|
|
38
|
+
* and refuses a variable it doesn't know as `failed`, so this can't pass
|
|
39
|
+
* anything else to the program.
|
|
40
|
+
*/
|
|
41
|
+
readonly settingsFolder?: ProgramSettingsFolder;
|
|
42
|
+
}
|
|
23
43
|
/**
|
|
24
44
|
* Finds a program on this machine and asks it something short, such as
|
|
25
45
|
* `claude --version`, the way a harness's `detect()` needs (requirement
|
|
@@ -34,6 +54,9 @@ export type ProgramProbeResult = {
|
|
|
34
54
|
* @example
|
|
35
55
|
* const answer = await probe.ask("codex", ["--version"]);
|
|
36
56
|
* if (answer.status === "missing") return { status: "missing" };
|
|
57
|
+
* const signIn = await probe.ask("codex", ["login", "status"], {
|
|
58
|
+
* settingsFolder: { variable: "CODEX_HOME", path: agentFolder },
|
|
59
|
+
* });
|
|
37
60
|
*/
|
|
38
61
|
export interface ProgramProbe {
|
|
39
62
|
/**
|
|
@@ -42,5 +65,5 @@ export interface ProgramProbe {
|
|
|
42
65
|
*
|
|
43
66
|
* @param program a bare name, such as "claude". A name with a path separator is `missing`.
|
|
44
67
|
*/
|
|
45
|
-
ask(program: string, args: readonly string[]): Promise<ProgramProbeResult>;
|
|
68
|
+
ask(program: string, args: readonly string[], question?: ProgramQuestion): Promise<ProgramProbeResult>;
|
|
46
69
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Version of the {@link ProgramProbe} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
-
export const programProbeVersion =
|
|
2
|
+
export const programProbeVersion = 2;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address a provider of this type calls when it sets no `baseUrl`, or
|
|
3
|
+
* undefined when the type has no usual address. The adapters' presets and
|
|
4
|
+
* the cost rules both read this one table, so they can't drift apart.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* defaultBaseUrl("ollama"); // "http://localhost:11434/v1"
|
|
8
|
+
* defaultBaseUrl("openai-compatible"); // undefined
|
|
9
|
+
*/
|
|
10
|
+
export declare function defaultBaseUrl(type: string): string | undefined;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { TunnelReason, TunnelStatus } from "./tunnel-provider.js";
|
|
2
|
+
/** Version of the {@link RemoteControl} port. A breaking change bumps it and comes with an ADR. */
|
|
3
|
+
export declare const remoteControlVersion = 1;
|
|
4
|
+
/** The platforms a paired phone can report. */
|
|
5
|
+
export declare const phonePlatforms: readonly ["android", "ios"];
|
|
6
|
+
/** One of {@link phonePlatforms}. */
|
|
7
|
+
export type PhonePlatform = (typeof phonePlatforms)[number];
|
|
8
|
+
/** A phone this computer has paired. Only public data: the host keeps no secret of the phone's. */
|
|
9
|
+
export interface PairedPhone {
|
|
10
|
+
/** The device id: a hash of the phone's public key, stable for as long as it stays paired. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** The name the phone gave, with " (2)", " (3)" and so on when another paired phone has it already. */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly platform: PhonePlatform;
|
|
15
|
+
/** When Allow was pressed, as an ISO 8601 time. */
|
|
16
|
+
readonly pairedAt: string;
|
|
17
|
+
/** When its last session ended, refreshed about once a minute while one is open; absent before the first ends. */
|
|
18
|
+
readonly lastSeenAt?: string;
|
|
19
|
+
/** Whether a session with it is open now. */
|
|
20
|
+
readonly connected: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** What Settings › Remote and the status bar show, as one snapshot. */
|
|
23
|
+
export interface RemoteState {
|
|
24
|
+
/**
|
|
25
|
+
* Whether this host offers remote at all. While it is `false`, Studio shows
|
|
26
|
+
* no Remote section, and `setRemote(true)` and `startPairing` reject.
|
|
27
|
+
*/
|
|
28
|
+
readonly available: boolean;
|
|
29
|
+
/** Whether the person turned remote on. Phones stay paired while it is off. */
|
|
30
|
+
readonly on: boolean;
|
|
31
|
+
/** The tunnel provider's id, such as "tailscale", so Studio can word its reasons. */
|
|
32
|
+
readonly tunnelProviderId: string;
|
|
33
|
+
/** The tunnel's state and reason; `down` with `stopped` while remote is off. */
|
|
34
|
+
readonly tunnel: TunnelStatus;
|
|
35
|
+
/** "Let phones answer risky approvals": off by default, and settable while remote is off. */
|
|
36
|
+
readonly allowRiskyRemotely: boolean;
|
|
37
|
+
/** The paired phones, oldest pairing first. */
|
|
38
|
+
readonly phones: readonly PairedPhone[];
|
|
39
|
+
/** Whether a pairing is open now; there is at most one at a time. */
|
|
40
|
+
readonly pairing: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Why a code stopped working while its pairing stays open, waiting for `newCode` or `close`. */
|
|
43
|
+
export declare const codeEndReasons: readonly [
|
|
44
|
+
/** Pressed Don't allow. */
|
|
45
|
+
"denied",
|
|
46
|
+
/** Allow wasn't pressed within the wait. */
|
|
47
|
+
"allow-timed-out",
|
|
48
|
+
/** No phone came within the code's life. */
|
|
49
|
+
"code-expired",
|
|
50
|
+
/** The code took its last wrong try. */
|
|
51
|
+
"too-many-tries"];
|
|
52
|
+
/** One of {@link codeEndReasons}. */
|
|
53
|
+
export type CodeEndReason = (typeof codeEndReasons)[number];
|
|
54
|
+
/** Why a pairing ended without a phone. */
|
|
55
|
+
export declare const pairingEndReasons: readonly [
|
|
56
|
+
/** The dialog was closed, or `close` was called. */
|
|
57
|
+
"closed",
|
|
58
|
+
/** Remote was turned off. */
|
|
59
|
+
"remote-off",
|
|
60
|
+
/** The tunnel didn't come up or went down; the event says why. */
|
|
61
|
+
"tunnel-down",
|
|
62
|
+
/** Another pairing is already open. */
|
|
63
|
+
"busy"];
|
|
64
|
+
/** One of {@link pairingEndReasons}. */
|
|
65
|
+
export type PairingEndReason = (typeof pairingEndReasons)[number];
|
|
66
|
+
/**
|
|
67
|
+
* One step of a pairing. It starts with `code` (unless it ends at once),
|
|
68
|
+
* then `check` once a phone has used the code. A code that stops working
|
|
69
|
+
* gives `code-ended`, and the pairing stays open: `newCode` gives a new
|
|
70
|
+
* `code`. The pairing ends with exactly one of `paired` or `ended`.
|
|
71
|
+
*/
|
|
72
|
+
export type PairingEvent = {
|
|
73
|
+
/** Show this code and QR code; waiting for a phone. */
|
|
74
|
+
readonly type: "code";
|
|
75
|
+
/** The pairing code, in its plain 12-symbol form. */
|
|
76
|
+
readonly code: string;
|
|
77
|
+
/** The QR code's text, `halonic-pair:…`. */
|
|
78
|
+
readonly qr: string;
|
|
79
|
+
/** The name this computer gives itself, for "choose Tim's laptop". */
|
|
80
|
+
readonly hostName: string;
|
|
81
|
+
/** When the code stops working, as an ISO 8601 time. */
|
|
82
|
+
readonly expiresAt: string;
|
|
83
|
+
} | {
|
|
84
|
+
/** A phone used the code: show the check code and wait for Allow. */
|
|
85
|
+
readonly type: "check";
|
|
86
|
+
/** The check code, in its plain 6-symbol form. */
|
|
87
|
+
readonly checkCode: string;
|
|
88
|
+
readonly phoneName: string;
|
|
89
|
+
readonly platform: PhonePlatform;
|
|
90
|
+
/** When the wait for Allow ends, as an ISO 8601 time. */
|
|
91
|
+
readonly allowBy: string;
|
|
92
|
+
} | {
|
|
93
|
+
/** The code stopped working; the pairing waits for `newCode` or `close`. */
|
|
94
|
+
readonly type: "code-ended";
|
|
95
|
+
readonly reason: CodeEndReason;
|
|
96
|
+
} | {
|
|
97
|
+
readonly type: "paired";
|
|
98
|
+
readonly phone: PairedPhone;
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "ended";
|
|
101
|
+
readonly reason: Exclude<PairingEndReason, "tunnel-down">;
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "ended";
|
|
104
|
+
readonly reason: "tunnel-down";
|
|
105
|
+
/** Why, as the tunnel said it; remote may be off again by the time Studio shows it. */
|
|
106
|
+
readonly tunnelReason: TunnelReason;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* One open pairing, as the Pair a phone dialog drives it: one session for as
|
|
110
|
+
* long as the dialog is open, however many codes it shows (design decision 10).
|
|
111
|
+
*/
|
|
112
|
+
export interface PairingSession {
|
|
113
|
+
/**
|
|
114
|
+
* Every event so far, then each new one; the stream ends after `paired`
|
|
115
|
+
* or `ended`. Each call gives a new stream.
|
|
116
|
+
*/
|
|
117
|
+
events(): AsyncIterable<PairingEvent>;
|
|
118
|
+
/** Pairs the phone. Rejects unless the last event is `check`. */
|
|
119
|
+
allow(): Promise<void>;
|
|
120
|
+
/** Refuses the phone: the code ends with `denied`. Rejects unless the last event is `check`. */
|
|
121
|
+
deny(): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Ends the current code, if it still works, without a `code-ended`, and
|
|
124
|
+
* gives a new `code` on this session. A phone waiting at `check` is
|
|
125
|
+
* refused. Remote stays on. Rejects once the pairing has ended.
|
|
126
|
+
*/
|
|
127
|
+
newCode(): Promise<void>;
|
|
128
|
+
/** Ends the pairing with `closed`. Does nothing once it has ended. */
|
|
129
|
+
close(): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* How Studio turns remote on and off, pairs and revokes phones and sets the
|
|
133
|
+
* risky-approvals switch, on loopback to the host (requirement
|
|
134
|
+
* `ports.remote-control`). The host does the work and keeps the rules
|
|
135
|
+
* (ADR "Pairing and the end-to-end session"); Studio only shows and asks.
|
|
136
|
+
*
|
|
137
|
+
* `startPairing` turns remote on when it was off, and a pairing that ends
|
|
138
|
+
* without a phone turns it off again if it did so and no phone is paired.
|
|
139
|
+
* A code that stops working doesn't end its pairing, so a new code never
|
|
140
|
+
* restarts the tunnel.
|
|
141
|
+
* Revoking a phone closes its session at once; its agents keep running.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const pairing = await remote.startPairing();
|
|
145
|
+
* for await (const event of pairing.events()) dialog.show(event);
|
|
146
|
+
*/
|
|
147
|
+
export interface RemoteControl {
|
|
148
|
+
/** The current state first, then every change. Each call gives a new stream. */
|
|
149
|
+
state(): AsyncIterable<RemoteState>;
|
|
150
|
+
/** Turns remote on or off. Turning it off ends an open pairing with `remote-off`. */
|
|
151
|
+
setRemote(on: boolean): Promise<void>;
|
|
152
|
+
/** Opens a pairing; a second one while one is open ends at once with `busy`. */
|
|
153
|
+
startPairing(): Promise<PairingSession>;
|
|
154
|
+
/** Unpairs one phone. An id that isn't paired does nothing. */
|
|
155
|
+
revoke(phoneId: string): Promise<void>;
|
|
156
|
+
/** Unpairs every phone. */
|
|
157
|
+
revokeAll(): Promise<void>;
|
|
158
|
+
setAllowRiskyRemotely(allow: boolean): Promise<void>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Version of the {@link RemoteControl} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export const remoteControlVersion = 1;
|
|
3
|
+
/** The platforms a paired phone can report. */
|
|
4
|
+
export const phonePlatforms = ["android", "ios"];
|
|
5
|
+
/** Why a code stopped working while its pairing stays open, waiting for `newCode` or `close`. */
|
|
6
|
+
export const codeEndReasons = [
|
|
7
|
+
/** Pressed Don't allow. */
|
|
8
|
+
"denied",
|
|
9
|
+
/** Allow wasn't pressed within the wait. */
|
|
10
|
+
"allow-timed-out",
|
|
11
|
+
/** No phone came within the code's life. */
|
|
12
|
+
"code-expired",
|
|
13
|
+
/** The code took its last wrong try. */
|
|
14
|
+
"too-many-tries",
|
|
15
|
+
];
|
|
16
|
+
/** Why a pairing ended without a phone. */
|
|
17
|
+
export const pairingEndReasons = [
|
|
18
|
+
/** The dialog was closed, or `close` was called. */
|
|
19
|
+
"closed",
|
|
20
|
+
/** Remote was turned off. */
|
|
21
|
+
"remote-off",
|
|
22
|
+
/** The tunnel didn't come up or went down; the event says why. */
|
|
23
|
+
"tunnel-down",
|
|
24
|
+
/** Another pairing is already open. */
|
|
25
|
+
"busy",
|
|
26
|
+
];
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remote gateway protocol: what a phone and the desktop host's remote
|
|
3
|
+
* gateway say to each other, inside the end-to-end session (requirement
|
|
4
|
+
* `ports.remote-gateway-protocol`). It covers sessions, their events,
|
|
5
|
+
* approvals and prompt input, the end of a pairing, and nothing else. Each
|
|
6
|
+
* message is one JSON object in one Noise transport message; nothing here is
|
|
7
|
+
* ever sent in cleartext. The session around it is in
|
|
8
|
+
* `remote-gateway-session.ts` (ADR "Pairing and the end-to-end session").
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The protocol version. Both sides send it in `hello` and `welcome`, and the
|
|
12
|
+
* Noise prologue names it too, so a peer of another version fails the
|
|
13
|
+
* handshake. A host speaks exactly one and there is no negotiation. The host
|
|
14
|
+
* answers a `hello` with another version with `unsupported-version` and
|
|
15
|
+
* closes; the phone closes on a `welcome` with another version.
|
|
16
|
+
*/
|
|
17
|
+
export declare const gatewayProtocolVersion = 2;
|
|
18
|
+
/**
|
|
19
|
+
* The largest message either side accepts, in bytes of its UTF-8 JSON: one
|
|
20
|
+
* Noise transport message (65,535 bytes) less its 16-byte tag. A larger one is
|
|
21
|
+
* refused: the host sends `error` with `too-large` and closes. The host checks
|
|
22
|
+
* the size before it parses.
|
|
23
|
+
*/
|
|
24
|
+
export declare const gatewayMaxMessageBytes: number;
|
|
25
|
+
/**
|
|
26
|
+
* The longest prompt text, in UTF-16 code units. It is set from the worst
|
|
27
|
+
* case: JSON writes a control character or a lone surrogate as six bytes, so
|
|
28
|
+
* 10,000 of them take 60,000 bytes and still fit in one message with the
|
|
29
|
+
* envelope. A prompt within this length never gets `too-large`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const gatewayMaxPromptLength = 10000;
|
|
32
|
+
/**
|
|
33
|
+
* The longest id, the phone's or the host's. Every id is 1 to this many
|
|
34
|
+
* characters from `A`–`Z`, `a`–`z`, `0`–`9`, `_` and `-`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const gatewayMaxIdLength = 128;
|
|
37
|
+
/**
|
|
38
|
+
* The most sessions one connection may watch at once. A `watch` for one more
|
|
39
|
+
* gets `too-many-watches` and leaves the connection open.
|
|
40
|
+
*/
|
|
41
|
+
export declare const gatewayMaxWatches = 16;
|
|
42
|
+
/**
|
|
43
|
+
* The most bytes the host holds unsent for one connection. A phone that
|
|
44
|
+
* reads more slowly than its sessions produce events is closed when this is
|
|
45
|
+
* exceeded, never buffered without limit; it resumes by watching again.
|
|
46
|
+
*/
|
|
47
|
+
export declare const gatewayMaxBufferedBytes: number;
|
|
48
|
+
/** A session as the phone lists it. `waiting` means an approval waits for an answer. */
|
|
49
|
+
export interface GatewaySession {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly title: string;
|
|
52
|
+
readonly state: "running" | "waiting" | "done" | "failed";
|
|
53
|
+
/** The sequence number of the session's newest event. */
|
|
54
|
+
readonly lastSeq: number;
|
|
55
|
+
readonly updatedAt: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An approval the phone may show. Only the host sets `risk`; the phone's
|
|
59
|
+
* answer carries none. A `risky` approval (a shell command, a file write, a
|
|
60
|
+
* secret, leaving the sandbox) is refused by default: every answer to it
|
|
61
|
+
* gets `not-allowed-remotely` unless the person has allowed remote answers
|
|
62
|
+
* to risky approvals for this host on the desktop. The phone asks for a
|
|
63
|
+
* biometric unlock before it sends one, but the host can't check that and
|
|
64
|
+
* never treats it as proof.
|
|
65
|
+
*/
|
|
66
|
+
export interface GatewayApproval {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly summary: string;
|
|
69
|
+
readonly risk: "normal" | "risky";
|
|
70
|
+
/** The connector the tool comes from, when it comes from one, so the phone can say which connector asks. */
|
|
71
|
+
readonly connector?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What happened in a session, as narrow as the phone needs. The host shortens
|
|
75
|
+
* a `message` text that would make its event larger than
|
|
76
|
+
* {@link gatewayMaxMessageBytes} and ends it with "…"; the full text stays on
|
|
77
|
+
* the desktop.
|
|
78
|
+
*/
|
|
79
|
+
export type GatewayEventBody = {
|
|
80
|
+
readonly type: "message";
|
|
81
|
+
readonly role: "user" | "agent";
|
|
82
|
+
readonly text: string;
|
|
83
|
+
} | {
|
|
84
|
+
readonly type: "state";
|
|
85
|
+
readonly state: GatewaySession["state"];
|
|
86
|
+
} | {
|
|
87
|
+
readonly type: "approval-requested";
|
|
88
|
+
readonly approval: GatewayApproval;
|
|
89
|
+
} | {
|
|
90
|
+
readonly type: "approval-settled";
|
|
91
|
+
readonly approvalId: string;
|
|
92
|
+
readonly decision: "approve" | "deny";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Why the host refused a message and closed the connection. Such an `error`
|
|
96
|
+
* has no `replyTo`, since the message it answers may not have parsed.
|
|
97
|
+
*/
|
|
98
|
+
export declare const gatewayClosingErrorCodes: readonly ["malformed", "too-large", "unsupported-version"];
|
|
99
|
+
/** Why the host refused a well-formed message and kept the connection open. */
|
|
100
|
+
export declare const gatewayRefusalCodes: readonly ["unknown-session", "unknown-approval", "not-allowed-remotely", "history-gone", "too-many-watches"];
|
|
101
|
+
/** Every error code, closing ones first. Studio words each code. */
|
|
102
|
+
export declare const gatewayErrorCodes: readonly ["malformed", "too-large", "unsupported-version", "unknown-session", "unknown-approval", "not-allowed-remotely", "history-gone", "too-many-watches"];
|
|
103
|
+
/** One of {@link gatewayErrorCodes}. */
|
|
104
|
+
export type GatewayErrorCode = (typeof gatewayErrorCodes)[number];
|
|
105
|
+
/**
|
|
106
|
+
* What the phone sends. `id` is the phone's own id for the message; the
|
|
107
|
+
* host's `ok` or refusal names it in `replyTo`.
|
|
108
|
+
*
|
|
109
|
+
* - `hello` comes first on every connection, also after a reconnect, and
|
|
110
|
+
* only once.
|
|
111
|
+
* - `watch` streams a session's events after `afterSeq`, then each new one.
|
|
112
|
+
* `afterSeq` 0 starts from the oldest event the host keeps; the host keeps
|
|
113
|
+
* every event from the oldest `approval-requested` that isn't settled.
|
|
114
|
+
* A `watch` for a session already watched replaces that watch.
|
|
115
|
+
* - **Resume.** Each session's `seq` starts at 1 and grows by one per event,
|
|
116
|
+
* never reused. After a reconnect the phone watches again from the last
|
|
117
|
+
* `seq` it saw. An `afterSeq` above the session's `lastSeq` is `malformed`.
|
|
118
|
+
* When the events after `afterSeq` are gone, the host answers
|
|
119
|
+
* `history-gone`. On `history-gone`, or a gap in `seq` within a watch, the
|
|
120
|
+
* phone drops what it holds for the session and watches from 0. It shows
|
|
121
|
+
* an approval only from an `approval-requested` event not followed by its
|
|
122
|
+
* `approval-settled`; an answer to a settled or unknown approval gets
|
|
123
|
+
* `unknown-approval`.
|
|
124
|
+
*/
|
|
125
|
+
export type GatewayClientMessage = {
|
|
126
|
+
readonly type: "hello";
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly version: number;
|
|
129
|
+
} | {
|
|
130
|
+
readonly type: "list-sessions";
|
|
131
|
+
readonly id: string;
|
|
132
|
+
} | {
|
|
133
|
+
readonly type: "watch";
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly sessionId: string;
|
|
136
|
+
readonly afterSeq: number;
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "unwatch";
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly sessionId: string;
|
|
141
|
+
} | {
|
|
142
|
+
readonly type: "answer-approval";
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly sessionId: string;
|
|
145
|
+
readonly approvalId: string;
|
|
146
|
+
readonly decision: "approve" | "deny";
|
|
147
|
+
} | {
|
|
148
|
+
readonly type: "prompt";
|
|
149
|
+
readonly id: string;
|
|
150
|
+
readonly sessionId: string;
|
|
151
|
+
readonly text: string;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Why the host ended a pairing after the phone's message 3 decrypted: the
|
|
155
|
+
* person pressed Don't allow, or didn't press Allow in time. Refusals before
|
|
156
|
+
* that are cleartext frames (`PairRefusedReason` in `remote-gateway-session.ts`).
|
|
157
|
+
*/
|
|
158
|
+
export type GatewayPairDeniedReason = "denied" | "timed-out";
|
|
159
|
+
/**
|
|
160
|
+
* What the host sends.
|
|
161
|
+
*
|
|
162
|
+
* **Pairing and reconnecting.** At the end of a pairing the host sends
|
|
163
|
+
* `paired` once the person pressed Allow, or `pair-refused` and closes; the
|
|
164
|
+
* phone sends nothing before either. After a reconnect the host sends
|
|
165
|
+
* `not-paired` and closes when it doesn't know the phone's key; it sends it
|
|
166
|
+
* only after its handshake message has proved who it is, and also at once
|
|
167
|
+
* when the phone is revoked while connected. Then, and after `paired`, the
|
|
168
|
+
* phone's first message is `hello`.
|
|
169
|
+
*
|
|
170
|
+
* **Error and close.** The host sends one `error` with a code from
|
|
171
|
+
* {@link gatewayClosingErrorCodes}, without `replyTo`, then closes the
|
|
172
|
+
* connection, for:
|
|
173
|
+
* - `too-large`: more than {@link gatewayMaxMessageBytes} bytes;
|
|
174
|
+
* - `unsupported-version`: a `hello` whose `version` isn't
|
|
175
|
+
* {@link gatewayProtocolVersion};
|
|
176
|
+
* - `malformed`: anything else that isn't exactly one listed message. That is
|
|
177
|
+
* bytes that aren't valid UTF-8, text that isn't one JSON object, an
|
|
178
|
+
* unlisted `type`, a missing, extra or wrongly typed field, an id that
|
|
179
|
+
* breaks {@link gatewayMaxIdLength}, an `afterSeq` that isn't a whole number
|
|
180
|
+
* from 0 up to the session's `lastSeq`, a prompt `text` that is empty or
|
|
181
|
+
* longer than {@link gatewayMaxPromptLength}, any message before `hello`,
|
|
182
|
+
* and a second `hello`.
|
|
183
|
+
*
|
|
184
|
+
* A well-formed message the host won't carry out gets an `error` with a code
|
|
185
|
+
* from {@link gatewayRefusalCodes} and its `replyTo`, and the connection
|
|
186
|
+
* stays open.
|
|
187
|
+
*/
|
|
188
|
+
export type GatewayHostMessage = {
|
|
189
|
+
readonly type: "welcome";
|
|
190
|
+
readonly replyTo: string;
|
|
191
|
+
readonly version: number;
|
|
192
|
+
readonly maxMessageBytes: number;
|
|
193
|
+
} | {
|
|
194
|
+
readonly type: "sessions";
|
|
195
|
+
readonly replyTo: string;
|
|
196
|
+
readonly sessions: readonly GatewaySession[];
|
|
197
|
+
} | {
|
|
198
|
+
readonly type: "event";
|
|
199
|
+
readonly sessionId: string;
|
|
200
|
+
readonly seq: number;
|
|
201
|
+
readonly at: string;
|
|
202
|
+
readonly body: GatewayEventBody;
|
|
203
|
+
} | {
|
|
204
|
+
readonly type: "ok";
|
|
205
|
+
readonly replyTo: string;
|
|
206
|
+
} | {
|
|
207
|
+
readonly type: "paired";
|
|
208
|
+
} | {
|
|
209
|
+
readonly type: "pair-refused";
|
|
210
|
+
readonly reason: GatewayPairDeniedReason;
|
|
211
|
+
} | {
|
|
212
|
+
readonly type: "not-paired";
|
|
213
|
+
} | {
|
|
214
|
+
readonly type: "error";
|
|
215
|
+
readonly code: (typeof gatewayClosingErrorCodes)[number];
|
|
216
|
+
} | {
|
|
217
|
+
readonly type: "error";
|
|
218
|
+
readonly replyTo: string;
|
|
219
|
+
readonly code: (typeof gatewayRefusalCodes)[number];
|
|
220
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remote gateway protocol: what a phone and the desktop host's remote
|
|
3
|
+
* gateway say to each other, inside the end-to-end session (requirement
|
|
4
|
+
* `ports.remote-gateway-protocol`). It covers sessions, their events,
|
|
5
|
+
* approvals and prompt input, the end of a pairing, and nothing else. Each
|
|
6
|
+
* message is one JSON object in one Noise transport message; nothing here is
|
|
7
|
+
* ever sent in cleartext. The session around it is in
|
|
8
|
+
* `remote-gateway-session.ts` (ADR "Pairing and the end-to-end session").
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The protocol version. Both sides send it in `hello` and `welcome`, and the
|
|
12
|
+
* Noise prologue names it too, so a peer of another version fails the
|
|
13
|
+
* handshake. A host speaks exactly one and there is no negotiation. The host
|
|
14
|
+
* answers a `hello` with another version with `unsupported-version` and
|
|
15
|
+
* closes; the phone closes on a `welcome` with another version.
|
|
16
|
+
*/
|
|
17
|
+
export const gatewayProtocolVersion = 2;
|
|
18
|
+
/**
|
|
19
|
+
* The largest message either side accepts, in bytes of its UTF-8 JSON: one
|
|
20
|
+
* Noise transport message (65,535 bytes) less its 16-byte tag. A larger one is
|
|
21
|
+
* refused: the host sends `error` with `too-large` and closes. The host checks
|
|
22
|
+
* the size before it parses.
|
|
23
|
+
*/
|
|
24
|
+
export const gatewayMaxMessageBytes = 65_535 - 16;
|
|
25
|
+
/**
|
|
26
|
+
* The longest prompt text, in UTF-16 code units. It is set from the worst
|
|
27
|
+
* case: JSON writes a control character or a lone surrogate as six bytes, so
|
|
28
|
+
* 10,000 of them take 60,000 bytes and still fit in one message with the
|
|
29
|
+
* envelope. A prompt within this length never gets `too-large`.
|
|
30
|
+
*/
|
|
31
|
+
export const gatewayMaxPromptLength = 10_000;
|
|
32
|
+
/**
|
|
33
|
+
* The longest id, the phone's or the host's. Every id is 1 to this many
|
|
34
|
+
* characters from `A`–`Z`, `a`–`z`, `0`–`9`, `_` and `-`.
|
|
35
|
+
*/
|
|
36
|
+
export const gatewayMaxIdLength = 128;
|
|
37
|
+
/**
|
|
38
|
+
* The most sessions one connection may watch at once. A `watch` for one more
|
|
39
|
+
* gets `too-many-watches` and leaves the connection open.
|
|
40
|
+
*/
|
|
41
|
+
export const gatewayMaxWatches = 16;
|
|
42
|
+
/**
|
|
43
|
+
* The most bytes the host holds unsent for one connection. A phone that
|
|
44
|
+
* reads more slowly than its sessions produce events is closed when this is
|
|
45
|
+
* exceeded, never buffered without limit; it resumes by watching again.
|
|
46
|
+
*/
|
|
47
|
+
export const gatewayMaxBufferedBytes = 1024 * 1024;
|
|
48
|
+
/**
|
|
49
|
+
* Why the host refused a message and closed the connection. Such an `error`
|
|
50
|
+
* has no `replyTo`, since the message it answers may not have parsed.
|
|
51
|
+
*/
|
|
52
|
+
export const gatewayClosingErrorCodes = ["malformed", "too-large", "unsupported-version"];
|
|
53
|
+
/** Why the host refused a well-formed message and kept the connection open. */
|
|
54
|
+
export const gatewayRefusalCodes = [
|
|
55
|
+
"unknown-session",
|
|
56
|
+
"unknown-approval",
|
|
57
|
+
"not-allowed-remotely",
|
|
58
|
+
"history-gone",
|
|
59
|
+
"too-many-watches",
|
|
60
|
+
];
|
|
61
|
+
/** Every error code, closing ones first. Studio words each code. */
|
|
62
|
+
export const gatewayErrorCodes = [...gatewayClosingErrorCodes, ...gatewayRefusalCodes];
|