WeKnora/cli/internal/cmdutil
nullkey d54a7a5834 feat(cli): search verb-noun subtree (chunks/kb/docs/sessions)
Roadmap 3-1. Verb-noun shape borrowed from gh search (gh search repos
/ code / commits / issues / prs verified against the gh manual).

Subcommands:
- `search chunks "<q>" --kb X` — hybrid retrieval (RAG search).
- `search kb "<q>"` — case-insensitive substring match across KB names
  and descriptions; sorted by name length (shortest hits first).
- `search docs "<q>" --kb X` — pages through ListKnowledge filtering by
  title / file_name; stops once --limit matches are found.
- `search sessions "<q>"` — pages through GetSessionsByTenant filtering
  by title / description.

kb / docs / sessions are client-side filters because the server has no
fuzzy search endpoint for any of them. ListKnowledgeBases returns the
full tenant catalog in one call; the doc/session walkers chunk at 200
per request and stop early on limit.

The parent `search` command is a pure dispatcher — there is no bare-
positional form (no `weknora search "<q>"`).

Cleanups surfaced by the post-commit reviewer round:
- UX consistency: search docs's displayDocName ordered Title →
  FileName → "-", while doc list's displayName uses FileName → Title
  → ID. Same Knowledge rendered differently across commands. Aligned
  search docs on doc list's existing FileName-first convention.
- cmdutil.ResolveKBFlag(ctx, lister, raw) — extracted the
  `IsKBID ? raw : ResolveKBNameToID` block duplicated across chunks
  and docs.
- text.ContainsFold(needle, fields...) — replaces inline
  `strings.Contains(strings.ToLower(field), needle)` patterns.

37 unit tests across chunks/kb/docs/sessions plus the parent
registration smoke-test.

Roadmap: 3-1.
2026-05-14 10:57:17 +08:00
..
authrefresh.go feat(cli): auth refresh + transparent 401 retry transport 2026-05-14 10:57:17 +08:00
authretry.go feat(cli): auth refresh + transparent 401 retry transport 2026-05-14 10:57:17 +08:00
authretry_test.go feat(cli): auth refresh + transparent 401 retry transport 2026-05-14 10:57:17 +08:00
confirm.go feat(cli): add agent-first affordance — envelope, exit-10, --dry-run 2026-05-12 13:20:42 +08:00
dryrun.go feat(cli): add agent-first affordance — envelope, exit-10, --dry-run 2026-05-12 13:20:42 +08:00
errors.go refactor(cli): align command surface with mainstream conventions 2026-05-12 13:20:42 +08:00
errors_codes_test.go feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6) 2026-05-09 12:18:01 +08:00
errors_test.go feat(cli): scaffold weknora CLI module foundation (PR-1) 2026-05-07 23:19:46 +08:00
exit.go refactor(cli): align command surface with mainstream conventions 2026-05-12 13:20:42 +08:00
exit_test.go feat(cli): scaffold weknora CLI module foundation (PR-1) 2026-05-07 23:19:46 +08:00
exporter.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00
exporter_test.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00
factory.go feat(cli): auth refresh + transparent 401 retry transport 2026-05-14 10:57:17 +08:00
factory_test.go fix(cli): correct KB id detection, SSE terminal-frame, and CI test isolation 2026-05-12 13:20:42 +08:00
host.go feat(cli): context CRUD 2026-05-14 10:57:17 +08:00
kb.go feat(cli): search verb-noun subtree (chunks/kb/docs/sessions) 2026-05-14 10:57:17 +08:00
options.go chore(cli): remove unused v0.0 scaffolding 2026-05-12 13:20:42 +08:00