mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-14 16:10:59 -07:00
feat(admin): enable 30 day default retention for chat history & remove warning (#20853)
This commit is contained in:
@@ -37,9 +37,6 @@ import { AdminSettingsChangedDialog } from './AdminSettingsChangedDialog.js';
|
||||
import { IdeTrustChangeDialog } from './IdeTrustChangeDialog.js';
|
||||
import { NewAgentsNotification } from './NewAgentsNotification.js';
|
||||
import { AgentConfigDialog } from './AgentConfigDialog.js';
|
||||
import { SessionRetentionWarningDialog } from './SessionRetentionWarningDialog.js';
|
||||
import { useCallback } from 'react';
|
||||
import { SettingScope } from '../../config/settings.js';
|
||||
import { PolicyUpdateDialog } from './PolicyUpdateDialog.js';
|
||||
|
||||
interface DialogManagerProps {
|
||||
@@ -62,56 +59,8 @@ export const DialogManager = ({
|
||||
terminalHeight,
|
||||
staticExtraHeight,
|
||||
terminalWidth: uiTerminalWidth,
|
||||
shouldShowRetentionWarning,
|
||||
sessionsToDeleteCount,
|
||||
} = uiState;
|
||||
|
||||
const handleKeep120Days = useCallback(() => {
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.warningAcknowledged',
|
||||
true,
|
||||
);
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.enabled',
|
||||
true,
|
||||
);
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.maxAge',
|
||||
'120d',
|
||||
);
|
||||
}, [settings]);
|
||||
|
||||
const handleKeep30Days = useCallback(() => {
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.warningAcknowledged',
|
||||
true,
|
||||
);
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.enabled',
|
||||
true,
|
||||
);
|
||||
settings.setValue(
|
||||
SettingScope.User,
|
||||
'general.sessionRetention.maxAge',
|
||||
'30d',
|
||||
);
|
||||
}, [settings]);
|
||||
|
||||
if (shouldShowRetentionWarning && sessionsToDeleteCount !== undefined) {
|
||||
return (
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={handleKeep120Days}
|
||||
onKeep30Days={handleKeep30Days}
|
||||
sessionsToDeleteCount={sessionsToDeleteCount ?? 0}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (uiState.adminSettingsChanged) {
|
||||
return <AdminSettingsChangedDialog />;
|
||||
}
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @license
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { renderWithProviders } from '../../test-utils/render.js';
|
||||
import { SessionRetentionWarningDialog } from './SessionRetentionWarningDialog.js';
|
||||
import { waitFor } from '../../test-utils/async.js';
|
||||
import { act } from 'react';
|
||||
|
||||
// Helper to write to stdin
|
||||
const writeKey = (stdin: { write: (data: string) => void }, key: string) => {
|
||||
act(() => {
|
||||
stdin.write(key);
|
||||
});
|
||||
};
|
||||
|
||||
describe('SessionRetentionWarningDialog', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('renders correctly with warning message and session count', async () => {
|
||||
const { lastFrame, waitUntilReady } = renderWithProviders(
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={vi.fn()}
|
||||
onKeep30Days={vi.fn()}
|
||||
sessionsToDeleteCount={42}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('Keep chat history');
|
||||
expect(lastFrame()).toContain(
|
||||
'introducing a limit on how long chat sessions are stored',
|
||||
);
|
||||
expect(lastFrame()).toContain('Keep for 30 days (Recommended)');
|
||||
expect(lastFrame()).toContain('42 sessions will be deleted');
|
||||
expect(lastFrame()).toContain('Keep for 120 days');
|
||||
expect(lastFrame()).toContain('No sessions will be deleted at this time');
|
||||
});
|
||||
|
||||
it('handles pluralization correctly for 1 session', async () => {
|
||||
const { lastFrame, waitUntilReady } = renderWithProviders(
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={vi.fn()}
|
||||
onKeep30Days={vi.fn()}
|
||||
sessionsToDeleteCount={1}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
expect(lastFrame()).toContain('1 session will be deleted');
|
||||
});
|
||||
|
||||
it('defaults to "Keep for 120 days" when there are sessions to delete', async () => {
|
||||
const onKeep120Days = vi.fn();
|
||||
const onKeep30Days = vi.fn();
|
||||
|
||||
const { stdin, waitUntilReady } = renderWithProviders(
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={onKeep120Days}
|
||||
onKeep30Days={onKeep30Days}
|
||||
sessionsToDeleteCount={10}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
// Initial selection should be "Keep for 120 days" (index 1) because count > 0
|
||||
// Pressing Enter immediately should select it.
|
||||
writeKey(stdin, '\r');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onKeep120Days).toHaveBeenCalled();
|
||||
expect(onKeep30Days).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('calls onKeep30Days when "Keep for 30 days" is explicitly selected (from 120 days default)', async () => {
|
||||
const onKeep120Days = vi.fn();
|
||||
const onKeep30Days = vi.fn();
|
||||
|
||||
const { stdin, waitUntilReady } = renderWithProviders(
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={onKeep120Days}
|
||||
onKeep30Days={onKeep30Days}
|
||||
sessionsToDeleteCount={10}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
// Default is index 1 (120 days). Move UP to index 0 (30 days).
|
||||
writeKey(stdin, '\x1b[A'); // Up arrow
|
||||
writeKey(stdin, '\r');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onKeep30Days).toHaveBeenCalled();
|
||||
expect(onKeep120Days).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should match snapshot', async () => {
|
||||
const { lastFrame, waitUntilReady } = renderWithProviders(
|
||||
<SessionRetentionWarningDialog
|
||||
onKeep120Days={vi.fn()}
|
||||
onKeep30Days={vi.fn()}
|
||||
sessionsToDeleteCount={123}
|
||||
/>,
|
||||
);
|
||||
await waitUntilReady();
|
||||
|
||||
// Initial render
|
||||
expect(lastFrame()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { Box, Text } from 'ink';
|
||||
import { theme } from '../semantic-colors.js';
|
||||
import {
|
||||
RadioButtonSelect,
|
||||
type RadioSelectItem,
|
||||
} from './shared/RadioButtonSelect.js';
|
||||
|
||||
interface SessionRetentionWarningDialogProps {
|
||||
onKeep120Days: () => void;
|
||||
onKeep30Days: () => void;
|
||||
sessionsToDeleteCount: number;
|
||||
}
|
||||
|
||||
export const SessionRetentionWarningDialog = ({
|
||||
onKeep120Days,
|
||||
onKeep30Days,
|
||||
sessionsToDeleteCount,
|
||||
}: SessionRetentionWarningDialogProps) => {
|
||||
const options: Array<RadioSelectItem<() => void>> = [
|
||||
{
|
||||
label: 'Keep for 30 days (Recommended)',
|
||||
value: onKeep30Days,
|
||||
key: '30days',
|
||||
sublabel: `${sessionsToDeleteCount} session${
|
||||
sessionsToDeleteCount === 1 ? '' : 's'
|
||||
} will be deleted`,
|
||||
},
|
||||
{
|
||||
label: 'Keep for 120 days',
|
||||
value: onKeep120Days,
|
||||
key: '120days',
|
||||
sublabel: 'No sessions will be deleted at this time',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Box
|
||||
borderStyle="round"
|
||||
borderColor={theme.border.default}
|
||||
flexDirection="column"
|
||||
width="100%"
|
||||
padding={1}
|
||||
>
|
||||
<Box marginBottom={1} justifyContent="center" width="100%">
|
||||
<Text bold>Keep chat history</Text>
|
||||
</Box>
|
||||
|
||||
<Box flexDirection="column" gap={1} marginBottom={1}>
|
||||
<Text>
|
||||
To keep your workspace clean, we are introducing a limit on how long
|
||||
chat sessions are stored. Please choose a retention period for your
|
||||
existing chats:
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
<Box marginTop={1}>
|
||||
<RadioButtonSelect
|
||||
items={options}
|
||||
onSelect={(action) => action()}
|
||||
initialIndex={1}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box marginTop={1}>
|
||||
<Text color={theme.text.secondary}>
|
||||
Set a custom limit <Text color={theme.text.primary}>/settings</Text>{' '}
|
||||
and change "Keep chat history".
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`SessionRetentionWarningDialog > should match snapshot 1`] = `
|
||||
"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ │
|
||||
│ Keep chat history │
|
||||
│ │
|
||||
│ To keep your workspace clean, we are introducing a limit on how long chat sessions are stored. │
|
||||
│ Please choose a retention period for your existing chats: │
|
||||
│ │
|
||||
│ │
|
||||
│ 1. Keep for 30 days (Recommended) │
|
||||
│ 123 sessions will be deleted │
|
||||
│ ● 2. Keep for 120 days │
|
||||
│ No sessions will be deleted at this time │
|
||||
│ │
|
||||
│ Set a custom limit /settings and change "Keep chat history". │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
"
|
||||
`;
|
||||
Reference in New Issue
Block a user