afyx-engineering-kit 0.0.0-stage → 0.1.0-alpha.3

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.
Files changed (208) hide show
  1. package/.afyx-source-revision +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +377 -2
  4. package/SECURITY.md +74 -0
  5. package/afyx-context/LICENSE +21 -0
  6. package/afyx-context/README.md +155 -0
  7. package/afyx-context/afyx-context.json +30 -0
  8. package/afyx-context/contracts/integration-v1.schema.json +34 -0
  9. package/afyx-context/package-lock.json +53 -0
  10. package/afyx-context/package.json +34 -0
  11. package/afyx-context/scripts/benchmark.mjs +39 -0
  12. package/afyx-context/scripts/build.mjs +15 -0
  13. package/afyx-context/scripts/comparative-benchmark.mjs +342 -0
  14. package/afyx-context/scripts/comparative-worker.mjs +74 -0
  15. package/afyx-context/scripts/graph-integration-e2e.mjs +188 -0
  16. package/afyx-context/scripts/integrated-dogfood.mjs +309 -0
  17. package/afyx-context/src/budget.js +166 -0
  18. package/afyx-context/src/cli.js +110 -0
  19. package/afyx-context/src/coordination.js +343 -0
  20. package/afyx-context/src/engine.js +198 -0
  21. package/afyx-context/src/errors.js +14 -0
  22. package/afyx-context/src/graph-integration-worker.js +70 -0
  23. package/afyx-context/src/graph-integration.js +373 -0
  24. package/afyx-context/src/graph-mcp-bridge.js +103 -0
  25. package/afyx-context/src/index.js +25 -0
  26. package/afyx-context/src/integrations.js +87 -0
  27. package/afyx-context/src/memory.js +255 -0
  28. package/afyx-context/src/storage.js +364 -0
  29. package/afyx-context/test-fixtures/coordination-worker.mjs +52 -0
  30. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__init__.py +1 -0
  31. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__manifest__.py +4 -0
  32. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/__init__.py +1 -0
  33. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/sale_order.py +5 -0
  34. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__init__.py +1 -0
  35. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__manifest__.py +10 -0
  36. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/__init__.py +2 -0
  37. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order.py +20 -0
  38. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order_audit.py +11 -0
  39. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/security/ir.model.access.csv +2 -0
  40. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/views/sale_order_views.xml +14 -0
  41. package/afyx-forge/LICENSE +55 -0
  42. package/afyx-forge/README.md +126 -0
  43. package/afyx-forge/afyx-forge.json +28 -0
  44. package/afyx-forge/bin/afyx-forge +4 -0
  45. package/afyx-forge/bin/afyx-forge.cmd +3 -0
  46. package/afyx-forge/bin/afyx-forge.js +16 -0
  47. package/afyx-forge/contracts/forge-plan-v1.schema.json +172 -0
  48. package/afyx-forge/package.json +26 -0
  49. package/afyx-forge/src/classifier.js +190 -0
  50. package/afyx-forge/src/cli.js +111 -0
  51. package/afyx-forge/src/doctor.js +105 -0
  52. package/afyx-forge/src/guidance.js +120 -0
  53. package/afyx-forge/src/index.js +273 -0
  54. package/afyx-forge/src/planning.js +107 -0
  55. package/afyx-forge/src/policy.js +109 -0
  56. package/afyx-forge/src/workflow-refiner.js +151 -0
  57. package/afyx-graph/afyx-graph.json +20 -0
  58. package/afyx-graph/engine/LICENSE +21 -0
  59. package/afyx-graph/engine/README.md +104 -0
  60. package/afyx-graph/engine/release/RELEASE-MANIFEST.json +21 -0
  61. package/afyx-graph/engine/release/SHA256SUMS +2 -0
  62. package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
  63. package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
  64. package/afyx-graph/engine/scripts/distribution-contract.mjs +212 -0
  65. package/afyx-graph/engine/scripts/distribution-product.json +33 -0
  66. package/bin/afyx-engineering-kit.mjs +61 -0
  67. package/install.ps1 +1053 -0
  68. package/install.sh +617 -0
  69. package/package.json +66 -4
  70. package/scripts/afyx-capability-orchestrator.mjs +752 -0
  71. package/scripts/afyx-claude-integration.mjs +547 -0
  72. package/scripts/afyx-context-artifact.mjs +105 -0
  73. package/scripts/afyx-credential-broker.mjs +75 -0
  74. package/scripts/afyx-doctor.ps1 +152 -0
  75. package/scripts/afyx-doctor.sh +146 -0
  76. package/scripts/afyx-forge-artifact.mjs +183 -0
  77. package/scripts/afyx-global-routing-policy.md +12 -0
  78. package/scripts/afyx-global-routing.mjs +168 -0
  79. package/scripts/afyx-graph-artifact.mjs +178 -0
  80. package/scripts/afyx-host-adapters.mjs +543 -0
  81. package/scripts/afyx-host-bridge-lifecycle.mjs +174 -0
  82. package/scripts/afyx-host-bridge.mjs +288 -0
  83. package/scripts/afyx-integration-contracts.mjs +825 -0
  84. package/scripts/afyx-mcp-integration.mjs +528 -0
  85. package/scripts/afyx-modular-integration.mjs +361 -0
  86. package/scripts/afyx-modular-runtime.mjs +451 -0
  87. package/scripts/afyx-native-skill-host.mjs +124 -0
  88. package/scripts/afyx-npm-installer.mjs +486 -0
  89. package/scripts/afyx-project.ps1 +205 -0
  90. package/scripts/afyx-project.sh +207 -0
  91. package/scripts/afyx-provider-backup.mjs +1206 -0
  92. package/scripts/afyx-provider-integration.mjs +724 -0
  93. package/scripts/afyx-provider-inventory.mjs +147 -0
  94. package/scripts/afyx-security-auditor.mjs +224 -0
  95. package/scripts/afyx-skill-engineering.mjs +354 -0
  96. package/scripts/afyx-tool-family-routing.mjs +64 -0
  97. package/scripts/afyx-universal-runtime.mjs +530 -0
  98. package/scripts/alpha_acceptance_preflight.py +240 -0
  99. package/scripts/benchmark-graph-memory.mjs +96 -0
  100. package/scripts/benchmark_capability_orchestrator.mjs +64 -0
  101. package/scripts/build-windows-installer.ps1 +259 -0
  102. package/scripts/build_forge_synthetic_image.py +328 -0
  103. package/scripts/check-reference-staleness.py +71 -0
  104. package/scripts/components.json +254 -0
  105. package/scripts/contracts/afyx-capability-request-v1.schema.json +189 -0
  106. package/scripts/contracts/afyx-capability-result-v1.schema.json +32 -0
  107. package/scripts/dogfood_engineering_comparison.mjs +303 -0
  108. package/scripts/engineering-assurance.json +28 -0
  109. package/scripts/install-afyx-context.ps1 +142 -0
  110. package/scripts/install-afyx-context.sh +126 -0
  111. package/scripts/install-afyx-forge.ps1 +265 -0
  112. package/scripts/install-afyx-forge.sh +273 -0
  113. package/scripts/install-afyx-graph.ps1 +571 -0
  114. package/scripts/install-afyx-graph.sh +438 -0
  115. package/scripts/install-codex-usage-tracker.ps1 +172 -0
  116. package/scripts/lib/AfyxComponents.psm1 +399 -0
  117. package/scripts/lib/AfyxSkillLifecycle.psm1 +289 -0
  118. package/scripts/lib/AfyxTerminal.psm1 +838 -0
  119. package/scripts/lib/afyx-components.sh +256 -0
  120. package/scripts/lib/afyx-skill-lifecycle.sh +271 -0
  121. package/scripts/link-global-dev.ps1 +193 -0
  122. package/scripts/link-global-dev.sh +130 -0
  123. package/scripts/phase8-paired-evidence.mjs +195 -0
  124. package/scripts/phase8-representative-workload.mjs +771 -0
  125. package/scripts/phase8-session-recorder.mjs +157 -0
  126. package/scripts/phase8_event_ledger.py +248 -0
  127. package/scripts/phase8_evidence_discovery.py +189 -0
  128. package/scripts/prepare-g6-package.mjs +349 -0
  129. package/scripts/resolve-git-release-artifacts.mjs +321 -0
  130. package/scripts/stage-npm-release.mjs +94 -0
  131. package/scripts/validate-afyx-graph.py +203 -0
  132. package/scripts/validate-components.py +194 -0
  133. package/scripts/validate-engineering-assurance.py +281 -0
  134. package/scripts/verify-graph-archive.mjs +64 -0
  135. package/skills/afyx-context/SKILL.md +26 -0
  136. package/skills/afyx-engineering-expert/README.md +42 -0
  137. package/skills/afyx-engineering-expert/SKILL.md +70 -0
  138. package/skills/afyx-engineering-expert/assets/result-template.md +15 -0
  139. package/skills/afyx-engineering-expert/references/ai-ml-engineer.md +17 -0
  140. package/skills/afyx-engineering-expert/references/business-analyst.md +17 -0
  141. package/skills/afyx-engineering-expert/references/clean-code-engineer.md +26 -0
  142. package/skills/afyx-engineering-expert/references/code-reviewer.md +24 -0
  143. package/skills/afyx-engineering-expert/references/cybersecurity-devsecops.md +17 -0
  144. package/skills/afyx-engineering-expert/references/data-analyst-bi.md +24 -0
  145. package/skills/afyx-engineering-expert/references/data-engineer.md +24 -0
  146. package/skills/afyx-engineering-expert/references/database-administrator.md +17 -0
  147. package/skills/afyx-engineering-expert/references/debugging-specialist.md +24 -0
  148. package/skills/afyx-engineering-expert/references/embedded-iot-engineer.md +24 -0
  149. package/skills/afyx-engineering-expert/references/erp-technical-specialist.md +17 -0
  150. package/skills/afyx-engineering-expert/references/hardware-diagnostics-auditor.md +24 -0
  151. package/skills/afyx-engineering-expert/references/hardware-electronics-engineer.md +24 -0
  152. package/skills/afyx-engineering-expert/references/integration-engineer.md +24 -0
  153. package/skills/afyx-engineering-expert/references/legacy-modernization-engineer.md +24 -0
  154. package/skills/afyx-engineering-expert/references/llmops-prompt-engineer.md +24 -0
  155. package/skills/afyx-engineering-expert/references/network-engineer.md +24 -0
  156. package/skills/afyx-engineering-expert/references/performance-benchmark-engineer.md +24 -0
  157. package/skills/afyx-engineering-expert/references/platform-engineer.md +24 -0
  158. package/skills/afyx-engineering-expert/references/product-manager.md +17 -0
  159. package/skills/afyx-engineering-expert/references/qa-engineer.md +17 -0
  160. package/skills/afyx-engineering-expert/references/site-reliability-engineer.md +17 -0
  161. package/skills/afyx-engineering-expert/references/software-engineer.md +17 -0
  162. package/skills/afyx-engineering-expert/references/solutions-architect.md +17 -0
  163. package/skills/afyx-engineering-expert/references/specialists-index.md +33 -0
  164. package/skills/afyx-engineering-expert/references/subject-matter-expert.md +17 -0
  165. package/skills/afyx-engineering-expert/references/system-analyst.md +17 -0
  166. package/skills/afyx-engineering-expert/references/technical-project-manager.md +24 -0
  167. package/skills/afyx-engineering-expert/references/technical-writer.md +24 -0
  168. package/skills/afyx-engineering-expert/references/ui-ux-designer.md +17 -0
  169. package/skills/afyx-engineering-expert/workflows/ai-data-erp.md +20 -0
  170. package/skills/afyx-engineering-expert/workflows/debugging.md +10 -0
  171. package/skills/afyx-engineering-expert/workflows/discovery-design.md +11 -0
  172. package/skills/afyx-engineering-expert/workflows/implementation.md +12 -0
  173. package/skills/afyx-engineering-expert/workflows/incident-reliability.md +12 -0
  174. package/skills/afyx-engineering-expert/workflows/review-audit.md +13 -0
  175. package/skills/afyx-forge/SKILL.md +43 -0
  176. package/skills/afyx-forge/references/adaptive-policy.md +19 -0
  177. package/skills/efficient-coding/SKILL.md +33 -0
  178. package/skills/efficient-coding/references/investigation.md +27 -0
  179. package/skills/efficient-coding/references/token-efficiency.md +25 -0
  180. package/skills/efficient-coding/references/tool-routing.md +13 -0
  181. package/skills/odoo-engineering/SKILL.md +33 -0
  182. package/skills/odoo-engineering/references/common.md +9 -0
  183. package/skills/odoo-engineering/references/odoo-10.md +32 -0
  184. package/skills/odoo-engineering/references/odoo-11.md +26 -0
  185. package/skills/odoo-engineering/references/odoo-12.md +31 -0
  186. package/skills/odoo-engineering/references/odoo-13.md +27 -0
  187. package/skills/odoo-engineering/references/odoo-14.md +31 -0
  188. package/skills/odoo-engineering/references/odoo-15.md +34 -0
  189. package/skills/odoo-engineering/references/odoo-16.md +37 -0
  190. package/skills/odoo-engineering/references/odoo-17.md +37 -0
  191. package/skills/odoo-engineering/references/odoo-18.md +48 -0
  192. package/skills/odoo-engineering/references/odoo-19.md +43 -0
  193. package/skills/odoo-engineering/references/odoo-20.md +39 -0
  194. package/skills/odoo-engineering/references/reference-schema.md +16 -0
  195. package/skills/odoo-engineering/references/version-detection.md +13 -0
  196. package/tools/codex-usage/CodexUsage.psm1 +496 -0
  197. package/tools/codex-usage/codex-usage-doctor.ps1 +150 -0
  198. package/tools/codex-usage/codex-usage-pricing.json +25 -0
  199. package/tools/codex-usage/codex-usage-stop.ps1 +167 -0
  200. package/tools/codex-usage/codex-usage-watch.ps1 +250 -0
  201. package/tools/codex-usage/vscode-user-task.json +31 -0
  202. package/tools/windows-setup/SetupBootstrapper.cs +258 -0
  203. package/uninstall.ps1 +189 -0
  204. package/uninstall.sh +167 -0
  205. package/update.ps1 +95 -0
  206. package/update.sh +67 -0
  207. package/verify.ps1 +411 -0
  208. package/verify.sh +265 -0
