Files
dth/scripts/prep-sandbox-skills.sh
T
xstudio agentandClaude Opus 4.8 a94f40e42e merge sandbox/dd24a29: chg_0003 dispatch_helpers — A1 prep + A2 setup + A3 wait scripts (3 host tools, 8 cases, gate PASS)
- scripts/prep-sandbox-skills.sh: A1 host-side skill 拷贝 (跳过 symlink/template-boot-jnpf/JNPF_*)
- scripts/setup-xstudio-ai.sh: A2 host-side ai-config writer (python3 merge 不覆盖已有 providers)
- scripts/wait-for-task.sh: A3 host-side completion poller (轮询 /tmp/xstudio-sandbox/*/space/.xstudio-report.md)
- tests/e2e/dispatch_helpers.test.sh: 6 case 自检
- openspec/changes/chg_0003_dispatch_helpers/{5 工件}

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

146 lines
3.5 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
# prep-sandbox-skills.sh — A1: copy host skills into sandbox space before dispatch.
#
# Usage:
# bash scripts/prep-sandbox-skills.sh <wsHash> [--src <skillSrcDir>]
#
# Why: xstudio 内核 ccWorkDir 挂载时 .xstudio/ 被排除(容器不挂)。
# sandbox agent 启动后需要 skill 资产 → 必须 pre-dispatch 把 host 的
# ~/.claude/skills/ 拷到 sandbox space 的 .claude/skills/。
#
# 跳过:
# - symlink(在容器里 host 路径解析失败)
# - ssw-jnpf-lite-react/template-boot-jnpf(>50MB 模板)
# - ssw-jnpf-lite-react/JNPF_*(>10KB 大型资源)
#
# Exit codes:
# 0 成功(断言 .claude/skills/ai-collab-framework/ 存在)
# 1 入参 / 空间 / source 路径错误
# 2 复制后断言失败(sandbox 端 skill 资产缺失)
set -euo pipefail
# ---- args ----
usage() {
cat <<'EOF'
prep-sandbox-skills.sh — A1 host-side skill prep
Usage:
bash scripts/prep-sandbox-skills.sh <wsHash> [--src <skillSrcDir>]
Arguments:
wsHash -- sandbox hash; /tmp/xstudio-sandbox/<wsHash>/space/ must exist
--src <dir> -- source skills dir (default: $HOME/.claude/skills/)
Example:
bash scripts/prep-sandbox-skills.sh $(ls /tmp/xstudio-sandbox | head -1)
EOF
}
if [[ $# -lt 1 || "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
usage
exit 0
fi
WS_HASH="$1"
shift
SKILL_SRC="$HOME/.claude/skills/"
while [[ $# -gt 0 ]]; do
case "$1" in
--src)
SKILL_SRC="${2:-}"
shift 2
;;
--src=*)
SKILL_SRC="${1#--src=}"
shift
;;
*)
echo "ERROR: unknown arg: $1" >&2
usage >&2
exit 1
;;
esac
done
# ---- validation ----
if [[ -z "$WS_HASH" ]]; then
echo "ERROR: wsHash is required" >&2
usage >&2
exit 1
fi
SPACE_DIR="/tmp/xstudio-sandbox/${WS_HASH}/space"
if [[ ! -d "$SPACE_DIR" ]]; then
echo "ERROR: sandbox space $SPACE_DIR 不存在;先派一个任务让内核播种" >&2
exit 1
fi
if [[ ! -d "$SKILL_SRC" ]]; then
echo "ERROR: skill source $SKILL_SRC 不存在" >&2
exit 1
fi
# ---- copy ----
DEST="$SPACE_DIR/.claude/skills"
mkdir -p "$DEST"
# Clear stale copies so re-runs don't accumulate (idempotent)
rm -rf "$DEST"/*
copied=()
skipped=()
for skill_dir in "$SKILL_SRC"/*/; do
[[ -d "$skill_dir" ]] || continue
name=$(basename "$skill_dir")
# 跳过 symlink(容器里 host 绝对路径解析失败)
if [[ -L "$skill_dir" ]]; then
skipped+=("$name (symlink)")
continue
fi
# 跳过 ssw-jnpf-lite-react 内的超大资源
case "$name" in
template-boot-jnpf|JNPF_*)
skipped+=("$name (large)")
continue
;;
esac
cp -R "$skill_dir" "$DEST/$name"
copied+=("$name")
done
# 也跳过 ssw-jnpf-lite-react 内的特定子目录
if [[ -d "$DEST/ssw-jnpf-lite-react" ]]; then
for sub in template-boot-jnpf; do
if [[ -e "$DEST/ssw-jnpf-lite-react/$sub" ]]; then
rm -rf "$DEST/ssw-jnpf-lite-react/$sub"
skipped+=("ssw-jnpf-lite-react/$sub (large)")
fi
done
# JNPF_* glob(空匹配走字面量 shopt 关闭 nullglob 后会留 *)
shopt -s nullglob
for sub in "$DEST/ssw-jnpf-lite-react"/JNPF_*; do
if [[ -e "$sub" ]]; then
local_name="${sub##*/}"
rm -rf "$sub"
skipped+=("ssw-jnpf-lite-react/$local_name (large)")
fi
done
shopt -u nullglob
fi
echo "copied: ${copied[*]:-none}"
echo "skipped: ${skipped[*]:-none}"
echo "skills present:"
ls -1 "$DEST" | sed 's/^/ - /'
# ---- assertion ----
if [[ ! -d "$DEST/ai-collab-framework" ]]; then
echo "ERROR: ai-collab-framework not present after copy" >&2
exit 2
fi
exit 0