chatccc 0.2.197 → 0.2.199

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 (52) hide show
  1. package/agent-prompts/cursor_specific.md +13 -13
  2. package/bin/cccagent.mjs +17 -17
  3. package/config.sample.json +27 -27
  4. package/package.json +2 -1
  5. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -277
  7. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  8. package/src/__tests__/builtin-config.test.ts +33 -33
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +224 -224
  11. package/src/__tests__/builtin-session-select.test.ts +116 -116
  12. package/src/__tests__/builtin-sigint.test.ts +56 -56
  13. package/src/__tests__/cards.test.ts +109 -109
  14. package/src/__tests__/ccc-adapter.test.ts +114 -114
  15. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  16. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  17. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  18. package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
  19. package/src/__tests__/codex-raw-stream-log.test.ts +163 -120
  20. package/src/__tests__/config-reload.test.ts +10 -10
  21. package/src/__tests__/config-sample.test.ts +18 -18
  22. package/src/__tests__/cursor-adapter.test.ts +114 -1
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/jsonl-stream.test.ts +79 -0
  25. package/src/__tests__/orchestrator.test.ts +200 -200
  26. package/src/__tests__/raw-stream-log.test.ts +106 -106
  27. package/src/__tests__/session.test.ts +40 -40
  28. package/src/__tests__/sim-platform.test.ts +12 -12
  29. package/src/__tests__/web-ui.test.ts +209 -209
  30. package/src/adapters/ccc-adapter.ts +121 -121
  31. package/src/adapters/claude-adapter.ts +603 -603
  32. package/src/adapters/codex-adapter.ts +380 -392
  33. package/src/adapters/cursor-adapter.ts +56 -30
  34. package/src/adapters/jsonl-stream.ts +157 -0
  35. package/src/adapters/raw-stream-log.ts +124 -124
  36. package/src/agent-reload-config-rpc.ts +34 -34
  37. package/src/builtin/cli.ts +473 -473
  38. package/src/builtin/context.ts +323 -323
  39. package/src/builtin/file-tools.ts +1072 -1072
  40. package/src/builtin/index.ts +404 -404
  41. package/src/builtin/session-select.ts +48 -48
  42. package/src/builtin/sigint.ts +50 -50
  43. package/src/cards.ts +195 -195
  44. package/src/chatgpt-subscription-rpc.ts +27 -27
  45. package/src/chatgpt-subscription.ts +299 -299
  46. package/src/chrome-devtools-guard.ts +318 -318
  47. package/src/config.ts +125 -125
  48. package/src/feishu-api.ts +49 -49
  49. package/src/orchestrator.ts +179 -179
  50. package/src/runtime-reload.ts +34 -34
  51. package/src/session.ts +141 -141
  52. 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,12 +319,12 @@ 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-ring-gray-consumed-v13";
327
+ const CURSOR_AVATAR_USAGE_STYLE_VERSION = "usage-battery-v1";
328
328
 
329
329
  export interface CodexUsageBalance {
330
330
  usedPercent: number;
@@ -355,17 +355,17 @@ export interface CodexResetConsumeResult {
355
355
  const avatarKeyCache = new Map<string, string>();
356
356
  let avatarKeyCacheLoaded = false;
357
357
 
358
- function normalizeAvatarTool(tool: string): string {
359
- return AVATAR_BADGES[tool] ? tool : PLAIN_AVATAR_TOOL;
360
- }
358
+ function normalizeAvatarTool(tool: string): string {
359
+ return AVATAR_BADGES[tool] ? tool : PLAIN_AVATAR_TOOL;
360
+ }
361
361
 
362
362
  function normalizeAvatarStatus(status: string): string {
363
363
  return AVATAR_SOURCES[status] ? status : "idle";
364
364
  }
365
365
 
366
- function avatarCombinationPath(tool: string, status: string): string {
367
- return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
368
- }
366
+ function avatarCombinationPath(tool: string, status: string): string {
367
+ return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
368
+ }
369
369
 
370
370
  function avatarCacheKey(
371
371
  tool: string,
@@ -758,19 +758,19 @@ async function renderAvatar(
758
758
  codexUsage: CodexUsageSummary | null = null,
759
759
  cursorBatteryPercent: number | null = null,
760
760
  ): 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];
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];
774
774
 
775
775
  if (useDynamicCodexAvatar) {
776
776
  composites.push(
@@ -797,16 +797,16 @@ async function renderAvatar(
797
797
  .jpeg({ quality: 95, progressive: false })
798
798
  .toBuffer();
799
799
 
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
- }
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
+ }
810
810
 
811
811
  async function uploadImage(
812
812
  token: string,