Files
karuo-ai/01_卡资(金)/金仓_存储备份/Cursor持久对话/verify.sh
2026-07-19 00:21:46 +08:00

85 lines
3.1 KiB
Bash
Executable File
Raw 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.

#!/usr/bin/env bash
# 可持续对话 · 验收脚本(打印成功/失败与修复动作)
set -u
INSTALL_DIR="${PCHAT_INSTALL_DIR:-$HOME/.persistent-chat-local}"
GLOBAL_MCP="$HOME/.cursor/mcp.json"
CODEX_MCP="$HOME/.codex/config.toml"
PORT="${PCHAT_HTTP_PORT:-13458}"
FAIL=0
ok() { echo "$1"; }
bad() { echo "$1"; FAIL=$((FAIL+1)); }
warn() { echo " ⚠️ $1"; }
echo "🔍 可持续对话验收"
echo ""
# 1. 文件
for f in server.js panel.html mongo_sync.py hub.js ensure-hub.sh; do
[[ -f "$INSTALL_DIR/$f" ]] && ok "$f 存在" || bad "$f 缺失 → 重新运行 install.sh"
done
# 1b. server.js 必须是 Hub 客户端(非旧版自带 HTTP
if [[ -f "$INSTALL_DIR/server.js" ]] && grep -q 'MCP stdio client' "$INSTALL_DIR/server.js" 2>/dev/null; then
ok "server.js 为 Hub 客户端版"
else
bad "server.js 是旧版单体 → bash install.sh --global-only 后 Cmd+Q 重启 Cursor"
fi
# 2. node
if command -v node >/dev/null 2>&1; then
ok "node $(node -v)"
else
bad "node 未安装 → brew install node@22"
fi
# 3. 全局 mcp
if [[ -f "$GLOBAL_MCP" ]] && grep -q '"persistent-chat"' "$GLOBAL_MCP" 2>/dev/null; then
ok "~/.cursor/mcp.json 含 persistent-chat"
else
bad "~/.cursor/mcp.json 无 persistent-chat → bash install.sh --global-only"
fi
# 3b. Codex 配置
if [[ -f "$CODEX_MCP" ]] && grep -q 'persistent-chat' "$CODEX_MCP" 2>/dev/null; then
ok "~/.codex/config.toml 含 persistent-chat"
else
warn "~/.codex/config.toml 无 persistent-chat → bash 脚本/codex_persistent_chat_apply.sh \"/你的工作区\""
fi
# 4. HTTP 面板Hub 独立进程)
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -m 2 "http://127.0.0.1:${PORT}/" 2>/dev/null || echo "000")
HUB_OK=$(curl -sf -m 2 "http://127.0.0.1:${PORT}/api/health" 2>/dev/null || echo "")
if [[ "$HTTP_CODE" == "200" && -n "$HUB_OK" ]]; then
ok "Hub 在线 http://127.0.0.1:${PORT}/ (pid $(echo "$HUB_OK" | python3 -c "import sys,json; print(json.load(sys.stdin).get('pid','?'))" 2>/dev/null || echo ?))"
STATE=$(curl -s -m 2 "http://127.0.0.1:${PORT}/api/state" 2>/dev/null || echo "{}")
WAITING=$(echo "$STATE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(sum(1 for s in d.get('sessions',[]) if s.get('status')=='waiting'))" 2>/dev/null || echo "?")
echo " 当前 waiting 会话: $WAITING"
else
warn "Hub 未响应 (HTTP $HTTP_CODE) → bash install.sh 或 node $INSTALL_DIR/hub.js"
fi
# 5. Mongo可选
if python3 "$INSTALL_DIR/mongo_sync.py" >/dev/null 2>&1; then
ok "MongoDB karuo_site.持久对话会话 可写"
else
warn "MongoDB 未同步27017 未开或缺 pymongo主功能不受影响"
fi
# 6. 规则
if [[ -f "$PWD/.cursor/rules/persistent-chat.mdc" ]]; then
ok "当前目录有 persistent-chat.mdc 规则"
else
warn "当前目录无 .cursor/rules/persistent-chat.mdc → install.sh --project $(pwd)"
fi
echo ""
if [[ $FAIL -eq 0 ]]; then
echo "🟢 核心项通过。若 Cursor 里仍无 MCP必须 Cmd+Q 完全退出再开。"
exit 0
else
echo "🔴 $FAIL 项失败。按上面 ❌ 行的修复动作执行后重跑 verify.sh"
exit 1
fi