Forge
powershelldeeb25a2
1# Пример: проверка контракта агента (--agent-contract) из CI на PowerShell.
2# В репозитории чаще используют dotnet-script — см. agent-contract-ci.csx рядом.
3# Рекомендуется PowerShell 7+ (pwsh): после вызова нативного .exe доступен $LASTEXITCODE.
4# В Windows PowerShell 5.1 $LASTEXITCODE после & exe не всегда заполняется — используй Start-Process -PassThru.ExitCode или pwsh.
5
6param(
7 [Parameter(Mandatory = $true, HelpMessage = "Путь к CascadeIDE.exe после publish/build.")]
8 [string] $CascadeIdeExe,
9 [string] $Workspace = (Get-Location).ProviderPath
10)
11
12$ErrorActionPreference = "Stop"
13
14if (-not (Test-Path -LiteralPath $CascadeIdeExe)) {
15 throw "CascadeIDE not found: $CascadeIdeExe"
16}
17
18function Invoke-AgentContract {
19 param([string[]] $Arguments)
20 $raw = & $CascadeIdeExe @Arguments 2>&1
21 $code = $LASTEXITCODE
22 $text = if ($null -eq $raw) {
23 ""
24 } elseif ($raw -is [System.Array]) {
25 $raw -join [Environment]::NewLine
26 } else {
27 [string]$raw
28 }
29 if ($code -ne 0) {
30 throw "agent-contract failed (exit $code): $text"
31 }
32 return $text
33}
34
35# Без git — только stdout JSON
36$uiModesJson = Invoke-AgentContract -Arguments @("--agent-contract", "get_ui_modes_diagnostics")
37if ([string]::IsNullOrWhiteSpace($uiModesJson)) { throw "empty JSON from get_ui_modes_diagnostics" }
38
39$langJson = Invoke-AgentContract -Arguments @("--agent-contract", "get_supported_editor_languages")
40
41$solutionJson = Invoke-AgentContract -Arguments @("--agent-contract", "get_solution_info")
42$null = $solutionJson | ConvertFrom-Json
43
44$cockpitJson = Invoke-AgentContract -Arguments @("--agent-contract", "get_cockpit_surface")
45$null = $cockpitJson | ConvertFrom-Json
46
47$ideStateJson = Invoke-AgentContract -Arguments @("--agent-contract", "get_ide_state")
48$wsObj = $ideStateJson | ConvertFrom-Json
49if (-not $wsObj.PSObject.Properties.Match('cockpit_surface')) { throw "get_ide_state: missing cockpit_surface" }
50
51# Git — явный корень репозитория (как в MCP)
52$gitJson = Invoke-AgentContract -Arguments @("--agent-contract", "--workspace", $Workspace, "git_status")
53
54Write-Host "OK: ui_modes=$($uiModesJson.Length) lang=$($langJson.Length) solution=$($solutionJson.Length) cockpit=$($cockpitJson.Length) ide_state=$($ideStateJson.Length) git=$($gitJson.Length)"
55
View only · write via MCP/CIDE