Adds enriched_text column to chunks table that prepends document title (and section header when present) to chunk text. Embeddings and FTS now use enriched text for better search relevance. Includes schema migration with backfill for existing data. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2.0 KiB
Context
The root cobra command in client/cmd/root.go uses cobra.ArbitraryArgs and its RunE handler to catch any arguments not matching a subcommand. Currently, any non-empty args are joined and submitted as a note. This means a single mistyped word (e.g., kb infow instead of kb info) silently creates a junk note in the knowledge base.
Goals / Non-Goals
Goals:
- Prevent single bare words from being silently ingested as notes
- Provide a clear error message that helps the user correct their input
- Preserve the multi-word implicit note shorthand (
kb remember to update dns)
Non-Goals:
- Detecting "close matches" to real commands (fuzzy matching / did-you-mean)
- Changing how quoted strings work at the shell level (we can't detect quotes after shell expansion)
Decisions
Guard on argument count in RunE
When len(args) == 1, reject with an error message instead of submitting as a note. When len(args) > 1, continue treating as implicit note shorthand.
Rationale: This is the simplest reliable heuristic. The shell strips quotes before cobra sees args, so we cannot distinguish kb "singleword" from kb singleword. However, single-word notes are rare in practice, and the error message tells the user how to work around it (use multiple words or the full note workflow). Multi-word input is almost certainly intentional note text, not a mistyped command.
Alternative considered: Checking against a list of known subcommand names — rejected because it wouldn't catch typos of commands we don't know about and adds maintenance burden.
Risks / Trade-offs
- Single-word notes no longer work via shorthand → Users must use
kb add --note "singleword"or include additional words. This is an acceptable trade-off since single-word notes are uncommon and the error message is clear. - Shell quote stripping means we can't be perfect →
kb "my note"with exactly one word after quote removal will be rejected. This is a known limitation but very rare in practice.