@evomap/evolver 1.90.0 → 2.0.0-beta.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.
Files changed (231) hide show
  1. package/README.md +27 -564
  2. package/bin/evolver-llm-proxy.js +3 -0
  3. package/bin/evolver-mcp.js +2 -0
  4. package/bin/evolver-proxy.js +3 -0
  5. package/bin/evolver.js +4 -0
  6. package/index.js +1 -3670
  7. package/package.json +32 -62
  8. package/CONTRIBUTING.md +0 -19
  9. package/LICENSE +0 -641
  10. package/README.ja-JP.md +0 -521
  11. package/README.ko-KR.md +0 -520
  12. package/README.zh-CN.md +0 -531
  13. package/SKILL.md +0 -365
  14. package/assets/cover.png +0 -0
  15. package/assets/gep/genes.seed.json +0 -496
  16. package/conformance/savings-core/constants.json +0 -30
  17. package/conformance/savings-core/golden-vectors.json +0 -333
  18. package/scripts/a2a_export.js +0 -63
  19. package/scripts/a2a_ingest.js +0 -79
  20. package/scripts/a2a_promote.js +0 -118
  21. package/scripts/analyze_by_skill.js +0 -121
  22. package/scripts/build_binaries.js +0 -479
  23. package/scripts/check-changelog.js +0 -166
  24. package/scripts/extract_log.js +0 -85
  25. package/scripts/generate_history.js +0 -75
  26. package/scripts/gep_append_event.js +0 -96
  27. package/scripts/gep_personality_report.js +0 -234
  28. package/scripts/human_report.js +0 -147
  29. package/scripts/recall-verify-report.js +0 -234
  30. package/scripts/recover_loop.js +0 -61
  31. package/scripts/refresh_stars_badge.js +0 -168
  32. package/scripts/seed-merchants.js +0 -91
  33. package/scripts/skill2recipes.js +0 -118
  34. package/scripts/suggest_version.js +0 -89
  35. package/scripts/validate-modules.js +0 -38
  36. package/scripts/validate-suite.js +0 -78
  37. package/src/adapters/claudeCode.js +0 -194
  38. package/src/adapters/codex.js +0 -216
  39. package/src/adapters/cursor.js +0 -91
  40. package/src/adapters/hookAdapter.js +0 -469
  41. package/src/adapters/kiro.js +0 -195
  42. package/src/adapters/opencode.js +0 -326
  43. package/src/adapters/scripts/_lockPaths.js +0 -74
  44. package/src/adapters/scripts/_memoryFiltering.js +0 -35
  45. package/src/adapters/scripts/_runtimePaths.js +0 -440
  46. package/src/adapters/scripts/evolver-session-end.js +0 -321
  47. package/src/adapters/scripts/evolver-session-start.js +0 -587
  48. package/src/adapters/scripts/evolver-signal-detect.js +0 -98
  49. package/src/adapters/scripts/evolver-task-recall.js +0 -173
  50. package/src/atp/atpExecute.js +0 -283
  51. package/src/atp/atpTaskPickup.js +0 -233
  52. package/src/atp/autoBuyer.js +0 -382
  53. package/src/atp/autoDeliver.js +0 -215
  54. package/src/atp/cli.js +0 -354
  55. package/src/atp/cliAutobuyPrompt.js +0 -154
  56. package/src/atp/consumerAgent.js +0 -157
  57. package/src/atp/defaultHandler.js +0 -69
  58. package/src/atp/heartbeatSignalsHandler.js +0 -254
  59. package/src/atp/hubClient.js +0 -317
  60. package/src/atp/index.js +0 -38
  61. package/src/atp/merchantAgent.js +0 -118
  62. package/src/atp/protocol.js +0 -41
  63. package/src/atp/questionComposer.js +0 -133
  64. package/src/atp/serviceHelper.js +0 -92
  65. package/src/canary.js +0 -13
  66. package/src/config.js +0 -351
  67. package/src/evolve/guards.js +0 -1
  68. package/src/evolve/pipeline/collect.js +0 -1
  69. package/src/evolve/pipeline/dispatch.js +0 -1
  70. package/src/evolve/pipeline/enrich.js +0 -1
  71. package/src/evolve/pipeline/hub.js +0 -1
  72. package/src/evolve/pipeline/select.js +0 -1
  73. package/src/evolve/pipeline/signals.js +0 -1
  74. package/src/evolve/utils.js +0 -1
  75. package/src/evolve.js +0 -1
  76. package/src/experiment/agentRunner.js +0 -229
  77. package/src/experiment/cli.js +0 -159
  78. package/src/experiment/comparison.js +0 -233
  79. package/src/experiment/metrics.js +0 -75
  80. package/src/forceUpdate.js +0 -991
  81. package/src/gep/a2a.js +0 -173
  82. package/src/gep/a2aProtocol.js +0 -1
  83. package/src/gep/analyzer.js +0 -35
  84. package/src/gep/antiAbuseTelemetry.js +0 -1
  85. package/src/gep/assetCallLog.js +0 -197
  86. package/src/gep/assetStore.js +0 -723
  87. package/src/gep/assets.js +0 -36
  88. package/src/gep/autoDistillConv.js +0 -1
  89. package/src/gep/autoDistillLlm.js +0 -1
  90. package/src/gep/bridge.js +0 -138
  91. package/src/gep/candidateEval.js +0 -1
  92. package/src/gep/candidates.js +0 -1
  93. package/src/gep/claimNudge.js +0 -121
  94. package/src/gep/cliContracts.js +0 -1190
  95. package/src/gep/contentHash.js +0 -1
  96. package/src/gep/conversationDistiller.js +0 -1
  97. package/src/gep/conversationSniffer.js +0 -1
  98. package/src/gep/crypto.js +0 -1
  99. package/src/gep/curriculum.js +0 -1
  100. package/src/gep/deviceId.js +0 -1
  101. package/src/gep/directoryClient.js +0 -115
  102. package/src/gep/envFingerprint.js +0 -1
  103. package/src/gep/epigenetics.js +0 -1
  104. package/src/gep/execBridge.js +0 -1
  105. package/src/gep/executionTrace.js +0 -291
  106. package/src/gep/explore.js +0 -1
  107. package/src/gep/featureFlags.js +0 -121
  108. package/src/gep/gitOps.js +0 -265
  109. package/src/gep/hash.js +0 -1
  110. package/src/gep/hostErrorClassifier.js +0 -34
  111. package/src/gep/hubFetch.js +0 -1
  112. package/src/gep/hubReview.js +0 -1
  113. package/src/gep/hubSearch.js +0 -1
  114. package/src/gep/hubVerify.js +0 -1
  115. package/src/gep/idleScheduler.js +0 -400
  116. package/src/gep/issueReporter.js +0 -416
  117. package/src/gep/learningSignals.js +0 -1
  118. package/src/gep/llmReview.js +0 -92
  119. package/src/gep/localStateAwareness.js +0 -243
  120. package/src/gep/mailboxTransport.js +0 -119
  121. package/src/gep/memoryGraph.js +0 -1
  122. package/src/gep/memoryGraphAdapter.js +0 -1
  123. package/src/gep/mutation.js +0 -1
  124. package/src/gep/narrativeMemory.js +0 -1
  125. package/src/gep/oauthLogin.js +0 -181
  126. package/src/gep/openPRRegistry.js +0 -1
  127. package/src/gep/paths.js +0 -522
  128. package/src/gep/personality.js +0 -1
  129. package/src/gep/policyCheck.js +0 -1
  130. package/src/gep/portable.js +0 -103
  131. package/src/gep/privacyClient.js +0 -235
  132. package/src/gep/prompt.js +0 -1
  133. package/src/gep/questionGenerator.js +0 -518
  134. package/src/gep/recallInject.js +0 -1
  135. package/src/gep/recallVerifier.js +0 -1
  136. package/src/gep/reflection.js +0 -1
  137. package/src/gep/sanitize.js +0 -264
  138. package/src/gep/savingsCore.js +0 -1
  139. package/src/gep/schemas/capsule.js +0 -170
  140. package/src/gep/schemas/gene.js +0 -154
  141. package/src/gep/schemas/index.js +0 -8
  142. package/src/gep/schemas/protocol.js +0 -51
  143. package/src/gep/schemas/task.js +0 -74
  144. package/src/gep/selector.js +0 -1
  145. package/src/gep/selfPR.js +0 -469
  146. package/src/gep/signals.js +0 -776
  147. package/src/gep/skill2gep.js +0 -1056
  148. package/src/gep/skill2gepAudit.js +0 -303
  149. package/src/gep/skill2recipes.js +0 -511
  150. package/src/gep/skillDistiller.js +0 -1
  151. package/src/gep/skillPublisher.js +0 -358
  152. package/src/gep/solidify.js +0 -1
  153. package/src/gep/strategy.js +0 -1
  154. package/src/gep/taskReceiver.js +0 -575
  155. package/src/gep/tokenSavings.js +0 -1
  156. package/src/gep/trajectoryExport.js +0 -1
  157. package/src/gep/validationReport.js +0 -55
  158. package/src/gep/validator/index.js +0 -411
  159. package/src/gep/validator/reporter.js +0 -210
  160. package/src/gep/validator/sandboxExecutor.js +0 -480
  161. package/src/gep/validator/stakeBootstrap.js +0 -357
  162. package/src/gep/workspaceKeychain.js +0 -1
  163. package/src/ops/cleanup.js +0 -80
  164. package/src/ops/commentary.js +0 -60
  165. package/src/ops/health_check.js +0 -104
  166. package/src/ops/index.js +0 -11
  167. package/src/ops/innovation.js +0 -67
  168. package/src/ops/lifecycle.js +0 -798
  169. package/src/ops/self_repair.js +0 -76
  170. package/src/ops/skills_monitor.js +0 -147
  171. package/src/ops/trigger.js +0 -33
  172. package/src/proxy/clientSettings.js +0 -405
  173. package/src/proxy/envelope.js +0 -59
  174. package/src/proxy/extensions/dmHandler.js +0 -45
  175. package/src/proxy/extensions/sessionHandler.js +0 -141
  176. package/src/proxy/extensions/skillUpdater.js +0 -64
  177. package/src/proxy/extensions/traceControl.js +0 -1
  178. package/src/proxy/index.js +0 -1395
  179. package/src/proxy/inject.js +0 -1
  180. package/src/proxy/lifecycle/manager.js +0 -1568
  181. package/src/proxy/mailbox/state.js +0 -207
  182. package/src/proxy/mailbox/store.js +0 -602
  183. package/src/proxy/router/cache_passthrough.js +0 -26
  184. package/src/proxy/router/features.js +0 -84
  185. package/src/proxy/router/gemini_route.js +0 -154
  186. package/src/proxy/router/messages_route.js +0 -535
  187. package/src/proxy/router/model_router.js +0 -113
  188. package/src/proxy/router/models_route.js +0 -52
  189. package/src/proxy/router/ollama_route.js +0 -103
  190. package/src/proxy/router/responses_route.js +0 -170
  191. package/src/proxy/router/vertex_route.js +0 -110
  192. package/src/proxy/server/http.js +0 -363
  193. package/src/proxy/server/routes.js +0 -558
  194. package/src/proxy/server/settings.js +0 -115
  195. package/src/proxy/sync/engine.js +0 -179
  196. package/src/proxy/sync/inbound.js +0 -211
  197. package/src/proxy/sync/outbound.js +0 -361
  198. package/src/proxy/task/monitor.js +0 -131
  199. package/src/proxy/trace/extractor.js +0 -1
  200. package/src/proxy/trace/usage.js +0 -1
  201. package/src/solo/breaker.js +0 -25
  202. package/src/solo/gitGuard.js +0 -65
  203. package/src/webui/client/clientJs/assets.js +0 -111
  204. package/src/webui/client/clientJs/bootstrap.js +0 -92
  205. package/src/webui/client/clientJs/common.js +0 -77
  206. package/src/webui/client/clientJs/i18n.js +0 -366
  207. package/src/webui/client/clientJs/index.js +0 -35
  208. package/src/webui/client/clientJs/interactions.js +0 -351
  209. package/src/webui/client/clientJs/overview.js +0 -152
  210. package/src/webui/client/clientJs/personality.js +0 -285
  211. package/src/webui/client/clientJs/pipelines.js +0 -330
  212. package/src/webui/client/indexHtml.js +0 -221
  213. package/src/webui/client/static.js +0 -23
  214. package/src/webui/client/stylesCss.js +0 -639
  215. package/src/webui/client/vendor/README.md +0 -15
  216. package/src/webui/client/vendor/echarts.min.js +0 -45
  217. package/src/webui/index.js +0 -14
  218. package/src/webui/observer/assets.js +0 -146
  219. package/src/webui/observer/index.js +0 -37
  220. package/src/webui/observer/interactions.js +0 -127
  221. package/src/webui/observer/jsonl.js +0 -75
  222. package/src/webui/observer/paths.js +0 -46
  223. package/src/webui/observer/personality.js +0 -43
  224. package/src/webui/observer/pipelineEvents.js +0 -58
  225. package/src/webui/observer/redact.js +0 -63
  226. package/src/webui/observer/runs.js +0 -356
  227. package/src/webui/observer/safety.js +0 -57
  228. package/src/webui/observer/skills.js +0 -70
  229. package/src/webui/observer/status.js +0 -71
  230. package/src/webui/server/http.js +0 -138
  231. package/src/webui/server/routes.js +0 -41
