@mycadet/cli 0.13.0-dev.202611162029.012a930 → 0.13.0-dev.202611171101.13836af

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -353,7 +353,7 @@ export function guardianTokenDueForRenewal(token: GuardianTokenData): boolean {
353
353
  * host-scoped, so a remote gateway's origin (baseten's preview URL) can
354
354
  * never see this jar.
355
355
  */
356
- export function webviewCookieFeed(token: GuardianTokenData): string[] {
356
+ export function getGuardianTokenAsCookies(token: GuardianTokenData): string[] {
357
357
  return [
358
358
  `cadet_web_access=${encodeURIComponent(token.accessToken)}; HttpOnly; Path=/; SameSite=Strict`,
359
359
  `cadet_web_refresh=${encodeURIComponent(token.refreshToken)}; HttpOnly; Path=/; SameSite=Strict`,
@@ -232,13 +232,6 @@ export async function hatchBaseten(
232
232
  log(
233
233
  ` Exec into it: baseten sandbox exec --name ${sandboxName} -- 'cadet ps'`,
234
234
  );
235
- // cookies stay empty on purpose: a Set-Cookie on the hatch response
236
- // lands in the hatch host's jar, and a cookie is host-scoped — the
237
- // baseten gateway answers on its preview origin, which this jar can
238
- // never reach. The browser earns its baseten cookie with one
239
- // authenticated open on the preview edge instead. The local and
240
- // docker legs feed the jar because their gateways answer on the same
241
- // loopback host as the hatch response.
242
235
  return { ok: true, assistant: entry, ready: false, cookies: [] };
243
236
  }
244
237
  log(
@@ -27,7 +27,7 @@ import {
27
27
  } from "../../ports";
28
28
  import {
29
29
  leaseGuardianToken,
30
- webviewCookieFeed,
30
+ getGuardianTokenAsCookies,
31
31
  type GuardianTokenData,
32
32
  } from "../../guardian-token";
33
33
  import type { HatchAssistantResult } from "../../operations/types";
@@ -967,7 +967,7 @@ export async function hatchDocker(
967
967
  // The lease's fresh pair IS the webview's jar, same as the local leg:
968
968
  // the docker gateway answers on the same host as this response
969
969
  // (loopback port map), so the host-scoped jar applies.
970
- cookies: guardianToken ? webviewCookieFeed(guardianToken) : [],
970
+ cookies: guardianToken ? getGuardianTokenAsCookies(guardianToken) : [],
971
971
  };
972
972
  } catch (error) {
973
973
  return {
@@ -21,7 +21,7 @@ import { findAvailablePort, getDefaultPorts } from "../../ports";
21
21
  import {
22
22
  GuardianLeasePermanentError,
23
23
  leaseGuardianToken,
24
- webviewCookieFeed,
24
+ getGuardianTokenAsCookies,
25
25
  } from "../../guardian-token";
26
26
  import { configureHatchProviderApiKey } from "../../provider-credentials";
27
27
  import { readCloudToken } from "../../cloud-auth";
@@ -195,7 +195,7 @@ export async function hatchLocal(params: {
195
195
  // hatch response so the page's requests authenticate through the
196
196
  // gateway's own middleware. Same host as this response (loopback), so
197
197
  // the host-scoped jar applies.
198
- cookies.push(...webviewCookieFeed(tokenData));
198
+ cookies.push(...getGuardianTokenAsCookies(tokenData));
199
199
  break;
200
200
  } catch (err) {
201
201
  if (
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
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.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202611162029.012a930",
3
+ "version": "0.13.0-dev.202611171101.13836af",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Tests for `cadet client --token <jwt> --url <gateway>`: an ephemeral session
3
- * that authenticates with a handed-over token and needs no lockfile entry.
2
+ * Tests for `cadet client`'s arg parsing: the assistant comes from the
3
+ * positional name or the active assistant — there is no --url/--token escape
4
+ * hatch. What remains overridable is the assistant id segment.
4
5
  */
5
6
  import {
6
7
  afterAll,
@@ -17,24 +18,28 @@ import { join } from "node:path";
17
18
  // NB: do NOT mock.module("../lib/guardian-token.js") here — that mock is
18
19
  // process-global in Bun and leaks into other test files (it dropped the
19
20
  // module's other exports and broke guardian-token-paths / setup suites in CI).
20
- // The "--token skips the credential lookup" behavior is enforced structurally
21
- // in parseArgs (the lookup is gated on the override) and reviewed there.
22
21
 
23
- // An EMPTY temp dir so there is no lockfile entry — the ephemeral path must
24
- // work without one. Env mutation is scoped to each test and restored after, so
25
- // it can't leak into other test files in the same Bun run.
26
22
  const testDir = mkdtempSync(join(tmpdir(), "client-token-test-"));
27
23
  const ORIGINAL_XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
28
24
  const ORIGINAL_ARGV = [...process.argv];
29
25
 
30
26
  import { parseArgs } from "../commands/client.js";
27
+ import { saveLockfileAssistant } from "@mycadet/local-mode";
31
28
 
32
- // A clearly non-local URL so maybeSwapToLocalhost won't rewrite it to 127.0.0.1.
33
- const REMOTE_URL = "http://192.0.2.50:7830";
29
+ // A clearly non-local recorded host so getGatewayUrl yields a remote URL
30
+ // and the test pins that the runtime URL comes from the ENTRY, not flags.
31
+ const ENTRY = {
32
+ assistantId: "remote-xyz",
33
+ name: "Remote Pal",
34
+ cloud: "custom" as const,
35
+ ipAddress: "192.0.2.50",
36
+ port: 7830,
37
+ };
34
38
 
35
- describe("client --token (ephemeral)", () => {
39
+ describe("client arg parsing", () => {
36
40
  beforeEach(() => {
37
41
  process.env.XDG_CONFIG_HOME = testDir;
42
+ saveLockfileAssistant(ENTRY);
38
43
  });
39
44
 
40
45
  afterEach(() => {
@@ -50,38 +55,29 @@ describe("client --token (ephemeral)", () => {
50
55
  rmSync(testDir, { recursive: true, force: true });
51
56
  });
52
57
 
53
- test("--url + --token resolves to a bearer session with no lockfile entry", () => {
54
- process.argv = [
55
- "bun",
56
- "cadet",
57
- "client",
58
- "--url",
59
- REMOTE_URL,
60
- "--token",
61
- "test-jwt-token",
62
- ];
58
+ test("the runtime URL and bearer come from the entry's persisted state", () => {
59
+ process.argv = ["bun", "cadet", "client", "Remote Pal"];
63
60
  const parsed = parseArgs();
64
61
 
65
- expect(parsed.runtimeUrl).toBe(REMOTE_URL);
66
- expect(parsed.assistantId).toBe("self"); // DAEMON_INTERNAL_ASSISTANT_ID
67
- expect(parsed.bearerToken).toBe("test-jwt-token");
62
+ expect(parsed.runtimeUrl).toBe("https://192.0.2.50:7830");
63
+ expect(parsed.assistantId).toBe("remote-xyz");
64
+ expect(parsed.assistantName).toBe("Remote Pal");
65
+ // No stored guardian token was seeded, so no bearer is invented.
66
+ expect(parsed.bearerToken).toBeUndefined();
68
67
  expect(parsed.cloudToken).toBeUndefined();
69
68
  });
70
69
 
71
- test("--assistant-id overrides the default 'self' segment", () => {
70
+ test("--assistant-id overrides the entry's id segment", () => {
72
71
  process.argv = [
73
72
  "bun",
74
73
  "cadet",
75
74
  "client",
76
- "--url",
77
- REMOTE_URL,
78
- "--token",
79
- "tok",
75
+ "Remote Pal",
80
76
  "--assistant-id",
81
- "remote-xyz",
77
+ "remote-abc",
82
78
  ];
83
79
  const parsed = parseArgs();
84
- expect(parsed.assistantId).toBe("remote-xyz");
85
- expect(parsed.bearerToken).toBe("tok");
80
+ expect(parsed.assistantId).toBe("remote-abc");
81
+ expect(parsed.assistantName).toBeUndefined();
86
82
  });
87
83
  });
@@ -1,7 +1,6 @@
1
1
  import { type LockfileAssistant } from "@mycadet/local-mode/contract";
2
2
  import {
3
3
  findAssistantByName,
4
- resolveAssistant,
5
4
  resolveConversationKey,
6
5
  } from "../lib/assistant-config";
7
6
  import {
@@ -15,7 +14,6 @@ import {
15
14
  readCloudToken,
16
15
  saveLockfileAssistant,
17
16
  } from "@mycadet/local-mode";
18
- import { DAEMON_INTERNAL_ASSISTANT_ID, GATEWAY_PORT } from "../lib/constants";
19
17
 
20
18
  import { normalizeRuntimeUrl } from "../lib/runtime-url";
21
19
  import { getGatewayUrl } from "@mycadet/local-mode/contract";
@@ -50,12 +48,8 @@ export function parseArgs(): ParsedArgs {
50
48
  const args = process.argv.slice(3);
51
49
 
52
50
  const positionalName = parseAssistantTargetArg(args, [
53
- "--url",
54
- "-u",
55
51
  "--assistant-id",
56
52
  "-a",
57
- "--token",
58
- "-t",
59
53
  ]);
60
54
  const flagArgs: string[] = [];
61
55
  for (let i = 0; i < args.length; i++) {
@@ -63,21 +57,12 @@ export function parseArgs(): ParsedArgs {
63
57
  if (arg === "--help" || arg === "-h") {
64
58
  printUsage();
65
59
  process.exit(0);
66
- } else if (
67
- (arg === "--url" ||
68
- arg === "-u" ||
69
- arg === "--assistant-id" ||
70
- arg === "-a" ||
71
- arg === "--token" ||
72
- arg === "-t") &&
73
- args[i + 1]
74
- ) {
60
+ } else if ((arg === "--assistant-id" || arg === "-a") && args[i + 1]) {
75
61
  flagArgs.push(arg, args[++i]);
76
62
  }
77
63
  }
78
64
 
79
65
  let entry: LockfileAssistant | null = null;
80
- const hasExplicitUrl = flagArgs.includes("--url") || flagArgs.includes("-u");
81
66
  if (positionalName) {
82
67
  const result = lookupAssistantByIdentifier(positionalName);
83
68
  if (result.status !== "found") {
@@ -92,76 +77,44 @@ export function parseArgs(): ParsedArgs {
92
77
  if (result.status === "found") {
93
78
  entry = result.entry;
94
79
  }
95
- if (!entry && !hasExplicitUrl) {
80
+ if (!entry) {
96
81
  console.error(
97
82
  `Active assistant '${active}' not found in lockfile. Set an active assistant with 'cadet use <name-or-id>'.`,
98
83
  );
99
84
  process.exit(1);
100
85
  }
101
86
  }
102
- if (!entry && hasExplicitUrl) {
103
- // URL provided but active assistant missing or unset — resolve for remaining defaults
104
- entry = resolveAssistant();
105
- } else if (!entry) {
87
+ if (!entry) {
106
88
  console.error(
107
89
  "No active assistant set. Set one with 'cadet use <name-or-id>' or specify one: 'cadet client <name-or-id>'.",
108
90
  );
109
91
  process.exit(1);
110
92
  }
111
93
  }
112
-
113
- if (!entry && !hasExplicitUrl) {
94
+ if (!entry) {
114
95
  console.error("No assistant found. Hatch one first with 'cadet hatch'.");
115
96
  process.exit(1);
116
97
  }
117
98
 
118
- // An explicit --url with no lockfile entry is the ephemeral session (the
119
- // handed-over --token authenticates it) — the overrides below supply the
120
- // url and the "self" assistant id, so no entry is required.
121
- let runtimeUrl = entry
122
- ? getGatewayUrl(entry)
123
- : `http://127.0.0.1:${GATEWAY_PORT}`;
124
- let assistantId = entry?.assistantId ?? DAEMON_INTERNAL_ASSISTANT_ID;
125
- let assistantName = entry ? getAssistantDisplayName(entry) : undefined;
126
- const cloud = entry?.cloud;
127
-
128
- // Ephemeral auth: a handed-over token (e.g. from `cadet pair`) used for this
129
- // session only. Resolve it BEFORE the credential lookup below so an ephemeral
130
- // session never reads (or writes) the local token store.
131
- let bearerTokenOverride: string | undefined;
132
- for (let i = 0; i < flagArgs.length; i++) {
133
- if (
134
- (flagArgs[i] === "--token" || flagArgs[i] === "-t") &&
135
- flagArgs[i + 1]
136
- ) {
137
- bearerTokenOverride = flagArgs[i + 1];
138
- }
139
- }
99
+ const runtimeUrl = getGatewayUrl(entry);
100
+ let assistantId = entry.assistantId;
101
+ let assistantName: string | undefined = getAssistantDisplayName(entry);
102
+ const cloud = entry.cloud;
140
103
 
141
104
  // Platform-hosted assistants (cloud "cadet") use a session token; every
142
- // other topology — local, docker, and "paired" (a remote assistant paired
143
- // from another machine) — uses a bearer guardian JWT. Both are skipped
144
- // entirely when --token supplies the credential, so no saved creds are read.
145
- const cloudToken = bearerTokenOverride
146
- ? undefined
147
- : cloud === "cloud"
148
- ? (readCloudToken() ?? undefined)
149
- : undefined;
150
- const bearerToken = bearerTokenOverride
151
- ? bearerTokenOverride
152
- : cloud === "cloud"
105
+ // other topology — local, docker, and "paired" — uses a bearer guardian JWT.
106
+ const cloudToken =
107
+ cloud === "cloud" ? (readCloudToken() ?? undefined) : undefined;
108
+ const bearerToken =
109
+ cloud === "cloud"
153
110
  ? undefined
154
- : (loadGuardianToken(entry?.assistantId ?? "")?.accessToken ?? undefined);
111
+ : (loadGuardianToken(entry.assistantId)?.accessToken ?? undefined);
155
112
 
156
113
  for (let i = 0; i < flagArgs.length; i++) {
157
114
  const flag = flagArgs[i];
158
- if ((flag === "--url" || flag === "-u") && flagArgs[i + 1]) {
159
- runtimeUrl = flagArgs[++i];
160
- } else if (
161
- (flag === "--assistant-id" || flag === "-a") &&
162
- flagArgs[i + 1]
163
- ) {
164
- assistantId = flagArgs[++i];
115
+ const value = flagArgs[i + 1];
116
+ if ((flag === "--assistant-id" || flag === "-a") && value) {
117
+ assistantId = value;
165
118
  assistantName = undefined;
166
119
  }
167
120
  }
@@ -186,24 +139,12 @@ ${ANSI.bold}ARGUMENTS:${ANSI.reset}
186
139
  [name-or-id] Assistant display name or ID (default: active)
187
140
 
188
141
  ${ANSI.bold}OPTIONS:${ANSI.reset}
189
- -u, --url <url> Runtime URL
190
- -t, --token <jwt> Bearer token to use for this session (e.g. from
191
- 'cadet pair'). Overrides the stored token and is
192
- not persisted.
193
142
  -a, --assistant-id <id> Assistant ID
194
143
  -h, --help Show this help message
195
144
 
196
145
  ${ANSI.bold}EXAMPLES:${ANSI.reset}
197
146
  cadet client
198
147
  cadet client mycadet-foo
199
- # Remote assistants must be reached over https (e.g. a tunnel) — the
200
- # guardian refresh token is only sent over https or a loopback address:
201
- cadet client --url https://your-tunnel.example
202
- cadet client mycadet-foo --url http://localhost:${GATEWAY_PORT}
203
-
204
- # Ephemeral: connect to another machine's assistant with a paired token
205
- # (no lockfile entry, nothing persisted):
206
- cadet client --url https://your-tunnel.example --token <jwt>
207
148
 
208
149
  `);
209
150
  }
@@ -280,16 +221,7 @@ export const client = Object.assign(
280
221
  ...getClientRegistrationHeaders(CLI_INTERFACE_ID),
281
222
  };
282
223
  } else {
283
- // Proactively renew a stale STORED guardian token before opening the
284
- // TUI, so launching after the access token expired renews transparently
285
- // rather than erroring. The one door: a fresh stored lease comes back
286
- // unchanged, a due one re-invokes the pair flow, and a failed re-pair
287
- // still hands back the stored token when it has life left. A
288
- // caller-supplied `--token` survives (the pair flow talks only to the
289
- // lockfile's persisted entry, and a null door result falls back to it).
290
- // (Mid-session expiry — the token dying while the TUI is already open —
291
- // is a separate follow-up, since the TUI threads a static auth object
292
- // through React.)
224
+ // Renew a stale stored lease through the one door before the TUI opens.
293
225
  const fresh = await loadFreshGuardianToken(assistantId);
294
226
  const token = fresh?.accessToken ?? bearerToken;
295
227
  auth = {
@@ -1,10 +1,7 @@
1
1
  import { resolveAssistant } from "../lib/assistant-config.js";
2
2
  import { getGatewayUrl } from "@mycadet/local-mode/contract";
3
3
  import { cliCommand, loadFreshGuardianToken } from "@mycadet/local-mode";
4
- import {
5
- ensureProviderApiKey,
6
- formatProviderName,
7
- } from "@mycadet/local-mode";
4
+ import { ensureProviderApiKey, formatProviderName } from "@mycadet/local-mode";
8
5
  import { yellow } from "../lib/color.js";
9
6
 
10
7
  function parseSetupArgs(args: string[]): { provider?: string } {
@@ -126,9 +123,6 @@ export const setup = Object.assign(
126
123
  }
127
124
 
128
125
  const gatewayUrl = getGatewayUrl(entry);
129
- // The one door: a fresh stored lease comes back unchanged; a due one
130
- // re-invokes the pair flow and persists the fresh pair; a failed re-pair
131
- // still hands back the stored token when it has life left.
132
126
  const freshToken = await loadFreshGuardianToken(entry.assistantId);
133
127
  const bearerToken = freshToken?.accessToken;
134
128