summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.ts
diff options
context:
space:
mode:
authorAbhi <[email protected]>2025-06-08 18:01:02 -0400
committerGitHub <[email protected]>2025-06-08 18:01:02 -0400
commit7868ef82299ae1da5a09334f67d57eb3b472563a (patch)
tree68e6a007dc0a762ae868cb7313c700686c4a1857 /packages/cli/src/ui/hooks/slashCommandProcessor.ts
parent9104ac02f7ac68d84bf9a3a78514bd080c77eec5 (diff)
feat: Introduce session context and add session duration stat for `/stats` command (#854)
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
index 38fdddba..85ae825e 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
@@ -11,6 +11,7 @@ import process from 'node:process';
import { UseHistoryManagerReturn } from './useHistoryManager.js';
import { Config, MCPServerStatus, getMCPServerStatus } from '@gemini-cli/core';
import { Message, MessageType, HistoryItemWithoutId } from '../types.js';
+import { useSession } from '../contexts/SessionContext.js';
import { createShowMemoryAction } from './useShowMemoryCommand.js';
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
import { formatMemoryUsage } from '../utils/formatters.js';
@@ -49,6 +50,8 @@ export const useSlashCommandProcessor = (
toggleCorgiMode: () => void,
showToolDescriptions: boolean = false,
) => {
+ const session = useSession();
+
const addMessage = useCallback(
(message: Message) => {
// Convert Message to HistoryItemWithoutId
@@ -139,6 +142,33 @@ export const useSlashCommandProcessor = (
},
},
{
+ name: 'stats',
+ altName: 'usage',
+ description: 'check session stats',
+ action: (_mainCommand, _subCommand, _args) => {
+ const now = new Date();
+ const duration = now.getTime() - session.startTime.getTime();
+ const durationInSeconds = Math.floor(duration / 1000);
+ const hours = Math.floor(durationInSeconds / 3600);
+ const minutes = Math.floor((durationInSeconds % 3600) / 60);
+ const seconds = durationInSeconds % 60;
+
+ const durationString = [
+ hours > 0 ? `${hours}h` : '',
+ minutes > 0 ? `${minutes}m` : '',
+ `${seconds}s`,
+ ]
+ .filter(Boolean)
+ .join(' ');
+
+ addMessage({
+ type: MessageType.INFO,
+ content: `Session duration: ${durationString}`,
+ timestamp: new Date(),
+ });
+ },
+ },
+ {
name: 'mcp',
description: 'list configured MCP servers and tools',
action: async (_mainCommand, _subCommand, _args) => {
@@ -447,6 +477,7 @@ Add any other context about the problem here.
toggleCorgiMode,
config,
showToolDescriptions,
+ session.startTime,
],
);