Files
dth/openspec/scripts/create_change.sh
T
xstudio agent c1cf6f54e5 merge sandbox/ai-1790562657-0EF743: chg_0001 dth scaffold + chg_0002 experiment_platform MVP
- chg_0001_dth_scaffold (skip_coverage): openspec framework + NestJS+React+PGlite scaffold
- chg_0002_sp1_experiment_platform_mvp: 6 scenarios S1-S6 + 21 perm-smoke + 16 e2e + 3 demo operators (hello-mpc/pir/vertical-lr)

Sandbox task exit 0. Independent verification: check_spec_coverage.sh gap=0 PASS.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-09-28 10:54:34 +08:00

75 lines
2.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
# ==============================================================================
# scripts/create_change.sh (skill: ai-collab-framework)
# 简化版 change 创建:
# - 找下一个 chg_NNNN 编号
# - 创建 openspec/changes/chg_NNNN_<slug>/(含 mvp/prototype/)
# - 复制技能包 templates/ 里的全部模板
#
# 需要 branch + worktree + Change-Id 校验时,用 scripts/create_change.py。
#
# 目标项目定位:环境变量 PROJECT_ROOT,默认当前目录。
# (脚本位于技能包内,不假设自己在目标项目里。)
#
# 用法:PROJECT_ROOT=/path/to/project bash create_change.sh <slug>
# 例:bash create_change.sh add_note_crud
# ==============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEMPLATES_DIR="$SCRIPT_DIR/../templates"
ROOT="${PROJECT_ROOT:-$(pwd)}"
CHANGES_DIR="$ROOT/openspec/changes"
SLUG="${1:-}"
if [ -z "$SLUG" ]; then
echo "Usage: PROJECT_ROOT=<project> $0 <slug> e.g. $0 add_note_crud"
exit 2
fi
if [ ! -d "$TEMPLATES_DIR" ]; then
echo "FAIL: 找不到模板目录 $TEMPLATES_DIR" >&2
exit 1
fi
# 找下一个编号:识别 chg_NNNN[_slug] 与归档项 archive/YYYY-MM-DD-chg_NNNN_slug,
# 必须连 archive/ 一起扫,否则归档后编号会复用旧号。
mkdir -p "$CHANGES_DIR"
LAST=$(find "$CHANGES_DIR" -mindepth 1 -maxdepth 2 -type d 2>/dev/null \
| grep -oE 'chg_[0-9]{4}' | sort -u | tail -1 | sed 's/chg_//' || true)
LAST="${LAST:-0}"
# 10# 前缀:避免 "0009" 被当成非法八进制
NEXT=$((10#$LAST + 1))
printf -v CHG_ID 'chg_%04d' "$NEXT"
TARGET="$CHANGES_DIR/${CHG_ID}_${SLUG}"
if [ -d "$TARGET" ]; then
echo "FAIL: $TARGET 已存在"
exit 1
fi
mkdir -p "$TARGET/mvp/prototype"
touch "$TARGET/mvp/prototype/.gitkeep"
echo "created $TARGET"
# 复制全部模板(含无后缀的 testcases.map.yaml)
COUNT=0
for tpl in "$TEMPLATES_DIR"/*; do
[ -f "$tpl" ] || continue
cp "$tpl" "$TARGET/$(basename "$tpl")"
COUNT=$((COUNT + 1))
done
echo
echo "templates copied: $COUNT files"
ls "$TARGET"
echo
echo "Next:"
echo " 1. edit $TARGET/proposal.md (PM)"
echo " 2. edit $TARGET/spec.md (PD, 场景写成 '### S1 <场景名>')"
echo " 3. edit $TARGET/testcases.md + testcases.map.yaml (QA, case id 形如 C1_xxx)"
echo " 4. edit $TARGET/tasks.md (TM)"
echo " 5. PROJECT_ROOT=$ROOT bash $SCRIPT_DIR/check_spec_coverage.sh"
echo
echo "Change-Id trailer to add in commit: Change-Id: $CHG_ID"