@@ -0,0 +1,838 @@
1
+ Set-StrictMode -Version Latest
2
+
3
+ $script:AfyxAnsi = [char]27
4
+ $script:AfyxPalette = @{
5
+ Primary = '38;2;34;211;238'
6
+ Secondary = '38;2;139;92;246'
7
+ Accent = '38;2;96;165;250'
8
+ Success = '38;2;52;211;153'
9
+ Warning = '38;2;251;191;36'
10
+ Error = '38;2;251;113;133'
11
+ Text = '38;2;229;242;255'
12
+ Muted = '38;2;147;164;187'
13
+ }
14
+
15
+ function Test-AfyxAnsiSupport {
16
+ [CmdletBinding()]
17
+ param([switch]$ForcePlain)
18
+ if ($ForcePlain -or $env:NO_COLOR -or $env:TERM -eq 'dumb') { return $false }
19
+ try {
20
+ if ([Console]::IsOutputRedirected) { return $false }
21
+ $property = $Host.UI.PSObject.Properties['SupportsVirtualTerminal']
22
+ if ($property -and [bool]$property.Value) { return $true }
23
+ return [bool]($env:WT_SESSION -or $env:TERM_PROGRAM -or ($env:TERM -match 'color|ansi|xterm'))
24
+ } catch { return $false }
25
+ }
26
+
27
+ function Test-AfyxInteractiveTerminal {
28
+ [CmdletBinding()]
29
+ param([switch]$ForceInteractive, [switch]$ForcePlain)
30
+ if ($ForcePlain -or $env:CI) { return $false }
31
+ try {
32
+ if ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected) { return $false }
33
+ if ($ForceInteractive -or $env:AFYX_FORCE_INTERACTIVE -eq '1') { return $true }
34
+ return $null -ne $Host.UI.RawUI
35
+ } catch { return $false }
36
+ }
37
+
38
+ function New-AfyxTerminalContext {
39
+ [CmdletBinding()]
40
+ param([switch]$ForceInteractive, [switch]$ForcePlain, [int]$Width = 0)
41
+ if ($Width -lt 1) {
42
+ try { $Width = [Math]::Max(40, [int]$Host.UI.RawUI.WindowSize.Width) }
43
+ catch { $Width = 80 }
44
+ }
45
+ [pscustomobject]@{
46
+ Interactive = Test-AfyxInteractiveTerminal -ForceInteractive:$ForceInteractive -ForcePlain:$ForcePlain
47
+ Ansi = Test-AfyxAnsiSupport -ForcePlain:$ForcePlain
48
+ Width = $Width
49
+ Height = $(try { [Math]::Max(20, [int]$Host.UI.RawUI.WindowSize.Height) } catch { 24 })
50
+ }
51
+ }
52
+
53
+ function Get-AfyxStyledText {
54
+ [CmdletBinding()]
55
+ param(
56
+ [Parameter(Mandatory)][AllowEmptyString()][string]$Text,
57
+ [ValidateSet('Primary', 'Secondary', 'Accent', 'Success', 'Warning', 'Error', 'Text', 'Muted')][string]$Tone = 'Text',
58
+ [Parameter(Mandatory)]$Terminal
59
+ )
60
+ if (-not $Terminal.Ansi) { return $Text }
61
+ return "$script:AfyxAnsi[$($script:AfyxPalette[$Tone])m$Text$script:AfyxAnsi[0m"
62
+ }
63
+
64
+ function Format-AfyxWrappedText {
65
+ [CmdletBinding()]
66
+ param([AllowEmptyString()][string]$Text, [int]$Width = 80, [string]$Indent = '')
67
+ $available = [Math]::Max(10, $Width - $Indent.Length)
68
+ $result = @()
69
+ foreach ($paragraph in @($Text -split "`r?`n")) {
70
+ if (-not $paragraph) { $result += $Indent; continue }
71
+ $line = ''
72
+ foreach ($word in @($paragraph -split '\s+')) {
73
+ if (-not $line) { $line = $word; continue }
74
+ if (($line.Length + 1 + $word.Length) -le $available) { $line += " $word" }
75
+ else { $result += "$Indent$line"; $line = $word }
76
+ }
77
+ if ($line) { $result += "$Indent$line" }
78
+ }
79
+ return @($result)
80
+ }
81
+
82
+ function Write-AfyxText {
83
+ [CmdletBinding()]
84
+ param(
85
+ [AllowEmptyString()][string]$Text = '',
86
+ [ValidateSet('Primary', 'Secondary', 'Accent', 'Success', 'Warning', 'Error', 'Text', 'Muted')][string]$Tone = 'Text',
87
+ [Parameter(Mandatory)]$Terminal,
88
+ [string]$Indent = ''
89
+ )
90
+ if (Test-AfyxDashboard -Terminal $Terminal) {
91
+ $Terminal.DashboardState.Events += [pscustomobject]@{ Text = "$Indent$Text"; Tone = $Tone }
92
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
93
+ return
94
+ }
95
+ foreach ($line in @(Format-AfyxWrappedText -Text $Text -Width $Terminal.Width -Indent $Indent)) {
96
+ Write-Host (Get-AfyxStyledText -Text $line -Tone $Tone -Terminal $Terminal)
97
+ }
98
+ }
99
+
100
+ function Show-AfyxBanner {
101
+ [CmdletBinding()]
102
+ param([Parameter(Mandatory)]$Terminal, [string]$Subtitle = 'Code Engineering Kit')
103
+ Write-Host ''
104
+ $width = [Math]::Max(34, [Math]::Min(76, $Terminal.Width - 4))
105
+ $top = if ($Terminal.Ansi) { [string][char]0x256D + ([string][char]0x2500 * $width) + [char]0x256E } else { '+' + ('-' * $width) + '+' }
106
+ $bottom = if ($Terminal.Ansi) { [string][char]0x2570 + ([string][char]0x2500 * $width) + [char]0x256F } else { '+' + ('-' * $width) + '+' }
107
+ Write-Host (Get-AfyxStyledText -Text $top -Tone Primary -Terminal $Terminal)
108
+ $lines = @(' A F Y X / ENGINEERING KIT', " $Subtitle", ' I choose my path, even in the unknown.')
109
+ foreach ($line in $lines) {
110
+ foreach ($part in @(Format-AfyxWrappedText -Text $line -Width ($width - 2))) {
111
+ $edge = if ($Terminal.Ansi) { [string][char]0x2502 } else { '|' }
112
+ $padded = $part.PadRight($width)
113
+ Write-Host ((Get-AfyxStyledText -Text $edge -Tone Primary -Terminal $Terminal) + (Get-AfyxStyledText -Text $padded -Tone Text -Terminal $Terminal) + (Get-AfyxStyledText -Text $edge -Tone Primary -Terminal $Terminal))
114
+ }
115
+ }
116
+ Write-Host (Get-AfyxStyledText -Text $bottom -Tone Primary -Terminal $Terminal)
117
+ }
118
+
119
+ function Show-AfyxStep {
120
+ [CmdletBinding()]
121
+ param([Parameter(Mandatory)][ValidateRange(1, 5)][int]$Current, [Parameter(Mandatory)]$Terminal)
122
+ if (Test-AfyxDashboard -Terminal $Terminal) {
123
+ $Terminal.DashboardState.Step = $Current
124
+ $Terminal.DashboardState.Prompt = ''
125
+ $Terminal.DashboardState.Options = @()
126
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
127
+ return
128
+ }
129
+ $steps = @('Detect', 'Select', 'Configure', 'Install', 'Finish')
130
+ $parts = @()
131
+ for ($i = 0; $i -lt $steps.Count; $i++) {
132
+ $tone = if (($i + 1) -eq $Current) { 'Primary' } elseif (($i + 1) -lt $Current) { 'Success' } else { 'Muted' }
133
+ $parts += Get-AfyxStyledText -Text "[$($i + 1) $($steps[$i])]" -Tone $tone -Terminal $Terminal
134
+ }
135
+ if ($Terminal.Width -lt 72) {
136
+ Write-AfyxText -Terminal $Terminal -Tone Primary -Text "Step $Current/5: $($steps[$Current - 1])"
137
+ } else {
138
+ Write-Host (' ' + ($parts -join ' > '))
139
+ }
140
+ }
141
+
142
+ function Write-AfyxSection {
143
+ [CmdletBinding()]
144
+ param([Parameter(Mandatory)][string]$Title, [Parameter(Mandatory)]$Terminal)
145
+ if (Test-AfyxDashboard -Terminal $Terminal) {
146
+ $Terminal.DashboardState.Section = $Title
147
+ $Terminal.DashboardState.Prompt = ''
148
+ $Terminal.DashboardState.Options = @()
149
+ $Terminal.DashboardState.Events = @()
150
+ $Terminal.DashboardState.Scroll[1] = 0
151
+ $Terminal.DashboardState.Scroll[2] = 0
152
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
153
+ return
154
+ }
155
+ Write-Host ''
156
+ Write-AfyxText -Terminal $Terminal -Tone Primary -Text "-- $Title"
157
+ }
158
+
159
+ function Get-AfyxStatusTone {
160
+ [CmdletBinding()]
161
+ param([Parameter(Mandatory)][string]$Status)
162
+ switch ($Status.ToUpperInvariant()) {
163
+ { $_ -in @('HEALTHY', 'NO CHANGE', 'READY') } { return 'Success' }
164
+ { $_ -in @('UPDATE AVAILABLE', 'PLANNED', 'RESTART REQUIRED', 'WARNING') } { return 'Warning' }
165
+ { $_ -in @('BLOCKED', 'FAILED', 'ERROR') } { return 'Error' }
166
+ { $_ -in @('SKIPPED', 'INFO', 'NOT INSTALLED', 'EXTRA') } { return 'Muted' }
167
+ default { return 'Text' }
168
+ }
169
+ }
170
+
171
+ function Write-AfyxStatus {
172
+ [CmdletBinding()]
173
+ param(
174
+ [Parameter(Mandatory)][string]$Status,
175
+ [Parameter(Mandatory)][string]$Name,
176
+ [string]$Detail = '',
177
+ [Parameter(Mandatory)]$Terminal
178
+ )
179
+ if (Test-AfyxDashboard -Terminal $Terminal) {
180
+ $Terminal.DashboardState.Events += [pscustomobject]@{
181
+ Text = "[$($Status.ToUpperInvariant())] $Name$(if ($Detail) { " - $Detail" })"
182
+ Tone = Get-AfyxStatusTone -Status $Status
183
+ }
184
+ $Terminal.DashboardState.Scroll[2] = [int]::MaxValue
185
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
186
+ return
187
+ }
188
+ $label = "[$($Status.ToUpperInvariant())]"
189
+ $styled = Get-AfyxStyledText -Text $label -Tone (Get-AfyxStatusTone -Status $Status) -Terminal $Terminal
190
+ $suffix = if ($Detail) { " - $Detail" } else { '' }
191
+ Write-Host "$styled $Name$suffix"
192
+ }
193
+
194
+ function Get-AfyxOutcomeStatus {
195
+ [CmdletBinding()]
196
+ param([string]$ComponentState, [string]$Action, [switch]$WhatIf)
197
+ if ($WhatIf -and $Action -notin @('', 'skip', 'skipped')) { return 'PLANNED' }
198
+ if ($Action -match 'blocked|failed|error') { return 'BLOCKED' }
199
+ if ($Action -match 'restart') { return 'RESTART REQUIRED' }
200
+ if ($Action -in @('installed', 'replaced', 'updated', 'update', 'repair', 'repaired', 'adopted', 'already adopted', 'install')) { return 'HEALTHY' }
201
+ if ($Action -in @('planned', 'planned adoption')) { return 'PLANNED' }
202
+ if ($Action -in @('skip', 'skipped', '')) {
203
+ if ($ComponentState -eq 'HEALTHY') { return 'NO CHANGE' }
204
+ return 'SKIPPED'
205
+ }
206
+ return $Action.ToUpperInvariant()
207
+ }
208
+
209
+ function Get-AfyxEnabledOptionIndex {
210
+ param([object[]]$Options, [int]$Start, [int]$Direction)
211
+ $index = $Start
212
+ for ($attempt = 0; $attempt -lt $Options.Count; $attempt++) {
213
+ $index = ($index + $Direction + $Options.Count) % $Options.Count
214
+ $enabled = -not $Options[$index].PSObject.Properties['Enabled'] -or [bool]$Options[$index].Enabled
215
+ if ($enabled) { return $index }
216
+ }
217
+ return $Start
218
+ }
219
+
220
+ function Show-AfyxChoiceFrame {
221
+ param([string]$Prompt, [object[]]$Options, [int]$Selected, [hashtable]$Checked, $Terminal, [switch]$Multiple)
222
+ if (Test-AfyxDashboard -Terminal $Terminal) {
223
+ $Terminal.DashboardState.Prompt = $Prompt
224
+ $Terminal.DashboardState.Options = @($Options)
225
+ $Terminal.DashboardState.Selected = $Selected
226
+ $Terminal.DashboardState.Checked = $Checked
227
+ $Terminal.DashboardState.Multiple = [bool]$Multiple
228
+ if ($Terminal.Width -lt 96 -and $Terminal.DashboardState.Focus -eq 1) {
229
+ $Terminal.DashboardState.Scroll[1] = [Math]::Max(0, $Selected - 4)
230
+ }
231
+ Show-AfyxDashboard -Terminal $Terminal
232
+ return 0
233
+ }
234
+ $border = if ($Terminal.Ansi) { [string][char]0x2500 } else { '-' }
235
+ $lineCount = @(Format-AfyxWrappedText -Text $Prompt -Width $Terminal.Width).Count + 2
236
+ Write-AfyxText -Terminal $Terminal -Tone Secondary -Text ((' ' + $border * ([Math]::Max(20, [Math]::Min(72, $Terminal.Width - 4)))))
237
+ Write-AfyxText -Terminal $Terminal -Tone Text -Text $Prompt
238
+ for ($i = 0; $i -lt $Options.Count; $i++) {
239
+ $option = $Options[$i]
240
+ $enabled = -not $option.PSObject.Properties['Enabled'] -or [bool]$option.Enabled
241
+ $cursor = if ($i -eq $Selected) { '>' } else { ' ' }
242
+ $mark = if ($Multiple) { if ($Checked.ContainsKey([string]$option.Id)) { '[x]' } else { '[ ]' } } else { "[$($i + 1)]" }
243
+ $detail = if ($option.PSObject.Properties['Detail'] -and $option.Detail) { " - $($option.Detail)" } else { '' }
244
+ $tone = if (-not $enabled) { 'Muted' } elseif ($i -eq $Selected) { 'Primary' } else { 'Text' }
245
+ $optionText = "$cursor $mark $($option.Label)$detail"
246
+ $lineCount += @(Format-AfyxWrappedText -Text $optionText -Width $Terminal.Width -Indent ' ').Count
247
+ Write-AfyxText -Terminal $Terminal -Tone $tone -Text $optionText -Indent ' '
248
+ }
249
+ $helpText = if ($Multiple) { 'Up/Down move | Space toggle | Enter continue | Esc cancel' } else { 'Up/Down move | Enter select | Esc cancel' }
250
+ $lineCount += @(Format-AfyxWrappedText -Text $helpText -Width $Terminal.Width -Indent ' ').Count
251
+ Write-AfyxText -Terminal $Terminal -Tone Muted -Text $helpText -Indent ' '
252
+ Write-AfyxText -Terminal $Terminal -Tone Secondary -Text ((' ' + $border * ([Math]::Max(20, [Math]::Min(72, $Terminal.Width - 4)))))
253
+ return $lineCount
254
+ }
255
+
256
+ function Reset-AfyxChoiceFrame {
257
+ param([int]$LineCount, [Parameter(Mandatory)]$Terminal)
258
+ if ($LineCount -lt 1 -or -not $Terminal.Ansi -or (Test-AfyxDashboard -Terminal $Terminal)) { return }
259
+ Write-Host -NoNewline "$script:AfyxAnsi[$($LineCount)A`r$script:AfyxAnsi[0J"
260
+ }
261
+
262
+ function Test-AfyxAdvancedMenu {
263
+ param([Parameter(Mandatory)]$Terminal, [scriptblock]$ReadKey)
264
+ if (-not $Terminal.Interactive) { return $false }
265
+ if ($ReadKey) { return $true }
266
+ if (-not $Terminal.Ansi) { return $false }
267
+ try { return $null -ne $Host.UI.RawUI } catch { return $false }
268
+ }
269
+
270
+ function Get-AfyxKeyAction {
271
+ [CmdletBinding()]
272
+ param([Parameter(Mandatory)]$RawKey)
273
+ if ($null -eq $RawKey) { return $null }
274
+ $props = $RawKey.PSObject.Properties
275
+
276
+ if ($null -ne $props['KeyDown'] -and -not [bool]$props['KeyDown'].Value) {
277
+ return $null
278
+ }
279
+
280
+ $virtualCode = if ($null -ne $props['VirtualKeyCode']) { [int]$props['VirtualKeyCode'].Value }
281
+ elseif ($null -ne $props['Key']) { [int][ConsoleKey]$props['Key'].Value }
282
+ else { 0 }
283
+
284
+ $char = if ($null -ne $props['Character']) { [string]$props['Character'].Value }
285
+ elseif ($null -ne $props['KeyChar']) { [string]$props['KeyChar'].Value }
286
+ else { '' }
287
+
288
+ switch ($virtualCode) {
289
+ 37 { return 'LeftArrow' }
290
+ 38 { return 'UpArrow' }
291
+ 39 { return 'RightArrow' }
292
+ 40 { return 'DownArrow' }
293
+ 33 { return 'PageUp' }
294
+ 34 { return 'PageDown' }
295
+ 35 { return 'End' }
296
+ 36 { return 'Home' }
297
+ 9 {
298
+ if ($props['ControlKeyState'] -and ([int]$props['ControlKeyState'].Value -band [int][System.Management.Automation.Host.ControlKeyStates]::ShiftPressed)) { return 'ShiftTab' }
299
+ if ($props['Modifiers'] -and ([int]$props['Modifiers'].Value -band [int][ConsoleModifiers]::Shift)) { return 'ShiftTab' }
300
+ return 'Tab'
301
+ }
302
+ 13 { return 'Enter' }
303
+ 27 { return 'Escape' }
304
+ 32 { return 'Spacebar' }
305
+ 81 { return 'Escape' }
306
+ }
307
+
308
+ if ($virtualCode -ge 49 -and $virtualCode -le 57) {
309
+ return [string]($virtualCode - 48)
310
+ }
311
+ if ($virtualCode -ge 97 -and $virtualCode -le 105) {
312
+ return [string]($virtualCode - 96)
313
+ }
314
+
315
+ if ($char -match '^[1-9]$') {
316
+ return $char
317
+ }
318
+
319
+ if ($char -match '^(?i:q|esc)$') {
320
+ return 'Escape'
321
+ }
322
+
323
+ if ($char -eq [char]13 -or $char -eq [char]10) {
324
+ return 'Enter'
325
+ }
326
+
327
+ if ($char -eq ' ') {
328
+ return 'Spacebar'
329
+ }
330
+
331
+ return $null
332
+ }
333
+
334
+ function Read-AfyxMenuKey {
335
+ param([Parameter(Mandatory)]$Terminal, [scriptblock]$ReadKey)
336
+ if ($ReadKey) { return (& $ReadKey) }
337
+ if (Test-AfyxDashboard -Terminal $Terminal) {
338
+ try {
339
+ while (-not $Host.UI.RawUI.KeyAvailable) {
340
+ $width = [int]$Host.UI.RawUI.WindowSize.Width
341
+ $height = [int]$Host.UI.RawUI.WindowSize.Height
342
+ if ($width -ne $Terminal.Width -or $height -ne $Terminal.Height) {
343
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
344
+ }
345
+ Start-Sleep -Milliseconds 80
346
+ }
347
+ } catch {
348
+ # Hosts without KeyAvailable still support the blocking ReadKey path.
349
+ }
350
+ }
351
+ return $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
352
+ }
353
+
354
+ function Read-AfyxSingleChoice {
355
+ [CmdletBinding()]
356
+ param(
357
+ [Parameter(Mandatory)][string]$Prompt,
358
+ [Parameter(Mandatory)][object[]]$Options,
359
+ [string]$DefaultId = '',
360
+ [Parameter(Mandatory)]$Terminal,
361
+ [scriptblock]$ReadKey,
362
+ [scriptblock]$ReadLine,
363
+ [switch]$NoRender
364
+ )
365
+ if (-not $Options.Count) { throw 'At least one choice is required.' }
366
+ $selected = 0
367
+ for ($i = 0; $i -lt $Options.Count; $i++) { if ([string]$Options[$i].Id -eq $DefaultId) { $selected = $i; break } }
368
+ if (-not (Test-AfyxAdvancedMenu -Terminal $Terminal -ReadKey $ReadKey)) {
369
+ if (-not $NoRender) { $null = Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected $selected -Checked @{} -Terminal $Terminal }
370
+ $reader = if ($ReadLine) { $ReadLine } else { { Read-Host 'Selection' } }
371
+ while ($true) {
372
+ $answer = (& $reader).Trim()
373
+ if (-not $answer -and $DefaultId) { return $DefaultId }
374
+ if ($answer -match '^(?i:q|quit|esc|escape)$') { throw [OperationCanceledException]::new('Installer cancelled by user.') }
375
+ if ($answer -match '^\d+$') {
376
+ $at = [int]$answer - 1
377
+ if ($at -ge 0 -and $at -lt $Options.Count -and (-not $Options[$at].PSObject.Properties['Enabled'] -or [bool]$Options[$at].Enabled)) { return [string]$Options[$at].Id }
378
+ }
379
+ }
380
+ }
381
+ $frameLines = if (-not $NoRender) { Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected $selected -Checked @{} -Terminal $Terminal } else { 0 }
382
+ while ($true) {
383
+ $key = Read-AfyxMenuKey -Terminal $Terminal -ReadKey $ReadKey
384
+ $action = Get-AfyxKeyAction -RawKey $key
385
+ if ($null -eq $action) { continue }
386
+ switch -Regex ($action) {
387
+ '^Tab$' { Move-AfyxDashboardFocus -Terminal $Terminal }
388
+ '^ShiftTab$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction -1 }
389
+ '^LeftArrow$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction -1 }
390
+ '^RightArrow$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction 1 }
391
+ '^PageUp$' { Move-AfyxDashboardScroll -Terminal $Terminal -Direction -5 }
392
+ '^PageDown$' { Move-AfyxDashboardScroll -Terminal $Terminal -Direction 5 }
393
+ '^Home$' { Set-AfyxDashboardScroll -Terminal $Terminal -Position 0 }
394
+ '^End$' { Set-AfyxDashboardScroll -Terminal $Terminal -Position ([int]::MaxValue) }
395
+ '^UpArrow$' { if ((Test-AfyxDashboard -Terminal $Terminal) -and $Terminal.DashboardState.Focus -ne 1) { Move-AfyxDashboardScroll -Terminal $Terminal -Direction -1 } else { $selected = Get-AfyxEnabledOptionIndex -Options $Options -Start $selected -Direction -1 } }
396
+ '^DownArrow$' { if ((Test-AfyxDashboard -Terminal $Terminal) -and $Terminal.DashboardState.Focus -ne 1) { Move-AfyxDashboardScroll -Terminal $Terminal -Direction 1 } else { $selected = Get-AfyxEnabledOptionIndex -Options $Options -Start $selected -Direction 1 } }
397
+ '^Escape$' { throw [OperationCanceledException]::new('Installer cancelled by user.') }
398
+ '^Enter$' {
399
+ $enabled = -not $Options[$selected].PSObject.Properties['Enabled'] -or [bool]$Options[$selected].Enabled
400
+ if ($enabled) { return [string]$Options[$selected].Id }
401
+ }
402
+ '^[1-9]$' {
403
+ $at = [int]$action - 1
404
+ if ($at -ge 0 -and $at -lt $Options.Count -and (-not $Options[$at].PSObject.Properties['Enabled'] -or [bool]$Options[$at].Enabled)) { return [string]$Options[$at].Id }
405
+ }
406
+ default { }
407
+ }
408
+ if (-not $NoRender) {
409
+ Reset-AfyxChoiceFrame -LineCount $frameLines -Terminal $Terminal
410
+ $frameLines = Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected $selected -Checked @{} -Terminal $Terminal
411
+ }
412
+ }
413
+ }
414
+
415
+ function Read-AfyxMultiChoice {
416
+ [CmdletBinding()]
417
+ param(
418
+ [Parameter(Mandatory)][string]$Prompt,
419
+ [Parameter(Mandatory)][object[]]$Options,
420
+ [string[]]$DefaultId = @(),
421
+ [Parameter(Mandatory)]$Terminal,
422
+ [scriptblock]$ReadKey,
423
+ [scriptblock]$ReadLine,
424
+ [switch]$NoRender
425
+ )
426
+ $checked = @{}
427
+ foreach ($id in $DefaultId) { $checked[[string]$id] = $true }
428
+ if (-not (Test-AfyxAdvancedMenu -Terminal $Terminal -ReadKey $ReadKey)) {
429
+ if (-not $NoRender) { $null = Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected 0 -Checked $checked -Terminal $Terminal -Multiple }
430
+ $reader = if ($ReadLine) { $ReadLine } else { { Read-Host 'Selections (comma-separated numbers)' } }
431
+ $answer = (& $reader).Trim()
432
+ if ($answer -match '^(?i:q|quit|esc|escape)$') { throw [OperationCanceledException]::new('Installer cancelled by user.') }
433
+ if (-not $answer) { return @($DefaultId) }
434
+ $result = @()
435
+ foreach ($part in @($answer -split ',')) {
436
+ if ($part.Trim() -notmatch '^\d+$') { continue }
437
+ $at = [int]$part.Trim() - 1
438
+ if ($at -ge 0 -and $at -lt $Options.Count -and (-not $Options[$at].PSObject.Properties['Enabled'] -or [bool]$Options[$at].Enabled)) { $result += [string]$Options[$at].Id }
439
+ }
440
+ return @($result | Select-Object -Unique)
441
+ }
442
+ $selected = 0
443
+ $frameLines = if (-not $NoRender) { Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected $selected -Checked $checked -Terminal $Terminal -Multiple } else { 0 }
444
+ while ($true) {
445
+ $key = Read-AfyxMenuKey -Terminal $Terminal -ReadKey $ReadKey
446
+ $action = Get-AfyxKeyAction -RawKey $key
447
+ if ($null -eq $action) { continue }
448
+ switch -Regex ($action) {
449
+ '^Tab$' { Move-AfyxDashboardFocus -Terminal $Terminal }
450
+ '^ShiftTab$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction -1 }
451
+ '^LeftArrow$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction -1 }
452
+ '^RightArrow$' { Move-AfyxDashboardFocus -Terminal $Terminal -Direction 1 }
453
+ '^PageUp$' { Move-AfyxDashboardScroll -Terminal $Terminal -Direction -5 }
454
+ '^PageDown$' { Move-AfyxDashboardScroll -Terminal $Terminal -Direction 5 }
455
+ '^Home$' { Set-AfyxDashboardScroll -Terminal $Terminal -Position 0 }
456
+ '^End$' { Set-AfyxDashboardScroll -Terminal $Terminal -Position ([int]::MaxValue) }
457
+ '^UpArrow$' { if ((Test-AfyxDashboard -Terminal $Terminal) -and $Terminal.DashboardState.Focus -ne 1) { Move-AfyxDashboardScroll -Terminal $Terminal -Direction -1 } else { $selected = Get-AfyxEnabledOptionIndex -Options $Options -Start $selected -Direction -1 } }
458
+ '^DownArrow$' { if ((Test-AfyxDashboard -Terminal $Terminal) -and $Terminal.DashboardState.Focus -ne 1) { Move-AfyxDashboardScroll -Terminal $Terminal -Direction 1 } else { $selected = Get-AfyxEnabledOptionIndex -Options $Options -Start $selected -Direction 1 } }
459
+ '^Escape$' { throw [OperationCanceledException]::new('Installer cancelled by user.') }
460
+ '^Spacebar$' {
461
+ $id = [string]$Options[$selected].Id
462
+ if ($checked.ContainsKey($id)) { $checked.Remove($id) } else { $checked[$id] = $true }
463
+ }
464
+ '^Enter$' { return @($Options | Where-Object { $checked.ContainsKey([string]$_.Id) } | ForEach-Object { [string]$_.Id }) }
465
+ '^[1-9]$' {
466
+ $at = [int]$action - 1
467
+ if ($at -ge 0 -and $at -lt $Options.Count -and (-not $Options[$at].PSObject.Properties['Enabled'] -or [bool]$Options[$at].Enabled)) {
468
+ $id = [string]$Options[$at].Id
469
+ if ($checked.ContainsKey($id)) { $checked.Remove($id) } else { $checked[$id] = $true }
470
+ $selected = $at
471
+ }
472
+ }
473
+ default { }
474
+ }
475
+ if (-not $NoRender) {
476
+ Reset-AfyxChoiceFrame -LineCount $frameLines -Terminal $Terminal
477
+ $frameLines = Show-AfyxChoiceFrame -Prompt $Prompt -Options $Options -Selected $selected -Checked $checked -Terminal $Terminal -Multiple
478
+ }
479
+ }
480
+ }
481
+
482
+ function Read-AfyxConfirmation {
483
+ [CmdletBinding()]
484
+ param([Parameter(Mandatory)][string]$Prompt, [Parameter(Mandatory)]$Terminal, [scriptblock]$ReadKey, [scriptblock]$ReadLine, [switch]$NoRender)
485
+ $options = @(
486
+ [pscustomobject]@{ Id = 'yes'; Label = 'Apply this plan'; Detail = 'Mutation is explicitly authorized'; Enabled = $true },
487
+ [pscustomobject]@{ Id = 'no'; Label = 'Cancel'; Detail = 'No configuration changes'; Enabled = $true }
488
+ )
489
+ # Text-only / redirected prompt: accept Y/N explicitly while retaining numbered and Enter behavior.
490
+ $sourceLine = if ($ReadLine) { $ReadLine } else { { Read-Host 'Selection' } }
491
+ $mappedLine = {
492
+ $answer = ([string](& $sourceLine)).Trim()
493
+ if ($answer -match '^(?i:y|yes)$') { return '1' }
494
+ if ($answer -match '^(?i:n|no)$') { return '2' }
495
+ return $answer
496
+ }.GetNewClosure()
497
+ return (Read-AfyxSingleChoice -Prompt $Prompt -Options $options -DefaultId 'no' -Terminal $Terminal -ReadKey $ReadKey -ReadLine $mappedLine -NoRender:$NoRender) -eq 'yes'
498
+ }
499
+
500
+ function Show-AfyxReceipt {
501
+ [CmdletBinding()]
502
+ param([Parameter(Mandatory)][object[]]$Items, [Parameter(Mandatory)]$Terminal, [string]$Title = 'Installation Receipt')
503
+ if (Test-AfyxDashboard -Terminal $Terminal) {
504
+ $Terminal.DashboardState.Step = 5
505
+ $Terminal.DashboardState.Section = $Title
506
+ $Terminal.DashboardState.Prompt = ''
507
+ $Terminal.DashboardState.Options = @()
508
+ $Terminal.DashboardState.Events = @($Items | ForEach-Object {
509
+ [pscustomobject]@{ Text = "[$([string]$_.Status)] $([string]$_.Name) - $([string]$_.Detail)"; Tone = Get-AfyxStatusTone -Status ([string]$_.Status) }
510
+ })
511
+ $Terminal.DashboardState.Scroll[1] = 0
512
+ $Terminal.DashboardState.Scroll[2] = 0
513
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
514
+ return
515
+ }
516
+ Write-AfyxSection -Title $Title -Terminal $Terminal
517
+ foreach ($item in $Items) { Write-AfyxStatus -Status ([string]$item.Status) -Name ([string]$item.Name) -Detail ([string]$item.Detail) -Terminal $Terminal }
518
+ }
519
+
520
+ function ConvertFrom-AfyxJson {
521
+ [CmdletBinding()]
522
+ param(
523
+ [Parameter(Mandatory = $true, ValueFromPipeline = $true)][string]$InputObject,
524
+ [int]$Depth = 10
525
+ )
526
+ process {
527
+ if ([string]::IsNullOrWhiteSpace($InputObject)) { return $null }
528
+ if ($PSVersionTable.PSVersion.Major -ge 6) {
529
+ return ($InputObject | ConvertFrom-Json -Depth $Depth)
530
+ }
531
+ return ($InputObject | ConvertFrom-Json)
532
+ }
533
+ }
534
+
535
+ function Test-AfyxDashboard {
536
+ param([Parameter(Mandatory)]$Terminal)
537
+ return [bool]($Terminal.PSObject.Properties['DashboardState'] -and $Terminal.DashboardState.Enabled)
538
+ }
539
+
540
+ function Enable-AfyxDashboard {
541
+ [CmdletBinding()]
542
+ param([Parameter(Mandatory)]$Terminal, [string[]]$Providers = @())
543
+ if (-not $Terminal.Interactive -or -not $Terminal.Ansi) { return }
544
+ $state = [pscustomobject]@{
545
+ Enabled = $true
546
+ Step = 1
547
+ Section = 'Environment'
548
+ Prompt = ''
549
+ Options = @()
550
+ Selected = 0
551
+ Checked = @{}
552
+ Multiple = $false
553
+ Providers = @($Providers)
554
+ Events = @()
555
+ Focus = 1
556
+ Scroll = @{ 0 = 0; 1 = 0; 2 = 0 }
557
+ LastFrame = @()
558
+ LastWidth = 0
559
+ }
560
+ $Terminal | Add-Member -NotePropertyName DashboardState -NotePropertyValue $state -Force
561
+ Show-AfyxDashboard -Terminal $Terminal -ForceFull
562
+ }
563
+
564
+ function Fit-AfyxDashboardLine {
565
+ param([AllowEmptyString()][string]$Text, [int]$Width)
566
+ if ($Width -lt 1) { return '' }
567
+ $clean = ($Text -replace '[\r\n\t]', ' ')
568
+ if ($clean.Length -gt $Width) {
569
+ if ($Width -eq 1) { return '>' }
570
+ return $clean.Substring(0, $Width - 1) + '>'
571
+ }
572
+ return $clean.PadRight($Width)
573
+ }
574
+
575
+ function Expand-AfyxDashboardItems {
576
+ param([object[]]$Items, [int]$Width)
577
+ $expanded = @()
578
+ $limit = [Math]::Max(8, $Width)
579
+ $hangIndent = ' '
580
+ foreach ($item in $Items) {
581
+ $remaining = [string]$item.Text
582
+ $tone = if ($item.PSObject.Properties['Tone']) { [string]$item.Tone } else { 'Text' }
583
+ $selected = [bool]($item.PSObject.Properties['Selected'] -and $item.Selected)
584
+ $isFirstLine = $true
585
+ while ($remaining.Length -gt $limit) {
586
+ $effectiveLimit = if ($isFirstLine) { $limit } else { [Math]::Max(6, $limit - $hangIndent.Length) }
587
+ $cut = -1
588
+ $spaceCut = $remaining.LastIndexOf(' ', [Math]::Min($remaining.Length - 1, $effectiveLimit - 1), $effectiveLimit)
589
+ if ($spaceCut -ge [Math]::Floor($effectiveLimit / 3)) {
590
+ $cut = $spaceCut
591
+ } else {
592
+ $delims = @(';', ',', '\', '/')
593
+ foreach ($delim in $delims) {
594
+ $dCut = $remaining.LastIndexOf($delim, [Math]::Min($remaining.Length - 1, $effectiveLimit - 1), $effectiveLimit)
595
+ if ($dCut -ge [Math]::Floor($effectiveLimit / 3) -and $dCut -gt $cut) {
596
+ $cut = $dCut + 1
597
+ }
598
+ }
599
+ }
600
+ if ($cut -le 0 -or $cut -gt $effectiveLimit) { $cut = $effectiveLimit }
601
+ $chunk = $remaining.Substring(0, $cut)
602
+ $lineText = if ($isFirstLine) { $chunk } else { "$hangIndent$chunk" }
603
+ $expanded += [pscustomobject]@{ Text = $lineText; Tone = $tone; Selected = $selected }
604
+ $remaining = $remaining.Substring($cut).TrimStart()
605
+ $selected = $false
606
+ $isFirstLine = $false
607
+ }
608
+ $lastLine = if ($isFirstLine) { $remaining } else { "$hangIndent$remaining" }
609
+ $expanded += [pscustomobject]@{ Text = $lastLine; Tone = $tone; Selected = $selected }
610
+ }
611
+ return $expanded
612
+ }
613
+
614
+ function Select-AfyxDashboardWindow {
615
+ param([object[]]$Items, [int]$Capacity, $State, [int]$Panel)
616
+ $capacity = [Math]::Max(1, $Capacity)
617
+ $last = [Math]::Max(0, $Items.Count - $capacity)
618
+ $start = [Math]::Max(0, [Math]::Min([long]$State.Scroll[$Panel], [long]$last))
619
+ $State.Scroll[$Panel] = [int]$start
620
+ return @($Items | Select-Object -Skip $start -First $capacity)
621
+ }
622
+
623
+ function Format-AfyxDashboardSegment {
624
+ param([string]$Text, [string]$Tone, [string]$Background, $Terminal)
625
+ if (-not $Terminal.Ansi) { return $Text }
626
+ $foreground = $script:AfyxPalette[$Tone]
627
+ if (-not $foreground) { $foreground = $script:AfyxPalette.Text }
628
+ $backgroundCode = switch ($Background) {
629
+ 'Focus' { '48;2;34;211;238' }
630
+ 'Base' { '48;2;11;16;32' }
631
+ default { '48;2;17;25;43' }
632
+ }
633
+ if ($Background -eq 'Focus') { $foreground = '38;2;11;16;32' }
634
+ return "$script:AfyxAnsi[$foreground;$backgroundCode" + "m$Text$script:AfyxAnsi[0m"
635
+ }
636
+
637
+ function New-AfyxDashboardPanel {
638
+ param(
639
+ [string]$Title,
640
+ [object[]]$Items,
641
+ [int]$Width,
642
+ [int]$Height,
643
+ $Terminal,
644
+ [bool]$Focused = $false,
645
+ [int]$TotalCount = 0,
646
+ [int]$StartIndex = 0
647
+ )
648
+ $horizontal = [string][char]0x2500
649
+ $vertical = [string][char]0x2502
650
+ $top = [string][char]0x256D + ($horizontal * ($Width - 2)) + [char]0x256E
651
+ $bottom = [string][char]0x2570 + ($horizontal * ($Width - 2)) + [char]0x256F
652
+ $borderTone = if ($Focused) { 'Primary' } else { 'Secondary' }
653
+ $result = @((Format-AfyxDashboardSegment -Text $top -Tone $borderTone -Background Base -Terminal $Terminal))
654
+ $interior = [Math]::Max(0, $Height - 2)
655
+ $contentWidth = [Math]::Max(4, $Width - 4)
656
+
657
+ for ($index = 0; $index -lt $interior; $index++) {
658
+ $item = if ($index -eq 0) {
659
+ $headerText = " $Title"
660
+ if ($TotalCount -gt ($interior - 1)) {
661
+ $endIndex = [Math]::Min($TotalCount, $StartIndex + $interior - 1)
662
+ $upArrow = if ($StartIndex -gt 0) { '^' } else { ' ' }
663
+ $downArrow = if ($endIndex -lt $TotalCount) { 'v' } else { ' ' }
664
+ $headerText = " $Title $upArrow[$($StartIndex + 1)-$endIndex/$TotalCount]$downArrow"
665
+ }
666
+ [pscustomobject]@{ Text = $headerText; Tone = $borderTone; Selected = $false }
667
+ } elseif (($index - 1) -lt $Items.Count) {
668
+ $Items[$index - 1]
669
+ } else {
670
+ [pscustomobject]@{ Text = ''; Tone = 'Text'; Selected = $false }
671
+ }
672
+ $tone = if ($item.PSObject.Properties['Tone']) { [string]$item.Tone } else { 'Text' }
673
+ $selected = [bool]($item.PSObject.Properties['Selected'] -and $item.Selected)
674
+ $background = if ($selected) { 'Focus' } else { 'Surface' }
675
+ $content = Fit-AfyxDashboardLine -Text ([string]$item.Text) -Width $contentWidth
676
+ $result += (Format-AfyxDashboardSegment -Text $vertical -Tone $borderTone -Background Base -Terminal $Terminal) +
677
+ (Format-AfyxDashboardSegment -Text " $content " -Tone $tone -Background $background -Terminal $Terminal) +
678
+ (Format-AfyxDashboardSegment -Text $vertical -Tone $borderTone -Background Base -Terminal $Terminal)
679
+ }
680
+ $result += Format-AfyxDashboardSegment -Text $bottom -Tone $borderTone -Background Base -Terminal $Terminal
681
+ return $result
682
+ }
683
+
684
+ function Get-AfyxDashboardFrame {
685
+ [CmdletBinding()]
686
+ param([Parameter(Mandatory)]$Terminal)
687
+ $state = $Terminal.DashboardState
688
+ $width = [Math]::Max(40, [int]$Terminal.Width)
689
+ $height = [Math]::Max(20, [int]$Terminal.Height)
690
+ $wide = $width -ge 96
691
+ $brandLines = @(
692
+ ' AFYX / ENGINEERING KIT'
693
+ ' MIDNIGHT CIRCUIT | ALPHA INSTALLER'
694
+ " $($state.Section) | Component versions and source identity in the review"
695
+ )
696
+ $header = @($brandLines | ForEach-Object { Fit-AfyxDashboardLine -Text $_ -Width $width })
697
+ $frame = @($header | ForEach-Object { Format-AfyxDashboardSegment -Text $_ -Tone Primary -Background Base -Terminal $Terminal })
698
+ $steps = @('DETECT', 'SELECT', 'CONFIGURE', 'REVIEW/APPLY', 'FINISH')
699
+ if ($wide) {
700
+ $stepParts = @()
701
+ for ($index = 0; $index -lt $steps.Count; $index++) {
702
+ $mark = if (($index + 1) -eq $state.Step) { '>' } elseif (($index + 1) -lt $state.Step) { '+' } else { ' ' }
703
+ $stepParts += "$mark$($index + 1) $($steps[$index])"
704
+ }
705
+ $stepText = ' ' + ($stepParts -join ' -- ')
706
+ } else {
707
+ $stepText = " STEP $($state.Step)/5 $($steps[$state.Step - 1])"
708
+ }
709
+ $frame += Format-AfyxDashboardSegment -Text (Fit-AfyxDashboardLine -Text $stepText -Width $width) -Tone Secondary -Background Base -Terminal $Terminal
710
+
711
+ $choice = @()
712
+ if ($state.Prompt) {
713
+ $choice += [pscustomobject]@{ Text = "$($state.Prompt)"; Tone = 'Accent'; Selected = $false }
714
+ for ($index = 0; $index -lt $state.Options.Count; $index++) {
715
+ $option = $state.Options[$index]
716
+ $enabled = -not $option.PSObject.Properties['Enabled'] -or [bool]$option.Enabled
717
+ $mark = if ($state.Multiple) { if ($state.Checked.ContainsKey([string]$option.Id)) { '[x]' } else { '[ ]' } } else { "[$($index + 1)]" }
718
+ $cursor = if ($index -eq $state.Selected) { '>' } else { ' ' }
719
+ $choice += [pscustomobject]@{
720
+ Text = "$cursor $mark $($option.Label)"
721
+ Tone = if ($enabled) { 'Text' } else { 'Muted' }
722
+ Selected = ($index -eq $state.Selected -and $enabled)
723
+ }
724
+ if (($index -eq $state.Selected -or $state.Options.Count -le 4) -and $option.PSObject.Properties['Detail'] -and $option.Detail) {
725
+ $choice += [pscustomobject]@{ Text = " $($option.Detail)"; Tone = 'Muted'; Selected = $false }
726
+ }
727
+ }
728
+ } else {
729
+ $choice += [pscustomobject]@{ Text = "$($state.Section)"; Tone = 'Accent'; Selected = $false }
730
+ $choice += @($state.Events)
731
+ }
732
+ $providers = @($state.Providers | ForEach-Object { [pscustomobject]@{ Text = "$_"; Tone = 'Text'; Selected = $false } })
733
+ if (-not $providers.Count) { $providers = @([pscustomobject]@{ Text = 'Detection pending'; Tone = 'Muted'; Selected = $false }) }
734
+ $activity = @($state.Events)
735
+ if (-not $activity.Count) { $activity = @([pscustomobject]@{ Text = 'Awaiting selection'; Tone = 'Muted'; Selected = $false }) }
736
+ $panelHeight = $height - 5
737
+ if ($wide) {
738
+ $gap = ' '
739
+ $usable = $width - 4
740
+ $leftWidth = [Math]::Floor($usable * 0.25)
741
+ $middleWidth = [Math]::Floor($usable * 0.44)
742
+ $rightWidth = $usable - $leftWidth - $middleWidth
743
+ $providers = @(Expand-AfyxDashboardItems -Items $providers -Width ($leftWidth - 4))
744
+ $choice = @(Expand-AfyxDashboardItems -Items $choice -Width ($middleWidth - 4))
745
+ $activity = @(Expand-AfyxDashboardItems -Items $activity -Width ($rightWidth - 4))
746
+ $leftHeight = [Math]::Min($panelHeight, [Math]::Max(6, $providers.Count + 3))
747
+ $middleHeight = [Math]::Min($panelHeight, [Math]::Max(8, $choice.Count + 3))
748
+ $rightHeight = [Math]::Min($panelHeight, [Math]::Max(8, $activity.Count + 3))
749
+ $contentHeight = [Math]::Max($leftHeight, [Math]::Max($middleHeight, $rightHeight))
750
+ $left = New-AfyxDashboardPanel -Title 'PROVIDERS / HOST' -Items @(Select-AfyxDashboardWindow -Items $providers -Capacity ($leftHeight - 3) -State $state -Panel 0) -Width $leftWidth -Height $leftHeight -Terminal $Terminal -Focused ($state.Focus -eq 0) -TotalCount $providers.Count -StartIndex ([int]$state.Scroll[0])
751
+ $middle = New-AfyxDashboardPanel -Title 'SELECTION / STATUS' -Items @(Select-AfyxDashboardWindow -Items $choice -Capacity ($middleHeight - 3) -State $state -Panel 1) -Width $middleWidth -Height $middleHeight -Terminal $Terminal -Focused ($state.Focus -eq 1) -TotalCount $choice.Count -StartIndex ([int]$state.Scroll[1])
752
+ $right = New-AfyxDashboardPanel -Title 'PLAN / ACTIVITY' -Items @(Select-AfyxDashboardWindow -Items $activity -Capacity ($rightHeight - 3) -State $state -Panel 2) -Width $rightWidth -Height $rightHeight -Terminal $Terminal -Focused ($state.Focus -eq 2) -TotalCount $activity.Count -StartIndex ([int]$state.Scroll[2])
753
+ $blankLeft = Format-AfyxDashboardSegment -Text (' ' * $leftWidth) -Tone Muted -Background Base -Terminal $Terminal
754
+ $blankMiddle = Format-AfyxDashboardSegment -Text (' ' * $middleWidth) -Tone Muted -Background Base -Terminal $Terminal
755
+ $blankRight = Format-AfyxDashboardSegment -Text (' ' * $rightWidth) -Tone Muted -Background Base -Terminal $Terminal
756
+ for ($index = 0; $index -lt $contentHeight; $index++) {
757
+ $frame += $(if ($index -lt $left.Count) { $left[$index] } else { $blankLeft }) + $gap + $(if ($index -lt $middle.Count) { $middle[$index] } else { $blankMiddle }) + $gap + $(if ($index -lt $right.Count) { $right[$index] } else { $blankRight })
758
+ }
759
+ while ($frame.Count -lt $height - 1) {
760
+ $frame += Format-AfyxDashboardSegment -Text (' ' * $width) -Tone Muted -Background Base -Terminal $Terminal
761
+ }
762
+ } else {
763
+ $mainHeight = [Math]::Max(8, $height - 14)
764
+ $subHeight = [Math]::Max(4, [Math]::Floor(($height - $mainHeight - 5) / 2))
765
+ $choice = @(Expand-AfyxDashboardItems -Items $choice -Width ($width - 4))
766
+ $providers = @(Expand-AfyxDashboardItems -Items $providers -Width ($width - 4))
767
+ $activity = @(Expand-AfyxDashboardItems -Items $activity -Width ($width - 4))
768
+ $frame += New-AfyxDashboardPanel -Title 'SELECTION / STATUS' -Items @(Select-AfyxDashboardWindow -Items $choice -Capacity ($mainHeight - 3) -State $state -Panel 1) -Width $width -Height $mainHeight -Terminal $Terminal -Focused ($state.Focus -eq 1) -TotalCount $choice.Count -StartIndex ([int]$state.Scroll[1])
769
+ $frame += New-AfyxDashboardPanel -Title 'PROVIDERS / HOST' -Items @(Select-AfyxDashboardWindow -Items $providers -Capacity ($subHeight - 3) -State $state -Panel 0) -Width $width -Height $subHeight -Terminal $Terminal -Focused ($state.Focus -eq 0) -TotalCount $providers.Count -StartIndex ([int]$state.Scroll[0])
770
+ $frame += New-AfyxDashboardPanel -Title 'PLAN / ACTIVITY' -Items @(Select-AfyxDashboardWindow -Items $activity -Capacity ($subHeight - 3) -State $state -Panel 2) -Width $width -Height $subHeight -Terminal $Terminal -Focused ($state.Focus -eq 2) -TotalCount $activity.Count -StartIndex ([int]$state.Scroll[2])
771
+ }
772
+ $footer = if ($wide) { ' UP/DOWN scroll/move TAB/ARROWS switch panel SPACE toggle ENTER continue ESC cancel' } else { ' UP/DOWN move TAB panel SPACE toggle ENTER select ESC cancel' }
773
+ $frame += Format-AfyxDashboardSegment -Text (Fit-AfyxDashboardLine -Text $footer -Width $width) -Tone Muted -Background Base -Terminal $Terminal
774
+ return $frame
775
+ }
776
+
777
+ function Show-AfyxDashboard {
778
+ [CmdletBinding()]
779
+ param([Parameter(Mandatory)]$Terminal, [switch]$ForceFull)
780
+ if (-not (Test-AfyxDashboard -Terminal $Terminal)) { return }
781
+ try {
782
+ $Terminal.Width = [Math]::Max(40, [int]$Host.UI.RawUI.WindowSize.Width)
783
+ $Terminal.Height = [Math]::Max(20, [int]$Host.UI.RawUI.WindowSize.Height)
784
+ } catch { }
785
+ $state = $Terminal.DashboardState
786
+ $frame = @(Get-AfyxDashboardFrame -Terminal $Terminal)
787
+ $escape = [char]27
788
+ $changes = ''
789
+ if ($state.LastWidth -ne $Terminal.Width -or $state.LastFrame.Count -ne $frame.Count) {
790
+ $changes += "$escape[2J"
791
+ $ForceFull = $true
792
+ }
793
+ for ($index = 0; $index -lt $frame.Count; $index++) {
794
+ if ($ForceFull -or $index -ge $state.LastFrame.Count -or $frame[$index] -cne $state.LastFrame[$index]) {
795
+ $changes += "$escape[$($index + 1);1H$escape[2K$($frame[$index])"
796
+ }
797
+ }
798
+ if ($changes) {
799
+ Write-Host -NoNewline "$escape[?25l$changes$escape[$($frame.Count + 1);1H$escape[?25h"
800
+ }
801
+ $state.LastFrame = $frame
802
+ $state.LastWidth = $Terminal.Width
803
+ }
804
+
805
+ function Move-AfyxDashboardFocus {
806
+ param([Parameter(Mandatory)]$Terminal, [int]$Direction = 1)
807
+ if (-not (Test-AfyxDashboard -Terminal $Terminal)) { return }
808
+ $Terminal.DashboardState.Focus = ($Terminal.DashboardState.Focus + $Direction + 3) % 3
809
+ Show-AfyxDashboard -Terminal $Terminal
810
+ }
811
+
812
+ function Move-AfyxDashboardScroll {
813
+ param([Parameter(Mandatory)]$Terminal, [int]$Direction)
814
+ if (-not (Test-AfyxDashboard -Terminal $Terminal)) { return }
815
+ $panel = [int]$Terminal.DashboardState.Focus
816
+ $Terminal.DashboardState.Scroll[$panel] = [Math]::Max(0, [long]$Terminal.DashboardState.Scroll[$panel] + $Direction)
817
+ Show-AfyxDashboard -Terminal $Terminal
818
+ }
819
+
820
+ function Set-AfyxDashboardScroll {
821
+ param([Parameter(Mandatory)]$Terminal, [int]$Position)
822
+ if (-not (Test-AfyxDashboard -Terminal $Terminal)) { return }
823
+ $panel = [int]$Terminal.DashboardState.Focus
824
+ $Terminal.DashboardState.Scroll[$panel] = [Math]::Max(0, [long]$Position)
825
+ Show-AfyxDashboard -Terminal $Terminal
826
+ }
827
+
828
+ function Disable-AfyxDashboard {
829
+ [CmdletBinding()]
830
+ param([Parameter(Mandatory)]$Terminal)
831
+ if (-not (Test-AfyxDashboard -Terminal $Terminal)) { return }
832
+ $escape = [char]27
833
+ $height = if ($Terminal.DashboardState.LastFrame.Count) { $Terminal.DashboardState.LastFrame.Count } else { 24 }
834
+ Write-Host "$escape[$($height + 1);1H$escape[?25h"
835
+ $Terminal.DashboardState.Enabled = $false
836
+ }
837
+
838
+ Export-ModuleMember -Function Test-AfyxAnsiSupport, Test-AfyxInteractiveTerminal, New-AfyxTerminalContext, Get-AfyxStyledText, Format-AfyxWrappedText, Write-AfyxText, Show-AfyxBanner, Show-AfyxStep, Write-AfyxSection, Write-AfyxStatus, Get-AfyxOutcomeStatus, Get-AfyxKeyAction, Read-AfyxSingleChoice, Read-AfyxMultiChoice, Read-AfyxConfirmation, Show-AfyxReceipt, ConvertFrom-AfyxJson, Enable-AfyxDashboard, Get-AfyxDashboardFrame, Show-AfyxDashboard, Move-AfyxDashboardFocus, Move-AfyxDashboardScroll, Set-AfyxDashboardScroll, Disable-AfyxDashboard, Test-AfyxDashboard