ccem 2.96.0 → 2.97.0

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 (2) hide show
  1. package/dist/index.js +333 -258
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1254,6 +1254,8 @@ function importClaudePlugins(sourceHome, targetHome) {
1254
1254
  var CLAUDE_PLUGIN_LINK_LEDGER = ".ccem-plugin-links-v1.json";
1255
1255
  var MARKER = ".ccem-plugin-link-v1.json";
1256
1256
  var BACKUP = ".ccem-plugin-links-backup-v1";
1257
+ var METADATA = ".claude-plugin";
1258
+ var LAYOUT = ".ccem-layout-v2";
1257
1259
  var IGNORED = /* @__PURE__ */ new Set([".git", ".in_use", ".orphaned_at", MARKER]);
1258
1260
  function absolute(value) {
1259
1261
  return typeof value === "string" && path3.isAbsolute(value) && !value.split(/[\\/]/).includes("..");
@@ -1290,31 +1292,42 @@ function readLinks(target) {
1290
1292
  function children(root) {
1291
1293
  return fs3.readdirSync(root).filter((name) => !IGNORED.has(name)).sort();
1292
1294
  }
1293
- function validateCode(file, store, protectedCatalogues, ancestors = /* @__PURE__ */ new Set()) {
1295
+ function metadataChildren(root) {
1296
+ return fs3.readdirSync(root).filter((name) => name !== "marketplace.json").sort();
1297
+ }
1298
+ function linkChildren(root, legacy = false) {
1299
+ return children(root).flatMap((name) => {
1300
+ if (name !== METADATA || legacy && stat(path3.join(root, name))?.isSymbolicLink()) return [name];
1301
+ return metadataChildren(path3.join(root, name)).map((child) => path3.join(name, child));
1302
+ });
1303
+ }
1304
+ function validateCode(file, store, protectedCatalogues, ancestors = /* @__PURE__ */ new Set(), metadata = false) {
1294
1305
  const resolved = fs3.realpathSync(file);
1295
- if (!contained(store, resolved)) throw new Error("Linked plugin code escapes the official plugin store");
1296
- rejectPrivateData(store, resolved);
1297
- const parts = path3.relative(store, resolved).split(path3.sep);
1298
- if (parts.length < 2 || protectedCatalogues.has(resolved) || parts.some((part) => [".in_use", ".orphaned_at", MARKER].includes(part))) {
1299
- throw new Error("Linked plugin code cannot expose official plugin metadata or runtime markers");
1306
+ for (const candidate of [path3.resolve(file), resolved]) {
1307
+ if (!contained(store, candidate)) throw new Error("Linked plugin code escapes the official plugin store");
1308
+ rejectPrivateData(store, candidate);
1309
+ const parts = path3.relative(store, candidate).split(path3.sep);
1310
+ if (parts.length < 2 || protectedCatalogues.has(candidate) || parts.some((part) => [".in_use", ".orphaned_at", MARKER].includes(part))) {
1311
+ throw new Error("Linked plugin code cannot expose official plugin metadata or runtime markers");
1312
+ }
1300
1313
  }
1301
1314
  if (ancestors.has(resolved)) throw new Error("Linked plugin code has a symlink cycle");
1302
1315
  const info = fs3.statSync(resolved);
1303
1316
  if (info.isDirectory()) {
1304
1317
  const next = new Set(ancestors).add(resolved);
1305
- const names = ancestors.size === 0 ? children(resolved) : fs3.readdirSync(resolved).sort();
1306
- for (const name of names) validateCode(path3.join(resolved, name), store, protectedCatalogues, next);
1318
+ const names = metadata ? metadataChildren(resolved) : ancestors.size === 0 ? children(resolved) : fs3.readdirSync(resolved).sort();
1319
+ for (const name of names) validateCode(path3.join(resolved, name), store, protectedCatalogues, next, ancestors.size === 0 && name === METADATA);
1307
1320
  } else if (!info.isFile()) throw new Error("Linked plugin code is not a regular file or directory");
1308
1321
  }
1309
- function equalCopy(source, target) {
1322
+ function equalCopy(source, target, top = true, metadata = false) {
1310
1323
  noLinks(target);
1311
1324
  const from = fs3.statSync(source);
1312
1325
  const to = stat(target);
1313
1326
  if (!to || from.isDirectory() !== to.isDirectory() || from.isFile() !== to.isFile()) return false;
1314
1327
  if (from.isFile()) return fs3.readFileSync(source).equals(fs3.readFileSync(target)) && (from.mode & 73) === (to.mode & 73);
1315
- const names = children(source);
1316
- const local = children(target);
1317
- return JSON.stringify(names) === JSON.stringify(local) && names.every((name) => equalCopy(path3.join(source, name), path3.join(target, name)));
1328
+ const names = metadata ? metadataChildren(source) : children(source);
1329
+ const local = metadata ? metadataChildren(target) : children(target);
1330
+ return JSON.stringify(names) === JSON.stringify(local) && names.every((name) => equalCopy(path3.join(source, name), path3.join(target, name), false, top && name === METADATA));
1318
1331
  }
1319
1332
  function rootMarker(target, source) {
1320
1333
  noLinks(target);
@@ -1333,22 +1346,36 @@ function recoverPublished(row, key, id, sourceRoot, targetRoot) {
1333
1346
  const suffix = `.ccem-linked-${createHash("sha256").update(marker.value.source).digest("hex").slice(0, 8)}`;
1334
1347
  if (!row.version.endsWith(suffix) || row.version.length === suffix.length) return;
1335
1348
  rootMarker(row.installPath, marker.value.source);
1349
+ if (!ownedChildren(row.installPath, marker.value.source)) return;
1336
1350
  return { ...key, sourcePath: marker.value.source, installPath: row.installPath, version: row.version };
1337
1351
  }
1338
1352
  function planRoot(source, target) {
1339
1353
  const marker = rootMarker(target, source);
1340
1354
  let changed2 = marker.before === void 0;
1341
- const wanted = new Set(children(source));
1342
- if (stat(target)) for (const name of children(target)) {
1355
+ noLinks(path3.join(target, METADATA));
1356
+ const wanted = new Set(linkChildren(source));
1357
+ if (stat(target)) for (const name of linkChildren(target)) {
1343
1358
  const child = path3.join(target, name);
1344
1359
  if (!stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(source, name)) {
1345
1360
  throw new Error("CCEM plugin code was changed locally; keeping it");
1346
1361
  }
1347
1362
  if (!wanted.has(name)) changed2 = true;
1348
1363
  }
1364
+ if (!stat(path3.join(target, METADATA))) changed2 = true;
1349
1365
  for (const name of wanted) if (!stat(path3.join(target, name))) changed2 = true;
1350
1366
  return { source, target, changed: changed2 };
1351
1367
  }
1368
+ function ownedChildren(target, source) {
1369
+ if (!stat(target)) return false;
1370
+ const legacy = !path3.basename(target).includes(`${LAYOUT}.ccem-linked-`);
1371
+ const metadata = stat(path3.join(target, METADATA));
1372
+ if (metadata && !(legacy ? metadata.isSymbolicLink() : metadata.isDirectory())) return false;
1373
+ if (!legacy && stat(path3.join(target, METADATA, "marketplace.json"))) return false;
1374
+ return linkChildren(target, legacy).every((name) => {
1375
+ const child = path3.join(target, name);
1376
+ return stat(child)?.isSymbolicLink() && fs3.readlinkSync(child) === path3.join(source, name);
1377
+ });
1378
+ }
1352
1379
  function publishRoot(root) {
1353
1380
  if (!root.changed) return;
1354
1381
  planRoot(root.source, root.target);
@@ -1358,8 +1385,9 @@ function publishRoot(root) {
1358
1385
  try {
1359
1386
  if (fresh) fs3.writeFileSync(path3.join(directory, MARKER), `${JSON.stringify({ version: 1, source: root.source })}
1360
1387
  `, { flag: "wx", mode: 384 });
1361
- const wanted = new Set(children(root.source));
1362
- for (const name of children(directory)) if (!wanted.has(name)) {
1388
+ const wanted = new Set(linkChildren(root.source));
1389
+ privateDirectory(path3.join(directory, METADATA));
1390
+ for (const name of linkChildren(directory)) if (!wanted.has(name)) {
1363
1391
  const child = path3.join(directory, name);
1364
1392
  if (!stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(root.source, name)) throw new Error("Plugin link changed during preparation");
1365
1393
  fs3.unlinkSync(child);
@@ -1486,7 +1514,7 @@ function planLinks(sourceHome, targetHome) {
1486
1514
  validateCode(code, sourceRoot, protectedCatalogues);
1487
1515
  const sourceVersion = typeof official.version === "string" ? official.version : path3.basename(original.source);
1488
1516
  if (!/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(sourceVersion)) throw new Error("Invalid plugin version");
1489
- const version = `${sourceVersion}.ccem-linked-${createHash("sha256").update(code).digest("hex").slice(0, 8)}`;
1517
+ const version = `${sourceVersion}${LAYOUT}.ccem-linked-${createHash("sha256").update(code).digest("hex").slice(0, 8)}`;
1490
1518
  const destination = path3.join(targetRoot, "cache", market, name, version);
1491
1519
  if (registryMoved) {
1492
1520
  if (local.installPath === destination && local.version === version && stat(destination)) rootMarker(destination, code);
@@ -1497,10 +1525,7 @@ function planLinks(sourceHome, targetHome) {
1497
1525
  }
1498
1526
  if (old && !registryMoved) {
1499
1527
  rootMarker(old.installPath, old.sourcePath);
1500
- if (!stat(old.installPath) || children(old.installPath).some((name2) => {
1501
- const child = path3.join(old.installPath, name2);
1502
- return !stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(old.sourcePath, name2);
1503
- })) {
1528
+ if (!ownedChildren(old.installPath, old.sourcePath)) {
1504
1529
  detach();
1505
1530
  continue;
1506
1531
  }
@@ -1537,7 +1562,7 @@ function planLinks(sourceHome, targetHome) {
1537
1562
  if (!choices.length) delete ledger.value.plugins[id];
1538
1563
  }
1539
1564
  const targets = [...catalogues.values(), targetRegistry, ledger];
1540
- return { documents, targets, roots: [...roots.values()], changed: targets.some(changed) || [...roots.values()].some((root) => root.changed) };
1565
+ return { documents, targets, roots: [...roots.values()], changed: targets.some(changed) || [...roots.values()].some((root) => root.changed), store: sourceRoot, protectedCatalogues };
1541
1566
  }
1542
1567
  function claudePluginLinksPending(sourceHome, targetHome) {
1543
1568
  return planLinks(sourceHome, targetHome).changed;
@@ -1546,7 +1571,10 @@ function linkClaudePlugins(sourceHome, targetHome) {
1546
1571
  const plan = planLinks(sourceHome, targetHome);
1547
1572
  if (!plan.changed) return;
1548
1573
  for (const document of plan.documents) unchanged(document);
1549
- for (const root of plan.roots) publishRoot(root);
1574
+ for (const root of plan.roots) {
1575
+ validateCode(root.source, plan.store, plan.protectedCatalogues);
1576
+ publishRoot(root);
1577
+ }
1550
1578
  for (const document of plan.targets) {
1551
1579
  for (const observed of plan.documents) unchanged(observed);
1552
1580
  publishDocument(document, targetHome, BACKUP);
@@ -2511,8 +2539,8 @@ import inquirer from "inquirer";
2511
2539
  import chalk9 from "chalk";
2512
2540
  import Table4 from "cli-table3";
2513
2541
  import { spawn as spawn4 } from "child_process";
2514
- import * as fs18 from "fs";
2515
- import * as path16 from "path";
2542
+ import * as fs19 from "fs";
2543
+ import * as path17 from "path";
2516
2544
  import { fileURLToPath as fileURLToPath2 } from "url";
2517
2545
  import { randomUUID as randomUUID4 } from "crypto";
2518
2546
 
@@ -2521,19 +2549,84 @@ import chalk from "chalk";
2521
2549
  import Table from "cli-table3";
2522
2550
 
2523
2551
  // src/usage.ts
2524
- import * as fs7 from "fs";
2552
+ import * as fs8 from "fs";
2525
2553
  import * as fsPromises from "fs/promises";
2526
- import * as path7 from "path";
2554
+ import * as path8 from "path";
2527
2555
  import * as os3 from "os";
2528
- import * as readline from "readline";
2556
+ import { createHash as createHash2 } from "crypto";
2529
2557
  import { fileURLToPath } from "url";
2558
+
2559
+ // src/usage-profiles.ts
2560
+ import path7 from "path";
2561
+ import * as fs7 from "fs/promises";
2562
+ async function discoverClaudeUsageFiles(roots) {
2563
+ const files = [];
2564
+ const seen = /* @__PURE__ */ new Set();
2565
+ async function walk(dir, depth) {
2566
+ try {
2567
+ for (const entry of await fs7.readdir(dir, { withFileTypes: true })) {
2568
+ const file = path7.join(dir, entry.name);
2569
+ if (entry.isDirectory() && depth < 4) await walk(file, depth + 1);
2570
+ else if (entry.isFile() && entry.name.endsWith(".jsonl")) files.push(file);
2571
+ }
2572
+ } catch {
2573
+ }
2574
+ }
2575
+ for (const root of roots) {
2576
+ const canonical = await fs7.realpath(root).catch(() => root);
2577
+ if (seen.has(canonical)) continue;
2578
+ seen.add(canonical);
2579
+ await walk(root, 0);
2580
+ }
2581
+ return files;
2582
+ }
2583
+ function logicalPath(file, roots) {
2584
+ for (const root of roots) {
2585
+ const relative2 = path7.relative(root, file);
2586
+ if (relative2 && !relative2.startsWith(`..${path7.sep}`) && relative2 !== ".." && !path7.isAbsolute(relative2)) {
2587
+ return relative2;
2588
+ }
2589
+ }
2590
+ return file;
2591
+ }
2592
+ function newer(left, right) {
2593
+ const time = (row) => Date.parse(row.timestamp) || 0;
2594
+ const tokens = (row) => row.usage.inputTokens + row.usage.outputTokens + row.usage.cacheReadTokens + row.usage.cacheCreationTokens;
2595
+ return time(left) > time(right) || time(left) === time(right) && tokens(left) > tokens(right);
2596
+ }
2597
+ function mergeClaudeUsage(files, roots) {
2598
+ const merged = /* @__PURE__ */ new Map();
2599
+ for (const [file, data] of Object.entries(files).sort(([a], [b]) => a.localeCompare(b))) {
2600
+ const session = logicalPath(file, roots);
2601
+ const occurrences = /* @__PURE__ */ new Map();
2602
+ for (const [index, row] of data.stats.entries.entries()) {
2603
+ let identity2;
2604
+ if (row.messageId) identity2 = `id:${row.messageId}`;
2605
+ else {
2606
+ const signature = row.recordFingerprint ?? JSON.stringify([file, index]);
2607
+ const occurrence = (occurrences.get(signature) ?? 0) + 1;
2608
+ occurrences.set(signature, occurrence);
2609
+ identity2 = `row:${signature}:${occurrence}`;
2610
+ }
2611
+ const key = JSON.stringify([session, identity2]);
2612
+ const previous = merged.get(key);
2613
+ if (!previous || newer(row, previous)) merged.set(key, row);
2614
+ }
2615
+ }
2616
+ return [...merged.values()];
2617
+ }
2618
+
2619
+ // src/usage.ts
2530
2620
  var __filename = fileURLToPath(import.meta.url);
2531
- var __dirname = path7.dirname(__filename);
2532
- var CLAUDE_PROJECTS_DIR = path7.join(getCcemAgentHome("claude"), "projects");
2533
- var CCEM_DIR = path7.join(os3.homedir(), ".ccem");
2534
- var CACHE_VERSION = 3;
2535
- var getCachePath = () => path7.join(CCEM_DIR, "usage-cache.json");
2536
- var getPricesPath = () => path7.join(CCEM_DIR, "model-prices.json");
2621
+ var __dirname = path8.dirname(__filename);
2622
+ var CLAUDE_PROJECTS_DIRS = [
2623
+ path8.join(getCcemAgentHome("claude"), "projects"),
2624
+ path8.join(os3.homedir(), ".claude", "projects")
2625
+ ];
2626
+ var CCEM_DIR = path8.join(os3.homedir(), ".ccem");
2627
+ var CACHE_VERSION = 4;
2628
+ var getCachePath = () => path8.join(CCEM_DIR, "usage-cache.json");
2629
+ var getPricesPath = () => path8.join(CCEM_DIR, "model-prices.json");
2537
2630
  async function ensureCcemDir2() {
2538
2631
  try {
2539
2632
  await fsPromises.access(CCEM_DIR);
@@ -2543,7 +2636,7 @@ async function ensureCcemDir2() {
2543
2636
  }
2544
2637
  var LITELLM_PRICES_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
2545
2638
  var getBundledPricesPath = () => {
2546
- return path7.join(__dirname, "..", "model-prices.json");
2639
+ return path8.join(__dirname, "..", "model-prices.json");
2547
2640
  };
2548
2641
  var DEFAULT_PRICES = {
2549
2642
  "claude-opus-4-5": {
@@ -2662,9 +2755,9 @@ async function getFileMetaAsync(filePath) {
2662
2755
  function loadCacheSync() {
2663
2756
  try {
2664
2757
  const cachePath = getCachePath();
2665
- if (!fs7.existsSync(cachePath)) return null;
2666
- const data = JSON.parse(fs7.readFileSync(cachePath, "utf-8"));
2667
- if (data.version !== CACHE_VERSION) return null;
2758
+ if (!fs8.existsSync(cachePath)) return null;
2759
+ const data = JSON.parse(fs8.readFileSync(cachePath, "utf-8"));
2760
+ if (data.version !== 3 && data.version !== CACHE_VERSION) return null;
2668
2761
  return data;
2669
2762
  } catch {
2670
2763
  return null;
@@ -2675,7 +2768,7 @@ async function loadCacheAsync() {
2675
2768
  const cachePath = getCachePath();
2676
2769
  const content = await fsPromises.readFile(cachePath, "utf-8");
2677
2770
  const data = JSON.parse(content);
2678
- if (data.version !== CACHE_VERSION) return null;
2771
+ if (data.version !== 3 && data.version !== CACHE_VERSION) return null;
2679
2772
  return data;
2680
2773
  } catch {
2681
2774
  return null;
@@ -2696,26 +2789,24 @@ function getUsageStatsFromCache() {
2696
2789
  byModel: {},
2697
2790
  lastUpdated: now.toISOString()
2698
2791
  };
2699
- for (const fileData of Object.values(cache.files)) {
2700
- for (const entry of fileData.stats.entries) {
2701
- const entryTime = new Date(entry.timestamp);
2702
- const dateKey = entry.timestamp.split("T")[0];
2703
- stats.total = mergeUsage(stats.total, entry.usage);
2704
- if (!stats.dailyHistory[dateKey]) {
2705
- stats.dailyHistory[dateKey] = emptyUsage();
2706
- }
2707
- stats.dailyHistory[dateKey] = mergeUsage(stats.dailyHistory[dateKey], entry.usage);
2708
- const normalizedModel = normalizeModelName(entry.model);
2709
- if (!stats.byModel[normalizedModel]) {
2710
- stats.byModel[normalizedModel] = emptyUsage();
2711
- }
2712
- stats.byModel[normalizedModel] = mergeUsage(stats.byModel[normalizedModel], entry.usage);
2713
- if (entryTime >= todayStart) {
2714
- stats.today = mergeUsage(stats.today, entry.usage);
2715
- }
2716
- if (entryTime >= weekStart) {
2717
- stats.week = mergeUsage(stats.week, entry.usage);
2718
- }
2792
+ for (const entry of mergeClaudeUsage(cache.files, CLAUDE_PROJECTS_DIRS)) {
2793
+ const entryTime = new Date(entry.timestamp);
2794
+ const dateKey = entry.timestamp.split("T")[0];
2795
+ stats.total = mergeUsage(stats.total, entry.usage);
2796
+ if (!stats.dailyHistory[dateKey]) {
2797
+ stats.dailyHistory[dateKey] = emptyUsage();
2798
+ }
2799
+ stats.dailyHistory[dateKey] = mergeUsage(stats.dailyHistory[dateKey], entry.usage);
2800
+ const normalizedModel = normalizeModelName(entry.model);
2801
+ if (!stats.byModel[normalizedModel]) {
2802
+ stats.byModel[normalizedModel] = emptyUsage();
2803
+ }
2804
+ stats.byModel[normalizedModel] = mergeUsage(stats.byModel[normalizedModel], entry.usage);
2805
+ if (entryTime >= todayStart) {
2806
+ stats.today = mergeUsage(stats.today, entry.usage);
2807
+ }
2808
+ if (entryTime >= weekStart) {
2809
+ stats.week = mergeUsage(stats.week, entry.usage);
2719
2810
  }
2720
2811
  }
2721
2812
  return stats;
@@ -2727,21 +2818,31 @@ async function saveCacheAsync(cache) {
2727
2818
  } catch {
2728
2819
  }
2729
2820
  }
2821
+ async function* completeLines(stream) {
2822
+ let pending = "";
2823
+ try {
2824
+ for await (const chunk of stream) {
2825
+ pending += chunk.toString();
2826
+ let newline;
2827
+ while ((newline = pending.indexOf("\n")) >= 0) {
2828
+ yield pending.slice(0, newline);
2829
+ pending = pending.slice(newline + 1);
2830
+ }
2831
+ }
2832
+ } finally {
2833
+ stream.destroy();
2834
+ }
2835
+ }
2730
2836
  async function parseJSONLFileAsync(filePath, prices, signal) {
2731
2837
  const entries = [];
2732
2838
  const messageEntryIndexes = /* @__PURE__ */ new Map();
2733
2839
  try {
2734
- const fileStream = fs7.createReadStream(filePath, { encoding: "utf-8" });
2735
- const rl = readline.createInterface({
2736
- input: fileStream,
2737
- crlfDelay: Infinity
2738
- });
2840
+ const fileStream = fs8.createReadStream(filePath, { encoding: "utf-8" });
2739
2841
  let lineCount = 0;
2740
- for await (const line of rl) {
2842
+ for await (const line of completeLines(fileStream)) {
2741
2843
  lineCount++;
2742
2844
  if (lineCount % 100 === 0) {
2743
2845
  if (signal?.aborted) {
2744
- rl.close();
2745
2846
  fileStream.destroy();
2746
2847
  throw new Error("Aborted");
2747
2848
  }
@@ -2766,6 +2867,7 @@ async function parseJSONLFileAsync(filePath, prices, signal) {
2766
2867
  const statsEntry = {
2767
2868
  timestamp: entry.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
2768
2869
  model,
2870
+ ...typeof entry.message.id === "string" && entry.message.id ? { messageId: entry.message.id } : { recordFingerprint: createHash2("sha256").update(line.trim()).digest("hex") },
2769
2871
  usage: { ...usage, cost }
2770
2872
  };
2771
2873
  const messageId = entry.message.id;
@@ -2787,49 +2889,22 @@ async function parseJSONLFileAsync(filePath, prices, signal) {
2787
2889
  if (err.message === "Aborted") {
2788
2890
  throw err;
2789
2891
  }
2892
+ return null;
2790
2893
  }
2791
2894
  return { entries };
2792
2895
  }
2793
- async function getAllJSONLFilesAsync() {
2794
- const files = [];
2795
- try {
2796
- const projectsDirExists = await fsPromises.access(CLAUDE_PROJECTS_DIR).then(() => true).catch(() => false);
2797
- if (!projectsDirExists) return files;
2798
- const projects = await fsPromises.readdir(CLAUDE_PROJECTS_DIR);
2799
- for (const project of projects) {
2800
- const projectPath = path7.join(CLAUDE_PROJECTS_DIR, project);
2801
- try {
2802
- const stat3 = await fsPromises.lstat(projectPath);
2803
- if (stat3.isDirectory()) {
2804
- const projectFiles = await fsPromises.readdir(projectPath);
2805
- for (const file of projectFiles) {
2806
- const filePath = path7.join(projectPath, file);
2807
- if (file.endsWith(".jsonl") && (await fsPromises.lstat(filePath)).isFile()) {
2808
- files.push(filePath);
2809
- }
2810
- }
2811
- }
2812
- } catch {
2813
- }
2814
- }
2815
- } catch {
2816
- }
2817
- return files;
2818
- }
2819
2896
  async function getUsageStats(signal) {
2820
2897
  if (signal?.aborted) throw new Error("Aborted");
2821
- ensureCcemAgentHome("claude");
2822
2898
  const prices = await loadPrices();
2823
2899
  if (signal?.aborted) throw new Error("Aborted");
2824
- const files = await getAllJSONLFilesAsync();
2900
+ const files = await discoverClaudeUsageFiles(CLAUDE_PROJECTS_DIRS);
2825
2901
  if (signal?.aborted) throw new Error("Aborted");
2826
2902
  const cache = await loadCacheAsync();
2827
2903
  const newCache = {
2828
2904
  version: CACHE_VERSION,
2829
- files: {},
2905
+ files: { ...cache?.files },
2830
2906
  lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
2831
2907
  };
2832
- const allEntries = [];
2833
2908
  const CONCURRENCY_LIMIT = 5;
2834
2909
  const chunks = [];
2835
2910
  for (let i = 0; i < files.length; i += CONCURRENCY_LIMIT) {
@@ -2843,12 +2918,13 @@ async function getUsageStats(signal) {
2843
2918
  const meta = await getFileMetaAsync(file);
2844
2919
  if (!meta) return null;
2845
2920
  const cachedFile = cache?.files[file];
2846
- const cacheValid = cachedFile && cachedFile.meta.mtime === meta.mtime && cachedFile.meta.size === meta.size;
2921
+ const cacheValid = cachedFile && cachedFile.stats.entries.every((entry) => entry.messageId || entry.recordFingerprint) && cachedFile.meta.mtime === meta.mtime && cachedFile.meta.size === meta.size;
2847
2922
  let fileStats;
2848
2923
  if (cacheValid) {
2849
2924
  fileStats = cachedFile.stats;
2850
2925
  } else {
2851
2926
  fileStats = await parseJSONLFileAsync(file, prices, signal);
2927
+ if (!fileStats) return null;
2852
2928
  await new Promise((resolve5) => setTimeout(resolve5, 0));
2853
2929
  }
2854
2930
  return {
@@ -2864,7 +2940,6 @@ async function getUsageStats(signal) {
2864
2940
  meta: result.meta,
2865
2941
  stats: result.stats
2866
2942
  };
2867
- allEntries.push(...result.stats.entries);
2868
2943
  }
2869
2944
  }
2870
2945
  if (!signal?.aborted) {
@@ -2883,7 +2958,7 @@ async function getUsageStats(signal) {
2883
2958
  byModel: {},
2884
2959
  lastUpdated: now.toISOString()
2885
2960
  };
2886
- for (const entry of allEntries) {
2961
+ for (const entry of mergeClaudeUsage(newCache.files, CLAUDE_PROJECTS_DIRS)) {
2887
2962
  const entryTime = new Date(entry.timestamp);
2888
2963
  const dateKey = entry.timestamp.split("T")[0];
2889
2964
  stats.total = mergeUsage(stats.total, entry.usage);
@@ -3029,10 +3104,10 @@ var renderLogoWithEnvPanel = (envName, env, defaultMode) => {
3029
3104
  const parsed = new URL(url);
3030
3105
  const protocol = parsed.protocol + "//";
3031
3106
  const host = parsed.host;
3032
- const path17 = parsed.pathname + parsed.search;
3107
+ const path18 = parsed.pathname + parsed.search;
3033
3108
  const hostStart = host.slice(0, 8);
3034
3109
  const hostEnd = host.slice(-4);
3035
- const pathPart = path17.length > 10 ? path17.slice(0, 7) + "..." : path17;
3110
+ const pathPart = path18.length > 10 ? path18.slice(0, 7) + "..." : path18;
3036
3111
  return `${protocol}${hostStart}...${hostEnd}${pathPart}`;
3037
3112
  } catch {
3038
3113
  return truncate(url, max);
@@ -3470,45 +3545,45 @@ var selectEnvWithKeys = (registries, current) => {
3470
3545
  };
3471
3546
 
3472
3547
  // src/permissions.ts
3473
- import fs11 from "fs";
3548
+ import fs12 from "fs";
3474
3549
  import chalk3 from "chalk";
3475
3550
  import Table2 from "cli-table3";
3476
3551
 
3477
3552
  // src/utils.ts
3478
3553
  import crypto3 from "crypto";
3479
- import fs8 from "fs";
3480
- import path8 from "path";
3554
+ import fs9 from "fs";
3555
+ import path9 from "path";
3481
3556
  var SECRET_KEY = crypto3.scryptSync("claude-code-env-manager-secret", "salt", 32);
3482
3557
  var findProjectRoot = () => {
3483
3558
  let currentDir = process.cwd();
3484
- const root = path8.parse(currentDir).root;
3559
+ const root = path9.parse(currentDir).root;
3485
3560
  while (currentDir !== root) {
3486
- if (fs8.existsSync(path8.join(currentDir, ".git")) || fs8.existsSync(path8.join(currentDir, "package.json"))) {
3561
+ if (fs9.existsSync(path9.join(currentDir, ".git")) || fs9.existsSync(path9.join(currentDir, "package.json"))) {
3487
3562
  return currentDir;
3488
3563
  }
3489
- currentDir = path8.dirname(currentDir);
3564
+ currentDir = path9.dirname(currentDir);
3490
3565
  }
3491
3566
  return process.cwd();
3492
3567
  };
3493
3568
  var getSettingsPath = (useLocal = true) => {
3494
3569
  const projectRoot = findProjectRoot();
3495
- const claudeDir = path8.join(projectRoot, ".claude");
3570
+ const claudeDir = path9.join(projectRoot, ".claude");
3496
3571
  const filename = useLocal ? "settings.local.json" : "settings.json";
3497
- return path8.join(claudeDir, filename);
3572
+ return path9.join(claudeDir, filename);
3498
3573
  };
3499
3574
  var ensureClaudeDir = () => {
3500
3575
  const projectRoot = findProjectRoot();
3501
- const claudeDir = path8.join(projectRoot, ".claude");
3502
- if (!fs8.existsSync(claudeDir)) {
3503
- fs8.mkdirSync(claudeDir, { recursive: true });
3576
+ const claudeDir = path9.join(projectRoot, ".claude");
3577
+ if (!fs9.existsSync(claudeDir)) {
3578
+ fs9.mkdirSync(claudeDir, { recursive: true });
3504
3579
  }
3505
3580
  return claudeDir;
3506
3581
  };
3507
3582
  var getGlobalClaudeConfigPath = () => {
3508
- return path8.join(getCcemAgentHome("claude"), ".claude.json");
3583
+ return path9.join(getCcemAgentHome("claude"), ".claude.json");
3509
3584
  };
3510
3585
  var getGlobalClaudeSettingsPath = () => {
3511
- return path8.join(getCcemAgentHome("claude"), "settings.json");
3586
+ return path9.join(getCcemAgentHome("claude"), "settings.json");
3512
3587
  };
3513
3588
  var ensureGlobalClaudeDir = () => {
3514
3589
  return ensureCcemAgentHome("claude");
@@ -3516,16 +3591,16 @@ var ensureGlobalClaudeDir = () => {
3516
3591
 
3517
3592
  // src/launcher.ts
3518
3593
  import { spawn as spawn2 } from "child_process";
3519
- import * as fs10 from "fs";
3520
- import * as path10 from "path";
3594
+ import * as fs11 from "fs";
3595
+ import * as path11 from "path";
3521
3596
  import chalk2 from "chalk";
3522
3597
 
3523
3598
  // src/sessionProvenance.ts
3524
3599
  import { execFileSync as execFileSync2 } from "child_process";
3525
- import fs9 from "fs";
3600
+ import fs10 from "fs";
3526
3601
  import { createRequire } from "module";
3527
3602
  import os4 from "os";
3528
- import path9 from "path";
3603
+ import path10 from "path";
3529
3604
  var DEFAULT_CONFIG_SOURCE = "ccem";
3530
3605
  var STATE_DB_FILE_NAME = "state.sqlite";
3531
3606
  var BIND_POLL_INTERVAL_MS = 500;
@@ -3580,7 +3655,7 @@ function startCliClaudeProvenanceTracking(options) {
3580
3655
  if (!jsonlPath) {
3581
3656
  return;
3582
3657
  }
3583
- const sourceSessionId = readClaudeSessionId(jsonlPath) ?? normalizeText(path9.parse(jsonlPath).name);
3658
+ const sourceSessionId = readClaudeSessionId(jsonlPath) ?? normalizeText(path10.parse(jsonlPath).name);
3584
3659
  if (!sourceSessionId) {
3585
3660
  return;
3586
3661
  }
@@ -3707,7 +3782,7 @@ function bindSourceSessionId(client, ccemSessionId, sourceSessionId) {
3707
3782
  }
3708
3783
  function openNodeSqliteDb(DatabaseSync) {
3709
3784
  const dbPath = getStateDbPath();
3710
- fs9.mkdirSync(path9.dirname(dbPath), { recursive: true });
3785
+ fs10.mkdirSync(path10.dirname(dbPath), { recursive: true });
3711
3786
  const db = new DatabaseSync(dbPath);
3712
3787
  db.exec(schemaSql());
3713
3788
  return db;
@@ -3748,7 +3823,7 @@ function execSqlite3Cli(statementSql) {
3748
3823
  throw new Error("sqlite3 CLI is unavailable and node:sqlite is not supported by this Node runtime");
3749
3824
  }
3750
3825
  const dbPath = getStateDbPath();
3751
- fs9.mkdirSync(path9.dirname(dbPath), { recursive: true });
3826
+ fs10.mkdirSync(path10.dirname(dbPath), { recursive: true });
3752
3827
  execFileSync2("sqlite3", [dbPath], {
3753
3828
  input: `${schemaSql()}
3754
3829
  ${statementSql}
@@ -3761,7 +3836,7 @@ function getStateDbPath() {
3761
3836
  if (override) {
3762
3837
  return override;
3763
3838
  }
3764
- return path9.join(os4.homedir(), ".ccem", STATE_DB_FILE_NAME);
3839
+ return path10.join(os4.homedir(), ".ccem", STATE_DB_FILE_NAME);
3765
3840
  }
3766
3841
  function schemaSql() {
3767
3842
  return `
@@ -3787,16 +3862,16 @@ function schemaSql() {
3787
3862
  `;
3788
3863
  }
3789
3864
  function discoverClaudeJsonlPath(projectDir, startedAtMs) {
3790
- const projectsDir = path9.join(getCcemAgentHome("claude"), "projects");
3865
+ const projectsDir = path10.join(getCcemAgentHome("claude"), "projects");
3791
3866
  const earliestModifiedAt = startedAtMs - 15e3;
3792
3867
  for (const key of projectDirKeys(projectDir)) {
3793
- const baseDir = path9.join(projectsDir, key);
3794
- if (!fs9.existsSync(baseDir)) {
3868
+ const baseDir = path10.join(projectsDir, key);
3869
+ if (!fs10.existsSync(baseDir)) {
3795
3870
  continue;
3796
3871
  }
3797
- const candidates = fs9.readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => {
3798
- const fullPath = path9.join(baseDir, entry.name);
3799
- return { path: fullPath, modifiedAt: fs9.statSync(fullPath).mtimeMs };
3872
+ const candidates = fs10.readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => {
3873
+ const fullPath = path10.join(baseDir, entry.name);
3874
+ return { path: fullPath, modifiedAt: fs10.statSync(fullPath).mtimeMs };
3800
3875
  }).filter((candidate) => candidate.modifiedAt >= earliestModifiedAt).sort((left, right) => right.modifiedAt - left.modifiedAt);
3801
3876
  if (candidates.length > 0) {
3802
3877
  return candidates[0].path;
@@ -3807,16 +3882,16 @@ function discoverClaudeJsonlPath(projectDir, startedAtMs) {
3807
3882
  function projectDirKeys(projectDir) {
3808
3883
  const candidates = [projectDir];
3809
3884
  try {
3810
- candidates.push(fs9.realpathSync(projectDir));
3885
+ candidates.push(fs10.realpathSync(projectDir));
3811
3886
  } catch {
3812
3887
  }
3813
3888
  if (process.platform === "darwin") {
3814
3889
  if (projectDir.startsWith("/private/")) {
3815
3890
  candidates.push(projectDir.slice("/private".length));
3816
3891
  } else if (projectDir.startsWith("/tmp")) {
3817
- candidates.push(path9.posix.join("/private", projectDir));
3892
+ candidates.push(path10.posix.join("/private", projectDir));
3818
3893
  } else if (projectDir.startsWith("/var/")) {
3819
- candidates.push(path9.posix.join("/private", projectDir));
3894
+ candidates.push(path10.posix.join("/private", projectDir));
3820
3895
  }
3821
3896
  }
3822
3897
  return [...new Set(candidates.map(projectDirKey))];
@@ -3825,7 +3900,7 @@ function projectDirKey(projectDir) {
3825
3900
  return projectDir.replace(/[\/\\: ]/g, "-");
3826
3901
  }
3827
3902
  function readClaudeSessionId(jsonlPath) {
3828
- const lines = fs9.readFileSync(jsonlPath, "utf8").split("\n");
3903
+ const lines = fs10.readFileSync(jsonlPath, "utf8").split("\n");
3829
3904
  for (const line of lines) {
3830
3905
  if (!line.trim()) {
3831
3906
  continue;
@@ -3900,9 +3975,9 @@ function buildPermArgs(modeName) {
3900
3975
  return args;
3901
3976
  }
3902
3977
  function ensureSessionsDir() {
3903
- const dir = path10.join(ensureCcemDir(), "sessions");
3904
- if (!fs10.existsSync(dir)) {
3905
- fs10.mkdirSync(dir, { recursive: true });
3978
+ const dir = path11.join(ensureCcemDir(), "sessions");
3979
+ if (!fs11.existsSync(dir)) {
3980
+ fs11.mkdirSync(dir, { recursive: true });
3906
3981
  }
3907
3982
  return dir;
3908
3983
  }
@@ -3973,8 +4048,8 @@ async function launchClaude(options) {
3973
4048
  provenanceTracking?.stop();
3974
4049
  if (sessionId) {
3975
4050
  try {
3976
- fs10.writeFileSync(
3977
- path10.join(sessionsDir, `${sessionId}.exit`),
4051
+ fs11.writeFileSync(
4052
+ path11.join(sessionsDir, `${sessionId}.exit`),
3978
4053
  String(code ?? 0)
3979
4054
  );
3980
4055
  } catch {
@@ -4044,14 +4119,14 @@ var formatPermissionRulesForDisplay = (rules) => {
4044
4119
  }).join("\n");
4045
4120
  };
4046
4121
  var readSettings = (settingsPath) => {
4047
- if (fs11.existsSync(settingsPath)) {
4122
+ if (fs12.existsSync(settingsPath)) {
4048
4123
  try {
4049
- const content = fs11.readFileSync(settingsPath, "utf-8");
4124
+ const content = fs12.readFileSync(settingsPath, "utf-8");
4050
4125
  return JSON.parse(content);
4051
4126
  } catch {
4052
4127
  console.warn(chalk3.yellow(`\u8B66\u544A: \u65E0\u6CD5\u89E3\u6790 ${settingsPath}\uFF0C\u5C06\u521B\u5EFA\u5907\u4EFD`));
4053
4128
  const backupPath = settingsPath + ".error." + Date.now();
4054
- fs11.copyFileSync(settingsPath, backupPath);
4129
+ fs12.copyFileSync(settingsPath, backupPath);
4055
4130
  console.log(chalk3.gray(`\u5907\u4EFD\u5DF2\u4FDD\u5B58\u5230: ${backupPath}`));
4056
4131
  return {};
4057
4132
  }
@@ -4060,7 +4135,7 @@ var readSettings = (settingsPath) => {
4060
4135
  };
4061
4136
  var writeSettings = (settingsPath, config3) => {
4062
4137
  ensureClaudeDir();
4063
- fs11.writeFileSync(settingsPath, JSON.stringify(config3, null, 2) + "\n");
4138
+ fs12.writeFileSync(settingsPath, JSON.stringify(config3, null, 2) + "\n");
4064
4139
  };
4065
4140
  var mergePermissions = (existing, preset) => {
4066
4141
  const existingAllow = normalizePermissionAllowRules(existing.permissions?.allow || []);
@@ -4093,14 +4168,14 @@ var applyPermissionMode = (modeName) => {
4093
4168
  };
4094
4169
  var resetPermissions = () => {
4095
4170
  const settingsPath = getSettingsPath(true);
4096
- if (!fs11.existsSync(settingsPath)) {
4171
+ if (!fs12.existsSync(settingsPath)) {
4097
4172
  console.log(chalk3.yellow("\u6CA1\u6709\u81EA\u5B9A\u4E49\u6743\u9650\u914D\u7F6E\u9700\u8981\u91CD\u7F6E"));
4098
4173
  return;
4099
4174
  }
4100
4175
  const config3 = readSettings(settingsPath);
4101
4176
  delete config3.permissions;
4102
4177
  if (Object.keys(config3).length === 0) {
4103
- fs11.unlinkSync(settingsPath);
4178
+ fs12.unlinkSync(settingsPath);
4104
4179
  console.log(chalk3.green("\u5DF2\u5220\u9664\u914D\u7F6E\u6587\u4EF6\uFF08\u6587\u4EF6\u4E3A\u7A7A\uFF09"));
4105
4180
  } else {
4106
4181
  writeSettings(settingsPath, config3);
@@ -4110,7 +4185,7 @@ var resetPermissions = () => {
4110
4185
  };
4111
4186
  var showCurrentMode = () => {
4112
4187
  const settingsPath = getSettingsPath(true);
4113
- if (!fs11.existsSync(settingsPath)) {
4188
+ if (!fs12.existsSync(settingsPath)) {
4114
4189
  console.log(chalk3.yellow("\u672A\u914D\u7F6E\u81EA\u5B9A\u4E49\u6743\u9650"));
4115
4190
  console.log(chalk3.gray(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${settingsPath}`));
4116
4191
  return;
@@ -4169,14 +4244,14 @@ var runWithTempPermissions = async (modeName, envConfig, envName) => {
4169
4244
  };
4170
4245
 
4171
4246
  // src/environmentMutations.ts
4172
- import fs12 from "fs";
4173
- import path11 from "path";
4247
+ import fs13 from "fs";
4248
+ import path12 from "path";
4174
4249
  function nativeRuntimeStatePath() {
4175
- return path11.join(getCcemConfigDir(), "native-runtime-state.json");
4250
+ return path12.join(getCcemConfigDir(), "native-runtime-state.json");
4176
4251
  }
4177
4252
  function resolveMutationAuthority(options) {
4178
- const descriptorExists = options.descriptorExists ?? (() => fs12.existsSync(getDesktopControlDescriptorPath()));
4179
- const stateExists = options.stateExists ?? (() => fs12.existsSync(nativeRuntimeStatePath()));
4253
+ const descriptorExists = options.descriptorExists ?? (() => fs13.existsSync(getDesktopControlDescriptorPath()));
4254
+ const stateExists = options.stateExists ?? (() => fs13.existsSync(nativeRuntimeStatePath()));
4180
4255
  return { descriptorExists, stateExists };
4181
4256
  }
4182
4257
  function assertOfflineMutationIsSafe(name, stateExists) {
@@ -4276,13 +4351,13 @@ function deleteEnvironmentFromConfig(config3, name) {
4276
4351
  }
4277
4352
 
4278
4353
  // src/setup.ts
4279
- import fs13 from "fs";
4354
+ import fs14 from "fs";
4280
4355
  import chalk4 from "chalk";
4281
4356
  import { spawn as spawn3 } from "child_process";
4282
4357
  var readJsonFile = (filePath) => {
4283
- if (fs13.existsSync(filePath)) {
4358
+ if (fs14.existsSync(filePath)) {
4284
4359
  try {
4285
- const content = fs13.readFileSync(filePath, "utf-8");
4360
+ const content = fs14.readFileSync(filePath, "utf-8");
4286
4361
  return JSON.parse(content);
4287
4362
  } catch {
4288
4363
  console.warn(chalk4.yellow(`\u8B66\u544A: \u65E0\u6CD5\u89E3\u6790 ${filePath}`));
@@ -4292,7 +4367,7 @@ var readJsonFile = (filePath) => {
4292
4367
  return {};
4293
4368
  };
4294
4369
  var writeJsonFile = (filePath, data) => {
4295
- fs13.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n");
4370
+ fs14.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n");
4296
4371
  };
4297
4372
  var setupOnboarding = () => {
4298
4373
  const configPath = getGlobalClaudeConfigPath();
@@ -4421,8 +4496,8 @@ var runSetupInit = async (options = {}) => {
4421
4496
 
4422
4497
  // src/skills.ts
4423
4498
  import { execFileSync as execFileSync3 } from "child_process";
4424
- import * as fs14 from "fs";
4425
- import * as path12 from "path";
4499
+ import * as fs15 from "fs";
4500
+ import * as path13 from "path";
4426
4501
  import chalk5 from "chalk";
4427
4502
  var SKILL_GROUPS = {
4428
4503
  official: { label: "\u5B98\u65B9", icon: "\u{1F3E2}" },
@@ -4658,7 +4733,7 @@ function parseGitHubUrl(url) {
4658
4733
  repo,
4659
4734
  branch,
4660
4735
  repoPath,
4661
- repoPath ? path12.basename(repoPath) : repo
4736
+ repoPath ? path13.basename(repoPath) : repo
4662
4737
  );
4663
4738
  return { owner, repo, branch, path: repoPath };
4664
4739
  } catch {
@@ -4666,12 +4741,12 @@ function parseGitHubUrl(url) {
4666
4741
  }
4667
4742
  }
4668
4743
  function getSkillsDir() {
4669
- return path12.join(process.cwd(), ".claude", "skills");
4744
+ return path13.join(process.cwd(), ".claude", "skills");
4670
4745
  }
4671
4746
  function ensureSkillsDir() {
4672
4747
  const skillsDir = getSkillsDir();
4673
- if (!fs14.existsSync(skillsDir)) {
4674
- fs14.mkdirSync(skillsDir, { recursive: true });
4748
+ if (!fs15.existsSync(skillsDir)) {
4749
+ fs15.mkdirSync(skillsDir, { recursive: true });
4675
4750
  } else {
4676
4751
  cleanupTempDirs(skillsDir);
4677
4752
  }
@@ -4679,11 +4754,11 @@ function ensureSkillsDir() {
4679
4754
  }
4680
4755
  function cleanupTempDirs(skillsDir) {
4681
4756
  try {
4682
- const entries = fs14.readdirSync(skillsDir, { withFileTypes: true });
4757
+ const entries = fs15.readdirSync(skillsDir, { withFileTypes: true });
4683
4758
  for (const entry of entries) {
4684
4759
  if (entry.isDirectory() && entry.name.startsWith(".tmp-")) {
4685
- const tmpPath = path12.join(skillsDir, entry.name);
4686
- fs14.rmSync(tmpPath, { recursive: true });
4760
+ const tmpPath = path13.join(skillsDir, entry.name);
4761
+ fs15.rmSync(tmpPath, { recursive: true });
4687
4762
  }
4688
4763
  }
4689
4764
  } catch {
@@ -4694,27 +4769,27 @@ function downloadSkillWithGit(owner, repo, branch, repoPath, targetName) {
4694
4769
  try {
4695
4770
  validateGitHubInstallParts(owner, repo, branch, repoPath, targetName);
4696
4771
  const skillsDir = ensureSkillsDir();
4697
- const targetDir = path12.join(skillsDir, targetName);
4698
- if (fs14.existsSync(targetDir)) {
4772
+ const targetDir = path13.join(skillsDir, targetName);
4773
+ if (fs15.existsSync(targetDir)) {
4699
4774
  console.log(chalk5.yellow(`Skill "${targetName}" already exists. Updating...`));
4700
- fs14.rmSync(targetDir, { recursive: true });
4775
+ fs15.rmSync(targetDir, { recursive: true });
4701
4776
  }
4702
4777
  const repoUrl = `https://github.com/${owner}/${repo}.git`;
4703
- tempDir = path12.join(skillsDir, `.tmp-${Date.now()}`);
4704
- fs14.mkdirSync(tempDir, { recursive: true });
4778
+ tempDir = path13.join(skillsDir, `.tmp-${Date.now()}`);
4779
+ fs15.mkdirSync(tempDir, { recursive: true });
4705
4780
  execFileSync3("git", ["init"], { cwd: tempDir, stdio: "pipe" });
4706
4781
  execFileSync3("git", ["remote", "add", "origin", repoUrl], { cwd: tempDir, stdio: "pipe" });
4707
4782
  execFileSync3("git", ["config", "core.sparseCheckout", "true"], { cwd: tempDir, stdio: "pipe" });
4708
- const sparseFile = path12.join(tempDir, ".git", "info", "sparse-checkout");
4709
- fs14.mkdirSync(path12.dirname(sparseFile), { recursive: true });
4710
- fs14.writeFileSync(sparseFile, repoPath ? `${repoPath}/
4783
+ const sparseFile = path13.join(tempDir, ".git", "info", "sparse-checkout");
4784
+ fs15.mkdirSync(path13.dirname(sparseFile), { recursive: true });
4785
+ fs15.writeFileSync(sparseFile, repoPath ? `${repoPath}/
4711
4786
  ` : "*\n");
4712
4787
  execFileSync3("git", ["pull", "--depth=1", "origin", branch], {
4713
4788
  cwd: tempDir,
4714
4789
  stdio: "pipe"
4715
4790
  });
4716
- const sourceDir = repoPath ? path12.join(tempDir, repoPath) : tempDir;
4717
- if (!fs14.existsSync(sourceDir)) {
4791
+ const sourceDir = repoPath ? path13.join(tempDir, repoPath) : tempDir;
4792
+ if (!fs15.existsSync(sourceDir)) {
4718
4793
  throw new Error(`Path "${repoPath}" not found in repository`);
4719
4794
  }
4720
4795
  copyDir(sourceDir, targetDir);
@@ -4725,31 +4800,31 @@ function downloadSkillWithGit(owner, repo, branch, repoPath, targetName) {
4725
4800
  console.error(chalk5.red(`Failed to download skill: ${errMsg}`));
4726
4801
  return false;
4727
4802
  } finally {
4728
- if (tempDir && fs14.existsSync(tempDir)) {
4729
- fs14.rmSync(tempDir, { recursive: true });
4803
+ if (tempDir && fs15.existsSync(tempDir)) {
4804
+ fs15.rmSync(tempDir, { recursive: true });
4730
4805
  }
4731
4806
  }
4732
4807
  }
4733
4808
  function copyDir(src, dest) {
4734
- fs14.mkdirSync(dest, { recursive: true });
4735
- const entries = fs14.readdirSync(src, { withFileTypes: true });
4809
+ fs15.mkdirSync(dest, { recursive: true });
4810
+ const entries = fs15.readdirSync(src, { withFileTypes: true });
4736
4811
  for (const entry of entries) {
4737
4812
  if (entry.name === ".git") continue;
4738
- const srcPath = path12.join(src, entry.name);
4739
- const destPath = path12.join(dest, entry.name);
4813
+ const srcPath = path13.join(src, entry.name);
4814
+ const destPath = path13.join(dest, entry.name);
4740
4815
  if (entry.isDirectory()) {
4741
4816
  copyDir(srcPath, destPath);
4742
4817
  } else {
4743
- fs14.copyFileSync(srcPath, destPath);
4818
+ fs15.copyFileSync(srcPath, destPath);
4744
4819
  }
4745
4820
  }
4746
4821
  }
4747
4822
  function isSafeSkillName(name) {
4748
- return name.trim().length > 0 && name !== "." && name !== ".." && !name.startsWith(".") && !path12.isAbsolute(name) && !name.includes("/") && !name.includes("\\") && !name.includes("\0");
4823
+ return name.trim().length > 0 && name !== "." && name !== ".." && !name.startsWith(".") && !path13.isAbsolute(name) && !name.includes("/") && !name.includes("\\") && !name.includes("\0");
4749
4824
  }
4750
4825
  function isPathInside(childPath, parentPath) {
4751
- const relativePath = path12.relative(parentPath, childPath);
4752
- return relativePath === "" || relativePath.length > 0 && !relativePath.startsWith("..") && !path12.isAbsolute(relativePath);
4826
+ const relativePath = path13.relative(parentPath, childPath);
4827
+ return relativePath === "" || relativePath.length > 0 && !relativePath.startsWith("..") && !path13.isAbsolute(relativePath);
4753
4828
  }
4754
4829
  function addSkillFromGitHub(urlOrPreset) {
4755
4830
  const preset = SKILL_PRESETS.find((p) => p.name === urlOrPreset);
@@ -4793,7 +4868,7 @@ function addSkillFromGitHub(urlOrPreset) {
4793
4868
  }
4794
4869
  let skillName;
4795
4870
  if (parsed.path) {
4796
- skillName = path12.basename(parsed.path);
4871
+ skillName = path13.basename(parsed.path);
4797
4872
  } else {
4798
4873
  skillName = parsed.repo;
4799
4874
  }
@@ -4807,13 +4882,13 @@ function addSkillFromGitHub(urlOrPreset) {
4807
4882
  }
4808
4883
  function listInstalledSkills() {
4809
4884
  const skillsDir = getSkillsDir();
4810
- if (!fs14.existsSync(skillsDir)) {
4885
+ if (!fs15.existsSync(skillsDir)) {
4811
4886
  return [];
4812
4887
  }
4813
- const entries = fs14.readdirSync(skillsDir, { withFileTypes: true });
4888
+ const entries = fs15.readdirSync(skillsDir, { withFileTypes: true });
4814
4889
  return entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => ({
4815
4890
  name: entry.name,
4816
- path: path12.join(skillsDir, entry.name)
4891
+ path: path13.join(skillsDir, entry.name)
4817
4892
  }));
4818
4893
  }
4819
4894
  function removeSkill(name) {
@@ -4822,18 +4897,18 @@ function removeSkill(name) {
4822
4897
  return false;
4823
4898
  }
4824
4899
  const skillsDir = getSkillsDir();
4825
- const targetDir = path12.resolve(skillsDir, name);
4826
- if (!fs14.existsSync(targetDir)) {
4900
+ const targetDir = path13.resolve(skillsDir, name);
4901
+ if (!fs15.existsSync(targetDir)) {
4827
4902
  console.error(chalk5.red(`Skill "${name}" not found`));
4828
4903
  return false;
4829
4904
  }
4830
- const canonicalSkillsDir = fs14.realpathSync(skillsDir);
4831
- const canonicalTargetDir = fs14.realpathSync(targetDir);
4905
+ const canonicalSkillsDir = fs15.realpathSync(skillsDir);
4906
+ const canonicalTargetDir = fs15.realpathSync(targetDir);
4832
4907
  if (!isPathInside(canonicalTargetDir, canonicalSkillsDir)) {
4833
4908
  console.error(chalk5.red(`Refusing to remove skill outside skills directory: "${name}"`));
4834
4909
  return false;
4835
4910
  }
4836
- fs14.rmSync(targetDir, { recursive: true });
4911
+ fs15.rmSync(targetDir, { recursive: true });
4837
4912
  console.log(chalk5.green(`Removed skill "${name}"`));
4838
4913
  return true;
4839
4914
  }
@@ -5388,9 +5463,9 @@ import Table3 from "cli-table3";
5388
5463
 
5389
5464
  // src/cron.ts
5390
5465
  import crypto5 from "crypto";
5391
- import * as fs15 from "fs";
5466
+ import * as fs16 from "fs";
5392
5467
  import * as os5 from "os";
5393
- import * as path13 from "path";
5468
+ import * as path14 from "path";
5394
5469
  function parseHermesNotification(value) {
5395
5470
  if (value == null) return null;
5396
5471
  const target = value;
@@ -5454,13 +5529,13 @@ var EXECUTION_PROFILES = /* @__PURE__ */ new Set([
5454
5529
  "autonomous"
5455
5530
  ]);
5456
5531
  function getCronTasksPath(baseDir = getCcemConfigDir()) {
5457
- return path13.join(baseDir, CRON_TASKS_FILE_NAME);
5532
+ return path14.join(baseDir, CRON_TASKS_FILE_NAME);
5458
5533
  }
5459
5534
  function readCronTasks(tasksPath = getCronTasksPath()) {
5460
- if (!fs15.existsSync(tasksPath)) {
5535
+ if (!fs16.existsSync(tasksPath)) {
5461
5536
  return [];
5462
5537
  }
5463
- const content = fs15.readFileSync(tasksPath, "utf-8").trim();
5538
+ const content = fs16.readFileSync(tasksPath, "utf-8").trim();
5464
5539
  if (!content) {
5465
5540
  return [];
5466
5541
  }
@@ -5475,14 +5550,14 @@ function writeCronTasks(tasks, tasksPath = getCronTasksPath()) {
5475
5550
  if (tasksPath === getCronTasksPath()) {
5476
5551
  ensureCcemDir();
5477
5552
  } else {
5478
- fs15.mkdirSync(path13.dirname(tasksPath), { recursive: true });
5553
+ fs16.mkdirSync(path14.dirname(tasksPath), { recursive: true });
5479
5554
  }
5480
5555
  const payload = { tasks };
5481
5556
  const content = `${JSON.stringify(payload, null, 2)}
5482
5557
  `;
5483
5558
  const tempPath = `${tasksPath}.${process.pid}.${Date.now()}.tmp`;
5484
- fs15.writeFileSync(tempPath, content, { encoding: "utf-8", mode: 384 });
5485
- fs15.renameSync(tempPath, tasksPath);
5559
+ fs16.writeFileSync(tempPath, content, { encoding: "utf-8", mode: 384 });
5560
+ fs16.renameSync(tempPath, tasksPath);
5486
5561
  }
5487
5562
  function validateCronExpression(cronExpression) {
5488
5563
  const fields = cronExpression.trim().split(/\s+/);
@@ -5609,10 +5684,10 @@ function deleteCronTask(selector, tasksPath = getCronTasksPath()) {
5609
5684
  }
5610
5685
  function resolveJsonInput(raw) {
5611
5686
  if (raw === "-") {
5612
- return fs15.readFileSync(0, "utf-8");
5687
+ return fs16.readFileSync(0, "utf-8");
5613
5688
  }
5614
5689
  if (raw.startsWith("@")) {
5615
- return fs15.readFileSync(path13.resolve(raw.slice(1)), "utf-8");
5690
+ return fs16.readFileSync(path14.resolve(raw.slice(1)), "utf-8");
5616
5691
  }
5617
5692
  return raw;
5618
5693
  }
@@ -5757,7 +5832,7 @@ function registerCronCommands(program2) {
5757
5832
  import chalk8 from "chalk";
5758
5833
 
5759
5834
  // src/dsh/provider.ts
5760
- import { createHash as createHash2 } from "crypto";
5835
+ import { createHash as createHash3 } from "crypto";
5761
5836
  var DSH_API_KEY_ENV = "CCEM_DSH_API_KEY";
5762
5837
  var DSH_PROTOCOL = "anthropic-messages";
5763
5838
  var DSH_TIERS = ["opus", "sonnet", "haiku"];
@@ -5800,7 +5875,7 @@ function collectDshModels(envName, envConfig) {
5800
5875
  }
5801
5876
  function generateProviderId(envName) {
5802
5877
  const slug = envName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24) || "env";
5803
- const hash = createHash2("sha256").update(envName).digest("hex").slice(0, 12);
5878
+ const hash = createHash3("sha256").update(envName).digest("hex").slice(0, 12);
5804
5879
  return `ccem-${slug}-${hash}`;
5805
5880
  }
5806
5881
  function verifyTokenPresence(envConfig) {
@@ -5889,9 +5964,9 @@ function deriveDshProvider(envName, envConfig, options = {}) {
5889
5964
 
5890
5965
  // src/dsh/launcher.ts
5891
5966
  import { spawn as defaultSpawn } from "child_process";
5892
- import * as fs17 from "fs";
5967
+ import * as fs18 from "fs";
5893
5968
  import * as os7 from "os";
5894
- import * as path15 from "path";
5969
+ import * as path16 from "path";
5895
5970
 
5896
5971
  // src/dsh/patch.ts
5897
5972
  var IDENTIFIER_PATTERN = /^[A-Za-z0-9][\w./-]*$/;
@@ -5929,9 +6004,9 @@ function renderCordisPatch(spec) {
5929
6004
 
5930
6005
  // src/dsh/environment.ts
5931
6006
  import { execFile } from "child_process";
5932
- import * as fs16 from "fs";
6007
+ import * as fs17 from "fs";
5933
6008
  import * as os6 from "os";
5934
- import * as path14 from "path";
6009
+ import * as path15 from "path";
5935
6010
  import { promisify } from "util";
5936
6011
 
5937
6012
  // src/dsh/version.ts
@@ -6002,17 +6077,17 @@ function resolveDshRoot(env = process.env) {
6002
6077
  const inherited = env.DSH_HOME?.trim();
6003
6078
  if (inherited) return inherited;
6004
6079
  const home = env.HOME?.trim() || os6.homedir();
6005
- return path14.join(home, ".dsh");
6080
+ return path15.join(home, ".dsh");
6006
6081
  }
6007
6082
  function resolveBinOnPath(name, env = process.env, platform = process.platform) {
6008
6083
  if (name.includes("/") || platform === "win32" && name.includes("\\")) {
6009
6084
  return fileIsExecutable(name, platform) ? name : null;
6010
6085
  }
6011
- const searchDirs = (env.PATH ?? "").split(path14.delimiter).filter(Boolean);
6086
+ const searchDirs = (env.PATH ?? "").split(path15.delimiter).filter(Boolean);
6012
6087
  const extensions = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").toLowerCase().split(";").filter(Boolean) : [""];
6013
6088
  for (const dir of searchDirs) {
6014
6089
  for (const ext of extensions) {
6015
- const candidate = path14.join(dir, name + ext);
6090
+ const candidate = path15.join(dir, name + ext);
6016
6091
  if (fileIsExecutable(candidate, platform)) return candidate;
6017
6092
  }
6018
6093
  }
@@ -6021,10 +6096,10 @@ function resolveBinOnPath(name, env = process.env, platform = process.platform)
6021
6096
  function fileIsExecutable(file, platform = process.platform) {
6022
6097
  try {
6023
6098
  if (platform === "win32") {
6024
- return fs16.statSync(file).isFile();
6099
+ return fs17.statSync(file).isFile();
6025
6100
  }
6026
- fs16.accessSync(file, fs16.constants.X_OK);
6027
- return fs16.statSync(file).isFile();
6101
+ fs17.accessSync(file, fs17.constants.X_OK);
6102
+ return fs17.statSync(file).isFile();
6028
6103
  } catch {
6029
6104
  return false;
6030
6105
  }
@@ -6042,15 +6117,15 @@ function resolveDshInvocation(deps = {}) {
6042
6117
  function resolveWindowsDshInvocation(env) {
6043
6118
  const dshFile = resolveBinOnPath("dsh", env, "win32");
6044
6119
  if (!dshFile) return null;
6045
- const ext = path14.extname(dshFile).toLowerCase();
6120
+ const ext = path15.extname(dshFile).toLowerCase();
6046
6121
  if (ext === ".exe" || ext === ".com") {
6047
6122
  return { bin: dshFile, prefix: [] };
6048
6123
  }
6049
6124
  if (ext !== ".cmd") return null;
6050
- const shimDir = path14.dirname(dshFile);
6125
+ const shimDir = path15.dirname(dshFile);
6051
6126
  const candidates = [
6052
- path14.join(shimDir, "node_modules", "@deepseek-ai", "dsh"),
6053
- path14.join(shimDir, "..", "node_modules", "@deepseek-ai", "dsh")
6127
+ path15.join(shimDir, "node_modules", "@deepseek-ai", "dsh"),
6128
+ path15.join(shimDir, "..", "node_modules", "@deepseek-ai", "dsh")
6054
6129
  ];
6055
6130
  for (const pkgDir of candidates) {
6056
6131
  const entryScript = verifyDshPackage(pkgDir);
@@ -6063,18 +6138,18 @@ function resolveWindowsDshInvocation(env) {
6063
6138
  return null;
6064
6139
  }
6065
6140
  function verifyDshPackage(pkgDir) {
6066
- const pkgJsonPath = path14.join(pkgDir, "package.json");
6141
+ const pkgJsonPath = path15.join(pkgDir, "package.json");
6067
6142
  try {
6068
- const raw = fs16.readFileSync(pkgJsonPath, "utf-8");
6143
+ const raw = fs17.readFileSync(pkgJsonPath, "utf-8");
6069
6144
  const pkg2 = JSON.parse(raw);
6070
6145
  if (pkg2.name !== "@deepseek-ai/dsh") return null;
6071
6146
  const binEntry = typeof pkg2.bin === "string" ? pkg2.bin : pkg2.bin?.dsh ?? null;
6072
6147
  if (!binEntry || typeof binEntry !== "string") return null;
6073
- const entryPath = path14.resolve(pkgDir, binEntry);
6074
- const realEntry = fs16.realpathSync(entryPath);
6075
- const realPkgDir = fs16.realpathSync(pkgDir);
6076
- if (!realEntry.startsWith(realPkgDir + path14.sep) && realEntry !== realPkgDir) return null;
6077
- if (!fs16.statSync(realEntry).isFile()) return null;
6148
+ const entryPath = path15.resolve(pkgDir, binEntry);
6149
+ const realEntry = fs17.realpathSync(entryPath);
6150
+ const realPkgDir = fs17.realpathSync(pkgDir);
6151
+ if (!realEntry.startsWith(realPkgDir + path15.sep) && realEntry !== realPkgDir) return null;
6152
+ if (!fs17.statSync(realEntry).isFile()) return null;
6078
6153
  return realEntry;
6079
6154
  } catch {
6080
6155
  return null;
@@ -6212,7 +6287,7 @@ var DSH_PERMISSION_MODES = [
6212
6287
  ];
6213
6288
  var DSH_PERMISSION_ENV = "DSH_PERMISSION_MODE";
6214
6289
  function cleanupTempDir(dir) {
6215
- fs17.rmSync(dir, { recursive: true, force: true });
6290
+ fs18.rmSync(dir, { recursive: true, force: true });
6216
6291
  }
6217
6292
  function signalExitCode(signal) {
6218
6293
  if (!signal) return 1;
@@ -6317,10 +6392,10 @@ async function runDshTask(options) {
6317
6392
  };
6318
6393
  }
6319
6394
  const inheritedDshHome = env.DSH_HOME?.trim() || void 0;
6320
- const tempDir = fs17.mkdtempSync(path15.join(os7.tmpdir(), "ccem-dsh-"));
6321
- const patchPath = path15.join(tempDir, "cordis.ccem.patch.yml");
6395
+ const tempDir = fs18.mkdtempSync(path16.join(os7.tmpdir(), "ccem-dsh-"));
6396
+ const patchPath = path16.join(tempDir, "cordis.ccem.patch.yml");
6322
6397
  const patchContent = renderCordisPatch(options.spec);
6323
- fs17.writeFileSync(patchPath, patchContent, { mode: 384 });
6398
+ fs18.writeFileSync(patchPath, patchContent, { mode: 384 });
6324
6399
  let exitCode = null;
6325
6400
  let signal = null;
6326
6401
  let spawnError = null;
@@ -6689,9 +6764,9 @@ Note: Use -- to separate task text from options if the task could be
6689
6764
 
6690
6765
  // src/index.ts
6691
6766
  var __filename2 = fileURLToPath2(import.meta.url);
6692
- var __dirname2 = path16.dirname(__filename2);
6693
- var pkgPath = path16.resolve(__dirname2, "..", "package.json");
6694
- var pkg = JSON.parse(fs18.readFileSync(pkgPath, "utf-8"));
6767
+ var __dirname2 = path17.dirname(__filename2);
6768
+ var pkgPath = path17.resolve(__dirname2, "..", "package.json");
6769
+ var pkg = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
6695
6770
  var program = new Command();
6696
6771
  var DEFAULT_OFFICIAL_ENV = {
6697
6772
  ANTHROPIC_BASE_URL: "https://api.anthropic.com",
@@ -6778,11 +6853,11 @@ var recoverRegistriesFromLegacy = (registries) => {
6778
6853
  return registries;
6779
6854
  }
6780
6855
  const legacyConfigPath = getLegacyConfigPath();
6781
- if (!fs18.existsSync(legacyConfigPath)) {
6856
+ if (!fs19.existsSync(legacyConfigPath)) {
6782
6857
  return registries;
6783
6858
  }
6784
6859
  try {
6785
- const legacyRaw = JSON.parse(fs18.readFileSync(legacyConfigPath, "utf-8"));
6860
+ const legacyRaw = JSON.parse(fs19.readFileSync(legacyConfigPath, "utf-8"));
6786
6861
  const legacyRegistries = legacyRaw.registries ?? {};
6787
6862
  let changed2 = false;
6788
6863
  const recovered = { ...registries };
@@ -6985,15 +7060,15 @@ var switchEnvironment = async (name) => {
6985
7060
  exportCmds.forEach((cmd) => console.log(cmd));
6986
7061
  }
6987
7062
  };
6988
- var getSessionsFilePath = () => path16.join(getCcemConfigDir(), "sessions.json");
6989
- var getRuntimeStateFilePath = () => path16.join(getCcemConfigDir(), "runtime-state.json");
6990
- var getBotBindRequestFilePath = () => path16.join(getCcemConfigDir(), "bot-bind-requests.jsonl");
7063
+ var getSessionsFilePath = () => path17.join(getCcemConfigDir(), "sessions.json");
7064
+ var getRuntimeStateFilePath = () => path17.join(getCcemConfigDir(), "runtime-state.json");
7065
+ var getBotBindRequestFilePath = () => path17.join(getCcemConfigDir(), "bot-bind-requests.jsonl");
6991
7066
  var parseJsonFile = (filePath) => {
6992
- if (!fs18.existsSync(filePath)) {
7067
+ if (!fs19.existsSync(filePath)) {
6993
7068
  return null;
6994
7069
  }
6995
7070
  try {
6996
- return JSON.parse(fs18.readFileSync(filePath, "utf-8"));
7071
+ return JSON.parse(fs19.readFileSync(filePath, "utf-8"));
6997
7072
  } catch {
6998
7073
  return null;
6999
7074
  }
@@ -7085,8 +7160,8 @@ var resolveBotBindRuntimeId = (explicitRuntimeId) => {
7085
7160
  };
7086
7161
  var appendBotBindRequest = (payload) => {
7087
7162
  const requestPath = getBotBindRequestFilePath();
7088
- fs18.mkdirSync(path16.dirname(requestPath), { recursive: true });
7089
- fs18.appendFileSync(requestPath, `${JSON.stringify(payload)}
7163
+ fs19.mkdirSync(path17.dirname(requestPath), { recursive: true });
7164
+ fs19.appendFileSync(requestPath, `${JSON.stringify(payload)}
7090
7165
  `, "utf-8");
7091
7166
  return requestPath;
7092
7167
  };
@@ -7389,12 +7464,12 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
7389
7464
  const newConfigPath = getCcemConfigPath();
7390
7465
  const legacyConfigPath = getLegacyConfigPath();
7391
7466
  console.log(chalk9.cyan("\n\u{1F504} \u914D\u7F6E\u8FC1\u79FB\n"));
7392
- if (!fs18.existsSync(legacyConfigPath)) {
7467
+ if (!fs19.existsSync(legacyConfigPath)) {
7393
7468
  console.log(chalk9.yellow("\u672A\u627E\u5230\u65E7\u7248\u914D\u7F6E\u6587\u4EF6"));
7394
7469
  console.log(chalk9.gray(` \u65E7\u8DEF\u5F84: ${legacyConfigPath}`));
7395
7470
  return;
7396
7471
  }
7397
- if (fs18.existsSync(newConfigPath) && !options.force) {
7472
+ if (fs19.existsSync(newConfigPath) && !options.force) {
7398
7473
  console.log(chalk9.green("\u2713 \u914D\u7F6E\u5DF2\u5728\u65B0\u8DEF\u5F84"));
7399
7474
  console.log(chalk9.gray(` \u8DEF\u5F84: ${newConfigPath}`));
7400
7475
  console.log(chalk9.gray("\n\u4F7F\u7528 --force \u5F3A\u5236\u91CD\u65B0\u8FC1\u79FB"));
@@ -7402,7 +7477,7 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
7402
7477
  }
7403
7478
  try {
7404
7479
  ensureCcemDir();
7405
- const legacyRaw = JSON.parse(fs18.readFileSync(legacyConfigPath, "utf-8"));
7480
+ const legacyRaw = JSON.parse(fs19.readFileSync(legacyConfigPath, "utf-8"));
7406
7481
  const migrated = normalizeCcemConfig(legacyRaw);
7407
7482
  if (!migrated.registries[OFFICIAL_ENV_NAME]) {
7408
7483
  migrated.registries[OFFICIAL_ENV_NAME] = { ...DEFAULT_OFFICIAL_ENV };
@@ -7413,10 +7488,10 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
7413
7488
  console.log(chalk9.gray(` \u4ECE: ${legacyConfigPath}`));
7414
7489
  console.log(chalk9.gray(` \u5230: ${newConfigPath}`));
7415
7490
  if (options.clean) {
7416
- fs18.unlinkSync(legacyConfigPath);
7417
- const legacyDir = path16.dirname(legacyConfigPath);
7491
+ fs19.unlinkSync(legacyConfigPath);
7492
+ const legacyDir = path17.dirname(legacyConfigPath);
7418
7493
  try {
7419
- fs18.rmdirSync(legacyDir);
7494
+ fs19.rmdirSync(legacyDir);
7420
7495
  } catch {
7421
7496
  }
7422
7497
  console.log(chalk9.green("\u2713 \u5DF2\u5220\u9664\u65E7\u914D\u7F6E\u6587\u4EF6"));
@@ -7427,13 +7502,13 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
7427
7502
  });
7428
7503
  setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \u7684 Claude Code").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
7429
7504
  const options = this.opts();
7430
- const skillDir = path16.join(ensureCcemAgentHome("claude"), "skills");
7431
- const targetPath = path16.join(skillDir, "ccem-cron.md");
7432
- if (!fs18.existsSync(skillDir)) {
7433
- fs18.mkdirSync(skillDir, { recursive: true });
7505
+ const skillDir = path17.join(ensureCcemAgentHome("claude"), "skills");
7506
+ const targetPath = path17.join(skillDir, "ccem-cron.md");
7507
+ if (!fs19.existsSync(skillDir)) {
7508
+ fs19.mkdirSync(skillDir, { recursive: true });
7434
7509
  console.log(chalk9.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
7435
7510
  }
7436
- if (fs18.existsSync(targetPath) && !options.force) {
7511
+ if (fs19.existsSync(targetPath) && !options.force) {
7437
7512
  const { overwrite } = await inquirer.prompt([
7438
7513
  {
7439
7514
  type: "confirm",
@@ -7447,7 +7522,7 @@ setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \
7447
7522
  return;
7448
7523
  }
7449
7524
  }
7450
- fs18.writeFileSync(targetPath, CCEM_CRON_SKILL_CONTENT, "utf-8");
7525
+ fs19.writeFileSync(targetPath, CCEM_CRON_SKILL_CONTENT, "utf-8");
7451
7526
  console.log(chalk9.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-cron skill`));
7452
7527
  console.log(chalk9.gray(` \u8DEF\u5F84: ${targetPath}`));
7453
7528
  console.log(chalk9.cyan(`
@@ -7455,13 +7530,13 @@ setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \
7455
7530
  });
7456
7531
  setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u5230 CCEM \u7684 Claude Code").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
7457
7532
  const options = this.opts();
7458
- const skillDir = path16.join(ensureCcemAgentHome("claude"), "skills");
7459
- const targetPath = path16.join(skillDir, "ccem-bot-bind.md");
7460
- if (!fs18.existsSync(skillDir)) {
7461
- fs18.mkdirSync(skillDir, { recursive: true });
7533
+ const skillDir = path17.join(ensureCcemAgentHome("claude"), "skills");
7534
+ const targetPath = path17.join(skillDir, "ccem-bot-bind.md");
7535
+ if (!fs19.existsSync(skillDir)) {
7536
+ fs19.mkdirSync(skillDir, { recursive: true });
7462
7537
  console.log(chalk9.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
7463
7538
  }
7464
- if (fs18.existsSync(targetPath) && !options.force) {
7539
+ if (fs19.existsSync(targetPath) && !options.force) {
7465
7540
  const { overwrite } = await inquirer.prompt([
7466
7541
  {
7467
7542
  type: "confirm",
@@ -7475,7 +7550,7 @@ setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u523
7475
7550
  return;
7476
7551
  }
7477
7552
  }
7478
- fs18.writeFileSync(targetPath, CCEM_BOT_BIND_SKILL_CONTENT, "utf-8");
7553
+ fs19.writeFileSync(targetPath, CCEM_BOT_BIND_SKILL_CONTENT, "utf-8");
7479
7554
  console.log(chalk9.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-bot-bind skill`));
7480
7555
  console.log(chalk9.gray(` \u8DEF\u5F84: ${targetPath}`));
7481
7556
  console.log(chalk9.cyan(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccem",
3
- "version": "2.96.0",
3
+ "version": "2.97.0",
4
4
  "type": "module",
5
5
  "description": "Claude Code Environment Manager",
6
6
  "repository": {