@love-moon/conductor-cli 0.1.0
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/bin/conductor-chrome.js +376 -0
- package/bin/conductor-config.js +82 -0
- package/bin/conductor-daemon.js +67 -0
- package/bin/conductor-fire.js +903 -0
- package/package.json +34 -0
- package/src/daemon.js +376 -0
- package/src/fire/history.js +605 -0
- package/src/pageAutomation.js +131 -0
- package/src/providers/deepseek.js +405 -0
- package/src/providers/generic.js +6 -0
- package/src/providers/qwen.js +203 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { promises as fsp } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import readline from "node:readline";
|
|
6
|
+
import enquirer from "enquirer";
|
|
7
|
+
|
|
8
|
+
const { Select } = enquirer;
|
|
9
|
+
|
|
10
|
+
const SUPPORTED_FROM_PROVIDERS = ["codex", "claude"];
|
|
11
|
+
const DEFAULT_HISTORY_LIMIT = 50;
|
|
12
|
+
const DEFAULT_SESSION_LIMIT = 20;
|
|
13
|
+
|
|
14
|
+
export function parseFromSpec(rawFrom, rawProvider, defaultProvider) {
|
|
15
|
+
if (!rawFrom) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const providerOverride = rawProvider ? String(rawProvider).trim().toLowerCase() : "";
|
|
20
|
+
if (providerOverride && !SUPPORTED_FROM_PROVIDERS.includes(providerOverride)) {
|
|
21
|
+
throw new Error(`Unsupported --from-provider: ${rawProvider}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (rawFrom === true) {
|
|
25
|
+
const provider = providerOverride || defaultProvider;
|
|
26
|
+
if (!provider) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"Missing provider for --from. Use --from <provider>:<sessionId> or --from-provider <provider>."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return { provider, sessionId: "" };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const text = typeof rawFrom === "string" ? rawFrom.trim() : "";
|
|
35
|
+
if (!text) {
|
|
36
|
+
const provider = providerOverride || defaultProvider;
|
|
37
|
+
if (!provider) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return { provider, sessionId: "" };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let provider = providerOverride || "";
|
|
44
|
+
let sessionId = text;
|
|
45
|
+
|
|
46
|
+
const colonIndex = text.indexOf(":");
|
|
47
|
+
if (colonIndex > 0) {
|
|
48
|
+
const maybeProvider = text.slice(0, colonIndex).trim().toLowerCase();
|
|
49
|
+
const maybeSession = text.slice(colonIndex + 1).trim();
|
|
50
|
+
if (SUPPORTED_FROM_PROVIDERS.includes(maybeProvider)) {
|
|
51
|
+
provider = maybeProvider;
|
|
52
|
+
sessionId = maybeSession;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!provider) {
|
|
57
|
+
provider = defaultProvider || "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!provider) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"Missing provider for --from. Use --from <provider>:<sessionId> or --from-provider <provider>."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!sessionId) {
|
|
67
|
+
return { provider, sessionId: "" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { provider, sessionId };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function loadHistoryFromSpec(spec, options = {}) {
|
|
74
|
+
if (!spec) {
|
|
75
|
+
return { history: [], source: null, provider: null, sessionId: null };
|
|
76
|
+
}
|
|
77
|
+
const provider = spec.provider;
|
|
78
|
+
if (!SUPPORTED_FROM_PROVIDERS.includes(provider)) {
|
|
79
|
+
throw new Error(`Unsupported --from provider: ${provider}`);
|
|
80
|
+
}
|
|
81
|
+
if (provider === "codex") {
|
|
82
|
+
return loadCodexHistory(spec.sessionId, options);
|
|
83
|
+
}
|
|
84
|
+
return loadClaudeHistory(spec.sessionId, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function listHistorySessions(provider, options = {}) {
|
|
88
|
+
if (!SUPPORTED_FROM_PROVIDERS.includes(provider)) {
|
|
89
|
+
throw new Error(`Unsupported --from provider: ${provider}`);
|
|
90
|
+
}
|
|
91
|
+
if (provider === "codex") {
|
|
92
|
+
return listCodexSessions(options);
|
|
93
|
+
}
|
|
94
|
+
return listClaudeSessions(options);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function selectHistorySession(provider, options = {}) {
|
|
98
|
+
const sessions = await listHistorySessions(provider, options);
|
|
99
|
+
if (!sessions.length) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
103
|
+
throw new Error("Interactive --from requires a TTY.");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const choices = sessions.map((session) => ({
|
|
107
|
+
name: session.sessionId,
|
|
108
|
+
message: formatSessionLine(session),
|
|
109
|
+
value: session
|
|
110
|
+
}));
|
|
111
|
+
choices.push({
|
|
112
|
+
name: "__cancel__",
|
|
113
|
+
message: "Cancel",
|
|
114
|
+
value: null
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const prompt = new Select({
|
|
118
|
+
name: "session",
|
|
119
|
+
message: `Select a ${provider} session to resume`,
|
|
120
|
+
choices,
|
|
121
|
+
initial: 0
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const selected = await prompt.run();
|
|
125
|
+
return selected || null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function resolveHomeDir(options) {
|
|
129
|
+
if (options?.homeDir) {
|
|
130
|
+
return options.homeDir;
|
|
131
|
+
}
|
|
132
|
+
return os.homedir();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function trimHistory(history, limit) {
|
|
136
|
+
const max = Number.isFinite(limit) ? Math.max(1, limit) : DEFAULT_HISTORY_LIMIT;
|
|
137
|
+
if (history.length <= max) {
|
|
138
|
+
return history;
|
|
139
|
+
}
|
|
140
|
+
return history.slice(history.length - max);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function loadCodexHistory(sessionId, options = {}) {
|
|
144
|
+
const homeDir = resolveHomeDir(options);
|
|
145
|
+
const sessionsDir = options.codexSessionsDir || path.join(homeDir, ".codex", "sessions");
|
|
146
|
+
const sessionFile = await findCodexSessionFile(sessionsDir, sessionId);
|
|
147
|
+
|
|
148
|
+
if (!sessionFile) {
|
|
149
|
+
return {
|
|
150
|
+
provider: "codex",
|
|
151
|
+
sessionId,
|
|
152
|
+
history: [],
|
|
153
|
+
source: null,
|
|
154
|
+
warning: `Codex session file not found for ${sessionId}`
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const messages = [];
|
|
159
|
+
const rl = readline.createInterface({
|
|
160
|
+
input: fs.createReadStream(sessionFile),
|
|
161
|
+
crlfDelay: Infinity
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
for await (const line of rl) {
|
|
165
|
+
const trimmed = line.trim();
|
|
166
|
+
if (!trimmed) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
let entry;
|
|
170
|
+
try {
|
|
171
|
+
entry = JSON.parse(trimmed);
|
|
172
|
+
} catch {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (entry.type === "event_msg" && entry.payload?.type === "user_message") {
|
|
177
|
+
const content = String(entry.payload.message || "").trim();
|
|
178
|
+
if (content) {
|
|
179
|
+
messages.push({
|
|
180
|
+
role: "user",
|
|
181
|
+
content,
|
|
182
|
+
timestamp: entry.timestamp || Date.now()
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (entry.type === "response_item" && entry.payload?.type === "message") {
|
|
189
|
+
const role = entry.payload.role || "assistant";
|
|
190
|
+
const textContent = extractCodexText(entry.payload.content);
|
|
191
|
+
if (!textContent || textContent.includes("<environment_context>")) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (textContent.trim()) {
|
|
195
|
+
messages.push({
|
|
196
|
+
role: role === "user" ? "user" : "assistant",
|
|
197
|
+
content: textContent.trim(),
|
|
198
|
+
timestamp: entry.timestamp || Date.now()
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const history = trimHistory(
|
|
205
|
+
messages
|
|
206
|
+
.sort((a, b) => new Date(a.timestamp || 0) - new Date(b.timestamp || 0))
|
|
207
|
+
.map(({ role, content }) => ({ role, content })),
|
|
208
|
+
options.maxMessages
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
provider: "codex",
|
|
213
|
+
sessionId,
|
|
214
|
+
history,
|
|
215
|
+
source: sessionFile
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function listCodexSessions(options = {}) {
|
|
220
|
+
const homeDir = resolveHomeDir(options);
|
|
221
|
+
const sessionsDir = options.codexSessionsDir || path.join(homeDir, ".codex", "sessions");
|
|
222
|
+
const jsonlFiles = await findJsonlFiles(sessionsDir);
|
|
223
|
+
const sessions = [];
|
|
224
|
+
|
|
225
|
+
for (const filePath of jsonlFiles) {
|
|
226
|
+
const session = await parseCodexSessionFile(filePath);
|
|
227
|
+
if (session) {
|
|
228
|
+
sessions.push(session);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
sessions.sort((a, b) => new Date(b.lastActivity || 0) - new Date(a.lastActivity || 0));
|
|
233
|
+
return sessions.slice(0, options.sessionLimit ?? DEFAULT_SESSION_LIMIT);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function loadClaudeHistory(sessionId, options = {}) {
|
|
237
|
+
const homeDir = resolveHomeDir(options);
|
|
238
|
+
const projectsDir = options.claudeProjectsDir || path.join(homeDir, ".claude", "projects");
|
|
239
|
+
const sessionEntries = await findClaudeSessionEntries(projectsDir, sessionId);
|
|
240
|
+
|
|
241
|
+
if (!sessionEntries.length) {
|
|
242
|
+
return {
|
|
243
|
+
provider: "claude",
|
|
244
|
+
sessionId,
|
|
245
|
+
history: [],
|
|
246
|
+
source: null,
|
|
247
|
+
warning: `Claude session not found for ${sessionId}`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const history = [];
|
|
252
|
+
const sorted = sessionEntries.sort(
|
|
253
|
+
(a, b) => new Date(a.timestamp || 0) - new Date(b.timestamp || 0)
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
for (const entry of sorted) {
|
|
257
|
+
const message = entry.message;
|
|
258
|
+
if (!message || !message.role || !message.content) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const role = String(message.role).toLowerCase();
|
|
262
|
+
if (role !== "user" && role !== "assistant") {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const content = extractClaudeText(message.content);
|
|
266
|
+
if (!content) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (shouldSkipClaudeMessage(content)) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
history.push({ role, content });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
provider: "claude",
|
|
277
|
+
sessionId,
|
|
278
|
+
history: trimHistory(history, options.maxMessages),
|
|
279
|
+
source: sessionEntries[0]?.source || null
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function listClaudeSessions(options = {}) {
|
|
284
|
+
const homeDir = resolveHomeDir(options);
|
|
285
|
+
const projectsDir = options.claudeProjectsDir || path.join(homeDir, ".claude", "projects");
|
|
286
|
+
const sessions = new Map();
|
|
287
|
+
|
|
288
|
+
let projectDirs = [];
|
|
289
|
+
try {
|
|
290
|
+
projectDirs = await fsp.readdir(projectsDir, { withFileTypes: true });
|
|
291
|
+
} catch {
|
|
292
|
+
return [];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
for (const projectDir of projectDirs) {
|
|
296
|
+
if (!projectDir.isDirectory()) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const projectPath = path.join(projectsDir, projectDir.name);
|
|
300
|
+
let files = [];
|
|
301
|
+
try {
|
|
302
|
+
files = await fsp.readdir(projectPath, { withFileTypes: true });
|
|
303
|
+
} catch {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
for (const file of files) {
|
|
308
|
+
if (!file.isFile()) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (!file.name.endsWith(".jsonl") || file.name.startsWith("agent-")) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const filePath = path.join(projectPath, file.name);
|
|
315
|
+
const rl = readline.createInterface({
|
|
316
|
+
input: fs.createReadStream(filePath),
|
|
317
|
+
crlfDelay: Infinity
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
for await (const line of rl) {
|
|
321
|
+
const trimmed = line.trim();
|
|
322
|
+
if (!trimmed) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
let entry;
|
|
326
|
+
try {
|
|
327
|
+
entry = JSON.parse(trimmed);
|
|
328
|
+
} catch {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (!entry.sessionId) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const sessionId = entry.sessionId;
|
|
335
|
+
const record = sessions.get(sessionId) || {
|
|
336
|
+
provider: "claude",
|
|
337
|
+
sessionId,
|
|
338
|
+
projectName: projectDir.name,
|
|
339
|
+
summary: "Claude Session",
|
|
340
|
+
lastActivity: null,
|
|
341
|
+
messageCount: 0,
|
|
342
|
+
source: filePath
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
if (entry.timestamp) {
|
|
346
|
+
record.lastActivity = entry.timestamp;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (entry.message?.role && entry.message?.content) {
|
|
350
|
+
const content = extractClaudeText(entry.message.content);
|
|
351
|
+
if (content && !shouldSkipClaudeMessage(content)) {
|
|
352
|
+
record.messageCount += 1;
|
|
353
|
+
if (entry.message.role === "user") {
|
|
354
|
+
record.summary = truncateSummary(content);
|
|
355
|
+
} else if (record.summary === "Claude Session") {
|
|
356
|
+
record.summary = truncateSummary(content);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
sessions.set(sessionId, record);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const list = Array.from(sessions.values());
|
|
367
|
+
list.sort((a, b) => new Date(b.lastActivity || 0) - new Date(a.lastActivity || 0));
|
|
368
|
+
return list.slice(0, options.sessionLimit ?? DEFAULT_SESSION_LIMIT);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function findCodexSessionFile(rootDir, sessionId) {
|
|
372
|
+
const queue = [rootDir];
|
|
373
|
+
while (queue.length) {
|
|
374
|
+
const current = queue.pop();
|
|
375
|
+
let entries = [];
|
|
376
|
+
try {
|
|
377
|
+
entries = await fsp.readdir(current, { withFileTypes: true });
|
|
378
|
+
} catch {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
for (const entry of entries) {
|
|
382
|
+
const fullPath = path.join(current, entry.name);
|
|
383
|
+
if (entry.isDirectory()) {
|
|
384
|
+
queue.push(fullPath);
|
|
385
|
+
} else if (
|
|
386
|
+
entry.isFile() &&
|
|
387
|
+
entry.name.includes(sessionId) &&
|
|
388
|
+
entry.name.endsWith(".jsonl")
|
|
389
|
+
) {
|
|
390
|
+
return fullPath;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async function findClaudeSessionEntries(projectsDir, sessionId) {
|
|
398
|
+
const entries = [];
|
|
399
|
+
let projectDirs = [];
|
|
400
|
+
try {
|
|
401
|
+
projectDirs = await fsp.readdir(projectsDir, { withFileTypes: true });
|
|
402
|
+
} catch {
|
|
403
|
+
return entries;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
for (const projectDir of projectDirs) {
|
|
407
|
+
if (!projectDir.isDirectory()) {
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const projectPath = path.join(projectsDir, projectDir.name);
|
|
411
|
+
let files = [];
|
|
412
|
+
try {
|
|
413
|
+
files = await fsp.readdir(projectPath, { withFileTypes: true });
|
|
414
|
+
} catch {
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
for (const file of files) {
|
|
419
|
+
if (!file.isFile()) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (!file.name.endsWith(".jsonl") || file.name.startsWith("agent-")) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const filePath = path.join(projectPath, file.name);
|
|
427
|
+
const rl = readline.createInterface({
|
|
428
|
+
input: fs.createReadStream(filePath),
|
|
429
|
+
crlfDelay: Infinity
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
for await (const line of rl) {
|
|
433
|
+
const trimmed = line.trim();
|
|
434
|
+
if (!trimmed) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
let entry;
|
|
438
|
+
try {
|
|
439
|
+
entry = JSON.parse(trimmed);
|
|
440
|
+
} catch {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (entry.sessionId === sessionId) {
|
|
444
|
+
entries.push({ ...entry, source: filePath });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return entries;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async function findJsonlFiles(rootDir) {
|
|
454
|
+
const files = [];
|
|
455
|
+
const queue = [rootDir];
|
|
456
|
+
while (queue.length) {
|
|
457
|
+
const current = queue.pop();
|
|
458
|
+
let entries = [];
|
|
459
|
+
try {
|
|
460
|
+
entries = await fsp.readdir(current, { withFileTypes: true });
|
|
461
|
+
} catch {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
for (const entry of entries) {
|
|
465
|
+
const fullPath = path.join(current, entry.name);
|
|
466
|
+
if (entry.isDirectory()) {
|
|
467
|
+
queue.push(fullPath);
|
|
468
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
469
|
+
files.push(fullPath);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return files;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async function parseCodexSessionFile(filePath) {
|
|
477
|
+
const fileStream = fs.createReadStream(filePath);
|
|
478
|
+
const rl = readline.createInterface({
|
|
479
|
+
input: fileStream,
|
|
480
|
+
crlfDelay: Infinity
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
let sessionMeta = null;
|
|
484
|
+
let lastTimestamp = null;
|
|
485
|
+
let lastUserMessage = null;
|
|
486
|
+
let messageCount = 0;
|
|
487
|
+
|
|
488
|
+
for await (const line of rl) {
|
|
489
|
+
if (!line.trim()) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
let entry;
|
|
493
|
+
try {
|
|
494
|
+
entry = JSON.parse(line);
|
|
495
|
+
} catch {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (entry.timestamp) {
|
|
500
|
+
lastTimestamp = entry.timestamp;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (entry.type === "session_meta" && entry.payload) {
|
|
504
|
+
sessionMeta = {
|
|
505
|
+
id: entry.payload.id,
|
|
506
|
+
cwd: entry.payload.cwd,
|
|
507
|
+
model: entry.payload.model || entry.payload.model_provider,
|
|
508
|
+
timestamp: entry.timestamp
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (entry.type === "event_msg" && entry.payload?.type === "user_message") {
|
|
513
|
+
messageCount += 1;
|
|
514
|
+
if (entry.payload.message) {
|
|
515
|
+
lastUserMessage = entry.payload.message;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (entry.type === "response_item" && entry.payload?.type === "message") {
|
|
520
|
+
messageCount += 1;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (!sessionMeta?.id) {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return {
|
|
529
|
+
provider: "codex",
|
|
530
|
+
sessionId: sessionMeta.id,
|
|
531
|
+
summary: lastUserMessage ? truncateSummary(lastUserMessage) : "Codex Session",
|
|
532
|
+
lastActivity: lastTimestamp || sessionMeta.timestamp,
|
|
533
|
+
messageCount,
|
|
534
|
+
cwd: sessionMeta.cwd,
|
|
535
|
+
model: sessionMeta.model,
|
|
536
|
+
source: filePath
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function extractCodexText(content) {
|
|
541
|
+
if (!Array.isArray(content)) {
|
|
542
|
+
return typeof content === "string" ? content : "";
|
|
543
|
+
}
|
|
544
|
+
return content
|
|
545
|
+
.map((item) => {
|
|
546
|
+
if (item?.type === "input_text" || item?.type === "output_text" || item?.type === "text") {
|
|
547
|
+
return item.text;
|
|
548
|
+
}
|
|
549
|
+
return "";
|
|
550
|
+
})
|
|
551
|
+
.filter(Boolean)
|
|
552
|
+
.join("\n");
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function extractClaudeText(content) {
|
|
556
|
+
if (Array.isArray(content)) {
|
|
557
|
+
const parts = content
|
|
558
|
+
.map((part) => {
|
|
559
|
+
if (part?.type === "text") {
|
|
560
|
+
return part.text;
|
|
561
|
+
}
|
|
562
|
+
return "";
|
|
563
|
+
})
|
|
564
|
+
.filter(Boolean);
|
|
565
|
+
return parts.join("\n").trim();
|
|
566
|
+
}
|
|
567
|
+
if (typeof content === "string") {
|
|
568
|
+
return content.trim();
|
|
569
|
+
}
|
|
570
|
+
return String(content || "").trim();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function shouldSkipClaudeMessage(content) {
|
|
574
|
+
if (!content) {
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
const trimmed = content.trim();
|
|
578
|
+
return (
|
|
579
|
+
trimmed.startsWith("<command-name>") ||
|
|
580
|
+
trimmed.startsWith("<command-message>") ||
|
|
581
|
+
trimmed.startsWith("<command-args>") ||
|
|
582
|
+
trimmed.startsWith("<local-command-stdout>") ||
|
|
583
|
+
trimmed.startsWith("<system-reminder>") ||
|
|
584
|
+
trimmed.startsWith("Caveat:") ||
|
|
585
|
+
trimmed.startsWith("This session is being continued from a previous") ||
|
|
586
|
+
trimmed.startsWith("[Request interrupted")
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function truncateSummary(value) {
|
|
591
|
+
const text = String(value || "").trim();
|
|
592
|
+
if (!text) {
|
|
593
|
+
return "";
|
|
594
|
+
}
|
|
595
|
+
return text.length > 60 ? `${text.slice(0, 60)}...` : text;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function formatSessionLine(session) {
|
|
599
|
+
const summary = session.summary || "Untitled session";
|
|
600
|
+
const when = session.lastActivity ? new Date(session.lastActivity).toLocaleString() : "unknown time";
|
|
601
|
+
const project = session.projectName ? ` · ${session.projectName}` : "";
|
|
602
|
+
return `${summary} (${session.sessionId}) · ${when}${project}`;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export { SUPPORTED_FROM_PROVIDERS };
|