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.
Files changed (296) hide show
  1. package/README.md +10 -1
  2. package/bin/cccagent.mjs +12 -3
  3. package/bin/chatccc.mjs +15 -6
  4. package/config.sample.json +2 -1
  5. package/deepccc-agent/README.md +40 -35
  6. package/deepccc-agent/os-prompts/darwin.md +8 -8
  7. package/deepccc-agent/os-prompts/linux.md +8 -8
  8. package/deepccc-agent/os-prompts/win32.md +11 -11
  9. package/deepccc-agent/package.json +65 -65
  10. package/dist/deepccc-agent/src/cli.js +634 -0
  11. package/dist/deepccc-agent/src/config.js +81 -0
  12. package/dist/deepccc-agent/src/context.js +348 -0
  13. package/dist/deepccc-agent/src/file-log.js +34 -0
  14. package/dist/deepccc-agent/src/file-tools.js +1208 -0
  15. package/dist/deepccc-agent/src/index.js +601 -0
  16. package/dist/deepccc-agent/src/permissions.js +170 -0
  17. package/dist/deepccc-agent/src/privacy.js +124 -0
  18. package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
  19. package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
  20. package/dist/deepccc-agent/src/progress/reducer.js +102 -0
  21. package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
  22. package/dist/deepccc-agent/src/progress/view.js +30 -0
  23. package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
  24. package/dist/deepccc-agent/src/session-search.js +276 -0
  25. package/dist/deepccc-agent/src/session-select.js +23 -0
  26. package/dist/deepccc-agent/src/sigint.js +26 -0
  27. package/dist/deepccc-agent/src/skills.js +178 -0
  28. package/dist/deepccc-agent/src/web-tools.js +246 -0
  29. package/dist/src/adapters/adapter-interface.js +19 -0
  30. package/dist/src/adapters/ccc-adapter.js +112 -0
  31. package/dist/src/adapters/claude-adapter.js +497 -0
  32. package/dist/src/adapters/claude-session-meta-store.js +92 -0
  33. package/dist/src/adapters/codex-adapter.js +279 -0
  34. package/dist/src/adapters/codex-session-meta-store.js +94 -0
  35. package/dist/src/adapters/cursor-adapter.js +491 -0
  36. package/dist/src/adapters/cursor-session-meta-store.js +116 -0
  37. package/dist/src/adapters/jsonl-stream.js +104 -0
  38. package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
  39. package/dist/src/adapters/raw-stream-log.js +106 -0
  40. package/dist/src/adapters/resource-monitor.js +113 -0
  41. package/dist/src/agent-activity.js +133 -0
  42. package/dist/src/agent-delegate-task-rpc.js +129 -0
  43. package/dist/src/agent-delegate-task.js +48 -0
  44. package/dist/src/agent-file-rpc.js +152 -0
  45. package/dist/src/agent-image-rpc.js +148 -0
  46. package/dist/src/agent-platform-routing.js +13 -0
  47. package/dist/src/agent-reload-config-rpc.js +23 -0
  48. package/dist/src/agent-rpc-body.js +87 -0
  49. package/dist/src/agent-stop-stuck.js +110 -0
  50. package/dist/src/agent-team/application/board-service.js +142 -0
  51. package/dist/src/agent-team/application/main-agent-service.js +151 -0
  52. package/dist/src/agent-team/domain/board.js +69 -0
  53. package/dist/src/agent-team/http/board-routes.js +213 -0
  54. package/dist/src/agent-team/infrastructure/filesystem-browser.js +112 -0
  55. package/dist/src/agent-team/infrastructure/main-agent-session-runtime.js +30 -0
  56. package/dist/src/agent-team/main-agent-bootstrap.js +15 -0
  57. package/dist/src/agent-team/repositories/board-repository.js +10 -0
  58. package/dist/src/agent-team/repositories/feishu-p2p-contact-store.js +64 -0
  59. package/dist/src/agent-team/repositories/json-board-repository.js +209 -0
  60. package/dist/src/agent-team/repositories/main-agent-binding-repository.js +84 -0
  61. package/dist/src/agent-team/sync/board-sync-adapter.js +1 -0
  62. package/dist/src/agent-team/web/agent-team-page.js +219 -0
  63. package/dist/src/agent-tool.js +10 -0
  64. package/dist/src/card-action-routing.js +7 -0
  65. package/dist/src/card-plain-text.js +101 -0
  66. package/dist/src/cardkit.js +158 -0
  67. package/dist/src/cards.js +573 -0
  68. package/dist/src/chatgpt-subscription-rpc.js +18 -0
  69. package/dist/src/chatgpt-subscription.js +199 -0
  70. package/dist/src/chrome-devtools-guard.js +238 -0
  71. package/dist/src/claude-sdk-installer.js +249 -0
  72. package/dist/src/codex-reset-actions.js +143 -0
  73. package/dist/src/config-utils.js +149 -0
  74. package/dist/src/config.js +808 -0
  75. package/dist/src/cursor-usage.js +77 -0
  76. package/dist/src/exit-banner.js +28 -0
  77. package/dist/src/feishu-api.js +1404 -0
  78. package/dist/src/feishu-message-ingress.js +137 -0
  79. package/dist/src/feishu-platform.js +97 -0
  80. package/dist/src/format-message.js +252 -0
  81. package/dist/src/git-command.js +155 -0
  82. package/dist/src/im-skills.js +121 -0
  83. package/dist/src/index.js +835 -0
  84. package/dist/src/litellm-proxy.js +300 -0
  85. package/dist/src/orchestrator.js +2096 -0
  86. package/dist/src/package-root.js +26 -0
  87. package/dist/src/platform-adapter.js +7 -0
  88. package/dist/src/platform-startup.js +6 -0
  89. package/dist/src/privacy.js +100 -0
  90. package/dist/src/progress/reducer.js +102 -0
  91. package/dist/src/progress/terminal-renderer.js +264 -0
  92. package/dist/src/progress/view.js +30 -0
  93. package/dist/src/response-stall.js +14 -0
  94. package/dist/src/runtime-entry.js +13 -0
  95. package/dist/src/runtime-reload.js +19 -0
  96. package/dist/src/session-chat-binding.js +183 -0
  97. package/dist/src/session-name.js +7 -0
  98. package/dist/src/session.js +2147 -0
  99. package/dist/src/shared-prefix.js +16 -0
  100. package/dist/src/shared.js +493 -0
  101. package/dist/src/sim-agent.js +105 -0
  102. package/dist/src/sim-platform.js +142 -0
  103. package/dist/src/sim-store.js +231 -0
  104. package/dist/src/simplify.js +99 -0
  105. package/dist/src/startup-lifecycle.js +209 -0
  106. package/dist/src/stream-state.js +141 -0
  107. package/dist/src/terminal-error.js +100 -0
  108. package/dist/src/trace.js +50 -0
  109. package/dist/src/turn-cards.js +92 -0
  110. package/dist/src/update-command-guard.js +114 -0
  111. package/{src/web-ui.ts → dist/src/web-ui.js} +753 -839
  112. package/dist/src/wechat-platform.js +545 -0
  113. package/package.json +76 -74
  114. package/deepccc-agent/LICENSE +0 -201
  115. package/deepccc-agent/bin/deepccc.mjs +0 -26
  116. package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
  117. package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
  118. package/deepccc-agent/package-lock.json +0 -2027
  119. package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
  120. package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
  121. package/deepccc-agent/src/__tests__/config.test.ts +0 -34
  122. package/deepccc-agent/src/__tests__/context.test.ts +0 -341
  123. package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
  124. package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
  125. package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
  126. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
  127. package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
  128. package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
  129. package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
  130. package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
  131. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
  132. package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
  133. package/deepccc-agent/src/cli.ts +0 -682
  134. package/deepccc-agent/src/config.ts +0 -101
  135. package/deepccc-agent/src/context.ts +0 -465
  136. package/deepccc-agent/src/file-log.ts +0 -38
  137. package/deepccc-agent/src/file-tools.ts +0 -1493
  138. package/deepccc-agent/src/index.ts +0 -710
  139. package/deepccc-agent/src/permissions.ts +0 -226
  140. package/deepccc-agent/src/privacy.ts +0 -141
  141. package/deepccc-agent/src/proc-tree-kill.ts +0 -61
  142. package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
  143. package/deepccc-agent/src/progress/reducer.ts +0 -113
  144. package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
  145. package/deepccc-agent/src/progress/view.ts +0 -77
  146. package/deepccc-agent/src/raw-stream-log.ts +0 -124
  147. package/deepccc-agent/src/session-search.ts +0 -370
  148. package/deepccc-agent/src/session-select.ts +0 -48
  149. package/deepccc-agent/src/sigint.ts +0 -50
  150. package/deepccc-agent/src/skills.ts +0 -205
  151. package/deepccc-agent/src/web-tools.ts +0 -313
  152. package/deepccc-agent/tsconfig.build.json +0 -13
  153. package/deepccc-agent/tsconfig.json +0 -13
  154. package/deepccc-agent/vitest.config.ts +0 -7
  155. package/src/__tests__/adapter-interface.test.ts +0 -152
  156. package/src/__tests__/agent-activity.test.ts +0 -86
  157. package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
  158. package/src/__tests__/agent-image-rpc.test.ts +0 -34
  159. package/src/__tests__/agent-platform-routing.test.ts +0 -26
  160. package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
  161. package/src/__tests__/agent-rpc-body.test.ts +0 -42
  162. package/src/__tests__/builtin-chat-session.test.ts +0 -532
  163. package/src/__tests__/builtin-cli-json.test.ts +0 -39
  164. package/src/__tests__/builtin-config.test.ts +0 -26
  165. package/src/__tests__/builtin-context.test.ts +0 -319
  166. package/src/__tests__/builtin-file-tools.test.ts +0 -240
  167. package/src/__tests__/builtin-permissions.test.ts +0 -219
  168. package/src/__tests__/builtin-session-search.test.ts +0 -262
  169. package/src/__tests__/builtin-session-select.test.ts +0 -116
  170. package/src/__tests__/builtin-sigint.test.ts +0 -56
  171. package/src/__tests__/builtin-skills.test.ts +0 -284
  172. package/src/__tests__/builtin-web-tools.test.ts +0 -220
  173. package/src/__tests__/card-action-routing.test.ts +0 -18
  174. package/src/__tests__/card-plain-text.test.ts +0 -45
  175. package/src/__tests__/cardkit.test.ts +0 -60
  176. package/src/__tests__/cards.test.ts +0 -607
  177. package/src/__tests__/ccc-adapter.test.ts +0 -194
  178. package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
  179. package/src/__tests__/chatgpt-subscription.test.ts +0 -135
  180. package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
  181. package/src/__tests__/claude-adapter.test.ts +0 -614
  182. package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
  183. package/src/__tests__/claude-sdk-installer.test.ts +0 -285
  184. package/src/__tests__/codex-adapter.test.ts +0 -331
  185. package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
  186. package/src/__tests__/codex-reset-actions.test.ts +0 -146
  187. package/src/__tests__/config-reload.test.ts +0 -284
  188. package/src/__tests__/config-sample.test.ts +0 -97
  189. package/src/__tests__/config-utils.test.ts +0 -40
  190. package/src/__tests__/config.test.ts +0 -395
  191. package/src/__tests__/crash-logging.test.ts +0 -360
  192. package/src/__tests__/cursor-adapter.test.ts +0 -890
  193. package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
  194. package/src/__tests__/feishu-api.test.ts +0 -60
  195. package/src/__tests__/feishu-avatar.test.ts +0 -504
  196. package/src/__tests__/feishu-message-ingress.test.ts +0 -138
  197. package/src/__tests__/feishu-platform.test.ts +0 -75
  198. package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
  199. package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
  200. package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
  201. package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
  202. package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
  203. package/src/__tests__/format-message.test.ts +0 -316
  204. package/src/__tests__/git-command.test.ts +0 -288
  205. package/src/__tests__/im-skills.test.ts +0 -125
  206. package/src/__tests__/jsonl-stream.test.ts +0 -79
  207. package/src/__tests__/orchestrator.test.ts +0 -1268
  208. package/src/__tests__/package-files.test.ts +0 -24
  209. package/src/__tests__/platform-startup.test.ts +0 -19
  210. package/src/__tests__/privacy.test.ts +0 -198
  211. package/src/__tests__/proc-tree-kill.test.ts +0 -108
  212. package/src/__tests__/progress-reducer.test.ts +0 -121
  213. package/src/__tests__/raw-stream-log.test.ts +0 -106
  214. package/src/__tests__/response-stall.test.ts +0 -49
  215. package/src/__tests__/restart.test.ts +0 -232
  216. package/src/__tests__/session-ccc-config.test.ts +0 -66
  217. package/src/__tests__/session.test.ts +0 -3004
  218. package/src/__tests__/shared-prefix.test.ts +0 -36
  219. package/src/__tests__/sim-agent.test.ts +0 -174
  220. package/src/__tests__/sim-platform.test.ts +0 -93
  221. package/src/__tests__/sim-store.test.ts +0 -214
  222. package/src/__tests__/simplify.test.ts +0 -283
  223. package/src/__tests__/startup-lifecycle.test.ts +0 -231
  224. package/src/__tests__/stop-session.test.ts +0 -162
  225. package/src/__tests__/stream-state.test.ts +0 -164
  226. package/src/__tests__/terminal-error.test.ts +0 -54
  227. package/src/__tests__/terminal-renderer.test.ts +0 -247
  228. package/src/__tests__/update-command-guard.test.ts +0 -144
  229. package/src/__tests__/web-ui.test.ts +0 -438
  230. package/src/__tests__/wechat-platform.test.ts +0 -111
  231. package/src/adapters/adapter-interface.ts +0 -217
  232. package/src/adapters/ccc-adapter.ts +0 -150
  233. package/src/adapters/claude-adapter.ts +0 -673
  234. package/src/adapters/claude-session-meta-store.ts +0 -120
  235. package/src/adapters/codex-adapter.ts +0 -426
  236. package/src/adapters/codex-session-meta-store.ts +0 -131
  237. package/src/adapters/cursor-adapter.ts +0 -681
  238. package/src/adapters/cursor-session-meta-store.ts +0 -154
  239. package/src/adapters/jsonl-stream.ts +0 -157
  240. package/src/adapters/raw-stream-log.ts +0 -124
  241. package/src/adapters/resource-monitor.ts +0 -141
  242. package/src/agent-activity.ts +0 -175
  243. package/src/agent-delegate-task-rpc.ts +0 -153
  244. package/src/agent-delegate-task.ts +0 -91
  245. package/src/agent-file-rpc.ts +0 -172
  246. package/src/agent-image-rpc.ts +0 -168
  247. package/src/agent-platform-routing.ts +0 -28
  248. package/src/agent-reload-config-rpc.ts +0 -34
  249. package/src/agent-rpc-body.ts +0 -92
  250. package/src/agent-stop-stuck.ts +0 -129
  251. package/src/card-action-routing.ts +0 -14
  252. package/src/card-plain-text.ts +0 -108
  253. package/src/cardkit.ts +0 -179
  254. package/src/cards.ts +0 -684
  255. package/src/chatgpt-subscription-rpc.ts +0 -27
  256. package/src/chatgpt-subscription.ts +0 -299
  257. package/src/chrome-devtools-guard.ts +0 -318
  258. package/src/claude-sdk-installer.ts +0 -324
  259. package/src/codex-reset-actions.ts +0 -184
  260. package/src/config-utils.ts +0 -211
  261. package/src/config.ts +0 -1063
  262. package/src/cursor-usage.ts +0 -128
  263. package/src/exit-banner.ts +0 -33
  264. package/src/feishu-api.ts +0 -1616
  265. package/src/feishu-message-ingress.ts +0 -195
  266. package/src/feishu-platform.ts +0 -159
  267. package/src/format-message.ts +0 -293
  268. package/src/git-command.ts +0 -202
  269. package/src/im-skills.ts +0 -149
  270. package/src/index.ts +0 -1089
  271. package/src/litellm-proxy.ts +0 -374
  272. package/src/orchestrator.ts +0 -2543
  273. package/src/platform-adapter.ts +0 -70
  274. package/src/platform-startup.ts +0 -16
  275. package/src/privacy.ts +0 -118
  276. package/src/progress/reducer.ts +0 -113
  277. package/src/progress/terminal-renderer.ts +0 -294
  278. package/src/progress/view.ts +0 -77
  279. package/src/response-stall.ts +0 -28
  280. package/src/runtime-reload.ts +0 -34
  281. package/src/session-chat-binding.ts +0 -292
  282. package/src/session-name.ts +0 -8
  283. package/src/session.ts +0 -2659
  284. package/src/shared-prefix.ts +0 -29
  285. package/src/shared.ts +0 -552
  286. package/src/sim-agent.ts +0 -167
  287. package/src/sim-platform.ts +0 -177
  288. package/src/sim-store.ts +0 -317
  289. package/src/simplify.ts +0 -120
  290. package/src/startup-lifecycle.ts +0 -250
  291. package/src/stream-state.ts +0 -177
  292. package/src/terminal-error.ts +0 -129
  293. package/src/trace.ts +0 -51
  294. package/src/turn-cards.ts +0 -118
  295. package/src/update-command-guard.ts +0 -165
  296. package/src/wechat-platform.ts +0 -680
