fix(cli): post-audit fixes (MCP MatchCount + sessions + auth + view)

Four unrelated shipped-code drifts found during v0.5 audit cycles:

1. MCP search_chunks tool omitted MatchCount from SearchParams. Server
   fell back to its default cap; agents asking for limit:50 silently
   got fewer results. Adds MatchCount: limit to the struct literal.

2. search sessions printed UpdatedAt as raw RFC3339 while session list
   used a fuzzy "X hours ago" render — same SDK field, two human
   renderings. Switches to the shared text.FuzzyAgoStr helper for
   parity.

3. auth status --json omitted three operationally-meaningful AuthUser
   fields (username, is_active, can_access_all_tenants). Agents
   branching on can_access_all_tenants previously needed a second
   round-trip.

4. session view Long help claimed the SDK doesn't wrap session_messages;
   it does (LoadMessages / GetMessagesBefore / GetRecentMessages all
   exist in client/message.go). Rewrites the comment to be accurate.
This commit is contained in:
nullkey
2026-05-16 01:22:27 +08:00
committed by lyingbug
parent 5b07c9ab87
commit 26fa43e2cc
6 changed files with 58 additions and 12 deletions
+1
View File
@@ -283,6 +283,7 @@ func addSearchChunks(server *mcpsdk.Server, svc knowledgeService) {
}
results, err := svc.HybridSearch(ctx, in.KBID, &sdk.SearchParams{
QueryText: in.Query,
MatchCount: limit,
VectorThreshold: in.VectorThreshold,
KeywordThreshold: in.KeywordThreshold,
})
+13
View File
@@ -334,6 +334,19 @@ func TestTool_SearchChunks_LimitCap(t *testing.T) {
}
}
// TestTool_SearchChunks_PassesMatchCountFromLimit is a regression guard for
// the v0.5 audit bug: the search_chunks dispatch built SearchParams without
// setting MatchCount, so the server fell back to its default cap and the
// client-side trim (results[:limit]) was a no-op when limit > server default.
// Verifies the limit arg is threaded into SearchParams.MatchCount.
func TestTool_SearchChunks_PassesMatchCountFromLimit(t *testing.T) {
svc := &fakeSvc{}
c, _ := newTestServer(t, svc)
callTool(t, c, "search_chunks", map[string]any{"kb_id": "kb_x", "query": "test", "limit": 50}, nil)
require.NotNil(t, svc.calls.hybridParams, "HybridSearch must be called with non-nil SearchParams")
assert.Equal(t, 50, svc.calls.hybridParams.MatchCount, "MCP search_chunks must thread limit into SearchParams.MatchCount")
}
func TestTool_Chat_AccumulateAnswerAndReferences(t *testing.T) {
svc := &fakeSvc{
kbStreamEvents: []*sdk.StreamResponse{