diff --git a/dashboard/e2e/skill-schedules.spec.ts b/dashboard/e2e/skill-schedules.spec.ts index 64376e22..8a729e4a 100644 --- a/dashboard/e2e/skill-schedules.spec.ts +++ b/dashboard/e2e/skill-schedules.spec.ts @@ -11,10 +11,26 @@ interface Backend { schedules: Record[]; posted: Record[]; ran: string[]; + resolves: number; + polls: number; } +const SERVER = { id: "traffic-mcp", source: { kind: "git", repo: "acme/traffic-mcp", commit: "0123456789abcdef0123456789abcdef01234567" }, command: ["python3", "server.py"], aws_account: "111122223333", env: {} }; +const RESOLUTION = { + at: "2026-11-30T12:00:00Z", + tools: [ + { name: "traffic_counts", source: "sandbox:traffic-mcp", tool: "traffic_counts", risk: "read", basis: "model", why: "looks up visit counts" }, + { name: "tag_page", source: "sandbox:traffic-mcp", tool: "tag_page", risk: "write", basis: "annotation", why: "" }, + { name: "set_banner", source: "sandbox:traffic-mcp", tool: "set_banner", risk: "consequential", basis: "annotation", why: "" }, + ], + missing: [], + servers: [SERVER], + problems: [], + memory: ["snapshots"], +}; + async function mockApi(page: Page): Promise { - const db: Backend = { schedules: [], posted: [], ran: [] }; + const db: Backend = { schedules: [], posted: [], ran: [], resolves: 0, polls: 0 }; const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); await page.route((url) => url.hostname !== "localhost", (route) => route.abort()); @@ -33,6 +49,15 @@ async function mockApi(page: Page): Promise { servers: [{ id: "acme-traffic", name: "Traffic", kind: "remote" }], aws_accounts: [], }); + if (p === "/api/skill-runs/resolve" && method === "POST") { + db.resolves += 1; + return json(route, { id: "01DRAFT" }); + } + // The worker answers on its second look, as it does after a moment. + if (p === "/api/skill-runs/resolve/01DRAFT") { + db.polls += 1; + return json(route, { draft: { id: "01DRAFT", skill_repo: "acme/skills", skill_path: "skills/visit-count/SKILL.md", skill_name: "visit-count", done: db.polls > 1, resolution: db.polls > 1 ? RESOLUTION : null } }); + } if (p === "/api/skill-runs" && method === "GET") return json(route, { schedules: db.schedules, can_edit: true }); if (p === "/api/skill-runs" && method === "POST") { const body = JSON.parse(req.postData() as string) as Record; @@ -61,7 +86,7 @@ async function mockApi(page: Page): Promise { return db; } -test("an admin schedules a skill, presses Run now and reads the run's report on its page", async ({ page }) => { +test("an admin picks a skill and a time, presses Run now and reads the run's report on its page", async ({ page }) => { const db = await mockApi(page); await page.goto("/skills/schedules/"); await expect(page.getByRole("heading", { name: "Scheduled skill runs" })).toBeVisible(); @@ -71,14 +96,20 @@ test("an admin schedules a skill, presses Run now and reads the run's report on const form = page.getByRole("form", { name: "Schedule" }); await form.getByRole("combobox", { name: "Skill" }).click(); await page.getByRole("option", { name: "visit-count (acme/skills)" }).click(); - await form.getByRole("textbox", { name: "Schedule" }).fill("23 7 * * MON"); + await form.getByRole("textbox", { name: "Schedule", exact: true }).fill("23 7 * * MON"); await form.getByRole("textbox", { name: "Time zone" }).fill("America/New_York"); - await form.getByRole("button", { name: "Add a tool" }).click(); - await form.getByRole("textbox", { name: "Name in the skill" }).fill("traffic_counts"); - await form.getByRole("combobox", { name: "Server" }).click(); - await page.getByRole("option", { name: "Traffic" }).click(); - await form.getByTestId("tool-row").getByRole("checkbox", { name: "Only reads" }).check(); - await form.getByRole("textbox", { name: "Memory folder" }).fill("snapshots"); + // The skill's tools are found for it: nothing to name or tick. + const found = form.getByTestId("tools-found"); + await expect(found.getByTestId("tool-found")).toHaveCount(3); + await expect(found.getByTestId("tool-found").nth(0)).toContainText("traffic_counts"); + await expect(found.getByTestId("tool-found").nth(0)).toContainText("acme/traffic-mcp at 0123456, in the run's sandbox"); + await expect(found.getByTestId("tool-found").nth(0)).toContainText("Reads"); + await expect(found.getByTestId("tool-found").nth(0)).toContainText("read from its description: looks up visit counts"); + await expect(found.getByTestId("tool-found").nth(1)).toContainText("Writes: refused"); + await expect(found.getByTestId("tool-found").nth(2)).toContainText("Never runs"); + await expect(found.getByTestId("tool-found").nth(2).getByRole("combobox")).toHaveCount(0); + expect(db.resolves).toBe(1); + await expect(form.getByRole("textbox", { name: "Memory folder" })).toHaveValue("snapshots"); await form.getByRole("button", { name: "Save schedule" }).click(); await expect(page.getByText("Schedule saved")).toBeVisible(); @@ -88,7 +119,13 @@ test("an admin schedules a skill, presses Run now and reads the run's report on skill_path: "skills/visit-count/SKILL.md", cron: "23 7 * * MON", timezone: "America/New_York", - tools: [{ name: "traffic_counts", server: "acme-traffic", tool: "", reads_only: true }], + tools: [ + { name: "traffic_counts", server: "sandbox:traffic-mcp", tool: "" }, + { name: "tag_page", server: "sandbox:traffic-mcp", tool: "" }, + { name: "set_banner", server: "sandbox:traffic-mcp", tool: "" }, + ], + stdio: [SERVER], + auto_tools: true, state_dirs: ["snapshots"], allow_writes: false, }); diff --git a/dashboard/e2e/wide-data/skill-runs.ts b/dashboard/e2e/wide-data/skill-runs.ts index 7102cccb..a4220231 100644 --- a/dashboard/e2e/wide-data/skill-runs.ts +++ b/dashboard/e2e/wide-data/skill-runs.ts @@ -15,7 +15,16 @@ const schedule = { cron: "23 7 * * MON,TUE,WED,THU,FRI", timezone: "America/Argentina/ComodRivadavia", paused: false, - tools: [{ name: TOOL, server: SERVER, tool: TOKEN, reads_only: true }], + tools: [{ name: TOOL, server: `sandbox:${SERVER}`, tool: TOKEN }], + auto_tools: true, + stdio: [{ id: SERVER, source: { kind: "git", repo: REPO, commit: "4f1c2a9e8b7d6c5f4e3d2c1b0a9f8e7d6c5b4a39" }, command: ["node", "bin/server-mcp.js"], aws_account: "123456789012", env: {} }], + resolution: { + at: iso(60), + tools: [{ name: TOOL, source: `sandbox:${SERVER}`, tool: TOKEN, risk: "read", basis: "model", why: SENTENCE }], + missing: ["execute_a_query_against_a_service_nobody_connected_with_a_long_name"], + servers: [], + problems: [SENTENCE], + }, aws: { account: "123456789012", region: "ap-southeast-2", workgroup: TOKEN, max_gb: 30 }, allow_writes: false, state_dirs: ["snapshots-of-every-week-kept-between-runs", TOKEN], diff --git a/dashboard/src/app/skills/schedules/page.tsx b/dashboard/src/app/skills/schedules/page.tsx index a9f8100a..9e14d3ba 100644 --- a/dashboard/src/app/skills/schedules/page.tsx +++ b/dashboard/src/app/skills/schedules/page.tsx @@ -27,9 +27,17 @@ import { type ScheduleOptions, type SkillRunEntry, type SkillSchedule, - type ToolGrant, + type Resolution, + basisLabel, + sourceLabel, } from "@/lib/skill-runs"; +const WHEN: { value: "off" | "always" | "failure"; label: string }[] = [ + { value: "off", label: "Never (the run page only)" }, + { value: "always", label: "After every run" }, + { value: "failure", label: "When a run fails" }, +]; + const STATUS_TONE: Record = { queued: "neutral", running: "info", @@ -54,14 +62,85 @@ function Field({ label, hint, children, htmlFor }: { label: string; hint?: strin ); } +/** The skill's tools, as reading it found them: where each comes from and how far it may go. + * Nothing to tick: an admin may only change a tool's risk. */ +function ToolsFound({ + d, + resolution, + reading, + onRisk, +}: { + d: ScheduleDraft; + resolution: Resolution | null; + reading: boolean; + onRisk: (name: string, risk: "" | "read" | "write") => void; +}) { + if (!d.skill_repo) return null; + if (reading && !resolution) { + return ( +

+ Finding the skill's tools: its connected servers, and servers in your repositories it can start in its sandbox. +

+ ); + } + if (!resolution) return null; + return ( +
+ {resolution.tools.length === 0 ? ( +

The skill names no tool a connected server offers. It runs with its scripts only.

+ ) : ( +
    + {resolution.tools.map((t) => { + const own = d.tools.find((g) => g.name === t.name); + const never = t.risk === "consequential"; + return ( +
  • + {t.name} + {sourceLabel(t.source, resolution.servers)} + + {t.risk === "read" ? "Reads" : never ? "Never runs" : d.allow_writes ? "Writes" : "Writes: refused"} + + {basisLabel(t)} + {!never && ( + + setTool(i, { name: e.target.value })} /> - - - setTool(i, { tool: e.target.value })} /> - - - -
- ))} - - {options.servers.length === 0 && ( -

- No MCP server is connected yet. Connect one. -

- )} + set({ tools: d.tools.map((t) => (t.name === name ? { ...t, risk: risk || undefined, reads_only: false } : t)) })} + />
@@ -215,11 +297,7 @@ function ScheduleForm({ className="w-full" value={d.notify.chat} onChange={(v) => set({ notify: { ...d.notify, chat: v as ScheduleDraft["notify"]["chat"] } })} - options={[ - { value: "off", label: "Never (the run page only)" }, - { value: "always", label: "After every run" }, - { value: "failure", label: "When a run fails" }, - ]} + options={WHEN} />
@@ -234,6 +312,41 @@ function ScheduleForm({
+
+ + set({ notify: { ...d.notify, emails: e.target.value.split(",").map((x) => x.trim()) } })} + /> + + + set({ notify: { ...d.notify, jira_ticket: e.target.value } })} /> + + + set({ notify: { ...d.notify, jira_project: e.target.value } })} /> + +
+