@@ -1,288 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { EventEmitter } from "node:events";
3
- import { Readable } from "node:stream";
4
- import { mkdtemp, rm } from "node:fs/promises";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
-
8
- import {
9
- runGitCommand,
10
- formatGitResult,
11
- gitResultHeaderTemplate,
12
- type GitCommandResult,
13
- } from "../git-command.ts";
14
-
15
- // ---------------------------------------------------------------------------
16
- // 通过自定义 spawn 桩测试纯逻辑(流处理 / 超时 / 截断 / 退出码)
17
- // ---------------------------------------------------------------------------
18
-
19
- interface StubSpawnOptions {
20
- stdout?: string[];
21
- stderr?: string[];
22
- exitCode?: number | null;
23
- /** 数据推送 / close 事件相对于 spawn 的延迟(ms) */
24
- emitDelayMs?: number;
25
- /** 模拟 spawn 同步抛出(如可执行文件不存在) */
26
- throwOnStart?: Error;
27
- /** 模拟 child.on("error") 异步触发(如 ENOENT) */
28
- emitErrorAfterMs?: number;
29
- emitErrorMessage?: string;
30
- /** 是否永远不结束(用来测超时) */
31
- hang?: boolean;
32
- }
33
-
34
- function makeStubSpawn(opts: StubSpawnOptions): any {
35
- return ((..._args: unknown[]) => {
36
- if (opts.throwOnStart) throw opts.throwOnStart;
37
-
38
- const child = new EventEmitter() as EventEmitter & {
39
- stdout: Readable;
40
- stderr: Readable;
41
- kill: (sig?: string) => void;
42
- };
43
- child.stdout = new Readable({ read() {} });
44
- child.stderr = new Readable({ read() {} });
45
-
46
- let killed = false;
47
- child.kill = (_sig?: string) => {
48
- killed = true;
49
- child.stdout.push(null);
50
- child.stderr.push(null);
51
- setImmediate(() => child.emit("close", null));
52
- };
53
-
54
- const delay = opts.emitDelayMs ?? 5;
55
- setTimeout(() => {
56
- if (killed) return;
57
- for (const c of opts.stdout ?? []) child.stdout.push(Buffer.from(c));
58
- child.stdout.push(null);
59
- for (const c of opts.stderr ?? []) child.stderr.push(Buffer.from(c));
60
- child.stderr.push(null);
61
- if (opts.emitErrorAfterMs !== undefined) {
62
- setTimeout(
63
- () => child.emit("error", new Error(opts.emitErrorMessage ?? "stub error")),
64
- opts.emitErrorAfterMs,
65
- );
66
- }
67
- if (!opts.hang) {
68
- setTimeout(() => {
69
- if (!killed) child.emit("close", opts.exitCode ?? 0);
70
- }, 2);
71
- }
72
- }, delay);
73
-
74
- return child;
75
- }) as any;
76
- }
77
-
78
- describe("runGitCommand (with stub spawn)", () => {
79
- it("collects stdout and reports exit code 0", async () => {
80
- const result = await runGitCommand("status", "/some/dir", {
81
- spawnImpl: makeStubSpawn({ stdout: ["On branch main\n", "nothing to commit\n"], exitCode: 0 }),
82
- });
83
- expect(result.exitCode).toBe(0);
84
- expect(result.stdout).toBe("On branch main\nnothing to commit\n");
85
- expect(result.stderr).toBe("");
86
- expect(result.timedOut).toBe(false);
87
- expect(result.truncated).toBe(false);
88
- expect(result.spawnError).toBeUndefined();
89
- });
90
-
91
- it("collects stderr and non-zero exit code", async () => {
92
- const result = await runGitCommand("notacommand", "/some/dir", {
93
- spawnImpl: makeStubSpawn({
94
- stderr: ["git: 'notacommand' is not a git command\n"],
95
- exitCode: 1,
96
- }),
97
- });
98
- expect(result.exitCode).toBe(1);
99
- expect(result.stdout).toBe("");
100
- expect(result.stderr).toContain("not a git command");
101
- });
102
-
103
- it("truncates stdout when exceeding maxBytes", async () => {
104
- const big = "x".repeat(5000);
105
- const result = await runGitCommand("log", "/some/dir", {
106
- maxBytes: 1024,
107
- spawnImpl: makeStubSpawn({ stdout: [big], exitCode: 0 }),
108
- });
109
- expect(result.truncated).toBe(true);
110
- // 截断后 stdout 长度 ≤ 1024
111
- expect(Buffer.byteLength(result.stdout, "utf-8")).toBeLessThanOrEqual(1024);
112
- });
113
-
114
- it("truncates stderr when exceeding maxBytes", async () => {
115
- const big = "e".repeat(3000);
116
- const result = await runGitCommand("log", "/some/dir", {
117
- maxBytes: 512,
118
- spawnImpl: makeStubSpawn({ stderr: [big], exitCode: 1 }),
119
- });
120
- expect(result.truncated).toBe(true);
121
- expect(Buffer.byteLength(result.stderr, "utf-8")).toBeLessThanOrEqual(512);
122
- });
123
-
124
- it("times out hung command and sets timedOut=true with exitCode=null", async () => {
125
- const result = await runGitCommand("log", "/some/dir", {
126
- timeoutMs: 30,
127
- spawnImpl: makeStubSpawn({ hang: true, stdout: ["partial output\n"] }),
128
- });
129
- expect(result.timedOut).toBe(true);
130
- expect(result.exitCode).toBeNull();
131
- // 超时前已收集的 partial output 应保留
132
- expect(result.stdout).toContain("partial output");
133
- });
134
-
135
- it("captures spawn synchronous throw as spawnError", async () => {
136
- const result = await runGitCommand("status", "/some/dir", {
137
- spawnImpl: makeStubSpawn({ throwOnStart: new Error("ENOENT git") }),
138
- });
139
- expect(result.spawnError).toBe("ENOENT git");
140
- expect(result.exitCode).toBeNull();
141
- });
142
-
143
- it("records durationMs as a non-negative number", async () => {
144
- const result = await runGitCommand("status", "/some/dir", {
145
- spawnImpl: makeStubSpawn({ stdout: ["ok\n"], exitCode: 0, emitDelayMs: 10 }),
146
- });
147
- expect(typeof result.durationMs).toBe("number");
148
- expect(result.durationMs).toBeGreaterThanOrEqual(0);
149
- });
150
- });
151
-
152
- // ---------------------------------------------------------------------------
153
- // formatGitResult —— 渲染逻辑
154
- // ---------------------------------------------------------------------------
155
-
156
- describe("formatGitResult", () => {
157
- const baseResult = (overrides: Partial<GitCommandResult> = {}): GitCommandResult => ({
158
- exitCode: 0,
159
- stdout: "",
160
- stderr: "",
161
- durationMs: 12,
162
- truncated: false,
163
- timedOut: false,
164
- ...overrides,
165
- });
166
-
167
- it("includes the rendered command, cwd and exit code header", () => {
168
- const out = formatGitResult("status", "/repo", baseResult({ stdout: "ok\n" }));
169
- expect(out).toContain("git status");
170
- expect(out).toContain("/repo");
171
- expect(out).toContain("退出码: `0`");
172
- });
173
-
174
- it("renders stdout in a fenced block when present", () => {
175
- const out = formatGitResult("status", "/repo", baseResult({ stdout: "On branch dev" }));
176
- expect(out).toContain("**stdout:**");
177
- expect(out).toContain("On branch dev");
178
- expect(out.match(/```/g)?.length).toBeGreaterThanOrEqual(2);
179
- });
180
-
181
- it("renders stderr block when present", () => {
182
- const out = formatGitResult(
183
- "push",
184
- "/repo",
185
- baseResult({ exitCode: 1, stderr: "fatal: remote rejected" }),
186
- );
187
- expect(out).toContain("**stderr:**");
188
- expect(out).toContain("fatal: remote rejected");
189
- expect(out).toContain("退出码: `1`");
190
- });
191
-
192
- it("hints empty output when both streams are blank", () => {
193
- const out = formatGitResult("status", "/repo", baseResult({ stdout: "", stderr: "" }));
194
- expect(out).toContain("(命令无输出)");
195
- });
196
-
197
- it("annotates timedOut, truncated and spawnError flags", () => {
198
- const out = formatGitResult(
199
- "log",
200
- "/repo",
201
- baseResult({ exitCode: null, timedOut: true, truncated: true, spawnError: "ENOENT" }),
202
- );
203
- expect(out).toContain("超时");
204
- expect(out).toContain("截断");
205
- expect(out).toContain("ENOENT");
206
- expect(out).toContain("退出码: `(无)`");
207
- });
208
-
209
- it("truncates very long stdout via truncateContent", () => {
210
- const long = Array.from({ length: 500 }, (_, i) => `line${i + 1}`).join("\n");
211
- const out = formatGitResult("log", "/repo", baseResult({ stdout: long }), {
212
- maxLines: 5,
213
- maxChars: 1000,
214
- });
215
- expect(out).toContain("...");
216
- // 只保留前 1 行 + "..." + 后 4 行
217
- expect(out).toContain("line1");
218
- expect(out).toContain("line500");
219
- expect(out).not.toContain("line250");
220
- });
221
- });
222
-
223
- // ---------------------------------------------------------------------------
224
- // gitResultHeaderTemplate
225
- // ---------------------------------------------------------------------------
226
-
227
- describe("gitResultHeaderTemplate", () => {
228
- const r = (overrides: Partial<GitCommandResult>): GitCommandResult => ({
229
- exitCode: 0,
230
- stdout: "",
231
- stderr: "",
232
- durationMs: 0,
233
- truncated: false,
234
- timedOut: false,
235
- ...overrides,
236
- });
237
-
238
- it("returns green when exitCode=0", () => {
239
- expect(gitResultHeaderTemplate(r({ exitCode: 0 }))).toBe("green");
240
- });
241
-
242
- it("returns red when exitCode≠0", () => {
243
- expect(gitResultHeaderTemplate(r({ exitCode: 1 }))).toBe("red");
244
- expect(gitResultHeaderTemplate(r({ exitCode: 128 }))).toBe("red");
245
- });
246
-
247
- it("returns yellow when timedOut", () => {
248
- expect(gitResultHeaderTemplate(r({ exitCode: null, timedOut: true }))).toBe("yellow");
249
- });
250
-
251
- it("returns yellow when spawnError set", () => {
252
- expect(gitResultHeaderTemplate(r({ exitCode: null, spawnError: "x" }))).toBe("yellow");
253
- });
254
- });
255
-
256
- // ---------------------------------------------------------------------------
257
- // 集成 smoke test:真正调起 `git --version` 在临时目录
258
- // (前置条件:开发机已安装 git)
259
- // ---------------------------------------------------------------------------
260
-
261
- describe("runGitCommand integration (real git)", () => {
262
- it("`git --version` runs successfully in a tmp dir", async () => {
263
- const dir = await mkdtemp(join(tmpdir(), "chatccc-git-test-"));
264
- try {
265
- const result = await runGitCommand("--version", dir, { timeoutMs: 15_000 });
266
- // git 不在 PATH 时会得到 spawnError 或非 0 退出,这里整体期望成功
267
- expect(result.spawnError).toBeUndefined();
268
- expect(result.exitCode).toBe(0);
269
- expect(result.stdout.toLowerCase()).toContain("git version");
270
- } finally {
271
- await rm(dir, { recursive: true, force: true });
272
- }
273
- });
274
-
275
- it("`git status` outside repo reports non-zero exit code with helpful stderr", async () => {
276
- const dir = await mkdtemp(join(tmpdir(), "chatccc-git-test-"));
277
- try {
278
- const result = await runGitCommand("status", dir, { timeoutMs: 15_000 });
279
- expect(result.spawnError).toBeUndefined();
280
- // not a git repo → exitCode ≠ 0
281
- expect(result.exitCode).not.toBe(0);
282
- const combined = (result.stdout + result.stderr).toLowerCase();
283
- expect(combined).toMatch(/not a git repository|fatal/);
284
- } finally {
285
- await rm(dir, { recursive: true, force: true });
286
- }
287
- });
288
- });
@@ -1,125 +0,0 @@
1
- import { mkdtemp, mkdir, rm, writeFile, readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { tmpdir } from "node:os";
4
- import { afterEach, describe, expect, it } from "vitest";
5
-
6
- import {
7
- buildImSkillsPrompt,
8
- buildImSkillsPromptCached,
9
- clearImSkillsPromptCache,
10
- exportSkillSubDocs,
11
- } from "../im-skills.ts";
12
-
13
- let tempRoot: string | null = null;
14
-
15
- describe("IM skills prompt rendering", () => {
16
- afterEach(async () => {
17
- if (tempRoot) await rm(tempRoot, { recursive: true, force: true });
18
- tempRoot = null;
19
- });
20
-
21
- it("loads skill.md files and renders runtime variables", async () => {
22
- tempRoot = await mkdtemp(join(tmpdir(), "chatccc-im-skills-"));
23
- const skillDir = join(tempRoot, "feishu-skill");
24
- await mkdir(skillDir);
25
- await writeFile(
26
- join(skillDir, "skill.md"),
27
- [
28
- "---",
29
- "name: feishu-skill",
30
- "---",
31
- "GET {{session_grants_url}}?sid={{session_id}}",
32
- "cwd={{cwd}}",
33
- ].join("\n"),
34
- "utf-8",
35
- );
36
-
37
- const prompt = await buildImSkillsPrompt({
38
- skillsDir: tempRoot,
39
- variables: {
40
- cwd: "C:/work",
41
- session_grants_url: "http://127.0.0.1:18080/api/agent/session-grants",
42
- session_id: "sid_test",
43
- },
44
- });
45
-
46
- expect(prompt).toContain("[ChatCCC IM skill: feishu-skill]");
47
- expect(prompt).toContain("GET http://127.0.0.1:18080/api/agent/session-grants?sid=sid_test");
48
- expect(prompt).toContain("cwd=C:/work");
49
- expect(prompt).not.toContain("{{");
50
- });
51
-
52
- it("filters skills by enabledSkillNames", async () => {
53
- tempRoot = await mkdtemp(join(tmpdir(), "chatccc-im-skills-filter-"));
54
- const feishuDir = join(tempRoot, "feishu-skill");
55
- const wechatDir = join(tempRoot, "wechat-skill");
56
- const outDir = join(tempRoot, "out");
57
- await mkdir(feishuDir);
58
- await mkdir(wechatDir);
59
- await writeFile(join(feishuDir, "skill.md"), "Feishu {{cwd}}", "utf-8");
60
- await writeFile(join(feishuDir, "receive-send-image.md"), "Feishu doc", "utf-8");
61
- await writeFile(join(wechatDir, "skill.md"), "WeChat {{cwd}}", "utf-8");
62
- await writeFile(join(wechatDir, "receive-send-image.md"), "WeChat doc", "utf-8");
63
-
64
- const input = {
65
- skillsDir: tempRoot,
66
- enabledSkillNames: ["feishu-skill"],
67
- variables: { cwd: "C:/work" },
68
- };
69
- const prompt = await buildImSkillsPrompt(input);
70
- const exported = await exportSkillSubDocs(input, outDir);
71
-
72
- expect(prompt).toContain("[ChatCCC IM skill: feishu-skill]");
73
- expect(prompt).toContain("Feishu C:/work");
74
- expect(prompt).not.toContain("[ChatCCC IM skill: wechat-skill]");
75
- expect(prompt).not.toContain("WeChat C:/work");
76
- expect(exported).toHaveLength(1);
77
- expect(exported[0]).toContain(join("feishu-skill", "receive-send-image.md"));
78
- await expect(readFile(join(outDir, "feishu-skill", "receive-send-image.md"), "utf8")).resolves.toContain(
79
- "Feishu doc",
80
- );
81
- });
82
-
83
- it("skips filtering when enabledSkillNames is omitted", async () => {
84
- tempRoot = await mkdtemp(join(tmpdir(), "chatccc-im-skills-all-"));
85
- const feishuDir = join(tempRoot, "feishu-skill");
86
- const wechatDir = join(tempRoot, "wechat-skill");
87
- const outDir = join(tempRoot, "out");
88
- await mkdir(feishuDir);
89
- await mkdir(wechatDir);
90
- await writeFile(join(feishuDir, "skill.md"), "Feishu {{cwd}}", "utf-8");
91
- await writeFile(join(feishuDir, "receive-send-image.md"), "Feishu doc", "utf-8");
92
- await writeFile(join(wechatDir, "skill.md"), "WeChat {{cwd}}", "utf-8");
93
- await writeFile(join(wechatDir, "receive-send-image.md"), "WeChat doc", "utf-8");
94
-
95
- const prompt = await buildImSkillsPrompt({
96
- skillsDir: tempRoot,
97
- variables: { cwd: "C:/work" },
98
- });
99
- const exported = await exportSkillSubDocs({ skillsDir: tempRoot, variables: { cwd: "C:/work" } }, outDir);
100
-
101
- expect(prompt).toContain("[ChatCCC IM skill: feishu-skill]");
102
- expect(prompt).toContain("[ChatCCC IM skill: wechat-skill]");
103
- expect(exported.length).toBeGreaterThanOrEqual(2);
104
- });
105
-
106
- it("exports cached prompt helpers used by session startup", async () => {
107
- tempRoot = await mkdtemp(join(tmpdir(), "chatccc-im-skills-cache-"));
108
- const skillDir = join(tempRoot, "feishu-skill");
109
- await mkdir(skillDir);
110
- await writeFile(join(skillDir, "skill.md"), "cwd={{cwd}}", "utf-8");
111
-
112
- const input = {
113
- skillsDir: tempRoot,
114
- variables: { cwd: "C:/first", session_id: "sid_cache" },
115
- };
116
- const first = await buildImSkillsPromptCached(input);
117
- await writeFile(join(skillDir, "skill.md"), "cwd={{cwd}} changed", "utf-8");
118
- const cached = await buildImSkillsPromptCached(input);
119
- clearImSkillsPromptCache("sid_cache");
120
- const refreshed = await buildImSkillsPromptCached(input);
121
-
122
- expect(cached).toBe(first);
123
- expect(refreshed).toContain("changed");
124
- });
125
- });
@@ -1,79 +0,0 @@
1
- import { PassThrough } from "node:stream";
2
-
3
- import { afterEach, describe, expect, it, vi } from "vitest";
4
-
5
- import {
6
- BadJsonIdleTimeoutError,
7
- readJsonLinesWithBadJsonIdleWatchdog,
8
- } from "../adapters/jsonl-stream.ts";
9
-
10
- function createReader(input: PassThrough, idleTimeoutMs = 100): AsyncIterator<unknown> {
11
- return readJsonLinesWithBadJsonIdleWatchdog({
12
- input,
13
- tool: "test-agent",
14
- tag: "sid-test",
15
- idleTimeoutMs,
16
- parse: (line) => JSON.parse(line) as unknown,
17
- })[Symbol.asyncIterator]();
18
- }
19
-
20
- afterEach(() => {
21
- vi.useRealTimers();
22
- });
23
-
24
- describe("readJsonLinesWithBadJsonIdleWatchdog", () => {
25
- it("throws when a JSON-like bad line remains the last stdout past the idle timeout", async () => {
26
- vi.useFakeTimers();
27
- const input = new PassThrough();
28
- const iterator = createReader(input);
29
-
30
- const pending = iterator.next().catch((error: unknown) => error);
31
- input.write("{\"type\":\"tool_call\",\"subtype\":\"started\"\n");
32
-
33
- await vi.advanceTimersByTimeAsync(100);
34
-
35
- const error = await pending;
36
- expect(error).toBeInstanceOf(BadJsonIdleTimeoutError);
37
- expect(error).toMatchObject({
38
- code: "BAD_JSON_IDLE_TIMEOUT",
39
- tool: "test-agent",
40
- tag: "sid-test",
41
- });
42
- });
43
-
44
- it("does not throw when a valid JSON line arrives after the bad line before timeout", async () => {
45
- vi.useFakeTimers();
46
- const input = new PassThrough();
47
- const iterator = createReader(input);
48
-
49
- const pending = iterator.next();
50
- input.write("{\"type\":\"tool_call\"\n");
51
- await vi.advanceTimersByTimeAsync(50);
52
- input.write("{\"type\":\"ok\"}\n");
53
-
54
- await expect(pending).resolves.toEqual({
55
- done: false,
56
- value: { type: "ok" },
57
- });
58
-
59
- const done = iterator.next();
60
- input.end();
61
- await expect(done).resolves.toEqual({ done: true, value: undefined });
62
- });
63
-
64
- it("ignores non-JSON banner lines for the bad JSON idle watchdog", async () => {
65
- vi.useFakeTimers();
66
- const input = new PassThrough();
67
- const iterator = createReader(input);
68
-
69
- const pending = iterator.next();
70
- input.write("Reading prompt from stdin...\n");
71
- await vi.advanceTimersByTimeAsync(200);
72
- input.write("{\"type\":\"ok\"}\n");
73
-
74
- await expect(pending).resolves.toEqual({
75
- done: false,
76
- value: { type: "ok" },
77
- });
78
- });
79
- });