@mycadet/cli 0.13.0-dev.202610200020.9f20440 → 0.13.0-dev.202610201855.522ff0d

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 (80) hide show
  1. package/node_modules/@mycadet/assistant-api/constants/personality-sliders.test.ts +0 -8
  2. package/node_modules/@mycadet/assistant-api/constants/personality-sliders.ts +5 -41
  3. package/node_modules/@mycadet/assistant-api/events/message-complete.ts +0 -5
  4. package/node_modules/@mycadet/assistant-api/index.ts +0 -2
  5. package/node_modules/@mycadet/assistant-api/responses/conversation-message.ts +0 -10
  6. package/node_modules/@mycadet/environments/src/seeds.ts +6 -2
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +6 -2
  8. package/node_modules/@mycadet/local-mode/src/config.ts +0 -2
  9. package/node_modules/@mycadet/local-mode/src/index.ts +1 -1
  10. package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +1 -22
  11. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +26 -7
  12. package/node_modules/@mycadet/local-mode/src/util.ts +1 -20
  13. package/node_modules/@mycadet/shared/github-repository.ts +5 -0
  14. package/node_modules/@mycadet/shared/package.json +10 -0
  15. package/node_modules/@mycadet/shared/scripts/run-isolated-tests.ts +700 -0
  16. package/package.json +3 -2
  17. package/src/__tests__/app-command.test.ts +164 -0
  18. package/src/__tests__/client-web-config.test.ts +0 -1
  19. package/src/__tests__/cloud-releases.test.ts +1 -1
  20. package/src/__tests__/local-version.test.ts +16 -0
  21. package/src/__tests__/nginx-ingress.test.ts +248 -630
  22. package/src/__tests__/ps-cloud-status.test.ts +85 -11
  23. package/src/__tests__/root-process-lockfile.test.ts +29 -2
  24. package/src/__tests__/tunnel-holder-heal.test.ts +119 -0
  25. package/src/__tests__/tunnel-stop.test.ts +6 -13
  26. package/src/__tests__/tunnel.test.ts +50 -193
  27. package/src/__tests__/wake.test.ts +6 -38
  28. package/src/__tests__/web-dist.test.ts +267 -89
  29. package/src/commands/app.ts +113 -0
  30. package/src/commands/backup.ts +5 -4
  31. package/src/commands/clean.ts +2 -1
  32. package/src/commands/client.ts +5 -68
  33. package/src/commands/completions.ts +12 -1
  34. package/src/commands/connect.ts +2 -1
  35. package/src/commands/debug.ts +2 -1
  36. package/src/commands/exec.ts +7 -6
  37. package/src/commands/gateway/token.ts +2 -1
  38. package/src/commands/gateway.ts +2 -1
  39. package/src/commands/hatch.ts +74 -80
  40. package/src/commands/login.ts +7 -6
  41. package/src/commands/logs.ts +2 -1
  42. package/src/commands/ps.ts +136 -6
  43. package/src/commands/restart.ts +2 -1
  44. package/src/commands/restore.ts +10 -9
  45. package/src/commands/retire.ts +4 -3
  46. package/src/commands/setup.ts +5 -4
  47. package/src/commands/sleep.ts +3 -2
  48. package/src/commands/teleport.ts +2 -1
  49. package/src/commands/terminal.ts +7 -6
  50. package/src/commands/tunnel.ts +196 -242
  51. package/src/commands/uninstall.ts +2 -1
  52. package/src/commands/upgrade.ts +2 -1
  53. package/src/commands/use.ts +2 -1
  54. package/src/commands/wake.ts +3 -2
  55. package/src/index.ts +5 -4
  56. package/src/lib/__tests__/web-dist.test.ts +1 -27
  57. package/src/lib/assistant-config.ts +101 -37
  58. package/src/lib/cli-name.ts +14 -0
  59. package/src/lib/cloud-client.ts +2 -1
  60. package/src/lib/cloud-login-poll.ts +2 -1
  61. package/src/lib/cloud-releases.ts +1 -1
  62. package/src/lib/docker.ts +32 -21
  63. package/src/lib/hatch-local.ts +1 -3
  64. package/src/lib/hatch-next-steps.ts +1 -9
  65. package/src/lib/ingress-config.ts +0 -31
  66. package/src/lib/local-version.ts +25 -4
  67. package/src/lib/local.ts +34 -9
  68. package/src/lib/nginx-ingress.ts +143 -244
  69. package/src/lib/provider-secrets.ts +0 -5
  70. package/src/lib/statefulset.ts +0 -1
  71. package/src/lib/tunnel.ts +244 -43
  72. package/src/lib/tunnels/ngrok.ts +57 -9
  73. package/src/lib/tunnels/tailscale.ts +2 -1
  74. package/src/lib/web-dist.ts +134 -56
  75. package/src/__tests__/flags.test.ts +0 -318
  76. package/src/__tests__/shell-mode.test.ts +0 -83
  77. package/src/commands/flags.ts +0 -255
  78. package/src/lib/flag-args.test.ts +0 -84
  79. package/src/lib/flag-args.ts +0 -74
  80. package/src/lib/github-repository.ts +0 -2
