From 600151cc2c78c457112e6d7480cb8bafea40f255 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 28 Aug 2025 10:25:13 -0700 Subject: [PATCH] bug(core): Strip thoughts when loading history. (#7167) --- .../ui/hooks/slashCommandProcessor.test.ts | 38 +++++++++++++++++++ .../cli/src/ui/hooks/slashCommandProcessor.ts | 4 +- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index b19cd21d3a..f04caf1fb4 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -417,6 +417,44 @@ describe('useSlashCommandProcessor', () => { ); }); + it('should strip thoughts when handling "load_history" action', async () => { + const mockSetHistory = vi.fn(); + const mockGeminiClient = { + setHistory: mockSetHistory, + }; + vi.spyOn(mockConfig, 'getGeminiClient').mockReturnValue( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + mockGeminiClient as any, + ); + + const historyWithThoughts = [ + { + role: 'model', + parts: [{ text: 'response', thoughtSignature: 'CikB...' }], + }, + ]; + const command = createTestCommand({ + name: 'loadwiththoughts', + action: vi.fn().mockResolvedValue({ + type: 'load_history', + history: [{ type: MessageType.MODEL, text: 'response' }], + clientHistory: historyWithThoughts, + }), + }); + + const result = setupProcessorHook([command]); + await waitFor(() => expect(result.current.slashCommands).toHaveLength(1)); + + await act(async () => { + await result.current.handleSlashCommand('/loadwiththoughts'); + }); + + expect(mockSetHistory).toHaveBeenCalledTimes(1); + expect(mockSetHistory).toHaveBeenCalledWith(historyWithThoughts, { + stripThoughts: true, + }); + }); + describe('with fake timers', () => { // This test needs to let the async `waitFor` complete with REAL timers // before switching to FAKE timers to test setTimeout. diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index c36340db11..350df660d2 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -393,9 +393,9 @@ export const useSlashCommandProcessor = ( } } case 'load_history': { - await config + config ?.getGeminiClient() - ?.setHistory(result.clientHistory); + ?.setHistory(result.clientHistory, { stripThoughts: true }); fullCommandContext.ui.clear(); result.history.forEach((item, index) => { fullCommandContext.ui.addItem(item, index);