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.), and
17//! user-defined patterns can be loaded from TOML files in `~/.config/oo/patterns/`.
18//! - **Storage**: Large unpatterned outputs are stored in a searchable database (SQLite by
19//! default, with optional Vipune semantic search). Stored outputs can be recalled with
20//! full-text search.
21//! - **Categories**: Commands are auto-detected as Status (tests, builds, linters),
22//! Content (git show, diff, cat), Data (git log, ls, gh), or Unknown. This determines
23//! default behavior when no pattern matches.
24//!
25//! # Example
26//!
27//! ```
28//! use double_o::{classify, Classification, CommandOutput, Pattern};
29//! use double_o::pattern::builtins;
30//!
31//! // Run a command
32//! let args = vec!["echo".into(), "hello".into()];
33//! let output = double_o::exec::run(&args).unwrap();
34//!
35//! // Classify the output
36//! let command = "echo hello";
37//! let patterns = builtins(); // or load_user_patterns(&path)
38//! let result = classify(&output, command, &patterns);
39//!
40//! match result {
41//! Classification::Passthrough { output } => {
42//! println!("Output: {}", output);
43//! }
44//! Classification::Success { label, summary } => {
45//! println!("✓ {}: {}", label, summary);
46//! }
47//! Classification::Failure { label, output } => {
48//! println!("✗ {}: {}", label, output);
49//! }
50//! Classification::Large { label, size, .. } => {
51//! println!("Indexed: {} ({} bytes)", label, size);
52//! }
53//! }
54//! ```
55
56/// Command output classification and intelligent truncation.
57pub mod classify;
58#[doc(hidden)]
59#[allow(missing_docs)]
60pub mod commands;
61/// Error types for oo operations.
62pub mod error;
63/// Command execution and output capture.
64pub mod exec;
65#[doc(hidden)]
66#[allow(missing_docs)]
67pub mod init;
68/// LLM-powered pattern learning.
69pub mod learn;
70/// Pattern matching and output compression.
71pub mod pattern;
72/// Session tracking and management.
73pub mod session;
74/// Storage backends for indexed output.
75pub mod store;
76
77// CLI internals - hidden from documentation but accessible to binary crate
78#[doc(hidden)]
79#[allow(missing_docs)]
80pub mod help;
81#[doc(hidden)]
82#[allow(missing_docs)]
83pub mod util;
84
85// Re-exports for library users
86pub use classify::{Classification, classify};
87pub use error::Error;
88pub use exec::CommandOutput;
89pub use pattern::{Pattern, builtins, load_user_patterns};
90pub use store::{SessionMeta, Store};
91
92// CLI internals - re-exported for binary crate but hidden from documentation
93#[doc(hidden)]
94pub use commands::{
95 Action, InitFormat, check_and_clear_learn_status, classify_with_refs, cmd_forget, cmd_help,
96 cmd_init, cmd_learn, cmd_patterns, cmd_patterns_in, cmd_recall, cmd_run, parse_action,
97 try_index, write_learn_status,
98};
99
100// Internal type re-exported for learn module
101#[doc(hidden)]
102pub use pattern::FailureSection;