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:
@@ -92,6 +92,11 @@ to stop after one page.`,
|
||||
cmd.Flags().IntVar(&opts.PageSize, "page-size", sessionsPageSize, "Items per server batch (1..1000)")
|
||||
cmd.Flags().BoolVar(&opts.AllPages, "all-pages", true, "Walk every server page until exhausted or --limit hit")
|
||||
cmdutil.AddFormatFlag(cmd, sessionsSearchFields...)
|
||||
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
|
||||
UsedFor: "Find chat sessions by title or description (client-side case-insensitive substring match). Results come with meta.count; use --limit to cap and --all-pages=false to stop after one page.",
|
||||
Examples: []string{`weknora search sessions "onboarding" --format json`},
|
||||
Output: "envelope.data is an array of Session objects with id, title, updated_at; meta.count is the returned count; meta.has_more=true if more matched than --limit",
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -117,7 +122,8 @@ func runSessionsSearch(ctx context.Context, opts *SessionsSearchOptions, fopts *
|
||||
for _, s := range items {
|
||||
if matchSession(s, needle) {
|
||||
matches = append(matches, s)
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -131,12 +137,16 @@ func runSessionsSearch(ctx context.Context, opts *SessionsSearchOptions, fopts *
|
||||
}
|
||||
done:
|
||||
sortSessionsByRecency(matches)
|
||||
truncated := opts.Limit > 0 && len(matches) > opts.Limit
|
||||
if truncated {
|
||||
matches = matches[:opts.Limit]
|
||||
}
|
||||
|
||||
if fopts.WantsJSON() {
|
||||
if matches == nil {
|
||||
matches = []sdk.Session{}
|
||||
}
|
||||
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