Skip to content

fix(ghostty): import palette indexes in supported numeric bases - #50546

Closed
Afloat16 wants to merge 1 commit into
stablyai:mainfrom
Afloat16:afloat16/orca50-20261127-ghostty-palette-indexes
Closed

Afloat16 wants to merge 1 commit into
stablyai:mainfrom
Afloat16:afloat16/orca50-20261127-ghostty-palette-indexes

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

ELI5

Import Ghostty palette colors into their intended slots.

What Changed

Parse the documented decimal, hexadecimal, octal and binary palette-index syntax as whole values, then keep the existing range and ANSI-color mapping. Invalid suffixes no longer overwrite a valid earlier color.

Why

Ghostty supports decimal, hexadecimal, octal, and binary palette indexes. The importer parsed every 0x/0o/0b index as zero, overwriting black and leaving the intended ANSI colors unset. It also accepted invalid trailing characters as a valid index.

src/main/ghostty/index.ts imports terminal config and themes through mapGhosttyConfig.

Linked Issue

Fixes #50545

Visual Proof

N/A — no graphical layout or interaction change; data-level evidence follows.

Before/after data-level reproduction of the same input:

Before After
Both regressions failed on main: supported indexes collapsed onto black, and 1wrong overwrote red. Documented numeric bases map to red/green/yellow/blue, invalid trailing characters do not override valid earlier colors; 2 tests passed.

No graphical layout change is included. The evidence above is from the production operation; no desktop screenshot is claimed.

Testing

  • I manually tested these changes locally through the production-entry reproduction described above
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Parser data integrity and accounting; production parser baseline reproduced

node config/scripts/test-runtime/execution-policy/run-vitest.mjs run --config config/vitest.config.ts src/main/ghostty/palette-index-import.test.ts

Locally exercised on Linux with Node 24.22.3. External API cases use protocol fixtures; no live provider account, graphical desktop, macOS, Windows or remote SSH execution is claimed.

Changed-code quality passed with zero findings. Node typecheck passed (17,005 files); web typecheck passed (16,094 files). The integrated regression run passed 51 tests in 30 files; the Drive performance contract passed separately. The final three test typing changes were rerun and passed. These are aggregate first-batch results, not per-PR test counts.

The required pnpm check:changed --base=9890ea181c0f9ae59fb82da64c4a6fbc0504a817 was attempted after final edits. It stopped in the workspace-package build because this environment rejects the tsx CLI's local IPC socket (listen EPERM). The full gate/build is therefore not claimed to pass; CI remains required. The process-host build entry executed successfully using node --import tsx --conditions=orca-source.

Performance

Only documented numeric syntax and 0..255 indexes are accepted. Only the existing ANSI 0..15 mappings are applied. No I/O or allocations proportional to terminal contents.

Risk

Level: Low

Only documented numeric syntax and 0..255 indexes are accepted. Only the existing ANSI 0..15 mappings are applied. No I/O or allocations proportional to terminal contents.

A plain revert restores the previous behavior; no schema migration is introduced.

AI Disclosure

Core contribution owner: @Afloat16. Required tooling disclosure: GPT-6 Astra Pro was used for implementation and review.

Review

Reviewed the production caller, baseline failure, ordinary controls, data integrity and additional work. No new shell commands, path grammar, remote protocol fields, polling or UI layout were introduced. SSH/remote, mobile and agent integrations retain their existing entry points.

Agent skill upstream boundary

  • Not applicable: this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments or documentation.

Notes

Primary references:

Related work checked for distinct scope:

Checklist

  • This PR is small and focused
  • I explained what changed and why, including the mechanism and before/after result
  • I stated the risk and how to back it out
  • Before/after data evidence is included; no graphical layout change
  • Self-reviewed for correctness, security and performance
  • Cross-platform, SSH/remote and path/shortcut impact considered
  • Full lint/typecheck/test/build gate: component results and local IPC limitation are recorded above; CI still needs to cover the complete gate

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The Ghostty palette importer now accepts decimal, hexadecimal, octal, and binary indices as whole values and rejects invalid or out-of-range indices. Tests cover mapping supported indices to ANSI color slots and preventing malformed input from replacing a valid decimal-index override.

Severity of issue fixed: Low

Merge Risk: Low · up to f8ca0

