server-side TurnState in the harness, exposed via /api/state
new TurnState { Idle, Thinking, Compacting } on hive_ag3nt::events::Bus
with set_state + state_snapshot. the turn loops in hive-ag3nt and
hive-m1nd flip Thinking before drive_turn and Idle after; the
web_ui's /api/compact handler flips Compacting around compact_session.
per-agent /api/state grows turn_state + turn_state_since (unix
seconds). frontend prefers the server-reported state over the
client-derived one — setStateAbs takes the absolute since-time so
the 'last turn' chip reads the actual server-side duration instead
of the client's perceived gap between SSE events. SSE turn_start /
turn_end still drive state instantly between renders; /api/state
re-anchors on each turn_end refresh.
new compacting state gets its own purple badge with pulse
animation (mirrors thinking's amber). napping will slot in the
same way once the nap tool lands.
This commit is contained in:
parent
0385d96bf3
commit
637085644d
7 changed files with 94 additions and 32 deletions
|
|
@ -153,6 +153,11 @@ struct StateSnapshot {
|
|||
/// from the broker via the per-agent socket on each render.
|
||||
/// Empty on transport failure.
|
||||
inbox: Vec<hive_sh4re::InboxRow>,
|
||||
/// Authoritative turn-loop state from the harness and the unix
|
||||
/// timestamp the state was entered. The JS computes the age
|
||||
/// client-side off this rather than tracking it from SSE events.
|
||||
turn_state: crate::events::TurnState,
|
||||
turn_state_since: i64,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
@ -187,12 +192,15 @@ async fn api_state(State(state): State<AppState>) -> axum::Json<StateSnapshot> {
|
|||
.and_then(|s| s.parse::<u16>().ok())
|
||||
.unwrap_or(7000);
|
||||
let inbox = recent_inbox(&state.socket, state.flavor).await;
|
||||
let (turn_state, turn_state_since) = state.bus.state_snapshot();
|
||||
axum::Json(StateSnapshot {
|
||||
label: state.label.clone(),
|
||||
dashboard_port,
|
||||
status,
|
||||
session: session_view,
|
||||
inbox,
|
||||
turn_state,
|
||||
turn_state_since,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +367,10 @@ async fn post_compact(State(state): State<AppState>) -> Response {
|
|||
return;
|
||||
}
|
||||
};
|
||||
if let Err(e) = crate::turn::compact_session(&settings, &bus).await {
|
||||
bus.set_state(crate::events::TurnState::Compacting);
|
||||
let r = crate::turn::compact_session(&settings, &bus).await;
|
||||
bus.set_state(crate::events::TurnState::Idle);
|
||||
if let Err(e) = r {
|
||||
bus.emit(crate::events::LiveEvent::Note(format!(
|
||||
"/compact failed: {e:#}"
|
||||
)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue