param( [Parameter(Mandatory=$true)] [string]$Prompt, [ValidateSet("Worker", "QA", "Utility")] [string]$Role = "Utility", [string]$Model = "flash" ) # Ensure the session has the API key loaded if (Test-Path "C:\projects\misc\setup_gemini.ps1") { . C:\projects\misc\setup_gemini.ps1 } $SystemPrompts = @{ "Worker" = "STRICT SYSTEM DIRECTIVE: You are a stateless Tier 3 Worker (Contributor). Your goal is to generate high-quality code or diffs based on the provided ticket. DO NOT USE ANY TOOLS (no write_file, no run_shell_command, etc.). ONLY output the clean code or the requested diff inside XML-style tags if requested, otherwise just the code. No pleasantries." "QA" = "STRICT SYSTEM DIRECTIVE: You are a stateless Tier 4 QA Agent. Your goal is to analyze the provided error trace and compress it into a surgical, 20-word fix. DO NOT USE ANY TOOLS. ONLY output the compressed fix. No explanations." "Utility" = "STRICT SYSTEM DIRECTIVE: You are a stateless utility function. DO NOT USE ANY TOOLS. ONLY output the exact requested text, code, or JSON." } $SelectedPrompt = $SystemPrompts[$Role] $SafePrompt = "$SelectedPrompt`n`nUSER PROMPT:`n$Prompt" # Execute headless Gemini using -p, suppressing stderr noise $jsonOutput = gemini -p $SafePrompt --model $Model --output-format json 2>$null try { # Extract only the JSON part $fullString = $jsonOutput -join "`n" $jsonStartIndex = $fullString.IndexOf("{") if ($jsonStartIndex -ge 0) { $cleanJsonString = $fullString.Substring($jsonStartIndex) $parsed = $cleanJsonString | ConvertFrom-Json # Output only the clean response text Write-Output $parsed.response } else { Write-Warning "No JSON object found in output." Write-Output $fullString } } catch { # Fallback if parsing fails Write-Warning "Failed to parse JSON from sub-agent. Raw output:" Write-Output $jsonOutput }