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,205 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [string]$Path = (Get-Location).Path,
4
+ [ValidateSet('json', 'text')][string]$Format = 'json',
5
+ [switch]$AllowExec,
6
+ [switch]$WriteCache
7
+ )
8
+
9
+ # Zero-model project context detector (read-only unless -WriteCache is passed).
10
+ # Detects project root, project type, Odoo major version with its evidence, and
11
+ # likely addon roots. Evidence priority mirrors the Odoo Engineering skill:
12
+ # strong: odoo/release.py > odoo.egg-info/PKG-INFO > odoo-bin --version (opt-in)
13
+ # weak: git branch/tag > __manifest__.py versions > dependency files
14
+ # Conflicting evidence is reported, never guessed. The optional
15
+ # .afyx/project.json cache is a hint only; runtime/source evidence always wins.
16
+
17
+ Set-StrictMode -Version Latest
18
+ $ErrorActionPreference = 'Stop'
19
+
20
+ $SupportedMin = 10
21
+ $SupportedMax = 20
22
+ $SkipDirectories = @('.git', 'node_modules', '.venv', 'venv', '__pycache__', '.tox', 'dist', 'build', '.afyx-graph')
23
+ $ManifestCap = 200
24
+
25
+ function Read-Text([string]$File) {
26
+ try { return [System.IO.File]::ReadAllText($File) } catch { return '' }
27
+ }
28
+
29
+ function Test-InRange([int]$Major) { return ($Major -ge $SupportedMin -and $Major -le $SupportedMax) }
30
+
31
+ function Find-Root([string]$Start) {
32
+ # Nearest ancestor (including the start directory) carrying a root marker wins.
33
+ $current = (Resolve-Path -LiteralPath $Start).Path
34
+ $cursor = $current
35
+ while ($cursor) {
36
+ if (Test-Path -LiteralPath (Join-Path $cursor '.git')) { return @{ Root = $cursor; Evidence = '.git' } }
37
+ if ((Test-Path -LiteralPath (Join-Path $cursor 'odoo\release.py')) -or (Test-Path -LiteralPath (Join-Path $cursor 'odoo-bin'))) {
38
+ return @{ Root = $cursor; Evidence = 'odoo-source' }
39
+ }
40
+ $parent = Split-Path -Parent $cursor
41
+ if (-not $parent -or $parent -eq $cursor) { break }
42
+ $cursor = $parent
43
+ }
44
+ return @{ Root = $current; Evidence = 'start-directory' }
45
+ }
46
+
47
+ function Get-Manifests([string]$Root) {
48
+ $found = New-Object System.Collections.Generic.List[object]
49
+ $stack = New-Object System.Collections.Generic.Stack[object]
50
+ $stack.Push(@($Root, 0, ''))
51
+ while ($stack.Count -gt 0 -and $found.Count -lt $ManifestCap) {
52
+ $item = $stack.Pop(); $directory = $item[0]; $depth = $item[1]; $relativeDirectory = $item[2]
53
+ $manifest = Join-Path $directory '__manifest__.py'
54
+ if (Test-Path -LiteralPath $manifest -PathType Leaf) {
55
+ $found.Add([pscustomobject]@{ Path = $manifest; RelativeDirectory = $relativeDirectory })
56
+ }
57
+ if ($depth -ge 4) { continue }
58
+ foreach ($child in (Get-ChildItem -LiteralPath $directory -Directory -Force -ErrorAction SilentlyContinue | Sort-Object Name)) {
59
+ if ($SkipDirectories -contains $child.Name) { continue }
60
+ $childRelative = if ($relativeDirectory) { Join-Path $relativeDirectory $child.Name } else { $child.Name }
61
+ $stack.Push(@($child.FullName, ($depth + 1), $childRelative))
62
+ }
63
+ }
64
+ return $found
65
+ }
66
+
67
+ $located = Find-Root $Path
68
+ $root = $located.Root
69
+ $evidence = New-Object System.Collections.Generic.List[object]
70
+
71
+ # 1. odoo/release.py (strong)
72
+ $releaseFile = Join-Path $root 'odoo\release.py'
73
+ if (Test-Path -LiteralPath $releaseFile -PathType Leaf) {
74
+ $match = [regex]::Match((Read-Text $releaseFile), "version_info\s*=\s*\(\s*['""]?(?:saas~)?(\d+)")
75
+ if ($match.Success) { $evidence.Add([ordered]@{ source = 'odoo/release.py'; strength = 'strong'; major = [int]$match.Groups[1].Value; count = 1; priority = 1 }) }
76
+ }
77
+ # 2. release metadata (strong)
78
+ $pkgInfo = Join-Path $root 'odoo.egg-info\PKG-INFO'
79
+ if (Test-Path -LiteralPath $pkgInfo -PathType Leaf) {
80
+ $match = [regex]::Match((Read-Text $pkgInfo), '(?m)^Version:\s*(\d+)\.')
81
+ if ($match.Success) { $evidence.Add([ordered]@{ source = 'odoo.egg-info/PKG-INFO'; strength = 'strong'; major = [int]$match.Groups[1].Value; count = 1; priority = 2 }) }
82
+ }
83
+ # 3. odoo-bin --version (strong, executes project code: opt-in only)
84
+ $odooBin = Join-Path $root 'odoo-bin'
85
+ if ($AllowExec -and (Test-Path -LiteralPath $odooBin -PathType Leaf)) {
86
+ $python = Get-Command python -ErrorAction SilentlyContinue
87
+ if (-not $python) { $python = Get-Command python3 -ErrorAction SilentlyContinue }
88
+ if ($python) {
89
+ try {
90
+ $output = (& $python.Source $odooBin --version 2>$null) -join ' '
91
+ $match = [regex]::Match($output, 'Odoo Server\s+(?:saas~)?(\d+)')
92
+ if ($match.Success) { $evidence.Add([ordered]@{ source = 'odoo-bin --version'; strength = 'strong'; major = [int]$match.Groups[1].Value; count = 1; priority = 3 }) }
93
+ } catch { }
94
+ }
95
+ }
96
+ # 4. git branch / tag (weak)
97
+ if ($located.Evidence -eq '.git' -and (Get-Command git -ErrorAction SilentlyContinue)) {
98
+ $pattern = '(?<![0-9.])(1[0-9]|20)\.0(?![0-9])'
99
+ $branch = (& git -C $root symbolic-ref --short -q HEAD 2>$null) -join ''
100
+ $match = [regex]::Match($branch, $pattern)
101
+ if ($match.Success) { $evidence.Add([ordered]@{ source = 'git branch'; strength = 'weak'; major = [int]$match.Groups[1].Value; count = 1; priority = 4 }) }
102
+ else {
103
+ $tag = (& git -C $root describe --tags --abbrev=0 2>$null) -join ''
104
+ $match = [regex]::Match($tag, $pattern)
105
+ if ($match.Success) { $evidence.Add([ordered]@{ source = 'git tag'; strength = 'weak'; major = [int]$match.Groups[1].Value; count = 1; priority = 4 }) }
106
+ }
107
+ }
108
+ $global:LASTEXITCODE = 0 # `git describe` legitimately fails when there are no tags
109
+ # 5. __manifest__.py module versions (weak) and addon roots
110
+ $manifests = @(Get-Manifests $root)
111
+ $manifestMajors = @{}
112
+ $addonRoots = New-Object System.Collections.Generic.SortedSet[string] ([System.StringComparer]::Ordinal)
113
+ foreach ($manifest in $manifests) {
114
+ $relativeContainer = [IO.Path]::GetDirectoryName([string]$manifest.RelativeDirectory)
115
+ [void]$addonRoots.Add($(if ($relativeContainer) { $relativeContainer -replace '\\', '/' } else { '.' }))
116
+ $match = [regex]::Match((Read-Text $manifest.Path), "['""]version['""]\s*:\s*['""](\d{2})\.0\.\d+\.\d+\.\d+['""]")
117
+ if ($match.Success -and (Test-InRange ([int]$match.Groups[1].Value))) {
118
+ $major = [int]$match.Groups[1].Value
119
+ $manifestMajors[$major] = 1 + $(if ($manifestMajors.ContainsKey($major)) { $manifestMajors[$major] } else { 0 })
120
+ }
121
+ }
122
+ foreach ($major in ($manifestMajors.Keys | Sort-Object)) {
123
+ $evidence.Add([ordered]@{ source = '__manifest__.py'; strength = 'weak'; major = [int]$major; count = [int]$manifestMajors[$major]; priority = 5 })
124
+ }
125
+ # 6. dependency files (weak)
126
+ foreach ($name in @('requirements.txt', 'pyproject.toml', 'Dockerfile', 'docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml')) {
127
+ $file = Join-Path $root $name
128
+ if (-not (Test-Path -LiteralPath $file -PathType Leaf)) { continue }
129
+ $text = Read-Text $file
130
+ $majors = @{}
131
+ foreach ($pattern in @('(?im)^\s*odoo\s*(?:==|~=|>=)\s*(\d{2})\.0', '(?i)image:\s*[''"]?odoo:(\d{2})(?:\.0)?', '(?im)^\s*FROM\s+odoo:(\d{2})', '(?i)\bodoo(?:/odoo)?(?:\.git)?@(\d{2})\.0')) {
132
+ foreach ($m in [regex]::Matches($text, $pattern)) { $majors[[int]$m.Groups[1].Value] = 1 }
133
+ }
134
+ foreach ($major in ($majors.Keys | Sort-Object)) {
135
+ if (Test-InRange $major) { $evidence.Add([ordered]@{ source = $name; strength = 'weak'; major = [int]$major; count = 1; priority = 6 }) }
136
+ }
137
+ }
138
+
139
+ # Resolve
140
+ $strong = @($evidence | Where-Object { $_.strength -eq 'strong' } | ForEach-Object { $_.major } | Sort-Object -Unique)
141
+ $weak = @($evidence | Where-Object { $_.strength -eq 'weak' } | ForEach-Object { $_.major } | Sort-Object -Unique)
142
+ $resolved = $null; $status = 'unknown'
143
+ if ($strong.Count -eq 1) { $resolved = [int]$strong[0]; $status = 'proven' }
144
+ elseif ($strong.Count -gt 1) { $status = 'conflict' }
145
+ elseif ($weak.Count -eq 1) { $resolved = [int]$weak[0]; $status = 'inferred' }
146
+ elseif ($weak.Count -gt 1) { $status = 'conflict' }
147
+ if ($null -ne $resolved -and -not (Test-InRange $resolved)) { $status = 'unsupported' }
148
+ $conflicts = @()
149
+ if ($status -eq 'proven') { $conflicts = @($evidence | Where-Object { $_.strength -eq 'weak' -and $_.major -ne $resolved } | ForEach-Object { [ordered]@{ source = $_.source; major = $_.major } }) }
150
+ $odooDetected = ($evidence.Count -gt 0) -or ($manifests.Count -gt 0) -or (Test-Path -LiteralPath $odooBin -PathType Leaf) -or (Test-Path -LiteralPath $releaseFile -PathType Leaf)
151
+
152
+ $projectType = 'unknown'
153
+ if ($odooDetected) { $projectType = 'odoo' }
154
+ elseif ((Test-Path -LiteralPath (Join-Path $root 'pyproject.toml')) -or (Test-Path -LiteralPath (Join-Path $root 'setup.py')) -or (Test-Path -LiteralPath (Join-Path $root 'requirements.txt'))) { $projectType = 'python' }
155
+ elseif (Test-Path -LiteralPath (Join-Path $root 'package.json')) { $projectType = 'node' }
156
+
157
+ # Optional cache (hint only)
158
+ $cachePath = Join-Path $root '.afyx\project.json'
159
+ $cachePresent = Test-Path -LiteralPath $cachePath -PathType Leaf
160
+ $hint = $null; $agrees = $null
161
+ if ($cachePresent) {
162
+ try {
163
+ $cache = Get-Content -Raw -LiteralPath $cachePath -Encoding utf8 | ConvertFrom-Json
164
+ $property = $cache.PSObject.Properties['odoo_major']
165
+ if ($property) { $hint = [int]$property.Value }
166
+ } catch { }
167
+ if ($null -ne $hint -and $null -ne $resolved) { $agrees = ($hint -eq $resolved) }
168
+ }
169
+
170
+ $sortedEvidence = @($evidence | Sort-Object { $_.priority }, { $_.source }, { $_.major } | ForEach-Object { [ordered]@{ source = $_.source; strength = $_.strength; major = $_.major; count = $_.count } })
171
+ $result = [ordered]@{
172
+ schema_version = 1
173
+ project_root = $root
174
+ root_evidence = $located.Evidence
175
+ project_type = $projectType
176
+ odoo = [ordered]@{
177
+ detected = [bool]$odooDetected
178
+ supported_range = "$SupportedMin-$SupportedMax"
179
+ major_version = $resolved
180
+ version_status = $status
181
+ evidence = $sortedEvidence
182
+ conflicts = @($conflicts)
183
+ addon_roots = @($addonRoots | Select-Object -First 20)
184
+ }
185
+ cache = [ordered]@{ path = '.afyx/project.json'; present = [bool]$cachePresent; hint_major = $hint; agrees = $agrees }
186
+ }
187
+
188
+ if ($WriteCache) {
189
+ $cacheDirectory = Split-Path -Parent $cachePath
190
+ New-Item -ItemType Directory -Force -Path $cacheDirectory | Out-Null
191
+ $hintDocument = [ordered]@{ note = 'Hint only. Source and runtime evidence always win.'; odoo_major = $resolved; version_status = $status }
192
+ Set-Content -LiteralPath $cachePath -Value ($hintDocument | ConvertTo-Json) -Encoding utf8
193
+ }
194
+
195
+ if ($Format -eq 'json') { $result | ConvertTo-Json -Depth 8; return }
196
+
197
+ Write-Output "Project root: $root ($($located.Evidence))"
198
+ Write-Output "Project type: $projectType"
199
+ if ($odooDetected) {
200
+ $versionText = if ($null -ne $resolved) { "version $resolved ($status)" } else { "version $status" }
201
+ Write-Output "Odoo: detected; $versionText"
202
+ foreach ($item in $sortedEvidence) { Write-Output " evidence: $($item.source) = $($item.major) [$($item.strength)]" }
203
+ foreach ($item in $conflicts) { Write-Output " conflict: $($item.source) = $($item.major)" }
204
+ if ($addonRoots.Count -gt 0) { Write-Output " addon roots: $(@($addonRoots | Select-Object -First 20) -join ', ')" }
205
+ } else { Write-Output 'Odoo: not detected' }
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Zero-model project context detector (read-only unless --write-cache is passed).
5
+ # Detects project root, project type, Odoo major version with its evidence, and
6
+ # likely addon roots. Evidence priority mirrors the Odoo Engineering skill:
7
+ # strong: odoo/release.py > odoo.egg-info/PKG-INFO > odoo-bin --version (opt-in)
8
+ # weak: git branch/tag > __manifest__.py versions > dependency files
9
+ # Conflicting evidence is reported, never guessed. The optional
10
+ # .afyx/project.json cache is a hint only; runtime/source evidence always wins.
11
+ # Bash 3.2 compatible (macOS): no associative arrays, no mapfile.
12
+
13
+ path="$PWD"
14
+ format=json
15
+ allow_exec=false
16
+ write_cache=false
17
+ SUPPORTED_MIN=10
18
+ SUPPORTED_MAX=20
19
+ MANIFEST_CAP=200
20
+ TAB="$(printf '\t')"
21
+
22
+ usage() { printf '%s\n' 'Usage: afyx-project.sh [--path DIR] [--format json|text] [--allow-exec] [--write-cache]'; }
23
+ while (($#)); do
24
+ case "$1" in
25
+ --path) path="$2"; shift 2 ;;
26
+ --format) format="$2"; shift 2 ;;
27
+ --allow-exec) allow_exec=true; shift ;;
28
+ --write-cache) write_cache=true; shift ;;
29
+ -h|--help) usage; exit 0 ;;
30
+ *) printf 'Unknown option: %s\n' "$1" >&2; usage >&2; exit 2 ;;
31
+ esac
32
+ done
33
+ [[ "$format" == json || "$format" == text ]] || { printf 'Invalid --format: %s\n' "$format" >&2; exit 2; }
34
+
35
+ in_range() { (($1 >= SUPPORTED_MIN && $1 <= SUPPORTED_MAX)); }
36
+ json_escape() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'; }
37
+ first_number() { grep -Eo '[0-9]+' | head -n 1; }
38
+
39
+ # Nearest ancestor (including the start directory) carrying a root marker wins.
40
+ start="$(cd -- "$path" && pwd)"
41
+ root="$start"; root_evidence=start-directory
42
+ cursor="$start"
43
+ while :; do
44
+ if [[ -e "$cursor/.git" ]]; then root="$cursor"; root_evidence=.git; break; fi
45
+ if [[ -f "$cursor/odoo/release.py" || -f "$cursor/odoo-bin" ]]; then root="$cursor"; root_evidence=odoo-source; break; fi
46
+ parent="$(dirname "$cursor")"
47
+ [[ "$parent" != "$cursor" ]] || break
48
+ cursor="$parent"
49
+ done
50
+
51
+ # evidence rows: priority<TAB>source<TAB>strength<TAB>major<TAB>count
52
+ evidence=""
53
+ add_evidence() { evidence="${evidence}$1${TAB}$2${TAB}$3${TAB}$4${TAB}$5"$'\n'; }
54
+
55
+ # 1. odoo/release.py (strong)
56
+ release_file="$root/odoo/release.py"
57
+ if [[ -f "$release_file" ]]; then
58
+ major="$(grep -Eo "version_info[[:space:]]*=[[:space:]]*\\([[:space:]]*['\"]?(saas~)?[0-9]+" "$release_file" | head -n 1 | grep -Eo '[0-9]+$' || true)"
59
+ [[ -n "$major" ]] && add_evidence 1 'odoo/release.py' strong "$major" 1
60
+ fi
61
+ # 2. release metadata (strong)
62
+ pkg_info="$root/odoo.egg-info/PKG-INFO"
63
+ if [[ -f "$pkg_info" ]]; then
64
+ major="$(grep -E '^Version:[[:space:]]*[0-9]+\.' "$pkg_info" | head -n 1 | sed -E 's/^Version:[[:space:]]*([0-9]+)\..*/\1/' || true)"
65
+ [[ -n "$major" ]] && add_evidence 2 'odoo.egg-info/PKG-INFO' strong "$major" 1
66
+ fi
67
+ # 3. odoo-bin --version (strong, executes project code: opt-in only)
68
+ odoo_bin="$root/odoo-bin"
69
+ if "$allow_exec" && [[ -f "$odoo_bin" ]]; then
70
+ python_bin="$(command -v python3 || command -v python || true)"
71
+ if [[ -n "$python_bin" ]]; then
72
+ output="$("$python_bin" "$odoo_bin" --version 2>/dev/null || true)"
73
+ major="$(printf '%s' "$output" | grep -Eo 'Odoo Server[[:space:]]+(saas~)?[0-9]+' | head -n 1 | grep -Eo '[0-9]+$' || true)"
74
+ [[ -n "$major" ]] && add_evidence 3 'odoo-bin --version' strong "$major" 1
75
+ fi
76
+ fi
77
+ # 4. git branch / tag (weak)
78
+ branch_re='(^|[^0-9.])(1[0-9]|20)\.0([^0-9]|$)'
79
+ if [[ "$root_evidence" == .git ]] && command -v git >/dev/null 2>&1; then
80
+ branch="$(git -C "$root" symbolic-ref --short -q HEAD 2>/dev/null || true)"
81
+ if [[ "$branch" =~ $branch_re ]]; then add_evidence 4 'git branch' weak "${BASH_REMATCH[2]}" 1
82
+ else
83
+ tag="$(git -C "$root" describe --tags --abbrev=0 2>/dev/null || true)"
84
+ if [[ "$tag" =~ $branch_re ]]; then add_evidence 4 'git tag' weak "${BASH_REMATCH[2]}" 1; fi
85
+ fi
86
+ fi
87
+ # 5. __manifest__.py module versions (weak) and addon roots
88
+ manifest_list="$(find "$root" -maxdepth 5 \( -name .git -o -name node_modules -o -name .venv -o -name venv -o -name __pycache__ -o -name .tox -o -name dist -o -name build -o -name .afyx-graph \) -prune -o -type f -name __manifest__.py -print 2>/dev/null | LC_ALL=C sort | head -n "$MANIFEST_CAP")"
89
+ manifest_count=0
90
+ manifest_majors=""
91
+ addon_roots=""
92
+ while IFS= read -r manifest; do
93
+ [[ -n "$manifest" ]] || continue
94
+ manifest_count=$((manifest_count + 1))
95
+ container="$(dirname "$(dirname "$manifest")")"
96
+ if [[ "$container" == "$root" ]]; then addon_roots="${addon_roots}.
97
+ "; else relative="${container#"$root"/}"; addon_roots="${addon_roots}${relative}
98
+ "; fi
99
+ version="$(grep -Eo "['\"]version['\"][[:space:]]*:[[:space:]]*['\"][0-9]{2}\\.0\\.[0-9]+\\.[0-9]+\\.[0-9]+['\"]" "$manifest" | head -n 1 | grep -Eo '[0-9]{2}' | head -n 1 || true)"
100
+ if [[ -n "$version" ]] && in_range "$version"; then manifest_majors="${manifest_majors}${version}"$'\n'; fi
101
+ done <<EOF
102
+ $manifest_list
103
+ EOF
104
+ if [[ -n "$manifest_majors" ]]; then
105
+ while IFS= read -r line; do
106
+ [[ -n "$line" ]] || continue
107
+ count="${line%% *}"; major="${line#* }"
108
+ add_evidence 5 '__manifest__.py' weak "$major" "$count"
109
+ done <<EOF
110
+ $(printf '%s' "$manifest_majors" | LC_ALL=C sort | uniq -c | awk '{print $1, $2}')
111
+ EOF
112
+ fi
113
+ # 6. dependency files (weak)
114
+ for name in requirements.txt pyproject.toml Dockerfile docker-compose.yml docker-compose.yaml compose.yml compose.yaml; do
115
+ file="$root/$name"
116
+ [[ -f "$file" ]] || continue
117
+ found=""
118
+ found="$found$(grep -Ei '^[[:space:]]*odoo[[:space:]]*(==|~=|>=)[[:space:]]*[0-9]{2}\.0' "$file" | grep -Eio '(==|~=|>=)[[:space:]]*[0-9]{2}' | grep -Eo '[0-9]{2}' || true)"$'\n'
119
+ found="$found$(grep -Eio "image:[[:space:]]*['\"]?odoo:[0-9]{2}" "$file" | grep -Eo '[0-9]{2}$' || true)"$'\n'
120
+ found="$found$(grep -Ei '^[[:space:]]*FROM[[:space:]]+odoo:[0-9]{2}' "$file" | grep -Eo '[0-9]{2}' | head -n 1 || true)"$'\n'
121
+ found="$found$(grep -Eio 'odoo(/odoo)?(\.git)?@[0-9]{2}\.0' "$file" | grep -Eo '@[0-9]{2}' | grep -Eo '[0-9]{2}' || true)"$'\n'
122
+ for major in $(printf '%s' "$found" | grep -E '^[0-9]{2}$' | LC_ALL=C sort -un || true); do
123
+ if in_range "$major"; then add_evidence 6 "$name" weak "$major" 1; fi
124
+ done
125
+ done
126
+
127
+ # Resolve
128
+ sorted_evidence="$(printf '%s' "$evidence" | LC_ALL=C sort -t "$TAB" -k1,1n -k2,2 -k4,4n)"
129
+ strong_majors="$(printf '%s' "$sorted_evidence" | awk -F"$TAB" '$3=="strong"{print $4}' | LC_ALL=C sort -un)"
130
+ weak_majors="$(printf '%s' "$sorted_evidence" | awk -F"$TAB" '$3=="weak"{print $4}' | LC_ALL=C sort -un)"
131
+ count_lines() { if [[ -z "$1" ]]; then printf 0; else printf '%s\n' "$1" | grep -c .; fi; }
132
+ resolved=""; status=unknown
133
+ strong_count="$(count_lines "$strong_majors")"; weak_count="$(count_lines "$weak_majors")"
134
+ if ((strong_count == 1)); then resolved="$strong_majors"; status=proven
135
+ elif ((strong_count > 1)); then status=conflict
136
+ elif ((weak_count == 1)); then resolved="$weak_majors"; status=inferred
137
+ elif ((weak_count > 1)); then status=conflict; fi
138
+ if [[ -n "$resolved" ]] && ! in_range "$resolved"; then status=unsupported; fi
139
+
140
+ conflicts=""
141
+ if [[ "$status" == proven ]]; then
142
+ conflicts="$(printf '%s' "$sorted_evidence" | awk -F"$TAB" -v r="$resolved" '$3=="weak" && $4!=r {print $2 "\t" $4}')"
143
+ fi
144
+
145
+ odoo_detected=false
146
+ if [[ -n "$evidence" ]] || ((manifest_count > 0)) || [[ -f "$odoo_bin" || -f "$release_file" ]]; then odoo_detected=true; fi
147
+ project_type=unknown
148
+ if "$odoo_detected"; then project_type=odoo
149
+ elif [[ -f "$root/pyproject.toml" || -f "$root/setup.py" || -f "$root/requirements.txt" ]]; then project_type=python
150
+ elif [[ -f "$root/package.json" ]]; then project_type=node; fi
151
+
152
+ sorted_roots="$(printf '%s' "$addon_roots" | grep . | LC_ALL=C sort -u | head -n 20 || true)"
153
+
154
+ # Optional cache (hint only)
155
+ cache_path="$root/.afyx/project.json"
156
+ cache_present=false; hint=""; agrees=null
157
+ if [[ -f "$cache_path" ]]; then
158
+ cache_present=true
159
+ hint="$(grep -Eo '"odoo_major"[[:space:]]*:[[:space:]]*[0-9]+' "$cache_path" | head -n 1 | grep -Eo '[0-9]+$' || true)"
160
+ if [[ -n "$hint" && -n "$resolved" ]]; then if [[ "$hint" == "$resolved" ]]; then agrees=true; else agrees=false; fi; fi
161
+ fi
162
+
163
+ if "$write_cache"; then
164
+ mkdir -p "$root/.afyx"
165
+ printf '{\n "note": "Hint only. Source and runtime evidence always win.",\n "odoo_major": %s,\n "version_status": "%s"\n}\n' "${resolved:-null}" "$status" > "$cache_path"
166
+ fi
167
+
168
+ if [[ "$format" == text ]]; then
169
+ printf 'Project root: %s (%s)\nProject type: %s\n' "$root" "$root_evidence" "$project_type"
170
+ if "$odoo_detected"; then
171
+ if [[ -n "$resolved" ]]; then printf 'Odoo: detected; version %s (%s)\n' "$resolved" "$status"; else printf 'Odoo: detected; version %s\n' "$status"; fi
172
+ printf '%s\n' "$sorted_evidence" | while IFS="$TAB" read -r _ source strength major _; do
173
+ if [[ -n "$source" ]]; then printf ' evidence: %s = %s [%s]\n' "$source" "$major" "$strength"; fi
174
+ done
175
+ printf '%s\n' "$conflicts" | while IFS="$TAB" read -r source major; do
176
+ if [[ -n "$source" ]]; then printf ' conflict: %s = %s\n' "$source" "$major"; fi
177
+ done
178
+ if [[ -n "$sorted_roots" ]]; then printf ' addon roots: %s\n' "$(printf '%s' "$sorted_roots" | paste -sd ',' - | sed 's/,/, /g')"; fi
179
+ else printf 'Odoo: not detected\n'; fi
180
+ exit 0
181
+ fi
182
+
183
+ # JSON
184
+ evidence_json=""
185
+ while IFS="$TAB" read -r _ source strength major count; do
186
+ [[ -n "$source" ]] || continue
187
+ evidence_json="${evidence_json:+$evidence_json,}{\"source\":\"$(json_escape "$source")\",\"strength\":\"$strength\",\"major\":$major,\"count\":$count}"
188
+ done <<EOF
189
+ $sorted_evidence
190
+ EOF
191
+ conflicts_json=""
192
+ while IFS="$TAB" read -r source major; do
193
+ [[ -n "$source" ]] || continue
194
+ conflicts_json="${conflicts_json:+$conflicts_json,}{\"source\":\"$(json_escape "$source")\",\"major\":$major}"
195
+ done <<EOF
196
+ $conflicts
197
+ EOF
198
+ roots_json=""
199
+ while IFS= read -r relative; do
200
+ [[ -n "$relative" ]] || continue
201
+ roots_json="${roots_json:+$roots_json,}\"$(json_escape "$relative")\""
202
+ done <<EOF
203
+ $sorted_roots
204
+ EOF
205
+ printf '{"schema_version":1,"project_root":"%s","root_evidence":"%s","project_type":"%s","odoo":{"detected":%s,"supported_range":"%s-%s","major_version":%s,"version_status":"%s","evidence":[%s],"conflicts":[%s],"addon_roots":[%s]},"cache":{"path":".afyx/project.json","present":%s,"hint_major":%s,"agrees":%s}}\n' \
206
+ "$(json_escape "$root")" "$root_evidence" "$project_type" "$odoo_detected" "$SUPPORTED_MIN" "$SUPPORTED_MAX" "${resolved:-null}" "$status" \
207
+ "$evidence_json" "$conflicts_json" "$roots_json" "$cache_present" "${hint:-null}" "$agrees"