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,240 @@
1
+ #!/usr/bin/env python3
2
+ """Offline, zero-provider alpha/v1 evidence preflight (never grants release approval).
3
+
4
+ Checks the structure and internal consistency of *claims*, not the truth of external
5
+ artifacts or evaluator conclusions. Raw workspaces, prompts and private telemetry
6
+ are neither scanned nor included in the public output.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import re
13
+ import stat
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ SHA40 = re.compile(r"^[0-9a-f]{40}$")
18
+ SHA256 = re.compile(r"^[0-9a-f]{64}$")
19
+ REASON = re.compile(r"^[A-Z][A-Z0-9_]{2,79}$")
20
+ REF = re.compile(
21
+ r"^(?:urn:afyx:evidence:[0-9a-f]{64}|"
22
+ r"https://github\.com/a5zero7/(?:afyx-engineering-kit|afyx-codex-engineering-kit)/actions/runs/[0-9]+)$"
23
+ )
24
+ STATUSES = frozenset(("PASS", "FAIL", "NOT_RUN", "BLOCKED"))
25
+ # Order is dependency order. Every gate is release-blocking in the expanded v1
26
+ # contract. An Alpha pilot can proceed only through its separately authorized gate.
27
+ GATES = {
28
+ "GRAPH_STANDALONE": ("owner", ()),
29
+ "CONTEXT_STANDALONE": ("owner", ()),
30
+ "FORGE_STANDALONE": ("owner", ()),
31
+ "ODOO_STANDALONE": ("owner", ()),
32
+ "EXPERT_STANDALONE": ("owner", ()),
33
+ "GRAPH_ACE_RUNTIME": ("owner", ("GRAPH_STANDALONE", "CONTEXT_STANDALONE")),
34
+ "PROVIDER_THREE_HOST": ("owner", ("GRAPH_STANDALONE",)),
35
+ "INSTALLER_LIFECYCLE": ("owner", ()),
36
+ "EXPERT_D6": ("independent_evaluator", ("EXPERT_STANDALONE", "ODOO_STANDALONE")),
37
+ "FORGE_FORMAL_36": ("independent_evaluator", ("FORGE_STANDALONE",)),
38
+ "FORGE_A8_DECISION": ("independent_evaluator", ("FORGE_FORMAL_36",)),
39
+ "FORGE_A9_A12": ("independent_evaluator", ("FORGE_A8_DECISION",)),
40
+ "PLATFORM_TB7": ("owner", ("PROVIDER_THREE_HOST",)),
41
+ "PHASE8_REAL_DOGFOOD": ("independent_evaluator", ("GRAPH_ACE_RUNTIME", "EXPERT_D6")),
42
+ "PHASE9_HARDENING": ("owner", ("INSTALLER_LIFECYCLE",)),
43
+ "T12_INSTALLED_PRODUCT": ("release_reviewer", (
44
+ "GRAPH_ACE_RUNTIME", "PLATFORM_TB7", "FORGE_A9_A12",
45
+ "PHASE8_REAL_DOGFOOD", "PHASE9_HARDENING", "EXPERT_D6",
46
+ )),
47
+ "PHASE10_PRIVATE_BETA": ("release_reviewer", ("T12_INSTALLED_PRODUCT",)),
48
+ "PHASE11_STABLE": ("release_reviewer", ("PHASE10_PRIVATE_BETA",)),
49
+ }
50
+ SCENARIOS = {
51
+ "KNOWN_SYMBOL_DIRECT": ("known_symbol", "small", "CONTROL_TREATMENT"),
52
+ "ODOO_CROSS_MODULE": ("odoo_multimodule", "large", "CONTROL_TREATMENT"),
53
+ "PYTHON_REGRESSION": ("python", "medium", "CONTROL_TREATMENT"),
54
+ "TYPESCRIPT_MONOREPO": ("typescript_monorepo", "large", "CONTROL_TREATMENT"),
55
+ "ACE_LARGE_REPEAT_RECOVERY": ("context_recovery", "large", "CONTROL_TREATMENT"),
56
+ "PROVIDER_RESTART_ROLLBACK": ("provider_lifecycle", "medium", "OBSERVATIONAL"),
57
+ }
58
+ REQUIRES_INSTALLED_ARTIFACT = frozenset((
59
+ "GRAPH_ACE_RUNTIME", "PROVIDER_THREE_HOST", "INSTALLER_LIFECYCLE",
60
+ "PLATFORM_TB7", "T12_INSTALLED_PRODUCT", "PHASE10_PRIVATE_BETA",
61
+ "PHASE11_STABLE",
62
+ ))
63
+ MAX_LEDGER_BYTES = 1024 * 1024
64
+
65
+
66
+ class LedgerError(ValueError):
67
+ pass
68
+
69
+
70
+ def require(condition: bool, error_code: str) -> None:
71
+ if not condition:
72
+ raise LedgerError(error_code)
73
+
74
+
75
+ def sha40(value: object) -> bool:
76
+ return isinstance(value, str) and SHA40.fullmatch(value) is not None
77
+
78
+
79
+ def sha256(value: object) -> bool:
80
+ return isinstance(value, str) and SHA256.fullmatch(value) is not None
81
+
82
+
83
+ def verify_evidence(items: object, candidate: str | None, role: str, status: str) -> None:
84
+ require(isinstance(items, list) and len(items) <= 16, "INVALID_EVIDENCE_COLLECTION")
85
+ if status == "PASS":
86
+ require(candidate is not None, "PASS_WITHOUT_CANDIDATE")
87
+ require(bool(items), "PASS_WITHOUT_EVIDENCE")
88
+ for value in items:
89
+ require(isinstance(value, dict), "INVALID_EVIDENCE_RECORD")
90
+ require(set(value) == {"reference", "digest_sha256", "source_sha", "verifier_role", "scope"},
91
+ "INVALID_EVIDENCE_FIELDS")
92
+ require(isinstance(value["reference"], str) and REF.fullmatch(value["reference"]) is not None,
93
+ "INVALID_EVIDENCE_REFERENCE")
94
+ require(sha256(value["digest_sha256"]), "INVALID_EVIDENCE_DIGEST")
95
+ require(sha40(value["source_sha"]) and value["source_sha"] == candidate, "EVIDENCE_IDENTITY_MISMATCH")
96
+ require(value["verifier_role"] == role, "EVIDENCE_AUTHORITY_MISMATCH")
97
+ require(isinstance(value["scope"], str) and REASON.fullmatch(value["scope"]) is not None,
98
+ "INVALID_EVIDENCE_SCOPE")
99
+
100
+
101
+ def validate(document: object, *, expected_source_sha: str | None = None) -> dict:
102
+ require(isinstance(document, dict), "INVALID_LEDGER_ROOT")
103
+ require(set(document) == {"schema_version", "contract", "purpose", "baseline", "execution", "gates", "scenarios"},
104
+ "LEDGER_FIELDS_MISMATCH")
105
+ require(type(document["schema_version"]) is int and document["schema_version"] == 1
106
+ and document["contract"] == "afyx.alpha.acceptance/v1", "UNSUPPORTED_LEDGER_CONTRACT")
107
+ baseline = document["baseline"]
108
+ require(isinstance(baseline, dict)
109
+ and set(baseline) == {"branch", "observed_source_sha", "candidate_source_sha", "artifact_digest_sha256"},
110
+ "INVALID_BASELINE")
111
+ require(baseline["branch"] == "dev" and sha40(baseline["observed_source_sha"]), "INVALID_OBSERVED_SOURCE")
112
+ candidate = baseline["candidate_source_sha"]
113
+ require(candidate is None or sha40(candidate), "INVALID_CANDIDATE_SHA")
114
+ artifact = baseline["artifact_digest_sha256"]
115
+ require(artifact is None or sha256(artifact), "INVALID_ARTIFACT_DIGEST")
116
+ if expected_source_sha is not None:
117
+ require(sha40(expected_source_sha) and candidate == expected_source_sha, "CANDIDATE_REVISION_MISMATCH")
118
+ execution = document["execution"]
119
+ require(isinstance(execution, dict) and set(execution) == {
120
+ "provider_calls_observed", "real_world_pilot_executed",
121
+ "independent_evaluator_run", "owner_release_approval"
122
+ }, "INVALID_EXECUTION_RECORD")
123
+ require(type(execution["provider_calls_observed"]) is int and execution["provider_calls_observed"] >= 0,
124
+ "INVALID_PROVIDER_CALL_COUNT")
125
+ for key in ("real_world_pilot_executed", "independent_evaluator_run", "owner_release_approval"):
126
+ require(type(execution[key]) is bool, "INVALID_EXECUTION_FLAG")
127
+ gates = document["gates"]
128
+ scenarios = document["scenarios"]
129
+ require(isinstance(gates, list) and len(gates) == len(GATES), "GATE_COVERAGE_INCOMPLETE")
130
+ require(isinstance(scenarios, list) and len(scenarios) == len(SCENARIOS), "SCENARIO_COVERAGE_INCOMPLETE")
131
+ seen_gates: dict[str, str] = {}
132
+ gate_counts = {status: 0 for status in STATUSES}
133
+ for entry in gates:
134
+ require(isinstance(entry, dict) and set(entry) == {
135
+ "id", "required_verifier", "depends_on", "status", "reason_code", "evidence"
136
+ }, "INVALID_GATE_FIELDS")
137
+ identity = entry["id"]
138
+ require(isinstance(identity, str) and identity in GATES and identity not in seen_gates,
139
+ "INVALID_GATE_IDENTITY")
140
+ role, prerequisites = GATES[identity]
141
+ require(entry["required_verifier"] == role and entry["depends_on"] == list(prerequisites),
142
+ "GATE_CONTRACT_DRIFT")
143
+ status = entry["status"]
144
+ require(status in STATUSES, "INVALID_GATE_STATUS")
145
+ require(isinstance(entry["reason_code"], str) and REASON.fullmatch(entry["reason_code"]) is not None,
146
+ "INVALID_REASON_CODE")
147
+ verify_evidence(entry["evidence"], candidate, role, status)
148
+ if status == "PASS":
149
+ require(all(seen_gates.get(parent) == "PASS" for parent in prerequisites),
150
+ "PASS_WITHOUT_PREREQUISITE_ACCEPTANCE")
151
+ if identity in REQUIRES_INSTALLED_ARTIFACT:
152
+ require(artifact is not None, "PASS_WITHOUT_INSTALLED_ARTIFACT_IDENTITY")
153
+ if role == "independent_evaluator":
154
+ require(execution["independent_evaluator_run"], "INDEPENDENT_EVALUATION_NOT_OBSERVED")
155
+ if identity == "PHASE8_REAL_DOGFOOD":
156
+ require(execution["real_world_pilot_executed"], "PILOT_NOT_OBSERVED")
157
+ if identity == "PHASE11_STABLE":
158
+ require(execution["owner_release_approval"], "RELEASE_APPROVAL_NOT_OBSERVED")
159
+ seen_gates[identity] = status
160
+ gate_counts[status] += 1
161
+ require(tuple(seen_gates) == tuple(GATES), "GATE_ORDER_MISMATCH")
162
+ seen_scenarios: set[str] = set()
163
+ scenario_counts = {status: 0 for status in STATUSES}
164
+ for entry in scenarios:
165
+ require(isinstance(entry, dict) and set(entry) == {
166
+ "id", "task_family", "size_band", "method", "status", "reason_code", "evidence"
167
+ }, "INVALID_SCENARIO_FIELDS")
168
+ identity = entry["id"]
169
+ require(isinstance(identity, str) and identity in SCENARIOS and identity not in seen_scenarios,
170
+ "INVALID_SCENARIO_ID")
171
+ require((entry["task_family"], entry["size_band"], entry["method"]) == SCENARIOS[identity],
172
+ "SCENARIO_CONTRACT_DRIFT")
173
+ status = entry["status"]
174
+ require(status in STATUSES and isinstance(entry["reason_code"], str)
175
+ and REASON.fullmatch(entry["reason_code"]) is not None, "INVALID_SCENARIO_STATUS")
176
+ role = "independent_evaluator" if entry["method"] == "CONTROL_TREATMENT" else "owner"
177
+ verify_evidence(entry["evidence"], candidate, role, status)
178
+ if status == "PASS":
179
+ require(execution["real_world_pilot_executed"], "PILOT_NOT_OBSERVED")
180
+ if role == "independent_evaluator":
181
+ require(execution["independent_evaluator_run"], "INDEPENDENT_EVALUATION_NOT_OBSERVED")
182
+ seen_scenarios.add(identity)
183
+ scenario_counts[status] += 1
184
+ require(seen_scenarios == set(SCENARIOS), "SCENARIO_IDS_INCOMPLETE")
185
+ if seen_gates.get("PHASE8_REAL_DOGFOOD") == "PASS":
186
+ require(all(e["status"] == "PASS" for e in scenarios), "PHASE8_WITHOUT_SCENARIO_ACCEPTANCE")
187
+ all_claimed_pass = gate_counts["PASS"] == len(GATES) and scenario_counts["PASS"] == len(SCENARIOS)
188
+ # This program never verifies independent evidence bytes or signs an
189
+ # acceptance verdict. It is a schema+consistency checker only.
190
+ return {
191
+ "contract": "afyx.alpha.preflight.report/v1",
192
+ "validation": "CLAIM_SCHEMA_AND_DEPENDENCIES_ONLY",
193
+ "external_evidence_verified": False,
194
+ "status": "READY_FOR_INDEPENDENT_REVIEW" if all_claimed_pass else "BLOCKED",
195
+ "gates": gate_counts,
196
+ "scenarios": scenario_counts,
197
+ "pending_gate_ids": [e["id"] for e in gates if e["status"] != "PASS"],
198
+ "pending_scenario_ids": [e["id"] for e in scenarios if e["status"] != "PASS"],
199
+ "release_approved_by_tool": False,
200
+ "provider_calls_by_tool": 0,
201
+ }
202
+
203
+
204
+ def read_ledger(file: Path) -> object:
205
+ item = file.lstat()
206
+ require(stat.S_ISREG(item.st_mode) and not file.is_symlink()
207
+ and not (getattr(item, "st_file_attributes", 0) & 0x400), "UNSAFE_LEDGER_PATH")
208
+ require(item.st_size <= MAX_LEDGER_BYTES, "LEDGER_TOO_LARGE")
209
+ with file.open("rb") as handle:
210
+ return json.load(handle)
211
+
212
+
213
+ def main(argv: list[str] | None = None) -> int:
214
+ parser = argparse.ArgumentParser(description=__doc__)
215
+ parser.add_argument("--ledger", type=Path, default=Path(__file__).resolve().parents[1] /
216
+ "docs" / "AFYX_ALPHA_ACCEPTANCE_LEDGER.json")
217
+ parser.add_argument("--expected-source-sha", default=None)
218
+ parser.add_argument("--require-review-ready", action="store_true")
219
+ parser.add_argument("--output", type=Path, default=None, help="Create a new sanitized report; refuse overwrite")
220
+ args = parser.parse_args(argv)
221
+ try:
222
+ report = validate(read_ledger(args.ledger), expected_source_sha=args.expected_source_sha)
223
+ serialized = json.dumps(report, indent=2, sort_keys=True) + "\n"
224
+ if args.output:
225
+ with args.output.open("x", encoding="utf-8", newline="\n") as handle:
226
+ handle.write(serialized)
227
+ else:
228
+ sys.stdout.write(serialized)
229
+ if args.require_review_ready and report["status"] != "READY_FOR_INDEPENDENT_REVIEW":
230
+ return 3
231
+ return 0
232
+ except (LedgerError, OSError, ValueError, TypeError) as exc:
233
+ # Do not expose absolute private file paths or raw evidence in errors.
234
+ code = str(exc) if isinstance(exc, LedgerError) else "LEDGER_UNREADABLE_OR_OUTPUT_UNAVAILABLE"
235
+ print("ALPHA_PREFLIGHT_BLOCKED: " + code, file=sys.stderr)
236
+ return 2
237
+
238
+
239
+ if __name__ == "__main__":
240
+ raise SystemExit(main())
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AFYX Graph Memory Profiling & Benchmark Harness
4
+ * Measures memory (RSS), CPU time, duration, and correctness on a repository workload.
5
+ */
6
+
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import { performance } from 'node:perf_hooks';
11
+ import { fileURLToPath, pathToFileURL } from 'node:url';
12
+
13
+ const testDir = path.dirname(fileURLToPath(import.meta.url));
14
+ const kitRoot = path.resolve(testDir, '..');
15
+ const graphDist = path.join(kitRoot, 'afyx-graph', 'engine', 'dist');
16
+
17
+ async function runBenchmark(targetRepo, options = {}) {
18
+ const graphModule = await import(pathToFileURL(path.join(graphDist, 'index.js')).href);
19
+ const GraphClass = graphModule.default?.default ?? graphModule.default ?? graphModule.AfyxGraph;
20
+
21
+ const tempStateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'afyx-mem-bench-'));
22
+ const priorGraphState = process.env.AFYX_GRAPH_STATE_DIR;
23
+ process.env.AFYX_GRAPH_STATE_DIR = tempStateDir;
24
+
25
+ let peakRss = 0;
26
+ const initialRss = process.memoryUsage().rss;
27
+ const startCpu = process.cpuUsage();
28
+ const startTime = performance.now();
29
+
30
+ const sampler = setInterval(() => {
31
+ const current = process.memoryUsage().rss;
32
+ if (current > peakRss) peakRss = current;
33
+ }, 25);
34
+
35
+ let graph;
36
+ let indexResult;
37
+ try {
38
+ graph = GraphClass.initSync(targetRepo);
39
+ indexResult = await graph.indexAll({ verbose: false });
40
+ } finally {
41
+ clearInterval(sampler);
42
+ const endRss = process.memoryUsage().rss;
43
+ if (endRss > peakRss) peakRss = endRss;
44
+
45
+ const durationMs = performance.now() - startTime;
46
+ const cpuDiff = process.cpuUsage(startCpu);
47
+ const totalCpuSec = (cpuDiff.user + cpuDiff.system) / 1_000_000;
48
+
49
+ let nodeCount = 0;
50
+ let edgeCount = 0;
51
+ if (graph) {
52
+ try {
53
+ nodeCount = graph.queries.getNodesCount ? graph.queries.getNodesCount() : indexResult?.nodesCreated ?? 0;
54
+ edgeCount = graph.queries.getEdgesCount ? graph.queries.getEdgesCount() : indexResult?.edgesCreated ?? 0;
55
+ } catch {
56
+ // fallback to indexResult counts
57
+ nodeCount = indexResult?.nodesCreated ?? 0;
58
+ edgeCount = indexResult?.edgesCreated ?? 0;
59
+ }
60
+ try { graph.close(); } catch {}
61
+ }
62
+
63
+ if (priorGraphState !== undefined) {
64
+ process.env.AFYX_GRAPH_STATE_DIR = priorGraphState;
65
+ } else {
66
+ delete process.env.AFYX_GRAPH_STATE_DIR;
67
+ }
68
+
69
+ if (fs.existsSync(tempStateDir)) {
70
+ try { fs.rmSync(tempStateDir, { recursive: true, force: true }); } catch {}
71
+ }
72
+
73
+ return {
74
+ targetRepo,
75
+ durationMs: Number(durationMs.toFixed(2)),
76
+ durationSec: Number((durationMs / 1000).toFixed(2)),
77
+ initialRssMiB: Number((initialRss / (1024 * 1024)).toFixed(2)),
78
+ peakRssMiB: Number((peakRss / (1024 * 1024)).toFixed(2)),
79
+ deltaRssMiB: Number(((peakRss - initialRss) / (1024 * 1024)).toFixed(2)),
80
+ cpuSec: Number(totalCpuSec.toFixed(2)),
81
+ filesIndexed: indexResult?.filesIndexed ?? 0,
82
+ nodesCreated: nodeCount,
83
+ edgesCreated: edgeCount,
84
+ success: indexResult?.success ?? false,
85
+ };
86
+ }
87
+ }
88
+
89
+ const target = process.argv[2] ? path.resolve(process.argv[2]) : path.join(kitRoot, 'afyx-context');
90
+ console.log(`[mem-bench] Benchmarking target: ${target}`);
91
+ runBenchmark(target).then((metrics) => {
92
+ console.log(JSON.stringify(metrics, null, 2));
93
+ }).catch((err) => {
94
+ console.error('[mem-bench] Failed:', err);
95
+ process.exit(1);
96
+ });
@@ -0,0 +1,64 @@
1
+ import { performance } from 'node:perf_hooks';
2
+
3
+ import {
4
+ SEVEN_REGISTERED_COMPONENT_IDS,
5
+ resolveAfyxCapabilityRoute,
6
+ } from './afyx-capability-orchestrator.mjs';
7
+
8
+ const iterations = 10_000;
9
+ const componentStates = Object.fromEntries(SEVEN_REGISTERED_COMPONENT_IDS.map((id) => [id, {
10
+ installed: true,
11
+ enabled: true,
12
+ healthy: true,
13
+ compatible: true,
14
+ authorized: true,
15
+ sourceIdentity: 'benchmark-fixture',
16
+ ...(id === 'afyx-graph' ? { indexReady: true, indexFresh: true } : {}),
17
+ }]));
18
+ const input = {
19
+ task: {
20
+ id: 'benchmark-route',
21
+ taskType: 'odoo-impact-analysis',
22
+ project: { isOdoo: true },
23
+ needsRelationalEvidence: true,
24
+ needsContextOptimization: true,
25
+ workspaceIdentity: 'benchmark/fixture',
26
+ sourceRevision: 'benchmark',
27
+ },
28
+ provider: 'codex',
29
+ componentStates,
30
+ };
31
+
32
+ // Warm the module and JIT before measuring.
33
+ for (let index = 0; index < 1_000; index += 1) resolveAfyxCapabilityRoute(input);
34
+ const heapBefore = process.memoryUsage().heapUsed;
35
+ const cpuBefore = process.cpuUsage();
36
+ const startedAt = performance.now();
37
+ let selectedCapabilities = 0;
38
+ for (let index = 0; index < iterations; index += 1) {
39
+ selectedCapabilities += resolveAfyxCapabilityRoute(input).requests.length;
40
+ }
41
+ const elapsedMs = performance.now() - startedAt;
42
+ const cpu = process.cpuUsage(cpuBefore);
43
+ const heapAfter = process.memoryUsage().heapUsed;
44
+ let directSourceRuntimeSelections = 0;
45
+ for (let index = 0; index < iterations; index += 1) {
46
+ directSourceRuntimeSelections += resolveAfyxCapabilityRoute({
47
+ ...input,
48
+ task: { ...input.task, taskType: 'string-replacement', exactKnownSource: true },
49
+ }).requests.length;
50
+ }
51
+
52
+ console.log(JSON.stringify({
53
+ contract: 'AfyxCapabilityRouterBenchmark/v1',
54
+ iterations,
55
+ elapsedMs,
56
+ averageRouteMs: elapsedMs / iterations,
57
+ heapDeltaBytes: heapAfter - heapBefore,
58
+ cpuUserMicroseconds: cpu.user,
59
+ cpuSystemMicroseconds: cpu.system,
60
+ selectedCapabilities,
61
+ averageSelectedCapabilities: selectedCapabilities / iterations,
62
+ directSourceRuntimeSelections,
63
+ note: 'CPU elapsed and process heap delta are local deterministic observations, not provider cost.',
64
+ }, null, 2));
@@ -0,0 +1,259 @@
1
+ # Builder for Afyx Unified Windows Installer (TASK U-A02)
2
+ # Generates a single lightweight AfyxSetup.exe executable with embedded 7-component offline payload.
3
+
4
+ [CmdletBinding()]
5
+ param(
6
+ [string]$OutputDir = (Join-Path $PSScriptRoot '..\dist'),
7
+ [switch]$SkipPayloadBuild,
8
+ [string]$RepoRoot = ''
9
+ )
10
+
11
+ Set-StrictMode -Version Latest
12
+ $ErrorActionPreference = 'Stop'
13
+
14
+ $scriptRoot = $PSScriptRoot
15
+ $repoRoot = if ($RepoRoot) {
16
+ if (-not (Test-Path -LiteralPath $RepoRoot)) {
17
+ throw "Repository root path does not exist: $RepoRoot"
18
+ }
19
+ (Resolve-Path $RepoRoot).Path
20
+ } else {
21
+ (Resolve-Path (Join-Path $scriptRoot '..')).Path
22
+ }
23
+ $toolsDir = Join-Path $repoRoot 'tools\windows-setup'
24
+
25
+ Write-Host "=== Afyx Unified Windows Installer Builder (TASK U-A02) ===" -ForegroundColor Cyan
26
+ Write-Host "Repo Root: $repoRoot"
27
+ Write-Host "Output Dir: $OutputDir"
28
+
29
+ # Preflight: Require mandatory capability contracts before packaging (AFYX-304)
30
+ $contractsDir = Join-Path $repoRoot 'scripts\contracts'
31
+ if (-not (Test-Path -LiteralPath $contractsDir -PathType Container)) {
32
+ throw "Required capability contracts directory missing: $contractsDir. Packaging requires capability contracts for host bridge productization."
33
+ }
34
+
35
+ $requiredSchemas = @(
36
+ 'afyx-capability-request-v1.schema.json',
37
+ 'afyx-capability-result-v1.schema.json'
38
+ )
39
+ foreach ($schemaFile in $requiredSchemas) {
40
+ $schemaPath = Join-Path $contractsDir $schemaFile
41
+ if (-not (Test-Path -LiteralPath $schemaPath -PathType Leaf)) {
42
+ throw "Required capability contract schema missing: $schemaPath. The Windows installer package requires valid capability contracts."
43
+ }
44
+ }
45
+
46
+ if ($SkipPayloadBuild) {
47
+ Write-Host "Contract preflight PASSED. Skipping installer payload build (-SkipPayloadBuild specified)." -ForegroundColor Green
48
+ return [pscustomobject]@{
49
+ Preflight = 'PASS'
50
+ ContractsDir = $contractsDir
51
+ RequiredSchemas = $requiredSchemas
52
+ }
53
+ }
54
+
55
+ if (-not (Test-Path -LiteralPath $OutputDir)) {
56
+ New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
57
+ }
58
+
59
+ $stagingDir = Join-Path ([System.IO.Path]::GetTempPath()) "afyx-setup-staging-$([Guid]::NewGuid().ToString('N').Substring(0, 8))"
60
+ $payloadZip = Join-Path $OutputDir 'afyx-kit-payload.zip'
61
+ $outputExe = Join-Path $OutputDir 'AfyxSetup.exe'
62
+
63
+ try {
64
+ Write-Host "[1/4] Preparing Clean 7-Component Distribution Staging..." -ForegroundColor Yellow
65
+ New-Item -ItemType Directory -Path $stagingDir -Force | Out-Null
66
+
67
+ # Root scripts
68
+ foreach ($file in @('install.ps1', 'verify.ps1', 'update.ps1', 'uninstall.ps1')) {
69
+ Copy-Item -LiteralPath (Join-Path $repoRoot $file) -Destination (Join-Path $stagingDir $file) -Force
70
+ }
71
+ $currentRevision = ((& git -C $repoRoot rev-parse HEAD 2>$null) -join '').Trim()
72
+ if ($currentRevision -match '^[0-9a-f]{40}$') {
73
+ Set-Content -LiteralPath (Join-Path $stagingDir '.afyx-source-revision') -Value $currentRevision -Encoding utf8
74
+ }
75
+
76
+ # Scripts directory
77
+ $stagedScripts = Join-Path $stagingDir 'scripts'
78
+ New-Item -ItemType Directory -Path $stagedScripts -Force | Out-Null
79
+ Copy-Item -LiteralPath (Join-Path $repoRoot 'scripts\lib') -Destination $stagedScripts -Recurse -Force
80
+ Copy-Item -LiteralPath $contractsDir -Destination $stagedScripts -Recurse -Force
81
+
82
+ Get-ChildItem -Path (Join-Path $repoRoot 'scripts') -File | Where-Object {
83
+ $_.Name -notin @('build-windows-installer.ps1')
84
+ } | ForEach-Object {
85
+ Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $stagedScripts $_.Name) -Force
86
+ }
87
+
88
+ # Skills directory
89
+ $stagedSkills = Join-Path $stagingDir 'skills'
90
+ New-Item -ItemType Directory -Path $stagedSkills -Force | Out-Null
91
+ # Include optional provider companions from the candidate source tree.
92
+ # Context is introduced on a separate PR; staging must pick it up when
93
+ # that source is integrated, without changing today's standalone default.
94
+ foreach ($sk in @('efficient-coding', 'odoo-engineering', 'afyx-engineering-expert', 'afyx-forge', 'afyx-context')) {
95
+ $skSrc = Join-Path $repoRoot "skills\$sk"
96
+ if (Test-Path -LiteralPath $skSrc) {
97
+ Copy-Item -LiteralPath $skSrc -Destination $stagedSkills -Recurse -Force
98
+ }
99
+ }
100
+
101
+ # Afyx Context directory
102
+ $stagedContext = Join-Path $stagingDir 'afyx-context'
103
+ New-Item -ItemType Directory -Path $stagedContext -Force | Out-Null
104
+ Copy-Item -Path (Join-Path $repoRoot 'afyx-context\*') -Destination $stagedContext -Recurse -Force
105
+
106
+ # Afyx Forge directory
107
+ $stagedForge = Join-Path $stagingDir 'afyx-forge'
108
+ New-Item -ItemType Directory -Path $stagedForge -Force | Out-Null
109
+ Copy-Item -Path (Join-Path $repoRoot 'afyx-forge\*') -Destination $stagedForge -Recurse -Force
110
+
111
+ # Afyx Graph directory
112
+ $stagedGraph = Join-Path $stagingDir 'afyx-graph'
113
+ New-Item -ItemType Directory -Path $stagedGraph -Force | Out-Null
114
+ Copy-Item -LiteralPath (Join-Path $repoRoot 'afyx-graph\afyx-graph.json') -Destination (Join-Path $stagedGraph 'afyx-graph.json') -Force
115
+
116
+ $distJsonSrc = Join-Path $repoRoot 'afyx-graph\engine\scripts\distribution-product.json'
117
+ $distContractSrc = Join-Path $repoRoot 'afyx-graph\engine\scripts\distribution-contract.mjs'
118
+ if (Test-Path -LiteralPath $distJsonSrc) {
119
+ $stagedGraphScripts = Join-Path $stagedGraph 'engine\scripts'
120
+ New-Item -ItemType Directory -Path $stagedGraphScripts -Force | Out-Null
121
+ Copy-Item -LiteralPath $distJsonSrc -Destination (Join-Path $stagedGraphScripts 'distribution-product.json') -Force
122
+ if (Test-Path -LiteralPath $distContractSrc) {
123
+ Copy-Item -LiteralPath $distContractSrc -Destination (Join-Path $stagedGraphScripts 'distribution-contract.mjs') -Force
124
+ }
125
+ }
126
+
127
+ $graphReleaseZip = Join-Path $repoRoot 'afyx-graph\engine\release\afyx-graph-win32-x64.zip'
128
+ if (-not (Test-Path -LiteralPath $graphReleaseZip)) {
129
+ throw "Afyx Graph win32 release artifact not found at $graphReleaseZip. Run graph build first."
130
+ }
131
+ $stagedGraphRelease = Join-Path $stagedGraph 'engine\release'
132
+ New-Item -ItemType Directory -Path $stagedGraphRelease -Force | Out-Null
133
+ Copy-Item -LiteralPath $graphReleaseZip -Destination (Join-Path $stagedGraphRelease 'afyx-graph-win32-x64.zip') -Force
134
+ $graphSums = Join-Path $repoRoot 'afyx-graph\engine\release\SHA256SUMS'
135
+ if (Test-Path -LiteralPath $graphSums) {
136
+ Copy-Item -LiteralPath $graphSums -Destination (Join-Path $stagedGraphRelease 'SHA256SUMS') -Force
137
+ }
138
+
139
+ # Tools directory
140
+ $stagedTools = Join-Path $stagingDir 'tools'
141
+ New-Item -ItemType Directory -Path $stagedTools -Force | Out-Null
142
+ Get-ChildItem -Path (Join-Path $repoRoot 'tools') -Directory | Where-Object {
143
+ $_.Name -ne 'windows-setup'
144
+ } | ForEach-Object {
145
+ Copy-Item -LiteralPath $_.FullName -Destination $stagedTools -Recurse -Force
146
+ }
147
+
148
+ Write-Host "[2/4] Compressing Clean 7-Component Staging into $payloadZip..." -ForegroundColor Yellow
149
+ if (Test-Path -LiteralPath $payloadZip) { Remove-Item -LiteralPath $payloadZip -Force }
150
+
151
+ # Use .NET ZipArchive for deterministic, clean compression
152
+ [System.IO.Compression.ZipFile]::CreateFromDirectory($stagingDir, $payloadZip, [System.IO.Compression.CompressionLevel]::Optimal, $false)
153
+ $zipLengthMB = [math]::Round(((Get-Item -LiteralPath $payloadZip).Length / 1MB), 2)
154
+ Write-Host "-> Payload package created: $zipLengthMB MB" -ForegroundColor Green
155
+
156
+ Write-Host "[3/4] Compiling AfyxSetup.exe via .NET C# Compiler..." -ForegroundColor Yellow
157
+ $cscPath = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe"
158
+ if (-not (Test-Path -LiteralPath $cscPath)) {
159
+ $cscPath = (Get-Command csc.exe -ErrorAction SilentlyContinue).Source
160
+ }
161
+ if (-not $cscPath) { throw "C# compiler csc.exe not found on system." }
162
+
163
+ $sourceCs = Join-Path $toolsDir 'SetupBootstrapper.cs'
164
+ $cscArgs = @(
165
+ '/target:exe',
166
+ '/platform:anycpu',
167
+ '/optimize+',
168
+ "/out:$outputExe",
169
+ "/resource:$payloadZip,afyx-kit-payload.zip",
170
+ '/reference:System.IO.Compression.dll',
171
+ '/reference:System.IO.Compression.FileSystem.dll',
172
+ $sourceCs
173
+ )
174
+
175
+ & $cscPath $cscArgs
176
+ if ($LASTEXITCODE -ne 0) { throw "csc.exe compilation failed with exit code $LASTEXITCODE" }
177
+
178
+ $exeLengthMB = [math]::Round(((Get-Item -LiteralPath $outputExe).Length / 1MB), 2)
179
+ Write-Host "-> Executable created: $outputExe ($exeLengthMB MB)" -ForegroundColor Green
180
+
181
+ Write-Host "[4/4] Calculating SHA-256 Checksums & Generating Build Manifest..." -ForegroundColor Yellow
182
+ $hash = (Get-FileHash -LiteralPath $outputExe -Algorithm SHA256).Hash.ToLowerInvariant()
183
+ $checksumFile = Join-Path $OutputDir 'AfyxSetup.exe.sha256'
184
+ Set-Content -LiteralPath $checksumFile -Value "$hash AfyxSetup.exe`n" -Encoding utf8
185
+
186
+ $sumsFile = Join-Path $OutputDir 'SHA256SUMS'
187
+ $zipHash = (Get-FileHash -LiteralPath $payloadZip -Algorithm SHA256).Hash.ToLowerInvariant()
188
+ $sumsContent = @"
189
+ $hash AfyxSetup.exe
190
+ $zipHash afyx-kit-payload.zip
191
+ "@
192
+ Set-Content -LiteralPath $sumsFile -Value $sumsContent -Encoding utf8
193
+
194
+ $manifestFile = Join-Path $OutputDir 'build-manifest.json'
195
+ $kitVersion = (Get-Content -Raw -LiteralPath (Join-Path $repoRoot 'package.json') | ConvertFrom-Json).version
196
+ function Get-StagedSkillVersion([string]$Skill) {
197
+ $source = Get-Content -Raw -LiteralPath (Join-Path $repoRoot "skills/$Skill/SKILL.md")
198
+ if ($source -notmatch '(?m)^\s*version:\s*"?([0-9]+\.[0-9]+\.[0-9]+)"?\s*$') { throw "Missing version metadata for $Skill" }
199
+ return $Matches[1]
200
+ }
201
+ function Get-StagedRuntimeVersion([string]$RelativePath) {
202
+ return (Get-Content -Raw -LiteralPath (Join-Path $repoRoot $RelativePath) | ConvertFrom-Json).version
203
+ }
204
+ $buildManifest = [ordered]@{
205
+ product_name = "Afyx Engineering Kit"
206
+ distribution_channel = "technical-alpha"
207
+ package_name = "AfyxSetup.exe"
208
+ package_version = $kitVersion
209
+ target_platform = "win32-x64"
210
+ source_revision = $currentRevision
211
+ build_timestamp = (Get-Date).ToString('o')
212
+ executable_size_bytes = (Get-Item -LiteralPath $outputExe).Length
213
+ executable_sha256 = $hash
214
+ payload_size_bytes = (Get-Item -LiteralPath $payloadZip).Length
215
+ payload_sha256 = $zipHash
216
+ components = @(
217
+ @{ id = "efficient-coding"; name = "Afyx Efficient Coding"; type = "skill"; version = (Get-StagedSkillVersion 'efficient-coding'); tier = "core" },
218
+ @{ id = "odoo-engineering"; name = "Afyx Odoo Engineering"; type = "skill"; version = (Get-StagedSkillVersion 'odoo-engineering'); tier = "core" },
219
+ @{ id = "afyx-engineering-expert"; name = "Afyx Engineering Expert"; type = "skill"; version = (Get-StagedSkillVersion 'afyx-engineering-expert'); tier = "optional" },
220
+ @{ id = "afyx-graph"; name = "Afyx Graph"; type = "runtime"; version = (Get-StagedRuntimeVersion 'afyx-graph/engine/package.json'); tier = "optional"; activation = "on-demand" },
221
+ @{ id = "afyx-context"; name = "Afyx Context Engine"; type = "runtime"; version = (Get-StagedRuntimeVersion 'afyx-context/package.json'); tier = "optional"; integration_default = "OFF" },
222
+ @{ id = "afyx-forge"; name = "Afyx Forge Core"; type = "runtime"; version = (Get-StagedRuntimeVersion 'afyx-forge/package.json'); tier = "optional"; mode = "assistive-guidance-only"; a8_gate = "EVALUATION_GATED"; assistive_planner_decision = "GO_BOUNDED_LOCAL_ASSISTIVE_PLANNER" },
223
+ @{ id = "codex-usage-tracking"; name = "Afyx Codex Usage Tracking"; type = "toolset"; version = "1.0.0"; tier = "optional"; platform = "windows" }
224
+ )
225
+ governance_boundaries = @{
226
+ forge_autonomous_execution = "FORBIDDEN"
227
+ forge_a8_gate = "EVALUATION_GATED (0/36 NOT_RUN)"
228
+ context_graph_integration = "DEFAULT_OFF"
229
+ graph_v29_wip = "EXCLUDED"
230
+ code_signing = "UNSIGNED_ALPHA_CANDIDATE"
231
+ }
232
+ runtime_prerequisites = @(
233
+ "Windows 10 / Windows 11 (x64)",
234
+ "PowerShell 7.0+ (pwsh) or Windows PowerShell 5.1",
235
+ "Node.js >= 22.5.0 (for Graph, Context, and Forge runtimes)",
236
+ "Git for Windows (for version control operations)"
237
+ )
238
+ }
239
+ Set-Content -LiteralPath $manifestFile -Value ($buildManifest | ConvertTo-Json -Depth 10) -Encoding utf8
240
+
241
+ Write-Host "`n=== BUILD COMPLETE ===" -ForegroundColor Green
242
+ Write-Host "Installer Executable: $outputExe ($exeLengthMB MB)"
243
+ Write-Host "SHA-256: $hash"
244
+ Write-Host "Checksum file: $checksumFile"
245
+ Write-Host "Build manifest: $manifestFile"
246
+
247
+ return [pscustomobject]@{
248
+ Executable = $outputExe
249
+ SizeMB = $exeLengthMB
250
+ SHA256 = $hash
251
+ PayloadZip = $payloadZip
252
+ Manifest = $manifestFile
253
+ }
254
+ }
255
+ finally {
256
+ if (Test-Path -LiteralPath $stagingDir) {
257
+ Remove-Item -LiteralPath $stagingDir -Recurse -Force -ErrorAction SilentlyContinue
258
+ }
259
+ }