Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Keep the reasoning row open when a live turn moves it

Fei2411b0a0a5d09d5b
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 2ce04520..e3aa158d 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -4421,32 +4421,42 @@ function useThinkingMs({ sessionId, turn, settledSteps, skip }) {
}, [key, skip]);
return ms;
}
-function ThinkingRow({ text, live, at, ms }) {
+var rowViews = /* @__PURE__ */ new Map();
+function ThinkingRow({ text, live, at, ms, viewKey }) {
const box = (0, import_react8.useRef)(null);
- const atEnd = (0, import_react8.useRef)(true);
- const [open, setOpen] = (0, import_react8.useState)(false);
+ const view = (0, import_react8.useRef)(rowViews.get(viewKey));
+ const atEnd = (0, import_react8.useRef)(view.current?.atEnd ?? true);
+ const [open, setOpen] = (0, import_react8.useState)(view.current?.open ?? false);
const [fade, setFade] = (0, import_react8.useState)(void 0);
+ const remember = (patch) => {
+ if (viewKey !== void 0) rowViews.set(viewKey, { ...rowViews.get(viewKey), ...patch });
+ };
const measure = () => {
const el = box.current;
atEnd.current = el.scrollHeight - el.scrollTop - el.clientHeight < 2;
+ remember({ atEnd: atEnd.current, top: el.scrollTop });
const above = el.scrollTop > 0;
setFade(above && !atEnd.current ? "both" : above ? "top" : !atEnd.current ? "bottom" : void 0);
};
const toggle = (event) => {
const next = event.currentTarget.open;
if (next) atEnd.current = true;
+ remember({ open: next });
setOpen(next);
};
(0, import_react8.useLayoutEffect)(() => {
if (!open) return;
const el = box.current;
+ const restore = view.current;
+ view.current = void 0;
if (atEnd.current) el.scrollTop = el.scrollHeight;
+ else if (restore?.top !== void 0) el.scrollTop = restore.top;
measure();
}, [text, open]);
const title = live ? t("Thinking") : t("Thought it through");
return (0, import_react8.createElement)(
"details",
- { className: "bt-think", onToggle: toggle },
+ { className: "bt-think", open, onToggle: toggle },
(0, import_react8.createElement)(
"summary",
null,
@@ -4505,6 +4515,7 @@ function AssistantCell({ node, groupPart, sessionId, openFile, fileMentions, use
reasoning ? (0, import_react8.createElement)(ThinkingRow, {
text: reasoning,
live: thinking !== void 0,
+ viewKey: `${sessionId}:${data.turn}`,
// The live clock counts the settled steps too: backing `at` by the settled
// time makes one Elapsed show settled + running.
...thinking !== void 0 ? { at: typeof thinking.time === "number" ? thinking.time - (ms ?? 0) : void 0 } : { ms }
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index f9ffb47b..97259661 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -138,30 +138,40 @@ function useThinkingMs({ sessionId, turn, settledSteps, skip }) {
// steps add reasoning, unless the reader has scrolled up. While a step of the turn is
// thinking the row shows immediately and ticks (`at` backs the live clock so it counts
// the settled steps too); settled, it shows the turn's exact thinking time if known.
-export function ThinkingRow({ text, live, at, ms }) {
+// A live turn's row moves to the step that reasons now, so whether the reader opened it
+// and where they scrolled is kept per turn (`viewKey`), not per row.
+const rowViews = new Map()
+export function ThinkingRow({ text, live, at, ms, viewKey }) {
const box = useRef(null)
- const atEnd = useRef(true)
- const [open, setOpen] = useState(false)
+ const view = useRef(rowViews.get(viewKey))
+ const atEnd = useRef(view.current?.atEnd ?? true)
+ const [open, setOpen] = useState(view.current?.open ?? false)
const [fade, setFade] = useState(undefined)
+ const remember = patch => { if (viewKey !== undefined) rowViews.set(viewKey, { ...rowViews.get(viewKey), ...patch }) }
const measure = () => {
const el = box.current
atEnd.current = el.scrollHeight - el.scrollTop - el.clientHeight < 2
+ remember({ atEnd: atEnd.current, top: el.scrollTop })
const above = el.scrollTop > 0
setFade(above && !atEnd.current ? 'both' : above ? 'top' : !atEnd.current ? 'bottom' : undefined)
}
const toggle = event => {
const next = event.currentTarget.open
if (next) atEnd.current = true
+ remember({ open: next })
setOpen(next)
}
useLayoutEffect(() => {
if (!open) return
const el = box.current
+ const restore = view.current
+ view.current = undefined
if (atEnd.current) el.scrollTop = el.scrollHeight
+ else if (restore?.top !== undefined) el.scrollTop = restore.top
measure()
}, [text, open])
const title = live ? t('Thinking') : t('Thought it through')
- return h('details', { className: 'bt-think', onToggle: toggle },
+ return h('details', { className: 'bt-think', open, onToggle: toggle },
h('summary', null, title,
live && at !== undefined ? h(Elapsed, { at, className: 'bt-think-time' }) : null,
!live && ms !== undefined ? h('span', { className: 'bt-think-time' }, `· ${elapsedLabel(Math.max(1000, ms))}`) : null),
@@ -219,7 +229,7 @@ export function AssistantCell({ node, groupPart, sessionId, openFile, fileMentio
})
}),
reasoning ? h(ThinkingRow, {
- text: reasoning, live: thinking !== undefined,
+ text: reasoning, live: thinking !== undefined, viewKey: `${sessionId}:${data.turn}`,
// The live clock counts the settled steps too: backing `at` by the settled
// time makes one Elapsed show settled + running.
...(thinking !== undefined ? { at: typeof thinking.time === 'number' ? thinking.time - (ms ?? 0) : undefined } : { ms }),
diff --git a/ds-bot/test/chat-rows.test.js b/ds-bot/test/chat-rows.test.js
index 9b568a11..5bfd01ed 100644
--- a/ds-bot/test/chat-rows.test.js
+++ b/ds-bot/test/chat-rows.test.js
@@ -54,11 +54,18 @@ test('with the clock, a time separator sits above the first entry and after each
assert.deepEqual(shape(ChatRows({ items, sessionId: 'b', roster, actions: {}, clock: true })), ['PartLine', 'clock', 'EarlierUser', 'bot:one+two', 'clock', 'EarlierUser'])
})
+test('a reasoning row the reader opened stays open when the turn moves it to a later step', () => {
+ const first = ThinkingRow({ text: 'one', live: true, viewKey: 's:7' })
+ first.props.onToggle({ currentTarget: { open: true } })
+ assert.equal(ThinkingRow({ text: 'one\n\ntwo', live: true, viewKey: 's:7' }).props.open, true)
+ assert.equal(ThinkingRow({ text: 'other', viewKey: 's:8' }).props.open, false)
+})
+
test('the reasoning row is a closed details that opens to the text', () => {
const row = ThinkingRow({ text: 'one\ntwo' })
assert.equal(row.type, 'details')
assert.equal(row.props.className, 'bt-think')
- assert.equal('open' in row.props, false)
+ assert.equal(row.props.open, false)
assert.equal(typeof row.props.onToggle, 'function')
const [title, box] = row.children
assert.equal(title.type, 'summary')