From 4bcf061d7619f6fec1b1104c1506dd28f101fa83 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Thu, 19 Nov 2026 07:46:45 +0800 Subject: [PATCH 1/2] Open the part a search hit was said in (#3114) The palette's whole-text rows named the turn a hit belongs to but dropped the part the host already knew, so a hit in an earlier part was only labelled Earlier part and the click landed on the start of the current part. chats.search now answers part (the hit's own Session id) for the caller's own Bot chats, and the client opens that part at its turn; a part the chat does not own, or the session list no longer holds, keeps the current part and gives the seek up. --- changelog.d/3114-history-hit-part.added.md | 1 + core/client.js | 22 ++++++++++---- core/src/client/index.js | 11 +++---- core/src/client/palette.js | 12 ++++++-- core/src/client/text.js | 12 ++++++++ core/src/host/channel.js | 9 ++++-- core/test/chat-index-writers.test.js | 25 ++++++++++++++++ core/test/land-on.test.js | 17 +++++++++++ core/test/palette-preview.test.js | 27 +++++++++++++++++ docs/subsystems/core-client.md | 2 +- docs/subsystems/core-host.md | 2 +- patches/ds-bot/0001-core-fixes.patch | 14 ++++++++- patches/ds-bot/0003-flybot-api-client.patch | 30 ++++++++++++------- patches/ds-bot/0005-social-seams.patch | 11 +++++-- patches/ds-bot/0008-client-bundle.patch | 27 ++++++++++++----- .../files/test/chat-index-writers.test.js | 25 ++++++++++++++++ patches/ds-bot/files/test/land-on.test.js | 17 +++++++++++ .../ds-bot/files/test/palette-preview.test.js | 27 +++++++++++++++++ 18 files changed, 250 insertions(+), 41 deletions(-) create mode 100644 changelog.d/3114-history-hit-part.added.md diff --git a/changelog.d/3114-history-hit-part.added.md b/changelog.d/3114-history-hit-part.added.md new file mode 100644 index 000000000..a2a3d1c1f --- /dev/null +++ b/changelog.d/3114-history-hit-part.added.md @@ -0,0 +1 @@ +A history search hit that was said in an earlier part of a chat now opens that part and lands on the message, instead of only being labelled `Earlier part` and dropping the reader at the start of the current part; a hit in a part the chat does not own, or that the session list no longer holds, stays on the current part and does not jump to a same-numbered turn that is another message ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index c862224a8..4c518dd1e 100644 --- a/core/client.js +++ b/core/client.js @@ -2098,6 +2098,14 @@ function landingPart(roster, last, mainId, { stay = false, view = "", sessions } if (sessions === void 0) return destinations[0]; return destinations.find((id) => sessions.byId?.[id] !== void 0); } +function openTarget(roster, sessions, id, part) { + const bot = roster.byId?.[id]; + if (bot === void 0) return { target: id, seek: true }; + const current = currentPart(bot); + if (part === void 0 || part === current) return { target: current, seek: true }; + const owned = part === bot.sessionId || (bot.parts ?? []).includes(part); + return owned && sessions?.byId?.[part] !== void 0 ? { target: part, seek: true } : { target: current, seek: false }; +} function reminderPrompts(text2) { const one = /^reminder_prompt_json: (.*)$/m.exec(text2); const batch = /^reminders_json: (.*)$/m.exec(text2); @@ -16661,7 +16669,7 @@ function CommandPalette({ start, token, roster, actions, useSessions }) { const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => { const bot = roster.byId[row.chat]; const room2 = roster.roomsById[row.chat]; - const here = inPart(row.chat, row.turn); + const earlier = typeof row.part === "string" ? bot !== void 0 && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false; const at = `${row.chat}:${row.turn}`; const count = (keyCounts.get(at) ?? 0) + 1; keyCounts.set(at, count); @@ -16670,8 +16678,10 @@ function CommandPalette({ start, token, roster, actions, useSessions }) { title: bot?.name ?? room2?.name ?? t("Bot"), subtitle: row.text, avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }), - badge: here === false ? t("Earlier part") : void 0, - run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }) + badge: earlier ? t("Earlier part") : void 0, + // A row lands where it points: another part opens that part at its turn, so the words are + // on screen; the current part keeps its seek; a row with no part keeps today's navigation. + run: earlier && row.part !== void 0 ? () => actions.openSession(row.chat, { part: row.part, turn: row.turn }) : earlier ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }) }; }); const hidden = wholeText?.more ?? 0; @@ -24022,15 +24032,15 @@ function apply(ctx) { // The full-pane overlays sit above the conversation, so opening one must dismiss them // or the click appears to do nothing. isAgentSession: (id) => isAgentSessionId(id), - openSession: (id, { turn } = {}) => { + openSession: (id, { turn, part } = {}) => { noteNavigation("openSession", id); if (isAgentSessionId(id)) return actions.openAgentSession(id); 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); + const { target, seek } = openTarget(roster.getSnapshot(), ctx.sessions.list.getSnapshot(), id, part); expected = target; ctx.uiWorkspace.openSession(target); - seekTurn(turn); + if (seek) seekTurn(turn); }, // The palette's whole-text message search (P-820): the host answers with the // caller's own chats, whole lines with the turn they belong to. diff --git a/core/src/client/index.js b/core/src/client/index.js index d981e7316..c18aa4235 100644 --- a/core/src/client/index.js +++ b/core/src/client/index.js @@ -7,7 +7,7 @@ import { isHex } from './inks.js' import { SHAPES, markupCache } from './characters.js' import { countCards, createSource, EMPTY_ROSTER, indexRoster, isAgentSession, stateAnswerIsStale, stateRequest } from './sources.js' import { themeCss, shellTokens, registry, registerShape, registerTheme, allThemes } from './themes.js' -import { currentPart, landingPart, setPluginTools } from './text.js' +import { currentPart, landingPart, openTarget, setPluginTools } from './text.js' import { mentionCss } from './mention-style.js' import { SHELL_CSS, CONVERSATION_CSS, installStyles, installCompiledStyles } from './styles.js' import { installBrandChrome, installTabTitle } from './brand.js' @@ -414,10 +414,11 @@ export function apply(ctx) { for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id) return ids } - // The palette's whole-text rows name the turn the hit belongs to (P-820). DSH opens a + // The palette's whole-text rows name the turn the hit belongs to and its part (#3114). DSH opens a // session by id only, so the turn is found where the message pills already look: the // flow's own DOM. A turn the host has not loaded lands on the nearest view — the row's // snippet still shows the words — and the seek gives up rather than spin. + // A part that could not be opened gives the seek up too: the same turn number is another line. const seekTurn = (turn) => { if (!Number.isInteger(turn) || turn < 0 || typeof document === 'undefined') return let tries = 0 @@ -433,16 +434,16 @@ export function apply(ctx) { // The full-pane overlays sit above the conversation, so opening one must dismiss them // or the click appears to do nothing. isAgentSession: id => isAgentSessionId(id), - openSession: (id, { turn } = {}) => { + openSession: (id, { turn, part } = {}) => { noteNavigation('openSession', id) // A DSH Agent Session id lands on the plain surface, not the Bot skin. if (isAgentSessionId(id)) return actions.openAgentSession(id) 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) + const { target, seek } = openTarget(roster.getSnapshot(), ctx.sessions.list.getSnapshot(), id, part) expected = target ctx.uiWorkspace.openSession(target) - seekTurn(turn) + if (seek) seekTurn(turn) }, // The palette's whole-text message search (P-820): the host answers with the // caller's own chats, whole lines with the turn they belong to. diff --git a/core/src/client/palette.js b/core/src/client/palette.js index 2d7c3bc15..5bd7804b8 100644 --- a/core/src/client/palette.js +++ b/core/src/client/palette.js @@ -124,15 +124,21 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => { const bot = roster.byId[row.chat] const room = roster.roomsById[row.chat] - const here = inPart(row.chat, row.turn) + // A row that names its part is placed by that part (#3114); a row without one keeps the + // outline's answer, the only proof the client has about what the part it holds contains. + const earlier = typeof row.part === 'string' ? bot !== undefined && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false const at = `${row.chat}:${row.turn}` const count = (keyCounts.get(at) ?? 0) + 1 keyCounts.set(at, count) return { key: count > 1 ? `${at}:${count}` : at, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text, avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }), - badge: here === false ? t('Earlier part') : undefined, - run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }), + badge: earlier ? t('Earlier part') : undefined, + // A row lands where it points: another part opens that part at its turn, so the words are + // on screen; the current part keeps its seek; a row with no part keeps today's navigation. + run: earlier && row.part !== undefined + ? () => actions.openSession(row.chat, { part: row.part, turn: row.turn }) + : earlier ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }), } }) const hidden = wholeText?.more ?? 0 diff --git a/core/src/client/text.js b/core/src/client/text.js index 45ce369d8..a155eb9e8 100644 --- a/core/src/client/text.js +++ b/core/src/client/text.js @@ -101,6 +101,18 @@ export function landingPart(roster, last, mainId, { stay = false, view = '', ses // caught up with falls back to the chat it replaced, and nothing known at all is `undefined`. return destinations.find(id => sessions.byId?.[id] !== undefined) } +// #3114: where a search row lands. A row that names its part is placed by that part: the part +// opens when the chat owns it and the shell's session list holds it. A part that fails either +// test is not opened — the chat's current part opens with no seek, because the same turn +// number there is a different message. +export function openTarget(roster, sessions, id, part) { + const bot = roster.byId?.[id] + if (bot === undefined) return { target: id, seek: true } + const current = currentPart(bot) + if (part === undefined || part === current) return { target: current, seek: true } + const owned = part === bot.sessionId || (bot.parts ?? []).includes(part) + return owned && sessions?.byId?.[part] !== undefined ? { target: part, seek: true } : { target: current, seek: false } +} // The prompts in a due scheduled task's message. DSH frames it for the model: one // task as `reminder_prompt_json: "…"`, several as `reminders_json: [{reminder_prompt}]`. export function reminderPrompts(text) { diff --git a/core/src/host/channel.js b/core/src/host/channel.js index c25f1790a..16ddf79ba 100644 --- a/core/src/host/channel.js +++ b/core/src/host/channel.js @@ -383,14 +383,16 @@ export function install(rt) { // The palette's whole-text rows (P-820). `view(actor)` is the narrowing `state` uses: // it keeps the actor's own Bots, and also the other-owner Bots a shared room carries so // the room renders. Those Bots' own chats are not room content, so only the sessions - // the actor owns are searched; a room's own parts stay, because the room is shared. + // the actor owns are searched; a room's own parts stay, because the room is shared. Only a Bot's own chat part is named `part` (#3114). await rt.load() const query = String(body.query ?? '') const scoped = view(actor) const sessionToChat = new Map() + const ownParts = new Set() for (const bot of scoped.bots) for (const part of [bot.sessionId, ...(bot.parts ?? [])]) { if (rt.authzEnforced?.() && !rt.sessionOwnedBy?.(actor, part)) continue sessionToChat.set(part, bot.id) + ownParts.add(part) } for (const room of scoped.rooms) for (const part of room.parts ?? []) if (!sessionToChat.has(part)) sessionToChat.set(part, room.id) const { rows, more } = await rt.searchHomeChat([...sessionToChat.keys()], query) @@ -400,7 +402,10 @@ export function install(rt) { .map(row => { const lower = row.text.toLowerCase() const wanted = terms.find(term => lower.includes(term)) ?? '' - return { chat: sessionToChat.get(row.session) ?? null, turn: row.turn, text: excerpt(row.text, wanted) } + return { + chat: sessionToChat.get(row.session) ?? null, turn: row.turn, text: excerpt(row.text, wanted), + ...(ownParts.has(row.session) ? { part: row.session } : {}), + } }) .filter(row => row.chat !== null), more, diff --git a/core/test/chat-index-writers.test.js b/core/test/chat-index-writers.test.js index 1e29d5453..00e2e5325 100644 --- a/core/test/chat-index-writers.test.js +++ b/core/test/chat-index-writers.test.js @@ -367,6 +367,30 @@ test('chats.search answers through the channel with only the caller\'s chats (P- } }) +// #3114. A row already names the turn the hit belongs to; it now names the part too, so the +// client can open that part instead of only marking the hit as earlier. The part is the part's +// own Session id — the same `session` the index rows carry — and it is only for a Bot's own +// chat: a room's row is not a part the palette may open, so it carries none. +test('#3114: a chats.search row names the part the hit was said in', async (t) => { + const home = scratch(t, 'ds-bot-index-part-') + HISTORY.older = [turnStart(0, 4), line(1, 'a plain line'), turnStart(2, 5), line(3, NEEDLE_LINE)] + try { + const seeded = seed() + seeded.bots.a.segments = [{ sessionId: 'older', endedAt: T0 + 9000 }] + const host = await start(t, home, { saved: seeded }) + assert.notEqual(host.route, undefined, 'the channel registered its /api/bot route') + const response = await host.route.fetch(new Request('http://localhost/api/bot', { + method: 'POST', + body: JSON.stringify({ endpoint: 'chats.search', payload: { query: 'needle' } }), + })) + const result = await response.json() + assert.equal(result.ok, true, JSON.stringify(result)) + assert.deepEqual(result.value.rows.map(row => [row.chat, row.part, row.turn]), [['a', 'older', 5]], JSON.stringify(result.value)) + } finally { + delete HISTORY.older + } +}) + // The same view, the security case: a shared room renders because it keeps the other member's // Bot in `bots`, and that Bot's own chat is not room content. owner-1 sits in `r1` with // owner-2's Bot `b`; `duo` is b's own chat. Searching it as owner-1 must answer nothing, while @@ -398,6 +422,7 @@ test('chats.search never reads another member\'s Bot own chat through a shared r assert.equal(shared.ok, true, JSON.stringify(shared)) assert.deepEqual(shared.value.rows.map(row => row.chat), ['r1'], JSON.stringify(shared.value)) assert.match(shared.value.rows[0].text, /hello from the room/) + assert.equal('part' in shared.value.rows[0], false, 'a room row names no part: the member part is not a chat to open') // What the fix restores: the refused read the state view already refused, at both layers. const refused = await host.route.fetch(new Request('http://localhost/api/bot', { diff --git a/core/test/land-on.test.js b/core/test/land-on.test.js index 8008da7da..444b54466 100644 --- a/core/test/land-on.test.js +++ b/core/test/land-on.test.js @@ -88,3 +88,20 @@ test('#1306: a destination the session list does not know is never handed to the assert.equal(landingPart({ byId: { friend: fresh, chief } }, last, 'chief', { stay: true, sessions: gone }), 'chief-2', 'a fresh part the list has not caught up with, the chat it replaced gone: the Main Bot') assert.equal(landingPart({ byId: { friend: fresh, chief } }, last, 'chief', { stay: true, sessions }), 'friend-1', 'the fresh part is unknown, the chat it replaced is known: stay on that chat') }) + +// #3114: a message row names the part it was said in. That part opens only when the chat owns +// it and the shell's session list holds it; a part that fails either test is not opened at all, +// and the row falls back to the chat's current part with no seek — the same turn number there +// is a different message. An id the roster does not hold keeps the id fallback it always had. +// The fix exports this, so it is resolved here: a missing export fails this case alone. +test('#3114: a named part is opened only when the chat owns it and the shell lists it', async () => { + const { openTarget } = await import('../src/client/text.js') + const bot = { id: 'friend', sessionId: 'friend-2', parts: ['friend-1'] } + const at = (id, part, known = sessions) => openTarget({ byId: { ...roster.byId, friend: bot } }, known, id, part) + assert.deepEqual(at('friend', 'friend-1'), { target: 'friend-1', seek: true }, 'a part the chat owns and the list holds') + assert.deepEqual(at('friend', 'friend-2'), { target: 'friend-2', seek: true }, 'the part that is already open') + assert.deepEqual(at('friend'), { target: 'friend-2', seek: true }, 'no part: the current part, as before') + assert.deepEqual(at('friend', 'chief-2'), { target: 'friend-2', seek: false }, 'a part another chat owns: no seek') + assert.deepEqual(at('friend', 'friend-1', { byId: {} }), { target: 'friend-2', seek: false }, 'a part the shell does not list: no seek') + assert.deepEqual(at('gone', 'friend-1'), { target: 'gone', seek: true }, 'an id the roster does not hold') +}) diff --git a/core/test/palette-preview.test.js b/core/test/palette-preview.test.js index 677c0e5ca..7757487b6 100644 --- a/core/test/palette-preview.test.js +++ b/core/test/palette-preview.test.js @@ -382,3 +382,30 @@ test('#3114: a query shorter than two characters asks nothing and renders no row assert.deepEqual(palette.calls.search, []) assert.deepEqual(palette.rows().filter(key => !key.startsWith('cmd:')), []) }) + +// A row that names its part is placed by that part (#3114): a hit the host puts in an earlier +// part opens that part and still seeks its turn there. The outline holds no turn of that part, +// so the row's own part is the only thing that can say where the words were said — and the row +// still says `Earlier part`, because the part it names is not the one the view holds. +test('#3114: a hit the host places in an earlier part opens that part at its turn', async () => { + const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, part: 's1-old', text: 'NEEDLE far past this part' }] }) + await palette.settle() + assert.deepEqual(palette.badges(), ['Earlier part']) + palette.choose('s1:12') + assert.equal(palette.calls.openSession.length, 1) + assert.equal(palette.calls.openSession[0][0], 's1') + assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') + assert.equal(palette.calls.openSession[0][1]?.turn, 12) +}) + +// The part that is already open is no earlier part: the row keeps its seek and names no part, +// so the navigation is the one it always was, and a hit the host says is here is not marked. +// The part is named, so this one case pins that naming it does not change the answer. +test('#3114: a hit in the current part keeps its own seek', async () => { + const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 1, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 1, part: 's1', text: 'NEEDLE inside this part' }] }) + await palette.settle() + assert.deepEqual(palette.badges(), []) + palette.choose('s1:1') + assert.equal(palette.calls.openSession[0][1]?.turn, 1) + assert.equal(palette.calls.openSession[0][1]?.part, undefined, 'the current part is not named as another part') +}) diff --git a/docs/subsystems/core-client.md b/docs/subsystems/core-client.md index 805c1d0e7..d991f6b35 100644 --- a/docs/subsystems/core-client.md +++ b/docs/subsystems/core-client.md @@ -259,7 +259,7 @@ The member's own chat keeps its `busyAcks[sessionId]` bubble and its visibility - The palette's Messages group read each chat's `turnOutline` projection, whose prompt and response previews stop at 50/120 characters, so any hit past that budget found nothing — most of a long reply. The Messages group keeps its outline read; beside it, **Messages (full text)** (`palette.js`) asks the host through `actions.searchChats` (`call('chats.search')` in `index.js`, scoped to the caller's own chats — the host half is in [core-host](core-host.md)), debounced 150 ms, with an `AbortController` and a generation guard so an answer for a query the user already changed is dropped with the effect that asked. Rows a chat/turn pair the outline already found are the same message and are not shown twice; a part's own Session id and the Bot id a host row names are first folded to the one chat (`chatOf`), so a Bot whose current part is a Session of its own still shows one row; a row whose chat the roster does not hold is not drawn. - Choosing a whole-text row opens the chat at that turn: `openSession(id, { turn })` navigates as before and then `seekTurn` finds the flow item `[data-chat-turn=N]` in the DOM — the same seek surface the message pills use, because DSH's `uiWorkspace` opens a session by id only — retrying briefly for the conversation to paint, and an unindexed turn (host `-1`) or one the host has not loaded lands on the nearest view, with the row's snippet still showing the words. -- Covered by `core/test/palette-preview.test.js`, whose live-react harness (a `useState` that rerenders and a `useEffect` that runs with its cleanup) drives the same bundle the static cases load: a hit 300 characters past the preview budget, the click that names the turn, and the no-duplicate rule. A Messages row now passes its own turn (`openSession(id, { turn })`), so an outline hit lands on its message. Two hits in one turn are two rows: the second and later key as `chat:turn:n`, the first keeps `chat:turn`. A hit the current part's outline does not hold is marked `Earlier part` and opens the chat with no turn, because that seek could not land; a chat whose outline has not loaded proves nothing and behaves as before (the test is a negation: the client can only say the turn is not in this part, never which part holds it). When the host caps the answer (`OWN_CHAT_SEARCH = 20`), the group ends with `{count} more matches · add a word to narrow it` (`.bt-palette-note`), drawn under its rows and outside the keyboard walk. +- Covered by `core/test/palette-preview.test.js`, whose live-react harness (a `useState` that rerenders and a `useEffect` that runs with its cleanup) drives the same bundle the static cases load: a hit 300 characters past the preview budget, the click that names the turn, and the no-duplicate rule. A Messages row now passes its own turn (`openSession(id, { turn })`), so an outline hit lands on its message. Two hits in one turn are two rows: the second and later key as `chat:turn:n`, the first keeps `chat:turn`. A hit the current part's outline does not hold is marked `Earlier part`: `openSession(id, { turn, part })` hands the row's part to `openTarget` (`text.js`), which opens the current part with a seek when the row names none, the named part with a seek when the chat owns it and the shell's `sessions.byId` holds it, and otherwise the current part with **no seek** (#3114); a row that names no part — a room's, or an older host's — opens the chat with no turn, because that seek could not land; a chat whose outline has not loaded proves nothing and behaves as before (for a row with no part the client can only say the turn is not in this part, never which part holds it). When the host caps the answer (`OWN_CHAT_SEARCH = 20`), the group ends with `{count} more matches · add a word to narrow it` (`.bt-palette-note`), drawn under its rows and outside the keyboard walk. ### Silent creation (#645) diff --git a/docs/subsystems/core-host.md b/docs/subsystems/core-host.md index 75bffca6e..f4f00c9f8 100644 --- a/docs/subsystems/core-host.md +++ b/docs/subsystems/core-host.md @@ -466,7 +466,7 @@ has lines (#2790, `core/test/room-read-floor-clamp.test.js`). - The client's command palette searched each chat's `turnOutline` projection, whose prompt and response previews stop at 50/120 characters, so a hit past that budget — most of any long reply — found nothing. The index this file already keeps holds the whole text, so the search became a host read: `chat-index.js` lifts the term/any-term core of `searchOwnChat` into `matchedRows` (both reads share it; `searchOwnChat` answers byte for byte as before) and adds `rt.searchHomeChat(sessionIds, query, { limit })` — raw rows (`text, session, seq, time, who, turn`), best first, over the sessions the caller names. Each named session is caught up bare first, exactly as a Bot's parts are; no `endedAt` is known there, so nothing seals. Without an index there are no rows and the palette keeps its outline search. - Every indexed line carries the turn it belongs to by number: `lines.turn` (and `marks.turnNo`, what the next catch-up resumes from), tracked from the number a `turn/start` event carries, `INDEX_VERSION` 4 → 5 — a bump rides the same drop-and-rebuild path as #2711's. A line written before any turn, or after a `turn/start` that carried no number, keeps `-1`, which the client reads as no turn to jump to. -- The channel endpoint is `chats.search` (`{ query }` → `{ rows: [{ chat, turn, text }], more }`, `text` an `excerpt` around the first term the row holds): the sessions are taken from `view(actor)` — the same narrowing the `state` answer carries — but each Bot's parts map to their chat id only while `sessionOwnedBy` passes, and every member/owned room's parts map unconditionally. The view keeps an other-owner Bot so a shared room renders, and that Bot's own chat is not room content, so the ownership test is what stops a signed-in member from reading another member's Bot chats here, while a room's own parts stay searchable because the room is shared. `authorize` and this channel handler are installed as a pair (`authz.js` defines `rt.authorize`; `channel.js:326` calls it before its switch), and mounting the handler alone is fail-open — `channel.js:370` then skips every ownership test — so the two are never reused separately; a host whose `authzEnforced()` answers `false` is a supported single-user install, not a missing pair. `authz.js` allows the endpoint for any signed-in actor the way `schedules` is allowed (the handler scopes), and the channel's `READS` whitelist carries it, so a second read-only window answers it too. +- The channel endpoint is `chats.search` (`{ query }` → `{ rows: [{ chat, turn, text, part? }], more }`, `text` an `excerpt` around the first term the row holds, `part` the Session id of the part the hit was said in — set only for a Bot's own chat, and absent from a room's row, because a room's member part is not a chat the palette may open (#3114)): the sessions are taken from `view(actor)` — the same narrowing the `state` answer carries — but each Bot's parts map to their chat id only while `sessionOwnedBy` passes, and every member/owned room's parts map unconditionally. The view keeps an other-owner Bot so a shared room renders, and that Bot's own chat is not room content, so the ownership test is what stops a signed-in member from reading another member's Bot chats here, while a room's own parts stay searchable because the room is shared. `authorize` and this channel handler are installed as a pair (`authz.js` defines `rt.authorize`; `channel.js:326` calls it before its switch), and mounting the handler alone is fail-open — `channel.js:370` then skips every ownership test — so the two are never reused separately; a host whose `authzEnforced()` answers `false` is a supported single-user install, not a missing pair. `authz.js` allows the endpoint for any signed-in actor the way `schedules` is allowed (the handler scopes), and the channel's `READS` whitelist carries it, so a second read-only window answers it too. - Covered by `core/test/chat-index-writers.test.js` (a line whose match sits 300 characters past the preview budget, with its turn; the endpoint scoped to the signed-in member through the real `/api/bot` route; and a shared room where the other member's Bot own chat stays unreadable while the room's own Session is found, with `earlier` and `sessionOwnedBy` still refusing it) and `core/test/authz.test.js` (allowed for a signed-in actor, refused without one). ### Out-of-app delivery, first half (#355) diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 105181000..c3165c6fd 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -3376,7 +3376,7 @@ diff --git a/src/client/text.js b/src/client/text.js function clock(ms) { return new Date(ms).toLocaleTimeString(dateLocale(), { hour: 'numeric', minute: '2-digit' }) } -@@ -48,6 +48,34 @@ export function relativeShort(ms) { +@@ -48,6 +48,46 @@ export function relativeShort(ms) { export const contentText = content => (content ?? []).filter(block => block?.type === 'text').map(block => block.text).join('\n') export const HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/ export const currentPart = bot => bot.sessionId ?? bot.id @@ -3407,6 +3407,18 @@ diff --git a/src/client/text.js b/src/client/text.js + // With the list in hand only a destination that list knows is returned: a fresh part it has not + // caught up with falls back to the chat it replaced, and nothing known at all is `undefined`. + return destinations.find(id => sessions.byId?.[id] !== undefined) ++} ++// #3114: where a search row lands. A row that names its part is placed by that part: the part ++// opens when the chat owns it and the shell's session list holds it. A part that fails either ++// test is not opened — the chat's current part opens with no seek, because the same turn ++// number there is a different message. ++export function openTarget(roster, sessions, id, part) { ++ const bot = roster.byId?.[id] ++ if (bot === undefined) return { target: id, seek: true } ++ const current = currentPart(bot) ++ if (part === undefined || part === current) return { target: current, seek: true } ++ const owned = part === bot.sessionId || (bot.parts ?? []).includes(part) ++ return owned && sessions?.byId?.[part] !== undefined ? { target: part, seek: true } : { target: current, seek: false } +} // The prompts in a due scheduled task's message. DSH frames it for the model: one // task as `reminder_prompt_json: "…"`, several as `reminders_json: [{reminder_prompt}]`. diff --git a/patches/ds-bot/0003-flybot-api-client.patch b/patches/ds-bot/0003-flybot-api-client.patch index 7815452f3..e8e253b93 100644 --- a/patches/ds-bot/0003-flybot-api-client.patch +++ b/patches/ds-bot/0003-flybot-api-client.patch @@ -1731,7 +1731,7 @@ diff --git a/src/client/index.js b/src/client/index.js +import { countCards, createSource, EMPTY_ROSTER, indexRoster, isAgentSession, stateAnswerIsStale, stateRequest } from './sources.js' import { themeCss, shellTokens, registry, registerShape, registerTheme, allThemes } from './themes.js' -import { MENTION_ORIGIN, currentPart } from './text.js' -+import { currentPart, landingPart, setPluginTools } from './text.js' ++import { currentPart, landingPart, openTarget, setPluginTools } from './text.js' +import { mentionCss } from './mention-style.js' import { SHELL_CSS, CONVERSATION_CSS, installStyles, installCompiledStyles } from './styles.js' -import { lookOf } from './mark.js' @@ -1964,14 +1964,15 @@ diff --git a/src/client/index.js b/src/client/index.js // A Bot id, or any part of its chat, opens the Bot's current part. const partFor = (id) => { const bot = roster.getSnapshot().byId[id] -@@ -337,11 +337,27 @@ export function apply(ctx) { +@@ -337,23 +337,44 @@ export function apply(ctx) { for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id) return ids } -+ // The palette's whole-text rows name the turn the hit belongs to (P-820). DSH opens a ++ // The palette's whole-text rows name the turn the hit belongs to and its part (#3114). DSH opens a + // session by id only, so the turn is found where the message pills already look: the + // flow's own DOM. A turn the host has not loaded lands on the nearest view — the row's + // snippet still shows the words — and the seek gives up rather than spin. ++ // A part that could not be opened gives the seek up too: the same turn number is another line. + const seekTurn = (turn) => { + if (!Number.isInteger(turn) || turn < 0 || typeof document === 'undefined') return + let tries = 0 @@ -1988,16 +1989,17 @@ diff --git a/src/client/index.js b/src/client/index.js // or the click appears to do nothing. isAgentSession: id => isAgentSessionId(id), - openSession: (id) => { -+ openSession: (id, { turn } = {}) => { ++ openSession: (id, { turn, part } = {}) => { + noteNavigation('openSession', id) // A DSH Agent Session id lands on the plain surface, not the Bot skin. if (isAgentSessionId(id)) return actions.openAgentSession(id) ui.set(state => (state.newChat || state.exchange || state.menu || state.palette ? { ...state, newChat: null, exchange: null, menu: null, palette: null } : state)) -@@ -349,11 +349,15 @@ export function apply(ctx) { - const target = partFor(id) + setPlain(false) +- const target = partFor(id) ++ const { target, seek } = openTarget(roster.getSnapshot(), ctx.sessions.list.getSnapshot(), id, part) expected = target ctx.uiWorkspace.openSession(target) -+ seekTurn(turn) ++ if (seek) seekTurn(turn) }, + // The palette's whole-text message search (P-820): the host answers with the + // caller's own chats, whole lines with the turn they belong to. @@ -2877,7 +2879,7 @@ diff --git a/src/client/palette.js b/src/client/palette.js badge: room.hidden ? t('Hidden') : undefined, run: async () => { if (room.hidden) await actions.setFlags(room.id, { hidden: false }); actions.openSession(room.id) }, })), -@@ -67,21 +67,50 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { +@@ -67,21 +67,56 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { run: () => actions.openAgent(agent.id), })) if (agents.length) sections.push(['DSH Agent', agents]) @@ -2909,15 +2911,21 @@ diff --git a/src/client/palette.js b/src/client/palette.js + const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => { + const bot = roster.byId[row.chat] + const room = roster.roomsById[row.chat] -+ const here = inPart(row.chat, row.turn) ++ // A row that names its part is placed by that part (#3114); a row without one keeps the ++ // outline's answer, the only proof the client has about what the part it holds contains. ++ const earlier = typeof row.part === 'string' ? bot !== undefined && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false + const at = `${row.chat}:${row.turn}` + const count = (keyCounts.get(at) ?? 0) + 1 + keyCounts.set(at, count) + return { + key: count > 1 ? `${at}:${count}` : at, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text, + avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }), -+ badge: here === false ? t('Earlier part') : undefined, -+ run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }), ++ badge: earlier ? t('Earlier part') : undefined, ++ // A row lands where it points: another part opens that part at its turn, so the words are ++ // on screen; the current part keeps its seek; a row with no part keeps today's navigation. ++ run: earlier && row.part !== undefined ++ ? () => actions.openSession(row.chat, { part: row.part, turn: row.turn }) ++ : earlier ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }), + } + }) + const hidden = wholeText?.more ?? 0 diff --git a/patches/ds-bot/0005-social-seams.patch b/patches/ds-bot/0005-social-seams.patch index 628867d8d..6c500bb11 100644 --- a/patches/ds-bot/0005-social-seams.patch +++ b/patches/ds-bot/0005-social-seams.patch @@ -641,7 +641,7 @@ diff --git a/src/host/channel.js b/src/host/channel.js case 'duplicate-bot': await rt.load() return ok(await rt.duplicateBot(body.id)) -@@ -134,14 +134,43 @@ export function install(rt) { +@@ -134,14 +134,48 @@ export function install(rt) { case 'earlier': await rt.load() return ok(await rt.earlierPage(String(body.sessionId ?? ''), body.cursor ?? undefined)) @@ -649,14 +649,16 @@ diff --git a/src/host/channel.js b/src/host/channel.js + // The palette's whole-text rows (P-820). `view(actor)` is the narrowing `state` uses: + // it keeps the actor's own Bots, and also the other-owner Bots a shared room carries so + // the room renders. Those Bots' own chats are not room content, so only the sessions -+ // the actor owns are searched; a room's own parts stay, because the room is shared. ++ // the actor owns are searched; a room's own parts stay, because the room is shared. Only a Bot's own chat part is named `part` (#3114). + await rt.load() + const query = String(body.query ?? '') + const scoped = view(actor) + const sessionToChat = new Map() ++ const ownParts = new Set() + for (const bot of scoped.bots) for (const part of [bot.sessionId, ...(bot.parts ?? [])]) { + if (rt.authzEnforced?.() && !rt.sessionOwnedBy?.(actor, part)) continue + sessionToChat.set(part, bot.id) ++ ownParts.add(part) + } + for (const room of scoped.rooms) for (const part of room.parts ?? []) if (!sessionToChat.has(part)) sessionToChat.set(part, room.id) + const { rows, more } = await rt.searchHomeChat([...sessionToChat.keys()], query) @@ -666,7 +668,10 @@ diff --git a/src/host/channel.js b/src/host/channel.js + .map(row => { + const lower = row.text.toLowerCase() + const wanted = terms.find(term => lower.includes(term)) ?? '' -+ return { chat: sessionToChat.get(row.session) ?? null, turn: row.turn, text: excerpt(row.text, wanted) } ++ return { ++ chat: sessionToChat.get(row.session) ?? null, turn: row.turn, text: excerpt(row.text, wanted), ++ ...(ownParts.has(row.session) ? { part: row.session } : {}), ++ } + }) + .filter(row => row.chat !== null), + more, diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 6deb5284f..72d484c62 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -1997,7 +1997,7 @@ diff --git a/client.js b/client.js function clock(ms) { return new Date(ms).toLocaleTimeString(dateLocale(), { hour: "numeric", minute: "2-digit" }); } -@@ -1483,9 +1483,22 @@ function relativeShort(ms) { +@@ -1483,9 +1483,30 @@ function relativeShort(ms) { var contentText = (content) => (content ?? []).filter((block) => block?.type === "text").map((block) => block.text).join("\n"); var HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/; var currentPart = (bot) => bot.sessionId ?? bot.id; @@ -2017,6 +2017,14 @@ diff --git a/client.js b/client.js + if (sessions === void 0) return destinations[0]; + return destinations.find((id) => sessions.byId?.[id] !== void 0); +} ++function openTarget(roster, sessions, id, part) { ++ const bot = roster.byId?.[id]; ++ if (bot === void 0) return { target: id, seek: true }; ++ const current = currentPart(bot); ++ if (part === void 0 || part === current) return { target: current, seek: true }; ++ const owned = part === bot.sessionId || (bot.parts ?? []).includes(part); ++ return owned && sessions?.byId?.[part] !== void 0 ? { target: part, seek: true } : { target: current, seek: false }; ++} +function reminderPrompts(text2) { + const one = /^reminder_prompt_json: (.*)$/m.exec(text2); + const batch = /^reminders_json: (.*)$/m.exec(text2); @@ -20289,7 +20297,7 @@ diff --git a/client.js b/client.js } }; window.addEventListener("mousedown", onDown); -@@ -7646,514 +7646,1048 @@ function MemoryDialog({ bot, actions, leaving = false }) { +@@ -7646,514 +7646,1050 @@ function MemoryDialog({ bot, actions, leaving = false }) { window.removeEventListener("mousedown", onDown); window.removeEventListener("keydown", onKey, true); }; @@ -21542,7 +21550,7 @@ diff --git a/client.js b/client.js + const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => { + const bot = roster.byId[row.chat]; + const room2 = roster.roomsById[row.chat]; -+ const here = inPart(row.chat, row.turn); ++ const earlier = typeof row.part === "string" ? bot !== void 0 && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false; + const at = `${row.chat}:${row.turn}`; + const count = (keyCounts.get(at) ?? 0) + 1; + keyCounts.set(at, count); @@ -21551,8 +21559,10 @@ diff --git a/client.js b/client.js + title: bot?.name ?? room2?.name ?? t("Bot"), + subtitle: row.text, + avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }), -+ badge: here === false ? t("Earlier part") : void 0, -+ run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }) ++ badge: earlier ? t("Earlier part") : void 0, ++ // A row lands where it points: another part opens that part at its turn, so the words are ++ // on screen; the current part keeps its seek; a row with no part keeps today's navigation. ++ run: earlier && row.part !== void 0 ? () => actions.openSession(row.chat, { part: row.part, turn: row.turn }) : earlier ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }) + }; + }); + const hidden = wholeText?.more ?? 0; @@ -28535,15 +28545,16 @@ diff --git a/client.js b/client.js // or the click appears to do nothing. isAgentSession: (id) => isAgentSessionId(id), - openSession: (id) => { -+ openSession: (id, { turn } = {}) => { ++ openSession: (id, { turn, part } = {}) => { + noteNavigation("openSession", id); if (isAgentSessionId(id)) return actions.openAgentSession(id); 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); +- const target = partFor(id); ++ const { target, seek } = openTarget(roster.getSnapshot(), ctx.sessions.list.getSnapshot(), id, part); expected = target; ctx.uiWorkspace.openSession(target); -+ seekTurn(turn); ++ if (seek) seekTurn(turn); }, + // The palette's whole-text message search (P-820): the host answers with the + // caller's own chats, whole lines with the turn they belong to. diff --git a/patches/ds-bot/files/test/chat-index-writers.test.js b/patches/ds-bot/files/test/chat-index-writers.test.js index 1e29d5453..00e2e5325 100644 --- a/patches/ds-bot/files/test/chat-index-writers.test.js +++ b/patches/ds-bot/files/test/chat-index-writers.test.js @@ -367,6 +367,30 @@ test('chats.search answers through the channel with only the caller\'s chats (P- } }) +// #3114. A row already names the turn the hit belongs to; it now names the part too, so the +// client can open that part instead of only marking the hit as earlier. The part is the part's +// own Session id — the same `session` the index rows carry — and it is only for a Bot's own +// chat: a room's row is not a part the palette may open, so it carries none. +test('#3114: a chats.search row names the part the hit was said in', async (t) => { + const home = scratch(t, 'ds-bot-index-part-') + HISTORY.older = [turnStart(0, 4), line(1, 'a plain line'), turnStart(2, 5), line(3, NEEDLE_LINE)] + try { + const seeded = seed() + seeded.bots.a.segments = [{ sessionId: 'older', endedAt: T0 + 9000 }] + const host = await start(t, home, { saved: seeded }) + assert.notEqual(host.route, undefined, 'the channel registered its /api/bot route') + const response = await host.route.fetch(new Request('http://localhost/api/bot', { + method: 'POST', + body: JSON.stringify({ endpoint: 'chats.search', payload: { query: 'needle' } }), + })) + const result = await response.json() + assert.equal(result.ok, true, JSON.stringify(result)) + assert.deepEqual(result.value.rows.map(row => [row.chat, row.part, row.turn]), [['a', 'older', 5]], JSON.stringify(result.value)) + } finally { + delete HISTORY.older + } +}) + // The same view, the security case: a shared room renders because it keeps the other member's // Bot in `bots`, and that Bot's own chat is not room content. owner-1 sits in `r1` with // owner-2's Bot `b`; `duo` is b's own chat. Searching it as owner-1 must answer nothing, while @@ -398,6 +422,7 @@ test('chats.search never reads another member\'s Bot own chat through a shared r assert.equal(shared.ok, true, JSON.stringify(shared)) assert.deepEqual(shared.value.rows.map(row => row.chat), ['r1'], JSON.stringify(shared.value)) assert.match(shared.value.rows[0].text, /hello from the room/) + assert.equal('part' in shared.value.rows[0], false, 'a room row names no part: the member part is not a chat to open') // What the fix restores: the refused read the state view already refused, at both layers. const refused = await host.route.fetch(new Request('http://localhost/api/bot', { diff --git a/patches/ds-bot/files/test/land-on.test.js b/patches/ds-bot/files/test/land-on.test.js index 8008da7da..444b54466 100644 --- a/patches/ds-bot/files/test/land-on.test.js +++ b/patches/ds-bot/files/test/land-on.test.js @@ -88,3 +88,20 @@ test('#1306: a destination the session list does not know is never handed to the assert.equal(landingPart({ byId: { friend: fresh, chief } }, last, 'chief', { stay: true, sessions: gone }), 'chief-2', 'a fresh part the list has not caught up with, the chat it replaced gone: the Main Bot') assert.equal(landingPart({ byId: { friend: fresh, chief } }, last, 'chief', { stay: true, sessions }), 'friend-1', 'the fresh part is unknown, the chat it replaced is known: stay on that chat') }) + +// #3114: a message row names the part it was said in. That part opens only when the chat owns +// it and the shell's session list holds it; a part that fails either test is not opened at all, +// and the row falls back to the chat's current part with no seek — the same turn number there +// is a different message. An id the roster does not hold keeps the id fallback it always had. +// The fix exports this, so it is resolved here: a missing export fails this case alone. +test('#3114: a named part is opened only when the chat owns it and the shell lists it', async () => { + const { openTarget } = await import('../src/client/text.js') + const bot = { id: 'friend', sessionId: 'friend-2', parts: ['friend-1'] } + const at = (id, part, known = sessions) => openTarget({ byId: { ...roster.byId, friend: bot } }, known, id, part) + assert.deepEqual(at('friend', 'friend-1'), { target: 'friend-1', seek: true }, 'a part the chat owns and the list holds') + assert.deepEqual(at('friend', 'friend-2'), { target: 'friend-2', seek: true }, 'the part that is already open') + assert.deepEqual(at('friend'), { target: 'friend-2', seek: true }, 'no part: the current part, as before') + assert.deepEqual(at('friend', 'chief-2'), { target: 'friend-2', seek: false }, 'a part another chat owns: no seek') + assert.deepEqual(at('friend', 'friend-1', { byId: {} }), { target: 'friend-2', seek: false }, 'a part the shell does not list: no seek') + assert.deepEqual(at('gone', 'friend-1'), { target: 'gone', seek: true }, 'an id the roster does not hold') +}) diff --git a/patches/ds-bot/files/test/palette-preview.test.js b/patches/ds-bot/files/test/palette-preview.test.js index 677c0e5ca..7757487b6 100644 --- a/patches/ds-bot/files/test/palette-preview.test.js +++ b/patches/ds-bot/files/test/palette-preview.test.js @@ -382,3 +382,30 @@ test('#3114: a query shorter than two characters asks nothing and renders no row assert.deepEqual(palette.calls.search, []) assert.deepEqual(palette.rows().filter(key => !key.startsWith('cmd:')), []) }) + +// A row that names its part is placed by that part (#3114): a hit the host puts in an earlier +// part opens that part and still seeks its turn there. The outline holds no turn of that part, +// so the row's own part is the only thing that can say where the words were said — and the row +// still says `Earlier part`, because the part it names is not the one the view holds. +test('#3114: a hit the host places in an earlier part opens that part at its turn', async () => { + const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, part: 's1-old', text: 'NEEDLE far past this part' }] }) + await palette.settle() + assert.deepEqual(palette.badges(), ['Earlier part']) + palette.choose('s1:12') + assert.equal(palette.calls.openSession.length, 1) + assert.equal(palette.calls.openSession[0][0], 's1') + assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') + assert.equal(palette.calls.openSession[0][1]?.turn, 12) +}) + +// The part that is already open is no earlier part: the row keeps its seek and names no part, +// so the navigation is the one it always was, and a hit the host says is here is not marked. +// The part is named, so this one case pins that naming it does not change the answer. +test('#3114: a hit in the current part keeps its own seek', async () => { + const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 1, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 1, part: 's1', text: 'NEEDLE inside this part' }] }) + await palette.settle() + assert.deepEqual(palette.badges(), []) + palette.choose('s1:1') + assert.equal(palette.calls.openSession[0][1]?.turn, 1) + assert.equal(palette.calls.openSession[0][1]?.part, undefined, 'the current part is not named as another part') +}) From 6a3562bf4d733cda1c599555295aa8c4409a1223 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Thu, 19 Nov 2026 08:15:59 +0800 Subject: [PATCH 2/2] Complete the part-aware search landing (#3114) The review at 4bcf0611 found two gaps. The core-client page still described a whole-text row as openSession(id, { turn }) and named no openTarget branch, though a row whose part is another chat's part opens the current part and does not seek. And openTarget tested only undefined for "no part", so a part that is not a string fell through to the no-seek fallback instead of the contract's current-part seek. Document the row's { turn, part } and the openTarget branches, guard on typeof part !== 'string' first, and pin the guard with a #3114 case; the client bundle and the patch mirrors are regenerated. --- core/client.js | 2 +- core/src/client/text.js | 4 +++- core/test/land-on.test.js | 10 ++++++++++ docs/subsystems/core-client.md | 2 +- patches/ds-bot/0001-core-fixes.patch | 6 ++++-- patches/ds-bot/0008-client-bundle.patch | 2 +- patches/ds-bot/files/test/land-on.test.js | 10 ++++++++++ 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/core/client.js b/core/client.js index 4c518dd1e..6f8d93a05 100644 --- a/core/client.js +++ b/core/client.js @@ -2102,7 +2102,7 @@ function openTarget(roster, sessions, id, part) { const bot = roster.byId?.[id]; if (bot === void 0) return { target: id, seek: true }; const current = currentPart(bot); - if (part === void 0 || part === current) return { target: current, seek: true }; + if (typeof part !== "string" || part === current) return { target: current, seek: true }; const owned = part === bot.sessionId || (bot.parts ?? []).includes(part); return owned && sessions?.byId?.[part] !== void 0 ? { target: part, seek: true } : { target: current, seek: false }; } diff --git a/core/src/client/text.js b/core/src/client/text.js index a155eb9e8..bf276cc6f 100644 --- a/core/src/client/text.js +++ b/core/src/client/text.js @@ -109,7 +109,9 @@ export function openTarget(roster, sessions, id, part) { const bot = roster.byId?.[id] if (bot === undefined) return { target: id, seek: true } const current = currentPart(bot) - if (part === undefined || part === current) return { target: current, seek: true } + // A part is a Session id string or nothing at all: a row that names nothing, or names something + // that is not a string (a number from an older host), asks for the current part and its turn. + if (typeof part !== 'string' || part === current) return { target: current, seek: true } const owned = part === bot.sessionId || (bot.parts ?? []).includes(part) return owned && sessions?.byId?.[part] !== undefined ? { target: part, seek: true } : { target: current, seek: false } } diff --git a/core/test/land-on.test.js b/core/test/land-on.test.js index 444b54466..32ba50c89 100644 --- a/core/test/land-on.test.js +++ b/core/test/land-on.test.js @@ -105,3 +105,13 @@ test('#3114: a named part is opened only when the chat owns it and the shell lis assert.deepEqual(at('friend', 'friend-1', { byId: {} }), { target: 'friend-2', seek: false }, 'a part the shell does not list: no seek') assert.deepEqual(at('gone', 'friend-1'), { target: 'gone', seek: true }, 'an id the roster does not hold') }) + +// #3114: a part is a Session id string or nothing at all. A row that names something else — a +// number, from an older host or a hand-built row — is not a part this chat could open, so it takes +// the road of a row that names no part: the current part, and a seek there, never the no-seek +// fallback a part this chat cannot reach gets. +test('#3114: a part that is not a string opens the current part and keeps the seek', async () => { + const { openTarget } = await import('../src/client/text.js') + const withParts = { id: 'friend', sessionId: 'friend-2', parts: ['friend-1'] } + assert.deepEqual(openTarget({ byId: { ...roster.byId, friend: withParts } }, sessions, 'friend', 5), { target: 'friend-2', seek: true }) +}) diff --git a/docs/subsystems/core-client.md b/docs/subsystems/core-client.md index d991f6b35..2f051b189 100644 --- a/docs/subsystems/core-client.md +++ b/docs/subsystems/core-client.md @@ -258,7 +258,7 @@ The member's own chat keeps its `busyAcks[sessionId]` bubble and its visibility ### Command palette message search (P-820) - The palette's Messages group read each chat's `turnOutline` projection, whose prompt and response previews stop at 50/120 characters, so any hit past that budget found nothing — most of a long reply. The Messages group keeps its outline read; beside it, **Messages (full text)** (`palette.js`) asks the host through `actions.searchChats` (`call('chats.search')` in `index.js`, scoped to the caller's own chats — the host half is in [core-host](core-host.md)), debounced 150 ms, with an `AbortController` and a generation guard so an answer for a query the user already changed is dropped with the effect that asked. Rows a chat/turn pair the outline already found are the same message and are not shown twice; a part's own Session id and the Bot id a host row names are first folded to the one chat (`chatOf`), so a Bot whose current part is a Session of its own still shows one row; a row whose chat the roster does not hold is not drawn. -- Choosing a whole-text row opens the chat at that turn: `openSession(id, { turn })` navigates as before and then `seekTurn` finds the flow item `[data-chat-turn=N]` in the DOM — the same seek surface the message pills use, because DSH's `uiWorkspace` opens a session by id only — retrying briefly for the conversation to paint, and an unindexed turn (host `-1`) or one the host has not loaded lands on the nearest view, with the row's snippet still showing the words. +- Choosing a whole-text row opens the chat at that turn, in the part the row was said in: `openSession(id, { turn, part })` navigates as before and then `seekTurn` finds the flow item `[data-chat-turn=N]` in the DOM — the same seek surface the message pills use, because DSH's `uiWorkspace` opens a session by id only — retrying briefly for the conversation to paint, and an unindexed turn (host `-1`) or one the host has not loaded lands on the nearest view, with the row's snippet still showing the words. Which session it lands on is `openTarget` (`text.js`): an id the roster does not hold keeps its plain id and seeks; a row with no part, or with a part that is not a string, opens the chat's current part and seeks there; a part the chat owns and the shell's `sessions.byId` lists opens that part and seeks; any other part, another chat's or one the shell does not list, opens the current part with **no seek**, because the same turn number there is a different message; and a row with no part whose turn the current part's outline does not hold is still marked `Earlier part` and opens with no turn, since there is nothing to seek. - Covered by `core/test/palette-preview.test.js`, whose live-react harness (a `useState` that rerenders and a `useEffect` that runs with its cleanup) drives the same bundle the static cases load: a hit 300 characters past the preview budget, the click that names the turn, and the no-duplicate rule. A Messages row now passes its own turn (`openSession(id, { turn })`), so an outline hit lands on its message. Two hits in one turn are two rows: the second and later key as `chat:turn:n`, the first keeps `chat:turn`. A hit the current part's outline does not hold is marked `Earlier part`: `openSession(id, { turn, part })` hands the row's part to `openTarget` (`text.js`), which opens the current part with a seek when the row names none, the named part with a seek when the chat owns it and the shell's `sessions.byId` holds it, and otherwise the current part with **no seek** (#3114); a row that names no part — a room's, or an older host's — opens the chat with no turn, because that seek could not land; a chat whose outline has not loaded proves nothing and behaves as before (for a row with no part the client can only say the turn is not in this part, never which part holds it). When the host caps the answer (`OWN_CHAT_SEARCH = 20`), the group ends with `{count} more matches · add a word to narrow it` (`.bt-palette-note`), drawn under its rows and outside the keyboard walk. ### Silent creation (#645) diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index c3165c6fd..3bd827b2d 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -3376,7 +3376,7 @@ diff --git a/src/client/text.js b/src/client/text.js function clock(ms) { return new Date(ms).toLocaleTimeString(dateLocale(), { hour: 'numeric', minute: '2-digit' }) } -@@ -48,6 +48,46 @@ export function relativeShort(ms) { +@@ -48,6 +48,48 @@ export function relativeShort(ms) { export const contentText = content => (content ?? []).filter(block => block?.type === 'text').map(block => block.text).join('\n') export const HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/ export const currentPart = bot => bot.sessionId ?? bot.id @@ -3416,7 +3416,9 @@ diff --git a/src/client/text.js b/src/client/text.js + const bot = roster.byId?.[id] + if (bot === undefined) return { target: id, seek: true } + const current = currentPart(bot) -+ if (part === undefined || part === current) return { target: current, seek: true } ++ // A part is a Session id string or nothing at all: a row that names nothing, or names something ++ // that is not a string (a number from an older host), asks for the current part and its turn. ++ if (typeof part !== 'string' || part === current) return { target: current, seek: true } + const owned = part === bot.sessionId || (bot.parts ?? []).includes(part) + return owned && sessions?.byId?.[part] !== undefined ? { target: part, seek: true } : { target: current, seek: false } +} diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 72d484c62..47b04ea0d 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -2021,7 +2021,7 @@ diff --git a/client.js b/client.js + const bot = roster.byId?.[id]; + if (bot === void 0) return { target: id, seek: true }; + const current = currentPart(bot); -+ if (part === void 0 || part === current) return { target: current, seek: true }; ++ if (typeof part !== "string" || part === current) return { target: current, seek: true }; + const owned = part === bot.sessionId || (bot.parts ?? []).includes(part); + return owned && sessions?.byId?.[part] !== void 0 ? { target: part, seek: true } : { target: current, seek: false }; +} diff --git a/patches/ds-bot/files/test/land-on.test.js b/patches/ds-bot/files/test/land-on.test.js index 444b54466..32ba50c89 100644 --- a/patches/ds-bot/files/test/land-on.test.js +++ b/patches/ds-bot/files/test/land-on.test.js @@ -105,3 +105,13 @@ test('#3114: a named part is opened only when the chat owns it and the shell lis assert.deepEqual(at('friend', 'friend-1', { byId: {} }), { target: 'friend-2', seek: false }, 'a part the shell does not list: no seek') assert.deepEqual(at('gone', 'friend-1'), { target: 'gone', seek: true }, 'an id the roster does not hold') }) + +// #3114: a part is a Session id string or nothing at all. A row that names something else — a +// number, from an older host or a hand-built row — is not a part this chat could open, so it takes +// the road of a row that names no part: the current part, and a seek there, never the no-seek +// fallback a part this chat cannot reach gets. +test('#3114: a part that is not a string opens the current part and keeps the seek', async () => { + const { openTarget } = await import('../src/client/text.js') + const withParts = { id: 'friend', sessionId: 'friend-2', parts: ['friend-1'] } + assert.deepEqual(openTarget({ byId: { ...roster.byId, friend: withParts } }, sessions, 'friend', 5), { target: 'friend-2', seek: true }) +})