hive-runtime: shared runtime crate with claude and acp backends
A `Runtime` trait (run / compact / archive) with two backends: - claude: a pass-through to hive_claude's InfiniteSession and SessionStore, so a claude turn is the same spawn, session handling and errors as before. - acp: a generic Agent Client Protocol client. It spawns the command, args and env from RuntimeSpec (HIVE_RUNTIME / HIVE_ACP_COMMAND / HIVE_ACP_ARGS / HIVE_ACP_ENV), refuses an agent whose mcpCapabilities.http is not true, passes the claude --mcp-config servers as ACP mcpServers, keeps one session id in a file (session/load after a restart, session/new otherwise), and maps session/update into claude stream-json events plus usage_update into Telemetry. Permission requests are answered by a caller-supplied policy on the ACP tool kind. compact returns Unsupported for now. The crate depends on no hyperhive binary crate, so the subagent daemon can move onto it without pulling in hive-agent. Refs #4391
This commit is contained in:
parent
d98d407bf1
commit
b0e26e7e44
10 changed files with 1583 additions and 0 deletions
42
hive-runtime/src/claude.rs
Normal file
42
hive-runtime/src/claude.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//! The claude backend: a pass-through to `hive_claude`.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use hive_claude::{CompactionPolicy, Config, InfiniteSession, Progress, SessionStore, Sink};
|
||||
|
||||
use crate::{Result, Runtime};
|
||||
|
||||
/// `claude --print` turns on a titled [`InfiniteSession`], which owns
|
||||
/// resume-or-create and compaction.
|
||||
pub struct ClaudeRuntime<P: CompactionPolicy> {
|
||||
session: InfiniteSession<P>,
|
||||
store: SessionStore,
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl<P: CompactionPolicy> ClaudeRuntime<P> {
|
||||
/// A runtime for the session titled `title`, found through `store` and
|
||||
/// compacted per `policy`.
|
||||
pub fn new(title: impl Into<String>, store: SessionStore, policy: P) -> Self {
|
||||
let title = title.into();
|
||||
Self {
|
||||
session: InfiniteSession::new(title.clone(), store.clone(), policy),
|
||||
store,
|
||||
title,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: CompactionPolicy> Runtime for ClaudeRuntime<P> {
|
||||
async fn run(&self, config: &Config, prompt: &str, sink: &impl Sink) -> Result<Progress> {
|
||||
Ok(self.session.run(config, prompt, sink).await?)
|
||||
}
|
||||
|
||||
async fn compact(&self, config: &Config, sink: &impl Sink) -> Result<()> {
|
||||
Ok(self.session.compact(config, sink).await?)
|
||||
}
|
||||
|
||||
fn archive(&self) -> Result<Option<PathBuf>> {
|
||||
Ok(self.store.archive_by_title(&self.title)?)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue