Skip to content

feat(settings): per-agent terminal theme overrides in Appearance - #14293

Open
edenaion wants to merge 1 commit into
stablyai:mainfrom
edenaion:feat/per-agent-terminal-themes
Open

edenaion wants to merge 1 commit into
stablyai:mainfrom
edenaion:feat/per-agent-terminal-themes

Conversation

@edenaion

@edenaion edenaion commented Aug 13, 2026 •

Copy link
Copy Markdown

ELI5

Orca can theme every terminal, but all agents share that one theme, so five side-by-side agent panes look identical. This adds per-agent theme overrides: give Claude a cream theme and Codex Dracula, and each pane (plus its OSC color replies) follows its agent. Everything defaults to "Inherit global", collapsed behind a disclosure, so nothing changes unless you opt in.
Screenshot 2026-08-13 104802
Screenshot 2026-08-13 102442

What

Fixes #14174. Settings map (agentTerminalThemes, missing key = inherit), agent-aware resolver, per-pane apply keyed by immutable pane-lifetime launch identity (splits and shells stay global), atomic {global, byAgent} view-attribute snapshot with cold-start seeding so hidden worker-start PTYs answer OSC 10/11/12 with the right palette (local/direct-SSH; paired-server background workers documented out of scope), dashboard preview support, collapsed-by-default Appearance UI with detected-agent rows, i18n and settings search. Catalog re-homed to src/shared with a renderer re-export.

Why

Multi-agent workflows can be unreadable at a glance when every TUI shares one palette; #13908/#6091-class startup color races made this worse. Related-but-different: #7257 (launch overrides).

Testing

~270 new/updated tests across sanitizer, resolver, per-pane apply, snapshot store/IPC, runtime spawn colors (Codex PTY receives Codex palette; scoped fan-out), UI (real-render assertions, no component mocks). pnpm typecheck and pnpm build pass. Full Windows vitest under Node 24 (the CI engine): 50,032 passed, 337 failed across 83 files with ZERO overlap with this PR's changed files - the failures are pre-existing env-dependent suites (ai-vault, cloud artifacts, git/fsync) that reproduce identically on Node 24 and Node 25 independent of this diff. Every diff in this PR also passed an independent review pass before merge into the branch (real-render test assertions; component mocks removed where found). Dev-build E2E verified: screenshots attached (settings state, multi-pane split with distinct palettes, match-dark-mode behavior).

Behavior note

Agents that hard-paint their own TUI colors (Grok CLI) keep their native look; the override governs the base palette, host-palette TUIs, shells, and OSC replies.

AI disclosure

AI-assisted implementation, human-reviewed and E2E-verified.

X: x.com/edenaion

@edenaion
edenaion requested a review from brennanb2025 as a code owner August 13, 2026 15:07
@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd898783-28fb-44b6-b56c-fe550af378df

📥 Commits

Reviewing files that changed from the base of the PR and between ff273b0df8880304329cbd73785f5411b994cba8 and d841ff7.


