ruvector 0.2.20 → 0.2.21
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/package.json +2 -1
- package/src/decompiler/index.js +57 -1
- package/wasm/package.json +27 -0
- package/wasm/ruvector_decompiler_wasm.d.ts +27 -0
- package/wasm/ruvector_decompiler_wasm.js +220 -0
- package/wasm/ruvector_decompiler_wasm_bg.wasm +0 -0
- package/wasm/ruvector_decompiler_wasm_bg.wasm.d.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruvector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"description": "Self-learning vector database for Node.js — hybrid search, Graph RAG, FlashAttention-3, DiskANN, 50+ attention mechanisms",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"bin/",
|
|
91
91
|
"dist/",
|
|
92
92
|
"src/decompiler/",
|
|
93
|
+
"wasm/",
|
|
93
94
|
"README.md",
|
|
94
95
|
"LICENSE"
|
|
95
96
|
],
|
package/src/decompiler/index.js
CHANGED
|
@@ -27,6 +27,55 @@ const { computeMetrics, computeModuleMetrics } = require('./metrics');
|
|
|
27
27
|
const { reconstructCode, reconstructRunnable } = require('./reconstructor');
|
|
28
28
|
const { validateReconstruction } = require('./validator');
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Try the WASM Louvain decompiler (full graph-partitioning pipeline).
|
|
32
|
+
* Returns null if WASM module is not available or fails.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} source - raw JavaScript source
|
|
35
|
+
* @param {object} [options]
|
|
36
|
+
* @returns {{modules: object[], metrics: object, witness: object|null}|null}
|
|
37
|
+
*/
|
|
38
|
+
function tryWasmDecompiler(source, options = {}) {
|
|
39
|
+
try {
|
|
40
|
+
const wasm = require('../../wasm/ruvector_decompiler_wasm');
|
|
41
|
+
const configJson = JSON.stringify({
|
|
42
|
+
target_modules: null,
|
|
43
|
+
min_confidence: options.minConfidence || 0.3,
|
|
44
|
+
generate_source_maps: false,
|
|
45
|
+
generate_witness: options.witness !== false,
|
|
46
|
+
output_filename: 'bundle.js',
|
|
47
|
+
model_path: null,
|
|
48
|
+
hierarchical_output: true,
|
|
49
|
+
max_depth: 3,
|
|
50
|
+
min_folder_size: 3,
|
|
51
|
+
});
|
|
52
|
+
const resultJson = wasm.decompile(source, configJson);
|
|
53
|
+
const result = JSON.parse(resultJson);
|
|
54
|
+
if (result.error) return null;
|
|
55
|
+
|
|
56
|
+
// Convert Rust DecompileResult to Node.js format
|
|
57
|
+
return {
|
|
58
|
+
modules: (result.modules || []).map((m) => ({
|
|
59
|
+
name: m.name,
|
|
60
|
+
content: m.source || '',
|
|
61
|
+
declarations: (m.declarations && m.declarations.length) || 0,
|
|
62
|
+
fragments: (m.declarations && m.declarations.length) || 0,
|
|
63
|
+
confidence: 0.8,
|
|
64
|
+
})),
|
|
65
|
+
metrics: {
|
|
66
|
+
source: { sizeBytes: source.length },
|
|
67
|
+
modules: (result.modules || []).length,
|
|
68
|
+
engine: 'wasm-louvain',
|
|
69
|
+
},
|
|
70
|
+
witness: result.witness || null,
|
|
71
|
+
moduleTree: result.module_tree || null,
|
|
72
|
+
beautifiedSource: source,
|
|
73
|
+
};
|
|
74
|
+
} catch {
|
|
75
|
+
return null; // WASM not available, fall back
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
30
79
|
/**
|
|
31
80
|
* Try to beautify source code using js-beautify (optional dep).
|
|
32
81
|
* Falls back to returning the source unchanged if not installed.
|
|
@@ -118,7 +167,13 @@ function decompileSource(source, options = {}) {
|
|
|
118
167
|
filePath,
|
|
119
168
|
} = options;
|
|
120
169
|
|
|
121
|
-
//
|
|
170
|
+
// Priority 1: WASM Louvain (full pipeline, works everywhere, no binary needed)
|
|
171
|
+
if (useRust !== false && source.length > 1000) {
|
|
172
|
+
const wasmResult = tryWasmDecompiler(source, options);
|
|
173
|
+
if (wasmResult) return wasmResult;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Priority 2: Rust binary (full pipeline, requires cargo build)
|
|
122
177
|
if (useRust && filePath && source.length > 100000) {
|
|
123
178
|
const tmpDir = path.join(require('os').tmpdir(), 'ruvector-decompile-' + Date.now());
|
|
124
179
|
const rustResult = tryRustDecompiler(filePath, tmpDir);
|
|
@@ -404,4 +459,5 @@ module.exports = {
|
|
|
404
459
|
reconstructCode,
|
|
405
460
|
reconstructRunnable,
|
|
406
461
|
validateReconstruction,
|
|
462
|
+
tryWasmDecompiler,
|
|
407
463
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ruvector-decompiler-wasm",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"Ruvector Team"
|
|
5
|
+
],
|
|
6
|
+
"description": "WASM bindings for the RuVector JavaScript bundle decompiler (Louvain pipeline)",
|
|
7
|
+
"version": "2.1.0",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ruvnet/ruvector"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"ruvector_decompiler_wasm_bg.wasm",
|
|
15
|
+
"ruvector_decompiler_wasm.js",
|
|
16
|
+
"ruvector_decompiler_wasm.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"main": "ruvector_decompiler_wasm.js",
|
|
19
|
+
"types": "ruvector_decompiler_wasm.d.ts",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"decompiler",
|
|
22
|
+
"javascript",
|
|
23
|
+
"wasm",
|
|
24
|
+
"mincut",
|
|
25
|
+
"louvain"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Decompile a minified JavaScript bundle using the full Louvain pipeline.
|
|
6
|
+
*
|
|
7
|
+
* # Arguments
|
|
8
|
+
*
|
|
9
|
+
* * `source` - The minified JavaScript source code.
|
|
10
|
+
* * `config_json` - JSON string of `DecompileConfig` fields. Pass `"{}"` for defaults.
|
|
11
|
+
*
|
|
12
|
+
* # Returns
|
|
13
|
+
*
|
|
14
|
+
* A JSON string containing the `DecompileResult` (modules, witness, inferred names, etc.)
|
|
15
|
+
* or a JSON object with an `"error"` field on failure.
|
|
16
|
+
*/
|
|
17
|
+
export function decompile(source: string, config_json: string): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the WASM module (sets up panic hook for better error messages).
|
|
21
|
+
*/
|
|
22
|
+
export function init(): void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return the version of the decompiler WASM module.
|
|
26
|
+
*/
|
|
27
|
+
export function version(): string;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* @ts-self-types="./ruvector_decompiler_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decompile a minified JavaScript bundle using the full Louvain pipeline.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `source` - The minified JavaScript source code.
|
|
9
|
+
* * `config_json` - JSON string of `DecompileConfig` fields. Pass `"{}"` for defaults.
|
|
10
|
+
*
|
|
11
|
+
* # Returns
|
|
12
|
+
*
|
|
13
|
+
* A JSON string containing the `DecompileResult` (modules, witness, inferred names, etc.)
|
|
14
|
+
* or a JSON object with an `"error"` field on failure.
|
|
15
|
+
* @param {string} source
|
|
16
|
+
* @param {string} config_json
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
function decompile(source, config_json) {
|
|
20
|
+
let deferred3_0;
|
|
21
|
+
let deferred3_1;
|
|
22
|
+
try {
|
|
23
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
24
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
25
|
+
const len0 = WASM_VECTOR_LEN;
|
|
26
|
+
const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
27
|
+
const len1 = WASM_VECTOR_LEN;
|
|
28
|
+
wasm.decompile(retptr, ptr0, len0, ptr1, len1);
|
|
29
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
30
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
31
|
+
deferred3_0 = r0;
|
|
32
|
+
deferred3_1 = r1;
|
|
33
|
+
return getStringFromWasm0(r0, r1);
|
|
34
|
+
} finally {
|
|
35
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
36
|
+
wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.decompile = decompile;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the WASM module (sets up panic hook for better error messages).
|
|
43
|
+
*/
|
|
44
|
+
function init() {
|
|
45
|
+
wasm.init();
|
|
46
|
+
}
|
|
47
|
+
exports.init = init;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Return the version of the decompiler WASM module.
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
function version() {
|
|
54
|
+
let deferred1_0;
|
|
55
|
+
let deferred1_1;
|
|
56
|
+
try {
|
|
57
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
58
|
+
wasm.version(retptr);
|
|
59
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
60
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
61
|
+
deferred1_0 = r0;
|
|
62
|
+
deferred1_1 = r1;
|
|
63
|
+
return getStringFromWasm0(r0, r1);
|
|
64
|
+
} finally {
|
|
65
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
66
|
+
wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.version = version;
|
|
70
|
+
|
|
71
|
+
function __wbg_get_imports() {
|
|
72
|
+
const import0 = {
|
|
73
|
+
__proto__: null,
|
|
74
|
+
__wbg___wbindgen_throw_39bc967c0e5a9b58: function(arg0, arg1) {
|
|
75
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
76
|
+
},
|
|
77
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
78
|
+
let deferred0_0;
|
|
79
|
+
let deferred0_1;
|
|
80
|
+
try {
|
|
81
|
+
deferred0_0 = arg0;
|
|
82
|
+
deferred0_1 = arg1;
|
|
83
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
84
|
+
} finally {
|
|
85
|
+
wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
89
|
+
const ret = new Error();
|
|
90
|
+
return addHeapObject(ret);
|
|
91
|
+
},
|
|
92
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
93
|
+
const ret = getObject(arg1).stack;
|
|
94
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
95
|
+
const len1 = WASM_VECTOR_LEN;
|
|
96
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
97
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
98
|
+
},
|
|
99
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
100
|
+
takeObject(arg0);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
__proto__: null,
|
|
105
|
+
"./ruvector_decompiler_wasm_bg.js": import0,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function addHeapObject(obj) {
|
|
110
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
111
|
+
const idx = heap_next;
|
|
112
|
+
heap_next = heap[idx];
|
|
113
|
+
|
|
114
|
+
heap[idx] = obj;
|
|
115
|
+
return idx;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function dropObject(idx) {
|
|
119
|
+
if (idx < 1028) return;
|
|
120
|
+
heap[idx] = heap_next;
|
|
121
|
+
heap_next = idx;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let cachedDataViewMemory0 = null;
|
|
125
|
+
function getDataViewMemory0() {
|
|
126
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
127
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
128
|
+
}
|
|
129
|
+
return cachedDataViewMemory0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getStringFromWasm0(ptr, len) {
|
|
133
|
+
ptr = ptr >>> 0;
|
|
134
|
+
return decodeText(ptr, len);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let cachedUint8ArrayMemory0 = null;
|
|
138
|
+
function getUint8ArrayMemory0() {
|
|
139
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
140
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
141
|
+
}
|
|
142
|
+
return cachedUint8ArrayMemory0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getObject(idx) { return heap[idx]; }
|
|
146
|
+
|
|
147
|
+
let heap = new Array(1024).fill(undefined);
|
|
148
|
+
heap.push(undefined, null, true, false);
|
|
149
|
+
|
|
150
|
+
let heap_next = heap.length;
|
|
151
|
+
|
|
152
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
153
|
+
if (realloc === undefined) {
|
|
154
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
155
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
156
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
157
|
+
WASM_VECTOR_LEN = buf.length;
|
|
158
|
+
return ptr;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let len = arg.length;
|
|
162
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
163
|
+
|
|
164
|
+
const mem = getUint8ArrayMemory0();
|
|
165
|
+
|
|
166
|
+
let offset = 0;
|
|
167
|
+
|
|
168
|
+
for (; offset < len; offset++) {
|
|
169
|
+
const code = arg.charCodeAt(offset);
|
|
170
|
+
if (code > 0x7F) break;
|
|
171
|
+
mem[ptr + offset] = code;
|
|
172
|
+
}
|
|
173
|
+
if (offset !== len) {
|
|
174
|
+
if (offset !== 0) {
|
|
175
|
+
arg = arg.slice(offset);
|
|
176
|
+
}
|
|
177
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
178
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
179
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
180
|
+
|
|
181
|
+
offset += ret.written;
|
|
182
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
WASM_VECTOR_LEN = offset;
|
|
186
|
+
return ptr;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function takeObject(idx) {
|
|
190
|
+
const ret = getObject(idx);
|
|
191
|
+
dropObject(idx);
|
|
192
|
+
return ret;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
196
|
+
cachedTextDecoder.decode();
|
|
197
|
+
function decodeText(ptr, len) {
|
|
198
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const cachedTextEncoder = new TextEncoder();
|
|
202
|
+
|
|
203
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
204
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
205
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
206
|
+
view.set(buf);
|
|
207
|
+
return {
|
|
208
|
+
read: arg.length,
|
|
209
|
+
written: buf.length
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let WASM_VECTOR_LEN = 0;
|
|
215
|
+
|
|
216
|
+
const wasmPath = `${__dirname}/ruvector_decompiler_wasm_bg.wasm`;
|
|
217
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
218
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
219
|
+
let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
220
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const decompile: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
5
|
+
export const version: (a: number) => void;
|
|
6
|
+
export const init: () => void;
|
|
7
|
+
export const mincut_add_result: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
8
|
+
export const mincut_get_coordinator: () => number;
|
|
9
|
+
export const mincut_get_result: () => number;
|
|
10
|
+
export const mincut_init: (a: number, b: number, c: number) => void;
|
|
11
|
+
export const mincut_is_complete: () => number;
|
|
12
|
+
export const __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
14
|
+
export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
|
|
15
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
16
|
+
export const __wbindgen_start: () => void;
|