Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: show thinking is a toggle of its own, apart from the developer details

This commit is contained in:
iris 2026-11-16 20:35:03 +01:00 • committed by mara
commit 857b175a74
2 changed files with 243 additions and 25 deletions

View file

@ -15,7 +15,7 @@
//! `mcp__hyperhive__send`'s row say, which tools get an expandable body)
//! didn't change; only the shape it gets packed into did.
use crate::term_msg::{BodyFormat, ClassifyCtx, Level, TermMsg};
use crate::term_msg::{BodyFormat, ClassifyCtx, Kind, Level, TermMsg};
use hive_types::term_msg::{SEND_ICON, SEND_SUMMARY_PREFIX};
use serde_json::{Value, json};
@ -71,7 +71,8 @@ fn classify_system(v: &Value) -> Vec<TermMsg> {
summary.unwrap_or_else(|| "thinking…".to_owned()),
)
.icon("🧠")
.coalesce("thinking-tok"),
.coalesce("thinking-tok")
.kind(Kind::Thinking),
],
"details" => {
let mut m = TermMsg::new(Level::Debug, summary.unwrap_or_default());
@ -254,7 +255,11 @@ fn classify_assistant_content(content: &[Value], ctx: &mut ClassifyCtx) -> Vec<T
} else {
txt
};
rows.push(TermMsg::new(Level::Debug, summary).icon("💭"));
rows.push(
TermMsg::new(Level::Debug, summary)
.icon("💭")
.kind(Kind::Thinking),
);
}
Some("tool_use") => {
if let (Some(id), Some(name)) = (
@ -1043,6 +1048,23 @@ mod tests {
assert_eq!(bare.coalesce_key.as_deref(), Some("thinking-tok"));
}
/// A client shows or hides thinking apart from the other `debug` rows, so
/// both the thinking text and the live token count say what they are.
#[test]
fn the_thinking_rows_are_marked_and_the_other_debug_rows_are_not() {
let count = one(&json!({ "type": "system", "subtype": "thinking_tokens" }));
assert_eq!(count.kind, Some(Kind::Thinking));
assert_eq!(
serde_json::to_value(&count).unwrap()["kind"],
json!("thinking")
);
let tick = one(&json!({ "type": "system", "subtype": "status" }));
assert_eq!(tick.level, Level::Debug);
assert_eq!(tick.kind, None);
assert!(serde_json::to_value(&tick).unwrap().get("kind").is_none());
}
#[test]
fn commands_changed_expands_into_the_command_list() {
let m = one(&json!({
@ -1285,6 +1307,9 @@ mod tests {
assert_eq!(rows.len(), 3, "the unknown content block is skipped");
assert_eq!(rows[0].icon.as_deref(), Some("💬"));
assert_eq!(rows[1].icon.as_deref(), Some("💭"));
assert_eq!(rows[1].kind, Some(Kind::Thinking));
assert_eq!(rows[0].kind, None);
assert_eq!(rows[2].kind, None);
// The tool_use was recorded for later correlation as a side effect.
assert_eq!(ctx.tool_name("t1"), Some("Bash"));
}

View file

@ -39,6 +39,17 @@ pub enum Level {
Error,
}
/// What a row is about, for the few kinds a client treats on their own. Most
/// rows have none; their `level` and `icon` say what they need to.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Kind {
/// What claude is thinking: its thinking text and the live count of
/// thinking tokens. A client can show or hide these apart from the other
/// `debug` rows.
Thinking,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum BodyFormat {
@ -68,6 +79,8 @@ pub struct TermMsg {
pub body_format: Option<BodyFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub coalesce_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<Kind>,
}
impl TermMsg {
@ -80,6 +93,7 @@ impl TermMsg {
body: None,
body_format: None,
coalesce_key: None,
kind: None,
}
}
@ -102,6 +116,12 @@ impl TermMsg {
self
}
#[must_use]
pub fn kind(mut self, kind: Kind) -> Self {
self.kind = Some(kind);
self
}
/// Stamp the row with the time of the event it came from.
#[must_use]
pub fn at(mut self, ts: impl Into<String>) -> Self {