fix(runtime): explain full worktree id selectors (#7432) (#7892)

* fix(runtime): explain full worktree id selectors (#7432)

* Fix full worktree id selectors for bare repo ids and doc guidance

- Reject bare repo-id selectors up front via a shared validator instead
  of relying on worktree-list scanning, so RPC callers no longer trigger
  an unnecessary rescan just to detect the mistake
- Propagate the structured worktree_id_requires_full_path code through
  RPC error mapping so callers get a typed error, not just a message
- Update orca-cli, orca-emulator, and orchestration skill docs to show
  the full `<repo-id>::<path>` id shape and stop implying a bare repo
  id is a valid worktree selector

---------

Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
Rod Boev
2026-07-11 22:40:44 -07:00
committed by GitHub
co-authored by Jinjing
parent c99095b1e8
commit 3090ff0edb
12 changed files with 219 additions and 45 deletions
@@ -4,9 +4,11 @@ import { describe, expect, it } from 'vitest'
const projectDir = resolve(import.meta.dirname, '../..')
const skillPath = join(projectDir, 'skills', 'orca-cli', 'SKILL.md')
const orchestrationSkillPath = join(projectDir, 'skills', 'orchestration', 'SKILL.md')
const emulatorSkillPath = join(projectDir, 'skills', 'orca-emulator', 'SKILL.md')
function readSkill() {
return readFileSync(skillPath, 'utf8')
function readSkill(path = skillPath) {
return readFileSync(path, 'utf8')
}
describe('orca CLI skill guidance', () => {
@@ -67,6 +69,21 @@ describe('orca CLI skill guidance', () => {
)
})
it('requires full worktree ids across bundled agent guidance', () => {
const cliSkill = readSkill()
const orchestrationSkill = readSkill(orchestrationSkillPath)
const emulatorSkill = readSkill(emulatorSkillPath)
for (const skill of [cliSkill, orchestrationSkill, emulatorSkill]) {
expect(skill).toContain('<repo-id>::<path>')
expect(skill).toContain('bare repo id')
}
expect(cliSkill).toContain('id:<repoId>::<worktreePath>')
expect(cliSkill).toContain('two-part address')
expect(orchestrationSkill).toContain('id:<newFullWorktreeId>')
expect(emulatorSkill).not.toContain('id:abc123')
})
it('keeps browser injection guidance narrow and avoids literal secret examples', () => {
const skill = readSkill()
+14 -9
View File
@@ -59,9 +59,11 @@ Custom Codex model/effort handoff:
**Extra first terminal:** when no repo default-terminal configuration supplies a primary terminal, bare `worktree create` (no `--agent`) opens a fallback shell before the later `terminal create --command ...` adds the agent. Configured default tabs are materialized instead and may run real commands. Prefer `--agent` whenever the built-in launcher is enough. When custom argv forces the two-step path, target the agent handle only; close a prior terminal only after `terminal list` or `terminal show` confirms it is an unused shell.
The create result's `worktree.id` already contains both pieces Orca needs: `<repoId>::<worktreePath>`. Copy that whole value into the next command; do not shorten it to the repo id.
```bash
orca worktree create --name <task-name> --no-parent --json
orca terminal create --worktree id:<newWorktreeId> --title <task-name> --command 'codex --model gpt-5.5 -c model_reasoning_effort="xhigh"' --json
orca terminal create --worktree id:<repoId>::<newWorktreePath> --title <task-name> --command 'codex --model gpt-5.5 -c model_reasoning_effort="xhigh"' --json
orca terminal wait --terminal <handle> --for tui-idle --timeout-ms 60000 --json
orca terminal send --terminal <handle> --text "<task brief>" --enter --json
```
@@ -76,6 +78,8 @@ orca terminal send --terminal <handle> --text "<task brief>" --enter --json
An Orca worktree is Orca's tracked view of a repo checkout, its metadata, terminals, browser tabs, and UI state.
Think of its id as a two-part address: `<repoId>::<worktreePath>`. For example, `repo-123::/Users/me/orca/fix-login` means “the `fix-login` checkout inside repo `repo-123`.” Always copy the complete `id` field from `orca worktree create --json` or `orca worktree list --json`; `repo-123` alone identifies only the repo.
Common commands:
```bash
@@ -93,23 +97,24 @@ orca worktree create --repo id:<repoId> --name related-task --parent-worktree ac
orca worktree create --repo id:<repoId> --name folder-child --parent-worktree folder:<folderId> --json
orca worktree create --name child-task --agent codex --prompt "hi" --json
orca worktree create --name independent-task --no-parent --json
orca worktree set --worktree id:<worktreeId> --display-name "My Task" --json
orca worktree set --worktree id:<repoId>::<worktreePath> --display-name "My Task" --json
orca worktree set --worktree active --comment "reproduced bug; testing fix" --json
orca worktree set --worktree active --workspace-status in-review --json
orca worktree rm --worktree id:<worktreeId> --force --json
orca worktree rm --worktree id:<repoId>::<worktreePath> --force --json
```
Selectors:
- `id:<worktreeId>`, `name:<displayName>`, `path:<absolutePath>`, `branch:<branchName>`, `issue:<number>`
- `id:<repoId>::<worktreePath>`, `name:<displayName>`, `path:<absolutePath>`, `branch:<branchName>`, `issue:<number>`
- 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
- For `worktree create --parent-worktree` only, folder/worktree parent context keys are also valid: `folder:<folderId>`, `worktree:<worktreeId>`, `id:folder:<folderId>`, `id:worktree:<worktreeId>`
- For `worktree create --parent-worktree` only, folder/worktree parent context keys are also valid: `folder:<folderId>`, `worktree:<repoId>::<worktreePath>`, `id:folder:<folderId>`, `id:worktree:<repoId>::<worktreePath>`
Lineage rules:
- When creating from inside an Orca-managed worktree or folder context, Orca infers the current parent context when it can.
- Use `--parent-worktree active` when the child worktree relationship should be explicit.
- Use `--parent-worktree folder:<folderId>` or `--parent-worktree worktree:<worktreeId>` when a folder or worktree parent context should be explicit.
- 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.
- `--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".
- If `--repo` is omitted, Orca infers the repo from the current Orca worktree when possible.
@@ -125,7 +130,7 @@ orca worktree create --name task --run-hooks --json
- `--agent <id>` launches that agent **in the first terminal** (Orca docs: *"`--agent` launches the selected agent in the first terminal"*); `--prompt <text>` sends initial work to it. Known ids include `claude`, `codex`, `omp`, `pi`, `grok`, and other installed TUI agents.
- **Prefer agent-first create for agent workers.** `orca worktree create --agent <id> --prompt "..."` puts the agent in the worktree's first terminal without adding a separate fallback shell for that worker. Repo setup or default-terminal settings may still add tabs or splits. Without configured default tabs, the bare-create fallback shell plus a later `terminal create --command <agent>` is an anti-pattern for ordinary agent worktrees — use `--agent` instead of “create worktree, then open agent.” Configured default tabs are intentional surfaces; never treat one as disposable without verifying that it is an unused shell.
- After create, use exactly one agent handle: `startupTerminal.handle` from the create response when present, or the matching result from `orca terminal list --worktree id:<newWorktreeId> --json` (or `name:<displayName>`) when the response omits it. If a handle later returns `terminal_handle_stale`, re-list it; never dual-send to old and replacement handles.
- After create, use exactly one agent handle: `startupTerminal.handle` from the create response when present, or the matching result from `orca terminal list --worktree id:<repoId>::<newWorktreePath> --json` (or `name:<displayName>`) when the response omits it. If a handle later returns `terminal_handle_stale`, re-list it; never dual-send to old and replacement handles.
- `--setup run|skip|inherit` controls repo setup hooks. Default is `inherit`, which follows the repo's setup policy.
- `--run-hooks` is a legacy alias for `--setup run`; it also reveals/activates the new worktree.
- `--agent`, `--activate`, and `--run-hooks` reveal the new worktree. Plain create stays in the background.
@@ -152,7 +157,7 @@ Card status uses `--workspace-status <id>`; defaults are `todo`, `in-progress`,
Common commands:
```bash
orca terminal list --worktree id:<worktreeId> --json
orca terminal list --worktree id:<repoId>::<worktreePath> --json
orca terminal show --terminal <handle> --json
orca terminal read --terminal <handle> --json
orca terminal read --terminal <handle> --cursor <cursor> --limit 1000 --json
@@ -161,7 +166,7 @@ orca terminal send --terminal <handle> --text "continue" --enter --json
orca terminal send --text "echo hello" --enter --json
orca terminal wait --terminal <handle> --for exit --timeout-ms 5000 --json
orca terminal wait --terminal <handle> --for tui-idle --timeout-ms 300000 --json
orca terminal stop --worktree id:<worktreeId> --json
orca terminal stop --worktree id:<repoId>::<worktreePath> --json
orca terminal create --json
orca terminal create --title "Worker" --json
orca terminal create --worktree active --command "codex" --json
+1 -1
View File
@@ -107,7 +107,7 @@ Most support `--worktree <selector>` and explicit `--device <udid|name>` or `--e
## Targeting devices & worktrees
- Default: current worktree's active emulator (resolved from shell cwd or Orca context).
- Explicit worktree: `--worktree id:abc123` or `--worktree active`.
- Explicit worktree: `--worktree id:<fullWorktreeId>` or `--worktree active`. The full id is the exact `<repo-id>::<path>` value returned by `orca worktree list --json`; a bare repo id is not valid here.
- Explicit device: `--device "iPhone 16 Pro"` or `--device <udid>` (after `list`).
- Orca-generated emulator id (for stability, like browserPageId): use `--emulator <id>` returned by list (recommended for scripts that persist ids).
+3 -1
View File
@@ -165,9 +165,11 @@ Custom Codex model/effort handoff:
Note: when no repo default-terminal configuration supplies a primary terminal, bare create opens a fallback shell before `terminal create` adds the agent. Configured default tabs are materialized instead and may run real commands. Prefer `--agent` whenever custom argv is not required. With the two-step path, target only the agent handle; close a prior terminal only after `terminal list` or `terminal show` confirms it is an unused shell.
Use the exact full `<repo-id>::<path>` worktree id returned by `orca worktree create --json`; a bare repo id cannot target the new worktree.
```bash
orca worktree create --name <task-name> --no-parent --json
orca terminal create --worktree id:<newWorktreeId> --title <task-name> --command 'codex --model gpt-5.5 -c model_reasoning_effort="xhigh"' --json
orca terminal create --worktree id:<newFullWorktreeId> --title <task-name> --command 'codex --model gpt-5.5 -c model_reasoning_effort="xhigh"' --json
orca terminal wait --terminal <handle> --for tui-idle --timeout-ms 60000 --json
orca terminal send --terminal <handle> --text "<task brief>" --enter --json
```
+2 -2
View File
@@ -99,7 +99,7 @@ describe('formatCliError', () => {
message: 'Parent selector was not found.',
data: {
nextSteps: [
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<id>, id:<worktreeId>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<worktreeId>, id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Retry with --no-parent to create without lineage.',
123
]
@@ -111,7 +111,7 @@ describe('formatCliError', () => {
expect(formatCliError(error)).toBe(
[
'Parent selector was not found.',
'Next step: Pass a valid --parent-worktree selector such as folder:<id>, worktree:<id>, id:<worktreeId>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Next step: Pass a valid --parent-worktree selector such as folder:<id>, worktree:<worktreeId>, id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Next step: Retry with --no-parent to create without lineage.'
].join('\n')
)
+5 -5
View File
@@ -236,9 +236,9 @@ Common Commands:
Selectors:
--repo <selector> Registered repo selector such as id:<id>, name:<name>, or path:<path>
--worktree <selector> Worktree selector such as id:<id>, name:<displayName>, branch:<branch>, issue:<number>, path:<path>, or active/current
--worktree <selector> Worktree selector such as id:<repo-id>::<path>, name:<displayName>, branch:<branch>, issue:<number>, path:<path>, or active/current
--terminal <handle> Runtime-issued terminal handle returned by \`orca terminal list --json\`
--parent-worktree <selector> Parent worktree selector such as id:<id>, branch:<branch>, issue:<number>, path:<path>, or active/current
--parent-worktree <selector> Parent worktree selector such as id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<path>, or active/current
--no-parent Force no parent lineage for unrelated worktree creation/update
Terminal Send Options:
@@ -446,7 +446,7 @@ function formatCommandFlagHelp(flag: string, commandPath: string[]): string {
return '--parent-current Use the current linked issue as parent'
}
if (command === 'worktree create' && flag === 'parent-worktree') {
return '--parent-worktree <selector> Parent selector such as active/current, id:<id>, branch:<branch>, issue:<number>, path:<path>, folder:<id>, or worktree:<id>'
return '--parent-worktree <selector> Parent selector such as active/current, id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<path>, folder:<id>, or worktree:<worktreeId>'
}
if (command === 'orchestration task-create' && flag === 'task-title') {
return '--task-title <text> Concise title for the orchestration task'
@@ -501,7 +501,7 @@ export function formatFlagHelp(flag: string): string {
'no-screenshot': '--no-screenshot Skip screenshot capture after the operation',
pages: '--pages <n> Number of scroll pages',
'parent-worktree':
'--parent-worktree <selector> Parent worktree selector such as id:<id>, branch:<branch>, issue:<number>, path:<path>, or active/current',
'--parent-worktree <selector> Parent worktree selector such as id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<path>, or active/current',
path: '--path <path> Path argument for the command',
prompt: '--prompt <text> Prompt text for agent-backed commands',
query: '--query <text> Search text for matching refs',
@@ -525,7 +525,7 @@ export function formatFlagHelp(flag: string): string {
'to-x': '--to-x <x> Destination window-local x coordinate',
'to-y': '--to-y <y> Destination window-local y coordinate',
worktree:
'--worktree <selector> Worktree selector such as id:<id>, name:<displayName>, branch:<branch>, issue:<number>, path:<path>, or active/current',
'--worktree <selector> Worktree selector such as id:<repo-id>::<path>, name:<displayName>, branch:<branch>, issue:<number>, path:<path>, or active/current',
workspace: '--workspace <selector> Existing worktree selector for automation runs',
'workspace-status':
'--workspace-status <id> Board status id (defaults: todo, in-progress, in-review, completed)',
+5 -2
View File
@@ -446,7 +446,7 @@ describe('orca root help', () => {
expect(createHelp).not.toContain('folderWorkspaceId')
expect(createHelp).toContain('folder:<id>')
expect(createHelp).toContain('folder:<folderId>')
expect(createHelp).toContain('worktree:<id>')
expect(createHelp).toContain('worktree:<worktreeId>')
expect(createHelp).toContain(
'--no-parent only affects Orca lineage; omit --base-branch to use the repo default base'
)
@@ -756,6 +756,9 @@ describe('orca cli worktree awareness', () => {
expect([...logSpy.mock.calls, ...errSpy.mock.calls].flat().join('\n')).toContain(
'current is a local cwd shortcut and cannot be resolved against a remote runtime.'
)
expect([...logSpy.mock.calls, ...errSpy.mock.calls].flat().join('\n')).toContain(
'id:<repo-id>::<path>'
)
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
@@ -1886,7 +1889,7 @@ describe('orca cli worktree awareness', () => {
message: 'Parent selector was not found.',
data: {
nextSteps: [
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<id>, id:<worktreeId>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<worktreeId>, id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Retry with --no-parent to create without lineage.'
]
}
+1 -1
View File
@@ -39,7 +39,7 @@ function assertLocalCwdWorktreeSelector(selector: string, client: RuntimeClient)
// server, so cwd-derived worktree selectors are only valid locally.
throw new RuntimeClientError(
'invalid_argument',
`${selector} is a local cwd shortcut and cannot be resolved against a remote runtime. Pass an explicit server-side worktree selector such as id:<id>, name:<displayName>, branch:<branch>, issue:<number>, or path:<absolute-server-path>.`
`${selector} is a local cwd shortcut and cannot be resolved against a remote runtime. Pass an explicit server-side worktree selector such as id:<repo-id>::<path>, name:<displayName>, branch:<branch>, issue:<number>, or path:<absolute-server-path>.`
)
}
+1 -1
View File
@@ -111,7 +111,7 @@ export const CORE_COMMAND_SPECS: CommandSpec[] = [
'By default, Orca records the new worktree as a child of the caller context when it can infer one from the Orca terminal or current directory.',
'If --repo is omitted, Orca infers the repo from the current Orca-managed worktree.',
'Use --project with --host to create on a ready project host setup without spelling the backing repo id.',
'For related work, use the inferred parent or pass --parent-worktree active, folder:<id>, or worktree:<id> to make the relationship explicit.',
'For related work, use the inferred parent or pass --parent-worktree active, folder:<id>, or worktree:<worktreeId> to make the relationship explicit. Worktree ids are the full <repo-id>::<path> values returned by `orca worktree list --json`.',
'Use --no-parent when the new worktree should be independent of the current context.',
'--no-parent only affects Orca lineage; omit --base-branch to use the repo default base, or pass the default base ref explicitly for independent top-level work.',
'By default this creates the worktree and its first terminal without switching the active Orca view.',
+101
View File
@@ -2257,6 +2257,20 @@ describe('OrcaRuntimeService', () => {
expect(internals.ptysById.has('cwd-only-pty')).toBe(false)
})
it('keeps unknown bare terminal-list ids on the no-scan exact-id path', async () => {
vi.mocked(listWorktrees).mockClear()
vi.mocked(listWorktrees).mockRejectedValue(
new Error('unknown explicit ids should not rescan worktrees')
)
const runtime = createRuntime()
await expect(runtime.listTerminals('id:not-a-repo')).resolves.toMatchObject({
terminals: [],
totalCount: 0
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('matches explicit-id cwd PTYs for folder workspace instance IDs', async () => {
const folderWorktreeId = `${TEST_REPO_ID}::${TEST_FOLDER_WORKSPACE_PATH}${FOLDER_WORKSPACE_INSTANCE_SEPARATOR}11111111-1111-4111-8111-111111111111`
vi.mocked(listWorktrees).mockClear()
@@ -2579,6 +2593,72 @@ describe('OrcaRuntimeService', () => {
).rejects.toThrow('selector_not_found')
})
it('guides bare repo-id worktree selectors to the full id shape', async () => {
vi.mocked(listWorktrees).mockClear()
vi.mocked(listWorktrees).mockRejectedValue(new Error('bare repo ids should not scan worktrees'))
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree(`id:${TEST_REPO_ID}`)).rejects.toThrow(
'Worktree id selectors must use the full <repo-id>::<path> value.'
)
expect(listWorktrees).not.toHaveBeenCalled()
})
it('guides registered SSH repo ids without probing the provider', async () => {
const remoteRepo = { ...store.getRepos()[0], connectionId: 'ssh-1' }
const remoteStore = {
...store,
getRepos: () => [remoteRepo],
getRepo: (id: string) => (id === remoteRepo.id ? remoteRepo : undefined)
}
vi.mocked(listWorktrees).mockClear()
getSshGitProviderMock.mockClear()
const runtime = new OrcaRuntimeService(remoteStore)
await expect(runtime.showManagedWorktree(`id:${TEST_REPO_ID}`)).rejects.toMatchObject({
code: 'worktree_id_requires_full_path'
})
expect(listWorktrees).not.toHaveBeenCalled()
expect(getSshGitProviderMock).not.toHaveBeenCalled()
})
it('rejects bare repo ids through terminal list RPC with the structured code', async () => {
vi.mocked(listWorktrees).mockClear()
const runtime = new OrcaRuntimeService(store)
const dispatcher = new RpcDispatcher({ runtime, methods: TERMINAL_METHODS })
const response = await dispatcher.dispatch(
makeRpcRequest('terminal.list', { worktree: `id:${TEST_REPO_ID}` })
)
expect(response).toMatchObject({
ok: false,
error: {
code: 'worktree_id_requires_full_path',
message: expect.stringContaining('full <repo-id>::<path> value')
}
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('rejects bare repo ids through the mobile session exact-id fast path', async () => {
vi.mocked(listWorktrees).mockClear()
const runtime = new OrcaRuntimeService(store)
await expect(runtime.listMobileSessionTabs(`id:${TEST_REPO_ID}`)).rejects.toMatchObject({
code: 'worktree_id_requires_full_path'
})
expect(listWorktrees).not.toHaveBeenCalled()
})
it('still resolves the full worktree id selector', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree(`id:${TEST_WORKTREE_ID}`)).resolves.toMatchObject({
id: TEST_WORKTREE_ID
})
})
it('still throws selector_not_found for an unknown id selector', async () => {
const runtime = new OrcaRuntimeService(store)
@@ -2587,6 +2667,27 @@ describe('OrcaRuntimeService', () => {
)
})
it('still throws selector_not_found for unknown bare ids', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree('id:not-a-repo')).rejects.toThrow('selector_not_found')
})
it('does not treat partial repo ids as full worktree ids', async () => {
const runtime = new OrcaRuntimeService(store)
await expect(runtime.showManagedWorktree('id:repo')).rejects.toThrow('selector_not_found')
})
it('preserves full-id guidance for explicit parent-worktree lineage selectors', async () => {
const runtime = new OrcaRuntimeService(store)
const resolveLineage = runtime['resolveLineageForWorktreeCreate'].bind(runtime)
await expect(resolveLineage({ parentWorktree: `id:${TEST_REPO_ID}` })).rejects.toThrow(
'Worktree id selectors must use the full <repo-id>::<path> value.'
)
})
it('does not reuse stale in-flight worktree scans after creating a worktree', async () => {
const runtime = new OrcaRuntimeService(store)
const staleScan = deferred<typeof MOCK_GIT_WORKTREES>()
+50 -21
View File
@@ -179,6 +179,7 @@ import type { FeatureInteractionId } from '../../shared/feature-interactions'
import type { TerminalPaneSplitSource } from '../../shared/feature-education-telemetry'
import {
FOLDER_WORKSPACE_INSTANCE_SEPARATOR,
WORKTREE_ID_SEPARATOR,
splitWorktreeId,
splitWorktreeIdForFilesystem
} from '../../shared/worktree-id'
@@ -2015,6 +2016,16 @@ class RuntimeLineageError extends Error {
}
}
class WorktreeIdRequiresFullPathError extends Error {
readonly code = 'worktree_id_requires_full_path'
constructor() {
super(
'Worktree id selectors must use the full <repo-id>::<path> value. Use the id from `orca worktree list --json`, or target by path:<path>, branch:<branch>, or issue:<number>.'
)
}
}
type ResolvedWorktreeCache = {
expiresAt: number
worktrees: ResolvedWorktree[]
@@ -3196,7 +3207,7 @@ export class OrcaRuntimeService {
}
async listMobileSessionTabs(worktreeSelector: string): Promise<RuntimeMobileSessionTabsResult> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
if (explicitWorktreeId) {
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(explicitWorktreeId)
await this.refreshMobileSessionPtyRecords()
@@ -4180,7 +4191,7 @@ export class OrcaRuntimeService {
leafId?: string,
opts: { notifyClients?: boolean } = {}
): Promise<RuntimeMobileSessionTabsResult> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(worktreeId)
@@ -4456,7 +4467,7 @@ export class OrcaRuntimeService {
}
async closeMobileSessionTab(worktreeSelector: string, tabId: string): Promise<{ closed: true }> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(worktreeId)
@@ -4651,7 +4662,7 @@ export class OrcaRuntimeService {
worktreeSelector: string,
move: RuntimeMobileSessionTabMove
): Promise<RuntimeMobileSessionTabMoveResult> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(worktreeId)
@@ -4707,7 +4718,7 @@ export class OrcaRuntimeService {
titlesByLeafId?: Record<string, string>
}
): Promise<{ updated: true }> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
// Why: when a renderer is authoritative (desktop host reached via shared
@@ -4740,7 +4751,7 @@ export class OrcaRuntimeService {
viewMode?: 'terminal' | 'chat'
}
): Promise<{ updated: true }> {
const explicitWorktreeId = getExplicitWorktreeIdSelector(worktreeSelector)
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
const worktreeId =
explicitWorktreeId ?? (await this.resolveWorktreeSelector(worktreeSelector)).id
// Why: a renderer-authoritative host owns + republishes tab props, so a
@@ -9692,7 +9703,7 @@ export class OrcaRuntimeService {
}
const graphEpoch = this.graphStatus === 'ready' ? this.rendererGraphEpoch : null
const explicitTargetWorktreeId = worktreeSelector
? getExplicitWorktreeIdSelector(worktreeSelector)
? this.getValidatedExplicitWorktreeIdSelector(worktreeSelector)
: null
const initialResolvedWorktreeCache = this.resolvedWorktreeCache
const cachedResolvedWorktrees =
@@ -19064,7 +19075,22 @@ export class OrcaRuntimeService {
}
}
private getValidatedExplicitWorktreeIdSelector(selector: string | undefined): string | null {
const worktreeId = getExplicitWorktreeIdSelector(selector)
if (
worktreeId &&
!worktreeId.includes(WORKTREE_ID_SEPARATOR) &&
this.store?.getRepo(worktreeId)
) {
// Why: registered repo ids are known-invalid worktree ids, so reject them
// before exact-id fast paths or Git/SSH worktree scans can hide the mistake.
throw new WorktreeIdRequiresFullPathError()
}
return worktreeId
}
private async resolveWorktreeSelector(selector: string): Promise<ResolvedWorktree> {
const explicitWorktreeId = this.getValidatedExplicitWorktreeIdSelector(selector)
const worktrees = await this.listResolvedWorktrees()
let candidates: ResolvedWorktree[]
@@ -19073,7 +19099,7 @@ export class OrcaRuntimeService {
}
if (selector.startsWith('id:')) {
const worktreeId = selector.slice(3)
const worktreeId = explicitWorktreeId ?? selector.slice(3)
candidates = worktrees.filter((worktree) => worktree.id === worktreeId)
if (candidates.length === 0) {
const parsed = splitWorktreeIdForFilesystem(worktreeId)
@@ -19200,6 +19226,15 @@ export class OrcaRuntimeService {
private async resolveLineageForWorktreeCreate(
input?: WorktreeLineageInput
): Promise<WorktreeLineageResolution> {
const parentSelectorNextSteps = [
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<worktreeId>, id:<repo-id>::<path>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Retry with --no-parent to create without lineage.'
]
const parentSelectorNotFoundMessage = (err: unknown): string =>
err instanceof WorktreeIdRequiresFullPathError
? err.message
: 'Parent selector was not found.'
if (!input) {
return { kind: 'none', warnings: [] }
}
@@ -19229,15 +19264,12 @@ export class OrcaRuntimeService {
origin: 'cli',
capture: { source: 'explicit-cli-flag', confidence: 'explicit' }
}
} catch {
} catch (err) {
throw new RuntimeLineageError(
'LINEAGE_PARENT_NOT_FOUND',
'Parent selector was not found.',
parentSelectorNotFoundMessage(err),
{
nextSteps: [
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<id>, id:<worktreeId>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Retry with --no-parent to create without lineage.'
]
nextSteps: parentSelectorNextSteps
}
)
}
@@ -19257,15 +19289,12 @@ export class OrcaRuntimeService {
origin: 'cli',
capture: { source: 'explicit-cli-flag', confidence: 'explicit' }
}
} catch {
} catch (err) {
throw new RuntimeLineageError(
'LINEAGE_PARENT_NOT_FOUND',
'Parent selector was not found.',
parentSelectorNotFoundMessage(err),
{
nextSteps: [
'Pass a valid --parent-worktree selector such as folder:<id>, worktree:<id>, id:<worktreeId>, branch:<branch>, issue:<number>, path:<absolute-path>, or active/current.',
'Retry with --no-parent to create without lineage.'
]
nextSteps: parentSelectorNextSteps
}
)
}
@@ -20450,7 +20479,7 @@ export class OrcaRuntimeService {
tabId: string
): Promise<string> {
const worktreeId =
getExplicitWorktreeIdSelector(worktreeSelector) ??
this.getValidatedExplicitWorktreeIdSelector(worktreeSelector) ??
(await this.resolveWorktreeSelector(worktreeSelector)).id
const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId)
const tab = snapshot?.tabs.find(
+17
View File
@@ -51,6 +51,9 @@ const RUNTIME_PASSTHROUGH_CODES: ReadonlySet<string> = new Set([
const COMPUTER_PASSTHROUGH_CODES: ReadonlySet<string> = new Set(Object.values(COMPUTER_ERROR_CODES))
const LINEAR_PASSTHROUGH_CODES: ReadonlySet<string> = new Set(LINEAR_ERROR_CODES)
const STRUCTURED_RUNTIME_PASSTHROUGH_CODES: ReadonlySet<string> = new Set([
'worktree_id_requires_full_path'
])
export function mapRuntimeError(id: string, meta: RpcEnvelopeMeta, error: unknown): RpcFailure {
const message = error instanceof Error ? error.message : String(error)
@@ -91,6 +94,20 @@ export function mapRuntimeError(id: string, meta: RpcEnvelopeMeta, error: unknow
(error as { data?: unknown }).data
)
}
if (
error instanceof Error &&
'code' in error &&
typeof (error as { code: unknown }).code === 'string' &&
STRUCTURED_RUNTIME_PASSTHROUGH_CODES.has((error as { code: string }).code)
) {
return errorResponse(
id,
meta,
(error as { code: string }).code,
message,
(error as { data?: unknown }).data
)
}
if (RUNTIME_PASSTHROUGH_CODES.has(message)) {
return errorResponse(id, meta, message, message)
}