Files
opencode-manager/shared/src/schemas/session-goals.ts
T
Chris Scott 96e02e9646 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.
2026-10-03 21:16:05 -04:00

60 lines
2.0 KiB
TypeScript

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"]);
export type SessionGoalStatus = z.infer<typeof SessionGoalStatusSchema>;
export const SessionGoalStopReasonSchema = z.enum([
"cancelled",
"user_paused",
"continuation_limit",
"token_budget",
"turn_error",
"interrupted",
"audit_failed",
"session_deleted",
]);
export type SessionGoalStopReason = z.infer<typeof SessionGoalStopReasonSchema>;
export const SessionGoalVerdictSchema = z.enum(["continue", "done", "blocked"]);
export type SessionGoalVerdict = z.infer<typeof SessionGoalVerdictSchema>;
export const SessionGoalTurnStateSchema = z.enum(["waiting", "running"]);
export type SessionGoalTurnState = z.infer<typeof SessionGoalTurnStateSchema>;
export const SessionGoalSchema = z.object({
id: z.number().int(),
sessionId: z.string(),
directory: z.string(),
objective: z.string(),
status: SessionGoalStatusSchema,
stopReason: SessionGoalStopReasonSchema.nullable(),
turnState: SessionGoalTurnStateSchema,
continuationCount: z.number().int(),
maxContinuations: z.number().int(),
tokenBudget: z.number().int().nullable(),
tokensUsed: z.number().int(),
consecutiveBlocked: z.number().int(),
lastVerdict: SessionGoalVerdictSchema.nullable(),
lastReason: z.string().nullable(),
createdAt: z.number(),
updatedAt: z.number(),
finishedAt: z.number().nullable(),
});
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(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(),
});
export type StartSessionGoalRequest = z.infer<typeof StartSessionGoalRequestSchema>;