@love-moon/conductor-cli 0.2.14 → 0.2.16

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.js CHANGED
@@ -16,7 +16,7 @@ import path from "node:path";
16
16
  import { createRequire } from "node:module";
17
17
  import fs from "node:fs";
18
18
  import yargs from "yargs/yargs";
19
- import { hideBin } from "yargs/helpers";
19
+ import { hideBin } from "yargs/helpers";
20
20
 
21
21
  const __filename = fileURLToPath(import.meta.url);
22
22
  const __dirname = path.dirname(__filename);
@@ -36,7 +36,8 @@ if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
36
36
 
37
37
  // If version flag, show version
38
38
  if (argv[0] === "--version" || argv[0] === "-v") {
39
- console.log(`conductor version ${pkgJson.version}`);
39
+ const commitId = pkgJson.gitCommitId || "unknown";
40
+ console.log(`conductor version ${pkgJson.version} (${commitId})`);
40
41
  process.exit(0);
41
42
  }
42
43
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@love-moon/conductor-cli",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
+ "gitCommitId": "13b4d6c",
4
5
  "type": "module",
5
6
  "bin": {
6
7
  "conductor": "bin/conductor.js"
@@ -16,8 +17,8 @@
16
17
  "test": "node --test"
17
18
  },
18
19
  "dependencies": {
19
- "@love-moon/tui-driver": "0.2.14",
20
- "@love-moon/conductor-sdk": "0.2.14",
20
+ "@love-moon/ai-sdk": "0.2.16",
21
+ "@love-moon/conductor-sdk": "0.2.16",
21
22
  "dotenv": "^16.4.5",
22
23
  "enquirer": "^2.4.1",
23
24
  "js-yaml": "^4.1.1",
@@ -28,8 +29,8 @@
28
29
  },
29
30
  "pnpm": {
30
31
  "overrides": {
31
- "@love-moon/tui-driver": "file:../modules/tui-driver",
32
- "@love-moon/conductor-sdk": "file:../modules/sdk"
32
+ "@love-moon/ai-sdk": "file:../modules/ai-sdk",
33
+ "@love-moon/conductor-sdk": "file:../modules/conductor-sdk"
33
34
  }
34
35
  }
35
36
  }
@@ -5,6 +5,13 @@ import path from "node:path";
5
5
  import readline from "node:readline";
6
6
  import enquirer from "enquirer";
7
7
 
8
+ export {
9
+ findClaudeSessionPath,
10
+ findCodexSessionPath,
11
+ findCopilotSessionPath,
12
+ findSessionPath,
13
+ } from "./resume.js";
14
+
8
15
  const { Select } = enquirer;
9
16
 
10
17
  const SUPPORTED_FROM_PROVIDERS = ["codex", "claude"];
@@ -125,73 +132,6 @@ export async function selectHistorySession(provider, options = {}) {
125
132
  return selected || null;
126
133
  }
127
134
 
