Files
Enterprise-Knowledge-Base/cli/internal/prompt/prompt.go
T
nullkey a39805aa89 feat(cli): scaffold weknora CLI module foundation (PR-1)
Empty cli/ Go module with Factory + Options skeleton that all v0.x commands
plug into.

Foundation packages (10 internal/):
- cmdutil: Factory(3 closure: Config/Client/Prompter) + Options + Errors
  with namespaced ErrorCode + typed predicates (IsAuthError / IsNotFound /
  IsTransient / IsAuthExpired) + Exporter + AddJSONFlags + ExitCode/PrintError
- iostreams: package singleton with TTY detection; ColorEnabled honors
  NO_COLOR / TERM=dumb on demand
- agent: mode + detect + annotations (Stripe pkg/useragent pattern;
  CLAUDECODE / CURSOR_AGENT / CODEX_* / AIDER_* / CONTINUE_* /
  OPENCODE_* / GEMINICODER env detection)
- build: ldflags-injected version/commit/date
- safepaths: separator-aware path-traversal protection
- config: yaml.v3 schema + atomic save 0600 (XDG-style)
- format: success/failure envelope (code/hint/request_id/risk/retryable/
  console_url) with typed RiskLevel
- prompt: Prompter interface + AgentPrompter (rejects in agent mode)
- secrets: file 0600 store with weknora:<context>:<key> namespace
- testutil: XDGTempDir(t) test helper

Smoke command: weknora version (-/--json). Build/test/vet matrix in
.github/workflows/cli.yml across linux x macos x windows x Go 1.24.

Factory.Client returns CodeLocalUnimplemented until PR-3 wires the SDK
adapter; PR-1 commands (version) don't need it.
2026-05-07 23:19:46 +08:00

33 lines
1.5 KiB
Go

// Package prompt defines the interactive-input abstraction.
//
// Production impl will use charmbracelet/huh in v0.0 commands that need
// password input (auth login). Foundation PR ships only the interface +
// a sentinel error so non-TTY contexts surface the right error.
package prompt
import "errors"
// ErrAgentNoPrompt is returned by any Prompter call made when the CLI is in
// agent / non-interactive mode. Commands should map this to a "missing flag"
// user error before returning to cobra.
var ErrAgentNoPrompt = errors.New("prompt: interactive input not available in agent/non-interactive mode")
// Prompter is the small abstraction the auth login flow needs. Tests inject
// scripted responses; production wires charmbracelet/huh.
type Prompter interface {
// Input collects free-form text input from the user.
Input(label, defaultValue string) (string, error)
// Password collects a secret without echoing.
Password(label string) (string, error)
// Confirm asks for yes/no confirmation, used by destructive commands.
Confirm(label string, defaultValue bool) (bool, error)
}
// AgentPrompter rejects all interactive calls. Use it as the Factory.Prompter
// closure result whenever agent mode is detected.
type AgentPrompter struct{}
func (AgentPrompter) Input(string, string) (string, error) { return "", ErrAgentNoPrompt }
func (AgentPrompter) Password(string) (string, error) { return "", ErrAgentNoPrompt }
func (AgentPrompter) Confirm(string, bool) (bool, error) { return false, ErrAgentNoPrompt }