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]>
This commit is contained in:
xstudio agentandClaude Opus 4.8 committed 2026-09-28 13:57:57 +08:00
1 parent 77337aeef4
commit 9eeb9a8030
4 files changed
+556

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
#!/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 全部就绪,可派单"
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# prep-sandbox-space.sh — host-side修补:A-1 mount 断链 host-side 重播种
#
# 用法:
# bash scripts/prep-sandbox-space.sh <wsHash>
# bash scripts/prep-sandbox-space.sh <wsHash> --force # 强制 rm 重播种
#
# 行为:
# 1. 检查 /tmp/xstudio-sandbox/<wsHash>/space/ 是否存在
# 2. 不存在或 --force → 拷贝 workspace 当前状态进去 + git checkout -B sandbox
# 3. 存在 → 跳过
# 4. 输出 workspaceRoot 推断
#
# 配合 dispatch-preflight.sh 自动调用
set -euo pipefail
usage() {
cat <<'EOF'
Usage: prep-sandbox-space.sh <wsHash> [--force]
wsHash xstudio-sandbox/<hash> 里的 hash
--force 强制 rm + 重播种(即使空间已存在)
Exit codes:
0 空间就绪(已存在或刚创建)
1 参数错误
2 workspaceRoot 不可推断
3 cp / git 失败
EOF
}
if [ $# -lt 1 ] || [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
usage
exit 0
fi
WS_HASH="$1"
shift
FORCE="false"
while [ $# -gt 0 ]; do
case "$1" in
--force) FORCE="true"; shift ;;
*) echo "ERROR: unknown arg: $1" >&2; usage >&2; exit 1 ;;
esac
done
SPACE_BASE="/tmp/xstudio-sandbox"
SPACE_DIR="$SPACE_BASE/$WS_HASH/space"
# 推断 workspaceRoot
WORKSPACE_ROOT="${WORKSPACE_ROOT:-}"
if [ -z "$WORKSPACE_ROOT" ]; then
# 兜底:从 macOS 上 xstudio 的 last_workspace 文件读
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
if [ -z "$WORKSPACE_ROOT" ] || [ ! -d "$WORKSPACE_ROOT" ]; then
echo "ERROR: workspaceRoot 不可推断(\$WORKSPACE_ROOT 空 + last_workspace 不存在/无效)" >&2
exit 2
fi
echo "[prep-sandbox-space] workspaceRoot=$WORKSPACE_ROOT"
echo "[prep-sandbox-space] spaceDir=$SPACE_DIR"
echo "[prep-sandbox-space] force=$FORCE"
if [ -d "$SPACE_DIR" ] && [ "$FORCE" != "true" ]; then
echo "[prep-sandbox-space] 空间已存在,跳过重播种"
exit 0
fi
if [ "$FORCE" = "true" ] && [ -d "$SPACE_DIR" ]; then
echo "[prep-sandbox-space] --force: 删旧空间"
rm -rf "$SPACE_DIR"
fi
# 拷贝 workspace 当前状态
mkdir -p "$SPACE_DIR"
if ! cp -R "$WORKSPACE_ROOT/." "$SPACE_DIR/"; then
echo "ERROR: cp $WORKSPACE_ROOT/. → $SPACE_DIR 失败" >&2
exit 3
fi
# 在空间里 checkout sandbox 分支
cd "$SPACE_DIR"
if ! git checkout -B sandbox 2>&1 | tail -3; then
echo "ERROR: git checkout -B sandbox 失败" >&2
exit 3
fi
echo "[prep-sandbox-space] 重播种完成"
git log --oneline | head -3