Skip to content

feat(cli): add orca ports to list a workspace's detected ports - #32663

Closed
manuelmeurer wants to merge 2 commits into
stablyai:mainfrom
manuelmeurer:orca/orca-ports-cli
Closed

manuelmeurer wants to merge 2 commits into
stablyai:mainfrom
manuelmeurer:orca/orca-ports-cli

Conversation

@manuelmeurer

@manuelmeurer manuelmeurer commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca already knows which ports each workspace is listening on: it shows them on the workspace card, in the status-bar popover and in the Ports panel. Now the CLI can tell you too: orca ports lists them, so a script or agent can find "the dev site of this workspace" without guessing the port.

What Changed

Before: the CLI had no way to read the detected ports. A script had to repeat Orca's own scan (lsof -iTCP -sTCP:LISTEN, then lsof -d cwd per PID, then compare paths), which is slow and does not work for SSH workspaces.

After: a new read-only command.

orca ports [--worktree <selector>] [--all] [--json]
  • With no --worktree, it uses the workspace that contains the current directory, the same way orca agent launch finds it (native folders first, then git worktrees). --worktree takes the usual selectors (active/current, id:, branch:, path:, ...).
  • Each row shows the port, PID, process name, connect host, protocol, how Orca tied it to the workspace (match=cwd or match=command), and the URL the dev server printed in an Orca terminal, if Orca saw one:
    3000  pid=3001  node  localhost  http  match=command
    5173  pid=5174  node  localhost  http  match=cwd  url=http://dev.test:5173
    
    host=local
    
  • --all lists every listener on that workspace's host, with the owning workspace per row (or (none) for processes Orca could not tie to one), like the status-bar popover. A native folder workspace always gets this view, because Orca only ties listeners to repo-backed workspaces. When two owners share a display name, the row adds the worktree id.
  • When the scan cannot run, the command prints the unavailableReason instead of an empty list.
  • --json prints the usual { id, ok, result, _meta } envelope, with result in the WorkspacePortHostScanResult shape (platform, scannedAt, ports, unavailableReason?, executionHostId), keeping only the selected workspace's rows unless --all is set. Example: orca ports --json | jq -r '.result.ports[0].advertisedUrl'.

Mechanism: the handler calls the existing host-scoped workspacePorts.scanHost({ worktree }) RPC from #27188, so the runtime decides which host the workspace runs on. The CLI then asks worktree.show for the workspace path, keeps the rows whose owner.path matches, and sorts them by port. Matching on the path rather than the id keeps the rows for every instance of a repo-backed folder workspace, since those instances share one path and attribution names only the first as owner. No new RPC, no runtime changes. The command is registered in the spec list, handler manifest, help text, the launch-redirect command names, and the orca-cli skill guide.

Why

Many dev servers (Puma with port 0, Vite when its default port is taken) pick a random port and write it nowhere. Orca already does the hard part, including SSH hosts, so exposing its result is simpler and more reliable than each script redoing the scan. Filtering on the CLI side, rather than adding a per-workspace RPC, keeps this compatible with every runtime that already ships scanHost.

Linked Issue

Fixes #32632

Visual Proof

N/A: CLI-only change, no UI. Sample text output is in "What Changed" above.

