Skip to content

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

Drop a waiting open when the view moves elsewhere

Fei2411024134496918
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 2dc70733..65ca56dc 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -14236,7 +14236,7 @@ function noticeApprovals({ work, roster, shownSession, openSession, since = Date
}
// src/client/open-listed.js
-function listedOpener({ list, open, refresh }) {
+function listedOpener({ list, open, refresh, current }) {
let drop = () => {
};
return (target) => {
@@ -14248,7 +14248,14 @@ function listedOpener({ list, open, refresh }) {
open(target);
return;
}
+ const from = current?.();
const off = list.subscribe(() => {
+ if (current?.() !== from) {
+ off();
+ drop = () => {
+ };
+ return;
+ }
if (!listed()) return;
off();
drop = () => {
@@ -14577,10 +14584,11 @@ function apply(ctx) {
for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id);
return ids;
};
+ const mainView = () => Object.values(ctx.sessions.list.getSnapshot().byId ?? {}).find((session) => (session?.retainedBy?.mainView ?? 0) > 0)?.id;
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);
- } });
+ }, current: mainView });
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
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 93f7277c..335c5a23 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -341,7 +341,8 @@ 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 mainView = () => Object.values(ctx.sessions.list.getSnapshot().byId ?? {}).find(session => (session?.retainedBy?.mainView ?? 0) > 0)?.id
+ 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) }, current: mainView })
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
diff --git a/ds-bot/src/client/open-listed.js b/ds-bot/src/client/open-listed.js
index 2744639a..460741df 100644
--- a/ds-bot/src/client/open-listed.js
+++ b/ds-bot/src/client/open-listed.js
@@ -1,14 +1,21 @@
// 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 }) {
+// before the first list arrives, waits for the list; a newer navigation — through here or
+// elsewhere — drops the wait.
+export function listedOpener({ list, open, refresh, current }) {
let drop = () => {}
return (target) => {
drop()
drop = () => {}
const listed = () => list.getSnapshot().byId?.[target] !== undefined
if (listed()) { open(target); return }
+ const from = current?.()
const off = list.subscribe(() => {
+ if (current?.() !== from) {
+ off()
+ drop = () => {}
+ return
+ }
if (!listed()) return
off()
drop = () => {}
diff --git a/ds-bot/test/open-listed.test.js b/ds-bot/test/open-listed.test.js
index baa35172..f639c911 100644
--- a/ds-bot/test/open-listed.test.js
+++ b/ds-bot/test/open-listed.test.js
@@ -5,18 +5,23 @@ 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 }
+ const notify = () => { for (const fn of listeners) fn() }
+ const put = (id, main) => { snapshot.byId[id] = main ? { id, retainedBy: { mainView: 1 } } : { id } }
+ for (const id of ids) put(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() },
+ set: (id) => { put(id); notify() },
+ setMain: (id) => { for (const row of Object.values(snapshot.byId)) delete row.retainedBy; put(id, true); notify() },
}
}
+const mainViewOf = list => Object.values(list.getSnapshot().byId).find(row => (row?.retainedBy?.mainView ?? 0) > 0)?.id
+
const rig = (list) => {
const opened = []
let refreshes = 0
- const show = listedOpener({ list, open: id => opened.push(id), refresh: () => { refreshes += 1 } })
+ const show = listedOpener({ list, open: id => opened.push(id), refresh: () => { refreshes += 1 }, current: () => mainViewOf(list) })
return { show, opened, refreshes: () => refreshes }
}
@@ -58,3 +63,13 @@ test('two waits in a row keep only the last one', () => {
list.set('b')
assert.deepEqual(opened, ['b'])
})
+
+test('a navigation elsewhere drops the wait', () => {
+ const list = store(['x'])
+ list.setMain('x')
+ const { show, opened } = rig(list)
+ show('a')
+ list.setMain('y')
+ list.set('a')
+ assert.deepEqual(opened, [])
+})