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,284 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
- import { mkdtempSync, rmSync, writeFileSync, mkdirSync, utimesSync } from "node:fs";
3
- import { homedir, tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- import {
7
- normalizeSkillPathForPrompt,
8
- parseSkillFrontmatter,
9
- scanSkillsDirs,
10
- buildDefaultSkillDirs,
11
- buildSkillsIndexPrompt,
12
- buildSkillTemplate,
13
- type SkillDirSpec,
14
- type SkillSource,
15
- type SkillScope,
16
- } from "../skills.js";
17
-
18
- let tempRoot: string;
19
-
20
- beforeEach(() => {
21
- tempRoot = mkdtempSync(join(tmpdir(), "deepccc-skills-"));
22
- });
23
-
24
- afterEach(() => {
25
- try {
26
- rmSync(tempRoot, { recursive: true, force: true });
27
- } catch {}
28
- });
29
-
30
- function makeSkill(specDir: string, name: string, description: string): string {
31
- const dir = join(specDir, name);
32
- mkdirSync(dir, { recursive: true });
33
- const skillPath = join(dir, "SKILL.md");
34
- writeFileSync(skillPath, `---\nname: ${name}\ndescription: ${description}\n---\n\nbody\n`, "utf8");
35
- return skillPath;
36
- }
37
-
38
- function spec(
39
- dir: string,
40
- source: SkillSource,
41
- scope: SkillScope = "global",
42
- ): SkillDirSpec {
43
- return { dir, source, scope };
44
- }
45
-
46
- describe("parseSkillFrontmatter", () => {
47
- it("parses name and description from frontmatter", () => {
48
- const content = [
49
- "---",
50
- "name: feishu-doc-download-md",
51
- "description: 下载飞书文档为 Markdown",
52
- "---",
53
- "",
54
- "# 正文",
55
- ].join("\n");
56
- expect(parseSkillFrontmatter(content)).toEqual({
57
- name: "feishu-doc-download-md",
58
- description: "下载飞书文档为 Markdown",
59
- });
60
- });
61
-
62
- it("returns null when there is no frontmatter", () => {
63
- expect(parseSkillFrontmatter("# just a heading")).toBeNull();
64
- });
65
-
66
- it("tolerates missing description", () => {
67
- expect(parseSkillFrontmatter("---\nname: minimal-skill\n---\n\nbody")).toEqual({
68
- name: "minimal-skill",
69
- description: "",
70
- });
71
- });
72
-
73
- it("handles CRLF line endings", () => {
74
- const content = "---\r\nname: crlf-skill\r\ndescription: CRLF 描述\r\n---\r\n\r\nbody";
75
- expect(parseSkillFrontmatter(content)).toEqual({
76
- name: "crlf-skill",
77
- description: "CRLF 描述",
78
- });
79
- });
80
- });
81
-
82
- describe("scanSkillsDirs priority matrix", () => {
83
- it("codex wins over cursor, cursor wins over claude for same-name skills", async () => {
84
- const claudeDir = join(tempRoot, "claude");
85
- const cursorDir = join(tempRoot, "cursor");
86
- const codexDir = join(tempRoot, "codex");
87
- makeSkill(claudeDir, "dupe", "claude version");
88
- makeSkill(cursorDir, "dupe", "cursor version");
89
- makeSkill(codexDir, "dupe", "codex version");
90
- makeSkill(codexDir, "only-codex", "codex only");
91
-
92
- const skills = await scanSkillsDirs([
93
- spec(claudeDir, "claude"),
94
- spec(cursorDir, "cursor"),
95
- spec(codexDir, "codex"),
96
- ]);
97
-
98
- const byName = new Map(skills.map((s) => [s.name, s]));
99
- expect(byName.get("dupe")?.description).toBe("codex version");
100
- expect(byName.get("dupe")?.source).toBe("codex");
101
- expect(byName.get("dupe")?.skillPath).toContain(join("codex", "dupe"));
102
- expect(byName.get("only-codex")?.source).toBe("codex");
103
- });
104
-
105
- it("project scope wins over global scope within the same source", async () => {
106
- const globalCodex = join(tempRoot, "codex-global");
107
- const projectCodex = join(tempRoot, "codex-project");
108
- makeSkill(globalCodex, "dup", "global version");
109
- makeSkill(projectCodex, "dup", "project version");
110
-
111
- const skills = await scanSkillsDirs([
112
- spec(globalCodex, "codex", "global"),
113
- spec(projectCodex, "codex", "project"),
114
- ]);
115
-
116
- const byName = new Map(skills.map((s) => [s.name, s]));
117
- expect(byName.get("dup")?.description).toBe("project version");
118
- expect(byName.get("dup")?.scope).toBe("project");
119
- });
120
-
121
- it("deepccc source has the highest priority over codex", async () => {
122
- const codexDir = join(tempRoot, "codex");
123
- const deepcccDir = join(tempRoot, "deepccc");
124
- makeSkill(codexDir, "dup", "from codex");
125
- makeSkill(deepcccDir, "dup", "from deepccc");
126
-
127
- const skills = await scanSkillsDirs([
128
- spec(codexDir, "codex"),
129
- spec(deepcccDir, "deepccc"),
130
- ]);
131
-
132
- expect(skills.find((s) => s.name === "dup")?.description).toBe("from deepccc");
133
- expect(skills.find((s) => s.name === "dup")?.source).toBe("deepccc");
134
- });
135
-
136
- it("skips hidden dirs, dirs without SKILL.md, and missing dirs", async () => {
137
- const dir = join(tempRoot, "src");
138
- mkdirSync(join(dir, ".system"), { recursive: true });
139
- writeFileSync(join(dir, ".system", "SKILL.md"), "---\nname: system-skill\ndescription: x\n---\n", "utf8");
140
- mkdirSync(join(dir, "no-skill-dir"));
141
-
142
- makeSkill(dir, "ok", "fine");
143
- const skills = await scanSkillsDirs([
144
- spec(join(tempRoot, "missing-dir"), "codex"),
145
- spec(dir, "codex"),
146
- ]);
147
-
148
- expect(skills).toHaveLength(1);
149
- expect(skills[0].name).toBe("ok");
150
- });
151
- });
152
-
153
- describe("scanSkillsDirs hot reload (mtime cache)", () => {
154
- it("re-reads a skill after its SKILL.md content changes", async () => {
155
- const dir = join(tempRoot, "src");
156
- const skillPath = makeSkill(dir, "live", "v1");
157
-
158
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
159
- expect(first.find((s) => s.name === "live")?.description).toBe("v1");
160
-
161
- writeFileSync(skillPath, "---\nname: live\ndescription: v2\n---\n\nbody\n", "utf8");
162
- utimesSync(skillPath, new Date(Date.now() + 3000), new Date(Date.now() + 3000)); // 强制 mtime 前进
163
-
164
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
165
- expect(second.find((s) => s.name === "live")?.description).toBe("v2");
166
- });
167
-
168
- it("new skill dirs are picked up on the next scan", async () => {
169
- const dir = join(tempRoot, "src");
170
- makeSkill(dir, "a", "A");
171
-
172
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
173
- expect(first).toHaveLength(1);
174
-
175
- makeSkill(dir, "b", "B"); // 新技能,无需改 mtime(目录枚举每次都做)
176
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
177
- expect(second.map((s) => s.name).sort()).toEqual(["a", "b"]);
178
- });
179
-
180
- it("unchanged skills return identical results across scans", async () => {
181
- const dir = join(tempRoot, "src");
182
- makeSkill(dir, "a", "A");
183
-
184
- const first = await scanSkillsDirs([spec(dir, "deepccc")]);
185
- const second = await scanSkillsDirs([spec(dir, "deepccc")]);
186
- expect(second).toEqual(first);
187
- });
188
- });
189
-
190
- describe("buildDefaultSkillDirs", () => {
191
- it("orders dirs low->high priority: claude < cursor < codex < deepccc, project after global", () => {
192
- const dirs = buildDefaultSkillDirs("C:/proj");
193
- expect(dirs.map((d) => `${d.source}:${d.scope}`)).toEqual([
194
- "claude:global",
195
- "claude:project",
196
- "cursor:global",
197
- "cursor:project",
198
- "codex:global",
199
- "codex:global",
200
- "codex:project",
201
- "deepccc:global",
202
- "deepccc:project",
203
- ]);
204
- });
205
-
206
- it("points codex global dirs at ~/.codex/skills and ~/.agents/skills", () => {
207
- const dirs = buildDefaultSkillDirs("C:/proj").filter((d) => d.source === "codex" && d.scope === "global");
208
- expect(dirs.map((d) => d.dir)).toEqual([
209
- join(require("node:os").homedir(), ".codex", "skills"),
210
- join(require("node:os").homedir(), ".agents", "skills"),
211
- ]);
212
- });
213
- });
214
-
215
- describe("normalizeSkillPathForPrompt", () => {
216
- it("abbreviates home-directory paths with ~ and normalizes separators", () => {
217
- const home = homedir();
218
- const abs = join(home, ".codex", "skills", "x", "SKILL.md");
219
- expect(normalizeSkillPathForPrompt(abs)).toBe("~/.codex/skills/x/SKILL.md");
220
- expect(normalizeSkillPathForPrompt(home)).toBe("~");
221
- });
222
-
223
- it("keeps paths outside the home directory unchanged (separators normalized)", () => {
224
- expect(normalizeSkillPathForPrompt("C:\\proj\\.claude\\skills\\x\\SKILL.md")).toBe(
225
- "C:/proj/.claude/skills/x/SKILL.md",
226
- );
227
- });
228
- });
229
-
230
- describe("buildSkillsIndexPrompt", () => {
231
- it("renders index with source markers and the skill creation convention", () => {
232
- const prompt = buildSkillsIndexPrompt([
233
- {
234
- name: "feishu-doc",
235
- description: "下载飞书文档",
236
- skillPath: "C:/x/feishu-doc/SKILL.md",
237
- source: "codex",
238
- scope: "global",
239
- },
240
- ]);
241
-
242
- expect(prompt).toContain("## 可用技能");
243
- expect(prompt).toContain("**feishu-doc**");
244
- expect(prompt).toContain("[codex:global]");
245
- expect(prompt).toContain("## 创建技能");
246
- expect(prompt).toContain(".deepccc/skills");
247
- expect(prompt).toContain("read_file");
248
- });
249
-
250
- it("renders home-abbreviated skill paths so the prompt stays stable across machines", () => {
251
- const home = homedir();
252
- const prompt = buildSkillsIndexPrompt([
253
- {
254
- name: "demo",
255
- description: "d",
256
- skillPath: join(home, ".codex", "skills", "demo", "SKILL.md"),
257
- source: "codex",
258
- scope: "global",
259
- },
260
- ]);
261
-
262
- expect(prompt).toContain("~/.codex/skills/demo/SKILL.md");
263
- expect(prompt).not.toContain(home);
264
- });
265
-
266
- it("returns empty string for no skills", () => {
267
- expect(buildSkillsIndexPrompt([])).toBe("");
268
- });
269
- });
270
-
271
- describe("buildSkillTemplate", () => {
272
- it("renders a Codex-style SKILL.md with frontmatter", () => {
273
- const tpl = buildSkillTemplate("my-skill", "does something");
274
- expect(tpl.startsWith("---")).toBe(true);
275
- expect(tpl).toContain("name: my-skill");
276
- expect(tpl).toContain("description: does something");
277
- expect(tpl).toContain("# my-skill");
278
- });
279
-
280
- it("defaults description to empty when omitted", () => {
281
- const tpl = buildSkillTemplate("bare-skill", "");
282
- expect(tpl).toContain("description: ");
283
- });
284
- });
@@ -1,247 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
-
3
- import {
4
- buildBlockLines,
5
- charWidth,
6
- clipToWidth,
7
- TerminalProgressRenderer,
8
- } from "../progress/terminal-renderer.js";
9
- import { progressView } from "../progress/view.js";
10
-
11
- class FakeOut {
12
- chunks: string[] = [];
13
- columns = 100;
14
- write(s: string): boolean {
15
- this.chunks.push(s);
16
- return true;
17
- }
18
- get output(): string {
19
- return this.chunks.join("");
20
- }
21
- }
22
-
23
- /** 测试桩:仅实现 write 的假输出流,类型上按 WritableStream 对待 */
24
- function asOut(out: FakeOut): NodeJS.WritableStream & { columns?: number } {
25
- return out as unknown as NodeJS.WritableStream & { columns?: number };
26
- }
27
-
28
- afterEach(() => {
29
- vi.useRealTimers();
30
- });
31
-
32
- describe("buildBlockLines", () => {
33
- it("renders generating status line with header title and stop hint", () => {
34
- const lines = buildBlockLines(
35
- progressView({ headerTitle: "正在启动 Agent · 0秒", text: "" }),
36
- 100,
37
- );
38
- expect(lines[0]).toContain("⏳ 正在启动 Agent · 0秒");
39
- expect(lines[0]).toContain("Ctrl+C 停止");
40
- expect(lines[1]).toContain("等待 Agent 输出...");
41
- });
42
-
43
- it("renders done / stopped / error status lines", () => {
44
- const done = buildBlockLines(progressView({ status: "done", text: "ok" }), 100);
45
- expect(done[0]).toContain("✅ 完成");
46
- expect(done[0]).toContain("\x1b[1m"); // 完成状态行加粗,不用浅色
47
- const stopped = buildBlockLines(progressView({ status: "stopped", text: "x" }), 100);
48
- expect(stopped[0]).toContain("⏹ 已停止");
49
- const error = buildBlockLines(progressView({ status: "error", text: "x" }), 100);
50
- expect(error[0]).toContain("❌ 异常结束");
51
- });
52
-
53
- it("renders tool lines with emoji and status mark", () => {
54
- const lines = buildBlockLines(
55
- progressView({
56
- text: "",
57
- tools: [
58
- { id: "t1", name: "edit_file", status: "running", detail: "edit a.ts" },
59
- { id: "t2", name: "run_command", status: "ok", summary: "npm test passed" },
60
- { id: "t3", name: "search_code", status: "error", summary: "regex error" },
61
- ],
62
- }),
63
- 100,
64
- );
65
- expect(lines[1]).toContain("edit_file");
66
- expect(lines[1]).toContain("…");
67
- expect(lines[1]).toContain("edit a.ts");
68
- expect(lines[2]).toContain("✓");
69
- expect(lines[2]).toContain("npm test passed");
70
- expect(lines[3]).toContain("✗");
71
- expect(lines[3]).toContain("regex error");
72
- // 工具行摘要不用浅色字体(回复内容可读性优先)
73
- for (const line of [lines[1], lines[2], lines[3]]) {
74
- expect(line).not.toContain("\x1b[2m");
75
- }
76
- });
77
-
78
- it("truncates long body to maxBodyLines", () => {
79
- const text = Array.from({ length: 50 }, (_, i) => `line ${i}`).join("\n");
80
- const lines = buildBlockLines(progressView({ text }), 100, 5);
81
- expect(lines.filter((l) => l.startsWith("line"))).toHaveLength(5);
82
- expect(lines.join("\n")).toContain("...");
83
- });
84
-
85
- it("clips lines wider than terminal width to avoid wrapping", () => {
86
- const lines = buildBlockLines(
87
- progressView({ text: "x".repeat(200) }),
88
- 30,
89
- );
90
- for (const line of lines) {
91
- expect(line.length).toBeLessThanOrEqual(30);
92
- }
93
- });
94
-
95
- it("charWidth counts CJK/emoji as 2 columns and control/ZWJ as 0", () => {
96
- expect(charWidth("a")).toBe(1);
97
- expect(charWidth("中")).toBe(2);
98
- expect(charWidth("📂")).toBe(2);
99
- expect(charWidth("\u200d")).toBe(0); // ZWJ
100
- });
101
-
102
- it("clipToWidth truncates by display width, not string length", () => {
103
- expect(clipToWidth("中文abc", 4)).toBe("中文");
104
- expect(clipToWidth("中文abc", 5)).toBe("中文a");
105
- expect(clipToWidth("📂 x", 2)).toBe("📂");
106
- expect(clipToWidth("📂 x", 3)).toBe("📂 ");
107
- });
108
-
109
- it("clipToWidth keeps ANSI tokens whole and closes colors at the cut", () => {
110
- const ansi = "\x1b[32m📂\x1b[0m abc";
111
- expect(clipToWidth(ansi, 6)).toBe("\x1b[32m📂\x1b[0m abc");
112
- expect(clipToWidth(ansi, 5)).toBe("\x1b[32m📂\x1b[0m ab");
113
- // 截断发生在未闭合颜色内时自动补 reset,避免颜色泄漏
114
- expect(clipToWidth("\x1b[1m\x1b[32m✅ 完成\x1b[0m", 6)).toBe("\x1b[1m\x1b[32m✅ 完\x1b[0m");
115
- });
116
-
117
- it("emoji tool lines are clipped by display width so the block never wraps", () => {
118
- // 模拟用户示例:emoji + 超长 JSON 工具行,宽 40 的终端必须整行不折行
119
- const lines = buildBlockLines(
120
- progressView({
121
- text: "",
122
- tools: [
123
- { id: "t1", name: "list_dir", status: "ok", summary: `{"path":"C:\\Users\\weizhangjian\\.chatccc","entries":[{"name":"builtin","path":"C:\\Users${'x'.repeat(300)}"}]}` },
124
- ],
125
- }),
126
- 40,
127
- );
128
- const toolLine = lines.find((l) => l.includes("list_dir"))!;
129
- // 显示宽度(剥离 ANSI 后按 charWidth 计算)不超过终端列宽,永不折行
130
- const visible = [...toolLine.replace(/\x1b\[[0-9;]*m/g, "")].reduce((w, ch) => w + charWidth(ch), 0);
131
- expect(visible).toBeLessThanOrEqual(40);
132
- expect(toolLine).toContain("\x1b[0m"); // ANSI 完整闭合
133
- });
134
- });
135
-
136
- describe("TerminalProgressRenderer", () => {
137
- it("begin writes hide-cursor and the first frame", () => {
138
- const out = new FakeOut();
139
- const r = new TerminalProgressRenderer({ out: asOut(out) });
140
- r.begin(progressView({ text: "hello" }));
141
- expect(out.output.startsWith("\x1b[?25l")).toBe(true);
142
- expect(out.output).toContain("hello");
143
- r.dispose();
144
- });
145
-
146
- it("end finalizes the block and restores cursor, keeping block on screen", () => {
147
- const out = new FakeOut();
148
- const r = new TerminalProgressRenderer({ out: asOut(out) });
149
- r.begin(progressView({ text: "a" }));
150
- const before = out.chunks.length;
151
- r.end(progressView({ status: "done", text: "final" }));
152
- const delta = out.output.slice(out.chunks.slice(0, before).join("").length);
153
- expect(delta).toContain("✅ 完成");
154
- expect(delta.endsWith("\x1b[?25h")).toBe(true);
155
- });
156
-
157
- it("render is frame-throttled and flush forces immediate redraw", () => {
158
- vi.useFakeTimers();
159
- const out = new FakeOut();
160
- const r = new TerminalProgressRenderer({ out: asOut(out), frameMs: 100 });
161
-
162
- r.begin(progressView({ text: "" }));
163
- const outputAfterBegin = out.output;
164
-
165
- r.render(progressView({ text: "one" }));
166
- r.render(progressView({ text: "two" }));
167
- r.render(progressView({ text: "three" }));
168
- // 节流窗口内多次 render 不应产生任何输出
169
- expect(out.output).toBe(outputAfterBegin);
170
-
171
- vi.advanceTimersByTime(100);
172
- // 合并后只重绘一次,且展示的是最新视图
173
- expect(out.output).toContain("three");
174
- expect(out.output).not.toContain("two");
175
-
176
- r.flush();
177
- // flush 立即重绘当前视图(输出继续增长且仍是三帧内容)
178
- expect(out.output.length).toBeGreaterThan(outputAfterBegin.length);
179
- expect(out.output).toContain("three");
180
- r.dispose();
181
- });
182
-
183
- it("clears leftover lines when the block shrinks", () => {
184
- const out = new FakeOut();
185
- const r = new TerminalProgressRenderer({ out: asOut(out) });
186
- r.begin(progressView({ text: "a\nb\nc\nd" }));
187
- r.end(progressView({ status: "done", text: "short" }));
188
- expect(out.output).toContain("\x1b[2K\n");
189
- expect(out.output).toContain("\x1b[J");
190
- });
191
-
192
- it("heartbeat animates generating dots so the block never freezes", () => {
193
- vi.useFakeTimers();
194
- const out = new FakeOut();
195
- const r = new TerminalProgressRenderer({ out: asOut(out), animMs: 100 });
196
- r.begin(progressView({ headerTitle: "生成中...", text: "" }));
197
- const frame0 = out.output;
198
- expect(frame0).toContain("·"); // 首帧即带动画点
199
- vi.advanceTimersByTime(100);
200
- const frame1 = out.output;
201
- expect(frame1).not.toBe(frame0); // 无新事件也持续重绘
202
- expect(frame1).toContain("··"); // 第二帧点号增长
203
- r.dispose();
204
- });
205
-
206
- it("stops the heartbeat after end so the final block stays static", () => {
207
- vi.useFakeTimers();
208
- const out = new FakeOut();
209
- const r = new TerminalProgressRenderer({ out: asOut(out), animMs: 100 });
210
- r.begin(progressView({ text: "" }));
211
- r.end(progressView({ status: "done", text: "final" }));
212
- const afterEnd = out.output.length;
213
- vi.advanceTimersByTime(500);
214
- expect(out.output.length).toBe(afterEnd);
215
- });
216
-
217
- it("redraw moves up exactly blockLines-1 rows, never eating history above", () => {
218
- // 回归测试:光标在区块最后一行时,回到第一行只需上移 N-1 行。
219
- // 上移 N 行会每帧多上移 1 行,把上方历史内容逐行吃掉。
220
- const out = new FakeOut();
221
- const r = new TerminalProgressRenderer({ out: asOut(out), animMs: 0 });
222
- // 状态行 1 行 + 正文 4 行 = 5 行区块
223
- r.begin(progressView({ text: "a\nb\nc\nd" }));
224
- const afterBegin = out.output;
225
- r.flush(); // 第二帧强制重绘
226
- const delta = out.output.slice(afterBegin.length);
227
- expect(delta).toContain("\x1b[4A"); // 上移 5-1=4 行
228
- expect(delta).not.toContain("\x1b[5A"); // 绝不出现上移 N 行
229
- r.dispose();
230
- });
231
-
232
- it("multi-frame redraws keep moving up N-1 rows each time (no drift)", () => {
233
- const out = new FakeOut();
234
- const r = new TerminalProgressRenderer({ out: asOut(out), animMs: 0 });
235
- r.begin(progressView({ text: "a\nb\nc\nd" }));
236
- for (let i = 0; i < 3; i++) {
237
- r.flush();
238
- }
239
- // 连续多帧重绘,每帧上移都是 4 行(5 行区块),不是 5/6/7... 逐帧递增
240
- const moves = out.output.match(/\x1b\[(\d+)A/g) ?? [];
241
- expect(moves.length).toBe(3);
242
- for (const move of moves) {
243
- expect(move).toBe("\x1b[4A");
244
- }
245
- r.dispose();
246
- });
247
- });