Repository navigation
Route terminal links based on pane ownership, not global state - #12233
Conversation
Terminal link clicks classified ownership from the global activeRuntimeEnvironmentId, which is null when runtimes are bound per workspace, so a link clicked in a remote-hosted pane opened a local-only Orca browser tab and never reached the host. Thread each pane's resolved runtimeEnvironmentId into openHttpLink as sourceOwner across the OSC 8, WebLinksAddon, and click-fallback paths. Co-authored-by: Orca <[email protected]>
Clicking links on remote-hosted panes was routing based on global runtime state, causing unexpected reconnections. Now link routing decisions (where to open: Orca vs system browser) are based on the actual pane's owner — local, SSH connection, remote runtime, or unknown — regardless of whether any runtime is globally active. This ensures a local pane can route to Orca while another pane's remote runtime is active, and a remote pane always routes to the system browser.
📝 WalkthroughWalkthroughThe change adds terminal HTTP URL extraction and per-pane source ownership resolution. Ownership now flows through terminal lifecycle handling, URL hit testing, OSC links, click hints, tooltips, and web-link routing. Runtime- and SSH-owned links use system-browser routing, while local links retain Orca routing. Localhost display labeling now uses the resolved source owner. Tests cover ownership, extraction, routing, modifier behavior, and pane-scoped tooltip callbacks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts (1)
86-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the duplicated sourceOwner fallback into a shared helper. Both sites compute the identical default:
deps.sourceOwner ?? (deps.runtimeEnvironmentId ? { kind: 'runtime', runtimeEnvironmentId: deps.runtimeEnvironmentId } : { kind: 'local' }). A shared helper keeps the two call sites in sync if the fallback rule changes.
src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts#L86-L90: replace the inline fallback with a call to a shared helper, e.g.resolveHttpLinkSourceOwnerFallback(deps.sourceOwner, deps.runtimeEnvironmentId).src/renderer/src/components/terminal-pane/terminal-web-link-click.ts#L34-L38: replace the inline fallback with the same shared helper call.♻️ Proposed shared helper
// e.g. in a shared location near HttpLinkSourceOwner's definition export function resolveHttpLinkSourceOwnerFallback( sourceOwner: HttpLinkSourceOwner | undefined, runtimeEnvironmentId: string | null | undefined ): HttpLinkSourceOwner { return ( sourceOwner ?? (runtimeEnvironmentId ? { kind: 'runtime', runtimeEnvironmentId } : { kind: 'local' }) ) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e4e00ed0-60b5-4a5f-a011-45435d0c3c86
📒 Files selected for processing (16)
src/renderer/src/components/terminal-pane/terminal-http-link-source-owner.test.tssrc/renderer/src/components/terminal-pane/terminal-http-link-source-owner.tssrc/renderer/src/components/terminal-pane/terminal-http-url-extraction.tssrc/renderer/src/components/terminal-pane/terminal-link-open-hints.test.tssrc/renderer/src/components/terminal-pane/terminal-link-open-hints.tssrc/renderer/src/components/terminal-pane/terminal-osc-link-routing.tssrc/renderer/src/components/terminal-pane/terminal-runtime-host-link-routing.test.tssrc/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.tssrc/renderer/src/components/terminal-pane/terminal-web-link-click.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/lib/http-link-modifier-routing.test.tssrc/renderer/src/lib/http-link-routing.test.tssrc/renderer/src/lib/http-link-routing.tssrc/renderer/src/lib/pane-manager/pane-dom-creation.test.tssrc/renderer/src/lib/pane-manager/pane-dom-creation.tssrc/renderer/src/lib/pane-manager/pane-manager-types.ts
| function findHttpUrlCandidateEnd(lineText: string, startIndex: number): number { | ||
| const scanEnd = Math.min(lineText.length, startIndex + TERMINAL_HTTP_URL_MAX_LENGTH + 1) | ||
| for (let index = startIndex; index < scanEnd; index += 1) { | ||
| if (isHttpUrlBodyTerminator(lineText.charCodeAt(index))) { | ||
| return index | ||
| } | ||
| } | ||
| return scanEnd | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix: parenthesized URLs get truncated at the first paren.
isHttpUrlBodyTerminator treats ( and ) as unconditional terminators. A URL that legitimately contains a paren, such as http://en.wikipedia.org/wiki/C_(programming_language), gets cut at the first (, producing http://en.wikipedia.org/wiki/C_ instead of the full URL.
Track paren balance in findHttpUrlCandidateEnd so an opening paren does not terminate the scan, and only an unmatched closing paren terminates it. Note that after this change, isHttpUrlTrailingPunctuation still unconditionally trims a trailing ), so a legitimately matched closing paren immediately followed by other trailing punctuation (for example a sentence period) can still get stripped; this needs a corresponding adjustment or a targeted test to confirm the final behavior.
Consider adding unit tests for extractTerminalHttpLinks covering parenthesized URLs, trailing punctuation, and the length-limit boundary; no dedicated test file for this function exists in this batch, which is likely why this edge case was not caught.
🐛 Proposed fix for paren handling in the scan
function findHttpUrlCandidateEnd(lineText: string, startIndex: number): number {
const scanEnd = Math.min(lineText.length, startIndex + TERMINAL_HTTP_URL_MAX_LENGTH + 1)
- for (let index = startIndex; index < scanEnd; index += 1) {
- if (isHttpUrlBodyTerminator(lineText.charCodeAt(index))) {
- return index
- }
- }
+ let parenDepth = 0
+ for (let index = startIndex; index < scanEnd; index += 1) {
+ const code = lineText.charCodeAt(index)
+ if (code === 0x28) {
+ parenDepth += 1
+ continue
+ }
+ if (code === 0x29) {
+ if (parenDepth === 0) {
+ return index
+ }
+ parenDepth -= 1
+ continue
+ }
+ if (isHttpUrlBodyTerminator(code)) {
+ return index
+ }
+ }
return scanEnd
} function isHttpUrlBodyTerminator(code: number): boolean {
return (
isAsciiWhitespace(code) ||
code === 0x22 ||
code === 0x27 ||
code === 0x21 ||
code === 0x2a ||
- code === 0x28 ||
- code === 0x29 ||
code === 0x7b ||Also applies to: 99-117, 119-143
Conflict resolution: `installHttpLinkClickFallback` deps — main added `getSourceOwner` (stablyai#12233, pane-owned link routing) and this branch added `getMouseEventsRequireAlt`. Both are independent optional deps on the same object, so both are kept; the merged `terminal-url-link-hit-testing.ts` already declares all three.
…yai#12233) * fix(terminal): route remote-runtime link clicks to the system browser Terminal link clicks classified ownership from the global activeRuntimeEnvironmentId, which is null when runtimes are bound per workspace, so a link clicked in a remote-hosted pane opened a local-only Orca browser tab and never reached the host. Thread each pane's resolved runtimeEnvironmentId into openHttpLink as sourceOwner across the OSC 8, WebLinksAddon, and click-fallback paths. Co-authored-by: Orca <[email protected]> * fix(terminal): route link clicks based on pane ownership, not global sta Clicking links on remote-hosted panes was routing based on global runtime state, causing unexpected reconnections. Now link routing decisions (where to open: Orca vs system browser) are based on the actual pane's owner — local, SSH connection, remote runtime, or unknown — regardless of whether any runtime is globally active. This ensures a local pane can route to Orca while another pane's remote runtime is active, and a remote pane always routes to the system browser. --------- Co-authored-by: Orca <[email protected]>
Summary
Fixes links clicked on remote-runtime and SSH panes incorrectly routing through the global active runtime state. Links are now routed based on the clicked pane's actual ownership (local, runtime-hosted, or SSH), preventing unwanted reconnections when clicking links on remote hosts.
Changes
resolveTerminalHttpLinkSourceOwner()to determine whether a pane is local, runtime-owned, or SSH-owned by inspecting its PTY ID and transport stateextractTerminalHttpLinks()for reuse across link handlershandleOscLink,handleTerminalWebLinkClick,installHttpLinkClickFallback) to receive and pass the source pane's ownershipterminalUrlOpenHintOptionsFor()to suppress the modifier-inversion hint when a remote pane cannot reach Orca, preventing false routing promisesScreenshots
No visual change
Testing
terminal-http-link-source-owner.test.tscovering local, runtime, SSH, and legacy remote PTY classificationterminal-runtime-host-link-routing.test.tscovering OSC 8, WebLinksAddon, and click-fallback routing for runtime-owned, SSH-owned, and local panespnpm lintpnpm typecheckpnpm testNotes
Workspace-bound runtimes are per-workspace, so
activeRuntimeEnvironmentIdis commonly null while a pane lives on a remote host. Link routing now correctly uses pane ownership instead of global runtime state. Local panes retain in-app routing when a different pane's runtime is active.