@raindrop-ai/claude-code 0.0.2 → 0.0.3
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/dist/cli.js +59 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1284,13 +1284,14 @@ import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as rea
|
|
|
1284
1284
|
import { homedir as homedir2, userInfo as userInfo2 } from "os";
|
|
1285
1285
|
import { dirname as dirname2, join as join5, resolve } from "path";
|
|
1286
1286
|
import { createInterface } from "readline";
|
|
1287
|
+
import { execSync } from "child_process";
|
|
1287
1288
|
function getClaudeSettingsPath(scope, cwd) {
|
|
1288
1289
|
if (scope === "project") {
|
|
1289
1290
|
return resolve(cwd, ".claude", "settings.json");
|
|
1290
1291
|
}
|
|
1291
1292
|
return join5(homedir2(), ".claude", "settings.json");
|
|
1292
1293
|
}
|
|
1293
|
-
var
|
|
1294
|
+
var CORE_HOOK_EVENTS = [
|
|
1294
1295
|
"SessionStart",
|
|
1295
1296
|
"UserPromptSubmit",
|
|
1296
1297
|
"PreToolUse",
|
|
@@ -1298,15 +1299,58 @@ var HOOK_EVENTS = [
|
|
|
1298
1299
|
"PostToolUseFailure",
|
|
1299
1300
|
"SubagentStart",
|
|
1300
1301
|
"SubagentStop",
|
|
1301
|
-
"PermissionDenied",
|
|
1302
|
-
"PostCompact",
|
|
1303
1302
|
"Stop",
|
|
1304
|
-
"StopFailure",
|
|
1305
1303
|
"SessionEnd"
|
|
1306
1304
|
];
|
|
1307
|
-
|
|
1305
|
+
var VERSIONED_HOOK_EVENTS = [
|
|
1306
|
+
{ minVersion: "2.1.78", events: ["StopFailure"] },
|
|
1307
|
+
{ minVersion: "2.1.76", events: ["PostCompact"] },
|
|
1308
|
+
{ minVersion: "2.1.89", events: ["PermissionDenied"] }
|
|
1309
|
+
];
|
|
1310
|
+
function parseVersion(version) {
|
|
1311
|
+
const match = version.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
1312
|
+
if (!match) return void 0;
|
|
1313
|
+
return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)];
|
|
1314
|
+
}
|
|
1315
|
+
function isVersionAtLeast(current, required) {
|
|
1316
|
+
const req = parseVersion(required);
|
|
1317
|
+
if (!req) return false;
|
|
1318
|
+
for (let i = 0; i < 3; i++) {
|
|
1319
|
+
if (current[i] > req[i]) return true;
|
|
1320
|
+
if (current[i] < req[i]) return false;
|
|
1321
|
+
}
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1324
|
+
function detectClaudeCodeVersion() {
|
|
1325
|
+
try {
|
|
1326
|
+
const output = execSync("claude --version", {
|
|
1327
|
+
encoding: "utf-8",
|
|
1328
|
+
timeout: 5e3,
|
|
1329
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
1330
|
+
}).trim();
|
|
1331
|
+
const match = output.match(/(\d+\.\d+\.\d+)/);
|
|
1332
|
+
return match ? match[1] : void 0;
|
|
1333
|
+
} catch (e) {
|
|
1334
|
+
return void 0;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
function getHookEventsForVersion(version) {
|
|
1338
|
+
const events = [...CORE_HOOK_EVENTS];
|
|
1339
|
+
if (!version) {
|
|
1340
|
+
return events;
|
|
1341
|
+
}
|
|
1342
|
+
const parsed = parseVersion(version);
|
|
1343
|
+
if (!parsed) return events;
|
|
1344
|
+
for (const { minVersion, events: versionedEvents } of VERSIONED_HOOK_EVENTS) {
|
|
1345
|
+
if (isVersionAtLeast(parsed, minVersion)) {
|
|
1346
|
+
events.push(...versionedEvents);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return events;
|
|
1350
|
+
}
|
|
1351
|
+
function makeHookConfig(hookEvents) {
|
|
1308
1352
|
const hooks = {};
|
|
1309
|
-
for (const event of
|
|
1353
|
+
for (const event of hookEvents) {
|
|
1310
1354
|
hooks[event] = [
|
|
1311
1355
|
{
|
|
1312
1356
|
hooks: [
|
|
@@ -1371,6 +1415,14 @@ async function runSetup(args2) {
|
|
|
1371
1415
|
writeFileSync4(configPath, JSON.stringify(raindropConfig, null, 2) + "\n", "utf-8");
|
|
1372
1416
|
console.log(` Saved Raindrop config to ${configPath}`);
|
|
1373
1417
|
}
|
|
1418
|
+
const ccVersion = detectClaudeCodeVersion();
|
|
1419
|
+
const hookEvents = getHookEventsForVersion(ccVersion);
|
|
1420
|
+
if (ccVersion) {
|
|
1421
|
+
console.log(` Detected Claude Code v${ccVersion}`);
|
|
1422
|
+
} else {
|
|
1423
|
+
console.log(` Could not detect Claude Code version \u2014 registering core hooks only.`);
|
|
1424
|
+
console.log(` Run setup again after installing Claude Code to enable all hooks.`);
|
|
1425
|
+
}
|
|
1374
1426
|
const settingsPath = getClaudeSettingsPath(scope, process.cwd());
|
|
1375
1427
|
const settingsDir = dirname2(settingsPath);
|
|
1376
1428
|
mkdirSync4(settingsDir, { recursive: true });
|
|
@@ -1384,7 +1436,7 @@ async function runSetup(args2) {
|
|
|
1384
1436
|
}
|
|
1385
1437
|
}
|
|
1386
1438
|
const existingHooks = (_e = settings["hooks"]) != null ? _e : {};
|
|
1387
|
-
const newHooks = makeHookConfig();
|
|
1439
|
+
const newHooks = makeHookConfig(hookEvents);
|
|
1388
1440
|
for (const [event, hookGroups] of Object.entries(newHooks)) {
|
|
1389
1441
|
const existing = existingHooks[event];
|
|
1390
1442
|
if (!existing || !Array.isArray(existing)) {
|
|
@@ -1405,7 +1457,6 @@ async function runSetup(args2) {
|
|
|
1405
1457
|
settings["hooks"] = existingHooks;
|
|
1406
1458
|
writeFileSync4(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
1407
1459
|
console.log(` Updated Claude Code hooks in ${settingsPath} (${scopeLabel})`);
|
|
1408
|
-
const { execSync } = await import("child_process");
|
|
1409
1460
|
const whichCmd = process.platform === "win32" ? "where" : "which";
|
|
1410
1461
|
try {
|
|
1411
1462
|
execSync(`${whichCmd} raindrop-claude-code`, { stdio: "ignore" });
|
package/package.json
CHANGED