@metaharness/kernel 0.1.7 → 0.1.8

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.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <!-- ruv-seo:start (ADR-356) -->
4
4
  `@metaharness/kernel` is the shared runtime contract for MetaHarness: the `HarnessSpec` and `HostAdapter` types, MCP server validation, a hash-chained `SessionLog`, and memory backends, behind one `loadKernel()` that picks a native, WASM or pure-JS backend.
5
5
 
6
- **Supported environments:** Node.js 20+ on Linux, macOS and Windows. ESM only (`import`, not `require`). `loadKernel()` prefers an installed per-platform native package, then WASM, then a dependency-free JavaScript backend; the native packages are optional peers that are not yet on npm, and the published tarball currently resolves to the JS backend, as the output below shows. `@ruvector/rvf` is an optional peer for the persistent `memory-rvf` backend.
6
+ **Supported environments:** Node.js 20+ on Linux, macOS and Windows. ESM only (`import`, not `require`). `loadKernel()` prefers an installed per-platform native package, then WASM, then a dependency-free JavaScript backend; the native packages are optional peers that are not yet on npm, so a plain install resolves to the bundled WASM backend, as the output below shows. `kernelInfo().version` is the version of the compiled Rust kernel, not the npm package. `@ruvector/rvf` is an optional peer for the persistent `memory-rvf` backend.
7
7
 
8
8
  ## Quickstart
9
9
 
@@ -27,7 +27,7 @@ node quickstart.mjs
27
27
  Expected output:
28
28
 
