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,75 @@
1
+ /** Authorization boundary for credential use. Never returns credential material. */
2
+ import { randomUUID } from 'node:crypto';
3
+
4
+ export const CREDENTIAL_BROKER_CONTRACT = 'AfyxCredentialBroker/v1';
5
+ const OPERATIONS = new Set(['inject-process', 'fill-host-field']);
6
+ const PROVIDERS = new Set(['codex', 'antigravity', 'claude']);
7
+ const ALIAS = /^[a-z][a-z0-9-]{1,63}$/;
8
+ const BACKEND = /^[a-z0-9][a-z0-9-]{1,63}$/;
9
+
10
+ function valid(value, pattern) { return typeof value === 'string' && pattern.test(value); }
11
+
12
+ /** Adapters are supplied by a trusted host, never by a task payload. */
13
+ export function createCredentialBroker({ adapters = {}, now = Date.now } = {}) {
14
+ const sessions = new Map();
15
+ const supported = new Map(Object.entries(adapters).filter(([name, adapter]) =>
16
+ valid(name, BACKEND) && adapter && typeof adapter.use === 'function'));
17
+
18
+ function grant({ provider, backend, scope, aliases, operations, targets, ttlMs }, { authorize, consent } = {}) {
19
+ if (!PROVIDERS.has(provider) || !valid(backend, BACKEND) || !valid(scope, ALIAS)
20
+ || !Array.isArray(aliases) || !aliases.length || !aliases.every((x) => valid(x, ALIAS))
21
+ || !Array.isArray(operations) || !operations.length || !operations.every((x) => OPERATIONS.has(x))
22
+ || !Array.isArray(targets) || !targets.length || !targets.every((x) => valid(x, ALIAS))
23
+ || !Number.isSafeInteger(ttlMs) || ttlMs < 1 || ttlMs > 300_000) {
24
+ return { contract: CREDENTIAL_BROKER_CONTRACT, status: 'INVALID_GRANT' };
25
+ }
26
+ if (!supported.has(backend)) return { contract: CREDENTIAL_BROKER_CONTRACT, status: 'BACKEND_UNAVAILABLE' };
27
+ const grantRequest = Object.freeze({ provider, backend, scope, aliases: Object.freeze([...aliases]),
28
+ operations: Object.freeze([...operations]), targets: Object.freeze([...targets]), ttlMs });
29
+ let approved = false;
30
+ try { approved = typeof authorize === 'function' && authorize(grantRequest) === true
31
+ && typeof consent === 'function' && consent(grantRequest) === true; } catch { /* fail closed */ }
32
+ if (!approved) {
33
+ return { contract: CREDENTIAL_BROKER_CONTRACT, status: 'DENIED' };
34
+ }
35
+ const sessionId = randomUUID();
36
+ const expiresAt = now() + ttlMs;
37
+ sessions.set(sessionId, { ...grantRequest, expiresAt });
38
+ return { contract: CREDENTIAL_BROKER_CONTRACT, status: 'GRANTED', sessionId, expiresAt };
39
+ }
40
+
41
+ async function use(request) {
42
+ const base = { contract: CREDENTIAL_BROKER_CONTRACT };
43
+ if (!request || request.contract !== CREDENTIAL_BROKER_CONTRACT
44
+ || Object.keys(request).some((key) => !['contract', 'sessionId', 'provider', 'scope', 'alias', 'operation', 'target'].includes(key))
45
+ || !valid(request.alias, ALIAS) || !valid(request.target, ALIAS) || !OPERATIONS.has(request.operation)) {
46
+ return { ...base, status: 'INVALID_REQUEST' };
47
+ }
48
+ const session = sessions.get(request.sessionId);
49
+ if (!session) return { ...base, status: 'DENIED' };
50
+ if (now() >= session.expiresAt) { sessions.delete(request.sessionId); return { ...base, status: 'EXPIRED' }; }
51
+ if (session.provider !== request.provider || session.scope !== request.scope
52
+ || !session.aliases.includes(request.alias) || !session.operations.includes(request.operation)
53
+ || !session.targets.includes(request.target)) {
54
+ return { ...base, status: 'DENIED' };
55
+ }
56
+ const adapter = supported.get(session.backend);
57
+ if (!adapter) return { ...base, status: 'BACKEND_UNAVAILABLE' };
58
+ // An approved grant authorizes exactly one use, not unlimited secret-use
59
+ // operations during the TTL. Consume it before awaiting the trusted
60
+ // backend so simultaneous/replayed requests cannot race past consent.
61
+ sessions.delete(request.sessionId);
62
+ try {
63
+ // Adapter output and thrown errors are intentionally never returned to the agent.
64
+ const result = await adapter.use(Object.freeze({ alias: request.alias, operation: request.operation,
65
+ scope: request.scope, target: request.target }));
66
+ return { ...base, status: result?.performed === true ? 'EXECUTED' : 'BACKEND_FAILED', backend: session.backend };
67
+ } catch {
68
+ return { ...base, status: 'BACKEND_FAILED', backend: session.backend };
69
+ }
70
+ }
71
+
72
+ function revoke(sessionId) { return sessions.delete(sessionId); }
73
+ function availableBackends() { return [...supported.keys()]; }
74
+ return Object.freeze({ grant, use, revoke, availableBackends });
75
+ }
@@ -0,0 +1,152 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [string]$SkillsRoot,
4
+ [string]$ProjectPath = (Get-Location).Path
5
+ )
6
+
7
+ # Afyx Engineering Doctor (Windows PowerShell / PowerShell 7). Read-only:
8
+ # reports component health from the shared contract (scripts/components.json),
9
+ # the environment, and the current project. It never installs, repairs, or
10
+ # writes anything, and it never opens the Afyx Graph database.
11
+
12
+ Set-StrictMode -Version Latest
13
+ $ErrorActionPreference = 'Stop'
14
+
15
+ Import-Module (Join-Path $PSScriptRoot 'lib\AfyxComponents.psm1') -Force
16
+ $context = New-AfyxComponentContext -SkillsRoot $SkillsRoot
17
+ $script:Failures = 0
18
+ $script:Warnings = 0
19
+
20
+ function Write-Line([string]$State, [string]$Name, [string]$Detail = '') {
21
+ if ($State -eq 'FAIL') { $script:Failures++ }
22
+ if ($State -eq 'WARN') { $script:Warnings++ }
23
+ $suffix = if ($Detail) { " — $Detail" } else { '' }
24
+ Write-Host "[$State] $Name$suffix"
25
+ }
26
+
27
+ function Get-ToolVersion([string]$Command, [string[]]$Arguments) {
28
+ $found = Get-Command $Command -ErrorAction SilentlyContinue
29
+ if (-not $found) { return $null }
30
+ try { return ((& $found.Source @Arguments 2>$null) -join ' ').Trim() } catch { return '' }
31
+ }
32
+
33
+ # ---- Freshness: cheap local evidence only (never opens the database) --------------------
34
+ # .afyx-graph/freshness.json is written by Afyx Graph after each index/sync:
35
+ # { "schema_version": 1, "indexed_at": ISO-8601, "git_head": "<sha>"|null, "tracked_clean": true|false|null }
36
+ # The same rules as src/freshness.ts in the engine.
37
+ function Get-GraphFreshness([string]$Root) {
38
+ $stateName = if ($env:AFYX_GRAPH_DIR) { $env:AFYX_GRAPH_DIR } else { '.afyx-graph' }
39
+ $stateDirectory = Join-Path $Root $stateName
40
+ $database = Join-Path $stateDirectory 'afyx-graph.db'
41
+ if (-not (Test-Path -LiteralPath $database -PathType Leaf)) { return @{ State = 'MISSING'; Detail = 'no .afyx-graph/afyx-graph.db; run "afyx-graph init"' } }
42
+ try {
43
+ $stream = [System.IO.File]::OpenRead($database)
44
+ try { $header = New-Object byte[] 16; $read = $stream.Read($header, 0, 16) } finally { $stream.Dispose() }
45
+ } catch { return @{ State = 'INVALID'; Detail = 'database is not readable' } }
46
+ $magic = [System.Text.Encoding]::ASCII.GetString($header, 0, [Math]::Min($read, 15))
47
+ if ($read -lt 16 -or $magic -ne 'SQLite format 3') { return @{ State = 'INVALID'; Detail = 'database is not a SQLite file' } }
48
+ $metaFile = Join-Path $stateDirectory 'freshness.json'
49
+ if (-not (Test-Path -LiteralPath $metaFile -PathType Leaf)) { return @{ State = 'UNKNOWN'; Detail = 'index metadata not recorded yet; run "afyx-graph sync" with a current release' } }
50
+ try { $meta = Get-Content -Raw -LiteralPath $metaFile -Encoding utf8 | ConvertFrom-Json } catch { return @{ State = 'INVALID'; Detail = 'freshness.json is not valid JSON' } }
51
+ if (-not (Get-Command git -ErrorAction SilentlyContinue) -or -not (Test-Path -LiteralPath (Join-Path $Root '.git'))) {
52
+ return @{ State = 'UNKNOWN'; Detail = 'not a git working tree; freshness cannot be proven cheaply' }
53
+ }
54
+ $head = ((& git -C $Root rev-parse HEAD 2>$null) -join '').Trim()
55
+ $dirty = @(& git -C $Root status --porcelain --untracked-files=no 2>$null).Count -gt 0
56
+ $global:LASTEXITCODE = 0
57
+ $recorded = $meta.PSObject.Properties['git_head']
58
+ if (-not $recorded -or -not $recorded.Value) { return @{ State = 'UNKNOWN'; Detail = 'index metadata has no git head' } }
59
+ if ($head -ne [string]$recorded.Value) { return @{ State = 'STALE'; Detail = 'git HEAD changed since the last index' } }
60
+ if ($dirty) { return @{ State = 'STALE'; Detail = 'tracked files changed since the last index' } }
61
+ $clean = $meta.PSObject.Properties['tracked_clean']
62
+ if (-not $clean -or $clean.Value -ne $true) { return @{ State = 'STALE'; Detail = 'the index was built while tracked files had uncommitted changes' } }
63
+ return @{ State = 'FRESH'; Detail = 'matches git HEAD with a clean tracked tree' }
64
+ }
65
+
66
+ Write-Host 'Afyx Engineering Doctor'
67
+ $states = @{}
68
+ foreach ($state in (Get-AfyxComponentStates -Context $context)) { $states[$state.Id] = $state }
69
+
70
+ Write-Host ''
71
+ Write-Host 'CORE'
72
+ foreach ($id in @('efficient-coding', 'odoo-engineering')) {
73
+ $component = $states[$id]
74
+ if ($component.State -eq 'HEALTHY') { Write-Line 'OK' $component.Name $component.Version }
75
+ else { Write-Line 'FAIL' $component.Name "$($component.State): $($component.Detail)" }
76
+ }
77
+
78
+ Write-Host ''
79
+ Write-Host 'OPTIONAL'
80
+ $expert = $states['afyx-engineering-expert']
81
+ switch ($expert.State) {
82
+ 'HEALTHY' { Write-Line 'OK' $expert.Name $expert.Version }
83
+ 'NOT INSTALLED' { Write-Line 'INFO' $expert.Name 'not installed (optional)' }
84
+ default { Write-Line 'WARN' $expert.Name "$($expert.State): $($expert.Detail)" }
85
+ }
86
+ $graph = $states['afyx-graph']
87
+ switch ($graph.State) {
88
+ 'HEALTHY' { Write-Line 'OK' $graph.Name $graph.Version; Write-Host " State: $($graph.State)" }
89
+ 'NOT INSTALLED' { Write-Line 'INFO' $graph.Name 'not installed (optional)' }
90
+ default { Write-Line 'WARN' $graph.Name "$($graph.State): $($graph.Detail)" }
91
+ }
92
+ $usage = $states['codex-usage-tracking']
93
+ switch ($usage.State) {
94
+ 'HEALTHY' { Write-Line 'OK' $usage.Name }
95
+ 'NOT INSTALLED' { Write-Line 'INFO' $usage.Name $(if ($usage.Detail -eq 'not installed') { 'not installed (optional)' } else { $usage.Detail }) }
96
+ default { Write-Line 'WARN' $usage.Name "$($usage.State): $($usage.Detail)" }
97
+ }
98
+ Write-Host ''
99
+ Write-Host 'ENVIRONMENT'
100
+ $codexVersion = Get-ToolVersion 'codex' @('--version')
101
+ $extension = [bool](Get-ChildItem -Path (Join-Path $(if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:HOME }) '.vscode\extensions\openai.chatgpt-*') -Directory -ErrorAction SilentlyContinue | Select-Object -First 1)
102
+ if ($codexVersion) { Write-Line 'OK' 'Codex CLI' $codexVersion } else { Write-Line 'INFO' 'Codex CLI' 'not found' }
103
+ if ($extension) { Write-Line 'OK' 'VS Code extension' 'detected' } else { Write-Line 'INFO' 'VS Code extension' 'not detected' }
104
+ $antigravityVersion = Get-ToolVersion 'agy' @('--version')
105
+ if (-not $antigravityVersion) { $antigravityVersion = Get-ToolVersion 'antigravity' @('--version') }
106
+ $claudeVersion = Get-ToolVersion 'claude' @('--version')
107
+ $claudeExtension = [bool](Get-ChildItem -Path (Join-Path $(if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:HOME }) '.vscode\extensions\anthropic.claude-code-*') -Directory -ErrorAction SilentlyContinue | Select-Object -First 1)
108
+ if ($antigravityVersion) { Write-Line 'OK' 'Antigravity CLI' $antigravityVersion } else { Write-Line 'INFO' 'Antigravity CLI' 'not found (optional)' }
109
+ if ($claudeVersion -or $claudeExtension) { Write-Line 'OK' 'Claude Code host' $(if ($claudeVersion) { $claudeVersion } else { 'VS Code extension detected' }) } else { Write-Line 'INFO' 'Claude Code host' 'not found (optional)' }
110
+ if (-not $codexVersion -and -not $extension -and -not $antigravityVersion -and -not $claudeVersion -and -not $claudeExtension) {
111
+ Write-Line 'INFO' 'Provider host' 'none detected; component-only installation remains supported'
112
+ }
113
+ $gitVersion = Get-ToolVersion 'git' @('--version')
114
+ if ($gitVersion) { Write-Line 'OK' 'Git' $gitVersion } else { Write-Line 'WARN' 'Git' 'not found; required for source and freshness checks' }
115
+ $pythonVersion = Get-ToolVersion 'python' @('--version')
116
+ if (-not $pythonVersion) { $pythonVersion = Get-ToolVersion 'python3' @('--version') }
117
+ if ($pythonVersion) { Write-Line 'OK' 'Python' "$pythonVersion (optional: validators and evals)" } else { Write-Line 'INFO' 'Python' 'not found (optional: validators and evals)' }
118
+ Write-Line 'OK' 'PowerShell' "$($PSVersionTable.PSVersion) ($($context.Platform))"
119
+
120
+ Write-Host ''
121
+ Write-Host 'PROJECT'
122
+ $projectJson = & (Join-Path $PSScriptRoot 'afyx-project.ps1') -Path $ProjectPath -Format json
123
+ $project = ($projectJson -join "`n") | ConvertFrom-Json
124
+ Write-Host " Root: $($project.project_root) ($($project.root_evidence))"
125
+ if ($project.odoo.detected) {
126
+ Write-Line 'OK' 'Odoo detected'
127
+ switch ($project.odoo.version_status) {
128
+ 'proven' { Write-Line 'OK' "Version: $($project.odoo.major_version)" 'proven by source evidence' }
129
+ 'inferred' { Write-Line 'OK' "Version: $($project.odoo.major_version)" 'inferred from repository evidence; confirm before version-specific work' }
130
+ 'conflict' { Write-Line 'WARN' 'Version' 'conflicting evidence; do not guess (see afyx-project.ps1 -Format text)' }
131
+ 'unsupported' { Write-Line 'WARN' 'Version' 'outside the supported Odoo 10-20 range' }
132
+ default { Write-Line 'WARN' 'Version' 'no version evidence found' }
133
+ }
134
+ foreach ($conflict in @($project.odoo.conflicts)) { Write-Line 'WARN' 'Version evidence disagrees' "$($conflict.source) says $($conflict.major)" }
135
+ if (@($project.odoo.addon_roots).Count -gt 0) { Write-Host " Addon roots: $(@($project.odoo.addon_roots) -join ', ')" }
136
+ } else {
137
+ Write-Line 'INFO' "Project type: $($project.project_type)" 'no Odoo project detected'
138
+ }
139
+ $freshness = Get-GraphFreshness $project.project_root
140
+ switch ($freshness.State) {
141
+ 'FRESH' { Write-Line 'OK' 'Afyx Graph index: FRESH' $freshness.Detail }
142
+ 'MISSING' { Write-Line 'INFO' 'Afyx Graph index: MISSING' $freshness.Detail }
143
+ 'STALE' { Write-Line 'WARN' 'Afyx Graph index: STALE' $freshness.Detail }
144
+ 'INVALID' { Write-Line 'WARN' 'Afyx Graph index: INVALID' $freshness.Detail }
145
+ default { Write-Line 'INFO' "Afyx Graph index: $($freshness.State)" $freshness.Detail }
146
+ }
147
+
148
+ Write-Host ''
149
+ if ($script:Failures -gt 0) { Write-Host 'NOT READY'; exit 1 }
150
+ if ($script:Warnings -gt 0) { Write-Host 'READY (with warnings)'; exit 0 }
151
+ Write-Host 'READY'
152
+ exit 0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Afyx Engineering Doctor (Linux/macOS, Bash 3.2+). Read-only: reports component
5
+ # health from the shared contract (scripts/components.json), the environment,
6
+ # and the current project. It never installs, repairs, or writes anything, and
7
+ # it never opens the Afyx Graph database.
8
+
9
+ script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
10
+ project_path="$PWD"
11
+
12
+ usage() { printf '%s\n' 'Usage: scripts/afyx-doctor.sh [--skills-root PATH] [--project PATH]'; }
13
+ while (($#)); do
14
+ case "$1" in
15
+ --skills-root) skills_root="$2"; shift 2 ;;
16
+ --project) project_path="$2"; shift 2 ;;
17
+ -h|--help) usage; exit 0 ;;
18
+ *) printf 'Unknown option: %s\n' "$1" >&2; usage >&2; exit 2 ;;
19
+ esac
20
+ done
21
+
22
+ # shellcheck source=scripts/lib/afyx-components.sh
23
+ . "$script_dir/lib/afyx-components.sh"
24
+
25
+ failures=0
26
+ warnings=0
27
+ line() {
28
+ local state="$1" name="$2" detail="${3:-}"
29
+ [[ "$state" == FAIL ]] && failures=$((failures + 1))
30
+ [[ "$state" == WARN ]] && warnings=$((warnings + 1))
31
+ if [[ -n "$detail" ]]; then printf '[%s] %s — %s\n' "$state" "$name" "$detail"; else printf '[%s] %s\n' "$state" "$name"; fi
32
+ return 0
33
+ }
34
+ tool_version() { command -v "$1" >/dev/null 2>&1 || return 1; "$@" 2>/dev/null | head -n 1 || true; }
35
+
36
+ # ---- Freshness: cheap local evidence only (never opens the database) -------------------
37
+ # .afyx-graph/freshness.json is written by Afyx Graph after each index/sync:
38
+ # { "schema_version": 1, "indexed_at": ISO-8601, "git_head": "<sha>"|null, "tracked_clean": true|false|null }
39
+ # The same rules as src/freshness.ts in the engine.
40
+ graph_freshness() {
41
+ local root="$1" state_dir="$1/${AFYX_GRAPH_DIR:-.afyx-graph}" db meta head recorded
42
+ db="$state_dir/afyx-graph.db"; meta="$state_dir/freshness.json"
43
+ if [[ ! -f "$db" ]]; then FRESH_STATE=MISSING; FRESH_DETAIL='no .afyx-graph/afyx-graph.db; run "afyx-graph init"'; return 0; fi
44
+ if [[ "$(LC_ALL=C head -c 15 "$db" 2>/dev/null || true)" != 'SQLite format 3' ]]; then FRESH_STATE=INVALID; FRESH_DETAIL='database is not a SQLite file'; return 0; fi
45
+ if [[ ! -f "$meta" ]]; then FRESH_STATE=UNKNOWN; FRESH_DETAIL='index metadata not recorded yet; run "afyx-graph sync" with a current release'; return 0; fi
46
+ if ! grep -q '"schema_version"' "$meta"; then FRESH_STATE=INVALID; FRESH_DETAIL='freshness.json is not valid'; return 0; fi
47
+ if ! command -v git >/dev/null 2>&1 || [[ ! -e "$root/.git" ]]; then FRESH_STATE=UNKNOWN; FRESH_DETAIL='not a git working tree; freshness cannot be proven cheaply'; return 0; fi
48
+ recorded="$(sed -n 's/.*"git_head"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$meta" | head -n 1)"
49
+ if [[ -z "$recorded" ]]; then FRESH_STATE=UNKNOWN; FRESH_DETAIL='index metadata has no git head'; return 0; fi
50
+ head="$(git -C "$root" rev-parse HEAD 2>/dev/null || true)"
51
+ if [[ "$head" != "$recorded" ]]; then FRESH_STATE=STALE; FRESH_DETAIL='git HEAD changed since the last index'; return 0; fi
52
+ if [[ -n "$(git -C "$root" status --porcelain --untracked-files=no 2>/dev/null || true)" ]]; then FRESH_STATE=STALE; FRESH_DETAIL='tracked files changed since the last index'; return 0; fi
53
+ if ! grep -Eq '"tracked_clean"[[:space:]]*:[[:space:]]*true' "$meta"; then FRESH_STATE=STALE; FRESH_DETAIL='the index was built while tracked files had uncommitted changes'; return 0; fi
54
+ FRESH_STATE=FRESH; FRESH_DETAIL='matches git HEAD with a clean tracked tree'
55
+ }
56
+
57
+ printf 'Afyx Engineering Doctor\n'
58
+
59
+ printf '\nCORE\n'
60
+ for id in efficient-coding odoo-engineering; do
61
+ afyx_component_evaluate "$id"
62
+ name="$(afyx_component_field "$id" name)"
63
+ if [[ "$AFYX_STATE" == HEALTHY ]]; then line OK "$name" "$AFYX_VERSION"; else line FAIL "$name" "$AFYX_STATE: $AFYX_DETAIL"; fi
64
+ done
65
+
66
+ printf '\nOPTIONAL\n'
67
+ afyx_component_evaluate afyx-engineering-expert
68
+ case "$AFYX_STATE" in
69
+ HEALTHY) line OK 'Afyx Engineering Expert' "$AFYX_VERSION" ;;
70
+ 'NOT INSTALLED') line INFO 'Afyx Engineering Expert' 'not installed (optional)' ;;
71
+ *) line WARN 'Afyx Engineering Expert' "$AFYX_STATE: $AFYX_DETAIL" ;;
72
+ esac
73
+ afyx_component_evaluate afyx-graph
74
+ case "$AFYX_STATE" in
75
+ HEALTHY) line OK 'Afyx Graph' "$AFYX_VERSION"; printf ' State: %s\n' "$AFYX_STATE" ;;
76
+ 'NOT INSTALLED') line INFO 'Afyx Graph' 'not installed (optional)' ;;
77
+ *) line WARN 'Afyx Graph' "$AFYX_STATE: $AFYX_DETAIL" ;;
78
+ esac
79
+ afyx_component_evaluate codex-usage-tracking
80
+ case "$AFYX_STATE" in
81
+ HEALTHY) line OK 'Codex Usage Tracking' ;;
82
+ 'NOT INSTALLED') if [[ "$AFYX_DETAIL" == 'not installed' ]]; then line INFO 'Codex Usage Tracking' 'not installed (optional)'; else line INFO 'Codex Usage Tracking' "$AFYX_DETAIL"; fi ;;
83
+ *) line WARN 'Codex Usage Tracking' "$AFYX_STATE: $AFYX_DETAIL" ;;
84
+ esac
85
+ printf '\nENVIRONMENT\n'
86
+ codex_version="$(tool_version codex --version || true)"
87
+ extension_detected=false
88
+ for extension in "$HOME"/.vscode/extensions/openai.chatgpt-*; do [[ -d "$extension" ]] && { extension_detected=true; break; }; done
89
+ if [[ -n "$codex_version" ]]; then line OK 'Codex CLI' "$codex_version"; else line INFO 'Codex CLI' 'not found'; fi
90
+ if "$extension_detected"; then line OK 'VS Code extension' 'detected'; else line INFO 'VS Code extension' 'not detected'; fi
91
+ antigravity_version="$(tool_version agy --version || tool_version antigravity --version || true)"
92
+ claude_version="$(tool_version claude --version || true)"
93
+ claude_extension=false
94
+ for extension in "$HOME"/.vscode/extensions/anthropic.claude-code-* "$HOME"/.vscode-server/extensions/anthropic.claude-code-*; do [[ -d "$extension" ]] && { claude_extension=true; break; }; done
95
+ if [[ -n "$antigravity_version" ]]; then line OK 'Antigravity CLI' "$antigravity_version"; else line INFO 'Antigravity CLI' 'not found (optional)'; fi
96
+ if [[ -n "$claude_version" ]]; then line OK 'Claude Code host' "$claude_version"; elif "$claude_extension"; then line OK 'Claude Code host' 'VS Code extension detected'; else line INFO 'Claude Code host' 'not found (optional)'; fi
97
+ if [[ -z "$codex_version" ]] && ! "$extension_detected" && [[ -z "$antigravity_version" && -z "$claude_version" ]] && ! "$claude_extension"; then
98
+ line INFO 'Provider host' 'none detected; component-only installation remains supported'
99
+ fi
100
+ git_version="$(tool_version git --version || true)"
101
+ if [[ -n "$git_version" ]]; then line OK 'Git' "$git_version"; else line WARN 'Git' 'not found; required for source and freshness checks'; fi
102
+ python_version="$(tool_version python3 --version || tool_version python --version || true)"
103
+ if [[ -n "$python_version" ]]; then line OK 'Python' "$python_version (optional: validators and evals)"; else line INFO 'Python' 'not found (optional: validators and evals)'; fi
104
+ line OK 'Bash' "${BASH_VERSION:-unknown} ($(afyx_platform))"
105
+
106
+ printf '\nPROJECT\n'
107
+ project_json="$(bash "$script_dir/afyx-project.sh" --path "$project_path" --format json)"
108
+ jget() { printf '%s' "$project_json" | grep -Eo "\"$1\":(\"[^\"]*\"|[^,}]*)" | head -n 1 | sed -E "s/^\"$1\"://; s/^\"//; s/\"$//"; }
109
+ project_root="$(jget project_root)"
110
+ printf ' Root: %s (%s)\n' "$project_root" "$(jget root_evidence)"
111
+ if [[ "$(jget detected)" == true ]]; then
112
+ line OK 'Odoo detected'
113
+ major="$(jget major_version)"
114
+ case "$(jget version_status)" in
115
+ proven) line OK "Version: $major" 'proven by source evidence' ;;
116
+ inferred) line OK "Version: $major" 'inferred from repository evidence; confirm before version-specific work' ;;
117
+ conflict) line WARN 'Version' 'conflicting evidence; do not guess (see scripts/afyx-project.sh --format text)' ;;
118
+ unsupported) line WARN 'Version' 'outside the supported Odoo 10-20 range' ;;
119
+ *) line WARN 'Version' 'no version evidence found' ;;
120
+ esac
121
+ conflicts="$(printf '%s' "$project_json" | sed -E 's/.*"conflicts":\[([^]]*)\].*/\1/' | grep -Eo '\{"source":"[^"]*","major":[0-9]+\}' || true)"
122
+ if [[ -n "$conflicts" ]]; then
123
+ printf '%s\n' "$conflicts" | while IFS= read -r item; do
124
+ source="$(printf '%s' "$item" | sed -E 's/.*"source":"([^"]*)".*/\1/')"; other="$(printf '%s' "$item" | sed -E 's/.*"major":([0-9]+).*/\1/')"
125
+ printf '[WARN] Version evidence disagrees — %s says %s\n' "$source" "$other"
126
+ done
127
+ warnings=$((warnings + $(printf '%s\n' "$conflicts" | grep -c .)))
128
+ fi
129
+ roots="$(printf '%s' "$project_json" | sed -E 's/.*"addon_roots":\[([^]]*)\].*/\1/' | tr -d '"' | sed 's/,/, /g')"
130
+ [[ -n "$roots" ]] && printf ' Addon roots: %s\n' "$roots"
131
+ else
132
+ line INFO "Project type: $(jget project_type)" 'no Odoo project detected'
133
+ fi
134
+ graph_freshness "$project_root"
135
+ case "$FRESH_STATE" in
136
+ FRESH) line OK 'Afyx Graph index: FRESH' "$FRESH_DETAIL" ;;
137
+ MISSING) line INFO 'Afyx Graph index: MISSING' "$FRESH_DETAIL" ;;
138
+ STALE) line WARN 'Afyx Graph index: STALE' "$FRESH_DETAIL" ;;
139
+ INVALID) line WARN 'Afyx Graph index: INVALID' "$FRESH_DETAIL" ;;
140
+ *) line INFO "Afyx Graph index: $FRESH_STATE" "$FRESH_DETAIL" ;;
141
+ esac
142
+
143
+ printf '\n'
144
+ if ((failures > 0)); then printf 'NOT READY\n'; exit 1; fi
145
+ if ((warnings > 0)); then printf 'READY (with warnings)\n'; exit 0; fi
146
+ printf 'READY\n'
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Afyx Forge Core — Deterministic Release Artifact & Integrity Stager
4
+ *
5
+ * Stages a self-contained Afyx Forge Core runtime bundle into <stage>/current,
6
+ * creates top-level bin launchers (<stage>/bin/afyx-forge and afyx-forge.cmd),
7
+ * writes <stage>/current/identity.json and <stage>/metadata.json bound to the
8
+ * exact source revision and artifact digest, and emits <stage>/integrity.sha256.
9
+ */
10
+
11
+ import crypto from "node:crypto";
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+
15
+ function parseArgs(argv) {
16
+ const out = {};
17
+ for (let i = 0; i < argv.length; i += 1) {
18
+ const token = argv[i];
19
+ if (!token.startsWith("--")) continue;
20
+ const key = token.slice(2);
21
+ const next = argv[i + 1];
22
+ if (next !== undefined && !next.startsWith("--")) {
23
+ out[key] = next;
24
+ i += 1;
25
+ } else {
26
+ out[key] = "true";
27
+ }
28
+ }
29
+ return out;
30
+ }
31
+
32
+ function sha256File(filePath) {
33
+ const hash = crypto.createHash("sha256");
34
+ hash.update(fs.readFileSync(filePath));
35
+ return hash.digest("hex");
36
+ }
37
+
38
+ function copyTree(src, dst) {
39
+ fs.mkdirSync(dst, { recursive: true });
40
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
41
+ const srcPath = path.join(src, entry.name);
42
+ const dstPath = path.join(dst, entry.name);
43
+ const stat = fs.lstatSync(srcPath);
44
+ if (stat.isSymbolicLink()) {
45
+ throw new Error(`Refusing to package symbolic link in Afyx Forge artifact: ${srcPath}`);
46
+ }
47
+ if (entry.isDirectory()) {
48
+ copyTree(srcPath, dstPath);
49
+ } else if (entry.isFile()) {
50
+ fs.copyFileSync(srcPath, dstPath);
51
+ }
52
+ }
53
+ }
54
+
55
+ function collectFiles(root, prefix = "") {
56
+ const files = [];
57
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
58
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
59
+ const full = path.join(root, entry.name);
60
+ if (entry.isDirectory()) {
61
+ files.push(...collectFiles(full, rel));
62
+ } else if (entry.isFile()) {
63
+ files.push(rel);
64
+ }
65
+ }
66
+ return files.sort();
67
+ }
68
+
69
+ const args = parseArgs(process.argv.slice(2));
70
+ const sourceRoot = path.resolve(args["source-root"] || "");
71
+ const stageDir = path.resolve(args["stage-dir"] || "");
72
+ const runtimeRoot = args["runtime-root"] ? path.resolve(args["runtime-root"]) : stageDir;
73
+ const revision = args.revision || "unknown";
74
+ const provenance = args.provenance || "LOCAL_SOURCE_CLEAN";
75
+ const installedAt = args["installed-at"] || new Date().toISOString();
76
+
77
+ if (!args["source-root"] || !args["stage-dir"]) {
78
+ console.error(
79
+ "Usage: node scripts/afyx-forge-artifact.mjs --source-root <dir> --stage-dir <dir> [--runtime-root <dir>] [--revision <sha>] [--provenance <tag>] [--installed-at <iso>]"
80
+ );
81
+ process.exit(2);
82
+ }
83
+
84
+ const manifestPath = path.join(sourceRoot, "afyx-forge.json");
85
+ const packagePath = path.join(sourceRoot, "package.json");
86
+ const licensePath = path.join(sourceRoot, "LICENSE");
87
+ if (!fs.existsSync(manifestPath) || !fs.existsSync(packagePath) || !fs.existsSync(licensePath)) {
88
+ console.error(`Missing Afyx Forge source manifests or LICENSE in ${sourceRoot}`);
89
+ process.exit(2);
90
+ }
91
+
92
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
93
+ const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"));
94
+
95
+ const licenseText = fs.readFileSync(licensePath, "utf8");
96
+ if (
97
+ pkg.license !== "Apache-2.0" ||
98
+ sha256File(licensePath) !== "2b6d9feeccd4b2fe06c3530972b136d0448b3be163b62fc7bf22355419fdd881" ||
99
+ !licenseText.includes("Apache License") ||
100
+ !licenseText.includes("Version 2.0, January 2004") ||
101
+ !licenseText.includes("END OF TERMS AND CONDITIONS")
102
+ ) {
103
+ console.error("Afyx Forge package must include the complete Apache-2.0 license.");
104
+ process.exit(2);
105
+ }
106
+
107
+ if (manifest.product_name !== "Afyx Forge Core" || manifest.product_version !== pkg.version) {
108
+ console.error("Afyx Forge manifest and package.json version/identity mismatch.");
109
+ process.exit(2);
110
+ }
111
+ if (
112
+ manifest.component_id !== "afyx-forge" ||
113
+ manifest.runtime_mode !== "ASSISTIVE_GUIDANCE_ONLY" ||
114
+ manifest.evaluation_gate?.status !== "EVALUATION_GATED" ||
115
+ manifest.evaluation_gate?.autonomous_code_execution !== false
116
+ ) {
117
+ console.error("Afyx Forge manifest violates bounded assistive-guidance governance invariants.");
118
+ process.exit(2);
119
+ }
120
+
121
+ const currentDir = path.join(stageDir, "current");
122
+ const binDir = path.join(stageDir, "bin");
123
+ fs.mkdirSync(currentDir, { recursive: true });
124
+ fs.mkdirSync(binDir, { recursive: true });
125
+
126
+ fs.copyFileSync(packagePath, path.join(currentDir, "package.json"));
127
+ fs.copyFileSync(manifestPath, path.join(currentDir, "afyx-forge.json"));
128
+ fs.copyFileSync(licensePath, path.join(currentDir, "LICENSE"));
129
+ copyTree(path.join(sourceRoot, "contracts"), path.join(currentDir, "contracts"));
130
+ copyTree(path.join(sourceRoot, "src"), path.join(currentDir, "src"));
131
+ copyTree(path.join(sourceRoot, "bin"), path.join(currentDir, "bin"));
132
+
133
+ const currentUnixBin = path.join(currentDir, "bin", "afyx-forge");
134
+ if (fs.existsSync(currentUnixBin)) {
135
+ fs.chmodSync(currentUnixBin, 0o755);
136
+ }
137
+
138
+ const identity = {
139
+ product_name: manifest.product_name,
140
+ product_version: manifest.product_version,
141
+ component_id: manifest.component_id,
142
+ source_revision: revision,
143
+ ownership_class: "AFYX",
144
+ build_provenance: provenance,
145
+ release_channel: manifest.distribution_channel || "technical-alpha",
146
+ runtime_mode: manifest.runtime_mode,
147
+ governance_state: manifest.evaluation_gate.status,
148
+ };
149
+ fs.writeFileSync(path.join(currentDir, "identity.json"), `${JSON.stringify(identity, null, 2)}\n`, "utf8");
150
+
151
+ const files = collectFiles(currentDir);
152
+ const checksumLines = files.map((rel) => `${sha256File(path.join(currentDir, rel))} current/${rel}`);
153
+ const integrityPath = path.join(stageDir, "integrity.sha256");
154
+ fs.writeFileSync(integrityPath, `${checksumLines.join("\n")}\n`, "utf8");
155
+
156
+ const artifactDigest = sha256File(integrityPath);
157
+
158
+ const topCmdWrapper = `@echo off\r\nnode "%~dp0..\\current\\bin\\afyx-forge.js" %*\r\n`;
159
+ fs.writeFileSync(path.join(binDir, "afyx-forge.cmd"), topCmdWrapper, "ascii");
160
+
161
+ const topShWrapper = `#!/usr/bin/env bash\nDIR="$(cd "$(dirname "\${BASH_SOURCE[0]}")" && pwd)"\nexec node "$DIR/../current/bin/afyx-forge.js" "$@"\n`;
162
+ const topShPath = path.join(binDir, "afyx-forge");
163
+ fs.writeFileSync(topShPath, topShWrapper, "utf8");
164
+ fs.chmodSync(topShPath, 0o755);
165
+
166
+ const metadata = {
167
+ schema_version: 1,
168
+ product_name: manifest.product_name,
169
+ product_version: manifest.product_version,
170
+ component_id: manifest.component_id,
171
+ ownership_class: "AFYX",
172
+ distribution_channel: manifest.distribution_channel || "technical-alpha",
173
+ release_channel: manifest.distribution_channel || "technical-alpha",
174
+ runtime_mode: manifest.runtime_mode,
175
+ governance_state: manifest.evaluation_gate.status,
176
+ source_revision: revision,
177
+ build_provenance: provenance,
178
+ artifact_digest: artifactDigest,
179
+ installed_at: installedAt,
180
+ runtime_root: runtimeRoot,
181
+ };
182
+ fs.writeFileSync(path.join(stageDir, "metadata.json"), `${JSON.stringify(metadata, null, 2)}\n`, "utf8");
183
+
@@ -0,0 +1,12 @@
1
+ # Afyx adaptive tool routing — global
2
+
3
+ Use the lowest-cost reliable evidence path for each task. Afyx is preferred **when a matching capability materially helps**, not called automatically because it is installed.
4
+
5
+ 1. **Understand task scope first.** For a known file, exact symbol, simple edit, config lookup or localized debugging, use direct source reads, `rg` or focused tests. Avoid Graph, Context and other tool calls when direct source is sufficient.
6
+ 2. **Use a specialist only for measurable value.** For cross-file relationships, inheritance, dependency/impact analysis, uncertain code navigation or large context selection, consider a matching tool. For complex multi-domain engineering use a relevant Afyx skill/expert if it helps; do not force every Afyx component into every task.
7
+ 3. **Afyx-family first, per capability and active provider surface.** When needed, prefer a verified installed, enabled, authorized, reachable, healthy, fresh, task-compatible Afyx capability (for example Afyx Graph for relationship analysis). Never assume the CLI, IDE and MCP surfaces have identical registrations or permissions. Validate source/index freshness; source files remain authoritative.
8
+ 4. **Controlled external fallback.** If no suitable Afyx capability is usable, an independently installed external equivalent may be used only when its exact CLI/MCP/IDE surface and fallback are independently permitted. Disabled MCP never implies permission to call an external CLI or wrapper. Do not auto-install, re-enable, change credentials, modify indices or bypass an explicit denial.
9
+ 5. **Choose minimal work.** Avoid redundant tool calls, blanket indexing, duplicate scans, irrelevant experts and unnecessary context injection. If native or external tools are unsuitable, continue with direct source and disclose any material coverage limitation.
10
+ 6. **Honor precedence and ownership.** Keep workspace-specific business rules, user permissions, safety constraints and higher-priority instructions intact. Treat legacy external index folders or binaries on PATH as availability hints, never as higher routing priority than suitable Afyx tools.
11
+
12
+ This is a provider-neutral routing preference, not authorization for mutation, expenditure, installation or privileged access.