MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / buildDirectoryTree

Function buildDirectoryTree

src/context/tree.ts:102–128  ·  view source on GitHub ↗
(
  rootDir: string,
  options: TreeOptions = {},
)

Source from the content-addressed store, hash-verified

100}
101
102export async function buildDirectoryTree(
103 rootDir: string,
104 options: TreeOptions = {},
105): Promise<string> {
106 const ctx: TreeContext = {
107 maxDepth: options.maxDepth ?? 3,
108 maxEntries: options.maxEntries ?? 200,
109 maxBytes: options.maxBytes ?? 4000,
110 relevantFolders: inferRelevantFolders(options.userPromptHint),
111 hasWeighting: false,
112 entryCount: 0,
113 byteCount: 0,
114 truncated: false,
115 lines: [path.basename(rootDir) + '/'],
116 };
117 ctx.hasWeighting = ctx.relevantFolders.size > 0;
118 ctx.byteCount = ctx.lines[0]!.length;
119
120 await walk(rootDir, 1, '', ctx);
121
122 if (ctx.hasWeighting) {
123 ctx.lines.push('');
124 ctx.lines.push(`(tree weighted for query: kept ${[...ctx.relevantFolders].slice(0, 6).join('/')}; other folders summarised)`);
125 }
126
127 return ctx.lines.join('\n');
128}
129
130/** Whether a directory should be EXPANDED (deep walk) vs SUMMARISED (one-line count). */
131function shouldExpandDir(name: string, ctx: TreeContext): boolean {

Callers 3

phase-a.test.tsFile · 0.85
index.tsFile · 0.85
buildInitialMessagesMethod · 0.85

Calls 3

inferRelevantFoldersFunction · 0.85
walkFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected