Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

62 lines
2.0 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
)
var (
contextTask string
contextEntryPoint string
contextMaxSymbols int
contextFormat string
contextBudget int
contextIndex string
)
var contextCmd = &cobra.Command{
Use: "context [flags]",
Short: "Generate a portable context briefing for a task",
Long: `Runs export_context for the given task against the daemon that owns the
repo and renders the result as a self-contained markdown or JSON briefing.
Use for sharing context outside MCP — paste into Slack, PRs, docs, or other
AI tools. Requires a running daemon that tracks the repo.`,
RunE: runContext,
}
func init() {
contextCmd.Flags().StringVarP(&contextTask, "task", "t", "", "task description (required)")
contextCmd.Flags().StringVarP(&contextEntryPoint, "entry-point", "e", "", "symbol ID or file path to start from")
contextCmd.Flags().IntVarP(&contextMaxSymbols, "max-symbols", "n", 5, "max symbols to include")
contextCmd.Flags().StringVarP(&contextFormat, "format", "f", "markdown", "output format: markdown or json")
contextCmd.Flags().IntVar(&contextBudget, "token-budget", 2000, "approximate token budget for output")
contextCmd.Flags().StringVar(&contextIndex, "index", "", "repository path the daemon must track (default: current directory)")
_ = contextCmd.MarkFlagRequired("task")
rootCmd.AddCommand(contextCmd)
}
func runContext(cmd *cobra.Command, args []string) error {
repoPath := "."
if contextIndex != "" {
repoPath = contextIndex
} else if len(args) > 0 {
repoPath = args[0]
}
out, err := requireDaemonTool(repoPath, "export_context", map[string]any{
"task": contextTask,
"entry_point": contextEntryPoint,
"max_symbols": contextMaxSymbols,
"format": contextFormat,
"token_budget": contextBudget,
})
if err != nil {
return err
}
// export_context returns the rendered briefing (markdown or JSON) as
// the tool's text content; print it verbatim.
fmt.Fprintln(cmd.OutOrStdout(), string(out))
return nil
}