Skip to content

Commit 2b9e974

Browse files
committed
/chats screen!
1 parent 70a56e6 commit 2b9e974

File tree

8 files changed

+600
-4
lines changed

8 files changed

+600
-4
lines changed

cli/src/app.tsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
33
import { useShallow } from 'zustand/react/shallow'
44

55
import { Chat } from './chat'
6+
import { ChatHistoryScreen } from './components/chat-history-screen'
67
import { LoginModal } from './components/login-modal'
78
import { ProjectPickerScreen } from './components/project-picker-screen'
89
import { TerminalLink } from './components/terminal-link'
@@ -15,6 +16,7 @@ import { useTerminalFocus } from './hooks/use-terminal-focus'
1516
import { useTheme } from './hooks/use-theme'
1617
import { getProjectRoot } from './project-files'
1718
import { useChatStore, type TopBannerType } from './state/chat-store'
19+
import { useChatHistoryStore } from './state/chat-history-store'
1820
import { openFileAtPath } from './utils/open-file'
1921
import { formatCwd } from './utils/path-helpers'
2022
import { findGitRoot } from './utils/git'
@@ -169,6 +171,32 @@ export const App = ({
169171
}
170172
}, [gitRoot, onProjectChange])
171173

174+
// Chat history state from store
175+
const { showChatHistory, closeChatHistory } = useChatHistoryStore()
176+
177+
// State to track which chat to resume (set when user selects from history)
178+
const [resumeChatId, setResumeChatId] = useState<string | null>(null)
179+
180+
const handleResumeChat = useCallback(
181+
(chatId: string) => {
182+
closeChatHistory()
183+
// Reset chat store to clear previous messages before loading the selected chat
184+
resetChatStore()
185+
setResumeChatId(chatId)
186+
},
187+
[closeChatHistory, resetChatStore]
188+
)
189+
190+
const handleNewChat = useCallback(() => {
191+
closeChatHistory()
192+
resetChatStore()
193+
setResumeChatId(null)
194+
}, [closeChatHistory, resetChatStore])
195+
196+
// Determine effective continueChat values
197+
const effectiveContinueChat = continueChat || resumeChatId !== null
198+
const effectiveContinueChatId = resumeChatId ?? continueChatId
199+
172200
const headerContent = useMemo(() => {
173201
const displayPath = formatCwd(projectRoot)
174202

@@ -252,8 +280,23 @@ export const App = ({
252280
)
253281
}
254282

283+
// Render chat history screen when requested
284+
if (showChatHistory) {
285+
return (
286+
<ChatHistoryScreen
287+
onSelectChat={handleResumeChat}
288+
onCancel={closeChatHistory}
289+
onNewChat={handleNewChat}
290+
/>
291+
)
292+
}
293+
294+
// Use key to force remount when resuming a different chat from history
295+
const chatKey = resumeChatId ?? 'current'
296+
255297
return (
256298
<Chat
299+
key={chatKey}
257300
headerContent={headerContent}
258301
initialPrompt={initialPrompt}
259302
agentId={agentId}
@@ -262,8 +305,8 @@ export const App = ({
262305
setIsAuthenticated={setIsAuthenticated}
263306
setUser={setUser}
264307
logoutMutation={logoutMutation}
265-
continueChat={continueChat}
266-
continueChatId={continueChatId}
308+
continueChat={effectiveContinueChat}
309+
continueChatId={effectiveContinueChatId}
267310
authStatus={authStatus}
268311
initialMode={initialMode}
269312
gitRoot={gitRoot}

cli/src/chat.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { useUsageMonitor } from './hooks/use-usage-monitor'
5454
import { WEBSITE_URL } from './login/constants'
5555
import { getProjectRoot } from './project-files'
5656
import { useChatStore } from './state/chat-store'
57+
import { useChatHistoryStore } from './state/chat-history-store'
5758
import { useFeedbackStore } from './state/feedback-store'
5859
import { usePublishStore } from './state/publish-store'
5960
import {
@@ -867,6 +868,10 @@ export const Chat = ({
867868
openPublishMode()
868869
}
869870
}
871+
872+
if (result.openChatHistory) {
873+
useChatHistoryStore.getState().openChatHistory()
874+
}
870875
},
871876
[
872877
saveCurrentInput,

cli/src/commands/command-registry.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type RouterParams = {
5454
export type CommandResult = {
5555
openFeedbackMode?: boolean
5656
openPublishMode?: boolean
57+
openChatHistory?: boolean
5758
preSelectAgents?: string[]
5859
} | void
5960

@@ -463,6 +464,15 @@ export const COMMAND_REGISTRY: CommandDefinition[] = [
463464
clearInput(params)
464465
},
465466
}),
467+
defineCommand({
468+
name: 'chats',
469+
aliases: ['history'],
470+
handler: (params) => {
471+
params.saveToHistory(params.inputValue.trim())
472+
clearInput(params)
473+
return { openChatHistory: true }
474+
},
475+
}),
466476
]
467477

468478
export function findCommand(cmd: string): CommandDefinition | undefined {

0 commit comments

Comments
 (0)