#!/bin/sh # ============================================================ # 下载地址(首次运行从这里拉取 notify.exe)—— 按需修改 DOWNLOAD_URL="https://git.pchuan.top/cc-tools/notify/releases/download/v1.0.0/notify.exe" # ============================================================ DIR="$(cd "$(dirname "$0")" && pwd)" BIN="$DIR/../bin" EXE="$BIN/notify.exe" PART="$BIN/notify.exe.partial" LOCK="$BIN/notify.download.lock" # 常规路径:exe 已就绪 -> 直接转发参数与 stdin(保持管道完整) if [ -f "$EXE" ]; then exec "$EXE" "$@" fi # ---- exe 缺失:绝不阻塞 hook ---- mkdir -p "$BIN" 2>/dev/null # 自愈:上次下载进程被硬杀(关机/崩溃)可能留下陈旧锁,挡住所有重试。 # .partial 不存在(没真正开始)或 >2 分钟没增长(进程已死)则回收锁,让 -C - 续传。 if [ -d "$LOCK" ]; then if [ ! -f "$PART" ]; then rmdir "$LOCK" 2>/dev/null elif [ -n "$(find "$PART" -mmin +2 2>/dev/null)" ]; then rmdir "$LOCK" 2>/dev/null fi fi # 原子锁:只有第一个 hook 派生唯一的后台下载进程;并发/后续 hook 抢锁失败 # -> 不重复下载,只汇报进度。下载脱离 hook 后台进行,不受 30s 超时影响。 if mkdir "$LOCK" 2>/dev/null; then # 断点续传 -C -;失败保留 .partial 供下次续传;无论成败都释放锁 nohup sh -c "curl -fsSL -C - '$DOWNLOAD_URL' -o '$PART' && mv -f '$PART' '$EXE' && chmod +x '$EXE'; rmdir '$LOCK' 2>/dev/null" >/dev/null 2>&1 & fi # 已下载大小(取 .partial 字节数),汇报给 Claude DLBYTES=0 [ -f "$PART" ] && DLBYTES=$(wc -c < "$PART" 2>/dev/null | tr -d ' ') DLMB=$(awk "BEGIN{printf \"%.1f\", $DLBYTES/1048576}") # exit 0 让 Claude 解析此 JSON;systemMessage 展示给用户,本次通知跳过 printf '{"suppressOutput":true,"systemMessage":"[Claude Code Notify] notifier not ready, downloading in background: %s MB / ~14 MB done. Works automatically once finished; this notification is skipped."}\n' "$DLMB" exit 0