feat: Add a --session-summary flag (#7347)

This commit is contained in:
Lee James
2025-08-29 12:53:39 -04:00
committed by GitHub
parent eb13b2a7a1
commit 6a9fb6d2ea
3 changed files with 61 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ export interface CliArgs {
proxy: string | undefined;
includeDirectories: string[] | undefined;
screenReader: boolean | undefined;
sessionSummary: string | undefined;
}
export async function parseArguments(settings: Settings): Promise<CliArgs> {
@@ -227,6 +228,10 @@ export async function parseArguments(settings: Settings): Promise<CliArgs> {
description: 'Enable screen reader mode for accessibility.',
default: false,
})
.option('session-summary', {
type: 'string',
description: 'File to write session summary to.',
})
.deprecateOption(
'telemetry',
'Use settings.json instead. This flag will be removed in a future version.',

View File

@@ -24,7 +24,11 @@ import { getUserStartupWarnings } from './utils/userStartupWarnings.js';
import { ConsolePatcher } from './ui/utils/ConsolePatcher.js';
import { runNonInteractive } from './nonInteractiveCli.js';
import { loadExtensions } from './config/extension.js';
import { cleanupCheckpoints, registerCleanup } from './utils/cleanup.js';
import {
cleanupCheckpoints,
registerCleanup,
runExitCleanup,
} from './utils/cleanup.js';
import { getCliVersion } from './utils/version.js';
import type { Config } from '@google/gemini-cli-core';
import {
@@ -36,6 +40,7 @@ import {
IdeConnectionEvent,
IdeConnectionType,
FatalConfigError,
uiTelemetryService,
} from '@google/gemini-cli-core';
import { validateAuthMethod } from './config/auth.js';
import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js';
@@ -45,6 +50,7 @@ import { checkForUpdates } from './ui/utils/updateCheck.js';
import { handleAutoUpdate } from './utils/handleAutoUpdate.js';
import { appEvents, AppEvent } from './utils/events.js';
import { SettingsContext } from './ui/contexts/SettingsContext.js';
import { writeFileSync } from 'node:fs';
export function validateDnsResolutionOrder(
order: string | undefined,
@@ -225,6 +231,16 @@ export async function main() {
argv,
);
if (argv.sessionSummary) {
registerCleanup(() => {
const metrics = uiTelemetryService.getMetrics();
writeFileSync(
argv.sessionSummary!,
JSON.stringify({ sessionMetrics: metrics }, null, 2),
);
});
}
const consolePatcher = new ConsolePatcher({
stderr: true,
debugMode: config.getDebugMode(),
@@ -434,6 +450,8 @@ export async function main() {
}
await runNonInteractive(nonInteractiveConfig, input, prompt_id);
// Call cleanup before process.exit, which causes cleanup to not run
await runExitCleanup();
process.exit(0);
}