Skip to content
TypeScript

perf(web): typing in form dialogs no longer re-renders the dialog chrome (#20842)

Julius Marminge812b7006f8a1
diff --git a/apps/web/src/components/chat/ProposedPlanCard.tsx b/apps/web/src/components/chat/ProposedPlanCard.tsx
index 534c3ba93f8..4edbd103e3d 100644
--- a/apps/web/src/components/chat/ProposedPlanCard.tsx
+++ b/apps/web/src/components/chat/ProposedPlanCard.tsx
@@ -56,7 +56,8 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
const [expanded, setExpanded] = useState(false);
const canWriteFiles = useEnvironmentScope(environmentId, AuthFilesystemWriteScope);
const [isSaveDialogOpen, setIsSaveDialogOpen] = useState(false);
- const [savePath, setSavePath] = useState("");
+ // The path last submitted, so reopening the dialog offers it again.
+ const [lastSavePath, setLastSavePath] = useState("");
const [isSavingToWorkspace, setIsSavingToWorkspace] = useState(false);
const writeProjectFile = useAtomCommand(projectEnvironment.writeFile, {
reportFailure: false,
@@ -73,7 +74,6 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
);
},
});
- const savePathInputId = useId();
const title = proposedPlanTitle(planMarkdown) ?? "Proposed plan";
const lineCount = planMarkdown.split("\n").length;
const canCollapse = planMarkdown.length > 900 || lineCount > 20;
@@ -109,11 +109,10 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
);
return;
}
- setSavePath((existing) => (existing.length > 0 ? existing : downloadFilename));
setIsSaveDialogOpen(true);
};
- const handleSaveToWorkspace = () => {
+ const handleSaveToWorkspace = (savePath: string) => {
const relativePath = savePath.trim();
if (!workspaceRoot || !readEnvironmentScope(environmentId, AuthFilesystemWriteScope)) {
return;
@@ -126,6 +125,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
return;
}
+ setLastSavePath(savePath);
setIsSavingToWorkspace(true);
void (async () => {
const result = await writeProjectFile({
@@ -241,45 +241,71 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
}
}}
>
+ {/* The form owns the path so a keystroke re-renders it, not the dialog chrome. */}
<DialogPopup className="max-w-xl">
- <DialogHeader>
- <DialogTitle>Save plan to workspace</DialogTitle>
- <DialogDescription>
- Enter a path relative to <code>{workspaceRoot ?? "the workspace"}</code>.
- </DialogDescription>
- </DialogHeader>
- <DialogPanel>
- <label htmlFor={savePathInputId} className="grid gap-1.5">
- <span className="text-xs font-medium text-foreground">Workspace path</span>
- <Input
- id={savePathInputId}
- value={savePath}
- onChange={(event) => setSavePath(event.target.value)}
- placeholder={downloadFilename}
- spellCheck={false}
- disabled={isSavingToWorkspace}
- />
- </label>
- </DialogPanel>
- <DialogFooter>
- <Button
- variant="outline"
- size="sm"
- onClick={() => setIsSaveDialogOpen(false)}
- disabled={isSavingToWorkspace}
- >
- Cancel
- </Button>
- <Button
- size="sm"
- onClick={() => void handleSaveToWorkspace()}
- disabled={!canWriteFiles || isSavingToWorkspace}
- >
- {isSavingToWorkspace ? "Saving..." : "Save"}
- </Button>
- </DialogFooter>
+ <SavePlanToWorkspaceForm
+ initialPath={lastSavePath || downloadFilename}
+ placeholder={downloadFilename}
+ workspaceRoot={workspaceRoot}
+ canWriteFiles={canWriteFiles}
+ saving={isSavingToWorkspace}
+ onCancel={() => setIsSaveDialogOpen(false)}
+ onSave={handleSaveToWorkspace}
+ />
</DialogPopup>
</Dialog>
</div>
);
});
+
+function SavePlanToWorkspaceForm({
+ initialPath,
+ placeholder,
+ workspaceRoot,
+ canWriteFiles,
+ saving,
+ onCancel,
+ onSave,
+}: {
+ initialPath: string;
+ placeholder: string;
+ workspaceRoot: string | undefined;
+ canWriteFiles: boolean;
+ saving: boolean;
+ onCancel: () => void;
+ onSave: (path: string) => void;
+}) {
+ const [savePath, setSavePath] = useState(initialPath);
+ const savePathInputId = useId();
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Save plan to workspace</DialogTitle>
+ <DialogDescription>
+ Enter a path relative to <code>{workspaceRoot ?? "the workspace"}</code>.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogPanel>
+ <label htmlFor={savePathInputId} className="grid gap-1.5">
+ <span className="text-xs font-medium text-foreground">Workspace path</span>
+ <Input
+ id={savePathInputId}
+ value={savePath}
+ onChange={(event) => setSavePath(event.target.value)}
+ placeholder={placeholder}
+ spellCheck={false}
+ disabled={saving}
+ />
+ </label>
+ </DialogPanel>
+ <DialogFooter>
+ <Button variant="outline" size="sm" onClick={onCancel} disabled={saving}>
+ Cancel
+ </Button>
+ <Button size="sm" onClick={() => onSave(savePath)} disabled={!canWriteFiles || saving}>
+ {saving ? "Saving..." : "Save"}
+ </Button>
+ </DialogFooter>
+ </>
+ );
+}
diff --git a/apps/web/src/components/projectScriptEditor.tsx b/apps/web/src/components/projectScriptEditor.tsx
index cc23d326916..3f58813ce93 100644
--- a/apps/web/src/components/projectScriptEditor.tsx
+++ b/apps/web/src/components/projectScriptEditor.tsx
@@ -156,6 +156,98 @@ export function ProjectScriptEditorDialog({
) => Promise<ProjectScriptActionResult>;
onDelete: (scriptId: string) => void;
onClose: () => void;
+}) {
+ const canEditActions = useEnvironmentScope(environmentId, editScope);
+ const [validationError, setValidationError] = useState<string | null>(null);
+ const [deleteConfirmOpen, setDeleteConfirmOpen] = useComposerMenuState(!canEditActions);
+ const [deleteName, setDeleteName] = useState("");
+ const [errorRequest, setErrorRequest] = useState<ProjectScriptEditorRequest | null>(null);
+ if (request !== errorRequest) {
+ setErrorRequest(request);
+ if (request) setValidationError(request.error ?? null);
+ }
+
+ return (
+ <>
+ <Dialog
+ open={request !== null}
+ onOpenChange={(open) => {
+ if (!open) onClose();
+ }}
+ >
+ {/* The form owns its fields so a keystroke re-renders it, not the dialog chrome. */}
+ <DialogPopup>
+ <ProjectScriptEditorForm
+ environmentId={environmentId}
+ editScope={editScope}
+ request={request}
+ scripts={scripts}
+ validationError={validationError}
+ onValidationError={setValidationError}
+ onSubmit={onSubmit}
+ onRequestDelete={(name) => {
+ setDeleteName(name);
+ setDeleteConfirmOpen(true);
+ }}
+ onClose={onClose}
+ />
+ </DialogPopup>
+ </Dialog>
+
+ <AlertDialog open={deleteConfirmOpen && canEditActions} onOpenChange={setDeleteConfirmOpen}>
+ <AlertDialogPopup>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Delete action "{deleteName}"?</AlertDialogTitle>
+ <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
+ <Button
+ variant="destructive"
+ disabled={!canEditActions}
+ onClick={() => {
+ if (!request?.scriptId) return;
+ if (!readEnvironmentScope(environmentId, editScope)) {
+ setValidationError("This connection cannot change project actions.");
+ return;
+ }
+ setDeleteConfirmOpen(false);
+ onClose();
+ onDelete(request.scriptId);
+ }}
+ >
+ Delete action
+ </Button>
+ </AlertDialogFooter>
+ </AlertDialogPopup>
+ </AlertDialog>
+ </>
+ );
+}
+
+function ProjectScriptEditorForm({
+ environmentId,
+ editScope,
+ request,
+ scripts,
+ validationError,
+ onValidationError: setValidationError,
+ onSubmit,
+ onRequestDelete,
+ onClose,
+}: {
+ environmentId: EnvironmentId;
+ editScope: typeof AuthOrchestrationOperateScope | typeof AuthSettingsWriteScope;
+ request: ProjectScriptEditorRequest | null;
+ scripts: ReadonlyArray<ProjectScript>;
+ validationError: string | null;
+ onValidationError: (error: string | null) => void;
+ onSubmit: (
+ scriptId: string | null,
+ input: NewProjectScriptInput,
+ ) => Promise<ProjectScriptActionResult>;
+ onRequestDelete: (name: string) => void;
+ onClose: () => void;
}) {
const canEditActions = useEnvironmentScope(environmentId, editScope);
const canWriteSettings = useEnvironmentScope(environmentId, AuthSettingsWriteScope);
@@ -170,12 +262,9 @@ export function ProjectScriptEditorDialog({
const [keybinding, setKeybinding] = useState("");
const [previewUrl, setPreviewUrl] = useState("");
const [autoOpenPreview, setAutoOpenPreview] = useState(false);
- const [validationError, setValidationError] = useState<string | null>(null);
- const [deleteConfirmOpen, setDeleteConfirmOpen] = useComposerMenuState(!canEditActions);
const [savingRequest, setSavingRequest] = useState<ProjectScriptEditorRequest | null>(null);
const pendingSubmissionRef = useRef<{ request: ProjectScriptEditorRequest } | null>(null);
- const isOpen = request !== null;
const isEditing = request?.scriptId != null;
const isSaving = request !== null && savingRequest === request;
@@ -202,7 +291,6 @@ export function ProjectScriptEditorDialog({
setKeybinding(request.initial.keybinding ?? "");
setPreviewUrl(request.initial.previewUrl ?? "");
setAutoOpenPreview(request.initial.autoOpenPreview);
- setValidationError(request.error ?? null);
setSavingRequest(null);
}
}
@@ -314,202 +402,163 @@ export function ProjectScriptEditorDialog({
return (
<>
- <Dialog
- open={isOpen}
- onOpenChange={(open) => {
- if (!open) {
- close();
- }
- }}
- >
- <DialogPopup>
- <DialogHeader>
- <DialogTitle>{isEditing ? "Edit Action" : "Add Action"}</DialogTitle>
- <DialogDescription>
- Actions are project-scoped commands you can run from the top bar or keybindings.
- </DialogDescription>
- </DialogHeader>
- <DialogPanel>
- <form id={formId} onSubmit={submit}>
- <fieldset className="space-y-4" disabled={isSaving || !canEditActions}>
- <div className="space-y-1.5">
- <Label htmlFor="script-name">Name</Label>
- <div className="flex items-center gap-2">
- <Popover onOpenChange={setIconPickerOpen} open={iconPickerOpen}>
- <PopoverTrigger
- render={
- <Button
+ <DialogHeader>
+ <DialogTitle>{isEditing ? "Edit Action" : "Add Action"}</DialogTitle>
+ <DialogDescription>
+ Actions are project-scoped commands you can run from the top bar or keybindings.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogPanel>
+ <form id={formId} onSubmit={submit}>
+ <fieldset className="space-y-4" disabled={isSaving || !canEditActions}>
+ <div className="space-y-1.5">
+ <Label htmlFor="script-name">Name</Label>
+ <div className="flex items-center gap-2">
+ <Popover onOpenChange={setIconPickerOpen} open={iconPickerOpen}>
+ <PopoverTrigger
+ render={
+ <Button
+ type="button"
+ variant="outline"
+ className="size-9 shrink-0"
+ aria-label="Choose icon"
+ />
+ }
+ >
+ <ScriptIcon icon={icon} className="size-4.5" />
+ </PopoverTrigger>
+ <PopoverPopup align="start">
+ <div className="grid grid-cols-3 gap-2">
+ {SCRIPT_ICONS.map((entry) => {
+ const isSelected = entry.id === icon;
+ return (
+ <button
+ key={entry.id}
type="button"
- variant="outline"
- className="size-9 shrink-0"
- aria-label="Choose icon"
- />
- }
- >
- <ScriptIcon icon={icon} className="size-4.5" />
- </PopoverTrigger>
- <PopoverPopup align="start">
- <div className="grid grid-cols-3 gap-2">
- {SCRIPT_ICONS.map((entry) => {
- const isSelected = entry.id === icon;
- return (
- <button
- key={entry.id}
- type="button"
- className={`relative flex flex-col items-center gap-2 rounded-md border px-2 py-2 text-xs dark:border-transparent ${
- isSelected
- ? "border-primary/70 bg-primary/10 ring-inset dark:ring-1 dark:ring-primary/30"
- : "border-border/70 hover:bg-accent/60 dark:bg-white/[0.035]"
- }`}
- onClick={() => {
- setIcon(entry.id);
- setIconPickerOpen(false);
- }}
- >
- <ScriptIcon icon={entry.id} className="size-4" />
- <span>{entry.label}</span>
- </button>
- );
- })}
- </div>
- </PopoverPopup>
- </Popover>
- <Input
- id="script-name"
- autoFocus
- placeholder="Test"
- value={name}
- onChange={(event) => setName(event.target.value)}
- />
- </div>
- </div>
- <div className="space-y-1.5">
- <Label htmlFor="script-keybinding">Keybinding</Label>
- <Input
- disabled={!canWriteSettings}
- id="script-keybinding"
- placeholder="Press shortcut"
- value={keybinding}
- readOnly
- onKeyDown={captureKeybinding}
- />
- <p className="text-xs text-muted-foreground">
- Press a shortcut. Use <code>Backspace</code> to clear. Shortcuts are
- environment-wide. Projects using the same action share its shortcut.
- </p>
- </div>
- <div className="space-y-1.5">
- <Label htmlFor="script-command">Command</Label>
- <Textarea
- id="script-command"
- placeholder="bun test"
- value={command}
- onChange={(event) => setCommand(event.target.value)}
- />
- </div>
- <div className="space-y-1.5">
- <Label htmlFor="script-preview-url">Preview URL (optional)</Label>
- <Input
- id="script-preview-url"
- placeholder="http://localhost:5173"
- value={previewUrl}
- onChange={(event) => setPreviewUrl(event.target.value)}
- />
- <p className="text-xs text-muted-foreground">
- Open this URL in the in-app preview when this action runs.
- </p>
- </div>
- <label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
- <span>Run automatically on worktree creation</span>
- <Switch
- checked={runOnWorktreeCreate}
- onCheckedChange={(checked) => setRunOnWorktreeCreate(Boolean(checked))}
- />
- </label>
- <label
- className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
- runOnWorktreeCreate ? "" : "opacity-60"
- }`}
- >
- <span>Wait for it to finish before the agent starts</span>
- <Switch
- checked={waitForSetup}
- disabled={!runOnWorktreeCreate}
- onCheckedChange={(checked) => setWaitForSetup(Boolean(checked))}
- />
- </label>
- <label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
- <span>Run in the thread's worktree when the thread settles</span>
- <Switch
- checked={runOnSettle}
- onCheckedChange={(checked) => setRunOnSettle(Boolean(checked))}
- />
- </label>
- <label
- className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
- previewUrl.trim().length === 0 ? "opacity-60" : ""
- }`}
- >
- <span>Open preview automatically when this action runs</span>
- <Switch
- checked={autoOpenPreview}
- disabled={previewUrl.trim().length === 0}
- onCheckedChange={(checked) => setAutoOpenPreview(Boolean(checked))}
- />
- </label>
- {validationError && <p className="text-sm text-destructive">{validationError}</p>}
- </fieldset>
- </form>
- </DialogPanel>
- <DialogFooter variant="bare">
- {isEditing && (
- <Button
- type="button"
- variant="destructive-outline"
- className="mr-auto"
- disabled={isSaving || !canEditActions}
- onClick={() => setDeleteConfirmOpen(true)}
- >
- Delete
- </Button>
- )}
- <Button type="button" variant="outline" onClick={close}>
- Cancel
- </Button>
- <Button form={formId} type="submit" disabled={isSaving || !canEditActions}>
- {isSaving ? "Saving…" : isEditing ? "Save changes" : "Save action"}
- </Button>
- </DialogFooter>
- </DialogPopup>
- </Dialog>
-
- <AlertDialog open={deleteConfirmOpen && canEditActions} onOpenChange={setDeleteConfirmOpen}>
- <AlertDialogPopup>
- <AlertDialogHeader>
- <AlertDialogTitle>Delete action "{name}"?</AlertDialogTitle>
- <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
- <Button
- variant="destructive"
- disabled={isSaving || !canEditActions}
- onClick={() => {
- if (!request?.scriptId) return;
- if (!readEnvironmentScope(environmentId, editScope)) {
- setValidationError("This connection cannot change project actions.");
- return;
- }
- setDeleteConfirmOpen(false);
- close();
- onDelete(request.scriptId);
- }}
+ className={`relative flex flex-col items-center gap-2 rounded-md border px-2 py-2 text-xs dark:border-transparent ${
+ isSelected
+ ? "border-primary/70 bg-primary/10 ring-inset dark:ring-1 dark:ring-primary/30"
+ : "border-border/70 hover:bg-accent/60 dark:bg-white/[0.035]"
+ }`}
+ onClick={() => {
+ setIcon(entry.id);
+ setIconPickerOpen(false);
+ }}
+ >
+ <ScriptIcon icon={entry.id} className="size-4" />
+ <span>{entry.label}</span>
+ </button>
+ );
+ })}
+ </div>
+ </PopoverPopup>
+ </Popover>
+ <Input
+ id="script-name"
+ autoFocus
+ placeholder="Test"
+ value={name}
+ onChange={(event) => setName(event.target.value)}
+ />
+ </div>
+ </div>
+ <div className="space-y-1.5">
+ <Label htmlFor="script-keybinding">Keybinding</Label>
+ <Input
+ disabled={!canWriteSettings}
+ id="script-keybinding"
+ placeholder="Press shortcut"
+ value={keybinding}
+ readOnly
+ onKeyDown={captureKeybinding}
+ />
+ <p className="text-xs text-muted-foreground">
+ Press a shortcut. Use <code>Backspace</code> to clear. Shortcuts are
+ environment-wide. Projects using the same action share its shortcut.
+ </p>
+ </div>
+ <div className="space-y-1.5">
+ <Label htmlFor="script-command">Command</Label>
+ <Textarea
+ id="script-command"
+ placeholder="bun test"
+ value={command}
+ onChange={(event) => setCommand(event.target.value)}
+ />
+ </div>
+ <div className="space-y-1.5">
+ <Label htmlFor="script-preview-url">Preview URL (optional)</Label>
+ <Input
+ id="script-preview-url"
+ placeholder="http://localhost:5173"
+ value={previewUrl}
+ onChange={(event) => setPreviewUrl(event.target.value)}
+ />
+ <p className="text-xs text-muted-foreground">
+ Open this URL in the in-app preview when this action runs.
+ </p>
+ </div>
+ <label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
+ <span>Run automatically on worktree creation</span>
+ <Switch
+ checked={runOnWorktreeCreate}
+ onCheckedChange={(checked) => setRunOnWorktreeCreate(Boolean(checked))}
+ />
+ </label>
+ <label
+ className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
+ runOnWorktreeCreate ? "" : "opacity-60"
+ }`}
>
- Delete action
- </Button>
- </AlertDialogFooter>
- </AlertDialogPopup>
- </AlertDialog>
+ <span>Wait for it to finish before the agent starts</span>
+ <Switch
+ checked={waitForSetup}
+ disabled={!runOnWorktreeCreate}
+ onCheckedChange={(checked) => setWaitForSetup(Boolean(checked))}
+ />
+ </label>
+ <label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
+ <span>Run in the thread's worktree when the thread settles</span>
+ <Switch
+ checked={runOnSettle}
+ onCheckedChange={(checked) => setRunOnSettle(Boolean(checked))}
+ />
+ </label>
+ <label
+ className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
+ previewUrl.trim().length === 0 ? "opacity-60" : ""
+ }`}
+ >
+ <span>Open preview automatically when this action runs</span>
+ <Switch
+ checked={autoOpenPreview}
+ disabled={previewUrl.trim().length === 0}
+ onCheckedChange={(checked) => setAutoOpenPreview(Boolean(checked))}
+ />
+ </label>
+ {validationError && <p className="text-sm text-destructive">{validationError}</p>}
+ </fieldset>
+ </form>
+ </DialogPanel>
+ <DialogFooter variant="bare">
+ {isEditing && (
+ <Button
+ type="button"
+ variant="destructive-outline"
+ className="mr-auto"
+ disabled={isSaving || !canEditActions}
+ onClick={() => onRequestDelete(name)}
+ >
+ Delete
+ </Button>
+ )}
+ <Button type="button" variant="outline" onClick={close}>
+ Cancel
+ </Button>
+ <Button form={formId} type="submit" disabled={isSaving || !canEditActions}>
+ {isSaving ? "Saving…" : isEditing ? "Save changes" : "Save action"}
+ </Button>
+ </DialogFooter>
</>
);
}
diff --git a/apps/web/src/components/settings/DeviceHostEditor.tsx b/apps/web/src/components/settings/DeviceHostEditor.tsx
index a93699752cb..8d05040e9ea 100644
--- a/apps/web/src/components/settings/DeviceHostEditor.tsx
+++ b/apps/web/src/components/settings/DeviceHostEditor.tsx
@@ -37,6 +37,43 @@ export function DeviceHostEditor({
busy: boolean;
onSave: (host: SshDeviceHostConfig) => void;
onClose: () => void;
+}) {
+ return (
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open && !busy) onClose();
+ }}
+ >
+ {/* The form owns the draft so a keystroke re-renders it, not the dialog chrome. */}
+ <DialogPopup showCloseButton={!busy}>
+ <DeviceHostEditorForm
+ host={host}
+ isNew={isNew}
+ targets={targets}
+ busy={busy}
+ onSave={onSave}
+ onClose={onClose}
+ />
+ </DialogPopup>
+ </Dialog>
+ );
+}
+
+function DeviceHostEditorForm({
+ host,
+ isNew,
+ targets,
+ busy,
+ onSave,
+ onClose,
+}: {
+ host: SshDeviceHostConfig;
+ isNew: boolean;
+ targets: ReadonlyArray<DeviceHostCheckTarget>;
+ busy: boolean;
+ onSave: (host: SshDeviceHostConfig) => void;
+ onClose: () => void;
}) {
const [draft, setDraft] = useState(host);
const [expandedChecks, setExpandedChecks] = useState<{ key: string; open: boolean } | null>(null);
@@ -58,199 +95,195 @@ export function DeviceHostEditor({
: "Connection checks passed"
: "Check access before saving";
return (
- <Dialog
- open
- onOpenChange={(open) => {
- if (!open && !busy) onClose();
+ <form
+ className="flex min-h-0 flex-col"
+ onSubmit={(event) => {
+ event.preventDefault();
+ if (Option.isSome(input) && draft.label.trim() && !busy && !checking) onSave(input.value);
}}
>
- <DialogPopup
- showCloseButton={!busy}
- render={
- <form
- onSubmit={(event) => {
- event.preventDefault();
- if (Option.isSome(input) && draft.label.trim() && !busy && !checking)
- onSave(input.value);
+ <DialogHeader>
+ <DialogTitle>{isNew ? "Add device host" : "Edit device host"}</DialogTitle>
+ <DialogDescription>
+ {targets.length === 1
+ ? `Connect from ${targets[0]?.label}.`
+ : `Connect from ${targets.length} selected environments.`}{" "}
+ Hosts on the same machine are skipped.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogPanel>
+ <label className="block space-y-1.5 text-sm">
+ <span>Name</span>
+ <Input
+ autoFocus
+ required
+ value={draft.label}
+ disabled={busy}
+ onChange={(event) => {
+ const label = event.target.value;
+ setDraft((current) => ({ ...current, label }));
}}
+ placeholder="Mac mini"
/>
- }
- >
- <DialogHeader>
- <DialogTitle>{isNew ? "Add device host" : "Edit device host"}</DialogTitle>
- <DialogDescription>
- {targets.length === 1
- ? `Connect from ${targets[0]?.label}.`
- : `Connect from ${targets.length} selected environments.`}{" "}
- Hosts on the same machine are skipped.
- </DialogDescription>
- </DialogHeader>
- <DialogPanel>
- <label className="block space-y-1.5 text-sm">
- <span>Name</span>
- <Input
- autoFocus
- required
- value={draft.label}
- disabled={busy}
- onChange={(event) => setDraft({ ...draft, label: event.target.value })}
- placeholder="Mac mini"
- />
- </label>
- <label className="block space-y-1.5 text-sm">
- <span>SSH target</span>
- <Input
- required
- value={draft.target}
- disabled={busy}
- onChange={(event) => setDraft({ ...draft, target: event.target.value })}
- placeholder="user@host or SSH alias"
- />
- </label>
- <details
- open={host.port !== undefined || host.identityFile !== undefined || undefined}
- className="text-sm"
- >
- <summary className="cursor-pointer text-muted-foreground">SSH options</summary>
- <div className="mt-3 grid grid-cols-[minmax(0,1fr)_7rem] gap-3">
- <label className="block space-y-1.5">
- <span>Identity file</span>
- <Input
- value={draft.identityFile ?? ""}
- disabled={busy}
- onChange={(event) => {
- const { identityFile: _, ...rest } = draft;
- setDraft(
- event.target.value ? { ...rest, identityFile: event.target.value } : rest,
- );
- }}
- placeholder="SSH config default"
- />
- </label>
- <label className="block space-y-1.5">
- <span>Port</span>
- <Input
- type="number"
- min={1}
- max={65535}
- value={draft.port ?? ""}
- disabled={busy}
- onChange={(event) => {
- const { port: _, ...rest } = draft;
- setDraft(
- event.target.value ? { ...rest, port: Number(event.target.value) } : rest,
- );
- }}
- placeholder="Default"
- />
- </label>
- </div>
- <p className="mt-2 text-xs text-muted-foreground">
- Optional. Resolved separately on each environment.
- </p>
- </details>
- <Collapsible
- open={checksOpen}
- onOpenChange={(open) => setExpandedChecks({ key: connectionKey, open })}
- render={<div className="rounded-lg border border-border/60" />}
- >
- <div className="flex items-center justify-between gap-3 px-3 py-2.5">
- {targets.length === 1 ? (
- <p role="status" className="text-xs text-muted-foreground">
- {checkSummary}
- </p>
- ) : (
- <div className="min-w-0 text-xs [--inline-button-white-space:normal]">
- <CollapsibleTrigger
- disabled={!results}
- aria-label={`${checkSummary}. Per-machine results`}
- render={<InlineButton tone="muted" />}
- >
- <span role="status" className="text-left">
- {checkSummary}
- </span>
- {results ? (
- <ChevronDownIcon
- className={`size-3 shrink-0 ${checksOpen ? "rotate-180" : ""}`}
- />
- ) : null}
- </CollapsibleTrigger>
- </div>
- )}
- <Button
- type="button"
- size="sm"
- variant="outline"
- disabled={busy || checking || !valid}
- onClick={() => {
- if (Option.isSome(input)) void testConnection(input.value);
+ </label>
+ <label className="block space-y-1.5 text-sm">
+ <span>SSH target</span>
+ <Input
+ required
+ value={draft.target}
+ disabled={busy}
+ onChange={(event) => {
+ const target = event.target.value;
+ setDraft((current) => ({ ...current, target }));
+ }}
+ placeholder="user@host or SSH alias"
+ />
+ </label>
+ <details
+ open={host.port !== undefined || host.identityFile !== undefined || undefined}
+ className="text-sm"
+ >
+ <summary className="cursor-pointer text-muted-foreground">SSH options</summary>
+ <div className="mt-3 grid grid-cols-[minmax(0,1fr)_7rem] gap-3">
+ <label className="block space-y-1.5">
+ <span>Identity file</span>
+ <Input
+ value={draft.identityFile ?? ""}
+ disabled={busy}
+ onChange={(event) => {
+ const identityFile = event.target.value;
+ setDraft((current) => {
+ const { identityFile: _, ...rest } = current;
+ return identityFile ? { ...rest, identityFile } : rest;
+ });
+ }}
+ placeholder="SSH config default"
+ />
+ </label>
+ <label className="block space-y-1.5">
+ <span>Port</span>
+ <Input
+ type="number"
+ min={1}
+ max={65535}
+ value={draft.port ?? ""}
+ disabled={busy}
+ onChange={(event) => {
+ const port = event.target.value;
+ setDraft((current) => {
+ const { port: _, ...rest } = current;
+ return port ? { ...rest, port: Number(port) } : rest;
+ });
}}
- >
- {checking ? <Spinner size="xs" /> : null} Test connection
- </Button>
- </div>
- {results ? (
- <CollapsiblePanel
- render={<ul className="border-t border-border/60 divide-y divide-border/40" />}
- >
- {targets.map((target) => {
- const result = results[target.environmentId];
- if (!result) return null;
- return (
- <li key={target.environmentId} className="px-3 py-2.5 text-xs">
- <div className="flex items-center justify-between gap-3">
- <span className="truncate font-medium">{target.label}</span>
- <span
- className={`flex shrink-0 items-center gap-1.5 ${result.status === "failed" ? "text-destructive" : "text-muted-foreground"}`}
- >
- {result.status === "pending" ? (
- <>
- <Spinner size="xs" /> Checking…
- </>
- ) : result.status === "local" ? (
- <>
- <MonitorIcon className="size-3" /> Already available locally
- </>
- ) : result.status === "failed" ? (
- <>
- <XIcon className="size-3" /> Failed
- </>
- ) : (
- <>
- <CheckIcon className="size-3" /> Connected
- </>
- )}
- </span>
+ placeholder="Default"
+ />
+ </label>
+ </div>
+ <p className="mt-2 text-xs text-muted-foreground">
+ Optional. Resolved separately on each environment.
+ </p>
+ </details>
+ <Collapsible
+ open={checksOpen}
+ onOpenChange={(open) => setExpandedChecks({ key: connectionKey, open })}
+ render={<div className="rounded-lg border border-border/60" />}
+ >
+ <div className="flex items-center justify-between gap-3 px-3 py-2.5">
+ {targets.length === 1 ? (
+ <p role="status" className="text-xs text-muted-foreground">
+ {checkSummary}
+ </p>
+ ) : (
+ <div className="min-w-0 text-xs [--inline-button-white-space:normal]">
+ <CollapsibleTrigger
+ disabled={!results}
+ aria-label={`${checkSummary}. Per-machine results`}
+ render={<InlineButton tone="muted" />}
+ >
+ <span role="status" className="text-left">
+ {checkSummary}
+ </span>
+ {results ? (
+ <ChevronDownIcon
+ className={`size-3 shrink-0 ${checksOpen ? "rotate-180" : ""}`}
+ />
+ ) : null}
+ </CollapsibleTrigger>
+ </div>
+ )}
+ <Button
+ type="button"
+ size="sm"
+ variant="outline"
+ disabled={busy || checking || !valid}
+ onClick={() => {
+ if (Option.isSome(input)) void testConnection(input.value);
+ }}
+ >
+ {checking ? <Spinner size="xs" /> : null} Test connection
+ </Button>
+ </div>
+ {results ? (
+ <CollapsiblePanel
+ render={<ul className="border-t border-border/60 divide-y divide-border/40" />}
+ >
+ {targets.map((target) => {
+ const result = results[target.environmentId];
+ if (!result) return null;
+ return (
+ <li key={target.environmentId} className="px-3 py-2.5 text-xs">
+ <div className="flex items-center justify-between gap-3">
+ <span className="truncate font-medium">{target.label}</span>
+ <span
+ className={`flex shrink-0 items-center gap-1.5 ${result.status === "failed" ? "text-destructive" : "text-muted-foreground"}`}
+ >
+ {result.status === "pending" ? (
+ <>
+ <Spinner size="xs" /> Checking…
+ </>
+ ) : result.status === "local" ? (
+ <>
+ <MonitorIcon className="size-3" /> Already available locally
+ </>
+ ) : result.status === "failed" ? (
+ <>
+ <XIcon className="size-3" /> Failed
+ </>
+ ) : (
+ <>
+ <CheckIcon className="size-3" /> Connected
+ </>
+ )}
+ </span>
+ </div>
+ {result.status === "connected" ? (
+ <div className="mt-1.5">
+ <DeviceHostAvailability platforms={result.platforms} />
</div>
- {result.status === "connected" ? (
- <div className="mt-1.5">
- <DeviceHostAvailability platforms={result.platforms} />
- </div>
- ) : null}
- {result.status === "failed" ? (
- <details className="mt-1.5 text-muted-foreground">
- <summary className="cursor-pointer">Show error</summary>
- <p className="mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-words">
- {result.error}
- </p>
- </details>
- ) : null}
- </li>
- );
- })}
- </CollapsiblePanel>
- ) : null}
- </Collapsible>
- </DialogPanel>
- <DialogFooter>
- <Button type="button" variant="ghost" disabled={busy} onClick={onClose}>
- Cancel
- </Button>
- <Button type="submit" disabled={busy || checking || !valid || !draft.label.trim()}>
- {busy ? <Spinner size="xs" /> : null} Save host
- </Button>
- </DialogFooter>
- </DialogPopup>
- </Dialog>
+ ) : null}
+ {result.status === "failed" ? (
+ <details className="mt-1.5 text-muted-foreground">
+ <summary className="cursor-pointer">Show error</summary>
+ <p className="mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-words">
+ {result.error}
+ </p>
+ </details>
+ ) : null}
+ </li>
+ );
+ })}
+ </CollapsiblePanel>
+ ) : null}
+ </Collapsible>
+ </DialogPanel>
+ <DialogFooter>
+ <Button type="button" variant="ghost" disabled={busy} onClick={onClose}>
+ Cancel
+ </Button>
+ <Button type="submit" disabled={busy || checking || !valid || !draft.label.trim()}>
+ {busy ? <Spinner size="xs" /> : null} Save host
+ </Button>
+ </DialogFooter>
+ </form>
);
}
diff --git a/apps/web/src/components/settings/ScheduledTasksSettings.tsx b/apps/web/src/components/settings/ScheduledTasksSettings.tsx
index 307b1879ff0..e85d17da5be 100644
--- a/apps/web/src/components/settings/ScheduledTasksSettings.tsx
+++ b/apps/web/src/components/settings/ScheduledTasksSettings.tsx
@@ -922,6 +922,41 @@ function ScheduledTaskEditorDialog({
readonly initialEnvironmentId: EnvironmentId;
readonly task: ScheduledTask | null;
readonly onClose: () => void;
+}) {
+ const [saving, setSaving] = useState(false);
+ return (
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open && !saving) onClose();
+ }}
+ >
+ {/* The form owns the draft so a keystroke re-renders it, not the dialog chrome. */}
+ <DialogPopup className="max-w-xl">
+ <ScheduledTaskEditorForm
+ initialEnvironmentId={initialEnvironmentId}
+ task={task}
+ saving={saving}
+ onSavingChange={setSaving}
+ onClose={onClose}
+ />
+ </DialogPopup>
+ </Dialog>
+ );
+}
+
+function ScheduledTaskEditorForm({
+ initialEnvironmentId,
+ task,
+ saving,
+ onSavingChange: setSaving,
+ onClose,
+}: {
+ readonly initialEnvironmentId: EnvironmentId;
+ readonly task: ScheduledTask | null;
+ readonly saving: boolean;
+ readonly onSavingChange: (saving: boolean) => void;
+ readonly onClose: () => void;
}) {
const { scope, connectedEnvironments } = useSettingsScope();
const [environmentId, setEnvironmentId] = useState(initialEnvironmentId);
@@ -949,7 +984,6 @@ function ScheduledTaskEditorDialog({
const [draft, setDraft] = useState<DraftState>(() =>
task ? taskToDraft(task) : { ...EMPTY_DRAFT, projectId: projects[0]?.id ?? "" },
);
- const [saving, setSaving] = useState(false);
const submissionPending = useRef(false);
const editingTaskMissing =
draft.editingId !== null &&
@@ -1090,459 +1124,446 @@ function ScheduledTaskEditorDialog({
};
return (
- <Dialog
- open
- onOpenChange={(open) => {
- if (!open && !saving) onClose();
- }}
- >
- <DialogPopup className="max-w-xl">
- <DialogHeader>
- <DialogTitle>{draft.editingId ? "Edit task" : "New task"}</DialogTitle>
- <DialogDescription>
- Run a prompt automatically — on an interval, at a fixed time, or when a webhook is
- called.
- </DialogDescription>
- </DialogHeader>
+ <>
+ <DialogHeader>
+ <DialogTitle>{draft.editingId ? "Edit task" : "New task"}</DialogTitle>
+ <DialogDescription>
+ Run a prompt automatically — on an interval, at a fixed time, or when a webhook is called.
+ </DialogDescription>
+ </DialogHeader>
- <DialogPanel>
- <fieldset disabled={saving} className="space-y-5">
- {!connected ? (
- <p className="text-sm text-destructive">Reconnect this environment before saving.</p>
- ) : null}
- <Field label="Runs on" htmlFor="scheduled-task-environment">
+ <DialogPanel>
+ <fieldset disabled={saving} className="space-y-5">
+ {!connected ? (
+ <p className="text-sm text-destructive">Reconnect this environment before saving.</p>
+ ) : null}
+ <Field label="Runs on" htmlFor="scheduled-task-environment">
+ <Select
+ value={environmentId}
+ disabled={task !== null || saving}
+ onValueChange={(id) => {
+ const next = connectedEnvironments.find((entry) => entry.environmentId === id);
+ if (!next) return;
+ setEnvironmentId(next.environmentId);
+ setDraft((current) => ({
+ ...current,
+ projectId: "",
+ modelKey: "",
+ baseModelSelection: null,
+ baseRef: "main",
+ startFromOrigin: true,
+ existingWorktreePath: "",
+ }));
+ }}
+ >
+ <SelectTrigger id="scheduled-task-environment" size="sm">
+ <SelectValue>
+ <span className="flex items-center gap-2">
+ <EnvironmentMachineIcon
+ kind={resolveEnvironmentMachineKind(environment?.serverConfig ?? null)}
+ className="size-4"
+ />
+ {environment?.label ?? "Unavailable environment"}
+ </span>
+ </SelectValue>
+ </SelectTrigger>
+ <SelectPopup>
+ {connectedEnvironments.map((entry) => {
+ const { secondary } = settingsScopeEnvironmentLabels(
+ entry,
+ connectedEnvironments,
+ );
+ return (
+ <SelectItem
+ key={entry.environmentId}
+ value={entry.environmentId}
+ label={entry.label}
+ >
+ <span className="flex min-w-0 items-center gap-2">
+ <EnvironmentMachineIcon
+ kind={resolveEnvironmentMachineKind(entry.serverConfig)}
+ className="size-4"
+ />
+ <span className="min-w-0">
+ <span className="block truncate">{entry.label}</span>
+ {secondary ? (
+ <span className="block max-w-72 truncate text-xs text-muted-foreground">
+ {secondary}
+ </span>
+ ) : null}
+ </span>
+ </span>
+ </SelectItem>
+ );
+ })}
+ </SelectPopup>
+ </Select>
+ </Field>
+ {tasksQuery.error ? (
+ <p className="text-sm text-destructive" role="status">
+ {tasksQuery.error}
+ </p>
+ ) : null}
+ {editingTaskMissing ? (
+ <p className="text-xs text-destructive" role="status">
+ This scheduled task no longer exists.
+ </p>
+ ) : null}
+ <Field label="Name" htmlFor="scheduled-task-title">
+ <Input
+ id="scheduled-task-title"
+ placeholder="e.g. Check for Sentry issues"
+ value={draft.title}
+ onChange={(event) =>
+ setDraft((current) => ({ ...current, title: event.target.value }))
+ }
+ />
+ </Field>
+
+ <div className="grid gap-3 sm:grid-cols-2">
+ <Field label="Project" htmlFor="scheduled-task-project">
<Select
- value={environmentId}
- disabled={task !== null || saving}
- onValueChange={(id) => {
- const next = connectedEnvironments.find((entry) => entry.environmentId === id);
- if (!next) return;
- setEnvironmentId(next.environmentId);
- setDraft((current) => ({
- ...current,
- projectId: "",
- modelKey: "",
- baseModelSelection: null,
- baseRef: "main",
- startFromOrigin: true,
- existingWorktreePath: "",
- }));
- }}
+ value={selectedProjectId}
+ onValueChange={(projectId) =>
+ setDraft((current) => ({ ...current, projectId: projectId ?? "" }))
+ }
>
- <SelectTrigger id="scheduled-task-environment" size="sm">
- <SelectValue>
- <span className="flex items-center gap-2">
- <EnvironmentMachineIcon
- kind={resolveEnvironmentMachineKind(environment?.serverConfig ?? null)}
- className="size-4"
- />
- {environment?.label ?? "Unavailable environment"}
- </span>
- </SelectValue>
+ <SelectTrigger size="sm" id="scheduled-task-project">
+ <SelectValue placeholder="Select a project">{selectedProject?.title}</SelectValue>
</SelectTrigger>
<SelectPopup>
- {connectedEnvironments.map((entry) => {
- const { secondary } = settingsScopeEnvironmentLabels(
- entry,
- connectedEnvironments,
- );
- return (
- <SelectItem
- key={entry.environmentId}
- value={entry.environmentId}
- label={entry.label}
- >
- <span className="flex min-w-0 items-center gap-2">
- <EnvironmentMachineIcon
- kind={resolveEnvironmentMachineKind(entry.serverConfig)}
- className="size-4"
- />
- <span className="min-w-0">
- <span className="block truncate">{entry.label}</span>
- {secondary ? (
- <span className="block max-w-72 truncate text-xs text-muted-foreground">
- {secondary}
- </span>
- ) : null}
- </span>
+ {projects.map((project) => (
+ <SelectItem key={project.id} value={project.id} label={project.title}>
+ <span className="block truncate">{project.title}</span>
+ {allProjects.some(
+ (other) =>
+ other.title === project.title &&
+ (other.environmentId !== project.environmentId ||
+ other.id !== project.id),
+ ) ? (
+ <span className="block max-w-72 truncate text-xs text-muted-foreground">
+ {project.workspaceRoot}
</span>
- </SelectItem>
- );
- })}
+ ) : null}
+ </SelectItem>
+ ))}
</SelectPopup>
</Select>
</Field>
- {tasksQuery.error ? (
- <p className="text-sm text-destructive" role="status">
- {tasksQuery.error}
- </p>
- ) : null}
- {editingTaskMissing ? (
- <p className="text-xs text-destructive" role="status">
- This scheduled task no longer exists.
- </p>
- ) : null}
- <Field label="Name" htmlFor="scheduled-task-title">
+
+ <Field label="Workspace" htmlFor="scheduled-task-workspace">
+ <Select
+ value={draft.workspaceMode}
+ onValueChange={(value) =>
+ setDraft((current) => ({ ...current, workspaceMode: value as WorkspaceMode }))
+ }
+ >
+ <SelectTrigger size="sm" id="scheduled-task-workspace">
+ <SelectValue>{WORKSPACE_MODE_LABELS[draft.workspaceMode]}</SelectValue>
+ </SelectTrigger>
+ <SelectPopup>
+ <SelectItem value="worktree">Create a new worktree</SelectItem>
+ <SelectItem value="root">Use the project checkout</SelectItem>
+ <SelectItem value="existing_worktree">Use a specific checkout</SelectItem>
+ </SelectPopup>
+ </Select>
+ </Field>
+ </div>
+
+ {draft.workspaceMode === "worktree" ? (
+ <Field label="Base branch" htmlFor="scheduled-task-base-ref">
+ <WorktreeBaseBranchPicker
+ key={`${environmentId}:${selectedProjectId}`}
+ id="scheduled-task-base-ref"
+ environmentId={environmentId}
+ cwd={selectedProject?.workspaceRoot ?? null}
+ value={draft.baseRef}
+ onValueChange={(baseRef) => setDraft((current) => ({ ...current, baseRef }))}
+ startFromOrigin={draft.startFromOrigin}
+ onStartFromOriginChange={(startFromOrigin) =>
+ setDraft((current) => ({ ...current, startFromOrigin }))
+ }
+ disabled={saving || !connected}
+ />
+ </Field>
+ ) : null}
+ {draft.workspaceMode === "existing_worktree" ? (
+ <Field label="Checkout path" htmlFor="scheduled-task-checkout">
<Input
- id="scheduled-task-title"
- placeholder="e.g. Check for Sentry issues"
- value={draft.title}
+ id="scheduled-task-checkout"
+ value={draft.existingWorktreePath}
+ placeholder="/path/to/checkout"
onChange={(event) =>
- setDraft((current) => ({ ...current, title: event.target.value }))
+ setDraft((current) => ({
+ ...current,
+ existingWorktreePath: event.target.value,
+ }))
}
/>
</Field>
+ ) : null}
- <div className="grid gap-3 sm:grid-cols-2">
- <Field label="Project" htmlFor="scheduled-task-project">
- <Select
- value={selectedProjectId}
- onValueChange={(projectId) =>
- setDraft((current) => ({ ...current, projectId: projectId ?? "" }))
- }
- >
- <SelectTrigger size="sm" id="scheduled-task-project">
- <SelectValue placeholder="Select a project">
- {selectedProject?.title}
- </SelectValue>
- </SelectTrigger>
- <SelectPopup>
- {projects.map((project) => (
- <SelectItem key={project.id} value={project.id} label={project.title}>
- <span className="block truncate">{project.title}</span>
- {allProjects.some(
- (other) =>
- other.title === project.title &&
- (other.environmentId !== project.environmentId ||
- other.id !== project.id),
- ) ? (
- <span className="block max-w-72 truncate text-xs text-muted-foreground">
- {project.workspaceRoot}
- </span>
- ) : null}
- </SelectItem>
- ))}
- </SelectPopup>
- </Select>
- </Field>
+ <Field label="Prompt" htmlFor="scheduled-task-prompt">
+ <Textarea
+ id="scheduled-task-prompt"
+ className="max-h-64 overflow-y-auto"
+ placeholder="What should the agent do each time this runs?"
+ value={draft.prompt}
+ onChange={(event) =>
+ setDraft((current) => ({ ...current, prompt: event.target.value }))
+ }
+ />
+ </Field>
- <Field label="Workspace" htmlFor="scheduled-task-workspace">
- <Select
- value={draft.workspaceMode}
- onValueChange={(value) =>
- setDraft((current) => ({ ...current, workspaceMode: value as WorkspaceMode }))
- }
- >
- <SelectTrigger size="sm" id="scheduled-task-workspace">
- <SelectValue>{WORKSPACE_MODE_LABELS[draft.workspaceMode]}</SelectValue>
- </SelectTrigger>
- <SelectPopup>
- <SelectItem value="worktree">Create a new worktree</SelectItem>
- <SelectItem value="root">Use the project checkout</SelectItem>
- <SelectItem value="existing_worktree">Use a specific checkout</SelectItem>
- </SelectPopup>
- </Select>
- </Field>
+ <Field label="Model">
+ <div>
+ <ProviderModelPicker
+ environmentId={environmentId}
+ disabled={saving || !connected}
+ activeInstanceId={activeInstanceId}
+ model={activeModel}
+ lockedProvider={null}
+ instanceEntries={instanceEntries}
+ modelOptionsByInstance={modelOptionsByInstance}
+ isComposerOwned={false}
+ triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
+ onInstanceModelChange={(instanceId, model) =>
+ setDraft((current) => ({ ...current, modelKey: `${instanceId}:${model}` }))
+ }
+ />
</div>
+ </Field>
- {draft.workspaceMode === "worktree" ? (
- <Field label="Base branch" htmlFor="scheduled-task-base-ref">
- <WorktreeBaseBranchPicker
- key={`${environmentId}:${selectedProjectId}`}
- id="scheduled-task-base-ref"
- environmentId={environmentId}
- cwd={selectedProject?.workspaceRoot ?? null}
- value={draft.baseRef}
- onValueChange={(baseRef) => setDraft((current) => ({ ...current, baseRef }))}
- startFromOrigin={draft.startFromOrigin}
- onStartFromOriginChange={(startFromOrigin) =>
- setDraft((current) => ({ ...current, startFromOrigin }))
- }
- disabled={saving || !connected}
- />
- </Field>
+ <div className="space-y-3">
+ {task?.schedule.type === "interval" &&
+ task.schedule.everyMs < MIN_SCHEDULED_TASK_INTERVAL_MS ? (
+ <p className="text-sm text-muted-foreground" role="status">
+ This task uses a legacy interval below one minute. Saving updates it to at least one
+ minute.
+ </p>
) : null}
- {draft.workspaceMode === "existing_worktree" ? (
- <Field label="Checkout path" htmlFor="scheduled-task-checkout">
- <Input
- id="scheduled-task-checkout"
- value={draft.existingWorktreePath}
- placeholder="/path/to/checkout"
- onChange={(event) =>
+ <div className="flex items-center justify-between gap-2">
+ <Label>Schedule</Label>
+ <ToggleGroup
+ aria-label="Schedule type"
+ value={[draft.scheduleMode]}
+ onValueChange={(values) => {
+ const mode = values[0] as ScheduleMode | undefined;
+ if (mode === "fixed" || mode === "interval" || mode === "webhook")
setDraft((current) => ({
...current,
- existingWorktreePath: event.target.value,
- }))
- }
- />
- </Field>
- ) : null}
-
- <Field label="Prompt" htmlFor="scheduled-task-prompt">
- <Textarea
- id="scheduled-task-prompt"
- className="max-h-64 overflow-y-auto"
- placeholder="What should the agent do each time this runs?"
- value={draft.prompt}
- onChange={(event) =>
- setDraft((current) => ({ ...current, prompt: event.target.value }))
- }
- />
- </Field>
+ scheduleMode: mode,
+ prompt:
+ mode === "webhook" && !current.prompt.trim()
+ ? DEFAULT_WEBHOOK_PROMPT
+ : current.prompt,
+ }));
+ }}
+ >
+ <Toggle value="fixed">At a time</Toggle>
+ <Toggle value="interval">Every interval</Toggle>
+ <Toggle value="webhook">On webhook</Toggle>
+ </ToggleGroup>
+ </div>
- <Field label="Model">
- <div>
- <ProviderModelPicker
- environmentId={environmentId}
- disabled={saving || !connected}
- activeInstanceId={activeInstanceId}
- model={activeModel}
- lockedProvider={null}
- instanceEntries={instanceEntries}
- modelOptionsByInstance={modelOptionsByInstance}
- isComposerOwned={false}
- triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
- onInstanceModelChange={(instanceId, model) =>
- setDraft((current) => ({ ...current, modelKey: `${instanceId}:${model}` }))
+ {draft.scheduleMode === "webhook" ? (
+ <div className="space-y-4">
+ <WebhookEndpointField environmentId={environmentId} task={liveTask} />
+ <p className="text-xs text-muted-foreground">
+ {
+ "Each request runs the prompt. Use {{body.path}}, {{headers.name}}, {{query.name}}, {{body}} or {{request}} in the prompt; only what it names reaches the agent."
}
- />
- </div>
- </Field>
-
- <div className="space-y-3">
- {task?.schedule.type === "interval" &&
- task.schedule.everyMs < MIN_SCHEDULED_TASK_INTERVAL_MS ? (
- <p className="text-sm text-muted-foreground" role="status">
- This task uses a legacy interval below one minute. Saving updates it to at least
- one minute.
</p>
- ) : null}
- <div className="flex items-center justify-between gap-2">
- <Label>Schedule</Label>
- <ToggleGroup
- aria-label="Schedule type"
- value={[draft.scheduleMode]}
- onValueChange={(values) => {
- const mode = values[0] as ScheduleMode | undefined;
- if (mode === "fixed" || mode === "interval" || mode === "webhook")
+ <Field
+ label="Skip requests older than"
+ hint="minutes, optional"
+ htmlFor="scheduled-task-max-age"
+ >
+ <Input
+ id="scheduled-task-max-age"
+ type="number"
+ nativeInput
+ min={1}
+ max={MAX_WEBHOOK_DELIVERY_AGE_MINUTES}
+ placeholder="Run every request"
+ value={draft.maxDeliveryAgeMinutes}
+ onChange={(event) =>
setDraft((current) => ({
...current,
- scheduleMode: mode,
- prompt:
- mode === "webhook" && !current.prompt.trim()
- ? DEFAULT_WEBHOOK_PROMPT
- : current.prompt,
- }));
- }}
- >
- <Toggle value="fixed">At a time</Toggle>
- <Toggle value="interval">Every interval</Toggle>
- <Toggle value="webhook">On webhook</Toggle>
- </ToggleGroup>
- </div>
-
- {draft.scheduleMode === "webhook" ? (
- <div className="space-y-4">
- <WebhookEndpointField environmentId={environmentId} task={liveTask} />
- <p className="text-xs text-muted-foreground">
- {
- "Each request runs the prompt. Use {{body.path}}, {{headers.name}}, {{query.name}}, {{body}} or {{request}} in the prompt; only what it names reaches the agent."
+ maxDeliveryAgeMinutes: event.target.value,
+ }))
}
- </p>
- <Field
- label="Skip requests older than"
- hint="minutes, optional"
- htmlFor="scheduled-task-max-age"
- >
- <Input
- id="scheduled-task-max-age"
- type="number"
- nativeInput
- min={1}
- max={MAX_WEBHOOK_DELIVERY_AGE_MINUTES}
- placeholder="Run every request"
- value={draft.maxDeliveryAgeMinutes}
- onChange={(event) =>
- setDraft((current) => ({
- ...current,
- maxDeliveryAgeMinutes: event.target.value,
- }))
- }
- />
- </Field>
- <div className="flex items-center justify-between gap-4">
- <div className="min-w-0 space-y-1">
- <Label htmlFor="scheduled-task-signature">Require signature</Label>
- <p className="text-sm text-muted-foreground">
- Reject requests without a valid HMAC-SHA256 signature of the body.
- </p>
- </div>
- <Switch
- id="scheduled-task-signature"
- checked={draft.signatureEnabled}
- onCheckedChange={(signatureEnabled) =>
- setDraft((current) => ({ ...current, signatureEnabled }))
- }
- />
+ />
+ </Field>
+ <div className="flex items-center justify-between gap-4">
+ <div className="min-w-0 space-y-1">
+ <Label htmlFor="scheduled-task-signature">Require signature</Label>
+ <p className="text-sm text-muted-foreground">
+ Reject requests without a valid HMAC-SHA256 signature of the body.
+ </p>
</div>
- {draft.signatureEnabled ? (
- <div className="grid gap-3 sm:grid-cols-2">
- <Field label="Header" htmlFor="scheduled-task-signature-header">
- <Input
- id="scheduled-task-signature-header"
- value={draft.signatureHeader}
- onChange={(event) =>
- setDraft((current) => ({
- ...current,
- signatureHeader: event.target.value,
- }))
- }
- />
- </Field>
- <Field label="Prefix" htmlFor="scheduled-task-signature-prefix">
- <Input
- id="scheduled-task-signature-prefix"
- value={draft.signaturePrefix}
- placeholder="None"
- onChange={(event) =>
- setDraft((current) => ({
- ...current,
- signaturePrefix: event.target.value,
- }))
- }
- />
- </Field>
- <Field label="Encoding" htmlFor="scheduled-task-signature-encoding">
- <Select
- value={draft.signatureEncoding}
- onValueChange={(value) =>
- setDraft((current) => ({
- ...current,
- signatureEncoding: value === "base64" ? "base64" : "hex",
- }))
- }
- >
- <SelectTrigger size="sm" id="scheduled-task-signature-encoding">
- <SelectValue>{draft.signatureEncoding}</SelectValue>
- </SelectTrigger>
- <SelectPopup>
- <SelectItem value="hex">hex</SelectItem>
- <SelectItem value="base64">base64</SelectItem>
- </SelectPopup>
- </Select>
- </Field>
- <Field label="Secret" htmlFor="scheduled-task-signature-secret">
- <Input
- id="scheduled-task-signature-secret"
- type="password"
- autoComplete="off"
- value={draft.signatureSecret}
- placeholder={
- liveTask?.schedule.type === "webhook" && liveTask.webhook?.hasSecret
- ? "Unchanged"
- : "Shared secret"
- }
- onChange={(event) =>
- setDraft((current) => ({
- ...current,
- signatureSecret: event.target.value,
- }))
- }
- />
- </Field>
- </div>
- ) : null}
+ <Switch
+ id="scheduled-task-signature"
+ checked={draft.signatureEnabled}
+ onCheckedChange={(signatureEnabled) =>
+ setDraft((current) => ({ ...current, signatureEnabled }))
+ }
+ />
</div>
- ) : draft.scheduleMode === "fixed" ? (
- <div className="flex flex-wrap items-center gap-3">
- <div className="flex items-center gap-2">
- <Label htmlFor="scheduled-task-time">Run at</Label>
- <Input
- type="time"
- id="scheduled-task-time"
- nativeInput
- className="w-32"
- value={draft.timeOfDay}
- onChange={(event) =>
- setDraft((current) => ({ ...current, timeOfDay: event.target.value }))
- }
- />
- <span className="text-xs text-muted-foreground">on</span>
+ {draft.signatureEnabled ? (
+ <div className="grid gap-3 sm:grid-cols-2">
+ <Field label="Header" htmlFor="scheduled-task-signature-header">
+ <Input
+ id="scheduled-task-signature-header"
+ value={draft.signatureHeader}
+ onChange={(event) =>
+ setDraft((current) => ({
+ ...current,
+ signatureHeader: event.target.value,
+ }))
+ }
+ />
+ </Field>
+ <Field label="Prefix" htmlFor="scheduled-task-signature-prefix">
+ <Input
+ id="scheduled-task-signature-prefix"
+ value={draft.signaturePrefix}
+ placeholder="None"
+ onChange={(event) =>
+ setDraft((current) => ({
+ ...current,
+ signaturePrefix: event.target.value,
+ }))
+ }
+ />
+ </Field>
+ <Field label="Encoding" htmlFor="scheduled-task-signature-encoding">
+ <Select
+ value={draft.signatureEncoding}
+ onValueChange={(value) =>
+ setDraft((current) => ({
+ ...current,
+ signatureEncoding: value === "base64" ? "base64" : "hex",
+ }))
+ }
+ >
+ <SelectTrigger size="sm" id="scheduled-task-signature-encoding">
+ <SelectValue>{draft.signatureEncoding}</SelectValue>
+ </SelectTrigger>
+ <SelectPopup>
+ <SelectItem value="hex">hex</SelectItem>
+ <SelectItem value="base64">base64</SelectItem>
+ </SelectPopup>
+ </Select>
+ </Field>
+ <Field label="Secret" htmlFor="scheduled-task-signature-secret">
+ <Input
+ id="scheduled-task-signature-secret"
+ type="password"
+ autoComplete="off"
+ value={draft.signatureSecret}
+ placeholder={
+ liveTask?.schedule.type === "webhook" && liveTask.webhook?.hasSecret
+ ? "Unchanged"
+ : "Shared secret"
+ }
+ onChange={(event) =>
+ setDraft((current) => ({
+ ...current,
+ signatureSecret: event.target.value,
+ }))
+ }
+ />
+ </Field>
</div>
- <ToggleGroup
- multiple
- variant="outline"
- size="sm"
- aria-label="Days to run"
- value={[...draft.weekdays].map(String)}
- onValueChange={(values) => {
- if (values.length === 0) return;
- setDraft((current) => ({
- ...current,
- weekdays: new Set(values.map(Number)),
- }));
- }}
- >
- {WEEKDAY_ORDER.map((day) => (
- <Toggle key={day} value={String(day)} aria-label={WEEKDAY_LABELS[day]}>
- {WEEKDAY_SHORT[day]}
- </Toggle>
- ))}
- </ToggleGroup>
- </div>
- ) : (
+ ) : null}
+ </div>
+ ) : draft.scheduleMode === "fixed" ? (
+ <div className="flex flex-wrap items-center gap-3">
<div className="flex items-center gap-2">
- <Label htmlFor="scheduled-task-interval">Run every</Label>
+ <Label htmlFor="scheduled-task-time">Run at</Label>
<Input
- type="number"
- id="scheduled-task-interval"
+ type="time"
+ id="scheduled-task-time"
nativeInput
- min={1}
- step="any"
- className="w-24"
- value={draft.intervalMinutes}
+ className="w-32"
+ value={draft.timeOfDay}
onChange={(event) =>
- setDraft((current) => ({ ...current, intervalMinutes: event.target.value }))
+ setDraft((current) => ({ ...current, timeOfDay: event.target.value }))
}
/>
- <span className="text-xs text-muted-foreground">minutes</span>
+ <span className="text-xs text-muted-foreground">on</span>
</div>
- )}
- </div>
-
- <div className="flex items-center justify-between gap-4">
- <div className="min-w-0 space-y-1">
- <Label htmlFor="scheduled-task-enabled">Enabled</Label>
- <p
- id="scheduled-task-enabled-description"
- className="text-sm text-muted-foreground"
+ <ToggleGroup
+ multiple
+ variant="outline"
+ size="sm"
+ aria-label="Days to run"
+ value={[...draft.weekdays].map(String)}
+ onValueChange={(values) => {
+ if (values.length === 0) return;
+ setDraft((current) => ({
+ ...current,
+ weekdays: new Set(values.map(Number)),
+ }));
+ }}
>
- Disabled tasks stay saved but do not run.
- </p>
+ {WEEKDAY_ORDER.map((day) => (
+ <Toggle key={day} value={String(day)} aria-label={WEEKDAY_LABELS[day]}>
+ {WEEKDAY_SHORT[day]}
+ </Toggle>
+ ))}
+ </ToggleGroup>
</div>
- <Switch
- id="scheduled-task-enabled"
- aria-describedby="scheduled-task-enabled-description"
- checked={draft.enabled}
- onCheckedChange={(enabled) => setDraft((current) => ({ ...current, enabled }))}
- />
+ ) : (
+ <div className="flex items-center gap-2">
+ <Label htmlFor="scheduled-task-interval">Run every</Label>
+ <Input
+ type="number"
+ id="scheduled-task-interval"
+ nativeInput
+ min={1}
+ step="any"
+ className="w-24"
+ value={draft.intervalMinutes}
+ onChange={(event) =>
+ setDraft((current) => ({ ...current, intervalMinutes: event.target.value }))
+ }
+ />
+ <span className="text-xs text-muted-foreground">minutes</span>
+ </div>
+ )}
+ </div>
+
+ <div className="flex items-center justify-between gap-4">
+ <div className="min-w-0 space-y-1">
+ <Label htmlFor="scheduled-task-enabled">Enabled</Label>
+ <p id="scheduled-task-enabled-description" className="text-sm text-muted-foreground">
+ Disabled tasks stay saved but do not run.
+ </p>
</div>
- </fieldset>
- </DialogPanel>
+ <Switch
+ id="scheduled-task-enabled"
+ aria-describedby="scheduled-task-enabled-description"
+ checked={draft.enabled}
+ onCheckedChange={(enabled) => setDraft((current) => ({ ...current, enabled }))}
+ />
+ </div>
+ </fieldset>
+ </DialogPanel>
- <DialogFooter>
- <DialogClose render={<Button variant="outline" size="sm" disabled={saving} />}>
- Cancel
- </DialogClose>
- <Button
- size="sm"
- disabled={!canOperate || saving || editingTaskMissing || !connected || !tasksQuery.data}
- onClick={() => void submit()}
- >
- {draft.editingId ? "Save task" : "Create task"}
- </Button>
- </DialogFooter>
- </DialogPopup>
- </Dialog>
+ <DialogFooter>
+ <DialogClose render={<Button variant="outline" size="sm" disabled={saving} />}>
+ Cancel
+ </DialogClose>
+ <Button
+ size="sm"
+ disabled={!canOperate || saving || editingTaskMissing || !connected || !tasksQuery.data}
+ onClick={() => void submit()}
+ >
+ {draft.editingId ? "Save task" : "Create task"}
+ </Button>
+ </DialogFooter>
+ </>
);
}