Skip to content

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

Merged
nwparker merged 6 commits into
mainfrom
nwparker/orca-ports-cli
Oct 24, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/orca-ports-cli

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​369 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​369
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273

ELI5

Orca already knows which ports each workspace's dev servers listen on, and shows them on the workspace card and in the Ports panel. Now the CLI can tell you too: orca ports lists them, so a script or agent can open "this workspace's dev site" without guessing the port.

This builds on #32663 by @manuelmeurer, who designed and wrote the command. His two commits are kept with his authorship; this PR adds fixes on top.

What Changed

Before: the CLI had no way to read detected ports. Scripts had to repeat Orca's own scan with lsof.

After: a new read-only command, orca ports [--worktree <selector>] [--all] [--json].

  • With no --worktree it uses the workspace containing the current directory, the same way orca agent launch finds it.
  • Each row shows port, pid, process, connect host, protocol, how Orca matched it (match=cwd / match=command), and the URL the dev server printed in an Orca terminal, if Orca saw one. --json gives the usual envelope with result in the WorkspacePortHostScanResult shape.
  • --all lists every listener on that workspace's host, with each row's owner.
  • If the scan can't run, it prints unavailableReason instead of an empty list. An older runtime with no host-scoped scan gets an "Update Orca" error.

Mechanism: the handler calls the existing workspacePorts.scanHost RPC (#27188), so the runtime decides which host to scan. The CLI then keeps only the rows whose owner path matches the workspace path from worktree.show. No new RPC and no runtime changes.

Changes on top of #32663:

  • Native folder workspaces. Orca doesn't tie ports to native folder workspaces. feat(cli): add orca ports to list a workspace's detected ports #32663 fell back to every listener on the host, so jq '.result.ports[0]' could return another workspace's dev server. Now orca ports refuses with a clear message that points to --all.
  • --worktree path:<folder>. A path that names a native folder is recognised as that folder. If the path matches more than one workspace (two folders on different hosts, or a worktree and a folder), the command fails with selector_ambiguous and lists the candidates instead of guessing a host.
  • The command is added to the CLI reference docs (docs/site/content/docs/cli/reference.mdx). The docs and skill guide note the folder and SSH limits.
  • Unused exports were dropped, and parseWorkspaceKey is now reused.

Why

Many dev servers (Vite when its default port is taken, Puma with port 0) pick a random port and write it nowhere. Orca already does the scan and attribution, including on managed servers, so exposing that result is simpler and more reliable than every script redoing it. Filtering in the CLI instead of adding a per-workspace RPC means it works with every runtime that already has scanHost, with nothing new on the wire.

There was no existing way to get this: no CLI command or worktree ps field exposes ports, and the only RPCs are workspacePorts.*, which the renderer calls.

Linked Issue

Fixes #32632 (requested by @manuelmeurer)

Visual Proof

N/A: CLI-only change, with no UI.

Testing

  • src/cli/index-ports.test.ts (12 tests) runs the command through main(). It covers: the default workspace from cwd; an explicit selector; a folder-repo instance that shares its owner's path; --all owner rows; the JSON envelope; an unavailable scan; the "update Orca" error; a native folder refused without --all and scanned with it; a path: native folder; and an ambiguous path. The new folder tests fail on feat(cli): add orca ports to list a workspace's detected ports #32663's original handler.

  • Live on macOS: I built the CLI and started an isolated headless runtime (orca serve with a throwaway ORCA_USER_DATA_PATH, the installed app binary, background launch). I added a temp git repo and started one HTTP listener inside the repo and one outside it.

    • orca ports showed only the repo's listener (47931 pid=… Python 127.0.0.1 unknown match=cwd, host=local).
    • --all also showed the outside listener as workspace=(none).
    • --json returned the envelope.
  • The full static job passed locally (lint, format, anti-slop, code-quality, type-aware, typecheck, ratchets, generated-catalog checks). src/cli and src/main/startup unit tests ran single-worker.

  • Not verified live: SSH (direct and managed server), WSL, and paired runtimes. By code reading: a workspace on a managed server is scanned on that server when the CLI runs there or with --environment. Direct SSH workspaces get the runtime's existing unavailableReason, because the desktop runtime no longer scans SSH hosts (refactor(runtime): runtime git and file callers drop SSH arms #27501). WSL behaves the same as the Ports panel.

  • I manually tested these changes locally

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

AI Disclosure

Review

Codex review: round 1 was clean. Rounds 2 and 3 flagged path collisions in the new path: to folder mapping (fixed above). Round 4 was clean. An independent review found no P0–P2 issues; its P3s were taken.

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

Mobile: CLI-only, so there is no mobile surface to change.

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)

