@fickydev/pigent 0.1.9 → 0.1.11

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/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  ### Added
6
6
 
7
+ - Added `task_runs` table and `TaskRepository` for scheduled task persistence.
8
+ - Added `Scheduler` module with global tick, per-task due check, lock, NOOP handling, and channel output.
9
+ - Added `scheduler` block to root config (`pigent.yaml`) with `tickIntervalMs` and `tasks[]`.
10
+ - Added `agent` field to task config to reference which agent executes the task.
11
+ - Replaced per-agent `heartbeat` config with daemon-level scheduler.
12
+ - Wired scheduler into daemon start/stop lifecycle.
13
+ - Added `task_configs` table and `TaskConfigRepository` for runtime task CRUD.
14
+ - Added `/task list`, `/task create <intervalMs> <prompt>`, `/task remove <id>` Telegram commands.
15
+ - Scheduler loads tasks from both config file and database, supports hot-add and hot-remove.
16
+ - Scheduler now shares AgentRunner's per-session lock instead of using its own PiAgentRunner.
17
+ - Tasks skip message persistence (inbound/outbound) in AgentRunner to avoid DB noise.
18
+ - Added `source` field to InboundMessage type (`"user"` default, `"task"` for scheduled runs).
19
+
7
20
  - Added `bunx @fickydev/pigent <dir>` scaffold/setup/run CLI path.
8
21
  - Added one-command setup-and-run CLI at `src/cli/run.ts` and `bun run run`.
9
22
  - Added interactive setup CLI at `src/cli/setup.ts` and `bun run setup`.
package/PLAN.md CHANGED
@@ -77,17 +77,18 @@ Skill is Pi-compatible instruction bundle, usually a `SKILL.md` folder. Agents c
77
77
 
78
78
  Extension is Pi-compatible TypeScript/JavaScript module that adds tools, hooks, commands, or runtime behavior. Agents can load different extensions.
79
79
 
80
- ### Heartbeat
80
+ ### Scheduled Tasks
81
81
 
82
- Heartbeat is scheduled self-activation. It prompts an agent periodically to check tasks, channels, external state, or pending work.
82
+ Scheduled tasks are periodic self-activations defined in `pigent.yaml` or created at runtime via `/task create`. Each task references an agent, an interval, a prompt, and a target channel.
83
83
 
84
- Heartbeat must avoid spam via:
84
+ The global `Scheduler` ticks on a configurable interval and evaluates every task's due-ness against its last run timestamp.
85
85
 
86
- - `NOOP` convention
87
- - cooldowns
88
- - dedupe
89
- - max messages per hour
90
- - lock per agent/session
86
+ Constraints:
87
+
88
+ - `NOOP` convention — agent returns "NOOP" to skip output
89
+ - Per-task lock prevent stacking runs of the same task
90
+ - Max messages per hour — rate limit (not yet implemented)
91
+ - Tasks must share the same session lock as user messages to avoid concurrent Pi runs for the same agent+channel+chat
91
92
 
92
93
  ## Target Architecture
93
94
 
@@ -252,9 +253,10 @@ Initial entities:
252
253
  - telegram chats
253
254
  - telegram chat agents
254
255
  - messages
255
- - heartbeats
256
+ - task_runs (history)
257
+ - task_configs (runtime task definitions)
258
+ - runtime_kv (offsets, daemon state)
256
259
  - session model/thinking overrides
257
- - tasks/events later
258
260
 
259
261
  SQLite first. Keep schema types portable so PostgreSQL migration is straightforward.
260
262
 
@@ -282,7 +284,8 @@ src/
282
284
 
283
285
  daemon/
284
286
  AgentDaemon.ts
285
- HeartbeatScheduler.ts
287
+ Scheduler.ts
288
+ taskDue.ts
286
289
 
287
290
  channels/
288
291
  types.ts
@@ -299,15 +302,19 @@ src/
299
302
 
300
303
  pi/
301
304
  PiAgentRunner.ts
302
- PiSessionFactory.ts
305
+ PiAvailableModels.ts
306
+ PiModelResolver.ts
303
307
 
304
308
  db/
305
309
  client.ts
306
310
  schema.ts
307
311
  repositories/
308
312
  AgentRepository.ts
313
+ HeartbeatRepository.ts
309
314
  MessageRepository.ts
310
315
  SessionRepository.ts
316
+ TaskRepository.ts
317
+ TaskConfigRepository.ts
311
318
  TelegramRepository.ts
312
319
 
313
320
  config/
@@ -384,13 +391,16 @@ drizzle/
384
391
  - return responses
385
392
  - persist inbound/outbound messages
386
393
 
387
- ### Milestone 7: Heartbeat
394
+ ### Milestone 7: Scheduler
388
395
 
389
- - scheduler
390
- - per-agent lock
396
+ - global scheduler tick
397
+ - config-based tasks from `pigent.yaml`
398
+ - DB-based tasks (runtime CRUD via `/task` commands)
399
+ - per-task lock
400
+ - shared session lock with user messages (prevent concurrent Pi runs)
391
401
  - `NOOP` handling
