Files
dth/scripts/dispatch-preflight.sh
T
xstudio agentandClaude Opus 4.8 9eeb9a8030 feat(dispatch-helpers): A-2 prep-sandbox-space.sh + dispatch-preflight.sh; B-2 brainstorming↔openspec 映射; E-2 prompt 模板
A-2 prep-sandbox-space.sh:
- 修 A-1 mount 断链:拷贝 workspace 当前状态到 /tmp/xstudio-sandbox/<hash>/space/
- +force 选项覆盖已有空间
- 推断 workspaceRoot 走 last_workspace 文件兜底

A-2 dispatch-preflight.sh:
- 4 项自检:docker / 容器 up / space 可写 / .claude/skills 拷到位
- + bonus: workspaceRoot ai-config
- 自动调 prep-sandbox-space / prep-sandbox-skills / auto-setup-xstudio-ai
- 实测:ccc workspace 全部 ✅

B-2 brainstorming-openspec-mapping.md:
- design.md → chg 工件字段映射表
- naming 约定 (capability / chg_id / S 编号 / C 编号)
- chg 创建 10 步 checklist
- 与 superskills using-superpowers 冲突解决

E-2 prompt-template.md:
- 6 段 prompt 结构 (Header / Cache / Don't / 工件 / 步骤 / 汇报)
- 完整 chg_0005 实例
- 模板生成脚本占位(待下次写)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-09-28 13:57:57 +08:00

115 lines
3.6 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
# 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"
if ! bash "$SELF_DIR/prep-sandbox-space.sh" "$WS_HASH" $FORCE; 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 全部就绪,可派单"