дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
The New Agent Task composer gets the clock button next to Start. It opens New Automation prefilled with the draft instructions, agent, model settings and workspace; opening or cancelling the dialog keeps the draft, and unattended permissions stay configured in the dialog.
871 рядки
33 KiB
TypeScript
871 рядки
33 KiB
TypeScript
/**
|
||
* Modal dialog for creating or editing a host-owned Agent Automation.
|
||
*/
|
||
import clsx from "clsx";
|
||
import { useEffect, useMemo, useState } from "react";
|
||
import type {
|
||
AgentConfigChoice,
|
||
AgentMemoryOverrides,
|
||
AgentSkillMode,
|
||
AutomationContinuity,
|
||
AutomationMisfirePolicy,
|
||
AutomationPermissionMode,
|
||
AutomationTrigger,
|
||
Branch,
|
||
Isolation,
|
||
} from "@/bindings";
|
||
import { useTx } from "@/platform/i18n";
|
||
import { call, commands, isTauri } from "@/platform/ipc";
|
||
import { basename, useProject } from "@/platform/project";
|
||
import { Button, Checkbox, Dialog, Icon, Input, Select, T, type SelectOption } from "@/ui";
|
||
import { ConfigPickers } from "./ConfigPickers";
|
||
import { McpPicker } from "./McpPicker";
|
||
import { MemoryPicker } from "./MemoryPicker";
|
||
import { SkillsPicker } from "./SkillsPicker";
|
||
import {
|
||
closeAutomationDialog,
|
||
defaultAutomationsBackend,
|
||
formatShortTimestamp,
|
||
refreshAutomations,
|
||
triggersEqual,
|
||
useAutomations,
|
||
type AutomationsBackend,
|
||
} from "./automationsModel";
|
||
import { useAgentSettings } from "./agentSettings";
|
||
import { providerIcon } from "./model";
|
||
import { providerOptions as buildProviderOptions } from "./providerOptions";
|
||
import { useAgents } from "./store";
|
||
import styles from "./Automations.module.css";
|
||
|
||
type TriggerKind = AutomationTrigger["kind"];
|
||
|
||
const SCHEDULE_KIND_OPTIONS: ReadonlyArray<SelectOption<TriggerKind>> = [
|
||
{ value: "weekdays", label: "Weekdays" },
|
||
{ value: "daily", label: "Daily" },
|
||
{ value: "weekly", label: "Weekly" },
|
||
{ value: "hourly", label: "Hourly" },
|
||
{ value: "cron", label: "Cron expression" },
|
||
{ value: "oneShot", label: "One-shot" },
|
||
{ value: "manual", label: "Manual only" },
|
||
];
|
||
|
||
const PERMISSION_OPTIONS: ReadonlyArray<SelectOption<AutomationPermissionMode>> = [
|
||
{
|
||
value: "assisted",
|
||
label: "Accept edits",
|
||
detail: "Edit workspace files without asking; ask before commands",
|
||
},
|
||
{
|
||
value: "allowAll",
|
||
label: "Allow all",
|
||
detail: "Capped by your interactive approval setting",
|
||
},
|
||
{
|
||
value: "default",
|
||
label: "Ask for approval",
|
||
detail: "Ask before edits and commands",
|
||
},
|
||
];
|
||
|
||
const CONTINUITY_OPTIONS: ReadonlyArray<SelectOption<AutomationContinuity>> = [
|
||
{ value: "newTask", label: "Fresh session on each run" },
|
||
{ value: "sameTask", label: "Reuse rolling session" },
|
||
];
|
||
|
||
const MISFIRE_OPTIONS: ReadonlyArray<SelectOption<string>> = [
|
||
{ value: "default", label: "Use global setting" },
|
||
{ value: "runOnce", label: "Run once on wake" },
|
||
{ value: "skip", label: "Skip missed runs" },
|
||
];
|
||
|
||
const WEEKDAYS = [
|
||
{ day: 1, label: "Mon" },
|
||
{ day: 2, label: "Tue" },
|
||
{ day: 3, label: "Wed" },
|
||
{ day: 4, label: "Thu" },
|
||
{ day: 5, label: "Fri" },
|
||
{ day: 6, label: "Sat" },
|
||
{ day: 0, label: "Sun" },
|
||
] as const;
|
||
|
||
const EMPTY_BRANCHES: Branch[] = [];
|
||
|
||
function pad2(n: number): string {
|
||
return String(n).padStart(2, "0");
|
||
}
|
||
|
||
function toDatetimeLocalValue(ms: number): string {
|
||
const d = new Date(ms);
|
||
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
||
}
|
||
|
||
export function AutomationDialog({ backend = defaultAutomationsBackend }: { backend?: AutomationsBackend }) {
|
||
const dialog = useAutomations((s) => s.dialog);
|
||
if (!dialog.open) return null;
|
||
const formKey = `${dialog.editing?.id ?? "new"}:${dialog.editing?.updatedMs ?? 0}:${dialog.prefillName}:${dialog.prefillPrompt}:${JSON.stringify(dialog.prefillSettings)}`;
|
||
return <AutomationDialogBody key={formKey} backend={backend} />;
|
||
}
|
||
|
||
function AutomationDialogBody({ backend }: { backend: AutomationsBackend }) {
|
||
const tx = useTx();
|
||
const agentSettings = useAgentSettings();
|
||
const dialog = useAutomations((s) => s.dialog);
|
||
const project = useProject((s) => s.project);
|
||
const providers = useAgents((s) => s.providers);
|
||
const draftProvider = useAgents((s) => s.draft.provider);
|
||
|
||
const editing = dialog.editing;
|
||
const preSettings = dialog.prefillSettings;
|
||
const defaultRoot = project?.root ?? "";
|
||
const fallbackProvider = providers[0]?.id ?? draftProvider ?? "claude";
|
||
|
||
const [name, setName] = useState(() => editing?.name ?? (dialog.prefillName || ""));
|
||
const [enabled, setEnabled] = useState(() => editing?.enabled ?? true);
|
||
const [promptText, setPromptText] = useState(() => editing?.prompt.text ?? (dialog.prefillPrompt || ""));
|
||
const [workspaceMode, setWorkspaceMode] = useState<"project" | "chatOnly">(() => {
|
||
if (editing) return editing.workspace.kind === "chatOnly" ? "chatOnly" : "project";
|
||
return defaultRoot ? "project" : "chatOnly";
|
||
});
|
||
const [projectRoot, setProjectRoot] = useState(() => {
|
||
if (editing && editing.workspace.kind === "project") return editing.workspace.root || defaultRoot;
|
||
return preSettings?.projectRoot ?? defaultRoot;
|
||
});
|
||
const [isolation, setIsolation] = useState<Isolation>(() => {
|
||
if (editing && editing.workspace.kind === "project") return editing.workspace.isolation;
|
||
return preSettings?.isolation ?? "worktree";
|
||
});
|
||
const [baseBranch, setBaseBranch] = useState<string>(() => {
|
||
if (editing && editing.workspace.kind === "project") return editing.workspace.base ?? "";
|
||
return preSettings?.base ?? "";
|
||
});
|
||
const [autoCleanWorktree, setAutoCleanWorktree] = useState(() =>
|
||
editing && editing.workspace.kind === "project" ? editing.workspace.autoCleanWorktree : true,
|
||
);
|
||
const [continuity, setContinuity] = useState<AutomationContinuity>(() => editing?.continuity ?? "newTask");
|
||
const [providerId, setProviderId] = useState(() => editing?.provider || preSettings?.provider || fallbackProvider);
|
||
const [configMap, setConfigMap] = useState<Record<string, string>>(() => {
|
||
if (editing) return Object.fromEntries(editing.config.map((c) => [c.id, c.value]));
|
||
if (preSettings)
|
||
return Object.fromEntries(preSettings.config.filter((c) => c.current).map((c) => [c.id, c.current!]));
|
||
return {};
|
||
});
|
||
const [permissions, setPermissions] = useState<AutomationPermissionMode>(() => editing?.permissions ?? "assisted");
|
||
const [mcpOverrides, setMcpOverrides] = useState<Record<string, boolean>>(() => ({
|
||
...(editing?.mcpOverrides ?? preSettings?.mcpOverrides ?? {}),
|
||
}));
|
||
const [skillOverrides, setSkillOverrides] = useState<Record<string, AgentSkillMode>>(() => ({
|
||
...(editing?.skillOverrides ?? preSettings?.skillOverrides ?? {}),
|
||
}));
|
||
const [memoryOverrides, setMemoryOverrides] = useState<AgentMemoryOverrides | null>(
|
||
() => editing?.memoryOverrides ?? preSettings?.memoryOverrides ?? null,
|
||
);
|
||
|
||
const [triggerKind, setTriggerKind] = useState<TriggerKind>(() => editing?.trigger.kind ?? "weekdays");
|
||
const [timeStr, setTimeStr] = useState(() => {
|
||
const t = editing?.trigger;
|
||
if (t && (t.kind === "daily" || t.kind === "weekdays" || t.kind === "weekly")) {
|
||
return `${pad2(t.hour)}:${pad2(t.minute)}`;
|
||
}
|
||
return "09:00";
|
||
});
|
||
const [hourlyMinute, setHourlyMinute] = useState(() =>
|
||
editing?.trigger.kind === "hourly" ? String(editing.trigger.minute) : "0",
|
||
);
|
||
const [weeklyDays, setWeeklyDays] = useState<number[]>(() =>
|
||
editing?.trigger.kind === "weekly" && editing.trigger.days.length ? [...editing.trigger.days] : [1, 3, 5],
|
||
);
|
||
const [cronExpr, setCronExpr] = useState(() =>
|
||
editing?.trigger.kind === "cron" ? editing.trigger.expression : "0 9 * * MON-FRI",
|
||
);
|
||
const [timeZone, setTimeZone] = useState(() => {
|
||
const t = editing?.trigger;
|
||
if (t && "timeZone" in t && t.timeZone) return t.timeZone;
|
||
return "local";
|
||
});
|
||
const initialOneShotValue = useMemo(
|
||
() =>
|
||
editing?.trigger.kind === "oneShot" && editing.trigger.runAtMs
|
||
? toDatetimeLocalValue(editing.trigger.runAtMs)
|
||
: null,
|
||
[editing],
|
||
);
|
||
const [oneShotValue, setOneShotValue] = useState(
|
||
() => initialOneShotValue ?? toDatetimeLocalValue(Date.now() + 3_600_000),
|
||
);
|
||
const [misfirePolicy, setMisfirePolicy] = useState<string>(() => editing?.misfirePolicy ?? "default");
|
||
const [allowAgentSchedule, setAllowAgentSchedule] = useState(() => editing?.allowAgentSchedule ?? false);
|
||
const [clearOverride, setClearOverride] = useState(false);
|
||
const [maxRunsStr, setMaxRunsStr] = useState(() => (editing?.maxRuns != null ? String(editing.maxRuns) : ""));
|
||
const [disableAfterStr, setDisableAfterStr] = useState(() =>
|
||
editing?.disableAfterMs ? toDatetimeLocalValue(editing.disableAfterMs).slice(0, 10) : "",
|
||
);
|
||
// Expand Advanced automatically when editing a schedule with non-default advanced options.
|
||
const [advancedOpen, setAdvancedOpen] = useState(() =>
|
||
Boolean(
|
||
editing &&
|
||
(editing.allowAgentSchedule ||
|
||
editing.permissions !== "assisted" ||
|
||
editing.continuity !== "newTask" ||
|
||
editing.misfirePolicy != null ||
|
||
editing.maxRuns != null ||
|
||
editing.disableAfterMs != null ||
|
||
(editing.workspace.kind === "project" && !editing.workspace.autoCleanWorktree)),
|
||
),
|
||
);
|
||
|
||
const [fetchedBranches, setFetchedBranches] = useState<{ root: string; list: Branch[] }>({ root: "", list: [] });
|
||
const [previewState, setPreviewState] = useState<{ runs: number[]; error: string | null }>({
|
||
runs: [],
|
||
error: null,
|
||
});
|
||
const [saveError, setSaveError] = useState<string | null>(null);
|
||
const [saving, setSaving] = useState(false);
|
||
|
||
useEffect(() => {
|
||
if (workspaceMode !== "project" || !projectRoot || !isTauri()) return;
|
||
let active = true;
|
||
void call(commands.vcsBranches(project?.workspace ? projectRoot : null))
|
||
.then((list) => {
|
||
if (active) setFetchedBranches({ root: projectRoot, list: list.filter((b) => !b.remote) });
|
||
})
|
||
.catch(() => {
|
||
if (active) setFetchedBranches({ root: projectRoot, list: [] });
|
||
});
|
||
return () => {
|
||
active = false;
|
||
};
|
||
}, [workspaceMode, projectRoot, project?.workspace]);
|
||
|
||
const currentTrigger = useMemo<AutomationTrigger>(() => {
|
||
const [hRaw, mRaw] = timeStr.split(":");
|
||
const hour = Math.max(0, Math.min(23, Number(hRaw) || 0));
|
||
const minute = Math.max(0, Math.min(59, Number(mRaw) || 0));
|
||
const tz = timeZone.trim() || "local";
|
||
switch (triggerKind) {
|
||
case "manual":
|
||
return { kind: "manual" };
|
||
case "hourly":
|
||
return { kind: "hourly", minute: Math.max(0, Math.min(59, Number(hourlyMinute) || 0)), timeZone: tz };
|
||
case "daily":
|
||
return { kind: "daily", hour, minute, timeZone: tz };
|
||
case "weekdays":
|
||
return { kind: "weekdays", hour, minute, timeZone: tz };
|
||
case "weekly":
|
||
return { kind: "weekly", days: weeklyDays, hour, minute, timeZone: tz };
|
||
case "cron":
|
||
return { kind: "cron", expression: cronExpr.trim(), timeZone: tz };
|
||
case "oneShot": {
|
||
if (editing?.trigger.kind === "oneShot" && initialOneShotValue && oneShotValue === initialOneShotValue) {
|
||
return editing.trigger;
|
||
}
|
||
const parsed = Date.parse(oneShotValue);
|
||
return { kind: "oneShot", runAtMs: Number.isFinite(parsed) ? parsed : null };
|
||
}
|
||
}
|
||
}, [triggerKind, timeStr, hourlyMinute, weeklyDays, cronExpr, timeZone, oneShotValue, editing, initialOneShotValue]);
|
||
|
||
const pendingOverrideMs = editing?.nextRunOverrideMs ?? null;
|
||
const pendingPromptOverride = editing?.nextPromptOverride ?? null;
|
||
const triggerChanged = Boolean(editing && !triggersEqual(editing.trigger, currentTrigger));
|
||
const parsedMaxRuns = maxRunsStr.trim() ? Number(maxRunsStr.trim()) : null;
|
||
const maxRunsBlocksOverride = Boolean(
|
||
editing && parsedMaxRuns && parsedMaxRuns > 0 && editing.runCount >= Math.round(parsedMaxRuns),
|
||
);
|
||
const parsedDisableAfterMs = disableAfterStr.trim() ? Date.parse(`${disableAfterStr.trim()}T23:59:59`) : null;
|
||
const disableAfterBlocksOverride = Boolean(
|
||
pendingOverrideMs != null &&
|
||
parsedDisableAfterMs &&
|
||
Number.isFinite(parsedDisableAfterMs) &&
|
||
pendingOverrideMs >= parsedDisableAfterMs,
|
||
);
|
||
const willPreserveOverride = Boolean(
|
||
pendingOverrideMs != null &&
|
||
!clearOverride &&
|
||
enabled &&
|
||
allowAgentSchedule &&
|
||
!triggerChanged &&
|
||
!maxRunsBlocksOverride &&
|
||
!disableAfterBlocksOverride,
|
||
);
|
||
const canToggleKeepOverride = Boolean(
|
||
pendingOverrideMs != null &&
|
||
enabled &&
|
||
allowAgentSchedule &&
|
||
!triggerChanged &&
|
||
!maxRunsBlocksOverride &&
|
||
!disableAfterBlocksOverride,
|
||
);
|
||
|
||
useEffect(() => {
|
||
if (currentTrigger.kind === "manual") return;
|
||
let live = true;
|
||
void backend
|
||
.previewSchedule(currentTrigger, 3)
|
||
.then((runs) => {
|
||
if (live) setPreviewState({ runs, error: null });
|
||
})
|
||
.catch((e: unknown) => {
|
||
if (live) setPreviewState({ runs: [], error: e instanceof Error ? e.message : String(e) });
|
||
});
|
||
return () => {
|
||
live = false;
|
||
};
|
||
}, [currentTrigger, backend]);
|
||
|
||
const branches =
|
||
workspaceMode === "project" && fetchedBranches.root === projectRoot ? fetchedBranches.list : EMPTY_BRANCHES;
|
||
const previewRuns = currentTrigger.kind === "manual" ? [] : previewState.runs;
|
||
const previewError = currentTrigger.kind === "manual" ? null : previewState.error;
|
||
|
||
const selectedProvider = providers.find((p) => p.id === providerId) ?? providers[0];
|
||
// Exclude interactive permission/approval controls here so they don't conflict with Unattended Permissions.
|
||
const providerConfig = useMemo(
|
||
() =>
|
||
(selectedProvider?.config ?? [])
|
||
.filter((opt) => opt.category !== "permissions" && opt.category !== "approval" && opt.category !== "mode")
|
||
.map((opt) => ({
|
||
...opt,
|
||
current: configMap[opt.id] ?? opt.current,
|
||
})),
|
||
[selectedProvider, configMap],
|
||
);
|
||
|
||
const providerSelectOptions = useMemo<SelectOption[]>(() => {
|
||
const built = buildProviderOptions(providers, tx, providerIcon).filter((o) => o.value !== "__add__");
|
||
if (built.length) return built;
|
||
return [
|
||
{ value: "claude", label: "Claude Code" },
|
||
{ value: "codex", label: "Codex" },
|
||
{ value: "copilot", label: "GitHub Copilot" },
|
||
{ value: "gemini", label: "Gemini CLI" },
|
||
];
|
||
}, [providers, tx]);
|
||
|
||
const workspaceProjects = project?.workspace?.projects ?? (project?.root ? [project.root] : []);
|
||
const branchOptions = useMemo<SelectOption[]>(
|
||
() => [{ value: "", label: tx("Current HEAD") }, ...branches.map((b) => ({ value: b.name, label: b.name }))],
|
||
[branches, tx],
|
||
);
|
||
|
||
const permissionSummary = tx(PERMISSION_OPTIONS.find((o) => o.value === permissions)?.label ?? "Accept edits");
|
||
const continuitySummary = continuity === "sameTask" ? tx("Rolling session") : tx("Fresh session");
|
||
|
||
const toggleWeekday = (day: number) => {
|
||
setWeeklyDays((cur) =>
|
||
cur.includes(day) ? (cur.length > 1 ? cur.filter((d) => d !== day) : cur) : [...cur, day].sort(),
|
||
);
|
||
};
|
||
|
||
const handleSave = async () => {
|
||
if (!name.trim()) {
|
||
setSaveError(tx("Enter a name for the automation."));
|
||
return;
|
||
}
|
||
if (!promptText.trim()) {
|
||
setSaveError(tx("Enter instructions for the agent."));
|
||
return;
|
||
}
|
||
if (previewError) {
|
||
setSaveError(previewError);
|
||
return;
|
||
}
|
||
setSaving(true);
|
||
setSaveError(null);
|
||
try {
|
||
const choices: AgentConfigChoice[] = Object.entries(configMap)
|
||
.filter(([, val]) => !!val)
|
||
.map(([id, value]) => ({ id, value }));
|
||
const maxRunsNum = maxRunsStr.trim() ? Number(maxRunsStr.trim()) : null;
|
||
const disableAfterMs = disableAfterStr.trim() ? Date.parse(`${disableAfterStr.trim()}T23:59:59`) : null;
|
||
await backend.save({
|
||
id: editing?.id ?? null,
|
||
name: name.trim(),
|
||
enabled,
|
||
prompt: { text: promptText.trim(), files: [], images: [] },
|
||
workspace:
|
||
workspaceMode === "chatOnly" || !projectRoot
|
||
? { kind: "chatOnly" }
|
||
: {
|
||
kind: "project",
|
||
root: projectRoot,
|
||
isolation,
|
||
base: isolation === "worktree" && baseBranch ? baseBranch : null,
|
||
autoCleanWorktree: isolation === "worktree" && continuity === "newTask" ? autoCleanWorktree : false,
|
||
},
|
||
continuity,
|
||
provider: providerId,
|
||
config: choices,
|
||
permissions,
|
||
mcpOverrides,
|
||
skillOverrides,
|
||
memoryOverrides,
|
||
trigger: currentTrigger,
|
||
allowAgentSchedule,
|
||
clearOverride,
|
||
misfirePolicy: misfirePolicy === "default" ? null : (misfirePolicy as AutomationMisfirePolicy),
|
||
maxRuns: maxRunsNum && maxRunsNum > 0 ? Math.round(maxRunsNum) : null,
|
||
disableAfterMs: disableAfterMs && Number.isFinite(disableAfterMs) ? disableAfterMs : null,
|
||
});
|
||
await refreshAutomations(backend);
|
||
closeAutomationDialog();
|
||
} catch (e: unknown) {
|
||
setSaveError(e instanceof Error ? e.message : String(e));
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
};
|
||
|
||
return (
|
||
<Dialog
|
||
open={dialog.open}
|
||
onClose={closeAutomationDialog}
|
||
title={editing ? tx("Edit Automation") : tx("New Automation")}
|
||
width={560}
|
||
maxHeight={760}
|
||
resizable="both"
|
||
footerStart={<Checkbox checked={enabled} onChange={setEnabled} label="Active schedule" />}
|
||
buttons={[
|
||
{ label: "Cancel", role: "cancel" },
|
||
{
|
||
label: editing ? "Save Changes" : "Create Automation",
|
||
role: "default",
|
||
disabled: saving || !!previewError,
|
||
onClick: () => void handleSave(),
|
||
},
|
||
]}
|
||
>
|
||
<div className={styles.dialogForm}>
|
||
{saveError && (
|
||
<div className={styles.errorBox} role="alert">
|
||
<Icon name="error" size={14} />
|
||
<span>{saveError}</span>
|
||
</div>
|
||
)}
|
||
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-name-input">
|
||
<T>Name</T>
|
||
</label>
|
||
<Input
|
||
id="automation-name-input"
|
||
value={name}
|
||
onChange={(e) => setName(e.target.value)}
|
||
placeholder="Morning PR & CI Triage"
|
||
/>
|
||
</div>
|
||
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Agent</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Agent")}
|
||
value={providerId}
|
||
options={providerSelectOptions}
|
||
onChange={setProviderId}
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-prompt-input">
|
||
<T>Prompt Instructions</T>
|
||
</label>
|
||
<div className={styles.promptBox}>
|
||
<textarea
|
||
id="automation-prompt-input"
|
||
className={styles.promptTextarea}
|
||
value={promptText}
|
||
onChange={(e) => setPromptText(e.target.value)}
|
||
placeholder={tx("Describe what the agent should inspect, verify, or report on each run…")}
|
||
/>
|
||
<div className={styles.promptBar}>
|
||
<ConfigPickers
|
||
config={providerConfig}
|
||
onChange={(id, val) => setConfigMap((prev) => ({ ...prev, [id]: val }))}
|
||
/>
|
||
<McpPicker provider={providerId} overrides={mcpOverrides} onChange={setMcpOverrides} />
|
||
<SkillsPicker provider={providerId} overrides={skillOverrides} onChange={setSkillOverrides} />
|
||
<MemoryPicker provider={providerId} overrides={memoryOverrides} onChange={setMemoryOverrides} />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Schedule</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Schedule")}
|
||
value={triggerKind}
|
||
options={SCHEDULE_KIND_OPTIONS}
|
||
onChange={(v) => setTriggerKind(v)}
|
||
/>
|
||
</div>
|
||
|
||
{(triggerKind === "daily" || triggerKind === "weekdays" || triggerKind === "weekly") && (
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-time-input">
|
||
<T>Run Time</T>
|
||
</label>
|
||
<Input
|
||
id="automation-time-input"
|
||
type="time"
|
||
value={timeStr}
|
||
onChange={(e) => setTimeStr(e.target.value)}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
{triggerKind === "hourly" && (
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-minute-input">
|
||
<T>Minute Past Hour (0–59)</T>
|
||
</label>
|
||
<Input
|
||
id="automation-minute-input"
|
||
type="number"
|
||
min={0}
|
||
max={59}
|
||
value={hourlyMinute}
|
||
onChange={(e) => setHourlyMinute(e.target.value)}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
{triggerKind === "oneShot" && (
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-oneshot-input">
|
||
<T>Run Once At</T>
|
||
</label>
|
||
<Input
|
||
id="automation-oneshot-input"
|
||
type="datetime-local"
|
||
value={oneShotValue}
|
||
onChange={(e) => setOneShotValue(e.target.value)}
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{triggerKind === "weekly" && (
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Days of Week</T>
|
||
</span>
|
||
<div className={styles.weekdayRow}>
|
||
{WEEKDAYS.map((w) => (
|
||
<button
|
||
key={w.day}
|
||
type="button"
|
||
className={clsx(styles.dayBtn, weeklyDays.includes(w.day) && styles.dayBtnActive)}
|
||
aria-pressed={weeklyDays.includes(w.day)}
|
||
onClick={() => toggleWeekday(w.day)}
|
||
>
|
||
{tx(w.label)}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{triggerKind === "cron" && (
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-cron-input">
|
||
<T>Cron Expression (5-field)</T>
|
||
</label>
|
||
<Input
|
||
id="automation-cron-input"
|
||
value={cronExpr}
|
||
onChange={(e) => setCronExpr(e.target.value)}
|
||
placeholder="0 9,15 * * MON-FRI"
|
||
/>
|
||
</div>
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-tz-input">
|
||
<T>Time Zone</T>
|
||
</label>
|
||
<Input
|
||
id="automation-tz-input"
|
||
value={timeZone}
|
||
onChange={(e) => setTimeZone(e.target.value)}
|
||
placeholder="America/Los_Angeles"
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{pendingOverrideMs != null && (
|
||
<div
|
||
className={clsx(styles.overrideCard, !willPreserveOverride && styles.overrideCardClearing)}
|
||
data-testid="automation-dialog-override"
|
||
>
|
||
<div className={styles.overrideHeader}>
|
||
<span className={styles.overrideTitle}>
|
||
<Icon name="clock" size={13} />
|
||
<strong>
|
||
<T>Next run (scheduled by agent):</T>
|
||
</strong>
|
||
<span>{formatShortTimestamp(pendingOverrideMs)}</span>
|
||
</span>
|
||
{willPreserveOverride ? (
|
||
<Button size="small" onClick={() => setClearOverride(true)}>
|
||
<T>Clear override</T>
|
||
</Button>
|
||
) : canToggleKeepOverride ? (
|
||
<Button size="small" onClick={() => setClearOverride(false)}>
|
||
<T>Keep override</T>
|
||
</Button>
|
||
) : null}
|
||
</div>
|
||
{willPreserveOverride ? (
|
||
pendingPromptOverride ? (
|
||
<div className={styles.overridePrompt}>“{pendingPromptOverride}”</div>
|
||
) : null
|
||
) : (
|
||
<div className={styles.fieldHint}>
|
||
<T>Will be cleared when you save.</T>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{triggerKind !== "manual" && (
|
||
<div className={styles.previewLine} data-testid="automation-schedule-preview">
|
||
{previewError ? (
|
||
<span className={styles.previewError}>{previewError}</span>
|
||
) : previewRuns.length > 0 ? (
|
||
<>
|
||
<span className={styles.previewLabel}>
|
||
{willPreserveOverride ? <T>Fallback schedule:</T> : <T>Upcoming runs:</T>}
|
||
</span>
|
||
<span>{previewRuns.map((ms) => formatShortTimestamp(ms)).join(" · ")}</span>
|
||
</>
|
||
) : willPreserveOverride && triggerKind === "oneShot" ? (
|
||
<span>
|
||
<T>Seed run already completed; next run is scheduled by the agent above.</T>
|
||
</span>
|
||
) : (
|
||
<span>
|
||
<T>No future runs match this schedule.</T>
|
||
</span>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
<div className={styles.workspaceRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Workspace Target</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Workspace Target")}
|
||
value={workspaceMode}
|
||
options={[
|
||
...(projectRoot ? [{ value: "project", label: tx("Project workspace") }] : []),
|
||
{ value: "chatOnly", label: tx("No workspace (chat only)") },
|
||
]}
|
||
onChange={(v) => setWorkspaceMode(v as "project" | "chatOnly")}
|
||
/>
|
||
</div>
|
||
|
||
{workspaceMode === "project" && projectRoot && workspaceProjects.length > 1 && (
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Repository</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Repository")}
|
||
value={projectRoot}
|
||
options={workspaceProjects.map((p) => ({ value: p, label: basename(p) }))}
|
||
onChange={setProjectRoot}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
{workspaceMode === "project" && projectRoot && (
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Checkout Isolation</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Checkout Isolation")}
|
||
value={isolation}
|
||
options={[
|
||
{ value: "worktree", label: tx("Isolated Git worktree"), detail: tx("Recommended") },
|
||
{ value: "local", label: tx("Local checkout") },
|
||
]}
|
||
onChange={(v) => setIsolation(v as Isolation)}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
{workspaceMode === "project" && projectRoot && isolation === "worktree" && (
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Base Branch</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Base Branch")}
|
||
value={baseBranch}
|
||
options={branchOptions}
|
||
onChange={setBaseBranch}
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className={styles.advancedSection}>
|
||
<button
|
||
type="button"
|
||
className={styles.advancedToggle}
|
||
aria-expanded={advancedOpen}
|
||
onClick={() => setAdvancedOpen((v) => !v)}
|
||
>
|
||
<span className={styles.advancedTitle}>
|
||
<Icon name={advancedOpen ? "chevron-down" : "chevron-right"} size={13} />
|
||
<T>Advanced</T>
|
||
</span>
|
||
{!advancedOpen && (
|
||
<span className={styles.advancedSummary}>
|
||
{permissionSummary} · {continuitySummary}
|
||
{allowAgentSchedule ? ` · ${tx("Self-scheduling")}` : ""}
|
||
</span>
|
||
)}
|
||
</button>
|
||
|
||
{advancedOpen && (
|
||
<div className={styles.advancedBody}>
|
||
<div className={styles.fieldGroup}>
|
||
<Checkbox
|
||
checked={allowAgentSchedule}
|
||
onChange={setAllowAgentSchedule}
|
||
label="Allow agent to schedule its next run (unattended)"
|
||
/>
|
||
|
||
{allowAgentSchedule && (
|
||
<div className={styles.fieldHint}>
|
||
<T>
|
||
Active runs of this automation can call schedule_next_run over MCP to set a one-time next-run
|
||
override (keeping the base schedule and prompt intact; 60s minimum delay, respects Stop After Runs
|
||
and Disable After Date).
|
||
</T>
|
||
{triggerKind === "oneShot" && (
|
||
<>
|
||
{" "}
|
||
<T>
|
||
With One-shot, the schedule stays active while a run executes and disables automatically once
|
||
a run finishes without scheduling another.
|
||
</T>
|
||
</>
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className={styles.fieldGroup}>
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Unattended Permissions</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Unattended Permissions")}
|
||
value={permissions}
|
||
options={PERMISSION_OPTIONS}
|
||
onChange={(v) => setPermissions(v)}
|
||
/>
|
||
</div>
|
||
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Session Continuity</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Session Continuity")}
|
||
value={continuity}
|
||
options={CONTINUITY_OPTIONS}
|
||
onChange={(v) => setContinuity(v)}
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
{agentSettings.newTaskApprovals === "ask" && permissions !== "default" && (
|
||
<div className={styles.fieldHint}>
|
||
<T>
|
||
Your interactive New Tasks setting is Asking for approval, so scheduled turns are capped to ask
|
||
before edits and commands.
|
||
</T>
|
||
</div>
|
||
)}
|
||
|
||
{permissions === "allowAll" && workspaceMode === "project" && isolation === "local" && (
|
||
<div className={styles.fieldHint} style={{ color: "var(--warning)" }}>
|
||
<T>
|
||
Warning: Autonomous mode on a local checkout can modify your working files directly. Prefer an
|
||
isolated Git worktree.
|
||
</T>
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{workspaceMode === "project" && isolation === "worktree" && continuity === "newTask" && (
|
||
<Checkbox
|
||
checked={autoCleanWorktree}
|
||
onChange={setAutoCleanWorktree}
|
||
label="Auto-delete temporary worktree when the run makes zero file changes"
|
||
/>
|
||
)}
|
||
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<span className={styles.fieldLabel}>
|
||
<T>Missed Schedule Policy</T>
|
||
</span>
|
||
<Select
|
||
aria-label={tx("Missed Schedule Policy")}
|
||
value={misfirePolicy}
|
||
options={MISFIRE_OPTIONS}
|
||
onChange={setMisfirePolicy}
|
||
/>
|
||
</div>
|
||
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-max-runs-input">
|
||
<T>Stop After Runs (optional)</T>
|
||
</label>
|
||
<Input
|
||
id="automation-max-runs-input"
|
||
type="number"
|
||
min={1}
|
||
value={maxRunsStr}
|
||
onChange={(e) => setMaxRunsStr(e.target.value)}
|
||
placeholder="50"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div className={styles.fieldRow}>
|
||
<div className={styles.fieldGroup}>
|
||
<label className={styles.fieldLabel} htmlFor="automation-disable-after-input">
|
||
<T>Disable After Date (optional)</T>
|
||
</label>
|
||
<Input
|
||
id="automation-disable-after-input"
|
||
type="date"
|
||
value={disableAfterStr}
|
||
onChange={(e) => setDisableAfterStr(e.target.value)}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</Dialog>
|
||
);
|
||
}
|