From f4eea54498e113251c2e6dfae494f48801023678 Mon Sep 17 00:00:00 2001
From: blaise1030
Date: Sat, 6 Jun 2026 13:06:51 +0800
Subject: [PATCH 01/16] docs: add preview bridge design spec
---
.../specs/2026-06-06-preview-bridge-design.md | 136 ++++++++++++++++++
1 file changed, 136 insertions(+)
create mode 100644 docs/specs/2026-06-06-preview-bridge-design.md
diff --git a/docs/specs/2026-06-06-preview-bridge-design.md b/docs/specs/2026-06-06-preview-bridge-design.md
new file mode 100644
index 0000000..0371383
--- /dev/null
+++ b/docs/specs/2026-06-06-preview-bridge-design.md
@@ -0,0 +1,136 @@
+# Preview Bridge
+
+A live preview feature for browser-sidecar that mirrors Cursor's browser panel concept — but between two browser tabs instead of embedded in the IDE. The IDE detects running dev servers from terminal output, and `Cmd+click` opens a proxy-wrapped preview tab that stays in sync with the IDE.
+
+## Scope
+
+- Terminal URL detection with click / Cmd+click behaviour
+- Go reverse proxy that injects a control script into HTML responses
+- WebSocket hub on the Go backend relaying messages between IDE and preview tabs
+- Auto-refresh preview on file save
+- Element selection mode in the preview tab — captures CSS selector + screenshot and pastes into the active IDE terminal
+
+Out of scope for v1: bidirectional navigation, click-to-source-file, cross-origin support.
+
+---
+
+## 1. Terminal URL detection
+
+The terminal panel parses each output line with a regex for `https?://localhost:\d+(/\S*)?`. Matched URLs are rendered as clickable links inline in the terminal output.
+
+- **Normal click** → `window.open(url)` — opens raw dev server in new tab
+- **Cmd+click** → `window.open('/sidecar/proxy?target=' + encodeURIComponent(url))` — opens via sidecar proxy
+
+No new toolbar, button, or sidebar chrome needed. Works with any framework that prints a local URL on boot (Vite, Next.js, SvelteKit, etc.).
+
+---
+
+## 2. New pnpm package: `sidecar-client`
+
+A standalone package in the monorepo responsible for the injected browser script.
+
+```
+sidecar-client/
+ package.json ← name: @browser-sidecar/sidecar-client
+ vite.config.ts ← lib mode, iife format, single entry
+ src/
+ index.ts ← pill UI + WebSocket client + selection logic
+ dist/
+ client.js ← output embedded by Go
+```
+
+Added to `pnpm-workspace.yaml`. Built as part of `pnpm -r build`. VanJS bundled directly into the output — no host app dependencies required.
+
+---
+
+## 3. Go backend — new endpoints
+
+| Endpoint | Method | Purpose |
+|---|---|---|
+| `/sidecar/proxy` | GET | Reverse proxy to `?target=` URL. Rewrites HTML responses to inject `
`) {
+ t.Errorf("script not injected before : %s", out)
+ }
+}
+
+func TestInjectClientScript_appendsWhenNoBodyTag(t *testing.T) {
+ body := `