@raolin2025/claude-code-node 2.6.3 → 2.6.5

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.3",
3
+ "version": "2.6.5",
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",
@@ -273,6 +273,8 @@ export class TelegramListener {
273
273
  this._pollTimer = null
274
274
  this._retryDelay = 1000
275
275
  this.maxRetryDelay = 30000
276
+ this._lastPollError = null // 最近一次轮询错误消息(用于去抖刷屏)
277
+ this._lastPollErrorAt = 0 // 最近一次轮询错误时间戳
276
278
  this.conversations = new ConversationState()
277
279
  this._onMessage = null
278
280
  this._handlers = {}
@@ -323,6 +325,9 @@ export class TelegramListener {
323
325
  const res = await this._fetch(url, {
324
326
  method: 'POST',
325
327
  headers: { 'Content-Type': 'application/json' },
328
+ // 长轮询本身最多等 30s(Telegram API 参数),HTTP 层超时必须更长,
329
+ // 否则代理路径(fetchViaSocks5)30s 硬超时会误杀长轮询 → HTTP request timeout 刷屏。
330
+ timeout: 60000,
326
331
  body: JSON.stringify({
327
332
  offset: this.lastUpdateId + 1,
328
333
  timeout: 30,
@@ -360,7 +365,17 @@ export class TelegramListener {
360
365
  this._retryDelay = 1000
361
366
 
362
367
  } catch (e) {
363
- log(`[TG] Poll error: ${e.message} (retry in ${this._retryDelay}ms)`)
368
+ // 错误去抖:连续相同的错误(如长轮询超时)只在首次/状态变化时打印,
369
+ // 避免 AI 处理长任务时 getUpdates 空转超时不断刷屏。
370
+ const msg = e.message || 'unknown'
371
+ const now = Date.now()
372
+ const isSame = msg === this._lastPollError
373
+ const isRecent = (now - (this._lastPollErrorAt || 0)) < 60000
374
+ if (!isSame || !isRecent) {
375
+ log(`[TG] Poll error: ${msg} (retry in ${this._retryDelay}ms)`)
376
+ this._lastPollError = msg
377
+ this._lastPollErrorAt = now
378
+ }
364
379
  await this._sleep(this._retryDelay)
365
380
  this._retryDelay = Math.min(this._retryDelay * 2, this.maxRetryDelay)
366
381
  }
@@ -271,10 +271,13 @@ export async function fetchViaSocks5(url, options = {}, proxyAddr) {
271
271
 
272
272
  return new Promise((resolve, reject) => {
273
273
  let responseData = ''
274
+ // 超时可配置(options.timeout,毫秒),默认 30s。
275
+ // Telegram getUpdates 是长轮询(最多等 30s),必须传更大的超时避免误判超时。
276
+ const timeoutMs = options.timeout || 30000
274
277
  const timeout = setTimeout(() => {
275
278
  socket.destroy()
276
279
  reject(new Error('HTTP request timeout'))
277
- }, 30000)
280
+ }, timeoutMs)
278
281
 
279
282
  socket.write(reqBuf)
280
283
  socket.on('data', (chunk) => {
package/src/core/cli.js CHANGED
@@ -907,7 +907,9 @@ const systemPrompt = cliArgs.systemPrompt || DEFAULT_SYSTEM_PROMPT
907
907
  // - Telegram 消息会作为 REPL 输入,与 CLI 共享同一个引擎和对话记忆
908
908
  // ============================================================
909
909
  const tgToken = process.env.CC_NODE_CHANNEL_TELEGRAM_TOKEN || config.get('channels')?.telegram?.token || ''
910
- if (tgToken) {
910
+ // 关键修复: 使用 --with-notify 时,由 startBuiltinListeners 统一启动 Telegram 监听器,
911
+ // 这里不能再独立启动一个,否则同一 token 会有两个 getUpdates 长轮询 → Telegram 报 HTTP 409 Conflict。
912
+ if (tgToken && !cliArgs.withNotify) {
911
913
  try {
912
914
  tgListener = new TelegramListener({
913
915
  channels: {