Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor: docs and simplification of the usage

Luigi Agostie0f3a1b3cf4d
diff --git a/README.md b/README.md
index b527ce16..74e383e1 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,37 @@
## What is PinchTab?
-PinchTab is a **standalone HTTP server** that gives AI agents direct control over a Chrome browser.
+PinchTab is a **standalone HTTP server** that gives AI agents direct control over Chrome.
+
+It has two runtime roles:
+- `pinchtab` or `pinchtab server` — the full control-plane server
+- `pinchtab bridge` — a single-instance bridge runtime
+
+Most users only need the full server. It manages profiles, instances, routing, and the web dashboard. The `bridge` mode is the thin per-instance runtime used behind the scenes for managed child instances.
+
+### Process Model
+
+PinchTab is server-first:
+- start `pinchtab` for the full control plane
+- let the server manage profiles and instances
+- let each managed instance run behind a lightweight `pinchtab bridge` runtime
+
+In practice:
+- **Server** is the public product entrypoint
+- **Bridge** is the per-instance runtime for one browser
+- **Attach** is the advanced path for registering an externally managed Chrome
+
+### Primary Usage
+
+The primary user journey is:
+
+1. install Pinchtab
+2. run `pinchtab`
+3. point your agent or tool at `http://localhost:9867`
+4. let Pinchtab act as your local browser service
+
+That is the default “replace the browser runtime” scenario.
+Most users should not need to think about `pinchtab bridge` directly.
### Key Features
@@ -84,15 +114,22 @@ pinchtab text
Or use the HTTP API directly:
```bash
-# Navigate (returns tabId)
-TAB=$(curl -s -X POST http://localhost:9867/instances \
- -d '{"profile":"work"}' | jq -r '.id')
+# Create an instance (returns instance id)
+INST=$(curl -s -X POST http://localhost:9867/instances/launch \
+ -H "Content-Type: application/json" \
+ -d '{"name":"work","mode":"headless"}' | jq -r '.id')
+
+# Open a tab in that instance
+TAB=$(curl -s -X POST http://localhost:9867/instances/$INST/tabs/open \
+ -H "Content-Type: application/json" \
+ -d '{"url":"https://pinchtab.com"}' | jq -r '.tabId')
# Get snapshot
-curl "http://localhost:9867/instances/$TAB/snapshot?filter=interactive"
+curl "http://localhost:9867/tabs/$TAB/snapshot?filter=interactive"
# Click element
-curl -X POST "http://localhost:9867/instances/$TAB/action" \
+curl -X POST "http://localhost:9867/tabs/$TAB/action" \
+ -H "Content-Type: application/json" \
-d '{"kind":"click","ref":"e5"}'
```
@@ -100,12 +137,16 @@ curl -X POST "http://localhost:9867/instances/$TAB/action" \
## Core Concepts
+**Server** — The main PinchTab process. It manages profiles, instances, routing, and the dashboard.
+
**Instance** — A running Chrome process. Each instance can have one profile.
**Profile** — Browser state (cookies, history, local storage). Log in once, stay logged in across restarts.
**Tab** — A single webpage. Each instance can have multiple tabs.
+**Bridge** — The single-instance runtime behind a managed instance. Usually spawned by the server, not started manually.
+
Read more in the [Core Concepts](https://pinchtab.com/docs/core-concepts) guide.
---
@@ -121,7 +162,7 @@ Read more in the [Core Concepts](https://pinchtab.com/docs/core-concepts) guide.
| **Persistent sessions** | ✅ |
| **Binary size** | ✅ |
| **Multi-instance** | ✅ |
-| **Remote Chrome** | ✅ |
+| **External Chrome attach** | ✅ |
---
@@ -168,7 +209,7 @@ Full docs at **[pinchtab.com/docs](https://pinchtab.com/docs)**
- **[Headless vs Headed](https://pinchtab.com/docs/headless-vs-headed)** — Choose the right mode
- **[API Reference](https://pinchtab.com/docs/api-reference)** — HTTP endpoints
- **[CLI Reference](https://pinchtab.com/docs/cli-reference)** — Command-line commands
-- **[Configuration](https://pinchtab.com/docs/configuration)** — Environment variables
+- **[Configuration](https://pinchtab.com/docs/configuration)** — Config file and runtime settings
### MCP (SMCP) integration
@@ -201,12 +242,16 @@ pinchtab text # ~800 tokens instead of 10,000
```bash
# Run multiple instances in parallel
-pinchtab instances create --profile=alice --port=9868
-pinchtab instances create --profile=bob --port=9869
+curl -s -X POST http://localhost:9867/instances/start \
+ -H "Content-Type: application/json" \
+ -d '{"profileId":"alice","mode":"headless"}'
+
+curl -s -X POST http://localhost:9867/instances/start \
+ -H "Content-Type: application/json" \
+ -d '{"profileId":"bob","mode":"headless"}'
# Each instance is isolated
-curl http://localhost:9868/text?tabId=X # Alice's instance
-curl http://localhost:9869/text?tabId=Y # Bob's instance
+curl http://localhost:9867/instances
```
---
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index ae1f305b..1dfad1cf 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -20,7 +20,9 @@ func printHelp() {
fmt.Printf(`pinchtab %s - Browser control for AI agents
MODES:
- pinchtab Start server (default port 9867)
+ pinchtab Start full server (default)
+ pinchtab server Start full server explicitly
+ pinchtab bridge Start single-instance bridge-only server
pinchtab connect <name> Get URL for a running profile
QUICK START (requires running server):
@@ -78,9 +80,9 @@ PDF FLAGS:
ENVIRONMENT:
PINCHTAB_URL Server URL (default: http://127.0.0.1:9867)
- PINCHTAB_TOKEN Auth token (or BRIDGE_TOKEN for server)
- BRIDGE_PORT Server port (default: 9867)
- BRIDGE_HEADLESS Run Chrome headless (default: true)
+ PINCHTAB_TOKEN Auth token
+ PINCHTAB_PORT Server port (default: 9867)
+ CHROME_BIN Chrome binary path
FLAGS (global, place before or after command):
--instance <id> Target a specific instance by ID (e.g., pinchtab nav --instance abc123 https://...)
@@ -197,7 +199,7 @@ QUICK START:
pinchtab quick <url> Navigate and show page structure (combines nav + snap)
WORKFLOW:
- 1. Start server: pinchtab (runs on :9867)
+ 1. Start server: pinchtab (or: pinchtab server)
2. Navigate: pinchtab nav https://pinchtab.com
3. See page: pinchtab snap (shows clickable refs)
4. Interact: pinchtab click e5 (click element)
@@ -1222,7 +1224,7 @@ func checkServerAndGuide(client *http.Client, base, token string) bool {
To start the server:
pinchtab # Run in foreground (recommended for beginners)
pinchtab & # Run in background
- pinchtab --port 9868 # Use different port
+ PINCHTAB_PORT=9868 pinchtab # Use different port
Then try your command again:
%s
@@ -1238,7 +1240,7 @@ Learn more: https://github.com/pinchtab/pinchtab#quick-start
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode == 401 {
- fmt.Fprintf(os.Stderr, "❌ Authentication required. Set BRIDGE_TOKEN or PINCHTAB_TOKEN environment variable.\n")
+ fmt.Fprintf(os.Stderr, "❌ Authentication required. Set PINCHTAB_TOKEN.\n")
return false
}
diff --git a/cmd/pinchtab/main.go b/cmd/pinchtab/main.go
index d70c532d..82c7701d 100644
--- a/cmd/pinchtab/main.go
+++ b/cmd/pinchtab/main.go
@@ -9,6 +9,22 @@ import (
var version = "dev"
+func startupMode(args []string) (string, bool) {
+ if os.Getenv("PINCHTAB_ONLY") == "1" || os.Getenv("BRIDGE_ONLY") == "1" {
+ return "bridge", true
+ }
+ if len(args) <= 1 {
+ return "server", true
+ }
+ switch args[1] {
+ case "server":
+ return "server", true
+ case "bridge":
+ return "bridge", true
+ }
+ return "", false
+}
+
func main() {
cfg := config.Load()
@@ -38,13 +54,19 @@ func main() {
return
}
- // Check if running as bridge-only instance (spawned by orchestrator)
- if os.Getenv("PINCHTAB_ONLY") == "1" || os.Getenv("BRIDGE_ONLY") == "1" {
- runBridgeServer(cfg)
- return
+ mode, ok := startupMode(os.Args)
+ if !ok {
+ fmt.Fprintf(os.Stderr, "unknown command: %s\n\n", os.Args[1])
+ printHelp()
+ os.Exit(1)
}
- // Default: run dashboard mode
- // (includes 'pinchtab' with no args and unrecognized args like 'dashboard')
- runDashboard(cfg)
+ switch mode {
+ case "bridge":
+ runBridgeServer(cfg)
+ case "server":
+ runDashboard(cfg)
+ default:
+ runDashboard(cfg)
+ }
}
diff --git a/cmd/pinchtab/main_test.go b/cmd/pinchtab/main_test.go
index 5a9a3253..a44b5619 100644
--- a/cmd/pinchtab/main_test.go
+++ b/cmd/pinchtab/main_test.go
@@ -23,3 +23,38 @@ func TestServerTimeoutOrdering(t *testing.T) {
t.Errorf("WriteTimeout (%v) should be less than IdleTimeout (%v)", write, idle)
}
}
+
+func TestStartupMode(t *testing.T) {
+ t.Setenv("PINCHTAB_ONLY", "")
+ t.Setenv("BRIDGE_ONLY", "")
+
+ tests := []struct {
+ name string
+ args []string
+ env map[string]string
+ want string
+ ok bool
+ }{
+ {name: "default", args: []string{"pinchtab"}, want: "server", ok: true},
+ {name: "server explicit", args: []string{"pinchtab", "server"}, want: "server", ok: true},
+ {name: "bridge explicit", args: []string{"pinchtab", "bridge"}, want: "bridge", ok: true},
+ {name: "unknown rejected", args: []string{"pinchtab", "weird"}, want: "", ok: false},
+ {name: "dashboard rejected", args: []string{"pinchtab", "dashboard"}, want: "", ok: false},
+ {name: "env bridge", args: []string{"pinchtab"}, env: map[string]string{"PINCHTAB_ONLY": "1"}, want: "bridge", ok: true},
+ {name: "legacy env bridge", args: []string{"pinchtab"}, env: map[string]string{"BRIDGE_ONLY": "1"}, want: "bridge", ok: true},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Setenv("PINCHTAB_ONLY", "")
+ t.Setenv("BRIDGE_ONLY", "")
+ for k, v := range tt.env {
+ t.Setenv(k, v)
+ }
+ got, ok := startupMode(tt.args)
+ if ok != tt.ok || got != tt.want {
+ t.Fatalf("startupMode(%v) = (%q, %v), want (%q, %v)", tt.args, got, ok, tt.want, tt.ok)
+ }
+ })
+ }
+}
diff --git a/docs/architecture/chrome-lifecycle-and-orchestration.md b/docs/architecture/chrome-lifecycle-and-orchestration.md
index c389d5a7..bc84985d 100644
--- a/docs/architecture/chrome-lifecycle-and-orchestration.md
+++ b/docs/architecture/chrome-lifecycle-and-orchestration.md
@@ -1,13 +1,13 @@
# Orchestration
-Pinchtab is a Go-based bridge and orchestrator for Chrome. It doesn't just "run" a browser; it manages a fleet of "sanitized" Chrome instances, hardened against detection and optimized for automation.
+Pinchtab is a Go-based server and bridge system for Chrome. It doesn't just "run" a browser; it manages a fleet of isolated instances, hardened against detection and optimized for automation.
## 1. Allocator Strategy
-The foundation of every Chrome instance is the chromedp Allocator. Pinchtab supports two modes:
+The foundation of every managed Chrome instance is the chromedp allocator. Pinchtab primarily uses local launch:
-- **Remote Connection:** If `CDP_URL` is set, Pinchtab connects to an existing Chrome instance via the DevTools Protocol (CDP).
-- **Local Launch:** By default, it uses `NewExecAllocator` to spawn a new Chrome process on the local machine with a dedicated profile and port.
+- **Managed Launch:** the server spawns a dedicated `pinchtab bridge` child process, which uses `NewExecAllocator` to launch Chrome with a dedicated profile and port.
+- **Attach:** separately, the server can register an externally managed Chrome instance through the attach API when attach policy allows it.
## 2. Hardening & Launch Flags
@@ -19,7 +19,7 @@ When launching locally, Pinchtab applies a comprehensive set of command-line fla
## 3. Instance Orchestration
-The Orchestrator (`orchestrator_runtime.go`) handles the lifecycle of multiple independent Chrome processes:
+The orchestrator handles the lifecycle of multiple independent Chrome processes:
- **Process Isolation:** Each instance runs as a separate OS process with its own PID.
- **Health Monitoring:** After launching a process, the Orchestrator polls the instance's `/health` endpoint until it is ready to accept commands.
@@ -45,5 +45,5 @@ Once the browser is running, the `TabManager` (`tab_manager.go`) tracks all open
- **Context Lifecycle:** Manages the creation and cancellation of Go `context.Context` objects for each tab.
- **Setup Hooks:** Automatically reapplies stealth and optimization scripts to every new tab opened by the user or by automation scripts.
-- **Tab Limits:** Enforces `BRIDGE_MAX_TABS` (default 20) to prevent runaway agents from consuming all memory.
+- **Tab Limits:** Enforces the configured max-tab policy to prevent runaway agents from consuming all memory.
- **Stale Tab Cleanup:** Periodically removes tabs that no longer exist in Chrome.
diff --git a/docs/architecture/instance-model-charts.md b/docs/architecture/instance-model-charts.md
new file mode 100644
index 00000000..29d80c13
--- /dev/null
+++ b/docs/architecture/instance-model-charts.md
@@ -0,0 +1,106 @@
+# Instance Model Charts
+
+This page collects the visual mental model for Pinchtab instances.
+
+It complements:
+- [Architecture](pinchtab-architecture.md)
+- [Managed Bridge vs Managed Direct-CDP](managed-bridge-vs-managed-direct-cdp.md)
+
+## Chart 1: Current High-Level Model
+
+```mermaid
+flowchart LR
+ U["User / Agent"] --> S["Pinchtab Server"]
+
+ S --> I1["Managed Instance"]
+ I1 --> B["Bridge process"]
+ B --> C["Chrome"]
+ C --> T["Tabs"]
+
+ S -. attach .-> E["External Chrome"]
+ E --> T2["Tabs"]
+```
+
+## Chart 2: Instance Kinds
+
+```mermaid
+flowchart TD
+ I["Instance"] --> K{"Kind"}
+
+ K --> A["attached-external"]
+ K --> B["managed-bridge"]
+ K --> C["managed-direct-cdp"]
+ K --> D["adopted / handover"]
+
+ A --> A1["Pinchtab did not launch browser"]
+ B --> B1["Pinchtab launched bridge process"]
+ C --> C1["Pinchtab launched browser directly"]
+ D --> D1["Browser was created elsewhere, then handed to server"]
+```
+
+## Chart 3: Communication Paths
+
+```mermaid
+flowchart LR
+ S["Pinchtab Server"]
+
+ S -->|HTTP| B["Bridge instance"]
+ B -->|CDP| C1["Chrome"]
+
+ S -->|CDP| C2["Direct-CDP instance"]
+
+ S -->|CDP| C3["Attached external Chrome"]
+```
+
+## Chart 4: Lifecycle Ownership
+
+```mermaid
+flowchart TD
+ M["Instance lifecycle"] --> L1["Launch by Pinchtab"]
+ M --> L2["Attach existing browser"]
+ M --> L3["Adopt then manage"]
+ M --> L4["Create then hand over"]
+
+ L1 --> X1["Pinchtab owns start/stop"]
+ L2 --> X2["Pinchtab routes, but may not own process"]
+ L3 --> X3["Pinchtab takes over ownership after attach"]
+ L4 --> X4["Pinchtab creates browser, then another controller owns it"]
+```
+
+## Chart 5: Recommended Taxonomy
+
+```mermaid
+flowchart TD
+ S["Pinchtab Server / Control Plane"]
+
+ S --> R["Instance Registry"]
+
+ R --> I1["managed-bridge"]
+ R --> I2["managed-direct-cdp"]
+ R --> I3["attached-external"]
+
+ I1 --> P1["Transport: HTTP -> bridge -> CDP"]
+ I2 --> P2["Transport: direct CDP"]
+ I3 --> P3["Transport: direct CDP"]
+
+ P1 --> T1["Tabs"]
+ P2 --> T2["Tabs"]
+ P3 --> T3["Tabs"]
+```
+
+## Recommended Reading Of These Charts
+
+The cleanest interpretation is:
+
+- `source` answers who introduced the instance
+- `runtime` answers how Pinchtab reaches the browser
+- `ownership` answers who controls lifecycle
+
+For the current architecture, the useful combinations are:
+
+- `managed + bridge + pinchtab`
+- `attached + direct-cdp + external`
+
+And the main future option is:
+
+- `managed + direct-cdp + pinchtab`
diff --git a/docs/architecture/managed-bridge-vs-managed-direct-cdp.md b/docs/architecture/managed-bridge-vs-managed-direct-cdp.md
new file mode 100644
index 00000000..f70816db
--- /dev/null
+++ b/docs/architecture/managed-bridge-vs-managed-direct-cdp.md
@@ -0,0 +1,160 @@
+# Managed Bridge vs Managed Direct-CDP
+
+This page compares two ways Pinchtab can manage a browser instance:
+
+- `managed + bridge`
+- `managed + direct-cdp`
+
+Both are **managed** because Pinchtab owns the instance lifecycle.
+The difference is where the browser control logic lives and how the server reaches Chrome.
+
+## Short Version
+
+```text
+managed + bridge
+ server -> bridge -> Chrome
+
+managed + direct-cdp
+ server -> Chrome
+```
+
+The bridge model adds one extra process and one extra hop.
+The direct-CDP model removes that hop and keeps control in the main server.
+
+## Chart 1: Runtime Shape
+
+```text
+Managed + bridge
+ Pinchtab server
+ └─ Pinchtab bridge child
+ └─ Chrome
+ └─ Tabs
+
+Managed + direct-cdp
+ Pinchtab server
+ └─ Chrome
+ └─ Tabs
+```
+
+## Managed + Bridge
+
+### What it is
+
+Pinchtab starts a child `pinchtab bridge` process for each managed instance.
+That bridge owns one browser and exposes a single-instance HTTP API.
+The main server routes instance and tab requests to that child.
+
+### Communication Path
+
+```text
+agent -> server -> bridge -> Chrome
+```
+
+### Benefits
+
+- strong per-instance isolation
+- clearer process boundaries
+- easier crash containment
+- easier per-instance logs and health checks
+- easier to reason about operationally as a worker model
+
+### Costs
+
+- one extra process per instance
+- one extra HTTP hop before reaching Chrome
+- more ports to allocate and monitor
+- more startup overhead
+- some configuration must be propagated to child runtimes
+
+### Best fit
+
+- multi-instance orchestration
+- strong isolation between instances
+- cases where instance failures should stay local
+- systems that benefit from worker-style process supervision
+
+## Managed + Direct-CDP
+
+### What it is
+
+Pinchtab starts Chrome itself and keeps the CDP session inside the main server process.
+There is no bridge child and no extra per-instance HTTP server.
+
+### Communication Path
+
+```text
+agent -> server -> Chrome
+```
+
+### Benefits
+
+- fewer moving parts
+- lower latency
+- less process and port overhead
+- simpler network model
+- less duplicated HTTP handling
+
+### Costs
+
+- weaker process isolation by default
+- more complexity inside the main server
+- harder to contain instance-specific failures
+- more shared memory and state inside one process
+- main server becomes responsible for more lifecycle details directly
+
+### Best fit
+
+- low-overhead single-host deployments
+- workloads where efficiency matters more than hard isolation
+- environments where an extra worker process is unnecessary
+- future architectures that want fewer internal hops
+
+## Chart 2: Ownership And Transport
+
+```text
+managed + bridge
+ ownership: pinchtab
+ transport: http-bridge + cdp
+
+managed + direct-cdp
+ ownership: pinchtab
+ transport: direct cdp
+```
+
+## Chart 3: Failure Boundary
+
+```text
+managed + bridge
+ one instance crash
+ -> bridge worker dies
+ -> instance is affected
+ -> server survives
+
+managed + direct-cdp
+ one instance failure
+ -> handled inside server process
+ -> isolation depends on server design
+```
+
+## Decision Frame
+
+Use this rule:
+
+- choose **managed + bridge** when isolation and operational clarity matter more
+- choose **managed + direct-cdp** when simplicity of the runtime path and lower overhead matter more
+
+Or even shorter:
+
+```text
+bridge = better isolation
+direct-cdp = better efficiency
+```
+
+## Current Status
+
+Today, the intended architecture is:
+
+- `managed + bridge` for Pinchtab-launched instances
+- `attached + direct-cdp` for externally managed browsers
+
+`managed + direct-cdp` is a useful future model, but it is primarily an architectural option, not the default implementation.
diff --git a/docs/architecture/pinchtab-architecture.md b/docs/architecture/pinchtab-architecture.md
index 72d8eb70..0817069e 100644
--- a/docs/architecture/pinchtab-architecture.md
+++ b/docs/architecture/pinchtab-architecture.md
@@ -5,7 +5,11 @@
Pinchtab is an HTTP server (Go binary, ~12MB) that wraps Chrome DevTools Protocol (CDP)
to give AI agents browser control via a simple REST API.
-**Self-hosted mode (default):** Pinchtab launches and manages its own Chrome instance.
+The product has two process roles:
+- **Server** — the default `pinchtab` process that manages profiles, instances, routing, and the dashboard
+- **Bridge** — the single-instance runtime used for one managed browser
+
+**Managed mode (default):** the Pinchtab server launches and manages bridge-backed Chrome instances.
```
┌─────────────┐ HTTP ┌──────────────┐ CDP ┌──────────────┐
@@ -14,27 +18,159 @@ to give AI agents browser control via a simple REST API.
└─────────────┘ JSON/text └──────────────┘ WebSocket └──────────────┘
```
-**Remote Chrome mode (CDP_URL):** Pinchtab connects to an existing Chrome instance via CDP_URL.
+**Attach mode (advanced):** the Pinchtab server can register an externally managed Chrome instance through the instance API when attach is enabled by policy.
```
┌─────────────┐ HTTP ┌──────────────┐ CDP ┌──────────────┐
-│ Multiple │ ────────────▶ │ Multiple │ ─────────────▶ │ Shared │
-│ Agents │ ◀──────────── │ Pinchtab │ ◀───────────── │ Chrome │
-│ │ JSON/text │ instances │ WebSocket │ instance │
+│ Multiple │ ────────────▶ │ Pinchtab │ ─────────────▶ │ External │
+│ Agents │ ◀──────────── │ Server │ ◀───────────── │ Chrome │
+│ │ JSON/text │ │ WebSocket │ Instance │
└─────────────┘ └──────────────┘ └──────────────┘
```
-See [docs/cdp-url-shared-chrome.md](cdp-url-shared-chrome.md) for multi-agent resource sharing and container deployment patterns.
-
Agents never touch CDP directly. They send HTTP requests, get back JSON.
The accessibility tree (a11y) is the primary interface — not screenshots, not DOM.
+## Instance Mental Model
+
+The cleanest way to think about instances is with two axes:
+
+- **Source** — who created or registered the instance
+- **Runtime** — how the server reaches the browser
+
+### Chart 1: Process Roles
+
+```text
+pinchtab server
+ ├─ manages profiles
+ ├─ manages instances
+ ├─ routes requests
+ └─ serves dashboard/API
+
+pinchtab bridge
+ ├─ wraps one browser
+ ├─ exposes single-instance HTTP API
+ └─ is usually spawned by the server
+```
+
+### Chart 2: Instance Taxonomy
+
+```text
+Instance
+ ├─ source: managed
+ │ ├─ runtime: bridge
+ │ └─ runtime: direct-cdp (possible future model)
+ │
+ └─ source: attached
+ └─ runtime: direct-cdp
+```
+
+This separation matters:
+
+- `managed` means Pinchtab owns instance lifecycle
+- `attached` means Pinchtab registers an already running browser
+- `bridge` means the server talks HTTP to a child Pinchtab runtime
+- `direct-cdp` means the server talks to Chrome over CDP directly
+
+### Suggested Instance Schema
+
+If you model this explicitly in the instance object, the clean shape is:
+
+```json
+{
+ "id": "inst_0a89a5bb",
+ "name": "work",
+ "source": "managed",
+ "runtime": "bridge",
+ "ownership": "pinchtab",
+ "status": "starting",
+ "profileId": "prof_278be873",
+ "profileName": "work",
+ "port": "9868",
+ "baseUrl": "http://127.0.0.1:9868",
+ "cdpUrl": "",
+ "attached": false
+}
+```
+
+Recommended fields:
+
+- `id` — stable instance identifier
+- `name` — human-oriented instance/profile label
+- `source` — `managed` or `attached`
+- `runtime` — `bridge` or `direct-cdp`
+- `ownership` — `pinchtab`, `external`, or `adopted`
+- `status` — `starting`, `running`, `stopping`, `stopped`, `error`
+- `profileId` / `profileName` — associated profile, when relevant
+- `port` / `baseUrl` — bridge-facing address when the instance has an HTTP runtime
+- `cdpUrl` — discovered or attached CDP endpoint when relevant
+- `attached` — compatibility field for old clients; derivable from `source == "attached"`
+
+In other words:
+
+```text
+source = who introduced the instance
+runtime = how the server reaches it
+ownership = who controls its lifecycle
+```
+
+That gives these combinations:
+
+```text
+managed + bridge + pinchtab
+managed + direct-cdp + pinchtab
+attached + direct-cdp + external
+```
+
+### Chart 3: Routing Paths
+
+```text
+Managed + bridge
+ server -> bridge -> Chrome -> tabs
+
+Managed + direct-cdp
+ server -> Chrome -> tabs
+
+Attached + direct-cdp
+ server -> external Chrome -> tabs
+```
+
+### Chart 4: What Lives In The Pool
+
+```text
+Pinchtab server
+ └─ instance pool
+ ├─ instance A
+ │ └─ tabs
+ ├─ instance B
+ │ └─ tabs
+ └─ instance C
+ └─ tabs
+```
+
+The pool contains **instances**, not tabs.
+Tabs always belong to an instance.
+
+### Current And Future Scope
+
+Today, the intended architecture is:
+
+- `managed + bridge` for Pinchtab-launched instances
+- `attached + direct-cdp` for externally managed browsers
+
+A plausible future expansion is:
+
+- `managed + direct-cdp` to remove the extra HTTP hop when the server can own Chrome directly
+
+For a focused comparison, see [Managed Bridge vs Managed Direct-CDP](managed-bridge-vs-managed-direct-cdp.md).
+For the visual version of the model, see [Instance Model Charts](instance-model-charts.md).
+
## Design Principles
1. **A11y tree over screenshots** — 4x cheaper in tokens, works with any LLM
2. **HTTP over WebSocket** — Stateless requests, no connection management for agents
3. **Ref stability** — Snapshot refs (e0, e1...) are cached and reused by action endpoints
-4. **Self-contained** — Launches its own Chrome, manages its own state, zero config needed
+4. **Self-contained by default** — Launches and manages Chrome itself unless you explicitly use attach
5. **Decoupled Architecture** — Interface-driven design for testability and maintainability
## Project Layout
@@ -131,13 +267,13 @@ Two main simulation engines for anti-detection:
go build -o pinchtab ./cmd/pinchtab
# Run
-BRIDGE_TOKEN=secret ./pinchtab
+PINCHTAB_TOKEN=secret ./pinchtab
```
### Docker
```bash
docker build -t pinchtab .
-docker run -d -p 9867:9867 -e BRIDGE_TOKEN=secret pinchtab
+docker run -d -p 9867:9867 -e PINCHTAB_TOKEN=secret pinchtab
```
---
diff --git a/docs/core-concepts.md b/docs/core-concepts.md
index f5401ad9..9b7bb926 100644
--- a/docs/core-concepts.md
+++ b/docs/core-concepts.md
@@ -1,6 +1,11 @@
# Core Concepts
-PinchTab is an HTTP server that controls four key entities: **PinchTab itself**, **Instances**, **Profiles**, and **Tabs**.
+PinchTab is built around two process roles and three main runtime entities:
+- **Server**
+- **Bridge**
+- **Instance**
+- **Profile**
+- **Tab**
**See also:**
- [Instance API Reference](references/instance-api.md) — Complete instance endpoints
@@ -9,26 +14,45 @@ PinchTab is an HTTP server that controls four key entities: **PinchTab itself**,
---
-## PinchTab
+## Server
-The **HTTP server controller** (orchestrator) that manages all instances, profiles, and tabs.
+The **full PinchTab server** is the main control-plane process. It manages instances, profiles, routing, and the web dashboard.
- Listens on port `9867` (configurable, dashboard + API)
- Routes requests to the appropriate instance
- Manages instance lifecycle (launch, monitor, stop)
- Provides unified HTTP API for all operations
-- No Chrome process itself — purely orchestrator
+- Does not talk to Chrome directly for normal managed instances; it delegates to bridge runtimes
```bash
-# Start PinchTab orchestrator (default: port 9867)
+# Start the full server
pinchtab
# Listening on http://localhost:9867
+# Or explicitly
+pinchtab server
+
# Or specify port
-BRIDGE_PORT=9870 pinchtab
+PINCHTAB_PORT=9870 pinchtab server
# Listening on http://localhost:9870
```
+## Bridge
+
+The **bridge** is the single-instance runtime.
+
+- Wraps one browser instance
+- Exposes the tab/browser HTTP API
+- Used for managed child instances spawned by the server
+- Can also be started explicitly with `pinchtab bridge`
+
+```bash
+# Explicit bridge mode
+pinchtab bridge
+```
+
+Most users do not start `bridge` directly. They run the server, and the server launches bridge children as needed.
+
---
## Instance
@@ -47,7 +71,7 @@ A **running Chrome process** with an optional profile, auto-allocated to a uniqu
### Creating Instances
-Instances are managed by the orchestrator via the API (not by running separate processes).
+Instances are managed by the server via the API. Managed instances run as isolated bridge child processes.
```bash
# CLI: Create instance (headless by default)
@@ -80,7 +104,7 @@ curl -X POST http://localhost:9867/instances/launch \
You can run multiple instances simultaneously for isolation and scalability. The orchestrator manages them automatically:
```bash
-# Terminal 1: Start orchestrator
+# Terminal 1: Start server
pinchtab
# Terminal 2: Create multiple instances
@@ -186,10 +210,15 @@ curl -X POST http://localhost:9867/instances/start \
curl -X POST http://localhost:9867/instances/start \
-d '{"profileId": "work"}'
-# Navigate and log in
-curl -X POST http://localhost:9867/instances/inst_xyz/navigate \
- -d '{"url": "https://pinchtab.com/login"}'
-# ... fill login form, click submit ...
+# Open a login tab and log in
+TAB_ID=$(curl -s -X POST http://localhost:9867/instances/inst_xyz/tabs/open \
+ -H "Content-Type: application/json" \
+ -d '{"url": "https://pinchtab.com/login"}' | jq -r '.tabId')
+
+curl -X POST http://localhost:9867/tabs/$TAB_ID/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"fill","ref":"e3","text":"[email protected]"}'
+# ... continue login flow ...
# Later (even after instance restart): Profile is persistent
pinchtab instance launch # Or restart orchestrator
@@ -223,14 +252,16 @@ pinchtab tab open inst_0a89a5bb https://pinchtab.com
curl http://localhost:9867/tabs/tab_abc123 | jq .
# Navigate tab
-curl -X POST http://localhost:9867/instances/inst_0a89a5bb/navigate \
+curl -X POST http://localhost:9867/tabs/tab_abc123/navigate \
+ -H "Content-Type: application/json" \
-d '{"url": "https://google.com"}'
# Take snapshot (DOM structure)
-curl http://localhost:9867/instances/inst_0a89a5bb/snapshot | jq .
+curl http://localhost:9867/tabs/tab_abc123/snapshot | jq .
# Interact with tab (click, type, etc.)
-curl -X POST http://localhost:9867/instances/inst_0a89a5bb/action \
+curl -X POST http://localhost:9867/tabs/tab_abc123/action \
+ -H "Content-Type: application/json" \
-d '{"kind": "click", "ref": "e5"}'
# Close tab
@@ -247,7 +278,7 @@ pinchtab tab close tab_abc123
## Hierarchy
```text
-PinchTab Orchestrator (HTTP server on port 9867)
+PinchTab Server (HTTP server on port 9867)
│
├── Instance 1 (inst_0a89a5bb, port 9868, temp profile)
│ ├── Tab 1 (tab_xyz123, https://pinchtab.com)
@@ -366,9 +397,12 @@ while true; do
sleep 0.5
done
-# Now safe to make requests to the instance
-curl -X POST http://localhost:9867/instances/$INST/navigate \
- -d '{"url":"https://pinchtab.com"}'
+# Now safe to create a tab and work through tab endpoints
+TAB_ID=$(curl -s -X POST http://localhost:9867/instances/$INST/tabs/open \
+ -H "Content-Type: application/json" \
+ -d '{"url":"https://pinchtab.com"}' | jq -r '.tabId')
+
+curl http://localhost:9867/tabs/$TAB_ID/snapshot
```
---
@@ -378,7 +412,7 @@ curl -X POST http://localhost:9867/instances/$INST/navigate \
```
What you control │ What it is │ Identified by
─────────────────────────┼──────────────────────────┼─────────────────────
-PinchTab Orchestrator │ HTTP server controller │ port (9867 default)
+PinchTab Server │ HTTP control plane │ port (9867 default)
Instance │ Chrome process │ inst_XXXXXXXX (hash ID)
Profile (optional) │ Browser state directory │ prof_XXXXXXXX (hash ID)
Tab │ Single webpage │ tab_XXXXXXXX (hash ID)
@@ -386,7 +420,7 @@ Tab │ Single webpage │ tab_XXXXXXXX (hash ID)
## Summary
-- **PinchTab Orchestrator** is the HTTP server that manages everything
+- **PinchTab Server** is the HTTP control plane that manages everything
- **Instance** is a running Chrome process with optional profile and multiple tabs
- **Profile** is optional persistent browser state (cookies, auth, history)
- **Tab** is the actual webpage you navigate and interact with
diff --git a/docs/dashboard.md b/docs/dashboard.md
index 931a31ae..f0ab6af9 100644
--- a/docs/dashboard.md
+++ b/docs/dashboard.md
@@ -2,6 +2,10 @@
PinchTab includes a built-in web dashboard for monitoring and managing instances, profiles, and agent activity.
+The dashboard is part of the **full server**:
+- `pinchtab` or `pinchtab server` starts the full server and serves the dashboard
+- `pinchtab bridge` does not serve the dashboard; it only exposes the single-instance bridge API
+
Access the dashboard at **`http://localhost:9867`** (adjust port if needed).
Alternatively, use **`http://localhost:9867/dashboard`** (also works for backward compatibility).
diff --git a/docs/get-started.md b/docs/get-started.md
index 2bc99cf3..46582e83 100644
--- a/docs/get-started.md
+++ b/docs/get-started.md
@@ -61,7 +61,16 @@ go build -o pinchtab ./cmd/pinchtab
## Quick Start (5 Minutes)
-### Step 1: Start the Orchestrator
+The primary usage model is simple:
+
+- install Pinchtab
+- run `pinchtab`
+- point your agent or automation client at `http://localhost:9867`
+- treat Pinchtab as the local browser service
+
+That is the default setup for users who want Pinchtab to replace an embedded browser runtime in another tool.
+
+### Step 1: Start the Server
**Terminal 1:**
```bash
@@ -70,11 +79,13 @@ pinchtab
**Expected output:**
```
-🦀 Pinchtab Dashboard port=9867
+🦀 Pinchtab port=9867
dashboard ready url=http://localhost:9867/dashboard
```
-The orchestrator is running on `http://127.0.0.1:9867`. Open the dashboard in your browser to see instances and profiles.
+The full server is running on `http://127.0.0.1:9867`. Open the dashboard in your browser to see instances and profiles.
+
+PinchTab also has a `pinchtab bridge` mode, but that is the single-instance runtime used behind managed instances. For normal use, start the full server.
### Step 2: Create an Instance
@@ -92,7 +103,9 @@ sleep 3
```bash
# Navigate to a website
-pinchtab instance navigate $INST https://pinchtab.com
+TAB_ID=$(curl -s -X POST http://localhost:9867/instances/$INST/tabs/open \
+ -H "Content-Type: application/json" \
+ -d '{"url":"https://pinchtab.com"}' | jq -r '.tabId')
# Get page structure
curl http://localhost:9867/tabs/$TAB_ID/snapshot | jq '.nodes | map({role, name}) | .[0:5]'
@@ -182,10 +195,11 @@ curl -X POST http://localhost:9867/tabs/$TAB_ID/action \
### Key Concepts
-**Orchestrator** (port 9867):
-- Manages instances
-- Routes requests via `/instances/{id}/*`
-- No Chrome process itself
+**Server** (port 9867):
+- Manages instances and profiles
+- Routes requests via `/instances/{id}/*` and `/tabs/{id}/*`
+- Serves the dashboard UI
+- Spawns bridge runtimes for managed instances
**Instance** (ports 9868-9968):
- Real Chrome browser process
@@ -193,6 +207,11 @@ curl -X POST http://localhost:9867/tabs/$TAB_ID/action \
- Isolated cookies, history, storage
- Each has unique ID: `inst_XXXXXXXX`
+**Bridge**:
+- The single-instance runtime backing a managed instance
+- Thin HTTP wrapper over one browser instance
+- Usually spawned by the server automatically
+
**Tab**:
- Single webpage within instance
- Has state (URL, DOM, focus, content)
@@ -385,17 +404,17 @@ main();
## Configuration
-### Orchestrator Configuration
+### Server Configuration
```bash
-# Custom port (orchestrator)
-BRIDGE_PORT=9868 pinchtab
+# Custom port
+PINCHTAB_PORT=9868 pinchtab
# Auth token for remote access
-BRIDGE_TOKEN=my-secret-token pinchtab
+PINCHTAB_TOKEN=my-secret-token pinchtab
# Bind to all interfaces (for remote access)
-BRIDGE_BIND=0.0.0.0 pinchtab
+PINCHTAB_BIND=0.0.0.0 pinchtab
# Custom Chrome binary (used by all instances)
CHROME_BIN=/usr/bin/google-chrome pinchtab
@@ -603,8 +622,8 @@ curl -X POST http://localhost:9867/instances/$INST/tabs/open \
**Solution:**
```bash
-# Use different orchestrator port
-BRIDGE_PORT=9868 pinchtab
+# Use different server port
+PINCHTAB_PORT=9868 pinchtab
# Or kill the process using 9867
lsof -i :9867
diff --git a/docs/guides/expert-attach.md b/docs/guides/expert-attach.md
new file mode 100644
index 00000000..a904feb0
--- /dev/null
+++ b/docs/guides/expert-attach.md
@@ -0,0 +1,155 @@
+# Expert Guide: Attach
+
+This guide is for advanced setups where Chrome already exists outside Pinchtab and you want the server to register it as an instance.
+
+## What Attach Means
+
+Attach does not launch Chrome.
+
+Instead:
+- Chrome is already running somewhere else
+- Pinchtab server receives a `cdpUrl`
+- Pinchtab registers that browser as an instance
+- requests can then be routed through the server
+
+Mental model:
+
+```text
+launch = Pinchtab creates the browser
+attach = Pinchtab registers an existing browser
+```
+
+## When Attach Makes Sense
+
+Use attach when:
+- Chrome is managed by another system
+- Chrome runs in another container or service
+- you need Pinchtab routing around an existing CDP endpoint
+- you want the server to treat external Chrome as an instance
+
+## When Attach Does Not Make Sense
+
+Do not use attach if your goal is simply:
+- “start a browser for my agent”
+- “run Pinchtab locally as my browser service”
+
+In those cases, use managed launch via the full server.
+
+## Enable Attach Policy
+
+Attach is controlled by config policy.
+
+Example:
+
+```json
+{
+ "attach": {
+ "enabled": true,
+ "allowHosts": ["127.0.0.1", "localhost", "::1"],
+ "allowSchemes": ["ws", "wss"]
+ }
+}
+```
+
+This does not define a browser.
+It only defines which attach requests are allowed.
+
+## Attach Request
+
+Example:
+
+```bash
+curl -X POST http://localhost:9867/instances/attach \
+ -H "Content-Type: application/json" \
+ -d '{
+ "name": "shared-chrome",
+ "cdpUrl": "ws://127.0.0.1:9222/devtools/browser/..."
+ }'
+```
+
+## Getting A CDP URL
+
+If you are attaching to a browser you started yourself, the usual flow is:
+
+```bash
+# Start Chrome with remote debugging enabled
+google-chrome --remote-debugging-port=9222
+
+# Or on some systems:
+# chromium --remote-debugging-port=9222
+```
+
+Then ask Chrome for its browser-level websocket endpoint:
+
+```bash
+curl http://localhost:9222/json/version
+```
+
+Example response:
+
+```json
+{
+ "webSocketDebuggerUrl": "ws://localhost:9222/devtools/browser/abc123"
+}
+```
+
+That `webSocketDebuggerUrl` is the value you pass as `cdpUrl` in the attach request.
+
+Example:
+
+```bash
+curl -X POST http://localhost:9867/instances/attach \
+ -H "Content-Type: application/json" \
+ -d '{
+ "name": "shared-chrome",
+ "cdpUrl": "ws://localhost:9222/devtools/browser/abc123"
+ }'
+```
+
+## What Pinchtab Owns
+
+By default, attached instances are externally owned:
+
+```text
+source = attached
+runtime = direct-cdp
+ownership = external
+```
+
+That means:
+- Pinchtab routes to them
+- Pinchtab did not launch them
+- lifecycle ownership may remain outside Pinchtab
+
+## Security Considerations
+
+Attach should be treated as an expert feature because it widens trust boundaries.
+
+Recommended rules:
+- keep `attach.enabled` off by default
+- restrict `allowHosts`
+- restrict `allowSchemes`
+- require `PINCHTAB_TOKEN` when the server is reachable by anything other than localhost
+- only attach to CDP endpoints you trust
+
+## Operational Model
+
+```text
+agent -> pinchtab server -> attached external Chrome
+```
+
+There is no bridge child in the attach path.
+
+## Current Scope
+
+Attach is the right abstraction for:
+- external Chrome
+- containerized Chrome managed elsewhere
+- CDP endpoints outside Pinchtab lifecycle control
+
+It is not the primary user path.
+The primary user path remains:
+
+```bash
+pinchtab
+```
diff --git a/docs/guides/expert-bridge-mode.md b/docs/guides/expert-bridge-mode.md
new file mode 100644
index 00000000..3af158b6
--- /dev/null
+++ b/docs/guides/expert-bridge-mode.md
@@ -0,0 +1,113 @@
+# Expert Guide: Bridge Mode
+
+This guide is for advanced users who want to run `pinchtab bridge` directly.
+
+For most users, the right entrypoint is still:
+
+```bash
+pinchtab
+```
+
+Use bridge mode only when you explicitly want the single-instance runtime without the full server control plane.
+
+## What Bridge Mode Is
+
+`pinchtab bridge` starts the single-instance HTTP runtime.
+
+It:
+- wraps one browser
+- exposes the browser/tab API directly
+- does not serve the dashboard
+- does not manage multiple instances
+- does not act as the main control plane
+
+In normal managed mode, the server spawns bridge children for you.
+
+## When To Use It
+
+Bridge mode makes sense when:
+- you want one browser runtime only
+- you do not need profiles/instance orchestration in the parent process
+- you want to debug the single-instance runtime directly
+- you want to run the bridge as a standalone worker
+
+## When Not To Use It
+
+Do not use bridge mode as the primary onboarding path if your real goal is:
+- “give my agent a local browser service”
+- “replace an embedded browser runtime in another tool”
+- “manage profiles and instances from one endpoint”
+
+In those cases, use:
+
+```bash
+pinchtab
+```
+
+## Minimal Example
+
+```bash
+pinchtab bridge
+```
+
+Then call the single-instance API on the configured port:
+
+```bash
+curl -X POST http://localhost:9867/navigate \
+ -H "Content-Type: application/json" \
+ -d '{"url":"https://pinchtab.com"}'
+
+curl http://localhost:9867/snapshot?filter=interactive
+```
+
+## Configuration Model
+
+Bridge mode still uses the same `config.json` and operational env surface:
+
+```bash
+PINCHTAB_PORT=9868 pinchtab bridge
+PINCHTAB_TOKEN=secret pinchtab bridge
+CHROME_BIN=/usr/bin/google-chrome pinchtab bridge
+```
+
+Behavior defaults still come from config file sections like:
+- `browser`
+- `instanceDefaults`
+- `security`
+- `timeouts`
+
+## Mental Model
+
+```text
+pinchtab bridge
+ -> one runtime
+ -> one browser
+ -> many tabs
+```
+
+Compared with full server mode:
+
+```text
+pinchtab
+ -> one control plane
+ -> many instances
+ -> each managed instance may run through a bridge
+```
+
+## Tradeoffs
+
+Benefits:
+- fewer product layers visible to you
+- direct access to the single-instance API
+- useful for debugging and specialized deployments
+
+Costs:
+- no instance pool
+- no profile/instance dashboard workflow
+- no attach/launch control plane
+- you are choosing the lower-level runtime, not the main product entrypoint
+
+## Recommended Rule
+
+Use bridge mode when you explicitly want the worker runtime.
+Use server mode when you want Pinchtab as a browser service.
diff --git a/docs/guides/expert-strategies.md b/docs/guides/expert-strategies.md
new file mode 100644
index 00000000..5775421e
--- /dev/null
+++ b/docs/guides/expert-strategies.md
@@ -0,0 +1,188 @@
+# Expert Guide: Multi-Instance Strategies And Allocation
+
+This guide covers advanced server behavior for users running more than the default simple local setup.
+
+## Two Separate Concepts
+
+Pinchtab has two knobs for advanced multi-instance behavior:
+
+- `multiInstance.strategy`
+- `multiInstance.allocationPolicy`
+
+These are different.
+
+Mental model:
+
+```text
+strategy = what routing model the server exposes
+allocationPolicy = which running instance gets selected
+```
+
+## Strategy
+
+Valid strategies on this branch:
+
+- `simple`
+- `explicit`
+- `simple-autorestart`
+
+### `simple`
+
+`simple` is the default.
+
+It behaves like:
+- shorthand routes proxy to the first running instance
+- if needed, the strategy may ensure one instance exists
+- good default for single-user, single-active-instance workflows
+
+Best fit:
+- local development
+- “just give me one browser service”
+- simplest replacement for an embedded browser runtime
+
+### `explicit`
+
+`explicit` exposes the orchestrator model directly.
+
+It is best when you want to think in terms of:
+- profiles
+- instances
+- tab IDs
+- explicit routing
+
+Best fit:
+- systems that manage several instances deliberately
+- users who want predictable, explicit control over which instance handles work
+- environments where shorthand auto-routing is too implicit
+
+### `simple-autorestart`
+
+`simple-autorestart` behaves like `simple`, but actively tries to keep a managed instance alive.
+
+Best fit:
+- kiosk-style or always-on setups
+- local browser service behavior where one managed instance should come back after a crash
+- unattended environments
+
+## Allocation Policy
+
+Valid allocation policies on this branch:
+
+- `fcfs`
+- `round_robin`
+- `random`
+
+### `fcfs`
+
+First suitable instance wins.
+
+Best fit:
+- predictable behavior
+- simple deployments
+- minimal surprise
+
+### `round_robin`
+
+Requests rotate across eligible instances.
+
+Best fit:
+- distributing work across a stable set of running instances
+- light balancing without randomness
+
+### `random`
+
+Requests pick a random eligible instance.
+
+Best fit:
+- spreading work without a fixed order
+- experiments or looser balancing behavior
+
+## Example Config
+
+```json
+{
+ "multiInstance": {
+ "strategy": "explicit",
+ "allocationPolicy": "round_robin",
+ "instancePortStart": 9868,
+ "instancePortEnd": 9968
+ }
+}
+```
+
+## Recommended Usage Patterns
+
+### Primary User Path
+
+For the normal “local browser service” workflow:
+
+```json
+{
+ "multiInstance": {
+ "strategy": "simple",
+ "allocationPolicy": "fcfs"
+ }
+}
+```
+
+This matches:
+- install Pinchtab
+- run `pinchtab`
+- point the client to `http://localhost:9867`
+
+### Explicit Multi-Instance Control
+
+Use:
+
+```json
+{
+ "multiInstance": {
+ "strategy": "explicit",
+ "allocationPolicy": "round_robin"
+ }
+}
+```
+
+when you want:
+- clear instance boundaries
+- explicit instance API usage
+- predictable multi-instance orchestration
+
+### Self-Healing Single-Service Setup
+
+Use:
+
+```json
+{
+ "multiInstance": {
+ "strategy": "simple-autorestart",
+ "allocationPolicy": "fcfs"
+ }
+}
+```
+
+when you want one logical browser service that tries to recover automatically.
+
+## Decision Rule
+
+Use this rule:
+
+```text
+simple = easiest default
+explicit = most control
+simple-autorestart = single-service resilience
+
+fcfs = most predictable
+round_robin = balanced rotation
+random = loose distribution
+```
+
+## Important Boundary
+
+These settings are expert-level because they change control-plane behavior.
+
+They are not required for the primary Pinchtab experience.
+Most users should stay on:
+
+- `strategy = simple`
+- `allocationPolicy = fcfs`
diff --git a/docs/index.json b/docs/index.json
index 5c02d728..8e2debe7 100644
--- a/docs/index.json
+++ b/docs/index.json
@@ -8,7 +8,7 @@
],
"references": [
"references/api-structure.md",
- "references/api-reference.json",
+ "references/endpoints.md",
"references/profile-api.md",
"references/instance-api.md",
"references/tabs-api.md",
@@ -17,12 +17,16 @@
],
"architecture": [
"architecture/pinchtab-architecture.md",
+ "architecture/instance-model-charts.md",
+ "architecture/managed-bridge-vs-managed-direct-cdp.md",
"architecture/chrome-lifecycle-and-orchestration.md",
"architecture/dashboard-ui.md",
"architecture/building.md"
],
"guides": [
- "guides/cdp-url-shared-chrome.md",
+ "guides/expert-bridge-mode.md",
+ "guides/expert-attach.md",
+ "guides/expert-strategies.md",
"guides/headed-mode-guide.md",
"guides/identifying-instances.md",
"guides/agent-optimization.md",
diff --git a/docs/overview.md b/docs/overview.md
index b084dc64..36724ffd 100644
--- a/docs/overview.md
+++ b/docs/overview.md
@@ -4,7 +4,32 @@ Welcome to PinchTab — browser control for AI agents, scripts, and automation w
## What is PinchTab?
-PinchTab is a **standalone HTTP server** that gives you direct control over a Chrome browser. Any AI agent can use the CLI or HTTP API.
+PinchTab is a **standalone HTTP server** that gives you direct control over Chrome. Any AI agent can use the CLI or HTTP API.
+
+The main concept to understand first is that PinchTab has two runtime roles:
+
+- `pinchtab` or `pinchtab server` — the full control-plane server
+- `pinchtab bridge` — the single-instance bridge runtime
+
+The server is the normal entrypoint. It manages profiles, instances, routing, and the dashboard. The bridge runtime is the lightweight single-instance HTTP wrapper used for managed child instances.
+
+That gives you a simple mental model:
+- start the **server**
+- create or attach **instances**
+- operate on **tabs**
+
+## Primary Usage
+
+For most users, Pinchtab is a local browser service:
+
+1. install Pinchtab
+2. run `pinchtab`
+3. connect your agent or tool to `http://localhost:9867`
+4. use Pinchtab instead of embedding a browser runtime directly in the client
+
+In that model:
+- `pinchtab server` is the primary target
+- `pinchtab bridge` is an internal or advanced runtime detail
**CLI example:**
```bash
@@ -20,26 +45,35 @@ pinchtab click e5
**HTTP example (realistic flow):**
```bash
-# 1. Navigate to URL (returns tabId)
-TAB=$(curl -s -X POST http://localhost:9867/tab \
- -d '{"action":"new","url":"https://pinchtab.com"}' | jq -r '.tabId')
-
-# 2. Get page structure
-curl -s "http://localhost:9867/snapshot?tabId=$TAB&filter=interactive" | jq
-
-# 3. Click element using the tabId
-curl -s -X POST http://localhost:9867/action \
- -d "{\"kind\":\"click\",\"ref\":\"e5\",\"tabId\":\"$TAB\"}"
+# 1. Create an instance
+INST=$(curl -s -X POST http://localhost:9867/instances/launch \
+ -H "Content-Type: application/json" \
+ -d '{"name":"work","mode":"headless"}' | jq -r '.id')
+
+# 2. Open a tab
+TAB=$(curl -s -X POST http://localhost:9867/instances/$INST/tabs/open \
+ -H "Content-Type: application/json" \
+ -d '{"url":"https://pinchtab.com"}' | jq -r '.tabId')
+
+# 3. Get page structure
+curl -s "http://localhost:9867/tabs/$TAB/snapshot?filter=interactive" | jq
+
+# 4. Click element using the tabId
+curl -s -X POST http://localhost:9867/tabs/$TAB/action \
+ -H "Content-Type: application/json" \
+ -d '{"kind":"click","ref":"e5"}'
```
---
## Characteristics
+- **Server-first** — The default process is the control-plane server, not a raw browser wrapper
+- **Bridge-backed instances** — Managed instances run as isolated bridge runtimes behind the server
- **Tab-Centric** — Everything revolves around tabs, not URLs
- **Stateful** — Sessions persist between requests. Log in once, stay logged in across restarts
- **Token Inexpensive** — Text extraction at 800 tokens/page (5-13x cheaper than full snapshots)
-- **Flexible Modes** — Run headless, headed, with browser profiles, or connect to external Chrome via CDP
+- **Flexible Modes** — Launch headed or headless browsers, keep persistent profiles, or attach to external Chrome when allowed
- **Monitoring & Control** — Tab locking for multi-agent safety, stealth mode for bot detection bypass
---
@@ -56,6 +90,14 @@ curl -s -X POST http://localhost:9867/action \
- 📄 **PDF Export** — Full pages to PDF with headers, footers, landscape mode.
- 🎭 **Multi-Tab** — Create, switch, close tabs. Work with multiple pages concurrently.
+## Expert Guides
+
+If you are moving beyond the primary server-first workflow, use the expert guides:
+
+- [Bridge Mode](guides/expert-bridge-mode.md) — run the single-instance runtime directly
+- [Attach](guides/expert-attach.md) — register externally managed Chrome instances
+- [Multi-Instance Strategies](guides/expert-strategies.md) — advanced routing and allocation behavior
+
---
## Support & Community
diff --git a/docs/references/cli-design.md b/docs/references/cli-design.md
index 6b651ee8..10002188 100644
--- a/docs/references/cli-design.md
+++ b/docs/references/cli-design.md
@@ -1,368 +1,263 @@
# CLI Design Guide
-## Principles
+This page describes the CLI that exists today in `cmd/pinchtab/cmd_cli.go` and `cmd/pinchtab/main.go`.
-1. **Hierarchical path mirroring** — CLI command structure mirrors HTTP endpoints
-2. **Resource-oriented** — `pinchtab <resource> <action>` not `pinchtab <action>`
-3. **Consistent argument order** — `<resource> <id> <sub-resource> <sub-id> <action> [flags] [payload]`
-4. **Smart payload handling** — Flags for simple cases, stdin/JSON for complex payloads
-5. **No breaking changes** — Always maintain backward compatibility
+## Process Modes
-## Command Structure
+Pinchtab has three startup modes:
-### Pattern 1: List Resources
-```
-pinchtab <resource> List all resources
-```
-
-**Examples:**
```bash
-pinchtab instances # GET /instances
-pinchtab profiles # GET /profiles
+pinchtab # Start full server (default)
+pinchtab server # Start full server explicitly
+pinchtab bridge # Start bridge-only runtime
```
-**Output:** JSON array (auto-formatted)
+The CLI commands below are client commands. They expect a running full server unless noted otherwise.
-### Pattern 2: Manage Resource (Orchestrator)
-```
-pinchtab <resource> <action> Orchestrator-level actions
-pinchtab <resource> <id> <action> Instance-scoped actions
-```
+## Core Rule
-**Examples:**
-```bash
-pinchtab instance launch --mode headed --port 9869
-pinchtab instance <id> logs
-pinchtab instance <id> stop
-```
+The current CLI is split into three layers:
-**HTTP mapping:**
-- `pinchtab instance launch [flags]` → `POST /instances/launch {mode, port}`
-- `pinchtab instance <id> logs` → `GET /instances/<id>/logs`
-- `pinchtab instance <id> stop` → `POST /instances/<id>/stop`
+1. startup and utility commands
+2. top-level browser control commands
+3. explicit instance and tab management commands
-### Pattern 3: Browser Control (Instance-scoped)
-```
-pinchtab [--instance <id>] <action> [args] [flags]
-```
+The important constraint is that the CLI does **not** support a global `--instance` flag today.
+
+If you need to target a specific instance:
+- create or inspect it with `pinchtab instance ...`
+- open a tab inside it with `pinchtab instance navigate <instance-id> <url>` or the HTTP API
+- then operate on the returned tab ID with `pinchtab tab ...`
+
+## Startup And Utility Commands
+
+These commands are handled outside the main HTTP CLI dispatcher:
-**Examples:**
```bash
-# Default instance (auto-detected from PINCHTAB_INSTANCE env or from running instance)
-pinchtab nav https://pinchtab.com
-pinchtab snap -i -c
-pinchtab click e5
+pinchtab --version
+pinchtab help
+
+pinchtab config init
+pinchtab config show
+pinchtab config path
+pinchtab config validate
-# Explicit instance
-pinchtab --instance inst_abc123 nav https://pinchtab.com
-pinchtab --instance inst_abc123 snap
+pinchtab connect <profile>
+pinchtab connect <profile> --json
+pinchtab connect <profile> --dashboard http://localhost:9867
```
-**HTTP mapping:**
-- `pinchtab nav <url>` → `POST /navigate {url}`
-- `pinchtab --instance <id> snap` → `GET /snapshot` (with `tabId`)
-- `pinchtab tab click <tabId> <ref>` → `POST /tabs/<tabId>/action {kind: "click", ref}`
+Notes:
+- `connect` resolves a running profile to its bridge URL via `/profiles/{id}/instance`
+- there is no CLI command for `attach` yet; attach is API-only for now
-### Pattern 4: Nested Resources (Tabs within Instance)
-```
-pinchtab --instance <id> tab <action> [args] List/manage tabs
-pinchtab --instance <id> tab <tabId> <action> Operate on specific tab
-```
+## Top-Level Browser Control
-**Examples:**
-```bash
-# List tabs
-pinchtab --instance inst_abc123 tabs # GET /instances/<id>/tabs
+These commands talk to the server shorthand endpoints:
-# Create tab
-pinchtab --instance inst_abc123 tab create https://pinchtab.com
- # POST /instances/<id>/tabs/open {url}
+```bash
+pinchtab nav <url>
+pinchtab snap
+pinchtab click <ref>
+pinchtab type <ref> <text>
+pinchtab fill <ref|selector> <text>
+pinchtab press <key>
+pinchtab hover <ref>
+pinchtab scroll <ref|pixels>
+pinchtab select <ref> <value>
+pinchtab focus <ref>
+pinchtab text
+pinchtab ss
+pinchtab eval <expression>
+pinchtab pdf --tab <tabId>
+pinchtab health
+pinchtab quick <url>
+```
+
+These commands operate against the default routed tab context on the server.
+
+Supported flags:
-# Navigate tab
-pinchtab --instance inst_abc123 tab <tabId> navigate https://pinchtab.com
- # POST /tabs/<tabId>/navigate {url}
+```bash
+pinchtab nav <url> [--new-tab] [--block-images] [--block-ads]
-# Close tab
-pinchtab --instance inst_abc123 tab <tabId> close
- # POST /tab {action:"close", tabId}
+pinchtab snap [-i|--interactive] [-c|--compact] [-d|--diff]
+ [-s|--selector <css>] [--max-tokens N] [--depth N] [--tab <tabId>]
-# Lock tab
-pinchtab --instance inst_abc123 tab <tabId> lock --owner agent1 --ttl 60
- # POST /tabs/<tabId>/lock {owner, ttl}
-```
+pinchtab text [--raw] [--tab <tabId>]
-### Pattern 5: Complex Payloads
+pinchtab ss [-o|--output <file>] [-q|--quality N] [--tab <tabId>]
-#### Option A: Flags (simple cases)
-```bash
-pinchtab --instance <id> navigate https://pinchtab.com --block-images --block-ads --timeout 30
+pinchtab pdf --tab <tabId> [-o|--output <file>] [--landscape] [--scale N]
+ [--paper-width N] [--paper-height N]
+ [--margin-top N] [--margin-bottom N]
+ [--margin-left N] [--margin-right N]
+ [--page-ranges RANGE]
+ [--prefer-css-page-size]
+ [--display-header-footer]
+ [--header-template HTML]
+ [--footer-template HTML]
+ [--generate-tagged-pdf]
+ [--generate-document-outline]
+ [--file-output]
+ [--path PATH]
```
-Maps to:
-```json
-POST /tabs/<tabId>/navigate
-{
- "url": "https://pinchtab.com",
- "blockImages": true,
- "blockAds": true,
- "timeout": 30
-}
-```
+## Instance Commands
-#### Option B: JSON stdin (complex cases)
-```bash
-cat << 'EOF' | pinchtab --instance <id> action
-{
- "kind": "select",
- "ref": "e5",
- "value": "option2",
- "waitNav": true
-}
-EOF
-```
+The current instance CLI shape is:
-Or:
```bash
-pinchtab --instance <id> action -f payload.json
-pinchtab --instance <id> action --json '{...}'
-```
+pinchtab instances
-#### Option C: Shell-friendly formats
-```bash
-# String payload (auto-quoted)
-pinchtab --instance <id> evaluate 'document.title'
-
-# File reference
-pinchtab --instance <id> upload --file screenshot.png --to /form/input
-
-# Multi-line (heredoc)
-pinchtab --instance <id> action << 'EOF'
-{
- "kind": "actions",
- "actions": [
- {"kind": "click", "ref": "e5"},
- {"kind": "type", "ref": "e12", "text": "hello"}
- ]
-}
-EOF
-```
+pinchtab instance start [--profileId <id>] [--mode headed|headless] [--port <port>]
+pinchtab instance launch [--profileId <id>] [--mode headed|headless] [--port <port>]
-## Mapping: Endpoints → CLI Commands
-
-### Instance Management
-| Endpoint | HTTP | CLI Command |
-|----------|------|-------------|
-| `/instances` | GET | `pinchtab instances` |
-| `/instances/launch` | POST | `pinchtab instance launch --mode headed --port 9869` |
-| `/instances/{id}/logs` | GET | `pinchtab instance <id> logs` |
-| `/instances/{id}/stop` | POST | `pinchtab instance <id> stop` |
-| `/instances/{id}/tabs/open` | POST | `pinchtab --instance <id> tab create https://pinchtab.com` |
-| `/instances/{id}/tabs` | GET | `pinchtab --instance <id> tabs` |
-
-### Browser Control (Single Instance)
-| Endpoint | HTTP | CLI Command |
-|----------|------|-------------|
-| `/navigate` | POST | `pinchtab nav https://pinchtab.com` |
-| `/snapshot` | GET | `pinchtab snap -i -c` |
-| `/screenshot` | GET | `pinchtab ss -o out.png` |
-| `/action` | POST | `pinchtab click e5` |
-| `/actions` | POST | `pinchtab action -f actions.json` |
-| `/tab` | POST | `pinchtab tab create https://pinchtab.com` |
-| `/tabs` | GET | `pinchtab tabs` |
-| `/evaluate` | POST | `pinchtab eval "document.title"` |
-| `/tabs/{id}/pdf` | GET | `pinchtab pdf --tab <tabId> -o out.pdf --landscape` |
-| `/text` | GET | `pinchtab text` |
-| `/text` | GET | `pinchtab text --raw` |
-| `/cookies` | GET | `pinchtab cookies` |
-| `/cookies` | POST | `pinchtab cookies --set 'name=value; domain=.pinchtab.com'` |
-
-### Orchestrator Proxying (Instance-scoped)
-| Endpoint | HTTP | CLI Command |
-|----------|------|-------------|
-| `/tabs/{id}/navigate` | POST | `pinchtab instance navigate <id> https://pinchtab.com` |
-| `/tabs/{id}/snapshot` | GET | `pinchtab tab <tabId> snapshot -i` |
-| `/tabs/{id}/screenshot` | GET | `pinchtab tab screenshot <tabId> -o out.jpg` |
-| `/tabs/{id}/action` | POST | `pinchtab tab click <tabId> e5` |
-| `/tabs/{id}/actions` | POST | `curl -X POST /tabs/{id}/actions` |
-| `/tabs/{id}/text` | GET | `pinchtab tab text <tabId>` |
-| `/tabs/{id}/evaluate` | POST | `pinchtab tab eval <tabId> 'code'` |
-| `/tabs/{id}/pdf` | GET | `pinchtab --tab <tabId> pdf -o out.pdf` |
-
-## Real-World Examples
-
-### Example 1: Launch instance and navigate
-```bash
-# Start dashboard (separate terminal)
-pinchtab
+pinchtab instance navigate <instance-id> <url>
-# In another terminal:
-INST=$(pinchtab instance launch --mode headed --port 9869 | jq -r .id)
-echo "Started instance: $INST"
+pinchtab instance logs <instance-id>
+pinchtab instance logs --id <instance-id>
-# Navigate in that instance
-pinchtab --instance $INST nav https://github.com/pinchtab/pinchtab
+pinchtab instance stop <instance-id>
+pinchtab instance stop --id <instance-id>
```
-### Example 2: Snapshot and click
-```bash
-# See page structure
-pinchtab --instance inst_abc123 snap -i -c | jq .
+Important details:
+- `launch` is a CLI alias for `start`
+- both `start` and `launch` call `POST /instances/start` today
+- there is no `pinchtab instance <id> logs` grammar
+- there is no CLI subcommand for `attach`
-# Click a button
-pinchtab --instance inst_abc123 click e5
+HTTP mapping:
-# See what changed
-pinchtab --instance inst_abc123 snap -d
-```
+| CLI | HTTP |
+|---|---|
+| `pinchtab instances` | `GET /instances` |
+| `pinchtab instance start ...` | `POST /instances/start` |
+| `pinchtab instance launch ...` | `POST /instances/start` |
+| `pinchtab instance navigate <id> <url>` | `POST /instances/{id}/tabs/open` then `POST /tabs/{tabId}/navigate` |
+| `pinchtab instance logs <id>` | `GET /instances/{id}/logs` |
+| `pinchtab instance stop <id>` | `POST /instances/{id}/stop` |
-### Example 3: Multi-step workflow
-```bash
-# Get instances
-pinchtab instances
+## Tab Commands
-# Check instance status
-pinchtab instance inst_abc123 logs
-
-# Run actions on instance
-cat << 'EOF' | pinchtab --instance inst_abc123 action
-{
- "kind": "actions",
- "actions": [
- {"kind": "click", "ref": "e1"},
- {"kind": "type", "ref": "e2", "text": "search query"},
- {"kind": "press", "key": "Enter"},
- {"kind": "wait", "time": 2000}
- ]
-}
-EOF
-
-# Capture result
-pinchtab --instance inst_abc123 snap -c > page.json
-```
+The current tab CLI has two shapes:
+
+1. list or legacy lifecycle shortcuts
+2. explicit tab operations
+
+### List And Legacy Shortcuts
-### Example 4: Tab management
```bash
-# List tabs
-pinchtab --instance inst_abc123 tabs
+pinchtab tabs
+pinchtab tab
-# Create new tab
-TAB_ID=$(pinchtab --instance inst_abc123 tab create https://pinchtab.com | jq -r .id)
+pinchtab tabs new [url]
+pinchtab tab new [url]
-# Lock tab (prevent other agents from using it)
-pinchtab --instance inst_abc123 tab $TAB_ID lock --owner my-agent --ttl 60
+pinchtab tabs close <tabId>
+pinchtab tab close <tabId>
+```
-# Navigate in locked tab
-pinchtab --instance inst_abc123 tab $TAB_ID navigate https://google.com
+Notes:
+- `tabs` and `tab` are both accepted
+- `new` and `close` use the legacy `/tab` endpoint
+- `tab new` will auto-launch a default instance if none is running
-# Unlock
-pinchtab --instance inst_abc123 tab $TAB_ID unlock --owner my-agent
+### Explicit Tab Operations
-# Close tab
-pinchtab --instance inst_abc123 tab $TAB_ID close
-```
+The implemented grammar is:
-## Environment Variables
+```bash
+pinchtab tab navigate <tabId> <url>
+pinchtab tab snapshot <tabId> [-i] [-c] [-d]
+pinchtab tab screenshot <tabId> [-o file] [-q N]
+pinchtab tab click <tabId> <ref>
+pinchtab tab type <tabId> <ref> <text>
+pinchtab tab fill <tabId> <ref> <text>
+pinchtab tab press <tabId> <key>
+pinchtab tab hover <tabId> <ref>
+pinchtab tab scroll <tabId> <direction|pixels>
+pinchtab tab select <tabId> <ref> <value>
+pinchtab tab focus <tabId> <ref>
+pinchtab tab text <tabId> [--raw]
+pinchtab tab eval <tabId> <expression>
+pinchtab tab pdf <tabId> [-o file] [--landscape] [--scale N]
+pinchtab tab cookies <tabId>
+pinchtab tab lock <tabId> [--owner name] [--ttl seconds]
+pinchtab tab unlock <tabId> [--owner name]
+pinchtab tab locks <tabId>
+pinchtab tab info <tabId>
+```
+
+Important detail:
+- the operation comes before the tab ID
+- the implemented syntax is `pinchtab tab screenshot <tabId>`
+- it is **not** `pinchtab tab <tabId> screenshot`
+
+## Profiles Command
+
+The implemented profile command is:
```bash
-# Default instance for commands without --instance flag
-export PINCHTAB_INSTANCE=inst_abc123
+pinchtab profiles
+```
+
+Current behavior:
+- calls `GET /profiles`
+- prints a simple human-friendly list of names
+- does not currently expose create/update/delete operations through the CLI
-# Server URL/port
-export PINCHTAB_URL=http://localhost:9867
-export BRIDGE_PORT=9867
+## Environment
-# Authentication
-export PINCHTAB_TOKEN=sk_...
+The CLI uses these environment variables:
-# Default behavior
-export PINCHTAB_FORMAT=json # json, text, table
-export PINCHTAB_NO_COLOR=1 # Disable colored output
-export PINCHTAB_TIMEOUT=30 # Request timeout in seconds
+```bash
+PINCHTAB_URL # server base URL, default http://127.0.0.1:9867
+PINCHTAB_TOKEN # bearer token for API requests
+PINCHTAB_PORT # startup/server port
+CHROME_BIN # startup Chrome binary path
```
-## Flag Conventions
+Use `PINCHTAB_TOKEN`, not `BRIDGE_TOKEN`.
-### Common Flags (all commands)
-```
---instance <id> Target instance (overrides PINCHTAB_INSTANCE)
---tab <id> Target tab within instance
---timeout N Request timeout in seconds (default: 30)
---raw Raw output (no formatting)
---json Output as JSON
-```
+## Recommended Workflows
-### Snapshot Flags
-```
--i, --interactive Interactive elements only
--c, --compact Compact format (most token-efficient)
--d, --diff Only changes since last snapshot
--s, --selector CSS Scope to CSS selector
---max-tokens N Truncate to ~N tokens
---depth N Max tree depth
-```
+### Basic Top-Level Flow
-### Screenshot Flags
-```
--o, --output FILE Output filename
--q, --quality 0-100 JPEG quality (default: 80)
---format png|jpeg Output format
-```
+```bash
+pinchtab
-### PDF Flags
-```
--o, --output FILE Output filename
---landscape Landscape orientation
---paper-width N Width in inches (default: 8.5)
---paper-height N Height in inches (default: 11)
---margin-top/bottom/left/right N
---scale N Print scale 0.1-2.0
---page-ranges "1-3,5" Pages to export
+pinchtab nav https://pinchtab.com
+pinchtab snap -i -c
+pinchtab click e5
+pinchtab text
```
-### Navigation Flags
-```
---block-images Skip loading images
---block-ads Block ad requests
---block-media Skip media (video, audio)
---timeout N Navigation timeout in seconds
---new-tab Open in new tab (for orchestrator)
-```
+### Explicit Instance Flow
-## Error Handling
+```bash
+INST=$(pinchtab instance start --mode headed | jq -r '.id')
-All commands follow this pattern:
-```
-exit 0 — Success
-exit 1 — User error (bad args, file not found)
-exit 2 — Server error (500, connection refused)
-exit 3 — Timeout
-exit 4 — Instance/resource not found
+pinchtab instance navigate "$INST" https://pinchtab.com
+pinchtab tabs
```
-Error messages always printed to stderr:
+### Tab-Targeted Flow
+
```bash
-pinchtab --instance nonexistent snap 2>&1
-# Error: instance not found: nonexistent
-# exit: 4
+TAB=$(pinchtab tabs | jq -r '.[0].id')
+
+pinchtab tab snapshot "$TAB" -i -c
+pinchtab tab click "$TAB" e5
+pinchtab tab text "$TAB" --raw
+pinchtab tab pdf "$TAB" -o page.pdf
```
-## Future Extensibility
-
-This design scales to:
-- **Three-level nesting**: `pinchtab instance <id> tab <tabId> screencast <action>`
-- **Bulk operations**: `pinchtab instances exec 'snap -c' --all`
-- **Piping**: `pinchtab instances | jq '.[] | .id' | xargs -I {} pinchtab instance {} snap`
-- **Streaming**: `pinchtab --instance <id> screencast --stream` (server-sent events)
-- **REPL mode**: `pinchtab repl --instance <id>` (interactive shell)
-
-## Implementation Checklist
-
-- [ ] Implement `pinchtab instance <id> navigate <url>` (proxy to instance)
-- [ ] Implement `pinchtab --instance <id> tab <tabId> navigate <url>`
-- [ ] Add `--instance` flag to all browser control commands
-- [ ] Support stdin JSON for complex payloads
-- [ ] Support `-f` flag for reading payload from file
-- [ ] Add error handling with proper exit codes
-- [ ] Add `PINCHTAB_INSTANCE` environment variable support
-- [ ] Document in help (`pinchtab help`)
-- [ ] Add shell completion (`_bash`, `_zsh`)
+## Non-Goals For This Doc
+
+This page intentionally does not document commands that are not implemented yet, including:
+- a global `--instance` flag
+- `pinchtab instance attach`
+- full profile CRUD through the CLI
+- `pinchtab tab <tabId> <action>` grammar
diff --git a/docs/references/cli-quick-reference.md b/docs/references/cli-quick-reference.md
index 439cfe00..7474454e 100644
--- a/docs/references/cli-quick-reference.md
+++ b/docs/references/cli-quick-reference.md
@@ -1,483 +1,198 @@
# CLI Quick Reference
-**Legend:**
-- `inst_abc123` — Instance ID
-- `tab_xyz789` — Tab ID
-- `e5` — Element reference (from snapshot)
+This quick reference matches the current CLI implementation on this branch.
-## Instance Management
+## Startup
-### Launch an instance
```bash
-# Headless (default)
-pinchtab instance launch
-
-# Headed (with window)
-pinchtab instance launch --mode headed
-
-# On specific port
-pinchtab instance launch --port 9868
-
-# Get instance ID
-INST=$(pinchtab instance launch --mode headed | jq -r .id)
-echo $INST # inst_abc123
+pinchtab
+pinchtab server
+pinchtab bridge
```
-### List running instances
-```bash
-pinchtab instances
-
-# Get just IDs
-pinchtab instances | jq -r '.[] | .id'
+## Utility Commands
-# Get specific instance
-pinchtab instances | jq '.[] | select(.id == "inst_abc123")'
-```
-
-### Instance logs
```bash
-pinchtab instance inst_abc123 logs
+pinchtab --version
+pinchtab help
-# Follow logs (continuous)
-pinchtab instance inst_abc123 logs | tail -f
+pinchtab config init
+pinchtab config show
+pinchtab config path
+pinchtab config validate
-# Last 100 lines
-pinchtab instance inst_abc123 logs | tail -100
-```
-
-### Stop instance
-```bash
-pinchtab instance inst_abc123 stop
+pinchtab connect <profile>
+pinchtab connect <profile> --json
+pinchtab connect <profile> --dashboard http://localhost:9867
```
----
+## Environment
-## Browser Control (Single Instance)
-
-### Navigate
```bash
-# Default instance
-pinchtab nav https://pinchtab.com
-
-# Specific instance
-pinchtab --instance inst_abc123 nav https://pinchtab.com
-
-# Open in new tab
-pinchtab --instance inst_abc123 nav https://pinchtab.com --new-tab
-
-# Without images (faster)
-pinchtab --instance inst_abc123 nav https://pinchtab.com --block-images
+export PINCHTAB_URL=http://127.0.0.1:9867
+export PINCHTAB_TOKEN=secret_token
```
-### Snapshot page
-```bash
-# Full page
-pinchtab --instance inst_abc123 snap
-
-# Interactive elements only
-pinchtab --instance inst_abc123 snap -i
-
-# Compact (token-efficient)
-pinchtab --instance inst_abc123 snap -c
-
-# Interactive + compact (best for AI)
-pinchtab --instance inst_abc123 snap -i -c
-
-# Only changes since last snapshot
-pinchtab --instance inst_abc123 snap -d
-
-# Save to file
-pinchtab --instance inst_abc123 snap > page.json
-
-# Parse in script
-pinchtab --instance inst_abc123 snap -c | jq '.elements[] | .ref' | head -5
-```
+Startup-related envs:
-### Click element
```bash
-pinchtab --instance inst_abc123 click e5
+PINCHTAB_PORT=9868 pinchtab
+PINCHTAB_BIND=0.0.0.0 pinchtab
+CHROME_BIN=/usr/bin/google-chrome pinchtab
```
-### Type text
-```bash
-pinchtab --instance inst_abc123 type e12 "hello world"
-```
-
-### Fill input (directly, no events)
-```bash
-pinchtab --instance inst_abc123 fill e12 "value"
-```
+## Top-Level Browser Control
-### Press key
```bash
-pinchtab --instance inst_abc123 press Enter
-pinchtab --instance inst_abc123 press Tab
-pinchtab --instance inst_abc123 press Escape
-```
+pinchtab nav https://pinchtab.com
+pinchtab nav https://pinchtab.com --new-tab
+pinchtab nav https://pinchtab.com --block-images --block-ads
+
+pinchtab snap
+pinchtab snap -i
+pinchtab snap -i -c
+pinchtab snap -d
+pinchtab snap --selector 'main'
+pinchtab snap --tab <tabId>
+
+pinchtab click e5
+pinchtab type e12 "hello world"
+pinchtab fill e12 "value"
+pinchtab fill 'input[name=email]' "[email protected]"
+pinchtab press Enter
+pinchtab hover e5
+pinchtab scroll e5
+pinchtab scroll 500
+pinchtab select e7 option2
+pinchtab focus e7
+
+pinchtab text
+pinchtab text --raw
+pinchtab text --tab <tabId>
+
+pinchtab ss -o out.jpg
+pinchtab ss -q 85 -o out.jpg
+pinchtab ss --tab <tabId> -o out.jpg
+
+pinchtab eval "document.title"
+
+pinchtab pdf --tab <tabId> -o page.pdf
+pinchtab pdf --tab <tabId> -o page.pdf --landscape
+pinchtab pdf --tab <tabId> --scale 0.9 -o page.pdf
-### Scroll
-```bash
-pinchtab --instance inst_abc123 scroll down
-pinchtab --instance inst_abc123 scroll up
-pinchtab --instance inst_abc123 scroll 500 # pixels
+pinchtab health
+pinchtab quick https://pinchtab.com
```
-### Get page text
-```bash
-pinchtab --instance inst_abc123 text
+## Instance Commands
-# Raw text (no JSON wrapper)
-pinchtab --instance inst_abc123 text --raw
-```
-
-### Screenshot
```bash
-# To stdout (PNG)
-pinchtab --instance inst_abc123 ss > screenshot.png
-
-# To file
-pinchtab --instance inst_abc123 ss -o out.png
+pinchtab instances
-# JPEG with quality
-pinchtab --instance inst_abc123 ss -o out.jpg -q 85
-```
+pinchtab instance start
+pinchtab instance start --mode headed
+pinchtab instance start --profileId prof_123
+pinchtab instance start --port 9999
-### PDF export
-```bash
-# Default (A4 portrait)
-pinchtab --instance inst_abc123 pdf -o out.pdf
+pinchtab instance launch
+pinchtab instance launch --mode headed
-# Landscape
-pinchtab --instance inst_abc123 pdf -o out.pdf --landscape
+pinchtab instance navigate inst_abc123 https://pinchtab.com
-# Letter size
-pinchtab --instance inst_abc123 pdf -o out.pdf --paper-width 8.5 --paper-height 11
+pinchtab instance logs inst_abc123
+pinchtab instance logs --id inst_abc123
-# Specific pages
-pinchtab --instance inst_abc123 pdf -o out.pdf --page-ranges "1-3,5"
+pinchtab instance stop inst_abc123
+pinchtab instance stop --id inst_abc123
```
-### Run JavaScript
-```bash
-pinchtab --instance inst_abc123 eval "document.title"
-
-# JSON result
-pinchtab --instance inst_abc123 eval "document.querySelectorAll('a').length"
-
-# Complex script
-pinchtab --instance inst_abc123 eval '
- JSON.stringify({
- title: document.title,
- url: location.href,
- links: document.querySelectorAll("a").length
- })
-'
-```
+Notes:
+- `launch` is a CLI alias for `start`
+- there is no CLI `attach` command yet
+- there is no `pinchtab instance <id> logs` grammar
----
+## Tabs
-## Tab Management
+### List And Legacy Lifecycle
-### List tabs
```bash
-pinchtab --instance inst_abc123 tabs
+pinchtab tabs
+pinchtab tab
-# Get tab IDs
-pinchtab --instance inst_abc123 tabs | jq -r '.tabs[] | .id'
+pinchtab tabs new https://pinchtab.com
+pinchtab tab new https://pinchtab.com
-# Count tabs
-pinchtab --instance inst_abc123 tabs | jq '.tabs | length'
+pinchtab tabs close tab_xyz789
+pinchtab tab close tab_xyz789
```
-### Create tab
-```bash
-# Create and get ID
-TAB=$(pinchtab --instance inst_abc123 tab create https://pinchtab.com | jq -r .id)
-echo $TAB # tab_xyz789
-```
+### Explicit Tab Operations
-### Navigate specific tab
```bash
-pinchtab --instance inst_abc123 tab tab_xyz789 navigate https://google.com
+pinchtab tab navigate tab_xyz789 https://google.com
+pinchtab tab snapshot tab_xyz789 -i -c
+pinchtab tab screenshot tab_xyz789 -o out.png
+pinchtab tab click tab_xyz789 e5
+pinchtab tab type tab_xyz789 e12 "hello world"
+pinchtab tab fill tab_xyz789 e12 "value"
+pinchtab tab press tab_xyz789 Enter
+pinchtab tab hover tab_xyz789 e5
+pinchtab tab scroll tab_xyz789 down
+pinchtab tab scroll tab_xyz789 500
+pinchtab tab select tab_xyz789 e7 option2
+pinchtab tab focus tab_xyz789 e7
+pinchtab tab text tab_xyz789 --raw
+pinchtab tab eval tab_xyz789 "document.title"
+pinchtab tab pdf tab_xyz789 -o page.pdf
+pinchtab tab cookies tab_xyz789
+pinchtab tab lock tab_xyz789 --owner my-agent --ttl 60
+pinchtab tab unlock tab_xyz789 --owner my-agent
+pinchtab tab locks tab_xyz789
+pinchtab tab info tab_xyz789
```
-### Close tab
-```bash
-pinchtab --instance inst_abc123 tab tab_xyz789 close
-```
+Important:
+- the implemented order is `pinchtab tab <operation> <tabId> ...`
+- not `pinchtab tab <tabId> <operation>`
-### Lock tab (prevent concurrent access)
-```bash
-# Lock for 60 seconds
-pinchtab --instance inst_abc123 tab tab_xyz789 lock --owner my-agent --ttl 60
+## Profiles
-# After work, unlock
-pinchtab --instance inst_abc123 tab tab_xyz789 unlock --owner my-agent
-```
-
----
-
-## Complex Actions
-
-### Multi-step workflow (JSON stdin)
```bash
-cat << 'EOF' | pinchtab --instance inst_abc123 action
-{
- "kind": "actions",
- "actions": [
- {"kind": "click", "ref": "e1"},
- {"kind": "type", "ref": "e2", "text": "search query"},
- {"kind": "press", "key": "Enter"},
- {"kind": "wait", "time": 2000},
- {"kind": "click", "ref": "e5"}
- ]
-}
-EOF
+pinchtab profiles
```
-### From file
-```bash
-# Create actions file
-cat > actions.json << 'EOF'
-{
- "kind": "actions",
- "actions": [
- {"kind": "click", "ref": "e1"},
- {"kind": "type", "ref": "e2", "text": "hello"},
- {"kind": "press", "key": "Enter"}
- ]
-}
-EOF
-
-# Run it
-pinchtab --instance inst_abc123 action -f actions.json
-```
+Current behavior:
+- lists profile names from the server
+- prints human-friendly output, not a structured JSON array
-### From inline JSON
-```bash
-pinchtab --instance inst_abc123 action --json '{"kind":"click","ref":"e5"}'
-```
+## Common Flows
----
+### Start And Drive A Page
-## Typical Workflow
-
-### 1. Start orchestrator
```bash
-# Terminal 1: Start the dashboard/orchestrator
pinchtab
-# Now listening on http://localhost:9867
-```
-### 2. Launch instance
-```bash
-# Terminal 2: Launch a headed instance
-INST=$(pinchtab instance launch --mode headed | jq -r .id)
-echo "Instance: $INST"
+pinchtab nav https://github.com/pinchtab/pinchtab
+pinchtab snap -i -c
+pinchtab click e5
+pinchtab text --raw
```
-### 3. Navigate and interact
-```bash
-# Navigate to website
-pinchtab --instance $INST nav https://github.com/pinchtab/pinchtab
-
-# See page structure
-pinchtab --instance $INST snap -i -c | jq .
-
-# Click button (find e5 from snapshot)
-pinchtab --instance $INST click e5
+### Launch An Instance Then Navigate It
-# See result
-pinchtab --instance $INST snap -i -c | jq '.elements[] | select(.ref == "e5")'
-```
-
-### 4. Extract data
```bash
-# Get all visible text
-pinchtab --instance $INST text --raw
-
-# Count links
-pinchtab --instance $INST eval 'document.querySelectorAll("a").length'
-
-# Export page
-pinchtab --instance $INST pdf -o page.pdf
+INST=$(pinchtab instance start --mode headed | jq -r '.id')
+pinchtab instance navigate "$INST" https://pinchtab.com
+pinchtab tabs
```
-### 5. Cleanup
-```bash
-# Stop instance
-pinchtab instance $INST stop
-
-# Verify stopped
-pinchtab instances
-```
-
----
-
-## Scripting Examples
-
-### Batch instances
-```bash
-# Launch 3 instances
-for i in {1..3}; do
- PORT=$((9868 + i))
- INST=$(pinchtab instance launch --mode headed --port $PORT | jq -r .id)
- echo "Instance $i: $INST"
-done
-```
+### Work Directly With A Known Tab
-### Parallel navigation
```bash
-# Navigate multiple instances concurrently
-for inst in $(pinchtab instances | jq -r '.[] | .id'); do
- (pinchtab --instance $inst nav https://pinchtab.com) &
-done
-wait
-
-echo "All instances navigated"
-```
-
-### Monitor instances
-```bash
-# Watch instance status
-while true; do
- clear
- pinchtab instances | jq -r '.[] | "\(.id) (\(.mode)): \(.status)"'
- sleep 2
-done
-```
-
-### Cleanup all instances
-```bash
-# Stop all instances
-pinchtab instances | jq -r '.[] | .id' | xargs -I {} pinchtab instance {} stop
-```
-
----
-
-## Troubleshooting
-
-### Check server status
-```bash
-pinchtab health
-# Should print: {"status": "ok"}
-```
-
-### View server logs
-```bash
-# If running in foreground, Ctrl+C to see logs
-# If running in background:
-jobs
-fg # bring to foreground
-```
-
-### Instance not starting?
-```bash
-# Check logs
-pinchtab instance inst_abc123 logs | tail -50
-
-# Check port availability
-lsof -i :9868
-```
-
-### Can't connect to instance?
-```bash
-# Verify instance is running
-pinchtab instances | jq '.[] | select(.id == "inst_abc123")'
-
-# Check status
-pinchtab instances | jq '.[] | select(.id == "inst_abc123") | .status'
-# Should be "running"
-```
-
-### Need to specify server address?
-```bash
-# For remote server
-export PINCHTAB_URL=http://192.168.1.100:9867
-
-# Or per-command (coming soon)
-pinchtab --server http://192.168.1.100:9867 instances
-```
-
----
-
-## Environment Variables
-
-```bash
-# Server address (if not on localhost:9867)
-export PINCHTAB_URL=http://localhost:9867
-
-# Server port (alternative to PINCHTAB_URL)
-export BRIDGE_PORT=9868
-
-# Default instance (skip --instance flag)
-export PINCHTAB_INSTANCE=inst_abc123
-
-# Auth token
-export PINCHTAB_TOKEN=sk_xxx
-
-# Request timeout
-export PINCHTAB_TIMEOUT=30
-
-# Output format
-export PINCHTAB_FORMAT=json # json, text (coming soon)
-
-# Disable colors
-export PINCHTAB_NO_COLOR=1
-```
-
----
-
-## Common Patterns
-
-### Wait for page load, then interact
-```bash
-pinchtab --instance inst_abc123 nav https://pinchtab.com
-sleep 2 # Wait for page
-pinchtab --instance inst_abc123 snap -i
-```
-
-### Click, wait, screenshot
-```bash
-pinchtab --instance inst_abc123 click e5
-sleep 1
-pinchtab --instance inst_abc123 ss -o result.png
-```
-
-### Form fill
-```bash
-pinchtab --instance inst_abc123 fill e1 "John Doe"
-pinchtab --instance inst_abc123 fill e2 "[email protected]"
-pinchtab --instance inst_abc123 click e3 # Submit button
-sleep 2
-pinchtab --instance inst_abc123 snap
-```
-
-### Search and verify
-```bash
-pinchtab --instance inst_abc123 nav https://google.com
-pinchtab --instance inst_abc123 fill e1 "golang"
-pinchtab --instance inst_abc123 press Enter
-sleep 2
-pinchtab --instance inst_abc123 text | grep -q "golang"
-echo "Search results found"
-```
-
----
-
-## Exit Codes
-
-```bash
-pinchtab instance inst_abc123 logs
-echo $? # 0 = success
-
-pinchtab --instance nonexistent snap
-echo $? # 4 = not found
-
-pinchtab instance launch --invalid-flag
-echo $? # 1 = user error
+TAB=tab_xyz789
-curl http://localhost:9867/health > /dev/null || {
- echo "Server down" # 2 = server error
-}
+pinchtab tab snapshot "$TAB" -i -c
+pinchtab tab click "$TAB" e5
+pinchtab tab text "$TAB" --raw
+pinchtab tab pdf "$TAB" -o page.pdf
```
diff --git a/docs/references/configuration.md b/docs/references/configuration.md
index 86ac84be..ef2a6b06 100644
--- a/docs/references/configuration.md
+++ b/docs/references/configuration.md
@@ -244,7 +244,7 @@ This is policy only. The actual `cdpUrl` belongs to the attach request, not glob
### Custom Ports
```bash
-PINCHTAB_PORT=8080 pinchtab dashboard
+PINCHTAB_PORT=8080 pinchtab server
```
Or in config file:
diff --git a/docs/references/endpoints.md b/docs/references/endpoints.md
index ae4198da..1e564f25 100644
--- a/docs/references/endpoints.md
+++ b/docs/references/endpoints.md
@@ -4,13 +4,12 @@ Complete HTTP API reference for instances, tabs, and browser operations.
## Overview
-PinchTab uses an **instance-scoped** REST API where:
-- **PinchTab server** listens on port 9867 and manages all instances
-- Each **instance** is an independent browser process (Chrome)
-- Each instance can use a different **profile** (Chrome user data directory)
-- Each instance can be **headed** (visible window) or **headless** (background)
-- Instances manage **tabs** (browser tabs/pages)
-- **Chrome starts on instance creation** (or first request, depending on configuration)
+Pinchtab uses a **server-first** API model:
+- the **Pinchtab server** listens on port `9867` and manages profiles and instances
+- each managed **instance** is backed by a single `pinchtab bridge` runtime
+- tab operations are tab-first under `/tabs/{id}/...`
+- instance lifecycle operations live under `/instances/...`
+- attach is the advanced path for registering externally managed Chrome
```text
HTTP Client
@@ -24,18 +23,18 @@ HTTP Client
│ │ - Dashboard │ │
│ │ - Instance management │ │
│ │ - Profile management │ │
-│ │ - Request routing via DevTools API │ │
+│ │ - Routing to bridge runtimes │ │
│ └────────────────────────────────────┘ │
└─────┬──────────────────────────────────────┘
│
- │ DevTools Protocol (WebSocket)
+ │ HTTP proxying to managed instances
│
├─────────────────────────────────────┐
│ │
↓ ↓
┌──────────────────┐ ┌──────────────────┐
-│ Chrome Process 1 │ │ Chrome Process 2 │
-│ (headed) │ │ (headless) │
+│ Bridge Runtime 1 │ │ Bridge Runtime 2 │
+│ + Chrome │ │ + Chrome │
│ profile: work │ │ profile: scraping│
├──────────────────┤ ├──────────────────┤
│ Tab 1: LinkedIn │ │ Tab 1: API │
@@ -48,7 +47,7 @@ HTTP Client
| Category | Operations | Purpose |
|---|---|---|
-| **Instance Management** | `POST /instances` `GET /instances` `GET /instances/{id}` `DELETE /instances/{id}` | Create, list, and manage browser instances |
+| **Instance Management** | `POST /instances/start` `POST /instances/launch` `POST /instances/attach` `GET /instances` `GET /instances/{id}` `POST /instances/{id}/stop` | Create, attach, list, inspect, and stop instances |
| **Navigation** | `POST /tabs/{id}/navigate` | Navigate an existing tab by tab ID |
| **Tab Operations** | `POST /instances/{id}/tabs/open` `GET /instances/{id}/tabs` `POST /tabs/{tabId}/navigate` | Open/list tabs and navigate existing tab |
| **Page Inspection** | `GET /tabs/{id}/snapshot` `GET /tabs/{id}/text` | Get accessibility tree, extract text |
@@ -72,58 +71,71 @@ All requests go to port 9867. Instance-scoped proxy operations use `/instances/{
## Instance Management API
-### Create Instance
+### Launch or Start Instance
**Endpoint:**
```
-POST /instances
+POST /instances/start
+POST /instances/launch
```
**Request Body:**
```json
{
- "profile": "work",
- "headless": false
+ "profileId": "work",
+ "mode": "headed"
}
```
**Parameters:**
-- `profile` (string, required) — Chrome profile name (stored in `~/.pinchtab/profiles/{name}`)
-- `headless` (boolean, required) — `true` for headless mode (no window), `false` for visible window
+- `profileId` (string, optional) - profile ID or name
+- `name` (string, optional on `/instances/launch`) - instance/profile name when launching by name
+- `mode` (string, optional) - `headless` or `headed`
+- `port` (string, optional) - explicit port if you do not want auto-allocation
**Behavior:**
-- **Synchronously starts Chrome** with the specified profile and mode
-- If headless=false, a visible Chrome window opens immediately
-- If headless=true, Chrome runs in the background
-- Returns only after Chrome is fully initialized and ready for commands
+- Creates a managed instance record on the server
+- Spawns a `pinchtab bridge` child process for managed instances
+- Chrome may initialize lazily on the first browser request
+- Returns instance metadata used for later tab operations
**Response (201 Created):**
```json
{
- "id": "work-9868",
- "profile": "work",
+ "id": "inst_0a89a5bb",
+ "profileId": "prof_278be873",
+ "profileName": "work",
"headless": false,
- "status": "running",
+ "status": "starting",
"port": "9868",
- "startTime": "2026-02-28T18:35:18Z",
- "tabs": []
+ "startTime": "2026-02-28T18:35:18Z"
}
```
-**Notes:**
-- Instance is **fully ready** immediately after this call (Chrome already running)
-- Subsequent navigation and action calls use this running Chrome
-- No lazy initialization - Chrome starts upfront for predictable behavior
-
**Example (curl):**
```bash
-curl -X POST http://localhost:9867/instances \
+curl -X POST http://localhost:9867/instances/launch \
-H "Content-Type: application/json" \
- -d '{"profile":"work","headless":false}'
+ -d '{"name":"work","mode":"headed"}'
+```
+
+### Attach Instance
-# Returns immediately with running instance ready for use
+**Endpoint:**
+```
+POST /instances/attach
```
+**Request Body:**
+```json
+{
+ "name": "shared-chrome",
+ "cdpUrl": "ws://127.0.0.1:9222/devtools/browser/..."
+}
+```
+
+Attach is only available when enabled in config under `attach.enabled`, and the target must pass `allowHosts` and `allowSchemes` policy checks.
+
---
### List All Instances
@@ -203,14 +215,20 @@ curl http://localhost:9867/instances/work-9868
**Endpoint:**
```
-DELETE /instances/{id}
+POST /instances/{id}/stop
```
-**Response (204 No Content):**
+**Response:**
+```json
+{
+ "id": "inst_0a89a5bb",
+ "status": "stopped"
+}
+```
**Example (curl):**
```bash
-curl -X DELETE http://localhost:9867/instances/work-9868
+curl -X POST http://localhost:9867/instances/inst_0a89a5bb/stop
```
---
@@ -768,10 +786,10 @@ curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:9867/instances
```
-Set via `BRIDGE_TOKEN` env var when starting server:
+Set via `PINCHTAB_TOKEN` when starting the server:
```bash
-BRIDGE_TOKEN=secret_token pinchtab
+PINCHTAB_TOKEN=secret_token pinchtab
```
---
diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go
index 97aade34..c1d019df 100644
--- a/internal/orchestrator/orchestrator.go
+++ b/internal/orchestrator/orchestrator.go
@@ -288,7 +288,6 @@ func (o *Orchestrator) Launch(name, port string, headless bool, extensionPaths [
envOverrides := map[string]string{
"PINCHTAB_PORT": port,
"PINCHTAB_CONFIG": childConfigPath,
- "PINCHTAB_ONLY": "1",
}
if o.runtimeCfg != nil && o.runtimeCfg.ChromeBinary != "" {
envOverrides["CHROME_BIN"] = o.runtimeCfg.ChromeBinary
@@ -298,7 +297,7 @@ func (o *Orchestrator) Launch(name, port string, headless bool, extensionPaths [
logBuf := newRingBuffer(64 * 1024)
slog.Info("starting instance process", "id", instanceID, "profile", name, "port", port)
- cmd, err := o.runner.Run(context.Background(), o.binary, env, logBuf, logBuf)
+ cmd, err := o.runner.Run(context.Background(), o.binary, []string{"bridge"}, env, logBuf, logBuf)
if err != nil {
return nil, fmt.Errorf("failed to start: %w", err)
}
diff --git a/internal/orchestrator/process_test.go b/internal/orchestrator/process_test.go
index 1bd2379b..0ac0ead6 100644
--- a/internal/orchestrator/process_test.go
+++ b/internal/orchestrator/process_test.go
@@ -12,6 +12,7 @@ import (
type mockRunner struct {
runCalled bool
portAvail bool
+ args []string
}
type mockCmd struct {
@@ -23,8 +24,9 @@ func (m *mockCmd) Wait() error { return nil }
func (m *mockCmd) PID() int { return m.pid }
func (m *mockCmd) Cancel() {}
-func (m *mockRunner) Run(ctx context.Context, binary string, env []string, stdout, stderr io.Writer) (Cmd, error) {
+func (m *mockRunner) Run(ctx context.Context, binary string, args []string, env []string, stdout, stderr io.Writer) (Cmd, error) {
m.runCalled = true
+ m.args = append([]string(nil), args...)
return &mockCmd{pid: 1234, isAlive: true}, nil
}
@@ -44,6 +46,9 @@ func TestLaunch_Mocked(t *testing.T) {
if !runner.runCalled {
t.Error("expected runner.Run to be called")
}
+ if len(runner.args) != 1 || runner.args[0] != "bridge" {
+ t.Fatalf("expected child process args [bridge], got %v", runner.args)
+ }
if !idutil.IsValidID(inst.ID, "inst") {
t.Errorf("expected ID format inst_XXXXXXXX, got %s", inst.ID)
}
diff --git a/internal/orchestrator/runner.go b/internal/orchestrator/runner.go
index 5fef7e69..ee82bbea 100644
--- a/internal/orchestrator/runner.go
+++ b/internal/orchestrator/runner.go
@@ -7,7 +7,7 @@ import (
)
type HostRunner interface {
- Run(ctx context.Context, binary string, env []string, stdout, stderr io.Writer) (Cmd, error)
+ Run(ctx context.Context, binary string, args []string, env []string, stdout, stderr io.Writer) (Cmd, error)
IsPortAvailable(port string) bool
}
@@ -24,9 +24,9 @@ type localCmd struct {
cancel context.CancelFunc
}
-func (r *LocalRunner) Run(ctx context.Context, binary string, env []string, stdout, stderr io.Writer) (Cmd, error) {
+func (r *LocalRunner) Run(ctx context.Context, binary string, args []string, env []string, stdout, stderr io.Writer) (Cmd, error) {
runCtx, cancel := context.WithCancel(ctx)
- cmd := exec.CommandContext(runCtx, binary)
+ cmd := exec.CommandContext(runCtx, binary, args...)
cmd.Env = env
cmd.Stdout = stdout
cmd.Stderr = stderr
diff --git a/scripts/testing/simulate-memory-load.sh b/scripts/testing/simulate-memory-load.sh
index 981af77b..8bf3c863 100755
--- a/scripts/testing/simulate-memory-load.sh
+++ b/scripts/testing/simulate-memory-load.sh
@@ -12,7 +12,7 @@ set -euo pipefail
# ./scripts/simulate-memory-load.sh localhost:9867 3 20 # 3 instances, 20 tabs each
#
# Prerequisites:
-# - pinchtab running in dashboard mode: ./pinchtab dashboard
+# - pinchtab running in server mode: ./pinchtab server
# - Chrome installed
HOST="${1:-localhost:9867}"
@@ -61,7 +61,7 @@ echo ""
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "http://${HOST}/health" 2>/dev/null || echo "000")
if [ "$STATUS" != "200" ]; then
echo -e "${RED}✗ Server not reachable at ${HOST} (HTTP ${STATUS})${NC}"
- echo " Start pinchtab first: ./pinchtab dashboard"
+ echo " Start pinchtab first: ./pinchtab server"
exit 1
fi
echo -e "${GREEN}✓ Server healthy${NC}"