Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06af23c8a4 | ||
|
|
90df2106bf | ||
|
|
96cb9f84c9 | ||
|
|
7276e6d5d9 |
17 changed files with 335 additions and 66 deletions
28
TODO.md
28
TODO.md
|
|
@ -3,21 +3,6 @@
|
|||
Pick anything from here when relevant. Cross-cutting design notes live in
|
||||
[CLAUDE.md](CLAUDE.md); high-level project intro in [README.md](README.md).
|
||||
|
||||
## Turn loop
|
||||
|
||||
- **`recv` with no `wait_seconds` should return immediately.**
|
||||
Today omitting the argument falls through to the 30s
|
||||
default long-poll (`RECV_LONG_POLL_DEFAULT` in
|
||||
`hive-c0re/src/agent_server.rs`); a manager that wants a
|
||||
cheap "anything in the inbox right now?" peek has to
|
||||
explicitly pass `wait_seconds: 0`. Flip the semantics so
|
||||
`None` = no sleep, returning `None` (or the empty inbox
|
||||
shape) right away. The agent opts into the long-poll by
|
||||
setting a positive value. Update both `AgentRequest::Recv`
|
||||
and `ManagerRequest::Recv` handlers + the prompt language
|
||||
in `prompts/{agent,manager}.md`. Tighten the cap (180s)
|
||||
too — only meaningful when the agent is choosing to wait.
|
||||
|
||||
## Permissions / policy
|
||||
|
||||
- **Per-agent send allow-list.** Today any agent can `send` to any
|
||||
|
|
@ -88,19 +73,6 @@ Pick anything from here when relevant. Cross-cutting design notes live in
|
|||
|
||||
## UI / UX
|
||||
|
||||
- **Approval history tab on P3NDING APPR0VALS.** Today the
|
||||
section renders pending rows only; once approved / denied /
|
||||
failed they drop off the dashboard. Sqlite still has every
|
||||
row (approvals table never deletes), and the meta git log +
|
||||
applied repo's annotated `denied/<id>` / `failed/<id>` tags
|
||||
already carry the human-readable reasons. A second tab —
|
||||
`pending | history` — that scrolls the last N resolved
|
||||
approvals with their terminal status, `resolved_at`
|
||||
timestamp, operator note (deny), build error (failed), and
|
||||
a quick link/diff to the `proposal/<id>` tag would close
|
||||
the loop so the operator can see "what went out, what got
|
||||
rejected, why" without ssh-ing to the host.
|
||||
|
||||
- **Web UI for config repos + meta deploy log.** Browse
|
||||
per-agent proposed / applied tags
|
||||
(`proposal/* / approved/* / building/* / deployed/* /
|
||||
|
|
|
|||
|
|
@ -102,16 +102,43 @@ it as a stdio child via `--mcp-config`. The hyperhive socket name is
|
|||
- `send(to, body)` — message a peer (logical agent name), another
|
||||
agent, or the operator (recipient `operator`, surfaces in the
|
||||
dashboard inbox).
|
||||
- `recv(wait_seconds?)` — drain one inbox message. Long-polls
|
||||
server-side; `wait_seconds` is capped at 180 (default 30 when
|
||||
omitted). Agents use a long wait to park their turn waiting for
|
||||
work instead of busy-looping with short polls — they wake
|
||||
instantly when a message arrives.
|
||||
- `recv(wait_seconds?)` — drain one inbox message. Without
|
||||
`wait_seconds` (or with `0`) returns immediately, a cheap
|
||||
"anything pending?" peek. Positive value parks the turn up
|
||||
to that many seconds (cap 180) — incoming messages wake
|
||||
instantly, otherwise returns empty at the timeout.
|
||||
- `ask_operator(question, options?, multi?, ttl_seconds?)` —
|
||||
surface a question on the dashboard. Same shape as the manager's;
|
||||
answer routes back to the asker's own inbox as
|
||||
`HelperEvent::OperatorAnswered` via `coord.notify_agent`.
|
||||
|
||||
### Waking the agent from inside the container
|
||||
|
||||
External MCP servers (and any other in-container process) can
|
||||
inject a wake-up event into the agent's inbox via the per-agent
|
||||
socket at `/run/hive/mcp.sock`. Two equivalent paths:
|
||||
|
||||
- **Shell out to `hive-ag3nt wake --from <label> --body <text>`**
|
||||
(use `--body -` to read body from stdin). Already on the
|
||||
container's `PATH` since the harness binary is in
|
||||
`systemPackages`. Convenient for shell-script integrations.
|
||||
|
||||
- **Speak the wire protocol directly** — JSON-line over the
|
||||
unix socket: `{"cmd":"wake","from":"matrix","body":"new dm
|
||||
from @alice"}\n`. Same shape any other AgentRequest uses;
|
||||
see `hive-sh4re::AgentRequest::Wake`.
|
||||
|
||||
The wake event lands in the broker as `{from:<label>,
|
||||
to:<agent>, body}`, which wakes whatever `recv` call the
|
||||
harness is currently blocked on. Next turn fires with the
|
||||
wake prompt formed from that message — claude sees "from:
|
||||
matrix" (or whatever label) and reacts.
|
||||
|
||||
Identity = socket: anything that can connect to
|
||||
`/run/hive/mcp.sock` is implicitly trusted to inject these,
|
||||
which is fine because the bind-mount is the agent's own
|
||||
container only.
|
||||
|
||||
### Extra MCP servers (per-agent)
|
||||
|
||||
Each agent's NixOS config can declare additional MCP servers via
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ You are hyperhive agent `{label}` in a multi-agent system. The operator (recipie
|
|||
|
||||
Tools (hyperhive surface):
|
||||
|
||||
- `mcp__hyperhive__recv(wait_seconds?)` — drain one more message from your inbox (returns `(empty)` if nothing pending after the wait). Without `wait_seconds` it long-polls 30s. To **wait** for work when you have nothing else useful to do this turn, call with a long wait (e.g. `wait_seconds: 180`, the max) — you'll be woken instantly when a message arrives, otherwise return after the timeout. That is strictly better than calling `recv` repeatedly with short waits: lower latency on new work, fewer turns, no busy-loop. Never use a fixed `sleep` shell command for the same purpose.
|
||||
- `mcp__hyperhive__recv(wait_seconds?)` — drain one more message from your inbox (returns `(empty)` if nothing pending). Without `wait_seconds` (or with `0`) it returns immediately — a cheap "anything pending?" peek you can sprinkle between tool calls. To **wait** for work when you have nothing else useful to do this turn, call with a long wait (e.g. `wait_seconds: 180`, the max) — incoming messages wake you instantly, otherwise the call returns empty at the timeout. That's strictly better than a fixed `sleep` shell command: lower latency on new work, no busy-loop.
|
||||
- `mcp__hyperhive__send(to, body)` — message a peer (by their name) or the operator (recipient `operator`, surfaces in the dashboard).
|
||||
- (some agents only) **extra MCP tools** surfaced as `mcp__<server>__<tool>` — these are agent-specific (matrix client, scraper, db connector, etc.) declared in your `agent.nix` under `hyperhive.extraMcpServers`. Treat them as first-class tools alongside the hyperhive surface; the operator already auto-approved them at deploy time.
|
||||
- `mcp__hyperhive__ask_operator(question, options?, multi?, ttl_seconds?)` — surface a question to the human operator on the dashboard. Returns immediately with a question id — do NOT wait inline. When the operator answers, a system message with event `operator_answered { id, question, answer }` lands in your inbox; handle it on a future turn. Use this for clarifications, permission for risky actions, or choice between options. `options` is advisory: a short fixed-choice list when applicable, otherwise leave empty for free text. `multi: true` lets the operator pick multiple (checkboxes), answer comes back comma-joined. `ttl_seconds` auto-cancels with answer `[expired]` when the decision becomes moot.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ You are the hyperhive manager `{label}` in a multi-agent system. You coordinate
|
|||
|
||||
Tools (hyperhive surface):
|
||||
|
||||
- `mcp__hyperhive__recv(wait_seconds?)` — drain one more message from your inbox. Without `wait_seconds` it long-polls 30s. To **wait** when you have nothing else to do, call with a long wait (e.g. `wait_seconds: 180`, the max) — you'll wake instantly on new work, otherwise return after the timeout. Use this instead of ending the turn or sleeping in a Bash command.
|
||||
- `mcp__hyperhive__recv(wait_seconds?)` — drain one more message from your inbox. Without `wait_seconds` (or with `0`) it returns immediately — a cheap inbox peek you can drop between actions. To **wait** when you have nothing else to do, call with a long wait (e.g. `wait_seconds: 180`, the max) — you'll wake instantly on new work, otherwise return after the timeout. Use that instead of ending the turn or sleeping in a Bash command.
|
||||
- `mcp__hyperhive__send(to, body)` — message an agent (by name), another peer, or the operator (`operator` surfaces in the dashboard).
|
||||
- `mcp__hyperhive__request_spawn(name)` — queue a brand-new sub-agent for operator approval (≤9 char name).
|
||||
- `mcp__hyperhive__kill(name)` — graceful stop on a sub-agent. No approval required.
|
||||
|
|
|
|||
|
|
@ -33,6 +33,19 @@ enum Cmd {
|
|||
/// `--mcp-config`; tools dispatch through `/run/hive/mcp.sock` back into
|
||||
/// the hyperhive broker.
|
||||
Mcp,
|
||||
/// Inject a wake-up event into this agent's inbox so the next turn
|
||||
/// fires with the given body. Intended for extra MCP servers /
|
||||
/// helpers running inside the container (matrix bridge, scraper,
|
||||
/// webhook listener) that need to nudge claude on external events.
|
||||
/// `from` is the sender label that appears in the wake prompt
|
||||
/// (claude sees "from: matrix" etc.).
|
||||
Wake {
|
||||
#[arg(long)]
|
||||
from: String,
|
||||
/// Body of the wake message. Pass `-` to read from stdin.
|
||||
#[arg(long)]
|
||||
body: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -94,6 +107,25 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
Cmd::Mcp => mcp::serve_agent_stdio(cli.socket).await,
|
||||
Cmd::Wake { from, body } => {
|
||||
// Read body from stdin if caller passed `-`. Same convention
|
||||
// many CLI tools use; keeps multi-line / shell-quoting
|
||||
// friction out of the body content.
|
||||
let body = if body == "-" {
|
||||
let mut buf = String::new();
|
||||
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)?;
|
||||
buf
|
||||
} else {
|
||||
body
|
||||
};
|
||||
let resp: AgentResponse =
|
||||
client::request(&cli.socket, &AgentRequest::Wake { from, body }).await?;
|
||||
match resp {
|
||||
AgentResponse::Ok => Ok(()),
|
||||
AgentResponse::Err { message } => anyhow::bail!("wake: {message}"),
|
||||
other => anyhow::bail!("wake: unexpected response {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +140,17 @@ async fn serve(
|
|||
let _ = state; // reserved for future state transitions (turn-loop -> needs-login)
|
||||
loop {
|
||||
let recv: Result<AgentResponse> =
|
||||
client::request(socket, &AgentRequest::Recv { wait_seconds: None }).await;
|
||||
// Explicit long-poll: the new agent_server semantics treat
|
||||
// `None` as "peek, don't wait", which would tight-loop on
|
||||
// sleep(interval). The harness wants to park until a
|
||||
// message arrives, so opt into the full 180s cap.
|
||||
client::request(
|
||||
socket,
|
||||
&AgentRequest::Recv {
|
||||
wait_seconds: Some(180),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
match recv {
|
||||
Ok(AgentResponse::Message { from, body }) => {
|
||||
tracing::info!(%from, %body, "inbox");
|
||||
|
|
|
|||
|
|
@ -92,7 +92,16 @@ async fn serve(
|
|||
tracing::info!(socket = %socket.display(), "hive-m1nd serve");
|
||||
loop {
|
||||
let recv: Result<ManagerResponse> =
|
||||
client::request(socket, &ManagerRequest::Recv { wait_seconds: None }).await;
|
||||
// Explicit long-poll: see hive-ag3nt's serve loop for the
|
||||
// rationale — recv now defaults to peek when wait_seconds
|
||||
// is None.
|
||||
client::request(
|
||||
socket,
|
||||
&ManagerRequest::Recv {
|
||||
wait_seconds: Some(180),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
match recv {
|
||||
Ok(ManagerResponse::Message { from, body }) => {
|
||||
if from == SYSTEM_SENDER {
|
||||
|
|
|
|||
|
|
@ -205,11 +205,13 @@ impl AgentServer {
|
|||
|
||||
#[tool(
|
||||
description = "Pop one message from this agent's inbox. Returns the sender and body, \
|
||||
or an empty marker if nothing is waiting. Optional `wait_seconds` long-polls \
|
||||
for that many seconds (capped at 180) before returning empty — default 30. \
|
||||
Use a long wait_seconds (e.g. 120 or 180) when you have nothing else to do — \
|
||||
it parks the turn until either a message arrives or the timeout fires, which \
|
||||
is strictly better than a fixed sleep because incoming work wakes you instantly."
|
||||
or an empty marker if nothing is waiting. Without `wait_seconds` (or with 0) the \
|
||||
call returns immediately — a cheap 'anything pending?' peek. Pass a positive \
|
||||
`wait_seconds` (capped at 180) to park the turn waiting for new work — incoming \
|
||||
messages wake you instantly, otherwise the call returns empty at the timeout. \
|
||||
That's strictly better than a fixed shell `sleep`. Typical pattern: when you have \
|
||||
nothing else useful to do, call `recv(wait_seconds: 180)` to park until \
|
||||
something arrives."
|
||||
)]
|
||||
async fn recv(&self, Parameters(args): Parameters<RecvArgs>) -> String {
|
||||
let log = format!("{args:?}");
|
||||
|
|
@ -363,10 +365,10 @@ impl ManagerServer {
|
|||
|
||||
#[tool(
|
||||
description = "Pop one message from the manager inbox. Returns sender + body, or \
|
||||
empty. Optional `wait_seconds` long-polls (capped at 180, default 30) so the \
|
||||
manager can sit on Recv when there's nothing to do without burning turns — \
|
||||
prefer a long wait (120 or 180) over ending a turn early; you'll wake \
|
||||
instantly when work arrives."
|
||||
empty. Without `wait_seconds` (or 0) returns immediately — a cheap inbox peek. \
|
||||
Pass a positive value (capped at 180) to park until either a message arrives \
|
||||
or the timeout fires; prefer a long wait (120 or 180) over ending a turn \
|
||||
early when you have nothing else to do."
|
||||
)]
|
||||
async fn recv(&self, Parameters(args): Parameters<RecvArgs>) -> String {
|
||||
let log = format!("{args:?}");
|
||||
|
|
|
|||
|
|
@ -601,6 +601,7 @@
|
|||
root.append(ul);
|
||||
}
|
||||
|
||||
const APPROVAL_TAB_KEY = 'hyperhive:approvals:tab';
|
||||
function renderApprovals(s) {
|
||||
const root = $('approvals-section');
|
||||
root.innerHTML = '';
|
||||
|
|
@ -622,6 +623,41 @@
|
|||
);
|
||||
root.append(spawn);
|
||||
|
||||
const history = s.approval_history || [];
|
||||
const active = localStorage.getItem(APPROVAL_TAB_KEY) || 'pending';
|
||||
const tabs = el('div', { class: 'approval-tabs' });
|
||||
const pendingTab = el(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: 'approval-tab' + (active === 'pending' ? ' active' : ''),
|
||||
},
|
||||
`pending · ${s.approvals.length}`,
|
||||
);
|
||||
const historyTab = el(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
class: 'approval-tab' + (active === 'history' ? ' active' : ''),
|
||||
},
|
||||
`history · ${history.length}`,
|
||||
);
|
||||
pendingTab.addEventListener('click', () => {
|
||||
localStorage.setItem(APPROVAL_TAB_KEY, 'pending');
|
||||
renderApprovals(s);
|
||||
});
|
||||
historyTab.addEventListener('click', () => {
|
||||
localStorage.setItem(APPROVAL_TAB_KEY, 'history');
|
||||
renderApprovals(s);
|
||||
});
|
||||
tabs.append(pendingTab, historyTab);
|
||||
root.append(tabs);
|
||||
|
||||
if (active === 'history') {
|
||||
renderApprovalHistory(root, history);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s.approvals.length) {
|
||||
root.append(el('p', { class: 'empty' }, 'queue empty'));
|
||||
return;
|
||||
|
|
@ -681,6 +717,49 @@
|
|||
root.append(ul);
|
||||
}
|
||||
|
||||
function renderApprovalHistory(root, history) {
|
||||
if (!history.length) {
|
||||
root.append(el('p', { class: 'empty' }, 'no resolved approvals yet'));
|
||||
return;
|
||||
}
|
||||
const ul = el('ul', { class: 'approvals approvals-history' });
|
||||
for (const a of history) {
|
||||
const li = el('li');
|
||||
const row = el('div', { class: 'row' });
|
||||
const glyph = a.status === 'approved' ? '✓'
|
||||
: a.status === 'denied' ? '✗'
|
||||
: '⚠';
|
||||
row.append(
|
||||
el('span', { class: 'glyph glyph-' + a.status }, glyph), ' ',
|
||||
el('span', { class: 'id' }, '#' + a.id), ' ',
|
||||
el('span', { class: 'agent' }, a.agent), ' ',
|
||||
el('span', { class: 'kind' }, a.kind === 'apply_commit' ? 'apply' : 'spawn'), ' ',
|
||||
);
|
||||
if (a.sha_short) row.append(el('code', {}, a.sha_short), ' ');
|
||||
row.append(
|
||||
el('span', { class: 'status status-' + a.status }, a.status), ' ',
|
||||
el('span', { class: 'msg-ts' }, fmtAgo(a.resolved_at)),
|
||||
);
|
||||
li.append(row);
|
||||
if (a.note) {
|
||||
li.append(el('div', { class: 'history-note' }, a.note));
|
||||
}
|
||||
ul.append(li);
|
||||
}
|
||||
root.append(ul);
|
||||
}
|
||||
|
||||
// Relative time, anchored to now. resolved_at is unix seconds (server-
|
||||
// authored), so we don't have to worry about client/server clock skew
|
||||
// for sub-minute precision.
|
||||
function fmtAgo(unixSecs) {
|
||||
const ageSec = Math.max(0, Math.floor(Date.now() / 1000 - unixSecs));
|
||||
if (ageSec < 60) return ageSec + 's ago';
|
||||
if (ageSec < 3600) return Math.floor(ageSec / 60) + 'm ago';
|
||||
if (ageSec < 86400) return Math.floor(ageSec / 3600) + 'h ago';
|
||||
return Math.floor(ageSec / 86400) + 'd ago';
|
||||
}
|
||||
|
||||
// ─── state polling ──────────────────────────────────────────────────────
|
||||
let pollTimer = null;
|
||||
// Sections whose innerHTML gets blown away on each refresh. If the
|
||||
|
|
|
|||
|
|
@ -258,6 +258,44 @@ code {
|
|||
}
|
||||
.approvals .row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4em; }
|
||||
.approvals form.inline { display: inline; margin-left: 0.4em; }
|
||||
.approval-tabs {
|
||||
display: flex;
|
||||
gap: 0.4em;
|
||||
margin: 0.6em 0 0.4em;
|
||||
}
|
||||
.approval-tab {
|
||||
background: transparent;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--muted);
|
||||
font: inherit;
|
||||
font-size: 0.85em;
|
||||
letter-spacing: 0.08em;
|
||||
padding: 0.25em 0.9em;
|
||||
cursor: pointer;
|
||||
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
|
||||
}
|
||||
.approval-tab:hover { color: var(--fg); }
|
||||
.approval-tab.active {
|
||||
color: var(--purple);
|
||||
border-color: var(--purple);
|
||||
background: rgba(203, 166, 247, 0.08);
|
||||
text-shadow: 0 0 4px currentColor;
|
||||
}
|
||||
.approvals-history .status { font-size: 0.85em; padding: 0 0.5em; }
|
||||
.status-approved { color: var(--green); }
|
||||
.status-denied { color: var(--red); }
|
||||
.status-failed { color: var(--amber); }
|
||||
.glyph-approved { color: var(--green); }
|
||||
.glyph-denied { color: var(--red); }
|
||||
.glyph-failed { color: var(--amber); }
|
||||
.history-note {
|
||||
margin-left: 1.8em;
|
||||
margin-top: 0.2em;
|
||||
color: var(--muted);
|
||||
font-size: 0.85em;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
ul form.inline { display: inline-block; }
|
||||
.btn {
|
||||
font-family: inherit;
|
||||
|
|
|
|||
|
|
@ -81,19 +81,20 @@ async fn serve(stream: UnixStream, agent: String, coord: Arc<Coordinator>) -> Re
|
|||
}
|
||||
}
|
||||
|
||||
/// Default and max long-poll window for `Recv`. Caller can request a
|
||||
/// shorter (or longer up to `RECV_LONG_POLL_MAX`) wait via the
|
||||
/// `wait_seconds` field; values above the cap are clamped. 180s
|
||||
/// max keeps us under typical TCP/proxy idle limits while letting
|
||||
/// agents park their turn until a message lands instead of busy-
|
||||
/// looping with short waits.
|
||||
const RECV_LONG_POLL_DEFAULT: std::time::Duration = std::time::Duration::from_secs(30);
|
||||
/// Max long-poll window the caller can ask for; values above the
|
||||
/// cap are clamped. 180s keeps us under typical TCP/proxy idle
|
||||
/// limits while still letting agents park their turn until a
|
||||
/// message arrives. Omitting `wait_seconds` (or passing `0`) means
|
||||
/// "peek, don't wait" — claude can call recv whenever it wants a
|
||||
/// cheap "is there anything pending?" check without blocking the
|
||||
/// turn for 30 seconds. To actually park, the caller passes a
|
||||
/// positive `wait_seconds`.
|
||||
const RECV_LONG_POLL_MAX: std::time::Duration = std::time::Duration::from_secs(180);
|
||||
|
||||
fn recv_timeout(wait_seconds: Option<u64>) -> std::time::Duration {
|
||||
match wait_seconds {
|
||||
Some(s) => std::time::Duration::from_secs(s).min(RECV_LONG_POLL_MAX),
|
||||
None => RECV_LONG_POLL_DEFAULT,
|
||||
None => std::time::Duration::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,6 +142,16 @@ async fn dispatch(req: &AgentRequest, agent: &str, coord: &Arc<Coordinator>) ->
|
|||
message: format!("{e:#}"),
|
||||
},
|
||||
},
|
||||
AgentRequest::Wake { from, body } => match broker.send(&Message {
|
||||
from: from.clone(),
|
||||
to: agent.to_owned(),
|
||||
body: body.clone(),
|
||||
}) {
|
||||
Ok(()) => AgentResponse::Ok,
|
||||
Err(e) => AgentResponse::Err {
|
||||
message: format!("{e:#}"),
|
||||
},
|
||||
},
|
||||
AgentRequest::Recent { limit } => match broker.recent_for(agent, *limit) {
|
||||
Ok(rows) => AgentResponse::Recent { rows },
|
||||
Err(e) => AgentResponse::Err {
|
||||
|
|
|
|||
|
|
@ -102,6 +102,22 @@ impl Approvals {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Last `limit` resolved approvals (approved / denied / failed),
|
||||
/// newest-first. Drives the history tab on the dashboard.
|
||||
pub fn recent_resolved(&self, limit: u64) -> Result<Vec<Approval>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, agent, kind, commit_ref, requested_at, status, resolved_at, note, fetched_sha
|
||||
FROM approvals
|
||||
WHERE status IN ('approved', 'denied', 'failed')
|
||||
ORDER BY resolved_at DESC, id DESC
|
||||
LIMIT ?1",
|
||||
)?;
|
||||
let rows = stmt.query_map([limit], row_to_approval)?;
|
||||
rows.collect::<rusqlite::Result<Vec<_>>>()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn pending(&self) -> Result<Vec<Approval>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare(
|
||||
|
|
|
|||
|
|
@ -134,6 +134,9 @@ struct StateSnapshot {
|
|||
containers: Vec<ContainerView>,
|
||||
transients: Vec<TransientView>,
|
||||
approvals: Vec<ApprovalView>,
|
||||
/// Last 30 resolved approvals (approved / denied / failed), newest-
|
||||
/// first. Drives the "history" tab on the approvals section.
|
||||
approval_history: Vec<ApprovalHistoryView>,
|
||||
/// Latest messages addressed to `operator` — surfaces agent replies
|
||||
/// asynchronously so the operator can see them without watching the
|
||||
/// live panel during a turn.
|
||||
|
|
@ -203,6 +206,24 @@ struct TransientView {
|
|||
secs: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct ApprovalHistoryView {
|
||||
id: i64,
|
||||
agent: String,
|
||||
kind: &'static str,
|
||||
/// First 12 chars of the canonical sha (preferred) or
|
||||
/// manager-supplied ref. None for resolved spawn approvals.
|
||||
sha_short: Option<String>,
|
||||
/// `approved` / `denied` / `failed`.
|
||||
status: &'static str,
|
||||
/// Unix seconds. Renders as a relative time on the dashboard.
|
||||
resolved_at: i64,
|
||||
/// Operator-supplied deny reason (for `denied`) or build error
|
||||
/// (for `failed`). None on `approved`.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
note: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct ApprovalView {
|
||||
id: i64,
|
||||
|
|
@ -233,6 +254,14 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
|||
build_container_views(&raw_containers, current_rev.as_deref(), &transient_snapshot).await;
|
||||
let transients = build_transient_views(&raw_containers, &transient_snapshot);
|
||||
let approvals = build_approval_views(pending_approvals).await;
|
||||
let approval_history = state
|
||||
.coord
|
||||
.approvals
|
||||
.recent_resolved(30)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(history_view)
|
||||
.collect();
|
||||
let tombstones = build_tombstone_views(&state.coord, &containers, &transient_snapshot);
|
||||
let port_conflicts = build_port_conflicts(&containers);
|
||||
|
||||
|
|
@ -250,6 +279,7 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
|||
containers,
|
||||
transients,
|
||||
approvals,
|
||||
approval_history,
|
||||
operator_inbox,
|
||||
questions,
|
||||
tombstones,
|
||||
|
|
@ -376,6 +406,38 @@ fn build_transient_views(
|
|||
|
||||
/// Render each pending approval into its dashboard view (short sha +
|
||||
/// unified diff for `ApplyCommit`, just the name for `Spawn`).
|
||||
/// Project a resolved sqlite row into the lean shape the dashboard
|
||||
/// history tab consumes — no `diff_html` (rendering 30 of them
|
||||
/// per /api/state poll would mean 30 git diffs per refresh).
|
||||
fn history_view(a: Approval) -> ApprovalHistoryView {
|
||||
let displayed = a.fetched_sha.as_deref().unwrap_or(&a.commit_ref);
|
||||
let sha_short = if displayed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(displayed[..displayed.len().min(12)].to_owned())
|
||||
};
|
||||
let status = match a.status {
|
||||
hive_sh4re::ApprovalStatus::Approved => "approved",
|
||||
hive_sh4re::ApprovalStatus::Denied => "denied",
|
||||
hive_sh4re::ApprovalStatus::Failed => "failed",
|
||||
// Pending shouldn't appear in recent_resolved, but be defensive.
|
||||
hive_sh4re::ApprovalStatus::Pending => "pending",
|
||||
};
|
||||
let kind = match a.kind {
|
||||
hive_sh4re::ApprovalKind::ApplyCommit => "apply_commit",
|
||||
hive_sh4re::ApprovalKind::Spawn => "spawn",
|
||||
};
|
||||
ApprovalHistoryView {
|
||||
id: a.id,
|
||||
agent: a.agent,
|
||||
kind,
|
||||
sha_short,
|
||||
status,
|
||||
resolved_at: a.resolved_at.unwrap_or(0),
|
||||
note: a.note,
|
||||
}
|
||||
}
|
||||
|
||||
async fn build_approval_views(approvals: Vec<Approval>) -> Vec<ApprovalView> {
|
||||
let mut out = Vec::with_capacity(approvals.len());
|
||||
for a in approvals {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ pub const CONTAINER_CLAUDE_MOUNT: &str = "/root/.claude";
|
|||
/// state here; persists across destroy/recreate.
|
||||
pub const CONTAINER_NOTES_MOUNT: &str = "/state";
|
||||
|
||||
const GIT_NAME: &str = "hive-c0re";
|
||||
const GIT_EMAIL: &str = "hive-c0re@hyperhive";
|
||||
const GIT_NAME: &str = "c0re";
|
||||
const GIT_EMAIL: &str = "c0re@hyperhive";
|
||||
|
||||
/// Sub-agent web UI port range. Deterministic from the agent's name (FNV-1a
|
||||
/// hash mod range size), so the dashboard can compute the same port without
|
||||
|
|
|
|||
|
|
@ -69,15 +69,16 @@ async fn serve(stream: UnixStream, coord: Arc<Coordinator>) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Default and max long-poll window for manager `Recv`. Caller can
|
||||
/// request a shorter or longer (up to MAX) wait via `wait_seconds`.
|
||||
const MANAGER_RECV_LONG_POLL_DEFAULT: std::time::Duration = std::time::Duration::from_secs(30);
|
||||
/// Max long-poll window for manager `Recv`. Same semantics as the
|
||||
/// sub-agent socket: omitted `wait_seconds` (or `0`) = peek and
|
||||
/// return immediately, positive value = park up to that many
|
||||
/// seconds (clamped at MAX).
|
||||
const MANAGER_RECV_LONG_POLL_MAX: std::time::Duration = std::time::Duration::from_secs(180);
|
||||
|
||||
fn manager_recv_timeout(wait_seconds: Option<u64>) -> std::time::Duration {
|
||||
match wait_seconds {
|
||||
Some(s) => std::time::Duration::from_secs(s).min(MANAGER_RECV_LONG_POLL_MAX),
|
||||
None => MANAGER_RECV_LONG_POLL_DEFAULT,
|
||||
None => std::time::Duration::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ use crate::lifecycle;
|
|||
|
||||
const META_ROOT: &str = "/var/lib/hyperhive/meta";
|
||||
const APPLIED_ROOT: &str = "/var/lib/hyperhive/applied";
|
||||
const GIT_NAME: &str = "hive-c0re";
|
||||
const GIT_EMAIL: &str = "hive-c0re@hyperhive";
|
||||
const GIT_NAME: &str = "c0re";
|
||||
const GIT_EMAIL: &str = "c0re@hyperhive";
|
||||
|
||||
/// Single-writer lock around every meta-repo operation. Git isn't
|
||||
/// safe to drive from concurrent processes against the same `.git/`
|
||||
|
|
|
|||
|
|
@ -148,9 +148,9 @@ async fn migrate_applied_repo(name: &str) -> Result<()> {
|
|||
&dir,
|
||||
&[
|
||||
"-c",
|
||||
"user.name=hive-c0re",
|
||||
"user.name=c0re",
|
||||
"-c",
|
||||
"user.email=hive-c0re@hyperhive",
|
||||
"user.email=c0re@hyperhive",
|
||||
"add",
|
||||
"flake.nix",
|
||||
],
|
||||
|
|
@ -160,9 +160,9 @@ async fn migrate_applied_repo(name: &str) -> Result<()> {
|
|||
&dir,
|
||||
&[
|
||||
"-c",
|
||||
"user.name=hive-c0re",
|
||||
"user.name=c0re",
|
||||
"-c",
|
||||
"user.email=hive-c0re@hyperhive",
|
||||
"user.email=c0re@hyperhive",
|
||||
"commit",
|
||||
"-m",
|
||||
"migration: module-only flake",
|
||||
|
|
|
|||
|
|
@ -191,6 +191,16 @@ pub enum AgentRequest {
|
|||
/// per-agent equivalent of the old dashboard T4LK form, but scoped to
|
||||
/// the agent whose page the operator is on.
|
||||
OperatorMsg { body: String },
|
||||
/// Wake-up event injected from inside the container — typically an
|
||||
/// extra MCP server (matrix, scraper, webhook bridge) signalling
|
||||
/// that external work has arrived for this agent. Recipient is
|
||||
/// implicit (this agent); `from` is caller-chosen so the wake
|
||||
/// prompt can label the source ("matrix: new message in
|
||||
/// #general"). Identity = socket means anything that can connect
|
||||
/// to `/run/hive/mcp.sock` is implicitly trusted to inject these,
|
||||
/// which is fine: the bind-mount is restricted to the agent's
|
||||
/// own container.
|
||||
Wake { from: String, body: String },
|
||||
/// Last `limit` messages addressed to this agent, newest-first.
|
||||
/// Non-mutating — pulls from the broker without delivering. The
|
||||
/// per-agent web UI uses this to render its own inbox section.
|
||||
|
|
|
|||
Loading…
Reference in a new issue