feat(cli): --log-level + kb/agent status & check + cross-cutting refactor

Operability surface and the bulk of the jopts→fopts migration:

* --log-level error|warn|info|debug + WEKNORA_LOG_LEVEL env, wired to
  the SDK via client.SetDebugLevel. Invalid --log-level returns FlagError
  (exit 2).
* kb status <kb-id> / kb check <kb-id> verb split (1 HTTP vs 1+N for
  failed_count aggregation).
* agent status <agent-id> / agent check <agent-id> verb split
  (probes kb_scope_all_reachable via 1+N HTTP).
* kb create <name> positional (matches agent create).
* Positional id help strings namespaced (<kb-id> / <agent-id>).
* All auth / context / link / doctor / kb / agent CRUD commands migrated
  to the FormatOptions API.
* root.go Execute(ctx) takes a context so signal-cancellation propagates
  via cmd.Context() into long-running commands.
* Pagination termination uses len(accum) >= total (not page*pageSize)
  so server-capped page sizes do not truncate aggregations.
This commit is contained in:
nullkey
2026-05-18 01:38:16 +08:00
committed by lyingbug
parent 7eeb3bec5d
commit 0e081aec5c
64 changed files with 1581 additions and 393 deletions
+5 -5
View File
@@ -65,7 +65,7 @@ func TestLink_ByID(t *testing.T) {
f := newFactory("default", nil)
opts := &Options{KB: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa"}
require.NoError(t, runLink(context.Background(), opts, nil, f))
require.NoError(t, runLink(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, f))
linkPath := filepath.Join(dir, ".weknora", "project.yaml")
p, err := projectlink.Load(linkPath)
@@ -87,7 +87,7 @@ func TestLink_ByName(t *testing.T) {
cli := sdk.NewClient(srv.URL)
f := newFactory("default", cli)
opts := &Options{KB: "foo"}
require.NoError(t, runLink(context.Background(), opts, nil, f))
require.NoError(t, runLink(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, f))
p, err := projectlink.Load(filepath.Join(dir, ".weknora", "project.yaml"))
require.NoError(t, err)
@@ -103,7 +103,7 @@ func TestLink_KBNotFound(t *testing.T) {
cli := sdk.NewClient(srv.URL)
f := newFactory("default", cli)
opts := &Options{KB: "missing"}
err := runLink(context.Background(), opts, nil, f)
err := runLink(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, f)
require.Error(t, err)
var typed *cmdutil.Error
require.ErrorAs(t, err, &typed)
@@ -123,7 +123,7 @@ func TestLink_OverwritesExisting(t *testing.T) {
f := newFactory("default", nil)
opts := &Options{KB: "22222222-2222-4222-8222-222222222222"}
require.NoError(t, runLink(context.Background(), opts, nil, f))
require.NoError(t, runLink(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, f))
p, err := projectlink.Load(linkPath)
require.NoError(t, err)
@@ -140,7 +140,7 @@ func TestLink_NonInteractive_NoKB(t *testing.T) {
f := newFactory("default", nil)
opts := &Options{} // no KB
err := runLink(context.Background(), opts, nil, f)
err := runLink(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, f)
require.Error(t, err)
var typed *cmdutil.Error
require.ErrorAs(t, err, &typed)