@hmharness/cognitive 0.23.28 → 0.23.29
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/learning-targets.d.ts +14 -1
- package/dist/learning-targets.js +57 -1
- package/package.json +2 -2
|
@@ -27,7 +27,9 @@ import type { Candidate, EvalResult, LearningDataset, LearningPlan, LearningTarg
|
|
|
27
27
|
import type { CognitiveLedger } from './ledger.js';
|
|
28
28
|
import { type WorkflowCandidate } from './skill-compiler.js';
|
|
29
29
|
export type TargetTrainer = (plan: LearningPlan, dataset: LearningDataset) => Promise<Candidate>;
|
|
30
|
-
|
|
30
|
+
/** train rides along: deterministic-rebuild evaluators (world_model) need
|
|
31
|
+
* the exact training set; evaluators that don't care ignore the 3rd arg. */
|
|
32
|
+
export type TargetEvaluator = (candidate: Candidate, holdout: LearningDataset, train: LearningDataset) => Promise<EvalResult>;
|
|
31
33
|
export type TargetRollback = (candidate: Candidate) => Promise<void>;
|
|
32
34
|
export interface PromotionPolicy {
|
|
33
35
|
/** minimum evidence metric before promotion is even considered */
|
|
@@ -90,3 +92,14 @@ export declare function registerSkillTarget(registry: LearningTargetRegistry, op
|
|
|
90
92
|
policy?: Partial<PromotionPolicy>;
|
|
91
93
|
lineageSource?: string;
|
|
92
94
|
}): void;
|
|
95
|
+
export interface WorldModelCandidate extends Candidate {
|
|
96
|
+
environmentId: string;
|
|
97
|
+
beliefs: number;
|
|
98
|
+
corrections: number;
|
|
99
|
+
}
|
|
100
|
+
export declare function registerWorldModelTarget(registry: LearningTargetRegistry, opts: {
|
|
101
|
+
environmentId: string;
|
|
102
|
+
holdout: () => Promise<LearningDataset>;
|
|
103
|
+
policy?: Partial<PromotionPolicy>;
|
|
104
|
+
lineageSource?: string;
|
|
105
|
+
}): void;
|
package/dist/learning-targets.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { evidenceThreshold } from "./continual.js";
|
|
2
2
|
import { mineWorkflows } from "./skill-compiler.js";
|
|
3
|
+
import { WorldModel } from "./world-model.js";
|
|
4
|
+
import { replayIntoWorldModel } from "./analysis.js";
|
|
3
5
|
const REQUIRED_FIELDS = ['trainer', 'evaluator', 'holdout', 'promotionPolicy', 'rollback', 'lineage'];
|
|
4
6
|
/** Only vocabulary kinds are mirrored - see the module doc. */
|
|
5
7
|
const LEDGER_MAP = {
|
|
@@ -52,7 +54,7 @@ export class LearningTargetRegistry {
|
|
|
52
54
|
let evalResult;
|
|
53
55
|
if (reg.promotionPolicy.requireHoldout) {
|
|
54
56
|
const hold = await reg.holdout();
|
|
55
|
-
evalResult = await reg.evaluator(candidate, hold);
|
|
57
|
+
evalResult = await reg.evaluator(candidate, hold, train);
|
|
56
58
|
candidate = { ...candidate, status: 'evaluated', evalResult };
|
|
57
59
|
}
|
|
58
60
|
const evidence = evalResult?.metrics.evidence ?? 0;
|
|
@@ -122,3 +124,57 @@ export function registerSkillTarget(registry, opts) {
|
|
|
122
124
|
lineage: { registeredAt: new Date().toISOString(), version: 1, source: opts.lineageSource ?? 'skill-compiler.mineWorkflows' },
|
|
123
125
|
});
|
|
124
126
|
}
|
|
127
|
+
function brierScoreOnly(wm, holdout, environmentId) {
|
|
128
|
+
let checked = 0;
|
|
129
|
+
let sum = 0;
|
|
130
|
+
for (const traj of holdout) {
|
|
131
|
+
if (traj.environment.id !== environmentId)
|
|
132
|
+
continue;
|
|
133
|
+
for (const step of traj.steps) {
|
|
134
|
+
const p = wm.predict({ action: step.action });
|
|
135
|
+
const binary = step.outcome === 'success' ? 1 : 0;
|
|
136
|
+
sum += (p.confidence - binary) ** 2;
|
|
137
|
+
checked++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { checked, brier: checked > 0 ? Number((sum / checked).toFixed(4)) : 0 };
|
|
141
|
+
}
|
|
142
|
+
export function registerWorldModelTarget(registry, opts) {
|
|
143
|
+
registry.register({
|
|
144
|
+
target: 'world_model',
|
|
145
|
+
trainer: async (plan, dataset) => {
|
|
146
|
+
const wm = replayIntoWorldModel(dataset.trajectories, opts.environmentId);
|
|
147
|
+
const st = wm.worldState;
|
|
148
|
+
const corrections = st.beliefs.reduce((s, b) => s + (b.corrections?.length ?? 0), 0);
|
|
149
|
+
return {
|
|
150
|
+
id: `wm-${plan.opportunityId}-${Math.random().toString(36).slice(2, 8)}`,
|
|
151
|
+
plan,
|
|
152
|
+
createdAt: new Date().toISOString(),
|
|
153
|
+
status: 'draft',
|
|
154
|
+
environmentId: opts.environmentId,
|
|
155
|
+
beliefs: st.beliefs.filter((b) => b.id.startsWith('act:')).length,
|
|
156
|
+
corrections,
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
evaluator: async (candidate, holdout, train) => {
|
|
160
|
+
// deterministic rebuild from the SAME train set the trainer used - the
|
|
161
|
+
// evaluator receives the train dataset by contract, so no smuggling
|
|
162
|
+
const trained = replayIntoWorldModel(train.trajectories, opts.environmentId);
|
|
163
|
+
const fresh = new WorldModel(opts.environmentId);
|
|
164
|
+
const t = brierScoreOnly(trained, holdout.trajectories, opts.environmentId);
|
|
165
|
+
const f = brierScoreOnly(fresh, holdout.trajectories, opts.environmentId);
|
|
166
|
+
const evidence = f.brier > 0 ? Number(((f.brier - t.brier) / f.brier).toFixed(3)) : 0;
|
|
167
|
+
const pass = t.checked >= 10 && t.brier < f.brier && evidence >= 0.5;
|
|
168
|
+
return {
|
|
169
|
+
candidateId: candidate.id,
|
|
170
|
+
pass,
|
|
171
|
+
metrics: { evidence, brierTrained: t.brier, brierFresh: f.brier, checked: t.checked },
|
|
172
|
+
holdoutSize: holdout.trajectories.length,
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
holdout: opts.holdout,
|
|
176
|
+
promotionPolicy: { minEvidence: 0.5, requireHoldout: true, canaryShare: 0.2, ...opts.policy },
|
|
177
|
+
rollback: async () => undefined, // world-model rollback = dropping the candidate model; the base model is never mutated in-place
|
|
178
|
+
lineage: { registeredAt: new Date().toISOString(), version: 1, source: opts.lineageSource ?? 'analysis.replayIntoWorldModel' },
|
|
179
|
+
});
|
|
180
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cognitive",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.29",
|
|
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.
|
|
29
|
+
"@hmharness/kernel": "0.23.29"
|
|
30
30
|
}
|
|
31
31
|
}
|