Ghostty palette imports now ignore plus-prefixed indices such as +1, which were previously imported. This is a rare edge case and the import falls back safely, so the risk is low. Handle the leading + before merging, or accept the narrow regression.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: palette indexes in Ghostty imports are now parsed in the supported numeric bases. The raw summary confirms the mapper now validates decimal, 0x, 0o and 0b indices. The…
Description check Passed The description follows the template and covers the main sections: ELI5, What Changed, Why, Linked Issue (Fixes #50545), Visual Proof (N/A with reason), Testing, Performance, Risk with level, AI Discl…
Linked Issues check Passed Issue #50545 requires that Ghostty decimal, 0x, 0o, and 0b palette indices map to their ANSI slots, and that an invalid suffix such as 1wrong does not overwrite an earlier valid entry. The diff in src…
Out of Scope Changes check Passed The whole-PR diff against merge base 9890ea1 changes two files. src/main/ghostty/mapper.ts contains only the palette index parsing change, with the ANSI index mapping …
Full details: Title check

Explanation

The title names the main change: palette indexes in Ghostty imports are now parsed in the supported numeric bases. The raw summary confirms the mapper now validates decimal, 0x, 0o and 0b indices. The fix prefix and the scope in parentheses are clear. The title is specific and does not use vague terms.

Full details: Description check

Explanation

The description follows the template and covers the main sections: ELI5, What Changed, Why, Linked Issue (Fixes #50545), Visual Proof (N/A with reason), Testing, Performance, Risk with level, AI Disclosure, Review, upstream boundary, and Checklist. The What Changed and Why sections explain the before and after and the mechanism. The Testing section records the test command and the local environment, and it states which platforms were not tested. The description also records that the full pnpm check:changed gate did not complete locally, and CI must cover it. The Visual Proof section is a data-level table instead of a before/after visual, which the template accepts when no UI changes. Two items are weak: the Testing checklist entry for the 'fails without this change' anti-pattern check is ticked without a clear per-test demonstration, and the 'Full lint/typecheck/test/build gate' checkbox is left unchecked. The Visual Proof table is also oddly worded (for example 'Both regressions failed on main'). The description also has a stray line about src/main/ghostty/index.ts that is not explained under What Changed. These gaps are minor and do not make the description incomplete, so the check passes.

Full details: Linked Issues check

Explanation

Issue #50545 requires that Ghostty decimal, 0x, 0o, and 0b palette indices map to their ANSI slots, and that an invalid suffix such as 1wrong does not overwrite an earlier valid entry. The diff in src/main/ghostty/mapper.ts replaces Number.parseInt(idxStr, 10) with a whole-value check. The check accepts /^(?:\d+|0x[\da-f]+|0o[0-7]+|0b[01]+)$/i and converts with Number. Non-integers and indices above 255 are skipped. A malformed index now yields NaN and is skipped, so it no longer overwrites red. The added tests in src/main/ghostty/palette-index-import.test.ts cover 0x1 (red), 0b10 (green), 0o3 (yellow), and decimal 4 (blue). They also cover 1wrong not overriding 1=#112233. The code matches the issue requirements. The test results were reported by the author and were not re-run in this review.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against merge base 9890ea1 changes two files. src/main/ghostty/mapper.ts contains only the palette index parsing change, with the ANSI index mapping and color validation kept. src/main/ghostty/palette-index-import.test.ts contains only regression tests for that change. The related issues #7126, #37292, and #42678 are listed as scope references only and are not implemented here. No unrelated change was found in the inspected evidence.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f51ed64-fb02-4ca7-8ac3-5fdbbe476d75
Commits

Reviewing files that changed from the base of the PR and between f7eb7be and f8ca09d.

Files selected for processing: 2

  • src/main/ghostty/mapper.ts
  • src/main/ghostty/palette-index-import.test.ts

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

const index = Number.parseInt(idxStr, 10)
if (Number.isNaN(index) || !HEX_COLOR_RE.test(color)) {
// Ghostty accepts decimal and 0x/0o/0b indices; parseInt(..., 10) maps each prefix to black.
const index = /^(?:\d+|0x[\da-f]+|0o[0-7]+|0b[01]+)$/i.test(idxStr)

@coderabbitai coderabbitai Bot Nov 27, 2026 •

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.

Minor · Functional Correctness · Quick win

Preserve valid plus-prefixed palette indices.

Ghostty 1.2.3 parses palette indices with Zig’s parseInt, which accepts a leading +. (raw.githubusercontent.com)

For palette = +1=#112233, the previous decimal parseInt conversion produced index 1. (tc39.es) The new regex rejects +1, so the supplied mapper drops the red override.

Remove an optional leading + before validation and conversion. Keep whole-value validation so 1wrong remains invalid. Add a regression assertion for +1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ff11078. The importer now preserves a leading plus sign in decimal and radix-prefixed indices, signed zero, and interior digit separators supported by Ghostty’s Zig parser. It still rejects malformed whole values such as 1wrong, 0x_1, 1_, and 0_x1.

The new compatibility case failed against the previous commit; all three palette tests now pass. I also saw the follow-up in #50608; this records the corresponding compatibility fix on the original branch.

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.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Revision ---'
git rev-parse HEAD
git show --no-patch --format='%H %s' ff110780bde874cc04541bf99c787774e89c6b66 2>&1 || true
if git merge-base --is-ancestor ff110780bde874cc04541bf99c787774e89c6b66 HEAD 2>/dev/null; then echo 'Reported commit is an ancestor of HEAD'; else echo 'Reported commit is not confirmed as an ancestor of HEAD'; fi
printf '%s\n' '--- Mapper outline ---'
ast-grep outline src/main/ghostty/mapper.ts --items all 2>&1 | head -100
printf '%s\n' '--- Mapper parser and palette ---'
cat -n src/main/ghostty/mapper.ts | sed -n '1,175p'
printf '%s\n' '--- Palette test outline ---'
ast-grep outline src/main/ghostty/palette-index-import.test.ts --items all 2>&1 | head -100
printf '%s\n' '--- Palette tests ---'
cat -n src/main/ghostty/palette-index-import.test.ts | sed -n '1,220p'
printf '%s\n' '--- Repository instruction file names ---'
fd -H -t f '^(AGENTS\.md|CLAUDE\.md)$' . -E node_modules -E .git | head -80

Length of output: 10362


Script executed:

#!/bin/bash
set -u
fix=ff110780bde874cc04541bf99c787774e89c6b66
printf '%s\n' '--- Repository instructions ---'
cat -n AGENTS.md | sed -n '1,220p'
printf '%s\n' '--- Reported fix diff ---'
git show --format=fuller --stat "$fix"
git show --format= "$fix" -- src/main/ghostty/mapper.ts src/main/ghostty/palette-index-import.test.ts
printf '%s\n' '--- Commit ancestry ---'
if git merge-base --is-ancestor f8ca09d1f791b8057ad917c25349d96dfd7409f6 "$fix"; then echo 'Original review commit is an ancestor of the reported fix'; else echo 'Original review commit is not confirmed as an ancestor of the reported fix'; fi
printf '%s\n' '--- Current pull request metadata ---'
if metadata=$(gh api repos/stablyai/orca/pulls/50546 --jq '{state, merged, head_sha: .head.sha, head_ref: .head.ref}' 2>&1); then
  printf '%s\n' "$metadata"
  head_sha=$(printf '%s\n' "$metadata" | jq -r '.head_sha')
  if git cat-file -e "$head_sha^{commit}" 2>/dev/null; then
    if git merge-base --is-ancestor "$fix" "$head_sha"; then echo 'Reported fix is an ancestor of the current pull request head'; else echo 'Reported fix is not an ancestor of the current pull request head'; fi
    printf '%s\n' '--- Current pull request head palette index lines ---'
    git show "$head_sha:src/main/ghostty/mapper.ts" | cat -n | sed -n '1,70p;120,170p'
  else
    echo 'Current pull request head is not available in the local checkout'
  fi
else
  printf 'Could not retrieve pull request metadata: %s\n' "$metadata"
fi

Length of output: 15685


@Afloat16, commit ff11078 accepts +1 and adds a regression test. I did not run the tests.

As of my check, #50546 is closed without merging. Its head is still f8ca09d, which rejects +1; ff11078 is not in that head. I am not marking the finding addressed for this PR.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @Afloat16 for finding and fixing this! We needed a couple of follow-ups (keeping +/-0 signs and _ digit separators the way Ghostty parses them) and couldn't push to your branch, so we're landing it in #50608. Your authorship is kept via a Co-authored-by trailer.

@nwparker nwparker closed this Nov 27, 2026
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.

[Bug]: Ghostty hexadecimal, octal and binary palette indexes map to black

2 participants