chatccc 0.2.252 → 0.2.253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/README.md +1 -1
  2. package/bin/cccagent.mjs +12 -3
  3. package/bin/chatccc.mjs +15 -6
  4. package/deepccc-agent/os-prompts/darwin.md +8 -8
  5. package/deepccc-agent/os-prompts/linux.md +8 -8
  6. package/deepccc-agent/os-prompts/win32.md +11 -11
  7. package/deepccc-agent/package.json +65 -65
  8. package/dist/deepccc-agent/src/cli.js +634 -0
  9. package/dist/deepccc-agent/src/config.js +76 -0
  10. package/dist/deepccc-agent/src/context.js +348 -0
  11. package/dist/deepccc-agent/src/file-log.js +34 -0
  12. package/dist/deepccc-agent/src/file-tools.js +1208 -0
  13. package/dist/deepccc-agent/src/index.js +571 -0
  14. package/dist/deepccc-agent/src/permissions.js +170 -0
  15. package/dist/deepccc-agent/src/privacy.js +124 -0
  16. package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
  17. package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
  18. package/dist/deepccc-agent/src/progress/reducer.js +102 -0
  19. package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
  20. package/dist/deepccc-agent/src/progress/view.js +30 -0
  21. package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
  22. package/dist/deepccc-agent/src/session-search.js +276 -0
  23. package/dist/deepccc-agent/src/session-select.js +23 -0
  24. package/dist/deepccc-agent/src/sigint.js +26 -0
  25. package/dist/deepccc-agent/src/skills.js +178 -0
  26. package/dist/deepccc-agent/src/web-tools.js +246 -0
  27. package/dist/src/adapters/adapter-interface.js +19 -0
  28. package/dist/src/adapters/ccc-adapter.js +112 -0
  29. package/dist/src/adapters/claude-adapter.js +497 -0
  30. package/dist/src/adapters/claude-session-meta-store.js +92 -0
  31. package/dist/src/adapters/codex-adapter.js +279 -0
  32. package/dist/src/adapters/codex-session-meta-store.js +94 -0
  33. package/dist/src/adapters/cursor-adapter.js +491 -0
  34. package/dist/src/adapters/cursor-session-meta-store.js +116 -0
  35. package/dist/src/adapters/jsonl-stream.js +104 -0
  36. package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
  37. package/dist/src/adapters/raw-stream-log.js +106 -0
  38. package/dist/src/adapters/resource-monitor.js +113 -0
  39. package/dist/src/agent-activity.js +133 -0
  40. package/dist/src/agent-delegate-task-rpc.js +129 -0
  41. package/dist/src/agent-delegate-task.js +48 -0
  42. package/dist/src/agent-file-rpc.js +152 -0
  43. package/dist/src/agent-image-rpc.js +148 -0
  44. package/dist/src/agent-platform-routing.js +13 -0
  45. package/dist/src/agent-reload-config-rpc.js +23 -0
  46. package/dist/src/agent-rpc-body.js +87 -0
  47. package/dist/src/agent-stop-stuck.js +110 -0
  48. package/dist/src/card-action-routing.js +7 -0
  49. package/dist/src/card-plain-text.js +101 -0
  50. package/dist/src/cardkit.js +158 -0
  51. package/dist/src/cards.js +573 -0
  52. package/dist/src/chatgpt-subscription-rpc.js +18 -0
  53. package/dist/src/chatgpt-subscription.js +199 -0
  54. package/dist/src/chrome-devtools-guard.js +238 -0
  55. package/dist/src/claude-sdk-installer.js +249 -0
  56. package/dist/src/codex-reset-actions.js +143 -0
  57. package/dist/src/config-utils.js +149 -0
  58. package/dist/src/config.js +804 -0
  59. package/dist/src/cursor-usage.js +77 -0
  60. package/dist/src/exit-banner.js +28 -0
  61. package/dist/src/feishu-api.js +1404 -0
  62. package/dist/src/feishu-message-ingress.js +137 -0
  63. package/dist/src/feishu-platform.js +97 -0
  64. package/dist/src/format-message.js +252 -0
  65. package/dist/src/git-command.js +155 -0
  66. package/dist/src/im-skills.js +121 -0
  67. package/dist/src/index.js +833 -0
  68. package/dist/src/litellm-proxy.js +300 -0
  69. package/dist/src/orchestrator.js +2078 -0
  70. package/dist/src/package-root.js +26 -0
  71. package/dist/src/platform-adapter.js +7 -0
  72. package/dist/src/platform-startup.js +6 -0
  73. package/dist/src/privacy.js +100 -0
  74. package/dist/src/progress/reducer.js +102 -0
  75. package/dist/src/progress/terminal-renderer.js +264 -0
  76. package/dist/src/progress/view.js +30 -0
  77. package/dist/src/response-stall.js +14 -0
  78. package/dist/src/runtime-entry.js +13 -0
  79. package/dist/src/runtime-reload.js +19 -0
  80. package/dist/src/session-chat-binding.js +183 -0
  81. package/dist/src/session-name.js +7 -0
  82. package/dist/src/session.js +2144 -0
  83. package/dist/src/shared-prefix.js +16 -0
  84. package/dist/src/shared.js +493 -0
  85. package/dist/src/sim-agent.js +105 -0
  86. package/dist/src/sim-platform.js +142 -0
  87. package/dist/src/sim-store.js +231 -0
  88. package/dist/src/simplify.js +99 -0
  89. package/dist/src/startup-lifecycle.js +209 -0
  90. package/dist/src/stream-state.js +141 -0
  91. package/dist/src/terminal-error.js +100 -0
  92. package/dist/src/trace.js +50 -0
  93. package/dist/src/turn-cards.js +92 -0
  94. package/dist/src/update-command-guard.js +114 -0
  95. package/{src/web-ui.ts → dist/src/web-ui.js} +749 -823
  96. package/dist/src/wechat-platform.js +545 -0
  97. package/package.json +76 -74
  98. package/deepccc-agent/LICENSE +0 -201
  99. package/deepccc-agent/bin/deepccc.mjs +0 -26
  100. package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
  101. package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
  102. package/deepccc-agent/package-lock.json +0 -2027
  103. package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
  104. package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
  105. package/deepccc-agent/src/__tests__/config.test.ts +0 -34
  106. package/deepccc-agent/src/__tests__/context.test.ts +0 -341
  107. package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
  108. package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
  109. package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
  110. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
  111. package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
  112. package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
  113. package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
  114. package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
  115. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
  116. package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
  117. package/deepccc-agent/src/cli.ts +0 -682
  118. package/deepccc-agent/src/config.ts +0 -101
  119. package/deepccc-agent/src/context.ts +0 -465
  120. package/deepccc-agent/src/file-log.ts +0 -38
  121. package/deepccc-agent/src/file-tools.ts +0 -1493
  122. package/deepccc-agent/src/index.ts +0 -710
  123. package/deepccc-agent/src/permissions.ts +0 -226
  124. package/deepccc-agent/src/privacy.ts +0 -141
  125. package/deepccc-agent/src/proc-tree-kill.ts +0 -61
  126. package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
  127. package/deepccc-agent/src/progress/reducer.ts +0 -113
  128. package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
  129. package/deepccc-agent/src/progress/view.ts +0 -77
  130. package/deepccc-agent/src/raw-stream-log.ts +0 -124
  131. package/deepccc-agent/src/session-search.ts +0 -370
  132. package/deepccc-agent/src/session-select.ts +0 -48
  133. package/deepccc-agent/src/sigint.ts +0 -50
  134. package/deepccc-agent/src/skills.ts +0 -205
  135. package/deepccc-agent/src/web-tools.ts +0 -313
  136. package/deepccc-agent/tsconfig.build.json +0 -13
  137. package/deepccc-agent/tsconfig.json +0 -13
  138. package/deepccc-agent/vitest.config.ts +0 -7
  139. package/src/__tests__/adapter-interface.test.ts +0 -152
  140. package/src/__tests__/agent-activity.test.ts +0 -86
  141. package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
  142. package/src/__tests__/agent-image-rpc.test.ts +0 -34
  143. package/src/__tests__/agent-platform-routing.test.ts +0 -26
  144. package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
  145. package/src/__tests__/agent-rpc-body.test.ts +0 -42
  146. package/src/__tests__/builtin-chat-session.test.ts +0 -532
  147. package/src/__tests__/builtin-cli-json.test.ts +0 -39
  148. package/src/__tests__/builtin-config.test.ts +0 -26
  149. package/src/__tests__/builtin-context.test.ts +0 -319
  150. package/src/__tests__/builtin-file-tools.test.ts +0 -240
  151. package/src/__tests__/builtin-permissions.test.ts +0 -219
  152. package/src/__tests__/builtin-session-search.test.ts +0 -262
  153. package/src/__tests__/builtin-session-select.test.ts +0 -116
  154. package/src/__tests__/builtin-sigint.test.ts +0 -56
  155. package/src/__tests__/builtin-skills.test.ts +0 -284
  156. package/src/__tests__/builtin-web-tools.test.ts +0 -220
  157. package/src/__tests__/card-action-routing.test.ts +0 -18
  158. package/src/__tests__/card-plain-text.test.ts +0 -45
  159. package/src/__tests__/cardkit.test.ts +0 -60
  160. package/src/__tests__/cards.test.ts +0 -607
  161. package/src/__tests__/ccc-adapter.test.ts +0 -194
  162. package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
  163. package/src/__tests__/chatgpt-subscription.test.ts +0 -135
  164. package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
  165. package/src/__tests__/claude-adapter.test.ts +0 -614
  166. package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
  167. package/src/__tests__/claude-sdk-installer.test.ts +0 -285
  168. package/src/__tests__/codex-adapter.test.ts +0 -331
  169. package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
  170. package/src/__tests__/codex-reset-actions.test.ts +0 -146
  171. package/src/__tests__/config-reload.test.ts +0 -284
  172. package/src/__tests__/config-sample.test.ts +0 -97
  173. package/src/__tests__/config-utils.test.ts +0 -40
  174. package/src/__tests__/config.test.ts +0 -395
  175. package/src/__tests__/crash-logging.test.ts +0 -360
  176. package/src/__tests__/cursor-adapter.test.ts +0 -890
  177. package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
  178. package/src/__tests__/feishu-api.test.ts +0 -60
  179. package/src/__tests__/feishu-avatar.test.ts +0 -504
  180. package/src/__tests__/feishu-message-ingress.test.ts +0 -138
  181. package/src/__tests__/feishu-platform.test.ts +0 -75
  182. package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
  183. package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
  184. package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
  185. package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
  186. package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
  187. package/src/__tests__/format-message.test.ts +0 -316
  188. package/src/__tests__/git-command.test.ts +0 -288
  189. package/src/__tests__/im-skills.test.ts +0 -125
  190. package/src/__tests__/jsonl-stream.test.ts +0 -79
  191. package/src/__tests__/orchestrator.test.ts +0 -1268
  192. package/src/__tests__/package-files.test.ts +0 -24
  193. package/src/__tests__/platform-startup.test.ts +0 -19
  194. package/src/__tests__/privacy.test.ts +0 -198
  195. package/src/__tests__/proc-tree-kill.test.ts +0 -108
  196. package/src/__tests__/progress-reducer.test.ts +0 -121
  197. package/src/__tests__/raw-stream-log.test.ts +0 -106
  198. package/src/__tests__/response-stall.test.ts +0 -49
  199. package/src/__tests__/restart.test.ts +0 -232
  200. package/src/__tests__/session-ccc-config.test.ts +0 -66
  201. package/src/__tests__/session.test.ts +0 -3004
  202. package/src/__tests__/shared-prefix.test.ts +0 -36
  203. package/src/__tests__/sim-agent.test.ts +0 -174
  204. package/src/__tests__/sim-platform.test.ts +0 -93
  205. package/src/__tests__/sim-store.test.ts +0 -214
  206. package/src/__tests__/simplify.test.ts +0 -283
  207. package/src/__tests__/startup-lifecycle.test.ts +0 -231
  208. package/src/__tests__/stop-session.test.ts +0 -162
  209. package/src/__tests__/stream-state.test.ts +0 -164
  210. package/src/__tests__/terminal-error.test.ts +0 -54
  211. package/src/__tests__/terminal-renderer.test.ts +0 -247
  212. package/src/__tests__/update-command-guard.test.ts +0 -144
  213. package/src/__tests__/web-ui.test.ts +0 -438
  214. package/src/__tests__/wechat-platform.test.ts +0 -111
  215. package/src/adapters/adapter-interface.ts +0 -217
  216. package/src/adapters/ccc-adapter.ts +0 -150
  217. package/src/adapters/claude-adapter.ts +0 -673
  218. package/src/adapters/claude-session-meta-store.ts +0 -120
  219. package/src/adapters/codex-adapter.ts +0 -426
  220. package/src/adapters/codex-session-meta-store.ts +0 -131
  221. package/src/adapters/cursor-adapter.ts +0 -681
  222. package/src/adapters/cursor-session-meta-store.ts +0 -154
  223. package/src/adapters/jsonl-stream.ts +0 -157
  224. package/src/adapters/raw-stream-log.ts +0 -124
  225. package/src/adapters/resource-monitor.ts +0 -141
  226. package/src/agent-activity.ts +0 -175
  227. package/src/agent-delegate-task-rpc.ts +0 -153
  228. package/src/agent-delegate-task.ts +0 -91
  229. package/src/agent-file-rpc.ts +0 -172
  230. package/src/agent-image-rpc.ts +0 -168
  231. package/src/agent-platform-routing.ts +0 -28
  232. package/src/agent-reload-config-rpc.ts +0 -34
  233. package/src/agent-rpc-body.ts +0 -92
  234. package/src/agent-stop-stuck.ts +0 -129
  235. package/src/card-action-routing.ts +0 -14
  236. package/src/card-plain-text.ts +0 -108
  237. package/src/cardkit.ts +0 -179
  238. package/src/cards.ts +0 -684
  239. package/src/chatgpt-subscription-rpc.ts +0 -27
  240. package/src/chatgpt-subscription.ts +0 -299
  241. package/src/chrome-devtools-guard.ts +0 -318
  242. package/src/claude-sdk-installer.ts +0 -324
  243. package/src/codex-reset-actions.ts +0 -184
  244. package/src/config-utils.ts +0 -211
  245. package/src/config.ts +0 -1063
  246. package/src/cursor-usage.ts +0 -128
  247. package/src/exit-banner.ts +0 -33
  248. package/src/feishu-api.ts +0 -1616
  249. package/src/feishu-message-ingress.ts +0 -195
  250. package/src/feishu-platform.ts +0 -159
  251. package/src/format-message.ts +0 -293
  252. package/src/git-command.ts +0 -202
  253. package/src/im-skills.ts +0 -149
  254. package/src/index.ts +0 -1089
  255. package/src/litellm-proxy.ts +0 -374
  256. package/src/orchestrator.ts +0 -2543
  257. package/src/platform-adapter.ts +0 -70
  258. package/src/platform-startup.ts +0 -16
  259. package/src/privacy.ts +0 -118
  260. package/src/progress/reducer.ts +0 -113
  261. package/src/progress/terminal-renderer.ts +0 -294
  262. package/src/progress/view.ts +0 -77
  263. package/src/response-stall.ts +0 -28
  264. package/src/runtime-reload.ts +0 -34
  265. package/src/session-chat-binding.ts +0 -292
  266. package/src/session-name.ts +0 -8
  267. package/src/session.ts +0 -2659
  268. package/src/shared-prefix.ts +0 -29
  269. package/src/shared.ts +0 -552
  270. package/src/sim-agent.ts +0 -167
  271. package/src/sim-platform.ts +0 -177
  272. package/src/sim-store.ts +0 -317
  273. package/src/simplify.ts +0 -120
  274. package/src/startup-lifecycle.ts +0 -250
  275. package/src/stream-state.ts +0 -177
  276. package/src/terminal-error.ts +0 -129
  277. package/src/trace.ts +0 -51
  278. package/src/turn-cards.ts +0 -118
  279. package/src/update-command-guard.ts +0 -165
  280. package/src/wechat-platform.ts +0 -680
