Skip to content

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

Mount the activity row inside a nested running slot

Fei2411514cf2e4e724
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 662dd1c1..899861be 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -5855,6 +5855,15 @@ var import_react10 = require("react");
var import_react_dom2 = require("react-dom");
var PHRASE_HOLD_MS = 800;
var drawPhrase = (pool) => t(pool[Math.min(pool.length - 1, Math.floor(Math.random() * pool.length))]);
+var mountMissed = false;
+function findHost() {
+ const node = document.querySelector("[data-chat-flow] [data-chat-running]") ?? document.querySelector("[data-chat-flow]");
+ if (node === null && !mountMissed) {
+ mountMissed = true;
+ noteClientError("activity row", new Error("[data-chat-flow] not found"));
+ }
+ return node;
+}
function useRunningHost(active) {
const [host, setHost] = (0, import_react10.useState)(null);
(0, import_react10.useEffect)(() => {
@@ -5865,8 +5874,10 @@ function useRunningHost(active) {
let frame = 0;
const find = () => {
frame = 0;
- const node = document.querySelector("[data-chat-flow] > [data-chat-running]");
- setHost((prev) => prev === node ? prev : node);
+ setHost((prev) => {
+ const node = findHost();
+ return prev === node ? prev : node;
+ });
};
const observer = new MutationObserver(() => {
if (!frame) frame = requestAnimationFrame(find);
@@ -6054,6 +6065,7 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
const groups = workKeys(useGroupWork(useWork, (rooms) => Object.entries(rooms).flatMap(([roomId, entries2]) => entries2.filter((entry) => entry.botId === id).map((entry) => ({ id: roomId, ...doingOf(entry) })))));
const away = !running && groups.length > 0;
const state = botState(running || away, doing, alert);
+ const runningLine = running && doing ? workLine(bot.name, doing, 0) : null;
const awayLine = away ? workLine(roster.roomsById[groups[0].id]?.name ?? t("a group chat"), groups[0], groups.length - 1) : null;
const waits = workKeys(useWork ? useWork((work) => JSON.stringify(work.waiting?.[id] ?? null)) : "null");
const waitsFor = state === "waiting" ? waitingFor(roster, waits) : "";
@@ -6100,7 +6112,7 @@ function BotRow({ bot, roster, actions, useSessions, useSessionStatus, useSessio
"span",
{ className: "bt-row-body" },
(0, import_react11.createElement)("span", { className: "bt-row-name" }, (0, import_react11.createElement)("span", { className: "bt-row-title" }, bot.name), pinned ? (0, import_react11.createElement)(PinMark) : null),
- awayLine ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, awayLine) : waitsFor ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, waitsFor) : preview ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, preview) : null
+ runningLine ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, runningLine) : awayLine ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, awayLine) : waitsFor ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, waitsFor) : preview ? (0, import_react11.createElement)("span", { className: "bt-row-preview" }, preview) : null
) : null,
wide && unread && !active ? (0, import_react11.createElement)("span", { className: "bt-unread", "aria-hidden": true }) : null
);
diff --git a/ds-bot/src/client/activity-row.js b/ds-bot/src/client/activity-row.js
index c219ec67..f146863b 100644
--- a/ds-bot/src/client/activity-row.js
+++ b/ds-bot/src/client/activity-row.js
@@ -2,6 +2,7 @@ import { createElement as h, useEffect, useLayoutEffect, useMemo, useRef, useSta
import { createPortal } from 'react-dom'
import { BotMark, RoomAvatar } from './mark.js'
import { Elapsed, Shimmer, PHRASES } from './cells.js'
+import { noteClientError } from './diagnostics.js'
import { reducedMotion } from './motion.js'
import { t } from './i18n.js'
@@ -14,6 +15,21 @@ const PHRASE_HOLD_MS = 800
const drawPhrase = pool => t(pool[Math.min(pool.length - 1, Math.floor(Math.random() * pool.length))])
export { reducedMotion }
+// The shell's running slot can sit under wrappers it adds around the flow, so the
+// search is a descendant one; without the slot the row mounts at the flow's tail.
+// No flow at all is a mount failure, noted once per page — the observer keeps
+// retrying in case the transcript is only mid-mount.
+let mountMissed = false
+export function findHost() {
+ const node = document.querySelector('[data-chat-flow] [data-chat-running]')
+ ?? document.querySelector('[data-chat-flow]')
+ if (node === null && !mountMissed) {
+ mountMissed = true
+ noteClientError('activity row', new Error('[data-chat-flow] not found'))
+ }
+ return node
+}
+
function useRunningHost(active) {
const [host, setHost] = useState(null)
useEffect(() => {
@@ -21,8 +37,10 @@ function useRunningHost(active) {
let frame = 0
const find = () => {
frame = 0
- const node = document.querySelector('[data-chat-flow] > [data-chat-running]')
- setHost(prev => (prev === node ? prev : node))
+ setHost(prev => {
+ const node = findHost()
+ return prev === node ? prev : node
+ })
}
const observer = new MutationObserver(() => { if (!frame) frame = requestAnimationFrame(find) })
observer.observe(document.querySelector('[data-conversation-scroll]') ?? document.body, { childList: true, subtree: true })
diff --git a/ds-bot/test/activity-row.test.js b/ds-bot/test/activity-row.test.js
new file mode 100644
index 00000000..295f82d8
--- /dev/null
+++ b/ds-bot/test/activity-row.test.js
@@ -0,0 +1,64 @@
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { createRequire } from 'node:module'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { runInNewContext } from 'node:vm'
+import { build } from 'esbuild'
+
+// jsdom comes from the harness that test/harness-resolve.mjs found, like the dsh packages.
+const PLUGIN = dirname(dirname(fileURLToPath(import.meta.url)))
+const { JSDOM } = createRequire(join(process.env.DSH_HARNESS ?? join(PLUGIN, '..', 'deepseek-harness'), 'package.json'))('jsdom')
+
+// The activity row and the diagnostics it reports into, bundled once and run with a
+// minimal React stand-in; the row's DOM helpers only read `document` at call time.
+const { outputFiles } = await build({
+ stdin: {
+ contents: [
+ "export { findHost } from './src/client/activity-row.js'",
+ "export { clientErrors } from './src/client/diagnostics.js'",
+ ].join('\n'),
+ resolveDir: PLUGIN,
+ },
+ bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+const react = {
+ createElement: (type, props, ...children) => ({ type, props: { ...props, children } }), Fragment: Symbol('Fragment'),
+ useEffect() {}, useLayoutEffect() {}, useState: initial => [initial, () => {}],
+ useMemo: make => make(), useRef: current => ({ current }), useId: () => 'id',
+}
+const dom = new JSDOM('<!doctype html><body></body>')
+const module = { exports: {} }
+runInNewContext(outputFiles[0].text, {
+ module, exports: module.exports,
+ document: dom.window.document,
+ window: { matchMedia: () => ({ matches: false }) },
+ MutationObserver: dom.window.MutationObserver,
+ requestAnimationFrame: fn => setTimeout(fn, 0),
+ cancelAnimationFrame: id => clearTimeout(id),
+ require: name => (name === 'react' ? react : name === 'react-dom' ? { createPortal: node => node } : {}),
+})
+const { findHost, clientErrors } = module.exports
+
+test('the activity row mounts at the running slot even under an extra wrapper', () => {
+ dom.window.document.body.innerHTML = '<div data-chat-flow><div class="wrap"><div data-chat-running id="slot"></div></div></div>'
+ const host = findHost()
+ assert.equal(host?.id, 'slot')
+})
+
+test('without the running slot the row mounts at the flow tail', () => {
+ dom.window.document.body.innerHTML = '<div data-chat-flow id="flow"><div data-chat-flow-key="1"></div></div>'
+ const host = findHost()
+ assert.equal(host?.id, 'flow')
+})
+
+test('a missing chat flow is reported once per page, not on every retry', () => {
+ dom.window.document.body.innerHTML = '<div></div>'
+ const before = clientErrors().filter(entry => entry.text.startsWith('activity row:')).length
+ assert.equal(findHost(), null)
+ assert.equal(findHost(), null)
+ const entries = clientErrors().filter(entry => entry.text.startsWith('activity row:'))
+ assert.equal(entries.length, before + 1)
+ assert.match(entries.at(-1).text, /activity row:/)
+})