moving `/save`, `/resume` to `/chat <save|resume>` (#1355)

This commit is contained in:
Seth Troisi 2025-06-23 16:56:08 -07:00 committed by GitHub
parent f741630572
commit 335802f4dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 91 additions and 80 deletions

View File

@ -651,14 +651,25 @@ Add any other context about the problem here.
}, },
}, },
{ {
name: 'save', name: 'chat',
description: 'save conversation checkpoint. Usage: /save [tag]', description:
action: async (_mainCommand, subCommand, _args) => { 'Manage conversation history. Usage: /chat <save|resume> [tag]',
const tag = (subCommand || '').trim(); action: async (_mainCommand, subCommand, args) => {
const tag = (args || '').trim();
const logger = new Logger(config?.getSessionId() || ''); const logger = new Logger(config?.getSessionId() || '');
await logger.initialize(); await logger.initialize();
const chat = await config?.getGeminiClient()?.getChat(); const chat = await config?.getGeminiClient()?.getChat();
const history = chat?.getHistory() || []; if (!chat) {
addMessage({
type: MessageType.ERROR,
content: 'No chat client available for conversation status.',
timestamp: new Date(),
});
return;
}
switch (subCommand) {
case 'save': {
const history = chat.getHistory();
if (history.length > 0) { if (history.length > 0) {
await logger.saveCheckpoint(chat?.getHistory() || [], tag); await logger.saveCheckpoint(chat?.getHistory() || [], tag);
addMessage({ addMessage({
@ -673,35 +684,11 @@ Add any other context about the problem here.
timestamp: new Date(), timestamp: new Date(),
}); });
} }
}, return;
},
{
name: 'resume',
description:
'resume from conversation checkpoint. Usage: /resume [tag]',
completion: async () => {
const geminiDir = config?.getProjectTempDir();
if (!geminiDir) {
return [];
} }
try { case 'resume':
const files = await fs.readdir(geminiDir); case 'restore':
return files case 'load': {
.filter(
(file) =>
file.startsWith('checkpoint-') && file.endsWith('.json'),
)
.map((file) =>
file.replace('checkpoint-', '').replace('.json', ''),
);
} catch (_err) {
return [];
}
},
action: async (_mainCommand, subCommand, _args) => {
const tag = (subCommand || '').trim();
const logger = new Logger(config?.getSessionId() || '');
await logger.initialize();
const conversation = await logger.loadCheckpoint(tag); const conversation = await logger.loadCheckpoint(tag);
if (conversation.length === 0) { if (conversation.length === 0) {
addMessage({ addMessage({
@ -711,23 +698,15 @@ Add any other context about the problem here.
}); });
return; return;
} }
const chat = await config?.getGeminiClient()?.getChat();
if (!chat) {
addMessage({
type: MessageType.ERROR,
content: 'No chat client available to resume conversation.',
timestamp: new Date(),
});
return;
}
clearItems(); clearItems();
chat.clearHistory(); chat.clearHistory();
const rolemap: { [key: string]: MessageType } = { const rolemap: { [key: string]: MessageType } = {
user: MessageType.USER, user: MessageType.USER,
model: MessageType.GEMINI, model: MessageType.GEMINI,
}; };
let i = 0;
let hasSystemPrompt = false; let hasSystemPrompt = false;
let i = 0;
for (const item of conversation) { for (const item of conversation) {
i += 1; i += 1;
const text = const text =
@ -746,7 +725,8 @@ Add any other context about the problem here.
if (i > 2 || !hasSystemPrompt) { if (i > 2 || !hasSystemPrompt) {
addItem( addItem(
{ {
type: (item.role && rolemap[item.role]) || MessageType.GEMINI, type:
(item.role && rolemap[item.role]) || MessageType.GEMINI,
text, text,
} as HistoryItemWithoutId, } as HistoryItemWithoutId,
i, i,
@ -755,6 +735,37 @@ Add any other context about the problem here.
} }
console.clear(); console.clear();
refreshStatic(); refreshStatic();
return;
}
default:
addMessage({
type: MessageType.ERROR,
content: `Unknown /chat command: ${subCommand}. Available: save, resume`,
timestamp: new Date(),
});
return;
}
},
completion: async () => {
const geminiDir = config?.getProjectTempDir();
if (!geminiDir) {
return [];
}
try {
const files = await fs.readdir(geminiDir);
return files
.filter(
(file) =>
file.startsWith('checkpoint-') && file.endsWith('.json'),
)
.map(
(file) =>
'resume ' +
file.replace('checkpoint-', '').replace('.json', ''),
);
} catch (_err) {
return [];
}
}, },
}, },
{ {