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
+8 -2
View File
@@ -79,6 +79,11 @@ content, use ` + "`weknora search chunks`" + `.`,
}
cmd.Flags().IntVarP(&opts.Limit, "limit", "L", 30, "Maximum results to return")
cmdutil.AddFormatFlag(cmd, kbSearchFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "Find knowledge bases by name or description (client-side case-insensitive substring match). Results come with meta.count; use --limit to cap. For searching content inside a KB, use 'search chunks' instead.",
Examples: []string{`weknora search kb "engineering" --format json`},
Output: "envelope.data is an array of KnowledgeBase objects with id, name, knowledge_count; meta.count is the returned count; meta.has_more=true if more matched than --limit",
})
return cmd
}
@@ -88,7 +93,8 @@ func runKBSearch(ctx context.Context, opts *KBSearchOptions, fopts *cmdutil.Form
return cmdutil.WrapHTTP(err, "list knowledge bases")
}
matches := filterKBs(items, opts.Query)
if opts.Limit > 0 && len(matches) > opts.Limit {
truncated := opts.Limit > 0 && len(matches) > opts.Limit
if truncated {
matches = matches[:opts.Limit]
}
@@ -96,7 +102,7 @@ func runKBSearch(ctx context.Context, opts *KBSearchOptions, fopts *cmdutil.Form
if matches == nil {
matches = []sdk.KnowledgeBase{}
}
meta := &output.Meta{Count: len(matches)}
meta := &output.Meta{Count: len(matches), HasMore: truncated}
return fopts.Emit(iostreams.IO.Out, matches, meta)
}
if len(matches) == 0 {