392
- - notification cooldown
393
- - heartbeat history
402
+ - notification rate limits (future)
403
+ - `/task list`, `/task create`, `/task remove` commands
394
404
 
395
405
  ### Milestone 8: Safety
396
406
 
@@ -425,8 +435,9 @@ Add Hono only after daemon works. Use it for:
425
435
 
426
436
  - Should `/model <agentId> ...` support non-default agent sessions in the command itself?
427
437
  - Should model availability errors block `/model` saves or save with a warning?
428
- - Which Pi SDK session manager should be used for persistent sessions?
429
438
  - How exactly should per-agent skills/extensions be loaded into Pi runtime?
430
439
  - Should group instructions live in YAML, DB, or both?
431
440
  - Should each chat have one default agent or multiple active agents?
432
441
  - What minimum approval flow is needed before shell/file-write tools?
442
+ - Should scheduled tasks share the same session lock as user messages, or allow concurrent Pi runs?
443
+ - Should `/task create` enforce permission checks before allowing runtime task creation?
package/TODO.md CHANGED
@@ -145,17 +145,24 @@
145
145
  - [x] Prototype one prompt through Pi SDK
146
146
  - [x] Decide CLI fallback strategy if SDK gaps appear
147
147
 
148
- ## Heartbeat
149
-
150
- - [ ] Define heartbeat config
151
- - [ ] Implement scheduler
152
- - [ ] Add per-agent heartbeat lock
153
- - [ ] Add heartbeat prompt composition
154
- - [ ] Add `NOOP` handling
155
- - [x] Persist heartbeat start/result/failure
156
- - [ ] Add notification cooldown
157
- - [ ] Add max heartbeat messages per hour
158
- - [ ] Send heartbeat output to configured channel only when useful
148
+ ## Scheduler
149
+
150
+ - [x] Define task config schema
151
+ - [x] Move task config from per-agent to daemon-level (`pigent.yaml`)
152
+ - [x] Add `task_runs` database table
153
+ - [x] Implement `TaskRepository`
154
+ - [x] Create `Scheduler` module (global tick, per-task due check, lock, NOOP, channel output)
155
+ - [x] Wire scheduler into daemon start/stop
156
+ - [x] Update example root config with scheduler block
157
+ - [x] Add `task_configs` DB table for runtime task definitions
158
+ - [x] Add `TaskConfigRepository`
159
+ - [x] Add `/task list` command
160
+ - [x] Add `/task create <intervalMs> <prompt>` command
161
+ - [x] Add `/task remove <id>` command
162
+ - [x] Scheduler loads tasks from both config file + DB
163
+ - [x] Share session lock between Scheduler and AgentRunner (prevent concurrent Pi runs for same agent+chat)
164
+ - [ ] Add max task runs per hour rate limit
165
+ - [ ] Add `/task status` or similar command
159
166
 
160
167
  ## Policy And Safety
161
168
 
@@ -196,11 +203,11 @@
196
203
 
197
204
  ## Tests
198
205
 
206
+ - [x] Unit test `isTaskDue` logic
199
207
  - [ ] Unit test config validation
200
208
  - [ ] Unit test Telegram update normalization
201
209
  - [ ] Unit test routing rules
202
210
  - [ ] Unit test session key generation
203
- - [ ] Unit test heartbeat `NOOP` behavior
204
211
  - [ ] Unit test model selection priority
205
212
  - [ ] Unit test Telegram `/model` command parsing
206
213
  - [ ] Unit test Telegram model picker callback parsing
@@ -10,11 +10,6 @@ extensions: []
10
10
  channels:
11
11
  telegram:
12
12
  enabled: false
13
- heartbeat:
14
- enabled: false
15
- intervalMs: 600000
16
- prompt: |
17
- Check assigned tasks. If no useful action is needed, reply exactly: NOOP.
18
13
  permissions:
19
14
  canRunShell: false
20
15
  canEditFiles: false
@@ -0,0 +1,13 @@
1
+ CREATE TABLE `task_runs` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `agent_id` text NOT NULL,
4
+ `task_id` text NOT NULL,
5
+ `prompt` text NOT NULL,
6
+ `session_id` text,
7
+ `status` text NOT NULL,
8
+ `result` text,
9
+ `error` text,
10
+ `started_at` integer,
11
+ `finished_at` integer,
12
+ `created_at` integer NOT NULL
13
+ );
@@ -0,0 +1,11 @@
1
+ CREATE TABLE `task_configs` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `agent` text NOT NULL,
4
+ `interval_ms` integer NOT NULL,
5
+ `prompt` text NOT NULL,
6
+ `channel` text DEFAULT 'telegram' NOT NULL,
7
+ `chat_id` text NOT NULL,
8
+ `enabled` integer DEFAULT true NOT NULL,
9
+ `created_at` integer NOT NULL,
10
+ `updated_at` integer NOT NULL
11
+ );