mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
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:
1 parent
2af2577af8
commit
96e02e9646
91 files changed
+2140
-688
No files matched your search
@@ -11,7 +11,7 @@ const baseState: SessionPermissionModeState = {
|
||||
sessionId: 'ses_1',
|
||||
rootSessionId: 'ses_1',
|
||||
mode: 'ask',
|
||||
inherited: false,
|
||||
lockedReason: null,
|
||||
}
|
||||
|
||||
function mockHooks(overrides: {
|
||||
@@ -66,14 +66,22 @@ describe('PermissionModeToggle', () => {
|
||||
expect(mutate).toHaveBeenCalledWith({ directory: '/repo', mode: 'ask' })
|
||||
})
|
||||
|
||||
it('is disabled and labelled as inherited for child sessions', () => {
|
||||
mockHooks({ state: { inherited: true, mode: 'auto' } })
|
||||
it('is disabled and labelled as locked for child sessions', () => {
|
||||
mockHooks({ state: { lockedReason: 'child', mode: 'auto' } })
|
||||
render(<PermissionModeToggle sessionID="ses_child" directory="/repo" />)
|
||||
|
||||
const button = screen.getByRole('button', { name: 'Inherited from parent session' })
|
||||
expect(button).toBeDisabled()
|
||||
})
|
||||
|
||||
it('is disabled and labelled for schedule-run sessions', () => {
|
||||
mockHooks({ state: { lockedReason: 'schedule', mode: 'ask' } })
|
||||
render(<PermissionModeToggle sessionID="ses_sched" directory="/repo" />)
|
||||
|
||||
const button = screen.getByRole('button', { name: "Scheduled runs use the schedule's permission configuration" })
|
||||
expect(button).toBeDisabled()
|
||||
})
|
||||
|
||||
it('cannot mutate while the mode read is still loading', async () => {
|
||||
const user = userEvent.setup()
|
||||
const mutate = vi.fn()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Shield, ShieldCheck } from 'lucide-react'
|
||||
import { useSessionPermissionMode, useSetSessionPermissionMode } from '@/hooks/useSessionPermissionMode'
|
||||
import { IconToggleButton } from '@/components/ui/icon-toggle-button'
|
||||
|
||||
interface PermissionModeToggleProps {
|
||||
sessionID: string
|
||||
@@ -12,18 +13,20 @@ export function PermissionModeToggle({ sessionID, directory }: PermissionModeTog
|
||||
|
||||
const loaded = data !== undefined
|
||||
const isAuto = data?.mode === 'auto'
|
||||
const inherited = data?.inherited ?? false
|
||||
const disabled = !loaded || inherited || setMode.isPending
|
||||
const lockedReason = data?.lockedReason ?? null
|
||||
const disabled = !loaded || lockedReason !== null || setMode.isPending
|
||||
|
||||
const label = !loaded
|
||||
? isError
|
||||
? 'Permissions: unavailable'
|
||||
: 'Permissions: loading'
|
||||
: inherited
|
||||
: lockedReason === 'child'
|
||||
? 'Inherited from parent session'
|
||||
: isAuto
|
||||
? 'Permissions: accept everything'
|
||||
: 'Permissions: ask every time'
|
||||
: lockedReason === 'schedule'
|
||||
? "Scheduled runs use the schedule's permission configuration"
|
||||
: isAuto
|
||||
? 'Permissions: accept everything'
|
||||
: 'Permissions: ask every time'
|
||||
|
||||
const handleClick = () => {
|
||||
if (disabled) return
|
||||
@@ -31,19 +34,8 @@ export function PermissionModeToggle({ sessionID, directory }: PermissionModeTog
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
disabled={disabled}
|
||||
title={label}
|
||||
aria-label={label}
|
||||
className={`p-2 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border disabled:opacity-50 disabled:cursor-not-allowed disabled:active:scale-100 disabled:hover:scale-100 ${
|
||||
isAuto
|
||||
? 'bg-highlight hover:bg-highlight/90 text-highlight-foreground border-highlight'
|
||||
: 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border'
|
||||
}`}
|
||||
>
|
||||
<IconToggleButton active={isAuto} label={label} disabled={disabled} onClick={handleClick}>
|
||||
{isAuto ? <ShieldCheck className="w-5 h-5" /> : <Shield className="w-5 h-5" />}
|
||||
</button>
|
||||
</IconToggleButton>
|
||||
)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ describe('SessionGoalBar', () => {
|
||||
render(<SessionGoalBar sessionID="ses_1" />)
|
||||
|
||||
expect(screen.getByText('Goal completed')).toBeInTheDocument()
|
||||
expect(screen.getByText('continuation limit reached')).toBeInTheDocument()
|
||||
expect(screen.getByText('Continuation limit reached')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Pause' })).not.toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Dismiss' }))
|
||||
@@ -115,6 +115,22 @@ describe('SessionGoalBar', () => {
|
||||
expect(screen.queryByText('Goal completed')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the shared stop-reason wording for a user-paused goal', () => {
|
||||
mockGoals({ ...baseGoal, status: 'stopped', stopReason: 'user_paused' })
|
||||
render(<SessionGoalBar sessionID="ses_1" />)
|
||||
|
||||
expect(screen.getByText('Goal stopped')).toBeInTheDocument()
|
||||
expect(screen.getByText('Paused by user')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the shared stop-reason wording for an audit failure', () => {
|
||||
mockGoals({ ...baseGoal, status: 'blocked', stopReason: 'audit_failed' })
|
||||
render(<SessionGoalBar sessionID="ses_1" />)
|
||||
|
||||
expect(screen.getByText('Goal blocked')).toBeInTheDocument()
|
||||
expect(screen.getByText('Audit failed')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('cancels the goal through the cancel API', async () => {
|
||||
const user = userEvent.setup()
|
||||
const cancel = vi.fn()
|
||||
|
||||
@@ -1,32 +1,15 @@
|
||||
import { useState } from 'react'
|
||||
import { ChevronDown, ChevronUp, Target } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import {
|
||||
useCancelSessionGoal,
|
||||
usePauseSessionGoal,
|
||||
useResumeSessionGoal,
|
||||
useSessionGoal,
|
||||
} from '@/hooks/useSessionGoals'
|
||||
import type { SessionGoalStatus, SessionGoalStopReason } from '@opencode-manager/shared/schemas'
|
||||
|
||||
const STATUS_LABELS: Record<SessionGoalStatus, string> = {
|
||||
active: 'Goal active',
|
||||
paused: 'Goal paused',
|
||||
completed: 'Goal completed',
|
||||
blocked: 'Goal blocked',
|
||||
stopped: 'Goal stopped',
|
||||
}
|
||||
|
||||
const STOP_REASON_LABELS: Record<SessionGoalStopReason, string> = {
|
||||
cancelled: 'cancelled',
|
||||
user_paused: 'paused by you',
|
||||
continuation_limit: 'continuation limit reached',
|
||||
token_budget: 'token budget reached',
|
||||
turn_error: 'turn failed',
|
||||
interrupted: 'interrupted',
|
||||
audit_failed: 'auditor failed',
|
||||
session_deleted: 'session deleted',
|
||||
}
|
||||
import { getGoalOutcomeTitle, getGoalStopReasonLabel } from '@opencode-manager/shared/notifications'
|
||||
import type { SessionGoalStatus } from '@opencode-manager/shared/schemas'
|
||||
|
||||
const STATUS_CHIP_CLASSES: Record<SessionGoalStatus, string> = {
|
||||
active: 'bg-highlight text-highlight-foreground border-highlight',
|
||||
@@ -54,17 +37,18 @@ export function SessionGoalBar({ sessionID }: { sessionID: string }) {
|
||||
if (isTerminal(goal.status) && dismissedGoalId === goal.id) return null
|
||||
|
||||
const terminal = isTerminal(goal.status)
|
||||
const reason = goal.stopReason ? STOP_REASON_LABELS[goal.stopReason] : goal.lastReason
|
||||
const reason = goal.stopReason ? getGoalStopReasonLabel(goal.stopReason) : goal.lastReason
|
||||
|
||||
return (
|
||||
<div className="mb-1 flex flex-col gap-1 rounded-lg border border-border bg-card/70 px-2 py-1.5 text-xs">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-medium ${STATUS_CHIP_CLASSES[goal.status]}`}
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={`gap-1 px-2 py-0.5 font-medium ${STATUS_CHIP_CLASSES[goal.status]}`}
|
||||
>
|
||||
<Target className="h-3 w-3" />
|
||||
{STATUS_LABELS[goal.status]}
|
||||
</span>
|
||||
{getGoalOutcomeTitle(goal.status)}
|
||||
</Badge>
|
||||
|
||||
{!terminal && (
|
||||
<span className="text-muted-foreground">
|
||||
|
||||
Reference in new issue
Block a user