2026-01-01 14:59:51 +02:00
|
|
|
import React from 'react';
|
2026-01-19 02:50:40 +02:00
|
|
|
import { toast } from '@/components/ui';
|
2026-01-01 14:59:51 +02:00
|
|
|
import { Button } from '@/components/ui/button';
|
2026-05-15 11:35:23 +03:00
|
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
2026-01-01 14:59:51 +02:00
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
2026-01-07 12:08:53 +02:00
|
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
2026-03-22 22:31:29 +02:00
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
|
|
|
|
import { ScrollShadow } from '@/components/ui/ScrollShadow';
|
|
|
|
|
import { cn, formatDirectoryName } from '@/lib/utils';
|
2026-01-01 14:59:51 +02:00
|
|
|
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
|
|
|
|
import { useMultiRunStore } from '@/stores/useMultiRunStore';
|
2026-03-31 18:47:00 +03:00
|
|
|
import { useSessionUIStore } from '@/sync/session-ui-store';
|
2026-01-07 12:08:53 +02:00
|
|
|
import { useProjectsStore } from '@/stores/useProjectsStore';
|
|
|
|
|
import { getWorktreeSetupCommands } from '@/lib/openchamberConfig';
|
2026-01-27 19:59:48 +02:00
|
|
|
import type { ProjectRef } from '@/lib/openchamberConfig';
|
2026-05-21 09:35:42 -04:00
|
|
|
import type { CreateMultiRunParams, MultiRunGroup } from '@/types/multirun';
|
2026-01-03 22:11:16 +01:00
|
|
|
import { ModelMultiSelect, generateInstanceId, type ModelSelectionWithId } from './ModelMultiSelect';
|
|
|
|
|
import { BranchSelector, useBranchOptions } from './BranchSelector';
|
2026-01-04 15:53:44 +01:00
|
|
|
import { AgentSelector } from './AgentSelector';
|
2026-05-21 20:00:35 +03:00
|
|
|
import { CommandAutocomplete, type CommandAutocompleteHandle, type CommandInfo } from '@/components/chat/CommandAutocomplete';
|
|
|
|
|
import { FileMentionAutocomplete, type FileMentionHandle } from '@/components/chat/FileMentionAutocomplete';
|
|
|
|
|
import { SnippetAutocomplete, type SnippetAutocompleteHandle } from '@/components/chat/SnippetAutocomplete';
|
2026-05-13 13:26:15 +03:00
|
|
|
import { Icon } from "@/components/icon/Icon";
|
2026-04-20 15:41:15 +03:00
|
|
|
import { isDesktopShell } from '@/lib/desktop';
|
2026-05-03 21:39:30 +03:00
|
|
|
import { useTabletStandalonePwaRuntime } from '@/lib/device';
|
2026-03-22 22:31:29 +02:00
|
|
|
import { useThemeSystem } from '@/contexts/useThemeSystem';
|
2026-06-02 00:43:05 +03:00
|
|
|
import { PROJECT_ICON_MAP, PROJECT_COLOR_MAP, ProjectIconImage } from '@/lib/projectMeta';
|
2026-03-22 22:31:29 +02:00
|
|
|
import type { ProjectEntry } from '@/lib/api/types';
|
2026-04-20 15:41:15 +03:00
|
|
|
import { startDesktopWindowDrag } from '@/lib/desktopNative';
|
2026-04-26 14:03:39 +03:00
|
|
|
import { useI18n } from '@/lib/i18n';
|
2026-01-01 14:59:51 +02:00
|
|
|
|
2026-01-02 14:18:40 +02:00
|
|
|
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
2026-05-21 09:35:42 -04:00
|
|
|
const MAX_MODELS_PER_GROUP = 5;
|
2026-01-02 14:18:40 +02:00
|
|
|
|
|
|
|
|
interface MultiRunAttachedFile {
|
|
|
|
|
id: string;
|
|
|
|
|
filename: string;
|
|
|
|
|
mimeType: string;
|
|
|
|
|
size: number;
|
|
|
|
|
dataUrl: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
interface RunGroupState {
|
|
|
|
|
id: string;
|
|
|
|
|
prompt: string;
|
|
|
|
|
models: ModelSelectionWithId[];
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
interface MultiRunLauncherProps {
|
|
|
|
|
initialPrompt?: string;
|
|
|
|
|
onCreated?: () => void;
|
|
|
|
|
onCancel?: () => void;
|
2026-03-22 22:31:29 +02:00
|
|
|
isWindowed?: boolean;
|
2026-01-01 14:59:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
const InfoTip: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
2026-04-30 22:41:33 +03:00
|
|
|
<Tooltip>
|
2026-03-22 22:31:29 +02:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button type="button" tabIndex={-1} className="inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors">
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="information" className="h-3.5 w-3.5" />
|
2026-03-22 22:31:29 +02:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="top" className="max-w-[240px]">
|
|
|
|
|
{children}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const FieldLabel: React.FC<{
|
|
|
|
|
htmlFor?: string;
|
|
|
|
|
required?: boolean;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
info?: React.ReactNode;
|
|
|
|
|
}> = ({ htmlFor, required, children, info }) => (
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<label htmlFor={htmlFor} className="typography-meta font-medium text-foreground">
|
|
|
|
|
{children}
|
|
|
|
|
{required && <span className="text-destructive ml-0.5">*</span>}
|
|
|
|
|
</label>
|
|
|
|
|
{info && info}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
export const MultiRunLauncher: React.FC<MultiRunLauncherProps> = ({
|
|
|
|
|
initialPrompt,
|
|
|
|
|
onCreated,
|
|
|
|
|
onCancel,
|
2026-03-22 22:31:29 +02:00
|
|
|
isWindowed = false,
|
2026-01-01 14:59:51 +02:00
|
|
|
}) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const { t } = useI18n();
|
2026-01-01 14:59:51 +02:00
|
|
|
const [name, setName] = React.useState('');
|
2026-05-21 09:35:42 -04:00
|
|
|
const [runGroups, setRunGroups] = React.useState<RunGroupState[]>(() => [
|
2026-05-21 20:00:35 +03:00
|
|
|
{ id: generateInstanceId(), prompt: '', models: [] },
|
2026-05-21 09:35:42 -04:00
|
|
|
]);
|
2026-01-04 15:53:44 +01:00
|
|
|
const [selectedAgent, setSelectedAgent] = React.useState<string>('');
|
2026-01-02 14:18:40 +02:00
|
|
|
const [attachedFiles, setAttachedFiles] = React.useState<MultiRunAttachedFile[]>([]);
|
2026-01-01 14:59:51 +02:00
|
|
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
2026-01-07 12:08:53 +02:00
|
|
|
const [setupCommands, setSetupCommands] = React.useState<string[]>([]);
|
|
|
|
|
const [isSetupCommandsOpen, setIsSetupCommandsOpen] = React.useState(false);
|
|
|
|
|
const [isLoadingSetupCommands, setIsLoadingSetupCommands] = React.useState(false);
|
2026-05-15 11:35:23 +03:00
|
|
|
const [isolateRuns, setIsolateRuns] = React.useState(true);
|
2026-01-02 14:18:40 +02:00
|
|
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
2026-05-21 09:35:42 -04:00
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
const currentDirectory = useDirectoryStore((state) => state.currentDirectory ?? null);
|
2026-03-22 22:31:29 +02:00
|
|
|
const homeDirectory = useDirectoryStore((state) => state.homeDirectory ?? null);
|
2026-05-21 09:35:42 -04:00
|
|
|
|
2026-01-07 12:08:53 +02:00
|
|
|
const vscodeWorkspaceFolder = React.useMemo(() => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (typeof window === 'undefined') return null;
|
2026-01-07 12:08:53 +02:00
|
|
|
const folder = (window as unknown as { __VSCODE_CONFIG__?: { workspaceFolder?: unknown } }).__VSCODE_CONFIG__?.workspaceFolder;
|
|
|
|
|
return typeof folder === 'string' && folder.trim().length > 0 ? folder.trim() : null;
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const activeProjectId = useProjectsStore((state) => state.activeProjectId);
|
2026-03-22 22:31:29 +02:00
|
|
|
const setActiveProjectIdOnly = useProjectsStore((state) => state.setActiveProjectIdOnly);
|
2026-01-07 12:08:53 +02:00
|
|
|
const projects = useProjectsStore((state) => state.projects);
|
2026-03-22 22:31:29 +02:00
|
|
|
const [selectedProjectId, setSelectedProjectId] = React.useState<string | null>(() => activeProjectId ?? null);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2026-01-07 12:08:53 +02:00
|
|
|
if (activeProjectId) {
|
2026-03-22 22:31:29 +02:00
|
|
|
setSelectedProjectId(activeProjectId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!selectedProjectId && projects.length > 0) {
|
|
|
|
|
setSelectedProjectId(projects[0].id);
|
|
|
|
|
}
|
|
|
|
|
}, [activeProjectId, projects, selectedProjectId]);
|
|
|
|
|
|
|
|
|
|
const selectedProject = React.useMemo(() => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!selectedProjectId) return null;
|
2026-03-22 22:31:29 +02:00
|
|
|
return projects.find((project) => project.id === selectedProjectId) ?? null;
|
|
|
|
|
}, [projects, selectedProjectId]);
|
|
|
|
|
|
|
|
|
|
const selectedProjectDirectory = selectedProject?.path ?? currentDirectory;
|
|
|
|
|
|
|
|
|
|
const handleProjectChange = React.useCallback((projectId: string) => {
|
|
|
|
|
setSelectedProjectId(projectId);
|
|
|
|
|
if (projectId !== activeProjectId) {
|
|
|
|
|
setActiveProjectIdOnly(projectId);
|
|
|
|
|
}
|
|
|
|
|
}, [activeProjectId, setActiveProjectIdOnly]);
|
|
|
|
|
|
|
|
|
|
const { currentTheme } = useThemeSystem();
|
|
|
|
|
|
|
|
|
|
const renderProjectLabel = React.useCallback((project: ProjectEntry) => {
|
|
|
|
|
const displayLabel = project.label?.trim() || formatDirectoryName(project.path, homeDirectory);
|
2026-05-13 13:26:15 +03:00
|
|
|
const projectIconName = project.icon ? PROJECT_ICON_MAP[project.icon] : null;
|
2026-03-22 22:31:29 +02:00
|
|
|
const iconColor = project.color ? PROJECT_COLOR_MAP[project.color] : undefined;
|
2026-06-02 00:43:05 +03:00
|
|
|
const fallbackIcon = projectIconName ? (
|
|
|
|
|
<Icon name={projectIconName} className="h-3.5 w-3.5 shrink-0" style={iconColor ? { color: iconColor } : undefined} />
|
|
|
|
|
) : (
|
|
|
|
|
<Icon name="folder" className="h-3.5 w-3.5 shrink-0 text-muted-foreground/80" style={iconColor ? { color: iconColor } : undefined}/>
|
|
|
|
|
);
|
2026-03-22 22:31:29 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span className="inline-flex min-w-0 items-center gap-1.5">
|
2026-06-02 00:43:05 +03:00
|
|
|
{project.iconImage ? (
|
2026-03-22 22:31:29 +02:00
|
|
|
<span
|
|
|
|
|
className="inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]"
|
|
|
|
|
style={project.iconBackground ? { backgroundColor: project.iconBackground } : undefined}
|
|
|
|
|
>
|
2026-06-02 00:43:05 +03:00
|
|
|
<ProjectIconImage
|
|
|
|
|
project={{ id: project.id, iconImage: project.iconImage ?? null }}
|
|
|
|
|
options={{
|
|
|
|
|
themeVariant: currentTheme.metadata.variant,
|
|
|
|
|
iconColor: currentTheme.colors.surface.foreground,
|
|
|
|
|
}}
|
|
|
|
|
className="h-full w-full object-contain"
|
|
|
|
|
fallback={fallbackIcon}
|
|
|
|
|
/>
|
2026-03-22 22:31:29 +02:00
|
|
|
</span>
|
2026-06-02 00:43:05 +03:00
|
|
|
) : fallbackIcon}
|
2026-03-22 22:31:29 +02:00
|
|
|
<span className="truncate">{displayLabel}</span>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}, [homeDirectory, currentTheme.metadata.variant, currentTheme.colors.surface.foreground]);
|
|
|
|
|
|
|
|
|
|
const projectRef = React.useMemo<ProjectRef | null>(() => {
|
|
|
|
|
if (selectedProject?.path) {
|
|
|
|
|
return { id: selectedProject.id, path: selectedProject.path };
|
2026-01-07 12:08:53 +02:00
|
|
|
}
|
|
|
|
|
const base = currentDirectory ?? vscodeWorkspaceFolder;
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!base) return null;
|
2026-01-27 19:59:48 +02:00
|
|
|
return { id: `path:${base}`, path: base };
|
2026-03-22 22:31:29 +02:00
|
|
|
}, [selectedProject, currentDirectory, vscodeWorkspaceFolder]);
|
2026-01-01 16:55:40 +02:00
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const [isDesktopApp] = React.useState(() => (typeof window !== 'undefined' ? isDesktopShell() : false));
|
2026-01-01 16:55:40 +02:00
|
|
|
|
|
|
|
|
const isMacPlatform = React.useMemo(() => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (typeof navigator === 'undefined') return false;
|
2026-01-01 16:55:40 +02:00
|
|
|
return /Macintosh|Mac OS X/.test(navigator.userAgent || '');
|
|
|
|
|
}, []);
|
2026-05-03 21:39:30 +03:00
|
|
|
const isTabletStandalonePwa = useTabletStandalonePwaRuntime();
|
2026-01-01 16:55:40 +02:00
|
|
|
|
2026-02-05 01:59:49 +02:00
|
|
|
const macosMajorVersion = React.useMemo(() => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (typeof window === 'undefined') return null;
|
2026-02-05 01:59:49 +02:00
|
|
|
const injected = (window as unknown as { __OPENCHAMBER_MACOS_MAJOR__?: unknown }).__OPENCHAMBER_MACOS_MAJOR__;
|
2026-05-21 09:35:42 -04:00
|
|
|
if (typeof injected === 'number' && Number.isFinite(injected) && injected > 0) return injected;
|
|
|
|
|
if (typeof navigator === 'undefined') return null;
|
2026-02-05 01:59:49 +02:00
|
|
|
const match = (navigator.userAgent || '').match(/Mac OS X (\d+)[._](\d+)/);
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!match) return null;
|
2026-02-05 01:59:49 +02:00
|
|
|
const first = Number.parseInt(match[1], 10);
|
|
|
|
|
const second = Number.parseInt(match[2], 10);
|
2026-05-21 09:35:42 -04:00
|
|
|
if (Number.isNaN(first)) return null;
|
2026-02-05 01:59:49 +02:00
|
|
|
return first === 10 ? second : first;
|
2026-01-01 16:55:40 +02:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const desktopHeaderPaddingClass = React.useMemo(() => {
|
2026-05-03 21:39:30 +03:00
|
|
|
if ((isDesktopApp && isMacPlatform) || isTabletStandalonePwa) {
|
|
|
|
|
// Match main app header: reserve space for Mac/iPadOS traffic lights.
|
2026-01-30 02:46:43 +02:00
|
|
|
return 'pl-[5.5rem]';
|
2026-01-01 16:55:40 +02:00
|
|
|
}
|
|
|
|
|
return 'pl-3';
|
2026-05-03 21:39:30 +03:00
|
|
|
}, [isDesktopApp, isMacPlatform, isTabletStandalonePwa]);
|
2026-01-27 19:59:48 +02:00
|
|
|
|
2026-02-05 01:59:49 +02:00
|
|
|
const macosHeaderSizeClass = React.useMemo(() => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!isDesktopApp || !isMacPlatform || macosMajorVersion === null) return '';
|
|
|
|
|
if (macosMajorVersion >= 26) return 'h-12';
|
|
|
|
|
if (macosMajorVersion <= 15) return 'h-14';
|
2026-02-05 01:59:49 +02:00
|
|
|
return '';
|
|
|
|
|
}, [isDesktopApp, isMacPlatform, macosMajorVersion]);
|
|
|
|
|
|
2026-01-27 19:59:48 +02:00
|
|
|
const handleDragStart = React.useCallback(async (e: React.MouseEvent) => {
|
2026-05-21 09:35:42 -04:00
|
|
|
if ((e.target as HTMLElement).closest('button, a, input, select, textarea')) return;
|
|
|
|
|
if (e.button !== 0) return;
|
|
|
|
|
if (isDesktopApp) await startDesktopWindowDrag();
|
2026-01-27 19:59:48 +02:00
|
|
|
}, [isDesktopApp]);
|
2026-01-01 14:59:51 +02:00
|
|
|
|
2026-01-30 02:46:43 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!onCancel) return;
|
|
|
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onCancel();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
window.addEventListener('keydown', handleKeyDown, true);
|
|
|
|
|
return () => window.removeEventListener('keydown', handleKeyDown, true);
|
|
|
|
|
}, [onCancel]);
|
|
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
const [worktreeBaseBranch, setWorktreeBaseBranch] = React.useState<string>('');
|
|
|
|
|
const { isLoading: isLoadingWorktreeBaseBranches, isGitRepository } = useBranchOptions(selectedProjectDirectory);
|
2026-05-15 11:35:23 +03:00
|
|
|
const wasIsolationDisabledByNonGitRef = React.useRef(false);
|
|
|
|
|
const canIsolateRuns = isGitRepository === true;
|
|
|
|
|
const effectiveIsolateRuns = canIsolateRuns && isolateRuns;
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (isGitRepository === false) {
|
|
|
|
|
wasIsolationDisabledByNonGitRef.current = true;
|
|
|
|
|
setIsolateRuns(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isGitRepository === true && wasIsolationDisabledByNonGitRef.current) {
|
|
|
|
|
wasIsolationDisabledByNonGitRef.current = false;
|
|
|
|
|
setIsolateRuns(true);
|
|
|
|
|
}
|
|
|
|
|
}, [isGitRepository]);
|
2026-01-01 14:59:51 +02:00
|
|
|
|
|
|
|
|
const createMultiRun = useMultiRunStore((state) => state.createMultiRun);
|
|
|
|
|
const error = useMultiRunStore((state) => state.error);
|
|
|
|
|
const clearError = useMultiRunStore((state) => state.clearError);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (typeof initialPrompt === 'string' && initialPrompt.trim().length > 0) {
|
2026-05-21 09:35:42 -04:00
|
|
|
setRunGroups((prev) => {
|
|
|
|
|
const updated = [...prev];
|
|
|
|
|
if (updated.length > 0 && !updated[0].prompt.trim()) {
|
|
|
|
|
updated[0] = { ...updated[0], prompt: initialPrompt };
|
|
|
|
|
}
|
|
|
|
|
return updated;
|
|
|
|
|
});
|
2026-01-01 14:59:51 +02:00
|
|
|
}
|
|
|
|
|
}, [initialPrompt]);
|
|
|
|
|
|
2026-01-07 12:08:53 +02:00
|
|
|
React.useEffect(() => {
|
2026-01-27 19:59:48 +02:00
|
|
|
if (!projectRef) return;
|
2026-01-07 12:08:53 +02:00
|
|
|
let cancelled = false;
|
|
|
|
|
setIsLoadingSetupCommands(true);
|
|
|
|
|
(async () => {
|
|
|
|
|
try {
|
2026-01-27 19:59:48 +02:00
|
|
|
const commands = await getWorktreeSetupCommands(projectRef);
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!cancelled) setSetupCommands(commands);
|
2026-01-07 12:08:53 +02:00
|
|
|
} catch {
|
2026-05-21 09:35:42 -04:00
|
|
|
// Ignore
|
2026-01-07 12:08:53 +02:00
|
|
|
} finally {
|
2026-05-21 09:35:42 -04:00
|
|
|
if (!cancelled) setIsLoadingSetupCommands(false);
|
2026-01-07 12:08:53 +02:00
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
return () => { cancelled = true; };
|
2026-01-27 19:59:48 +02:00
|
|
|
}, [projectRef]);
|
2026-01-07 12:08:53 +02:00
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const updateGroup = React.useCallback((groupId: string, updates: Partial<RunGroupState>) => {
|
|
|
|
|
setRunGroups((prev) => prev.map((g) => g.id === groupId ? { ...g, ...updates } : g));
|
|
|
|
|
}, []);
|
2026-01-01 14:59:51 +02:00
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const removeGroup = React.useCallback((groupId: string) => {
|
|
|
|
|
setRunGroups((prev) => prev.filter((g) => g.id !== groupId));
|
|
|
|
|
}, []);
|
2026-01-01 14:59:51 +02:00
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const addGroup = React.useCallback(() => {
|
2026-05-21 20:00:35 +03:00
|
|
|
setRunGroups((prev) => [...prev, { id: generateInstanceId(), prompt: '', models: [] }]);
|
2026-01-08 17:01:24 +02:00
|
|
|
}, []);
|
|
|
|
|
|
2026-01-02 14:18:40 +02:00
|
|
|
const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const files = e.target.files;
|
|
|
|
|
if (!files) return;
|
|
|
|
|
let attachedCount = 0;
|
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
|
const file = files[i];
|
|
|
|
|
if (file.size > MAX_FILE_SIZE) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('multirun.launcher.toast.fileTooLarge', { fileName: file.name }));
|
2026-01-02 14:18:40 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const dataUrl = await new Promise<string>((resolve, reject) => {
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = () => resolve(reader.result as string);
|
|
|
|
|
reader.onerror = reject;
|
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
|
});
|
2026-05-21 09:35:42 -04:00
|
|
|
setAttachedFiles((prev) => [...prev, {
|
2026-01-02 14:18:40 +02:00
|
|
|
id: generateInstanceId(),
|
|
|
|
|
filename: file.name,
|
|
|
|
|
mimeType: file.type || 'application/octet-stream',
|
|
|
|
|
size: file.size,
|
|
|
|
|
dataUrl,
|
2026-05-21 09:35:42 -04:00
|
|
|
}]);
|
2026-01-02 14:18:40 +02:00
|
|
|
attachedCount++;
|
2026-05-21 09:35:42 -04:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('File attach failed', err);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('multirun.launcher.toast.attachFailed', { fileName: file.name }));
|
2026-01-02 14:18:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (attachedCount > 0) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(
|
|
|
|
|
attachedCount === 1
|
|
|
|
|
? t('multirun.launcher.toast.attachedSingle', { count: attachedCount })
|
2026-05-21 09:35:42 -04:00
|
|
|
: t('multirun.launcher.toast.attachedPlural', { count: attachedCount }),
|
2026-04-26 14:03:39 +03:00
|
|
|
);
|
2026-01-02 14:18:40 +02:00
|
|
|
}
|
2026-05-21 09:35:42 -04:00
|
|
|
if (fileInputRef.current) fileInputRef.current.value = '';
|
2026-01-02 14:18:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRemoveFile = (id: string) => {
|
|
|
|
|
setAttachedFiles((prev) => prev.filter((f) => f.id !== id));
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const totalRunCount = React.useMemo(
|
|
|
|
|
() => runGroups.reduce((sum, g) => sum + g.models.length, 0),
|
|
|
|
|
[runGroups],
|
|
|
|
|
);
|
2026-04-16 15:55:08 +03:00
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const validGroups = runGroups.filter((g) => g.prompt.trim() && g.models.length >= 1);
|
|
|
|
|
if (validGroups.length === 0) return;
|
|
|
|
|
if (totalRunCount < 1) return;
|
2026-01-01 14:59:51 +02:00
|
|
|
|
|
|
|
|
setIsSubmitting(true);
|
|
|
|
|
clearError();
|
|
|
|
|
|
|
|
|
|
try {
|
2026-03-22 22:31:29 +02:00
|
|
|
if (selectedProjectId && selectedProjectId !== activeProjectId) {
|
|
|
|
|
setActiveProjectIdOnly(selectedProjectId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 14:18:40 +02:00
|
|
|
const filesForStore = attachedFiles.map((f) => ({
|
|
|
|
|
mime: f.mimeType,
|
|
|
|
|
filename: f.filename,
|
|
|
|
|
url: f.dataUrl,
|
|
|
|
|
}));
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const commandsForStore = setupCommands.filter((cmd) => cmd.trim().length > 0);
|
|
|
|
|
|
|
|
|
|
const groups: MultiRunGroup[] = validGroups.map((g) => ({
|
|
|
|
|
prompt: g.prompt.trim(),
|
|
|
|
|
models: g.models.map((m) => ({ providerID: m.providerID, modelID: m.modelID, displayName: m.displayName, variant: m.variant })),
|
|
|
|
|
}));
|
2026-01-07 12:08:53 +02:00
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
const params: CreateMultiRunParams = {
|
|
|
|
|
name: name.trim(),
|
2026-05-21 09:35:42 -04:00
|
|
|
groups,
|
2026-01-04 15:53:44 +01:00
|
|
|
agent: selectedAgent || undefined,
|
2026-05-15 11:35:23 +03:00
|
|
|
worktreeBaseBranch: effectiveIsolateRuns ? worktreeBaseBranch : undefined,
|
|
|
|
|
isolateRuns: effectiveIsolateRuns,
|
2026-01-02 14:18:40 +02:00
|
|
|
files: filesForStore.length > 0 ? filesForStore : undefined,
|
2026-01-07 12:08:53 +02:00
|
|
|
setupCommands: commandsForStore.length > 0 ? commandsForStore : undefined,
|
2026-01-01 14:59:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = await createMultiRun(params);
|
2026-05-21 09:35:42 -04:00
|
|
|
if (result) {
|
|
|
|
|
if (result.firstSessionId) {
|
|
|
|
|
useSessionUIStore.getState().setCurrentSession(result.firstSessionId);
|
|
|
|
|
}
|
|
|
|
|
onCreated?.();
|
|
|
|
|
}
|
2026-01-01 14:59:51 +02:00
|
|
|
} finally {
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isValid = Boolean(
|
2026-05-21 09:35:42 -04:00
|
|
|
name.trim()
|
|
|
|
|
&& runGroups.some((g) => g.prompt.trim() && g.models.length >= 1)
|
|
|
|
|
&& totalRunCount >= 1
|
|
|
|
|
&& selectedProjectDirectory
|
|
|
|
|
&& !isLoadingWorktreeBaseBranches
|
|
|
|
|
&& (isGitRepository === false || !effectiveIsolateRuns || worktreeBaseBranch)
|
2026-01-01 14:59:51 +02:00
|
|
|
);
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
const configuredSetupCount = setupCommands.filter((cmd) => cmd.trim()).length;
|
2026-03-22 22:31:29 +02:00
|
|
|
|
2026-01-01 14:59:51 +02:00
|
|
|
return (
|
2026-04-24 09:33:02 +03:00
|
|
|
<form onSubmit={handleSubmit} className="flex flex-col h-full bg-background">
|
2026-03-22 22:31:29 +02:00
|
|
|
{!isWindowed ? (
|
|
|
|
|
<header
|
|
|
|
|
onMouseDown={handleDragStart}
|
|
|
|
|
className={cn(
|
|
|
|
|
'relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none',
|
|
|
|
|
desktopHeaderPaddingClass,
|
|
|
|
|
macosHeaderSizeClass,
|
|
|
|
|
)}
|
|
|
|
|
style={{ borderColor: 'var(--interactive-border)' }}
|
|
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
<h1 className="typography-ui-label font-medium">{t('multirun.launcher.title')}</h1>
|
2026-03-22 22:31:29 +02:00
|
|
|
{onCancel && (
|
|
|
|
|
<div className="absolute right-0 flex items-center pr-3">
|
2026-04-30 22:41:33 +03:00
|
|
|
<Tooltip>
|
2026-03-22 22:31:29 +02:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onCancel}
|
2026-04-26 14:03:39 +03:00
|
|
|
aria-label={t('multirun.launcher.actions.closeEsc')}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag"
|
|
|
|
|
>
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="close" className="h-5 w-5" />
|
2026-03-22 22:31:29 +02:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
2026-05-21 09:35:42 -04:00
|
|
|
<TooltipContent><p>{t('multirun.launcher.actions.closeEsc')}</p></TooltipContent>
|
2026-03-22 22:31:29 +02:00
|
|
|
</Tooltip>
|
2026-01-01 14:59:51 +02:00
|
|
|
</div>
|
2026-03-22 22:31:29 +02:00
|
|
|
)}
|
|
|
|
|
</header>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<ScrollShadow className="flex-1 min-h-0 overflow-auto" size={64} hideTopShadow>
|
|
|
|
|
<div className="mx-auto w-full max-w-2xl px-4 sm:px-6 py-5">
|
|
|
|
|
<div className="flex flex-col gap-5">
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3">
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-26 14:03:39 +03:00
|
|
|
<FieldLabel htmlFor="multirun-project" required>{t('multirun.launcher.project.label')}</FieldLabel>
|
2026-03-22 22:31:29 +02:00
|
|
|
{projects.length > 0 ? (
|
2026-05-21 09:35:42 -04:00
|
|
|
<Select value={selectedProjectId ?? undefined} onValueChange={handleProjectChange}>
|
2026-03-22 22:31:29 +02:00
|
|
|
<SelectTrigger id="multirun-project" size="lg" className="w-fit max-w-full">
|
|
|
|
|
{selectedProject ? (
|
|
|
|
|
<SelectValue>{renderProjectLabel(selectedProject)}</SelectValue>
|
|
|
|
|
) : (
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectValue placeholder={t('multirun.launcher.project.placeholder')} />
|
2026-03-22 22:31:29 +02:00
|
|
|
)}
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent fitContent>
|
|
|
|
|
{projects.map((project) => (
|
|
|
|
|
<SelectItem key={project.id} value={project.id} className="max-w-[24rem]">
|
|
|
|
|
{renderProjectLabel(project)}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
) : (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-micro text-muted-foreground py-2">{t('multirun.launcher.project.empty')}</p>
|
2026-03-22 22:31:29 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
2026-01-01 14:59:51 +02:00
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-21 09:35:42 -04:00
|
|
|
<FieldLabel htmlFor="group-name" required info={<InfoTip>{t('multirun.launcher.groupName.info')}</InfoTip>}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.groupName.label')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</FieldLabel>
|
|
|
|
|
<Input
|
|
|
|
|
id="group-name"
|
|
|
|
|
value={name}
|
|
|
|
|
onChange={(e) => setName(e.target.value)}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('multirun.launcher.groupName.placeholder')}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="typography-meta w-full"
|
|
|
|
|
required
|
|
|
|
|
/>
|
2026-01-01 14:59:51 +02:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-21 09:35:42 -04:00
|
|
|
<FieldLabel htmlFor="multirun-worktree-base-branch" info={<InfoTip>{t('multirun.launcher.baseBranch.info')}</InfoTip>}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.baseBranch.label')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</FieldLabel>
|
2026-01-03 22:11:16 +01:00
|
|
|
<BranchSelector
|
2026-03-22 22:31:29 +02:00
|
|
|
directory={selectedProjectDirectory}
|
2026-01-01 14:59:51 +02:00
|
|
|
value={worktreeBaseBranch}
|
2026-01-03 22:11:16 +01:00
|
|
|
onChange={setWorktreeBaseBranch}
|
2026-05-15 11:35:23 +03:00
|
|
|
disabled={!effectiveIsolateRuns}
|
2026-01-03 22:11:16 +01:00
|
|
|
id="multirun-worktree-base-branch"
|
|
|
|
|
/>
|
2026-05-15 11:35:23 +03:00
|
|
|
<label className="mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground">
|
|
|
|
|
<Checkbox
|
|
|
|
|
checked={isolateRuns}
|
|
|
|
|
onChange={setIsolateRuns}
|
|
|
|
|
disabled={!canIsolateRuns}
|
|
|
|
|
ariaLabel={t('multirun.launcher.isolateRuns.label')}
|
|
|
|
|
/>
|
|
|
|
|
<span>{t('multirun.launcher.isolateRuns.label')}</span>
|
|
|
|
|
</label>
|
2026-01-01 14:59:51 +02:00
|
|
|
</div>
|
2026-01-07 12:08:53 +02:00
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
<div className="flex flex-col gap-1">
|
2026-05-21 09:35:42 -04:00
|
|
|
<FieldLabel htmlFor="multirun-agent" info={<InfoTip>{t('multirun.launcher.agent.info')}</InfoTip>}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.agent.label')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</FieldLabel>
|
2026-05-21 09:35:42 -04:00
|
|
|
<AgentSelector value={selectedAgent} onChange={setSelectedAgent} id="multirun-agent" />
|
2026-03-22 22:31:29 +02:00
|
|
|
</div>
|
2026-01-04 15:53:44 +01:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-22 22:31:29 +02:00
|
|
|
<Collapsible open={isSetupCommandsOpen} onOpenChange={setIsSetupCommandsOpen}>
|
|
|
|
|
<CollapsibleTrigger className="w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group">
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="terminal" className="h-3.5 w-3.5 text-muted-foreground/70" />
|
2026-03-22 22:31:29 +02:00
|
|
|
<span className="typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors">
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.setupCommands.label')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</span>
|
|
|
|
|
{configuredSetupCount > 0 && (
|
|
|
|
|
<span
|
|
|
|
|
className="inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'var(--primary-base)',
|
|
|
|
|
color: 'var(--primary-foreground)',
|
|
|
|
|
fontSize: '0.625rem',
|
|
|
|
|
lineHeight: 1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{configuredSetupCount}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="arrow-down-s" className={cn(
|
2026-03-22 22:31:29 +02:00
|
|
|
'h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto',
|
2026-05-21 09:35:42 -04:00
|
|
|
isSetupCommandsOpen && 'rotate-180',
|
2026-03-22 22:31:29 +02:00
|
|
|
)} />
|
|
|
|
|
</CollapsibleTrigger>
|
|
|
|
|
<CollapsibleContent>
|
|
|
|
|
<div className="pt-2 space-y-1.5">
|
|
|
|
|
{isLoadingSetupCommands ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground/70 px-2">{t('multirun.launcher.setupCommands.loading')}</p>
|
2026-03-22 22:31:29 +02:00
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{setupCommands.map((command, index) => (
|
2026-04-26 16:24:07 +03:00
|
|
|
<div key={`${command}-${index}`} className="flex gap-1.5">
|
2026-03-22 22:31:29 +02:00
|
|
|
<Input
|
|
|
|
|
value={command}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const newCommands = [...setupCommands];
|
|
|
|
|
newCommands[index] = e.target.value;
|
|
|
|
|
setSetupCommands(newCommands);
|
|
|
|
|
}}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('multirun.launcher.setupCommands.commandPlaceholder')}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="h-8 flex-1 font-mono text-xs"
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-05-21 09:35:42 -04:00
|
|
|
onClick={() => setSetupCommands(setupCommands.filter((_, i) => i !== index))}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
2026-04-26 14:03:39 +03:00
|
|
|
aria-label={t('multirun.launcher.setupCommands.removeCommandAria')}
|
2026-03-22 22:31:29 +02:00
|
|
|
>
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="close" className="h-3.5 w-3.5" />
|
2026-03-22 22:31:29 +02:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setSetupCommands([...setupCommands, ''])}
|
|
|
|
|
className="flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1"
|
|
|
|
|
>
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="add" className="h-3 w-3" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.setupCommands.addCommand')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</CollapsibleContent>
|
|
|
|
|
</Collapsible>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
2026-05-21 09:35:42 -04:00
|
|
|
<FieldLabel htmlFor="prompt" required>{t('multirun.launcher.attachments.label')}</FieldLabel>
|
2026-03-22 22:31:29 +02:00
|
|
|
<div className="flex flex-wrap items-center gap-1.5">
|
2026-05-21 09:35:42 -04:00
|
|
|
<input ref={fileInputRef} type="file" multiple className="hidden" onChange={handleFileSelect} accept="*/*" />
|
2026-04-30 22:41:33 +03:00
|
|
|
<Tooltip>
|
2026-03-22 22:31:29 +02:00
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => fileInputRef.current?.click()}
|
|
|
|
|
className="inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors"
|
|
|
|
|
>
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="attachment-2" className="h-3 w-3" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.attachments.attach')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
2026-04-26 14:03:39 +03:00
|
|
|
<TooltipContent>{t('multirun.launcher.attachments.tooltip')}</TooltipContent>
|
2026-03-22 22:31:29 +02:00
|
|
|
</Tooltip>
|
2026-01-02 14:18:40 +02:00
|
|
|
{attachedFiles.map((file) => (
|
|
|
|
|
<div
|
|
|
|
|
key={file.id}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border"
|
2026-05-21 09:35:42 -04:00
|
|
|
style={{ backgroundColor: 'var(--surface-elevated)', borderColor: 'var(--interactive-border)' }}
|
2026-01-02 14:18:40 +02:00
|
|
|
>
|
|
|
|
|
{file.mimeType.startsWith('image/') ? (
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="file-image" className="h-3 w-3 text-muted-foreground" />
|
2026-01-02 14:18:40 +02:00
|
|
|
) : (
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="file" className="h-3 w-3 text-muted-foreground" />
|
2026-01-02 14:18:40 +02:00
|
|
|
)}
|
2026-03-22 22:31:29 +02:00
|
|
|
<span className="truncate max-w-[100px]" title={file.filename}>
|
2026-01-02 14:18:40 +02:00
|
|
|
{file.filename}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => handleRemoveFile(file.id)}
|
2026-03-22 22:31:29 +02:00
|
|
|
className="text-muted-foreground hover:text-destructive"
|
2026-01-02 14:18:40 +02:00
|
|
|
>
|
2026-05-13 13:26:15 +03:00
|
|
|
<Icon name="close" className="h-3 w-3" />
|
2026-01-02 14:18:40 +02:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
{runGroups.map((group, groupIndex) => (
|
|
|
|
|
<RunGroupCard
|
|
|
|
|
key={group.id}
|
|
|
|
|
group={group}
|
|
|
|
|
groupIndex={groupIndex}
|
|
|
|
|
canRemove={runGroups.length > 1}
|
|
|
|
|
onUpdate={updateGroup}
|
|
|
|
|
onRemove={removeGroup}
|
2026-01-01 14:59:51 +02:00
|
|
|
/>
|
2026-05-21 09:35:42 -04:00
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={addGroup}
|
|
|
|
|
className="flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Icon name="add" className="h-3.5 w-3.5" />
|
|
|
|
|
{t('multirun.launcher.groups.addGroup')}
|
|
|
|
|
</button>
|
2026-01-01 14:59:51 +02:00
|
|
|
|
|
|
|
|
{error && (
|
2026-03-22 22:31:29 +02:00
|
|
|
<div
|
|
|
|
|
className="px-3 py-2 rounded-lg typography-meta"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'var(--status-error-background)',
|
|
|
|
|
color: 'var(--status-error)',
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
borderColor: 'var(--status-error-border)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-01 14:59:51 +02:00
|
|
|
{error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-22 22:31:29 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ScrollShadow>
|
|
|
|
|
|
|
|
|
|
<div className="shrink-0 px-4 sm:px-6 py-3">
|
|
|
|
|
<div className="mx-auto w-full max-w-2xl flex items-center justify-end gap-2">
|
2026-05-15 11:35:23 +03:00
|
|
|
{!effectiveIsolateRuns && isGitRepository !== null ? (
|
2026-05-14 23:33:04 +03:00
|
|
|
<div className="mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground">
|
|
|
|
|
<Icon name="information" className="h-3.5 w-3.5 shrink-0" />
|
|
|
|
|
<span className="truncate">{t('multirun.launcher.project.gitRequired')}</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
2026-03-22 22:31:29 +02:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={onCancel}
|
|
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('multirun.launcher.actions.cancel')}
|
2026-03-22 22:31:29 +02:00
|
|
|
</Button>
|
2026-05-21 09:35:42 -04:00
|
|
|
<Button type="submit" size="sm" disabled={!isValid || isSubmitting}>
|
2026-03-22 22:31:29 +02:00
|
|
|
{isSubmitting ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
t('multirun.launcher.actions.creating')
|
2026-03-22 22:31:29 +02:00
|
|
|
) : (
|
2026-05-21 09:35:42 -04:00
|
|
|
<>{t('multirun.launcher.actions.startWithRunCount', { count: totalRunCount })}</>
|
2026-03-22 22:31:29 +02:00
|
|
|
)}
|
|
|
|
|
</Button>
|
2026-01-01 14:59:51 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-22 22:31:29 +02:00
|
|
|
</form>
|
2026-01-01 14:59:51 +02:00
|
|
|
);
|
|
|
|
|
};
|
2026-05-21 09:35:42 -04:00
|
|
|
|
|
|
|
|
interface RunGroupCardProps {
|
|
|
|
|
group: RunGroupState;
|
|
|
|
|
groupIndex: number;
|
|
|
|
|
canRemove: boolean;
|
|
|
|
|
onUpdate: (groupId: string, updates: Partial<RunGroupState>) => void;
|
|
|
|
|
onRemove: (groupId: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RunGroupCard: React.FC<RunGroupCardProps> = ({
|
|
|
|
|
group,
|
|
|
|
|
groupIndex,
|
|
|
|
|
canRemove,
|
|
|
|
|
onUpdate,
|
|
|
|
|
onRemove,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useI18n();
|
2026-05-21 20:00:35 +03:00
|
|
|
const [showFileMention, setShowFileMention] = React.useState(false);
|
|
|
|
|
const [mentionQuery, setMentionQuery] = React.useState('');
|
|
|
|
|
const [showCommandAutocomplete, setShowCommandAutocomplete] = React.useState(false);
|
|
|
|
|
const [commandQuery, setCommandQuery] = React.useState('');
|
|
|
|
|
const [showSnippetAutocomplete, setShowSnippetAutocomplete] = React.useState(false);
|
|
|
|
|
const [snippetQuery, setSnippetQuery] = React.useState('');
|
|
|
|
|
const promptTextareaRef = React.useRef<HTMLTextAreaElement>(null);
|
|
|
|
|
const mentionRef = React.useRef<FileMentionHandle>(null);
|
|
|
|
|
const commandRef = React.useRef<CommandAutocompleteHandle>(null);
|
|
|
|
|
const snippetRef = React.useRef<SnippetAutocompleteHandle>(null);
|
2026-05-21 09:35:42 -04:00
|
|
|
|
|
|
|
|
const handleAddModel = React.useCallback((model: ModelSelectionWithId) => {
|
|
|
|
|
if (group.models.length >= MAX_MODELS_PER_GROUP) return;
|
|
|
|
|
onUpdate(group.id, { models: [...group.models, model] });
|
|
|
|
|
}, [group.id, group.models, onUpdate]);
|
|
|
|
|
|
|
|
|
|
const handleRemoveModel = React.useCallback((index: number) => {
|
|
|
|
|
onUpdate(group.id, { models: group.models.filter((_, i) => i !== index) });
|
|
|
|
|
}, [group.id, group.models, onUpdate]);
|
|
|
|
|
|
|
|
|
|
const handleUpdateModel = React.useCallback((index: number, model: ModelSelectionWithId) => {
|
|
|
|
|
onUpdate(group.id, { models: group.models.map((item, i) => (i === index ? model : item)) });
|
|
|
|
|
}, [group.id, group.models, onUpdate]);
|
|
|
|
|
|
2026-05-21 20:00:35 +03:00
|
|
|
const updateAutocompleteState = React.useCallback((value: string, cursorPosition: number) => {
|
|
|
|
|
if (value.startsWith('/')) {
|
|
|
|
|
const firstSpace = value.indexOf(' ');
|
|
|
|
|
const firstNewline = value.indexOf('\n');
|
|
|
|
|
const commandEnd = Math.min(
|
|
|
|
|
firstSpace === -1 ? value.length : firstSpace,
|
|
|
|
|
firstNewline === -1 ? value.length : firstNewline,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (cursorPosition <= commandEnd && firstSpace === -1) {
|
|
|
|
|
setCommandQuery(value.substring(1, commandEnd));
|
|
|
|
|
setShowCommandAutocomplete(true);
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
setShowSnippetAutocomplete(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setShowCommandAutocomplete(false);
|
|
|
|
|
|
|
|
|
|
const textBeforeCursor = value.substring(0, cursorPosition);
|
|
|
|
|
const lastHashSymbol = textBeforeCursor.lastIndexOf('#');
|
|
|
|
|
if (lastHashSymbol !== -1) {
|
|
|
|
|
const charBefore = lastHashSymbol > 0 ? textBeforeCursor[lastHashSymbol - 1] : null;
|
|
|
|
|
const textAfterHash = textBeforeCursor.substring(lastHashSymbol + 1);
|
|
|
|
|
const isWordBoundary = !charBefore || /\s/.test(charBefore);
|
|
|
|
|
if (isWordBoundary && !textAfterHash.includes(' ') && !textAfterHash.includes('\n')) {
|
|
|
|
|
setSnippetQuery(textAfterHash);
|
|
|
|
|
setShowSnippetAutocomplete(true);
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setShowSnippetAutocomplete(false);
|
|
|
|
|
|
|
|
|
|
const lastAtSymbol = textBeforeCursor.lastIndexOf('@');
|
|
|
|
|
if (lastAtSymbol !== -1) {
|
|
|
|
|
const charBefore = lastAtSymbol > 0 ? textBeforeCursor[lastAtSymbol - 1] : null;
|
|
|
|
|
const textAfterAt = textBeforeCursor.substring(lastAtSymbol + 1);
|
|
|
|
|
const isWordBoundary = !charBefore || /\s/.test(charBefore);
|
|
|
|
|
if (isWordBoundary && !textAfterAt.includes(' ') && !textAfterAt.includes('\n')) {
|
|
|
|
|
setMentionQuery(textAfterAt);
|
|
|
|
|
setShowFileMention(true);
|
|
|
|
|
} else {
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const setPrompt = React.useCallback((value: string) => {
|
|
|
|
|
onUpdate(group.id, { prompt: value });
|
|
|
|
|
}, [group.id, onUpdate]);
|
|
|
|
|
|
|
|
|
|
const handleFileSelect = React.useCallback((file: { name: string; path: string; relativePath?: string }) => {
|
|
|
|
|
const prompt = group.prompt;
|
|
|
|
|
const textarea = promptTextareaRef.current;
|
|
|
|
|
const cursorPosition = textarea?.selectionStart ?? prompt.length;
|
|
|
|
|
const textBeforeCursor = prompt.substring(0, cursorPosition);
|
|
|
|
|
const lastAtSymbol = textBeforeCursor.lastIndexOf('@');
|
|
|
|
|
const mentionPath = (file.relativePath && file.relativePath.trim().length > 0)
|
|
|
|
|
? file.relativePath.trim()
|
|
|
|
|
: (file.path || file.name);
|
|
|
|
|
|
|
|
|
|
const startIndex = lastAtSymbol !== -1 ? lastAtSymbol : cursorPosition;
|
|
|
|
|
const nextPrompt = `${prompt.substring(0, startIndex)}@${mentionPath} ${prompt.substring(cursorPosition)}`;
|
|
|
|
|
const nextCursor = startIndex + mentionPath.length + 2;
|
|
|
|
|
|
|
|
|
|
setPrompt(nextPrompt);
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
setMentionQuery('');
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
const currentTextarea = promptTextareaRef.current;
|
|
|
|
|
if (currentTextarea) {
|
|
|
|
|
currentTextarea.selectionStart = nextCursor;
|
|
|
|
|
currentTextarea.selectionEnd = nextCursor;
|
|
|
|
|
currentTextarea.focus();
|
|
|
|
|
}
|
|
|
|
|
updateAutocompleteState(nextPrompt, nextCursor);
|
|
|
|
|
});
|
|
|
|
|
}, [group.prompt, setPrompt, updateAutocompleteState]);
|
|
|
|
|
|
|
|
|
|
const handleAgentSelect = React.useCallback((agentName: string) => {
|
|
|
|
|
const prompt = group.prompt;
|
|
|
|
|
const textarea = promptTextareaRef.current;
|
|
|
|
|
const cursorPosition = textarea?.selectionStart ?? prompt.length;
|
|
|
|
|
const textBeforeCursor = prompt.substring(0, cursorPosition);
|
|
|
|
|
const lastAtSymbol = textBeforeCursor.lastIndexOf('@');
|
|
|
|
|
const startIndex = lastAtSymbol !== -1 ? lastAtSymbol : cursorPosition;
|
|
|
|
|
const nextPrompt = `${prompt.substring(0, startIndex)}@${agentName} ${prompt.substring(cursorPosition)}`;
|
|
|
|
|
const nextCursor = startIndex + agentName.length + 2;
|
|
|
|
|
|
|
|
|
|
setPrompt(nextPrompt);
|
|
|
|
|
setShowFileMention(false);
|
|
|
|
|
setMentionQuery('');
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
const currentTextarea = promptTextareaRef.current;
|
|
|
|
|
if (currentTextarea) {
|
|
|
|
|
currentTextarea.selectionStart = nextCursor;
|
|
|
|
|
currentTextarea.selectionEnd = nextCursor;
|
|
|
|
|
currentTextarea.focus();
|
|
|
|
|
}
|
|
|
|
|
updateAutocompleteState(nextPrompt, nextCursor);
|
|
|
|
|
});
|
|
|
|
|
}, [group.prompt, setPrompt, updateAutocompleteState]);
|
|
|
|
|
|
|
|
|
|
const handleCommandSelect = React.useCallback((command: CommandInfo) => {
|
|
|
|
|
const nextPrompt = `/${command.name} `;
|
|
|
|
|
setPrompt(nextPrompt);
|
|
|
|
|
setShowCommandAutocomplete(false);
|
|
|
|
|
setCommandQuery('');
|
|
|
|
|
setShowSnippetAutocomplete(false);
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
const currentTextarea = promptTextareaRef.current;
|
|
|
|
|
if (currentTextarea) {
|
|
|
|
|
currentTextarea.focus();
|
|
|
|
|
currentTextarea.selectionStart = currentTextarea.value.length;
|
|
|
|
|
currentTextarea.selectionEnd = currentTextarea.value.length;
|
|
|
|
|
}
|
|
|
|
|
updateAutocompleteState(nextPrompt, nextPrompt.length);
|
|
|
|
|
});
|
|
|
|
|
}, [setPrompt, updateAutocompleteState]);
|
|
|
|
|
|
|
|
|
|
const handleSnippetSelect = React.useCallback((_snippet: unknown, trigger: string) => {
|
|
|
|
|
const prompt = group.prompt;
|
|
|
|
|
const textarea = promptTextareaRef.current;
|
|
|
|
|
const cursorPosition = textarea?.selectionStart ?? prompt.length;
|
|
|
|
|
const textBeforeCursor = prompt.substring(0, cursorPosition);
|
|
|
|
|
const lastHashSymbol = textBeforeCursor.lastIndexOf('#');
|
|
|
|
|
const startIndex = lastHashSymbol !== -1 ? lastHashSymbol : cursorPosition;
|
|
|
|
|
const nextPrompt = `${prompt.substring(0, startIndex)}#${trigger} ${prompt.substring(cursorPosition)}`;
|
|
|
|
|
const nextCursor = startIndex + trigger.length + 2;
|
|
|
|
|
setPrompt(nextPrompt);
|
|
|
|
|
setShowSnippetAutocomplete(false);
|
|
|
|
|
setSnippetQuery('');
|
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
|
const currentTextarea = promptTextareaRef.current;
|
|
|
|
|
if (currentTextarea) {
|
|
|
|
|
currentTextarea.selectionStart = nextCursor;
|
|
|
|
|
currentTextarea.selectionEnd = nextCursor;
|
|
|
|
|
currentTextarea.focus();
|
|
|
|
|
}
|
|
|
|
|
updateAutocompleteState(nextPrompt, nextCursor);
|
|
|
|
|
});
|
|
|
|
|
}, [group.prompt, setPrompt, updateAutocompleteState]);
|
|
|
|
|
|
|
|
|
|
const handlePromptKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
|
|
if (showCommandAutocomplete && commandRef.current) {
|
|
|
|
|
if (event.key === 'Enter' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Escape' || event.key === 'Tab') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
commandRef.current.handleKeyDown(event.key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showFileMention && mentionRef.current) {
|
|
|
|
|
if (event.key === 'Enter' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Escape' || event.key === 'Tab') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
mentionRef.current.handleKeyDown(event.key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showSnippetAutocomplete && snippetRef.current) {
|
|
|
|
|
if (event.key === 'Enter' || event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'Escape' || event.key === 'Tab') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
snippetRef.current.handleKeyDown(event.key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [showCommandAutocomplete, showFileMention, showSnippetAutocomplete]);
|
|
|
|
|
|
2026-05-21 09:35:42 -04:00
|
|
|
return (
|
|
|
|
|
<div className="rounded-lg border border-border p-3 space-y-3">
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<span className="typography-meta font-medium text-foreground">
|
|
|
|
|
{t('multirun.launcher.groups.groupLabel', { index: groupIndex + 1 })}
|
|
|
|
|
</span>
|
|
|
|
|
{canRemove && (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => onRemove(group.id)}
|
|
|
|
|
className="inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
|
|
|
|
aria-label={t('multirun.launcher.groups.removeGroup')}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="close" className="h-3.5 w-3.5" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<FieldLabel required>{t('multirun.launcher.groups.prompt.label')}</FieldLabel>
|
2026-05-21 20:00:35 +03:00
|
|
|
<div className="relative">
|
|
|
|
|
<Textarea
|
|
|
|
|
ref={promptTextareaRef}
|
|
|
|
|
value={group.prompt}
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
const nextPrompt = event.target.value;
|
|
|
|
|
setPrompt(nextPrompt);
|
|
|
|
|
const cursorPosition = event.target.selectionStart ?? nextPrompt.length;
|
|
|
|
|
updateAutocompleteState(nextPrompt, cursorPosition);
|
|
|
|
|
}}
|
|
|
|
|
onKeyDown={handlePromptKeyDown}
|
|
|
|
|
placeholder={t('multirun.launcher.groups.prompt.placeholder')}
|
|
|
|
|
className="typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content"
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{showCommandAutocomplete ? (
|
|
|
|
|
<CommandAutocomplete
|
|
|
|
|
ref={commandRef}
|
|
|
|
|
searchQuery={commandQuery}
|
|
|
|
|
onCommandSelect={handleCommandSelect}
|
|
|
|
|
onClose={() => setShowCommandAutocomplete(false)}
|
|
|
|
|
style={{ left: 0, top: 'auto', bottom: 'calc(100% + 6px)', marginBottom: 0, maxWidth: '100%' }}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{showFileMention ? (
|
|
|
|
|
<FileMentionAutocomplete
|
|
|
|
|
ref={mentionRef}
|
|
|
|
|
searchQuery={mentionQuery}
|
|
|
|
|
onFileSelect={handleFileSelect}
|
|
|
|
|
onAgentSelect={handleAgentSelect}
|
|
|
|
|
onClose={() => setShowFileMention(false)}
|
|
|
|
|
style={{ left: 0, top: 'auto', bottom: 'calc(100% + 6px)', marginBottom: 0, maxWidth: '100%' }}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{showSnippetAutocomplete ? (
|
|
|
|
|
<SnippetAutocomplete
|
|
|
|
|
ref={snippetRef}
|
|
|
|
|
searchQuery={snippetQuery}
|
|
|
|
|
onSnippetSelect={handleSnippetSelect}
|
|
|
|
|
onClose={() => setShowSnippetAutocomplete(false)}
|
|
|
|
|
style={{ left: 0, top: 'auto', bottom: 'calc(100% + 6px)', marginBottom: 0, maxWidth: '100%' }}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
2026-05-21 09:35:42 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<FieldLabel
|
|
|
|
|
required
|
|
|
|
|
info={<InfoTip>{t('multirun.launcher.models.info', { max: MAX_MODELS_PER_GROUP })}</InfoTip>}
|
|
|
|
|
>
|
|
|
|
|
{t('multirun.launcher.models.label')}
|
|
|
|
|
</FieldLabel>
|
|
|
|
|
<ModelMultiSelect
|
|
|
|
|
selectedModels={group.models}
|
|
|
|
|
onAdd={handleAddModel}
|
|
|
|
|
onRemove={handleRemoveModel}
|
|
|
|
|
onUpdate={handleUpdateModel}
|
|
|
|
|
minModels={1}
|
|
|
|
|
maxModels={MAX_MODELS_PER_GROUP}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|