Files
knox/internal/cmd/watch.go
T
david 1f35b7eea4 Merge commit '52c4d1f' into feat/remote-node
# Conflicts:
#	internal/db/db.go
2026-11-04 18:13:14 -08:00

49 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"io"
"log"
"os"
"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 {
// Not log.Fatalf: --quiet redirects the logger to io.Discard,
// so a fatal exit must reach the user on stderr directly.
fmt.Fprintf(os.Stderr, "watcher error: %v\n", err)
os.Exit(1)
}
},
}
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/log",
home + "/.skills",
}
}