← Back to Pull requests

feat(server): pages a terminal command opens show up in the thread's browser #44437

Open
unknown opened this pull request with 463 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 27, 2026 20:39 UTC
Author

Problem

When a command in an integrated terminal opens a browser, such as gh auth login --web, an OAuth device flow, or a dev server's --open, the page goes to the host machine's default browser. That's no use when T3 Code runs on a remote host or you're on web or mobile, and on a headless host there's no browser at all.

Demo

!Terminal links open in the thread's browser

An explainer of the flow; the UI is drawn, not a screen capture.

Change

Integrated terminals now set BROWSER to a small generated script that runs t3 browser open <url>. The command asks the running server (new POST /api/preview/open, preview:operate scope) to open the page as a new tab in the thread's browser panel. It uses the same PreviewManager.open path as a user opening a tab, so the tab works on every surface and belongs to the user, not an agent.

  • A BROWSER the user or provider already set, even an empty one, is kept.

  • If T3 Code can't open the page (no thread, server down, request fails), the command falls back to the host's browser through the existing launchBrowser, with BROWSER cleared so xdg-open can't loop. If that fails too, it prints the URL. It always exits 0, so tools like gh don't treat the fallback as an error.

  • Integrated terminals only; agent command environments are unchanged.

  • Windows is left out: a .cmd wrapper re-parses the & in the sign-in URLs this is for. The docs say so.

  • No BROWSER is set if the script path contains whitespace, quotes, a backslash, $ or a backtick, because tools shell-split the variable.
  • Scope

    A small feature from a vouched contributor. No existing issue; searched issues and PRs for BROWSER and terminal browser opening.

    Verification

    Live, against vp run dev from this branch in the web client:

  • In a thread's terminal, env shows BROWSER=<worktree>/.t3/userdata/bin/t3-browser.

  • Running it with https://example.com opened the page in that thread's floating browser preview, and the command printed exit=0.

  • The first version opened the tab under a synthetic agent caller, and the panel showed "Agent has control" with a "Take control" button. After switching to PreviewManager.open, a re-run showed "You have control". The tab now uses the user's default cookie profile and is not closed as an idle agent tab.

  • With no server running and no opener on PATH, the script prints the URL and exits 0. Run with no URL, it prints usage and exits 1.
  • Tests:

  • preview/ThreadBrowser.test.ts (new): an unknown thread fails and creates no tab; a known thread gets one server tab with reveal: true and no automationOwner. The automation-owner case fails on the first version.

  • preview/http.test.ts (new): auth scope, non-http(s) URL rejected, unknown thread returns 404.

  • terminal/browserCommand.test.ts (new): the script reaches this server's own state; no script on win32.

  • terminal/Manager.test.ts: a BROWSER from the server env or runtime env (even empty) is kept, on linux and on win32 with mixed-case keys.

  • cli/browser.test.ts: opens in the terminal's thread; falls back to this host when T3 can't open it or outside a thread's terminal; leaves non-web URLs to this host; prints the URL when nothing can open it.
  • vp run check:changed passes (format, lint, knip, graphql, typecheck, tests). Not checked: the desktop app's native tabs (the request always used the server browser, and the new path doesn't change that), mobile, and a real gh auth login --web round trip.

    Written with Claude Opus 5.5 in Claude Code.

    🤖 Generated with Claude Code

    Diff: 463 lines (+347 / -116) across 5 files Reviewer: mvanhorn Review duration: 3975m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 463 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #44437"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.3% · Safe to merge
    24.3%