Skip to content

Commit 04b5b85

Browse files
Adib234mboshernitsan
authored andcommitted
Add session subtask in /stats command (#13750)
1 parent 45ff3a0 commit 04b5b85

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

packages/cli/src/ui/commands/statsCommand.ts

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,46 @@ import {
1313
CommandKind,
1414
} from './types.js';
1515

16+
function defaultSessionView(context: CommandContext) {
17+
const now = new Date();
18+
const { sessionStartTime } = context.session.stats;
19+
if (!sessionStartTime) {
20+
context.ui.addItem(
21+
{
22+
type: MessageType.ERROR,
23+
text: 'Session start time is unavailable, cannot calculate stats.',
24+
},
25+
Date.now(),
26+
);
27+
return;
28+
}
29+
const wallDuration = now.getTime() - sessionStartTime.getTime();
30+
31+
const statsItem: HistoryItemStats = {
32+
type: MessageType.STATS,
33+
duration: formatDuration(wallDuration),
34+
};
35+
36+
context.ui.addItem(statsItem, Date.now());
37+
}
38+
1639
export const statsCommand: SlashCommand = {
1740
name: 'stats',
1841
altNames: ['usage'],
19-
description: 'Check session stats. Usage: /stats [model|tools]',
42+
description: 'Check session stats. Usage: /stats [session|model|tools]',
2043
kind: CommandKind.BUILT_IN,
2144
action: (context: CommandContext) => {
22-
const now = new Date();
23-
const { sessionStartTime } = context.session.stats;
24-
if (!sessionStartTime) {
25-
context.ui.addItem(
26-
{
27-
type: MessageType.ERROR,
28-
text: 'Session start time is unavailable, cannot calculate stats.',
29-
},
30-
Date.now(),
31-
);
32-
return;
33-
}
34-
const wallDuration = now.getTime() - sessionStartTime.getTime();
35-
36-
const statsItem: HistoryItemStats = {
37-
type: MessageType.STATS,
38-
duration: formatDuration(wallDuration),
39-
};
40-
41-
context.ui.addItem(statsItem, Date.now());
45+
defaultSessionView(context);
4246
},
4347
subCommands: [
48+
{
49+
name: 'session',
50+
description: 'Show session-specific usage statistics',
51+
kind: CommandKind.BUILT_IN,
52+
action: (context: CommandContext) => {
53+
defaultSessionView(context);
54+
},
55+
},
4456
{
4557
name: 'model',
4658
description: 'Show model-specific usage statistics',

packages/cli/src/ui/hooks/useSlashCompletion.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ describe('useSlashCompletion', () => {
183183
createTestCommand({
184184
name: 'stats',
185185
altNames: ['usage'],
186-
description: 'check session stats. Usage: /stats [model|tools]',
186+
description:
187+
'check session stats. Usage: /stats [session|model|tools]',
187188
}),
188189
createTestCommand({ name: 'clear', description: 'Clear the screen' }),
189190
createTestCommand({
@@ -282,7 +283,8 @@ describe('useSlashCompletion', () => {
282283
createTestCommand({
283284
name: 'stats',
284285
altNames: ['usage'],
285-
description: 'check session stats. Usage: /stats [model|tools]',
286+
description:
287+
'check session stats. Usage: /stats [session|model|tools]',
286288
}),
287289
];
288290
let result: {
@@ -307,7 +309,8 @@ describe('useSlashCompletion', () => {
307309
{
308310
label: 'stats',
309311
value: 'stats',
310-
description: 'check session stats. Usage: /stats [model|tools]',
312+
description:
313+
'check session stats. Usage: /stats [session|model|tools]',
311314
commandKind: CommandKind.BUILT_IN,
312315
},
313316
]);
@@ -360,7 +363,8 @@ describe('useSlashCompletion', () => {
360363
createTestCommand({
361364
name: 'stats',
362365
altNames: ['usage'],
363-
description: 'check session stats. Usage: /stats [model|tools]',
366+
description:
367+
'check session stats. Usage: /stats [session|model|tools]',
364368
action: vi.fn(),
365369
}),
366370
];

0 commit comments

Comments
 (0)