afyx-engineering-kit 0.1.0-alpha.4 → 0.1.0-alpha.7

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 (35) hide show
  1. package/.afyx-source-revision +1 -1
  2. package/README.md +12 -0
  3. package/afyx-graph/engine/release/RELEASE-MANIFEST.json +3 -3
  4. package/afyx-graph/engine/release/SHA256SUMS +2 -2
  5. package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
  6. package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
  7. package/bin/afyx-engineering-kit.mjs +22 -1
  8. package/install.ps1 +84 -13
  9. package/install.sh +91 -4
  10. package/package.json +2 -1
  11. package/scripts/afyx-install-backend.mjs +46 -0
  12. package/scripts/afyx-install-contract.mjs +139 -0
  13. package/scripts/afyx-midnight-circuit.mjs +328 -0
  14. package/scripts/afyx-npm-installer.mjs +27 -5
  15. package/scripts/install-afyx-forge.ps1 +14 -10
  16. package/scripts/install-afyx-forge.sh +13 -10
  17. package/scripts/install-afyx-graph.ps1 +75 -29
  18. package/scripts/lib/AfyxPlatform.ps1 +133 -0
  19. package/scripts/lib/AfyxPlatform.psm1 +6 -0
  20. package/scripts/package-release-zip.ps1 +124 -0
  21. package/scripts/validate-release-zip-graph.mjs +55 -0
  22. package/verify.ps1 +27 -10
  23. package/verify.sh +10 -2
  24. package/afyx-context/test-fixtures/coordination-worker.mjs +0 -52
  25. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__init__.py +0 -1
  26. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__manifest__.py +0 -4
  27. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/__init__.py +0 -1
  28. package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/sale_order.py +0 -5
  29. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__init__.py +0 -1
  30. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__manifest__.py +0 -10
  31. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/__init__.py +0 -2
  32. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order.py +0 -20
  33. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order_audit.py +0 -11
  34. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/security/ir.model.access.csv +0 -2
  35. package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/views/sale_order_views.xml +0 -14
