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 net;
14mod review;
15mod tools;
16
17pub(crate) use agent::{compaction, model, session};
18pub(crate) use cli::{chat, config, ui};
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub(crate) enum TextDecodeError {
22    Binary,
23    NonUtf8,
24}
25
26pub(crate) fn decode_utf8(raw: Vec<u8>) -> Result<String, TextDecodeError> {
27    if raw.contains(&0) {
28        return Err(TextDecodeError::Binary);
29    }
30    String::from_utf8(raw).map_err(|_| TextDecodeError::NonUtf8)
31}
32
33/// Runs the `oy` command dispatcher.
34pub async fn run(argv: Vec<String>) -> anyhow::Result<i32> {
35    cli::app::run(argv).await
36}
37
38/// Writes a formatted diagnostic line to standard error.
39pub fn err_line(args: std::fmt::Arguments<'_>) {
40    ui::err_line(args);
41}
42
43#[cfg(test)]
44pub(crate) static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());