fix(coding-agent): parse quoted import paths and missing files
This commit is contained in:
@@ -47,7 +47,7 @@ import {
|
||||
VERSION,
|
||||
} from "../../config.js";
|
||||
import { type AgentSession, type AgentSessionEvent, parseSkillBlock } from "../../core/agent-session.js";
|
||||
import type { AgentSessionRuntime } from "../../core/agent-session-runtime.js";
|
||||
import { type AgentSessionRuntime, SessionImportFileNotFoundError } from "../../core/agent-session-runtime.js";
|
||||
import type {
|
||||
ExtensionContext,
|
||||
ExtensionRunner,
|
||||
@@ -2278,12 +2278,12 @@ export class InteractiveMode {
|
||||
await this.handleModelCommand(searchTerm);
|
||||
return;
|
||||
}
|
||||
if (text.startsWith("/export")) {
|
||||
if (text === "/export" || text.startsWith("/export ")) {
|
||||
await this.handleExportCommand(text);
|
||||
this.editor.setText("");
|
||||
return;
|
||||
}
|
||||
if (text.startsWith("/import")) {
|
||||
if (text === "/import" || text.startsWith("/import ")) {
|
||||
await this.handleImportCommand(text);
|
||||
this.editor.setText("");
|
||||
return;
|
||||
@@ -4353,8 +4353,7 @@ export class InteractiveMode {
|
||||
}
|
||||
|
||||
private async handleExportCommand(text: string): Promise<void> {
|
||||
const parts = text.split(/\s+/);
|
||||
const outputPath = parts.length > 1 ? parts[1] : undefined;
|
||||
const outputPath = this.getPathCommandArgument(text, "/export");
|
||||
|
||||
try {
|
||||
if (outputPath?.endsWith(".jsonl")) {
|
||||
@@ -4369,13 +4368,41 @@ export class InteractiveMode {
|
||||
}
|
||||
}
|
||||
|
||||
private getPathCommandArgument(text: string, command: "/export" | "/import"): string | undefined {
|
||||
if (text === command) {
|
||||
return undefined;
|
||||
}
|
||||
if (!text.startsWith(`${command} `)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const argsString = text.slice(command.length + 1).trimStart();
|
||||
if (!argsString) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const firstChar = argsString[0];
|
||||
if (firstChar === '"' || firstChar === "'") {
|
||||
const closingQuoteIndex = argsString.indexOf(firstChar, 1);
|
||||
if (closingQuoteIndex < 0) {
|
||||
return undefined;
|
||||
}
|
||||
return argsString.slice(1, closingQuoteIndex);
|
||||
}
|
||||
|
||||
const firstWhitespaceIndex = argsString.search(/\s/);
|
||||
if (firstWhitespaceIndex < 0) {
|
||||
return argsString;
|
||||
}
|
||||
return argsString.slice(0, firstWhitespaceIndex);
|
||||
}
|
||||
|
||||
private async handleImportCommand(text: string): Promise<void> {
|
||||
const parts = text.split(/\s+/);
|
||||
if (parts.length < 2 || !parts[1]) {
|
||||
const inputPath = this.getPathCommandArgument(text, "/import");
|
||||
if (!inputPath) {
|
||||
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) {
|
||||
@@ -4414,6 +4441,10 @@ export class InteractiveMode {
|
||||
this.showStatus(`Session imported from: ${inputPath}`);
|
||||
return;
|
||||
}
|
||||
if (error instanceof SessionImportFileNotFoundError) {
|
||||
this.showError(`Failed to import session: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
await this.handleFatalRuntimeError("Failed to import session", error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user