a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
exploreEntryPoint string
|
|
exploreFormat string
|
|
exploreMaxSymbols int
|
|
exploreIndex string
|
|
)
|
|
|
|
var exploreCmd = &cobra.Command{
|
|
Use: "explore <task...>",
|
|
Short: "Assemble the relevant working set for a task (shell smart_context)",
|
|
Long: `Run smart_context for a task against the daemon that tracks the repo and print
|
|
the assembled working set — the same payload an MCP client gets, so a non-MCP
|
|
Task subagent (or a shell script) can explore the graph without a protocol.`,
|
|
Args: cobra.MinimumNArgs(1),
|
|
RunE: runExplore,
|
|
}
|
|
|
|
func init() {
|
|
exploreCmd.Flags().StringVarP(&exploreEntryPoint, "entry-point", "e", "", "symbol ID or file path to start from")
|
|
exploreCmd.Flags().StringVarP(&exploreFormat, "format", "f", "", "output format: json|gcx|toon (default: tool default)")
|
|
exploreCmd.Flags().IntVarP(&exploreMaxSymbols, "max-symbols", "n", 5, "max symbols to include source for")
|
|
exploreCmd.Flags().StringVar(&exploreIndex, "index", "", "repository path the daemon tracks (default: current directory)")
|
|
rootCmd.AddCommand(exploreCmd)
|
|
}
|
|
|
|
// buildExploreArgs builds the smart_context tool arguments from the explore
|
|
// flags, omitting empty optional fields.
|
|
func buildExploreArgs(task, entryPoint, format string, maxSymbols int) map[string]any {
|
|
args := map[string]any{"task": task, "max_symbols": maxSymbols}
|
|
if entryPoint != "" {
|
|
args["entry_point"] = entryPoint
|
|
}
|
|
if format != "" {
|
|
args["format"] = format
|
|
}
|
|
return args
|
|
}
|
|
|
|
func runExplore(cmd *cobra.Command, args []string) error {
|
|
task := strings.TrimSpace(strings.Join(args, " "))
|
|
if task == "" {
|
|
return fmt.Errorf("explore: a task description is required")
|
|
}
|
|
repoPath := exploreIndex
|
|
if repoPath == "" {
|
|
repoPath = "."
|
|
}
|
|
out, err := requireDaemonTool(repoPath, "smart_context",
|
|
buildExploreArgs(task, exploreEntryPoint, exploreFormat, exploreMaxSymbols))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintln(cmd.OutOrStdout(), string(out))
|
|
return nil
|
|
}
|