@@ -109,13 +109,57 @@ export function createCommandHandler(deps: CommandDeps): CommandHandler {
109109 return true ;
110110 }
111111
112+ async function cmdKill (
113+ channel : string ,
114+ chatId : string ,
115+ args : string ,
116+ reply : ReplyFn ,
117+ ) : Promise < true > {
118+ const nameOrId = args . trim ( ) ;
119+ if ( ! nameOrId ) {
120+ await reply ( 'Usage: /kill <session-name>' ) ;
121+ return true ;
122+ }
123+
124+ try {
125+ // Resolve the session first to get its ID for interruption
126+ const sessions = await sessionManager . listSessions ( channel , chatId ) ;
127+ const target =
128+ sessions . find ( ( s ) => s . name === nameOrId ) ??
129+ sessions . find ( ( s ) => s . id . startsWith ( nameOrId ) ) ;
130+
131+ if ( target ) {
132+ await deps . agentRunner . interrupt ( target . id ) ;
133+ }
134+
135+ const { deletedId, wasActive } = await sessionManager . deleteSession (
136+ channel ,
137+ chatId ,
138+ nameOrId ,
139+ ) ;
140+
141+ let msg = `Killed session \`${ nameOrId } \` (${ deletedId . slice ( 0 , 8 ) } )` ;
142+ if ( wasActive ) {
143+ const active = await sessionManager . getActiveSession ( channel , chatId ) ;
144+ msg += active
145+ ? `\nSwitched to \`${ sessionLabel ( active ) } \``
146+ : '\nNo sessions left — send a message to start one.' ;
147+ }
148+ await reply ( msg ) ;
149+ } catch ( err ) {
150+ await reply ( getErrorMessage ( err ) ) ;
151+ }
152+ return true ;
153+ }
154+
112155 async function cmdHelp ( reply : ReplyFn ) : Promise < true > {
113156 const help = [
114157 'Available commands:' ,
115158 '' ,
116159 '/new [name] — Start a new session' ,
117160 '/use <name> — Switch to a session' ,
118161 '/sessions — List all sessions' ,
162+ '/kill <name> — Delete a session and its history' ,
119163 '/ping — Check if Homie is alive' ,
120164 '/status — Show system status' ,
121165 '/help — Show this help' ,
@@ -174,6 +218,8 @@ export function createCommandHandler(deps: CommandDeps): CommandHandler {
174218 return cmdUse ( channel , chatId , args , reply ) ;
175219 case 'sessions' :
176220 return cmdSessions ( channel , chatId , reply ) ;
221+ case 'kill' :
222+ return cmdKill ( channel , chatId , args , reply ) ;
177223 case 'ping' :
178224 return cmdPing ( reply ) ;
179225 default :
0 commit comments