feat(cli): add whoami / doctor / kb / context commands (PR-7)
5 new leaf commands wired into the root tree:
whoami — simplified `auth status` (user_id + tenant_id only)
doctor — 4-item self-check (base_url / auth / server_version / cred_storage)
with --offline / --no-cache flags + skip cascade + summary.all_passed
防 agent 看到 envelope.ok=true 误判命令整体 success
kb list — list KBs (default updated_at desc; 0 KB → "(no knowledge bases)")
tabwriter 4-col (ID/NAME/DOCS/UPDATED), display-width truncation
kb get — show single KB details (KEY: VALUE, suppress empty fields)
context use — switch default context (writes config.current_context),
带 levenshtein distance ≤ 2 的 did-you-mean hint
Each command uses the v0.0 narrow Service interface pattern (testable via
fakes), agent.SetAgentHelp for AI-friendly hints, and ClassifyHTTPError
for stable error code mapping.
cmdutil/errors.go: 新增 CodeLocalContextNotFound for `context use`,加入 AllCodes() 注册集.
cli/cmd/root.go: NewRootCmd 改为 exported (acceptance/contract 测试需要),
注册 4 个新命令 + 1 parent group; root_test.go 跟随更新.
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestRoot_Help(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
root := newRootCmd(cmdutil.New())
|
||||
root := NewRootCmd(cmdutil.New())
|
||||
root.SetArgs([]string{"--help"})
|
||||
root.SetOut(&out)
|
||||
require.NoError(t, root.Execute())
|
||||
@@ -26,7 +26,7 @@ func TestRoot_Help(t *testing.T) {
|
||||
|
||||
func TestVersion_JSON(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
root := newRootCmd(cmdutil.New())
|
||||
root := NewRootCmd(cmdutil.New())
|
||||
root.SetArgs([]string{"version", "--json"})
|
||||
root.SetOut(&out)
|
||||
require.NoError(t, root.Execute())
|
||||
@@ -50,7 +50,7 @@ func TestExecute_ExitCodeSurface(t *testing.T) {
|
||||
// provides them).
|
||||
func TestMapCobraError_PinnedPrefixes(t *testing.T) {
|
||||
t.Run("unknown command", func(t *testing.T) {
|
||||
root := newRootCmd(cmdutil.New())
|
||||
root := NewRootCmd(cmdutil.New())
|
||||
root.SetArgs([]string{"bogus"})
|
||||
root.SetErr(&bytes.Buffer{})
|
||||
root.SetOut(&bytes.Buffer{})
|
||||
|
||||
Reference in New Issue
Block a user