Squashed 'docs/standards/playbook/' changes from b529012..a854534
a854534 ✨ feat(plan_progress): auto-detect env for blocked plans 0d9a8ec 🐛 fix(playbook): honor no_backup for sync 2d401fa ✅ test(templates): update prompts validation e23474e 📝 docs(playbook): update prompts and sync notes 60ff3cd 🐛 fix(playbook): sync templates per file 816f036 ✅ test(playbook): add sync and vendor coverage 625cabb 📝 docs(memory_bank): reformat templates 2554c87 📝 docs(prompts): refresh prompt templates 6774a9d ✨ feat(plan_progress): track plan status in progress.md 73d5c26 🔧 chore(playbook): split sync_templates into sections 278750e ✨ feat(playbook): add plan progress tracking and rules updates 6efd637 🐛 fix(sync): keep agents block blank lines ea00d43 🐛 fix(playbook): support toml without tomllib ab0dd11 📝 docs(playbook): drop docs/plans snapshots 398696c ✨ feat(playbook): merge unified cli d959f80 🎨 style(docs): format markdown b4f712a 🗑️ remove(legacy): drop old scripts and tests 0c4cd0e ✨ feat(actions): add install_skills and format_md 3d1582c ✨ feat(sync): add templates and standards actions 49bbfa1 ✨ feat(vendor): add playbook snapshot generation 8cfcc25 ✨ feat(cli): parse toml config and dispatch actions 05903c3 ✨ feat(cli): add toml config and dispatch order 65d216e ✅ test(cli): add basic playbook cli tests f0bcf54 📝 docs(plans): add unified playbook cli plan 0885309 📝 docs(plans): add unified playbook cli design 3483d8a 🔧 chore(git): ignore .worktrees dir eb75036 🔧 chore(templates): align agent templates and docs efb93f1 📝 docs(playbook): drop todo/confirm mentions 4a85306 🗑️ remove(workflow): drop todo/confirm artifacts 9c5ee9f 🎨 style(markdown): format docs with prettier 5a2925f 🐛 fix(scripts): repair windows script parsing 26a35e0 ✅ test(ci): update required skills list 8df3883 🐛 fix(test): skip external root doc links b067fc1 📦 deps(skills): sync superpowers c03cda0 🔧 chore(ci): sync from origin main 55e05cb 🔧 chore(ci): use superpowers sync script 73c97f3 🔧 chore(ci): centralize superpowers sync 945704f 🔧 chore(ci): add superpowers sync workflow e5d2c93 🗑️ remove(skills): drop duplicate workflows 3ae9708 🐛 fix(ci): update tests for flag-only scripts c44b9aa 🔧 chore(scripts): require flag-driven args e4e1d14 🔧 chore(scripts): unify single-dash options b2eb475 ✅ test(templates): add template coverage fc230b7 🎨 style(markdown): format markdown files 8dc8924 🔧 chore(markdown): add prettier config and usage 2045dd4 ✨ feat(vendor_playbook): add apply-templates option 872d8cf ✨ feat(templates): add sync templates scaffolding 5b1ca45 📝 docs(skills): clarify todo-plan template 054967a ✨ feat(skills): add todo-plan skill cc340f1 🔧 chore(ci): align standards-check workflow template e9de0aa 🔧 chore(ci): drop removed skill check e5dd7d9 🔧 fix(sync): avoid backtick expansion 087b0b9 🔧 chore(sync): align agents block across ps1/bat 9481510 🔧 chore(sync): scope agents block to existing langs b0ca842 🔧 fix(sync): rewrite docs path in agents c98d65c 🔧 chore(sync): rewrite agents docs paths c33611c 🗑️ remove(skills): drop unused skills and update references 2b37860 🎨 style(markdown): format markdown files e3ecd26 📝 docs(tsl): align syntax annotations and examples 37546fe 🐛 fix(playbook): enforce rulesets to agents flow f2df89d 🐛 fix(scripts): include language list in AGENTS.md c0d0737 🐛 fix(playbook): add agents mirror for sync 3b8b99b 🎨 style(markdown): normalize md headings and lists 31f3000 ♻️ refactor(playbook): rename agents template directory to rulesets 11b2bed ✨ feat(markdown): add ruleset and sync support 5b89580 ✅ test(scripts): quiet git init warnings 5822a87 ♻️ refactor(playbook): streamline agents and refresh tsl docs git-subtree-dir: docs/standards/playbook git-subtree-split: a85453439f65b0c0aa05a5bbece773a02216ce76
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem Install Codex skills from this Playbook snapshot into CODEX_HOME.
|
||||
rem - Source: <snapshot>\codex\skills\<skill-name>\
|
||||
rem - Dest: %CODEX_HOME%\skills\<skill-name>\ (default CODEX_HOME=%USERPROFILE%\.codex)
|
||||
rem
|
||||
rem Usage:
|
||||
rem install_codex_skills.bat
|
||||
rem install_codex_skills.bat style-cleanup code-review-workflow
|
||||
rem
|
||||
rem Notes:
|
||||
rem - Codex loads skills at startup; restart `codex` after installation.
|
||||
rem - Existing destination skill dirs are backed up with a random suffix.
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
|
||||
set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills"
|
||||
|
||||
set "CODEX_HOME=%CODEX_HOME%"
|
||||
if "%CODEX_HOME%"=="" set "CODEX_HOME=%USERPROFILE%\\.codex"
|
||||
set "SKILLS_DST_ROOT=%CODEX_HOME%\\skills"
|
||||
|
||||
if not exist "%SKILLS_SRC_ROOT%" (
|
||||
echo ERROR: skills source dir not found: "%SKILLS_SRC_ROOT%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%SKILLS_DST_ROOT%" mkdir "%SKILLS_DST_ROOT%"
|
||||
|
||||
set "HAS_ARGS=0"
|
||||
if not "%~1"=="" set "HAS_ARGS=1"
|
||||
|
||||
if "%HAS_ARGS%"=="1" (
|
||||
for %%S in (%*) do call :InstallOne "%%~S"
|
||||
goto Done
|
||||
)
|
||||
|
||||
for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do (
|
||||
set "NAME=%%~nD"
|
||||
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!"
|
||||
)
|
||||
|
||||
:Done
|
||||
echo Done. Skills installed to: "%SKILLS_DST_ROOT%"
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:InstallOne
|
||||
set "NAME=%~1"
|
||||
set "SRC_DIR=%SKILLS_SRC_ROOT%\\%NAME%"
|
||||
set "DST_DIR=%SKILLS_DST_ROOT%\\%NAME%"
|
||||
|
||||
if not exist "%SRC_DIR%" (
|
||||
echo ERROR: skill not found: %NAME% "%SRC_DIR%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if exist "%DST_DIR%" (
|
||||
set "RAND=%RANDOM%"
|
||||
pushd "%SKILLS_DST_ROOT%"
|
||||
ren "%NAME%" "%NAME%.bak.!RAND!"
|
||||
popd
|
||||
echo Backed up existing skill: %NAME% -> %NAME%.bak.!RAND!
|
||||
)
|
||||
|
||||
xcopy "%SRC_DIR%\\*" "%DST_DIR%\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy skill: %NAME%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Installed: %NAME%
|
||||
exit /b 0
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
# Install Codex skills from this Playbook snapshot into CODEX_HOME.
|
||||
# - Source: <snapshot>\codex\skills\<skill-name>\
|
||||
# - Dest: $env:CODEX_HOME\skills\<skill-name>\ (default CODEX_HOME=$HOME\.codex)
|
||||
#
|
||||
# Usage:
|
||||
# powershell -File scripts/install_codex_skills.ps1
|
||||
# powershell -File scripts/install_codex_skills.ps1 style-cleanup code-review-workflow
|
||||
#
|
||||
# Notes:
|
||||
# - Codex loads skills at startup; restart `codex` after installation.
|
||||
# - Existing destination skill dirs are backed up with a timestamp suffix.
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $false, ValueFromRemainingArguments = $true)]
|
||||
[string[]]$Skills
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
||||
$SkillsSrcRoot = Join-Path $Src "codex/skills"
|
||||
|
||||
if (-not (Test-Path $SkillsSrcRoot)) {
|
||||
throw "Skills source dir not found: $SkillsSrcRoot"
|
||||
}
|
||||
|
||||
$CodexHome = $env:CODEX_HOME
|
||||
if (-not $CodexHome) {
|
||||
$homeDir = $HOME
|
||||
if (-not $homeDir) { $homeDir = $env:USERPROFILE }
|
||||
$CodexHome = (Join-Path $homeDir ".codex")
|
||||
}
|
||||
$SkillsDstRoot = Join-Path $CodexHome "skills"
|
||||
New-Item -ItemType Directory -Path $SkillsDstRoot -Force | Out-Null
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
|
||||
|
||||
function Install-One([string]$Name) {
|
||||
$srcDir = Join-Path $SkillsSrcRoot $Name
|
||||
$dstDir = Join-Path $SkillsDstRoot $Name
|
||||
|
||||
if (-not (Test-Path $srcDir)) {
|
||||
throw "Skill not found: $Name ($srcDir)"
|
||||
}
|
||||
|
||||
if (Test-Path $dstDir) {
|
||||
$bak = Join-Path $SkillsDstRoot "$Name.bak.$timestamp"
|
||||
Move-Item $dstDir $bak
|
||||
Write-Host "Backed up existing skill: $Name -> $(Split-Path -Leaf $bak)"
|
||||
}
|
||||
|
||||
Copy-Item $srcDir $dstDir -Recurse -Force
|
||||
Write-Host "Installed: $Name"
|
||||
}
|
||||
|
||||
if ($Skills -and $Skills.Count -gt 0) {
|
||||
foreach ($name in $Skills) {
|
||||
if (-not $name) { continue }
|
||||
Install-One $name
|
||||
}
|
||||
} else {
|
||||
foreach ($dir in (Get-ChildItem -Path $SkillsSrcRoot -Directory)) {
|
||||
if ($dir.Name.StartsWith(".")) { continue }
|
||||
Install-One $dir.Name
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Done. Skills installed to: $SkillsDstRoot"
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Install Codex skills from this Playbook snapshot into CODEX_HOME.
|
||||
# - Source: <snapshot>/codex/skills/<skill-name>/
|
||||
# - Dest: $CODEX_HOME/skills/<skill-name>/ (default CODEX_HOME=~/.codex)
|
||||
#
|
||||
# Usage:
|
||||
# sh scripts/install_codex_skills.sh # install all skills
|
||||
# sh scripts/install_codex_skills.sh style-cleanup code-review-workflow
|
||||
#
|
||||
# Notes:
|
||||
# - Codex loads skills at startup; restart `codex` after installation.
|
||||
# - Existing destination skill dirs are backed up with a timestamp suffix.
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
|
||||
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
|
||||
SKILLS_SRC_ROOT="$SRC/codex/skills"
|
||||
|
||||
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
|
||||
SKILLS_DST_ROOT="$CODEX_HOME/skills"
|
||||
|
||||
if [ ! -d "$SKILLS_SRC_ROOT" ]; then
|
||||
echo "ERROR: skills source dir not found: $SKILLS_SRC_ROOT" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$SKILLS_DST_ROOT"
|
||||
timestamp="$(date +%Y%m%d%H%M%S 2>/dev/null || echo bak)"
|
||||
|
||||
install_one() {
|
||||
name="$1"
|
||||
src_dir="$SKILLS_SRC_ROOT/$name"
|
||||
dst_dir="$SKILLS_DST_ROOT/$name"
|
||||
|
||||
if [ ! -d "$src_dir" ]; then
|
||||
echo "ERROR: skill not found: $name ($src_dir)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -e "$dst_dir" ]; then
|
||||
mv "$dst_dir" "$SKILLS_DST_ROOT/$name.bak.$timestamp"
|
||||
echo "Backed up existing skill: $name -> $name.bak.$timestamp"
|
||||
fi
|
||||
cp -R "$src_dir" "$dst_dir"
|
||||
echo "Installed: $name"
|
||||
}
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
for name in "$@"; do
|
||||
install_one "$name"
|
||||
done
|
||||
else
|
||||
for dir in "$SKILLS_SRC_ROOT"/*; do
|
||||
[ -d "$dir" ] || continue
|
||||
name="$(basename -- "$dir")"
|
||||
case "$name" in
|
||||
""|.*) continue ;;
|
||||
esac
|
||||
install_one "$name"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Done. Skills installed to: $SKILLS_DST_ROOT"
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
#!/usr/bin/env python3
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
PLAN_STATUS_START = "<!-- plan-status:start -->"
|
||||
PLAN_STATUS_END = "<!-- plan-status:end -->"
|
||||
PLAN_FILE_RE = re.compile(r"^(\d{4}-\d{2}-\d{2})-.+\.md$")
|
||||
PLAN_LINE_RE = re.compile(
|
||||
r"^- \[(?P<check>[ xX])\] `(?P<plan>[^`]+)` (?P<status>done|blocked|pending|in-progress|skipped)(?:: (?P<note>.*))?$"
|
||||
)
|
||||
VALID_STATUSES = {"done", "blocked", "pending", "in-progress", "skipped"}
|
||||
|
||||
|
||||
def usage() -> str:
|
||||
return (
|
||||
"Usage:\n"
|
||||
" python scripts/plan_progress.py select -plans <dir> -progress <file>\n"
|
||||
" python scripts/plan_progress.py record -plan <path> -status <status> -progress <file> [-note <text>]\n"
|
||||
" python scripts/plan_progress.py -h\n"
|
||||
"Options:\n"
|
||||
" -plans DIR\n"
|
||||
" -plan PATH\n"
|
||||
" -status done|blocked|pending|in-progress|skipped\n"
|
||||
" -progress FILE\n"
|
||||
" -note TEXT\n"
|
||||
" -h, -help Show this help.\n"
|
||||
)
|
||||
|
||||
|
||||
def parse_flags(args: list[str]) -> dict[str, str]:
|
||||
flags: dict[str, str] = {}
|
||||
idx = 0
|
||||
while idx < len(args):
|
||||
arg = args[idx]
|
||||
if arg in ("-h", "-help"):
|
||||
raise ValueError("help")
|
||||
if not arg.startswith("-"):
|
||||
raise ValueError(f"unexpected arg: {arg}")
|
||||
if idx + 1 >= len(args):
|
||||
raise ValueError(f"missing value for {arg}")
|
||||
flags[arg] = args[idx + 1]
|
||||
idx += 2
|
||||
return flags
|
||||
|
||||
|
||||
def normalize_plan_key(plan_value: str) -> str:
|
||||
raw = plan_value.strip().replace("\\", "/")
|
||||
raw = raw.lstrip("./")
|
||||
if raw.startswith("docs/plans/"):
|
||||
return raw[len("docs/plans/") :]
|
||||
marker = "/docs/plans/"
|
||||
if marker in raw:
|
||||
return raw.split(marker, 1)[1]
|
||||
return raw
|
||||
|
||||
|
||||
def render_plan_line(plan_key: str, status: str, note: Optional[str]) -> str:
|
||||
checked = "x" if status == "done" else " "
|
||||
if status == "blocked":
|
||||
suffix = "blocked"
|
||||
if note:
|
||||
suffix += f": {note}"
|
||||
elif status == "pending":
|
||||
suffix = "pending"
|
||||
elif status == "in-progress":
|
||||
suffix = "in-progress"
|
||||
elif status == "skipped":
|
||||
suffix = "skipped"
|
||||
if note:
|
||||
suffix += f": {note}"
|
||||
else:
|
||||
suffix = "done"
|
||||
return f"- [{checked}] `{plan_key}` {suffix}"
|
||||
|
||||
|
||||
def normalize_note(note: str) -> str:
|
||||
cleaned = note.replace("\n", " ").replace("\r", " ").replace("`", "'").strip()
|
||||
return cleaned
|
||||
|
||||
|
||||
def list_plan_files(plans_dir: Path) -> list[str]:
|
||||
entries: list[str] = []
|
||||
for path in plans_dir.iterdir():
|
||||
if not path.is_file():
|
||||
continue
|
||||
if not PLAN_FILE_RE.match(path.name):
|
||||
continue
|
||||
try:
|
||||
rel = path.resolve().relative_to(plans_dir.resolve()).as_posix()
|
||||
except ValueError:
|
||||
rel = path.name
|
||||
entries.append(rel)
|
||||
return sorted(entries)
|
||||
|
||||
|
||||
def find_block(lines: list[str]) -> Optional[tuple[int, int]]:
|
||||
start_idx = None
|
||||
for idx, line in enumerate(lines):
|
||||
if line.strip() == PLAN_STATUS_START:
|
||||
start_idx = idx
|
||||
break
|
||||
if start_idx is None:
|
||||
return None
|
||||
for idx in range(start_idx + 1, len(lines)):
|
||||
if lines[idx].strip() == PLAN_STATUS_END:
|
||||
return start_idx, idx
|
||||
return None
|
||||
|
||||
|
||||
def parse_entries(lines: list[str], start_idx: int, end_idx: int) -> list[tuple[str, str, Optional[str], int]]:
|
||||
entries: list[tuple[str, str, Optional[str], int]] = []
|
||||
for idx in range(start_idx + 1, end_idx):
|
||||
line = lines[idx].strip()
|
||||
match = PLAN_LINE_RE.match(line)
|
||||
if not match:
|
||||
continue
|
||||
plan_key = normalize_plan_key(match.group("plan"))
|
||||
status = match.group("status")
|
||||
note = match.group("note")
|
||||
entries.append((plan_key, status, note, idx))
|
||||
return entries
|
||||
|
||||
|
||||
def render_progress_lines(plans: list[str]) -> list[str]:
|
||||
lines = ["# Plan 状态", "", PLAN_STATUS_START]
|
||||
for plan_key in plans:
|
||||
lines.append(render_plan_line(plan_key, "pending", None))
|
||||
lines.append(PLAN_STATUS_END)
|
||||
return lines
|
||||
|
||||
|
||||
ENV_BLOCKED_RE = re.compile(r"^env:([^:]+):(.+)$")
|
||||
|
||||
|
||||
def parse_env_blocked_note(note: Optional[str]) -> Optional[tuple[str, str]]:
|
||||
"""Parse 'env:windows:Task2,Task4' format. Returns (env, tasks) or None."""
|
||||
if not note:
|
||||
return None
|
||||
match = ENV_BLOCKED_RE.match(note)
|
||||
if match:
|
||||
return match.group(1), match.group(2)
|
||||
return None
|
||||
|
||||
|
||||
def detect_env() -> Optional[str]:
|
||||
mapping = {"windows": "windows", "linux": "linux", "darwin": "darwin"}
|
||||
return mapping.get(platform.system().lower())
|
||||
|
||||
|
||||
def select_plan(plans_dir: Path, progress_path: Path) -> tuple[int, str]:
|
||||
if not plans_dir.is_dir():
|
||||
return 2, f"ERROR: plans dir not found: {plans_dir}"
|
||||
plan_keys = list_plan_files(plans_dir)
|
||||
if not plan_keys:
|
||||
return 2, "ERROR: no plan files found"
|
||||
|
||||
progress_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if progress_path.exists():
|
||||
lines = progress_path.read_text(encoding="utf-8").splitlines()
|
||||
else:
|
||||
lines = []
|
||||
|
||||
block = find_block(lines)
|
||||
if not block:
|
||||
lines = render_progress_lines(plan_keys)
|
||||
progress_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
return 0, (plans_dir / plan_keys[0]).as_posix()
|
||||
|
||||
start_idx, end_idx = block
|
||||
entries = parse_entries(lines, start_idx, end_idx)
|
||||
existing = {plan for plan, _, _, _ in entries}
|
||||
missing = [plan for plan in plan_keys if plan not in existing]
|
||||
if missing:
|
||||
insert_lines = [render_plan_line(plan, "pending", None) for plan in missing]
|
||||
lines[end_idx:end_idx] = insert_lines
|
||||
end_idx += len(insert_lines)
|
||||
progress_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
entries = parse_entries(lines, start_idx, end_idx)
|
||||
|
||||
for plan_key, status, note, _ in entries:
|
||||
if status in ("pending", "in-progress"):
|
||||
return 0, (plans_dir / plan_key).as_posix()
|
||||
|
||||
# Check for env-blocked Plans if current environment is detected
|
||||
current_env = detect_env()
|
||||
if current_env:
|
||||
for plan_key, status, note, _ in entries:
|
||||
if status == "blocked":
|
||||
env_info = parse_env_blocked_note(note)
|
||||
if env_info and env_info[0] == current_env:
|
||||
return 0, (plans_dir / plan_key).as_posix()
|
||||
|
||||
return 2, "ERROR: no pending plans"
|
||||
|
||||
|
||||
def record_status(plan: str, status: str, progress_path: Path, note: Optional[str]) -> tuple[int, str]:
|
||||
if status not in VALID_STATUSES:
|
||||
return 2, f"ERROR: invalid status: {status}"
|
||||
if not plan:
|
||||
return 2, "ERROR: plan is required"
|
||||
|
||||
progress_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if progress_path.exists():
|
||||
lines = progress_path.read_text(encoding="utf-8").splitlines()
|
||||
else:
|
||||
lines = []
|
||||
|
||||
plan_key = normalize_plan_key(plan)
|
||||
block = find_block(lines)
|
||||
if not block:
|
||||
lines = render_progress_lines([plan_key])
|
||||
block = find_block(lines)
|
||||
if not block:
|
||||
return 2, "ERROR: failed to create plan status block"
|
||||
|
||||
start_idx, end_idx = block
|
||||
entries = parse_entries(lines, start_idx, end_idx)
|
||||
|
||||
rendered_note = None
|
||||
if status in ("blocked", "skipped") and note:
|
||||
rendered_note = normalize_note(note)
|
||||
|
||||
updated_line = render_plan_line(plan_key, status, rendered_note)
|
||||
updated = False
|
||||
for entry_plan, _, _, idx in entries:
|
||||
if entry_plan == plan_key:
|
||||
lines[idx] = updated_line
|
||||
updated = True
|
||||
break
|
||||
|
||||
if not updated:
|
||||
lines[end_idx:end_idx] = [updated_line]
|
||||
|
||||
progress_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
return 0, updated_line
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
if not argv:
|
||||
print(usage(), file=sys.stderr)
|
||||
return 2
|
||||
if argv[0] in ("-h", "-help"):
|
||||
print(usage())
|
||||
return 0
|
||||
|
||||
mode = argv[0]
|
||||
if mode not in ("select", "record"):
|
||||
print(f"ERROR: unknown mode: {mode}", file=sys.stderr)
|
||||
print(usage(), file=sys.stderr)
|
||||
return 2
|
||||
|
||||
try:
|
||||
flags = parse_flags(argv[1:])
|
||||
except ValueError as exc:
|
||||
if str(exc) == "help":
|
||||
print(usage())
|
||||
return 0
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
print(usage(), file=sys.stderr)
|
||||
return 2
|
||||
|
||||
if mode == "select":
|
||||
plans = flags.get("-plans")
|
||||
progress = flags.get("-progress")
|
||||
if not plans or not progress:
|
||||
print("ERROR: -plans and -progress are required", file=sys.stderr)
|
||||
print(usage(), file=sys.stderr)
|
||||
return 2
|
||||
code, message = select_plan(Path(plans), Path(progress))
|
||||
if code != 0:
|
||||
print(message, file=sys.stderr)
|
||||
return code
|
||||
print(message)
|
||||
return 0
|
||||
|
||||
plan = flags.get("-plan")
|
||||
status = flags.get("-status")
|
||||
progress = flags.get("-progress")
|
||||
note = flags.get("-note")
|
||||
if not plan or not status or not progress:
|
||||
print("ERROR: -plan, -status, and -progress are required", file=sys.stderr)
|
||||
print(usage(), file=sys.stderr)
|
||||
return 2
|
||||
code, message = record_status(plan, status, Path(progress), note)
|
||||
if code != 0:
|
||||
print(message, file=sys.stderr)
|
||||
return code
|
||||
print(message)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
+1201
File diff suppressed because it is too large
Load Diff
@@ -1,324 +0,0 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem Sync standards snapshot to project root.
|
||||
rem - Copies <snapshot>\.agents\<AGENTS_NS> -> <project-root>\.agents\<AGENTS_NS>
|
||||
rem - Updates <project-root>\.gitattributes (append missing rules by default)
|
||||
rem Existing targets are backed up before overwrite.
|
||||
rem
|
||||
rem Multi rulesets:
|
||||
rem sync_standards.bat tsl cpp
|
||||
rem Notes:
|
||||
rem - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
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%"=="" set "ROOT=%cd%"
|
||||
for %%I in ("%ROOT%") do set "ROOT=%%~fI"
|
||||
|
||||
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
|
||||
set "AGENTS_SRC_ROOT=%SRC%\.agents"
|
||||
set "GITATTR_SRC=%SRC%\.gitattributes"
|
||||
set "AGENTS_NS=%AGENTS_NS%"
|
||||
set "GITATTR_DST=%ROOT%\.gitattributes"
|
||||
set "SYNC_GITATTR_MODE=%SYNC_GITATTR_MODE%"
|
||||
if "%SYNC_GITATTR_MODE%"=="" set "SYNC_GITATTR_MODE=append"
|
||||
|
||||
rem Multi rulesets: only on outer invocation.
|
||||
if "%SYNC_STANDARDS_INNER%"=="" (
|
||||
set "LANG_LIST="
|
||||
if not "%~1"=="" set "LANG_LIST=%*"
|
||||
if "%LANG_LIST%"=="" (
|
||||
if "%AGENTS_NS%"=="" (
|
||||
if exist "%ROOT%\.agents" (
|
||||
for /d %%D in ("%ROOT%\.agents\*") do (
|
||||
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%"=="" (
|
||||
set "FIRST=1"
|
||||
set "SYNC_FIRST=%SYNC_GITATTR_MODE%"
|
||||
for %%L in (!LANG_LIST!) do (
|
||||
if "!FIRST!"=="1" (
|
||||
set "FIRST=0"
|
||||
set "SYNC_STANDARDS_INNER=1"
|
||||
set "AGENTS_NS=%%~L"
|
||||
set "SYNC_GITATTR_MODE=!SYNC_FIRST!"
|
||||
call "%~f0"
|
||||
) else (
|
||||
set "SYNC_STANDARDS_INNER=1"
|
||||
set "AGENTS_NS=%%~L"
|
||||
set "SYNC_GITATTR_MODE=skip"
|
||||
call "%~f0"
|
||||
)
|
||||
)
|
||||
exit /b 0
|
||||
)
|
||||
)
|
||||
|
||||
if "%AGENTS_NS%"=="" set "AGENTS_NS=tsl"
|
||||
echo %AGENTS_NS%| findstr /r "[\\/]" >nul && (
|
||||
echo ERROR: invalid AGENTS_NS=%AGENTS_NS%
|
||||
exit /b 1
|
||||
)
|
||||
echo %AGENTS_NS%| findstr /c:".." >nul && (
|
||||
echo ERROR: invalid AGENTS_NS=%AGENTS_NS%
|
||||
exit /b 1
|
||||
)
|
||||
set "AGENTS_ROOT=%ROOT%\.agents"
|
||||
set "AGENTS_DST=%AGENTS_ROOT%\%AGENTS_NS%"
|
||||
|
||||
set "AGENTS_SRC=%AGENTS_SRC_ROOT%\%AGENTS_NS%"
|
||||
if not exist "%AGENTS_SRC%" (
|
||||
rem Backward-compatible fallback: older snapshots used ^<snapshot^>\.agents\* directly.
|
||||
if exist "%AGENTS_SRC_ROOT%\index.md" if exist "%AGENTS_SRC_ROOT%\auth.md" (
|
||||
set "AGENTS_SRC=%AGENTS_SRC_ROOT%"
|
||||
) else (
|
||||
echo ERROR: Standards snapshot not found at "%AGENTS_SRC%".
|
||||
echo Hint: set AGENTS_NS to one of the subdirs under "%AGENTS_SRC_ROOT%" ^(e.g. tsl/cpp^).
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
if not exist "%AGENTS_SRC%" (
|
||||
echo ERROR: Standards snapshot not found at "%AGENTS_SRC%".
|
||||
echo Run: git subtree add --prefix docs/standards/playbook ^<standards-url^> ^<branch^> --squash
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if /I "%SRC%"=="%ROOT%" (
|
||||
echo Skip: snapshot root equals project root.
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if not exist "%AGENTS_ROOT%" mkdir "%AGENTS_ROOT%"
|
||||
|
||||
if exist "%AGENTS_DST%" (
|
||||
set "RAND=%RANDOM%"
|
||||
pushd "%AGENTS_ROOT%"
|
||||
ren "%AGENTS_NS%" "%AGENTS_NS%.bak.!RAND!"
|
||||
popd
|
||||
echo Backed up existing %AGENTS_NS% agents -> %AGENTS_NS%.bak.!RAND!
|
||||
)
|
||||
|
||||
xcopy "%AGENTS_SRC%\\*" "%AGENTS_DST%\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy .agents
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Synced .agents\%AGENTS_NS% from standards.
|
||||
|
||||
if not exist "%AGENTS_ROOT%\index.md" (
|
||||
> "%AGENTS_ROOT%\index.md" echo # .agents(多语言)
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo 本目录用于存放仓库级/语言级的代理规则集。
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo 建议约定:
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `.agents/tsl/`:TSL 相关规则集(由 `sync_standards.*` 同步;适用于 `.tsl`/`.tsf`)
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `.agents/cpp/`:C++ 相关规则集(由 `sync_standards.*` 同步;适用于 C++23/Modules)
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `.agents/python/` 等:其他语言的规则集(按需增加)
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo 规则发生冲突时,建议以“更靠近代码的目录规则更具体”为准。
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo 入口建议从:
|
||||
>> "%AGENTS_ROOT%\index.md" echo.
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `.agents/tsl/index.md`(TSL 规则集入口)
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `.agents/cpp/index.md`(C++ 规则集入口)
|
||||
>> "%AGENTS_ROOT%\index.md" echo - `docs/standards/playbook/docs/`(人类开发规范快照:`tsl/`、`cpp/`、`python/`、`common/`)
|
||||
echo Created .agents\index.md
|
||||
)
|
||||
|
||||
if not exist "%ROOT%\AGENTS.md" (
|
||||
> "%ROOT%\AGENTS.md" echo # Agent Instructions
|
||||
>> "%ROOT%\AGENTS.md" echo.
|
||||
>> "%ROOT%\AGENTS.md" echo 请以 `.agents/` 下的规则为准:
|
||||
>> "%ROOT%\AGENTS.md" echo.
|
||||
>> "%ROOT%\AGENTS.md" echo - 入口:`.agents/index.md`
|
||||
echo Created AGENTS.md
|
||||
)
|
||||
|
||||
:SyncGitAttr
|
||||
if exist "%GITATTR_SRC%" (
|
||||
if /I "%SYNC_GITATTR_MODE%"=="skip" (
|
||||
echo Skip: .gitattributes sync ^(SYNC_GITATTR_MODE=skip^).
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if /I "%SYNC_GITATTR_MODE%"=="overwrite" (
|
||||
for %%I in ("%GITATTR_SRC%") do set "GITATTR_SRC_F=%%~fI"
|
||||
for %%I in ("%GITATTR_DST%") do set "GITATTR_DST_F=%%~fI"
|
||||
if /I "!GITATTR_SRC_F!"=="!GITATTR_DST_F!" (
|
||||
echo Skip: .gitattributes source equals destination.
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if exist "%GITATTR_DST%" (
|
||||
set "RAND=%RANDOM%"
|
||||
set "BAK_NAME=.gitattributes.bak.!RAND!"
|
||||
ren "%GITATTR_DST%" "!BAK_NAME!"
|
||||
echo Backed up existing .gitattributes -> !BAK_NAME!
|
||||
)
|
||||
copy /y "%GITATTR_SRC%" "%GITATTR_DST%" >nul
|
||||
echo Synced .gitattributes from standards ^(overwrite^).
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if /I "%SYNC_GITATTR_MODE%"=="append" (
|
||||
for %%I in ("%GITATTR_SRC%") do set "GITATTR_SRC_F=%%~fI"
|
||||
for %%I in ("%GITATTR_DST%") do set "GITATTR_DST_F=%%~fI"
|
||||
if /I "!GITATTR_SRC_F!"=="!GITATTR_DST_F!" (
|
||||
echo Skip: .gitattributes source equals destination.
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
set "TMP_DST=%TEMP%\\gitattributes.dst.%RANDOM%.tmp"
|
||||
set "TMP_MISS=%TEMP%\\gitattributes.missing.%RANDOM%.tmp"
|
||||
if exist "!TMP_DST!" del /q "!TMP_DST!" >nul 2>nul
|
||||
if exist "!TMP_MISS!" del /q "!TMP_MISS!" >nul 2>nul
|
||||
type nul > "!TMP_DST!"
|
||||
type nul > "!TMP_MISS!"
|
||||
|
||||
if exist "%GITATTR_DST%" (
|
||||
for /f "usebackq delims=" %%L in ("%GITATTR_DST%") do (
|
||||
set "LINE=%%L"
|
||||
for /f "tokens=* delims= " %%A in ("!LINE!") do set "LINE=%%A"
|
||||
if not "!LINE!"=="" (
|
||||
if /I not "!LINE:~0,1!"=="#" (
|
||||
echo(!LINE!>>"!TMP_DST!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
for /f "usebackq delims=" %%L in ("%GITATTR_SRC%") do (
|
||||
set "LINE=%%L"
|
||||
for /f "tokens=* delims= " %%A in ("!LINE!") do set "LINE=%%A"
|
||||
if not "!LINE!"=="" (
|
||||
if /I not "!LINE:~0,1!"=="#" (
|
||||
findstr /x /l /c:"!LINE!" "!TMP_DST!" >nul || (
|
||||
findstr /x /l /c:"!LINE!" "!TMP_MISS!" >nul || echo(!LINE!>>"!TMP_MISS!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
set "MISS_SIZE=0"
|
||||
if exist "!TMP_MISS!" for %%S in ("!TMP_MISS!") do set "MISS_SIZE=%%~zS"
|
||||
if "!MISS_SIZE!"=="0" (
|
||||
del /q "!TMP_DST!" "!TMP_MISS!" >nul 2>nul
|
||||
echo No missing .gitattributes rules to append.
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if exist "%GITATTR_DST%" (
|
||||
set "RAND=%RANDOM%"
|
||||
set "BAK_NAME=.gitattributes.bak.!RAND!"
|
||||
ren "%GITATTR_DST%" "!BAK_NAME!"
|
||||
echo Backed up existing .gitattributes -> !BAK_NAME!
|
||||
set "DST_IN=%ROOT%\\!BAK_NAME!"
|
||||
) else (
|
||||
set "DST_IN="
|
||||
)
|
||||
|
||||
set "TMP_OUT=%TEMP%\\gitattributes.out.%RANDOM%.tmp"
|
||||
if exist "!TMP_OUT!" del /q "!TMP_OUT!" >nul 2>nul
|
||||
|
||||
if not "!DST_IN!"=="" (
|
||||
type "!DST_IN!" > "!TMP_OUT!"
|
||||
for %%S in ("!DST_IN!") do set "DST_SIZE=%%~zS"
|
||||
if not "!DST_SIZE!"=="0" echo.>>"!TMP_OUT!"
|
||||
)
|
||||
|
||||
set "SOURCE_NOTE=%GITATTR_SRC%"
|
||||
>>"!TMP_OUT!" echo # Added from playbook .gitattributes ^(source: !SOURCE_NOTE!^)
|
||||
type "!TMP_MISS!" >> "!TMP_OUT!"
|
||||
|
||||
copy /y "!TMP_OUT!" "%GITATTR_DST%" >nul
|
||||
del /q "!TMP_DST!" "!TMP_MISS!" "!TMP_OUT!" >nul 2>nul
|
||||
echo Appended missing .gitattributes rules from standards.
|
||||
goto AfterGitAttr
|
||||
)
|
||||
|
||||
if /I not "%SYNC_GITATTR_MODE%"=="block" (
|
||||
echo ERROR: invalid SYNC_GITATTR_MODE=%SYNC_GITATTR_MODE% ^(use block^|overwrite^|append^|skip^)
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
rem block mode: maintain a managed block inside the destination file
|
||||
set "BEGIN=# BEGIN playbook .gitattributes"
|
||||
set "END=# END playbook .gitattributes"
|
||||
set "BEGIN_OLD=# BEGIN tsl-playbook .gitattributes"
|
||||
set "END_OLD=# END tsl-playbook .gitattributes"
|
||||
set "TMP_FILE=%TEMP%\\gitattributes.%RANDOM%.tmp"
|
||||
|
||||
if exist "%GITATTR_DST%" (
|
||||
set "RAND=%RANDOM%"
|
||||
set "BAK_NAME=.gitattributes.bak.!RAND!"
|
||||
ren "%GITATTR_DST%" "!BAK_NAME!"
|
||||
echo Backed up existing .gitattributes -> !BAK_NAME!
|
||||
set "DST_IN=%ROOT%\\!BAK_NAME!"
|
||||
) else (
|
||||
set "DST_IN="
|
||||
)
|
||||
|
||||
set "IN_BLOCK=0"
|
||||
set "DONE=0"
|
||||
|
||||
if not "%DST_IN%"=="" (
|
||||
> "!TMP_FILE!" (
|
||||
for /f "usebackq delims=" %%L in ("!DST_IN!") do (
|
||||
set "LINE=%%L"
|
||||
if "!LINE!"=="%BEGIN%" (
|
||||
if "!DONE!"=="0" (
|
||||
echo %BEGIN%
|
||||
type "%GITATTR_SRC%"
|
||||
echo %END%
|
||||
set "DONE=1"
|
||||
)
|
||||
set "IN_BLOCK=1"
|
||||
) else if "!LINE!"=="%BEGIN_OLD%" (
|
||||
if "!DONE!"=="0" (
|
||||
echo %BEGIN%
|
||||
type "%GITATTR_SRC%"
|
||||
echo %END%
|
||||
set "DONE=1"
|
||||
)
|
||||
set "IN_BLOCK=1"
|
||||
) else if "!LINE!"=="%END%" (
|
||||
set "IN_BLOCK=0"
|
||||
) else if "!LINE!"=="%END_OLD%" (
|
||||
set "IN_BLOCK=0"
|
||||
) else (
|
||||
if "!IN_BLOCK!"=="0" echo(!LINE!
|
||||
)
|
||||
)
|
||||
if "!DONE!"=="0" (
|
||||
echo.
|
||||
echo %BEGIN%
|
||||
type "%GITATTR_SRC%"
|
||||
echo %END%
|
||||
)
|
||||
)
|
||||
) else (
|
||||
> "!TMP_FILE!" (
|
||||
echo %BEGIN%
|
||||
type "%GITATTR_SRC%"
|
||||
echo %END%
|
||||
)
|
||||
)
|
||||
|
||||
copy /y "!TMP_FILE!" "%GITATTR_DST%" >nul
|
||||
del /q "!TMP_FILE!" >nul 2>nul
|
||||
echo Updated .gitattributes from standards ^(managed block^).
|
||||
)
|
||||
|
||||
:AfterGitAttr
|
||||
echo Done.
|
||||
endlocal
|
||||
@@ -1,264 +0,0 @@
|
||||
# Sync standards snapshot to project root.
|
||||
# - Copies <snapshot>/.agents/<AGENTS_NS> -> <project-root>/.agents/<AGENTS_NS>
|
||||
# - Updates <project-root>/.gitattributes (append missing rules by default)
|
||||
# Existing targets are backed up before overwrite.
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
# Sync multiple rulesets in one run:
|
||||
# -Langs tsl,cpp
|
||||
# -Langs @("tsl","cpp")
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string[]]$Langs
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
||||
|
||||
$Root = $env:SYNC_ROOT
|
||||
if (-not $Root) {
|
||||
$Root = (git -C $ScriptDir rev-parse --show-toplevel 2>$null)
|
||||
if (-not $Root) { $Root = (Get-Location).Path }
|
||||
}
|
||||
$Root = (Resolve-Path $Root).Path
|
||||
|
||||
$AgentsSrcRoot = Join-Path $Src ".agents"
|
||||
$GitAttrSrc = Join-Path $Src ".gitattributes"
|
||||
|
||||
if (-not (Test-Path $AgentsSrcRoot)) {
|
||||
throw "Standards snapshot not found at $AgentsSrcRoot. Run: git subtree add --prefix docs/standards/playbook <url> <branch> --squash"
|
||||
}
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
|
||||
|
||||
# Auto-detect languages from existing .agents when no args are provided.
|
||||
if (-not $env:SYNC_STANDARDS_INNER -and (-not $Langs -or $Langs.Count -eq 0) -and -not $env:AGENTS_NS) {
|
||||
$agentsRoot = Join-Path $Root ".agents"
|
||||
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.
|
||||
if (-not $env:SYNC_STANDARDS_INNER -and $Langs -and $Langs.Count -gt 0) {
|
||||
$oldInner = $env:SYNC_STANDARDS_INNER
|
||||
$oldAgentsNs = $env:AGENTS_NS
|
||||
$oldMode = $env:SYNC_GITATTR_MODE
|
||||
|
||||
$syncModeFirst = $env:SYNC_GITATTR_MODE
|
||||
if (-not $syncModeFirst) { $syncModeFirst = "append" }
|
||||
|
||||
$first = $true
|
||||
foreach ($ns in $Langs) {
|
||||
if (-not $ns) { continue }
|
||||
|
||||
$env:SYNC_STANDARDS_INNER = "1"
|
||||
$env:AGENTS_NS = $ns
|
||||
if ($first) {
|
||||
$first = $false
|
||||
$env:SYNC_GITATTR_MODE = $syncModeFirst
|
||||
} else {
|
||||
$env:SYNC_GITATTR_MODE = "skip"
|
||||
}
|
||||
|
||||
& $MyInvocation.MyCommand.Path
|
||||
}
|
||||
|
||||
$env:SYNC_STANDARDS_INNER = $oldInner
|
||||
$env:AGENTS_NS = $oldAgentsNs
|
||||
$env:SYNC_GITATTR_MODE = $oldMode
|
||||
exit 0
|
||||
}
|
||||
|
||||
$AgentsNs = $env:AGENTS_NS
|
||||
if (-not $AgentsNs) { $AgentsNs = "tsl" }
|
||||
if ($AgentsNs -match '[\\/]' -or $AgentsNs -match '\.\.') {
|
||||
throw "Invalid AGENTS_NS=$AgentsNs"
|
||||
}
|
||||
$AgentsSrc = Join-Path $AgentsSrcRoot $AgentsNs
|
||||
if (-not (Test-Path $AgentsSrc)) {
|
||||
# Backward-compatible fallback: older snapshots used <snapshot>/.agents/* directly.
|
||||
if ((Test-Path (Join-Path $AgentsSrcRoot "index.md")) -and (Test-Path (Join-Path $AgentsSrcRoot "auth.md"))) {
|
||||
$AgentsSrc = $AgentsSrcRoot
|
||||
} else {
|
||||
throw "Agents ruleset not found: $AgentsSrc (set AGENTS_NS to one of the subdirs under $AgentsSrcRoot, e.g. tsl/cpp)."
|
||||
}
|
||||
}
|
||||
$AgentsRoot = Join-Path $Root ".agents"
|
||||
$AgentsDst = Join-Path $AgentsRoot $AgentsNs
|
||||
|
||||
if ($Src -ieq $Root) {
|
||||
Write-Host "Skip: snapshot root equals project root."
|
||||
Write-Host "Done."
|
||||
exit 0
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $AgentsRoot -Force | Out-Null
|
||||
|
||||
if (Test-Path $AgentsDst) {
|
||||
$bak = (Join-Path $AgentsRoot "$AgentsNs.bak.$timestamp")
|
||||
Move-Item $AgentsDst $bak
|
||||
Write-Host "Backed up existing $AgentsNs agents -> $(Split-Path -Leaf $bak)"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $AgentsDst -Force | Out-Null
|
||||
Copy-Item (Join-Path $AgentsSrc "*") $AgentsDst -Recurse -Force
|
||||
Write-Host "Synced .agents/$AgentsNs from standards."
|
||||
|
||||
$AgentsIndex = Join-Path $AgentsRoot "index.md"
|
||||
if (-not (Test-Path $AgentsIndex)) {
|
||||
@'
|
||||
# .agents(多语言)
|
||||
|
||||
本目录用于存放仓库级/语言级的代理规则集。
|
||||
|
||||
建议约定:
|
||||
|
||||
- `.agents/tsl/`:TSL 相关规则集(由 `sync_standards.*` 同步;适用于 `.tsl`/`.tsf`)
|
||||
- `.agents/cpp/`:C++ 相关规则集(由 `sync_standards.*` 同步;适用于 C++23/Modules)
|
||||
- `.agents/python/` 等:其他语言的规则集(按需增加)
|
||||
|
||||
规则发生冲突时,建议以“更靠近代码的目录规则更具体”为准。
|
||||
|
||||
入口建议从:
|
||||
|
||||
- `.agents/tsl/index.md`(TSL 规则集入口)
|
||||
- `.agents/cpp/index.md`(C++ 规则集入口)
|
||||
- `docs/standards/playbook/docs/`(人类开发规范快照:`tsl/`、`cpp/`、`python/`、`common/`)
|
||||
'@ | Set-Content -Path $AgentsIndex -Encoding UTF8
|
||||
Write-Host "Created .agents/index.md"
|
||||
}
|
||||
|
||||
$AgentsMd = Join-Path $Root "AGENTS.md"
|
||||
if (-not (Test-Path $AgentsMd)) {
|
||||
@'
|
||||
# Agent Instructions
|
||||
|
||||
请以 `.agents/` 下的规则为准:
|
||||
|
||||
- 入口:`.agents/index.md`
|
||||
'@ | Set-Content -Path $AgentsMd -Encoding UTF8
|
||||
Write-Host "Created AGENTS.md"
|
||||
}
|
||||
|
||||
$GitAttrDst = Join-Path $Root ".gitattributes"
|
||||
if (Test-Path $GitAttrSrc) {
|
||||
$mode = $env:SYNC_GITATTR_MODE
|
||||
if (-not $mode) { $mode = "append" }
|
||||
switch ($mode.ToLowerInvariant()) {
|
||||
"skip" {
|
||||
Write-Host "Skip: .gitattributes sync (SYNC_GITATTR_MODE=skip)."
|
||||
break
|
||||
}
|
||||
"overwrite" {
|
||||
if ($GitAttrSrc -ieq $GitAttrDst) {
|
||||
Write-Host "Skip: .gitattributes source equals destination."
|
||||
break
|
||||
}
|
||||
if (Test-Path $GitAttrDst) {
|
||||
$bak = "$GitAttrDst.bak.$timestamp"
|
||||
Move-Item $GitAttrDst $bak
|
||||
Write-Host "Backed up existing .gitattributes -> $bak"
|
||||
}
|
||||
Copy-Item $GitAttrSrc $GitAttrDst -Force
|
||||
Write-Host "Synced .gitattributes from standards (overwrite)."
|
||||
break
|
||||
}
|
||||
"append" {
|
||||
if ($GitAttrSrc -ieq $GitAttrDst) {
|
||||
Write-Host "Skip: .gitattributes source equals destination."
|
||||
break
|
||||
}
|
||||
|
||||
$dstLines = @{}
|
||||
if (Test-Path $GitAttrDst) {
|
||||
Get-Content $GitAttrDst | ForEach-Object {
|
||||
$line = $_.Trim()
|
||||
if ($line -eq "" -or $line.StartsWith("#")) { return }
|
||||
$dstLines[$line] = $true
|
||||
}
|
||||
}
|
||||
|
||||
$missing = New-Object System.Collections.Generic.List[string]
|
||||
Get-Content $GitAttrSrc | ForEach-Object {
|
||||
$line = $_.Trim()
|
||||
if ($line -eq "" -or $line.StartsWith("#")) { return }
|
||||
if (-not $dstLines.ContainsKey($line)) {
|
||||
$dstLines[$line] = $true
|
||||
$missing.Add($line)
|
||||
}
|
||||
}
|
||||
|
||||
if ($missing.Count -eq 0) {
|
||||
Write-Host "No missing .gitattributes rules to append."
|
||||
break
|
||||
}
|
||||
|
||||
$bak = $null
|
||||
if (Test-Path $GitAttrDst) {
|
||||
$bak = "$GitAttrDst.bak.$timestamp"
|
||||
Move-Item $GitAttrDst $bak -Force
|
||||
Write-Host "Backed up existing .gitattributes -> $bak"
|
||||
}
|
||||
|
||||
$sourceNote = $GitAttrSrc
|
||||
$rootPrefix = "$Root\"
|
||||
if ($sourceNote.StartsWith($rootPrefix)) {
|
||||
$sourceNote = $sourceNote.Substring($rootPrefix.Length)
|
||||
}
|
||||
$header = "# Added from playbook .gitattributes (source: $sourceNote)"
|
||||
|
||||
$content = @()
|
||||
if ($bak -and (Test-Path $bak)) {
|
||||
$existing = Get-Content $bak
|
||||
if ($existing.Count -gt 0) {
|
||||
$content += $existing
|
||||
$content += ""
|
||||
}
|
||||
}
|
||||
$content += $header
|
||||
$content += $missing
|
||||
$content | Set-Content -Path $GitAttrDst -Encoding UTF8
|
||||
|
||||
Write-Host "Appended missing .gitattributes rules from standards."
|
||||
break
|
||||
}
|
||||
"block" {
|
||||
$begin = "# BEGIN playbook .gitattributes"
|
||||
$end = "# END playbook .gitattributes"
|
||||
$beginOld = "# BEGIN tsl-playbook .gitattributes"
|
||||
$endOld = "# END tsl-playbook .gitattributes"
|
||||
$src = Get-Content -Path $GitAttrSrc -Raw
|
||||
$block = $begin + "`r`n" + $src.TrimEnd() + "`r`n" + $end + "`r`n"
|
||||
|
||||
$dst = ""
|
||||
if (Test-Path $GitAttrDst) {
|
||||
$bak = "$GitAttrDst.bak.$timestamp"
|
||||
Move-Item $GitAttrDst $bak
|
||||
Write-Host "Backed up existing .gitattributes -> $bak"
|
||||
$dst = Get-Content -Path $bak -Raw
|
||||
}
|
||||
|
||||
$pattern = "(?ms)^(" + [regex]::Escape($begin) + "|" + [regex]::Escape($beginOld) + ")\\R.*?^(" + [regex]::Escape($end) + "|" + [regex]::Escape($endOld) + ")\\R?"
|
||||
if ($dst -and ($dst -match $pattern)) {
|
||||
$new = [regex]::Replace($dst, $pattern, $block)
|
||||
} elseif ($dst) {
|
||||
$new = $dst.TrimEnd() + "`r`n`r`n" + $block
|
||||
} else {
|
||||
$new = $block
|
||||
}
|
||||
|
||||
$new | Set-Content -Path $GitAttrDst -Encoding UTF8
|
||||
Write-Host "Updated .gitattributes from standards (managed block)."
|
||||
break
|
||||
}
|
||||
default {
|
||||
throw "Invalid SYNC_GITATTR_MODE=$mode (use block|overwrite|append|skip)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Done."
|
||||
@@ -1,300 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Sync standards snapshot to project root.
|
||||
# - Copies <snapshot>/.agents/<AGENTS_NS> -> <project-root>/.agents/<AGENTS_NS>
|
||||
# - Updates <project-root>/.gitattributes (append missing rules by default)
|
||||
# Existing targets are backed up before overwrite.
|
||||
#
|
||||
# Multi rulesets:
|
||||
# sh .../sync_standards.sh tsl cpp
|
||||
# sh .../sync_standards.sh --langs tsl,cpp
|
||||
# Notes:
|
||||
# - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
|
||||
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
|
||||
if [ -n "${SYNC_ROOT:-}" ]; then
|
||||
ROOT="$SYNC_ROOT"
|
||||
else
|
||||
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || pwd)"
|
||||
fi
|
||||
ROOT="$(CDPATH= cd -- "$ROOT" && pwd -P)"
|
||||
AGENTS_SRC_ROOT="$SRC/.agents"
|
||||
GITATTR_SRC="$SRC/.gitattributes"
|
||||
|
||||
if [ ! -d "$AGENTS_SRC_ROOT" ]; then
|
||||
echo "ERROR: Standards snapshot not found at $AGENTS_SRC_ROOT" >&2
|
||||
echo "Run: git subtree add --prefix docs/standards/playbook <standards-url> <branch> --squash" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
timestamp="$(date +%Y%m%d%H%M%S 2>/dev/null || echo bak)"
|
||||
|
||||
if [ "$SRC" = "$ROOT" ]; then
|
||||
echo "Skip: snapshot root equals project root."
|
||||
echo "Done."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Parse multi rulesets only on the outer invocation.
|
||||
if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
|
||||
langs=""
|
||||
if [ "${1:-}" = "--langs" ]; then
|
||||
langs="${2:-}"
|
||||
shift 2
|
||||
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
|
||||
if [ -n "${langs:-}" ]; then
|
||||
sync_mode_first="${SYNC_GITATTR_MODE:-append}"
|
||||
|
||||
first=1
|
||||
old_ifs="${IFS}"
|
||||
IFS=', '
|
||||
set -- $langs
|
||||
IFS="${old_ifs}"
|
||||
|
||||
for ns in "$@"; do
|
||||
[ -n "$ns" ] || continue
|
||||
if [ "$first" -eq 1 ]; then
|
||||
first=0
|
||||
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE="$sync_mode_first" sh "$0"
|
||||
else
|
||||
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE=skip sh "$0"
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
: "${AGENTS_NS:=tsl}"
|
||||
case "$AGENTS_NS" in
|
||||
""|*/*|*\\*|*..*)
|
||||
echo "ERROR: invalid AGENTS_NS=$AGENTS_NS" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
AGENTS_SRC="$AGENTS_SRC_ROOT/$AGENTS_NS"
|
||||
if [ ! -d "$AGENTS_SRC" ]; then
|
||||
# Backward-compatible fallback: older snapshots used <snapshot>/.agents/* directly.
|
||||
if [ -f "$AGENTS_SRC_ROOT/index.md" ] && [ -f "$AGENTS_SRC_ROOT/auth.md" ]; then
|
||||
AGENTS_SRC="$AGENTS_SRC_ROOT"
|
||||
else
|
||||
echo "ERROR: agents ruleset not found: $AGENTS_SRC" >&2
|
||||
echo "Hint: set AGENTS_NS to one of the subdirs under $AGENTS_SRC_ROOT (e.g. tsl/cpp)." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
AGENTS_ROOT="$ROOT/.agents"
|
||||
AGENTS_DST="$AGENTS_ROOT/$AGENTS_NS"
|
||||
mkdir -p "$AGENTS_ROOT"
|
||||
|
||||
if [ -e "$AGENTS_DST" ]; then
|
||||
mv "$AGENTS_DST" "$AGENTS_ROOT/$AGENTS_NS.bak.$timestamp"
|
||||
echo "Backed up existing $AGENTS_NS agents -> $AGENTS_NS.bak.$timestamp"
|
||||
fi
|
||||
|
||||
cp -R "$AGENTS_SRC" "$AGENTS_DST"
|
||||
echo "Synced .agents/$AGENTS_NS from standards."
|
||||
|
||||
AGENTS_INDEX="$AGENTS_ROOT/index.md"
|
||||
if [ ! -f "$AGENTS_INDEX" ]; then
|
||||
cat >"$AGENTS_INDEX" <<'EOF'
|
||||
# .agents(多语言)
|
||||
|
||||
本目录用于存放仓库级/语言级的代理规则集。
|
||||
|
||||
建议约定:
|
||||
|
||||
- `.agents/tsl/`:TSL 相关规则集(由 `sync_standards.*` 同步;适用于 `.tsl`/`.tsf`)
|
||||
- `.agents/cpp/`:C++ 相关规则集(由 `sync_standards.*` 同步;适用于 C++23/Modules)
|
||||
- `.agents/python/` 等:其他语言的规则集(按需增加)
|
||||
|
||||
规则发生冲突时,建议以“更靠近代码的目录规则更具体”为准。
|
||||
|
||||
入口建议从:
|
||||
|
||||
- `.agents/tsl/index.md`(TSL 规则集入口)
|
||||
- `.agents/cpp/index.md`(C++ 规则集入口)
|
||||
- `docs/standards/playbook/docs/`(人类开发规范快照:`tsl/`、`cpp/`、`python/`、`common/`)
|
||||
EOF
|
||||
echo "Created .agents/index.md"
|
||||
fi
|
||||
|
||||
AGENTS_MD="$ROOT/AGENTS.md"
|
||||
if [ ! -f "$AGENTS_MD" ]; then
|
||||
cat >"$AGENTS_MD" <<'EOF'
|
||||
# Agent Instructions
|
||||
|
||||
请以 `.agents/` 下的规则为准:
|
||||
|
||||
- 入口:`.agents/index.md`
|
||||
EOF
|
||||
echo "Created AGENTS.md"
|
||||
fi
|
||||
|
||||
echo "Synced agents ruleset to $AGENTS_DST."
|
||||
|
||||
GITATTR_DST="$ROOT/.gitattributes"
|
||||
if [ -f "$GITATTR_SRC" ]; then
|
||||
: "${SYNC_GITATTR_MODE:=append}"
|
||||
case "$SYNC_GITATTR_MODE" in
|
||||
skip)
|
||||
echo "Skip: .gitattributes sync (SYNC_GITATTR_MODE=skip)."
|
||||
;;
|
||||
overwrite)
|
||||
if [ "$(CDPATH= cd -- "$(dirname -- "$GITATTR_SRC")" && pwd -P)/$(basename -- "$GITATTR_SRC")" = "$GITATTR_DST" ]; then
|
||||
echo "Skip: .gitattributes source equals destination."
|
||||
else
|
||||
if [ -e "$GITATTR_DST" ]; then
|
||||
mv "$GITATTR_DST" "$ROOT/.gitattributes.bak.$timestamp"
|
||||
echo "Backed up existing .gitattributes -> .gitattributes.bak.$timestamp"
|
||||
fi
|
||||
cp "$GITATTR_SRC" "$GITATTR_DST"
|
||||
echo "Synced .gitattributes from standards (overwrite)."
|
||||
fi
|
||||
;;
|
||||
append)
|
||||
if [ "$(CDPATH= cd -- "$(dirname -- "$GITATTR_SRC")" && pwd -P)/$(basename -- "$GITATTR_SRC")" = "$GITATTR_DST" ]; then
|
||||
echo "Skip: .gitattributes source equals destination."
|
||||
else
|
||||
missing_tmp="$(mktemp 2>/dev/null || echo "$ROOT/.gitattributes.missing.$timestamp")"
|
||||
if [ -f "$GITATTR_DST" ]; then
|
||||
awk '
|
||||
function norm(line) {
|
||||
gsub(/^[ \t]+|[ \t]+$/, "", line)
|
||||
return line
|
||||
}
|
||||
FNR==NR {
|
||||
line=norm($0)
|
||||
if (line == "" || line ~ /^#/) next
|
||||
seen[line]=1
|
||||
next
|
||||
}
|
||||
{
|
||||
line=norm($0)
|
||||
if (line == "" || line ~ /^#/) next
|
||||
if (!seen[line] && !out[line]++) print line
|
||||
}
|
||||
' "$GITATTR_DST" "$GITATTR_SRC" >"$missing_tmp"
|
||||
else
|
||||
awk '
|
||||
function norm(line) {
|
||||
gsub(/^[ \t]+|[ \t]+$/, "", line)
|
||||
return line
|
||||
}
|
||||
{
|
||||
line=norm($0)
|
||||
if (line == "" || line ~ /^#/) next
|
||||
if (!out[line]++) print line
|
||||
}
|
||||
' "$GITATTR_SRC" >"$missing_tmp"
|
||||
fi
|
||||
|
||||
if [ ! -s "$missing_tmp" ]; then
|
||||
rm -f "$missing_tmp"
|
||||
echo "No missing .gitattributes rules to append."
|
||||
echo "Done."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -e "$GITATTR_DST" ]; then
|
||||
mv "$GITATTR_DST" "$ROOT/.gitattributes.bak.$timestamp"
|
||||
echo "Backed up existing .gitattributes -> .gitattributes.bak.$timestamp"
|
||||
fi
|
||||
|
||||
source_note="$GITATTR_SRC"
|
||||
case "$GITATTR_SRC" in
|
||||
"$ROOT"/*) source_note="${GITATTR_SRC#$ROOT/}" ;;
|
||||
esac
|
||||
header="# Added from playbook .gitattributes (source: $source_note)"
|
||||
|
||||
{
|
||||
if [ -f "$ROOT/.gitattributes.bak.$timestamp" ]; then
|
||||
cat "$ROOT/.gitattributes.bak.$timestamp"
|
||||
if [ -s "$ROOT/.gitattributes.bak.$timestamp" ]; then
|
||||
printf "\n"
|
||||
fi
|
||||
fi
|
||||
printf "%s\n" "$header"
|
||||
cat "$missing_tmp"
|
||||
} >"$GITATTR_DST"
|
||||
rm -f "$missing_tmp"
|
||||
echo "Appended missing .gitattributes rules from standards."
|
||||
fi
|
||||
;;
|
||||
block)
|
||||
begin="# BEGIN playbook .gitattributes"
|
||||
end="# END playbook .gitattributes"
|
||||
begin_old="# BEGIN tsl-playbook .gitattributes"
|
||||
end_old="# END tsl-playbook .gitattributes"
|
||||
|
||||
if [ -e "$GITATTR_DST" ]; then
|
||||
mv "$GITATTR_DST" "$ROOT/.gitattributes.bak.$timestamp"
|
||||
echo "Backed up existing .gitattributes -> .gitattributes.bak.$timestamp"
|
||||
fi
|
||||
|
||||
tmp="${GITATTR_DST}.tmp.${timestamp}"
|
||||
if [ -f "$ROOT/.gitattributes.bak.$timestamp" ]; then
|
||||
src_dst="$ROOT/.gitattributes.bak.$timestamp"
|
||||
else
|
||||
src_dst=""
|
||||
fi
|
||||
|
||||
if [ -n "$src_dst" ]; then
|
||||
awk -v begin="$begin" -v end="$end" -v begin_old="$begin_old" -v end_old="$end_old" -v src="$GITATTR_SRC" '
|
||||
function emit_src() {
|
||||
print begin
|
||||
while ((getline line < src) > 0) print line
|
||||
close(src)
|
||||
print end
|
||||
}
|
||||
BEGIN { in_block=0; done=0 }
|
||||
$0 == begin || $0 == begin_old { in_block=1; if (!done) { emit_src(); done=1 } ; next }
|
||||
$0 == end || $0 == end_old { in_block=0; next }
|
||||
!in_block { print }
|
||||
END {
|
||||
if (!done) {
|
||||
if (NR > 0) print ""
|
||||
emit_src()
|
||||
}
|
||||
}
|
||||
' "$src_dst" >"$tmp"
|
||||
else
|
||||
{
|
||||
printf "%s\n" "$begin"
|
||||
cat "$GITATTR_SRC"
|
||||
printf "\n%s\n" "$end"
|
||||
} >"$tmp"
|
||||
fi
|
||||
|
||||
mv "$tmp" "$GITATTR_DST"
|
||||
echo "Updated .gitattributes from standards (managed block)."
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: invalid SYNC_GITATTR_MODE=$SYNC_GITATTR_MODE (use block|overwrite|append|skip)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
@@ -1,264 +0,0 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem Vendor a trimmed Playbook snapshot into a target project (offline copy),
|
||||
rem then run sync_standards to materialize .agents\<lang>\ and .gitattributes in
|
||||
rem the target project root.
|
||||
rem
|
||||
rem Usage:
|
||||
rem scripts\vendor_playbook.bat <project-root> (default: tsl)
|
||||
rem scripts\vendor_playbook.bat <project-root> tsl cpp
|
||||
rem scripts\vendor_playbook.bat <project-root> --langs tsl,cpp
|
||||
rem
|
||||
rem Notes:
|
||||
rem - Snapshot is written to: <project-root>\docs\standards\playbook\
|
||||
rem - Existing snapshot is backed up before overwrite.
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
|
||||
|
||||
if "%~1"=="" goto Usage
|
||||
if "%~1"=="-h" goto Usage
|
||||
if "%~1"=="--help" goto Usage
|
||||
|
||||
set "DEST_ROOT=%~1"
|
||||
shift /1
|
||||
|
||||
set "LANGS="
|
||||
if "%~1"=="--langs" (
|
||||
set "LANGS=%~2"
|
||||
shift /1
|
||||
shift /1
|
||||
) else (
|
||||
set "LANGS=%1 %2 %3 %4 %5 %6 %7 %8 %9"
|
||||
)
|
||||
|
||||
if "%LANGS%"=="" set "LANGS=tsl"
|
||||
set "LANGS=%LANGS:,= %"
|
||||
|
||||
if not exist "%DEST_ROOT%" mkdir "%DEST_ROOT%"
|
||||
for %%I in ("%DEST_ROOT%") do set "DEST_ROOT_ABS=%%~fI"
|
||||
|
||||
set "STANDARDS_DIR=%DEST_ROOT_ABS%\\docs\\standards"
|
||||
set "DEST_PREFIX=%STANDARDS_DIR%\\playbook"
|
||||
|
||||
if not exist "%STANDARDS_DIR%" mkdir "%STANDARDS_DIR%"
|
||||
|
||||
if exist "%DEST_PREFIX%" (
|
||||
set "RAND=%RANDOM%"
|
||||
pushd "%STANDARDS_DIR%"
|
||||
ren "playbook" "playbook.bak.!RAND!"
|
||||
popd
|
||||
echo Backed up existing snapshot -^> docs\\standards\\playbook.bak.!RAND!
|
||||
)
|
||||
|
||||
if not exist "%DEST_PREFIX%" mkdir "%DEST_PREFIX%"
|
||||
|
||||
copy /y "%SRC%\\.gitattributes" "%DEST_PREFIX%\\.gitattributes" >nul
|
||||
copy /y "%SRC%\\SKILLS.md" "%DEST_PREFIX%\\SKILLS.md" >nul
|
||||
|
||||
xcopy "%SRC%\\scripts\\*" "%DEST_PREFIX%\\scripts\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy scripts
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
xcopy "%SRC%\\codex\\*" "%DEST_PREFIX%\\codex\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy codex
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
xcopy "%SRC%\\docs\\common\\*" "%DEST_PREFIX%\\docs\\common\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy docs\\common
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%DEST_PREFIX%\\.agents" mkdir "%DEST_PREFIX%\\.agents"
|
||||
copy /y "%SRC%\\.agents\\index.md" "%DEST_PREFIX%\\.agents\\index.md" >nul
|
||||
|
||||
if not exist "%DEST_PREFIX%\\templates" mkdir "%DEST_PREFIX%\\templates"
|
||||
|
||||
if exist "%SRC%\\templates\\ci" (
|
||||
xcopy "%SRC%\\templates\\ci\\*" "%DEST_PREFIX%\\templates\\ci\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy templates\\ci
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
set "LANGS_CSV="
|
||||
for %%L in (%LANGS%) do (
|
||||
echo %%~L| findstr /r "[\\/]" >nul && (
|
||||
echo ERROR: invalid lang=%%~L
|
||||
exit /b 1
|
||||
)
|
||||
echo %%~L| findstr /c:".." >nul && (
|
||||
echo ERROR: invalid lang=%%~L
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%SRC%\\docs\\%%~L" (
|
||||
echo ERROR: docs not found for lang=%%~L "%SRC%\\docs\\%%~L"
|
||||
exit /b 1
|
||||
)
|
||||
if not exist "%SRC%\\.agents\\%%~L" (
|
||||
echo ERROR: agents ruleset not found for lang=%%~L "%SRC%\\.agents\\%%~L"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
xcopy "%SRC%\\docs\\%%~L\\*" "%DEST_PREFIX%\\docs\\%%~L\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy docs for lang=%%~L
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
xcopy "%SRC%\\.agents\\%%~L\\*" "%DEST_PREFIX%\\.agents\\%%~L\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy agents for lang=%%~L
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if exist "%SRC%\\templates\\%%~L" (
|
||||
xcopy "%SRC%\\templates\\%%~L\\*" "%DEST_PREFIX%\\templates\\%%~L\\" /e /i /y >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: failed to copy templates for lang=%%~L
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
if "!LANGS_CSV!"=="" (
|
||||
set "LANGS_CSV=%%~L"
|
||||
) else (
|
||||
set "LANGS_CSV=!LANGS_CSV!,%%~L"
|
||||
)
|
||||
)
|
||||
|
||||
set "DOC_INDEX=%DEST_PREFIX%\\docs\\index.md"
|
||||
> "%DOC_INDEX%" echo # 文档导航(Docs Index)
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo 本快照为裁剪版 Playbook(langs: %LANGS_CSV%)。
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo ## 跨语言(common)
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo - 提交信息与版本号:`common/commit_message.md`
|
||||
|
||||
for %%L in (%LANGS%) do call :AppendDocsSection "%%~L"
|
||||
|
||||
set "COMMIT="
|
||||
for /f "delims=" %%H in ('git -C "%SRC%" rev-parse HEAD 2^>nul') do set "COMMIT=%%H"
|
||||
if "%COMMIT%"=="" set "COMMIT=N/A"
|
||||
|
||||
set "README=%DEST_PREFIX%\\README.md"
|
||||
> "%README%" echo # Playbook(裁剪快照)
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo 本目录为从 Playbook vendoring 的裁剪快照(langs: %LANGS_CSV%)。
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo ## 使用
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo 在目标项目根目录执行(多语言一次同步):
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo ```sh
|
||||
>> "%README%" echo sh docs/standards/playbook/scripts/sync_standards.sh %LANGS_CSV%
|
||||
>> "%README%" echo ```
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo 查看规范入口:
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo - `docs/standards/playbook/docs/index.md`
|
||||
>> "%README%" echo - `.agents/index.md`
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo ## Codex skills(可选)
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo 安装到本机(需要先在 `~/.codex/config.toml` 启用 skills;见 `docs/standards/playbook/SKILLS.md`):
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo ```sh
|
||||
>> "%README%" echo sh docs/standards/playbook/scripts/install_codex_skills.sh
|
||||
>> "%README%" echo ```
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo ## CI templates(可选)
|
||||
>> "%README%" echo.
|
||||
>> "%README%" echo 目标项目可复制启用的 CI 示例模板(如 Gitea Actions):`templates/ci/`。
|
||||
|
||||
set "SOURCE=%DEST_PREFIX%\\SOURCE.md"
|
||||
> "%SOURCE%" echo # SOURCE
|
||||
>> "%SOURCE%" echo.
|
||||
>> "%SOURCE%" echo - Source: %SRC%
|
||||
>> "%SOURCE%" echo - Commit: %COMMIT%
|
||||
>> "%SOURCE%" echo - Date: %DATE% %TIME%
|
||||
>> "%SOURCE%" echo - Langs: %LANGS_CSV%
|
||||
>> "%SOURCE%" echo - Generated-by: scripts/vendor_playbook.bat
|
||||
|
||||
echo Vendored snapshot -^> %DEST_PREFIX%
|
||||
|
||||
set "PROJECT_AGENTS_ROOT=%DEST_ROOT_ABS%\\.agents"
|
||||
set "PROJECT_AGENTS_INDEX=%PROJECT_AGENTS_ROOT%\\index.md"
|
||||
if not exist "%PROJECT_AGENTS_ROOT%" mkdir "%PROJECT_AGENTS_ROOT%"
|
||||
if not exist "%PROJECT_AGENTS_INDEX%" (
|
||||
> "%PROJECT_AGENTS_INDEX%" echo # .agents(多语言)
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo.
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo 本目录用于存放仓库级/语言级的代理规则集。
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo.
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo 本项目已启用的规则集:
|
||||
for %%L in (%LANGS%) do (
|
||||
if /I "%%~L"=="tsl" >> "%PROJECT_AGENTS_INDEX%" echo - .agents/tsl/:TSL 相关规则集(适用于 .tsl/.tsf)
|
||||
if /I "%%~L"=="cpp" >> "%PROJECT_AGENTS_INDEX%" echo - .agents/cpp/:C++ 相关规则集(C++23,含 Modules)
|
||||
if /I "%%~L"=="python" >> "%PROJECT_AGENTS_INDEX%" echo - .agents/python/:Python 相关规则集
|
||||
)
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo.
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo 入口建议从:
|
||||
for %%L in (%LANGS%) do >> "%PROJECT_AGENTS_INDEX%" echo - .agents/%%~L/index.md
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo.
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo 标准快照文档入口:
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo.
|
||||
>> "%PROJECT_AGENTS_INDEX%" echo - docs/standards/playbook/docs/index.md
|
||||
)
|
||||
|
||||
set "OLD_SYNC_ROOT=%SYNC_ROOT%"
|
||||
set "SYNC_ROOT=%DEST_ROOT_ABS%"
|
||||
pushd "%DEST_ROOT_ABS%"
|
||||
call "%DEST_PREFIX%\\scripts\\sync_standards.bat" %LANGS%
|
||||
popd
|
||||
set "SYNC_ROOT=%OLD_SYNC_ROOT%"
|
||||
|
||||
echo Done.
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:AppendDocsSection
|
||||
set "LANG=%~1"
|
||||
if /I "%LANG%"=="tsl" (
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo ## TSL(tsl)
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo - 代码风格:`tsl/code_style.md`
|
||||
>> "%DOC_INDEX%" echo - 命名规范:`tsl/naming.md`
|
||||
>> "%DOC_INDEX%" echo - 语法手册:`tsl/syntax_book/index.md`
|
||||
>> "%DOC_INDEX%" echo - 工具链与验证命令(模板):`tsl/toolchain.md`
|
||||
)
|
||||
if /I "%LANG%"=="cpp" (
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo ## C++(cpp)
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo - 代码风格:`cpp/code_style.md`
|
||||
>> "%DOC_INDEX%" echo - 命名规范:`cpp/naming.md`
|
||||
>> "%DOC_INDEX%" echo - 工具链与验证命令(模板):`cpp/toolchain.md`
|
||||
>> "%DOC_INDEX%" echo - 第三方依赖(Conan):`cpp/dependencies_conan.md`
|
||||
>> "%DOC_INDEX%" echo - clangd 配置:`cpp/clangd.md`
|
||||
)
|
||||
if /I "%LANG%"=="python" (
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo ## Python(python)
|
||||
>> "%DOC_INDEX%" echo.
|
||||
>> "%DOC_INDEX%" echo - 代码风格:`python/style_guide.md`
|
||||
>> "%DOC_INDEX%" echo - 工具链:`python/tooling.md`
|
||||
>> "%DOC_INDEX%" echo - 配置清单:`python/configuration.md`
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:Usage
|
||||
echo Usage:
|
||||
echo scripts\vendor_playbook.bat ^<project-root^> ^(default: tsl^)
|
||||
echo scripts\vendor_playbook.bat ^<project-root^> tsl cpp
|
||||
echo scripts\vendor_playbook.bat ^<project-root^> --langs tsl,cpp
|
||||
exit /b 1
|
||||
@@ -1,242 +0,0 @@
|
||||
# Vendor a trimmed Playbook snapshot into a target project (offline copy),
|
||||
# then run sync_standards to materialize .agents\<lang>\ and .gitattributes in
|
||||
# the target project root.
|
||||
#
|
||||
# Usage:
|
||||
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root>
|
||||
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs tsl,cpp
|
||||
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs @("tsl","cpp")
|
||||
#
|
||||
# Notes:
|
||||
# - Snapshot is written to: <project-root>\docs\standards\playbook\
|
||||
# - Existing snapshot is backed up before overwrite.
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$DestRoot,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string[]]$Langs
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Normalize-Langs([string[]]$InputLangs) {
|
||||
if (-not $InputLangs -or $InputLangs.Count -eq 0) { return @("tsl") }
|
||||
|
||||
$result = New-Object System.Collections.Generic.List[string]
|
||||
foreach ($item in $InputLangs) {
|
||||
if (-not $item) { continue }
|
||||
foreach ($part in $item.Split(@(',', ' '), [System.StringSplitOptions]::RemoveEmptyEntries)) {
|
||||
if (-not $part) { continue }
|
||||
$result.Add($part)
|
||||
}
|
||||
}
|
||||
if ($result.Count -eq 0) { return @("tsl") }
|
||||
return $result.ToArray()
|
||||
}
|
||||
|
||||
$Langs = Normalize-Langs $Langs
|
||||
|
||||
foreach ($lang in $Langs) {
|
||||
if ($lang -match '[\\/]' -or $lang -match '\.\.') {
|
||||
throw "Invalid lang=$lang"
|
||||
}
|
||||
}
|
||||
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
||||
|
||||
New-Item -ItemType Directory -Path $DestRoot -Force | Out-Null
|
||||
$DestRootAbs = (Resolve-Path $DestRoot).Path
|
||||
|
||||
$StandardsDir = Join-Path $DestRootAbs "docs/standards"
|
||||
$DestPrefix = Join-Path $StandardsDir "playbook"
|
||||
|
||||
New-Item -ItemType Directory -Path $StandardsDir -Force | Out-Null
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
|
||||
if (Test-Path $DestPrefix) {
|
||||
$bak = Join-Path $StandardsDir "playbook.bak.$timestamp"
|
||||
Move-Item $DestPrefix $bak
|
||||
Write-Host "Backed up existing snapshot -> docs\\standards\\$(Split-Path -Leaf $bak)"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $DestPrefix -Force | Out-Null
|
||||
|
||||
Copy-Item (Join-Path $Src ".gitattributes") (Join-Path $DestPrefix ".gitattributes") -Force
|
||||
Copy-Item (Join-Path $Src "scripts") $DestPrefix -Recurse -Force
|
||||
Copy-Item (Join-Path $Src "codex") $DestPrefix -Recurse -Force
|
||||
Copy-Item (Join-Path $Src "SKILLS.md") (Join-Path $DestPrefix "SKILLS.md") -Force
|
||||
|
||||
$DocsDir = Join-Path $DestPrefix "docs"
|
||||
New-Item -ItemType Directory -Path $DocsDir -Force | Out-Null
|
||||
Copy-Item (Join-Path $Src "docs/common") $DocsDir -Recurse -Force
|
||||
|
||||
$AgentsDir = Join-Path $DestPrefix ".agents"
|
||||
New-Item -ItemType Directory -Path $AgentsDir -Force | Out-Null
|
||||
Copy-Item (Join-Path $Src ".agents/index.md") (Join-Path $AgentsDir "index.md") -Force
|
||||
|
||||
$TemplatesDir = Join-Path $DestPrefix "templates"
|
||||
New-Item -ItemType Directory -Path $TemplatesDir -Force | Out-Null
|
||||
|
||||
$ciTplSrc = Join-Path (Join-Path $Src "templates") "ci"
|
||||
if (Test-Path $ciTplSrc) {
|
||||
Copy-Item $ciTplSrc $TemplatesDir -Recurse -Force
|
||||
}
|
||||
|
||||
foreach ($lang in $Langs) {
|
||||
$docsSrc = Join-Path (Join-Path $Src "docs") $lang
|
||||
if (-not (Test-Path $docsSrc)) { throw "Docs not found for lang=$lang ($docsSrc)" }
|
||||
Copy-Item $docsSrc $DocsDir -Recurse -Force
|
||||
|
||||
$agentsSrc = Join-Path (Join-Path $Src ".agents") $lang
|
||||
if (-not (Test-Path $agentsSrc)) { throw "Agents ruleset not found for lang=$lang ($agentsSrc)" }
|
||||
Copy-Item $agentsSrc $AgentsDir -Recurse -Force
|
||||
|
||||
$tplSrc = Join-Path (Join-Path $Src "templates") $lang
|
||||
if (Test-Path $tplSrc) {
|
||||
Copy-Item $tplSrc $TemplatesDir -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
$langsCsv = ($Langs -join ",")
|
||||
|
||||
$docLines = New-Object System.Collections.Generic.List[string]
|
||||
$docLines.Add("# 文档导航(Docs Index)")
|
||||
$docLines.Add("")
|
||||
$docLines.Add("本快照为裁剪版 Playbook(langs: $langsCsv)。")
|
||||
$docLines.Add("")
|
||||
$docLines.Add("## 跨语言(common)")
|
||||
$docLines.Add("")
|
||||
$docLines.Add('- 提交信息与版本号:`common/commit_message.md`')
|
||||
|
||||
function Append-DocsSection([string]$Lang) {
|
||||
switch ($Lang) {
|
||||
"tsl" {
|
||||
$docLines.Add("")
|
||||
$docLines.Add("## TSL(tsl)")
|
||||
$docLines.Add("")
|
||||
$docLines.Add('- 代码风格:`tsl/code_style.md`')
|
||||
$docLines.Add('- 命名规范:`tsl/naming.md`')
|
||||
$docLines.Add('- 语法手册:`tsl/syntax_book/index.md`')
|
||||
$docLines.Add('- 工具链与验证命令(模板):`tsl/toolchain.md`')
|
||||
break
|
||||
}
|
||||
"cpp" {
|
||||
$docLines.Add("")
|
||||
$docLines.Add("## C++(cpp)")
|
||||
$docLines.Add("")
|
||||
$docLines.Add('- 代码风格:`cpp/code_style.md`')
|
||||
$docLines.Add('- 命名规范:`cpp/naming.md`')
|
||||
$docLines.Add('- 工具链与验证命令(模板):`cpp/toolchain.md`')
|
||||
$docLines.Add('- 第三方依赖(Conan):`cpp/dependencies_conan.md`')
|
||||
$docLines.Add('- clangd 配置:`cpp/clangd.md`')
|
||||
break
|
||||
}
|
||||
"python" {
|
||||
$docLines.Add("")
|
||||
$docLines.Add("## Python(python)")
|
||||
$docLines.Add("")
|
||||
$docLines.Add('- 代码风格:`python/style_guide.md`')
|
||||
$docLines.Add('- 工具链:`python/tooling.md`')
|
||||
$docLines.Add('- 配置清单:`python/configuration.md`')
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($lang in $Langs) {
|
||||
Append-DocsSection $lang
|
||||
}
|
||||
|
||||
($docLines -join "`n") | Set-Content -Path (Join-Path $DocsDir "index.md") -Encoding UTF8
|
||||
|
||||
$commit = ""
|
||||
try {
|
||||
$commit = (git -C $Src rev-parse HEAD 2>$null)
|
||||
} catch {
|
||||
$commit = ""
|
||||
}
|
||||
if (-not $commit) { $commit = "N/A" }
|
||||
|
||||
@"
|
||||
# Playbook(裁剪快照)
|
||||
|
||||
本目录为从 Playbook vendoring 的裁剪快照(langs: $langsCsv)。
|
||||
|
||||
## 使用
|
||||
|
||||
在目标项目根目录执行(多语言一次同步):
|
||||
|
||||
```sh
|
||||
sh docs/standards/playbook/scripts/sync_standards.sh $langsCsv
|
||||
```
|
||||
|
||||
查看规范入口:
|
||||
|
||||
- `docs/standards/playbook/docs/index.md`
|
||||
- `.agents/index.md`
|
||||
|
||||
## Codex skills(可选)
|
||||
|
||||
安装到本机(需要先在 `~/.codex/config.toml` 启用 skills;见 `docs/standards/playbook/SKILLS.md`):
|
||||
|
||||
```sh
|
||||
sh docs/standards/playbook/scripts/install_codex_skills.sh
|
||||
```
|
||||
|
||||
## CI templates(可选)
|
||||
|
||||
目标项目可复制启用的 CI 示例模板(如 Gitea Actions):`templates/ci/`。
|
||||
"@ | Set-Content -Path (Join-Path $DestPrefix "README.md") -Encoding UTF8
|
||||
|
||||
@"
|
||||
# SOURCE
|
||||
|
||||
- Source: $Src
|
||||
- Commit: $commit
|
||||
- Date: $(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||
- Langs: $langsCsv
|
||||
- Generated-by: scripts/vendor_playbook.ps1
|
||||
"@ | Set-Content -Path (Join-Path $DestPrefix "SOURCE.md") -Encoding UTF8
|
||||
|
||||
Write-Host "Vendored snapshot -> $DestPrefix"
|
||||
|
||||
$ProjectAgentsRoot = Join-Path $DestRootAbs ".agents"
|
||||
$ProjectAgentsIndex = Join-Path $ProjectAgentsRoot "index.md"
|
||||
New-Item -ItemType Directory -Path $ProjectAgentsRoot -Force | Out-Null
|
||||
if (-not (Test-Path $ProjectAgentsIndex)) {
|
||||
$agentLines = New-Object System.Collections.Generic.List[string]
|
||||
$agentLines.Add("# .agents(多语言)")
|
||||
$agentLines.Add("")
|
||||
$agentLines.Add("本目录用于存放仓库级/语言级的代理规则集。")
|
||||
$agentLines.Add("")
|
||||
$agentLines.Add("本项目已启用的规则集:")
|
||||
foreach ($lang in $Langs) {
|
||||
switch ($lang) {
|
||||
"tsl" { $agentLines.Add("- .agents/tsl/:TSL 相关规则集(适用于 .tsl/.tsf)"); break }
|
||||
"cpp" { $agentLines.Add("- .agents/cpp/:C++ 相关规则集(C++23,含 Modules)"); break }
|
||||
"python" { $agentLines.Add("- .agents/python/:Python 相关规则集"); break }
|
||||
}
|
||||
}
|
||||
$agentLines.Add("")
|
||||
$agentLines.Add("入口建议从:")
|
||||
foreach ($lang in $Langs) { $agentLines.Add("- .agents/$lang/index.md") }
|
||||
$agentLines.Add("")
|
||||
$agentLines.Add("标准快照文档入口:")
|
||||
$agentLines.Add("")
|
||||
$agentLines.Add("- docs/standards/playbook/docs/index.md")
|
||||
($agentLines -join "`n") | Set-Content -Path $ProjectAgentsIndex -Encoding UTF8
|
||||
}
|
||||
|
||||
$oldSyncRoot = $env:SYNC_ROOT
|
||||
$env:SYNC_ROOT = $DestRootAbs
|
||||
try {
|
||||
& (Join-Path $DestPrefix "scripts/sync_standards.ps1") -Langs $Langs
|
||||
} finally {
|
||||
$env:SYNC_ROOT = $oldSyncRoot
|
||||
}
|
||||
|
||||
Write-Host "Done."
|
||||
@@ -1,269 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Vendor a trimmed Playbook snapshot into a target project (offline copy),
|
||||
# then run sync_standards to materialize .agents/<lang>/ and .gitattributes in
|
||||
# the target project root.
|
||||
#
|
||||
# Usage:
|
||||
# sh scripts/vendor_playbook.sh <project-root> # default: tsl
|
||||
# sh scripts/vendor_playbook.sh <project-root> tsl cpp
|
||||
# sh scripts/vendor_playbook.sh <project-root> --langs tsl,cpp
|
||||
#
|
||||
# Notes:
|
||||
# - Snapshot is written to: <project-root>/docs/standards/playbook/
|
||||
# - Existing snapshot is backed up before overwrite.
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
|
||||
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF' >&2
|
||||
Usage:
|
||||
sh scripts/vendor_playbook.sh <project-root> # default: tsl
|
||||
sh scripts/vendor_playbook.sh <project-root> tsl cpp
|
||||
sh scripts/vendor_playbook.sh <project-root> --langs tsl,cpp
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "$#" -lt 1 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PROJECT_ROOT="$1"
|
||||
shift
|
||||
|
||||
langs=""
|
||||
if [ "${1:-}" = "--langs" ]; then
|
||||
langs="${2:-}"
|
||||
shift 2 || true
|
||||
fi
|
||||
if [ -z "${langs:-}" ] && [ "$#" -gt 0 ]; then
|
||||
langs="$*"
|
||||
fi
|
||||
|
||||
if [ -z "${langs:-}" ]; then
|
||||
langs="tsl"
|
||||
fi
|
||||
|
||||
timestamp="$(date +%Y%m%d%H%M%S 2>/dev/null || echo bak)"
|
||||
|
||||
if [ ! -d "$PROJECT_ROOT" ]; then
|
||||
echo "ERROR: project root does not exist: $PROJECT_ROOT" >&2
|
||||
exit 1
|
||||
fi
|
||||
PROJECT_ROOT_ABS="$(CDPATH= cd -- "$PROJECT_ROOT" && pwd -P)"
|
||||
DEST_PREFIX="$PROJECT_ROOT_ABS/docs/standards/playbook"
|
||||
DEST_STANDARDS="$PROJECT_ROOT_ABS/docs/standards"
|
||||
|
||||
mkdir -p "$DEST_STANDARDS"
|
||||
|
||||
if [ -e "$DEST_PREFIX" ]; then
|
||||
mv "$DEST_PREFIX" "$DEST_STANDARDS/playbook.bak.$timestamp"
|
||||
echo "Backed up existing snapshot -> docs/standards/playbook.bak.$timestamp"
|
||||
fi
|
||||
|
||||
mkdir -p "$DEST_PREFIX"
|
||||
|
||||
# Always include: scripts + gitattributes + docs/common + codex/skills
|
||||
cp "$SRC/.gitattributes" "$DEST_PREFIX/.gitattributes"
|
||||
cp -R "$SRC/scripts" "$DEST_PREFIX/"
|
||||
cp -R "$SRC/codex" "$DEST_PREFIX/"
|
||||
cp "$SRC/SKILLS.md" "$DEST_PREFIX/SKILLS.md"
|
||||
|
||||
mkdir -p "$DEST_PREFIX/docs"
|
||||
cp -R "$SRC/docs/common" "$DEST_PREFIX/docs/"
|
||||
|
||||
mkdir -p "$DEST_PREFIX/.agents"
|
||||
cp "$SRC/.agents/index.md" "$DEST_PREFIX/.agents/index.md"
|
||||
|
||||
mkdir -p "$DEST_PREFIX/templates"
|
||||
if [ -d "$SRC/templates/ci" ]; then
|
||||
cp -R "$SRC/templates/ci" "$DEST_PREFIX/templates/"
|
||||
fi
|
||||
|
||||
old_ifs="${IFS}"
|
||||
IFS=', '
|
||||
set -- $langs
|
||||
IFS="${old_ifs}"
|
||||
|
||||
langs_csv=""
|
||||
for lang in "$@"; do
|
||||
[ -n "$lang" ] || continue
|
||||
|
||||
case "$lang" in
|
||||
""|*/*|*\\*|*..*)
|
||||
echo "ERROR: invalid lang=$lang" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ! -d "$SRC/docs/$lang" ]; then
|
||||
echo "ERROR: docs not found for lang=$lang ($SRC/docs/$lang)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$SRC/.agents/$lang" ]; then
|
||||
echo "ERROR: agents ruleset not found for lang=$lang ($SRC/.agents/$lang)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp -R "$SRC/docs/$lang" "$DEST_PREFIX/docs/"
|
||||
cp -R "$SRC/.agents/$lang" "$DEST_PREFIX/.agents/"
|
||||
if [ -d "$SRC/templates/$lang" ]; then
|
||||
cp -R "$SRC/templates/$lang" "$DEST_PREFIX/templates/"
|
||||
fi
|
||||
|
||||
if [ -n "$langs_csv" ]; then
|
||||
langs_csv="$langs_csv,$lang"
|
||||
else
|
||||
langs_csv="$lang"
|
||||
fi
|
||||
done
|
||||
|
||||
cat >"$DEST_PREFIX/docs/index.md" <<EOF
|
||||
# 文档导航(Docs Index)
|
||||
|
||||
本快照为裁剪版 Playbook(langs: ${langs_csv})。
|
||||
|
||||
## 跨语言(common)
|
||||
|
||||
- 提交信息与版本号:\`common/commit_message.md\`
|
||||
EOF
|
||||
|
||||
append_docs_section() {
|
||||
lang="$1"
|
||||
case "$lang" in
|
||||
tsl)
|
||||
cat >>"$DEST_PREFIX/docs/index.md" <<'EOF'
|
||||
|
||||
## TSL(tsl)
|
||||
|
||||
- 代码风格:`tsl/code_style.md`
|
||||
- 命名规范:`tsl/naming.md`
|
||||
- 语法手册:`tsl/syntax_book/index.md`
|
||||
- 工具链与验证命令(模板):`tsl/toolchain.md`
|
||||
EOF
|
||||
;;
|
||||
cpp)
|
||||
cat >>"$DEST_PREFIX/docs/index.md" <<'EOF'
|
||||
|
||||
## C++(cpp)
|
||||
|
||||
- 代码风格:`cpp/code_style.md`
|
||||
- 命名规范:`cpp/naming.md`
|
||||
- 工具链与验证命令(模板):`cpp/toolchain.md`
|
||||
- 第三方依赖(Conan):`cpp/dependencies_conan.md`
|
||||
- clangd 配置:`cpp/clangd.md`
|
||||
EOF
|
||||
;;
|
||||
python)
|
||||
cat >>"$DEST_PREFIX/docs/index.md" <<'EOF'
|
||||
|
||||
## Python(python)
|
||||
|
||||
- 代码风格:`python/style_guide.md`
|
||||
- 工具链:`python/tooling.md`
|
||||
- 配置清单:`python/configuration.md`
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
for lang in "$@"; do
|
||||
[ -n "$lang" ] || continue
|
||||
append_docs_section "$lang"
|
||||
done
|
||||
|
||||
commit=""
|
||||
if command -v git >/dev/null 2>&1; then
|
||||
commit="$(git -C "$SRC" rev-parse HEAD 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
cat >"$DEST_PREFIX/README.md" <<EOF
|
||||
# Playbook(裁剪快照)
|
||||
|
||||
本目录为从 Playbook vendoring 的裁剪快照(langs: ${langs_csv})。
|
||||
|
||||
## 使用
|
||||
|
||||
在目标项目根目录执行(多语言一次同步):
|
||||
|
||||
\`\`\`sh
|
||||
sh docs/standards/playbook/scripts/sync_standards.sh ${langs_csv}
|
||||
\`\`\`
|
||||
|
||||
查看规范入口:
|
||||
|
||||
- \`docs/standards/playbook/docs/index.md\`
|
||||
- \`.agents/index.md\`
|
||||
|
||||
## Codex skills(可选)
|
||||
|
||||
安装到本机(需要先在 \`~/.codex/config.toml\` 启用 skills;见 \`docs/standards/playbook/SKILLS.md\`):
|
||||
|
||||
\`\`\`sh
|
||||
sh docs/standards/playbook/scripts/install_codex_skills.sh
|
||||
\`\`\`
|
||||
|
||||
## CI templates(可选)
|
||||
|
||||
目标项目可复制启用的 CI 示例模板(如 Gitea Actions):\`templates/ci/\`。
|
||||
EOF
|
||||
|
||||
cat >"$DEST_PREFIX/SOURCE.md" <<EOF
|
||||
# SOURCE
|
||||
|
||||
- Source: $SRC
|
||||
- Commit: ${commit:-N/A}
|
||||
- Date: $(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date)
|
||||
- Langs: ${langs_csv}
|
||||
- Generated-by: scripts/vendor_playbook.sh
|
||||
EOF
|
||||
|
||||
echo "Vendored snapshot -> $DEST_PREFIX"
|
||||
|
||||
PROJECT_AGENTS_ROOT="$PROJECT_ROOT_ABS/.agents"
|
||||
PROJECT_AGENTS_INDEX="$PROJECT_AGENTS_ROOT/index.md"
|
||||
mkdir -p "$PROJECT_AGENTS_ROOT"
|
||||
if [ ! -f "$PROJECT_AGENTS_INDEX" ]; then
|
||||
cat >"$PROJECT_AGENTS_INDEX" <<EOF
|
||||
# .agents(多语言)
|
||||
|
||||
本目录用于存放仓库级/语言级的代理规则集。
|
||||
|
||||
本项目已启用的规则集:
|
||||
EOF
|
||||
|
||||
for lang in "$@"; do
|
||||
case "$lang" in
|
||||
tsl) printf '%s\n' "- .agents/tsl/:TSL 相关规则集(适用于 .tsl/.tsf)" >>"$PROJECT_AGENTS_INDEX" ;;
|
||||
cpp) printf '%s\n' "- .agents/cpp/:C++ 相关规则集(C++23,含 Modules)" >>"$PROJECT_AGENTS_INDEX" ;;
|
||||
python) printf '%s\n' "- .agents/python/:Python 相关规则集" >>"$PROJECT_AGENTS_INDEX" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
cat >>"$PROJECT_AGENTS_INDEX" <<'EOF'
|
||||
|
||||
入口建议从:
|
||||
EOF
|
||||
|
||||
for lang in "$@"; do
|
||||
printf '%s\n' "- .agents/$lang/index.md" >>"$PROJECT_AGENTS_INDEX"
|
||||
done
|
||||
|
||||
cat >>"$PROJECT_AGENTS_INDEX" <<'EOF'
|
||||
|
||||
标准快照文档入口:
|
||||
|
||||
- docs/standards/playbook/docs/index.md
|
||||
EOF
|
||||
fi
|
||||
|
||||
SYNC_ROOT="$PROJECT_ROOT_ABS" sh "$DEST_PREFIX/scripts/sync_standards.sh" "$@"
|
||||
echo "Done."
|
||||
Reference in New Issue
Block a user