|
| 1 | +#!/bin/bash |
| 2 | +# Hook script for Auggie Stop event |
| 3 | +# Sends a Warp notification when Auggie completes a task |
| 4 | + |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | + |
| 7 | +# Opt-in debug logging (set AUGGIE_WARP_DEBUG=1) |
| 8 | +if [ -n "${AUGGIE_WARP_DEBUG:-}" ]; then |
| 9 | + _LOG="${AUGGIE_WARP_DEBUG_LOG:-/tmp/auggie-warp-debug.log}" |
| 10 | + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $(basename "$0") pid=$$ TERM_PROGRAM=${TERM_PROGRAM:-} WARP_PROTO=${WARP_CLI_AGENT_PROTOCOL_VERSION:-} WARP_VER=${WARP_CLIENT_VERSION:-}" >> "$_LOG" |
| 11 | +fi |
| 12 | + |
| 13 | +# Read hook input from stdin |
| 14 | +INPUT=$(cat) |
| 15 | +[ -n "${AUGGIE_WARP_DEBUG:-}" ] && echo "[stdin] $INPUT" >> "${AUGGIE_WARP_DEBUG_LOG:-/tmp/auggie-warp-debug.log}" |
| 16 | + |
| 17 | +# Extract transcript path from the hook input |
| 18 | +TRANSCRIPT_PATH=$(echo "$INPUT" | jq -r '.transcript_path // empty' 2>/dev/null) |
| 19 | + |
| 20 | +# Default message |
| 21 | +MSG="Task completed" |
| 22 | + |
| 23 | +# Try to extract prompt and response from the transcript (JSONL format) |
| 24 | +if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then |
| 25 | + # Get the first user prompt |
| 26 | + PROMPT=$(jq -rs ' |
| 27 | + [.[] | select(.type == "user")] | first | .message.content // empty |
| 28 | + ' "$TRANSCRIPT_PATH" 2>/dev/null) |
| 29 | + |
| 30 | + # Get the last assistant response |
| 31 | + RESPONSE=$(jq -rs ' |
| 32 | + [.[] | select(.type == "assistant" and .message.content)] | last | |
| 33 | + [.message.content[] | select(.type == "text") | .text] | join(" ") |
| 34 | + ' "$TRANSCRIPT_PATH" 2>/dev/null) |
| 35 | + |
| 36 | + if [ -n "$PROMPT" ] && [ -n "$RESPONSE" ]; then |
| 37 | + # Truncate prompt to 50 chars |
| 38 | + if [ ${#PROMPT} -gt 50 ]; then |
| 39 | + PROMPT="${PROMPT:0:47}..." |
| 40 | + fi |
| 41 | + # Truncate response to 120 chars |
| 42 | + if [ ${#RESPONSE} -gt 120 ]; then |
| 43 | + RESPONSE="${RESPONSE:0:117}..." |
| 44 | + fi |
| 45 | + MSG="\"${PROMPT}\" → ${RESPONSE}" |
| 46 | + elif [ -n "$RESPONSE" ]; then |
| 47 | + # Fallback to just response if no prompt found |
| 48 | + if [ ${#RESPONSE} -gt 175 ]; then |
| 49 | + RESPONSE="${RESPONSE:0:172}..." |
| 50 | + fi |
| 51 | + MSG="$RESPONSE" |
| 52 | + fi |
| 53 | +fi |
| 54 | + |
| 55 | +"$SCRIPT_DIR/warp-notify.sh" "Auggie" "$MSG" |
0 commit comments