@@ -40,6 +40,10 @@ define(function (require, exports, module) {
4040 let _hasReceivedContent = false ; // tracks if we've received any text/tool in current response
4141 const _previousContentMap = { } ; // filePath → previous content before edit, for undo support
4242
43+ // --- AI event trace logging (compact, non-flooding) ---
44+ let _traceTextChunks = 0 ;
45+ let _traceToolStreamCounts = { } ; // toolId → count
46+
4347 // DOM references
4448 let $panel , $messages , $status , $statusText , $textarea , $sendBtn , $stopBtn ;
4549
@@ -230,12 +234,17 @@ define(function (require, exports, module) {
230234 // Get project path
231235 const projectPath = _getProjectRealPath ( ) ;
232236
237+ _traceTextChunks = 0 ;
238+ _traceToolStreamCounts = { } ;
239+ console . log ( "[AI UI] Sending prompt:" , text . slice ( 0 , 60 ) ) ;
240+
233241 _nodeConnector . execPeer ( "sendPrompt" , {
234242 prompt : text ,
235243 projectPath : projectPath ,
236244 sessionAction : "continue"
237245 } ) . then ( function ( result ) {
238246 _currentRequestId = result . requestId ;
247+ console . log ( "[AI UI] RequestId:" , result . requestId ) ;
239248 } ) . catch ( function ( err ) {
240249 _setStreaming ( false ) ;
241250 _appendErrorMessage ( "Failed to send message: " + ( err . message || String ( err ) ) ) ;
@@ -288,6 +297,11 @@ define(function (require, exports, module) {
288297 // --- Event handlers for node-side events ---
289298
290299 function _onTextStream ( _event , data ) {
300+ _traceTextChunks ++ ;
301+ if ( _traceTextChunks === 1 ) {
302+ console . log ( "[AI UI]" , "First text chunk" ) ;
303+ }
304+
291305 // Remove thinking indicator on first content
292306 if ( ! _hasReceivedContent ) {
293307 _hasReceivedContent = true ;
@@ -315,6 +329,7 @@ define(function (require, exports, module) {
315329 } ;
316330
317331 function _onProgress ( _event , data ) {
332+ console . log ( "[AI UI]" , "Progress:" , data . phase , data . toolName ? data . toolName + " #" + data . toolId : "" ) ;
318333 if ( $statusText ) {
319334 const toolName = data . toolName || "" ;
320335 const config = TOOL_CONFIG [ toolName ] ;
@@ -326,11 +341,17 @@ define(function (require, exports, module) {
326341 }
327342
328343 function _onToolInfo ( _event , data ) {
344+ const uid = ( _currentRequestId || "" ) + "-" + data . toolId ;
345+ const streamCount = _traceToolStreamCounts [ uid ] || 0 ;
346+ console . log ( "[AI UI]" , "ToolInfo:" , data . toolName , "#" + data . toolId ,
347+ "file=" + ( data . toolInput && data . toolInput . file_path || "?" ) . split ( "/" ) . pop ( ) ,
348+ "streamEvents=" + streamCount ) ;
329349 _updateToolIndicator ( data . toolId , data . toolName , data . toolInput ) ;
330350 }
331351
332352 function _onToolStream ( _event , data ) {
333353 const uniqueToolId = ( _currentRequestId || "" ) + "-" + data . toolId ;
354+ _traceToolStreamCounts [ uniqueToolId ] = ( _traceToolStreamCounts [ uniqueToolId ] || 0 ) + 1 ;
334355 const $tool = $messages . find ( '.ai-msg-tool[data-tool-id="' + uniqueToolId + '"]' ) ;
335356 if ( ! $tool . length ) {
336357 return ;
@@ -348,6 +369,10 @@ define(function (require, exports, module) {
348369 }
349370
350371 const preview = _extractToolPreview ( data . toolName , data . partialJson ) ;
372+ if ( _traceToolStreamCounts [ uniqueToolId ] === 1 ) {
373+ console . log ( "[AI UI]" , "ToolStream first:" , data . toolName , "#" + data . toolId ,
374+ "json=" + ( data . partialJson || "" ) . length + "ch" ) ;
375+ }
351376 if ( preview ) {
352377 $tool . find ( ".ai-tool-preview" ) . text ( preview ) ;
353378 _scrollToBottom ( ) ;
@@ -389,7 +414,8 @@ define(function (require, exports, module) {
389414 if ( ! partialJson ) {
390415 return "" ;
391416 }
392- // Map tool names to the key whose value we want to preview
417+ // Map tool names to the key whose value we want to preview.
418+ // Tools not listed here get no streaming preview.
393419 const interestingKey = {
394420 Write : "content" ,
395421 Edit : "new_string" ,
@@ -398,19 +424,21 @@ define(function (require, exports, module) {
398424 Glob : "pattern"
399425 } [ toolName ] ;
400426
427+ if ( ! interestingKey ) {
428+ return "" ;
429+ }
430+
401431 let raw = "" ;
402- if ( interestingKey ) {
403- // Find the interesting key and grab everything after it
404- const keyPattern = '"' + interestingKey + '":' ;
405- const idx = partialJson . indexOf ( keyPattern ) ;
406- if ( idx !== - 1 ) {
407- raw = partialJson . slice ( idx + keyPattern . length ) . slice ( - 120 ) ;
408- }
409- // If the interesting key hasn't appeared yet, show nothing
410- // rather than raw JSON noise like {"file_path":...
411- } else {
412- // No interesting key defined for this tool — use the tail
413- raw = partialJson . slice ( - 120 ) ;
432+ // Find the interesting key and grab everything after it
433+ const keyPattern = '"' + interestingKey + '":' ;
434+ const idx = partialJson . indexOf ( keyPattern ) ;
435+ if ( idx !== - 1 ) {
436+ raw = partialJson . slice ( idx + keyPattern . length ) . slice ( - 120 ) ;
437+ }
438+ // If the interesting key hasn't appeared yet, show a byte counter
439+ // so the user sees streaming activity during the file_path phase
440+ if ( ! raw && partialJson . length > 3 ) {
441+ return "receiving " + partialJson . length + " bytes..." ;
414442 }
415443 if ( ! raw ) {
416444 return "" ;
@@ -430,6 +458,7 @@ define(function (require, exports, module) {
430458 }
431459
432460 function _onEditResult ( _event , data ) {
461+ console . log ( "[AI UI]" , "EditResult:" , ( data . edits || [ ] ) . length , "edits" ) ;
433462 if ( data . edits && data . edits . length > 0 ) {
434463 data . edits . forEach ( function ( edit ) {
435464 _appendEditCard ( edit ) ;
@@ -438,11 +467,17 @@ define(function (require, exports, module) {
438467 }
439468
440469 function _onError ( _event , data ) {
470+ console . log ( "[AI UI]" , "Error:" , ( data . error || "" ) . slice ( 0 , 200 ) ) ;
441471 _appendErrorMessage ( data . error ) ;
442472 // Don't stop streaming — the node side may continue (partial results)
443473 }
444474
445475 function _onComplete ( _event , data ) {
476+ console . log ( "[AI UI]" , "Complete. textChunks=" + _traceTextChunks ,
477+ "toolStreams=" + JSON . stringify ( _traceToolStreamCounts ) ) ;
478+ // Reset trace counters for next query
479+ _traceTextChunks = 0 ;
480+ _traceToolStreamCounts = { } ;
446481 _setStreaming ( false ) ;
447482 }
448483
@@ -654,10 +689,17 @@ define(function (require, exports, module) {
654689
655690 /**
656691 * Mark all active (non-done) tool indicators as finished.
692+ * Tools that already received _updateToolIndicator (spinner replaced with
693+ * .ai-tool-icon) are skipped — their delayed timeout will add .ai-tool-done.
694+ * This only force-finishes tools that never got a toolInfo (e.g. interrupted).
657695 */
658696 function _finishActiveTools ( ) {
659697 $messages . find ( ".ai-msg-tool:not(.ai-tool-done)" ) . each ( function ( ) {
660698 const $prev = $ ( this ) ;
699+ // _updateToolIndicator already ran — let the delayed timeout handle it
700+ if ( $prev . find ( ".ai-tool-icon" ) . length ) {
701+ return ;
702+ }
661703 $prev . addClass ( "ai-tool-done" ) ;
662704 const iconClass = $prev . attr ( "data-tool-icon" ) || "fa-solid fa-check" ;
663705 const color = $prev . css ( "--tool-color" ) || "#adb9bd" ;
0 commit comments