🔧 chore(sync): align agents block across ps1/bat
This commit is contained in:
parent
9481510154
commit
087b0b9c75
|
|
@ -121,6 +121,15 @@ if errorlevel 1 (
|
||||||
|
|
||||||
echo Synced .agents\%AGENTS_NS% from standards.
|
echo Synced .agents\%AGENTS_NS% from standards.
|
||||||
|
|
||||||
|
set "REL_SNAPSHOT=%SRC:%ROOT%\=%"
|
||||||
|
if /I not "%REL_SNAPSHOT%"=="%SRC%" (
|
||||||
|
set "DOCS_PREFIX=%REL_SNAPSHOT%\docs"
|
||||||
|
set "DOCS_PREFIX=%DOCS_PREFIX:\=/%"
|
||||||
|
for %%F in ("%AGENTS_DST%\*.md") do (
|
||||||
|
powershell -NoProfile -Command "$p='%%~fF'; $c=Get-Content -Raw $p; $c=$c.Replace('`docs/tsl/','`%DOCS_PREFIX%/tsl/'); $c=$c.Replace('`docs/cpp/','`%DOCS_PREFIX%/cpp/'); $c=$c.Replace('`docs/python/','`%DOCS_PREFIX%/python/'); $c=$c.Replace('`docs/markdown/','`%DOCS_PREFIX%/markdown/'); $c=$c.Replace('`docs/common/','`%DOCS_PREFIX%/common/'); Set-Content -Path $p -Value $c -Encoding UTF8"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not exist "%AGENTS_ROOT%\index.md" (
|
if not exist "%AGENTS_ROOT%\index.md" (
|
||||||
> "%AGENTS_ROOT%\index.md" echo # .agents(多语言)
|
> "%AGENTS_ROOT%\index.md" echo # .agents(多语言)
|
||||||
>> "%AGENTS_ROOT%\index.md" echo.
|
>> "%AGENTS_ROOT%\index.md" echo.
|
||||||
|
|
@ -144,15 +153,58 @@ if not exist "%AGENTS_ROOT%\index.md" (
|
||||||
echo Created .agents\index.md
|
echo Created .agents\index.md
|
||||||
)
|
)
|
||||||
|
|
||||||
if not exist "%ROOT%\AGENTS.md" (
|
set "AGENTS_LANGS="
|
||||||
> "%ROOT%\AGENTS.md" echo # Agent Instructions
|
for /d %%D in ("%AGENTS_ROOT%\*") do (
|
||||||
>> "%ROOT%\AGENTS.md" echo.
|
set "NAME=%%~nxD"
|
||||||
>> "%ROOT%\AGENTS.md" echo 请以 `.agents/` 下的规则为准:
|
if /I not "!NAME:~0,1!"=="." (
|
||||||
>> "%ROOT%\AGENTS.md" echo.
|
echo "!NAME!" | findstr /I /C:".bak." >nul
|
||||||
>> "%ROOT%\AGENTS.md" echo - 入口:`.agents/index.md`
|
if errorlevel 1 (
|
||||||
>> "%ROOT%\AGENTS.md" echo - 语言规则:`.agents/tsl/index.md`、`.agents/cpp/index.md`、`.agents/python/index.md`、`.agents/markdown/index.md`
|
if exist "%%D\index.md" (
|
||||||
echo Created AGENTS.md
|
if defined AGENTS_LANGS (
|
||||||
|
set "AGENTS_LANGS=!AGENTS_LANGS!、`.agents/!NAME!/index.md`"
|
||||||
|
) else (
|
||||||
|
set "AGENTS_LANGS=`.agents/!NAME!/index.md`"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
if not defined AGENTS_LANGS set "AGENTS_LANGS=`.agents/%AGENTS_NS%/index.md`"
|
||||||
|
|
||||||
|
set "AGENTS_BLOCK_START=<!-- playbook:agents:start -->"
|
||||||
|
set "AGENTS_BLOCK_END=<!-- playbook:agents:end -->"
|
||||||
|
set "AGENTS_BLOCK_FILE=%ROOT%\.agents_block.!RANDOM!.tmp"
|
||||||
|
> "%AGENTS_BLOCK_FILE%" echo %AGENTS_BLOCK_START%
|
||||||
|
>> "%AGENTS_BLOCK_FILE%" echo 请以 `.agents/` 下的规则为准:
|
||||||
|
>> "%AGENTS_BLOCK_FILE%" echo.
|
||||||
|
>> "%AGENTS_BLOCK_FILE%" echo - 入口:`.agents/index.md`
|
||||||
|
>> "%AGENTS_BLOCK_FILE%" echo - 语言规则:%AGENTS_LANGS%
|
||||||
|
>> "%AGENTS_BLOCK_FILE%" echo %AGENTS_BLOCK_END%
|
||||||
|
|
||||||
|
set "AGENTS_MD=%ROOT%\AGENTS.md"
|
||||||
|
if not exist "%AGENTS_MD%" (
|
||||||
|
> "%AGENTS_MD%" echo # Agent Instructions
|
||||||
|
>> "%AGENTS_MD%" echo.
|
||||||
|
type "%AGENTS_BLOCK_FILE%" >> "%AGENTS_MD%"
|
||||||
|
echo Created AGENTS.md
|
||||||
|
) else (
|
||||||
|
findstr /C:"%AGENTS_BLOCK_START%" "%AGENTS_MD%" >nul
|
||||||
|
if not errorlevel 1 (
|
||||||
|
powershell -NoProfile -Command "$file='%AGENTS_MD%'; $block=Get-Content -Raw '%AGENTS_BLOCK_FILE%'; $start='%AGENTS_BLOCK_START%'; $end='%AGENTS_BLOCK_END%'; $pattern=[regex]::Escape($start)+'.*?'+[regex]::Escape($end); $regex=New-Object System.Text.RegularExpressions.Regex($pattern,[System.Text.RegularExpressions.RegexOptions]::Singleline); $content=Get-Content -Raw $file; $new=$regex.Replace($content,$block,1); Set-Content -Path $file -Value $new -Encoding UTF8"
|
||||||
|
echo Updated AGENTS.md (playbook block).
|
||||||
|
) else (
|
||||||
|
findstr /C:".agents/index.md" "%AGENTS_MD%" >nul
|
||||||
|
if not errorlevel 1 (
|
||||||
|
echo Skip: AGENTS.md already references .agents/index.md
|
||||||
|
) else (
|
||||||
|
>> "%AGENTS_MD%" echo.
|
||||||
|
type "%AGENTS_BLOCK_FILE%" >> "%AGENTS_MD%"
|
||||||
|
>> "%AGENTS_MD%" echo.
|
||||||
|
echo Appended playbook block to AGENTS.md
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
del "%AGENTS_BLOCK_FILE%" >nul 2>&1
|
||||||
|
|
||||||
:SyncGitAttr
|
:SyncGitAttr
|
||||||
if exist "%GITATTR_SRC%" (
|
if exist "%GITATTR_SRC%" (
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,26 @@ New-Item -ItemType Directory -Path $AgentsDst -Force | Out-Null
|
||||||
Copy-Item (Join-Path $AgentsSrc "*") $AgentsDst -Recurse -Force
|
Copy-Item (Join-Path $AgentsSrc "*") $AgentsDst -Recurse -Force
|
||||||
Write-Host "Synced .agents/$AgentsNs from standards."
|
Write-Host "Synced .agents/$AgentsNs from standards."
|
||||||
|
|
||||||
|
# Rewrite docs/* references to the snapshot docs path.
|
||||||
|
$relSnapshot = $null
|
||||||
|
$rootPrefix = $Root.TrimEnd('\', '/')
|
||||||
|
$rootPrefixWithSep = $rootPrefix + [System.IO.Path]::DirectorySeparatorChar
|
||||||
|
if ($Src.ToLowerInvariant().StartsWith($rootPrefixWithSep.ToLowerInvariant())) {
|
||||||
|
$relSnapshot = $Src.Substring($rootPrefixWithSep.Length)
|
||||||
|
}
|
||||||
|
if ($relSnapshot) {
|
||||||
|
$docsPrefix = (Join-Path $relSnapshot "docs") -replace "\\", "/"
|
||||||
|
Get-ChildItem -Path $AgentsDst -Filter *.md -File | ForEach-Object {
|
||||||
|
$content = Get-Content -Raw -Path $_.FullName
|
||||||
|
$content = $content.Replace("``docs/tsl/", "``$docsPrefix/tsl/")
|
||||||
|
$content = $content.Replace("``docs/cpp/", "``$docsPrefix/cpp/")
|
||||||
|
$content = $content.Replace("``docs/python/", "``$docsPrefix/python/")
|
||||||
|
$content = $content.Replace("``docs/markdown/", "``$docsPrefix/markdown/")
|
||||||
|
$content = $content.Replace("``docs/common/", "``$docsPrefix/common/")
|
||||||
|
Set-Content -Path $_.FullName -Value $content -Encoding UTF8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$AgentsIndex = Join-Path $AgentsRoot "index.md"
|
$AgentsIndex = Join-Path $AgentsRoot "index.md"
|
||||||
if (-not (Test-Path $AgentsIndex)) {
|
if (-not (Test-Path $AgentsIndex)) {
|
||||||
@'
|
@'
|
||||||
|
|
@ -135,16 +155,51 @@ if (-not (Test-Path $AgentsIndex)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$AgentsMd = Join-Path $Root "AGENTS.md"
|
$AgentsMd = Join-Path $Root "AGENTS.md"
|
||||||
if (-not (Test-Path $AgentsMd)) {
|
$AgentsBlockStart = "<!-- playbook:agents:start -->"
|
||||||
@'
|
$AgentsBlockEnd = "<!-- playbook:agents:end -->"
|
||||||
# Agent Instructions
|
$agentsLangs = @()
|
||||||
|
if (Test-Path $AgentsRoot) {
|
||||||
|
Get-ChildItem -Path $AgentsRoot -Directory | ForEach-Object {
|
||||||
|
$name = $_.Name
|
||||||
|
if ($name -and -not $name.StartsWith(".") -and -not ($name -match "\.bak\.") -and (Test-Path (Join-Path $_.FullName "index.md"))) {
|
||||||
|
$agentsLangs += $name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($agentsLangs.Count -eq 0) { $agentsLangs = @($AgentsNs) }
|
||||||
|
$langsLine = ($agentsLangs | ForEach-Object { "`.agents/$_/index.md`" }) -join "、"
|
||||||
|
$agentsBlock = @"
|
||||||
|
<!-- playbook:agents:start -->
|
||||||
请以 `.agents/` 下的规则为准:
|
请以 `.agents/` 下的规则为准:
|
||||||
|
|
||||||
- 入口:`.agents/index.md`
|
- 入口:`.agents/index.md`
|
||||||
- 语言规则:`.agents/tsl/index.md`、`.agents/cpp/index.md`、`.agents/python/index.md`、`.agents/markdown/index.md`
|
- 语言规则:$langsLine
|
||||||
'@ | Set-Content -Path $AgentsMd -Encoding UTF8
|
<!-- playbook:agents:end -->
|
||||||
|
"@
|
||||||
|
|
||||||
|
if (-not (Test-Path $AgentsMd)) {
|
||||||
|
@"
|
||||||
|
# Agent Instructions
|
||||||
|
|
||||||
|
$agentsBlock
|
||||||
|
"@ | Set-Content -Path $AgentsMd -Encoding UTF8
|
||||||
Write-Host "Created AGENTS.md"
|
Write-Host "Created AGENTS.md"
|
||||||
|
} else {
|
||||||
|
$content = Get-Content -Raw -Path $AgentsMd
|
||||||
|
if ($content.Contains($AgentsBlockStart)) {
|
||||||
|
$pattern = [regex]::Escape($AgentsBlockStart) + ".*?" + [regex]::Escape($AgentsBlockEnd)
|
||||||
|
$regex = New-Object System.Text.RegularExpressions.Regex($pattern, [System.Text.RegularExpressions.RegexOptions]::Singleline)
|
||||||
|
$newContent = $regex.Replace($content, $agentsBlock, 1)
|
||||||
|
Set-Content -Path $AgentsMd -Value $newContent -Encoding UTF8
|
||||||
|
Write-Host "Updated AGENTS.md (playbook block)."
|
||||||
|
} elseif ($content.Contains(".agents/index.md")) {
|
||||||
|
Write-Host "Skip: AGENTS.md already references .agents/index.md"
|
||||||
|
} else {
|
||||||
|
Add-Content -Path $AgentsMd -Value "" -Encoding UTF8
|
||||||
|
Add-Content -Path $AgentsMd -Value $agentsBlock -Encoding UTF8
|
||||||
|
Add-Content -Path $AgentsMd -Value "" -Encoding UTF8
|
||||||
|
Write-Host "Appended playbook block to AGENTS.md"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$GitAttrDst = Join-Path $Root ".gitattributes"
|
$GitAttrDst = Join-Path $Root ".gitattributes"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue