Files
vibe-foreman/scripts/hub-hook-permission.sh
2a12a1611c feat: .app 真·开箱即用 + 终端派发修复 Keychain 登录态 (#3)
让 .app 不再依赖 hub 项目仓库存在,在新电脑上装上就能用。

## 自包含改造
- scripts/sounds 嵌入 .app Resources,启动自动同步到
  ~/Library/Application Support/claude-hub/(覆盖式)
- projects.yaml 迁到 ~/Library/Application Support/claude-hub/,
  首次启动自建空模板
- scripts 改自定位($(dirname $0) 推断 HUB_DIR),
  不再硬编码 ~/Documents/code/claude-hub
- 启动时 ensure_path() 跑 zsh -l -i 继承 user shell PATH,
  解决 launchd 启动只有 /usr/bin:/bin 找不到 brew/bun 的问题

## 依赖检查
- 新增 deps.rs 启动时 which tmux/iTerm/claude/git/terminal-notifier
- UI 红卡片显示缺失依赖 + 一键复制 brew install 命令

## 终端派发(修复 Claude 非登录状态)
- 新增 term.rs:检测 iTerm > Warp > WezTerm > Terminal.app
  优先级,第一版只支持 iTerm + Terminal.app
- 第一次 tmux new-session 改由终端跑,server 父进程是终端,
  claude 继承终端 Keychain ACL 解决登录态读不到的问题
- UI deps panel 显示当前终端 + 检测到旧版 server 时提示
  tmux kill-server

## UI 增强
- 空项目时显示扫描引导卡片
- 顶部加「⟳ 扫描」按钮,Rust 实现 git 仓库自动发现
- 缺失依赖卡片支持点击复制安装命令

Co-authored-by: wuguangan <anjaihd0206@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 14:52:41 +08:00

54 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Notification hook - Claude 需要授权时通知用户
# 全局生效,零配置。
# 获取项目名
if [ -n "$TMUX" ]; then
NAME=$(tmux display-message -p '#W' 2>/dev/null)
fi
if [ -z "$NAME" ]; then
NAME=$(git rev-parse --show-toplevel 2>/dev/null | xargs basename 2>/dev/null)
fi
NAME="${NAME:-$(basename "$PWD" 2>/dev/null)}"
# 自定位:从脚本所在目录推断 HUB_DIR,支持任意安装位置
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
HUB_DIR="${HUB_DIR:-$(dirname "$SCRIPT_DIR")}"
SOUNDS_DIR="$HUB_DIR/sounds"
SIGNAL_DIR="/tmp/hub-signals"
EVENTS_DIR="$SIGNAL_DIR/events"
# 随机选一条提醒语
MESSAGES=(
"需要你授权"
"在等你点确认"
"卡住了,需要你批准"
"Claude 在等你"
)
MSG="${MESSAGES[$((RANDOM % ${#MESSAGES[@]}))]}"
# 写 JSON 事件文件(供 Tauri app 读取)
mkdir -p "$EVENTS_DIR"
cat > "$EVENTS_DIR/$(date +%s%N 2>/dev/null || date +%s).json" << EOF
{
"type": "permission",
"project": "${NAME}",
"message": "${MSG}",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date +%H:%M:%S)"
}
EOF
# 桌面通知(点击跳转 iTerm2)
if command -v terminal-notifier &>/dev/null; then
terminal-notifier -title "⚠️ ${NAME}" -message "$MSG" -sound Basso -activate com.googlecode.iterm2 2>/dev/null
else
osascript -e "display notification \"${NAME} ${MSG}\" with title \"⚠️ 需要授权\" sound name \"Basso\"" 2>/dev/null
fi
# 语音播报
AUTH_FILES=("$SOUNDS_DIR"/auth*.aiff)
if [ ${#AUTH_FILES[@]} -gt 0 ]; then
SOUND="${AUTH_FILES[$((RANDOM % ${#AUTH_FILES[@]}))]}"
afplay "$SOUND" 2>/dev/null
fi