RunContext handles the "codemap context" subcommand.
(args []string, root string)
| 78 | |
| 79 | // RunContext handles the "codemap context" subcommand. |
| 80 | func RunContext(args []string, root string) { |
| 81 | fs := flag.NewFlagSet("context", flag.ContinueOnError) |
| 82 | forPrompt := fs.String("for", "", "Pre-classify intent for this prompt") |
| 83 | compact := fs.Bool("compact", false, "Minimal output for token-constrained agents") |
| 84 | if err := fs.Parse(args); err != nil { |
| 85 | os.Exit(1) |
| 86 | } |
| 87 | |
| 88 | if fs.NArg() > 0 { |
| 89 | root = fs.Arg(0) |
| 90 | } |
| 91 | |
| 92 | absRoot, err := filepath.Abs(root) |
| 93 | if err != nil { |
| 94 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 95 | os.Exit(1) |
| 96 | } |
| 97 | |
| 98 | envelope := buildContextEnvelope(absRoot, *forPrompt, *compact) |
| 99 | |
| 100 | enc := json.NewEncoder(os.Stdout) |
| 101 | enc.SetIndent("", " ") |
| 102 | if err := enc.Encode(envelope); err != nil { |
| 103 | fmt.Fprintf(os.Stderr, "Error encoding context: %v\n", err) |
| 104 | os.Exit(1) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | func buildContextEnvelope(root, prompt string, compact bool) ContextEnvelope { |
| 109 | projCfg := config.Load(root) |
no test coverage detected