From 494879f2d559494dd325060c982b2e49781199ab Mon Sep 17 00:00:00 2001 From: ericnoam Date: Thu, 2 Apr 2026 17:04:57 +0200 Subject: [PATCH] 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. --- .../forge/scripts/update-context.ps1 | 29 ++++++++++++++++++- .../forge/scripts/update-context.sh | 24 ++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/specify_cli/integrations/forge/scripts/update-context.ps1 b/src/specify_cli/integrations/forge/scripts/update-context.ps1 index c6071ff3a..64f32faf3 100644 --- a/src/specify_cli/integrations/forge/scripts/update-context.ps1 +++ b/src/specify_cli/integrations/forge/scripts/update-context.ps1 @@ -20,4 +20,31 @@ if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) { } } -& "$repoRoot/.specify/scripts/powershell/update-agent-context.ps1" -AgentType forge +$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 diff --git a/src/specify_cli/integrations/forge/scripts/update-context.sh b/src/specify_cli/integrations/forge/scripts/update-context.sh index 126fe1cfa..f2c5c51f7 100755 --- a/src/specify_cli/integrations/forge/scripts/update-context.sh +++ b/src/specify_cli/integrations/forge/scripts/update-context.sh @@ -25,4 +25,26 @@ if [ -z "${REPO_ROOT:-}" ]; then fi fi -exec "$REPO_ROOT/.specify/scripts/bash/update-agent-context.sh" forge +shared_script="$REPO_ROOT/.specify/scripts/bash/update-agent-context.sh" +# If the shared dispatcher already knows about "forge", delegate to it. +if grep -q 'forge)' "$shared_script" 2>/dev/null; then + exec "$shared_script" forge +fi + +# Forge-specific handling: update or create AGENTS.md directly until the shared +# dispatcher script supports "forge". +agents_file="$REPO_ROOT/AGENTS.md" +if [ -f "$agents_file" ]; then + # Only add a Forge entry if one does not already exist. + if ! grep -q '\bForge\b' "$agents_file"; then + printf '\n## Forge\n- Forge integration agent context\n' >> "$agents_file" + fi +else + cat > "$agents_file" << 'EOF' +# Agents + +## Forge +- Forge integration agent context +EOF +fi +exit 0