chatccc 0.2.10 → 0.2.11
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 +63 -11
- package/package.json +4 -1
- package/src/__tests__/cards.test.ts +1 -1
- package/src/__tests__/codex-adapter.test.ts +305 -0
- package/src/__tests__/fixtures/codex_simple_text.jsonl +4 -0
- package/src/__tests__/fixtures/codex_with_tool.jsonl +6 -0
- package/src/adapters/codex-adapter.ts +294 -0
- package/src/adapters/codex-session-meta-store.ts +131 -0
- package/src/cards.ts +28 -7
- package/src/config.ts +4 -0
- package/src/feishu-api.ts +115 -16
- package/src/index.ts +98 -20
- package/src/session.ts +28 -5
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// codex-adapter.ts — OpenAI Codex CLI 适配器
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// 通过 codex exec --json 与 Codex CLI 交互。
|
|
5
|
+
// - createSession: 生成 UUID sessionId,记录 cwd,不创建 Codex 线程(延迟到首次 prompt)
|
|
6
|
+
// - prompt: 首次调用用 codex exec 创建线程,后续用 codex exec resume 恢复
|
|
7
|
+
// - getSessionInfo: 从持久化映射读取 cwd / threadId
|
|
8
|
+
// =============================================================================
|
|
9
|
+
|
|
10
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
11
|
+
import { createInterface } from "node:readline";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
ToolAdapter,
|
|
16
|
+
UnifiedBlock,
|
|
17
|
+
UnifiedStreamMessage,
|
|
18
|
+
CreateSessionResult,
|
|
19
|
+
SessionInfo,
|
|
20
|
+
} from "./adapter-interface.ts";
|
|
21
|
+
import {
|
|
22
|
+
defaultCodexSessionMetaStore,
|
|
23
|
+
type CodexSessionMetaStore,
|
|
24
|
+
} from "./codex-session-meta-store.ts";
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// 命令与参数
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
/** 可通过 CHATCCC_CODEX_COMMAND 环境变量自定义 Codex 可执行文件路径 */
|
|
31
|
+
function detectCodexCommand(): string {
|
|
32
|
+
return process.env.CHATCCC_CODEX_COMMAND?.trim() || "codex";
|
|
33
|
+
}
|
|
34
|
+
const CODEX_COMMAND = detectCodexCommand();
|
|
35
|
+
|
|
36
|
+
/** exec 模式共用参数:JSONL 输出、绕过沙盒和确认、跳过 git 仓库检查 */
|
|
37
|
+
const CODEX_BASE_ARGS = [
|
|
38
|
+
"exec",
|
|
39
|
+
"--json",
|
|
40
|
+
"--dangerously-bypass-approvals-and-sandbox",
|
|
41
|
+
"--skip-git-repo-check",
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/** codex 模型 */
|
|
45
|
+
function resolveCodexModel(): string | null {
|
|
46
|
+
const m = process.env.CHATCCC_CODEX_MODEL?.trim();
|
|
47
|
+
return m && m !== "default" ? m : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** codex 努力程度(映射为 -c model_reasoning_effort=<value>) */
|
|
51
|
+
function resolveCodexEffort(): string | null {
|
|
52
|
+
const e = process.env.CHATCCC_CODEX_EFFORT?.trim();
|
|
53
|
+
return e && e !== "default" ? e : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// 类型:Codex JSONL 消息行
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
interface CodexItem {
|
|
61
|
+
id?: string;
|
|
62
|
+
type?: string;
|
|
63
|
+
text?: string;
|
|
64
|
+
command?: string;
|
|
65
|
+
aggregated_output?: string;
|
|
66
|
+
exit_code?: number | null;
|
|
67
|
+
status?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface CodexEvent {
|
|
71
|
+
type: string;
|
|
72
|
+
thread_id?: string;
|
|
73
|
+
item?: CodexItem;
|
|
74
|
+
usage?: {
|
|
75
|
+
input_tokens?: number;
|
|
76
|
+
cached_input_tokens?: number;
|
|
77
|
+
output_tokens?: number;
|
|
78
|
+
reasoning_output_tokens?: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// normalizeCodexMessage — Codex 事件 → UnifiedStreamMessage | null
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
export function normalizeCodexMessage(
|
|
87
|
+
msg: CodexEvent,
|
|
88
|
+
): UnifiedStreamMessage | null {
|
|
89
|
+
// agent_message 文本回复
|
|
90
|
+
if (
|
|
91
|
+
msg.type === "item.completed" &&
|
|
92
|
+
msg.item?.type === "agent_message" &&
|
|
93
|
+
msg.item.text
|
|
94
|
+
) {
|
|
95
|
+
return {
|
|
96
|
+
type: "assistant",
|
|
97
|
+
blocks: [{ type: "text", text: msg.item.text }],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// command_execution 工具调用开始
|
|
102
|
+
if (
|
|
103
|
+
msg.type === "item.started" &&
|
|
104
|
+
msg.item?.type === "command_execution" &&
|
|
105
|
+
msg.item.command
|
|
106
|
+
) {
|
|
107
|
+
return {
|
|
108
|
+
type: "assistant",
|
|
109
|
+
blocks: [
|
|
110
|
+
{
|
|
111
|
+
type: "tool_use",
|
|
112
|
+
name: "Bash",
|
|
113
|
+
input: { command: msg.item.command },
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// command_execution 工具调用完成
|
|
120
|
+
if (
|
|
121
|
+
msg.type === "item.completed" &&
|
|
122
|
+
msg.item?.type === "command_execution"
|
|
123
|
+
) {
|
|
124
|
+
const exitCode = msg.item.exit_code;
|
|
125
|
+
return {
|
|
126
|
+
type: "assistant",
|
|
127
|
+
blocks: [
|
|
128
|
+
{
|
|
129
|
+
type: "tool_result",
|
|
130
|
+
tool_use_id: msg.item.id ?? "",
|
|
131
|
+
content: msg.item.aggregated_output ?? "",
|
|
132
|
+
is_error: exitCode != null && exitCode !== 0 ? true : undefined,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// thread.started / turn.started / turn.completed → 不映射为用户可见消息
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// 子进程辅助函数
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
function spawnCodex(
|
|
147
|
+
args: string[],
|
|
148
|
+
cwd?: string,
|
|
149
|
+
stdinText?: string,
|
|
150
|
+
): ChildProcess {
|
|
151
|
+
const allArgs = [...args];
|
|
152
|
+
const model = resolveCodexModel();
|
|
153
|
+
if (model) {
|
|
154
|
+
// 把 -m 插在 exec 后面、其他参数前面
|
|
155
|
+
const execIdx = allArgs.indexOf("exec");
|
|
156
|
+
allArgs.splice(execIdx + 1, 0, "-m", model);
|
|
157
|
+
}
|
|
158
|
+
const effort = resolveCodexEffort();
|
|
159
|
+
if (effort) {
|
|
160
|
+
allArgs.push("-c", `model_reasoning_effort="${effort}"`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const proc = spawn(CODEX_COMMAND, allArgs, {
|
|
164
|
+
cwd,
|
|
165
|
+
stdio: [stdinText !== undefined ? "pipe" : "ignore", "pipe", "pipe"],
|
|
166
|
+
windowsHide: true,
|
|
167
|
+
shell: true,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
let stderr = "";
|
|
171
|
+
proc.stderr!.on("data", (chunk: Buffer) => {
|
|
172
|
+
stderr += chunk.toString();
|
|
173
|
+
});
|
|
174
|
+
proc.on("close", (code) => {
|
|
175
|
+
if (code !== 0 && stderr.trim()) {
|
|
176
|
+
console.error(
|
|
177
|
+
`[Codex stderr] exit=${code}: ${stderr.trim().slice(0, 2000)}`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (stdinText !== undefined) {
|
|
183
|
+
proc.stdin!.write(stdinText);
|
|
184
|
+
proc.stdin!.end();
|
|
185
|
+
}
|
|
186
|
+
return proc;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function* readJsonLines(
|
|
190
|
+
proc: ChildProcess,
|
|
191
|
+
signal?: AbortSignal,
|
|
192
|
+
): AsyncGenerator<CodexEvent> {
|
|
193
|
+
const rl = createInterface({ input: proc.stdout!, crlfDelay: Infinity });
|
|
194
|
+
for await (const line of rl) {
|
|
195
|
+
if (signal?.aborted) break;
|
|
196
|
+
const trimmed = line.trim();
|
|
197
|
+
if (!trimmed) continue;
|
|
198
|
+
try {
|
|
199
|
+
yield JSON.parse(trimmed) as CodexEvent;
|
|
200
|
+
} catch {
|
|
201
|
+
// 非 JSON 行静默跳过(如 "Reading prompt from stdin...")
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
// 适配器实现
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
class CodexAdapter implements ToolAdapter {
|
|
211
|
+
readonly displayName = "Codex";
|
|
212
|
+
readonly sessionDescPrefix = "Codex Session:";
|
|
213
|
+
private metaStore: CodexSessionMetaStore;
|
|
214
|
+
|
|
215
|
+
constructor(metaStore: CodexSessionMetaStore) {
|
|
216
|
+
this.metaStore = metaStore;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// createSession: 生成 sessionId,记录 cwd,不创建 Codex 线程(延迟到首次 prompt)
|
|
220
|
+
async createSession(cwd: string): Promise<CreateSessionResult> {
|
|
221
|
+
const sessionId = randomUUID();
|
|
222
|
+
await this.metaStore.set(sessionId, { cwd });
|
|
223
|
+
return { sessionId };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async *prompt(
|
|
227
|
+
sessionId: string,
|
|
228
|
+
userText: string,
|
|
229
|
+
cwd: string,
|
|
230
|
+
signal?: AbortSignal,
|
|
231
|
+
): AsyncIterable<UnifiedStreamMessage> {
|
|
232
|
+
let meta = await this.metaStore.get(sessionId);
|
|
233
|
+
const threadId = meta?.threadId;
|
|
234
|
+
const isFirstPrompt = !threadId;
|
|
235
|
+
|
|
236
|
+
// 首次 prompt: codex exec 创建新线程
|
|
237
|
+
// 后续 prompt: codex exec resume 恢复已有线程(resume 不接受 -C,cwd 继承自原线程)
|
|
238
|
+
const args = isFirstPrompt
|
|
239
|
+
? [...CODEX_BASE_ARGS, "-C", cwd, "-"]
|
|
240
|
+
: [...CODEX_BASE_ARGS, "resume", threadId, "-"];
|
|
241
|
+
|
|
242
|
+
const proc = spawnCodex(args, cwd, userText);
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
for await (const raw of readJsonLines(proc, signal)) {
|
|
246
|
+
if (signal?.aborted) break;
|
|
247
|
+
|
|
248
|
+
// 首次 prompt 时从 thread.started 事件学习 threadId
|
|
249
|
+
if (
|
|
250
|
+
isFirstPrompt &&
|
|
251
|
+
raw.type === "thread.started" &&
|
|
252
|
+
raw.thread_id
|
|
253
|
+
) {
|
|
254
|
+
void this.metaStore
|
|
255
|
+
.setThreadId(sessionId, raw.thread_id)
|
|
256
|
+
.catch(() => {});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const normalized = normalizeCodexMessage(raw);
|
|
260
|
+
if (normalized) yield normalized;
|
|
261
|
+
}
|
|
262
|
+
} finally {
|
|
263
|
+
proc.kill();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async getSessionInfo(
|
|
268
|
+
sessionId: string,
|
|
269
|
+
): Promise<SessionInfo | undefined> {
|
|
270
|
+
const meta = await this.metaStore.get(sessionId);
|
|
271
|
+
if (!meta) return undefined;
|
|
272
|
+
return { sessionId, cwd: meta.cwd };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async closeSession(_sessionId: string): Promise<void> {
|
|
276
|
+
// no-op:子进程由 prompt 的 finally 自动 kill
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
// 工厂函数
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
|
|
284
|
+
export interface CreateCodexAdapterOptions {
|
|
285
|
+
metaStore?: CodexSessionMetaStore;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function createCodexAdapter(
|
|
289
|
+
options: CreateCodexAdapterOptions = {},
|
|
290
|
+
): ToolAdapter {
|
|
291
|
+
return new CodexAdapter(
|
|
292
|
+
options.metaStore ?? defaultCodexSessionMetaStore,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// codex-session-meta-store.ts — Codex 会话 sessionId → meta 持久化映射
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Codex CLI 没有 SDK 可查询会话元数据,ChatCCC 内部维护 sessionId → { cwd, threadId } 映射。
|
|
5
|
+
// threadId 在首次 prompt 时才生成(Codex 不支持"空会话"创建),存储用于后续 resume。
|
|
6
|
+
// =============================================================================
|
|
7
|
+
|
|
8
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
|
|
11
|
+
import { PROJECT_ROOT } from "../config.ts";
|
|
12
|
+
|
|
13
|
+
export const CODEX_SESSION_META_FILE = join(
|
|
14
|
+
PROJECT_ROOT,
|
|
15
|
+
".claude",
|
|
16
|
+
"codex-session-meta.json",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export interface CodexSessionMeta {
|
|
20
|
+
cwd: string;
|
|
21
|
+
threadId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CodexSessionMetaStore {
|
|
25
|
+
get(sessionId: string): Promise<CodexSessionMeta | undefined>;
|
|
26
|
+
set(sessionId: string, partial: Partial<CodexSessionMeta>): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* 只更新 threadId(高频操作:prompt 首次调用时写入)。
|
|
29
|
+
* 与 set 的区别:不重新读写完整文件,内联到已有的 load→merge→save 流程。
|
|
30
|
+
*/
|
|
31
|
+
setThreadId(sessionId: string, threadId: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface RawEntry {
|
|
35
|
+
cwd?: string;
|
|
36
|
+
threadId?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isNonEmptyString(v: unknown): v is string {
|
|
40
|
+
return typeof v === "string" && v.length > 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseEntry(raw: unknown): RawEntry | null {
|
|
44
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
45
|
+
const obj = raw as Record<string, unknown>;
|
|
46
|
+
const out: RawEntry = {};
|
|
47
|
+
if (isNonEmptyString(obj.cwd)) out.cwd = obj.cwd;
|
|
48
|
+
if (isNonEmptyString(obj.threadId)) out.threadId = obj.threadId;
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createCodexSessionMetaStore(
|
|
55
|
+
filePath: string = CODEX_SESSION_META_FILE,
|
|
56
|
+
): CodexSessionMetaStore {
|
|
57
|
+
let cache: Record<string, RawEntry> | null = null;
|
|
58
|
+
|
|
59
|
+
async function load(): Promise<Record<string, RawEntry>> {
|
|
60
|
+
if (cache) return cache;
|
|
61
|
+
try {
|
|
62
|
+
const raw = await readFile(filePath, "utf-8");
|
|
63
|
+
const parsed = JSON.parse(raw);
|
|
64
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
65
|
+
const out: Record<string, RawEntry> = {};
|
|
66
|
+
for (const [k, v] of Object.entries(parsed as Record<string, unknown>)) {
|
|
67
|
+
const entry = parseEntry(v);
|
|
68
|
+
if (entry) out[k] = entry;
|
|
69
|
+
}
|
|
70
|
+
cache = out;
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// 文件不存在或损坏
|
|
75
|
+
}
|
|
76
|
+
cache = {};
|
|
77
|
+
return cache;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function save(map: Record<string, RawEntry>): Promise<void> {
|
|
81
|
+
try {
|
|
82
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
83
|
+
await writeFile(filePath, JSON.stringify(map, null, 2), "utf-8");
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(
|
|
86
|
+
`[codex-session-meta] failed to persist ${filePath}: ${(err as Error).message}`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
async get(sessionId: string): Promise<CodexSessionMeta | undefined> {
|
|
93
|
+
const map = await load();
|
|
94
|
+
const entry = map[sessionId];
|
|
95
|
+
if (!entry || !isNonEmptyString(entry.cwd)) return undefined;
|
|
96
|
+
return entry.threadId
|
|
97
|
+
? { cwd: entry.cwd, threadId: entry.threadId }
|
|
98
|
+
: { cwd: entry.cwd };
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
async set(
|
|
102
|
+
sessionId: string,
|
|
103
|
+
partial: Partial<CodexSessionMeta>,
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
const map = await load();
|
|
106
|
+
const existing = map[sessionId] ?? {};
|
|
107
|
+
const merged: RawEntry = { ...existing };
|
|
108
|
+
if (isNonEmptyString(partial.cwd)) merged.cwd = partial.cwd;
|
|
109
|
+
if (isNonEmptyString(partial.threadId)) merged.threadId = partial.threadId;
|
|
110
|
+
|
|
111
|
+
if (existing.cwd === merged.cwd && existing.threadId === merged.threadId) return;
|
|
112
|
+
|
|
113
|
+
map[sessionId] = merged;
|
|
114
|
+
await save(map);
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
async setThreadId(
|
|
118
|
+
sessionId: string,
|
|
119
|
+
threadId: string,
|
|
120
|
+
): Promise<void> {
|
|
121
|
+
const map = await load();
|
|
122
|
+
const existing = map[sessionId] ?? {};
|
|
123
|
+
if (existing.threadId === threadId) return;
|
|
124
|
+
const merged: RawEntry = { ...existing, threadId };
|
|
125
|
+
map[sessionId] = merged;
|
|
126
|
+
await save(map);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const defaultCodexSessionMetaStore = createCodexSessionMetaStore();
|
package/src/cards.ts
CHANGED
|
@@ -108,16 +108,25 @@ export function buildProgressCard(
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export function buildHelpCard(userText: string): string {
|
|
111
|
+
export function buildHelpCard(userText: string, opts: { greeting?: string } = {}): string {
|
|
112
|
+
const greeting = opts.greeting ?? `你发送了: ${userText}`;
|
|
113
|
+
const lines = [
|
|
114
|
+
"发送 **/new** 创建新会话(默认 Claude Code)",
|
|
115
|
+
"发送 **/new claude** 创建新 Claude 对话",
|
|
116
|
+
"发送 **/new cursor** 创建新 Cursor 会话",
|
|
117
|
+
"发送 **/new codex** 创建新 Codex 会话",
|
|
118
|
+
"发送 **/forget** 重置当前会话(保留工作目录,同一群内继续)",
|
|
119
|
+
].join("\n");
|
|
112
120
|
return JSON.stringify({
|
|
113
121
|
config: { wide_screen_mode: true },
|
|
114
122
|
header: { template: "blue", title: { content: "ChatCCC", tag: "plain_text" } },
|
|
115
123
|
elements: [
|
|
116
|
-
{ tag: "div", text: { tag: "lark_md", content:
|
|
117
|
-
{ tag: "div", text: { tag: "lark_md", content:
|
|
124
|
+
{ tag: "div", text: { tag: "lark_md", content: greeting } },
|
|
125
|
+
{ tag: "div", text: { tag: "lark_md", content: lines } },
|
|
118
126
|
buildButtons([
|
|
119
127
|
{ text: "新建 Claude Code 会话(/new claude)", value: JSON.stringify({ cmd: "new" }), type: "primary" },
|
|
120
128
|
{ text: "新建 Cursor 会话(/new cursor)", value: JSON.stringify({ cmd: "new cursor" }), type: "primary" },
|
|
129
|
+
{ text: "新建 Codex 会话(/new codex)", value: JSON.stringify({ cmd: "new codex" }), type: "primary" },
|
|
121
130
|
{ text: "重启 ChatCCC(/restart)", value: JSON.stringify({ cmd: "restart" }), type: "danger" },
|
|
122
131
|
{ text: "切换工作路径(/cd)", value: JSON.stringify({ cmd: "cd" }), type: "default" },
|
|
123
132
|
]),
|
|
@@ -247,18 +256,20 @@ export function buildSessionsCard(sessions: Array<{
|
|
|
247
256
|
model: string;
|
|
248
257
|
tool: string;
|
|
249
258
|
}>): string {
|
|
250
|
-
// 按 tool 分组排序:Claude Code 在前,Cursor
|
|
251
|
-
const claudeCodeSessions = sessions.filter(s => s.tool !== "cursor");
|
|
259
|
+
// 按 tool 分组排序:Claude Code 在前,Cursor 其次,Codex 最后
|
|
260
|
+
const claudeCodeSessions = sessions.filter(s => s.tool !== "cursor" && s.tool !== "codex");
|
|
252
261
|
const cursorSessions = sessions.filter(s => s.tool === "cursor");
|
|
262
|
+
const codexSessions = sessions.filter(s => s.tool === "codex");
|
|
253
263
|
const hasClaudeCode = claudeCodeSessions.length > 0;
|
|
254
264
|
const hasCursor = cursorSessions.length > 0;
|
|
265
|
+
const hasCodex = codexSessions.length > 0;
|
|
255
266
|
|
|
256
267
|
if (sessions.length === 0) {
|
|
257
268
|
return JSON.stringify({
|
|
258
269
|
config: { wide_screen_mode: true },
|
|
259
270
|
header: { template: "blue", title: { content: "所有会话", tag: "plain_text" } },
|
|
260
271
|
elements: [
|
|
261
|
-
{ tag: "div", text: { tag: "lark_md", content: "当前没有会话记录。\n\n使用 **/new**(默认 Claude Code)、**/new claude** 或 **/new
|
|
272
|
+
{ tag: "div", text: { tag: "lark_md", content: "当前没有会话记录。\n\n使用 **/new**(默认 Claude Code)、**/new claude**、**/new cursor** 或 **/new codex** 创建新会话。" } },
|
|
262
273
|
{ tag: "hr" },
|
|
263
274
|
{ tag: "action", actions: [{ tag: "button", text: { tag: "plain_text", content: "收起" }, type: "default", value: { action: "close" } }] },
|
|
264
275
|
],
|
|
@@ -274,7 +285,7 @@ export function buildSessionsCard(sessions: Array<{
|
|
|
274
285
|
const secs = s.elapsedSeconds % 60;
|
|
275
286
|
extra = ` | 本轮: ${mins}分${secs}秒`;
|
|
276
287
|
}
|
|
277
|
-
const toolLabel = s.tool === "cursor" ? "Cursor" : "Claude Code";
|
|
288
|
+
const toolLabel = s.tool === "cursor" ? "Cursor" : s.tool === "codex" ? "Codex" : "Claude Code";
|
|
278
289
|
return `**${i + 1}.** \`${shortId}\` ${status} | 工具: ${toolLabel} | 轮数: ${s.turnCount} | ${s.model}${extra}`;
|
|
279
290
|
};
|
|
280
291
|
|
|
@@ -296,12 +307,22 @@ export function buildSessionsCard(sessions: Array<{
|
|
|
296
307
|
}
|
|
297
308
|
}
|
|
298
309
|
|
|
310
|
+
if (hasCodex) {
|
|
311
|
+
if (hasClaudeCode || hasCursor) lines.push("", "**Codex 会话:**", "");
|
|
312
|
+
else lines.push("**Codex 会话:**", "");
|
|
313
|
+
for (const s of codexSessions) {
|
|
314
|
+
lines.push(formatSession(s, idx++));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
299
318
|
return JSON.stringify({
|
|
300
319
|
config: { wide_screen_mode: true },
|
|
301
320
|
header: { template: "blue", title: { content: "所有会话", tag: "plain_text" } },
|
|
302
321
|
elements: [
|
|
303
322
|
{ tag: "div", text: { tag: "lark_md", content: lines.join("\n") } },
|
|
304
323
|
{ tag: "hr" },
|
|
324
|
+
{ tag: "div", text: { tag: "lark_md", content: "在会话群内发送 **/forget** 可重置当前会话(创建新 Session,保留工作目录和群聊)。" } },
|
|
325
|
+
{ tag: "hr" },
|
|
305
326
|
{
|
|
306
327
|
tag: "action",
|
|
307
328
|
actions: [{
|
package/src/config.ts
CHANGED
|
@@ -364,15 +364,19 @@ export function explainMissingFeishuCredentialsAndExit(): never {
|
|
|
364
364
|
export const CLAUDE_SESSION_PREFIX = "Claude Code Session:";
|
|
365
365
|
/** 群描述中用于识别 Cursor 会话的前缀 */
|
|
366
366
|
export const CURSOR_SESSION_PREFIX = "Cursor Session:";
|
|
367
|
+
/** 群描述中用于识别 Codex 会话的前缀 */
|
|
368
|
+
export const CODEX_SESSION_PREFIX = "Codex Session:";
|
|
367
369
|
|
|
368
370
|
/** 根据 tool 名称返回对应的群描述前缀 */
|
|
369
371
|
export function sessionPrefixForTool(tool: string): string {
|
|
370
372
|
if (tool === "cursor") return CURSOR_SESSION_PREFIX;
|
|
373
|
+
if (tool === "codex") return CODEX_SESSION_PREFIX;
|
|
371
374
|
return CLAUDE_SESSION_PREFIX;
|
|
372
375
|
}
|
|
373
376
|
|
|
374
377
|
/** 根据 tool 名称返回用于状态展示的标签 */
|
|
375
378
|
export function toolDisplayName(tool: string): string {
|
|
376
379
|
if (tool === "cursor") return "Cursor";
|
|
380
|
+
if (tool === "codex") return "Codex";
|
|
377
381
|
return "Claude Code";
|
|
378
382
|
}
|