From db924d9e774331e0605bffffb8fa61af271c2a98 Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 16 Nov 2026 11:29:23 +0100 Subject: [PATCH] swarm ui: a fire now button on each schedule --- docs/2-handbook/swarm/schedules.md | 5 +++++ docs/4-implementation/web-ui/swarm-ui.md | 5 ++++- .../src/pages/schedules/ScheduleCard.tsx | 18 +++++++++++++++++- .../src/pages/schedules/ScheduleTypes.ts | 10 ++++++++++ .../src/pages/schedules/SchedulesPage.tsx | 13 ++++++++++++- .../packages/swarm-ui/test/fire-now.test.mjs | 14 ++++++++++++++ 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 frontend/packages/swarm-ui/test/fire-now.test.mjs diff --git a/docs/2-handbook/swarm/schedules.md b/docs/2-handbook/swarm/schedules.md index 0b5d2d839..cd6ec6df7 100644 --- a/docs/2-handbook/swarm/schedules.md +++ b/docs/2-handbook/swarm/schedules.md @@ -10,6 +10,11 @@ Operators manage them with `swarmctl schedule` on the swarm controller's host. Agents can't create, change or remove one. For a one-off wake an agent sets itself, it uses `remind`, which stays inside its container. +The schedules card on the swarm UI's messages tab does the same, and adds **fire +now**, which fires a prompt at once by moving its start to this moment. A +repeating prompt then carries on from now, at its interval, not at its old clock +times. A paused prompt has no fire now; resume it first. + ## Managing them ```console diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index 0d86cf043..b34e03603 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -352,7 +352,10 @@ The **schedules** card on the **messages** tab holds one card per scheduled prompt. It starts shut and reads nothing until you open it; the old `/schedules` address redirects to the messages tab. The **name** is the card's title, with the **agents** it fires for, the message, how often it repeats and -when it fires next. **edit** turns the card into its own form; **pause** and +when it fires next. **edit** turns the card into its own form; **fire now** sends +`PATCH /api/schedules/{id}` with the current second as `anchor_unix`, so a start +that has passed fires its latest time right away and a repeating schedule goes on +from there at its interval (a paused schedule has no fire now); **pause** and **resume** stop and restart it; **remove** deletes it after a confirmation. **+ schedule** opens an empty form above the list, and the filters narrow the list by name, agent or state (`active`, `paused`, or `past` for a one-shot diff --git a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx index 7ee321e52..3ec824227 100644 --- a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx @@ -1,6 +1,6 @@ // — one scheduled prompt as a card: its name as the title, // "agents: foo, bar" beneath, then the message, the cadence and when it -// fires next. Edit, pause/resume and remove sit at the foot; edit swaps the +// fires next. Edit, fire now, pause/resume and remove sit at the foot; edit swaps the // card for `ScheduleForm` (the page owns that swap). import { Badge, type BadgeTone } from "@hive/shared/badge.js"; import { ActionRow } from "../../ui/action-row/ActionRow.js"; @@ -27,6 +27,7 @@ export function ScheduleCard({ schedule, pending, onEdit, + onFireNow, onTogglePaused, onRemove, }: { @@ -34,6 +35,7 @@ export function ScheduleCard({ /** A pause/resume or remove for this schedule is in flight. */ pending: boolean; onEdit: () => void; + onFireNow: () => void; onTogglePaused: () => void; onRemove: () => void; }) { @@ -78,6 +80,19 @@ export function ScheduleCard({ + + + @@ -115,6 +130,7 @@ function ScheduleCardSkeleton() { + diff --git a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleTypes.ts b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleTypes.ts index 980a733b5..17a69027c 100644 --- a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleTypes.ts +++ b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleTypes.ts @@ -101,3 +101,13 @@ export function fmtLocal(unix: number): string { timeStyle: "short", }); } + +/** + * The `PATCH /api/schedules/{id}` body that fires a schedule now: its start + * (the origin of its fire times) moves to `nowMs`, and a start that has passed + * fires its latest time right away. A repeating schedule goes on from there, so + * its later fires keep the interval but not their old clock times. + */ +export function fireNowBody(nowMs: number): { anchor_unix: number } { + return { anchor_unix: Math.floor(nowMs / 1000) }; +} diff --git a/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx b/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx index 2a4f3aa44..4711ebd51 100644 --- a/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx @@ -27,7 +27,7 @@ import type { AgentRow } from "../../agent/AgentTypes.js"; import { ScheduleCard, ScheduleListSkeleton } from "./ScheduleCard.js"; import { agentNamesFrom, agentOptionsFor } from "./agent-options.js"; import { ScheduleForm } from "./ScheduleForm.js"; -import { scheduleState, type Schedule } from "./ScheduleTypes.js"; +import { fireNowBody, scheduleState, type Schedule } from "./ScheduleTypes.js"; // A refetch never touches an open form's own state (it lives in the form), // so the usual 30s default is safe here too. @@ -118,6 +118,16 @@ function SchedulesBody() { } } + function fireNow(s: Schedule) { + return act(s.id, () => + fetch(`/api/schedules/${encodeURIComponent(s.id)}`, { + method: "PATCH", + headers: { "content-type": "application/json" }, + body: JSON.stringify(fireNowBody(Date.now())), + }), + ); + } + function togglePaused(s: Schedule) { return act(s.id, () => fetch(`/api/schedules/${encodeURIComponent(s.id)}`, { @@ -207,6 +217,7 @@ function SchedulesBody() { schedule={s} pending={pendingIds.has(s.id)} onEdit={() => setEditingId(s.id)} + onFireNow={() => fireNow(s)} onTogglePaused={() => togglePaused(s)} onRemove={() => setRemoveTarget(s)} /> diff --git a/frontend/packages/swarm-ui/test/fire-now.test.mjs b/frontend/packages/swarm-ui/test/fire-now.test.mjs new file mode 100644 index 000000000..ceb275de1 --- /dev/null +++ b/frontend/packages/swarm-ui/test/fire-now.test.mjs @@ -0,0 +1,14 @@ +// The body of a schedule's "fire now". Run by `npm test`. +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { fireNowBody } from "../src/pages/schedules/ScheduleTypes.ts"; + +test("fire now moves the start to the current second", () => { + assert.deepEqual(fireNowBody(1_700_000_123_456), { + anchor_unix: 1_700_000_123, + }); +}); + +test("fire now sends nothing but the start", () => { + assert.deepEqual(Object.keys(fireNowBody(0)), ["anchor_unix"]); +});