@hmharness/cognitive 0.23.1 → 0.23.3

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.
@@ -72,6 +72,24 @@ export interface Arc3MetricsReport {
72
72
  * recovery metrics over recorded ARC-AGI-3 plays (trajectories + episodic
73
73
  * summaries). Honest on empty: null, never zeros-that-lie. */
74
74
  export declare function arc3Metrics(home: string, limit?: number): Promise<Arc3MetricsReport | null>;
75
+ export interface CalibrationRow {
76
+ actionType: string;
77
+ predictions: number;
78
+ meanError: number;
79
+ /** 1 - meanError: how trustworthy the model's instinct on this action is */
80
+ reliability: number;
81
+ }
82
+ export interface CalibrationReport {
83
+ totalSteps: number;
84
+ predictedSteps: number;
85
+ overallMeanError: number | null;
86
+ overallReliability: number | null;
87
+ rows: CalibrationRow[];
88
+ }
89
+ /** The crown-jewel metric made first-class: per-action prediction calibration
90
+ * over the whole trajectory store — the dimension where the harness's value
91
+ * is PROVEN (+0.4166 transfer); this surfaces it for the CLI and panel. */
92
+ export declare function calibrationReport(home: string, topN?: number): Promise<CalibrationReport>;
75
93
  /** Compact world-model digest for the SYSTEM PROMPT. The model sees which
76
94
  * tool types history trusts, which keep failing, and what the diagnosis
77
95
  * layer currently suggests — perception feeding action, capped hard so it
package/dist/analysis.js CHANGED
@@ -171,6 +171,49 @@ export async function arc3Metrics(home, limit = 100) {
171
171
  perPlay,
172
172
  };
173
173
  }
174
+ /** The crown-jewel metric made first-class: per-action prediction calibration
175
+ * over the whole trajectory store — the dimension where the harness's value
176
+ * is PROVEN (+0.4166 transfer); this surfaces it for the CLI and panel. */
177
+ export async function calibrationReport(home, topN = 12) {
178
+ const trajectories = await loadTrajectories(home, 500);
179
+ const byType = new Map();
180
+ let total = 0;
181
+ let predicted = 0;
182
+ let errSum = 0;
183
+ for (const traj of trajectories) {
184
+ for (const s of traj.steps) {
185
+ total++;
186
+ if (!s.prediction)
187
+ continue;
188
+ predicted++;
189
+ const actual = s.outcome === 'success' ? 1 : 0;
190
+ const err = Math.abs(s.prediction.confidence - actual);
191
+ errSum += err;
192
+ const t = s.action.type;
193
+ const agg = byType.get(t) ?? { n: 0, err: 0 };
194
+ agg.n++;
195
+ agg.err += err;
196
+ byType.set(t, agg);
197
+ }
198
+ }
199
+ const rows = [...byType.entries()]
200
+ .map(([actionType, v]) => ({
201
+ actionType,
202
+ predictions: v.n,
203
+ meanError: Number((v.err / v.n).toFixed(3)),
204
+ reliability: Number((1 - v.err / v.n).toFixed(3)),
205
+ }))
206
+ .sort((a, b) => b.predictions - a.predictions)
207
+ .slice(0, topN);
208
+ const overallMeanError = predicted ? Number((errSum / predicted).toFixed(3)) : null;
209
+ return {
210
+ totalSteps: total,
211
+ predictedSteps: predicted,
212
+ overallMeanError,
213
+ overallReliability: overallMeanError === null ? null : Number((1 - overallMeanError).toFixed(3)),
214
+ rows,
215
+ };
216
+ }
174
217
  /* ---- context advisor (blueprint M3: the planner consumes the world model) ---- */
175
218
  /** Compact world-model digest for the SYSTEM PROMPT. The model sees which
176
219
  * tool types history trusts, which keep failing, and what the diagnosis
@@ -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.1",
3
+ "version": "0.23.3",
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.1"
29
+ "@hmharness/kernel": "0.23.3"
30
30
  }
31
31
  }