Summary
Provide a helper API to hydrate context lines for ranked results, simplifying CLI/orchestrator code that needs to render snippets.
Motivation
- Multiple callers (CLI, agents) need to read files and extract
n_lines context around a matched line.
- Centralizing this logic improves consistency and reduces duplication.
Proposed API (Rust)
// File: src/workspace/store.rs
use anyhow::Result;
use crate::workspace::store::RankedLine;
pub async fn hydrate_context(
&self,
ranked: &[RankedLine],
n_lines: usize,
) -> Result<Vec<(RankedLine, Vec<String>)>> {
// Reads each file once, extracts [start..end) lines, returns alongside RankedLine
}
Notes
- This is an optional helper; not required for JSON output features.
search CLI could reuse it when --output json to include the lines field consistently for workspace-backed results.
Acceptance criteria
- Helper compiles and is covered by a basic test reading temp files.
- No change to defaults unless explicitly used by callers.
Summary
Provide a helper API to hydrate context lines for ranked results, simplifying CLI/orchestrator code that needs to render snippets.
Motivation
n_linescontext around a matched line.Proposed API (Rust)
Notes
searchCLI could reuse it when--output jsonto include thelinesfield consistently for workspace-backed results.Acceptance criteria