Add special handling when viewing projects/ and .git to text_editor_view tool

This commit is contained in:
Alex Gleason committed 2025-09-30 12:13:49 -05:00
1 parent f702d2300b
commit 8b981dcf36
2 files changed
+64 -8

No files matched your search

+19 -8
View File
@@ -59,9 +59,12 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
return tree;
}
// Check if we're starting from a .git directory
const isGitRoot = absolutePath.endsWith('/.git') || absolutePath === '.git';
// If it's a directory, generate a tree-like listing
// Note: start_line and end_line are ignored for directories
const tree = await this.generateDirectoryTree(absolutePath);
const tree = await this.generateDirectoryTree(absolutePath, "", 3, 0, isGitRoot);
return tree;
}
@@ -117,6 +120,7 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
prefix: string = "",
maxDepth: number = 3,
currentDepth: number = 0,
isGitRoot: boolean = false,
): Promise<string> {
if (currentDepth >= maxDepth) {
return prefix + "...\n";
@@ -142,13 +146,20 @@ export class TextEditorViewTool implements Tool<TextEditorViewParams> {
if (entry.isDirectory()) {
result += prefix + connector + entry.name + "/\n";
const subPath = join(dirPath, entry.name);
result += await this.generateDirectoryTree(
subPath,
nextPrefix,
maxDepth,
currentDepth + 1,
);
// Special handling for .git directories - don't traverse unless we started from .git
if (entry.name === '.git' && !isGitRoot) {
result += nextPrefix + "...\n";
} else {
const subPath = join(dirPath, entry.name);
result += await this.generateDirectoryTree(
subPath,
nextPrefix,
maxDepth,
currentDepth + 1,
isGitRoot,
);
}
} else {
result += prefix + connector + entry.name + "\n";
}