chatccc 0.2.77 → 0.2.79

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": "chatccc",
3
- "version": "0.2.77",
3
+ "version": "0.2.79",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -581,7 +581,7 @@ describe("createClaudeAdapter — sessionOpts 形状", () => {
581
581
  permissionMode: "bypassPermissions",
582
582
  allowDangerouslySkipPermissions: true,
583
583
  autoCompactEnabled: true,
584
- settingSources: ["project", "local"],
584
+ settingSources: ["user", "project", "local"],
585
585
  });
586
586
  });
587
587
 
@@ -856,7 +856,7 @@ describe("createClaudeAdapter — env 注入", () => {
856
856
  expect(opts.env.CLAUDE_CODE_EFFORT_LEVEL).toBeUndefined();
857
857
  });
858
858
 
859
- it("第三方 API 配置时仍然加载 CLAUDE.md(settingSources 始终为 project+local)", async () => {
859
+ it("第三方 API 配置时仍然加载 CLAUDE.md(settingSources 包含 user+project+local)", async () => {
860
860
  setupMockCreateSession();
861
861
  const adapter = createClaudeAdapter({
862
862
  model: "",
@@ -869,7 +869,7 @@ describe("createClaudeAdapter — env 注入", () => {
869
869
  await adapter.createSession("/cwd");
870
870
 
871
871
  const opts = sdk.unstable_v2_createSession.mock.calls[0][0];
872
- expect(opts.settingSources).toEqual(["project", "local"]);
872
+ expect(opts.settingSources).toEqual(["user", "project", "local"]);
873
873
  });
874
874
 
875
875
  it("不修改主进程 process.env(永不污染)", async () => {
@@ -117,10 +117,12 @@ function buildSdkEnv(
117
117
  function resolveSettingSources(
118
118
  _apiKey: string | undefined,
119
119
  _baseUrl: string | undefined,
120
- ): Array<"project" | "local"> {
120
+ ): Array<"user" | "project" | "local"> {
121
121
  // CLAUDE.md / CLAUDE.local.md 是 Agent 指令文件,与 API 来源无关,
122
122
  // 无论使用官方 Anthropic 还是第三方网关都应加载。
123
- return ["project", "local"];
123
+ // 包含 "user" 以使 ~/.claude/settings.json 中的配置(如 mcpServers)生效;
124
+ // buildSdkEnv() 会删除可能冲突的 env 变量,确保网关配置不被覆盖。
125
+ return ["user", "project", "local"];
124
126
  }
125
127
 
126
128
  // ---------------------------------------------------------------------------
@@ -100,6 +100,25 @@ export function pickDisplayChat(sessionId: string): string | undefined {
100
100
  return chats?.has(candidate) ? candidate : undefined;
101
101
  }
102
102
 
103
+ // ---------------------------------------------------------------------------
104
+ // queuePreservedChat: 队列消费时保留 display loop 目标 chat
105
+ // 队列消息来自其他群时,不应把 display loop 重定向到该群
106
+ // ---------------------------------------------------------------------------
107
+
108
+ const queuePreservedChatMap = new Map<string, string>();
109
+
110
+ /** 队列消费前保存当前 display chat,消费完后自动清除(一次性) */
111
+ export function setQueuePreservedChat(sessionId: string, chatId: string): void {
112
+ queuePreservedChatMap.set(sessionId, chatId);
113
+ }
114
+
115
+ /** 获取并清除队列保存的 display chat,没有则返回 undefined */
116
+ export function consumeQueuePreservedChat(sessionId: string): string | undefined {
117
+ const chat = queuePreservedChatMap.get(sessionId);
118
+ queuePreservedChatMap.delete(sessionId);
119
+ return chat;
120
+ }
121
+
103
122
  // ---------------------------------------------------------------------------
104
123
  // displayCards: chatId → 展示卡片状态(display loop 用)
105
124
  // ---------------------------------------------------------------------------
package/src/session.ts CHANGED
@@ -53,6 +53,8 @@ import {
53
53
  dequeueMessage,
54
54
  consumeQueuedMessage,
55
55
  cancelQueuedMessage,
56
+ setQueuePreservedChat,
57
+ consumeQueuePreservedChat,
56
58
  } from "./session-chat-binding.ts";
57
59
 
58
60
  // ---------------------------------------------------------------------------
@@ -680,8 +682,9 @@ export async function runAgentSession(
680
682
  const tid = traceId ?? "";
681
683
 
682
684
  // 记录用户最后发送消息的群(display loop 只推送到该群)
685
+ // 如果是从队列消费且队列消息来自其他群,保留原来的 display chat
683
686
  recordChatPlatform(_chatId, platform);
684
- recordLastActiveChat(sessionId, _chatId);
687
+ recordLastActiveChat(sessionId, consumeQueuePreservedChat(sessionId) ?? _chatId);
685
688
 
686
689
  // 并发检查:同一 session 只能有一个活跃 prompt
687
690
  if (activePrompts.has(sessionId)) {
@@ -859,12 +862,27 @@ export async function runAgentSession(
859
862
  activePrompts.delete(sessionId);
860
863
 
861
864
  // 消费队列中的缓存消息(异步,不阻塞后续清理)
862
- const queued = dequeueMessage(sessionId);
863
- if (queued) {
864
- console.log(`[${ts()}] [QUEUE] Consuming queued message for session ${sessionId}: "${queued.text.slice(0, 50)}"`);
865
- setImmediate(() => {
866
- consumeQueuedMessage(platform, queued);
867
- });
865
+ // 用户 /stop 后应丢弃队列消息,避免用户停止后又自动开始新轮
866
+ if (wasStopped) {
867
+ const discarded = dequeueMessage(sessionId);
868
+ if (discarded) {
869
+ console.log(`[${ts()}] [QUEUE] Discarding queued message for stopped session ${sessionId}`);
870
+ }
871
+ } else {
872
+ const queued = dequeueMessage(sessionId);
873
+ if (queued) {
874
+ // 队列消息可能来自其他群,保存当前 display chat 避免 display loop 被
875
+ // 错误重定向(runAgentSession 会 consumeQueuePreservedChat 并在存在时
876
+ // 用保存的 chat 替代 queued.chatId 作为 display 目标)
877
+ const preservedChat = getLastActiveChat(sessionId);
878
+ if (preservedChat && preservedChat !== queued.chatId) {
879
+ setQueuePreservedChat(sessionId, preservedChat);
880
+ }
881
+ console.log(`[${ts()}] [QUEUE] Consuming queued message for session ${sessionId}: "${queued.text.slice(0, 50)}"`);
882
+ setImmediate(() => {
883
+ consumeQueuedMessage(platform, queued);
884
+ });
885
+ }
868
886
  }
869
887
 
870
888
  // 写最终状态