chatccc 0.2.252 → 0.2.254
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 +10 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- package/config.sample.json +2 -1
- package/deepccc-agent/README.md +40 -35
- 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 +81 -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 +601 -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/agent-team/application/board-service.js +142 -0
- package/dist/src/agent-team/application/main-agent-service.js +151 -0
- package/dist/src/agent-team/domain/board.js +69 -0
- package/dist/src/agent-team/http/board-routes.js +213 -0
- package/dist/src/agent-team/infrastructure/filesystem-browser.js +112 -0
- package/dist/src/agent-team/infrastructure/main-agent-session-runtime.js +30 -0
- package/dist/src/agent-team/main-agent-bootstrap.js +15 -0
- package/dist/src/agent-team/repositories/board-repository.js +10 -0
- package/dist/src/agent-team/repositories/feishu-p2p-contact-store.js +64 -0
- package/dist/src/agent-team/repositories/json-board-repository.js +209 -0
- package/dist/src/agent-team/repositories/main-agent-binding-repository.js +84 -0
- package/dist/src/agent-team/sync/board-sync-adapter.js +1 -0
- package/dist/src/agent-team/web/agent-team-page.js +219 -0
- package/dist/src/agent-tool.js +10 -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 +808 -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 +835 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2096 -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 +2147 -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} +753 -839
- 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,607 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
buildProgressCard,
|
|
4
|
-
buildHelpCard,
|
|
5
|
-
buildCdContent,
|
|
6
|
-
buildCdCard,
|
|
7
|
-
buildSessionsCard,
|
|
8
|
-
buildStatusCard,
|
|
9
|
-
buildCodexUsageCard,
|
|
10
|
-
buildCodexResetConfirmCard,
|
|
11
|
-
buildFastModeCard,
|
|
12
|
-
buildModelCard,
|
|
13
|
-
buildButtons,
|
|
14
|
-
truncateContent,
|
|
15
|
-
getToolEmoji,
|
|
16
|
-
normalizeToolName,
|
|
17
|
-
} from "../cards.ts";
|
|
18
|
-
import { ABD_HELP_LINE } from "../shared-prefix.ts";
|
|
19
|
-
import { progressView } from "../progress/view.ts";
|
|
20
|
-
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// truncateContent
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
describe("truncateContent", () => {
|
|
26
|
-
it("returns original text when under limits", () => {
|
|
27
|
-
expect(truncateContent("hello")).toBe("hello");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("truncates lines when exceeding maxLines (default 20)", () => {
|
|
31
|
-
const lines = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`);
|
|
32
|
-
const text = lines.join("\n");
|
|
33
|
-
const result = truncateContent(text);
|
|
34
|
-
const resultLines = result.split("\n");
|
|
35
|
-
expect(resultLines.length).toBe(21); // 1 first + 1 "..." + 19 last
|
|
36
|
-
expect(resultLines[0]).toBe("line 1");
|
|
37
|
-
expect(resultLines[1]).toBe("...");
|
|
38
|
-
expect(resultLines[2]).toBe("line 7");
|
|
39
|
-
expect(resultLines[20]).toBe("line 25");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("returns empty string for empty input", () => {
|
|
43
|
-
expect(truncateContent("")).toBe("");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("respects custom maxLines", () => {
|
|
47
|
-
const lines = Array.from({ length: 10 }, (_, i) => `line ${i + 1}`);
|
|
48
|
-
const text = lines.join("\n");
|
|
49
|
-
const result = truncateContent(text, 5);
|
|
50
|
-
const resultLines = result.split("\n");
|
|
51
|
-
expect(resultLines[0]).toBe("line 1");
|
|
52
|
-
expect(resultLines[1]).toBe("...");
|
|
53
|
-
expect(resultLines[resultLines.length - 1]).toBe("line 10");
|
|
54
|
-
expect(resultLines.length).toBe(6); // 1 first + "..." + 4 last
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("skips leading empty lines, preserves first non-empty line", () => {
|
|
58
|
-
const lines = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`);
|
|
59
|
-
const text = "\n\n\n" + lines.join("\n");
|
|
60
|
-
const result = truncateContent(text);
|
|
61
|
-
const resultLines = result.split("\n");
|
|
62
|
-
expect(resultLines[0]).toBe("line 1");
|
|
63
|
-
expect(resultLines[1]).toBe("...");
|
|
64
|
-
expect(resultLines.length).toBe(21); // 1 first + "..." + 19 last
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
// getToolEmoji
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
|
|
72
|
-
describe("getToolEmoji", () => {
|
|
73
|
-
it("returns correct emoji for each known tool name", () => {
|
|
74
|
-
expect(getToolEmoji("Read")).toBe("\u{1F4D6}"); // 📖
|
|
75
|
-
expect(getToolEmoji("Write")).toBe("\u{270D}\u{FE0F}"); // ✍️
|
|
76
|
-
expect(getToolEmoji("Edit")).toBe("\u{270F}\u{FE0F}"); // ✏️
|
|
77
|
-
expect(getToolEmoji("Grep")).toBe("\u{1F50E}"); // 🔎
|
|
78
|
-
expect(getToolEmoji("Glob")).toBe("\u{1F4C2}"); // 📂
|
|
79
|
-
expect(getToolEmoji("Bash")).toBe("\u{1F5A5}\u{FE0F}"); // 🖥️
|
|
80
|
-
expect(getToolEmoji("WebSearch")).toBe("\u{1F310}"); // 🌐
|
|
81
|
-
expect(getToolEmoji("WebFetch")).toBe("\u{1F4E5}"); // 📥
|
|
82
|
-
expect(getToolEmoji("TodoWrite")).toBe("\u{2705}"); // ✅
|
|
83
|
-
expect(getToolEmoji("Agent")).toBe("\u{1F916}"); // 🤖
|
|
84
|
-
expect(getToolEmoji("NotebookEdit")).toBe("\u{1F4D3}"); // 📓
|
|
85
|
-
expect(getToolEmoji("AskUserQuestion")).toBe("\u{2753}");// ❓
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("returns correct emoji for CCC builtin tool names (snake_case)", () => {
|
|
89
|
-
expect(getToolEmoji("read_file")).toBe("\u{1F4D6}");
|
|
90
|
-
expect(getToolEmoji("list_dir")).toBe("\u{1F4C2}");
|
|
91
|
-
expect(getToolEmoji("search_code")).toBe("\u{1F50E}");
|
|
92
|
-
expect(getToolEmoji("run_command")).toBe("\u{1F5A5}\u{FE0F}");
|
|
93
|
-
expect(getToolEmoji("edit_file")).toBe("\u{270F}\u{FE0F}");
|
|
94
|
-
expect(getToolEmoji("create_file")).toBe("\u{270D}\u{FE0F}");
|
|
95
|
-
expect(getToolEmoji("delete_file")).toBe("\u{1F5D1}\u{FE0F}");
|
|
96
|
-
expect(getToolEmoji("move_file")).toBe("\u{1F4E6}");
|
|
97
|
-
expect(getToolEmoji("apply_patch")).toBe("\u{1F4CB}");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("normalizeToolName converts snake_case to PascalCase", () => {
|
|
101
|
-
expect(normalizeToolName("read_file")).toBe("ReadFile");
|
|
102
|
-
expect(normalizeToolName("run_command")).toBe("RunCommand");
|
|
103
|
-
expect(normalizeToolName("Read")).toBe("Read");
|
|
104
|
-
expect(normalizeToolName("")).toBe("");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("returns wrench for unknown tool names", () => {
|
|
108
|
-
expect(getToolEmoji("UnknownTool")).toBe("\u{1F527}");
|
|
109
|
-
expect(getToolEmoji("cat")).toBe("\u{1F527}");
|
|
110
|
-
expect(getToolEmoji("")).toBe("\u{1F527}");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
// buildProgressCard
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
|
|
118
|
-
describe("buildProgressCard", () => {
|
|
119
|
-
it("returns valid JSON with correct schema", () => {
|
|
120
|
-
const card = buildProgressCard(progressView({ text: "test content" }));
|
|
121
|
-
const parsed = JSON.parse(card);
|
|
122
|
-
expect(parsed.schema).toBe("2.0");
|
|
123
|
-
expect(parsed.config.update_multi).toBe(true);
|
|
124
|
-
expect(parsed.config.streaming_mode).toBe(false);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("uses default header title '生成中...'", () => {
|
|
128
|
-
const card = buildProgressCard(progressView({ text: "hello" }));
|
|
129
|
-
const parsed = JSON.parse(card);
|
|
130
|
-
expect(parsed.header.title.content).toBe("生成中...");
|
|
131
|
-
expect(parsed.header.template).toBe("blue");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("includes stop button by default", () => {
|
|
135
|
-
const card = buildProgressCard(progressView({ text: "hello" }));
|
|
136
|
-
const parsed = JSON.parse(card);
|
|
137
|
-
const buttons = parsed.body.elements.filter((e: any) => e.tag === "button");
|
|
138
|
-
expect(buttons).toHaveLength(2);
|
|
139
|
-
expect(buttons[0].text.content).toBe("查看状态(/state)");
|
|
140
|
-
expect(buttons[0].value).toEqual({ action: "state" });
|
|
141
|
-
expect(buttons[0].element_id).toBe("action_state");
|
|
142
|
-
expect(buttons[1].text.content).toBe("停止生成(/stop)");
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("hides stop button when showStop is false", () => {
|
|
146
|
-
const card = buildProgressCard(progressView({ text: "hello", showStop: false }));
|
|
147
|
-
const parsed = JSON.parse(card);
|
|
148
|
-
const buttons = parsed.body.elements.filter((e: any) => e.tag === "button");
|
|
149
|
-
expect(buttons).toHaveLength(0);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("uses custom header title and template", () => {
|
|
153
|
-
const card = buildProgressCard(progressView({ text: "hello", headerTitle: "已完成", headerTemplate: "green" }));
|
|
154
|
-
const parsed = JSON.parse(card);
|
|
155
|
-
expect(parsed.header.title.content).toBe("已完成");
|
|
156
|
-
expect(parsed.header.template).toBe("green");
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("includes markdown element with truncated content", () => {
|
|
160
|
-
const card = buildProgressCard(progressView({ text: "markdown text" }));
|
|
161
|
-
const parsed = JSON.parse(card);
|
|
162
|
-
const md = parsed.body.elements.find((e: any) => e.tag === "markdown");
|
|
163
|
-
expect(md).toBeDefined();
|
|
164
|
-
expect(md.element_id).toBe("main_content");
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
// buildHelpCard
|
|
170
|
-
// ---------------------------------------------------------------------------
|
|
171
|
-
|
|
172
|
-
describe("buildHelpCard", () => {
|
|
173
|
-
it("returns valid JSON with user text", () => {
|
|
174
|
-
const card = buildHelpCard("你好");
|
|
175
|
-
const parsed = JSON.parse(card);
|
|
176
|
-
expect(parsed.header.title.content).toBe("ChatCCC");
|
|
177
|
-
expect(parsed.elements[0].text.content).toContain("你好");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("includes action buttons", () => {
|
|
181
|
-
const card = buildHelpCard("test");
|
|
182
|
-
const parsed = JSON.parse(card);
|
|
183
|
-
const action = parsed.elements[2];
|
|
184
|
-
expect(action.tag).toBe("action");
|
|
185
|
-
expect(action.actions).toHaveLength(8);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("adds ABD prefix help as the final help line", () => {
|
|
189
|
-
const card = buildHelpCard("test");
|
|
190
|
-
const parsed = JSON.parse(card);
|
|
191
|
-
const lines = parsed.elements[1].text.content.split("\n");
|
|
192
|
-
|
|
193
|
-
expect(lines).toContain("发送 **/usage** 查看当前 Agent 的用量或余额");
|
|
194
|
-
expect(lines.at(-1)).toBe(ABD_HELP_LINE);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("advertises CCC Agent as a normal session option", () => {
|
|
198
|
-
const card = buildHelpCard("test");
|
|
199
|
-
const parsed = JSON.parse(card);
|
|
200
|
-
const text = JSON.stringify(parsed);
|
|
201
|
-
|
|
202
|
-
expect(text).toContain("/new ccc");
|
|
203
|
-
expect(text).toContain("CCC Agent");
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe("Codex Fast mode cards", () => {
|
|
208
|
-
it("shows the current mode and exposes ON/OFF commands", () => {
|
|
209
|
-
const card = JSON.parse(buildFastModeCard(false)) as {
|
|
210
|
-
header: { title: { content: string } };
|
|
211
|
-
elements: Array<{
|
|
212
|
-
tag: string;
|
|
213
|
-
text?: { content: string };
|
|
214
|
-
actions?: Array<{ text: { content: string }; value: string }>;
|
|
215
|
-
}>;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
expect(card.header.title.content).toBe("Codex Fast 模式");
|
|
219
|
-
expect(card.elements.find((element) => element.tag === "div")?.text?.content).toContain("OFF");
|
|
220
|
-
const actions = card.elements.find((element) => element.tag === "action")?.actions ?? [];
|
|
221
|
-
expect(actions.map((action) => JSON.parse(action.value).cmd)).toEqual([
|
|
222
|
-
"/fast on",
|
|
223
|
-
"/fast off",
|
|
224
|
-
]);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("places /fast help immediately after /model help for Codex", () => {
|
|
228
|
-
const card = JSON.parse(buildModelCard("gpt-5", ["gpt-5"], "codex")) as {
|
|
229
|
-
elements: Array<{ tag: string; text?: { content: string } }>;
|
|
230
|
-
};
|
|
231
|
-
const content = card.elements.find((element) => element.tag === "div")?.text?.content ?? "";
|
|
232
|
-
const modelHelpIndex = content.indexOf("/model");
|
|
233
|
-
const fastHelpIndex = content.indexOf("/fast");
|
|
234
|
-
|
|
235
|
-
expect(modelHelpIndex).toBeGreaterThanOrEqual(0);
|
|
236
|
-
expect(fastHelpIndex).toBeGreaterThan(modelHelpIndex);
|
|
237
|
-
expect(content.slice(modelHelpIndex, fastHelpIndex).split("\n")).toHaveLength(2);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// ---------------------------------------------------------------------------
|
|
242
|
-
// buildCdContent
|
|
243
|
-
// ---------------------------------------------------------------------------
|
|
244
|
-
|
|
245
|
-
describe("buildCdContent", () => {
|
|
246
|
-
const entries = [
|
|
247
|
-
{ name: "src", isDir: true },
|
|
248
|
-
{ name: "README.md", isDir: false },
|
|
249
|
-
{ name: "package.json", isDir: false },
|
|
250
|
-
];
|
|
251
|
-
|
|
252
|
-
it("returns markdown with path and listing", () => {
|
|
253
|
-
const content = buildCdContent("/home/user/project", entries, false);
|
|
254
|
-
expect(content).toContain("/home/user/project");
|
|
255
|
-
expect(content).toContain("📁 src/");
|
|
256
|
-
expect(content).toContain("📄 README.md");
|
|
257
|
-
expect(content).toContain("📄 package.json");
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it("shows 已切换 when isUpdate is true", () => {
|
|
261
|
-
const content = buildCdContent("/home/user/project", entries, true);
|
|
262
|
-
expect(content).toContain("(已切换)");
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("shows currentCwd when provided", () => {
|
|
266
|
-
const content = buildCdContent("/new/path", entries, false, "/old/path");
|
|
267
|
-
expect(content).toContain("当前会话工作路径");
|
|
268
|
-
expect(content).toContain("/old/path");
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("omits currentCwd line when not provided", () => {
|
|
272
|
-
const content = buildCdContent("/new/path", entries, false);
|
|
273
|
-
expect(content).not.toContain("当前会话工作路径");
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("caps listing at maxFiles", () => {
|
|
277
|
-
const many = Array.from({ length: 150 }, (_, i) => ({
|
|
278
|
-
name: `file${i}.txt`,
|
|
279
|
-
isDir: false,
|
|
280
|
-
}));
|
|
281
|
-
const content = buildCdContent("/path", many, false);
|
|
282
|
-
expect(content).toContain("仅显示前 100 个");
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// ---------------------------------------------------------------------------
|
|
287
|
-
// buildCdCard
|
|
288
|
-
// ---------------------------------------------------------------------------
|
|
289
|
-
|
|
290
|
-
describe("buildCdCard", () => {
|
|
291
|
-
const entries = [
|
|
292
|
-
{ name: "src", isDir: true },
|
|
293
|
-
{ name: "README.md", isDir: false },
|
|
294
|
-
];
|
|
295
|
-
|
|
296
|
-
// 提取 v1 卡片中 `tag:"div"` 的 markdown content(飞书 v1 富文本写在 text.content)
|
|
297
|
-
const mdContents = (parsed: any): string[] =>
|
|
298
|
-
parsed.elements
|
|
299
|
-
.filter((e: any) => e.tag === "div" && e.text?.tag === "lark_md")
|
|
300
|
-
.map((e: any) => e.text.content);
|
|
301
|
-
|
|
302
|
-
it("uses v1 interactive card format (no schema field, elements at top level)", () => {
|
|
303
|
-
// 必须用 v1 格式发送,否则通过 /im/v1/messages?msg_type=interactive 端点
|
|
304
|
-
// 直接发会被飞书静默拒绝(schema 2.0 卡片必须先经 CardKit 创建)
|
|
305
|
-
const card = buildCdCard("/home/project", entries, []);
|
|
306
|
-
const parsed = JSON.parse(card);
|
|
307
|
-
expect(parsed.schema).toBeUndefined();
|
|
308
|
-
expect(parsed.body).toBeUndefined();
|
|
309
|
-
expect(Array.isArray(parsed.elements)).toBe(true);
|
|
310
|
-
expect(parsed.header.title.content).toBe("工作路径");
|
|
311
|
-
expect(parsed.header.template).toBe("blue");
|
|
312
|
-
expect(parsed.config.wide_screen_mode).toBe(true);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("shows current working directory in markdown", () => {
|
|
316
|
-
const card = buildCdCard("/home/project", entries, []);
|
|
317
|
-
const parsed = JSON.parse(card);
|
|
318
|
-
const cwdContent = mdContents(parsed).find((c) => c.includes("后续新建会话默认工作路径"));
|
|
319
|
-
expect(cwdContent).toBeDefined();
|
|
320
|
-
expect(cwdContent).toContain("/home/project");
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("shows sessionCwd when provided", () => {
|
|
324
|
-
const card = buildCdCard("/default", entries, [], "/session/path");
|
|
325
|
-
const parsed = JSON.parse(card);
|
|
326
|
-
const sessionContent = mdContents(parsed).find((c) => c.includes("当前会话工作路径"));
|
|
327
|
-
expect(sessionContent).toBeDefined();
|
|
328
|
-
expect(sessionContent).toContain("/session/path");
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("does not show sessionCwd when not provided", () => {
|
|
332
|
-
const card = buildCdCard("/default", entries, []);
|
|
333
|
-
const parsed = JSON.parse(card);
|
|
334
|
-
const sessionContent = mdContents(parsed).find((c) => c.includes("当前会话工作路径"));
|
|
335
|
-
expect(sessionContent).toBeUndefined();
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it("shows recent dirs section with buttons", () => {
|
|
339
|
-
const recentDirs = ["/home/user/project1", "/home/user/project2"];
|
|
340
|
-
const card = buildCdCard("/current", entries, recentDirs);
|
|
341
|
-
const parsed = JSON.parse(card);
|
|
342
|
-
const recentMd = mdContents(parsed).find((c) => c.includes("最近使用过的路径"));
|
|
343
|
-
expect(recentMd).toBeDefined();
|
|
344
|
-
|
|
345
|
-
const actionElements: any[] = parsed.elements.filter((e: any) => e.tag === "action");
|
|
346
|
-
expect(actionElements.length).toBeGreaterThanOrEqual(1);
|
|
347
|
-
const recentAction = actionElements.find((e: any) =>
|
|
348
|
-
e.actions.some((a: any) => a.value?.action === "cd")
|
|
349
|
-
);
|
|
350
|
-
expect(recentAction).toBeDefined();
|
|
351
|
-
expect(recentAction.actions).toHaveLength(2);
|
|
352
|
-
expect(recentAction.actions[0].value.action).toBe("cd");
|
|
353
|
-
expect(recentAction.actions[0].value.path).toBe("/home/user/project1");
|
|
354
|
-
expect(recentAction.actions[1].value.path).toBe("/home/user/project2");
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it("does not show recent dirs section when empty", () => {
|
|
358
|
-
const card = buildCdCard("/current", entries, []);
|
|
359
|
-
const parsed = JSON.parse(card);
|
|
360
|
-
const recentMd = mdContents(parsed).find((c) => c.includes("最近使用过的路径"));
|
|
361
|
-
expect(recentMd).toBeUndefined();
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it("truncates long paths in button text", () => {
|
|
365
|
-
const longPath = "/home/user/very/long/path/that/exceeds/thirty/six/chars";
|
|
366
|
-
const card = buildCdCard("/current", entries, [longPath]);
|
|
367
|
-
const parsed = JSON.parse(card);
|
|
368
|
-
const action: any = parsed.elements.find((e: any) => e.tag === "action");
|
|
369
|
-
const btnText = action.actions[0].text.content;
|
|
370
|
-
expect(btnText.startsWith("...")).toBe(true);
|
|
371
|
-
expect(btnText.length).toBeLessThanOrEqual(36);
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it("shows directory listing", () => {
|
|
375
|
-
const card = buildCdCard("/current", entries, []);
|
|
376
|
-
const parsed = JSON.parse(card);
|
|
377
|
-
const listingContent = mdContents(parsed).find((c) => c.includes("📁 src/"));
|
|
378
|
-
expect(listingContent).toBeDefined();
|
|
379
|
-
expect(listingContent).toContain("📄 README.md");
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// ---------------------------------------------------------------------------
|
|
384
|
-
// buildSessionsCard
|
|
385
|
-
// ---------------------------------------------------------------------------
|
|
386
|
-
|
|
387
|
-
describe("buildSessionsCard", () => {
|
|
388
|
-
it("returns valid JSON for empty sessions", () => {
|
|
389
|
-
const card = buildSessionsCard([]);
|
|
390
|
-
const parsed = JSON.parse(card);
|
|
391
|
-
expect(parsed.elements[0].text.content).toContain("没有会话记录");
|
|
392
|
-
expect(parsed.elements[0].text.content).toContain("/new");
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("returns valid JSON with session listing", () => {
|
|
396
|
-
const card = buildSessionsCard([
|
|
397
|
-
{ sessionId: "abc123", chatName: "test-group", chatId: "oc_test123", active: true, turnCount: 5, elapsedSeconds: 120, model: "Claude Opus 4.7", tool: "claude" },
|
|
398
|
-
]);
|
|
399
|
-
const parsed = JSON.parse(card);
|
|
400
|
-
expect(parsed.elements[0].text.content).toContain("共 **1** 个会话");
|
|
401
|
-
expect(parsed.elements[0].text.content).toContain("abc123");
|
|
402
|
-
expect(parsed.elements[0].text.content).toContain("🟢 活跃");
|
|
403
|
-
expect(parsed.elements[0].text.content).toContain("Claude Code");
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("shows idle status for inactive sessions", () => {
|
|
407
|
-
const card = buildSessionsCard([
|
|
408
|
-
{ sessionId: "xyz", chatName: "", chatId: "oc_xyz", active: false, turnCount: 0, elapsedSeconds: null, model: "Claude Sonnet 4.6", tool: "claude" },
|
|
409
|
-
]);
|
|
410
|
-
const parsed = JSON.parse(card);
|
|
411
|
-
expect(parsed.elements[0].text.content).toContain("⚪ 空闲");
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it("shows elapsed time for active sessions", () => {
|
|
415
|
-
const card = buildSessionsCard([
|
|
416
|
-
{ sessionId: "active123", chatName: "", chatId: "oc_active123", active: true, turnCount: 3, elapsedSeconds: 95, model: "Claude Opus 4.7", tool: "claude" },
|
|
417
|
-
]);
|
|
418
|
-
const parsed = JSON.parse(card);
|
|
419
|
-
expect(parsed.elements[0].text.content).toContain("1分35秒");
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it("separates Claude Code and Cursor sessions", () => {
|
|
423
|
-
const card = buildSessionsCard([
|
|
424
|
-
{ sessionId: "c1", chatName: "", chatId: "oc_c1", active: false, turnCount: 1, elapsedSeconds: null, model: "(留空)", tool: "claude" },
|
|
425
|
-
{ sessionId: "c2", chatName: "", chatId: "oc_c2", active: false, turnCount: 2, elapsedSeconds: null, model: "claude-opus-4-7-max", tool: "cursor" },
|
|
426
|
-
]);
|
|
427
|
-
const parsed = JSON.parse(card);
|
|
428
|
-
const content: string = parsed.elements[0].text.content;
|
|
429
|
-
expect(content).toContain("Claude Code 会话");
|
|
430
|
-
expect(content).toContain("Cursor 会话");
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it("omits Cursor section when no Cursor sessions", () => {
|
|
434
|
-
const card = buildSessionsCard([
|
|
435
|
-
{ sessionId: "c1", chatName: "", chatId: "oc_c1", active: false, turnCount: 1, elapsedSeconds: null, model: "(留空)", tool: "claude" },
|
|
436
|
-
]);
|
|
437
|
-
const parsed = JSON.parse(card);
|
|
438
|
-
const content: string = parsed.elements[0].text.content;
|
|
439
|
-
expect(content).toContain("Claude Code 会话");
|
|
440
|
-
expect(content).not.toContain("Cursor 会话");
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it("labels CCC sessions without grouping them as Claude Code", () => {
|
|
444
|
-
const card = buildSessionsCard([
|
|
445
|
-
{ sessionId: "session-20260702-121530-a1b2c3", chatName: "", chatId: "oc_ccc", active: false, turnCount: 1, elapsedSeconds: null, model: "deepseek-v4-pro", tool: "ccc" },
|
|
446
|
-
]);
|
|
447
|
-
const parsed = JSON.parse(card);
|
|
448
|
-
const content: string = parsed.elements[0].text.content;
|
|
449
|
-
|
|
450
|
-
expect(content).toContain("CCC Agent 会话");
|
|
451
|
-
expect(content).toContain("工具: CCC Agent");
|
|
452
|
-
expect(content).not.toContain("Claude Code 会话");
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it("displays chatName when provided", () => {
|
|
456
|
-
const card = buildSessionsCard([
|
|
457
|
-
{ sessionId: "abc123", chatName: "帮我写代码-src", chatId: "oc_abc123", active: false, turnCount: 2, elapsedSeconds: null, model: "Claude Opus 4.7", tool: "claude" },
|
|
458
|
-
]);
|
|
459
|
-
const parsed = JSON.parse(card);
|
|
460
|
-
expect(parsed.elements[0].text.content).toContain("帮我写代码-src");
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
it("shows (群聊) tag for group chat sessions and not for private chats", () => {
|
|
464
|
-
const card = buildSessionsCard([
|
|
465
|
-
{ sessionId: "g1", chatName: "group-chat", chatId: "oc_group1", chatType: "group", active: false, turnCount: 1, elapsedSeconds: null, model: "Claude Opus 4.7", tool: "claude" },
|
|
466
|
-
{ sessionId: "p1", chatName: "private-chat", chatId: "oc_private1", chatType: "p2p", active: false, turnCount: 1, elapsedSeconds: null, model: "Claude Opus 4.7", tool: "claude" },
|
|
467
|
-
]);
|
|
468
|
-
const content: string = JSON.parse(card).elements[0].text.content;
|
|
469
|
-
expect(content).toContain("(群聊)");
|
|
470
|
-
expect(content).toContain("(私聊)");
|
|
471
|
-
// 群聊会话包含 (群聊)
|
|
472
|
-
expect(content).toMatch(/group-chat.*\(群聊\)/);
|
|
473
|
-
// 私聊会话不包含 (群聊)
|
|
474
|
-
expect(content).toMatch(/private-chat/);
|
|
475
|
-
const afterPrivateChat = content.split("private-chat")[1];
|
|
476
|
-
expect(afterPrivateChat).not.toContain("(群聊)");
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
it("shows chat id missing for sessions without a chat binding", () => {
|
|
480
|
-
const card = buildSessionsCard([
|
|
481
|
-
{ sessionId: "orphan", chatName: "", chatId: "", active: true, turnCount: 0, elapsedSeconds: 3, model: "Claude Opus 4.7", tool: "claude" },
|
|
482
|
-
]);
|
|
483
|
-
const content: string = JSON.parse(card).elements[0].text.content;
|
|
484
|
-
expect(content).toContain("chat id缺失");
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it("includes /session help text in non-empty card", () => {
|
|
488
|
-
const card = buildSessionsCard([
|
|
489
|
-
{ sessionId: "abc123", chatName: "", chatId: "oc_abc123", active: false, turnCount: 2, elapsedSeconds: null, model: "Claude Opus 4.7", tool: "claude" },
|
|
490
|
-
]);
|
|
491
|
-
const parsed = JSON.parse(card);
|
|
492
|
-
expect(parsed.elements[2].text.content).toContain("/session 数字");
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it("explains Feishu private-session default Agent following without advertising /session switching", () => {
|
|
496
|
-
const card = buildSessionsCard([
|
|
497
|
-
{ sessionId: "abc123", chatName: "飞书私聊", chatId: "ou_private", active: false, turnCount: 2, elapsedSeconds: null, model: "Claude Opus 4.7", tool: "claude" },
|
|
498
|
-
], { fixedPrivateSession: true });
|
|
499
|
-
const parsed = JSON.parse(card);
|
|
500
|
-
expect(parsed.elements[2].text.content).toContain("下一条普通消息");
|
|
501
|
-
expect(parsed.elements[2].text.content).toContain("新空会话");
|
|
502
|
-
expect(parsed.elements[2].text.content).toContain("不支持 **/session** 切换");
|
|
503
|
-
expect(parsed.elements[2].text.content).not.toContain("/session 数字");
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
it("includes close button", () => {
|
|
507
|
-
const card = buildSessionsCard([]);
|
|
508
|
-
const parsed = JSON.parse(card);
|
|
509
|
-
const action = parsed.elements[2];
|
|
510
|
-
expect(action.actions[0].text.content).toBe("收起");
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
// ---------------------------------------------------------------------------
|
|
515
|
-
// buildStatusCard
|
|
516
|
-
// ---------------------------------------------------------------------------
|
|
517
|
-
|
|
518
|
-
describe("buildStatusCard", () => {
|
|
519
|
-
it("returns valid JSON with status text", () => {
|
|
520
|
-
const card = buildStatusCard("一切正常");
|
|
521
|
-
const parsed = JSON.parse(card);
|
|
522
|
-
expect(parsed.header.title.content).toBe("会话状态");
|
|
523
|
-
expect(parsed.elements[0].text.content).toBe("一切正常");
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
it("uses custom template color", () => {
|
|
527
|
-
const card = buildStatusCard("警告", "red");
|
|
528
|
-
const parsed = JSON.parse(card);
|
|
529
|
-
expect(parsed.header.template).toBe("red");
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
it("includes close button", () => {
|
|
533
|
-
const card = buildStatusCard("test");
|
|
534
|
-
const parsed = JSON.parse(card);
|
|
535
|
-
const action = parsed.elements[2];
|
|
536
|
-
expect(action.actions[0].text.content).toBe("收起");
|
|
537
|
-
});
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
// ---------------------------------------------------------------------------
|
|
541
|
-
// buildCodexUsageCard / buildCodexResetConfirmCard
|
|
542
|
-
// ---------------------------------------------------------------------------
|
|
543
|
-
|
|
544
|
-
describe("Codex usage reset cards", () => {
|
|
545
|
-
it("shows the reset button only when reset credits are available", () => {
|
|
546
|
-
const card = buildCodexUsageCard("Codex 用量", 2);
|
|
547
|
-
const parsed = JSON.parse(card);
|
|
548
|
-
const action = parsed.elements.find((element: any) => element.tag === "action");
|
|
549
|
-
expect(action.actions[0].text.content).toBe("发起重置");
|
|
550
|
-
expect(action.actions[0].value).toEqual({ action: "codex_reset_request", availableCount: 2 });
|
|
551
|
-
|
|
552
|
-
const noCreditCard = buildCodexUsageCard("Codex 用量", 0);
|
|
553
|
-
const noCreditParsed = JSON.parse(noCreditCard);
|
|
554
|
-
expect(noCreditParsed.elements.some((element: any) => element.tag === "action")).toBe(false);
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
it("builds yes/no confirmation buttons tied to the parent usage card", () => {
|
|
558
|
-
const card = buildCodexResetConfirmCard({
|
|
559
|
-
availableCount: 2,
|
|
560
|
-
parentMessageId: "usage-message",
|
|
561
|
-
requestId: "request-1",
|
|
562
|
-
});
|
|
563
|
-
const parsed = JSON.parse(card);
|
|
564
|
-
const action = parsed.elements.find((element: any) => element.tag === "action");
|
|
565
|
-
|
|
566
|
-
expect(action.actions[0].text.content).toBe("是,发起重置");
|
|
567
|
-
expect(action.actions[0].value).toEqual({
|
|
568
|
-
action: "codex_reset_confirm",
|
|
569
|
-
decision: "yes",
|
|
570
|
-
parentMessageId: "usage-message",
|
|
571
|
-
requestId: "request-1",
|
|
572
|
-
});
|
|
573
|
-
expect(action.actions[1].text.content).toBe("否");
|
|
574
|
-
expect(action.actions[1].value).toEqual({
|
|
575
|
-
action: "codex_reset_confirm",
|
|
576
|
-
decision: "no",
|
|
577
|
-
parentMessageId: "usage-message",
|
|
578
|
-
requestId: "request-1",
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
// ---------------------------------------------------------------------------
|
|
584
|
-
// buildButtons
|
|
585
|
-
// ---------------------------------------------------------------------------
|
|
586
|
-
|
|
587
|
-
describe("buildButtons", () => {
|
|
588
|
-
it("returns action with buttons", () => {
|
|
589
|
-
const result = buildButtons([
|
|
590
|
-
{ text: "确认", value: "ok", type: "primary" },
|
|
591
|
-
]);
|
|
592
|
-
const obj = result as any;
|
|
593
|
-
expect(obj.tag).toBe("action");
|
|
594
|
-
expect(obj.actions).toHaveLength(1);
|
|
595
|
-
expect(obj.actions[0].text.content).toBe("确认");
|
|
596
|
-
expect(obj.actions[0].type).toBe("primary");
|
|
597
|
-
expect(obj.actions[0].value).toBe("ok");
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it("defaults button type to primary", () => {
|
|
601
|
-
const result = buildButtons([
|
|
602
|
-
{ text: "取消", value: "cancel" },
|
|
603
|
-
]);
|
|
604
|
-
const obj = result as any;
|
|
605
|
-
expect(obj.actions[0].type).toBe("primary");
|
|
606
|
-
});
|
|
607
|
-
});
|