Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
14298b8
feat(cli): one enclosing-workspace rule, --environment local, and cop…
Jinwoo-H Nov 8, 2026
a81938c
test: answer the folder catalog read in agent launch cwd tests
Jinwoo-H Nov 8, 2026
699d832
feat(cli): worktree rm refuses current/active and names the selector …
Jinwoo-H Nov 8, 2026
1835a0c
fix(cli): keep the remote-environment guidance when rm refuses current
Jinwoo-H Nov 8, 2026
44aefe1
fix(cli): surface folder-catalog failures for omitted targets; no add…
Jinwoo-H Nov 8, 2026
26cba09
fix(cli): surface a worktree-list failure for omitted browser and ter…
Jinwoo-H Nov 8, 2026
8a3507c
test(cli): folder rm refuses current/active before the folder removal…
Jinwoo-H Nov 8, 2026
49fbf4b
fix(cli): refuse a cwd owner whose folder host can't be derived inste…
Jinwoo-H Nov 8, 2026
13bd870
fix(cli): compare cwd owners by filesystem identity, refuse every equ…
Jinwoo-H Nov 8, 2026
138f7c6
fix(cli): read the realpath helper from shared so the packaged CLI sh…
Jinwoo-H Nov 8, 2026
12ad2a0
refactor(cli): move the catalog row type and unresolved-owner refusal…
Jinwoo-H Nov 8, 2026
58e9d3d
fix(cli): resolve every caller-filesystem workspace path, not only ba…
Jinwoo-H Nov 8, 2026
20c91fd
test: answer the folder catalog read in the ambiguous orchestration-c…
Jinwoo-H Nov 8, 2026
565e88f
feat(cli): --parent-environment names where a worktree's parent lives
Jinwoo-H Nov 8, 2026
2cd1807
fix(cli): parent lookup errors name and list the environment searched
Jinwoo-H Nov 8, 2026
ec383d1
docs(cli): a local address names the Orca that printed it
Jinwoo-H Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion skill-guides/orca-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ Selectors:
- When several workspaces match, the error usually lists each choice's kind, host, path and exact selector; pass one of those. If it lists none, find the row with `ORCA worktree ps --json` (if `truncated`, repeat with `--limit <totalCount>`) and pass `identity:<identity.key>`, `folder:<folderId>`, or `id:<worktreeId>` when no other row has that id. A folder id that two folder workspaces share can't be selected; the error says how to repair it.
- For a workspace in another environment, add `--environment <id>` to the command, as with any other selector.
- The full id is the exact `<repo-id>::<path>` value returned by `ORCA worktree create --json` or `ORCA worktree list --json`; a bare repo id is not a worktree id.
- `active` / `current` for the enclosing Orca-managed worktree from the shell cwd; when targeting a paired server with `--environment` or `--pairing-code`, use an explicit selector from that server instead.
- `active` / `current` for the Orca workspace enclosing the shell cwd, worktree or folder workspace: the innermost one wins, so a worktree nested inside a folder workspace is picked over the folder; at equal depth this terminal's own workspace wins, otherwise the error lists the choices. Pass `folder:<folderId>` to get the folder itself. `worktree rm` refuses `current`/`active` and needs an explicit selector; its error prints the one `current` resolves to. `current` resolves on this machine's Orca, so it is refused with `--environment <id>` or `--pairing-code`; use an explicit selector from that environment instead (`--environment local` keeps it on this machine even when `ORCA_ENVIRONMENT` is set).
- `--environment` selects which Orca receives the command (`local` is this machine's own Orca); `host` is that Orca's stored location metadata. Never derive an environment from `host`.
- `worktree ps` and `worktree show` give each workspace an `address` (text: an `address:` line). Copy `address.line` as is, keeping its `--environment`, or pass `address.environment` and `address.worktree` as `--environment` and `--worktree`. If `address` is null, follow `addressUnavailable` (`one-off-connection`, `unverifiable-row` or `duplicate-folder-id`) and never construct a route yourself. `parent` names the parent's environment when it is known; with `state: unknown-environment` there is no route to it from here.
- For `worktree create --parent-worktree`, folder/worktree parent context keys are also valid: `folder:<folderId>`, `worktree:<repoId>::<worktreePath>`, `id:folder:<folderId>`, `id:worktree:<repoId>::<worktreePath>`. `worktree set --parent-worktree` also takes the folder keys, `folder:<folderId>` or `id:folder:<folderId>`. On both, `path:` and `name:` record a folder workspace parent when they match one.

Lineage rules:
Expand All @@ -146,6 +148,8 @@ Lineage rules:
- Use `--parent-worktree folder:<folderId>` or `--parent-worktree worktree:<repoId>::<worktreePath>` when a folder or worktree parent context should be explicit.
- Use `--no-parent` only when the new work is independent.
- A parent can be in a different project from its child, such as `worktree create --repo id:<otherRepoId> --name related-task --parent-worktree id:<parentRepoId>::<parentPath>`. A worktree parent and child must use the same execution host (local machine, SSH target, or paired server).
- `--parent-worktree` is looked up in the child's environment. For a parent in another environment, add `--parent-environment <local|environment-id>`: to reuse a workspace from `ps`/`show` as a parent, pass its `address.environment` as `--parent-environment` and its `address.worktree` as `--parent-worktree`. Orca never searches other environments; a parent missing there is an error. `active`/`current` always mean this machine's own workspace, so they take only `--parent-environment local`.
- An address with `--environment local` means the Orca that printed it, because `local` is always the machine running the command; don't hand an address to another machine to run. To link workspaces across environments, run the command from the Orca that has both paired, such as `--environment <server> --worktree <selector> --parent-worktree current`.
- To move an existing worktree under a different parent, or make it top-level, use `worktree set` with `--parent-worktree <selector>` or `--no-parent`.
- `--no-parent` only controls Orca lineage; it does not choose the Git base. For independent top-level work, omit `--base-branch` so Orca uses the repo default base, or explicitly pass the repo default base. Never base it on the current feature branch unless the user asks for stacked work or "branch from current".

Expand Down
72 changes: 0 additions & 72 deletions src/cli/agent-workspace-selector.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/cli/browser/browser-command-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { RuntimeStatus } from '../../shared/runtime-types'
import { getOptionalStringFlag, getPresentStringFlag } from '../flags'
import type { RuntimeClient } from '../runtime-client'
import { RuntimeClientError } from '../runtime/types'
import { assertLocalCwdWorktreeSelector } from '../local-environment-selector'
import {
assertLocalCwdWorktreeSelector,
getBrowserWorktreeSelector,
normalizeWorktreeSelectorForCaller,
resolveCurrentWorktreeSelector
Expand Down
20 changes: 15 additions & 5 deletions src/cli/browser/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ vi.mock('../runtime-client', async () => {

import { main } from '../index'
import { RuntimeClientError } from '../runtime/types'
import { buildWorktree, okFixture, queueFixtures, worktreeListFixture } from '../test-fixtures'
import {
buildWorktree,
noFolderWorkspacesFixture,
okFixture,
queueFixtures,
worktreeListFixture
} from '../test-fixtures'

describe('orca cli browser page targeting', () => {
beforeEach(() => {
Expand Down Expand Up @@ -162,6 +168,7 @@ describe('orca cli browser page targeting', () => {
queueFixtures(
callMock,
worktreeListFixture([buildWorktree('/tmp/repo/feature', 'feature/foo')]),
noFolderWorkspacesFixture(),
okFixture('req_snapshot', {
browserPageId: 'page-1',
snapshot: 'tree',
Expand All @@ -178,7 +185,7 @@ describe('orca cli browser page targeting', () => {
)

expect(callMock).toHaveBeenNthCalledWith(1, 'worktree.list', { limit: 10_000 })
expect(callMock).toHaveBeenNthCalledWith(2, 'browser.snapshot', {
expect(callMock).toHaveBeenNthCalledWith(3, 'browser.snapshot', {
page: 'page-1',
worktree: 'id:repo::/tmp/repo/feature'
})
Expand All @@ -202,6 +209,7 @@ describe('orca cli browser page targeting', () => {
queueFixtures(
callMock,
worktreeListFixture([buildWorktree('/tmp/repo/feature', 'feature/foo')]),
noFolderWorkspacesFixture(),
okFixture('req_switch', { switched: 2, browserPageId: 'page-2' })
)
vi.spyOn(console, 'log').mockImplementation(() => {})
Expand All @@ -212,7 +220,7 @@ describe('orca cli browser page targeting', () => {
)

expect(callMock).toHaveBeenNthCalledWith(1, 'worktree.list', { limit: 10_000 })
expect(callMock).toHaveBeenNthCalledWith(2, 'browser.tabSwitch', {
expect(callMock).toHaveBeenNthCalledWith(3, 'browser.tabSwitch', {
index: undefined,
page: 'page-2',
worktree: 'id:repo::/tmp/repo/feature'
Expand Down Expand Up @@ -277,14 +285,15 @@ describe('orca cli browser page targeting', () => {
queueFixtures(
callMock,
worktreeListFixture([buildWorktree('/tmp/repo/feature', 'feature/foo')]),
noFolderWorkspacesFixture(),
okFixture('req_open_url', { browserPageId: 'page-local' })
)
vi.spyOn(console, 'log').mockImplementation(() => {})

await main(['open-url', '--url', 'https://example.com/login', '--json'], '/tmp/repo/feature')

expect(callMock).toHaveBeenNthCalledWith(
2,
3,
'browser.openUrl',
{
url: 'https://example.com/login',
Expand All @@ -300,6 +309,7 @@ describe('orca cli browser page targeting', () => {
queueFixtures(
callMock,
worktreeListFixture([parent, workspace]),
noFolderWorkspacesFixture(),
okFixture('req_tab_create', { browserPageId: 'page-1' })
)
vi.spyOn(console, 'log').mockImplementation(() => {})
Expand All @@ -308,7 +318,7 @@ describe('orca cli browser page targeting', () => {
await main(['tab', 'create', '--url', 'https://example.com', '--json'], '/tmp/folder')

expect(callMock).toHaveBeenNthCalledWith(
2,
3,
'browser.tabCreate',
{ url: 'https://example.com', worktree: `id:${workspace.id}` },
{ timeoutMs: 60_000 }
Expand Down
6 changes: 5 additions & 1 deletion src/cli/bundled-skill-guides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ const ORCA_CLI_MARKDOWN = [
"- When several workspaces match, the error usually lists each choice's kind, host, path and exact selector; pass one of those. If it lists none, find the row with `ORCA worktree ps --json` (if `truncated`, repeat with `--limit <totalCount>`) and pass `identity:<identity.key>`, `folder:<folderId>`, or `id:<worktreeId>` when no other row has that id. A folder id that two folder workspaces share can't be selected; the error says how to repair it.",
"- For a workspace in another environment, add `--environment <id>` to the command, as with any other selector.",
"- The full id is the exact `<repo-id>::<path>` value returned by `ORCA worktree create --json` or `ORCA worktree list --json`; a bare repo id is not a worktree id.",
"- `active` / `current` for the enclosing Orca-managed worktree from the shell cwd; when targeting a paired server with `--environment` or `--pairing-code`, use an explicit selector from that server instead.",
"- `active` / `current` for the Orca workspace enclosing the shell cwd, worktree or folder workspace: the innermost one wins, so a worktree nested inside a folder workspace is picked over the folder; at equal depth this terminal's own workspace wins, otherwise the error lists the choices. Pass `folder:<folderId>` to get the folder itself. `worktree rm` refuses `current`/`active` and needs an explicit selector; its error prints the one `current` resolves to. `current` resolves on this machine's Orca, so it is refused with `--environment <id>` or `--pairing-code`; use an explicit selector from that environment instead (`--environment local` keeps it on this machine even when `ORCA_ENVIRONMENT` is set).",
"- `--environment` selects which Orca receives the command (`local` is this machine's own Orca); `host` is that Orca's stored location metadata. Never derive an environment from `host`.",
"- `worktree ps` and `worktree show` give each workspace an `address` (text: an `address:` line). Copy `address.line` as is, keeping its `--environment`, or pass `address.environment` and `address.worktree` as `--environment` and `--worktree`. If `address` is null, follow `addressUnavailable` (`one-off-connection`, `unverifiable-row` or `duplicate-folder-id`) and never construct a route yourself. `parent` names the parent's environment when it is known; with `state: unknown-environment` there is no route to it from here.",
"- For `worktree create --parent-worktree`, folder/worktree parent context keys are also valid: `folder:<folderId>`, `worktree:<repoId>::<worktreePath>`, `id:folder:<folderId>`, `id:worktree:<repoId>::<worktreePath>`. `worktree set --parent-worktree` also takes the folder keys, `folder:<folderId>` or `id:folder:<folderId>`. On both, `path:` and `name:` record a folder workspace parent when they match one.",
"",
"Lineage rules:",
Expand All @@ -374,6 +376,8 @@ const ORCA_CLI_MARKDOWN = [
"- Use `--parent-worktree folder:<folderId>` or `--parent-worktree worktree:<repoId>::<worktreePath>` when a folder or worktree parent context should be explicit.",
"- Use `--no-parent` only when the new work is independent.",
"- A parent can be in a different project from its child, such as `worktree create --repo id:<otherRepoId> --name related-task --parent-worktree id:<parentRepoId>::<parentPath>`. A worktree parent and child must use the same execution host (local machine, SSH target, or paired server).",
"- `--parent-worktree` is looked up in the child's environment. For a parent in another environment, add `--parent-environment <local|environment-id>`: to reuse a workspace from `ps`/`show` as a parent, pass its `address.environment` as `--parent-environment` and its `address.worktree` as `--parent-worktree`. Orca never searches other environments; a parent missing there is an error. `active`/`current` always mean this machine's own workspace, so they take only `--parent-environment local`.",
"- An address with `--environment local` means the Orca that printed it, because `local` is always the machine running the command; don't hand an address to another machine to run. To link workspaces across environments, run the command from the Orca that has both paired, such as `--environment <server> --worktree <selector> --parent-worktree current`.",
"- To move an existing worktree under a different parent, or make it top-level, use `worktree set` with `--parent-worktree <selector>` or `--no-parent`.",
"- `--no-parent` only controls Orca lineage; it does not choose the Git base. For independent top-level work, omit `--base-branch` so Orca uses the repo default base, or explicitly pass the repo default base. Never base it on the current feature branch unless the user asks for stacked work or \"branch from current\".",
"",
Expand Down
49 changes: 49 additions & 0 deletions src/cli/caller-cwd-containment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { resolve as resolvePath } from 'node:path'
import {
isPathInsideOrEqual,
normalizeRuntimePathForComparison
} from '../shared/cross-platform-path'
import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../shared/execution-host'
import { resolveRealPathSync } from '../shared/real-path-sync'

// One CLI process is one command, so the folder prefilter and ranking share each resolution.
const realPaths = new Map<string, string>()

/** A local path with symlinks resolved; a path that no longer exists keeps its lexical spelling. */
function realPathOf(lexical: string): string {
let real = realPaths.get(lexical)
if (real === undefined) {
real = resolveRealPathSync(lexical) ?? lexical
realPaths.set(lexical, real)
}
return real
}

/**
* Whether a workspace path contains cwd, and its comparison key for ranking. Paths on the caller's
* own filesystem compare by filesystem identity, so any symlink alias matches; a path on another
* host, or whose host is unknown, is never resolved here and compares as written.
*/
export function createCwdContainment(
cwd: string,
callerHostId: ExecutionHostId
): (path: string, onCallerFilesystem: boolean) => string | null {
const lexicalCwd = resolvePath(cwd)
const local = callerHostId === LOCAL_EXECUTION_HOST_ID
const realCwd = local ? realPathOf(lexicalCwd) : lexicalCwd
return (path, onCallerFilesystem) => {
const lexical = resolvePath(path)
const real = local && onCallerFilesystem ? realPathOf(lexical) : lexical
return isPathInsideOrEqual(real, realCwd) || isPathInsideOrEqual(lexical, lexicalCwd)
? normalizeRuntimePathForComparison(real)
: null
}
}

/** Unstamped rows belong to the answering Orca, as the caller-host rule treats them. */
export function isOnCallerFilesystem(row: {
hostId?: string | null
hostUnresolved?: true
}): boolean {
return !row.hostUnresolved && (!row.hostId || row.hostId === LOCAL_EXECUTION_HOST_ID)
}
Loading
Loading