Skip to content

fix(branch-out): support Orca terminal handles and preserve cwd - #19

Merged
w-winter merged 2 commits into
w-winter:mainfrom
pstanton237:fix/orca-terminal-handle
Sep 14, 2026
Merged

w-winter merged 2 commits into
w-winter:mainfrom
pstanton237:fix/orca-terminal-handle

Conversation

@pstanton237

Copy link
Copy Markdown
Contributor

Why

/branch should open a copy of the current session beside the terminal that invoked it, without changing the project that session is working on.

In the Orca environment tested, the terminal provides ORCA_WORKTREE_ID and ORCA_TERMINAL_HANDLE, but no ORCA_PANE_KEY. The existing detection therefore skips Orca and rejects the default split request, even though Orca supplies a usable terminal identity.

Pi's working directory can also differ from the enclosing Orca workspace root. Without explicitly preserving that directory, the child can open the copied conversation in a different project.

Approach

  • Accept ORCA_TERMINAL_HANDLE as an alternative to the pane key and match it against a fresh terminal list scoped to the current worktree. This targets the caller rather than guessing from the active tab or selecting another pane. A stale handle fails without falling back to an unrelated terminal.
  • Keep the existing pane-key lookup when no handle is supplied.
  • Run cd <quoted current directory> && pi --session <quoted fork file> in the child. The parent directory is unchanged, and a failed cd prevents launching Pi in the wrong directory.

This is limited to compatibility within the existing Orca backend. No dependencies or configuration options are added. Other backends, session copying, focus restoration, and waiting for the current run to finish are unchanged.

Verification

  • node --test extensions/branch-out/orca.test.mjs passed. Checks cover handle-based detection, legacy pane-key lookup, stale-handle rejection, malformed JSON, exact split targeting, single-quote escaping in the directory, and split/focus command ordering.
  • node --experimental-strip-types --check extensions/branch-out/index.ts passed.
  • git diff --check passed.
  • A manual Orca 1.4.199 check opened the fork in a separate session with inherited conversation history and the original working directory. Existing parent-session entries remained unchanged; normal status hooks could still append entries.

Other terminal backends were not manually retested. Package publication is left to the maintainer.

Fixes #18

@w-winter

Copy link
Copy Markdown
Owner

thanks, this looks good. could you also update extensions/branch-out/README.md and packages/pi-branch-out/README.md to document ORCA_TERMINAL_HANDLE detection and the ORCA_PANE_KEY lookup path? the current docs still say ORCA_PANE_KEY is required

@pstanton237

pstanton237 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

could you also update extensions/branch-out/README.md and packages/pi-branch-out/README.md to document ORCA_TERMINAL_HANDLE detection and the ORCA_PANE_KEY lookup path?

Thanks for reviewing this and catching the missing documentation.

Updated both READMEs in 75dfbc5. They now describe handle-based detection, the tabId:leafId lookup when no handle is supplied, and rejection of stale handles without falling back to another terminal. They also clarify that the child retains the Pi session working directory.

The Orca regression test and git diff --check pass. No runtime code changed.

@w-winter

Copy link
Copy Markdown
Owner

thx!

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.

branch-out: Orca handle-only terminals are not detected

2 participants