feat(web): choose whether links open in the default browser or in T3 Code #9339
Mergedjuliusmarmingemerged 4 commits into
main fromrefs/pull/9339/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/lib/openPullRequestLink.ts line 348OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -342,13 +343,6 @@342343 event.preventDefault();343344 if (!openInBrowser && openChangeRequest(event, prUrl, targetThreadRef)) return true;344345345- const api = readLocalApi();346- if (!api) {347- toastManager.add({348- type: "error",349- title: "Link opening is unavailable.",350- });351- return false;352- }353-354- void openPullRequestLink(api.shell, prUrl).catch((error) => {346+ // No project to show it in, so it is an ordinary link and follows the347+ // "Open links in" setting; the modifier still forces the system browser.348+ void openLink(prUrl, event).catch((error: unknown) => {apps/web/src/components/ChatMarkdown.tsx line 2497Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2475,3 +2476,18 @@2475- // the panel it opens offers the browser as one of its actions. Anything else is2476- // an ordinary link and keeps the `_blank` the shell already handles.2477- if (href) openChangeRequestLink(event, href);2476+ // the panel it opens offers the browser as one of its actions.2477+ if (!href || openChangeRequestLink(event, href)) return;2478+ // Anything else follows the "Open links in" setting. The system browser2479+ // keeps the `_blank` the shell already handles; the in-app browser needs2480+ // the click intercepted here. A modifier click is the way out of the2481+ // in-app default, so it is left to the shell too.2482+ if (2483+ event.defaultPrevented ||2484+ resolveLinkTarget({2485+ url: href,2486+ event,2487+ preference: getBrowserLinkTargetPreference(),2488+ canOpenInApp: canOpenInPreview,2489+ }) !== "app"2490+ ) {2491+ return;2492+ }2493+ event.preventDefault();apps/web/src/browser/useOpenLink.ts line 44OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +24,21 @@24+ * The in-app open falling over is reported through the returned promise, so25+ * the caller decides whether that deserves a toast; the system-browser path26+ * rejects the same way `shell.openExternal` does.27+ */28+export function useOpenLink(29+ threadRef: ScopedThreadRef | null | undefined,30+): (31+ url: string,32+ event?: { readonly metaKey: boolean; readonly ctrlKey: boolean },33+) => Promise<void> {34+ const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });35+ return useCallback(36+ async (url, event = NO_MODIFIER) => {37+ const target = resolveLinkTarget({38+ url,39+ event,40+ preference: getBrowserLinkTargetPreference(),41+ canOpenInApp: canOpenLinksInApp(Boolean(threadRef)),42+ });43+ if (target === "app" && threadRef) {44+ const result = await openUrlInPreview({ threadRef, url, openPreview });apps/web/src/browser/useOpenLink.ts line 40OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +20,21 @@20+ * beside a thread but are not markdown anchors: CI check details, a pull21+ * request that has no project to open in the panel. Without a thread there is22+ * nowhere to put an in-app tab, so the link goes to the system browser.23+ *24+ * The in-app open falling over is reported through the returned promise, so25+ * the caller decides whether that deserves a toast; the system-browser path26+ * rejects the same way `shell.openExternal` does.27+ */28+export function useOpenLink(29+ threadRef: ScopedThreadRef | null | undefined,30+): (31+ url: string,32+ event?: { readonly metaKey: boolean; readonly ctrlKey: boolean },33+) => Promise<void> {34+ const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });35+ return useCallback(36+ async (url, event = NO_MODIFIER) => {37+ const target = resolveLinkTarget({38+ url,39+ event,40+ preference: getBrowserLinkTargetPreference(),
- @@ -436,3 +438,4 @@436438 onRefresh,437439 }: {438440 environmentId: EnvironmentId;441+ threadRef: ScopedThreadRef | null;@@ -0,0 +26,21 @@26+ * rejects the same way `shell.openExternal` does.27+ */28+export function useOpenLink(29+ threadRef: ScopedThreadRef | null | undefined,30+): (31+ url: string,32+ event?: { readonly metaKey: boolean; readonly ctrlKey: boolean },33+) => Promise<void> {34+ const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });35+ return useCallback(36+ async (url, event = NO_MODIFIER) => {37+ const target = resolveLinkTarget({38+ url,39+ event,40+ preference: getBrowserLinkTargetPreference(),41+ canOpenInApp: canOpenLinksInApp(Boolean(threadRef)),42+ });43+ if (target === "app" && threadRef) {44+ const result = await openUrlInPreview({ threadRef, url, openPreview });45+ if (result._tag === "Success" || isAtomCommandInterrupted(result)) return;46+ throw new Error("Unable to open the link in T3 Code.", { cause: result.cause });
- apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx line 750Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -735,3 +745,4 @@735745 text={detail.body.trim().length > 0 ? detail.body : "_No description provided._"}736746 cwd={detail.workspaceRoot}737747 environmentId={environmentId}748+ threadRef={threadRef}
juliusmarminge merged this18062da
juliusmarminge closed this
Sign in to join this conversation.





Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
1aa44a0· PR result:69ee98f· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.