Skip to content

Commit 146f776

Browse files
authored
Merge pull request #2 from agentic-utils/feat/exclude-dirs
feat: add --exclude flag to filter out directories
2 parents d1ba9ca + f368d29 commit 146f776

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func parseConversationFile(path string, cutoff time.Time, maxSize int64) (*Conve
687687
return conv, nil
688688
}
689689

690-
func getConversations(cutoff time.Time, maxSize int64) ([]Conversation, error) {
690+
func getConversations(cutoff time.Time, maxSize int64, excludeDirs []string) ([]Conversation, error) {
691691
projectsDir := getProjectsDir()
692692

693693
var files []string
@@ -698,6 +698,13 @@ func getConversations(cutoff time.Time, maxSize int64) ([]Conversation, error) {
698698
if info.IsDir() && info.Name() == "subagents" {
699699
return filepath.SkipDir
700700
}
701+
if info.IsDir() {
702+
for _, exc := range excludeDirs {
703+
if strings.Contains(info.Name(), exc) {
704+
return filepath.SkipDir
705+
}
706+
}
707+
}
701708
if !info.IsDir() && strings.HasSuffix(path, ".jsonl") && !strings.HasPrefix(info.Name(), "agent-") {
702709
files = append(files, path)
703710
}
@@ -863,6 +870,7 @@ Flags:
863870
--max-age=N Only search last N days (default: 60, 0 = no limit)
864871
--max-size=N Max file size in MB (default: 1024, 0 = no limit)
865872
--all Include everything (same as --max-age=0 --max-size=0)
873+
--exclude=a,b Exclude dirs containing these strings (default: observer-sessions)
866874
--dump [query] Debug: print all search items (with optional highlighting)
867875
868876
Examples:
@@ -902,6 +910,7 @@ func main() {
902910
// Parse flags
903911
maxAgeDays := 60 // Default to 60 days
904912
maxSizeMB := int64(1024) // Default to 1GB
913+
excludeDirs := []string{"observer-sessions"}
905914
for _, arg := range args {
906915
if arg == "--all" {
907916
maxAgeDays = 0
@@ -912,6 +921,9 @@ func main() {
912921
} else if strings.HasPrefix(arg, "--max-size=") {
913922
val := strings.TrimPrefix(arg, "--max-size=")
914923
fmt.Sscanf(val, "%d", &maxSizeMB)
924+
} else if strings.HasPrefix(arg, "--exclude=") {
925+
val := strings.TrimPrefix(arg, "--exclude=")
926+
excludeDirs = strings.Split(val, ",")
915927
}
916928
}
917929

@@ -931,7 +943,7 @@ func main() {
931943
if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
932944
filter = args[i+1]
933945
}
934-
conversations, _ := getConversations(cutoff, maxSize)
946+
conversations, _ := getConversations(cutoff, maxSize, excludeDirs)
935947
items := buildItems(conversations)
936948
for _, item := range items {
937949
line := item.searchText
@@ -953,7 +965,7 @@ func main() {
953965
break
954966
}
955967
// Skip our flags when looking for filter query
956-
if arg == "--all" || strings.HasPrefix(arg, "--max-age=") || strings.HasPrefix(arg, "--max-size=") {
968+
if arg == "--all" || strings.HasPrefix(arg, "--max-age=") || strings.HasPrefix(arg, "--max-size=") || strings.HasPrefix(arg, "--exclude=") {
957969
continue
958970
}
959971
if !strings.HasPrefix(arg, "-") && filterQuery == "" {
@@ -969,7 +981,7 @@ func main() {
969981
}
970982

971983
fmt.Fprint(os.Stderr, "Loading conversations...")
972-
conversations, err := getConversations(cutoff, maxSize)
984+
conversations, err := getConversations(cutoff, maxSize, excludeDirs)
973985
if err != nil {
974986
fmt.Fprintf(os.Stderr, "\rError loading conversations: %v\n", err)
975987
os.Exit(1)

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ func TestGetConversations(t *testing.T) {
10361036
defer func() { getProjectsDir = oldGetProjectsDir }()
10371037

10381038
// Get conversations
1039-
convs, err := getConversations(time.Time{}, 0)
1039+
convs, err := getConversations(time.Time{}, 0, nil)
10401040
if err != nil {
10411041
t.Fatalf("getConversations failed: %v", err)
10421042
}
@@ -1084,7 +1084,7 @@ func TestGetConversationsSkipsSubagents(t *testing.T) {
10841084
getProjectsDir = func() string { return tmpDir }
10851085
defer func() { getProjectsDir = oldGetProjectsDir }()
10861086

1087-
convs, err := getConversations(time.Time{}, 0)
1087+
convs, err := getConversations(time.Time{}, 0, nil)
10881088
if err != nil {
10891089
t.Fatalf("getConversations failed: %v", err)
10901090
}

0 commit comments

Comments
 (0)