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

+42 -1
View File
@@ -1,5 +1,6 @@
import type { Context } from 'hono'
import type { ContentfulStatusCode } from 'hono/utils/http-status'
import type { ZodType } from 'zod'
import { ClientError, openCodeErrorStatus } from '@opencode-manager/shared/opencode'
import { isOAuthErrorCode } from '@opencode-manager/shared/schemas'
import { getErrorMessage } from './error-utils'
@@ -43,7 +44,12 @@ export function handleServiceError(
return c.json({ error: getErrorMessage(error) }, 500)
}
export function handleOpenCodeError(c: Context, error: unknown, fallback: string) {
export function handleOpenCodeError(
c: Context,
error: unknown,
fallback: string,
options?: { unknownStatus?: 500 | 502 },
) {
if (error instanceof Error) {
const tag = (error as { _tag?: unknown })._tag
if (typeof tag === 'string') {
@@ -59,5 +65,40 @@ export function handleOpenCodeError(c: Context, error: unknown, fallback: string
}
logger.error(fallback, error)
const status = options?.unknownStatus ?? 500
if (status === 502) {
return c.json({ error: getErrorMessage(error) || fallback }, 502)
}
return c.json({ error: fallback }, 500)
}
export type JsonBodyResult<T> = { ok: true; data: T } | { ok: false; response: Response }
export async function parseJsonBody<T>(
c: Context,
schema: ZodType<T>,
options?: { allowEmpty?: boolean },
): Promise<JsonBodyResult<T>> {
const text = await c.req.text()
let value: unknown
if (!text.trim()) {
if (!options?.allowEmpty) {
return { ok: false, response: c.json({ error: 'Invalid JSON' }, 400) }
}
value = {}
} else {
try {
value = JSON.parse(text)
} catch {
return { ok: false, response: c.json({ error: 'Invalid JSON' }, 400) }
}
}
const parsed = schema.safeParse(value)
if (!parsed.success) {
return { ok: false, response: c.json({ error: 'Invalid request body', details: parsed.error.issues }, 400) }
}
return { ok: true, data: parsed.data }
}