package cmd import ( "io" "log" "github.com/david/knox/internal/db" "github.com/david/knox/internal/watch" "github.com/spf13/cobra" ) func NewWatchCmd(kdb *db.KnoxDB) *cobra.Command { var dirs []string var quiet bool cmd := &cobra.Command{ Use: "watch", Short: "Watch directories for new session data and ingest into index", Run: func(cmd *cobra.Command, args []string) { if len(dirs) == 0 { dirs = defaultWatchDirs() } if quiet { log.SetOutput(io.Discard) } log.Printf("[knox] starting watcher, scanning %d directories", len(dirs)) w := watch.New(kdb, dirs) if err := w.Start(); err != nil { log.Fatalf("watcher error: %v", err) } }, } cmd.Flags().StringSliceVarP(&dirs, "dir", "d", nil, "Directories to watch (default: opencode storage/log + skills)") cmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "Suppress per-entry log output") return cmd } func defaultWatchDirs() []string { home, _ := getHomeDir() return []string{ home + "/.local/share/opencode/storage/session_diff", home + "/.local/share/opencode/log", home + "/.skills", } }