128
- export async function findSessionPath(provider, sessionId, options = {}) {
129
- const normalizedProvider = String(provider || "").trim().toLowerCase();
130
- if (normalizedProvider === "codex") {
131
- return findCodexSessionPath(sessionId, options);
132
- }
133
- if (normalizedProvider === "claude") {
134
- return findClaudeSessionPath(sessionId, options);
135
- }
136
- if (normalizedProvider === "copilot") {
137
- return findCopilotSessionPath(sessionId, options);
138
- }
139
- throw new Error(`Unsupported provider: ${provider}`);
140
- }
141
-
142
- export async function findCodexSessionPath(sessionId, options = {}) {
143
- const normalizedSessionId = normalizeSessionId(sessionId);
144
- if (!normalizedSessionId) {
145
- return null;
146
- }
147
- const homeDir = resolveHomeDir(options);
148
- const sessionsDir = options.codexSessionsDir || path.join(homeDir, ".codex", "sessions");
149
- return findCodexSessionFile(sessionsDir, normalizedSessionId);
150
- }
151
-
152
- export async function findClaudeSessionPath(sessionId, options = {}) {
153
- const normalizedSessionId = normalizeSessionId(sessionId);
154
- if (!normalizedSessionId) {
155
- return null;
156
- }
157
-
158
- const homeDir = resolveHomeDir(options);
159
- const projectsDir = options.claudeProjectsDir || path.join(homeDir, ".claude", "projects");
160
- const sessionEntries = await findClaudeSessionEntries(projectsDir, normalizedSessionId);
161
- if (sessionEntries.length > 0) {
162
- return sessionEntries[0]?.source || null;
163
- }
164
-
165
- const tasksDir = options.claudeTasksDir || path.join(homeDir, ".claude", "tasks");
166
- const directTaskDir = path.join(tasksDir, normalizedSessionId);
167
- if (await pathExists(directTaskDir, "directory")) {
168
- return directTaskDir;
169
- }
170
-
171
- return null;
172
- }
173
-
174
- export async function findCopilotSessionPath(sessionId, options = {}) {
175
- const normalizedSessionId = normalizeSessionId(sessionId);
176
- if (!normalizedSessionId) {
177
- return null;
178
- }
179
-
180
- const homeDir = resolveHomeDir(options);
181
- const sessionStateDir = options.copilotSessionStateDir || path.join(homeDir, ".copilot", "session-state");
182
- const directJsonlPath = path.join(sessionStateDir, `${normalizedSessionId}.jsonl`);
183
- if (await pathExists(directJsonlPath, "file")) {
184
- return directJsonlPath;
185
- }
186
-
187
- const directSessionDir = path.join(sessionStateDir, normalizedSessionId);
188
- if (await pathExists(directSessionDir, "directory")) {
189
- return directSessionDir;
190
- }
191
-
192
- return findPathByName(sessionStateDir, normalizedSessionId);
193
- }
194
-
195
135
  function resolveHomeDir(options) {
196
136
  if (options?.homeDir) {
197
137
  return options.homeDir;
@@ -199,10 +139,6 @@ function resolveHomeDir(options) {
199
139
  return os.homedir();
200
140
  }
201
141
 
202
- function normalizeSessionId(sessionId) {
203
- return typeof sessionId === "string" ? sessionId.trim() : "";
204
- }
205
-
206
142
  function trimHistory(history, limit) {
207
143
  const max = Number.isFinite(limit) ? Math.max(1, limit) : DEFAULT_HISTORY_LIMIT;
208
144
  if (history.length <= max) {
@@ -544,44 +480,6 @@ async function findJsonlFiles(rootDir) {
544
480
  return files;
545
481
  }
546
482
 
547
- async function findPathByName(rootDir, sessionId) {
548
- const queue = [rootDir];
549
- while (queue.length) {
550
- const current = queue.pop();
551
- let entries = [];
552
- try {
553
- entries = await fsp.readdir(current, { withFileTypes: true });
554
- } catch {
555
- continue;
556
- }
557
- for (const entry of entries) {
558
- const fullPath = path.join(current, entry.name);
559
- if (entry.name.includes(sessionId)) {
560
- return fullPath;
561
- }
562
- if (entry.isDirectory()) {
563
- queue.push(fullPath);
564
- }
565
- }
566
- }
567
- return null;
568
- }
569
-
570
- async function pathExists(targetPath, expectedType) {
571
- try {
572
- const stats = await fsp.stat(targetPath);
573
- if (expectedType === "file") {
574
- return stats.isFile();
575
- }
576
- if (expectedType === "directory") {
577
- return stats.isDirectory();
578
- }
579
- return true;
580
- } catch {
581
- return false;
582
- }
583
- }
584
-
585
483
  async function parseCodexSessionFile(filePath) {
586
484
  const fileStream = fs.createReadStream(filePath);
587
485
  const rl = readline.createInterface({
@@ -0,0 +1,420 @@
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
+
7
+ import yaml from "js-yaml";
8
+
9
+ function normalizeBackend(backend) {
10
+ return String(backend || "").trim().toLowerCase();
11
+ }
12
+
13
+ function resolveHomeDir(options) {
14
+ if (options?.homeDir) {
15
+ return options.homeDir;
16
+ }
17
+ return os.homedir();
18
+ }
19
+
20
+ function normalizeSessionId(sessionId) {
21
+ return typeof sessionId === "string" ? sessionId.trim() : "";
22
+ }
23
+
24
+ export function buildResumeArgsForBackend(backend, sessionId) {
25
+ const resumeSessionId = normalizeSessionId(sessionId);
26
+ if (!resumeSessionId) {
27
+ return [];
28
+ }
29
+ const normalizedBackend = normalizeBackend(backend);
30
+ if (normalizedBackend === "codex" || normalizedBackend === "code") {
31
+ return ["resume", resumeSessionId];
32
+ }
33
+ if (normalizedBackend === "claude" || normalizedBackend === "claude-code") {
34
+ return ["--resume", resumeSessionId];
35
+ }
36
+ if (normalizedBackend === "copilot") {
37
+ return [`--resume=${resumeSessionId}`];
38
+ }
39
+ throw new Error(`--resume is not supported for backend "${backend}"`);
40
+ }
41
+
42
+ export function resumeProviderForBackend(backend) {
43
+ const normalizedBackend = normalizeBackend(backend);
44
+ if (normalizedBackend === "codex" || normalizedBackend === "code") {
45
+ return "codex";
46
+ }
47
+ if (normalizedBackend === "claude" || normalizedBackend === "claude-code") {
48
+ return "claude";
49
+ }
50
+ if (normalizedBackend === "copilot") {
51
+ return "copilot";
52
+ }
53
+ return null;
54
+ }
55
+
56
+ export async function findSessionPath(provider, sessionId, options = {}) {
57
+ const normalizedProvider = String(provider || "").trim().toLowerCase();
58
+ if (normalizedProvider === "codex") {
59
+ return findCodexSessionPath(sessionId, options);
60
+ }
61
+ if (normalizedProvider === "claude") {
62
+ return findClaudeSessionPath(sessionId, options);
63
+ }
64
+ if (normalizedProvider === "copilot") {
65
+ return findCopilotSessionPath(sessionId, options);
66
+ }
67
+ throw new Error(`Unsupported provider: ${provider}`);
68
+ }
69
+
70
+ export async function findCodexSessionPath(sessionId, options = {}) {
71
+ const normalizedSessionId = normalizeSessionId(sessionId);
72
+ if (!normalizedSessionId) {
73
+ return null;
74
+ }
75
+ const homeDir = resolveHomeDir(options);
76
+ const sessionsDir = options.codexSessionsDir || path.join(homeDir, ".codex", "sessions");
77
+ return findCodexSessionFile(sessionsDir, normalizedSessionId);
78
+ }
79
+
80
+ export async function findClaudeSessionPath(sessionId, options = {}) {
81
+ const normalizedSessionId = normalizeSessionId(sessionId);
82
+ if (!normalizedSessionId) {
83
+ return null;
84
+ }
85
+
86
+ const homeDir = resolveHomeDir(options);
87
+ const projectsDir = options.claudeProjectsDir || path.join(homeDir, ".claude", "projects");
88
+ const sessionEntries = await findClaudeSessionEntries(projectsDir, normalizedSessionId);
89
+ if (sessionEntries.length > 0) {
90
+ return sessionEntries[0]?.source || null;
91
+ }
92
+
93
+ const tasksDir = options.claudeTasksDir || path.join(homeDir, ".claude", "tasks");
94
+ const directTaskDir = path.join(tasksDir, normalizedSessionId);
95
+ if (await pathExists(directTaskDir, "directory")) {
96
+ return directTaskDir;
97
+ }
98
+
99
+ return null;
100
+ }
101
+
102
+ export async function findCopilotSessionPath(sessionId, options = {}) {
103
+ const normalizedSessionId = normalizeSessionId(sessionId);
104
+ if (!normalizedSessionId) {
105
+ return null;
106
+ }
107
+
108
+ const homeDir = resolveHomeDir(options);
109
+ const sessionStateDir = options.copilotSessionStateDir || path.join(homeDir, ".copilot", "session-state");
110
+ const directJsonlPath = path.join(sessionStateDir, `${normalizedSessionId}.jsonl`);
111
+ if (await pathExists(directJsonlPath, "file")) {
112
+ return directJsonlPath;
113
+ }
114
+
115
+ const directSessionDir = path.join(sessionStateDir, normalizedSessionId);
116
+ if (await pathExists(directSessionDir, "directory")) {
117
+ return directSessionDir;
118
+ }
119
+
120
+ return findPathByName(sessionStateDir, normalizedSessionId);
121
+ }
122
+
123
+ export async function resolveSessionRunDirectory(sessionPath) {
124
+ const normalizedPath = typeof sessionPath === "string" ? sessionPath.trim() : "";
125
+ if (!normalizedPath) {
126
+ throw new Error("Invalid session path");
127
+ }
128
+ let stats;
129
+ try {
130
+ stats = await fsp.stat(normalizedPath);
131
+ } catch {
132
+ throw new Error(`Session path does not exist: ${normalizedPath}`);
133
+ }
134
+ return stats.isDirectory() ? normalizedPath : path.dirname(normalizedPath);
135
+ }
136
+
137
+ export async function inspectResumeTarget(backend, sessionId, options = {}) {
138
+ return resolveResumeContext(backend, sessionId, options);
139
+ }
140
+
141
+ export async function resolveResumeContext(backend, sessionId, options = {}) {
142
+ const normalizedSessionId = normalizeSessionId(sessionId);
143
+ if (!normalizedSessionId) {
144
+ throw new Error("--resume requires a session id");
145
+ }
146
+ const provider = resumeProviderForBackend(backend);
147
+ if (!provider) {
148
+ throw new Error(`--resume is not supported for backend "${backend}"`);
149
+ }
150
+
151
+ const sessionPath = await findSessionPath(provider, normalizedSessionId, options);
152
+ if (!sessionPath) {
153
+ throw new Error(`Invalid --resume session id for ${provider}: ${normalizedSessionId}`);
154
+ }
155
+
156
+ const cwdFromSession = await extractResumeCwdFromSession(provider, sessionPath, normalizedSessionId);
157
+ const fallbackCwd = await resolveSessionRunDirectory(sessionPath);
158
+ const cwd = cwdFromSession || fallbackCwd;
159
+ if (!(await isExistingDirectory(cwd))) {
160
+ throw new Error(`Resume workspace path does not exist: ${cwd}`);
161
+ }
162
+
163
+ return {
164
+ provider,
165
+ sessionId: normalizedSessionId,
166
+ sessionPath,
167
+ cwd,
168
+ debugMetadata: {
169
+ cwdSource: cwdFromSession ? "session" : "session_path",
170
+ sessionPath,
171
+ },
172
+ };
173
+ }
174
+
175
+ async function isExistingDirectory(targetPath) {
176
+ const normalizedPath = typeof targetPath === "string" ? targetPath.trim() : "";
177
+ if (!normalizedPath) {
178
+ return false;
179
+ }
180
+ try {
181
+ const stats = await fsp.stat(normalizedPath);
182
+ return stats.isDirectory();
183
+ } catch {
184
+ return false;
185
+ }
186
+ }
187
+
188
+ async function extractCodexResumeCwd(sessionPath) {
189
+ if (!sessionPath.endsWith(".jsonl")) {
190
+ return null;
191
+ }
192
+ const rl = readline.createInterface({
193
+ input: fs.createReadStream(sessionPath),
194
+ crlfDelay: Infinity,
195
+ });
196
+ for await (const line of rl) {
197
+ const trimmed = line.trim();
198
+ if (!trimmed) {
199
+ continue;
200
+ }
201
+ let entry;
202
+ try {
203
+ entry = JSON.parse(trimmed);
204
+ } catch {
205
+ continue;
206
+ }
207
+ const maybeCwd = entry?.type === "session_meta" ? entry?.payload?.cwd : null;
208
+ if (typeof maybeCwd === "string" && maybeCwd.trim()) {
209
+ return maybeCwd.trim();
210
+ }
211
+ }
212
+ return null;
213
+ }
214
+
215
+ async function extractClaudeResumeCwd(sessionPath, sessionId) {
216
+ if (!sessionPath.endsWith(".jsonl")) {
217
+ return null;
218
+ }
219
+ const rl = readline.createInterface({
220
+ input: fs.createReadStream(sessionPath),
221
+ crlfDelay: Infinity,
222
+ });
223
+ for await (const line of rl) {
224
+ const trimmed = line.trim();
225
+ if (!trimmed) {
226
+ continue;
227
+ }
228
+ let entry;
229
+ try {
230
+ entry = JSON.parse(trimmed);
231
+ } catch {
232
+ continue;
233
+ }
234
+ const idMatches = String(entry?.sessionId || "").trim() === sessionId;
235
+ const maybeCwd = entry?.cwd;
236
+ if (idMatches && typeof maybeCwd === "string" && maybeCwd.trim()) {
237
+ return maybeCwd.trim();
238
+ }
239
+ }
240
+ return null;
241
+ }
242
+
243
+ async function extractCopilotResumeCwd(sessionPath) {
244
+ let stats;
245
+ try {
246
+ stats = await fsp.stat(sessionPath);
247
+ } catch {
248
+ return null;
249
+ }
250
+
251
+ if (stats.isDirectory()) {
252
+ const workspaceYamlPath = path.join(sessionPath, "workspace.yaml");
253
+ try {
254
+ const yamlContent = await fsp.readFile(workspaceYamlPath, "utf8");
255
+ const parsed = yaml.load(yamlContent);
256
+ const maybeCwd = parsed && typeof parsed === "object" ? parsed.cwd : null;
257
+ if (typeof maybeCwd === "string" && maybeCwd.trim()) {
258
+ return maybeCwd.trim();
259
+ }
260
+ } catch {
261
+ return null;
262
+ }
263
+ return null;
264
+ }
265
+
266
+ if (!sessionPath.endsWith(".jsonl")) {
267
+ return null;
268
+ }
269
+
270
+ const rl = readline.createInterface({
271
+ input: fs.createReadStream(sessionPath),
272
+ crlfDelay: Infinity,
273
+ });
274
+ for await (const line of rl) {
275
+ const trimmed = line.trim();
276
+ if (!trimmed) {
277
+ continue;
278
+ }
279
+ let entry;
280
+ try {
281
+ entry = JSON.parse(trimmed);
282
+ } catch {
283
+ continue;
284
+ }
285
+ const maybeCwd = entry?.data?.context?.cwd || entry?.data?.cwd;
286
+ if (typeof maybeCwd === "string" && maybeCwd.trim()) {
287
+ return maybeCwd.trim();
288
+ }
289
+ }
290
+ return null;
291
+ }
292
+
293
+ async function extractResumeCwdFromSession(provider, sessionPath, sessionId) {
294
+ if (provider === "codex") {
295
+ return extractCodexResumeCwd(sessionPath);
296
+ }
297
+ if (provider === "claude") {
298
+ return extractClaudeResumeCwd(sessionPath, sessionId);
299
+ }
300
+ if (provider === "copilot") {
301
+ return extractCopilotResumeCwd(sessionPath);
302
+ }
303
+ return null;
304
+ }
305
+
306
+ async function findCodexSessionFile(rootDir, sessionId) {
307
+ const queue = [rootDir];
308
+ while (queue.length) {
309
+ const current = queue.pop();
310
+ let entries = [];
311
+ try {
312
+ entries = await fsp.readdir(current, { withFileTypes: true });
313
+ } catch {
314
+ continue;
315
+ }
316
+ for (const entry of entries) {
317
+ const fullPath = path.join(current, entry.name);
318
+ if (entry.isDirectory()) {
319
+ queue.push(fullPath);
320
+ } else if (entry.isFile() && entry.name.includes(sessionId) && entry.name.endsWith(".jsonl")) {
321
+ return fullPath;
322
+ }
323
+ }
324
+ }
325
+ return null;
326
+ }
327
+
328
+ async function findClaudeSessionEntries(projectsDir, sessionId) {
329
+ const entries = [];
330
+ let projectDirs = [];
331
+ try {
332
+ projectDirs = await fsp.readdir(projectsDir, { withFileTypes: true });
333
+ } catch {
334
+ return entries;
335
+ }
336
+
337
+ for (const projectDir of projectDirs) {
338
+ if (!projectDir.isDirectory()) {
339
+ continue;
340
+ }
341
+ const projectPath = path.join(projectsDir, projectDir.name);
342
+ let files = [];
343
+ try {
344
+ files = await fsp.readdir(projectPath, { withFileTypes: true });
345
+ } catch {
346
+ continue;
347
+ }
348
+
349
+ for (const file of files) {
350
+ if (!file.isFile()) {
351
+ continue;
352
+ }
353
+ if (!file.name.endsWith(".jsonl") || file.name.startsWith("agent-")) {
354
+ continue;
355
+ }
356
+
357
+ const filePath = path.join(projectPath, file.name);
358
+ const rl = readline.createInterface({
359
+ input: fs.createReadStream(filePath),
360
+ crlfDelay: Infinity,
361
+ });
362
+
363
+ for await (const line of rl) {
364
+ const trimmed = line.trim();
365
+ if (!trimmed) {
366
+ continue;
367
+ }
368
+ let entry;
369
+ try {
370
+ entry = JSON.parse(trimmed);
371
+ } catch {
372
+ continue;
373
+ }
374
+ if (entry.sessionId === sessionId) {
375
+ entries.push({ ...entry, source: filePath });
376
+ }
377
+ }
378
+ }
379
+ }
380
+
381
+ return entries;
382
+ }
383
+
384
+ async function findPathByName(rootDir, sessionId) {
385
+ const queue = [rootDir];
386
+ while (queue.length) {
387
+ const current = queue.pop();
388
+ let entries = [];
389
+ try {
390
+ entries = await fsp.readdir(current, { withFileTypes: true });
391
+ } catch {
392
+ continue;
393
+ }
394
+ for (const entry of entries) {
395
+ const fullPath = path.join(current, entry.name);
396
+ if (entry.name.includes(sessionId)) {
397
+ return fullPath;
398
+ }
399
+ if (entry.isDirectory()) {
400
+ queue.push(fullPath);
401
+ }
402
+ }
403
+ }
404
+ return null;
405
+ }
406
+
407
+ async function pathExists(targetPath, expectedType) {
408
+ try {
409
+ const stats = await fsp.stat(targetPath);
410
+ if (expectedType === "file") {
411
+ return stats.isFile();
412
+ }
413
+ if (expectedType === "directory") {
414
+ return stats.isDirectory();
415
+ }
416
+ return true;
417
+ } catch {
418
+ return false;
419
+ }
420
+ }