@hmharness/cognitive 0.23.14 → 0.23.15

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.
@@ -84,6 +84,17 @@ export interface EnvironmentScore {
84
84
  export interface Environment {
85
85
  id: string;
86
86
  version: string;
87
+ /**
88
+ * Snapshot semantics (review 02 doc, Snapshot/Restore v2). Every
89
+ * environment MUST declare what its snapshot/restore actually means:
90
+ * - deterministic: restore() returns the environment to the exact
91
+ * snapshotted state (in-memory scratch worlds)
92
+ * - forkable: state copies into independent branches (RLM-style)
93
+ * - observational: the snapshot is an OBSERVATION for audit/diff only;
94
+ * restore() cannot rewind the real world and must not pretend to
95
+ * (browsers, desktops, devices, live games)
96
+ */
97
+ snapshotClass: 'deterministic' | 'forkable' | 'observational';
87
98
  capabilities(): Promise<Capability[]>;
88
99
  reset(opts?: ResetOptions): Promise<Observation>;
89
100
  observe(): Promise<Observation>;
@@ -50,6 +50,7 @@ export declare class EnvironmentRegistry {
50
50
  export declare class MemoryEnvironment implements Environment {
51
51
  id: string;
52
52
  version: string;
53
+ snapshotClass: "deterministic";
53
54
  private state;
54
55
  private stepCount;
55
56
  constructor(id?: string);
package/dist/registry.js CHANGED
@@ -92,6 +92,15 @@ export class EnvironmentRegistry {
92
92
  if (r.outcome === 'failure' && !r.error)
93
93
  throw new Error('failure without structured error');
94
94
  });
95
+ await step('snapshot-class', async () => {
96
+ // Snapshot/Restore v2: every environment declares what its snapshot
97
+ // MEANS; observational ones must not be treated as rewindable by
98
+ // callers (the hash-divergence check below is advisory for them).
99
+ const cls = env.snapshotClass;
100
+ if (!['deterministic', 'forkable', 'observational'].includes(cls ?? '')) {
101
+ throw new Error(`snapshotClass must be declared (got ${String(cls)})`);
102
+ }
103
+ });
95
104
  await step('snapshot+restore', async () => {
96
105
  const snap = await env.snapshot();
97
106
  if (typeof snap.stateHash !== 'string' || !snap.stateHash)
@@ -99,7 +108,11 @@ export class EnvironmentRegistry {
99
108
  await env.restore(snap);
100
109
  const after = await env.snapshot();
101
110
  if (after.stateHash !== stableHash(snap.payload) && after.stateHash !== snap.stateHash) {
102
- // hash drift after immediate restore means restore is not faithful
111
+ // hash drift after immediate restore means restore is not faithful.
112
+ // For observational environments this is EXPECTED (restore is a
113
+ // no-op); only deterministic/forkable worlds must replay exactly.
114
+ if (env.snapshotClass === 'observational')
115
+ return;
103
116
  failures.push('snapshot/restore: stateHash diverged right after restore');
104
117
  }
105
118
  });
@@ -125,6 +138,7 @@ function withTimeout(p, ms, message) {
125
138
  export class MemoryEnvironment {
126
139
  id;
127
140
  version = '1.0.0';
141
+ snapshotClass = 'deterministic'; // in-memory scratch world: restore replays exactly
128
142
  state = {};
129
143
  stepCount = 0;
130
144
  constructor(id = 'memory') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/cognitive",
3
- "version": "0.23.14",
3
+ "version": "0.23.15",
4
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
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,6 +26,6 @@
26
26
  "node": ">=22"
27
27
  },
28
28
  "dependencies": {
29
- "@hmharness/kernel": "0.23.14"
29
+ "@hmharness/kernel": "0.23.15"
30
30
  }
31
31
  }