@@ -41,13 +41,19 @@ def format_node(node: FileSystemNode, query: IngestionQuery) -> tuple[str, str,
41
41
A tuple containing the summary, directory structure, and file contents.
42
42
43
43
"""
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 "
47
52
48
53
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 ()
51
57
52
58
token_estimate = _format_token_count (tree + content )
53
59
if token_estimate :
@@ -96,26 +102,6 @@ def _create_summary_prefix(query: IngestionQuery, *, single_file: bool = False)
96
102
return "\n " .join (parts ) + "\n "
97
103
98
104
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
-
119
105
def _create_tree_structure (
120
106
query : IngestionQuery ,
121
107
* ,
@@ -152,11 +138,10 @@ def _create_tree_structure(
152
138
tree_str = ""
153
139
current_prefix = "└── " if is_last else "├── "
154
140
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 "
158
143
159
- if node .has_children () :
144
+ if node .children :
160
145
prefix += " " if is_last else "│ "
161
146
for i , child in enumerate (node .children ):
162
147
tree_str += _create_tree_structure (query , node = child , prefix = prefix , is_last = i == len (node .children ) - 1 )
0 commit comments