A local-first multi-agent app development platform, built on PenguinHarness
feat(web): 定时任务统一管理页,从账号菜单进入
lmliheng58b0b5c8a782
diff --git a/packages/ui-gallery/src/app/surfaces.ts b/packages/ui-gallery/src/app/surfaces.tsindex d95f9dae..1db76ed2 100644--- a/packages/ui-gallery/src/app/surfaces.ts+++ b/packages/ui-gallery/src/app/surfaces.ts@@ -28,6 +28,7 @@ export const SURFACE_IDS = ["agents","agent-settings","schedules",+ "schedules-project","plugins","plugin-detail","models",@@ -64,6 +65,7 @@ export const SURFACES: readonly Surface[] = [{ id: "agents", group: "workbench", route: "/agents" },{ id: "agent-settings", group: "workbench", route: "/agents/docs-expert" },{ id: "schedules", group: "workbench", route: "/agents/docs-expert?tab=schedules" },+ { id: "schedules-project", group: "workbench", route: "/schedules" },{ id: "plugins", group: "resources", route: "/plugins" },{ id: "plugin-detail", group: "resources", route: "/plugins/registry/claude-code-expert" },{ id: "models", group: "resources", route: "/models" },diff --git a/packages/ui-gallery/src/strings-en.ts b/packages/ui-gallery/src/strings-en.tsindex b440efa1..3a9fdbc5 100644--- a/packages/ui-gallery/src/strings-en.ts+++ b/packages/ui-gallery/src/strings-en.ts@@ -91,6 +91,12 @@ export const en: GalleryStrings = {"The Agent settings' schedule tab: periods, next fire time, the bound Session and model.",how: "Agents › Agent settings › the Schedules tab.",},+ "schedules-project": {+ title: "Schedules (whole Project)",+ description:+ "Every Agent's scheduled tasks in this Project, grouped by Agent: enable, edit and delete them all here, and see the files that failed to parse.",+ how: "The avatar at the bottom left › the account menu › Schedules.",+ },plugins: {title: "Plugins",description:diff --git a/packages/ui-gallery/src/strings.ts b/packages/ui-gallery/src/strings.tsindex 7bbeec2d..c93efb23 100644--- a/packages/ui-gallery/src/strings.ts+++ b/packages/ui-gallery/src/strings.ts@@ -105,6 +105,12 @@ export const zh = {description: "智能体设置的定时任务标签页:周期、下次触发、绑定的会话与模型。",how: "智能体 › 智能体设置 › 定时任务标签页。",},+ "schedules-project": {+ title: "定时任务(全项目)",+ description:+ "本项目的定时任务总表:按 Agent 分组,可统一启停、编辑与删除,解析失败的文件也在这里列出。",+ how: "左下角头像 › 账号菜单 › 定时任务。",+ },plugins: {title: "插件市场",description: "插件库按分类列出,带搜索与筛选;已安装的 Skill 与钩子按智能体显示。",diff --git a/packages/web/src/components/layout/user-menu.tsx b/packages/web/src/components/layout/user-menu.tsxindex c7d078a7..65f77403 100644--- a/packages/web/src/components/layout/user-menu.tsx+++ b/packages/web/src/components/layout/user-menu.tsx@@ -1,8 +1,9 @@/*** The account menu, shared by both avatars that open one: the pinned sidebar's user row and* the collapsed rail's avatar. One component rather than a copy per anchor — the rows- * (Settings, the update entry, sign out) and the dialog behind the first of them must- * stay the same menu from either side, and a second copy is how two menus drift apart.+ * (Settings, the scheduled-tasks page, the update entry, sign out) and the dialog behind the+ * first of them must stay the same menu from either side, and a second copy is how two menus+ * drift apart.** Only the trigger differs, so the trigger is the caller's: it is handed the menu's own open* state, which is what keeps "what opening means" here rather than in two places.@@ -114,12 +115,23 @@ export function UserMenu({setSettingsOpen(true);}}/>- {/* Update entry, directly under the settings entry rather than on a page inside- it: one row for both backends (the server release here, the shell's own- updater in the desktop window), naming where the update flow stands and- opening the update modal — where the flow is explained and acted on. The- modal is mounted by the app layout, so it outlives this menu. Hidden where- this session can update nothing (a browser signed into a desktop-mode+ {/* The Project's scheduled tasks, the one page reached from here rather than from+ the sidebar: it is a Project-wide inventory visited now and then, not a+ workspace. A plain row of its own, right under the settings dialog's entry —+ both leave this menu, and the two navigations belong together. */}+ <MenuItem+ label={S.schedule.pageTitle}+ onSelect={() => {+ setOpen(false);+ navigate("/schedules");+ }}+ />+ {/* Update entry, under the two navigation rows rather than on a page inside the+ settings dialog: one row for both backends (the server release here, the+ shell's own updater in the desktop window), naming where the update flow+ stands and opening the update modal — where the flow is explained and acted+ on. The modal is mounted by the app layout, so it outlives this menu. Hidden+ where this session can update nothing (a browser signed into a desktop-modeserver, see updateModeFor). */}<UpdateRowonOpen={() => {diff --git a/packages/web/src/features/schedules/schedule-page-state.ts b/packages/web/src/features/schedules/schedule-page-state.tsnew file mode 100644index 00000000..6342fdaa--- /dev/null+++ b/packages/web/src/features/schedules/schedule-page-state.ts@@ -0,0 +1,48 @@+/**+ * Pure state of the scheduled-tasks page (features/schedules/schedules-page.tsx): how the+ * Project's one flat list of tasks becomes the page's per-Agent groups. Kept apart from the+ * component so the ordering rules run in the node-only unit tests (test/schedules-page-state.ts).+ *+ * The page groups rather than sorts flat, because the two questions a task raises are answered+ * by its owner: a file lives in one Agent's agent_state/schedule/, and the Agent is the only+ * thing that says where a task's workspace, model and Session picker point. The filter and the+ * search box narrow the rows inside the groups; they never dissolve the groups.+ */++/** One Agent's tasks, in the order the server listed them (its own listing's order). */+export interface ScheduleAgentGroup<T> {+ agentId: string;+ items: T[];+}++/**+ * The list split by owning Agent: `agentOrder` is the Project's Agent list, so the groups come+ * out in the order the settings pages, pickers and the Agent list all use.+ *+ * An Agent with no task is omitted rather than drawn as an empty group — the page answers "what+ * is scheduled", and a heading over nothing is a row the reader has to skip on every visit. A+ * task whose Agent is missing from `agentOrder` is not dropped: the caller may hold a stale Agent+ * list (an Agent deleted or added since it was loaded, or a task file written by hand), and+ * hiding those rows would hide real tasks. They come last, in the order they first appear in the+ * list, which for the server's own ordering is Agent id order.+ *+ * Generic in the item so the caller keeps what it passed in: the page draws ProjectScheduleItem+ * rows and needs each one's `name` and `agentId` for its own writes.+ */+export function groupSchedulesByAgent<T extends { agentId: string }>(+ items: readonly T[],+ agentOrder: readonly string[],+): ScheduleAgentGroup<T>[] {+ const groups = new Map<string, T[]>();+ for (const item of items) {+ const bucket = groups.get(item.agentId);+ if (bucket === undefined) groups.set(item.agentId, [item]);+ else bucket.push(item);+ }+ // `Array.prototype.sort` is stable, so the Agents absent from `agentOrder` - all sharing one+ // rank - keep the first-seen order the Map already gave them.+ const rank = new Map(agentOrder.map((agentId, index) => [agentId, index]));+ return [...groups.entries()]+ .sort(([a], [b]) => (rank.get(a) ?? agentOrder.length) - (rank.get(b) ?? agentOrder.length))+ .map(([agentId, group]) => ({ agentId, items: group }));+}diff --git a/packages/web/src/features/schedules/schedule-panel-state.ts b/packages/web/src/features/schedules/schedule-panel-state.tsindex f4f8746a..13e1b239 100644--- a/packages/web/src/features/schedules/schedule-panel-state.ts+++ b/packages/web/src/features/schedules/schedule-panel-state.ts@@ -1,15 +1,27 @@/**- * Pure state of the chat dock's scheduled-tasks panel: which of the Project's tasks belong to- * the conversation on screen, how the filter chips bucket the server's display statuses,- * what the search box matches, and which state glyph a row wears. Kept apart from the panel- * so the rules run in the node-only unit tests (test/schedule-panel-state.test.ts).+ * Pure state of the surfaces that list the Project's scheduled tasks: how the filter chips+ * bucket the server's display statuses, what the search box matches, which state glyph a row+ * wears, and the chips' wording. Kept apart from the components so the rules run in the+ * node-only unit tests (test/schedule-panel-state.test.ts), and shared by both listers — the+ * chat dock's panel and the scheduled-tasks page — so the two filter one list the same way.*/import type { ScheduleItem, ScheduleStatus } from "@lmliheng/penguin-server/api";+import { S } from "../../lib/strings";export type ScheduleFilter = "all" | "active" | "paused" | "completed";export const SCHEDULE_FILTERS: readonly ScheduleFilter[] = ["all", "active", "paused", "completed"];+/** The chips' wording, from the active dictionary (read at render time, so a locale switch relabels them). */+export function scheduleFilterLabels(): Record<ScheduleFilter, string> {+ return {+ all: S.schedule.filterAll,+ active: S.schedule.filterActive,+ paused: S.schedule.filterPaused,+ completed: S.schedule.filterCompleted,+ };+}+/*** The chip a status sits under. `disabled` is "paused" — the switch on the row resumes it —* and every settled state is "completed". An invalid file fits no chip: it shows under "all"diff --git a/packages/web/src/features/schedules/schedule-panel.tsx b/packages/web/src/features/schedules/schedule-panel.tsxindex abcd90ef..50e36d49 100644--- a/packages/web/src/features/schedules/schedule-panel.tsx+++ b/packages/web/src/features/schedules/schedule-panel.tsx@@ -16,38 +16,28 @@* while the AI path stays open to everyone — asking the agent is a message, not a write.*/import { useEffect, useState } from "react";-import type { ProjectScheduleItem, ScheduleItem, SessionInfo } from "@lmliheng/penguin-server/api";+import type { ProjectScheduleItem, SessionInfo } from "@lmliheng/penguin-server/api";import {- Badge,ConfirmModal,- Dropdown,- GlyphIcon,- ICONS,- ICON_SIZE,- Menu,- MenuItem,SearchInput,Segmented,SettingsEmpty,SkeletonList,- Switch,toastError,toastSuccess,} from "@lmliheng/penguin-ui";import * as api from "../../api/endpoints";import { S } from "../../lib/strings";import { apiErrorText } from "../../lib/api-error";-import { toneInk } from "../../lib/tone";-import { useLocale } from "../../state/locale";import { useProject } from "../../state/project";import { AiCreateButtons } from "../ai-create/ai-create-buttons";-import { describeSchedule } from "./schedule-describe";import { ScheduleAiModal } from "./schedule-ai-modal";import { ScheduleFormModal } from "./schedule-form-modal";+import { ScheduleRow } from "./schedule-row";import {SCHEDULE_FILTERS,filterSchedules,- scheduleGlyph,+ scheduleFilterLabels,sessionSchedules,} from "./schedule-panel-state";import type { ScheduleFilter } from "./schedule-panel-state";@@ -58,69 +48,6 @@ import { toggleBody } from "./schedule-upsert";/** How often the list refetches while on screen — about the server's own re-read cadence for the schedule directory. */const REFRESH_MS = 30_000;-/** The state marks: a filled play for an armed task, pause bars, a check for the settled states. */-const PLAY_ICON = "M7 4l13 8-13 8z";-const PAUSE_ICON = "M8 4v16M16 4v16";-const CHECK_ICON = "M5 12l4 4L19 6";--/** The row's leading state glyph; an invalid file wears the info circle in the danger tone, its reason in the tooltip. */-function StateGlyph({ item }: { item: ScheduleItem }) {- const glyph = scheduleGlyph(item.status);- const name = S.schedule.statusNames[item.status] ?? item.status;- const tone =- glyph === "play" ? toneInk.success : glyph === "alert" ? toneInk.danger : toneInk.muted;- const d =- glyph === "play"- ? PLAY_ICON- : glyph === "pause"- ? PAUSE_ICON- : glyph === "check"- ? CHECK_ICON- : ICONS.info;- return (- <span className={`shrink-0 ${tone}`} data-tooltip={item.invalidReason ?? name}>- <GlyphIcon d={d} size={ICON_SIZE.rowLead} filled={glyph === "play"} />- <span className="sr-only">{name}</span>- </span>- );-}--/** A row's overflow menu: edit, and delete in the destructive treatment (small Menu rows). */-function RowMenu({ onEdit, onDelete }: { onEdit: () => void; onDelete: () => void }) {- const [open, setOpen] = useState(false);- const item = (fn: () => void) => () => {- setOpen(false);- fn();- };- return (- <Dropdown- open={open}- setOpen={setOpen}- portal={{ direction: "down", align: "right" }}- menuClass="w-32"- button={- <button- type="button"- data-tooltip={S.schedule.rowActions}- aria-label={S.schedule.rowActions}- aria-haspopup="menu"- aria-expanded={open}- onClick={() => setOpen(!open)}- className="flex h-6 w-6 shrink-0 items-center justify-center rounded text-gray-400 transition-colors duration-150 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-500 dark:hover:bg-gray-800 dark:hover:text-gray-200"- >- <GlyphIcon d={ICONS.ellipsis} size={ICON_SIZE.rowLead} filled />- </button>- }- >- <Menu density="sm">- <MenuItem glyph={ICONS.pencil} label={S.common.edit} onSelect={item(onEdit)} />- {/* The glyph inherits the row's red. */}- <MenuItem glyph={ICONS.trash} label={S.common.delete} danger onSelect={item(onDelete)} />- </Menu>- </Dropdown>- );-}-export interface SchedulePanelProps {session: SessionInfo;/** Whether this tab is the one on screen (the dock keeps hidden tabs mounted): a hidden tab does not poll. */@@ -131,7 +58,6 @@ export interface SchedulePanelProps {export function SchedulePanel({ session, active, onPrefillComposer }: SchedulePanelProps) {const { currentProject, agents, reloadAgents } = useProject();- const { locale } = useLocale();const projectId = currentProject?.projectId ?? null;const isOwner = currentProject?.role === "owner";// The shared store's list, narrowed to this conversation; only the first load's failure shows@@ -207,12 +133,7 @@ export function SchedulePanel({ session, active, onPrefillComposer }: SchedulePaconst openAi = (initial: string) => setAi({ initial });const visible = items === null ? [] : filterSchedules(items, filter, query);const searching = query.trim() !== "";- const filterLabels: Record<ScheduleFilter, string> = {- all: S.schedule.filterAll,- active: S.schedule.filterActive,- paused: S.schedule.filterPaused,- completed: S.schedule.filterCompleted,- };+ const filterLabels = scheduleFilterLabels();return (<div className="h-full overflow-y-auto p-3">@@ -267,53 +188,18 @@ export function SchedulePanel({ session, active, onPrefillComposer }: SchedulePa<SettingsEmpty>{S.schedule.panelNoMatch}</SettingsEmpty>) : (<ul className="space-y-1">- {visible.map((item) => {- const line = describeSchedule(item, locale);- return (- <li- key={item.name}- className="flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors duration-150 hover:bg-gray-50 dark:hover:bg-gray-800/60"- >- <StateGlyph item={item} />- <div className="min-w-0 flex-1">- <div className="flex items-center gap-1.5">- <span- className="truncate text-sm text-gray-800 dark:text-gray-100"- // The name leads the tooltip, not just the prompt: a task name is a- // file name and truncates in a dock this narrow, and the panel would- // otherwise be the one surface that cannot show it in full.- data-tooltip={`${item.name}\n${item.prompt}`}- data-tooltip-content="text"- >- {item.name}- </span>- {item.queued && <Badge variant="solid">{S.schedule.queued}</Badge>}- </div>- <div- className="truncate text-xs text-gray-500 dark:text-gray-400"- data-tooltip={item.invalidReason ?? line}- data-tooltip-content="text"- >- {line}- </div>- </div>- {isOwner && (- <>- <Switch- checked={item.enabled}- disabled={busy}- aria-label={item.enabled ? S.schedule.disable : S.schedule.enable}- onChange={() => void toggle(item)}- />- <RowMenu- onEdit={() => setForm({ editing: item })}- onDelete={() => setDeleting({ agentId: item.agentId, name: item.name })}- />- </>- )}- </li>- );- })}+ {visible.map((item) => (+ <li key={item.name}>+ <ScheduleRow+ item={item}+ owner={isOwner}+ busy={busy}+ onToggle={() => void toggle(item)}+ onEdit={() => setForm({ editing: item })}+ onDelete={() => setDeleting({ agentId: item.agentId, name: item.name })}+ />+ </li>+ ))}</ul>)}diff --git a/packages/web/src/features/schedules/schedule-row.tsx b/packages/web/src/features/schedules/schedule-row.tsxnew file mode 100644index 00000000..8c9fd3a5--- /dev/null+++ b/packages/web/src/features/schedules/schedule-row.tsx@@ -0,0 +1,150 @@+/**+ * One scheduled task's row, shared by the two surfaces that list tasks: the chat dock's panel+ * (the tasks bound to the conversation on screen) and the scheduled-tasks page (every Agent's+ * tasks in the Project). Both list the same thing, so a task has to read the same in both —+ * state mark, name and its human schedule line, the queue badge, the enable switch and the+ * overflow menu (edit / delete) — and a second copy of that markup is how the two would drift+ * apart the day one of them gains a state.+ *+ * The actions are the caller's: the panel and the page run the same three writes, but the page+ * has to name the Agent holding the file, so each one passes its own callbacks.+ */+import { useState } from "react";+import type { ScheduleItem } from "@lmliheng/penguin-server/api";+import {+ Badge,+ Dropdown,+ GlyphIcon,+ ICONS,+ ICON_SIZE,+ Menu,+ MenuItem,+ Switch,+} from "@lmliheng/penguin-ui";+import { S } from "../../lib/strings";+import { toneInk } from "../../lib/tone";+import { useLocale } from "../../state/locale";+import { describeSchedule } from "./schedule-describe";+import { scheduleGlyph } from "./schedule-panel-state";++/** The state marks: a filled play for an armed task, pause bars, a check for the settled states. */+const PLAY_ICON = "M7 4l13 8-13 8z";+const PAUSE_ICON = "M8 4v16M16 4v16";+const CHECK_ICON = "M5 12l4 4L19 6";++/** The row's leading state glyph; an invalid file wears the info circle in the danger tone, its reason in the tooltip. */+function StateGlyph({ item }: { item: ScheduleItem }) {+ const glyph = scheduleGlyph(item.status);+ const name = S.schedule.statusNames[item.status] ?? item.status;+ const tone =+ glyph === "play" ? toneInk.success : glyph === "alert" ? toneInk.danger : toneInk.muted;+ const d =+ glyph === "play"+ ? PLAY_ICON+ : glyph === "pause"+ ? PAUSE_ICON+ : glyph === "check"+ ? CHECK_ICON+ : ICONS.info;+ return (+ <span className={`shrink-0 ${tone}`} data-tooltip={item.invalidReason ?? name}>+ <GlyphIcon d={d} size={ICON_SIZE.rowLead} filled={glyph === "play"} />+ <span className="sr-only">{name}</span>+ </span>+ );+}++/** A row's overflow menu: edit, and delete in the destructive treatment (small Menu rows). */+function RowMenu({ onEdit, onDelete }: { onEdit: () => void; onDelete: () => void }) {+ const [open, setOpen] = useState(false);+ const item = (fn: () => void) => () => {+ setOpen(false);+ fn();+ };+ return (+ <Dropdown+ open={open}+ setOpen={setOpen}+ portal={{ direction: "down", align: "right" }}+ menuClass="w-32"+ button={+ <button+ type="button"+ data-tooltip={S.schedule.rowActions}+ aria-label={S.schedule.rowActions}+ aria-haspopup="menu"+ aria-expanded={open}+ onClick={() => setOpen(!open)}+ className="flex h-6 w-6 shrink-0 items-center justify-center rounded text-gray-400 transition-colors duration-150 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-500 dark:hover:bg-gray-800 dark:hover:text-gray-200"+ >+ <GlyphIcon d={ICONS.ellipsis} size={ICON_SIZE.rowLead} filled />+ </button>+ }+ >+ <Menu density="sm">+ <MenuItem glyph={ICONS.pencil} label={S.common.edit} onSelect={item(onEdit)} />+ {/* The glyph inherits the row's red. */}+ <MenuItem glyph={ICONS.trash} label={S.common.delete} danger onSelect={item(onDelete)} />+ </Menu>+ </Dropdown>+ );+}++export function ScheduleRow({+ item,+ /** Whether this account may write: the switch and the menu are owner-only, and a member sees the row read-only. */+ owner,+ /** A write on this list is in flight: every control on the row waits for it. */+ busy,+ onToggle,+ onEdit,+ onDelete,+}: {+ item: ScheduleItem;+ owner: boolean;+ busy: boolean;+ onToggle: () => void;+ onEdit: () => void;+ onDelete: () => void;+}) {+ const { locale } = useLocale();+ const line = describeSchedule(item, locale);+ return (+ <div className="flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors duration-150 hover:bg-gray-50 dark:hover:bg-gray-800/60">+ <StateGlyph item={item} />+ <div className="min-w-0 flex-1">+ <div className="flex items-center gap-1.5">+ <span+ className="truncate text-sm text-gray-800 dark:text-gray-100"+ // The name leads the tooltip, not just the prompt: a task name is a file name and+ // truncates in a narrow column, and the row would otherwise be the one surface that+ // cannot show it in full.+ data-tooltip={`${item.name}\n${item.prompt}`}+ data-tooltip-content="text"+ >+ {item.name}+ </span>+ {item.queued && <Badge variant="solid">{S.schedule.queued}</Badge>}+ </div>+ <div+ className="truncate text-xs text-gray-500 dark:text-gray-400"+ data-tooltip={item.invalidReason ?? line}+ data-tooltip-content="text"+ >+ {line}+ </div>+ </div>+ {owner && (+ <>+ <Switch+ checked={item.enabled}+ disabled={busy}+ aria-label={item.enabled ? S.schedule.disable : S.schedule.enable}+ onChange={onToggle}+ />+ <RowMenu onEdit={onEdit} onDelete={onDelete} />+ </>+ )}+ </div>+ );+}diff --git a/packages/web/src/features/schedules/schedule-store.ts b/packages/web/src/features/schedules/schedule-store.tsindex 05646697..e1ed7a11 100644--- a/packages/web/src/features/schedules/schedule-store.ts+++ b/packages/web/src/features/schedules/schedule-store.ts@@ -1,11 +1,16 @@/**- * A Project's scheduled tasks, as a tiny module-level store shared by the two surfaces that read+ * A Project's scheduled tasks, as a tiny module-level store shared by the surfaces that read* them: the session list's alarm-clock mark (which of the listed Sessions have a task still to- * fire) and the dock's scheduled-tasks panel (the open conversation's own tasks, listed). They- * must never disagree about whether a conversation has tasks, so they read one cache rather than- * fetching one each.+ * fire), the dock's scheduled-tasks panel (the open conversation's own tasks, listed) and the+ * scheduled-tasks page (every Agent's tasks in the Project). They must never disagree about+ * whether a conversation has tasks, so they read one cache rather than fetching one each.*- * The scope is the whole Project because that is what the two surfaces need between them: the+ * One answer carries both what the server listed and the task files it could not parse. The+ * list is what every reader draws; the page is the only one that also shows the skipped files,+ * since it is the surface that manages the Project's tasks as a whole — but they come from the+ * same read, so the page never has to ask a second time.+ *+ * The scope is the whole Project because that is what the surfaces need between them: the* session list draws every Agent's Sessions — workspace, time and agent grouping all mix them —* while the panel is one conversation of one of them. Read per agent, the list answered only the* panel: every other Agent's rows wore no mark, and because the chat page moves the current Agent@@ -28,14 +33,19 @@* kilobytes back for exactly the blank-then-refetch this cache exists to remove.*/import { useEffect, useSyncExternalStore } from "react";-import type { ProjectScheduleItem } from "@lmliheng/penguin-server/api";+import type { ProjectScheduleItem, ProjectSchedulesResponse } from "@lmliheng/penguin-server/api";import * as api from "../../api/endpoints";import { apiErrorText } from "../../lib/api-error";+/** A task file the server could not parse, with the agent whose directory holds it. */+export type InvalidScheduleFile = ProjectSchedulesResponse["invalidFiles"][number];+interface Entry {projectId: string;/** Null until this Project has answered once; a refetch keeps the list it already has. */items: ProjectScheduleItem[] | null;+ /** Files the server skipped, same answer as the list: the page surfaces them, the dock panel does not. */+ invalidFiles: InvalidScheduleFile[];/** Last failure text, cleared by the next success. The panel shows it only while `items` is null. */error: string | null;/** This Project's request: concurrent readers share it, another Project gets its own. */@@ -53,6 +63,7 @@ function entryFor(projectId: string): Entry {const created: Entry = {projectId,items: null,+ invalidFiles: [],error: null,inflight: null,readers: 0,@@ -90,6 +101,11 @@ export function scheduleError(projectId: string | null): string | null {return peek(projectId)?.error ?? null;}+/** The files this Project's last answer reported as unparseable — empty before it has answered. */+export function scheduleInvalidFiles(projectId: string | null): InvalidScheduleFile[] {+ return peek(projectId)?.invalidFiles ?? [];+}+/*** Re-reads one Project's list. The Project is an argument rather than whatever the store last* pointed at, which is what makes the request always the one the caller asked for: concurrent@@ -104,6 +120,7 @@ export function refreshSchedules(projectId: string | null): Promise<void> {try {const res = await api.listProjectSchedules(projectId);entry.items = res.schedules;+ entry.invalidFiles = res.invalidFiles;entry.error = null;} catch (e) {// The list it already has stays: a refetch failing is not news that the tasks are gone.@@ -181,7 +198,11 @@ export function subscribeSchedules(listener: () => void): () => void {export function useProjectSchedules(projectId: string | null,refreshKey: string,-): { items: ProjectScheduleItem[] | null; error: string | null } {+): {+ items: ProjectScheduleItem[] | null;+ invalidFiles: InvalidScheduleFile[];+ error: string | null;+} {useSyncExternalStore(subscribeSchedules, schedulesVersion, schedulesVersion);// Held for as long as this reader is mounted, and deliberately not keyed on `refreshKey`:// moving between two conversations of one Project must not release the entry and take it again.@@ -191,6 +212,7 @@ export function useProjectSchedules(}, [projectId, refreshKey]);return {items: scheduleItems(projectId),+ invalidFiles: scheduleInvalidFiles(projectId),error: scheduleError(projectId),};}diff --git a/packages/web/src/features/schedules/schedules-page.tsx b/packages/web/src/features/schedules/schedules-page.tsxnew file mode 100644index 00000000..00c18333--- /dev/null+++ b/packages/web/src/features/schedules/schedules-page.tsx@@ -0,0 +1,312 @@+/**+ * Scheduled-tasks page: every Agent's tasks in the Project in one place, so the Project can be+ * seen as a whole instead of Agent by Agent. The other two surfaces stay as they are and answer+ * different questions — the Agent settings tab lists ONE Agent's tasks in a table (with the+ * prompt-injection controls beside them), and the chat dock's panel lists the tasks of the+ * conversation on screen. This is the one that answers "what is scheduled in this Project".+ *+ * Reached from the account menu rather than the sidebar's nav: it is a Project-wide inventory+ * looked at now and then, not a workspace the user lives in, and the sidebar's top group is for+ * the latter.+ *+ * The list is the shared store's (schedule-store.ts), the same Project-wide answer the session+ * list's marks and the dock's panel read, so the three can never disagree. It comes back flat,+ * with the owning Agent on every task, and is drawn GROUPED by that Agent: a task file lives in+ * one Agent's agent_state/schedule/, and the Agent is what says where its workspace, model and+ * Session picker point — so a flat list of same-named tasks from different Agents would read as+ * a pile of duplicates. The filter chips and the search box narrow the rows inside the groups.+ *+ * Creating picks the Agent first (the header's button opens one row per Agent): the form's Agent+ * is fixed for the task's whole life — the file's directory IS the owner — so the choice cannot+ * be left to whatever the app happens to have selected. Editing and deleting always name the+ * file's own Agent, which is where the row's task came from.+ *+ * The files the server could not parse are listed at the end, which is the one thing this page+ * shows that the dock's panel does not: an unparseable file is invisible in every listing (the+ * server skips it), so without this the only way to learn a task never got scheduled would be+ * the server log.+ *+ * Readable by any member; the switch, the menu and the create button are owner-only — a schedule+ * writes files and sends prompts, exactly as in the settings tab.+ */+import { useState } from "react";+import type { ProjectScheduleItem } from "@lmliheng/penguin-server/api";+import {+ AgentAvatar,+ Button,+ ConfirmModal,+ Dropdown,+ Menu,+ MenuItem,+ PageFrame,+ PageHeader,+ SearchInput,+ Segmented,+ SettingsEmpty,+ SkeletonList,+ toastError,+ toastSuccess,+} from "@lmliheng/penguin-ui";+import * as api from "../../api/endpoints";+import { S } from "../../lib/strings";+import { apiErrorText } from "../../lib/api-error";+import { useDocumentTitle } from "../../lib/use-document-title";+import { agentDisplayName, useProject } from "../../state/project";+import { groupSchedulesByAgent } from "./schedule-page-state";+import { SCHEDULE_FILTERS, filterSchedules, scheduleFilterLabels } from "./schedule-panel-state";+import type { ScheduleFilter } from "./schedule-panel-state";+import { ScheduleFormModal } from "./schedule-form-modal";+import { ScheduleRow } from "./schedule-row";+import { refreshSchedules, useProjectSchedules } from "./schedule-store";+import { toggleBody } from "./schedule-upsert";++/**+ * The `refreshKey` of the store hook: a constant, because this page is scoped to nothing but the+ * Project. The panel passes the Session on screen there; here nothing finer than the Project can+ * change, so the list is read on mount and re-read on the store's own triggers (focus, schedule+ * events, every write this page makes).+ */+const PAGE_REFRESH_KEY = "schedules-page";++export function SchedulesPage() {+ useDocumentTitle(S.schedule.pageTitle);+ const { currentProject, agents, reloadAgents } = useProject();+ const projectId = currentProject?.projectId ?? null;+ const isOwner = currentProject?.role === "owner";+ const { items, invalidFiles, error } = useProjectSchedules(projectId, PAGE_REFRESH_KEY);+ const [query, setQuery] = useState("");+ const [filter, setFilter] = useState<ScheduleFilter>("all");+ // A write is in flight: every control on the list waits for it.+ const [busy, setBusy] = useState(false);+ // Form dialog: non-null means open, carrying the Agent whose directory the task lives in (the+ // one being edited, or the one just picked for a new task).+ const [form, setForm] = useState<{+ agentId: string;+ editing: ProjectScheduleItem | null;+ } | null>(null);+ // The task pending deletion confirmation, named by its file: the Agent whose directory holds it+ // and the file name, which is what the delete call takes.+ const [deleting, setDeleting] = useState<{ agentId: string; name: string } | null>(null);+ // The "new task" button's Agent picker.+ const [agentsOpen, setAgentsOpen] = useState(false);++ /** After a create, update or delete: the list, and the Agent cards' schedule counts. */+ const changed = () => {+ void refreshSchedules(projectId);+ void reloadAgents();+ };++ /**+ * Toggle: whole-file-replace semantics — resend original fields, only flip enabled. The write+ * names the Agent whose schedule directory holds the file, which the Project-wide list stamps+ * on every task.+ */+ const toggle = async (item: ProjectScheduleItem) => {+ if (!projectId) return;+ setBusy(true);+ try {+ await api.updateSchedule(projectId, item.agentId, item.name, toggleBody(item, !item.enabled));+ toastSuccess(item.enabled ? S.schedule.toastDisabled : S.schedule.toastEnabled);+ await refreshSchedules(projectId);+ } catch (e) {+ toastError(apiErrorText(e));+ } finally {+ setBusy(false);+ }+ };++ const confirmRemove = async () => {+ if (!projectId || deleting === null) return;+ setBusy(true);+ try {+ await api.deleteSchedule(projectId, deleting.agentId, deleting.name);+ // The form may be sitting open on the very task just deleted (the row menu offers both).+ const editing = form?.editing;+ if (editing?.agentId === deleting.agentId && editing?.name === deleting.name) setForm(null);+ changed();+ } catch (e) {+ toastError(apiErrorText(e));+ } finally {+ setBusy(false);+ setDeleting(null);+ }+ };++ const filterLabels = scheduleFilterLabels();+ const visible = items === null ? [] : filterSchedules(items, filter, query);+ const groups = groupSchedulesByAgent(+ visible,+ agents.map((a) => a.agentId),+ );+ /** What to call the Agent holding a file: its display name, or the id if the Agent list no longer carries it. */+ const agentLabel = (agentId: string): string => {+ const agent = agents.find((a) => a.agentId === agentId);+ return agent ? agentDisplayName(agent) : agentId;+ };++ return (+ <PageFrame className="[scrollbar-gutter:stable]">+ <PageHeader+ title={S.schedule.pageTitle}+ description={S.schedule.pageDesc}+ // A member reads the whole Project's schedule here and can change none of it; the "?"+ // says why, exactly as the settings tab's help fold does.+ info={isOwner ? undefined : S.schedule.readOnlyHint}+ actions={+ isOwner && (+ // Creating picks its Agent first: the file's directory is the task's owner for good,+ // and "whichever Agent is selected" is a setting the user cannot even see from here.+ <Dropdown+ open={agentsOpen}+ setOpen={setAgentsOpen}+ portal={{ direction: "down", align: "right" }}+ menuClass="w-56"+ button={+ <Button+ size="sm"+ variant="primary"+ disabled={agents.length === 0}+ onClick={() => setAgentsOpen(!agentsOpen)}+ >+ {S.schedule.addTitle}+ </Button>+ }+ >+ <Menu density="sm">+ {agents.map((agent) => (+ <MenuItem+ key={agent.agentId}+ density="sm"+ glyph={+ <AgentAvatar+ id={agent.agentId}+ name={agentDisplayName(agent)}+ size={20}+ className="shrink-0 rounded"+ />+ }+ label={agentDisplayName(agent)}+ onSelect={() => {+ setAgentsOpen(false);+ setForm({ agentId: agent.agentId, editing: null });+ }}+ />+ ))}+ </Menu>+ </Dropdown>+ )+ }+ >+ {/* Search and the state chips, on a line of their own under the title: they narrow the+ rows inside the groups (never the groups themselves), so they belong to the list+ rather than to the header's action row, where a member - who has no create button -+ would find them beside nothing. */}+ <div className="mt-3 flex flex-wrap items-center gap-2">+ <div className="w-full sm:w-56">+ <SearchInput+ size="sm"+ value={query}+ placeholder={S.schedule.panelSearchPlaceholder}+ aria-label={S.schedule.panelSearchPlaceholder}+ onChange={setQuery}+ />+ </div>+ <div className="w-full sm:w-72">+ <Segmented+ cols={4}+ options={SCHEDULE_FILTERS.map((value) => ({ value, label: filterLabels[value] }))}+ value={filter}+ onChange={setFilter}+ />+ </div>+ </div>+ </PageHeader>++ {items === null ? (+ error !== null ? (+ <p className="text-sm text-red-600 dark:text-red-400">{error}</p>+ ) : (+ <SkeletonList rows={4} />+ )+ ) : items.length === 0 ? (+ <SettingsEmpty>{S.schedule.pageEmpty}</SettingsEmpty>+ ) : groups.length === 0 ? (+ <SettingsEmpty>{S.schedule.panelNoMatch}</SettingsEmpty>+ ) : (+ <div className="space-y-4">+ {groups.map((group) => (+ <section key={group.agentId}>+ <h2 className="mb-1.5 flex min-w-0 items-center gap-2 text-sm font-medium text-fg">+ <AgentAvatar+ id={group.agentId}+ name={agentLabel(group.agentId)}+ size={18}+ className="shrink-0 rounded"+ />+ <span className="truncate">{agentLabel(group.agentId)}</span>+ <span className="shrink-0 text-xs font-normal text-fg-muted">+ {S.schedule.pageGroupCount(group.items.length)}+ </span>+ </h2>+ <ul className="space-y-1">+ {group.items.map((item) => (+ // The name is unique inside one Agent's schedule directory, which is exactly+ // what a group is.+ <li key={item.name}>+ <ScheduleRow+ item={item}+ owner={isOwner}+ busy={busy}+ onToggle={() => void toggle(item)}+ onEdit={() => setForm({ agentId: item.agentId, editing: item })}+ onDelete={() => setDeleting({ agentId: item.agentId, name: item.name })}+ />+ </li>+ ))}+ </ul>+ </section>+ ))}+ </div>+ )}++ {/* Task files the scheduler skipped, each with the Agent whose directory holds it: the one+ thing no other surface reports, and the reason a task can be "missing" from the list. */}+ {invalidFiles.length > 0 && (+ <div className="mt-6 text-xs text-red-600 dark:text-red-400">+ <p className="font-medium">{S.schedule.invalidFiles}</p>+ <ul className="mt-0.5 space-y-1 font-mono">+ {invalidFiles.map((file) => (+ <li key={`${file.agentId}/${file.name}`}>+ {agentLabel(file.agentId)} · {file.name}: {file.error}+ </li>+ ))}+ </ul>+ </div>+ )}++ <ScheduleFormModal+ open={form !== null}+ // The Agent is fixed by what opened the dialog (the row's own file, or the picker), so it+ // is only ever read once the dialog is open.+ agentId={form?.agentId ?? ""}+ editing={form?.editing ?? null}+ onClose={() => setForm(null)}+ onSaved={changed}+ />++ <ConfirmModal+ open={deleting !== null}+ title={S.schedule.deleteTitle}+ busy={busy}+ onClose={() => setDeleting(null)}+ onConfirm={() => void confirmRemove()}+ confirmLabel={S.common.confirm}+ cancelLabel={S.common.cancel}+ >+ <p className="text-sm text-gray-600 dark:text-gray-300">+ {deleting !== null ? S.schedule.deleteConfirm(deleting.name) : ""}+ </p>+ </ConfirmModal>+ </PageFrame>+ );+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex ffedb736..7ee41552 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -1933,6 +1933,16 @@ export const en: Strings = {panelNoMatch: "No matching scheduled tasks",/** The panel's body on the draft page, where no Session exists yet. */panelDraftEmpty: "Send the first message, then schedule tasks for this conversation",+ /**+ * The scheduled-tasks page (features/schedules/schedules-page.tsx): every Agent's tasks in+ * the Project, grouped by the Agent that owns each file. Reached from the account menu, so+ * `pageTitle` is also the row's wording there.+ */+ pageTitle: "Scheduled tasks",+ pageDesc:+ "Every Agent's scheduled tasks in this Project; enable, edit and delete them all here.",+ pageEmpty: "No scheduled tasks in this Project yet",+ pageGroupCount: (n: number): string => (n === 1 ? "1 task" : `${n} tasks`),/** Accessible name of a row's overflow menu (edit / delete). */rowActions: "More actions",/** The human schedule line under a task's name (schedule-describe.ts). */diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex c208623f..fae83ad6 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -1985,6 +1985,15 @@ export const zh = {panelNoMatch: "没有匹配的定时任务",/** The panel's body on the draft page, where no Session exists yet. */panelDraftEmpty: "发送第一条消息后即可为这段对话安排定时任务",+ /**+ * The scheduled-tasks page (features/schedules/schedules-page.tsx): every Agent's tasks in+ * the Project, grouped by the Agent that owns each file. Reached from the account menu, so+ * `pageTitle` is also the row's wording there.+ */+ pageTitle: "定时任务",+ pageDesc: "本项目所有 Agent 的定时任务,可在此统一启停、编辑与删除。",+ pageEmpty: "本项目还没有定时任务",+ pageGroupCount: (n: number): string => `${n} 个任务`,/** Accessible name of a row's overflow menu (edit / delete). */rowActions: "更多操作",/** The human schedule line under a task's name (schedule-describe.ts). */diff --git a/packages/web/src/module.json b/packages/web/src/module.jsonindex 2e2420d4..0dee3dc3 100644--- a/packages/web/src/module.json+++ b/packages/web/src/module.json@@ -114,6 +114,17 @@"renderer": {"builtin": "BenchmarkDetailPage"}+ },+ {+ "id": "web.schedules",+ "key": "schedules",+ "path": "/schedules",+ "nav": "none",+ "admin": false,+ "released": true,+ "renderer": {+ "builtin": "SchedulesPage"+ }}]}diff --git a/packages/web/src/router.tsx b/packages/web/src/router.tsxindex 30cf9aaf..aa90956b 100644--- a/packages/web/src/router.tsx+++ b/packages/web/src/router.tsx@@ -24,6 +24,7 @@ import { PluginDetailPage } from "./features/plugins/plugin-detail-page";import { UsagePage } from "./features/usage/usage-page";import { BenchmarkPage } from "./features/benchmark/benchmark-page";import { BenchmarkDetailPage } from "./features/benchmark/benchmark-detail-page";+import { SchedulesPage } from "./features/schedules/schedules-page";import { TerminalPage } from "./features/terminal/terminal-page";import { OrgIndexRedirect, OrgLayout } from "./features/company/org-layout";import { OverviewPage } from "./features/company/overview-page";@@ -53,6 +54,7 @@ const BUILTIN_PAGES: Record<string, React.ComponentType> = {UsagePage,BenchmarkPage,BenchmarkDetailPage,+ SchedulesPage,};function renderPage(page: PageEntry): React.ReactNode {diff --git a/packages/web/test/icon-registry.test.ts b/packages/web/test/icon-registry.test.tsindex 1bd4e7a2..91a0deec 100644--- a/packages/web/test/icon-registry.test.ts+++ b/packages/web/test/icon-registry.test.ts@@ -43,7 +43,7 @@ const ALLOWLIST: Readonly<Record<string, readonly [number, string]>> = {"features/company/shared.tsx": [2, "W4"],"features/models/models-page.tsx": [4, "W4"],"features/plugins/plugins-page.tsx": [2, "W4"],- "features/schedules/schedule-panel.tsx": [3, "W4"],+ "features/schedules/schedule-row.tsx": [3, "W4"],"features/schedules/schedule-suggestions.tsx": [3, "W4"],"features/semantic-id/semantic-id-field.tsx": [1, "W2"],"features/settings/shortcuts-section.tsx": [1, "W10"],diff --git a/packages/web/test/schedules-page-state.test.ts b/packages/web/test/schedules-page-state.test.tsnew file mode 100644index 00000000..fea52086--- /dev/null+++ b/packages/web/test/schedules-page-state.test.ts@@ -0,0 +1,74 @@+/**+ * The scheduled-tasks page's pure rules (src/features/schedules/schedule-page-state.ts): how the+ * Project's one flat list of tasks becomes the page's per-Agent groups, and which Agent comes+ * first.+ */+import { describe, expect, it } from "vitest";+import type { ProjectScheduleItem } from "@lmliheng/penguin-server/api";+import { groupSchedulesByAgent } from "../src/features/schedules/schedule-page-state";++function task(name: string, agentId: string): ProjectScheduleItem {+ return {+ name,+ agentId,+ prompt: "Summarize yesterday",+ enabled: true,+ startAt: "2026-09-01T00:00:00.000Z",+ status: "active",+ queued: false,+ };+}++/** The groups as assertions read them: `agentId` → the names under it. */+const shape = (items: ProjectScheduleItem[], order: string[]) =>+ groupSchedulesByAgent(items, order).map((g) => [g.agentId, g.items.map((i) => i.name)]);++describe("groupSchedulesByAgent", () => {+ it("collects each Agent's tasks under it, in the server's order", () => {+ const items = [task("a", "writer"), task("b", "writer"), task("c", "reviewer")];+ expect(shape(items, ["writer", "reviewer"])).toEqual([+ ["writer", ["a", "b"]],+ ["reviewer", ["c"]],+ ]);+ });++ it("follows the Agent list's order, not the order the tasks arrive in", () => {+ const items = [task("c", "reviewer"), task("a", "writer")];+ expect(shape(items, ["writer", "reviewer"])).toEqual([+ ["writer", ["a"]],+ ["reviewer", ["c"]],+ ]);+ });++ it("omits an Agent with no task rather than drawing an empty group", () => {+ expect(shape([task("a", "writer")], ["writer", "reviewer"])).toEqual([["writer", ["a"]]]);+ expect(shape([], ["writer"])).toEqual([]);+ });++ it("keeps a task whose Agent is not in the list, after the ones that are", () => {+ const items = [task("ghost", "retired"), task("a", "writer")];+ expect(shape(items, ["writer", "reviewer"])).toEqual([+ ["writer", ["a"]],+ ["retired", ["ghost"]],+ ]);+ });++ it("orders the unknown Agents by first appearance, among themselves", () => {+ const items = [task("g1", "b"), task("g2", "a"), task("g3", "b")];+ expect(shape(items, ["writer"])).toEqual([+ ["b", ["g1", "g3"]],+ ["a", ["g2"]],+ ]);+ });++ it("keeps the caller's item type, so the page still knows which Agent owns each task", () => {+ const items = [task("a", "writer")];+ // The annotation is the assertion: the page writes to a task's own agent directory, so a+ // grouping that handed back a narrower type would not compile here.+ const groups: { agentId: string; items: ProjectScheduleItem[] }[] = groupSchedulesByAgent(+ items,+ ["writer"],+ );+ expect(groups[0]?.items[0]?.agentId).toBe("writer");+ });+});