feat(sessions): Add automatic session cleanup and retention policy (#7662)

This commit is contained in:
bl-ue
2025-10-06 13:34:00 -06:00
committed by GitHub
parent abe4045c63
commit 974ab66b7a
14 changed files with 2473 additions and 46 deletions
+4
View File
@@ -28,6 +28,10 @@ vi.mock('./trustedFolders.js', () => ({
.mockReturnValue({ isTrusted: true, source: 'file' }), // Default to trusted
}));
vi.mock('./sandboxConfig.js', () => ({
loadSandboxConfig: vi.fn().mockResolvedValue(undefined),
}));
vi.mock('fs', async (importOriginal) => {
const actualFs = await importOriginal<typeof import('fs')>();
const pathMod = await import('node:path');
+14
View File
@@ -170,6 +170,20 @@ export interface AccessibilitySettings {
screenReader?: boolean;
}
export interface SessionRetentionSettings {
/** Enable automatic session cleanup */
enabled?: boolean;
/** Maximum age of sessions to keep (e.g., "30d", "7d", "24h", "1w") */
maxAge?: string;
/** Alternative: Maximum number of sessions to keep (most recent) */
maxCount?: number;
/** Minimum retention period (safety limit, defaults to "1d") */
minRetention?: string;
}
export interface SettingsError {
message: string;
path: string;
+50
View File
@@ -16,6 +16,8 @@ import {
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
} from '@google/gemini-cli-core';
import type { CustomTheme } from '../ui/themes/theme.js';
import type { SessionRetentionSettings } from './settings.js';
import { DEFAULT_MIN_RETENTION } from '../utils/sessionCleanup.js';
export type SettingsType =
| 'boolean'
@@ -185,6 +187,54 @@ const SETTINGS_SCHEMA = {
description: 'Enable debug logging of keystrokes to the console.',
showInDialog: true,
},
sessionRetention: {
type: 'object',
label: 'Session Retention',
category: 'General',
requiresRestart: false,
default: undefined as SessionRetentionSettings | undefined,
properties: {
enabled: {
type: 'boolean',
label: 'Enable Session Cleanup',
category: 'General',
requiresRestart: false,
default: false,
description: 'Enable automatic session cleanup',
showInDialog: true,
},
maxAge: {
type: 'string',
label: 'Max Session Age',
category: 'General',
requiresRestart: false,
default: undefined as string | undefined,
description:
'Maximum age of sessions to keep (e.g., "30d", "7d", "24h", "1w")',
showInDialog: false,
},
maxCount: {
type: 'number',
label: 'Max Session Count',
category: 'General',
requiresRestart: false,
default: undefined as number | undefined,
description:
'Alternative: Maximum number of sessions to keep (most recent)',
showInDialog: false,
},
minRetention: {
type: 'string',
label: 'Min Retention Period',
category: 'General',
requiresRestart: false,
default: DEFAULT_MIN_RETENTION,
description: `Minimum retention period (safety limit, defaults to "${DEFAULT_MIN_RETENTION}")`,
showInDialog: false,
},
},
description: 'Settings for automatic session cleanup.',
},
},
},
output: {