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

+29
View File
@@ -1,3 +1,32 @@
import type { SessionGoalStatus, SessionGoalStopReason } from '../schemas/session-goals'
const GOAL_OUTCOME_TITLES: Record<SessionGoalStatus, string> = {
active: 'Goal active',
paused: 'Goal paused',
completed: 'Goal completed',
blocked: 'Goal blocked',
stopped: 'Goal stopped',
}
const GOAL_STOP_REASON_LABELS: Record<SessionGoalStopReason, string> = {
cancelled: 'Cancelled',
user_paused: 'Paused by user',
continuation_limit: 'Continuation limit reached',
token_budget: 'Token budget reached',
turn_error: 'Turn failed',
interrupted: 'Interrupted',
audit_failed: 'Audit failed',
session_deleted: 'Session deleted',
}
export function getGoalOutcomeTitle(status: SessionGoalStatus): string {
return GOAL_OUTCOME_TITLES[status]
}
export function getGoalStopReasonLabel(stopReason: SessionGoalStopReason): string {
return GOAL_STOP_REASON_LABELS[stopReason]
}
const PERMISSION_LABELS: Record<string, string> = {
read: 'Read File',
edit: 'Edit File',
+1
View File
@@ -1,3 +1,4 @@
export * from './limits'
export * from './settings'
export * from './repo'
export * from './files'
+3 -8
View File
@@ -1,9 +1,10 @@
import { z } from "zod";
import { SESSION_PROMPT_MAX_LENGTH } from "./limits";
export const InternalCreateSessionRequestSchema = z
.object({
repoId: z.number().int(),
prompt: z.string().trim().min(1).max(20000),
prompt: z.string().trim().min(1).max(SESSION_PROMPT_MAX_LENGTH),
title: z.string().max(200).optional(),
model: z.string().optional(),
agent: z.string().optional(),
@@ -12,20 +13,14 @@ export const InternalCreateSessionRequestSchema = z
})
.strict();
export type InternalCreateSessionRequest = z.infer<typeof InternalCreateSessionRequestSchema>;
export const InternalSessionPromptRequestSchema = z
.object({
text: z.string().trim().min(1).max(20000),
text: z.string().trim().min(1).max(SESSION_PROMPT_MAX_LENGTH),
})
.strict();
export type InternalSessionPromptRequest = z.infer<typeof InternalSessionPromptRequestSchema>;
export const InternalForkSessionRequestSchema = z
.object({
beforeMessageId: z.string().optional(),
})
.strict();
export type InternalForkSessionRequest = z.infer<typeof InternalForkSessionRequestSchema>;
+3
View File
@@ -0,0 +1,3 @@
export const SESSION_PROMPT_MAX_LENGTH = 20000;
export const GOAL_MAX_CONTINUATIONS_MIN = 1;
export const GOAL_MAX_CONTINUATIONS_MAX = 200;
+2 -1
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { SESSION_PROMPT_MAX_LENGTH } from "./limits";
export const MULTI_RUN_MAX_MODELS = 5;
@@ -36,7 +37,7 @@ export type MultiRun = z.infer<typeof MultiRunSchema>;
export const LaunchMultiRunRequestSchema = z.object({
repoId: z.number().int(),
name: z.string().trim().min(1).max(80),
prompt: z.string().trim().min(1).max(20000),
prompt: z.string().trim().min(1).max(SESSION_PROMPT_MAX_LENGTH),
models: z
.array(z.string().min(3))
.min(1)
+3 -2
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { SESSION_PROMPT_MAX_LENGTH, GOAL_MAX_CONTINUATIONS_MIN, GOAL_MAX_CONTINUATIONS_MAX } from "./limits";
export const SessionGoalStatusSchema = z.enum(["active", "paused", "completed", "blocked", "stopped"]);
@@ -50,8 +51,8 @@ export type SessionGoal = z.infer<typeof SessionGoalSchema>;
export const StartSessionGoalRequestSchema = z.object({
sessionId: z.string().min(1),
directory: z.string().min(1),
objective: z.string().trim().min(1).max(20000),
maxContinuations: z.number().int().min(1).max(200).optional(),
objective: z.string().trim().min(1).max(SESSION_PROMPT_MAX_LENGTH),
maxContinuations: z.number().int().min(GOAL_MAX_CONTINUATIONS_MIN).max(GOAL_MAX_CONTINUATIONS_MAX).optional(),
tokenBudget: z.number().int().positive().optional(),
});
+5 -1
View File
@@ -4,6 +4,10 @@ export const SessionPermissionModeSchema = z.enum(["ask", "auto"]);
export type SessionPermissionMode = z.infer<typeof SessionPermissionModeSchema>;
export const SessionLockReasonSchema = z.enum(["schedule", "child"]);
export type SessionLockReason = z.infer<typeof SessionLockReasonSchema>;
export const SetSessionPermissionModeRequestSchema = z.object({
directory: z.string().min(1),
mode: SessionPermissionModeSchema,
@@ -15,7 +19,7 @@ export const SessionPermissionModeStateSchema = z.object({
sessionId: z.string(),
rootSessionId: z.string(),
mode: SessionPermissionModeSchema,
inherited: z.boolean(),
lockedReason: SessionLockReasonSchema.nullable(),
});
export type SessionPermissionModeState = z.infer<typeof SessionPermissionModeStateSchema>;
+2 -1
View File
@@ -3,6 +3,7 @@ import { NotificationPreferencesSchema, DEFAULT_NOTIFICATION_PREFERENCES } from
import { OPENCODE_CONFIG_SOURCE_NAMES } from "../config/defaults";
import { ColorThemeIdSchema, MANAGER_COLOR_THEME_ID } from "../themes";
import { SessionPermissionModeSchema } from "./session-permissions";
import { GOAL_MAX_CONTINUATIONS_MIN, GOAL_MAX_CONTINUATIONS_MAX } from "./limits";
export const CustomCommandSchema = z.object({
name: z.string(),
@@ -145,7 +146,7 @@ export const DEFAULT_SANDBOX_PREFERENCES: SandboxPreferences = {
export const SessionDefaultsSchema = z.object({
permissionMode: SessionPermissionModeSchema,
goalMaxContinuations: z.number().int().min(1).max(200).optional(),
goalMaxContinuations: z.number().int().min(GOAL_MAX_CONTINUATIONS_MIN).max(GOAL_MAX_CONTINUATIONS_MAX).optional(),
goalTokenBudget: z.number().int().positive().optional(),
goalAuditorModel: z.string().optional(),
});
+19 -2
View File
@@ -3,17 +3,34 @@ export const ASSISTANT_REPO_NAME = 'Assistant'
export const ASSISTANT_REPO_PATH = 'assistant'
export const ASSISTANT_OPENCODE_DIR_NAME = '.opencode'
export function buildSessionPath(
repoId: number | string,
sessionId: string,
options?: { repoTab?: string },
): string {
const params = new URLSearchParams()
if (String(repoId) === String(ASSISTANT_REPO_ID)) {
params.set('assistant', '1')
}
if (options?.repoTab) {
params.set('repoTab', options.repoTab)
}
const search = params.toString()
return `/repos/${repoId}/sessions/${sessionId}${search ? `?${search}` : ''}`
}
function trimTrailingChar(value: string, char: string): string {
let end = value.length
while (end > 0 && value[end - 1] === char) end--
return value.slice(0, end)
}
export function sanitizeRepoDirectoryName(input: string): string {
export function sanitizeRepoDirectoryName(input: string, fallback = 'repo'): string {
const collapsed = input.trim().replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+/, '')
const sanitized = trimTrailingChar(collapsed, '-')
return sanitized || 'repo'
return sanitized || fallback
}
export function getRepoDirectoryNameError(input: string): string | null {