@diffmind/core-wasm 0.1.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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +25 -0
  3. package/pkg/core_wasm.js +282 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diffmind Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@diffmind/core-wasm",
3
+ "version": "0.1.0",
4
+ "description": "diffmind Wasm core — compiled from Rust via wasm-pack",
5
+ "license": "MIT",
6
+ "author": "Thinkgrid Labs <hello@thinkgrid.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/thinkgrid-labs/diffmind.git",
10
+ "directory": "packages/core-wasm"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./pkg/core_wasm.js",
16
+ "types": "./pkg/core_wasm.d.ts",
17
+ "files": [
18
+ "pkg/"
19
+ ],
20
+ "scripts": {
21
+ "build": "wasm-pack build --target nodejs --out-dir pkg --out-name core_wasm",
22
+ "build:web": "wasm-pack build --target web --out-dir pkg-web --out-name core_wasm",
23
+ "test": "wasm-pack test --node"
24
+ }
25
+ }
@@ -0,0 +1,282 @@
1
+ /* @ts-self-types="./core_wasm.d.ts" */
2
+
3
+ class ReviewAnalyzer {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ ReviewAnalyzerFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_reviewanalyzer_free(ptr, 0);
13
+ }
14
+ /**
15
+ * @param {string} diff
16
+ * @returns {string}
17
+ */
18
+ analyze_diff(diff) {
19
+ let deferred3_0;
20
+ let deferred3_1;
21
+ try {
22
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
23
+ const ptr0 = passStringToWasm0(diff, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
24
+ const len0 = WASM_VECTOR_LEN;
25
+ wasm.reviewanalyzer_analyze_diff(retptr, this.__wbg_ptr, ptr0, len0);
26
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
27
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
28
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
29
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
30
+ var ptr2 = r0;
31
+ var len2 = r1;
32
+ if (r3) {
33
+ ptr2 = 0; len2 = 0;
34
+ throw takeObject(r2);
35
+ }
36
+ deferred3_0 = ptr2;
37
+ deferred3_1 = len2;
38
+ return getStringFromWasm0(ptr2, len2);
39
+ } finally {
40
+ wasm.__wbindgen_add_to_stack_pointer(16);
41
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
42
+ }
43
+ }
44
+ /**
45
+ * @param {string} diff
46
+ * @param {number} _max_tokens_per_chunk
47
+ * @returns {string}
48
+ */
49
+ analyze_diff_chunked(diff, _max_tokens_per_chunk) {
50
+ let deferred3_0;
51
+ let deferred3_1;
52
+ try {
53
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
54
+ const ptr0 = passStringToWasm0(diff, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
55
+ const len0 = WASM_VECTOR_LEN;
56
+ wasm.reviewanalyzer_analyze_diff_chunked(retptr, this.__wbg_ptr, ptr0, len0, _max_tokens_per_chunk);
57
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
58
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
59
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
60
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
61
+ var ptr2 = r0;
62
+ var len2 = r1;
63
+ if (r3) {
64
+ ptr2 = 0; len2 = 0;
65
+ throw takeObject(r2);
66
+ }
67
+ deferred3_0 = ptr2;
68
+ deferred3_1 = len2;
69
+ return getStringFromWasm0(ptr2, len2);
70
+ } finally {
71
+ wasm.__wbindgen_add_to_stack_pointer(16);
72
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
73
+ }
74
+ }
75
+ /**
76
+ * @param {Uint8Array} model_bytes
77
+ * @param {Uint8Array} tokenizer_bytes
78
+ */
79
+ constructor(model_bytes, tokenizer_bytes) {
80
+ try {
81
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
82
+ const ptr0 = passArray8ToWasm0(model_bytes, wasm.__wbindgen_export3);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ptr1 = passArray8ToWasm0(tokenizer_bytes, wasm.__wbindgen_export3);
85
+ const len1 = WASM_VECTOR_LEN;
86
+ wasm.reviewanalyzer_new(retptr, ptr0, len0, ptr1, len1);
87
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
88
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
89
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
90
+ if (r2) {
91
+ throw takeObject(r1);
92
+ }
93
+ this.__wbg_ptr = r0 >>> 0;
94
+ ReviewAnalyzerFinalization.register(this, this.__wbg_ptr, this);
95
+ return this;
96
+ } finally {
97
+ wasm.__wbindgen_add_to_stack_pointer(16);
98
+ }
99
+ }
100
+ }
101
+ if (Symbol.dispose) ReviewAnalyzer.prototype[Symbol.dispose] = ReviewAnalyzer.prototype.free;
102
+ exports.ReviewAnalyzer = ReviewAnalyzer;
103
+ function __wbg_get_imports() {
104
+ const import0 = {
105
+ __proto__: null,
106
+ __wbg_Error_960c155d3d49e4c2: function(arg0, arg1) {
107
+ const ret = Error(getStringFromWasm0(arg0, arg1));
108
+ return addHeapObject(ret);
109
+ },
110
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
111
+ throw new Error(getStringFromWasm0(arg0, arg1));
112
+ },
113
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
114
+ let deferred0_0;
115
+ let deferred0_1;
116
+ try {
117
+ deferred0_0 = arg0;
118
+ deferred0_1 = arg1;
119
+ console.error(getStringFromWasm0(arg0, arg1));
120
+ } finally {
121
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
122
+ }
123
+ },
124
+ __wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
125
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
126
+ }, arguments); },
127
+ __wbg_new_227d7c05414eb861: function() {
128
+ const ret = new Error();
129
+ return addHeapObject(ret);
130
+ },
131
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
132
+ const ret = getObject(arg1).stack;
133
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
134
+ const len1 = WASM_VECTOR_LEN;
135
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
136
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
137
+ },
138
+ __wbindgen_object_drop_ref: function(arg0) {
139
+ takeObject(arg0);
140
+ },
141
+ };
142
+ return {
143
+ __proto__: null,
144
+ "./core_wasm_bg.js": import0,
145
+ };
146
+ }
147
+
148
+ const ReviewAnalyzerFinalization = (typeof FinalizationRegistry === 'undefined')
149
+ ? { register: () => {}, unregister: () => {} }
150
+ : new FinalizationRegistry(ptr => wasm.__wbg_reviewanalyzer_free(ptr >>> 0, 1));
151
+
152
+ function addHeapObject(obj) {
153
+ if (heap_next === heap.length) heap.push(heap.length + 1);
154
+ const idx = heap_next;
155
+ heap_next = heap[idx];
156
+
157
+ heap[idx] = obj;
158
+ return idx;
159
+ }
160
+
161
+ function dropObject(idx) {
162
+ if (idx < 1028) return;
163
+ heap[idx] = heap_next;
164
+ heap_next = idx;
165
+ }
166
+
167
+ function getArrayU8FromWasm0(ptr, len) {
168
+ ptr = ptr >>> 0;
169
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
170
+ }
171
+
172
+ let cachedDataViewMemory0 = null;
173
+ function getDataViewMemory0() {
174
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
175
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
176
+ }
177
+ return cachedDataViewMemory0;
178
+ }
179
+
180
+ function getStringFromWasm0(ptr, len) {
181
+ ptr = ptr >>> 0;
182
+ return decodeText(ptr, len);
183
+ }
184
+
185
+ let cachedUint8ArrayMemory0 = null;
186
+ function getUint8ArrayMemory0() {
187
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
188
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
189
+ }
190
+ return cachedUint8ArrayMemory0;
191
+ }
192
+
193
+ function getObject(idx) { return heap[idx]; }
194
+
195
+ function handleError(f, args) {
196
+ try {
197
+ return f.apply(this, args);
198
+ } catch (e) {
199
+ wasm.__wbindgen_export2(addHeapObject(e));
200
+ }
201
+ }
202
+
203
+ let heap = new Array(1024).fill(undefined);
204
+ heap.push(undefined, null, true, false);
205
+
206
+ let heap_next = heap.length;
207
+
208
+ function passArray8ToWasm0(arg, malloc) {
209
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
210
+ getUint8ArrayMemory0().set(arg, ptr / 1);
211
+ WASM_VECTOR_LEN = arg.length;
212
+ return ptr;
213
+ }
214
+
215
+ function passStringToWasm0(arg, malloc, realloc) {
216
+ if (realloc === undefined) {
217
+ const buf = cachedTextEncoder.encode(arg);
218
+ const ptr = malloc(buf.length, 1) >>> 0;
219
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
220
+ WASM_VECTOR_LEN = buf.length;
221
+ return ptr;
222
+ }
223
+
224
+ let len = arg.length;
225
+ let ptr = malloc(len, 1) >>> 0;
226
+
227
+ const mem = getUint8ArrayMemory0();
228
+
229
+ let offset = 0;
230
+
231
+ for (; offset < len; offset++) {
232
+ const code = arg.charCodeAt(offset);
233
+ if (code > 0x7F) break;
234
+ mem[ptr + offset] = code;
235
+ }
236
+ if (offset !== len) {
237
+ if (offset !== 0) {
238
+ arg = arg.slice(offset);
239
+ }
240
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
241
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
242
+ const ret = cachedTextEncoder.encodeInto(arg, view);
243
+
244
+ offset += ret.written;
245
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
246
+ }
247
+
248
+ WASM_VECTOR_LEN = offset;
249
+ return ptr;
250
+ }
251
+
252
+ function takeObject(idx) {
253
+ const ret = getObject(idx);
254
+ dropObject(idx);
255
+ return ret;
256
+ }
257
+
258
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
259
+ cachedTextDecoder.decode();
260
+ function decodeText(ptr, len) {
261
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
262
+ }
263
+
264
+ const cachedTextEncoder = new TextEncoder();
265
+
266
+ if (!('encodeInto' in cachedTextEncoder)) {
267
+ cachedTextEncoder.encodeInto = function (arg, view) {
268
+ const buf = cachedTextEncoder.encode(arg);
269
+ view.set(buf);
270
+ return {
271
+ read: arg.length,
272
+ written: buf.length
273
+ };
274
+ };
275
+ }
276
+
277
+ let WASM_VECTOR_LEN = 0;
278
+
279
+ const wasmPath = `${__dirname}/core_wasm_bg.wasm`;
280
+ const wasmBytes = require('fs').readFileSync(wasmPath);
281
+ const wasmModule = new WebAssembly.Module(wasmBytes);
282
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;