Skip to main content

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 `~/.config/oo/patterns/` TOML files (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/// Command output classification and intelligent truncation.
61pub mod classify;
62#[doc(hidden)]
63#[allow(missing_docs)]
64pub mod commands;
65/// Error types for oo operations.
66pub mod error;
67/// Command execution and output capture.
68pub mod exec;
69#[doc(hidden)]
70#[allow(missing_docs)]
71pub mod help;
72#[doc(hidden)]
73#[allow(missing_docs)]
74pub mod init;
75#[doc(hidden)]
76#[allow(missing_docs)]
77pub mod init_pi;
78/// LLM-powered pattern learning.
79pub mod learn;
80/// Pattern matching and output compression.
81pub mod pattern;
82/// Canonical pattern-set assembly (project/user/builtins precedence) shared
83/// by the dispatch layer and the rewrite/hook feature modules.
84#[doc(hidden)]
85pub mod pattern_load;
86/// Session tracking and management.
87pub mod session;
88/// Storage backends for indexed output.
89pub mod store;
90
91/// Claude Code PreToolUse hook processor + settings.json installer (issue #172).
92#[doc(hidden)]
93pub mod hook;
94pub mod recall_display;
95pub mod rewrite;
96
97pub mod commands_patterns;
98#[cfg(test)]
99#[path = "init_args_tests.rs"]
100mod init_args_tests;
101pub mod learn_prompt;
102pub mod learn_utils;
103
104// CLI internals - hidden from documentation but accessible to binary crate
105#[doc(hidden)]
106#[allow(missing_docs)]
107pub mod util;
108
109// Re-exports for library users
110pub use classify::{Classification, classify};
111pub use error::Error;
112pub use exec::CommandOutput;
113pub use pattern::{Pattern, builtins, load_user_patterns};
114pub use store::{SessionMeta, Store};
115
116// CLI internals - re-exported for binary crate but hidden from documentation
117#[doc(hidden)]
118pub use commands::{
119    Action, InitFormat, InitMode, check_and_clear_learn_status, cmd_forget, cmd_help, cmd_hook,
120    cmd_init, cmd_learn, cmd_patterns, cmd_patterns_in, cmd_recall, cmd_rewrite, cmd_run,
121    parse_action, render_classification, try_index, write_learn_status,
122};
123
124// Internal type re-exported for learn module
125#[doc(hidden)]
126pub use pattern::FailureSection;