@@ -41,10 +41,8 @@ async function listSessions(context: CommandContext): Promise<void> {
4141 const sessionClient = sessionService . sessionClient
4242
4343 try {
44- const result = await sessionClient . list ( { limit : 50 } )
45- const { cliSessions } = result
46-
47- if ( cliSessions . length === 0 ) {
44+ const result = await sessionClient ?. list ( { limit : 50 } )
45+ if ( ! result || result . cliSessions . length === 0 ) {
4846 addMessage ( {
4947 ...generateMessage ( ) ,
5048 type : "system" ,
@@ -53,6 +51,8 @@ async function listSessions(context: CommandContext): Promise<void> {
5351 return
5452 }
5553
54+ const { cliSessions } = result
55+
5656 // Format and display sessions
5757 let content = `**Available Sessions:**\n\n`
5858 cliSessions . forEach ( ( session , index ) => {
@@ -148,10 +148,9 @@ async function searchSessions(context: CommandContext, query: string): Promise<v
148148 }
149149
150150 try {
151- const result = await sessionClient . search ( { search_string : query , limit : 20 } )
152- const { results, total } = result
151+ const result = await sessionClient ?. search ( { search_string : query , limit : 20 } )
153152
154- if ( results . length === 0 ) {
153+ if ( ! result || result . results . length === 0 ) {
155154 addMessage ( {
156155 ...generateMessage ( ) ,
157156 type : "system" ,
@@ -160,6 +159,8 @@ async function searchSessions(context: CommandContext, query: string): Promise<v
160159 return
161160 }
162161
162+ const { results, total } = result
163+
163164 let content = `**Search Results** (${ results . length } of ${ total } ):\n\n`
164165 results . forEach ( ( session , index ) => {
165166 const isActive = session . session_id === sessionService . sessionId ? " * [Active]" : ""
@@ -198,7 +199,7 @@ async function shareSession(context: CommandContext): Promise<void> {
198199 addMessage ( {
199200 ...generateMessage ( ) ,
200201 type : "system" ,
201- content : `✅ Session shared successfully!\n\n\`https://kilo.ai/share/${ result . share_id } \`` ,
202+ content : `✅ Session shared successfully!\n\n\`https://app. kilo.ai/share/${ result . share_id } \`` ,
202203 } )
203204 } catch ( error ) {
204205 addMessage ( {
@@ -212,15 +213,15 @@ async function shareSession(context: CommandContext): Promise<void> {
212213/**
213214 * Fork a shared session by share ID
214215 */
215- async function forkSession ( context : CommandContext , shareId : string ) : Promise < void > {
216+ async function forkSession ( context : CommandContext , id : string ) : Promise < void > {
216217 const { addMessage, replaceMessages, refreshTerminal } = context
217218 const sessionService = SessionManager . init ( )
218219
219- if ( ! shareId ) {
220+ if ( ! id ) {
220221 addMessage ( {
221222 ...generateMessage ( ) ,
222223 type : "error" ,
223- content : "Usage: /session fork <shareId >" ,
224+ content : "Usage: /session fork <id >" ,
224225 } )
225226 return
226227 }
@@ -238,14 +239,14 @@ async function forkSession(context: CommandContext, shareId: string): Promise<vo
238239 {
239240 id : `system-${ now + 1 } ` ,
240241 type : "system" ,
241- content : `Forking session from share ID \`${ shareId } \`...` ,
242+ content : `Forking session from ID \`${ id } \`...` ,
242243 ts : 2 ,
243244 } ,
244245 ] )
245246
246247 await refreshTerminal ( )
247248
248- await sessionService . forkSession ( shareId , true )
249+ await sessionService . forkSession ( id , true )
249250
250251 // Success message handled by restoreSession via extension messages
251252 } catch ( error ) {
@@ -275,6 +276,10 @@ async function deleteSession(context: CommandContext, sessionId: string): Promis
275276 }
276277
277278 try {
279+ if ( ! sessionClient ) {
280+ throw new Error ( "SessionManager used before initialization" )
281+ }
282+
278283 await sessionClient . delete ( { session_id : sessionId } )
279284
280285 addMessage ( {
@@ -340,7 +345,11 @@ async function sessionIdAutocompleteProvider(context: ArgumentProviderContext):
340345 }
341346
342347 try {
343- const response = await sessionClient . search ( { search_string : prefix , limit : 20 } )
348+ const response = await sessionClient ?. search ( { search_string : prefix , limit : 20 } )
349+
350+ if ( ! response ) {
351+ return [ ]
352+ }
344353
345354 return response . results . map ( ( session , index ) => {
346355 const title = session . title || "Untitled"
@@ -373,7 +382,7 @@ export const sessionCommand: Command = {
373382 "/session search <query>" ,
374383 "/session select <sessionId>" ,
375384 "/session share" ,
376- "/session fork <shareId >" ,
385+ "/session fork <id >" ,
377386 "/session delete <sessionId>" ,
378387 "/session rename <new name>" ,
379388 ] ,
@@ -390,7 +399,7 @@ export const sessionCommand: Command = {
390399 { value : "search" , description : "Search sessions by title or ID" } ,
391400 { value : "select" , description : "Restore a session" } ,
392401 { value : "share" , description : "Share current session publicly" } ,
393- { value : "fork" , description : "Fork a shared session" } ,
402+ { value : "fork" , description : "Fork a session" } ,
394403 { value : "delete" , description : "Delete a session" } ,
395404 { value : "rename" , description : "Rename the current session" } ,
396405 ] ,
0 commit comments