chatccc 0.2.201 → 0.2.203

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.
Files changed (95) hide show
  1. package/README.md +23 -21
  2. package/agent-prompts/claude_specific.md +45 -45
  3. package/agent-prompts/codex_specific.md +2 -2
  4. package/agent-prompts/cursor_specific.md +13 -13
  5. package/bin/cccagent.mjs +17 -17
  6. package/config.sample.json +27 -27
  7. package/im-skills/feishu-skill/receive-send-file.md +63 -63
  8. package/im-skills/feishu-skill/receive-send-image.md +24 -24
  9. package/im-skills/feishu-skill/skill.md +3 -3
  10. package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
  11. package/im-skills/wechat-file-skill/send-file.mjs +83 -83
  12. package/im-skills/wechat-file-skill/skill.md +10 -10
  13. package/im-skills/wechat-image-skill/skill.md +10 -10
  14. package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
  15. package/im-skills/wechat-video-skill/send-video.mjs +79 -79
  16. package/im-skills/wechat-video-skill/skill.md +10 -10
  17. package/package.json +1 -1
  18. package/scripts/postinstall-sharp-check.mjs +58 -58
  19. package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
  20. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  21. package/src/__tests__/builtin-chat-session.test.ts +277 -277
  22. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  23. package/src/__tests__/builtin-config.test.ts +33 -33
  24. package/src/__tests__/builtin-context.test.ts +163 -163
  25. package/src/__tests__/builtin-file-tools.test.ts +224 -224
  26. package/src/__tests__/builtin-session-select.test.ts +116 -116
  27. package/src/__tests__/builtin-sigint.test.ts +56 -56
  28. package/src/__tests__/card-plain-text.test.ts +5 -5
  29. package/src/__tests__/cardkit.test.ts +60 -60
  30. package/src/__tests__/cards.test.ts +133 -122
  31. package/src/__tests__/ccc-adapter.test.ts +114 -114
  32. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  33. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  34. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  35. package/src/__tests__/claude-adapter.test.ts +592 -592
  36. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  37. package/src/__tests__/codex-raw-stream-log.test.ts +163 -163
  38. package/src/__tests__/codex-reset-actions.test.ts +146 -146
  39. package/src/__tests__/config-reload.test.ts +10 -10
  40. package/src/__tests__/config-sample.test.ts +18 -18
  41. package/src/__tests__/cursor-adapter.test.ts +226 -226
  42. package/src/__tests__/feishu-api.test.ts +60 -60
  43. package/src/__tests__/feishu-avatar.test.ts +90 -90
  44. package/src/__tests__/feishu-platform.test.ts +22 -22
  45. package/src/__tests__/format-message.test.ts +47 -47
  46. package/src/__tests__/jsonl-stream.test.ts +79 -79
  47. package/src/__tests__/orchestrator.test.ts +464 -301
  48. package/src/__tests__/privacy.test.ts +198 -198
  49. package/src/__tests__/raw-stream-log.test.ts +106 -106
  50. package/src/__tests__/session.test.ts +46 -44
  51. package/src/__tests__/shared-prefix.test.ts +36 -36
  52. package/src/__tests__/sim-platform.test.ts +12 -12
  53. package/src/__tests__/stream-state.test.ts +42 -42
  54. package/src/__tests__/update-command-guard.test.ts +144 -0
  55. package/src/__tests__/web-ui.test.ts +209 -209
  56. package/src/adapters/ccc-adapter.ts +121 -121
  57. package/src/adapters/claude-adapter.ts +603 -603
  58. package/src/adapters/claude-session-meta-store.ts +120 -120
  59. package/src/adapters/codex-adapter.ts +380 -380
  60. package/src/adapters/cursor-adapter.ts +673 -673
  61. package/src/adapters/jsonl-stream.ts +157 -157
  62. package/src/adapters/raw-stream-log.ts +124 -124
  63. package/src/adapters/resource-monitor.ts +140 -140
  64. package/src/agent-delegate-task-rpc.ts +153 -153
  65. package/src/agent-delegate-task.ts +81 -81
  66. package/src/agent-reload-config-rpc.ts +34 -34
  67. package/src/agent-stop-stuck.ts +129 -129
  68. package/src/builtin/cli.ts +473 -473
  69. package/src/builtin/context.ts +323 -323
  70. package/src/builtin/file-tools.ts +1072 -1072
  71. package/src/builtin/index.ts +404 -404
  72. package/src/builtin/session-select.ts +48 -48
  73. package/src/builtin/sigint.ts +50 -50
  74. package/src/cards.ts +222 -210
  75. package/src/chatgpt-subscription-rpc.ts +27 -27
  76. package/src/chatgpt-subscription.ts +299 -299
  77. package/src/chrome-devtools-guard.ts +318 -318
  78. package/src/codex-reset-actions.ts +184 -184
  79. package/src/config.ts +125 -125
  80. package/src/feishu-api.ts +118 -118
  81. package/src/feishu-platform.ts +20 -20
  82. package/src/format-message.ts +293 -293
  83. package/src/index.ts +48 -9
  84. package/src/litellm-proxy.ts +374 -374
  85. package/src/orchestrator.ts +391 -346
  86. package/src/privacy.ts +118 -118
  87. package/src/runtime-reload.ts +34 -34
  88. package/src/session-chat-binding.ts +6 -6
  89. package/src/session-name.ts +8 -8
  90. package/src/session.ts +177 -169
  91. package/src/shared-prefix.ts +29 -29
  92. package/src/sim-platform.ts +20 -20
  93. package/src/turn-cards.ts +117 -117
  94. package/src/update-command-guard.ts +165 -0
  95. package/src/web-ui.ts +205 -205
