klaudio 0.13.0 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaudio",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Add sound effects to your coding sessions — play sounds when tasks complete, notifications arrive, and more",
5
5
  "type": "module",
6
6
  "bin": {
package/src/installer.js CHANGED
@@ -120,6 +120,7 @@ export async function install({ scope, sounds, tts = false, voice, speed } = {})
120
120
  async function installApprovalHooks(settings, soundPath, claudeDir) {
121
121
  const normalized = soundPath.replace(/\\/g, "/");
122
122
  const scriptPath = join(claudeDir, "approval-notify.sh").replace(/\\/g, "/");
123
+ const cliPath = new URL("../bin/cli.js", import.meta.url).pathname;
123
124
 
124
125
  // Write the timer script
125
126
  const script = `#!/usr/bin/env bash
@@ -128,6 +129,7 @@ async function installApprovalHooks(settings, soundPath, claudeDir) {
128
129
  DELAY=120
129
130
  MARKER="/tmp/.claude-approval-pending"
130
131
  SOUND="${normalized}"
132
+ CLI="${cliPath}"
131
133
 
132
134
  case "$1" in
133
135
  start)
@@ -140,9 +142,9 @@ case "$1" in
140
142
  if [ -f "$MARKER" ] && [ "$(head -1 "$MARKER" 2>/dev/null)" = "$TOKEN" ]; then
141
143
  PROJECT=$(tail -1 "$MARKER" 2>/dev/null | sed 's|.*[/\\\\]||')
142
144
  rm -f "$MARKER"
143
- npx klaudio play "$SOUND" 2>/dev/null
144
- npx klaudio notify "\${PROJECT:-project}" "Waiting for your approval" 2>/dev/null
145
- npx klaudio say "\${PROJECT:-project} needs your attention" 2>/dev/null
145
+ node "$CLI" play "$SOUND" 2>/dev/null
146
+ node "$CLI" notify "\${PROJECT:-project}" "Waiting for your approval" 2>/dev/null
147
+ node "$CLI" say "\${PROJECT:-project} needs your attention" 2>/dev/null
146
148
  fi
147
149
  ) &
148
150
  ;;
package/src/player.js CHANGED
@@ -371,20 +371,22 @@ export async function handlePlayCommand(args) {
371
371
  const soundFile = args.find((a) => !a.startsWith("-"));
372
372
  const tts = args.includes("--tts");
373
373
 
374
- // Read stdin (hook JSON) non-blocking
374
+ // Read stdin (hook JSON) only when TTS or notifications need it
375
375
  let hookData = {};
376
- try {
377
- const chunks = [];
378
- process.stdin.setEncoding("utf-8");
379
- // Read whatever is available with a short timeout
380
- const stdinData = await new Promise((res) => {
381
- const timer = setTimeout(() => { process.stdin.pause(); res(chunks.join("")); }, 500);
382
- process.stdin.on("data", (chunk) => chunks.push(chunk));
383
- process.stdin.on("end", () => { clearTimeout(timer); res(chunks.join("")); });
384
- process.stdin.resume();
385
- });
386
- if (stdinData.trim()) hookData = JSON.parse(stdinData);
387
- } catch { /* no stdin or invalid JSON */ }
376
+ if (tts || args.includes("--notify")) {
377
+ try {
378
+ const chunks = [];
379
+ process.stdin.setEncoding("utf-8");
380
+ // Read whatever is available with a short timeout
381
+ const stdinData = await new Promise((res) => {
382
+ const timer = setTimeout(() => { process.stdin.pause(); res(chunks.join("")); }, 500);
383
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
384
+ process.stdin.on("end", () => { clearTimeout(timer); res(chunks.join("")); });
385
+ process.stdin.resume();
386
+ });
387
+ if (stdinData.trim()) hookData = JSON.parse(stdinData);
388
+ } catch { /* no stdin or invalid JSON */ }
389
+ }
388
390
 
389
391
  const notify = args.includes("--notify");
390
392
 
@@ -497,5 +499,8 @@ export function getHookPlayCommand(soundFilePath, { tts = false, voice, speed, n
497
499
  const voiceFlag = tts && voice ? ` --voice ${voice}` : "";
498
500
  const speedFlag = tts && speed && speed !== 1.0 ? ` --speed ${speed}` : "";
499
501
  const notifyFlag = notify ? " --notify" : "";
500
- return `npx klaudio play "${normalized}"${ttsFlag}${voiceFlag}${speedFlag}${notifyFlag}`;
502
+ // Resolve the CLI path at install time to avoid npx overhead on every hook call.
503
+ // When klaudio is updated and re-installed, hooks are rewritten with the new path.
504
+ const cliPath = new URL("../bin/cli.js", import.meta.url).pathname;
505
+ return `node "${cliPath}" play "${normalized}"${ttsFlag}${voiceFlag}${speedFlag}${notifyFlag}`;
501
506
  }