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
12 changed files with 243 additions and 25 deletions

View file

@ -171,12 +171,16 @@ stream with an error status, the browser gives up and the badge reads
the stream replays the rows. The messages page works the same way.
The settings menu in the header has a **hide developer details** toggle. It drops
the muted debug rows (thinking, coalesced ticks, harness chatter) from every
the muted debug rows (coalesced ticks, harness chatter) from every
terminal, the preview and the tabs, and rows already on screen hide or show as
you flip it. It also hides the **components** tab, a page for developers, which
still answers at `/components`. The browser keeps the choice for the swarm UI, apart from the
hive dashboard's.
A **show thinking** toggle, on by default, shows or hides claude's thinking in
the same terminals, apart from the toggle above: thinking can be on with the
developer details hidden, or off with them shown.
The menu also has a **solid backgrounds** toggle. It turns the frosted, see-through
surfaces opaque: the header bar, the badges and the terminal panes. It stays off
until you turn it on, and the browser keeps the choice.

View file

@ -2,7 +2,7 @@
An agent's terminal in the swarm UI renders one row per `TermMsg`
(`hive-agent/src/term_msg.rs`): `{ts, icon?, level: debug|info|warn|error,
summary, body?, body_format?: markdown|diff, coalesce_key?}`. Classification
summary, body?, body_format?: markdown|diff, coalesce_key?, kind?: thinking}`. Classification
(icon, summary text, whether a tool call gets an expandable body) happens
server-side, once — `term_msg.rs` + `stream_enrich.rs` — and the swarm queue's
terminal rows and `GET /events/stream` carry it identically. The stream wraps
@ -53,11 +53,20 @@ that motivated the change.
The settings menu's "hide developer details" toggle (`getHideDebugPref()`,
`@hive/shared/prefs.js`) skips `debug`-level rows entirely rather than
muting them further — client-side only, no reload. The swarm UI and the hive
dashboard both have the toggle, as one shared row
(`@hive/shared/hide-debug-setting.js`). Each browser origin keeps its own
setting. A `debug` row follows the toggle as it changes, so rows already
on screen hide or show at once, not only the rows that arrive after it.
muting them further — client-side only, no reload. The swarm UI has the
toggle as a shared row (`@hive/shared/hide-debug-setting.js`). Each browser
origin keeps its own setting. A `debug` row follows the toggle as it changes,
so rows already on screen hide or show at once, not only the rows that arrive
after it.
Thinking has its own toggle, "show thinking" (`getShowThinkingPref()`, on by
default, `@hive/shared/show-thinking-setting.js`). The harness marks the two
thinking rows, the thinking text and the live token count, with
`kind: "thinking"`; they stay `debug` level on the wire. A thinking row follows
"show thinking" alone and every other `debug` row follows "hide developer
details" alone (`terminal/row-visibility.ts` is the rule). A row from before the
harness sent `kind` has none, so it follows "hide developer details" until the
agent is rebuilt.
Per-tool icon + summary formatting (what a `Read`/`Edit`/`send` call's row
actually says) lives in `stream_enrich.rs`'s `fmt_tool_use()` family —

View file

@ -53,6 +53,7 @@
"./motion-apply.js": "./src/settings/motion-apply.ts",
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
"./show-thinking-setting.js": "./src/settings/ShowThinkingSetting.tsx",
"./expand-details-setting.js": "./src/settings/ExpandDetailsSetting.tsx",
"./settings-menu.css": "./src/settings/SettingsMenu.css",
"./solid-backgrounds.js": "./src/settings/solid-backgrounds.tsx",

View file

@ -2,9 +2,9 @@
// so a future second consumer (e.g. swarm-ui's own terminal) gets the
// exact same key name for free via the browser's shared per-origin
// storage, rather than an independent copy that could drift.
// `ExpandDetailsSetting` / `HideDebugSetting` (the settings popover rows
// of the per-agent page and of the swarm UI) are the only writers today;
// `Row.tsx` is the only reader of either.
// `ExpandDetailsSetting` / `HideDebugSetting` / `ShowThinkingSetting` (the
// settings popover rows of the per-agent page and of the swarm UI) are the only
// writers today; `Row.tsx` is the only reader of any of them.
const EXPAND_DETAILS_KEY = "hive-agent-expand-details";
@ -74,3 +74,43 @@ export function subscribeHideDebugPref(listener: () => void): () => void {
window.removeEventListener("storage", onStorage);
};
}
const HIDE_THINKING_KEY = "hive-agent-hide-thinking";
// Whether a terminal shows claude's thinking (its thinking text and the live
// count of thinking tokens). On unless turned off, and apart from the "hide
// developer details" preference above. The key records the off state, so a
// browser that never touched the setting shows thinking. Same shape as the
// others: client-side only, read live.
export function getShowThinkingPref(): boolean {
try {
return localStorage.getItem(HIDE_THINKING_KEY) !== "1";
} catch {
return true;
}
}
export function setShowThinkingPref(v: boolean): void {
try {
if (v) localStorage.removeItem(HIDE_THINKING_KEY);
else localStorage.setItem(HIDE_THINKING_KEY, "1");
} catch {
/* localStorage unavailable — preference is session-only */
}
for (const listener of showThinkingListeners) listener();
}
const showThinkingListeners = new Set<() => void>();
// Calls `listener` whenever the preference changes, here or in another tab of
// the same origin, as `subscribeHideDebugPref` does. Returns the unsubscribe.
export function subscribeShowThinkingPref(listener: () => void): () => void {
showThinkingListeners.add(listener);
const onStorage = (e: StorageEvent) => {
if (e.key === HIDE_THINKING_KEY || e.key === null) listener();
};
window.addEventListener("storage", onStorage);
return () => {
showThinkingListeners.delete(listener);
window.removeEventListener("storage", onStorage);
};
}

View file

@ -0,0 +1,24 @@
// Settings-menu row: "show thinking". A `<SettingsMenu>` child, like
// `HideDebugSetting`, and apart from it: thinking shows or hides on this row
// alone, whatever "hide developer details" says. `../terminal/Row.tsx` follows
// the preference as it changes.
import { useState } from "preact/hooks";
import { getShowThinkingPref, setShowThinkingPref } from "../prefs.js";
export function ShowThinkingSetting() {
const [show, setShow] = useState(() => getShowThinkingPref());
return (
<label class="settings-menu-row">
<span>show thinking</span>
<input
type="checkbox"
checked={show}
onChange={(e) => {
const v = (e.target as HTMLInputElement).checked;
setShowThinkingPref(v);
setShow(v);
}}
/>
</label>
);
}

View file

@ -17,8 +17,11 @@ import { renderMarkdown } from "./markdown.js";
import {
getExpandDetailsPref,
getHideDebugPref,
getShowThinkingPref,
subscribeHideDebugPref,
subscribeShowThinkingPref,
} from "../prefs.js";
import { rowHidden, rowIsFilterable } from "./row-visibility.js";
function MarkdownBody({ text }: { text: string }) {
const ref = useRef<HTMLDivElement>(null);
@ -58,24 +61,33 @@ function DiffBody({ text }: { text: string }) {
);
}
// A `debug` row, which follows the "hide developer details" preference as it
// changes. Only debug rows subscribe, so a long terminal does not hold a
// listener per row.
function DebugRow({ row }: { row: TermRow }) {
const [hidden, setHidden] = useState(() => getHideDebugPref());
// A row that a preference can hide: a `debug` row ("hide developer details")
// or a thinking row ("show thinking"). It follows them as they change. Only
// these rows subscribe, so a long terminal does not hold a listener per row.
function FilterableRow({ row }: { row: TermRow }) {
const [hideDebug, setHideDebug] = useState(() => getHideDebugPref());
const [showThinking, setShowThinking] = useState(() => getShowThinkingPref());
useEffect(
() => subscribeHideDebugPref(() => setHidden(getHideDebugPref())),
() => subscribeHideDebugPref(() => setHideDebug(getHideDebugPref())),
[],
);
// "hide developer details" is a skip, not a dimmer — a hidden debug row
// still occupies no DOM node at all, same as it never streamed, rather
// than a CSS `display: none` that would keep it in the layout/DOM for
// no benefit.
return hidden ? null : <RowBody row={row} />;
useEffect(
() =>
subscribeShowThinkingPref(() => setShowThinking(getShowThinkingPref())),
[],
);
// A hidden row is a skip, not a dimmer — it occupies no DOM node at all, same
// as it never streamed, rather than a CSS `display: none` that would keep it
// in the layout/DOM for no benefit.
return rowHidden(row, hideDebug, showThinking) ? null : <RowBody row={row} />;
}
export function Row({ row }: { row: TermRow }) {
return row.level === "debug" ? <DebugRow row={row} /> : <RowBody row={row} />;
return rowIsFilterable(row) ? (
<FilterableRow row={row} />
) : (
<RowBody row={row} />
);
}
function RowBody({ row }: { row: TermRow }) {

View file

@ -0,0 +1,24 @@
// Whether a terminal row is shown, given the two preferences that can hide it.
// Pure, so the rule is tested without a DOM: `Row.tsx` asks it for every
// `debug` row and every thinking row.
//
// A thinking row follows "show thinking" alone, so it can be on while the
// developer details are hidden, or off while they are shown. Every other
// `debug` row follows "hide developer details" alone. A row of any other level
// is always shown.
import type { TermMsg } from "./termMsg.js";
export function rowHidden(
row: Pick<TermMsg, "level" | "kind">,
hideDebug: boolean,
showThinking: boolean,
): boolean {
if (row.kind === "thinking") return !showThinking;
return row.level === "debug" && hideDebug;
}
/** Whether a preference can hide the row at all, so that only those rows
* subscribe to the preferences. */
export function rowIsFilterable(row: Pick<TermMsg, "level" | "kind">): boolean {
return row.level === "debug" || row.kind === "thinking";
}

View file

@ -21,6 +21,10 @@ export interface TermMsg {
body?: string;
body_format?: "markdown" | "diff";
coalesce_key?: string;
/** What the row is about, for the kinds a client treats apart from its level:
* claude's thinking, which "show thinking" controls. Absent on every other
* row, and on rows from before the harness sent it. */
kind?: "thinking";
}
/** One SSE frame / history array entry — `hive-agent`'s `TermEnvelope`.

View file

@ -34,6 +34,7 @@ import { UserMenu } from "./UserMenu.js";
import { useHideDebug } from "./useHideDebug.js";
import { SettingsMenu } from "@hive/shared/settings-menu.js";
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
import { ShowThinkingSetting } from "@hive/shared/show-thinking-setting.js";
import { ExpandDetailsSetting } from "@hive/shared/expand-details-setting.js";
import { useApplyThemeOverride } from "@hive/shared/theme-apply.js";
import { useApplyMotionOverride } from "@hive/shared/motion-apply.js";
@ -495,6 +496,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
instead of sitting flush together at the right edge. */}
<div class="shell-header-actions">
<SettingsMenu themeKey={THEME_KEY} motionKey={MOTION_KEY}>
<ShowThinkingSetting />
<HideDebugSetting />
<ExpandDetailsSetting />
<SolidBackgroundsSetting storageKey={SOLID_KEY} />

View file

@ -0,0 +1,53 @@
// Which terminal rows the two preferences hide. Run by `npm test`, which
// imports the `.ts` module as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
rowHidden,
rowIsFilterable,
} from "../../shared/src/terminal/row-visibility.ts";
const thinking = { level: "debug", kind: "thinking" };
const chatter = { level: "debug" };
const info = { level: "info" };
test("thinking follows show thinking alone", () => {
assert.equal(rowHidden(thinking, false, true), false);
assert.equal(
rowHidden(thinking, true, true),
false,
"developer details are hidden, thinking is not",
);
assert.equal(
rowHidden(thinking, false, false),
true,
"developer details are shown, thinking is not",
);
assert.equal(rowHidden(thinking, true, false), true);
});
test("other debug rows follow hide developer details alone", () => {
assert.equal(rowHidden(chatter, false, true), false);
assert.equal(rowHidden(chatter, true, true), true);
assert.equal(rowHidden(chatter, true, false), true);
assert.equal(
rowHidden(chatter, false, false),
false,
"hiding thinking leaves the rest",
);
});
test("a row of any other level is always shown", () => {
for (const hide of [true, false])
for (const show of [true, false]) {
assert.equal(rowHidden(info, hide, show), false);
assert.equal(rowHidden({ level: "error" }, hide, show), false);
}
});
test("only debug and thinking rows can be hidden", () => {
assert.equal(rowIsFilterable(thinking), true);
assert.equal(rowIsFilterable(chatter), true);
assert.equal(rowIsFilterable(info), false);
assert.equal(rowIsFilterable({ level: "warn" }), false);
});

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 {