Add deterministic dev port runner for multi-instance local workflows - #20
Conversation
- Route `dev*` scripts through `scripts/dev-runner.mjs` to compute shared server/web port offsets - Support `T3CODE_DEV_INSTANCE` (hashed or numeric) and explicit `T3CODE_PORT_OFFSET` - Document multi-instance usage and allow server `VITE_DEV_SERVER_URL` override
WalkthroughThis change introduces support for running multiple development instances with deterministic port shifting. A new dev-runner script orchestrates Turbo-based development workflows, calculating port offsets from environment variables. Development scripts are updated to delegate to this runner, and documentation is added explaining the feature with example usage. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Add a dev-runner to shift server and web dev ports deterministically for multi-instance local workflows via
|
Greptile OverviewGreptile SummaryAdds a centralized dev script runner ( Key changes:
The implementation correctly propagates environment variables and validates port ranges, though numeric Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Runner as dev-runner.mjs
participant Turbo as Turbo Build System
participant Server as apps/server
participant Web as apps/web
participant Desktop as apps/desktop
Dev->>Runner: bun run dev (or dev:desktop)
Runner->>Runner: Resolve port offset<br/>(T3CODE_PORT_OFFSET or<br/>T3CODE_DEV_INSTANCE hash)
Runner->>Runner: Compute ports<br/>server=3773+offset<br/>web=5173+offset
Runner->>Runner: Set env vars:<br/>T3CODE_PORT, PORT,<br/>ELECTRON_RENDERER_PORT,<br/>VITE_WS_URL, VITE_DEV_SERVER_URL
Runner->>Turbo: spawn turbo with computed env
Turbo->>Server: Start with T3CODE_PORT
Turbo->>Web: Start with PORT & VITE_WS_URL
opt Desktop Mode
Turbo->>Desktop: Start with ELECTRON_RENDERER_PORT
Desktop->>Desktop: Wait for web server on port
Desktop->>Desktop: Launch Electron with VITE_DEV_SERVER_URL
end
Server->>Web: WebSocket connection on coordinated ports
Last reviewed commit: f4df41a |
| if (/^\d+$/.test(seed)) { | ||
| return { offset: Number(seed), source: `numeric T3CODE_DEV_INSTANCE=${seed}` }; |
There was a problem hiding this comment.
numeric T3CODE_DEV_INSTANCE values aren't validated before use - large numbers like "70000" will pass through but fail port validation later with a confusing error
| if (/^\d+$/.test(seed)) { | |
| return { offset: Number(seed), source: `numeric T3CODE_DEV_INSTANCE=${seed}` }; | |
| if (/^\d+$/.test(seed)) { | |
| const offset = Number(seed); | |
| if (offset < 0 || offset > 65535 - Math.max(BASE_SERVER_PORT, BASE_WEB_PORT)) { | |
| throw new Error(`T3CODE_DEV_INSTANCE numeric offset ${offset} would exceed valid port range`); | |
| } | |
| return { offset, source: `numeric T3CODE_DEV_INSTANCE=${seed}` }; | |
| } |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@scripts/dev-runner.mjs`:
- Around line 61-67: The usage string thrown in main() is misleading because the
script is invoked via "bun run"; update the thrown Error message inside the mode
validation (the block that checks mode and MODE_ARGS) to reflect the actual
invocation (e.g., include "bun run" and mention optional flags like --dry-run)
so the message matches how users run this script; locate the error creation in
function main() where MODE_ARGS is referenced and replace the existing Usage
text with the corrected invocation text.
| function main() { | ||
| const mode = process.argv[2]; | ||
| const isDryRun = process.argv.includes("--dry-run"); | ||
| if (!mode || !(mode in MODE_ARGS)) { | ||
| const supportedModes = Object.keys(MODE_ARGS).join(", "); | ||
| throw new Error(`Usage: bun scripts/dev-runner.mjs <mode>. Supported modes: ${supportedModes}`); | ||
| } |
There was a problem hiding this comment.
Align usage message with actual invocation.
The scripts call this via bun run, so the error text is slightly misleading.
✏️ Suggested tweak
- throw new Error(`Usage: bun scripts/dev-runner.mjs <mode>. Supported modes: ${supportedModes}`);
+ throw new Error(`Usage: bun run scripts/dev-runner.mjs <mode>. Supported modes: ${supportedModes}`);📝 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.
| function main() { | |
| const mode = process.argv[2]; | |
| const isDryRun = process.argv.includes("--dry-run"); | |
| if (!mode || !(mode in MODE_ARGS)) { | |
| const supportedModes = Object.keys(MODE_ARGS).join(", "); | |
| throw new Error(`Usage: bun scripts/dev-runner.mjs <mode>. Supported modes: ${supportedModes}`); | |
| } | |
| function main() { | |
| const mode = process.argv[2]; | |
| const isDryRun = process.argv.includes("--dry-run"); | |
| if (!mode || !(mode in MODE_ARGS)) { | |
| const supportedModes = Object.keys(MODE_ARGS).join(", "); | |
| throw new Error(`Usage: bun run scripts/dev-runner.mjs <mode>. Supported modes: ${supportedModes}`); | |
| } |
🤖 Prompt for AI Agents
In `@scripts/dev-runner.mjs` around lines 61 - 67, The usage string thrown in
main() is misleading because the script is invoked via "bun run"; update the
thrown Error message inside the mode validation (the block that checks mode and
MODE_ARGS) to reflect the actual invocation (e.g., include "bun run" and mention
optional flags like --dry-run) so the message matches how users run this script;
locate the error creation in function main() where MODE_ARGS is referenced and
replace the existing Usage text with the corrected invocation text.
Summary
scripts/dev-runner.mjsto centralizedevscript startup and compute coordinated server/web port offsetsT3CODE_DEV_INSTANCE(hashed or numeric) and explicit override viaT3CODE_PORT_OFFSETT3CODE_PORT,PORT,VITE_WS_URL,VITE_DEV_SERVER_URL,ELECTRON_RENDERER_PORT)package.jsondev scripts to route through the new runnerapps/server/package.jsoninstead of hardcodinghttp://localhost:5173README.mdELECTRON_RENDERER_PORTin Turbo global env passthroughTesting
bun run scripts/dev-runner.mjs <mode> --dry-runto confirm computed ports/env wiringSummary by CodeRabbit
New Features
Documentation
Chores