Merge commit 'ac794a6a7051497ff60b947642d44f0f8c04d6c6' into lsp-server

This commit is contained in:
csh
2026-01-08 15:56:37 +08:00
113 changed files with 254751 additions and 176 deletions
@@ -1,6 +1,6 @@
# Sync standards snapshot to project root.
# - Copies <snapshot>/.agents/<AGENTS_NS> -> <project-root>/.agents/<AGENTS_NS>
# - Updates <project-root>/.gitattributes (managed block by default)
# - Updates <project-root>/.gitattributes (append missing rules by default)
# Existing targets are backed up before overwrite.
[CmdletBinding()]
param(
@@ -15,8 +15,11 @@ $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 = $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"
@@ -28,6 +31,17 @@ if (-not (Test-Path $AgentsSrcRoot)) {
$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
@@ -35,7 +49,7 @@ if (-not $env:SYNC_STANDARDS_INNER -and $Langs -and $Langs.Count -gt 0) {
$oldMode = $env:SYNC_GITATTR_MODE
$syncModeFirst = $env:SYNC_GITATTR_MODE
if (-not $syncModeFirst) { $syncModeFirst = "block" }
if (-not $syncModeFirst) { $syncModeFirst = "append" }
$first = $true
foreach ($ns in $Langs) {
@@ -118,10 +132,22 @@ if (-not (Test-Path $AgentsIndex)) {
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 = "block" }
if (-not $mode) { $mode = "append" }
switch ($mode.ToLowerInvariant()) {
"skip" {
Write-Host "Skip: .gitattributes sync (SYNC_GITATTR_MODE=skip)."
@@ -141,6 +167,65 @@ if (Test-Path $GitAttrSrc) {
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"
@@ -171,7 +256,7 @@ if (Test-Path $GitAttrSrc) {
break
}
default {
throw "Invalid SYNC_GITATTR_MODE=$mode (use block|overwrite|skip)"
throw "Invalid SYNC_GITATTR_MODE=$mode (use block|overwrite|append|skip)"
}
}
}