yingclaw 2.4.2 → 2.4.3

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 (3) hide show
  1. package/bin/cli.js +16 -13
  2. package/lib/config.js +35 -0
  3. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -25,7 +25,7 @@ const pkg = require('../package.json');
25
25
  const { buildMenuStatusLines, buildStatusView } = require('../lib/panel');
26
26
  const { buildClaudeInstallCommand } = require('../lib/install');
27
27
  const { clearClaudeDesktopConfig, isDesktopConfigured, openClaudeDesktop, writeClaudeDesktopConfig } = require('../lib/desktop');
28
- const { runDoctorChecks, summarize, checkShellRcBlock, STATUS_OK, STATUS_FAIL, STATUS_WARN, STATUS_INFO } = require('../lib/doctor');
28
+ const { runDoctorChecks, summarize, STATUS_OK, STATUS_FAIL, STATUS_WARN, STATUS_INFO } = require('../lib/doctor');
29
29
 
30
30
  const program = new Command();
31
31
 
@@ -684,10 +684,9 @@ program
684
684
  const spinner = ora('清除中...').start();
685
685
  setSystemPrompt(config, null);
686
686
  saveConfig(config);
687
- const rcBlockOnClear = checkShellRcBlock();
688
- if (rcBlockOnClear.found) {
687
+ try {
689
688
  writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, {});
690
- }
689
+ } catch {}
691
690
  spinner.succeed(chalk.green('系统提示词已清除'));
692
691
  return;
693
692
  }
@@ -711,21 +710,25 @@ program
711
710
  setSystemPrompt(config, newPrompt);
712
711
  saveConfig(config);
713
712
 
714
- // 如果终端已配置,自动同步 shell RC
715
- const rcBlock = checkShellRcBlock();
716
- if (rcBlock.found) {
717
- writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, { systemPrompt: getSystemPrompt(config) });
718
- spinner.succeed(chalk.green('系统提示词已保存,已同步到终端配置'));
713
+ // 无论是否已有 clawai 块,都同步写入 shell RC / PowerShell Profile
714
+ let rcFile;
715
+ try {
716
+ ({ file: rcFile } = writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, { systemPrompt: getSystemPrompt(config) }));
717
+ } catch {}
718
+
719
+ spinner.succeed(chalk.green('系统提示词已保存'));
720
+
721
+ if (process.platform === 'win32') {
719
722
  console.log(boxen(
720
723
  chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
721
- chalk.dim('• 终端直接运行 claude 需先执行:') + chalk.cyan(`source ${rcBlock.file}`),
724
+ chalk.dim('• 直接运行 claude 需重新打开 PowerShell 后生效\n') +
725
+ chalk.dim(' (已写入 PowerShell Profile,新窗口自动加载)'),
722
726
  { padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
723
727
  ));
724
728
  } else {
725
- spinner.succeed(chalk.green('系统提示词已保存'));
726
729
  console.log(boxen(
727
- chalk.dim('• 通过菜单"启动 Claude Code"时自动应用\n') +
728
- chalk.dim('• 终端直接使用 claude 命令请重新运行 ') + chalk.cyan('claw code'),
730
+ chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
731
+ chalk.dim('• 终端直接运行 claude 需先执行:') + chalk.cyan(`source ${rcFile || '~/.zshrc'}`),
729
732
  { padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
730
733
  ));
731
734
  }
package/lib/config.js CHANGED
@@ -370,6 +370,38 @@ function buildEnvBlock(baseUrl, apiKey, model, fastModel, systemPrompt) {
370
370
  return lines.join('\n');
371
371
  }
372
372
 
373
+ function buildPsBlock(systemPrompt) {
374
+ const escaped = systemPrompt.replace(/'/g, "''");
375
+ return [
376
+ '',
377
+ '# clawai-start',
378
+ `$_claw_system_prompt = '${escaped}'`,
379
+ `function claude { $claudePath = (Get-Command -Name claude.cmd -ErrorAction SilentlyContinue)?.Source; if (-not $claudePath) { $claudePath = 'claude' }; & $claudePath --append-system-prompt $_claw_system_prompt @args }`,
380
+ '# clawai-end',
381
+ '',
382
+ ].join('\r\n');
383
+ }
384
+
385
+ function writePowerShellProfile(systemPrompt, options = {}) {
386
+ const homeDir = options.homeDir || os.homedir();
387
+ const profilePaths = [
388
+ path.join(homeDir, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1'),
389
+ path.join(homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
390
+ ];
391
+ const written = [];
392
+ for (const profilePath of profilePaths) {
393
+ try {
394
+ fs.mkdirSync(path.dirname(profilePath), { recursive: true });
395
+ const current = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
396
+ const cleaned = current.replace(/\r?\n?# clawai-start[\s\S]*?# clawai-end\r?\n?/g, '');
397
+ const next = (systemPrompt && systemPrompt.trim()) ? cleaned + buildPsBlock(systemPrompt) : cleaned;
398
+ fs.writeFileSync(profilePath, next, 'utf8');
399
+ written.push(profilePath);
400
+ } catch {}
401
+ }
402
+ return written;
403
+ }
404
+
373
405
  // 写入或更新 shell 配置文件中的环境变量块
374
406
  function writeEnvToZshrc(baseUrl, apiKey, model, fastModel, options = {}) {
375
407
  const platform = options.platform || process.platform;
@@ -377,6 +409,7 @@ function writeEnvToZshrc(baseUrl, apiKey, model, fastModel, options = {}) {
377
409
  const provider = providerKeyFromBaseUrl(baseUrl);
378
410
  const env = buildClaudeEnv({ provider, baseUrl, apiKey, model, fastModel });
379
411
  runWindowsEnvCommands(buildWindowsSetEnvCommands(env), options.runner || spawnSync);
412
+ writePowerShellProfile(options.systemPrompt, options);
380
413
  return { result: 'updated', file: WINDOWS_ENV_LABEL };
381
414
  }
382
415
 
@@ -453,6 +486,8 @@ module.exports = {
453
486
  getSystemPrompt,
454
487
  setSystemPrompt,
455
488
  writeEnvToZshrc,
489
+ writePowerShellProfile,
490
+ buildPsBlock,
456
491
  buildWindowsSetEnvCommands,
457
492
  buildWindowsClearEnvCommands,
458
493
  clearClaudeCodeEnv,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yingclaw",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "Claude Code × 国产大模型一键接入:DeepSeek、Kimi、Qwen、MiniMax、GLM、MiMo",
5
5
  "main": "index.js",
6
6
  "bin": {