@raolin2025/claude-code-node 2.8.22 → 2.8.23
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/__tests__/small-model.test.js +12 -3
- package/src/core/small-model.js +35 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raolin2025/claude-code-node",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.23",
|
|
4
4
|
"description": "Node.js AI Code Agent CLI - Zero dependencies, pure JavaScript, security hardened, multi-channel notifications, Telegram & QQ Bot remote programming, rich media upload, multi-account management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/core/index.js",
|
|
@@ -127,10 +127,19 @@ test('工具精简:未启用返回全部', () => {
|
|
|
127
127
|
assert.equal(selectRelevantTools(fakeTools, 'xx', { enable: false }), fakeTools)
|
|
128
128
|
})
|
|
129
129
|
|
|
130
|
-
test('
|
|
130
|
+
test('工具精简:无明确意图时返回全部工具(让模型自己挑)', () => {
|
|
131
131
|
const reduced = selectRelevantTools(fakeTools, '你好', { enable: true })
|
|
132
|
-
|
|
133
|
-
assert.
|
|
132
|
+
// 实测经验:小模型不能过度精简工具,无明确适配时干脆全部给
|
|
133
|
+
assert.equal(reduced.length, fakeTools.length, '无明确意图应返回全部工具')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('工具精简:有明确意图时至少保留 6 个核心工具', () => {
|
|
137
|
+
const reduced = selectRelevantTools(fakeTools, '阅读D:\\x\\COMPLETION_REPORT.md', { enable: true })
|
|
138
|
+
// 至少 6 个核心工具,绝不精简到 2 个
|
|
139
|
+
assert.ok(reduced.length >= 6, `应至少保留 6 个工具(实际 ${reduced.length})`)
|
|
140
|
+
assert.ok(reduced.some(t => t.name === 'Read'))
|
|
141
|
+
assert.ok(reduced.some(t => t.name === 'Bash'), '应保留 Bash')
|
|
142
|
+
assert.ok(reduced.some(t => t.name === 'Write'), '应保留 Write')
|
|
134
143
|
})
|
|
135
144
|
|
|
136
145
|
// ---- system prompt 强化 ----
|
package/src/core/small-model.js
CHANGED
|
@@ -377,32 +377,53 @@ export function buildCombinedGuidance(userInput, opts = {}) {
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
|
-
*
|
|
380
|
+
* 工具选择(层 A)— 小模型适配的关键经验
|
|
381
381
|
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
382
|
+
* 重要结论(来自实测):**小模型工具调用不能过度精简**。
|
|
383
|
+
* v2.8.12 之前(16 个工具全上)模型能正常调用工具;v2.8.13 之后我做了"按意图
|
|
384
|
+
* 精简成 2-6 个",结果模型反而不调用工具、只会瞎编。因此策略改为:
|
|
385
|
+
*
|
|
386
|
+
* 1. **保底至少 6 个核心工具**:Bash, Read, Edit, Write, Glob, Grep(每次必给);
|
|
387
|
+
* 2. **按任务适配追加**:若意图明确需要额外工具(联网→WebSearch/WebFetch 等),
|
|
388
|
+
* 在核心 6 个之上追加,绝不减少核心集;
|
|
389
|
+
* 3. **找不到合适的适配,就全部给**:宁可全给 16 个,也不要精简到很少。
|
|
390
|
+
*
|
|
391
|
+
* 原则:**工具给全,让模型自己挑;而不是替它精简,导致它无工具可用而瞎编。**
|
|
384
392
|
*
|
|
385
393
|
* @param {Array} allTools — 完整 ToolDef 列表
|
|
386
394
|
* @param {string} userInput — 用户指令
|
|
387
395
|
* @param {object} [opts]
|
|
388
|
-
* @param {boolean} [opts.enable=true] —
|
|
389
|
-
* @returns {Array}
|
|
396
|
+
* @param {boolean} [opts.enable=true] — 是否启用适配
|
|
397
|
+
* @returns {Array} 选择后的工具列表(至少 6 个核心;找不到适配则全部)
|
|
390
398
|
*/
|
|
391
399
|
export function selectRelevantTools(allTools, userInput, opts = {}) {
|
|
392
400
|
if (opts.enable === false) return allTools
|
|
393
401
|
if (!allTools || allTools.length === 0) return allTools
|
|
394
402
|
|
|
403
|
+
// 核心工具保底集(每次必给):小模型不能过度精简工具,否则不会调用只会瞎编
|
|
404
|
+
const CORE = ['Bash', 'Read', 'Edit', 'Write', 'Glob', 'Grep']
|
|
395
405
|
const intent = detectIntent(userInput)
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
// 核心工具优先,保留指定工具;若一个都没命中则退回首屏核心集
|
|
402
|
-
const selected = allTools.filter(t => coreNames.includes(t.name))
|
|
403
|
-
if (selected.length === 0) {
|
|
404
|
-
return allTools.filter(t => ['Bash', 'Read', 'Edit', 'Write', 'Glob', 'Grep'].includes(t.name))
|
|
406
|
+
|
|
407
|
+
// 找不到合适的适配(无明确意图)→ 干脆全部调用,让模型自己挑。
|
|
408
|
+
// 这是实测经验:v2.8.12 之前全 16 个工具模型能正常调用;精简后反而变傻。
|
|
409
|
+
if (!intent) {
|
|
410
|
+
return allTools
|
|
405
411
|
}
|
|
412
|
+
|
|
413
|
+
// 有明确意图 → 核心 6 个(保底)+ 意图命中的额外工具(追加,不减少核心)
|
|
414
|
+
const toolNames = new Set(CORE)
|
|
415
|
+
if (intent.toolHint) {
|
|
416
|
+
for (const name of intent.toolHint.split(',').map(s => s.trim())) {
|
|
417
|
+
toolNames.add(name)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const selected = allTools.filter(t => toolNames.has(t.name))
|
|
421
|
+
|
|
422
|
+
// 兜底:筛选不足 6 个(核心工具不全)→ 全给
|
|
423
|
+
if (selected.length < 6) {
|
|
424
|
+
return allTools
|
|
425
|
+
}
|
|
426
|
+
|
|
406
427
|
return selected
|
|
407
428
|
}
|
|
408
429
|
|