Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): open terminal links in system browser (#949)
Kmny19cf508da45f
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/__tests__/xtermPool.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/__tests__/xtermPool.test.tsnew file mode 100644index 0000000000..6913ce7bcb--- /dev/null+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/__tests__/xtermPool.test.ts@@ -0,0 +1,64 @@+// @vitest-environment jsdom++import { afterEach, describe, expect, it, vi } from 'vitest';++import { openTerminalExternalLink } from '../xtermPool';++const { warn } = vi.hoisted(() => ({+ warn: vi.fn(),+}));++vi.mock('@/lib/logger', () => ({+ createLogger: () => ({ warn }),+}));++describe('openTerminalExternalLink', () => {+ afterEach(() => {+ vi.clearAllMocks();+ });++ it('routes detected URLs through the host external-link bridge', async () => {+ const openExternal = vi.fn().mockResolvedValue({ success: true });+ Object.defineProperty(window, 'electronAPI', {+ configurable: true,+ value: { openExternal },+ });++ const event = new MouseEvent('click');+ const url = 'https://git.example.com/project/-/merge_requests/42';++ openTerminalExternalLink(event, url);++ expect(openExternal).toHaveBeenCalledOnce();+ expect(openExternal).toHaveBeenCalledWith(url);+ await vi.waitFor(() => expect(warn).not.toHaveBeenCalled());+ });++ it('logs when the host rejects or cannot open the URL', async () => {+ const openExternal = vi.fn().mockResolvedValue({ success: false });+ Object.defineProperty(window, 'electronAPI', {+ configurable: true,+ value: { openExternal },+ });++ openTerminalExternalLink(new MouseEvent('click'), 'https://example.com/rejected');++ await vi.waitFor(() => {+ expect(warn).toHaveBeenCalledWith('terminal link open rejected or failed');+ });+ });++ it('logs when the external-link IPC call fails', async () => {+ const openExternal = vi.fn().mockRejectedValue(new Error('IPC unavailable'));+ Object.defineProperty(window, 'electronAPI', {+ configurable: true,+ value: { openExternal },+ });++ openTerminalExternalLink(new MouseEvent('click'), 'https://example.com/ipc-error');++ await vi.waitFor(() => {+ expect(warn).toHaveBeenCalledWith('terminal link open IPC failed');+ });+ });+});diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/xtermPool.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/xtermPool.tsindex 1e99c25cad..b64a2414a8 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/xtermPool.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/terminal/lib/xtermPool.ts@@ -24,6 +24,10 @@ import { Terminal, type ITerminalOptions } from '@xterm/xterm';import { FitAddon } from '@xterm/addon-fit';import { WebLinksAddon } from '@xterm/addon-web-links';+import { createLogger } from '@/lib/logger';++const log = createLogger('terminal');+export interface XtermEntry {terminal: Terminal;fitAddon: FitAddon;@@ -68,7 +72,11 @@ export function getOrCreateXterm(tabId: string): XtermEntry {if (entry) return entry;const terminal = new Terminal(DEFAULT_OPTIONS);const fitAddon = new FitAddon();- const webLinks = new WebLinksAddon();+ // xterm's default link handler uses `window.open()`. In an Electron+ // renderer that creates a popup window, which is intentionally blocked by+ // the app's window policy and leaves terminal links inert. Route the click+ // through the existing main-process URL allowlist instead.+ const webLinks = new WebLinksAddon(openTerminalExternalLink);terminal.loadAddon(fitAddon);terminal.loadAddon(webLinks);attachSelectionCopyShortcut(terminal);@@ -82,6 +90,27 @@ export function getOrCreateXterm(tabId: string): XtermEntry {return entry;}+/**+ * Open a link detected in the terminal through the privileged host bridge.+ *+ * The main-process `shell:open-external` handler validates the URL protocol+ * before delegating to the operating system, so the renderer never opens+ * arbitrary terminal output directly.+ */+export function openTerminalExternalLink(_event: MouseEvent, uri: string): void {+ void window.electronAPI+ .openExternal(uri)+ .then((result) => {+ if (!result.success) {+ // Do not log the URL: terminal output may contain sensitive query parameters.+ log.warn('terminal link open rejected or failed');+ }+ })+ .catch(() => {+ log.warn('terminal link open IPC failed');+ });+}+/*** 侧边栏宿主在"内嵌 ↔ 独立子窗口"间迁移时调用(MainLayout detach/attach 转换清理,* 两个方向都要):把所有 entry 的 ptyAttached 复位为 false,强制下次 mount 重新走