chatccc 0.2.251 → 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 (277) 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/package.json +1 -1
  5. package/dist/deepccc-agent/src/cli.js +634 -0
  6. package/dist/deepccc-agent/src/config.js +76 -0
  7. package/dist/deepccc-agent/src/context.js +348 -0
  8. package/dist/deepccc-agent/src/file-log.js +34 -0
  9. package/dist/deepccc-agent/src/file-tools.js +1208 -0
  10. package/dist/deepccc-agent/src/index.js +571 -0
  11. package/dist/deepccc-agent/src/permissions.js +170 -0
  12. package/dist/deepccc-agent/src/privacy.js +124 -0
  13. package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
  14. package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
  15. package/dist/deepccc-agent/src/progress/reducer.js +102 -0
  16. package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
  17. package/dist/deepccc-agent/src/progress/view.js +30 -0
  18. package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
  19. package/dist/deepccc-agent/src/session-search.js +276 -0
  20. package/dist/deepccc-agent/src/session-select.js +23 -0
  21. package/dist/deepccc-agent/src/sigint.js +26 -0
  22. package/dist/deepccc-agent/src/skills.js +178 -0
  23. package/dist/deepccc-agent/src/web-tools.js +246 -0
  24. package/dist/src/adapters/adapter-interface.js +19 -0
  25. package/dist/src/adapters/ccc-adapter.js +112 -0
  26. package/dist/src/adapters/claude-adapter.js +497 -0
  27. package/dist/src/adapters/claude-session-meta-store.js +92 -0
  28. package/dist/src/adapters/codex-adapter.js +279 -0
  29. package/dist/src/adapters/codex-session-meta-store.js +94 -0
  30. package/dist/src/adapters/cursor-adapter.js +491 -0
  31. package/dist/src/adapters/cursor-session-meta-store.js +116 -0
  32. package/dist/src/adapters/jsonl-stream.js +104 -0
  33. package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
  34. package/dist/src/adapters/raw-stream-log.js +106 -0
  35. package/dist/src/adapters/resource-monitor.js +113 -0
  36. package/dist/src/agent-activity.js +133 -0
  37. package/dist/src/agent-delegate-task-rpc.js +129 -0
  38. package/dist/src/agent-delegate-task.js +48 -0
  39. package/dist/src/agent-file-rpc.js +152 -0
  40. package/dist/src/agent-image-rpc.js +148 -0
  41. package/dist/src/agent-platform-routing.js +13 -0
  42. package/dist/src/agent-reload-config-rpc.js +23 -0
  43. package/dist/src/agent-rpc-body.js +87 -0
  44. package/dist/src/agent-stop-stuck.js +110 -0
  45. package/dist/src/card-action-routing.js +7 -0
  46. package/dist/src/card-plain-text.js +101 -0
  47. package/dist/src/cardkit.js +158 -0
  48. package/dist/src/cards.js +573 -0
  49. package/dist/src/chatgpt-subscription-rpc.js +18 -0
  50. package/dist/src/chatgpt-subscription.js +199 -0
  51. package/dist/src/chrome-devtools-guard.js +238 -0
  52. package/dist/src/claude-sdk-installer.js +249 -0
  53. package/dist/src/codex-reset-actions.js +143 -0
  54. package/dist/src/config-utils.js +149 -0
  55. package/dist/src/config.js +804 -0
  56. package/dist/src/cursor-usage.js +77 -0
  57. package/dist/src/exit-banner.js +28 -0
  58. package/dist/src/feishu-api.js +1404 -0
  59. package/dist/src/feishu-message-ingress.js +137 -0
  60. package/dist/src/feishu-platform.js +97 -0
  61. package/dist/src/format-message.js +252 -0
  62. package/dist/src/git-command.js +155 -0
  63. package/dist/src/im-skills.js +121 -0
  64. package/dist/src/index.js +833 -0
  65. package/dist/src/litellm-proxy.js +300 -0
  66. package/dist/src/orchestrator.js +2078 -0
  67. package/dist/src/package-root.js +26 -0
  68. package/dist/src/platform-adapter.js +7 -0
  69. package/dist/src/platform-startup.js +6 -0
  70. package/dist/src/privacy.js +100 -0
  71. package/dist/src/progress/reducer.js +102 -0
  72. package/dist/src/progress/terminal-renderer.js +264 -0
  73. package/dist/src/progress/view.js +30 -0
  74. package/dist/src/response-stall.js +14 -0
  75. package/dist/src/runtime-entry.js +13 -0
  76. package/dist/src/runtime-reload.js +19 -0
  77. package/dist/src/session-chat-binding.js +183 -0
  78. package/dist/src/session-name.js +7 -0
  79. package/dist/src/session.js +2144 -0
  80. package/dist/src/shared-prefix.js +16 -0
  81. package/dist/src/shared.js +493 -0
  82. package/dist/src/sim-agent.js +105 -0
  83. package/dist/src/sim-platform.js +142 -0
  84. package/dist/src/sim-store.js +231 -0
  85. package/dist/src/simplify.js +99 -0
  86. package/dist/src/startup-lifecycle.js +209 -0
  87. package/dist/src/stream-state.js +141 -0
  88. package/dist/src/terminal-error.js +100 -0
  89. package/dist/src/trace.js +50 -0
  90. package/dist/src/turn-cards.js +92 -0
  91. package/dist/src/update-command-guard.js +114 -0
  92. package/{src/web-ui.ts → dist/src/web-ui.js} +749 -823
  93. package/dist/src/wechat-platform.js +545 -0
  94. package/package.json +7 -5
  95. package/deepccc-agent/LICENSE +0 -201
  96. package/deepccc-agent/bin/deepccc.mjs +0 -26
  97. package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
  98. package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
  99. package/deepccc-agent/package-lock.json +0 -2027
  100. package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -852
  101. package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
  102. package/deepccc-agent/src/__tests__/config.test.ts +0 -34
  103. package/deepccc-agent/src/__tests__/context.test.ts +0 -341
  104. package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
  105. package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
  106. package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
  107. package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
  108. package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
  109. package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
  110. package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
  111. package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
  112. package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
  113. package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
  114. package/deepccc-agent/src/cli.ts +0 -682
  115. package/deepccc-agent/src/config.ts +0 -101
  116. package/deepccc-agent/src/context.ts +0 -465
  117. package/deepccc-agent/src/file-log.ts +0 -38
  118. package/deepccc-agent/src/file-tools.ts +0 -1493
  119. package/deepccc-agent/src/index.ts +0 -676
  120. package/deepccc-agent/src/permissions.ts +0 -226
  121. package/deepccc-agent/src/privacy.ts +0 -141
  122. package/deepccc-agent/src/proc-tree-kill.ts +0 -61
  123. package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
  124. package/deepccc-agent/src/progress/reducer.ts +0 -113
  125. package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
  126. package/deepccc-agent/src/progress/view.ts +0 -77
  127. package/deepccc-agent/src/raw-stream-log.ts +0 -124
  128. package/deepccc-agent/src/session-search.ts +0 -370
  129. package/deepccc-agent/src/session-select.ts +0 -48
  130. package/deepccc-agent/src/sigint.ts +0 -50
  131. package/deepccc-agent/src/skills.ts +0 -205
  132. package/deepccc-agent/src/web-tools.ts +0 -313
  133. package/deepccc-agent/tsconfig.build.json +0 -13
  134. package/deepccc-agent/tsconfig.json +0 -13
  135. package/deepccc-agent/vitest.config.ts +0 -7
  136. package/src/__tests__/adapter-interface.test.ts +0 -152
  137. package/src/__tests__/agent-activity.test.ts +0 -86
  138. package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
  139. package/src/__tests__/agent-image-rpc.test.ts +0 -34
  140. package/src/__tests__/agent-platform-routing.test.ts +0 -26
  141. package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
  142. package/src/__tests__/agent-rpc-body.test.ts +0 -42
  143. package/src/__tests__/builtin-chat-session.test.ts +0 -532
  144. package/src/__tests__/builtin-cli-json.test.ts +0 -39
  145. package/src/__tests__/builtin-config.test.ts +0 -26
  146. package/src/__tests__/builtin-context.test.ts +0 -319
  147. package/src/__tests__/builtin-file-tools.test.ts +0 -240
  148. package/src/__tests__/builtin-permissions.test.ts +0 -219
  149. package/src/__tests__/builtin-session-search.test.ts +0 -262
  150. package/src/__tests__/builtin-session-select.test.ts +0 -116
  151. package/src/__tests__/builtin-sigint.test.ts +0 -56
  152. package/src/__tests__/builtin-skills.test.ts +0 -284
  153. package/src/__tests__/builtin-web-tools.test.ts +0 -220
  154. package/src/__tests__/card-action-routing.test.ts +0 -18
  155. package/src/__tests__/card-plain-text.test.ts +0 -45
  156. package/src/__tests__/cardkit.test.ts +0 -60
  157. package/src/__tests__/cards.test.ts +0 -607
  158. package/src/__tests__/ccc-adapter.test.ts +0 -194
  159. package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
  160. package/src/__tests__/chatgpt-subscription.test.ts +0 -135
  161. package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
  162. package/src/__tests__/claude-adapter.test.ts +0 -614
  163. package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
  164. package/src/__tests__/claude-sdk-installer.test.ts +0 -285
  165. package/src/__tests__/codex-adapter.test.ts +0 -331
  166. package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
  167. package/src/__tests__/codex-reset-actions.test.ts +0 -146
  168. package/src/__tests__/config-reload.test.ts +0 -284
  169. package/src/__tests__/config-sample.test.ts +0 -97
  170. package/src/__tests__/config-utils.test.ts +0 -40
  171. package/src/__tests__/config.test.ts +0 -395
  172. package/src/__tests__/crash-logging.test.ts +0 -360
  173. package/src/__tests__/cursor-adapter.test.ts +0 -890
  174. package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
  175. package/src/__tests__/feishu-api.test.ts +0 -60
  176. package/src/__tests__/feishu-avatar.test.ts +0 -504
  177. package/src/__tests__/feishu-message-ingress.test.ts +0 -138
  178. package/src/__tests__/feishu-platform.test.ts +0 -75
  179. package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
  180. package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
  181. package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
  182. package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
  183. package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
  184. package/src/__tests__/format-message.test.ts +0 -316
  185. package/src/__tests__/git-command.test.ts +0 -288
  186. package/src/__tests__/im-skills.test.ts +0 -125
  187. package/src/__tests__/jsonl-stream.test.ts +0 -79
  188. package/src/__tests__/orchestrator.test.ts +0 -1268
  189. package/src/__tests__/package-files.test.ts +0 -24
  190. package/src/__tests__/platform-startup.test.ts +0 -19
  191. package/src/__tests__/privacy.test.ts +0 -198
  192. package/src/__tests__/proc-tree-kill.test.ts +0 -108
  193. package/src/__tests__/progress-reducer.test.ts +0 -121
  194. package/src/__tests__/raw-stream-log.test.ts +0 -106
  195. package/src/__tests__/response-stall.test.ts +0 -49
  196. package/src/__tests__/restart.test.ts +0 -232
  197. package/src/__tests__/session-ccc-config.test.ts +0 -66
  198. package/src/__tests__/session.test.ts +0 -3004
  199. package/src/__tests__/shared-prefix.test.ts +0 -36
  200. package/src/__tests__/sim-agent.test.ts +0 -174
  201. package/src/__tests__/sim-platform.test.ts +0 -93
  202. package/src/__tests__/sim-store.test.ts +0 -214
  203. package/src/__tests__/simplify.test.ts +0 -283
  204. package/src/__tests__/startup-lifecycle.test.ts +0 -231
  205. package/src/__tests__/stop-session.test.ts +0 -162
  206. package/src/__tests__/stream-state.test.ts +0 -164
  207. package/src/__tests__/terminal-error.test.ts +0 -54
  208. package/src/__tests__/terminal-renderer.test.ts +0 -247
  209. package/src/__tests__/update-command-guard.test.ts +0 -144
  210. package/src/__tests__/web-ui.test.ts +0 -438
  211. package/src/__tests__/wechat-platform.test.ts +0 -111
  212. package/src/adapters/adapter-interface.ts +0 -217
  213. package/src/adapters/ccc-adapter.ts +0 -150
  214. package/src/adapters/claude-adapter.ts +0 -673
  215. package/src/adapters/claude-session-meta-store.ts +0 -120
  216. package/src/adapters/codex-adapter.ts +0 -426
  217. package/src/adapters/codex-session-meta-store.ts +0 -131
  218. package/src/adapters/cursor-adapter.ts +0 -681
  219. package/src/adapters/cursor-session-meta-store.ts +0 -154
  220. package/src/adapters/jsonl-stream.ts +0 -157
  221. package/src/adapters/raw-stream-log.ts +0 -124
  222. package/src/adapters/resource-monitor.ts +0 -141
  223. package/src/agent-activity.ts +0 -175
  224. package/src/agent-delegate-task-rpc.ts +0 -153
  225. package/src/agent-delegate-task.ts +0 -91
  226. package/src/agent-file-rpc.ts +0 -172
  227. package/src/agent-image-rpc.ts +0 -168
  228. package/src/agent-platform-routing.ts +0 -28
  229. package/src/agent-reload-config-rpc.ts +0 -34
  230. package/src/agent-rpc-body.ts +0 -92
  231. package/src/agent-stop-stuck.ts +0 -129
  232. package/src/card-action-routing.ts +0 -14
  233. package/src/card-plain-text.ts +0 -108
  234. package/src/cardkit.ts +0 -179
  235. package/src/cards.ts +0 -684
  236. package/src/chatgpt-subscription-rpc.ts +0 -27
  237. package/src/chatgpt-subscription.ts +0 -299
  238. package/src/chrome-devtools-guard.ts +0 -318
  239. package/src/claude-sdk-installer.ts +0 -324
  240. package/src/codex-reset-actions.ts +0 -184
  241. package/src/config-utils.ts +0 -211
  242. package/src/config.ts +0 -1063
  243. package/src/cursor-usage.ts +0 -128
  244. package/src/exit-banner.ts +0 -33
  245. package/src/feishu-api.ts +0 -1616
  246. package/src/feishu-message-ingress.ts +0 -195
  247. package/src/feishu-platform.ts +0 -159
  248. package/src/format-message.ts +0 -293
  249. package/src/git-command.ts +0 -202
  250. package/src/im-skills.ts +0 -149
  251. package/src/index.ts +0 -1089
  252. package/src/litellm-proxy.ts +0 -374
  253. package/src/orchestrator.ts +0 -2543
  254. package/src/platform-adapter.ts +0 -70
  255. package/src/platform-startup.ts +0 -16
  256. package/src/privacy.ts +0 -118
  257. package/src/progress/reducer.ts +0 -113
  258. package/src/progress/terminal-renderer.ts +0 -294
  259. package/src/progress/view.ts +0 -77
  260. package/src/response-stall.ts +0 -28
  261. package/src/runtime-reload.ts +0 -34
  262. package/src/session-chat-binding.ts +0 -292
  263. package/src/session-name.ts +0 -8
  264. package/src/session.ts +0 -2659
  265. package/src/shared-prefix.ts +0 -29
  266. package/src/shared.ts +0 -552
  267. package/src/sim-agent.ts +0 -167
  268. package/src/sim-platform.ts +0 -177
  269. package/src/sim-store.ts +0 -317
  270. package/src/simplify.ts +0 -120
  271. package/src/startup-lifecycle.ts +0 -250
  272. package/src/stream-state.ts +0 -177
  273. package/src/terminal-error.ts +0 -129
  274. package/src/trace.ts +0 -51
  275. package/src/turn-cards.ts +0 -118
  276. package/src/update-command-guard.ts +0 -165
  277. package/src/wechat-platform.ts +0 -680