29
29
  ```text
30
- kernel 0.1.7 (js backend)
30
+ kernel 0.1.0 (wasm backend)
31
31
  valid spec -> ok
32
32
  broken spec -> mcp: server name is empty
33
33
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metaharness/kernel",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Cross-platform kernel for MetaHarness harnesses: the HarnessSpec and HostAdapter contract, memory backends, and a WASM-first runtime with NAPI-RS native and pure-JS fallbacks.",
5
5
  "homepage": "https://ruv.io",
6
6
  "repository": {
@@ -40,6 +40,13 @@
40
40
  "README.md",
41
41
  "LICENSE"
42
42
  ],
43
+ "metaharness": {
44
+ "wasmArtifacts": [
45
+ "pkg/package.json",
46
+ "pkg/ruflo_kernel_wasm.js",
47
+ "pkg/ruflo_kernel_wasm_bg.wasm"
48
+ ]
49
+ },
43
50
  "scripts": {
44
51
  "build": "tsc",
45
52
  "test": "vitest run",
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "ruflo-kernel-wasm",
3
+ "collaborators": [
4
+ "rUv <ruv@ruv.net>"
5
+ ],
6
+ "description": "WebAssembly bindings for ruflo-kernel",
7
+ "version": "0.1.0",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ruvnet/agent-harness-generator"
12
+ },
13
+ "files": [
14
+ "ruflo_kernel_wasm_bg.wasm",
15
+ "ruflo_kernel_wasm.js",
16
+ "ruflo_kernel_wasm.d.ts"
17
+ ],
18
+ "main": "ruflo_kernel_wasm.js",
19
+ "types": "ruflo_kernel_wasm.d.ts",
20
+ "type": "commonjs"
21
+ }
@@ -0,0 +1,41 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Validate an autonomous spec block (ADR-246 §2.2).
6
+ * Returns a JS array of lockstep error strings; empty array = valid.
7
+ */
8
+ export function autonomousValidate(spec_json: string): any;
9
+
10
+ /**
11
+ * Return kernel build metadata as a JS object.
12
+ */
13
+ export function kernelInfo(): any;
14
+
15
+ /**
16
+ * Validate an MCP server spec (returns `null` on success, error string otherwise).
17
+ */
18
+ export function mcpValidate(spec_json: string): any;
19
+
20
+ /**
21
+ * Replay a branch of a JSONL session log.
22
+ * Returns `{ eventCount, stateHash }` on success, error string otherwise.
23
+ */
24
+ export function sessionReplay(log_jsonl: string, branch: string): any;
25
+
26
+ /**
27
+ * Deterministic state hash (lowercase sha256 hex) of a branch lineage
28
+ * in a JSONL session log.
29
+ */
30
+ export function sessionStateHash(log_jsonl: string, branch: string): string;
31
+
32
+ /**
33
+ * Validate a JSONL session log (ADR-246 §2.3).
34
+ * Returns a JS array of 'session: '-prefixed error strings; empty = valid.
35
+ */
36
+ export function sessionValidate(log_jsonl: string): any;
37
+
38
+ /**
39
+ * Returns the package version.
40
+ */
41
+ export function version(): string;
@@ -0,0 +1,349 @@
1
+ /* @ts-self-types="./ruflo_kernel_wasm.d.ts" */
2
+
3
+ /**
4
+ * Validate an autonomous spec block (ADR-246 §2.2).
5
+ * Returns a JS array of lockstep error strings; empty array = valid.
6
+ * @param {string} spec_json
7
+ * @returns {any}
8
+ */
9
+ function autonomousValidate(spec_json) {
10
+ try {
11
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
12
+ const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
13
+ const len0 = WASM_VECTOR_LEN;
14
+ wasm.autonomousValidate(retptr, ptr0, len0);
15
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
16
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
17
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
18
+ if (r2) {
19
+ throw takeFromExternrefTable0(r1);
20
+ }
21
+ return takeFromExternrefTable0(r0);
22
+ } finally {
23
+ wasm.__wbindgen_add_to_stack_pointer(16);
24
+ }
25
+ }
26
+ exports.autonomousValidate = autonomousValidate;
27
+
28
+ /**
29
+ * Return kernel build metadata as a JS object.
30
+ * @returns {any}
31
+ */
32
+ function kernelInfo() {
33
+ try {
34
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
35
+ wasm.kernelInfo(retptr);
36
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
37
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
38
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
39
+ if (r2) {
40
+ throw takeFromExternrefTable0(r1);
41
+ }
42
+ return takeFromExternrefTable0(r0);
43
+ } finally {
44
+ wasm.__wbindgen_add_to_stack_pointer(16);
45
+ }
46
+ }
47
+ exports.kernelInfo = kernelInfo;
48
+
49
+ /**
50
+ * Validate an MCP server spec (returns `null` on success, error string otherwise).
51
+ * @param {string} spec_json
52
+ * @returns {any}
53
+ */
54
+ function mcpValidate(spec_json) {
55
+ try {
56
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
57
+ const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
58
+ const len0 = WASM_VECTOR_LEN;
59
+ wasm.mcpValidate(retptr, ptr0, len0);
60
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
61
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
62
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
63
+ if (r2) {
64
+ throw takeFromExternrefTable0(r1);
65
+ }
66
+ return takeFromExternrefTable0(r0);
67
+ } finally {
68
+ wasm.__wbindgen_add_to_stack_pointer(16);
69
+ }
70
+ }
71
+ exports.mcpValidate = mcpValidate;
72
+
73
+ /**
74
+ * Replay a branch of a JSONL session log.
75
+ * Returns `{ eventCount, stateHash }` on success, error string otherwise.
76
+ * @param {string} log_jsonl
77
+ * @param {string} branch
78
+ * @returns {any}
79
+ */
80
+ function sessionReplay(log_jsonl, branch) {
81
+ try {
82
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
83
+ let ptr0, len0, ptr1, len1;
84
+ try {
85
+ ptr0 = passStringToWasm0(log_jsonl, wasm.__wbindgen_export, wasm.__wbindgen_export2);
86
+ len0 = WASM_VECTOR_LEN;
87
+ ptr1 = passStringToWasm0(branch, wasm.__wbindgen_export, wasm.__wbindgen_export2);
88
+ len1 = WASM_VECTOR_LEN;
89
+ } catch (e) {
90
+ if (ptr1) { wasm.__wbindgen_export3(ptr1, len1 * 1, 1); }
91
+ if (ptr0) { wasm.__wbindgen_export3(ptr0, len0 * 1, 1); }
92
+ throw e;
93
+ }
94
+ wasm.sessionReplay(retptr, ptr0, len0, ptr1, len1);
95
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
96
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
97
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
98
+ if (r2) {
99
+ throw takeFromExternrefTable0(r1);
100
+ }
101
+ return takeFromExternrefTable0(r0);
102
+ } finally {
103
+ wasm.__wbindgen_add_to_stack_pointer(16);
104
+ }
105
+ }
106
+ exports.sessionReplay = sessionReplay;
107
+
108
+ /**
109
+ * Deterministic state hash (lowercase sha256 hex) of a branch lineage
110
+ * in a JSONL session log.
111
+ * @param {string} log_jsonl
112
+ * @param {string} branch
113
+ * @returns {string}
114
+ */
115
+ function sessionStateHash(log_jsonl, branch) {
116
+ let deferred4_0;
117
+ let deferred4_1;
118
+ try {
119
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
120
+ let ptr0, len0, ptr1, len1;
121
+ try {
122
+ ptr0 = passStringToWasm0(log_jsonl, wasm.__wbindgen_export, wasm.__wbindgen_export2);
123
+ len0 = WASM_VECTOR_LEN;
124
+ ptr1 = passStringToWasm0(branch, wasm.__wbindgen_export, wasm.__wbindgen_export2);
125
+ len1 = WASM_VECTOR_LEN;
126
+ } catch (e) {
127
+ if (ptr1) { wasm.__wbindgen_export3(ptr1, len1 * 1, 1); }
128
+ if (ptr0) { wasm.__wbindgen_export3(ptr0, len0 * 1, 1); }
129
+ throw e;
130
+ }
131
+ wasm.sessionStateHash(retptr, ptr0, len0, ptr1, len1);
132
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
133
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
134
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
135
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
136
+ var ptr3 = r0;
137
+ var len3 = r1;
138
+ if (r3) {
139
+ ptr3 = 0; len3 = 0;
140
+ throw takeFromExternrefTable0(r2);
141
+ }
142
+ deferred4_0 = ptr3;
143
+ deferred4_1 = len3;
144
+ return getStringFromWasm0(ptr3, len3);
145
+ } finally {
146
+ wasm.__wbindgen_add_to_stack_pointer(16);
147
+ wasm.__wbindgen_export3(deferred4_0, deferred4_1, 1);
148
+ }
149
+ }
150
+ exports.sessionStateHash = sessionStateHash;
151
+
152
+ /**
153
+ * Validate a JSONL session log (ADR-246 §2.3).
154
+ * Returns a JS array of 'session: '-prefixed error strings; empty = valid.
155
+ * @param {string} log_jsonl
156
+ * @returns {any}
157
+ */
158
+ function sessionValidate(log_jsonl) {
159
+ try {
160
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
161
+ const ptr0 = passStringToWasm0(log_jsonl, wasm.__wbindgen_export, wasm.__wbindgen_export2);
162
+ const len0 = WASM_VECTOR_LEN;
163
+ wasm.sessionValidate(retptr, ptr0, len0);
164
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
165
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
166
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
167
+ if (r2) {
168
+ throw takeFromExternrefTable0(r1);
169
+ }
170
+ return takeFromExternrefTable0(r0);
171
+ } finally {
172
+ wasm.__wbindgen_add_to_stack_pointer(16);
173
+ }
174
+ }
175
+ exports.sessionValidate = sessionValidate;
176
+
177
+ /**
178
+ * Returns the package version.
179
+ * @returns {string}
180
+ */
181
+ function version() {
182
+ let deferred1_0;
183
+ let deferred1_1;
184
+ try {
185
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) >>> 0;
186
+ wasm.version(retptr);
187
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
188
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
189
+ deferred1_0 = r0;
190
+ deferred1_1 = r1;
191
+ return getStringFromWasm0(r0, r1);
192
+ } finally {
193
+ wasm.__wbindgen_add_to_stack_pointer(16);
194
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
195
+ }
196
+ }
197
+ exports.version = version;
198
+ function __wbg_get_imports() {
199
+ const import0 = {
200
+ __proto__: null,
201
+ __wbg_Error_208446807d0d1e30: function(arg0, arg1) {
202
+ const ret = Error(getStringFromWasm0(arg0, arg1));
203
+ return ret;
204
+ },
205
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
206
+ const ret = String(arg1);
207
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
208
+ const len1 = WASM_VECTOR_LEN;
209
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
210
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
211
+ },
212
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
213
+ throw new Error(getStringFromWasm0(arg0, arg1));
214
+ },
215
+ __wbg_new_37eb45aaf5eeb820: function() {
216
+ const ret = new Array();
217
+ return ret;
218
+ },
219
+ __wbg_new_cd4348290afae586: function() {
220
+ const ret = new Object();
221
+ return ret;
222
+ },
223
+ __wbg_set_d2d33b52458e984a: function(arg0, arg1, arg2) {
224
+ arg0[arg1 >>> 0] = arg2;
225
+ },
226
+ __wbg_set_e4b9a833d288759a: function(arg0, arg1, arg2) {
227
+ arg0[arg1] = arg2;
228
+ },
229
+ __wbindgen_generic_0000000000000001: function(arg0) {
230
+ // Cast intrinsic for `F64 -> Externref`.
231
+ const ret = arg0;
232
+ return ret;
233
+ },
234
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
235
+ // Cast intrinsic for `Ref(String) -> Externref`.
236
+ const ret = getStringFromWasm0(arg0, arg1);
237
+ return ret;
238
+ },
239
+ __wbindgen_generic_0000000000000003: function(arg0) {
240
+ // Cast intrinsic for `U64 -> Externref`.
241
+ const ret = BigInt.asUintN(64, arg0);
242
+ return ret;
243
+ },
244
+ __wbindgen_init_externref_table: function() {
245
+ const table = wasm.__wbindgen_externrefs;
246
+ table.set(0, undefined);
247
+ table.set(1024, undefined);
248
+ table.set(1025, null);
249
+ table.set(1026, true);
250
+ table.set(1027, false);
251
+ },
252
+ };
253
+ return {
254
+ __proto__: null,
255
+ "./ruflo_kernel_wasm_bg.js": import0,
256
+ };
257
+ }
258
+
259
+ let cachedDataViewMemory0 = null;
260
+ function getDataViewMemory0() {
261
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
262
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
263
+ }
264
+ return cachedDataViewMemory0;
265
+ }
266
+
267
+ function getStringFromWasm0(ptr, len) {
268
+ ptr = ptr >>> 0;
269
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
270
+ }
271
+
272
+ let cachedUint8ArrayMemory0 = null;
273
+ function getUint8ArrayMemory0() {
274
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
275
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
276
+ }
277
+ return cachedUint8ArrayMemory0;
278
+ }
279
+
280
+ function passStringToWasm0(arg, malloc, realloc) {
281
+ if (realloc === undefined) {
282
+ const buf = cachedTextEncoder.encode(arg);
283
+ const ptr = malloc(buf.length, 1) >>> 0;
284
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
285
+ WASM_VECTOR_LEN = buf.length;
286
+ return ptr;
287
+ }
288
+
289
+ let len = arg.length;
290
+ let ptr = malloc(len, 1) >>> 0;
291
+
292
+ const mem = getUint8ArrayMemory0();
293
+
294
+ let offset = 0;
295
+
296
+ for (; offset < len; offset++) {
297
+ const code = arg.charCodeAt(offset);
298
+ if (code > 0x7F) break;
299
+ mem[ptr + offset] = code;
300
+ }
301
+ if (offset !== len) {
302
+ if (offset !== 0) {
303
+ arg = arg.slice(offset);
304
+ }
305
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
306
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
307
+ const ret = cachedTextEncoder.encodeInto(arg, view);
308
+
309
+ offset += ret.written;
310
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
311
+ }
312
+
313
+ WASM_VECTOR_LEN = offset;
314
+ return ptr;
315
+ }
316
+
317
+ function takeFromExternrefTable0(idx) {
318
+ const value = wasm.__wbindgen_externrefs.get(idx);
319
+ wasm.__wbindgen_export4(idx);
320
+ return value;
321
+ }
322
+
323
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
324
+ cachedTextDecoder.decode();
325
+ function decodeText(bytes) {
326
+ return cachedTextDecoder.decode(bytes);
327
+ }
328
+
329
+ const cachedTextEncoder = new TextEncoder();
330
+
331
+ if (!('encodeInto' in cachedTextEncoder)) {
332
+ cachedTextEncoder.encodeInto = function (arg, view) {
333
+ const buf = cachedTextEncoder.encode(arg);
334
+ view.set(buf);
335
+ return {
336
+ read: arg.length,
337
+ written: buf.length
338
+ };
339
+ };
340
+ }
341
+
342
+ let WASM_VECTOR_LEN = 0;
343
+
344
+ const wasmPath = `${__dirname}/ruflo_kernel_wasm_bg.wasm`;
345
+ const wasmBytes = require('fs').readFileSync(wasmPath);
346
+ const wasmModule = new WebAssembly.Module(wasmBytes);
347
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
348
+ let wasm = wasmInstance.exports;
349
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const autonomousValidate: (a: number, b: number, c: number) => void;
5
+ export const kernelInfo: (a: number) => void;
6
+ export const mcpValidate: (a: number, b: number, c: number) => void;
7
+ export const sessionReplay: (a: number, b: number, c: number, d: number, e: number) => void;
8
+ export const sessionStateHash: (a: number, b: number, c: number, d: number, e: number) => void;
9
+ export const sessionValidate: (a: number, b: number, c: number) => void;
10
+ export const version: (a: number) => void;
11
+ export const __wbindgen_export: (a: number, b: number) => number;
12
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
14
+ export const __wbindgen_externrefs: WebAssembly.Table;
15
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
16
+ export const __wbindgen_export4: (a: number) => void;
17
+ export const __wbindgen_start: () => void;