The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fmt(js): `npm run fix` on merge (#118897)
hermes-seaeye[bot]969872ebaa14
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/response-occurrences.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/response-occurrences.test.tsxindex 29ca07f9f98..04cb081033a 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/response-occurrences.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-message-stream/response-occurrences.test.tsx@@ -16,8 +16,10 @@ it.each(['interim', 'completion', 'completion without delta'])(async boundary => {const sid = 'response-occurrences'const stream = renderMessageStream(sid)+const send = (type: GatewayEventName, payload: Record<string, unknown> = {}) =>act(() => stream.handleEvent({ type, payload, session_id: sid }))+const history: SessionMessage[] = []const comments = boundary === 'interim' ? ['Checking.', 'Checking.', 'Next phase.'] : ['Checking.', 'Checking.']@@ -35,8 +37,12 @@ it.each(['interim', 'completion', 'completion without delta'])(await send('tool.start', { name: 'read_file', tool_id: id, args: {} })await send('tool.complete', { name: 'read_file', tool_id: id, result: 'read' })history.push(- { id: index * 2 + 1, role: 'assistant', content: comment,- tool_calls: [{ id, type: 'function', function: { name: 'read_file', arguments: '{}' } }] },+ {+ id: index * 2 + 1,+ role: 'assistant',+ content: comment,+ tool_calls: [{ id, type: 'function', function: { name: 'read_file', arguments: '{}' } }]+ },{ id: index * 2 + 2, role: 'tool', content: 'read', tool_call_id: id })}@@ -49,8 +55,12 @@ it.each(['interim', 'completion', 'completion without delta'])(history.push({ id: 20, role: 'assistant', content: 'Done.' })const durable = toChatMessages(history)expect(text(stream.state().messages)).toBe(text(durable))- const toolIds = () => stream.state().messages.flatMap(row => row.parts.flatMap(part =>- part.type === 'tool-call' ? [part.toolCallId] : []))++ const toolIds = () =>+ stream+ .state()+ .messages.flatMap(row => row.parts.flatMap(part => (part.type === 'tool-call' ? [part.toolCallId] : [])))+expect(toolIds()).toEqual(comments.map((_, index) => `tool-${index}`))await send('message.complete', { text: 'Done.' })diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/response-parts.ts b/apps/desktop/src/app/session/hooks/use-message-stream/response-parts.tsindex bcf3376f25d..36bb16c04a4 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/response-parts.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/response-parts.ts@@ -7,11 +7,7 @@ export function currentResponseParts(parts: ChatMessagePart[]): ChatMessagePart[return parts.slice(parts.findLastIndex(part => part.type === 'tool-call') + 1)}-export function mergeCurrentResponseText(- parts: ChatMessagePart[],- text: string,- timestamp: number-): ChatMessagePart[] {+export function mergeCurrentResponseText(parts: ChatMessagePart[], text: string, timestamp: number): ChatMessagePart[] {const boundary = parts.findLastIndex(part => part.type === 'tool-call') + 1return [...parts.slice(0, boundary), ...mergeFinalAssistantText(parts.slice(boundary), text, timestamp)]diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex 2f68b5b6669..c0a850f2ab0 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -1525,7 +1525,8 @@ export function useSessionActions({// reconcile inside the fallback would return `null` again.reconciledCurrentLiveTurn = currentLiveTurn !== nullactivatedMessages =- currentLiveTurn ?? reconcileAuthoritativeChatMessages(persistedMessages, previousMessages, liveProjection)+ currentLiveTurn ??+ reconcileAuthoritativeChatMessages(persistedMessages, previousMessages, liveProjection)}}diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.tsindex 33287de2b7a..660f4ad4298 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts@@ -1228,7 +1228,9 @@ describe('preserveLocalPendingTurnMessages', () => {const next = [msg('1-user', 'user', 'inspect the fixture'), toolRound]const previous = [...next, msg('assistant-stream-final', 'assistant', 'The result is 71.', { pending: false })]- expect(preserveLocalPendingTurnMessages(next, previous).map(message => message.id)).toContain('assistant-stream-final')+ expect(preserveLocalPendingTurnMessages(next, previous).map(message => message.id)).toContain(+ 'assistant-stream-final'+ )})it('keeps an equal final answer that belongs to a later turn history has not stored', () => {@@ -1245,7 +1247,9 @@ describe('preserveLocalPendingTurnMessages', () => {const next = [msg('1-user', 'user', 'first'), folded, msg('2-user', 'user', 'again')]const previous = [...next, msg('assistant-stream-later', 'assistant', 'The result is 71.', { pending: false })]- expect(preserveLocalPendingTurnMessages(next, previous).map(message => message.id)).toContain('assistant-stream-later')+ expect(preserveLocalPendingTurnMessages(next, previous).map(message => message.id)).toContain(+ 'assistant-stream-later'+ )})// The whole point of replacing rather than appending: one reply on screen,diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex caaf87c1ba7..81d34b4b8d6 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -590,10 +590,7 @@ function durableFoldCoversLiveResponse(messages: ChatMessage[], live: ChatMessagconst lastUser = messages.findLastIndex(message => message.role === 'user' && !isGatewaySystemMarker(message))return messages.slice(lastUser + 1).some(message => {- if (- message.role !== 'assistant' ||- isLiveTailReplyId(message.id)- ) {+ if (message.role !== 'assistant' || isLiveTailReplyId(message.id)) {return false}diff --git a/apps/desktop/src/lib/chat-messages/coverage.ts b/apps/desktop/src/lib/chat-messages/coverage.tsindex fa7efc0b2ea..cac8c37c20e 100644--- a/apps/desktop/src/lib/chat-messages/coverage.ts+++ b/apps/desktop/src/lib/chat-messages/coverage.ts@@ -17,7 +17,7 @@ function sameOccurrencePart(stored: ChatMessagePart, local: ChatMessagePart): bo* interval. Hydration can fold several live bubbles into one durable row;* bubble ordinals and equal text alone cannot establish that coverage. */export function withoutCoveredAssistantPrefix(stored: ChatMessage[], local: ChatMessage[]): ChatMessage[] {- const parts = stored.flatMap(message => message.role === 'assistant' ? message.parts : [])+ const parts = stored.flatMap(message => (message.role === 'assistant' ? message.parts : []))let cursor = 0let anchored = falselet stopped = falsediff --git a/apps/desktop/src/lib/chat-messages/parts.ts b/apps/desktop/src/lib/chat-messages/parts.tsindex 06db68fbe9f..eedf425e5e6 100644--- a/apps/desktop/src/lib/chat-messages/parts.ts+++ b/apps/desktop/src/lib/chat-messages/parts.ts@@ -223,7 +223,8 @@ function dedupeRepeatedRowText(parts: ChatMessagePart[]): ChatMessagePart[] {})const kept = parts.filter(- (part, index) => part.type !== 'text' || part.sourceRowId === undefined || lastByOccurrence.get(occurrence(part)) === index+ (part, index) =>+ part.type !== 'text' || part.sourceRowId === undefined || lastByOccurrence.get(occurrence(part)) === index)return kept.length === parts.length ? parts : keptdiff --git a/apps/desktop/src/lib/inflight-turn-journal.ts b/apps/desktop/src/lib/inflight-turn-journal.tsindex 735538f2345..6ca1a364d8d 100644--- a/apps/desktop/src/lib/inflight-turn-journal.ts+++ b/apps/desktop/src/lib/inflight-turn-journal.ts@@ -147,7 +147,8 @@ function isSnapshot(value: unknown): value is InFlightTurnSnapshot {Boolean(part) &&typeof part === 'object' &&typeof part.type === 'string' &&- (part.sourceRowId === undefined || (typeof part.sourceRowId === 'number' && Number.isFinite(part.sourceRowId))) &&+ (part.sourceRowId === undefined ||+ (typeof part.sourceRowId === 'number' && Number.isFinite(part.sourceRowId))) &&(part.type !== 'text' && part.type !== 'reasoning'? part.type !== 'tool-call' ||(typeof part.toolName === 'string' &&@@ -721,23 +722,35 @@ function journalTailAlreadyCommitted(tailAssistants: ChatMessage[], baseMessagesconst lastTurnStart = baseMessages.findLastIndex(message => message.role === 'user')const identityCovers = (base: ChatMessage, index: number, journaled: ChatMessage) =>- base.id === journaled.id ||- (journaled.rowId === undefined ? index > lastTurnStart : base.rowId === journaled.rowId)-- return recoverable.every(message => baseMessages.some((base, index) =>- base.role === 'assistant' && !base.hidden && isCommittedRow(base) && identityCovers(base, index, message) &&- base.error === message.error &&- normalizedText(chatMessageText(base)) === normalizedText(chatMessageText(message)) &&- message.parts.every(part => {- if (part.type === 'tool-call') {- return base.parts.some(candidate => candidate.type === 'tool-call' && Boolean(part.toolCallId) &&- candidate.toolCallId === part.toolCallId)- }-- return part.type !== 'reasoning' || base.parts.some(candidate => candidate.type === 'reasoning' &&- normalizedText(candidate.text) === normalizedText(part.text))- })- ))+ base.id === journaled.id || (journaled.rowId === undefined ? index > lastTurnStart : base.rowId === journaled.rowId)++ return recoverable.every(message =>+ baseMessages.some(+ (base, index) =>+ base.role === 'assistant' &&+ !base.hidden &&+ isCommittedRow(base) &&+ identityCovers(base, index, message) &&+ base.error === message.error &&+ normalizedText(chatMessageText(base)) === normalizedText(chatMessageText(message)) &&+ message.parts.every(part => {+ if (part.type === 'tool-call') {+ return base.parts.some(+ candidate =>+ candidate.type === 'tool-call' && Boolean(part.toolCallId) && candidate.toolCallId === part.toolCallId+ )+ }++ return (+ part.type !== 'reasoning' ||+ base.parts.some(+ candidate =>+ candidate.type === 'reasoning' && normalizedText(candidate.text) === normalizedText(part.text)+ )+ )+ })+ )+ )}export function mergeInFlightMessages(@@ -813,9 +826,13 @@ export function mergeInFlightMessages(const afterUser = baseMessages.slice(matchingUserIndex + 1, end)const completedReply = afterUser.find(- message => assistantHasRecoverableContent(message) && isCommittedRow(message) &&- (message.durableComplete === true || (message.durableComplete === undefined && !message.interim &&- !message.parts.some(part => part.type === 'tool-call')))+ message =>+ assistantHasRecoverableContent(message) &&+ isCommittedRow(message) &&+ (message.durableComplete === true ||+ (message.durableComplete === undefined &&+ !message.interim &&+ !message.parts.some(part => part.type === 'tool-call'))))if (completedReply) {@@ -823,14 +840,16 @@ export function mergeInFlightMessages(return { ...noop, caughtUp: true }}- tailAssistants = withoutCoveredAssistantPrefix(- afterUser.filter(isCommittedRow), tailAssistants- )+ tailAssistants = withoutCoveredAssistantPrefix(afterUser.filter(isCommittedRow), tailAssistants)lastJournalRow = tailAssistants.findLast(assistantHasRecoverableContent) ?? nullconst projectionIndex = baseMessages.findLastIndex(- (message, index) => index > matchingUserIndex && index < end && message.role === 'assistant' &&- !message.interim && isLiveProjectionRow(message)+ (message, index) =>+ index > matchingUserIndex &&+ index < end &&+ message.role === 'assistant' &&+ !message.interim &&+ isLiveProjectionRow(message))if (projectionIndex < 0) {@@ -843,7 +862,11 @@ export function mergeInFlightMessages(return {applied: true,caughtUp: false,- messages: [...baseMessages.slice(0, end), ...withoutBaseIds(tailAssistants, baseMessages), ...baseMessages.slice(end)],+ messages: [+ ...baseMessages.slice(0, end),+ ...withoutBaseIds(tailAssistants, baseMessages),+ ...baseMessages.slice(end)+ ],// Only a running turn keeps a stream target; recovered metadata retains// the journal independently until durable completion is observed.streamId: options.keepPending ? streamId : null,@@ -969,9 +992,15 @@ export function persistInFlightTurnState(state: JournalableSessionState): void {// `some(recovered)` is a cheap pre-check: this runs on every idle commit of// every cached session, and recovered rows are rare.- if (!state.busy && !state.awaitingResponse && !state.streamId &&- !(state.messages.some(message => message.recovered) &&- recoverableTail(state.messages, null).some(message => message.recovered))) {+ if (+ !state.busy &&+ !state.awaitingResponse &&+ !state.streamId &&+ !(+ state.messages.some(message => message.recovered) &&+ recoverableTail(state.messages, null).some(message => message.recovered)+ )+ ) {clearInFlightTurnJournal(storedSessionId)returndiff --git a/apps/desktop/src/lib/transcript-occurrences.test.ts b/apps/desktop/src/lib/transcript-occurrences.test.tsindex a02f865a1b9..d27921d0d2d 100644--- a/apps/desktop/src/lib/transcript-occurrences.test.ts+++ b/apps/desktop/src/lib/transcript-occurrences.test.ts@@ -63,13 +63,19 @@ it('recovers only the uncommitted journal suffix until the complete reply becomeconst stored = toChatMessages([prompt, ...round(2, 'Checking the file.')])const tail: ChatMessage = {- id: 'assistant-stream-runtime', role: 'assistant', pending: true,+ id: 'assistant-stream-runtime',+ role: 'assistant',+ pending: true,parts: [{ type: 'text', text: 'The unfinished conclusion.' }]}const state = {- storedSessionId: 'occurrence-session', busy: true, awaitingResponse: false,- streamId: tail.id, turnStartedAt: 1000, messages: [...stored, tail]+ storedSessionId: 'occurrence-session',+ busy: true,+ awaitingResponse: false,+ streamId: tail.id,+ turnStartedAt: 1000,+ messages: [...stored, tail]}persistInFlightTurnState(state)@@ -88,7 +94,8 @@ it('recovers only the uncommitted journal suffix until the complete reply becomeexpect(readInFlightTurnJournal(state.storedSessionId)).not.toBeNull()const completed = toChatMessages([- prompt, ...round(2, 'Checking the file.'),+ prompt,+ ...round(2, 'Checking the file.'),{ id: 4, role: 'assistant', content: 'The unfinished conclusion. Now complete.', timestamp: 4 }])@@ -96,47 +103,63 @@ it('recovers only the uncommitted journal suffix until the complete reply becomeexpect(readInFlightTurnJournal(state.storedSessionId)).toBeNull()})-it.each(['missing prompt', 'repeated prompt', 'no prompt'])('does not clear an unknown journal occurrence by global text: %s', shape => {- // The equal reply belongs to an OLDER turn; only the most recently- // committed turn can prove a live journal row stale.- const older = toChatMessages([- prompt,- { id: 2, role: 'assistant', content: 'Still working.', timestamp: 2 },- { id: 3, role: 'user', content: 'And then?', timestamp: 3 },- { id: 4, role: 'assistant', content: 'Done.', timestamp: 4 }- ])-- const user: ChatMessage = {- id: 'new-user', rowId: 5, role: 'user',- parts: [{ type: 'text', text: shape === 'repeated prompt' ? 'Inspect each phase' : 'A new question' }]+it.each(['missing prompt', 'repeated prompt', 'no prompt'])(+ 'does not clear an unknown journal occurrence by global text: %s',+ shape => {+ // The equal reply belongs to an OLDER turn; only the most recently+ // committed turn can prove a live journal row stale.+ const older = toChatMessages([+ prompt,+ { id: 2, role: 'assistant', content: 'Still working.', timestamp: 2 },+ { id: 3, role: 'user', content: 'And then?', timestamp: 3 },+ { id: 4, role: 'assistant', content: 'Done.', timestamp: 4 }+ ])++ const user: ChatMessage = {+ id: 'new-user',+ rowId: 5,+ role: 'user',+ parts: [{ type: 'text', text: shape === 'repeated prompt' ? 'Inspect each phase' : 'A new question' }]+ }++ const answer: ChatMessage = {+ id: 'assistant-stream-new',+ role: 'assistant',+ pending: true,+ parts: [{ type: 'text', text: 'Still working.' }]+ }++ persistInFlightTurnState({+ storedSessionId: 'repeated-session',+ messages: [...(shape === 'no prompt' ? [] : [user]), answer],+ busy: true,+ awaitingResponse: false,+ streamId: answer.id,+ turnStartedAt: 3000+ })+ vi.advanceTimersByTime(400)+ const recovered = recoverInFlightTurnJournal('repeated-session', older)+ expect(recovered.caughtUp).toBe(false)+ expect(assistantTexts(recovered.messages)).toEqual(['Still working.', 'Done.', 'Still working.'])+ expect(readInFlightTurnJournal('repeated-session')).not.toBeNull()}-- const answer: ChatMessage = {- id: 'assistant-stream-new', role: 'assistant', pending: true,- parts: [{ type: 'text', text: 'Still working.' }]- }-- persistInFlightTurnState({- storedSessionId: 'repeated-session', messages: [...(shape === 'no prompt' ? [] : [user]), answer],- busy: true, awaitingResponse: false, streamId: answer.id, turnStartedAt: 3000- })- vi.advanceTimersByTime(400)- const recovered = recoverInFlightTurnJournal('repeated-session', older)- expect(recovered.caughtUp).toBe(false)- expect(assistantTexts(recovered.messages)).toEqual(['Still working.', 'Done.', 'Still working.'])- expect(readInFlightTurnJournal('repeated-session')).not.toBeNull()-})+)it.each([true, false])('journal replay preserves sealed occurrences (live projection: %s)', hasLiveProjection => {const user = toChatMessages([prompt])[0]const sealed: ChatMessage = {- id: 'assistant-stream-sealed', role: 'assistant', interim: true, pending: false,+ id: 'assistant-stream-sealed',+ role: 'assistant',+ interim: true,+ pending: false,parts: [{ type: 'text', text: 'Checking.' }]}const live: ChatMessage = {- id: 'assistant-stream-live', role: 'assistant', pending: true,+ id: 'assistant-stream-live',+ role: 'assistant',+ pending: true,parts: [{ type: 'text', text: 'Still working.' }]}