feat(cli): add /insights slash command to analyze past sessions

This commit is contained in:
Aishanee Shah
2026-02-10 01:26:04 +00:00
parent 3f051bc58e
commit 3e7dfe7fba
4 changed files with 258 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ import { directoryCommand } from '../ui/commands/directoryCommand.js';
import { editorCommand } from '../ui/commands/editorCommand.js';
import { extensionsCommand } from '../ui/commands/extensionsCommand.js';
import { helpCommand } from '../ui/commands/helpCommand.js';
import { insightsCommand } from '../ui/commands/insightsCommand.js';
import { shortcutsCommand } from '../ui/commands/shortcutsCommand.js';
import { rewindCommand } from '../ui/commands/rewindCommand.js';
import { hooksCommand } from '../ui/commands/hooksCommand.js';
@@ -117,6 +118,7 @@ export class BuiltinCommandLoader implements ICommandLoader {
]
: [extensionsCommand(this.config?.getEnableExtensionReloading())]),
helpCommand,
insightsCommand,
shortcutsCommand,
...(this.config?.getEnableHooksUI() ? [hooksCommand] : []),
rewindCommand,

View File

@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { InsightsService } from '@google/gemini-cli-core';
import { MessageType } from '../types.js';
import {
type CommandContext,
type SlashCommand,
CommandKind,
} from './types.js';
/**
* Slash command to generate usage insights based on past sessions.
*/
export const insightsCommand: SlashCommand = {
name: 'insights',
description: 'Analyze past sessions and get usage improvements and summary.',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context: CommandContext) => {
const config = context.services.config;
if (!config) {
context.ui.addItem({
type: MessageType.ERROR,
text: 'Config is not available.',
});
return;
}
context.ui.addItem({
type: MessageType.INFO,
text: 'Analyzing your past sessions to generate insights...',
});
try {
const insightsService = new InsightsService(config);
const baseLlmClient = config.getBaseLlmClient();
const reportMarkdown =
await insightsService.generateInsightsReport(baseLlmClient);
context.ui.addItem({
type: MessageType.GEMINI,
text: reportMarkdown,
});
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to generate insights: ${error instanceof Error ? error.message : String(error)}`,
});
}
},
};