diff --git a/cmd/root.go b/cmd/root.go index a659689..97260fc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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. @@ -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. @@ -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. diff --git a/cmd/watch.go b/cmd/watch.go deleted file mode 100644 index 987e1bf..0000000 --- a/cmd/watch.go +++ /dev/null @@ -1,47 +0,0 @@ -package cmd - -import ( - "time" - - "github.com/spf13/cobra" - - "github.com/supermodeltools/cli/internal/config" - "github.com/supermodeltools/cli/internal/files" -) - -func init() { - var opts files.WatchOptions - - c := &cobra.Command{ - Use: "watch [path]", - Short: "Generate graph files on startup, then keep them updated as you code", - 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.`, - Args: cobra.MaximumNArgs(1), - 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] - } - return files.Watch(cmd.Context(), cfg, dir, opts) - }, - } - - c.Flags().StringVar(&opts.CacheFile, "cache-file", "", "override cache file path") - c.Flags().DurationVar(&opts.Debounce, "debounce", 2*time.Second, "debounce duration before processing changes") - c.Flags().IntVar(&opts.NotifyPort, "notify-port", 7734, "UDP port for hook notifications") - c.Flags().BoolVar(&opts.FSWatch, "fs-watch", false, "enable git-poll fallback") - c.Flags().DurationVar(&opts.PollInterval, "poll-interval", 3*time.Second, "git poll interval when --fs-watch is enabled") - - rootCmd.AddCommand(c) -} diff --git a/internal/files/handler.go b/internal/files/handler.go index 3e40897..555c1e9 100644 --- a/internal/files/handler.go +++ b/internal/files/handler.go @@ -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{