tonton-cli 1.0.0 → 1.1.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/README.md +3 -3
- package/bin/tonton.js +21 -0
- package/lib/config.js +33 -0
- package/lib/index.js +3 -0
- package/lib/setup.js +26 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,11 +54,11 @@ Add to `~/.claude/settings.json`:
|
|
|
54
54
|
```json
|
|
55
55
|
{
|
|
56
56
|
"hooks": {
|
|
57
|
-
"
|
|
58
|
-
{ "type": "command", "command": "npx tonton-cli --done" }
|
|
57
|
+
"Stop": [
|
|
58
|
+
{ "matcher": "", "hooks": [{ "type": "command", "command": "npx tonton-cli --done" }] }
|
|
59
59
|
],
|
|
60
60
|
"Notification": [
|
|
61
|
-
{ "type": "command", "command": "npx tonton-cli --input" }
|
|
61
|
+
{ "matcher": "", "hooks": [{ "type": "command", "command": "npx tonton-cli --input" }] }
|
|
62
62
|
]
|
|
63
63
|
}
|
|
64
64
|
}
|
package/bin/tonton.js
CHANGED
|
@@ -27,6 +27,9 @@ Presets:
|
|
|
27
27
|
Options:
|
|
28
28
|
-s, --sound <name> Sound to play (default: "Ping" on macOS, "chime" elsewhere)
|
|
29
29
|
-v, --volume <0-1> Volume level, 0.0 to 1.0 (macOS only, default: 1.0)
|
|
30
|
+
-m, --mute Mute all sounds (persists across runs)
|
|
31
|
+
-u, --unmute Unmute sounds
|
|
32
|
+
--status Show current mute status
|
|
30
33
|
-l, --list List available sounds
|
|
31
34
|
-h, --help Show this help
|
|
32
35
|
--version Show version
|
|
@@ -62,6 +65,24 @@ After any command:
|
|
|
62
65
|
process.exit(0);
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
if (arg === '-m' || arg === '--mute') {
|
|
69
|
+
require('../lib/config').setMuted(true);
|
|
70
|
+
console.log('Muted. Run tonton --unmute to re-enable sounds.');
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (arg === '-u' || arg === '--unmute') {
|
|
75
|
+
require('../lib/config').setMuted(false);
|
|
76
|
+
console.log('Unmuted. Sounds are back on.');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (arg === '--status') {
|
|
81
|
+
const muted = require('../lib/config').isMuted();
|
|
82
|
+
console.log(muted ? 'Muted' : 'Unmuted');
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
|
|
65
86
|
if (arg === '-l' || arg === '--list') {
|
|
66
87
|
const sounds = listSounds();
|
|
67
88
|
console.log('Available sounds:');
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const CONFIG_DIR = path.join(os.homedir(), '.config', 'tonton');
|
|
8
|
+
const CONFIG_PATH = path.join(CONFIG_DIR, 'config.json');
|
|
9
|
+
|
|
10
|
+
function read() {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
13
|
+
} catch {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function write(config) {
|
|
19
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
20
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + '\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isMuted() {
|
|
24
|
+
return read().muted === true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function setMuted(muted) {
|
|
28
|
+
const config = read();
|
|
29
|
+
config.muted = muted;
|
|
30
|
+
write(config);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { isMuted, setMuted, read, write, CONFIG_PATH };
|
package/lib/index.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const { resolveSound, listSounds, generateWav } = require('./sounds');
|
|
4
4
|
const { playSound } = require('./player');
|
|
5
|
+
const { isMuted } = require('./config');
|
|
5
6
|
|
|
6
7
|
async function play(options = {}) {
|
|
7
8
|
const { sound = 'default', volume } = options;
|
|
8
9
|
|
|
10
|
+
if (isMuted()) return;
|
|
11
|
+
|
|
9
12
|
try {
|
|
10
13
|
const soundInfo = resolveSound(sound);
|
|
11
14
|
await playSound(soundInfo, { volume });
|
package/lib/setup.js
CHANGED
|
@@ -6,9 +6,16 @@ const os = require('os');
|
|
|
6
6
|
|
|
7
7
|
const CLAUDE_SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
|
|
8
8
|
|
|
9
|
+
// Claude Code hook format: { matcher: "", hooks: [{ type, command }] }
|
|
9
10
|
const HOOKS = {
|
|
10
|
-
Notification: {
|
|
11
|
-
|
|
11
|
+
Notification: {
|
|
12
|
+
matcher: '',
|
|
13
|
+
hooks: [{ type: 'command', command: 'npx tonton-cli --input' }],
|
|
14
|
+
},
|
|
15
|
+
Stop: {
|
|
16
|
+
matcher: '',
|
|
17
|
+
hooks: [{ type: 'command', command: 'npx tonton-cli --done' }],
|
|
18
|
+
},
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
function readSettings() {
|
|
@@ -26,8 +33,10 @@ function writeSettings(settings) {
|
|
|
26
33
|
fs.writeFileSync(CLAUDE_SETTINGS_PATH, JSON.stringify(settings, null, 2) + '\n');
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
function hookExists(
|
|
30
|
-
return
|
|
36
|
+
function hookExists(entries, command) {
|
|
37
|
+
return entries.some(e =>
|
|
38
|
+
e.hooks && e.hooks.some(h => h.command === command)
|
|
39
|
+
);
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
function setup() {
|
|
@@ -37,13 +46,15 @@ function setup() {
|
|
|
37
46
|
|
|
38
47
|
let added = 0;
|
|
39
48
|
|
|
40
|
-
for (const [event,
|
|
49
|
+
for (const [event, entry] of Object.entries(HOOKS)) {
|
|
41
50
|
if (!settings.hooks[event]) settings.hooks[event] = [];
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
const command = entry.hooks[0].command;
|
|
53
|
+
|
|
54
|
+
if (!hookExists(settings.hooks[event], command)) {
|
|
55
|
+
settings.hooks[event].push(entry);
|
|
45
56
|
added++;
|
|
46
|
-
console.log(` + ${event} → ${
|
|
57
|
+
console.log(` + ${event} → ${command}`);
|
|
47
58
|
} else {
|
|
48
59
|
console.log(` ~ ${event} → already configured`);
|
|
49
60
|
}
|
|
@@ -55,8 +66,8 @@ function setup() {
|
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
console.log('\nDone! Claude Code will now play:');
|
|
58
|
-
console.log(' --done sound when the agent finishes');
|
|
59
|
-
console.log(' --input sound when the agent needs you');
|
|
69
|
+
console.log(' --done sound when the agent finishes (Stop)');
|
|
70
|
+
console.log(' --input sound when the agent needs you (Notification)');
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
function unsetup() {
|
|
@@ -69,11 +80,14 @@ function unsetup() {
|
|
|
69
80
|
|
|
70
81
|
let removed = 0;
|
|
71
82
|
|
|
72
|
-
for (const [event,
|
|
83
|
+
for (const [event, entry] of Object.entries(HOOKS)) {
|
|
73
84
|
if (!settings.hooks[event]) continue;
|
|
74
85
|
|
|
86
|
+
const command = entry.hooks[0].command;
|
|
75
87
|
const before = settings.hooks[event].length;
|
|
76
|
-
settings.hooks[event] = settings.hooks[event].filter(
|
|
88
|
+
settings.hooks[event] = settings.hooks[event].filter(e =>
|
|
89
|
+
!(e.hooks && e.hooks.some(h => h.command === command))
|
|
90
|
+
);
|
|
77
91
|
const after = settings.hooks[event].length;
|
|
78
92
|
|
|
79
93
|
if (before !== after) {
|
|
@@ -81,13 +95,11 @@ function unsetup() {
|
|
|
81
95
|
console.log(` - ${event} → removed`);
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
// Clean up empty arrays
|
|
85
98
|
if (settings.hooks[event].length === 0) {
|
|
86
99
|
delete settings.hooks[event];
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
|
|
90
|
-
// Clean up empty hooks object
|
|
91
103
|
if (Object.keys(settings.hooks).length === 0) {
|
|
92
104
|
delete settings.hooks;
|
|
93
105
|
}
|