Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"core",
"exec",
"execpolicy",
"file-search",
"linux-sandbox",
"login",
"mcp-client",
Expand Down
20 changes: 20 additions & 0 deletions codex-rs/file-search/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "codex-file-search"
version = { workspace = true }
edition = "2024"

[[bin]]
name = "codex-file-search"
path = "src/main.rs"

[lib]
name = "codex_file_search"
path = "src/lib.rs"

[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive"] }
ignore = "0.4.23"
nucleo-matcher = "0.3.1"
serde_json = "1.0.110"
tokio = { version = "1", features = ["full"] }
5 changes: 5 additions & 0 deletions codex-rs/file-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# codex_file_search

Fast fuzzy file search tool for Codex.

Uses <https://crates.io/crates/ignore> under the hood (which is what `ripgrep` uses) to traverse a directory (while honoring `.gitignore`, etc.) to produce the list of files to search and then uses <https://crates.io/crates/nucleo-matcher> to fuzzy-match the user supplied `PATTERN` against the corpus.
38 changes: 38 additions & 0 deletions codex-rs/file-search/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::num::NonZero;
use std::path::PathBuf;

use clap::ArgAction;
use clap::Parser;

/// Fuzzy matches filenames under a directory.
#[derive(Parser)]
#[command(version)]
pub struct Cli {
/// Whether to output results in JSON format.
#[clap(long, default_value = "false")]
pub json: bool,

/// Maximum number of results to return.
#[clap(long, short = 'l', default_value = "64")]
pub limit: NonZero<usize>,

/// Directory to search.
#[clap(long, short = 'C')]
pub cwd: Option<PathBuf>,

// While it is common to default to the number of logical CPUs when creating
// a thread pool, empirically, the I/O of the filetree traversal offers
// limited parallelism and is the bottleneck, so using a smaller number of
// threads is more efficient. (Empirically, using more than 2 threads doesn't seem to provide much benefit.)
//
/// Number of worker threads to use.
#[clap(long, default_value = "2")]
pub threads: NonZero<usize>,

/// Exclude patterns
#[arg(short, long, action = ArgAction::Append)]
pub exclude: Vec<String>,

/// Search pattern.
pub pattern: Option<String>,
}
Loading