83 lines
2.6 KiB
PowerShell
83 lines
2.6 KiB
PowerShell
# Sync standards snapshot to project root.
|
||
# - Copies <snapshot>/.agents -> <project-root>/.agents/tsl
|
||
# - Copies <snapshot>/.gitattributes -> <project-root>/.gitattributes
|
||
# Existing targets are backed up before overwrite.
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
||
|
||
$Root = (git -C $ScriptDir rev-parse --show-toplevel 2>$null)
|
||
if (-not $Root) { $Root = (Get-Location).Path }
|
||
$Root = (Resolve-Path $Root).Path
|
||
|
||
$AgentsSrc = Join-Path $Src ".agents"
|
||
$GitAttrSrc = Join-Path $Src ".gitattributes"
|
||
|
||
if (-not (Test-Path $AgentsSrc)) {
|
||
throw "Standards snapshot not found at $AgentsSrc. Run git subtree add first (choose any prefix)."
|
||
}
|
||
|
||
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
|
||
|
||
$AgentsNs = $env:AGENTS_NS
|
||
if (-not $AgentsNs) { $AgentsNs = "tsl" }
|
||
if ($AgentsNs -match '[\\/]' -or $AgentsNs -match '\.\.') {
|
||
throw "Invalid AGENTS_NS=$AgentsNs"
|
||
}
|
||
$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.*` 同步)
|
||
- `.agents/cpp/`、`.agents/python/` 等:其他语言的规则集(按需增加)
|
||
|
||
规则发生冲突时,建议以“更靠近代码的目录规则更具体”为准。
|
||
"@ | Set-Content -Path $AgentsIndex -Encoding UTF8
|
||
Write-Host "Created .agents/index.md"
|
||
}
|
||
|
||
$GitAttrDst = Join-Path $Root ".gitattributes"
|
||
if (Test-Path $GitAttrSrc) {
|
||
if ($GitAttrSrc -ieq $GitAttrDst) {
|
||
Write-Host "Skip: .gitattributes source equals destination."
|
||
Write-Host "Done."
|
||
exit 0
|
||
}
|
||
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."
|
||
}
|
||
|
||
Write-Host "Done."
|