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
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
nodeCallers bool
|
|
nodeFormat string
|
|
nodeContext int
|
|
nodeIndex string
|
|
)
|
|
|
|
var nodeCmd = &cobra.Command{
|
|
Use: "node <symbol-id>",
|
|
Short: "Print one symbol's source (or its callers) by graph ID",
|
|
Long: `Fetch a single graph symbol by its human-readable ID (e.g.
|
|
internal/foo.go::Bar) from the daemon that tracks the repo — the same source
|
|
get_symbol_source returns to an MCP client. With --callers, print the caller
|
|
trail (get_callers) instead, so a shell script gets Gortex's provenance-tagged
|
|
caller output without speaking the protocol.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: runNode,
|
|
}
|
|
|
|
func init() {
|
|
nodeCmd.Flags().BoolVar(&nodeCallers, "callers", false, "print the symbol's callers (get_callers) instead of its source")
|
|
nodeCmd.Flags().StringVarP(&nodeFormat, "format", "f", "", "output format: json|gcx|toon (default: tool default)")
|
|
nodeCmd.Flags().IntVar(&nodeContext, "context", 3, "extra source lines above/below the symbol")
|
|
nodeCmd.Flags().StringVar(&nodeIndex, "index", "", "repository path the daemon tracks (default: current directory)")
|
|
rootCmd.AddCommand(nodeCmd)
|
|
}
|
|
|
|
// buildNodeArgs builds the get_symbol_source tool arguments for a symbol ID,
|
|
// omitting empty optional fields.
|
|
func buildNodeArgs(id, format string, contextLines int) map[string]any {
|
|
args := map[string]any{"id": id, "context_lines": contextLines}
|
|
if format != "" {
|
|
args["format"] = format
|
|
}
|
|
return args
|
|
}
|
|
|
|
func runNode(cmd *cobra.Command, args []string) error {
|
|
id := args[0]
|
|
repoPath := nodeIndex
|
|
if repoPath == "" {
|
|
repoPath = "."
|
|
}
|
|
|
|
tool := "get_symbol_source"
|
|
toolArgs := buildNodeArgs(id, nodeFormat, nodeContext)
|
|
if nodeCallers {
|
|
tool = "get_callers"
|
|
toolArgs = map[string]any{"id": id}
|
|
if nodeFormat != "" {
|
|
toolArgs["format"] = nodeFormat
|
|
}
|
|
}
|
|
|
|
out, err := requireDaemonTool(repoPath, tool, toolArgs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintln(cmd.OutOrStdout(), string(out))
|
|
return nil
|
|
}
|