@mycadet/cli 0.13.0-dev.202610251252.f691e47 → 0.13.0-dev.202610252248.6747732

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.
@@ -42,7 +42,7 @@ export {
42
42
  resolveEnvironmentName,
43
43
  } from "./environment";
44
44
  export {
45
- getLockfileData,
45
+ readLockfile,
46
46
  renameLockfileAssistantIfPresent,
47
47
  stampLockfileAssistantOnboardedIfPresent,
48
48
  saveLockfileAssistant,
@@ -58,7 +58,7 @@ export {
58
58
  LockfileAssistantSchema,
59
59
  parseLockfile,
60
60
  } from "./lockfile-contract";
61
- export { readRawLockfileStrict } from "./lockfile";
61
+ export { readRawLockfile, readRawLockfileStrict } from "./lockfile";
62
62
  export type {
63
63
  Lockfile,
64
64
  LockfileAssistant,
@@ -148,3 +148,4 @@ export type {
148
148
  PairedForwardAuthorizationResult,
149
149
  PairedGuardianTokenProvider,
150
150
  } from "./gateway-proxy";
151
+
@@ -5,21 +5,54 @@ import {
5
5
  isLoopbackGatewayCloud,
6
6
  isUsableRuntimeUrl,
7
7
  LockfileAssistantSchema,
8
+ LockfileSchema,
8
9
  parseLockfile,
9
10
  type Lockfile,
10
11
  } from "./lockfile-contract";
11
12
  import { isCloudHome } from "./lockfile-contract";
13
+ import { resolveLockfilePaths } from "./config";
12
14
  import { z } from "zod";
13
15
 
14
16
  import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
15
17
  import { withLockfileLock } from "./lockfile-lock";
16
18
  import { stripSensitiveFields } from "./util";
17
19
 
20
+ /**
21
+ * The one lockfile read: the first existing candidate file parsed against the
22
+ * contract, degrading to the empty registry when no file parses. Takes no
23
+ * input — the paths resolve from the process's environment (the same
24
+ * `CADET_ENVIRONMENT` / persisted-default resolution every host and the CLI
25
+ * share), so every consumer of a lockfile answers the same question about the
26
+ * same bytes.
27
+ */
28
+ export function readLockfile(): Lockfile {
29
+ for (const lockfilePath of resolveLockfilePaths(process.env)) {
30
+ if (!fs.existsSync(lockfilePath)) continue;
31
+ try {
32
+ const parsed = LockfileSchema.safeParse(
33
+ JSON.parse(fs.readFileSync(lockfilePath, "utf-8")),
34
+ );
35
+ if (parsed.success) {
36
+ return parsed.data;
37
+ }
38
+ } catch {
39
+ // Malformed lockfile; try next
40
+ }
41
+ }
42
+ return LockfileSchema.parse({});
43
+ }
44
+
18
45
  /** `raw` is the authoritative file's parsed JSON (unknown fields intact). */
19
46
  export type LockfileResult =
20
47
  | { ok: true; data: Lockfile; raw: Record<string, unknown> }
21
48
  | { ok: false; status: number; error?: string };
22
49
 
50
+ /**
51
+ * The raw-preserving read: the HTTP lockfile API and the instance-dir
52
+ * resolution need the unknown-field-intact record alongside the wire view, so
53
+ * this stays package-internal (never re-exported from the index) — everything
54
+ * else reads through {@link readLockfile}.
55
+ */
23
56
  export function getLockfileData(lockfilePaths: string[]): LockfileResult {
24
57
  let raw: string | undefined;
25
58
  for (const candidate of lockfilePaths) {
@@ -394,3 +427,4 @@ export function replaceCloudAssistants(
394
427
  });
395
428
  return locked.ok ? locked.value : lockFailure(locked.error);
396
429
  }
430
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202610251252.f691e47",
3
+ "version": "0.13.0-dev.202610252248.6747732",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -1,18 +1,15 @@
1
1
  import { randomBytes } from "crypto";
2
- import {
3
- existsSync,
4
- mkdirSync,
5
- readFileSync,
6
- renameSync,
7
- unlinkSync,
8
- writeFileSync,
9
- } from "fs";
2
+ import { mkdirSync, renameSync, unlinkSync, writeFileSync } from "fs";
10
3
  import { dirname, join } from "path";
11
4
 
12
5
  import { SEEDS, type EnvironmentDefinition } from "@mycadet/environments";
13
- import { withLockfileLock } from "@mycadet/local-mode";
14
6
  import {
15
- LockfileSchema,
7
+ readLockfile,
8
+ readRawLockfile,
9
+ withLockfileLock,
10
+ } from "@mycadet/local-mode";
11
+ import {
12
+ parseLockfile,
16
13
  type AppProcessRecord,
17
14
  type LocalAssistantResources,
18
15
  type Lockfile,
@@ -77,23 +74,6 @@ export function getDaemonPidPath(resources?: LocalAssistantResources): string {
77
74
  return join(getLocalInstanceDir(resources), "workspace", "cadet.pid");
78
75
  }
79
76
 
80
- function readLockfile(): Lockfile {
81
- for (const lockfilePath of getLockfilePaths(getCurrentEnvironment())) {
82
- if (!existsSync(lockfilePath)) continue;
83
- try {
84
- const parsed = LockfileSchema.safeParse(
85
- JSON.parse(readFileSync(lockfilePath, "utf-8")),
86
- );
87
- if (parsed.success) {
88
- return parsed.data;
89
- }
90
- } catch {
91
- // Malformed lockfile; try next
92
- }
93
- }
94
- return LockfileSchema.parse({});
95
- }
96
-
97
77
  function writeLockfileUnlocked(data: Lockfile): void {
98
78
  const lockfilePath = getLockfilePath(getCurrentEnvironment());
99
79
  mkdirSync(dirname(lockfilePath), { recursive: true });
@@ -318,32 +298,6 @@ export function removeLockfileAssistant(assistantId: string): void {
318
298
  });
319
299
  }
320
300
 
321
- /**
322
- * Read the first existing lockfile for an explicitly-provided environment,
323
- * without applying legacy migrations. This is the cross-env read path used by
324
- * {@link loadAllAssistantsAcrossEnvs}: it deliberately bypasses
325
- * {@link readLockfile} (which always resolves the *current* env) so callers
326
- * can enumerate state from every env without flipping `process.env` or the
327
- * persisted default. Migrations are skipped because we never want to write
328
- * to another env's lockfile from the current env's process.
329
- */
330
- function readLockfileForEnv(env: EnvironmentDefinition): Lockfile {
331
- for (const lockfilePath of getLockfilePaths(env)) {
332
- if (!existsSync(lockfilePath)) continue;
333
- try {
334
- const parsed = LockfileSchema.safeParse(
335
- JSON.parse(readFileSync(lockfilePath, "utf-8")),
336
- );
337
- if (parsed.success) {
338
- return parsed.data;
339
- }
340
- } catch {
341
- // Malformed; try next candidate
342
- }
343
- }
344
- return LockfileSchema.parse({});
345
- }
346
-
347
301
  /**
348
302
  * Load assistant entries from every known environment's lockfile.
349
303
  *
@@ -364,7 +318,9 @@ export function loadAllAssistantsAcrossEnvs(
364
318
  const envList = envs ?? Object.values(SEEDS).map((env) => ({ ...env }));
365
319
  const all: LockfileAssistant[] = [];
366
320
  for (const env of envList) {
367
- all.push(...readLockfileForEnv(env).assistants);
321
+ all.push(
322
+ ...parseLockfile(readRawLockfile(getLockfilePaths(env))).assistants,
323
+ );
368
324
  }
369
325
  return all;
370
326
  }
@@ -571,3 +527,4 @@ export function getLockfilePlatformBaseUrl(): string | undefined {
571
527
  if (typeof url === "string" && url.trim()) return url.trim();
572
528
  return undefined;
573
529
  }
530
+