Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package cmd
import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"

"github.com/supermodeltools/cli/internal/config"
"github.com/supermodeltools/cli/internal/files"
)

// noConfigCommands are subcommands that work without a config file.
Expand All @@ -23,12 +25,16 @@ var noConfigCommands = map[string]bool{
}

var rootCmd = &cobra.Command{
Use: "supermodel",
Use: "supermodel [path]",
Short: "Give your AI coding agent a map of your codebase",
Long: `Supermodel connects AI coding agents to the Supermodel API,
providing call graphs, dead code detection, and blast radius analysis.
Long: `Runs a full generate on startup (using cached graph if available), then
enters daemon mode. Listens for file-change notifications from the
'supermodel hook' command and incrementally re-renders affected files.

Press Ctrl+C to stop and remove graph files.

See https://supermodeltools.com for documentation.`,
Args: cobra.MaximumNArgs(1),
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Walk up to the root command name to get the subcommand.
Expand All @@ -48,6 +54,43 @@ See https://supermodeltools.com for documentation.`,
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.Load()
if err != nil {
return err
}
if err := cfg.RequireAPIKey(); err != nil {
return err
}
dir := "."
if len(args) > 0 {
dir = args[0]
}
opts := files.WatchOptions{
CacheFile: watchCacheFile,
Debounce: watchDebounce,
NotifyPort: watchNotifyPort,
FSWatch: watchFSWatch,
PollInterval: watchPollInterval,
}
return files.Watch(cmd.Context(), cfg, dir, opts)
},
}

var (
watchCacheFile string
watchDebounce time.Duration
watchNotifyPort int
watchFSWatch bool
watchPollInterval time.Duration
)

func init() {
rootCmd.Flags().StringVar(&watchCacheFile, "cache-file", "", "override cache file path")
rootCmd.Flags().DurationVar(&watchDebounce, "debounce", 2*time.Second, "debounce duration before processing changes")
rootCmd.Flags().IntVar(&watchNotifyPort, "notify-port", 7734, "UDP port for hook notifications")
rootCmd.Flags().BoolVar(&watchFSWatch, "fs-watch", false, "enable git-poll fallback")
rootCmd.Flags().DurationVar(&watchPollInterval, "poll-interval", 3*time.Second, "git poll interval when --fs-watch is enabled")
}

// Execute is the entry point called by main.
Expand Down
47 changes: 0 additions & 47 deletions cmd/watch.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/files/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func Watch(ctx context.Context, cfg *config.Config, dir string, opts WatchOption
}

logf := func(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "[files] "+format+"\n", args...)
fmt.Fprintf(os.Stderr, "[supermodel] "+format+"\n", args...)
}

daemonCfg := DaemonConfig{
Expand Down
Loading