feat(cli): agent-first WeKnora CLI

The `weknora` command-line client for the WeKnora RAG server. Full command
surface: kb / doc / chunk / session / message / agent / model / search / chat /
auth / profile / link / api / mcp / skills / config / doctor / schema /
exit-codes.

Agent-first wire contract: JSON envelope by default, typed error codes mapped to
stable exit codes, error.retry_argv / retryable / partial-failure status,
global --dry-run preview, the exit-10 confirmation protocol for writes, and
control/ANSI/Bidi input hygiene. Stateless env-credential auth
(WEKNORA_API_KEY / WEKNORA_TOKEN + WEKNORA_HOST) for headless/CI/agent use.
A curated read-only MCP tool surface (`mcp serve`) and embedded Agent Skills
(`skills install`). Extensive unit + contract-golden tests and CI.
This commit is contained in:
nullkey
2026-06-26 20:40:59 +08:00
committed by lyingbug
parent 445a4330fa
commit 6f8b825f5f
151 changed files with 7305 additions and 733 deletions
+42
View File
@@ -271,3 +271,45 @@ func TestList_AllPages_WithLimit_StopsAtLimit(t *testing.T) {
assert.Equal(t, 50, got)
assert.LessOrEqual(t, len(svc.calls), 3, "must not fetch beyond what fills --limit")
}
// TestList_JSON_TotalCount_SinglePage asserts that meta.total_count is populated
// from the server total when doing a single-page fetch.
func TestList_JSON_TotalCount_SinglePage(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &fakeListService{
items: []sdk.Session{{ID: "s_1", Title: "T1", UpdatedAt: "2026-05-12T14:00:00Z"}},
total: 42,
}
require.NoError(t, runList(context.Background(),
&ListOptions{PageSize: 10, Limit: 30},
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc))
body := out.String()
assert.Contains(t, body, `"total_count":42`, "single-page fetch must surface server total in meta.total_count")
}
// TestList_JSON_TotalCount_AllPages asserts meta.total_count is populated
// from the server total when walking all pages.
func TestList_JSON_TotalCount_AllPages(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &pagedSessionSvc{all: makeSessions(45)}
require.NoError(t, runList(context.Background(),
&ListOptions{PageSize: 20, AllPages: true, Limit: 10000},
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc))
body := out.String()
assert.Contains(t, body, `"total_count":45`, "--all-pages fetch must surface server total in meta.total_count")
}
// TestList_JSON_TotalCount_Zero_Present asserts that when server returns total=0
// on an empty list, meta.total_count (and meta.count) still serialize as 0. The
// *int + omitempty pattern omits only nil, so the agent contract stays stable:
// an empty result reports 0, not a missing key.
func TestList_JSON_TotalCount_Zero_Present(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &fakeListService{items: nil, total: 0}
require.NoError(t, runList(context.Background(),
&ListOptions{PageSize: 30, Limit: 30},
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc))
body := out.String()
assert.Contains(t, body, `"total_count":0`, "zero server total must serialize as 0 on empty list")
assert.Contains(t, body, `"count":0`, "empty list must report count:0, not omit it")
}