Files
dth/scripts/dispatch-preflight.sh
xstudio agentandClaude Code bce08505d2 fix(dispatch-preflight): prep-sandbox-space.sh 传 "true" 而非 "--force"(§2.5 1 行修复)
影响:dispatch-preflight.sh --force 实际未触发 prep-sandbox-space.sh 重播种,
      旧空间残留导致后续派单基于陈旧 main
改动:脚本 line 77 $FORCE 改为 FORCE_FLAG="--force"(仅在 true 时赋值)
参考:dispatch-session-v2 §2.5 + dispatch-preflight.sh 自检流程

Co-Authored-By: Claude Code <[email protected]>
2026-09-28 21:51:39 +08:00

118 lines
3.8 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.
#!/usr/bin/env bash
# dispatch-preflight.sh — dispatch 派单前自检(A-2 + A-4)
#
# 用法:
# bash scripts/dispatch-preflight.sh <wsHash> [--force]
#
# 自检项:
# 1. docker 可用 + 容器 up
# 2. /tmp/xstudio-sandbox/<wsHash>/space/ 存在且可写(不存在自动调用 prep-sandbox-space.sh)
# 3. .claude/skills/<skill> 拷到位(不存在自动调用 prep-sandbox-skills.sh)
# 4. <workspaceRoot>/.xstudio/ai-config.json 已写(不存在自动调用 auto-setup-xstudio-ai.sh)
#
# 退出码:
# 0 全部就绪
# 1 docker 不可用
# 2 workspaceRoot 不可推断
# 3 容器未 up
# 4 prep-sandbox-space.sh 失败
# 5 prep-sandbox-skills.sh 失败
# 6 auto-setup-xstudio-ai.sh 失败
set -euo pipefail
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
WS_HASH="${1:-}"
FORCE="false"
shift 2>/dev/null || true
while [ $# -gt 0 ]; do
case "$1" in
--force) FORCE="true"; shift ;;
*) echo "ERROR: unknown arg: $1" >&2; exit 1 ;;
esac
done
if [ -z "$WS_HASH" ]; then
# 兜底:取 ls /tmp/xstudio-sandbox | head -1
WS_HASH=$(ls /tmp/xstudio-sandbox 2>/dev/null | head -1 || echo "")
fi
if [ -z "$WS_HASH" ]; then
echo "ERROR: wsHash required or /tmp/xstudio-sandbox empty" >&2
exit 1
fi
# workspaceRoot 推断(与 prep-sandbox-space.sh 一致)
WORKSPACE_ROOT="${WORKSPACE_ROOT:-}"
if [ -z "$WORKSPACE_ROOT" ]; then
if [ -f "$HOME/Library/Application Support/XStudio/last_workspace" ]; then
WORKSPACE_ROOT=$(cat "$HOME/Library/Application Support/XStudio/last_workspace" 2>/dev/null || echo "")
fi
fi
echo "=============== dispatch-preflight ==============="
echo "[1/4] docker 可用性"
if ! command -v docker >/dev/null 2>&1; then
echo " ❌ docker 不在 PATH"
exit 1
fi
if ! docker ps >/dev/null 2>&1; then
echo " ❌ docker daemon 不可达"
exit 1
fi
echo " ✅ docker OK"
echo "[2/4] 容器 up"
CONTAINER="ccc-$WS_HASH-cc"
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
echo " ⚠️ 容器 $CONTAINER 不在 running list(派单时会自动 ensureRunning)"
else
echo " ✅ 容器 up: $CONTAINER"
fi
echo "[3/4] sandbox space 存在 + 可写"
SPACE_DIR="/tmp/xstudio-sandbox/$WS_HASH/space"
if [ ! -d "$SPACE_DIR" ] || [ "$FORCE" = "true" ]; then
echo " ⚠️ space 不存在(或 --force),调 prep-sandbox-space.sh"
# prep-sandbox-space.sh expects literal "--force" arg, not "true"(dispatch-session-v2 §2.5 bug)
FORCE_FLAG=""
[ "$FORCE" = "true" ] && FORCE_FLAG="--force"
if ! bash "$SELF_DIR/prep-sandbox-space.sh" "$WS_HASH" $FORCE_FLAG; then
exit 4
fi
fi
# 测试 mount 是否真的可写(probe-write)
if touch "$SPACE_DIR/.probe-write" 2>/dev/null && rm "$SPACE_DIR/.probe-write" 2>/dev/null; then
echo " ✅ space 可写: $SPACE_DIR"
else
echo " ❌ space 不可写: $SPACE_DIR"
exit 4
fi
echo "[4/4] .claude/skills 拷到位"
SKILLS_DIR="$SPACE_DIR/.claude/skills"
if [ ! -d "$SKILLS_DIR" ] || [ "$FORCE" = "true" ]; then
echo " ⚠️ skills 目录不存在,调 prep-sandbox-skills.sh"
if ! bash "$SELF_DIR/prep-sandbox-skills.sh" "$WS_HASH"; then
exit 5
fi
else
SKILL_COUNT=$(ls "$SKILLS_DIR" 2>/dev/null | wc -l | tr -d ' ')
echo " ✅ skills 目录有 $SKILL_COUNT 个 skill"
fi
# 检查 workspaceRoot 的 ai-config.json
if [ -n "$WORKSPACE_ROOT" ] && [ -d "$WORKSPACE_ROOT" ]; then
echo "[bonus] workspaceRoot ai-config"
if [ ! -f "$WORKSPACE_ROOT/.xstudio/ai-config.json" ] || [ "$FORCE" = "true" ]; then
echo " ⚠️ ai-config.json 缺失,调 auto-setup-xstudio-ai.sh"
if ! bash "$SELF_DIR/auto-setup-xstudio-ai.sh" "$WORKSPACE_ROOT"; then
exit 6
fi
else
echo " ✅ ai-config.json 已就绪"
fi
fi
echo "============================================="
echo "[OK] dispatch-preflight 全部就绪,可派单"