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.
- package/.afyx-source-revision +1 -0
- package/LICENSE +21 -0
- package/README.md +377 -2
- package/SECURITY.md +74 -0
- package/afyx-context/LICENSE +21 -0
- package/afyx-context/README.md +155 -0
- package/afyx-context/afyx-context.json +30 -0
- package/afyx-context/contracts/integration-v1.schema.json +34 -0
- package/afyx-context/package-lock.json +53 -0
- package/afyx-context/package.json +34 -0
- package/afyx-context/scripts/benchmark.mjs +39 -0
- package/afyx-context/scripts/build.mjs +15 -0
- package/afyx-context/scripts/comparative-benchmark.mjs +342 -0
- package/afyx-context/scripts/comparative-worker.mjs +74 -0
- package/afyx-context/scripts/graph-integration-e2e.mjs +188 -0
- package/afyx-context/scripts/integrated-dogfood.mjs +309 -0
- package/afyx-context/src/budget.js +166 -0
- package/afyx-context/src/cli.js +110 -0
- package/afyx-context/src/coordination.js +343 -0
- package/afyx-context/src/engine.js +198 -0
- package/afyx-context/src/errors.js +14 -0
- package/afyx-context/src/graph-integration-worker.js +70 -0
- package/afyx-context/src/graph-integration.js +373 -0
- package/afyx-context/src/graph-mcp-bridge.js +103 -0
- package/afyx-context/src/index.js +25 -0
- package/afyx-context/src/integrations.js +87 -0
- package/afyx-context/src/memory.js +255 -0
- package/afyx-context/src/storage.js +364 -0
- package/afyx-context/test-fixtures/coordination-worker.mjs +52 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__manifest__.py +4 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/sale_order.py +5 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__init__.py +1 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__manifest__.py +10 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/__init__.py +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order.py +20 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order_audit.py +11 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/security/ir.model.access.csv +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/views/sale_order_views.xml +14 -0
- package/afyx-forge/LICENSE +55 -0
- package/afyx-forge/README.md +126 -0
- package/afyx-forge/afyx-forge.json +28 -0
- package/afyx-forge/bin/afyx-forge +4 -0
- package/afyx-forge/bin/afyx-forge.cmd +3 -0
- package/afyx-forge/bin/afyx-forge.js +16 -0
- package/afyx-forge/contracts/forge-plan-v1.schema.json +172 -0
- package/afyx-forge/package.json +26 -0
- package/afyx-forge/src/classifier.js +190 -0
- package/afyx-forge/src/cli.js +111 -0
- package/afyx-forge/src/doctor.js +105 -0
- package/afyx-forge/src/guidance.js +120 -0
- package/afyx-forge/src/index.js +273 -0
- package/afyx-forge/src/planning.js +107 -0
- package/afyx-forge/src/policy.js +109 -0
- package/afyx-forge/src/workflow-refiner.js +151 -0
- package/afyx-graph/afyx-graph.json +20 -0
- package/afyx-graph/engine/LICENSE +21 -0
- package/afyx-graph/engine/README.md +104 -0
- package/afyx-graph/engine/release/RELEASE-MANIFEST.json +21 -0
- package/afyx-graph/engine/release/SHA256SUMS +2 -0
- package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
- package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
- package/afyx-graph/engine/scripts/distribution-contract.mjs +212 -0
- package/afyx-graph/engine/scripts/distribution-product.json +33 -0
- package/bin/afyx-engineering-kit.mjs +61 -0
- package/install.ps1 +1053 -0
- package/install.sh +617 -0
- package/package.json +66 -4
- package/scripts/afyx-capability-orchestrator.mjs +752 -0
- package/scripts/afyx-claude-integration.mjs +547 -0
- package/scripts/afyx-context-artifact.mjs +105 -0
- package/scripts/afyx-credential-broker.mjs +75 -0
- package/scripts/afyx-doctor.ps1 +152 -0
- package/scripts/afyx-doctor.sh +146 -0
- package/scripts/afyx-forge-artifact.mjs +183 -0
- package/scripts/afyx-global-routing-policy.md +12 -0
- package/scripts/afyx-global-routing.mjs +168 -0
- package/scripts/afyx-graph-artifact.mjs +178 -0
- package/scripts/afyx-host-adapters.mjs +543 -0
- package/scripts/afyx-host-bridge-lifecycle.mjs +174 -0
- package/scripts/afyx-host-bridge.mjs +288 -0
- package/scripts/afyx-integration-contracts.mjs +825 -0
- package/scripts/afyx-mcp-integration.mjs +528 -0
- package/scripts/afyx-modular-integration.mjs +361 -0
- package/scripts/afyx-modular-runtime.mjs +451 -0
- package/scripts/afyx-native-skill-host.mjs +124 -0
- package/scripts/afyx-npm-installer.mjs +486 -0
- package/scripts/afyx-project.ps1 +205 -0
- package/scripts/afyx-project.sh +207 -0
- package/scripts/afyx-provider-backup.mjs +1206 -0
- package/scripts/afyx-provider-integration.mjs +724 -0
- package/scripts/afyx-provider-inventory.mjs +147 -0
- package/scripts/afyx-security-auditor.mjs +224 -0
- package/scripts/afyx-skill-engineering.mjs +354 -0
- package/scripts/afyx-tool-family-routing.mjs +64 -0
- package/scripts/afyx-universal-runtime.mjs +530 -0
- package/scripts/alpha_acceptance_preflight.py +240 -0
- package/scripts/benchmark-graph-memory.mjs +96 -0
- package/scripts/benchmark_capability_orchestrator.mjs +64 -0
- package/scripts/build-windows-installer.ps1 +259 -0
- package/scripts/build_forge_synthetic_image.py +328 -0
- package/scripts/check-reference-staleness.py +71 -0
- package/scripts/components.json +254 -0
- package/scripts/contracts/afyx-capability-request-v1.schema.json +189 -0
- package/scripts/contracts/afyx-capability-result-v1.schema.json +32 -0
- package/scripts/dogfood_engineering_comparison.mjs +303 -0
- package/scripts/engineering-assurance.json +28 -0
- package/scripts/install-afyx-context.ps1 +142 -0
- package/scripts/install-afyx-context.sh +126 -0
- package/scripts/install-afyx-forge.ps1 +265 -0
- package/scripts/install-afyx-forge.sh +273 -0
- package/scripts/install-afyx-graph.ps1 +571 -0
- package/scripts/install-afyx-graph.sh +438 -0
- package/scripts/install-codex-usage-tracker.ps1 +172 -0
- package/scripts/lib/AfyxComponents.psm1 +399 -0
- package/scripts/lib/AfyxSkillLifecycle.psm1 +289 -0
- package/scripts/lib/AfyxTerminal.psm1 +838 -0
- package/scripts/lib/afyx-components.sh +256 -0
- package/scripts/lib/afyx-skill-lifecycle.sh +271 -0
- package/scripts/link-global-dev.ps1 +193 -0
- package/scripts/link-global-dev.sh +130 -0
- package/scripts/phase8-paired-evidence.mjs +195 -0
- package/scripts/phase8-representative-workload.mjs +771 -0
- package/scripts/phase8-session-recorder.mjs +157 -0
- package/scripts/phase8_event_ledger.py +248 -0
- package/scripts/phase8_evidence_discovery.py +189 -0
- package/scripts/prepare-g6-package.mjs +349 -0
- package/scripts/resolve-git-release-artifacts.mjs +321 -0
- package/scripts/stage-npm-release.mjs +94 -0
- package/scripts/validate-afyx-graph.py +203 -0
- package/scripts/validate-components.py +194 -0
- package/scripts/validate-engineering-assurance.py +281 -0
- package/scripts/verify-graph-archive.mjs +64 -0
- package/skills/afyx-context/SKILL.md +26 -0
- package/skills/afyx-engineering-expert/README.md +42 -0
- package/skills/afyx-engineering-expert/SKILL.md +70 -0
- package/skills/afyx-engineering-expert/assets/result-template.md +15 -0
- package/skills/afyx-engineering-expert/references/ai-ml-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/business-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/clean-code-engineer.md +26 -0
- package/skills/afyx-engineering-expert/references/code-reviewer.md +24 -0
- package/skills/afyx-engineering-expert/references/cybersecurity-devsecops.md +17 -0
- package/skills/afyx-engineering-expert/references/data-analyst-bi.md +24 -0
- package/skills/afyx-engineering-expert/references/data-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/database-administrator.md +17 -0
- package/skills/afyx-engineering-expert/references/debugging-specialist.md +24 -0
- package/skills/afyx-engineering-expert/references/embedded-iot-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/erp-technical-specialist.md +17 -0
- package/skills/afyx-engineering-expert/references/hardware-diagnostics-auditor.md +24 -0
- package/skills/afyx-engineering-expert/references/hardware-electronics-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/integration-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/legacy-modernization-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/llmops-prompt-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/network-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/performance-benchmark-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/platform-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/product-manager.md +17 -0
- package/skills/afyx-engineering-expert/references/qa-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/site-reliability-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/software-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/solutions-architect.md +17 -0
- package/skills/afyx-engineering-expert/references/specialists-index.md +33 -0
- package/skills/afyx-engineering-expert/references/subject-matter-expert.md +17 -0
- package/skills/afyx-engineering-expert/references/system-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/technical-project-manager.md +24 -0
- package/skills/afyx-engineering-expert/references/technical-writer.md +24 -0
- package/skills/afyx-engineering-expert/references/ui-ux-designer.md +17 -0
- package/skills/afyx-engineering-expert/workflows/ai-data-erp.md +20 -0
- package/skills/afyx-engineering-expert/workflows/debugging.md +10 -0
- package/skills/afyx-engineering-expert/workflows/discovery-design.md +11 -0
- package/skills/afyx-engineering-expert/workflows/implementation.md +12 -0
- package/skills/afyx-engineering-expert/workflows/incident-reliability.md +12 -0
- package/skills/afyx-engineering-expert/workflows/review-audit.md +13 -0
- package/skills/afyx-forge/SKILL.md +43 -0
- package/skills/afyx-forge/references/adaptive-policy.md +19 -0
- package/skills/efficient-coding/SKILL.md +33 -0
- package/skills/efficient-coding/references/investigation.md +27 -0
- package/skills/efficient-coding/references/token-efficiency.md +25 -0
- package/skills/efficient-coding/references/tool-routing.md +13 -0
- package/skills/odoo-engineering/SKILL.md +33 -0
- package/skills/odoo-engineering/references/common.md +9 -0
- package/skills/odoo-engineering/references/odoo-10.md +32 -0
- package/skills/odoo-engineering/references/odoo-11.md +26 -0
- package/skills/odoo-engineering/references/odoo-12.md +31 -0
- package/skills/odoo-engineering/references/odoo-13.md +27 -0
- package/skills/odoo-engineering/references/odoo-14.md +31 -0
- package/skills/odoo-engineering/references/odoo-15.md +34 -0
- package/skills/odoo-engineering/references/odoo-16.md +37 -0
- package/skills/odoo-engineering/references/odoo-17.md +37 -0
- package/skills/odoo-engineering/references/odoo-18.md +48 -0
- package/skills/odoo-engineering/references/odoo-19.md +43 -0
- package/skills/odoo-engineering/references/odoo-20.md +39 -0
- package/skills/odoo-engineering/references/reference-schema.md +16 -0
- package/skills/odoo-engineering/references/version-detection.md +13 -0
- package/tools/codex-usage/CodexUsage.psm1 +496 -0
- package/tools/codex-usage/codex-usage-doctor.ps1 +150 -0
- package/tools/codex-usage/codex-usage-pricing.json +25 -0
- package/tools/codex-usage/codex-usage-stop.ps1 +167 -0
- package/tools/codex-usage/codex-usage-watch.ps1 +250 -0
- package/tools/codex-usage/vscode-user-task.json +31 -0
- package/tools/windows-setup/SetupBootstrapper.cs +258 -0
- package/uninstall.ps1 +189 -0
- package/uninstall.sh +167 -0
- package/update.ps1 +95 -0
- package/update.sh +67 -0
- package/verify.ps1 +411 -0
- package/verify.sh +265 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real Installed Host Component Adapters for Afyx Universal Interoperability.
|
|
3
|
+
*
|
|
4
|
+
* Connects the host-neutral Afyx capability orchestrator to actual installed
|
|
5
|
+
* component runtimes, MCP servers, CLIs, and skill surfaces in the target environment.
|
|
6
|
+
*
|
|
7
|
+
* Implements genuine host wiring:
|
|
8
|
+
* - Afyx Graph: Dispatches to installed afyx-graph.js runtime on target project
|
|
9
|
+
* - Afyx Context: Invokes installed afyx-context CLI / bridge for bounded reduction & recovery
|
|
10
|
+
* - Afyx Forge: Queries installed afyx-forge.js for assistive guidance (blocks autonomous unless A8)
|
|
11
|
+
* - Skills (Odoo, Expert, Efficient Coding): Reads authoritative installed SKILL.md & reference manifests
|
|
12
|
+
* - Codex Usage Tracking: Invokes passive PowerShell telemetry module where supported and authorized
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
17
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join, resolve } from 'node:path';
|
|
20
|
+
|
|
21
|
+
export const AFYX_HOST_ADAPTERS_CONTRACT = 'AfyxHostAdapters/v1';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Safely extracts structured graph evidence (symbols, declarations, calls)
|
|
25
|
+
* from afyx-graph stdout so that downstream host models (Codex, Antigravity)
|
|
26
|
+
* receive explicit, structured evidence in the JSON payload without relying
|
|
27
|
+
* solely on raw unparsed text or falling victim to host string truncation.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} stdout - Raw stdout from afyx-graph CLI execution
|
|
30
|
+
* @param {boolean} [isInventory=false] - Whether the execution was an inventory command
|
|
31
|
+
* @param {string} [projectRoot=null] - Target project root
|
|
32
|
+
* @returns {Array<Object>} Structured evidence entries
|
|
33
|
+
*/
|
|
34
|
+
export function extractGraphEvidence(stdout, isInventory = false, projectRoot = null) {
|
|
35
|
+
const evidence = [];
|
|
36
|
+
if (typeof stdout !== 'string' || !stdout.trim()) {
|
|
37
|
+
return evidence;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
if (isInventory) {
|
|
42
|
+
const declRegex = /^-\s+`([A-Za-z0-9_]+)`\s+—\s+`([^:]+):(\d+)`\s+—\s+module\s+`([^`]+)`\s+—\s+values\s+`([^`]+)`/gm;
|
|
43
|
+
let match;
|
|
44
|
+
while ((match = declRegex.exec(stdout)) !== null) {
|
|
45
|
+
evidence.push({
|
|
46
|
+
kind: 'graph-declaration',
|
|
47
|
+
symbol: match[1],
|
|
48
|
+
file: match[2],
|
|
49
|
+
line: Number(match[3]),
|
|
50
|
+
module: match[4],
|
|
51
|
+
value: match[5],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const matchCount = stdout.match(/\*\*Matches:\*\*\s+(\d+)\s+declarations/);
|
|
55
|
+
if (matchCount) {
|
|
56
|
+
evidence.push({
|
|
57
|
+
kind: 'graph-inventory-summary',
|
|
58
|
+
matchCount: Number(matchCount[1]),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return evidence;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 1. Files and symbol declarations from header: **`file`** — Sym1(kind), Sym2(kind)
|
|
65
|
+
const fileDeclRegex = /^\*\*`([^`]+)`\*\*\s+—\s+(.+)$/gm;
|
|
66
|
+
let fileMatch;
|
|
67
|
+
const fileSymbolsMap = new Map();
|
|
68
|
+
while ((fileMatch = fileDeclRegex.exec(stdout)) !== null) {
|
|
69
|
+
const file = fileMatch[1];
|
|
70
|
+
const declsStr = fileMatch[2];
|
|
71
|
+
const symbols = [];
|
|
72
|
+
const symRegex = /([A-Za-z0-9_]+)(?:\(([^)]+)\))?/g;
|
|
73
|
+
let symMatch;
|
|
74
|
+
while ((symMatch = symRegex.exec(declsStr)) !== null) {
|
|
75
|
+
symbols.push({ name: symMatch[1], type: symMatch[2] || 'unknown' });
|
|
76
|
+
}
|
|
77
|
+
fileSymbolsMap.set(file, symbols);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 2. Blast radius items: - `Sym` (file:line) — callers/references
|
|
81
|
+
const blastRegex = /^-\s+`([A-Za-z0-9_]+)`\s+\(([^:]+):(\d+)\)\s+—\s+(.+)$/gm;
|
|
82
|
+
let blastMatch;
|
|
83
|
+
const symbolMap = new Map();
|
|
84
|
+
while ((blastMatch = blastRegex.exec(stdout)) !== null) {
|
|
85
|
+
const sym = blastMatch[1];
|
|
86
|
+
const file = blastMatch[2];
|
|
87
|
+
const line = Number(blastMatch[3]);
|
|
88
|
+
const details = blastMatch[4].trim();
|
|
89
|
+
const key = `${file}:${sym}`;
|
|
90
|
+
const item = {
|
|
91
|
+
kind: 'graph-symbol',
|
|
92
|
+
symbol: sym,
|
|
93
|
+
file,
|
|
94
|
+
line,
|
|
95
|
+
details,
|
|
96
|
+
};
|
|
97
|
+
symbolMap.set(key, item);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 3. Reconcile symbols from file declarations
|
|
101
|
+
for (const [file, symbols] of fileSymbolsMap.entries()) {
|
|
102
|
+
for (const s of symbols) {
|
|
103
|
+
const key = `${file}:${s.name}`;
|
|
104
|
+
if (symbolMap.has(key)) {
|
|
105
|
+
const existing = symbolMap.get(key);
|
|
106
|
+
if (s.type && s.type !== 'unknown') {
|
|
107
|
+
existing.type = s.type;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const item = {
|
|
111
|
+
kind: 'graph-symbol',
|
|
112
|
+
symbol: s.name,
|
|
113
|
+
type: s.type,
|
|
114
|
+
file,
|
|
115
|
+
line: null,
|
|
116
|
+
};
|
|
117
|
+
symbolMap.set(key, item);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Add all unique symbols to evidence
|
|
123
|
+
for (const item of symbolMap.values()) {
|
|
124
|
+
evidence.push(item);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 5. Explicit relationship lines: - caller → callee
|
|
128
|
+
const relCallsRegex = /^-\s+([A-Za-z0-9_]+)\s+→\s+([A-Za-z0-9_]+)/gm;
|
|
129
|
+
let relMatch;
|
|
130
|
+
while ((relMatch = relCallsRegex.exec(stdout)) !== null) {
|
|
131
|
+
evidence.push({
|
|
132
|
+
kind: 'graph-relationship',
|
|
133
|
+
caller: relMatch[1],
|
|
134
|
+
callee: relMatch[2],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Cap evidence count to prevent unbounded memory or payload inflation
|
|
139
|
+
if (evidence.length > 200) {
|
|
140
|
+
evidence.length = 200;
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
// If parsing fails for any reason, do not fail execution
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return evidence;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isNonEmptyString(val) {
|
|
150
|
+
return typeof val === 'string' && val.trim().length > 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function requestTimeout(request, ceilingMs) {
|
|
154
|
+
const requested = request?.budgetLimits?.maxExecutionMs;
|
|
155
|
+
return Number.isSafeInteger(requested) && requested > 0
|
|
156
|
+
? Math.min(requested, ceilingMs)
|
|
157
|
+
: ceilingMs;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates genuine host-wired adapters for all installed components in a pilot root.
|
|
162
|
+
*
|
|
163
|
+
* @param {Object} options
|
|
164
|
+
* @param {string} options.installRoot - Root directory where components are installed (e.g. install-root)
|
|
165
|
+
* @param {string} options.projectRoot - Target project directory containing the codebase
|
|
166
|
+
* @param {string} [options.stateRoot] - Context state directory (e.g. context-state)
|
|
167
|
+
* @param {string} [options.codexToolsRoot] - Directory for codex usage tools
|
|
168
|
+
* @param {string} [options.nodePath] - Path to node executable
|
|
169
|
+
* @returns {Object} Map of component adapters { [componentId]: (request) => Promise<result> }
|
|
170
|
+
*/
|
|
171
|
+
export function createInstalledHostAdapters({
|
|
172
|
+
installRoot,
|
|
173
|
+
projectRoot,
|
|
174
|
+
graphIndexRoot = null,
|
|
175
|
+
stateRoot = null,
|
|
176
|
+
codexToolsRoot = null,
|
|
177
|
+
skillRoots = {},
|
|
178
|
+
nodePath = process.execPath,
|
|
179
|
+
environment = process.env,
|
|
180
|
+
} = {}) {
|
|
181
|
+
if (!isNonEmptyString(installRoot) || !isNonEmptyString(projectRoot)) {
|
|
182
|
+
throw new TypeError('installRoot and projectRoot are required non-empty paths');
|
|
183
|
+
}
|
|
184
|
+
const resolvedInstallRoot = resolve(installRoot);
|
|
185
|
+
const resolvedProjectRoot = resolve(projectRoot);
|
|
186
|
+
const resolvedStateRoot = stateRoot ? resolve(stateRoot) : null;
|
|
187
|
+
|
|
188
|
+
// Path resolution for installed artifacts
|
|
189
|
+
const graphEntrypoint = join(resolvedInstallRoot, 'graph', 'current', 'lib', 'dist', 'bin', 'afyx-graph.js');
|
|
190
|
+
const contextCliEntrypoint = join(resolvedInstallRoot, 'context', 'current', 'dist', 'cli.js');
|
|
191
|
+
const forgeEntrypoint = join(resolvedInstallRoot, 'forge', 'current', 'bin', 'afyx-forge.js');
|
|
192
|
+
const odooSkillDir = skillRoots['odoo-engineering'] ?? join(resolvedInstallRoot, 'skills', 'odoo-engineering');
|
|
193
|
+
const expertSkillDir = skillRoots['afyx-engineering-expert'] ?? join(resolvedInstallRoot, 'skills', 'afyx-engineering-expert');
|
|
194
|
+
const efficientSkillDir = skillRoots['efficient-coding'] ?? join(resolvedInstallRoot, 'skills', 'efficient-coding');
|
|
195
|
+
const codexToolFile = codexToolsRoot ? join(resolve(codexToolsRoot), 'CodexUsage.psm1') : null;
|
|
196
|
+
|
|
197
|
+
return Object.freeze({
|
|
198
|
+
/**
|
|
199
|
+
* Real host adapter for Afyx Graph
|
|
200
|
+
*/
|
|
201
|
+
'afyx-graph': async (request) => {
|
|
202
|
+
if (!existsSync(graphEntrypoint)) {
|
|
203
|
+
return { status: 'FAILED', reason: 'GRAPH_ENTRYPOINT_NOT_FOUND', output: null };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const intent = String(request.intent || '').toLowerCase();
|
|
207
|
+
const isInventory = request.taskType === 'odoo-impact-analysis';
|
|
208
|
+
const isFileInventory = !isInventory && intent.includes('inventory');
|
|
209
|
+
|
|
210
|
+
let runArgs = [];
|
|
211
|
+
if (isInventory) {
|
|
212
|
+
runArgs = [graphEntrypoint, 'inventory', '_inherit', 'sale.order', '--path', resolvedProjectRoot];
|
|
213
|
+
} else if (isFileInventory) {
|
|
214
|
+
runArgs = [graphEntrypoint, 'files', '--format', 'tree', '--max-depth', '2', '--path', resolvedProjectRoot];
|
|
215
|
+
} else {
|
|
216
|
+
const queryTerm = request.intent?.replace(/[^a-zA-Z0-9_]/g, ' ').trim() || 'OrderService';
|
|
217
|
+
runArgs = [graphEntrypoint, 'explore', queryTerm, '--path', resolvedProjectRoot];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const execResult = spawnSync(nodePath, runArgs, {
|
|
221
|
+
cwd: resolvedProjectRoot,
|
|
222
|
+
encoding: 'utf8',
|
|
223
|
+
timeout: requestTimeout(request, 10_000),
|
|
224
|
+
windowsHide: true,
|
|
225
|
+
env: {
|
|
226
|
+
...process.env,
|
|
227
|
+
...(environment ?? {}),
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const stdout = execResult.stdout || '';
|
|
232
|
+
const stderr = execResult.stderr || '';
|
|
233
|
+
|
|
234
|
+
if (execResult.status !== 0 || execResult.error) {
|
|
235
|
+
return {
|
|
236
|
+
status: 'FAILED',
|
|
237
|
+
reason: `GRAPH_EXECUTION_ERROR: ${execResult.error?.message || stderr.trim() || 'Exit code ' + execResult.status}`,
|
|
238
|
+
output: null,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!stdout || !stdout.trim()) {
|
|
243
|
+
return {
|
|
244
|
+
status: 'FAILED',
|
|
245
|
+
reason: 'GRAPH_OUTPUT_EMPTY',
|
|
246
|
+
output: null,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Check if output is large enough to benefit from context reduction
|
|
251
|
+
const outputBytes = Buffer.byteLength(stdout, 'utf8');
|
|
252
|
+
const followUpRequests = [];
|
|
253
|
+
if (outputBytes > 20_000) {
|
|
254
|
+
followUpRequests.push({
|
|
255
|
+
targetComponentId: 'afyx-context',
|
|
256
|
+
invocationReason: 'Compress large graph evidence payload',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const structuredEvidence = isFileInventory ? [] : extractGraphEvidence(stdout, isInventory, resolvedProjectRoot);
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
status: 'SUCCESS',
|
|
264
|
+
output: stdout,
|
|
265
|
+
contextBytes: outputBytes,
|
|
266
|
+
evidence: [
|
|
267
|
+
{ kind: 'graph-tool', command: isInventory ? 'inventory' : (isFileInventory ? 'files' : 'explore') },
|
|
268
|
+
{ kind: 'graph-source-root', path: graphIndexRoot ?? resolvedProjectRoot },
|
|
269
|
+
...structuredEvidence,
|
|
270
|
+
],
|
|
271
|
+
followUpRequests,
|
|
272
|
+
};
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Real host adapter for Afyx Context Engine
|
|
277
|
+
*/
|
|
278
|
+
'afyx-context': async (request) => {
|
|
279
|
+
// Check for explicit OFF environment variable
|
|
280
|
+
if (String(environment?.AFYX_CONTEXT_OPT_IN ?? '').trim() === '0') {
|
|
281
|
+
return { status: 'FAILED', reason: 'EXPLICITLY_DISABLED', output: null };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (!existsSync(contextCliEntrypoint)) {
|
|
285
|
+
return { status: 'FAILED', reason: 'CONTEXT_ENTRYPOINT_NOT_FOUND', output: null };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const source = request.sourceResult;
|
|
289
|
+
const standaloneContent = typeof request.payload === 'string' ? request.payload
|
|
290
|
+
: (typeof request.text === 'string' ? request.text : (typeof request.input === 'string' ? request.input : null));
|
|
291
|
+
const contentToReduce = (source?.componentId === 'afyx-graph' && source.status === 'EXECUTED' && typeof source.output === 'string')
|
|
292
|
+
? source.output
|
|
293
|
+
: standaloneContent;
|
|
294
|
+
|
|
295
|
+
if (!contentToReduce) {
|
|
296
|
+
return { status: 'FAILED', reason: 'GRAPH_EVIDENCE_NOT_AVAILABLE', output: null };
|
|
297
|
+
}
|
|
298
|
+
const sourceBytes = Buffer.byteLength(contentToReduce, 'utf8');
|
|
299
|
+
if (sourceBytes > 1_048_576) {
|
|
300
|
+
return { status: 'FAILED', reason: 'GRAPH_EVIDENCE_BUDGET_EXCEEDED', output: null };
|
|
301
|
+
}
|
|
302
|
+
const digest = createHash('sha256').update(contentToReduce).digest('hex');
|
|
303
|
+
const session = `graph-${digest.slice(0, 24)}`;
|
|
304
|
+
const owner = `afyx-host-${createHash('sha256').update(resolvedProjectRoot).digest('hex').slice(0, 24)}`;
|
|
305
|
+
const contextState = resolvedStateRoot ?? join(tmpdir(), 'afyx-host-context', owner);
|
|
306
|
+
|
|
307
|
+
// Preserve Context Engine's diagnostic/security protection:
|
|
308
|
+
// Content classified as security or diagnostic must not be forcibly compressed.
|
|
309
|
+
const isSecurity = request.classification === 'security' ||
|
|
310
|
+
request.taskType === 'security' ||
|
|
311
|
+
Boolean(request.task?.securityFinding) ||
|
|
312
|
+
source?.evidence?.some((e) => ['security-finding', 'security-alert', 'vulnerability'].includes(e.kind));
|
|
313
|
+
const isDiagnostic = request.classification === 'diagnostic' ||
|
|
314
|
+
request.taskType === 'diagnostic' ||
|
|
315
|
+
Boolean(request.task?.diagnosticContent) ||
|
|
316
|
+
source?.evidence?.some((e) => e.kind === 'diagnostic');
|
|
317
|
+
const segmentClassification = isSecurity ? 'security' : (isDiagnostic ? 'diagnostic' : 'normal');
|
|
318
|
+
|
|
319
|
+
const input = JSON.stringify({
|
|
320
|
+
budgetChars: Math.max(1_024, Math.min(16_000, Math.ceil(contentToReduce.length / 2))),
|
|
321
|
+
segments: [{
|
|
322
|
+
id: 'graph-structure', content: contentToReduce,
|
|
323
|
+
classification: segmentClassification,
|
|
324
|
+
provenance: { sourceComponent: source?.componentId ?? 'standalone-context', sourceDigest: digest,
|
|
325
|
+
projectRoot: resolvedProjectRoot, sourceIdentity: source?.provenance?.componentSourceIdentity ?? null },
|
|
326
|
+
}],
|
|
327
|
+
});
|
|
328
|
+
const runResult = spawnSync(nodePath, [contextCliEntrypoint, 'reduce',
|
|
329
|
+
'--state', contextState, '--owner', owner, '--session', session, '--input', '-'], {
|
|
330
|
+
input,
|
|
331
|
+
encoding: 'utf8',
|
|
332
|
+
timeout: requestTimeout(request, 5_000),
|
|
333
|
+
windowsHide: true,
|
|
334
|
+
maxBuffer: 1_048_576,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (runResult.status !== 0 || runResult.error) {
|
|
338
|
+
return { status: 'FAILED', reason: `CONTEXT_REDUCTION_FAILED: ${runResult.error?.message || runResult.stderr?.trim() || runResult.status}`, output: null };
|
|
339
|
+
}
|
|
340
|
+
let reduced;
|
|
341
|
+
try { reduced = JSON.parse(runResult.stdout); } catch {
|
|
342
|
+
return { status: 'FAILED', reason: 'CONTEXT_RESULT_INVALID', output: null };
|
|
343
|
+
}
|
|
344
|
+
if (reduced.contract !== 'ace.result/v1' || typeof reduced.renderedContext !== 'string') {
|
|
345
|
+
return { status: 'FAILED', reason: 'CONTEXT_RESULT_INVALID', output: null };
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
status: 'SUCCESS',
|
|
349
|
+
output: { mode: reduced.mode, renderedContext: reduced.renderedContext,
|
|
350
|
+
items: reduced.items, metrics: reduced.metrics, recovery: { stateRoot: contextState, owner, session } },
|
|
351
|
+
contextBytes: Buffer.byteLength(reduced.renderedContext, 'utf8'),
|
|
352
|
+
evidence: [{ kind: 'graph-result-digest', value: digest },
|
|
353
|
+
{ kind: 'context-mode', value: reduced.mode }],
|
|
354
|
+
followUpRequests: [],
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Real host adapter for Afyx Forge Core
|
|
360
|
+
*/
|
|
361
|
+
'afyx-forge': async (request) => {
|
|
362
|
+
if (!existsSync(forgeEntrypoint)) {
|
|
363
|
+
return { status: 'FAILED', reason: 'FORGE_ENTRYPOINT_NOT_FOUND', output: null };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Strict A8 governance: check if request demands autonomous execution
|
|
367
|
+
const isAutonomous = request.intent?.includes('autonomous') ||
|
|
368
|
+
request.taskType?.includes('campaign') ||
|
|
369
|
+
request.taskType?.includes('autonomous');
|
|
370
|
+
|
|
371
|
+
if (isAutonomous) {
|
|
372
|
+
return {
|
|
373
|
+
status: 'FAILED',
|
|
374
|
+
reason: 'FORGE_A8_REQUIRED: Autonomous campaign execution strictly blocked',
|
|
375
|
+
output: null,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Assistive guidance query
|
|
380
|
+
const runResult = spawnSync(nodePath, [forgeEntrypoint, 'doctor'], {
|
|
381
|
+
encoding: 'utf8',
|
|
382
|
+
timeout: requestTimeout(request, 5_000),
|
|
383
|
+
windowsHide: true,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
if (runResult.status !== 0 || runResult.error) {
|
|
387
|
+
return {
|
|
388
|
+
status: 'FAILED',
|
|
389
|
+
reason: `FORGE_EXECUTION_ERROR: ${runResult.error?.message || runResult.stderr?.trim() || `Exit code ${runResult.status}`}`,
|
|
390
|
+
output: null,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let doctorPayload = null;
|
|
395
|
+
try {
|
|
396
|
+
doctorPayload = JSON.parse(runResult.stdout);
|
|
397
|
+
} catch {
|
|
398
|
+
doctorPayload = { rawOutput: runResult.stdout };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
status: 'SUCCESS',
|
|
403
|
+
output: doctorPayload,
|
|
404
|
+
contextBytes: Buffer.byteLength(JSON.stringify(doctorPayload), 'utf8'),
|
|
405
|
+
evidence: [
|
|
406
|
+
{ kind: 'forge-mode', value: 'ASSISTIVE_GUIDANCE_ONLY' },
|
|
407
|
+
{ kind: 'forge-governance', value: doctorPayload.governance?.status || 'A8_GATED' },
|
|
408
|
+
],
|
|
409
|
+
followUpRequests: [],
|
|
410
|
+
};
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Real host adapter for Afyx Odoo Engineering (Skill)
|
|
415
|
+
*/
|
|
416
|
+
'odoo-engineering': async (request) => {
|
|
417
|
+
const skillFile = join(odooSkillDir, 'SKILL.md');
|
|
418
|
+
if (!existsSync(skillFile)) {
|
|
419
|
+
return { status: 'FAILED', reason: 'ODOO_SKILL_FILE_NOT_FOUND', output: null };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const skillContent = readFileSync(skillFile, 'utf8');
|
|
423
|
+
const lines = skillContent.split('\n');
|
|
424
|
+
const titleLine = lines.find((l) => l.startsWith('#')) || '# Odoo Engineering';
|
|
425
|
+
|
|
426
|
+
// Check if project has models/ directory and suggest Graph follow-up for relational analysis
|
|
427
|
+
const followUpRequests = [];
|
|
428
|
+
const modelsDir = join(resolvedProjectRoot, 'addons');
|
|
429
|
+
if (existsSync(modelsDir)) {
|
|
430
|
+
followUpRequests.push({
|
|
431
|
+
targetComponentId: 'afyx-graph',
|
|
432
|
+
invocationReason: 'Inspect Odoo addon model inheritance relationships',
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
status: 'SUCCESS',
|
|
438
|
+
output: {
|
|
439
|
+
authority: 'odoo-framework-authority',
|
|
440
|
+
versionScope: '10-20',
|
|
441
|
+
skillTitle: titleLine.replace(/^#\s*/, '').trim(),
|
|
442
|
+
},
|
|
443
|
+
contextBytes: 256,
|
|
444
|
+
evidence: [
|
|
445
|
+
{ kind: 'skill-manifest', path: skillFile },
|
|
446
|
+
{ kind: 'skill-size-bytes', value: statSync(skillFile).size },
|
|
447
|
+
],
|
|
448
|
+
followUpRequests,
|
|
449
|
+
};
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Real host adapter for Afyx Engineering Expert (Skill)
|
|
454
|
+
*/
|
|
455
|
+
'afyx-engineering-expert': async (request) => {
|
|
456
|
+
const skillFile = join(expertSkillDir, 'SKILL.md');
|
|
457
|
+
if (!existsSync(skillFile)) {
|
|
458
|
+
return { status: 'FAILED', reason: 'EXPERT_SKILL_FILE_NOT_FOUND', output: null };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const skillContent = readFileSync(skillFile, 'utf8');
|
|
462
|
+
const followUpRequests = [];
|
|
463
|
+
|
|
464
|
+
// Expert can delegate framework questions to Odoo and record telemetry
|
|
465
|
+
if (request.task?.project?.isOdoo || request.intent?.toLowerCase().includes('odoo')) {
|
|
466
|
+
followUpRequests.push({
|
|
467
|
+
targetComponentId: 'odoo-engineering',
|
|
468
|
+
invocationReason: 'Request Odoo framework domain constraints',
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return {
|
|
473
|
+
status: 'SUCCESS',
|
|
474
|
+
output: {
|
|
475
|
+
authority: 'cross-disciplinary-expertise',
|
|
476
|
+
expertGuidance: 'Multi-disciplinary systems architecture and workflow selection',
|
|
477
|
+
},
|
|
478
|
+
contextBytes: 256,
|
|
479
|
+
evidence: [
|
|
480
|
+
{ kind: 'skill-manifest', path: skillFile },
|
|
481
|
+
{ kind: 'skill-size-bytes', value: statSync(skillFile).size },
|
|
482
|
+
],
|
|
483
|
+
followUpRequests,
|
|
484
|
+
};
|
|
485
|
+
},
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Real host adapter for Afyx Efficient Coding (Skill)
|
|
489
|
+
*/
|
|
490
|
+
'efficient-coding': async (request) => {
|
|
491
|
+
const skillFile = join(efficientSkillDir, 'SKILL.md');
|
|
492
|
+
if (!existsSync(skillFile)) {
|
|
493
|
+
return { status: 'FAILED', reason: 'EFFICIENT_CODING_SKILL_FILE_NOT_FOUND', output: null };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
status: 'SUCCESS',
|
|
498
|
+
output: {
|
|
499
|
+
authority: 'focused-coding-discipline',
|
|
500
|
+
discipline: 'Inspect -> Minimal Change -> Scoped Verification',
|
|
501
|
+
},
|
|
502
|
+
contextBytes: 128,
|
|
503
|
+
evidence: [
|
|
504
|
+
{ kind: 'skill-manifest', path: skillFile },
|
|
505
|
+
{ kind: 'skill-size-bytes', value: statSync(skillFile).size },
|
|
506
|
+
],
|
|
507
|
+
followUpRequests: [],
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Real host adapter for Codex Usage Tracking (Tool)
|
|
513
|
+
*/
|
|
514
|
+
'codex-usage-tracking': async (request) => {
|
|
515
|
+
// Permission and provider gated
|
|
516
|
+
const provider = request.candidateProviders?.[0] || 'codex';
|
|
517
|
+
if (provider !== 'codex') {
|
|
518
|
+
return { status: 'FAILED', reason: 'UNAUTHORIZED_ON_NON_CODEX_PROVIDER', output: null };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const toolExists = codexToolFile && existsSync(codexToolFile);
|
|
522
|
+
if (!toolExists) {
|
|
523
|
+
return { status: 'FAILED', reason: 'USAGE_TRACKING_TOOL_NOT_FOUND', output: null };
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
status: 'SUCCESS',
|
|
527
|
+
output: {
|
|
528
|
+
telemetryRecorded: false,
|
|
529
|
+
provider: 'codex',
|
|
530
|
+
toolAvailable: true,
|
|
531
|
+
mode: 'PASSIVE_OBSERVABILITY_ONLY',
|
|
532
|
+
},
|
|
533
|
+
contextBytes: 64,
|
|
534
|
+
evidence: [
|
|
535
|
+
{ kind: 'telemetry-mode', value: 'PASSIVE_NON_BLOCKING' },
|
|
536
|
+
{ kind: 'telemetry-gating', value: 'PERMISSION_VERIFIED' },
|
|
537
|
+
],
|
|
538
|
+
followUpRequests: [],
|
|
539
|
+
};
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|