@@ -1,121 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const REPO_ROOT = path.resolve(__dirname, '..');
5
- const LOG_FILE = path.join(REPO_ROOT, 'evolution_history_full.md');
6
- const OUT_FILE = path.join(REPO_ROOT, 'evolution_detailed_report.md');
7
-
8
- function analyzeEvolution() {
9
- if (!fs.existsSync(LOG_FILE)) {
10
- console.error("Source file missing.");
11
- return;
12
- }
13
-
14
- const content = fs.readFileSync(LOG_FILE, 'utf8');
15
- // Split by divider
16
- const entries = content.split('---').map(e => e.trim()).filter(e => e.length > 0);
17
-
18
- const skillUpdates = {}; // Map<SkillName, Array<Changes>>
19
- const generalUpdates = []; // Array<Changes>
20
-
21
- // Regex to detect skills/paths
22
- // e.g. `skills/feishu-card/send.js` or **Target**: `skills/git-sync`
23
- const skillRegex = /skills\/([a-zA-Z0-9\-_]+)/;
24
- const actionRegex = /Action:\s*([\s\S]*?)(?=\n\n|\n[A-Z]|$)/i; // Capture Action text
25
- const statusRegex = /Status:\s*\[?([A-Z\s_]+)\]?/i;
26
-
27
- entries.forEach(entry => {
28
- // Extract basic info
29
- const statusMatch = entry.match(statusRegex);
30
- const status = statusMatch ? statusMatch[1].trim().toUpperCase() : 'UNKNOWN';
31
-
32
- // Skip routine checks if we want a *detailed evolution* report (focus on changes)
33
- // But user asked for "what happened", so routine scans might be boring unless they found something.
34
- // Let's filter out "STABILITY" or "RUNNING" unless there is a clear "Mutated" or "Fixed" keyword.
35
- const isInteresting =
36
- entry.includes('Fixed') ||
37
- entry.includes('Hardened') ||
38
- entry.includes('Optimized') ||
39
- entry.includes('Patched') ||
40
- entry.includes('Created') ||
41
- entry.includes('Added') ||
42
- status === 'SUCCESS' ||
43
- status === 'COMPLETED';
44
-
45
- if (!isInteresting) return;
46
-
47
- // Find associated skill
48
- const skillMatch = entry.match(skillRegex);
49
- let skillName = 'General / System';
50
- if (skillMatch) {
51
- skillName = skillMatch[1];
52
- } else {
53
- // Try heuristics
54
- if (entry.toLowerCase().includes('feishu card')) skillName = 'feishu-card';
55
- else if (entry.toLowerCase().includes('git sync')) skillName = 'git-sync';
56
- else if (entry.toLowerCase().includes('logger')) skillName = 'interaction-logger';
57
- else if (entry.toLowerCase().includes('evolve')) skillName = 'capability-evolver';
58
- }
59
-
60
- // Extract description
61
- let description = "";
62
- const actionMatch = entry.match(actionRegex);
63
- if (actionMatch) {
64
- description = actionMatch[1].trim();
65
- } else {
66
- // Fallback: take lines that look like bullet points or text after header
67
- const lines = entry.split('\n');
68
- description = lines.filter(l => l.match(/^[•\-\*]|\w/)).slice(1).join('\n').trim();
69
- }
70
-
71
- // Clean up description (remove duplicate "Action:" prefix if captured)
72
- description = description.replace(/^Action:\s*/i, '');
73
-
74
- if (!skillUpdates[skillName]) skillUpdates[skillName] = [];
75
-
76
- // Dedup descriptions slightly (simple check)
77
- const isDuplicate = skillUpdates[skillName].some(u => u.desc.includes(description.substring(0, 20)));
78
- if (!isDuplicate) {
79
- // Extract Date if possible
80
- const dateMatch = entry.match(/\((\d{4}\/\d{1,2}\/\d{1,2}.*?)\)/);
81
- const date = dateMatch ? dateMatch[1] : 'Unknown';
82
-
83
- skillUpdates[skillName].push({
84
- date,
85
- status,
86
- desc: description
87
- });
88
- }
89
- });
90
-
91
- // Generate Markdown
92
- let md = "# Detailed Evolution Report (By Skill)\n\n> Comprehensive breakdown of system changes.\n\n";
93
-
94
- // Sort skills alphabetically
95
- const sortedSkills = Object.keys(skillUpdates).sort();
96
-
97
- sortedSkills.forEach(skill => {
98
- md += `## ${skill}\n`;
99
- const updates = skillUpdates[skill];
100
-
101
- updates.forEach(u => {
102
- // Icon based on content
103
- let icon = '*';
104
- const lowerDesc = u.desc.toLowerCase();
105
- if (lowerDesc.includes('optimiz')) icon = '[optimize]';
106
- if (lowerDesc.includes('secur') || lowerDesc.includes('harden') || lowerDesc.includes('permission')) icon = '[security]';
107
- if (lowerDesc.includes('fix') || lowerDesc.includes('patch')) icon = '[repair]';
108
- if (lowerDesc.includes('creat') || lowerDesc.includes('add')) icon = '[add]';
109
-
110
- md += `### ${icon} ${u.date}\n`;
111
- md += `${u.desc}\n\n`;
112
- });
113
- md += `---\n`;
114
- });
115
-
116
- fs.writeFileSync(OUT_FILE, md);
117
- console.log(`Generated report for ${sortedSkills.length} skills.`);
118
- }
119
-
120
- analyzeEvolution();
121
-
@@ -1,479 +0,0 @@
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
- // `--external '@napi-rs/keyring'`: keyring is an optional dep loaded via
196
- // dynamic require() in workspace-id; bun otherwise tries to bundle the
197
- // platform-specific `.node` file as a second output asset, which makes
198
- // `bun build … --outfile=…` fail with "cannot write multiple output files
199
- // without an output directory". Treating it as external preserves the
200
- // existing optional-fallback behaviour (require throws → FS path used) in
201
- // the standalone binaries.
202
- run('bun', ['build', ENTRY, '--target=node', `--outfile=${BUNDLED_JS}`, '--external', '@napi-rs/keyring']);
203
-
204
- const bundleSize = OPTS.dryRun ? 0 : fs.statSync(BUNDLED_JS).size;
205
- console.log(` bundled.js: ${(bundleSize / 1024 / 1024).toFixed(2)} MB`);
206
-
207
- // ---------- stage 2: obfuscate ----------
208
-
209
- let payloadJs = BUNDLED_JS;
210
-
211
- if (!OPTS.skipObfuscate) {
212
- step('Stage 2 — javascript-obfuscator (high strength, bundler-safe)');
213
- const OBF_JS = path.join(STAGE_DIR, 'bundled.obf.js');
214
-
215
- if (!OPTS.dryRun) {
216
- const O = require(require.resolve('javascript-obfuscator', { paths: [REPO_ROOT] }));
217
- const src = fs.readFileSync(BUNDLED_JS, 'utf8');
218
- // Seed obfuscation from release version: gives same-version reruns a
219
- // narrow PRNG path, but the obfuscator has internal non-determinism
220
- // beyond the seed (Set iteration / stringArray rotation timing) so two
221
- // runs with the same seed can still differ slightly. Empirically ~5%
222
- // of those runs emit invalid syntax (e.g. mangling `new.target` to
223
- // `#target`, which then crashes `bun compile`). Validate after each
224
- // attempt and retry — see RETRY note in pipeline rationale below.
225
- const baseSeed = parseInt(crypto.createHash('sha256').update(`evolver:${releaseVersion}`).digest('hex').slice(0, 8), 16);
226
- const obfOpts = {
227
- compact: true,
228
- controlFlowFlattening: true,
229
- controlFlowFlatteningThreshold: 0.75,
230
- deadCodeInjection: true,
231
- deadCodeInjectionThreshold: 0.4,
232
- stringArray: true,
233
- stringArrayEncoding: ['rc4'],
234
- stringArrayThreshold: 0.85,
235
- identifierNamesGenerator: 'hexadecimal',
236
- // The next three MUST stay disabled — they are incompatible with bun's
237
- // standalone wrapping (selfDefending + transformObjectKeys + renameGlobals
238
- // each break either compile-time bundling or run-time module resolution).
239
- // See pipeline notes at top of file.
240
- renameGlobals: false,
241
- selfDefending: false,
242
- transformObjectKeys: false,
243
- debugProtection: false,
244
- splitStrings: true,
245
- splitStringsChunkLength: 8,
246
- numbersToExpressions: true,
247
- unicodeEscapeSequence: true,
248
- target: 'node',
249
- };
250
-
251
- const MAX_OBF_ATTEMPTS_RAW = process.env.OBF_MAX_ATTEMPTS;
252
- // Default 12 (was 4). The obfuscator's new.target -> #target mangling is
253
- // non-deterministic ACROSS PROCESSES, not just across seeds: the same seed
254
- // + same input can pass in one node process and fail in another (Set
255
- // iteration / internal-state timing). So perturbing the seed per attempt is
256
- // not the real lever — re-running the obfuscate call is. The v1.87.4 deploy
257
- // hit 4/4 consecutive failures with the default of 4 and aborted the npm
258
- // publish + binary upload. At an observed per-attempt failure rate that can
259
- // run well above the historical ~5% for some bundles, 4 retries is too few;
260
- // 12 drives the all-fail probability to negligible while costing only extra
261
- // attempts on the rare unlucky run. Override with OBF_MAX_ATTEMPTS.
262
- const MAX_OBF_ATTEMPTS = MAX_OBF_ATTEMPTS_RAW === undefined
263
- ? 12
264
- : parseInt(MAX_OBF_ATTEMPTS_RAW, 10);
265
- if (!Number.isInteger(MAX_OBF_ATTEMPTS) || MAX_OBF_ATTEMPTS < 1) {
266
- console.error(` ERROR: OBF_MAX_ATTEMPTS must be a positive integer; got ${JSON.stringify(MAX_OBF_ATTEMPTS_RAW)}.`);
267
- process.exit(1);
268
- }
269
- let attempt = 0;
270
- let usedSeed = baseSeed;
271
- let lastValidationErr = null;
272
- let succeeded = false;
273
- while (attempt < MAX_OBF_ATTEMPTS) {
274
- attempt++;
275
- // Perturb seed on retries to dodge a stuck PRNG path. Attempt 1 keeps
276
- // the canonical seed for best-effort reproducibility; later attempts
277
- // shift by attempt index so the next deploy gets a fresh trajectory.
278
- usedSeed = baseSeed + (attempt - 1);
279
- const t0 = Date.now();
280
- const result = O.obfuscate(src, { ...obfOpts, seed: usedSeed });
281
- fs.writeFileSync(OBF_JS, result.getObfuscatedCode());
282
- const obfSize = fs.statSync(OBF_JS).size;
283
- const obfSecs = ((Date.now() - t0) / 1000).toFixed(1);
284
-
285
- const check = spawnSync('node', ['--check', OBF_JS], { encoding: 'utf8' });
286
- if (check.status !== 0) {
287
- lastValidationErr = (check.stderr || check.stdout || '').split('\n').slice(0, 3).join(' | ');
288
- console.warn(` attempt ${attempt}/${MAX_OBF_ATTEMPTS}: obfuscator output failed node --check (${lastValidationErr.slice(0, 200)}); retrying with perturbed seed...`);
289
- continue;
290
- }
291
- // Second gate: bun's compile-time parser is stricter than node's.
292
- // 1.87.x (post `@napi-rs/keyring` dep) revealed that ~5% of obfuscator
293
- // outputs that pass `node --check` still trip bun with errors like
294
- // `Expected "in" but found ","`. Probe with a cheap bundle-only call
295
- // (no --compile, native target) to fail fast and feed back into the
296
- // seed-perturbation loop instead of dying in stage 3.
297
- const bunProbe = spawnSync('bun', [
298
- 'build', OBF_JS,
299
- '--target=bun',
300
- `--outfile=${path.join(STAGE_DIR, 'bundled.obf.bunprobe.js')}`,
301
- ], { encoding: 'utf8' });
302
- if (bunProbe.status !== 0) {
303
- lastValidationErr = (bunProbe.stderr || bunProbe.stdout || '').split('\n').slice(0, 3).join(' | ');
304
- console.warn(` attempt ${attempt}/${MAX_OBF_ATTEMPTS}: obfuscator output rejected by bun parser (${lastValidationErr.slice(0, 200)}); retrying with perturbed seed...`);
305
- continue;
306
- }
307
- console.log(` obfuscation: ${obfSecs}s, output ${(obfSize / 1024 / 1024).toFixed(2)} MB (attempt ${attempt}/${MAX_OBF_ATTEMPTS}, seed=0x${usedSeed.toString(16)})`);
308
- succeeded = true;
309
- break;
310
- }
311
- if (!succeeded) {
312
- console.error(` ERROR: javascript-obfuscator produced syntactically invalid output in ${MAX_OBF_ATTEMPTS} attempts.`);
313
- console.error(` last error: ${lastValidationErr || '(none — loop did not run)'}`);
314
- console.error(` raise OBF_MAX_ATTEMPTS env var to retry more times, or temporarily run with --skip-obfuscate.`);
315
- process.exit(2);
316
- }
317
- } else {
318
- console.log(' [dry-run] would obfuscate stage/bundled.js -> stage/bundled.obf.js (with retry-on-syntax-error)');
319
- }
320
-
321
- payloadJs = OBF_JS;
322
- } else {
323
- console.log('\n>> Stage 2 — SKIPPED (--skip-obfuscate)');
324
- }
325
-
326
- // ---------- stage 3: per-target compile ----------
327
-
328
- step(`Stage 3 — bun compile (${TARGETS.length} target${TARGETS.length === 1 ? '' : 's'})`);
329
-
330
- // Idempotency: scrub OUT_DIR up front so stale binaries from a prior partial
331
- // run can't leak into a subsequent `gh release upload dist-binaries/*`.
332
- if (!OPTS.dryRun) {
333
- rmDir(OUT_DIR);
334
- }
335
- ensureDir(OUT_DIR);
336
- const sums = [];
337
-
338
- for (const t of TARGETS) {
339
- const outPath = path.join(OUT_DIR, t.name);
340
- console.log(`\n --- ${t.triple} -> ${path.relative(REPO_ROOT, outPath)} ---`);
341
-
342
- run('bun', [
343
- 'build',
344
- payloadJs,
345
- '--compile',
346
- '--minify',
347
- `--target=${t.triple}`,
348
- `--outfile=${outPath}`,
349
- ]);
350
-
351
- if (!OPTS.dryRun) {
352
- const stat = fs.statSync(outPath);
353
- fs.chmodSync(outPath, 0o755);
354
- const hash = sha256(outPath);
355
- fs.writeFileSync(`${outPath}.sha256`, `${hash} ${t.name}\n`);
356
- sums.push(`${hash} ${t.name}`);
357
- console.log(` size: ${(stat.size / 1024 / 1024).toFixed(1)} MB sha256: ${hash.slice(0, 16)}…`);
358
- }
359
- }
360
-
361
- // Smoke test only the host platform binary (cross-platform binaries cannot
362
- // be executed on the build host without an emulator; skip them by design).
363
- const hostTriple = (() => {
364
- const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
365
- const plat = process.platform === 'darwin' ? 'darwin'
366
- : process.platform === 'linux' ? 'linux'
367
- : process.platform === 'win32' ? 'windows'
368
- : null;
369
- return plat ? `${plat}-${arch}` : null;
370
- })();
371
-
372
- if (!OPTS.dryRun && hostTriple) {
373
- // Match against the triple suffix (e.g. "darwin-arm64"), since the binary
374
- // name on Windows includes a ".exe" extension.
375
- const hostBin = TARGETS.find(t => t.triple.endsWith(hostTriple));
376
- if (hostBin) {
377
- step(`Stage 4 — smoke test ${hostBin.name}`);
378
- const r = spawnSync(path.join(OUT_DIR, hostBin.name), ['--help'], {
379
- timeout: 15000,
380
- encoding: 'utf8',
381
- });
382
- if (r.status !== 0 || !r.stdout || !r.stdout.includes('Usage:')) {
383
- console.error(' ERROR: smoke test failed.');
384
- console.error(` exit: ${r.status}`);
385
- console.error(` stdout: ${(r.stdout || '').slice(0, 200)}`);
386
- console.error(` stderr: ${(r.stderr || '').slice(0, 200)}`);
387
- process.exit(3);
388
- }
389
- console.log(' smoke test: OK');
390
- }
391
- }
392
-
393
- // ---------- write combined SHA256SUMS ----------
394
-
395
- if (!OPTS.dryRun) {
396
- step('Writing combined SHA256SUMS.txt');
397
- const sumsFile = path.join(OUT_DIR, 'SHA256SUMS.txt');
398
- fs.writeFileSync(sumsFile, sums.join('\n') + '\n');
399
- console.log(` wrote ${path.relative(REPO_ROOT, sumsFile)}`);
400
- }
401
-
402
- // ---------- cleanup ----------
403
-
404
- if (!OPTS.keepStage && !OPTS.dryRun) {
405
- rmDir(STAGE_DIR);
406
- } else if (OPTS.keepStage) {
407
- console.log(`\n (kept stage at ${path.relative(REPO_ROOT, STAGE_DIR)} for inspection)`);
408
- }
409
-
410
- step(`Done. ${TARGETS.length} binar${TARGETS.length === 1 ? 'y' : 'ies'} in ${path.relative(REPO_ROOT, OUT_DIR)}/`);
411
- console.log(' next: gh release upload v<ver> dist-binaries/* --repo EvoMap/evolver');
412
-
413
- //
414
- // =====================================================================
415
- // PIPELINE RATIONALE — 2026-05-05
416
- // =====================================================================
417
- //
418
- // Why "bun-bundle then obfuscate" rather than the more obvious
419
- // "obfuscate src/ then bun-bundle":
420
- //
421
- // javascript-obfuscator at high strength (stringArray + RC4 +
422
- // transformObjectKeys + ...) rewrites string literals through a runtime
423
- // lookup function: require('./gep/paths') becomes
424
- // require(_0xLOOKUP(0x82b)). Bun's bundler does static analysis on
425
- // require() arguments at compile time, so it cannot resolve those
426
- // dynamic require calls and the resulting binary throws "Cannot find
427
- // module './gep/paths'" on first invocation.
428
- //
429
- // By bundling FIRST, every require() is inlined and resolved before the
430
- // obfuscator ever sees the code. The obfuscator then operates on a
431
- // single self-contained file with no remaining dynamic requires, so
432
- // stringArray and friends are safe.
433
- //
434
- // Why selfDefending must stay OFF:
435
- //
436
- // selfDefending: true injects a guard that hangs (infinite while loop)
437
- // when it detects formatting changes. bun --compile wraps the JS payload
438
- // in a standalone executable container that re-emits the source with
439
- // different whitespace + line endings, which trips the guard immediately.
440
- // Symptom: binary launches, opens stdio, then never exits.
441
- //
442
- // Why transformObjectKeys must stay OFF:
443
- //
444
- // Same family of issue — it rewrites top-level module.exports / exports
445
- // patterns in ways that bun's standalone runtime cannot rebuild.
446
- //
447
- // Why renameGlobals must stay OFF:
448
- //
449
- // Not strictly required after the bundle step (no external require'd
450
- // modules remain), but kept off as a safety belt; the cost is small
451
- // because identifier hashing already covers >99% of names through
452
- // identifierNamesGenerator='hexadecimal'.
453
- //
454
- // Smoke test policy:
455
- //
456
- // We only smoke test the binary that matches the BUILD HOST triple.
457
- // Cross-compiled binaries can't be executed without an emulator
458
- // (qemu-user-static on linux, Rosetta on darwin-x64-on-arm64). CI/CD
459
- // in GitHub Actions on `runs-on: macos-latest, ubuntu-latest` should
460
- // set up the matrix so each runner smoke-tests its own native target.
461
- //
462
- // Stage 2 retry-on-syntax-error (added 2026-05-22, v1.85.0 deploy
463
- // post-mortem):
464
- //
465
- // The v1.85.0 release deploy hit `bun compile` failing with
466
- // `Expected "in" but found ","` at offset ~1.5MB into bundled.obf.js.
467
- // The failing region contained `(#target,this)` — javascript-obfuscator
468
- // had mangled `new.target` into `#target` (a private class field syntax
469
- // that's only legal inside a class body). A from-scratch rebuild on the
470
- // same source + seed produced a different output (15.18 MB vs 15.14 MB)
471
- // that compiled cleanly, confirming the obfuscator has internal
472
- // non-determinism beyond the user-supplied seed.
473
- //
474
- // Mitigation: after each obfuscation attempt, run `node --check` on the
475
- // output; if syntax is invalid, perturb the seed by +attempt and retry
476
- // up to OBF_MAX_ATTEMPTS times (default 4). Cost of validation is
477
- // ~1 second on 15 MB; cost of catching the failure here vs after a
478
- // doomed bun compile pass is roughly 50s saved per failure.
479
- //