f2e8e3f56c
Survey of 10 mainstream CLIs (gh, lark, stripe, vercel, supabase, aws, azure, gcloud, openai/codex, github-copilot-cli) showed env-gated per-command --help blurbs are a Stripe-only pattern; gh uses env detect for telemetry only, and lark relies on installed agent Skills + MCP. Our cmd/mcp/serve already covers the dominant 2025/26 path, so internal/aiclient/ (136 LOC + 38 callsites) is net maintenance burden without precedent. - Drop internal/aiclient/ entirely (annotations + detect + tests) - Remove 38 SetAgentHelp callsites + agentAwareHelpFunc / SetHelpFunc wiring in cmd/root.go - Migrate 4 command-level rules to standard Long help (visible to all, not env-gated): doc upload mode mutex, kb edit at-least-one, kb pin idempotent, search chunks channel mutex - Rewrite AGENTS.md as a developer guide (gh-style 6 H2 / 167 lines): audience preamble + Build / Architecture / Command Structure / Testing / Code Style / Error Handling. Drops sections absent in surveyed projects (Commit & PR Conventions, Who Uses This CLI) - Clean 14 internal doc refs (ADR-N, spec §X, v0.X) in source comments and docs that pointed at docs/superpowers/ — that directory is local-only / uncommitted, so refs are dead for outside readers - Drop forward-looking "once v0.2 ships" from README
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
// Package auth holds the cobra commands for authentication
|
|
// (login / logout / list / refresh / status / token).
|
|
package auth
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
|
)
|
|
|
|
// Credential-mode tokens used in the JSON output of auth list / login /
|
|
// status / token. The string names describe the HTTP credential type rather
|
|
// than the login flow (e.g. JWT → bearer regardless of whether it was
|
|
// obtained via password or refresh) so an agent can branch directly on the
|
|
// header to construct: `Authorization: Bearer <token>` (ModeBearer) or
|
|
// `X-API-Key: <token>` (ModeAPIKey).
|
|
const (
|
|
ModeBearer = "bearer"
|
|
ModeAPIKey = "api-key"
|
|
ModeUnknown = "unknown"
|
|
)
|
|
|
|
// modeFromRefs maps the per-context TokenRef / APIKeyRef presence to a
|
|
// canonical credential-mode token. Bearer wins when both are present -
|
|
// matches the precedence in cmdutil.buildClient.
|
|
func modeFromRefs(apiKeyRef, tokenRef string) string {
|
|
switch {
|
|
case tokenRef != "":
|
|
return ModeBearer
|
|
case apiKeyRef != "":
|
|
return ModeAPIKey
|
|
default:
|
|
return ModeUnknown
|
|
}
|
|
}
|
|
|
|
// NewCmdAuth builds the `weknora auth` command tree and registers its
|
|
// subcommands. Called from cli/cmd/root.go.
|
|
func NewCmdAuth(f *cmdutil.Factory) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "auth",
|
|
Short: "Manage authentication credentials and contexts",
|
|
// NoArgs makes cobra emit its canonical `unknown command "X" for
|
|
// "weknora auth"` for any positional, which mapCobraError tags as
|
|
// FlagError → exit 2. Run (not RunE) is required: a parent with
|
|
// neither Run nor RunE short-circuits to help and skips Args
|
|
// validation entirely.
|
|
Args: cobra.NoArgs,
|
|
Run: func(c *cobra.Command, _ []string) { _ = c.Help() },
|
|
}
|
|
cmd.AddCommand(NewCmdLogin(f, nil))
|
|
cmd.AddCommand(NewCmdLogout(f))
|
|
cmd.AddCommand(NewCmdList(f))
|
|
cmd.AddCommand(NewCmdRefresh(f))
|
|
cmd.AddCommand(NewCmdStatus(f))
|
|
cmd.AddCommand(NewCmdToken(f))
|
|
return cmd
|
|
}
|