diff --git a/packages/cli/src/ui/commands/statsCommand.ts b/packages/cli/src/ui/commands/statsCommand.ts index 96b4073fcb..224b05f40f 100644 --- a/packages/cli/src/ui/commands/statsCommand.ts +++ b/packages/cli/src/ui/commands/statsCommand.ts @@ -13,34 +13,46 @@ import { CommandKind, } from './types.js'; +function defaultSessionView(context: CommandContext) { + const now = new Date(); + const { sessionStartTime } = context.session.stats; + if (!sessionStartTime) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: 'Session start time is unavailable, cannot calculate stats.', + }, + Date.now(), + ); + return; + } + const wallDuration = now.getTime() - sessionStartTime.getTime(); + + const statsItem: HistoryItemStats = { + type: MessageType.STATS, + duration: formatDuration(wallDuration), + }; + + context.ui.addItem(statsItem, Date.now()); +} + export const statsCommand: SlashCommand = { name: 'stats', altNames: ['usage'], - description: 'Check session stats. Usage: /stats [model|tools]', + description: 'Check session stats. Usage: /stats [session|model|tools]', kind: CommandKind.BUILT_IN, action: (context: CommandContext) => { - const now = new Date(); - const { sessionStartTime } = context.session.stats; - if (!sessionStartTime) { - context.ui.addItem( - { - type: MessageType.ERROR, - text: 'Session start time is unavailable, cannot calculate stats.', - }, - Date.now(), - ); - return; - } - const wallDuration = now.getTime() - sessionStartTime.getTime(); - - const statsItem: HistoryItemStats = { - type: MessageType.STATS, - duration: formatDuration(wallDuration), - }; - - context.ui.addItem(statsItem, Date.now()); + defaultSessionView(context); }, subCommands: [ + { + name: 'session', + description: 'Show session-specific usage statistics', + kind: CommandKind.BUILT_IN, + action: (context: CommandContext) => { + defaultSessionView(context); + }, + }, { name: 'model', description: 'Show model-specific usage statistics', diff --git a/packages/cli/src/ui/hooks/useSlashCompletion.test.ts b/packages/cli/src/ui/hooks/useSlashCompletion.test.ts index ffa957b41a..68548a0758 100644 --- a/packages/cli/src/ui/hooks/useSlashCompletion.test.ts +++ b/packages/cli/src/ui/hooks/useSlashCompletion.test.ts @@ -183,7 +183,8 @@ describe('useSlashCompletion', () => { createTestCommand({ name: 'stats', altNames: ['usage'], - description: 'check session stats. Usage: /stats [model|tools]', + description: + 'check session stats. Usage: /stats [session|model|tools]', }), createTestCommand({ name: 'clear', description: 'Clear the screen' }), createTestCommand({ @@ -282,7 +283,8 @@ describe('useSlashCompletion', () => { createTestCommand({ name: 'stats', altNames: ['usage'], - description: 'check session stats. Usage: /stats [model|tools]', + description: + 'check session stats. Usage: /stats [session|model|tools]', }), ]; let result: { @@ -307,7 +309,8 @@ describe('useSlashCompletion', () => { { label: 'stats', value: 'stats', - description: 'check session stats. Usage: /stats [model|tools]', + description: + 'check session stats. Usage: /stats [session|model|tools]', commandKind: CommandKind.BUILT_IN, }, ]); @@ -360,7 +363,8 @@ describe('useSlashCompletion', () => { createTestCommand({ name: 'stats', altNames: ['usage'], - description: 'check session stats. Usage: /stats [model|tools]', + description: + 'check session stats. Usage: /stats [session|model|tools]', action: vi.fn(), }), ];