Add session subtask in /stats command (#13750)

This commit is contained in:
Adib234
2025-11-24 11:01:41 -08:00
committed by GitHub
parent 95693e265e
commit c21b6899e1
2 changed files with 41 additions and 25 deletions
+33 -21
View File
@@ -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',