@xtccc/opencode-notifier 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/LICENSE +21 -0
- package/README.md +341 -0
- package/dist/index.js +4325 -0
- package/logos/opencode-logo-dark.png +0 -0
- package/logos/opencode-logo-light.png +0 -0
- package/package.json +47 -0
- package/sounds/complete.wav +0 -0
- package/sounds/error.wav +0 -0
- package/sounds/permission.wav +0 -0
- package/sounds/question.wav +0 -0
- package/sounds/subagent_complete.wav +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mohak S
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# opencode-notifier
|
|
2
|
+
|
|
3
|
+
OpenCode plugin that plays sounds and sends system notifications when permission is needed, generation completes, errors occur, or the question tool is invoked. Features intelligent focus detection to avoid spamming you when you're actively using OpenCode. Works on macOS, Linux, and Windows.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Add this to your `opencode.json`:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"plugin": ["@xtccc/opencode-notifier@latest"]
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Restart OpenCode. Done.
|
|
16
|
+
|
|
17
|
+
## What it does
|
|
18
|
+
|
|
19
|
+
You'll get notified when:
|
|
20
|
+
- OpenCode needs permission to run something
|
|
21
|
+
- Your session finishes
|
|
22
|
+
- A subagent task completes
|
|
23
|
+
- An error happens
|
|
24
|
+
- The question tool pops up
|
|
25
|
+
|
|
26
|
+
**Smart Focus Detection**: When `suppressWhenFocused` is enabled (default), notifications are delayed. If you interact with OpenCode within the focus window, the notification is suppressed (you're already there!). If you don't respond, the notification is sent after the delay.
|
|
27
|
+
|
|
28
|
+
## Setup by platform
|
|
29
|
+
|
|
30
|
+
**macOS**: Nothing to do, works out of the box. Shows the Script Editor icon.
|
|
31
|
+
|
|
32
|
+
**Linux**: Should work if you already have a notification system setup. If not install libnotify:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
sudo apt install libnotify-bin # Ubuntu/Debian
|
|
36
|
+
sudo dnf install libnotify # Fedora
|
|
37
|
+
sudo pacman -S libnotify # Arch
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For sounds, you need one of: `paplay`, `aplay`, `mpv`, or `ffplay`
|
|
41
|
+
|
|
42
|
+
**Windows**: Works out of the box. But heads up:
|
|
43
|
+
- Only `.wav` files work (not mp3)
|
|
44
|
+
- Use full paths like `C:/Users/You/sounds/alert.wav` not `~/`
|
|
45
|
+
|
|
46
|
+
## Config file
|
|
47
|
+
|
|
48
|
+
Create `~/.config/opencode/opencode-notifier.json` with the defaults:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"sound": true,
|
|
53
|
+
"notification": true,
|
|
54
|
+
"timeout": 5,
|
|
55
|
+
"showProjectName": true,
|
|
56
|
+
"showIcon": true,
|
|
57
|
+
"notificationSystem": "osascript",
|
|
58
|
+
"suppressWhenFocused": true,
|
|
59
|
+
"focusWindowSeconds": 60,
|
|
60
|
+
"debug": false,
|
|
61
|
+
"command": {
|
|
62
|
+
"enabled": false,
|
|
63
|
+
"path": "/path/to/command",
|
|
64
|
+
"args": ["--event", "{event}", "--message", "{message}"],
|
|
65
|
+
"minDuration": 0
|
|
66
|
+
},
|
|
67
|
+
"events": {
|
|
68
|
+
"permission": { "sound": true, "notification": true },
|
|
69
|
+
"complete": { "sound": true, "notification": true },
|
|
70
|
+
"subagent_complete": { "sound": false, "notification": false },
|
|
71
|
+
"error": { "sound": true, "notification": true },
|
|
72
|
+
"question": { "sound": true, "notification": true }
|
|
73
|
+
},
|
|
74
|
+
"messages": {
|
|
75
|
+
"permission": "Session needs permission",
|
|
76
|
+
"complete": "Session has finished",
|
|
77
|
+
"subagent_complete": "Subagent task completed",
|
|
78
|
+
"error": "Session encountered an error",
|
|
79
|
+
"question": "Session has a question"
|
|
80
|
+
},
|
|
81
|
+
"sounds": {
|
|
82
|
+
"permission": null,
|
|
83
|
+
"complete": null,
|
|
84
|
+
"subagent_complete": null,
|
|
85
|
+
"error": null,
|
|
86
|
+
"question": null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## All options
|
|
92
|
+
|
|
93
|
+
### Global options
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"sound": true,
|
|
98
|
+
"notification": true,
|
|
99
|
+
"timeout": 5,
|
|
100
|
+
"showProjectName": true,
|
|
101
|
+
"showIcon": true,
|
|
102
|
+
"notificationSystem": "osascript"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- `sound` - Turn sounds on/off (default: true)
|
|
107
|
+
- `notification` - Turn notifications on/off (default: true)
|
|
108
|
+
- `timeout` - How long notifications show in seconds, Linux only (default: 5)
|
|
109
|
+
- `showProjectName` - Show folder name in notification title (default: true)
|
|
110
|
+
- `showIcon` - Show OpenCode icon, Windows/Linux only (default: true)
|
|
111
|
+
- `notificationSystem` - macOS only: `"osascript"` or `"node-notifier"` (default: "osascript")
|
|
112
|
+
- `suppressWhenFocused` - Delay notifications; cancel if you interact with OpenCode within the window (default: true)
|
|
113
|
+
- `focusWindowSeconds` - How long to wait before sending notification when suppressWhenFocused is enabled (default: 60)
|
|
114
|
+
- `debug` - Enable debug logging to see plugin activity (default: false)
|
|
115
|
+
|
|
116
|
+
### Suppress When Focused
|
|
117
|
+
|
|
118
|
+
When enabled (default), the plugin intelligently avoids spamming you:
|
|
119
|
+
|
|
120
|
+
1. When an event occurs (e.g., session completes), a timer starts
|
|
121
|
+
2. If you respond to OpenCode within `focusWindowSeconds`, the notification is canceled
|
|
122
|
+
3. If you don't respond, the notification is sent after the delay
|
|
123
|
+
|
|
124
|
+
This prevents notifications when you're already actively using OpenCode, but ensures you get notified when you step away.
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"suppressWhenFocused": true,
|
|
129
|
+
"focusWindowSeconds": 60
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Set to `false` to always receive notifications immediately.
|
|
134
|
+
|
|
135
|
+
### Events
|
|
136
|
+
|
|
137
|
+
Control each event separately:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"events": {
|
|
142
|
+
"permission": { "sound": true, "notification": true },
|
|
143
|
+
"complete": { "sound": true, "notification": true },
|
|
144
|
+
"subagent_complete": { "sound": false, "notification": false },
|
|
145
|
+
"error": { "sound": true, "notification": true },
|
|
146
|
+
"question": { "sound": true, "notification": true }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Or use true/false for both:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"events": {
|
|
156
|
+
"complete": false
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Messages
|
|
162
|
+
|
|
163
|
+
Customize the notification text:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"messages": {
|
|
168
|
+
"permission": "Session needs permission",
|
|
169
|
+
"complete": "Session has finished",
|
|
170
|
+
"subagent_complete": "Subagent task completed",
|
|
171
|
+
"error": "Session encountered an error",
|
|
172
|
+
"question": "Session has a question"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Sounds
|
|
178
|
+
|
|
179
|
+
Use your own sound files:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"sounds": {
|
|
184
|
+
"permission": "/path/to/alert.wav",
|
|
185
|
+
"complete": "/path/to/done.wav",
|
|
186
|
+
"subagent_complete": "/path/to/subagent-done.wav",
|
|
187
|
+
"error": "/path/to/error.wav",
|
|
188
|
+
"question": "/path/to/question.wav"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Platform notes:
|
|
194
|
+
- macOS/Linux: .wav or .mp3 files work
|
|
195
|
+
- Windows: Only .wav files work
|
|
196
|
+
- If file doesn't exist, falls back to bundled sound
|
|
197
|
+
|
|
198
|
+
### Custom commands
|
|
199
|
+
|
|
200
|
+
Run your own script when something happens. Use `{event}` and `{message}` as placeholders:
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"command": {
|
|
205
|
+
"enabled": true,
|
|
206
|
+
"path": "/path/to/your/script",
|
|
207
|
+
"args": ["{event}", "{message}"],
|
|
208
|
+
"minDuration": 10
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- `enabled` - Turn command on/off
|
|
214
|
+
- `path` - Path to your script/executable
|
|
215
|
+
- `args` - Arguments to pass, can use `{event}` and `{message}` tokens
|
|
216
|
+
- `minDuration` - Skip if response was quick, avoids spam (seconds)
|
|
217
|
+
|
|
218
|
+
#### Example: Log events to a file
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"command": {
|
|
223
|
+
"enabled": true,
|
|
224
|
+
"path": "/bin/bash",
|
|
225
|
+
"args": [
|
|
226
|
+
"-c",
|
|
227
|
+
"echo '[{event}] {message}' >> /tmp/opencode.log"
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## macOS: Pick your notification style
|
|
234
|
+
|
|
235
|
+
**osascript** (default): Reliable but shows Script Editor icon
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"notificationSystem": "osascript"
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**node-notifier**: Shows OpenCode icon but might miss notifications sometimes
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"notificationSystem": "node-notifier"
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**NOTE:** If you go with node-notifier and start missing notifications, just switch back or remove the option from the config. Users have reported issues with using node-notifier for receiving only sounds and no notification popups.
|
|
252
|
+
|
|
253
|
+
## Updating
|
|
254
|
+
|
|
255
|
+
If Opencode does not update the plugin or there is an issue with the cache version:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# Linux/macOS
|
|
259
|
+
rm -rf ~/.cache/opencode/node_modules/@xtccc/opencode-notifier
|
|
260
|
+
|
|
261
|
+
# Windows
|
|
262
|
+
Remove-Item -Recurse -Force "$env:USERPROFILE\.cache\opencode\node_modules\@xtccc\opencode-notifier"
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Then restart OpenCode.
|
|
266
|
+
|
|
267
|
+
## Troubleshooting
|
|
268
|
+
|
|
269
|
+
**macOS: Not seeing notifications?**
|
|
270
|
+
Go to System Settings > Notifications > Script Editor, make sure it's set to Banners or Alerts.
|
|
271
|
+
|
|
272
|
+
**macOS: node-notifier not showing notifications?**
|
|
273
|
+
Switch back to osascript. Some users report node-notifier works for sounds but not visual notifications on certain macOS versions.
|
|
274
|
+
|
|
275
|
+
**Linux: No notifications?**
|
|
276
|
+
Install libnotify-bin:
|
|
277
|
+
```bash
|
|
278
|
+
sudo apt install libnotify-bin # Debian/Ubuntu
|
|
279
|
+
sudo dnf install libnotify # Fedora
|
|
280
|
+
sudo pacman -S libnotify # Arch
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Test with: `notify-send "Test" "Hello"`
|
|
284
|
+
|
|
285
|
+
**Linux: No sounds?**
|
|
286
|
+
Install one of: `paplay`, `aplay`, `mpv`, or `ffplay`
|
|
287
|
+
|
|
288
|
+
**Windows: Custom sounds not working?**
|
|
289
|
+
- Must be .wav format (not .mp3)
|
|
290
|
+
- Use full Windows paths: `C:/Users/YourName/sounds/alert.wav` (not `~/`)
|
|
291
|
+
- Make sure the file actually plays in Windows Media Player
|
|
292
|
+
- If using WSL, the path should be accessible from Windows
|
|
293
|
+
|
|
294
|
+
**Windows WSL notifications not working?**
|
|
295
|
+
WSL doesn't have a native notification daemon. Use PowerShell commands instead:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"notification": false,
|
|
300
|
+
"sound": true,
|
|
301
|
+
"command": {
|
|
302
|
+
"enabled": true,
|
|
303
|
+
"path": "powershell.exe",
|
|
304
|
+
"args": [
|
|
305
|
+
"-Command",
|
|
306
|
+
"$wshell = New-Object -ComObject Wscript.Shell; $wshell.Popup('{message}', 5, 'OpenCode - {event}', 0+64)"
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Windows: OpenCode crashes when notifications appear?**
|
|
313
|
+
This is a known Bun issue on Windows. Disable native notifications and use PowerShell popups:
|
|
314
|
+
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"notification": false,
|
|
318
|
+
"sound": true,
|
|
319
|
+
"command": {
|
|
320
|
+
"enabled": true,
|
|
321
|
+
"path": "powershell.exe",
|
|
322
|
+
"args": [
|
|
323
|
+
"-Command",
|
|
324
|
+
"$wshell = New-Object -ComObject Wscript.Shell; $wshell.Popup('{message}', 5, 'OpenCode - {event}', 0+64)"
|
|
325
|
+
]
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**Plugin not loading?**
|
|
331
|
+
- Check your opencode.json syntax
|
|
332
|
+
- Clear the cache (see Updating section)
|
|
333
|
+
- Restart OpenCode
|
|
334
|
+
|
|
335
|
+
## Changelog
|
|
336
|
+
|
|
337
|
+
See [CHANGELOG.md](CHANGELOG.md)
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
MIT
|