@raolin2025/claude-code-node 2.6.11 → 2.6.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raolin2025/claude-code-node",
3
- "version": "2.6.11",
3
+ "version": "2.6.13",
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",
@@ -275,6 +275,7 @@ export class TelegramListener {
275
275
  this.maxRetryDelay = 30000
276
276
  this._lastPollError = null // 最近一次轮询错误消息(用于去抖刷屏)
277
277
  this._lastPollErrorAt = 0 // 最近一次轮询错误时间戳
278
+ this._msgQueue = Promise.resolve() // 消息串行处理队列(避免阻塞轮询循环)
278
279
  this.conversations = new ConversationState()
279
280
  this._onMessage = null
280
281
  this._handlers = {}
@@ -348,15 +349,17 @@ export class TelegramListener {
348
349
  for (const update of data.result) {
349
350
  this.lastUpdateId = Math.max(this.lastUpdateId, update.update_id)
350
351
 
351
- // 处理回调查询(内联键盘按钮)
352
+ // 处理回调查询(按钮点击)— 快速操作,直接 await
352
353
  if (update.callback_query) {
353
354
  await this._handleCallbackQuery(update.callback_query)
354
355
  continue
355
356
  }
356
357
 
357
- // 处理消息
358
+ // 处理消息 — 加入串行队列异步处理,不阻塞轮询循环。
359
+ // 否则 AI 处理上一条消息时(可能很久),getUpdates 无法继续接收
360
+ // 新消息(如权限确认回复 a、/quit 等)。
358
361
  if (update.message) {
359
- await this._handleMessage(update.message)
362
+ this._enqueueMessage(update.message)
360
363
  }
361
364
  }
362
365
  }
@@ -382,6 +385,18 @@ export class TelegramListener {
382
385
  }
383
386
  }
384
387
 
388
+ /** 异步处理一条消息(不串行排队,避免权限确认死锁) */
389
+ _enqueueMessage(msg) {
390
+ // 关键:不能串行排队等待前一条消息处理完。
391
+ // 若第一条消息触发权限确认而挂起(await pendingConfirm),
392
+ // 后续的权限确认回复 a 会排在后面积压,造成死锁(a 永远处理不到)。
393
+ // 因此每条消息独立异步处理:权限确认回复能立即响应,普通消息由
394
+ // processInputLine 内部处理"引擎忙"的情况。
395
+ this._handleMessage(msg).catch((e) => {
396
+ log(`[TG] handle error: ${e.message}`)
397
+ })
398
+ }
399
+
385
400
  /** 处理消息 */
386
401
  async _handleMessage(msg) {
387
402
  const chatId = msg.chat?.id
package/src/core/cli.js CHANGED
@@ -855,6 +855,16 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
855
855
  return
856
856
  }
857
857
 
858
+ // 发送到引擎 — 引擎忙(如正在处理上一条消息)时,提示而不是崩溃/吞掉
859
+ if (engine.state.isRunning) {
860
+ const busyMsg = '⏳ 引擎正在处理其他任务,请稍候或输入 /stop 停止当前任务。'
861
+ console.log(busyMsg)
862
+ if (source === 'telegram' && tgListener?.bot) {
863
+ await sendTelegram(busyMsg, tgChatId || null).catch(() => {})
864
+ }
865
+ return
866
+ }
867
+
858
868
  // 发送到引擎
859
869
  try {
860
870
  const result = await processInput(input)