Add GSP links field and link inspection

This commit is contained in:
2026-05-07 10:41:38 +08:00
parent 0c5254eb1b
commit 27e71d8c51
18 changed files with 448 additions and 17 deletions

View File

@@ -48,6 +48,8 @@ func run(args []string) error {
return runFlatten(args[1:])
case "pack":
return runPack(args[1:])
case "links":
return runLinks(args[1:])
case "impact":
return runImpact(args[1:])
case "message":
@@ -78,6 +80,7 @@ Usage:
gsp trace <id> [--root .] [--depth 3] [--out trace.json]
gsp flatten <id> [--root .] [--depth 3] [--include-type a,b] [--exclude-type a,b] [--out flattened.json]
gsp pack <id> [--root .] [--for implement] [--stage implement] [--depth 3] [--budget 12000] [--format json|md|canvas] [--out context-pack.json]
gsp links <id> [--root .] [--depth -1] [--format json|md] [--out links.json]
gsp impact <id> [--root .] [--depth -1] [--format json|md|canvas] [--out impact.json]
gsp message validate <file> [--root .] [--out message-report.json]
gsp graph [id] [--root .] [--depth 3] [--format json|mermaid|md|canvas] [--out graph.json]
@@ -85,6 +88,33 @@ Usage:
`)
}
func runLinks(args []string) error {
fs := flag.NewFlagSet("links", flag.ContinueOnError)
root := commonRoot(fs)
out := commonOut(fs)
depth := fs.Int("depth", -1, "maximum relation depth; -1 means unlimited")
format := fs.String("format", "json", "json or md")
if err := fs.Parse(normalizeFlagArgs(args)); err != nil {
return err
}
if fs.NArg() != 1 {
return fmt.Errorf("links requires one GSP id")
}
project, err := gsp.LoadProject(*root)
if err != nil {
return err
}
result := project.Links(fs.Arg(0), *depth)
switch *format {
case "json":
return writeJSON(*out, result)
case "md":
return writeText(*out, result.Markdown())
default:
return fmt.Errorf("unsupported links format %q", *format)
}
}
func runCompletion(args []string) error {
if len(args) == 0 {
return fmt.Errorf("completion requires powershell, bash, zsh, fish, or install powershell")