MCPcopy Create free account
hub / github.com/Tencent/WeKnora / SetAgentHelp

Function SetAgentHelp

cli/internal/cmdutil/agenthelp.go:42–65  ·  view source on GitHub ↗

SetAgentHelp attaches agent-targeted help metadata to a command. Routing: - WEKNORA_AGENT_HELP=1: emit the AgentHelp JSON blob to stdout and return — agents get clean parseable JSON, no trailing prose. - Otherwise (human help path): if cmd has risk annotations from SetRisk, prepend "Risk:

(cmd *cobra.Command, ah AgentHelp)

Source from the content-addressed store, hash-verified

40// prepend "Risk: <action> (<level>)" line; then render the normal human
41// help via origHelp; then append the "AI agents:" Warnings block.
42func SetAgentHelp(cmd *cobra.Command, ah AgentHelp) {
43 origHelp := cmd.HelpFunc()
44 cmd.SetHelpFunc(func(c *cobra.Command, args []string) {
45 if os.Getenv("WEKNORA_AGENT_HELP") == "1" {
46 emitAgentHelp(c.OutOrStdout(), ah)
47 return
48 }
49 // Prepend Risk: line in the default (human) branch only; the
50 // JSON branch above already carries warnings[]. Skip silently if
51 // the command has no risk annotations.
52 if level, action, ok := GetRisk(c); ok {
53 fmt.Fprintf(c.OutOrStdout(), "Risk: %s (%s)\n\n", action, level)
54 }
55 origHelp(c, args)
56 if len(ah.Warnings) > 0 {
57 w := c.OutOrStdout()
58 fmt.Fprintln(w)
59 fmt.Fprintln(w, "AI agents:")
60 for _, msg := range ah.Warnings {
61 fmt.Fprintln(w, "- "+msg)
62 }
63 }
64 })
65}
66
67func emitAgentHelp(w io.Writer, ah AgentHelp) {
68 enc := json.NewEncoder(w)

Callers 15

newVersionCmdFunction · 0.92
NewCmdUnlinkFunction · 0.92
NewCmdFunction · 0.92
newPinCmdFunction · 0.92
NewCmdStatusFunction · 0.92
NewCmdDeleteFunction · 0.92
NewCmdCheckFunction · 0.92
NewCmdEditFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdViewFunction · 0.92
NewCmdListFunction · 0.92
NewCmdStatusFunction · 0.92

Calls 2

emitAgentHelpFunction · 0.85
GetRiskFunction · 0.85