Skip to content

Commit 2b43f08

Browse files
committed
initial
0 parents  commit 2b43f08

File tree

16 files changed

+5794
-0
lines changed

16 files changed

+5794
-0
lines changed

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build outputs
5+
dist/
6+
build/
7+
*.tsbuildinfo
8+
plan/
9+
10+
# Logs
11+
*.log
12+
npm-debug.log*
13+
yarn-debug.log*
14+
yarn-error.log*
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+
20+
# Editor directories
21+
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# Temporary files
28+
*.tmp
29+
.temp/

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Development files
2+
tsconfig.json
3+
.vscode/
4+
.git/
5+
.gitignore
6+
7+
# Documentation
8+
PLAN.md
9+
SUMMARY.md
10+
plan/
11+
media/
12+
13+
# Build artifacts
14+
*.log
15+
npm-debug.log*
16+
.DS_Store
17+
18+
# Tests (if any)
19+
test/
20+
tests/
21+
*.test.ts
22+
*.spec.ts

.pi/schedule-prompts.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"jobs": [
3+
{
4+
"id": "5j6HsAeYkc",
5+
"name": "job-PXwluQ",
6+
"schedule": "0 * * * * *",
7+
"prompt": "Say hi",
8+
"enabled": true,
9+
"type": "cron",
10+
"createdAt": "2026-02-13T09:46:10.036Z",
11+
"runCount": 10,
12+
"description": "Say hi every minute",
13+
"lastStatus": "success",
14+
"lastRun": "2026-02-13T10:18:00.031Z",
15+
"nextRun": "2026-02-13T10:19:00.000Z"
16+
},
17+
{
18+
"id": "hjqcTvBHJq",
19+
"name": "job-sEkJhk",
20+
"schedule": "0 0 0 * * *",
21+
"prompt": "Run the shell command: generate-daily-report",
22+
"enabled": true,
23+
"type": "cron",
24+
"createdAt": "2026-02-13T10:05:36.323Z",
25+
"runCount": 0,
26+
"description": "Daily report generation"
27+
},
28+
{
29+
"id": "QuEoTx2bir",
30+
"name": "job-h3PjB2",
31+
"schedule": "2026-02-14T10:06:19.854Z",
32+
"prompt": "Run the shell command: whoami",
33+
"enabled": true,
34+
"type": "once",
35+
"createdAt": "2026-02-13T10:06:19.854Z",
36+
"runCount": 0,
37+
"description": "Run whoami command tomorrow"
38+
}
39+
],
40+
"version": 1
41+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 tintinweb
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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)

media/demo.mp4

5.43 MB
Binary file not shown.

media/screenshot.png

188 KB
Loading

0 commit comments

Comments
 (0)