@@ -52,12 +52,14 @@ export const listTreeDefinition: ToolDefinition<'list_tree', typeof listTreeShap
5252
5353 if ( ! includeFiles && ! includeDirectories ) {
5454 const metadata : ListTreeMetadata = {
55- repo, ref, path : normalizedPath ,
55+ repo,
56+ ref,
57+ path : normalizedPath ,
5658 entries : [ ] ,
5759 totalReturned : 0 ,
5860 truncated : false ,
5961 } ;
60- return { output : JSON . stringify ( metadata ) , metadata } ;
62+ return { output : 'No entries found' , metadata } ;
6163 }
6264
6365 const queue : Array < { path : string ; depth : number } > = [ { path : normalizedPath , depth : 0 } ] ;
@@ -135,6 +137,38 @@ export const listTreeDefinition: ToolDefinition<'list_tree', typeof listTreeShap
135137 truncated,
136138 } ;
137139
138- return { output : JSON . stringify ( metadata ) , metadata } ;
140+ const outputLines = [ normalizedPath || '/' ] ;
141+
142+ const childrenByPath = new Map < string , ListTreeEntry [ ] > ( ) ;
143+ for ( const entry of sortedEntries ) {
144+ const siblings = childrenByPath . get ( entry . parentPath ) ?? [ ] ;
145+ siblings . push ( entry ) ;
146+ childrenByPath . set ( entry . parentPath , siblings ) ;
147+ }
148+
149+ function renderEntries ( parentPath : string ) {
150+ const children = childrenByPath . get ( parentPath ) ?? [ ] ;
151+ for ( const entry of children ) {
152+ const indent = ' ' . repeat ( entry . depth ) ;
153+ const label = entry . type === 'tree' ? `${ entry . name } /` : entry . name ;
154+ outputLines . push ( `${ indent } ${ label } ` ) ;
155+ if ( entry . type === 'tree' ) {
156+ renderEntries ( entry . path ) ;
157+ }
158+ }
159+ }
160+
161+ renderEntries ( normalizedPath ) ;
162+
163+ if ( sortedEntries . length === 0 ) {
164+ outputLines . push ( ' (no entries found)' ) ;
165+ }
166+
167+ if ( truncated ) {
168+ outputLines . push ( '' ) ;
169+ outputLines . push ( `(truncated — showing first ${ normalizedMaxEntries } entries)` ) ;
170+ }
171+
172+ return { output : outputLines . join ( '\n' ) , metadata } ;
139173 } ,
140174} ;
0 commit comments