Compare commits

...

2 Commits

Author SHA1 Message Date
csh c44b9aa4bb 🔧 chore(scripts): require flag-driven args 2026-01-21 15:19:53 +08:00
csh e4e1d14182 🔧 chore(scripts): unify single-dash options 2026-01-21 14:39:46 +08:00
20 changed files with 631 additions and 324 deletions

View File

@ -56,21 +56,21 @@ PlaybookTSL`.tsl`/`.tsf`+ C++ + Python + Markdown代码格式化
```bash ```bash
# Linux/macOS # Linux/macOS
sh scripts/sync_templates.sh /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project
# PowerShell # PowerShell
.\scripts\sync_templates.ps1 -ProjectRoot C:\path\to\project .\scripts\sync_templates.ps1 -ProjectRoot C:\path\to\project
# Windows CMD # Windows CMD
scripts\sync_templates.bat C:\path\to\project scripts\sync_templates.bat -project-root C:\path\to\project
``` ```
**部署行为** **部署行为**
- **新项目**:创建完整的 `AGENTS.md`、`AGENT_RULES.md`、`memory-bank/`、`docs/prompts/`、`TODO.md`、`CONFIRM.md` - **新项目**:创建完整的 `AGENTS.md`、`AGENT_RULES.md`、`memory-bank/`、`docs/prompts/`、`TODO.md`、`CONFIRM.md`
- **已有 AGENTS.md**:追加路由链接(使用 `<!-- playbook:templates:start/end -->` 标记) - **已有 AGENTS.md**:追加路由链接(使用 `<!-- playbook:templates:start/end -->` 标记)
- **--full 参数**:追加完整框架(规则优先级 + 新会话开始时)到已有 AGENTS.md - **-full 参数**:追加完整框架(规则优先级 + 新会话开始时)到已有 AGENTS.md
- **其他文件**:如果已存在则跳过(使用 `--force` 覆盖) - **其他文件**:如果已存在则跳过(使用 `-force` 覆盖)
详见:`templates/README.md` 详见:`templates/README.md`
@ -140,12 +140,13 @@ Layer 3: docs/ (权威静态文档)
| 你的情况 | 推荐方式 | 优势 | | 你的情况 | 推荐方式 | 优势 |
| -------------------------------- | ------------------------------- | ------------------------------- | | -------------------------------- | ------------------------------- | ------------------------------- |
| 新项目,需要持续同步更新 | **方式一git subtree(推荐)** | 可随时拉取最新标准,版本可追溯 | | 新项目,需要持续同步更新 | 方式一git subtree | 可随时拉取最新标准,版本可追溯 |
| 只需要一次性引入,不常更新 | 方式二:手动复制快照 | 简单直接,无需 git subtree 知识 | | 只需要一次性引入,不常更新 | 方式二:手动复制快照 | 简单直接,无需 git subtree 知识 |
| 只需要部分语言(如只要 TSL+C++ | 方式三:脚本裁剪复制 | 自动裁剪,只包含所需语言 | | 只需要部分语言(且希望快照也裁剪) | 方式三:脚本裁剪复制 | 快照只包含所需语言(更小) |
| **不确定?** | **方式一git subtree推荐** | 最灵活,后续可随时同步更新 | | **不确定?** | **方式一git subtree推荐** | 最灵活,后续可随时同步更新 |
**大部分情况推荐使用方式一git subtree。** **大部分情况推荐使用方式一git subtree。**
说明:方式一可选择同步哪些语言规则到 `.agents/`,但 `docs/standards/playbook/` 快照仍是全量;方式三会裁剪快照本身。
--- ---
@ -159,7 +160,7 @@ git subtree add --prefix docs/standards/playbook \
https://git.mytsl.cn/csh/playbook.git main --squash https://git.mytsl.cn/csh/playbook.git main --squash
# 2. 同步规则到项目根目录 # 2. 同步规则到项目根目录
sh docs/standards/playbook/scripts/sync_standards.sh tsl sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl
# 3. 提交 # 3. 提交
git add . git add .
@ -201,19 +202,19 @@ git commit -m ":package: deps(playbook): add tsl standards"
2. **同步到项目根目录**(生成/更新 `.agents/<lang>/`、更新 `.gitattributes` 2. **同步到项目根目录**(生成/更新 `.agents/<lang>/`、更新 `.gitattributes`
```bash ```bash
sh docs/standards/playbook/scripts/sync_standards.sh sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl
``` ```
同步 C++ 规则集(同一份快照,不同规则集): 同步 C++ 规则集(同一份快照,不同规则集):
```bash ```bash
sh docs/standards/playbook/scripts/sync_standards.sh cpp sh docs/standards/playbook/scripts/sync_standards.sh -langs cpp
``` ```
一次同步多个规则集(推荐,减少重复备份 `.gitattributes` 一次同步多个规则集(推荐,减少重复备份 `.gitattributes`
```bash ```bash
sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl,cpp
``` ```
> 说明:若项目根目录没有 `AGENTS.md``sync_standards.*` > 说明:若项目根目录没有 `AGENTS.md``sync_standards.*`
@ -239,14 +240,14 @@ git commit -m ":package: deps(playbook): add tsl standards"
```bash ```bash
git subtree add --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash git subtree add --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
sh docs/standards/playbook/scripts/sync_standards.sh tsl sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl
``` ```
**旧项目**(已有 `AGENTS.md` **旧项目**(已有 `AGENTS.md`
```bash ```bash
git subtree pull --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash git subtree pull --prefix docs/standards/playbook https://git.mytsl.cn/csh/playbook.git main --squash
sh docs/standards/playbook/scripts/sync_standards.sh tsl sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl
``` ```
旧项目的 `AGENTS.md` 不会被覆盖;如需指向 `.agents/`,请手动对齐内容。 旧项目的 `AGENTS.md` 不会被覆盖;如需指向 `.agents/`,请手动对齐内容。
@ -259,14 +260,14 @@ sh docs/standards/playbook/scripts/sync_standards.sh tsl
#!/usr/bin/env sh #!/usr/bin/env sh
set -eu set -eu
sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl,cpp
# sh docs/standards/python/scripts/sync_standards.sh # sh docs/standards/python/scripts/sync_standards.sh
``` ```
也可以直接一次同步多个规则集: 也可以直接一次同步多个规则集:
```sh ```sh
sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl,cpp
``` ```
#### 目录约定(建议) #### 目录约定(建议)
@ -303,16 +304,15 @@ sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp
- 脚本会从快照目录同步到项目根目录,并先备份旧文件(`.bak.*` - 脚本会从快照目录同步到项目根目录,并先备份旧文件(`.bak.*`
建议固定使用 `--prefix docs/standards/playbook`,因为同步后的 `.agents/*/` 建议固定使用 `--prefix docs/standards/playbook`,因为同步后的 `.agents/*/`
会引用该路径下的标准快照文档(`docs/standards/playbook/docs/...`)。无参数时若已存在 会引用该路径下的标准快照文档(`docs/standards/playbook/docs/...`)。同步时需显式指定
`.agents/<lang>/`,将按现有语言同步;否则默认 `.agents/tsl/`。如需同步 C++ 规则集, 语言参数(`-langs`),如需同步 C++ 规则集,推荐直接运行:
推荐直接运行:`sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp` `sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl,cpp`
这样 clone 任意项目时都能直接读取规范文件,不依赖外部访问权限。 这样 clone 任意项目时都能直接读取规范文件,不依赖外部访问权限。
**同步脚本行为**(目标项目内的最终落地内容): **同步脚本行为**(目标项目内的最终落地内容):
- 覆盖/更新:`.agents/<AGENTS_NS>/`(默认 `.agents/tsl/` - 覆盖/更新:`.agents/<AGENTS_NS>/`(由 `-langs``AGENTS_NS` 指定)
- 自动识别:未传语言参数且已存在 `.agents/<lang>/` 时,按现有语言同步
- 更新 `.gitattributes`:默认追加缺失规则(可用 - 更新 `.gitattributes`:默认追加缺失规则(可用
`SYNC_GITATTR_MODE=append|block|overwrite|skip` 控制) `SYNC_GITATTR_MODE=append|block|overwrite|skip` 控制)
- 缺省创建:`.agents/index.md` - 缺省创建:`.agents/index.md`
@ -362,19 +362,19 @@ sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp
- macOS/Linux - macOS/Linux
```bash ```bash
sh <PLAYBOOK_ROOT>/scripts/vendor_playbook.sh <target-project-root> tsl cpp sh <PLAYBOOK_ROOT>/scripts/vendor_playbook.sh -project-root <target-project-root> -langs tsl,cpp
``` ```
- PowerShell - PowerShell
```powershell ```powershell
powershell -File <PLAYBOOK_ROOT>\\scripts\\vendor_playbook.ps1 -DestRoot <target-project-root> -Langs tsl,cpp powershell -File <PLAYBOOK_ROOT>\\scripts\\vendor_playbook.ps1 -ProjectRoot <target-project-root> -Langs tsl,cpp
``` ```
- Windows bat - Windows bat
```bat ```bat
<PLAYBOOK_ROOT>\\scripts\\vendor_playbook.bat <target-project-root> --langs tsl,cpp <PLAYBOOK_ROOT>\\scripts\\vendor_playbook.bat -project-root <target-project-root> -langs tsl,cpp
``` ```
**脚本会** **脚本会**
@ -456,7 +456,7 @@ macOS/Linux 示例(目标项目的 `scripts/sync_standards.sh`
#!/usr/bin/env sh #!/usr/bin/env sh
set -eu set -eu
sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl,cpp
OVERLAY="docs/project/agents_overlay" OVERLAY="docs/project/agents_overlay"
if [ -d "$OVERLAY" ]; then if [ -d "$OVERLAY" ]; then
@ -490,7 +490,7 @@ if (Test-Path $overlay) {
- 若新增"本 Playbook 未覆盖的语言"再引入对应语言的标准仓库subtree/vendoring 到 - 若新增"本 Playbook 未覆盖的语言"再引入对应语言的标准仓库subtree/vendoring 到
`docs/standards/<lang>/` `docs/standards/<lang>/`
- **代理规则** - **代理规则**
- C++:运行 `sh docs/standards/playbook/scripts/sync_standards.sh cpp`(或 - C++:运行 `sh docs/standards/playbook/scripts/sync_standards.sh -langs cpp`(或
`& "docs/standards/playbook/scripts/sync_standards.ps1" -Langs cpp`),落地到 `& "docs/standards/playbook/scripts/sync_standards.ps1" -Langs cpp`),落地到
`.agents/cpp/`(与 `.agents/tsl/` 并行)。 `.agents/cpp/`(与 `.agents/tsl/` 并行)。
- 其他语言:在目标项目增加 `.agents/<lang>/`(与 `.agents/tsl/` - 其他语言:在目标项目增加 `.agents/<lang>/`(与 `.agents/tsl/`

View File

@ -49,38 +49,38 @@ $CODEX_HOME/skills/<skill-name>/SKILL.md
本仓库已提供跨平台安装脚本(会把 `codex/skills/*` 复制到 本仓库已提供跨平台安装脚本(会把 `codex/skills/*` 复制到
`$CODEX_HOME/skills/` `$CODEX_HOME/skills/`
- macOS/Linux`sh scripts/install_codex_skills.sh` - macOS/Linux`sh scripts/install_codex_skills.sh -all`
- PowerShell`powershell -File scripts/install_codex_skills.ps1` - PowerShell`powershell -File scripts/install_codex_skills.ps1 -All`
- Windows bat`scripts/install_codex_skills.bat` - Windows bat`scripts/install_codex_skills.bat -all`
用法示例: 用法示例:
```bash ```bash
# 安装全部 skills # 安装全部 skills
sh scripts/install_codex_skills.sh sh scripts/install_codex_skills.sh -all
# 只安装指定 skills # 只安装指定 skills
sh scripts/install_codex_skills.sh style-cleanup code-review-workflow sh scripts/install_codex_skills.sh -skills style-cleanup,code-review-workflow
``` ```
如果希望“项目内本地安装”(不污染全局),可用以下方式: 如果希望“项目内本地安装”(不污染全局),可用以下方式:
```bash ```bash
# 安装到当前目录的 .codex/skills/ # 安装到当前目录的 .codex/skills/
sh scripts/install_codex_skills.sh --local sh scripts/install_codex_skills.sh -local -all
# 或手动指定 CODEX_HOME # 或手动指定 CODEX_HOME
CODEX_HOME="$(pwd)/.codex" sh scripts/install_codex_skills.sh CODEX_HOME="$(pwd)/.codex" sh scripts/install_codex_skills.sh -all
``` ```
PowerShell / Windows PowerShell / Windows
```powershell ```powershell
powershell -File scripts/install_codex_skills.ps1 -Local powershell -File scripts/install_codex_skills.ps1 -Local -All
``` ```
```bat ```bat
scripts\install_codex_skills.bat --local scripts\install_codex_skills.bat -local -all
``` ```
> 注意Codex 只会从 `CODEX_HOME` 加载 skills使用本地安装时启动 Codex 需设置同样的 `CODEX_HOME` > 注意Codex 只会从 `CODEX_HOME` 加载 skills使用本地安装时启动 Codex 需设置同样的 `CODEX_HOME`
@ -89,7 +89,7 @@ scripts\install_codex_skills.bat --local
`docs/standards/playbook`),则在目标项目里执行: `docs/standards/playbook`),则在目标项目里执行:
```bash ```bash
sh docs/standards/playbook/scripts/install_codex_skills.sh sh docs/standards/playbook/scripts/install_codex_skills.sh -all
``` ```
安装后重启 `codex`,即可在运行时看到 `## Skills` 列表。 安装后重启 `codex`,即可在运行时看到 `## Skills` 列表。

View File

@ -6,9 +6,9 @@ rem - Source: <snapshot>\codex\skills\<skill-name>\
rem - Dest: %CODEX_HOME%\skills\<skill-name>\ (default CODEX_HOME=%USERPROFILE%\.codex) rem - Dest: %CODEX_HOME%\skills\<skill-name>\ (default CODEX_HOME=%USERPROFILE%\.codex)
rem rem
rem Usage: rem Usage:
rem install_codex_skills.bat rem install_codex_skills.bat -all
rem install_codex_skills.bat style-cleanup code-review-workflow rem install_codex_skills.bat -skills style-cleanup,code-review-workflow
rem install_codex_skills.bat --local rem install_codex_skills.bat -local -all
rem rem
rem Notes: rem Notes:
rem - Codex loads skills at startup; restart `codex` after installation. rem - Codex loads skills at startup; restart `codex` after installation.
@ -19,10 +19,42 @@ for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills" set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills"
set "LOCAL_MODE=0" set "LOCAL_MODE=0"
if /I "%~1"=="--local" set "LOCAL_MODE=1" set "INSTALL_ALL=0"
if /I "%~1"=="-l" set "LOCAL_MODE=1" set "SKILLS="
if "%LOCAL_MODE%"=="1" shift :parse_opts
if "%~1"=="" goto opts_done
if /I "%~1"=="-help" goto show_help
if /I "%~1"=="-h" goto show_help
if /I "%~1"=="-local" (
set "LOCAL_MODE=1"
shift
goto parse_opts
)
if /I "%~1"=="-l" (
set "LOCAL_MODE=1"
shift
goto parse_opts
)
if /I "%~1"=="-all" (
set "INSTALL_ALL=1"
shift
goto parse_opts
)
if /I "%~1"=="-skills" (
if "%~2"=="" (
echo ERROR: -skills requires a value.
exit /b 1
)
set "SKILLS=%~2"
shift
shift
goto parse_opts
)
echo ERROR: Unknown option: %~1
exit /b 1
goto opts_done
:opts_done
set "CODEX_HOME=%CODEX_HOME%" set "CODEX_HOME=%CODEX_HOME%"
if "%LOCAL_MODE%"=="1" if "%CODEX_HOME%"=="" set "CODEX_HOME=%CD%\\.codex" if "%LOCAL_MODE%"=="1" if "%CODEX_HOME%"=="" set "CODEX_HOME=%CD%\\.codex"
if "%CODEX_HOME%"=="" set "CODEX_HOME=%USERPROFILE%\\.codex" if "%CODEX_HOME%"=="" set "CODEX_HOME=%USERPROFILE%\\.codex"
@ -35,17 +67,23 @@ if not exist "%SKILLS_SRC_ROOT%" (
if not exist "%SKILLS_DST_ROOT%" mkdir "%SKILLS_DST_ROOT%" if not exist "%SKILLS_DST_ROOT%" mkdir "%SKILLS_DST_ROOT%"
set "HAS_ARGS=0" if "%INSTALL_ALL%"=="1" if not "%SKILLS%"=="" (
if not "%~1"=="" set "HAS_ARGS=1" echo ERROR: use either -all or -skills, not both.
exit /b 1
if "%HAS_ARGS%"=="1" ( )
for %%S in (%*) do call :InstallOne "%%~S" if "%INSTALL_ALL%"=="0" if "%SKILLS%"=="" (
goto Done echo ERROR: -all or -skills is required.
exit /b 1
) )
for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do ( if "%INSTALL_ALL%"=="1" (
set "NAME=%%~nD" for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do (
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!" set "NAME=%%~nD"
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!"
)
) else (
set "SKILLS=%SKILLS:,= %"
for %%S in (%SKILLS%) do call :InstallOne "%%~S"
) )
:Done :Done
@ -53,6 +91,21 @@ echo Done. Skills installed to: "%SKILLS_DST_ROOT%"
endlocal endlocal
exit /b 0 exit /b 0
:show_help
echo Usage:
echo install_codex_skills.bat -all
echo install_codex_skills.bat -skills style-cleanup,code-review-workflow
echo.
echo Options:
echo -local, -l Install to .\\.codex ^(or CODEX_HOME if set^)
echo -skills LIST Comma/space-separated skill names
echo -all Install all skills
echo -help, -h Show this help
echo.
echo Env:
echo CODEX_HOME Target Codex home ^(default: %%USERPROFILE%%\\.codex^)
exit /b 0
:InstallOne :InstallOne
set "NAME=%~1" set "NAME=%~1"
set "SRC_DIR=%SKILLS_SRC_ROOT%\\%NAME%" set "SRC_DIR=%SKILLS_SRC_ROOT%\\%NAME%"

View File

@ -13,12 +13,39 @@
[CmdletBinding()] [CmdletBinding()]
param( param(
[Alias('h', 'help', '?')]
[switch]$Help,
[switch]$Local, [switch]$Local,
[Parameter(Mandatory = $false, ValueFromRemainingArguments = $true)] [switch]$All,
[Parameter(Mandatory = $false)]
[string[]]$Skills [string[]]$Skills
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/install_codex_skills.ps1 -All"
Write-Host " powershell -File scripts/install_codex_skills.ps1 -Skills style-cleanup,code-review-workflow"
Write-Host ""
Write-Host "Options:"
Write-Host " -Local Install to ./.codex (or CODEX_HOME if set)."
Write-Host " -Skills Comma/space-separated skill names."
Write-Host " -All Install all skills."
Write-Host " -Help Show this help."
Write-Host ""
Write-Host "Env:"
Write-Host " CODEX_HOME Target Codex home (default: ~/.codex)."
exit 0
}
if ($All -and $Skills -and $Skills.Count -gt 0) {
throw "Use either -All or -Skills, not both."
}
if (-not $All -and (-not $Skills -or $Skills.Count -eq 0)) {
throw "Missing -All or -Skills. Use -Help for usage."
}
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
$SkillsSrcRoot = Join-Path $Src "codex/skills" $SkillsSrcRoot = Join-Path $Src "codex/skills"
@ -60,16 +87,19 @@ function Install-One([string]$Name) {
Write-Host "Installed: $Name" Write-Host "Installed: $Name"
} }
if ($Skills -and $Skills.Count -gt 0) { if ($All) {
foreach ($name in $Skills) {
if (-not $name) { continue }
Install-One $name
}
} else {
foreach ($dir in (Get-ChildItem -Path $SkillsSrcRoot -Directory)) { foreach ($dir in (Get-ChildItem -Path $SkillsSrcRoot -Directory)) {
if ($dir.Name.StartsWith(".")) { continue } if ($dir.Name.StartsWith(".")) { continue }
Install-One $dir.Name Install-One $dir.Name
} }
} else {
foreach ($item in $Skills) {
if (-not $item) { continue }
foreach ($part in $item.Split(@(',', ' '), [System.StringSplitOptions]::RemoveEmptyEntries)) {
if (-not $part) { continue }
Install-One $part
}
}
} }
Write-Host "Done. Skills installed to: $SkillsDstRoot" Write-Host "Done. Skills installed to: $SkillsDstRoot"

View File

@ -6,9 +6,9 @@ set -eu
# - Dest: $CODEX_HOME/skills/<skill-name>/ (default CODEX_HOME=~/.codex) # - Dest: $CODEX_HOME/skills/<skill-name>/ (default CODEX_HOME=~/.codex)
# #
# Usage: # Usage:
# sh scripts/install_codex_skills.sh # install all skills # sh scripts/install_codex_skills.sh -all
# sh scripts/install_codex_skills.sh style-cleanup code-review-workflow # sh scripts/install_codex_skills.sh -skills style-cleanup,code-review-workflow
# sh scripts/install_codex_skills.sh --local # install to <cwd>/.codex # sh scripts/install_codex_skills.sh -local -all # install to <cwd>/.codex
# #
# Notes: # Notes:
# - Codex loads skills at startup; restart `codex` after installation. # - Codex loads skills at startup; restart `codex` after installation.
@ -18,10 +18,72 @@ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
SKILLS_SRC_ROOT="$SRC/codex/skills" SKILLS_SRC_ROOT="$SRC/codex/skills"
usage() {
cat <<'EOF' >&2
Usage:
sh scripts/install_codex_skills.sh [options]
sh scripts/install_codex_skills.sh -skills style-cleanup,code-review-workflow
sh scripts/install_codex_skills.sh -all
Options:
-local, -l Install to ./.codex (or CODEX_HOME if set).
-skills LIST Comma/space-separated skill names.
-all Install all skills.
-h, -help Show this help.
Env:
CODEX_HOME Target Codex home (default: ~/.codex).
EOF
}
LOCAL_MODE=0 LOCAL_MODE=0
if [ "${1:-}" = "--local" ] || [ "${1:-}" = "-l" ]; then INSTALL_ALL=0
LOCAL_MODE=1 SKILLS=""
shift while [ $# -gt 0 ]; do
case "$1" in
-local|-l)
LOCAL_MODE=1
shift
;;
-skills)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -skills requires a value." >&2
usage
exit 1
fi
SKILLS="$2"
shift 2
;;
-all)
INSTALL_ALL=1
shift
;;
-h|-help)
usage
exit 0
;;
-*)
echo "ERROR: Unknown option: $1" >&2
usage
exit 1
;;
*)
echo "ERROR: positional args are not supported; use -skills/-all." >&2
usage
exit 1
;;
esac
done
if [ "$INSTALL_ALL" -eq 1 ] && [ -n "$SKILLS" ]; then
echo "ERROR: use either -all or -skills, not both." >&2
usage
exit 1
fi
if [ "$INSTALL_ALL" -eq 0 ] && [ -z "$SKILLS" ]; then
echo "ERROR: -all or -skills is required." >&2
usage
exit 1
fi fi
if [ "$LOCAL_MODE" -eq 1 ]; then if [ "$LOCAL_MODE" -eq 1 ]; then
@ -57,11 +119,7 @@ install_one() {
echo "Installed: $name" echo "Installed: $name"
} }
if [ "$#" -gt 0 ]; then if [ "$INSTALL_ALL" -eq 1 ]; then
for name in "$@"; do
install_one "$name"
done
else
for dir in "$SKILLS_SRC_ROOT"/*; do for dir in "$SKILLS_SRC_ROOT"/*; do
[ -d "$dir" ] || continue [ -d "$dir" ] || continue
name="$(basename -- "$dir")" name="$(basename -- "$dir")"
@ -70,6 +128,15 @@ else
esac esac
install_one "$name" install_one "$name"
done done
else
old_ifs="${IFS}"
IFS=', '
set -- $SKILLS
IFS="${old_ifs}"
for name in "$@"; do
[ -n "$name" ] || continue
install_one "$name"
done
fi fi
echo "Done. Skills installed to: $SKILLS_DST_ROOT" echo "Done. Skills installed to: $SKILLS_DST_ROOT"

View File

@ -7,10 +7,13 @@ rem - Updates <project-root>\.gitattributes (append missing rules by default)
rem Existing targets are backed up before overwrite. rem Existing targets are backed up before overwrite.
rem rem
rem Multi rulesets: rem Multi rulesets:
rem sync_standards.bat tsl cpp rem sync_standards.bat -langs tsl,cpp
rem Notes: rem Notes:
rem - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset). rem - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
if /I "%~1"=="-h" goto show_help
if /I "%~1"=="-help" goto show_help
set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%~dp0"
set "ROOT=%SYNC_ROOT%" set "ROOT=%SYNC_ROOT%"
if "%ROOT%"=="" for /f "delims=" %%R in ('git -C "%SCRIPT_DIR%" rev-parse --show-toplevel 2^>nul') do set "ROOT=%%R" if "%ROOT%"=="" for /f "delims=" %%R in ('git -C "%SCRIPT_DIR%" rev-parse --show-toplevel 2^>nul') do set "ROOT=%%R"
@ -32,20 +35,49 @@ set "GITATTR_DST=%ROOT%\.gitattributes"
set "SYNC_GITATTR_MODE=%SYNC_GITATTR_MODE%" set "SYNC_GITATTR_MODE=%SYNC_GITATTR_MODE%"
if "%SYNC_GITATTR_MODE%"=="" set "SYNC_GITATTR_MODE=append" if "%SYNC_GITATTR_MODE%"=="" set "SYNC_GITATTR_MODE=append"
:show_help
echo Usage:
echo sync_standards.bat
echo sync_standards.bat -langs tsl,cpp
echo.
echo Options:
echo -langs Comma/space-separated list of languages ^(required^).
echo -h, -help Show this help.
echo.
echo Env:
echo SYNC_ROOT Target project root ^(default: git root^).
echo AGENTS_NS Single ruleset name ^(default: tsl^).
echo SYNC_GITATTR_MODE append^|overwrite^|block^|skip ^(default: append^).
exit /b 0
set "LANG_LIST="
:parse_args
if "%~1"=="" goto args_done
if /I "%~1"=="-h" goto show_help
if /I "%~1"=="-help" goto show_help
if /I "%~1"=="-langs" (
if "%~2"=="" goto missing_langs
set "LANG_LIST=%~2"
shift /1
shift /1
goto parse_args
)
echo ERROR: Unknown option: %~1
exit /b 1
:missing_langs
echo ERROR: -langs requires a value.
exit /b 1
:args_done
if not "%LANG_LIST%"=="" set "LANG_LIST=%LANG_LIST:,= %"
rem Multi rulesets: only on outer invocation. rem Multi rulesets: only on outer invocation.
if "%SYNC_STANDARDS_INNER%"=="" ( if "%SYNC_STANDARDS_INNER%"=="" (
set "LANG_LIST="
if not "%~1"=="" set "LANG_LIST=%*"
if "%LANG_LIST%"=="" ( if "%LANG_LIST%"=="" (
if "%AGENTS_NS%"=="" ( if "%AGENTS_NS%"=="" (
if exist "%ROOT%\.agents" ( echo ERROR: -langs is required.
for /d %%D in ("%ROOT%\.agents\*") do ( exit /b 1
set "CAND=%%~nxD"
if exist "%AGENTS_SRC_ROOT%\!CAND!\" (
if defined LANG_LIST (set "LANG_LIST=!LANG_LIST! !CAND!") else set "LANG_LIST=!CAND!"
)
)
)
) )
) )
if not "%LANG_LIST%"=="" ( if not "%LANG_LIST%"=="" (
@ -57,12 +89,12 @@ if "%SYNC_STANDARDS_INNER%"=="" (
set "SYNC_STANDARDS_INNER=1" set "SYNC_STANDARDS_INNER=1"
set "AGENTS_NS=%%~L" set "AGENTS_NS=%%~L"
set "SYNC_GITATTR_MODE=!SYNC_FIRST!" set "SYNC_GITATTR_MODE=!SYNC_FIRST!"
call "%~f0" call "%~f0" -langs %%~L
) else ( ) else (
set "SYNC_STANDARDS_INNER=1" set "SYNC_STANDARDS_INNER=1"
set "AGENTS_NS=%%~L" set "AGENTS_NS=%%~L"
set "SYNC_GITATTR_MODE=skip" set "SYNC_GITATTR_MODE=skip"
call "%~f0" call "%~f0" -langs %%~L
) )
) )
exit /b 0 exit /b 0

View File

@ -4,6 +4,10 @@
# Existing targets are backed up before overwrite. # Existing targets are backed up before overwrite.
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $false)]
[Alias('h', 'help', '?')]
[switch]$Help,
# Sync multiple rulesets in one run: # Sync multiple rulesets in one run:
# -Langs tsl,cpp # -Langs tsl,cpp
# -Langs @("tsl","cpp") # -Langs @("tsl","cpp")
@ -12,6 +16,21 @@ param(
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/sync_standards.ps1 -Langs tsl,cpp"
Write-Host ""
Write-Host "Options:"
Write-Host " -Langs <list> Comma/space-separated list or array (required)."
Write-Host " -Help Show this help."
Write-Host ""
Write-Host "Env:"
Write-Host " SYNC_ROOT Target project root (default: git root)."
Write-Host " AGENTS_NS Single ruleset name (default: tsl)."
Write-Host " SYNC_GITATTR_MODE append|overwrite|block|skip (default: append)."
exit 0
}
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
@ -31,15 +50,9 @@ if (-not (Test-Path $AgentsSrcRoot)) {
$timestamp = Get-Date -Format "yyyyMMddHHmmss" $timestamp = Get-Date -Format "yyyyMMddHHmmss"
# Auto-detect languages from existing .agents when no args are provided. # Require explicit -Langs on outer invocation unless AGENTS_NS is provided.
if (-not $env:SYNC_STANDARDS_INNER -and (-not $Langs -or $Langs.Count -eq 0) -and -not $env:AGENTS_NS) { if (-not $env:SYNC_STANDARDS_INNER -and (-not $Langs -or $Langs.Count -eq 0) -and -not $env:AGENTS_NS) {
$agentsRoot = Join-Path $Root ".agents" throw "Missing -Langs. Use -Help for usage."
if (Test-Path $agentsRoot) {
$autoLangs = @(Get-ChildItem -Path $agentsRoot -Directory | ForEach-Object { $_.Name } | Where-Object { Test-Path (Join-Path $AgentsSrcRoot $_) })
if ($autoLangs.Count -gt 0) {
$Langs = $autoLangs
}
}
} }
# Multi rulesets: only on the outer invocation. # Multi rulesets: only on the outer invocation.

View File

@ -7,8 +7,7 @@ set -eu
# Existing targets are backed up before overwrite. # Existing targets are backed up before overwrite.
# #
# Multi rulesets: # Multi rulesets:
# sh .../sync_standards.sh tsl cpp # sh .../sync_standards.sh -langs tsl,cpp
# sh .../sync_standards.sh --langs tsl,cpp
# Notes: # Notes:
# - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset). # - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
@ -21,6 +20,53 @@ else
fi fi
ROOT="$(CDPATH= cd -- "$ROOT" && pwd -P)" ROOT="$(CDPATH= cd -- "$ROOT" && pwd -P)"
usage() {
cat <<'EOF' >&2
Usage:
sh scripts/sync_standards.sh -langs tsl
sh scripts/sync_standards.sh -langs tsl,cpp
Options:
-langs L1,L2 Comma/space-separated list of languages (required).
-h, -help Show this help.
Env:
SYNC_ROOT Target project root (default: git root).
AGENTS_NS Single ruleset name (default: tsl).
SYNC_GITATTR_MODE append|overwrite|block|skip (default: append).
EOF
}
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then
usage
exit 0
fi
langs=""
while [ $# -gt 0 ]; do
case "$1" in
-langs)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -langs requires a value." >&2
usage
exit 1
fi
langs="$2"
shift 2
;;
-*)
echo "ERROR: Unknown option: $1" >&2
usage
exit 1
;;
*)
echo "ERROR: positional args are not supported; use -langs." >&2
usage
exit 1
;;
esac
done
AGENTS_SRC_ROOT="$SRC/rulesets" AGENTS_SRC_ROOT="$SRC/rulesets"
GITATTR_SRC="$SRC/.gitattributes" GITATTR_SRC="$SRC/.gitattributes"
@ -40,28 +86,10 @@ fi
# Parse multi rulesets only on the outer invocation. # Parse multi rulesets only on the outer invocation.
if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
langs="" if [ -z "${langs:-}" ] && [ -z "${AGENTS_NS:-}" ]; then
if [ "${1:-}" = "--langs" ]; then echo "ERROR: -langs is required." >&2
langs="${2:-}" usage
shift 2 exit 1
fi
if [ -z "${langs:-}" ] && [ "$#" -gt 0 ]; then
langs="$*"
fi
if [ -z "${langs:-}" ] && [ "$#" -eq 0 ] && [ -z "${AGENTS_NS:-}" ]; then
auto_langs=""
if [ -d "$ROOT/.agents" ]; then
for dir in "$ROOT/.agents"/*; do
[ -d "$dir" ] || continue
ns="$(basename "$dir")"
if [ -d "$AGENTS_SRC_ROOT/$ns" ]; then
auto_langs="${auto_langs:+$auto_langs }$ns"
fi
done
fi
if [ -n "$auto_langs" ]; then
langs="$auto_langs"
fi
fi fi
if [ -n "${langs:-}" ]; then if [ -n "${langs:-}" ]; then
sync_mode_first="${SYNC_GITATTR_MODE:-append}" sync_mode_first="${SYNC_GITATTR_MODE:-append}"
@ -76,9 +104,9 @@ if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
[ -n "$ns" ] || continue [ -n "$ns" ] || continue
if [ "$first" -eq 1 ]; then if [ "$first" -eq 1 ]; then
first=0 first=0
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE="$sync_mode_first" sh "$0" SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE="$sync_mode_first" sh "$0" -langs "$ns"
else else
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE=skip sh "$0" SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE=skip sh "$0" -langs "$ns"
fi fi
done done
exit 0 exit 0

View File

@ -10,9 +10,9 @@ rem Existing targets are NOT overwritten (skip if exists).
rem rem
rem Usage: rem Usage:
rem sync_templates.bat # sync to current git root rem sync_templates.bat # sync to current git root
rem sync_templates.bat <project-root> # sync to specified project rem sync_templates.bat -project-root <path> # sync to specified project
rem sync_templates.bat --force # overwrite existing files rem sync_templates.bat -force # overwrite existing files
rem sync_templates.bat --full # append full framework to existing AGENTS.md rem sync_templates.bat -full # append full framework to existing AGENTS.md
set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI" for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
@ -23,30 +23,41 @@ set "PROJECT_ROOT="
:parse_args :parse_args
if "%~1"=="" goto args_done if "%~1"=="" goto args_done
if /I "%~1"=="--force" ( if /I "%~1"=="-force" (
set "FORCE=1" set "FORCE=1"
shift shift
goto parse_args goto parse_args
) )
if /I "%~1"=="--full" ( if /I "%~1"=="-full" (
set "FULL=1" set "FULL=1"
shift shift
goto parse_args goto parse_args
) )
if /I "%~1"=="-project-root" (
if "%~2"=="" (
echo ERROR: -project-root requires a path.
exit /b 1
)
set "PROJECT_ROOT=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="-h" goto show_help if /I "%~1"=="-h" goto show_help
if /I "%~1"=="--help" goto show_help if /I "%~1"=="-help" goto show_help
set "PROJECT_ROOT=%~1" echo ERROR: positional args are not supported. Use -project-root.
shift exit /b 1
goto parse_args
:show_help :show_help
echo Usage: echo Usage:
echo sync_templates.bat [options] [project-root] echo sync_templates.bat [options]
echo sync_templates.bat -project-root ^<path^>
echo. echo.
echo Options: echo Options:
echo --force Overwrite existing files echo -project-root PATH Target project root ^(default: git root^)
echo --full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md echo -force Overwrite existing files
echo -h, --help Show this help echo -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md
echo -h, -help Show this help
exit /b 0 exit /b 0
:args_done :args_done
@ -89,7 +100,7 @@ set "MEMORY_BANK_DST=%PROJECT_ROOT%\memory-bank"
if exist "%MEMORY_BANK_SRC%" ( if exist "%MEMORY_BANK_SRC%" (
if exist "%MEMORY_BANK_DST%" ( if exist "%MEMORY_BANK_DST%" (
if "%FORCE%"=="0" ( if "%FORCE%"=="0" (
echo memory-bank/ already exists. Skip. Use --force to overwrite. echo memory-bank/ already exists. Skip. Use -force to overwrite.
goto sync_prompts goto sync_prompts
) )
) )
@ -118,7 +129,7 @@ set "PROMPTS_DST=%PROJECT_ROOT%\docs\prompts"
if exist "%PROMPTS_SRC%" ( if exist "%PROMPTS_SRC%" (
if exist "%PROMPTS_DST%" ( if exist "%PROMPTS_DST%" (
if "%FORCE%"=="0" ( if "%FORCE%"=="0" (
echo docs/prompts/ already exists. Skip. Use --force to overwrite. echo docs/prompts/ already exists. Skip. Use -force to overwrite.
goto sync_agents goto sync_agents
) )
) )
@ -146,7 +157,7 @@ if exist "%PROMPTS_SRC%" (
rem 3. Sync AGENTS.md rem 3. Sync AGENTS.md
set "AGENTS_DST=%PROJECT_ROOT%\AGENTS.md" set "AGENTS_DST=%PROJECT_ROOT%\AGENTS.md"
rem Choose markers based on --full flag rem Choose markers based on -full flag
if "%FULL%"=="1" ( if "%FULL%"=="1" (
set "MARKER_START=<!-- playbook:framework:start -->" set "MARKER_START=<!-- playbook:framework:start -->"
set "MARKER_END=<!-- playbook:framework:end -->" set "MARKER_END=<!-- playbook:framework:end -->"
@ -199,7 +210,7 @@ set "AGENT_RULES_DST=%PROJECT_ROOT%\AGENT_RULES.md"
if exist "%AGENT_RULES_SRC%" ( if exist "%AGENT_RULES_SRC%" (
if exist "%AGENT_RULES_DST%" ( if exist "%AGENT_RULES_DST%" (
if "%FORCE%"=="0" ( if "%FORCE%"=="0" (
echo AGENT_RULES.md already exists. Skip. Use --force to overwrite. echo AGENT_RULES.md already exists. Skip. Use -force to overwrite.
goto sync_todo goto sync_todo
) )
) )

View File

@ -6,7 +6,11 @@
# Existing targets are backed up before overwrite. # Existing targets are backed up before overwrite.
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $false, Position = 0)] [Parameter(Mandatory = $false)]
[Alias('h', 'help', '?')]
[switch]$Help,
[Parameter(Mandatory = $false)]
[string]$ProjectRoot, [string]$ProjectRoot,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@ -26,6 +30,22 @@ param(
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/sync_templates.ps1 [options]"
Write-Host " powershell -File scripts/sync_templates.ps1 -ProjectRoot C:\\path\\to\\project"
Write-Host ""
Write-Host "Options:"
Write-Host " -ProjectRoot PATH Target project root (default: git root)."
Write-Host " -ProjectName NAME Replace {{PROJECT_NAME}} placeholder."
Write-Host " -Date DATE Replace {{DATE}} placeholder (default: today)."
Write-Host " -NoBackup Skip backup of existing files."
Write-Host " -Force Overwrite without prompting."
Write-Host " -Full Append full framework section to AGENTS.md."
Write-Host " -Help Show this help."
exit 0
}
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path

View File

@ -10,14 +10,16 @@ set -eu
# #
# Usage: # Usage:
# sh scripts/sync_templates.sh # sync to current git root # sh scripts/sync_templates.sh # sync to current git root
# sh scripts/sync_templates.sh <project-root> # sync to specified project # sh scripts/sync_templates.sh -project-root /path/to/project
# sh scripts/sync_templates.sh --project-name "MyProject" --date "2026-01-20" # sh scripts/sync_templates.sh -project-root /path/to/project -project-name "MyProject" -date "2026-01-20"
# #
# Options: # Options:
# --project-name NAME Replace {{PROJECT_NAME}} placeholder # -project-root PATH Target project root (default: git root)
# --date DATE Replace {{DATE}} placeholder (default: today) # -project-name NAME Replace {{PROJECT_NAME}} placeholder
# --no-backup Skip backup of existing files # -date DATE Replace {{DATE}} placeholder (default: today)
# --force Overwrite without prompting # -no-backup Skip backup of existing files
# -force Overwrite without prompting
# -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
@ -33,43 +35,61 @@ PROJECT_ROOT=""
# Parse arguments # Parse arguments
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--project-name) -project-root)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -project-root requires a path." >&2
exit 1
fi
PROJECT_ROOT="$2"
shift 2
;;
-project-name)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -project-name requires a value." >&2
exit 1
fi
PROJECT_NAME="$2" PROJECT_NAME="$2"
shift 2 shift 2
;; ;;
--date) -date)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -date requires a value." >&2
exit 1
fi
SYNC_DATE="$2" SYNC_DATE="$2"
shift 2 shift 2
;; ;;
--no-backup) -no-backup)
NO_BACKUP=1 NO_BACKUP=1
shift shift
;; ;;
--force) -force)
FORCE=1 FORCE=1
shift shift
;; ;;
--full) -full)
FULL=1 FULL=1
shift shift
;; ;;
-h|--help) -h|-help)
cat <<'EOF' cat <<'EOF'
Usage: Usage:
sh scripts/sync_templates.sh [options] [project-root] sh scripts/sync_templates.sh [options]
sh scripts/sync_templates.sh -project-root /path/to/project
Options: Options:
--project-name NAME Replace {{PROJECT_NAME}} placeholder -project-root PATH Target project root (default: git root)
--date DATE Replace {{DATE}} placeholder (default: today) -project-name NAME Replace {{PROJECT_NAME}} placeholder
--no-backup Skip backup of existing files -date DATE Replace {{DATE}} placeholder (default: today)
--force Overwrite without prompting -no-backup Skip backup of existing files
--full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md -force Overwrite without prompting
-h, --help Show this help -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md
-h, -help Show this help
Examples: Examples:
sh scripts/sync_templates.sh sh scripts/sync_templates.sh
sh scripts/sync_templates.sh /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project
sh scripts/sync_templates.sh --full /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project -full
EOF EOF
exit 0 exit 0
;; ;;
@ -78,8 +98,8 @@ EOF
exit 1 exit 1
;; ;;
*) *)
PROJECT_ROOT="$1" echo "ERROR: positional args are not supported; use -project-root." >&2
shift exit 1
;; ;;
esac esac
done done
@ -160,7 +180,7 @@ if [ -d "$MEMORY_BANK_SRC" ]; then
MEMORY_BANK_DST="$PROJECT_ROOT/memory-bank" MEMORY_BANK_DST="$PROJECT_ROOT/memory-bank"
if [ -e "$MEMORY_BANK_DST" ] && [ "$FORCE" -eq 0 ]; then if [ -e "$MEMORY_BANK_DST" ] && [ "$FORCE" -eq 0 ]; then
echo "memory-bank/ already exists. Use --force to overwrite." echo "memory-bank/ already exists. Use -force to overwrite."
else else
backup_if_exists "$MEMORY_BANK_DST" backup_if_exists "$MEMORY_BANK_DST"
mkdir -p "$MEMORY_BANK_DST" mkdir -p "$MEMORY_BANK_DST"
@ -185,7 +205,7 @@ if [ -d "$PROMPTS_SRC" ]; then
PROMPTS_DST="$PROJECT_ROOT/docs/prompts" PROMPTS_DST="$PROJECT_ROOT/docs/prompts"
if [ -e "$PROMPTS_DST" ] && [ "$FORCE" -eq 0 ]; then if [ -e "$PROMPTS_DST" ] && [ "$FORCE" -eq 0 ]; then
echo "docs/prompts/ already exists. Use --force to overwrite." echo "docs/prompts/ already exists. Use -force to overwrite."
else else
backup_if_exists "$PROMPTS_DST" backup_if_exists "$PROMPTS_DST"
mkdir -p "$PROJECT_ROOT/docs" mkdir -p "$PROJECT_ROOT/docs"
@ -206,7 +226,7 @@ else
fi fi
# 3. Sync AGENTS.md # 3. Sync AGENTS.md
# Choose markers based on --full flag # Choose markers based on -full flag
if [ "$FULL" -eq 1 ]; then if [ "$FULL" -eq 1 ]; then
MARKER_START="<!-- playbook:framework:start -->" MARKER_START="<!-- playbook:framework:start -->"
MARKER_END="<!-- playbook:framework:end -->" MARKER_END="<!-- playbook:framework:end -->"
@ -283,7 +303,7 @@ if [ -f "$AGENT_RULES_SRC" ]; then
AGENT_RULES_DST="$PROJECT_ROOT/AGENT_RULES.md" AGENT_RULES_DST="$PROJECT_ROOT/AGENT_RULES.md"
if [ -e "$AGENT_RULES_DST" ] && [ "$FORCE" -eq 0 ]; then if [ -e "$AGENT_RULES_DST" ] && [ "$FORCE" -eq 0 ]; then
echo "AGENT_RULES.md already exists. Use --force to overwrite." echo "AGENT_RULES.md already exists. Use -force to overwrite."
else else
backup_if_exists "$AGENT_RULES_DST" backup_if_exists "$AGENT_RULES_DST"
cp "$AGENT_RULES_SRC" "$AGENT_RULES_DST" cp "$AGENT_RULES_SRC" "$AGENT_RULES_DST"
@ -346,4 +366,4 @@ echo ""
echo "Next steps:" echo "Next steps:"
echo " 1. Edit memory-bank/*.md to fill in project-specific content" echo " 1. Edit memory-bank/*.md to fill in project-specific content"
echo " 2. Replace remaining {{PLACEHOLDER}} values" echo " 2. Replace remaining {{PLACEHOLDER}} values"
echo " 3. Run sync_standards.sh to sync .agents/ rules" echo " 3. Run sync_standards.sh -langs <lang> to sync .agents/ rules"

View File

@ -6,55 +6,67 @@ rem then run sync_standards to materialize .agents\<lang>\ and .gitattributes in
rem the target project root. rem the target project root.
rem rem
rem Usage: rem Usage:
rem scripts\vendor_playbook.bat <project-root> (default: tsl) rem scripts\vendor_playbook.bat -project-root <path> (default: tsl)
rem scripts\vendor_playbook.bat <project-root> tsl cpp rem scripts\vendor_playbook.bat -project-root <path> -langs tsl,cpp
rem scripts\vendor_playbook.bat <project-root> --langs tsl,cpp rem scripts\vendor_playbook.bat -project-root <path> -langs tsl,cpp -apply-templates
rem scripts\vendor_playbook.bat <project-root> tsl cpp --apply-templates
rem rem
rem Options: rem Options:
rem --apply-templates Apply CI/lang templates to project root (skip if exists) rem -project-root Target project root (required)
rem -apply-templates Apply CI/lang templates to project root (skip if exists)
rem rem
rem Notes: rem Notes:
rem - Snapshot is written to: <project-root>\docs\standards\playbook\ rem - Snapshot is written to: <project-root>\docs\standards\playbook\
rem - Existing snapshot is backed up before overwrite. rem - Existing snapshot is backed up before overwrite.
rem - With --apply-templates, CI and lang templates are copied to project root. rem - With -apply-templates, CI and lang templates are copied to project root.
set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI" for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
if "%~1"=="" goto Usage if "%~1"=="" goto Usage
if "%~1"=="-h" goto Usage if "%~1"=="-h" goto Usage
if "%~1"=="--help" goto Usage if "%~1"=="-help" goto Usage
set "DEST_ROOT=%~1"
shift /1
set "DEST_ROOT="
set "LANGS=" set "LANGS="
set "APPLY_TEMPLATES=0" set "APPLY_TEMPLATES=0"
rem Parse arguments rem Parse arguments
:parse_args :parse_args
if "%~1"=="" goto args_done if "%~1"=="" goto args_done
if "%~1"=="--langs" ( if "%~1"=="-project-root" (
if "%~2"=="" (
echo ERROR: -project-root requires a path.
exit /b 1
)
set "DEST_ROOT=%~2"
shift /1
shift /1
goto parse_args
)
if "%~1"=="-langs" (
if "%~2"=="" (
echo ERROR: -langs requires a value.
exit /b 1
)
set "LANGS=%~2" set "LANGS=%~2"
shift /1 shift /1
shift /1 shift /1
goto parse_args goto parse_args
) )
if "%~1"=="--apply-templates" ( if "%~1"=="-apply-templates" (
set "APPLY_TEMPLATES=1" set "APPLY_TEMPLATES=1"
shift /1 shift /1
goto parse_args goto parse_args
) )
if "%LANGS%"=="" ( echo ERROR: positional args are not supported. Use -project-root/-langs.
set "LANGS=%~1" exit /b 1
) else (
set "LANGS=%LANGS% %~1"
)
shift /1
goto parse_args
:args_done :args_done
if "%DEST_ROOT%"=="" (
echo ERROR: -project-root is required.
exit /b 1
)
if "%LANGS%"=="" set "LANGS=tsl" if "%LANGS%"=="" set "LANGS=tsl"
set "LANGS=%LANGS:,= %" set "LANGS=%LANGS:,= %"
@ -182,7 +194,7 @@ set "README=%DEST_PREFIX%\\README.md"
>> "%README%" echo 在目标项目根目录执行(多语言一次同步): >> "%README%" echo 在目标项目根目录执行(多语言一次同步):
>> "%README%" echo. >> "%README%" echo.
>> "%README%" echo ```sh >> "%README%" echo ```sh
>> "%README%" echo sh docs/standards/playbook/scripts/sync_standards.sh %LANGS_CSV% >> "%README%" echo sh docs/standards/playbook/scripts/sync_standards.sh -langs %LANGS_CSV%
>> "%README%" echo ``` >> "%README%" echo ```
>> "%README%" echo. >> "%README%" echo.
>> "%README%" echo 查看规范入口: >> "%README%" echo 查看规范入口:
@ -195,7 +207,7 @@ set "README=%DEST_PREFIX%\\README.md"
>> "%README%" echo 安装到本机(需要先在 `~/.codex/config.toml` 启用 skills见 `docs/standards/playbook/SKILLS.md` >> "%README%" echo 安装到本机(需要先在 `~/.codex/config.toml` 启用 skills见 `docs/standards/playbook/SKILLS.md`
>> "%README%" echo. >> "%README%" echo.
>> "%README%" echo ```sh >> "%README%" echo ```sh
>> "%README%" echo sh docs/standards/playbook/scripts/install_codex_skills.sh >> "%README%" echo sh docs/standards/playbook/scripts/install_codex_skills.sh -all
>> "%README%" echo ``` >> "%README%" echo ```
>> "%README%" echo. >> "%README%" echo.
>> "%README%" echo ## CI templates可选 >> "%README%" echo ## CI templates可选
@ -240,7 +252,7 @@ if not exist "%PROJECT_AGENTS_INDEX%" (
set "OLD_SYNC_ROOT=%SYNC_ROOT%" set "OLD_SYNC_ROOT=%SYNC_ROOT%"
set "SYNC_ROOT=%DEST_ROOT_ABS%" set "SYNC_ROOT=%DEST_ROOT_ABS%"
pushd "%DEST_ROOT_ABS%" pushd "%DEST_ROOT_ABS%"
call "%DEST_PREFIX%\\scripts\\sync_standards.bat" %LANGS% call "%DEST_PREFIX%\\scripts\\sync_standards.bat" -langs %LANGS_CSV%
popd popd
set "SYNC_ROOT=%OLD_SYNC_ROOT%" set "SYNC_ROOT=%OLD_SYNC_ROOT%"
@ -356,11 +368,12 @@ exit /b 0
:Usage :Usage
echo Usage: echo Usage:
echo scripts\vendor_playbook.bat ^<project-root^> ^(default: tsl^) echo scripts\vendor_playbook.bat -project-root ^<path^> ^(default: tsl^)
echo scripts\vendor_playbook.bat ^<project-root^> tsl cpp echo scripts\vendor_playbook.bat -project-root ^<path^> -langs tsl,cpp
echo scripts\vendor_playbook.bat ^<project-root^> --langs tsl,cpp echo scripts\vendor_playbook.bat -project-root ^<path^> -langs tsl,cpp -apply-templates
echo scripts\vendor_playbook.bat ^<project-root^> tsl cpp --apply-templates
echo. echo.
echo Options: echo Options:
echo --apply-templates Apply CI/lang templates to project root ^(skip if exists^) echo -project-root Target project root ^(required^)
echo -langs Comma/space-separated list of languages ^(default: tsl^)
echo -apply-templates Apply CI/lang templates to project root ^(skip if exists^)
exit /b 1 exit /b 1

View File

@ -3,9 +3,9 @@
# the target project root. # the target project root.
# #
# Usage: # Usage:
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> # powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path>
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs tsl,cpp # powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs tsl,cpp
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs @("tsl","cpp") -ApplyTemplates # powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs @("tsl","cpp") -ApplyTemplates
# #
# Options: # Options:
# -ApplyTemplates Apply CI/lang templates to project root (skip if exists) # -ApplyTemplates Apply CI/lang templates to project root (skip if exists)
@ -17,8 +17,12 @@
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $false)]
[string]$DestRoot, [Alias('h', 'help', '?')]
[switch]$Help,
[Parameter(Mandatory = $false)]
[string]$ProjectRoot,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string[]]$Langs, [string[]]$Langs,
@ -29,6 +33,24 @@ param(
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path>"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs tsl,cpp"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs @('tsl','cpp') -ApplyTemplates"
Write-Host ""
Write-Host "Options:"
Write-Host " -ProjectRoot Target project root (required)."
Write-Host " -Langs Comma/space-separated list or array (default: tsl)."
Write-Host " -ApplyTemplates Apply CI/lang templates to project root."
Write-Host " -Help Show this help."
exit 0
}
if (-not $ProjectRoot) {
throw "ProjectRoot is required. Use -Help for usage."
}
function Normalize-Langs([string[]]$InputLangs) { function Normalize-Langs([string[]]$InputLangs) {
if (-not $InputLangs -or $InputLangs.Count -eq 0) { return @("tsl") } if (-not $InputLangs -or $InputLangs.Count -eq 0) { return @("tsl") }
@ -55,8 +77,8 @@ foreach ($lang in $Langs) {
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
New-Item -ItemType Directory -Path $DestRoot -Force | Out-Null New-Item -ItemType Directory -Path $ProjectRoot -Force | Out-Null
$DestRootAbs = (Resolve-Path $DestRoot).Path $DestRootAbs = (Resolve-Path $ProjectRoot).Path
$StandardsDir = Join-Path $DestRootAbs "docs/standards" $StandardsDir = Join-Path $DestRootAbs "docs/standards"
$DestPrefix = Join-Path $StandardsDir "playbook" $DestPrefix = Join-Path $StandardsDir "playbook"
@ -185,7 +207,7 @@ if (-not $commit) { $commit = "N/A" }
在目标项目根目录执行多语言一次同步 在目标项目根目录执行多语言一次同步
```sh ```sh
sh docs/standards/playbook/scripts/sync_standards.sh $langsCsv sh docs/standards/playbook/scripts/sync_standards.sh -langs $langsCsv
``` ```
查看规范入口 查看规范入口
@ -198,7 +220,7 @@ sh docs/standards/playbook/scripts/sync_standards.sh $langsCsv
安装到本机需要先在 `~/.codex/config.toml` 启用 skills `docs/standards/playbook/SKILLS.md` 安装到本机需要先在 `~/.codex/config.toml` 启用 skills `docs/standards/playbook/SKILLS.md`
```sh ```sh
sh docs/standards/playbook/scripts/install_codex_skills.sh sh docs/standards/playbook/scripts/install_codex_skills.sh -all
``` ```
## CI templates可选 ## CI templates可选

View File

@ -6,19 +6,20 @@ set -eu
# the target project root. # the target project root.
# #
# Usage: # Usage:
# sh scripts/vendor_playbook.sh <project-root> # default: tsl # sh scripts/vendor_playbook.sh -project-root <path> # default: tsl
# sh scripts/vendor_playbook.sh <project-root> tsl cpp # sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp
# sh scripts/vendor_playbook.sh <project-root> --langs tsl,cpp # sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp -apply-templates
# sh scripts/vendor_playbook.sh <project-root> tsl cpp --apply-templates
# #
# Options: # Options:
# --apply-templates Apply CI/lang templates to project root (skip if exists) # -project-root PATH Target project root (required)
# -langs L1,L2 Comma/space-separated list of languages (default: tsl)
# -apply-templates Apply CI/lang templates to project root (skip if exists)
# #
# Notes: # Notes:
# - Snapshot is written to: <project-root>/docs/standards/playbook/ # - Snapshot is written to: <project-root>/docs/standards/playbook/
# - Existing snapshot is backed up before overwrite. # - Existing snapshot is backed up before overwrite.
# - Ruleset templates from rulesets/ will be copied to snapshot for sync_standards use. # - Ruleset templates from rulesets/ will be copied to snapshot for sync_standards use.
# - With --apply-templates, CI and lang templates are copied to project root. # - With -apply-templates, CI and lang templates are copied to project root.
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
@ -26,41 +27,49 @@ SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
usage() { usage() {
cat <<'EOF' >&2 cat <<'EOF' >&2
Usage: Usage:
sh scripts/vendor_playbook.sh <project-root> # default: tsl sh scripts/vendor_playbook.sh -project-root <path> # default: tsl
sh scripts/vendor_playbook.sh <project-root> tsl cpp sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp
sh scripts/vendor_playbook.sh <project-root> --langs tsl,cpp sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp -apply-templates
sh scripts/vendor_playbook.sh <project-root> tsl cpp --apply-templates
Options: Options:
--apply-templates Apply CI/lang templates to project root (skip if exists) -project-root PATH Target project root (required)
-h, --help Show this help -langs L1,L2 Comma/space-separated list of languages (default: tsl)
-apply-templates Apply CI/lang templates to project root (skip if exists)
-h, -help Show this help
EOF EOF
} }
if [ "$#" -lt 1 ]; then if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then
usage
exit 1
fi
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
usage usage
exit 0 exit 0
fi fi
PROJECT_ROOT="$1" PROJECT_ROOT=""
shift
langs="" langs=""
APPLY_TEMPLATES=0 APPLY_TEMPLATES=0
# Parse arguments # Parse arguments
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--langs) -project-root)
langs="${2:-}" if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
shift 2 || true echo "ERROR: -project-root requires a path." >&2
usage
exit 1
fi
PROJECT_ROOT="$2"
shift 2
;; ;;
--apply-templates) -langs)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -langs requires a value." >&2
usage
exit 1
fi
langs="$2"
shift 2
;;
-apply-templates)
APPLY_TEMPLATES=1 APPLY_TEMPLATES=1
shift shift
;; ;;
@ -69,16 +78,18 @@ while [ $# -gt 0 ]; do
exit 1 exit 1
;; ;;
*) *)
if [ -z "$langs" ]; then echo "ERROR: positional args are not supported; use -project-root/-langs." >&2
langs="$1" exit 1
else
langs="$langs $1"
fi
shift
;; ;;
esac esac
done done
if [ -z "$PROJECT_ROOT" ]; then
echo "ERROR: -project-root is required." >&2
usage
exit 1
fi
if [ -z "${langs:-}" ]; then if [ -z "${langs:-}" ]; then
langs="tsl" langs="tsl"
fi fi
@ -236,7 +247,7 @@ cat >"$DEST_PREFIX/README.md" <<EOF
在目标项目根目录执行(多语言一次同步): 在目标项目根目录执行(多语言一次同步):
\`\`\`sh \`\`\`sh
sh docs/standards/playbook/scripts/sync_standards.sh ${langs_csv} sh docs/standards/playbook/scripts/sync_standards.sh -langs ${langs_csv}
\`\`\` \`\`\`
查看规范入口: 查看规范入口:
@ -249,7 +260,7 @@ sh docs/standards/playbook/scripts/sync_standards.sh ${langs_csv}
安装到本机(需要先在 \`~/.codex/config.toml\` 启用 skills\`docs/standards/playbook/SKILLS.md\` 安装到本机(需要先在 \`~/.codex/config.toml\` 启用 skills\`docs/standards/playbook/SKILLS.md\`
\`\`\`sh \`\`\`sh
sh docs/standards/playbook/scripts/install_codex_skills.sh sh docs/standards/playbook/scripts/install_codex_skills.sh -all
\`\`\` \`\`\`
## CI templates可选 ## CI templates可选
@ -307,7 +318,7 @@ EOF
EOF EOF
fi fi
SYNC_ROOT="$PROJECT_ROOT_ABS" sh "$DEST_PREFIX/scripts/sync_standards.sh" "$@" SYNC_ROOT="$PROJECT_ROOT_ABS" sh "$DEST_PREFIX/scripts/sync_standards.sh" -langs "$langs_csv"
# Apply templates to project root if requested # Apply templates to project root if requested
if [ "$APPLY_TEMPLATES" -eq 1 ]; then if [ "$APPLY_TEMPLATES" -eq 1 ]; then

View File

@ -44,10 +44,10 @@ templates/
```bash ```bash
# 基础部署 # 基础部署
sh scripts/sync_templates.sh /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project
# 追加完整框架到已有 AGENTS.md # 追加完整框架到已有 AGENTS.md
sh scripts/sync_templates.sh --full /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project -full
``` ```
**Windows PowerShell** **Windows PowerShell**
@ -63,8 +63,8 @@ sh scripts/sync_templates.sh --full /path/to/project
**Windows CMD** **Windows CMD**
```cmd ```cmd
scripts\sync_templates.bat C:\path\to\project scripts\sync_templates.bat -project-root C:\path\to\project
scripts\sync_templates.bat --full C:\path\to\project scripts\sync_templates.bat -project-root C:\path\to\project -full
``` ```
### 部署行为 ### 部署行为
@ -72,8 +72,8 @@ scripts\sync_templates.bat --full C:\path\to\project
- **新项目**:创建完整的 AGENTS.md、AGENT_RULES.md、memory-bank/、docs/prompts/ - **新项目**:创建完整的 AGENTS.md、AGENT_RULES.md、memory-bank/、docs/prompts/
- **已有 AGENTS.md** - **已有 AGENTS.md**
- 默认:追加路由链接(`<!-- playbook:templates:start/end -->` - 默认:追加路由链接(`<!-- playbook:templates:start/end -->`
- `--full`:追加完整框架(规则优先级 + 路由 + 新会话开始时) - `-full`:追加完整框架(规则优先级 + 路由 + 新会话开始时)
- **其他文件**:如果已存在则跳过(使用 `--force` 覆盖) - **其他文件**:如果已存在则跳过(使用 `-force` 覆盖)
- **自动创建**TODO.md 和 CONFIRM.md如果不存在 - **自动创建**TODO.md 和 CONFIRM.md如果不存在
- **占位符替换**:自动替换 `{{DATE}}` 为当前日期 - **占位符替换**:自动替换 `{{DATE}}` 为当前日期
@ -157,11 +157,11 @@ project/
| --------------------------------------- | ----------------------- | -------------- | | --------------------------------------- | ----------------------- | -------------- |
| `<!-- playbook:agents:start/end -->` | 语言规则链接 | sync_standards | | `<!-- playbook:agents:start/end -->` | 语言规则链接 | sync_standards |
| `<!-- playbook:templates:start/end -->` | 路由链接(默认追加) | sync_templates | | `<!-- playbook:templates:start/end -->` | 路由链接(默认追加) | sync_templates |
| `<!-- playbook:framework:start/end -->` | 完整框架(--full 追加) | sync_templates | | `<!-- playbook:framework:start/end -->` | 完整框架(-full 追加) | sync_templates |
### ci/、cpp/、python/ ### ci/、cpp/、python/
语言和 CI 配置模板。通过 `vendor_playbook --apply-templates` 部署: 语言和 CI 配置模板。通过 `vendor_playbook -apply-templates` 部署:
| 目录 | 内容 | 部署位置 | | 目录 | 内容 | 部署位置 |
| ----------- | ----------------------------------------- | ---------- | | ----------- | ----------------------------------------- | ---------- |
@ -173,7 +173,7 @@ project/
```bash ```bash
# vendor_playbook 时一并部署 # vendor_playbook 时一并部署
sh scripts/vendor_playbook.sh /path/to/project tsl cpp --apply-templates sh scripts/vendor_playbook.sh -project-root /path/to/project -langs tsl,cpp -apply-templates
``` ```
## 与 playbook 其他部分的关系 ## 与 playbook 其他部分的关系
@ -193,10 +193,10 @@ playbook/
```bash ```bash
# 1. 部署项目架构模板 # 1. 部署项目架构模板
sh scripts/sync_templates.sh /path/to/project sh scripts/sync_templates.sh -project-root /path/to/project
# 2. 部署语言规则 # 2. 部署语言规则
sh scripts/sync_standards.sh tsl # 或其他语言 sh scripts/sync_standards.sh -langs tsl # 或其他语言
# 3. 编辑 memory-bank/*.md 填写项目信息 # 3. 编辑 memory-bank/*.md 填写项目信息

View File

@ -72,9 +72,8 @@ sh check_doc_links.sh
- **基础功能** - **基础功能**
- 脚本存在且可执行 - 脚本存在且可执行
- 无参数时默认同步 tsl已有 `.agents/<lang>/` 则自动识别) - 单语言同步(`-langs tsl`/`-langs cpp`
- 单语言同步tsl/cpp - 多语言同步(`-langs tsl,cpp`
- 多语言同步tsl cpp
- **.gitattributes 同步** - **.gitattributes 同步**
- 默认模式追加缺失规则 - 默认模式追加缺失规则
- 保留现有内容 - 保留现有内容
@ -102,18 +101,18 @@ sh check_doc_links.sh
- **占位符替换** - **占位符替换**
- `{{PROJECT_NAME}}``{{DATE}}` - `{{PROJECT_NAME}}``{{DATE}}`
- **目录覆盖策略** - **目录覆盖策略**
- 无 `--force` 时不覆盖已有目录 - 无 `-force` 时不覆盖已有目录
- `--force` 时覆盖并备份 - `-force` 时覆盖并备份
- **AGENTS.md 更新** - **AGENTS.md 更新**
- `--full` 更新 framework 区块 - `-full` 更新 framework 区块
#### test_vendor_playbook.bats #### test_vendor_playbook.bats
测试 `scripts/vendor_playbook.sh` 脚本的功能: 测试 `scripts/vendor_playbook.sh` 脚本的功能:
- **基础功能** - **基础功能**
- 单语言 vendoring - 单语言 vendoring`-langs tsl`
- 多语言 vendoring - 多语言 vendoring`-langs tsl,cpp`
- **自动同步** - **自动同步**
- 自动执行 sync_standards - 自动执行 sync_standards
- **SOURCE.md 生成** - **SOURCE.md 生成**
@ -145,10 +144,12 @@ sh check_doc_links.sh
- **安装功能** - **安装功能**
- 创建 skills 目录 - 创建 skills 目录
- 复制 skill 目录(包含 `SKILL.md` - 复制 skill 目录(包含 `SKILL.md`
- 支持指定单个 skill 安装 - 支持 `-skills` 指定单个 skill 安装
- 支持 `-all` 安装全部 skills
- 同名目录安装前创建备份 - 同名目录安装前创建备份
- **错误处理** - **错误处理**
- 指定不存在的 skill 报错 - 指定不存在的 skill 报错
- 未传 `-all/-skills` 报错
- **幂等性** - **幂等性**
- 多次安装结果一致 - 多次安装结果一致

View File

@ -49,7 +49,7 @@ first_skill_name() {
[ ! -d "$SKILLS_DST_ROOT" ] [ ! -d "$SKILLS_DST_ROOT" ]
sh "$SCRIPT_PATH" sh "$SCRIPT_PATH" -all
[ -d "$SKILLS_DST_ROOT" ] [ -d "$SKILLS_DST_ROOT" ]
} }
@ -57,7 +57,7 @@ first_skill_name() {
@test "安装 - 复制 skill 目录" { @test "安装 - 复制 skill 目录" {
skip_if_no_skills skip_if_no_skills
sh "$SCRIPT_PATH" sh "$SCRIPT_PATH" -all
SKILL_DIRS=$(find "$SKILLS_DST_ROOT" -mindepth 1 -maxdepth 1 -type d) SKILL_DIRS=$(find "$SKILLS_DST_ROOT" -mindepth 1 -maxdepth 1 -type d)
[ -n "$SKILL_DIRS" ] [ -n "$SKILL_DIRS" ]
@ -73,7 +73,7 @@ first_skill_name() {
SKILL_NAME="$(first_skill_name)" SKILL_NAME="$(first_skill_name)"
[ -n "$SKILL_NAME" ] [ -n "$SKILL_NAME" ]
sh "$SCRIPT_PATH" "$SKILL_NAME" sh "$SCRIPT_PATH" -skills "$SKILL_NAME"
[ -d "$SKILLS_DST_ROOT/$SKILL_NAME" ] [ -d "$SKILLS_DST_ROOT/$SKILL_NAME" ]
COUNT=$(find "$SKILLS_DST_ROOT" -mindepth 1 -maxdepth 1 -type d | wc -l) COUNT=$(find "$SKILLS_DST_ROOT" -mindepth 1 -maxdepth 1 -type d | wc -l)
@ -89,7 +89,7 @@ first_skill_name() {
mkdir -p "$SKILLS_DST_ROOT/$SKILL_NAME" mkdir -p "$SKILLS_DST_ROOT/$SKILL_NAME"
echo "marker" > "$SKILLS_DST_ROOT/$SKILL_NAME/marker.txt" echo "marker" > "$SKILLS_DST_ROOT/$SKILL_NAME/marker.txt"
sh "$SCRIPT_PATH" "$SKILL_NAME" sh "$SCRIPT_PATH" -skills "$SKILL_NAME"
BACKUP_DIRS=$(find "$SKILLS_DST_ROOT" -maxdepth 1 -type d -name "$SKILL_NAME.bak.*") BACKUP_DIRS=$(find "$SKILLS_DST_ROOT" -maxdepth 1 -type d -name "$SKILL_NAME.bak.*")
[ -n "$BACKUP_DIRS" ] [ -n "$BACKUP_DIRS" ]
@ -98,7 +98,7 @@ first_skill_name() {
@test "错误处理 - 指定不存在 skill 报错" { @test "错误处理 - 指定不存在 skill 报错" {
skip_if_no_skills skip_if_no_skills
run sh "$SCRIPT_PATH" nonexistent-skill run sh "$SCRIPT_PATH" -skills nonexistent-skill
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@ -106,10 +106,10 @@ first_skill_name() {
@test "幂等性 - 多次安装结果一致" { @test "幂等性 - 多次安装结果一致" {
skip_if_no_skills skip_if_no_skills
sh "$SCRIPT_PATH" sh "$SCRIPT_PATH" -all
CHECKSUM1=$(find "$SKILLS_DST_ROOT" -type f -name "SKILL.md" ! -path "$SKILLS_DST_ROOT"'/*.bak.*/*' -exec md5sum {} \; | sort | md5sum) CHECKSUM1=$(find "$SKILLS_DST_ROOT" -type f -name "SKILL.md" ! -path "$SKILLS_DST_ROOT"'/*.bak.*/*' -exec md5sum {} \; | sort | md5sum)
sh "$SCRIPT_PATH" sh "$SCRIPT_PATH" -all
CHECKSUM2=$(find "$SKILLS_DST_ROOT" -type f -name "SKILL.md" ! -path "$SKILLS_DST_ROOT"'/*.bak.*/*' -exec md5sum {} \; | sort | md5sum) CHECKSUM2=$(find "$SKILLS_DST_ROOT" -type f -name "SKILL.md" ! -path "$SKILLS_DST_ROOT"'/*.bak.*/*' -exec md5sum {} \; | sort | md5sum)
[ "$CHECKSUM1" = "$CHECKSUM2" ] [ "$CHECKSUM1" = "$CHECKSUM2" ]

View File

@ -35,30 +35,16 @@ teardown() {
[ -f "$SCRIPT_PATH" ] [ -f "$SCRIPT_PATH" ]
} }
@test "sync_standards.sh 无参数时同步 tsl 规则集" { @test "sync_standards.sh - 未传 -langs 报错" {
cd "$TEST_DIR" cd "$TEST_DIR"
sh "$SCRIPT_PATH" run sh "$SCRIPT_PATH"
# 验证输出目录 [ "$status" -ne 0 ]
[ -d ".agents/tsl" ]
[ -f ".agents/tsl/index.md" ]
}
@test "sync_standards.sh 无参数时自动识别已有语言" {
cd "$TEST_DIR"
mkdir -p .agents/cpp
echo "# placeholder" > .agents/cpp/index.md
sh "$SCRIPT_PATH"
[ -d ".agents/cpp" ]
[ -f ".agents/cpp/index.md" ]
[ ! -d ".agents/tsl" ]
} }
@test "sync_standards.sh tsl - 同步 TSL 规则集" { @test "sync_standards.sh tsl - 同步 TSL 规则集" {
cd "$TEST_DIR" cd "$TEST_DIR"
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
# 验证必须文件 # 验证必须文件
[ -d ".agents/tsl" ] [ -d ".agents/tsl" ]
@ -71,7 +57,7 @@ teardown() {
@test "sync_standards.sh cpp - 同步 C++ 规则集" { @test "sync_standards.sh cpp - 同步 C++ 规则集" {
cd "$TEST_DIR" cd "$TEST_DIR"
sh "$SCRIPT_PATH" cpp sh "$SCRIPT_PATH" -langs cpp
# 验证必须文件 # 验证必须文件
[ -d ".agents/cpp" ] [ -d ".agents/cpp" ]
@ -84,7 +70,7 @@ teardown() {
@test "sync_standards.sh tsl cpp - 同步多个规则集" { @test "sync_standards.sh tsl cpp - 同步多个规则集" {
cd "$TEST_DIR" cd "$TEST_DIR"
sh "$SCRIPT_PATH" tsl cpp sh "$SCRIPT_PATH" -langs tsl,cpp
# 验证两个规则集都存在 # 验证两个规则集都存在
[ -d ".agents/tsl" ] [ -d ".agents/tsl" ]
@ -100,7 +86,7 @@ teardown() {
cd "$TEST_DIR" cd "$TEST_DIR"
[ ! -f ".gitattributes" ] [ ! -f ".gitattributes" ]
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
[ -f ".gitattributes" ] [ -f ".gitattributes" ]
grep -q "Added from playbook .gitattributes" .gitattributes grep -q "Added from playbook .gitattributes" .gitattributes
@ -112,7 +98,7 @@ teardown() {
echo "# My custom rules" > .gitattributes echo "# My custom rules" > .gitattributes
echo "*.custom binary" >> .gitattributes echo "*.custom binary" >> .gitattributes
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
grep -q "# My custom rules" .gitattributes grep -q "# My custom rules" .gitattributes
grep -q "*.custom binary" .gitattributes grep -q "*.custom binary" .gitattributes
@ -127,7 +113,7 @@ teardown() {
EOF EOF
export SYNC_GITATTR_MODE=block export SYNC_GITATTR_MODE=block
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
# 验证 block 已更新(不再包含 "Old content" # 验证 block 已更新(不再包含 "Old content"
! grep -q "Old content" .gitattributes ! grep -q "Old content" .gitattributes
@ -141,7 +127,7 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
[ ! -f "AGENTS.md" ] [ ! -f "AGENTS.md" ]
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
[ -f "AGENTS.md" ] [ -f "AGENTS.md" ]
grep -q ".agents/" AGENTS.md grep -q ".agents/" AGENTS.md
@ -151,7 +137,7 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
echo "# My custom AGENTS.md" > AGENTS.md echo "# My custom AGENTS.md" > AGENTS.md
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
grep -q "# My custom AGENTS.md" AGENTS.md grep -q "# My custom AGENTS.md" AGENTS.md
} }
@ -164,7 +150,7 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
echo "# Original content" > .gitattributes echo "# Original content" > .gitattributes
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
# 验证备份文件存在 # 验证备份文件存在
[ -f ".gitattributes.bak."* ] || [ -f ".gitattributes.bak" ] [ -f ".gitattributes.bak."* ] || [ -f ".gitattributes.bak" ]
@ -175,7 +161,7 @@ EOF
mkdir -p .agents/tsl mkdir -p .agents/tsl
echo "# Old index" > .agents/tsl/index.md echo "# Old index" > .agents/tsl/index.md
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
# 验证备份目录存在 # 验证备份目录存在
[ -d ".agents/tsl.bak."* ] || [ -d ".agents/tsl.bak" ] [ -d ".agents/tsl.bak."* ] || [ -d ".agents/tsl.bak" ]
@ -193,7 +179,7 @@ EOF
cp -r "$PLAYBOOK_ROOT/rulesets/python" docs/standards/playbook/rulesets/ cp -r "$PLAYBOOK_ROOT/rulesets/python" docs/standards/playbook/rulesets/
fi fi
sh "$SCRIPT_PATH" tsl cpp sh "$SCRIPT_PATH" -langs tsl,cpp
# 验证规则集不互相覆盖 # 验证规则集不互相覆盖
[ -d ".agents/tsl" ] [ -d ".agents/tsl" ]
@ -211,7 +197,7 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
rm -rf docs/standards/playbook/rulesets rm -rf docs/standards/playbook/rulesets
run sh "$SCRIPT_PATH" tsl run sh "$SCRIPT_PATH" -langs tsl
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@ -219,7 +205,7 @@ EOF
@test "错误处理 - 无效语言参数时报错" { @test "错误处理 - 无效语言参数时报错" {
cd "$TEST_DIR" cd "$TEST_DIR"
run sh "$SCRIPT_PATH" invalid_lang run sh "$SCRIPT_PATH" -langs invalid_lang
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@ -232,7 +218,7 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
export SYNC_GITATTR_MODE=skip export SYNC_GITATTR_MODE=skip
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
[ ! -f ".gitattributes" ] [ ! -f ".gitattributes" ]
} }
@ -242,7 +228,7 @@ EOF
echo "# Custom content" > .gitattributes echo "# Custom content" > .gitattributes
export SYNC_GITATTR_MODE=overwrite export SYNC_GITATTR_MODE=overwrite
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
# 验证自定义内容被覆盖 # 验证自定义内容被覆盖
! grep -q "# Custom content" .gitattributes ! grep -q "# Custom content" .gitattributes
@ -253,7 +239,7 @@ EOF
echo "# Custom rules only" > .gitattributes echo "# Custom rules only" > .gitattributes
export SYNC_GITATTR_MODE=append export SYNC_GITATTR_MODE=append
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
grep -q "Added from playbook .gitattributes" .gitattributes grep -q "Added from playbook .gitattributes" .gitattributes
grep -q "\\*.tsl" .gitattributes grep -q "\\*.tsl" .gitattributes
@ -264,7 +250,7 @@ EOF
cp "$PLAYBOOK_ROOT/.gitattributes" .gitattributes cp "$PLAYBOOK_ROOT/.gitattributes" .gitattributes
export SYNC_GITATTR_MODE=append export SYNC_GITATTR_MODE=append
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
! grep -q "Added from playbook .gitattributes" .gitattributes ! grep -q "Added from playbook .gitattributes" .gitattributes
} }
@ -277,11 +263,11 @@ EOF
cd "$TEST_DIR" cd "$TEST_DIR"
# 第一次同步 # 第一次同步
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
CHECKSUM1=$(find rulesets/tsl -type f -exec md5sum {} \; | sort | md5sum) CHECKSUM1=$(find rulesets/tsl -type f -exec md5sum {} \; | sort | md5sum)
# 第二次同步 # 第二次同步
sh "$SCRIPT_PATH" tsl sh "$SCRIPT_PATH" -langs tsl
CHECKSUM2=$(find rulesets/tsl -type f -exec md5sum {} \; | sort | md5sum) CHECKSUM2=$(find rulesets/tsl -type f -exec md5sum {} \; | sort | md5sum)
[ "$CHECKSUM1" = "$CHECKSUM2" ] [ "$CHECKSUM1" = "$CHECKSUM2" ]

View File

@ -23,7 +23,7 @@ teardown() {
} }
@test "sync_templates.sh - 基础同步与占位符替换" { @test "sync_templates.sh - 基础同步与占位符替换" {
sh "$SCRIPT_PATH" --project-name "DemoProject" --date "2026-02-03" "$TARGET_DIR" sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -project-name "DemoProject" -date "2026-02-03"
[ -d "$TARGET_DIR/memory-bank" ] [ -d "$TARGET_DIR/memory-bank" ]
[ -f "$TARGET_DIR/memory-bank/project-brief.md" ] [ -f "$TARGET_DIR/memory-bank/project-brief.md" ]
@ -39,13 +39,13 @@ teardown() {
[ -z "$(find "$TARGET_DIR" -name '*.template.md' -print -quit)" ] [ -z "$(find "$TARGET_DIR" -name '*.template.md' -print -quit)" ]
} }
@test "sync_templates.sh - 已存在目录不覆盖 (无 --force)" { @test "sync_templates.sh - 已存在目录不覆盖 (无 -force)" {
mkdir -p "$TARGET_DIR/memory-bank" mkdir -p "$TARGET_DIR/memory-bank"
mkdir -p "$TARGET_DIR/docs/prompts" mkdir -p "$TARGET_DIR/docs/prompts"
echo "keep" > "$TARGET_DIR/memory-bank/keep.md" echo "keep" > "$TARGET_DIR/memory-bank/keep.md"
echo "keep" > "$TARGET_DIR/docs/prompts/keep.md" echo "keep" > "$TARGET_DIR/docs/prompts/keep.md"
sh "$SCRIPT_PATH" "$TARGET_DIR" sh "$SCRIPT_PATH" -project-root "$TARGET_DIR"
[ -f "$TARGET_DIR/memory-bank/keep.md" ] [ -f "$TARGET_DIR/memory-bank/keep.md" ]
[ ! -f "$TARGET_DIR/memory-bank/project-brief.md" ] [ ! -f "$TARGET_DIR/memory-bank/project-brief.md" ]
@ -53,11 +53,11 @@ teardown() {
[ ! -f "$TARGET_DIR/docs/prompts/README.md" ] [ ! -f "$TARGET_DIR/docs/prompts/README.md" ]
} }
@test "sync_templates.sh - --force 覆盖并备份" { @test "sync_templates.sh - -force 覆盖并备份" {
mkdir -p "$TARGET_DIR/memory-bank" mkdir -p "$TARGET_DIR/memory-bank"
echo "marker" > "$TARGET_DIR/memory-bank/marker.txt" echo "marker" > "$TARGET_DIR/memory-bank/marker.txt"
sh "$SCRIPT_PATH" --force "$TARGET_DIR" sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -force
[ -f "$TARGET_DIR/memory-bank/project-brief.md" ] [ -f "$TARGET_DIR/memory-bank/project-brief.md" ]
[ ! -f "$TARGET_DIR/memory-bank/marker.txt" ] [ ! -f "$TARGET_DIR/memory-bank/marker.txt" ]
@ -67,7 +67,7 @@ teardown() {
[ -f "$backup_dir/marker.txt" ] [ -f "$backup_dir/marker.txt" ]
} }
@test "sync_templates.sh - --full 更新 framework 区块" { @test "sync_templates.sh - -full 更新 framework 区块" {
cat > "$TARGET_DIR/AGENTS.md" << 'EOF' cat > "$TARGET_DIR/AGENTS.md" << 'EOF'
# Agent Instructions # Agent Instructions
@ -78,7 +78,7 @@ OLD_FRAMEWORK
Footer Footer
EOF EOF
sh "$SCRIPT_PATH" --full "$TARGET_DIR" sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -full
! grep -q "OLD_FRAMEWORK" "$TARGET_DIR/AGENTS.md" ! grep -q "OLD_FRAMEWORK" "$TARGET_DIR/AGENTS.md"
grep -q "<!-- playbook:framework:start -->" "$TARGET_DIR/AGENTS.md" grep -q "<!-- playbook:framework:start -->" "$TARGET_DIR/AGENTS.md"

View File

@ -47,7 +47,7 @@ teardown() {
@test "vendor_playbook.sh - 单语言 vendoring (tsl)" { @test "vendor_playbook.sh - 单语言 vendoring (tsl)" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证快照目录结构 # 验证快照目录结构
[ -d "docs/standards/playbook" ] [ -d "docs/standards/playbook" ]
@ -60,7 +60,7 @@ teardown() {
@test "vendor_playbook.sh - 多语言 vendoring (tsl cpp)" { @test "vendor_playbook.sh - 多语言 vendoring (tsl cpp)" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl cpp sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl,cpp
# 验证包含两种语言的文档 # 验证包含两种语言的文档
[ -d "docs/standards/playbook/docs/tsl" ] [ -d "docs/standards/playbook/docs/tsl" ]
@ -76,7 +76,7 @@ teardown() {
@test "vendor_playbook.sh - 自动执行 sync_standards" { @test "vendor_playbook.sh - 自动执行 sync_standards" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证根目录已同步规则集 # 验证根目录已同步规则集
[ -d ".agents/tsl" ] [ -d ".agents/tsl" ]
@ -87,7 +87,7 @@ teardown() {
@test "vendor_playbook.sh - 多语言自动同步" { @test "vendor_playbook.sh - 多语言自动同步" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl cpp sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl,cpp
# 验证两个规则集都已同步 # 验证两个规则集都已同步
[ -d ".agents/tsl" ] [ -d ".agents/tsl" ]
@ -102,7 +102,7 @@ teardown() {
@test "vendor_playbook.sh - 生成 SOURCE.md" { @test "vendor_playbook.sh - 生成 SOURCE.md" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
[ -f "docs/standards/playbook/SOURCE.md" ] [ -f "docs/standards/playbook/SOURCE.md" ]
grep -q "Source:" docs/standards/playbook/SOURCE.md grep -q "Source:" docs/standards/playbook/SOURCE.md
@ -112,7 +112,7 @@ teardown() {
@test "vendor_playbook.sh - SOURCE.md 包含 commit hash" { @test "vendor_playbook.sh - SOURCE.md 包含 commit hash" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证包含 commit hash40个十六进制字符 # 验证包含 commit hash40个十六进制字符
grep -E "[0-9a-f]{40}" docs/standards/playbook/SOURCE.md grep -E "[0-9a-f]{40}" docs/standards/playbook/SOURCE.md
@ -121,7 +121,7 @@ teardown() {
@test "vendor_playbook.sh - SOURCE.md 包含时间戳" { @test "vendor_playbook.sh - SOURCE.md 包含时间戳" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证包含日期格式 YYYY-MM-DD # 验证包含日期格式 YYYY-MM-DD
grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2}" docs/standards/playbook/SOURCE.md grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2}" docs/standards/playbook/SOURCE.md
@ -134,7 +134,7 @@ teardown() {
@test "裁剪 - 仅包含指定语言的文档" { @test "裁剪 - 仅包含指定语言的文档" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证包含 TSL 文档 # 验证包含 TSL 文档
[ -d "docs/standards/playbook/docs/tsl" ] [ -d "docs/standards/playbook/docs/tsl" ]
@ -148,7 +148,7 @@ teardown() {
@test "裁剪 - 始终包含 common 目录" { @test "裁剪 - 始终包含 common 目录" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
[ -d "docs/standards/playbook/docs/common" ] [ -d "docs/standards/playbook/docs/common" ]
[ -f "docs/standards/playbook/docs/common/commit_message.md" ] [ -f "docs/standards/playbook/docs/common/commit_message.md" ]
@ -157,7 +157,7 @@ teardown() {
@test "裁剪 - 包含对应的模板文件" { @test "裁剪 - 包含对应的模板文件" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" cpp sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs cpp
# 验证包含 C++ 模板 # 验证包含 C++ 模板
[ -d "docs/standards/playbook/templates/cpp" ] [ -d "docs/standards/playbook/templates/cpp" ]
@ -171,15 +171,15 @@ teardown() {
@test "裁剪 - 包含通用 CI 模板" { @test "裁剪 - 包含通用 CI 模板" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
[ -d "docs/standards/playbook/templates/ci" ] [ -d "docs/standards/playbook/templates/ci" ]
} }
@test "vendor_playbook.sh - --apply-templates 应用模板到项目根目录" { @test "vendor_playbook.sh - -apply-templates 应用模板到项目根目录" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" cpp --apply-templates sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs cpp -apply-templates
if [ -f "$PLAYBOOK_ROOT/templates/cpp/.clang-format" ]; then if [ -f "$PLAYBOOK_ROOT/templates/cpp/.clang-format" ]; then
[ -f ".clang-format" ] [ -f ".clang-format" ]
@ -198,13 +198,13 @@ teardown() {
cd "$TARGET_DIR" cd "$TARGET_DIR"
# 首次 vendor # 首次 vendor
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 在快照中添加标记文件 # 在快照中添加标记文件
touch docs/standards/playbook/OLD_MARKER touch docs/standards/playbook/OLD_MARKER
# 再次 vendor # 再次 vendor
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证旧标记不存在(已被覆盖) # 验证旧标记不存在(已被覆盖)
[ ! -f "docs/standards/playbook/OLD_MARKER" ] [ ! -f "docs/standards/playbook/OLD_MARKER" ]
@ -216,7 +216,7 @@ teardown() {
# 确保 docs/standards 不存在 # 确保 docs/standards 不存在
[ ! -d "docs/standards" ] [ ! -d "docs/standards" ]
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
[ -d "docs/standards/playbook" ] [ -d "docs/standards/playbook" ]
} }
@ -231,7 +231,7 @@ teardown() {
missing_dir="$TEST_DIR/missing-project" missing_dir="$TEST_DIR/missing-project"
rm -rf "$missing_dir" rm -rf "$missing_dir"
run sh "$SCRIPT_PATH" "$missing_dir" tsl run sh "$SCRIPT_PATH" -project-root "$missing_dir" -langs tsl
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@ -239,7 +239,7 @@ teardown() {
@test "错误处理 - 无效语言参数时报错" { @test "错误处理 - 无效语言参数时报错" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
run sh "$SCRIPT_PATH" "$TARGET_DIR" invalid_lang run sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs invalid_lang
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
} }
@ -248,7 +248,7 @@ teardown() {
cd "$TARGET_DIR" cd "$TARGET_DIR"
rm -rf .git rm -rf .git
run sh "$SCRIPT_PATH" "$TARGET_DIR" tsl run sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 应该给出警告但不失败 # 应该给出警告但不失败
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -261,7 +261,7 @@ teardown() {
@test "完整性 - 验证所有必要文件已复制" { @test "完整性 - 验证所有必要文件已复制" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证关键文件 # 验证关键文件
[ -f "docs/standards/playbook/README.md" ] [ -f "docs/standards/playbook/README.md" ]
@ -274,10 +274,10 @@ teardown() {
@test "完整性 - 验证脚本可执行性" { @test "完整性 - 验证脚本可执行性" {
cd "$TARGET_DIR" cd "$TARGET_DIR"
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
# 验证同步脚本可执行 # 验证同步脚本可执行
run sh docs/standards/playbook/scripts/sync_standards.sh tsl run sh docs/standards/playbook/scripts/sync_standards.sh -langs tsl
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@ -290,11 +290,11 @@ teardown() {
cd "$TARGET_DIR" cd "$TARGET_DIR"
# 第一次 vendor # 第一次 vendor
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
CHECKSUM1=$(find docs/standards/playbook -type f -name "*.md" ! -name "SOURCE.md" -exec md5sum {} \; | sort | md5sum) CHECKSUM1=$(find docs/standards/playbook -type f -name "*.md" ! -name "SOURCE.md" -exec md5sum {} \; | sort | md5sum)
# 第二次 vendor # 第二次 vendor
sh "$SCRIPT_PATH" "$TARGET_DIR" tsl sh "$SCRIPT_PATH" -project-root "$TARGET_DIR" -langs tsl
CHECKSUM2=$(find docs/standards/playbook -type f -name "*.md" ! -name "SOURCE.md" -exec md5sum {} \; | sort | md5sum) CHECKSUM2=$(find docs/standards/playbook -type f -name "*.md" ! -name "SOURCE.md" -exec md5sum {} \; | sort | md5sum)
[ "$CHECKSUM1" = "$CHECKSUM2" ] [ "$CHECKSUM1" = "$CHECKSUM2" ]