feat(coding-agent): add JSONL export/import for sessions (#2356)

fixes #2274
This commit is contained in:
Helmut Januschka
2026-03-18 22:37:11 +01:00
committed by GitHub
parent ce095e2846
commit fd385ecf06
3 changed files with 123 additions and 6 deletions

View File

@@ -1977,6 +1977,11 @@ export class InteractiveMode {
this.editor.setText("");
return;
}
if (text.startsWith("/import")) {
await this.handleImportCommand(text);
this.editor.setText("");
return;
}
if (text === "/share") {
await this.handleShareCommand();
this.editor.setText("");
@@ -3909,13 +3914,62 @@ export class InteractiveMode {
const outputPath = parts.length > 1 ? parts[1] : undefined;
try {
const filePath = await this.session.exportToHtml(outputPath);
this.showStatus(`Session exported to: ${filePath}`);
if (outputPath?.endsWith(".jsonl")) {
const filePath = this.session.exportToJsonl(outputPath);
this.showStatus(`Session exported to: ${filePath}`);
} else {
const filePath = await this.session.exportToHtml(outputPath);
this.showStatus(`Session exported to: ${filePath}`);
}
} catch (error: unknown) {
this.showError(`Failed to export session: ${error instanceof Error ? error.message : "Unknown error"}`);
}
}
private async handleImportCommand(text: string): Promise<void> {
const parts = text.split(/\s+/);
if (parts.length < 2 || !parts[1]) {
this.showError("Usage: /import <path.jsonl>");
return;
}
const inputPath = parts[1];
const confirmed = await this.showExtensionConfirm("Import session", `Replace current session with ${inputPath}?`);
if (!confirmed) {
this.showStatus("Import cancelled");
return;
}
try {
// Stop loading animation
if (this.loadingAnimation) {
this.loadingAnimation.stop();
this.loadingAnimation = undefined;
}
this.statusContainer.clear();
// Clear UI state
this.pendingMessagesContainer.clear();
this.compactionQueuedMessages = [];
this.streamingComponent = undefined;
this.streamingMessage = undefined;
this.pendingTools.clear();
const success = await this.session.importFromJsonl(inputPath);
if (!success) {
this.showWarning("Import cancelled");
return;
}
// Clear and re-render the chat
this.chatContainer.clear();
this.renderInitialMessages();
this.showStatus(`Session imported from: ${inputPath}`);
} catch (error: unknown) {
this.showError(`Failed to import session: ${error instanceof Error ? error.message : "Unknown error"}`);
}
}
private async handleShareCommand(): Promise<void> {
// Check if gh is available and logged in
try {