yingclaw 2.4.2 → 2.4.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.
- package/bin/cli.js +30 -14
- package/lib/config.js +35 -0
- 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,
|
|
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
|
|
|
@@ -237,6 +237,14 @@ async function showStatus() {
|
|
|
237
237
|
env: process.env,
|
|
238
238
|
});
|
|
239
239
|
|
|
240
|
+
const systemPromptText = getSystemPrompt(config);
|
|
241
|
+
if (systemPromptText) {
|
|
242
|
+
const preview = systemPromptText.length > 60 ? systemPromptText.slice(0, 60) + '…' : systemPromptText;
|
|
243
|
+
view.lines.push({ label: '系统提示词', value: preview });
|
|
244
|
+
} else {
|
|
245
|
+
view.lines.push({ label: '系统提示词', value: '未配置' });
|
|
246
|
+
}
|
|
247
|
+
|
|
240
248
|
const lines = view.lines.map(({ label, value }) => {
|
|
241
249
|
const coloredValue = label === '厂商'
|
|
242
250
|
? chalk.white.bold(value)
|
|
@@ -684,10 +692,9 @@ program
|
|
|
684
692
|
const spinner = ora('清除中...').start();
|
|
685
693
|
setSystemPrompt(config, null);
|
|
686
694
|
saveConfig(config);
|
|
687
|
-
|
|
688
|
-
if (rcBlockOnClear.found) {
|
|
695
|
+
try {
|
|
689
696
|
writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, {});
|
|
690
|
-
}
|
|
697
|
+
} catch {}
|
|
691
698
|
spinner.succeed(chalk.green('系统提示词已清除'));
|
|
692
699
|
return;
|
|
693
700
|
}
|
|
@@ -711,21 +718,25 @@ program
|
|
|
711
718
|
setSystemPrompt(config, newPrompt);
|
|
712
719
|
saveConfig(config);
|
|
713
720
|
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, { systemPrompt: getSystemPrompt(config) });
|
|
718
|
-
|
|
721
|
+
// 无论是否已有 clawai 块,都同步写入 shell RC / PowerShell Profile
|
|
722
|
+
let rcFile;
|
|
723
|
+
try {
|
|
724
|
+
({ file: rcFile } = writeEnvToZshrc(config.baseUrl, config.apiKey, config.model, config.fastModel, { systemPrompt: getSystemPrompt(config) }));
|
|
725
|
+
} catch {}
|
|
726
|
+
|
|
727
|
+
spinner.succeed(chalk.green('系统提示词已保存'));
|
|
728
|
+
|
|
729
|
+
if (process.platform === 'win32') {
|
|
719
730
|
console.log(boxen(
|
|
720
731
|
chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
|
|
721
|
-
chalk.dim('•
|
|
732
|
+
chalk.dim('• 直接运行 claude 需重新打开 PowerShell 后生效\n') +
|
|
733
|
+
chalk.dim(' (已写入 PowerShell Profile,新窗口自动加载)'),
|
|
722
734
|
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
|
|
723
735
|
));
|
|
724
736
|
} else {
|
|
725
|
-
spinner.succeed(chalk.green('系统提示词已保存'));
|
|
726
737
|
console.log(boxen(
|
|
727
|
-
chalk.dim('• 通过菜单"启动 Claude Code"
|
|
728
|
-
chalk.dim('•
|
|
738
|
+
chalk.dim('• 通过菜单"启动 Claude Code"立即生效\n') +
|
|
739
|
+
chalk.dim('• 终端直接运行 claude 需先执行:') + chalk.cyan(`source ${rcFile || '~/.zshrc'}`),
|
|
729
740
|
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
|
|
730
741
|
));
|
|
731
742
|
}
|
|
@@ -1190,7 +1201,12 @@ async function runMenu() {
|
|
|
1190
1201
|
if (resolvedAction === 'launch') {
|
|
1191
1202
|
const cfg = loadConfig();
|
|
1192
1203
|
if (!cfg || getConfigValidationMessage(cfg)) continue;
|
|
1193
|
-
const
|
|
1204
|
+
const systemPromptText = getSystemPrompt(cfg);
|
|
1205
|
+
const launchArgs = systemPromptText ? ['--append-system-prompt', systemPromptText] : [];
|
|
1206
|
+
if (systemPromptText) {
|
|
1207
|
+
const preview = systemPromptText.length > 40 ? systemPromptText.slice(0, 40) + '…' : systemPromptText;
|
|
1208
|
+
console.log(chalk.dim(` 系统提示词已启用:${preview}`));
|
|
1209
|
+
}
|
|
1194
1210
|
await new Promise((resolve) => {
|
|
1195
1211
|
const child = spawn('claude', launchArgs, {
|
|
1196
1212
|
stdio: 'inherit',
|
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,
|