The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(tui): add event-driven state updates
Steven Enamakel1a4855a655c4
diff --git a/crates/openhuman-tui/src/lib.rs b/crates/openhuman-tui/src/lib.rsindex 66e10dda56..366d4072e7 100644--- a/crates/openhuman-tui/src/lib.rs+++ b/crates/openhuman-tui/src/lib.rs@@ -47,6 +47,7 @@ mod render;mod runner;mod session;mod state;+mod state_events;mod terminal;mod theme;mod ui_state;diff --git a/crates/openhuman-tui/src/state.rs b/crates/openhuman-tui/src/state.rsindex 83b1fa9282..1f9bcd54f2 100644--- a/crates/openhuman-tui/src/state.rs+++ b/crates/openhuman-tui/src/state.rs@@ -348,9 +348,12 @@ impl TranscriptState {}self.finish_turn();}- other => {- log::trace!("[tui] state: unhandled event={other}");- }+ other => match super::state_events::disposition(other) {+ super::state_events::Disposition::Unknown => {+ log::debug!("[tui] state: unknown event={other} (not in the web contract)");+ }+ _ => log::trace!("[tui] state: ignored event={other}"),+ },}}diff --git a/crates/openhuman-tui/src/state_events.rs b/crates/openhuman-tui/src/state_events.rsnew file mode 100644index 0000000000..a12478dd11--- /dev/null+++ b/crates/openhuman-tui/src/state_events.rs@@ -0,0 +1,87 @@+//! Which web-channel events the Chat tab folds into the transcript, and which+//! it leaves alone on purpose.+//!+//! The event vocabulary is the tinychannels `WebChannelEvent` contract (the+//! same one the desktop app's generated TypeScript types come from). Every+//! tag in it is classified here, so a tag the contract gains cannot be dropped+//! silently: `state_events_tests.rs` checks the classification against the+//! contract's JSON schema.++/// What the Chat tab does with one event tag.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub(crate) enum Disposition {+ /// Folded into the transcript by `TranscriptState::apply_event`.+ Reduced,+ /// Part of the contract, deliberately not shown in the terminal.+ Ignored,+ /// Not in the contract (a newer core); logged and skipped.+ Unknown,+}++/// Tags `apply_event` reduces. Every `subagent_*` tag is reduced too (see+/// [`disposition`]).+const REDUCED: &[&str] = &[+ "text_delta",+ "thinking_delta",+ "tool_call",+ "tool_result",+ "tool_args_delta",+ "artifact_pending",+ "artifact_ready",+ "artifact_failed",+ "chat_done",+ "chat_error",+];++/// Tags the terminal ignores, with the reason each is safe to skip.+const IGNORED: &[&str] = &[+ // Turn bookkeeping with nothing to show; the stream itself is the signal.+ "inference_start",+ "inference_heartbeat",+ "iteration_start",+ "turn_cost",+ "memory_activity",+ // `chat_error` already ends a cancelled turn (the core sends both for a+ // release), and `chat_interim`/`chat_segment`/`chat_message` repeat text+ // the deltas and `chat_done.full_response` already delivered.+ "chat_cancelled",+ "chat_interim",+ "chat_segment",+ "chat_message",+ // Live tool progress text; the call/result rows carry the outcome.+ "tool_progress",+ // Follow-up chips, run queue and plan/goal/todo panels are desktop UI.+ "chat_suggestions",+ "queue_item_queued",+ "queue_item_delivered",+ "queue_item_removed",+ "thread_goal_updated",+ "thread_goal_cleared",+ "thread_todos_changed",+ "run_mode_changed",+ // The terminal has its own approval prompt; these are the web cards.+ "approval_request",+ "approval_decided",+ "plan_review_request",+ "plan_review_decided",+ "external_transfer_pending",+ // Not tied to this client's turn (system client id) or UI-only.+ "proactive_message",+ "voice_speak",+ "user_error",+];++/// Classify one event tag.+pub(crate) fn disposition(event: &str) -> Disposition {+ if event.starts_with("subagent_") || REDUCED.contains(&event) {+ Disposition::Reduced+ } else if IGNORED.contains(&event) {+ Disposition::Ignored+ } else {+ Disposition::Unknown+ }+}++#[cfg(test)]+#[path = "state_events_tests.rs"]+mod tests;diff --git a/crates/openhuman-tui/src/state_events_tests.rs b/crates/openhuman-tui/src/state_events_tests.rsnew file mode 100644index 0000000000..57d4cdd40e--- /dev/null+++ b/crates/openhuman-tui/src/state_events_tests.rs@@ -0,0 +1,58 @@+use super::*;++const SCHEMA: &str = concat!(+ env!("CARGO_MANIFEST_DIR"),+ "/../../vendor/tinychannels/crates/tinychannels-bus/schema/web-channel-event.schema.json"+);++fn contract_tags() -> Vec<String> {+ let raw = std::fs::read_to_string(SCHEMA).expect("web channel event schema (init submodules)");+ let schema: serde_json::Value = serde_json::from_str(&raw).expect("schema is JSON");+ schema["oneOf"]+ .as_array()+ .expect("oneOf variants")+ .iter()+ .map(|variant| {+ variant["properties"]["event"]["const"]+ .as_str()+ .expect("variant has an event tag")+ .to_string()+ })+ .collect()+}++#[test]+fn every_contract_event_is_classified() {+ let unclassified: Vec<String> = contract_tags()+ .into_iter()+ .filter(|tag| disposition(tag) == Disposition::Unknown)+ .collect();+ assert!(+ unclassified.is_empty(),+ "web channel events with no TUI disposition: {unclassified:?}"+ );+}++#[test]+fn classified_tags_exist_in_the_contract() {+ let tags = contract_tags();+ for tag in REDUCED.iter().chain(IGNORED) {+ assert!(tags.iter().any(|t| t == tag), "{tag} is not in the contract");+ }+}++#[test]+fn no_tag_is_both_reduced_and_ignored() {+ for tag in IGNORED {+ assert!(!REDUCED.contains(tag), "{tag} is in both lists");+ assert!(!tag.starts_with("subagent_"), "{tag} is reduced by prefix");+ }+}++#[test]+fn dispositions_cover_the_three_cases() {+ assert_eq!(disposition("chat_done"), Disposition::Reduced);+ assert_eq!(disposition("subagent_spawned"), Disposition::Reduced);+ assert_eq!(disposition("turn_cost"), Disposition::Ignored);+ assert_eq!(disposition("from_the_future"), Disposition::Unknown);+}