pi-discord-bot 0.1.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.
@@ -0,0 +1,278 @@
1
+ # Operator env and config guide
2
+
3
+ This page is for people operating `pi-discord-bot` locally, especially if they already use the normal Pi CLI / TUI on the same machine.
4
+
5
+ ## Mental model
6
+
7
+ `pi-discord-bot` uses:
8
+ - **Discord token** from an env file
9
+ - **Pi shared auth/settings** from your normal Pi setup
10
+ - **runtime workspace** outside the repo by default
11
+ - **Discord policy** from `<workspace>/discord-policy.json`
12
+
13
+ So in most cases you do **not** need to put model provider API keys in this repo-specific env file if Pi is already authenticated on the machine.
14
+
15
+ ---
16
+
17
+ ## 1. Environment file
18
+
19
+ Recommended path:
20
+
21
+ ```bash
22
+ ~/.config/pi-discord-bot.env
23
+ ```
24
+
25
+ Minimum example:
26
+
27
+ ```bash
28
+ DISCORD_TOKEN=your_discord_bot_token
29
+ ```
30
+
31
+ Optional:
32
+
33
+ ```bash
34
+ DISCORD_GUILD_ID=123456789012345678
35
+ ```
36
+
37
+ ### What each variable does
38
+
39
+ #### `DISCORD_TOKEN`
40
+ Required.
41
+ Used by the Discord bot client to log in.
42
+
43
+ #### `DISCORD_GUILD_ID`
44
+ Optional.
45
+ If set, the default generated policy can use it for guild-scoped slash command registration / faster iteration.
46
+ If omitted, the bot can register commands globally.
47
+
48
+ ---
49
+
50
+ ## 2. Pi auth and settings
51
+
52
+ This bot intentionally follows **Pi shared auth/settings/default model flow**.
53
+
54
+ That means:
55
+ - it uses Pi’s shared auth storage
56
+ - it uses Pi’s shared settings manager
57
+ - it does **not** hardcode a provider/model in repo config
58
+
59
+ ### If you already use Pi TUI / CLI
60
+ If you already use Pi normally on this machine, that is the expected setup.
61
+ The Discord bot should reuse that auth/settings context.
62
+
63
+ Typical user flow:
64
+ 1. open Pi TUI / CLI
65
+ 2. authenticate there
66
+ 3. run `pi-discord-bot`
67
+ 4. use `/model`, `/settings`, etc. in Discord if you want per-session changes
68
+
69
+ ### Important operator note
70
+ Do not keep stale repo docs or env files that suggest this bot requires provider-specific API keys like:
71
+ - `ANTHROPIC_API_KEY`
72
+ - `OPENAI_API_KEY`
73
+
74
+ Those may still be valid for Pi itself depending on your environment, but this bot is designed to rely on **Pi shared auth** rather than hardcoded bot-local model credentials.
75
+
76
+ ---
77
+
78
+ ## 3. Runtime workspace
79
+
80
+ Default runtime dir used by this repo:
81
+
82
+ ```text
83
+ $XDG_STATE_HOME/pi-discord-bot/agent
84
+ ```
85
+
86
+ or, if `XDG_STATE_HOME` is unset:
87
+
88
+ ```text
89
+ ~/.local/state/pi-discord-bot/agent
90
+ ```
91
+
92
+ Optional override via env:
93
+
94
+ ```bash
95
+ PI_DISCORD_BOT_WORKDIR=/absolute/path/to/pi-discord-bot-agent
96
+ ```
97
+
98
+ Important contents:
99
+
100
+ ```text
101
+ ./agent/
102
+ discord-policy.json
103
+ MEMORY.md
104
+ skills/
105
+ guild:.../
106
+ dm:.../
107
+ ```
108
+
109
+ Treat this directory as **private runtime state**.
110
+ It may contain:
111
+ - user messages
112
+ - assistant responses
113
+ - local file paths
114
+ - attachment metadata
115
+ - tool outputs
116
+
117
+ Do not commit or share it.
118
+
119
+ ---
120
+
121
+ ## 4. Discord policy file
122
+
123
+ Create it with:
124
+
125
+ ```bash
126
+ mkdir -p ~/.local/state/pi-discord-bot/agent
127
+ cp discord-policy.example.json ~/.local/state/pi-discord-bot/agent/discord-policy.json
128
+ ```
129
+
130
+ Or with a custom workspace:
131
+
132
+ ```bash
133
+ mkdir -p "$PI_DISCORD_BOT_WORKDIR"
134
+ cp discord-policy.example.json "$PI_DISCORD_BOT_WORKDIR/discord-policy.json"
135
+ ```
136
+
137
+ Example:
138
+
139
+ ```json
140
+ {
141
+ "allowDMs": true,
142
+ "guildIds": ["123456789012345678"],
143
+ "channelIds": ["234567890123456789"],
144
+ "mentionMode": "mention-only",
145
+ "slashCommands": {
146
+ "enabled": true
147
+ }
148
+ }
149
+ ```
150
+
151
+ ### Main fields
152
+
153
+ #### `allowDMs`
154
+ Allow or deny bot usage in DMs.
155
+
156
+ #### `guildIds`
157
+ Optional guild allowlist.
158
+ Omit to allow all guilds.
159
+
160
+ #### `channelIds`
161
+ Optional channel allowlist.
162
+ Omit to allow all channels.
163
+
164
+ #### `mentionMode`
165
+ - `mention-only`: normal guild chat must mention the bot
166
+ - `allow-all`: normal guild chat can be processed without mention gating
167
+
168
+ Text commands starting with `/` are still accepted as commands.
169
+
170
+ #### `slashCommands.enabled`
171
+ Enable or disable slash command registration.
172
+
173
+ #### `slashCommands.guildId`
174
+ Optional guild-scoped slash command registration.
175
+ Useful for faster development iteration.
176
+ If omitted, global commands are used.
177
+
178
+ ---
179
+
180
+ ## 5. How this fits with Pi TUI users
181
+
182
+ Most operators who use Pi already will probably do this:
183
+
184
+ ### Step A: authenticate in Pi first
185
+ Use Pi in its normal interface and make sure auth works there.
186
+
187
+ ### Step B: configure Discord env
188
+ Create:
189
+
190
+ ```bash
191
+ ~/.config/pi-discord-bot.env
192
+ ```
193
+
194
+ with at least:
195
+
196
+ ```bash
197
+ DISCORD_TOKEN=...
198
+ ```
199
+
200
+ ### Step C: configure workspace policy
201
+ Create:
202
+
203
+ ```bash
204
+ ~/.local/state/pi-discord-bot/agent/discord-policy.json
205
+ ```
206
+
207
+ ### Step D: start bot
208
+
209
+ ```bash
210
+ npx tsx src/main.ts ./agent
211
+ ```
212
+
213
+ or with systemd.
214
+
215
+ This is the intended operator workflow.
216
+ The workspace should live outside the repo.
217
+
218
+ ---
219
+
220
+ ## 6. systemd setup
221
+
222
+ Typical setup:
223
+
224
+ ```bash
225
+ mkdir -p ~/.config/systemd/user ~/.config
226
+ cp pi-discord-bot.service ~/.config/systemd/user/
227
+ cp pi-discord-bot.env.example ~/.config/pi-discord-bot.env
228
+ $EDITOR ~/.config/pi-discord-bot.env
229
+ systemctl --user daemon-reload
230
+ systemctl --user enable --now pi-discord-bot.service
231
+ ```
232
+
233
+ Useful commands:
234
+
235
+ ```bash
236
+ systemctl --user status pi-discord-bot.service
237
+ journalctl --user -u pi-discord-bot.service -f
238
+ systemctl --user restart pi-discord-bot.service
239
+ ```
240
+
241
+ ---
242
+
243
+ ## 7. Troubleshooting checklist
244
+
245
+ ### Bot starts but cannot answer model requests
246
+ Check that Pi auth works outside the bot first.
247
+ If Pi itself is not authenticated, the Discord bot will not have usable model access either.
248
+
249
+ ### Slash commands do not show immediately
250
+ If commands are global, Discord may take time to refresh them.
251
+ This is a Discord propagation issue, not necessarily a bot bug.
252
+
253
+ ### Normal guild messages are ignored
254
+ Check:
255
+ - `guildIds`
256
+ - `channelIds`
257
+ - `mentionMode`
258
+
259
+ If `mentionMode` is `mention-only`, normal chat must mention the bot.
260
+ Text commands like `/tree` are handled separately.
261
+
262
+ ### Admin actions fail
263
+ Check bot permissions in Discord:
264
+ - Manage Channels
265
+ - Create Public Threads
266
+ - Create Private Threads
267
+ - Send Messages
268
+ - Read Message History
269
+
270
+ ---
271
+
272
+ ## 8. Recommended operator practice
273
+
274
+ If you maintain this repo for other Pi users:
275
+ - keep env docs focused on `DISCORD_TOKEN`
276
+ - document Pi shared auth instead of provider-specific API keys
277
+ - keep `./agent` out of version control
278
+ - treat Discord policy and systemd as the main operator knobs
@@ -0,0 +1,95 @@
1
+ # Publishing checklist
2
+
3
+ Use this checklist before publishing `pi-discord-bot` as a public repo or future npm package.
4
+
5
+ ## 1. Publish safety review
6
+
7
+ ### Do not publish runtime/private state
8
+ Make sure these are **not** included in your release commit or package contents:
9
+ - workspace contents
10
+ - `~/.config/pi-discord-bot.env`
11
+ - Pi auth files
12
+ - Discord tokens
13
+ - logs with user conversations
14
+ - downloaded attachments
15
+
16
+ ### Current repo risk summary
17
+ The main source tree does **not** contain obvious hardcoded secrets.
18
+ The main publishing risk is runtime data in the workspace directory, which should live outside the repo and is private operational state.
19
+
20
+ ## 2. Git repo checklist
21
+
22
+ Before pushing to GitHub/GitLab:
23
+
24
+ ```bash
25
+ git status
26
+ ```
27
+
28
+ Check that these are ignored or absent:
29
+ - workspace contents
30
+ - `.env`
31
+ - local auth/config files
32
+ - generated `.tgz` package artifacts
33
+
34
+ Recommended validation:
35
+
36
+ ```bash
37
+ npm test
38
+ npx tsc --noEmit
39
+ ```
40
+
41
+ ## 3. Repo metadata checklist
42
+
43
+ Before publishing the repo publicly, confirm:
44
+ - `README.md` is current
45
+ - `docs/operator-env-config.md` is current
46
+ - `LICENSE` is correct for your intended distribution
47
+ - `package.json` metadata is updated with your real repository URLs
48
+
49
+ Fields to replace before public release:
50
+ - `repository.url`
51
+ - `homepage`
52
+ - `bugs.url`
53
+ - author/publisher metadata if you want them included
54
+
55
+ ## 4. npm publishing checklist
56
+
57
+ When publishing to npm:
58
+ 1. confirm `dist/` build output is correct
59
+ 2. confirm package metadata is correct
60
+ 3. confirm the package contents are safe
61
+ 4. run a dry pack:
62
+
63
+ ```bash
64
+ npm pack --dry-run
65
+ ```
66
+
67
+ 5. inspect the file list carefully
68
+ 6. only then publish
69
+
70
+ ## 5. Recommended package-content review
71
+
72
+ Run:
73
+
74
+ ```bash
75
+ npm pack --dry-run
76
+ ```
77
+
78
+ Verify that the package would include only things like:
79
+ - `dist/`
80
+ - `README.md`
81
+ - `LICENSE`
82
+ - maybe selected docs/examples
83
+
84
+ It should **not** include:
85
+ - workspace contents
86
+ - tests unless you want them shipped
87
+ - local config
88
+ - private logs
89
+
90
+ ## 6. Release recommendation
91
+
92
+ Recommended order:
93
+ 1. publish the Git repo
94
+ 2. publish the npm package
95
+ 3. let users install either from npm or from source, depending on their workflow
@@ -0,0 +1,128 @@
1
+ # Use `pi-discord-bot` from Pi with almost zero setup
2
+
3
+ This guide is for people who already use **Pi CLI / TUI** and want Pi itself to guide the bot setup.
4
+
5
+ The goal is:
6
+ - install the package as a Pi package
7
+ - load the skill
8
+ - let the skill walk you through the rest
9
+
10
+ ## Recommended path: install the skill from npm
11
+
12
+ Once the package is published, install it into Pi with:
13
+
14
+ ```bash
15
+ pi install npm:pi-discord-bot
16
+ ```
17
+
18
+ Then start Pi:
19
+
20
+ ```bash
21
+ pi
22
+ ```
23
+
24
+ Then run:
25
+
26
+ ```text
27
+ /skill:pi-discord-bot
28
+ ```
29
+
30
+ Or directly:
31
+
32
+ ```text
33
+ /skill:pi-discord-bot help me set up and run the Discord bot
34
+ ```
35
+
36
+ That is the preferred low-friction workflow.
37
+
38
+ ---
39
+
40
+ ## Install the skill from source instead
41
+
42
+ If you have the repo checked out locally, you can install it into Pi from the local path:
43
+
44
+ ```bash
45
+ pi install /absolute/path/to/pi-discord-bot
46
+ ```
47
+
48
+ Then:
49
+
50
+ ```bash
51
+ pi
52
+ ```
53
+
54
+ And in Pi:
55
+
56
+ ```text
57
+ /skill:pi-discord-bot
58
+ ```
59
+
60
+ This is the best option if you are developing the repo locally.
61
+
62
+ ---
63
+
64
+ ## No install path if you are already inside the repo
65
+
66
+ If you are already in the repo, Pi can discover the project skill automatically:
67
+
68
+ ```bash
69
+ cd ~/pi-discord-bot
70
+ pi
71
+ ```
72
+
73
+ Then either ask naturally:
74
+
75
+ ```text
76
+ Help me configure this bot.
77
+ ```
78
+
79
+ or force the skill explicitly:
80
+
81
+ ```text
82
+ /skill:pi-discord-bot
83
+ ```
84
+
85
+ ---
86
+
87
+ ## What to ask Pi
88
+
89
+ After the skill is loaded, ask Pi things like:
90
+ - "Set up this bot with the simplest workflow."
91
+ - "Help me configure `~/.config/pi-discord-bot.env`."
92
+ - "Help me create the workspace `discord-policy.json`."
93
+ - "Set this up with the included systemd user service."
94
+ - "The bot is not responding in Discord; debug it."
95
+
96
+ The skill is meant to drive the setup flow for you, instead of making you manually piece the repo together.
97
+
98
+ ---
99
+
100
+ ## Best practice
101
+
102
+ If you want the cleanest user flow, do this:
103
+
104
+ ### npm package flow
105
+ ```bash
106
+ pi install npm:pi-discord-bot
107
+ pi
108
+ ```
109
+
110
+ Then in Pi:
111
+
112
+ ```text
113
+ /skill:pi-discord-bot help me set up the bot
114
+ ```
115
+
116
+ ### source flow
117
+ ```bash
118
+ pi install /absolute/path/to/pi-discord-bot
119
+ pi
120
+ ```
121
+
122
+ Then in Pi:
123
+
124
+ ```text
125
+ /skill:pi-discord-bot help me set up the bot
126
+ ```
127
+
128
+ That way the user mainly interacts with **Pi + the skill**, not a long manual checklist.
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "pi-discord-bot",
3
+ "version": "0.1.1",
4
+ "description": "A small Discord harness built around Pi primitives.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "keywords": [
8
+ "pi",
9
+ "pi-package",
10
+ "discord",
11
+ "bot",
12
+ "agent",
13
+ "discord.js"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/shuyhere/pi-discord-bot.git"
18
+ },
19
+ "homepage": "https://github.com/shuyhere/pi-discord-bot#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/shuyhere/pi-discord-bot/issues"
22
+ },
23
+ "engines": {
24
+ "node": ">=22"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "skills",
29
+ "README.md",
30
+ "LICENSE",
31
+ "docs",
32
+ "discord-policy.example.json",
33
+ "pi-discord-bot.env.example",
34
+ "pi-discord-bot.service"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "bin": {
40
+ "pi-discord-bot": "dist/main.js"
41
+ },
42
+ "pi": {
43
+ "skills": [
44
+ "./skills"
45
+ ]
46
+ },
47
+ "scripts": {
48
+ "dev": "tsx watch src/main.ts",
49
+ "build": "tsc -p tsconfig.json",
50
+ "start": "node dist/main.js",
51
+ "test": "node --import tsx --test src/**/*.test.ts",
52
+ "prepublishOnly": "npm run build && npm test"
53
+ },
54
+ "dependencies": {
55
+ "@mariozechner/pi-agent-core": "^0.64.0",
56
+ "@mariozechner/pi-ai": "^0.64.0",
57
+ "@mariozechner/pi-coding-agent": "^0.64.0",
58
+ "@sinclair/typebox": "^0.34.41",
59
+ "discord.js": "^14.19.3"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^24.3.0",
63
+ "tsx": "^4.19.2",
64
+ "typescript": "^5.7.3"
65
+ }
66
+ }
@@ -0,0 +1,12 @@
1
+ # Required
2
+ DISCORD_TOKEN=replace_me
3
+
4
+ # Optional: useful for guild-scoped slash command iteration
5
+ # DISCORD_GUILD_ID=123456789012345678
6
+
7
+ # Optional: external runtime workspace directory.
8
+ # Default if unset:
9
+ # $XDG_STATE_HOME/pi-discord-bot/agent
10
+ # or:
11
+ # ~/.local/state/pi-discord-bot/agent
12
+ # PI_DISCORD_BOT_WORKDIR=/absolute/path/to/pi-discord-bot-agent
@@ -0,0 +1,16 @@
1
+ [Unit]
2
+ Description=Pi Discord Bot
3
+ After=network-online.target
4
+ Wants=network-online.target
5
+
6
+ [Service]
7
+ Type=simple
8
+ WorkingDirectory=%h/pi-discord-bot
9
+ EnvironmentFile=%h/.config/pi-discord-bot.env
10
+ ExecStart=/usr/bin/env npx tsx src/main.ts
11
+ Restart=always
12
+ RestartSec=5
13
+ TimeoutStopSec=20
14
+
15
+ [Install]
16
+ WantedBy=default.target