Skip to content

Commit d1ba9ca

Browse files
brtkwrclaude
andcommitted
feat: skip subagents directory when loading conversations
Skip the entire subagents/ directory tree during filepath.Walk instead of only filtering agent- prefixed filenames. This avoids walking into subagent files entirely, improving performance and correctness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d9b3b88 commit d1ba9ca

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ func getConversations(cutoff time.Time, maxSize int64) ([]Conversation, error) {
695695
if err != nil {
696696
return nil
697697
}
698+
if info.IsDir() && info.Name() == "subagents" {
699+
return filepath.SkipDir
700+
}
698701
if !info.IsDir() && strings.HasSuffix(path, ".jsonl") && !strings.HasPrefix(info.Name(), "agent-") {
699702
files = append(files, path)
700703
}

main_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,53 @@ func TestGetConversations(t *testing.T) {
10551055
}
10561056
}
10571057

1058+
func TestGetConversationsSkipsSubagents(t *testing.T) {
1059+
tmpDir := t.TempDir()
1060+
1061+
// Create a regular session file
1062+
sessionFile := filepath.Join(tmpDir, "session-1.jsonl")
1063+
content := `{"type":"user","cwd":"/test","message":{"content":"hello"},"timestamp":"2024-01-15T10:00:00Z"}`
1064+
if err := os.WriteFile(sessionFile, []byte(content), 0644); err != nil {
1065+
t.Fatalf("failed to write session file: %v", err)
1066+
}
1067+
1068+
// Create a subagents directory with a session file inside
1069+
subagentsDir := filepath.Join(tmpDir, "abc123", "subagents")
1070+
if err := os.MkdirAll(subagentsDir, 0755); err != nil {
1071+
t.Fatalf("failed to create subagents dir: %v", err)
1072+
}
1073+
subagentFile := filepath.Join(subagentsDir, "agent-test.jsonl")
1074+
if err := os.WriteFile(subagentFile, []byte(content), 0644); err != nil {
1075+
t.Fatalf("failed to write subagent file: %v", err)
1076+
}
1077+
// Also put a non-agent-prefixed file in subagents to confirm the directory is skipped entirely
1078+
sneakyFile := filepath.Join(subagentsDir, "sneaky-session.jsonl")
1079+
if err := os.WriteFile(sneakyFile, []byte(content), 0644); err != nil {
1080+
t.Fatalf("failed to write sneaky file: %v", err)
1081+
}
1082+
1083+
oldGetProjectsDir := getProjectsDir
1084+
getProjectsDir = func() string { return tmpDir }
1085+
defer func() { getProjectsDir = oldGetProjectsDir }()
1086+
1087+
convs, err := getConversations(time.Time{}, 0)
1088+
if err != nil {
1089+
t.Fatalf("getConversations failed: %v", err)
1090+
}
1091+
1092+
// Should only have 1 conversation (subagents dir should be skipped entirely)
1093+
if len(convs) != 1 {
1094+
t.Errorf("expected 1 conversation, got %d", len(convs))
1095+
for _, c := range convs {
1096+
t.Logf(" found: %s (file: %s)", c.SessionID, c.FilePath)
1097+
}
1098+
}
1099+
1100+
if len(convs) > 0 && convs[0].SessionID != "session-1" {
1101+
t.Errorf("expected session-1, got %s", convs[0].SessionID)
1102+
}
1103+
}
1104+
10581105
func TestPrintHelp(t *testing.T) {
10591106
// Just call it to ensure no panics - we can't easily test stdout
10601107
// but this at least ensures the function doesn't crash

0 commit comments

Comments
 (0)