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

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