feat(ui): preview port menu, terminal auto-start, and project actions tabs

This commit is contained in:
Chris Scott committed 2026-10-04 01:34:57 -04:00
1 parent cf9fa61118
commit 62e36eb3b2
31 files changed
+1332 -489

No files matched your search

+4
View File
@@ -121,6 +121,10 @@ AUTH_TRUSTED_ORIGINS=https://yourdomain.com
AUTH_SECURE_COOKIES=true
```
### Cloudflare Tunnel
To reach a Manager on your local network through a Cloudflare Tunnel, including the Preview panel, follow [Cloudflare Tunnel](cloudflare-tunnel.md).
## Passkeys
Passwordless authentication using WebAuthn.
+170
View File
@@ -0,0 +1,170 @@
# Cloudflare Tunnel
Reach an OpenCode Manager running on your local network from anywhere over HTTPS, without opening ports on your router. This guide covers the Manager itself and the [Preview](../features/preview.md) panel, which needs a hostname of its own.
## What You Need
- A domain managed by Cloudflare, for example `example.com`.
- A Cloudflare Tunnel with `cloudflared` running on a machine that can reach the Manager. See Cloudflare's [Create a tunnel](https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/) guide.
- Two hostnames on that domain:
| Hostname | Serves | Manager port |
|----------|--------|--------------|
| `oc.example.com` | The Manager | 5003 |
| `preview.example.com` | The [preview gateway](../features/preview.md#gateway) | 5004 |
The examples below use these names; replace them with your own.
!!! info "Why Preview needs its own hostname"
Preview shows pages from dev servers you run, which is untrusted content. It is served from a separate origin so it can never act as the Manager. Both hostnames must be on the **same domain**: the preview login cookie is `SameSite=Lax`, which the browser only sends to a frame on the same site as the page around it.
!!! warning "Quick tunnels are not supported"
`trycloudflare.com` quick tunnels get a random hostname each time they start, so `PREVIEW_PUBLIC_URL` would change on every restart. Use a named tunnel on your own domain.
## 1. Publish Both Hostnames
In your tunnel, add a **published application route** for each hostname. The service URL depends on where `cloudflared` runs.
=== "cloudflared in Docker Compose"
Run `cloudflared` next to the Manager in the same `docker-compose.yml`, so it reaches the Manager over the Compose network:
```yaml
services:
app:
# the existing OpenCode Manager service
cloudflared:
image: cloudflare/cloudflared:latest
command: tunnel --no-autoupdate run
environment:
- TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN}
restart: unless-stopped
```
Put the tunnel token from the Cloudflare dashboard in `.env` as `CLOUDFLARE_TUNNEL_TOKEN`, then add these routes:
| Hostname | Service |
|----------|---------|
| `oc.example.com` | `http://app:5003` |
| `preview.example.com` | `http://app:5004` |
=== "cloudflared on another machine"
Point the routes at the Manager's LAN address:
| Hostname | Service |
|----------|---------|
| `oc.example.com` | `http://192.168.1.10:5003` |
| `preview.example.com` | `http://192.168.1.10:5004` |
With Docker, ports 5003 and 5004 must be published, as they are in the default `docker-compose.yml`.
=== "Locally managed tunnel"
For a tunnel configured with a `config.yml` file:
```yaml
tunnel: <TUNNEL-ID>
credentials-file: /etc/cloudflared/<TUNNEL-ID>.json
ingress:
- hostname: oc.example.com
service: http://192.168.1.10:5003
- hostname: preview.example.com
service: http://192.168.1.10:5004
- service: http_status:404
```
## 2. Configure the Manager
Add to `.env`:
```bash
AUTH_TRUSTED_ORIGINS=https://oc.example.com
AUTH_SECURE_COOKIES=true
PASSKEY_RP_ID=oc.example.com
PASSKEY_ORIGIN=https://oc.example.com
PREVIEW_PUBLIC_URL=https://preview.example.com
```
Then restart the Manager. With Docker: `docker compose up -d`.
| Variable | Why |
|----------|-----|
| `AUTH_TRUSTED_ORIGINS` | Lets the browser sign in from the tunnel hostname. |
| `AUTH_SECURE_COOKIES` | The tunnel serves HTTPS, so session cookies are marked secure. |
| `PASSKEY_RP_ID`, `PASSKEY_ORIGIN` | Passkeys are bound to the hostname. Passkeys added under another hostname (such as `localhost`) do not work here; add a new one from **Settings > Account**. |
| `PREVIEW_PUBLIC_URL` | Without it, the Preview panel loads `https://oc.example.com:5004`, which the tunnel does not serve, and the preview stays blank. |
!!! danger "Never add the preview hostname to `AUTH_TRUSTED_ORIGINS`"
The Manager rejects state-changing requests from other origins on the same site unless they are trusted. Trusting the preview hostname would let any page you preview act as you in the Manager. See [Isolation level](../features/preview.md#isolation-level).
## 3. Turn Off Caching for the Preview Hostname
**This step is required.** Cloudflare caches JavaScript, CSS, images and fonts by default, and keeps responses that have no cache headers for up to two hours ([Cloudflare default cache behavior](https://developers.cloudflare.com/cache/concepts/default-cache-behavior/)). The cache cannot tell dev servers or users apart. Every dev server shares the one preview hostname, and the gateway picks the target from your login cookie. Without this rule:
- Changes to your files do not appear for up to two hours.
- Two projects that serve the same path, such as `/main.js`, can receive each other's files.
- Cloudflare serves a cached file without going through the preview login, so anyone with its URL can download it.
Create a cache rule in the Cloudflare dashboard:
1. Go to **Caching > Cache Rules** and select **Create rule**.
2. Name it, for example `OpenCode Manager preview: bypass cache`.
3. Under **When incoming requests match**, choose **Custom filter expression**: **Hostname** **equals** `preview.example.com`.
4. Under **Cache eligibility**, select **Bypass cache**.
5. Select **Deploy**.
The Manager hostname does not need this rule.
## 4. Check WebSockets
The Terminal and Preview live reload (HMR) use WebSockets. On your domain's **Network** page in the Cloudflare dashboard, make sure **WebSockets** is **On**.
## 5. Cloudflare Access (Optional)
If you protect `oc.example.com` with [Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/), choose one of these for the preview hostname:
- **Add it to the same Access application.** In an application with several domains, Access issues the login cookie for the other domains after you sign in once, so the Preview frame never shows a login page ([multi-domain applications](https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/authorization-cookie/#multi-domain-applications)).
- **Leave it out of Access.** The preview gateway has its own login: it only opens a preview from a single-use token issued by a signed-in Manager, and answers every other request with `401`.
Do not put the preview hostname in a **separate** Access application. The Preview frame would be sent to the Access login page, which cannot be shown inside a frame, and the preview stays blank.
## Using the LAN Address as Well
`PREVIEW_PUBLIC_URL` applies however you open the Manager:
- **Through the tunnel** (`https://oc.example.com`): Preview works in the panel.
- **Through a LAN address** (`http://192.168.1.10:5003`): the panel still loads the preview from `https://preview.example.com`. That is a different site, so the browser blocks the preview cookie inside the frame. Use **Open in new tab** in the Preview toolbar, or use the tunnel hostname.
With `AUTH_SECURE_COOKIES=true` you also cannot sign in over plain HTTP, because browsers do not store secure cookies for `http://` addresses. Sign in through the tunnel hostname.
## Check the Setup
1. Open `https://oc.example.com` and sign in.
2. Start a dev server from the [Terminal](../features/terminal.md) or [Actions](../features/project-actions.md).
3. Open **Preview** and select its port. The page appears in the panel.
4. Edit a file the dev server serves. The change appears after live reload or a refresh.
5. Optional: open `https://preview.example.com` in a private window. It shows **Preview session expired. Reopen it from OpenCode Manager.** (or the Access login page, if the hostname is behind Access), which confirms that the preview cannot be opened without signing in.
## Troubleshooting
| Symptom | Cause | Fix |
|---------|-------|-----|
| Preview stays blank or cannot connect | `PREVIEW_PUBLIC_URL` is not set, so the panel uses port 5004 on the Manager hostname | Set `PREVIEW_PUBLIC_URL` and restart the Manager |
| **Preview session is invalid or expired.** inside the panel | The browser blocked the preview cookie: the hostnames are on different domains, or the Manager was opened by its LAN address | Put both hostnames on the same domain and open the Manager through the tunnel, or use **Open in new tab** |
| **Preview must run on a different origin than OpenCode Manager.** | `PREVIEW_PUBLIC_URL` points at the Manager's own hostname | Use a separate hostname for the preview |
| Old file contents, or another project's files | Cloudflare cached the files | Add the [cache rule](#3-turn-off-caching-for-the-preview-hostname), then purge the cache under **Caching > Configuration** |
| Live reload does not work, or the Terminal does not connect | WebSockets are off | Turn on [WebSockets](#4-check-websockets) |
| Access login page or a blank frame in the Preview panel | The preview hostname is in a separate Access application | Follow [Cloudflare Access](#5-cloudflare-access-optional) |
| Sign-in fails on the tunnel hostname | `AUTH_TRUSTED_ORIGINS` does not include `https://oc.example.com` | Add it and restart the Manager |
## Related
- [Preview](../features/preview.md) — how the preview gateway works.
- [Authentication](authentication.md) — trusted origins, secure cookies and passkeys.
- [Docker](docker.md) — ports and environment variables.
- [Environment Variables](environment.md#preview-gateway) — `PREVIEW_PORT` and `PREVIEW_PUBLIC_URL`.
+4
View File
@@ -76,6 +76,7 @@ services:
- PASSKEY_RP_ID=${PASSKEY_RP_ID:-localhost}
- PASSKEY_RP_NAME=${PASSKEY_RP_NAME:-OpenCode Manager}
- PASSKEY_ORIGIN=${PASSKEY_ORIGIN:-http://localhost:5003}
- PREVIEW_PUBLIC_URL=${PREVIEW_PUBLIC_URL:-}
- VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY:-}
- VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY:-}
- VAPID_SUBJECT=${VAPID_SUBJECT:-}
@@ -120,6 +121,9 @@ GITHUB_CLIENT_SECRET=your-client-secret
PASSKEY_RP_ID=localhost
PASSKEY_ORIGIN=http://localhost:5003
# Optional - preview gateway behind HTTPS (see Cloudflare Tunnel)
PREVIEW_PUBLIC_URL=https://preview.example.com
# Optional - push notifications
VAPID_PUBLIC_KEY=BMx-1234567890abcdefghijklmnopqrstuv...
VAPID_PRIVATE_KEY=abcd1234567890abcdef...
+13 -5
View File
@@ -6,11 +6,13 @@ The Preview panel lists the loopback ports that are currently listening, then pr
## Port List
Open **Preview** from the desktop sidebar tool list or the **More** drawer, including in the Assistant workspace. The panel lists every listening loopback port on the host, with its port number and process command. On Linux hosts (including the Docker image) it also shows each process's working directory, and ports inside the selected repository or workspace directory are badged **this repo** and sorted first. On macOS the working directory is not available, so no port is badged. Other platforms list no ports.
Open **Preview** from the desktop sidebar tool list or the **More** drawer, including in the Assistant workspace. The port menu at the start of the toolbar lists every listening loopback port on the host as `:PORT command`, with the process's working directory underneath. Type in the menu to filter by port, command or directory. Working directories are read on Linux hosts (including the Docker image) and macOS; ports whose process runs inside the selected repository or workspace directory are grouped under **This repo** at the top, and the rest under **Other ports**. Other platforms list no ports.
Until a port is selected, the panel body lists the dev servers of this repo so one click opens the preview, and counts the other listening ports. When nothing is listening, it points to the Terminal and Actions to start a dev server.
The list excludes reserved ports — the Manager port (`PORT`, default 5003), the OpenCode server port (default 5551) and the preview gateway port itself — and only includes ports at or above 1024. Any other listening loopback port can be previewed; there is no per-port allow-list. This grants nothing an authenticated user does not already have, because the [Terminal](terminal.md) can reach the same ports.
While the port list is shown it refreshes every 2 seconds. It stops refreshing while a preview is open.
Until a preview is open, the port list refreshes every 2 seconds. While a preview is open it refreshes only when you open the port menu.
Selecting a port creates a preview session and renders the target in an iframe on the gateway origin. The iframe keeps that origin (`allow-same-origin`) so dev servers can use cookies and storage; isolation from the Manager comes from the separate origin, not from an opaque sandbox. Selecting a different port starts a new session for it.
@@ -44,16 +46,17 @@ A browser can hold one preview target per gateway origin at a time: the `ocm_pre
A preview can be opened from more than one place:
- **Port list** — select a port in the panel.
- **Port menu** — pick a port in the toolbar, or a dev server listed in the panel body.
- **Terminal links** — clicking a local dev URL (`http://localhost:PORT`, `127.0.0.1`, `0.0.0.0`, or `[::1]`) printed in a terminal opens the Preview panel at that port and path instead of a new browser tab. External links still open in a new tab.
- **Project actions** — an action's resolved URL opens in the Preview panel when **Auto-open URL** is enabled.
## Toolbar
- **Port** — the port menu described in [Port List](#port-list). Press Escape to close the menu without closing the panel.
- **Path** — enter a path and press **Go** (or Enter) to start a session for that path.
- **Reload** — remounts the iframe.
- **Open in new tab** — creates a fresh session and opens its start URL in a new tab with `noopener`. Start tokens are single-use, so this always mints a new one.
- **Viewport** — switch between Mobile (390 px), Tablet (820 px), and Full width.
- **Viewport** — switch between Mobile (390 px), Tablet (820 px), and Full width. Hidden on small screens, where the panel is already phone-width.
## Behind HTTPS or a Reverse Proxy
@@ -62,7 +65,12 @@ By default the panel builds the gateway origin as `${location.protocol}//${locat
- **Mixed content** — an `https://` page cannot embed an `http://` preview.
- **Third-party cookies** — the `ocm_preview` cookie is blocked in a cross-site iframe.
Set `PREVIEW_PUBLIC_URL` to a same-site HTTPS origin that proxies the preview gateway, for example `https://preview.example.com`. Do not add it to `AUTH_TRUSTED_ORIGINS` (see [Isolation level](#isolation-level)). The panel then builds preview URLs from that origin instead. As a fallback, **Open in new tab** opens the preview as a top-level page, where the session cookie is first-party.
Set `PREVIEW_PUBLIC_URL` to a same-site HTTPS origin that proxies the preview gateway, for example `https://preview.example.com`. Do not add it to `AUTH_TRUSTED_ORIGINS` (see [Isolation level](#isolation-level)). The panel then builds preview URLs from that origin instead, however the Manager itself was opened. As a fallback, **Open in new tab** opens the preview as a top-level page, where the session cookie is first-party.
!!! warning "Turn off caching for the preview origin"
The gateway passes the dev server's cache headers through unchanged, and every port shares the one preview origin. A CDN or caching proxy in front of the gateway can therefore serve stale files, mix files between projects, and serve cached files without the preview login. Bypass caching for the preview hostname.
For a complete setup through a Cloudflare Tunnel, including the cache rule and Cloudflare Access, see [Cloudflare Tunnel](../configuration/cloudflare-tunnel.md).
## Related
+4 -4
View File
@@ -81,7 +81,7 @@ Project actions are not available in the Assistant workspace.
## Moving Actions and Setup Commands
The Project Actions dialog moves items between personal settings and the repository file:
The Project Actions dialog moves items between personal settings and the repository file from each row's **⋯** menu:
- **Move to repository** writes the item into `.ocm/project.json` and removes it from personal settings. Because the user authored it, the file is trusted automatically.
- **Move to my settings** removes the item from `.ocm/project.json` (deleting the file if it becomes empty) and stores it in personal settings.
@@ -93,10 +93,10 @@ Moves are transactional: if the file write or the settings update fails, the fil
Commands in `.ocm/project.json` run on your machine, so the Manager does not run them until you trust the file:
- Trust covers everything in the file that can run or open: each action's `id`, `name`, `command`, `url` and `autoOpenUrl` (including actions hidden because a personal action has the same `id`), plus every setup command. Changing any of these resets trust; changing an icon does not.
- Both trust prompts — **Trust these commands** in the dialog and **Trust and run** in the header menu — list every action and setup command that trusting covers, not only the one you clicked.
- Both trust prompts — **Review** in the dialog and **Trust and run** in the header menu — list every action and setup command that trusting covers, not only the one you clicked.
- Trusting requires echoing the exact hash of the content shown, so a file cannot be swapped between review and trust.
- Untrusted repository commands never run — not from the header menu, and not as worktree setup commands.
- The dialog shows the untrusted commands and a **Trust these commands** button. Attempting to run an untrusted action prompts for trust first.
- The dialog shows a banner above its tabs while the file is untrusted. **Review** lists the untrusted commands, and **Trust these commands** confirms. Attempting to run an untrusted action prompts for trust first.
- Moving an item into the file auto-trusts it, because the user authored it.
## Worktree Setup Commands
@@ -105,7 +105,7 @@ Setup commands run once after a new working directory is created — Manager wor
- `$ROOT_PROJECT_PATH` is available in the environment and points at the repository's main checkout.
- Personal setup commands always run. Repository setup commands are skipped while the file is untrusted; the skipped result is reported.
- Setup commands are configured in the **Worktree setup** section of the Project Actions dialog.
- Setup commands are configured in the **Worktree setup** tab of the Project Actions dialog. Edits are saved together with **Save setup**, which is enabled once there are unsaved changes.
## Related
+1 -1
View File
@@ -9,7 +9,7 @@ Open the terminal from either surface:
- **Desktop sidebar** — click **Terminal** in the tool list for a repository or session.
- **More drawer** — on mobile or from the overflow menu, open **More** and select **Terminal**.
The terminal panel opens as a dialog. If no terminal exists for the selected directory yet, the panel starts one automatically.
The terminal panel opens as a dialog. If nothing is running in the selected directory, opening the panel starts a shell automatically; exited terminals do not count. Opening a specific terminal — such as a project action or worktree setup — shows that terminal instead and starts nothing extra.
Terminals are scoped to the selected repository or OpenCode workspace directory. A terminal opened from a repo runs in that repo's path; a terminal opened from a session runs in the session's working directory. Switching directories shows that directory's terminals.