#3337: fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle
scripts
Cluster:
Build and Fix Enhancements
fix(macos-app): patch SwiftPM Bundle.module accessor for app bundle compatibility
Problem
SwiftPM's auto-generated resource_bundle_accessor.swift files use Bundle.main.bundleURL.appendingPathComponent(...) to locate package resource bundles. This resolves to .app/Package_Target.bundle at the app root.
However:
• macOS app bundles put resources in .app/Contents/Resources/
• Code signing prohibits arbitrary files/symlinks at the app root
• This causes EXC_BREAKPOINT crashes when packages like Textual try Bundle.module.url(forResource:) (e.g., prism-bundle.js for syntax highlighting)
Crash trace:
Thread 0 Crashed:
0 libswiftCore.dylib _assertionFailure
1 Clawdbot closure #1 in variable initialization expression of static NSBundle.module
2 Clawdbot CodeTokenizer.init()
Solution
After the first swift build (which generates accessors), patch all resource_bundle_accessor.swift files:
- let mainPath = Bundle.main.bundleURL.appendingPathComponent("textual_Textual.bundle").path
+ let mainPath = (Bundle.main.resourceURL ?? Bundle.main.bundleURL).appendingPathComponent("textual_Textual.bundle").path
• Falls back to resourceURL first (correct for .app/Contents/Resources/), then bundleURL (development builds)
• Rebuilds with patched accessors
• No upstream changes needed
Changes
• scripts/package-mac-app.sh: Add double-build + sed patching step
• Works for all arches, all packages (Textual, SwiftUIMath, ClawdbotKit, etc.)
• Minimal overhead (~1-2s rebuild)
Testing
1. BUNDLE_ID=dev.rwx.ai.bot ./scripts/package-mac-app.sh
2. Copy to /Applications/ → launches without crash ✅
3. Syntax highlighting works (uses Prism.js from Textual bundle) ✅
4. Codesign verifies ✅
Before/After
Development (swift run)
• Before: ✅
• After: ✅
Packaged .app
• Before: 💥 Crash on startup
• After: ✅ Launches + full functionality
Codesign
• Before: ✅
• After: ✅
Fixes #1709 (https://github.com/clawdbot/clawdbot/issues/1709) (Textual/CodeTokenizer crash).
Closes: #1709
Type: Fix
Scope: macos-app, swiftpm
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `scripts/package-mac-app.sh` to patch SwiftPM-generated `resource_bundle_accessor.swift` files so `Bundle.module` resolves resources via `Bundle.main.resourceURL` inside a signed `.app` bundle (instead of `bundleURL` at the app root). The script now performs an initial `swift build` per-arch to generate accessors, rewrites the accessor code via `sed`, then rebuilds and continues packaging by copying resource bundles (including adding SwiftUIMath’s bundle) into `Moltbot.app/Contents/Resources`.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but the build-step error handling could mask failures and produce flaky packaged apps.
- The change is localized to a packaging script and aligns with macOS bundle resource layout, but the new `swift build ... || true` can let the script proceed without actually generating/patching accessors, making failures harder to diagnose and potentially reintroducing the crash at runtime.
- scripts/package-mac-app.sh (new build+patch loop and error handling)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#3534: Update ad-hoc signing instructions in dev setup
by yeasy · 2026-01-28
78.5%
#15909: Guard notifications on macOS; fix focus issue and build fixes
by jasonkneen · 2026-02-14
77.4%
#3973: fix: enhance npm package integrity checks and include critical files
by YeSuX · 2026-01-29
75.4%
#11951: Prepending Windows Node to PATH didn’t help
by tranhoangtu-it · 2026-02-08
75.4%
#3474: fix(macos): menu bar activity badge not showing during agent work
by elektricM · 2026-01-28
74.3%
#18792: docs: add macOS source-run troubleshooting for setup/auth issues
by yash27-lab · 2026-02-17
74.1%
#11048: fix: address repository issues (env, author, CI comments, security ...
by cavula · 2026-02-07
74.0%
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
73.6%
#7121: feat(macos): update app icon OpenClaw branding
by rishavgoenka · 2026-02-02
73.5%
#18493: making pnpm build:ui and pnpm build to work on windows
by darkpowerxo · 2026-02-16
73.5%