double_o/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2#![warn(missing_docs)]
3
4//! `oo` (double-o) — a context-efficient command runner for AI coding agents.
5//!
6//! This library helps AI agents run shell commands efficiently by classifying output
7//! and reducing context usage. Commands are executed, their output is analyzed, and
8//! results are compressed using pattern matching and intelligent categorization.
9//!
10//! # Core Concepts
11//!
12//! - **Classification**: Commands are categorized into four tiers based on success/failure
13//! and output size. Small successful outputs pass through verbatim, while large outputs
14//! are pattern-matched to extract terse summaries or indexed for later recall.
15//! - **Patterns**: Regular expressions define how to extract summaries from command output.
16//! Built-in patterns exist for common tools (pytest, cargo test, npm test, etc.).
17//! Custom patterns can be loaded from project-local `<git-root>/.oo/patterns/` or
18//! user-global TOML files in the user patterns directory (project patterns take precedence).
19//! - **Storage**: Large unpatterned outputs are stored in a searchable database (SQLite by
20//! default, with optional Vipune semantic search). Stored outputs can be recalled with
21//! full-text search.
22//! - **Categories**: Commands are auto-detected as Status (tests, builds, linters),
23//! Content (git show, diff, cat), Data (git log, ls, gh), or Unknown. This determines
24//! default behavior when no pattern matches.
25//!
26//! # Example
27//!
28//! ```
29//! use double_o::{classify, Classification, CommandOutput, Pattern};
30//! use double_o::pattern::builtins;
31//!
32//! // Run a command
33//! let args = vec!["echo".into(), "hello".into()];
34//! let output = double_o::exec::run(&args).unwrap();
35//!
36//! // Classify the output
37//! let command = "echo hello";
38//! let patterns = builtins(); // or load_user_patterns(&path)
39//! let result = classify(&output, command, &patterns);
40//!
41//! match result {
42//! Classification::Passthrough { output } => {
43//! println!("Output: {}", output);
44//! }
45//! Classification::Success { label, summary } => {
46//! println!("✓ {}: {}", label, summary);
47//! }
48//! Classification::Failure { label, output, .. } => {
49//! println!("✗ {}: {}", label, output);
50//! }
51//! Classification::Bounded { label, size, .. } => {
52//! println!("Bounded: {} ({} bytes)", label, size);
53//! }
54//! Classification::Large { label, size, .. } => {
55//! println!("Indexed: {} ({} bytes)", label, size);
56//! }
57//! }
58//! ```
59
60/// API key presence check for `oo learn`.
61pub mod api_key;
62/// OS-string argv helpers: lossy display and UTF-8-or-reject conversion (issue #213).
63#[doc(hidden)]
64pub mod argv;
65#[cfg(test)]
66#[path = "argv_tests.rs"]
67mod argv_tests;
68/// Command output classification and intelligent truncation.
69pub mod classify;
70/// Byte-bounded head+tail truncation, re-exported from [`classify`].
71mod classify_bounded;
72#[doc(hidden)]
73#[allow(missing_docs)]
74pub mod commands;
75/// Config and data directory resolution (`OO_CONFIG_DIR`, `OO_DATA_DIR`, or the platform dirs).
76mod config;
77/// Savings suffix for compressed indicator lines (shared by the render arms).
78mod display;
79/// Error types for oo operations.
80pub mod error;
81/// Command execution and output capture.
82pub mod exec;
83/// Failure-tier display and recall notice (used by `render_classification`).
84mod failure_display;
85#[doc(hidden)]
86#[allow(missing_docs)]
87pub mod help;
88/// Indexing of raw command output for `oo recall` (shared by the render arms).
89mod indexing;
90#[doc(hidden)]
91#[allow(missing_docs)]
92pub mod init;
93#[doc(hidden)]
94#[allow(missing_docs)]
95pub mod init_pi;
96/// LLM-powered pattern learning.
97pub mod learn;
98mod learn_payload;
99#[doc(hidden)]
100pub mod learn_status;
101/// Pattern matching and output compression.
102pub mod pattern;
103/// Canonical pattern-set assembly (project/user/builtins precedence) shared
104/// by the dispatch layer and the rewrite/hook feature modules.
105#[doc(hidden)]
106pub mod pattern_load;
107/// Page-based project drain and stale cleanup for backends without bulk
108/// delete or pagination offset (Vipune adapter).
109#[cfg(any(feature = "vipune-store", test))]
110mod project_drain;
111/// Retention of indexed output (`[store] retention` in config.toml).
112mod retention;
113/// Session tracking and management.
114pub mod session;
115/// Storage backends for indexed output.
116pub mod store;
117
118/// Claude Code PreToolUse hook processor + settings.json installer (issue #172).
119#[doc(hidden)]
120pub mod hook;
121pub mod recall_display;
122pub mod rewrite;
123
124pub mod commands_patterns;
125#[cfg(test)]
126#[path = "init_args_tests.rs"]
127mod init_args_tests;
128pub mod init_cmd;
129pub mod learn_prompt;
130mod learn_url;
131pub mod learn_utils;
132/// Static usage text for reserved subcommands (`--help` and `oo help <sub>`).
133#[doc(hidden)]
134pub mod usage;
135#[cfg(test)]
136#[path = "usage_tests.rs"]
137mod usage_tests;
138
139// CLI internals - hidden from documentation but accessible to binary crate
140#[doc(hidden)]
141#[allow(missing_docs)]
142pub mod util;
143
144// Re-exports for library users
145pub use classify::{Classification, classify};
146pub use config::warn_ignored_overrides;
147pub use error::Error;
148pub use exec::CommandOutput;
149pub use pattern::{Pattern, builtins, load_user_patterns};
150pub use store::{SessionMeta, Store};
151
152// CLI internals - re-exported for binary crate but hidden from documentation
153#[doc(hidden)]
154pub use commands::{
155 Action, InitFormat, InitMode, cmd_forget, cmd_help, cmd_hook, cmd_init, cmd_learn,
156 cmd_patterns, cmd_patterns_in, cmd_recall, cmd_rewrite, cmd_run, parse_action,
157 render_classification, try_index,
158};
159
160// Internal type re-exported for learn module
161#[doc(hidden)]
162pub use pattern::FailureSection;
163
164#[cfg(test)]
165mod test_env;