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:
+13
-2
@@ -115,6 +115,12 @@ reached or the KB is exhausted. Pass --all-pages=false to stop after one page.`,
|
||||
cmd.Flags().BoolVar(&opts.AllPages, "all-pages", true, "Walk every server page until exhausted or --limit hit")
|
||||
cmdutil.AddFormatFlag(cmd, docsFields...)
|
||||
_ = cmd.MarkFlagRequired("kb")
|
||||
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
|
||||
UsedFor: "Find documents in a knowledge base by keyword (server-side LIKE filter on title/file_name). Results come with meta.count; use --limit to cap and --all-pages=false to stop after one page.",
|
||||
RequiredFlags: []string{"<query> (positional)", "--kb"},
|
||||
Examples: []string{`weknora search docs "spec" --kb engineering --format json`},
|
||||
Output: "envelope.data is an array of Knowledge objects with id, title, file_name, parse_status; meta.count is the returned count; meta.has_more=true if more matched than --limit",
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -139,7 +145,8 @@ func runDocsSearch(ctx context.Context, opts *DocsSearchOptions, fopts *cmdutil.
|
||||
}
|
||||
for _, k := range items {
|
||||
matches = append(matches, k)
|
||||
if opts.Limit > 0 && len(matches) >= opts.Limit {
|
||||
// Collect one past --limit so has_more is accurate; trimmed below.
|
||||
if opts.Limit > 0 && len(matches) > opts.Limit {
|
||||
goto done
|
||||
}
|
||||
}
|
||||
@@ -152,12 +159,16 @@ func runDocsSearch(ctx context.Context, opts *DocsSearchOptions, fopts *cmdutil.
|
||||
}
|
||||
done:
|
||||
sortKnowledgeByRecency(matches)
|
||||
truncated := opts.Limit > 0 && len(matches) > opts.Limit
|
||||
if truncated {
|
||||
matches = matches[:opts.Limit]
|
||||
}
|
||||
|
||||
if fopts.WantsJSON() {
|
||||
if matches == nil {
|
||||
matches = []sdk.Knowledge{}
|
||||
}
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user