33param ([string ]$AgentType )
44$ErrorActionPreference = ' Stop'
55
6- $repoRoot = git rev- parse -- show-toplevel
7- $currentBranch = git rev- parse -- abbrev- ref HEAD
8- $featureDir = Join-Path $repoRoot " specs/$currentBranch "
9- $newPlan = Join-Path $featureDir ' plan.md'
10- if (-not (Test-Path $newPlan )) { Write-Error " ERROR: No plan.md found at $newPlan " ; exit 1 }
6+ # Load common functions
7+ . " $PSScriptRoot /common.ps1"
118
12- $claudeFile = Join-Path $repoRoot ' CLAUDE.md'
13- $geminiFile = Join-Path $repoRoot ' GEMINI.md'
14- $copilotFile = Join-Path $repoRoot ' .github/copilot-instructions.md'
15- $cursorFile = Join-Path $repoRoot ' .cursor/rules/specify-rules.mdc'
16- $qwenFile = Join-Path $repoRoot ' QWEN.md'
17- $agentsFile = Join-Path $repoRoot ' AGENTS.md'
18- $windsurfFile = Join-Path $repoRoot ' .windsurf/rules/specify-rules.md'
9+ # Get all paths and variables from common functions
10+ $paths = Get-FeaturePathsEnv
1911
20- Write-Output " === Updating agent context files for feature $currentBranch ==="
12+ $newPlan = $paths.IMPL_PLAN
13+ if (-not (Test-Path $newPlan )) {
14+ Write-Error " ERROR: No plan.md found at $newPlan "
15+ if (-not $paths.HAS_GIT ) {
16+ Write-Output " Use: `$ env:SPECIFY_FEATURE='your-feature-name' or create a new feature first"
17+ }
18+ exit 1
19+ }
20+
21+ $claudeFile = Join-Path $paths.REPO_ROOT ' CLAUDE.md'
22+ $geminiFile = Join-Path $paths.REPO_ROOT ' GEMINI.md'
23+ $copilotFile = Join-Path $paths.REPO_ROOT ' .github/copilot-instructions.md'
24+ $cursorFile = Join-Path $paths.REPO_ROOT ' .cursor/rules/specify-rules.mdc'
25+ $qwenFile = Join-Path $paths.REPO_ROOT ' QWEN.md'
26+ $agentsFile = Join-Path $paths.REPO_ROOT ' AGENTS.md'
27+ $windsurfFile = Join-Path $paths.REPO_ROOT ' .windsurf/rules/specify-rules.md'
28+
29+ Write-Output " === Updating agent context files for feature $ ( $paths.CURRENT_BRANCH ) ==="
2130
2231function Get-PlanValue ($pattern ) {
2332 if (-not (Test-Path $newPlan )) { return ' ' }
@@ -34,12 +43,12 @@ $newProjectType = Get-PlanValue 'Project Type'
3443
3544function Initialize-AgentFile ($targetFile , $agentName ) {
3645 if (Test-Path $targetFile ) { return }
37- $template = Join-Path $repoRoot ' .specify/templates/agent-file-template.md'
46+ $template = Join-Path $paths .REPO_ROOT ' .specify/templates/agent-file-template.md'
3847 if (-not (Test-Path $template )) { Write-Error " Template not found: $template " ; return }
3948 $content = Get-Content $template - Raw
40- $content = $content.Replace (' [PROJECT NAME]' , (Split-Path $repoRoot - Leaf))
49+ $content = $content.Replace (' [PROJECT NAME]' , (Split-Path $paths .REPO_ROOT - Leaf))
4150 $content = $content.Replace (' [DATE]' , (Get-Date - Format ' yyyy-MM-dd' ))
42- $content = $content.Replace (' [EXTRACTED FROM ALL PLAN.MD FILES]' , " - $newLang + $newFramework ($currentBranch )" )
51+ $content = $content.Replace (' [EXTRACTED FROM ALL PLAN.MD FILES]' , " - $newLang + $newFramework ($ ( $paths .CURRENT_BRANCH ) )" )
4352 if ($newProjectType -match ' web' ) { $structure = " backend/`n frontend/`n tests/" } else { $structure = " src/`n tests/" }
4453 $content = $content.Replace (' [ACTUAL STRUCTURE FROM PLANS]' , $structure )
4554 if ($newLang -match ' Python' ) { $commands = ' cd src && pytest && ruff check .' }
@@ -48,18 +57,18 @@ function Initialize-AgentFile($targetFile, $agentName) {
4857 else { $commands = " # Add commands for $newLang " }
4958 $content = $content.Replace (' [ONLY COMMANDS FOR ACTIVE TECHNOLOGIES]' , $commands )
5059 $content = $content.Replace (' [LANGUAGE-SPECIFIC, ONLY FOR LANGUAGES IN USE]' , " ${newLang} : Follow standard conventions" )
51- $content = $content.Replace (' [LAST 3 FEATURES AND WHAT THEY ADDED]' , " - ${currentBranch} : Added ${newLang} + ${newFramework} " )
60+ $content = $content.Replace (' [LAST 3 FEATURES AND WHAT THEY ADDED]' , " - $ ( $paths .CURRENT_BRANCH ) : Added ${newLang} + ${newFramework} " )
5261 $content | Set-Content $targetFile - Encoding UTF8
5362}
5463
5564function Update-AgentFile ($targetFile , $agentName ) {
5665 if (-not (Test-Path $targetFile )) { Initialize-AgentFile $targetFile $agentName ; return }
5766 $content = Get-Content $targetFile - Raw
58- if ($newLang -and ($content -notmatch [regex ]::Escape($newLang ))) { $content = $content -replace ' (## Active Technologies\n)' , " `$ 1- $newLang + $newFramework ($currentBranch )`n " }
59- if ($newDb -and $newDb -ne ' N/A' -and ($content -notmatch [regex ]::Escape($newDb ))) { $content = $content -replace ' (## Active Technologies\n)' , " `$ 1- $newDb ($currentBranch )`n " }
67+ if ($newLang -and ($content -notmatch [regex ]::Escape($newLang ))) { $content = $content -replace ' (## Active Technologies\n)' , " `$ 1- $newLang + $newFramework ($ ( $paths .CURRENT_BRANCH ) )`n " }
68+ if ($newDb -and $newDb -ne ' N/A' -and ($content -notmatch [regex ]::Escape($newDb ))) { $content = $content -replace ' (## Active Technologies\n)' , " `$ 1- $newDb ($ ( $paths .CURRENT_BRANCH ) )`n " }
6069 if ($content -match ' ## Recent Changes\n([\s\S]*?)(\n\n|$)' ) {
6170 $changesBlock = $matches [1 ].Trim().Split(" `n " )
62- $changesBlock = , " - ${currentBranch} : Added ${newLang} + ${newFramework} " + $changesBlock
71+ $changesBlock = , " - $ ( $paths .CURRENT_BRANCH ) : Added ${newLang} + ${newFramework} " + $changesBlock
6372 $changesBlock = $changesBlock | Where-Object { $_ } | Select-Object - First 3
6473 $joined = ($changesBlock -join " `n " )
6574 $content = [regex ]::Replace($content , ' ## Recent Changes\n([\s\S]*?)(\n\n|$)' , " ## Recent Changes`n $joined `n`n " )
0 commit comments