chatccc 0.2.199 → 0.2.200

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 (90) hide show
  1. package/README.md +1 -1
  2. package/agent-prompts/claude_specific.md +45 -45
  3. package/agent-prompts/codex_specific.md +2 -2
  4. package/agent-prompts/cursor_specific.md +13 -13
  5. package/bin/cccagent.mjs +17 -17
  6. package/config.sample.json +27 -27
  7. package/im-skills/feishu-skill/receive-send-file.md +63 -63
  8. package/im-skills/feishu-skill/receive-send-image.md +24 -24
  9. package/im-skills/feishu-skill/skill.md +3 -3
  10. package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
  11. package/im-skills/wechat-file-skill/send-file.mjs +83 -83
  12. package/im-skills/wechat-file-skill/skill.md +10 -10
  13. package/im-skills/wechat-image-skill/skill.md +10 -10
  14. package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
  15. package/im-skills/wechat-video-skill/send-video.mjs +79 -79
  16. package/im-skills/wechat-video-skill/skill.md +10 -10
  17. package/package.json +1 -1
  18. package/scripts/postinstall-sharp-check.mjs +58 -58
  19. package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
  20. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  21. package/src/__tests__/builtin-chat-session.test.ts +277 -277
  22. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  23. package/src/__tests__/builtin-config.test.ts +33 -33
  24. package/src/__tests__/builtin-context.test.ts +163 -163
  25. package/src/__tests__/builtin-file-tools.test.ts +224 -224
  26. package/src/__tests__/builtin-session-select.test.ts +116 -116
  27. package/src/__tests__/builtin-sigint.test.ts +56 -56
  28. package/src/__tests__/card-plain-text.test.ts +5 -5
  29. package/src/__tests__/cardkit.test.ts +60 -60
  30. package/src/__tests__/cards.test.ts +109 -109
  31. package/src/__tests__/ccc-adapter.test.ts +114 -114
  32. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  33. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  34. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  35. package/src/__tests__/claude-adapter.test.ts +592 -592
  36. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  37. package/src/__tests__/codex-raw-stream-log.test.ts +163 -163
  38. package/src/__tests__/codex-reset-actions.test.ts +146 -146
  39. package/src/__tests__/config-reload.test.ts +10 -10
  40. package/src/__tests__/config-sample.test.ts +18 -18
  41. package/src/__tests__/feishu-api.test.ts +60 -60
  42. package/src/__tests__/feishu-avatar.test.ts +87 -45
  43. package/src/__tests__/feishu-platform.test.ts +22 -22
  44. package/src/__tests__/format-message.test.ts +47 -47
  45. package/src/__tests__/jsonl-stream.test.ts +79 -79
  46. package/src/__tests__/orchestrator.test.ts +227 -202
  47. package/src/__tests__/privacy.test.ts +198 -198
  48. package/src/__tests__/raw-stream-log.test.ts +106 -106
  49. package/src/__tests__/session.test.ts +40 -40
  50. package/src/__tests__/shared-prefix.test.ts +36 -36
  51. package/src/__tests__/sim-platform.test.ts +12 -12
  52. package/src/__tests__/stream-state.test.ts +42 -42
  53. package/src/__tests__/web-ui.test.ts +209 -209
  54. package/src/adapters/ccc-adapter.ts +121 -121
  55. package/src/adapters/claude-adapter.ts +603 -603
  56. package/src/adapters/claude-session-meta-store.ts +120 -120
  57. package/src/adapters/codex-adapter.ts +380 -380
  58. package/src/adapters/jsonl-stream.ts +157 -157
  59. package/src/adapters/raw-stream-log.ts +124 -124
  60. package/src/adapters/resource-monitor.ts +140 -140
  61. package/src/agent-delegate-task-rpc.ts +153 -153
  62. package/src/agent-delegate-task.ts +81 -81
  63. package/src/agent-reload-config-rpc.ts +34 -34
  64. package/src/agent-stop-stuck.ts +129 -129
  65. package/src/builtin/cli.ts +473 -473
  66. package/src/builtin/context.ts +323 -323
  67. package/src/builtin/file-tools.ts +1072 -1072
  68. package/src/builtin/index.ts +404 -404
  69. package/src/builtin/session-select.ts +48 -48
  70. package/src/builtin/sigint.ts +50 -50
  71. package/src/cards.ts +195 -195
  72. package/src/chatgpt-subscription-rpc.ts +27 -27
  73. package/src/chatgpt-subscription.ts +299 -299
  74. package/src/chrome-devtools-guard.ts +318 -318
  75. package/src/codex-reset-actions.ts +184 -184
  76. package/src/config.ts +125 -125
  77. package/src/feishu-api.ts +86 -63
  78. package/src/feishu-platform.ts +20 -20
  79. package/src/format-message.ts +293 -293
  80. package/src/litellm-proxy.ts +374 -374
  81. package/src/orchestrator.ts +183 -183
  82. package/src/privacy.ts +118 -118
  83. package/src/runtime-reload.ts +34 -34
  84. package/src/session-chat-binding.ts +6 -6
  85. package/src/session-name.ts +8 -8
  86. package/src/session.ts +141 -141
  87. package/src/shared-prefix.ts +29 -29
  88. package/src/sim-platform.ts +20 -20
  89. package/src/turn-cards.ts +117 -117
  90. package/src/web-ui.ts +205 -205
package/src/config.ts CHANGED
@@ -88,9 +88,9 @@ export interface CursorConfig {
88
88
  onDemandMonthlyBudget: number;
89
89
  }
