diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index aeb5076..6eb2f93 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -10,7 +10,7 @@ { "name": "devscope", "description": "Real-time developer activity monitoring for Claude Code sessions", - "version": "0.38.0", + "version": "0.39.0", "author": { "name": "Lucas Dow", "email": "lucdow7@gmail.com" diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 2bedb33..7ed3727 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "devscope", - "version": "0.38.0", + "version": "0.39.0", "description": "Real-time developer activity monitoring for Claude Code sessions", "author": { "name": "Lucas Dow", diff --git a/CHANGELOG.md b/CHANGELOG.md index c14174f..c9dbd5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [0.39.0] - 2026-11-10 + +### Changed +- **Answering cuts the announcement short.** When you approve or deny a + permission prompt or answer a question while the voice is still announcing + it, that announcement stops instead of playing to the end. Only speech + about a prompt you settled is cut: a "several sessions need you" sentence + stops once all of them are answered, and auto voice and explanations are + never cut this way. An approved Bash command counts as answered as soon as it + is seen running, which is usually well before it finishes. + ## [0.38.0] - 2026-11-05 ### Added diff --git a/CLAUDE.md b/CLAUDE.md index 3f52797..4a46405 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -221,6 +221,12 @@ claude plugin disable devscope@devscope # Disable no voice or is unreachable it falls back to Piper if installed (`/devscope:voice setup`), else `say`/`spd-say`/`espeak`. What is sent follows the privacy mode: `standard` sends no more than its events do. Tests: `tests/voice/run.sh`. +- **Cut on answer** (`_ds_voice_speak_announcement`): the announcer speaks in a background job in + its own process group (`set -m`) and polls the markers it is about every 0.2 s (the approved-command + `ps` check once a second). Once none still has the eventId it was armed with, it signals the group + *and* every pid in the tree listed beforehand (`_ds_voice_tree`), since GNU `timeout` around the + player makes a group of its own. Speech gets `TMPDIR=voice/ann/`, pruned when that pid + is dead, so a cut or a killed timer leaves no WAV behind. Log line: `answered: announcement cut short`. - **Speech queue** (`_ds_voice_with_lock`): every speaker (timer announcements, `speak.sh` replies and explanations) writes `queue/-`; the oldest ticket whose pid is alive is next, and the lock (flock, or on macOS a `speak.lock.d/pid` taken over only when that pid is diff --git a/scripts/voice/lib.sh b/scripts/voice/lib.sh index 1aa6cf9..40f2f77 100755 --- a/scripts/voice/lib.sh +++ b/scripts/voice/lib.sh @@ -772,7 +772,9 @@ _ds_voice_announce_due() { [ "$(jq -r '.privacy' "$f" 2>/dev/null)" = "private" ] && privacy=private done _ds_voice_log "speak: $text" - _ds_voice_speak "$text" "$privacy" + local -a specs=() + for i in "${!files[@]}"; do specs+=("${files[$i]}:${eids[$i]}"); done + _ds_voice_speak_announcement "$text" "$privacy" "${specs[@]}" for i in "${!files[@]}"; do _ds_voice_bump "${files[$i]}" "${eids[$i]}"; done return 0 fi @@ -783,11 +785,62 @@ _ds_voice_announce_due() { # Summarizing takes a moment; skip a session that was answered meanwhile. [ "$(jq -r '.eventId' "$f" 2>/dev/null)" = "${eids[$i]}" ] || continue _ds_voice_log "speak: $text" - _ds_voice_speak "$text" "$(jq -r '.privacy' "$f" 2>/dev/null)" + _ds_voice_speak_announcement "$text" "$(jq -r '.privacy' "$f" 2>/dev/null)" "$f:${eids[$i]}" _ds_voice_bump "$f" "${eids[$i]}" done } +# True while any of these blocks still waits: its marker has the same eventId +# and, when asked, its approved Bash command is not yet seen running. +_ds_voice_any_waiting() { # check-running marker:event-id... + local check="$1" spec f + shift + for spec in "$@"; do + f="${spec%:*}" + [ "$(jq -r '.eventId' "$f" 2>/dev/null)" = "${spec##*:}" ] || continue + [ "$check" = 1 ] && _ds_voice_tool_started "$f" && continue + return 0 + done + return 1 +} + +# Speak an announcement, cut short once every block it is about was answered +# (marker cleared or re-armed by a later event, or the approved command is +# running), so a prompt you already settled is not read out to the end. The +# speech runs in its own process group (set -m), and every process in its tree +# is signalled too, since `timeout` (around the player) makes a group of its +# own. It gets its own TMPDIR (ann/, pruned once that pid is gone), so a +# cut or a killed timer leaves no audio file behind. +_ds_voice_speak_announcement() { # text privacy marker:event-id... + local text="$1" privacy="$2" pid tmpd d pids n=0 + shift 2 + for d in "$DS_VOICE_DIR/ann/"*; do + [ -d "$d" ] && ! kill -0 "${d##*/}" 2>/dev/null && rm -rf "$d" + done + tmpd="$DS_VOICE_DIR/ann/$$" + mkdir -p "$tmpd" 2>/dev/null || { _ds_voice_speak "$text" "$privacy"; return 0; } + set -m + ( TMPDIR="$tmpd"; _ds_voice_speak "$text" "$privacy" ) & + pid=$! + set +m + while kill -0 "$pid" 2>/dev/null; do + sleep 0.2 + n=$((n + 1)) + # The process check (ps) once a second, the marker check every time. + _ds_voice_any_waiting "$(( n % 5 == 0 ))" "$@" && continue + # Listed before the group goes, while the tree still hangs together. + pids=$(_ds_voice_tree "$pid") + kill -TERM -- "-$pid" 2>/dev/null + # shellcheck disable=SC2086 + kill -TERM $pids 2>/dev/null + _ds_voice_log "answered: announcement cut short" + break + done + wait "$pid" 2>/dev/null + rm -rf "$tmpd" + return 0 +} + # Run a command while holding the global speak lock. # Run a command when it is this process's turn to speak. Every speaker takes a # ticket; the oldest ticket whose process is alive goes next, and the lock @@ -1111,6 +1164,13 @@ _ds_voice_chunks() { }' } +# A process and everything it started, one pid per line. +_ds_voice_tree() { # pid + local c + printf '%s\n' "$1" + for c in $(pgrep -P "$1" 2>/dev/null); do _ds_voice_tree "$c"; done +} + # End a process and everything it started (the speech engine under timeout). _ds_voice_kill_tree() { # pid local c diff --git a/tests/voice/run.sh b/tests/voice/run.sh index cc8eeaf..47749b9 100644 --- a/tests/voice/run.sh +++ b/tests/voice/run.sh @@ -78,6 +78,27 @@ sleep 2.5 [ "$(lines)" = 0 ] && [ ! -f "$PENDING/s15.json" ] && ok "approved long-running command: silent" || bad "approved running" "$(spoken)" kill "$RUNNING" 2>/dev/null; wait "$RUNNING" 2>/dev/null || true configure; reset + +# 2c. Answered while the announcement is being spoken: it is cut short. An +# answer in another session does not cut it. +TL="$TMP/timeline-cut"; VLOG="$HOME/.cache/devscope/voice/voice.log" +wait_started() { for _ in $(seq 1 50); do grep -q '^start' "$TL" 2>/dev/null && return 0; sleep 0.1; done; return 1; } +configure; reset; rm -f "$TL" "$VLOG"; respond '{"text": "cloud wants to run the migration."}' +DS_VOICE_TIMELINE="$TL" DS_VOICE_TEST_SPEAK_SEC=4 hook permission-request.sh s16 /work/cloud "$PERM" +if wait_started; then + hook tool-complete.sh s16 /work/cloud "$DONE_BASH" + sleep 1.5 + ! grep -q '^end' "$TL" && [ "$(lines)" = 0 ] && grep -q 'announcement cut short' "$VLOG" \ + && ok "answered mid-announcement: speech cut short" || bad "cut" "$(cat "$TL"; spoken)" +else bad "cut" "announcement never started"; fi +configure; reset; rm -f "$TL" "$VLOG" +DS_VOICE_TIMELINE="$TL" DS_VOICE_TEST_SPEAK_SEC=2 hook permission-request.sh s17 /work/cloud "$PERM" +if wait_started; then + hook tool-complete.sh other-session /work/cloud "$DONE_BASH" + wait_spoken 1 4 && grep -q '^end' "$TL" && ! grep -q 'cut short' "$VLOG" 2>/dev/null \ + && ok "another session's answer does not cut it" || bad "no cut" "$(cat "$TL"; spoken)" +else bad "no cut" "announcement never started"; fi +configure; reset DS_VOICE_CLAUDE_PID=$$ DEVSCOPE_PRIVACY=private hook permission-request.sh s16 /work/cloud "$PERM" wait_spoken 1 5 && ok "not running yet: still announced" || bad "not running" "silent"