@mycadet/cli 0.13.0-dev.202611152042.1bf2622 → 0.13.0-dev.202611162029.012a930

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 (48) hide show
  1. package/eslint.config.mjs +15 -0
  2. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
  3. package/node_modules/@mycadet/assistant-api/responses/activation.ts +0 -6
  4. package/node_modules/@mycadet/assistant-api/responses/conversation-message.ts +0 -5
  5. package/node_modules/@mycadet/assistant-api/surface-show-result.ts +0 -6
  6. package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  7. package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  8. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  9. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  10. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
  11. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
  12. package/node_modules/@mycadet/local-mode/package.json +1 -1
  13. package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token.test.ts +0 -43
  14. package/node_modules/@mycadet/local-mode/src/__tests__/operations-hatch.test.ts +17 -13
  15. package/node_modules/@mycadet/local-mode/src/__tests__/operations-pair.test.ts +114 -1
  16. package/node_modules/@mycadet/local-mode/src/__tests__/operations-resolution.test.ts +9 -0
  17. package/node_modules/@mycadet/local-mode/src/__tests__/operations-routes.test.ts +29 -0
  18. package/node_modules/@mycadet/local-mode/src/guardian-token.ts +103 -144
  19. package/node_modules/@mycadet/local-mode/src/index.ts +3 -1
  20. package/node_modules/@mycadet/local-mode/src/operations/hatch.ts +5 -35
  21. package/node_modules/@mycadet/local-mode/src/operations/resolve.ts +3 -2
  22. package/node_modules/@mycadet/local-mode/src/operations/routes.ts +22 -3
  23. package/node_modules/@mycadet/local-mode/src/operations/types.ts +25 -0
  24. package/node_modules/@mycadet/local-mode/src/remotes/baseten/hatch.ts +25 -9
  25. package/node_modules/@mycadet/local-mode/src/remotes/cloud/hatch.ts +9 -6
  26. package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +30 -29
  27. package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +10 -6
  28. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  29. package/node_modules/@mycadet/shared/package.json +1 -1
  30. package/package.json +2 -2
  31. package/src/__tests__/assistant-client-refresh.test.ts +93 -112
  32. package/src/__tests__/cloud-client.test.ts +73 -82
  33. package/src/__tests__/guardian-token.test.ts +5 -456
  34. package/src/__tests__/provider-secrets.test.ts +35 -23
  35. package/src/__tests__/servers/bun.test.ts +111 -14
  36. package/src/__tests__/setup.test.ts +19 -57
  37. package/src/__tests__/tui-midsession-refresh.test.ts +20 -13
  38. package/src/commands/client.ts +15 -59
  39. package/src/commands/setup.ts +7 -51
  40. package/src/components/DefaultMainScreen.tsx +13 -35
  41. package/src/lib/assistant-client.ts +10 -17
  42. package/src/lib/cloud-client.ts +29 -173
  43. package/src/lib/live-voice/connection.ts +6 -24
  44. package/src/lib/runtime-url.ts +0 -28
  45. package/src/lib/tunnels/ngrok.ts +2 -2
  46. package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token-refresh.test.ts +0 -142
  47. package/src/__tests__/client-tui-refresh.test.ts +0 -218
  48. package/src/lib/guardian-token.ts +0 -346
package/eslint.config.mjs CHANGED
@@ -27,6 +27,21 @@ const eslintConfig = defineConfig([
27
27
  plugins: { "@mycadet": { rules: { "no-re-exports": noReExports } } },
28
28
  rules: { "@mycadet/no-re-exports": "error" },
29
29
  },
30
+ {
31
+ rules: {
32
+ "no-restricted-syntax": [
33
+ "warn",
34
+ {
35
+ selector: "ImportDeclaration > ImportNamespaceSpecifier",
36
+ message: "Namespace imports hide the used surface.",
37
+ },
38
+ ],
39
+ },
40
+ },
41
+ {
42
+ files: ["**/__tests__/**/*.ts", "**/*.test.ts"],
43
+ rules: { "no-restricted-syntax": "off" },
44
+ },
30
45
  ]);
