refactor(agent): extract claude driver into hive-claude crate
This commit is contained in:
parent
e35acca814
commit
a3b66241d1
13 changed files with 907 additions and 442 deletions
30
hive-claude/src/sink.rs
Normal file
30
hive-claude/src/sink.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//! Streaming-output consumer hook.
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
/// Consumer callbacks for a claude run's output streams. Every method has a
|
||||
/// no-op default, so an implementor overrides only what it needs.
|
||||
///
|
||||
/// Methods are called synchronously from the stdout/stderr readers as lines
|
||||
/// arrive, so keep them cheap — the idiomatic body forwards to a channel or an
|
||||
/// event bus rather than blocking. The driver handles sentinel classification
|
||||
/// (rate-limit, prompt-too-long, …) itself; a sink only *observes* the stream.
|
||||
pub trait Sink {
|
||||
/// A parsed `stream-json` object from stdout (assistant/result/system/…
|
||||
/// event). The driver has already classified it for sentinels.
|
||||
fn on_event(&self, _event: &Value) {}
|
||||
|
||||
/// A stdout line that was not valid JSON — occasional Claude Code CLI
|
||||
/// chatter rather than conversation content.
|
||||
fn on_stdout_line(&self, _line: &str) {}
|
||||
|
||||
/// A stderr line, delivered verbatim. The last several are also retained
|
||||
/// by the driver for [`crate::Error::Exit`].
|
||||
fn on_stderr_line(&self, _line: &str) {}
|
||||
}
|
||||
|
||||
/// A [`Sink`] that discards everything. Useful for fire-and-forget runs where
|
||||
/// only the [`crate::Outcome`] matters.
|
||||
pub struct NoopSink;
|
||||
|
||||
impl Sink for NoopSink {}
|
||||
Loading…
Reference in a new issue