mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 13: Phase 13: Multi-run launcher and run groups in the repo page
This commit is contained in:
1 parent
891f5427b4
commit
444a43aa1d
6 files changed
+674
-4
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { LaunchMultiRunRequest, MultiRun } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export async function listMultiRuns(repoId: number): Promise<MultiRun[]> {
|
||||
const res = await fetchWrapper<{ runs: MultiRun[] }>(`${API_BASE_URL}/api/multi-runs`, {
|
||||
params: { repoId },
|
||||
})
|
||||
return res.runs
|
||||
}
|
||||
|
||||
export async function launchMultiRun(request: LaunchMultiRunRequest): Promise<MultiRun> {
|
||||
const res = await fetchWrapper<{ run: MultiRun }>(`${API_BASE_URL}/api/multi-runs`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
return res.run
|
||||
}
|
||||
|
||||
export async function discardMultiRunEntry(runId: number, entryId: number): Promise<MultiRun> {
|
||||
const res = await fetchWrapper<{ run: MultiRun }>(
|
||||
`${API_BASE_URL}/api/multi-runs/${encodeURIComponent(runId)}/entries/${encodeURIComponent(entryId)}/discard`,
|
||||
{ method: 'POST' },
|
||||
)
|
||||
return res.run
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import type { ReactNode } from 'react'
|
||||
import { MultiRunDialog } from './MultiRunDialog'
|
||||
import type { MultiRun } from '@opencode-manager/shared/schemas'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
listMultiRuns: vi.fn(),
|
||||
launchMultiRun: vi.fn(),
|
||||
discardMultiRunEntry: vi.fn(),
|
||||
useProvidersWithModels: vi.fn(),
|
||||
}))
|
||||
|
||||
const mockNavigate = vi.fn()
|
||||
|
||||
vi.mock('react-router-dom', async (importOriginal) => ({
|
||||
...(await importOriginal('react-router-dom')),
|
||||
useNavigate: () => mockNavigate,
|
||||
}))
|
||||
|
||||
vi.mock('@/api/multiRuns', () => ({
|
||||
listMultiRuns: mocks.listMultiRuns,
|
||||
launchMultiRun: mocks.launchMultiRun,
|
||||
discardMultiRunEntry: mocks.discardMultiRunEntry,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useProvidersWithModels', () => ({
|
||||
useProvidersWithModels: mocks.useProvidersWithModels,
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/toast', () => ({
|
||||
showToast: {
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
info: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
const providers = [
|
||||
{
|
||||
id: 'openai',
|
||||
name: 'OpenAI',
|
||||
source: 'configured',
|
||||
isConnected: true,
|
||||
models: [
|
||||
{ id: 'gpt-4o', name: 'GPT-4o' },
|
||||
{ id: 'gpt-4o-mini', name: 'GPT-4o mini' },
|
||||
{ id: 'gpt-4.1', name: 'GPT-4.1' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'anthropic',
|
||||
name: 'Anthropic',
|
||||
source: 'configured',
|
||||
isConnected: true,
|
||||
models: [
|
||||
{ id: 'claude-opus', name: 'Claude Opus' },
|
||||
{ id: 'claude-sonnet', name: 'Claude Sonnet' },
|
||||
{ id: 'claude-haiku', name: 'Claude Haiku' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const startedRun: MultiRun = {
|
||||
id: 3,
|
||||
repoId: 7,
|
||||
name: 'Sweep',
|
||||
prompt: 'go',
|
||||
isolated: true,
|
||||
baseRef: 'main',
|
||||
createdAt: 1,
|
||||
entries: [
|
||||
{
|
||||
id: 11,
|
||||
model: 'openai/gpt-4o',
|
||||
status: 'started',
|
||||
sessionId: 'ses_1',
|
||||
directory: '/workspaces/sweep-1',
|
||||
isolated: true,
|
||||
error: null,
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
model: 'anthropic/claude-opus',
|
||||
status: 'failed',
|
||||
sessionId: null,
|
||||
directory: null,
|
||||
isolated: true,
|
||||
error: 'launch failed',
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
function createWrapper() {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
return ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function renderDialog(overrides: Partial<React.ComponentProps<typeof MultiRunDialog>> = {}) {
|
||||
return render(
|
||||
<MultiRunDialog
|
||||
repoId={7}
|
||||
directory="/repo"
|
||||
defaultBaseRef="main"
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
{...overrides}
|
||||
/>,
|
||||
{ wrapper: createWrapper() },
|
||||
)
|
||||
}
|
||||
|
||||
describe('MultiRunDialog', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.useProvidersWithModels.mockReturnValue({ data: providers, isLoading: false })
|
||||
mocks.listMultiRuns.mockResolvedValue([])
|
||||
})
|
||||
|
||||
it('caps model selection at five', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderDialog()
|
||||
|
||||
const names = ['GPT-4o', 'GPT-4o mini', 'GPT-4.1', 'Claude Opus', 'Claude Sonnet']
|
||||
for (const name of names) {
|
||||
await user.click(screen.getByRole('checkbox', { name }))
|
||||
}
|
||||
|
||||
expect(screen.getByText('5/5 selected')).toBeInTheDocument()
|
||||
expect(screen.getByRole('checkbox', { name: 'Claude Haiku' })).toBeDisabled()
|
||||
|
||||
await user.click(screen.getByRole('checkbox', { name: 'Claude Haiku' }))
|
||||
expect(screen.getByText('5/5 selected')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('submits the launch request', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.launchMultiRun.mockResolvedValue(startedRun)
|
||||
renderDialog()
|
||||
|
||||
await user.type(screen.getByLabelText('Group name'), 'Sweep')
|
||||
await user.type(screen.getByLabelText('Prompt'), 'go')
|
||||
await user.click(screen.getByRole('checkbox', { name: 'GPT-4o' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Launch' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.launchMultiRun).toHaveBeenCalledWith({
|
||||
repoId: 7,
|
||||
name: 'Sweep',
|
||||
prompt: 'go',
|
||||
models: ['openai/gpt-4o'],
|
||||
isolate: true,
|
||||
baseRef: 'main',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('lists run entries with Open and Discard actions', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.listMultiRuns.mockResolvedValue([startedRun])
|
||||
renderDialog()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'Runs' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('openai/gpt-4o')).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.getByText('launch failed')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /open/i })).toBeInTheDocument()
|
||||
expect(screen.getAllByRole('button', { name: /discard/i })).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('opens a started run in the workspaces tab', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.listMultiRuns.mockResolvedValue([startedRun])
|
||||
renderDialog()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'Runs' }))
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button', { name: /open/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /open/i }))
|
||||
|
||||
expect(mockNavigate).toHaveBeenCalledWith('/repos/7/sessions/ses_1?repoTab=workspaces')
|
||||
})
|
||||
|
||||
it('discards an entry after confirmation', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.listMultiRuns.mockResolvedValue([startedRun])
|
||||
mocks.discardMultiRunEntry.mockResolvedValue(startedRun)
|
||||
renderDialog()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'Runs' }))
|
||||
await waitFor(() => {
|
||||
expect(screen.getAllByRole('button', { name: /discard/i })).toHaveLength(2)
|
||||
})
|
||||
|
||||
await user.click(screen.getAllByRole('button', { name: /discard/i })[0])
|
||||
|
||||
const confirmDialog = await screen.findByRole('dialog', { name: 'Discard run' })
|
||||
await user.click(within(confirmDialog).getByRole('button', { name: 'Discard' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.discardMultiRunEntry).toHaveBeenCalledWith(3, 11)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,336 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Loader2, Trash2, ArrowUpRight } from 'lucide-react'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { ConfirmDestructiveDialog } from '@/components/ui/confirm-destructive-dialog'
|
||||
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
|
||||
import { useProvidersWithModels } from '@/hooks/useProvidersWithModels'
|
||||
import { useDiscardMultiRunEntry, useLaunchMultiRun, useMultiRuns } from '@/hooks/useMultiRuns'
|
||||
import {
|
||||
MULTI_RUN_MAX_MODELS,
|
||||
type LaunchMultiRunRequest,
|
||||
type MultiRunEntry,
|
||||
type MultiRunEntryStatus,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
|
||||
interface MultiRunDialogProps {
|
||||
repoId: number
|
||||
directory?: string
|
||||
defaultBaseRef?: string
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
interface PendingDiscard {
|
||||
runId: number
|
||||
entryId: number
|
||||
model: string
|
||||
isolated: boolean
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<MultiRunEntryStatus, string> = {
|
||||
starting: 'Starting',
|
||||
started: 'Started',
|
||||
failed: 'Failed',
|
||||
discarded: 'Discarded',
|
||||
}
|
||||
|
||||
export function MultiRunDialog({
|
||||
repoId,
|
||||
directory,
|
||||
defaultBaseRef,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: MultiRunDialogProps) {
|
||||
const navigate = useNavigate()
|
||||
const [activeTab, setActiveTab] = useState('launch')
|
||||
const [name, setName] = useState('')
|
||||
const [prompt, setPrompt] = useState('')
|
||||
const [selectedModels, setSelectedModels] = useState<string[]>([])
|
||||
const [isolate, setIsolate] = useState(true)
|
||||
const [baseRef, setBaseRef] = useState('')
|
||||
const [pendingDiscard, setPendingDiscard] = useState<PendingDiscard | null>(null)
|
||||
|
||||
const { data: providers } = useProvidersWithModels({ enabled: open, directory })
|
||||
const runsQuery = useMultiRuns(repoId, open)
|
||||
const launch = useLaunchMultiRun(repoId)
|
||||
const discard = useDiscardMultiRunEntry(repoId)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
setActiveTab('launch')
|
||||
setName('')
|
||||
setPrompt('')
|
||||
setSelectedModels([])
|
||||
setIsolate(true)
|
||||
setBaseRef(defaultBaseRef ?? '')
|
||||
}, [open, defaultBaseRef])
|
||||
|
||||
const modelGroups = useMemo(
|
||||
() => providers.filter((provider) => provider.models.length > 0),
|
||||
[providers],
|
||||
)
|
||||
|
||||
const toggleModel = (value: string, checked: boolean) => {
|
||||
setSelectedModels((current) => {
|
||||
if (checked) {
|
||||
if (current.includes(value) || current.length >= MULTI_RUN_MAX_MODELS) return current
|
||||
return [...current, value]
|
||||
}
|
||||
return current.filter((model) => model !== value)
|
||||
})
|
||||
}
|
||||
|
||||
const canSubmit =
|
||||
name.trim().length > 0 && prompt.trim().length > 0 && selectedModels.length > 0 && !launch.isPending
|
||||
|
||||
const handleLaunch = async () => {
|
||||
const request: LaunchMultiRunRequest = {
|
||||
repoId,
|
||||
name: name.trim(),
|
||||
prompt: prompt.trim(),
|
||||
models: selectedModels,
|
||||
isolate,
|
||||
...(baseRef.trim() ? { baseRef: baseRef.trim() } : {}),
|
||||
}
|
||||
await launch.mutateAsync(request)
|
||||
setActiveTab('runs')
|
||||
}
|
||||
|
||||
const openEntry = (entry: MultiRunEntry) => {
|
||||
if (!entry.sessionId) return
|
||||
onOpenChange(false)
|
||||
const suffix = entry.isolated ? '?repoTab=workspaces' : ''
|
||||
navigate(`/repos/${repoId}/sessions/${entry.sessionId}${suffix}`)
|
||||
}
|
||||
|
||||
const confirmDiscard = () => {
|
||||
if (!pendingDiscard) return
|
||||
discard.mutate(
|
||||
{ runId: pendingDiscard.runId, entryId: pendingDiscard.entryId },
|
||||
{ onSuccess: () => setPendingDiscard(null) },
|
||||
)
|
||||
}
|
||||
|
||||
const runs = runsQuery.data ?? []
|
||||
|
||||
return (
|
||||
<>
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent mobileFullscreen keyboardAware className="sm:max-w-3xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 pb-safe">
|
||||
<DialogHeader className="p-4 sm:p-6 border-b shrink-0">
|
||||
<DialogTitle>Multi-run</DialogTitle>
|
||||
<DialogDescription>
|
||||
Run one prompt on up to {MULTI_RUN_MAX_MODELS} models at once, each in its own session.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab} className="flex-1 flex flex-col min-h-0">
|
||||
<div className="px-4 sm:px-6 pt-3 shrink-0">
|
||||
<TabsList className="w-full justify-start">
|
||||
<TabsTrigger value="launch">Launch</TabsTrigger>
|
||||
<TabsTrigger value="runs">Runs</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
|
||||
<TabsContent value="launch" className="flex-1 overflow-y-auto p-4 sm:p-6 mt-0 space-y-4">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="multi-run-name">Group name</Label>
|
||||
<Input
|
||||
id="multi-run-name"
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
placeholder="Sweep"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="multi-run-prompt">Prompt</Label>
|
||||
<Textarea
|
||||
id="multi-run-prompt"
|
||||
value={prompt}
|
||||
onChange={(event) => setPrompt(event.target.value)}
|
||||
placeholder="The prompt to send to every model"
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>Models</Label>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{selectedModels.length}/{MULTI_RUN_MAX_MODELS} selected
|
||||
</span>
|
||||
</div>
|
||||
<div className="max-h-56 overflow-y-auto rounded-md border border-border divide-y divide-border">
|
||||
{modelGroups.length === 0 ? (
|
||||
<p className="p-3 text-sm text-muted-foreground">No models available.</p>
|
||||
) : (
|
||||
modelGroups.map((provider) => (
|
||||
<div key={provider.id} className="p-3 space-y-2">
|
||||
<p className="text-xs font-medium text-muted-foreground">
|
||||
{provider.name || provider.id}
|
||||
</p>
|
||||
{provider.models.map((model) => {
|
||||
const value = `${provider.id}/${model.id}`
|
||||
const checked = selectedModels.includes(value)
|
||||
const atCapacity = selectedModels.length >= MULTI_RUN_MAX_MODELS && !checked
|
||||
return (
|
||||
<label key={value} className="flex items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
aria-label={model.name || model.id}
|
||||
checked={checked}
|
||||
disabled={atCapacity}
|
||||
onCheckedChange={(next) => toggleModel(value, next === true)}
|
||||
/>
|
||||
<span className="truncate">{model.name || model.id}</span>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between rounded-lg border border-border p-3">
|
||||
<div className="space-y-0.5">
|
||||
<Label htmlFor="multi-run-isolate">Isolate runs</Label>
|
||||
<p className="text-xs text-muted-foreground">Give each model its own workspace.</p>
|
||||
</div>
|
||||
<Switch id="multi-run-isolate" checked={isolate} onCheckedChange={setIsolate} />
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="multi-run-base-ref">Start from</Label>
|
||||
<Input
|
||||
id="multi-run-base-ref"
|
||||
value={baseRef}
|
||||
onChange={(event) => setBaseRef(event.target.value)}
|
||||
placeholder="Current HEAD"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Branch or ref. Empty starts from the current HEAD.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={() => { void handleLaunch() }} disabled={!canSubmit}>
|
||||
{launch.isPending ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Launching...
|
||||
</>
|
||||
) : (
|
||||
'Launch'
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="runs" className="flex-1 overflow-y-auto p-4 sm:p-6 mt-0 space-y-4">
|
||||
{runsQuery.isLoading ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : runsQuery.error ? (
|
||||
<p className="text-sm text-destructive">
|
||||
{runsQuery.error instanceof Error ? runsQuery.error.message : 'Failed to load runs'}
|
||||
</p>
|
||||
) : runs.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No runs yet.</p>
|
||||
) : (
|
||||
runs.map((run) => (
|
||||
<div key={run.id} className="rounded-md border border-border">
|
||||
<div className="flex items-center justify-between gap-2 border-b border-border px-3 py-2">
|
||||
<span className="truncate text-sm font-medium">{run.name}</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
{run.entries.length} model{run.entries.length === 1 ? '' : 's'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="divide-y divide-border">
|
||||
{run.entries.map((entry) => (
|
||||
<div key={entry.id} className="flex flex-wrap items-center gap-2 px-3 py-2">
|
||||
<span className="min-w-0 flex-1 truncate text-sm">{entry.model}</span>
|
||||
<EntryStatus entry={entry} />
|
||||
{entry.status === 'failed' && entry.error ? (
|
||||
<span className="w-full text-xs text-destructive">{entry.error}</span>
|
||||
) : null}
|
||||
<div className="flex items-center gap-1">
|
||||
{entry.sessionId ? (
|
||||
<Button variant="ghost" size="sm" onClick={() => openEntry(entry)}>
|
||||
<ArrowUpRight className="mr-1 h-3.5 w-3.5" />
|
||||
Open
|
||||
</Button>
|
||||
) : null}
|
||||
{entry.status === 'started' || entry.status === 'failed' ? (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-destructive hover:text-destructive"
|
||||
onClick={() =>
|
||||
setPendingDiscard({
|
||||
runId: run.id,
|
||||
entryId: entry.id,
|
||||
model: entry.model,
|
||||
isolated: entry.isolated,
|
||||
})
|
||||
}
|
||||
>
|
||||
<Trash2 className="mr-1 h-3.5 w-3.5" />
|
||||
Discard
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<ConfirmDestructiveDialog
|
||||
open={pendingDiscard !== null}
|
||||
onOpenChange={(isOpen) => {
|
||||
if (!isOpen) setPendingDiscard(null)
|
||||
}}
|
||||
onConfirm={confirmDiscard}
|
||||
onCancel={() => setPendingDiscard(null)}
|
||||
title="Discard run"
|
||||
description={
|
||||
pendingDiscard?.isolated
|
||||
? 'Discard this run and remove its workspace directory? This action cannot be undone.'
|
||||
: 'Discard this run? This action cannot be undone.'
|
||||
}
|
||||
warning={pendingDiscard?.model}
|
||||
confirmLabel="Discard"
|
||||
pendingLabel="Discarding..."
|
||||
isPending={discard.isPending}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function EntryStatus({ entry }: { entry: MultiRunEntry }) {
|
||||
if (entry.status === 'started' && entry.sessionId) {
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<SessionStatusIndicator sessionID={entry.sessionId} size="sm" />
|
||||
<Badge variant="secondary">{STATUS_LABELS[entry.status]}</Badge>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const variant = entry.status === 'failed' ? 'destructive' : entry.status === 'discarded' ? 'outline' : 'secondary'
|
||||
return <Badge variant={variant}>{STATUS_LABELS[entry.status]}</Badge>
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { useMutation, useQuery, useQueryClient, type QueryClient } from '@tanstack/react-query'
|
||||
import { discardMultiRunEntry, launchMultiRun, listMultiRuns } from '@/api/multiRuns'
|
||||
import { repoSiblingsQueryKey } from '@/hooks/useRepoSiblings'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import type { LaunchMultiRunRequest, MultiRun } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export function multiRunQueryKey(repoId: number) {
|
||||
return ['multi-runs', repoId] as const
|
||||
}
|
||||
|
||||
function invalidateMultiRunCaches(queryClient: QueryClient, repoId: number) {
|
||||
queryClient.invalidateQueries({ queryKey: multiRunQueryKey(repoId) })
|
||||
queryClient.invalidateQueries({ queryKey: repoSiblingsQueryKey(repoId) })
|
||||
}
|
||||
|
||||
function countEntries(run: MultiRun, status: MultiRun['entries'][number]['status']) {
|
||||
return run.entries.filter((entry) => entry.status === status).length
|
||||
}
|
||||
|
||||
export function useMultiRuns(repoId: number | undefined, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: multiRunQueryKey(repoId ?? 0),
|
||||
queryFn: () => listMultiRuns(repoId!),
|
||||
enabled: enabled && !!repoId && repoId > 0,
|
||||
staleTime: 10_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useLaunchMultiRun(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (request: LaunchMultiRunRequest) => launchMultiRun(request),
|
||||
onSuccess: (run) => {
|
||||
invalidateMultiRunCaches(queryClient, repoId)
|
||||
const started = countEntries(run, 'started')
|
||||
const failed = countEntries(run, 'failed')
|
||||
if (failed === 0) {
|
||||
showToast.success(`Started ${started} run${started === 1 ? '' : 's'}`)
|
||||
} else if (started === 0) {
|
||||
showToast.error(`Failed to start ${failed} run${failed === 1 ? '' : 's'}`)
|
||||
} else {
|
||||
showToast.warning(`Started ${started}, failed ${failed}`)
|
||||
}
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to launch multi-run')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDiscardMultiRunEntry(repoId: number) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ runId, entryId }: { runId: number; entryId: number }) =>
|
||||
discardMultiRunEntry(runId, entryId),
|
||||
onSuccess: () => {
|
||||
invalidateMultiRunCaches(queryClient, repoId)
|
||||
showToast.success('Run discarded')
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to discard run')
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -2,9 +2,13 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { createRepoWorkspace, deleteRepoWorkspace, getRepoSiblings, type RepoSibling } from '@/api/repos'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
export function repoSiblingsQueryKey(repoId: number | undefined) {
|
||||
return ['repo', 'siblings', repoId] as const
|
||||
}
|
||||
|
||||
export function useRepoSiblings(repoId: number | undefined) {
|
||||
return useQuery<RepoSibling[]>({
|
||||
queryKey: ['repo', 'siblings', repoId],
|
||||
queryKey: repoSiblingsQueryKey(repoId),
|
||||
queryFn: () => getRepoSiblings(repoId!),
|
||||
enabled: !!repoId && repoId > 0,
|
||||
staleTime: 30_000,
|
||||
@@ -24,7 +28,7 @@ export function useDeleteRepoWorkspaces(repoId: number | undefined) {
|
||||
return { total: directories.length, failed }
|
||||
},
|
||||
onSuccess: ({ total, failed }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repo', 'siblings', repoId] })
|
||||
queryClient.invalidateQueries({ queryKey: repoSiblingsQueryKey(repoId) })
|
||||
const deleted = total - failed
|
||||
if (failed === 0) {
|
||||
showToast.success(deleted === 1 ? 'Workspace deleted' : `${deleted} workspaces deleted`)
|
||||
@@ -49,7 +53,7 @@ export function useCreateRepoWorkspace(repoId: number | undefined) {
|
||||
return createRepoWorkspace(repoId)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repo', 'siblings', repoId] })
|
||||
queryClient.invalidateQueries({ queryKey: repoSiblingsQueryKey(repoId) })
|
||||
showToast.success('Workspace created')
|
||||
},
|
||||
onError: () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet";
|
||||
import { Header } from "@/components/ui/header";
|
||||
import { RepoMcpDialog } from "@/components/repo/RepoMcpDialog";
|
||||
import { RepoSkillsDialog } from "@/components/repo/RepoSkillsDialog";
|
||||
import { MultiRunDialog } from "@/components/repo/MultiRunDialog";
|
||||
import { SourceControlPanel } from "@/components/source-control";
|
||||
import { useCreateSession } from "@/hooks/useOpenCode";
|
||||
import { useRepoActivity } from "@/hooks/useRepoActivity";
|
||||
@@ -18,7 +19,7 @@ import { WorktreeTabs } from "@/components/repo/WorktreeTabs";
|
||||
import { WorkspaceManager } from "@/components/repo/WorkspaceManager";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { GitBranch, Plus, Loader2, Layers } from "lucide-react";
|
||||
import { GitBranch, Plus, Loader2, Layers, Columns3 } from "lucide-react";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
@@ -34,6 +35,7 @@ export function RepoDetail() {
|
||||
const [skillsDialogOpen, setSkillsDialogOpen] = useDialogParam('skills');
|
||||
const [sourceControlOpen, setSourceControlOpen] = useDialogParam('sourceControl');
|
||||
const [resetPermissionsOpen, setResetPermissionsOpen] = useDialogParam('resetPermissions');
|
||||
const [multiRunOpen, setMultiRunOpen] = useDialogParam('multiRun');
|
||||
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
|
||||
const [workspaceSelectorOpen, setWorkspaceSelectorOpen] = useState(false);
|
||||
const [activeWorkspaceDirectory, setActiveWorkspaceDirectory] = useState<string | undefined>();
|
||||
@@ -202,6 +204,16 @@ export function RepoDetail() {
|
||||
<div className="flex items-center gap-1">
|
||||
<PendingActionsGroup />
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setMultiRunOpen(true)}
|
||||
aria-label="Multi-run"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-10 sm:h-9"
|
||||
>
|
||||
<Columns3 className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Multi-run</span>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => handleCreateSession()}
|
||||
disabled={createSessionMutation.isPending}
|
||||
@@ -296,6 +308,14 @@ export function RepoDetail() {
|
||||
onOpenChange={setResetPermissionsOpen}
|
||||
repoId={repoId}
|
||||
/>
|
||||
|
||||
<MultiRunDialog
|
||||
repoId={repoId}
|
||||
directory={baseDirectory}
|
||||
defaultBaseRef={currentBranch}
|
||||
open={multiRunOpen}
|
||||
onOpenChange={setMultiRunOpen}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user