swarm ui: show thinking is a toggle of its own, apart from the developer details
This commit is contained in:
parent
2e9a65b414
commit
857b175a74
6 changed files with 243 additions and 25 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 }) {
|
||||
|
|
|
|||
24
frontend/packages/shared/src/terminal/row-visibility.ts
Normal file
24
frontend/packages/shared/src/terminal/row-visibility.ts
Normal 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";
|
||||
}
|
||||
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue