дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
fix(agents): add scheduling to the new task composer
Цей коміт міститься в:
1 джерело
2f3f08efde
коміт
134c0e6cb6
6 files changed
+111
-23
No files matched your search
@@ -703,6 +703,30 @@ test("running composer replaces Send with Stop and keeps the Agents header focus
|
||||
await expect(page.getByRole("menuitem", { name: "Stop", exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("opens persistent automation scheduling directly from a new agent task", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 840 });
|
||||
await installAutomationDesktopHarness(page);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const storeModule = "/src/features/agents/store.ts";
|
||||
const store = await import(/* @vite-ignore */ storeModule);
|
||||
store.openHome();
|
||||
});
|
||||
|
||||
const composer = page.getByRole("textbox", { name: "Message", exact: true });
|
||||
await composer.fill("Review the weekly changelog");
|
||||
const clock = page.getByRole("button", { name: "New Agent Automation…" });
|
||||
await expect(clock).toBeVisible();
|
||||
await clock.click();
|
||||
const dialog = page.getByRole("dialog", { name: "New Automation" });
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(dialog.getByLabel("Prompt Instructions")).toHaveValue("Review the weekly changelog");
|
||||
await expect(dialog.getByRole("button", { name: "Agent", exact: true })).toContainText("Claude Code");
|
||||
await dialog.getByRole("button", { name: "Cancel" }).click();
|
||||
await expect(dialog).not.toBeVisible();
|
||||
await expect(composer).toHaveText("Review the weekly changelog");
|
||||
});
|
||||
|
||||
test("schedules in-session Send Later, /loop recurring prompts, and /automate from SessionComposer", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
|
||||
@@ -102,7 +102,7 @@ function toDatetimeLocalValue(ms: number): string {
|
||||
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}:${dialog.prefillTask?.id ?? ""}`;
|
||||
const formKey = `${dialog.editing?.id ?? "new"}:${dialog.editing?.updatedMs ?? 0}:${dialog.prefillName}:${dialog.prefillPrompt}:${JSON.stringify(dialog.prefillSettings)}`;
|
||||
return <AutomationDialogBody key={formKey} backend={backend} />;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ function AutomationDialogBody({ backend }: { backend: AutomationsBackend }) {
|
||||
const draftProvider = useAgents((s) => s.draft.provider);
|
||||
|
||||
const editing = dialog.editing;
|
||||
const preTask = dialog.prefillTask;
|
||||
const preSettings = dialog.prefillSettings;
|
||||
const defaultRoot = project?.root ?? "";
|
||||
const fallbackProvider = providers[0]?.id ?? draftProvider ?? "claude";
|
||||
|
||||
@@ -128,35 +128,36 @@ function AutomationDialogBody({ backend }: { backend: AutomationsBackend }) {
|
||||
});
|
||||
const [projectRoot, setProjectRoot] = useState(() => {
|
||||
if (editing && editing.workspace.kind === "project") return editing.workspace.root || defaultRoot;
|
||||
return preTask?.projectRoot ?? defaultRoot;
|
||||
return preSettings?.projectRoot ?? defaultRoot;
|
||||
});
|
||||
const [isolation, setIsolation] = useState<Isolation>(() => {
|
||||
if (editing && editing.workspace.kind === "project") return editing.workspace.isolation;
|
||||
return preTask?.isolation ?? "worktree";
|
||||
return preSettings?.isolation ?? "worktree";
|
||||
});
|
||||
const [baseBranch, setBaseBranch] = useState<string>(() => {
|
||||
if (editing && editing.workspace.kind === "project") return editing.workspace.base ?? "";
|
||||
return preTask?.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 || preTask?.provider || fallbackProvider);
|
||||
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 (preTask) return Object.fromEntries(preTask.config.filter((c) => c.current).map((c) => [c.id, c.current!]));
|
||||
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 ?? preTask?.mcpOverrides ?? {}),
|
||||
...(editing?.mcpOverrides ?? preSettings?.mcpOverrides ?? {}),
|
||||
}));
|
||||
const [skillOverrides, setSkillOverrides] = useState<Record<string, AgentSkillMode>>(() => ({
|
||||
...(editing?.skillOverrides ?? preTask?.skillOverrides ?? {}),
|
||||
...(editing?.skillOverrides ?? preSettings?.skillOverrides ?? {}),
|
||||
}));
|
||||
const [memoryOverrides, setMemoryOverrides] = useState<AgentMemoryOverrides | null>(
|
||||
() => editing?.memoryOverrides ?? preTask?.memoryOverrides ?? null,
|
||||
() => editing?.memoryOverrides ?? preSettings?.memoryOverrides ?? null,
|
||||
);
|
||||
|
||||
const [triggerKind, setTriggerKind] = useState<TriggerKind>(() => editing?.trigger.kind ?? "weekdays");
|
||||
|
||||
@@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor, within } from "@testing-library/rea
|
||||
import type { AgentConfigOption, AgentProvider, CustomAgentInput, NewAgentTask, ProjectInfo } from "@/bindings";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { HomeEditor } from "./HomeEditor";
|
||||
import { closeAutomationDialog, useAutomations } from "./automationsModel";
|
||||
import homeStyles from "./Home.module.css";
|
||||
import { HOME, disconnect, savedDraft, updateComposer, useAgents } from "./store";
|
||||
|
||||
@@ -59,6 +60,7 @@ const option = (id: string, category: string, values: string[], current: string)
|
||||
|
||||
beforeEach(() => {
|
||||
disconnect();
|
||||
closeAutomationDialog();
|
||||
backend.branches = [];
|
||||
backend.create.mockReset().mockImplementation((req: NewAgentTask) => ok({ id: "new", config: req.config }));
|
||||
backend.probe.mockReset().mockImplementation(() => ok(null));
|
||||
@@ -119,6 +121,37 @@ function codexWithFast(current = "false") {
|
||||
useAgents.setState({ providers: [codex], draft: savedDraft({ provider: "codex", config: {} }) });
|
||||
}
|
||||
|
||||
it.each([false, true])("opens automation scheduling from the New Task composer (docked: %s)", async (docked) => {
|
||||
render(<HomeEditor docked={docked} />);
|
||||
await chooseModel("small");
|
||||
await chooseEffort("medium");
|
||||
const schedule = screen.getByRole("button", { name: "New Agent Automation…" });
|
||||
fireEvent.click(schedule);
|
||||
expect(useAutomations.getState().dialog).toMatchObject({
|
||||
open: true,
|
||||
prefillPrompt: "Check the project",
|
||||
prefillSettings: {
|
||||
provider: "fake",
|
||||
config: expect.arrayContaining([
|
||||
expect.objectContaining({ id: "model", current: "small" }),
|
||||
expect.objectContaining({ id: "effort", current: "medium" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
expect(backend.create).not.toHaveBeenCalled();
|
||||
expect(useAgents.getState().composers.get(HOME)?.text).toBe("Check the project");
|
||||
closeAutomationDialog();
|
||||
});
|
||||
|
||||
it("allows scheduling even with an empty New Task draft", () => {
|
||||
updateComposer(HOME, { text: "" });
|
||||
render(<HomeEditor />);
|
||||
expect(screen.getByRole("button", { name: "Start" })).toBeDisabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "New Agent Automation…" }));
|
||||
expect(useAutomations.getState().dialog).toMatchObject({ open: true, prefillPrompt: "" });
|
||||
closeAutomationDialog();
|
||||
});
|
||||
|
||||
it.each(["false", "true"])("leaves an untouched Codex Fast default (%s) to the runtime", async (current) => {
|
||||
codexWithFast(current);
|
||||
render(<HomeEditor />);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { executeAction } from "@/platform/actions";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { useTx, useTxTemplate } from "@/platform/i18n";
|
||||
import { basename, useProject } from "@/platform/project";
|
||||
import { Icon, Select, T, tooltipAttrs, type SelectOption } from "@/ui";
|
||||
import { Icon, IconButton, Select, T, tooltipAttrs, type SelectOption } from "@/ui";
|
||||
import { defaultTaskProject } from "./project";
|
||||
import { maybeEditorService, useEditorShown, type EditorInput } from "@/workbench/contributions";
|
||||
import { Composer } from "./Composer";
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
} from "./store";
|
||||
import { useGitEnabled } from "@/platform/gitEnabled";
|
||||
import { useAgentSettings } from "./agentSettings";
|
||||
import { openAutomationDialog } from "./automationsModel";
|
||||
import styles from "./Home.module.css";
|
||||
|
||||
export function HomeEditor({ docked = false, input }: { docked?: boolean; input?: EditorInput }) {
|
||||
@@ -297,12 +298,36 @@ export function HomeEditor({ docked = false, input }: { docked?: boolean; input?
|
||||
</>
|
||||
}
|
||||
actions={
|
||||
<SubmitButton
|
||||
label={starting ? "Starting…" : "Start"}
|
||||
pending={starting}
|
||||
disabled={!canStart}
|
||||
onClick={start}
|
||||
/>
|
||||
<>
|
||||
<IconButton
|
||||
icon="clock"
|
||||
size="small"
|
||||
title="New Agent Automation…"
|
||||
onClick={() =>
|
||||
openAutomationDialog({
|
||||
prefillPrompt: composer.text.trim(),
|
||||
prefillSettings: {
|
||||
projectRoot: root || null,
|
||||
isolation,
|
||||
base: isolation === "worktree" ? draft.base : null,
|
||||
provider: provider?.id ?? draft.provider,
|
||||
config: config.filter(
|
||||
(o) => o.category !== "permissions" && o.category !== "approval" && o.category !== "mode",
|
||||
),
|
||||
mcpOverrides: draft.mcpOverrides,
|
||||
skillOverrides: draft.skillOverrides,
|
||||
memoryOverrides: draft.memoryOverrides,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
<SubmitButton
|
||||
label={starting ? "Starting…" : "Start"}
|
||||
pending={starting}
|
||||
disabled={!canStart}
|
||||
onClick={start}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{/* Under the box: where the agent works. Project and checkout on the left, the branch on the right. */}
|
||||
|
||||
@@ -636,12 +636,17 @@ export const defaultAutomationsBackend: AutomationsBackend = {
|
||||
// Store & Navigation
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
type AutomationSettingsPrefill = Pick<
|
||||
AgentTask,
|
||||
"projectRoot" | "isolation" | "base" | "provider" | "config" | "mcpOverrides" | "skillOverrides" | "memoryOverrides"
|
||||
>;
|
||||
|
||||
export interface AutomationDialogRequest {
|
||||
open: boolean;
|
||||
editing: AgentAutomation_Serialize | null;
|
||||
prefillPrompt: string;
|
||||
prefillName: string;
|
||||
prefillTask: AgentTask | null;
|
||||
prefillSettings: AutomationSettingsPrefill | null;
|
||||
}
|
||||
|
||||
interface AutomationsState {
|
||||
@@ -666,7 +671,7 @@ export const useAutomations = create<AutomationsState>(() => ({
|
||||
editing: null,
|
||||
prefillPrompt: "",
|
||||
prefillName: "",
|
||||
prefillTask: null,
|
||||
prefillSettings: null,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -701,7 +706,7 @@ export function openAutomationDialog(opts?: {
|
||||
editing?: AgentAutomation_Serialize | null;
|
||||
prefillPrompt?: string;
|
||||
prefillName?: string;
|
||||
prefillTask?: AgentTask | null;
|
||||
prefillSettings?: AutomationSettingsPrefill | null;
|
||||
}): void {
|
||||
useAutomations.setState({
|
||||
dialog: {
|
||||
@@ -709,7 +714,7 @@ export function openAutomationDialog(opts?: {
|
||||
editing: opts?.editing ?? null,
|
||||
prefillPrompt: opts?.prefillPrompt ?? "",
|
||||
prefillName: opts?.prefillName ?? "",
|
||||
prefillTask: opts?.prefillTask ?? null,
|
||||
prefillSettings: opts?.prefillSettings ?? null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ export function SessionComposer({
|
||||
if (parsedSchedule) {
|
||||
if (parsedSchedule.kind === "automate") {
|
||||
updateComposer(task.id, emptyDraft());
|
||||
openAutomationDialog({ prefillPrompt: parsedSchedule.prompt, prefillTask: task });
|
||||
openAutomationDialog({ prefillPrompt: parsedSchedule.prompt, prefillSettings: task });
|
||||
return;
|
||||
}
|
||||
setSending(true);
|
||||
@@ -831,7 +831,7 @@ function ScheduleSendButton({
|
||||
run: () => {
|
||||
const prefill = draftText.trim();
|
||||
if (prefill) updateComposer(task.id, emptyDraft());
|
||||
openAutomationDialog({ prefillPrompt: prefill, prefillTask: task });
|
||||
openAutomationDialog({ prefillPrompt: prefill, prefillSettings: task });
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Reference in new issue
Заблокувати користувача