@@ -1,70 +0,0 @@
1
- /**
2
- * platform-adapter.ts — IM 平台适配器接口
3
- *
4
- * 独立于 orchestrator.ts,避免 orchestrator ↔ session 循环依赖。
5
- * 每个方法内部自行管理认证,消费者不感知 token 等认证细节。
6
- */
7
-
8
- import type { CursorUsageSummary } from "./cursor-usage.ts";
9
- import type { CodexUsageSummary } from "./feishu-api.ts";
10
-
11
- export interface ChatAvatarUsageHints {
12
- codexUsage?: CodexUsageSummary | null;
13
- cursorUsage?: CursorUsageSummary | null;
14
- fastMode?: boolean;
15
- }
16
-
17
- export interface PlatformAdapter {
18
- /** 平台标识,用于区分不同平台的行为(如 wechat、feishu 等) */
19
- kind?: string;
20
-
21
- /** 发送纯文本回复 */
22
- sendText(chatId: string, text: string): Promise<boolean>;
23
-
24
- /** 发送卡片回复(标题 + 内容 + 颜色模板) */
25
- sendCard(
26
- chatId: string,
27
- title: string,
28
- content: string,
29
- template: string,
30
- ): Promise<boolean>;
31
-
32
- /** 发送原始卡片 JSON */
33
- sendRawCard(chatId: string, cardJson: string): Promise<boolean>;
34
-
35
- /** 创建群聊,返回新群 ID */
36
- createGroup(name: string, userIds: string[]): Promise<string>;
37
-
38
- /** 更新群名称和描述 */
39
- updateChatInfo(
40
- chatId: string,
41
- name: string,
42
- description: string,
43
- ): Promise<void>;
44
-
45
- /** 获取群信息 */
46
- getChatInfo(chatId: string): Promise<{ name: string; description: string }>;
47
-
48
- /** 解散群聊 */
49
- disbandChat(chatId: string): Promise<void>;
50
-
51
- /** 设置群头像 */
52
- setChatAvatar(chatId: string, tool: string, status: string, usageHints?: ChatAvatarUsageHints): Promise<void>;
53
-
54
- /** 从群描述中提取 session 信息 */
55
- extractSessionInfo(
56
- description: string,
57
- ): { sessionId: string; tool: string } | null;
58
-
59
- // ---- 进度展示(display loop 使用) ----
60
- // 不同平台能力不同:飞书用 CardKit 实时卡片,微信降级为纯文本。
61
-
62
- /** 创建进度展示实体,返回唯一标识;不支持进度展示的平台返回 null */
63
- cardCreate(cardJson: string): Promise<string | null>;
64
-
65
- /** 将进度展示发送到指定会话,返回 message_id */
66
- cardSend(chatId: string, cardId: string): Promise<string>;
67
-
68
- /** 更新已发送的进度展示,sequence 保证有序 */
69
- cardUpdate(cardId: string, cardJson: string, sequence: number): Promise<void>;
70
- }
@@ -1,16 +0,0 @@
1
- export interface PlatformStartupPlanInput {
2
- feishuEnabled: boolean;
3
- ilinkEnabled: boolean;
4
- }
5
-
6
- export interface PlatformStartupPlan {
7
- startFeishu: boolean;
8
- startIlink: boolean;
9
- }
10
-
11
- export function buildPlatformStartupPlan(input: PlatformStartupPlanInput): PlatformStartupPlan {
12
- return {
13
- startFeishu: input.feishuEnabled,
14
- startIlink: input.ilinkEnabled,
15
- };
16
- }
package/src/privacy.ts DELETED
@@ -1,118 +0,0 @@
1
- import { existsSync, readFileSync, statSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { USER_DATA_DIR } from "./config.ts";
4
-
5
- interface PrivacyRules {
6
- [key: string]: string;
7
- }
8
-
9
- interface PrivacyConfig {
10
- enabled: boolean;
11
- rules: PrivacyRules;
12
- }
13
-
14
- let config: PrivacyConfig | null = null;
15
- let loadedStamp: string | null | undefined;
16
-
17
- function privacyFilePath(): string {
18
- return join(USER_DATA_DIR, "privacy.json");
19
- }
20
-
21
- function privacyFileStamp(): string | null {
22
- const filePath = privacyFilePath();
23
- if (!existsSync(filePath)) return null;
24
- try {
25
- const s = statSync(filePath);
26
- return `${s.mtimeMs}:${s.size}`;
27
- } catch {
28
- return null;
29
- }
30
- }
31
-
32
- function sanitizeRules(raw: Record<string, unknown>): PrivacyRules {
33
- const result: PrivacyRules = {};
34
- for (const [from, to] of Object.entries(raw)) {
35
- if (!from) {
36
- console.error("[PRIVACY] privacy.json rule key cannot be empty, skipped");
37
- continue;
38
- }
39
- if (typeof to !== "string") {
40
- console.error(`[PRIVACY] privacy.json value must be a string, skipped "${from}"`);
41
- continue;
42
- }
43
- result[from] = to;
44
- }
45
- return result;
46
- }
47
-
48
- function normalizeConfig(parsed: Record<string, unknown>): PrivacyConfig {
49
- const hasNewSchema = Object.prototype.hasOwnProperty.call(parsed, "enabled") ||
50
- Object.prototype.hasOwnProperty.call(parsed, "rules");
51
-
52
- if (!hasNewSchema) {
53
- return { enabled: true, rules: sanitizeRules(parsed) };
54
- }
55
-
56
- const enabledRaw = parsed.enabled;
57
- const enabled = enabledRaw === undefined ? true : enabledRaw !== false;
58
- if (enabledRaw !== undefined && typeof enabledRaw !== "boolean") {
59
- console.error("[PRIVACY] privacy.json enabled must be a boolean, using true");
60
- }
61
-
62
- const rulesRaw = parsed.rules;
63
- if (rulesRaw === undefined) return { enabled, rules: {} };
64
- if (typeof rulesRaw !== "object" || rulesRaw === null || Array.isArray(rulesRaw)) {
65
- console.error("[PRIVACY] privacy.json rules must be an object");
66
- return { enabled, rules: {} };
67
- }
68
- return { enabled, rules: sanitizeRules(rulesRaw as Record<string, unknown>) };
69
- }
70
-
71
- function loadConfig(): PrivacyConfig {
72
- const filePath = privacyFilePath();
73
- if (!existsSync(filePath)) {
74
- return { enabled: true, rules: {} };
75
- }
76
- try {
77
- const raw = readFileSync(filePath, "utf-8").replace(/^\uFEFF/, "");
78
- const parsed = JSON.parse(raw);
79
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
80
- console.error("[PRIVACY] privacy.json must be an object");
81
- return { enabled: true, rules: {} };
82
- }
83
- return normalizeConfig(parsed as Record<string, unknown>);
84
- } catch (err) {
85
- console.error(`[PRIVACY] failed to read privacy.json: ${(err as Error).message}`);
86
- return { enabled: true, rules: {} };
87
- }
88
- }
89
-
90
- export function getPrivacyConfig(): PrivacyConfig {
91
- const stamp = privacyFileStamp();
92
- if (!config || stamp !== loadedStamp) {
93
- config = loadConfig();
94
- loadedStamp = stamp;
95
- }
96
- return config;
97
- }
98
-
99
- export function getPrivacyRules(): PrivacyRules {
100
- return getPrivacyConfig().rules;
101
- }
102
-
103
- export function reloadPrivacyRules(): void {
104
- config = null;
105
- loadedStamp = undefined;
106
- }
107
-
108
- export function applyPrivacy(text: string): string {
109
- const { enabled, rules } = getPrivacyConfig();
110
- if (!enabled || Object.keys(rules).length === 0 || !text) return text;
111
-
112
- let result = text;
113
- for (const [from, to] of Object.entries(rules)) {
114
- // Use split+join instead of regex replacement so rule keys stay literal.
115
- result = result.split(from).join(to);
116
- }
117
- return result;
118
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * progress/reducer.ts — ChatEvent 事件流 → ProgressView 的增量合并
3
- *
4
- * 这是飞书与终端共享的唯一一份"事件 → 过程视图"公共逻辑:
5
- * 终端 REPL 直接消费 ChatSession.chat() 的事件流,逐条 reduce;
6
- * 飞书侧 display loop 若未来接入事件流,同样使用本 reducer,保证两端
7
- * 看到的过程状态(正文累积、工具调用、终态判定)完全一致。
8
- */
9
-
10
- import type { ChatEvent } from "../../deepccc-agent/src/index.ts";
11
- import {
12
- withProgressView,
13
- type ProgressToolCall,
14
- type ProgressView,
15
- } from "./view.ts";
16
-
17
- /** 工具调用 input 单行摘要(终端折叠行展示用) */
18
- export function summarizeToolInput(input: unknown, maxChars = 120): string {
19
- let raw: string;
20
- if (typeof input === "string") {
21
- raw = input;
22
- } else {
23
- try {
24
- raw = JSON.stringify(input);
25
- } catch {
26
- raw = String(input);
27
- }
28
- }
29
- const oneLine = raw.replace(/\s+/g, " ").trim();
30
- return oneLine.length > maxChars ? oneLine.slice(0, maxChars) + "…" : oneLine;
31
- }
32
-
33
- /** 工具结果单行摘要(成功/失败各取首行) */
34
- export function summarizeToolResult(content: unknown, maxChars = 120): string {
35
- let raw: string;
36
- if (typeof content === "string") {
37
- raw = content;
38
- } else if (content instanceof Error) {
39
- raw = content.message;
40
- } else {
41
- try {
42
- raw = JSON.stringify(content);
43
- } catch {
44
- raw = String(content);
45
- }
46
- }
47
- const firstLine = raw.split("\n")[0] ?? "";
48
- return firstLine.length > maxChars ? firstLine.slice(0, maxChars) + "…" : firstLine;
49
- }
50
-
51
- /**
52
- * 把一条 ChatEvent 合并进 ProgressView,返回新视图(不可变更新)。
53
- * 未识别的/不影响展示的事件(如 compact)返回原视图。
54
- */
55
- export function reduceProgress(prev: ProgressView, event: ChatEvent): ProgressView {
56
- switch (event.type) {
57
- case "status":
58
- return withProgressView(prev, {
59
- headerTitle: event.phase === "compacting" ? "压缩上下文中..." : "生成回复中...",
60
- });
61
-
62
- case "text":
63
- // accumulated 是全文累积,直接全量替换,天然幂等
64
- return withProgressView(prev, { text: event.accumulated });
65
-
66
- case "tool_use": {
67
- const tool: ProgressToolCall = {
68
- id: event.id ?? `tool-${prev.tools.length + 1}`,
69
- name: event.name,
70
- status: "running",
71
- detail: summarizeToolInput(event.input),
72
- };
73
- return withProgressView(prev, { tools: [...prev.tools, tool] });
74
- }
75
-
76
- case "tool_result": {
77
- const nextStatus = event.is_error ? ("error" as const) : ("ok" as const);
78
- const summary = summarizeToolResult(event.content);
79
- let matched = false;
80
- const tools = prev.tools.map((t) => {
81
- if (matched || t.id !== event.tool_use_id) return t;
82
- matched = true;
83
- return { ...t, status: nextStatus, summary };
84
- });
85
- if (!matched) {
86
- // id 缺失或失配:兜底更新最后一个 running 工具,避免状态悬挂
87
- const lastRunning = [...prev.tools].reverse().findIndex((t) => t.status === "running");
88
- if (lastRunning >= 0) {
89
- const idx = prev.tools.length - 1 - lastRunning;
90
- const updated = prev.tools.map((t, i) =>
91
- i === idx ? { ...t, status: nextStatus, summary } : t,
92
- );
93
- return withProgressView(prev, { tools: updated });
94
- }
95
- }
96
- return withProgressView(prev, { tools });
97
- }
98
-
99
- case "done":
100
- return withProgressView(prev, {
101
- status: "done",
102
- showStop: false,
103
- text: event.text,
104
- });
105
-
106
- case "error":
107
- return withProgressView(prev, { status: "error", showStop: false });
108
-
109
- case "compact":
110
- // 旧上下文压缩不影响当前过程展示
111
- return prev;
112
- }
113
- }
@@ -1,294 +0,0 @@
1
- /**
2
- * progress/terminal-renderer.ts — 终端"过程区块"渲染器
3
- *
4
- * 把 ProgressView 渲染为终端里的一块固定区域(对应飞书过程卡片):
5
- * - 状态行:生成中 / 完成 / 已停止 / 异常结束
6
- * - 工具行:每个工具调用一行(emoji + 名称 + ✓/✗ + 摘要),不再滚屏刷 JSON
7
- * - 正文行:模型流式输出,原地更新不滚动
8
- *
9
- * 实现要点:
10
- * - 隐藏光标(\x1b[?25l)→ 每帧整块重绘(\x1b[{n}A 上移 + \x1b[2K 清行 + \x1b[J 清下方)
11
- * - 帧节流合并重绘,避免高频文本增量导致闪烁
12
- * - 每行按显示宽度截断(CJK/emoji 算 2 列),保证永不折行:一旦折行,
13
- * 实际占用的屏幕行数会超过 blockLines 计数,下次重绘上移行数不足,
14
- * 会清掉区块上方的历史内容(用户输入的问题被"吃掉")。
15
- * - end() 时把终态区块定型留在屏幕上(与飞书完成卡片留在消息流语义一致),恢复光标
16
- */
17
-
18
- import { getToolEmoji, truncateContent } from "../cards.ts";
19
- import { progressView, type ProgressToolCall, type ProgressView } from "./view.ts";
20
-
21
- const RESET = "\x1b[0m";
22
- const DIM = "\x1b[2m";
23
- const BOLD = "\x1b[1m";
24
- const GREEN = "\x1b[32m";
25
- const YELLOW = "\x1b[33m";
26
- const RED = "\x1b[31m";
27
-
28
- const HIDE_CURSOR = "\x1b[?25l";
29
- const SHOW_CURSOR = "\x1b[?25h";
30
-
31
- /** 生成中标题后的心跳点号动画帧(1 → 2 → 3 → 2 循环,避免跳变感) */
32
- const ANIM_FRAMES = ["·", "··", "···", "··"];
33
-
34
- const ANSI_TOKEN = /\x1b\[[0-9;]*m/;
35
-
36
- /** 单个字符在终端里的显示列宽:CJK/emoji 占 2 列,控制符/ZWJ/变体选择符占 0 列 */
37
- export function charWidth(ch: string): number {
38
- const code = ch.codePointAt(0)!;
39
- if (code < 32 || (code >= 0x7f && code <= 0xa0)) return 0; // 控制字符
40
- if (code === 0x200d || code === 0xfe0e || code === 0xfe0f) return 0; // ZWJ / VS15 / VS16
41
- if (
42
- (code >= 0x1100 && code <= 0x115f) || // 谚文 Jamo
43
- (code >= 0x2e80 && code <= 0x303f) || // CJK 部首 / 标点
44
- (code >= 0x3040 && code <= 0xa4cf) || // 假名 / 汉字 / 谚文 / 彝文
45
- (code >= 0xac00 && code <= 0xd7a3) || // 谚文音节
46
- (code >= 0xf900 && code <= 0xfaff) || // CJK 兼容汉字
47
- (code >= 0xfe30 && code <= 0xfe6f) || // CJK 兼容形式
48
- (code >= 0xff00 && code <= 0xff60) || // 全角形式
49
- (code >= 0xffe0 && code <= 0xffe6) || // 全角符号
50
- (code >= 0x2600 && code <= 0x27bf) || // 杂项符号 + Dingbats(emoji 呈现 2 列)
51
- (code >= 0x1f000 && code <= 0x1faff) // emoji 补充区
52
- ) {
53
- return 2;
54
- }
55
- return 1;
56
- }
57
-
58
- /**
59
- * 按终端显示宽度截断一行(CJK/emoji 计 2 列),ANSI 序列零宽且永不截断。
60
- * 截断位置若处于未闭合的颜色状态,自动补 \x1b[0m,避免颜色泄漏到后续输出。
61
- */
62
- export function clipToWidth(s: string, maxCols: number): string {
63
- if (maxCols <= 0) return "";
64
- let out = "";
65
- let visible = 0;
66
- let colorOpen = false;
67
- let i = 0;
68
- while (i < s.length) {
69
- if (s.charCodeAt(i) === 0x1b) {
70
- const m = ANSI_TOKEN.exec(s.slice(i));
71
- if (m && m.index === 0) {
72
- out += m[0];
73
- colorOpen = m[0] !== "\x1b[0m";
74
- i += m[0].length;
75
- continue;
76
- }
77
- }
78
- const cp = s.codePointAt(i)!;
79
- const ch = String.fromCodePoint(cp);
80
- const w = charWidth(ch);
81
- if (visible + w > maxCols) break;
82
- out += ch;
83
- visible += w;
84
- i += ch.length;
85
- }
86
- if (colorOpen) out += "\x1b[0m";
87
- return out;
88
- }
89
-
90
- export interface TerminalRendererOptions {
91
- /** 输出流,默认 process.stdout */
92
- out?: NodeJS.WritableStream & { columns?: number };
93
- /** 帧节流毫秒数,默认 66(约 15fps) */
94
- frameMs?: number;
95
- /** 生成中心跳动画毫秒数,默认 300;<=0 禁用动画 */
96
- animMs?: number;
97
- /** 正文最大行数(超出截断,保留首行+末段) */
98
- maxBodyLines?: number;
99
- /** 正文最大字符数 */
100
- maxBodyChars?: number;
101
- }
102
-
103
- function buildStatusLine(view: ProgressView): string {
104
- switch (view.status) {
105
- case "done":
106
- return `${BOLD}${GREEN}✅ 完成${RESET}`;
107
- case "stopped":
108
- return `${YELLOW}⏹ 已停止${RESET}`;
109
- case "error":
110
- return `${RED}❌ 异常结束${RESET}`;
111
- case "generating": {
112
- const hint = view.showStop ? `${DIM} · Ctrl+C 停止${RESET}` : "";
113
- return `⏳ ${view.headerTitle}${hint}`;
114
- }
115
- }
116
- }
117
-
118
- function buildToolLine(tool: ProgressToolCall): string {
119
- const emoji = getToolEmoji(tool.name);
120
- const mark =
121
- tool.status === "running"
122
- ? "…"
123
- : tool.status === "ok"
124
- ? `${GREEN}✓${RESET}`
125
- : `${RED}✗${RESET}`;
126
- const info = tool.status === "running" ? (tool.detail ?? "") : (tool.summary ?? "");
127
- // 摘要/详情用正常色:最终区块里不出现浅色文字(可读性优先)
128
- return ` ${emoji} ${tool.name} ${mark} ${info}`;
129
- }
130
-
131
- /**
132
- * 把 ProgressView 展开为区块的完整行列表(不含 ANSI 定位序列,只含内容与颜色)。
133
- * 单独导出便于单元测试;每行按终端宽度截断,避免长行折行导致行数计数失准。
134
- */
135
- export function buildBlockLines(
136
- view: ProgressView,
137
- width: number,
138
- maxBodyLines = 30,
139
- maxBodyChars = 12000,
140
- ): string[] {
141
- const clip = (s: string) => clipToWidth(s, width);
142
- const lines: string[] = [];
143
- lines.push(clip(buildStatusLine(view)));
144
- for (const tool of view.tools) {
145
- lines.push(clip(buildToolLine(tool)));
146
- }
147
- const body = truncateContent(view.text, maxBodyLines, maxBodyChars);
148
- if (body.trim()) {
149
- for (const line of body.split("\n")) {
150
- lines.push(clip(line));
151
- }
152
- } else {
153
- lines.push(`${DIM}等待 Agent 输出...${RESET}`);
154
- }
155
- return lines;
156
- }
157
-
158
- export class TerminalProgressRenderer {
159
- private readonly out: NodeJS.WritableStream & { columns?: number };
160
- private readonly frameMs: number;
161
- private readonly animMs: number;
162
- private readonly maxBodyLines: number;
163
- private readonly maxBodyChars: number;
164
- private view: ProgressView;
165
- private blockLines = 0;
166
- private dirty = false;
167
- private timer: NodeJS.Timeout | null = null;
168
- private ended = false;
169
- private animFrame = 0;
170
- private animTimer: NodeJS.Timeout | null = null;
171
-
172
- constructor(opts: TerminalRendererOptions = {}) {
173
- this.out = opts.out ?? process.stdout;
174
- this.frameMs = opts.frameMs ?? 66;
175
- this.animMs = opts.animMs ?? 300;
176
- this.maxBodyLines = opts.maxBodyLines ?? 30;
177
- this.maxBodyChars = opts.maxBodyChars ?? 12000;
178
- this.view = progressView();
179
- }
180
-
181
- /** 开始一轮区块:隐藏光标并渲染首帧,随后启动生成中心跳动画 */
182
- begin(view: ProgressView): void {
183
- this.view = view;
184
- this.out.write(HIDE_CURSOR);
185
- this.renderNow(view);
186
- this.startAnimation();
187
- }
188
-
189
- /** 标记视图已更新,按帧节流合并重绘(高频增量不闪烁) */
190
- render(view: ProgressView): void {
191
- this.view = view;
192
- if (this.ended) return;
193
- this.dirty = true;
194
- if (this.timer) return;
195
- this.timer = setTimeout(() => {
196
- this.timer = null;
197
- if (this.dirty && !this.ended) {
198
- this.dirty = false;
199
- this.renderNow(this.view);
200
- }
201
- }, this.frameMs);
202
- }
203
-
204
- /** 强制立即重绘(工具结果、终态等低频率但需及时反馈的事件) */
205
- flush(): void {
206
- if (this.timer) {
207
- clearTimeout(this.timer);
208
- this.timer = null;
209
- }
210
- if (this.ended) return;
211
- this.dirty = false;
212
- this.renderNow(this.view);
213
- }
214
-
215
- /** 结束一轮:定型终态区块(留在屏幕上),恢复光标,停止动画 */
216
- end(view: ProgressView): void {
217
- if (this.timer) {
218
- clearTimeout(this.timer);
219
- this.timer = null;
220
- }
221
- this.stopAnimation();
222
- this.ended = true;
223
- this.renderNow(view);
224
- this.out.write(SHOW_CURSOR);
225
- }
226
-
227
- /** 兜底清理:清除未决定时器并恢复光标 */
228
- dispose(): void {
229
- if (this.timer) {
230
- clearTimeout(this.timer);
231
- this.timer = null;
232
- }
233
- this.stopAnimation();
234
- if (!this.ended) {
235
- this.out.write(SHOW_CURSOR);
236
- }
237
- }
238
-
239
- private startAnimation(): void {
240
- if (this.animMs <= 0 || this.animTimer) return;
241
- this.animTimer = setInterval(() => {
242
- this.animFrame++;
243
- // 终态(done/stopped/error)由 end() 停止;此处兜底跳过,避免结束后还在重绘
244
- if (this.ended || this.view.status !== "generating") return;
245
- // 无新事件也持续重绘,点号动画让静止期(思考/工具运行中)也有动态感
246
- this.renderNow(this.view);
247
- }, this.animMs);
248
- this.animTimer.unref?.();
249
- }
250
-
251
- private stopAnimation(): void {
252
- if (this.animTimer) {
253
- clearInterval(this.animTimer);
254
- this.animTimer = null;
255
- }
256
- }
257
-
258
- private renderNow(view: ProgressView): void {
259
- const width = this.out.columns && this.out.columns > 0 ? this.out.columns : 80;
260
- const lines = buildBlockLines(this.applyAnimation(view), width, this.maxBodyLines, this.maxBodyChars);
261
- const newLines = lines.length;
262
-
263
- if (this.blockLines > 0) {
264
- // 关键:光标此刻停在区块【最后一行】行尾,回到区块第一行只需上移
265
- // blockLines - 1 行。上移 blockLines 行会每帧多上移 1 行,把区块上方
266
- // 的历史内容逐行"吃掉"(用户看到的"一行一行往上吃")。
267
- this.out.write(`\x1b[${this.blockLines - 1}A`);
268
- this.out.write("\r");
269
- }
270
- for (let i = 0; i < lines.length; i++) {
271
- this.out.write(`\r\x1b[2K${lines[i]}`);
272
- if (i < lines.length - 1) {
273
- this.out.write("\n");
274
- }
275
- }
276
- if (newLines < this.blockLines) {
277
- // 新区块比旧区块短:清掉下方多出的行
278
- this.out.write("\n");
279
- for (let i = 0; i < this.blockLines - newLines; i++) {
280
- this.out.write("\x1b[2K\n");
281
- }
282
- }
283
- this.out.write("\x1b[J");
284
- this.blockLines = newLines;
285
- }
286
-
287
- /** 生成中阶段在标题后叠加心跳点号动画;终态原样返回(buildBlockLines 保持纯函数可测) */
288
- private applyAnimation(view: ProgressView): ProgressView {
289
- if (view.status !== "generating") return view;
290
- const base = view.headerTitle.replace(/\.\.\.\s*$/, "").trim();
291
- const dots = ANIM_FRAMES[this.animFrame % ANIM_FRAMES.length];
292
- return { ...view, headerTitle: `${base} ${dots}` };
293
- }
294
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * progress/view.ts — 平台无关的"过程进度"视图模型
3
- *
4
- * 这是飞书过程卡片与终端过程区块共享的唯一数据模型:
5
- * - 飞书:buildProgressCard(view) 把 ProgressView 渲染为卡片 JSON
6
- * - 终端:TerminalProgressRenderer 把 ProgressView 渲染为 ANSI 区块
7
- * - 事件流:reduceProgress(prev, event) 把 ChatEvent 增量合并进 ProgressView
8
- *
9
- * 语义与飞书卡片对齐:
10
- * - headerTitle 是"生成中"阶段展示的标题(如"正在启动 Agent · 0秒")
11
- * - status 决定终态外观(完成 / 已停止 / 异常结束)
12
- * - text 是正文累积(对应卡片 main_content / 终端区块正文)
13
- * - tools 是本轮工具调用列表(飞书卡片暂不展示,终端折叠为单行)
14
- */
15
-
16
- export type ProgressStatus = "generating" | "done" | "stopped" | "error";
17
-
18
- export type ProgressToolStatus = "running" | "ok" | "error";
19
-
20
- export interface ProgressToolCall {
21
- /** 工具调用 ID(ChatEvent.tool_use.id,可能缺失) */
22
- id: string;
23
- /** 工具名,如 edit_file */
24
- name: string;
25
- status: ProgressToolStatus;
26
- /** 工具输入摘要(终端折叠行展示,截断保存) */
27
- detail?: string;
28
- /** 工具结果摘要(成功/失败,截断保存) */
29
- summary?: string;
30
- }
31
-
32
- export interface ProgressView {
33
- /** 当前阶段状态,决定终态外观 */
34
- status: ProgressStatus;
35
- /** 生成中阶段的头部标题(对应飞书卡片 header title) */
36
- headerTitle: string;
37
- /** 卡片头部颜色模板(飞书用),终端忽略 */
38
- headerTemplate: string;
39
- /** 正文累积内容 */
40
- text: string;
41
- /** 本轮工具调用列表 */
42
- tools: ProgressToolCall[];
43
- /** 是否展示停止按钮 / 停止提示 */
44
- showStop: boolean;
45
- /** 最近一次更新时间戳 */
46
- updatedAt: number;
47
- }
48
-
49
- export interface ProgressViewInit {
50
- status?: ProgressStatus;
51
- headerTitle?: string;
52
- headerTemplate?: string;
53
- text?: string;
54
- tools?: ProgressToolCall[];
55
- showStop?: boolean;
56
- }
57
-
58
- /** 创建 ProgressView,未提供的字段使用与飞书 buildProgressCard 一致的默认值 */
59
- export function progressView(init: ProgressViewInit = {}): ProgressView {
60
- return {
61
- status: init.status ?? "generating",
62
- headerTitle: init.headerTitle ?? "生成中...",
63
- headerTemplate: init.headerTemplate ?? "blue",
64
- text: init.text ?? "",
65
- tools: init.tools ?? [],
66
- showStop: init.showStop ?? true,
67
- updatedAt: Date.now(),
68
- };
69
- }
70
-
71
- /** 只读浅拷贝并覆盖部分字段,返回新视图(reducer 的不可变更新用) */
72
- export function withProgressView(
73
- prev: ProgressView,
74
- patch: Partial<ProgressView>,
75
- ): ProgressView {
76
- return { ...prev, ...patch, updatedAt: Date.now() };
77
- }