A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep the sidebar closed during repeated navigation
Chimneyfa4341c7109a
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 12654a9d..5d924028 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -5536,8 +5536,12 @@ function useListGlide(listRef, layout, key) {}, [layout, key]);}function TeamSidebar(props) {- const { wide, useRoster, useUi, useSessions, actions } = props;+ const { wide, expandSidebar, useRoster, useUi, useSessions, actions } = props;const listRef = (0, import_react9.useRef)(null);+ const closing = (0, import_react9.useRef)(false);+ (0, import_react9.useLayoutEffect)(() => {+ closing.current = false;+ });const roster = useRoster((value) => value);const markedUnread = useUi((value) => value.unread);props.useRegistry((value) => value);@@ -5561,7 +5565,11 @@ function TeamSidebar(props) {useLandOnMainBot(roster, useSessions, actions);const navigate = (open, id) => {const result = open(id);- if (wide && window.innerWidth < 1024) actions.toggleSidebar();+ if (wide && window.innerWidth < 1024 && !closing.current) {+ closing.current = true;+ expandSidebar();+ actions.toggleSidebar();+ }return result;};const rowActions = {diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.jsindex e222f8cf..f9c178c5 100644--- a/ds-bot/src/client/sidebar.js+++ b/ds-bot/src/client/sidebar.js@@ -244,8 +244,10 @@ function useListGlide(listRef, layout, key) {}export function TeamSidebar(props) {- const { wide, useRoster, useUi, useSessions, actions } = props+ const { wide, expandSidebar, useRoster, useUi, useSessions, actions } = propsconst listRef = useRef(null)+ const closing = useRef(false)+ useLayoutEffect(() => { closing.current = false })const roster = useRoster(value => value)const markedUnread = useUi(value => value.unread)props.useRegistry(value => value)@@ -267,11 +269,16 @@ export function TeamSidebar(props) {const main = roster.byId[roster.mainBotId]useListGlide(listRef, wide, order.map(entry => entry.item.id).join(','))useLandOnMainBot(roster, useSessions, actions)- // The shell gives this slot its live fold state. Only a navigation from its- // expanded, narrow sidebar dismisses it; other ways to open a chat never toggle it.+ // The shell keeps wide content during its collapse fade. Normalize through its+ // public expansion action before toggling; coalesce synchronous activations+ // until React commits the result.const navigate = (open, id) => {const result = open(id)- if (wide && window.innerWidth < 1024) actions.toggleSidebar()+ if (wide && window.innerWidth < 1024 && !closing.current) {+ closing.current = true+ expandSidebar()+ actions.toggleSidebar()+ }return result}const rowActions = {diff --git a/ds-bot/test/sidebar-switch.test.js b/ds-bot/test/sidebar-switch.test.jsindex a89754ba..d08bd40b 100644--- a/ds-bot/test/sidebar-switch.test.js+++ b/ds-bot/test/sidebar-switch.test.js@@ -11,7 +11,8 @@ const PLUGIN = dirname(dirname(fileURLToPath(import.meta.url)))const { JSDOM } = createRequire(join(process.env.DSH_HARNESS ?? join(PLUGIN, '..', 'deepseek-harness'), 'package.json'))('jsdom')// The sidebar and its style sheets import the browser's React; bundle them with a minimal-// stand-in, as the tool-cell tests do: components run as plain functions, effects never run.+// stand-in, as the tool-cell tests do: components run as plain functions. Navigation+// fixtures retain refs across commits and run their layout effects after each render.const { outputFiles } = await build({stdin: {contents: "export { SHELL_CSS } from './src/client/styles.js'\nexport { SIDEBAR_CSS, TeamSidebar } from './src/client/sidebar.js'",@@ -20,10 +21,13 @@ const { outputFiles } = await build({bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],})+let renderRefs+let refIndex = 0+let layoutEffectsconst 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',+ useEffect() {}, useLayoutEffect: effect => layoutEffects?.push(effect), useState: initial => [initial, () => {}],+ useMemo: make => make(), useRef: current => renderRefs ? renderRefs[refIndex++] ??= { current } : { current }, useId: () => 'id',}const module = { exports: {} }const viewport = { innerWidth: 1280 }@@ -36,17 +40,14 @@ const { SHELL_CSS, SIDEBAR_CSS, TeamSidebar } = module.exportsfunction navigationSidebar(wide) {const calls = []+ const refs = []+ let collapsed = !wideconst bot = { id: 'writer', name: 'Writer', createdAt: 1 }const room = { id: 'room', name: 'Team', members: [], createdAt: 2 }const agent = { id: 'agent', sessions: ['session'], createdAt: 3 }const roster = { bots: [bot], rooms: [room], agents: [agent], byId: { writer: bot }, ready: true }const actions = Object.fromEntries(['openSession', 'openAgent', 'openAgentSession', 'newAgentSession'].map(name => [name, id => { calls.push([name, id]); return id }]))- actions.toggleSidebar = () => calls.push(['toggleSidebar'])- const tree = TeamSidebar({- wide, actions,- useRoster: pick => pick(roster), useUi: pick => pick({ unread: {} }), useRegistry: pick => pick({}),- useSessions: pick => pick({ ids: [], byId: {} }), useUpdate: () => ({}),- })+ actions.toggleSidebar = () => { collapsed = !collapsed; calls.push(['toggleSidebar']) }const rows = []const walk = (node) => {if (Array.isArray(node)) { node.forEach(walk); return }@@ -54,21 +55,41 @@ function navigationSidebar(wide) {if (['BotRow', 'RoomRow', 'AgentRow'].includes(node.type?.name)) rows.push(node)walk(node.props?.children)}- walk(tree)- return { calls, rows, actions }+ const render = (nextWide = wide) => {+ wide = nextWide+ // The public owner action closes over the shell's committed collapsed state;+ // wide may still be true during the shell's 150ms content fade-out.+ const committedCollapsed = collapsed+ renderRefs = refs+ refIndex = 0+ layoutEffects = []+ const tree = TeamSidebar({+ wide, actions, expandSidebar: () => { if (committedCollapsed) actions.toggleSidebar() },+ useRoster: pick => pick(roster), useUi: pick => pick({ unread: {} }), useRegistry: pick => pick({}),+ useSessions: pick => pick({ ids: [], byId: {} }), useUpdate: () => ({}),+ })+ renderRefs = undefined+ const effects = layoutEffects+ layoutEffects = undefined+ effects.forEach(effect => effect())+ rows.length = 0+ walk(tree)+ }+ render()+ return { calls, rows, actions, render, get collapsed() { return collapsed } }}for (const width of [390, 1023, 1024, 1280]) {for (const wide of [false, true]) {test(`sidebar navigation at ${width}px with ${wide ? 'expanded content' : 'a collapsed rail'} only closes an open mobile sidebar`, () => {viewport.innerWidth = width- const { rows, calls } = navigationSidebar(wide)- assert.equal(rows.length, 3)- for (const row of rows) {+ const initial = navigationSidebar(wide)+ assert.equal(initial.rows.length, 3)+ for (const [index, row] of initial.rows.entries()) {const names = row.type.name === 'AgentRow' ? ['openAgent', 'openAgentSession', 'newAgentSession'] : ['openSession']for (const name of names) {- calls.length = 0- assert.equal(row.props.actions[name]('selected'), 'selected')+ const { rows, calls } = navigationSidebar(wide)+ assert.equal(rows[index].props.actions[name]('selected'), 'selected')assert.deepEqual(calls, wide && width < 1024 ? [[name, 'selected'], ['toggleSidebar']] : [[name, 'selected']])}}@@ -76,6 +97,54 @@ for (const width of [390, 1023, 1024, 1280]) {}}+test('repeated sidebar navigation before another commit closes only once', () => {+ viewport.innerWidth = 390+ const side = navigationSidebar(true)+ side.rows[0].props.actions.openAgent('first')+ side.rows[1].props.actions.openSession('second')+ assert.equal(side.collapsed, true)+ assert.deepEqual(side.calls, [['openAgent', 'first'], ['toggleSidebar'], ['openSession', 'second']])+})++test('navigation during the shell fade-out keeps the already collapsed sidebar closed', () => {+ viewport.innerWidth = 390+ const side = navigationSidebar(true)+ side.rows[0].props.actions.openAgentSession('first')+ assert.equal(side.collapsed, true)+ side.render(true)+ side.calls.length = 0+ side.rows[1].props.actions.openSession('during-fade')+ assert.equal(side.collapsed, true, 'wide remains true until the content fade settles')+ assert.equal(side.calls.filter(([name]) => name === 'openSession').length, 1)+})++test('a sidebar reopened before wide becomes false still closes on the next navigation', () => {+ viewport.innerWidth = 390+ const side = navigationSidebar(true)+ side.rows[0].props.actions.openAgent('first')+ side.render(true)+ side.actions.toggleSidebar()+ side.render(true)+ assert.equal(side.collapsed, false)+ side.rows[1].props.actions.openSession('after-reopen')+ assert.equal(side.collapsed, true)+})++test('the navigation guard resets across a full collapse and expansion cycle', () => {+ viewport.innerWidth = 390+ const side = navigationSidebar(true)+ side.rows[0].props.actions.newAgentSession('first')+ side.render(false)+ side.calls.length = 0+ side.rows[1].props.actions.openSession('from-rail')+ assert.equal(side.collapsed, true)+ assert.deepEqual(side.calls, [['openSession', 'from-rail']])+ side.actions.toggleSidebar()+ side.render(true)+ side.rows[1].props.actions.openSession('after-expansion')+ assert.equal(side.collapsed, true)+})+test('preparing sidebar navigation leaves actions elsewhere unchanged', () => {viewport.innerWidth = 390const { actions, calls } = navigationSidebar(true)