remove the agent's live terminal page and the endpoints only it used
This commit is contained in:
parent
802151820c
commit
6289b8d64b
1 changed files with 127 additions and 4053 deletions
|
|
@ -25,9 +25,6 @@ use crate::harness_state::{
|
|||
};
|
||||
|
||||
const CHANNEL_CAPACITY: usize = 256;
|
||||
/// Max `LiveEvent`s the `Bus` returns from `history()` and keeps in
|
||||
/// sqlite. Older rows are vacuumed on a periodic sweep.
|
||||
pub const HISTORY_CAPACITY: usize = 2000;
|
||||
/// 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 {
|
||||
|
|
@ -65,17 +62,6 @@ pub struct BusEvent {
|
|||
pub event: LiveEvent,
|
||||
}
|
||||
|
||||
/// A persisted event paired with its stored unix-seconds timestamp.
|
||||
/// Serializes with `ts` as a sibling of the `kind` tag — same wire shape
|
||||
/// as a live [`BusEvent`] minus `seq` — so the agent terminal reads `ts`
|
||||
/// identically whether an event arrives live or is replayed from history.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StoredEvent {
|
||||
pub ts: i64,
|
||||
#[serde(flatten)]
|
||||
pub event: LiveEvent,
|
||||
}
|
||||
|
||||
/// One row of the agent's live stream. Serialised to JSON for SSE delivery.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
|
|
@ -179,65 +165,6 @@ impl EventStore {
|
|||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Fetch up to `limit` events with id < `before_id` (or the most recent
|
||||
/// `limit` events when `before_id` is `None`). Returns
|
||||
/// `(events_oldest_first, min_row_id, has_more)`.
|
||||
fn page(
|
||||
&self,
|
||||
before_id: Option<i64>,
|
||||
limit: usize,
|
||||
) -> rusqlite::Result<(Vec<StoredEvent>, Option<i64>, bool)> {
|
||||
let limit_i = i64::try_from(limit).unwrap_or(i64::MAX);
|
||||
let conn = self.conn.lock().unwrap();
|
||||
// Fetch one extra row so we can tell whether more exist.
|
||||
let fetch = limit_i.saturating_add(1);
|
||||
// `ts` is the persisted emit-time unix-seconds stamp; carried out
|
||||
// alongside each event so history replay shows the same turn
|
||||
// start/end times the live stream did.
|
||||
let rows: Vec<(i64, StoredEvent)> = if let Some(bid) = before_id {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, ts, payload_json FROM events
|
||||
WHERE id < ?1
|
||||
ORDER BY id DESC
|
||||
LIMIT ?2",
|
||||
)?;
|
||||
stmt.query_map(params![bid, fetch], |row| {
|
||||
let id: i64 = row.get(0)?;
|
||||
let ts: i64 = row.get(1)?;
|
||||
let s: String = row.get(2)?;
|
||||
Ok(serde_json::from_str::<LiveEvent>(&s)
|
||||
.ok()
|
||||
.map(|event| (id, StoredEvent { ts, event })))
|
||||
})?
|
||||
.flatten()
|
||||
.flatten()
|
||||
.collect()
|
||||
} else {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, ts, payload_json FROM events
|
||||
ORDER BY id DESC
|
||||
LIMIT ?1",
|
||||
)?;
|
||||
stmt.query_map(params![fetch], |row| {
|
||||
let id: i64 = row.get(0)?;
|
||||
let ts: i64 = row.get(1)?;
|
||||
let s: String = row.get(2)?;
|
||||
Ok(serde_json::from_str::<LiveEvent>(&s)
|
||||
.ok()
|
||||
.map(|event| (id, StoredEvent { ts, event })))
|
||||
})?
|
||||
.flatten()
|
||||
.flatten()
|
||||
.collect()
|
||||
};
|
||||
let has_more = rows.len() > limit;
|
||||
let mut rows: Vec<(i64, StoredEvent)> = rows.into_iter().take(limit).collect();
|
||||
rows.reverse(); // oldest first
|
||||
let min_id = rows.first().map(|(id, _)| *id);
|
||||
let events = rows.into_iter().map(|(_, e)| e).collect();
|
||||
Ok((events, min_id, has_more))
|
||||
}
|
||||
}
|
||||
|
||||
/// Authoritative turn-loop state. The harness owns it; the web UI
|
||||
|
|
@ -333,10 +260,6 @@ pub struct Bus {
|
|||
/// by the serve loop when it builds the session; unset on claude, whose
|
||||
/// turn `/api/cancel` stops by signalling the `claude` process.
|
||||
turn_canceller: Arc<OnceLock<hive_runtime::Canceller>>,
|
||||
/// The model and effort the session offers, for a runtime that reads them
|
||||
/// from its session (ACP). Set once by the serve loop when it builds the
|
||||
/// session; unset on claude.
|
||||
session_choices: Arc<OnceLock<hive_runtime::Choices>>,
|
||||
/// 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
|
||||
/// every `turn_stats` row until the next fresh session. `None` before
|
||||
|
|
@ -418,7 +341,6 @@ impl Bus {
|
|||
compact_pending: Arc::new(Mutex::new(None)),
|
||||
post_compact_wake: Arc::new(Mutex::new(None)),
|
||||
turn_canceller: Arc::default(),
|
||||
session_choices: Arc::default(),
|
||||
session_id: Arc::new(Mutex::new(None)),
|
||||
fresh_session: Arc::new(AtomicBool::new(false)),
|
||||
tool_calls: Arc::new(Mutex::new(std::collections::HashMap::new())),
|
||||
|
|
@ -429,16 +351,6 @@ impl Bus {
|
|||
}
|
||||
}
|
||||
|
||||
/// Current high-water seq. Snapshot endpoints read this before
|
||||
/// gathering state so the resulting (snapshot.seq, snapshot) pair
|
||||
/// satisfies: any live event with seq > snapshot.seq is post-snapshot
|
||||
/// (not yet reflected). Clients dedupe buffered SSE traffic against
|
||||
/// this value.
|
||||
#[must_use]
|
||||
pub fn current_seq(&self) -> u64 {
|
||||
self.event_seq.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn next_seq(&self) -> u64 {
|
||||
self.event_seq.fetch_add(1, Ordering::SeqCst) + 1
|
||||
}
|
||||
|
|
@ -456,19 +368,6 @@ impl Bus {
|
|||
self.turn_canceller.get()
|
||||
}
|
||||
|
||||
/// Record where the session's model and effort choices are read. Only the
|
||||
/// first call takes effect; there is one session per harness.
|
||||
pub fn set_session_choices(&self, choices: hive_runtime::Choices) {
|
||||
let _ = self.session_choices.set(choices);
|
||||
}
|
||||
|
||||
/// Where the session's model and effort choices are read, if the runtime
|
||||
/// offers them (see [`Self::set_session_choices`]).
|
||||
#[must_use]
|
||||
pub fn session_choices(&self) -> Option<&hive_runtime::Choices> {
|
||||
self.session_choices.get()
|
||||
}
|
||||
|
||||
/// Request a session reset (operator `POST /api/new-session`). Deferred:
|
||||
/// 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
|
||||
|
|
@ -949,23 +848,6 @@ impl Bus {
|
|||
pub fn subscribe(&self) -> broadcast::Receiver<BusEvent> {
|
||||
self.tx.subscribe()
|
||||
}
|
||||
|
||||
/// Paginated history: up to `limit` events before `before_id`
|
||||
/// (or the most recent `limit` when `before_id` is `None`).
|
||||
/// Returns `(events_oldest_first, min_row_id, has_more)`.
|
||||
/// `min_row_id` is the cursor for the next page; pass it as
|
||||
/// `before_id` on the next call.
|
||||
#[must_use]
|
||||
pub fn history_page(
|
||||
&self,
|
||||
before_id: Option<i64>,
|
||||
limit: usize,
|
||||
) -> (Vec<StoredEvent>, Option<i64>, bool) {
|
||||
let Some(store) = &self.store else {
|
||||
return (Vec::new(), None, false);
|
||||
};
|
||||
store.page(before_id, limit).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Bus {
|
||||
|
|
@ -1016,21 +898,7 @@ fn breakdown_key(name: &str, input: Option<&serde_json::Value>) -> String {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{BusEvent, LiveEvent, StoredEvent};
|
||||
|
||||
#[test]
|
||||
fn stored_event_serializes_ts_beside_kind() {
|
||||
// History-row wire shape: `ts` is a flattened sibling of `kind`,
|
||||
// which is what the agent terminal reads to time turn boundaries.
|
||||
let v = serde_json::to_value(StoredEvent {
|
||||
ts: 1_700_000_000,
|
||||
event: LiveEvent::Note { text: "hi".into() },
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v["ts"], 1_700_000_000_i64);
|
||||
assert_eq!(v["kind"], "note");
|
||||
assert_eq!(v["text"], "hi");
|
||||
}
|
||||
use super::{BusEvent, LiveEvent};
|
||||
|
||||
#[test]
|
||||
fn bus_event_serializes_ts_and_seq_beside_kind() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue