mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 16: Phase 16: Documentation, container ports and full repository checks
This commit is contained in:
1 parent
81a9f0c8ef
commit
a383e57bc5
55 files changed
+4095
-59
No files matched your search
@@ -40,6 +40,7 @@ services:
|
||||
container_name: opencode-manager
|
||||
ports:
|
||||
- "5003:5003"
|
||||
- "5004:5004"
|
||||
- "5100:5100"
|
||||
- "5101:5101"
|
||||
- "5102:5102"
|
||||
@@ -157,7 +158,14 @@ ports:
|
||||
|
||||
### Dev Server Ports
|
||||
|
||||
Ports 5100-5103 are exposed for running dev servers inside repositories:
|
||||
Port 5004 is the [preview gateway](../features/preview.md). It proxies a running dev server through an authenticated origin and supports HMR, so it is the recommended way to view a dev server:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "5004:5004"
|
||||
```
|
||||
|
||||
Ports 5100-5103 remain exposed for running dev servers inside repositories and reaching them directly:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
@@ -167,6 +175,8 @@ ports:
|
||||
- "5103:5103"
|
||||
```
|
||||
|
||||
Exposing these raw ports bypasses the preview gateway's authentication and same-origin isolation. Prefer the gateway unless you need direct access to a dev server.
|
||||
|
||||
Configure your dev server to use one of these ports:
|
||||
|
||||
=== "Vite"
|
||||
|
||||
@@ -76,6 +76,15 @@ When configured, users can enable push notifications in Settings → Notificatio
|
||||
| `LOG_LEVEL` | Accepted but currently unused; debug output is controlled by `DEBUG` | `info` |
|
||||
| `DEBUG` | Enable debug logging | `false` |
|
||||
|
||||
## Preview Gateway
|
||||
|
||||
The preview gateway serves dev servers through an authenticated, separate origin (see [Preview](../features/preview.md)).
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `PREVIEW_PORT` | Port for the preview gateway. Set to `0` to disable preview entirely. | `5004` |
|
||||
| `PREVIEW_PUBLIC_URL` | Same-site HTTPS origin that proxies the preview gateway. Set this when the Manager is served over HTTPS or behind a reverse proxy, where mixed content and third-party cookies otherwise block the preview iframe. | empty |
|
||||
|
||||
## Database
|
||||
|
||||
| Variable | Description | Default |
|
||||
|
||||
@@ -23,6 +23,14 @@ OpenCode Manager provides a comprehensive web interface for managing OpenCode AI
|
||||
|
||||
[Learn more →](files.md)
|
||||
|
||||
### Terminal & Dev Loop
|
||||
|
||||
- **Terminal** — Interactive PTY terminals scoped to a repo or workspace directory, with tabs and reconnect after reload
|
||||
- **Project Actions** — Run and stop repo commands from the header menu, with shared `.ocm/project.json` actions and worktree setup commands
|
||||
- **Preview** — View a running dev server through an authenticated, same-origin-safe preview gateway with HMR support
|
||||
|
||||
[Terminal →](terminal.md) · [Project Actions →](project-actions.md) · [Preview →](preview.md)
|
||||
|
||||
### Chat & Sessions
|
||||
|
||||
- **Real-time Streaming** - Live message streaming with SSE
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# Preview
|
||||
|
||||
Open a running dev server inside the WebUI through an authenticated gateway.
|
||||
|
||||
The Preview panel lists the loopback ports that are currently listening, then proxies the selected one through a dedicated gateway origin. This lets you view a Vite, Next.js, or other dev server without exposing its raw port or weakening the Manager's own origin.
|
||||
|
||||
## Port List
|
||||
|
||||
Open **Preview** from the desktop sidebar tool list or the **More** drawer. The panel lists every listening loopback port on the host, with its port number, process command, and working directory. Ports inside the selected repository or workspace directory are badged **this repo** and sorted first.
|
||||
|
||||
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.
|
||||
|
||||
Selecting a port creates a preview session and renders the target in a sandboxed iframe. Selecting a different port starts a new session for it.
|
||||
|
||||
When preview is disabled the panel shows **Preview is disabled (PREVIEW_PORT=0)**.
|
||||
|
||||
If the requested port is not listening yet, the panel shows **Waiting for port N…** and refetches the list every 2 seconds for up to 60 seconds, then shows an error with a **Retry** button.
|
||||
|
||||
## Gateway
|
||||
|
||||
The preview gateway listens on `PREVIEW_PORT` (default 5004) on its own origin. It is a separate origin from the Manager on purpose: preview content is untrusted and must not share the Manager origin. Setting `PREVIEW_PORT=0` disables the gateway.
|
||||
|
||||
Access requires an authenticated preview session:
|
||||
|
||||
1. The Manager API mints a **single-use start token** for a listening port.
|
||||
2. The browser navigates to `/__ocm_preview/start?token=…&path=…` on the gateway origin.
|
||||
3. The gateway consumes the token (it expires after 60 seconds and cannot be reused) and sets an `ocm_preview` session cookie.
|
||||
|
||||
Requests then carry the cookie. Manager auth cookies are stripped before proxying, because host-scoped cookies are shared across ports; the preview target never sees them.
|
||||
|
||||
The gateway also proxies **WebSocket upgrades** on the same origin, so dev-server HMR works through the panel.
|
||||
|
||||
A browser can hold one preview target per gateway origin at a time: the `ocm_preview` cookie names a single session. Opening a different port replaces the current target.
|
||||
|
||||
## Opening Previews
|
||||
|
||||
A preview can be opened from more than one place:
|
||||
|
||||
- **Port list** — select a port in the panel.
|
||||
- **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
|
||||
|
||||
- **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.
|
||||
|
||||
## Behind HTTPS or a Reverse Proxy
|
||||
|
||||
By default the panel builds the gateway origin as `${location.protocol}//${location.hostname}:${PREVIEW_PORT}`. When the Manager is served over HTTPS (directly or behind a reverse proxy), the browser blocks the iframe for two reasons:
|
||||
|
||||
- **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`. 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.
|
||||
|
||||
## Related
|
||||
|
||||
- [Environment Variables](../configuration/environment.md) — `PREVIEW_PORT` and `PREVIEW_PUBLIC_URL`.
|
||||
- [Docker](../configuration/docker.md) — exposing the preview gateway port.
|
||||
- [Terminal & Dev Loop](terminal.md) — start a dev server in a terminal.
|
||||
@@ -0,0 +1,107 @@
|
||||
# Project Actions
|
||||
|
||||
Define repeatable commands for a repository and run them from the header menu.
|
||||
|
||||
Project actions are long-lived commands — a dev server, a build watcher, a test runner — that run in a terminal. They are configured in one of two places:
|
||||
|
||||
- **My settings** (personal) — stored in the Manager database, keyed to the repository's main checkout, so they apply across the repository and all its worktrees.
|
||||
- **The repository file** — `.ocm/project.json` at the repo root, committed and shared with everyone who clones it.
|
||||
|
||||
Both sources are merged in the **Project Actions** dialog and the header menu.
|
||||
|
||||
## Actions
|
||||
|
||||
An action has these fields:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `id` | Stable identifier. Letters, digits, `_` and `-`, up to 64 characters. |
|
||||
| `name` | Label shown in the menu, up to 60 characters. |
|
||||
| `command` | Shell command, up to 4000 characters. |
|
||||
| `icon` | Optional icon: `play`, `build`, `test`, `lint`, `terminal`, `server`, `bug`, or `rocket`. |
|
||||
| `url` | Optional URL template opened for the action. |
|
||||
| `autoOpenUrl` | When enabled, the resolved URL opens automatically after the action starts. |
|
||||
|
||||
Actions run as `/bin/sh -c <command>` in a PTY. Starting an action that is already running focuses its existing terminal instead of starting a second process. Stopping an action removes its PTY.
|
||||
|
||||
### URL Templates
|
||||
|
||||
The `url` field accepts two placeholders:
|
||||
|
||||
| Placeholder | Resolves to |
|
||||
|-------------|-------------|
|
||||
| `{worktree}` | The basename of the current directory. |
|
||||
| `{branch}` | The current git branch of the directory, from `git rev-parse --abbrev-ref HEAD`. |
|
||||
|
||||
For example, `http://localhost:5173/{worktree}` becomes `http://localhost:5173/feature-login` in a worktree named `feature-login`. If `{branch}` cannot be resolved (for example, a detached HEAD with no branch), the template is left unchanged.
|
||||
|
||||
When the resolved URL is a local dev URL (`http://localhost:PORT`, `127.0.0.1`, `0.0.0.0`, or `[::1]`), it opens in the [Preview](preview.md) panel rather than a new browser tab.
|
||||
|
||||
## Running and Stopping
|
||||
|
||||
The repository and session headers show a **Project actions** play button. The menu lists every configured action:
|
||||
|
||||
- Select an action to start it. The terminal opens automatically.
|
||||
- A running action shows a dot. Select **Stop** under it to remove its PTY.
|
||||
- Select **Manage actions…** to open the Project Actions dialog.
|
||||
|
||||
Actions defined in the repository file never run until trusted (see [Trust](#trust)).
|
||||
|
||||
## Repository Configuration File
|
||||
|
||||
`.ocm/project.json` defines actions and worktree setup commands for the repository. The format:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": 1,
|
||||
"projectActions": [
|
||||
{
|
||||
"id": "dev",
|
||||
"name": "Dev server",
|
||||
"command": "pnpm dev",
|
||||
"icon": "server",
|
||||
"url": "http://localhost:5173/{worktree}",
|
||||
"autoOpenUrl": true
|
||||
}
|
||||
],
|
||||
"setupWorktree": [
|
||||
"pnpm install"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `version` is required and must be `1`.
|
||||
- `projectActions` and `setupWorktree` are optional. Up to 50 actions and 20 setup commands are allowed.
|
||||
- A repository action whose `id` matches a personal action is ignored, and the dialog reports a warning, so personal actions always win.
|
||||
|
||||
## Moving Actions and Setup Commands
|
||||
|
||||
The Project Actions dialog moves items between personal settings and the repository file:
|
||||
|
||||
- **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.
|
||||
|
||||
Moves are transactional: if the file write or the settings update fails, the file is restored.
|
||||
|
||||
## Trust
|
||||
|
||||
Commands in `.ocm/project.json` run on your machine, so the Manager does not run them until you trust the file:
|
||||
|
||||
- Trust is a hash of the file's **executable content only**: each action's `id`, `command` and `url`, plus the setup commands. Changing an action's name, icon, or `autoOpenUrl` does not affect trust; changing a command, URL, or setup command does.
|
||||
- Trusting requires echoing the exact hash 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.
|
||||
- Moving an item into the file auto-trusts it, because the user authored it.
|
||||
|
||||
## Worktree Setup Commands
|
||||
|
||||
Setup commands run once after a new working directory is created — both Manager worktrees and OpenCode workspaces. They run in a PTY with `set -e`, so the first failing command stops the rest.
|
||||
|
||||
- `$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.
|
||||
|
||||
## Related
|
||||
|
||||
- [Terminal & Dev Loop](terminal.md) — the PTY terminals actions run in.
|
||||
- [Preview](preview.md) — open an action's URL in the preview panel.
|
||||
@@ -18,7 +18,7 @@ The microVM sees repositories through bind mounts at the same paths used by the
|
||||
| WebUI `!command` shell mode (`POST /api/session/:sessionID/shell`) | Yes; it spawns through the same `Shell.create` path as the `shell` tool, so it is planned and routed into the microVM. It is not badged in the UI because the surface fires no `tool.execute.after` hook |
|
||||
| Shell API (`POST /api/shell`) | Yes; it spawns through the same `Shell.create` path as the `shell` tool. It is not badged in the UI because the surface fires no `tool.execute.after` hook |
|
||||
| Slash-command shell templates (`` !`cmd` ``, `POST /api/session/:sessionID/command`) | No; OpenCode expands each interpolation itself with the configured shell, directly on the host and outside `Shell.create`, so the `create.before` hook never sees it |
|
||||
| PTY terminals (`POST /api/pty`, `POST /api/pty/:ptyID/connect`) | No; normal OpenCode behavior, with the user's configured shell |
|
||||
| PTY terminals (`POST /api/pty`, `POST /api/pty/:ptyID/connect`), including the Manager Terminal panel and project action terminals | No; normal OpenCode behavior, with the user's configured shell. Manager terminals and project actions receive the repo-scoped GitHub token and assigned commit identity env through `CredentialProvider.getShellEnv` at creation |
|
||||
| OpenCode file tools | No; while enforcement is on they are denied the global configuration directory (see [Mounts and Secrets](#mounts-and-secrets)) |
|
||||
| Manager-side git operations | No |
|
||||
| Plugins and custom tools | No; normal OpenCode behavior |
|
||||
@@ -49,7 +49,7 @@ Configured extensions execute with OpenCode's normal host-process privileges. Th
|
||||
|
||||
WebUI `!command` shell mode and the shell API (`POST /api/shell`) **are** sandboxed: both spawn through the same `Shell.create` path as the `shell` tool, so they are planned and routed into the microVM.
|
||||
|
||||
PTY terminals follow OpenCode's normal host-process behavior during enforcement and use the user's configured shell. Slash-command shell templates are not sandboxed either: when a command template contains a `` !`cmd` `` interpolation, OpenCode resolves the configured shell and runs the command directly on the host before the resulting prompt is sent, without going through `Shell.create` or its `create.before` hook. That interpolation is trusted configuration outside the agent `shell` isolation boundary.
|
||||
PTY terminals follow OpenCode's normal host-process behavior during enforcement and use the user's configured shell. This includes the Manager [Terminal panel](terminal.md) and [project actions](project-actions.md): they run as OpenCode PTYs on the host, receive the repo-scoped GitHub token and assigned commit identity env through `CredentialProvider.getShellEnv` at creation, and still bypass the sandbox shell hook. Slash-command shell templates are not sandboxed either: when a command template contains a `` !`cmd` `` interpolation, OpenCode resolves the configured shell and runs the command directly on the host before the resulting prompt is sent, without going through `Shell.create` or its `create.before` hook. That interpolation is trusted configuration outside the agent `shell` isolation boundary.
|
||||
|
||||
There is no fallback to a host shell in the `Shell.create` path: the shim refuses to run without a pinned sandbox working directory, so a spawn whose plan, shim, or lock is unavailable is refused instead of running on the host.
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Terminal & Dev Loop
|
||||
|
||||
Run interactive shells against a repository or workspace directory without leaving the WebUI.
|
||||
|
||||
## Opening a Terminal
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Tabs and Reconnect
|
||||
|
||||
Each terminal runs in its own tab:
|
||||
|
||||
- Click **+** to create another terminal in the same directory.
|
||||
- Click a tab to focus it.
|
||||
- Click the **×** on a tab to close it. Closing a running terminal asks for confirmation, then stops the process.
|
||||
- An exited terminal keeps its tab and shows `exited` with its exit code.
|
||||
|
||||
Terminals are backed by OpenCode PTYs, so they survive a browser close or reload: reopening the panel reattaches and replays the buffered output. They do **not** survive an OpenCode restart, which ends every PTY.
|
||||
|
||||
## Mobile Key Bar
|
||||
|
||||
On mobile, the panel shows a key bar above the keyboard with keys that are awkward to reach on a soft keyboard:
|
||||
|
||||
- **Esc**, **Tab**
|
||||
- **Ctrl** — tap to arm, then tap a key to send the modified combination; arming is consumed by the next key.
|
||||
- Arrow keys
|
||||
- `|`, `~`, `/`
|
||||
|
||||
## Runtime and Environment
|
||||
|
||||
Terminals run as OpenCode PTYs on the host, using the user's configured shell. They are **not sandboxed**: sandbox enforcement applies to agent `shell` tool calls, not to PTY terminals (see [Agent Sandboxing](sandboxing.md)).
|
||||
|
||||
Each terminal receives environment resolved for its directory:
|
||||
|
||||
- the repository's GitHub token environment, so `git` and `gh` authenticate as the repo's credentials;
|
||||
- the assigned git commit identity, so commits made in the terminal use the repo's configured author.
|
||||
|
||||
## Related
|
||||
|
||||
- [Project Actions](project-actions.md) — run and stop long-lived commands as terminals from the header menu.
|
||||
- [Preview](preview.md) — open a dev server started in a terminal.
|
||||
Reference in new issue
Block a user