A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Open a Session only once DSH's list holds it
Fei241165c8d63c2487
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 22b7d294..2dc70733 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -14235,6 +14235,31 @@ function noticeApprovals({ work, roster, shownSession, openSession, since = Datereturn work.subscribe(notify);}+// src/client/open-listed.js+function listedOpener({ list, open, refresh }) {+ let drop = () => {+ };+ return (target) => {+ drop();+ drop = () => {+ };+ const listed = () => list.getSnapshot().byId?.[target] !== void 0;+ if (listed()) {+ open(target);+ return;+ }+ const off = list.subscribe(() => {+ if (!listed()) return;+ off();+ drop = () => {+ };+ open(target);+ });+ drop = off;+ refresh?.();+ };+}+// src/client/index.jsvar inject = ["sessions", "uiWorkspace", "uiConversation", "slots", "theme", "layout"];function apply(ctx) {@@ -14552,6 +14577,10 @@ function apply(ctx) {for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id);return ids;};+ const show = listedOpener({ list: ctx.sessions.list, refresh: () => Promise.resolve(ctx.sessions.refresh?.()).catch(quietly("refresh sessions")), open: (target) => {+ expected = target;+ ctx.uiWorkspace.openSession(target);+ } });const actions = {...teamActions({ call, after, partFor, roster, ui: ui2, live, cards, turnClock }),// The full-pane overlays sit above the conversation, so opening one must dismiss them@@ -14562,16 +14591,14 @@ function apply(ctx) {ui2.set((state) => state.newChat || state.exchange || state.menu || state.palette ? { ...state, newChat: null, exchange: null, menu: null, palette: null } : state);setPlain(false);const target = partFor(id);- expected = target;- ctx.uiWorkspace.openSession(target);+ show(target);},// The conversation replacements withdraw for a plain Session; set the surface// before the navigation so the Bot skin never flashes.openAgentSession: (sessionId) => {ui2.set((state) => ({ ...state, newChat: null, exchange: null, menu: null, palette: null, details: null, view: "details", renaming: false, tab: null }));setPlain(true);- expected = sessionId;- ctx.uiWorkspace.openSession(sessionId);+ show(sessionId);},addAgent: async () => {const agent = await after(call("add-agent"));@@ -14629,8 +14656,7 @@ function apply(ctx) {const bot = last ? roster.getSnapshot().byId[last.botId] : void 0;setPlain(false);const target = bot && currentPart(bot) !== last.sessionId ? currentPart(bot) : partFor(id);- expected = target;- ctx.uiWorkspace.openSession(target);+ show(target);},selectPanel: (id) => {ctx.layout.selectPanel(id);diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex c4127b07..93f7277c 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -35,6 +35,7 @@ import { ABOUT_CSS } from './about.js'import { MEMBER_CSS, MemberDock } from './member-status.js'import { USER_MESSAGE_CSS, UserMessageCell, canDrawUserMessages } from './user-message.js'import { noticeApprovals } from './approval-notices.js'+import { listedOpener } from './open-listed.js'export const inject = ['sessions', 'uiWorkspace', 'uiConversation', 'slots', 'theme', 'layout']@@ -340,6 +341,7 @@ export function apply(ctx) {for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id)return ids}+ const show = listedOpener({ list: ctx.sessions.list, refresh: () => Promise.resolve(ctx.sessions.refresh?.()).catch(quietly('refresh sessions')), open: (target) => { expected = target; ctx.uiWorkspace.openSession(target) } })const actions = {...teamActions({ call, after, partFor, roster, ui, live, cards, turnClock }),// The full-pane overlays sit above the conversation, so opening one must dismiss them@@ -351,16 +353,14 @@ export function apply(ctx) {ui.set(state => (state.newChat || state.exchange || state.menu || state.palette ? { ...state, newChat: null, exchange: null, menu: null, palette: null } : state))setPlain(false)const target = partFor(id)- expected = target- ctx.uiWorkspace.openSession(target)+ show(target)},// The conversation replacements withdraw for a plain Session; set the surface// before the navigation so the Bot skin never flashes.openAgentSession: (sessionId) => {ui.set(state => ({ ...state, newChat: null, exchange: null, menu: null, palette: null, details: null, view: 'details', renaming: false, tab: null }))setPlain(true)- expected = sessionId- ctx.uiWorkspace.openSession(sessionId)+ show(sessionId)},addAgent: async () => {const agent = await after(call('add-agent'))@@ -418,8 +418,7 @@ export function apply(ctx) {const bot = last ? roster.getSnapshot().byId[last.botId] : undefinedsetPlain(false)const target = bot && currentPart(bot) !== last.sessionId ? currentPart(bot) : partFor(id)- expected = target- ctx.uiWorkspace.openSession(target)+ show(target)},selectPanel: (id) => { ctx.layout.selectPanel(id) },toggleSidebar: () => { ctx.layout.toggleSidebar() },diff --git a/ds-bot/src/client/open-listed.js b/ds-bot/src/client/open-listed.jsnew file mode 100644index 00000000..2744639a--- /dev/null+++ b/ds-bot/src/client/open-listed.js@@ -0,0 +1,20 @@+// DSH's main view opens only a Session that its client list already holds; any other id+// throws `sessions.retain: unknown session`. A part the Host made a moment ago, or any part+// before the first list arrives, waits for the list; a newer navigation drops the wait.+export function listedOpener({ list, open, refresh }) {+ let drop = () => {}+ return (target) => {+ drop()+ drop = () => {}+ const listed = () => list.getSnapshot().byId?.[target] !== undefined+ if (listed()) { open(target); return }+ const off = list.subscribe(() => {+ if (!listed()) return+ off()+ drop = () => {}+ open(target)+ })+ drop = off+ refresh?.()+ }+}diff --git a/ds-bot/test/open-listed.test.js b/ds-bot/test/open-listed.test.jsnew file mode 100644index 00000000..baa35172--- /dev/null+++ b/ds-bot/test/open-listed.test.js@@ -0,0 +1,60 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { listedOpener } from '../src/client/open-listed.js'++const store = (ids = []) => {+ const listeners = new Set()+ const snapshot = { byId: {} }+ for (const id of ids) snapshot.byId[id] = { id }+ return {+ getSnapshot: () => snapshot,+ subscribe: (fn) => { listeners.add(fn); return () => { listeners.delete(fn) } },+ set: (id) => { snapshot.byId[id] = { id }; for (const fn of listeners) fn() },+ }+}++const rig = (list) => {+ const opened = []+ let refreshes = 0+ const show = listedOpener({ list, open: id => opened.push(id), refresh: () => { refreshes += 1 } })+ return { show, opened, refreshes: () => refreshes }+}++test('a listed Session opens at once and no refresh is asked for', () => {+ const { show, opened, refreshes } = rig(store(['a']))+ show('a')+ assert.deepEqual(opened, ['a'])+ assert.equal(refreshes(), 0)+})++test('an unlisted Session opens when the list reaches it, only once', () => {+ const list = store()+ const { show, opened, refreshes } = rig(list)+ show('a')+ assert.deepEqual(opened, [])+ assert.equal(refreshes(), 1)+ list.set('a')+ assert.deepEqual(opened, ['a'])+ list.set('b')+ assert.deepEqual(opened, ['a'])+})++test('a newer navigation drops the wait for the old one', () => {+ const list = store(['b'])+ const { show, opened } = rig(list)+ show('a')+ show('b')+ assert.deepEqual(opened, ['b'])+ list.set('a')+ assert.deepEqual(opened, ['b'])+})++test('two waits in a row keep only the last one', () => {+ const list = store()+ const { show, opened } = rig(list)+ show('a')+ show('b')+ list.set('a')+ list.set('b')+ assert.deepEqual(opened, ['b'])+})