|
| 1 | +# pi-schedule-prompt |
| 2 | + |
| 3 | +A [Pi](https://pi.dev) extension that schedules AI prompts to execute at specific times or intervals - for reminders, deferred tasks, and recurring automation. |
| 4 | + |
| 5 | + |
| 6 | +<img width="600" alt="image" src="https://github.com/tintinweb/pi-schedule-prompt/raw/master/media/screenshot.png" /> |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +https://github.com/user-attachments/assets/8c723cc4-cf3e-4b6a-abf5-85d4f46c73ba |
| 12 | + |
| 13 | +> **Status:** Production-ready. Natural language scheduling with cron expressions, intervals, relative time, and one-shot timers. |
| 14 | +
|
| 15 | +Schedule future prompts with natural language: |
| 16 | +- **"schedule 'analyze logs' every hour"** (recurring) |
| 17 | +- **"remind me to review PR in 30 minutes"** (one-time) |
| 18 | +- **"defer that task until tomorrow at 9am"** (specific time) |
| 19 | + |
| 20 | +## Features |
| 21 | + |
| 22 | +### Core `schedule_prompt` Tool |
| 23 | +- **Natural language scheduling**: "schedule X in 5 minutes", "every hour do Y" |
| 24 | +- **Multiple formats**: Cron expressions, intervals, ISO timestamps, relative time (+5m, +1h) |
| 25 | +- **Job types**: |
| 26 | + - **Recurring** (cron/interval) — repeats automatically |
| 27 | + - **One-shot** (once) — runs once then auto-disables |
| 28 | +- **Actions**: add, remove, list, enable, disable, update, cleanup |
| 29 | +- **Auto-cleanup**: Removes disabled jobs on session exit |
| 30 | + |
| 31 | +### Use Cases |
| 32 | + |
| 33 | +#### Schedule (Recurring Tasks) |
| 34 | +Execute prompts repeatedly at set intervals: |
| 35 | +``` |
| 36 | +"schedule 'check build status' every 5 minutes" |
| 37 | +"run 'analyze metrics' every hour" |
| 38 | +"execute 'daily summary' at midnight every day" |
| 39 | +``` |
| 40 | + |
| 41 | +#### Remind (One-time Notifications) |
| 42 | +Get prompted to do something once at a specific time: |
| 43 | +``` |
| 44 | +"remind me to review the PR in 30 minutes" |
| 45 | +"remind me to check deployment status in 1 hour" |
| 46 | +"remind me tomorrow at 9am to follow up on the issue" |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +### Enhanced Pi Features |
| 51 | +- ✓ **Live widget** below editor showing active schedules (auto-hides when empty) |
| 52 | +- ✓ **Human-readable display**: "every minute", "daily at 9:00" instead of raw cron expressions |
| 53 | +- ✓ **Status tracking**: next run, last run, execution count, errors, prompt preview |
| 54 | +- ✓ **Flexible scheduling**: 6-field cron, intervals (5m, 1h), relative time (+10s), ISO timestamps |
| 55 | +- ✓ **User commands**: `/schedule-prompt` interactive menu with widget visibility toggle |
| 56 | +- ✓ **Safety features**: duplicate name prevention, infinite loop detection, past timestamp handling |
| 57 | + |
| 58 | +## Install |
| 59 | + |
| 60 | +**Option A — Install from npm:** |
| 61 | +```bash |
| 62 | +pi install npm:pi-schedule-prompt |
| 63 | +``` |
| 64 | + |
| 65 | +**Option B — Load directly (dev):** |
| 66 | +```bash |
| 67 | +pi -e ~/projects/pi-cron-schedule/src/index.ts |
| 68 | +``` |
| 69 | + |
| 70 | +**Option C — Install from local folder:** |
| 71 | +```bash |
| 72 | +pi install ~/projects/pi-cron-schedule |
| 73 | +``` |
| 74 | + |
| 75 | +Then run `pi` normally; the extension auto-discovers. |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +### LLM-driven (automatic) |
| 80 | + |
| 81 | +The agent automatically uses `schedule_prompt` when you want to schedule, defer, or be reminded: |
| 82 | + |
| 83 | +``` |
| 84 | +You: Remind me to check the deployment logs in 10 minutes |
| 85 | +
|
| 86 | +Agent: [calls schedule_prompt with schedule="+10m", prompt="check the deployment logs"] |
| 87 | +✓ Scheduled job "abc123" to run in 10 minutes |
| 88 | +``` |
| 89 | + |
| 90 | +The widget displays below your editor (only when jobs exist): |
| 91 | + |
| 92 | +``` |
| 93 | + Scheduled Prompts (3 jobs) |
| 94 | + ✓ check-logs every hour check deployment logs in 45m 12m ago 5 |
| 95 | + ✗ daily-report daily analyze metrics in 8h never 0 |
| 96 | + ✓ review-pr Feb 13 15:30 review PR #123 in 2h never 0 |
| 97 | +``` |
| 98 | + |
| 99 | +### Manual commands |
| 100 | + |
| 101 | +| Command | Description | |
| 102 | +|---------|-------------| |
| 103 | +| `/schedule-prompt` | Interactive menu: view/add/toggle/remove jobs, cleanup, toggle widget visibility | |
| 104 | + |
| 105 | +### Schedule Formats |
| 106 | + |
| 107 | +The tool accepts multiple time formats: |
| 108 | + |
| 109 | +| Format | Example | Type | Description | |
| 110 | +|--------|---------|------|-------------| |
| 111 | +| **Relative time** | `+5m`, `+1h`, `+30s`, `+2d` | once | Runs once after delay | |
| 112 | +| **Interval** | `5m`, `1h`, `30s`, `2d` | interval | Repeats at interval | |
| 113 | +| **ISO timestamp** | `2026-02-13T15:30:00Z` | once | Runs once at exact time | |
| 114 | +| **Cron expression** | `0 */5 * * * *` | cron | Runs on cron schedule | |
| 115 | + |
| 116 | +**Cron format** (6 fields - **must include seconds**): |
| 117 | +``` |
| 118 | +┌─ second (0-59) |
| 119 | +│ ┌─ minute (0-59) |
| 120 | +│ │ ┌─ hour (0-23) |
| 121 | +│ │ │ ┌─ day of month (1-31) |
| 122 | +│ │ │ │ ┌─ month (1-12) |
| 123 | +│ │ │ │ │ ┌─ day of week (0-6, Sun-Sat) |
| 124 | +│ │ │ │ │ │ |
| 125 | +0 * * * * * → every minute |
| 126 | +0 0 * * * * → every hour |
| 127 | +0 */5 * * * * → every 5 minutes |
| 128 | +0 0 0 * * * → daily at midnight |
| 129 | +0 0 9 * * 1-5 → 9am on weekdays |
| 130 | +* * * * * * → every second |
| 131 | +``` |
| 132 | + |
| 133 | +**Note:** Traditional 5-field cron expressions (without seconds) are not supported. Use `0 * * * * *` for "every minute", not `* * * * *`. |
| 134 | + |
| 135 | +## How It Works |
| 136 | + |
| 137 | +**Storage:** |
| 138 | +- File-based persistence at `.pi/schedule-prompts.json` (project-local) |
| 139 | +- Atomic writes prevent corruption |
| 140 | +- Auto-creates directory structure |
| 141 | + |
| 142 | +**Scheduler:** |
| 143 | +- Uses `croner` library for cron expressions |
| 144 | +- Native `setTimeout`/`setInterval` for intervals and one-shots |
| 145 | +- Tracks: next run, last run, execution count, status (running/success/error) |
| 146 | + |
| 147 | +**Execution:** |
| 148 | +- Sends scheduled prompt as user message to Pi agent |
| 149 | +- Displays custom message showing what was triggered |
| 150 | +- Updates job statistics after each run |
| 151 | + |
| 152 | +**Safety:** |
| 153 | +- **Infinite loop prevention**: Blocks scheduled jobs from creating more schedules |
| 154 | +- **Past timestamp detection**: Auto-disables jobs scheduled in the past |
| 155 | +- **Duplicate names**: Prevents name collisions |
| 156 | +- **Auto-cleanup**: Removes disabled jobs on exit |
| 157 | + |
| 158 | +**Widget:** |
| 159 | +- Auto-hides when no jobs configured |
| 160 | +- Shows: status icon, name, schedule (human-readable), prompt (truncated), next run, last run, run count |
| 161 | +- Human-readable formatting: "every minute", "daily", "Feb 13 15:30" instead of raw cron/ISO |
| 162 | +- Auto-refreshes every 30 seconds |
| 163 | +- Toggleable visibility via `/schedule-prompt` menu |
| 164 | +- Status icons: `✓` enabled, `✗` disabled, `⟳` running, `!` error |
| 165 | + |
| 166 | +## Examples |
| 167 | + |
| 168 | +### One-time reminders |
| 169 | +``` |
| 170 | +"remind me to check logs in 5 minutes" |
| 171 | + → schedule="+5m", type=once |
| 172 | +
|
| 173 | +"schedule 'review metrics' for 3pm today" |
| 174 | + → schedule="2026-02-13T15:00:00Z", type=once |
| 175 | +``` |
| 176 | + |
| 177 | +### Recurring tasks |
| 178 | +``` |
| 179 | +"analyze error rates every 10 minutes" |
| 180 | + → schedule="10m", type=interval |
| 181 | +
|
| 182 | +"run daily summary at midnight" |
| 183 | + → schedule="0 0 0 * * *", type=cron |
| 184 | +
|
| 185 | +"check build status every hour" |
| 186 | + → schedule="0 0 * * * *", type=cron |
| 187 | +
|
| 188 | +"execute every minute" |
| 189 | + → schedule="0 * * * * *", type=cron |
| 190 | +``` |
| 191 | + |
| 192 | +### Heartbeat monitoring |
| 193 | +``` |
| 194 | +"check system health every 5 minutes" |
| 195 | + → schedule="5m", type=interval |
| 196 | +``` |
| 197 | + |
| 198 | +## Development |
| 199 | + |
| 200 | +**TypeScript check:** |
| 201 | +```bash |
| 202 | +npx tsc --noEmit |
| 203 | +``` |
| 204 | + |
| 205 | +**Test with Pi:** |
| 206 | +```bash |
| 207 | +pi -e ./src/index.ts |
| 208 | +``` |
| 209 | + |
| 210 | +## Project Structure |
| 211 | + |
| 212 | +``` |
| 213 | +src/ |
| 214 | + types.ts # CronJob, CronJobType, CronToolParams |
| 215 | + storage.ts # File-based persistence (.pi/schedule-prompts.json) |
| 216 | + scheduler.ts # Core scheduling engine with croner |
| 217 | + tool.ts # schedule_prompt tool definition |
| 218 | + ui/ |
| 219 | + cron-widget.ts # Live status widget below editor |
| 220 | + index.ts # Extension entry point |
| 221 | +``` |
| 222 | + |
| 223 | +## License |
| 224 | + |
| 225 | +MIT (see [LICENSE](LICENSE)) |
| 226 | + |
| 227 | +## Author |
| 228 | + |
| 229 | +[tintinweb](https://github.com/tintinweb) |
0 commit comments