Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,27 @@ ${skillMd}
return true;
}

/**
* Rename a session by updating its summary (display title).
* Returns true if the session was found and renamed, false otherwise.
*/
renameSession(sessionId: string, summary: string): boolean {
const trimmed = summary.trim();
if (!trimmed) {
return false;
}
const entry = this.getSession(sessionId);
if (!entry) {
return false;
}
this.updateSessionEntry(sessionId, (existing) => ({
...existing,
summary: trimmed,
updateTime: new Date().toISOString(),
}));
return true;
}

listSessionMessages(sessionId: string): SessionMessage[] {
const messagePath = this.getSessionMessagesPath(sessionId);
if (!fs.existsSync(messagePath)) {
Expand Down
8 changes: 8 additions & 0 deletions src/ui/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ function App({ projectRoot, initialPrompt, onRestart }: AppProps): React.ReactEl
onDelete={(id) => {
void handleDeleteSession(id);
}}
onRename={(id, newName) => {
if (sessionManager.renameSession(id, newName)) {
refreshSessionsList();
setStatusLine(`Session renamed to "${newName}".`);
} else {
setErrorLine("Failed to rename session.");
}
}}
/>
) : view === "undo" ? (
<UndoSelector
Expand Down
109 changes: 102 additions & 7 deletions src/ui/views/SessionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Props = {
onSelect: (sessionId: string) => void;
onCancel: () => void;
onDelete?: (sessionId: string) => void;
onRename?: (sessionId: string, newName: string) => void;
};

/**
Expand Down Expand Up @@ -38,10 +39,13 @@ export function filterSessions(sessions: SessionEntry[], query: string): Session
});
}

export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props): React.ReactElement {
export function SessionList({ sessions, onSelect, onCancel, onDelete, onRename }: Props): React.ReactElement {
const [index, setIndex] = useState(0);
const [searchQuery, setSearchQuery] = useState("");
const [confirmDeleteSessionId, setConfirmDeleteSessionId] = useState<string | null>(null);
const [renameSessionId, setRenameSessionId] = useState<string | null>(null);
const [renameValue, setRenameValue] = useState("");
const [renameCursor, setRenameCursor] = useState(0);
const { columns, rows } = useWindowSize();

// Filter sessions by search query
Expand Down Expand Up @@ -83,6 +87,65 @@ export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props):
const selectedSession = filteredSessions[safeIndex];

useInput((input, key) => {
// If in rename mode, handle rename editing
if (renameSessionId) {
if (key.return) {
if (renameValue.trim()) {
onRename?.(renameSessionId, renameValue.trim());
}
setRenameSessionId(null);
setRenameValue("");
setRenameCursor(0);
return;
}
if (key.escape) {
setRenameSessionId(null);
setRenameValue("");
setRenameCursor(0);
return;
}
if (key.leftArrow) {
setRenameCursor((c) => Math.max(0, c - 1));
return;
}
if (key.rightArrow) {
setRenameCursor((c) => Math.min(renameValue.length, c + 1));
return;
}
if (key.home) {
setRenameCursor(0);
return;
}
if (key.end) {
setRenameCursor(renameValue.length);
return;
}
if (key.delete) {
if (renameCursor < renameValue.length) {
setRenameValue((prev) => prev.slice(0, renameCursor) + prev.slice(renameCursor + 1));
// cursor stays at same position (next char shifts left)
}
return;
}
if (key.backspace) {
if (renameCursor > 0) {
setRenameValue((prev) => prev.slice(0, renameCursor - 1) + prev.slice(renameCursor));
setRenameCursor((c) => c - 1);
}
return;
}
// Printable character: insert at cursor position
if (input && input.length > 0 && !key.meta && !key.ctrl && !key.tab) {
if (key.upArrow || key.downArrow) {
return;
}
setRenameValue((prev) => prev.slice(0, renameCursor) + input + prev.slice(renameCursor));
setRenameCursor((c) => c + input.length);
return;
}
return;
}

// If in delete confirmation mode, handle confirm/cancel
if (confirmDeleteSessionId) {
if (key.return) {
Expand Down Expand Up @@ -114,6 +177,17 @@ export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props):
return;
}

// Ctrl+R: start rename on selected session
if (key.ctrl && (input === "r" || input === "R")) {
if (selectedSession && onRename) {
const name = selectedSession.summary || "";
setRenameSessionId(selectedSession.id);
setRenameValue(name);
setRenameCursor(name.length);
return;
}
}

// Delete key: remove search character, or start delete confirmation
if (key.delete || key.backspace) {
if (searchQuery) {
Expand Down Expand Up @@ -237,19 +311,28 @@ export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props):
const actualIndex = scrollOffset + i;
const isSelected = actualIndex === safeIndex;
const isConfirming = confirmDeleteSessionId === session.id;
const isRenaming = renameSessionId === session.id;
return (
<Box key={session.id} height={2} marginBottom={1}>
<Box>
<Text color="#229ac3">{isSelected ? "> " : " "}</Text>
</Box>
<Box flexDirection="column" flexGrow={1}>
<Box width={"100%"}>
<Text {...(isSelected ? { bold: true } : {})} color={isSelected ? "#229ac3" : undefined}>
{formatSessionTitle(session.summary || "Untitled")}
</Text>
{isRenaming ? (
<Text color="yellow">
Rename: {renameValue.slice(0, renameCursor)}
<Text bold>|</Text>
{renameValue.slice(renameCursor)}
</Text>
) : (
<Text {...(isSelected ? { bold: true } : {})} color={isSelected ? "#229ac3" : undefined}>
{formatSessionTitle(session.summary || "Untitled")}
</Text>
)}
{isConfirming ? (
<Text color="yellow"> [Delete? Enter=yes, Esc=no]</Text>
) : (
) : isRenaming ? null : (
<Text dimColor> ({formatSessionStatus(session.status)})</Text>
)}
</Box>
Expand All @@ -272,7 +355,19 @@ export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props):
</Box>
{/* Footer */}
<Box flexDirection="column">
{confirmDeleteSessionId ? (
{renameSessionId ? (
<Box>
<Text color="yellow">Input new session name, </Text>
<Text bold color="green">
Enter
</Text>
<Text dimColor> to save · </Text>
<Text bold color="red">
Esc
</Text>
<Text dimColor> to cancel</Text>
</Box>
) : confirmDeleteSessionId ? (
<Box>
<Text color="yellow">Delete this session? </Text>
<Text bold color="green">
Expand All @@ -292,7 +387,7 @@ export function SessionList({ sessions, onSelect, onCancel, onDelete }: Props):
) : (
<Box>
<Text dimColor>
Type to search · ↑/↓ navigate · PgUp/PgDn page · Enter select · Esc cancel · Del delete
Type to search · ↑/↓ navigate · PgUp/PgDn page · Enter select · Esc cancel · Del delete · Ctrl+r rename
</Text>
</Box>
)}
Expand Down
Loading