31
46
 
32
47
  export default eslintConfig;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -105,9 +105,6 @@ export const ActivationTaskStartRequestSchema = z.object({
105
105
  "List the task came from, stored only while no list is frozen",
106
106
  ),
107
107
  });
108
- export type ActivationTaskStartRequest = z.infer<
109
- typeof ActivationTaskStartRequestSchema
110
- >;
111
108
 
112
109
  export const ActivationDismissKindSchema = z
113
110
  .enum(["modal", "all-done"])
@@ -120,9 +117,6 @@ export const ActivationDismissRequestSchema = z.object({
120
117
  "List the surface showed, stored only while no list is frozen",
121
118
  ),
122
119
  });
123
- export type ActivationDismissRequest = z.infer<
124
- typeof ActivationDismissRequestSchema
125
- >;
126
120
 
127
121
  /** Empty progress, returned before the store file exists. */
128
122
  export function emptyActivationProgress(): ActivationProgress {
@@ -130,7 +130,6 @@ export const PendingToolQuestionSchema = z.object({
130
130
  requestId: z.string(),
131
131
  entries: z.array(QuestionEntrySchema),
132
132
  });
133
- export type PendingToolQuestion = z.infer<typeof PendingToolQuestionSchema>;
134
133
 
135
134
  /**
136
135
  * Closed set of confirmation outcomes recorded for a tool call. The daemon
@@ -143,7 +142,6 @@ export const ConfirmationDecisionSchema = z.enum([
143
142
  "denied",
144
143
  "timed_out",
145
144
  ]);
146
- export type ConfirmationDecision = z.infer<typeof ConfirmationDecisionSchema>;
147
145
 
148
146
  /**
149
147
  * A single tool call rendered into a history row. Mirrors the object the
@@ -328,9 +326,6 @@ const ConversationAcpNotificationSchema = z.object({
328
326
  acpSessionId: z.string(),
329
327
  agent: z.string().optional(),
330
328
  });
331
- export type ConversationAcpNotification = z.infer<
332
- typeof ConversationAcpNotificationSchema
333
- >;
334
329
 
335
330
  // ---------------------------------------------------------------------------
336
331
  // Background-tool completion
@@ -11,12 +11,6 @@
11
11
  * so guidance can only ever be added in a way the parser still understands.
12
12
  */
13
13
 
14
- /** Fields a `ui_show` result envelope may carry beyond the surface id. */
15
- export interface SurfaceShowResult {
16
- surfaceId: string;
17
- [key: string]: unknown;
18
- }
19
-
20
14
  /**
21
15
  * Read the `surfaceId` out of a `ui_show` tool result, or `undefined` when the
22
16
  * content is not a surface envelope.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/shared",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/local-mode",
3
- "version": "0.13.0-dev.202611152042.1bf2622",
3
+ "version": "0.13.0-dev.202611162029.012a930",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -7,8 +7,6 @@ import { configureCliPaths } from "../cli-invocation";
7
7
 
8
8
  import {
9
9
  getGuardianAccessToken,
10
- formatGuardianRefreshCliFailure,
11
- parseGuardianRefreshCliFailure,
12
10
  isConfidentialRefreshUrl,
13
11
  saveBasetenSandboxToken,
14
12
  saveGuardianToken,
@@ -111,47 +109,6 @@ describe("getGuardianAccessToken", () => {
111
109
  });
112
110
  });
113
111
 
114
- describe("parseGuardianRefreshCliFailure", () => {
115
- test("reads a labeled 401 from stderr", () => {
116
- expect(
117
- parseGuardianRefreshCliFailure(
118
- "",
119
- `Failed to refresh guardian token.\n${formatGuardianRefreshCliFailure(401, "Failed to refresh guardian token")}\n`,
120
- ),
121
- ).toEqual({
122
- ok: false,
123
- status: 401,
124
- error: "Failed to refresh guardian token",
125
- });
126
- });
127
-
128
- test("reads a labeled 503 from stderr", () => {
129
- expect(
130
- parseGuardianRefreshCliFailure(
131
- "",
132
- formatGuardianRefreshCliFailure(
133
- 503,
134
- "Assistant gateway is unreachable",
135
- ),
136
- ),
137
- ).toEqual({
138
- ok: false,
139
- status: 503,
140
- error: "Assistant gateway is unreachable",
141
- });
142
- });
143
-
144
- test("an unlabeled non-zero CLI exit is a 503, not a 401", () => {
145
- expect(
146
- parseGuardianRefreshCliFailure("", "Failed to refresh guardian token."),
147
- ).toEqual({
148
- ok: false,
149
- status: 503,
150
- error: "Failed to refresh guardian token",
151
- });
152
- });
153
- });
154
-
155
112
  describe("isConfidentialRefreshUrl", () => {
156
113
  test.each([
157
114
  ["https://gw.example.com", "https reaches it encrypted"],
@@ -1,17 +1,19 @@
1
- import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test";
1
+ import {
2
+ afterAll,
3
+ afterEach,
4
+ beforeEach,
5
+ describe,
6
+ expect,
7
+ test,
8
+ } from "bun:test";
2
9
  import { mkdtempSync, rmSync } from "node:fs";
3
10
  import os from "node:os";
4
11
  import path from "node:path";
5
12
 
6
13
  import { mock } from "bun:test";
7
- import {
8
- type HatchDockerParams,
9
- type HatchDockerResult,
10
- } from "../remotes/docker/hatch";
11
- import {
12
- type HatchBasetenParams,
13
- type HatchBasetenResult,
14
- } from "../remotes/baseten/hatch";
14
+ import { type HatchDockerParams } from "../remotes/docker/hatch";
15
+ import { type HatchBasetenParams } from "../remotes/baseten/hatch";
16
+ import { type HatchAssistantResult } from "../operations/types";
15
17
  import { hatchAssistant } from "../operations/hatch";
16
18
  import { existsSync } from "node:fs";
17
19
  import { resolveLockfilePath } from "../config";
@@ -19,16 +21,17 @@ import { readLockfile, saveLockfileAssistant } from "../lockfile";
19
21
  import { findAssistantByName } from "../operations/lookup";
20
22
 
21
23
  const hatchDockerMock = mock<
22
- (params: HatchDockerParams) => Promise<HatchDockerResult>
24
+ (params: HatchDockerParams) => Promise<HatchAssistantResult>
23
25
  >(async () => ({
24
26
  ok: true,
25
- entry: {
27
+ assistant: {
26
28
  assistantId: "leg-entry",
27
29
  cloud: "docker",
28
30
  port: 7830,
29
31
  daemonPort: 7821,
30
32
  },
31
33
  ready: true,
34
+ cookies: [],
32
35
  }));
33
36
  const realDockerHatch = { ...(await import("../remotes/docker/hatch")) };
34
37
  const realBasetenHatch = { ...(await import("../remotes/baseten/hatch")) };
@@ -39,10 +42,10 @@ mock.module("../remotes/docker/hatch", () => ({
39
42
  }));
40
43
 
41
44
  const basetenMock = mock<
42
- (params: HatchBasetenParams) => Promise<HatchBasetenResult>
45
+ (params: HatchBasetenParams) => Promise<HatchAssistantResult>
43
46
  >(async () => ({
44
47
  ok: true,
45
- entry: {
48
+ assistant: {
46
49
  assistantId: "baseten-entry",
47
50
  name: "sandbox-entry",
48
51
  cloud: "baseten",
@@ -50,6 +53,7 @@ const basetenMock = mock<
50
53
  port: 7830,
51
54
  },
52
55
  ready: false,
56
+ cookies: [],
53
57
  }));
54
58
  mock.module("../remotes/baseten/hatch", () => ({
55
59
  ...realBasetenHatch,
@@ -7,8 +7,17 @@ import {
7
7
  mock,
8
8
  test,
9
9
  } from "bun:test";
10
+ import fs from "node:fs";
11
+ import os from "node:os";
12
+ import path from "node:path";
10
13
  import type { LocalAssistant, LockfileAssistant } from "../lockfile-contract";
11
- import type { GuardianTokenData } from "../guardian-token";
14
+ import {
15
+ getGuardianAccessToken,
16
+ loadFreshGuardianToken,
17
+ saveGuardianToken,
18
+ type GuardianTokenData,
19
+ } from "../guardian-token";
20
+ import { saveLockfileAssistant } from "../lockfile";
12
21
  import type {
13
22
  PairDeviceIdentity,
14
23
  PairOperationResult,
@@ -164,3 +173,107 @@ describe("pairDevice — the credential door routes by remote", () => {
164
173
  );
165
174
  });
166
175
  });
176
+
177
+ /**
178
+ * The ONE renewal door: a due or expired stored lease re-invokes the pair
179
+ * flow (the transport mocks above answer in the transports' stead), a fresh
180
+ * lease comes back untouched, and a failed re-pair degrades to the stored
181
+ * token. Co-located with the transport mocks so the shared-loader's
182
+ * module-mock lifetime can't hijack the lease seam mid-run.
183
+ */
184
+ describe("loadFreshGuardianToken — the one renewal door", () => {
185
+ let home: string;
186
+
187
+ beforeEach(() => {
188
+ home = fs.mkdtempSync(path.join(os.tmpdir(), "guardian-door-test-"));
189
+ process.env.XDG_CONFIG_HOME = home;
190
+ });
191
+
192
+ afterEach(() => {
193
+ Reflect.deleteProperty(process.env, "XDG_CONFIG_HOME");
194
+ fs.rmSync(home, { recursive: true, force: true });
195
+ });
196
+
197
+ const FUTURE = new Date(Date.now() + 60 * 60 * 1000).toISOString();
198
+ const PAST = new Date(Date.now() - 60_000).toISOString();
199
+
200
+ const storedToken = (
201
+ over: Partial<GuardianTokenData>,
202
+ ): GuardianTokenData => ({
203
+ guardianPrincipalId: "principal-stored",
204
+ accessToken: "stored-access",
205
+ accessTokenExpiresAt: FUTURE,
206
+ refreshToken: "stored-refresh",
207
+ refreshTokenExpiresAt: FUTURE,
208
+ refreshAfter: FUTURE,
209
+ deviceId: "device-stored",
210
+ leasedAt: new Date().toISOString(),
211
+ ...over,
212
+ });
213
+
214
+ const freshPair = {
215
+ ok: true as const,
216
+ response: {
217
+ guardianPrincipalId: "principal-fresh",
218
+ accessToken: "fresh-access",
219
+ accessTokenExpiresAt: FUTURE,
220
+ refreshToken: "fresh-refresh",
221
+ refreshTokenExpiresAt: FUTURE,
222
+ refreshAfter: FUTURE,
223
+ deviceId: "device-fresh",
224
+ leasedAt: new Date().toISOString(),
225
+ },
226
+ };
227
+
228
+ function seedEntry(): void {
229
+ saveLockfileAssistant({
230
+ assistantId: "asst-door",
231
+ cloud: "local",
232
+ instanceDir: path.join(home, "instance"),
233
+ port: 7830,
234
+ daemonPort: 7821,
235
+ cesPort: 7822,
236
+ } as unknown as LocalAssistant);
237
+ }
238
+
239
+ test("the holder refreshes a due token by re-pairing, not by calling a refresh API", async () => {
240
+ seedEntry();
241
+ saveGuardianToken(
242
+ "asst-door",
243
+ storedToken({ accessTokenExpiresAt: PAST, refreshAfter: PAST }),
244
+ );
245
+ pairLocalMock.mockResolvedValue(freshPair);
246
+
247
+ const result = await getGuardianAccessToken("asst-door");
248
+
249
+ expect(pairLocalMock).toHaveBeenCalledTimes(1);
250
+ expect(result).toEqual({ ok: true, accessToken: "fresh-access" });
251
+ });
252
+
253
+ test("a failed re-pair degrades to the stored token", async () => {
254
+ seedEntry();
255
+ saveGuardianToken(
256
+ "asst-door",
257
+ storedToken({ accessTokenExpiresAt: PAST, refreshAfter: PAST }),
258
+ );
259
+ pairLocalMock.mockResolvedValue({
260
+ ok: false,
261
+ status: 503,
262
+ error: "gateway unreachable",
263
+ });
264
+
265
+ const degraded = await loadFreshGuardianToken("asst-door");
266
+
267
+ expect(degraded?.accessToken).toBe("stored-access");
268
+ });
269
+
270
+ test("a fresh stored lease never triggers a pair", async () => {
271
+ seedEntry();
272
+ saveGuardianToken("asst-door", storedToken({}));
273
+
274
+ const fresh = await loadFreshGuardianToken("asst-door");
275
+
276
+ expect(fresh?.accessToken).toBe("stored-access");
277
+ expect(pairLocalMock).not.toHaveBeenCalled();
278
+ });
279
+ });
@@ -176,6 +176,14 @@ describe("matchOperatorRequest — the four prefixes", () => {
176
176
  test("the derivation helpers give every row both versioned spellings", () => {
177
177
  for (const route of OPERATOR_ROUTES) {
178
178
  const derived = route.pattern.source;
179
+ if (derived.startsWith("^\\/webhooks")) {
180
+ // The channel-webhook row is PUBLIC ingress at the root — external
181
+ // services post fixed URLs (Telegram's registered callback), so no
182
+ // version arm or tail hygiene applies. Pinned exactly so no other
183
+ // row sneaks past the derivation unversioned.
184
+ expect(derived).toBe("^\\/webhooks(?:\\/.*)?$");
185
+ continue;
186
+ }
179
187
  if (derived.includes("(?<id>")) {
180
188
  // An assistant row: helper 2's id capture plus helper 1's required
181
189
  // version arm. Rows declare relative patterns, so the scoping arm
@@ -285,6 +293,7 @@ describe("runResolveRoute — the lockfile arms", () => {
285
293
 
286
294
  const response = await runResolution();
287
295
 
296
+ expect(response.status).toBe(409);
288
297
  expect(await resolutionBody(response)).toEqual({ status: "notReady" });
289
298
  });
290
299
 
@@ -643,3 +643,32 @@ describe("the route table's method scoping", () => {
643
643
  expect(match?.assistantId).toBe("");
644
644
  });
645
645
  });
646
+
647
+ describe("the webhook row — /webhooks/* bridges to the fronted gateway", () => {
648
+ test("matches the subtree at the root in every method, unscoped to the active entry", () => {
649
+ const entry = seedEntry({
650
+ assistantId: "assistant-1",
651
+ name: "Homelab",
652
+ cloud: "local",
653
+ port: 7830,
654
+ });
655
+ for (const path of [
656
+ "/webhooks",
657
+ "/webhooks/telegram",
658
+ "/webhooks/twilio/voice",
659
+ "/webhooks/oauth/callback",
660
+ ]) {
661
+ for (const method of ["GET", "POST", "DELETE"]) {
662
+ const match = matchOperatorRequest(path, method);
663
+ expect(match?.assistantId).toBe(entry.assistantId);
664
+ }
665
+ }
666
+ });
667
+
668
+ test("near-miss roots match no row", () => {
669
+ seedEntry({ assistantId: "assistant-1", cloud: "local", port: 7830 });
670
+ expect(matchOperatorRequest("/webhooks/telegram", "POST")).not.toBeNull();
671
+ expect(matchOperatorRequest("/hooks/telegram", "POST")).toBeNull();
672
+ expect(matchOperatorRequest("/webhookss/telegram", "POST")).toBeNull();
673
+ });
674
+ });