Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3114-history-hit-part.added.md
Original file line number Diff line number Diff line change
@@ -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)).
22 changes: 16 additions & 6 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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 };
}
function reminderPrompts(text2) {
const one = /^reminder_prompt_json: (.*)$/m.exec(text2);
const batch = /^reminders_json: (.*)$/m.exec(text2);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions core/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions core/src/client/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions core/src/client/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ 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)
// 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 }
}
// 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) {
Expand Down
9 changes: 7 additions & 2 deletions core/src/host/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions core/test/chat-index-writers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', {
Expand Down
27 changes: 27 additions & 0 deletions core/test/land-on.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,30 @@ 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')
})

// #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 })
})
27 changes: 27 additions & 0 deletions core/test/palette-preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Loading
Loading