Skip to main content

oy/
lib.rs

1//! Internal library crate for the `oy` binary.
2//!
3//! The supported automation surface is the `oy` command-line interface. Rust module paths
4//! and exported items beyond [`run`] and [`err_line`] are intentionally unstable while the
5//! binary is still evolving.
6
7#![recursion_limit = "256"]
8
9mod agent;
10mod audit;
11mod cli;
12mod llm;
13mod review;
14mod tools;
15
16pub(crate) use agent::{compaction, model, session};
17pub(crate) use cli::{chat, config, ui};
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub(crate) enum TextDecodeError {
21    Binary,
22    NonUtf8,
23}
24
25pub(crate) fn decode_utf8(raw: Vec<u8>) -> Result<String, TextDecodeError> {
26    if raw.contains(&0) {
27        return Err(TextDecodeError::Binary);
28    }
29    String::from_utf8(raw).map_err(|_| TextDecodeError::NonUtf8)
30}
31
32/// Runs the `oy` command dispatcher.
33pub async fn run(argv: Vec<String>) -> anyhow::Result<i32> {
34    cli::app::run(argv).await
35}
36
37/// Writes a formatted diagnostic line to standard error.
38pub fn err_line(args: std::fmt::Arguments<'_>) {
39    ui::err_line(args);
40}
41
42#[cfg(test)]
43pub(crate) static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());