Skip to main content

looprs_core/ports/
user_output.rs

1//! UserOutput port — abstraction over user-facing terminal/UI output.
2
3// TODO: hex refactor Phase 1 — Agent currently calls ui::* static functions
4// directly. Replace with this port. Wire the terminal adapter in looprs-cli;
5// inject NullOutput in tests.
6
7/// Port: emit structured output to the user.
8///
9/// Implementations may render to a terminal, a log file, a TUI widget,
10/// or a machine-readable JSON stream.
11pub trait UserOutput: Send + Sync {
12    fn info(&self, msg: &str);
13    fn warn(&self, msg: &str);
14    fn error(&self, msg: &str);
15    fn assistant_text(&self, text: &str);
16    fn tool_call(&self, tool_name: &str, input_preview: &str);
17    fn tool_ok(&self);
18    fn tool_err(&self, err_msg: &str);
19
20    /// Emit a single streaming chunk of assistant text.
21    ///
22    /// Called once per token/chunk during streaming inference. The default
23    /// implementation delegates to `assistant_text`, so existing adapters
24    /// remain valid until they opt into incremental rendering.
25    fn write_chunk(&self, chunk: &str) {
26        self.assistant_text(chunk);
27    }
28}