Skip to content

Conversation

@prosdev
Copy link
Collaborator

@prosdev prosdev commented Nov 23, 2025

πŸ› Bug

explore similar was searching the filename as text instead of reading and searching the file's content embeddings.

$ dev explore similar coordinator.ts
⚠ No similar code found  # Searched "coordinator.ts" as text ❌

βœ… Fix

Read file content and search its embeddings for semantic similarity.


πŸ“ Changes

1. Extracted File Utilities (cli/src/utils/file.ts)

Pure, testable functions:

  • resolveFilePath: Resolve paths relative to repo root
  • normalizeFilePath: Create relative paths
  • readFileContent: Read and validate file content
  • prepareFileForSearch: Prepare file for similarity search

2. 100% Test Coverage (cli/src/utils/file.test.ts)

22 unit tests covering:

  • Path resolution and normalization
  • File reading with validation
  • Error handling (missing, empty files)
  • Edge cases (special chars, large files, nested dirs)

3. Refactored explore similar

  • Uses new utilities for clean separation
  • Added --threshold option (default: 0.5)
  • Better error messages

πŸ§ͺ Verification

Before:

$ dev explore similar packages/core/src/vector/store.ts
⚠ No similar code found

After:

$ dev explore similar packages/core/src/vector/store.ts
βœ” Found 3 similar files

1. packages/core/src/vector/README.md (64.1% similar)
2. packages/core/src/vector/embedder.ts (61.7% similar)  
3. packages/core/src/scanner/README.md (56.8% similar)

Tests:

$ pnpm test packages/cli/src/utils/file.test.ts
βœ“ 22 tests passing βœ…

πŸ“Š Stats

  • +329 lines, -4 lines
  • 3 files changed
  • 22 new tests (100% coverage on utilities)
  • Follows testability philosophy (extract pure functions, test them)

πŸš€ Impact

Users can now find semantically similar code based on actual file content, not filenames. Feature works as intended!

Bug: explore similar searched filename as text β†’ 0 results
Fix: Read file content and search its embeddings

Changes:
- Extract file utilities (resolveFilePath, readFileContent, etc.)
- Add 22 unit tests for utilities (100% coverage)
- Refactor explore similar to use utilities
- Add --threshold option (default: 0.5)
- Improve error messages for missing/empty files

Before:
  $ dev explore similar file.ts
  ⚠ No similar code found  # searched "file.ts" as text

After:
  $ dev explore similar packages/core/src/vector/store.ts
  1. packages/core/src/vector/README.md (64.1% similar)
  2. packages/core/src/vector/embedder.ts (61.7% similar)

Tests: 22/22 passing βœ…
@prosdev prosdev merged commit 830051c into main Nov 23, 2025
1 check passed
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