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

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,399 @@
1
+ Set-StrictMode -Version Latest
2
+
3
+ # Canonical component model for the Afyx Codex Engineering Kit (PowerShell).
4
+ # The data lives once in scripts/components.json; installer, updater,
5
+ # uninstaller, verifier and doctor all ask this module for component state.
6
+ # Read-only: nothing here writes, installs, or changes configuration.
7
+
8
+ $script:ContractPath = Join-Path (Split-Path -Parent $PSScriptRoot) 'components.json'
9
+ $script:States = @('NOT INSTALLED', 'HEALTHY', 'INCOMPLETE', 'INVALID', 'DRIFTED', 'UNKNOWN')
10
+
11
+ function Get-AfyxPlatform {
12
+ if ($PSVersionTable.PSVersion.Major -ge 6) {
13
+ if ($IsWindows) { return 'windows' }
14
+ return 'unix'
15
+ }
16
+ return 'windows'
17
+ }
18
+
19
+ function Get-AfyxCodexHost {
20
+ [CmdletBinding()]
21
+ param()
22
+
23
+ if ((Get-AfyxPlatform) -eq 'windows') {
24
+ foreach ($name in @('codex.exe', 'codex.cmd')) {
25
+ $command = Get-Command $name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
26
+ if ($command) {
27
+ return [pscustomobject]@{
28
+ State = 'CLI_READY'
29
+ Path = [string]$command.Source
30
+ Command = $name
31
+ Detail = "Compatible native Codex launcher detected: $name"
32
+ }
33
+ }
34
+ }
35
+ $shim = Get-Command codex.ps1 -CommandType ExternalScript -ErrorAction SilentlyContinue | Select-Object -First 1
36
+ if ($shim) {
37
+ return [pscustomobject]@{
38
+ State = 'UNSUPPORTED_POWERSHELL_SHIM'
39
+ Path = [string]$shim.Source
40
+ Command = 'codex.ps1'
41
+ Detail = 'codex.ps1 cannot be passed to the native Node.js MCP lifecycle; install or expose codex.exe or codex.cmd.'
42
+ }
43
+ }
44
+ return [pscustomobject]@{
45
+ State = 'CLI_NOT_FOUND'
46
+ Path = ''
47
+ Command = ''
48
+ Detail = 'No compatible Codex CLI launcher was found; install or expose codex.exe or codex.cmd.'
49
+ }
50
+ }
51
+
52
+ $command = Get-Command codex -ErrorAction SilentlyContinue | Select-Object -First 1
53
+ if ($command) {
54
+ return [pscustomobject]@{
55
+ State = 'CLI_READY'
56
+ Path = [string]$command.Source
57
+ Command = 'codex'
58
+ Detail = 'Codex CLI detected.'
59
+ }
60
+ }
61
+ return [pscustomobject]@{
62
+ State = 'CLI_NOT_FOUND'
63
+ Path = ''
64
+ Command = ''
65
+ Detail = 'No compatible Codex CLI launcher was found.'
66
+ }
67
+ }
68
+
69
+ function New-AfyxComponentContext {
70
+ [CmdletBinding()]
71
+ param(
72
+ [string]$SkillsRoot,
73
+ [string]$GraphRoot,
74
+ [string]$ContextRoot,
75
+ [string]$ForgeRoot,
76
+ [string]$CodexHome,
77
+ [string]$Platform
78
+ )
79
+ $userHome = if ($env:USERPROFILE) { $env:USERPROFILE } elseif ($env:HOME) { $env:HOME } else { [Environment]::GetFolderPath('UserProfile') }
80
+ if (-not $SkillsRoot) { $SkillsRoot = Join-Path (Join-Path $userHome '.agents') 'skills' }
81
+ if (-not $GraphRoot) { $GraphRoot = if ($env:AFYX_GRAPH_RUNTIME_ROOT) { $env:AFYX_GRAPH_RUNTIME_ROOT } else { Join-Path (Join-Path $userHome '.afyx') 'graph' } }
82
+ if (-not $ContextRoot) { $ContextRoot = if ($env:AFYX_CONTEXT_RUNTIME_ROOT) { $env:AFYX_CONTEXT_RUNTIME_ROOT } else { Join-Path (Join-Path $userHome '.afyx') 'context' } }
83
+ if (-not $ForgeRoot) { $ForgeRoot = if ($env:AFYX_FORGE_RUNTIME_ROOT) { $env:AFYX_FORGE_RUNTIME_ROOT } else { Join-Path (Join-Path $userHome '.afyx') 'forge' } }
84
+ if (-not $CodexHome) { $CodexHome = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $userHome '.codex' } }
85
+ if (-not $Platform) { $Platform = Get-AfyxPlatform }
86
+ [pscustomobject]@{
87
+ SkillsRoot = $SkillsRoot
88
+ GraphRoot = $GraphRoot
89
+ ContextRoot = $ContextRoot
90
+ ForgeRoot = $ForgeRoot
91
+ CodexHome = $CodexHome
92
+ Platform = $Platform
93
+ }
94
+ }
95
+
96
+ function Get-AfyxComponentContract {
97
+ [CmdletBinding()]
98
+ param([string]$Path = $script:ContractPath)
99
+ $document = Get-Content -Raw -LiteralPath $Path -Encoding utf8 | ConvertFrom-Json
100
+ if ($document.schema_version -ne 1) { throw "Unsupported component contract schema_version: $($document.schema_version)" }
101
+ return @($document.components)
102
+ }
103
+
104
+ function Get-AfyxControlPlaneContract {
105
+ [CmdletBinding()]
106
+ param([string]$Path = $script:ContractPath)
107
+ $document = Get-Content -Raw -LiteralPath $Path -Encoding utf8 | ConvertFrom-Json
108
+ if ($document.schema_version -ne 1 -or $document.control_plane_version -ne 1) {
109
+ throw 'Unsupported Afyx component/control-plane contract version.'
110
+ }
111
+ return $document
112
+ }
113
+
114
+ function Get-AfyxProviderRegistry {
115
+ [CmdletBinding()]
116
+ param([string]$Path = $script:ContractPath)
117
+ return @((Get-AfyxControlPlaneContract -Path $Path).providers)
118
+ }
119
+
120
+ function Get-AfyxDesiredComponentIds {
121
+ [CmdletBinding()]
122
+ param(
123
+ [Parameter(Mandatory)][ValidateSet('minimal', 'recommended', 'full', 'custom')][string]$Preset,
124
+ [string[]]$CustomComponent = @(),
125
+ [string]$Path = $script:ContractPath
126
+ )
127
+ $components = @(Get-AfyxComponentContract -Path $Path)
128
+ if ($CustomComponent.Count) {
129
+ $CustomComponent = @($CustomComponent | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
130
+ }
131
+ $selectable = @($components | Where-Object { $_.type -ne 'detected-cli' } | ForEach-Object { [string]$_.id })
132
+ if ($Preset -eq 'custom') {
133
+ $unknown = @($CustomComponent | Where-Object { $_ -notin $selectable })
134
+ if ($unknown.Count) { throw "Unknown custom component(s): $($unknown -join ', ')" }
135
+ return @($selectable | Where-Object { $_ -in $CustomComponent })
136
+ }
137
+ if ($CustomComponent.Count) { throw '-CustomComponent is valid only with preset custom.' }
138
+ return @($components | Where-Object { ";$($_.presets);" -like "*;$Preset;*" } | ForEach-Object { [string]$_.id })
139
+ }
140
+
141
+ function Get-AfyxControlPlan {
142
+ [CmdletBinding()]
143
+ param(
144
+ [Parameter(Mandatory)][ValidateSet('minimal', 'recommended', 'full', 'custom')][string]$Preset,
145
+ [Parameter(Mandatory)]$Context,
146
+ [string[]]$CustomComponent = @(),
147
+ [string[]]$Provider = @(),
148
+ [hashtable]$StateById,
149
+ [string]$ContractPath = $script:ContractPath
150
+ )
151
+ $contract = Get-AfyxControlPlaneContract -Path $ContractPath
152
+ $components = @($contract.components)
153
+ if (-not $Provider.Count) { $Provider = @([string]$contract.default_provider) }
154
+ $providerIds = @($contract.providers | ForEach-Object { [string]$_.provider })
155
+ $unknownProviders = @($Provider | Where-Object { $_ -notin $providerIds })
156
+ if ($unknownProviders.Count) { throw "Unknown provider(s): $($unknownProviders -join ', ')" }
157
+ $Provider = @($providerIds | Where-Object { $_ -in $Provider })
158
+ $desiredIds = @(Get-AfyxDesiredComponentIds -Preset $Preset -CustomComponent $CustomComponent -Path $ContractPath)
159
+ $desiredIds = @($desiredIds | Where-Object {
160
+ $wantedId = $_
161
+ $component = @($components | Where-Object { [string]$_.id -eq $wantedId })[0]
162
+ $restrictionText = if ($component.PSObject.Properties['providers']) { [string]$component.providers } else { '' }
163
+ [string]::IsNullOrEmpty($restrictionText) -or @(($restrictionText -split ';') | Where-Object { $_ -in $Provider }).Count -gt 0
164
+ })
165
+ if (-not $StateById) {
166
+ $StateById = @{}
167
+ foreach ($state in (Get-AfyxComponentStates -Context $Context -ContractPath $ContractPath)) { $StateById[$state.Id] = $state }
168
+ }
169
+ $items = foreach ($component in $components) {
170
+ $id = [string]$component.id
171
+ $state = $StateById[$id]
172
+ $desired = $id -in $desiredIds
173
+ $notApplicable = $component.platforms -eq 'windows' -and $Context.Platform -ne 'windows'
174
+ $actualState = if ($state) { [string]$state.State } else { 'UNKNOWN' }
175
+ $runtimeOwnershipVerified = $true
176
+ if ($component.type -eq 'runtime' -and $actualState -ne 'NOT INSTALLED') {
177
+ $runtimeOwnershipVerified = $false
178
+ try {
179
+ $markerPath = Join-Path (Get-AfyxComponentRoot -Component $component -Context $Context) ([string]$component.marker_file)
180
+ $markerDocument = Get-Content -Raw -LiteralPath $markerPath -Encoding utf8 | ConvertFrom-Json -ErrorAction Stop
181
+ $marker = $markerDocument.PSObject.Properties[[string]$component.marker_field]
182
+ $runtimeOwnershipVerified = $marker -and [string]$marker.Value -eq [string]$component.marker_value
183
+ } catch { $runtimeOwnershipVerified = $false }
184
+ }
185
+ $drift = if ($notApplicable) { 'NOT_APPLICABLE' }
186
+ elseif (-not $desired) { if ($actualState -eq 'NOT INSTALLED') { 'ABSENT' } else { 'EXTRA' } }
187
+ elseif (-not $runtimeOwnershipVerified) { 'UNVERIFIED' }
188
+ else { switch ($actualState) {
189
+ 'HEALTHY' { 'IN_SYNC' }
190
+ 'NOT INSTALLED' { 'MISSING' }
191
+ 'DRIFTED' { 'MODIFIED' }
192
+ { $_ -in @('INCOMPLETE', 'INVALID') } { 'DEGRADED' }
193
+ default { 'UNVERIFIED' }
194
+ } }
195
+ $ownership = if ($actualState -eq 'UNKNOWN' -or -not $runtimeOwnershipVerified) { 'USER' } elseif ($actualState -eq 'NOT INSTALLED') { 'NONE' } else { [string]$component.ownership_class }
196
+ $repair = switch ($drift) {
197
+ 'MISSING' { 'INSTALL' }
198
+ { $_ -in @('MODIFIED', 'DEGRADED') } { if ($component.ownership_class -eq 'AFYX') { 'REPAIR' } else { 'BLOCKED' } }
199
+ 'UNVERIFIED' { 'BLOCKED' }
200
+ default { 'NONE' }
201
+ }
202
+ [pscustomobject]@{
203
+ Id = $id; Desired = $desired; Ownership = [string]$component.ownership_class
204
+ ActualOwnership = $ownership; ActualState = $actualState; Drift = $drift; Repair = $repair
205
+ }
206
+ }
207
+ $identity = "v$($contract.control_plane_version)|$Preset|$($Provider -join ',')|$($desiredIds -join ',')"
208
+ [pscustomobject]@{
209
+ Version = [int]$contract.control_plane_version
210
+ Identity = $identity
211
+ Preset = $Preset
212
+ Provider = ($Provider -join ',')
213
+ Providers = @($Provider)
214
+ DesiredComponents = @($desiredIds)
215
+ Components = @($items)
216
+ }
217
+ }
218
+
219
+ function Get-AfyxField {
220
+ param($Component, [string]$Name)
221
+ $property = $Component.PSObject.Properties[$Name]
222
+ if ($property -and $null -ne $property.Value) { return [string]$property.Value }
223
+ return ''
224
+ }
225
+
226
+ function Get-AfyxList {
227
+ param([string]$Value)
228
+ if ([string]::IsNullOrEmpty($Value)) { return @() }
229
+ return @($Value -split ';' | Where-Object { $_ })
230
+ }
231
+
232
+ function Get-AfyxComponentRoot {
233
+ [CmdletBinding()]
234
+ param([Parameter(Mandatory)]$Component, [Parameter(Mandatory)]$Context)
235
+ $root = switch (Get-AfyxField $Component 'install_root') {
236
+ 'skills_root' { $Context.SkillsRoot }
237
+ 'afyx_graph_root' { $Context.GraphRoot }
238
+ 'afyx_context_root' { $Context.ContextRoot }
239
+ 'afyx_forge_root' { $Context.ForgeRoot }
240
+ 'codex_tools' { Join-Path $Context.CodexHome 'tools' }
241
+ default { '' }
242
+ }
243
+ if (-not $root) { return '' }
244
+ $relative = Get-AfyxField $Component 'install_path'
245
+ if ($relative) { return Join-Path $root $relative }
246
+ return $root
247
+ }
248
+
249
+ function Test-AfyxSkillManifest {
250
+ [CmdletBinding()]
251
+ param([Parameter(Mandatory)][string]$Directory, [bool]$RequireVersion = $false)
252
+ $manifest = Join-Path $Directory 'SKILL.md'
253
+ if (-not (Test-Path -LiteralPath $manifest -PathType Leaf)) { return @{ Ok = $false; Detail = 'SKILL.md missing' } }
254
+ try { $text = Get-Content -Raw -LiteralPath $manifest -Encoding utf8 } catch { return @{ Ok = $false; Detail = 'not readable as UTF-8' } }
255
+ if ([string]::IsNullOrWhiteSpace($text)) { return @{ Ok = $false; Detail = 'SKILL.md is empty' } }
256
+ if ($text -notmatch '\A---\r?\n[\s\S]*?\r?\n---\r?\n') { return @{ Ok = $false; Detail = 'frontmatter delimiters missing or malformed' } }
257
+ if ($text -notmatch '(?m)^name:\s*[a-z0-9-]+\s*$') { return @{ Ok = $false; Detail = 'valid name missing' } }
258
+ if ($text -notmatch '(?m)^description:\s*\S.+$') { return @{ Ok = $false; Detail = 'description missing' } }
259
+ if ($RequireVersion -and $text -notmatch '(?ms)^metadata:\s*\r?\n\s+version:\s*["''][^"'']+["'']\s*$') { return @{ Ok = $false; Detail = 'metadata.version missing' } }
260
+ return @{ Ok = $true; Detail = 'frontmatter valid' }
261
+ }
262
+
263
+ function Get-AfyxSkillVersion {
264
+ [CmdletBinding()]
265
+ param([Parameter(Mandatory)][string]$Directory)
266
+ $manifest = Join-Path $Directory 'SKILL.md'
267
+ if (-not (Test-Path -LiteralPath $manifest -PathType Leaf)) { return $null }
268
+ $text = Get-Content -Raw -LiteralPath $manifest -Encoding utf8
269
+ $match = [regex]::Match($text, '(?m)^[ \t]*version:[ \t]*["'']?([^"''\s]+)')
270
+ if ($match.Success) { return $match.Groups[1].Value }
271
+ return $null
272
+ }
273
+
274
+ function New-AfyxState {
275
+ param($Component, [string]$State, [string]$Detail, [string]$Version = '', [string]$Path = '')
276
+ [pscustomobject]@{
277
+ Id = Get-AfyxField $Component 'id'
278
+ Name = Get-AfyxField $Component 'name'
279
+ Type = Get-AfyxField $Component 'type'
280
+ Tier = Get-AfyxField $Component 'tier'
281
+ Ownership = Get-AfyxField $Component 'ownership'
282
+ State = $State
283
+ Detail = $Detail
284
+ Version = $Version
285
+ Path = $Path
286
+ }
287
+ }
288
+
289
+ function Test-AfyxRuntimeIntegrity {
290
+ param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$ManifestRelative, [string]$IdentityRelative = '')
291
+ try {
292
+ $rootItem = Get-Item -LiteralPath $Root -Force
293
+ if ($rootItem.Attributes -band [IO.FileAttributes]::ReparsePoint) { return $false }
294
+ $manifest = Join-Path $Root $ManifestRelative
295
+ $metadata = Get-Content -Raw -LiteralPath (Join-Path $Root 'metadata.json') -Encoding utf8 | ConvertFrom-Json -ErrorAction Stop
296
+ if ($IdentityRelative) {
297
+ $identity = Get-Content -Raw -LiteralPath (Join-Path $Root $IdentityRelative) -Encoding utf8 | ConvertFrom-Json -ErrorAction Stop
298
+ foreach ($field in @('product_name','product_version','source_revision','ownership_class','build_provenance','release_channel','integration_default')) {
299
+ if ([string]$metadata.$field -ne [string]$identity.$field) { return $false }
300
+ }
301
+ }
302
+ if ((Get-FileHash -LiteralPath $manifest -Algorithm SHA256).Hash.ToLowerInvariant() -ne [string]$metadata.artifact_digest) { return $false }
303
+ foreach ($line in (Get-Content -LiteralPath $manifest -Encoding utf8)) {
304
+ if ($line -notmatch '^([0-9a-f]{64}) (current/[A-Za-z0-9._/-]+)$' -or $Matches[2] -match '(^|/)\.\.(/|$)') { return $false }
305
+ $file = Join-Path $Root ($Matches[2] -replace '/', [IO.Path]::DirectorySeparatorChar)
306
+ if (-not (Test-Path -LiteralPath $file -PathType Leaf)) { return $false }
307
+ if ((Get-Item -LiteralPath $file -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) { return $false }
308
+ if ((Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLowerInvariant() -ne $Matches[1]) { return $false }
309
+ }
310
+ return $true
311
+ } catch { return $false }
312
+ }
313
+
314
+ function Get-AfyxComponentState {
315
+ [CmdletBinding()]
316
+ param([Parameter(Mandatory)]$Component, [Parameter(Mandatory)]$Context)
317
+
318
+ $type = Get-AfyxField $Component 'type'
319
+ $platforms = Get-AfyxField $Component 'platforms'
320
+
321
+ if ($type -eq 'detected-cli') {
322
+ $command = Get-AfyxField $Component 'detect_command'
323
+ if (Get-Command $command -ErrorAction SilentlyContinue) { return New-AfyxState $Component 'HEALTHY' 'externally managed; detected' }
324
+ return New-AfyxState $Component 'NOT INSTALLED' 'externally managed; not detected'
325
+ }
326
+ if ($platforms -eq 'windows' -and $Context.Platform -ne 'windows') {
327
+ return New-AfyxState $Component 'NOT INSTALLED' 'Windows-only runtime'
328
+ }
329
+
330
+ $path = Get-AfyxComponentRoot -Component $Component -Context $Context
331
+ if (-not $path) { return New-AfyxState $Component 'UNKNOWN' 'component root is not defined' }
332
+
333
+ $required = @(Get-AfyxList (Get-AfyxField $Component 'required_files'))
334
+ $required += @(Get-AfyxList (Get-AfyxField $Component "required_files_$($Context.Platform)"))
335
+
336
+ try {
337
+ switch ($type) {
338
+ 'skill' {
339
+ if (-not (Test-Path -LiteralPath $path)) { return New-AfyxState $Component 'NOT INSTALLED' 'not installed' '' $path }
340
+ $requireVersion = (Get-AfyxField $Component 'version_required') -eq 'true'
341
+ $manifest = Test-AfyxSkillManifest -Directory $path -RequireVersion $requireVersion
342
+ if (-not $manifest.Ok) { return New-AfyxState $Component 'INVALID' $manifest.Detail '' $path }
343
+ foreach ($relative in $required) {
344
+ $file = Join-Path $path $relative
345
+ if (-not (Test-Path -LiteralPath $file -PathType Leaf)) { return New-AfyxState $Component 'INCOMPLETE' "reference missing: $relative" '' $path }
346
+ if ($relative -ne 'SKILL.md' -and [string]::IsNullOrWhiteSpace((Get-Content -Raw -LiteralPath $file -Encoding utf8))) {
347
+ return New-AfyxState $Component 'INCOMPLETE' "reference empty: $relative" '' $path
348
+ }
349
+ }
350
+ return New-AfyxState $Component 'HEALTHY' 'frontmatter and required references valid' (Get-AfyxSkillVersion -Directory $path) $path
351
+ }
352
+ 'runtime' {
353
+ if (-not (Test-Path -LiteralPath $path)) { return New-AfyxState $Component 'NOT INSTALLED' 'not installed' '' $path }
354
+ if ((Get-Item -LiteralPath $path -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) { return New-AfyxState $Component 'UNKNOWN' 'runtime root is a reparse point' '' $path }
355
+ foreach ($relative in $required) {
356
+ if (-not (Test-Path -LiteralPath (Join-Path $path $relative) -PathType Leaf)) { return New-AfyxState $Component 'INCOMPLETE' "missing: $relative" '' $path }
357
+ }
358
+ $markerFile = Join-Path $path (Get-AfyxField $Component 'marker_file')
359
+ try { $document = Get-Content -Raw -LiteralPath $markerFile -Encoding utf8 | ConvertFrom-Json -ErrorAction Stop }
360
+ catch { return New-AfyxState $Component 'INVALID' 'ownership metadata is not valid JSON' '' $path }
361
+ $field = Get-AfyxField $Component 'marker_field'
362
+ $marker = $document.PSObject.Properties[$field]
363
+ if (-not $marker -or [string]$marker.Value -ne (Get-AfyxField $Component 'marker_value')) {
364
+ return New-AfyxState $Component 'INVALID' 'ownership marker mismatch' '' $path
365
+ }
366
+ $versionField = (Get-AfyxField $Component 'version_source') -replace '^[^#]*#', ''
367
+ $version = $document.PSObject.Properties[$versionField]
368
+ if ((Get-AfyxField $Component 'version_required') -eq 'true' -and (-not $version -or -not $version.Value)) {
369
+ return New-AfyxState $Component 'INVALID' "$versionField missing from metadata" '' $path
370
+ }
371
+ $versionText = if ($version) { [string]$version.Value } else { '' }
372
+ $integrityManifest = Get-AfyxField $Component 'integrity_manifest_file'
373
+ if ($integrityManifest -and -not (Test-AfyxRuntimeIntegrity -Root $path -ManifestRelative $integrityManifest -IdentityRelative (Get-AfyxField $Component 'identity_file'))) {
374
+ return New-AfyxState $Component 'DRIFTED' 'Afyx ownership verified but runtime integrity differs' $versionText $path
375
+ }
376
+ return New-AfyxState $Component 'HEALTHY' 'Afyx-owned runtime valid' $versionText $path
377
+ }
378
+ 'toolset' {
379
+ $present = @($required | Where-Object { Test-Path -LiteralPath (Join-Path $path $_) -PathType Leaf })
380
+ if ($present.Count -eq 0) { return New-AfyxState $Component 'NOT INSTALLED' 'not installed' '' $path }
381
+ if ($present.Count -eq $required.Count) { return New-AfyxState $Component 'HEALTHY' 'runtime files installed' '' $path }
382
+ return New-AfyxState $Component 'INCOMPLETE' "$($present.Count) of $($required.Count) runtime files present" '' $path
383
+ }
384
+ default { return New-AfyxState $Component 'UNKNOWN' "unsupported component type: $type" '' $path }
385
+ }
386
+ }
387
+ catch [System.UnauthorizedAccessException] { return New-AfyxState $Component 'UNKNOWN' 'access denied while inspecting component' '' $path }
388
+ catch { return New-AfyxState $Component 'UNKNOWN' "inspection failed: $($_.Exception.Message)" '' $path }
389
+ }
390
+
391
+ function Get-AfyxComponentStates {
392
+ [CmdletBinding()]
393
+ param([Parameter(Mandatory)]$Context, [string]$ContractPath = $script:ContractPath)
394
+ foreach ($component in (Get-AfyxComponentContract -Path $ContractPath)) {
395
+ Get-AfyxComponentState -Component $component -Context $Context
396
+ }
397
+ }
398
+
399
+ Export-ModuleMember -Function Get-AfyxPlatform, Get-AfyxCodexHost, New-AfyxComponentContext, Get-AfyxComponentContract, Get-AfyxControlPlaneContract, Get-AfyxProviderRegistry, Get-AfyxDesiredComponentIds, Get-AfyxControlPlan, Get-AfyxComponentRoot, Test-AfyxSkillManifest, Get-AfyxSkillVersion, Get-AfyxComponentState, Get-AfyxComponentStates