mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
section 8: Phase 8: Goal mode in the composer, goal status bar and goal
This commit is contained in:
1 parent
4e9f27ab0b
commit
8cd00e1a8a
19 files changed
+877
-11
No files matched your search
@@ -170,4 +170,18 @@ describe('NotificationSettings', () => {
|
||||
render(<NotificationSettings />)
|
||||
expect(screen.getByText(/not supported in this browser/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('writes the goal outcome preference and defaults it on', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updateEventPreference = vi.fn()
|
||||
mockNotifications({ updateEventPreference })
|
||||
render(<NotificationSettings />)
|
||||
|
||||
const toggle = screen.getByRole('switch', { name: 'Goal outcomes' })
|
||||
expect(toggle).toBeChecked()
|
||||
|
||||
await user.click(toggle)
|
||||
|
||||
expect(updateEventPreference).toHaveBeenCalledWith('goalOutcome', false)
|
||||
})
|
||||
})
|
||||
@@ -213,6 +213,24 @@ export function NotificationSettings() {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start justify-between gap-4 py-3">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="notifGoalOutcome" className="text-base">
|
||||
Goal outcomes
|
||||
</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
When a session goal completes, blocks or stops
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="notifGoalOutcome"
|
||||
checked={preferences.events.goalOutcome ?? true}
|
||||
onCheckedChange={(checked) =>
|
||||
updateEventPreference("goalOutcome", checked)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { SessionAutomationSettings } from './SessionAutomationSettings'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
@@ -57,4 +57,59 @@ describe('SessionAutomationSettings', () => {
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({ sessionDefaults: { permissionMode: 'auto' } })
|
||||
})
|
||||
|
||||
it('persists the goal auditor model', () => {
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({
|
||||
preferences: { ...basePreferences, sessionDefaults: { permissionMode: 'ask', goalMaxContinuations: 20 } },
|
||||
updateSettings,
|
||||
})
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Goal auditor model'), {
|
||||
target: { value: 'anthropic/claude-sonnet-4' },
|
||||
})
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({
|
||||
sessionDefaults: {
|
||||
permissionMode: 'ask',
|
||||
goalMaxContinuations: 20,
|
||||
goalAuditorModel: 'anthropic/claude-sonnet-4',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('persists the max automatic continuations', () => {
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({
|
||||
preferences: { ...basePreferences, sessionDefaults: { permissionMode: 'ask', goalMaxContinuations: 20 } },
|
||||
updateSettings,
|
||||
})
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Max automatic continuations'), {
|
||||
target: { value: '50' },
|
||||
})
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({
|
||||
sessionDefaults: { permissionMode: 'ask', goalMaxContinuations: 50 },
|
||||
})
|
||||
})
|
||||
|
||||
it('persists the token budget per goal', () => {
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({
|
||||
preferences: { ...basePreferences, sessionDefaults: { permissionMode: 'ask', goalMaxContinuations: 20 } },
|
||||
updateSettings,
|
||||
})
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
fireEvent.change(screen.getByLabelText('Token budget per goal'), {
|
||||
target: { value: '5000' },
|
||||
})
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({
|
||||
sessionDefaults: { permissionMode: 'ask', goalMaxContinuations: 20, goalTokenBudget: 5000 },
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,11 +1,26 @@
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import type { SessionPermissionMode } from '@opencode-manager/shared/schemas'
|
||||
import type { SessionDefaults, SessionPermissionMode } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export function SessionAutomationSettings() {
|
||||
const { preferences, updateSettings } = useSettings()
|
||||
const permissionMode = preferences?.sessionDefaults?.permissionMode ?? 'ask'
|
||||
const sessionDefaults = preferences?.sessionDefaults
|
||||
const permissionMode = sessionDefaults?.permissionMode ?? 'ask'
|
||||
const goalMaxContinuations = sessionDefaults?.goalMaxContinuations ?? 20
|
||||
const goalTokenBudget = sessionDefaults?.goalTokenBudget
|
||||
const goalAuditorModel = sessionDefaults?.goalAuditorModel ?? ''
|
||||
|
||||
const updateSessionDefaults = (patch: Partial<SessionDefaults>) => {
|
||||
updateSettings({
|
||||
sessionDefaults: {
|
||||
...sessionDefaults,
|
||||
permissionMode,
|
||||
...patch,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -20,12 +35,7 @@ export function SessionAutomationSettings() {
|
||||
</div>
|
||||
<Select
|
||||
value={permissionMode}
|
||||
onValueChange={(value) => updateSettings({
|
||||
sessionDefaults: {
|
||||
...preferences?.sessionDefaults,
|
||||
permissionMode: value as SessionPermissionMode,
|
||||
},
|
||||
})}
|
||||
onValueChange={(value) => updateSessionDefaults({ permissionMode: value as SessionPermissionMode })}
|
||||
>
|
||||
<SelectTrigger id="sessionPermissionMode" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a mode" />
|
||||
@@ -36,6 +46,73 @@ export function SessionAutomationSettings() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="goalAuditorModel">Goal auditor model</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Model that decides whether a session goal is done, as provider/model. Leave empty to use the OpenCode default model.
|
||||
</p>
|
||||
</div>
|
||||
<Input
|
||||
id="goalAuditorModel"
|
||||
value={goalAuditorModel}
|
||||
placeholder="provider/model"
|
||||
className="w-full shrink-0 sm:w-64"
|
||||
onChange={(event) => updateSessionDefaults({ goalAuditorModel: event.target.value.trim() || undefined })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="goalMaxContinuations">Max automatic continuations</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
How many times a goal may keep the agent working after each audit before it stops.
|
||||
</p>
|
||||
</div>
|
||||
<Input
|
||||
id="goalMaxContinuations"
|
||||
type="number"
|
||||
min={1}
|
||||
max={200}
|
||||
value={goalMaxContinuations}
|
||||
className="w-full shrink-0 sm:w-40"
|
||||
onChange={(event) => {
|
||||
const value = Number(event.target.value)
|
||||
if (Number.isInteger(value) && value >= 1 && value <= 200) {
|
||||
updateSessionDefaults({ goalMaxContinuations: value })
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="goalTokenBudget">Token budget per goal</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Stop a goal once it has spent this many tokens. Leave empty for no limit.
|
||||
</p>
|
||||
</div>
|
||||
<Input
|
||||
id="goalTokenBudget"
|
||||
type="number"
|
||||
min={1}
|
||||
value={goalTokenBudget ?? ''}
|
||||
placeholder="No limit"
|
||||
className="w-full shrink-0 sm:w-40"
|
||||
onChange={(event) => {
|
||||
const raw = event.target.value
|
||||
if (raw === '') {
|
||||
updateSessionDefaults({ goalTokenBudget: undefined })
|
||||
return
|
||||
}
|
||||
const value = Number(raw)
|
||||
if (Number.isInteger(value) && value > 0) {
|
||||
updateSessionDefaults({ goalTokenBudget: value })
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user