Lines 1-109javascript
3 * VANEXA AGENT - Sovereign Digital Brain
4 * V8 Bytecode Launcher with Runtime Version Guard
6import path from 'path';
8import { fileURLToPath } from 'url';
10import bytenode from 'bytenode';
11import { createRequire } from 'module';
12import { UI } from '../src/utils/cli_ui.js';
14const require = createRequire(import.meta.url);
15const __filename = fileURLToPath(import.meta.url);
MediumDynamic Require
Package source references dynamic require/import behavior.
bin/vanexa-agent.jsView on unpkg · L13 16const __dirname = path.dirname(__filename);
18// ── V8 Version Guard ──
19// V8 bytecode is NOT portable across V8 engine versions.
20// The .jsc file MUST be loaded by the same V8 major version that compiled it.
21const REQUIRED_NODE_MAJOR = 24;
22const userNodeMajor = parseInt(process.versions.node.split('.')[0], 10);
24if (userNodeMajor < REQUIRED_NODE_MAJOR) {
25 UI.printFatalBox('FATAL: Node.js Version Mismatch', [
26 `Your Node.js: v${process.versions.node} (V8 ${process.versions.v8})`,
27 `Required: v${REQUIRED_NODE_MAJOR}.x LTS or higher`,
29 `Vanexa Agent uses V8 bytecode compiled for Node.js v24 LTS.`,
30 `The bytecode is incompatible with older Node.js versions.`,
32 `➤ Fix: Install Node.js v24 LTS from https://nodejs.org`,
34 `Quick install commands:`,
35 ` macOS/Linux: nvm install 24 && nvm use 24`,
36 ` Windows: winget install OpenJS.NodeJS.LTS`
41// Optimize V8 memory flag for bytecode execution
42v8.setFlagsFromString('--no-flush-bytecode');
44const bytecodePath = path.join(__dirname, '../dist/bundle.jsc');
45const cjsPath = path.join(__dirname, '../dist/bundle.cjs');
MediumAi Review Evidence
CLI executes an opaque 3.6 MB V8 bytecode bundle.
bin/vanexa-agent.jsView on unpkg · L44 47// Helper function to recompile local bytecode when V8 engine differs or .jsc is missing
48function tryAutoCompileBytecode() {
49 if (fs.existsSync(cjsPath)) {
50 console.log('⚡ V8 engine adaptation or upgrade detected.');
51 console.log(` Optimizing local V8 bytecode for Node.js v${process.versions.node} (V8 ${process.versions.v8})...`);
53 bytenode.compileFile({
57 const stampPath = path.join(__dirname, '../dist/.v8-version');
58 const stampContent = [
59 `node=${process.versions.node}`,
60 `v8=${process.versions.v8}`,
61 `platform=${process.platform}`,
62 `arch=${process.arch}`,
63 `compiled=${new Date().toISOString()}`,
64 `required_node_major=24`
70 console.error('⚠ Auto-compile warning:', e.message);
77// Check if bytecode file exists, if not try to auto compile
78if (!fs.existsSync(bytecodePath)) {
79 if (!tryAutoCompileBytecode() || !fs.existsSync(bytecodePath)) {
80 UI.printFatalBox('FATAL: Bytecode file not found', [
81 `File missing at: ${bytecodePath}`,
82 `The package may be corrupted.`,
83 `Try: npm install -g @vanexalabs-ai/vanexa-agent@latest`
89function loadAgentBrain() {
91 // Execute the protected proprietary brain
92 require(bytecodePath);
MediumAi Review Evidence
CLI executes an opaque 3.6 MB V8 bytecode bundle.
bin/vanexa-agent.jsView on unpkg · L89 94 const isBytecodeMismatch = error && error.message && (
95 error.message.includes('cachedDataRejected') ||
96 error.message.includes('Invalid bytecode') ||
97 error.message.includes('bytecode') ||
98 error.message.includes('Invalid or incompatible') ||
99 error.message.includes('bad bytecode')
102 if (isBytecodeMismatch) {
103 if (tryAutoCompileBytecode() && fs.existsSync(bytecodePath)) {
105 delete require.cache[require.resolve(bytecodePath)];
106 require(bytecodePath);
108 } catch (retryError) {