Skip to content

feat: add ctx similar — pre-implementation reuse check#3

Merged
saldestechnology merged 3 commits into
mainfrom
feat/similar
Jul 9, 2026
Merged

feat: add ctx similar — pre-implementation reuse check#3
saldestechnology merged 3 commits into
mainfrom
feat/similar

Conversation

@saldestechnology

Copy link
Copy Markdown
Collaborator

Summary

PR 5 of 7 in the Quality Intelligence Suite. Stacked on #2 (feat/quality-foundation) — will be retargeted to main once #2 merges; review only the top 2 commits until then.

  • New ctx similar "<description>" command: semantic search scoped to function/method symbols, enriched with fan_in (is this an established utility?) and a one-line brief (falling back to the docstring's first sentence), so a coding agent can decide to reuse instead of rewrite.
  • No embeddings → exit 2 with an actionable message (ctx embed, or use --keyword).
  • --keyword fallback routes to FTS5 hybrid_search — works offline with no API key.
  • --json emits the standard envelope (docs/json-output.md updated with per-mode score semantics); empty results still emit a valid envelope.
  • README: documents the intended agent workflow (run ctx similar before writing a new function).

Test plan

  • 11 new unit tests: kind scoping, similarity ordering with hand-crafted embeddings, no-embeddings error → exit-2 mapping, keyword path with zero embeddings, fan_in vs inserted calls edges, brief fallback, JSON payloads.
  • cargo test (191 green), clippy -D warnings, fmt --check, --no-default-features build — all clean; smoke-tested against a scratch project.

🤖 Generated with Claude Code

Thin wrapper over embedding search scoped to function/method symbols.
Each hit reports a one-line doc (brief, falling back to the first
sentence of the docstring), the similarity score, and fan-in so an
agent can judge whether an established utility already exists.

- Kind scoping via over-fetch (limit * 3) and filter; no schema changes
- Missing embeddings is an operational error (exit 2) with a hint to
  run 'ctx embed' or use --keyword
- --keyword routes to the FTS5 hybrid_search fallback that needs no
  embeddings or API key
- --json emits the standard envelope (command: similar) with an empty
  results array when nothing matches
- docs/json-output.md: 'similar' payload, score semantics per mode,
  and exit-code behavior
- README: command reference entry with the agent workflow (run
  'ctx similar' before writing a new function; reuse strong matches)
- CHANGELOG: Unreleased entry
@saldestechnology
saldestechnology deleted the branch main July 9, 2026 15:38
@saldestechnology
saldestechnology changed the base branch from feat/quality-foundation to main July 9, 2026 15:41
@saldestechnology
saldestechnology merged commit d8d51ae into main Jul 9, 2026
5 checks passed
@saldestechnology
saldestechnology deleted the feat/similar branch July 9, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant