@fickydev/pigent 0.1.15 → 0.1.16
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 +6 -0
- package/README.md +184 -233
- package/TODO.md +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,290 +1,217 @@
|
|
|
1
1
|
# Pigent
|
|
2
2
|
|
|
3
|
-
Pigent
|
|
3
|
+
Pigent lets you run a Pi-powered assistant from Telegram.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Install it on a machine that stays online, connect a Telegram bot, then chat with your own coding/automation agent from Telegram private chats or groups. Pigent keeps per-chat sessions, supports multiple agents, and can run scheduled tasks.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## What Pigent Does
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- Runs as a background user service.
|
|
10
|
+
- Connects Telegram messages to Pi-backed agents.
|
|
11
|
+
- Keeps a separate session per agent + chat + thread.
|
|
12
|
+
- Lets you start a fresh session with `/new`.
|
|
13
|
+
- Shows current session/model/context info with `/status`.
|
|
14
|
+
- Supports model and thinking-level overrides from Telegram.
|
|
15
|
+
- Supports scheduled `/task` runs.
|
|
16
|
+
- Stores app state locally in SQLite.
|
|
17
|
+
- Persists Pi session files under `~/.pigent/pi-sessions` by default.
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
Telegram polling -> MessageRouter -> fake AgentRunner -> SQLite persistence -> Telegram reply
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Pi SDK execution is now wired through `PiAgentRunner`. Fake responses can still be forced for transport/routing tests with `PIGENT_FAKE_AGENT=1`.
|
|
16
|
-
|
|
17
|
-
## Stack
|
|
18
|
-
|
|
19
|
-
- Bun
|
|
20
|
-
- TypeScript
|
|
21
|
-
- Drizzle ORM
|
|
22
|
-
- SQLite now, PostgreSQL later
|
|
23
|
-
- Telegram polling first
|
|
24
|
-
- Pi SDK planned as execution core
|
|
25
|
-
- Hono deferred until webhooks/API are needed
|
|
26
|
-
|
|
27
|
-
## Architecture
|
|
28
|
-
|
|
29
|
-
```text
|
|
30
|
-
Channel Adapter -> Message Router -> Agent Orchestrator -> Pi Runner
|
|
31
|
-
-> State Store
|
|
32
|
-
-> Policy Engine
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Current modules:
|
|
36
|
-
|
|
37
|
-
```text
|
|
38
|
-
src/
|
|
39
|
-
main.ts
|
|
40
|
-
|
|
41
|
-
daemon/
|
|
42
|
-
AgentDaemon.ts
|
|
43
|
-
|
|
44
|
-
pi/
|
|
45
|
-
PiAgentRunner.ts
|
|
46
|
-
|
|
47
|
-
channels/
|
|
48
|
-
types.ts
|
|
49
|
-
telegram/
|
|
50
|
-
TelegramApi.ts
|
|
51
|
-
TelegramPollingAdapter.ts
|
|
52
|
-
types.ts
|
|
53
|
-
|
|
54
|
-
agents/
|
|
55
|
-
AgentRunner.ts
|
|
56
|
-
BotCommandHandler.ts
|
|
57
|
-
MessageRouter.ts
|
|
58
|
-
|
|
59
|
-
config/
|
|
60
|
-
loadConfig.ts
|
|
61
|
-
schemas.ts
|
|
19
|
+
Pigent is still an early MVP. Telegram polling is the first supported channel.
|
|
62
20
|
|
|
63
|
-
|
|
64
|
-
client.ts
|
|
65
|
-
schema.ts
|
|
66
|
-
repositories/
|
|
21
|
+
## Quick Start
|
|
67
22
|
|
|
68
|
-
|
|
69
|
-
logger.ts
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Setup And Run
|
|
73
|
-
|
|
74
|
-
Install and start Pigent as a user service:
|
|
23
|
+
Install and start Pigent:
|
|
75
24
|
|
|
76
25
|
```bash
|
|
77
26
|
bunx @fickydev/pigent
|
|
78
27
|
```
|
|
79
28
|
|
|
29
|
+
The setup wizard will ask for:
|
|
30
|
+
|
|
31
|
+
- quick or custom setup
|
|
32
|
+
- Telegram bot token
|
|
33
|
+
- default agent routing
|
|
34
|
+
- optional automatic Telegram chat setup
|
|
35
|
+
|
|
80
36
|
Default app directory:
|
|
81
37
|
|
|
82
38
|
```text
|
|
83
39
|
~/.pigent/app
|
|
84
40
|
```
|
|
85
41
|
|
|
86
|
-
After
|
|
42
|
+
After setup, use:
|
|
87
43
|
|
|
88
44
|
```bash
|
|
89
45
|
pigent status
|
|
90
46
|
pigent logs
|
|
91
|
-
pigent stop
|
|
92
|
-
pigent start
|
|
93
47
|
pigent restart
|
|
94
48
|
pigent update
|
|
95
49
|
pigent setup
|
|
96
50
|
```
|
|
97
51
|
|
|
98
|
-
Update
|
|
52
|
+
Update Pigent later:
|
|
99
53
|
|
|
100
54
|
```bash
|
|
101
55
|
pigent update
|
|
102
56
|
```
|
|
103
57
|
|
|
104
|
-
`pigent update` backs up the app,
|
|
58
|
+
`pigent update` backs up the app, keeps your `.env`, SQLite database, `pigent.yaml`, `agents/`, and `profiles/`, refreshes package files, then restarts the service.
|
|
105
59
|
|
|
106
|
-
|
|
60
|
+
## Create A Telegram Bot
|
|
107
61
|
|
|
108
|
-
|
|
109
|
-
|
|
62
|
+
1. Open Telegram and message `@BotFather`.
|
|
63
|
+
2. Send:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
/newbot
|
|
110
67
|
```
|
|
111
68
|
|
|
112
|
-
|
|
69
|
+
3. Follow BotFather prompts.
|
|
70
|
+
4. Copy the bot token.
|
|
71
|
+
5. Run setup again if needed:
|
|
113
72
|
|
|
114
73
|
```bash
|
|
115
|
-
|
|
74
|
+
pigent setup
|
|
116
75
|
```
|
|
117
76
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
- ask for quick or custom mode
|
|
121
|
-
- create `.env` from `.env.example` if missing
|
|
122
|
-
- configure `DATABASE_URL`
|
|
123
|
-
- optionally write or replace `TELEGRAM_BOT_TOKEN`
|
|
124
|
-
- optionally enable automatic Telegram chat setup
|
|
125
|
-
- optionally configure Telegram chat routing in `pigent.yaml`
|
|
126
|
-
- optionally configure log level and Telegram polling values in custom mode
|
|
127
|
-
Database migrations run automatically at daemon startup. The published CLI does not ask users to run `bun install`, `bun start`, or `bun typecheck`.
|
|
77
|
+
Paste the token when prompted.
|
|
128
78
|
|
|
129
|
-
|
|
79
|
+
You can also put it in `~/.pigent/app/.env`:
|
|
130
80
|
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
cp .env.example .env
|
|
134
|
-
bun run db:migrate
|
|
135
|
-
bun run typecheck
|
|
81
|
+
```env
|
|
82
|
+
TELEGRAM_BOT_TOKEN=123456:abc...
|
|
136
83
|
```
|
|
137
84
|
|
|
138
|
-
|
|
85
|
+
## First Chat
|
|
139
86
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
PIGENT_FAKE_AGENT=0
|
|
145
|
-
PIGENT_FALLBACK_FAKE_AGENT=1
|
|
146
|
-
PIGENT_AUTO_SETUP_CHATS=1
|
|
147
|
-
PIGENT_AUTO_SETUP_DEFAULT_AGENT=assistant
|
|
87
|
+
Send your bot a message in Telegram:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
/help
|
|
148
91
|
```
|
|
149
92
|
|
|
150
|
-
|
|
93
|
+
If automatic chat setup is enabled, Pigent will route the chat to the default `assistant` agent.
|
|
151
94
|
|
|
152
|
-
|
|
153
|
-
|
|
95
|
+
If automatic setup is disabled, configure the chat in `pigent.yaml`:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
telegramChats:
|
|
99
|
+
- chatId: "123456"
|
|
100
|
+
title: My Private Chat
|
|
101
|
+
defaultAgent: assistant
|
|
102
|
+
allowedAgents:
|
|
103
|
+
- assistant
|
|
104
|
+
instructions: |
|
|
105
|
+
Be concise.
|
|
154
106
|
```
|
|
155
107
|
|
|
156
|
-
|
|
108
|
+
Then restart:
|
|
157
109
|
|
|
158
110
|
```bash
|
|
159
|
-
|
|
111
|
+
pigent restart
|
|
160
112
|
```
|
|
161
113
|
|
|
162
|
-
|
|
114
|
+
To find a chat id, send any message to the bot and check logs:
|
|
163
115
|
|
|
164
116
|
```bash
|
|
165
|
-
|
|
117
|
+
pigent logs
|
|
166
118
|
```
|
|
167
119
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
### 1. Create bot
|
|
171
|
-
|
|
172
|
-
Use Telegram `@BotFather`:
|
|
120
|
+
Look for:
|
|
173
121
|
|
|
174
|
-
```
|
|
175
|
-
|
|
122
|
+
```json
|
|
123
|
+
{"message":"inbound message received","chatId":"123456"}
|
|
176
124
|
```
|
|
177
125
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
```env
|
|
181
|
-
TELEGRAM_BOT_TOKEN=123456:abc...
|
|
182
|
-
```
|
|
126
|
+
Group chat ids often start with `-100`.
|
|
183
127
|
|
|
184
|
-
|
|
128
|
+
## Telegram Commands
|
|
185
129
|
|
|
186
|
-
|
|
130
|
+
Common commands:
|
|
187
131
|
|
|
188
|
-
```
|
|
189
|
-
|
|
132
|
+
```text
|
|
133
|
+
/help Show help
|
|
134
|
+
/start Start bot help
|
|
135
|
+
/agents List agents
|
|
136
|
+
/new Start a fresh chat session
|
|
137
|
+
/status Show session/model/context status
|
|
138
|
+
/model Pick model
|
|
139
|
+
/thinking Pick thinking level
|
|
140
|
+
/agent <agentId> <message> Send message to a specific agent
|
|
141
|
+
@agentId <message> Send message to a specific agent
|
|
190
142
|
```
|
|
191
143
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
Logs will include:
|
|
144
|
+
Task commands:
|
|
195
145
|
|
|
196
|
-
```
|
|
197
|
-
|
|
146
|
+
```text
|
|
147
|
+
/task list
|
|
148
|
+
/task create <intervalMs> <prompt>
|
|
149
|
+
/task remove <id>
|
|
198
150
|
```
|
|
199
151
|
|
|
200
|
-
|
|
152
|
+
Example:
|
|
201
153
|
|
|
202
154
|
```text
|
|
203
|
-
|
|
155
|
+
/task create 3600000 Check repo status and summarize anything important.
|
|
204
156
|
```
|
|
205
157
|
|
|
206
|
-
|
|
158
|
+
## Sessions And Memory
|
|
207
159
|
|
|
208
|
-
|
|
160
|
+
Pigent keeps sessions by this key:
|
|
209
161
|
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
- chatId: "123456"
|
|
213
|
-
title: Ficky Private Chat
|
|
214
|
-
defaultAgent: assistant
|
|
215
|
-
allowedAgents:
|
|
216
|
-
- assistant
|
|
217
|
-
instructions: |
|
|
218
|
-
Be concise.
|
|
162
|
+
```text
|
|
163
|
+
agentId + channel + chatId + threadId
|
|
219
164
|
```
|
|
220
165
|
|
|
221
|
-
|
|
166
|
+
That means:
|
|
222
167
|
|
|
223
|
-
|
|
168
|
+
- private chats get their own session
|
|
169
|
+
- groups share a session by default
|
|
170
|
+
- Telegram forum topics can have separate sessions
|
|
171
|
+
- different agents do not share the same session
|
|
224
172
|
|
|
225
|
-
|
|
173
|
+
Use `/new` to end the current active session and start fresh. The next normal message creates a new Pi session file.
|
|
226
174
|
|
|
227
|
-
|
|
228
|
-
/help
|
|
229
|
-
```
|
|
175
|
+
Use `/status` to inspect current state. When a Pi session exists, status shows Pi context usage; otherwise it falls back to a database estimate.
|
|
230
176
|
|
|
231
|
-
|
|
232
|
-
/agents
|
|
233
|
-
```
|
|
177
|
+
Pi session files live here by default:
|
|
234
178
|
|
|
235
179
|
```text
|
|
236
|
-
|
|
180
|
+
~/.pigent/pi-sessions
|
|
237
181
|
```
|
|
238
182
|
|
|
239
|
-
|
|
240
|
-
@assistant review this
|
|
241
|
-
```
|
|
183
|
+
Override with:
|
|
242
184
|
|
|
243
|
-
```
|
|
244
|
-
/
|
|
185
|
+
```env
|
|
186
|
+
PIGENT_PI_SESSION_DIR=/path/to/pi-sessions
|
|
245
187
|
```
|
|
246
188
|
|
|
247
|
-
|
|
189
|
+
## Agents
|
|
190
|
+
|
|
191
|
+
The default assistant lives at:
|
|
248
192
|
|
|
249
193
|
```text
|
|
250
|
-
|
|
194
|
+
~/.pigent/app/agents/assistant/
|
|
251
195
|
```
|
|
252
196
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
## Agent Config
|
|
256
|
-
|
|
257
|
-
Example agent lives at:
|
|
197
|
+
Main files:
|
|
258
198
|
|
|
259
199
|
```text
|
|
260
200
|
agents/assistant/agent.yaml
|
|
261
201
|
agents/assistant/SYSTEM.md
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Example profile:
|
|
265
|
-
|
|
266
|
-
```text
|
|
267
202
|
profiles/assistant.yaml
|
|
268
203
|
```
|
|
269
204
|
|
|
270
|
-
|
|
205
|
+
Example `agent.yaml`:
|
|
271
206
|
|
|
272
207
|
```yaml
|
|
273
208
|
id: assistant
|
|
274
209
|
name: Assistant
|
|
275
|
-
profile:
|
|
210
|
+
profile: assistant
|
|
276
211
|
workspace: ~/.pigent/workspaces/assistant
|
|
277
212
|
systemPromptFile: ./SYSTEM.md
|
|
278
213
|
skills: []
|
|
279
214
|
extensions: []
|
|
280
|
-
channels:
|
|
281
|
-
telegram:
|
|
282
|
-
enabled: false
|
|
283
|
-
heartbeat:
|
|
284
|
-
enabled: false
|
|
285
|
-
intervalMs: 600000
|
|
286
|
-
prompt: |
|
|
287
|
-
Check assigned tasks. If no useful action is needed, reply exactly: NOOP.
|
|
288
215
|
permissions:
|
|
289
216
|
canRunShell: false
|
|
290
217
|
canEditFiles: false
|
|
@@ -292,100 +219,124 @@ permissions:
|
|
|
292
219
|
blockedTools: []
|
|
293
220
|
```
|
|
294
221
|
|
|
295
|
-
|
|
222
|
+
Edit `SYSTEM.md` to change how the agent behaves.
|
|
223
|
+
|
|
224
|
+
Each agent can have its own:
|
|
225
|
+
|
|
226
|
+
- name
|
|
227
|
+
- profile
|
|
228
|
+
- workspace
|
|
229
|
+
- system prompt
|
|
230
|
+
- skills/extensions
|
|
231
|
+
- permissions
|
|
296
232
|
|
|
297
|
-
|
|
233
|
+
## Configuration
|
|
298
234
|
|
|
299
|
-
|
|
235
|
+
Important environment variables in `~/.pigent/app/.env`:
|
|
300
236
|
|
|
301
237
|
```env
|
|
238
|
+
DATABASE_URL=file:./pigent.db
|
|
239
|
+
TELEGRAM_BOT_TOKEN=
|
|
240
|
+
PIGENT_WORKSPACE_ROOT=~/.pigent
|
|
241
|
+
PIGENT_PI_SESSION_DIR=~/.pigent/pi-sessions
|
|
242
|
+
PIGENT_FAKE_AGENT=0
|
|
243
|
+
PIGENT_FALLBACK_FAKE_AGENT=1
|
|
302
244
|
PIGENT_AUTO_SETUP_CHATS=1
|
|
303
245
|
PIGENT_AUTO_SETUP_DEFAULT_AGENT=assistant
|
|
304
246
|
```
|
|
305
247
|
|
|
306
|
-
|
|
248
|
+
Use fake mode only for testing Telegram routing without calling Pi:
|
|
307
249
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
250
|
+
```env
|
|
251
|
+
PIGENT_FAKE_AGENT=1
|
|
252
|
+
```
|
|
311
253
|
|
|
312
|
-
|
|
254
|
+
## Running In Foreground
|
|
313
255
|
|
|
314
|
-
|
|
256
|
+
Run without installing a service:
|
|
315
257
|
|
|
316
|
-
|
|
258
|
+
```bash
|
|
259
|
+
bunx @fickydev/pigent run
|
|
260
|
+
```
|
|
317
261
|
|
|
318
|
-
|
|
262
|
+
From a checked-out repo:
|
|
319
263
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
264
|
+
```bash
|
|
265
|
+
bun install
|
|
266
|
+
bun run run
|
|
267
|
+
```
|
|
324
268
|
|
|
325
|
-
|
|
269
|
+
Development commands:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
bun run start
|
|
273
|
+
bun run dev
|
|
274
|
+
bun run typecheck
|
|
275
|
+
bun run check
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Data Storage
|
|
279
|
+
|
|
280
|
+
Pigent stores local runtime data in SQLite.
|
|
281
|
+
|
|
282
|
+
Default database:
|
|
326
283
|
|
|
327
284
|
```text
|
|
328
|
-
|
|
285
|
+
~/.pigent/app/pigent.db
|
|
329
286
|
```
|
|
330
287
|
|
|
331
|
-
|
|
288
|
+
Configured by:
|
|
332
289
|
|
|
333
|
-
|
|
290
|
+
```env
|
|
291
|
+
DATABASE_URL=file:./pigent.db
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Important tables include:
|
|
334
295
|
|
|
335
296
|
- `agents`
|
|
336
297
|
- `agent_sessions`
|
|
337
298
|
- `telegram_chats`
|
|
338
299
|
- `telegram_chat_agents`
|
|
339
300
|
- `messages`
|
|
340
|
-
- `
|
|
301
|
+
- `task_configs`
|
|
302
|
+
- `task_runs`
|
|
341
303
|
- `runtime_kv`
|
|
342
304
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
```env
|
|
346
|
-
DATABASE_URL=file:./pigent.db
|
|
347
|
-
```
|
|
305
|
+
Database migrations run automatically when the daemon starts.
|
|
348
306
|
|
|
349
|
-
##
|
|
307
|
+
## Architecture
|
|
350
308
|
|
|
351
|
-
|
|
309
|
+
High-level flow:
|
|
352
310
|
|
|
353
311
|
```text
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
/agents
|
|
357
|
-
/new
|
|
358
|
-
/status
|
|
359
|
-
/model
|
|
360
|
-
/thinking
|
|
361
|
-
/task list
|
|
362
|
-
/task create <intervalMs> <prompt>
|
|
363
|
-
/task remove <id>
|
|
364
|
-
/agent <agentId> <message>
|
|
312
|
+
Telegram -> Message Router -> Agent Runner -> Pi Runner
|
|
313
|
+
\-> SQLite state
|
|
365
314
|
```
|
|
366
315
|
|
|
367
|
-
|
|
316
|
+
Code layout:
|
|
368
317
|
|
|
369
318
|
```text
|
|
370
|
-
/
|
|
371
|
-
|
|
372
|
-
/
|
|
373
|
-
/
|
|
374
|
-
/
|
|
319
|
+
src/
|
|
320
|
+
main.ts
|
|
321
|
+
daemon/
|
|
322
|
+
channels/telegram/
|
|
323
|
+
agents/
|
|
324
|
+
pi/
|
|
325
|
+
db/
|
|
326
|
+
config/
|
|
327
|
+
logging/
|
|
375
328
|
```
|
|
376
329
|
|
|
377
|
-
##
|
|
330
|
+
## Safety Notes
|
|
378
331
|
|
|
379
|
-
- Do not
|
|
380
|
-
- Keep Telegram-specific logic inside
|
|
381
|
-
- Channel adapters
|
|
382
|
-
- Pi runner
|
|
383
|
-
-
|
|
384
|
-
-
|
|
385
|
-
- Keep SQLite/PostgreSQL portability in mind.
|
|
386
|
-
- Never inject secrets or raw `.env` values into model prompts.
|
|
332
|
+
- Do not put bot tokens or API keys in prompts.
|
|
333
|
+
- Keep Telegram-specific logic inside the Telegram channel adapter or routing config.
|
|
334
|
+
- Channel adapters should not call Pi directly.
|
|
335
|
+
- Pi runner should not know Telegram secrets.
|
|
336
|
+
- Default permissions are conservative.
|
|
337
|
+
- File and shell capabilities should be enabled only for trusted agents/workspaces.
|
|
387
338
|
|
|
388
|
-
|
|
339
|
+
## More Docs
|
|
389
340
|
|
|
390
341
|
- `PLAN.md` — architecture and milestones
|
|
391
342
|
- `TODO.md` — task checklist
|
package/TODO.md
CHANGED
|
@@ -143,6 +143,7 @@
|
|
|
143
143
|
- [x] Persist Pi session file path per active Pigent session
|
|
144
144
|
- [x] Reuse Pi session files across messages
|
|
145
145
|
- [x] Self-heal missing runtime `agent_sessions` columns after partial/mismatched migration state
|
|
146
|
+
- [x] Make README more end-user facing
|
|
146
147
|
- [ ] Confirm per-agent system prompt injection
|
|
147
148
|
- [ ] Confirm per-agent skills loading
|
|
148
149
|
- [ ] Confirm per-agent extensions loading
|