@jl1990/pi-scheduler 0.1.1 → 0.2.0

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # Pi Scheduler
2
2
 
3
- **Give Pi coding agents a clock: schedule reminders, shell commands, and self-waking prompts for CI polling and autonomous follow-ups.**
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. Use it for simple reminders, delayed shell commands, or autonomous workflows where the agent needs to wake itself up later, check an external system, and continue.
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 the agent to remind you or continue a task after a delay.
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 its own follow-up prompt:
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
- > “Check the pipeline again in 3 minutes. If it failed, inspect logs and fix it. If it is still running, schedule another check.”
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
- - **Delayed shell commands** — run commands later with optional follow-up prompts containing stdout/stderr.
24
- - **Reminders and messages** — notify the user or inject scheduled messages.
25
- - **Agent-callable tools** — the LLM can schedule, list, and cancel tasks itself.
26
- - **Slash commands** — manually schedule tasks from the Pi prompt.
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 pending or historical tasks.
55
- - `cancel_scheduled_task` — cancel a pending task by ID or prefix.
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
- | `prompt` | Injects a future user prompt and wakes the agent | CI polling, deployments, autonomous follow-ups |
62
- | `shell` | Runs a future shell command | Delayed checks, tests, status commands |
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
- ## Example: autonomous GitLab pipeline polling
70
+ ### Schedule types
67
71
 
68
- Ask the agent to create a pipeline, then schedule itself to check it:
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": "prompt",
73
- "when": "3m",
74
- "prompt": "Check GitLab pipeline 123 for project jl1990/example. If it passed, report success. If it failed, inspect the failed job logs and propose or apply fixes. If it is still running, schedule another check in 3 minutes."
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
- This pattern lets the agent keep working without you manually nudging it every few minutes.
104
+ ## Example: recurring agent prompt
79
105
 
80
- ## Example: run a command later, then wake the agent
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
- "when": "2m",
86
- "command": "glab pipeline view 123 --repo jl1990/example",
87
- "followUpPrompt": "Review this pipeline status. If it is still running, schedule another check. If it failed, inspect logs and fix the issue."
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] <when> :: <payload>
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 at 14:30 :: npm test
149
+ /schedule shell every 5m :: glab pipeline view 123 --repo jl1990/example
150
+ /schedule shell cron 0 */5 * * * * :: date
109
151
  /schedules
110
- /schedule-cancel task_abc123
152
+ /schedules all
153
+ /schedule-disable task_abc123
154
+ /schedule-cleanup
111
155
  ```
112
156
 
113
157
  ## Time formats
114
158
 
115
- Supported examples:
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,56 @@ 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
+ ## How this differs from `pi-schedule-prompt`
209
+
210
+ [`pi-schedule-prompt`](https://github.com/tintinweb/pi-schedule-prompt) is a mature prompt scheduler with a richer prompt-focused UI and optional per-task model/subagent mode.
211
+
212
+ Pi Scheduler focuses on **scheduled actions**:
213
+
214
+ - direct scheduled shell commands
215
+ - deterministic stdout/stderr capture
216
+ - success/failure-specific agent wakeups
217
+ - bounded command polling with `maxRuns`
218
+ - prompt/notify/message actions as lightweight companions
219
+
220
+ If you mainly want recurring prompts and a full jobs overlay, `pi-schedule-prompt` may be the better fit. If you want delayed or recurring command execution with result-aware follow-up, use Pi Scheduler.
221
+
127
222
  ## Important limitations
128
223
 
129
224
  Pi Scheduler currently uses **in-process timers**:
@@ -168,12 +263,7 @@ This package is published as:
168
263
  @jl1990/pi-scheduler
169
264
  ```
170
265
 
171
- The GitHub Actions workflow `.github/workflows/publish-npm.yml` publishes to npm when a GitHub Release is published. It also supports manual runs from the Actions tab, including a dry-run option.
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.
266
+ The GitHub Actions workflow `.github/workflows/publish-npm.yml` publishes to npm when a GitHub Release is published.
177
267
 
178
268
  Release flow:
179
269