52c4d1f1e6
- rebuild: fold observations per fingerprint in a total order (hcl DESC, node_id DESC, id DESC) so two nodes with identical logs rebuild identical entries (was: arbitrary bare-column row, merge-order dependent) - threads: CreateThreadCluster uses INSERT OR IGNORE + existing-id fallback — concurrent auto-threaders converge instead of hitting UNIQUE - errors surfaced instead of swallowed: scanEntries returns rows.Err(), Stats() fails fast on query errors, AutoLinkThreadObservations / linkTemporalNeighbors / golden-thread linking propagate failures, AddThreadNote + LinkObservationToThread write under one tx, watch records session upsert failures - gossip client: push checks HTTP status and reports errors (a broken push direction no longer looks like a silent success); gossip diff gets a 10s timeout so a dead peer cannot hang the CLI - ingest: failed source sweeps (obsidian/browser/gitea) are logged, and -d's help text now states its file-only scope - watch --quiet: fatal errors go to stderr instead of io.Discard - main: cobra SilenceErrors/SilenceUsage (errors print once, usage is not dumped on runtime failures); knox mcp exits 0 on SIGINT/SIGTERM - metrics: drop _total suffix from gauges (knox_observations, knox_entries, knox_projects, knox_sessions, knox_peers, knox_threads); _total stays on counters per Prometheus convention - http: ReadHeaderTimeout + IdleTimeout on gossip, metrics, and web servers tests: concurrent cluster-create idempotency, HCL-order rebuild fold (both merge orders), push HTTP-error surfacing; full suite + -race pass, gofmt clean
50 lines
1.3 KiB
Go
50 lines
1.3 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/storage/session_diff",
|
|
home + "/.local/share/opencode/log",
|
|
home + "/.skills",
|
|
}
|
|
}
|