@deepstorm/cli 0.2.3 → 0.2.4

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/cli.js +79 -28
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -6996,7 +6996,7 @@ async function runSetup(reader, targetDir, cliDir2, options, registry2) {
6996
6996
  enabledMcpJsonServers = Object.keys(servers);
6997
6997
  console.log(`\u2714 \u5DF2\u5B89\u88C5 ${selectedMcpTools.length} \u4E2A MCP \u670D\u52A1`);
6998
6998
  }
6999
- installMcpSkills(tools, reader, cliDir2, targetDir, installedSkillIds);
6999
+ installMcpSkills(tools, reader, cliDir2, targetDir, installedSkillIds, selectedMcpTools);
7000
7000
  for (const tool of tools) {
7001
7001
  const ids = renderToolAssets(tool, reader, cliDir2, targetDir, templateVariables, config, registry2, selectedMcpTools);
7002
7002
  installedSkillIds.push(...ids);
@@ -7092,7 +7092,7 @@ function shouldSkipAgent(agentFile, config) {
7092
7092
  const value = config[configKey];
7093
7093
  return !value || value === "none";
7094
7094
  }
7095
- function renderToolAssets(tool, reader, cliDir2, targetDir, templateVariables, config, registry2, installedMcpTools = [], targetSubDir = ".claude") {
7095
+ function renderToolAssets(tool, reader, cliDir2, targetDir, templateVariables, config, registry2, installedMcpTools = [], targetSubDir = ".claude", skillIdFilter) {
7096
7096
  const installedSkillIds = [];
7097
7097
  const targetSkillsDir = targetSubDir ? path6.join(targetDir, targetSubDir, "skills") : path6.join(targetDir, "skills");
7098
7098
  const toolSkills = reader.getToolSkills(tool);
@@ -7100,6 +7100,7 @@ function renderToolAssets(tool, reader, cliDir2, targetDir, templateVariables, c
7100
7100
  for (const skill of toolSkills) {
7101
7101
  const skillId = getSkillId(skill, registry2);
7102
7102
  if (!skillId) continue;
7103
+ if (skillIdFilter && !skillIdFilter.has(skillId)) continue;
7103
7104
  if (shouldSkipSkill(skill, config)) {
7104
7105
  console.log(` \u23ED ${skillId}\uFF1A\u4F9D\u8D56 ${skill.configKey} \u672A\u914D\u7F6E\uFF0C\u8DF3\u8FC7`);
7105
7106
  continue;
@@ -7180,14 +7181,21 @@ function renderToolAssets(tool, reader, cliDir2, targetDir, templateVariables, c
7180
7181
  }
7181
7182
  return installedSkillIds;
7182
7183
  }
7183
- function installMcpSkills(tools, reader, cliDir2, targetDir, installedSkillIds) {
7184
+ function installMcpSkills(tools, reader, cliDir2, targetDir, installedSkillIds, selectedMcpTools = []) {
7184
7185
  const mcpSkillsDir = path6.join(cliDir2, "mcp-skills");
7185
7186
  const targetSkillsDir = path6.join(targetDir, ".claude", "skills");
7186
7187
  if (!fs10.existsSync(mcpSkillsDir)) return;
7188
+ if (selectedMcpTools.length === 0) {
7189
+ console.log("\u23ED \u672A\u9009\u62E9 MCP \u670D\u52A1\uFF0C\u8DF3\u8FC7 MCP \u6280\u80FD\u5B89\u88C5");
7190
+ return;
7191
+ }
7192
+ const selectedMcpSet = new Set(selectedMcpTools);
7187
7193
  const neededSkills = /* @__PURE__ */ new Set();
7188
7194
  for (const tool of tools) {
7189
7195
  const toolMcpSkills = reader.getToolMcpSkills(tool);
7190
7196
  for (const skillId of toolMcpSkills) {
7197
+ const service = skillId.replace(/^deepstorm-mcp-/, "").replace(/-(read|write)$/, "");
7198
+ if (!selectedMcpSet.has(service)) continue;
7191
7199
  neededSkills.add(skillId);
7192
7200
  }
7193
7201
  }
@@ -8355,7 +8363,19 @@ function syncToolAssets(cliDir2, targetDir, installedSkillIds) {
8355
8363
  }
8356
8364
  const { config, installedMcpTools } = readSettingsConfig(targetDir);
8357
8365
  const templateVariables = buildTemplateVariables(registry2, config, installedMcpTools);
8358
- const backedUpFiles = backupModifiedAssets(targetDir, installedSkillIds, toolNames, registry2);
8366
+ const mcpSkillSet = /* @__PURE__ */ new Set();
8367
+ if (installedMcpTools.length > 0) {
8368
+ const selectedMcpSet = new Set(installedMcpTools);
8369
+ for (const tool of toolNames) {
8370
+ for (const skillId of reader.getToolMcpSkills(tool)) {
8371
+ const service = skillId.replace(/^deepstorm-mcp-/, "").replace(/-(read|write)$/, "");
8372
+ if (selectedMcpSet.has(service)) mcpSkillSet.add(skillId);
8373
+ }
8374
+ }
8375
+ }
8376
+ const mcpSkillIds = [...mcpSkillSet];
8377
+ const allSkillIdsForBackup = [.../* @__PURE__ */ new Set([...installedSkillIds, ...mcpSkillIds])];
8378
+ const backedUpFiles = backupModifiedAssets(targetDir, allSkillIdsForBackup, toolNames, registry2);
8359
8379
  if (backedUpFiles.length > 0) {
8360
8380
  console.log("\n\u26A0 \u68C0\u6D4B\u5230\u7528\u6237\u4FEE\u6539\u7684\u6587\u4EF6\uFF1A");
8361
8381
  for (const info of backedUpFiles) {
@@ -8396,15 +8416,20 @@ function syncToolAssets(cliDir2, targetDir, installedSkillIds) {
8396
8416
  }
8397
8417
  }
8398
8418
  const syncedSkills = actualSkillIds.length > 0 ? actualSkillIds : [...installedSkillIds];
8419
+ const syncedMcpSkillIds = [];
8420
+ if (installedMcpTools.length > 0) {
8421
+ installMcpSkills(toolNames, reader, cliDir2, targetDir, syncedMcpSkillIds, installedMcpTools);
8422
+ }
8399
8423
  mergeToolHooksJson(toolNames, cliDir2, targetDir);
8400
- storeNewChecksums(targetDir, installedSkillIds, toolNames, registry2);
8424
+ const allSkillIds = [...installedSkillIds, ...syncedMcpSkillIds];
8425
+ storeNewChecksums(targetDir, allSkillIds, toolNames, registry2);
8401
8426
  if (hasWarning) {
8402
8427
  console.log("\n\u26A0 \u90E8\u5206\u5DE5\u5177\u540C\u6B65\u51FA\u9519\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5");
8403
8428
  }
8404
8429
  const uniqueAgents = [...new Set(syncedAgents)];
8405
8430
  const uniqueHooks = [...new Set(syncedHooks)];
8406
8431
  return {
8407
- syncedSkills,
8432
+ syncedSkills: [...syncedSkills, ...syncedMcpSkillIds],
8408
8433
  syncedAgents: uniqueAgents,
8409
8434
  syncedHooks: uniqueHooks,
8410
8435
  backedUpFiles
@@ -8426,12 +8451,33 @@ function upgradeTemplates(cliDir2, targetDir, skillIds) {
8426
8451
 
8427
8452
  // src/commands/update.ts
8428
8453
  var NPM_REGISTRY_URL = "https://registry.npmjs.org/@deepstorm/cli/latest";
8454
+ function getRegistryUrl() {
8455
+ return process.env.DEEPSTORM_REGISTRY_URL || NPM_REGISTRY_URL;
8456
+ }
8457
+ function readLocalRegistryFile(url) {
8458
+ let filePath = url;
8459
+ if (filePath.startsWith("file://")) {
8460
+ filePath = filePath.slice(7);
8461
+ }
8462
+ try {
8463
+ if (fs21.existsSync(filePath)) {
8464
+ return JSON.parse(fs21.readFileSync(filePath, "utf-8"));
8465
+ }
8466
+ } catch {
8467
+ }
8468
+ return null;
8469
+ }
8429
8470
  async function checkNpmVersion(fetchFn = globalThis.fetch) {
8430
8471
  const current = getCliVersion();
8472
+ const url = getRegistryUrl();
8431
8473
  try {
8474
+ const localData = readLocalRegistryFile(url);
8475
+ if (localData) {
8476
+ return parseVersionResponse(localData, current);
8477
+ }
8432
8478
  const controller = new AbortController();
8433
8479
  const timeout = setTimeout(() => controller.abort(), 5e3);
8434
- const response = await fetchFn(NPM_REGISTRY_URL, {
8480
+ const response = await fetchFn(url, {
8435
8481
  signal: controller.signal
8436
8482
  });
8437
8483
  clearTimeout(timeout);
@@ -8439,47 +8485,52 @@ async function checkNpmVersion(fetchFn = globalThis.fetch) {
8439
8485
  return {
8440
8486
  current,
8441
8487
  latest: null,
8442
- error: `npm registry \u8FD4\u56DE\u72B6\u6001\u7801 ${response.status}`
8488
+ error: `registry \u8FD4\u56DE\u72B6\u6001\u7801 ${response.status}`
8443
8489
  };
8444
8490
  }
8445
8491
  const data = await response.json();
8446
- const latest = data.version;
8447
- if (!latest) {
8448
- return {
8449
- current,
8450
- latest: null,
8451
- error: "\u65E0\u6CD5\u89E3\u6790 registry \u54CD\u5E94\u4E2D\u7684\u7248\u672C\u53F7"
8452
- };
8453
- }
8454
- const isUpToDate = current === latest;
8455
- const hasUpdate = !isUpToDate && latest !== null;
8492
+ return parseVersionResponse(data, current);
8493
+ } catch (err) {
8494
+ const message = err instanceof Error ? err.message : String(err);
8495
+ const hint = message.includes("abort") ? "\u8FDE\u63A5\u8D85\u65F6" : message.includes("fetch failed") || message.includes("ECONNREFUSED") || message.includes("ENOTFOUND") ? `\u65E0\u6CD5\u8FDE\u63A5 registry\uFF08${url}\uFF09\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC` : message;
8456
8496
  return {
8457
8497
  current,
8458
- latest,
8459
- isUpToDate,
8460
- hasUpdate
8498
+ latest: null,
8499
+ error: hint
8461
8500
  };
8462
- } catch (err) {
8463
- const message = err instanceof Error ? err.message : String(err);
8501
+ }
8502
+ }
8503
+ function parseVersionResponse(data, current) {
8504
+ const latest = data.version;
8505
+ if (!latest) {
8464
8506
  return {
8465
8507
  current,
8466
8508
  latest: null,
8467
- error: message
8509
+ error: "\u65E0\u6CD5\u89E3\u6790 registry \u54CD\u5E94\u4E2D\u7684\u7248\u672C\u53F7"
8468
8510
  };
8469
8511
  }
8512
+ const isUpToDate = current === latest;
8513
+ const hasUpdate = !isUpToDate && latest !== null;
8514
+ return {
8515
+ current,
8516
+ latest,
8517
+ isUpToDate,
8518
+ hasUpdate
8519
+ };
8470
8520
  }
8471
8521
  async function updateCLI(fetchFn) {
8472
8522
  const result = await checkNpmVersion(fetchFn);
8473
8523
  if (result.error) {
8474
8524
  console.log(`\u26A0 \u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0\uFF1A${result.error}`);
8475
- return;
8525
+ return result;
8476
8526
  }
8477
8527
  console.log(`\u2714 \u5F53\u524D\u7248\u672C: v${result.current}`);
8478
8528
  console.log(`\u2714 \u6700\u65B0\u7248\u672C: v${result.latest}`);
8479
8529
  if (result.hasUpdate) {
8480
8530
  console.log("\u2192 \u6B63\u5728\u81EA\u52A8\u66F4\u65B0...");
8531
+ const updateCmd = process.env.DEEPSTORM_UPDATE_CMD || "npm install -g @deepstorm/cli@latest";
8481
8532
  try {
8482
- (0, import_node_child_process.execSync)("npm install -g @deepstorm/cli@latest", { stdio: "inherit" });
8533
+ (0, import_node_child_process.execSync)(updateCmd, { stdio: "inherit" });
8483
8534
  console.log(`
8484
8535
  \u2714 \u5DF2\u66F4\u65B0\u81F3 v${result.latest}`);
8485
8536
  } catch {
@@ -8489,6 +8540,7 @@ async function updateCLI(fetchFn) {
8489
8540
  } else {
8490
8541
  console.log("\u2713 \u5DF2\u662F\u6700\u65B0\u7248\u672C");
8491
8542
  }
8543
+ return result;
8492
8544
  }
8493
8545
  function getInstalledSkillIds(targetDir) {
8494
8546
  const settingsPath = path19.join(targetDir, ".claude", "settings.json");
@@ -8503,14 +8555,13 @@ function getInstalledSkillIds(targetDir) {
8503
8555
  function registerUpdateCommand(program2) {
8504
8556
  const cliDir2 = __dirname;
8505
8557
  program2.command("update").description("\u68C0\u67E5 CLI \u66F4\u65B0\u5E76\u540C\u6B65\u5DF2\u5B89\u88C5 skill \u7684\u5B98\u65B9\u6700\u65B0\u6A21\u677F").action(async () => {
8506
- await updateCLI();
8507
- console.log("");
8508
8558
  const installedIds = getInstalledSkillIds(process.cwd());
8509
8559
  if (installedIds.length === 0) {
8510
8560
  console.log("\u672A\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684 skill\uFF0C\u8DF3\u8FC7\u540C\u6B65");
8511
8561
  } else {
8512
8562
  upgradeTemplates(cliDir2, process.cwd(), installedIds);
8513
8563
  }
8564
+ await updateCLI();
8514
8565
  });
8515
8566
  }
8516
8567
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepstorm/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "DeepStorm CLI — 一键配置项目开发环境",
5
5
  "license": "MIT",
6
6
  "author": "billkang",