@@ -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+
1639export 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' ,
0 commit comments