@mycadet/cli 0.13.0-dev.202610221914.02130b1 → 0.13.0-dev.202610231403.3079a3f

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 (27) hide show
  1. package/node_modules/@mycadet/assistant-api/events/conversation-error.ts +1 -1
  2. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  3. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +6 -6
  4. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  5. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +6 -6
  6. package/node_modules/@mycadet/local-mode/src/__tests__/pair.test.ts +2 -1
  7. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -4
  8. package/node_modules/@mycadet/local-mode/src/pair.ts +3 -5
  9. package/node_modules/@mycadet/service-contracts/src/cloud-credential.ts +5 -5
  10. package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +6 -6
  11. package/package.json +1 -1
  12. package/src/__tests__/ingress-config.test.ts +0 -14
  13. package/src/__tests__/ngrok-spawn.test.ts +0 -86
  14. package/src/__tests__/pair.test.ts +17 -340
  15. package/src/__tests__/wake.test.ts +9 -5
  16. package/src/commands/app.ts +1 -1
  17. package/src/commands/pair.ts +7 -54
  18. package/src/commands/retire.ts +1 -5
  19. package/src/commands/tunnel.ts +3 -58
  20. package/src/lib/cloud-client.ts +4 -4
  21. package/src/lib/ingress-config.ts +0 -8
  22. package/src/lib/lan-ip.ts +50 -0
  23. package/src/lib/local.ts +1 -50
  24. package/src/lib/nginx-ingress.ts +1 -1
  25. package/src/lib/runtime-url.ts +1 -1
  26. package/src/lib/tunnel.ts +19 -20
  27. package/src/lib/tunnels/ngrok.ts +13 -73
