param( [Parameter(Mandatory = $true)] [string]$Task, [string]$Project = "furniture-3d-system", [string[]]$RoleIds = @( "backend-engineer", "frontend-engineer", "3d-engineer", "rule-reviewer", "security-reviewer", "performance-reviewer", "qa-tester" ), [string]$BaseDir = "_logs/agent-teams/runs" ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" function Convert-ToTaskSlug { param([string]$Value) $normalized = $Value.Trim().ToLowerInvariant() $normalized = [regex]::Replace($normalized, "[^a-z0-9]+", "-") $normalized = $normalized.Trim("-") if ([string]::IsNullOrWhiteSpace($normalized)) { return "task" } return $normalized } $roleCatalog = @{ "backend-engineer" = @{ name = "Backend Engineer" type = "development" rule = ".cursor/rules/backend.mdc" focus = "API, Service, Repository, permission, transaction" } "frontend-engineer" = @{ name = "Frontend Engineer" type = "development" rule = ".cursor/rules/frontend.mdc" focus = "page, component, interaction, visual standard" } "3d-engineer" = @{ name = "3D Engineer" type = "development" rule = ".cursor/rules/3d-engineer.mdc" focus = "Three.js, model, interaction, rendering" } "rule-reviewer" = @{ name = "Rule Reviewer" type = "review" rule = ".cursor/rules/checklist.mdc" focus = "architecture standard, visual standard" } "security-reviewer" = @{ name = "Security Reviewer" type = "review" rule = ".cursor/rules/security.mdc" focus = "injection, XSS, permission" } "performance-reviewer" = @{ name = "Performance Reviewer" type = "review" rule = ".cursor/rules/performance.mdc" focus = "query, rendering, memory, response time" } "qa-tester" = @{ name = "QA Tester" type = "test" rule = ".cursor/rules/testing.mdc" focus = "unit test, integration test, key flow regression" } } $missingRoleIds = @($RoleIds | Where-Object { -not $roleCatalog.ContainsKey($_) }) if ($missingRoleIds.Count -gt 0) { throw "Undefined role id(s): $($missingRoleIds -join ', ')" } $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path $runId = Get-Date -Format "yyyyMMdd-HHmmss" $taskSlug = Convert-ToTaskSlug -Value $Task $runDir = Join-Path $repoRoot "$BaseDir/$runId-$taskSlug" $dispatchDir = Join-Path $runDir "dispatch" $reportDir = Join-Path $runDir "reports" New-Item -ItemType Directory -Path $dispatchDir -Force | Out-Null New-Item -ItemType Directory -Path $reportDir -Force | Out-Null $createdAt = (Get-Date).ToString("s") $manifestRoles = @() foreach ($roleId in $RoleIds) { $role = $roleCatalog[$roleId] $dispatchPath = Join-Path $dispatchDir "$roleId.prompt.md" $reportPath = Join-Path $reportDir "$roleId.report.md" $dispatchPathRelative = $dispatchPath.Replace("$repoRoot\", "").Replace("\", "/") $reportPathRelative = $reportPath.Replace("$repoRoot\", "").Replace("\", "/") $dispatchText = @" # Agent Task Card - Role: $($role.name) - Role ID: $roleId - Type: $($role.type) - Rule File: $($role.rule) - Goal: $Task - Project: $Project - Focus: $($role.focus) ## Output Requirements 1. Only change code within this role scope. 2. Run minimal verification and write evidence. 3. Write report to: $reportPathRelative ## Acceptance - Change traceability (file path + purpose) - Verification evidence (command + result) - Rule compliance (architecture + visual + security) "@ $reportText = @" # Agent Execution Report - Role: $($role.name) - Role ID: $roleId - Status: pending - Updated At: $createdAt ## Changes - Files: - Purpose: ## Verification - Command: - Result: ## Review Conclusion - Passed: - Risks: - Next: "@ Set-Content -LiteralPath $dispatchPath -Value $dispatchText -Encoding UTF8 Set-Content -LiteralPath $reportPath -Value $reportText -Encoding UTF8 $manifestRoles += [ordered]@{ id = $roleId name = $role.name type = $role.type rule = $role.rule focus = $role.focus status = "pending" dispatchPath = $dispatchPathRelative reportPath = $reportPathRelative } } $manifest = [ordered]@{ runId = $runId task = $Task project = $Project createdAt = $createdAt updatedAt = $createdAt reviewOrder = @("rule-reviewer", "security-reviewer", "performance-reviewer") roles = $manifestRoles } $manifestPath = Join-Path $runDir "manifest.json" $manifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $manifestPath -Encoding UTF8 $runReadme = @" # Multi-Agent Run Folder - Run ID: $runId - Task: $Task - Project: $Project - Created At: $createdAt ## Commands Update role status: powershell -File scripts/agent-teams/update-role-status.ps1 -RunPath "$($runDir.Replace('\', '/'))" -RoleId "frontend-engineer" -Status "done" -Note "Page updates completed and verified" View dashboard: powershell -File scripts/agent-teams/dashboard.ps1 -RunPath "$($runDir.Replace('\', '/'))" "@ Set-Content -LiteralPath (Join-Path $runDir "README.md") -Value $runReadme -Encoding UTF8 Write-Host "Run folder created: $runDir" Write-Host "Distribute dispatch cards first, then keep reports status updated."