clinkx 1.3.0 → 1.4.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 (179) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +13 -6
  3. package/clinkx-workflows/dist/child-env.d.ts +3 -0
  4. package/clinkx-workflows/dist/child-env.js +11 -0
  5. package/clinkx-workflows/dist/child-env.js.map +1 -1
  6. package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
  7. package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
  8. package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
  9. package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
  10. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
  11. package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
  12. package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
  13. package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
  14. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
  15. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
  16. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
  17. package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
  18. package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
  19. package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
  20. package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
  21. package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
  22. package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
  23. package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
  24. package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
  25. package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
  26. package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
  27. package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
  28. package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
  29. package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
  30. package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
  31. package/clinkx-workflows/dist/dashboard-ui/assets/index-CX4FrhYN.js +122 -0
  32. package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
  33. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  34. package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
  35. package/clinkx-workflows/dist/durable-file-core.js +146 -0
  36. package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
  37. package/clinkx-workflows/dist/durable-file.d.ts +8 -64
  38. package/clinkx-workflows/dist/durable-file.js +14 -137
  39. package/clinkx-workflows/dist/durable-file.js.map +1 -1
  40. package/clinkx-workflows/dist/index.js +68 -2
  41. package/clinkx-workflows/dist/index.js.map +1 -1
  42. package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
  43. package/clinkx-workflows/dist/settings/audit.js +318 -0
  44. package/clinkx-workflows/dist/settings/audit.js.map +1 -0
  45. package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
  46. package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
  47. package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
  48. package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
  49. package/clinkx-workflows/dist/settings/codec.js +410 -0
  50. package/clinkx-workflows/dist/settings/codec.js.map +1 -0
  51. package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
  52. package/clinkx-workflows/dist/settings/durable-write.js +31 -0
  53. package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
  54. package/clinkx-workflows/dist/settings/index.d.ts +20 -0
  55. package/clinkx-workflows/dist/settings/index.js +23 -0
  56. package/clinkx-workflows/dist/settings/index.js.map +1 -0
  57. package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
  58. package/clinkx-workflows/dist/settings/loader.js +577 -0
  59. package/clinkx-workflows/dist/settings/loader.js.map +1 -0
  60. package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
  61. package/clinkx-workflows/dist/settings/lock.js +344 -0
  62. package/clinkx-workflows/dist/settings/lock.js.map +1 -0
  63. package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
  64. package/clinkx-workflows/dist/settings/paths.js +173 -0
  65. package/clinkx-workflows/dist/settings/paths.js.map +1 -0
  66. package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
  67. package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
  68. package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
  69. package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
  70. package/clinkx-workflows/dist/settings/registry.js +1290 -0
  71. package/clinkx-workflows/dist/settings/registry.js.map +1 -0
  72. package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
  73. package/clinkx-workflows/dist/settings/schema.js +415 -0
  74. package/clinkx-workflows/dist/settings/schema.js.map +1 -0
  75. package/clinkx-workflows/dist/settings/store.d.ts +157 -0
  76. package/clinkx-workflows/dist/settings/store.js +842 -0
  77. package/clinkx-workflows/dist/settings/store.js.map +1 -0
  78. package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
  79. package/clinkx-workflows/dist/stdio-entry.js +52 -0
  80. package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
  81. package/dist/dashboard-cli.d.ts +11 -3
  82. package/dist/dashboard-cli.js +199 -33
  83. package/dist/dashboard-cli.js.map +1 -1
  84. package/dist/dashboard-companion/client.d.ts +14 -0
  85. package/dist/dashboard-companion/client.js +16 -0
  86. package/dist/dashboard-companion/client.js.map +1 -1
  87. package/dist/dashboard-companion/credential-expectation.d.ts +23 -0
  88. package/dist/dashboard-companion/credential-expectation.js +50 -0
  89. package/dist/dashboard-companion/credential-expectation.js.map +1 -0
  90. package/dist/dashboard-companion/host-channel.d.ts +36 -0
  91. package/dist/dashboard-companion/host-channel.js +78 -0
  92. package/dist/dashboard-companion/host-channel.js.map +1 -0
  93. package/dist/dashboard-companion/host-status.d.ts +179 -0
  94. package/dist/dashboard-companion/host-status.js +122 -0
  95. package/dist/dashboard-companion/host-status.js.map +1 -0
  96. package/dist/dashboard-companion/protocol.js +17 -0
  97. package/dist/dashboard-companion/protocol.js.map +1 -1
  98. package/dist/dashboard-companion/standalone-assets.d.ts +8 -0
  99. package/dist/dashboard-companion/standalone-assets.js +7 -1
  100. package/dist/dashboard-companion/standalone-assets.js.map +1 -1
  101. package/dist/dashboard-companion/standalone-entry.js +34 -13
  102. package/dist/dashboard-companion/standalone-entry.js.map +1 -1
  103. package/dist/dashboard-gateway/control-plane/contracts.d.ts +38 -38
  104. package/dist/dashboard-gateway/tunnel-http.js +20 -0
  105. package/dist/dashboard-gateway/tunnel-http.js.map +1 -1
  106. package/dist/desktop-host/child-env.d.ts +23 -0
  107. package/dist/desktop-host/child-env.js +70 -0
  108. package/dist/desktop-host/child-env.js.map +1 -0
  109. package/dist/desktop-host/daemon-entry.d.ts +2 -0
  110. package/dist/desktop-host/daemon-entry.js +50 -0
  111. package/dist/desktop-host/daemon-entry.js.map +1 -0
  112. package/dist/desktop-host/daemon-env.d.ts +12 -0
  113. package/dist/desktop-host/daemon-env.js +35 -0
  114. package/dist/desktop-host/daemon-env.js.map +1 -0
  115. package/dist/desktop-host/daemon-protocol.d.ts +210 -0
  116. package/dist/desktop-host/daemon-protocol.js +56 -0
  117. package/dist/desktop-host/daemon-protocol.js.map +1 -0
  118. package/dist/desktop-host/daemon.d.ts +50 -0
  119. package/dist/desktop-host/daemon.js +441 -0
  120. package/dist/desktop-host/daemon.js.map +1 -0
  121. package/dist/desktop-host/enrollment.d.ts +17 -0
  122. package/dist/desktop-host/enrollment.js +25 -0
  123. package/dist/desktop-host/enrollment.js.map +1 -0
  124. package/dist/desktop-host/import.d.ts +14 -0
  125. package/dist/desktop-host/import.js +95 -0
  126. package/dist/desktop-host/import.js.map +1 -0
  127. package/dist/desktop-host/profile.d.ts +130 -0
  128. package/dist/desktop-host/profile.js +176 -0
  129. package/dist/desktop-host/profile.js.map +1 -0
  130. package/dist/desktop-host/service.d.ts +6 -0
  131. package/dist/desktop-host/service.js +7 -0
  132. package/dist/desktop-host/service.js.map +1 -0
  133. package/dist/desktop-host/supervisor.d.ts +57 -0
  134. package/dist/desktop-host/supervisor.js +256 -0
  135. package/dist/desktop-host/supervisor.js.map +1 -0
  136. package/dist/desktop-host/view-state.d.ts +138 -0
  137. package/dist/desktop-host/view-state.js +27 -0
  138. package/dist/desktop-host/view-state.js.map +1 -0
  139. package/dist/elaris/config.d.ts +10 -0
  140. package/dist/elaris/config.js +27 -1
  141. package/dist/elaris/config.js.map +1 -1
  142. package/dist/elaris/tools.js +4 -1
  143. package/dist/elaris/tools.js.map +1 -1
  144. package/dist/index.d.ts +0 -31
  145. package/dist/index.js +41 -404
  146. package/dist/index.js.map +1 -1
  147. package/dist/lib.d.ts +17 -0
  148. package/dist/lib.js +17 -0
  149. package/dist/lib.js.map +1 -0
  150. package/dist/progress-report/lock.d.ts +17 -59
  151. package/dist/progress-report/lock.js +25 -329
  152. package/dist/progress-report/lock.js.map +1 -1
  153. package/dist/registry.d.ts +7 -0
  154. package/dist/registry.js +21 -7
  155. package/dist/registry.js.map +1 -1
  156. package/dist/server.js +75 -4
  157. package/dist/server.js.map +1 -1
  158. package/dist/settings-cli/clients.d.ts +137 -0
  159. package/dist/settings-cli/clients.js +1124 -0
  160. package/dist/settings-cli/clients.js.map +1 -0
  161. package/dist/settings-cli/commands.d.ts +67 -0
  162. package/dist/settings-cli/commands.js +726 -0
  163. package/dist/settings-cli/commands.js.map +1 -0
  164. package/dist/settings-cli/format.d.ts +34 -0
  165. package/dist/settings-cli/format.js +40 -0
  166. package/dist/settings-cli/format.js.map +1 -0
  167. package/dist/settings-cli/main.d.ts +18 -0
  168. package/dist/settings-cli/main.js +256 -0
  169. package/dist/settings-cli/main.js.map +1 -0
  170. package/dist/stdio-main.d.ts +73 -0
  171. package/dist/stdio-main.js +455 -0
  172. package/dist/stdio-main.js.map +1 -0
  173. package/docs/configuration.md +340 -39
  174. package/docs/security.md +150 -6
  175. package/docs/verification/README.md +28 -2
  176. package/docs/verification/workflow-handoff.md +86 -0
  177. package/package.json +3 -3
  178. package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +0 -119
  179. package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +0 -1
