refactor(cli): align command surface with gh CLI conventions (ADR-3)
Audited the v0.0~v0.2 21-command surface against gh / kubectl / cargo /
npm / git / docker / flyctl / vercel / supabase / brew. WeKnora was
cherry-picking from multiple heritages, producing an inconsistent feel:
the kb subtree mixed gh verbs (create / delete / list) with a kubectl
verb (get); confirmation flag duplicated --force (docker/kubectl) with
global -y/--yes (gh/vercel/npm); the --agent flag stretched Stripe's
telemetry-tag pattern into a behavior-mode switch that no mainstream
CLI does.
ADR-3 picks gh as the primary north star. Documented deviations remain
for project-link (vercel/cargo), chat (openai-cli), context (kubectl-
light), and doctor (brew/flutter). The decision and its deviations are
documented self-contained in cli/AGENTS.md.
Surface changes:
- kb get → kb view (gh repo view convention); "get" kept as cobra Alias
for v0.0/v0.1 callers — see https://cli.github.com/manual/gh_repo_view.
- kb delete --force / doc delete --force removed in favor of the global
-y/--yes persistent flag (gh repo delete --yes convention). One
mechanism skips destructive prompts; ConfirmDestructive's parameter
renamed `force` → `yes` to match.
- --agent omnibus mode-switch removed. Stripe's DetectAIAgent (the
cited inspiration) only tags User-Agent for telemetry, never flips
behavior; gh / kubectl / aws / docker / flyctl all decline this kind
of flag. The 7-env auto-detect list is reduced to the two entries
Stripe also recognizes (CLAUDECODE, CURSOR_AGENT) — the other five
had no agent-documented source. ApplyAgentSugar / ShouldUseAgentMode
and the dead --no-interactive / --no-progress globals are deleted
entirely.
- DetectAIAgent and SetAgentHelp annotations are kept: env detection
now only triggers AGENT-targeted help text rendering (no behavior
change), matching Stripe's narrower scope.
Tests: 27 cli packages green (acceptance/contract still pins kb get
golden; the alias keeps it valid).
This commit is contained in:
+6
-9
@@ -42,7 +42,7 @@ func Execute() int {
|
||||
return 0
|
||||
}
|
||||
err = MapCobraError(err)
|
||||
if agent.ShouldUseAgentMode(cmd) || WantsJSONOutput(cmd) {
|
||||
if WantsJSONOutput(cmd) {
|
||||
cmdutil.PrintErrorEnvelope(iostreams.IO.Out, err)
|
||||
} else {
|
||||
cmdutil.PrintError(iostreams.IO.Err, err)
|
||||
@@ -143,7 +143,7 @@ func NewRootCmd(f *cmdutil.Factory) *cobra.Command {
|
||||
hybrid searches against a WeKnora server from your shell or an AI agent.`,
|
||||
Example: ` weknora auth login --host=https://kb.example.com # one-time setup
|
||||
weknora kb list # list knowledge bases
|
||||
weknora kb get <id> # show one
|
||||
weknora kb view <id> # show one
|
||||
weknora search "your question" --kb=<id> # hybrid retrieval
|
||||
weknora doctor --json # health check (agent-readable)`,
|
||||
SilenceUsage: true,
|
||||
@@ -154,7 +154,6 @@ hybrid searches against a WeKnora server from your shell or an AI agent.`,
|
||||
// subcommand still owns the richer `--json` envelope output.
|
||||
Version: fmt.Sprintf("%s (commit %s, built %s)", v, commit, date),
|
||||
PersistentPreRun: func(c *cobra.Command, args []string) {
|
||||
agent.ApplyAgentSugar(c)
|
||||
// Propagate the global --context flag into the Factory for this
|
||||
// invocation only. Spec §1.2: single-shot override, no disk write.
|
||||
if v, _ := c.Flags().GetString("context"); v != "" {
|
||||
@@ -196,20 +195,18 @@ hybrid searches against a WeKnora server from your shell or an AI agent.`,
|
||||
// v0.7's compat probe consumer.
|
||||
func addGlobalFlags(cmd *cobra.Command) {
|
||||
pf := cmd.PersistentFlags()
|
||||
pf.Bool("agent", false, "Agent mode: envelope JSON output + no interactive prompts + no progress UI")
|
||||
pf.Bool("no-interactive", false, "Refuse interactive prompts; missing input becomes a hard error")
|
||||
pf.Bool("no-progress", false, "Suppress progress bars and spinners")
|
||||
pf.BoolP("yes", "y", false, "Skip confirmation prompts on destructive operations")
|
||||
pf.String("context", "", "Override the active context for this invocation (no disk write)")
|
||||
}
|
||||
|
||||
// agentAwareHelpFunc wraps cobra's default help to append the AI agent guidance
|
||||
// (Annotations[agent.AIAgentHelpKey]) only when agent mode is active.
|
||||
// Stripe pkg/cmd/templates.go pattern.
|
||||
// (Annotations[agent.AIAgentHelpKey]) only when an AI coding agent env var is
|
||||
// detected (CLAUDECODE / CURSOR_AGENT). Help-only render — no behavior switch.
|
||||
// Stripe pkg/cmd/templates.go pattern, but reduced from mode-switch (v0.2 ADR-3).
|
||||
func agentAwareHelpFunc(orig func(*cobra.Command, []string)) func(*cobra.Command, []string) {
|
||||
return func(c *cobra.Command, args []string) {
|
||||
orig(c, args)
|
||||
if !agent.ShouldUseAgentMode(c) {
|
||||
if agent.DetectAIAgent() == "" {
|
||||
return
|
||||
}
|
||||
extra := agent.FormatAgentGuidance(c)
|
||||
|
||||
Reference in New Issue
Block a user