drop the sqlite event log nothing reads, and the comments naming routes that are gone
This commit is contained in:
parent
6289b8d64b
commit
cbda9c162f
15 changed files with 71 additions and 305 deletions
|
|
@ -41,48 +41,6 @@ Retention:
|
||||||
successful turn, so `requeue_inflight` can still requeue
|
successful turn, so `requeue_inflight` can still requeue
|
||||||
an unacked row on a crash.
|
an unacked row on a crash.
|
||||||
|
|
||||||
### `/harness/hyperhive-events.sqlite` (per agent)
|
|
||||||
|
|
||||||
Lives inside each container's bind-mounted `/harness/` dir (host
|
|
||||||
path: `/var/lib/hyperhive/agents/<name>/harness/hyperhive-events.sqlite`).
|
|
||||||
One table:
|
|
||||||
|
|
||||||
- `events(id, ts, kind, payload_json)` — every `LiveEvent` the
|
|
||||||
harness emits during turn loop execution.
|
|
||||||
|
|
||||||
The db runs in WAL mode, so `-wal` and `-shm` files sit beside it while
|
|
||||||
the harness is up. Copy or back up the three together, or the recent rows
|
|
||||||
sit in the `-wal` file until a checkpoint.
|
|
||||||
|
|
||||||
<!-- vale write-good.Passive = NO -->
|
|
||||||
|
|
||||||
The harness both writes and vacuums it. Cleanup runs in-container
|
|
||||||
because hive-c0re runs as the unprivileged `hive-core` user under
|
|
||||||
privsep and can't delete agent-owned files (host-side deletes hit
|
|
||||||
`PermissionDenied` on the bash-task trio and a readonly database error
|
|
||||||
here). `hive-agent`'s `vacuum::run`
|
|
||||||
(`hive-agent/src/vacuum.rs`) sweeps hourly. Retention is
|
|
||||||
**type-scoped**: it deletes only the verbose `stream` rows (the raw
|
|
||||||
claude `stream-json` deltas — one per text chunk / tool use, the bulk
|
|
||||||
of the file's size) older than 14 days, and keeps every other kind
|
|
||||||
(`turn_start`, `turn_end`, `note`, `status_changed`, `model_changed`,
|
|
||||||
`token_usage_changed`, `turn_state_changed`) indefinitely — those are
|
|
||||||
small and carry the semantic per-turn history the operator scrolls
|
|
||||||
back through when debugging a regression. Age-only within the
|
|
||||||
`stream` kind — no row cap — so a chatty turn doesn't lose its stream
|
|
||||||
history sooner than a quiet one. The trade-off (accepted): a
|
|
||||||
misbehaving harness can skip its own cleanup — but a compromised harness is
|
|
||||||
already inside the container trust boundary
|
|
||||||
([`docs/2-handbook/agents/security.md`](../../2-handbook/agents/security.md)), and these are ephemeral local
|
|
||||||
artifacts, so cleaning them up where they live is the honest fix.
|
|
||||||
|
|
||||||
<!-- vale write-good.Passive = YES -->
|
|
||||||
|
|
||||||
Path overridable via `HYPERHIVE_EVENTS_DB` (for dev / no-`/harness`
|
|
||||||
setups). On open failure the `Bus` falls back to no-store mode
|
|
||||||
rather than crashing the harness — events still broadcast over SSE,
|
|
||||||
just nothing persisted.
|
|
||||||
|
|
||||||
### `/harness/hyperhive-turn-stats.sqlite` (per agent)
|
### `/harness/hyperhive-turn-stats.sqlite` (per agent)
|
||||||
|
|
||||||
Per-turn analytics sink. One row per claude turn captures
|
Per-turn analytics sink. One row per claude turn captures
|
||||||
|
|
@ -266,8 +224,8 @@ Under `/var/lib/hyperhive/agents/<name>/`:
|
||||||
counts, so an unchanged situation re-upserts as `changed == false`
|
counts, so an unchanged situation re-upserts as `changed == false`
|
||||||
and never re-wakes.
|
and never re-wakes.
|
||||||
|
|
||||||
Retention, same hourly `hive-agent::vacuum::run` sweep as
|
Retention, by the hourly `hive-agent::vacuum::run` sweep, which runs in-container
|
||||||
`hyperhive-events.sqlite` below: it reaps delivered (soft-deleted) reminder
|
because hive-c0re can't delete agent-owned files: it reaps delivered (soft-deleted) reminder
|
||||||
rows 14 days after delivery, kept that long only to serve
|
rows 14 days after delivery, kept that long only to serve
|
||||||
the trailing-window `ReminderRollup` stats, and reaps acked todo rows
|
the trailing-window `ReminderRollup` stats, and reaps acked todo rows
|
||||||
30 days after acking (long enough that only a genuinely quiet
|
30 days after acking (long enough that only a genuinely quiet
|
||||||
|
|
@ -277,7 +235,6 @@ Under `/var/lib/hyperhive/agents/<name>/`:
|
||||||
swept — same "audit trail, not cache" treatment as the c0re-side
|
swept — same "audit trail, not cache" treatment as the c0re-side
|
||||||
tables above.
|
tables above.
|
||||||
|
|
||||||
- `hyperhive-events.sqlite` — turn-loop event log.
|
|
||||||
- `hyperhive-turn-stats.sqlite` — per-turn timing stats.
|
- `hyperhive-turn-stats.sqlite` — per-turn timing stats.
|
||||||
- `hyperhive-model` / `hyperhive-effort` — single-line model name and
|
- `hyperhive-model` / `hyperhive-effort` — single-line model name and
|
||||||
effort level files, read-only fallbacks.
|
effort level files, read-only fallbacks.
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ across `destroy`/recreate (`--purge` wipes them).
|
||||||
The harness exposes the same path
|
The harness exposes the same path
|
||||||
via `$HYPERHIVE_STATE_DIR`. System prompts tell agents to keep
|
via `$HYPERHIVE_STATE_DIR`. System prompts tell agents to keep
|
||||||
durable knowledge here (`notes.md`, anything else) — the harness's own
|
durable knowledge here (`notes.md`, anything else) — the harness's own
|
||||||
internal files (`hyperhive-events.sqlite`, `hyperhive-turn-stats.sqlite`,
|
internal files (`hyperhive-turn-stats.sqlite`,
|
||||||
`hyperhive-model`) live in the separate `harness` dir instead, so they
|
`hyperhive-model`) live in the separate `harness` dir instead, so they
|
||||||
don't clutter what claude sees as "my notes dir" (see
|
don't clutter what claude sees as "my notes dir" (see
|
||||||
[`docs/4-implementation/agent-state/persistence.md`](../../4-implementation/agent-state/persistence.md)). Survives `destroy`/recreate
|
[`docs/4-implementation/agent-state/persistence.md`](../../4-implementation/agent-state/persistence.md)). Survives `destroy`/recreate
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,11 @@
|
||||||
//! future events; the dashboard JS deals with the cold-start case by
|
//! future events; the dashboard JS deals with the cold-start case by
|
||||||
//! showing "connecting…" until the first event arrives.
|
//! showing "connecting…" until the first event arrives.
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering};
|
||||||
use std::sync::{Arc, Mutex, OnceLock};
|
use std::sync::{Arc, Mutex, OnceLock};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use hive_claude::TokenUsage;
|
use hive_claude::TokenUsage;
|
||||||
use rusqlite::{Connection, params};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use swarm_wire::agent_inference::Source;
|
use swarm_wire::agent_inference::Source;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
@ -25,38 +23,15 @@ use crate::harness_state::{
|
||||||
};
|
};
|
||||||
|
|
||||||
const CHANNEL_CAPACITY: usize = 256;
|
const CHANNEL_CAPACITY: usize = 256;
|
||||||
/// Path to the persisted event db. Overridable via `HYPERHIVE_EVENTS_DB`
|
|
||||||
/// for dev / tests; otherwise derived from the agent's harness dir.
|
|
||||||
fn events_db_path() -> PathBuf {
|
|
||||||
std::env::var_os("HYPERHIVE_EVENTS_DB").map_or_else(
|
|
||||||
|| crate::paths::harness_dir().join("hyperhive-events.sqlite"),
|
|
||||||
PathBuf::from,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const SCHEMA: &str = "
|
|
||||||
CREATE TABLE IF NOT EXISTS events (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
ts INTEGER NOT NULL,
|
|
||||||
kind TEXT NOT NULL,
|
|
||||||
payload_json TEXT NOT NULL
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_events_ts ON events (ts);
|
|
||||||
";
|
|
||||||
|
|
||||||
/// Envelope carried over the broadcast channel: the `LiveEvent` itself
|
/// Envelope carried over the broadcast channel: the `LiveEvent` itself
|
||||||
/// plus a monotonic per-process seq stamped by `Bus::emit`. SSE consumers
|
/// plus a monotonic per-process seq stamped by `Bus::emit`. SSE consumers
|
||||||
/// serialize this directly (seq becomes a sibling of the `kind` tag);
|
/// serialize this directly (seq becomes a sibling of the `kind` tag).
|
||||||
/// clients use seq to dedupe their buffered live traffic against the
|
|
||||||
/// snapshot/history responses (drop anything with `seq <= snapshot.seq`).
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct BusEvent {
|
pub struct BusEvent {
|
||||||
pub seq: u64,
|
pub seq: u64,
|
||||||
/// Unix seconds at emit time. Serialized as a sibling of the `kind`
|
/// Unix seconds at emit time. Serialized as a sibling of the `kind`
|
||||||
/// tag so the agent terminal can render turn start/end times (and
|
/// tag so the agent terminal can render turn start/end times (and
|
||||||
/// turn duration) on the live stream; history rows carry the same
|
/// turn duration) on the live stream.
|
||||||
/// `ts` field sourced from the persisted `events.ts` column, so the
|
|
||||||
/// renderer reads `ts` identically for live + scrollback.
|
|
||||||
pub ts: i64,
|
pub ts: i64,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub event: LiveEvent,
|
pub event: LiveEvent,
|
||||||
|
|
@ -86,9 +61,9 @@ pub enum LiveEvent {
|
||||||
/// enums can't flatten a tag onto a primitive newtype, and serde
|
/// enums can't flatten a tag onto a primitive newtype, and serde
|
||||||
/// fails serialization at runtime — silently, because the SSE
|
/// fails serialization at runtime — silently, because the SSE
|
||||||
/// handler's `filter_map(... .ok()? ...)` swallows the error, so a
|
/// handler's `filter_map(... .ok()? ...)` swallows the error, so a
|
||||||
/// regression here goes unnoticed until the sqlite history shows
|
/// regression here goes unnoticed until a reader sees
|
||||||
/// `"null"` rows. The web UI's `note` renderer already reads
|
/// `"null"` rows. The `note` renderer reads `ev.text`, so the wire shape
|
||||||
/// `ev.text`, so the wire shape matches without a JS change.
|
/// matches without a JS change.
|
||||||
Note { text: String },
|
Note { text: String },
|
||||||
/// Turn finished. `ok=false` means claude exited non-zero or the
|
/// Turn finished. `ok=false` means claude exited non-zero or the
|
||||||
/// harness hit a transport error.
|
/// harness hit a transport error.
|
||||||
|
|
@ -121,54 +96,8 @@ pub enum LiveEvent {
|
||||||
TurnStateChanged { state: TurnState, since_unix: i64 },
|
TurnStateChanged { state: TurnState, since_unix: i64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// sqlite-backed event log. Wraps a `Connection` behind a `Mutex` so the
|
|
||||||
/// `Bus` (which clones cheaply) shares one writer.
|
|
||||||
struct EventStore {
|
|
||||||
conn: Mutex<Connection>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventStore {
|
|
||||||
fn open(path: &Path) -> rusqlite::Result<Self> {
|
|
||||||
if let Some(parent) = path.parent() {
|
|
||||||
let _ = std::fs::create_dir_all(parent);
|
|
||||||
}
|
|
||||||
let conn = Connection::open(path)?;
|
|
||||||
crate::sqlite_writer::configure_wal(&conn)?;
|
|
||||||
conn.execute_batch(SCHEMA)?;
|
|
||||||
Ok(Self {
|
|
||||||
conn: Mutex::new(conn),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn append(&self, event: &LiveEvent) -> rusqlite::Result<()> {
|
|
||||||
let ts = std::time::SystemTime::now()
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.ok()
|
|
||||||
.and_then(|d| i64::try_from(d.as_secs()).ok())
|
|
||||||
.unwrap_or(0);
|
|
||||||
let kind = match event {
|
|
||||||
LiveEvent::TurnStart { .. } => "turn_start",
|
|
||||||
LiveEvent::Stream(_) => "stream",
|
|
||||||
LiveEvent::Note { .. } => "note",
|
|
||||||
LiveEvent::TurnEnd { .. } => "turn_end",
|
|
||||||
LiveEvent::StatusChanged { .. } => "status_changed",
|
|
||||||
LiveEvent::ModelChanged { .. } => "model_changed",
|
|
||||||
LiveEvent::EffortChanged { .. } => "effort_changed",
|
|
||||||
LiveEvent::TokenUsageChanged { .. } => "token_usage_changed",
|
|
||||||
LiveEvent::TurnStateChanged { .. } => "turn_state_changed",
|
|
||||||
};
|
|
||||||
let payload = serde_json::to_string(event).unwrap_or_else(|_| "null".into());
|
|
||||||
let conn = self.conn.lock().unwrap();
|
|
||||||
conn.execute(
|
|
||||||
"INSERT INTO events (ts, kind, payload_json) VALUES (?1, ?2, ?3)",
|
|
||||||
params![ts, kind, payload],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Authoritative turn-loop state. The harness owns it; the web UI
|
/// Authoritative turn-loop state. The harness owns it; the web UI
|
||||||
/// reads via `/api/state` and renders. Lives alongside the bus
|
/// is published to the swarm queue for the swarm UI. Lives alongside the bus
|
||||||
/// because everyone who has a `Bus` already has the right handle to
|
/// because everyone who has a `Bus` already has the right handle to
|
||||||
/// poke the state on transitions.
|
/// poke the state on transitions.
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
|
|
@ -196,13 +125,7 @@ pub struct Bus {
|
||||||
/// Monotonic per-process counter stamped onto every `BusEvent`.
|
/// Monotonic per-process counter stamped onto every `BusEvent`.
|
||||||
/// Persisted nowhere — a harness restart resets seq to 0; clients
|
/// Persisted nowhere — a harness restart resets seq to 0; clients
|
||||||
/// always treat reconnect as "fresh state, fresh stream of seqs."
|
/// always treat reconnect as "fresh state, fresh stream of seqs."
|
||||||
/// Historical events served from sqlite carry no seq (they predate
|
|
||||||
/// the live channel the seq is meant to dedupe against).
|
|
||||||
event_seq: Arc<AtomicU64>,
|
event_seq: Arc<AtomicU64>,
|
||||||
/// Persistent event log. `None` only if opening the sqlite db failed
|
|
||||||
/// at construction — we keep going so the harness doesn't die on a
|
|
||||||
/// missing state dir mount in dev / test scenarios.
|
|
||||||
store: Option<Arc<EventStore>>,
|
|
||||||
/// Current turn-loop state + since-when (unix seconds).
|
/// Current turn-loop state + since-when (unix seconds).
|
||||||
state: Arc<Mutex<(TurnState, i64)>>,
|
state: Arc<Mutex<(TurnState, i64)>>,
|
||||||
/// Model name passed to `claude --model`. Default `haiku`; a value the
|
/// Model name passed to `claude --model`. Default `haiku`; a value the
|
||||||
|
|
@ -229,8 +152,8 @@ pub struct Bus {
|
||||||
/// `hyperhive-harness.json` (see `harness_state`), so the host can
|
/// `hyperhive-harness.json` (see `harness_state`), so the host can
|
||||||
/// surface the status on the dashboard without a live socket call.
|
/// surface the status on the dashboard without a live socket call.
|
||||||
rate_limited: Arc<AtomicBool>,
|
rate_limited: Arc<AtomicBool>,
|
||||||
/// One-shot: operator asked to reset the claude session (`POST
|
/// One-shot: operator asked to reset the claude session (the swarm
|
||||||
/// /api/new-session`). Consumed at the *next* turn boundary by
|
/// UI's `/clear`). Consumed at the *next* turn boundary by
|
||||||
/// `turn::drive_turn`, which archives the current session so the turn
|
/// `turn::drive_turn`, which archives the current session so the turn
|
||||||
/// starts fresh. Deferred (not applied in the handler) so the archive
|
/// starts fresh. Deferred (not applied in the handler) so the archive
|
||||||
/// never races a claude process mid-write — one claude per container,
|
/// never races a claude process mid-write — one claude per container,
|
||||||
|
|
@ -258,7 +181,7 @@ pub struct Bus {
|
||||||
post_compact_wake: Arc<Mutex<Option<String>>>,
|
post_compact_wake: Arc<Mutex<Option<String>>>,
|
||||||
/// Stops the turn in flight, for a runtime that offers it (ACP). Set once
|
/// Stops the turn in flight, for a runtime that offers it (ACP). Set once
|
||||||
/// by the serve loop when it builds the session; unset on claude, whose
|
/// by the serve loop when it builds the session; unset on claude, whose
|
||||||
/// turn `/api/cancel` stops by signalling the `claude` process.
|
/// turn the swarm UI's cancel stops by signalling the `claude` process.
|
||||||
turn_canceller: Arc<OnceLock<hive_runtime::Canceller>>,
|
turn_canceller: Arc<OnceLock<hive_runtime::Canceller>>,
|
||||||
/// Current fresh-claude-session id (FK to `sessions.id`). Set by the
|
/// Current fresh-claude-session id (FK to `sessions.id`). Set by the
|
||||||
/// bin loop after minting a session row on a fresh start; stamped onto
|
/// bin loop after minting a session row on a fresh start; stamped onto
|
||||||
|
|
@ -306,18 +229,10 @@ pub struct Bus {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bus {
|
impl Bus {
|
||||||
/// Open the events db (path from `events_db_path()`). On failure, fall back
|
/// A bus with no subscribers and the model, effort and rate-limit state the harness
|
||||||
/// to a no-store bus — the harness still works, just without persistent history.
|
/// last recorded.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let path = events_db_path();
|
|
||||||
let store = match EventStore::open(&path) {
|
|
||||||
Ok(s) => Some(Arc::new(s)),
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(error = ?e, path = %path.display(), "events db open failed; running without history");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let (tx, _) = broadcast::channel(CHANNEL_CAPACITY);
|
let (tx, _) = broadcast::channel(CHANNEL_CAPACITY);
|
||||||
let (initial_model, model_source) = local_model(configured_model());
|
let (initial_model, model_source) = local_model(configured_model());
|
||||||
let (initial_effort, effort_source) = local_effort(configured_effort());
|
let (initial_effort, effort_source) = local_effort(configured_effort());
|
||||||
|
|
@ -328,7 +243,6 @@ impl Bus {
|
||||||
Self {
|
Self {
|
||||||
tx: Arc::new(tx),
|
tx: Arc::new(tx),
|
||||||
event_seq: Arc::new(AtomicU64::new(0)),
|
event_seq: Arc::new(AtomicU64::new(0)),
|
||||||
store,
|
|
||||||
state: Arc::new(Mutex::new((TurnState::Idle, Utc::now().timestamp()))),
|
state: Arc::new(Mutex::new((TurnState::Idle, Utc::now().timestamp()))),
|
||||||
model: Arc::new(Mutex::new(initial_model)),
|
model: Arc::new(Mutex::new(initial_model)),
|
||||||
effort: Arc::new(Mutex::new(initial_effort)),
|
effort: Arc::new(Mutex::new(initial_effort)),
|
||||||
|
|
@ -368,7 +282,7 @@ impl Bus {
|
||||||
self.turn_canceller.get()
|
self.turn_canceller.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request a session reset (operator `POST /api/new-session`). Deferred:
|
/// Request a session reset (the swarm UI's `/clear`). Deferred:
|
||||||
/// the flag is consumed at the next turn boundary by `drive_turn`, which
|
/// the flag is consumed at the next turn boundary by `drive_turn`, which
|
||||||
/// archives the current session so no claude process is mid-write when the
|
/// archives the current session so no claude process is mid-write when the
|
||||||
/// file is renamed. Idempotent — two clicks before the next turn still
|
/// file is renamed. Idempotent — two clicks before the next turn still
|
||||||
|
|
@ -766,10 +680,9 @@ impl Bus {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Broadcast a status flip (online / `needs_login_idle` / `rate_limited`).
|
/// Broadcast a status flip (online / `needs_login_idle` / `rate_limited`).
|
||||||
/// Called by the bin entry points + `turn::wait_for_login` + the
|
/// Called by the bin entry points + `turn::wait_for_login` + the login
|
||||||
/// `/api/logout` handler — every site that mutates the
|
/// watch — every site that mutates the `Arc<Mutex<LoginState>>` should
|
||||||
/// `Arc<Mutex<LoginState>>` should also call this so the web UI
|
/// also call this so the status the swarm reads follows it.
|
||||||
/// drops its periodic /api/state poll while a turn loop is running.
|
|
||||||
///
|
///
|
||||||
/// `hyperhive-harness.json` persists across harness restarts so the
|
/// `hyperhive-harness.json` persists across harness restarts so the
|
||||||
/// host-side dashboard can render the status without a live socket call:
|
/// host-side dashboard can render the status without a live socket call:
|
||||||
|
|
@ -830,11 +743,6 @@ impl Bus {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit(&self, event: LiveEvent) {
|
pub fn emit(&self, event: LiveEvent) {
|
||||||
if let Some(store) = &self.store
|
|
||||||
&& let Err(e) = store.append(&event)
|
|
||||||
{
|
|
||||||
tracing::warn!(error = ?e, "events: append failed");
|
|
||||||
}
|
|
||||||
let envelope = BusEvent {
|
let envelope = BusEvent {
|
||||||
seq: self.next_seq(),
|
seq: self.next_seq(),
|
||||||
ts: Utc::now().timestamp(),
|
ts: Utc::now().timestamp(),
|
||||||
|
|
@ -902,8 +810,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bus_event_serializes_ts_and_seq_beside_kind() {
|
fn bus_event_serializes_ts_and_seq_beside_kind() {
|
||||||
// Live SSE frame: same `ts` sibling as history (plus `seq`), so the
|
// Live SSE frame: `ts` and `seq` are siblings of `kind`.
|
||||||
// renderer is path-agnostic between live + scrollback.
|
|
||||||
let v = serde_json::to_value(BusEvent {
|
let v = serde_json::to_value(BusEvent {
|
||||||
seq: 7,
|
seq: 7,
|
||||||
ts: 1_700_000_000,
|
ts: 1_700_000_000,
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,7 @@ pub fn default_dir() -> PathBuf {
|
||||||
/// exactly these to force re-login while preserving session-history files —
|
/// exactly these to force re-login while preserving session-history files —
|
||||||
/// so boot detection ([`has_session`]) and logout agree by construction.
|
/// so boot detection ([`has_session`]) and logout agree by construction.
|
||||||
/// Rationale + the previous wholesale-wipe shape we replaced live in
|
/// Rationale + the previous wholesale-wipe shape we replaced live in
|
||||||
/// `docs/4-implementation/web-ui/agent-page.md::Per-agent endpoints`
|
/// the login watch (`login_watch.rs`).
|
||||||
/// (the `/api/logout` bullet).
|
|
||||||
///
|
///
|
||||||
/// `.credentials.json` is the actual OAuth session; `mcp-needs-auth-cache.json`
|
/// `.credentials.json` is the actual OAuth session; `mcp-needs-auth-cache.json`
|
||||||
/// is claude-code's MCP-auth cache and a weaker signal. Both are kept in the
|
/// is claude-code's MCP-auth cache and a weaker signal. Both are kept in the
|
||||||
|
|
@ -168,7 +167,7 @@ pub async fn wait_for_login(
|
||||||
);
|
);
|
||||||
// Announce `needs_login_idle` to the bus so
|
// Announce `needs_login_idle` to the bus so
|
||||||
// `hyperhive-harness.json` records it on every entry path —
|
// `hyperhive-harness.json` records it on every entry path —
|
||||||
// cold-boot, 401-mid-turn, and `/api/logout`. The host reads that
|
// cold-boot, 401-mid-turn, and the login watch's logout. The host reads that
|
||||||
// file to surface `needs_login` on the dashboard. Idempotent —
|
// file to surface `needs_login` on the dashboard. Idempotent —
|
||||||
// re-entering this function after a transient operator action
|
// re-entering this function after a transient operator action
|
||||||
// rewrites the same on-disk state.
|
// rewrites the same on-disk state.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
//! while waiting ([`crate::claude_credentials`]).
|
//! while waiting ([`crate::claude_credentials`]).
|
||||||
//! - A store that answers "nothing stored" after a version was installed here
|
//! - A store that answers "nothing stored" after a version was installed here
|
||||||
//! means the operator deleted the stored login: the agent is logged out as
|
//! means the operator deleted the stored login: the agent is logged out as
|
||||||
//! `/api/logout` does it, and the recorded version is forgotten so the next
|
//! the harness does it, and the recorded version is forgotten so the next
|
||||||
//! login installs.
|
//! login installs.
|
||||||
//! - A read that fails does nothing. A store that cannot be reached says
|
//! - A read that fails does nothing. A store that cannot be reached says
|
||||||
//! nothing about the login, and logging out on it would turn a store restart
|
//! nothing about the login, and logging out on it would turn a store restart
|
||||||
|
|
|
||||||
|
|
@ -524,7 +524,7 @@ async fn serve_main<S: Surface>(socket: &Path, poll_ms: u64) -> Result<()> {
|
||||||
tokio::spawn(swarm_inference::run(bus.clone()));
|
tokio::spawn(swarm_inference::run(bus.clone()));
|
||||||
// The permissions the swarm grants this agent, read before each turn.
|
// The permissions the swarm grants this agent, read before each turn.
|
||||||
tokio::spawn(swarm_permissions::run());
|
tokio::spawn(swarm_permissions::run());
|
||||||
// Set by the web UI's `/api/cancel` on a successful SIGINT, read-and-
|
// Set by a cancel (the swarm UI's cancel command) on a successful SIGINT, read-and-
|
||||||
// cleared by `handle_turn` before building the next wake prompt — see
|
// cleared by `handle_turn` before building the next wake prompt — see
|
||||||
// `hive_sh4re::inbox::INTERRUPTED_HINT`. Shared between the web server task and
|
// `hive_sh4re::inbox::INTERRUPTED_HINT`. Shared between the web server task and
|
||||||
// the serve loop the same way `bus`/`todo_wake` are.
|
// the serve loop the same way `bus`/`todo_wake` are.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! All agents (including the manager `root`) use `/agents/{label}/state`
|
//! All agents (including the manager `root`) use `/agents/{label}/state`
|
||||||
//! for agent-owned durable notes, and `/agents/{label}/harness` for
|
//! for agent-owned durable notes, and `/agents/{label}/harness` for
|
||||||
//! harness-internal files (`hyperhive-events.sqlite`, `hyperhive-model`, etc.)
|
//! harness-internal files (`hyperhive-turn-stats.sqlite`, `hyperhive-model`, etc.)
|
||||||
//! that should not clutter what claude sees as "my notes dir".
|
//! that should not clutter what claude sees as "my notes dir".
|
||||||
//! Claude credentials live at `$HOME/.claude` (resolves to
|
//! Claude credentials live at `$HOME/.claude` (resolves to
|
||||||
//! `/home/<agent-name>/.claude` because the harness service runs as a
|
//! `/home/<agent-name>/.claude` because the harness service runs as a
|
||||||
|
|
@ -28,7 +28,7 @@ pub fn state_dir() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Harness-internal state directory. Holds files the harness owns
|
/// Harness-internal state directory. Holds files the harness owns
|
||||||
/// (`hyperhive-events.sqlite`, `hyperhive-turn-stats.sqlite`,
|
/// (`hyperhive-turn-stats.sqlite`,
|
||||||
/// `hyperhive-model`) so they do not appear inside the agent-visible
|
/// `hyperhive-model`) so they do not appear inside the agent-visible
|
||||||
/// `/agents/{label}/state` tree. Delegates to the shared canonical
|
/// `/agents/{label}/state` tree. Delegates to the shared canonical
|
||||||
/// resolver in `hive_agent_sock::paths` so the harness + every
|
/// resolver in `hive_agent_sock::paths` so the harness + every
|
||||||
|
|
@ -41,8 +41,8 @@ pub fn harness_dir() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consolidated harness-local state db — todos + reminders, one table
|
/// Consolidated harness-local state db — todos + reminders, one table
|
||||||
/// each — mutable per-agent state the harness owns, kept out of the
|
/// each — mutable per-agent state the harness owns, kept apart
|
||||||
/// append-only `hyperhive-events.sqlite` sink. Each store's `open()` only
|
/// from the append-only turn-stats db. Each store's `open()` only
|
||||||
/// applies its own `CREATE TABLE IF NOT EXISTS` against this same path
|
/// applies its own `CREATE TABLE IF NOT EXISTS` against this same path
|
||||||
/// (see their call sites), so distinct table names keep them from
|
/// (see their call sites), so distinct table names keep them from
|
||||||
/// colliding without needing a per-store path wrapper here.
|
/// colliding without needing a per-store path wrapper here.
|
||||||
|
|
|
||||||
|
|
@ -1,99 +1,10 @@
|
||||||
//! Shared connection setup for the harness's own sqlite writers.
|
//! Shared connection setup for the harness's own sqlite writers.
|
||||||
//!
|
//!
|
||||||
//! The default rollback journal costs an fsync per commit and takes an
|
//! A write that overlaps another connection's lock (the stats page, the hourly
|
||||||
//! exclusive lock, so a write that overlaps a read on another connection (the
|
//! vacuum) fails at once with `SQLITE_BUSY` unless the connection has a busy
|
||||||
//! stats page, the hourly vacuum) fails at once with `SQLITE_BUSY`. WAL with
|
//! timeout, so writers set [`BUSY_TIMEOUT`] to wait instead of dropping the row.
|
||||||
//! `synchronous=NORMAL` removes the per-row fsync and lets readers and the
|
|
||||||
//! writer overlap, and the busy timeout makes the remaining writer-vs-writer
|
|
||||||
//! overlap wait instead of dropping the row.
|
|
||||||
//!
|
|
||||||
//! WAL is only for databases that nothing outside the agent reads: a
|
|
||||||
//! read-only connection to a WAL database needs the `-wal` and `-shm`
|
|
||||||
//! sidecars to exist or be creatable, and hive-c0re reads as another uid
|
|
||||||
//! across the agent-owned harness dir. Such a database takes just
|
|
||||||
//! [`BUSY_TIMEOUT`].
|
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use rusqlite::Connection;
|
|
||||||
|
|
||||||
/// How long a writer waits on a locked database before giving up.
|
/// How long a writer waits on a locked database before giving up.
|
||||||
pub const BUSY_TIMEOUT: Duration = Duration::from_secs(5);
|
pub const BUSY_TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
/// Put `conn` into WAL mode with `synchronous=NORMAL` and a busy timeout.
|
|
||||||
///
|
|
||||||
/// The timeout is set first so the journal-mode switch, which needs a lock,
|
|
||||||
/// waits too. `journal_mode` persists in the database file; the other two are
|
|
||||||
/// per connection, so every writer connection calls this.
|
|
||||||
///
|
|
||||||
/// When sqlite answers the switch with the old mode (it does that, not an
|
|
||||||
/// error, on a filesystem that cannot do WAL), this logs a warning and leaves
|
|
||||||
/// the database in that mode: a working rollback-journal database beats no
|
|
||||||
/// database.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
///
|
|
||||||
/// Propagates sqlite pragma failures.
|
|
||||||
pub fn configure_wal(conn: &Connection) -> rusqlite::Result<()> {
|
|
||||||
conn.busy_timeout(BUSY_TIMEOUT)?;
|
|
||||||
let mode =
|
|
||||||
conn.pragma_update_and_check(None, "journal_mode", "WAL", |row| row.get::<_, String>(0))?;
|
|
||||||
if !mode.eq_ignore_ascii_case("wal") {
|
|
||||||
tracing::warn!(%mode, "sqlite journal_mode stayed put instead of switching to wal");
|
|
||||||
}
|
|
||||||
conn.pragma_update(None, "synchronous", "NORMAL")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn configure_wal_sets_wal_normal_sync_and_busy_timeout() {
|
|
||||||
let dir = tempfile::tempdir().unwrap();
|
|
||||||
let conn = Connection::open(dir.path().join("w.sqlite")).unwrap();
|
|
||||||
configure_wal(&conn).unwrap();
|
|
||||||
|
|
||||||
let mode: String = conn
|
|
||||||
.query_row("PRAGMA journal_mode", [], |r| r.get(0))
|
|
||||||
.unwrap();
|
|
||||||
let sync: i64 = conn
|
|
||||||
.query_row("PRAGMA synchronous", [], |r| r.get(0))
|
|
||||||
.unwrap();
|
|
||||||
let busy: i64 = conn
|
|
||||||
.query_row("PRAGMA busy_timeout", [], |r| r.get(0))
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(mode, "wal");
|
|
||||||
assert_eq!(sync, 1, "NORMAL");
|
|
||||||
assert_eq!(busy, 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn configure_wal_keeps_a_database_that_cannot_switch_usable() {
|
|
||||||
// An in-memory database cannot switch to WAL; sqlite answers "memory".
|
|
||||||
let conn = Connection::open_in_memory().unwrap();
|
|
||||||
configure_wal(&conn).unwrap();
|
|
||||||
let mode: String = conn
|
|
||||||
.query_row("PRAGMA journal_mode", [], |r| r.get(0))
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(mode, "memory");
|
|
||||||
conn.execute_batch("CREATE TABLE t(x); INSERT INTO t VALUES (1)")
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn a_second_connection_still_sees_committed_rows() {
|
|
||||||
let dir = tempfile::tempdir().unwrap();
|
|
||||||
let path = dir.path().join("w.sqlite");
|
|
||||||
let writer = Connection::open(&path).unwrap();
|
|
||||||
configure_wal(&writer).unwrap();
|
|
||||||
writer.execute_batch("CREATE TABLE t(x)").unwrap();
|
|
||||||
let reader = Connection::open(&path).unwrap();
|
|
||||||
configure_wal(&reader).unwrap();
|
|
||||||
writer.execute("INSERT INTO t VALUES (1)", []).unwrap();
|
|
||||||
let n: i64 = reader
|
|
||||||
.query_row("SELECT COUNT(*) FROM t", [], |r| r.get(0))
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(n, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -427,7 +427,7 @@ fn acp_permits(ask: &PermissionAsk<'_>, web: bool) -> bool {
|
||||||
/// the percent policy — including the pre-compaction checkpoint turn). This
|
/// the percent policy — including the pre-compaction checkpoint turn). This
|
||||||
/// layer wraps it with the two hyperhive-specific concerns:
|
/// layer wraps it with the two hyperhive-specific concerns:
|
||||||
///
|
///
|
||||||
/// - **Session reset (pre-turn)** — an operator reset (`/api/new-session`) or
|
/// - **Session reset (pre-turn)** — an operator reset (the swarm UI's `/clear`) or
|
||||||
/// the auto-reset heuristic (context large AND prompt cache gone cold)
|
/// the auto-reset heuristic (context large AND prompt cache gone cold)
|
||||||
/// archives the current session at this turn boundary so the run starts
|
/// archives the current session at this turn boundary so the run starts
|
||||||
/// fresh. The two are mutually exclusive. This is deliberately *not* part of
|
/// fresh. The two are mutually exclusive. This is deliberately *not* part of
|
||||||
|
|
@ -445,7 +445,7 @@ pub async fn drive_turn(
|
||||||
session: &AgentSession,
|
session: &AgentSession,
|
||||||
) -> TurnOutcome {
|
) -> TurnOutcome {
|
||||||
if bus.take_session_reset() {
|
if bus.take_session_reset() {
|
||||||
// Operator-requested (deferred from `POST /api/new-session`).
|
// Operator-requested (deferred from the swarm UI's `/clear`).
|
||||||
bus.emit(LiveEvent::Note {
|
bus.emit(LiveEvent::Note {
|
||||||
text: "operator: resetting session — archiving before this turn".into(),
|
text: "operator: resetting session — archiving before this turn".into(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
//! Agent-side cleanup of this agent's own harness artifacts: completed
|
//! Agent-side cleanup of this agent's own harness artifacts: completed
|
||||||
//! bash-task files and verbose `stream` event rows.
|
//! bash-task files, delivered reminders and acked todos, and the event log an
|
||||||
|
//! earlier harness wrote.
|
||||||
//!
|
//!
|
||||||
//! Runs IN the harness (not host-side in hive-c0re) because the files are
|
//! Runs IN the harness (not host-side in hive-c0re) because the files are
|
||||||
//! owned by the agent user. Under privsep hive-c0re runs as the unprivileged
|
//! owned by the agent user. Under privsep hive-c0re runs as the unprivileged
|
||||||
//! `hive-core` user and cannot delete agent-owned files — the old host-side
|
//! `hive-core` user and cannot delete agent-owned files — the old host-side
|
||||||
//! sweeps hit `PermissionDenied` on the bash-task trio and an
|
//! sweeps hit `PermissionDenied` on the bash-task trio and an
|
||||||
//! attempt-to-write-a-readonly-database error on `events.sqlite`. The harness
|
//! attempt-to-write-a-readonly-database error on a harness database. The harness
|
||||||
//! owns these paths, so the deletes succeed here.
|
//! owns these paths, so the deletes succeed here.
|
||||||
//!
|
//!
|
||||||
//! Trade-off (accepted — issue tracker "perms borked"): a misbehaving harness
|
//! Trade-off (accepted — issue tracker "perms borked"): a misbehaving harness
|
||||||
|
|
@ -17,16 +18,10 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use rusqlite::{Connection, Result, params};
|
|
||||||
|
|
||||||
/// How often the sweep runs.
|
/// How often the sweep runs.
|
||||||
const VACUUM_INTERVAL: Duration = Duration::from_hours(1);
|
const VACUUM_INTERVAL: Duration = Duration::from_hours(1);
|
||||||
/// Keep completed bash-task files this long before deleting their trio.
|
/// Keep completed bash-task files this long before deleting their trio.
|
||||||
const BASH_KEEP_SECS: i64 = 48 * 3600;
|
const BASH_KEEP_SECS: i64 = 48 * 3600;
|
||||||
/// Keep verbose `stream` event rows this long before pruning. Other event
|
|
||||||
/// kinds are never deleted by this sweep — they carry the semantic per-turn
|
|
||||||
/// history the operator scrolls back through.
|
|
||||||
const STREAM_KEEP_SECS: i64 = 14 * 24 * 3600;
|
|
||||||
/// Keep delivered (soft-deleted, `sent_at` set) reminder rows this long
|
/// Keep delivered (soft-deleted, `sent_at` set) reminder rows this long
|
||||||
/// before reaping them — same window as `STREAM_KEEP_SECS`, kept around
|
/// before reaping them — same window as `STREAM_KEEP_SECS`, kept around
|
||||||
/// only to serve the trailing-window `ReminderRollup` stats.
|
/// only to serve the trailing-window `ReminderRollup` stats.
|
||||||
|
|
@ -41,7 +36,7 @@ const TODO_ACKED_KEEP_SECS: i64 = 30 * 24 * 3600;
|
||||||
const TERMINAL_STATUSES: &[&str] = &["done", "timed_out", "interrupted"];
|
const TERMINAL_STATUSES: &[&str] = &["done", "timed_out", "interrupted"];
|
||||||
|
|
||||||
/// Background loop: hourly, prune this agent's stale bash-task files and
|
/// Background loop: hourly, prune this agent's stale bash-task files and
|
||||||
/// verbose event rows. Detached task — runs for the harness's lifetime;
|
/// the event log an earlier harness left behind. Detached task — runs for the harness's lifetime;
|
||||||
/// errors are logged, never fatal.
|
/// errors are logged, never fatal.
|
||||||
pub async fn run() {
|
pub async fn run() {
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -62,14 +57,7 @@ fn sweep_once() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let events_db = harness.join("hyperhive-events.sqlite");
|
remove_old_event_log(&harness);
|
||||||
if events_db.exists() {
|
|
||||||
match vacuum_events(&events_db) {
|
|
||||||
Ok(0) => {}
|
|
||||||
Ok(n) => tracing::info!(removed = n, "events vacuum"),
|
|
||||||
Err(e) => tracing::warn!(error = ?e, "events vacuum failed"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let state_db = crate::paths::state_db();
|
let state_db = crate::paths::state_db();
|
||||||
if state_db.exists() {
|
if state_db.exists() {
|
||||||
|
|
@ -87,8 +75,7 @@ fn sweep_once() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reap delivered reminder rows older than [`REMINDER_KEEP_SECS`] via the
|
/// Reap delivered reminder rows older than [`REMINDER_KEEP_SECS`] via the
|
||||||
/// typed store API (own short-lived connection — mirrors `vacuum_events`'s
|
/// typed store API (own short-lived connection rather than the harness's live
|
||||||
/// own connection to `events.sqlite` rather than sharing the harness's live
|
|
||||||
/// `Reminders` handle).
|
/// `Reminders` handle).
|
||||||
fn vacuum_reminders(path: &Path) -> anyhow::Result<usize> {
|
fn vacuum_reminders(path: &Path) -> anyhow::Result<usize> {
|
||||||
let store = crate::reminders::Reminders::open(path)?;
|
let store = crate::reminders::Reminders::open(path)?;
|
||||||
|
|
@ -165,15 +152,21 @@ fn delete_trio(dir: &Path, stem: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prune verbose `stream` event rows older than [`STREAM_KEEP_SECS`] from the
|
/// Delete the sqlite event log (and its WAL files) that harnesses used to
|
||||||
/// agent's `events.sqlite`. Returns the number of rows deleted.
|
/// write for the per-agent page's history. Nothing reads or writes it now.
|
||||||
fn vacuum_events(path: &Path) -> Result<u64> {
|
fn remove_old_event_log(harness: &Path) {
|
||||||
let conn = Connection::open(path)?;
|
for name in [
|
||||||
crate::sqlite_writer::configure_wal(&conn)?;
|
"hyperhive-events.sqlite",
|
||||||
let cutoff = chrono::Utc::now().timestamp() - STREAM_KEEP_SECS;
|
"hyperhive-events.sqlite-wal",
|
||||||
let removed = conn.execute(
|
"hyperhive-events.sqlite-shm",
|
||||||
"DELETE FROM events WHERE kind = 'stream' AND ts < ?1",
|
] {
|
||||||
params![cutoff],
|
let path = harness.join(name);
|
||||||
)?;
|
match std::fs::remove_file(&path) {
|
||||||
Ok(u64::try_from(removed).unwrap_or(0))
|
Ok(()) => tracing::info!(path = %path.display(), "removed the old event log"),
|
||||||
|
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(path = %path.display(), error = %e, "removing the old event log failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use super::LoginStateCell;
|
||||||
/// the credential files (via [`crate::login::clear_session`]) and flip
|
/// the credential files (via [`crate::login::clear_session`]) and flip
|
||||||
/// `LoginState::NeedsLogin`; `by` heads the Note. Returns what was wiped, for the response.
|
/// `LoginState::NeedsLogin`; `by` heads the Note. Returns what was wiped, for the response.
|
||||||
pub(crate) async fn force_logout(login: &LoginStateCell, bus: &Bus, by: &str) -> String {
|
pub(crate) async fn force_logout(login: &LoginStateCell, bus: &Bus, by: &str) -> String {
|
||||||
// Step 1: SIGINT claude (best-effort, matches `post_cancel_turn`).
|
// Step 1: SIGINT claude (best-effort, as a cancel does).
|
||||||
let _ = super::sigint_claude();
|
let _ = super::sigint_claude();
|
||||||
// Step 2: delete OAuth credential files only — login::clear_session owns
|
// Step 2: delete OAuth credential files only — login::clear_session owns
|
||||||
// the file set and preserves session-history files alongside them.
|
// the file set and preserves session-history files alongside them.
|
||||||
|
|
@ -35,7 +35,7 @@ pub(crate) async fn force_logout(login: &LoginStateCell, bus: &Bus, by: &str) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Human-readable summary of a [`crate::login::ClearedSession`] outcome for
|
/// Human-readable summary of a [`crate::login::ClearedSession`] outcome for
|
||||||
/// the `/api/logout` response + note. Deliberately distinguishes "nothing to
|
/// the login watch's note. Deliberately distinguishes "nothing to
|
||||||
/// delete" from "something's there but we couldn't delete it" — both leave
|
/// delete" from "something's there but we couldn't delete it" — both leave
|
||||||
/// `wiped` empty, but only the former is actually "already logged out";
|
/// `wiped` empty, but only the former is actually "already logged out";
|
||||||
/// conflating them would report a stuck undeletable `.credentials.json` as
|
/// conflating them would report a stuck undeletable `.credentials.json` as
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
//! Per-container HTTP UI. SPA shape: `GET /` returns a static shell;
|
//! Per-container HTTP server: the stats and screen pages (`GET /stats`,
|
||||||
//! `GET /static/*` serves CSS + JS; `GET /api/state` returns the page
|
//! `GET /screen`, `GET /static/*`), `GET /` redirecting to `/stats`, the small
|
||||||
//! state as JSON; the JS app renders. Live events stream on
|
//! JSON the dashboard card and those pages read (`/api/state`,
|
||||||
//! `/events/stream`. Action POSTs return either a
|
//! `/api/dashboard-state`, `/api/stats`) and the live event stream
|
||||||
//! 303 Redirect (for browsers that submit the form normally) or just
|
//! `/events/stream`.
|
||||||
//! 200 OK — the JS app re-fetches `/api/state` afterwards.
|
|
||||||
//!
|
//!
|
||||||
//! Handlers are split by concern into the submodules below; this file owns the
|
//! Handlers are split by concern into the submodules below; this file owns the
|
||||||
//! shared [`AppState`], the listener + router wiring in [`serve`], and a couple
|
//! shared [`AppState`], the listener + router wiring in [`serve`], and the
|
||||||
//! of small shared helpers ([`error_response`], [`SOCKET_FETCH_TIMEOUT`]).
|
//! claude-signalling helpers the cancel command and the login watch share.
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
pub(crate) use auth::force_logout;
|
pub(crate) use auth::force_logout;
|
||||||
|
|
@ -230,8 +229,8 @@ fn read_gui_vnc_port() -> Option<u16> {
|
||||||
std::env::var("HIVE_GUI_VNC_PORT").ok()?.parse().ok()
|
std::env::var("HIVE_GUI_VNC_PORT").ok()?.parse().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Outcome of [`sigint_claude`] — shared by `/api/cancel` and `/api/logout`
|
/// Outcome of [`sigint_claude`] — shared by the cancel command and the login watch's
|
||||||
/// so both can render the same three cases.
|
/// logout so both can render the same three cases.
|
||||||
enum SigintOutcome {
|
enum SigintOutcome {
|
||||||
/// The tracked pid was signalled.
|
/// The tracked pid was signalled.
|
||||||
Signalled,
|
Signalled,
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ fn read_own_status() -> (Option<String>, Option<i64>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the navigation link list for the agent page header. URLs
|
/// Build the navigation link list for the dashboard card's icon strip. URLs
|
||||||
/// are paths (relative) for `Container` targets and absolute
|
/// are paths (relative) for `Container` targets and absolute
|
||||||
/// for `External`; the frontend resolves each against its `kind`
|
/// for `External`; the frontend resolves each against its `kind`
|
||||||
/// against the right base so the backend never has to guess the
|
/// against the right base so the backend never has to guess the
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub const REDELIVERY_HINT: &str = "[redelivered after harness restart — may al
|
||||||
/// Banner prepended to a wake prompt when the previous turn was cut off by
|
/// Banner prepended to a wake prompt when the previous turn was cut off by
|
||||||
/// an explicit operator `/cancel` (SIGINT) rather than ending normally. Set
|
/// an explicit operator `/cancel` (SIGINT) rather than ending normally. Set
|
||||||
/// once, read-and-cleared by the next turn's wake-prompt build — see
|
/// once, read-and-cleared by the next turn's wake-prompt build — see
|
||||||
/// `hive-agent`'s `post_cancel_turn` (sets it) and `handle_turn` (clears
|
/// `hive-agent`'s cancel (sets it) and `handle_turn` (clears
|
||||||
/// it). Lives here for the same reason as `REDELIVERY_HINT`: a single
|
/// it). Lives here for the same reason as `REDELIVERY_HINT`: a single
|
||||||
/// phrasing, not duplicated between call sites.
|
/// phrasing, not duplicated between call sites.
|
||||||
pub const INTERRUPTED_HINT: &str = "[your previous turn was interrupted by the operator (/cancel) \
|
pub const INTERRUPTED_HINT: &str = "[your previous turn was interrupted by the operator (/cancel) \
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
//!
|
//!
|
||||||
//! [`classify_stream_value`] is the entry point — it walks one raw claude
|
//! [`classify_stream_value`] is the entry point — it walks one raw claude
|
||||||
//! `stream-json` line and returns zero or more terminal rows. Two callers:
|
//! `stream-json` line and returns zero or more terminal rows. Two callers:
|
||||||
//! `hive-agent` applies it at SSE-emit time, so both the live tail
|
//! `hive-agent` applies it at SSE-emit time, so the live tail
|
||||||
//! (`events/stream`) and the history replay (`events/history`) deliver the
|
//! (`events/stream`) delivers the same classified shape the swarm queue
|
||||||
//! same classified shape while the sqlite event log keeps the raw event; and
|
//! carries; and
|
||||||
//! `hive-subagent-mcp` applies it to each subagent's output before publishing
|
//! `hive-subagent-mcp` applies it to each subagent's output before publishing
|
||||||
//! it to the swarm queue.
|
//! it to the swarm queue.
|
||||||
//!
|
//!
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue