Skip to content

Automatically find available local server ports - #46

Merged
elemdos merged 1 commit into
masterfrom
codex/local-port-fallback
Sep 29, 2026
Merged

elemdos merged 1 commit into
masterfrom
codex/local-port-fallback

Conversation

@elemdos

@elemdos elemdos commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Starting a second local workspace currently fails when port 3000 is occupied. The CLI now automatically selects the next available CMS/reload port pair when using the default port. Explicitly configured ports require confirmation before switching for the session; noninteractive runs fail with an override instruction.

  • Detect any TCP listener, check both ports, and honor --port before server.yaml before the default.
  • Keep the configured port unchanged and record the selected session in .primo/dev-server.json.
  • Make status, CLI preview, new-site handling, and local pull discovery use the running workspace's actual port; guard against duplicate workspace servers and stale session records.
  • Preserve an explicit port: 3000 when rewriting configuration, while new workspaces omit the default.

Companion MCP PR: primocms/mcp#20. Release both changes together so MCP previews also follow the selected port.

Validation:

  • TypeScript build passed.
  • Full CLI suite: 72 tests passed on Node 20, including two simultaneous dev sessions, raw TCP/reload collisions, confirmation decisions, noninteractive refusal, file/flag precedence, runtime discovery, and shutdown cleanup.
  • Server-startup tests use a disposable mock CMS process; they verify the CLI's actual bind arguments and lifecycle.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 86428891-2831-4368-9ec1-de09f09c3be2

📥 Commits

Reviewing files that changed from the base of the PR and between 937aa86 and 1f69bec.

📒 Files selected for processing (15)
  • README.md
  • src/commands/add.ts
  • src/commands/dev.ts
  • src/commands/init.ts
  • src/commands/new.ts
  • src/commands/preview.ts
  • src/commands/pull-library.ts
  • src/commands/pull.ts
  • src/commands/status.ts
  • src/index.ts
  • src/utils/dev-port.ts
  • src/utils/dev-runtime.ts
  • src/utils/server-config.ts
  • tests/dev-port.test.mjs
  • tests/dev-runtime.test.mjs

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

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

@elemdos
elemdos merged commit 9392cfc into master Sep 29, 2026
2 checks passed
@elemdos elemdos mentioned this pull request Sep 30, 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.

1 participant