From fc77a4ca11001b28113d7f83efc454d3d1c04bd3 Mon Sep 17 00:00:00 2001 From: Jared Pleva Date: Sat, 4 Apr 2026 01:15:20 +0000 Subject: [PATCH 1/2] feat: brain-24-1775264868 --- internal/tools/tools.go | 9 +- internal/tools/tools_test.go | 169 ++++++++++++++++++++++++ outputs/debug_walk.go | 40 ++++++ outputs/integration_check.go | 64 +++++++++ outputs/listfiles_test.go | 166 +++++++++++++++++++++++ outputs/test_listfiles.go | 87 ++++++++++++ outputs/test_listfiles_comprehensive.go | 99 ++++++++++++++ outputs/test_listfiles_fixed.go | 93 +++++++++++++ 8 files changed, 725 insertions(+), 2 deletions(-) create mode 100644 outputs/debug_walk.go create mode 100644 outputs/integration_check.go create mode 100644 outputs/listfiles_test.go create mode 100644 outputs/test_listfiles.go create mode 100644 outputs/test_listfiles_comprehensive.go create mode 100644 outputs/test_listfiles_fixed.go diff --git a/internal/tools/tools.go b/internal/tools/tools.go index a053763..42c82aa 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -198,7 +198,8 @@ if err != nil { return nil } name := d.Name() -if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { +// Skip hidden files/directories and special directories, but not the root directory +if path != dir && (name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".")) { if d.IsDir() { return filepath.SkipDir } @@ -210,7 +211,11 @@ return fmt.Errorf("limit reached") if ext != "" && filepath.Ext(name) != ext { return nil } -rel, _ := filepath.Rel(".", path) +rel, _ := filepath.Rel(dir, path) +// Skip the root directory itself (it will be ".") +if rel == "." { +return nil +} if d.IsDir() { files = append(files, rel+"/") } else { diff --git a/internal/tools/tools_test.go b/internal/tools/tools_test.go index 667155b..bdef31a 100644 --- a/internal/tools/tools_test.go +++ b/internal/tools/tools_test.go @@ -473,3 +473,172 @@ func TestExecuteDirect_Grep(t *testing.T) { t.Fatalf("expected match, got: %s", r.Output) } } + +// ── list_files tests ── + +func TestListFiles_Basic(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) + sub := filepath.Join(dir, "sub") + os.MkdirAll(sub, 0o755) + os.WriteFile(filepath.Join(sub, "c.md"), []byte(""), 0o644) + + // Save original working directory + originalWd, _ := os.Getwd() + defer os.Chdir(originalWd) + + // Change to a different directory to test relative paths + os.Chdir("/tmp") + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Check that paths are relative to 'dir', not to cwd + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + expected := []string{"a.txt", "b.go", "sub/", "sub/c.md"} + if len(lines) != len(expected) { + t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) + } + + for i, line := range lines { + if line != expected[i] { + t.Errorf("line %d: got %q, want %q", i, line, expected[i]) + } + } +} + +func TestListFiles_FromWithinDirectory(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "test.txt"), []byte(""), 0o644) + + // Save original working directory + originalWd, _ := os.Getwd() + defer os.Chdir(originalWd) + + // Change to the test directory + os.Chdir(dir) + + r := listFiles(map[string]string{ + "directory": ".", + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should list files relative to current directory (.) + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 1 || lines[0] != "test.txt" { + t.Fatalf("expected ['test.txt'], got %v", lines) + } +} + +func TestListFiles_ExtensionFilter(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "c.go"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": dir, + "extension": ".go", + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 2 { + t.Fatalf("expected 2 .go files, got %d: %s", len(lines), r.Output) + } + for _, line := range lines { + if !strings.HasSuffix(line, ".go") { + t.Errorf("expected .go file, got %q", line) + } + } +} + +func TestListFiles_EmptyDirectory(t *testing.T) { + dir := t.TempDir() + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + if r.Output != "(empty directory)" { + t.Fatalf("expected '(empty directory)', got %q", r.Output) + } +} + +func TestListFiles_SkipsHiddenAndSpecialDirs(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "normal.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, ".hidden"), []byte(""), 0o644) + gitDir := filepath.Join(dir, ".git") + os.MkdirAll(gitDir, 0o755) + os.WriteFile(filepath.Join(gitDir, "config"), []byte(""), 0o644) + nodeModules := filepath.Join(dir, "node_modules") + os.MkdirAll(nodeModules, 0o755) + os.WriteFile(filepath.Join(nodeModules, "package.json"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should only show normal.txt + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 1 || lines[0] != "normal.txt" { + t.Fatalf("expected only 'normal.txt', got %v", lines) + } +} + +func TestListFiles_SubdirectoryListing(t *testing.T) { + dir := t.TempDir() + sub := filepath.Join(dir, "subdir") + os.MkdirAll(sub, 0o755) + os.WriteFile(filepath.Join(sub, "file.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(sub, "another.md"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": sub, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should list files relative to subdir + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + expected := []string{"file.txt", "another.md"} + if len(lines) != len(expected) { + t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) + } + // Check that we have both files (order may vary) + hasFileTxt := false + hasAnotherMd := false + for _, line := range lines { + if line == "file.txt" { + hasFileTxt = true + } + if line == "another.md" { + hasAnotherMd = true + } + } + if !hasFileTxt || !hasAnotherMd { + t.Errorf("missing expected files: got %v", lines) + } +} diff --git a/outputs/debug_walk.go b/outputs/debug_walk.go new file mode 100644 index 0000000..cddd702 --- /dev/null +++ b/outputs/debug_walk.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func main() { + // Create test directory + dir := "/tmp/debug_test" + os.RemoveAll(dir) + os.MkdirAll(dir, 0755) + os.WriteFile(filepath.Join(dir, "test.txt"), []byte(""), 0644) + + // Change to the directory + originalWd, _ := os.Getwd() + os.Chdir(dir) + defer os.Chdir(originalWd) + + // Walk the directory + fmt.Println("Walking directory '.'") + filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + name := d.Name() + fmt.Printf(" path=%q, name=%q, isDir=%v\n", path, name, d.IsDir()) + + // Check if it would be filtered + if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { + fmt.Printf(" -> Would be filtered (starts with '.' or is special dir)\n") + if d.IsDir() { + fmt.Printf(" -> Would skip directory\n") + } + } + return nil + }) +} \ No newline at end of file diff --git a/outputs/integration_check.go b/outputs/integration_check.go new file mode 100644 index 0000000..4a48b52 --- /dev/null +++ b/outputs/integration_check.go @@ -0,0 +1,64 @@ +package main + +import ( + "fmt" + "os" + + "github.com/AgentGuardHQ/shellforge/internal/tools" +) + +func main() { + // Create test directory structure + testDir := "/tmp/listfiles_integration_test" + os.RemoveAll(testDir) + os.MkdirAll(testDir+"/subdir", 0755) + os.WriteFile(testDir+"/file1.txt", []byte("test1"), 0644) + os.WriteFile(testDir+"/file2.go", []byte("package main"), 0644) + os.WriteFile(testDir+"/subdir/file3.md", []byte("# Test"), 0644) + + // Save original working directory + originalWd, _ := os.Getwd() + defer os.Chdir(originalWd) + + fmt.Println("Test 1: List files from parent directory") + fmt.Println("========================================") + os.Chdir("/tmp") + result := tools.ExecuteDirect("list_files", map[string]string{ + "directory": testDir, + }, 10) + fmt.Printf("Success: %v\n", result.Success) + fmt.Printf("Output:\n%s\n", result.Output) + fmt.Println() + + fmt.Println("Test 2: List files from within the directory") + fmt.Println("============================================") + os.Chdir(testDir) + result = tools.ExecuteDirect("list_files", map[string]string{ + "directory": ".", + }, 10) + fmt.Printf("Success: %v\n", result.Success) + fmt.Printf("Output:\n%s\n", result.Output) + fmt.Println() + + fmt.Println("Test 3: List files with .go extension filter") + fmt.Println("============================================") + os.Chdir("/tmp") + result = tools.ExecuteDirect("list_files", map[string]string{ + "directory": testDir, + "extension": ".go", + }, 10) + fmt.Printf("Success: %v\n", result.Success) + fmt.Printf("Output:\n%s\n", result.Output) + fmt.Println() + + fmt.Println("Test 4: List files from subdirectory") + fmt.Println("====================================") + result = tools.ExecuteDirect("list_files", map[string]string{ + "directory": testDir + "/subdir", + }, 10) + fmt.Printf("Success: %v\n", result.Success) + fmt.Printf("Output:\n%s\n", result.Output) + + // Cleanup + os.RemoveAll(testDir) +} \ No newline at end of file diff --git a/outputs/listfiles_test.go b/outputs/listfiles_test.go new file mode 100644 index 0000000..120bae3 --- /dev/null +++ b/outputs/listfiles_test.go @@ -0,0 +1,166 @@ +package tools + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestListFiles_Basic(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) + sub := filepath.Join(dir, "sub") + os.MkdirAll(sub, 0o755) + os.WriteFile(filepath.Join(sub, "c.md"), []byte(""), 0o644) + + // Save original working directory + originalWd, _ := os.Getwd() + defer os.Chdir(originalWd) + + // Change to a different directory to test relative paths + os.Chdir("/tmp") + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Check that paths are relative to 'dir', not to cwd + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + expected := []string{"./", "a.txt", "b.go", "sub/", "sub/c.md"} + if len(lines) != len(expected) { + t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) + } + + for i, line := range lines { + if line != expected[i] { + t.Errorf("line %d: got %q, want %q", i, line, expected[i]) + } + } +} + +func TestListFiles_FromWithinDirectory(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "test.txt"), []byte(""), 0o644) + + // Save original working directory + originalWd, _ := os.Getwd() + defer os.Chdir(originalWd) + + // Change to the test directory + os.Chdir(dir) + + r := listFiles(map[string]string{ + "directory": ".", + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should list files relative to current directory (.) + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 1 || lines[0] != "test.txt" { + t.Fatalf("expected ['test.txt'], got %v", lines) + } +} + +func TestListFiles_ExtensionFilter(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, "c.go"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": dir, + "extension": ".go", + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 2 { + t.Fatalf("expected 2 .go files, got %d: %s", len(lines), r.Output) + } + for _, line := range lines { + if !strings.HasSuffix(line, ".go") { + t.Errorf("expected .go file, got %q", line) + } + } +} + +func TestListFiles_EmptyDirectory(t *testing.T) { + dir := t.TempDir() + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + if r.Output != "(empty directory)" { + t.Fatalf("expected '(empty directory)', got %q", r.Output) + } +} + +func TestListFiles_SkipsHiddenAndSpecialDirs(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "normal.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(dir, ".hidden"), []byte(""), 0o644) + gitDir := filepath.Join(dir, ".git") + os.MkdirAll(gitDir, 0o755) + os.WriteFile(filepath.Join(gitDir, "config"), []byte(""), 0o644) + nodeModules := filepath.Join(dir, "node_modules") + os.MkdirAll(nodeModules, 0o755) + os.WriteFile(filepath.Join(nodeModules, "package.json"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": dir, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should only show normal.txt + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + if len(lines) != 1 || lines[0] != "normal.txt" { + t.Fatalf("expected only 'normal.txt', got %v", lines) + } +} + +func TestListFiles_SubdirectoryListing(t *testing.T) { + dir := t.TempDir() + sub := filepath.Join(dir, "subdir") + os.MkdirAll(sub, 0o755) + os.WriteFile(filepath.Join(sub, "file.txt"), []byte(""), 0o644) + os.WriteFile(filepath.Join(sub, "another.md"), []byte(""), 0o644) + + r := listFiles(map[string]string{ + "directory": sub, + }, 0) + + if !r.Success { + t.Fatalf("expected success, got error: %s", r.Error) + } + + // Should list files relative to subdir + lines := strings.Split(strings.TrimSpace(r.Output), "\n") + expected := []string{"./", "file.txt", "another.md"} + if len(lines) != len(expected) { + t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) + } + for i, line := range lines { + if line != expected[i] { + t.Errorf("line %d: got %q, want %q", i, line, expected[i]) + } + } +} \ No newline at end of file diff --git a/outputs/test_listfiles.go b/outputs/test_listfiles.go new file mode 100644 index 0000000..cc88124 --- /dev/null +++ b/outputs/test_listfiles.go @@ -0,0 +1,87 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func listFiles(params map[string]string) string { + dir := params["directory"] + if dir == "" { + dir = params["path"] + } + if dir == "" { + dir = params["dir"] + } + if dir == "" { + dir = "." + } + ext := params["extension"] + var files []string + filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { + if err != nil { + return nil + } + name := d.Name() + if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + if len(files) > 200 { + return fmt.Errorf("limit reached") + } + if ext != "" && filepath.Ext(name) != ext { + return nil + } + rel, _ := filepath.Rel(".", path) + if d.IsDir() { + files = append(files, rel+"/") + } else { + files = append(files, rel) + } + return nil + }) + if len(files) == 0 { + return "(empty directory)" + } + return strings.Join(files, "\n") +} + +func main() { + // Test current behavior + fmt.Println("Current behavior test:") + fmt.Println("======================") + + // Save original cwd + originalCwd, _ := os.Getwd() + + // Create test directory structure + testDir := "/tmp/test_listfiles" + os.Chdir(testDir) + + // Test listing from current directory + result := listFiles(map[string]string{"directory": "."}) + fmt.Println("listFiles from '.':") + fmt.Println(result) + fmt.Println() + + // Test listing from subdirectory + result = listFiles(map[string]string{"directory": "subdir"}) + fmt.Println("listFiles from 'subdir':") + fmt.Println(result) + fmt.Println() + + // Change to a different directory and test + os.Chdir("/tmp") + result = listFiles(map[string]string{"directory": testDir}) + fmt.Println("listFiles from '/tmp' with directory='", testDir, "':") + fmt.Println(result) + fmt.Println() + + // Restore original cwd + os.Chdir(originalCwd) +} \ No newline at end of file diff --git a/outputs/test_listfiles_comprehensive.go b/outputs/test_listfiles_comprehensive.go new file mode 100644 index 0000000..3f78d94 --- /dev/null +++ b/outputs/test_listfiles_comprehensive.go @@ -0,0 +1,99 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func listFiles(params map[string]string) string { + dir := params["directory"] + if dir == "" { + dir = params["path"] + } + if dir == "" { + dir = params["dir"] + } + if dir == "" { + dir = "." + } + ext := params["extension"] + var files []string + filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { + if err != nil { + return nil + } + name := d.Name() + if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + if len(files) > 200 { + return fmt.Errorf("limit reached") + } + if ext != "" && filepath.Ext(name) != ext { + return nil + } + rel, _ := filepath.Rel(dir, path) + if d.IsDir() { + files = append(files, rel+"/") + } else { + files = append(files, rel) + } + return nil + }) + if len(files) == 0 { + return "(empty directory)" + } + return strings.Join(files, "\n") +} + +func main() { + // Create a fresh test directory + testDir := "/tmp/test_listfiles_fresh" + os.RemoveAll(testDir) + os.MkdirAll(testDir+"/subdir", 0755) + os.WriteFile(testDir+"/file1.txt", []byte("test"), 0644) + os.WriteFile(testDir+"/file2.go", []byte("package main"), 0644) + os.WriteFile(testDir+"/subdir/file3.md", []byte("# Test"), 0644) + + // Save original cwd + originalCwd, _ := os.Getwd() + + fmt.Println("Test 1: From parent directory, list subdirectory") + fmt.Println("================================================") + os.Chdir("/tmp") + result := listFiles(map[string]string{"directory": testDir}) + fmt.Println("Result:") + fmt.Println(result) + fmt.Println() + + fmt.Println("Test 2: From within the directory, list current directory") + fmt.Println("========================================================") + os.Chdir(testDir) + result = listFiles(map[string]string{"directory": "."}) + fmt.Println("Result:") + fmt.Println(result) + fmt.Println() + + fmt.Println("Test 3: From parent, list subdirectory with extension filter") + fmt.Println("===========================================================") + os.Chdir("/tmp") + result = listFiles(map[string]string{"directory": testDir, "extension": ".go"}) + fmt.Println("Result:") + fmt.Println(result) + fmt.Println() + + fmt.Println("Test 4: List a nested subdirectory") + fmt.Println("==================================") + result = listFiles(map[string]string{"directory": testDir + "/subdir"}) + fmt.Println("Result:") + fmt.Println(result) + fmt.Println() + + // Restore original cwd + os.Chdir(originalCwd) +} \ No newline at end of file diff --git a/outputs/test_listfiles_fixed.go b/outputs/test_listfiles_fixed.go new file mode 100644 index 0000000..e34bce2 --- /dev/null +++ b/outputs/test_listfiles_fixed.go @@ -0,0 +1,93 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func listFiles(params map[string]string) string { + dir := params["directory"] + if dir == "" { + dir = params["path"] + } + if dir == "" { + dir = params["dir"] + } + if dir == "" { + dir = "." + } + ext := params["extension"] + var files []string + filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { + if err != nil { + return nil + } + name := d.Name() + if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + if len(files) > 200 { + return fmt.Errorf("limit reached") + } + if ext != "" && filepath.Ext(name) != ext { + return nil + } + rel, _ := filepath.Rel(dir, path) + if d.IsDir() { + files = append(files, rel+"/") + } else { + files = append(files, rel) + } + return nil + }) + if len(files) == 0 { + return "(empty directory)" + } + return strings.Join(files, "\n") +} + +func main() { + // Test fixed behavior + fmt.Println("Fixed behavior test:") + fmt.Println("====================") + + // Save original cwd + originalCwd, _ := os.Getwd() + + // Create test directory structure + testDir := "/tmp/test_listfiles" + + // Test listing from current directory + os.Chdir(testDir) + result := listFiles(map[string]string{"directory": "."}) + fmt.Println("listFiles from '.':") + fmt.Println(result) + fmt.Println() + + // Test listing from subdirectory + result = listFiles(map[string]string{"directory": "subdir"}) + fmt.Println("listFiles from 'subdir':") + fmt.Println(result) + fmt.Println() + + // Change to a different directory and test + os.Chdir("/tmp") + result = listFiles(map[string]string{"directory": testDir}) + fmt.Println("listFiles from '/tmp' with directory='", testDir, "':") + fmt.Println(result) + fmt.Println() + + // Test with absolute path + result = listFiles(map[string]string{"directory": testDir + "/subdir"}) + fmt.Println("listFiles from '/tmp' with directory='", testDir + "/subdir", "':") + fmt.Println(result) + fmt.Println() + + // Restore original cwd + os.Chdir(originalCwd) +} \ No newline at end of file From 8293ea8752cf09d21eac55de1fa3866ad5a0ffa1 Mon Sep 17 00:00:00 2001 From: Jared Pleva Date: Sat, 4 Apr 2026 01:43:48 +0000 Subject: [PATCH 2/2] chore: remove debug outputs/ artifacts that break go build The outputs/ directory contained debug Go files with conflicting package declarations that caused CI build failures. Simplified .gitignore to exclude the entire outputs/ directory. Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitignore | 6 +- outputs/debug_walk.go | 40 ------ outputs/integration_check.go | 64 --------- outputs/listfiles_test.go | 166 ------------------------ outputs/logs/.gitkeep | 1 - outputs/reports/.gitkeep | 1 - outputs/test_listfiles.go | 87 ------------- outputs/test_listfiles_comprehensive.go | 99 -------------- outputs/test_listfiles_fixed.go | 93 ------------- 9 files changed, 1 insertion(+), 556 deletions(-) delete mode 100644 outputs/debug_walk.go delete mode 100644 outputs/integration_check.go delete mode 100644 outputs/listfiles_test.go delete mode 100644 outputs/logs/.gitkeep delete mode 100644 outputs/reports/.gitkeep delete mode 100644 outputs/test_listfiles.go delete mode 100644 outputs/test_listfiles_comprehensive.go delete mode 100644 outputs/test_listfiles_fixed.go diff --git a/.gitignore b/.gitignore index 0514c63..38befa5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,11 +6,7 @@ dist/ # Agent outputs (generated at runtime) -outputs/logs/*.log -outputs/logs/*.md -outputs/logs/*.jsonl -outputs/reports/*.md -outputs/reports/*.jsonl +outputs/ # Environment .env diff --git a/outputs/debug_walk.go b/outputs/debug_walk.go deleted file mode 100644 index cddd702..0000000 --- a/outputs/debug_walk.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "strings" -) - -func main() { - // Create test directory - dir := "/tmp/debug_test" - os.RemoveAll(dir) - os.MkdirAll(dir, 0755) - os.WriteFile(filepath.Join(dir, "test.txt"), []byte(""), 0644) - - // Change to the directory - originalWd, _ := os.Getwd() - os.Chdir(dir) - defer os.Chdir(originalWd) - - // Walk the directory - fmt.Println("Walking directory '.'") - filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error { - if err != nil { - return err - } - name := d.Name() - fmt.Printf(" path=%q, name=%q, isDir=%v\n", path, name, d.IsDir()) - - // Check if it would be filtered - if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { - fmt.Printf(" -> Would be filtered (starts with '.' or is special dir)\n") - if d.IsDir() { - fmt.Printf(" -> Would skip directory\n") - } - } - return nil - }) -} \ No newline at end of file diff --git a/outputs/integration_check.go b/outputs/integration_check.go deleted file mode 100644 index 4a48b52..0000000 --- a/outputs/integration_check.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/AgentGuardHQ/shellforge/internal/tools" -) - -func main() { - // Create test directory structure - testDir := "/tmp/listfiles_integration_test" - os.RemoveAll(testDir) - os.MkdirAll(testDir+"/subdir", 0755) - os.WriteFile(testDir+"/file1.txt", []byte("test1"), 0644) - os.WriteFile(testDir+"/file2.go", []byte("package main"), 0644) - os.WriteFile(testDir+"/subdir/file3.md", []byte("# Test"), 0644) - - // Save original working directory - originalWd, _ := os.Getwd() - defer os.Chdir(originalWd) - - fmt.Println("Test 1: List files from parent directory") - fmt.Println("========================================") - os.Chdir("/tmp") - result := tools.ExecuteDirect("list_files", map[string]string{ - "directory": testDir, - }, 10) - fmt.Printf("Success: %v\n", result.Success) - fmt.Printf("Output:\n%s\n", result.Output) - fmt.Println() - - fmt.Println("Test 2: List files from within the directory") - fmt.Println("============================================") - os.Chdir(testDir) - result = tools.ExecuteDirect("list_files", map[string]string{ - "directory": ".", - }, 10) - fmt.Printf("Success: %v\n", result.Success) - fmt.Printf("Output:\n%s\n", result.Output) - fmt.Println() - - fmt.Println("Test 3: List files with .go extension filter") - fmt.Println("============================================") - os.Chdir("/tmp") - result = tools.ExecuteDirect("list_files", map[string]string{ - "directory": testDir, - "extension": ".go", - }, 10) - fmt.Printf("Success: %v\n", result.Success) - fmt.Printf("Output:\n%s\n", result.Output) - fmt.Println() - - fmt.Println("Test 4: List files from subdirectory") - fmt.Println("====================================") - result = tools.ExecuteDirect("list_files", map[string]string{ - "directory": testDir + "/subdir", - }, 10) - fmt.Printf("Success: %v\n", result.Success) - fmt.Printf("Output:\n%s\n", result.Output) - - // Cleanup - os.RemoveAll(testDir) -} \ No newline at end of file diff --git a/outputs/listfiles_test.go b/outputs/listfiles_test.go deleted file mode 100644 index 120bae3..0000000 --- a/outputs/listfiles_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package tools - -import ( - "os" - "path/filepath" - "strings" - "testing" -) - -func TestListFiles_Basic(t *testing.T) { - dir := t.TempDir() - os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) - os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) - sub := filepath.Join(dir, "sub") - os.MkdirAll(sub, 0o755) - os.WriteFile(filepath.Join(sub, "c.md"), []byte(""), 0o644) - - // Save original working directory - originalWd, _ := os.Getwd() - defer os.Chdir(originalWd) - - // Change to a different directory to test relative paths - os.Chdir("/tmp") - - r := listFiles(map[string]string{ - "directory": dir, - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - - // Check that paths are relative to 'dir', not to cwd - lines := strings.Split(strings.TrimSpace(r.Output), "\n") - expected := []string{"./", "a.txt", "b.go", "sub/", "sub/c.md"} - if len(lines) != len(expected) { - t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) - } - - for i, line := range lines { - if line != expected[i] { - t.Errorf("line %d: got %q, want %q", i, line, expected[i]) - } - } -} - -func TestListFiles_FromWithinDirectory(t *testing.T) { - dir := t.TempDir() - os.WriteFile(filepath.Join(dir, "test.txt"), []byte(""), 0o644) - - // Save original working directory - originalWd, _ := os.Getwd() - defer os.Chdir(originalWd) - - // Change to the test directory - os.Chdir(dir) - - r := listFiles(map[string]string{ - "directory": ".", - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - - // Should list files relative to current directory (.) - lines := strings.Split(strings.TrimSpace(r.Output), "\n") - if len(lines) != 1 || lines[0] != "test.txt" { - t.Fatalf("expected ['test.txt'], got %v", lines) - } -} - -func TestListFiles_ExtensionFilter(t *testing.T) { - dir := t.TempDir() - os.WriteFile(filepath.Join(dir, "a.txt"), []byte(""), 0o644) - os.WriteFile(filepath.Join(dir, "b.go"), []byte(""), 0o644) - os.WriteFile(filepath.Join(dir, "c.go"), []byte(""), 0o644) - - r := listFiles(map[string]string{ - "directory": dir, - "extension": ".go", - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - - lines := strings.Split(strings.TrimSpace(r.Output), "\n") - if len(lines) != 2 { - t.Fatalf("expected 2 .go files, got %d: %s", len(lines), r.Output) - } - for _, line := range lines { - if !strings.HasSuffix(line, ".go") { - t.Errorf("expected .go file, got %q", line) - } - } -} - -func TestListFiles_EmptyDirectory(t *testing.T) { - dir := t.TempDir() - - r := listFiles(map[string]string{ - "directory": dir, - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - if r.Output != "(empty directory)" { - t.Fatalf("expected '(empty directory)', got %q", r.Output) - } -} - -func TestListFiles_SkipsHiddenAndSpecialDirs(t *testing.T) { - dir := t.TempDir() - os.WriteFile(filepath.Join(dir, "normal.txt"), []byte(""), 0o644) - os.WriteFile(filepath.Join(dir, ".hidden"), []byte(""), 0o644) - gitDir := filepath.Join(dir, ".git") - os.MkdirAll(gitDir, 0o755) - os.WriteFile(filepath.Join(gitDir, "config"), []byte(""), 0o644) - nodeModules := filepath.Join(dir, "node_modules") - os.MkdirAll(nodeModules, 0o755) - os.WriteFile(filepath.Join(nodeModules, "package.json"), []byte(""), 0o644) - - r := listFiles(map[string]string{ - "directory": dir, - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - - // Should only show normal.txt - lines := strings.Split(strings.TrimSpace(r.Output), "\n") - if len(lines) != 1 || lines[0] != "normal.txt" { - t.Fatalf("expected only 'normal.txt', got %v", lines) - } -} - -func TestListFiles_SubdirectoryListing(t *testing.T) { - dir := t.TempDir() - sub := filepath.Join(dir, "subdir") - os.MkdirAll(sub, 0o755) - os.WriteFile(filepath.Join(sub, "file.txt"), []byte(""), 0o644) - os.WriteFile(filepath.Join(sub, "another.md"), []byte(""), 0o644) - - r := listFiles(map[string]string{ - "directory": sub, - }, 0) - - if !r.Success { - t.Fatalf("expected success, got error: %s", r.Error) - } - - // Should list files relative to subdir - lines := strings.Split(strings.TrimSpace(r.Output), "\n") - expected := []string{"./", "file.txt", "another.md"} - if len(lines) != len(expected) { - t.Fatalf("expected %d lines, got %d: %s", len(expected), len(lines), r.Output) - } - for i, line := range lines { - if line != expected[i] { - t.Errorf("line %d: got %q, want %q", i, line, expected[i]) - } - } -} \ No newline at end of file diff --git a/outputs/logs/.gitkeep b/outputs/logs/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/outputs/logs/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/outputs/reports/.gitkeep b/outputs/reports/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/outputs/reports/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/outputs/test_listfiles.go b/outputs/test_listfiles.go deleted file mode 100644 index cc88124..0000000 --- a/outputs/test_listfiles.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "strings" -) - -func listFiles(params map[string]string) string { - dir := params["directory"] - if dir == "" { - dir = params["path"] - } - if dir == "" { - dir = params["dir"] - } - if dir == "" { - dir = "." - } - ext := params["extension"] - var files []string - filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { - if err != nil { - return nil - } - name := d.Name() - if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { - if d.IsDir() { - return filepath.SkipDir - } - return nil - } - if len(files) > 200 { - return fmt.Errorf("limit reached") - } - if ext != "" && filepath.Ext(name) != ext { - return nil - } - rel, _ := filepath.Rel(".", path) - if d.IsDir() { - files = append(files, rel+"/") - } else { - files = append(files, rel) - } - return nil - }) - if len(files) == 0 { - return "(empty directory)" - } - return strings.Join(files, "\n") -} - -func main() { - // Test current behavior - fmt.Println("Current behavior test:") - fmt.Println("======================") - - // Save original cwd - originalCwd, _ := os.Getwd() - - // Create test directory structure - testDir := "/tmp/test_listfiles" - os.Chdir(testDir) - - // Test listing from current directory - result := listFiles(map[string]string{"directory": "."}) - fmt.Println("listFiles from '.':") - fmt.Println(result) - fmt.Println() - - // Test listing from subdirectory - result = listFiles(map[string]string{"directory": "subdir"}) - fmt.Println("listFiles from 'subdir':") - fmt.Println(result) - fmt.Println() - - // Change to a different directory and test - os.Chdir("/tmp") - result = listFiles(map[string]string{"directory": testDir}) - fmt.Println("listFiles from '/tmp' with directory='", testDir, "':") - fmt.Println(result) - fmt.Println() - - // Restore original cwd - os.Chdir(originalCwd) -} \ No newline at end of file diff --git a/outputs/test_listfiles_comprehensive.go b/outputs/test_listfiles_comprehensive.go deleted file mode 100644 index 3f78d94..0000000 --- a/outputs/test_listfiles_comprehensive.go +++ /dev/null @@ -1,99 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "strings" -) - -func listFiles(params map[string]string) string { - dir := params["directory"] - if dir == "" { - dir = params["path"] - } - if dir == "" { - dir = params["dir"] - } - if dir == "" { - dir = "." - } - ext := params["extension"] - var files []string - filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { - if err != nil { - return nil - } - name := d.Name() - if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { - if d.IsDir() { - return filepath.SkipDir - } - return nil - } - if len(files) > 200 { - return fmt.Errorf("limit reached") - } - if ext != "" && filepath.Ext(name) != ext { - return nil - } - rel, _ := filepath.Rel(dir, path) - if d.IsDir() { - files = append(files, rel+"/") - } else { - files = append(files, rel) - } - return nil - }) - if len(files) == 0 { - return "(empty directory)" - } - return strings.Join(files, "\n") -} - -func main() { - // Create a fresh test directory - testDir := "/tmp/test_listfiles_fresh" - os.RemoveAll(testDir) - os.MkdirAll(testDir+"/subdir", 0755) - os.WriteFile(testDir+"/file1.txt", []byte("test"), 0644) - os.WriteFile(testDir+"/file2.go", []byte("package main"), 0644) - os.WriteFile(testDir+"/subdir/file3.md", []byte("# Test"), 0644) - - // Save original cwd - originalCwd, _ := os.Getwd() - - fmt.Println("Test 1: From parent directory, list subdirectory") - fmt.Println("================================================") - os.Chdir("/tmp") - result := listFiles(map[string]string{"directory": testDir}) - fmt.Println("Result:") - fmt.Println(result) - fmt.Println() - - fmt.Println("Test 2: From within the directory, list current directory") - fmt.Println("========================================================") - os.Chdir(testDir) - result = listFiles(map[string]string{"directory": "."}) - fmt.Println("Result:") - fmt.Println(result) - fmt.Println() - - fmt.Println("Test 3: From parent, list subdirectory with extension filter") - fmt.Println("===========================================================") - os.Chdir("/tmp") - result = listFiles(map[string]string{"directory": testDir, "extension": ".go"}) - fmt.Println("Result:") - fmt.Println(result) - fmt.Println() - - fmt.Println("Test 4: List a nested subdirectory") - fmt.Println("==================================") - result = listFiles(map[string]string{"directory": testDir + "/subdir"}) - fmt.Println("Result:") - fmt.Println(result) - fmt.Println() - - // Restore original cwd - os.Chdir(originalCwd) -} \ No newline at end of file diff --git a/outputs/test_listfiles_fixed.go b/outputs/test_listfiles_fixed.go deleted file mode 100644 index e34bce2..0000000 --- a/outputs/test_listfiles_fixed.go +++ /dev/null @@ -1,93 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "strings" -) - -func listFiles(params map[string]string) string { - dir := params["directory"] - if dir == "" { - dir = params["path"] - } - if dir == "" { - dir = params["dir"] - } - if dir == "" { - dir = "." - } - ext := params["extension"] - var files []string - filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { - if err != nil { - return nil - } - name := d.Name() - if name == "node_modules" || name == ".git" || strings.HasPrefix(name, ".") { - if d.IsDir() { - return filepath.SkipDir - } - return nil - } - if len(files) > 200 { - return fmt.Errorf("limit reached") - } - if ext != "" && filepath.Ext(name) != ext { - return nil - } - rel, _ := filepath.Rel(dir, path) - if d.IsDir() { - files = append(files, rel+"/") - } else { - files = append(files, rel) - } - return nil - }) - if len(files) == 0 { - return "(empty directory)" - } - return strings.Join(files, "\n") -} - -func main() { - // Test fixed behavior - fmt.Println("Fixed behavior test:") - fmt.Println("====================") - - // Save original cwd - originalCwd, _ := os.Getwd() - - // Create test directory structure - testDir := "/tmp/test_listfiles" - - // Test listing from current directory - os.Chdir(testDir) - result := listFiles(map[string]string{"directory": "."}) - fmt.Println("listFiles from '.':") - fmt.Println(result) - fmt.Println() - - // Test listing from subdirectory - result = listFiles(map[string]string{"directory": "subdir"}) - fmt.Println("listFiles from 'subdir':") - fmt.Println(result) - fmt.Println() - - // Change to a different directory and test - os.Chdir("/tmp") - result = listFiles(map[string]string{"directory": testDir}) - fmt.Println("listFiles from '/tmp' with directory='", testDir, "':") - fmt.Println(result) - fmt.Println() - - // Test with absolute path - result = listFiles(map[string]string{"directory": testDir + "/subdir"}) - fmt.Println("listFiles from '/tmp' with directory='", testDir + "/subdir", "':") - fmt.Println(result) - fmt.Println() - - // Restore original cwd - os.Chdir(originalCwd) -} \ No newline at end of file