tokens-for-good 0.4.1 → 0.4.2
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/package.json +1 -1
- package/src/cli.js +1 -1
- package/src/init.js +33 -3
package/package.json
CHANGED
package/src/cli.js
CHANGED
package/src/init.js
CHANGED
|
@@ -7,6 +7,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
|
7
7
|
import { join, dirname } from 'path';
|
|
8
8
|
import { homedir } from 'os';
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
|
+
import { spawnSync } from 'child_process';
|
|
10
11
|
import { detectPlatform } from './platform.js';
|
|
11
12
|
import { loadState, saveState } from './state.js';
|
|
12
13
|
|
|
@@ -238,15 +239,44 @@ function writeSessionStartHook() {
|
|
|
238
239
|
matcher: '',
|
|
239
240
|
hooks: [{
|
|
240
241
|
type: 'command',
|
|
241
|
-
command:
|
|
242
|
-
? 'cmd /c npx -y tokens-for-good session-start-hook'
|
|
243
|
-
: 'npx -y tokens-for-good session-start-hook',
|
|
242
|
+
command: hookCommand(),
|
|
244
243
|
}],
|
|
245
244
|
});
|
|
246
245
|
}
|
|
247
246
|
writeJson(abs, cfg);
|
|
248
247
|
}
|
|
249
248
|
|
|
249
|
+
// Claude Code runs SessionStart hooks under Git Bash on Windows with a
|
|
250
|
+
// stripped PATH that typically does not include C:\Program Files\nodejs,
|
|
251
|
+
// so a bare `npx` lookup fails silently. Resolve the absolute npx path at
|
|
252
|
+
// init time (when the user's full PATH is available) and bake it into the
|
|
253
|
+
// hook command so it works regardless of Claude Code's hook-runner PATH.
|
|
254
|
+
function hookCommand() {
|
|
255
|
+
if (!IS_WINDOWS) return 'npx -y tokens-for-good session-start-hook';
|
|
256
|
+
|
|
257
|
+
const npxPath = resolveWindowsNpxPath();
|
|
258
|
+
// Bash accepts double-quoted paths with spaces; escape backslashes for JSON.
|
|
259
|
+
return `"${npxPath}" -y tokens-for-good session-start-hook`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function resolveWindowsNpxPath() {
|
|
263
|
+
// First try `where npx.cmd` — most reliable when PATH is correct.
|
|
264
|
+
try {
|
|
265
|
+
const r = spawnSync('where', ['npx.cmd'], { encoding: 'utf-8' });
|
|
266
|
+
if (r.status === 0) {
|
|
267
|
+
const first = r.stdout.trim().split(/\r?\n/)[0];
|
|
268
|
+
if (first && existsSync(first)) return first;
|
|
269
|
+
}
|
|
270
|
+
} catch { /* fall through */ }
|
|
271
|
+
|
|
272
|
+
// Fallback: npx.cmd usually sits alongside node.exe.
|
|
273
|
+
const alongside = join(dirname(process.execPath), 'npx.cmd');
|
|
274
|
+
if (existsSync(alongside)) return alongside;
|
|
275
|
+
|
|
276
|
+
// Last-resort guess — user's hook may need manual edit if this is wrong.
|
|
277
|
+
return 'C:\\Program Files\\nodejs\\npx.cmd';
|
|
278
|
+
}
|
|
279
|
+
|
|
250
280
|
function writeSkillFile(name) {
|
|
251
281
|
const src = join(PKG_ROOT, 'skills', `${name}.md`);
|
|
252
282
|
const dst = join(homedir(), '.claude', 'skills', name, 'SKILL.md');
|