Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

make resume available in agents view (#318)

ktf53f9feaa250
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-commands.ts b/packages/coding-agent/src/modes/agents-view/agents-view-commands.ts
index b6489a152e..69616652ac 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-commands.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-commands.ts
@@ -16,7 +16,7 @@ import {
resolveBuiltinSlashCommandName,
} from "../../core/slash-commands.js";
-const AGENTS_VIEW_COMMAND_NAMES = ["login", "logout", "model", "quit"] as const;
+const AGENTS_VIEW_COMMAND_NAMES = ["login", "logout", "model", "resume", "quit"] as const;
export type AgentsViewCommandName = (typeof AGENTS_VIEW_COMMAND_NAMES)[number];
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
index 86319dd648..89981d529f 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
@@ -1,4 +1,5 @@
import { existsSync } from "node:fs";
+import { resolve as resolvePath } from "node:path";
import type { Api, ImageContent, Model } from "@earendil-works/pi-ai";
import type { AutocompleteItem, OverlayHandle, SlashCommand } from "@earendil-works/pi-tui";
import {
@@ -17,16 +18,22 @@ import { APP_TITLE, appendRotatingLog, getAgentDir, getClientErrorLogPath, VERSI
import type { AgentSessionRuntimeConfig } from "../../core/agent-session-config.js";
import { KeybindingsManager } from "../../core/keybindings.js";
import { findExactModelReferenceMatch } from "../../core/model-resolver.js";
-import { SessionManager } from "../../core/session-manager.js";
+import type { DeleteSessionFileResult } from "../../core/session-file-actions.js";
+import { type SessionInfo, SessionManager } from "../../core/session-manager.js";
import { DaemonAgentConnection } from "../agent-connection/daemon-agent-connection.js";
import { DaemonClient } from "../daemon/daemon-client.js";
import { type DaemonCommand, type DaemonResponse, isUnknownDaemonCommandError } from "../daemon/daemon-protocol.js";
-import { resolveAttachModelFallbackMessage, type SessionSummary } from "../daemon/daemon-session-list.js";
+import {
+ resolveAttachModelFallbackMessage,
+ type SessionSummary,
+ summaryForInactiveSession,
+} from "../daemon/daemon-session-list.js";
import { getAnthropicSubscriptionAuthWarning, ProviderAuthFlows } from "../interactive/auth-flows.js";
import { showFullPaneOverlay } from "../interactive/components/centered-overlay.js";
import { CustomEditor } from "../interactive/components/custom-editor.js";
import { keyText } from "../interactive/components/keybinding-hints.js";
import { ModelSelectorComponent } from "../interactive/components/model-selector.js";
+import { SessionSelectorComponent } from "../interactive/components/session-selector.js";
import { BrandSplashHeader, InteractiveMode } from "../interactive/interactive-mode.js";
import type { InteractiveModeUiServices } from "../interactive/interactive-mode-services.js";
import {
@@ -118,6 +125,7 @@ type AgentsViewPersistentState = {
};
type PromptCommand = Extract<DaemonCommand, { type: "prompt" }>;
+type DeleteSavedSessionCommand = Extract<DaemonCommand, { type: "delete_saved_session" }>;
type PendingDeleteAgent = {
identity: string;
activeSessionId?: string;
@@ -159,6 +167,37 @@ export function createAgentsViewListCommand(): Extract<DaemonCommand, { type: "l
return { type: "list" };
}
+export function createAgentsViewDeleteSavedSessionCommand(sessionPath: string): DeleteSavedSessionCommand {
+ return { type: "delete_saved_session", sessionPath };
+}
+
+export function resolveAgentsViewResumeSummary(
+ sessionPath: string,
+ savedSessions: readonly SessionInfo[],
+ visibleSummaries: readonly SessionSummary[],
+): SessionSummary | undefined {
+ const activeSummary = resolveAgentsViewActiveSummaryForPath(sessionPath, visibleSummaries);
+ if (activeSummary) {
+ return activeSummary;
+ }
+ const selectedPath = resolvePath(sessionPath);
+ const savedSession = savedSessions.find((session) => resolvePath(session.path) === selectedPath);
+ return savedSession ? summaryForInactiveSession(savedSession) : undefined;
+}
+
+export function resolveAgentsViewActiveSummaryForPath(
+ sessionPath: string,
+ summaries: readonly SessionSummary[],
+): SessionSummary | undefined {
+ const selectedPath = resolvePath(sessionPath);
+ return summaries.find(
+ (summary) =>
+ summary.activeSessionId !== undefined &&
+ summary.sessionFile !== undefined &&
+ resolvePath(summary.sessionFile) === selectedPath,
+ );
+}
+
// Status messages render in a single-row hint slot below the editor; embedded
// newlines would make that row taller than the layout accounts for and overlap
// the input, so flatten all whitespace runs to single spaces.
@@ -341,6 +380,7 @@ class AgentsViewMode implements Component, Focusable {
private deleteConfirmTimer: ReturnType<typeof setTimeout> | undefined;
private workingIconFrame = 0;
private rows: AgentsViewRow[] = [];
+ private lastListedSummaries: SessionSummary[] = [];
private lastVisibleSummaries: SessionSummary[] = [];
private expandedSubagentParents = new Set<string>();
// Agent row identities whose full spawn program is currently shown.
@@ -907,6 +947,9 @@ class AgentsViewMode implements Component, Focusable {
await this.showModelSelector(searchTerm);
return;
}
+ case "resume":
+ await this.showSessionSelector();
+ return;
case "quit":
this.finish({ type: "exit" });
return;
@@ -984,6 +1027,97 @@ class AgentsViewMode implements Component, Focusable {
});
}
+ private showSessionSelector(): Promise<void> {
+ return new Promise((done) => {
+ let handle: OverlayHandle | undefined;
+ let settled = false;
+ const savedSessionsByPath = new Map<string, SessionInfo>();
+
+ const rememberSessions = (sessions: SessionInfo[]): SessionInfo[] => {
+ for (const session of sessions) {
+ savedSessionsByPath.set(resolvePath(session.path), session);
+ }
+ return sessions;
+ };
+
+ const close = () => {
+ if (settled) {
+ return;
+ }
+ settled = true;
+ handle?.hide();
+ this.ui.requestRender();
+ done();
+ };
+
+ const selector = new SessionSelectorComponent(
+ async (onProgress) =>
+ rememberSessions(
+ await SessionManager.list(this.getSavedSessionCwd(), this.options.config.sessionDir, onProgress),
+ ),
+ async (onProgress) =>
+ rememberSessions(await SessionManager.listAll(onProgress, this.options.config.sessionDir)),
+ (sessionPath) => {
+ const summary = resolveAgentsViewResumeSummary(
+ sessionPath,
+ [...savedSessionsByPath.values()],
+ this.lastListedSummaries,
+ );
+ close();
+ if (!summary) {
+ this.setStatusMessage("Failed to resume session: selected session was not found");
+ return;
+ }
+ this.finish({ type: "open", summary });
+ },
+ close,
+ () => {
+ close();
+ this.finish({ type: "exit" });
+ },
+ () => this.ui.requestRender(),
+ {
+ renameSession: async (sessionPath, nextName) => {
+ const name = (nextName ?? "").trim();
+ if (!name) {
+ return;
+ }
+ await this.renameSavedSessionFromSelector(sessionPath, name);
+ },
+ deleteSession: (sessionPath) => this.deleteSavedSessionFromSelector(sessionPath),
+ showRenameHint: true,
+ keybindings: this.keybindings,
+ },
+ );
+ handle = showFullPaneOverlay(this.ui, selector, 96);
+ });
+ }
+
+ private getSavedSessionCwd(): string {
+ return this.options.config.cwd ?? this.options.uiServices.getInitialCwd();
+ }
+
+ private async renameSavedSessionFromSelector(sessionPath: string, name: string): Promise<void> {
+ const activeSummary = resolveAgentsViewActiveSummaryForPath(sessionPath, this.lastListedSummaries);
+ if (!activeSummary?.activeSessionId) {
+ SessionManager.open(sessionPath).appendSessionInfo(name);
+ return;
+ }
+ const response = await this.requireClient().request({
+ type: "rename_saved_session",
+ activeSessionId: activeSummary.activeSessionId,
+ sessionPath,
+ name,
+ });
+ requireDaemonData(response);
+ await this.refreshSessions();
+ }
+
+ private async deleteSavedSessionFromSelector(sessionPath: string): Promise<DeleteSessionFileResult> {
+ const response = await this.requireClient().request(createAgentsViewDeleteSavedSessionCommand(sessionPath));
+ return expectDeleteSessionFileResult(requireDaemonData(response));
+ }
+
private getDefaultModelForNewAgents(): Model<Api> | undefined {
const settings = this.options.uiServices.settingsManager;
const provider = settings.getDefaultProvider();
@@ -1571,6 +1705,7 @@ class AgentsViewMode implements Component, Focusable {
const response = await client.request(createAgentsViewListCommand());
const data = requireDaemonData(response);
const sessions = expectSessionList(data);
+ this.lastListedSummaries = sessions;
const visibleSessions = sessions.filter((summary) =>
shouldShowAgentsViewSession(summary, this.inactiveAgentIdentities.has(getSummaryIdentity(summary))),
);
@@ -2046,6 +2181,22 @@ function expectSessionSummary(value: unknown): SessionSummary {
return value;
}
+function expectDeleteSessionFileResult(value: unknown): DeleteSessionFileResult {
+ if (!isRecord(value) || typeof value.ok !== "boolean") {
+ throw new Error("Daemon returned an invalid delete session response");
+ }
+ if (value.ok) {
+ if (value.method !== "trash" && value.method !== "unlink") {
+ throw new Error("Daemon returned an invalid delete session response");
+ }
+ return { ok: true, method: value.method };
+ }
+ if (typeof value.error !== "string") {
+ throw new Error("Daemon returned an invalid delete session response");
+ }
+ return { ok: false, error: value.error };
+}
+
function isSessionSummary(value: unknown): value is SessionSummary {
return isRecord(value) && typeof value.id === "string" && typeof value.sessionId === "string";
}
diff --git a/packages/coding-agent/src/modes/interactive/components/session-selector.ts b/packages/coding-agent/src/modes/interactive/components/session-selector.ts
index 8cf70827e6..cf1a39b503 100644
--- a/packages/coding-agent/src/modes/interactive/components/session-selector.ts
+++ b/packages/coding-agent/src/modes/interactive/components/session-selector.ts
@@ -59,6 +59,10 @@ function canonicalizePath(path: string | undefined): string | undefined {
return _canonicalizePath(path);
}
+function formatMutationError(error: unknown): string {
+ return error instanceof Error ? error.message : String(error);
+}
+
class SessionSelectorHeader implements Component {
private scope: SessionScope;
private sortMode: SortMode;
@@ -129,6 +133,7 @@ class SessionSelectorHeader implements Component {
this.statusTimeout = null;
this.requestRender();
}, autoHideMs);
+ this.statusTimeout.unref?.();
}
invalidate(): void {}
@@ -814,7 +819,17 @@ export class SessionSelectorComponent extends Container implements Focusable {
// Handle session deletion
this.sessionList.onDeleteSession = async (sessionPath: string) => {
- const result = await this.deleteSession(sessionPath);
+ let result: DeleteSessionFileResult;
+ try {
+ result = await this.deleteSession(sessionPath);
+ } catch (error) {
+ this.header.setStatusMessage(
+ { type: "error", message: `Failed to delete: ${formatMutationError(error)}` },
+ 3000,
+ );
+ this.requestRender();
+ return;
+ }
if (result.ok) {
if (this.currentSessions) {
@@ -829,8 +844,15 @@ export class SessionSelectorComponent extends Container implements Focusable {
this.sessionList.setSessions(sessions, showCwd);
const msg = result.method === "trash" ? "Session moved to trash" : "Session deleted";
- this.header.setStatusMessage({ type: "info", message: msg }, 2000);
- await this.refreshSessionsAfterMutation();
+ try {
+ await this.refreshSessionsAfterMutation();
+ this.header.setStatusMessage({ type: "info", message: msg }, 2000);
+ } catch (error) {
+ this.header.setStatusMessage(
+ { type: "error", message: `${msg}; refresh failed: ${formatMutationError(error)}` },
+ 3000,
+ );
+ }
} else {
const errorMessage = result.error ?? "Unknown error";
this.header.setStatusMessage({ type: "error", message: `Failed to delete: ${errorMessage}` }, 3000);
@@ -897,10 +919,29 @@ export class SessionSelectorComponent extends Container implements Focusable {
try {
await renameSession(target, next);
+ } catch (error) {
+ this.exitRenameMode();
+ this.header.setStatusMessage(
+ { type: "error", message: `Failed to rename: ${formatMutationError(error)}` },
+ 4000,
+ );
+ this.requestRender();
+ return;
+ }
+
+ try {
await this.refreshSessionsAfterMutation();
- } finally {
+ } catch (error) {
this.exitRenameMode();
+ this.header.setStatusMessage(
+ { type: "error", message: `Session renamed; refresh failed: ${formatMutationError(error)}` },
+ 4000,
+ );
+ this.requestRender();
+ return;
}
+
+ this.exitRenameMode();
}
private async loadScope(scope: SessionScope, reason: "initial" | "refresh" | "toggle"): Promise<void> {
diff --git a/packages/coding-agent/test/agents-view-commands.test.ts b/packages/coding-agent/test/agents-view-commands.test.ts
index ff22941468..515555dca1 100644
--- a/packages/coding-agent/test/agents-view-commands.test.ts
+++ b/packages/coding-agent/test/agents-view-commands.test.ts
@@ -33,13 +33,13 @@ describe("parseSlashCommand", () => {
describe("classifyAgentsViewCommand", () => {
test("whitelisted global commands run in the agents view", () => {
- for (const name of ["login", "logout", "model", "quit"]) {
+ for (const name of ["login", "logout", "model", "resume", "quit"]) {
expect(classifyAgentsViewCommand(name)).toBe("agents-view");
}
});
test("other built-ins are session-only", () => {
- for (const name of ["compact", "fork", "settings", "resume", "new", "clear", "export"]) {
+ for (const name of ["compact", "fork", "settings", "new", "clear", "export"]) {
expect(classifyAgentsViewCommand(name)).toBe("session-only");
}
});
diff --git a/packages/coding-agent/test/agents-view-state.test.ts b/packages/coding-agent/test/agents-view-state.test.ts
index 0738f73f65..4cd3c0c6cd 100644
--- a/packages/coding-agent/test/agents-view-state.test.ts
+++ b/packages/coding-agent/test/agents-view-state.test.ts
@@ -4,15 +4,19 @@ import { join } from "node:path";
import { describe, expect, test, vi } from "vitest";
import type { AgentSessionRuntimeConfig } from "../src/core/agent-session-config.js";
import type { ModelRegistry } from "../src/core/model-registry.js";
+import type { SessionInfo } from "../src/core/session-manager.js";
import type { SettingsManager } from "../src/core/settings-manager.js";
import {
+ createAgentsViewDeleteSavedSessionCommand,
createAgentsViewListCommand,
createAgentsViewReplyHeadline,
createAgentsViewResumeConfig,
createAgentsViewSessionName,
formatAgentsViewRelativeTime,
formatAgentsViewStatusLine,
+ resolveAgentsViewActiveSummaryForPath,
resolveAgentsViewOpenCwd,
+ resolveAgentsViewResumeSummary,
resolveAgentsViewSessionUiServices,
} from "../src/modes/agents-view/agents-view-mode.js";
import {
@@ -510,6 +514,77 @@ describe("agents view state", () => {
expect(createAgentsViewListCommand()).toEqual({ type: "list" });
});
+ test("creates an inactive summary for a saved session selected from resume", () => {
+ const savedSession = makeSessionInfo({
+ path: "/tmp/sessions/saved.jsonl",
+ id: "saved",
+ name: "Saved session",
+ cwd: "/tmp/project",
+ });
+
+ const summary = resolveAgentsViewResumeSummary(savedSession.path, [savedSession], []);
+
+ expect(summary).toMatchObject({
+ id: "saved",
+ activity: "idle",
+ sessionId: "saved",
+ sessionFile: savedSession.path,
+ sessionName: "Saved session",
+ cwd: "/tmp/project",
+ });
+ expect(summary?.activeSessionId).toBeUndefined();
+ expect(summary?.lifecycle).toBe("live");
+ });
+
+ test("reuses the live daemon summary when resuming an already-active saved session", () => {
+ const savedSession = makeSessionInfo({
+ path: "/tmp/sessions/active.jsonl",
+ id: "saved-active",
+ cwd: "/tmp/project",
+ });
+ const activeSummary = makeSummary({
+ id: "active-runtime",
+ activeSessionId: "active-runtime",
+ sessionId: "saved-active",
+ sessionFile: savedSession.path,
+ sessionName: "Running",
+ });
+
+ expect(resolveAgentsViewResumeSummary(savedSession.path, [savedSession], [activeSummary])).toBe(activeSummary);
+ });
+
+ test("resolves active summaries by session file path", () => {
+ const activeSummary = makeSummary({
+ id: "active-runtime",
+ activeSessionId: "active-runtime",
+ sessionId: "saved-active",
+ sessionFile: "/tmp/sessions/active.jsonl",
+ sessionName: "Running",
+ });
+ const inactiveSummary = makeSummary({
+ id: "inactive",
+ activeSessionId: undefined,
+ sessionId: "inactive",
+ sessionFile: "/tmp/sessions/inactive.jsonl",
+ });
+
+ expect(
+ resolveAgentsViewActiveSummaryForPath("/tmp/sessions/active.jsonl", [inactiveSummary, activeSummary]),
+ ).toBe(activeSummary);
+ expect(resolveAgentsViewActiveSummaryForPath("/tmp/sessions/inactive.jsonl", [inactiveSummary])).toBeUndefined();
+ });
+
+ test("routes saved session deletes through the daemon file guard", () => {
+ expect(createAgentsViewDeleteSavedSessionCommand("/tmp/sessions/active.jsonl")).toEqual({
+ type: "delete_saved_session",
+ sessionPath: "/tmp/sessions/active.jsonl",
+ });
+ expect(createAgentsViewDeleteSavedSessionCommand("/tmp/sessions/inactive.jsonl")).toEqual({
+ type: "delete_saved_session",
+ sessionPath: "/tmp/sessions/inactive.jsonl",
+ });
+ });
+
test("derives the reply headline from the first line of the latest assistant text", () => {
expect(createAgentsViewReplyHeadline(" Done.\nNext step? ")).toBe("Done.");
expect(createAgentsViewReplyHeadline("\n\n spread over \nlines")).toBe("spread over");
@@ -636,6 +711,23 @@ function makeSummary(overrides: Partial<SessionSummary>): SessionSummary {
};
}
+function makeSessionInfo(overrides: Partial<SessionInfo> & { path: string; id: string }): SessionInfo {
+ return {
+ path: overrides.path,
+ id: overrides.id,
+ cwd: overrides.cwd ?? "/tmp/project",
+ name: overrides.name,
+ state: overrides.state,
+ parentSessionPath: overrides.parentSessionPath,
+ created: overrides.created ?? new Date("2026-01-01T00:00:00Z"),
+ modified: overrides.modified ?? new Date("2026-01-01T00:00:00Z"),
+ messageCount: overrides.messageCount ?? 1,
+ firstMessage: overrides.firstMessage ?? "hello",
+ allMessagesText: overrides.allMessagesText ?? "hello",
+ agentStatus: overrides.agentStatus,
+ };
+}
+
function makeUiServices(cwd: string): InteractiveModeUiServices {
return {
settingsManager: {} as SettingsManager,
diff --git a/packages/coding-agent/test/session-selector-path-delete.test.ts b/packages/coding-agent/test/session-selector-path-delete.test.ts
index 92936d217f..3ce2914102 100644
--- a/packages/coding-agent/test/session-selector-path-delete.test.ts
+++ b/packages/coding-agent/test/session-selector-path-delete.test.ts
@@ -6,7 +6,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
import { KeybindingsManager } from "../src/core/keybindings.js";
import type { AgentConnectionSavedSessionInfo } from "../src/modes/agent-connection/index.js";
import { SessionSelectorComponent } from "../src/modes/interactive/components/session-selector.js";
-import { initTheme } from "../src/modes/interactive/theme/theme.js";
+import { initTheme, preloadCodeHighlighter } from "../src/modes/interactive/theme/theme.js";
type Deferred<T> = {
promise: Promise<T>;
@@ -103,9 +103,10 @@ describe("session selector path/delete interactions", () => {
setKeybindings(new KeybindingsManager());
});
- beforeAll(() => {
+ beforeAll(async () => {
// session selector uses the global theme instance
initTheme("dark");
+ await preloadCodeHighlighter();
});
it("does not treat Ctrl+Backspace as delete when search query is non-empty", async () => {
const sessions = [makeSession({ id: "a" }), makeSession({ id: "b" })];
@@ -210,6 +211,66 @@ describe("session selector path/delete interactions", () => {
expect(deleteSession).toHaveBeenCalledWith(sessions[0]!.path);
});
+ it("shows an error when the injected delete handler rejects", async () => {
+ const sessions = [makeSession({ id: "a" })];
+ const deleteSession = vi.fn(async () => {
+ throw new Error("Cannot delete the currently active session");
+ });
+
+ const selector = new SessionSelectorComponent(
+ async () => sessions,
+ async () => [],
+ () => {},
+ () => {},
+ () => {},
+ () => {},
+ { keybindings, deleteSession },
+ );
+ await flushPromises();
+
+ const list = selector.getSessionList();
+ list.handleInput(CTRL_X);
+ list.handleInput(CTRL_X);
+ await flushPromises();
+
+ const output = stripAnsi(selector.render(120).join("\n"));
+ expect(deleteSession).toHaveBeenCalledTimes(1);
+ expect(output).toContain("Failed to delete: Cannot delete the currently active session");
+ });
+
+ it("keeps delete success visible when refresh after deletion fails", async () => {
+ const sessions = [makeSession({ id: "a" })];
+ const deleteSession = vi.fn(async () => ({ ok: true as const, method: "unlink" as const }));
+ let loadCalls = 0;
+
+ const selector = new SessionSelectorComponent(
+ async () => {
+ loadCalls++;
+ if (loadCalls > 1) {
+ throw new Error("refresh unavailable");
+ }
+ return sessions;
+ },
+ async () => [],
+ () => {},
+ () => {},
+ () => {},
+ () => {},
+ { keybindings, deleteSession },
+ );
+ await flushPromises();
+
+ const list = selector.getSessionList();
+ list.handleInput(CTRL_X);
+ list.handleInput(CTRL_X);
+ await flushPromises();
+
+ const output = stripAnsi(selector.render(120).join("\n"));
+ expect(deleteSession).toHaveBeenCalledTimes(1);
+ expect(output).toContain("Session deleted");
+ expect(output).not.toContain("Failed to delete");
+ });
+
it("does not switch scope back to All when All load resolves after toggling back to Current", async () => {
const currentSessions = [makeSession({ id: "current" })];
const allDeferred = createDeferred<AgentConnectionSavedSessionInfo[]>();
diff --git a/packages/coding-agent/test/session-selector-rename.test.ts b/packages/coding-agent/test/session-selector-rename.test.ts
index f230d8c573..76014546f9 100644
--- a/packages/coding-agent/test/session-selector-rename.test.ts
+++ b/packages/coding-agent/test/session-selector-rename.test.ts
@@ -3,7 +3,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { KeybindingsManager } from "../src/core/keybindings.js";
import type { AgentConnectionSavedSessionInfo } from "../src/modes/agent-connection/index.js";
import { SessionSelectorComponent } from "../src/modes/interactive/components/session-selector.js";
-import { initTheme } from "../src/modes/interactive/theme/theme.js";
+import { initTheme, preloadCodeHighlighter } from "../src/modes/interactive/theme/theme.js";
async function flushPromises(): Promise<void> {
await new Promise<void>((resolve) => {
@@ -31,8 +31,9 @@ function makeSession(
const CTRL_R = "\x1b[114;5u";
describe("session selector rename", () => {
- beforeAll(() => {
+ beforeAll(async () => {
initTheme("dark");
+ await preloadCodeHighlighter();
});
beforeEach(() => {
@@ -110,4 +111,69 @@ describe("session selector rename", () => {
expect(renameSession).toHaveBeenCalledTimes(1);
expect(renameSession).toHaveBeenCalledWith(sessions[0]!.path, "XOld");
});
+
+ it("shows an error when rename fails", async () => {
+ const sessions = [makeSession({ id: "a", name: "Old" })];
+ const renameSession = vi.fn(async () => {
+ throw new Error("daemon unavailable");
+ });
+
+ const keybindings = new KeybindingsManager();
+ const selector = new SessionSelectorComponent(
+ async () => sessions,
+ async () => [],
+ () => {},
+ () => {},
+ () => {},
+ () => {},
+ { renameSession, showRenameHint: true, keybindings },
+ );
+ await flushPromises();
+
+ selector.getSessionList().handleInput(CTRL_R);
+ await flushPromises();
+
+ selector.handleInput("\r");
+ await flushPromises();
+
+ const output = selector.render(120).join("\n");
+ expect(renameSession).toHaveBeenCalledTimes(1);
+ expect(output).toContain("Resume Session");
+ expect(output).toContain("Failed to rename: daemon unavailable");
+ });
+
+ it("does not report rename failure when refresh after rename fails", async () => {
+ const sessions = [makeSession({ id: "a", name: "Old" })];
+ const renameSession = vi.fn(async () => {});
+ let loadCalls = 0;
+
+ const keybindings = new KeybindingsManager();
+ const selector = new SessionSelectorComponent(
+ async () => {
+ loadCalls++;
+ if (loadCalls > 1) {
+ throw new Error("refresh unavailable");
+ }
+ return sessions;
+ },
+ async () => [],
+ () => {},
+ () => {},
+ () => {},
+ () => {},
+ { renameSession, showRenameHint: true, keybindings },
+ );
+ await flushPromises();
+
+ selector.getSessionList().handleInput(CTRL_R);
+ await flushPromises();
+
+ selector.handleInput("\r");
+ await flushPromises();
+
+ const output = selector.render(120).join("\n");
+ expect(renameSession).toHaveBeenCalledTimes(1);
+ expect(output).toContain("Resume Session");
+ expect(output).not.toContain("Failed to rename");
+ });
});