Skip to content

The agent that grows with you

fix(desktop): only merge an older history page that actually touches the window

teknium1edff95806043
diff --git a/apps/desktop/src/app/chat/history-window.test.tsx b/apps/desktop/src/app/chat/history-window.test.tsx
index bdf4c29c344..7ef349d23e3 100644
--- a/apps/desktop/src/app/chat/history-window.test.tsx
+++ b/apps/desktop/src/app/chat/history-window.test.tsx
@@ -31,12 +31,12 @@ beforeEach(() => {
Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { api: vi.fn() } })
})
-function mount() {
+function mount(storedId = 'stored') {
const $messages = atom(Array.from({ length: 120 }, (_, index) => message(10_000 + index)))
const view = {
...PRIMARY_SESSION_VIEW, $messages,
- $runtimeId: atom<string | null>('runtime'), $storedId: atom<string | null>('stored')
+ $runtimeId: atom<string | null>('runtime'), $storedId: atom<string | null>(storedId)
}
let window!: Required<TranscriptWindowValue>
@@ -210,6 +210,27 @@ describe('paging earlier from an open history window', () => {
])
})
+ it('shows the older page on its own when a turn longer than the page limit separates it from the anchor', async () => {
+ vi.spyOn(window.hermesDesktop, 'api')
+ // 300 display rows precede the anchor; the previous prompt's forward
+ // page (offset 40, 120 rows) ends 140 rows short of it.
+ .mockResolvedValueOnce({ ...page(4000), pagination: { ...page(4000).pagination, offset: 300 } })
+ .mockResolvedValueOnce(index([3700, 4000]))
+ .mockResolvedValueOnce(page(3700))
+ const mounted = mount('stored-gap')
+
+ await act(async () => { await mounted.window.revealRow(4000, new AbortController().signal) })
+ const beforePrepend = vi.fn()
+ let grew = false
+ await act(async () => { grew = (await mounted.window.expandWindow(beforePrepend)) === true })
+
+ expect(grew).toBe(true)
+ const rows = mounted.window.currentMessages?.map(message => message.rowId) ?? []
+ // Never one continuous transcript with a silent hole before 4000.
+ expect(rows).toEqual(Array.from({ length: 120 }, (_, index) => 3700 + index))
+ expect(beforePrepend).not.toHaveBeenCalled()
+ })
+
it('still retires the entry point when the open window starts at the session top', async () => {
const api = vi.spyOn(window.hermesDesktop, 'api').mockResolvedValue({
...page(1),
diff --git a/apps/desktop/src/app/chat/history-window.ts b/apps/desktop/src/app/chat/history-window.ts
index b13b4ba79bd..1007a4a3767 100644
--- a/apps/desktop/src/app/chat/history-window.ts
+++ b/apps/desktop/src/app/chat/history-window.ts
@@ -21,6 +21,8 @@ interface HistoryPage {
messages: ChatMessage[]
olderAvailable: boolean
newerAvailable: boolean
+ /** Display rows before this page's first row; how two pages prove they touch. */
+ offset: number
}
export async function fetchHistoryWindow(
@@ -54,7 +56,8 @@ export async function fetchHistoryWindow(
return {
messages: toChatMessages(response.messages),
olderAvailable: response.pagination.has_older === true,
- newerAvailable: response.pagination.has_newer === true
+ newerAvailable: response.pagination.has_newer === true,
+ offset: Math.max(0, Number(response.pagination.offset) || 0)
}
}
@@ -163,7 +166,12 @@ export function useHistoryWindow({ scopeKey, storedId, scope, isCurrent }: Histo
}
const next = await fetchHistoryWindow(captured.storedId, rowId, captured.scope, controller.signal)
- const messages = mergeOlderTranscriptPage(current.messages, next.messages)
+ // The around route reads forward from a prompt, so a turn longer than the
+ // page limit leaves rows between that page's end and this anchor. Never
+ // paint that as one continuous transcript: show the older page on its
+ // own instead, the way a rail jump to that mark would.
+ const contiguous = next.offset + next.messages.length >= current.offset
+ const messages = contiguous ? mergeOlderTranscriptPage(current.messages, next.messages) : next.messages
// A window replaced while this one was in flight owns the display page.
if (
@@ -175,10 +183,13 @@ export function useHistoryWindow({ scopeKey, storedId, scope, isCurrent }: Histo
return false
}
- beforePrepend?.()
+ if (contiguous) {
+ beforePrepend?.()
+ }
+
setSelection({
lifetime: captured.lifetime,
- page: { messages, olderAvailable: next.olderAvailable, newerAvailable: current.newerAvailable }
+ page: contiguous ? { ...next, messages, newerAvailable: current.newerAvailable } : next
})
return true
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 7d68072c48d..92d8a0fa0f4 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -53,7 +53,7 @@ The center of the app. You get:
- **Comment mode in the in-app browser** — click **Annotate** in the preview browser bar, then click any element (or drag a box) on the live page and type a note; each saved comment stays as a numbered pin on the page. Saving a pin never sends a turn — when you're done, **Add N comments** attaches a cropped screenshot per pin and a short prompt naming each comment to the composer, and you still hit send yourself. Each element comment carries its CSS selector, its markup, and the computed styles that matter for layout, so the agent can find the element in your source instead of guessing from the picture. Password and hidden field values, and any attribute that looks like a key or token, are redacted on the page before the markup leaves it. Larger batches arrive grouped by which part of the page each comment sits in, so twenty-odd comments become a handful of pieces of work rather than one task each — and because the groups are separate DOM subtrees they usually touch separate files, which is what makes handing them to parallel workers safe. Pin numbers hold steady if you delete one, and switching chats clears the stack.
- **Composer history and queue editing** — press the up/down arrow keys in an empty composer to recall and reuse previous prompts, and edit messages you've queued up before they're sent. Pressing Stop (or Esc) while turns are queued pauses the queue and expands it above the composer; resume it from there, or send, edit, and delete individual entries.
- **Task progress above the composer** — expand the Tasks header to inspect each phase. Long lists stay bounded above the input; scroll inside the expanded list to reach the final tasks without moving the conversation.
-- **A conversation timeline rail** — long chats get a slim rail of markers along the edge of the transcript, one per prompt. Hover it to pop open the list of prompts, click one to jump straight to that point in the conversation. (It appears once the chat has a handful of turns.)
+- **A conversation timeline rail** — long chats get a slim rail of markers along the edge of the transcript, one per prompt. Hover it to pop open the list of prompts, click one to jump straight to that point in the conversation. After a jump, **Show earlier** at the top of the transcript keeps paging backwards from that prompt all the way to the start of the session. (It appears once the chat has a handful of turns.)
- **Reading-position memory** — returning to a session restores its saved distance from the bottom instead of always jumping to the latest message. Sessions left at the bottom continue following new output. Use **Scroll to bottom** to return to the live edge. Positions are kept in this Desktop installation's local storage; they are not synchronized through the backend.
- **Find in page** — press **Cmd/Ctrl+F** to open a find bar that searches the rendered chat transcript. Enter / Shift+Enter (or Cmd/Ctrl+G / Cmd/Ctrl+Shift+G while the bar is open) step through matches; Esc closes it.