Skip to content

Scheduled prompts (cron-like) - #1409

Open
draxxris wants to merge 2 commits into
agegr:mainfrom
draxxris:scheduled-prompts
Open

draxxris wants to merge 2 commits into
agegr:mainfrom
draxxris:scheduled-prompts

Conversation

@draxxris

Copy link
Copy Markdown
Contributor
  1. Alleviate spacing problems with Settings popup tab bar
  2. Support scheduled tasks; add task listing to Settings popup

Add a schedule_prompt tool to Pi Web so the agent can schedule prompts
to itself, and a Settings tab that turns the feature off and lists and
cancels active jobs.

- Scheduler core (lib/scheduled-prompts.ts):
  - Add the schedule_prompt tool with add, list, remove, enable,
    disable, update and cleanup actions for cron (6-field), interval
    and one-shot jobs, using croner for cron expressions.
  - Store jobs in <cwd>/.pi/schedule-prompts.json.
  - Fire a job by sending a visible scheduled_prompt marker, then the
    prompt as a follow-up user message. Re-read the job before firing,
    record run count and status, and disable one-shot jobs after use.
  - Default jobs to the creating session; a scope parameter of
    workdir leaves them unbound so every session in the folder fires
    them. Refuse add from within a scheduled prompt to avoid loops.
  - Register each session's scheduler in a globalThis registry and a
    session liveness provider, so idle eviction keeps sessions that
    have live schedules.
- Integration:
  - In lib/rpc-manager.ts, load createScheduledPromptsExtension for
    normal sessions and wrap extensionsOverride with
    preferPiWebScheduledPromptsExtension, which drops a conflicting
    external schedule_prompt extension and its conflict error.
  - Add lib/scheduled-prompts-settings.ts: an enabled flag in
    ~/.pi/agent/scheduled-prompts/settings.json, on by default and
    failing closed when the file is damaged.
- API and Settings UI:
  - Add app/api/scheduled-prompts/route.ts: GET returns the switch and
    active jobs, PUT sets the switch (turning off stops all timers),
    DELETE cancels a job only if a live session is firing it.
  - Add components/ScheduledPromptsConfig.tsx, wired into
    SettingsPanel as a new schedule section with an icon, plus
    settings.css styles, ScheduledPromptsResponse in api-types.ts, and
    the section in lib/settings-navigation.ts.
  - Add schedule.* strings to the en, zh-CN and zh-TW locales.

(cherry picked from commit 5087f75e3e0195f4c04dc0fac10dad18c553b241)
Every section tab was forced to the same 96px box
(flex: 0 0 96px; width: 96px; padding: 0 2px), so the label length, not
the strip, decided the spacing between tabs: measured in the header at
1200px the visible gap between one tab's icon and the previous tab's
label ran from 12px (MCP → Scheduled prompts) to 44px (Plugins → MCP),
and "Scheduled prompts" needed 124px of content in its 96px box, so its
text spilled out of the tab and was clipped by the strip's scroll
overflow (scrollWidth 698 in a 684px nav, which also left the header
scrollable on a desktop window).

Let each tab take its own width with one padding that does the spacing
instead:

- flex: 0 0 auto, drop width: 96px, padding: 0 14px (the tab's content
  is the icon, a 5px gap and the label), keeping the 2px flex gap for
  the focus ring's radius.
- Padding is then the only space between tabs: 30px between one group
  and the next, on every pair, because 14px + 2px + 14px does not
  depend on what the labels say.
- No label overflows its tab any more: the widest, "Sub-agents" with
  its 1.25x-scaled icon, is 110px, and the strip is 644px instead of
  684, so it fits a window down to ~790px rather than ~845px.
  overflow-x: auto stays for narrower desktop windows, where the strip
  still scrolls as before.

The schedule tab's label is "Schedule" since the commit that adds the
section; its panel keeps the longer "Scheduled prompts" heading.

(cherry picked from commit 472fc778c7f16763800f86aa1fc295826c72cb19)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant