The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(staged): the line saying the file is not your diff now reaches the user
Davidb72de61351d0
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsxindex 9c6935d6..4ffbb90d 100644--- a/src/components/chat/CodexView.tsx+++ b/src/components/chat/CodexView.tsx@@ -23,7 +23,7 @@ import { useSettingsStore } from '../../stores/settingsStore'import { useModelStore } from '../../stores/modelStore'import { StagedChangesPanel } from './StagedChangesPanel'import { SlashStepsBlock } from './SlashStepsBlock'-import { User, Code, Eye, GitBranch, Download, RefreshCw, RotateCcw, Folder } from 'lucide-react'+import { User, Code, Eye, GitBranch, Download, RefreshCw, RotateCcw, Folder, Check, AlertTriangle } from 'lucide-react'import { useEffect, useState } from 'react'import { checkGitInstalled, openExternal, type GitStatus } from '../../api/backend'import { CodexConfirmDialog } from './CodexConfirmDialog'@@ -206,6 +206,28 @@ export function CodexView() {) : (<div ref={contentRef} className="py-1">{messages.filter(msg => !msg.hidden).map((msg) => {+ // App notices (a staged change that landed on disk) are not+ // model turns. They used to be written hidden, so the one line+ // that says "the file on disk is not the diff you approved"+ // reached nobody, and an assistant bubble would be the other+ // wrong answer: it would claim the model said it.+ if (msg.role === 'system' && msg.notice) {+ const warn = msg.notice === 'warn'+ return (+ <div key={msg.id} className="px-3 py-1" data-testid="codex-notice">+ <div className={`flex items-start gap-1.5 px-2 py-1 rounded border text-[0.6rem] leading-snug ${+ warn+ ? 'border-amber-300/70 dark:border-amber-500/30 bg-amber-50 dark:bg-amber-500/10 text-amber-900 dark:text-amber-200'+ : 'border-gray-200 dark:border-white/10 bg-gray-50/60 dark:bg-white/[0.02] text-gray-500 dark:text-gray-400'+ }`}>+ {warn+ ? <AlertTriangle size={10} className="mt-0.5 shrink-0" />+ : <Check size={10} className="mt-0.5 shrink-0" />}+ <span className="break-words">{msg.content}</span>+ </div>+ </div>+ )+ }// Slash commands: the user typed "/review", but msg.content holds// the expanded instruction the model ran on, show displayContent.const rawForDisplay = msg.role === 'user' ? (msg.displayContent || msg.content) : msg.contentdiff --git a/src/components/chat/__tests__/staged-apply-notice-reaches-the-user.test.ts b/src/components/chat/__tests__/staged-apply-notice-reaches-the-user.test.tsnew file mode 100644index 00000000..7b8f4a59--- /dev/null+++ b/src/components/chat/__tests__/staged-apply-notice-reaches-the-user.test.ts@@ -0,0 +1,82 @@+/**+ * The one line that says "the file on disk is not the diff you approved" has+ * to reach the user.+ *+ * Review 2026-08-14. applyStagedChange writes that line into the chat log with+ * a comment saying it is there "so the user sees a confirmation in the main+ * pane", and then flagged it `hidden: true`. Both renderers drop hidden+ * messages, and MessageList drops every system role on top of that, so the+ * notice rendered nowhere at all. The Pending row just disappeared, exactly as+ * it does after a clean apply, and with codexAutoApply on the user never even+ * clicked. There is no undo on that write.+ *+ * The other wrong answer would have been to let it render as an assistant+ * bubble: that claims the model said it (the same rule useCodex states where+ * it refuses to author answer text on the model's behalf). So it renders as a+ * plain notice line, and it stays role:'system' so the payload builder keeps+ * dropping it and the model never sees it.+ *+ * Run: npx vitest run src/components/chat/__tests__/staged-apply-notice-reaches-the-user.test.ts+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { fileURLToPath } from 'node:url'+import { dirname, resolve } from 'node:path'++const here = dirname(fileURLToPath(import.meta.url))+const read = (rel: string) => readFileSync(resolve(here, rel), 'utf8')+const codexView = read('../CodexView.tsx')+const stagedApply = read('../../../lib/staged-apply.ts')+const useCodex = read('../../../hooks/useCodex.ts')+const chatTypes = read('../../../types/chat.ts')++describe('the notice is written to be seen', () => {+ it('carries no hidden flag any more', () => {+ // Comments stripped: the doc above the call quotes the old flag on purpose,+ // so the whole file would match while the code is clean.+ const codeOnly = stagedApply+ .split('\n')+ .filter((l) => {+ const t = l.trim()+ return !t.startsWith('//') && !t.startsWith('*') && !t.startsWith('/*')+ })+ .join('\n')+ expect(codeOnly).not.toMatch(/hidden:\s*true/)+ })++ it('marks a merged apply as something to act on, a clean one as confirmation', () => {+ expect(stagedApply).toContain("notice: merged > 0 ? 'warn' : 'info'")+ expect(stagedApply).toMatch(/not byte for byte the diff you approved/)+ })++ it('the flag exists on the message type, so this is not a stray property', () => {+ expect(chatTypes).toMatch(/notice\?: 'info' \| 'warn'/)+ })+})++describe('the coding view renders it as a notice, not as the model talking', () => {+ it('has a branch for it before the bubble branch', () => {+ const list = codexView.slice(codexView.indexOf('messages.filter(msg => !msg.hidden)'))+ const branch = list.indexOf("msg.role === 'system' && msg.notice")+ const bubble = list.indexOf("msg.role === 'user' ? 'flex-row-reverse' : ''")+ expect(branch).toBeGreaterThan(-1)+ expect(branch).toBeLessThan(bubble)+ })++ it('a warn notice looks different from a confirmation', () => {+ const branch = codexView.slice(+ codexView.indexOf("msg.role === 'system' && msg.notice"),+ codexView.indexOf('// Slash commands:'),+ )+ expect(branch).toContain("const warn = msg.notice === 'warn'")+ expect(branch).toContain('AlertTriangle')+ expect(branch).toContain('amber')+ expect(branch).toContain('{msg.content}')+ })+})++describe('and the model still never sees it', () => {+ it('the payload builder drops the system role', () => {+ expect(useCodex).toContain("m.role !== 'system'")+ })+})diff --git a/src/lib/__tests__/staged-apply.test.ts b/src/lib/__tests__/staged-apply.test.tsindex daea1caa..7e3815d5 100644--- a/src/lib/__tests__/staged-apply.test.ts+++ b/src/lib/__tests__/staged-apply.test.ts@@ -193,6 +193,35 @@ describe('applyStagedChange refuses to overwrite a file that moved on', () => {expect(addMessage.mock.calls[0][1].content).toMatch(/merged with 1 change made on disk/)})+ // The merge notice was written with `hidden: true`, and both renderers drop+ // hidden messages (MessageList drops every system role on top of that), so+ // the only line that ever said "the bytes on disk are not the diff you+ // approved" reached nobody. On a write with no undo that is the one thing+ // the user must not miss.+ it('the merge notice is visible and marked as something to act on', async () => {+ route('a\nb\nc\nadded by another tool')+ stage('a.py', { oldContent: 'a\nb\nc', newContent: 'a\nCHANGED\nc' })+ await applyStagedChange(CHAT, useStagedChangesStore.getState().list(CHAT)[0])++ const msg = addMessage.mock.calls[0][1]+ expect(msg.hidden).toBeUndefined()+ expect(msg.notice).toBe('warn')+ expect(msg.content).toMatch(/not byte for byte the diff you approved/)+ // Still a system message: that is what keeps it out of the model payload.+ expect(msg.role).toBe('system')+ })++ it('a clean apply is a quiet confirmation, not a warning', async () => {+ route('a\nb\nc')+ stage('a.py', { oldContent: 'a\nb\nc', newContent: 'a\nCHANGED\nc' })+ await applyStagedChange(CHAT, useStagedChangesStore.getState().list(CHAT)[0])++ const msg = addMessage.mock.calls[0][1]+ expect(msg.hidden).toBeUndefined()+ expect(msg.notice).toBe('info')+ expect(msg.content).not.toMatch(/merged/)+ })+it('counts an already-applied file as done instead of failing it', async () => {route('a\nCHANGED\nc')stage('a.py', { oldContent: 'a\nb\nc', newContent: 'a\nCHANGED\nc' })diff --git a/src/lib/staged-apply.ts b/src/lib/staged-apply.tsindex fe45c2c5..3a16866c 100644--- a/src/lib/staged-apply.ts+++ b/src/lib/staged-apply.ts@@ -92,14 +92,23 @@ export async function applyStagedChange(chatId: string, change: StagedChange): P// Mirror the apply in the chat log so the user sees a confirmation in the// main pane, not just the side-pane entry disappearing. A merge is named as// one: the file that landed is not byte for byte the diff that was reviewed.+ //+ // This used to carry `hidden: true`, which made the sentence above a lie.+ // MessageList drops `hidden` AND every system role, CodexView drops+ // `hidden`, so the notice rendered nowhere at all, and the only line that+ // ever said "what landed is not what you approved" reached nobody. On a+ // write to disk that has no undo, that is the one thing the user must not+ // miss. The role stays 'system' so it still never reaches the model+ // (useCodex's payload builder filters that role out); `notice` is what tells+ // the view to render a plain line instead of an assistant bubble.useChatStore.getState().addMessage(chatId, {id: crypto.randomUUID(),role: 'system',content: merged > 0- ? `Applied staged change: ${change.path} (merged with ${merged} change${merged === 1 ? '' : 's'} made on disk since it was staged)`+ ? `Applied staged change: ${change.path} (merged with ${merged} change${merged === 1 ? '' : 's'} made on disk since it was staged, so this file is not byte for byte the diff you approved)`: `Applied staged change: ${change.path}`,timestamp: Date.now(),- hidden: true,+ notice: merged > 0 ? 'warn' : 'info',})}diff --git a/src/types/chat.ts b/src/types/chat.tsindex 212f447d..1b7059f7 100644--- a/src/types/chat.ts+++ b/src/types/chat.ts@@ -72,6 +72,13 @@ export interface Message {// of only the visible messages); it flips to false once the model reports the// exact prompt_eval_count / usage.prompt_tokens.usage?: { promptTokens: number; completionTokens: number; totalTokens: number; estimated?: boolean }+ /** An app notice, not a model turn: the coding view renders it as a plain+ * line instead of an assistant bubble, because putting it in a bubble would+ * claim the model said it. 'warn' is for a notice the user has to act on,+ * today the one that says the bytes on disk are NOT the diff they approved.+ * Carried on role:'system' messages, which the payload builder drops, so a+ * notice never reaches the model. */+ notice?: 'info' | 'warn'/** Why generation ended, when the model did NOT stop on its own terms:* 'length' (token budget) or 'disconnect'. Drives the small cut-off badge so* a truncated answer is not shown as if it were complete (parity with the