@@ -223,7 +223,14 @@ export function App({
223223 const parsed = parseHistoryLog ( raw )
224224 setHistoricalTurns ( parsed . turns )
225225 setPendingHistoryMessages ( parsed . messages )
226+ setBusy ( false )
227+ setStatusMessage ( null )
226228 setTurns ( [ ] )
229+ setSession ( null )
230+ setSessionLogPath ( null )
231+ currentTurnRef . current = null
232+ // 重新拉起 session,避免旧上下文残留/计数错位
233+ setSessionOptionsState ( ( prev ) => ( { ...prev , sessionId : randomUUID ( ) } ) )
227234 appendSystemMessage ( '历史记录已加载' , parsed . summary || entry . input )
228235 } catch ( err ) {
229236 appendSystemMessage (
@@ -319,6 +326,15 @@ export function App({
319326 ] ,
320327 )
321328
329+ useEffect ( ( ) => {
330+ if ( ! session || ! pendingHistoryMessages ?. length ) return
331+ // 用历史对话覆盖当前 session 的用户上下文,保留系统提示词。
332+ const systemMessage = session . history [ 0 ]
333+ if ( ! systemMessage ) return
334+ session . history . splice ( 0 , session . history . length , systemMessage , ...pendingHistoryMessages )
335+ setPendingHistoryMessages ( null )
336+ } , [ pendingHistoryMessages , session ] )
337+
322338 const handleSubmit = useCallback (
323339 async ( value : string ) => {
324340 if ( ! session || busy ) return
@@ -328,10 +344,6 @@ export function App({
328344 return
329345 }
330346 setInputHistory ( ( prev ) => [ ...prev , value ] )
331- if ( pendingHistoryMessages ?. length && session ) {
332- session . history . push ( ...pendingHistoryMessages )
333- setPendingHistoryMessages ( null )
334- }
335347 setBusy ( true )
336348 try {
337349 await session . runTurn ( value )
@@ -340,7 +352,7 @@ export function App({
340352 setBusy ( false )
341353 }
342354 } ,
343- [ busy , handleCommand , session , pendingHistoryMessages ] ,
355+ [ busy , handleCommand , session ] ,
344356 )
345357
346358 const lastTurn = turns [ turns . length - 1 ]
0 commit comments