@@ -227,31 +227,31 @@ export class HookHandler {
227227 const inputObj = input as Record < string , unknown > | null ;
228228 const toolName = inputObj ?. tool_name || 'unknown' ;
229229
230- console . log ( `[HOOK ENTRY] ${ eventName } for ${ toolName } , socket=${ socket ?. id || 'null' } , connected=${ socket ?. connected } ` ) ;
230+ this . log . debug ( `[HOOK ENTRY] ${ eventName } for ${ toolName } , socket=${ socket ?. id || 'null' } , connected=${ socket ?. connected } ` , undefined , socket ?. id ) ;
231231
232232 // Capture SDK session ID from hook event data
233233 this . captureSessionId ( inputObj , eventName , socket ) ;
234234
235235 // Check if session is aborted
236236 if ( this . context . abortSignal . aborted ) {
237- console . log ( `[HOOK ABORT] ${ eventName } - session aborted` ) ;
237+ this . log . warn ( `[HOOK ABORT] ${ eventName } - session aborted` , this . context . sessionId ) ;
238238 return { } ;
239239 }
240240
241241 // Handle disconnected socket
242242 if ( ! socket || ! socket . connected ) {
243- console . warn ( `[HOOK SKIP] ${ eventName } - socket disconnected or null` ) ;
243+ this . log . warn ( `[HOOK SKIP] ${ eventName } - socket disconnected or null` , this . context . sessionId ) ;
244244 this . log . warn ( `Skipping hook ${ eventName } (socket disconnected)` , this . context . sessionId ) ;
245245 return { } ;
246246 }
247247
248248 // Use strategy based on hook type
249249 if ( AUTO_CONTINUE_HOOKS . has ( eventName ) ) {
250- console . log ( `[HOOK AUTO] ${ eventName } - using auto-continue strategy` ) ;
250+ this . log . debug ( `[HOOK AUTO] ${ eventName } - using auto-continue strategy` , undefined , socket . id ) ;
251251 return this . handleAutoContinueHook ( eventName , input , socket ) ;
252252 }
253253
254- console . log ( `[HOOK REQUEST] ${ eventName } - using request-response strategy` ) ;
254+ this . log . debug ( `[HOOK REQUEST] ${ eventName } - using request-response strategy` , undefined , socket . id ) ;
255255 return this . handleRequestResponseHook ( eventName , input , socket , timeoutMs ) ;
256256 } ;
257257 }
@@ -303,7 +303,7 @@ export class HookHandler {
303303 }
304304
305305 const sdkSessionId = input . session_id as string ;
306- console . log ( `[SDK SESSION] Captured SDK session_id from ${ eventName } hook: ${ sdkSessionId } ` ) ;
306+ this . log . info ( `[SDK SESSION] Captured SDK session_id from ${ eventName } hook: ${ sdkSessionId } ` , socket ?. id ) ;
307307
308308 this . log . outgoing ( socket . id , 'message[system/init]' , { sdk_session_id : sdkSessionId } ) ;
309309
@@ -359,17 +359,19 @@ export class HookHandler {
359359 return ;
360360 }
361361
362- console . log ( `[HookHandler] Detected ${ imagePaths . length } image(s):`, imagePaths ) ;
362+ this . log . info ( ` Detected ${ imagePaths . length } image artifact (s): ${ imagePaths . join ( ', ' ) } `, socket . id ) ;
363363
364364 // Emit each image path - the worker will handle upload to R2
365365 for ( const filePath of imagePaths ) {
366- socket . emit ( "image_created" , {
366+ socket . emit ( "image_artifact" , {
367+ type : 'image' ,
368+ url : '' , // Worker populates after R2 upload
367369 sandboxPath : filePath ,
368- sessionId : this . context . sessionId ,
370+ mimeType : filePath . endsWith ( '.png' ) ? 'image/png' : filePath . endsWith ( '.svg' ) ? 'image/svg+xml' : 'image/jpeg' ,
369371 } ) ;
370372 }
371373 } catch ( error ) {
372- console . error ( '[HookHandler] Error detecting image paths: ' , error ) ;
374+ this . log . error ( 'Error detecting image paths' , error , socket . id ) ;
373375 }
374376 }
375377
@@ -386,8 +388,8 @@ export class HookHandler {
386388 const toolName = inputObj ?. tool_name || 'unknown' ;
387389 const hookId = `${ eventName } -${ Date . now ( ) } ` ;
388390
389- console . log ( `[HOOK ${ hookId } ] START: ${ eventName } for tool=${ toolName } ` ) ;
390- console . log ( `[HOOK ${ hookId } ] Socket state: connected=${ socket . connected } , id=${ socket . id } ` ) ;
391+ this . log . debug ( `[HOOK ${ hookId } ] START: ${ eventName } for tool=${ toolName } ` , undefined , socket . id ) ;
392+ this . log . debug ( `[HOOK ${ hookId } ] Socket state: connected=${ socket . connected } , id=${ socket . id } ` , undefined , socket . id ) ;
391393
392394 this . log . debug (
393395 `Hook triggered: ${ eventName } ` ,
@@ -405,13 +407,13 @@ export class HookHandler {
405407 progressCount ++ ;
406408 const elapsed = Date . now ( ) - startTime ;
407409 const socketNow = this . context . getSocket ( ) ;
408- console . warn ( `[HOOK ${ hookId } ] WAITING ${ progressCount * 5 } s (${ elapsed } ms elapsed), socket=${ socketNow ?. id || 'null' } , connected=${ socketNow ?. connected } ` ) ;
410+ this . log . warn ( `[HOOK ${ hookId } ] WAITING ${ progressCount * 5 } s (${ elapsed } ms elapsed), socket=${ socketNow ?. id || 'null' } , connected=${ socketNow ?. connected } ` , this . context . sessionId ) ;
409411 } , 5000 ) ;
410412
411413 // Timeout handler
412414 const timeout = setTimeout ( ( ) => {
413415 const elapsed = Date . now ( ) - startTime ;
414- console . error ( `[HOOK ${ hookId } ] TIMEOUT after ${ elapsed } ms (limit=${ timeoutMs } ms)` ) ;
416+ this . log . error ( `[HOOK ${ hookId } ] TIMEOUT after ${ elapsed } ms (limit=${ timeoutMs } ms)` , undefined , this . context . sessionId ) ;
415417 this . log . warn ( `Hook ${ eventName } timed out after ${ timeoutMs } ms` , this . context . sessionId ) ;
416418 cleanup ( ) ;
417419 resolve ( { } ) ;
@@ -420,7 +422,7 @@ export class HookHandler {
420422 // Disconnect handler
421423 const onDisconnect = ( ) => {
422424 const elapsed = Date . now ( ) - startTime ;
423- console . error ( `[HOOK ${ hookId } ] DISCONNECT after ${ elapsed } ms` ) ;
425+ this . log . error ( `[HOOK ${ hookId } ] DISCONNECT after ${ elapsed } ms` , undefined , this . context . sessionId ) ;
424426 this . log . warn ( `Client disconnected while waiting for hook ${ eventName } ` , this . context . sessionId ) ;
425427 cleanup ( ) ;
426428 resolve ( { } ) ;
@@ -435,7 +437,7 @@ export class HookHandler {
435437 } ;
436438
437439 // Emit hook request with callback
438- console . log ( `[HOOK ${ hookId } ] EMITTING hook_request to client...` ) ;
440+ this . log . debug ( `[HOOK ${ hookId } ] EMITTING hook_request to client...` , undefined , socket . id ) ;
439441 this . log . outgoing (
440442 socket . id ,
441443 'hook_request' ,
@@ -447,22 +449,22 @@ export class HookHandler {
447449 { event : eventName , data : input } ,
448450 ( clientResponse : HookResponse ) => {
449451 const elapsed = Date . now ( ) - startTime ;
450- console . log ( `[HOOK ${ hookId } ] CALLBACK received after ${ elapsed } ms: ` , JSON . stringify ( clientResponse ) ) ;
452+ this . log . debug ( `[HOOK ${ hookId } ] CALLBACK received after ${ elapsed } ms` , clientResponse , socket . id ) ;
451453 cleanup ( ) ;
452454 this . log . incoming ( socket . id , `hook_response[${ eventName } ]` , clientResponse ) ;
453455 resolve ( clientResponse || { } ) ;
454456 }
455457 ) ;
456458
457- console . log ( `[HOOK ${ hookId } ] hook_request emitted, waiting for callback...` ) ;
459+ this . log . debug ( `[HOOK ${ hookId } ] hook_request emitted, waiting for callback...` , undefined , socket . id ) ;
458460 } ) ;
459461
460462 const totalTime = Date . now ( ) - startTime ;
461- console . log ( `[HOOK ${ hookId } ] COMPLETE in ${ totalTime } ms, response:` , JSON . stringify ( response ) ) ;
463+ this . log . debug ( `[HOOK ${ hookId } ] COMPLETE in ${ totalTime } ms` , response , socket . id ) ;
462464 return response ;
463465 } catch ( error ) {
464466 const elapsed = Date . now ( ) - startTime ;
465- console . error ( `[HOOK ${ hookId } ] ERROR after ${ elapsed } ms: ` , error ) ;
467+ this . log . error ( `[HOOK ${ hookId } ] ERROR after ${ elapsed } ms` , error , this . context . sessionId ) ;
466468 this . log . error ( `Error in hook ${ eventName } ` , error , this . context . sessionId ) ;
467469 return { } ;
468470 }
0 commit comments