@@ -0,0 +1,130 @@
1
+ import { z } from "zod";
2
+ export declare const DESKTOP_PROFILE_FILENAME = "profile.json";
3
+ /**
4
+ * Everything the launcher needs to start the companion for one workstation.
5
+ * The workstation key is not here: it lives in the OS secret store. The
6
+ * enrollment expectation is recorded here, outside the credential and binding
7
+ * directories, so losing both cannot make an enrolled profile look new.
8
+ */
9
+ export declare const DesktopProfileSchema: z.ZodObject<{
10
+ version: z.ZodLiteral<1>;
11
+ service: z.ZodObject<{
12
+ /** Canonical HTTPS origin of the hosted dashboard; also the passkey RP. */
13
+ origin: z.ZodString;
14
+ /** The gateway's agent endpoint. */
15
+ gatewayUrl: z.ZodString;
16
+ /** `tenant` takes a clxd_ workstation key; `legacy` a single-user pairing token. */
17
+ mode: z.ZodEnum<["tenant", "legacy"]>;
18
+ }, "strict", z.ZodTypeAny, {
19
+ mode: "legacy" | "tenant";
20
+ origin: string;
21
+ gatewayUrl: string;
22
+ }, {
23
+ mode: "legacy" | "tenant";
24
+ origin: string;
25
+ gatewayUrl: string;
26
+ }>;
27
+ roots: z.ZodObject<{
28
+ state: z.ZodEffects<z.ZodString, string, string>;
29
+ contextRuns: z.ZodEffects<z.ZodString, string, string>;
30
+ workspace: z.ZodEffects<z.ZodString, string, string>;
31
+ settings: z.ZodEffects<z.ZodString, string, string>;
32
+ credentials: z.ZodEffects<z.ZodString, string, string>;
33
+ binding: z.ZodEffects<z.ZodString, string, string>;
34
+ /** Optional explicit producer adapter configuration (CLINKX_CONFIG_PATH). */
35
+ adapters: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
36
+ }, "strict", z.ZodTypeAny, {
37
+ credentials: string;
38
+ state: string;
39
+ binding: string;
40
+ settings: string;
41
+ contextRuns: string;
42
+ workspace: string;
43
+ adapters?: string | undefined;
44
+ }, {
45
+ credentials: string;
46
+ state: string;
47
+ binding: string;
48
+ settings: string;
49
+ contextRuns: string;
50
+ workspace: string;
51
+ adapters?: string | undefined;
52
+ }>;
53
+ credentialExpectation: z.ZodEnum<["bootstrap", "existing-enrolled"]>;
54
+ lifecycle: z.ZodObject<{
55
+ keepRunningInBackground: z.ZodBoolean;
56
+ startAtLogin: z.ZodBoolean;
57
+ }, "strict", z.ZodTypeAny, {
58
+ keepRunningInBackground: boolean;
59
+ startAtLogin: boolean;
60
+ }, {
61
+ keepRunningInBackground: boolean;
62
+ startAtLogin: boolean;
63
+ }>;
64
+ }, "strict", z.ZodTypeAny, {
65
+ version: 1;
66
+ roots: {
67
+ credentials: string;
68
+ state: string;
69
+ binding: string;
70
+ settings: string;
71
+ contextRuns: string;
72
+ workspace: string;
73
+ adapters?: string | undefined;
74
+ };
75
+ credentialExpectation: "bootstrap" | "existing-enrolled";
76
+ lifecycle: {
77
+ keepRunningInBackground: boolean;
78
+ startAtLogin: boolean;
79
+ };
80
+ service: {
81
+ mode: "legacy" | "tenant";
82
+ origin: string;
83
+ gatewayUrl: string;
84
+ };
85
+ }, {
86
+ version: 1;
87
+ roots: {
88
+ credentials: string;
89
+ state: string;
90
+ binding: string;
91
+ settings: string;
92
+ contextRuns: string;
93
+ workspace: string;
94
+ adapters?: string | undefined;
95
+ };
96
+ credentialExpectation: "bootstrap" | "existing-enrolled";
97
+ lifecycle: {
98
+ keepRunningInBackground: boolean;
99
+ startAtLogin: boolean;
100
+ };
101
+ service: {
102
+ mode: "legacy" | "tenant";
103
+ origin: string;
104
+ gatewayUrl: string;
105
+ };
106
+ }>;
107
+ export type DesktopProfile = z.infer<typeof DesktopProfileSchema>;
108
+ export interface DesktopService {
109
+ readonly origin: string;
110
+ readonly gatewayUrl: string;
111
+ readonly mode: "tenant" | "legacy";
112
+ }
113
+ /** Producer defaults for a native install; private companion stores live in the app's data directory. */
114
+ export declare function defaultDesktopProfile(input: {
115
+ readonly home: string;
116
+ readonly appData: string;
117
+ readonly service: DesktopService;
118
+ }): DesktopProfile;
119
+ /** The agent endpoint for a hosted origin: same host, `/agent`, over WSS. */
120
+ export declare function gatewayUrlForOrigin(origin: string): string;
121
+ /**
122
+ * Semantic checks the schema cannot express. The service authority comes from
123
+ * the app build or an explicit self-hosted choice, never from a web page.
124
+ */
125
+ export declare function validateDesktopProfile(profile: DesktopProfile, home: string): Promise<void>;
126
+ export declare function desktopProfilePath(appData: string): string;
127
+ /** `undefined` when no profile exists yet; an unreadable profile throws rather than resetting setup. */
128
+ export declare function readDesktopProfile(path: string): Promise<DesktopProfile | undefined>;
129
+ /** Atomically publish the profile: private temp file, fsync, rename, then fsync the directory. */
130
+ export declare function writeDesktopProfile(path: string, profile: DesktopProfile): Promise<void>;
@@ -0,0 +1,176 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { closeSync, fsyncSync, openSync } from "node:fs";
3
+ import { mkdir, open, readFile, rename, unlink } from "node:fs/promises";
4
+ import { dirname, isAbsolute, join, parse, resolve } from "node:path";
5
+ import { z } from "zod";
6
+ import { parseCanonicalHttpsOrigin } from "../../clinkx-workflows/dist/config.js";
7
+ import { validateSettingsDirOverride } from "../../clinkx-workflows/dist/settings/paths.js";
8
+ import { assertSeparateBindingAndCredentialDirectories } from "../dashboard-companion/config.js";
9
+ import { DASHBOARD_CREDENTIAL_EXPECTATIONS } from "../dashboard-companion/credential-expectation.js";
10
+ export const DESKTOP_PROFILE_FILENAME = "profile.json";
11
+ const MAX_PROFILE_BYTES = 16 * 1_024;
12
+ const absolutePath = z
13
+ .string()
14
+ .min(1)
15
+ .max(4_096)
16
+ .refine((value) => isAbsolute(value) && parse(resolve(value)).root !== resolve(value), "must be an absolute, non-root path");
17
+ /**
18
+ * Everything the launcher needs to start the companion for one workstation.
19
+ * The workstation key is not here: it lives in the OS secret store. The
20
+ * enrollment expectation is recorded here, outside the credential and binding
21
+ * directories, so losing both cannot make an enrolled profile look new.
22
+ */
23
+ export const DesktopProfileSchema = z
24
+ .object({
25
+ version: z.literal(1),
26
+ service: z
27
+ .object({
28
+ /** Canonical HTTPS origin of the hosted dashboard; also the passkey RP. */
29
+ origin: z.string().min(1).max(512),
30
+ /** The gateway's agent endpoint. */
31
+ gatewayUrl: z.string().min(1).max(512),
32
+ /** `tenant` takes a clxd_ workstation key; `legacy` a single-user pairing token. */
33
+ mode: z.enum(["tenant", "legacy"]),
34
+ })
35
+ .strict(),
36
+ roots: z
37
+ .object({
38
+ state: absolutePath,
39
+ contextRuns: absolutePath,
40
+ workspace: absolutePath,
41
+ settings: absolutePath,
42
+ credentials: absolutePath,
43
+ binding: absolutePath,
44
+ /** Optional explicit producer adapter configuration (CLINKX_CONFIG_PATH). */
45
+ adapters: absolutePath.optional(),
46
+ })
47
+ .strict(),
48
+ credentialExpectation: z.enum(DASHBOARD_CREDENTIAL_EXPECTATIONS),
49
+ lifecycle: z
50
+ .object({
51
+ keepRunningInBackground: z.boolean(),
52
+ startAtLogin: z.boolean(),
53
+ })
54
+ .strict(),
55
+ })
56
+ .strict();
57
+ /** Producer defaults for a native install; private companion stores live in the app's data directory. */
58
+ export function defaultDesktopProfile(input) {
59
+ return {
60
+ version: 1,
61
+ service: { ...input.service },
62
+ roots: {
63
+ state: join(input.home, ".clinkx"),
64
+ contextRuns: join(input.home, ".clinkx", "context-builder", "runs"),
65
+ workspace: input.home,
66
+ settings: join(input.home, ".config", "clinkx", "settings"),
67
+ credentials: join(input.appData, "companion", "webauthn"),
68
+ binding: join(input.appData, "companion", "binding"),
69
+ },
70
+ credentialExpectation: "bootstrap",
71
+ lifecycle: { keepRunningInBackground: true, startAtLogin: false },
72
+ };
73
+ }
74
+ function isLoopbackHost(hostname) {
75
+ return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
76
+ }
77
+ /** The agent endpoint for a hosted origin: same host, `/agent`, over WSS. */
78
+ export function gatewayUrlForOrigin(origin) {
79
+ const url = new URL("/agent", parseCanonicalHttpsOrigin(origin, "service origin").origin);
80
+ url.protocol = "wss:";
81
+ return url.href;
82
+ }
83
+ /**
84
+ * Semantic checks the schema cannot express. The service authority comes from
85
+ * the app build or an explicit self-hosted choice, never from a web page.
86
+ */
87
+ export async function validateDesktopProfile(profile, home) {
88
+ const origin = parseCanonicalHttpsOrigin(profile.service.origin, "service origin").origin;
89
+ if (origin !== profile.service.origin)
90
+ throw new Error("service origin must be canonical");
91
+ let gateway;
92
+ try {
93
+ gateway = new URL(profile.service.gatewayUrl);
94
+ }
95
+ catch {
96
+ throw new Error("gateway URL must be an absolute WSS URL");
97
+ }
98
+ if (gateway.username !== "" || gateway.password !== "" || gateway.search !== "" || gateway.hash !== "") {
99
+ throw new Error("gateway URL must not contain credentials, query, or fragment");
100
+ }
101
+ if (gateway.protocol !== "wss:" && !(gateway.protocol === "ws:" && isLoopbackHost(gateway.hostname))) {
102
+ throw new Error("gateway URL must use WSS (plaintext only on loopback)");
103
+ }
104
+ // The launcher passes explicit roots and never CLINKX_HOME, so the
105
+ // companion's settings resolver measures containment against $HOME/.clinkx.
106
+ const settingsRejection = validateSettingsDirOverride(profile.roots.settings, home, join(home, ".clinkx"));
107
+ if (settingsRejection !== undefined)
108
+ throw new Error(settingsRejection);
109
+ await assertSeparateBindingAndCredentialDirectories(profile.roots.binding, profile.roots.credentials);
110
+ }
111
+ export function desktopProfilePath(appData) {
112
+ return join(appData, DESKTOP_PROFILE_FILENAME);
113
+ }
114
+ /** `undefined` when no profile exists yet; an unreadable profile throws rather than resetting setup. */
115
+ export async function readDesktopProfile(path) {
116
+ let raw;
117
+ try {
118
+ raw = await readFile(path);
119
+ }
120
+ catch (error) {
121
+ if (error.code === "ENOENT")
122
+ return undefined;
123
+ throw error;
124
+ }
125
+ if (raw.byteLength > MAX_PROFILE_BYTES)
126
+ throw new Error(`${path} exceeds the profile size limit`);
127
+ let value;
128
+ try {
129
+ value = JSON.parse(raw.toString("utf8"));
130
+ }
131
+ catch {
132
+ throw new Error(`${path} is not valid JSON`);
133
+ }
134
+ const parsed = DesktopProfileSchema.safeParse(value);
135
+ if (!parsed.success)
136
+ throw new Error(`${path} is not a valid ClinkX desktop profile`);
137
+ return parsed.data;
138
+ }
139
+ function syncDirectory(directory) {
140
+ if (process.platform === "win32")
141
+ return;
142
+ const descriptor = openSync(directory, "r");
143
+ try {
144
+ fsyncSync(descriptor);
145
+ }
146
+ finally {
147
+ closeSync(descriptor);
148
+ }
149
+ }
150
+ /** Atomically publish the profile: private temp file, fsync, rename, then fsync the directory. */
151
+ export async function writeDesktopProfile(path, profile) {
152
+ const serialized = `${JSON.stringify(DesktopProfileSchema.parse(profile), null, 2)}\n`;
153
+ const directory = dirname(path);
154
+ await mkdir(directory, { recursive: true, mode: 0o700 });
155
+ const temporary = join(directory, `.${DESKTOP_PROFILE_FILENAME}.${String(process.pid)}.${randomBytes(8).toString("hex")}.tmp`);
156
+ let created = false;
157
+ try {
158
+ const handle = await open(temporary, "wx", 0o600);
159
+ created = true;
160
+ try {
161
+ await handle.writeFile(serialized, "utf8");
162
+ await handle.sync();
163
+ }
164
+ finally {
165
+ await handle.close();
166
+ }
167
+ await rename(temporary, path);
168
+ created = false;
169
+ }
170
+ finally {
171
+ if (created)
172
+ await unlink(temporary).catch(() => { });
173
+ }
174
+ syncDirectory(directory);
175
+ }
176
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/desktop-host/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,KAAK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AG,KAAK,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAClD,OAAO,GAAG,IAAI,CAAC;QACf,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAC3C,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,GAAG,KAAK,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,IAAI,OAAO;YAAE,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,aAAa,CAAC,SAAS,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** The hosted ClinkX service this build connects to; a self-hosted gateway is an explicit setup choice. */
2
+ export declare const HOSTED_SERVICE: {
3
+ readonly origin: "https://clinkx.jayjie.com";
4
+ readonly gatewayUrl: "wss://clinkx.jayjie.com/agent";
5
+ readonly mode: "tenant";
6
+ };
@@ -0,0 +1,7 @@
1
+ /** The hosted ClinkX service this build connects to; a self-hosted gateway is an explicit setup choice. */
2
+ export const HOSTED_SERVICE = {
3
+ origin: "https://clinkx.jayjie.com",
4
+ gatewayUrl: "wss://clinkx.jayjie.com/agent",
5
+ mode: "tenant",
6
+ };
7
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/desktop-host/service.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,2BAA2B;IACnC,UAAU,EAAE,+BAA+B;IAC3C,IAAI,EAAE,QAAQ;CACN,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { type HostGatewayState, type HostSettingsState } from "../dashboard-companion/host-status.js";
2
+ export type CompanionPhase = "stopped" | "starting" | "ready" | "stopping" | "failed";
3
+ export interface CompanionFailure {
4
+ /** The companion's fatal reason, or a supervisor reason (`exited`, `spawn_failed`, `protocol_error`, `settings_unavailable`). */
5
+ readonly reason: string;
6
+ readonly message: string;
7
+ }
8
+ export interface CompanionStatus {
9
+ readonly phase: CompanionPhase;
10
+ readonly settings?: HostSettingsState;
11
+ readonly gateway?: HostGatewayState;
12
+ /** HTTP status of the latest refused upgrade; cleared once a connection opens. */
13
+ readonly rejectedStatus?: number;
14
+ /** Transient first-enrollment code; present only while this process runs. */
15
+ readonly enrollmentCode?: string;
16
+ readonly origin?: string;
17
+ readonly failure?: CompanionFailure;
18
+ }
19
+ export interface CompanionLaunch {
20
+ /** Absolute path of the app-owned executable; never resolved through PATH. */
21
+ readonly executable: string;
22
+ readonly args: readonly string[];
23
+ readonly env: Readonly<Record<string, string>>;
24
+ readonly cwd: string;
25
+ /** Values that must never appear in retained diagnostics. */
26
+ readonly secrets: readonly string[];
27
+ }
28
+ export interface CompanionSupervisorOptions {
29
+ readonly onStatus: (status: CompanionStatus) => void;
30
+ /** Longer than the companion's own 8 s shutdown deadline. */
31
+ readonly stopTimeoutMs?: number;
32
+ readonly diagnosticLines?: number;
33
+ }
34
+ /**
35
+ * Owns one companion process for the selected profile. It reads only the
36
+ * private status channel and a bounded, redacted stderr tail, and it stops the
37
+ * companion through its graceful path. It never signals a process it did not
38
+ * start, so an occupied port or a second companion is reported, not reclaimed.
39
+ */
40
+ export declare class CompanionSupervisor {
41
+ #private;
42
+ constructor(options: CompanionSupervisorOptions);
43
+ get status(): CompanionStatus;
44
+ get running(): boolean;
45
+ /** Recent stderr, redacted, for a support view; never contains the key or the enrollment code. */
46
+ diagnostics(): string;
47
+ start(launch: CompanionLaunch): void;
48
+ /** Ask the companion to shut down through its graceful path; kill only this child, after the deadline. */
49
+ stop(): Promise<{
50
+ readonly forced: boolean;
51
+ }>;
52
+ }
53
+ /** Run the companion once with a one-shot command (for example `--reset-passkey-binding`) and collect its stderr. */
54
+ export declare function runCompanionCommand(launch: CompanionLaunch, timeoutMs?: number): Promise<{
55
+ readonly code: number | null;
56
+ readonly output: string;
57
+ }>;
@@ -0,0 +1,256 @@
1
+ import { spawn } from "node:child_process";
2
+ import { isAbsolute } from "node:path";
3
+ import { HostStatusProtocolError, MAX_HOST_STATUS_LINE_BYTES, parseHostStatusLine, } from "../dashboard-companion/host-status.js";
4
+ const MAX_DIAGNOSTIC_LINE_LENGTH = 2_000;
5
+ function redact(text, secrets) {
6
+ let result = text;
7
+ for (const secret of secrets) {
8
+ if (secret !== "")
9
+ result = result.split(secret).join("[redacted]");
10
+ }
11
+ return result;
12
+ }
13
+ function waitForExit(child, timeoutMs) {
14
+ if (child.exitCode !== null || child.signalCode !== null)
15
+ return Promise.resolve(true);
16
+ return new Promise((resolveWait) => {
17
+ const timer = setTimeout(() => {
18
+ child.off("exit", onExit);
19
+ resolveWait(false);
20
+ }, timeoutMs);
21
+ const onExit = () => {
22
+ clearTimeout(timer);
23
+ resolveWait(true);
24
+ };
25
+ child.once("exit", onExit);
26
+ });
27
+ }
28
+ /** The most useful stderr line for an exit message: an error line if any, else the last. */
29
+ function diagnosticHeadline(lines) {
30
+ for (const line of lines) {
31
+ if (/^(Error|TypeError|RangeError|SyntaxError|ReferenceError|SystemError)|\berror\b\s|errno |clinkx-dashboard: /.test(line)) {
32
+ return line;
33
+ }
34
+ }
35
+ return lines.at(-1);
36
+ }
37
+ /**
38
+ * Owns one companion process for the selected profile. It reads only the
39
+ * private status channel and a bounded, redacted stderr tail, and it stops the
40
+ * companion through its graceful path. It never signals a process it did not
41
+ * start, so an occupied port or a second companion is reported, not reclaimed.
42
+ */
43
+ export class CompanionSupervisor {
44
+ #options;
45
+ #child;
46
+ #status = { phase: "stopped" };
47
+ #stopRequested = false;
48
+ #diagnostics = [];
49
+ #secrets = [];
50
+ constructor(options) {
51
+ this.#options = options;
52
+ }
53
+ get status() {
54
+ return this.#status;
55
+ }
56
+ get running() {
57
+ return this.#child !== undefined;
58
+ }
59
+ /** Recent stderr, redacted, for a support view; never contains the key or the enrollment code. */
60
+ diagnostics() {
61
+ return this.#diagnostics.join("\n");
62
+ }
63
+ start(launch) {
64
+ if (this.#child !== undefined)
65
+ throw new Error("the companion is already running");
66
+ if (!isAbsolute(launch.executable))
67
+ throw new Error("the companion executable path must be absolute");
68
+ this.#stopRequested = false;
69
+ this.#diagnostics = [];
70
+ this.#secrets = launch.secrets;
71
+ this.#update({ phase: "starting" }, true);
72
+ const child = spawn(launch.executable, [...launch.args], {
73
+ cwd: launch.cwd,
74
+ env: { ...launch.env },
75
+ shell: false,
76
+ windowsHide: true,
77
+ stdio: ["pipe", "pipe", "pipe"],
78
+ });
79
+ this.#child = child;
80
+ let pending = "";
81
+ child.stdout?.setEncoding("utf8");
82
+ child.stdout?.on("data", (chunk) => {
83
+ pending += chunk;
84
+ let newline = pending.indexOf("\n");
85
+ while (newline !== -1) {
86
+ this.#handleLine(pending.slice(0, newline));
87
+ pending = pending.slice(newline + 1);
88
+ newline = pending.indexOf("\n");
89
+ }
90
+ if (Buffer.byteLength(pending) > MAX_HOST_STATUS_LINE_BYTES) {
91
+ pending = "";
92
+ this.#protocolFailure(new HostStatusProtocolError("host status line exceeds the size limit"));
93
+ }
94
+ });
95
+ let partial = "";
96
+ child.stderr?.setEncoding("utf8");
97
+ child.stderr?.on("data", (chunk) => {
98
+ const lines = (partial + chunk).split("\n");
99
+ partial = lines.pop() ?? "";
100
+ for (const line of lines)
101
+ this.#record(line);
102
+ });
103
+ // Losing the companion's stdin pipe only means it is already exiting.
104
+ child.stdin?.on("error", () => { });
105
+ child.once("error", (error) => {
106
+ this.#child = undefined;
107
+ this.#update({
108
+ phase: "failed",
109
+ failure: { reason: "spawn_failed", message: redact(error.message, this.#secrets) },
110
+ }, true);
111
+ });
112
+ child.once("exit", (code, signal) => {
113
+ if (partial !== "")
114
+ this.#record(partial);
115
+ this.#child = undefined;
116
+ const failure = this.#status.failure;
117
+ if (this.#stopRequested && failure === undefined) {
118
+ this.#update({ phase: "stopped" }, true);
119
+ return;
120
+ }
121
+ const last = diagnosticHeadline(this.#diagnostics);
122
+ this.#update({
123
+ phase: "failed",
124
+ ...(this.#status.settings === undefined ? {} : { settings: this.#status.settings }),
125
+ failure: failure ?? {
126
+ reason: "exited",
127
+ message: `the companion exited unexpectedly (${signal ?? `code ${String(code)}`})${last === undefined ? "" : `: ${last}`}`,
128
+ },
129
+ }, true);
130
+ });
131
+ }
132
+ /** Ask the companion to shut down through its graceful path; kill only this child, after the deadline. */
133
+ async stop() {
134
+ const child = this.#child;
135
+ if (child === undefined)
136
+ return { forced: false };
137
+ this.#stopRequested = true;
138
+ if (this.#status.phase !== "failed")
139
+ this.#update({ ...this.#status, phase: "stopping" });
140
+ child.stdin?.end();
141
+ if (await waitForExit(child, this.#options.stopTimeoutMs ?? 12_000))
142
+ return { forced: false };
143
+ child.kill("SIGKILL");
144
+ await waitForExit(child, 5_000);
145
+ return { forced: true };
146
+ }
147
+ #record(line) {
148
+ const trimmed = line.trimEnd();
149
+ if (trimmed === "")
150
+ return;
151
+ this.#diagnostics.push(redact(trimmed, this.#secrets).slice(0, MAX_DIAGNOSTIC_LINE_LENGTH));
152
+ const limit = this.#options.diagnosticLines ?? 200;
153
+ if (this.#diagnostics.length > limit)
154
+ this.#diagnostics.splice(0, this.#diagnostics.length - limit);
155
+ }
156
+ #protocolFailure(error) {
157
+ if (this.#status.failure !== undefined)
158
+ return;
159
+ this.#update({ ...this.#status, failure: { reason: "protocol_error", message: error.message } });
160
+ void this.stop();
161
+ }
162
+ #handleLine(line) {
163
+ let event;
164
+ try {
165
+ event = parseHostStatusLine(line);
166
+ }
167
+ catch (error) {
168
+ this.#protocolFailure(error instanceof Error ? error : new Error(String(error)));
169
+ return;
170
+ }
171
+ if (event === undefined)
172
+ return;
173
+ const current = this.#status;
174
+ switch (event.type) {
175
+ case "starting":
176
+ this.#update({ ...current, phase: "starting" });
177
+ break;
178
+ case "settings":
179
+ this.#update({ ...current, settings: event.state });
180
+ if (event.state === "invalid" || event.state === "unresolvable") {
181
+ // A running listener without its Settings store is not a usable companion.
182
+ this.#update({
183
+ ...this.#status,
184
+ failure: {
185
+ reason: "settings_unavailable",
186
+ message: `the Settings folder is ${event.state === "invalid" ? "invalid" : "unresolvable"}; choose a valid folder in Setup`,
187
+ },
188
+ });
189
+ void this.stop();
190
+ }
191
+ break;
192
+ case "listening":
193
+ this.#update({ ...current, origin: event.origin });
194
+ break;
195
+ case "enrollment_code":
196
+ this.#update({ ...current, enrollmentCode: event.code });
197
+ break;
198
+ case "gateway": {
199
+ const { rejectedStatus: _previous, ...rest } = current;
200
+ const rejectedStatus = event.state === "rejected" ? event.status : event.state === "open" || event.state === "accepted" ? undefined : current.rejectedStatus;
201
+ this.#update({ ...rest, gateway: event.state, ...(rejectedStatus === undefined ? {} : { rejectedStatus }) });
202
+ break;
203
+ }
204
+ case "ready":
205
+ this.#update({ ...current, phase: "ready" });
206
+ break;
207
+ case "stopping":
208
+ this.#update({ ...current, phase: "stopping" });
209
+ break;
210
+ case "fatal":
211
+ this.#update({ ...current, failure: { reason: event.reason, message: redact(event.message, this.#secrets) } });
212
+ break;
213
+ }
214
+ }
215
+ #update(status, replace = false) {
216
+ // The enrollment code is valid only for the process that printed it.
217
+ this.#status = replace || status.phase === "stopped" || status.phase === "failed"
218
+ ? withoutEnrollmentCode(status)
219
+ : status;
220
+ this.#options.onStatus(this.#status);
221
+ }
222
+ }
223
+ function withoutEnrollmentCode(status) {
224
+ const { enrollmentCode: _dropped, ...rest } = status;
225
+ return rest;
226
+ }
227
+ /** Run the companion once with a one-shot command (for example `--reset-passkey-binding`) and collect its stderr. */
228
+ export function runCompanionCommand(launch, timeoutMs = 30_000) {
229
+ if (!isAbsolute(launch.executable))
230
+ return Promise.reject(new Error("the companion executable path must be absolute"));
231
+ return new Promise((resolveRun, reject) => {
232
+ const child = spawn(launch.executable, [...launch.args], {
233
+ cwd: launch.cwd,
234
+ env: { ...launch.env },
235
+ shell: false,
236
+ windowsHide: true,
237
+ stdio: ["ignore", "ignore", "pipe"],
238
+ });
239
+ let output = "";
240
+ child.stderr?.setEncoding("utf8");
241
+ child.stderr?.on("data", (chunk) => {
242
+ if (output.length < 16_384)
243
+ output += chunk;
244
+ });
245
+ const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
246
+ child.once("error", (error) => {
247
+ clearTimeout(timer);
248
+ reject(error);
249
+ });
250
+ child.once("exit", (code) => {
251
+ clearTimeout(timer);
252
+ resolveRun({ code, output: redact(output, launch.secrets) });
253
+ });
254
+ });
255
+ }
256
+ //# sourceMappingURL=supervisor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor.js","sourceRoot":"","sources":["../../src/desktop-host/supervisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAIpB,MAAM,uCAAuC,CAAC;AAuC/C,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEzC,SAAS,MAAM,CAAC,IAAY,EAAE,OAA0B;IACtD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,EAAE;YAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAmB,EAAE,SAAiB;IACzD,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,I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