feat: add ref (commit SHA) to search and symbol navigation results
Fixes : #1173
[FR] Add ref to search results #1173
Description
This PR addresses issue #1173 by returning the git ref (commit SHA) in search results, symbol definitions, and symbol references. This allows clients and AI agents to fetch stable file references at the exact matching commit via /api/source later.
Additionally, this PR resolves local repository setup and indexing compatibility bugs on Windows OS when paths contain spaces.
Key Changes
1. Schema Enhancements
- Added
refas an optional string in search (searchFileSchema) and symbol navigation (findRelatedSymbolsResponseSchema) schemas. - Regenerated OpenAPI specs (
sourcebot-public.openapi.json) to reflect the newreffield.
2. Result Mapping
- Mapped the Zoekt search
versionfield (which stores the commit SHA) to thereffield in search response parsing. - Passed the mapped
refcleanly through the definitions and references endpoints.
3. Agent Tools Update
- Updated the
findSymbolDefinitionsandfindSymbolReferencesagent tools to usefile.refas their revision instead of hardcoding"HEAD".
4. Windows Compatibility Bug Fixes
- Used
fileURLToPathwith a fallback mechanism inrepoCompileUtils.tsandshared/src/utils.tsto prevent path parsing errors (such asPath /C:/... does not exist) on Windows. - Added double quotes around the
-indexpath and repository source path inzoekt-git-indexCLI commands to support directories containing spaces (e.g.Open Source). - Mapped repository
path.joincalls topath.posix.jointo enforce forward-slash/URI separators consistently across all operating systems.
Verification & Testing
- Automated Tests: Ran the full workspace tests (
yarn test). All 884 tests passed successfully. - Integration Test: Verified that the local server successfully indexes local directories on Windows.
- API Test: Verified that queries to
/api/find_referencesreturn the correct commit SHA (ref) in the JSON output:"files": [ { "fileName": "packages\\web\\src\\features\\codeNav\\api.ts", "repository": "github.com\\Amresh-01\\sourcebot", "ref": "4ec87e1cc721341d51c1b9e8e03fbe7ea8289f3b" } ]
Summary by CodeRabbit
-
New Features
- Public search and symbol APIs now include a per-file git commit SHA ("ref") in responses.
-
Bug Fixes
- More consistent cross-platform path handling and safer command-line argument quoting.
-
Tests
- Added tests verifying symbol search/definition behavior includes file commit refs.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 50ccdd10-9d71-4404-abcd-23ff273be82a
📥 Commits
Reviewing files that changed from the base of the PR and between df90ef47a633ef2cb3718ff1fc354bef77afc528 and 289ee7b808d6cd42be8d1a55c8adf1f32fa51171.
📒 Files selected for processing (1)
docs/api-reference/sourcebot-public.openapi.json
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/api-reference/sourcebot-public.openapi.json
Walkthrough
This PR propagates git ref/commit SHA information across the system and standardizes repository path handling. It updates public API schemas to include ref fields, normalizes all repository path derivation to use POSIX path joining, fixes file:// URL-to-filesystem path conversion, and threads the ref value through search responses, CodeNav APIs, and symbol tools with comprehensive tests.
Changes
Git Ref Propagation and Path Normalization
| Layer / File(s) | Summary |
|---|---|
Public API Response Schemas with ref docs/api-reference/sourcebot-public.openapi.json |
PublicSearchResponse and PublicFindSymbolsResponse schemas add optional ref string field representing the git commit SHA for each file chunk and file item respectively. |
Backend Repository Path Normalization packages/backend/src/repoCompileUtils.ts |
All repository compile functions (GitHub, GitLab, Gitea, Gerrit, Bitbucket, generic, Azure DevOps) switch to path.posix.join for consistent forward-slash repo names. File:// URLs derive normalized folderPath via fileURLToPath with try/catch fallback, used for globbing and logging. |
Shared File URL-to-Filesystem Path Conversion packages/shared/src/utils.ts |
getRepoPath utility correctly converts file: protocol clone URLs to filesystem paths using fileURLToPath instead of pathname, with proper character normalization and JSDoc. |
Zoekt Command Argument Quoting packages/backend/src/zoekt.ts |
zoekt-git-index command construction quotes all dynamic arguments (index cache directory, branches, repository path) for shell robustness; JSDoc added for indexGitRepository. |
Search Response Processing with ref Field packages/web/src/features/search/types.ts, packages/web/src/features/search/zoektSearcher.ts |
searchFileSchema and transformZoektSearchResponse add ref field sourced from zoekt file.version, propagating commit SHA through the search pipeline. |
CodeNav API Integration with ref and Tests packages/web/src/features/codeNav/types.ts, packages/web/src/features/codeNav/api.ts, packages/web/src/features/codeNav/api.test.ts |
findRelatedSymbolsResponseSchema adds optional ref field, parseRelatedSymbolsSearchResponse maps ref in file results, and Vitest suite verifies both findSearchBasedSymbolReferences and findSearchBasedSymbolDefinitions propagate commit SHA from search responses. |
Tool Metadata with Per-File Revision packages/web/src/features/tools/findSymbolDefinitions.ts, packages/web/src/features/tools/findSymbolReferences.ts |
find_symbol_definitions and find_symbol_references now record each file's revision from file.ref when available, falling back to tool default (HEAD), enabling correct commit SHA in tool metadata and derived sources. |
Sequence Diagram
sequenceDiagram
participant Test as CodeNav api.test.ts
participant API as findSearchBasedSymbolReferences/Definitions
participant Search as search
participant Parser as parseRelatedSymbolsSearchResponse
Test->>API: call symbol lookup
API->>Search: execute search query
Search-->>API: files with ref
API->>Parser: parse search response
Parser-->>API: files[] including ref
API-->>Test: FindRelatedSymbolsResponse
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- sourcebot-dev/sourcebot#1066: Both PRs modify
docs/api-reference/sourcebot-public.openapi.json's symbol/navigation search response schemas (the retrieved PR reshapes/addsPublicFindSymbolsResponse/search models, while this PR addsreffields toPublicSearchResponseandPublicFindSymbolsResponse).
Suggested reviewers
- msukkari
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately summarizes the main objective of the changeset: adding git ref/commit SHA to search and symbol navigation results across multiple API endpoints and responses. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@brendan-kellam and @msukkari Please Review this PR
@brendan-kellam and @msukkari Please Review this PR