manuelmeurer and others added 6 commits October 23, 2026 19:19
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]>
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]>
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The pull request adds the orca ports command. It resolves a workspace selector, scans the selected host, and filters listeners to the workspace unless --all is set. The command supports JSON and table output, reports unavailable scans, and handles native-folder workspace constraints. It also adds command registration, help text, tests, and documentation.

Priority: Normal

Merge Risk: Low · up to 1f88f

The command is mergeable with a documentation correction: scripts following the reference may assume host-wide rows contain owner fields that are absent.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 11 files. (2 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 follows the repository template and covers the user-facing change, rationale, linked issue, testing, limitations, review notes, and checklist. It provides sufficient implementation and…
Linked Issues check Passed Issue #32632 requires a read-only orca ports command with current-workspace selection, explicit selectors, host scanning, workspace filtering, listener fields, JSON output, and --all host-wide out…
Out of Scope Changes check Passed The changes stay within issue #32632. CLI registration, flag help, command specifications, formatting, tests, CLI reference documentation, and the skill guide support the new orca ports command. The…
Full details: Description check

Explanation

The description follows the repository template and covers the user-facing change, rationale, linked issue, testing, limitations, review notes, and checklist. It provides sufficient implementation and validation detail.

Full details: Linked Issues check

Explanation

Issue #32632 requires a read-only orca ports command with current-workspace selection, explicit selectors, host scanning, workspace filtering, listener fields, JSON output, and --all host-wide output. src/cli/handlers/ports.ts calls workspacePorts.scanHost, resolves the current or explicit workspace, filters by owner path, and handles native folders, unavailable scans, and older runtimes. src/cli/ports-format.ts and the command specification provide the required fields and output modes. src/cli/index-ports.test.ts covers the command, selectors, JSON, --all, folder workspaces, unavailable scans, and runtime compatibility.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #32632. CLI registration, flag help, command specifications, formatting, tests, CLI reference documentation, and the skill guide support the new orca ports command. The PR does not add unrelated runtime or UI behavior.

Full details: Docstring Coverage

Explanation

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

Resolution

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

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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: 1


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: 87dfa37e-a9aa-4190-a3ff-7e61c100031f
Commits

Reviewing files that changed from the base of the PR and between 82534d0 and 1f88fa3.

Files selected for processing: 14
  • docs/site/content/docs/cli/reference.mdx
  • 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; 7 remain after this review.

orca ports --all
```

`ports` lists the listening ports Orca tied to a workspace, from the host the workspace runs on. It defaults to the workspace that contains the current directory. Each row has `port`, `pid`, `processName`, `connectHost`, `protocol`, how Orca matched it (`owner.confidence`: `cwd` or `command`), and `advertisedUrl` when the dev server printed one in an Orca terminal. `--all` lists every listener on that host. Native folder workspaces need `--all`, because Orca does not tie ports to them. If `unavailableReason` is set, the scan could not run on that host; SSH workspaces opened directly from the desktop report this for now, while a workspace on a managed Orca server is scanned on that server.

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.

🗄️ Data Integrity & Integration | Minor | ⚡ Quick win

Mark owner.confidence as workspace-only.

With --all, container and external rows have no owner. The current “Each row” wording can lead scripts to read a missing owner.confidence field. State that only kind: 'workspace' rows have owner.confidence and may have advertisedUrl, as the skill guide does.

@nwparker
nwparker merged commit cedce2a into main Oct 24, 2026
40 checks passed
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

2 participants