tonton-cli 1.0.0 → 1.0.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.
- package/README.md +3 -3
- 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/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
|
}
|