mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-18 09:51:59 +00:00
* fix(desktop): make composer message queue reliable The queue felt 'dumb' because of three real bugs: 1. Drained-after-interrupt sends went silent. cancelRun sets interrupted:true and nothing reset it; submitPromptText's optimistic seed preserved it, and the message stream drops every delta while interrupted. So Send-now-while-busy and any interrupt+drain submitted the next turn into a muted session. Fix: a fresh submit is a new turn — seed interrupted:false. 2. Back-to-back queue drains stalled. The drain fires on the busy->false settle edge, but busyRef (synced from the busy store by a separate effect) can still read true on that same edge, so the drained send hit the busy guard, returned false, and the entry was never removed. Fix: fromQueue sends bypass the busyRef guard (the queue drain lock serializes them); the user path keeps the guard. 3. Double-enter-to-interrupt killed single non-queue turns. The hidden 450ms timer meant a natural double-tap after sending stopped the agent. Fix: empty Enter while busy is a no-op; interrupting is explicit — Stop button or Esc. Also: clean stop (no [interrupted] marker), Send-now works while busy (promote + interrupt + auto-drain), settle on the interrupted completion path. Adds regression tests and unblocks the prompt-actions suite by completing its stale @/hermes mock. * fix(desktop): float the queue panel as an overlay so the chat doesn't resize The queue list rendered in-flow inside the composer root, so its height fed --composer-measured-height (the composer rect drives the thread's bottom padding + last-message clearance). Queuing a message grew that rect and the whole chat visibly resized. Anchor the panel out of flow above the composer (absolute bottom-full, capped at 40vh with internal scroll). It no longer contributes to the measured height, so the thread layout stays put and the list overlays the (already faded) chat. Still collapsible via the panel's own disclosure header. * fix(desktop): queue panel collapsed by default + shared border with composer - Default the queue disclosure to collapsed (compact 'N queued' pill) instead of expanded. - Drop the gap and merge the panel into the composer: square bottom corners, no bottom border/radius, and overlap down by the Root's pt-2 (-mb-2) so the panel's borderless bottom lands on the composer surface's top border — one continuous bordered shape. * style(desktop): tighten queue panel padding * style(desktop): trim queue-ux comments to house style * style(desktop): drop 'Cursor' references from comments
148 lines
5.4 KiB
TypeScript
148 lines
5.4 KiB
TypeScript
import { beforeEach, describe, expect, it } from 'vitest'
|
|
|
|
import type { ComposerAttachment } from './composer'
|
|
import {
|
|
$queuedPromptsBySession,
|
|
clearQueuedPrompts,
|
|
dequeueQueuedPrompt,
|
|
enqueueQueuedPrompt,
|
|
getQueuedPrompts,
|
|
promoteQueuedPrompt,
|
|
removeQueuedPrompt,
|
|
shouldAutoDrainOnSettle,
|
|
updateQueuedPrompt,
|
|
updateQueuedPromptText
|
|
} from './composer-queue'
|
|
|
|
const SESSION_KEY = 'session-abc'
|
|
const QUEUE_STORAGE_KEY = 'hermes.desktop.composerQueue.v1'
|
|
|
|
function attachment(id: string, kind: ComposerAttachment['kind'] = 'file'): ComposerAttachment {
|
|
return {
|
|
id,
|
|
kind,
|
|
label: id,
|
|
refText: `@file:${id}`
|
|
}
|
|
}
|
|
|
|
describe('composer queue store', () => {
|
|
beforeEach(() => {
|
|
window.localStorage.removeItem(QUEUE_STORAGE_KEY)
|
|
$queuedPromptsBySession.set({})
|
|
})
|
|
|
|
it('queues prompts in FIFO order', () => {
|
|
enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'first' })
|
|
enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'second' })
|
|
|
|
expect(dequeueQueuedPrompt(SESSION_KEY)?.text).toBe('first')
|
|
expect(dequeueQueuedPrompt(SESSION_KEY)?.text).toBe('second')
|
|
expect(dequeueQueuedPrompt(SESSION_KEY)).toBeNull()
|
|
})
|
|
|
|
it('clones attachments when queueing', () => {
|
|
const source = [attachment('a-1')]
|
|
const queued = enqueueQueuedPrompt(SESSION_KEY, { attachments: source, text: 'check clones' })
|
|
|
|
expect(queued).not.toBeNull()
|
|
expect(getQueuedPrompts(SESSION_KEY)[0]?.attachments[0]).toEqual(source[0])
|
|
expect(getQueuedPrompts(SESSION_KEY)[0]?.attachments[0]).not.toBe(source[0])
|
|
})
|
|
|
|
it('updates and removes queued entries by id', () => {
|
|
const first = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'draft one' })
|
|
const second = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'draft two' })
|
|
|
|
expect(first).not.toBeNull()
|
|
expect(second).not.toBeNull()
|
|
|
|
expect(updateQueuedPromptText(SESSION_KEY, first!.id, 'draft one edited')).toBe(true)
|
|
expect(getQueuedPrompts(SESSION_KEY).map(entry => entry.text)).toEqual(['draft one edited', 'draft two'])
|
|
|
|
expect(removeQueuedPrompt(SESSION_KEY, first!.id)).toBe(true)
|
|
expect(getQueuedPrompts(SESSION_KEY).map(entry => entry.text)).toEqual(['draft two'])
|
|
})
|
|
|
|
it('promotes a queued entry to the front', () => {
|
|
const first = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'first' })
|
|
const second = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'second' })
|
|
const third = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'third' })
|
|
|
|
expect(first).not.toBeNull()
|
|
expect(second).not.toBeNull()
|
|
expect(third).not.toBeNull()
|
|
|
|
expect(promoteQueuedPrompt(SESSION_KEY, third!.id)).toBe(true)
|
|
expect(getQueuedPrompts(SESSION_KEY).map(entry => entry.text)).toEqual(['third', 'first', 'second'])
|
|
expect(promoteQueuedPrompt(SESSION_KEY, third!.id)).toBe(false)
|
|
})
|
|
|
|
it('updates queued text and attachment snapshot', () => {
|
|
const first = enqueueQueuedPrompt(SESSION_KEY, { attachments: [attachment('f-1')], text: 'draft one' })
|
|
const editedAttachments = [attachment('f-2'), attachment('f-3', 'image')]
|
|
|
|
expect(first).not.toBeNull()
|
|
expect(
|
|
updateQueuedPrompt(SESSION_KEY, first!.id, {
|
|
attachments: editedAttachments,
|
|
text: 'edited text'
|
|
})
|
|
).toBe(true)
|
|
|
|
const queue = getQueuedPrompts(SESSION_KEY)
|
|
expect(queue[0]?.text).toBe('edited text')
|
|
expect(queue[0]?.attachments).toEqual(editedAttachments)
|
|
expect(queue[0]?.attachments[0]).not.toBe(editedAttachments[0])
|
|
})
|
|
|
|
it('clears queue state for a session', () => {
|
|
enqueueQueuedPrompt(SESSION_KEY, { attachments: [attachment('img-1', 'image')], text: 'queued' })
|
|
|
|
clearQueuedPrompts(SESSION_KEY)
|
|
|
|
expect(getQueuedPrompts(SESSION_KEY)).toEqual([])
|
|
expect($queuedPromptsBySession.get()[SESSION_KEY]).toBeUndefined()
|
|
expect(window.localStorage.getItem(QUEUE_STORAGE_KEY)).toBeNull()
|
|
})
|
|
|
|
it('persists queue entries into local storage', () => {
|
|
enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'persist me' })
|
|
|
|
const raw = window.localStorage.getItem(QUEUE_STORAGE_KEY)
|
|
expect(raw).toBeTruthy()
|
|
|
|
const parsed = JSON.parse(String(raw)) as Record<string, { text: string }[]>
|
|
expect(parsed[SESSION_KEY]?.[0]?.text).toBe('persist me')
|
|
})
|
|
})
|
|
|
|
describe('shouldAutoDrainOnSettle', () => {
|
|
const base = { isBusy: false, queueLength: 1, wasBusy: true }
|
|
|
|
it('drains the next queued prompt when a turn settles', () => {
|
|
expect(shouldAutoDrainOnSettle(base)).toBe(true)
|
|
})
|
|
|
|
it('drains after an interrupt — the settle edge is the same', () => {
|
|
// Interrupting to reach a queued message is the point of the queue; the
|
|
// gateway emits the same settle whether the turn finished or was stopped.
|
|
expect(shouldAutoDrainOnSettle(base)).toBe(true)
|
|
})
|
|
|
|
it('does not drain when the queue is empty', () => {
|
|
expect(shouldAutoDrainOnSettle({ ...base, queueLength: 0 })).toBe(false)
|
|
})
|
|
|
|
it('ignores steady busy state (no true → false transition)', () => {
|
|
expect(shouldAutoDrainOnSettle({ ...base, isBusy: true })).toBe(false)
|
|
})
|
|
|
|
it('ignores busy entry (false → true, not a settle)', () => {
|
|
expect(shouldAutoDrainOnSettle({ ...base, isBusy: true, wasBusy: false })).toBe(false)
|
|
})
|
|
|
|
it('ignores steady idle state (was not busy)', () => {
|
|
expect(shouldAutoDrainOnSettle({ ...base, wasBusy: false })).toBe(false)
|
|
})
|
|
})
|