@luswt/parse-session 1.0.0 → 1.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/parse-session.mjs +24 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@luswt/parse-session",
3
- "version": "1.0.0",
4
- "description": "Export AI agent sessions (opencode) from SQLite database to JSON",
3
+ "version": "1.1.0",
4
+ "description": "Export AI coding agent sessions to JSON run in any project directory to auto-detect and export all sessions",
5
5
  "bin": {
6
6
  "parse-session": "./parse-session.mjs"
7
7
  },
package/parse-session.mjs CHANGED
@@ -409,38 +409,51 @@ async function exportProjectSessions(agent) {
409
409
  console.log(`\nExported to: ${exportDir}`);
410
410
  }
411
411
 
412
+ const SUPPORTED_AGENTS = ["opencode"];
413
+
412
414
  const args = process.argv.slice(2);
413
415
  let agent = null;
414
416
  let sessionId = null;
417
+ let showList = false;
415
418
 
416
419
  for (const arg of args) {
417
- if (arg.startsWith("--agent=")) {
418
- agent = arg.split("=")[1];
420
+ if (arg === "--list" || arg === "-l") {
421
+ showList = true;
422
+ } else if (arg.startsWith("--")) {
423
+ const val = arg.startsWith("--agent=") ? arg.split("=")[1] : null;
424
+ if (val) agent = val;
419
425
  } else if (arg.startsWith("ses_")) {
420
426
  sessionId = arg;
421
- } else {
427
+ } else if (SUPPORTED_AGENTS.includes(arg)) {
422
428
  agent = arg;
423
429
  }
424
430
  }
425
431
 
426
- if (agent) {
427
- await exportProjectSessions(agent);
428
- } else if (!sessionId) {
432
+ if (showList) {
429
433
  const sessions = await listSessions();
430
- console.log("Usage: node parse-session.mjs <session_id>");
431
- console.log(" node parse-session.mjs <agent>");
432
- console.log(" node parse-session.mjs --agent=<agent>\n");
433
- console.log("Agents: opencode\n");
434
434
  console.log("Recent sessions:");
435
435
  for (const s of sessions) {
436
436
  console.log(` ${s.id} ${s.title} (${s.date})`);
437
437
  }
438
438
  process.exit(0);
439
- } else {
439
+ }
440
+
441
+ if (sessionId) {
440
442
  const info = await getSessionInfo(sessionId);
441
443
  const exportsDir = path.join(process.cwd(), "exports");
442
444
  if (!fs.existsSync(exportsDir)) fs.mkdirSync(exportsDir, { recursive: true });
443
445
  const outPath = path.join(exportsDir, `${sessionId}.json`);
444
446
  fs.writeFileSync(outPath, JSON.stringify(info, null, 2), "utf-8");
445
447
  console.log(`Saved: ${outPath}`);
448
+ process.exit(0);
449
+ }
450
+
451
+ const agents = agent ? [agent] : SUPPORTED_AGENTS;
452
+ for (const a of agents) {
453
+ const cwdSessions = await findSessionsByDirectory(process.cwd());
454
+ if (cwdSessions.length === 0) {
455
+ console.log(`No ${a} sessions found for: ${process.cwd()}`);
456
+ continue;
457
+ }
458
+ await exportProjectSessions(a);
446
459
  }