claude: pipe prompt via stdin (variadic --allowedTools was eating it); + ManagerRequest::Status
This commit is contained in:
parent
9eab28a716
commit
accb1445e3
5 changed files with 34 additions and 10 deletions
|
|
@ -9,7 +9,7 @@ use hive_ag3nt::events::{Bus, LiveEvent};
|
|||
use hive_ag3nt::login::{self, LoginState};
|
||||
use hive_ag3nt::{DEFAULT_SOCKET, DEFAULT_WEB_PORT, client, mcp, web_ui};
|
||||
use hive_sh4re::{AgentRequest, AgentResponse};
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::process::Command;
|
||||
|
||||
#[derive(Parser)]
|
||||
|
|
@ -211,6 +211,11 @@ fn format_wake_prompt(label: &str, from: &str, body: &str) -> String {
|
|||
/// the hyperhive MCP surface auto-approved. Bash pattern allow-list is on
|
||||
/// the backlog (CLAUDE.md).
|
||||
async fn run_turn(prompt: &str, mcp_config: &Path, bus: &Bus) -> Result<()> {
|
||||
// Don't pass the prompt as a positional arg: `--allowedTools <tools...>`
|
||||
// and `--tools <tools...>` are variadic in claude-code, and the
|
||||
// trailing positional gets swallowed into one of them — claude then
|
||||
// errors with "Input must be provided either through stdin or as a
|
||||
// prompt argument when using --print". Pipe via stdin instead.
|
||||
let mut child = Command::new("claude")
|
||||
.arg("--print")
|
||||
.arg("--verbose")
|
||||
|
|
@ -224,11 +229,16 @@ async fn run_turn(prompt: &str, mcp_config: &Path, bus: &Bus) -> Result<()> {
|
|||
.arg(mcp::builtin_tools_arg())
|
||||
.arg("--allowedTools")
|
||||
.arg(mcp::allowed_tools_arg())
|
||||
.arg(prompt)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
if let Some(mut stdin) = child.stdin.take() {
|
||||
stdin.write_all(prompt.as_bytes()).await?;
|
||||
stdin.shutdown().await.ok();
|
||||
drop(stdin); // signal EOF to claude
|
||||
}
|
||||
let stdout = child.stdout.take().expect("piped stdout");
|
||||
let stderr = child.stderr.take().expect("piped stderr");
|
||||
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@ async fn serve(socket: &Path, interval: Duration) -> Result<()> {
|
|||
}
|
||||
}
|
||||
Ok(ManagerResponse::Empty) => {}
|
||||
Ok(ManagerResponse::Ok) => {
|
||||
tracing::warn!("recv produced Ok (unexpected)");
|
||||
Ok(ManagerResponse::Ok | ManagerResponse::Status { .. }) => {
|
||||
tracing::warn!("recv produced unexpected response kind");
|
||||
}
|
||||
Ok(ManagerResponse::Err { message }) => {
|
||||
tracing::warn!(%message, "recv error");
|
||||
|
|
|
|||
|
|
@ -1,16 +1,20 @@
|
|||
//! Embedded MCP server. Claude Code (running inside the agent container)
|
||||
//! launches this as a stdio child via `--mcp-config`; tool calls land here
|
||||
//! and are translated to `AgentRequest::Send`/`Recv` against hyperhive's
|
||||
//! own per-agent unix socket at `/run/hive/mcp.sock`.
|
||||
//! and are translated to `AgentRequest::*` / `ManagerRequest::*` against
|
||||
//! hyperhive's own per-container unix socket at `/run/hive/mcp.sock`.
|
||||
//!
|
||||
//! Two protocols, two surfaces:
|
||||
//! - **hyperhive socket** at `/run/hive/mcp.sock` — JSON-line, our
|
||||
//! broker-routed Send/Recv. Unaffected by this module.
|
||||
//! broker-routed protocol. Unaffected by this module.
|
||||
//! - **MCP stdio** owned by this module — what claude actually speaks.
|
||||
//!
|
||||
//! The agent surface today is intentionally tiny (send/recv); the manager
|
||||
//! surface (Phase 8 follow-up) will add `request_spawn`, `request_kill`,
|
||||
//! `request_apply_commit`.
|
||||
//! Two server flavors:
|
||||
//! - `AgentServer` — sub-agent tools (`send`, `recv`).
|
||||
//! - `ManagerServer` — agent tools + lifecycle (`request_spawn`, `kill`,
|
||||
//! `request_apply_commit`).
|
||||
//!
|
||||
//! Both go through the same `run_tool_envelope` helper so logging + status
|
||||
//! line stay uniform.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue