Skip to content

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.

feat(codex): auto-apply option for staged changes — "auto on everything" means auto

purple049ef504e1a3
diff --git a/src/components/chat/StagedChangesPanel.tsx b/src/components/chat/StagedChangesPanel.tsx
index 1053a9f5..38fc836a 100644
--- a/src/components/chat/StagedChangesPanel.tsx
+++ b/src/components/chat/StagedChangesPanel.tsx
@@ -1,8 +1,7 @@
import { useState } from 'react'
import { Check, X, ChevronDown, ChevronRight, FileText } from 'lucide-react'
import { useStagedChangesStore, type StagedChange } from '../../stores/stagedChangesStore'
-import { useChatStore } from '../../stores/chatStore'
-import { backendCall } from '../../api/backend'
+import { applyStagedChange } from '../../lib/staged-apply'
import { DiffView } from './DiffView'
import { log } from '../../lib/logger'
@@ -42,36 +41,10 @@ export function StagedChangesPanel({ chatId }: Props) {
if (!chatId) return
setApplying((prev) => new Set(prev).add(change.id))
try {
- // Write via fs_write DIRECTLY, not the `file_write` model tool. Two
- // reasons: (1) by apply time the loop's finally has cleared the active
- // chat/workspace, so file_write's chatCtx() is empty and the write jails
- // to agent-workspace/default — which REJECTS the absolute project path and
- // every apply silently fails. (2) file_write deliberately does NOT let its
- // caller pick the jail root (2.5.7 security review: a prompt-injected model
- // could set workingDirectory to escape the sandbox). Apply is a trusted,
- // user-gated UI action, so it is safe for the UI to pass the workspace root
- // captured at stage time as the jail root.
- const res = await backendCall<{ status?: string; path?: string }>('fs_write', {
- path: change.resolvedPath || change.path,
- content: change.newContent,
- chatId,
- workingDirectory: change.workingDirectory,
- })
- // 'saved' and 'unchanged' are both success ('unchanged' = the file already
- // matched byte-for-byte). Anything else is a real failure worth retrying.
- if (res?.status && res.status !== 'saved' && res.status !== 'unchanged') {
- throw new Error(`fs_write returned status "${res.status}"`)
- }
- remove(chatId, change.id)
- // Mirror the apply in the chat log so the user sees a confirmation
- // in the main pane, not just the side-pane disappearing.
- useChatStore.getState().addMessage(chatId, {
- id: crypto.randomUUID(),
- role: 'system',
- content: `Applied staged change: ${change.path}`,
- timestamp: Date.now(),
- hidden: true,
- })
+ // Shared trusted write path (lib/staged-apply) — the same call Codex
+ // auto-apply uses, so the reviewed diff and the auto-applied diff can
+ // never diverge.
+ await applyStagedChange(chatId, change)
} catch (e) {
// Apply failures leave the entry in the queue so the user can retry.
log.error('[StagedChangesPanel] apply failed', { err: e })
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index b7108866..6ae33b03 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -730,6 +730,13 @@ function CodexAgentSettings() {
enabled={settings.codexStageMode}
onChange={() => updateSettings({ codexStageMode: !settings.codexStageMode })}
/>
+ {settings.codexStageMode && (
+ <InlineToggle
+ label="Auto-apply staged changes when the run finishes (no per-file clicking)"
+ enabled={settings.codexAutoApply}
+ onChange={() => updateSettings({ codexAutoApply: !settings.codexAutoApply })}
+ />
+ )}
<InlineToggle
label="Code-Review mode (read-only)"
enabled={settings.codexReviewMode}