Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
Merge remote-tracking branch 'origin/dev' into fix/stateless-incident-containment
Alfredo Lopez65bc16c26ac7
diff --cc control-api/package-lock.jsonindex 817e575a9,817e575a9..9c880649c--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-control-api",-- "version": "0.1.680",++ "version": "0.1.681","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",-- "version": "0.1.680",++ "version": "0.1.681","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --cc control-api/package.jsonindex ab5a7cfd6,ab5a7cfd6..2e64e8220--- a/control-api/package.json+++ b/control-api/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-control-api",-- "version": "0.1.680",++ "version": "0.1.681","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --cc control-ui/package-lock.jsonindex 55d17d3ac,c1d49250d..6cf07b947--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-control-ui",-- "version": "0.1.662",++ "version": "0.1.663","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",-- "version": "0.1.662",++ "version": "0.1.663","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --cc control-ui/package.jsonindex e75746e40,e75746e40..42dfc7727--- a/control-ui/package.json+++ b/control-ui/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-control-ui",-- "version": "0.1.662",++ "version": "0.1.663","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --cc desktop-app/src/ipc.tsindex 622e4f3b2,e5540b7c3..845195265--- a/desktop-app/src/ipc.ts+++ b/desktop-app/src/ipc.ts@@@ -10,12 -10,9 +10,13 @@@ importimport { randomUUID } from 'node:crypto'import { promises as fs } from 'node:fs'import path from 'node:path'+ import { parseFileReferenceV1 } from '@clerum/gfs-interaction-policy'import { AppService } from './appService.js'-import { requireChatStore } from './chatStoreBinding.js'+import {+ getChatStoreBindingGeneration,+ requireChatStore,+ requireChatStoreForBindingGeneration,+} from './chatStoreBinding.js'import { GFS_PREVIEW_MAX_BYTES } from './gfs/previewLimits.js'import { assertSafeRouteSegment } from './pathSafety.js'import {diff --cc desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsxindex 000000000,70f9bee06..8606e28b1mode 000000,100644..100644--- a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx@@@ -1,0 -1,383 +1,385 @@@+ // @vitest-environment jsdom+ /**+ * Issue #666 — a Global Files selection is sent as a structured FileReference v1+ * in `fileReferences`, next to the prompt line that names it. The prompt no+ * longer tells the model how to read the file; the Host's turn context does.+ */+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+ import { act, waitFor } from '@testing-library/react'+ import type { ComposerGlobalFileReference } from '../../../uiTypes'+ import { renderController } from './__fixtures__/controllerHarness'+ import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'++ let clerum: MockClerum+ let uuidCounter = 0++ ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++ const RID = '0123456789abcdef0123456789abcdef'++ const planFile: ComposerGlobalFileReference = {+ id: `global-file:main:${RID}`,+ type: 'global_file',+ resourceId: RID,+ drive: 'main',+ gfsUri: `gfs://main/${RID}`,+ label: 'plan.md',+ version: 4,+ bytes: 2048,+ }++ beforeEach(() => {+ uuidCounter = 0+ vi.spyOn(globalThis.crypto, 'randomUUID').mockImplementation(+ () => `uuid-${++uuidCounter}` as `${string}-${string}-${string}-${string}-${string}`+ )+ clerum = installMockClerum()+ })++ afterEach(() => {+ vi.restoreAllMocks()+ uninstallMockClerum()+ })++ async function settleMount() {+ await waitFor(() => expect(clerum.chat.getIndex).toHaveBeenCalled())+ }++ function sentRequest(): Record<string, unknown> {+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)+ return clerum.rpc.invokeHostMessage.mock.calls[0]?.[1] as Record<string, unknown>+ }++ describe('sendAgentMessage — structured Global Files references (#666)', () => {+ it('sends the selection as a FileReference v1', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const { result } = renderController()+ await settleMount()++ act(() => {+ result.current.handleAddComposerReferenceAttachments([planFile])+ })+ await act(async () => {+ await result.current.handleSendAgentMessage('Summarize the plan')+ })++ const request = sentRequest()+ expect(request.fileReferences).toEqual([+ expect.objectContaining({+ schemaVersion: 1,+ id: `gfs:main:${RID}@v4`,+ source: {+ kind: 'gfs',+ drive: 'main',+ resourceId: RID,+ gfsUri: `gfs://main/${RID}`,+ version: 4,+ },+ name: 'plan.md',+ class: 'markdown',+ byteLength: 2048,+ }),+ ])+ expect(request.content).toContain(+ 'Global Files: "plan.md". These files were explicitly selected by the user.'+ )+ expect(request.content).not.toContain('clerum__gfs_read')+ // The URI travels only in the structured reference above.+ expect(request.content).not.toContain('gfs://')+ })++ it('sends no fileReferences field without a Global Files selection', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const { result } = renderController()+ await settleMount()++ await act(async () => {+ await result.current.handleSendAgentMessage('plain question')+ })++ // Witness: the message was sent with its content.+ const request = sentRequest()+ expect(request.content).toBe('plain question')+ expect(request).not.toHaveProperty('fileReferences')+ })+ })++ const NOT_RECEIVED =+ 'The Host did not receive the selected Global Files; the message was sent without them.'++ const notesFile: ComposerGlobalFileReference = {+ ...planFile,+ id: `global-file:main:${RID.replace('0', 'f')}`,+ resourceId: RID.replace('0', 'f'),+ gfsUri: `gfs://main/${RID.replace('0', 'f')}`,+ label: 'notes.md',+ version: 1,+ }++ const PLAN_ID = `gfs:main:${RID}@v4`+ const NOTES_ID = `gfs:main:${RID.replace('0', 'f')}@v1`++ /**+ * The Host's accepted answers (`messageHandler.ts`): a direct reply, a new+ * task, and the replay of a duplicate delivery whose first task completed.+ */+ const ACK_SHAPES = [+ ['synchronous', { success: true, response: 'done' }],+ ['async', { success: true, status: 'pending', taskId: 'task-refs' }],+ ['async replay', { success: true, status: 'completed', taskId: 'task-refs', response: 'done' }],+ ] as const++ async function sendWithReferences(+ ack: Record<string, unknown>,+ references: ComposerGlobalFileReference[]+ ) {+ clerum.rpc.invokeHostMessage.mockResolvedValue(ack)+ const rendered = renderController()+ await settleMount()+ act(() => {+ rendered.result.current.handleAddComposerReferenceAttachments(references)+ })+ await act(async () => {+ await rendered.result.current.handleSendAgentMessage('Summarize the files')+ })+ return rendered+ }++ function sentReferenceIds(): string[] {+ const request = sentRequest()+ return (request.fileReferences as Array<{ id: string }>).map(reference => reference.id)+ }++ /** Proves the accepted-ack branch ran, whatever the ack shape. */+ function expectAcceptedAck(+ shape: string,+ pushToast: ReturnType<typeof vi.fn>,+ droppedMessage?: string+ ) {+ if (shape === 'synchronous') {+ if (droppedMessage === undefined) {+ expect(pushToast).toHaveBeenCalledWith('Message sent to agent-x.', 'success')+ return+ }+ // A send that lost its files shows only the error that says so: a success+ // toast beside it would contradict it. The error toast is the witness that+ // the accepted branch ran, and no other error toast may appear with it.+ expect(pushToast).not.toHaveBeenCalledWith('Message sent to agent-x.', 'success')+ expect(pushToast.mock.calls.filter(([, kind]) => kind === 'error')).toEqual([+ [droppedMessage, 'error'],+ ])+ return+ }- expect(clerum.chat.appendMessages).toHaveBeenCalledWith(++ // The async ack persists the user turn with its task_id through the++ // idempotent upsert (the turn was already written once before the send).++ expect(clerum.chat.upsertMessages).toHaveBeenCalledWith(+ 'agent-x',+ expect.any(String),+ expect.arrayContaining([expect.objectContaining({ role: 'user', task_id: 'task-refs' })])+ )+ }++ describe('sendAgentMessage — references the Host did not receive (#666 M1)', () => {+ it.each(ACK_SHAPES)(+ '%s ack without acceptedFileReferenceIds shows the error once, without a retry',+ async (shape, ack) => {+ const { result, spies } = await sendWithReferences({ ...ack }, [planFile])++ expect(sentReferenceIds()).toEqual([PLAN_ID])+ expect(result.current.agentError).toBe(NOT_RECEIVED)+ expect(spies.pushToast).toHaveBeenCalledWith(NOT_RECEIVED, 'error')+ // The send stands: accepted, not failed, and not resent.+ expectAcceptedAck(shape, spies.pushToast, NOT_RECEIVED)+ expect(result.current.failedAgentSend).toBeNull()+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)+ }+ )++ it('does not read an empty ack (the proxy answer to an unreadable Host body) as a drop', async () => {+ const { result, spies } = await sendWithReferences({}, [planFile])++ // Witness: the send went out with the reference and was not marked failed.+ expect(sentReferenceIds()).toEqual([PLAN_ID])+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)+ expect(result.current.failedAgentSend).toBeNull()+ expect(result.current.agentError).toBeNull()+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')+ })++ it.each(ACK_SHAPES)('%s ack that echoes every sent id shows no error', async (shape, ack) => {+ const { result, spies } = await sendWithReferences(+ { ...ack, acceptedFileReferenceIds: [PLAN_ID, NOTES_ID] },+ [planFile, notesFile]+ )++ // Witness: the ack reached the accepted branch and echoed exactly the+ // ids that were sent.+ expectAcceptedAck(shape, spies.pushToast)+ expect(sentReferenceIds()).toEqual([PLAN_ID, NOTES_ID])+ expect(result.current.agentError).toBeNull()+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')+ })++ it.each(ACK_SHAPES)(+ '%s ack that echoes only some sent ids names the dropped count',+ async (shape, ack) => {+ const { result, spies } = await sendWithReferences(+ { ...ack, acceptedFileReferenceIds: [PLAN_ID] },+ [planFile, notesFile]+ )++ expect(sentReferenceIds()).toEqual([PLAN_ID, NOTES_ID])+ const partial =+ 'The Host did not receive 1 of the selected Global Files; the message was sent without them.'+ expect(result.current.agentError).toBe(partial)+ expect(spies.pushToast).toHaveBeenCalledWith(partial, 'error')+ expectAcceptedAck(shape, spies.pushToast, partial)+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)+ }+ )++ it('shows a file reference refusal as its own error, not as a drop', async () => {+ const refusal = {+ success: false,+ error: {+ code: 'FILE_REFERENCE_CHECK_FAILED',+ message: 'The selected files could not be checked. Try again.',+ retryable: true,+ provider: 'unknown',+ },+ }+ const { result, spies } = await sendWithReferences(refusal, [planFile])++ // Witness: the refusal reached the chat as an error message with its code.+ expect(sentReferenceIds()).toEqual([PLAN_ID])+ const lastMessage = result.current.chatMessages.at(-1)+ expect(lastMessage).toMatchObject({+ role: 'assistant',+ isError: true,+ errorCode: 'FILE_REFERENCE_CHECK_FAILED',+ content: 'The selected files could not be checked. Try again.',+ })+ expect(result.current.agentError).not.toBe(NOT_RECEIVED)+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')+ })++ it('does not check the ack of a send without references', async () => {+ const { result, spies } = await sendWithReferences({ response: 'done' }, [])++ // Witness: the send was accepted; the ack carries no ids and needs none.+ expectAcceptedAck('synchronous', spies.pushToast)+ expect(sentRequest()).not.toHaveProperty('fileReferences')+ expect(result.current.agentError).toBeNull()+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')+ })+ })++ describe('sendAgentMessage — file limit (#666 M4)', () => {+ function manyFiles(count: number): ComposerGlobalFileReference[] {+ return Array.from({ length: count }, (_, index) => {+ const rid = index.toString(16).padStart(32, 'a')+ return {+ ...planFile,+ id: `global-file:main:${rid}`,+ resourceId: rid,+ gfsUri: `gfs://main/${rid}`,+ label: `f${index}.md`,+ }+ })+ }++ it('refuses an eleventh file before anything is cleared or sent', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const { result, spies } = renderController()+ await settleMount()++ // Two picker opens, each within the ten-file limit on its own.+ act(() => {+ result.current.handleAddComposerReferenceAttachments(manyFiles(6))+ })+ act(() => {+ result.current.handleAddComposerReferenceAttachments(manyFiles(11).slice(6))+ })+ // Liveness witness: all eleven are in the composer, so the refusal below+ // comes from the limit and not from an empty selection.+ expect(result.current.composerReferenceAttachments).toHaveLength(11)++ await act(async () => {+ await result.current.handleSendAgentMessage('Summarize the files')+ })++ const limit = 'A message can reference at most 10 files.'+ expect(result.current.agentError).toBe(limit)+ expect(spies.pushToast).toHaveBeenCalledWith(limit, 'error')+ expect(clerum.rpc.invokeHostMessage).not.toHaveBeenCalled()+ // The composer keeps the selection so the user can remove one and resend.+ expect(result.current.composerReferenceAttachments).toHaveLength(11)+ expect(result.current.agentSending).toBe(false)+ })++ it('sends after the user removes the extra file, so the refusal does not lock the composer', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const { result } = renderController()+ await settleMount()++ const files = manyFiles(11)+ act(() => {+ result.current.handleAddComposerReferenceAttachments(files)+ })+ await act(async () => {+ await result.current.handleSendAgentMessage('Summarize the files')+ })+ // Liveness witness: the first attempt was refused.+ expect(result.current.agentError).toBe('A message can reference at most 10 files.')+ expect(clerum.rpc.invokeHostMessage).not.toHaveBeenCalled()++ act(() => {+ result.current.handleRemoveComposerReferenceAttachment(files[10]!.id)+ })+ // Removing a file answers the refusal, so the error goes away with it.+ expect(result.current.agentError).toBeNull()++ await act(async () => {+ await result.current.handleSendAgentMessage('Summarize the files')+ })+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)+ })++ it('refuses a selection whose reference cannot be built, before anything is cleared or sent', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const { result, spies } = renderController()+ await settleMount()++ act(() => {+ result.current.handleAddComposerReferenceAttachments([+ { ...planFile, label: 'drafts/plan.md' },+ ])+ })+ await act(async () => {+ await result.current.handleSendAgentMessage('Summarize the plan')+ })++ expect(result.current.agentError).toMatch(/^Global file reference is invalid \(/)+ expect(spies.pushToast).toHaveBeenCalledWith(result.current.agentError, 'error')+ expect(clerum.rpc.invokeHostMessage).not.toHaveBeenCalled()+ expect(result.current.composerReferenceAttachments).toHaveLength(1)+ expect(result.current.agentSending).toBe(false)+ })+ })++ describe('sendAgentMessage — payload too large (#666 L12)', () => {+ it('names images and attached files in the 413 message', async () => {+ clerum.rpc.invokeHostMessage.mockRejectedValue(new Error('Request Entity Too Large'))+ const { result } = renderController()+ await settleMount()++ await act(async () => {+ await result.current.handleSendAgentMessage('large send')+ })++ expect(result.current.agentError).toContain(+ 'The message is larger than the deployed runtime accepts (images or attached files).'+ )+ expect(result.current.agentError).not.toContain('Image payload')+ })+ })diff --cc desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex f86544b29,2f97a56eb..dca0f7034--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@@ -2806,15 -2545,21 +2809,29 @@@ export function useAgentChatController(visualModelForSend = selection.intentModel ?? selection.effectiveModel ?? undefinedvisualModelRevisionForSend = selection.confirmedRevision ?? undefined}+ // #666 — build the structured references before anything is cleared or+ // created. A selection past the shared limit (or an invalid reference)+ // must leave the composer and its draft as the user typed them, with the+ // reason on screen, instead of failing after the send cleared the composer.+ let fileReferencesForSend: ReturnType<typeof buildComposerFileReferences>+ try {+ fileReferencesForSend = buildComposerFileReferences(effectiveReferences)+ } catch (error) {+ const blocker = error instanceof Error ? error.message : String(error)+ setAgentError(blocker)+ pushToast(blocker, 'error')- agentSendInFlightRef.current = false++ releaseSendSetup()+ return+ }- let sendChatId = activeChatId+ let sendChatId = currentChatId ?? activeChatId+ const sendStillAuthorized = () =>+ sendScope === sendScopeGeneration.current &&+ sendScopeIdentity === currentAuthScopeRef.current &&+ !isHostAccessBlocked(sendAgent) &&+ (!sendChatId || !isChatDeleted(sendAgent, sendChatId))+ const sendChatIsVisible = () =>+ activeChatVisibilityRef.current.selectedAgent === sendAgent &&+ activeChatVisibilityRef.current.activeChatId === sendChatId// Captured for the retention snapshot: the model this attempt actually// asked for (issue #654), readable from the catch below.let requestModelForRetention: string | undefined@@@ -3008,9 -2717,10 +3025,10 @@@// R2 "Option A": a per-session model chosen while the host was suspended// couldn't be persisted server-side, so it was held as pending. Piggyback// it here — this send wakes the host and applies the model to this task.- if (sendScope !== sendScopeGeneration.current) return+ if (!sendStillAuthorized()) returnconst pendingModel = pendingModelForSendconst requestModel = requestModelForRetention+ const fileReferences = fileReferencesForSendconst request = {content: effectiveContentForRequest,channelType: 'rpc',diff --cc external-rest-api/src/releaseManifest.tsindex 0baa962b2,338f898a4..bb35bc927--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@@ -9,7 -9,7 +9,7 @@@ export type ReleaseManifest =export const releaseManifest: ReleaseManifest = {releaseId: 'v0.10.0',externalRestApiVersion: '0.1.85',- rpcProxyVersion: '0.1.102',- rpcProxyVersion: '0.1.94',++ rpcProxyVersion: '0.1.103',desktopVersion: '0.10.0',minimumDesktopVersion: '0.1.252',}diff --cc mcp-host/package-lock.jsonindex bfb636360,fa85fc3a0..c2fb5f9b4--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-mcp-host",- "version": "0.1.473",- "version": "0.1.471",++ "version": "0.1.474","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.473",- "version": "0.1.471",++ "version": "0.1.474","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --cc mcp-host/package.jsonindex a29c57701,2313280cd..46645f24d--- a/mcp-host/package.json+++ b/mcp-host/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-mcp-host",- "version": "0.1.473",- "version": "0.1.471",++ "version": "0.1.474","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --cc rpc-proxy/package-lock.jsonindex 657a6aee4,fa235616b..3fdbed6fc--- a/rpc-proxy/package-lock.json+++ b/rpc-proxy/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-rpc-proxy",- "version": "0.1.102",- "version": "0.1.94",++ "version": "0.1.103","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-rpc-proxy",- "version": "0.1.102",- "version": "0.1.94",++ "version": "0.1.103","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --cc rpc-proxy/package.jsonindex 88a2121f3,cbaa8cf89..35c37b165--- a/rpc-proxy/package.json+++ b/rpc-proxy/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-rpc-proxy",- "version": "0.1.102",- "version": "0.1.94",++ "version": "0.1.103","description": "External-facing RPC proxy for tenant-scoped MCP access","main": "dist/main.js","engines": {