claude-notification-plugin 1.0.6 → 1.0.13
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 -21
- package/README.md +116 -113
- package/bin/install.js +178 -166
- package/bin/uninstall.js +53 -53
- package/notifier/notifier.js +322 -252
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Michael Makarov
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Michael Makarov
|
|
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
CHANGED
|
@@ -1,113 +1,116 @@
|
|
|
1
|
-
# claude-notification-plugin
|
|
2
|
-
|
|
3
|
-
Notifications for Claude Code task completion. Sends alerts to Telegram and Windows when Claude finishes working.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Windows desktop notifications (toast)
|
|
8
|
-
- Telegram bot messages
|
|
9
|
-
- Sound alert
|
|
10
|
-
- Voice announcement (TTS)
|
|
11
|
-
- Skips short tasks (< 15s by default)
|
|
12
|
-
- Granular per-channel enable/disable (globally and per-project)
|
|
13
|
-
|
|
14
|
-
## Install
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install -g claude-notification-plugin
|
|
18
|
-
claude-notify-install
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The installer will:
|
|
22
|
-
1. Ask for Telegram bot credentials (optional)
|
|
23
|
-
2. Create config at `~/.claude/notifier.config.json`
|
|
24
|
-
3. Register hooks in `~/.claude/settings.json`
|
|
25
|
-
|
|
26
|
-
## Configuration
|
|
27
|
-
|
|
28
|
-
Config file: `~/.claude/notifier.config.json`
|
|
29
|
-
|
|
30
|
-
```json
|
|
31
|
-
{
|
|
32
|
-
"telegram": {
|
|
33
|
-
"enabled": true,
|
|
34
|
-
"token": "YOUR_BOT_TOKEN",
|
|
35
|
-
"chatId": "YOUR_CHAT_ID"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
|
63
|
-
|
|
64
|
-
| `
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
# claude-notification-plugin
|
|
2
|
+
|
|
3
|
+
Notifications for Claude Code task completion. Sends alerts to Telegram and Windows when Claude finishes working.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Windows desktop notifications (toast)
|
|
8
|
+
- Telegram bot messages
|
|
9
|
+
- Sound alert
|
|
10
|
+
- Voice announcement (TTS)
|
|
11
|
+
- Skips short tasks (< 15s by default)
|
|
12
|
+
- Granular per-channel enable/disable (globally and per-project)
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g claude-notification-plugin
|
|
18
|
+
claude-notify-install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The installer will:
|
|
22
|
+
1. Ask for Telegram bot credentials (optional)
|
|
23
|
+
2. Create config at `~/.claude/notifier.config.json`
|
|
24
|
+
3. Register hooks in `~/.claude/settings.json`
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
Config file: `~/.claude/notifier.config.json`
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"telegram": {
|
|
33
|
+
"enabled": true,
|
|
34
|
+
"token": "YOUR_BOT_TOKEN",
|
|
35
|
+
"chatId": "YOUR_CHAT_ID",
|
|
36
|
+
"deleteAfterHours": 24
|
|
37
|
+
},
|
|
38
|
+
"windowsNotification": {
|
|
39
|
+
"enabled": true
|
|
40
|
+
},
|
|
41
|
+
"sound": {
|
|
42
|
+
"enabled": true,
|
|
43
|
+
"file": "C:/Windows/Media/notify.wav"
|
|
44
|
+
},
|
|
45
|
+
"voice": {
|
|
46
|
+
"enabled": true
|
|
47
|
+
},
|
|
48
|
+
"minSeconds": 15
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Each channel has an `enabled` flag (`true`/`false`) for global control.
|
|
53
|
+
|
|
54
|
+
`deleteAfterHours` — auto-delete old Telegram messages after the specified number of hours (default: `24`, set `0` to disable).
|
|
55
|
+
|
|
56
|
+
Environment variables `TELEGRAM_TOKEN` and `TELEGRAM_CHAT_ID` override config file values.
|
|
57
|
+
|
|
58
|
+
### Per-channel environment variables
|
|
59
|
+
|
|
60
|
+
These env vars override the global config per channel (`"1"` = on, `"0"` = off):
|
|
61
|
+
|
|
62
|
+
| Variable | Channel |
|
|
63
|
+
|--------------------------|----------------------------|
|
|
64
|
+
| `CLAUDE_NOTIFY_TELEGRAM` | Telegram messages |
|
|
65
|
+
| `CLAUDE_NOTIFY_WINDOWS` | Windows toast notifications|
|
|
66
|
+
| `CLAUDE_NOTIFY_SOUND` | Sound alert |
|
|
67
|
+
| `CLAUDE_NOTIFY_VOICE` | Voice announcement (TTS) |
|
|
68
|
+
|
|
69
|
+
### Per-project configuration
|
|
70
|
+
|
|
71
|
+
Add to `.claude/settings.local.json` in the project root to control channels per project:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"env": {
|
|
76
|
+
"DISABLE_CLAUDE_NOTIFIER": 0,
|
|
77
|
+
"CLAUDE_NOTIFY_TELEGRAM": 1,
|
|
78
|
+
"CLAUDE_NOTIFY_WINDOWS": 1,
|
|
79
|
+
"CLAUDE_NOTIFY_SOUND": 1,
|
|
80
|
+
"CLAUDE_NOTIFY_VOICE": 1
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To disable all notifications for a project:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"env": {
|
|
90
|
+
"DISABLE_CLAUDE_NOTIFIER": "1"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Telegram Setup
|
|
96
|
+
|
|
97
|
+
1. Open Telegram, find **@BotFather**
|
|
98
|
+
2. Send `/newbot`, follow prompts, pick a name
|
|
99
|
+
3. Copy the bot token (format: `123456789:ABCdef...`)
|
|
100
|
+
4. **Send any message to your new bot**
|
|
101
|
+
5. Open `https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates`
|
|
102
|
+
6. Find `"chat":{"id":123456789}` in the response — that's your Chat ID
|
|
103
|
+
7. Run `claude-notify-install` and enter the token and chat ID
|
|
104
|
+
|
|
105
|
+
Alternative for Chat ID: add **@userinfobot** to a chat and it will reply with the ID.
|
|
106
|
+
|
|
107
|
+
## Uninstall
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
claude-notify-uninstall
|
|
111
|
+
npm uninstall -g claude-notification-plugin
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
package/bin/install.js
CHANGED
|
@@ -1,166 +1,178 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import readline from 'readline';
|
|
7
|
-
|
|
8
|
-
const home = os.homedir();
|
|
9
|
-
const claudeDir = path.join(home, '.claude');
|
|
10
|
-
const configPath = path.join(claudeDir, 'notifier.config.json');
|
|
11
|
-
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
12
|
-
|
|
13
|
-
const HOOK_COMMAND = 'claude-notifier';
|
|
14
|
-
|
|
15
|
-
// ----------------------
|
|
16
|
-
// HELPERS
|
|
17
|
-
// ----------------------
|
|
18
|
-
|
|
19
|
-
function ask (rl, question) {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
rl.question(question, (answer) => resolve(answer.trim()));
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function fetchChatId (token) {
|
|
26
|
-
const url = `https://api.telegram.org/bot${token}/getUpdates`;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const res = await fetch(url);
|
|
30
|
-
const data = await res.json();
|
|
31
|
-
|
|
32
|
-
if (!data.ok || !data.result?.length) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const msg = data.result[data.result.length - 1].message;
|
|
37
|
-
if (msg?.chat?.id) {
|
|
38
|
-
return String(msg.chat.id);
|
|
39
|
-
}
|
|
40
|
-
} catch {
|
|
41
|
-
// silent fail
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function addHook (settings, event) {
|
|
48
|
-
if (!settings.hooks[event]) {
|
|
49
|
-
settings.hooks[event] = [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const exists = settings.hooks[event].some((matcher) =>
|
|
53
|
-
matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (!exists) {
|
|
57
|
-
settings.hooks[event].push({
|
|
58
|
-
hooks: [
|
|
59
|
-
{
|
|
60
|
-
type: 'command',
|
|
61
|
-
command: HOOK_COMMAND,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ----------------------
|
|
69
|
-
// MAIN
|
|
70
|
-
// ----------------------
|
|
71
|
-
|
|
72
|
-
async function main () {
|
|
73
|
-
const rl = readline.createInterface({
|
|
74
|
-
input: process.stdin,
|
|
75
|
-
output: process.stdout,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
console.log('');
|
|
79
|
-
console.log('Claude Notification Plugin - Setup');
|
|
80
|
-
console.log('==================================');
|
|
81
|
-
console.log('');
|
|
82
|
-
|
|
83
|
-
// Telegram setup
|
|
84
|
-
let token = '';
|
|
85
|
-
let chatId = '';
|
|
86
|
-
|
|
87
|
-
const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
|
|
88
|
-
|
|
89
|
-
if (useTelegram.toLowerCase() === 'y') {
|
|
90
|
-
token = await ask(rl, 'Bot Token: ');
|
|
91
|
-
|
|
92
|
-
if (token) {
|
|
93
|
-
console.log('');
|
|
94
|
-
console.log('Send any message to your bot in Telegram, then press Enter.');
|
|
95
|
-
await ask(rl, '');
|
|
96
|
-
|
|
97
|
-
console.log('Fetching Chat ID...');
|
|
98
|
-
chatId = await fetchChatId(token);
|
|
99
|
-
|
|
100
|
-
if (chatId) {
|
|
101
|
-
console.log('Chat ID detected: ' + chatId);
|
|
102
|
-
} else {
|
|
103
|
-
console.log('Could not detect Chat ID automatically.');
|
|
104
|
-
chatId = await ask(rl, 'Enter Chat ID manually: ');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
rl.close();
|
|
110
|
-
|
|
111
|
-
// Create config
|
|
112
|
-
fs.mkdirSync(claudeDir, { recursive: true });
|
|
113
|
-
|
|
114
|
-
const config = {
|
|
115
|
-
telegram: {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
console.log('');
|
|
161
|
-
console.log('
|
|
162
|
-
console.log('
|
|
163
|
-
console.log('');
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import readline from 'readline';
|
|
7
|
+
|
|
8
|
+
const home = os.homedir();
|
|
9
|
+
const claudeDir = path.join(home, '.claude');
|
|
10
|
+
const configPath = path.join(claudeDir, 'notifier.config.json');
|
|
11
|
+
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
12
|
+
|
|
13
|
+
const HOOK_COMMAND = 'claude-notifier';
|
|
14
|
+
|
|
15
|
+
// ----------------------
|
|
16
|
+
// HELPERS
|
|
17
|
+
// ----------------------
|
|
18
|
+
|
|
19
|
+
function ask (rl, question) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
rl.question(question, (answer) => resolve(answer.trim()));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function fetchChatId (token) {
|
|
26
|
+
const url = `https://api.telegram.org/bot${token}/getUpdates`;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const res = await fetch(url);
|
|
30
|
+
const data = await res.json();
|
|
31
|
+
|
|
32
|
+
if (!data.ok || !data.result?.length) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const msg = data.result[data.result.length - 1].message;
|
|
37
|
+
if (msg?.chat?.id) {
|
|
38
|
+
return String(msg.chat.id);
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// silent fail
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addHook (settings, event) {
|
|
48
|
+
if (!settings.hooks[event]) {
|
|
49
|
+
settings.hooks[event] = [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const exists = settings.hooks[event].some((matcher) =>
|
|
53
|
+
matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (!exists) {
|
|
57
|
+
settings.hooks[event].push({
|
|
58
|
+
hooks: [
|
|
59
|
+
{
|
|
60
|
+
type: 'command',
|
|
61
|
+
command: HOOK_COMMAND,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ----------------------
|
|
69
|
+
// MAIN
|
|
70
|
+
// ----------------------
|
|
71
|
+
|
|
72
|
+
async function main () {
|
|
73
|
+
const rl = readline.createInterface({
|
|
74
|
+
input: process.stdin,
|
|
75
|
+
output: process.stdout,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log('Claude Notification Plugin - Setup');
|
|
80
|
+
console.log('==================================');
|
|
81
|
+
console.log('');
|
|
82
|
+
|
|
83
|
+
// Telegram setup
|
|
84
|
+
let token = '';
|
|
85
|
+
let chatId = '';
|
|
86
|
+
|
|
87
|
+
const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
|
|
88
|
+
|
|
89
|
+
if (useTelegram.toLowerCase() === 'y') {
|
|
90
|
+
token = await ask(rl, 'Bot Token: ');
|
|
91
|
+
|
|
92
|
+
if (token) {
|
|
93
|
+
console.log('');
|
|
94
|
+
console.log('Send any message to your bot in Telegram, then press Enter.');
|
|
95
|
+
await ask(rl, '');
|
|
96
|
+
|
|
97
|
+
console.log('Fetching Chat ID...');
|
|
98
|
+
chatId = await fetchChatId(token);
|
|
99
|
+
|
|
100
|
+
if (chatId) {
|
|
101
|
+
console.log('Chat ID detected: ' + chatId);
|
|
102
|
+
} else {
|
|
103
|
+
console.log('Could not detect Chat ID automatically.');
|
|
104
|
+
chatId = await ask(rl, 'Enter Chat ID manually: ');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
rl.close();
|
|
110
|
+
|
|
111
|
+
// Create config
|
|
112
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
113
|
+
|
|
114
|
+
const config = {
|
|
115
|
+
telegram: {
|
|
116
|
+
enabled: true,
|
|
117
|
+
token,
|
|
118
|
+
chatId,
|
|
119
|
+
deleteAfterHours: 24,
|
|
120
|
+
},
|
|
121
|
+
windowsNotification: {
|
|
122
|
+
enabled: true,
|
|
123
|
+
},
|
|
124
|
+
sound: {
|
|
125
|
+
enabled: true,
|
|
126
|
+
file: 'C:/Windows/Media/notify.wav',
|
|
127
|
+
},
|
|
128
|
+
voice: {
|
|
129
|
+
enabled: true,
|
|
130
|
+
},
|
|
131
|
+
minSeconds: 15,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
135
|
+
|
|
136
|
+
// Patch settings.json
|
|
137
|
+
let settings = {};
|
|
138
|
+
|
|
139
|
+
if (fs.existsSync(settingsPath)) {
|
|
140
|
+
try {
|
|
141
|
+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
142
|
+
} catch {
|
|
143
|
+
settings = {};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
settings.hooks = settings.hooks || {};
|
|
148
|
+
|
|
149
|
+
addHook(settings, 'UserPromptSubmit');
|
|
150
|
+
addHook(settings, 'Stop');
|
|
151
|
+
addHook(settings, 'Notification');
|
|
152
|
+
|
|
153
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
154
|
+
|
|
155
|
+
// Output
|
|
156
|
+
console.log('');
|
|
157
|
+
console.log('Installed!');
|
|
158
|
+
console.log('');
|
|
159
|
+
console.log('Hooks registered:');
|
|
160
|
+
console.log(' - UserPromptSubmit (start timer)');
|
|
161
|
+
console.log(' - Stop (task finished)');
|
|
162
|
+
console.log(' - Notification (waiting for input)');
|
|
163
|
+
console.log('');
|
|
164
|
+
console.log('Config: ' + configPath);
|
|
165
|
+
|
|
166
|
+
if (token) {
|
|
167
|
+
console.log('Telegram: configured');
|
|
168
|
+
} else {
|
|
169
|
+
console.log('Telegram: skipped (edit config later)');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
console.log('');
|
|
173
|
+
console.log('To disable per project, add to .claude/settings.local.json:');
|
|
174
|
+
console.log(' { "env": { "DISABLE_CLAUDE_NOTIFIER": "1" } }');
|
|
175
|
+
console.log('');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
main().then(() => 0);
|
package/bin/uninstall.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const home = os.homedir();
|
|
8
|
-
const claudeDir = path.join(home, '.claude');
|
|
9
|
-
const configPath = path.join(claudeDir, 'notifier.config.json');
|
|
10
|
-
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
11
|
-
const statePath = path.join(claudeDir, '.notifier_state.json');
|
|
12
|
-
|
|
13
|
-
const HOOK_COMMAND = 'claude-notifier';
|
|
14
|
-
|
|
15
|
-
// Remove hooks from settings.json
|
|
16
|
-
if (fs.existsSync(settingsPath)) {
|
|
17
|
-
try {
|
|
18
|
-
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
19
|
-
|
|
20
|
-
if (settings.hooks) {
|
|
21
|
-
for (const event of Object.keys(settings.hooks)) {
|
|
22
|
-
settings.hooks[event] = settings.hooks[event].filter((matcher) =>
|
|
23
|
-
!matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
if (settings.hooks[event].length === 0) {
|
|
27
|
-
delete settings.hooks[event];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (Object.keys(settings.hooks).length === 0) {
|
|
32
|
-
delete settings.hooks;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
37
|
-
} catch {
|
|
38
|
-
// ignore
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Remove config and state files
|
|
43
|
-
for (const file of [configPath, statePath]) {
|
|
44
|
-
if (fs.existsSync(file)) {
|
|
45
|
-
fs.unlinkSync(file);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
console.log('');
|
|
50
|
-
console.log('Claude Notification Plugin uninstalled.');
|
|
51
|
-
console.log('Hooks removed from settings.json');
|
|
52
|
-
console.log('Config files deleted.');
|
|
53
|
-
console.log('');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
const home = os.homedir();
|
|
8
|
+
const claudeDir = path.join(home, '.claude');
|
|
9
|
+
const configPath = path.join(claudeDir, 'notifier.config.json');
|
|
10
|
+
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
11
|
+
const statePath = path.join(claudeDir, '.notifier_state.json');
|
|
12
|
+
|
|
13
|
+
const HOOK_COMMAND = 'claude-notifier';
|
|
14
|
+
|
|
15
|
+
// Remove hooks from settings.json
|
|
16
|
+
if (fs.existsSync(settingsPath)) {
|
|
17
|
+
try {
|
|
18
|
+
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
19
|
+
|
|
20
|
+
if (settings.hooks) {
|
|
21
|
+
for (const event of Object.keys(settings.hooks)) {
|
|
22
|
+
settings.hooks[event] = settings.hooks[event].filter((matcher) =>
|
|
23
|
+
!matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (settings.hooks[event].length === 0) {
|
|
27
|
+
delete settings.hooks[event];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (Object.keys(settings.hooks).length === 0) {
|
|
32
|
+
delete settings.hooks;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
37
|
+
} catch {
|
|
38
|
+
// ignore
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Remove config and state files
|
|
43
|
+
for (const file of [configPath, statePath]) {
|
|
44
|
+
if (fs.existsSync(file)) {
|
|
45
|
+
fs.unlinkSync(file);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log('');
|
|
50
|
+
console.log('Claude Notification Plugin uninstalled.');
|
|
51
|
+
console.log('Hooks removed from settings.json');
|
|
52
|
+
console.log('Config files deleted.');
|
|
53
|
+
console.log('');
|
package/notifier/notifier.js
CHANGED
|
@@ -1,252 +1,322 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import process from 'process';
|
|
7
|
-
import notifier from 'node-notifier';
|
|
8
|
-
import player from 'play-sound';
|
|
9
|
-
import say from 'say';
|
|
10
|
-
|
|
11
|
-
const audio = player({});
|
|
12
|
-
|
|
13
|
-
// ----------------------
|
|
14
|
-
// CONFIG
|
|
15
|
-
// ----------------------
|
|
16
|
-
|
|
17
|
-
function loadConfig () {
|
|
18
|
-
const configPath = path.join(os.homedir(), '.claude', 'notifier.config.json');
|
|
19
|
-
|
|
20
|
-
const config = {
|
|
21
|
-
telegram: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
config.
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
fs.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import process from 'process';
|
|
7
|
+
import notifier from 'node-notifier';
|
|
8
|
+
import player from 'play-sound';
|
|
9
|
+
import say from 'say';
|
|
10
|
+
|
|
11
|
+
const audio = player({});
|
|
12
|
+
|
|
13
|
+
// ----------------------
|
|
14
|
+
// CONFIG
|
|
15
|
+
// ----------------------
|
|
16
|
+
|
|
17
|
+
function loadConfig () {
|
|
18
|
+
const configPath = path.join(os.homedir(), '.claude', 'notifier.config.json');
|
|
19
|
+
|
|
20
|
+
const config = {
|
|
21
|
+
telegram: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
token: '',
|
|
24
|
+
chatId: '',
|
|
25
|
+
deleteAfterHours: 24,
|
|
26
|
+
},
|
|
27
|
+
windowsNotification: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
},
|
|
30
|
+
sound: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
file: 'C:/Windows/Media/notify.wav',
|
|
33
|
+
},
|
|
34
|
+
voice: {
|
|
35
|
+
enabled: true,
|
|
36
|
+
},
|
|
37
|
+
minSeconds: 15,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (fs.existsSync(configPath)) {
|
|
41
|
+
try {
|
|
42
|
+
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
43
|
+
const user = JSON.parse(raw);
|
|
44
|
+
if (user.telegram) {
|
|
45
|
+
config.telegram = { ...config.telegram, ...user.telegram };
|
|
46
|
+
}
|
|
47
|
+
if (user.windowsNotification) {
|
|
48
|
+
config.windowsNotification = { ...config.windowsNotification, ...user.windowsNotification };
|
|
49
|
+
}
|
|
50
|
+
if (user.sound) {
|
|
51
|
+
config.sound = { ...config.sound, ...user.sound };
|
|
52
|
+
}
|
|
53
|
+
if (user.voice) {
|
|
54
|
+
config.voice = { ...config.voice, ...user.voice };
|
|
55
|
+
}
|
|
56
|
+
if (typeof user.minSeconds === 'number') {
|
|
57
|
+
config.minSeconds = user.minSeconds;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// ignore malformed config
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (process.env.TELEGRAM_TOKEN) {
|
|
65
|
+
config.telegram.token = process.env.TELEGRAM_TOKEN;
|
|
66
|
+
}
|
|
67
|
+
if (process.env.TELEGRAM_CHAT_ID) {
|
|
68
|
+
config.telegram.chatId = process.env.TELEGRAM_CHAT_ID;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Per-channel env overrides (0 = off, 1 = on)
|
|
72
|
+
if (process.env.CLAUDE_NOTIFY_TELEGRAM !== undefined) {
|
|
73
|
+
config.telegram.enabled = process.env.CLAUDE_NOTIFY_TELEGRAM === '1';
|
|
74
|
+
}
|
|
75
|
+
if (process.env.CLAUDE_NOTIFY_WINDOWS !== undefined) {
|
|
76
|
+
config.windowsNotification.enabled = process.env.CLAUDE_NOTIFY_WINDOWS === '1';
|
|
77
|
+
}
|
|
78
|
+
if (process.env.CLAUDE_NOTIFY_SOUND !== undefined) {
|
|
79
|
+
config.sound.enabled = process.env.CLAUDE_NOTIFY_SOUND === '1';
|
|
80
|
+
}
|
|
81
|
+
if (process.env.CLAUDE_NOTIFY_VOICE !== undefined) {
|
|
82
|
+
config.voice.enabled = process.env.CLAUDE_NOTIFY_VOICE === '1';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return config;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ----------------------
|
|
89
|
+
// PROJECT-LEVEL DISABLE
|
|
90
|
+
// ----------------------
|
|
91
|
+
|
|
92
|
+
function isNotifierDisabled () {
|
|
93
|
+
return process.env.DISABLE_CLAUDE_NOTIFIER === '1'
|
|
94
|
+
|| process.env.DISABLE_CLAUDE_NOTIFIER === 'true';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ----------------------
|
|
98
|
+
// STATE FILE
|
|
99
|
+
// ----------------------
|
|
100
|
+
|
|
101
|
+
const STATE_FILE = path.join(
|
|
102
|
+
os.homedir(),
|
|
103
|
+
'.claude',
|
|
104
|
+
'.notifier_state.json',
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
function loadState () {
|
|
108
|
+
if (fs.existsSync(STATE_FILE)) {
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
|
|
111
|
+
} catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function saveState (state) {
|
|
119
|
+
const dir = path.dirname(STATE_FILE);
|
|
120
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
121
|
+
fs.writeFileSync(STATE_FILE, JSON.stringify(state));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ----------------------
|
|
125
|
+
// TELEGRAM
|
|
126
|
+
// ----------------------
|
|
127
|
+
|
|
128
|
+
async function sendTelegram (config, state) {
|
|
129
|
+
if (!config.telegram.enabled || !config.telegram.token || !config.telegram.chatId) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const baseUrl = `https://api.telegram.org/bot${config.telegram.token}`;
|
|
134
|
+
|
|
135
|
+
// Send new message and store its id
|
|
136
|
+
try {
|
|
137
|
+
const res = await fetch(`${baseUrl}/sendMessage`, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
headers: { 'Content-Type': 'application/json' },
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
chat_id: config.telegram.chatId,
|
|
142
|
+
text: state._telegramText,
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
const data = await res.json();
|
|
146
|
+
if (data.ok && data.result?.message_id) {
|
|
147
|
+
if (!state.sentMessages) {
|
|
148
|
+
state.sentMessages = [];
|
|
149
|
+
}
|
|
150
|
+
state.sentMessages.push({
|
|
151
|
+
id: data.result.message_id,
|
|
152
|
+
ts: Date.now(),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
// silent fail
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Delete old messages
|
|
160
|
+
const maxAge = (config.telegram.deleteAfterHours || 24) * 3600_000;
|
|
161
|
+
if (state.sentMessages?.length) {
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
const keep = [];
|
|
164
|
+
for (const msg of state.sentMessages) {
|
|
165
|
+
if (now - msg.ts > maxAge) {
|
|
166
|
+
try {
|
|
167
|
+
await fetch(`${baseUrl}/deleteMessage`, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: { 'Content-Type': 'application/json' },
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
chat_id: config.telegram.chatId,
|
|
172
|
+
message_id: msg.id,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
} catch {
|
|
176
|
+
// silent fail
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
keep.push(msg);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
state.sentMessages = keep;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ----------------------
|
|
187
|
+
// WINDOWS NOTIFICATION
|
|
188
|
+
// ----------------------
|
|
189
|
+
|
|
190
|
+
function sendWindowsNotification (config, message) {
|
|
191
|
+
if (!config.windowsNotification.enabled) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
notifier.notify({
|
|
195
|
+
title: 'Claude Code',
|
|
196
|
+
message,
|
|
197
|
+
sound: true,
|
|
198
|
+
wait: false,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ----------------------
|
|
203
|
+
// SOUND & VOICE
|
|
204
|
+
// ----------------------
|
|
205
|
+
|
|
206
|
+
function playSound (config) {
|
|
207
|
+
if (!config.sound.enabled) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
audio.play(config.sound.file);
|
|
212
|
+
} catch {
|
|
213
|
+
// silent fail
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const voicePhrases = {
|
|
218
|
+
en: (d) => `Claude finished coding in ${d} seconds`,
|
|
219
|
+
ru: (d) => `Клод завершил работу за ${d} секунд`,
|
|
220
|
+
de: (d) => `Claude hat die Arbeit in ${d} Sekunden abgeschlossen`,
|
|
221
|
+
fr: (d) => `Claude a termine en ${d} secondes`,
|
|
222
|
+
es: (d) => `Claude termino en ${d} segundos`,
|
|
223
|
+
pt: (d) => `Claude terminou em ${d} segundos`,
|
|
224
|
+
ja: (d) => `Claudeは${d}秒でコーディングを完了しました`,
|
|
225
|
+
ko: (d) => `Claude가 ${d}초 만에 코딩을 완료했습니다`,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
function getVoicePhrase (duration) {
|
|
229
|
+
const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en';
|
|
230
|
+
const lang = locale.split('-')[0].toLowerCase();
|
|
231
|
+
const fn = voicePhrases[lang] || voicePhrases.en;
|
|
232
|
+
return fn(duration);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function speakResult (config, duration) {
|
|
236
|
+
if (!config.voice.enabled) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
say.speak(getVoicePhrase(duration));
|
|
241
|
+
} catch {
|
|
242
|
+
// silent fail
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ----------------------
|
|
247
|
+
// READ HOOK INPUT
|
|
248
|
+
// ----------------------
|
|
249
|
+
|
|
250
|
+
let input = '';
|
|
251
|
+
|
|
252
|
+
process.stdin.on('data', (chunk) => {
|
|
253
|
+
input += chunk;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
process.stdin.on('end', async () => {
|
|
257
|
+
const config = loadConfig();
|
|
258
|
+
|
|
259
|
+
let event = {};
|
|
260
|
+
try {
|
|
261
|
+
event = JSON.parse(input);
|
|
262
|
+
} catch {
|
|
263
|
+
// ignore
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const eventType = event.hook_event_name || 'unknown';
|
|
267
|
+
const cwd = event.cwd || process.cwd();
|
|
268
|
+
const project = path.basename(cwd);
|
|
269
|
+
|
|
270
|
+
if (isNotifierDisabled()) {
|
|
271
|
+
process.exit(0);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const state = loadState();
|
|
275
|
+
|
|
276
|
+
// ----------------------
|
|
277
|
+
// START TIMER
|
|
278
|
+
// ----------------------
|
|
279
|
+
|
|
280
|
+
if (eventType === 'UserPromptSubmit') {
|
|
281
|
+
state.start = Date.now();
|
|
282
|
+
saveState(state);
|
|
283
|
+
process.exit(0);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ----------------------
|
|
287
|
+
// STOP / NOTIFICATION EVENT
|
|
288
|
+
// ----------------------
|
|
289
|
+
|
|
290
|
+
if (eventType !== 'Stop' && eventType !== 'Notification') {
|
|
291
|
+
process.exit(0);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
let duration = 0;
|
|
295
|
+
if (state.start) {
|
|
296
|
+
duration = Math.round((Date.now() - state.start) / 1000);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (duration < config.minSeconds) {
|
|
300
|
+
process.exit(0);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let status = 'success';
|
|
304
|
+
if (event.error) {
|
|
305
|
+
status = 'error';
|
|
306
|
+
}
|
|
307
|
+
if (eventType === 'Notification') {
|
|
308
|
+
status = 'waiting';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const message =
|
|
312
|
+
`Claude finished coding\n\nProject: ${project}\nDuration: ${duration}s\nStatus: ${status}`;
|
|
313
|
+
|
|
314
|
+
state._telegramText = `\u{1F916} ${message}`;
|
|
315
|
+
await sendTelegram(config, state);
|
|
316
|
+
delete state._telegramText;
|
|
317
|
+
saveState(state);
|
|
318
|
+
|
|
319
|
+
sendWindowsNotification(config, message);
|
|
320
|
+
playSound(config);
|
|
321
|
+
speakResult(config, duration);
|
|
322
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-notification-plugin",
|
|
3
3
|
"productName": "claude-notification-plugin",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13",
|
|
5
5
|
"description": "Telegram and Windows notifications for Claude Code task completion",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/Bazilio-san/claude-notification-plugin#readme",
|
|
42
42
|
"publishConfig": {
|
|
43
|
-
"
|
|
43
|
+
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"node-notifier": "^10.0.1",
|