Testing

  • New src/cli/index-ports.test.ts runs the command through main(): default workspace from the cwd (git worktree, standalone native folder, native folder nested in a git worktree), a folder workspace instance that is not the recorded owner, duplicate owner names under --all, explicit selector resolved via worktree.show, text rows with and without --all, the JSON envelope, an unavailable scan, and the "update Orca" error when an older runtime answers method_not_found.

  • pnpm typecheck and pnpm lint pass; the changed-code quality gate reports 0 new findings.

  • pnpm test src/cli src/main/startup passed on the first commit (4 startup tests timed out at 30s while the typecheck ran at the same time; they pass when run alone). After the follow-up commit, src/cli/index-ports.test.ts, index-agent-launch.test.ts, and handler-group-manifest.test.ts pass; the remaining src/cli failures on my machine are in the launch/serve tests, which spawn local Orca binaries and check the real profile path, and do not touch this change.

  • Built the CLI (pnpm run build:cli) and checked orca ports --help and unknown-flag handling. I did not run it against a live Orca runtime.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Code (Claude Opus 5.5), reviewed by me.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mixed versions: a runtime without workspacePorts.scanHost gets incompatible_runtime with "This Orca runtime cannot list workspace ports yet. Update Orca and try again." rather than a raw method_not_found.
  • SSH / remote: the runtime picks the host. When it cannot scan that host (for example an SSH host it does not serve), the CLI shows the reason it returns. With --environment / --pairing-code, pass an explicit server-side selector, as with other commands; current is refused there.
  • Cross-platform: no platform-specific code in the CLI; scanning stays in the runtime.
  • Mobile: N/A, CLI-only.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Fixes #32632

Scripts and agents had no way to read the ports Orca already detects for
a workspace, so finding a dev server on a random port meant redoing the
lsof scan by hand. `orca ports` reuses the host-scoped
workspacePorts.scanHost RPC, keeps the rows owned by the current (or
--worktree) workspace, and prints port, pid, process, connect host,
protocol, how the owner was matched, and the advertised URL. --all shows
every listener on that host. An older runtime without scanHost gets an
"update Orca" error instead of a raw method_not_found.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Folder-workspace targeting and older-runtime SSH filtering can fail or produce misleading empty results.

3 open issues
What changed in this PR

Adds orca ports so scripts and agents can access Orca’s existing host-scoped port detection without implementing their own scans.

Changes:

  • Adds workspace selection, ownership filtering, --all, and text/JSON output using the existing runtime API.
  • Handles unavailable scans and runtimes that lack the API.
  • Registers the command and adds help, skill documentation, and CLI tests.
File Description
src/​main/​startup/​cli-command-names.ts Enables launch redirection for ports.
src/​cli/​specs/​ports.ts Defines command syntax, flags, and examples.
src/​cli/​specs/​index.ts Registers the command specification.
src/​cli/​root-help-text-secondary.ts Adds command usage to root help.
src/​cli/​root-help-text-primary.ts Adds the root command summary.
src/​cli/​ports-format.ts Formats listeners and scan status.
src/​cli/​index-ports.test.ts Tests selection, output, and error handling.
src/​cli/​handlers/​ports.ts Resolves targets, scans hosts, and filters results.
src/​cli/​handler-group-manifest.ts Registers the lazy-loaded handler.
src/​cli/​command-scoped-flag-help.ts Documents --all.
src/​cli/​bundled-skill-guides.ts Updates bundled CLI documentation.
src/​cli/​args.ts Excludes browser-page flags from ports.
skill-guides/​orca-cli.md Documents port discovery for agents.

Review effort: Balanced

Comment thread src/cli/handlers/ports.ts Resolved
Comment thread src/cli/handlers/ports.ts Resolved
Comment thread src/cli/handlers/ports.ts Resolved
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff0f34d9-feec-47af-968b-6a6eebbaea3b
📥 Commits

Reviewing files that changed from the base of the PR and between cc6712a and 8ed32ff.

📒 Files selected for processing: 5
  • skill-guides/orca-cli.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/ports.ts
  • src/cli/index-ports.test.ts
  • src/cli/ports-format.ts
🚧 Files skipped from review as they are similar to previous changes: 2
  • skill-guides/orca-cli.md
  • src/cli/ports-format.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The pull request adds the orca ports command. It scans listening ports on the workspace host and can filter results by worktree or include all host listeners. The command supports JSON and formatted output, with process, connection, protocol, ownership, and optional advertised-URL details. It also adds CLI registration and help text, documents the command, and tests selection, output, unavailable scans, and unsupported runtimes.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 8ed32

