@@ -305,6 +305,78 @@ async function showTextOutput( format, replState, prefix='', suffix='' ) {
305305 * when autoshow is not displayed, this just returns baseOutput.
306306 *
307307 */
308+ /**
309+ * Formats graph output with nice styling and colors
310+ */
311+ function formatGraphOutput ( graphText ) {
312+ if ( ! graphText ) return '' ;
313+
314+ const lines = graphText . split ( '\n' ) ;
315+ const styledLines = [ ] ;
316+
317+ for ( let line of lines ) {
318+ if ( line . includes ( '--' ) || line . includes ( '->' ) ) {
319+ // This is a node connection line
320+ const parts = line . split ( / ( \s + - - \s + | \s + - > \s + ) / ) ;
321+ if ( parts . length >= 3 ) {
322+ const nodeName = parts [ 0 ] ;
323+ const connector = parts [ 1 ] ;
324+ const connections = parts [ 2 ] ;
325+
326+ // Style the node name and connections
327+ const styledNode = chalk . cyan . bold ( nodeName ) ;
328+ const styledConnector = chalk . gray ( connector ) ;
329+ const styledConnections = connections . split ( ', ' )
330+ . map ( conn => chalk . green ( conn . trim ( ) ) )
331+ . join ( chalk . gray ( ', ' ) ) ;
332+
333+ styledLines . push ( ` ${ styledNode } ${ styledConnector } ${ styledConnections } ` ) ;
334+ } else {
335+ styledLines . push ( ` ${ line } ` ) ;
336+ }
337+ } else if ( line . includes ( ':' ) && ( line . includes ( 'color' ) || line . includes ( 'shape' ) || line . includes ( 'size' ) ) ) {
338+ // This is a node property line (like "A: color "red"")
339+ const parts = line . split ( ':' ) ;
340+ if ( parts . length >= 2 ) {
341+ const nodeName = parts [ 0 ] . trim ( ) ;
342+ const properties = parts [ 1 ] . trim ( ) ;
343+
344+ const styledNode = chalk . cyan . bold ( nodeName ) ;
345+ const styledProperties = chalk . yellow ( properties ) ;
346+
347+ styledLines . push ( ` ${ styledNode } : ${ styledProperties } ` ) ;
348+ } else {
349+ styledLines . push ( ` ${ line } ` ) ;
350+ }
351+ } else if ( line . includes ( 'This is' ) ) {
352+ // This is the graph classification line
353+ styledLines . push ( `\n${ chalk . italic . gray ( line ) } ` ) ;
354+ } else if ( line . trim ( ) === '' ) {
355+ // Empty line - add some spacing
356+ styledLines . push ( '' ) ;
357+ } else if ( line . trim ( ) ) {
358+ // Other non-empty lines
359+ styledLines . push ( ` ${ line } ` ) ;
360+ }
361+ }
362+
363+ // Create a nice box around the graph
364+ const graphTitle = chalk . bold . blue ( '📊 Current Graph Structure' ) ;
365+ const boxedGraph = boxen (
366+ styledLines . join ( '\n' ) ,
367+ {
368+ padding : 1 ,
369+ margin : 1 ,
370+ borderStyle : 'round' ,
371+ borderColor : 'blue' ,
372+ title : graphTitle ,
373+ titleAlignment : 'center'
374+ }
375+ ) ;
376+
377+ return boxedGraph ;
378+ }
379+
308380async function autoshowText ( replState , baseOutput = '' , { prefix= '' , beginHistoryIndex, endHistoryIndex } = { } ) {
309381 const textFormats = [ 'tex' , 'latex' , 'json' ] ;
310382 const summaryFormats = [ 'auto' , 'graph' , 'nodes' , 'edges' , 'decorations' , 'constraints' , 'data' ] ;
@@ -319,9 +391,17 @@ async function autoshowText( replState, baseOutput='', { prefix='', beginHistory
319391 aggregatedDiff = merge ( aggregatedDiff , JSON . parse ( replState . history [ i ] . diff ) ) ;
320392 }
321393 const summarizer = autoSummarizer ( aggregatedDiff ) ;
322- autoshow = init + summarizer ( replState . graph ) + '\n' ;
394+ const rawOutput = summarizer ( replState . graph ) ;
395+
396+ // Always include the full graph structure for context
397+ const graphStructure = summarize ( 'graph' , replState . graph ) ;
398+ const combinedOutput = rawOutput . includes ( '--' ) || rawOutput . includes ( '->' ) ?
399+ rawOutput : `${ graphStructure } \n\n${ rawOutput } ` ;
400+
401+ autoshow = init + formatGraphOutput ( combinedOutput ) + '\n' ;
323402 } else if ( replState . config . autoshow && summaryFormats . includes ( replState . config . autoshow ) ) {
324- autoshow = init + summarize ( replState . config . autoshow , replState . graph ) + '\n' ;
403+ const rawOutput = summarize ( replState . config . autoshow , replState . graph ) ;
404+ autoshow = init + formatGraphOutput ( rawOutput ) + '\n' ;
325405 } else if ( replState . config . autoshow && textFormats . includes ( replState . config . autoshow ) ) {
326406 autoshow = init + showTextOutput ( replState . config . autoshow , replState ) + '\n' ;
327407 }
0 commit comments