Skip to content

Fix Ghostty shell integration and surface background ordering#31

Merged
trydis merged 2 commits intomainfrom
fix/ghostty-shell-integration
Mar 17, 2026
Merged

Fix Ghostty shell integration and surface background ordering#31
trydis merged 2 commits intomainfrom
fix/ghostty-shell-integration

Conversation

@trydis
Copy link
Owner

@trydis trydis commented Mar 17, 2026

Source ghostty-integration from the zshrc shim so shell-integration features (title, CWD, marks) work inside Shellraiser-managed surfaces. Move surface background styling after Ghostty surface registration to ensure correct render ordering. Update tests accordingly.

Summary by CodeRabbit

  • New Features

    • Added automatic sourcing of Ghostty shell integration during shell initialization.
    • Build scripts now synchronize Ghostty resources into app bundles and provide a new run-isolated target to launch an isolated app with the proper environment.
  • Bug Fixes

    • Improved shell command execution handling to leverage native shell integration capabilities.
  • Tests

    • Added verification for Ghostty integration sourcing in shell configuration.
    • Updated tests to reflect corrected shell command execution behavior.

Source ghostty-integration from the zshrc shim so shell-integration
features (title, CWD, marks) work inside Shellraiser-managed surfaces.
Move surface background styling after Ghostty surface registration to
ensure correct render ordering. Update tests accordingly.
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

The PR adds Ghostty resource sync steps to builds, updates zsh RC shims to conditionally source Ghostty integration, removes shell-wrapper wrapping from Ghostty launch commands, and adjusts Metal layer/background styling initialization in the Ghostty surface view. Tests updated/added accordingly.

Changes

Cohort / File(s) Summary
Build Configuration
Makefile
Adds resource synchronization to build-app and build-isolated: verify ghostty/zig-out/share/ghostty and .../terminfo, remove existing Resources, copy fresh ghostty/terminfo into app Resources; adds run-isolated target to open isolated app with specific env.
Ghostty Shell Integration
Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift
Appends a conditional block to the zsh Rc shim that, when GHOSTTY_RESOURCES_DIR is set and ghostty-integration is readable there, sources the integration script (placed before PATH/other Shellraiser exports).
Ghostty Runtime Command Execution
Sources/Shellraiser/Infrastructure/Ghostty/GhosttyRuntime.swift
Changes launchCommand(for:) to return the escaped executable+args directly (no /bin/sh -lc wrapper when workingDirectory is provided), relying on Ghostty for working-directory/login-shell handling.
Ghostty GUI Components
Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift
Removes inline CAMetalLayer setup from initializer; moves applyGhosttyBackgroundStyle() to run after updateScaleAndSize() in init and calls it after updateScaleAndSize() in the update flow.
Tests
Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift, Tests/ShellraiserTests/GhosttyRuntimeCommandTests.swift
Adds testPrepareRuntimeSupportWritesZshRcShimWithGhosttyIntegrationSourcing() to verify zsh shim includes GHOSTTY_RESOURCES_DIR and sourcing lines; updates runtime command tests to expect direct shell command (no /bin/sh wrapper or embedded cd).
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main changes: Ghostty shell integration fixes and surface background ordering adjustments.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ghostty-shell-integration
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift (1)

453-454: ⚠️ Potential issue | 🟡 Minor

Keep background-style ordering consistent with initializer path.

Line 453 applies style before resizing, but Lines 68-69 do the reverse. This inconsistency can cause background styling to be overwritten during updates.

