Repository navigation
Description
Context
The ProPR planner already retrieves repository files and matches prompts using relevance algorithms and indexed summaries (findRelevantFiles, scoreSemanticRelevance, file_summaries, directory_summaries), while git operations inspect commits and worktrees. However, there is no shared service that surfaces repository code search and file reading as clean, standalone primitives. Today, external clients (such as MCP agents) have no mechanism to read repository code or search files without pulling the entire repository locally. This task implements a unified repository retrieval service in @propr/core that reuses the planner's indexing and relevance engine for semantic search, provides literal git grep across the repository tree at any ref, and supports bounded file reading directly from git.
Requirements
- Create Repository Retrieval Service: Create
packages/core/src/services/repositoryRetrievalService.tsexporting typed options and result interfaces for search and file reading. - Implement
searchRepositoryFiles:- Accept parameters:
repository,query,mode('semantic' | 'literal', default'semantic'),branch/ref,pathprefix,caseSensitive,offset, andlimit. - Semantic Mode:
- Inspect indexing status in the
repositoriestable for the specified branch (indexing_status,last_indexed_at,last_indexed_hash). - Delegate to
findRelevantFilesusinguseSummaryScoring: trueand the default agent fromAgentRegistry. - Degrade gracefully if the repository is not yet indexed or if indexing is in progress by falling back to keyword and path scoring, returning an explicit freshness caveat in
freshness.caveat. - Return ranked file paths with relevance scores, matching reasons (
semantic,path-match,git-history), and pagination metadata (offset,limit,nextOffset,totalMatches).
- Inspect indexing status in the
- Literal Mode:
- Resolve the repository's local clone path via
ensureRepoCloned/resolveRepositoryClonePath. - Use
createHooklessGit(repoPath)to executegit.raw(['grep', '-n', '-I', ...])against the target ref. - Parse grep output into matching paths, match counts, and line matches.
- Return matching file paths and match counts without loading full file bodies, with pagination metadata.
- Resolve the repository's local clone path via
- Accept parameters:
- Implement
readRepositoryFileContent:- Accept parameters:
repository,path,ref/branch,startLine,endLine,maxLines,maxBytes. - Prevent directory traversal by rejecting paths containing
.., leading/, backslashes\, or null bytes\0. - Fetch the exact file content from the git object database at
ref:pathusingcreateHooklessGit(repoPath).show(). - Detect binary files (
\0byte) and throw a descriptive error with status 400. - Slice lines between
startLineandendLine, bounded bymaxLines(default 800) andmaxBytes(default 120,000). - Return file content, line counts, total bytes, and truncation status.
- Accept parameters:
- Public Core Exports: Export the service functions and types in
packages/core/src/index.ts. - Unit Test Suite: Implement unit tests in
packages/core/test/repositoryRetrievalService.test.tsverifying semantic search, literal grep parsing, chunked reading, and error conditions.
Implementation Specification
- File:
packages/core/src/services/repositoryRetrievalService.ts(new file) - File:
packages/core/src/index.ts(add export) - File:
packages/core/test/repositoryRetrievalService.test.ts(new file)
Acceptance Criteria
searchRepositoryFilesin semantic mode returns files scored and ranked by relevance with freshness metadata.- If the repository is not indexed or indexing is incomplete, semantic search returns results via fallback heuristics with an explicit caveat explaining index staleness.
searchRepositoryFilesin literal mode executes git grep at the requested ref, correctly filters by path prefix, handles case sensitivity, and returns empty results (not an error) when no matches are found.readRepositoryFileContentreads lines accurately withinstartLine/endLine, caps output atmaxLinesandmaxBytes, setstruncated: truewhen truncated, and rejects traversal or binary files with clear errors.- Unit tests in
packages/core/test/repositoryRetrievalService.test.tspass cleanly.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
This implementation introduces a centralized repository retrieval service within
@propr/corethat directly exposes the existing planner relevance pipeline (findRelevantFiles) and git tree inspection (createHooklessGit). Rather than duplicating relevance logic or spawning ad-hoc processes, we consolidate search and read operations into reusable domain primitives. For semantic search, we query database indexing metadata and invokefindRelevantFileswith AI-generated summary scoring, degrading gracefully to keyword and git-history scoring when the repository index is pending or stale. For literal search, we execute git grep against the repository tree at a specific ref, which bypasses the index entirely and guarantees commit-level freshness without requiring a checked-out worktree. For file reading, we usegit showto stream bounded line and byte slices directly from the object database, enforcing path sanitization and binary detection.File:
packages/core/src/services/repositoryRetrievalService.ts(new file)Why this file: This new service module centralizes all repository code retrieval logic for both semantic and literal modes. It bridges
findRelevantFiles, database index records, and git object inspection so that both backend planners and external MCP tools can search and read repository files through consistent, bounded interfaces.File:
packages/core/src/index.tsWhy this file:
packages/core/src/index.tsis the public API entry point for the@propr/corepackage. Re-exporting the repository retrieval service here makessearchRepositoryFilesandreadRepositoryFileContentavailable for the API layer (@propr/api), MCP handlers, and background tasks.File:
packages/core/test/repositoryRetrievalService.test.ts(new file)Why this file: Provides automated unit test coverage for the repository retrieval engine. It validates semantic search ranking, literal tree grep parsing, line-bounded chunk reading, binary file rejection, and path traversal protection.
propr-dev commentedon Oct 6, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52797/claude-opus-5-5-implement-core-repository-20261006-1219-gso2797-epic-repository-search-sgjissue-2797-20261006-1219-claude-opus-5-5-gso🔍 Track Task Execution