yingclaw 1.7.4 → 1.7.8

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Claude Code × 国产大模型,一键接入。
4
4
 
5
- 支持 DeepSeek、阿里云百炼(Qwen)、MiniMax、智谱 GLM、小米 MiMo,也支持自定义 Anthropic 兼容接口,无需梯子即可使用 Claude Code。
5
+ 支持 DeepSeek、Kimi、阿里云百炼(Qwen)、MiniMax、智谱 GLM、小米 MiMo,也支持自定义 Anthropic 兼容接口,无需梯子即可使用 Claude Code。
6
6
 
7
7
  ## 安装
8
8
 
@@ -14,7 +14,7 @@ npm install -g yingclaw
14
14
 
15
15
  ## 使用步骤
16
16
 
17
- > 当前自动写入环境变量支持 macOS / Linux zshbashWindows 用户可参考“原理”中的环境变量手动配置,PowerShell 自动写入后续版本支持。
17
+ > 支持 macOS / Linux / Windows / WSL。macOS、Linux、WSL 会写入 zsh/bash 配置文件;Windows 会写入用户级环境变量,重新打开 PowerShell / CMD 后生效。
18
18
 
19
19
  **第一步:安装 Claude Code**
20
20
  ```bash
@@ -28,6 +28,13 @@ claw setup
28
28
  ```
29
29
  选择厂商 → 输入 API Key → 选择模型,自动写入环境变量,配置完成后自动启动 Claude。
30
30
 
31
+ **可选:配置 Claude 桌面应用**
32
+ ```bash
33
+ claw desktop
34
+ ```
35
+ 将当前模型配置写入 Claude Desktop 的第三方推理(Cowork on 3P)本地配置。配置后需要完全退出并重新打开 Claude 桌面应用。
36
+ macOS 会询问是否自动重启 Claude 桌面应用;Windows 需要手动重新打开。
37
+
31
38
  选择“自定义 Anthropic 兼容接口”时,需要输入:
32
39
 
33
40
  - `ANTHROPIC_BASE_URL`
@@ -35,7 +42,7 @@ claw setup
35
42
 
36
43
  工具会根据 Base URL 自动尝试获取模型列表;如果获取失败,则手动输入主模型和快速模型。
37
44
 
38
- 注意:模型列表能获取不代表一定可用于 Claude Code。自定义接口还必须支持 Anthropic `/v1/messages`,否则 Claude Code 请求会被网关拒绝。
45
+ 注意:模型列表能获取不代表一定可用于 Claude Code 或 Claude 桌面应用。自定义接口还必须支持 Anthropic `/v1/messages`,否则请求会被网关拒绝。Claude 桌面应用的 Gateway Base URL 还必须使用 HTTPS。
39
46
 
40
47
  **第三步:以后直接用**
41
48
  ```bash
@@ -47,6 +54,7 @@ claude
47
54
  | 厂商 | 模型 |
48
55
  |------|------|
49
56
  | DeepSeek | V4 Flash、V4 Pro |
57
+ | Kimi / Moonshot | Kimi K2.5 |
50
58
  | 阿里云百炼 | Qwen3 Max、Plus、Flash |
51
59
  | MiniMax | M2.7、M2.7 Turbo、M2.5 |
52
60
  | 智谱 GLM | GLM-4.7、GLM-5.1、GLM-5 Turbo、GLM-4.5 Air |
@@ -57,7 +65,9 @@ claude
57
65
 
58
66
  ```bash
59
67
  claw switch # 快速切换模型(无需重新输入 Key)
68
+ claw desktop # 配置 Claude 桌面应用第三方推理
60
69
  claw status # 查看当前配置,验证 Key 是否有效
