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.
- 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,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/** Atomic lifecycle for the installed AfyxHostBridge/v1 runtime bundle. */
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import {
|
|
6
|
+
copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync,
|
|
7
|
+
renameSync, rmdirSync, rmSync, writeFileSync,
|
|
8
|
+
} from 'node:fs';
|
|
9
|
+
import { dirname, join, resolve } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
|
|
12
|
+
export const AFYX_HOST_BRIDGE_PRODUCT = 'Afyx Universal Host Bridge';
|
|
13
|
+
export const AFYX_HOST_BRIDGE_CONTRACT = 'AfyxHostBridge/v1';
|
|
14
|
+
export const HOST_BRIDGE_FILES = Object.freeze([
|
|
15
|
+
'afyx-host-bridge.mjs',
|
|
16
|
+
'afyx-universal-runtime.mjs',
|
|
17
|
+
'afyx-host-adapters.mjs',
|
|
18
|
+
'afyx-capability-orchestrator.mjs',
|
|
19
|
+
'afyx-modular-integration.mjs',
|
|
20
|
+
'afyx-modular-runtime.mjs',
|
|
21
|
+
'afyx-tool-family-routing.mjs',
|
|
22
|
+
'afyx-native-skill-host.mjs',
|
|
23
|
+
'afyx-skill-engineering.mjs',
|
|
24
|
+
'components.json',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
function sha256(file) {
|
|
28
|
+
return createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function json(file) {
|
|
32
|
+
try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return null; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function atomicJson(file, value) {
|
|
36
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
37
|
+
const temporary = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { encoding: 'utf8', flag: 'wx' });
|
|
40
|
+
renameSync(temporary, file);
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(temporary, { force: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function ensureOrdinaryDirectory(path) {
|
|
47
|
+
if (!existsSync(path)) return;
|
|
48
|
+
const info = lstatSync(path);
|
|
49
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error(`HOST_BRIDGE_PATH_UNSAFE: ${path}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function identity(runtimeRoot) {
|
|
53
|
+
return json(join(runtimeRoot, 'metadata.json'));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function verifyHostBridge(runtimeRoot) {
|
|
57
|
+
const root = resolve(runtimeRoot);
|
|
58
|
+
const metadata = identity(root);
|
|
59
|
+
if (metadata?.product_name !== AFYX_HOST_BRIDGE_PRODUCT
|
|
60
|
+
|| metadata?.contract !== AFYX_HOST_BRIDGE_CONTRACT) {
|
|
61
|
+
return { status: 'NOT_INSTALLED', runtimeRoot: root, entry: join(root, 'current', 'afyx-host-bridge.mjs') };
|
|
62
|
+
}
|
|
63
|
+
const integrity = json(join(root, 'integrity.json'));
|
|
64
|
+
if (!integrity?.files || typeof integrity.files !== 'object') {
|
|
65
|
+
return { status: 'BROKEN', runtimeRoot: root, reason: 'INTEGRITY_MISSING' };
|
|
66
|
+
}
|
|
67
|
+
for (const file of HOST_BRIDGE_FILES) {
|
|
68
|
+
const target = join(root, 'current', file);
|
|
69
|
+
if (!existsSync(target) || sha256(target) !== integrity.files[file]) {
|
|
70
|
+
return { status: 'BROKEN', runtimeRoot: root, reason: 'INTEGRITY_MISMATCH', file };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
status: 'READY', runtimeRoot: root,
|
|
75
|
+
entry: join(root, 'current', 'afyx-host-bridge.mjs'),
|
|
76
|
+
sourceRevision: metadata.source_revision ?? null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function installHostBridge({ sourceRoot, runtimeRoot, sourceRevision = 'UNKNOWN' }) {
|
|
81
|
+
const source = resolve(sourceRoot);
|
|
82
|
+
const root = resolve(runtimeRoot);
|
|
83
|
+
ensureOrdinaryDirectory(root);
|
|
84
|
+
const existing = identity(root);
|
|
85
|
+
if (existsSync(root) && readdirSync(root).length > 0
|
|
86
|
+
&& existing?.product_name !== AFYX_HOST_BRIDGE_PRODUCT) {
|
|
87
|
+
throw new Error(`HOST_BRIDGE_FOREIGN_RUNTIME: ${root}`);
|
|
88
|
+
}
|
|
89
|
+
for (const file of HOST_BRIDGE_FILES) {
|
|
90
|
+
if (!existsSync(join(source, file))) throw new Error(`HOST_BRIDGE_SOURCE_MISSING: ${file}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const current = join(root, 'current');
|
|
94
|
+
if (existsSync(current)) ensureOrdinaryDirectory(current);
|
|
95
|
+
const verified = verifyHostBridge(root);
|
|
96
|
+
if (verified.status === 'READY' && verified.sourceRevision === sourceRevision
|
|
97
|
+
&& HOST_BRIDGE_FILES.every((file) => sha256(join(source, file)) === sha256(join(current, file)))) {
|
|
98
|
+
return { ...verified, changed: false };
|
|
99
|
+
}
|
|
100
|
+
mkdirSync(root, { recursive: true });
|
|
101
|
+
const stage = join(root, `.stage-${process.pid}-${Date.now()}`);
|
|
102
|
+
const backup = join(root, `.backup-${process.pid}-${Date.now()}`);
|
|
103
|
+
let movedCurrent = false;
|
|
104
|
+
try {
|
|
105
|
+
mkdirSync(stage, { recursive: false });
|
|
106
|
+
const hashes = {};
|
|
107
|
+
for (const file of HOST_BRIDGE_FILES) {
|
|
108
|
+
const target = join(stage, file);
|
|
109
|
+
copyFileSync(join(source, file), target);
|
|
110
|
+
hashes[file] = sha256(target);
|
|
111
|
+
}
|
|
112
|
+
if (existsSync(current)) {
|
|
113
|
+
ensureOrdinaryDirectory(current);
|
|
114
|
+
renameSync(current, backup);
|
|
115
|
+
movedCurrent = true;
|
|
116
|
+
}
|
|
117
|
+
renameSync(stage, current);
|
|
118
|
+
atomicJson(join(root, 'integrity.json'), { schema_version: 1, files: hashes });
|
|
119
|
+
atomicJson(join(root, 'metadata.json'), {
|
|
120
|
+
schema_version: 1,
|
|
121
|
+
product_name: AFYX_HOST_BRIDGE_PRODUCT,
|
|
122
|
+
contract: AFYX_HOST_BRIDGE_CONTRACT,
|
|
123
|
+
source_revision: sourceRevision,
|
|
124
|
+
entry: 'current/afyx-host-bridge.mjs',
|
|
125
|
+
});
|
|
126
|
+
const verified = verifyHostBridge(root);
|
|
127
|
+
if (verified.status !== 'READY') throw new Error(`HOST_BRIDGE_VERIFY_FAILED: ${verified.reason}`);
|
|
128
|
+
if (movedCurrent) rmSync(backup, { recursive: true, force: true });
|
|
129
|
+
return { ...verified, changed: true };
|
|
130
|
+
} catch (error) {
|
|
131
|
+
rmSync(stage, { recursive: true, force: true });
|
|
132
|
+
if (movedCurrent && !existsSync(current) && existsSync(backup)) renameSync(backup, current);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function uninstallHostBridge(runtimeRoot) {
|
|
138
|
+
const root = resolve(runtimeRoot);
|
|
139
|
+
const verified = verifyHostBridge(root);
|
|
140
|
+
if (verified.status === 'NOT_INSTALLED') return { status: 'NOT_INSTALLED', changed: false, runtimeRoot: root };
|
|
141
|
+
if (verified.status !== 'READY') throw new Error(`HOST_BRIDGE_UNINSTALL_REFUSED: ${verified.reason}`);
|
|
142
|
+
rmSync(join(root, 'current'), { recursive: true, force: false });
|
|
143
|
+
rmSync(join(root, 'integrity.json'), { force: false });
|
|
144
|
+
rmSync(join(root, 'metadata.json'), { force: false });
|
|
145
|
+
if (readdirSync(root).length === 0) rmdirSync(root);
|
|
146
|
+
return { status: 'NOT_INSTALLED', changed: true, runtimeRoot: root };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function argument(name, fallback = '') {
|
|
150
|
+
const index = process.argv.indexOf(name);
|
|
151
|
+
return index >= 0 ? process.argv[index + 1] : fallback;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
|
155
|
+
try {
|
|
156
|
+
const runtimeRoot = argument('--runtime-root');
|
|
157
|
+
let result;
|
|
158
|
+
if (process.argv.includes('--install')) {
|
|
159
|
+
result = installHostBridge({
|
|
160
|
+
sourceRoot: argument('--source-root'), runtimeRoot,
|
|
161
|
+
sourceRevision: argument('--source-revision', 'UNKNOWN'),
|
|
162
|
+
});
|
|
163
|
+
} else if (process.argv.includes('--uninstall')) {
|
|
164
|
+
result = uninstallHostBridge(runtimeRoot);
|
|
165
|
+
} else {
|
|
166
|
+
result = verifyHostBridge(runtimeRoot);
|
|
167
|
+
}
|
|
168
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
169
|
+
if (result.status === 'BROKEN') process.exitCode = 2;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
process.stderr.write(`[host-bridge-lifecycle] ${error instanceof Error ? error.message : String(error)}\n`);
|
|
172
|
+
process.exitCode = 2;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provider-neutral host bridge connecting AI coding hosts (Antigravity, Codex, Claude)
|
|
5
|
+
* to the AFYX Universal Interoperability Runtime.
|
|
6
|
+
*
|
|
7
|
+
* Implements supported, verifiable host entrypoints:
|
|
8
|
+
* 1. Programmatic API: invokeHostWorkflow(options)
|
|
9
|
+
* 2. CLI Entrypoint: node scripts/afyx-host-bridge.mjs --task '<json>' ...
|
|
10
|
+
* 3. JSON-RPC 2.0 Stdio MCP Server: node scripts/afyx-host-bridge.mjs serve --mcp
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { resolve } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import readline from 'node:readline';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
runInstalledAfyxWorkflow,
|
|
20
|
+
} from './afyx-universal-runtime.mjs';
|
|
21
|
+
|
|
22
|
+
export const AFYX_HOST_BRIDGE_CONTRACT = 'AfyxHostBridge/v1';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes host invocation options and runs the installed AFYX workflow.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options
|
|
28
|
+
* @param {Object|string} options.task - Engineering task specification
|
|
29
|
+
* @param {string} [options.projectRoot] - Root directory of the target project
|
|
30
|
+
* @param {string} [options.installRoot] - Root directory where AFYX components are installed
|
|
31
|
+
* @param {string} [options.provider] - Host provider: 'antigravity', 'codex', or 'claude'
|
|
32
|
+
* @param {Object} [options.authorizations] - Map of authorized component IDs
|
|
33
|
+
* @param {Object} [options.providerPermissions] - Map of provider permissions
|
|
34
|
+
* @param {Object} [options.budgetLimits] - Budget limits override
|
|
35
|
+
* @param {Object} [options.environment] - Environment variables
|
|
36
|
+
* @param {Object} [options.trustedSkillEngineering] - Host-supplied plan and approval callback; never MCP tool input
|
|
37
|
+
* @returns {Promise<Object>} Workflow execution result with host bridge envelope
|
|
38
|
+
*/
|
|
39
|
+
export async function invokeHostWorkflow({
|
|
40
|
+
task = {},
|
|
41
|
+
projectRoot = process.cwd(),
|
|
42
|
+
installRoot = process.env.AFYX_INSTALL_ROOT || null,
|
|
43
|
+
provider = 'antigravity',
|
|
44
|
+
authorizations = {},
|
|
45
|
+
providerPermissions = null,
|
|
46
|
+
budgetLimits = undefined,
|
|
47
|
+
environment = process.env,
|
|
48
|
+
trustedSkillEngineering = null,
|
|
49
|
+
} = {}) {
|
|
50
|
+
const parsedTask = typeof task === 'string' ? JSON.parse(task) : task;
|
|
51
|
+
const resolvedProjectRoot = resolve(projectRoot);
|
|
52
|
+
const resolvedInstallRoot = installRoot ? resolve(installRoot) : null;
|
|
53
|
+
const permissions = providerPermissions ?? authorizations;
|
|
54
|
+
|
|
55
|
+
const workflowResult = await runInstalledAfyxWorkflow({
|
|
56
|
+
task: parsedTask,
|
|
57
|
+
projectRoot: resolvedProjectRoot,
|
|
58
|
+
installRoot: resolvedInstallRoot,
|
|
59
|
+
provider,
|
|
60
|
+
authorizations,
|
|
61
|
+
providerPermissions: permissions,
|
|
62
|
+
budgetLimits,
|
|
63
|
+
environment,
|
|
64
|
+
trustedSkillEngineering,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...workflowResult,
|
|
69
|
+
bridgeContract: AFYX_HOST_BRIDGE_CONTRACT,
|
|
70
|
+
host: {
|
|
71
|
+
provider,
|
|
72
|
+
projectRoot: resolvedProjectRoot,
|
|
73
|
+
timestamp: new Date().toISOString(),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Runs a lightweight stdio MCP server for host environments that interact via MCP.
|
|
80
|
+
*
|
|
81
|
+
* @param {Object} [serverOptions]
|
|
82
|
+
* @param {string} [serverOptions.installRoot]
|
|
83
|
+
* @param {string} [serverOptions.projectRoot]
|
|
84
|
+
* @param {string} [serverOptions.provider]
|
|
85
|
+
*/
|
|
86
|
+
export function serveHostMcpBridge(serverOptions = {}) {
|
|
87
|
+
const rl = readline.createInterface({
|
|
88
|
+
input: process.stdin,
|
|
89
|
+
output: process.stdout,
|
|
90
|
+
terminal: false,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const sendResponse = (response) => {
|
|
94
|
+
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
rl.on('close', () => {
|
|
98
|
+
process.exit(0);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
rl.on('line', async (line) => {
|
|
102
|
+
const trimmed = line.trim();
|
|
103
|
+
if (!trimmed) return;
|
|
104
|
+
|
|
105
|
+
let request;
|
|
106
|
+
try {
|
|
107
|
+
request = JSON.parse(trimmed);
|
|
108
|
+
} catch {
|
|
109
|
+
sendResponse({
|
|
110
|
+
jsonrpc: '2.0',
|
|
111
|
+
id: null,
|
|
112
|
+
error: { code: -32700, message: 'Parse error: invalid JSON' },
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const { id, method, params } = request;
|
|
118
|
+
|
|
119
|
+
// Handle JSON-RPC notifications (no id)
|
|
120
|
+
if (id === undefined || id === null) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
switch (method) {
|
|
125
|
+
case 'initialize': {
|
|
126
|
+
sendResponse({
|
|
127
|
+
jsonrpc: '2.0',
|
|
128
|
+
id,
|
|
129
|
+
result: {
|
|
130
|
+
protocolVersion: '2024-11-05',
|
|
131
|
+
capabilities: {
|
|
132
|
+
tools: {},
|
|
133
|
+
},
|
|
134
|
+
serverInfo: {
|
|
135
|
+
name: 'afyx-universal-host-bridge',
|
|
136
|
+
version: '1.0.0',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
case 'tools/list': {
|
|
144
|
+
sendResponse({
|
|
145
|
+
jsonrpc: '2.0',
|
|
146
|
+
id,
|
|
147
|
+
result: {
|
|
148
|
+
tools: [
|
|
149
|
+
{
|
|
150
|
+
name: 'afyx_workflow',
|
|
151
|
+
description: 'Execute task-driven AFYX capability workflow for the host environment.',
|
|
152
|
+
inputSchema: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
task: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
description: 'The engineering task specification',
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
required: ['task'],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
case 'tools/call': {
|
|
170
|
+
if (params?.name !== 'afyx_workflow') {
|
|
171
|
+
sendResponse({
|
|
172
|
+
jsonrpc: '2.0',
|
|
173
|
+
id,
|
|
174
|
+
error: { code: -32601, message: `Unknown tool: ${params?.name}` },
|
|
175
|
+
});
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
const args = params.arguments || {};
|
|
181
|
+
const result = await invokeHostWorkflow({
|
|
182
|
+
task: args.task,
|
|
183
|
+
budgetLimits: args.budgetLimits,
|
|
184
|
+
...serverOptions,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
sendResponse({
|
|
188
|
+
jsonrpc: '2.0',
|
|
189
|
+
id,
|
|
190
|
+
result: {
|
|
191
|
+
content: [
|
|
192
|
+
{
|
|
193
|
+
type: 'text',
|
|
194
|
+
text: JSON.stringify(result, null, 2),
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
} catch (err) {
|
|
200
|
+
sendResponse({
|
|
201
|
+
jsonrpc: '2.0',
|
|
202
|
+
id,
|
|
203
|
+
error: {
|
|
204
|
+
code: -32000,
|
|
205
|
+
message: err instanceof Error ? err.message : String(err),
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
default: {
|
|
213
|
+
sendResponse({
|
|
214
|
+
jsonrpc: '2.0',
|
|
215
|
+
id,
|
|
216
|
+
error: { code: -32601, message: `Method not found: ${method}` },
|
|
217
|
+
});
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return rl;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function argumentValue(flag) {
|
|
227
|
+
const index = process.argv.indexOf(flag);
|
|
228
|
+
return index >= 0 && index + 1 < process.argv.length ? process.argv[index + 1] : null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function main() {
|
|
232
|
+
if (process.argv.includes('--mcp') || (process.argv.includes('serve') && process.argv.includes('--mcp'))) {
|
|
233
|
+
const installRoot = argumentValue('--install-root');
|
|
234
|
+
const projectRoot = argumentValue('--project-root');
|
|
235
|
+
const provider = argumentValue('--provider') || 'antigravity';
|
|
236
|
+
const authorizedIds = new Set((argumentValue('--authorize') ?? '').split(',').filter(Boolean));
|
|
237
|
+
const authorizations = Object.fromEntries([...authorizedIds].map((id) => [id, true]));
|
|
238
|
+
serveHostMcpBridge({
|
|
239
|
+
installRoot,
|
|
240
|
+
projectRoot,
|
|
241
|
+
provider,
|
|
242
|
+
authorizations,
|
|
243
|
+
providerPermissions: authorizations,
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const installRoot = argumentValue('--install-root') || process.env.AFYX_INSTALL_ROOT;
|
|
249
|
+
const projectRoot = argumentValue('--project-root') || process.cwd();
|
|
250
|
+
const provider = argumentValue('--provider') || 'antigravity';
|
|
251
|
+
const taskArg = argumentValue('--task');
|
|
252
|
+
const taskFile = argumentValue('--task-file');
|
|
253
|
+
const authorizedIds = new Set((argumentValue('--authorize') ?? '').split(',').filter(Boolean));
|
|
254
|
+
|
|
255
|
+
let task = null;
|
|
256
|
+
if (taskArg) {
|
|
257
|
+
task = JSON.parse(taskArg);
|
|
258
|
+
} else if (taskFile) {
|
|
259
|
+
if (taskFile === '-') {
|
|
260
|
+
task = JSON.parse(readFileSync(0, 'utf8'));
|
|
261
|
+
} else {
|
|
262
|
+
task = JSON.parse(readFileSync(resolve(taskFile), 'utf8'));
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
throw new Error('Either --task <json> or --task-file <file> is required');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const authorizations = Object.fromEntries([...authorizedIds].map((id) => [id, true]));
|
|
269
|
+
const result = await invokeHostWorkflow({
|
|
270
|
+
installRoot,
|
|
271
|
+
projectRoot,
|
|
272
|
+
task,
|
|
273
|
+
provider,
|
|
274
|
+
authorizations,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
278
|
+
if (result.status === 'FAILED' || result.status === 'BLOCKED') {
|
|
279
|
+
process.exitCode = 2;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
|
284
|
+
main().catch((error) => {
|
|
285
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
286
|
+
process.exitCode = 1;
|
|
287
|
+
});
|
|
288
|
+
}
|