feat(sessions): add permission modes, session goals, ocm session tool and multi-run

Per-session permission modes: each root session runs in ask or auto.
Auto answers each permission request once from the backend, child
sessions inherit their root's mode, forks copy the source's mode, and
scheduled runs and agent-created sessions stay on ask. A lock reason
reports why a session's mode cannot change.

Session goals: arm a goal in the composer and a backend audit loop keeps
the session working until an auditor model returns done or blocked. The
loop is bounded by continuation and token limits, survives restarts, and
pushes an outcome notification. Goals cannot start on scheduled-run or
child sessions.

ocm session tool: allow-listed internal routes to list, create, follow up
on, read replies from, and fork sessions. Created and forked sessions are
pinned to ask, listing covers a repo's workspaces, and replies wait for
the session to settle with a capped response.

Multi-run: launch one prompt on up to five models, optionally each in its
own OpenCode workspace, with per-entry status and discard.

Also add the shared owners this group needed (session launcher, session
reply, workspace create/remove, multi-run storage) and update the feature
docs.
This commit is contained in:
Chris Scott committed 2026-10-03 21:16:05 -04:00
1 parent 2af2577af8
commit 96e02e9646
91 files changed
+2140 -688

No files matched your search

+7 -6
View File
@@ -378,11 +378,11 @@ Retrieve a list of all managed repositories, ordered by the user's repo preferen
### Sessions
These routes back the `session-management` skill, so an agent can start work in a repo, hand a task to a new session, follow it up, read its reply, and fork it. Session creation always goes through the Manager's session launcher, which validates the repository and the requested model before creating anything.
These routes back the `session-management` skill, so an agent can start work in a repo, hand a task to a new session, follow it up, read its reply, and fork it. Session creation always goes through the Manager's session launcher, which validates the repository and the requested model before creating anything. Malformed JSON is rejected with `{ "error": "Invalid JSON" }`; a body that fails validation is rejected with `{ "error": "Invalid request body", "details": [...] }`; unknown upstream failures return `502`.
**GET `/api/internal/sessions`**
List sessions, newest first. Pass `repoId` to restrict the list to one repo and `limit` (1-50, default 10) to bound it.
List sessions, newest first. Pass `repoId` to restrict the list to one repo — this covers every OpenCode workspace of that repo, not only the repo directory — and `limit` (1-50, default 10) to bound it.
**Query Parameters:**
- `repoId` (optional): Restrict to a repository. An unknown id returns `404`.
@@ -395,7 +395,7 @@ List sessions, newest first. Pass `repoId` to restrict the list to one repo and
id: string
title: string | null
directory: string
repoId: number | null // null when the directory matches no known repo
repoId: number | null // null only when the directory belongs to no known repo
busy: boolean // true while the session is running
outcome: 'succeeded' | 'failed' | 'interrupted' | null
updated: number
@@ -412,7 +412,7 @@ List sessions, newest first. Pass `repoId` to restrict the list to one repo and
**POST `/api/internal/sessions`**
Create a session in a repo and send the first prompt. The response returns as soon as the prompt is queued, not when the run finishes; poll `GET /api/internal/sessions/:sessionId/reply` for the result. Pass `worktree: true` to run in a new isolated workspace, with `ref` selecting its base ref. A requested `model` must be available; an unavailable model is rejected with `400` rather than silently substituted.
Create a session in a repo and send the first prompt. The response returns as soon as the prompt is queued, not when the run finishes; poll `GET /api/internal/sessions/:sessionId/reply` for the result. Pass `worktree: true` to run in a new isolated workspace, with `ref` selecting its base ref. A requested `model` must be available; an unavailable model is rejected with `400` rather than silently substituted. Sessions created here are pinned to **ask** permission mode. With `worktree: true`, creation can take tens of seconds; a request that times out may still have succeeded, so check `GET /api/internal/sessions` before retrying.
**Request Body:**
```ts
@@ -472,7 +472,7 @@ Queue a follow-up prompt for an existing session.
**GET `/api/internal/sessions/:sessionId/reply`**
Read the latest assistant reply for a session and whether it is still running. Poll this after creating a session or queueing a prompt until `busy` is `false`.
Read the latest assistant reply for a session and whether it is still running. Poll this after creating a session or queueing a prompt until `busy` is `false`. Pass `waitMs` (0-45000) to wait until the session settles instead of polling in a loop; the response returns when it settles or the timeout elapses. `responseText` is capped at 20,000 characters, with a truncation marker appended when it is longer.
**Response:**
```ts
@@ -486,13 +486,14 @@ Read the latest assistant reply for a session and whether it is still running. P
**Status Codes:**
- `200`: Reply state returned
- `400`: Invalid `waitMs`
- `401`: Missing or invalid bearer token
- `404`: Session not found
- `502`: OpenCode error
**POST `/api/internal/sessions/:sessionId/fork`**
Fork a session, optionally before a specific message. Omit `beforeMessageId` to fork from the current point.
Fork a session, optionally before a specific message. Omit `beforeMessageId` to fork from the current point. The forked session is pinned to **ask** permission mode.
**Request Body:**
```ts
+2 -1
View File
@@ -15,7 +15,7 @@ The assistant workspace is a special repository-like directory managed and maint
## Skills Provided
Four skills are provisioned automatically when assistant mode is initialized:
Five skills are provisioned automatically when assistant mode is initialized:
| Skill | What it teaches |
|-------|----------------|
@@ -23,6 +23,7 @@ Four skills are provisioned automatically when assistant mode is initialized:
| `notifications` | Send push notifications to registered user devices with the `ocm` `send_notification` action |
| `manager-settings` | Read and patch user preferences, read and update the OpenCode configuration file, and reload the assistant workspace, through the `ocm` `request` action |
| `repo-management` | List all managed repositories through the `ocm` `request` action |
| `session-management` | List, create, follow up, read the reply of, and fork sessions through the `ocm` `request` action |
The assistant manages the Manager's global OpenCode configuration file through the `ocm` tool (`/opencode-config`), and the file on disk is the source of truth.
+6 -2
View File
@@ -103,7 +103,11 @@ Control who answers OpenCode permission requests for a session. The shield butto
The mode is owned by the backend, so a session in Accept everything keeps working while the browser is closed. Accept everything answers each request once and never saves a permanent rule, and it never overrides a `deny` rule. When you switch a session to Accept everything, requests already waiting are answered immediately.
Child sessions inherit the mode of their root session and cannot change it. Sessions started by a scheduled run always use their schedule's own permission configuration.
Child sessions inherit the mode of their root session and cannot change it, and the composer toggle is disabled for them with an explanation. A session forked from another starts with the source session's mode, except that forks of scheduled runs stay **Ask every time**.
Sessions started by a scheduled run always use their schedule's own permission configuration; the composer toggle is disabled there with an explanation. Sessions created or forked by an agent through the `ocm` tool always start in **Ask every time**, regardless of the default, though an agent can still send follow-ups to a session you switched to **Accept everything**.
If Manager restarts or loses its connection to OpenCode, permission requests already waiting in **Accept everything** sessions are answered when it reconnects.
To change the default for new sessions, go to **Settings → General → Sessions** and pick a **Default permission mode for new sessions**. The default is stamped onto a session when it is created, so changing it only affects sessions created afterwards, never existing ones.
@@ -113,7 +117,7 @@ Auto-accepted requests send no push notification, so you are not alerted for a r
A goal keeps a session working on an objective until an auditor model decides it is done or blocked, without you sending follow-up messages.
Arm goal mode with the target button in the composer, then send your message. That message becomes the goal objective, and it is sent to the session as usual. While a goal is active, each time the session goes idle the auditor decides the next step:
Arm goal mode with the target button in the composer, then send your message. That message becomes the goal objective, and it is sent to the session as usual. Goals cannot be started on scheduled-run sessions or subagent (child) sessions, and the goal button is disabled there. If you arm a goal and send while the agent is still responding, the message is queued and the goal starts; auditing begins after that queued turn. While a goal is active, each time the session goes idle the auditor decides the next step:
- **done** - the objective is verifiably achieved, and the goal completes.
- **blocked** - the agent needs a decision or access it cannot obtain. Three consecutive blocked verdicts stop the goal as blocked.
+3 -3
View File
@@ -12,7 +12,7 @@ Open a repository and click **Multi-run** in the header, next to **New Session**
4. Leave **Isolate runs** on to give each model its own workspace.
5. Optionally set **Start from** to a branch or ref. Empty starts from the current HEAD.
Click **Launch**. Each selected model gets its own session, and the same prompt is sent to all of them. Launching is parallel, and one model failing does not stop the others: the failed entry records its error while the rest keep running.
Click **Launch**. Each selected model gets its own session, and the same prompt is sent to all of them. Models are checked before any workspace is created, so a model that is not available fails its entry without creating a workspace while the other models still launch. Launching is parallel, and one model failing does not stop the others: the failed entry records its error while the rest keep running.
## Isolation
@@ -23,6 +23,6 @@ With **Isolate runs** on, each run is created in its own OpenCode workspace: a d
The **Runs** tab lists each group and its entries. Every entry shows the model, its status, and for a started run the live session status indicator. From here you can:
- **Open** a run to view its session and compare the result.
- **Discard** a run after confirmation. Discarding an isolated run also removes its workspace directory from the Workspaces tab. A non-isolated run keeps its session in the repository.
- **Discard** a run after confirmation. Discarding an isolated run also removes its workspace directory from the Workspaces tab; if that workspace was already removed, for example from the Workspaces tab, discarding still succeeds. A non-isolated run keeps its session in the repository.
Discarding is irreversible and cannot be repeated on an already discarded run.
Discarding is irreversible and cannot be repeated on an already discarded run. Deleting a repository removes its multi-run history.
+1 -1
View File
@@ -11,7 +11,7 @@ Push notifications allow you to receive alerts on your mobile device or desktop
- A **session encounters an error** during execution
- A **session completes successfully**
A notification is suppressed when a visible tab is already viewing the session that raised it, preventing duplicate alerts while you're actively monitoring that session. Subagent sessions never notify. A permission request that a session answers automatically (Accept everything mode) sends no notification, and a session with an active goal does not notify for each intermediate turn.
A notification is suppressed when a visible tab is already viewing the session that raised it, preventing duplicate alerts while you're actively monitoring that session. Subagent sessions never notify. A permission request that a session answers automatically (Accept everything mode) sends no notification. Goal outcome pushes are not sent when you paused or cancelled the goal yourself, when the turn failed (the regular error notification covers it), or while you are viewing the session.
## Supported Events