cc-hook-registry 2.0.0 → 2.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/index.mjs +49 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -192,10 +192,55 @@ else if (command === 'install') {
|
|
|
192
192
|
console.log();
|
|
193
193
|
|
|
194
194
|
if (hook.install.startsWith('npx cc-safe-setup')) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
// Try direct download first (no cc-safe-setup dependency)
|
|
196
|
+
const exampleName = hook.install.match(/--install-example\s+(\S+)/)?.[1];
|
|
197
|
+
if (exampleName) {
|
|
198
|
+
const rawUrl = `https://raw.githubusercontent.com/yurukusa/cc-safe-setup/main/examples/${exampleName}.sh`;
|
|
199
|
+
const hookPath = join(HOME, '.claude', 'hooks', exampleName + '.sh');
|
|
200
|
+
try {
|
|
201
|
+
mkdirSync(join(HOME, '.claude', 'hooks'), { recursive: true });
|
|
202
|
+
const script = execSync(`curl -sL "${rawUrl}"`, { encoding: 'utf-8' });
|
|
203
|
+
if (script.startsWith('#!/bin/bash')) {
|
|
204
|
+
writeFileSync(hookPath, script);
|
|
205
|
+
chmodSync(hookPath, 0o755);
|
|
206
|
+
|
|
207
|
+
// Auto-register in settings.json
|
|
208
|
+
const trigger = script.includes('PreToolUse') ? 'PreToolUse' :
|
|
209
|
+
script.includes('PostToolUse') ? 'PostToolUse' :
|
|
210
|
+
script.includes('Stop') ? 'Stop' : 'PreToolUse';
|
|
211
|
+
const matcher = script.includes('Matcher: "Bash"') || script.includes('MATCHER: "Bash"') ? 'Bash' :
|
|
212
|
+
script.includes('Matcher: "Edit|Write"') ? 'Edit|Write' : '';
|
|
213
|
+
|
|
214
|
+
let settings = {};
|
|
215
|
+
if (existsSync(SETTINGS_PATH)) {
|
|
216
|
+
try { settings = JSON.parse(readFileSync(SETTINGS_PATH, 'utf-8')); } catch {}
|
|
217
|
+
}
|
|
218
|
+
if (!settings.hooks) settings.hooks = {};
|
|
219
|
+
if (!settings.hooks[trigger]) settings.hooks[trigger] = [];
|
|
220
|
+
|
|
221
|
+
const existing = settings.hooks[trigger].flatMap(e => (e.hooks || []).map(h => h.command));
|
|
222
|
+
if (!existing.some(cmd => cmd.includes(exampleName))) {
|
|
223
|
+
settings.hooks[trigger].push({
|
|
224
|
+
matcher,
|
|
225
|
+
hooks: [{ type: 'command', command: hookPath }],
|
|
226
|
+
});
|
|
227
|
+
mkdirSync(dirname(SETTINGS_PATH), { recursive: true });
|
|
228
|
+
writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
console.log(c.green + ' ✓ Installed: ' + hookPath + c.reset);
|
|
232
|
+
console.log(c.green + ' ✓ Registered in settings.json (' + trigger + ')' + c.reset);
|
|
233
|
+
console.log(c.dim + ' Restart Claude Code to activate.' + c.reset);
|
|
234
|
+
} else {
|
|
235
|
+
throw new Error('Invalid script');
|
|
236
|
+
}
|
|
237
|
+
} catch {
|
|
238
|
+
// Fallback to cc-safe-setup
|
|
239
|
+
console.log(c.dim + ' Direct download failed, using cc-safe-setup...' + c.reset);
|
|
240
|
+
try { execSync(hook.install, { stdio: 'inherit' }); } catch {}
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
try { execSync(hook.install, { stdio: 'inherit' }); } catch {}
|
|
199
244
|
}
|
|
200
245
|
} else {
|
|
201
246
|
console.log(c.dim + ' This hook requires manual installation. Follow the instructions above.' + c.reset);
|