fix(coding-agent): handle missing session cwd

This commit is contained in:
Mario Zechner
2026-04-05 21:24:15 +02:00
parent 127547f2b3
commit 080af6fc06
6 changed files with 259 additions and 12 deletions

View File

@@ -61,6 +61,7 @@ import { createCompactionSummaryMessage } from "../../core/messages.js";
import { findExactModelReferenceMatch, resolveModelScope } from "../../core/model-resolver.js";
import { DefaultPackageManager } from "../../core/package-manager.js";
import type { ResourceDiagnostic } from "../../core/resource-loader.js";
import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
import { type SessionContext, SessionManager } from "../../core/session-manager.js";
import { BUILTIN_SLASH_COMMANDS } from "../../core/slash-commands.js";
import type { SourceInfo } from "../../core/source-info.js";
@@ -1719,6 +1720,14 @@ export class InteractiveMode {
return result === "Yes";
}
private async promptForMissingSessionCwd(error: MissingSessionCwdError): Promise<string | undefined> {
const confirmed = await this.showExtensionConfirm(
"Session cwd not found",
formatMissingSessionCwdPrompt(error.issue),
);
return confirmed ? error.issue.fallbackCwd : undefined;
}
/**
* Show a text input for extensions.
*/
@@ -3843,6 +3852,21 @@ export class InteractiveMode {
this.renderCurrentSessionState();
this.showStatus("Resumed session");
} catch (error: unknown) {
if (error instanceof MissingSessionCwdError) {
const selectedCwd = await this.promptForMissingSessionCwd(error);
if (!selectedCwd) {
this.showStatus("Resume cancelled");
return;
}
const result = await this.runtimeHost.switchSession(sessionPath, selectedCwd);
if (result.cancelled) {
return;
}
await this.handleRuntimeSessionChange();
this.renderCurrentSessionState();
this.showStatus("Resumed session in current cwd");
return;
}
await this.handleFatalRuntimeError("Failed to resume session", error);
}
}
@@ -4109,6 +4133,22 @@ export class InteractiveMode {
this.renderCurrentSessionState();
this.showStatus(`Session imported from: ${inputPath}`);
} catch (error: unknown) {
if (error instanceof MissingSessionCwdError) {
const selectedCwd = await this.promptForMissingSessionCwd(error);
if (!selectedCwd) {
this.showStatus("Import cancelled");
return;
}
const result = await this.runtimeHost.importFromJsonl(inputPath, selectedCwd);
if (result.cancelled) {
this.showStatus("Import cancelled");
return;
}
await this.handleRuntimeSessionChange();
this.renderCurrentSessionState();
this.showStatus(`Session imported from: ${inputPath}`);
return;
}
await this.handleFatalRuntimeError("Failed to import session", error);
}
}