feat: add dump command for bulk session export#20
feat: add dump command for bulk session export#20commandlinetips wants to merge 3 commits intoyigitkonur:mainfrom
Conversation
src/commands/dump.ts
Outdated
| try { | ||
| if (!fs.existsSync(targetDir)) { | ||
| fs.mkdirSync(targetDir, { recursive: true }); | ||
| } |
There was a problem hiding this comment.
Unnecessary check. mkdirSync with recursive: true already handles existing directories gracefully. Delete the existsSync check:
| try { | |
| if (!fs.existsSync(targetDir)) { | |
| fs.mkdirSync(targetDir, { recursive: true }); | |
| } | |
| try { | |
| fs.mkdirSync(targetDir, { recursive: true }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/dump.ts
Line: 62-65
Comment:
Unnecessary check. `mkdirSync` with `recursive: true` already handles existing directories gracefully. Delete the `existsSync` check:
```suggestion
try {
fs.mkdirSync(targetDir, { recursive: true });
```
How can I resolve this? If you propose a fix, please make it concise.
src/commands/dump.ts
Outdated
| fs.writeFileSync(filepath, json, 'utf8'); | ||
| } else { | ||
| // Markdown export - reuse adapter's extractContext | ||
| const adapter = adapters[session.source]; |
There was a problem hiding this comment.
Missing null check. If session has corrupted/invalid source, adapters[session.source] returns undefined and line 107 crashes with "Cannot read property 'extractContext' of undefined".
Add guard:
| const adapter = adapters[session.source]; | |
| const adapter = adapters[session.source]; | |
| if (!adapter) { | |
| errorCount++; | |
| continue; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/dump.ts
Line: 106
Comment:
Missing null check. If session has corrupted/invalid source, `adapters[session.source]` returns undefined and line 107 crashes with "Cannot read property 'extractContext' of undefined".
Add guard:
```suggestion
const adapter = adapters[session.source];
if (!adapter) {
errorCount++;
continue;
}
```
How can I resolve this? If you propose a fix, please make it concise.
src/commands/dump.ts
Outdated
| const bySource = sessions.reduce( | ||
| (acc, s) => { | ||
| acc[s.source] = (acc[s.source] || 0) + 1; | ||
| return acc; | ||
| }, | ||
| {} as Record<string, number>, | ||
| ); |
There was a problem hiding this comment.
"By source" count includes failed exports. If 10 claude sessions were attempted and 3 failed, this shows "claude: 10" when only 7 actually exported. Track which sessions succeeded and count those instead.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/dump.ts
Line: 135-141
Comment:
"By source" count includes failed exports. If 10 claude sessions were attempted and 3 failed, this shows "claude: 10" when only 7 actually exported. Track which sessions succeeded and count those instead.
How can I resolve this? If you propose a fix, please make it concise.| export async function dumpCommand( | ||
| sourceOrAll: string, | ||
| directory: string, | ||
| options: { | ||
| preset?: string; | ||
| json?: boolean; | ||
| limit?: string; | ||
| rebuild?: boolean; | ||
| }, | ||
| context: { isTTY: boolean }, | ||
| ): Promise<void> { |
There was a problem hiding this comment.
No top-level error handler. If getAllSessions or getSessionsBySource throws, the command crashes ungracefully. See list.ts:15-60 which wraps everything in try-catch and sets process.exitCode = 1 on error.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/dump.ts
Line: 17-27
Comment:
No top-level error handler. If `getAllSessions` or `getSessionsBySource` throws, the command crashes ungracefully. See `list.ts:15-60` which wraps everything in try-catch and sets `process.exitCode = 1` on error.
How can I resolve this? If you propose a fix, please make it concise.- Add adapter null check to prevent crash on invalid source - Fix 'by source' count to only include successful exports - Add top-level try-catch for consistent error handling - Remove unnecessary existsSync before mkdirSync with recursive
Summary
Adds a new
dumpcommand to bulk export sessions to markdown or JSON files.Usage
Options
--preset <name>--json--limit <n>--rebuildImplementation
src/commands/dump.ts- dump command handlersrc/cli.ts- register the commandREADME.md- documentationFile Naming
{source}_{id}.md(e.g.,claude_abc123def456.md){source}_{id}.json(e.g.,gemini_def789ghi012.json)Test plan
continues dump --helpshows correct usagecontinues dump all ./dir --limit 3exports 3 markdown filescontinues dump all ./dir --jsonexports JSON filescontinues dump opencode ./dirfilters by sourcecontinues dump claude ./dir --preset fulluses full verbosityReview all of them with eye of John Carmack-like simplicity with elegeance approach and apply the one only if required
Greptile Summary
Adds bulk export command for sessions. Core feature is solid — reuses existing
getAllSessions,getSessionsBySource, and adapterextractContextmethods. Integrates naturally with the CLI's flag patterns and verbosity presets.Critical bugs found:
list.ts)fs.existsSynccheck beforemkdirSyncwith recursive flagFeature itself fits well. Implementation needs tightening.
Confidence Score: 2/5
src/commands/dump.tsneeds immediate fixes for crash bugs and error handlingImportant Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD Start([continues dump source dir --options]) --> ValidateSource{Valid source?} ValidateSource -->|No| ErrorExit1[Exit with error] ValidateSource -->|Yes| LoadSessions[Load sessions from index] LoadSessions --> CheckEmpty{Sessions found?} CheckEmpty -->|No| InfoExit[Print 'No sessions found' & exit] CheckEmpty -->|Yes| ApplyLimit[Apply --limit if specified] ApplyLimit --> CreateDir[Create target directory recursive] CreateDir --> GetPreset[Load verbosity preset] GetPreset --> LoopStart[Start export loop] LoopStart --> LoopNext{More sessions?} LoopNext -->|No| PrintSummary[Print summary: success/errors/time] LoopNext -->|Yes| CheckFormat{--json flag?} CheckFormat -->|Yes| ExportJSON[Write session as JSON] CheckFormat -->|No| GetAdapter[Get adapter for session.source] GetAdapter --> ExtractContext[adapter.extractContext with preset] ExtractContext --> ExportMD[Write markdown file] ExportJSON --> IncrSuccess[Increment successCount] ExportMD --> IncrSuccess IncrSuccess --> LoopNext PrintSummary --> CountBySource[Count sessions by source] CountBySource --> PrintBreakdown[Print source breakdown table] PrintBreakdown --> End([Exit with code 0 or 1])Last reviewed commit: a2a51c2
(2/5) Greptile learns from your feedback when you react with thumbs up/down!