diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 0f34bcf9c..3ddc1a12e 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -70,6 +70,11 @@ export const SYSTEM_SLASH_COMMANDS: SystemCommand[] = [ description: "Summarize chat history into a compact form", category: "system", }, + { + name: "resume", + description: "Resume a previous chat session", + category: "system", + }, { name: "exit", description: "Exit the chat", diff --git a/src/slashCommands.test.ts b/src/slashCommands.test.ts index 619239860..c8e9efc23 100644 --- a/src/slashCommands.test.ts +++ b/src/slashCommands.test.ts @@ -194,6 +194,13 @@ describe("handleSlashCommands", () => { expect(result?.compact).toBe(true); }); + test("resume command should open session selector", async () => { + const result = await handleSlashCommands("/resume", mockAssistant); + + expect(result).not.toBeNull(); + expect(result?.openSessionSelector).toBe(true); + }); + test("non-slash input should return null", async () => { const result = await handleSlashCommands("regular input", mockAssistant); expect(result).toBeNull(); diff --git a/src/slashCommands.ts b/src/slashCommands.ts index a865c8e9c..9a5247379 100644 --- a/src/slashCommands.ts +++ b/src/slashCommands.ts @@ -197,6 +197,10 @@ const commandHandlers: Record = { posthogService.capture("useSlashCommand", { name: "mcp" }); return { openMcpSelector: true }; }, + resume: () => { + posthogService.capture("useSlashCommand", { name: "resume" }); + return { openSessionSelector: true }; + }, org: handleOrg, }; @@ -211,6 +215,7 @@ export async function handleSlashCommands( openConfigSelector?: boolean; openModelSelector?: boolean; openMCPSelector?: boolean; + openSessionSelector?: boolean; compact?: boolean; } | null> { // Only trigger slash commands if slash is the very first character diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index c8c4e0f29..a730d5daa 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -108,6 +108,7 @@ const TUIChat: React.FC = ({ messages, setMessages, chatHistory, + setChatHistory, isWaitingForResponse, responseStartTime, inputMode, @@ -128,6 +129,7 @@ const TUIChat: React.FC = ({ onShowConfigSelector: () => navigateTo("config"), onShowModelSelector: () => navigateTo("model"), onShowMCPSelector: () => navigateTo("mcp"), + onShowSessionSelector: () => navigateTo("session"), onLoginPrompt: handleLoginPrompt, onReload: handleReload, // Remote mode configuration @@ -146,6 +148,48 @@ const TUIChat: React.FC = ({ const { handleOrganizationSelect, handleConfigSelect, handleModelSelect } = useSelectors(configPath, setMessages, resetChatHistory); + // Session selection handler + const handleSessionSelect = async (sessionId: string) => { + try { + // Close the session selector + closeCurrentScreen(); + + // Import session functions + const { loadSessionById } = await import("../session.js"); + + // Load the session history + const sessionHistory = loadSessionById(sessionId); + if (!sessionHistory) { + console.error(`Session ${sessionId} could not be loaded.`); + return; + } + + // Set the session ID so future operations use this session + process.env.CONTINUE_CLI_TEST_SESSION_ID = sessionId.replace( + "continue-cli-", + "", + ); + + // Directly set the chat history and messages to the loaded session + setChatHistory(sessionHistory); + + // Convert chat history to display messages (exclude system messages) + const displayMessages = sessionHistory + .filter((msg) => msg.role !== "system") + .map((msg) => ({ + role: msg.role, + content: msg.content as string, + })); + + setMessages(displayMessages); + + // Clear the intro message since we're now showing a resumed session + setShowIntroMessage(false); + } catch (error) { + console.error("Error loading session:", error); + } + }; + // Determine if input should be disabled // Allow input even when services are loading, but disable for UI overlays const isInputDisabled = @@ -203,6 +247,7 @@ const TUIChat: React.FC = ({ handleOrganizationSelect={handleOrganizationSelect} handleConfigSelect={handleConfigSelect} handleModelSelect={handleModelSelect} + handleSessionSelect={handleSessionSelect} handleReload={handleReload} closeCurrentScreen={closeCurrentScreen} activePermissionRequest={activePermissionRequest} diff --git a/src/ui/components/ScreenContent.tsx b/src/ui/components/ScreenContent.tsx index 8e0e8c779..effe7483c 100644 --- a/src/ui/components/ScreenContent.tsx +++ b/src/ui/components/ScreenContent.tsx @@ -1,12 +1,14 @@ import { Box, Text } from "ink"; import React from "react"; +import { listSessions } from "../../session.js"; import { ConfigSelector } from "../ConfigSelector.js"; import type { NavigationScreen } from "../context/NavigationContext.js"; import { FreeTrialTransitionUI } from "../FreeTrialTransitionUI.js"; import { MCPSelector } from "../MCPSelector.js"; import { ModelSelector } from "../ModelSelector.js"; import { OrganizationSelector } from "../OrganizationSelector.js"; +import { SessionSelector } from "../SessionSelector.js"; import type { ConfigOption, ModelOption } from "../types/selectorTypes.js"; import { UserInput } from "../UserInput.js"; @@ -23,6 +25,7 @@ interface ScreenContentProps { ) => Promise; handleConfigSelect: (config: ConfigOption) => Promise; handleModelSelect: (model: ModelOption) => Promise; + handleSessionSelect: (sessionId: string) => Promise; handleReload: () => Promise; closeCurrentScreen: () => void; activePermissionRequest: any; @@ -49,6 +52,7 @@ export const ScreenContent: React.FC = ({ handleOrganizationSelect, handleConfigSelect, handleModelSelect, + handleSessionSelect, handleReload, closeCurrentScreen, activePermissionRequest, @@ -122,6 +126,18 @@ export const ScreenContent: React.FC = ({ ); } + // Session selector + if (isScreenActive("session")) { + const sessions = listSessions(20); + return ( + + ); + } + // Free trial transition UI if (isScreenActive("free-trial")) { return ; diff --git a/src/ui/context/NavigationContext.tsx b/src/ui/context/NavigationContext.tsx index 70e052940..dc3e1d8fa 100644 --- a/src/ui/context/NavigationContext.tsx +++ b/src/ui/context/NavigationContext.tsx @@ -17,7 +17,8 @@ export type NavigationScreen = | "model" // Model selector | "free-trial" // Free trial transition UI | "login" // Login prompt - | "mcp"; // MCP selector + | "mcp" // MCP selector + | "session"; // Session selector interface NavigationState { currentScreen: NavigationScreen; diff --git a/src/ui/hooks/useChat.helpers.ts b/src/ui/hooks/useChat.helpers.ts index b2b0687e3..68fbb6abe 100644 --- a/src/ui/hooks/useChat.helpers.ts +++ b/src/ui/hooks/useChat.helpers.ts @@ -126,6 +126,7 @@ interface ProcessSlashCommandResultOptions { onShowConfigSelector: () => void; onShowModelSelector?: () => void; onShowMCPSelector?: () => void; + onShowSessionSelector?: () => void; } /** @@ -140,6 +141,7 @@ export function processSlashCommandResult({ onShowConfigSelector, onShowModelSelector, onShowMCPSelector, + onShowSessionSelector, }: ProcessSlashCommandResultOptions): string | null { if (result.exit) { exit(); @@ -161,6 +163,11 @@ export function processSlashCommandResult({ return null; } + if (result.openSessionSelector && onShowSessionSelector) { + onShowSessionSelector(); + return null; + } + if (result.clear) { const systemMessage = chatHistory.find((msg) => msg.role === "system"); const newHistory = systemMessage ? [systemMessage] : []; diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts index b679c327e..9ee962327 100644 --- a/src/ui/hooks/useChat.ts +++ b/src/ui/hooks/useChat.ts @@ -46,6 +46,7 @@ export function useChat({ onShowConfigSelector, onShowModelSelector, onShowMCPSelector, + onShowSessionSelector, onLoginPrompt: _onLoginPrompt, isRemoteMode = false, remoteUrl, @@ -197,6 +198,7 @@ export function useChat({ onShowConfigSelector, onShowModelSelector, onShowMCPSelector, + onShowSessionSelector, }); if (newInput) { diff --git a/src/ui/hooks/useChat.types.ts b/src/ui/hooks/useChat.types.ts index 8660cd717..832f96501 100644 --- a/src/ui/hooks/useChat.types.ts +++ b/src/ui/hooks/useChat.types.ts @@ -15,6 +15,7 @@ export interface UseChatProps { onShowConfigSelector: () => void; onShowMCPSelector: () => void; onShowModelSelector?: () => void; + onShowSessionSelector?: () => void; onLoginPrompt?: (promptText: string) => Promise; onReload?: () => Promise; // Remote mode props @@ -58,5 +59,6 @@ export interface SlashCommandResult { openConfigSelector?: boolean; openModelSelector?: boolean; openMcpSelector?: boolean; + openSessionSelector?: boolean; compact?: boolean; }