@@ -94,30 +94,29 @@ json_value() {
94
94
 
95
95
  resolve_source_revision() {
96
96
  if [[ -n "$source_revision" ]]; then
97
+ [[ "$source_revision" =~ ^[0-9a-f]{40}$ ]] || { printf 'Explicit source revision is invalid.\n' >&2; return 1; }
97
98
  printf '%s\n' "$source_revision"
98
99
  return 0
99
100
  fi
100
- if [[ -f "$PACKAGE_ROOT/.afyx-source-revision" ]]; then
101
- tr -d '\r\n' < "$PACKAGE_ROOT/.afyx-source-revision"
102
- printf '\n'
103
- return 0
104
- fi
105
101
  if [[ -e "$PACKAGE_ROOT/.git" ]] && command -v git >/dev/null 2>&1; then
106
102
  local rev
107
103
  rev="$(git -C "$PACKAGE_ROOT" rev-parse HEAD 2>/dev/null || true)"
108
- if [[ -n "$rev" ]]; then
104
+ if [[ "$rev" =~ ^[0-9a-f]{40}$ ]]; then
109
105
  printf '%s\n' "$rev"
110
106
  return 0
111
107
  fi
112
108
  fi
109
+ if [[ -f "$PACKAGE_ROOT/.afyx-source-revision" ]]; then
110
+ local marker
111
+ marker="$(tr -d '\r\n' < "$PACKAGE_ROOT/.afyx-source-revision")"
112
+ [[ "$marker" =~ ^[0-9a-f]{40}$ ]] || { printf 'Packaged source revision marker is invalid.\n' >&2; return 1; }
113
+ printf '%s\n' "$marker"
114
+ return 0
115
+ fi
113
116
  printf '%s\n' 'unknown'
114
117
  }
115
118
 
116
119
  resolve_source_provenance() {
117
- if [[ -f "$PACKAGE_ROOT/.afyx-source-revision" ]]; then
118
- printf '%s\n' 'RELEASE_CANDIDATE_SNAPSHOT'
119
- return 0
120
- fi
121
120
  if [[ -e "$PACKAGE_ROOT/.git" ]] && command -v git >/dev/null 2>&1 && git -C "$PACKAGE_ROOT" rev-parse HEAD >/dev/null 2>&1; then
122
121
  local dirty
123
122
  dirty="$(git -C "$PACKAGE_ROOT" status --porcelain -- afyx-forge 2>/dev/null || true)"
@@ -128,6 +127,10 @@ resolve_source_provenance() {
128
127
  fi
129
128
  return 0
130
129
  fi
130
+ if [[ -f "$PACKAGE_ROOT/.afyx-source-revision" ]]; then
131
+ printf '%s\n' 'RELEASE_CANDIDATE_SNAPSHOT'
132
+ return 0
133
+ fi
131
134
  printf '%s\n' 'LOCAL_SOURCE_UNVERIFIED'
132
135
  }
133
136
 
@@ -21,13 +21,21 @@ $kitRoot = Split-Path -Parent $PSScriptRoot
21
21
  $metadataPath = Join-Path $kitRoot 'afyx-graph\afyx-graph.json'
22
22
  $metadata = Get-Content -Raw -LiteralPath $metadataPath -Encoding utf8 | ConvertFrom-Json
23
23
  $distributionProductPath = Join-Path $kitRoot 'afyx-graph\engine\scripts\distribution-product.json'
24
- $releaseChannel = (Get-Content -Raw -LiteralPath $distributionProductPath -Encoding utf8 | ConvertFrom-Json).releaseChannel
25
- $architecture = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()) {
26
- 'Arm64' { 'arm64' }
27
- 'X64' { 'x64' }
28
- default { throw "Unsupported Windows architecture: $_" }
24
+ $releaseChannel = if (Test-Path -LiteralPath $distributionProductPath -PathType Leaf) {
25
+ (Get-Content -Raw -LiteralPath $distributionProductPath -Encoding utf8 | ConvertFrom-Json).releaseChannel
26
+ } elseif ($metadata.PSObject.Properties['release_channel']) {
27
+ [string]$metadata.release_channel
28
+ } else {
29
+ 'technical-alpha'
30
+ }
31
+ . (Join-Path $PSScriptRoot 'lib\AfyxPlatform.ps1')
32
+ $target = Get-AfyxGraphTarget
33
+ if ($target -ne 'win32-x64') { throw "Afyx Graph prebuilt runtime is unavailable for $target. Minimal and Recommended Kit presets remain available; consumer source compilation is disabled." }
34
+ $architecture = switch ($target) {
35
+ 'win32-x64' { 'x64' }
36
+ 'win32-arm64' { 'arm64' }
37
+ default { throw "Unsupported Windows architecture: $target" }
29
38
  }
30
- $target = "win32-$architecture"
31
39
  if ($target -ne 'win32-x64') { throw "Afyx Graph prebuilt runtime is unavailable for $target. Minimal and Recommended Kit presets remain available; consumer source compilation is disabled." }
32
40
  $assetName = "afyx-graph-$target.zip"
33
41
  $current = Join-Path $RuntimeRoot 'current'
@@ -105,12 +113,11 @@ function Get-SourceRevision {
105
113
  function Get-RequestedRevision {
106
114
  $source = Get-SourceRevision
107
115
  if ($source) { return $source.Commit }
108
- $marker = Join-Path $kitRoot '.afyx-source-revision'
109
- if (Test-Path -LiteralPath $marker -PathType Leaf) {
110
- $revision = (Get-Content -Raw -LiteralPath $marker -Encoding utf8).Trim()
111
- if ($revision -notmatch '^[0-9a-f]{40}$') { throw 'Packaged source revision marker is invalid.' }
112
- return $revision
113
- }
116
+ $marker = Join-Path $kitRoot '.afyx-source-revision'
117
+ if (Test-Path -LiteralPath $marker -PathType Leaf) {
118
+ $revision = (Get-Content -Raw -LiteralPath $marker -Encoding utf8).Trim()
119
+ if ($revision -match '^[0-9a-f]{40}$') { return $revision }
120
+ }
114
121
  return $null
115
122
  }
116
123
 
@@ -290,25 +297,64 @@ function Resolve-Archive {
290
297
  }
291
298
  if (-not $Offline) {
292
299
  $downloadRoot = Join-Path ([System.IO.Path]::GetTempPath()) "afyx-graph-download-$([guid]::NewGuid().ToString('N'))"
293
- try {
294
- New-Item -ItemType Directory -Path $downloadRoot | Out-Null
295
- $download = Join-Path $downloadRoot $assetName
296
- $tag = "afyx-graph-v$($metadata.product_version)"
297
- $repoBase = 'https://github.com/a5zero7/afyx-engineering-kit'
298
- $url = "$repoBase/releases/download/$tag/$assetName"
299
- Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $download
300
- Invoke-WebRequest -UseBasicParsing -Uri "$repoBase/releases/download/$tag/SHA256SUMS" -OutFile (Join-Path $downloadRoot 'SHA256SUMS')
301
- Invoke-WebRequest -UseBasicParsing -Uri "$repoBase/releases/download/$tag/RELEASE-MANIFEST.json" -OutFile (Join-Path $downloadRoot 'RELEASE-MANIFEST.json')
302
- Test-ArchiveChecksum -Path $download
303
- Test-ArchiveBundle -Path $download
304
- $identity = Get-ArchiveIdentity -Path $download -RequestedRevision $requestedRevision
305
- if ($requestedRevision -and $identity.revisionStatus -ne 'MATCH') {
306
- throw "Downloaded release revision is $($identity.sourceRevision), requested checkout is $requestedRevision."
300
+ $candidateTags = @()
301
+ if ($requestedRevision) {
302
+ $shortSha = if ($requestedRevision.Length -ge 12) { $requestedRevision.Substring(0, 12) } else { $requestedRevision }
303
+ $candidateTags += "afyx-dev-$requestedRevision"
304
+ $candidateTags += "dev-$requestedRevision"
305
+ $candidateTags += "afyx-dev-$shortSha"
306
+ $candidateTags += "dev-$shortSha"
307
+ }
308
+ $candidateTags += "afyx-graph-v$($metadata.product_version)"
309
+ $candidateTags += "v$($metadata.product_version)"
310
+ $candidateTags += "afyx-dev-snapshot"
311
+
312
+ $repoBase = 'https://github.com/a5zero7/afyx-engineering-kit'
313
+ $downloadedArchive = $null
314
+ $lastDownloadErr = $null
315
+
316
+ foreach ($tag in $candidateTags) {
317
+ try {
318
+ if (Test-Path -LiteralPath $downloadRoot) { Remove-Item -LiteralPath $downloadRoot -Recurse -Force }
319
+ New-Item -ItemType Directory -Path $downloadRoot | Out-Null
320
+ $download = Join-Path $downloadRoot $assetName
321
+ $sumsFile = Join-Path $downloadRoot 'SHA256SUMS'
322
+ $manifestFile = Join-Path $downloadRoot 'RELEASE-MANIFEST.json'
323
+
324
+ Invoke-WebRequest -UseBasicParsing -Uri "$repoBase/releases/download/$tag/RELEASE-MANIFEST.json" -OutFile $manifestFile -ErrorAction Stop
325
+ $manifestData = Get-Content -Raw -LiteralPath $manifestFile -Encoding utf8 | ConvertFrom-Json
326
+ if ($requestedRevision -and $manifestData.source_revision -ne $requestedRevision) {
327
+ continue
328
+ }
329
+
330
+ Invoke-WebRequest -UseBasicParsing -Uri "$repoBase/releases/download/$tag/SHA256SUMS" -OutFile $sumsFile -ErrorAction Stop
331
+ Invoke-WebRequest -UseBasicParsing -Uri "$repoBase/releases/download/$tag/$assetName" -OutFile $download -ErrorAction Stop
332
+
333
+ Test-ArchiveChecksum -Path $download
334
+ Test-ArchiveBundle -Path $download
335
+ $identity = Get-ArchiveIdentity -Path $download -RequestedRevision $requestedRevision
336
+ if ($requestedRevision -and $identity.revisionStatus -ne 'MATCH') {
337
+ continue
338
+ }
339
+ $downloadedArchive = [pscustomobject]@{
340
+ Path = $download
341
+ Source = 'github-release'
342
+ Commit = $identity.sourceRevision
343
+ RevisionStatus = $identity.revisionStatus
344
+ BuildProvenance = 'GITHUB_RELEASE'
345
+ }
346
+ break
347
+ } catch {
348
+ $lastDownloadErr = $_
307
349
  }
308
- return [pscustomobject]@{ Path = $download; Source = 'github-release'; Commit = $identity.sourceRevision; RevisionStatus = $identity.revisionStatus; BuildProvenance = 'GITHUB_RELEASE' }
309
- } catch {
310
- Write-Warning "Verified GitHub release unavailable ($($_.Exception.Message)); trying bounded local build fallback."
311
350
  }
351
+
352
+ if ($downloadedArchive) {
353
+ return $downloadedArchive
354
+ }
355
+
356
+ $diag = if ($lastDownloadErr) { $lastDownloadErr.Exception.Message } else { 'No matching release tag found' }
357
+ Write-Warning "Verified GitHub release unavailable ($diag); trying bounded local build fallback."
312
358
  } else { Write-Host 'Offline mode: skipping GitHub release lookup.' }
313
359
  return Build-LocalArchive
314
360
  }
@@ -0,0 +1,133 @@
1
+ # AfyxPlatform.ps1 — Shared Windows and cross-platform architecture detection helper
2
+ # Compatible with Windows PowerShell 5.1, PowerShell 7+, and Set-StrictMode -Version Latest.
3
+
4
+ Set-StrictMode -Version Latest
5
+
6
+ function Get-AfyxOperatingSystemArchitecture {
7
+ <#
8
+ .SYNOPSIS
9
+ Detects the physical/host Windows OS architecture safely without failing on missing .NET APIs.
10
+ .OUTPUTS
11
+ [string] 'x64', 'arm64', 'x86', or 'unknown'
12
+ #>
13
+ [CmdletBinding()]
14
+ param()
15
+
16
+ # 1. Safely inspect RuntimeInformation via reflection to avoid PropertyNotFoundStrict in PS 5.1
17
+ try {
18
+ $rtType = [Type]::GetType('System.Runtime.InteropServices.RuntimeInformation, System.Runtime.InteropServices.RuntimeInformation', $false)
19
+ if (-not $rtType) {
20
+ $rtType = [Type]::GetType('System.Runtime.InteropServices.RuntimeInformation', $false)
21
+ }
22
+ if ($rtType) {
23
+ $prop = $rtType.GetProperty('OSArchitecture')
24
+ if ($prop) {
25
+ $val = $prop.GetValue($null, $null)
26
+ if ($val) {
27
+ $strVal = $val.ToString().ToUpperInvariant()
28
+ switch ($strVal) {
29
+ 'X64' { return 'x64' }
30
+ 'ARM64' { return 'arm64' }
31
+ 'X86' { return 'x86' }
32
+ 'ARM' { return 'arm' }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ } catch {
38
+ # Fall through to environment inspection
39
+ }
40
+
41
+ # 2. Check PROCESSOR_ARCHITEW6432 (set when a 32-bit process runs on 64-bit OS) then PROCESSOR_ARCHITECTURE
42
+ $archCandidate = $env:PROCESSOR_ARCHITEW6432
43
+ if (-not $archCandidate) {
44
+ $archCandidate = $env:PROCESSOR_ARCHITECTURE
45
+ }
46
+ if ($archCandidate) {
47
+ $norm = $archCandidate.Trim().ToUpperInvariant()
48
+ switch ($norm) {
49
+ 'AMD64' { return 'x64' }
50
+ 'ARM64' { return 'arm64' }
51
+ 'X86' {
52
+ try {
53
+ if ([System.Environment]::Is64BitOperatingSystem) { return 'x64' }
54
+ } catch { }
55
+ return 'x86'
56
+ }
57
+ }
58
+ }
59
+
60
+ # 3. Fallback via CIM / WMI
61
+ try {
62
+ $cs = Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue
63
+ if ($cs -and $cs.OSArchitecture) {
64
+ $desc = $cs.OSArchitecture.ToString()
65
+ if ($desc -match 'ARM') { return 'arm64' }
66
+ if ($desc -match '64') { return 'x64' }
67
+ if ($desc -match '32') { return 'x86' }
68
+ }
69
+ } catch { }
70
+
71
+ try {
72
+ if ([System.Environment]::Is64BitOperatingSystem) { return 'x64' }
73
+ } catch { }
74
+
75
+ return 'unknown'
76
+ }
77
+
78
+ function Get-AfyxPlatformDescription {
79
+ <#
80
+ .SYNOPSIS
81
+ Returns a formatted OS and architecture description string (e.g. 'Microsoft Windows 11 / X64').
82
+ #>
83
+ [CmdletBinding()]
84
+ param()
85
+
86
+ $osDesc = $null
87
+ try {
88
+ $rtType = [Type]::GetType('System.Runtime.InteropServices.RuntimeInformation, System.Runtime.InteropServices.RuntimeInformation', $false)
89
+ if (-not $rtType) {
90
+ $rtType = [Type]::GetType('System.Runtime.InteropServices.RuntimeInformation', $false)
91
+ }
92
+ if ($rtType) {
93
+ $prop = $rtType.GetProperty('OSDescription')
94
+ if ($prop) {
95
+ $val = $prop.GetValue($null, $null)
96
+ if ($val) { $osDesc = [string]$val }
97
+ }
98
+ }
99
+ } catch { }
100
+
101
+ if (-not $osDesc) {
102
+ try {
103
+ $cs = Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue
104
+ if ($cs -and $cs.Caption) {
105
+ $osDesc = "$($cs.Caption) $($cs.Version)"
106
+ }
107
+ } catch { }
108
+ }
109
+
110
+ if (-not $osDesc) {
111
+ $osDesc = [System.Environment]::OSVersion.VersionString
112
+ }
113
+
114
+ $arch = (Get-AfyxOperatingSystemArchitecture).ToUpperInvariant()
115
+ return "$osDesc / $arch"
116
+ }
117
+
118
+ function Get-AfyxGraphTarget {
119
+ <#
120
+ .SYNOPSIS
121
+ Maps the detected OS architecture to the canonical Afyx Graph target string.
122
+ #>
123
+ [CmdletBinding()]
124
+ param()
125
+
126
+ $arch = Get-AfyxOperatingSystemArchitecture
127
+ switch ($arch) {
128
+ 'x64' { return 'win32-x64' }
129
+ 'arm64' { return 'win32-arm64' }
130
+ 'x86' { return 'win32-x86' }
131
+ default { return "win32-$arch" }
132
+ }
133
+ }
@@ -0,0 +1,6 @@
1
+ # AfyxPlatform.psm1 — Shared Windows and cross-platform architecture detection module
2
+ # Compatible with Windows PowerShell 5.1, PowerShell 7+, and Set-StrictMode -Version Latest.
3
+
4
+ . (Join-Path $PSScriptRoot 'AfyxPlatform.ps1')
5
+
6
+ Export-ModuleMember -Function Get-AfyxOperatingSystemArchitecture, Get-AfyxPlatformDescription, Get-AfyxGraphTarget
@@ -0,0 +1,124 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [string]$OutputDir = (Join-Path $PSScriptRoot '..\testing\integration\release-zip'),
4
+ [string]$Revision = '',
5
+ [string]$GraphReleaseDir = '',
6
+ [switch]$BuildGraphFromSource
7
+ )
8
+
9
+ Set-StrictMode -Version Latest
10
+ $ErrorActionPreference = 'Stop'
11
+ $kitRoot = Split-Path -Parent $PSScriptRoot
12
+ $validator = Join-Path $PSScriptRoot 'validate-release-zip-graph.mjs'
13
+ $stageDir = $null
14
+
15
+ function Invoke-Required([string]$Program, [string[]]$Arguments) {
16
+ $global:LASTEXITCODE = 0
17
+ $output = & $Program @Arguments 2>&1
18
+ if ($LASTEXITCODE -ne 0) { throw "$Program failed ($LASTEXITCODE): $($output -join ' ')" }
19
+ return $output
20
+ }
21
+
22
+ if (-not $Revision) { $Revision = (Invoke-Required 'git' @('-C', $kitRoot, 'rev-parse', 'HEAD') | Select-Object -Last 1).Trim() }
23
+ if ($Revision -cnotmatch '^[0-9a-f]{40}$') { throw 'Revision must be an exact 40-character Git commit SHA.' }
24
+ $resolved = (Invoke-Required 'git' @('-C', $kitRoot, 'rev-parse', '--verify', "$Revision^{commit}") | Select-Object -Last 1).Trim()
25
+ if ($resolved -cne $Revision) { throw 'Revision does not identify the selected Git commit.' }
26
+ $head = (Invoke-Required 'git' @('-C', $kitRoot, 'rev-parse', 'HEAD') | Select-Object -Last 1).Trim()
27
+ if ($head -cne $Revision) { throw 'Package only the current HEAD; switch to the selected immutable commit first.' }
28
+ if (Invoke-Required 'git' @('-C', $kitRoot, 'status', '--porcelain')) { throw 'Source checkout is dirty; commit or use a clean worktree before packaging.' }
29
+
30
+ if (-not $GraphReleaseDir) { $GraphReleaseDir = Join-Path $kitRoot 'afyx-graph\engine\release' }
31
+ if ($BuildGraphFromSource) {
32
+ Invoke-Required 'node' @($validator, 'build', '--root', $kitRoot, '--revision', $Revision) | Out-Null
33
+ }
34
+ Invoke-Required 'node' @($validator, 'verify', '--release', $GraphReleaseDir, '--revision', $Revision, '--root', $kitRoot) | Out-Null
35
+
36
+ $stageDir = Join-Path ([IO.Path]::GetTempPath()) ("afyx-zip-stage-" + [guid]::NewGuid().ToString('N'))
37
+ try {
38
+ $sourceDir = Join-Path $stageDir 'source'
39
+ $kitStage = Join-Path $stageDir 'afyx-engineering-kit'
40
+ [IO.Directory]::CreateDirectory($sourceDir) | Out-Null
41
+ [IO.Directory]::CreateDirectory($kitStage) | Out-Null
42
+ $sourceTar = Join-Path $stageDir 'source.tar'
43
+ Invoke-Required 'git' @('-C', $kitRoot, 'archive', '--format=tar', "--output=$sourceTar", $Revision) | Out-Null
44
+ Invoke-Required 'tar' @('-xf', $sourceTar, '-C', $sourceDir) | Out-Null
45
+
46
+ $items = @('bin', 'scripts', 'skills', 'afyx-context', 'afyx-forge', 'tools',
47
+ 'install.ps1', 'install.sh', 'verify.ps1', 'verify.sh', 'update.ps1', 'update.sh',
48
+ 'uninstall.ps1', 'uninstall.sh', 'package.json', 'LICENSE', 'README.md', 'SECURITY.md')
49
+ foreach ($item in $items) {
50
+ $from = Join-Path $sourceDir $item
51
+ if (-not (Test-Path -LiteralPath $from)) { throw "Committed source is missing required package item: $item" }
52
+ Copy-Item -LiteralPath $from -Destination (Join-Path $kitStage $item) -Recurse -Force
53
+ }
54
+ $stageRoot = [IO.Path]::GetFullPath($kitStage).TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar
55
+ foreach ($relative in @('scripts\tests', 'afyx-context\test', 'afyx-context\test-fixtures', 'afyx-context\benchmark',
56
+ 'afyx-forge\test', 'tools\codex-usage\tests')) {
57
+ $target = [IO.Path]::GetFullPath((Join-Path $kitStage $relative))
58
+ if (-not $target.StartsWith($stageRoot, [StringComparison]::OrdinalIgnoreCase)) { throw 'Unsafe staging path' }
59
+ if (Test-Path -LiteralPath $target) { Remove-Item -LiteralPath $target -Recurse -Force }
60
+ }
61
+ $graphStage = Join-Path $kitStage 'afyx-graph'
62
+ [IO.Directory]::CreateDirectory($graphStage) | Out-Null
63
+ Copy-Item -LiteralPath (Join-Path $sourceDir 'afyx-graph\afyx-graph.json') -Destination $graphStage
64
+ $engineStage = Join-Path $graphStage 'engine'
65
+ [IO.Directory]::CreateDirectory($engineStage) | Out-Null
66
+ $engineScripts = Join-Path $engineStage 'scripts'
67
+ [IO.Directory]::CreateDirectory($engineScripts) | Out-Null
68
+ foreach ($name in @('distribution-contract.mjs', 'distribution-product.json')) {
69
+ Copy-Item -LiteralPath (Join-Path $sourceDir "afyx-graph\engine\scripts\$name") -Destination $engineScripts
70
+ }
71
+ $releaseStage = Join-Path $engineStage 'release'
72
+ [IO.Directory]::CreateDirectory($releaseStage) | Out-Null
73
+ foreach ($name in @('afyx-graph-win32-x64.zip', 'RELEASE-MANIFEST.json', 'SHA256SUMS')) {
74
+ Copy-Item -LiteralPath (Join-Path $GraphReleaseDir $name) -Destination $releaseStage
75
+ }
76
+ [IO.File]::WriteAllText((Join-Path $kitStage '.afyx-source-revision'), "$Revision`n", [Text.UTF8Encoding]::new($false))
77
+
78
+ $version = (Get-Content -Raw -LiteralPath (Join-Path $sourceDir 'package.json') | ConvertFrom-Json).version
79
+ $name = "afyx-engineering-kit-v$version-windows-x64.zip"
80
+ $tempZip = Join-Path $stageDir $name
81
+ $timestamp = [datetime]::SpecifyKind([datetime]'2020-01-01', [DateTimeKind]::Utc)
82
+ Get-ChildItem -LiteralPath $kitStage -Recurse -Force | ForEach-Object { $_.LastWriteTimeUtc = $timestamp }
83
+ (Get-Item -LiteralPath $kitStage).LastWriteTimeUtc = $timestamp
84
+ Add-Type -AssemblyName System.IO.Compression
85
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
86
+ $writer = [IO.Compression.ZipFile]::Open($tempZip, [IO.Compression.ZipArchiveMode]::Create)
87
+ try {
88
+ foreach ($file in (Get-ChildItem -LiteralPath $kitStage -Recurse -Force -File | Sort-Object FullName)) {
89
+ $relative = $file.FullName.Substring($kitStage.Length).TrimStart([char[]]@('\', '/')).Replace('\', '/')
90
+ $entryName = "afyx-engineering-kit/$relative"
91
+ [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($writer, $file.FullName, $entryName, [IO.Compression.CompressionLevel]::Optimal) | Out-Null
92
+ }
93
+ } finally { $writer.Dispose() }
94
+ $zip = [IO.Compression.ZipFile]::OpenRead($tempZip)
95
+ try {
96
+ $required = @("afyx-engineering-kit/.afyx-source-revision", "afyx-engineering-kit/install.ps1",
97
+ "afyx-engineering-kit/verify.ps1", "afyx-engineering-kit/afyx-graph/engine/release/afyx-graph-win32-x64.zip")
98
+ foreach ($entryName in $required) {
99
+ if (-not $zip.GetEntry($entryName)) { throw "Release ZIP is missing $entryName" }
100
+ }
101
+ foreach ($forbidden in @('scripts/tests/', 'afyx-context/test/', 'afyx-context/test-fixtures/', 'afyx-context/benchmark/',
102
+ 'afyx-forge/test/', 'tools/codex-usage/tests/', 'afyx-graph/engine/scripts/tests/')) {
103
+ if ($zip.Entries.FullName | Where-Object { $_.StartsWith("afyx-engineering-kit/$forbidden", [StringComparison]::OrdinalIgnoreCase) }) {
104
+ throw "Development fixture leaked into release ZIP: $forbidden"
105
+ }
106
+ }
107
+ $reader = [IO.StreamReader]::new($zip.GetEntry($required[0]).Open())
108
+ try { if ($reader.ReadToEnd().Trim() -cne $Revision) { throw 'Packed revision marker mismatch' } }
109
+ finally { $reader.Dispose() }
110
+ } finally { $zip.Dispose() }
111
+
112
+ [IO.Directory]::CreateDirectory([IO.Path]::GetFullPath($OutputDir)) | Out-Null
113
+ $destination = Join-Path ([IO.Path]::GetFullPath($OutputDir)) $name
114
+ $digest = (Get-FileHash -Algorithm SHA256 -LiteralPath $tempZip).Hash.ToLowerInvariant()
115
+ if (Test-Path -LiteralPath $destination) {
116
+ $existing = (Get-FileHash -Algorithm SHA256 -LiteralPath $destination).Hash.ToLowerInvariant()
117
+ if ($existing -ne $digest) { throw "Destination already exists with different bytes: $destination" }
118
+ } else { Move-Item -LiteralPath $tempZip -Destination $destination }
119
+ [pscustomobject]@{ Path = $destination; Version = $version; Revision = $Revision; Sha256 = $digest }
120
+ } finally {
121
+ if ($stageDir -and (Test-Path -LiteralPath $stageDir)) {
122
+ Remove-Item -LiteralPath $stageDir -Recurse -Force
123
+ }
124
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import { execFileSync } from 'node:child_process';
3
+ import { createHash } from 'node:crypto';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { basename, join, resolve } from 'node:path';
6
+ import { buildGraphReleaseArtifacts } from './prepare-g6-package.mjs';
7
+ import { verifyGraphArchivePaths } from './verify-graph-archive.mjs';
8
+
9
+ const [mode, ...args] = process.argv.slice(2);
10
+ function arg(name) { const index = args.indexOf(name); return index < 0 ? '' : args[index + 1]; }
11
+ const root = resolve(arg('--root') || '.');
12
+ const revision = arg('--revision');
13
+ if (!/^[0-9a-f]{40}$/.test(revision)) throw new Error('Exact source commit SHA required');
14
+ if (mode === 'build') {
15
+ buildGraphReleaseArtifacts(root, revision);
16
+ process.stdout.write('Graph artifacts built from selected commit\n');
17
+ } else if (mode === 'verify') {
18
+ const release = resolve(arg('--release'));
19
+ const archiveName = 'afyx-graph-win32-x64.zip';
20
+ const archive = join(release, archiveName);
21
+ const manifest = JSON.parse(readFileSync(join(release, 'RELEASE-MANIFEST.json'), 'utf8'));
22
+ const graphVersion = JSON.parse(readFileSync(join(root, 'afyx-graph', 'engine', 'package.json'), 'utf8')).version;
23
+ if (manifest.schema !== 1 || manifest.product !== 'Afyx Graph' ||
24
+ manifest.source_revision !== revision || manifest.product_version !== graphVersion ||
25
+ !Array.isArray(manifest.artifacts)) throw new Error('Graph manifest source/product mismatch');
26
+ const matches = manifest.artifacts.filter((item) => item.file === archiveName);
27
+ if (matches.length !== 1 || matches[0].target !== 'win32-x64' || !/^[0-9a-f]{64}$/.test(matches[0].sha256)) {
28
+ throw new Error('Missing or invalid Windows x64 Graph manifest entry');
29
+ }
30
+ const lines = readFileSync(join(release, 'SHA256SUMS'), 'utf8').trim().split(/\r?\n/);
31
+ const sums = lines.map((line) => /^([0-9a-f]{64}) (afyx-graph-(?:win32|linux)-x64\.(?:zip|tar\.gz))$/.exec(line));
32
+ if (sums.some((match) => !match) || sums.filter((match) => match[2] === archiveName).length !== 1) {
33
+ throw new Error('Missing, duplicate, or malformed Windows Graph SHA256SUMS entry');
34
+ }
35
+ const bytes = readFileSync(archive);
36
+ const digest = createHash('sha256').update(bytes).digest('hex');
37
+ if (digest !== matches[0].sha256 || digest !== sums.find((match) => match[2] === archiveName)[1]) {
38
+ throw new Error('Graph archive checksum mismatch');
39
+ }
40
+ verifyGraphArchivePaths(bytes, archiveName);
41
+ const names = execFileSync('tar', ['-tf', archive], { encoding: 'utf8' }).trim().split(/\r?\n/);
42
+ const prefix = basename(archive, '.zip');
43
+ for (const required of [`${prefix}/metadata.json`, `${prefix}/bin/afyx-graph.cmd`,
44
+ `${prefix}/lib/dist/bin/afyx-graph.js`, `${prefix}/lib/dist/viewer/index.html`]) {
45
+ if (!names.includes(required)) throw new Error(`Incomplete Graph archive: ${required}`);
46
+ }
47
+ const metadata = JSON.parse(execFileSync('tar', ['-xOf', archive, `${prefix}/metadata.json`], { encoding: 'utf8' }));
48
+ if (metadata.artifact_target !== 'win32-x64' || metadata.source_revision !== revision ||
49
+ metadata.build_identity !== `git:${revision}` || metadata.product_version !== graphVersion) {
50
+ throw new Error('Embedded Graph metadata source/target mismatch');
51
+ }
52
+ process.stdout.write(JSON.stringify({ revision, digest, target: metadata.artifact_target, entries: names.length }) + '\n');
53
+ } else {
54
+ throw new Error('Usage: validate-release-zip-graph.mjs build|verify --root PATH --revision SHA [--release PATH]');
55
+ }
package/verify.ps1 CHANGED
@@ -11,21 +11,28 @@ param(
11
11
  [string]$ClaudeConfigDir = $(if ($env:CLAUDE_CONFIG_DIR) { $env:CLAUDE_CONFIG_DIR } else { '' }),
12
12
  [string]$ContextRuntimeRoot = $(if ($env:AFYX_CONTEXT_RUNTIME_ROOT) { $env:AFYX_CONTEXT_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\context' }),
13
13
  [string]$ForgeRuntimeRoot = $(if ($env:AFYX_FORGE_RUNTIME_ROOT) { $env:AFYX_FORGE_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\forge' }),
14
+ [string]$GraphRuntimeRoot = $(if ($env:AFYX_GRAPH_RUNTIME_ROOT) { $env:AFYX_GRAPH_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\graph' }),
14
15
  [string]$AfyxInstallRoot = $(if ($env:AFYX_INSTALL_ROOT) { $env:AFYX_INSTALL_ROOT } else { Join-Path $env:USERPROFILE '.afyx' }),
15
- [string]$HostBridgeRuntimeRoot = $(if ($env:AFYX_HOST_BRIDGE_RUNTIME_ROOT) { $env:AFYX_HOST_BRIDGE_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\host-bridge' })
16
+ [string]$HostBridgeRuntimeRoot = $(if ($env:AFYX_HOST_BRIDGE_RUNTIME_ROOT) { $env:AFYX_HOST_BRIDGE_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\host-bridge' }),
17
+ [switch]$SkipProviderConfiguration,
18
+ [switch]$ReportJson
16
19
  )
17
20
 
18
21
  Set-StrictMode -Version Latest
19
22
  $ErrorActionPreference = 'Stop'
20
23
  $coreFailure = $false
21
24
  $configuredProviders = @()
25
+ $claudeCommand = Get-Command claude -ErrorAction SilentlyContinue
22
26
  $codexHome = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $env:USERPROFILE '.codex' }
23
27
  $configPath = Join-Path $codexHome 'config.toml'
24
- $graphRoot = if ($env:AFYX_GRAPH_RUNTIME_ROOT) { $env:AFYX_GRAPH_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\graph' }
28
+ $graphRoot = if ($GraphRuntimeRoot) { $GraphRuntimeRoot } elseif ($env:AFYX_GRAPH_RUNTIME_ROOT) { $env:AFYX_GRAPH_RUNTIME_ROOT } else { Join-Path $env:USERPROFILE '.afyx\graph' }
25
29
  Import-Module (Join-Path $PSScriptRoot 'scripts\lib\AfyxTerminal.psm1') -Force
30
+ Import-Module (Join-Path $PSScriptRoot 'scripts\lib\AfyxPlatform.psm1') -Force
26
31
  $terminal = New-AfyxTerminalContext
27
32
 
33
+ $verificationRows = [Collections.Generic.List[object]]::new()
28
34
  function Write-Result([string]$State, [string]$Name, [string]$Detail = '') {
35
+ $verificationRows.Add([ordered]@{ state = $State; name = $Name; detail = $Detail })
29
36
  $status = switch ($State) {
30
37
  'OK' { 'HEALTHY' }
31
38
  'FAIL' { 'BLOCKED' }
@@ -39,6 +46,7 @@ function Write-Result([string]$State, [string]$Name, [string]$Detail = '') {
39
46
  Import-Module (Join-Path $PSScriptRoot 'scripts\lib\AfyxComponents.psm1') -Force
40
47
  Import-Module (Join-Path $PSScriptRoot 'scripts\lib\AfyxSkillLifecycle.psm1') -Force -DisableNameChecking
41
48
  $providerIds = @(Get-AfyxProviderRegistry | ForEach-Object { [string]$_.provider })
49
+ $Provider = @($Provider | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ } | Select-Object -Unique)
42
50
  $unknownProviders = @($Provider | Where-Object { $_ -notin $providerIds })
43
51
  if ($unknownProviders.Count) { throw "Unknown provider(s): $($unknownProviders -join ', ')" }
44
52
  $providerSkillRoots = @()
@@ -96,7 +104,7 @@ if ($gitSource -and (Test-Path -LiteralPath (Join-Path $PSScriptRoot '.git'))) {
96
104
  foreach ($providerRecord in (Get-AfyxProviderRegistry)) {
97
105
  Write-Result 'INFO' "Provider adapter: $($providerRecord.name)" "primary=$($providerRecord.primary); ownership=$($providerRecord.ownership_class); capabilities=$($providerRecord.capabilities); policy=$($providerRecord.configuration_policy)"
98
106
  }
99
- if ($Provider.Count) {
107
+ if ($Provider.Count -and -not $SkipProviderConfiguration) {
100
108
  $nodeCommand = Get-Command node -ErrorAction SilentlyContinue
101
109
  $entry = Join-Path $graphRoot 'current\lib\dist\bin\afyx-graph.js'
102
110
  if ($nodeCommand -and (Test-Path -LiteralPath $entry -PathType Leaf)) {
@@ -106,7 +114,6 @@ if ($Provider.Count) {
106
114
  '--node', $nodeCommand.Source, '--entry', $entry)
107
115
  $codexHost = Get-AfyxCodexHost
108
116
  $codexCommand = if ($codexHost.State -eq 'CLI_READY') { [pscustomobject]@{ Source = $codexHost.Path } } else { $null }
109
- $claudeCommand = Get-Command claude -ErrorAction SilentlyContinue
110
117
  if ($codexCommand) { $providerArguments += @('--codex', $codexCommand.Source) }
111
118
  if ($claudeCommand) { $providerArguments += @('--claude', $claudeCommand.Source) }
112
119
  if ($ClaudeConfigDir) { $providerArguments += @('--claude-config-dir', $ClaudeConfigDir) }
@@ -169,7 +176,7 @@ if ($controlPlan -and $Provider.Count) {
169
176
  $git = Get-Command git -ErrorAction SilentlyContinue
170
177
  $node = Get-Command node -ErrorAction SilentlyContinue
171
178
  $npm = Get-Command npm -ErrorAction SilentlyContinue
172
- Write-Result 'OK' 'OS/architecture [REQUIRED]' "$([System.Runtime.InteropServices.RuntimeInformation]::OSDescription) / $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)"
179
+ Write-Result 'OK' 'OS/architecture [REQUIRED]' (Get-AfyxPlatformDescription)
173
180
  Write-Result 'OK' 'Platform shell [REQUIRED]' "PowerShell $($PSVersionTable.PSVersion)"
174
181
  if ($git) { Write-Result 'OK' 'Git [REQUIRED]' ((& git --version 2>$null) -join ' ') } else { Write-Result 'FAIL' 'Git [REQUIRED]' 'missing; install Git for Windows from https://git-scm.com/'; $coreFailure = $true }
175
182
  if ($node) {
@@ -182,9 +189,9 @@ if ($node) { Write-Result 'OK' 'Node.js [COMPONENT_REQUIRED:Afyx Context]' ((& n
182
189
  else { Write-Result 'INFO' 'Node.js [COMPONENT_REQUIRED:Afyx Context]' 'missing; required only when Afyx Context is selected' }
183
190
  if ($npm) { Write-Result 'OK' 'npm [BUILD_ONLY:Afyx Graph]' ((& npm --version 2>$null) -join ' ') } else { Write-Result 'INFO' 'npm [BUILD_ONLY:Afyx Graph]' 'missing; required only for local artifact fallback' }
184
191
  Write-Result 'OK' 'Archive/checksum [COMPONENT_REQUIRED:Afyx Graph]' 'Expand-Archive and Get-FileHash available'
185
- $codexRequired = 'codex' -in $Provider -or -not $Provider.Count
186
- $antigravityRequired = 'antigravity' -in $Provider
187
- $claudeRequired = 'claude' -in $Provider
192
+ $codexRequired = -not $SkipProviderConfiguration -and ('codex' -in $Provider -or -not $Provider.Count)
193
+ $antigravityRequired = -not $SkipProviderConfiguration -and 'antigravity' -in $Provider
194
+ $claudeRequired = -not $SkipProviderConfiguration -and 'claude' -in $Provider
188
195
 
189
196
  $codexHost = Get-AfyxCodexHost
190
197
  $codex = if ($codexHost.State -eq 'CLI_READY') { [pscustomobject]@{ Source = $codexHost.Path } } else { $null }
@@ -371,7 +378,7 @@ if (-not $usagePresent) {
371
378
  Write-Result 'INFO' 'Codex Usage Hook trust' 'verify with /hooks'
372
379
  }
373
380
 
374
- if ($Provider.Count -and $node) {
381
+ if ($Provider.Count -and $node -and -not $SkipProviderConfiguration) {
375
382
  $workflowProviders = @($Provider | Where-Object { $_ -eq 'antigravity' -or ($_ -eq 'claude' -and $ProviderScope -eq 'workspace') })
376
383
  $bridgeLifecycle = Join-Path $PSScriptRoot 'scripts\afyx-host-bridge-lifecycle.mjs'
377
384
  $bridgeJson = (& $node.Source $bridgeLifecycle '--runtime-root' $HostBridgeRuntimeRoot 2>$null) -join ''
@@ -407,5 +414,15 @@ if ($Provider.Count -and $node) {
407
414
  }
408
415
  }
409
416
 
410
- if ($coreFailure) { Write-Result 'FAIL' 'Core readiness'; exit 1 }
417
+ function Write-VerificationContract {
418
+ if (-not $ReportJson) { return }
419
+ $previousOutputEncoding = $OutputEncoding
420
+ try {
421
+ $OutputEncoding = [Text.UTF8Encoding]::new($false)
422
+ ConvertTo-Json -InputObject @($verificationRows.ToArray()) -Depth 5 -Compress | & node (Join-Path $PSScriptRoot 'scripts\afyx-install-contract.mjs') verification
423
+ if ($LASTEXITCODE -ne 0) { throw 'Unable to serialize backend verification results.' }
424
+ } finally { $OutputEncoding = $previousOutputEncoding }
425
+ }
426
+ if ($coreFailure) { Write-Result 'FAIL' 'Core readiness'; Write-VerificationContract; exit 1 }
411
427
  Write-Result 'OK' 'Core readiness' 'ready; optional enhancement warnings do not affect this result'
428
+ Write-VerificationContract
package/verify.sh CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ report_json=false
4
+ verification_rows=()
3
5
 
4
6
  PACKAGE_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
5
7
 
@@ -29,6 +31,7 @@ while (($#)); do
29
31
  --skills-root) skills_root="$2"; skills_root_explicit=true; shift 2 ;;
30
32
  --context-runtime-root) context_root="$2"; shift 2 ;;
31
33
  --forge-runtime-root) forge_root="$2"; shift 2 ;;
34
+ --report-json) report_json=true; shift ;;
32
35
  --preset) preset="$2"; shift 2 ;;
33
36
  --custom-component) custom_component_list="${custom_component_list:+$custom_component_list;}$2"; shift 2 ;;
34
37
  --provider) provider_list="$2"; provider_explicit=true; shift 2 ;;
@@ -64,6 +67,7 @@ fi
64
67
 
65
68
  result() {
66
69
  local state="$1" label="$2" detail="${3:-}"
70
+ verification_rows+=("$state" "$label" "$detail")
67
71
  [[ -n "$detail" ]] && printf '[%s] %s — %s\n' "$state" "$label" "$detail" || printf '[%s] %s\n' "$state" "$label"
68
72
  }
69
73
 
@@ -138,7 +142,7 @@ if command -v tar >/dev/null 2>&1 && { command -v shasum >/dev/null 2>&1 || comm
138
142
  codex_detected=false
139
143
  if command -v codex >/dev/null 2>&1; then
140
144
  codex_detected=true
141
- if version="$(codex --version 2>/dev/null)"; then result OK 'Codex CLI' "$version"; elif "$provider_explicit" && [[ ",$provider_list," == *,codex,* ]]; then result FAIL 'Codex CLI' 'selected host version command failed'; core_failure=true; else result WARN 'Codex CLI' 'version command failed (not selected)'; fi
145
+ if version="$(codex --version 2>/dev/null)"; then result OK 'Codex CLI' "$version"; elif [[ ",$provider_list," == *,codex,* ]]; then result FAIL 'Codex CLI' 'version command failed'; core_failure=true; else result WARN 'Codex CLI' 'version command failed (not selected)'; fi
142
146
  else result SKIP 'Codex CLI' 'PROVIDER_NOT_INSTALLED'; fi
143
147
  extension_detected=false
144
148
  for extension in "$HOME"/.vscode/extensions/openai.chatgpt-*; do [[ -d "$extension" ]] && { extension_detected=true; break; }; done
@@ -261,5 +265,9 @@ if ! "$codex_detected"; then result SKIP 'Codex config' 'PROVIDER_NOT_INSTALLED'
261
265
  elif [[ -f "$config" ]]; then result OK 'Codex config' 'read-only check completed'
262
266
  else result WARN 'Codex config' 'not found; optional MCP entries unavailable'; fi
263
267
 
264
- if "$core_failure"; then result FAIL 'Core readiness'; exit 1; fi
268
+ emit_verification_contract() {
269
+ if "$report_json"; then node "$PACKAGE_ROOT/scripts/afyx-install-contract.mjs" verification-rows "${verification_rows[@]}"; fi
270
+ }
271
+ if "$core_failure"; then result FAIL 'Core readiness'; emit_verification_contract; exit 1; fi
265
272
  result OK 'Core readiness' 'ready; optional enhancement warnings do not affect this result'
273
+ emit_verification_contract