@raolin2025/claude-code-node 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/package.json +1 -1
- package/src/core/cli.js +53 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raolin2025/claude-code-node",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "Node.js AI Code Agent CLI - Zero dependencies, pure JavaScript, security hardened, multi-channel notifications, Telegram & QQ Bot remote programming",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/core/cli.js
CHANGED
|
@@ -407,11 +407,61 @@ export async function main() {
|
|
|
407
407
|
const config = new Config()
|
|
408
408
|
await config.load(process.cwd())
|
|
409
409
|
|
|
410
|
-
const
|
|
411
|
-
|
|
410
|
+
const apiBase = cliArgs.apiBase || config.get('apiBase') || process.env.LLM_API_BASE || ''
|
|
411
|
+
let model = cliArgs.model || config.get('model') || ''
|
|
412
|
+
// 未指定模型 → 自动从 API 拉取模型列表让用户选择
|
|
413
|
+
if (!model && apiBase) {
|
|
414
|
+
const apiKeyForModels = cliArgs.apiKey || config.get('apiKey') || process.env.LLM_API_KEY || process.env.DEEPSEEK_API_KEY || ''
|
|
415
|
+
if (apiKeyForModels) {
|
|
416
|
+
try {
|
|
417
|
+
const modelsUrl = apiBase.replace(/\/+$/, '') + '/models'
|
|
418
|
+
console.log('⚠️ 未指定模型,正在从 API 获取可用模型列表...')
|
|
419
|
+
const res = await fetch(modelsUrl, { headers: { 'Authorization': `Bearer ${apiKeyForModels}` } })
|
|
420
|
+
if (res.ok) {
|
|
421
|
+
const data = await res.json()
|
|
422
|
+
const models = data.data || []
|
|
423
|
+
if (models.length > 0) {
|
|
424
|
+
console.log(`\n可用模型 (${models.length}):`)
|
|
425
|
+
models.forEach((m, i) => {
|
|
426
|
+
const id = m.id || m
|
|
427
|
+
console.log(` ${(i + 1).toString().padStart(2)}. ${id}`)
|
|
428
|
+
})
|
|
429
|
+
console.log('输入编号选择,或直接输入模型名(回车跳过用 deepseek-chat):')
|
|
430
|
+
// 用 readline 等待输入(此时 REPL 还没启动,需要临时创建)
|
|
431
|
+
const tmpRl = createInterface({ input: process.stdin, output: process.stdout })
|
|
432
|
+
const answer = await new Promise(resolve => tmpRl.question('> ', resolve))
|
|
433
|
+
tmpRl.close()
|
|
434
|
+
const num = parseInt(answer, 10)
|
|
435
|
+
if (!isNaN(num) && num >= 1 && num <= models.length) {
|
|
436
|
+
model = models[num - 1].id || models[num - 1]
|
|
437
|
+
} else if (answer.trim()) {
|
|
438
|
+
model = answer.trim()
|
|
439
|
+
} else {
|
|
440
|
+
model = 'deepseek-chat'
|
|
441
|
+
}
|
|
442
|
+
console.log(`✅ Model → ${model}`)
|
|
443
|
+
} else {
|
|
444
|
+
model = 'deepseek-chat'
|
|
445
|
+
console.log('API 返回空模型列表,使用默认: deepseek-chat')
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
model = 'deepseek-chat'
|
|
449
|
+
console.log('无法获取模型列表,使用默认: deepseek-chat')
|
|
450
|
+
}
|
|
451
|
+
} catch (e) {
|
|
452
|
+
model = 'deepseek-chat'
|
|
453
|
+
console.log(`获取模型列表失败 (${e.message}),使用默认: deepseek-chat`)
|
|
454
|
+
}
|
|
455
|
+
} else {
|
|
456
|
+
model = 'deepseek-chat'
|
|
457
|
+
}
|
|
458
|
+
} else if (!model) {
|
|
459
|
+
model = 'deepseek-chat' // 无 apiBase 也无 model → DeepSeek 默认
|
|
460
|
+
}
|
|
461
|
+
const DEFAULT_SYSTEM_PROMPT = `You are cc-node, an AI coding assistant. Configuration files: user-level ~/.claude-code/config.json, project-level .claude-code/config.json (in project root). Runtime files (pid/socket): ~/.cc-node/. Never reference settings.json or .claude.json — those paths do not exist.`
|
|
462
|
+
const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
412
463
|
const permissionMode = cliArgs.permissionMode || config.get('permissionMode')
|
|
413
464
|
const maxTurns = cliArgs.maxTurns || config.get('maxTurns')
|
|
414
|
-
const apiBase = cliArgs.apiBase || config.get('apiBase') || process.env.LLM_API_BASE || ''
|
|
415
465
|
const apiKey = cliArgs.apiKey || config.get('apiKey') || ''
|
|
416
466
|
const verbose = cliArgs.verbose || config.get('verbose')
|
|
417
467
|
|