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