yingclaw 2.4.1 → 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.
- package/bin/cli.js +24 -5
- package/lib/config.js +35 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -684,6 +684,9 @@ program
|
|
|
684
684
|
const spinner = ora('清除中...').start();
|
|
685
685
|
setSystemPrompt(config, null);
|
|
686
686
|
saveConfig(config);
|
|
687
|
+
try {
|
|
688
|
+
writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, {});
|
|
689
|
+
} catch {}
|
|
687
690
|
spinner.succeed(chalk.green('系统提示词已清除'));
|
|
688
691
|
return;
|
|
689
692
|
}
|
|
@@ -706,13 +709,29 @@ program
|
|
|
706
709
|
const spinner = ora('保存中...').start();
|
|
707
710
|
setSystemPrompt(config, newPrompt);
|
|
708
711
|
saveConfig(config);
|
|
712
|
+
|
|
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
|
+
|
|
709
719
|
spinner.succeed(chalk.green('系统提示词已保存'));
|
|
710
720
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
721
|
+
if (process.platform === 'win32') {
|
|
722
|
+
console.log(boxen(
|
|
723
|
+
chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
|
|
724
|
+
chalk.dim('• 直接运行 claude 需重新打开 PowerShell 后生效\n') +
|
|
725
|
+
chalk.dim(' (已写入 PowerShell Profile,新窗口自动加载)'),
|
|
726
|
+
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
|
|
727
|
+
));
|
|
728
|
+
} else {
|
|
729
|
+
console.log(boxen(
|
|
730
|
+
chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
|
|
731
|
+
chalk.dim('• 终端直接运行 claude 需先执行:') + chalk.cyan(`source ${rcFile || '~/.zshrc'}`),
|
|
732
|
+
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
|
|
733
|
+
));
|
|
734
|
+
}
|
|
716
735
|
});
|
|
717
736
|
|
|
718
737
|
program
|
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,
|