70
+ claw reset # 清除配置和环境变量
61
71
  ```
62
72
 
63
73
  ## 卸载
@@ -68,7 +78,7 @@ npm uninstall -g yingclaw
68
78
 
69
79
  ## 原理
70
80
 
71
- 各厂商均原生支持 Anthropic API 格式。本工具会自动写入 Claude Code 所需的环境变量,包括:
81
+ 各厂商均原生支持 Anthropic API 格式。本工具会自动写入 Claude Code 所需的环境变量。macOS / Linux / WSL 写入 shell 配置文件,Windows 写入用户级环境变量,包括:
72
82
 
73
83
  - `ANTHROPIC_BASE_URL`
74
84
  - `ANTHROPIC_AUTH_TOKEN`
@@ -82,6 +92,13 @@ npm uninstall -g yingclaw
82
92
 
83
93
  以 DeepSeek 为例,主模型默认使用 `deepseek-v4-pro[1m]`,Haiku/Subagent 快速模型使用 `deepseek-v4-flash`。如果在线模型列表获取失败,会回退到内置默认列表。
84
94
 
95
+ `claw desktop` 会额外写入 Claude Desktop 第三方推理配置:
96
+
97
+ - macOS:`~/Library/Application Support/Claude-3p/claude_desktop_config.json`
98
+ - Windows:`%APPDATA%\Claude-3p\claude_desktop_config.json`
99
+
100
+ 写入的 `enterpriseConfig` 使用 `inferenceProvider=gateway`、`inferenceGatewayAuthScheme=bearer`,并把当前模型写入 `inferenceModels`。
101
+
85
102
  ## License
86
103
 
87
104
  MIT
package/bin/cli.js CHANGED
@@ -20,6 +20,7 @@ const { execSync, spawn, spawnSync } = require('child_process');
20
20
  const pkg = require('../package.json');
21
21
  const { buildMenuStatusLines, buildStatusView } = require('../lib/panel');
22
22
  const { buildClaudeInstallCommand } = require('../lib/install');
23
+ const { clearClaudeDesktopConfig, restartClaudeDesktop, writeClaudeDesktopConfig } = require('../lib/desktop');
23
24
 
24
25
  const program = new Command();
25
26
 
@@ -94,6 +95,24 @@ function isValidUrl(value) {
94
95
  }
95
96
  }
96
97
 
98
+ function getActivationHint(file) {
99
+ if (file === 'Windows 用户环境变量') {
100
+ return '重新打开 PowerShell / CMD 后生效';
101
+ }
102
+ return `运行 source ${file} 生效,或重新开一个终端`;
103
+ }
104
+
105
+ function getStorageHint(file) {
106
+ if (file === 'Windows 用户环境变量') {
107
+ return `⚠ API Key 以明文存储在 ${file} 和用户主目录下的 .clawai.json`;
108
+ }
109
+ return `⚠ API Key 以明文存储在 ${file} 和 ~/.clawai.json`;
110
+ }
111
+
112
+ function getDesktopRestartHint() {
113
+ return '请完全退出 Claude 桌面应用后重新打开,第三方模型配置才会生效';
114
+ }
115
+
97
116
  async function promptModelFromChoices({ chalk, choices, message, backLabel = '↩ 返回上一步', allowManual = true }) {
98
117
  const selected = await select({ loop: false,
99
118
  message: chalk.cyan(message),
@@ -395,7 +414,7 @@ program
395
414
  spinner.fail(chalk.red(`写入失败: ${e.message}`));
396
415
  return;
397
416
  }
398
- console.log(chalk.dim(`⚠ API Key 以明文存储在 ${file} 和 ~/.clawai.json`));
417
+ console.log(chalk.dim(getStorageHint(file)));
399
418
 
400
419
  console.log(boxen(
401
420
  chalk.bold('配置完成!\n\n') +
@@ -457,7 +476,7 @@ program
457
476
  const { file } = writeEnvToZshrc(customConfig.baseUrl, customConfig.apiKey, customConfig.model, customConfig.fastModel);
458
477
  await new Promise(r => setTimeout(r, 300));
459
478
  spinner.succeed(chalk.green(`已切换至 ${customConfig.providerName} · ${customConfig.model}`));
460
- console.log(chalk.dim(`运行 source ${file} 生效,或重新开一个终端`));
479
+ console.log(chalk.dim(getActivationHint(file)));
461
480
  return;
462
481
  }
463
482
 
@@ -503,7 +522,7 @@ program
503
522
  const { file } = writeEnvToZshrc(provider.baseUrl, apiKey, model, fastModel);
504
523
  await new Promise(r => setTimeout(r, 300));
505
524
  spinner.succeed(chalk.green(`已切换至 ${provider.name} · ${model}`));
506
- console.log(chalk.dim(`运行 source ${file} 生效,或重新开一个终端`));
525
+ console.log(chalk.dim(getActivationHint(file)));
507
526
  });
508
527
 
509
528
  program
@@ -511,6 +530,74 @@ program
511
530
  .description('查看当前配置和 Key 有效性')
512
531
  .action(showStatus);
513
532
 
533
+ program
534
+ .command('desktop')
535
+ .description('配置 Claude 桌面应用使用当前模型')
536
+ .action(async () => {
537
+ const chalk = (await import('chalk')).default;
538
+ const ora = (await import('ora')).default;
539
+ const boxen = (await import('boxen')).default;
540
+
541
+ console.log(await getBanner());
542
+
543
+ const config = loadConfig();
544
+ if (!config) {
545
+ console.log(chalk.red('\n未配置,请先运行: claw setup\n'));
546
+ return;
547
+ }
548
+ const configProblem = getConfigValidationMessage(config);
549
+ if (configProblem) {
550
+ console.log(chalk.red(`\n配置无效:${configProblem}`));
551
+ console.log(chalk.dim('请运行 claw setup 重新配置。\n'));
552
+ return;
553
+ }
554
+
555
+ if (process.platform !== 'darwin' && process.platform !== 'win32') {
556
+ console.log(chalk.yellow('\nClaude 桌面应用 3P 配置目前仅支持 macOS / Windows。\n'));
557
+ return;
558
+ }
559
+
560
+ const spinner = ora('写入 Claude 桌面应用配置...').start();
561
+ let result;
562
+ try {
563
+ result = writeClaudeDesktopConfig(config);
564
+ if (result.result === 'unsupported') {
565
+ spinner.warn(chalk.yellow('当前系统暂不支持自动配置 Claude 桌面应用'));
566
+ return;
567
+ }
568
+ spinner.succeed(chalk.green(`Claude 桌面应用配置已写入 → ${result.file}`));
569
+ } catch (e) {
570
+ spinner.fail(chalk.red(`写入失败: ${e.message}`));
571
+ return;
572
+ }
573
+
574
+ console.log(boxen(
575
+ chalk.bold('Claude 桌面应用已配置为 Gateway 模式\n\n') +
576
+ chalk.dim('Base URL ') + chalk.cyan(config.baseUrl) + '\n' +
577
+ chalk.dim('模型 ') + chalk.yellow(config.model) + '\n' +
578
+ chalk.dim('认证方式 ') + chalk.cyan('bearer') + '\n\n' +
579
+ chalk.yellow(getDesktopRestartHint()) + '\n' +
580
+ chalk.dim('要求:网关必须支持 Anthropic POST /v1/messages,且 Base URL 必须是 HTTPS。'),
581
+ { padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'cyan', margin: { top: 1, bottom: 1 } }
582
+ ));
583
+
584
+ if (process.platform === 'darwin') {
585
+ const shouldRestart = await confirm({ message: '是否自动重启 Claude 桌面应用?', default: false });
586
+ if (shouldRestart) {
587
+ const restartSpinner = ora('正在重启 Claude 桌面应用...').start();
588
+ try {
589
+ await restartClaudeDesktop();
590
+ restartSpinner.succeed(chalk.green('Claude 桌面应用已重新打开'));
591
+ } catch (e) {
592
+ restartSpinner.fail(chalk.red(`重启失败: ${e.message}`));
593
+ console.log(chalk.dim(getDesktopRestartHint()));
594
+ }
595
+ }
596
+ } else {
597
+ console.log(chalk.dim(getDesktopRestartHint()));
598
+ }
599
+ });
600
+
514
601
  program
515
602
  .command('reset')
516
603
  .description('恢复默认(清除所有 clawai 配置)')
@@ -532,16 +619,23 @@ program
532
619
 
533
620
  const spinner = ora('清除中...').start();
534
621
  const cleared = resetConfig();
622
+ const desktopCleared = clearClaudeDesktopConfig();
623
+ if (desktopCleared.result === 'updated') {
624
+ cleared.push(desktopCleared.file);
625
+ }
535
626
  await new Promise(r => setTimeout(r, 300));
536
627
 
537
628
  if (cleared.length === 0) {
538
629
  spinner.warn(chalk.yellow('没有找到任何配置,无需清除'));
539
630
  } else {
540
631
  spinner.succeed(chalk.green('已恢复默认'));
632
+ const resetNote = cleared.includes('Windows 用户环境变量')
633
+ ? '注:当前终端的环境变量还在内存中,重新打开 PowerShell / CMD 后才彻底清除'
634
+ : '注:当前终端的环境变量还在内存中,重开终端或 unset 才彻底清除';
541
635
  console.log(boxen(
542
636
  chalk.bold('已清除以下文件中的 clawai 配置:\n\n') +
543
637
  cleared.map(f => chalk.cyan(' • ' + f)).join('\n') +
544
- '\n\n' + chalk.dim('注:当前终端的环境变量还在内存中,重开终端或 unset 才彻底清除'),
638
+ '\n\n' + chalk.dim(resetNote),
545
639
  { padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
546
640
  ));
547
641
  }
@@ -562,7 +656,7 @@ async function renderStatusBar(apiStatus) {
562
656
  claudeInstalled,
563
657
  env: process.env,
564
658
  });
565
- const statusLines = buildMenuStatusLines(view, { apiStatus, claudeInstalled });
659
+ const statusLines = buildMenuStatusLines(view, { apiStatus, claudeInstalled, platform: process.platform });
566
660
  cfgPart = statusLines.map((line, index) => {
567
661
  if (index === 0) return line.replace('API 正常', chalk.green('API 正常')).replace('API Key 无效', chalk.red('API Key 无效')).replace('网络/服务异常', chalk.yellow('网络/服务异常'));
568
662
  if (line.startsWith('环境变量未生效')) return chalk.yellow(line);
@@ -611,9 +705,10 @@ async function runMenu() {
611
705
  { name: '📦 安装 Claude Code', value: 'install' },
612
706
  { name: config ? '⚙️ 重新配置(输入新的 API Key)' : '⚙️ 首次配置 API Key 和模型', value: 'setup' },
613
707
  { name: '🔄 切换厂商或模型', value: 'switch', disabled: (!config || configProblem) && '需先完成配置' },
708
+ { name: '🖥 配置 Claude 桌面应用', value: 'desktop', disabled: (!config || configProblem) && '需先完成配置' },
614
709
  { name: '📊 查看当前配置', value: 'status', disabled: !config && '需先完成配置' },
615
710
  { name: '🔁 重新检测 API', value: 'recheck', disabled: (!config || configProblem) && '需先完成配置' },
616
- { name: '🗑 恢复默认(清除所有配置)', value: 'reset', disabled: !config && '没有可清除的配置' },
711
+ { name: '🗑 恢复默认(清除所有配置)', value: 'reset' },
617
712
  { name: '退出', value: 'exit' },
618
713
  ],
619
714
  });
@@ -647,6 +742,7 @@ async function runMenu() {
647
742
  install: 'install-claude',
648
743
  setup: 'setup',
649
744
  switch: 'switch',
745
+ desktop: 'desktop',
650
746
  status: 'status',
651
747
  reset: 'reset',
652
748
  };
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  ...require('./lib/config'),
3
+ ...require('./lib/desktop'),
3
4
  ...require('./lib/install'),
4
5
  ...require('./lib/panel'),
5
6
  };
package/lib/config.js CHANGED
@@ -1,8 +1,21 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const os = require('os');
4
+ const { spawnSync } = require('child_process');
4
5
 
5
6
  const CONFIG_FILE = path.join(os.homedir(), '.clawai.json');
7
+ const WINDOWS_ENV_LABEL = 'Windows 用户环境变量';
8
+ const CLAUDE_ENV_KEYS = [
9
+ 'ANTHROPIC_BASE_URL',
10
+ 'ANTHROPIC_AUTH_TOKEN',
11
+ 'ANTHROPIC_API_KEY',
12
+ 'ANTHROPIC_MODEL',
13
+ 'ANTHROPIC_DEFAULT_OPUS_MODEL',
14
+ 'ANTHROPIC_DEFAULT_SONNET_MODEL',
15
+ 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
16
+ 'CLAUDE_CODE_SUBAGENT_MODEL',
17
+ 'CLAUDE_CODE_EFFORT_LEVEL',
18
+ ];
6
19
 
7
20
  const PROVIDERS = {
8
21
  deepseek: {
@@ -15,6 +28,15 @@ const PROVIDERS = {
15
28
  { name: 'DeepSeek V4 Flash(快速)', value: 'deepseek-v4-flash' },
16
29
  ],
17
30
  },
31
+ kimi: {
32
+ name: 'Kimi / Moonshot',
33
+ baseUrl: 'https://api.moonshot.ai/anthropic',
34
+ modelsUrl: 'https://api.moonshot.ai/v1/models',
35
+ fastModel: 'kimi-k2.5',
36
+ models: [
37
+ { name: 'Kimi K2.5(代码)', value: 'kimi-k2.5' },
38
+ ],
39
+ },
18
40
  qwen: {
19
41
  name: '阿里云百炼 (Qwen)',
20
42
  baseUrl: 'https://dashscope.aliyuncs.com/apps/anthropic',
@@ -222,6 +244,29 @@ function buildClaudeEnv({ provider, baseUrl, apiKey, model, fastModel }) {
222
244
  };
223
245
  }
224
246
 
247
+ function buildWindowsSetEnvCommands(env) {
248
+ return CLAUDE_ENV_KEYS.map((key) => ({
249
+ command: 'setx',
250
+ args: [key, env[key]],
251
+ }));
252
+ }
253
+
254
+ function buildWindowsClearEnvCommands() {
255
+ return CLAUDE_ENV_KEYS.map((key) => ({
256
+ command: 'reg',
257
+ args: ['delete', 'HKCU\\Environment', '/V', key, '/F'],
258
+ }));
259
+ }
260
+
261
+ function runWindowsEnvCommands(commands, runner = spawnSync, { ignoreErrors = false } = {}) {
262
+ for (const { command, args } of commands) {
263
+ const result = runner(command, args, { stdio: 'ignore', windowsHide: true });
264
+ if (!ignoreErrors && result.status !== 0) {
265
+ throw new Error(`${command} ${args[0]} 执行失败`);
266
+ }
267
+ }
268
+ }
269
+
225
270
  function classifyValidationStatus(statusCode) {
226
271
  if (statusCode >= 200 && statusCode < 300) return true;
227
272
  if (statusCode === 401 || statusCode === 403) return false;
@@ -254,7 +299,15 @@ function buildEnvBlock(baseUrl, apiKey, model, fastModel) {
254
299
  }
255
300
 
256
301
  // 写入或更新 shell 配置文件中的环境变量块
257
- function writeEnvToZshrc(baseUrl, apiKey, model, fastModel) {
302
+ function writeEnvToZshrc(baseUrl, apiKey, model, fastModel, options = {}) {
303
+ const platform = options.platform || process.platform;
304
+ if (platform === 'win32') {
305
+ const provider = providerKeyFromBaseUrl(baseUrl);
306
+ const env = buildClaudeEnv({ provider, baseUrl, apiKey, model, fastModel });
307
+ runWindowsEnvCommands(buildWindowsSetEnvCommands(env), options.runner || spawnSync);
308
+ return { result: 'updated', file: WINDOWS_ENV_LABEL };
309
+ }
310
+
258
311
  const shell = process.env.SHELL || '';
259
312
  let rcFile;
260
313
  if (shell.includes('bash')) {
@@ -278,17 +331,25 @@ function writeEnvToZshrc(baseUrl, apiKey, model, fastModel) {
278
331
  }
279
332
 
280
333
  // 清除所有 clawai 配置(配置文件 + shell 环境变量块)
281
- function resetConfig() {
334
+ function resetConfig(options = {}) {
282
335
  const cleared = [];
336
+ const configFile = options.configFile || CONFIG_FILE;
337
+ const platform = options.platform || process.platform;
283
338
 
284
339
  // 删配置文件
285
- if (fs.existsSync(CONFIG_FILE)) {
286
- fs.unlinkSync(CONFIG_FILE);
287
- cleared.push(CONFIG_FILE);
340
+ if (fs.existsSync(configFile)) {
341
+ fs.unlinkSync(configFile);
342
+ cleared.push(configFile);
343
+ }
344
+
345
+ if (platform === 'win32') {
346
+ runWindowsEnvCommands(buildWindowsClearEnvCommands(), options.runner || spawnSync, { ignoreErrors: true });
347
+ cleared.push(WINDOWS_ENV_LABEL);
348
+ return cleared;
288
349
  }
289
350
 
290
351
  // 清理所有可能的 rc 文件中的 clawai 块
291
- const rcFiles = [
352
+ const rcFiles = options.rcFiles || [
292
353
  path.join(os.homedir(), '.zshrc'),
293
354
  path.join(os.homedir(), '.bashrc'),
294
355
  path.join(os.homedir(), '.bash_profile'),
@@ -312,6 +373,8 @@ module.exports = {
312
373
  loadConfig,
313
374
  saveConfig,
314
375
  writeEnvToZshrc,
376
+ buildWindowsSetEnvCommands,
377
+ buildWindowsClearEnvCommands,
315
378
  fetchModels,
316
379
  resetConfig,
317
380
  validateConfig,
package/lib/desktop.js ADDED
@@ -0,0 +1,161 @@
1
+ const crypto = require('crypto');
2
+ const fs = require('fs');
3
+ const os = require('os');
4
+ const path = require('path');
5
+ const { spawnSync } = require('child_process');
6
+ const { normalizeAnthropicBaseUrl } = require('./config');
7
+
8
+ const CLAUDE_DESKTOP_LABEL = 'Claude 桌面应用配置';
9
+ const DESKTOP_GATEWAY_KEYS = [
10
+ 'inferenceProvider',
11
+ 'inferenceGatewayBaseUrl',
12
+ 'inferenceGatewayApiKey',
13
+ 'inferenceGatewayAuthScheme',
14
+ 'inferenceModels',
15
+ 'disableDeploymentModeChooser',
16
+ 'deploymentOrganizationUuid',
17
+ ];
18
+
19
+ function getClaudeDesktopConfigPath(options = {}) {
20
+ const platform = options.platform || process.platform;
21
+ const homeDir = options.homeDir || os.homedir();
22
+
23
+ if (platform === 'darwin') {
24
+ return path.join(homeDir, 'Library', 'Application Support', 'Claude-3p', 'claude_desktop_config.json');
25
+ }
26
+
27
+ if (platform === 'win32') {
28
+ const appData = options.appData || process.env.APPDATA || path.join(homeDir, 'AppData', 'Roaming');
29
+ return path.join(appData, 'Claude-3p', 'claude_desktop_config.json');
30
+ }
31
+
32
+ return null;
33
+ }
34
+
35
+ function readJsonFile(file) {
36
+ try {
37
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
38
+ } catch {
39
+ return {};
40
+ }
41
+ }
42
+
43
+ function uniqueModels(model, fastModel) {
44
+ return [...new Set([model, fastModel].filter(Boolean))];
45
+ }
46
+
47
+ function buildClaudeDesktopEnterpriseConfig(config, options = {}) {
48
+ const models = uniqueModels(config.model, config.fastModel);
49
+ const baseUrl = normalizeAnthropicBaseUrl(config.baseUrl);
50
+ if (!baseUrl.startsWith('https://')) {
51
+ throw new Error('Claude 桌面应用要求 Gateway Base URL 使用 HTTPS');
52
+ }
53
+ return {
54
+ inferenceProvider: 'gateway',
55
+ inferenceGatewayBaseUrl: baseUrl,
56
+ inferenceGatewayApiKey: config.apiKey,
57
+ inferenceGatewayAuthScheme: options.authScheme || 'bearer',
58
+ inferenceModels: JSON.stringify(models),
59
+ disableDeploymentModeChooser: 'true',
60
+ deploymentOrganizationUuid: options.uuid || crypto.randomUUID(),
61
+ };
62
+ }
63
+
64
+ function writeClaudeDesktopConfig(config, options = {}) {
65
+ const file = options.configFile || getClaudeDesktopConfigPath(options);
66
+ if (!file) {
67
+ return { result: 'unsupported', file: null };
68
+ }
69
+
70
+ const current = readJsonFile(file);
71
+ const existingEnterpriseConfig = current.enterpriseConfig && typeof current.enterpriseConfig === 'object'
72
+ ? current.enterpriseConfig
73
+ : {};
74
+ const deploymentOrganizationUuid = existingEnterpriseConfig.deploymentOrganizationUuid || options.uuid;
75
+ const enterpriseConfig = buildClaudeDesktopEnterpriseConfig(config, {
76
+ authScheme: options.authScheme,
77
+ uuid: deploymentOrganizationUuid,
78
+ });
79
+
80
+ const next = {
81
+ ...current,
82
+ enterpriseConfig: {
83
+ ...existingEnterpriseConfig,
84
+ ...enterpriseConfig,
85
+ },
86
+ };
87
+
88
+ fs.mkdirSync(path.dirname(file), { recursive: true });
89
+ const before = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
90
+ const body = JSON.stringify(next, null, 2) + '\n';
91
+ fs.writeFileSync(file, body);
92
+ return { result: before === body ? 'unchanged' : 'updated', file };
93
+ }
94
+
95
+ function clearClaudeDesktopConfig(options = {}) {
96
+ const file = options.configFile || getClaudeDesktopConfigPath(options);
97
+ if (!file || !fs.existsSync(file)) {
98
+ return { result: 'missing', file };
99
+ }
100
+
101
+ const current = readJsonFile(file);
102
+ if (!current.enterpriseConfig || typeof current.enterpriseConfig !== 'object') {
103
+ return { result: 'missing', file };
104
+ }
105
+
106
+ const enterpriseConfig = { ...current.enterpriseConfig };
107
+ for (const key of DESKTOP_GATEWAY_KEYS) {
108
+ delete enterpriseConfig[key];
109
+ }
110
+
111
+ const next = { ...current };
112
+ if (Object.keys(enterpriseConfig).length > 0) {
113
+ next.enterpriseConfig = enterpriseConfig;
114
+ } else {
115
+ delete next.enterpriseConfig;
116
+ }
117
+
118
+ fs.writeFileSync(file, JSON.stringify(next, null, 2) + '\n');
119
+ return { result: 'updated', file };
120
+ }
121
+
122
+ function buildClaudeDesktopRestartCommands(platform = process.platform) {
123
+ if (platform !== 'darwin') return null;
124
+ return [
125
+ { command: 'osascript', args: ['-e', 'tell application "Claude" to quit'] },
126
+ { command: 'open', args: ['-a', 'Claude'] },
127
+ ];
128
+ }
129
+
130
+ function delay(ms) {
131
+ return new Promise(resolve => setTimeout(resolve, ms));
132
+ }
133
+
134
+ async function restartClaudeDesktop(options = {}) {
135
+ const platform = options.platform || process.platform;
136
+ const commands = buildClaudeDesktopRestartCommands(platform);
137
+ if (!commands) return { result: 'unsupported' };
138
+
139
+ const runner = options.runner || spawnSync;
140
+ const delayMs = options.delayMs ?? 1500;
141
+ const [quitCommand, openCommand] = commands;
142
+
143
+ runner(quitCommand.command, quitCommand.args, { stdio: 'ignore', windowsHide: true });
144
+ await delay(delayMs);
145
+ const result = runner(openCommand.command, openCommand.args, { stdio: 'ignore', windowsHide: true });
146
+ if (result.status !== 0) {
147
+ throw new Error('Claude 桌面应用重新打开失败');
148
+ }
149
+
150
+ return { result: 'restarted' };
151
+ }
152
+
153
+ module.exports = {
154
+ buildClaudeDesktopEnterpriseConfig,
155
+ buildClaudeDesktopRestartCommands,
156
+ clearClaudeDesktopConfig,
157
+ getClaudeDesktopConfigPath,
158
+ restartClaudeDesktop,
159
+ writeClaudeDesktopConfig,
160
+ CLAUDE_DESKTOP_LABEL,
161
+ };
package/lib/panel.js CHANGED
@@ -54,6 +54,8 @@ function buildMenuStatusLines(view, options = {}) {
54
54
 
55
55
  if (view.envActive) {
56
56
  lines.push('环境变量已生效');
57
+ } else if (options.platform === 'win32') {
58
+ lines.push('环境变量未生效:重新打开 PowerShell / CMD');
57
59
  } else {
58
60
  lines.push('环境变量未生效:运行 source ~/.zshrc 或重开终端');
59
61
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yingclaw",
3
- "version": "1.7.4",
4
- "description": "Claude Code × 国产大模型一键接入:DeepSeek、Qwen、MiniMax、GLM、MiMo",
3
+ "version": "1.7.8",
4
+ "description": "Claude Code × 国产大模型一键接入:DeepSeek、Kimi、Qwen、MiniMax、GLM、MiMo",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "claw": "bin/cli.js"