fix(coding-agent): restore /import error flow and document throws

This commit is contained in:
Mario Zechner
2026-04-17 00:59:53 +02:00
parent 3ba0d85fa2
commit 36bffc1d13
3 changed files with 30 additions and 17 deletions

View File

@@ -33,6 +33,9 @@ export type CreateAgentSessionRuntimeFactory = (options: {
sessionStartEvent?: SessionStartEvent;
}) => Promise<CreateAgentSessionRuntimeResult>;
/**
* Thrown when /import references a JSONL file path that does not exist.
*/
export class SessionImportFileNotFoundError extends Error {
readonly filePath: string;
@@ -258,6 +261,13 @@ export class AgentSessionRuntime {
return { cancelled: false, selectedText };
}
/**
* Import a session JSONL file and switch runtime state to the imported session.
*
* @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.
* @throws {SessionImportFileNotFoundError} When the input path does not exist.
* @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.
*/
async importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {
const resolvedPath = resolve(inputPath);
if (!existsSync(resolvedPath)) {