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

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);
});