@evomap/evolver 1.78.10 → 1.79.0
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/README.ja-JP.md +1 -0
- package/README.ko-KR.md +1 -0
- package/README.md +1 -0
- package/README.zh-CN.md +1 -0
- package/index.js +125 -1
- package/package.json +1 -1
- package/scripts/build_binaries.js +388 -0
- package/src/evolve.js +1 -1
- package/src/gep/.integrity +0 -0
- package/src/gep/a2aProtocol.js +1 -1
- package/src/gep/candidateEval.js +1 -1
- package/src/gep/candidates.js +1 -1
- package/src/gep/contentHash.js +1 -1
- package/src/gep/crypto.js +1 -1
- package/src/gep/curriculum.js +1 -1
- package/src/gep/deviceId.js +1 -1
- package/src/gep/envFingerprint.js +1 -1
- package/src/gep/explore.js +1 -1
- package/src/gep/hubReview.js +1 -1
- package/src/gep/hubSearch.js +1 -1
- package/src/gep/hubVerify.js +1 -1
- package/src/gep/integrityCheck.js +1 -1
- package/src/gep/learningSignals.js +1 -1
- package/src/gep/memoryGraph.js +1 -1
- package/src/gep/memoryGraphAdapter.js +1 -1
- package/src/gep/mutation.js +1 -1
- package/src/gep/narrativeMemory.js +1 -1
- package/src/gep/personality.js +1 -1
- package/src/gep/policyCheck.js +1 -1
- package/src/gep/prompt.js +1 -1
- package/src/gep/reflection.js +1 -1
- package/src/gep/selector.js +1 -1
- package/src/gep/shield.js +1 -1
- package/src/gep/skillDistiller.js +1 -1
- package/src/gep/solidify.js +1 -1
- package/src/gep/strategy.js +1 -1
- package/assets/gep/candidates.jsonl +0 -1
- package/assets/gep/capsules.json +0 -4
- package/assets/gep/events.jsonl +0 -0
- package/assets/gep/failed_capsules.json +0 -4
- package/assets/gep/genes.json +0 -201
- package/assets/gep/genes.jsonl +0 -0
package/README.ja-JP.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/GPL-3.0)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://github.com/EvoMap/evolver/commits/main)
|
|
7
|
+
[](https://www.npmjs.com/package/@evomap/evolver)
|
|
7
8
|
[](https://github.com/EvoMap/evolver/issues)
|
|
8
9
|
[](https://arxiv.org/abs/2604.15097)
|
|
9
10
|
|
package/README.ko-KR.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/GPL-3.0)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://github.com/EvoMap/evolver/commits/main)
|
|
7
|
+
[](https://www.npmjs.com/package/@evomap/evolver)
|
|
7
8
|
[](https://github.com/EvoMap/evolver/issues)
|
|
8
9
|
[](https://arxiv.org/abs/2604.15097)
|
|
9
10
|
|
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/GPL-3.0)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://github.com/EvoMap/evolver/commits/main)
|
|
7
|
+
[](https://www.npmjs.com/package/@evomap/evolver)
|
|
7
8
|
[](https://github.com/EvoMap/evolver/issues)
|
|
8
9
|
[](https://arxiv.org/abs/2604.15097)
|
|
9
10
|
|
package/README.zh-CN.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/GPL-3.0)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://github.com/EvoMap/evolver/commits/main)
|
|
7
|
+
[](https://www.npmjs.com/package/@evomap/evolver)
|
|
7
8
|
[](https://github.com/EvoMap/evolver/issues)
|
|
8
9
|
[](https://arxiv.org/abs/2604.15097)
|
|
9
10
|
|
package/index.js
CHANGED
|
@@ -104,6 +104,42 @@ function parseMs(v, fallback) {
|
|
|
104
104
|
return fallback;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
function parseBoolEnv(v, fallback) {
|
|
108
|
+
if (v == null) return fallback;
|
|
109
|
+
const s = String(v).toLowerCase().trim();
|
|
110
|
+
if (s === '' ) return fallback;
|
|
111
|
+
if (s === 'false' || s === '0' || s === 'off' || s === 'no') return false;
|
|
112
|
+
if (s === 'true' || s === '1' || s === 'on' || s === 'yes') return true;
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
class CycleTimeoutError extends Error {
|
|
117
|
+
constructor(timeoutMs, phase, cycleNum) {
|
|
118
|
+
super('Cycle hard-timeout exceeded after ' + timeoutMs + 'ms (cycle=' + cycleNum + ', phase=' + phase + ')');
|
|
119
|
+
this.name = 'CycleTimeoutError';
|
|
120
|
+
this.code = 'CYCLE_TIMEOUT';
|
|
121
|
+
this.timeoutMs = timeoutMs;
|
|
122
|
+
this.phase = phase;
|
|
123
|
+
this.cycleNum = cycleNum;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Atomic write of the cycle_progress.json file. Wrapper polls this file every
|
|
128
|
+
// 60s; if updated_at goes stale beyond EVOLVE_INNER_STUCK_TIMEOUT_SEC the
|
|
129
|
+
// wrapper treats the inner core as zombie and SIGKILLs it. See Issue #19 (the
|
|
130
|
+
// 22-day stuck-cycle incident) and the cross-repo timeout plan for context.
|
|
131
|
+
function writeCycleProgressAtomic(progressPath, fields) {
|
|
132
|
+
try {
|
|
133
|
+
const data = Object.assign({}, fields, { updated_at: Date.now() });
|
|
134
|
+
const tmp = progressPath + '.tmp.' + process.pid;
|
|
135
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
136
|
+
fs.renameSync(tmp, progressPath);
|
|
137
|
+
return true;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
107
143
|
function getLastSignals(statePath) {
|
|
108
144
|
try {
|
|
109
145
|
const st = readJsonSafe(statePath);
|
|
@@ -255,6 +291,7 @@ async function main() {
|
|
|
255
291
|
|
|
256
292
|
const { getEvolutionDir, getEvolverLogPath } = require('./src/gep/paths');
|
|
257
293
|
const solidifyStatePath = path.join(getEvolutionDir(), 'evolution_solidify_state.json');
|
|
294
|
+
const cycleProgressPath = path.join(getEvolutionDir(), 'cycle_progress.json');
|
|
258
295
|
|
|
259
296
|
const minSleepMs = parseMs(process.env.EVOLVER_MIN_SLEEP_MS, 2000);
|
|
260
297
|
const maxSleepMs = parseMs(process.env.EVOLVER_MAX_SLEEP_MS, 300000);
|
|
@@ -270,6 +307,15 @@ async function main() {
|
|
|
270
307
|
const maxRssMb = parseMs(process.env.EVOLVER_MAX_RSS_MB, 500) || 500;
|
|
271
308
|
const suicideEnabled = String(process.env.EVOLVER_SUICIDE || '').toLowerCase() !== 'false';
|
|
272
309
|
|
|
310
|
+
// Issue #19: hard timeout around evolve.run() to break out of zombie
|
|
311
|
+
// cycles (e.g. unclosed socket / stuck LLM call). On timeout we throw
|
|
312
|
+
// CycleTimeoutError, log diagnostic stderr, and force suicide-respawn
|
|
313
|
+
// so the wrapper sees a fresh PID + cycle. Also write cycle_progress
|
|
314
|
+
// every progressUpdateMs so the wrapper has a true heartbeat to poll.
|
|
315
|
+
const cycleTimeoutEnabled = parseBoolEnv(process.env.EVOLVER_CYCLE_TIMEOUT_ENABLED, true);
|
|
316
|
+
const cycleTimeoutMs = parseMs(process.env.EVOLVER_CYCLE_TIMEOUT_MS, 2700000); // 45 min default
|
|
317
|
+
const progressUpdateMs = parseMs(process.env.EVOLVER_PROGRESS_UPDATE_MS, 60000); // 1 min default
|
|
318
|
+
|
|
273
319
|
// Start hub heartbeat (keeps node alive independently of evolution cycles)
|
|
274
320
|
try {
|
|
275
321
|
if (process.env.EVOMAP_PROXY === '1' || process.env.A2A_TRANSPORT === 'mailbox') {
|
|
@@ -388,8 +434,46 @@ async function main() {
|
|
|
388
434
|
|
|
389
435
|
const t0 = Date.now();
|
|
390
436
|
let ok = false;
|
|
437
|
+
// Issue #19: write progress at cycle start, refresh it every
|
|
438
|
+
// progressUpdateMs (default 60s) while evolve.run() is active, and
|
|
439
|
+
// wrap evolve.run() with Promise.race(timeout) so a hung internal
|
|
440
|
+
// call cannot freeze the daemon for days.
|
|
441
|
+
writeCycleProgressAtomic(cycleProgressPath, {
|
|
442
|
+
pid: process.pid,
|
|
443
|
+
outer_cycle: cycleCount,
|
|
444
|
+
inner_cycle: cycleCount,
|
|
445
|
+
started_at: t0,
|
|
446
|
+
phase: 'evolve.run',
|
|
447
|
+
});
|
|
448
|
+
let progressTicker = null;
|
|
449
|
+
if (progressUpdateMs > 0) {
|
|
450
|
+
progressTicker = setInterval(function () {
|
|
451
|
+
writeCycleProgressAtomic(cycleProgressPath, {
|
|
452
|
+
pid: process.pid,
|
|
453
|
+
outer_cycle: cycleCount,
|
|
454
|
+
inner_cycle: cycleCount,
|
|
455
|
+
started_at: t0,
|
|
456
|
+
phase: 'evolve.run',
|
|
457
|
+
});
|
|
458
|
+
}, progressUpdateMs);
|
|
459
|
+
if (typeof progressTicker.unref === 'function') progressTicker.unref();
|
|
460
|
+
}
|
|
461
|
+
let cycleTimeoutHandle = null;
|
|
462
|
+
let cycleTimedOut = false;
|
|
391
463
|
try {
|
|
392
|
-
|
|
464
|
+
const evolvePromise = evolve.run();
|
|
465
|
+
if (cycleTimeoutEnabled && cycleTimeoutMs > 0) {
|
|
466
|
+
const timeoutPromise = new Promise(function (_, reject) {
|
|
467
|
+
cycleTimeoutHandle = setTimeout(function () {
|
|
468
|
+
cycleTimedOut = true;
|
|
469
|
+
reject(new CycleTimeoutError(cycleTimeoutMs, 'evolve.run', cycleCount));
|
|
470
|
+
}, cycleTimeoutMs);
|
|
471
|
+
if (cycleTimeoutHandle && typeof cycleTimeoutHandle.unref === 'function') cycleTimeoutHandle.unref();
|
|
472
|
+
});
|
|
473
|
+
await Promise.race([evolvePromise, timeoutPromise]);
|
|
474
|
+
} else {
|
|
475
|
+
await evolvePromise;
|
|
476
|
+
}
|
|
393
477
|
ok = true;
|
|
394
478
|
|
|
395
479
|
if (String(process.env.EVOLVE_BRIDGE || '').toLowerCase() === 'false') {
|
|
@@ -403,7 +487,37 @@ async function main() {
|
|
|
403
487
|
}
|
|
404
488
|
} catch (error) {
|
|
405
489
|
const msg = error && error.message ? String(error.message) : String(error);
|
|
490
|
+
if (error && error.code === 'CYCLE_TIMEOUT') {
|
|
491
|
+
console.error('[Daemon] ' + msg);
|
|
492
|
+
if (progressTicker) { clearInterval(progressTicker); progressTicker = null; }
|
|
493
|
+
if (cycleTimeoutHandle) { clearTimeout(cycleTimeoutHandle); cycleTimeoutHandle = null; }
|
|
494
|
+
writeCycleProgressAtomic(cycleProgressPath, {
|
|
495
|
+
pid: process.pid,
|
|
496
|
+
outer_cycle: cycleCount,
|
|
497
|
+
inner_cycle: cycleCount,
|
|
498
|
+
started_at: t0,
|
|
499
|
+
phase: 'cycle_timeout_respawn',
|
|
500
|
+
});
|
|
501
|
+
try {
|
|
502
|
+
const logFd = fs.openSync(getEvolverLogPath(), 'a');
|
|
503
|
+
const spawnOpts = {
|
|
504
|
+
detached: true,
|
|
505
|
+
stdio: ['ignore', logFd, logFd],
|
|
506
|
+
env: process.env,
|
|
507
|
+
windowsHide: true,
|
|
508
|
+
};
|
|
509
|
+
const child = spawn(process.execPath, [__filename, ...args], spawnOpts);
|
|
510
|
+
child.unref();
|
|
511
|
+
} catch (spawnErr) {
|
|
512
|
+
console.error('[Daemon] Force-restart spawn after cycle timeout failed: ' + (spawnErr && spawnErr.message || spawnErr));
|
|
513
|
+
}
|
|
514
|
+
releaseLock();
|
|
515
|
+
process.exit(1);
|
|
516
|
+
}
|
|
406
517
|
console.error(`Evolution cycle failed: ${msg}`);
|
|
518
|
+
} finally {
|
|
519
|
+
if (progressTicker) { clearInterval(progressTicker); progressTicker = null; }
|
|
520
|
+
if (cycleTimeoutHandle) { clearTimeout(cycleTimeoutHandle); cycleTimeoutHandle = null; }
|
|
407
521
|
}
|
|
408
522
|
const dt = Date.now() - t0;
|
|
409
523
|
|
|
@@ -496,6 +610,13 @@ async function main() {
|
|
|
496
610
|
const signals = getLastSignals(solidifyStatePath).join(',');
|
|
497
611
|
console.log(`[Verbose] cycle=${cycleCount} ok=${ok} dt=${dt}ms sleep=${totalSleepMs}ms (base=${currentSleepMs} jitter=${jitter} sat=${saturationMultiplier}x) rss=${memMb}MB signals=[${signals}]`);
|
|
498
612
|
}
|
|
613
|
+
writeCycleProgressAtomic(cycleProgressPath, {
|
|
614
|
+
pid: process.pid,
|
|
615
|
+
outer_cycle: cycleCount,
|
|
616
|
+
inner_cycle: cycleCount,
|
|
617
|
+
started_at: t0,
|
|
618
|
+
phase: 'sleep',
|
|
619
|
+
});
|
|
499
620
|
await sleepMs(totalSleepMs);
|
|
500
621
|
|
|
501
622
|
} catch (loopErr) {
|
|
@@ -1581,4 +1702,7 @@ module.exports = {
|
|
|
1581
1702
|
readJsonSafe,
|
|
1582
1703
|
rejectPendingRun,
|
|
1583
1704
|
isPendingSolidify,
|
|
1705
|
+
parseBoolEnv,
|
|
1706
|
+
CycleTimeoutError,
|
|
1707
|
+
writeCycleProgressAtomic,
|
|
1584
1708
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.79.0",
|
|
4
4
|
"description": "A GEP-powered self-evolution engine for AI agents. Features automated log analysis and Genome Evolution Protocol (GEP) for auditable, reusable evolution assets.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
//
|
|
4
|
+
// build_binaries.js — produce standalone CLI binaries of evolver via the
|
|
5
|
+
// hardened "obfuscator -> bun bundle -> bun compile" pipeline.
|
|
6
|
+
//
|
|
7
|
+
// Pipeline (decided after empirical testing — see notes at end of this file):
|
|
8
|
+
//
|
|
9
|
+
// 1. bun build ./index.js --target=node --outfile=stage/bundled.js
|
|
10
|
+
// -> resolves all require() into one self-contained file.
|
|
11
|
+
//
|
|
12
|
+
// 2. javascript-obfuscator stage/bundled.js -> stage/bundled.obf.js
|
|
13
|
+
// -> high-strength config: stringArray (rc4) + controlFlowFlattening +
|
|
14
|
+
// deadCodeInjection + identifier hex + splitStrings + numbers-to-expr.
|
|
15
|
+
// -> selfDefending MUST be off: it triggers infinite-loop self-defense
|
|
16
|
+
// when bun later wraps the bundle inside its standalone container.
|
|
17
|
+
// -> renameGlobals MUST be off (otherwise bun's bundle step fails to
|
|
18
|
+
// resolve dynamic require strings — but we already pass a single-file
|
|
19
|
+
// bundle here, so this no longer applies; kept off for safety).
|
|
20
|
+
// -> transformObjectKeys MUST be off (similar reason as above).
|
|
21
|
+
//
|
|
22
|
+
// 3. bun build stage/bundled.obf.js --compile --minify --target=<TARGET>
|
|
23
|
+
// -> embeds bun runtime + bundled+obfuscated JS into a single executable.
|
|
24
|
+
// -> --minify gives a second-pass identifier/whitespace squash on top
|
|
25
|
+
// of the obfuscator output.
|
|
26
|
+
//
|
|
27
|
+
// Targets shipped (decision per AGENTS sync 2026-05-05):
|
|
28
|
+
// bun-darwin-arm64 -> evolver-darwin-arm64
|
|
29
|
+
// bun-darwin-x64 -> evolver-darwin-x64
|
|
30
|
+
// bun-linux-x64 -> evolver-linux-x64
|
|
31
|
+
// bun-linux-arm64 -> evolver-linux-arm64
|
|
32
|
+
// bun-windows-x64 -> evolver-windows-x64.exe
|
|
33
|
+
//
|
|
34
|
+
// Usage:
|
|
35
|
+
// node scripts/build_binaries.js # builds all 4 targets
|
|
36
|
+
// node scripts/build_binaries.js --target=darwin-arm64
|
|
37
|
+
// node scripts/build_binaries.js --skip-obfuscate # bun-only fast path (DEV)
|
|
38
|
+
// node scripts/build_binaries.js --out-dir=dist-binaries
|
|
39
|
+
// node scripts/build_binaries.js --dry-run
|
|
40
|
+
//
|
|
41
|
+
// Outputs:
|
|
42
|
+
// <outDir>/evolver-<platform> binary
|
|
43
|
+
// <outDir>/evolver-<platform>.sha256 hash file (one line)
|
|
44
|
+
// <outDir>/SHA256SUMS.txt combined sha256 manifest
|
|
45
|
+
//
|
|
46
|
+
// Exit codes:
|
|
47
|
+
// 0 success
|
|
48
|
+
// 1 precondition failed (missing tool, version mismatch)
|
|
49
|
+
// 2 build step failed
|
|
50
|
+
// 3 smoke test of produced binary failed
|
|
51
|
+
|
|
52
|
+
'use strict';
|
|
53
|
+
|
|
54
|
+
const fs = require('fs');
|
|
55
|
+
const path = require('path');
|
|
56
|
+
const crypto = require('crypto');
|
|
57
|
+
const { execFileSync, spawnSync } = require('child_process');
|
|
58
|
+
|
|
59
|
+
// ---------- argv ----------
|
|
60
|
+
|
|
61
|
+
const argv = process.argv.slice(2);
|
|
62
|
+
const OPTS = {
|
|
63
|
+
target: null,
|
|
64
|
+
skipObfuscate: false,
|
|
65
|
+
outDir: 'dist-binaries',
|
|
66
|
+
dryRun: false,
|
|
67
|
+
keepStage: false,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
for (const a of argv) {
|
|
71
|
+
if (a === '--skip-obfuscate') OPTS.skipObfuscate = true;
|
|
72
|
+
else if (a === '--dry-run') OPTS.dryRun = true;
|
|
73
|
+
else if (a === '--keep-stage') OPTS.keepStage = true;
|
|
74
|
+
else if (a.startsWith('--target=')) OPTS.target = a.slice('--target='.length);
|
|
75
|
+
else if (a.startsWith('--out-dir=')) OPTS.outDir = a.slice('--out-dir='.length);
|
|
76
|
+
else if (a === '--help' || a === '-h') {
|
|
77
|
+
console.log(fs.readFileSync(__filename, 'utf8').split('\n').filter(l => l.startsWith('//')).map(l => l.replace(/^\/\/ ?/, '')).slice(0, 50).join('\n'));
|
|
78
|
+
process.exit(0);
|
|
79
|
+
} else {
|
|
80
|
+
console.error(`build_binaries: unknown argument: ${a}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------- constants ----------
|
|
86
|
+
|
|
87
|
+
const REPO_ROOT = path.resolve(__dirname, '..');
|
|
88
|
+
const ENTRY = path.join(REPO_ROOT, 'index.js');
|
|
89
|
+
const STAGE_DIR = path.join(REPO_ROOT, '.binary-stage');
|
|
90
|
+
const OUT_DIR = path.resolve(REPO_ROOT, OPTS.outDir);
|
|
91
|
+
|
|
92
|
+
const ALL_TARGETS = [
|
|
93
|
+
{ triple: 'bun-darwin-arm64', name: 'evolver-darwin-arm64' },
|
|
94
|
+
{ triple: 'bun-darwin-x64', name: 'evolver-darwin-x64' },
|
|
95
|
+
{ triple: 'bun-linux-x64', name: 'evolver-linux-x64' },
|
|
96
|
+
{ triple: 'bun-linux-arm64', name: 'evolver-linux-arm64' },
|
|
97
|
+
{ triple: 'bun-windows-x64', name: 'evolver-windows-x64.exe' },
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const TARGETS = OPTS.target
|
|
101
|
+
? ALL_TARGETS.filter(t => t.name.endsWith(OPTS.target) || t.triple.endsWith(OPTS.target))
|
|
102
|
+
: ALL_TARGETS;
|
|
103
|
+
|
|
104
|
+
if (TARGETS.length === 0) {
|
|
105
|
+
console.error(`build_binaries: target "${OPTS.target}" matched no known triple. Known: ${ALL_TARGETS.map(t => t.triple).join(', ')}`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------- helpers ----------
|
|
110
|
+
|
|
111
|
+
function step(label) {
|
|
112
|
+
console.log(`\n>> ${label}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function run(cmd, args, opts = {}) {
|
|
116
|
+
if (OPTS.dryRun) {
|
|
117
|
+
console.log(` [dry-run] ${cmd} ${args.join(' ')}`);
|
|
118
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
119
|
+
}
|
|
120
|
+
const r = spawnSync(cmd, args, { stdio: 'inherit', ...opts });
|
|
121
|
+
if (r.status !== 0) {
|
|
122
|
+
console.error(` command failed (exit ${r.status}): ${cmd} ${args.join(' ')}`);
|
|
123
|
+
process.exit(2);
|
|
124
|
+
}
|
|
125
|
+
return r;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function runCapture(cmd, args, opts = {}) {
|
|
129
|
+
// Preflight version checks must always run (even in dry-run mode); use this
|
|
130
|
+
// helper only for read-only commands.
|
|
131
|
+
return execFileSync(cmd, args, { encoding: 'utf8', ...opts });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function ensureDir(d) {
|
|
135
|
+
if (!fs.existsSync(d)) fs.mkdirSync(d, { recursive: true });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function rmDir(d) {
|
|
139
|
+
if (fs.existsSync(d)) fs.rmSync(d, { recursive: true, force: true });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function sha256(filePath) {
|
|
143
|
+
const buf = fs.readFileSync(filePath);
|
|
144
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ---------- preflight ----------
|
|
148
|
+
|
|
149
|
+
step('Preflight');
|
|
150
|
+
|
|
151
|
+
if (!fs.existsSync(ENTRY)) {
|
|
152
|
+
console.error(` ERROR: entry not found: ${ENTRY}`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
const v = runCapture('bun', ['--version']).trim();
|
|
158
|
+
console.log(` bun: ${v}`);
|
|
159
|
+
// Pin a sane minimum. As of writing pipeline tested on 1.3.13.
|
|
160
|
+
const [maj, min] = v.split('.').map(Number);
|
|
161
|
+
if (maj < 1 || (maj === 1 && min < 3)) {
|
|
162
|
+
console.error(` ERROR: bun >= 1.3 required; found ${v}`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
console.error(' ERROR: `bun` not found in PATH. Install from https://bun.com');
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!OPTS.skipObfuscate) {
|
|
171
|
+
try {
|
|
172
|
+
require.resolve('javascript-obfuscator', { paths: [REPO_ROOT] });
|
|
173
|
+
console.log(' javascript-obfuscator: present');
|
|
174
|
+
} catch {
|
|
175
|
+
console.error(' ERROR: javascript-obfuscator not installed. Run `npm install` in repo root first.');
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const releaseVersion = process.env.RELEASE_VERSION
|
|
181
|
+
|| JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'package.json'), 'utf8')).version;
|
|
182
|
+
console.log(` release version: ${releaseVersion}`);
|
|
183
|
+
console.log(` targets: ${TARGETS.map(t => t.name).join(', ')}`);
|
|
184
|
+
console.log(` out dir: ${OUT_DIR}`);
|
|
185
|
+
if (OPTS.skipObfuscate) console.log(' WARN: --skip-obfuscate => DEV-grade binary, do NOT distribute');
|
|
186
|
+
if (OPTS.dryRun) console.log(' mode: DRY RUN (no files will change)');
|
|
187
|
+
|
|
188
|
+
// ---------- stage 1: bun bundle ----------
|
|
189
|
+
|
|
190
|
+
step('Stage 1 — bun bundle (resolve require tree to one file)');
|
|
191
|
+
|
|
192
|
+
ensureDir(STAGE_DIR);
|
|
193
|
+
const BUNDLED_JS = path.join(STAGE_DIR, 'bundled.js');
|
|
194
|
+
|
|
195
|
+
run('bun', ['build', ENTRY, '--target=node', `--outfile=${BUNDLED_JS}`]);
|
|
196
|
+
|
|
197
|
+
const bundleSize = OPTS.dryRun ? 0 : fs.statSync(BUNDLED_JS).size;
|
|
198
|
+
console.log(` bundled.js: ${(bundleSize / 1024 / 1024).toFixed(2)} MB`);
|
|
199
|
+
|
|
200
|
+
// ---------- stage 2: obfuscate ----------
|
|
201
|
+
|
|
202
|
+
let payloadJs = BUNDLED_JS;
|
|
203
|
+
|
|
204
|
+
if (!OPTS.skipObfuscate) {
|
|
205
|
+
step('Stage 2 — javascript-obfuscator (high strength, bundler-safe)');
|
|
206
|
+
const OBF_JS = path.join(STAGE_DIR, 'bundled.obf.js');
|
|
207
|
+
|
|
208
|
+
if (!OPTS.dryRun) {
|
|
209
|
+
const O = require(require.resolve('javascript-obfuscator', { paths: [REPO_ROOT] }));
|
|
210
|
+
const src = fs.readFileSync(BUNDLED_JS, 'utf8');
|
|
211
|
+
// Deterministic obfuscation: same release version + same source = same
|
|
212
|
+
// output. This makes binary diffs across re-runs meaningful and lets
|
|
213
|
+
// SHA256SUMS be reproduced by anyone with the source tree.
|
|
214
|
+
const seed = parseInt(crypto.createHash('sha256').update(`evolver:${releaseVersion}`).digest('hex').slice(0, 8), 16);
|
|
215
|
+
const t0 = Date.now();
|
|
216
|
+
const result = O.obfuscate(src, {
|
|
217
|
+
seed,
|
|
218
|
+
compact: true,
|
|
219
|
+
controlFlowFlattening: true,
|
|
220
|
+
controlFlowFlatteningThreshold: 0.75,
|
|
221
|
+
deadCodeInjection: true,
|
|
222
|
+
deadCodeInjectionThreshold: 0.4,
|
|
223
|
+
stringArray: true,
|
|
224
|
+
stringArrayEncoding: ['rc4'],
|
|
225
|
+
stringArrayThreshold: 0.85,
|
|
226
|
+
identifierNamesGenerator: 'hexadecimal',
|
|
227
|
+
// The next three MUST stay disabled — they are incompatible with bun's
|
|
228
|
+
// standalone wrapping (selfDefending + transformObjectKeys + renameGlobals
|
|
229
|
+
// each break either compile-time bundling or run-time module resolution).
|
|
230
|
+
// See pipeline notes at top of file.
|
|
231
|
+
renameGlobals: false,
|
|
232
|
+
selfDefending: false,
|
|
233
|
+
transformObjectKeys: false,
|
|
234
|
+
debugProtection: false,
|
|
235
|
+
splitStrings: true,
|
|
236
|
+
splitStringsChunkLength: 8,
|
|
237
|
+
numbersToExpressions: true,
|
|
238
|
+
unicodeEscapeSequence: true,
|
|
239
|
+
target: 'node',
|
|
240
|
+
});
|
|
241
|
+
fs.writeFileSync(OBF_JS, result.getObfuscatedCode());
|
|
242
|
+
const obfSize = fs.statSync(OBF_JS).size;
|
|
243
|
+
console.log(` obfuscation: ${((Date.now() - t0) / 1000).toFixed(1)}s, output ${(obfSize / 1024 / 1024).toFixed(2)} MB`);
|
|
244
|
+
} else {
|
|
245
|
+
console.log(' [dry-run] would obfuscate stage/bundled.js -> stage/bundled.obf.js');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
payloadJs = OBF_JS;
|
|
249
|
+
} else {
|
|
250
|
+
console.log('\n>> Stage 2 — SKIPPED (--skip-obfuscate)');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ---------- stage 3: per-target compile ----------
|
|
254
|
+
|
|
255
|
+
step(`Stage 3 — bun compile (${TARGETS.length} target${TARGETS.length === 1 ? '' : 's'})`);
|
|
256
|
+
|
|
257
|
+
// Idempotency: scrub OUT_DIR up front so stale binaries from a prior partial
|
|
258
|
+
// run can't leak into a subsequent `gh release upload dist-binaries/*`.
|
|
259
|
+
if (!OPTS.dryRun) {
|
|
260
|
+
rmDir(OUT_DIR);
|
|
261
|
+
}
|
|
262
|
+
ensureDir(OUT_DIR);
|
|
263
|
+
const sums = [];
|
|
264
|
+
|
|
265
|
+
for (const t of TARGETS) {
|
|
266
|
+
const outPath = path.join(OUT_DIR, t.name);
|
|
267
|
+
console.log(`\n --- ${t.triple} -> ${path.relative(REPO_ROOT, outPath)} ---`);
|
|
268
|
+
|
|
269
|
+
run('bun', [
|
|
270
|
+
'build',
|
|
271
|
+
payloadJs,
|
|
272
|
+
'--compile',
|
|
273
|
+
'--minify',
|
|
274
|
+
`--target=${t.triple}`,
|
|
275
|
+
`--outfile=${outPath}`,
|
|
276
|
+
]);
|
|
277
|
+
|
|
278
|
+
if (!OPTS.dryRun) {
|
|
279
|
+
const stat = fs.statSync(outPath);
|
|
280
|
+
fs.chmodSync(outPath, 0o755);
|
|
281
|
+
const hash = sha256(outPath);
|
|
282
|
+
fs.writeFileSync(`${outPath}.sha256`, `${hash} ${t.name}\n`);
|
|
283
|
+
sums.push(`${hash} ${t.name}`);
|
|
284
|
+
console.log(` size: ${(stat.size / 1024 / 1024).toFixed(1)} MB sha256: ${hash.slice(0, 16)}…`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Smoke test only the host platform binary (cross-platform binaries cannot
|
|
289
|
+
// be executed on the build host without an emulator; skip them by design).
|
|
290
|
+
const hostTriple = (() => {
|
|
291
|
+
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
|
|
292
|
+
const plat = process.platform === 'darwin' ? 'darwin'
|
|
293
|
+
: process.platform === 'linux' ? 'linux'
|
|
294
|
+
: process.platform === 'win32' ? 'windows'
|
|
295
|
+
: null;
|
|
296
|
+
return plat ? `${plat}-${arch}` : null;
|
|
297
|
+
})();
|
|
298
|
+
|
|
299
|
+
if (!OPTS.dryRun && hostTriple) {
|
|
300
|
+
// Match against the triple suffix (e.g. "darwin-arm64"), since the binary
|
|
301
|
+
// name on Windows includes a ".exe" extension.
|
|
302
|
+
const hostBin = TARGETS.find(t => t.triple.endsWith(hostTriple));
|
|
303
|
+
if (hostBin) {
|
|
304
|
+
step(`Stage 4 — smoke test ${hostBin.name}`);
|
|
305
|
+
const r = spawnSync(path.join(OUT_DIR, hostBin.name), ['--help'], {
|
|
306
|
+
timeout: 15000,
|
|
307
|
+
encoding: 'utf8',
|
|
308
|
+
});
|
|
309
|
+
if (r.status !== 0 || !r.stdout || !r.stdout.includes('Usage:')) {
|
|
310
|
+
console.error(' ERROR: smoke test failed.');
|
|
311
|
+
console.error(` exit: ${r.status}`);
|
|
312
|
+
console.error(` stdout: ${(r.stdout || '').slice(0, 200)}`);
|
|
313
|
+
console.error(` stderr: ${(r.stderr || '').slice(0, 200)}`);
|
|
314
|
+
process.exit(3);
|
|
315
|
+
}
|
|
316
|
+
console.log(' smoke test: OK');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ---------- write combined SHA256SUMS ----------
|
|
321
|
+
|
|
322
|
+
if (!OPTS.dryRun) {
|
|
323
|
+
step('Writing combined SHA256SUMS.txt');
|
|
324
|
+
const sumsFile = path.join(OUT_DIR, 'SHA256SUMS.txt');
|
|
325
|
+
fs.writeFileSync(sumsFile, sums.join('\n') + '\n');
|
|
326
|
+
console.log(` wrote ${path.relative(REPO_ROOT, sumsFile)}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ---------- cleanup ----------
|
|
330
|
+
|
|
331
|
+
if (!OPTS.keepStage && !OPTS.dryRun) {
|
|
332
|
+
rmDir(STAGE_DIR);
|
|
333
|
+
} else if (OPTS.keepStage) {
|
|
334
|
+
console.log(`\n (kept stage at ${path.relative(REPO_ROOT, STAGE_DIR)} for inspection)`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
step(`Done. ${TARGETS.length} binar${TARGETS.length === 1 ? 'y' : 'ies'} in ${path.relative(REPO_ROOT, OUT_DIR)}/`);
|
|
338
|
+
console.log(' next: gh release upload v<ver> dist-binaries/* --repo EvoMap/evolver');
|
|
339
|
+
|
|
340
|
+
//
|
|
341
|
+
// =====================================================================
|
|
342
|
+
// PIPELINE RATIONALE — 2026-05-05
|
|
343
|
+
// =====================================================================
|
|
344
|
+
//
|
|
345
|
+
// Why "bun-bundle then obfuscate" rather than the more obvious
|
|
346
|
+
// "obfuscate src/ then bun-bundle":
|
|
347
|
+
//
|
|
348
|
+
// javascript-obfuscator at high strength (stringArray + RC4 +
|
|
349
|
+
// transformObjectKeys + ...) rewrites string literals through a runtime
|
|
350
|
+
// lookup function: require('./gep/paths') becomes
|
|
351
|
+
// require(_0xLOOKUP(0x82b)). Bun's bundler does static analysis on
|
|
352
|
+
// require() arguments at compile time, so it cannot resolve those
|
|
353
|
+
// dynamic require calls and the resulting binary throws "Cannot find
|
|
354
|
+
// module './gep/paths'" on first invocation.
|
|
355
|
+
//
|
|
356
|
+
// By bundling FIRST, every require() is inlined and resolved before the
|
|
357
|
+
// obfuscator ever sees the code. The obfuscator then operates on a
|
|
358
|
+
// single self-contained file with no remaining dynamic requires, so
|
|
359
|
+
// stringArray and friends are safe.
|
|
360
|
+
//
|
|
361
|
+
// Why selfDefending must stay OFF:
|
|
362
|
+
//
|
|
363
|
+
// selfDefending: true injects a guard that hangs (infinite while loop)
|
|
364
|
+
// when it detects formatting changes. bun --compile wraps the JS payload
|
|
365
|
+
// in a standalone executable container that re-emits the source with
|
|
366
|
+
// different whitespace + line endings, which trips the guard immediately.
|
|
367
|
+
// Symptom: binary launches, opens stdio, then never exits.
|
|
368
|
+
//
|
|
369
|
+
// Why transformObjectKeys must stay OFF:
|
|
370
|
+
//
|
|
371
|
+
// Same family of issue — it rewrites top-level module.exports / exports
|
|
372
|
+
// patterns in ways that bun's standalone runtime cannot rebuild.
|
|
373
|
+
//
|
|
374
|
+
// Why renameGlobals must stay OFF:
|
|
375
|
+
//
|
|
376
|
+
// Not strictly required after the bundle step (no external require'd
|
|
377
|
+
// modules remain), but kept off as a safety belt; the cost is small
|
|
378
|
+
// because identifier hashing already covers >99% of names through
|
|
379
|
+
// identifierNamesGenerator='hexadecimal'.
|
|
380
|
+
//
|
|
381
|
+
// Smoke test policy:
|
|
382
|
+
//
|
|
383
|
+
// We only smoke test the binary that matches the BUILD HOST triple.
|
|
384
|
+
// Cross-compiled binaries can't be executed without an emulator
|
|
385
|
+
// (qemu-user-static on linux, Rosetta on darwin-x64-on-arm64). CI/CD
|
|
386
|
+
// in GitHub Actions on `runs-on: macos-latest, ubuntu-latest` should
|
|
387
|
+
// set up the matrix so each runner smoke-tests its own native target.
|
|
388
|
+
//
|