mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Merge forge/terminal-dev-loop into beta
feat: integrated terminal, project actions and dev server preview (OM-17, OM-18, OM-19) Integration with #380 and #379: - Adopt the git-config identity model: drop the branch's identity stubs (getShellEnv, getAssignedGitIdentityEnv, repo identity ids, duplicate createGitService and getMainCheckoutPath); terminals receive only the GitHub token env and take their commit identity from git config. - Add RepoWorkspaceService as the single owner of OpenCode workspace side effects: worktree setup commands on create and terminal cleanup on remove, used by the workspace routes, the session launcher (ocm tool and multi-run) and multi-run discard, with one worktree-sibling matcher. - Run repo-delete terminal cleanup inside the worktree branch deletion flow. - Combine the CreateWorktreeDialog tests and update docs for the identity model and setup command coverage.
This commit is contained in:
commit
b13707b5b3
135 files changed
+12726
-492
No files matched your search
@@ -93,7 +93,7 @@ POST /sessions/*/fork
|
||||
**Deliberately not allow-listed:**
|
||||
|
||||
- `POST /notifications/send` — use the `send_notification` action instead.
|
||||
- `GET /git-credentials/gh-env` — returns the GitHub CLI environment (`GH_TOKEN`, `GITHUB_TOKEN`) for the OpenCode host process; it must not be readable by the agent.
|
||||
- `GET /git-credentials/gh-env` — returns the GitHub CLI environment (`GH_TOKEN`, `GITHUB_TOKEN`) for a working directory for the OpenCode host process; it must not be readable by the agent.
|
||||
- `POST /sandbox/shell` — the sandbox planner's internal route that resolves and pins the shell for a `shell` call; exposing it would let the agent drive shell planning directly.
|
||||
- `/repos/*/mirror/*` — the repo mirror protocol that the `ocm` CLI uses to sync entire repositories; it can create, replace, patch, or delete whole repos, so it stays reserved for the CLI.
|
||||
|
||||
|
||||
@@ -26,6 +26,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,71 @@
|
||||
# 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, 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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
When preview is unavailable — `PREVIEW_PORT=0`, or the gateway could not listen on its port — the panel shows **Preview is unavailable**.
|
||||
|
||||
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. If the port is already in use, the Manager still starts, logs a warning, and reports preview as unavailable.
|
||||
|
||||
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. In the other direction, any `Set-Cookie` from the preview target that names a Manager auth cookie or `ocm_preview` is dropped, so preview content cannot overwrite the Manager session. The start `path` must stay on the gateway origin; anything else redirects to `/`.
|
||||
|
||||
The gateway asks the target for uncompressed responses. When you use the preview remotely, put a compressing reverse proxy in front of it.
|
||||
|
||||
The gateway also proxies **WebSocket upgrades** on the same origin, so dev-server HMR works through the panel.
|
||||
|
||||
### Isolation level
|
||||
|
||||
A gateway on another port of the same host — or a `PREVIEW_PUBLIC_URL` on a subdomain of the Manager's domain — is a different origin but the **same site** as the Manager, so the browser still sends the Manager's `SameSite=Lax` session cookie with requests from preview content. The Manager therefore rejects state-changing API requests (`POST`, `PUT`, `PATCH`, `DELETE`) whose `Sec-Fetch-Site` is `same-site` or `cross-site` unless their `Origin` is listed in `AUTH_TRUSTED_ORIGINS`. Never add the preview gateway origin to `AUTH_TRUSTED_ORIGINS`.
|
||||
|
||||
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`. 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.
|
||||
|
||||
## 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,113 @@
|
||||
# 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.
|
||||
- An action `url` must start with `http://` or `https://`.
|
||||
- A repository action whose `id` matches a personal action is not listed or run, and the dialog reports a warning, so personal actions always win. It is still part of the file's trusted content (see [Trust](#trust)).
|
||||
- `.ocm` and `.ocm/project.json` must be regular files and directories. A symbolic link at either path is reported as an invalid file and is never written through.
|
||||
- The file is read from the selected repository or workspace directory, so each worktree can carry its own version. Trust is stored once per project, so trusting the file in one worktree does not trust a different version of it in another.
|
||||
|
||||
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:
|
||||
|
||||
- **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 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.
|
||||
- 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.
|
||||
- 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 — Manager worktrees and every OpenCode workspace, including workspaces created by multi-run and by agents through `ocm`. 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 env through `CredentialProvider.getGhCliEnv` at creation; commits take their identity from git config |
|
||||
| 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 env through `CredentialProvider.getGhCliEnv` at creation, take their commit identity from git config, 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,47 @@
|
||||
# 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 the repository's GitHub token environment (`GH_TOKEN`, `GITHUB_TOKEN`) resolved for its directory, so `gh` authenticates with the repo's GitHub credential. Commits made in the terminal take their author from git config: the repository's own identity when one is set, otherwise the Manager default identity (see [Git identities](git.md)).
|
||||
|
||||
`git` itself authenticates with the same credentials as the OpenCode server process, which the Manager configures from its saved git credentials.
|
||||
|
||||
## 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