A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Remount the Bot shell when its sidebar never lands
Fei2411408d7c3a3232
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 0c7d9bf8..c71b66a9 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -10082,23 +10082,36 @@ function surfaceGroups(install, { onError } = {}) {mounted[group] = [];disposeAll(disposers, `withdraw ${group}`);};+ const mount = (group) => {+ const disposers = [];+ try {+ for (const step of install[group]()) if (step) disposers.push(step());+ mounted[group] = disposers;+ return true;+ } catch (error) {+ disposeAll(disposers, `roll back ${group}`);+ console.warn(`[ds-bot] install ${group}`, error);+ onError?.(group, error);+ return false;+ }+ };return {reconcile(wanted) {for (const group of [...GROUPS].reverse()) if (!wanted[group]) withdraw(group);for (const group of GROUPS) {if (!wanted[group] || mounted[group].length > 0) continue;- const disposers = [];- try {- for (const step of install[group]()) if (step) disposers.push(step());- mounted[group] = disposers;- } catch (error) {- disposeAll(disposers, `roll back ${group}`);- console.warn(`[ds-bot] install ${group}`, error);- onError?.(group, error);- break;- }+ if (!mount(group)) break;}},+ // A step can go on with nothing actually contributed — a slot inject whose+ // callback threw inside the host still returns its disposer. remount takes+ // the group off and puts it back, so a caller that notices the contribution+ // is missing can retry instead of trusting `mounted`.+ remount(group) {+ if (!GROUPS.includes(group)) return;+ withdraw(group);+ mount(group);+ },dispose() {for (const group of [...GROUPS].reverse()) withdraw(group);}@@ -19051,6 +19064,24 @@ function apply(ctx) {expected2 = target;ctx.uiWorkspace.openSession(target);}, current: mainView });+ const homeToMainBot = () => {+ const snapshot = roster.getSnapshot();+ if (!snapshot.ready || !snapshot.mainBotId) return;+ const main = mainView();+ if (main !== void 0 && snapshot.byId[main] === void 0 && snapshot.roomsById[main] === void 0) {+ actions.openSession(snapshot.mainBotId);+ }+ };+ const ensureBotHome = () => {+ if (roster.getSnapshot().ready) homeToMainBot();+ else {+ const off = roster.subscribe(() => {+ if (!roster.getSnapshot().ready) return;+ off();+ homeToMainBot();+ });+ }+ };const actions = {...teamActions({ call, after, partFor, roster, ui: ui2, live, cards, heldCards, turnClock }),// The full-pane overlays sit above the conversation, so opening one must dismiss them@@ -19138,30 +19169,17 @@ function apply(ctx) {// surface closes first so nothing stale reopens on the way back.setSurface: (mode) => {if (mode !== "bot" && mode !== "agent") return;- if (surface.getSnapshot().mode === mode) return;+ if (surface.getSnapshot().mode === mode) {+ if (mode === "bot") ensureBotHome();+ return;+ }if (mode === "agent") {ui2.set((state) => ({ ...state, details: null, view: "details", settings: null, palette: null, newChat: null, menu: null, voice: null, exchange: null, memory: null, toast: null }));}writeMode(mode);surface.set((state) => ({ ...state, mode }));if (mode !== "bot") return;- const home = () => {- const snapshot = roster.getSnapshot();- if (!snapshot.ready || !snapshot.mainBotId) return;- const list = ctx.sessions.list.getSnapshot();- const main = Object.values(list.byId ?? {}).find((session) => (session?.retainedBy?.mainView ?? 0) > 0)?.id;- if (main !== void 0 && snapshot.byId[main] === void 0 && snapshot.roomsById[main] === void 0) {- actions.openSession(snapshot.mainBotId);- }- };- if (roster.getSnapshot().ready) home();- else {- const off = roster.subscribe(() => {- if (!roster.getSnapshot().ready) return;- off();- home();- });- }+ ensureBotHome();},markUnread: (id) => writeUnread(id, true),beginVisit: (id) => {@@ -19555,11 +19573,44 @@ function apply(ctx) {const groups = surfaceGroups({ shell: installShell, conversation: installConversation }, {onError: (_group, error) => actions.reportError(new Error(t("Bot mode could not be set up here: {error}", { error: error?.message ?? String(error) })), "surface")});- const reconcile = () => groups.reconcile(groupsFor(surface.getSnapshot()));+ let verifyTimer = 0;+ let verifyAttempts = 0;+ const verifySidebar = () => {+ if (!groupsFor(surface.getSnapshot()).shell) return;+ let landed = false;+ let declared = true;+ try {+ landed = ctx.slots.entries("sidebar.workspaces").some((entry) => entry.component === TeamSidebar);+ declared = ctx.slots.spec?.("sidebar.workspaces") !== void 0;+ } catch {+ declared = false;+ }+ if (landed) return;+ if (!declared) {+ if (verifyAttempts < 20) {+ verifyAttempts += 1;+ verifyTimer = setTimeout(verifySidebar, 250);+ }+ return;+ }+ if (verifyAttempts >= 3) return;+ verifyAttempts += 1;+ console.warn("[ds-bot] sidebar entry missing after shell mount; remounting");+ groups.remount("shell");+ verifyTimer = setTimeout(verifySidebar, 250);+ };+ const reconcile = () => {+ groups.reconcile(groupsFor(surface.getSnapshot()));+ clearTimeout(verifyTimer);+ verifyAttempts = 0;+ verifyTimer = setTimeout(verifySidebar, 250);+ };reconcile();+ if (surface.getSnapshot().mode === "bot") ensureBotHome();const unsub = surface.subscribe(reconcile);return () => {unsub();+ clearTimeout(verifyTimer);groups.dispose();};}, "ds-bot: surface");diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex 6b8b5589..13b31576 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -375,6 +375,27 @@ export function apply(ctx) {}const mainView = () => Object.values(ctx.sessions.list.getSnapshot().byId ?? {}).find(session => (session?.retainedBy?.mainView ?? 0) > 0)?.idconst show = listedOpener({ list: ctx.sessions.list, refresh: () => Promise.resolve(ctx.sessions.refresh?.()).catch(quietly('refresh sessions')), open: (target) => { expected = target; ctx.uiWorkspace.openSession(target) }, current: mainView })+ // Bot mode's view must hold a team conversation; an outside Session wears the+ // Bot skin without one. Runs whenever the surface is (or stays) Bot mode —+ // including a cold start, where no setSurface call ever fires.+ const homeToMainBot = () => {+ const snapshot = roster.getSnapshot()+ if (!snapshot.ready || !snapshot.mainBotId) return+ const main = mainView()+ if (main !== undefined && snapshot.byId[main] === undefined && snapshot.roomsById[main] === undefined) {+ actions.openSession(snapshot.mainBotId)+ }+ }+ const ensureBotHome = () => {+ if (roster.getSnapshot().ready) homeToMainBot()+ else {+ const off = roster.subscribe(() => {+ if (!roster.getSnapshot().ready) return+ off()+ homeToMainBot()+ })+ }+ }const actions = {...teamActions({ call, after, partFor, roster, ui, live, cards, heldCards, turnClock }),// The full-pane overlays sit above the conversation, so opening one must dismiss them@@ -459,32 +480,19 @@ export function apply(ctx) {// surface closes first so nothing stale reopens on the way back.setSurface: (mode) => {if (mode !== 'bot' && mode !== 'agent') return- if (surface.getSnapshot().mode === mode) return+ // Already there: still worth the landing check — a cold start never calls+ // setSurface, so this is also how a stuck Bot surface recovers itself.+ if (surface.getSnapshot().mode === mode) {+ if (mode === 'bot') ensureBotHome()+ return+ }if (mode === 'agent') {ui.set(state => ({ ...state, details: null, view: 'details', settings: null, palette: null, newChat: null, menu: null, voice: null, exchange: null, memory: null, toast: null }))}writeMode(mode)surface.set(state => ({ ...state, mode }))if (mode !== 'bot') return- // Back in Bot mode the view must hold a team conversation; an outside- // Session left over from Agent mode would wear the Bot skin without one.- const home = () => {- const snapshot = roster.getSnapshot()- if (!snapshot.ready || !snapshot.mainBotId) return- const list = ctx.sessions.list.getSnapshot()- const main = Object.values(list.byId ?? {}).find(session => (session?.retainedBy?.mainView ?? 0) > 0)?.id- if (main !== undefined && snapshot.byId[main] === undefined && snapshot.roomsById[main] === undefined) {- actions.openSession(snapshot.mainBotId)- }- }- if (roster.getSnapshot().ready) home()- else {- const off = roster.subscribe(() => {- if (!roster.getSnapshot().ready) return- off()- home()- })- }+ ensureBotHome()},markUnread: id => writeUnread(id, true),beginVisit: (id) => {@@ -911,11 +919,50 @@ export function apply(ctx) {const groups = surfaceGroups({ shell: installShell, conversation: installConversation }, {onError: (_group, error) => actions.reportError(new Error(t('Bot mode could not be set up here: {error}', { error: error?.message ?? String(error) })), 'surface'),})- const reconcile = () => groups.reconcile(groupsFor(surface.getSnapshot()))+ // A shadow step can mount "successfully" with nothing registered: when a+ // slot's inject callback throws inside the host, the host cancels the+ // declaration's subscription but the step's disposer still counts the group+ // as mounted. After the shell goes on, check that its sidebar entry really+ // landed; remount a few times when it did not (cold start race).+ let verifyTimer = 0+ let verifyAttempts = 0+ const verifySidebar = () => {+ if (!groupsFor(surface.getSnapshot()).shell) return+ let landed = false+ let declared = true+ try {+ landed = ctx.slots.entries('sidebar.workspaces').some(entry => entry.component === TeamSidebar)+ declared = ctx.slots.spec?.('sidebar.workspaces') !== undefined+ } catch {+ declared = false+ }+ if (landed) return+ if (!declared) {+ // The slot itself is not declared yet; keep watching for a while.+ if (verifyAttempts < 20) {+ verifyAttempts += 1+ verifyTimer = setTimeout(verifySidebar, 250)+ }+ return+ }+ if (verifyAttempts >= 3) return+ verifyAttempts += 1+ console.warn('[ds-bot] sidebar entry missing after shell mount; remounting')+ groups.remount('shell')+ verifyTimer = setTimeout(verifySidebar, 250)+ }+ const reconcile = () => {+ groups.reconcile(groupsFor(surface.getSnapshot()))+ clearTimeout(verifyTimer)+ verifyAttempts = 0+ verifyTimer = setTimeout(verifySidebar, 250)+ }reconcile()+ if (surface.getSnapshot().mode === 'bot') ensureBotHome()const unsub = surface.subscribe(reconcile)return () => {unsub()+ clearTimeout(verifyTimer)groups.dispose()}}, 'ds-bot: surface')diff --git a/ds-bot/src/client/surface.js b/ds-bot/src/client/surface.jsindex 5644b887..262e5832 100644--- a/ds-bot/src/client/surface.js+++ b/ds-bot/src/client/surface.js@@ -33,23 +33,36 @@ export function surfaceGroups(install, { onError } = {}) {mounted[group] = []disposeAll(disposers, `withdraw ${group}`)}+ const mount = (group) => {+ const disposers = []+ try {+ for (const step of install[group]()) if (step) disposers.push(step())+ mounted[group] = disposers+ return true+ } catch (error) {+ disposeAll(disposers, `roll back ${group}`)+ console.warn(`[ds-bot] install ${group}`, error)+ onError?.(group, error)+ return false+ }+ }return {reconcile(wanted) {for (const group of [...GROUPS].reverse()) if (!wanted[group]) withdraw(group)for (const group of GROUPS) {if (!wanted[group] || mounted[group].length > 0) continue- const disposers = []- try {- for (const step of install[group]()) if (step) disposers.push(step())- mounted[group] = disposers- } catch (error) {- disposeAll(disposers, `roll back ${group}`)- console.warn(`[ds-bot] install ${group}`, error)- onError?.(group, error)- break- }+ if (!mount(group)) break}},+ // A step can go on with nothing actually contributed — a slot inject whose+ // callback threw inside the host still returns its disposer. remount takes+ // the group off and puts it back, so a caller that notices the contribution+ // is missing can retry instead of trusting `mounted`.+ remount(group) {+ if (!GROUPS.includes(group)) return+ withdraw(group)+ mount(group)+ },dispose() { for (const group of [...GROUPS].reverse()) withdraw(group) },}}diff --git a/ds-bot/test/surface.test.js b/ds-bot/test/surface.test.jsindex 752704a5..1c57804a 100644--- a/ds-bot/test/surface.test.js+++ b/ds-bot/test/surface.test.js@@ -123,6 +123,23 @@ test('a shell that cannot go on keeps the conversation group off too', (t) => {assert.deepEqual([...live], [])})+test('remount takes a mounted group off and installs it again', (t) => {+ t.mock.method(console, 'warn', () => {})+ const log = []+ const groups = recordingGroups(log)+ groups.reconcile(groupsFor({ mode: 'bot' }))+ log.length = 0+ groups.remount('shell')+ assert.deepEqual(log, ['shell theme', 'shell styles', 'install shell'])+ log.length = 0+ // A group that is not mounted installs without a withdraw pass.+ groups.reconcile(groupsFor({ mode: 'agent' }))+ log.length = 0+ groups.remount('shell')+ assert.deepEqual(log, ['install shell'])+ groups.dispose()+})+test('a shadow goes below every entry of its cell, so a same-priority plugin does not block it', () => {const entry = options => ({ options })assert.equal(freePriority([], { priority: -100 }), -100)