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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokens-for-good",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Donate your spare AI tokens to research nonprofits for Fierce Philanthropy",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  // CLI entry point for tokens-for-good.
4
4
  // Usage:
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: IS_WINDOWS
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');