diff options
Diffstat (limited to 'packages/cli/src/ui/hooks')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.test.ts | 37 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 23 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useReactToolScheduler.ts | 2 |
3 files changed, 59 insertions, 3 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index f16d3239..0c12d855 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -396,6 +396,43 @@ Add any other context about the problem here. }); }); + describe('/quit and /exit commands', () => { + beforeEach(() => { + vi.useFakeTimers(); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + + it.each([['/quit'], ['/exit']])( + 'should handle %s, add a quit message, and exit the process', + async (command) => { + const { handleSlashCommand } = getProcessor(); + const mockDate = new Date('2025-01-01T01:02:03.000Z'); + vi.setSystemTime(mockDate); + + await act(async () => { + handleSlashCommand(command); + }); + + expect(mockAddItem).toHaveBeenCalledTimes(2); + expect(mockAddItem).toHaveBeenNthCalledWith( + 2, + expect.objectContaining({ + type: MessageType.QUIT, + duration: '1h 2m 3s', + }), + expect.any(Number), + ); + + // Fast-forward timers to trigger process.exit + vi.advanceTimersByTime(100); + expect(mockProcessExit).toHaveBeenCalledWith(0); + }, + ); + }); + describe('Unknown command', () => { it('should show an error and return true for a general unknown command', async () => { const { handleSlashCommand } = getProcessor(); diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 3699b4e9..8e2f2bd2 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -97,6 +97,12 @@ export const useSlashCommandProcessor = ( lastTurnStats: message.lastTurnStats, duration: message.duration, }; + } else if (message.type === MessageType.QUIT) { + historyItemContent = { + type: 'quit', + stats: message.stats, + duration: message.duration, + }; } else { historyItemContent = { type: message.type as @@ -594,8 +600,20 @@ Add any other context about the problem here. altName: 'exit', description: 'exit the cli', action: async (_mainCommand, _subCommand, _args) => { - onDebugMessage('Quitting. Good-bye.'); - process.exit(0); + const now = new Date(); + const { sessionStartTime, cumulative } = session.stats; + const wallDuration = now.getTime() - sessionStartTime.getTime(); + + addMessage({ + type: MessageType.QUIT, + stats: cumulative, + duration: formatDuration(wallDuration), + timestamp: new Date(), + }); + + setTimeout(() => { + process.exit(0); + }, 100); }, }, ]; @@ -721,6 +739,7 @@ Add any other context about the problem here. session, gitService, loadHistory, + addItem, ]); const handleSlashCommand = useCallback( diff --git a/packages/cli/src/ui/hooks/useReactToolScheduler.ts b/packages/cli/src/ui/hooks/useReactToolScheduler.ts index 4e55cba4..8ae7ebfb 100644 --- a/packages/cli/src/ui/hooks/useReactToolScheduler.ts +++ b/packages/cli/src/ui/hooks/useReactToolScheduler.ts @@ -132,7 +132,7 @@ export function useReactToolScheduler( }); onComplete(completedToolCalls); }, - [onComplete], + [onComplete, config], ); const toolCallsUpdateHandler: ToolCallsUpdateHandler = useCallback( |
