chatccc 0.2.252 → 0.2.253
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/README.md +1 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- package/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package.json +65 -65
- package/dist/deepccc-agent/src/cli.js +634 -0
- package/dist/deepccc-agent/src/config.js +76 -0
- package/dist/deepccc-agent/src/context.js +348 -0
- package/dist/deepccc-agent/src/file-log.js +34 -0
- package/dist/deepccc-agent/src/file-tools.js +1208 -0
- package/dist/deepccc-agent/src/index.js +571 -0
- package/dist/deepccc-agent/src/permissions.js +170 -0
- package/dist/deepccc-agent/src/privacy.js +124 -0
- package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
- package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
- package/dist/deepccc-agent/src/progress/reducer.js +102 -0
- package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
- package/dist/deepccc-agent/src/progress/view.js +30 -0
- package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
- package/dist/deepccc-agent/src/session-search.js +276 -0
- package/dist/deepccc-agent/src/session-select.js +23 -0
- package/dist/deepccc-agent/src/sigint.js +26 -0
- package/dist/deepccc-agent/src/skills.js +178 -0
- package/dist/deepccc-agent/src/web-tools.js +246 -0
- package/dist/src/adapters/adapter-interface.js +19 -0
- package/dist/src/adapters/ccc-adapter.js +112 -0
- package/dist/src/adapters/claude-adapter.js +497 -0
- package/dist/src/adapters/claude-session-meta-store.js +92 -0
- package/dist/src/adapters/codex-adapter.js +279 -0
- package/dist/src/adapters/codex-session-meta-store.js +94 -0
- package/dist/src/adapters/cursor-adapter.js +491 -0
- package/dist/src/adapters/cursor-session-meta-store.js +116 -0
- package/dist/src/adapters/jsonl-stream.js +104 -0
- package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
- package/dist/src/adapters/raw-stream-log.js +106 -0
- package/dist/src/adapters/resource-monitor.js +113 -0
- package/dist/src/agent-activity.js +133 -0
- package/dist/src/agent-delegate-task-rpc.js +129 -0
- package/dist/src/agent-delegate-task.js +48 -0
- package/dist/src/agent-file-rpc.js +152 -0
- package/dist/src/agent-image-rpc.js +148 -0
- package/dist/src/agent-platform-routing.js +13 -0
- package/dist/src/agent-reload-config-rpc.js +23 -0
- package/dist/src/agent-rpc-body.js +87 -0
- package/dist/src/agent-stop-stuck.js +110 -0
- package/dist/src/card-action-routing.js +7 -0
- package/dist/src/card-plain-text.js +101 -0
- package/dist/src/cardkit.js +158 -0
- package/dist/src/cards.js +573 -0
- package/dist/src/chatgpt-subscription-rpc.js +18 -0
- package/dist/src/chatgpt-subscription.js +199 -0
- package/dist/src/chrome-devtools-guard.js +238 -0
- package/dist/src/claude-sdk-installer.js +249 -0
- package/dist/src/codex-reset-actions.js +143 -0
- package/dist/src/config-utils.js +149 -0
- package/dist/src/config.js +804 -0
- package/dist/src/cursor-usage.js +77 -0
- package/dist/src/exit-banner.js +28 -0
- package/dist/src/feishu-api.js +1404 -0
- package/dist/src/feishu-message-ingress.js +137 -0
- package/dist/src/feishu-platform.js +97 -0
- package/dist/src/format-message.js +252 -0
- package/dist/src/git-command.js +155 -0
- package/dist/src/im-skills.js +121 -0
- package/dist/src/index.js +833 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2078 -0
- package/dist/src/package-root.js +26 -0
- package/dist/src/platform-adapter.js +7 -0
- package/dist/src/platform-startup.js +6 -0
- package/dist/src/privacy.js +100 -0
- package/dist/src/progress/reducer.js +102 -0
- package/dist/src/progress/terminal-renderer.js +264 -0
- package/dist/src/progress/view.js +30 -0
- package/dist/src/response-stall.js +14 -0
- package/dist/src/runtime-entry.js +13 -0
- package/dist/src/runtime-reload.js +19 -0
- package/dist/src/session-chat-binding.js +183 -0
- package/dist/src/session-name.js +7 -0
- package/dist/src/session.js +2144 -0
- package/dist/src/shared-prefix.js +16 -0
- package/dist/src/shared.js +493 -0
- package/dist/src/sim-agent.js +105 -0
- package/dist/src/sim-platform.js +142 -0
- package/dist/src/sim-store.js +231 -0
- package/dist/src/simplify.js +99 -0
- package/dist/src/startup-lifecycle.js +209 -0
- package/dist/src/stream-state.js +141 -0
- package/dist/src/terminal-error.js +100 -0
- package/dist/src/trace.js +50 -0
- package/dist/src/turn-cards.js +92 -0
- package/dist/src/update-command-guard.js +114 -0
- package/{src/web-ui.ts → dist/src/web-ui.js} +749 -823
- package/dist/src/wechat-platform.js +545 -0
- package/package.json +76 -74
- package/deepccc-agent/LICENSE +0 -201
- package/deepccc-agent/bin/deepccc.mjs +0 -26
- package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
- package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
- package/deepccc-agent/package-lock.json +0 -2027
- package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
- package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
- package/deepccc-agent/src/__tests__/config.test.ts +0 -34
- package/deepccc-agent/src/__tests__/context.test.ts +0 -341
- package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
- package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
- package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
- package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
- package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
- package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
- package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
- package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
- package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
- package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
- package/deepccc-agent/src/cli.ts +0 -682
- package/deepccc-agent/src/config.ts +0 -101
- package/deepccc-agent/src/context.ts +0 -465
- package/deepccc-agent/src/file-log.ts +0 -38
- package/deepccc-agent/src/file-tools.ts +0 -1493
- package/deepccc-agent/src/index.ts +0 -710
- package/deepccc-agent/src/permissions.ts +0 -226
- package/deepccc-agent/src/privacy.ts +0 -141
- package/deepccc-agent/src/proc-tree-kill.ts +0 -61
- package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
- package/deepccc-agent/src/progress/reducer.ts +0 -113
- package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
- package/deepccc-agent/src/progress/view.ts +0 -77
- package/deepccc-agent/src/raw-stream-log.ts +0 -124
- package/deepccc-agent/src/session-search.ts +0 -370
- package/deepccc-agent/src/session-select.ts +0 -48
- package/deepccc-agent/src/sigint.ts +0 -50
- package/deepccc-agent/src/skills.ts +0 -205
- package/deepccc-agent/src/web-tools.ts +0 -313
- package/deepccc-agent/tsconfig.build.json +0 -13
- package/deepccc-agent/tsconfig.json +0 -13
- package/deepccc-agent/vitest.config.ts +0 -7
- package/src/__tests__/adapter-interface.test.ts +0 -152
- package/src/__tests__/agent-activity.test.ts +0 -86
- package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
- package/src/__tests__/agent-image-rpc.test.ts +0 -34
- package/src/__tests__/agent-platform-routing.test.ts +0 -26
- package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
- package/src/__tests__/agent-rpc-body.test.ts +0 -42
- package/src/__tests__/builtin-chat-session.test.ts +0 -532
- package/src/__tests__/builtin-cli-json.test.ts +0 -39
- package/src/__tests__/builtin-config.test.ts +0 -26
- package/src/__tests__/builtin-context.test.ts +0 -319
- package/src/__tests__/builtin-file-tools.test.ts +0 -240
- package/src/__tests__/builtin-permissions.test.ts +0 -219
- package/src/__tests__/builtin-session-search.test.ts +0 -262
- package/src/__tests__/builtin-session-select.test.ts +0 -116
- package/src/__tests__/builtin-sigint.test.ts +0 -56
- package/src/__tests__/builtin-skills.test.ts +0 -284
- package/src/__tests__/builtin-web-tools.test.ts +0 -220
- package/src/__tests__/card-action-routing.test.ts +0 -18
- package/src/__tests__/card-plain-text.test.ts +0 -45
- package/src/__tests__/cardkit.test.ts +0 -60
- package/src/__tests__/cards.test.ts +0 -607
- package/src/__tests__/ccc-adapter.test.ts +0 -194
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
- package/src/__tests__/chatgpt-subscription.test.ts +0 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
- package/src/__tests__/claude-adapter.test.ts +0 -614
- package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
- package/src/__tests__/claude-sdk-installer.test.ts +0 -285
- package/src/__tests__/codex-adapter.test.ts +0 -331
- package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
- package/src/__tests__/codex-reset-actions.test.ts +0 -146
- package/src/__tests__/config-reload.test.ts +0 -284
- package/src/__tests__/config-sample.test.ts +0 -97
- package/src/__tests__/config-utils.test.ts +0 -40
- package/src/__tests__/config.test.ts +0 -395
- package/src/__tests__/crash-logging.test.ts +0 -360
- package/src/__tests__/cursor-adapter.test.ts +0 -890
- package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
- package/src/__tests__/feishu-api.test.ts +0 -60
- package/src/__tests__/feishu-avatar.test.ts +0 -504
- package/src/__tests__/feishu-message-ingress.test.ts +0 -138
- package/src/__tests__/feishu-platform.test.ts +0 -75
- package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
- package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
- package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
- package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
- package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
- package/src/__tests__/format-message.test.ts +0 -316
- package/src/__tests__/git-command.test.ts +0 -288
- package/src/__tests__/im-skills.test.ts +0 -125
- package/src/__tests__/jsonl-stream.test.ts +0 -79
- package/src/__tests__/orchestrator.test.ts +0 -1268
- package/src/__tests__/package-files.test.ts +0 -24
- package/src/__tests__/platform-startup.test.ts +0 -19
- package/src/__tests__/privacy.test.ts +0 -198
- package/src/__tests__/proc-tree-kill.test.ts +0 -108
- package/src/__tests__/progress-reducer.test.ts +0 -121
- package/src/__tests__/raw-stream-log.test.ts +0 -106
- package/src/__tests__/response-stall.test.ts +0 -49
- package/src/__tests__/restart.test.ts +0 -232
- package/src/__tests__/session-ccc-config.test.ts +0 -66
- package/src/__tests__/session.test.ts +0 -3004
- package/src/__tests__/shared-prefix.test.ts +0 -36
- package/src/__tests__/sim-agent.test.ts +0 -174
- package/src/__tests__/sim-platform.test.ts +0 -93
- package/src/__tests__/sim-store.test.ts +0 -214
- package/src/__tests__/simplify.test.ts +0 -283
- package/src/__tests__/startup-lifecycle.test.ts +0 -231
- package/src/__tests__/stop-session.test.ts +0 -162
- package/src/__tests__/stream-state.test.ts +0 -164
- package/src/__tests__/terminal-error.test.ts +0 -54
- package/src/__tests__/terminal-renderer.test.ts +0 -247
- package/src/__tests__/update-command-guard.test.ts +0 -144
- package/src/__tests__/web-ui.test.ts +0 -438
- package/src/__tests__/wechat-platform.test.ts +0 -111
- package/src/adapters/adapter-interface.ts +0 -217
- package/src/adapters/ccc-adapter.ts +0 -150
- package/src/adapters/claude-adapter.ts +0 -673
- package/src/adapters/claude-session-meta-store.ts +0 -120
- package/src/adapters/codex-adapter.ts +0 -426
- package/src/adapters/codex-session-meta-store.ts +0 -131
- package/src/adapters/cursor-adapter.ts +0 -681
- package/src/adapters/cursor-session-meta-store.ts +0 -154
- package/src/adapters/jsonl-stream.ts +0 -157
- package/src/adapters/raw-stream-log.ts +0 -124
- package/src/adapters/resource-monitor.ts +0 -141
- package/src/agent-activity.ts +0 -175
- package/src/agent-delegate-task-rpc.ts +0 -153
- package/src/agent-delegate-task.ts +0 -91
- package/src/agent-file-rpc.ts +0 -172
- package/src/agent-image-rpc.ts +0 -168
- package/src/agent-platform-routing.ts +0 -28
- package/src/agent-reload-config-rpc.ts +0 -34
- package/src/agent-rpc-body.ts +0 -92
- package/src/agent-stop-stuck.ts +0 -129
- package/src/card-action-routing.ts +0 -14
- package/src/card-plain-text.ts +0 -108
- package/src/cardkit.ts +0 -179
- package/src/cards.ts +0 -684
- package/src/chatgpt-subscription-rpc.ts +0 -27
- package/src/chatgpt-subscription.ts +0 -299
- package/src/chrome-devtools-guard.ts +0 -318
- package/src/claude-sdk-installer.ts +0 -324
- package/src/codex-reset-actions.ts +0 -184
- package/src/config-utils.ts +0 -211
- package/src/config.ts +0 -1063
- package/src/cursor-usage.ts +0 -128
- package/src/exit-banner.ts +0 -33
- package/src/feishu-api.ts +0 -1616
- package/src/feishu-message-ingress.ts +0 -195
- package/src/feishu-platform.ts +0 -159
- package/src/format-message.ts +0 -293
- package/src/git-command.ts +0 -202
- package/src/im-skills.ts +0 -149
- package/src/index.ts +0 -1089
- package/src/litellm-proxy.ts +0 -374
- package/src/orchestrator.ts +0 -2543
- package/src/platform-adapter.ts +0 -70
- package/src/platform-startup.ts +0 -16
- package/src/privacy.ts +0 -118
- package/src/progress/reducer.ts +0 -113
- package/src/progress/terminal-renderer.ts +0 -294
- package/src/progress/view.ts +0 -77
- package/src/response-stall.ts +0 -28
- package/src/runtime-reload.ts +0 -34
- package/src/session-chat-binding.ts +0 -292
- package/src/session-name.ts +0 -8
- package/src/session.ts +0 -2659
- package/src/shared-prefix.ts +0 -29
- package/src/shared.ts +0 -552
- package/src/sim-agent.ts +0 -167
- package/src/sim-platform.ts +0 -177
- package/src/sim-store.ts +0 -317
- package/src/simplify.ts +0 -120
- package/src/startup-lifecycle.ts +0 -250
- package/src/stream-state.ts +0 -177
- package/src/terminal-error.ts +0 -129
- package/src/trace.ts +0 -51
- package/src/turn-cards.ts +0 -118
- package/src/update-command-guard.ts +0 -165
- package/src/wechat-platform.ts +0 -680
|
@@ -1,1268 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
import type { PlatformAdapter } from "../platform-adapter.ts";
|
|
7
|
-
import type { SessionInfo, ToolAdapter } from "../adapters/adapter-interface.ts";
|
|
8
|
-
|
|
9
|
-
const mockStreamStates = new Map<string, { status: "running" | "done" | "stopped"; finalReply: string }>();
|
|
10
|
-
const mockGetCodexUsageSummary = vi.hoisted(() => vi.fn());
|
|
11
|
-
const mockGetCursorUsageSummary = vi.hoisted(() => vi.fn());
|
|
12
|
-
const mockGetChatGptSubscriptionStatus = vi.hoisted(() => vi.fn());
|
|
13
|
-
const mockReloadRuntimeConfig = vi.hoisted(() => vi.fn());
|
|
14
|
-
|
|
15
|
-
vi.mock("../im-skills.ts", () => ({
|
|
16
|
-
buildImSkillsPrompt: async () => "",
|
|
17
|
-
buildImSkillsPromptCached: async () => "",
|
|
18
|
-
exportSkillSubDocs: async () => {},
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
vi.mock("../stream-state.ts", () => ({
|
|
22
|
-
readStreamState: async (sessionId: string) => {
|
|
23
|
-
const state = mockStreamStates.get(sessionId);
|
|
24
|
-
if (!state) return null;
|
|
25
|
-
return {
|
|
26
|
-
sessionId,
|
|
27
|
-
status: state.status,
|
|
28
|
-
accumulatedContent: "",
|
|
29
|
-
finalReply: state.finalReply,
|
|
30
|
-
chunkCount: 0,
|
|
31
|
-
turnCount: 1,
|
|
32
|
-
contextTokens: 0,
|
|
33
|
-
updatedAt: Date.now(),
|
|
34
|
-
cwd: "F:\\repo",
|
|
35
|
-
tool: "claude",
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
writeStreamState: async (state: { sessionId: string; status: "running" | "done" | "stopped"; finalReply: string }) => {
|
|
39
|
-
mockStreamStates.set(state.sessionId, {
|
|
40
|
-
status: state.status,
|
|
41
|
-
finalReply: state.finalReply,
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
createEmptyStreamState: (sessionId: string, cwd: string, tool: string, turnCount: number) => ({
|
|
45
|
-
sessionId,
|
|
46
|
-
status: "running" as const,
|
|
47
|
-
accumulatedContent: "",
|
|
48
|
-
finalReply: "",
|
|
49
|
-
chunkCount: 0,
|
|
50
|
-
turnCount,
|
|
51
|
-
contextTokens: 0,
|
|
52
|
-
updatedAt: Date.now(),
|
|
53
|
-
cwd,
|
|
54
|
-
tool,
|
|
55
|
-
}),
|
|
56
|
-
fixStaleStreamStates: async () => {},
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
vi.mock("../feishu-platform.ts", () => ({
|
|
60
|
-
getCodexUsageSummary: mockGetCodexUsageSummary,
|
|
61
|
-
getTenantAccessToken: vi.fn(async () => "tenant-token"),
|
|
62
|
-
sendPostMessage: vi.fn(async () => true),
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
vi.mock("../cursor-usage.ts", () => ({
|
|
66
|
-
getCursorUsageSummary: mockGetCursorUsageSummary,
|
|
67
|
-
}));
|
|
68
|
-
|
|
69
|
-
vi.mock("../chatgpt-subscription.ts", () => ({
|
|
70
|
-
getChatGptSubscriptionStatus: mockGetChatGptSubscriptionStatus,
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
vi.mock("../runtime-reload.ts", () => ({
|
|
74
|
-
reloadRuntimeConfig: mockReloadRuntimeConfig,
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
import { handleCommand } from "../orchestrator.ts";
|
|
78
|
-
import {
|
|
79
|
-
_clearAdapterCacheForTest,
|
|
80
|
-
_resetSessionRegistryFileForTest,
|
|
81
|
-
_resetSessionToolsFileForTest,
|
|
82
|
-
_setAdapterForToolForTest,
|
|
83
|
-
_setSessionRegistryFileForTest,
|
|
84
|
-
_setSessionToolsFileForTest,
|
|
85
|
-
loadSessionRegistryForBinding,
|
|
86
|
-
recordSessionRegistry,
|
|
87
|
-
resetState,
|
|
88
|
-
sessionInfoMap,
|
|
89
|
-
getEffectiveEffortForTool,
|
|
90
|
-
getEffectiveFastModeForTool,
|
|
91
|
-
} from "../session.ts";
|
|
92
|
-
import {
|
|
93
|
-
activePrompts,
|
|
94
|
-
dequeueMessage,
|
|
95
|
-
getChatsForSession,
|
|
96
|
-
resetBindingState,
|
|
97
|
-
} from "../session-chat-binding.ts";
|
|
98
|
-
import { ABD_APPEND_PROMPT } from "../shared-prefix.ts";
|
|
99
|
-
import { config } from "../config.ts";
|
|
100
|
-
|
|
101
|
-
function mockPlatform(kind: "wechat" | "feishu" = "wechat"): PlatformAdapter {
|
|
102
|
-
return {
|
|
103
|
-
kind,
|
|
104
|
-
sendText: vi.fn(async () => true),
|
|
105
|
-
sendCard: vi.fn(async () => true),
|
|
106
|
-
sendRawCard: vi.fn(async () => true),
|
|
107
|
-
createGroup: vi.fn(async () => "feishu-group"),
|
|
108
|
-
updateChatInfo: vi.fn(async () => {}),
|
|
109
|
-
getChatInfo: vi.fn(async () => ({ name: kind === "wechat" ? "微信会话" : "飞书会话", description: "" })),
|
|
110
|
-
disbandChat: vi.fn(async () => {}),
|
|
111
|
-
setChatAvatar: vi.fn(async () => {}),
|
|
112
|
-
extractSessionInfo: vi.fn(() => null),
|
|
113
|
-
cardCreate: vi.fn(async () => "card-id"),
|
|
114
|
-
cardSend: vi.fn(async () => "message-id"),
|
|
115
|
-
cardUpdate: vi.fn(async () => {}),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function mockAdapter(sessionId = "sid-wechat", promptText = "done"): ToolAdapter {
|
|
120
|
-
return {
|
|
121
|
-
displayName: "Claude",
|
|
122
|
-
sessionDescPrefix: "Claude Session:",
|
|
123
|
-
createSession: vi.fn(async () => ({ sessionId })),
|
|
124
|
-
prompt: async function* () {
|
|
125
|
-
yield {
|
|
126
|
-
type: "assistant",
|
|
127
|
-
blocks: [{ type: "text", text: promptText }],
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
131
|
-
sessionId,
|
|
132
|
-
cwd: "F:\\repo",
|
|
133
|
-
}),
|
|
134
|
-
closeSession: async () => {},
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
describe("handleCommand WeChat processing ack", () => {
|
|
139
|
-
let tempDir: string;
|
|
140
|
-
|
|
141
|
-
beforeEach(async () => {
|
|
142
|
-
vi.useFakeTimers();
|
|
143
|
-
tempDir = await mkdtemp(join(tmpdir(), "chatccc-orchestrator-"));
|
|
144
|
-
_setSessionRegistryFileForTest(join(tempDir, "session-registry.json"));
|
|
145
|
-
_setSessionToolsFileForTest(join(tempDir, "sessions.json"));
|
|
146
|
-
resetState();
|
|
147
|
-
resetBindingState();
|
|
148
|
-
config.claude.defaultAgent = true;
|
|
149
|
-
config.cursor.defaultAgent = false;
|
|
150
|
-
config.codex.defaultAgent = false;
|
|
151
|
-
config.codex.fastMode = false;
|
|
152
|
-
config.ccc.enabled = true;
|
|
153
|
-
config.ccc.defaultAgent = false;
|
|
154
|
-
config.ccc.DEEPSEEK_API_KEY = "sk-test-ccc";
|
|
155
|
-
config.ccc.DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1";
|
|
156
|
-
config.ccc.model = "deepseek-v4-pro";
|
|
157
|
-
config.ccc.alternativeModel = "deepseek-v4-flash";
|
|
158
|
-
mockStreamStates.clear();
|
|
159
|
-
mockGetCodexUsageSummary.mockReset();
|
|
160
|
-
mockGetCursorUsageSummary.mockReset();
|
|
161
|
-
mockGetChatGptSubscriptionStatus.mockReset();
|
|
162
|
-
mockReloadRuntimeConfig.mockReset();
|
|
163
|
-
mockGetCodexUsageSummary.mockResolvedValue({
|
|
164
|
-
fiveHour: { usedPercent: 0, remainingPercent: 100, resetAtEpochSeconds: null, resetAfterSeconds: null },
|
|
165
|
-
weekly: { usedPercent: 0, remainingPercent: 100, resetAtEpochSeconds: null, resetAfterSeconds: null },
|
|
166
|
-
rateLimitResetCreditsAvailable: null,
|
|
167
|
-
rateLimitResetCredits: null,
|
|
168
|
-
});
|
|
169
|
-
mockGetCursorUsageSummary.mockResolvedValue({
|
|
170
|
-
billingCycleStart: "1779357999000",
|
|
171
|
-
billingCycleEnd: "1782036399000",
|
|
172
|
-
planUsage: {
|
|
173
|
-
totalSpend: 8159,
|
|
174
|
-
includedSpend: 2000,
|
|
175
|
-
bonusSpend: 6159,
|
|
176
|
-
limit: 2000,
|
|
177
|
-
remainingBonus: false,
|
|
178
|
-
autoPercentUsed: 0,
|
|
179
|
-
apiPercentUsed: 100,
|
|
180
|
-
totalPercentUsed: 100,
|
|
181
|
-
},
|
|
182
|
-
spendLimitUsage: {
|
|
183
|
-
pooledLimit: 48950000,
|
|
184
|
-
pooledUsed: 31808224,
|
|
185
|
-
pooledRemaining: 17141776,
|
|
186
|
-
individualUsed: 101252,
|
|
187
|
-
limitType: "team",
|
|
188
|
-
},
|
|
189
|
-
displayThreshold: 200,
|
|
190
|
-
enabled: true,
|
|
191
|
-
displayMessage: "You've hit your usage limit",
|
|
192
|
-
autoBucketModels: ["default"],
|
|
193
|
-
});
|
|
194
|
-
mockGetChatGptSubscriptionStatus.mockResolvedValue({
|
|
195
|
-
ok: false,
|
|
196
|
-
code: "chrome_cdp_disabled",
|
|
197
|
-
reason: "Chrome CDP guard is disabled in ChatCCC config.",
|
|
198
|
-
chromeCdp: { enabled: false, port: 15166, status: "skipped" },
|
|
199
|
-
});
|
|
200
|
-
mockReloadRuntimeConfig.mockResolvedValue({
|
|
201
|
-
configPath: "C:\\Users\\me\\.chatccc\\config.json",
|
|
202
|
-
defaultAgent: "codex",
|
|
203
|
-
reloadedAt: "2026-07-02T05:00:00.000Z",
|
|
204
|
-
});
|
|
205
|
-
_setAdapterForToolForTest("claude", mockAdapter());
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
afterEach(async () => {
|
|
209
|
-
resetState();
|
|
210
|
-
resetBindingState();
|
|
211
|
-
_clearAdapterCacheForTest();
|
|
212
|
-
_resetSessionRegistryFileForTest();
|
|
213
|
-
_resetSessionToolsFileForTest();
|
|
214
|
-
vi.useRealTimers();
|
|
215
|
-
vi.unstubAllGlobals();
|
|
216
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("does not send the WeChat processing ack when the session is already running", async () => {
|
|
220
|
-
const platform = mockPlatform();
|
|
221
|
-
await recordSessionRegistry({
|
|
222
|
-
chatId: "wx-chat",
|
|
223
|
-
sessionId: "sid-wechat",
|
|
224
|
-
tool: "claude",
|
|
225
|
-
chatName: "busy-session",
|
|
226
|
-
running: true,
|
|
227
|
-
});
|
|
228
|
-
activePrompts.set("sid-wechat", {
|
|
229
|
-
controller: new AbortController(),
|
|
230
|
-
stopped: false,
|
|
231
|
-
startTime: Date.now(),
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
await handleCommand(platform, "继续说明", "wx-chat", "wx-user", Date.now(), "p2p");
|
|
235
|
-
|
|
236
|
-
// 不再发"生成中"卡片,改为入队文本通知
|
|
237
|
-
expect(platform.sendText).not.toHaveBeenCalledWith("wx-chat", "生成中...");
|
|
238
|
-
expect(platform.sendText).toHaveBeenCalledWith(
|
|
239
|
-
"wx-chat",
|
|
240
|
-
"当前会话正在生成中,你的消息已进入缓存队列,生成完成后会立即处理。发送 /cancel 可取消缓存。",
|
|
241
|
-
);
|
|
242
|
-
// sendCard 不再被调用(WeChat 用 sendText)
|
|
243
|
-
expect(platform.sendCard).not.toHaveBeenCalled();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("sends the WeChat processing ack after the busy check for normal prompts", async () => {
|
|
247
|
-
const platform = mockPlatform();
|
|
248
|
-
await recordSessionRegistry({
|
|
249
|
-
chatId: "wx-chat",
|
|
250
|
-
sessionId: "sid-wechat",
|
|
251
|
-
tool: "claude",
|
|
252
|
-
chatName: "ready-session",
|
|
253
|
-
running: false,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
await handleCommand(platform, "继续说明", "wx-chat", "wx-user", Date.now(), "p2p");
|
|
257
|
-
|
|
258
|
-
expect(platform.sendText).toHaveBeenCalledWith("wx-chat", "生成中...");
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it("treats /abd as a shared prompt prefix in an existing session", async () => {
|
|
262
|
-
const platform = mockPlatform();
|
|
263
|
-
const prompt = vi.fn(async function* (_sessionId: string, userText: string) {
|
|
264
|
-
yield {
|
|
265
|
-
type: "assistant" as const,
|
|
266
|
-
blocks: [{ type: "text" as const, text: "done" }],
|
|
267
|
-
};
|
|
268
|
-
});
|
|
269
|
-
_setAdapterForToolForTest("claude", {
|
|
270
|
-
displayName: "Claude",
|
|
271
|
-
sessionDescPrefix: "Claude Session:",
|
|
272
|
-
createSession: vi.fn(async () => ({ sessionId: "sid-wechat" })),
|
|
273
|
-
prompt,
|
|
274
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
275
|
-
sessionId,
|
|
276
|
-
cwd: "F:\\repo",
|
|
277
|
-
}),
|
|
278
|
-
closeSession: async () => {},
|
|
279
|
-
});
|
|
280
|
-
await recordSessionRegistry({
|
|
281
|
-
chatId: "wx-chat",
|
|
282
|
-
sessionId: "sid-wechat",
|
|
283
|
-
tool: "claude",
|
|
284
|
-
chatName: "ready-session",
|
|
285
|
-
running: false,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
await handleCommand(platform, "/abd帮我分析", "wx-chat", "wx-user", Date.now(), "p2p");
|
|
289
|
-
|
|
290
|
-
expect(platform.sendText).toHaveBeenCalledWith("wx-chat", "生成中...");
|
|
291
|
-
const userText = prompt.mock.calls[0][1];
|
|
292
|
-
expect(userText).toContain(`[User message]\n帮我分析\n\n---\n${ABD_APPEND_PROMPT}\n[/User message]`);
|
|
293
|
-
expect(userText).not.toContain("/abd");
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("does not send the stopped success text until the running prompt really exits", async () => {
|
|
297
|
-
const platform = mockPlatform();
|
|
298
|
-
await recordSessionRegistry({
|
|
299
|
-
chatId: "wx-chat",
|
|
300
|
-
sessionId: "sid-wechat",
|
|
301
|
-
tool: "claude",
|
|
302
|
-
chatName: "busy-session",
|
|
303
|
-
running: true,
|
|
304
|
-
});
|
|
305
|
-
activePrompts.set("sid-wechat", {
|
|
306
|
-
controller: new AbortController(),
|
|
307
|
-
stopped: false,
|
|
308
|
-
startTime: Date.now(),
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
await handleCommand(platform, "/stop", "wx-chat", "wx-user", Date.now(), "p2p");
|
|
312
|
-
|
|
313
|
-
expect(platform.sendText).not.toHaveBeenCalledWith("wx-chat", "会话已停止。");
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it("resumes the Feishu p2p session in place instead of creating a group", async () => {
|
|
317
|
-
const platform = mockPlatform("feishu");
|
|
318
|
-
const prompt = vi.fn(async function* (_sessionId: string, userText: string) {
|
|
319
|
-
yield {
|
|
320
|
-
type: "assistant" as const,
|
|
321
|
-
blocks: [{ type: "text" as const, text: `收到: ${userText}` }],
|
|
322
|
-
};
|
|
323
|
-
});
|
|
324
|
-
_setAdapterForToolForTest("claude", {
|
|
325
|
-
displayName: "Claude",
|
|
326
|
-
sessionDescPrefix: "Claude Session:",
|
|
327
|
-
createSession: vi.fn(async () => ({ sessionId: "sid-feishu-new" })),
|
|
328
|
-
prompt,
|
|
329
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
330
|
-
sessionId,
|
|
331
|
-
cwd: homedir(),
|
|
332
|
-
}),
|
|
333
|
-
closeSession: async () => {},
|
|
334
|
-
});
|
|
335
|
-
await recordSessionRegistry({
|
|
336
|
-
chatId: "feishu-p2p",
|
|
337
|
-
sessionId: "sid-feishu-private",
|
|
338
|
-
tool: "claude",
|
|
339
|
-
chatType: "p2p",
|
|
340
|
-
chatName: "飞书私聊",
|
|
341
|
-
running: false,
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
await handleCommand(platform, "帮我看一下日志", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
345
|
-
|
|
346
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
347
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
348
|
-
expect(prompt).toHaveBeenCalledWith(
|
|
349
|
-
"sid-feishu-private",
|
|
350
|
-
expect.stringContaining("帮我看一下日志"),
|
|
351
|
-
homedir(),
|
|
352
|
-
expect.any(AbortSignal),
|
|
353
|
-
expect.any(Object),
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
const registry = await loadSessionRegistryForBinding();
|
|
357
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private");
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("sends the normal session state card in an established Feishu p2p chat", async () => {
|
|
361
|
-
const platform = mockPlatform("feishu");
|
|
362
|
-
_setAdapterForToolForTest("claude", mockAdapter("sid-feishu-state"));
|
|
363
|
-
await recordSessionRegistry({
|
|
364
|
-
chatId: "feishu-p2p-state",
|
|
365
|
-
sessionId: "sid-feishu-state",
|
|
366
|
-
tool: "claude",
|
|
367
|
-
chatType: "p2p",
|
|
368
|
-
chatName: "飞书私聊",
|
|
369
|
-
turnCount: 2,
|
|
370
|
-
running: false,
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
await handleCommand(platform, "/state", "feishu-p2p-state", "ou-user", Date.now(), "p2p");
|
|
374
|
-
|
|
375
|
-
expect(platform.getChatInfo).not.toHaveBeenCalled();
|
|
376
|
-
expect(platform.sendRawCard).toHaveBeenCalledTimes(1);
|
|
377
|
-
const cardText = vi.mocked(platform.sendRawCard).mock.calls[0][1];
|
|
378
|
-
expect(cardText).toContain("sid-feishu-state");
|
|
379
|
-
expect(cardText).toContain("Claude Code");
|
|
380
|
-
expect(cardText).toContain("2");
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it("shows an explicit state card without creating an Agent when a Feishu p2p chat is not bound yet", async () => {
|
|
384
|
-
const platform = mockPlatform("feishu");
|
|
385
|
-
const adapter = mockAdapter("should-not-be-created");
|
|
386
|
-
_setAdapterForToolForTest("claude", adapter);
|
|
387
|
-
|
|
388
|
-
await handleCommand(platform, "/state", "feishu-p2p-empty", "ou-user", Date.now(), "p2p");
|
|
389
|
-
|
|
390
|
-
expect(adapter.createSession).not.toHaveBeenCalled();
|
|
391
|
-
expect(platform.sendRawCard).toHaveBeenCalledTimes(1);
|
|
392
|
-
const cardText = vi.mocked(platform.sendRawCard).mock.calls[0][1];
|
|
393
|
-
expect(cardText).toContain("未建立会话");
|
|
394
|
-
expect(cardText).toContain("Claude Code");
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it("switches an idle Feishu p2p chat to a fresh session when the default Agent changes", async () => {
|
|
398
|
-
const platform = mockPlatform("feishu");
|
|
399
|
-
const oldPrompt = vi.fn(async function* () {
|
|
400
|
-
yield { type: "assistant" as const, blocks: [{ type: "text" as const, text: "old" }] };
|
|
401
|
-
});
|
|
402
|
-
_setAdapterForToolForTest("claude", {
|
|
403
|
-
...mockAdapter("sid-old-claude"),
|
|
404
|
-
prompt: oldPrompt,
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
const createCursorSession = vi.fn(async () => ({ sessionId: "sid-new-cursor" }));
|
|
408
|
-
const cursorPrompt = vi.fn(async function* () {
|
|
409
|
-
yield { type: "assistant" as const, blocks: [{ type: "text" as const, text: "new" }] };
|
|
410
|
-
});
|
|
411
|
-
_setAdapterForToolForTest("cursor", {
|
|
412
|
-
...mockAdapter("sid-new-cursor"),
|
|
413
|
-
displayName: "Cursor",
|
|
414
|
-
sessionDescPrefix: "Cursor Session:",
|
|
415
|
-
createSession: createCursorSession,
|
|
416
|
-
prompt: cursorPrompt,
|
|
417
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({ sessionId, cwd: homedir() }),
|
|
418
|
-
});
|
|
419
|
-
await recordSessionRegistry({
|
|
420
|
-
chatId: "feishu-p2p",
|
|
421
|
-
sessionId: "sid-old-claude",
|
|
422
|
-
tool: "claude",
|
|
423
|
-
chatType: "p2p",
|
|
424
|
-
chatName: "飞书私聊",
|
|
425
|
-
running: false,
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
const originalCursorEnabled = config.cursor.enabled;
|
|
429
|
-
try {
|
|
430
|
-
config.cursor.enabled = true;
|
|
431
|
-
config.claude.defaultAgent = false;
|
|
432
|
-
config.cursor.defaultAgent = true;
|
|
433
|
-
|
|
434
|
-
await handleCommand(platform, "/state", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
435
|
-
expect(createCursorSession).not.toHaveBeenCalled();
|
|
436
|
-
expect((await loadSessionRegistryForBinding())["feishu-p2p"]?.sessionId).toBe("sid-old-claude");
|
|
437
|
-
|
|
438
|
-
await handleCommand(platform, "使用新的默认 Agent", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
439
|
-
|
|
440
|
-
expect(createCursorSession).toHaveBeenCalledWith(homedir(), expect.any(AbortSignal));
|
|
441
|
-
expect(oldPrompt).not.toHaveBeenCalled();
|
|
442
|
-
expect(cursorPrompt).toHaveBeenCalledWith(
|
|
443
|
-
"sid-new-cursor",
|
|
444
|
-
expect.stringContaining("使用新的默认 Agent"),
|
|
445
|
-
homedir(),
|
|
446
|
-
expect.any(AbortSignal),
|
|
447
|
-
expect.any(Object),
|
|
448
|
-
);
|
|
449
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
450
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
451
|
-
"feishu-p2p",
|
|
452
|
-
"默认 Agent 已切换",
|
|
453
|
-
expect.stringContaining("Claude Code → Cursor"),
|
|
454
|
-
"green",
|
|
455
|
-
);
|
|
456
|
-
|
|
457
|
-
const registry = await loadSessionRegistryForBinding();
|
|
458
|
-
expect(registry["feishu-p2p"]).toMatchObject({
|
|
459
|
-
sessionId: "sid-new-cursor",
|
|
460
|
-
tool: "cursor",
|
|
461
|
-
chatType: "p2p",
|
|
462
|
-
turnCount: 1,
|
|
463
|
-
});
|
|
464
|
-
} finally {
|
|
465
|
-
config.cursor.enabled = originalCursorEnabled;
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it("waits for a running Feishu p2p Agent before switching the queued message to the new default", async () => {
|
|
470
|
-
const platform = mockPlatform("feishu");
|
|
471
|
-
const createCursorSession = vi.fn(async () => ({ sessionId: "sid-cursor-after-wait" }));
|
|
472
|
-
const cursorPrompt = vi.fn(async function* () {
|
|
473
|
-
yield { type: "assistant" as const, blocks: [{ type: "text" as const, text: "new" }] };
|
|
474
|
-
});
|
|
475
|
-
_setAdapterForToolForTest("cursor", {
|
|
476
|
-
...mockAdapter("sid-cursor-after-wait"),
|
|
477
|
-
displayName: "Cursor",
|
|
478
|
-
sessionDescPrefix: "Cursor Session:",
|
|
479
|
-
createSession: createCursorSession,
|
|
480
|
-
prompt: cursorPrompt,
|
|
481
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({ sessionId, cwd: homedir() }),
|
|
482
|
-
});
|
|
483
|
-
await recordSessionRegistry({
|
|
484
|
-
chatId: "feishu-p2p-wait",
|
|
485
|
-
sessionId: "sid-running-claude",
|
|
486
|
-
tool: "claude",
|
|
487
|
-
chatType: "p2p",
|
|
488
|
-
chatName: "飞书私聊",
|
|
489
|
-
running: true,
|
|
490
|
-
});
|
|
491
|
-
activePrompts.set("sid-running-claude", {
|
|
492
|
-
controller: new AbortController(),
|
|
493
|
-
stopped: false,
|
|
494
|
-
startTime: Date.now(),
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
const originalCursorEnabled = config.cursor.enabled;
|
|
498
|
-
try {
|
|
499
|
-
config.cursor.enabled = true;
|
|
500
|
-
config.claude.defaultAgent = false;
|
|
501
|
-
config.cursor.defaultAgent = true;
|
|
502
|
-
|
|
503
|
-
await handleCommand(platform, "等当前回复完成后处理", "feishu-p2p-wait", "ou-user", Date.now(), "p2p");
|
|
504
|
-
|
|
505
|
-
expect(createCursorSession).not.toHaveBeenCalled();
|
|
506
|
-
const queued = dequeueMessage("sid-running-claude");
|
|
507
|
-
expect(queued?.text).toContain("等当前回复完成后处理");
|
|
508
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
509
|
-
"feishu-p2p-wait",
|
|
510
|
-
"Agent 切换等待中",
|
|
511
|
-
expect.stringContaining("完成后会切换到 Cursor"),
|
|
512
|
-
"blue",
|
|
513
|
-
);
|
|
514
|
-
|
|
515
|
-
activePrompts.delete("sid-running-claude");
|
|
516
|
-
await handleCommand(
|
|
517
|
-
platform,
|
|
518
|
-
queued!.text,
|
|
519
|
-
queued!.chatId,
|
|
520
|
-
queued!.openId,
|
|
521
|
-
queued!.msgTimestamp,
|
|
522
|
-
queued!.chatType,
|
|
523
|
-
queued!.traceId,
|
|
524
|
-
);
|
|
525
|
-
|
|
526
|
-
expect(createCursorSession).toHaveBeenCalledTimes(1);
|
|
527
|
-
expect(cursorPrompt).toHaveBeenCalledWith(
|
|
528
|
-
"sid-cursor-after-wait",
|
|
529
|
-
expect.stringContaining("等当前回复完成后处理"),
|
|
530
|
-
homedir(),
|
|
531
|
-
expect.any(AbortSignal),
|
|
532
|
-
expect.any(Object),
|
|
533
|
-
);
|
|
534
|
-
} finally {
|
|
535
|
-
config.cursor.enabled = originalCursorEnabled;
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it("creates the first Feishu p2p session in the OS user directory and sends the first prompt in place", async () => {
|
|
540
|
-
const platform = mockPlatform("feishu");
|
|
541
|
-
const createSession = vi.fn(async () => ({ sessionId: "sid-feishu-private" }));
|
|
542
|
-
const prompt = vi.fn(async function* (_sessionId: string, userText: string) {
|
|
543
|
-
yield {
|
|
544
|
-
type: "assistant" as const,
|
|
545
|
-
blocks: [{ type: "text" as const, text: `收到: ${userText}` }],
|
|
546
|
-
};
|
|
547
|
-
});
|
|
548
|
-
_setAdapterForToolForTest("claude", {
|
|
549
|
-
displayName: "Claude",
|
|
550
|
-
sessionDescPrefix: "Claude Session:",
|
|
551
|
-
createSession,
|
|
552
|
-
prompt,
|
|
553
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
554
|
-
sessionId,
|
|
555
|
-
cwd: homedir(),
|
|
556
|
-
}),
|
|
557
|
-
closeSession: async () => {},
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
await handleCommand(platform, "帮我看一下日志", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
561
|
-
|
|
562
|
-
expect(createSession).toHaveBeenCalledWith(homedir(), expect.any(AbortSignal));
|
|
563
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
564
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
565
|
-
expect(prompt).toHaveBeenCalledWith(
|
|
566
|
-
"sid-feishu-private",
|
|
567
|
-
expect.stringContaining("帮我看一下日志"),
|
|
568
|
-
homedir(),
|
|
569
|
-
expect.any(AbortSignal),
|
|
570
|
-
expect.any(Object),
|
|
571
|
-
);
|
|
572
|
-
|
|
573
|
-
const registry = await loadSessionRegistryForBinding();
|
|
574
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private");
|
|
575
|
-
expect(registry["feishu-p2p"]?.tool).toBe("claude");
|
|
576
|
-
expect(registry["feishu-p2p"]?.chatType).toBe("p2p");
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
it("replaces an unmarked legacy Feishu p2p binding with a home-directory session", async () => {
|
|
580
|
-
const platform = mockPlatform("feishu");
|
|
581
|
-
const createSession = vi.fn(async () => ({ sessionId: "sid-feishu-migrated" }));
|
|
582
|
-
const prompt = vi.fn(async function* () {
|
|
583
|
-
yield {
|
|
584
|
-
type: "assistant" as const,
|
|
585
|
-
blocks: [{ type: "text" as const, text: "done" }],
|
|
586
|
-
};
|
|
587
|
-
});
|
|
588
|
-
_setAdapterForToolForTest("claude", {
|
|
589
|
-
displayName: "Claude",
|
|
590
|
-
sessionDescPrefix: "Claude Session:",
|
|
591
|
-
createSession,
|
|
592
|
-
prompt,
|
|
593
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
594
|
-
sessionId,
|
|
595
|
-
cwd: homedir(),
|
|
596
|
-
}),
|
|
597
|
-
closeSession: async () => {},
|
|
598
|
-
});
|
|
599
|
-
await recordSessionRegistry({
|
|
600
|
-
chatId: "feishu-p2p",
|
|
601
|
-
sessionId: "sid-feishu-legacy",
|
|
602
|
-
tool: "claude",
|
|
603
|
-
chatName: "旧私聊绑定",
|
|
604
|
-
running: false,
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
await handleCommand(platform, "继续", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
608
|
-
|
|
609
|
-
expect(createSession).toHaveBeenCalledWith(homedir(), expect.any(AbortSignal));
|
|
610
|
-
expect(prompt).toHaveBeenCalledWith(
|
|
611
|
-
"sid-feishu-migrated",
|
|
612
|
-
expect.stringContaining("继续"),
|
|
613
|
-
homedir(),
|
|
614
|
-
expect.any(AbortSignal),
|
|
615
|
-
expect.any(Object),
|
|
616
|
-
);
|
|
617
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
618
|
-
const registry = await loadSessionRegistryForBinding();
|
|
619
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-migrated");
|
|
620
|
-
expect(registry["feishu-p2p"]?.chatType).toBe("p2p");
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
it("creates a Feishu p2p session for /abd and sends the transformed prompt without creating a group", async () => {
|
|
624
|
-
const platform = mockPlatform("feishu");
|
|
625
|
-
const createSession = vi.fn(async () => ({ sessionId: "sid-feishu-abd" }));
|
|
626
|
-
const prompt = vi.fn(async function* (_sessionId: string, userText: string) {
|
|
627
|
-
yield {
|
|
628
|
-
type: "assistant" as const,
|
|
629
|
-
blocks: [{ type: "text" as const, text: "done" }],
|
|
630
|
-
};
|
|
631
|
-
});
|
|
632
|
-
_setAdapterForToolForTest("claude", {
|
|
633
|
-
displayName: "Claude",
|
|
634
|
-
sessionDescPrefix: "Claude Session:",
|
|
635
|
-
createSession,
|
|
636
|
-
prompt,
|
|
637
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
638
|
-
sessionId,
|
|
639
|
-
cwd: homedir(),
|
|
640
|
-
}),
|
|
641
|
-
closeSession: async () => {},
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
await handleCommand(platform, "/abd帮我看一下日志", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
645
|
-
|
|
646
|
-
expect(createSession).toHaveBeenCalledWith(homedir(), expect.any(AbortSignal));
|
|
647
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
648
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
649
|
-
const userText = prompt.mock.calls[0][1];
|
|
650
|
-
expect(userText).toContain(`[User message]\n帮我看一下日志\n\n---\n${ABD_APPEND_PROMPT}\n[/User message]`);
|
|
651
|
-
expect(userText).not.toContain("/abd");
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it("keeps the Feishu p2p binding when handling commands", async () => {
|
|
655
|
-
const platform = mockPlatform("feishu");
|
|
656
|
-
await recordSessionRegistry({
|
|
657
|
-
chatId: "feishu-p2p",
|
|
658
|
-
sessionId: "sid-feishu-private",
|
|
659
|
-
tool: "claude",
|
|
660
|
-
chatType: "p2p",
|
|
661
|
-
chatName: "飞书私聊",
|
|
662
|
-
running: false,
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
await handleCommand(platform, "/model", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
666
|
-
|
|
667
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
668
|
-
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
669
|
-
const registry = await loadSessionRegistryForBinding();
|
|
670
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private");
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
it("queries and switches Fast mode for the current Codex session", async () => {
|
|
674
|
-
const platform = mockPlatform("feishu");
|
|
675
|
-
await recordSessionRegistry({
|
|
676
|
-
chatId: "feishu-codex",
|
|
677
|
-
sessionId: "sid-codex-fast",
|
|
678
|
-
tool: "codex",
|
|
679
|
-
chatType: "p2p",
|
|
680
|
-
chatName: "Codex",
|
|
681
|
-
running: false,
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
await handleCommand(platform, "/fast", "feishu-codex", "ou-user", Date.now(), "p2p");
|
|
685
|
-
let card = JSON.parse(
|
|
686
|
-
vi.mocked(platform.sendRawCard).mock.calls.at(-1)?.[1] ?? "{}",
|
|
687
|
-
) as { elements?: Array<{ tag: string; text?: { content: string } }> };
|
|
688
|
-
expect(card.elements?.find((element) => element.tag === "div")?.text?.content).toContain("OFF");
|
|
689
|
-
|
|
690
|
-
await handleCommand(platform, "/fast on", "feishu-codex", "ou-user", Date.now(), "p2p");
|
|
691
|
-
expect(getEffectiveFastModeForTool("codex", "sid-codex-fast")).toBe(true);
|
|
692
|
-
expect(platform.setChatAvatar).toHaveBeenLastCalledWith(
|
|
693
|
-
"feishu-codex",
|
|
694
|
-
"codex",
|
|
695
|
-
"idle",
|
|
696
|
-
{ fastMode: true },
|
|
697
|
-
);
|
|
698
|
-
|
|
699
|
-
await handleCommand(platform, "/fast off", "feishu-codex", "ou-user", Date.now(), "p2p");
|
|
700
|
-
expect(getEffectiveFastModeForTool("codex", "sid-codex-fast")).toBe(false);
|
|
701
|
-
expect(platform.setChatAvatar).toHaveBeenLastCalledWith(
|
|
702
|
-
"feishu-codex",
|
|
703
|
-
"codex",
|
|
704
|
-
"idle",
|
|
705
|
-
{ fastMode: false },
|
|
706
|
-
);
|
|
707
|
-
card = JSON.parse(
|
|
708
|
-
vi.mocked(platform.sendRawCard).mock.calls.at(-1)?.[1] ?? "{}",
|
|
709
|
-
) as { elements?: Array<{ tag: string; text?: { content: string } }> };
|
|
710
|
-
expect(card.elements?.find((element) => element.tag === "div")?.text?.content).toContain("OFF");
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
it("uses a text fallback for Fast mode commands on WeChat", async () => {
|
|
714
|
-
const platform = mockPlatform("wechat");
|
|
715
|
-
await recordSessionRegistry({
|
|
716
|
-
chatId: "wechat-codex",
|
|
717
|
-
sessionId: "sid-wechat-codex-fast",
|
|
718
|
-
tool: "codex",
|
|
719
|
-
chatType: "p2p",
|
|
720
|
-
chatName: "Codex",
|
|
721
|
-
running: false,
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
await handleCommand(platform, "/fast on", "wechat-codex", "wx-user", Date.now(), "p2p");
|
|
725
|
-
|
|
726
|
-
expect(getEffectiveFastModeForTool("codex", "sid-wechat-codex-fast")).toBe(true);
|
|
727
|
-
expect(platform.sendText).toHaveBeenCalledWith(
|
|
728
|
-
"wechat-codex",
|
|
729
|
-
expect.stringContaining("ON (Fast)"),
|
|
730
|
-
);
|
|
731
|
-
expect(platform.sendRawCard).not.toHaveBeenCalled();
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
it("keeps the Feishu p2p session bound when /new creates a separate group", async () => {
|
|
735
|
-
const platform = mockPlatform("feishu");
|
|
736
|
-
const createSession = vi.fn(async () => ({ sessionId: "sid-feishu-group" }));
|
|
737
|
-
_setAdapterForToolForTest("claude", {
|
|
738
|
-
...mockAdapter("sid-feishu-group"),
|
|
739
|
-
createSession,
|
|
740
|
-
});
|
|
741
|
-
await recordSessionRegistry({
|
|
742
|
-
chatId: "feishu-p2p",
|
|
743
|
-
sessionId: "sid-feishu-private",
|
|
744
|
-
tool: "claude",
|
|
745
|
-
chatType: "p2p",
|
|
746
|
-
chatName: "飞书私聊",
|
|
747
|
-
running: false,
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
await handleCommand(platform, "/new", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
751
|
-
|
|
752
|
-
expect(platform.createGroup).toHaveBeenCalledWith(expect.any(String), ["ou-user"]);
|
|
753
|
-
const registry = await loadSessionRegistryForBinding();
|
|
754
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private");
|
|
755
|
-
expect(registry["feishu-group"]?.sessionId).toBe("sid-feishu-group");
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
it("resets a Feishu p2p session in place with /newh and forces the OS user directory", async () => {
|
|
759
|
-
const platform = mockPlatform("feishu");
|
|
760
|
-
const createSession = vi.fn(async () => ({ sessionId: "sid-feishu-private-reset" }));
|
|
761
|
-
_setAdapterForToolForTest("claude", {
|
|
762
|
-
...mockAdapter("sid-feishu-private-reset"),
|
|
763
|
-
createSession,
|
|
764
|
-
getSessionInfo: async (sessionId: string): Promise<SessionInfo> => ({
|
|
765
|
-
sessionId,
|
|
766
|
-
cwd: "F:\\some-project",
|
|
767
|
-
}),
|
|
768
|
-
});
|
|
769
|
-
await recordSessionRegistry({
|
|
770
|
-
chatId: "feishu-p2p",
|
|
771
|
-
sessionId: "sid-feishu-private",
|
|
772
|
-
tool: "claude",
|
|
773
|
-
chatType: "p2p",
|
|
774
|
-
chatName: "飞书私聊",
|
|
775
|
-
running: false,
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
await handleCommand(platform, "/newh", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
779
|
-
|
|
780
|
-
expect(createSession).toHaveBeenCalledWith(homedir(), expect.any(AbortSignal));
|
|
781
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
782
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
783
|
-
const registry = await loadSessionRegistryForBinding();
|
|
784
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private-reset");
|
|
785
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
786
|
-
"feishu-p2p",
|
|
787
|
-
"Claude Code Session Reset",
|
|
788
|
-
expect.stringContaining(`${homedir()}\`(飞书私聊固定使用系统用户目录)`),
|
|
789
|
-
"green",
|
|
790
|
-
);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it("does not allow /session to replace the dedicated Feishu p2p session", async () => {
|
|
794
|
-
const platform = mockPlatform("feishu");
|
|
795
|
-
await recordSessionRegistry({
|
|
796
|
-
chatId: "feishu-p2p",
|
|
797
|
-
sessionId: "sid-feishu-private",
|
|
798
|
-
tool: "claude",
|
|
799
|
-
chatType: "p2p",
|
|
800
|
-
chatName: "飞书私聊",
|
|
801
|
-
running: false,
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
await handleCommand(platform, "/session 1", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
805
|
-
|
|
806
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
807
|
-
"feishu-p2p",
|
|
808
|
-
"/session",
|
|
809
|
-
expect.stringContaining("下一条普通消息时跟随默认 Agent"),
|
|
810
|
-
"yellow",
|
|
811
|
-
);
|
|
812
|
-
expect(platform.updateChatInfo).not.toHaveBeenCalled();
|
|
813
|
-
const registry = await loadSessionRegistryForBinding();
|
|
814
|
-
expect(registry["feishu-p2p"]?.sessionId).toBe("sid-feishu-private");
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
it("shows Claude effort switch card in an active Feishu session", async () => {
|
|
818
|
-
const platform = mockPlatform("feishu");
|
|
819
|
-
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "claude-session", description: "Claude Session: sid-claude-effort" });
|
|
820
|
-
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-claude-effort", tool: "claude" });
|
|
821
|
-
await recordSessionRegistry({
|
|
822
|
-
chatId: "feishu-chat",
|
|
823
|
-
sessionId: "sid-claude-effort",
|
|
824
|
-
tool: "claude",
|
|
825
|
-
chatName: "claude-session",
|
|
826
|
-
running: false,
|
|
827
|
-
});
|
|
828
|
-
sessionInfoMap.set("feishu-chat", {
|
|
829
|
-
sessionId: "sid-claude-effort",
|
|
830
|
-
tool: "claude",
|
|
831
|
-
turnCount: 0,
|
|
832
|
-
lastContextTokens: 0,
|
|
833
|
-
startTime: Date.now(),
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
await handleCommand(platform, "/effort", "feishu-chat", "ou-user", Date.now(), "group");
|
|
837
|
-
|
|
838
|
-
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
839
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
840
|
-
const raw = JSON.stringify(card);
|
|
841
|
-
expect(raw).toContain("/effort low");
|
|
842
|
-
expect(raw).toContain("/effort xhigh");
|
|
843
|
-
expect(raw).toContain("/effort max");
|
|
844
|
-
});
|
|
845
|
-
|
|
846
|
-
it("switches Codex effort for the current session and reflects it in /state", async () => {
|
|
847
|
-
const platform = mockPlatform("feishu");
|
|
848
|
-
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "codex-session", description: "Codex Session: sid-codex-effort" });
|
|
849
|
-
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-codex-effort", tool: "codex" });
|
|
850
|
-
_setAdapterForToolForTest("codex", mockAdapter("sid-codex-effort"));
|
|
851
|
-
await recordSessionRegistry({
|
|
852
|
-
chatId: "codex-chat",
|
|
853
|
-
sessionId: "sid-codex-effort",
|
|
854
|
-
tool: "codex",
|
|
855
|
-
chatName: "codex-session",
|
|
856
|
-
running: false,
|
|
857
|
-
});
|
|
858
|
-
sessionInfoMap.set("codex-chat", {
|
|
859
|
-
sessionId: "sid-codex-effort",
|
|
860
|
-
tool: "codex",
|
|
861
|
-
turnCount: 0,
|
|
862
|
-
lastContextTokens: 0,
|
|
863
|
-
startTime: Date.now(),
|
|
864
|
-
});
|
|
865
|
-
|
|
866
|
-
await handleCommand(platform, "/effort xhigh", "codex-chat", "ou-user", Date.now(), "group");
|
|
867
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
868
|
-
"codex-chat",
|
|
869
|
-
"Effort 切换",
|
|
870
|
-
expect.stringContaining("xhigh"),
|
|
871
|
-
"green",
|
|
872
|
-
);
|
|
873
|
-
|
|
874
|
-
vi.mocked(platform.sendCard).mockClear();
|
|
875
|
-
vi.mocked(platform.sendRawCard).mockClear();
|
|
876
|
-
await handleCommand(platform, "/state", "codex-chat", "ou-user", Date.now() + 1, "group");
|
|
877
|
-
|
|
878
|
-
expect(platform.sendRawCard).toHaveBeenCalled();
|
|
879
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
880
|
-
expect(JSON.stringify(card)).toContain("xhigh");
|
|
881
|
-
expect(getChatsForSession("sid-codex-effort")).toContain("codex-chat");
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
it("rejects /effort in Cursor sessions", async () => {
|
|
885
|
-
const platform = mockPlatform("feishu");
|
|
886
|
-
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "cursor-session", description: "Cursor Session: sid-cursor-effort" });
|
|
887
|
-
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-cursor-effort", tool: "cursor" });
|
|
888
|
-
_setAdapterForToolForTest("cursor", mockAdapter("sid-cursor-effort"));
|
|
889
|
-
await recordSessionRegistry({
|
|
890
|
-
chatId: "cursor-chat",
|
|
891
|
-
sessionId: "sid-cursor-effort",
|
|
892
|
-
tool: "cursor",
|
|
893
|
-
chatName: "cursor-session",
|
|
894
|
-
running: false,
|
|
895
|
-
});
|
|
896
|
-
sessionInfoMap.set("cursor-chat", {
|
|
897
|
-
sessionId: "sid-cursor-effort",
|
|
898
|
-
tool: "cursor",
|
|
899
|
-
turnCount: 0,
|
|
900
|
-
lastContextTokens: 0,
|
|
901
|
-
startTime: Date.now(),
|
|
902
|
-
});
|
|
903
|
-
|
|
904
|
-
await handleCommand(platform, "/effort high", "cursor-chat", "ou-user", Date.now(), "group");
|
|
905
|
-
|
|
906
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
907
|
-
"cursor-chat",
|
|
908
|
-
"Effort 切换",
|
|
909
|
-
expect.stringContaining("不支持 effort"),
|
|
910
|
-
"red",
|
|
911
|
-
);
|
|
912
|
-
});
|
|
913
|
-
|
|
914
|
-
it("switches CCC effort for the current session", async () => {
|
|
915
|
-
const platform = mockPlatform("feishu");
|
|
916
|
-
vi.mocked(platform.getChatInfo).mockResolvedValue({ name: "ccc-session", description: "CCC Session: sid-ccc-effort" });
|
|
917
|
-
vi.mocked(platform.extractSessionInfo).mockReturnValue({ sessionId: "sid-ccc-effort", tool: "ccc" });
|
|
918
|
-
_setAdapterForToolForTest("ccc", mockAdapter("sid-ccc-effort"));
|
|
919
|
-
await recordSessionRegistry({
|
|
920
|
-
chatId: "ccc-chat",
|
|
921
|
-
sessionId: "sid-ccc-effort",
|
|
922
|
-
tool: "ccc",
|
|
923
|
-
chatName: "ccc-session",
|
|
924
|
-
running: false,
|
|
925
|
-
});
|
|
926
|
-
sessionInfoMap.set("ccc-chat", {
|
|
927
|
-
sessionId: "sid-ccc-effort",
|
|
928
|
-
tool: "ccc",
|
|
929
|
-
turnCount: 0,
|
|
930
|
-
lastContextTokens: 0,
|
|
931
|
-
startTime: Date.now(),
|
|
932
|
-
});
|
|
933
|
-
|
|
934
|
-
await handleCommand(platform, "/effort max", "ccc-chat", "ou-user", Date.now(), "group");
|
|
935
|
-
|
|
936
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
937
|
-
"ccc-chat",
|
|
938
|
-
"Effort 切换",
|
|
939
|
-
expect.stringContaining("max"),
|
|
940
|
-
"green",
|
|
941
|
-
);
|
|
942
|
-
|
|
943
|
-
expect(getEffectiveEffortForTool("ccc", "sid-ccc-effort")).toBe("max");
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
it("handles /usage without creating a new Feishu group", async () => {
|
|
947
|
-
const platform = mockPlatform("feishu");
|
|
948
|
-
const usage = {
|
|
949
|
-
fiveHour: { usedPercent: 37, remainingPercent: 63, resetAtEpochSeconds: 1781528212, resetAfterSeconds: 10349 },
|
|
950
|
-
weekly: { usedPercent: 12, remainingPercent: 88, resetAtEpochSeconds: 1781842926, resetAfterSeconds: 325063 },
|
|
951
|
-
rateLimitResetCreditsAvailable: 2,
|
|
952
|
-
rateLimitResetCredits: [
|
|
953
|
-
{ grantedAt: "2026-06-12T04:01:47.770016Z", expiresAt: "2026-07-12T04:01:47.770016Z" },
|
|
954
|
-
{ grantedAt: "2026-06-18T00:44:23.904386Z", expiresAt: "2026-07-18T00:44:23.904386Z" },
|
|
955
|
-
],
|
|
956
|
-
};
|
|
957
|
-
mockGetCodexUsageSummary.mockResolvedValue(usage);
|
|
958
|
-
|
|
959
|
-
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
960
|
-
|
|
961
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
962
|
-
expect(platform.sendCard).not.toHaveBeenCalled();
|
|
963
|
-
expect(platform.sendRawCard).toHaveBeenCalledTimes(1);
|
|
964
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
965
|
-
expect(card.header.title.content).toBe("Codex Usage");
|
|
966
|
-
expect(card.elements[0].text.content).toContain("2026-07-12");
|
|
967
|
-
expect(card.elements[0].text.content).toContain("2026-07-18");
|
|
968
|
-
expect(card.elements[0].text.content).toContain("**主动重置:** 剩余 2 次");
|
|
969
|
-
expect(card.elements[0].text.content).not.toContain("ChatGPT 订阅");
|
|
970
|
-
expect(card.elements[0].text.content).toContain("**5h:** 已用 37%,剩余 63%,重置:");
|
|
971
|
-
expect(card.elements[0].text.content).toContain("约 2小时52分钟后");
|
|
972
|
-
expect(card.elements[0].text.content).toContain("[███████░░░░░░░░░░░░░]");
|
|
973
|
-
expect(card.elements[0].text.content).toContain("**7天:** 已用 12%,剩余 88%,重置:");
|
|
974
|
-
expect(card.elements[0].text.content).toContain("约 3天18小时17分钟后");
|
|
975
|
-
expect(card.elements[0].text.content).toContain("[██░░░░░░░░░░░░░░░░░░]");
|
|
976
|
-
expect(card.elements[2].actions[0].text.content).toBe("发起重置");
|
|
977
|
-
expect(card.elements[2].actions[0].value).toEqual({ action: "codex_reset_request", availableCount: 2 });
|
|
978
|
-
expect(platform.setChatAvatar).toHaveBeenCalledWith("feishu-p2p", "codex", "idle", { codexUsage: usage });
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
it("shows only the 7-day window when the 5h window is absent", async () => {
|
|
982
|
-
const platform = mockPlatform("feishu");
|
|
983
|
-
const usage = {
|
|
984
|
-
fiveHour: null,
|
|
985
|
-
weekly: {
|
|
986
|
-
usedPercent: 23,
|
|
987
|
-
remainingPercent: 77,
|
|
988
|
-
resetAtEpochSeconds: 1784510226,
|
|
989
|
-
resetAfterSeconds: 500000,
|
|
990
|
-
limitWindowSeconds: 604800,
|
|
991
|
-
},
|
|
992
|
-
rateLimitResetCreditsAvailable: 0,
|
|
993
|
-
rateLimitResetCredits: [],
|
|
994
|
-
};
|
|
995
|
-
mockGetCodexUsageSummary.mockResolvedValue(usage);
|
|
996
|
-
|
|
997
|
-
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
998
|
-
|
|
999
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
1000
|
-
const content = card.elements[0].text.content as string;
|
|
1001
|
-
expect(content).not.toContain("**5h:**");
|
|
1002
|
-
expect(content).toContain("**7天:** 已用 23%,剩余 77%,重置:");
|
|
1003
|
-
expect(platform.setChatAvatar).toHaveBeenCalledWith("feishu-p2p", "codex", "idle", { codexUsage: usage });
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
it("adds ChatGPT subscription expiry to Codex /usage when CDP lookup succeeds", async () => {
|
|
1007
|
-
const platform = mockPlatform("feishu");
|
|
1008
|
-
mockGetCodexUsageSummary.mockResolvedValue({
|
|
1009
|
-
fiveHour: { usedPercent: 37, remainingPercent: 63, resetAtEpochSeconds: 1781528212, resetAfterSeconds: 10349 },
|
|
1010
|
-
weekly: { usedPercent: 12, remainingPercent: 88, resetAtEpochSeconds: 1781842926, resetAfterSeconds: 325063 },
|
|
1011
|
-
rateLimitResetCreditsAvailable: 0,
|
|
1012
|
-
rateLimitResetCredits: [],
|
|
1013
|
-
});
|
|
1014
|
-
mockGetChatGptSubscriptionStatus.mockResolvedValue({
|
|
1015
|
-
ok: true,
|
|
1016
|
-
code: "ok",
|
|
1017
|
-
chromeCdp: { enabled: true, port: 15166, status: "healthy" },
|
|
1018
|
-
chatgpt: { sessionOk: true, maskedEmail: "gg***@gmail.com", sessionExpiresAt: "2026-09-20T09:30:07.340Z" },
|
|
1019
|
-
subscription: {
|
|
1020
|
-
active: true,
|
|
1021
|
-
plan: "chatgptprolite",
|
|
1022
|
-
expiresAt: "2026-07-12T10:20:11+00:00",
|
|
1023
|
-
willRenew: false,
|
|
1024
|
-
purchaseOriginPlatform: "chatgpt_web",
|
|
1025
|
-
remainingDays: 20,
|
|
1026
|
-
},
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
|
-
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
1030
|
-
|
|
1031
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
1032
|
-
expect(card.elements[0].text.content).toContain("**ChatGPT 订阅:**");
|
|
1033
|
-
expect(card.elements[0].text.content).toContain("- 套餐: chatgptprolite");
|
|
1034
|
-
expect(card.elements[0].text.content).toContain("剩余 20 天");
|
|
1035
|
-
expect(card.elements[0].text.content).toContain("- 自动续费: 否");
|
|
1036
|
-
});
|
|
1037
|
-
|
|
1038
|
-
it("shows an actionable ChatGPT subscription failure reason when Chrome CDP is enabled", async () => {
|
|
1039
|
-
const platform = mockPlatform("feishu");
|
|
1040
|
-
mockGetChatGptSubscriptionStatus.mockResolvedValue({
|
|
1041
|
-
ok: false,
|
|
1042
|
-
code: "chatgpt_session_missing",
|
|
1043
|
-
reason: "ChatGPT browser session has no access token.",
|
|
1044
|
-
chromeCdp: { enabled: true, port: 15166, status: "healthy" },
|
|
1045
|
-
chatgpt: { sessionOk: true },
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
await handleCommand(platform, "/usage", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
1049
|
-
|
|
1050
|
-
const card = JSON.parse(vi.mocked(platform.sendRawCard).mock.calls[0][1]);
|
|
1051
|
-
expect(card.elements[0].text.content).toContain("**ChatGPT 订阅查询失败:**");
|
|
1052
|
-
expect(card.elements[0].text.content).toContain("请在 15166 端口对应的 Chrome 浏览器中登录 ChatGPT");
|
|
1053
|
-
expect(card.elements[0].text.content).toContain("ChatGPT browser session has no access token.");
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
it("handles /usage as Cursor usage in Cursor chats", async () => {
|
|
1057
|
-
const platform = mockPlatform("feishu");
|
|
1058
|
-
await recordSessionRegistry({
|
|
1059
|
-
chatId: "cursor-chat",
|
|
1060
|
-
sessionId: "sid-cursor",
|
|
1061
|
-
tool: "cursor",
|
|
1062
|
-
chatName: "cursor-session",
|
|
1063
|
-
running: false,
|
|
1064
|
-
});
|
|
1065
|
-
|
|
1066
|
-
await handleCommand(platform, "/usage", "cursor-chat", "ou-user", Date.now(), "group");
|
|
1067
|
-
|
|
1068
|
-
expect(platform.createGroup).not.toHaveBeenCalled();
|
|
1069
|
-
expect(mockGetCodexUsageSummary).not.toHaveBeenCalled();
|
|
1070
|
-
expect(mockGetCursorUsageSummary).toHaveBeenCalled();
|
|
1071
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
1072
|
-
"cursor-chat",
|
|
1073
|
-
"Cursor Usage",
|
|
1074
|
-
expect.stringContaining("Individual used: $1012.52"),
|
|
1075
|
-
"blue",
|
|
1076
|
-
);
|
|
1077
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
1078
|
-
"cursor-chat",
|
|
1079
|
-
"Cursor Usage",
|
|
1080
|
-
expect.stringContaining("Pool remaining: $171417.76"),
|
|
1081
|
-
"blue",
|
|
1082
|
-
);
|
|
1083
|
-
expect(platform.setChatAvatar).toHaveBeenCalledWith(
|
|
1084
|
-
"cursor-chat",
|
|
1085
|
-
"cursor",
|
|
1086
|
-
"idle",
|
|
1087
|
-
{ cursorUsage: expect.objectContaining({ displayMessage: "You've hit your usage limit" }) },
|
|
1088
|
-
);
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
it("keeps the busy avatar status when /usage runs for an active Cursor session", async () => {
|
|
1092
|
-
const platform = mockPlatform("feishu");
|
|
1093
|
-
await recordSessionRegistry({
|
|
1094
|
-
chatId: "cursor-chat",
|
|
1095
|
-
sessionId: "sid-cursor",
|
|
1096
|
-
tool: "cursor",
|
|
1097
|
-
chatName: "cursor-session",
|
|
1098
|
-
running: true,
|
|
1099
|
-
});
|
|
1100
|
-
activePrompts.set("sid-cursor", {
|
|
1101
|
-
controller: new AbortController(),
|
|
1102
|
-
stopped: false,
|
|
1103
|
-
startTime: Date.now(),
|
|
1104
|
-
});
|
|
1105
|
-
|
|
1106
|
-
await handleCommand(platform, "/usage", "cursor-chat", "ou-user", Date.now(), "group");
|
|
1107
|
-
|
|
1108
|
-
expect(platform.setChatAvatar).toHaveBeenCalledWith(
|
|
1109
|
-
"cursor-chat",
|
|
1110
|
-
"cursor",
|
|
1111
|
-
"busy",
|
|
1112
|
-
{ cursorUsage: expect.objectContaining({ displayMessage: "You've hit your usage limit" }) },
|
|
1113
|
-
);
|
|
1114
|
-
});
|
|
1115
|
-
|
|
1116
|
-
it("advertises /usage in new Codex and Cursor session ready messages", async () => {
|
|
1117
|
-
const codexPlatform = mockPlatform("feishu");
|
|
1118
|
-
_setAdapterForToolForTest("codex", mockAdapter("sid-codex"));
|
|
1119
|
-
|
|
1120
|
-
await handleCommand(codexPlatform, "/new codex", "feishu-p2p", "ou-user", Date.now(), "p2p");
|
|
1121
|
-
|
|
1122
|
-
expect(codexPlatform.sendCard).toHaveBeenCalledWith(
|
|
1123
|
-
"feishu-group",
|
|
1124
|
-
"Codex Session Ready",
|
|
1125
|
-
expect.stringContaining("发送 **/usage** 查看 Codex 实际存在的 5h/7天用量窗口,以及查询/使用主动重置卡。"),
|
|
1126
|
-
"green",
|
|
1127
|
-
);
|
|
1128
|
-
|
|
1129
|
-
const codexReadyCall = vi.mocked(codexPlatform.sendCard).mock.calls.find(
|
|
1130
|
-
([chatId, title]) => chatId === "feishu-group" && title === "Codex Session Ready",
|
|
1131
|
-
);
|
|
1132
|
-
const modelHelpIndex = codexReadyCall?.[2].indexOf("/model") ?? -1;
|
|
1133
|
-
const fastHelpIndex = codexReadyCall?.[2].indexOf("/fast") ?? -1;
|
|
1134
|
-
expect(modelHelpIndex).toBeGreaterThanOrEqual(0);
|
|
1135
|
-
expect(fastHelpIndex).toBeGreaterThan(modelHelpIndex);
|
|
1136
|
-
|
|
1137
|
-
const cursorPlatform = mockPlatform("feishu");
|
|
1138
|
-
_setAdapterForToolForTest("cursor", mockAdapter("sid-cursor"));
|
|
1139
|
-
|
|
1140
|
-
await handleCommand(cursorPlatform, "/new cursor", "feishu-p2p-cursor", "ou-user", Date.now(), "p2p");
|
|
1141
|
-
|
|
1142
|
-
const cursorReadyCall = vi.mocked(cursorPlatform.sendCard).mock.calls.find(
|
|
1143
|
-
([chatId, title]) => chatId === "feishu-group" && title === "Cursor Session Ready",
|
|
1144
|
-
);
|
|
1145
|
-
expect(cursorReadyCall?.[2]).toContain("/usage");
|
|
1146
|
-
|
|
1147
|
-
const claudePlatform = mockPlatform("feishu");
|
|
1148
|
-
await handleCommand(claudePlatform, "/new claude", "feishu-p2p-2", "ou-user", Date.now(), "p2p");
|
|
1149
|
-
|
|
1150
|
-
const claudeReadyCall = vi.mocked(claudePlatform.sendCard).mock.calls.find(
|
|
1151
|
-
([chatId, title]) => chatId === "feishu-group" && title === "Claude Code Session Ready",
|
|
1152
|
-
);
|
|
1153
|
-
expect(claudeReadyCall?.[2]).not.toContain("/usage");
|
|
1154
|
-
});
|
|
1155
|
-
|
|
1156
|
-
it("handles /usage as DeepSeek balance in CCC Agent chats", async () => {
|
|
1157
|
-
const platform = mockPlatform("feishu");
|
|
1158
|
-
const fetchMock = vi.fn(async () => new Response(JSON.stringify({
|
|
1159
|
-
is_available: true,
|
|
1160
|
-
balance_infos: [{
|
|
1161
|
-
currency: "CNY",
|
|
1162
|
-
total_balance: "12.34",
|
|
1163
|
-
topped_up_balance: "10.00",
|
|
1164
|
-
granted_balance: "2.34",
|
|
1165
|
-
}],
|
|
1166
|
-
}), { status: 200 }));
|
|
1167
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
1168
|
-
await recordSessionRegistry({
|
|
1169
|
-
chatId: "ccc-chat",
|
|
1170
|
-
sessionId: "sid-ccc",
|
|
1171
|
-
tool: "ccc",
|
|
1172
|
-
chatName: "ccc-session",
|
|
1173
|
-
running: false,
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
await handleCommand(platform, "/usage", "ccc-chat", "ou-user", Date.now(), "group");
|
|
1177
|
-
|
|
1178
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
1179
|
-
"https://api.deepseek.com/user/balance",
|
|
1180
|
-
expect.objectContaining({ headers: { Authorization: "Bearer sk-test-ccc" } }),
|
|
1181
|
-
);
|
|
1182
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
1183
|
-
"ccc-chat",
|
|
1184
|
-
"CCC Usage",
|
|
1185
|
-
expect.stringContaining("总余额: 12.34"),
|
|
1186
|
-
"blue",
|
|
1187
|
-
);
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
it("does not query balance for a non-official CCC API endpoint", async () => {
|
|
1191
|
-
const platform = mockPlatform("feishu");
|
|
1192
|
-
const fetchMock = vi.fn();
|
|
1193
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
1194
|
-
config.ccc.DEEPSEEK_BASE_URL = "https://deepseek-proxy.example.com/v1";
|
|
1195
|
-
await recordSessionRegistry({
|
|
1196
|
-
chatId: "ccc-proxy-chat",
|
|
1197
|
-
sessionId: "sid-ccc-proxy",
|
|
1198
|
-
tool: "ccc",
|
|
1199
|
-
chatName: "ccc-proxy-session",
|
|
1200
|
-
running: false,
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
await handleCommand(platform, "/usage", "ccc-proxy-chat", "ou-user", Date.now(), "group");
|
|
1204
|
-
|
|
1205
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
1206
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
1207
|
-
"ccc-proxy-chat",
|
|
1208
|
-
"CCC Usage",
|
|
1209
|
-
expect.stringContaining("仅支持官方 DeepSeek API"),
|
|
1210
|
-
"blue",
|
|
1211
|
-
);
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
it("reloads runtime config for the exact /reload command", async () => {
|
|
1215
|
-
const platform = mockPlatform("feishu");
|
|
1216
|
-
|
|
1217
|
-
await handleCommand(platform, "/reload", "feishu-chat", "open-1", Date.now(), "group");
|
|
1218
|
-
|
|
1219
|
-
expect(mockReloadRuntimeConfig).toHaveBeenCalledWith("chat-command");
|
|
1220
|
-
expect(platform.sendText).toHaveBeenCalledWith(
|
|
1221
|
-
"feishu-chat",
|
|
1222
|
-
expect.stringContaining("配置已重新加载"),
|
|
1223
|
-
);
|
|
1224
|
-
expect(platform.sendText).toHaveBeenCalledWith(
|
|
1225
|
-
"feishu-chat",
|
|
1226
|
-
expect.stringContaining("默认 Agent: Codex"),
|
|
1227
|
-
);
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
|
-
it("allows and advertises the /new ccc entry", async () => {
|
|
1231
|
-
const platform = mockPlatform("feishu");
|
|
1232
|
-
_setAdapterForToolForTest("ccc", mockAdapter("session-20260702-121530-a1b2c3"));
|
|
1233
|
-
|
|
1234
|
-
await handleCommand(platform, "/new ccc", "feishu-p2p-ccc", "ou-user", Date.now(), "p2p");
|
|
1235
|
-
|
|
1236
|
-
expect(platform.updateChatInfo).toHaveBeenCalledWith(
|
|
1237
|
-
"feishu-group",
|
|
1238
|
-
expect.any(String),
|
|
1239
|
-
"CCC Session: session-20260702-121530-a1b2c3",
|
|
1240
|
-
);
|
|
1241
|
-
expect(platform.sendCard).toHaveBeenCalledWith(
|
|
1242
|
-
"feishu-group",
|
|
1243
|
-
"CCC Agent Session Ready",
|
|
1244
|
-
expect.stringContaining("CCC Agent"),
|
|
1245
|
-
"green",
|
|
1246
|
-
);
|
|
1247
|
-
|
|
1248
|
-
const helpPlatform = mockPlatform("feishu");
|
|
1249
|
-
await handleCommand(helpPlatform, "hello", "feishu-group-help", "ou-user", Date.now(), "group");
|
|
1250
|
-
const helpCard = vi.mocked(helpPlatform.sendRawCard).mock.calls.at(-1)?.[1] as string;
|
|
1251
|
-
expect(helpCard).toContain("/new ccc");
|
|
1252
|
-
expect(helpCard).toContain("CCC Agent");
|
|
1253
|
-
});
|
|
1254
|
-
|
|
1255
|
-
it("shows the CCC model list when CCC Agent is the unbound default", async () => {
|
|
1256
|
-
const platform = mockPlatform("feishu");
|
|
1257
|
-
config.claude.defaultAgent = false;
|
|
1258
|
-
config.cursor.defaultAgent = false;
|
|
1259
|
-
config.codex.defaultAgent = false;
|
|
1260
|
-
config.ccc.defaultAgent = true;
|
|
1261
|
-
|
|
1262
|
-
await handleCommand(platform, "/model", "feishu-p2p-ccc-model", "ou-user", Date.now(), "p2p");
|
|
1263
|
-
|
|
1264
|
-
const card = vi.mocked(platform.sendRawCard).mock.calls.at(-1)?.[1] as string;
|
|
1265
|
-
expect(card).toContain("deepseek-v4-pro");
|
|
1266
|
-
expect(card).toContain("deepseek-v4-flash");
|
|
1267
|
-
});
|
|
1268
|
-
});
|