A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep a folded panel folded when it follows the chat
Fei24112a27f864aa61
diff --git a/docs/design/ui-standard.md b/docs/design/ui-standard.mdindex 15c73e9c..0eec2d8a 100644--- a/docs/design/ui-standard.md+++ b/docs/design/ui-standard.md@@ -180,7 +180,7 @@ Bot 名字、提及用同一个颜色写字;纯黑读起来像标题,所以| 设置对话框 | 宽 `min(1100px, 100vw - 48px)`,高 `min(780px, …)`,所有页面同一尺寸(和用量页一致),切换页面时不变;左侧导航 198px || 记忆对话框 | 宽 `min(680px, 100vw - 48px)`,高 `min(760px, …)` || 右侧面板 | 详情 320px;浏览器默认 520px,可拖动,最小 360px,对话列至少保留 420px |-| 左侧栏 | 收起后是自己的 88px 头像窄栏(Windows、macOS、网页都一样)。窗口变窄时先收右侧面板,仍放不下才盖住对话;窄时打开面板,左侧栏先收成窄栏让位 |+| 左侧栏 | 和右侧面板一样不被挤窄。窗口变窄时先收起右侧面板(放得下时自动回来),再把左侧栏收成 88px 头像窄栏(头像 44px),Windows、macOS、网页都一样;手动收起也是这条窄栏。窄时打开面板,左侧栏先收成窄栏让位,仍放不下才盖住对话。桌面应用最小窗口宽 508px(窄栏 + 420) || 气泡 | Bot 气泡最宽 `min(var(--bt-msg-w) × 100%, 100% - 82px)`,用户气泡最宽 `var(--bt-msg-w) × 100%`;`--bt-msg-w` 是设置里的气泡宽度(50%–100%,默认 80%) || 输入框卡片 | 最宽 `min(992px, 100%)` || 主 Bot 卡片 | 宽 95px |diff --git a/ds-bot/client.js b/ds-bot/client.jsindex ac33b4d7..e821704c 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -1512,8 +1512,9 @@ function countCards(state, sessionId, callIds, delta) {// src/client/team-actions.jsfunction teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards, heldCards, turnClock, panelFolded }) {const memoryOf = (id) => roster.getSnapshot().roomsById[id] ? { roomId: id } : { botId: id };+ const yieldTo = (view) => panelFolded?.(view) === true;const openSideChat = (sessionId, chatId) => {- ui2.set((state) => ({ ...state, details: sessionId, view: "side", side: chatId ?? null, renaming: false, tab: null }));+ ui2.set((state) => ({ ...state, details: sessionId, view: "side", side: chatId ?? null, renaming: false, tab: null, panelYield: yieldTo("side") }));};return {openNewChat: (mode) => {@@ -1538,7 +1539,7 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cardstoggleDetails: (id, force) => {ui2.set((state) => {const details = force || state.details !== id || state.view !== "details" ? id : null;- if (details === null && panelFolded?.() === true) return { ...state, renaming: false, tab: null, details: id, view: "details", panelYield: true };+ if (details === null && yieldTo("details")) return { ...state, renaming: false, tab: null, details: id, view: "details", panelYield: true };return { ...state, renaming: false, tab: null, details, view: "details" };});},@@ -1554,11 +1555,11 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards});},showDetails: (id, tab = null) => {- ui2.set((state) => ({ ...state, details: id, view: "details", renaming: false, tab }));+ ui2.set((state) => ({ ...state, details: id, view: "details", renaming: false, tab, panelYield: yieldTo("details") }));},// Opening the conversation would move focus to its composer and blur the name field.renameBot: (id) => {- ui2.set((state) => ({ ...state, details: id, view: "details", renaming: true, tab: null }));+ ui2.set((state) => ({ ...state, details: id, view: "details", renaming: true, tab: null, panelYield: yieldTo("details") }));},// `id` opens one Bot (page 'bots') or one group chat (page 'groups').openSettings: (page = "general", id = null) => {@@ -1578,7 +1579,7 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards},setPanelView: (view) => {if (view !== "details" && view !== "browser" && view !== "side") return;- ui2.set((state) => state.details && state.view !== view ? { ...state, view } : state);+ ui2.set((state) => state.details && state.view !== view ? { ...state, view, panelYield: yieldTo(view) } : state);},// A side chat on the panel's own view, opened from the strip, the `···`// menus or `/side`. Closing the panel keeps the chats; only a tab's × deletes.@@ -8582,7 +8583,9 @@ function installFrameWatch(frame) {const watched = /* @__PURE__ */ new Set();const observer = typeof ResizeObserver === "function" ? new ResizeObserver(() => schedule()) : null;const read = () => {- const width = sidebarTrackWidth();+ const column = document.querySelector('[class*="_sidebarCol"]');+ const animating = column?.closest("[data-animating]") != null;+ const width = animating ? null : sidebarTrackWidth();const collapsed = dshCollapsed();if (width !== null) {if (collapsed === true) collapsedWidth = width;@@ -8612,7 +8615,7 @@ function installFrameWatch(frame) {};measure();const mutations = new MutationObserver(schedule);- mutations.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-sidebar-collapsed"] });+ mutations.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-sidebar-collapsed", "data-animating"] });window.addEventListener("resize", schedule);return () => {cancelAnimationFrame(raf);@@ -19433,11 +19436,11 @@ function apply(ctx) {expected2 = target;ctx.uiWorkspace.openSession(target);}, current: mainView });- const panelFolded = () => {+ const panelFolded = (view) => {const state = ui2.getSnapshot();if (state.details === null) return false;const f = frame.getSnapshot();- return frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: state.leftDrawer, panel: { view: state.view, yielded: false } }).panel === "folded";+ return frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: state.leftDrawer, panel: { view: view ?? state.view, yielded: false } }).panel === "folded";};const actions = {...teamActions({ call, after, partFor, roster, ui: ui2, live, cards, heldCards, turnClock, panelFolded }),@@ -19589,7 +19592,7 @@ function apply(ctx) {if (!bot) return;browsers.ensureTabs(bot.id);if (browsers.tabs.getSnapshot()[bot.id]?.active == null) browsers.openTab(bot.id);- ui2.set((state) => ({ ...state, details: id, view: "browser", renaming: false, tab: null }));+ ui2.set((state) => ({ ...state, details: id, view: "browser", renaming: false, tab: null, panelYield: panelFolded("browser") }));},// '+' on the strip or the drawer's new-tab card: a blank tab in the browser view.browserNewTab: (id) => {@@ -19597,7 +19600,7 @@ function apply(ctx) {if (!bot) return null;browsers.ensureTabs(bot.id);const tabId = browsers.openTab(bot.id);- ui2.set((state) => ({ ...state, details: id, view: "browser", renaming: false, tab: null }));+ ui2.set((state) => ({ ...state, details: id, view: "browser", renaming: false, tab: null, panelYield: panelFolded("browser") }));return tabId;},// A drawer card: its tab active, the panel on the browser view.@@ -19605,7 +19608,7 @@ function apply(ctx) {const bot = roster.getSnapshot().byId[id];if (!bot) return;browsers.activate(bot.id, tabId);- ui2.set((state) => ({ ...state, details: id, view: "browser" }));+ ui2.set((state) => ({ ...state, details: id, view: "browser", panelYield: panelFolded("browser") }));},browserEnsure: (botId) => browsers.ensureTabs(botId),browserCloseTab: (botId, tabId) => browsers.closeTab(botId, tabId),@@ -19831,12 +19834,12 @@ function apply(ctx) {controller.toggleSource(CHATS_SOURCE, { trigger: "@", query: "", quoted: false, position: "inline", span });};const installFrameSync = () => {- let last = { details: ui2.getSnapshot().details, view: ui2.getSnapshot().view };+ let lastDetails = ui2.getSnapshot().details;const sync = () => {const s = ui2.getSnapshot();const f = frame.getSnapshot();- const opened = s.details !== null && (s.details !== last.details || s.view !== last.view);- last = { details: s.details, view: s.view };+ const opened = s.details !== null && lastDetails === null;+ lastDetails = s.details;const layout = frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: s.leftDrawer === true, panel: s.details === null ? null : { view: s.view, yielded: false } });if (s.details === null) {if (s.panelYield) actions.setPanelYield(false);diff --git a/ds-bot/src/client/frame-watch.js b/ds-bot/src/client/frame-watch.jsindex d6d33fd0..4bc47d67 100644--- a/ds-bot/src/client/frame-watch.js+++ b/ds-bot/src/client/frame-watch.js@@ -73,7 +73,13 @@ export function installFrameWatch(frame) {const watched = new Set()const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(() => schedule()) : nullconst read = () => {- const width = sidebarTrackWidth()+ // While the shell slides its sidebar (data-animating on the frame) the+ // track reports in-between widths: keep the last settled ones. The viewport+ // and the collapsed flag still update; the observer refires when the flag+ // clears, so the settled width lands then.+ const column = document.querySelector('[class*="_sidebarCol"]')+ const animating = column?.closest('[data-animating]') != null+ const width = animating ? null : sidebarTrackWidth()const collapsed = dshCollapsed()if (width !== null) {if (collapsed === true) collapsedWidth = width@@ -97,7 +103,7 @@ export function installFrameWatch(frame) {}measure()const mutations = new MutationObserver(schedule)- mutations.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['data-sidebar-collapsed'] })+ mutations.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['data-sidebar-collapsed', 'data-animating'] })window.addEventListener('resize', schedule)return () => {cancelAnimationFrame(raf)diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex fb33c0fc..c10167b3 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -384,11 +384,11 @@ export function apply(ctx) {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 })// Whether the open Bot panel is folded away for lack of room: its opener then// means "show it" (the column yields), not "close it".- const panelFolded = () => {+ const panelFolded = (view) => {const state = ui.getSnapshot()if (state.details === null) return falseconst f = frame.getSnapshot()- return frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: state.leftDrawer, panel: { view: state.view, yielded: false } }).panel === 'folded'+ return frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: state.leftDrawer, panel: { view: view ?? state.view, yielded: false } }).panel === 'folded'}const actions = {...teamActions({ call, after, partFor, roster, ui, live, cards, heldCards, turnClock, panelFolded }),@@ -541,7 +541,7 @@ export function apply(ctx) {if (!bot) returnbrowsers.ensureTabs(bot.id)if (browsers.tabs.getSnapshot()[bot.id]?.active == null) browsers.openTab(bot.id)- ui.set(state => ({ ...state, details: id, view: 'browser', renaming: false, tab: null }))+ ui.set(state => ({ ...state, details: id, view: 'browser', renaming: false, tab: null, panelYield: panelFolded('browser') }))},// '+' on the strip or the drawer's new-tab card: a blank tab in the browser view.browserNewTab: (id) => {@@ -549,7 +549,7 @@ export function apply(ctx) {if (!bot) return nullbrowsers.ensureTabs(bot.id)const tabId = browsers.openTab(bot.id)- ui.set(state => ({ ...state, details: id, view: 'browser', renaming: false, tab: null }))+ ui.set(state => ({ ...state, details: id, view: 'browser', renaming: false, tab: null, panelYield: panelFolded('browser') }))return tabId},// A drawer card: its tab active, the panel on the browser view.@@ -557,7 +557,7 @@ export function apply(ctx) {const bot = roster.getSnapshot().byId[id]if (!bot) returnbrowsers.activate(bot.id, tabId)- ui.set(state => ({ ...state, details: id, view: 'browser' }))+ ui.set(state => ({ ...state, details: id, view: 'browser', panelYield: panelFolded('browser') }))},browserEnsure: botId => browsers.ensureTabs(botId),browserCloseTab: (botId, tabId) => browsers.closeTab(botId, tabId),@@ -801,12 +801,15 @@ export function apply(ctx) {// that fits again, or is closed, and a drawer that no longer applies drop// their flags.const installFrameSync = () => {- let last = { details: ui.getSnapshot().details, view: ui.getSnapshot().view }+ let lastDetails = ui.getSnapshot().detailsconst sync = () => {const s = ui.getSnapshot()const f = frame.getSnapshot()- const opened = s.details !== null && (s.details !== last.details || s.view !== last.view)- last = { details: s.details, view: s.view }+ // Only a fresh open counts: a folded panel that just follows the chat to+ // another subject is not the user asking to see it — the openers in+ // team-actions carry the yield themselves.+ const opened = s.details !== null && lastDetails === null+ lastDetails = s.detailsconst layout = frameLayout({ viewport: f.viewport, sidebarWidth: f.sidebarWidth, collapsedWidth: f.collapsedWidth, pref: sidebarPref.getSnapshot(), drawer: s.leftDrawer === true, panel: s.details === null ? null : { view: s.view, yielded: false } })if (s.details === null) {if (s.panelYield) actions.setPanelYield(false)diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.jsindex 10277071..8fc17628 100644--- a/ds-bot/src/client/team-actions.js+++ b/ds-bot/src/client/team-actions.js@@ -8,9 +8,13 @@ import { noteClientError } from './diagnostics.js'export function teamActions({ call, after, partFor, roster, ui, live, cards, heldCards, turnClock, panelFolded }) {// A memory is a Bot's or a group chat's; both are opened by id.const memoryOf = id => (roster.getSnapshot().roomsById[id] ? { roomId: id } : { botId: id })+ // An action that shows the panel lands the yield with it: when a folded+ // panel's explicit opener fires, the column gives way in the same set.+ // `view` is the next view, since its minimum decides what fits.+ const yieldTo = view => panelFolded?.(view) === true// The panel on a side chat's view, on the chat the strip tab or menu named.const openSideChat = (sessionId, chatId) => {- ui.set(state => ({ ...state, details: sessionId, view: 'side', side: chatId ?? null, renaming: false, tab: null }))+ ui.set(state => ({ ...state, details: sessionId, view: 'side', side: chatId ?? null, renaming: false, tab: null, panelYield: yieldTo('side') }))}return {openNewChat: (mode) => { ui.set(state => ({ ...state, newChat: mode, menu: null, palette: null })) },@@ -25,7 +29,7 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, helconst details = force || state.details !== id || state.view !== 'details' ? id : null// A folded panel is open but not shown: its opener then means "show it"// (the column yields it room), not "close it".- if (details === null && panelFolded?.() === true) return { ...state, renaming: false, tab: null, details: id, view: 'details', panelYield: true }+ if (details === null && yieldTo('details')) return { ...state, renaming: false, tab: null, details: id, view: 'details', panelYield: true }return { ...state, renaming: false, tab: null, details, view: 'details' }})},@@ -42,9 +46,9 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, helreturn { ...state, details: id, view, renaming: false, tab: null }})},- showDetails: (id, tab = null) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: false, tab })) },+ showDetails: (id, tab = null) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: false, tab, panelYield: yieldTo('details') })) },// Opening the conversation would move focus to its composer and blur the name field.- renameBot: (id) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: true, tab: null })) },+ renameBot: (id) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: true, tab: null, panelYield: yieldTo('details') })) },// `id` opens one Bot (page 'bots') or one group chat (page 'groups').openSettings: (page = 'general', id = null) => { ui.set(state => ({ ...state, settings: { page, id }, menu: null, palette: null, newChat: null })) },closeSettings: () => { ui.set(state => (state.settings ? { ...state, settings: null } : state)) },@@ -53,7 +57,7 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, helopenConnectors: () => { ui.set(state => ({ ...state, settings: { page: 'connectors', id: null }, menu: null, palette: null, newChat: null })) },setPanelView: (view) => {if (view !== 'details' && view !== 'browser' && view !== 'side') return- ui.set(state => (state.details && state.view !== view ? { ...state, view } : state))+ ui.set(state => (state.details && state.view !== view ? { ...state, view, panelYield: yieldTo(view) } : state))},// A side chat on the panel's own view, opened from the strip, the `···`// menus or `/side`. Closing the panel keeps the chats; only a tab's × deletes.diff --git a/ds-bot/test/frame-layout.test.js b/ds-bot/test/frame-layout.test.jsindex 313fe29b..7aeff6a0 100644--- a/ds-bot/test/frame-layout.test.js+++ b/ds-bot/test/frame-layout.test.js@@ -4,6 +4,8 @@ import {RAIL_WIDTH, DSH_NARROW,frameLayout, dshExpandedFor, userSidebarToggle,} from '../src/client/frame-layout.js'+import { createSource } from '../src/client/sources.js'+import { teamActions } from '../src/client/team-actions.js'// The window, the shell sidebar's track width and what is open decide which left// column shows and how the Bot panel sits; the chat keeps MIN_CHAT.@@ -97,3 +99,37 @@ test('an unrequested flip on one side of the line is the user', () => {assert.equal(userSidebarToggle({ before, after: { collapsed: true, viewport: 1300 } }), true)assert.equal(userSidebarToggle({ before: { collapsed: true, viewport: 800 }, after: { collapsed: false, viewport: 700 } }), true)})++// A folded panel is open but not shown. The panel following the chat to another+// subject is not the user asking to see it; the openers are.+const bench = (folded) => {+ const ui = createSource({ details: 'chief', view: 'details', renaming: false, tab: null, side: null, panelYield: false, leftDrawer: false })+ const roster = createSource({ byId: { chief: { id: 'chief' }, writer: { id: 'writer' } }, roomsById: {}, sideChats: {} })+ const actions = teamActions({+ call: () => Promise.resolve(null), after: promise => promise, partFor: id => id,+ roster, ui, panelFolded: () => folded,+ })+ return { ui, actions }+}++test('the folded panel does not resurface when it follows the chat elsewhere', () => {+ const { ui, actions } = bench(true)+ actions.followPanel('writer')+ assert.equal(ui.getSnapshot().details, 'writer')+ assert.equal(ui.getSnapshot().panelYield, false)+})++test('explicit openers on the folded panel yield the column to it', () => {+ const { ui, actions } = bench(true)+ actions.showDetails('writer')+ assert.equal(ui.getSnapshot().panelYield, true)+ ui.set(state => ({ ...state, panelYield: false }))+ actions.openSideChat('chief', 'chat-1')+ assert.equal(ui.getSnapshot().panelYield, true)+})++test('openers on a panel that fits do not yield', () => {+ const { ui, actions } = bench(false)+ actions.showDetails('writer')+ assert.equal(ui.getSnapshot().panelYield, false)+})