diff options
| author | Seth Troisi <[email protected]> | 2025-06-10 20:24:48 +0000 |
|---|---|---|
| committer | Seth Troisi <[email protected]> | 2025-06-10 16:14:42 -0700 |
| commit | 36f58a34b411f746c2b01f4cb96b2a5fb4e1822e (patch) | |
| tree | 12d374271de6ffca0169d93114682533cb81be23 /packages/cli/src/ui/hooks/slashCommandProcessor.ts | |
| parent | d79dafc57715a014e71884f3ba4e7d82b0bb228c (diff) | |
logConversation
loadConversation
/resume
clean up for review
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 9e82b6cf..c468a444 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -11,10 +11,11 @@ import process from 'node:process'; import { UseHistoryManagerReturn } from './useHistoryManager.js'; import { Config, + Logger, + MCPDiscoveryState, MCPServerStatus, - getMCPServerStatus, getMCPDiscoveryState, - MCPDiscoveryState, + getMCPServerStatus, } from '@gemini-cli/core'; import { Message, MessageType, HistoryItemWithoutId } from '../types.js'; import { useSessionStats } from '../contexts/SessionContext.js'; @@ -488,6 +489,76 @@ Add any other context about the problem here. }, }, { + name: 'save', + description: 'save conversation checkpoint', + action: async (_mainCommand, _subCommand, _args) => { + const logger = new Logger(); + await logger.initialize(); + const chat = await config?.getGeminiClient()?.getChat(); + const history = chat?.getHistory() || []; + if (history.length > 0) { + logger.saveCheckpoint(chat?.getHistory() || []); + } else { + addMessage({ + type: MessageType.INFO, + content: 'No conversation found to save.', + timestamp: new Date(), + }); + return; + } + }, + }, + { + name: 'resume', + description: 'resume from last conversation checkpoint', + action: async (_mainCommand, _subCommand, _args) => { + const logger = new Logger(); + await logger.initialize(); + const conversation = await logger.loadCheckpoint(); + if (conversation.length === 0) { + addMessage({ + type: MessageType.INFO, + content: 'No saved conversation found.', + timestamp: new Date(), + }); + return; + } + const chat = await config?.getGeminiClient()?.getChat(); + clearItems(); + let i = 0; + const rolemap: { [key: string]: MessageType } = { + user: MessageType.USER, + model: MessageType.GEMINI, + }; + for (const item of conversation) { + i += 1; + const text = + item.parts + ?.filter((m) => !!m.text) + .map((m) => m.text) + .join('') || ''; + if (i <= 2) { + // Skip system prompt back and forth. + continue; + } + if (!text) { + // Parsing Part[] back to various non-text output not yet implemented. + continue; + } + addItem( + { + type: (item.role && rolemap[item.role]) || MessageType.GEMINI, + text, + } as HistoryItemWithoutId, + i, + ); + chat?.addHistory(item); + } + console.clear(); + refreshStatic(); + }, + }, + { name: 'quit', altName: 'exit', description: 'exit the cli', |
