Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(browser): searchOrUrl (URL or Google search) helper
enes8947b14ed8f5
diff --git a/src/renderer/nodes/browserUrl.test.ts b/src/renderer/nodes/browserUrl.test.tsindex 093b7673c..fc0fecee1 100644--- a/src/renderer/nodes/browserUrl.test.ts+++ b/src/renderer/nodes/browserUrl.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { normalizeAddress } from './browserUrl'+import { normalizeAddress, searchOrUrl } from './browserUrl'describe('normalizeAddress', () => {it('passes http(s) URLs through (normalized)', () => {@@ -18,3 +18,26 @@ describe('normalizeAddress', () => {expect(normalizeAddress('')).toBeNull()})})++describe('searchOrUrl', () => {+ it('passes http(s) URLs through', () => {+ expect(searchOrUrl('https://x.com')).toBe('https://x.com/')+ expect(searchOrUrl('http://a.dev/p')).toBe('http://a.dev/p')+ })+ it('treats a bare host as https', () => {+ expect(searchOrUrl('github.com/a')).toBe('https://github.com/a')+ expect(searchOrUrl('example.com')).toBe('https://example.com/')+ })+ it('treats localhost / 127.0.0.1 as http (dev servers)', () => {+ expect(searchOrUrl('localhost:3000')).toBe('http://localhost:3000/')+ expect(searchOrUrl('127.0.0.1:8080/x')).toBe('http://127.0.0.1:8080/x')+ })+ it('Google-searches free text and non-http schemes', () => {+ expect(searchOrUrl('how to code')).toBe('https://www.google.com/search?q=how%20to%20code')+ expect(searchOrUrl('weather')).toBe('https://www.google.com/search?q=weather')+ expect(searchOrUrl('file:///etc/passwd')).toBe('https://www.google.com/search?q=file%3A%2F%2F%2Fetc%2Fpasswd')+ })+ it('returns null for empty', () => {+ expect(searchOrUrl(' ')).toBeNull()+ })+})diff --git a/src/renderer/nodes/browserUrl.ts b/src/renderer/nodes/browserUrl.tsindex 5500841df..8319548f9 100644--- a/src/renderer/nodes/browserUrl.ts+++ b/src/renderer/nodes/browserUrl.ts@@ -21,3 +21,40 @@ export function normalizeAddress(input: string): string | null {return null}}++function googleSearch(query: string): string {+ return `https://www.google.com/search?q=${encodeURIComponent(query)}`+}++/**+ * Turn an address-bar / start-page entry into a navigable http(s) URL, or a Google search for+ * free text. Returns null only for empty input. localhost/127.0.0.1 default to http (dev servers);+ * other bare hosts to https. Non-http schemes (file:/javascript:/…) are searched, never navigated.+ */+export function searchOrUrl(input: string): string | null {+ const raw = input.trim()+ if (!raw) return null+ // Explicit scheme. The negative lookahead keeps `host:port` (e.g. `localhost:3000`) out of the+ // scheme branch — a real URI scheme's colon is never immediately followed by a port digit.+ if (/^[a-z][a-z0-9+.-]*:(?!\d)/i.test(raw)) {+ if (/^https?:\/\//i.test(raw)) {+ try {+ return new URL(raw).toString()+ } catch {+ return googleSearch(raw)+ }+ }+ return googleSearch(raw)+ }+ // No scheme: is it a host?+ const isLocal = /^(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/i.test(raw)+ const looksHost = !/\s/.test(raw) && (isLocal || /^[^\s/]+\.[^\s/]+/.test(raw))+ if (looksHost) {+ try {+ return new URL(`${isLocal ? 'http' : 'https'}://${raw}`).toString()+ } catch {+ return googleSearch(raw)+ }+ }+ return googleSearch(raw)+}