swarm ui: show thinking is a toggle of its own, apart from the developer details
This commit is contained in:
parent
2e9a65b414
commit
857b175a74
3 changed files with 243 additions and 25 deletions
|
|
@ -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