refactor(cli): resource-command refactors — --kb resolver, MCP session_ask, session stop (BREAKING)

Unify the --kb resolver (accepts name or UUID) across kb/doc/chunk/session/
search/chat/link; `agent create` attaches knowledge bases via --attach-kb
(no longer --kb). Rename the MCP tool agent_invoke → session_ask and drop dead
MCP error codes. Add `session stop` (StopSession), completing the
start / continue-stream / stop triad.

Across these commands, bring the agent contract up to par: --dry-run previews
on mutations (incl. kb pin/unpin, session stop), agent-help blobs on the
read/health surface, accurate destructive-confirmation verbs, and search
has_more truncation signalling so an agent can tell its results were capped.
This commit is contained in:
nullkey
2026-05-29 20:06:30 +08:00
committed by lyingbug
parent a68cc59310
commit c90f4e895e
54 changed files with 807 additions and 93 deletions
+44
View File
@@ -193,3 +193,47 @@ func mustTime(t *testing.T, s string) time.Time {
require.NoError(t, err)
return v
}
// TestDocsSearch_HasMore asserts the meta.has_more truncation signal: true when
// more matches than --limit exist (over-fetch detects it, data trimmed to
// --limit), absent/false when the full result set fits. Mirrors the list
// commands' contract so an agent can tell its search was capped.
func TestDocsSearch_HasMore(t *testing.T) {
page := make([]sdk.Knowledge, 10)
for i := range page {
page[i] = sdk.Knowledge{ID: "match", Title: "needle"}
}
type meta struct {
Count int `json:"count"`
HasMore bool `json:"has_more"`
}
parse := func(t *testing.T, s string) meta {
var env struct {
Meta meta `json:"meta"`
}
require.NoError(t, json.Unmarshal([]byte(s), &env), "got %q", s)
return env.Meta
}
t.Run("truncated -> has_more true, data trimmed", func(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &fakeDocsSearchSvc{pages: map[int][]sdk.Knowledge{1: page}, total: 10}
require.NoError(t, runDocsSearch(context.Background(),
&DocsSearchOptions{Query: "needle", KBID: "kb1", Limit: 3, PageSize: docsPageSize, AllPages: true},
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc))
m := parse(t, out.String())
assert.Equal(t, 3, m.Count, "data must be trimmed to --limit")
assert.True(t, m.HasMore, "has_more must be true when results exceed --limit")
})
t.Run("fits -> has_more false", func(t *testing.T) {
out, _ := iostreams.SetForTest(t)
svc := &fakeDocsSearchSvc{pages: map[int][]sdk.Knowledge{1: page[:2]}, total: 2}
require.NoError(t, runDocsSearch(context.Background(),
&DocsSearchOptions{Query: "needle", KBID: "kb1", Limit: 20, PageSize: docsPageSize, AllPages: true},
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc))
m := parse(t, out.String())
assert.Equal(t, 2, m.Count)
assert.False(t, m.HasMore, "has_more must be false/absent when results fit under --limit")
})
}