@jl1990/pi-scheduler 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -36
- package/extensions/scheduler/index.ts +303 -62
- package/extensions/scheduler/scheduler-core.cjs +387 -59
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Pi Scheduler
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Scheduled actions for Pi agents: reminders, self-waking prompts, recurring shell commands, and command-output follow-ups.**
|
|
4
4
|
|
|
5
|
-
Pi Scheduler is a [Pi](https://github.com/earendil-works/pi) extension that lets an agent schedule future work from inside the conversation.
|
|
5
|
+
Pi Scheduler is a [Pi](https://github.com/earendil-works/pi) extension that lets an agent schedule future work from inside the conversation. It focuses on **scheduled actions**, not just prompts: the agent can wake itself later, run shell commands directly, capture stdout/stderr, and decide what to do next.
|
|
6
6
|
|
|
7
7
|
## Why?
|
|
8
8
|
|
|
@@ -11,19 +11,22 @@ Coding agents often need to wait:
|
|
|
11
11
|
- A GitLab/GitHub pipeline is still running.
|
|
12
12
|
- A deployment needs a few minutes to roll out.
|
|
13
13
|
- A long build or test command should be checked later.
|
|
14
|
-
- You want
|
|
14
|
+
- You want a reminder or a recurring project check.
|
|
15
15
|
|
|
16
|
-
Without scheduling, the agent has to stop and hope you come back. With Pi Scheduler, it can schedule
|
|
16
|
+
Without scheduling, the agent has to stop and hope you come back. With Pi Scheduler, it can schedule follow-up work such as:
|
|
17
17
|
|
|
18
|
-
> “
|
|
18
|
+
> “Run `glab pipeline view` every 5 minutes, wake me only on failure, and stop after 10 checks.”
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- **Self-waking prompts** — schedule a future prompt that wakes the agent in the current Pi session.
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
23
|
+
- **Direct shell scheduling** — run commands later or repeatedly without first asking the model to call `bash`.
|
|
24
|
+
- **Command-output follow-ups** — feed stdout/stderr back to the agent with success/failure-specific instructions.
|
|
25
|
+
- **Recurring schedules** — `once`, `interval`, and `cron` schedules for all action types.
|
|
26
|
+
- **Bounded polling** — `maxRuns` disables recurring tasks after a fixed number of executions.
|
|
27
|
+
- **Task lifecycle management** — enable, disable, update, remove, cleanup, list.
|
|
28
|
+
- **Scopes** — bind tasks to a session, cwd/project, or all sessions.
|
|
29
|
+
- **Compact widget** — shows the next few scheduled actions below the editor.
|
|
27
30
|
- **Persistent state** — scheduled tasks are stored in `~/.pi/agent/state/scheduler/tasks.json`.
|
|
28
31
|
|
|
29
32
|
## Install
|
|
@@ -50,54 +53,92 @@ Then restart Pi, or run:
|
|
|
50
53
|
|
|
51
54
|
Pi Scheduler registers these tools for the agent:
|
|
52
55
|
|
|
53
|
-
- `schedule_task` — schedule a future action.
|
|
54
|
-
- `list_scheduled_tasks` — list
|
|
55
|
-
- `cancel_scheduled_task` — cancel a
|
|
56
|
+
- `schedule_task` — schedule a future or recurring action.
|
|
57
|
+
- `list_scheduled_tasks` — list active or historical tasks.
|
|
58
|
+
- `cancel_scheduled_task` — cancel a task by ID or prefix.
|
|
59
|
+
- `manage_scheduled_task` — enable, disable, remove, update, or cleanup tasks.
|
|
56
60
|
|
|
57
61
|
### Scheduled action types
|
|
58
62
|
|
|
59
63
|
| Action | What it does | Best for |
|
|
60
64
|
| --- | --- | --- |
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
65
|
+
| `shell` | Runs a shell command and stores stdout/stderr | CI polling, tests, status commands |
|
|
66
|
+
| `prompt` | Injects a user prompt and wakes the agent | Agentic follow-ups |
|
|
63
67
|
| `notify` | Shows a reminder/notification | Human reminders |
|
|
64
68
|
| `message` | Injects a scheduled custom message | Lightweight status/context messages |
|
|
65
69
|
|
|
66
|
-
|
|
70
|
+
### Schedule types
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
| Type | Example | Meaning |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| `once` | `5m`, `tomorrow at 9am`, ISO datetime | Run one time |
|
|
75
|
+
| `interval` | `5m`, `1h`, `30s` | Run repeatedly after each interval |
|
|
76
|
+
| `cron` | `0 */5 * * * *` | Run on a cron schedule via `croner` |
|
|
77
|
+
|
|
78
|
+
Cron expressions use `croner`; 6-field expressions with seconds are recommended:
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
0 */5 * * * * every 5 minutes
|
|
82
|
+
0 0 * * * * hourly
|
|
83
|
+
0 0 9 * * 1-5 weekdays at 9am
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Example: bounded GitLab pipeline polling
|
|
87
|
+
|
|
88
|
+
Schedule a direct command every 5 minutes, wake the agent only if it fails, and stop after 10 checks:
|
|
69
89
|
|
|
70
90
|
```json
|
|
71
91
|
{
|
|
72
|
-
"action": "
|
|
73
|
-
"
|
|
74
|
-
"
|
|
92
|
+
"action": "shell",
|
|
93
|
+
"type": "interval",
|
|
94
|
+
"schedule": "5m",
|
|
95
|
+
"name": "pipeline-123",
|
|
96
|
+
"command": "glab pipeline view 123 --repo jl1990/example",
|
|
97
|
+
"wakeOn": "failure",
|
|
98
|
+
"failurePrompt": "The scheduled pipeline check failed or returned a non-zero status. Inspect the pipeline/jobs/logs and propose or apply fixes.",
|
|
99
|
+
"maxRuns": 10,
|
|
100
|
+
"scope": "cwd"
|
|
75
101
|
}
|
|
76
102
|
```
|
|
77
103
|
|
|
78
|
-
|
|
104
|
+
## Example: recurring agent prompt
|
|
79
105
|
|
|
80
|
-
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"action": "prompt",
|
|
109
|
+
"type": "interval",
|
|
110
|
+
"schedule": "10m",
|
|
111
|
+
"prompt": "Check whether the deployment has finished. If it failed, inspect logs. If it is still running, continue monitoring.",
|
|
112
|
+
"maxRuns": 6
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Example: one-shot command with output review
|
|
81
117
|
|
|
82
118
|
```json
|
|
83
119
|
{
|
|
84
120
|
"action": "shell",
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
121
|
+
"type": "once",
|
|
122
|
+
"schedule": "2m",
|
|
123
|
+
"command": "npm test",
|
|
124
|
+
"wakeOn": "always",
|
|
125
|
+
"followUpPrompt": "Review this test output. If tests failed, fix the issue. If they passed, summarize the result."
|
|
88
126
|
}
|
|
89
127
|
```
|
|
90
128
|
|
|
91
|
-
When the command finishes, Pi Scheduler sends the command output back to the agent together with your follow-up instruction.
|
|
92
|
-
|
|
93
129
|
## Slash commands
|
|
94
130
|
|
|
95
131
|
```text
|
|
96
|
-
/schedule [notify|prompt|shell|message] <
|
|
132
|
+
/schedule [notify|prompt|shell|message] [once|interval|cron|every] <schedule> :: <payload>
|
|
97
133
|
/remind <when> <message>
|
|
98
134
|
/schedules
|
|
99
135
|
/schedules all
|
|
100
136
|
/schedule-cancel <id-or-prefix>
|
|
137
|
+
/schedule-enable <id-or-prefix>
|
|
138
|
+
/schedule-disable <id-or-prefix>
|
|
139
|
+
/schedule-remove <id-or-prefix>
|
|
140
|
+
/schedule-cleanup
|
|
141
|
+
/schedule-widget [on|off]
|
|
101
142
|
```
|
|
102
143
|
|
|
103
144
|
Examples:
|
|
@@ -105,17 +146,21 @@ Examples:
|
|
|
105
146
|
```text
|
|
106
147
|
/remind 5m stretch
|
|
107
148
|
/schedule prompt 3m :: Check the GitLab pipeline and schedule another check if still running.
|
|
108
|
-
/schedule shell
|
|
149
|
+
/schedule shell every 5m :: glab pipeline view 123 --repo jl1990/example
|
|
150
|
+
/schedule shell cron 0 */5 * * * * :: date
|
|
109
151
|
/schedules
|
|
110
|
-
/
|
|
152
|
+
/schedules all
|
|
153
|
+
/schedule-disable task_abc123
|
|
154
|
+
/schedule-cleanup
|
|
111
155
|
```
|
|
112
156
|
|
|
113
157
|
## Time formats
|
|
114
158
|
|
|
115
|
-
|
|
159
|
+
One-shot schedules support examples like:
|
|
116
160
|
|
|
117
161
|
```text
|
|
118
162
|
5m
|
|
163
|
+
+5m
|
|
119
164
|
in 10 minutes
|
|
120
165
|
1h30m
|
|
121
166
|
2 days
|
|
@@ -124,6 +169,54 @@ tomorrow at 9am
|
|
|
124
169
|
2026-07-06T10:00:00
|
|
125
170
|
```
|
|
126
171
|
|
|
172
|
+
Interval schedules use durations like:
|
|
173
|
+
|
|
174
|
+
```text
|
|
175
|
+
30s
|
|
176
|
+
5m
|
|
177
|
+
1h
|
|
178
|
+
2d
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Scopes
|
|
182
|
+
|
|
183
|
+
`scope` controls where a task is visible and allowed to fire:
|
|
184
|
+
|
|
185
|
+
| Scope | Behavior |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `session` | Default. Bound to the Pi session that created it. |
|
|
188
|
+
| `cwd` | Visible to Pi sessions in the same working directory. Good for project automation. |
|
|
189
|
+
| `global` | Visible from any Pi session. |
|
|
190
|
+
|
|
191
|
+
## Wake behavior for shell tasks
|
|
192
|
+
|
|
193
|
+
Shell tasks can control when the parent agent is woken:
|
|
194
|
+
|
|
195
|
+
| `wakeOn` | Behavior |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| `always` | Wake after every run if a prompt is configured. |
|
|
198
|
+
| `failure` | Wake only when the command exits non-zero or is killed/timed out. |
|
|
199
|
+
| `success` | Wake only on exit code 0. |
|
|
200
|
+
| `never` | Never wake the agent; just record the result. |
|
|
201
|
+
|
|
202
|
+
Prompt priority:
|
|
203
|
+
|
|
204
|
+
1. `successPrompt` on success
|
|
205
|
+
2. `failurePrompt` on failure
|
|
206
|
+
3. `followUpPrompt` fallback
|
|
207
|
+
|
|
208
|
+
## Design focus
|
|
209
|
+
|
|
210
|
+
Pi Scheduler focuses on **scheduled actions**:
|
|
211
|
+
|
|
212
|
+
- direct scheduled shell commands
|
|
213
|
+
- deterministic stdout/stderr capture
|
|
214
|
+
- success/failure-specific agent wakeups
|
|
215
|
+
- bounded command polling with `maxRuns`
|
|
216
|
+
- prompt/notify/message actions as lightweight companions
|
|
217
|
+
|
|
218
|
+
The goal is to make command-driven automation simple: schedule the check, capture the result, and wake the agent only when useful.
|
|
219
|
+
|
|
127
220
|
## Important limitations
|
|
128
221
|
|
|
129
222
|
Pi Scheduler currently uses **in-process timers**:
|
|
@@ -168,12 +261,7 @@ This package is published as:
|
|
|
168
261
|
@jl1990/pi-scheduler
|
|
169
262
|
```
|
|
170
263
|
|
|
171
|
-
The GitHub Actions workflow `.github/workflows/publish-npm.yml` publishes to npm when a GitHub Release is published.
|
|
172
|
-
|
|
173
|
-
Before the first automated publish, configure one of these npm auth methods:
|
|
174
|
-
|
|
175
|
-
1. **Trusted publishing** on npm, for repository `jl1990/pi-scheduler` and workflow `publish-npm.yml`.
|
|
176
|
-
2. Or a GitHub repository secret named `NPM_TOKEN` with publish permission.
|
|
264
|
+
The GitHub Actions workflow `.github/workflows/publish-npm.yml` publishes to npm when a GitHub Release is published.
|
|
177
265
|
|
|
178
266
|
Release flow:
|
|
179
267
|
|