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::Large { label, size, .. } => {
52//!         println!("Indexed: {} ({} bytes)", label, size);
53//!     }
54//! }
55//! ```
56
57/// Command output classification and intelligent truncation.
58pub mod classify;
59#[doc(hidden)]
60#[allow(missing_docs)]
61pub mod commands;
62/// Error types for oo operations.
63pub mod error;
64/// Command execution and output capture.
65pub mod exec;
66#[doc(hidden)]
67#[allow(missing_docs)]
68pub mod init;
69/// LLM-powered pattern learning.
70pub mod learn;
71/// Pattern matching and output compression.
72pub mod pattern;
73/// Session tracking and management.
74pub mod session;
75/// Storage backends for indexed output.
76pub mod store;
77
78// CLI internals - hidden from documentation but accessible to binary crate
79#[doc(hidden)]
80#[allow(missing_docs)]
81pub mod help;
82#[doc(hidden)]
83#[allow(missing_docs)]
84pub mod util;
85
86// Re-exports for library users
87pub use classify::{Classification, classify};
88pub use error::Error;
89pub use exec::CommandOutput;
90pub use pattern::{Pattern, builtins, load_user_patterns};
91pub use store::{SessionMeta, Store};
92
93// CLI internals - re-exported for binary crate but hidden from documentation
94#[doc(hidden)]
95pub use commands::{
96    Action, InitFormat, check_and_clear_learn_status, classify_with_refs, cmd_forget, cmd_help,
97    cmd_init, cmd_learn, cmd_patterns, cmd_patterns_in, cmd_recall, cmd_run, load_project_patterns,
98    parse_action, try_index, write_learn_status,
99};
100
101// Internal type re-exported for learn module
102#[doc(hidden)]
103pub use pattern::FailureSection;