Files
github-spec-kit/src/specify_cli/integrations/forge/scripts/update-context.ps1
T
ericnoam 494879f2d5 fix: make Forge update-context scripts handle AGENTS.md directly
- Add fallback logic to update/create AGENTS.md when shared script doesn't support forge yet
- Check if shared dispatcher knows about 'forge' before delegating
- If shared script doesn't support forge, handle AGENTS.md updates directly:
  - Add Forge section to existing AGENTS.md if not present
  - Create new AGENTS.md with Forge section if file doesn't exist
- Both bash and PowerShell scripts implement same logic
- Prevents 'Unknown agent type' errors until shared scripts add forge support
- Future-compatible: automatically delegates when shared script supports forge

Addresses reviewer feedback about update-context scripts failing without forge support.
2026-04-02 17:04:57 +02:00

51 lines
2.1 KiB
PowerShell

# update-context.ps1 — Forge integration: create/update AGENTS.md
#
# Thin wrapper that delegates to the shared update-agent-context script.
# Activated in Stage 7 when the shared script uses integration.json dispatch.
#
# Until then, this delegates to the shared script as a subprocess.
$ErrorActionPreference = 'Stop'
# Derive repo root from script location (walks up to find .specify/)
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$repoRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null }
# If git did not return a repo root, or the git root does not contain .specify,
# fall back to walking up from the script directory to find the initialized project root.
if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {
$repoRoot = $scriptDir
$fsRoot = [System.IO.Path]::GetPathRoot($repoRoot)
while ($repoRoot -and $repoRoot -ne $fsRoot -and -not (Test-Path (Join-Path $repoRoot '.specify'))) {
$repoRoot = Split-Path -Parent $repoRoot
}
}
$sharedScript = "$repoRoot/.specify/scripts/powershell/update-agent-context.ps1"
# If the shared dispatcher already knows about "forge", delegate to it.
if ((Test-Path $sharedScript) -and (Select-String -Path $sharedScript -Pattern "'forge'|`"forge`"" -Quiet)) {
& $sharedScript -AgentType forge
exit $LASTEXITCODE
}
# Forge-specific handling: update or create AGENTS.md directly until the shared
# dispatcher script supports -AgentType forge.
$agentsFile = Join-Path $repoRoot 'AGENTS.md'
if (Test-Path $agentsFile) {
$agentsContent = Get-Content -Path $agentsFile -ErrorAction Stop
# Only add a Forge entry if one does not already exist.
if (-not ($agentsContent | Where-Object { $_ -match '\bForge\b' })) {
Add-Content -Path $agentsFile -Value ''
Add-Content -Path $agentsFile -Value '## Forge'
Add-Content -Path $agentsFile -Value '- Forge integration agent context'
}
} else {
$newContent = @(
'# Agents'
''
'## Forge'
'- Forge integration agent context'
)
$newContent | Set-Content -Path $agentsFile -Encoding UTF8
}
exit 0