Skip to content

Commit 4c0b3c2

Browse files
committed
feat(app): 优化历史记录加载逻辑,确保会话上下文正确更新;调整步骤视图组件的布局
1 parent 7c79d3e commit 4c0b3c2

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎packages/ui/src/tui/App.tsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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]

‎packages/ui/src/tui/components/turns/StepView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function StepView({ step }: StepViewProps) {
1616
<Box flexDirection="column">
1717
{shouldRenderAssistant ? <AssistantMessage text={assistantText} /> : null}
1818
{step.action ? (
19-
<Box flexDirection="column" marginTop={1} marginLeft={2}>
19+
<Box flexDirection="column" marginLeft={2}>
2020
<Text color="yellow">
2121
Tool: {step.action.tool} [{step.toolStatus ?? 'pending'}]
2222
</Text>

0 commit comments

Comments
 (0)