@ludi-uni/ludi-agent-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +55 -0
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/adapters/codex/README.md +24 -0
- package/adapters/codex/skill-metadata/visual-verification/agents/openai.yaml +7 -0
- package/adapters/pi/README.md +88 -0
- package/adapters/pi/browser/agent-browser.mjs +193 -0
- package/adapters/pi/lib/invoke.mjs +55 -0
- package/adapters/pi/lib/list-models.mjs +29 -0
- package/adapters/pi/lib/settings-proposal.mjs +34 -0
- package/adapters/pi/lib/subagent.mjs +175 -0
- package/adapters/pi/loop-guard/index.js +51 -0
- package/adapters/pi/maintenance-policy.json +36 -0
- package/adapters/pi/mcp.template.json +4 -0
- package/adapters/pi/model-catalog.json +97 -0
- package/adapters/pi/models.json +13 -0
- package/adapters/pi/models.local.example.json +14 -0
- package/adapters/pi/orchestrator-ext/command.mjs +14 -0
- package/adapters/pi/orchestrator-ext/index.js +150 -0
- package/adapters/pi/settings.template.json +7 -0
- package/adapters/pi/shell-gate/index.js +70 -0
- package/adapters/pi/sync-pi.ps1 +137 -0
- package/agents/README.md +26 -0
- package/agents/browser.md +64 -0
- package/agents/coder.md +31 -0
- package/agents/orchestrator.md +37 -0
- package/agents/reviewer.md +32 -0
- package/agents/scout.md +35 -0
- package/agents/tester.md +28 -0
- package/agents/visual.md +28 -0
- package/context-pack/SPEC.md +101 -0
- package/context-pack/context-pack.schema.json +79 -0
- package/context-pack/examples/example-fix.md +44 -0
- package/docs/architecture.md +55 -0
- package/docs/migration-from-codex-setting.md +44 -0
- package/docs/model-maintenance.md +401 -0
- package/docs/orchestrator.md +155 -0
- package/docs/phase2-report.md +39 -0
- package/docs/roadmap.md +27 -0
- package/docs/third-party.md +15 -0
- package/lib/agents.mjs +79 -0
- package/lib/context-pack.mjs +215 -0
- package/lib/job.mjs +312 -0
- package/lib/language-policy.mjs +27 -0
- package/lib/maintenance-exec.mjs +377 -0
- package/lib/maintenance-runner.mjs +266 -0
- package/lib/maintenance.mjs +422 -0
- package/lib/normalize.mjs +101 -0
- package/lib/observe/differ.mjs +185 -0
- package/lib/observe/observation.mjs +147 -0
- package/lib/observe/observers.mjs +134 -0
- package/lib/observe/sources.mjs +154 -0
- package/lib/orchestrator/activity.mjs +249 -0
- package/lib/orchestrator/api.mjs +151 -0
- package/lib/orchestrator/contract.mjs +68 -0
- package/lib/orchestrator/escalation.mjs +84 -0
- package/lib/orchestrator/evaluator.mjs +92 -0
- package/lib/orchestrator/failures.mjs +88 -0
- package/lib/orchestrator/health.mjs +53 -0
- package/lib/orchestrator/orchestrator.mjs +483 -0
- package/lib/orchestrator/permissions.mjs +64 -0
- package/lib/orchestrator/planner.mjs +194 -0
- package/lib/orchestrator/policy.mjs +134 -0
- package/lib/orchestrator/router.mjs +45 -0
- package/lib/orchestrator/runner.mjs +278 -0
- package/lib/orchestrator/shell-policy.mjs +52 -0
- package/lib/orchestrator/store.mjs +581 -0
- package/lib/orchestrator/task-store.mjs +79 -0
- package/lib/orchestrator/turn-budget.mjs +63 -0
- package/lib/orchestrator/worktree.mjs +72 -0
- package/lib/pipeline.mjs +279 -0
- package/lib/registry.mjs +63 -0
- package/lib/resolve.mjs +35 -0
- package/lib/routing.mjs +137 -0
- package/lib/telemetry.mjs +222 -0
- package/mcp/README.md +11 -0
- package/mcp/servers.json +13 -0
- package/orchestration/decision-policy.json +66 -0
- package/package.json +56 -0
- package/routing/README.md +24 -0
- package/routing/routing.json +81 -0
- package/routing/routing.schema.json +66 -0
- package/rules/README.md +10 -0
- package/rules/common.md +52 -0
- package/rules/loop-prevention.md +15 -0
- package/rules/repo-local.md +6 -0
- package/scripts/check-environment.ps1 +22 -0
- package/scripts/context-pack.mjs +17 -0
- package/scripts/e2e-investigate-repro.mjs +66 -0
- package/scripts/model-maintenance-job.mjs +59 -0
- package/scripts/observe-models.mjs +97 -0
- package/scripts/orchestrate.mjs +137 -0
- package/scripts/reevaluate-models.mjs +95 -0
- package/scripts/report-model-maintenance.mjs +70 -0
- package/scripts/resolve-capabilities.mjs +39 -0
- package/scripts/run-pipeline.mjs +56 -0
- package/scripts/sync-agents-md.ps1 +10 -0
- package/scripts/validate.mjs +71 -0
- package/skills/README.md +14 -0
- package/skills/pi-workflow/SKILL.md +26 -0
- package/skills/pi-workflow/references/code-investigation-and-fix.md +16 -0
- package/skills/pi-workflow/references/research.md +14 -0
- package/skills/pi-workflow/references/review.md +11 -0
- package/skills/pi-workflow/references/visual-work.md +14 -0
- package/skills/project-management/SKILL.md +106 -0
- package/skills/project-management/references/operations.md +52 -0
- package/skills/visual-verification/SKILL.md +88 -0
- package/skills/visual-verification/scripts/analyze-speech.ps1 +346 -0
- package/skills/visual-verification/scripts/backends/whisperx_backend.py +234 -0
- package/skills/visual-verification/scripts/common.ps1 +387 -0
- package/skills/visual-verification/scripts/contact-sheet.ps1 +121 -0
- package/skills/visual-verification/scripts/desktop-discover.ps1 +45 -0
- package/skills/visual-verification/scripts/desktop-inspect.ps1 +67 -0
- package/skills/visual-verification/scripts/desktop-record.ps1 +97 -0
- package/skills/visual-verification/scripts/desktop-screenshot.ps1 +65 -0
- package/skills/visual-verification/scripts/evaluate-sync.ps1 +249 -0
- package/skills/visual-verification/scripts/extract-frames.ps1 +79 -0
- package/skills/visual-verification/scripts/inspect-media.ps1 +138 -0
- package/skills/visual-verification/scripts/record-av.ps1 +102 -0
- package/skills/visual-verification/scripts/record.ps1 +72 -0
- package/skills/visual-verification/scripts/screenshot.ps1 +44 -0
- package/skills/visual-verification/scripts/waveform.ps1 +450 -0
- package/skills/visual-verification/scripts/winapp-common.ps1 +465 -0
- package/tests/activity.test.mjs +252 -0
- package/tests/attempt-budget.test.mjs +102 -0
- package/tests/browser.test.mjs +121 -0
- package/tests/context-pack.test.mjs +98 -0
- package/tests/dirty-gate.test.mjs +211 -0
- package/tests/e2e-browser.mjs +66 -0
- package/tests/e2e-real-orchestrator-resume.mjs +101 -0
- package/tests/e2e-real-orchestrator.mjs +41 -0
- package/tests/e2e-real-pi.mjs +27 -0
- package/tests/e2e-real-tool-orchestrator.mjs +66 -0
- package/tests/fixtures/browser-page/index.html +20 -0
- package/tests/fixtures/maintenance/availability.txt +5 -0
- package/tests/fixtures/maintenance/catalog.json +74 -0
- package/tests/fixtures/maintenance/events.json +13 -0
- package/tests/fixtures/math-repo/README.md +3 -0
- package/tests/fixtures/math-repo/package.json +7 -0
- package/tests/fixtures/math-repo/src/math.js +11 -0
- package/tests/fixtures/math-repo/test/math.test.js +7 -0
- package/tests/fixtures/observe/announcements.json +8 -0
- package/tests/fixtures/orch-concurrent-child.mjs +44 -0
- package/tests/fixtures/orch-persist-child.mjs +61 -0
- package/tests/job.test.mjs +230 -0
- package/tests/kit.test.mjs +79 -0
- package/tests/language-policy.test.mjs +93 -0
- package/tests/loop-guard.test.mjs +60 -0
- package/tests/maintenance-exec.test.mjs +218 -0
- package/tests/maintenance-runner.test.mjs +222 -0
- package/tests/maintenance.test.mjs +195 -0
- package/tests/observe.test.mjs +283 -0
- package/tests/observer-registry.test.mjs +157 -0
- package/tests/orchestrator-cleanup.test.mjs +358 -0
- package/tests/orchestrator-command.test.mjs +14 -0
- package/tests/orchestrator-persist.test.mjs +375 -0
- package/tests/orchestrator-tools.test.mjs +215 -0
- package/tests/orchestrator.test.mjs +396 -0
- package/tests/package.test.mjs +37 -0
- package/tests/pipeline.test.mjs +239 -0
- package/tests/planner-classification.test.mjs +81 -0
- package/tests/planner-split.test.mjs +67 -0
- package/tests/qoder-observer.test.mjs +266 -0
- package/tests/reassign-progression.test.mjs +104 -0
- package/tests/retry-escalation.test.mjs +120 -0
- package/tests/routing.test.mjs +110 -0
- package/tests/sqlite-concurrency.test.mjs +178 -0
- package/tests/task-global-e2e.test.mjs +63 -0
- package/tests/task-global-failed.test.mjs +134 -0
- package/tests/telemetry.test.mjs +173 -0
- package/tests/test-sync-pi.ps1 +56 -0
- package/tests/turn-budget.test.mjs +106 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
Set-StrictMode -Version Latest
|
|
2
|
+
|
|
3
|
+
$script:WinAppTestedVersion = '0.6.1'
|
|
4
|
+
|
|
5
|
+
function New-WinAppException {
|
|
6
|
+
[OutputType([System.InvalidOperationException])]
|
|
7
|
+
[CmdletBinding()]
|
|
8
|
+
param(
|
|
9
|
+
[Parameter(Mandatory)][string]$Code,
|
|
10
|
+
[Parameter(Mandatory)][string]$Message,
|
|
11
|
+
[string]$UpstreamCode,
|
|
12
|
+
[string]$UpstreamType,
|
|
13
|
+
[Nullable[int]]$ExitCode
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
$exception = [System.InvalidOperationException]::new($Message)
|
|
17
|
+
$exception.Data['WinAppErrorCode'] = $Code
|
|
18
|
+
if (-not [string]::IsNullOrWhiteSpace($UpstreamCode)) { $exception.Data['WinAppUpstreamCode'] = $UpstreamCode }
|
|
19
|
+
if (-not [string]::IsNullOrWhiteSpace($UpstreamType)) { $exception.Data['WinAppUpstreamType'] = $UpstreamType }
|
|
20
|
+
if ($null -ne $ExitCode) { $exception.Data['WinAppExitCode'] = [int]$ExitCode }
|
|
21
|
+
return $exception
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Get-WinAppVersionClassification {
|
|
25
|
+
[OutputType([string])]
|
|
26
|
+
[CmdletBinding()]
|
|
27
|
+
param([string]$ActualVersion)
|
|
28
|
+
|
|
29
|
+
if ([string]::IsNullOrWhiteSpace($ActualVersion)) { return 'NOT_INSTALLED' }
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
$actual = [Version]::Parse($ActualVersion)
|
|
33
|
+
$tested = [Version]::Parse($script:WinAppTestedVersion)
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return 'UNTESTED_NEWER'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ($actual -eq $tested) { return 'SUPPORTED_TESTED' }
|
|
40
|
+
if ($actual -gt $tested) { return 'UNTESTED_NEWER' }
|
|
41
|
+
return 'UNSUPPORTED_OLDER'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Invoke-WinAppProcess {
|
|
45
|
+
[OutputType([pscustomobject])]
|
|
46
|
+
[CmdletBinding()]
|
|
47
|
+
param(
|
|
48
|
+
[Parameter(Mandatory)][string]$Executable,
|
|
49
|
+
[Parameter(Mandatory)][string[]]$Arguments
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
$startInfo = [Diagnostics.ProcessStartInfo]::new()
|
|
53
|
+
$startInfo.FileName = $Executable
|
|
54
|
+
$startInfo.UseShellExecute = $false
|
|
55
|
+
$startInfo.RedirectStandardOutput = $true
|
|
56
|
+
$startInfo.RedirectStandardError = $true
|
|
57
|
+
$startInfo.CreateNoWindow = $true
|
|
58
|
+
$startInfo.Environment['WINAPP_CLI_TELEMETRY_OPTOUT'] = '1'
|
|
59
|
+
foreach ($argument in $Arguments) { [void]$startInfo.ArgumentList.Add($argument) }
|
|
60
|
+
|
|
61
|
+
$process = [Diagnostics.Process]::new()
|
|
62
|
+
$process.StartInfo = $startInfo
|
|
63
|
+
try {
|
|
64
|
+
if (-not $process.Start()) { throw 'Process start returned false.' }
|
|
65
|
+
$stdoutTask = $process.StandardOutput.ReadToEndAsync()
|
|
66
|
+
$stderrTask = $process.StandardError.ReadToEndAsync()
|
|
67
|
+
$process.WaitForExit()
|
|
68
|
+
$stdout = $stdoutTask.GetAwaiter().GetResult()
|
|
69
|
+
$stderr = $stderrTask.GetAwaiter().GetResult()
|
|
70
|
+
return [pscustomobject]@{
|
|
71
|
+
exit_code = $process.ExitCode
|
|
72
|
+
stdout = $stdout
|
|
73
|
+
stderr = $stderr
|
|
74
|
+
arguments = @($Arguments)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw (New-WinAppException -Code 'WINAPP_NOT_INSTALLED' -Message "WinApp CLI could not be started: $($_.Exception.Message)")
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
$process.Dispose()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Get-WinAppVersionInfo {
|
|
86
|
+
[OutputType([pscustomobject])]
|
|
87
|
+
[CmdletBinding()]
|
|
88
|
+
param([string]$Executable)
|
|
89
|
+
|
|
90
|
+
if ([string]::IsNullOrWhiteSpace($Executable)) {
|
|
91
|
+
$command = Get-Command winapp -ErrorAction SilentlyContinue
|
|
92
|
+
if ($null -eq $command -or $command.CommandType -ne [Management.Automation.CommandTypes]::Application) {
|
|
93
|
+
return [pscustomobject]@{ executable = $null; actual = $null; tested = $script:WinAppTestedVersion; classification = 'NOT_INSTALLED' }
|
|
94
|
+
}
|
|
95
|
+
$Executable = $command.Source
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
$resolvedExecutable = [IO.Path]::GetFullPath($Executable)
|
|
99
|
+
$result = Invoke-WinAppProcess -Executable $resolvedExecutable -Arguments @('--version')
|
|
100
|
+
$combined = "$($result.stdout)`n$($result.stderr)"
|
|
101
|
+
$match = [regex]::Match($combined, '(?m)(?<version>\d+\.\d+\.\d+(?:\.\d+)?)')
|
|
102
|
+
if ($result.exit_code -ne 0 -or -not $match.Success) {
|
|
103
|
+
throw (New-WinAppException -Code 'WINAPP_COMMAND_FAILED' -Message 'WinApp CLI version could not be determined.' -ExitCode $result.exit_code)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
$actual = $match.Groups['version'].Value
|
|
107
|
+
return [pscustomobject]@{
|
|
108
|
+
executable = $resolvedExecutable
|
|
109
|
+
actual = $actual
|
|
110
|
+
tested = $script:WinAppTestedVersion
|
|
111
|
+
classification = Get-WinAppVersionClassification -ActualVersion $actual
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function Assert-WinAppCaptureReady {
|
|
116
|
+
[CmdletBinding()]
|
|
117
|
+
param([Parameter(Mandatory)][pscustomobject]$VersionInfo)
|
|
118
|
+
|
|
119
|
+
switch ($VersionInfo.classification) {
|
|
120
|
+
'NOT_INSTALLED' { throw (New-WinAppException -Code 'WINAPP_NOT_INSTALLED' -Message 'WinApp CLI is not installed or is not available on PATH.') }
|
|
121
|
+
'UNSUPPORTED_OLDER' { throw (New-WinAppException -Code 'WINAPP_VERSION_UNTESTED' -Message "WinApp CLI $($VersionInfo.actual) is older than the tested $($VersionInfo.tested) contract.") }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function Get-WinAppPropertyValue {
|
|
126
|
+
param($InputObject, [Parameter(Mandatory)][string]$Name, $Default = $null)
|
|
127
|
+
if ($null -eq $InputObject) { return $Default }
|
|
128
|
+
$property = $InputObject.PSObject.Properties[$Name]
|
|
129
|
+
if ($null -eq $property) { return $Default }
|
|
130
|
+
return $property.Value
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function ConvertTo-WinAppError {
|
|
134
|
+
[OutputType([pscustomobject])]
|
|
135
|
+
[CmdletBinding()]
|
|
136
|
+
param(
|
|
137
|
+
[Parameter(Mandatory)][int]$ExitCode,
|
|
138
|
+
[string]$StdOut,
|
|
139
|
+
[string]$StdErr,
|
|
140
|
+
[Parameter(Mandatory)][ValidateSet('discover', 'screenshot', 'record', 'inspect')][string]$Operation
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
$raw = @($StdOut, $StdErr) -join "`n"
|
|
144
|
+
$upstreamCode = $null
|
|
145
|
+
$upstreamType = $null
|
|
146
|
+
$message = $raw.Trim()
|
|
147
|
+
foreach ($candidate in @($StdOut, $StdErr)) {
|
|
148
|
+
if ([string]::IsNullOrWhiteSpace($candidate)) { continue }
|
|
149
|
+
try {
|
|
150
|
+
$parsed = $candidate | ConvertFrom-Json -ErrorAction Stop
|
|
151
|
+
$errorObject = Get-WinAppPropertyValue -InputObject $parsed -Name 'error'
|
|
152
|
+
if ($null -ne $errorObject) {
|
|
153
|
+
$upstreamCode = [string](Get-WinAppPropertyValue -InputObject $errorObject -Name 'code')
|
|
154
|
+
$upstreamType = [string](Get-WinAppPropertyValue -InputObject $errorObject -Name 'details')
|
|
155
|
+
$parsedMessage = [string](Get-WinAppPropertyValue -InputObject $errorObject -Name 'message')
|
|
156
|
+
if (-not [string]::IsNullOrWhiteSpace($parsedMessage)) { $message = $parsedMessage }
|
|
157
|
+
break
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
$evidence = "$upstreamCode`n$upstreamType`n$message"
|
|
164
|
+
$code = if ($evidence -match '(?i)ambiguous|matched\s+\d+\s+(?:windows|elements)|UiAmbiguousSelectorException') {
|
|
165
|
+
'WINDOW_TARGET_AMBIGUOUS'
|
|
166
|
+
}
|
|
167
|
+
elseif ($evidence -match '(?i)missing_app|no_target|not found|no visible window|element_not_found') {
|
|
168
|
+
'WINDOW_NOT_FOUND'
|
|
169
|
+
}
|
|
170
|
+
elseif ($Operation -eq 'screenshot') { 'CAPTURE_FAILED' }
|
|
171
|
+
elseif ($Operation -eq 'record') { 'RECORD_FAILED' }
|
|
172
|
+
else { 'WINAPP_COMMAND_FAILED' }
|
|
173
|
+
|
|
174
|
+
return [pscustomobject]@{
|
|
175
|
+
code = $code
|
|
176
|
+
message = if ([string]::IsNullOrWhiteSpace($message)) { "WinApp CLI $Operation failed." } else { $message }
|
|
177
|
+
operation = $Operation
|
|
178
|
+
exit_code = $ExitCode
|
|
179
|
+
upstream_code = $upstreamCode
|
|
180
|
+
upstream_type = $upstreamType
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function Invoke-WinAppJson {
|
|
185
|
+
[OutputType([pscustomobject])]
|
|
186
|
+
[CmdletBinding()]
|
|
187
|
+
param(
|
|
188
|
+
[Parameter(Mandatory)][string]$Executable,
|
|
189
|
+
[Parameter(Mandatory)][string[]]$Arguments,
|
|
190
|
+
[Parameter(Mandatory)][ValidateSet('discover', 'screenshot', 'record', 'inspect')][string]$Operation
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
$result = Invoke-WinAppProcess -Executable $Executable -Arguments $Arguments
|
|
194
|
+
if ($result.exit_code -ne 0) {
|
|
195
|
+
$failure = ConvertTo-WinAppError -ExitCode $result.exit_code -StdOut $result.stdout -StdErr $result.stderr -Operation $Operation
|
|
196
|
+
throw (New-WinAppException -Code $failure.code -Message $failure.message -UpstreamCode $failure.upstream_code -UpstreamType $failure.upstream_type -ExitCode $failure.exit_code)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
try { $data = $result.stdout | ConvertFrom-Json -ErrorAction Stop }
|
|
200
|
+
catch {
|
|
201
|
+
throw (New-WinAppException -Code 'WINAPP_COMMAND_FAILED' -Message "WinApp CLI $Operation returned invalid JSON." -ExitCode $result.exit_code)
|
|
202
|
+
}
|
|
203
|
+
return [pscustomobject]@{ data = $data; process = $result }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function Select-WinAppWindowCandidate {
|
|
207
|
+
[OutputType([pscustomobject])]
|
|
208
|
+
[CmdletBinding()]
|
|
209
|
+
param(
|
|
210
|
+
[Parameter(Mandatory)]$Candidates,
|
|
211
|
+
[string]$ProcessName,
|
|
212
|
+
[string]$WindowTitle,
|
|
213
|
+
[string]$ClassName,
|
|
214
|
+
[Nullable[int]]$ProcessId,
|
|
215
|
+
[Nullable[long]]$Hwnd,
|
|
216
|
+
[Nullable[int]]$Width,
|
|
217
|
+
[Nullable[int]]$Height
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
$matches = @($Candidates)
|
|
221
|
+
if (-not [string]::IsNullOrWhiteSpace($ProcessName)) { $matches = @($matches | Where-Object { [string](Get-WinAppPropertyValue $_ 'processName') -ieq $ProcessName }) }
|
|
222
|
+
if (-not [string]::IsNullOrWhiteSpace($WindowTitle)) { $matches = @($matches | Where-Object { [string](Get-WinAppPropertyValue $_ 'title') -ceq $WindowTitle }) }
|
|
223
|
+
if (-not [string]::IsNullOrWhiteSpace($ClassName)) { $matches = @($matches | Where-Object { [string](Get-WinAppPropertyValue $_ 'className') -ceq $ClassName }) }
|
|
224
|
+
if ($null -ne $ProcessId) { $matches = @($matches | Where-Object { [int](Get-WinAppPropertyValue $_ 'processId' -1) -eq [int]$ProcessId }) }
|
|
225
|
+
if ($null -ne $Hwnd) { $matches = @($matches | Where-Object { [long](Get-WinAppPropertyValue $_ 'hwnd' -1) -eq [long]$Hwnd }) }
|
|
226
|
+
if ($null -ne $Width) { $matches = @($matches | Where-Object { [int](Get-WinAppPropertyValue $_ 'width' -1) -eq [int]$Width }) }
|
|
227
|
+
if ($null -ne $Height) { $matches = @($matches | Where-Object { [int](Get-WinAppPropertyValue $_ 'height' -1) -eq [int]$Height }) }
|
|
228
|
+
|
|
229
|
+
if ($matches.Count -eq 0) { throw (New-WinAppException -Code 'WINDOW_NOT_FOUND' -Message 'No window matched the requested identity and filters.') }
|
|
230
|
+
if ($matches.Count -gt 1) { throw (New-WinAppException -Code 'WINDOW_TARGET_AMBIGUOUS' -Message "$($matches.Count) windows matched; add an exact title, class, PID, HWND, or size filter.") }
|
|
231
|
+
|
|
232
|
+
$window = $matches[0]
|
|
233
|
+
return [pscustomobject]@{
|
|
234
|
+
process_name = [string](Get-WinAppPropertyValue $window 'processName')
|
|
235
|
+
window_title = [string](Get-WinAppPropertyValue $window 'title')
|
|
236
|
+
class_name = [string](Get-WinAppPropertyValue $window 'className')
|
|
237
|
+
process_id = [int](Get-WinAppPropertyValue $window 'processId' 0)
|
|
238
|
+
hwnd = [long](Get-WinAppPropertyValue $window 'hwnd' 0)
|
|
239
|
+
width = [int](Get-WinAppPropertyValue $window 'width' 0)
|
|
240
|
+
height = [int](Get-WinAppPropertyValue $window 'height' 0)
|
|
241
|
+
owner_hwnd = [long](Get-WinAppPropertyValue $window 'ownerHwnd' 0)
|
|
242
|
+
is_foreground = [bool](Get-WinAppPropertyValue $window 'isForeground' $false)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function Get-WinAppWindowTarget {
|
|
247
|
+
[OutputType([pscustomobject])]
|
|
248
|
+
[CmdletBinding()]
|
|
249
|
+
param(
|
|
250
|
+
[Parameter(Mandatory)][string]$Executable,
|
|
251
|
+
[string]$App,
|
|
252
|
+
[string]$ProcessName,
|
|
253
|
+
[string]$WindowTitle,
|
|
254
|
+
[string]$ClassName,
|
|
255
|
+
[Nullable[int]]$ProcessId,
|
|
256
|
+
[Nullable[long]]$Hwnd,
|
|
257
|
+
[Nullable[int]]$Width,
|
|
258
|
+
[Nullable[int]]$Height
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
if ($null -ne $Hwnd) {
|
|
262
|
+
$status = Invoke-WinAppJson -Executable $Executable -Arguments @('ui', 'status', '-w', ([long]$Hwnd).ToString([Globalization.CultureInfo]::InvariantCulture), '--json') -Operation discover
|
|
263
|
+
$statusPid = [int](Get-WinAppPropertyValue $status.data 'processId' 0)
|
|
264
|
+
if ($statusPid -le 0) { throw (New-WinAppException -Code 'WINDOW_NOT_FOUND' -Message "HWND $Hwnd did not resolve to a process.") }
|
|
265
|
+
$query = $statusPid.ToString([Globalization.CultureInfo]::InvariantCulture)
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
$query = if (-not [string]::IsNullOrWhiteSpace($App)) { $App }
|
|
269
|
+
elseif ($null -ne $ProcessId) { ([int]$ProcessId).ToString([Globalization.CultureInfo]::InvariantCulture) }
|
|
270
|
+
elseif (-not [string]::IsNullOrWhiteSpace($ProcessName)) { $ProcessName }
|
|
271
|
+
elseif (-not [string]::IsNullOrWhiteSpace($WindowTitle)) { $WindowTitle }
|
|
272
|
+
else { throw (New-WinAppException -Code 'WINDOW_NOT_FOUND' -Message 'Specify App, ProcessName, WindowTitle, PID, or HWND for bounded discovery.') }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
$listed = Invoke-WinAppJson -Executable $Executable -Arguments @('ui', 'list-windows', '-a', $query, '--json') -Operation discover
|
|
276
|
+
return Select-WinAppWindowCandidate -Candidates $listed.data -ProcessName $ProcessName -WindowTitle $WindowTitle -ClassName $ClassName -ProcessId $ProcessId -Hwnd $Hwnd -Width $Width -Height $Height
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function New-WinAppScreenshotArguments {
|
|
280
|
+
[OutputType([string[]])]
|
|
281
|
+
[CmdletBinding()]
|
|
282
|
+
param([Parameter(Mandatory)][long]$Hwnd, [Parameter(Mandatory)][string]$OutputPath)
|
|
283
|
+
return [string[]]@('ui', 'screenshot', '-w', $Hwnd.ToString([Globalization.CultureInfo]::InvariantCulture), '--output', [IO.Path]::GetFullPath($OutputPath), '--json')
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function New-WinAppRecordArguments {
|
|
287
|
+
[OutputType([string[]])]
|
|
288
|
+
[CmdletBinding()]
|
|
289
|
+
param(
|
|
290
|
+
[Parameter(Mandatory)][long]$Hwnd,
|
|
291
|
+
[Parameter(Mandatory)][string]$OutputPath,
|
|
292
|
+
[double]$Duration = 5,
|
|
293
|
+
[int]$Fps = 5,
|
|
294
|
+
[switch]$Frames,
|
|
295
|
+
[int]$MaxEdge = 1280
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
if ([double]::IsNaN($Duration) -or [double]::IsInfinity($Duration) -or $Duration -lt 1 -or $Duration -gt 60) { throw 'Duration must be between 1 and 60 seconds.' }
|
|
299
|
+
if ($Fps -lt 1 -or $Fps -gt 60) { throw 'Fps must be between 1 and 60.' }
|
|
300
|
+
if ($Frames -and $Fps -gt 30) { throw 'Fps must be between 1 and 30 when frame artifacts are enabled.' }
|
|
301
|
+
if ($Frames -and ($MaxEdge -lt 64 -or $MaxEdge -gt 4096)) { throw 'MaxEdge must be between 64 and 4096 when frame artifacts are enabled.' }
|
|
302
|
+
|
|
303
|
+
$culture = [Globalization.CultureInfo]::InvariantCulture
|
|
304
|
+
$arguments = [Collections.Generic.List[string]]::new()
|
|
305
|
+
foreach ($value in @('ui', 'record', '-w', $Hwnd.ToString($culture), '--duration-sec', $Duration.ToString('G17', $culture), '--fps', $Fps.ToString($culture), '--output', [IO.Path]::GetFullPath($OutputPath))) { [void]$arguments.Add($value) }
|
|
306
|
+
if ($Frames) {
|
|
307
|
+
[void]$arguments.Add('--frames')
|
|
308
|
+
[void]$arguments.Add('--max-edge')
|
|
309
|
+
[void]$arguments.Add($MaxEdge.ToString($culture))
|
|
310
|
+
}
|
|
311
|
+
[void]$arguments.Add('--json')
|
|
312
|
+
return [string[]]$arguments.ToArray()
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function New-WinAppInspectArguments {
|
|
316
|
+
[OutputType([string[]])]
|
|
317
|
+
[CmdletBinding()]
|
|
318
|
+
param([Parameter(Mandatory)][long]$Hwnd, [ValidateRange(1, 20)][int]$Depth = 6, [switch]$Interactive)
|
|
319
|
+
$arguments = [Collections.Generic.List[string]]::new()
|
|
320
|
+
foreach ($value in @('ui', 'inspect', '-w', $Hwnd.ToString([Globalization.CultureInfo]::InvariantCulture), '--depth', $Depth.ToString([Globalization.CultureInfo]::InvariantCulture))) { [void]$arguments.Add($value) }
|
|
321
|
+
if ($Interactive) { [void]$arguments.Add('--interactive') }
|
|
322
|
+
[void]$arguments.Add('--json')
|
|
323
|
+
return [string[]]$arguments.ToArray()
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function Get-PngDimensions {
|
|
327
|
+
[OutputType([pscustomobject])]
|
|
328
|
+
[CmdletBinding()]
|
|
329
|
+
param([Parameter(Mandatory)][string]$Path)
|
|
330
|
+
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { throw (New-WinAppException -Code 'CAPTURE_FAILED' -Message "Screenshot output is missing: $Path") }
|
|
331
|
+
$bytes = [byte[]]::new(24)
|
|
332
|
+
$stream = [IO.File]::OpenRead($Path)
|
|
333
|
+
try { $read = $stream.Read($bytes, 0, $bytes.Length) }
|
|
334
|
+
finally { $stream.Dispose() }
|
|
335
|
+
$signature = [byte[]](137, 80, 78, 71, 13, 10, 26, 10)
|
|
336
|
+
if ($read -lt 24) { throw (New-WinAppException -Code 'CAPTURE_FAILED' -Message 'Screenshot output is not a valid PNG.') }
|
|
337
|
+
for ($index = 0; $index -lt $signature.Length; $index++) { if ($bytes[$index] -ne $signature[$index]) { throw (New-WinAppException -Code 'CAPTURE_FAILED' -Message 'Screenshot output is not a valid PNG.') } }
|
|
338
|
+
$width = [int]($bytes[16] * 16777216 + $bytes[17] * 65536 + $bytes[18] * 256 + $bytes[19])
|
|
339
|
+
$height = [int]($bytes[20] * 16777216 + $bytes[21] * 65536 + $bytes[22] * 256 + $bytes[23])
|
|
340
|
+
if ($width -le 0 -or $height -le 0) { throw (New-WinAppException -Code 'CAPTURE_FAILED' -Message 'Screenshot PNG has zero dimensions.') }
|
|
341
|
+
return [pscustomobject]@{ width = $width; height = $height }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function Assert-WinAppMp4 {
|
|
345
|
+
[CmdletBinding()]
|
|
346
|
+
param([Parameter(Mandatory)][string]$Path)
|
|
347
|
+
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { throw (New-WinAppException -Code 'RECORD_FAILED' -Message "Recording output is missing: $Path") }
|
|
348
|
+
$bytes = [byte[]]::new(12)
|
|
349
|
+
$stream = [IO.File]::OpenRead($Path)
|
|
350
|
+
try { $read = $stream.Read($bytes, 0, $bytes.Length) }
|
|
351
|
+
finally { $stream.Dispose() }
|
|
352
|
+
if ($read -lt 12 -or [Text.Encoding]::ASCII.GetString($bytes, 4, 4) -ne 'ftyp') { throw (New-WinAppException -Code 'RECORD_FAILED' -Message 'Recording output is not a valid MP4 container.') }
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function Select-WinAppRepresentativeFrames {
|
|
356
|
+
[OutputType([pscustomobject[]])]
|
|
357
|
+
[CmdletBinding()]
|
|
358
|
+
param([Parameter(Mandatory)]$Samples, [Parameter(Mandatory)][string]$FramesRoot)
|
|
359
|
+
$items = @($Samples)
|
|
360
|
+
if ($items.Count -eq 0) { return @() }
|
|
361
|
+
$indices = [Collections.Generic.SortedSet[int]]::new()
|
|
362
|
+
[void]$indices.Add(0)
|
|
363
|
+
[void]$indices.Add([Math]::Floor(($items.Count - 1) / 2))
|
|
364
|
+
[void]$indices.Add($items.Count - 1)
|
|
365
|
+
$results = foreach ($index in $indices) {
|
|
366
|
+
$sample = $items[$index]
|
|
367
|
+
$relative = ([string](Get-WinAppPropertyValue $sample 'file')).Replace('/', [IO.Path]::DirectorySeparatorChar)
|
|
368
|
+
[pscustomobject]@{
|
|
369
|
+
role = if ($index -eq 0) { 'first' } elseif ($index -eq ($items.Count - 1)) { 'last' } else { 'middle' }
|
|
370
|
+
sample_index = [int](Get-WinAppPropertyValue $sample 'sampleIndex' $index)
|
|
371
|
+
elapsed_ms = [long](Get-WinAppPropertyValue $sample 'elapsedMs' 0)
|
|
372
|
+
media_time_ms = [long](Get-WinAppPropertyValue $sample 'mediaTimeMs' 0)
|
|
373
|
+
changed = [bool](Get-WinAppPropertyValue $sample 'changed' $false)
|
|
374
|
+
path = [IO.Path]::GetFullPath((Join-Path $FramesRoot $relative))
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return @($results)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function New-WinAppOperationMetadata {
|
|
381
|
+
[OutputType([pscustomobject])]
|
|
382
|
+
[CmdletBinding()]
|
|
383
|
+
param(
|
|
384
|
+
[Parameter(Mandatory)][string]$Operation,
|
|
385
|
+
[Parameter(Mandatory)][string]$Version,
|
|
386
|
+
[Parameter(Mandatory)][string]$VersionClassification,
|
|
387
|
+
[Parameter(Mandatory)][pscustomobject]$Target,
|
|
388
|
+
[string]$ArtifactPath,
|
|
389
|
+
[int]$Width,
|
|
390
|
+
[int]$Height,
|
|
391
|
+
$AssociatedWindows = @(),
|
|
392
|
+
$CommandResult
|
|
393
|
+
)
|
|
394
|
+
return [pscustomobject]@{
|
|
395
|
+
operation = $Operation
|
|
396
|
+
timestamp_utc = [DateTime]::UtcNow.ToString('o')
|
|
397
|
+
backend = [pscustomobject]@{ name = 'winapp-cli'; version = $Version; tested_version = $script:WinAppTestedVersion; version_classification = $VersionClassification }
|
|
398
|
+
target = $Target
|
|
399
|
+
artifact = if ([string]::IsNullOrWhiteSpace($ArtifactPath)) { $null } else { [pscustomobject]@{ path = [IO.Path]::GetFullPath($ArtifactPath); width = $Width; height = $Height } }
|
|
400
|
+
command = $CommandResult
|
|
401
|
+
capture = [pscustomobject]@{ mode = 'default_window_capture'; capture_screen = $false; associated_windows = @($AssociatedWindows) }
|
|
402
|
+
window_state = [pscustomobject]@{ visible = 'SUPPORTED'; occluded = 'SUPPORTED'; minimized = 'UNVERIFIED' }
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function Write-WinAppJsonFile {
|
|
407
|
+
[OutputType([string])]
|
|
408
|
+
[CmdletBinding()]
|
|
409
|
+
param([Parameter(Mandatory)]$Value, [Parameter(Mandatory)][string]$Path)
|
|
410
|
+
$resolved = [IO.Path]::GetFullPath($Path)
|
|
411
|
+
[IO.File]::WriteAllText($resolved, ($Value | ConvertTo-Json -Depth 12), [Text.UTF8Encoding]::new($false))
|
|
412
|
+
return $resolved
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function Write-WinAppTargetDocument {
|
|
416
|
+
[OutputType([string])]
|
|
417
|
+
[CmdletBinding()]
|
|
418
|
+
param(
|
|
419
|
+
[Parameter(Mandatory)][string]$Path,
|
|
420
|
+
[Parameter(Mandatory)][pscustomobject]$Target,
|
|
421
|
+
[Parameter(Mandatory)][pscustomobject]$VersionInfo
|
|
422
|
+
)
|
|
423
|
+
$resolved = [IO.Path]::GetFullPath($Path)
|
|
424
|
+
if (Test-Path -LiteralPath $resolved -PathType Leaf) {
|
|
425
|
+
try { $existing = Get-Content -LiteralPath $resolved -Raw | ConvertFrom-Json -ErrorAction Stop }
|
|
426
|
+
catch { throw (New-WinAppException -Code 'WINAPP_COMMAND_FAILED' -Message "Existing desktop-window.json cannot be read safely: $resolved") }
|
|
427
|
+
$existingTarget = Get-WinAppPropertyValue $existing 'target'
|
|
428
|
+
if ($null -eq $existingTarget -or [long](Get-WinAppPropertyValue $existingTarget 'hwnd' -1) -ne $Target.hwnd -or [int](Get-WinAppPropertyValue $existingTarget 'process_id' -1) -ne $Target.process_id) {
|
|
429
|
+
throw (New-WinAppException -Code 'WINDOW_TARGET_AMBIGUOUS' -Message 'The explicit run directory already belongs to a different desktop window target.')
|
|
430
|
+
}
|
|
431
|
+
return $resolved
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
$document = [pscustomobject]@{
|
|
435
|
+
schema_version = 'agent-verification-lab.desktop-window.v1'
|
|
436
|
+
timestamp_utc = [DateTime]::UtcNow.ToString('o')
|
|
437
|
+
backend = [pscustomobject]@{ name = 'winapp-cli'; version = $VersionInfo.actual; tested_version = $VersionInfo.tested; version_classification = $VersionInfo.classification }
|
|
438
|
+
target = $Target
|
|
439
|
+
window_state = [pscustomobject]@{ visible = 'SUPPORTED'; occluded = 'SUPPORTED'; minimized = 'UNVERIFIED' }
|
|
440
|
+
}
|
|
441
|
+
return Write-WinAppJsonFile -Value $document -Path $resolved
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function ConvertFrom-WinAppException {
|
|
445
|
+
[OutputType([pscustomobject])]
|
|
446
|
+
[CmdletBinding()]
|
|
447
|
+
param([Parameter(Mandatory)][Management.Automation.ErrorRecord]$ErrorRecord, [Parameter(Mandatory)][string]$Operation)
|
|
448
|
+
$exception = $ErrorRecord.Exception
|
|
449
|
+
return [pscustomobject]@{
|
|
450
|
+
status = 'error'
|
|
451
|
+
code = if ($exception.Data.Contains('WinAppErrorCode')) { [string]$exception.Data['WinAppErrorCode'] } else { 'WINAPP_COMMAND_FAILED' }
|
|
452
|
+
message = $exception.Message
|
|
453
|
+
operation = $Operation
|
|
454
|
+
exit_code = if ($exception.Data.Contains('WinAppExitCode')) { [int]$exception.Data['WinAppExitCode'] } else { $null }
|
|
455
|
+
upstream_code = if ($exception.Data.Contains('WinAppUpstreamCode')) { [string]$exception.Data['WinAppUpstreamCode'] } else { $null }
|
|
456
|
+
upstream_type = if ($exception.Data.Contains('WinAppUpstreamType')) { [string]$exception.Data['WinAppUpstreamType'] } else { $null }
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function Write-WinAppFailure {
|
|
461
|
+
[CmdletBinding()]
|
|
462
|
+
param([Parameter(Mandatory)][Management.Automation.ErrorRecord]$ErrorRecord, [Parameter(Mandatory)][string]$Operation)
|
|
463
|
+
$failure = ConvertFrom-WinAppException -ErrorRecord $ErrorRecord -Operation $Operation
|
|
464
|
+
[Console]::Error.WriteLine(($failure | ConvertTo-Json -Compress -Depth 5))
|
|
465
|
+
}
|