@mycadet/cli 0.13.0-dev.202610231403.3079a3f → 0.13.0-dev.202610241003.f9cbe80
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/node_modules/@mycadet/local-mode/src/__tests__/gateway-proxy.test.ts +1 -53
- package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +0 -4
- package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +17 -65
- package/node_modules/@mycadet/local-mode/src/index.ts +6 -2
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -3
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +1 -3
- package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +0 -31
- package/node_modules/@mycadet/local-mode/src/lockfile.ts +28 -48
- package/node_modules/@mycadet/shared/version.ts +15 -2
- package/package.json +1 -1
- package/src/__tests__/app-command.test.ts +2 -2
- package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
- package/src/__tests__/assistant-client-refresh.test.ts +2 -2
- package/src/__tests__/assistant-config.test.ts +28 -27
- package/src/__tests__/backup-ops.test.ts +4 -3
- package/src/__tests__/backup.test.ts +2 -2
- package/src/__tests__/client-tui-refresh.test.ts +3 -3
- package/src/__tests__/cloud-client.test.ts +0 -3
- package/src/__tests__/cloud-releases.test.ts +1 -29
- package/src/__tests__/connect-import.test.ts +4 -52
- package/src/__tests__/debug.test.ts +1 -1
- package/src/__tests__/devices.test.ts +5 -6
- package/src/__tests__/gateway-token.test.ts +3 -3
- package/src/__tests__/helpers/lockfile-entry.ts +37 -0
- package/src/__tests__/host-teleport-docker.test.ts +2 -2
- package/src/__tests__/host-teleport.test.ts +15 -15
- package/src/__tests__/local-runtime-version.test.ts +4 -2
- package/src/__tests__/multi-local.test.ts +14 -25
- package/src/__tests__/nginx-ingress.test.ts +73 -5
- package/src/__tests__/orphan-detection.test.ts +13 -12
- package/src/__tests__/ps-cloud-status.test.ts +9 -9
- package/src/__tests__/restore.test.ts +32 -28
- package/src/__tests__/retire-local.test.ts +25 -29
- package/src/__tests__/retire.test.ts +33 -32
- package/src/__tests__/root-backup-docker.test.ts +2 -2
- package/src/__tests__/root-backup.test.ts +2 -3
- package/src/__tests__/root-restore-command.test.ts +2 -2
- package/src/__tests__/setup.test.ts +2 -5
- package/src/__tests__/signing-key-continuity.test.ts +2 -93
- package/src/__tests__/sleep.test.ts +13 -6
- package/src/__tests__/teleport-backup.test.ts +8 -2
- package/src/__tests__/teleport.test.ts +1 -1
- package/src/__tests__/tui-midsession-refresh.test.ts +4 -23
- package/src/__tests__/tunnel-stop.test.ts +2 -3
- package/src/__tests__/tunnel.test.ts +27 -16
- package/src/__tests__/uninstall.test.ts +31 -28
- package/src/__tests__/upgrade-local.test.ts +29 -15
- package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
- package/src/__tests__/use.test.ts +16 -24
- package/src/__tests__/wake-error.test.ts +0 -1
- package/src/__tests__/wake.test.ts +22 -24
- package/src/commands/client.ts +5 -5
- package/src/commands/completions.test.ts +2 -2
- package/src/commands/debug.ts +13 -5
- package/src/commands/devices.ts +5 -5
- package/src/commands/gateway/token.ts +4 -4
- package/src/commands/hatch.ts +2 -2
- package/src/commands/login.ts +2 -2
- package/src/commands/logs.ts +4 -4
- package/src/commands/pair.ts +5 -5
- package/src/commands/ps.ts +23 -17
- package/src/commands/restore.ts +32 -20
- package/src/commands/retire.ts +6 -6
- package/src/commands/sleep.ts +117 -96
- package/src/commands/uninstall.ts +6 -4
- package/src/commands/upgrade.ts +203 -145
- package/src/commands/wake.ts +93 -93
- package/src/lib/__tests__/local-gateway-cli.test.ts +3 -3
- package/src/lib/__tests__/runtime-url.test.ts +1 -15
- package/src/lib/assistant-client.ts +5 -2
- package/src/lib/assistant-config.ts +43 -81
- package/src/lib/cloud-client.ts +2 -5
- package/src/lib/cloud-login.ts +12 -6
- package/src/lib/cloud-releases.ts +8 -42
- package/src/lib/constants.ts +0 -1
- package/src/lib/docker.ts +11 -11
- package/src/lib/exec-apple-container.ts +2 -2
- package/src/lib/hatch-local.ts +12 -6
- package/src/lib/health-check.ts +123 -109
- package/src/lib/host-teleport.ts +31 -23
- package/src/lib/ingress-config.ts +2 -2
- package/src/lib/live-voice/connection.ts +2 -2
- package/src/lib/local.ts +76 -48
- package/src/lib/nginx-ingress.ts +41 -10
- package/src/lib/orphan-detection.ts +4 -3
- package/src/lib/retire-apple-container.ts +2 -2
- package/src/lib/retire-local.ts +11 -5
- package/src/lib/root-backup.ts +35 -21
- package/src/lib/runtime-url.ts +4 -4
- package/src/lib/ssh-apple-container.ts +2 -2
- package/src/lib/sync-cloud-assistants.ts +5 -5
- package/src/lib/teleport-backup.ts +15 -13
- package/src/lib/terminal-client.ts +1 -1
- package/src/lib/tunnel.ts +6 -6
- package/src/lib/upgrade-lifecycle.ts +36 -30
|
@@ -38,7 +38,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
38
38
|
expect(parseAssistantGatewayUrl("/v1/assistants/abc-123")).toEqual({
|
|
39
39
|
match: true,
|
|
40
40
|
valid: true,
|
|
41
|
-
legacy: false,
|
|
42
41
|
target: {
|
|
43
42
|
assistantId: "abc-123",
|
|
44
43
|
path: "/v1/assistants/abc-123",
|
|
@@ -50,7 +49,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
50
49
|
).toEqual({
|
|
51
50
|
match: true,
|
|
52
51
|
valid: true,
|
|
53
|
-
legacy: false,
|
|
54
52
|
target: {
|
|
55
53
|
assistantId: "abc-123",
|
|
56
54
|
path: "/v1/assistants/abc-123/conversations",
|
|
@@ -63,7 +61,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
63
61
|
expect(parseAssistantGatewayUrl("/v1/assistants/abc-123/readyz")).toEqual({
|
|
64
62
|
match: true,
|
|
65
63
|
valid: true,
|
|
66
|
-
legacy: false,
|
|
67
64
|
target: { assistantId: "abc-123", path: "/readyz", search: "" },
|
|
68
65
|
});
|
|
69
66
|
});
|
|
@@ -74,7 +71,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
74
71
|
).toEqual({
|
|
75
72
|
match: true,
|
|
76
73
|
valid: true,
|
|
77
|
-
legacy: false,
|
|
78
74
|
target: {
|
|
79
75
|
assistantId: "abc-123",
|
|
80
76
|
path: "/v1/assistants/abc-123/messages",
|
|
@@ -89,7 +85,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
89
85
|
).toEqual({
|
|
90
86
|
match: true,
|
|
91
87
|
valid: true,
|
|
92
|
-
legacy: false,
|
|
93
88
|
target: {
|
|
94
89
|
assistantId: "abc-123",
|
|
95
90
|
path: "/v1/contacts/x",
|
|
@@ -101,7 +96,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
101
96
|
).toEqual({
|
|
102
97
|
match: true,
|
|
103
98
|
valid: true,
|
|
104
|
-
legacy: false,
|
|
105
99
|
target: {
|
|
106
100
|
assistantId: "abc-123",
|
|
107
101
|
path: "/v1/contact-channels/y",
|
|
@@ -110,24 +104,7 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
110
104
|
});
|
|
111
105
|
});
|
|
112
106
|
|
|
113
|
-
test("
|
|
114
|
-
expect(parseAssistantGatewayUrl("/__gateway/abc-123/auth/token")).toEqual({
|
|
115
|
-
match: true,
|
|
116
|
-
valid: true,
|
|
117
|
-
legacy: true,
|
|
118
|
-
target: { assistantId: "abc-123", path: "/auth/token", search: "" },
|
|
119
|
-
});
|
|
120
|
-
expect(
|
|
121
|
-
parseAssistantGatewayUrl("/assistant/__gateway/abc-123/readyz"),
|
|
122
|
-
).toEqual({
|
|
123
|
-
match: true,
|
|
124
|
-
valid: true,
|
|
125
|
-
legacy: true,
|
|
126
|
-
target: { assistantId: "abc-123", path: "/readyz", search: "" },
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("rejects dot segments on both shapes (raw and percent-encoded)", () => {
|
|
107
|
+
test("rejects dot segments (raw and percent-encoded)", () => {
|
|
131
108
|
expect(parseAssistantGatewayUrl("/v1/assistants/../secret")).toMatchObject({
|
|
132
109
|
match: true,
|
|
133
110
|
valid: false,
|
|
@@ -135,10 +112,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
135
112
|
expect(
|
|
136
113
|
parseAssistantGatewayUrl("/v1/assistants/abc/%2e%2e/secret"),
|
|
137
114
|
).toMatchObject({ match: true, valid: false });
|
|
138
|
-
expect(parseAssistantGatewayUrl("/__gateway/abc/../secret")).toMatchObject({
|
|
139
|
-
match: true,
|
|
140
|
-
valid: false,
|
|
141
|
-
});
|
|
142
115
|
});
|
|
143
116
|
|
|
144
117
|
test("rejects malformed percent-encoding as an invalid parse", () => {
|
|
@@ -146,10 +119,6 @@ describe("parseAssistantGatewayUrl", () => {
|
|
|
146
119
|
match: true,
|
|
147
120
|
valid: false,
|
|
148
121
|
});
|
|
149
|
-
expect(parseAssistantGatewayUrl("/__gateway/%zz/v1")).toEqual({
|
|
150
|
-
match: true,
|
|
151
|
-
valid: false,
|
|
152
|
-
});
|
|
153
122
|
});
|
|
154
123
|
|
|
155
124
|
test("does not match unrelated paths", () => {
|
|
@@ -220,27 +189,6 @@ describe("resolveGatewayProxyTarget", () => {
|
|
|
220
189
|
resolveGatewayProxyTarget("/v1/assistants/zzz-999/x", targets({})),
|
|
221
190
|
).toEqual({ kind: "pass" });
|
|
222
191
|
});
|
|
223
|
-
|
|
224
|
-
test("forwards the legacy prefix for unscoped gateway routes", () => {
|
|
225
|
-
expect(
|
|
226
|
-
resolveGatewayProxyTarget("/__gateway/abc-123/auth/token", entry),
|
|
227
|
-
).toEqual({
|
|
228
|
-
kind: "forward",
|
|
229
|
-
assistantId: "abc-123",
|
|
230
|
-
path: "/auth/token",
|
|
231
|
-
search: "",
|
|
232
|
-
target: loopback(8080),
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test("rejects an unknown id on the legacy prefix", () => {
|
|
237
|
-
expect(resolveGatewayProxyTarget("/__gateway/zzz-999/v1", entry)).toEqual(
|
|
238
|
-
rejection,
|
|
239
|
-
);
|
|
240
|
-
expect(
|
|
241
|
-
resolveGatewayProxyTarget("/__gateway/abc/../secret", entry),
|
|
242
|
-
).toEqual(rejection);
|
|
243
|
-
});
|
|
244
192
|
});
|
|
245
193
|
|
|
246
194
|
describe("gatewayTargetsFromLockfile", () => {
|
|
@@ -28,7 +28,6 @@ function writeLocalLockfile(overrides: Record<string, unknown> = {}): void {
|
|
|
28
28
|
instanceDir,
|
|
29
29
|
daemonPort: 30101,
|
|
30
30
|
gatewayPort: 30102,
|
|
31
|
-
qdrantPort: 30103,
|
|
32
31
|
},
|
|
33
32
|
...overrides,
|
|
34
33
|
});
|
|
@@ -147,7 +146,6 @@ describe("getLocalAssistantStatus", () => {
|
|
|
147
146
|
instanceDir,
|
|
148
147
|
daemonPort: await unusedPort(),
|
|
149
148
|
gatewayPort: 30102,
|
|
150
|
-
qdrantPort: 30103,
|
|
151
149
|
},
|
|
152
150
|
});
|
|
153
151
|
writeAssistantPid(String(process.pid));
|
|
@@ -167,7 +165,6 @@ describe("getLocalAssistantStatus", () => {
|
|
|
167
165
|
instanceDir,
|
|
168
166
|
daemonPort: await unusedPort(),
|
|
169
167
|
gatewayPort: 30102,
|
|
170
|
-
qdrantPort: 30103,
|
|
171
168
|
},
|
|
172
169
|
});
|
|
173
170
|
const pidPath = writeAssistantPid(String(process.pid));
|
|
@@ -194,7 +191,6 @@ describe("getLocalAssistantStatus", () => {
|
|
|
194
191
|
instanceDir,
|
|
195
192
|
daemonPort,
|
|
196
193
|
gatewayPort: await unusedPort(),
|
|
197
|
-
qdrantPort: 30103,
|
|
198
194
|
},
|
|
199
195
|
});
|
|
200
196
|
writeAssistantPid(String(process.pid));
|
|
@@ -21,15 +21,8 @@ export { FLATTENED_FIRST_SEGMENTS };
|
|
|
21
21
|
* hatched gateways) or recorded remote `runtimeUrl` (imported pairings), so
|
|
22
22
|
* the renderer never encodes a port or a host and the local/paired split
|
|
23
23
|
* lives entirely host-side.
|
|
24
|
-
*
|
|
25
|
-
* The legacy `/assistant/__gateway/{assistantId}` prefix survives only as
|
|
26
|
-
* transport for the gateway's UNSCOPED routes (`/auth/token` mint, `/readyz`
|
|
27
|
-
* probes, the lifecycle trio) until they fold into `/v1` too; it forwards the
|
|
28
|
-
* tail after the prefix.
|
|
29
24
|
*/
|
|
30
25
|
const GATEWAY_PATTERN = /^\/v1\/assistants\/([^/?#]+)(?:\/(.*))?$/;
|
|
31
|
-
const LEGACY_GATEWAY_PATTERN =
|
|
32
|
-
/^(?:\/assistant)?\/__gateway\/([^/?#]+)(\/.*)?$/;
|
|
33
26
|
|
|
34
27
|
export interface GatewayTarget {
|
|
35
28
|
assistantId: string;
|
|
@@ -40,13 +33,7 @@ export interface GatewayTarget {
|
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
export type GatewayParseResult =
|
|
43
|
-
| {
|
|
44
|
-
match: true;
|
|
45
|
-
valid: true;
|
|
46
|
-
/** False for the scoped surface, true for the legacy prefix. */
|
|
47
|
-
legacy: boolean;
|
|
48
|
-
target: GatewayTarget;
|
|
49
|
-
}
|
|
36
|
+
| { match: true; valid: true; target: GatewayTarget }
|
|
50
37
|
| { match: true; valid: false }
|
|
51
38
|
| { match: false };
|
|
52
39
|
|
|
@@ -74,15 +61,11 @@ function hasDotSegment(path: string): boolean {
|
|
|
74
61
|
/**
|
|
75
62
|
* Parse an assistant gateway's data-plane URL given as `pathname + search` (a
|
|
76
63
|
* `#fragment` suffix is tolerated and dropped), so every host hands over the
|
|
77
|
-
* same shape and the decision is host-independent.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* so the gateway receives exactly what the SDK addressed;
|
|
83
|
-
* - the legacy `/assistant/__gateway/{assistantId}[/tail]` prefix (with or
|
|
84
|
-
* without the `/assistant` mount) — the forward path is the tail after
|
|
85
|
-
* the prefix, the transport for the gateway's unscoped routes.
|
|
64
|
+
* same shape and the decision is host-independent. The scoped SDK surface
|
|
65
|
+
* `/v1/assistants/{assistantId}[/rest]` parses: the forward path is the scoped
|
|
66
|
+
* path itself (flattened for the contact family; the `readyz` tail forwards
|
|
67
|
+
* to the gateway's root `/readyz`), so the gateway receives exactly what the
|
|
68
|
+
* SDK addressed.
|
|
86
69
|
*/
|
|
87
70
|
export function parseAssistantGatewayUrl(url: string): GatewayParseResult {
|
|
88
71
|
const delimiter = url.search(/[?#]/);
|
|
@@ -114,37 +97,10 @@ export function parseAssistantGatewayUrl(url: string): GatewayParseResult {
|
|
|
114
97
|
FLATTENED_FIRST_SEGMENTS.has(firstSegment)
|
|
115
98
|
? `/v1/${rest}`
|
|
116
99
|
: pathname;
|
|
117
|
-
return {
|
|
118
|
-
match: true,
|
|
119
|
-
valid: true,
|
|
120
|
-
legacy: false,
|
|
121
|
-
target: { assistantId, path, search },
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const legacy = LEGACY_GATEWAY_PATTERN.exec(pathname);
|
|
126
|
-
if (!legacy) {
|
|
127
|
-
return { match: false };
|
|
100
|
+
return { match: true, valid: true, target: { assistantId, path, search } };
|
|
128
101
|
}
|
|
129
102
|
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
assistantId = decodeURIComponent(legacy[1]!);
|
|
133
|
-
} catch {
|
|
134
|
-
return { match: true, valid: false };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const path = legacy[2] || "/";
|
|
138
|
-
if (hasDotSegment(path)) {
|
|
139
|
-
return { match: true, valid: false };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
match: true,
|
|
144
|
-
valid: true,
|
|
145
|
-
legacy: true,
|
|
146
|
-
target: { assistantId, path, search },
|
|
147
|
-
};
|
|
103
|
+
return { match: false };
|
|
148
104
|
}
|
|
149
105
|
|
|
150
106
|
/**
|
|
@@ -164,15 +120,14 @@ export type GatewayEntryTarget =
|
|
|
164
120
|
* re-deriving the rules.
|
|
165
121
|
*
|
|
166
122
|
* - `pass` — not a gateway URL; the host serves it normally.
|
|
167
|
-
* - `reject` — a gateway URL whose id is malformed
|
|
168
|
-
* traversal attempt
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* `
|
|
174
|
-
*
|
|
175
|
-
* the status and message the host answers with.
|
|
123
|
+
* - `reject` — a gateway URL whose id is malformed or whose tail is a
|
|
124
|
+
* traversal attempt (the security boundary: the proxy only
|
|
125
|
+
* reaches gateways of assistants the user actually hatched
|
|
126
|
+
* or imported, never arbitrary loopback services or URLs).
|
|
127
|
+
* An unknown id is `pass` instead: cloud assistants' SDK
|
|
128
|
+
* routes and stale ids fall through to the host's generic
|
|
129
|
+
* `/v1` handling. Carries the status and message the host
|
|
130
|
+
* answers with.
|
|
176
131
|
* - `forward` — forward to the entry's resolved target, carrying the
|
|
177
132
|
* assistant id so the trusted host can resolve its bearer.
|
|
178
133
|
*/
|
|
@@ -216,10 +171,7 @@ export function resolveGatewayProxyTarget(
|
|
|
216
171
|
}
|
|
217
172
|
const target = getTargets().get(parsed.target.assistantId);
|
|
218
173
|
if (!target) {
|
|
219
|
-
|
|
220
|
-
return { kind: "pass" };
|
|
221
|
-
}
|
|
222
|
-
return GATEWAY_REJECTION;
|
|
174
|
+
return { kind: "pass" };
|
|
223
175
|
}
|
|
224
176
|
return {
|
|
225
177
|
kind: "forward",
|
|
@@ -46,7 +46,6 @@ export {
|
|
|
46
46
|
renameLockfileAssistantIfPresent,
|
|
47
47
|
stampLockfileAssistantOnboardedIfPresent,
|
|
48
48
|
upsertLockfileAssistant,
|
|
49
|
-
upsertRendererLockfileAssistant,
|
|
50
49
|
replaceCloudAssistants,
|
|
51
50
|
isActiveAssistant,
|
|
52
51
|
isPairedLockfileEntry,
|
|
@@ -54,7 +53,12 @@ export {
|
|
|
54
53
|
export type { LockfileResult, WriteResult } from "./lockfile";
|
|
55
54
|
export { withLockfileLock } from "./lockfile-lock";
|
|
56
55
|
export type { LockfileLockResult } from "./lockfile-lock";
|
|
57
|
-
export {
|
|
56
|
+
export {
|
|
57
|
+
getLoopbackGatewayPort,
|
|
58
|
+
LockfileAssistantSchema,
|
|
59
|
+
parseLockfile,
|
|
60
|
+
} from "./lockfile-contract";
|
|
61
|
+
export { readRawLockfileStrict } from "./lockfile";
|
|
58
62
|
export type {
|
|
59
63
|
Lockfile,
|
|
60
64
|
LockfileAssistant,
|
|
@@ -229,7 +229,6 @@ describe("parseLockfile", () => {
|
|
|
229
229
|
daemonPort: 7778,
|
|
230
230
|
runtimeVersion: "v0.8.13",
|
|
231
231
|
runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
|
|
232
|
-
qdrantPort: 7779,
|
|
233
232
|
cesPort: 7780,
|
|
234
233
|
signingKey: "hunter2",
|
|
235
234
|
},
|
|
@@ -243,7 +242,6 @@ describe("parseLockfile", () => {
|
|
|
243
242
|
daemonPort: 7778,
|
|
244
243
|
runtimeVersion: "v0.8.13",
|
|
245
244
|
runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
|
|
246
|
-
qdrantPort: 7779,
|
|
247
245
|
cesPort: 7780,
|
|
248
246
|
signingKey: "hunter2",
|
|
249
247
|
});
|
|
@@ -255,7 +253,6 @@ describe("parseLockfile", () => {
|
|
|
255
253
|
daemonPort: 7778,
|
|
256
254
|
runtimeVersion: "v0.8.13",
|
|
257
255
|
runtimeInstallDir: "/tmp/cadet/runtime/0.8.13",
|
|
258
|
-
qdrantPort: 7779,
|
|
259
256
|
cesPort: 7780,
|
|
260
257
|
});
|
|
261
258
|
});
|
|
@@ -124,7 +124,7 @@ export function isUsableRuntimeUrl(url: unknown): url is string {
|
|
|
124
124
|
/**
|
|
125
125
|
* First segments whose scoped `/v1/assistants/{id}/` prefix the gateway does
|
|
126
126
|
* not serve: the contact family lives on flat `/v1/...` control-plane routes
|
|
127
|
-
* (the shape the cloud's
|
|
127
|
+
* (the shape the cloud's runtime-proxy strip delivers). Every
|
|
128
128
|
* forwarder to the gateway — the scoped host proxy and the request
|
|
129
129
|
* interceptor's remote-ingress rewrite alike — flattens them to match.
|
|
130
130
|
*/
|
|
@@ -200,8 +200,6 @@ export const LocalAssistantResourcesSchema = z.object({
|
|
|
200
200
|
instanceDir: z.string().optional(),
|
|
201
201
|
gatewayPort: z.number(),
|
|
202
202
|
daemonPort: z.number(),
|
|
203
|
-
/** HTTP port for the Qdrant vector store (host-only). */
|
|
204
|
-
qdrantPort: z.number().optional(),
|
|
205
203
|
/** HTTP port for the CES (Claude Extension Server) (host-only). */
|
|
206
204
|
cesPort: z.number().optional(),
|
|
207
205
|
runtimeVersion: z.string().optional(),
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
stampLockfileAssistantOnboardedIfPresent,
|
|
11
11
|
replaceCloudAssistants,
|
|
12
12
|
upsertLockfileAssistant,
|
|
13
|
-
upsertRendererLockfileAssistant,
|
|
14
13
|
} from "./lockfile";
|
|
15
14
|
|
|
16
15
|
let dir: string;
|
|
@@ -558,36 +557,6 @@ describe("lockfile writers under lock contention", () => {
|
|
|
558
557
|
});
|
|
559
558
|
});
|
|
560
559
|
|
|
561
|
-
describe("upsertRendererLockfileAssistant", () => {
|
|
562
|
-
const paired = {
|
|
563
|
-
assistantId: "paired-1",
|
|
564
|
-
paired: true,
|
|
565
|
-
runtimeUrl: "https://gateway.example.com",
|
|
566
|
-
name: "Paired assistant",
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
test("allows non-security updates and activation of an existing pairing", () => {
|
|
570
|
-
writeOnDisk({ assistants: [paired], activeAssistant: null });
|
|
571
|
-
|
|
572
|
-
const result = upsertRendererLockfileAssistant(
|
|
573
|
-
[lockfilePath],
|
|
574
|
-
{
|
|
575
|
-
assistantId: "paired-1",
|
|
576
|
-
paired: true,
|
|
577
|
-
runtimeUrl: "https://gateway.example.com",
|
|
578
|
-
name: "Renamed pairing",
|
|
579
|
-
},
|
|
580
|
-
"paired-1",
|
|
581
|
-
);
|
|
582
|
-
|
|
583
|
-
expect(result.ok).toBe(true);
|
|
584
|
-
expect(readOnDisk()).toEqual({
|
|
585
|
-
assistants: [{ ...paired, name: "Renamed pairing" }],
|
|
586
|
-
activeAssistant: "paired-1",
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
});
|
|
590
|
-
|
|
591
560
|
describe("replaceCloudAssistants", () => {
|
|
592
561
|
test("rejects a renderer sync that tries to create a paired entry", () => {
|
|
593
562
|
writeOnDisk({
|
|
@@ -292,7 +292,34 @@ export function upsertLockfileAssistant(
|
|
|
292
292
|
(a: Record<string, unknown>) => a?.assistantId === assistant.assistantId,
|
|
293
293
|
);
|
|
294
294
|
if (existingIdx >= 0) {
|
|
295
|
-
|
|
295
|
+
const existing = assistants[existingIdx]!;
|
|
296
|
+
let incoming: Record<string, unknown> = assistant;
|
|
297
|
+
const storedResources = existing.resources;
|
|
298
|
+
const incomingResources = incoming.resources;
|
|
299
|
+
if (
|
|
300
|
+
incomingResources !== undefined &&
|
|
301
|
+
typeof storedResources === "object" &&
|
|
302
|
+
storedResources !== null &&
|
|
303
|
+
"signingKey" in storedResources &&
|
|
304
|
+
typeof storedResources.signingKey === "string" &&
|
|
305
|
+
!(
|
|
306
|
+
typeof incomingResources === "object" &&
|
|
307
|
+
incomingResources !== null &&
|
|
308
|
+
"signingKey" in incomingResources &&
|
|
309
|
+
incomingResources.signingKey !== undefined
|
|
310
|
+
)
|
|
311
|
+
) {
|
|
312
|
+
// The signing key is host custody: a save whose resources ride
|
|
313
|
+
// without one (the renderer's stripped view) never unsets it.
|
|
314
|
+
incoming = {
|
|
315
|
+
...incoming,
|
|
316
|
+
resources: {
|
|
317
|
+
...incomingResources,
|
|
318
|
+
signingKey: storedResources.signingKey,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
assistants[existingIdx] = { ...existing, ...incoming };
|
|
296
323
|
} else {
|
|
297
324
|
assistants.push(assistant);
|
|
298
325
|
}
|
|
@@ -306,53 +333,6 @@ export function upsertLockfileAssistant(
|
|
|
306
333
|
return locked.ok ? locked.value : lockFailure(locked.error);
|
|
307
334
|
}
|
|
308
335
|
|
|
309
|
-
// The renderer surface is an ALLOWLIST over the strict base schema: the base
|
|
310
|
-
// models host-owned fields (the secrets, resources, addressing, process
|
|
311
|
-
// bookkeeping) that must never ride a renderer payload, so a renderer save
|
|
312
|
-
// parses through the fields a renderer may write and nothing else — a newly
|
|
313
|
-
// modeled field is renderer-invisible until deliberately added here.
|
|
314
|
-
// `cloud` additionally never rides because the schema's `catch` would
|
|
315
|
-
// otherwise materialize a spurious "local" into every upsert, clobbering the
|
|
316
|
-
// recorded topology on merge.
|
|
317
|
-
const RendererAssistantUpdateSchema = LockfileAssistantSchema.pick({
|
|
318
|
-
assistantId: true,
|
|
319
|
-
name: true,
|
|
320
|
-
runtimeUrl: true,
|
|
321
|
-
hatchedAt: true,
|
|
322
|
-
onboardedAt: true,
|
|
323
|
-
cloudAssistantId: true,
|
|
324
|
-
cloudBaseUrl: true,
|
|
325
|
-
cloudOrganizationId: true,
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Apply a renderer-originated lockfile upsert. Resources and secrets are
|
|
330
|
-
* host-owned and never accepted from a renderer.
|
|
331
|
-
*/
|
|
332
|
-
export function upsertRendererLockfileAssistant(
|
|
333
|
-
lockfilePaths: string[],
|
|
334
|
-
assistant: Record<string, unknown>,
|
|
335
|
-
activeAssistant: string | undefined,
|
|
336
|
-
): WriteResult {
|
|
337
|
-
if (!assistant || typeof assistant.assistantId !== "string") {
|
|
338
|
-
return { ok: false, status: 400, error: "Missing assistant.assistantId" };
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const locked = withLockfileLock(lockfilePaths, (): WriteResult => {
|
|
342
|
-
const read = readRawLockfileStrict(lockfilePaths);
|
|
343
|
-
if (!read.ok) {
|
|
344
|
-
return { ok: false, status: 409, error: read.error };
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const update = RendererAssistantUpdateSchema.safeParse(assistant);
|
|
348
|
-
if (!update.success) {
|
|
349
|
-
return { ok: false, status: 400, error: "Invalid assistant metadata" };
|
|
350
|
-
}
|
|
351
|
-
return upsertLockfileAssistant(lockfilePaths, update.data, activeAssistant);
|
|
352
|
-
});
|
|
353
|
-
return locked.ok ? locked.value : lockFailure(locked.error);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
336
|
export function isActiveAssistant(
|
|
357
337
|
lockfilePaths: string[],
|
|
358
338
|
assistantId: string,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The version string a source checkout reports for `--version`.
|
|
@@ -39,6 +40,18 @@ function isSourceCheckout(entryPath: string): boolean {
|
|
|
39
40
|
return entryPath.endsWith(".ts");
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* This module's own file path, in whichever runtime is asking. Node only has
|
|
45
|
+
* `import.meta.url` — and bundlers rewrite it back to this file's real path
|
|
46
|
+
* (electron-vite's config loader injects it per module; rollup shims it to
|
|
47
|
+
* `__filename` in CJS output), so the URL is the trustworthy source everywhere:
|
|
48
|
+
* Bun, Node, and bundled evaluation all resolve it to this file on disk.
|
|
49
|
+
*/
|
|
50
|
+
function moduleEntryPath(): string {
|
|
51
|
+
if (typeof import.meta.url === "string") return fileURLToPath(import.meta.url);
|
|
52
|
+
return import.meta.path;
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
function gitRepoRoot(entryPath: string): string | null {
|
|
43
56
|
let dir = dirname(entryPath);
|
|
44
57
|
for (;;) {
|
|
@@ -72,7 +85,7 @@ function headCommitTime(root: string): Date | null {
|
|
|
72
85
|
export function stampedVersion(
|
|
73
86
|
base: string,
|
|
74
87
|
now: Date = new Date(),
|
|
75
|
-
entryPath: string =
|
|
88
|
+
entryPath: string = moduleEntryPath(),
|
|
76
89
|
): string {
|
|
77
90
|
if (!isSourceCheckout(entryPath)) return base;
|
|
78
91
|
const root = gitRepoRoot(entryPath);
|
|
@@ -103,5 +116,5 @@ export function resolveVersion(packageRoot: string = process.cwd()): string {
|
|
|
103
116
|
}
|
|
104
117
|
if (!base) return "";
|
|
105
118
|
if ((process.env.CADET_ENVIRONMENT || "local") !== "local") return base;
|
|
106
|
-
return stampedVersion(base, new Date(),
|
|
119
|
+
return stampedVersion(base, new Date(), moduleEntryPath());
|
|
107
120
|
}
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ import { join } from "node:path";
|
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
|
|
20
20
|
import * as tunnelLib from "../lib/tunnel.js";
|
|
21
|
-
import type {
|
|
21
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
22
22
|
import * as nginxIngress from "../lib/nginx-ingress.js";
|
|
23
23
|
|
|
24
24
|
const ensureNginxForEdgeMock = mock(tunnelLib.ensureNginxForEdge);
|
|
@@ -90,7 +90,7 @@ afterAll(() => {
|
|
|
90
90
|
rmSync(testDir, { recursive: true, force: true });
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
const LOCAL_ENTRY:
|
|
93
|
+
const LOCAL_ENTRY: LockfileAssistant = {
|
|
94
94
|
assistantId: "assistant-1",
|
|
95
95
|
runtimeUrl: "http://127.0.0.1:7830",
|
|
96
96
|
cloud: "local",
|
|
@@ -22,7 +22,7 @@ const ORIGINAL_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
|
|
|
22
22
|
const ORIGINAL_FETCH = globalThis.fetch;
|
|
23
23
|
|
|
24
24
|
import { AssistantClient } from "../lib/assistant-client.js";
|
|
25
|
-
import {
|
|
25
|
+
import { saveLockfileAssistant } from "../lib/assistant-config.js";
|
|
26
26
|
import {
|
|
27
27
|
clearCloudToken,
|
|
28
28
|
saveCloudToken,
|
|
@@ -34,7 +34,7 @@ const ORG_ID = "org-abc";
|
|
|
34
34
|
|
|
35
35
|
/** Seed a cloud-managed lockfile entry, optionally with a stored token. */
|
|
36
36
|
function seedCloud(token?: string): void {
|
|
37
|
-
|
|
37
|
+
saveLockfileAssistant({
|
|
38
38
|
assistantId: ASSISTANT_ID,
|
|
39
39
|
name: "Credence",
|
|
40
40
|
runtimeUrl: PLATFORM_URL,
|
|
@@ -22,7 +22,7 @@ const ORIGINAL_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
|
|
|
22
22
|
const ORIGINAL_FETCH = globalThis.fetch;
|
|
23
23
|
|
|
24
24
|
import { AssistantClient } from "../lib/assistant-client.js";
|
|
25
|
-
import {
|
|
25
|
+
import { saveLockfileAssistant } from "../lib/assistant-config.js";
|
|
26
26
|
import { loadGuardianToken, saveGuardianToken } from "../lib/guardian-token.js";
|
|
27
27
|
|
|
28
28
|
const RUNTIME = "https://gw.example.com";
|
|
@@ -36,7 +36,7 @@ const PAST = new Date(Date.now() - 60_000).toISOString();
|
|
|
36
36
|
*/
|
|
37
37
|
function seedPaired(refreshToken: string, opts?: { due?: boolean }): void {
|
|
38
38
|
const due = opts?.due ?? true;
|
|
39
|
-
|
|
39
|
+
saveLockfileAssistant({
|
|
40
40
|
assistantId: "px",
|
|
41
41
|
name: "Paired",
|
|
42
42
|
runtimeUrl: RUNTIME,
|