Skip to content

feat(ghostty): resolve theme references during config import - #7126

Merged
Jinwoo-H merged 3 commits into
stablyai:mainfrom
huhuhulululu:feat/ghostty-import-theme-references
Jul 4, 2026
Merged

Jinwoo-H merged 3 commits into
stablyai:mainfrom
huhuhulululu:feat/ghostty-import-theme-references

Conversation

@huhuhulululu

Copy link
Copy Markdown
Contributor

Summary

theme = <name> is the most common way Ghostty configs pick their colors, but the importer currently treats the key as unsupported — so for a config like:

theme = Tomorrow Night Bright
font-size = 13.5

the import silently drops the entire palette and only the font settings survive. This PR resolves the referenced theme file and merges its colors into the import, mirroring Ghostty's own precedence.

How it works

  • New theme-resolution.ts searches themes in Ghostty's lookup order: user themes ($XDG_CONFIG_HOME/ghostty/themes or ~/.config/ghostty/themes, plus the native macOS app-support dir) shadow the bundled themes inside the Ghostty install (Ghostty.app/Contents/Resources/ghostty/themes on macOS, /usr/share/ghostty/themes + /usr/local/share/ghostty/themes on Linux). Theme files are plain config subsets, so the existing parseGhosttyConfig parses them as-is.
  • Merge semantics match Ghostty: theme colors act as defaults — explicit config keys win, and config palette entries are appended after the theme's so per-index overrides apply naturally through the existing mapper.
  • Safety rails: theme names containing path separators are rejected (no directory traversal from a crafted config), files over 256 KB are ignored, and a whitelist ensures only color-bearing keys can flow from a theme into the import — a theme file can't smuggle font/window settings past the user's config.
  • Graceful degradation: unresolvable names surface as theme (theme file not found) and light:X,dark:Y pairs as theme (light:/dark: pairs not supported) in unsupportedKeys, instead of vanishing silently.

Test plan

  • 12 new tests: search-dir order (XDG override, macOS fallthrough), first-match-wins resolution, non-color key filtering, not-found, traversal rejection, size cap, end-to-end import with theme + config override semantics, annotated unsupported keys
  • vitest run src/main/ghostty/ — 125/125 pass
  • oxlint and tsgo --noEmit -p config/tsconfig.node.json clean
  • Verified against a real-world config using theme = Tomorrow Night Bright (palette previously lost entirely on import)

Related: #7125 (adjust-cell-height / dual-value paddings — independent branches, no overlap)

`theme = <name>` is how most Ghostty configs pick their colors, but the
importer treated the key as unsupported and silently dropped the entire
palette. Resolve the referenced theme file and merge its colors as
defaults, mirroring Ghostty's own precedence:

- Search user themes first (XDG, then the native macOS dir), then the
  bundled themes inside the Ghostty install, and parse the file with the
  existing parseGhosttyConfig (theme files are plain config subsets).
- Explicit config keys win over theme values; config palette entries are
  appended after the theme's so per-index overrides apply naturally.
- Only color-bearing keys may flow from a theme into the import, a theme
  file cannot smuggle font/window settings past the user's config.
- Theme names containing path separators are rejected (no traversal),
  files over 256 KB are ignored, and light:/dark: pairs plus unresolvable
  names surface as annotated unsupportedKeys instead of vanishing.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 429c96c4-8428-477f-af3b-3b9ecf18725d

📥 Commits

Reviewing files that changed from the base of the PR and between d362a6a and 3728d27.

📒 Files selected for processing (2)
  • src/main/ghostty/theme-import.test.ts
  • src/renderer/src/components/settings/AccountsPane.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/ghostty/theme-import.test.ts

📝 Walkthrough

Walkthrough

Changes

This change adds Ghostty theme reference support. A new module discovers theme search directories with platform-specific and environment-based overrides, then resolves theme files into a whitelisted set of color keys with size and path safety checks. Ghostty config preview now applies theme = <name> references before ORCA mapping, including handling for unsupported light:/dark: pairs and missing theme files. Tests cover directory resolution, color extraction, import preview behavior, and one AccountsPane Spanish assertion update.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning It covers summary and testing, but omits required template sections for screenshots, AI review report, security audit, and notes. Add the missing sections with screenshots or no visual change, AI review findings, a security audit summary, and any platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: resolving Ghostty theme references during config import.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@Jinwoo-H Jinwoo-H 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.

Thanks, this is a good fix. I added one maintainer follow-up before landing:

  • aligned theme resolution with Ghostty lookup details: absolute paths, GHOSTTY_RESOURCES_DIR, and invalid user-theme shadowing
  • split focused theme import coverage out of the general importer test
  • verified the Electron Settings import flow end to end

Validated with Ghostty unit tests, typecheck, integration lint on current main, and Electron e2e coverage for preview/apply/persisted settings.

@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: 1

🧹 Nitpick comments (1)
src/main/ghostty/theme-resolution.ts (1)

97-120: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Undocumented "no fallthrough on invalid" behavior — verify against Ghostty semantics.

When a relative-name candidate resolves to a path that exists but is invalid (not a regular file, or oversized), the loop returns null immediately instead of continuing to probe the remaining search directories (Line 115-117). This "shadowing" behavior is intentional per the test suite, but it's a subtle design choice with no inline explanation, and it's unclear whether this matches real Ghostty's fallback semantics when a named theme candidate exists but can't be read (e.g., a directory or file-system error) — Ghostty's own file-open logic might simply move on to the next search directory in that case.

As per coding guidelines, **/*.{ts,tsx,js,jsx}: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

📝 Suggested comment
     if (result.status === 'invalid') {
+      // Why: an invalid match "shadows" later search dirs — we don't want to
+      // silently fall back to a bundled theme when the user's named theme
+      // exists but is unreadable/oversized.
       return null
     }

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c1da576b-e52f-4f7e-9824-1c398f0e9390

📥 Commits

Reviewing files that changed from the base of the PR and between 290a027 and d362a6a.

📒 Files selected for processing (4)
  • src/main/ghostty/index.ts
  • src/main/ghostty/theme-import.test.ts
  • src/main/ghostty/theme-resolution.test.ts
  • src/main/ghostty/theme-resolution.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/ghostty/index.ts

Comment thread src/main/ghostty/theme-import.test.ts Resolved
@Jinwoo-H
Jinwoo-H merged commit a81b82f into stablyai:main Jul 4, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#7126)

* feat(ghostty): resolve theme references during config import

`theme = <name>` is how most Ghostty configs pick their colors, but the
importer treated the key as unsupported and silently dropped the entire
palette. Resolve the referenced theme file and merge its colors as
defaults, mirroring Ghostty's own precedence:

- Search user themes first (XDG, then the native macOS dir), then the
  bundled themes inside the Ghostty install, and parse the file with the
  existing parseGhosttyConfig (theme files are plain config subsets).
- Explicit config keys win over theme values; config palette entries are
  appended after the theme's so per-index overrides apply naturally.
- Only color-bearing keys may flow from a theme into the import, a theme
  file cannot smuggle font/window settings past the user's config.
- Theme names containing path separators are rejected (no traversal),
  files over 256 KB are ignored, and light:/dark: pairs plus unresolvable
  names surface as annotated unsupportedKeys instead of vanishing.

* fix(ghostty): align theme resolution with Ghostty lookup

Co-authored-by: Orca <[email protected]>

* test: stabilize ghostty import CI coverage

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinwoo-H <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

2 participants