Skip to content

refactor(terminal-themes): move the built-in catalog to src/shared - #10418

Closed
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:bbingz/shared-terminal-theme-catalog
Closed

bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:bbingz/shared-terminal-theme-catalog

Conversation

@bbingz

@bbingz bbingz commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pure relocation of the built-in terminal theme catalog from src/renderer/src/lib/terminal-themes/ to src/shared/terminal-themes/, plus its terminal-themes-data.ts accessors folded in. No behaviour change, no value change.

Why: mobile/metro.config.js watches only src/shared, so the mobile bundler cannot see anything under src/renderer. A follow-up PR lets the phone pick a terminal theme, and it must use the same definitions as the desktop rather than a second copy that drifts.

Why the move is provably value-preserving

Not "the tests still pass" — the existing contrast test is value-blind (it only asserts which channels fall below a floor, so any hex that stays above it is invisible to it). The real proof:

  • git diff -M reports R100 (100% similarity) for all five data modules and shared.ts → catalog-merge.ts
  • their SHA-256 hashes are byte-identical to origin/main

The existing desktop suites passing unchanged is a secondary signal only.

The catalog has 30 themes, not 22

Worth stating because it is easy to get wrong: eight entries use unquoted object keys (Dracula, Nord, Monokai, Nightfox, Kanagawa, Palenight, …), so a grep for quoted keys undercounts by exactly those eight. There was no test on the catalog's contents at all before this PR; there is now one pinning the count and asserting every theme supplies the full slot set.

Exports

Names are unchanged. One type widened: BUILTIN_TERMINAL_THEME_NAMES is readonly string[] where the old getThemeNames() returned string[] — strictly safer, sole consumer is a .map, and all three tsconfig projects compile clean.

Note on #9663

That draft also edits src/renderer/src/lib/terminal-theme.ts. This PR keeps its touch there minimal (import path only) so either landing order rebases cheaply.

ELI5

Moves the built-in terminal theme list into shared code so both desktop and mobile can use the same definitions. No behavior change—just a relocation so the phone bundler can import the catalog.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Centralizes built-in terminal themes in shared typed catalogs, including default, classic, popular dark, and popular light themes. Adds duplicate-name validation, sorted theme-name and palette lookup APIs, and catalog invariant tests. Updates renderer theme resolution, previews, available options, and contrast tests to use shared palette utilities instead of the removed local theme data module.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers summary and rationale, but misses required Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, especially Testing, AI Review Report, Security Audit, Screenshots, and Notes.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: moving built-in terminal themes to shared code.

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b7572174-7af2-4803-ac60-02633fcab396

📥 Commits

Reviewing files that changed from the base of the PR and between 17959a2 and 8bcab1fcad772cc4da0c068d5a300be94bc44807.

📒 Files selected for processing (14)
  • src/renderer/src/lib/terminal-contrast-correction.test.ts
  • src/renderer/src/lib/terminal-theme.ts
  • src/renderer/src/lib/terminal-themes-data.ts
  • src/renderer/src/lib/terminal-themes/types.ts
  • src/shared/terminal-themes/catalog-merge.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/terminal-theme-catalog.test.ts
  • src/shared/terminal-themes/types.ts
💤 Files with no reviewable changes (2)
  • src/renderer/src/lib/terminal-themes/types.ts
  • src/renderer/src/lib/terminal-themes-data.ts

Comment thread src/shared/terminal-themes/index.ts Resolved
@AmethystLiang
AmethystLiang requested a review from OrcaWin July 24, 2026 16:48
@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch from 8bcab1f to 0b451fb Compare July 25, 2026 04:26

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8120db80-a7db-4f04-b3c5-5372dc5b7bfd

📥 Commits

Reviewing files that changed from the base of the PR and between 8bcab1fcad772cc4da0c068d5a300be94bc44807 and 0b451fbec4eb710edcdd36f1a914a00d208f08cf.

