@mycadet/cli 0.13.0-dev.202611171301.b3e2e5c → 0.13.0-dev.202611181327.a51316f
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/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/eslint/base.mjs +57 -0
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +2 -1
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/helpers/memory-cookie-jar.ts +23 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-proxy.test.ts +79 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-routes.test.ts +106 -3
- package/node_modules/@mycadet/local-mode/src/index.ts +6 -0
- package/node_modules/@mycadet/local-mode/src/operations/cookie-jar.ts +102 -0
- package/node_modules/@mycadet/local-mode/src/operations/routes.ts +78 -14
- package/node_modules/@mycadet/local-mode/src/served-config.test.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/served-config.ts +0 -1
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/eslint/base.mjs +57 -0
- package/node_modules/@mycadet/shared/package.json +2 -1
- package/package.json +1 -1
- package/src/__tests__/web-dist.test.ts +54 -1
- package/src/lib/web-dist.ts +28 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
|
|
5
|
+
import { importsFirst } from "./imports-first.mjs";
|
|
6
|
+
import { noEmptyImports } from "./no-empty-imports.mjs";
|
|
7
|
+
import { noReExports } from "./no-re-exports.mjs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The `@mycadet` plugin, wired once. Every shared custom rule registers
|
|
11
|
+
* here; a service opts in by naming the rule (`@mycadet/imports-first`)
|
|
12
|
+
* rather than re-assembling the plugin — flat config would overwrite a
|
|
13
|
+
* same-named plugin definition wholesale, so one shared object identity
|
|
14
|
+
* is what keeps adoption declarative.
|
|
15
|
+
*/
|
|
16
|
+
export const mycadetPlugin = {
|
|
17
|
+
rules: {
|
|
18
|
+
"imports-first": importsFirst,
|
|
19
|
+
"no-empty-imports": noEmptyImports,
|
|
20
|
+
"no-re-exports": noReExports,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The repo's lint floor: the rules every service already enforces,
|
|
26
|
+
* declared once. Spread it first and add only what's yours — later
|
|
27
|
+
* config items win.
|
|
28
|
+
*
|
|
29
|
+
* Re-export shims are outlawed everywhere: consumers import from the
|
|
30
|
+
* defining module, and only index files aggregate a public surface.
|
|
31
|
+
* Warning-level countdowns (cast bans, mock.module, namespace imports)
|
|
32
|
+
* stay per-service — their pins are local.
|
|
33
|
+
*
|
|
34
|
+
* @param {{ ignores?: string[] }} [options]
|
|
35
|
+
* Extra global ignores for service build output (e.g. `drizzle/**`).
|
|
36
|
+
* `dist/**` is always ignored.
|
|
37
|
+
*/
|
|
38
|
+
export function baseEslintConfig(options = {}) {
|
|
39
|
+
const { ignores = [] } = options;
|
|
40
|
+
return defineConfig([
|
|
41
|
+
...tseslint.configs.recommended,
|
|
42
|
+
globalIgnores(["dist/**", ...ignores]),
|
|
43
|
+
{
|
|
44
|
+
plugins: { "@mycadet": mycadetPlugin },
|
|
45
|
+
rules: {
|
|
46
|
+
// Unused symbols are noise the compiler can't see (params kept
|
|
47
|
+
// for signature shape, type-only imports); an underscore-prefixed
|
|
48
|
+
// name declares the intent to keep.
|
|
49
|
+
"@typescript-eslint/no-unused-vars": [
|
|
50
|
+
"error",
|
|
51
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
|
|
52
|
+
],
|
|
53
|
+
"@mycadet/no-re-exports": "error",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/shared",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202611181327.a51316f",
|
|
4
4
|
"private": true,
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts",
|
|
7
7
|
"./eslint/imports-first": "./eslint/imports-first.mjs",
|
|
8
|
+
"./eslint/base": "./eslint/base.mjs",
|
|
8
9
|
"./eslint/no-empty-imports": "./eslint/no-empty-imports.mjs",
|
|
9
10
|
"./eslint/no-re-exports": "./eslint/no-re-exports.mjs",
|
|
10
11
|
"./fetch": "./fetch.ts",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CookieJar, OriginCookie } from "../../operations/cookie-jar";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Map-backed `CookieJar` fake: cookies keyed by origin URL, a re-set of
|
|
5
|
+
* a held name replacing it like a real store. The route-table tests seed
|
|
6
|
+
* `store` directly to arrange a jar state, then read it to assert what a
|
|
7
|
+
* row stored.
|
|
8
|
+
*/
|
|
9
|
+
export class MemoryCookieJar implements CookieJar {
|
|
10
|
+
readonly store = new Map<string, OriginCookie[]>();
|
|
11
|
+
|
|
12
|
+
async get(url: string): Promise<OriginCookie[]> {
|
|
13
|
+
return [...(this.store.get(url) ?? [])];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async set(url: string, cookie: OriginCookie): Promise<void> {
|
|
17
|
+
const list = this.store.get(url) ?? [];
|
|
18
|
+
const existing = list.findIndex((held) => held.name === cookie.name);
|
|
19
|
+
if (existing >= 0) list[existing] = cookie;
|
|
20
|
+
else list.push(cookie);
|
|
21
|
+
this.store.set(url, list);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -5,6 +5,7 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
7
7
|
import { matchOperatorRequest } from "../operations/routes";
|
|
8
|
+
import { MemoryCookieJar } from "./helpers/memory-cookie-jar";
|
|
8
9
|
|
|
9
10
|
// The proxy row forwards through globalThis.fetch; the real one stays
|
|
10
11
|
// snapshotted for the per-test restore (bun runs every test file in one
|
|
@@ -81,6 +82,7 @@ const runProxy = async (
|
|
|
81
82
|
headers?: Headers | IncomingHttpHeaders;
|
|
82
83
|
body?: ReadableStream | null;
|
|
83
84
|
peer?: string | null;
|
|
85
|
+
cookieJar?: MemoryCookieJar;
|
|
84
86
|
},
|
|
85
87
|
): Promise<Response> => {
|
|
86
88
|
const path = `/v1/assistants/asst-local/${tail}`;
|
|
@@ -93,6 +95,7 @@ const runProxy = async (
|
|
|
93
95
|
peer: init?.peer,
|
|
94
96
|
headers: init?.headers,
|
|
95
97
|
body: init?.body ?? null,
|
|
98
|
+
...(init?.cookieJar ? { cookieJar: init.cookieJar } : {}),
|
|
96
99
|
});
|
|
97
100
|
expect(response).not.toBeNull();
|
|
98
101
|
return response!;
|
|
@@ -111,6 +114,82 @@ describe("the operator route table — the proxy catch-all", () => {
|
|
|
111
114
|
expect(calls[0]!.headers.get("x-cadet-client-ip")).toBe("198.51.100.7");
|
|
112
115
|
});
|
|
113
116
|
|
|
117
|
+
test("the dial carries the host's jar cookies when the caller brings none", async () => {
|
|
118
|
+
seedLocalEntry();
|
|
119
|
+
const calls = stubGatewayFetch();
|
|
120
|
+
const jar = new MemoryCookieJar();
|
|
121
|
+
await jar.set("http://127.0.0.1:7830", {
|
|
122
|
+
name: "cadet_web_access",
|
|
123
|
+
value: "edge-token-1",
|
|
124
|
+
});
|
|
125
|
+
await jar.set("http://127.0.0.1:7830", {
|
|
126
|
+
name: "cadet_web_refresh",
|
|
127
|
+
value: "edge-token-2",
|
|
128
|
+
});
|
|
129
|
+
await runProxy("conversations", { cookieJar: jar });
|
|
130
|
+
expect(calls[0]!.headers.get("cookie")).toBe(
|
|
131
|
+
"cadet_web_access=edge-token-1; cadet_web_refresh=edge-token-2",
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a caller's own cookie wins — the jar never double-attaches", async () => {
|
|
136
|
+
seedLocalEntry();
|
|
137
|
+
const calls = stubGatewayFetch();
|
|
138
|
+
const jar = new MemoryCookieJar();
|
|
139
|
+
await jar.set("http://127.0.0.1:7830", {
|
|
140
|
+
name: "cadet_web_access",
|
|
141
|
+
value: "jar-copy",
|
|
142
|
+
});
|
|
143
|
+
await runProxy("conversations", {
|
|
144
|
+
headers: new Headers({ cookie: "cadet_web_access=browser-pair" }),
|
|
145
|
+
cookieJar: jar,
|
|
146
|
+
});
|
|
147
|
+
expect(calls[0]!.headers.get("cookie")).toBe(
|
|
148
|
+
"cadet_web_access=browser-pair",
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("a rotation response re-stores the fresh pair for the gateway origin", async () => {
|
|
153
|
+
seedLocalEntry();
|
|
154
|
+
const jar = new MemoryCookieJar();
|
|
155
|
+
stubGatewayFetch(() => {
|
|
156
|
+
const headers = new Headers();
|
|
157
|
+
headers.append(
|
|
158
|
+
"set-cookie",
|
|
159
|
+
"cadet_web_access=rotated-1; HttpOnly; Path=/; SameSite=Strict",
|
|
160
|
+
);
|
|
161
|
+
return new Response("ok", { headers });
|
|
162
|
+
});
|
|
163
|
+
const response = await runProxy("conversations", { cookieJar: jar });
|
|
164
|
+
// The row parsed the Set-Cookie value into the store's grain and
|
|
165
|
+
// stored it for the origin the next dial attaches.
|
|
166
|
+
expect(jar.store.get("http://127.0.0.1:7830")).toEqual([
|
|
167
|
+
{
|
|
168
|
+
name: "cadet_web_access",
|
|
169
|
+
value: "rotated-1",
|
|
170
|
+
path: "/",
|
|
171
|
+
httpOnly: true,
|
|
172
|
+
sameSite: "strict",
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
// The Set-Cookie headers still ride for native browser jars.
|
|
176
|
+
expect(response.headers.getSetCookie()).toHaveLength(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("a host without a jar forwards the rotation untouched — its browser jars natively", async () => {
|
|
180
|
+
seedLocalEntry();
|
|
181
|
+
stubGatewayFetch(() => {
|
|
182
|
+
const headers = new Headers();
|
|
183
|
+
headers.append(
|
|
184
|
+
"set-cookie",
|
|
185
|
+
"cadet_web_access=rotated-1; HttpOnly; Path=/; SameSite=Strict",
|
|
186
|
+
);
|
|
187
|
+
return new Response("ok", { headers });
|
|
188
|
+
});
|
|
189
|
+
const response = await runProxy("conversations");
|
|
190
|
+
expect(response.headers.getSetCookie()).toHaveLength(1);
|
|
191
|
+
});
|
|
192
|
+
|
|
114
193
|
test("the client-ip stamp falls back to the raw peer, then the loopback default", async () => {
|
|
115
194
|
seedLocalEntry();
|
|
116
195
|
const calls = stubGatewayFetch();
|
|
@@ -25,9 +25,22 @@ const hatchAssistantMock = mock(
|
|
|
25
25
|
async (_options: {
|
|
26
26
|
remote: string;
|
|
27
27
|
}): Promise<
|
|
28
|
-
| {
|
|
28
|
+
| {
|
|
29
|
+
ok: true;
|
|
30
|
+
assistant: { assistantId: string; cloud?: string; port?: number };
|
|
31
|
+
ready: boolean;
|
|
32
|
+
cookies: string[];
|
|
33
|
+
}
|
|
29
34
|
| { ok: false; status: number; error: string }
|
|
30
|
-
> => ({
|
|
35
|
+
> => ({
|
|
36
|
+
ok: true,
|
|
37
|
+
assistant: { assistantId: "hatched-1" },
|
|
38
|
+
ready: true,
|
|
39
|
+
cookies: [
|
|
40
|
+
"cadet_web_access=edge-token-1; HttpOnly; Path=/; SameSite=Strict",
|
|
41
|
+
"cadet_web_refresh=edge-token-2; HttpOnly; Path=/; SameSite=Strict; Max-Age=3600",
|
|
42
|
+
],
|
|
43
|
+
}),
|
|
31
44
|
);
|
|
32
45
|
const runDevicesListMock = mock(async (_assistantId: string) => ({
|
|
33
46
|
ok: true as const,
|
|
@@ -102,6 +115,7 @@ const pairingCancelMock = mock((_handle?: unknown): boolean => true);
|
|
|
102
115
|
import { readLockfile } from "../lockfile";
|
|
103
116
|
import { stripSensitiveFields } from "../util";
|
|
104
117
|
import { matchOperatorRequest } from "../operations/routes";
|
|
118
|
+
import { MemoryCookieJar } from "./helpers/memory-cookie-jar";
|
|
105
119
|
|
|
106
120
|
let tmpDir: string;
|
|
107
121
|
let lockfilePath: string;
|
|
@@ -161,6 +175,10 @@ beforeEach(() => {
|
|
|
161
175
|
ok: true as const,
|
|
162
176
|
assistant: { assistantId: "hatched-1" },
|
|
163
177
|
ready: true,
|
|
178
|
+
cookies: [
|
|
179
|
+
"cadet_web_access=edge-token-1; HttpOnly; Path=/; SameSite=Strict",
|
|
180
|
+
"cadet_web_refresh=edge-token-2; HttpOnly; Path=/; SameSite=Strict; Max-Age=3600",
|
|
181
|
+
],
|
|
164
182
|
}),
|
|
165
183
|
);
|
|
166
184
|
runDevicesListMock.mockImplementation(async () => ({
|
|
@@ -226,6 +244,7 @@ const dispatch = (
|
|
|
226
244
|
pathname: string,
|
|
227
245
|
method: string,
|
|
228
246
|
body?: unknown,
|
|
247
|
+
cookieJar?: MemoryCookieJar,
|
|
229
248
|
): Promise<Response | null> => {
|
|
230
249
|
const match = matchOperatorRequest(pathname, method);
|
|
231
250
|
if (!match) {
|
|
@@ -241,6 +260,7 @@ const dispatch = (
|
|
|
241
260
|
return match.route.run({
|
|
242
261
|
assistantId: match.assistantId,
|
|
243
262
|
body: request.body,
|
|
263
|
+
...(cookieJar ? { cookieJar } : {}),
|
|
244
264
|
});
|
|
245
265
|
};
|
|
246
266
|
|
|
@@ -249,8 +269,9 @@ const dispatchAnswered = async (
|
|
|
249
269
|
pathname: string,
|
|
250
270
|
method: string,
|
|
251
271
|
body?: unknown,
|
|
272
|
+
cookieJar?: MemoryCookieJar,
|
|
252
273
|
): Promise<Response> => {
|
|
253
|
-
const response = await dispatch(pathname, method, body);
|
|
274
|
+
const response = await dispatch(pathname, method, body, cookieJar);
|
|
254
275
|
if (!response) {
|
|
255
276
|
throw new Error(`${method} ${pathname} passed through; expected an answer`);
|
|
256
277
|
}
|
|
@@ -324,6 +345,88 @@ describe("the hatch row — POST /v1/assistants/hatch", () => {
|
|
|
324
345
|
error: "docker daemon unreachable",
|
|
325
346
|
});
|
|
326
347
|
});
|
|
348
|
+
|
|
349
|
+
test("the hatch jars the pair for the entry's gateway origin", async () => {
|
|
350
|
+
hatchAssistantMock.mockImplementation(async () => ({
|
|
351
|
+
ok: true as const,
|
|
352
|
+
assistant: { assistantId: "hatched-1", cloud: "local", port: 7833 },
|
|
353
|
+
ready: true,
|
|
354
|
+
cookies: [
|
|
355
|
+
"cadet_web_access=edge-token-1; HttpOnly; Path=/; SameSite=Strict",
|
|
356
|
+
"cadet_web_refresh=edge-token-2; HttpOnly; Path=/; SameSite=Strict; Max-Age=3600",
|
|
357
|
+
],
|
|
358
|
+
}));
|
|
359
|
+
const jar = new MemoryCookieJar();
|
|
360
|
+
|
|
361
|
+
const response = await dispatchAnswered(
|
|
362
|
+
"/v1/assistants/hatch",
|
|
363
|
+
"POST",
|
|
364
|
+
{ remote: "local" },
|
|
365
|
+
jar,
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// The origin the proxy row dials (`getGatewayUrl`) — the only origin
|
|
369
|
+
// a cookie store holds the pair for; `app://` itself is refused. The
|
|
370
|
+
// row parsed each Set-Cookie value into the store's grain.
|
|
371
|
+
const stored = jar.store.get("http://127.0.0.1:7833");
|
|
372
|
+
expect(stored?.map((cookie) => cookie.name)).toEqual([
|
|
373
|
+
"cadet_web_access",
|
|
374
|
+
"cadet_web_refresh",
|
|
375
|
+
]);
|
|
376
|
+
const refresh = stored?.find((c) => c.name === "cadet_web_refresh");
|
|
377
|
+
expect(refresh).toMatchObject({
|
|
378
|
+
value: "edge-token-2",
|
|
379
|
+
path: "/",
|
|
380
|
+
httpOnly: true,
|
|
381
|
+
sameSite: "strict",
|
|
382
|
+
});
|
|
383
|
+
expect(refresh?.expirationDate).toBe(Math.floor(Date.now() / 1000) + 3600);
|
|
384
|
+
// The pair still rides the response — the CLI edge's and dev server's
|
|
385
|
+
// browser callers jar natively, and the headers stay visible for QA.
|
|
386
|
+
const cookies = response.headers.getSetCookie();
|
|
387
|
+
expect(cookies).toHaveLength(2);
|
|
388
|
+
expect(cookies[0].startsWith("cadet_web_access=")).toBe(true);
|
|
389
|
+
expect(cookies[1].startsWith("cadet_web_refresh=")).toBe(true);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("a host without a jar still ships the pair as Set-Cookie headers", async () => {
|
|
393
|
+
hatchAssistantMock.mockImplementation(async () => ({
|
|
394
|
+
ok: true as const,
|
|
395
|
+
assistant: { assistantId: "hatched-1", cloud: "local", port: 7833 },
|
|
396
|
+
ready: true,
|
|
397
|
+
cookies: [
|
|
398
|
+
"cadet_web_access=edge-token-1; HttpOnly; Path=/; SameSite=Strict",
|
|
399
|
+
],
|
|
400
|
+
}));
|
|
401
|
+
|
|
402
|
+
const response = await dispatchAnswered("/v1/assistants/hatch", "POST", {});
|
|
403
|
+
|
|
404
|
+
expect(response.headers.getSetCookie()).toHaveLength(1);
|
|
405
|
+
expect((await response.json()).ok).toBe(true);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("an unresolvable gateway origin jars nothing but still ships the pair", async () => {
|
|
409
|
+
hatchAssistantMock.mockImplementation(async () => ({
|
|
410
|
+
ok: true as const,
|
|
411
|
+
assistant: { assistantId: "hatched-1" },
|
|
412
|
+
ready: true,
|
|
413
|
+
cookies: [
|
|
414
|
+
"cadet_web_access=edge-token-1; HttpOnly; Path=/; SameSite=Strict",
|
|
415
|
+
],
|
|
416
|
+
}));
|
|
417
|
+
const jar = new MemoryCookieJar();
|
|
418
|
+
|
|
419
|
+
const response = await dispatchAnswered(
|
|
420
|
+
"/v1/assistants/hatch",
|
|
421
|
+
"POST",
|
|
422
|
+
{},
|
|
423
|
+
jar,
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
expect(jar.store.size).toBe(0);
|
|
427
|
+
expect(response.headers.getSetCookie()).toHaveLength(1);
|
|
428
|
+
expect((await response.json()).ok).toBe(true);
|
|
429
|
+
});
|
|
327
430
|
});
|
|
328
431
|
|
|
329
432
|
describe("the unpair row — POST /v1/assistants/{id}/unpair", () => {
|
|
@@ -91,6 +91,12 @@ export {
|
|
|
91
91
|
matchOperatorRequest,
|
|
92
92
|
forwardOperatorRequest,
|
|
93
93
|
} from "./operations/routes";
|
|
94
|
+
export {
|
|
95
|
+
cookieHeader,
|
|
96
|
+
parseSetCookie,
|
|
97
|
+
type CookieJar,
|
|
98
|
+
type OriginCookie,
|
|
99
|
+
} from "./operations/cookie-jar";
|
|
94
100
|
|
|
95
101
|
export { retireAssistant } from "./operations/retire";
|
|
96
102
|
export { sleepAssistant, type SleepOptions } from "./operations/sleep";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cookie custody seam between the operator route table and the serving
|
|
3
|
+
* host's cookie store. The cookie-carrying rows — the hatch row, which
|
|
4
|
+
* mints the webview's credential pair, and the proxy row, whose upstream
|
|
5
|
+
* rotates it — speak this interface instead of a wire convention: the host
|
|
6
|
+
* hands its own store over as a `CookieJar` on `forwardOperatorRequest`,
|
|
7
|
+
* and the rows own the rest (parsing a `Set-Cookie` value into a
|
|
8
|
+
* `OriginCookie`, serializing the jar's cookies into a `Cookie` header) so
|
|
9
|
+
* no host repeats the logic.
|
|
10
|
+
*
|
|
11
|
+
* A jar is best-effort by contract: `get` resolves (a failed read is an
|
|
12
|
+
* empty jar), `set` swallows refusals (an unstored pair degrades to an
|
|
13
|
+
* unauthenticated dial, never a failed response) — a host that wants more
|
|
14
|
+
* noise logs inside its own adapter.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A cookie as a cookie store holds it — the store's grain, not the wire's.
|
|
19
|
+
* The field set is deliberately the intersection every real store speaks
|
|
20
|
+
* (Chromium's session jar, a browser's native jar): name, value, and the
|
|
21
|
+
* scope attributes. Absent attributes read as the store's defaults.
|
|
22
|
+
*/
|
|
23
|
+
export interface OriginCookie {
|
|
24
|
+
name: string;
|
|
25
|
+
value: string;
|
|
26
|
+
path?: string;
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
httpOnly?: boolean;
|
|
29
|
+
sameSite?: "unspecified" | "no_restriction" | "lax" | "strict";
|
|
30
|
+
/** Epoch seconds; absent reads as a session cookie. */
|
|
31
|
+
expirationDate?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A cookie store, addressed by URL: `get` answers the cookies the store
|
|
36
|
+
* holds for `url`'s origin (what a browser would attach as `Cookie`);
|
|
37
|
+
* `set` stores `cookie` for `url`'s origin, keyed by name (a re-set of a
|
|
38
|
+
* held name replaces it, like a real jar).
|
|
39
|
+
*/
|
|
40
|
+
export interface CookieJar {
|
|
41
|
+
get(url: string): Promise<OriginCookie[]>;
|
|
42
|
+
set(url: string, cookie: OriginCookie): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parse one raw `Set-Cookie` value into a jar-ready `OriginCookie` — the
|
|
47
|
+
* name/value pair plus the attributes a store keeps. A value with no
|
|
48
|
+
* parseable pair (empty name, no `=`) parses as null. `Max-Age` wins over
|
|
49
|
+
* `Expires` when both ride (the RFC 6265 precedence).
|
|
50
|
+
*/
|
|
51
|
+
export function parseSetCookie(raw: string): OriginCookie | null {
|
|
52
|
+
const [pair, ...attrs] = raw.split(";");
|
|
53
|
+
const eq = pair.indexOf("=");
|
|
54
|
+
if (eq <= 0) return null;
|
|
55
|
+
const name = pair.slice(0, eq).trim();
|
|
56
|
+
const value = pair.slice(eq + 1).trim();
|
|
57
|
+
if (!name) return null;
|
|
58
|
+
const cookie: OriginCookie = { name, value };
|
|
59
|
+
let maxAge: number | undefined;
|
|
60
|
+
for (const attr of attrs) {
|
|
61
|
+
const sep = attr.indexOf("=");
|
|
62
|
+
const attrName = (sep === -1 ? attr : attr.slice(0, sep))
|
|
63
|
+
.trim()
|
|
64
|
+
.toLowerCase();
|
|
65
|
+
const attrValue = sep === -1 ? "" : attr.slice(sep + 1).trim();
|
|
66
|
+
if (attrName === "path") {
|
|
67
|
+
cookie.path = attrValue || undefined;
|
|
68
|
+
} else if (attrName === "secure") {
|
|
69
|
+
cookie.secure = true;
|
|
70
|
+
} else if (attrName === "httponly") {
|
|
71
|
+
cookie.httpOnly = true;
|
|
72
|
+
} else if (attrName === "samesite") {
|
|
73
|
+
const site = attrValue.toLowerCase();
|
|
74
|
+
cookie.sameSite =
|
|
75
|
+
site === "strict"
|
|
76
|
+
? "strict"
|
|
77
|
+
: site === "lax"
|
|
78
|
+
? "lax"
|
|
79
|
+
: site === "none"
|
|
80
|
+
? "no_restriction"
|
|
81
|
+
: "unspecified";
|
|
82
|
+
} else if (attrName === "max-age") {
|
|
83
|
+
const parsed = Number(attrValue);
|
|
84
|
+
if (Number.isFinite(parsed)) maxAge = parsed;
|
|
85
|
+
} else if (attrName === "expires" && cookie.expirationDate === undefined) {
|
|
86
|
+
const parsed = Date.parse(attrValue);
|
|
87
|
+
if (Number.isFinite(parsed)) cookie.expirationDate = parsed / 1000;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (maxAge !== undefined) {
|
|
91
|
+
cookie.expirationDate = Math.floor(Date.now() / 1000) + maxAge;
|
|
92
|
+
}
|
|
93
|
+
return cookie;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Serialize the jar's cookies into the `Cookie` header a browser would
|
|
98
|
+
* attach — `name=value` pairs joined with `; `.
|
|
99
|
+
*/
|
|
100
|
+
export function cookieHeader(cookies: OriginCookie[]): string {
|
|
101
|
+
return cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
|
|
102
|
+
}
|
|
@@ -28,7 +28,8 @@ import { runResolveRoute } from "./resolve";
|
|
|
28
28
|
import { sleepAssistant } from "./sleep";
|
|
29
29
|
import { wakeAssistant } from "./wake";
|
|
30
30
|
import { z } from "zod";
|
|
31
|
-
import { getGatewayUrl } from "../lockfile-contract";
|
|
31
|
+
import { getGatewayUrl, type LockfileAssistant } from "../lockfile-contract";
|
|
32
|
+
import { cookieHeader, parseSetCookie, type CookieJar } from "./cookie-jar";
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* The operator ROUTE TABLE: the host-served operations — the headless
|
|
@@ -90,6 +91,18 @@ export interface OperatorRequest {
|
|
|
90
91
|
* down. Absent (direct `run` calls in tests) reads as no signal.
|
|
91
92
|
*/
|
|
92
93
|
signal?: AbortSignal | null;
|
|
94
|
+
/**
|
|
95
|
+
* The host's cookie jar, the custody seam for the cookie-carrying rows:
|
|
96
|
+
* the hatch row stores the pair it mints for the entry's gateway origin,
|
|
97
|
+
* and the proxy row attaches the jar's cookies on its dial (when the
|
|
98
|
+
* caller brings none) and re-stores every rotation the gateway sends
|
|
99
|
+
* back. The desktop's renderer can hold no cookies for `app://` (the
|
|
100
|
+
* cookie store refuses non-`http(s)` schemes), so its host supplies the
|
|
101
|
+
* session jar; hosts without one (the CLI edge, the dev server — whose
|
|
102
|
+
* browser callers jar natively) leave it unset and nothing is stored or
|
|
103
|
+
* attached.
|
|
104
|
+
*/
|
|
105
|
+
cookieJar?: CookieJar;
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
export interface OperatorRoute {
|
|
@@ -197,11 +210,20 @@ const json = (
|
|
|
197
210
|
body: unknown,
|
|
198
211
|
status = 200,
|
|
199
212
|
headers: Record<string, string | string[]> = {},
|
|
200
|
-
): Response =>
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
213
|
+
): Response => {
|
|
214
|
+
// Array values append per element — the Headers record constructor
|
|
215
|
+
// comma-joins them, which corrupts `Set-Cookie` (cookies carry commas
|
|
216
|
+
// in their Expires attributes, and the pair would ride as one value).
|
|
217
|
+
const out = new Headers({ "content-type": "application/json" });
|
|
218
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
219
|
+
if (Array.isArray(value)) {
|
|
220
|
+
for (const item of value) out.append(name, item);
|
|
221
|
+
} else {
|
|
222
|
+
out.append(name, value);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return new Response(JSON.stringify(body), { status, headers: out });
|
|
226
|
+
};
|
|
205
227
|
|
|
206
228
|
/**
|
|
207
229
|
* Buffer and parse a JSON request body. An empty body resolves to `{}` (the
|
|
@@ -293,13 +315,23 @@ async function runHatchRoute(request: OperatorRequest): Promise<Response> {
|
|
|
293
315
|
try {
|
|
294
316
|
const result = await hatchAssistant({ remote });
|
|
295
317
|
if (result.ok) {
|
|
296
|
-
// The leg's own lease minted the webview's credential pair
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
318
|
+
// The leg's own lease minted the webview's credential pair. A host
|
|
319
|
+
// with a jar stores it for the entry's gateway origin — the origin
|
|
320
|
+
// the proxy row dials, and the only origin a cookie store accepts
|
|
321
|
+
// (Chromium refuses `app://`). Hosts without one skip it; either
|
|
322
|
+
// way the pair still rides the response as Set-Cookie headers for
|
|
323
|
+
// the native-browser flow (the CLI edge, the dev server) and for
|
|
324
|
+
// QA visibility.
|
|
325
|
+
const jarOrigin = gatewayOriginFor(result.assistant);
|
|
326
|
+
if (request.cookieJar && jarOrigin) {
|
|
327
|
+
for (const raw of result.cookies) {
|
|
328
|
+
const cookie = parseSetCookie(raw);
|
|
329
|
+
if (cookie) await request.cookieJar.set(jarOrigin, cookie);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return json({ ok: true, assistantId: result.assistant.assistantId }, 200, {
|
|
333
|
+
"Set-Cookie": result.cookies,
|
|
334
|
+
});
|
|
303
335
|
}
|
|
304
336
|
return json({ ok: false, error: result.error }, result.status);
|
|
305
337
|
} catch (err) {
|
|
@@ -307,6 +339,15 @@ async function runHatchRoute(request: OperatorRequest): Promise<Response> {
|
|
|
307
339
|
}
|
|
308
340
|
}
|
|
309
341
|
|
|
342
|
+
/** The origin the entry's gateway serves on, or null when unresolvable. */
|
|
343
|
+
function gatewayOriginFor(entry: LockfileAssistant): string | null {
|
|
344
|
+
try {
|
|
345
|
+
return new URL(getGatewayUrl(entry)).origin;
|
|
346
|
+
} catch {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
310
351
|
/**
|
|
311
352
|
* Forget a paired assistant (the `paired` flag): remove its lockfile entry
|
|
312
353
|
* and delete its stored guardian token on this machine. Client-side only:
|
|
@@ -606,11 +647,20 @@ async function runProxyRoute(
|
|
|
606
647
|
}
|
|
607
648
|
const method = request.method ?? "GET";
|
|
608
649
|
const target = new URL(request.path ?? "/", getGatewayUrl(entry));
|
|
650
|
+
const gatewayOrigin = target.origin;
|
|
609
651
|
const hasBody = method !== "GET" && method !== "HEAD";
|
|
610
652
|
const headers = normalizeForwardHeaders(
|
|
611
653
|
request.headers,
|
|
612
654
|
request.peer ?? null,
|
|
613
655
|
);
|
|
656
|
+
// The caller's own Cookie wins (the CLI's browser jar holds the live
|
|
657
|
+
// pair); the host's jar fills the absence — the desktop's renderer can
|
|
658
|
+
// hold no cookies for `app://`, so its jar IS the browser-equivalent
|
|
659
|
+
// store.
|
|
660
|
+
if (!headers.has("cookie") && request.cookieJar) {
|
|
661
|
+
const jarCookies = await request.cookieJar.get(gatewayOrigin);
|
|
662
|
+
if (jarCookies.length > 0) headers.set("cookie", cookieHeader(jarCookies));
|
|
663
|
+
}
|
|
614
664
|
if (process.env.ASSISTANT_PROXY_TRANSPORT === "ipc") {
|
|
615
665
|
headers.set("x-cadet-proxy-server", "ipc");
|
|
616
666
|
}
|
|
@@ -627,6 +677,16 @@ async function runProxyRoute(
|
|
|
627
677
|
if (lower === "content-length" || lower === "content-encoding") return;
|
|
628
678
|
outHeaders.append(key, value);
|
|
629
679
|
});
|
|
680
|
+
// A rotation response re-stores the fresh pair for the gateway origin
|
|
681
|
+
// via the host's jar, so the next dial attaches it. Hosts without the
|
|
682
|
+
// jar skip it; their browser callers jar the forwarded Set-Cookie
|
|
683
|
+
// headers natively.
|
|
684
|
+
if (request.cookieJar) {
|
|
685
|
+
for (const raw of upstream.headers.getSetCookie()) {
|
|
686
|
+
const cookie = parseSetCookie(raw);
|
|
687
|
+
if (cookie) await request.cookieJar.set(gatewayOrigin, cookie);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
630
690
|
return new Response(upstream.body, {
|
|
631
691
|
status: upstream.status,
|
|
632
692
|
headers: outHeaders,
|
|
@@ -835,7 +895,10 @@ export function matchOperatorRequest(
|
|
|
835
895
|
*/
|
|
836
896
|
export async function forwardOperatorRequest(
|
|
837
897
|
request: Request,
|
|
838
|
-
options?: {
|
|
898
|
+
options?: {
|
|
899
|
+
peer?: string | null;
|
|
900
|
+
cookieJar?: CookieJar;
|
|
901
|
+
},
|
|
839
902
|
): Promise<Response | null> {
|
|
840
903
|
const match = matchOperatorRequest(
|
|
841
904
|
new URL(request.url).pathname,
|
|
@@ -853,5 +916,6 @@ export async function forwardOperatorRequest(
|
|
|
853
916
|
body: request.body,
|
|
854
917
|
signal: request.signal,
|
|
855
918
|
...(options?.peer !== undefined ? { peer: options.peer } : {}),
|
|
919
|
+
...(options?.cookieJar ? { cookieJar: options.cookieJar } : {}),
|
|
856
920
|
});
|
|
857
921
|
}
|
|
@@ -63,7 +63,6 @@ describe("servedConfigFromLockfile", () => {
|
|
|
63
63
|
expect(servedConfigFromLockfile(lockfile)).toEqual({
|
|
64
64
|
assistantId: "active",
|
|
65
65
|
assistantName: "Example Assistant",
|
|
66
|
-
remote: "docker",
|
|
67
66
|
});
|
|
68
67
|
// The entry carries no bearer at all — the token lives in its xdg
|
|
69
68
|
// file, never in the lockfile the renderer boundary reads.
|
|
@@ -117,7 +116,6 @@ describe("servedConfigFromLockfile", () => {
|
|
|
117
116
|
activeAssistant: "paired",
|
|
118
117
|
});
|
|
119
118
|
expect(config.assistantId).toBe("paired");
|
|
120
|
-
expect(config.remote).toBe("local");
|
|
121
119
|
// The stamp carries public identity only - no address, no secrets.
|
|
122
120
|
expect(JSON.stringify(config)).not.toContain("example-host-token");
|
|
123
121
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
|
|
5
|
+
import { importsFirst } from "./imports-first.mjs";
|
|
6
|
+
import { noEmptyImports } from "./no-empty-imports.mjs";
|
|
7
|
+
import { noReExports } from "./no-re-exports.mjs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The `@mycadet` plugin, wired once. Every shared custom rule registers
|
|
11
|
+
* here; a service opts in by naming the rule (`@mycadet/imports-first`)
|
|
12
|
+
* rather than re-assembling the plugin — flat config would overwrite a
|
|
13
|
+
* same-named plugin definition wholesale, so one shared object identity
|
|
14
|
+
* is what keeps adoption declarative.
|
|
15
|
+
*/
|
|
16
|
+
export const mycadetPlugin = {
|
|
17
|
+
rules: {
|
|
18
|
+
"imports-first": importsFirst,
|
|
19
|
+
"no-empty-imports": noEmptyImports,
|
|
20
|
+
"no-re-exports": noReExports,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The repo's lint floor: the rules every service already enforces,
|
|
26
|
+
* declared once. Spread it first and add only what's yours — later
|
|
27
|
+
* config items win.
|
|
28
|
+
*
|
|
29
|
+
* Re-export shims are outlawed everywhere: consumers import from the
|
|
30
|
+
* defining module, and only index files aggregate a public surface.
|
|
31
|
+
* Warning-level countdowns (cast bans, mock.module, namespace imports)
|
|
32
|
+
* stay per-service — their pins are local.
|
|
33
|
+
*
|
|
34
|
+
* @param {{ ignores?: string[] }} [options]
|
|
35
|
+
* Extra global ignores for service build output (e.g. `drizzle/**`).
|
|
36
|
+
* `dist/**` is always ignored.
|
|
37
|
+
*/
|
|
38
|
+
export function baseEslintConfig(options = {}) {
|
|
39
|
+
const { ignores = [] } = options;
|
|
40
|
+
return defineConfig([
|
|
41
|
+
...tseslint.configs.recommended,
|
|
42
|
+
globalIgnores(["dist/**", ...ignores]),
|
|
43
|
+
{
|
|
44
|
+
plugins: { "@mycadet": mycadetPlugin },
|
|
45
|
+
rules: {
|
|
46
|
+
// Unused symbols are noise the compiler can't see (params kept
|
|
47
|
+
// for signature shape, type-only imports); an underscore-prefixed
|
|
48
|
+
// name declares the intent to keep.
|
|
49
|
+
"@typescript-eslint/no-unused-vars": [
|
|
50
|
+
"error",
|
|
51
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
|
|
52
|
+
],
|
|
53
|
+
"@mycadet/no-re-exports": "error",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/shared",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202611181327.a51316f",
|
|
4
4
|
"private": true,
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts",
|
|
7
7
|
"./eslint/imports-first": "./eslint/imports-first.mjs",
|
|
8
|
+
"./eslint/base": "./eslint/base.mjs",
|
|
8
9
|
"./eslint/no-empty-imports": "./eslint/no-empty-imports.mjs",
|
|
9
10
|
"./eslint/no-re-exports": "./eslint/no-re-exports.mjs",
|
|
10
11
|
"./fetch": "./fetch.ts",
|
package/package.json
CHANGED
|
@@ -10,13 +10,18 @@ import {
|
|
|
10
10
|
import * as childProcess from "node:child_process";
|
|
11
11
|
import {
|
|
12
12
|
mkdirSync,
|
|
13
|
+
mkdtempSync,
|
|
13
14
|
readFileSync,
|
|
14
15
|
rmSync,
|
|
15
16
|
writeFileSync,
|
|
16
17
|
} from "node:fs";
|
|
17
18
|
import { join } from "node:path";
|
|
19
|
+
import { tmpdir } from "node:os";
|
|
18
20
|
import { PassThrough } from "node:stream";
|
|
19
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
findSourcePackageDir,
|
|
23
|
+
resolveClientDists,
|
|
24
|
+
} from "../lib/web-dist.js";
|
|
20
25
|
|
|
21
26
|
const realChildProcess = { ...childProcess };
|
|
22
27
|
const spawnMock = mock(childProcess.spawn);
|
|
@@ -240,3 +245,51 @@ describe("resolveClientDists", () => {
|
|
|
240
245
|
expect(() => distStamp(webDistDir())).toThrow();
|
|
241
246
|
});
|
|
242
247
|
});
|
|
248
|
+
|
|
249
|
+
describe("findSourcePackageDir", () => {
|
|
250
|
+
// The installed-package arm: `@mycadet/<kind>` lands at
|
|
251
|
+
// `node_modules/@mycadet/<kind>` — an ancestor's `<kind>/package.json`.
|
|
252
|
+
// Its published manifest strips scripts, so it must never read as the
|
|
253
|
+
// checkout arm (the dev-release "Script not found 'build'" startup
|
|
254
|
+
// failure was exactly this misclassification).
|
|
255
|
+
test("classifies an installed @mycadet package as the non-checkout arm", () => {
|
|
256
|
+
const root = mkdtempSync(join(tmpdir(), "web-dist-arm-"));
|
|
257
|
+
const appPackage = join(root, "node_modules", "@mycadet", "app");
|
|
258
|
+
mkdirSync(join(appPackage, "dist", "standalone"), { recursive: true });
|
|
259
|
+
writeFileSync(
|
|
260
|
+
join(appPackage, "package.json"),
|
|
261
|
+
JSON.stringify({ name: "@mycadet/app", version: "0.0.0" }),
|
|
262
|
+
);
|
|
263
|
+
writeFileSync(join(appPackage, "dist", "standalone", "index.html"), "<html></html>");
|
|
264
|
+
try {
|
|
265
|
+
const found = findSourcePackageDir(
|
|
266
|
+
"app",
|
|
267
|
+
join(root, "node_modules", "@mycadet", "cli", "src", "lib"),
|
|
268
|
+
);
|
|
269
|
+
expect(found?.dir).toBe(appPackage);
|
|
270
|
+
expect(found?.isCheckout).toBe(false);
|
|
271
|
+
} finally {
|
|
272
|
+
rmSync(root, { recursive: true, force: true });
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("classifies the repo checkout as the checkout arm", () => {
|
|
277
|
+
const root = mkdtempSync(join(tmpdir(), "web-dist-arm-"));
|
|
278
|
+
const appPackage = join(root, "clients", "app");
|
|
279
|
+
mkdirSync(appPackage, { recursive: true });
|
|
280
|
+
writeFileSync(
|
|
281
|
+
join(appPackage, "package.json"),
|
|
282
|
+
JSON.stringify({ name: "@mycadet/app", scripts: { build: "true" } }),
|
|
283
|
+
);
|
|
284
|
+
try {
|
|
285
|
+
const found = findSourcePackageDir(
|
|
286
|
+
"app",
|
|
287
|
+
join(root, "cli", "src", "lib"),
|
|
288
|
+
);
|
|
289
|
+
expect(found?.dir).toBe(appPackage);
|
|
290
|
+
expect(found?.isCheckout).toBe(true);
|
|
291
|
+
} finally {
|
|
292
|
+
rmSync(root, { recursive: true, force: true });
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
package/src/lib/web-dist.ts
CHANGED
|
@@ -98,17 +98,35 @@ export interface DistBuildOptions {
|
|
|
98
98
|
resolvePackage?: () => string;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* A located `clients/<kind>`-style package, and whether it is the checkout
|
|
103
|
+
* arm (a real `clients/<kind>` source package that owns a build script) or
|
|
104
|
+
* the installed-package arm (an npm-installed `@mycadet/<kind>` dist
|
|
105
|
+
* carrier, whose published manifest strips scripts).
|
|
106
|
+
*/
|
|
107
|
+
interface SourcePackage {
|
|
108
|
+
dir: string;
|
|
109
|
+
isCheckout: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
/** Locate the `clients/<kind>` package of the checkout this CLI runs from. */
|
|
102
|
-
function findSourcePackageDir(
|
|
103
|
-
|
|
113
|
+
export function findSourcePackageDir(
|
|
114
|
+
kind: "web" | "app",
|
|
115
|
+
startDir: string = import.meta.dir,
|
|
116
|
+
): SourcePackage | null {
|
|
117
|
+
let dir = startDir;
|
|
104
118
|
for (let depth = 0; depth < 8; depth++) {
|
|
105
119
|
const packageJson = join(dir, "clients", kind, "package.json");
|
|
106
120
|
if (existsSync(packageJson)) {
|
|
107
|
-
return dirname(packageJson);
|
|
121
|
+
return { dir: dirname(packageJson), isCheckout: true };
|
|
108
122
|
}
|
|
109
123
|
const npmPackageJson = join(dir, kind, "package.json");
|
|
110
124
|
if (existsSync(npmPackageJson)) {
|
|
111
|
-
|
|
125
|
+
// The `@mycadet/<kind>` package installs at
|
|
126
|
+
// `node_modules/@mycadet/<kind>` — exactly this arm. Its dist is
|
|
127
|
+
// owned by its release (the published manifest ships no scripts),
|
|
128
|
+
// so it is never a rebuild target.
|
|
129
|
+
return { dir: dirname(npmPackageJson), isCheckout: false };
|
|
112
130
|
}
|
|
113
131
|
const parent = dirname(dir);
|
|
114
132
|
if (parent === dir) {
|
|
@@ -202,9 +220,13 @@ interface DistArm {
|
|
|
202
220
|
|
|
203
221
|
async function resolveDistArm(kind: "web" | "app"): Promise<DistArm> {
|
|
204
222
|
const existing = kind === "web" ? findWebDistDir() : findAppDistDir();
|
|
205
|
-
const
|
|
223
|
+
const source = findSourcePackageDir(kind);
|
|
224
|
+
// Only the checkout arm can be source-built: an installed package's dist
|
|
225
|
+
// is its release's artifact (and its manifest has no build script), so it
|
|
226
|
+
// always serves as-is — a dev release never rebuilds.
|
|
227
|
+
const sourceDir = source?.dir ?? null;
|
|
206
228
|
const sourceBuilt =
|
|
207
|
-
|
|
229
|
+
source?.isCheckout === true && existing === sourceDistDir(kind, source.dir);
|
|
208
230
|
|
|
209
231
|
// An installed/packaged dist is owned by its release — served as-is, even
|
|
210
232
|
// when the release ships no source tree (an npm install has no
|