MCPcopy
hub / github.com/forloopcodes/contextplus / getContextTree

Function getContextTree

src/tools/context-tree.ts:107–128  ·  view source on GitHub ↗
(options: ContextTreeOptions)

Source from the content-addressed store, hash-verified

105}
106
107export async function getContextTree(options: ContextTreeOptions): Promise<string> {
108 const entries = await walkDirectory({
109 rootDir: options.rootDir,
110 targetPath: options.targetPath,
111 depthLimit: options.depthLimit,
112 });
113
114 const includeSymbols = options.includeSymbols !== false;
115 const tree = await buildTree(entries, options.rootDir, includeSymbols);
116 const maxTokens = options.maxTokens ?? 20000;
117
118 let rendered = renderTree(tree);
119 if (estimateTokens(rendered) <= maxTokens) return rendered;
120
121 pruneSymbols(tree);
122 rendered = renderTree(tree);
123 if (estimateTokens(rendered) <= maxTokens) return `[Level 1: Headers only, symbols pruned to fit ${maxTokens} tokens]\n\n${rendered}`;
124
125 pruneHeaders(tree);
126 rendered = renderTree(tree);
127 return `[Level 0: File names only, project too large for ${maxTokens} tokens]\n\n${rendered}`;
128}

Callers 4

index.tsFile · 0.85
mainFunction · 0.85

Calls 6

walkDirectoryFunction · 0.85
buildTreeFunction · 0.85
renderTreeFunction · 0.85
estimateTokensFunction · 0.85
pruneSymbolsFunction · 0.85
pruneHeadersFunction · 0.85

Tested by

no test coverage detected