mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add special handling when viewing projects/ and .git to text_editor_view tool
This commit is contained in:
2 files changed
+64
-8
No files matched your search
@@ -23,11 +23,15 @@ class MockFS implements JSRuntimeFS {
|
||||
|
||||
this.files.set('/projects/project1/package.json', '{"name": "project1"}');
|
||||
this.files.set('/projects/project1/src/index.ts', 'console.log("project1");');
|
||||
this.files.set('/projects/project1/.git/config', '[core]\nrepositoryformatversion = 0');
|
||||
this.files.set('/projects/project1/.git/HEAD', 'ref: refs/heads/main');
|
||||
this.files.set('/projects/project2/package.json', '{"name": "project2"}');
|
||||
this.files.set('/projects/project2/src/main.ts', 'console.log("project2");');
|
||||
this.files.set('/project/package.json', '{"name": "test"}');
|
||||
this.files.set('/project/src/index.ts', 'console.log("hello");');
|
||||
this.files.set('/project/.gitignore', 'node_modules\n.git\n');
|
||||
this.files.set('/project/.git/config', '[core]\nrepositoryformatversion = 0');
|
||||
this.files.set('/project/.git/HEAD', 'ref: refs/heads/main');
|
||||
this.files.set('/tmp/uploaded-file.txt', 'This is an uploaded file');
|
||||
|
||||
// Add binary files for testing
|
||||
@@ -284,4 +288,45 @@ describe('TextEditorViewTool', () => {
|
||||
expect(result).not.toContain('index.ts');
|
||||
expect(result).not.toContain('main.ts');
|
||||
});
|
||||
|
||||
it('should show .git directory but not traverse its contents when viewing project root', async () => {
|
||||
const result = await tool.execute({ path: '/project' });
|
||||
|
||||
// Should show the .git directory
|
||||
expect(result).toContain('.git/');
|
||||
|
||||
// Should show "..." under .git instead of its contents
|
||||
expect(result).toContain('...');
|
||||
|
||||
// Should NOT show .git file contents
|
||||
expect(result).not.toContain('config');
|
||||
expect(result).not.toContain('HEAD');
|
||||
expect(result).not.toContain('repositoryformatversion');
|
||||
|
||||
// Should still show other directory contents normally
|
||||
expect(result).toContain('src/');
|
||||
expect(result).toContain('package.json');
|
||||
});
|
||||
|
||||
it('should show .git contents when explicitly viewing .git directory', async () => {
|
||||
const result = await tool.execute({ path: '/project/.git' });
|
||||
|
||||
// Should show the .git file contents when explicitly requested
|
||||
expect(result).toContain('config');
|
||||
expect(result).toContain('HEAD');
|
||||
|
||||
// Should NOT show "..." when explicitly viewing .git
|
||||
expect(result).not.toContain('...');
|
||||
});
|
||||
|
||||
it('should show .git contents when explicitly viewing .git with relative path', async () => {
|
||||
const result = await tool.execute({ path: '.git' });
|
||||
|
||||
// Should show the .git file contents when explicitly requested
|
||||
expect(result).toContain('config');
|
||||
expect(result).toContain('HEAD');
|
||||
|
||||
// Should NOT show "..." when explicitly viewing .git
|
||||
expect(result).not.toContain('...');
|
||||
});
|
||||
});
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user