@@ -44,16 +44,14 @@ const detectOrphanedProcessesMock = spyOn(
44
44
  orphanDetection,
45
45
  "detectOrphanedProcesses",
46
46
  ).mockResolvedValue([]);
47
- const getCloudUrlMock = spyOn(
48
- cloudClient,
49
- "getCloudUrl",
50
- ).mockReturnValue("http://platform.test");
47
+ const getCloudUrlMock = spyOn(cloudClient, "getCloudUrl").mockReturnValue(
48
+ "http://platform.test",
49
+ );
51
50
 
52
51
  // Per-test toggle for `readCloudToken`.
53
- const readCloudTokenMock = spyOn(
54
- cloudClient,
55
- "readCloudToken",
56
- ).mockReturnValue(null);
52
+ const readCloudTokenMock = spyOn(cloudClient, "readCloudToken").mockReturnValue(
53
+ null,
54
+ );
57
55
 
58
56
  // `fetchCurrentUser` + `fetchCloudAssistants` are spied so we can assert
59
57
  // they're never invoked on the no-token path, and re-shaped per-test for the
@@ -141,7 +139,7 @@ afterAll(() => {
141
139
  // Import the command under test AFTER mocks are wired up
142
140
  // ---------------------------------------------------------------------------
143
141
 
144
- import { listAllAssistants } from "../commands/ps.js";
142
+ import { listAllAssistants, ps } from "../commands/ps.js";
145
143
 
146
144
  // ---------------------------------------------------------------------------
147
145
  // Tests
@@ -252,7 +250,7 @@ describe("cadet ps — platform status line", () => {
252
250
  startedAt: "2026-10-11T00:00:00.000Z",
253
251
  assistantId: "assistant-123",
254
252
  },
255
- app: { pid: 77, startedAt: "2026-10-11T00:00:00.000Z" },
253
+ app: { pid: 77, port: 7841, startedAt: "2026-10-11T00:00:00.000Z" },
256
254
  });
257
255
 
258
256
  await listAllAssistants(false);
@@ -263,7 +261,8 @@ describe("cadet ps — platform status line", () => {
263
261
  expect(output).toContain("ngrok");
264
262
  expect(output).not.toContain("└ ngrok");
265
263
  expect(output).toContain("nginx");
266
- expect(output).toContain("port ");
264
+ // The edge's INFO leads with its listen URL (not a bare port).
265
+ expect(output).toContain("http://127.0.0.1:7841");
267
266
  // …the type column distinguishes the three process kinds…
268
267
  expect(output).toContain("🤖 Assistant");
269
268
  expect(output).toContain("🚇 Tunnel");
@@ -324,3 +323,78 @@ describe("cadet ps — platform status line", () => {
324
323
  expect(output).toContain("sleeping");
325
324
  });
326
325
  });
326
+
327
+ describe("cadet ps <built-in process name> details", () => {
328
+ const originalArgv = process.argv;
329
+ afterEach(() => {
330
+ process.argv = originalArgv;
331
+ readRootProcessesMock.mockReturnValue({});
332
+ });
333
+
334
+ test("`ps nginx` details the app edge with its listen URL", async () => {
335
+ readRootProcessesMock.mockReturnValue({
336
+ app: {
337
+ pid: 77,
338
+ port: 7841,
339
+ startedAt: "2026-10-20T15:00:00.000Z",
340
+ },
341
+ });
342
+ process.argv = ["bun", "cadet", "ps", "nginx"];
343
+
344
+ await ps();
345
+
346
+ const output = stdout.join(NL);
347
+ expect(output).toContain("App edge (nginx):");
348
+ expect(output).toContain("http://127.0.0.1:7841");
349
+ });
350
+
351
+ test("`ps nginx` with no record points at `cadet app start`", async () => {
352
+ readRootProcessesMock.mockReturnValue({});
353
+ process.argv = ["bun", "cadet", "ps", "nginx"];
354
+
355
+ await ps();
356
+
357
+ expect(stdout.join(NL)).toContain("not recorded");
358
+ });
359
+
360
+ test("`ps ngrok` details the tunnel agent with its public URL", async () => {
361
+ readRootProcessesMock.mockReturnValue({
362
+ tunnel: {
363
+ pid: 4242,
364
+ provider: "ngrok",
365
+ startedAt: "2026-10-20T15:00:00.000Z",
366
+ publicUrl: "https://camping.ngrok-free.dev",
367
+ },
368
+ });
369
+ process.argv = ["bun", "cadet", "ps", "ngrok"];
370
+
371
+ await ps();
372
+
373
+ const output = stdout.join(NL);
374
+ expect(output).toContain("Tunnel agent (ngrok):");
375
+ expect(output).toContain("https://camping.ngrok-free.dev");
376
+ });
377
+
378
+ test("an assistant name still resolves the assistant", async () => {
379
+ loadAllAssistantsMock.mockReturnValue([
380
+ {
381
+ assistantId: "assistant-123",
382
+ name: "nginx",
383
+ runtimeUrl: "https://platform.example",
384
+ cloud: "cloud",
385
+ },
386
+ ]);
387
+ checkManagedHealthMock.mockImplementation(async () => ({
388
+ status: "healthy",
389
+ detail: null,
390
+ }));
391
+ process.argv = ["bun", "cadet", "ps", "assistant-123"];
392
+
393
+ await ps();
394
+
395
+ // A built-in name only wins when asked for by name; an assistant ID
396
+ // resolves the assistant's process table as before.
397
+ const output = stdout.join(NL);
398
+ expect(output).toContain("Processes for");
399
+ });
400
+ });
@@ -5,8 +5,11 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
5
5
  import { z } from "zod";
6
6
 
7
7
  import {
8
+ clearAppProcessRecord,
8
9
  clearRootProcess,
10
+ readAppBuiltSha,
9
11
  readRootProcesses,
12
+ stampAppBuiltSha,
10
13
  stampRootProcess,
11
14
  } from "../lib/assistant-config.js";
12
15
 
@@ -43,7 +46,11 @@ describe("root process lockfile entries", () => {
43
46
  });
44
47
 
45
48
  test("tunnel and app entries stamp and clear independently", () => {
46
- stampRootProcess("app", { pid: 77, startedAt: "2026-10-11T00:00:00.000Z" });
49
+ stampRootProcess("app", {
50
+ pid: 77,
51
+ port: 7841,
52
+ startedAt: "2026-10-11T00:00:00.000Z",
53
+ });
47
54
  stampRootProcess("tunnel", {
48
55
  pid: 78,
49
56
  provider: "cloudflare",
@@ -75,7 +82,7 @@ describe("root process lockfile entries", () => {
75
82
  });
76
83
 
77
84
  test("the records live at the lockfile root under their kind keys", () => {
78
- stampRootProcess("app", { pid: 1, startedAt: "t" });
85
+ stampRootProcess("app", { pid: 1, port: 7841, startedAt: "t" });
79
86
 
80
87
  const raw = z
81
88
  .object({
@@ -97,3 +104,23 @@ describe("root process lockfile entries", () => {
97
104
  expect(readRootProcesses()).toEqual({});
98
105
  });
99
106
  });
107
+
108
+ describe("the app entry's built-sha stamp", () => {
109
+ test("a stamp can land before any edge process exists (stamp-only entry)", () => {
110
+ stampAppBuiltSha("a".repeat(40));
111
+ expect(readAppBuiltSha()).toBe("a".repeat(40));
112
+ // Stamp-only entry: no process bookkeeping to report.
113
+ expect(readRootProcesses().app?.pid).toBeUndefined();
114
+ });
115
+
116
+ test("clearing the edge's process entry keeps its built-sha stamp", () => {
117
+ stampRootProcess("app", { pid: 5, port: 7841, startedAt: "t" });
118
+ stampAppBuiltSha("b".repeat(40));
119
+ expect(readAppBuiltSha()).toBe("b".repeat(40));
120
+
121
+ clearAppProcessRecord();
122
+ // The pid bookkeeping goes; the build-cache stamp stays.
123
+ expect(readRootProcesses().app?.pid).toBeUndefined();
124
+ expect(readAppBuiltSha()).toBe("b".repeat(40));
125
+ });
126
+ });
@@ -0,0 +1,119 @@
1
+ import { afterEach, describe, expect, mock, test } from "bun:test";
2
+
3
+ // The heal runs where the user's terminal is — the foreground `cadet tunnel`
4
+ // command — so its stdin gate and its line reader are process boundaries the
5
+ // tests pin here, and the holder discovery/stop calls are the ngrok module's
6
+ // own (mocked to their recorded calls).
7
+ const realEnsureBinary = await import("../lib/ensure-binary.js");
8
+ const realNgrok = await import("../lib/tunnels/ngrok.js");
9
+
10
+ const promptLog: string[] = [];
11
+ let readAnswer = "n";
12
+ let holderPid: number | null = null;
13
+ const stoppedPids: number[] = [];
14
+ let stopResult = true;
15
+
16
+ mock.module("../lib/ensure-binary.js", () => ({
17
+ ...realEnsureBinary,
18
+ readLineText: (prompt: string): Promise<string> => {
19
+ promptLog.push(prompt);
20
+ return Promise.resolve(readAnswer);
21
+ },
22
+ }));
23
+
24
+ mock.module("../lib/tunnels/ngrok.js", () => ({
25
+ ...realNgrok,
26
+ ngrokHolderPid: (): Promise<number | null> => Promise.resolve(holderPid),
27
+ stopNgrokHolderPid: (pid: number): Promise<boolean> => {
28
+ stoppedPids.push(pid);
29
+ return Promise.resolve(stopResult);
30
+ },
31
+ }));
32
+
33
+ const { offerStopNgrokHolder } = await import("../lib/tunnel.js");
34
+
35
+ const ONLINE_LOG = [
36
+ "Starting ngrok tunnel to localhost:7841...",
37
+ 't=2026-10-19T15:20:19-0400 lvl=eror msg="session closing" obj=tunnels.session err="failed to start tunnel: The endpoint \'https://camping-trustful-fog.ngrok-free.dev\' is already online. Either\\n1. stop your existing endpoint first, or\\n2. start both endpoints with `--pooling-enabled` to load balance between them.\\r\\n\\r\\nERR_NGROK_334\\r\\n"',
38
+ ].join("\n");
39
+
40
+ const OTHER_FAILURE_LOG = [
41
+ "Starting ngrok tunnel to localhost:7841...",
42
+ "creating tunnel session failed: dial tcp 3.219.x.x:443: connection refused",
43
+ ].join("\n");
44
+
45
+ let stdinWasTty = false;
46
+ function withTty(tty: boolean): void {
47
+ stdinWasTty = "isTTY" in process.stdin && process.stdin.isTTY;
48
+ Object.defineProperty(process.stdin, "isTTY", {
49
+ value: tty,
50
+ configurable: true,
51
+ });
52
+ }
53
+
54
+ afterEach(() => {
55
+ Object.defineProperty(process.stdin, "isTTY", {
56
+ value: stdinWasTty,
57
+ configurable: true,
58
+ });
59
+ promptLog.length = 0;
60
+ readAnswer = "n";
61
+ holderPid = null;
62
+ stoppedPids.length = 0;
63
+ stopResult = true;
64
+ });
65
+
66
+ describe("offerStopNgrokHolder — the foreground confirm-first heal", () => {
67
+ test("a log without the endpoint collision never prompts", async () => {
68
+ withTty(true);
69
+ holderPid = 4242;
70
+ expect(await offerStopNgrokHolder(OTHER_FAILURE_LOG)).toBe(false);
71
+ expect(promptLog).toEqual([]);
72
+ expect(stoppedPids).toEqual([]);
73
+ });
74
+
75
+ test("a detached (non-TTY) stdin never prompts", async () => {
76
+ withTty(false);
77
+ holderPid = 4242;
78
+ expect(await offerStopNgrokHolder(ONLINE_LOG)).toBe(false);
79
+ expect(promptLog).toEqual([]);
80
+ expect(stoppedPids).toEqual([]);
81
+ });
82
+
83
+ test("an unidentified holder is never prompted about", async () => {
84
+ withTty(true);
85
+ holderPid = null;
86
+ expect(await offerStopNgrokHolder(ONLINE_LOG)).toBe(false);
87
+ expect(promptLog).toEqual([]);
88
+ expect(stoppedPids).toEqual([]);
89
+ });
90
+
91
+ test("a confirmed stop stops the holder and asks for a relaunch", async () => {
92
+ withTty(true);
93
+ holderPid = 4242;
94
+ readAnswer = "y";
95
+ expect(await offerStopNgrokHolder(ONLINE_LOG)).toBe(true);
96
+ expect(promptLog).toEqual([
97
+ "Stop the other ngrok tunnel and start a new one pointing at this installation? [Y/n] ",
98
+ ]);
99
+ expect(stoppedPids).toEqual([4242]);
100
+ });
101
+
102
+ test("a declined stop keeps the holder and stays failed", async () => {
103
+ withTty(true);
104
+ holderPid = 4242;
105
+ readAnswer = "n";
106
+ expect(await offerStopNgrokHolder(ONLINE_LOG)).toBe(false);
107
+ expect(promptLog).toHaveLength(1);
108
+ expect(stoppedPids).toEqual([]);
109
+ });
110
+
111
+ test("a failed stop stays failed", async () => {
112
+ withTty(true);
113
+ holderPid = 4242;
114
+ readAnswer = "y";
115
+ stopResult = false;
116
+ expect(await offerStopNgrokHolder(ONLINE_LOG)).toBe(false);
117
+ expect(stoppedPids).toEqual([4242]);
118
+ });
119
+ });
@@ -72,14 +72,18 @@ beforeEach(() => {
72
72
  assistantId: "fixture",
73
73
  startedAt: new Date().toISOString(),
74
74
  });
75
- stampRootProcess("app", { pid: 424243, startedAt: new Date().toISOString() });
75
+ stampRootProcess("app", {
76
+ pid: 424243,
77
+ port: 7841,
78
+ startedAt: new Date().toISOString(),
79
+ });
76
80
  ngrok.saveNgrokDomain("old.ngrok.app");
77
81
  stop = spyOn(processes, "stopProcess").mockResolvedValue(true);
78
82
  identity = spyOn(processes, "readProcessCommandLine").mockReturnValue(
79
83
  "ngrok http 7840",
80
84
  );
81
85
  logs = spyOn(console, "log").mockImplementation(() => {});
82
- process.argv = ["bun", "cadet", "tunnel", "stop", "fixture"];
86
+ process.argv = ["bun", "cadet", "tunnel", "stop"];
83
87
  });
84
88
  afterEach(() => {
85
89
  stop.mockRestore();
@@ -113,17 +117,6 @@ test("a recycled PID is not signaled and its stale record is cleared", async ()
113
117
  expect(stop).not.toHaveBeenCalled();
114
118
  expect(readRootProcesses().tunnel).toBeUndefined();
115
119
  });
116
- test("another assistant's tunnel is left intact", async () => {
117
- stampRootProcess("tunnel", {
118
- pid: 424242,
119
- provider: "ngrok",
120
- assistantId: "another",
121
- startedAt: new Date().toISOString(),
122
- });
123
- await expect(tunnel()).rejects.toThrow("belongs to 'another'");
124
- expect(stop).not.toHaveBeenCalled();
125
- expect(readRootProcesses().tunnel?.assistantId).toBe("another");
126
- });
127
120
  test("failure to stop retains process and ingress state", async () => {
128
121
  stop.mockResolvedValue(false);
129
122
  await expect(tunnel()).rejects.toThrow("Could not stop ngrok");