@@ -41,13 +41,19 @@ def format_node(node: FileSystemNode, query: IngestionQuery) -> tuple[str, str,
4141 A tuple containing the summary, directory structure, and file contents.
4242
4343 """
44- is_single_file = node .is_single_file ()
45- summary = _create_summary_prefix (query , single_file = is_single_file )
46- summary += node .get_summary_info ()
44+ # Use polymorphic properties - much cleaner!
45+ summary = _create_summary_prefix (query , single_file = node .is_single_file )
46+
47+ # Add type-specific summary info
48+ if isinstance (node , FileSystemDirectory ):
49+ summary += f"Files analyzed: { node .file_count } \n "
50+ elif isinstance (node , FileSystemFile ):
51+ summary += f"File: { node .name or '' } \n Lines: { len (node .content .splitlines ()):,} \n "
4752
4853 tree = "Directory structure:\n " + _create_tree_structure (query , node = node )
49-
50- content = _gather_file_contents (node )
54+
55+ # Use polymorphic content gathering
56+ content = node .gather_contents ()
5157
5258 token_estimate = _format_token_count (tree + content )
5359 if token_estimate :
@@ -96,26 +102,6 @@ def _create_summary_prefix(query: IngestionQuery, *, single_file: bool = False)
96102 return "\n " .join (parts ) + "\n "
97103
98104
99- def _gather_file_contents (node : FileSystemNode ) -> str :
100- """Recursively gather contents of all files under the given node.
101-
102- This function recursively processes a directory node and gathers the contents of all files
103- under that node. It returns the concatenated content of all files as a single string.
104-
105- Parameters
106- ----------
107- node : FileSystemNode
108- The current directory or file node being processed.
109-
110- Returns
111- -------
112- str
113- The concatenated content of all files under the given node.
114-
115- """
116- return node .gather_contents ()
117-
118-
119105def _create_tree_structure (
120106 query : IngestionQuery ,
121107 * ,
@@ -152,11 +138,10 @@ def _create_tree_structure(
152138 tree_str = ""
153139 current_prefix = "└── " if is_last else "├── "
154140
155- # Get the display name (handles directory slash, symlink target, etc.)
156- display_name = node .get_display_name ()
157- tree_str += f"{ prefix } { current_prefix } { display_name } \n "
141+ # Use polymorphic display name - handles files, dirs, symlinks automatically!
142+ tree_str += f"{ prefix } { current_prefix } { node .display_name } \n "
158143
159- if node .has_children () :
144+ if node .children :
160145 prefix += " " if is_last else "│ "
161146 for i , child in enumerate (node .children ):
162147 tree_str += _create_tree_structure (query , node = child , prefix = prefix , is_last = i == len (node .children ) - 1 )
0 commit comments