💡 Proposed fix
-        applyGhosttyBackgroundStyle()
-        updateScaleAndSize()
+        updateScaleAndSize()
+        applyGhosttyBackgroundStyle()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift`
around lines 453 - 454, The background style is applied before resizing in the
update path (applyGhosttyBackgroundStyle() then updateScaleAndSize()), which is
inconsistent with the initializer where updateScaleAndSize() runs before
applyGhosttyBackgroundStyle(); swap the calls in the update path so
updateScaleAndSize() is invoked prior to applyGhosttyBackgroundStyle()
(reference functions updateScaleAndSize and applyGhosttyBackgroundStyle) to keep
ordering consistent and avoid the style being overwritten by size/scale
adjustments.
🧹 Nitpick comments (1)
Makefile (1)

19-21: Add a pre-copy resource existence check with an actionable error.

If ghostty/zig-out/share/* is missing, cp fails with a generic error. A small guard makes failures clearer for contributors.

💡 Proposed fix
 build-app:
 	xcodebuild $(BUILD_FLAGS) -derivedDataPath $(DERIVED_DATA) build
+	test -d ghostty/zig-out/share/ghostty -a -d ghostty/zig-out/share/terminfo || (echo "Missing Ghostty resources. Build/update ghostty submodule first."; exit 1)
 	rm -rf $(APP_PATH)/Contents/Resources/ghostty $(APP_PATH)/Contents/Resources/terminfo
 	cp -R ghostty/zig-out/share/ghostty $(APP_PATH)/Contents/Resources/ghostty
 	cp -R ghostty/zig-out/share/terminfo $(APP_PATH)/Contents/Resources/terminfo

 build-isolated:
 	xcodebuild $(ISOLATED_BUILD_FLAGS) -derivedDataPath $(ISOLATED_DERIVED_DATA) build
+	test -d ghostty/zig-out/share/ghostty -a -d ghostty/zig-out/share/terminfo || (echo "Missing Ghostty resources. Build/update ghostty submodule first."; exit 1)
 	rm -rf $(ISOLATED_APP_PATH)/Contents/Resources/ghostty $(ISOLATED_APP_PATH)/Contents/Resources/terminfo
 	cp -R ghostty/zig-out/share/ghostty $(ISOLATED_APP_PATH)/Contents/Resources/ghostty
 	cp -R ghostty/zig-out/share/terminfo $(ISOLATED_APP_PATH)/Contents/Resources/terminfo

Also applies to: 25-27

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Makefile` around lines 19 - 21, Add an existence check before copying the
built resources: in the Makefile rule that runs the cp commands for
ghostty/zig-out/share/ghostty and ghostty/zig-out/share/terminfo, test that each
source directory exists (e.g., with a shell test like [ -d ... ]) and if missing
print a clear actionable error (mentioning which source is missing and
suggesting to run the build for ghostty) and exit non‑zero; apply the same
pre-copy guard to the other cp invocations referenced in the same Makefile
section so failures are explicit and actionable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift`:
- Around line 569-571: Guard the ghostty sourcing by checking the target file is
present and readable before calling source: instead of only testing [[ -n
"$GHOSTTY_RESOURCES_DIR" ]], add a read-check for
"$GHOSTTY_RESOURCES_DIR/shell-integration/zsh/ghostty-integration" (e.g., test
-r or [[ -r ... ]]) and only run source when that check passes; update the
snippet that references GHOSTTY_RESOURCES_DIR and the path
"shell-integration/zsh/ghostty-integration" accordingly so startup won’t fail if
the integration file is missing or unreadable.

---

Outside diff comments:
In `@Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift`:
- Around line 453-454: The background style is applied before resizing in the
update path (applyGhosttyBackgroundStyle() then updateScaleAndSize()), which is
inconsistent with the initializer where updateScaleAndSize() runs before
applyGhosttyBackgroundStyle(); swap the calls in the update path so
updateScaleAndSize() is invoked prior to applyGhosttyBackgroundStyle()
(reference functions updateScaleAndSize and applyGhosttyBackgroundStyle) to keep
ordering consistent and avoid the style being overwritten by size/scale
adjustments.

---

Nitpick comments:
In `@Makefile`:
- Around line 19-21: Add an existence check before copying the built resources:
in the Makefile rule that runs the cp commands for ghostty/zig-out/share/ghostty
and ghostty/zig-out/share/terminfo, test that each source directory exists
(e.g., with a shell test like [ -d ... ]) and if missing print a clear
actionable error (mentioning which source is missing and suggesting to run the
build for ghostty) and exit non‑zero; apply the same pre-copy guard to the other
cp invocations referenced in the same Makefile section so failures are explicit
and actionable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d7d14f61-21e3-42b8-aecd-c5cdff053d07

📥 Commits

Reviewing files that changed from the base of the PR and between d8d3536 and fb64698.

📒 Files selected for processing (6)
  • Makefile
  • Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift
  • Sources/Shellraiser/Infrastructure/Ghostty/GhosttyRuntime.swift
  • Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift
  • Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift
  • Tests/ShellraiserTests/GhosttyRuntimeCommandTests.swift

- Guard ghostty integration source with -r readability check on the file
- Fix background style ordering in registerSurfaceCallbacks to match initializer order
- Add existence checks in Makefile before copying ghostty/terminfo resources
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Makefile (1)

25-31: Consider extracting the resource sync logic into a reusable target.

The ghostty/terminfo resource copy block is duplicated between build-app and build-isolated. This increases maintenance burden if paths or logic change.

♻️ Optional refactor to reduce duplication
+define sync_ghostty_resources
+	`@test` -d ghostty/zig-out/share/ghostty || (echo "Error: ghostty/zig-out/share/ghostty not found. Run 'zig build' in the ghostty directory first." && exit 1)
+	`@test` -d ghostty/zig-out/share/terminfo || (echo "Error: ghostty/zig-out/share/terminfo not found. Run 'zig build' in the ghostty directory first." && exit 1)
+	rm -rf $(1)/Contents/Resources/ghostty $(1)/Contents/Resources/terminfo
+	cp -R ghostty/zig-out/share/ghostty $(1)/Contents/Resources/ghostty
+	cp -R ghostty/zig-out/share/terminfo $(1)/Contents/Resources/terminfo
+endef
+
 build-app:
 	xcodebuild $(BUILD_FLAGS) -derivedDataPath $(DERIVED_DATA) build
-	`@test` -d ghostty/zig-out/share/ghostty || ...
-	...
+	$(call sync_ghostty_resources,$(APP_PATH))

 build-isolated:
 	xcodebuild $(ISOLATED_BUILD_FLAGS) -derivedDataPath $(ISOLATED_DERIVED_DATA) build
-	`@test` -d ghostty/zig-out/share/ghostty || ...
-	...
+	$(call sync_ghostty_resources,$(ISOLATED_APP_PATH))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Makefile` around lines 25 - 31, The Makefile duplicates the resource-copy
logic between the build-isolated and build-app targets; extract that into a
reusable target (e.g., a new target named sync-ghostty-resources) and have both
build-isolated and build-app depend on or invoke it. Move the `@test` existence
checks for ghostty/zig-out/share/ghostty and ghostty/zig-out/share/terminfo, the
rm -rf of $(ISOLATED_APP_PATH)/Contents/Resources/{ghostty,terminfo}, and the cp
-R commands into that new target, and reference variables like ISOLATED_APP_PATH
so path logic for ghostty/zig-out/share/ghostty and
ghostty/zig-out/share/terminfo is centralized and not duplicated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Makefile`:
- Around line 25-31: The Makefile duplicates the resource-copy logic between the
build-isolated and build-app targets; extract that into a reusable target (e.g.,
a new target named sync-ghostty-resources) and have both build-isolated and
build-app depend on or invoke it. Move the `@test` existence checks for
ghostty/zig-out/share/ghostty and ghostty/zig-out/share/terminfo, the rm -rf of
$(ISOLATED_APP_PATH)/Contents/Resources/{ghostty,terminfo}, and the cp -R
commands into that new target, and reference variables like ISOLATED_APP_PATH so
path logic for ghostty/zig-out/share/ghostty and ghostty/zig-out/share/terminfo
is centralized and not duplicated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5e51a4e-9d96-44c3-bc65-851add641a0e

📥 Commits

Reviewing files that changed from the base of the PR and between fb64698 and 5dd8915.

📒 Files selected for processing (3)
  • Makefile
  • Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift
  • Sources/Shellraiser/Infrastructure/Ghostty/LibghosttySurfaceView.swift

@trydis trydis merged commit a05792d into main Mar 17, 2026
2 checks passed
@trydis trydis deleted the fix/ghostty-shell-integration branch March 17, 2026 21:43
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.

1 participant