No identified issue blocks merging the ports command after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 11 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding the orca ports CLI command to list detected workspace ports.
Description check Passed The description is complete and relevant. It covers the user impact, implementation, rationale, linked issue, testing, compatibility considerations, and checklist. It also explains that full validatio…
Linked Issues check Passed Issue #32632 is the only active direct link. The implementation adds the read-only ports command and registers its handlers, specs, help, and command name. resolvePortsTarget selects the current w…
Out of Scope Changes check Passed The changed files support issue #32632. They implement the handler and formatter, register the command, add flag and help definitions, update launch command names, document the CLI skill, and add auto…
Full details: Description check

Explanation

The description is complete and relevant. It covers the user impact, implementation, rationale, linked issue, testing, compatibility considerations, and checklist. It also explains that full validation was not completed and that live-runtime testing was not performed.

Full details: Linked Issues check

Explanation

Issue #32632 is the only active direct link. The implementation adds the read-only ports command and registers its handlers, specs, help, and command name. resolvePortsTarget selects the current workspace or the explicit selector. The handler calls workspacePorts.scanHost, filters by workspace path, sorts by port, and supports --all. formatPortsScan reports port, PID, process, host, protocol, match confidence, advertised URL, owner labels, and unavailable reasons. printResult provides the JSON envelope. src/cli/index-ports.test.ts covers workspace resolution, native folders, filtering, text and JSON output, --all, unavailable scans, and older runtimes.

Full details: Out of Scope Changes check

Explanation

The changed files support issue #32632. They implement the handler and formatter, register the command, add flag and help definitions, update launch command names, document the CLI skill, and add automated tests. The handler uses the existing host-scoped RPC and does not add runtime or UI changes. No unrelated change is established by the supplied summary or inspected files.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 11 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19da759a-a5ca-4cae-abc9-c93756bc0419
📥 Commits

Reviewing files that changed from the base of the PR and between 2570d8f and cc6712a.

📒 Files selected for processing: 13
  • skill-guides/orca-cli.md
  • src/cli/args.ts
  • src/cli/bundled-skill-guides.ts
  • src/cli/command-scoped-flag-help.ts
  • src/cli/handler-group-manifest.ts
  • src/cli/handlers/ports.ts
  • src/cli/index-ports.test.ts
  • src/cli/ports-format.ts
  • src/cli/root-help-text-primary.ts
  • src/cli/root-help-text-secondary.ts
  • src/cli/specs/index.ts
  • src/cli/specs/ports.ts
  • src/main/startup/cli-command-names.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread skill-guides/orca-cli.md Resolved
Comment thread src/cli/ports-format.ts Resolved
Run inside a native folder, `orca ports` failed with selector_not_found
(or picked an enclosing git worktree) because it only searched the
worktree list. It now resolves the cwd like `agent launch`, native
folders first, and shows that host's listeners. Rows are matched on the
owner's path instead of its id, so every instance of a repo-backed
folder workspace keeps its ports even though attribution names only the
first instance as owner. `--all` adds the worktree id when two owners
share a display name, and the skill guide notes that only workspace
rows carry `owner` and `advertisedUrl`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Thank you @manuelmeurer! This was a well-scoped, clean addition, and it's landing via #33016 with both of your commits kept as-is (authorship preserved). We kept your whole design: the thin CLI over workspacePorts.scanHost, path-based row matching for folder-repo instances, the --all owner view, the "update Orca" fallback, the help/skill-guide wiring and your tests. On top we changed native folder workspaces to require --all (so .ports[0] can't return another workspace's server), taught --worktree path: to recognise native folders and refuse ambiguous paths, and added the command to the CLI reference docs. Closing this in favour of #33016. Thanks again for the clear issue and PR!

@nwparker nwparker closed this Oct 24, 2026
@manuelmeurer
manuelmeurer deleted the orca/orca-ports-cli branch November 25, 2026 09:57
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.

[Feature]: orca ports CLI command to list a workspace's detected ports

3 participants