package/src/index.ts CHANGED
@@ -189,16 +189,21 @@ function getInnerEvent(data: Evt): InnerEvent {
189
189
  return (data.event ?? data) as InnerEvent;
190
190
  }
191
191
 
192
- import { formatMessageContent } from "./format-message.ts";
192
+ import { formatMessageContent } from "./format-message.ts";
193
+ import {
194
+ buildUpdateCommandId,
195
+ extractFeishuEventId,
196
+ } from "./update-command-guard.ts";
193
197
 
194
198
  // ---------------------------------------------------------------------------
195
199
  // Card action helper: parse button click into text command
196
200
  // ---------------------------------------------------------------------------
197
201
 
198
- interface CardActionResult {
199
- text: string;
200
- chatId: string;
201
- openId: string;
202
+ interface CardActionResult {
203
+ text: string;
204
+ chatId: string;
205
+ openId: string;
206
+ commandId?: string;
202
207
  }
203
208
 
204
209
  function parseCardAction(data: unknown): CardActionResult | null {
@@ -237,7 +242,12 @@ function parseCardAction(data: unknown): CardActionResult | null {
237
242
  ((raw as Record<string, unknown>).operator as Record<string, unknown>)?.open_id as string ??
238
243
  "";
239
244
 
240
- return { text, chatId, openId };
245
+ return {
246
+ text,
247
+ chatId,
248
+ openId,
249
+ commandId: buildUpdateCommandId("card", extractFeishuEventId(data)),
250
+ };
241
251
  }
242
252
 
243
253
  // ---------------------------------------------------------------------------
@@ -432,7 +442,18 @@ async function startBotServiceCore(): Promise<void> {
432
442
  const delayToken = await getTenantAccessToken();
433
443
  await sendCardReply(delayToken, chatId, "延迟送达", delayNotice, "yellow").catch(() => {});
434
444
  }
435
- await handleCommand(feishuPlatform, text, chatId, openId, msgTimestamp, chatType, traceId);
445
+ // `/update` 会使用这个稳定 ID 做跨重启幂等;其他命令仍沿用
446
+ // processedMessages 的进程内去重。
447
+ await handleCommand(
448
+ feishuPlatform,
449
+ text,
450
+ chatId,
451
+ openId,
452
+ msgTimestamp,
453
+ chatType,
454
+ traceId,
455
+ buildUpdateCommandId("message", messageId),
456
+ );
436
457
  } catch (err) {
437
458
  logTrace(traceId, "ERROR", { message: (err as Error).message });
438
459
  console.error(`[${ts()}] [FATAL] im.message.receive_v1 handler crashed: ${(err as Error).message}`);
@@ -483,7 +504,16 @@ async function startBotServiceCore(): Promise<void> {
483
504
  const result = parseCardAction(data);
484
505
  if (!result) return;
485
506
  console.log(`[BTN] chat=${result.chatId} text="${result.text}"`);
486
- handleCommand(feishuPlatform, result.text, result.chatId, result.openId, Date.now()).catch((err) =>
507
+ handleCommand(
508
+ feishuPlatform,
509
+ result.text,
510
+ result.chatId,
511
+ result.openId,
512
+ Date.now(),
513
+ "group",
514
+ undefined,
515
+ result.commandId,
516
+ ).catch((err) =>
487
517
  console.error(`[${ts()}] [BTN] handleCommand failed: ${(err as Error).message}`)
488
518
  );
489
519
  } catch (err) {
@@ -508,7 +538,16 @@ async function startBotServiceCore(): Promise<void> {
508
538
  const data = JSON.parse(raw.toString()) as Evt;
509
539
  const action = parseCardAction(data);
510
540
  if (action) {
511
- handleCommand(feishuPlatform, action.text, action.chatId, action.openId, Date.now()).catch((err) =>
541
+ handleCommand(
542
+ feishuPlatform,
543
+ action.text,
544
+ action.chatId,
545
+ action.openId,
546
+ Date.now(),
547
+ "group",
548
+ undefined,
549
+ action.commandId,
550
+ ).catch((err) =>
512
551
  console.error(`[${ts()}] [BTN] handleCommand failed: ${(err as Error).message}`)
513
552
  );
514
553
  return;