feat: add Forge support to shared update-agent-context scripts

- Add forge case to bash and PowerShell update-agent-context scripts
- Add FORGE_FILE variable mapping to AGENTS.md (like opencode/codex/pi)
- Add forge to all usage/help text and ValidateSet parameters
- Include forge in update_all_existing_agents functions

Wrapper script improvements:
- Simplify Forge wrapper scripts to unconditionally delegate to shared script
- Remove complex fallback logic that created stub AGENTS.md files
- Add clear error messages if shared script is missing/not executable
- Align with pattern used by other integrations (opencode, bob, etc.)

Benefits:
- Plan command's {AGENT_SCRIPT} now works for Forge users
- No more incomplete/stub context files masking missing support
- Cleaner, more maintainable code (-39 lines in wrappers)
- Consistent architecture across all integrations

Update AGENTS.md to document that Forge integration ensures shared scripts
include forge support for context updates.

Addresses reviewer feedback about Forge support being incomplete for
workflow steps that run {AGENT_SCRIPT}.
This commit is contained in:
ericnoam
2026-04-02 18:16:50 +02:00
parent 494879f2d5
commit 99e1c3fedd
5 changed files with 31 additions and 52 deletions

View File

@@ -21,30 +21,13 @@ if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot '.specify'))) {
}
$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
# Always delegate to the shared updater; fail clearly if it is unavailable.
if (-not (Test-Path $sharedScript)) {
Write-Error "Error: shared agent context updater not found: $sharedScript"
Write-Error "Forge integration requires support in scripts/powershell/update-agent-context.ps1."
exit 1
}
# 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
& $sharedScript -AgentType forge
exit $LASTEXITCODE

View File

@@ -26,25 +26,13 @@ if [ -z "${REPO_ROOT:-}" ]; then
fi
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
# Always delegate to the shared updater; fail clearly if it is unavailable.
if [ ! -x "$shared_script" ]; then
echo "Error: shared agent context updater not found or not executable:" >&2
echo " $shared_script" >&2
echo "Forge integration requires support in scripts/bash/update-agent-context.sh." >&2
exit 1
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
exec "$shared_script" forge