theclawbay 0.3.69 → 0.3.70

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.
@@ -64,7 +64,7 @@ function fingerprintModel(model) {
64
64
  async function readJsonIfExists(filePath) {
65
65
  try {
66
66
  const raw = await promises_1.default.readFile(filePath, "utf8");
67
- return JSON.parse(raw);
67
+ return JSON.parse(raw.replace(/^\uFEFF/, ""));
68
68
  }
69
69
  catch (error) {
70
70
  const err = error;
@@ -73,6 +73,29 @@ async function readJsonIfExists(filePath) {
73
73
  throw error;
74
74
  }
75
75
  }
76
+ async function readModelsCacheIfExists(filePath) {
77
+ try {
78
+ const raw = await promises_1.default.readFile(filePath, "utf8");
79
+ const hadBom = raw.charCodeAt(0) === 0xfeff;
80
+ try {
81
+ return { exists: true, parsed: JSON.parse(raw.replace(/^\uFEFF/, "")), hadBom };
82
+ }
83
+ catch (error) {
84
+ return {
85
+ exists: true,
86
+ parsed: null,
87
+ hadBom,
88
+ parseError: error instanceof Error ? error.message : String(error),
89
+ };
90
+ }
91
+ }
92
+ catch (error) {
93
+ const err = error;
94
+ if (err.code === "ENOENT")
95
+ return { exists: false, parsed: null, hadBom: false };
96
+ throw error;
97
+ }
98
+ }
76
99
  async function removeFileIfExists(filePath) {
77
100
  try {
78
101
  await promises_1.default.unlink(filePath);
@@ -146,9 +169,6 @@ async function writePatchState(statePath, fingerprints) {
146
169
  }, null, 2);
147
170
  await promises_1.default.writeFile(statePath, `${contents}\n`, "utf8");
148
171
  }
149
- function findModel(models, slug) {
150
- return models.find((entry) => entry.slug === slug) ?? null;
151
- }
152
172
  function hasSeedMarker(model) {
153
173
  return LEGACY_SEED_MARKER_VALUES.has(model[SEED_MARKER_KEY]);
154
174
  }
@@ -497,16 +517,19 @@ async function ensureCodexModelCacheHasGpt54(params) {
497
517
  const statePath = node_path_1.default.join(params.codexHome, MODELS_CACHE_STATE_FILE);
498
518
  try {
499
519
  const existingState = await readPatchState(statePath);
500
- const parsed = await readJsonIfExists(cachePath);
520
+ const cacheRead = await readModelsCacheIfExists(cachePath);
521
+ const parsed = cacheRead.parsed;
501
522
  const catalogModels = buildCatalogModels();
502
523
  const catalogModelMap = buildCatalogModelMap();
503
- if (parsed === null) {
524
+ if (!cacheRead.exists || parsed === null) {
504
525
  const clientVersion = await inferCodexClientVersion(params.codexHome);
505
526
  if (!clientVersion) {
506
527
  await removeFileIfExists(statePath);
507
528
  return {
508
529
  action: "skipped",
509
- warning: "Codex models cache was not found, and Codex version could not be inferred for a safe The Claw Bay model catalog refresh.",
530
+ warning: cacheRead.exists
531
+ ? "Codex models cache is not valid JSON, and Codex version could not be inferred for a safe The Claw Bay model catalog repair."
532
+ : "Codex models cache was not found, and Codex version could not be inferred for a safe The Claw Bay model catalog refresh.",
510
533
  };
511
534
  }
512
535
  const docModels = cloneJson(catalogModels);
@@ -522,7 +545,7 @@ async function ensureCodexModelCacheHasGpt54(params) {
522
545
  await promises_1.default.mkdir(params.codexHome, { recursive: true });
523
546
  await promises_1.default.writeFile(cachePath, `${JSON.stringify(doc, null, 2)}\n`, "utf8");
524
547
  await writePatchState(statePath, nextState);
525
- return { action: "created" };
548
+ return { action: cacheRead.exists ? "refreshed" : "created" };
526
549
  }
527
550
  const doc = normalizeCacheDocument(parsed);
528
551
  if (!doc) {
@@ -533,7 +556,7 @@ async function ensureCodexModelCacheHasGpt54(params) {
533
556
  }
534
557
  const clientVersion = (await inferCodexClientVersion(params.codexHome)) ??
535
558
  (typeof doc.client_version === "string" && doc.client_version ? doc.client_version : null);
536
- let changed = false;
559
+ let changed = cacheRead.hadBom;
537
560
  let seeded = false;
538
561
  const currentCatalogEntries = new Map();
539
562
  const rest = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theclawbay",
3
- "version": "0.3.69",
3
+ "version": "0.3.70",
4
4
  "description": "CLI for connecting Codex, Continue, Cline, GSD, OpenClaw, OpenCode, Kilo, Roo Code, Aider, experimental Trae, and experimental Zo to The Claw Bay.",
5
5
  "license": "MIT",
6
6
  "repository": {