@raolin2025/claude-code-node 2.6.14 → 2.6.15
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 +19 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raolin2025/claude-code-node",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.15",
|
|
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",
|
package/src/core/cli.js
CHANGED
|
@@ -933,17 +933,18 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
|
933
933
|
}
|
|
934
934
|
|
|
935
935
|
// ============================================================
|
|
936
|
-
//
|
|
937
|
-
// 把引擎 onDelta
|
|
936
|
+
// 流式推送 → Telegram
|
|
937
|
+
// 把引擎 onDelta 产出的生成内容(text / reasoning)实时推送到 Telegram,
|
|
938
938
|
// 让远程用户看到 AI 正在工作,而不是"以为没回应"。
|
|
939
939
|
// 采用节流 + 编辑同一消息的方式,避免刷屏和触发速率限制。
|
|
940
940
|
// ============================================================
|
|
941
|
-
const tgThinking = { buffer: '', timer: null, target: null, lastMsgId: null }
|
|
941
|
+
const tgThinking = { buffer: '', timer: null, target: null, lastMsgId: null, flushing: false }
|
|
942
942
|
|
|
943
943
|
function tgThinkingStart(target) {
|
|
944
944
|
tgThinking.target = target || null
|
|
945
945
|
tgThinking.buffer = ''
|
|
946
946
|
tgThinking.lastMsgId = null
|
|
947
|
+
tgThinking.flushing = false
|
|
947
948
|
// 先发送 typing 动作,让 Telegram 立即显示"正在输入"
|
|
948
949
|
if (tgListener?.bot && tgThinking.target) {
|
|
949
950
|
tgListener.bot.sendChatAction(tgThinking.target, 'typing').catch(() => {})
|
|
@@ -955,14 +956,17 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
|
955
956
|
tgThinking.buffer += text
|
|
956
957
|
// 只保留最近 8000 字符,避免无限增长
|
|
957
958
|
if (tgThinking.buffer.length > 8000) tgThinking.buffer = tgThinking.buffer.slice(-8000)
|
|
958
|
-
// 节流:2 秒内最多刷新一次
|
|
959
959
|
if (tgThinking.timer) clearTimeout(tgThinking.timer)
|
|
960
|
-
|
|
960
|
+
// 首帧快速发送(500ms 聚合首段),之后节流编辑(1.5s)
|
|
961
|
+
const delay = tgThinking.lastMsgId ? 1500 : 500
|
|
962
|
+
tgThinking.timer = setTimeout(() => tgThinkingFlush(), delay)
|
|
961
963
|
}
|
|
962
964
|
|
|
963
965
|
async function tgThinkingFlush() {
|
|
966
|
+
if (tgThinking.flushing) return // 防止并发
|
|
964
967
|
if (tgThinking.timer) { clearTimeout(tgThinking.timer); tgThinking.timer = null }
|
|
965
968
|
if (!tgListener?.bot || !tgThinking.target || !tgThinking.buffer) return
|
|
969
|
+
tgThinking.flushing = true
|
|
966
970
|
const target = tgThinking.target
|
|
967
971
|
const body = `🧠 思考中…\n\n${tgThinking.buffer.slice(-3500)}`
|
|
968
972
|
try {
|
|
@@ -979,6 +983,8 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
|
979
983
|
const res = await tgListener.bot.sendMessage(target, body, { parseMode: 'HTML' })
|
|
980
984
|
tgThinking.lastMsgId = res?.message_id || null
|
|
981
985
|
} catch {}
|
|
986
|
+
} finally {
|
|
987
|
+
tgThinking.flushing = false
|
|
982
988
|
}
|
|
983
989
|
}
|
|
984
990
|
|
|
@@ -987,6 +993,7 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
|
987
993
|
tgThinking.buffer = ''
|
|
988
994
|
tgThinking.lastMsgId = null
|
|
989
995
|
tgThinking.target = null
|
|
996
|
+
tgThinking.flushing = false
|
|
990
997
|
}
|
|
991
998
|
|
|
992
999
|
// REPL 主循环 — 由 readline 原生处理回显、退格、行回绕与 Enter 提交
|
|
@@ -1101,20 +1108,17 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
|
|
|
1101
1108
|
}
|
|
1102
1109
|
|
|
1103
1110
|
// ============================================================
|
|
1104
|
-
// 引擎流式回调 — 保持 CLI
|
|
1111
|
+
// 引擎流式回调 — 保持 CLI 实时输出,并把生成内容推送到 Telegram
|
|
1105
1112
|
// onDelta 会在流式生成时被调用({type:'text'|'reasoning', text})。
|
|
1113
|
+
// 注意:DeepSeek 模型 thinking 被禁用时只有 text 事件、没有 reasoning,
|
|
1114
|
+
// 因此 text 也必须推送到 Telegram,否则远程看不到任何进度。
|
|
1106
1115
|
// 设置 onDelta 后引擎不再直接写终端,因此这里需手动维持终端输出。
|
|
1107
1116
|
// ============================================================
|
|
1108
1117
|
engine.config.onDelta = ({ type, text }) => {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
// CLI 也显示思维链
|
|
1114
|
-
process.stdout.write(text)
|
|
1115
|
-
// 实时推送到 Telegram(节流)
|
|
1116
|
-
tgThinkingPush(text)
|
|
1117
|
-
}
|
|
1118
|
+
// 保持 CLI 实时输出
|
|
1119
|
+
process.stdout.write(text)
|
|
1120
|
+
// 无论 text 还是 reasoning,都实时推送到 Telegram(节流)
|
|
1121
|
+
tgThinkingPush(text)
|
|
1118
1122
|
}
|
|
1119
1123
|
|
|
1120
1124
|
console.log(buildBanner({ model, permissionMode, session, maxTokens: tokenBudget.maxTokens }))
|