📒 Files selected for processing (75)
  • src/main/daemon/daemon-pty-connection-lifecycle.ts
  • src/main/daemon/daemon-pty-router.ts
  • src/main/ipc/pty-dispatcher-handshake-osc-answers.test.ts
  • src/main/ipc/pty/ipc/terminal-view-attributes-ipc.test.ts
  • src/main/ipc/pty/ipc/terminal-view-attributes-ipc.ts
  • src/main/ipc/pty/provider/registry.ts
  • src/main/ipc/settings.test.ts
  • src/main/ipc/settings.ts
  • src/main/ipc/terminal-startup-color-query-replies.test.ts
  • src/main/ipc/terminal-startup-color-query-replies.ts
  • src/main/persistence/applying-settings/settings-update-agent-terminal-themes.test.ts
  • src/main/persistence/applying-settings/settings-update.ts
  • src/main/persistence/loading-store/normalize-loaded-global-settings.test.ts
  • src/main/persistence/loading-store/normalize-loaded-global-settings.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-rpc-operations.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/runtime/orca-runtime-create-pty-headless-terminal-state.ts
  • src/main/runtime/orca-runtime-create-terminal.ts
  • src/main/runtime/orca-runtime-state-fields.ts
  • src/main/runtime/orca-runtime-tests/terminal-agent-view-attributes.spec.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/terminal-view-attribute-store.test.ts
  • src/main/runtime/terminal-view-attribute-store.ts
  • src/main/runtime/terminal-view-attributes-seed.test.ts
  • src/main/runtime/terminal-view-attributes-seed.ts
  • src/preload/api/pty-api.ts
  • src/preload/api/pty-bridge-session-control.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.theme.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/agent-terminal-preview-theme.ts
  • src/renderer/src/components/settings/AgentTerminalThemeRow.tsx
  • src/renderer/src/components/settings/AgentTerminalThemesSection.test.tsx
  • src/renderer/src/components/settings/AgentTerminalThemesSection.tsx
  • src/renderer/src/components/settings/TerminalAppearanceSection.tsx
  • src/renderer/src/components/settings/TerminalThemeSections.lifecycle.test.ts
  • src/renderer/src/components/settings/TerminalThemeSections.tsx
  • src/renderer/src/components/settings/agent-terminal-theme-options.ts
  • src/renderer/src/components/settings/agent-terminal-theme-rows.test.ts
  • src/renderer/src/components/settings/agent-terminal-theme-rows.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/renderer/src/components/settings/terminal-search.ts
  • src/renderer/src/components/terminal-pane/pane-theme-identity.test.ts
  • src/renderer/src/components/terminal-pane/pane-theme-identity.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.test.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-manager-options.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-pane-closed.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-pane-created.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-publisher.test.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-publisher.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-snapshot.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/terminal-theme.test.ts
  • src/renderer/src/lib/terminal-theme.ts
  • src/renderer/src/store/slices/settings.ts
  • src/shared/agent-terminal-themes.test.ts
  • src/shared/agent-terminal-themes.ts
  • src/shared/compose-active-terminal-theme.test.ts
  • src/shared/compose-active-terminal-theme.ts
  • src/shared/default-global-settings.ts
  • src/shared/global-settings-types.ts
  • src/shared/pty-owner-color-query-colors.test.ts
  • src/shared/pty-owner-color-query-colors.ts
  • src/shared/pty-owner-color-query-replies.ts
  • src/shared/pty-startup-ingress-contract.ts
  • src/shared/pty-startup-ingress-intent.ts
  • src/shared/pty-startup-ingress-lifetime-colors.test.ts
  • src/shared/terminal-theme-selection.ts
  • src/shared/terminal-view-attributes-composition.ts
  • src/shared/terminal-view-attributes.ts

🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

The change adds per-agent dark and light terminal theme settings, normalization, and Appearance controls. Renderer panes and dashboard previews resolve themes using agent identity. The renderer publishes global and per-agent terminal attribute snapshots. The main process validates and stores snapshots, applies changed attributes to matching PTYs, and uses agent-specific colors for terminal queries.

Priority: ⬇️ Low

Estimated code review effort:


Merge Risk: 🟡 Moderate · up to d841f

Theme colors can be rendered incorrectly, and a stale profile or unauthorized snapshot may supply terminal colors. Resolve the settings and IPC ownership risks before merging; the remaining wording issue is cosmetic.