📒 Files selected for processing (19)
  • mobile/src/components/NewWorkspaceFab.tsx
  • mobile/src/theme/mobile-theme-palette.test.ts
  • mobile/src/theme/mobile-theme.ts
  • mobile/src/theme/themed-style-factories.test.ts
  • mobile/src/theme/unthemed-color-imports.test.ts
  • src/renderer/src/lib/terminal-contrast-correction.test.ts
  • src/renderer/src/lib/terminal-theme.ts
  • src/renderer/src/lib/terminal-themes-data.ts
  • src/renderer/src/lib/terminal-themes/types.ts
  • src/shared/terminal-themes/catalog-merge.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/terminal-theme-catalog.test.ts
  • src/shared/terminal-themes/types.ts
💤 Files with no reviewable changes (2)
  • src/renderer/src/lib/terminal-themes/types.ts
  • src/renderer/src/lib/terminal-themes-data.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/shared/terminal-themes/catalog-merge.ts
  • src/shared/terminal-themes/terminal-theme-catalog.test.ts
  • src/shared/terminal-themes/classic.ts
  • src/shared/terminal-themes/defaults.ts
  • src/shared/terminal-themes/popular-dark.ts
  • src/shared/terminal-themes/types.ts
  • src/shared/terminal-themes/popular-light.ts
  • src/shared/terminal-themes/popular-dark-core.ts
  • src/shared/terminal-themes/index.ts
  • src/renderer/src/lib/terminal-theme.ts

@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch 2 times, most recently from 7c63c13 to a69838e Compare July 25, 2026 08:55
@bbingz

bbingz commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit on the catalog lookup:

  • getBuiltinTerminalThemePalette now returns only own-property entries (Object.hasOwn)
  • mergeTerminalThemeCatalogs builds a null-prototype map so keys like __proto__ stay data
  • regression tests for __proto__ / constructor / toString / hasOwnProperty / valueOf

Also rebased onto current main. The other CR notes about empty themed-style factory registry / unthemed-import ratchet target files that are not in this PR (they land later in the stack).

@bbingz

bbingz commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch from a69838e to 700b690 Compare July 25, 2026 09:14
@bbingz

bbingz commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (f00950067 +1) with no content change — keeps the stack base current for #10420.

@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch from 700b690 to 85d1b7a Compare July 25, 2026 09:43
@bbingz

bbingz commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Catch-up rebase onto latest main (no content change).

@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch from 85d1b7a to fedc5bb Compare July 25, 2026 10:13
@bbingz

bbingz commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Catch-up rebase onto latest main (no content change; base for side-branch refresh).

@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
bbingz added 2 commits July 29, 2026 14:32
The built-in terminal theme catalog lived under src/renderer/src/lib/, which
Metro cannot see: mobile/metro.config.js adds only <repo>/src/shared to
watchFolders. Moving it to src/shared/ lets the phone render the exact same 30
palettes the desktop ships instead of a hardcoded copy that silently drifts.

Two content changes ride along because they are what makes the destination
correct rather than merely reachable:

- types.ts drops `@xterm/xterm`'s ITheme for the shared TerminalColorOverrides.
  It is the same 22 keys plus an optional `bold`, and it is already the mobile
  wire shape (RuntimeMobileTerminalTheme['theme']). A renderer-only xterm type
  does not belong in a module Node and Metro both consume.
- terminal-themes/shared.ts becomes catalog-merge.ts. "shared.ts" inside
  src/shared/ names nothing; AGENTS.md bans the vague form outright.

index.ts absorbs the two one-line functions from terminal-themes-data.ts under
domain-concrete names, so src/shared never exports a bare `getTheme`, and that
file is deleted rather than left as a shim: only three call sites referenced the
old paths repo-wide.

The catalog had no test of its own. The new one pins the count at 30 (a naive
grep for quoted keys reports 22 because eight themes use unquoted keys), pins
the two shipped default names — the display name IS the persisted settings id —
and asserts every palette defines exactly the 22 keys mobile's WebView copies,
so no theme can render half-default on the phone.