@@ -1,211 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // 纯函数/常量工具集
3
- //
4
- // 这些工具与 fs / 进程状态完全无关(CLI 路径探测函数虽然要查文件/PATH,但所有
5
- // I/O 通过参数注入,函数本身仍然是纯函数,可被单测无副作用地调用)。
6
- // 其它生产代码应优先从 `./config.ts` 引用(`config.ts` 会 re-export 这里的符号),
7
- // 仅在需要避免触发 config.ts 副作用的场景(如单测)才直接 import 本文件。
8
- // ---------------------------------------------------------------------------
9
-
10
- import { join } from "node:path";
11
-
12
- /**
13
- * 把 model / effort 等"可选向 SDK/CLI 透传"的字段标准化为字符串。
14
- *
15
- * 项目内部统一约定:`""`(空字符串/全空白)表示**不向 SDK/CLI 传该字段**。
16
- * 旧版本曾使用字面量 `"default"` 表达同样的意思,本函数兼容性地把它视作 `""`,
17
- * 并在每次启动时打印一次 warning,提示用户更新 config.json。
18
- *
19
- * - `value` 不是字符串(例如 undefined / 缺失)→ 使用 `fallback`(默认 `""`)。
20
- * - `value` 去除空白后等于 `"default"`(不区分大小写)→ 视作 `""` 并 warn。
21
- * - 其余情况原样返回(不裁剪两端空白,留给具体调用方决定)。
22
- */
23
- export function normalizeOptionalConfigField(
24
- value: unknown,
25
- options: { label: string; fallback?: string },
26
- ): string {
27
- const fallback = options.fallback ?? "";
28
- if (typeof value !== "string") return fallback;
29
- const trimmed = value.trim();
30
- if (trimmed.toLowerCase() === "default") {
31
- console.warn(
32
- `[CONFIG] ${options.label} 的值 "${trimmed}" 已废弃,请改为 ""(空字符串)表示不向 SDK/CLI 传该字段;本次启动按 "" 处理。`,
33
- );
34
- return "";
35
- }
36
- return value;
37
- }
38
-
39
- /**
40
- * ccc.provider 的合法取值:空字符串表示不 override(跟随 DeepCCC 内核配置),
41
- * 或者显式指定 openai / anthropic 两种协议之一。
42
- */
43
- export type CccProviderOverride = "" | "openai" | "anthropic";
44
-
45
- /**
46
- * 归一化 `ccc.provider`(ChatCCC 主进程配置对 DeepCCC 内核传输层的 override):
47
- * - 非字符串 / 空串 / 字面量 "default" → `""`(不 override,跟随
48
- * ~/.deepccc/config.json 或 DEEPCCC_PROVIDER,向后兼容旧 config.json)
49
- * - `openai` / `anthropic`(大小写不敏感)→ 规范化小写返回
50
- * - 其它非法值 → `""` 并打印 warning(避免运行时 normalizeDeepCccProvider 抛错)
51
- */
52
- export function normalizeCccProviderOverride(value: unknown): CccProviderOverride {
53
- if (typeof value !== "string") return "";
54
- const trimmed = value.trim().toLowerCase();
55
- if (trimmed === "" || trimmed === "default") return "";
56
- if (trimmed === "openai" || trimmed === "anthropic") return trimmed;
57
- console.warn(
58
- `[CONFIG] ccc.provider 的值 "${value}" 非法,已忽略(仅支持 openai / anthropic / 空字符串)。`,
59
- );
60
- return "";
61
- }
62
-
63
- /**
64
- * CCC Agent requires credentials owned by ChatCCC. An explicit enabled=true
65
- * must not make the agent selectable when that credential is absent.
66
- */
67
- export function resolveCccEnabled(rawEnabled: unknown, apiKey: unknown): boolean {
68
- const hasApiKey = typeof apiKey === "string" && apiKey.trim().length > 0;
69
- if (!hasApiKey) return false;
70
- return typeof rawEnabled === "boolean" ? rawEnabled : true;
71
- }
72
-
73
- // ---------------------------------------------------------------------------
74
- // /git 超时配置相关
75
- // ---------------------------------------------------------------------------
76
-
77
- /** /git 命令默认超时秒数(用户未配置时使用) */
78
- export const DEFAULT_GIT_TIMEOUT_SECONDS = 180;
79
- /** /git 超时允许的下限/上限(防止 0、负数、过大值导致行为异常) */
80
- export const MIN_GIT_TIMEOUT_SECONDS = 1;
81
- export const MAX_GIT_TIMEOUT_SECONDS = 3600; // 1 小时
82
-
83
- export interface ParsedGitTimeout {
84
- /** 实际使用的超时秒数(无效时回退为 default) */
85
- seconds: number;
86
- /** 用户提供的原始字符串是否为合法整数秒(true 表示采纳了用户值或未提供) */
87
- valid: boolean;
88
- /** 用户原始字符串 */
89
- raw?: string;
90
- /** 是否使用了内置默认值(即用户未提供有效值) */
91
- usingDefault: boolean;
92
- }
93
-
94
- export function parseGitTimeoutSeconds(
95
- raw: string | number | undefined,
96
- defaultSeconds = DEFAULT_GIT_TIMEOUT_SECONDS,
97
- ): ParsedGitTimeout {
98
- if (typeof raw === "number") {
99
- if (
100
- !Number.isFinite(raw) ||
101
- !Number.isInteger(raw) ||
102
- raw < MIN_GIT_TIMEOUT_SECONDS ||
103
- raw > MAX_GIT_TIMEOUT_SECONDS
104
- ) {
105
- return { seconds: defaultSeconds, valid: false, raw: String(raw), usingDefault: true };
106
- }
107
- return { seconds: raw, valid: true, raw: String(raw), usingDefault: false };
108
- }
109
-
110
- const trimmed = raw?.trim();
111
- if (!trimmed) {
112
- return { seconds: defaultSeconds, valid: true, usingDefault: true };
113
- }
114
- const n = Number(trimmed);
115
- if (
116
- !Number.isFinite(n) ||
117
- !Number.isInteger(n) ||
118
- n < MIN_GIT_TIMEOUT_SECONDS ||
119
- n > MAX_GIT_TIMEOUT_SECONDS
120
- ) {
121
- return { seconds: defaultSeconds, valid: false, raw: trimmed, usingDefault: true };
122
- }
123
- return { seconds: n, valid: true, raw: trimmed, usingDefault: false };
124
- }
125
-
126
- /**
127
- * 判断 model / effort 等"可选向 SDK/CLI 透传"的字段是否为"不传值"。
128
- * 项目内部统一以空字符串(含全空白)表示该语义。
129
- */
130
- export function isAnthropicConfigEmpty(value: string): boolean {
131
- return value.trim() === "";
132
- }
133
-
134
- /** 状态展示用:留空时显示 `(留空)`,否则原样返回。 */
135
- export function anthropicConfigDisplay(value: string): string {
136
- return isAnthropicConfigEmpty(value) ? "(留空)" : value;
137
- }
138
-
139
- // ---------------------------------------------------------------------------
140
- // CLI 可执行文件路径探测(依赖 fs/PATH,但通过参数注入保持纯函数特性)
141
- // ---------------------------------------------------------------------------
142
-
143
- export interface PathDetectorDeps {
144
- /** 用于检查文件是否存在的同步函数(生产环境注入 fs.existsSync) */
145
- existsSync: (path: string) => boolean;
146
- /** 通过 `where` (Win) / `which` (Mac/Linux) 解析命令绝对路径,找不到返回 null */
147
- whichSync: (cmd: string) => string | null;
148
- /** process.env.LOCALAPPDATA(Windows 上 Cursor IDE 默认安装根) */
149
- localAppData?: string | undefined;
150
- /** process.platform(用于判定 Windows 默认安装路径是否适用) */
151
- platform: NodeJS.Platform;
152
- }
153
-
154
- /**
155
- * 探测 Cursor Agent CLI 的可执行文件绝对路径。
156
- *
157
- * 优先级(依次尝试,命中即返回):
158
- * 1. Windows + `%LOCALAPPDATA%\cursor-agent\agent.cmd`(Cursor IDE 默认安装位置)
159
- * 2. PATH 中查找 `cursor-agent`(独立 CLI 安装常见名)
160
- * 3. PATH 中查找 `agent`(旧版默认名)
161
- *
162
- * 全部命中失败时返回 `null`,调用方可选择留空让运行时回退到 PATH 兜底。
163
- */
164
- export function autoDetectCursorPath(deps: PathDetectorDeps): string | null {
165
- if (deps.platform === "win32" && deps.localAppData) {
166
- const localPath = join(deps.localAppData, "cursor-agent", "agent.cmd");
167
- if (deps.existsSync(localPath)) return localPath;
168
- }
169
- return deps.whichSync("cursor-agent") ?? deps.whichSync("agent");
170
- }
171
-
172
- /**
173
- * 探测 Codex CLI 的可执行文件绝对路径。
174
- *
175
- * Codex 没有固定安装位置,只通过 PATH 查找 `codex` 命令。
176
- * 找不到时返回 `null`,由调用方决定留空或后续重试。
177
- */
178
- export function autoDetectCodexPath(
179
- deps: Pick<PathDetectorDeps, "whichSync">,
180
- ): string | null {
181
- return deps.whichSync("codex");
182
- }
183
-
184
- // ---------------------------------------------------------------------------
185
- // CLI 路径字段(cursor.path / codex.path)的兼容性读取
186
- // ---------------------------------------------------------------------------
187
-
188
- /**
189
- * 从 raw config 对象中读取 cursor / codex 的 CLI 路径,兼容旧字段名 `command`。
190
- *
191
- * - 优先读 `path`,回退到旧字段 `command`(升级前的 config.json 仍然可用)
192
- * - 回退命中时通过 `onLegacyField` 回调通知调用方(用于打印一次性 warning)
193
- * - 不要在此函数里写文件,迁移交给上层
194
- */
195
- export function readToolCliPath(
196
- raw: { path?: unknown; command?: unknown } | undefined,
197
- options: {
198
- /** 工具标签,仅用于 warning 文案,例如 "cursor" / "codex" */
199
- label: string;
200
- /** 命中旧字段时调用,调用方负责打印或记录 warning */
201
- onLegacyField?: (label: string, legacyValue: string) => void;
202
- },
203
- ): string {
204
- if (!raw) return "";
205
- if (typeof raw.path === "string" && raw.path.trim() !== "") return raw.path;
206
- if (typeof raw.command === "string" && raw.command.trim() !== "") {
207
- options.onLegacyField?.(options.label, raw.command);
208
- return raw.command;
209
- }
210
- return "";
211
- }