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