Files
dth/scripts/prep-sandbox-space.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

93 lines
2.5 KiB
Bash
Executable File

#!/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