chatccc 0.2.231 → 0.2.233
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/.agents/skills/create-chatccc-feishu-app/SKILL.md +85 -85
- package/.claude/skills/create-chatccc-feishu-app/SKILL.md +85 -85
- package/.cursor/skills/create-chatccc-feishu-app/SKILL.md +85 -85
- package/README.md +90 -90
- package/agent-prompts/claude_specific.md +45 -45
- package/agent-prompts/codex_specific.md +2 -2
- package/agent-prompts/cursor_specific.md +13 -13
- package/bin/cccagent.mjs +17 -17
- package/im-skills/feishu-skill/receive-send-file.md +63 -63
- package/im-skills/feishu-skill/receive-send-image.md +24 -24
- package/im-skills/feishu-skill/skill.md +3 -3
- package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
- package/im-skills/wechat-file-skill/send-file.mjs +83 -83
- package/im-skills/wechat-file-skill/skill.md +10 -10
- package/im-skills/wechat-image-skill/skill.md +10 -10
- package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
- package/im-skills/wechat-video-skill/send-video.mjs +79 -79
- package/im-skills/wechat-video-skill/skill.md +10 -10
- package/package.json +1 -1
- package/scripts/postinstall-sharp-check.mjs +58 -58
- package/src/__tests__/agent-activity.test.ts +86 -86
- package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
- package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
- package/src/__tests__/builtin-chat-session.test.ts +449 -393
- package/src/__tests__/builtin-cli-json.test.ts +39 -39
- package/src/__tests__/builtin-config.test.ts +26 -26
- package/src/__tests__/builtin-context.test.ts +319 -202
- package/src/__tests__/builtin-file-tools.test.ts +240 -240
- package/src/__tests__/builtin-permissions.test.ts +211 -211
- package/src/__tests__/builtin-session-search.test.ts +228 -0
- package/src/__tests__/builtin-session-select.test.ts +116 -116
- package/src/__tests__/builtin-sigint.test.ts +56 -56
- package/src/__tests__/builtin-skills.test.ts +284 -284
- package/src/__tests__/builtin-web-tools.test.ts +220 -220
- package/src/__tests__/card-action-routing.test.ts +18 -18
- package/src/__tests__/cardkit.test.ts +60 -60
- package/src/__tests__/ccc-adapter.test.ts +170 -170
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
- package/src/__tests__/chatgpt-subscription.test.ts +135 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
- package/src/__tests__/claude-adapter.test.ts +614 -614
- package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
- package/src/__tests__/codex-adapter.test.ts +58 -58
- package/src/__tests__/codex-raw-stream-log.test.ts +170 -170
- package/src/__tests__/codex-reset-actions.test.ts +146 -146
- package/src/__tests__/crash-logging.test.ts +95 -1
- package/src/__tests__/cursor-adapter.test.ts +268 -268
- package/src/__tests__/feishu-api.test.ts +60 -60
- package/src/__tests__/feishu-avatar.test.ts +164 -164
- package/src/__tests__/feishu-message-ingress.test.ts +138 -138
- package/src/__tests__/feishu-platform.test.ts +22 -22
- package/src/__tests__/format-message.test.ts +47 -47
- package/src/__tests__/jsonl-stream.test.ts +79 -79
- package/src/__tests__/package-files.test.ts +24 -24
- package/src/__tests__/privacy.test.ts +198 -198
- package/src/__tests__/progress-reducer.test.ts +121 -121
- package/src/__tests__/raw-stream-log.test.ts +106 -106
- package/src/__tests__/response-stall.test.ts +49 -49
- package/src/__tests__/restart.test.ts +55 -10
- package/src/__tests__/session.test.ts +199 -199
- package/src/__tests__/shared-prefix.test.ts +36 -36
- package/src/__tests__/sim-platform.test.ts +16 -16
- package/src/__tests__/startup-lifecycle.test.ts +231 -231
- package/src/__tests__/stop-session.test.ts +34 -34
- package/src/__tests__/stream-state.test.ts +42 -42
- package/src/__tests__/terminal-error.test.ts +54 -54
- package/src/__tests__/terminal-renderer.test.ts +247 -247
- package/src/__tests__/update-command-guard.test.ts +144 -144
- package/src/__tests__/web-ui.test.ts +326 -326
- package/src/adapters/adapter-interface.ts +33 -33
- package/src/adapters/ccc-adapter.ts +141 -141
- package/src/adapters/claude-adapter.ts +620 -620
- package/src/adapters/claude-session-meta-store.ts +120 -120
- package/src/adapters/codex-adapter.ts +426 -426
- package/src/adapters/cursor-adapter.ts +681 -681
- package/src/adapters/jsonl-stream.ts +157 -157
- package/src/adapters/raw-stream-log.ts +124 -124
- package/src/adapters/resource-monitor.ts +140 -140
- package/src/agent-activity.ts +175 -175
- package/src/agent-delegate-task-rpc.ts +153 -153
- package/src/agent-delegate-task.ts +91 -91
- package/src/agent-reload-config-rpc.ts +34 -34
- package/src/agent-stop-stuck.ts +129 -129
- package/src/builtin/cli.ts +6 -0
- package/src/builtin/config.ts +84 -84
- package/src/builtin/context.ts +465 -391
- package/src/builtin/file-log.ts +38 -38
- package/src/builtin/file-tools.ts +34 -0
- package/src/builtin/index.ts +24 -23
- package/src/builtin/proc-tree-kill.ts +61 -61
- package/src/builtin/progress/cards-helpers.ts +76 -76
- package/src/builtin/progress/reducer.ts +113 -113
- package/src/builtin/progress/terminal-renderer.ts +294 -294
- package/src/builtin/progress/view.ts +77 -77
- package/src/builtin/raw-stream-log.ts +124 -124
- package/src/builtin/session-search.ts +363 -0
- package/src/builtin/session-select.ts +48 -48
- package/src/builtin/sigint.ts +50 -50
- package/src/builtin/skills.ts +205 -205
- package/src/builtin/web-tools.ts +313 -313
- package/src/card-action-routing.ts +14 -14
- package/src/chatgpt-subscription-rpc.ts +27 -27
- package/src/chatgpt-subscription.ts +299 -299
- package/src/chrome-devtools-guard.ts +318 -318
- package/src/codex-reset-actions.ts +184 -184
- package/src/feishu-api.ts +193 -193
- package/src/feishu-message-ingress.ts +195 -195
- package/src/feishu-platform.ts +20 -20
- package/src/format-message.ts +293 -293
- package/src/index.ts +6 -1
- package/src/litellm-proxy.ts +374 -374
- package/src/orchestrator.ts +36 -13
- package/src/platform-adapter.ts +6 -6
- package/src/privacy.ts +118 -118
- package/src/progress/reducer.ts +113 -113
- package/src/progress/terminal-renderer.ts +294 -294
- package/src/progress/view.ts +77 -77
- package/src/response-stall.ts +28 -28
- package/src/runtime-reload.ts +34 -34
- package/src/session-chat-binding.ts +82 -82
- package/src/session-name.ts +8 -8
- package/src/session.ts +201 -201
- package/src/shared-prefix.ts +29 -29
- package/src/shared.ts +44 -0
- package/src/sim-platform.ts +20 -20
- package/src/startup-lifecycle.ts +250 -250
- package/src/stream-state.ts +21 -21
- package/src/terminal-error.ts +129 -129
- package/src/turn-cards.ts +117 -117
- package/src/update-command-guard.ts +165 -165
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
// postinstall 检测 sharp 原生模块是否可用(常见于 Linux 缺少 libvips)
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
let ok = false;
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
require("sharp");
|
|
9
|
-
ok = true;
|
|
10
|
-
} catch (err) {
|
|
11
|
-
const msg = err.message;
|
|
12
|
-
const platform = process.platform;
|
|
13
|
-
|
|
14
|
-
console.warn("");
|
|
15
|
-
console.warn("============================================================");
|
|
16
|
-
console.warn(" ChatCCC: sharp 图像处理模块检测失败");
|
|
17
|
-
console.warn("============================================================");
|
|
18
|
-
|
|
19
|
-
if (platform === "linux") {
|
|
20
|
-
if (msg.includes("libvips") || msg.includes("vips") || msg.includes("libglib")) {
|
|
21
|
-
console.warn(" 原因:系统缺少 libvips 图像处理库。");
|
|
22
|
-
console.warn("");
|
|
23
|
-
console.warn(" 请先安装 libvips 然后重建 sharp:");
|
|
24
|
-
console.warn("");
|
|
25
|
-
console.warn(" Debian / Ubuntu:");
|
|
26
|
-
console.warn(" sudo apt install libvips-dev");
|
|
27
|
-
console.warn("");
|
|
28
|
-
console.warn(" CentOS / RHEL / Fedora:");
|
|
29
|
-
console.warn(" sudo yum install vips-devel");
|
|
30
|
-
console.warn("");
|
|
31
|
-
console.warn(" Alpine:");
|
|
32
|
-
console.warn(" sudo apk add vips-dev");
|
|
33
|
-
console.warn("");
|
|
34
|
-
console.warn(" 安装 libvips 后重建 sharp:");
|
|
35
|
-
console.warn(" npm install -g chatccc --force");
|
|
36
|
-
} else if (msg.includes("Cannot find module")) {
|
|
37
|
-
console.warn(" 原因:sharp 模块未成功安装。");
|
|
38
|
-
console.warn("");
|
|
39
|
-
console.warn(" 请尝试重建(可能需要先安装 libvips):");
|
|
40
|
-
console.warn(" npm install -g chatccc --force");
|
|
41
|
-
} else {
|
|
42
|
-
console.warn(" 错误详情:", msg);
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
console.warn(" 错误详情:", msg);
|
|
46
|
-
console.warn(" 平台:", platform);
|
|
47
|
-
console.warn(" 请尝试:npm install -g chatccc --force");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
console.warn("");
|
|
51
|
-
console.warn(" 缺少 sharp 不影响消息收发,但群聊头像状态指示");
|
|
52
|
-
console.warn(" (运行中/空闲/新建)将不会更新。");
|
|
53
|
-
console.warn("============================================================");
|
|
54
|
-
console.warn("");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!ok && process.env.npm_config_verbose) {
|
|
58
|
-
process.exitCode = 0; // 永远不阻塞安装
|
|
1
|
+
// postinstall 检测 sharp 原生模块是否可用(常见于 Linux 缺少 libvips)
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
let ok = false;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
require("sharp");
|
|
9
|
+
ok = true;
|
|
10
|
+
} catch (err) {
|
|
11
|
+
const msg = err.message;
|
|
12
|
+
const platform = process.platform;
|
|
13
|
+
|
|
14
|
+
console.warn("");
|
|
15
|
+
console.warn("============================================================");
|
|
16
|
+
console.warn(" ChatCCC: sharp 图像处理模块检测失败");
|
|
17
|
+
console.warn("============================================================");
|
|
18
|
+
|
|
19
|
+
if (platform === "linux") {
|
|
20
|
+
if (msg.includes("libvips") || msg.includes("vips") || msg.includes("libglib")) {
|
|
21
|
+
console.warn(" 原因:系统缺少 libvips 图像处理库。");
|
|
22
|
+
console.warn("");
|
|
23
|
+
console.warn(" 请先安装 libvips 然后重建 sharp:");
|
|
24
|
+
console.warn("");
|
|
25
|
+
console.warn(" Debian / Ubuntu:");
|
|
26
|
+
console.warn(" sudo apt install libvips-dev");
|
|
27
|
+
console.warn("");
|
|
28
|
+
console.warn(" CentOS / RHEL / Fedora:");
|
|
29
|
+
console.warn(" sudo yum install vips-devel");
|
|
30
|
+
console.warn("");
|
|
31
|
+
console.warn(" Alpine:");
|
|
32
|
+
console.warn(" sudo apk add vips-dev");
|
|
33
|
+
console.warn("");
|
|
34
|
+
console.warn(" 安装 libvips 后重建 sharp:");
|
|
35
|
+
console.warn(" npm install -g chatccc --force");
|
|
36
|
+
} else if (msg.includes("Cannot find module")) {
|
|
37
|
+
console.warn(" 原因:sharp 模块未成功安装。");
|
|
38
|
+
console.warn("");
|
|
39
|
+
console.warn(" 请尝试重建(可能需要先安装 libvips):");
|
|
40
|
+
console.warn(" npm install -g chatccc --force");
|
|
41
|
+
} else {
|
|
42
|
+
console.warn(" 错误详情:", msg);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
console.warn(" 错误详情:", msg);
|
|
46
|
+
console.warn(" 平台:", platform);
|
|
47
|
+
console.warn(" 请尝试:npm install -g chatccc --force");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.warn("");
|
|
51
|
+
console.warn(" 缺少 sharp 不影响消息收发,但群聊头像状态指示");
|
|
52
|
+
console.warn(" (运行中/空闲/新建)将不会更新。");
|
|
53
|
+
console.warn("============================================================");
|
|
54
|
+
console.warn("");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!ok && process.env.npm_config_verbose) {
|
|
58
|
+
process.exitCode = 0; // 永远不阻塞安装
|
|
59
59
|
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createAgentActivityTracker,
|
|
5
|
-
formatAgentActivityTitle,
|
|
6
|
-
updateAgentActivity,
|
|
7
|
-
} from "../agent-activity.ts";
|
|
8
|
-
|
|
9
|
-
describe("agent activity", () => {
|
|
10
|
-
it("starts with an explicit startup status", () => {
|
|
11
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
12
|
-
|
|
13
|
-
expect(formatAgentActivityTitle(tracker.activity, 4_000)).toBe("正在启动 Agent · 3秒");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("keeps the thinking timer stable across repeated thinking blocks", () => {
|
|
17
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
18
|
-
|
|
19
|
-
expect(updateAgentActivity(tracker, { type: "thinking", thinking: "first" }, 2_000)).toBe(true);
|
|
20
|
-
expect(updateAgentActivity(tracker, { type: "thinking", thinking: "second" }, 5_000)).toBe(false);
|
|
21
|
-
expect(formatAgentActivityTitle(tracker.activity, 8_000)).toBe("思考中 · 6秒");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("shows the active tool name and elapsed time", () => {
|
|
25
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
26
|
-
|
|
27
|
-
updateAgentActivity(tracker, {
|
|
28
|
-
type: "tool_use",
|
|
29
|
-
id: "tool-1",
|
|
30
|
-
name: "Bash",
|
|
31
|
-
input: { command: "npm test" },
|
|
32
|
-
}, 3_000);
|
|
33
|
-
|
|
34
|
-
expect(formatAgentActivityTitle(tracker.activity, 38_000)).toBe("正在执行 Bash · 35秒");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("tracks parallel tools and keeps the remaining tool after one result", () => {
|
|
38
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
39
|
-
|
|
40
|
-
updateAgentActivity(tracker, { type: "tool_use", id: "read", name: "Read", input: {} }, 2_000);
|
|
41
|
-
updateAgentActivity(tracker, { type: "tool_use", id: "grep", name: "Grep", input: {} }, 3_000);
|
|
42
|
-
expect(formatAgentActivityTitle(tracker.activity, 4_000)).toBe("正在执行 Read 等 2 项 · 2秒");
|
|
43
|
-
|
|
44
|
-
updateAgentActivity(tracker, {
|
|
45
|
-
type: "tool_result",
|
|
46
|
-
tool_use_id: "read",
|
|
47
|
-
content: "done",
|
|
48
|
-
}, 5_000);
|
|
49
|
-
expect(formatAgentActivityTitle(tracker.activity, 7_000)).toBe("正在执行 Grep · 4秒");
|
|
50
|
-
|
|
51
|
-
updateAgentActivity(tracker, {
|
|
52
|
-
type: "tool_result",
|
|
53
|
-
tool_use_id: "grep",
|
|
54
|
-
content: "done",
|
|
55
|
-
}, 8_000);
|
|
56
|
-
expect(formatAgentActivityTitle(tracker.activity, 10_000)).toBe("正在处理工具结果 · 2秒");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("switches to response and context-compaction statuses", () => {
|
|
60
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
61
|
-
|
|
62
|
-
updateAgentActivity(tracker, { type: "text", text: "answer" }, 2_000);
|
|
63
|
-
expect(formatAgentActivityTitle(tracker.activity, 3_000)).toBe("正在生成回复 · 1秒");
|
|
64
|
-
|
|
65
|
-
updateAgentActivity(tracker, {
|
|
66
|
-
type: "compact_boundary",
|
|
67
|
-
trigger: "auto",
|
|
68
|
-
pre_tokens: 100_000,
|
|
69
|
-
}, 4_000);
|
|
70
|
-
expect(formatAgentActivityTitle(tracker.activity, 5_000)).toBe("正在整理上下文 · 1秒");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("uses explicit DeepCCC phase events before text is emitted", () => {
|
|
74
|
-
const tracker = createAgentActivityTracker(1_000);
|
|
75
|
-
|
|
76
|
-
expect(updateAgentActivity(tracker, { type: "agent_status", status: "compacting" }, 2_000)).toBe(true);
|
|
77
|
-
expect(tracker.activity).toEqual({ kind: "compacting", startedAt: 2_000 });
|
|
78
|
-
|
|
79
|
-
expect(updateAgentActivity(tracker, { type: "agent_status", status: "responding" }, 5_000)).toBe(true);
|
|
80
|
-
expect(tracker.activity).toEqual({ kind: "responding", startedAt: 5_000 });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("formats longer elapsed time without decorative animation", () => {
|
|
84
|
-
expect(formatAgentActivityTitle({ kind: "thinking", startedAt: 1_000 }, 74_000)).toBe("思考中 · 1分13秒");
|
|
85
|
-
});
|
|
86
|
-
});
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createAgentActivityTracker,
|
|
5
|
+
formatAgentActivityTitle,
|
|
6
|
+
updateAgentActivity,
|
|
7
|
+
} from "../agent-activity.ts";
|
|
8
|
+
|
|
9
|
+
describe("agent activity", () => {
|
|
10
|
+
it("starts with an explicit startup status", () => {
|
|
11
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
12
|
+
|
|
13
|
+
expect(formatAgentActivityTitle(tracker.activity, 4_000)).toBe("正在启动 Agent · 3秒");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("keeps the thinking timer stable across repeated thinking blocks", () => {
|
|
17
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
18
|
+
|
|
19
|
+
expect(updateAgentActivity(tracker, { type: "thinking", thinking: "first" }, 2_000)).toBe(true);
|
|
20
|
+
expect(updateAgentActivity(tracker, { type: "thinking", thinking: "second" }, 5_000)).toBe(false);
|
|
21
|
+
expect(formatAgentActivityTitle(tracker.activity, 8_000)).toBe("思考中 · 6秒");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("shows the active tool name and elapsed time", () => {
|
|
25
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
26
|
+
|
|
27
|
+
updateAgentActivity(tracker, {
|
|
28
|
+
type: "tool_use",
|
|
29
|
+
id: "tool-1",
|
|
30
|
+
name: "Bash",
|
|
31
|
+
input: { command: "npm test" },
|
|
32
|
+
}, 3_000);
|
|
33
|
+
|
|
34
|
+
expect(formatAgentActivityTitle(tracker.activity, 38_000)).toBe("正在执行 Bash · 35秒");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("tracks parallel tools and keeps the remaining tool after one result", () => {
|
|
38
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
39
|
+
|
|
40
|
+
updateAgentActivity(tracker, { type: "tool_use", id: "read", name: "Read", input: {} }, 2_000);
|
|
41
|
+
updateAgentActivity(tracker, { type: "tool_use", id: "grep", name: "Grep", input: {} }, 3_000);
|
|
42
|
+
expect(formatAgentActivityTitle(tracker.activity, 4_000)).toBe("正在执行 Read 等 2 项 · 2秒");
|
|
43
|
+
|
|
44
|
+
updateAgentActivity(tracker, {
|
|
45
|
+
type: "tool_result",
|
|
46
|
+
tool_use_id: "read",
|
|
47
|
+
content: "done",
|
|
48
|
+
}, 5_000);
|
|
49
|
+
expect(formatAgentActivityTitle(tracker.activity, 7_000)).toBe("正在执行 Grep · 4秒");
|
|
50
|
+
|
|
51
|
+
updateAgentActivity(tracker, {
|
|
52
|
+
type: "tool_result",
|
|
53
|
+
tool_use_id: "grep",
|
|
54
|
+
content: "done",
|
|
55
|
+
}, 8_000);
|
|
56
|
+
expect(formatAgentActivityTitle(tracker.activity, 10_000)).toBe("正在处理工具结果 · 2秒");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("switches to response and context-compaction statuses", () => {
|
|
60
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
61
|
+
|
|
62
|
+
updateAgentActivity(tracker, { type: "text", text: "answer" }, 2_000);
|
|
63
|
+
expect(formatAgentActivityTitle(tracker.activity, 3_000)).toBe("正在生成回复 · 1秒");
|
|
64
|
+
|
|
65
|
+
updateAgentActivity(tracker, {
|
|
66
|
+
type: "compact_boundary",
|
|
67
|
+
trigger: "auto",
|
|
68
|
+
pre_tokens: 100_000,
|
|
69
|
+
}, 4_000);
|
|
70
|
+
expect(formatAgentActivityTitle(tracker.activity, 5_000)).toBe("正在整理上下文 · 1秒");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("uses explicit DeepCCC phase events before text is emitted", () => {
|
|
74
|
+
const tracker = createAgentActivityTracker(1_000);
|
|
75
|
+
|
|
76
|
+
expect(updateAgentActivity(tracker, { type: "agent_status", status: "compacting" }, 2_000)).toBe(true);
|
|
77
|
+
expect(tracker.activity).toEqual({ kind: "compacting", startedAt: 2_000 });
|
|
78
|
+
|
|
79
|
+
expect(updateAgentActivity(tracker, { type: "agent_status", status: "responding" }, 5_000)).toBe(true);
|
|
80
|
+
expect(tracker.activity).toEqual({ kind: "responding", startedAt: 5_000 });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("formats longer elapsed time without decorative animation", () => {
|
|
84
|
+
expect(formatAgentActivityTitle({ kind: "thinking", startedAt: 1_000 }, 74_000)).toBe("思考中 · 1分13秒");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { Readable } from "node:stream";
|
|
2
|
-
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
3
|
-
|
|
4
|
-
import type { PlatformAdapter } from "../platform-adapter.ts";
|
|
5
|
-
|
|
6
|
-
const mockDelegateAgentTask = vi.hoisted(() => vi.fn());
|
|
7
|
-
|
|
8
|
-
vi.mock("../agent-delegate-task.ts", () => ({
|
|
9
|
-
delegateAgentTask: mockDelegateAgentTask,
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
AGENT_DELEGATE_TASK_PATH,
|
|
14
|
-
buildAgentDelegateTaskCapabilityPrompt,
|
|
15
|
-
handleAgentDelegateTaskRequest,
|
|
16
|
-
} from "../agent-delegate-task-rpc.ts";
|
|
17
|
-
import { ABD_APPEND_PROMPT } from "../shared-prefix.ts";
|
|
18
|
-
|
|
19
|
-
function request(body: unknown, path = AGENT_DELEGATE_TASK_PATH, method = "POST"): Readable & {
|
|
20
|
-
url?: string;
|
|
21
|
-
method?: string;
|
|
22
|
-
headers: Record<string, string>;
|
|
23
|
-
} {
|
|
24
|
-
const req = Readable.from([Buffer.from(JSON.stringify(body), "utf8")]) as Readable & {
|
|
25
|
-
url?: string;
|
|
26
|
-
method?: string;
|
|
27
|
-
headers: Record<string, string>;
|
|
28
|
-
};
|
|
29
|
-
req.url = path;
|
|
30
|
-
req.method = method;
|
|
31
|
-
req.headers = { "content-type": "application/json; charset=utf-8" };
|
|
32
|
-
return req;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function response() {
|
|
36
|
-
const res = {
|
|
37
|
-
statusCode: 0,
|
|
38
|
-
headers: {} as Record<string, string>,
|
|
39
|
-
body: "",
|
|
40
|
-
writeHead(status: number, headers: Record<string, string>) {
|
|
41
|
-
this.statusCode = status;
|
|
42
|
-
this.headers = headers;
|
|
43
|
-
return this;
|
|
44
|
-
},
|
|
45
|
-
end(chunk?: string) {
|
|
46
|
-
this.body += chunk ?? "";
|
|
47
|
-
return this;
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
return res;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function platform(kind: "feishu" | "wechat" = "feishu"): PlatformAdapter {
|
|
54
|
-
return {
|
|
55
|
-
kind,
|
|
56
|
-
sendText: vi.fn(async () => true),
|
|
57
|
-
sendCard: vi.fn(async () => true),
|
|
58
|
-
sendRawCard: vi.fn(async () => true),
|
|
59
|
-
createGroup: vi.fn(async () => "chat-id"),
|
|
60
|
-
updateChatInfo: vi.fn(async () => {}),
|
|
61
|
-
getChatInfo: vi.fn(async () => ({ name: "chat", description: "" })),
|
|
62
|
-
disbandChat: vi.fn(async () => {}),
|
|
63
|
-
setChatAvatar: vi.fn(async () => {}),
|
|
64
|
-
extractSessionInfo: vi.fn(() => null),
|
|
65
|
-
cardCreate: vi.fn(async () => "card-id"),
|
|
66
|
-
cardSend: vi.fn(async () => "message-id"),
|
|
67
|
-
cardUpdate: vi.fn(async () => {}),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe("agent delegate task RPC", () => {
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
mockDelegateAgentTask.mockReset();
|
|
74
|
-
mockDelegateAgentTask.mockResolvedValue({
|
|
75
|
-
chatId: "chat-new",
|
|
76
|
-
sessionId: "sid-new",
|
|
77
|
-
tool: "codex",
|
|
78
|
-
cwd: "F:\\repo",
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("delegates a task through the local API", async () => {
|
|
83
|
-
const req = request({
|
|
84
|
-
tool: "codex",
|
|
85
|
-
cwd: "F:\\repo",
|
|
86
|
-
open_id: "ou-user",
|
|
87
|
-
prompt: "帮我分析日志",
|
|
88
|
-
});
|
|
89
|
-
const res = response();
|
|
90
|
-
|
|
91
|
-
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
92
|
-
|
|
93
|
-
expect(res.statusCode).toBe(200);
|
|
94
|
-
expect(JSON.parse(res.body)).toMatchObject({
|
|
95
|
-
ok: true,
|
|
96
|
-
chat_id: "chat-new",
|
|
97
|
-
session_id: "sid-new",
|
|
98
|
-
tool: "codex",
|
|
99
|
-
});
|
|
100
|
-
expect(mockDelegateAgentTask).toHaveBeenCalledWith(expect.objectContaining({
|
|
101
|
-
tool: "codex",
|
|
102
|
-
cwd: expect.stringContaining("repo"),
|
|
103
|
-
promptText: "帮我分析日志",
|
|
104
|
-
openIds: ["ou-user"],
|
|
105
|
-
chatNamePrefix: "帮我分析日志",
|
|
106
|
-
}));
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("applies the shared ABD prefix to API prompts", async () => {
|
|
110
|
-
const req = request({
|
|
111
|
-
tool: "claude",
|
|
112
|
-
cwd: "F:\\repo",
|
|
113
|
-
openIds: ["ou-user"],
|
|
114
|
-
prompt: "/abd帮我分析",
|
|
115
|
-
});
|
|
116
|
-
const res = response();
|
|
117
|
-
|
|
118
|
-
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
119
|
-
|
|
120
|
-
expect(res.statusCode).toBe(200);
|
|
121
|
-
expect(mockDelegateAgentTask).toHaveBeenCalledWith(expect.objectContaining({
|
|
122
|
-
promptText: `帮我分析\n\n---\n${ABD_APPEND_PROMPT}`,
|
|
123
|
-
chatNamePrefix: "帮我分析",
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("rejects non-Feishu platforms", async () => {
|
|
128
|
-
const req = request({
|
|
129
|
-
tool: "codex",
|
|
130
|
-
cwd: "F:\\repo",
|
|
131
|
-
open_id: "ou-user",
|
|
132
|
-
prompt: "task",
|
|
133
|
-
});
|
|
134
|
-
const res = response();
|
|
135
|
-
|
|
136
|
-
await handleAgentDelegateTaskRequest(req as never, res as never, platform("wechat"));
|
|
137
|
-
|
|
138
|
-
expect(res.statusCode).toBe(409);
|
|
139
|
-
expect(mockDelegateAgentTask).not.toHaveBeenCalled();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("rejects missing required parameters", async () => {
|
|
143
|
-
const req = request({ tool: "codex", cwd: "F:\\repo", prompt: "task" });
|
|
144
|
-
const res = response();
|
|
145
|
-
|
|
146
|
-
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
147
|
-
|
|
148
|
-
expect(res.statusCode).toBe(400);
|
|
149
|
-
expect(JSON.parse(res.body).error).toContain("open_id");
|
|
150
|
-
expect(mockDelegateAgentTask).not.toHaveBeenCalled();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("builds prompt instructions for the delegate endpoint", () => {
|
|
154
|
-
const prompt = buildAgentDelegateTaskCapabilityPrompt({
|
|
155
|
-
url: `http://127.0.0.1:18080${AGENT_DELEGATE_TASK_PATH}`,
|
|
156
|
-
cwd: "F:/repo",
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(prompt).toContain("POST http://127.0.0.1:18080/api/agent/delegate-task");
|
|
160
|
-
expect(prompt).toContain('"tool":"codex|claude|cursor"');
|
|
161
|
-
expect(prompt).toContain('"cwd":"absolute working directory"');
|
|
162
|
-
expect(prompt).toContain("project prompt injection and IM skills still apply");
|
|
163
|
-
expect(prompt).toContain("Current working directory: F:/repo");
|
|
164
|
-
});
|
|
165
|
-
});
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
3
|
+
|
|
4
|
+
import type { PlatformAdapter } from "../platform-adapter.ts";
|
|
5
|
+
|
|
6
|
+
const mockDelegateAgentTask = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock("../agent-delegate-task.ts", () => ({
|
|
9
|
+
delegateAgentTask: mockDelegateAgentTask,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
AGENT_DELEGATE_TASK_PATH,
|
|
14
|
+
buildAgentDelegateTaskCapabilityPrompt,
|
|
15
|
+
handleAgentDelegateTaskRequest,
|
|
16
|
+
} from "../agent-delegate-task-rpc.ts";
|
|
17
|
+
import { ABD_APPEND_PROMPT } from "../shared-prefix.ts";
|
|
18
|
+
|
|
19
|
+
function request(body: unknown, path = AGENT_DELEGATE_TASK_PATH, method = "POST"): Readable & {
|
|
20
|
+
url?: string;
|
|
21
|
+
method?: string;
|
|
22
|
+
headers: Record<string, string>;
|
|
23
|
+
} {
|
|
24
|
+
const req = Readable.from([Buffer.from(JSON.stringify(body), "utf8")]) as Readable & {
|
|
25
|
+
url?: string;
|
|
26
|
+
method?: string;
|
|
27
|
+
headers: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
req.url = path;
|
|
30
|
+
req.method = method;
|
|
31
|
+
req.headers = { "content-type": "application/json; charset=utf-8" };
|
|
32
|
+
return req;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function response() {
|
|
36
|
+
const res = {
|
|
37
|
+
statusCode: 0,
|
|
38
|
+
headers: {} as Record<string, string>,
|
|
39
|
+
body: "",
|
|
40
|
+
writeHead(status: number, headers: Record<string, string>) {
|
|
41
|
+
this.statusCode = status;
|
|
42
|
+
this.headers = headers;
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
end(chunk?: string) {
|
|
46
|
+
this.body += chunk ?? "";
|
|
47
|
+
return this;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function platform(kind: "feishu" | "wechat" = "feishu"): PlatformAdapter {
|
|
54
|
+
return {
|
|
55
|
+
kind,
|
|
56
|
+
sendText: vi.fn(async () => true),
|
|
57
|
+
sendCard: vi.fn(async () => true),
|
|
58
|
+
sendRawCard: vi.fn(async () => true),
|
|
59
|
+
createGroup: vi.fn(async () => "chat-id"),
|
|
60
|
+
updateChatInfo: vi.fn(async () => {}),
|
|
61
|
+
getChatInfo: vi.fn(async () => ({ name: "chat", description: "" })),
|
|
62
|
+
disbandChat: vi.fn(async () => {}),
|
|
63
|
+
setChatAvatar: vi.fn(async () => {}),
|
|
64
|
+
extractSessionInfo: vi.fn(() => null),
|
|
65
|
+
cardCreate: vi.fn(async () => "card-id"),
|
|
66
|
+
cardSend: vi.fn(async () => "message-id"),
|
|
67
|
+
cardUpdate: vi.fn(async () => {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("agent delegate task RPC", () => {
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
mockDelegateAgentTask.mockReset();
|
|
74
|
+
mockDelegateAgentTask.mockResolvedValue({
|
|
75
|
+
chatId: "chat-new",
|
|
76
|
+
sessionId: "sid-new",
|
|
77
|
+
tool: "codex",
|
|
78
|
+
cwd: "F:\\repo",
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("delegates a task through the local API", async () => {
|
|
83
|
+
const req = request({
|
|
84
|
+
tool: "codex",
|
|
85
|
+
cwd: "F:\\repo",
|
|
86
|
+
open_id: "ou-user",
|
|
87
|
+
prompt: "帮我分析日志",
|
|
88
|
+
});
|
|
89
|
+
const res = response();
|
|
90
|
+
|
|
91
|
+
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
92
|
+
|
|
93
|
+
expect(res.statusCode).toBe(200);
|
|
94
|
+
expect(JSON.parse(res.body)).toMatchObject({
|
|
95
|
+
ok: true,
|
|
96
|
+
chat_id: "chat-new",
|
|
97
|
+
session_id: "sid-new",
|
|
98
|
+
tool: "codex",
|
|
99
|
+
});
|
|
100
|
+
expect(mockDelegateAgentTask).toHaveBeenCalledWith(expect.objectContaining({
|
|
101
|
+
tool: "codex",
|
|
102
|
+
cwd: expect.stringContaining("repo"),
|
|
103
|
+
promptText: "帮我分析日志",
|
|
104
|
+
openIds: ["ou-user"],
|
|
105
|
+
chatNamePrefix: "帮我分析日志",
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("applies the shared ABD prefix to API prompts", async () => {
|
|
110
|
+
const req = request({
|
|
111
|
+
tool: "claude",
|
|
112
|
+
cwd: "F:\\repo",
|
|
113
|
+
openIds: ["ou-user"],
|
|
114
|
+
prompt: "/abd帮我分析",
|
|
115
|
+
});
|
|
116
|
+
const res = response();
|
|
117
|
+
|
|
118
|
+
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
119
|
+
|
|
120
|
+
expect(res.statusCode).toBe(200);
|
|
121
|
+
expect(mockDelegateAgentTask).toHaveBeenCalledWith(expect.objectContaining({
|
|
122
|
+
promptText: `帮我分析\n\n---\n${ABD_APPEND_PROMPT}`,
|
|
123
|
+
chatNamePrefix: "帮我分析",
|
|
124
|
+
}));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("rejects non-Feishu platforms", async () => {
|
|
128
|
+
const req = request({
|
|
129
|
+
tool: "codex",
|
|
130
|
+
cwd: "F:\\repo",
|
|
131
|
+
open_id: "ou-user",
|
|
132
|
+
prompt: "task",
|
|
133
|
+
});
|
|
134
|
+
const res = response();
|
|
135
|
+
|
|
136
|
+
await handleAgentDelegateTaskRequest(req as never, res as never, platform("wechat"));
|
|
137
|
+
|
|
138
|
+
expect(res.statusCode).toBe(409);
|
|
139
|
+
expect(mockDelegateAgentTask).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("rejects missing required parameters", async () => {
|
|
143
|
+
const req = request({ tool: "codex", cwd: "F:\\repo", prompt: "task" });
|
|
144
|
+
const res = response();
|
|
145
|
+
|
|
146
|
+
await handleAgentDelegateTaskRequest(req as never, res as never, platform());
|
|
147
|
+
|
|
148
|
+
expect(res.statusCode).toBe(400);
|
|
149
|
+
expect(JSON.parse(res.body).error).toContain("open_id");
|
|
150
|
+
expect(mockDelegateAgentTask).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("builds prompt instructions for the delegate endpoint", () => {
|
|
154
|
+
const prompt = buildAgentDelegateTaskCapabilityPrompt({
|
|
155
|
+
url: `http://127.0.0.1:18080${AGENT_DELEGATE_TASK_PATH}`,
|
|
156
|
+
cwd: "F:/repo",
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(prompt).toContain("POST http://127.0.0.1:18080/api/agent/delegate-task");
|
|
160
|
+
expect(prompt).toContain('"tool":"codex|claude|cursor"');
|
|
161
|
+
expect(prompt).toContain('"cwd":"absolute working directory"');
|
|
162
|
+
expect(prompt).toContain("project prompt injection and IM skills still apply");
|
|
163
|
+
expect(prompt).toContain("Current working directory: F:/repo");
|
|
164
|
+
});
|
|
165
|
+
});
|