@@ -36,7 +36,7 @@ export const ConversationErrorCodeSchema = z.enum([
36
36
  "PROVIDER_WEB_SEARCH",
37
37
  "PROVIDER_NOT_CONFIGURED",
38
38
  "PROVIDER_INVALID_KEY",
39
- "MANAGED_KEY_INVALID",
39
+ "CLOUD_KEY_INVALID",
40
40
  "CONTEXT_TOO_LARGE",
41
41
  "BUDGET_YIELD_UNRECOVERED",
42
42
  "MAX_TOKENS_REACHED",
@@ -3,7 +3,7 @@
3
3
  * credential still authenticates.
4
4
  *
5
5
  * The daemon route is the authoritative serving side:
6
- * - `POST /v1/platform/verify-credential`
6
+ * - `POST /v1/cloud/verify-credential`
7
7
  * (`assistant/src/runtime/routes/cloud-routes.ts`)
8
8
  *
9
9
  * The daemon's platform client produces the verdict, the route reports it,
@@ -32,10 +32,10 @@ export type CloudCredentialVerificationStatus = z.infer<
32
32
  typeof CloudCredentialVerificationStatusSchema
33
33
  >;
34
34
 
35
- /** `POST /v1/platform/verify-credential` response body. */
36
- export const PlatformVerifyCredentialResponseSchema = z.object({
35
+ /** `POST /v1/cloud/verify-credential` response body. */
36
+ export const CloudVerifyCredentialResponseSchema = z.object({
37
37
  status: CloudCredentialVerificationStatusSchema,
38
38
  });
39
- export type PlatformVerifyCredentialResponse = z.infer<
40
- typeof PlatformVerifyCredentialResponseSchema
39
+ export type CloudVerifyCredentialResponse = z.infer<
40
+ typeof CloudVerifyCredentialResponseSchema
41
41
  >;
@@ -37,12 +37,6 @@
37
37
  */
38
38
  export const REMOTE_WEB_PAIRING_CODE_TTL_MS = 10 * 60 * 1000;
39
39
 
40
- /** `POST /v1/remote-web/pairing-challenge` request body. */
41
- export interface RemoteWebPairingChallengeRequest {
42
- /** Public https base URL the scanning device can reach the assistant at. */
43
- publicBaseUrl: string;
44
- }
45
-
46
40
  /** `POST /v1/remote-web/pairing-challenge` success response body (200). */
47
41
  export interface RemoteWebPairingChallengeResponse {
48
42
  /** Opaque secret the paired device exchanges for a token. */
@@ -51,6 +45,12 @@ export interface RemoteWebPairingChallengeResponse {
51
45
  userCode: string;
52
46
  /** URL the device opens to complete pairing. */
53
47
  verificationUri: string;
48
+ /**
49
+ * The base URL the challenge was minted for (echoed into verificationUri).
50
+ * The gateway self-sources it — the request's own host through the trusted
51
+ * edge, else its recorded ingress URL; callers cannot request a URL.
52
+ */
53
+ publicBaseUrl: string;
54
54
  /** ISO-8601 instant the challenge expires. */
55
55
  expiresAt: string;
56
56
  /** Seconds until the challenge expires. */
@@ -3,7 +3,7 @@
3
3
  * credential still authenticates.
4
4
  *
5
5
  * The daemon route is the authoritative serving side:
6
- * - `POST /v1/platform/verify-credential`
6
+ * - `POST /v1/cloud/verify-credential`
7
7
  * (`assistant/src/runtime/routes/cloud-routes.ts`)
8
8
  *
9
9
  * The daemon's platform client produces the verdict, the route reports it,
@@ -32,10 +32,10 @@ export type CloudCredentialVerificationStatus = z.infer<
32
32
  typeof CloudCredentialVerificationStatusSchema
33
33
  >;
34
34
 
35
- /** `POST /v1/platform/verify-credential` response body. */
36
- export const PlatformVerifyCredentialResponseSchema = z.object({
35
+ /** `POST /v1/cloud/verify-credential` response body. */
36
+ export const CloudVerifyCredentialResponseSchema = z.object({
37
37
  status: CloudCredentialVerificationStatusSchema,
38
38
  });
39
- export type PlatformVerifyCredentialResponse = z.infer<
40
- typeof PlatformVerifyCredentialResponseSchema
39
+ export type CloudVerifyCredentialResponse = z.infer<
40
+ typeof CloudVerifyCredentialResponseSchema
41
41
  >;
@@ -37,12 +37,6 @@
37
37
  */
38
38
  export const REMOTE_WEB_PAIRING_CODE_TTL_MS = 10 * 60 * 1000;
39
39
 
40
- /** `POST /v1/remote-web/pairing-challenge` request body. */
41
- export interface RemoteWebPairingChallengeRequest {
42
- /** Public https base URL the scanning device can reach the assistant at. */
43
- publicBaseUrl: string;
44
- }
45
-
46
40
  /** `POST /v1/remote-web/pairing-challenge` success response body (200). */
47
41
  export interface RemoteWebPairingChallengeResponse {
48
42
  /** Opaque secret the paired device exchanges for a token. */
@@ -51,6 +45,12 @@ export interface RemoteWebPairingChallengeResponse {
51
45
  userCode: string;
52
46
  /** URL the device opens to complete pairing. */
53
47
  verificationUri: string;
48
+ /**
49
+ * The base URL the challenge was minted for (echoed into verificationUri).
50
+ * The gateway self-sources it — the request's own host through the trusted
51
+ * edge, else its recorded ingress URL; callers cannot request a URL.
52
+ */
53
+ publicBaseUrl: string;
54
54
  /** ISO-8601 instant the challenge expires. */
55
55
  expiresAt: string;
56
56
  /** Seconds until the challenge expires. */
@@ -149,6 +149,7 @@ const challengeBody = (
149
149
  ): Record<string, unknown> => ({
150
150
  deviceCode: "device-code-abc",
151
151
  userCode: "ABCD-EFGH",
152
+ publicBaseUrl: "https://gw.example.com",
152
153
  verificationUri: "https://gw.example.com/assistant/pair",
153
154
  expiresAt: new Date(Date.now() + 600_000).toISOString(),
154
155
  expiresInSeconds: 600,
@@ -720,7 +721,7 @@ describe("pairingStart", () => {
720
721
  expect(fetchCalls).toEqual([
721
722
  {
722
723
  url: "https://gw.example.com/v1/remote-web/pairing-challenge",
723
- body: { publicBaseUrl: "https://gw.example.com" },
724
+ body: {},
724
725
  redirect: "error",
725
726
  signal: expect.any(AbortSignal) as unknown as AbortSignal,
726
727
  },
@@ -133,10 +133,6 @@ export const FLATTENED_FIRST_SEGMENTS = new Set<string>([
133
133
  "contact-channels",
134
134
  ]);
135
135
 
136
- export function gatewayProxyUrl(assistantId: string): string {
137
- return `/assistant/__gateway/${encodeURIComponent(assistantId)}`;
138
- }
139
-
140
136
  /**
141
137
  * User-facing hosting label for a paired entry: "Paired · <hostname>" when
142
138
  * `runtimeUrl` names the remote host, plain "Paired" otherwise. Shared by the
@@ -9,7 +9,6 @@ import {
9
9
  tunnelProviderWebsiteName,
10
10
  type PairingFailureReason,
11
11
  type PublicBaseUrlRejection,
12
- type RemoteWebPairingChallengeRequest,
13
12
  type RemoteWebPairingChallengeResponse,
14
13
  type RemoteWebPairingTokenPendingResponse,
15
14
  type RemoteWebPairingTokenRequest,
@@ -907,9 +906,7 @@ export async function pairingStart(
907
906
  const posted = await postPairingRequest(
908
907
  parsed.publicBaseUrl,
909
908
  PAIRING_CHALLENGE_PATH,
910
- {
911
- publicBaseUrl: parsed.publicBaseUrl,
912
- } satisfies RemoteWebPairingChallengeRequest,
909
+ {},
913
910
  );
914
911
  if (!posted.ok) {
915
912
  return posted.failure;
@@ -926,7 +923,8 @@ export async function pairingStart(
926
923
  const challenge = posted.body;
927
924
  return openPairingSession(
928
925
  {
929
- publicBaseUrl: parsed.publicBaseUrl,
926
+ // The gateway self-sourced the URL; its echo is what it minted for.
927
+ publicBaseUrl: challenge.publicBaseUrl,
930
928
  deviceCode: challenge.deviceCode,
931
929
  deviceId,
932
930
  // A challenge expires somewhere inside the code's own TTL, so that TTL
@@ -3,7 +3,7 @@
3
3
  * credential still authenticates.
4
4
  *
5
5
  * The daemon route is the authoritative serving side:
6
- * - `POST /v1/platform/verify-credential`
6
+ * - `POST /v1/cloud/verify-credential`
7
7
  * (`assistant/src/runtime/routes/cloud-routes.ts`)
8
8
  *
9
9
  * The daemon's platform client produces the verdict, the route reports it,
@@ -32,10 +32,10 @@ export type CloudCredentialVerificationStatus = z.infer<
32
32
  typeof CloudCredentialVerificationStatusSchema
33
33
  >;
34
34
 
35
- /** `POST /v1/platform/verify-credential` response body. */
36
- export const PlatformVerifyCredentialResponseSchema = z.object({
35
+ /** `POST /v1/cloud/verify-credential` response body. */
36
+ export const CloudVerifyCredentialResponseSchema = z.object({
37
37
  status: CloudCredentialVerificationStatusSchema,
38
38
  });
39
- export type PlatformVerifyCredentialResponse = z.infer<
40
- typeof PlatformVerifyCredentialResponseSchema
39
+ export type CloudVerifyCredentialResponse = z.infer<
40
+ typeof CloudVerifyCredentialResponseSchema
41
41
  >;
@@ -37,12 +37,6 @@
37
37
  */
38
38
  export const REMOTE_WEB_PAIRING_CODE_TTL_MS = 10 * 60 * 1000;
39
39
 
40
- /** `POST /v1/remote-web/pairing-challenge` request body. */
41
- export interface RemoteWebPairingChallengeRequest {
42
- /** Public https base URL the scanning device can reach the assistant at. */
43
- publicBaseUrl: string;
44
- }
45
-
46
40
  /** `POST /v1/remote-web/pairing-challenge` success response body (200). */
47
41
  export interface RemoteWebPairingChallengeResponse {
48
42
  /** Opaque secret the paired device exchanges for a token. */
@@ -51,6 +45,12 @@ export interface RemoteWebPairingChallengeResponse {
51
45
  userCode: string;
52
46
  /** URL the device opens to complete pairing. */
53
47
  verificationUri: string;
48
+ /**
49
+ * The base URL the challenge was minted for (echoed into verificationUri).
50
+ * The gateway self-sources it — the request's own host through the trusted
51
+ * edge, else its recorded ingress URL; callers cannot request a URL.
52
+ */
53
+ publicBaseUrl: string;
54
54
  /** ISO-8601 instant the challenge expires. */
55
55
  expiresAt: string;
56
56
  /** Seconds until the challenge expires. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202610221914.02130b1",
3
+ "version": "0.13.0-dev.202610231403.3079a3f",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -10,7 +10,6 @@ import {
10
10
 
11
11
  import {
12
12
  clearIngressUrl,
13
- readIngressPublicBaseUrl,
14
13
  saveIngressUrl,
15
14
  savePairingTunnel,
16
15
  } from "../lib/ingress-config.js";
@@ -29,19 +28,6 @@ afterEach(() => {
29
28
  }
30
29
  });
31
30
 
32
- describe("readIngressPublicBaseUrl", () => {
33
- test("reads back what saveIngressUrl saved", () => {
34
- const ws = makeWorkspace();
35
- expect(readIngressPublicBaseUrl(ws)).toBeNull();
36
-
37
- saveIngressUrl(ws, "https://tunnel.example.ts.net");
38
-
39
- expect(readIngressPublicBaseUrl(ws)).toBe("https://tunnel.example.ts.net");
40
- clearIngressUrl(ws);
41
- expect(readIngressPublicBaseUrl(ws)).toBeNull();
42
- });
43
- });
44
-
45
31
  describe("last-tunnel record", () => {
46
32
  function readIngress(ws: string) {
47
33
  const config = JSON.parse(readFileSync(join(ws, "config.json"), "utf-8"));
@@ -9,7 +9,6 @@ import {
9
9
  ngrokAgentConfigPath,
10
10
  ngrokOnlineEndpoint,
11
11
  staleTrackedNgrokAgent,
12
- untrackedNgrokHolderPid,
13
12
  } from "../lib/tunnels/ngrok.js";
14
13
  import type { TunnelProcessRecord } from "../lib/assistant-config.js";
15
14
 
@@ -171,88 +170,3 @@ describe("staleTrackedNgrokAgent", () => {
171
170
  expect(staleTrackedNgrokAgent(undefined, () => true)).toBeNull();
172
171
  });
173
172
  });
174
-
175
- describe("untrackedNgrokHolderPid", () => {
176
- // Mirrors Vargas's Saturday incident: an agent with no lockfile record
177
- // holding the free plan's single domain, answering its inspection API on
178
- // the default port.
179
- const holderAgent = {
180
- apiAddr: "127.0.0.1:4040",
181
- tunnels: [
182
- {
183
- public_url: "https://camping-trustful-fog.ngrok-free.dev",
184
- config: { addr: "http://127.0.0.1:7840" },
185
- },
186
- ],
187
- };
188
-
189
- test("returns the verified pid of the agent serving the domain", () => {
190
- expect(
191
- untrackedNgrokHolderPid(
192
- [holderAgent],
193
- "camping-trustful-fog.ngrok-free.dev",
194
- () => true,
195
- () => 4242,
196
- ),
197
- ).toBe(4242);
198
- });
199
-
200
- test("refuses a port pid that does not verify as ngrok (reuse guard)", () => {
201
- expect(
202
- untrackedNgrokHolderPid(
203
- [holderAgent],
204
- "camping-trustful-fog.ngrok-free.dev",
205
- () => false,
206
- () => 4242,
207
- ),
208
- ).toBeNull();
209
- });
210
-
211
- test("only probes agents that actually serve the domain", () => {
212
- const probes: number[] = [];
213
- const pid = untrackedNgrokHolderPid(
214
- [
215
- {
216
- apiAddr: "127.0.0.1:4041",
217
- tunnels: [
218
- {
219
- public_url: "https://other-tunnel.ngrok-free.dev",
220
- config: { addr: "http://127.0.0.1:7840" },
221
- },
222
- ],
223
- },
224
- holderAgent,
225
- ],
226
- "camping-trustful-fog.ngrok-free.dev",
227
- () => true,
228
- (port) => {
229
- probes.push(port);
230
- return 4242;
231
- },
232
- );
233
- expect(pid).toBe(4242);
234
- expect(probes).toEqual([4040]);
235
- });
236
-
237
- test("returns null when the inspection port has no listener pid", () => {
238
- expect(
239
- untrackedNgrokHolderPid(
240
- [holderAgent],
241
- "camping-trustful-fog.ngrok-free.dev",
242
- () => true,
243
- () => null,
244
- ),
245
- ).toBeNull();
246
- });
247
-
248
- test("matches the domain case-insensitively", () => {
249
- expect(
250
- untrackedNgrokHolderPid(
251
- [holderAgent],
252
- "Camping-Trustful-Fog.ngrok-free.dev",
253
- () => true,
254
- () => 4242,
255
- ),
256
- ).toBe(4242);
257
- });
258
- });