Repository navigation
fix: resolve ESM crashes and enable multi-instance Electron for worktrees - #77
Conversation
…rees - add "type": "module" to lib packages missing it (logger/node, logger/browser, agents, integrations) (Node.js v25 + tsx treated them as CJS, breaking named ESM exports) - switch server dev script from tsx to tsup watch mode (tsx can't load .md files imported by libs/agents in ESM context) - bundle @xterm/headless and @xterm/addon-serialize in server tsup (CJS packages fail named-export destructuring under plain node ESM) - scope Electron identity per worktree via __WM_PORT_OFFSET__ (single-instance lock was killing worktree Electron immediately) - apply port offset to UI_DEV_SERVER_URL in Electron (Chromium networking bypasses both JS and native port hooks) - replace hardcoded "OpenKit" with APP_NAME constant in desktop-app
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughDesktop app now scopes APP_NAME and userData by worktree port offsets, updates protocol and window title, and adjusts dev-server URLs for port offsets. tsconfig paths and excludes changed. Server dev script and tsup externals updated. Several libs' package.json files set "type": "module". Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/desktop-app/src/main.ts`:
- Around line 257-261: The current devUrl port rewrite using a regex is brittle;
update the logic that modifies devUrl when portOffset > 0 to parse the string
with the URL class (or fallback by prepending a scheme if missing), adjust the
URL.port by adding portOffset to the parsed numeric port (or set to portOffset
when no port exists), and then serialize back to devUrl so pathname, query, and
hash are preserved; update the block around the devUrl and portOffset handling
to use new URL(...) and url.port manipulation instead of the current regex
replacement.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d40544ee-725f-4e9a-97c2-d177c8505240
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (8)
apps/desktop-app/src/main.tsapps/desktop-app/tsconfig.jsonapps/server/package.jsonapps/server/tsup.config.tslibs/agents/package.jsonlibs/integrations/package.jsonlibs/logger/browser/package.jsonlibs/logger/node/package.json
…t regex - read userData path before setName to avoid double-nested worktree dir - use URL parser instead of regex for dev server port offset
- custom URL schemes should be lowercase by convention (macOS/Linux normalize them anyway, but argv matching needs consistency)
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/desktop-app/src/main.ts (1)
57-72: Consider adding debug logging when worktree mode activates.When
portOffset > 0, a debug log would help diagnose multi-instance issues and confirm the expected configuration is applied.🔧 Proposed debug log
if (portOffset > 0) { // Resolve userData BEFORE setName, since setName changes the default path. const baseUserData = app.getPath("userData"); const suffix = `-worktree-${portOffset}`; app.setName(`${APP_NAME}${suffix}`); app.setPath("userData", path.join(baseUserData, `worktree-${portOffset}`)); + log.debug("running in worktree mode", { + domain: "app-init", + portOffset, + appName: `${APP_NAME}${suffix}`, + userData: path.join(baseUserData, `worktree-${portOffset}`), + }); } else { app.setName(APP_NAME); }As per coding guidelines: "Always include a
domainfield in the metadata object to namespace logs by feature area."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop-app/src/main.ts` around lines 57 - 72, Add a debug log when worktree mode activates (i.e., when portOffset > 0) to surface the computed values; log the portOffset, APP_NAME, baseUserData and the suffix before calling app.setName/app.setPath. Use the existing logging facility (or introduce one if absent) and include a metadata object with domain set to "worktree" (e.g., { domain: "worktree", portOffset }). Ensure the log occurs after computing suffix and before setName/setPath, referencing portOffset, APP_NAME, baseUserData, and suffix in the message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/desktop-app/src/main.ts`:
- Around line 259-264: Wrap the URL parsing around a try-catch so a malformed
UI_DEV_SERVER_URL doesn't crash startup: when you construct new URL(devUrl) (the
variable devUrl, and temporary u) guard it with if (devUrl) and try { const u =
new URL(devUrl); u.port = String(Number(u.port) + portOffset); devUrl =
u.toString(); } catch (err) { logger/error handler should log a meaningful
message including the original devUrl and the error (use the app's logger, e.g.,
processLogger.error) and leave devUrl unchanged or apply a safe fallback; ensure
the catch does not rethrow so the app can continue.
---
Nitpick comments:
In `@apps/desktop-app/src/main.ts`:
- Around line 57-72: Add a debug log when worktree mode activates (i.e., when
portOffset > 0) to surface the computed values; log the portOffset, APP_NAME,
baseUserData and the suffix before calling app.setName/app.setPath. Use the
existing logging facility (or introduce one if absent) and include a metadata
object with domain set to "worktree" (e.g., { domain: "worktree", portOffset }).
Ensure the log occurs after computing suffix and before setName/setPath,
referencing portOffset, APP_NAME, baseUserData, and suffix in the message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f09a672a-50aa-475b-a04b-1c4cc696248f
📒 Files selected for processing (1)
apps/desktop-app/src/main.ts
| let devUrl = process.env.UI_DEV_SERVER_URL; | ||
| if (portOffset > 0) { | ||
| const u = new URL(devUrl); | ||
| u.port = String(Number(u.port) + portOffset); | ||
| devUrl = u.toString(); | ||
| } |
There was a problem hiding this comment.
Add error handling for URL parsing to prevent app crash on malformed input.
new URL(devUrl) throws if UI_DEV_SERVER_URL is malformed. Without a try-catch, this crashes the app at startup.
🛡️ Proposed fix with error handling
let devUrl = process.env.UI_DEV_SERVER_URL;
if (portOffset > 0) {
- const u = new URL(devUrl);
- u.port = String(Number(u.port) + portOffset);
- devUrl = u.toString();
+ try {
+ const u = new URL(devUrl);
+ if (u.port) {
+ u.port = String(Number(u.port) + portOffset);
+ devUrl = u.toString();
+ }
+ } catch (error) {
+ log.warn("failed to apply worktree port offset to UI_DEV_SERVER_URL", {
+ domain: "window-bootstrap",
+ devUrl,
+ portOffset,
+ error,
+ });
+ }
}
mainWindow.loadURL(devUrl);As per coding guidelines: "Every catch block, every fallback branch, every error callback must do something meaningful: log through the appropriate logger."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let devUrl = process.env.UI_DEV_SERVER_URL; | |
| if (portOffset > 0) { | |
| const u = new URL(devUrl); | |
| u.port = String(Number(u.port) + portOffset); | |
| devUrl = u.toString(); | |
| } | |
| let devUrl = process.env.UI_DEV_SERVER_URL; | |
| if (portOffset > 0) { | |
| try { | |
| const u = new URL(devUrl); | |
| if (u.port) { | |
| u.port = String(Number(u.port) + portOffset); | |
| devUrl = u.toString(); | |
| } | |
| } catch (error) { | |
| log.warn("failed to apply worktree port offset to UI_DEV_SERVER_URL", { | |
| domain: "window-bootstrap", | |
| devUrl, | |
| portOffset, | |
| error, | |
| }); | |
| } | |
| } | |
| mainWindow.loadURL(devUrl); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/desktop-app/src/main.ts` around lines 259 - 264, Wrap the URL parsing
around a try-catch so a malformed UI_DEV_SERVER_URL doesn't crash startup: when
you construct new URL(devUrl) (the variable devUrl, and temporary u) guard it
with if (devUrl) and try { const u = new URL(devUrl); u.port =
String(Number(u.port) + portOffset); devUrl = u.toString(); } catch (err) {
logger/error handler should log a meaningful message including the original
devUrl and the error (use the app's logger, e.g., processLogger.error) and leave
devUrl unchanged or apply a safe fallback; ensure the catch does not rethrow so
the app can continue.
Summary by CodeRabbit
New Features
Chores
Refactor