diff options
Diffstat (limited to 'packages/cli/src/ui')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 75 | ||||
| -rw-r--r-- | packages/cli/src/ui/types.ts | 2 |
2 files changed, 74 insertions, 3 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', diff --git a/packages/cli/src/ui/types.ts b/packages/cli/src/ui/types.ts index 559a30a3..5fae1568 100644 --- a/packages/cli/src/ui/types.ts +++ b/packages/cli/src/ui/types.ts @@ -131,7 +131,7 @@ export enum MessageType { USER = 'user', ABOUT = 'about', STATS = 'stats', - // Add GEMINI if needed by other commands + GEMINI = 'gemini', } // Simplified message structure for internal feedback |