Pre-merge checks | Passed 4 | Inconclusive 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 54 files. (25 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: per-agent terminal theme overrides in Appearance settings.
Description check Passed The description covers the user impact, implementation, rationale, linked issue, visual proof, testing, AI disclosure, scope limits, and known test failures. It omits some template headings and checkl…
Linked Issues check Passed Issue #14174 is an active direct target. The PR adds normalized agentTerminalThemes settings with inherit fallback, detected and persisted agent rows, and Dark/Light slot handling. It resolves theme…
Out of Scope Changes check Passed The changed settings, shared theme utilities, renderer UI, IPC types, PTY provider plumbing, runtime application, localization, search entries, and tests support the per-agent theme objective in #1417…

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 54 files. (25 skipped: 2 unsupported, 23 over the file limit.)



Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (5)
src/renderer/src/i18n/locales/en.json (1)

10675-10687: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove internal roadmap terminology from user-facing description.

The description for AgentTerminalThemes states: "Paired-server background workers are not themed in phase 1." The phrase "phase 1" is internal release terminology. Users read this text in Settings without context for what "phase 1" means or when a later phase arrives. State the current limitation without referencing an internal phase number.

✏️ Proposed wording fix
-          "description": "Shells and unset agents use the global Dark/Light themes. App chrome does not follow the agent. Paired-server background workers are not themed in phase 1.",
+          "description": "Shells and unset agents use the global Dark/Light themes. App chrome does not follow the agent. Paired-server background workers do not use agent themes yet.",
src/renderer/src/components/settings/agent-terminal-theme-options.ts (1)

6-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a localized catalog for the inherit label.

getAgentTerminalThemeOptions calls translate on each invocation. The caller in AgentTerminalThemesSection.tsx memoizes the result with [settings] only. After a UI language change, the "Inherit global" label stays in the previous language until settings changes.

Wrap the option list with createLocalizedCatalog (the same pattern used in agent-terminal-theme-search.ts), or remove the useMemo at the call site.

src/renderer/src/components/settings/AgentTerminalThemesSection.tsx (1)

105-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use i18next pluralization for the override count.

The code selects between override_count_one and override_count_other with a JavaScript comparison. That bypasses CLDR plural rules, so locales with more than two plural forms cannot resolve the correct form.

Pass count to the translation call and let i18next select the form.

♻️ Proposed refactor
-  const overrideSummary =
-    overrideCount === 0
-      ? null
-      : overrideCount === 1
-        ? translate(
-            'auto.components.settings.AgentTerminalThemes.override_count_one',
-            '1 override'
-          )
-        : translate(
-            'auto.components.settings.AgentTerminalThemes.override_count_other',
-            '{{value0}} overrides',
-            { value0: overrideCount }
-          )
+  const overrideSummary =
+    overrideCount === 0
+      ? null
+      : translate(
+          'auto.components.settings.AgentTerminalThemes.override_count',
+          '{{count}} overrides',
+          { count: overrideCount }
+        )

Add the matching _one and _other catalog entries for the new key, then run the localization catalog scripts.

Based on learnings: "do not rely on synthetic plugin<hex> IDs … provide the pack's declared locale so i18next can apply the correct CLDR plural rules, especially for languages such as Russian that require more than _one and _other forms."

Source: Learnings

src/renderer/src/components/settings/TerminalThemeSections.tsx (1)

221-226: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Show the Dark-slot hint only while Match dark mode is on.

The paragraph renders whenever the target is light. When the user turns Match dark mode off, agent overrides use the Light slot, so the hint no longer applies to the current state.

♻️ Proposed change
-                <p className="text-xs text-muted-foreground">
-                  {translate(
-                    'auto.components.settings.TerminalThemeSections.agent_themes_follow_dark',
-                    'Agent terminal themes follow the Dark slot while Match dark mode is on.'
-                  )}
-                </p>
+                {matchDarkMode ? (
+                  <p className="text-xs text-muted-foreground">
+                    {translate(
+                      'auto.components.settings.TerminalThemeSections.agent_themes_follow_dark',
+                      'Agent terminal themes follow the Dark slot while Match dark mode is on.'
+                    )}
+                  </p>
+                ) : null}

Note: the added test in TerminalThemeSections.lifecycle.test.ts renders with terminalUseSeparateLightTheme: false, so it still passes with this change.

src/renderer/src/components/terminal-pane/terminal-appearance.ts (1)

71-91: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consider memoizing the composed themes and the published snapshot.

applyTerminalAppearance runs on every settings change and on every pane creation. Each call rebuilds the global appearance, calls publishTerminalViewAttributesSnapshot, and then composes one theme per pane. buildTerminalViewAttributesSnapshot builds a 256-entry palette for the global scope and for each overridden agent, and publishComposedTerminalViewAttributesSnapshot serializes that whole push with JSON.stringify for its dedupe check. A tab that restores several panes repeats that work once per pane.

Two low-cost improvements:

  • Cache the composed pane theme per resolved agent inside one invocation, because panes that share an agent produce an identical theme.
  • Gate the snapshot publish on a (settings, systemPrefersDark) identity check so repeated calls with unchanged inputs skip the compose and the serialization.
♻️ Per-agent theme cache inside one invocation
   const terminalFontWeights = resolveTerminalFontWeights(settings.terminalFontWeight)
   const ligaturesEnabled = resolveTerminalLigaturesEnabled(
     settings.terminalLigatures,
     settings.terminalFontFamily
   )
+  // Why: panes that share an agent compose an identical theme; build each palette once per call.
+  const themeByAgent = new Map<TuiAgent | null, ReturnType<typeof composeActiveTerminalTheme>>()
+  const composeForPaneAgent = (
+    agent: TuiAgent | null
+  ): { theme: ReturnType<typeof composeActiveTerminalTheme>; mode: 'dark' | 'light' } => {
+    const paneAppearance = resolveEffectiveTerminalAppearance(settings, systemPrefersDark, agent)
+    if (!themeByAgent.has(agent)) {
+      themeByAgent.set(
+        agent,
+        composeActiveTerminalTheme(
+          paneAppearance.theme ?? getBuiltinTheme(paneAppearance.themeName),
+          settings
+        )
+      )
+    }
+    return { theme: themeByAgent.get(agent) ?? null, mode: paneAppearance.mode }
+  }
 
   for (const pane of manager.getPanes()) {
     const agent = resolvePaneThemeAgent(pane)
-    const paneAppearance = resolveEffectiveTerminalAppearance(settings, systemPrefersDark, agent)
-    const paneTheme = composeActiveTerminalTheme(
-      paneAppearance.theme ?? getBuiltinTheme(paneAppearance.themeName),
-      settings
-    )
+    const { theme: paneTheme, mode: paneMode } = composeForPaneAgent(agent)

Then read paneMode where paneAppearance.mode is used for the contrast ratio.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9497a75d-4ea2-477e-863d-31ce01941486

📥 Commits

Reviewing files that changed from the base of the PR and between 93334dc and 3014e393517fa60b22b66fa30acdea75513e523b.

📒 Files selected for processing (66)
  • src/main/ipc/pty.ts
  • src/main/ipc/settings.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/terminal-view-attribute-store.test.ts
  • src/main/runtime/terminal-view-attribute-store.ts
  • src/main/runtime/terminal-view-attributes-seed.test.ts
  • src/main/runtime/terminal-view-attributes-seed.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.theme.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/agent-terminal-preview-theme.ts
  • src/renderer/src/components/settings/AgentTerminalThemeRow.tsx
  • src/renderer/src/components/settings/AgentTerminalThemesSection.test.tsx
  • src/renderer/src/components/settings/AgentTerminalThemesSection.tsx
  • src/renderer/src/components/settings/AppearanceAdvancedDisclosure.tsx
  • src/renderer/src/components/settings/TerminalAppearanceSection.tsx
  • src/renderer/src/components/settings/TerminalThemePicker.tsx
  • src/renderer/src/components/settings/TerminalThemeSections.lifecycle.test.ts
  • src/renderer/src/components/settings/TerminalThemeSections.tsx
  • src/renderer/src/components/settings/agent-terminal-theme-options.ts
  • src/renderer/src/components/settings/agent-terminal-theme-rows.test.ts
  • src/renderer/src/components/settings/agent-terminal-theme-rows.ts
  • src/renderer/src/components/settings/agent-terminal-theme-search.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/renderer/src/components/settings/terminal-search.ts
  • src/renderer/src/components/settings/terminal-theme-search.ts
  • src/renderer/src/components/terminal-pane/pane-theme-identity.test.ts
  • src/renderer/src/components/terminal-pane/pane-theme-identity.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.test.ts
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-publisher.test.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-publisher.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-snapshot.test.ts
  • src/renderer/src/components/terminal-pane/terminal-view-attributes-snapshot.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/terminal-theme.test.ts
  • src/renderer/src/lib/terminal-theme.ts
  • src/renderer/src/lib/terminal-themes-data.ts
  • src/renderer/src/lib/terminal-themes/index.ts
  • src/renderer/src/store/slices/settings.ts
  • src/shared/agent-terminal-themes.test.ts
  • src/shared/agent-terminal-themes.ts
  • src/shared/compose-active-terminal-theme.test.ts
  • src/shared/compose-active-terminal-theme.ts
  • src/shared/constants.ts
  • src/shared/terminal-themes/classic.ts
  • src/shared/terminal-themes/defaults.ts
  • src/shared/terminal-themes/index.ts
  • src/shared/terminal-themes/popular-dark-core.ts
  • src/shared/terminal-themes/popular-dark-extended.ts
  • src/shared/terminal-themes/popular-dark.ts
  • src/shared/terminal-themes/popular-light.ts
  • src/shared/terminal-themes/shared.ts
  • src/shared/terminal-themes/types.ts
  • src/shared/terminal-view-attributes-composition.test.ts
  • src/shared/terminal-view-attributes-composition.ts
  • src/shared/terminal-view-attributes.test.ts
  • src/shared/terminal-view-attributes.ts
  • src/shared/types.ts

Comment thread src/main/ipc/pty.ts Outdated
Comment on lines 7464 to 7471
ipcMain.removeAllListeners('pty:terminalViewAttributes')
ipcMain.on('pty:terminalViewAttributes', (_event, args: unknown) => {
// Why validate-or-drop: a malformed palette gives a wrong color reply that breaks TUI theme detection worse than the silent-until-first-push default.
const attributes = validateTerminalViewAttributes(args)
if (attributes) {
setTerminalViewAttributes(attributes)
const push = validateTerminalViewAttributesPush(args)
if (push) {
commitTerminalViewAttributesSnapshot(push)
markRendererCommittedSnapshot()
}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Restrict this handler to the main window's webContents.

The handler ignores _event, so any webContents in the app can commit terminal view attributes. Two consequences follow:

  • commitTerminalViewAttributesSnapshot sets the colors that main uses to answer OSC 4/10/11 for hidden PTYs and to seed cold-start palettes, so a foreign sender can inject arbitrary colors into every PTY reply.
  • markRendererCommittedSnapshot records that the renderer owns the snapshot. The seed layer reads that flag, so one spoofed push suppresses the settings-derived seed for the rest of the session.

Sibling state-mutating handlers in this file already gate on the sender, for example pty:write (line 7175), pty:writeAccepted (line 7186), and pty:rendererDispatcherReady (line 7372). Apply the same guard here.

🔒️ Proposed fix
   ipcMain.removeAllListeners('pty:terminalViewAttributes')
-  ipcMain.on('pty:terminalViewAttributes', (_event, args: unknown) => {
+  ipcMain.on('pty:terminalViewAttributes', (event, args: unknown) => {
+    // Why: these attributes drive OSC color replies and suppress the main-process seed; only the owning window may commit them.
+    if (!isPtyWriteEventFromMainWindow(event, mainWindow.webContents)) {
+      return
+    }
     const push = validateTerminalViewAttributesPush(args)
     if (push) {
       commitTerminalViewAttributesSnapshot(push)
       markRendererCommittedSnapshot()
     }
   })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ipcMain.removeAllListeners('pty:terminalViewAttributes')
ipcMain.on('pty:terminalViewAttributes', (_event, args: unknown) => {
// Why validate-or-drop: a malformed palette gives a wrong color reply that breaks TUI theme detection worse than the silent-until-first-push default.
const attributes = validateTerminalViewAttributes(args)
if (attributes) {
setTerminalViewAttributes(attributes)
const push = validateTerminalViewAttributesPush(args)
if (push) {
commitTerminalViewAttributesSnapshot(push)
markRendererCommittedSnapshot()
}
})
ipcMain.removeAllListeners('pty:terminalViewAttributes')
ipcMain.on('pty:terminalViewAttributes', (event, args: unknown) => {
// Only the owning window may commit terminal view attributes.
if (!isPtyWriteEventFromMainWindow(event, mainWindow.webContents)) {
return
}
const push = validateTerminalViewAttributesPush(args)
if (push) {
commitTerminalViewAttributesSnapshot(push)
markRendererCommittedSnapshot()
}
})

Comment on lines +153 to +163
const theme = getNativeTheme()
if (nativeThemeSeedingInstalled || typeof theme?.on !== 'function') {
return
}
nativeThemeSeedingInstalled = true
theme.on('updated', () => {
if (hasRendererCommittedSnapshot()) {
return
}
seedTerminalViewAttributesFromSettings(getSettings(), readSystemPrefersDarkForSeed())
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Refresh the native-theme settings accessor.

Line 154 returns after the first installation. The registered listener retains that first getSettings closure. If another Store becomes active, a later native-theme update can seed attributes from the earlier profile.

Store the latest accessor on every call. Keep one listener that reads the current accessor.

Proposed fix
 let nativeThemeSeedingInstalled = false
+let nativeThemeSettingsAccessor: (() => SeedSettings) | null = null

 export function installTerminalViewAttributeNativeThemeSeeding(
   getSettings: () => SeedSettings
 ): void {
+  nativeThemeSettingsAccessor = getSettings
   const theme = getNativeTheme()
   if (nativeThemeSeedingInstalled || typeof theme?.on !== 'function') {
     return
@@
-    seedTerminalViewAttributesFromSettings(getSettings(), readSystemPrefersDarkForSeed())
+    const settings = nativeThemeSettingsAccessor
+    if (settings) {
+      seedTerminalViewAttributesFromSettings(settings(), readSystemPrefersDarkForSeed())
+    }
   })
 }

 export function _resetNativeThemeViewAttributeSeedingForTest(): void {
   nativeThemeSeedingInstalled = false
+  nativeThemeSettingsAccessor = null
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const theme = getNativeTheme()
if (nativeThemeSeedingInstalled || typeof theme?.on !== 'function') {
return
}
nativeThemeSeedingInstalled = true
theme.on('updated', () => {
if (hasRendererCommittedSnapshot()) {
return
}
seedTerminalViewAttributesFromSettings(getSettings(), readSystemPrefersDarkForSeed())
})
const theme = getNativeTheme()
if (nativeThemeSeedingInstalled || typeof theme?.on !== 'function') {
return
}
nativeThemeSeedingInstalled = true
theme.on('updated', () => {
if (hasRendererCommittedSnapshot()) {
return
}
const settings = nativeThemeSettingsAccessor
if (settings) {
seedTerminalViewAttributesFromSettings(settings(), readSystemPrefersDarkForSeed())
}
})

Comment on lines +33 to 45
/** Publishes a snapshot with empty byAgent so existing callers keep compiling. */
export function publishTerminalViewAttributes(
theme: ITheme | null,
mode: TerminalColorSchemeMode,
settings: Pick<GlobalSettings, 'terminalCursorStyle' | 'terminalCursorBlink'>,
send: (attributes: TerminalViewAttributes) => boolean = sendViaPreload
send: (attributes: TerminalViewAttributes) => boolean = sendLegacyAttributesViaPreload
): boolean {
const attributes = composeTerminalViewAttributes(theme, mode, settings)
const serialized = JSON.stringify(attributes)
if (serialized === lastPublishedSnapshot) {
return false
}
if (!send(attributes)) {
// Not recorded: a later call with a working bridge must still publish.
return false
}
lastPublishedSnapshot = serialized
return true
return publishComposedTerminalViewAttributesSnapshot(
{ kind: 'snapshot', global: attributes, byAgent: {} },
(push) => send(push.global)
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

The legacy wrapper can erase every per-agent override in the main-process store.

publishTerminalViewAttributes publishes { kind: 'snapshot', global, byAgent: {} } through publishComposedTerminalViewAttributesSnapshot, which shares lastPublishedSnapshot with the full-snapshot publisher. commitTerminalViewAttributesSnapshot in src/main/runtime/terminal-view-attribute-store.ts replaces the stored map with byAgent: { ...snapshot.byAgent }. A legacy publish that lands after a full snapshot therefore drops every agent override and fans the global attributes out to each agent scope. src/main/runtime/terminal-view-attribute-store.test.ts lines 90-94 pin that replacement behavior. If a full snapshot follows, the overrides come back, so agent-scoped PTYs receive an OSC color flap.

Confirm whether any production caller still uses this wrapper. If one remains, either route it through buildTerminalViewAttributesSnapshot so it carries the agent map, or give the legacy path its own dedupe state and a store commit that leaves byAgent untouched.

#!/bin/bash
# Description: Find non-test callers of the legacy global-only publisher.
set -euo pipefail

rg -nP --type=ts --type=tsx '\bpublishTerminalViewAttributes\s*\(' -g '!**/*.test.ts' -g '!**/*.test.tsx' src

Comment on lines +48 to +52
if (settings.terminalBackgroundOpacity !== undefined && theme.background) {
theme = {
...theme,
background: hexToRgba(theme.background, settings.terminalBackgroundOpacity)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Guard non-hex backgrounds before opacity conversion.

If theme.background is rgb(...), rgba(...), or a named color, hexToRgba creates invalid CSS with NaN channels. Preserve non-hex backgrounds, or parse their CSS form before applying opacity.

Proposed fix
-  if (settings.terminalBackgroundOpacity !== undefined && theme.background) {
+  if (
+    settings.terminalBackgroundOpacity !== undefined &&
+    theme.background &&
+    isHexColor(theme.background)
+  ) {

@edenaion
edenaion force-pushed the feat/per-agent-terminal-themes branch from 3014e39 to ff273b0 Compare August 13, 2026 16:24
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@edenaion

Copy link
Copy Markdown
Author

Hi just checking in

Each agent can override the terminal theme (for example a cream theme for
Claude and Dracula for Codex). Every agent defaults to inheriting the
global theme, behind a collapsed disclosure in Appearance.

Ported onto main's owner-answered color replies:

☼ The PTY owner (main process, daemon, relay) keeps answering OSC 10/11
from one host-wide color, now with an optional per-agent map. The
startup intent carries launchAgent, so an agent pane answers with its
agent's colors. Older owners ignore both optional fields and answer
globally.

☼ The renderer pushes one atomic {global, byAgent} view-attribute
snapshot. Main fans it out per effective scope, so an identical re-push
or an unchanged inherit leaves live OSC color overlays alone.

☼ Per-agent seeds from saved settings answer OSC 10/11 before the first
renderer push. The hidden-pane OSC 4/12 responder still waits for that
push, as it does for the global palette.

☼ Settings normalization covers agentTerminalThemes on load, on update
and over the settings IPC.

☼ Reuses main's shared theme catalog and theme selection; the agent
argument is optional everywhere.
@edenaion
edenaion force-pushed the feat/per-agent-terminal-themes branch from ff273b0 to d841ff7 Compare October 11, 2026 15:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-agent terminal theme overrides in Settings → Appearance

4 participants