@hmharness/cognitive 0.23.32 → 0.23.33
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/dist/rlm-sandbox.js +17 -17
- package/dist/world-model.d.ts +16 -0
- package/dist/world-model.js +53 -0
- package/package.json +31 -31
package/dist/rlm-sandbox.js
CHANGED
|
@@ -29,23 +29,23 @@ import { Worker } from 'node:worker_threads';
|
|
|
29
29
|
* spawn). What remains impossible to block without a per-worker
|
|
30
30
|
* permission model is declared in SANDBOX_BYPASS_VECTORS below — pinned
|
|
31
31
|
* by the red-team test so a silent hole can never masquerade as covered. */
|
|
32
|
-
const WORKER_SOURCE = `
|
|
33
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
34
|
-
(async () => {
|
|
35
|
-
// hardening pass: strip escape globals BEFORE evaluating any user code
|
|
36
|
-
try { delete globalThis.process; } catch { /* non-configurable: shadow instead below */ }
|
|
37
|
-
try { globalThis.Worker = undefined; } catch { }
|
|
38
|
-
try { globalThis.fetch = undefined; } catch { }
|
|
39
|
-
try { globalThis.WebSocket = undefined; } catch { }
|
|
40
|
-
const ctx = Object.freeze({ vars: Object.freeze({ ...workerData.vars }), meta: Object.freeze({ ...workerData.meta }) });
|
|
41
|
-
try {
|
|
42
|
-
const fn = new Function('ctx', 'process', 'require', 'fetch', 'Worker', 'WebSocket', '"use strict";return (async()=>{' + workerData.code + '})();');
|
|
43
|
-
const value = await fn(ctx, undefined, undefined, undefined, undefined, undefined);
|
|
44
|
-
parentPort.postMessage({ ok: true, value });
|
|
45
|
-
} catch (err) {
|
|
46
|
-
parentPort.postMessage({ ok: false, error: { code: 'E_EVAL', message: err && err.message ? String(err.message).slice(0, 500) : String(err).slice(0, 500) } });
|
|
47
|
-
}
|
|
48
|
-
})();
|
|
32
|
+
const WORKER_SOURCE = `
|
|
33
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
34
|
+
(async () => {
|
|
35
|
+
// hardening pass: strip escape globals BEFORE evaluating any user code
|
|
36
|
+
try { delete globalThis.process; } catch { /* non-configurable: shadow instead below */ }
|
|
37
|
+
try { globalThis.Worker = undefined; } catch { }
|
|
38
|
+
try { globalThis.fetch = undefined; } catch { }
|
|
39
|
+
try { globalThis.WebSocket = undefined; } catch { }
|
|
40
|
+
const ctx = Object.freeze({ vars: Object.freeze({ ...workerData.vars }), meta: Object.freeze({ ...workerData.meta }) });
|
|
41
|
+
try {
|
|
42
|
+
const fn = new Function('ctx', 'process', 'require', 'fetch', 'Worker', 'WebSocket', '"use strict";return (async()=>{' + workerData.code + '})();');
|
|
43
|
+
const value = await fn(ctx, undefined, undefined, undefined, undefined, undefined);
|
|
44
|
+
parentPort.postMessage({ ok: true, value });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
parentPort.postMessage({ ok: false, error: { code: 'E_EVAL', message: err && err.message ? String(err.message).slice(0, 500) : String(err).slice(0, 500) } });
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
49
|
`;
|
|
50
50
|
/**
|
|
51
51
|
* HONEST threat model: escape vectors the worker CANNOT block today (they
|
package/dist/world-model.d.ts
CHANGED
|
@@ -192,4 +192,20 @@ export declare class WorldModel {
|
|
|
192
192
|
meanError: number | undefined;
|
|
193
193
|
};
|
|
194
194
|
get transitionsStore(): TransitionStore;
|
|
195
|
+
/** WM checkpoint: a serializable snapshot that fromCheckpoint() can restore
|
|
196
|
+
* exactly — the state, the rolling accuracy counters, and the transitions
|
|
197
|
+
* (the replay/revision evidence, capped to the most recent N). */
|
|
198
|
+
checkpoint(maxTransitions?: number): string;
|
|
199
|
+
static fromCheckpoint(json: string): WorldModel;
|
|
200
|
+
/** Stale-belief detection (0.30): beliefs whose last confirming evidence is
|
|
201
|
+
* older than the threshold are flagged — a long-running session should
|
|
202
|
+
* distrust them for planning until fresh evidence reconfirms. A belief
|
|
203
|
+
* never confirmed (no lastConfirmedAt) is flagged only when the model has
|
|
204
|
+
* been running (version > 1), so fresh models don't false-alarm. */
|
|
205
|
+
staleBeliefs(maxAgeMs: number, now?: Date): Array<{
|
|
206
|
+
id: string;
|
|
207
|
+
claim: string;
|
|
208
|
+
lastConfirmedAt?: string;
|
|
209
|
+
ageMs: number;
|
|
210
|
+
}>;
|
|
195
211
|
}
|
package/dist/world-model.js
CHANGED
|
@@ -299,4 +299,57 @@ export class WorldModel {
|
|
|
299
299
|
get transitionsStore() {
|
|
300
300
|
return this.transitions;
|
|
301
301
|
}
|
|
302
|
+
/* -------- Long-running sessions (weekly pack 0.30 P2 infrastructure) -------- */
|
|
303
|
+
/** WM checkpoint: a serializable snapshot that fromCheckpoint() can restore
|
|
304
|
+
* exactly — the state, the rolling accuracy counters, and the transitions
|
|
305
|
+
* (the replay/revision evidence, capped to the most recent N). */
|
|
306
|
+
checkpoint(maxTransitions = 1000) {
|
|
307
|
+
return JSON.stringify({
|
|
308
|
+
kind: 'hmharness-world-model-checkpoint',
|
|
309
|
+
version: 1,
|
|
310
|
+
state: this.state,
|
|
311
|
+
deltaChecked: this.deltaChecked,
|
|
312
|
+
deltaHits: this.deltaHits,
|
|
313
|
+
seq: this.seq,
|
|
314
|
+
predictions: [...this.predictions.values()].slice(-200),
|
|
315
|
+
transitions: this.transitions.all().slice(-maxTransitions),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
static fromCheckpoint(json) {
|
|
319
|
+
const j = JSON.parse(json);
|
|
320
|
+
if (j.kind !== 'hmharness-world-model-checkpoint')
|
|
321
|
+
throw new Error('not a world-model checkpoint');
|
|
322
|
+
const wm = new WorldModel(j.state.environmentId);
|
|
323
|
+
wm.state = j.state;
|
|
324
|
+
wm.deltaChecked = j.deltaChecked;
|
|
325
|
+
wm.deltaHits = j.deltaHits;
|
|
326
|
+
wm.seq = j.seq;
|
|
327
|
+
for (const p of j.predictions ?? [])
|
|
328
|
+
wm.predictions.set(p.id, p);
|
|
329
|
+
for (const t of j.transitions ?? [])
|
|
330
|
+
wm.transitions.append(t);
|
|
331
|
+
return wm;
|
|
332
|
+
}
|
|
333
|
+
/** Stale-belief detection (0.30): beliefs whose last confirming evidence is
|
|
334
|
+
* older than the threshold are flagged — a long-running session should
|
|
335
|
+
* distrust them for planning until fresh evidence reconfirms. A belief
|
|
336
|
+
* never confirmed (no lastConfirmedAt) is flagged only when the model has
|
|
337
|
+
* been running (version > 1), so fresh models don't false-alarm. */
|
|
338
|
+
staleBeliefs(maxAgeMs, now = new Date()) {
|
|
339
|
+
if (this.state.version <= 1)
|
|
340
|
+
return [];
|
|
341
|
+
const nowMs = now.getTime();
|
|
342
|
+
return this.state.beliefs
|
|
343
|
+
.filter((b) => {
|
|
344
|
+
if (!b.lastConfirmedAt)
|
|
345
|
+
return true; // never confirmed = stale by definition (after warm-up)
|
|
346
|
+
return nowMs - new Date(b.lastConfirmedAt).getTime() >= maxAgeMs;
|
|
347
|
+
})
|
|
348
|
+
.map((b) => ({
|
|
349
|
+
id: b.id,
|
|
350
|
+
claim: b.claim,
|
|
351
|
+
...(b.lastConfirmedAt ? { lastConfirmedAt: b.lastConfirmedAt } : {}),
|
|
352
|
+
ageMs: b.lastConfirmedAt ? nowMs - new Date(b.lastConfirmedAt).getTime() : Infinity,
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
302
355
|
}
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hmharness/cognitive",
|
|
3
|
-
"version": "0.23.
|
|
4
|
-
"description": "hmharness Cognitive OS core: Environment protocol, World Model, Goal system, Exploration, RLM runtime, five-layer memory, Skill Compiler, Continual Learning control plane, Evolution 2.0 governance, Multi-Agent topology, Transfer lab and GeneralBench schema. Cognitive strategy layer per the HMH Cognitive OS blueprint (2026-09).",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"default": "./dist/index.js"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"types": "dist/index.d.ts",
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc -p tsconfig.build.json"
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/swsgbl/hmharness.git"
|
|
24
|
-
},
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": ">=22"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@hmharness/kernel": "0.23.
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@hmharness/cognitive",
|
|
3
|
+
"version": "0.23.33",
|
|
4
|
+
"description": "hmharness Cognitive OS core: Environment protocol, World Model, Goal system, Exploration, RLM runtime, five-layer memory, Skill Compiler, Continual Learning control plane, Evolution 2.0 governance, Multi-Agent topology, Transfer lab and GeneralBench schema. Cognitive strategy layer per the HMH Cognitive OS blueprint (2026-09).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/swsgbl/hmharness.git"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hmharness/kernel": "0.23.33"
|
|
30
|
+
}
|
|
31
|
+
}
|