mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-03 16:34:31 -07:00
feat(cli): add --delete flag to /exit command for session deletion (#19332)
Co-authored-by: David Pierce <davidapierce@google.com>
This commit is contained in:
@@ -33,11 +33,12 @@ describe('quitCommand', () => {
|
||||
});
|
||||
|
||||
if (!quitCommand.action) throw new Error('Action is not defined');
|
||||
const result = quitCommand.action(mockContext, 'quit');
|
||||
const result = quitCommand.action(mockContext, '');
|
||||
|
||||
expect(formatDuration).toHaveBeenCalledWith(3600000); // 1 hour in ms
|
||||
expect(result).toEqual({
|
||||
type: 'quit',
|
||||
deleteSession: false,
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
@@ -52,4 +53,54 @@ describe('quitCommand', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('sets deleteSession to true when --delete flag is provided', () => {
|
||||
const mockContext = createMockCommandContext({
|
||||
session: {
|
||||
stats: {
|
||||
sessionStartTime: new Date('2025-01-01T00:00:00Z'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!quitCommand.action) throw new Error('Action is not defined');
|
||||
const result = quitCommand.action(mockContext, '--delete');
|
||||
|
||||
expect(result).toEqual({
|
||||
type: 'quit',
|
||||
deleteSession: true,
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
text: '/quit',
|
||||
id: expect.any(Number),
|
||||
},
|
||||
{
|
||||
type: 'quit',
|
||||
duration: '1h 0m 0s',
|
||||
id: expect.any(Number),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('does not set deleteSession for unrecognized args', () => {
|
||||
const mockContext = createMockCommandContext({
|
||||
session: {
|
||||
stats: {
|
||||
sessionStartTime: new Date('2025-01-01T00:00:00Z'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!quitCommand.action) throw new Error('Action is not defined');
|
||||
const result = quitCommand.action(mockContext, 'some-random-arg');
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
type: 'quit',
|
||||
deleteSession: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,13 +13,16 @@ export const quitCommand: SlashCommand = {
|
||||
description: 'Exit the cli',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
autoExecute: true,
|
||||
action: (context) => {
|
||||
action: (context, args) => {
|
||||
const now = Date.now();
|
||||
const { sessionStartTime } = context.session.stats;
|
||||
const wallDuration = now - sessionStartTime.getTime();
|
||||
|
||||
const deleteSession = args.trim() === '--delete';
|
||||
|
||||
return {
|
||||
type: 'quit',
|
||||
deleteSession,
|
||||
messages: [
|
||||
{
|
||||
type: 'user',
|
||||
|
||||
@@ -108,6 +108,8 @@ export interface CommandContext {
|
||||
export interface QuitActionReturn {
|
||||
type: 'quit';
|
||||
messages: HistoryItem[];
|
||||
/** When true, the current session's history and temporary files will be deleted on exit. */
|
||||
deleteSession?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user