90
90
 
91
- export interface CodexConfig {
92
- /** 是否启用 Codex Agent;缺省时按"有任意字段非空"自动判定(向后兼容) */
93
- enabled: boolean;
91
+ export interface CodexConfig {
92
+ /** 是否启用 Codex Agent;缺省时按"有任意字段非空"自动判定(向后兼容) */
93
+ enabled: boolean;
94
94
  /** 是否作为 /new 未指定工具时使用的默认 Agent */
95
95
  defaultAgent: boolean;
96
96
  /** Codex CLI 可执行文件绝对路径;留空时退回到 PATH 中的 `codex` */
@@ -98,22 +98,22 @@ export interface CodexConfig {
98
98
  model: string;
99
99
  /** /model 可切换的单个备选模型;留空则不加入候选列表 */
100
100
  alternativeModel: string;
101
- effort: string;
102
- }
103
-
104
- export interface CccConfig {
105
- /** DeepSeek API Key for the ChatCCC self-developed agent. */
106
- DEEPSEEK_API_KEY: string;
107
- /** DeepSeek-compatible API Base URL for the ChatCCC self-developed agent. */
108
- DEEPSEEK_BASE_URL: string;
109
- /** Model used by the ChatCCC self-developed agent. */
110
- model: string;
111
- }
112
-
113
- export interface FeishuConfig {
114
- appId: string;
115
- appSecret: string;
116
- }
101
+ effort: string;
102
+ }
103
+
104
+ export interface CccConfig {
105
+ /** DeepSeek API Key for the ChatCCC self-developed agent. */
106
+ DEEPSEEK_API_KEY: string;
107
+ /** DeepSeek-compatible API Base URL for the ChatCCC self-developed agent. */
108
+ DEEPSEEK_BASE_URL: string;
109
+ /** Model used by the ChatCCC self-developed agent. */
110
+ model: string;
111
+ }
112
+
113
+ export interface FeishuConfig {
114
+ appId: string;
115
+ appSecret: string;
116
+ }
117
117
 
118
118
  export interface PlatformConfig {
119
119
  enabled: boolean;
@@ -143,12 +143,12 @@ export interface RawStreamAgentLogConfig {
143
143
  keepCompleted: boolean;
144
144
  }
145
145
 
146
- export interface RawStreamLogsConfig {
147
- claude: RawStreamAgentLogConfig;
148
- cursor: RawStreamAgentLogConfig;
149
- codex: RawStreamAgentLogConfig;
150
- ccc: RawStreamAgentLogConfig;
151
- }
146
+ export interface RawStreamLogsConfig {
147
+ claude: RawStreamAgentLogConfig;
148
+ cursor: RawStreamAgentLogConfig;
149
+ codex: RawStreamAgentLogConfig;
150
+ ccc: RawStreamAgentLogConfig;
151
+ }
152
152
 
153
153
  export interface AppConfig {
154
154
  feishu: FeishuConfig;
@@ -159,22 +159,22 @@ export interface AppConfig {
159
159
  /** 若为 false,AI 生成过程中用户发送消息不会打断,须先点「停止」再发送新消息 */
160
160
  allowInterrupt: boolean;
161
161
  rawStreamLogs: RawStreamLogsConfig;
162
- claude: ClaudeConfig;
163
- cursor: CursorConfig;
164
- codex: CodexConfig;
165
- ccc: CccConfig;
166
- }
162
+ claude: ClaudeConfig;
163
+ cursor: CursorConfig;
164
+ codex: CodexConfig;
165
+ ccc: CccConfig;
166
+ }
167
167
 
168
168
  export type AgentTool = "claude" | "cursor" | "codex";
169
169
  export const AGENT_TOOLS: AgentTool[] = ["claude", "cursor", "codex"];
170
170
  export type CursorAvatarBatteryMode = "apiPercent" | "onDemandUse";
171
171
 
172
172
  /** 获取指定 agent 配置中所有模型相关的值(最多 100 个,去重) */
173
- export function getAllModelsForTool(tool: string, cfg: AppConfig = config): string[] {
174
- const seen = new Set<string>();
175
- const collect = (v: unknown) => {
176
- if (typeof v === "string" && v.trim()) seen.add(v.trim());
177
- };
173
+ export function getAllModelsForTool(tool: string, cfg: AppConfig = config): string[] {
174
+ const seen = new Set<string>();
175
+ const collect = (v: unknown) => {
176
+ if (typeof v === "string" && v.trim()) seen.add(v.trim());
177
+ };
178
178
 
179
179
  if (tool === "claude") {
180
180
  collect(cfg.claude.model);
@@ -182,35 +182,35 @@ export function getAllModelsForTool(tool: string, cfg: AppConfig = config): stri
182
182
  } else if (tool === "cursor") {
183
183
  collect(cfg.cursor.model);
184
184
  collect(cfg.cursor.alternativeModel);
185
- } else if (tool === "codex") {
186
- collect(cfg.codex.model);
187
- collect(cfg.codex.alternativeModel);
188
- } else if (tool === "ccc") {
189
- collect(cfg.ccc.model);
190
- }
191
-
192
- return Array.from(seen).slice(0, 100);
193
- }
194
-
195
- export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
196
- export const CODEX_EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh"] as const;
197
-
198
- export function getAllEffortsForTool(tool: string): string[] {
199
- if (tool === "claude") return [...CLAUDE_EFFORT_LEVELS];
200
- if (tool === "codex") return [...CODEX_EFFORT_LEVELS];
201
- return [];
202
- }
203
-
204
- export function getDefaultEffortForTool(tool: AgentTool, cfg: AppConfig = config): string {
205
- if (tool === "claude") return cfg.claude.effort;
206
- if (tool === "codex") return cfg.codex.effort;
207
- return "";
208
- }
209
-
210
- const CONFIG_FILE = join(USER_DATA_DIR, "config.json");
211
- const CONFIG_SAMPLE_FILE = join(PROJECT_ROOT, "config.sample.json");
212
- export const DEFAULT_CCC_DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1";
213
- export const DEFAULT_CCC_MODEL = "deepseek-v4-pro";
185
+ } else if (tool === "codex") {
186
+ collect(cfg.codex.model);
187
+ collect(cfg.codex.alternativeModel);
188
+ } else if (tool === "ccc") {
189
+ collect(cfg.ccc.model);
190
+ }
191
+
192
+ return Array.from(seen).slice(0, 100);
193
+ }
194
+
195
+ export const CLAUDE_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const;
196
+ export const CODEX_EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh"] as const;
197
+
198
+ export function getAllEffortsForTool(tool: string): string[] {
199
+ if (tool === "claude") return [...CLAUDE_EFFORT_LEVELS];
200
+ if (tool === "codex") return [...CODEX_EFFORT_LEVELS];
201
+ return [];
202
+ }
203
+
204
+ export function getDefaultEffortForTool(tool: AgentTool, cfg: AppConfig = config): string {
205
+ if (tool === "claude") return cfg.claude.effort;
206
+ if (tool === "codex") return cfg.codex.effort;
207
+ return "";
208
+ }
209
+
210
+ const CONFIG_FILE = join(USER_DATA_DIR, "config.json");
211
+ const CONFIG_SAMPLE_FILE = join(PROJECT_ROOT, "config.sample.json");
212
+ export const DEFAULT_CCC_DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1";
213
+ export const DEFAULT_CCC_MODEL = "deepseek-v4-pro";
214
214
 
215
215
  /**
216
216
  * 将旧位置(PROJECT_ROOT)的持久化数据一次性迁移到 USER_DATA_DIR。
@@ -424,13 +424,13 @@ function loadConfig(): AppConfig {
424
424
  port: 18080,
425
425
  gitTimeoutSeconds: 180,
426
426
  allowInterrupt: false,
427
- rawStreamLogs: {
428
- claude: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
429
- cursor: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
430
- codex: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
431
- ccc: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
432
- },
433
- claude: { enabled: false, defaultAgent: true, model: "", subagentModel: "", effort: "", apiKey: "", baseUrl: "", maxTurn: 0 },
427
+ rawStreamLogs: {
428
+ claude: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
429
+ cursor: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
430
+ codex: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
431
+ ccc: { enabled: false, maxBytesPerTurn: 50 * 1024 * 1024, retentionDays: 7, keepCompleted: false },
432
+ },
433
+ claude: { enabled: false, defaultAgent: true, model: "", subagentModel: "", effort: "", apiKey: "", baseUrl: "", maxTurn: 0 },
434
434
  cursor: {
435
435
  enabled: false,
436
436
  defaultAgent: false,
@@ -439,10 +439,10 @@ function loadConfig(): AppConfig {
439
439
  alternativeModel: "",
440
440
  avatarBatteryMode: "apiPercent",
441
441
  onDemandMonthlyBudget: 1000,
442
- },
443
- codex: { enabled: false, defaultAgent: false, path: "", model: "", alternativeModel: "", effort: "" },
444
- ccc: { DEEPSEEK_API_KEY: "", DEEPSEEK_BASE_URL: DEFAULT_CCC_DEEPSEEK_BASE_URL, model: DEFAULT_CCC_MODEL },
445
- };
442
+ },
443
+ codex: { enabled: false, defaultAgent: false, path: "", model: "", alternativeModel: "", effort: "" },
444
+ ccc: { DEEPSEEK_API_KEY: "", DEEPSEEK_BASE_URL: DEFAULT_CCC_DEEPSEEK_BASE_URL, model: DEFAULT_CCC_MODEL },
445
+ };
446
446
 
447
447
  if (!IS_TEST_ENV) {
448
448
  migrateLegacyData();
@@ -492,12 +492,12 @@ function loadConfig(): AppConfig {
492
492
  alternativeModel?: unknown;
493
493
  avatarBatteryMode?: unknown;
494
494
  onDemandMonthlyBudget?: unknown;
495
- };
496
- codex?: { enabled?: unknown; defaultAgent?: unknown; path?: unknown; command?: unknown; model?: unknown; alternativeModel?: unknown; effort?: unknown };
497
- ccc?: { DEEPSEEK_API_KEY?: unknown; DEEPSEEK_BASE_URL?: unknown; model?: unknown };
498
- chromeDevtools?: { enabled?: unknown; port?: unknown; chromePath?: unknown };
499
- rawStreamLogs?: unknown;
500
- };
495
+ };
496
+ codex?: { enabled?: unknown; defaultAgent?: unknown; path?: unknown; command?: unknown; model?: unknown; alternativeModel?: unknown; effort?: unknown };
497
+ ccc?: { DEEPSEEK_API_KEY?: unknown; DEEPSEEK_BASE_URL?: unknown; model?: unknown };
498
+ chromeDevtools?: { enabled?: unknown; port?: unknown; chromePath?: unknown };
499
+ rawStreamLogs?: unknown;
500
+ };
501
501
  try {
502
502
  parsed = JSON.parse(raw);
503
503
  } catch (err) {
@@ -507,10 +507,10 @@ function loadConfig(): AppConfig {
507
507
 
508
508
  const feishu = parsed.feishu ?? { appId: "", appSecret: "" };
509
509
  const claude = parsed.claude ?? {} as Partial<ClaudeConfig>;
510
- const cursorRaw = (parsed.cursor ?? {}) as NonNullable<typeof parsed.cursor>;
511
- const codexRaw = (parsed.codex ?? {}) as NonNullable<typeof parsed.codex>;
512
- const cccRaw = (parsed.ccc ?? {}) as NonNullable<typeof parsed.ccc>;
513
- const chromeDevtoolsRaw = (parsed.chromeDevtools ?? {}) as NonNullable<typeof parsed.chromeDevtools>;
510
+ const cursorRaw = (parsed.cursor ?? {}) as NonNullable<typeof parsed.cursor>;
511
+ const codexRaw = (parsed.codex ?? {}) as NonNullable<typeof parsed.codex>;
512
+ const cccRaw = (parsed.ccc ?? {}) as NonNullable<typeof parsed.ccc>;
513
+ const chromeDevtoolsRaw = (parsed.chromeDevtools ?? {}) as NonNullable<typeof parsed.chromeDevtools>;
514
514
  const rawStreamLogsRaw = typeof parsed.rawStreamLogs === "object" && parsed.rawStreamLogs !== null
515
515
  ? parsed.rawStreamLogs as unknown as Record<string, unknown>
516
516
  : {};
@@ -607,12 +607,12 @@ function loadConfig(): AppConfig {
607
607
  port: typeof parsed.port === "number" ? parsed.port : 18080,
608
608
  gitTimeoutSeconds: typeof parsed.gitTimeoutSeconds === "number" ? parsed.gitTimeoutSeconds : 180,
609
609
  allowInterrupt: typeof parsed.allowInterrupt === "boolean" ? parsed.allowInterrupt : false,
610
- rawStreamLogs: {
611
- claude: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.claude),
612
- cursor: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.cursor),
613
- codex: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.codex),
614
- ccc: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.ccc),
615
- },
610
+ rawStreamLogs: {
611
+ claude: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.claude),
612
+ cursor: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.cursor),
613
+ codex: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.codex),
614
+ ccc: normalizeRawStreamAgentLogConfig(rawStreamLogsRaw.ccc),
615
+ },
616
616
  claude: {
617
617
  enabled: claudeEnabled,
618
618
  defaultAgent: defaultTool === "claude",
@@ -634,24 +634,24 @@ function loadConfig(): AppConfig {
634
634
  avatarBatteryMode: normalizeCursorAvatarBatteryMode(cursorRaw.avatarBatteryMode),
635
635
  onDemandMonthlyBudget: normalizeCursorOnDemandMonthlyBudget(cursorRaw.onDemandMonthlyBudget),
636
636
  },
637
- codex: {
638
- enabled: codexEnabled,
639
- defaultAgent: defaultTool === "codex",
640
- path: readToolCliPath(codexRaw, { label: "codex", onLegacyField }),
641
- model: normalizeOptionalConfigField(codexRaw.model, { label: "codex.model" }),
642
- alternativeModel: normalizeOptionalConfigField(codexRaw.alternativeModel, { label: "codex.alternativeModel" }),
643
- effort: normalizeOptionalConfigField(codexRaw.effort, { label: "codex.effort" }),
644
- },
645
- ccc: {
646
- DEEPSEEK_API_KEY: normalizeOptionalConfigField(cccRaw.DEEPSEEK_API_KEY, { label: "ccc.DEEPSEEK_API_KEY" }),
647
- DEEPSEEK_BASE_URL: normalizeOptionalConfigField(cccRaw.DEEPSEEK_BASE_URL, {
648
- label: "ccc.DEEPSEEK_BASE_URL",
649
- fallback: DEFAULT_CCC_DEEPSEEK_BASE_URL,
650
- }),
651
- model: normalizeOptionalConfigField(cccRaw.model, { label: "ccc.model", fallback: DEFAULT_CCC_MODEL }),
652
- },
653
- };
654
- }
637
+ codex: {
638
+ enabled: codexEnabled,
639
+ defaultAgent: defaultTool === "codex",
640
+ path: readToolCliPath(codexRaw, { label: "codex", onLegacyField }),
641
+ model: normalizeOptionalConfigField(codexRaw.model, { label: "codex.model" }),
642
+ alternativeModel: normalizeOptionalConfigField(codexRaw.alternativeModel, { label: "codex.alternativeModel" }),
643
+ effort: normalizeOptionalConfigField(codexRaw.effort, { label: "codex.effort" }),
644
+ },
645
+ ccc: {
646
+ DEEPSEEK_API_KEY: normalizeOptionalConfigField(cccRaw.DEEPSEEK_API_KEY, { label: "ccc.DEEPSEEK_API_KEY" }),
647
+ DEEPSEEK_BASE_URL: normalizeOptionalConfigField(cccRaw.DEEPSEEK_BASE_URL, {
648
+ label: "ccc.DEEPSEEK_BASE_URL",
649
+ fallback: DEFAULT_CCC_DEEPSEEK_BASE_URL,
650
+ }),
651
+ model: normalizeOptionalConfigField(cccRaw.model, { label: "ccc.model", fallback: DEFAULT_CCC_MODEL }),
652
+ },
653
+ };
654
+ }
655
655
 
656
656
  /**
657
657
  * 全局可变 config 对象。
@@ -967,26 +967,26 @@ export function explainMissingFeishuCredentialsAndExit(): never {
967
967
  export const CLAUDE_SESSION_PREFIX = "Claude Code Session:";
968
968
  /** 群描述中用于识别 Cursor 会话的前缀 */
969
969
  export const CURSOR_SESSION_PREFIX = "Cursor Session:";
970
- /** 群描述中用于识别 Codex 会话的前缀 */
971
- export const CODEX_SESSION_PREFIX = "Codex Session:";
972
- /** 群描述中用于识别 hidden ccc agent 会话的前缀 */
973
- export const CCC_SESSION_PREFIX = "CCC Session:";
970
+ /** 群描述中用于识别 Codex 会话的前缀 */
971
+ export const CODEX_SESSION_PREFIX = "Codex Session:";
972
+ /** 群描述中用于识别 hidden ccc agent 会话的前缀 */
973
+ export const CCC_SESSION_PREFIX = "CCC Session:";
974
974
 
975
975
  /** 根据 tool 名称返回对应的群描述前缀 */
976
- export function sessionPrefixForTool(tool: string): string {
977
- if (tool === "cursor") return CURSOR_SESSION_PREFIX;
978
- if (tool === "codex") return CODEX_SESSION_PREFIX;
979
- if (tool === "ccc") return CCC_SESSION_PREFIX;
980
- return CLAUDE_SESSION_PREFIX;
981
- }
976
+ export function sessionPrefixForTool(tool: string): string {
977
+ if (tool === "cursor") return CURSOR_SESSION_PREFIX;
978
+ if (tool === "codex") return CODEX_SESSION_PREFIX;
979
+ if (tool === "ccc") return CCC_SESSION_PREFIX;
980
+ return CLAUDE_SESSION_PREFIX;
981
+ }
982
982
 
983
983
  /** 根据 tool 名称返回用于状态展示的标签 */
984
- export function toolDisplayName(tool: string): string {
985
- if (tool === "cursor") return "Cursor";
986
- if (tool === "codex") return "Codex";
987
- if (tool === "ccc") return "CCC Agent";
988
- return "Claude Code";
989
- }
984
+ export function toolDisplayName(tool: string): string {
985
+ if (tool === "cursor") return "Cursor";
986
+ if (tool === "codex") return "Codex";
987
+ if (tool === "ccc") return "CCC Agent";
988
+ return "Claude Code";
989
+ }
990
990
 
991
991
  /** 解析 /new 未指定工具时使用的默认 Agent。旧配置缺省 defaultAgent 时保持 Claude 优先。 */
992
992
  export function resolveDefaultAgentTool(cfg: AppConfig = config): AgentTool {
package/src/feishu-api.ts CHANGED
@@ -11,10 +11,10 @@ import {
11
11
  CHAT_LOGS_DIR,
12
12
  PROJECT_ROOT,
13
13
  USER_DATA_DIR,
14
- CLAUDE_SESSION_PREFIX,
15
- CURSOR_SESSION_PREFIX,
16
- CODEX_SESSION_PREFIX,
17
- CCC_SESSION_PREFIX,
14
+ CLAUDE_SESSION_PREFIX,
15
+ CURSOR_SESSION_PREFIX,
16
+ CODEX_SESSION_PREFIX,
17
+ CCC_SESSION_PREFIX,
18
18
  ts,
19
19
  resolveDefaultAgentTool,
20
20
  toolDisplayName,
@@ -277,16 +277,16 @@ export async function disbandChat(
277
277
 
278
278
  export function extractSessionInfo(description: string): { sessionId: string; tool: string } | null {
279
279
  const PREFIXES: Array<{ prefix: string; tool: string }> = [
280
- { prefix: CLAUDE_SESSION_PREFIX, tool: "claude" },
281
- { prefix: CURSOR_SESSION_PREFIX, tool: "cursor" },
282
- { prefix: CODEX_SESSION_PREFIX, tool: "codex" },
283
- { prefix: CCC_SESSION_PREFIX, tool: "ccc" },
284
- ];
285
- for (const { prefix, tool } of PREFIXES) {
286
- const idx = description.indexOf(prefix);
287
- if (idx === -1) continue;
288
- const after = description.slice(idx + prefix.length).trim();
289
- const match = after.match(/^([a-zA-Z0-9_.-]+)/);
280
+ { prefix: CLAUDE_SESSION_PREFIX, tool: "claude" },
281
+ { prefix: CURSOR_SESSION_PREFIX, tool: "cursor" },
282
+ { prefix: CODEX_SESSION_PREFIX, tool: "codex" },
283
+ { prefix: CCC_SESSION_PREFIX, tool: "ccc" },
284
+ ];
285
+ for (const { prefix, tool } of PREFIXES) {
286
+ const idx = description.indexOf(prefix);
287
+ if (idx === -1) continue;
288
+ const after = description.slice(idx + prefix.length).trim();
289
+ const match = after.match(/^([a-zA-Z0-9_.-]+)/);
290
290
  if (match) return { sessionId: match[1], tool };
291
291
  }
292
292
  return null;
@@ -319,18 +319,19 @@ const AVATAR_BADGES: Record<string, string> = {
319
319
  cursor: resolvePath(AVATAR_BADGE_DIR, "badge_cursor.png"),
320
320
  codex: resolvePath(AVATAR_BADGE_DIR, "badge_codex.png"),
321
321
  };
322
- const AVATAR_SIZE = 256;
323
- const AVATAR_BADGE_SIZE = 92;
324
- const AVATAR_BADGE_MARGIN = 10;
325
- const PLAIN_AVATAR_TOOL = "plain";
326
- const CODEX_AVATAR_USAGE_STYLE_VERSION = "usage-ring-gray-consumed-v13";
327
- const CURSOR_AVATAR_USAGE_STYLE_VERSION = "usage-battery-v1";
322
+ const AVATAR_SIZE = 256;
323
+ const AVATAR_BADGE_SIZE = 92;
324
+ const AVATAR_BADGE_MARGIN = 10;
325
+ const PLAIN_AVATAR_TOOL = "plain";
326
+ const CODEX_AVATAR_USAGE_STYLE_VERSION = "usage-window-aware-v14";
327
+ const CURSOR_AVATAR_USAGE_STYLE_VERSION = "usage-battery-v1";
328
328
 
329
329
  export interface CodexUsageBalance {
330
330
  usedPercent: number;
331
331
  remainingPercent: number;
332
332
  resetAtEpochSeconds: number | null;
333
333
  resetAfterSeconds: number | null;
334
+ limitWindowSeconds?: number | null;
334
335
  }
335
336
 
336
337
  export interface CodexRateLimitResetCredit {
@@ -339,7 +340,7 @@ export interface CodexRateLimitResetCredit {
339
340
  }
340
341
 
341
342
  export interface CodexUsageSummary {
342
- fiveHour: CodexUsageBalance;
343
+ fiveHour: CodexUsageBalance | null;
343
344
  weekly: CodexUsageBalance | null;
344
345
  rateLimitResetCreditsAvailable: number | null;
345
346
  rateLimitResetCredits: CodexRateLimitResetCredit[] | null;
@@ -355,17 +356,20 @@ export interface CodexResetConsumeResult {
355
356
  const avatarKeyCache = new Map<string, string>();
356
357
  let avatarKeyCacheLoaded = false;
357
358
 
358
- function normalizeAvatarTool(tool: string): string {
359
- return AVATAR_BADGES[tool] ? tool : PLAIN_AVATAR_TOOL;
360
- }
359
+ function normalizeAvatarTool(tool: string): string {
360
+ return AVATAR_BADGES[tool] ? tool : PLAIN_AVATAR_TOOL;
361
+ }
362
+
363
+ const FIVE_HOUR_WINDOW_SECONDS = 5 * 60 * 60;
364
+ const SEVEN_DAY_WINDOW_SECONDS = 7 * 24 * 60 * 60;
361
365
 
362
366
  function normalizeAvatarStatus(status: string): string {
363
367
  return AVATAR_SOURCES[status] ? status : "idle";
364
368
  }
365
369
 
366
- function avatarCombinationPath(tool: string, status: string): string {
367
- return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
368
- }
370
+ function avatarCombinationPath(tool: string, status: string): string {
371
+ return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
372
+ }
369
373
 
370
374
  function avatarCacheKey(
371
375
  tool: string,
@@ -376,9 +380,9 @@ function avatarCacheKey(
376
380
  const normalizedTool = normalizeAvatarTool(tool);
377
381
  const normalizedStatus = normalizeAvatarStatus(status);
378
382
  if (normalizedTool === "codex") {
379
- return codexUsage
380
- ? `${normalizedTool}:${normalizedStatus}:${CODEX_AVATAR_USAGE_STYLE_VERSION}:week-battery:${codexUsage.weekly?.remainingPercent}:5h-ring:${codexUsage.fiveHour.remainingPercent}`
381
- : `${normalizedTool}:${normalizedStatus}:plain`;
383
+ if (!codexUsage?.weekly) return `${normalizedTool}:${normalizedStatus}:plain`;
384
+ const ringKey = codexUsage.fiveHour ? `:5h-ring:${codexUsage.fiveHour.remainingPercent}` : "";
385
+ return `${normalizedTool}:${normalizedStatus}:${CODEX_AVATAR_USAGE_STYLE_VERSION}:7d-battery:${codexUsage.weekly.remainingPercent}${ringKey}`;
382
386
  }
383
387
  if (normalizedTool === "cursor") {
384
388
  return cursorBatteryPercent !== null
@@ -423,12 +427,22 @@ function usageBalanceFromWindow(raw: Record<string, unknown>, fieldName: string)
423
427
  const used = clampPercent(usedPercent);
424
428
  const resetAt = Number(raw.reset_at);
425
429
  const resetAfter = Number(raw.reset_after_seconds);
426
- return {
430
+ const rawLimitWindow = raw.limit_window_seconds;
431
+ const limitWindow = rawLimitWindow === null || rawLimitWindow === undefined || rawLimitWindow === ""
432
+ ? Number.NaN
433
+ : Number(rawLimitWindow);
434
+ const balance: CodexUsageBalance = {
427
435
  usedPercent: used,
428
436
  remainingPercent: clampPercent(100 - used),
429
437
  resetAtEpochSeconds: Number.isFinite(resetAt) ? resetAt : null,
430
438
  resetAfterSeconds: Number.isFinite(resetAfter) ? resetAfter : null,
431
439
  };
440
+ if (Number.isFinite(limitWindow)) balance.limitWindowSeconds = limitWindow;
441
+ return balance;
442
+ }
443
+
444
+ function isUsageWindowDuration(balance: CodexUsageBalance | null, seconds: number): boolean {
445
+ return balance?.limitWindowSeconds === seconds;
432
446
  }
433
447
 
434
448
  function parseOptionalUsageWindow(rateLimit: Record<string, unknown>, keys: string[]): CodexUsageBalance | null {
@@ -541,18 +555,25 @@ export async function getCodexUsageSummary(): Promise<CodexUsageSummary> {
541
555
  const rateLimit = data.rate_limit;
542
556
  if (!rateLimit || typeof rateLimit !== "object") throw new Error("missing rate_limit");
543
557
 
544
- const fiveHour = parseOptionalUsageWindow(rateLimit, ["primary_window"]);
545
- if (!fiveHour) throw new Error("missing rate_limit.primary_window.used_percent");
558
+ const primaryWindow = parseOptionalUsageWindow(rateLimit, ["primary_window"]);
559
+ const secondaryWindow = parseOptionalUsageWindow(rateLimit, [
560
+ "secondary_window",
561
+ "weekly_window",
562
+ "week_window",
563
+ "long_window",
564
+ ]);
565
+ if (!primaryWindow && !secondaryWindow) throw new Error("missing supported rate_limit usage window");
566
+
567
+ const windows = [primaryWindow, secondaryWindow];
568
+ const fiveHour = windows.find((window) => isUsageWindowDuration(window, FIVE_HOUR_WINDOW_SECONDS))
569
+ ?? (primaryWindow?.limitWindowSeconds === undefined ? primaryWindow : null);
570
+ const weekly = windows.find((window) => isUsageWindowDuration(window, SEVEN_DAY_WINDOW_SECONDS))
571
+ ?? (secondaryWindow?.limitWindowSeconds === undefined ? secondaryWindow : null);
546
572
  const resetCredits = await resetCreditsPromise;
547
573
 
548
574
  return {
549
575
  fiveHour,
550
- weekly: parseOptionalUsageWindow(rateLimit, [
551
- "secondary_window",
552
- "weekly_window",
553
- "week_window",
554
- "long_window",
555
- ]),
576
+ weekly,
556
577
  rateLimitResetCreditsAvailable: resetCredits?.availableCount ?? parseRateLimitResetCredits(data),
557
578
  rateLimitResetCredits: resetCredits?.availableCredits ?? null,
558
579
  };
@@ -758,23 +779,25 @@ async function renderAvatar(
758
779
  codexUsage: CodexUsageSummary | null = null,
759
780
  cursorBatteryPercent: number | null = null,
760
781
  ): Promise<{ buffer: Buffer; contentType: string; filename: string }> {
761
- const normalizedTool = normalizeAvatarTool(tool);
762
- const normalizedStatus = normalizeAvatarStatus(status);
763
- const composites: sharp.OverlayOptions[] = [];
764
- const hasAgentBadge = normalizedTool !== PLAIN_AVATAR_TOOL;
765
-
766
- const codexWeeklyUsage = normalizedTool === "codex" ? codexUsage?.weekly : null;
767
- const useDynamicCodexAvatar = codexUsage && codexWeeklyUsage;
768
- const useDynamicCursorAvatar = normalizedTool === "cursor" && cursorBatteryPercent !== null;
769
- const basePath = useDynamicCodexAvatar || useDynamicCursorAvatar
770
- ? AVATAR_SOURCES[normalizedStatus]
771
- : hasAgentBadge
772
- ? avatarCombinationPath(normalizedTool, normalizedStatus)
773
- : AVATAR_SOURCES[normalizedStatus];
782
+ const normalizedTool = normalizeAvatarTool(tool);
783
+ const normalizedStatus = normalizeAvatarStatus(status);
784
+ const composites: sharp.OverlayOptions[] = [];
785
+ const hasAgentBadge = normalizedTool !== PLAIN_AVATAR_TOOL;
786
+
787
+ const codexWeeklyUsage = normalizedTool === "codex" ? codexUsage?.weekly ?? null : null;
788
+ const useDynamicCodexAvatar = normalizedTool === "codex" && codexUsage !== null && codexWeeklyUsage !== null;
789
+ const useDynamicCursorAvatar = normalizedTool === "cursor" && cursorBatteryPercent !== null;
790
+ const basePath = useDynamicCodexAvatar || useDynamicCursorAvatar
791
+ ? AVATAR_SOURCES[normalizedStatus]
792
+ : hasAgentBadge
793
+ ? avatarCombinationPath(normalizedTool, normalizedStatus)
794
+ : AVATAR_SOURCES[normalizedStatus];
774
795
 
775
796
  if (useDynamicCodexAvatar) {
797
+ if (codexUsage.fiveHour) {
798
+ composites.push({ input: buildCodexUsageRingSvg(codexUsage.fiveHour.remainingPercent), left: 0, top: 0 });
799
+ }
776
800
  composites.push(
777
- { input: buildCodexUsageRingSvg(codexUsage.fiveHour.remainingPercent), left: 0, top: 0 },
778
801
  { input: buildCodexUsageBatterySvg(codexWeeklyUsage.remainingPercent), left: 0, top: 0 },
779
802
  await buildAgentBadgeOverlay(normalizedTool),
780
803
  );
@@ -797,16 +820,16 @@ async function renderAvatar(
797
820
  .jpeg({ quality: 95, progressive: false })
798
821
  .toBuffer();
799
822
 
800
- return {
801
- buffer: jpeg,
802
- contentType: "image/jpeg",
803
- filename: normalizedTool === "codex" && codexUsage?.weekly
804
- ? `avatar_${normalizedTool}_${normalizedStatus}_week_${codexUsage.weekly.remainingPercent}_5h_${codexUsage.fiveHour.remainingPercent}.jpg`
805
- : normalizedTool === "cursor" && cursorBatteryPercent !== null
806
- ? `avatar_${normalizedTool}_${normalizedStatus}_battery_${cursorBatteryPercent}.jpg`
807
- : `avatar_${normalizedTool}_${normalizedStatus}.jpg`,
808
- };
809
- }
823
+ return {
824
+ buffer: jpeg,
825
+ contentType: "image/jpeg",
826
+ filename: normalizedTool === "codex" && codexUsage?.weekly
827
+ ? `avatar_${normalizedTool}_${normalizedStatus}_7d_${codexUsage.weekly.remainingPercent}${codexUsage.fiveHour ? `_5h_${codexUsage.fiveHour.remainingPercent}` : ""}.jpg`
828
+ : normalizedTool === "cursor" && cursorBatteryPercent !== null
829
+ ? `avatar_${normalizedTool}_${normalizedStatus}_battery_${cursorBatteryPercent}.jpg`
830
+ : `avatar_${normalizedTool}_${normalizedStatus}.jpg`,
831
+ };
832
+ }
810
833
 
811
834
  async function uploadImage(
812
835
  token: string,
@@ -29,10 +29,10 @@ export interface FeishuPlatform {
29
29
  updateChatInfo: typeof realApi.updateChatInfo;
30
30
  getChatInfo: typeof realApi.getChatInfo;
31
31
  disbandChat: typeof realApi.disbandChat;
32
- setChatAvatar: typeof realApi.setChatAvatar;
33
- getCodexUsageSummary: typeof realApi.getCodexUsageSummary;
34
- consumeCodexRateLimitResetCredit: typeof realApi.consumeCodexRateLimitResetCredit;
35
- getOrDownloadImage: typeof realApi.getOrDownloadImage;
32
+ setChatAvatar: typeof realApi.setChatAvatar;
33
+ getCodexUsageSummary: typeof realApi.getCodexUsageSummary;
34
+ consumeCodexRateLimitResetCredit: typeof realApi.consumeCodexRateLimitResetCredit;
35
+ getOrDownloadImage: typeof realApi.getOrDownloadImage;
36
36
  verifyAllPermissions: typeof realApi.verifyAllPermissions;
37
37
  reportPermissionResults: typeof realApi.reportPermissionResults;
38
38
  extractSessionInfo: typeof realApi.extractSessionInfo;
@@ -110,21 +110,21 @@ export function disbandChat(...args: Parameters<typeof realApi.disbandChat>): Re
110
110
  return _impl.disbandChat(...args);
111
111
  }
112
112
 
113
- export function setChatAvatar(...args: Parameters<typeof realApi.setChatAvatar>): ReturnType<typeof realApi.setChatAvatar> {
114
- return _impl.setChatAvatar(...args);
115
- }
116
-
117
- export function getCodexUsageSummary(...args: Parameters<typeof realApi.getCodexUsageSummary>): ReturnType<typeof realApi.getCodexUsageSummary> {
118
- return _impl.getCodexUsageSummary(...args);
119
- }
120
-
121
- export function consumeCodexRateLimitResetCredit(...args: Parameters<typeof realApi.consumeCodexRateLimitResetCredit>): ReturnType<typeof realApi.consumeCodexRateLimitResetCredit> {
122
- return _impl.consumeCodexRateLimitResetCredit(...args);
123
- }
124
-
125
- export function getOrDownloadImage(...args: Parameters<typeof realApi.getOrDownloadImage>): ReturnType<typeof realApi.getOrDownloadImage> {
126
- return _impl.getOrDownloadImage(...args);
127
- }
113
+ export function setChatAvatar(...args: Parameters<typeof realApi.setChatAvatar>): ReturnType<typeof realApi.setChatAvatar> {
114
+ return _impl.setChatAvatar(...args);
115
+ }
116
+
117
+ export function getCodexUsageSummary(...args: Parameters<typeof realApi.getCodexUsageSummary>): ReturnType<typeof realApi.getCodexUsageSummary> {
118
+ return _impl.getCodexUsageSummary(...args);
119
+ }
120
+
121
+ export function consumeCodexRateLimitResetCredit(...args: Parameters<typeof realApi.consumeCodexRateLimitResetCredit>): ReturnType<typeof realApi.consumeCodexRateLimitResetCredit> {
122
+ return _impl.consumeCodexRateLimitResetCredit(...args);
123
+ }
124
+
125
+ export function getOrDownloadImage(...args: Parameters<typeof realApi.getOrDownloadImage>): ReturnType<typeof realApi.getOrDownloadImage> {
126
+ return _impl.getOrDownloadImage(...args);
127
+ }
128
128
 
129
129
  export function verifyAllPermissions(...args: Parameters<typeof realApi.verifyAllPermissions>): ReturnType<typeof realApi.verifyAllPermissions> {
130
130
  return _impl.verifyAllPermissions(...args);
@@ -156,4 +156,4 @@ export function sendRestartCard(...args: Parameters<typeof realApi.sendRestartCa
156
156
 
157
157
  export function getMergeForwardMessages(...args: Parameters<typeof realApi.getMergeForwardMessages>): ReturnType<typeof realApi.getMergeForwardMessages> {
158
158
  return _impl.getMergeForwardMessages(...args);
159
- }
159
+ }