oy/lib.rs
1//! Library facade for the `oy` command-line application.
2//!
3//! `oy` is primarily a binary crate: install and run the [`oy` CLI][repo] to inspect,
4//! edit, audit, and ask questions about local repositories. The library surface is kept
5//! intentionally small for the binary, integration tests, and lightweight embedders that
6//! want to invoke the same command handlers.
7//!
8//! Most implementation modules are private so their internals can evolve without creating
9//! an API compatibility promise. If you need to automate `oy`, prefer spawning the `oy`
10//! binary and using its documented CLI unless one of the functions below exactly fits your
11//! use case.
12//!
13//! Useful project documentation:
14//!
15//! - [README](https://github.com/wagov-dtt/oy-cli#readme) for installation and user guide.
16//! - [Architecture](https://github.com/wagov-dtt/oy-cli/blob/main/docs/architecture.md)
17//! for runtime flow, module responsibilities, and trust boundaries.
18//! - [Tool safety](https://github.com/wagov-dtt/oy-cli/blob/main/docs/tool-safety.md)
19//! for capability and approval-mode details.
20//!
21//! [repo]: https://github.com/wagov-dtt/oy-cli
22
23#![recursion_limit = "256"]
24
25mod agent;
26mod audit;
27mod cli;
28mod tools;
29
30pub(crate) use agent::{bedrock, model, session};
31pub(crate) use cli::{app, chat, config, ui};
32
33pub use ui::{OutputMode, set_output_mode};
34
35/// Runs the `oy` command dispatcher with command-line arguments excluding the program name.
36///
37/// This is the same application entry point used by the binary after `src/main.rs` strips
38/// the executable name. It returns the process exit code that the binary should use.
39///
40/// Prefer invoking the `oy` binary for automation unless embedding the CLI in-process is
41/// specifically needed.
42pub async fn run(argv: Vec<String>) -> anyhow::Result<i32> {
43 app::run(argv).await
44}
45
46/// Returns the interactive chat help text shown by `/help`.
47///
48/// This helper is public so snapshot tests and lightweight integrations can verify or
49/// display the same help content as the interactive shell.
50pub fn chat_help_text() -> String {
51 chat::chat_help_text()
52}
53
54/// Formats a tool result using the same compact preview renderer as the CLI.
55///
56/// `name` is the tool name, and `value` is the JSON result payload returned by that tool.
57/// The output is intended for humans and may change with CLI presentation improvements;
58/// do not treat it as a stable machine-readable format.
59pub fn preview_tool_output(name: &str, value: &serde_json::Value) -> String {
60 tools::preview_tool_output(name, value)
61}
62
63/// Writes a formatted diagnostic line to standard error using the current UI output mode.
64///
65/// Use [`format_args!`] to avoid allocating an intermediate `String`:
66///
67/// ```no_run
68/// oy::err_line(format_args!("provider failed: {}", "timeout"));
69/// ```
70pub fn err_line(args: std::fmt::Arguments<'_>) {
71 ui::err_line(args);
72}