| 1 | #Requires -Version 7.0 |
| 2 | <# |
| 3 | .SYNOPSIS |
| 4 | Idempotent harness setup for CIDE «CASA / Neumann T1» (interim, ADR 0166 §5.1). |
| 5 | |
| 6 | .DESCRIPTION |
| 7 | - Ensures %LocalAppData%\CascadeIDE exists |
| 8 | - Merges harness-neumann-t1.overlay.toml keys into settings.toml |
| 9 | - Deploys harness-external-mcp.json (optional roslyn + python stdio) |
| 10 | - Does NOT install Cloud.ru keys (ai-keys.toml) — operator only |
| 11 | |
| 12 | .PARAMETER Apply |
| 13 | Write files. Without -Apply, dry-run only. |
| 14 | |
| 15 | .PARAMETER AgentNotesConfigPath |
| 16 | Path to agent-notes-mcp.toml (same as Cursor --config). |
| 17 | |
| 18 | .PARAMETER SkipExternalMcp |
| 19 | Skip copying optional external MCP JSON (roslyn/python only). |
| 20 | |
| 21 | .PARAMETER RoslynMcpExe |
| 22 | Override roslyn MCP executable path in external JSON. |
| 23 | |
| 24 | .PARAMETER PythonMcpExe |
| 25 | Override python MCP executable path in external JSON. |
| 26 | #> |
| 27 | [CmdletBinding()] |
| 28 | param( |
| 29 | [switch]$Apply, |
| 30 | [string]$AgentNotesConfigPath = $env:CIDE_AGENT_NOTES_CONFIG, |
| 31 | [switch]$SkipExternalMcp, |
| 32 | [string]$RoslynMcpExe = $env:CIDE_ROSLYN_MCP_EXE, |
| 33 | [string]$PythonMcpExe = $env:CIDE_PYTHON_MCP_EXE |
| 34 | ) |
| 35 | |
| 36 | $ErrorActionPreference = 'Stop' |
| 37 | $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path |
| 38 | $samples = Join-Path $repoRoot 'docs\samples' |
| 39 | $cideDir = Join-Path $env:LOCALAPPDATA 'CascadeIDE' |
| 40 | $settingsPath = Join-Path $cideDir 'settings.toml' |
| 41 | $overlayPath = Join-Path $samples 'harness-neumann-t1.overlay.toml' |
| 42 | $externalTemplate = Join-Path $samples 'harness-external-mcp.optional.json' |
| 43 | $externalDest = Join-Path $cideDir 'harness-external-mcp.json' |
| 44 | |
| 45 | function Write-Step([string]$Message) { Write-Host "→ $Message" } |
| 46 | |
| 47 | function Merge-TomlBlock { |
| 48 | param( |
| 49 | [string]$Existing, |
| 50 | [string]$Overlay |
| 51 | ) |
| 52 | # Append overlay if settings missing; if exists, append overlay as commented block + key overrides for known sections. |
| 53 | if (-not $Existing) { |
| 54 | return $Overlay |
| 55 | } |
| 56 | $marker = "# --- harness-neumann-t1 overlay (Setup-CideHarness.ps1) ---" |
| 57 | if ($Existing -match [regex]::Escape($marker)) { |
| 58 | $before = ($Existing -split [regex]::Escape($marker))[0].TrimEnd() |
| 59 | return "$before`n`n$marker`n$Overlay" |
| 60 | } |
| 61 | return "$($Existing.TrimEnd())`n`n$marker`n$Overlay" |
| 62 | } |
| 63 | |
| 64 | Write-Step "CIDE harness setup (Apply=$Apply)" |
| 65 | Write-Step "Target: $cideDir" |
| 66 | |
| 67 | if (-not (Test-Path $overlayPath)) { |
| 68 | throw "Missing overlay: $overlayPath" |
| 69 | } |
| 70 | |
| 71 | $overlay = Get-Content -Raw -Path $overlayPath |
| 72 | if ($AgentNotesConfigPath) { |
| 73 | $overlay = $overlay -replace 'config_path = "D:/agent-notes-mcp/agent-notes-mcp.toml"', |
| 74 | "config_path = `"$($AgentNotesConfigPath.Replace('\', '/'))`"" |
| 75 | } |
| 76 | |
| 77 | if (-not $Apply) { |
| 78 | Write-Host "`n[DRY-RUN] Would ensure directory: $cideDir" |
| 79 | Write-Host "[DRY-RUN] Would merge overlay into: $settingsPath" |
| 80 | if (-not $SkipExternalMcp) { |
| 81 | Write-Host "[DRY-RUN] Would write: $externalDest" |
| 82 | } |
| 83 | Write-Host "`nRe-run with -Apply. Set -AgentNotesConfigPath or env CIDE_AGENT_NOTES_CONFIG." |
| 84 | exit 0 |
| 85 | } |
| 86 | |
| 87 | New-Item -ItemType Directory -Force -Path $cideDir | Out-Null |
| 88 | |
| 89 | $existingSettings = '' |
| 90 | if (Test-Path $settingsPath) { |
| 91 | $existingSettings = Get-Content -Raw -Path $settingsPath |
| 92 | } |
| 93 | $merged = Merge-TomlBlock -Existing $existingSettings -Overlay $overlay |
| 94 | Set-Content -Path $settingsPath -Value $merged -Encoding utf8NoBOM |
| 95 | Write-Step "Updated $settingsPath" |
| 96 | |
| 97 | if (-not $SkipExternalMcp) { |
| 98 | if (-not (Test-Path $externalTemplate)) { |
| 99 | throw "Missing template: $externalTemplate" |
| 100 | } |
| 101 | $json = Get-Content -Raw -Path $externalTemplate | ConvertFrom-Json |
| 102 | foreach ($entry in $json) { |
| 103 | if ($entry.name -eq 'roslyn' -and $RoslynMcpExe) { $entry.command = $RoslynMcpExe } |
| 104 | if ($entry.name -eq 'python' -and $PythonMcpExe) { $entry.command = $PythonMcpExe } |
| 105 | } |
| 106 | $json | ConvertTo-Json -Depth 5 | Set-Content -Path $externalDest -Encoding utf8 |
| 107 | Write-Step "Wrote $externalDest (edit paths if exe not built yet)" |
| 108 | } |
| 109 | |
| 110 | Write-Host @" |
| 111 | |
| 112 | Done. Manual steps: |
| 113 | 1. ai.mode — НЕ меняется overlay (local | mcp_only | cloud | acp). Cloud FM: harness-cloud-fm.overlay.toml + ai-keys.toml |
| 114 | 2. Smoke harness: read_hot_context / ide_agent_status (in-proc; mcp_only = внешний MCP-клиент) |
| 115 | 3. Cursor until ~Aug 2026: hooks.json for checkpoint |
| 116 | 4. ACP: suppress_acp_ide_stdio_inject in [agent.harness] (0082 loopback backlog) |
| 117 | |
| 118 | "@ |
| 119 | |