mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
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.
87 lines
3.0 KiB
TypeScript
87 lines
3.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
buildGoalAuditPrompt,
|
|
buildGoalContinuationPrompt,
|
|
GOAL_AUDIT_REASON_MAX_CHARS,
|
|
parseGoalVerdict,
|
|
} from '../../src/services/session-goal-audit'
|
|
import { SESSION_REPLY_MAX_LENGTH } from '../../src/services/session-reply'
|
|
|
|
describe('parseGoalVerdict', () => {
|
|
it('parses a plain JSON verdict', () => {
|
|
expect(parseGoalVerdict('{"verdict":"done","reason":"The feature shipped."}')).toEqual({
|
|
verdict: 'done',
|
|
reason: 'The feature shipped.',
|
|
})
|
|
})
|
|
|
|
it('parses a fenced JSON verdict with surrounding prose', () => {
|
|
const text = [
|
|
'Here is my decision:',
|
|
'```json',
|
|
'{"verdict":"blocked","reason":"Needs a database decision."}',
|
|
'```',
|
|
'Let me know.',
|
|
].join('\n')
|
|
|
|
expect(parseGoalVerdict(text)).toEqual({
|
|
verdict: 'blocked',
|
|
reason: 'Needs a database decision.',
|
|
})
|
|
})
|
|
|
|
it('returns null for invalid JSON', () => {
|
|
expect(parseGoalVerdict('not json at all')).toBeNull()
|
|
expect(parseGoalVerdict('{"verdict":')).toBeNull()
|
|
})
|
|
|
|
it('returns null for an unknown verdict', () => {
|
|
expect(parseGoalVerdict('{"verdict":"maybe","reason":"unsure"}')).toBeNull()
|
|
})
|
|
|
|
it('returns null for a missing or empty reason', () => {
|
|
expect(parseGoalVerdict('{"verdict":"done"}')).toBeNull()
|
|
expect(parseGoalVerdict('{"verdict":"done","reason":" "}')).toBeNull()
|
|
})
|
|
|
|
it('caps the reason length', () => {
|
|
const longReason = 'a'.repeat(GOAL_AUDIT_REASON_MAX_CHARS + 50)
|
|
const parsed = parseGoalVerdict(`{"verdict":"continue","reason":"${longReason}"}`)
|
|
|
|
expect(parsed?.verdict).toBe('continue')
|
|
expect(parsed?.reason).toHaveLength(GOAL_AUDIT_REASON_MAX_CHARS)
|
|
})
|
|
})
|
|
|
|
describe('buildGoalAuditPrompt', () => {
|
|
it('includes the objective and reply and asks for JSON only', () => {
|
|
const prompt = buildGoalAuditPrompt({ objective: 'Ship the feature', reply: 'I updated the route.' })
|
|
|
|
expect(prompt).toContain('Ship the feature')
|
|
expect(prompt).toContain('I updated the route.')
|
|
expect(prompt).toContain('{"verdict":"continue"|"done"|"blocked","reason":"<one sentence>"}')
|
|
})
|
|
|
|
it('marks a missing reply', () => {
|
|
expect(buildGoalAuditPrompt({ objective: 'Ship it', reply: null })).toContain('(no reply yet)')
|
|
})
|
|
|
|
it('truncates a long reply with a marker', () => {
|
|
const reply = 'x'.repeat(SESSION_REPLY_MAX_LENGTH + 100)
|
|
const prompt = buildGoalAuditPrompt({ objective: 'Ship it', reply })
|
|
|
|
expect(prompt).toContain('[reply truncated]')
|
|
expect(prompt).not.toContain('x'.repeat(SESSION_REPLY_MAX_LENGTH + 1))
|
|
})
|
|
})
|
|
|
|
describe('buildGoalContinuationPrompt', () => {
|
|
it('includes the objective and the progress reason', () => {
|
|
const prompt = buildGoalContinuationPrompt({ objective: 'Ship the feature', reason: 'Tests still fail.' })
|
|
|
|
expect(prompt).toContain('Ship the feature')
|
|
expect(prompt).toContain('Tests still fail.')
|
|
expect(prompt).toContain('state exactly what you need')
|
|
})
|
|
})
|