chatccc 0.2.200 → 0.2.202
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.
- package/README.md +17 -15
- package/agent-prompts/claude_specific.md +45 -45
- package/agent-prompts/codex_specific.md +2 -2
- package/agent-prompts/cursor_specific.md +13 -13
- package/bin/cccagent.mjs +17 -17
- package/config.sample.json +27 -27
- package/im-skills/feishu-skill/receive-send-file.md +63 -63
- package/im-skills/feishu-skill/receive-send-image.md +24 -24
- package/im-skills/feishu-skill/skill.md +3 -3
- package/im-skills/wechat-file-skill/receive-send-file.md +38 -38
- package/im-skills/wechat-file-skill/send-file.mjs +83 -83
- package/im-skills/wechat-file-skill/skill.md +10 -10
- package/im-skills/wechat-image-skill/skill.md +10 -10
- package/im-skills/wechat-video-skill/receive-send-video.md +38 -38
- package/im-skills/wechat-video-skill/send-video.mjs +79 -79
- package/im-skills/wechat-video-skill/skill.md +10 -10
- package/package.json +1 -1
- package/scripts/postinstall-sharp-check.mjs +58 -58
- package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -165
- package/src/__tests__/agent-reload-config-rpc.test.ts +99 -99
- package/src/__tests__/builtin-chat-session.test.ts +277 -277
- package/src/__tests__/builtin-cli-json.test.ts +39 -39
- package/src/__tests__/builtin-config.test.ts +33 -33
- package/src/__tests__/builtin-context.test.ts +163 -163
- package/src/__tests__/builtin-file-tools.test.ts +224 -224
- package/src/__tests__/builtin-session-select.test.ts +116 -116
- package/src/__tests__/builtin-sigint.test.ts +56 -56
- package/src/__tests__/card-plain-text.test.ts +5 -5
- package/src/__tests__/cardkit.test.ts +60 -60
- package/src/__tests__/cards.test.ts +133 -122
- package/src/__tests__/ccc-adapter.test.ts +114 -114
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
- package/src/__tests__/chatgpt-subscription.test.ts +135 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
- package/src/__tests__/claude-adapter.test.ts +592 -592
- package/src/__tests__/claude-raw-stream-log.test.ts +87 -87
- package/src/__tests__/codex-raw-stream-log.test.ts +163 -163
- package/src/__tests__/codex-reset-actions.test.ts +146 -146
- package/src/__tests__/config-reload.test.ts +10 -10
- package/src/__tests__/config-sample.test.ts +18 -18
- package/src/__tests__/cursor-adapter.test.ts +226 -226
- package/src/__tests__/feishu-api.test.ts +60 -60
- package/src/__tests__/feishu-avatar.test.ts +90 -90
- package/src/__tests__/feishu-platform.test.ts +22 -22
- package/src/__tests__/format-message.test.ts +47 -47
- package/src/__tests__/jsonl-stream.test.ts +79 -79
- package/src/__tests__/orchestrator.test.ts +464 -301
- package/src/__tests__/privacy.test.ts +198 -198
- package/src/__tests__/raw-stream-log.test.ts +106 -106
- package/src/__tests__/session.test.ts +46 -44
- package/src/__tests__/shared-prefix.test.ts +36 -36
- package/src/__tests__/sim-platform.test.ts +12 -12
- package/src/__tests__/stream-state.test.ts +42 -42
- package/src/__tests__/web-ui.test.ts +209 -209
- package/src/adapters/ccc-adapter.ts +121 -121
- package/src/adapters/claude-adapter.ts +603 -603
- package/src/adapters/claude-session-meta-store.ts +120 -120
- package/src/adapters/codex-adapter.ts +380 -380
- package/src/adapters/cursor-adapter.ts +673 -673
- package/src/adapters/jsonl-stream.ts +157 -157
- package/src/adapters/raw-stream-log.ts +124 -124
- package/src/adapters/resource-monitor.ts +140 -140
- package/src/agent-delegate-task-rpc.ts +153 -153
- package/src/agent-delegate-task.ts +81 -81
- package/src/agent-reload-config-rpc.ts +34 -34
- package/src/agent-stop-stuck.ts +129 -129
- package/src/builtin/cli.ts +473 -473
- package/src/builtin/context.ts +323 -323
- package/src/builtin/file-tools.ts +1072 -1072
- package/src/builtin/index.ts +404 -404
- package/src/builtin/session-select.ts +48 -48
- package/src/builtin/sigint.ts +50 -50
- package/src/cards.ts +222 -210
- package/src/chatgpt-subscription-rpc.ts +27 -27
- package/src/chatgpt-subscription.ts +299 -299
- package/src/chrome-devtools-guard.ts +318 -318
- package/src/codex-reset-actions.ts +184 -184
- package/src/config.ts +125 -125
- package/src/feishu-api.ts +118 -118
- package/src/feishu-platform.ts +20 -20
- package/src/format-message.ts +293 -293
- package/src/litellm-proxy.ts +374 -374
- package/src/orchestrator.ts +348 -329
- package/src/privacy.ts +118 -118
- package/src/runtime-reload.ts +34 -34
- package/src/session-chat-binding.ts +6 -6
- package/src/session-name.ts +8 -8
- package/src/session.ts +177 -169
- package/src/shared-prefix.ts +29 -29
- package/src/sim-platform.ts +20 -20
- package/src/turn-cards.ts +117 -117
- 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,29 +319,29 @@ 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-window-aware-v14";
|
|
327
|
-
const CURSOR_AVATAR_USAGE_STYLE_VERSION = "usage-battery-v1";
|
|
328
|
-
|
|
329
|
-
export interface CodexUsageBalance {
|
|
330
|
-
usedPercent: number;
|
|
331
|
-
remainingPercent: number;
|
|
332
|
-
resetAtEpochSeconds: number | null;
|
|
333
|
-
resetAfterSeconds: number | null;
|
|
334
|
-
limitWindowSeconds?: number | null;
|
|
335
|
-
}
|
|
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
|
+
|
|
329
|
+
export interface CodexUsageBalance {
|
|
330
|
+
usedPercent: number;
|
|
331
|
+
remainingPercent: number;
|
|
332
|
+
resetAtEpochSeconds: number | null;
|
|
333
|
+
resetAfterSeconds: number | null;
|
|
334
|
+
limitWindowSeconds?: number | null;
|
|
335
|
+
}
|
|
336
336
|
|
|
337
337
|
export interface CodexRateLimitResetCredit {
|
|
338
338
|
grantedAt: string | null;
|
|
339
339
|
expiresAt: string;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
export interface CodexUsageSummary {
|
|
343
|
-
fiveHour: CodexUsageBalance | null;
|
|
344
|
-
weekly: CodexUsageBalance | null;
|
|
342
|
+
export interface CodexUsageSummary {
|
|
343
|
+
fiveHour: CodexUsageBalance | null;
|
|
344
|
+
weekly: CodexUsageBalance | null;
|
|
345
345
|
rateLimitResetCreditsAvailable: number | null;
|
|
346
346
|
rateLimitResetCredits: CodexRateLimitResetCredit[] | null;
|
|
347
347
|
}
|
|
@@ -356,20 +356,20 @@ export interface CodexResetConsumeResult {
|
|
|
356
356
|
const avatarKeyCache = new Map<string, string>();
|
|
357
357
|
let avatarKeyCacheLoaded = false;
|
|
358
358
|
|
|
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;
|
|
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;
|
|
365
365
|
|
|
366
366
|
function normalizeAvatarStatus(status: string): string {
|
|
367
367
|
return AVATAR_SOURCES[status] ? status : "idle";
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
-
function avatarCombinationPath(tool: string, status: string): string {
|
|
371
|
-
return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
|
|
372
|
-
}
|
|
370
|
+
function avatarCombinationPath(tool: string, status: string): string {
|
|
371
|
+
return resolvePath(AVATAR_COMBINATIONS_DIR, `avatar_${normalizeAvatarTool(tool)}_${normalizeAvatarStatus(status)}.png`);
|
|
372
|
+
}
|
|
373
373
|
|
|
374
374
|
function avatarCacheKey(
|
|
375
375
|
tool: string,
|
|
@@ -377,12 +377,12 @@ function avatarCacheKey(
|
|
|
377
377
|
codexUsage: CodexUsageSummary | null = null,
|
|
378
378
|
cursorBatteryPercent: number | null = null,
|
|
379
379
|
): string {
|
|
380
|
-
const normalizedTool = normalizeAvatarTool(tool);
|
|
381
|
-
const normalizedStatus = normalizeAvatarStatus(status);
|
|
382
|
-
if (normalizedTool === "codex") {
|
|
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}`;
|
|
380
|
+
const normalizedTool = normalizeAvatarTool(tool);
|
|
381
|
+
const normalizedStatus = normalizeAvatarStatus(status);
|
|
382
|
+
if (normalizedTool === "codex") {
|
|
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}`;
|
|
386
386
|
}
|
|
387
387
|
if (normalizedTool === "cursor") {
|
|
388
388
|
return cursorBatteryPercent !== null
|
|
@@ -420,30 +420,30 @@ function clampPercent(value: number): number {
|
|
|
420
420
|
return Math.max(0, Math.min(100, Math.round(value)));
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
function usageBalanceFromWindow(raw: Record<string, unknown>, fieldName: string): CodexUsageBalance {
|
|
423
|
+
function usageBalanceFromWindow(raw: Record<string, unknown>, fieldName: string): CodexUsageBalance {
|
|
424
424
|
const value = raw.used_percent;
|
|
425
425
|
const usedPercent = Number(value);
|
|
426
426
|
if (!Number.isFinite(usedPercent)) throw new Error(`missing ${fieldName}.used_percent`);
|
|
427
|
-
const used = clampPercent(usedPercent);
|
|
428
|
-
const resetAt = Number(raw.reset_at);
|
|
429
|
-
const resetAfter = Number(raw.reset_after_seconds);
|
|
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 = {
|
|
435
|
-
usedPercent: used,
|
|
436
|
-
remainingPercent: clampPercent(100 - used),
|
|
437
|
-
resetAtEpochSeconds: Number.isFinite(resetAt) ? resetAt : null,
|
|
438
|
-
resetAfterSeconds: Number.isFinite(resetAfter) ? resetAfter : null,
|
|
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;
|
|
446
|
-
}
|
|
427
|
+
const used = clampPercent(usedPercent);
|
|
428
|
+
const resetAt = Number(raw.reset_at);
|
|
429
|
+
const resetAfter = Number(raw.reset_after_seconds);
|
|
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 = {
|
|
435
|
+
usedPercent: used,
|
|
436
|
+
remainingPercent: clampPercent(100 - used),
|
|
437
|
+
resetAtEpochSeconds: Number.isFinite(resetAt) ? resetAt : null,
|
|
438
|
+
resetAfterSeconds: Number.isFinite(resetAfter) ? resetAfter : null,
|
|
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;
|
|
446
|
+
}
|
|
447
447
|
|
|
448
448
|
function parseOptionalUsageWindow(rateLimit: Record<string, unknown>, keys: string[]): CodexUsageBalance | null {
|
|
449
449
|
for (const key of keys) {
|
|
@@ -555,25 +555,25 @@ export async function getCodexUsageSummary(): Promise<CodexUsageSummary> {
|
|
|
555
555
|
const rateLimit = data.rate_limit;
|
|
556
556
|
if (!rateLimit || typeof rateLimit !== "object") throw new Error("missing rate_limit");
|
|
557
557
|
|
|
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);
|
|
572
|
-
const resetCredits = await resetCreditsPromise;
|
|
573
|
-
|
|
574
|
-
return {
|
|
575
|
-
fiveHour,
|
|
576
|
-
weekly,
|
|
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);
|
|
572
|
+
const resetCredits = await resetCreditsPromise;
|
|
573
|
+
|
|
574
|
+
return {
|
|
575
|
+
fiveHour,
|
|
576
|
+
weekly,
|
|
577
577
|
rateLimitResetCreditsAvailable: resetCredits?.availableCount ?? parseRateLimitResetCredits(data),
|
|
578
578
|
rateLimitResetCredits: resetCredits?.availableCredits ?? null,
|
|
579
579
|
};
|
|
@@ -779,28 +779,28 @@ async function renderAvatar(
|
|
|
779
779
|
codexUsage: CodexUsageSummary | null = null,
|
|
780
780
|
cursorBatteryPercent: number | null = null,
|
|
781
781
|
): Promise<{ buffer: Buffer; contentType: string; filename: string }> {
|
|
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];
|
|
795
|
-
|
|
796
|
-
if (useDynamicCodexAvatar) {
|
|
797
|
-
if (codexUsage.fiveHour) {
|
|
798
|
-
composites.push({ input: buildCodexUsageRingSvg(codexUsage.fiveHour.remainingPercent), left: 0, top: 0 });
|
|
799
|
-
}
|
|
800
|
-
composites.push(
|
|
801
|
-
{ input: buildCodexUsageBatterySvg(codexWeeklyUsage.remainingPercent), left: 0, top: 0 },
|
|
802
|
-
await buildAgentBadgeOverlay(normalizedTool),
|
|
803
|
-
);
|
|
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];
|
|
795
|
+
|
|
796
|
+
if (useDynamicCodexAvatar) {
|
|
797
|
+
if (codexUsage.fiveHour) {
|
|
798
|
+
composites.push({ input: buildCodexUsageRingSvg(codexUsage.fiveHour.remainingPercent), left: 0, top: 0 });
|
|
799
|
+
}
|
|
800
|
+
composites.push(
|
|
801
|
+
{ input: buildCodexUsageBatterySvg(codexWeeklyUsage.remainingPercent), left: 0, top: 0 },
|
|
802
|
+
await buildAgentBadgeOverlay(normalizedTool),
|
|
803
|
+
);
|
|
804
804
|
} else if (useDynamicCursorAvatar) {
|
|
805
805
|
composites.push(
|
|
806
806
|
{ input: buildCodexUsageBatterySvg(cursorBatteryPercent), left: 0, top: 0 },
|
|
@@ -820,16 +820,16 @@ async function renderAvatar(
|
|
|
820
820
|
.jpeg({ quality: 95, progressive: false })
|
|
821
821
|
.toBuffer();
|
|
822
822
|
|
|
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
|
-
}
|
|
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
|
+
}
|
|
833
833
|
|
|
834
834
|
async function uploadImage(
|
|
835
835
|
token: string,
|