Ripgrep Context Builder

Fast code search with session.grep and session.glob lets you gather the relevant files and matching lines, then feed them into a prompt — a lightweight retrieval step before the agent reasons. Use this when you want to scope the agent to a specific slice of a large codebase instead of letting it explore from scratch.

Rust
Node.js
Python
Go
Rust
use a3s_code_core::Agent;
#[tokio::main]
async fn main() -> a3s_code_core::Result<()> {
let agent = Agent::new("agent.acl").await?;
let session = agent.session_builder(".").build().await?;
let files = session.glob("src/**/*.rs").await?;
let hits = session.grep("create_session").await?;
let context = format!(
"Files in scope:\n{}\n\nMatches for \"create_session\":\n{}",
files.join("\n"),
hits
);
let answer = session
.send(
&format!(
"Using only this context, explain how create_session is wired up:\n\n{context}"
),
None,
)
.await?;
println!("{}", answer.text);
session.close().await;
agent.close().await;
Ok(())
}

glob returns a list of matching file paths, while grep returns the raw ripgrep output as a single string. Both run locally and return quickly, so you can chain several searches to assemble context cheaply before spending a model turn. Pair them with session.readFile when you need the full body of a file rather than just the matching lines.