fix(cli): skip thought parts in copy output (#4738)

This commit is contained in:
Yufeng He 2026-06-04 11:43:46 +08:00 committed by GitHub
parent 16dd99fa3c
commit 58b4f35dfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -160,6 +160,32 @@ describe('copyCommand', () => {
});
});
it('should not copy thought parts from the last AI message', async () => {
if (!copyCommand.action) throw new Error('Command has no action');
const historyWithThoughtPart = [
{
role: 'model',
parts: [
{ text: 'internal reasoning', thought: true },
{ text: 'Visible report' },
],
},
];
mockGetHistoryShallow.mockReturnValue(historyWithThoughtPart);
mockCopyToClipboard.mockResolvedValue(undefined);
const result = await copyCommand.action(mockContext, '');
expect(mockCopyToClipboard).toHaveBeenCalledWith('Visible report');
expect(result).toEqual({
type: 'message',
messageType: 'info',
content: 'Last output copied to the clipboard',
});
});
it('should filter out non-text parts', async () => {
if (!copyCommand.action) throw new Error('Command has no action');

View file

@ -362,7 +362,7 @@ export const copyCommand: SlashCommand = {
}
// Extract text from the parts
const lastAiOutput = lastAiMessage.parts
?.filter((part) => part.text)
?.filter((part) => part.text && !part.thought)
.map((part) => part.text)
.join('');