@@ -52,7 +52,7 @@ import { SessionTodoDisplay } from "@/components/message/SessionTodoDisplay";
5252import { useDialogParam } from "@/hooks/useDialogParam" ;
5353import { useSidebarAction } from "@/hooks/useSidebarAction" ;
5454import { SessionMoreButton } from "@/components/navigation/SessionMoreButton" ;
55- import { setCachedAssistantSessionId } from "@/hooks/useAssistantSessionLauncher" ;
55+ import { getCachedAssistantDirectory , setCachedAssistantSessionId } from "@/hooks/useAssistantSessionLauncher" ;
5656
5757const compareMessageIds = ( id1 : string , id2 : string ) : number => {
5858 const num1 = parseInt ( id1 , 10 )
@@ -120,7 +120,8 @@ export function SessionDetail() {
120120
121121 const opcodeUrl = OPENCODE_API_ENDPOINT ;
122122
123- const repoDirectory = navigationDirectory ?? repo ?. fullPath ;
123+ const cachedAssistantDirectory = isAssistantSession ? getCachedAssistantDirectory ( repoId ) : undefined ;
124+ const repoDirectory = navigationDirectory ?? repo ?. fullPath ?? cachedAssistantDirectory ;
124125 const sessionRouteSuffix = isAssistantSession ? '?assistant=1' : '' ;
125126
126127 useEffect ( ( ) => {
@@ -129,13 +130,13 @@ export function SessionDetail() {
129130 }
130131 } , [ isAssistantSession , repoDirectory , repoId , sessionId ] ) ;
131132
132- const { isConnected, isReconnecting } = useSSE ( opcodeUrl , repoDirectory , sessionId ) ;
133-
134133 const { data : rawMessages , isLoading : messagesLoading } = useMessages ( opcodeUrl , sessionId , repoDirectory ) ;
134+ const initialMessagesDirectory = repoDirectory && ! messagesLoading ? repoDirectory : undefined ;
135+ const { isConnected, isReconnecting } = useSSE ( opcodeUrl , initialMessagesDirectory , sessionId ) ;
135136 const { data : session } = useSession (
136137 opcodeUrl ,
137138 sessionId ,
138- repoDirectory ,
139+ initialMessagesDirectory ,
139140 ) ;
140141
141142 const messages = useMemo ( ( ) => {
@@ -161,7 +162,7 @@ export function SessionDetail() {
161162 const abortSession = useAbortSession ( opcodeUrl , repoDirectory , sessionId ) ;
162163 const updateSession = useUpdateSession ( opcodeUrl , repoDirectory ) ;
163164 const createSession = useCreateSession ( opcodeUrl , repoDirectory ) ;
164- const { model, modelString } = useModelSelection ( opcodeUrl , repoDirectory ) ;
165+ const { model, modelString } = useModelSelection ( opcodeUrl , initialMessagesDirectory ) ;
165166 const isEditingMessage = useUIState ( ( state ) => state . isEditingMessage ) ;
166167 const setActivePromptFileBasePath = useUIState ( ( state ) => state . setActivePromptFileBasePath ) ;
167168 const { isEnabled : ttsEnabled } = useTTS ( ) ;
@@ -217,20 +218,20 @@ export function SessionDetail() {
217218 } , [ sessionId , minimizedQuestion ] )
218219
219220 const syncPendingActionsForSession = useCallback ( async ( ) => {
220- if ( ! repoDirectory || ! sessionId ) return
221+ if ( ! initialMessagesDirectory || ! sessionId ) return
221222 await Promise . all ( [
222- syncPermissionsForSession ( repoDirectory , sessionId ) ,
223- syncQuestionsForSession ( repoDirectory , sessionId ) ,
223+ syncPermissionsForSession ( initialMessagesDirectory , sessionId ) ,
224+ syncQuestionsForSession ( initialMessagesDirectory , sessionId ) ,
224225 ] )
225- } , [ repoDirectory , sessionId , syncPermissionsForSession , syncQuestionsForSession ] )
226+ } , [ initialMessagesDirectory , sessionId , syncPermissionsForSession , syncQuestionsForSession ] )
226227
227228 useQuery ( {
228- queryKey : [ 'opencode' , 'pending-actions' , opcodeUrl , sessionId , repoDirectory ] ,
229+ queryKey : [ 'opencode' , 'pending-actions' , opcodeUrl , sessionId , initialMessagesDirectory ] ,
229230 queryFn : async ( ) => {
230231 await syncPendingActionsForSession ( )
231232 return null
232233 } ,
233- enabled : ! ! repoDirectory && ! ! sessionId ,
234+ enabled : ! ! initialMessagesDirectory && ! ! sessionId ,
234235 refetchOnMount : 'always' ,
235236 refetchOnReconnect : true ,
236237 refetchOnWindowFocus : true ,
@@ -475,13 +476,15 @@ export function SessionDetail() {
475476 < div className = "flex items-center gap-1" >
476477 < PendingActionsGroup />
477478 </ div >
478- < ContextUsageIndicator
479- opcodeUrl = { opcodeUrl }
480- sessionID = { sessionId }
481- directory = { repoDirectory }
482- isConnected = { isConnected }
483- isReconnecting = { isReconnecting }
484- />
479+ { initialMessagesDirectory && (
480+ < ContextUsageIndicator
481+ opcodeUrl = { opcodeUrl }
482+ sessionID = { sessionId }
483+ directory = { initialMessagesDirectory }
484+ isConnected = { isConnected }
485+ isReconnecting = { isReconnecting }
486+ />
487+ ) }
485488 < SessionMoreButton />
486489 </ Header . Actions >
487490 </ Header >
@@ -508,7 +511,7 @@ export function SessionDetail() {
508511 />
509512 ) : null }
510513 </ div >
511- { opcodeUrl && repoDirectory && ! isEditingMessage && (
514+ { opcodeUrl && initialMessagesDirectory && ! isEditingMessage && (
512515 < div
513516 ref = { promptOverlayRef }
514517 className = "absolute left-0 right-0 flex justify-center"
@@ -563,7 +566,7 @@ export function SessionDetail() {
563566 < PromptInput
564567 ref = { promptInputRef }
565568 opcodeUrl = { opcodeUrl }
566- directory = { repoDirectory }
569+ directory = { initialMessagesDirectory }
567570 sessionID = { sessionId }
568571 disabled = { ! isConnected }
569572 showScrollButton = { showScrollButton && ! hasPromptContent }
0 commit comments