@hmharness/cognitive 0.23.2 → 0.23.4

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.
@@ -36,6 +36,10 @@ export interface ExplorationContext {
36
36
  worldModel: WorldModel;
37
37
  goalKeywords?: string[];
38
38
  hypotheses: HypothesisRegistry;
39
+ /** calibration-targeted exploration (§26 finding→product): per-action
40
+ * 1−reliability from the trajectory store; poorly-calibrated actions get
41
+ * a score BOOST — the model's prediction error IS the information gain */
42
+ calibrationBias?: Record<string, number>;
39
43
  }
40
44
  export interface ExplorationOutcome {
41
45
  action: Action;
@@ -79,7 +83,11 @@ export interface ExplorationPolicy {
79
83
  export declare function noveltyScore(state: unknown, seenStates: unknown[]): number;
80
84
  export declare class UcbExplorationPolicy implements ExplorationPolicy {
81
85
  private weights;
82
- constructor(weights?: Required<NonNullable<ExplorationRunOptions['weights']>>);
86
+ /** calibration weight: 0 = pure UCB, >0 boosts poorly-predicted actions */
87
+ private calibrationWeight;
88
+ constructor(weights?: Required<NonNullable<ExplorationRunOptions['weights']>>,
89
+ /** calibration weight: 0 = pure UCB, >0 boosts poorly-predicted actions */
90
+ calibrationWeight?: number);
83
91
  informationGain(action: Action, state: {
84
92
  uncertaintyByAction: Record<string, number>;
85
93
  }): Promise<number>;
@@ -49,13 +49,17 @@ function stateFeatures(state, prefix = '') {
49
49
  }
50
50
  export class UcbExplorationPolicy {
51
51
  weights;
52
+ calibrationWeight;
52
53
  constructor(weights = {
53
54
  uncertainty: 0.35,
54
55
  information: 0.25,
55
56
  goal: 0.25,
56
57
  risk: 0.15,
57
- }) {
58
+ },
59
+ /** calibration weight: 0 = pure UCB, >0 boosts poorly-predicted actions */
60
+ calibrationWeight = 0.2) {
58
61
  this.weights = weights;
62
+ this.calibrationWeight = calibrationWeight;
59
63
  }
60
64
  async informationGain(action, state) {
61
65
  // actions of an uncertain type carry more information: resolving high
@@ -83,9 +87,13 @@ export class UcbExplorationPolicy {
83
87
  const risk = this.risk(probe) + (spec.irreversible ? 0.4 : 0);
84
88
  if (risk > opts.riskTolerance)
85
89
  continue; // EXP-007 safe exploration
90
+ // calibration targeting: the model's prediction error on this action
91
+ // type is direct evidence that probing it teaches the world model
92
+ const calBias = ctx.calibrationBias?.[spec.type] ?? 0;
86
93
  const score = this.weights.uncertainty * uncertainty +
87
94
  this.weights.information * info +
88
- this.weights.goal * goalRelevance -
95
+ this.weights.goal * goalRelevance +
96
+ this.calibrationWeight * calBias -
89
97
  this.weights.risk * risk;
90
98
  candidates.push({ spec, score });
91
99
  }
@@ -20,6 +20,8 @@ export interface ExploreOptions {
20
20
  goalKeywords?: string[];
21
21
  /** the concrete environment to explore (host wires the adapter) */
22
22
  env?: Environment;
23
+ /** calibration-targeting weight (0 disables; default 0.2) */
24
+ calibrationWeight?: number;
23
25
  }
24
26
  export interface ExploreSummary {
25
27
  result: ExplorationResult;
@@ -29,12 +29,21 @@ export async function runExploration(home, opts = {}) {
29
29
  });
30
30
  const rec = new TrajectoryRecorder(`trj-explore-${Date.now().toString(36)}`, `explore-${environmentId}`, { id: env.id, version: env.version }, { id: 'goal-explore', description: 'reduce uncertainty about the environment affordances' });
31
31
  const obs = await env.reset({});
32
- const engine = new ExplorationEngine(new UcbExplorationPolicy());
32
+ // calibration targeting (§26 finding→product): actions the model predicts
33
+ // POORLY get an exploration boost — prediction error is information gain
34
+ let calibrationBias;
35
+ try {
36
+ const { calibrationReport } = await import("./analysis.js");
37
+ const cal = await calibrationReport(home);
38
+ calibrationBias = Object.fromEntries(cal.rows.map((r) => [r.actionType, 1 - r.reliability]));
39
+ }
40
+ catch { /* bias is best-effort; plain UCB still works */ }
41
+ const engine = new ExplorationEngine(new UcbExplorationPolicy(undefined, opts.calibrationWeight ?? 0.2));
33
42
  const result = await engine.run({
34
43
  maxActions,
35
44
  maxCost,
36
45
  riskTolerance,
37
- ctx: { observation: obs, worldModel: wm, hypotheses, goalKeywords: opts.goalKeywords },
46
+ ctx: { observation: obs, worldModel: wm, hypotheses, goalKeywords: opts.goalKeywords, calibrationBias },
38
47
  act: async (action) => {
39
48
  const prediction = wm.predict({ action });
40
49
  const started = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/cognitive",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
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.2"
29
+ "@hmharness/kernel": "0.23.4"
30
30
  }
31
31
  }