diff --git a/docs/features/assistant-internal-api.md b/docs/features/assistant-internal-api.md index 3b1a8f19..80c0e2a3 100644 --- a/docs/features/assistant-internal-api.md +++ b/docs/features/assistant-internal-api.md @@ -83,6 +83,11 @@ DELETE /repos/*/schedules/*/runs GET /repos/*/schedules/*/runs/* DELETE /repos/*/schedules/*/runs/* POST /repos/*/schedules/*/runs/*/cancel +GET /sessions +POST /sessions +POST /sessions/*/prompt +GET /sessions/*/reply +POST /sessions/*/fork ``` **Deliberately not allow-listed:** @@ -371,13 +376,156 @@ Retrieve a list of all managed repositories, ordered by the user's repo preferen - `401`: Missing or invalid bearer token - `500`: Server error (database failure) +### 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. + +**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. + +**Query Parameters:** +- `repoId` (optional): Restrict to a repository. An unknown id returns `404`. +- `limit` (optional): 1-50, default 10. + +**Response:** +```ts +{ + sessions: Array<{ + id: string + title: string | null + directory: string + repoId: number | null // null when the directory matches no known repo + busy: boolean // true while the session is running + outcome: 'succeeded' | 'failed' | 'interrupted' | null + updated: number + }> +} +``` + +**Status Codes:** +- `200`: Session list returned +- `400`: Invalid query +- `401`: Missing or invalid bearer token +- `404`: Repository not found +- `502`: OpenCode error + +**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. + +**Request Body:** +```ts +{ + repoId: number + prompt: string // 1-20000 characters + title?: string // max 200 characters + model?: string + agent?: string + worktree?: boolean + ref?: string +} +``` + +**Response (`201`):** +```ts +{ + sessionId: string + repoId: number + directory: string + workspaceDirectory: string | null + model: string + title: string | null + url: string // deep link to open the session in the UI +} +``` + +**Status Codes:** +- `201`: Session created and prompt queued +- `400`: Invalid request body, or the requested model is unavailable +- `401`: Missing or invalid bearer token +- `404`: Repository not found +- `502`: OpenCode error + +**POST `/api/internal/sessions/:sessionId/prompt`** + +Queue a follow-up prompt for an existing session. + +**Request Body:** +```ts +{ + text: string // 1-20000 characters +} +``` + +**Response (`202`):** +```ts +{ queued: true } +``` + +**Status Codes:** +- `202`: Prompt queued +- `400`: Invalid request body +- `401`: Missing or invalid bearer token +- `404`: Session not found +- `502`: OpenCode error + +**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`. + +**Response:** +```ts +{ + busy: boolean + responseText: string | null // latest assistant text, null when there is none yet + errorText: string | null // assistant error message, null when the turn succeeded + completed: boolean // true once the latest assistant turn finished +} +``` + +**Status Codes:** +- `200`: Reply state returned +- `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. + +**Request Body:** +```ts +{ + beforeMessageId?: string +} +``` + +**Response:** +```ts +{ + sessionId: string // the new forked session + directory: string +} +``` + +**Status Codes:** +- `200`: Session forked +- `400`: Invalid request body +- `401`: Missing or invalid bearer token +- `404`: Session not found +- `502`: OpenCode error + +There is no delete route for sessions. Deleting sessions and workspaces stays out of this tool, as does changing permission modes and starting goals. + ## Skills -The assistant workspace includes four skills that document these capabilities: +The assistant workspace includes five skills that document these capabilities: 1. **Schedule Management** (`.opencode/skills/schedule-management/SKILL.md`) — manage schedule jobs and runs through the `ocm` `request` action. 2. **Notifications** (`.opencode/skills/notifications/SKILL.md`) — send push notifications through the `ocm` `send_notification` action. 3. **Manager Settings** (`.opencode/skills/manager-settings/SKILL.md`) — read and patch user preferences, read and update the OpenCode configuration file, and reload the assistant workspace through the `ocm` `request` action. 4. **Repo Management** (`.opencode/skills/repo-management/SKILL.md`) — list managed repositories through the `ocm` `request` action. +5. **Session Management** (`.opencode/skills/session-management/SKILL.md`) — list, create, follow up, read the reply of, and fork sessions through the `ocm` `request` action. These skills are automatically provisioned when assistant mode is initialized and contain detailed examples and usage patterns. diff --git a/docs/features/chat.md b/docs/features/chat.md index 919adc6b..81e03c3f 100644 --- a/docs/features/chat.md +++ b/docs/features/chat.md @@ -94,6 +94,43 @@ Toggle between two operational modes: Toggle modes using the mode selector in the chat header. +## Permission modes + +Control who answers OpenCode permission requests for a session. The shield button in the composer toggles between two modes: + +- **Ask every time** (default) - each permission request waits for you in the permission dialog. +- **Accept everything** - every "ask" request is answered automatically. + +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. + +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. + +Auto-accepted requests send no push notification, so you are not alerted for a request the session answered itself. + +## Session goals + +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: + +- **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. +- **continue** - the agent keeps working toward the objective. + +The auditor only sees the objective and the agent's latest reply; it cannot run tools or read files. Automatic continuations are capped by **Max automatic continuations**, and you can also set a **Token budget per goal** to stop a goal once it has spent that many tokens. A failed turn stops the goal, an interrupted turn pauses it, and deleting the session stops it. + +The goal is persisted and driven by the backend, so it survives closing the browser and a Manager restart: an active goal resumes auditing once the session is idle again. + +A status bar above the message list shows the goal state, the turn count, token usage, and the latest reason, with **Pause** (or **Resume**), **Cancel**, and **Dismiss** actions. + +Goal settings live in **Settings → General → Sessions**: + +- **Goal auditor model** - the model that decides whether the goal is done, as `provider/model`. Leave empty to use the OpenCode default model. +- **Max automatic continuations** - how many times a goal may continue before it stops (1-200, default 20). +- **Token budget per goal** - stop once the goal has spent this many tokens. Empty means no limit. + ## Mermaid Diagrams AI responses can include Mermaid diagrams that render automatically: diff --git a/docs/features/multi-run.md b/docs/features/multi-run.md new file mode 100644 index 00000000..e1cb3237 --- /dev/null +++ b/docs/features/multi-run.md @@ -0,0 +1,28 @@ +# Multi-run + +Run one prompt across several models at once to compare their results. + +## Launching a Multi-run + +Open a repository and click **Multi-run** in the header, next to **New Session**. In the **Launch** tab: + +1. Give the run group a **Group name**. +2. Enter the **Prompt** to send to every model. +3. Select up to **five models** from the checkbox list, grouped by provider. +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. + +## Isolation + +With **Isolate runs** on, each run is created in its own OpenCode workspace: a detached checkout of the repository at the chosen ref, with no branch created. These workspaces appear in the repository's **Workspaces** tab, and the session for an isolated run opens with that tab selected. With isolation off, every run shares the repository directory. + +## Runs + +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. + +Discarding is irreversible and cannot be repeated on an already discarded run. diff --git a/docs/features/notifications.md b/docs/features/notifications.md index 8e54acfc..2a0501d9 100644 --- a/docs/features/notifications.md +++ b/docs/features/notifications.md @@ -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 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. ## Supported Events @@ -21,6 +21,7 @@ A notification is suppressed when a visible tab is already viewing the session t | `questionAsked` | Agent asks a clarifying question | Enabled | | `sessionError` | Session encounters an error | Enabled | | `sessionIdle` | Session completes successfully | Disabled | +| `goalOutcome` | A session goal completes, is blocked, stops, or pauses | Enabled | ## Content and Click Behaviour @@ -121,3 +122,4 @@ Control which events trigger notifications: - **Question Asked** - Get notified when agent has a question (default: on) - **Session Error** - Get notified on session errors (default: on) - **Session Complete** - Get notified when session finishes (default: off) +- **Goal outcomes** - Get notified when a session goal completes, is blocked, stops, or pauses (default: on) diff --git a/docs/features/overview.md b/docs/features/overview.md index b62c3f66..dc6a7303 100644 --- a/docs/features/overview.md +++ b/docs/features/overview.md @@ -29,6 +29,9 @@ OpenCode Manager provides a comprehensive web interface for managing OpenCode AI - **Slash Commands** - Built-in (`/help`, `/new`, `/compact`) and custom commands - **File Mentions** - Reference files with `@filename` autocomplete - **Plan/Build Modes** - Toggle between read-only and file-change modes +- **Permission Modes** — Ask every time or Accept everything, per session, with a default for new sessions +- **Session Goals** — Keep a session working toward an objective until an auditor model says it is done or blocked +- **Multi-run** — Run one prompt across up to five models at once, optionally each in its own workspace - **Per-Agent Model Selection** — Each agent retains its own model selection independently - **Session Pinning** — Pin important sessions to a dedicated section at the top of the session list - **Mermaid Diagrams** - Visual diagram rendering in chat @@ -108,7 +111,8 @@ Both pickers live under **Settings → General**. ### Assistant Mode - **Dedicated AI Workspace** — Isolated assistant directory with managed configuration and a built-in bearer-token API -- **Auto-Provisioned Skills** — Schedule management, notifications, settings, and repo listing skills available out of the box +- **Auto-Provisioned Skills** — Schedule management, notifications, settings, repo listing, and session management skills available out of the box +- **Session Management** — List, create, follow up, read the reply of, and fork sessions through the `ocm` tool - **Session Continuity** — Navigating to the assistant always resumes the most recent session or creates one automatically [Learn more →](assistant-mode.md) diff --git a/mkdocs.yml b/mkdocs.yml index 5a4441b8..a311e6f6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -33,6 +33,7 @@ nav: - Chat & Sessions: features/chat.md - Session Pinning: features/session-pins.md - Schedules & Recurring Jobs: features/schedules.md + - Multi-run: features/multi-run.md - AI Configuration: features/ai-config.md - Skills: features/skills.md - MCP Servers: features/mcp.md