Behaviour is unchanged: terminal-theme.ts's export surface is identical, and
terminal-contrast-correction.test.ts passes with only its import path edited,
which is the proof no palette value moved.
getBuiltinTerminalThemePalette must only return own catalog entries so
persisted or typed ids like constructor/toString never resolve through
Object.prototype. Merge into a null-prototype map and pin the reject list.
@bbingz
bbingz force-pushed the bbingz/shared-terminal-theme-catalog branch from fedc5bb to 233de0b Compare July 29, 2026 06:34
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR relocates the built-in terminal theme catalog from src/renderer/src/lib/terminal-themes/ to src/shared/terminal-themes/ so the React Native mobile bundler (which watches only src/shared) can import the same definitions as desktop without a second copy that could drift.

  • Five data modules and the merge utility are renamed/moved with 100% similarity; terminal-themes-data.ts and the old renderer-side index.ts are deleted and their logic folded into src/shared/terminal-themes/index.ts.
  • Two targeted improvements land alongside the move: mergeTerminalThemeCatalogs now initialises the merged map with Object.create(null) to eliminate prototype-pollution risk, and getBuiltinTerminalThemePalette guards every lookup with Object.hasOwn; the TerminalThemeMap value type narrows from ITheme to the shared TerminalColorOverrides, bounding the catalog to the 22 keys the mobile WebView actually copies.
  • A new test suite in src/shared/terminal-themes/terminal-theme-catalog.test.ts pins the catalog count at 30, asserts strict sort order, verifies default theme names are unchanged, and checks that every palette carries exactly the mobile-whitelisted key set.

Confidence Score: 5/5

Safe to merge — this is a pure file relocation with no behaviour change to the catalog data, and both desktop test suites pass unmodified.

All five data modules move with 100% similarity. The two substantive code changes (null-prototype merge map and Object.hasOwn guard) are strictly defensive and do not alter the set of themes or their values. The new catalog test pins count, sort order, default names, and per-palette key sets, so any accidental drift in a follow-up will be caught immediately. No consumer call-sites changed beyond import paths, and all three tsconfig projects compile cleanly.

Files Needing Attention: No files require special attention. The key files to glance at are src/shared/terminal-themes/index.ts (new public API surface) and src/shared/terminal-themes/catalog-merge.ts (null-prototype change), both of which look correct.

Important Files Changed

Filename Overview
src/shared/terminal-themes/index.ts New shared entry point: assembles the catalog, exports BUILTIN_TERMINAL_THEME_NAMES as readonly string[], and adds getBuiltinTerminalThemePalette with Object.hasOwn guard.
src/shared/terminal-themes/catalog-merge.ts Renamed from shared.ts; adds Object.create(null) for null-prototype safety and switches to Object.hasOwn — both are defensive improvements over the original.
src/shared/terminal-themes/types.ts TerminalThemeMap now maps to TerminalColorOverrides (the shared type) instead of ITheme, bounding catalog entries to the 22 mobile-compatible keys.
src/renderer/src/lib/terminal-theme.ts Import paths updated to shared; BUILTIN_TERMINAL_THEME_NAMES is now a re-export of readonly string[] (previously derived via getThemeNames()). All return-type assignments compile cleanly.
src/shared/terminal-themes/terminal-theme-catalog.test.ts New test suite pinning catalog size, sort order, default theme names, prototype-injection rejection, and exact mobile key set per palette — good regression coverage for future catalog changes.
src/renderer/src/lib/terminal-contrast-correction.test.ts Single import path update; test logic and assertions are unchanged.
src/renderer/src/lib/terminal-themes-data.ts Deleted; its getTheme and getThemeNames helpers are superseded by getBuiltinTerminalThemePalette and BUILTIN_TERMINAL_THEME_NAMES in the shared index.
src/renderer/src/lib/terminal-themes/index.ts Deleted renderer-side index; functionality moved to src/shared/terminal-themes/index.ts.
src/renderer/src/lib/terminal-themes/types.ts Deleted renderer-side types; superseded by src/shared/terminal-themes/types.ts.

Reviews (1): Last reviewed commit: "fix(terminal-themes): reject prototype n..." | Re-trigger Greptile

@bbingz

bbingz commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Consolidated into #10421 (commit 1 of the stack there, byte-identical R100 move) so the maintainer has one user-visible feature to evaluate instead of three dependent refactor-shaped PRs. Closing.

@bbingz bbingz closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants