Skip to main content

harness_grep/
lib.rs

1//! Grep tool — Rust port of `@agent-sh/harness-grep`.
2//!
3//! Conforms to `agent-knowledge/design/grep.md` (language-neutral spec).
4//! Public surface mirrors the TS package: `grep(params, session)`
5//! returns a discriminated `GrepResult` union. Alias pushback, zero-match
6//! hint, `NOT_FOUND` with fuzzy siblings, `INVALID_REGEX` with escape
7//! hint — all carry over.
8//!
9//! Engine: BurntSushi/ripgrep's library form (`grep-searcher` + `grep-regex`)
10//! and `ignore` for .gitignore-aware file walking. No WASM, no shell-out.
11
12mod constants;
13mod engine;
14mod fence;
15mod format;
16mod schema;
17mod suggest;
18mod types;
19
20pub use constants::*;
21pub use engine::{default_engine, GrepEngine, GrepEngineInput};
22pub use format::{format_content, format_count, format_files_with_matches};
23pub use schema::{
24    parse_grep_params, safe_parse_grep_params, GrepParams, GrepParseError,
25    GREP_TOOL_DESCRIPTION, GREP_TOOL_NAME,
26};
27pub use suggest::suggest_siblings;
28pub use types::{
29    ContentMeta, ContentResult, CountMeta, CountResult, ErrorResult,
30    FilesMatchMeta, FilesMatchResult, GrepOutputMode, GrepResult,
31    GrepSessionConfig, RgCount, RgMatch,
32};
33
34/// Top-level entry point. Parse + fence + engine + format, returning a
35/// discriminated result shape. This is the `grep()` function from the TS
36/// package, same contract.
37pub async fn grep(
38    params: serde_json::Value,
39    session: &GrepSessionConfig,
40) -> GrepResult {
41    run::run(params, session).await
42}
43
44mod run;