probe_code/
lib.rs

1//! # Probe
2//!
3//! Probe is an AI-friendly, fully local, semantic code search tool for large codebases.
4//!
5//! This crate provides both a command-line interface and a library that can be used
6//! programmatically in other Rust applications.
7//!
8//! ## Features
9//!
10//! - Semantic code search with intelligent ranking
11//! - Code block extraction with language-aware parsing
12//! - AST-based pattern matching for precise code structure search
13//!
14//! ## Examples
15//!
16//! ### Searching for code
17//!
18//! ```no_run
19//! use probe_code::search::{perform_probe, SearchOptions};
20//! use std::path::Path;
21//!
22//! // Create search options
23//! let options = SearchOptions {
24//!     path: Path::new("."),
25//!     queries: &vec!["function search".to_string()],
26//!     files_only: false,
27//!     custom_ignores: &[],
28//!     exclude_filenames: false,
29//!     reranker: "bm25",
30//!     frequency_search: true,
31//!     exact: false,
32//!     language: None,
33//!     max_results: Some(10),
34//!     max_bytes: None,
35//!     max_tokens: Some(10000),
36//!     allow_tests: false,
37//!     no_merge: false,
38//!     merge_threshold: None,
39//!     dry_run: false,
40//!     session: None,
41//!     timeout: 30,
42//! };
43//!
44//! let results = perform_probe(&options).unwrap();
45//! println!("Found {} results", results.results.len());
46//! ```
47//!
48//! ### Extracting code blocks
49//!
50//! ```no_run
51//! use probe_code::extract::{handle_extract, ExtractOptions};
52//!
53//! let options = ExtractOptions {
54//!     files: vec!["src/main.rs".to_string()],
55//!     custom_ignores: vec![],
56//!     context_lines: 0,
57//!     format: "text".to_string(),
58//!     from_clipboard: false,
59//!     input_file: None,
60//!     to_clipboard: false,
61//!     dry_run: false,
62//!     diff: false,
63//!     allow_tests: false,
64//!     keep_input: false,
65//!     prompt: None,
66//!     instructions: None,
67//! };
68//!
69//! handle_extract(options).unwrap();
70//! ```
71//!
72//! ### AST pattern matching
73//!
74//! ```no_run
75//! use probe_code::query::{perform_query, QueryOptions};
76//! use std::path::Path;
77//!
78//! // Using the lower-level perform_query function
79//! let options = QueryOptions {
80//!     path: Path::new("."),
81//!     pattern: "fn $NAME($$$PARAMS) { $$$BODY }",
82//!     language: Some("rust".to_string()),
83//!     ignore: &[],
84//!     allow_tests: false,
85//!     max_results: None,
86//!     format: "text".to_string(),
87//! };
88//!
89//! let matches = perform_query(&options).unwrap();
90//! println!("Found {} matches", matches.len());
91//! ```
92
93// Allow internal modules to reference the crate by its library name
94extern crate self as probe_code;
95
96pub mod extract;
97pub mod language;
98pub mod models;
99pub mod path_resolver;
100pub mod query;
101pub mod ranking;
102pub mod search;
103
104// Re-export commonly used types for convenience
105pub use extract::{
106    format_and_print_extraction_results, handle_extract, process_file_for_extraction,
107    ExtractOptions,
108};
109pub use models::{CodeBlock, LimitedSearchResults, SearchLimits, SearchResult};
110pub use path_resolver::resolve_path;
111pub use query::{
112    format_and_print_query_results, handle_query, perform_query, AstMatch, QueryOptions,
113};
114pub use search::{format_and_print_search_results, perform_probe, SearchOptions};
115
116// Tests are defined in their respective modules with #[cfg(test)]