@hmharness/cognitive 0.23.26 → 0.23.28
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/abstract-actions.d.ts +31 -1
- package/dist/abstract-actions.js +68 -0
- package/dist/credit-assignment.d.ts +51 -0
- package/dist/credit-assignment.js +78 -0
- package/dist/evidence-ledger.d.ts +41 -0
- package/dist/evidence-ledger.js +57 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/learning-targets.d.ts +92 -0
- package/dist/learning-targets.js +124 -0
- package/dist/ledger.d.ts +48 -0
- package/dist/ledger.js +111 -0
- package/dist/prediction-os.d.ts +115 -0
- package/dist/prediction-os.js +150 -0
- package/dist/rlm-sandbox.js +17 -17
- package/dist/world-model.d.ts +5 -0
- package/dist/world-model.js +9 -0
- package/package.json +31 -31
|
@@ -8,9 +8,39 @@
|
|
|
8
8
|
* environment can inform another — while the map itself stays explicit and
|
|
9
9
|
* auditable (no silent fuzzy matching).
|
|
10
10
|
*/
|
|
11
|
-
export type AbstractAction = 'observe' | 'read' | 'write' | 'edit' | 'run' | 'install' | 'launch' | 'remove' | 'query' | 'navigate' | 'interact';
|
|
11
|
+
export type AbstractAction = 'observe' | 'read' | 'write' | 'edit' | 'create' | 'run' | 'verify' | 'recover' | 'install' | 'launch' | 'remove' | 'query' | 'navigate' | 'interact';
|
|
12
12
|
/** explicit, auditable literal→abstract edges. Extend deliberately. */
|
|
13
13
|
export declare const ABSTRACT_ACTION_MAP: Record<string, AbstractAction>;
|
|
14
14
|
export declare function abstractOf(actionType: string): AbstractAction | undefined;
|
|
15
15
|
/** both sides map to the same abstract intent? */
|
|
16
16
|
export declare function abstractlyOverlaps(a: string, b: string): boolean;
|
|
17
|
+
export declare const TRANSFER_ENVIRONMENTS: readonly ["terminal", "harmonyos", "browser", "desktop", "arc3"];
|
|
18
|
+
export type TransferEnvironmentId = (typeof TRANSFER_ENVIRONMENTS)[number];
|
|
19
|
+
/** explicit, auditable literal→environment attribution - the matrix is
|
|
20
|
+
* only as honest as this table; nothing is inferred heuristically. */
|
|
21
|
+
export declare const LITERAL_ENVIRONMENT: Record<string, TransferEnvironmentId>;
|
|
22
|
+
/** Derived, never invented: an environment's abstract verbs are the union
|
|
23
|
+
* of its attributed literals' intents. */
|
|
24
|
+
export declare function environmentAbstractActions(env: TransferEnvironmentId): AbstractAction[];
|
|
25
|
+
export interface TransferMatrixCellEvidence {
|
|
26
|
+
score: number;
|
|
27
|
+
verdict: 'positive' | 'neutral' | 'negative';
|
|
28
|
+
runsPerArm: number;
|
|
29
|
+
calibrationDelta?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface TransferMatrixCell {
|
|
32
|
+
source: TransferEnvironmentId;
|
|
33
|
+
target: TransferEnvironmentId;
|
|
34
|
+
overlap: AbstractAction[];
|
|
35
|
+
/** |A∩B| / |A∪B| over the two environments' abstract verb sets */
|
|
36
|
+
jaccard: number;
|
|
37
|
+
status: 'same-env' | 'no-overlap' | 'overlap-no-evidence' | 'evidence';
|
|
38
|
+
evidence?: TransferMatrixCellEvidence;
|
|
39
|
+
}
|
|
40
|
+
/** The 5x5 the pack demands. Honesty rules, machine-encoded:
|
|
41
|
+
* - overlap is NECESSARY, not sufficient - a pair with verbs in common and
|
|
42
|
+
* no controlled two-arm experiment reports 'overlap-no-evidence', never
|
|
43
|
+
* a transfer claim (terminal->browser's honest lesson)
|
|
44
|
+
* - 'evidence' requires a supplied TransferExperimentReport-shaped record
|
|
45
|
+
* - the diagonal is 'same-env', not transfer */
|
|
46
|
+
export declare function transferMatrix(experiments: Array<Pick<import('./transfer-lab.ts').TransferExperimentReport, 'sourceEnv' | 'targetEnv' | 'score' | 'verdict' | 'runsPerArm' | 'calibrationDelta'>>): TransferMatrixCell[][];
|
package/dist/abstract-actions.js
CHANGED
|
@@ -20,11 +20,22 @@ export const ABSTRACT_ACTION_MAP = {
|
|
|
20
20
|
'hdc-shell': 'run',
|
|
21
21
|
'hdc-install': 'install',
|
|
22
22
|
'hdc-aa-start': 'launch',
|
|
23
|
+
'harmony_project_create': 'create',
|
|
24
|
+
'harmony_build': 'verify',
|
|
25
|
+
'harmony_device_test': 'verify',
|
|
26
|
+
// browser-extension bridge tools (round 43+: the real-browser surface)
|
|
27
|
+
'extension_page_read': 'read',
|
|
28
|
+
'extension_page_act': 'interact',
|
|
29
|
+
'extension_tabs': 'observe',
|
|
23
30
|
// arc-agi-3 environment (all seven actions are game interactions;
|
|
24
31
|
// ACTION6 is the coordinate variant of the same intent)
|
|
25
32
|
'ACTION1': 'interact', 'ACTION2': 'interact', 'ACTION3': 'interact',
|
|
26
33
|
'ACTION4': 'interact', 'ACTION5': 'interact', 'ACTION6': 'interact',
|
|
27
34
|
'ACTION7': 'interact',
|
|
35
|
+
// 'recover' currently maps NOTHING: recovery today is harness-internal
|
|
36
|
+
// (MEA bounded replan/retry), not a tool literal. The verb exists so a
|
|
37
|
+
// trajectory can express it the day a tool does - absent edges are not
|
|
38
|
+
// fabricated edges.
|
|
28
39
|
};
|
|
29
40
|
export function abstractOf(actionType) {
|
|
30
41
|
return ABSTRACT_ACTION_MAP[actionType];
|
|
@@ -35,3 +46,60 @@ export function abstractlyOverlaps(a, b) {
|
|
|
35
46
|
const ab = abstractOf(b);
|
|
36
47
|
return aa !== undefined && aa === ab;
|
|
37
48
|
}
|
|
49
|
+
/* ---------------- Transfer OS (upgrade pack section 12, P1) ---------------- */
|
|
50
|
+
export const TRANSFER_ENVIRONMENTS = ['terminal', 'harmonyos', 'browser', 'desktop', 'arc3'];
|
|
51
|
+
/** explicit, auditable literal→environment attribution - the matrix is
|
|
52
|
+
* only as honest as this table; nothing is inferred heuristically. */
|
|
53
|
+
export const LITERAL_ENVIRONMENT = {
|
|
54
|
+
'command': 'terminal', 'writeFile': 'terminal', 'deleteFile': 'terminal',
|
|
55
|
+
'read_file': 'terminal', 'write_file': 'terminal', 'edit_file': 'terminal',
|
|
56
|
+
'run_command': 'terminal', 'list_dir': 'terminal', 'web_fetch': 'terminal', 'web_search': 'terminal',
|
|
57
|
+
'browser_open': 'browser',
|
|
58
|
+
'extension_page_read': 'browser', 'extension_page_act': 'browser', 'extension_tabs': 'browser',
|
|
59
|
+
'desktop_click': 'desktop', 'desktop_type': 'desktop', 'desktop_screenshot': 'desktop',
|
|
60
|
+
'hdc-shell': 'harmonyos', 'hdc-install': 'harmonyos', 'hdc-aa-start': 'harmonyos',
|
|
61
|
+
'harmony_project_create': 'harmonyos', 'harmony_build': 'harmonyos', 'harmony_device_test': 'harmonyos',
|
|
62
|
+
'ACTION1': 'arc3', 'ACTION2': 'arc3', 'ACTION3': 'arc3', 'ACTION4': 'arc3',
|
|
63
|
+
'ACTION5': 'arc3', 'ACTION6': 'arc3', 'ACTION7': 'arc3',
|
|
64
|
+
};
|
|
65
|
+
/** Derived, never invented: an environment's abstract verbs are the union
|
|
66
|
+
* of its attributed literals' intents. */
|
|
67
|
+
export function environmentAbstractActions(env) {
|
|
68
|
+
const out = new Set();
|
|
69
|
+
for (const [literal, e] of Object.entries(LITERAL_ENVIRONMENT)) {
|
|
70
|
+
if (e !== env)
|
|
71
|
+
continue;
|
|
72
|
+
const a = ABSTRACT_ACTION_MAP[literal];
|
|
73
|
+
if (a)
|
|
74
|
+
out.add(a);
|
|
75
|
+
}
|
|
76
|
+
return [...out].sort();
|
|
77
|
+
}
|
|
78
|
+
/** The 5x5 the pack demands. Honesty rules, machine-encoded:
|
|
79
|
+
* - overlap is NECESSARY, not sufficient - a pair with verbs in common and
|
|
80
|
+
* no controlled two-arm experiment reports 'overlap-no-evidence', never
|
|
81
|
+
* a transfer claim (terminal->browser's honest lesson)
|
|
82
|
+
* - 'evidence' requires a supplied TransferExperimentReport-shaped record
|
|
83
|
+
* - the diagonal is 'same-env', not transfer */
|
|
84
|
+
export function transferMatrix(experiments) {
|
|
85
|
+
const envVerbs = new Map(TRANSFER_ENVIRONMENTS.map((e) => [e, new Set(environmentAbstractActions(e))]));
|
|
86
|
+
const expBy = new Map(experiments.map((e) => [`${e.sourceEnv}->${e.targetEnv}`, e]));
|
|
87
|
+
return TRANSFER_ENVIRONMENTS.map((source) => TRANSFER_ENVIRONMENTS.map((target) => {
|
|
88
|
+
if (source === target)
|
|
89
|
+
return { source, target, overlap: [], jaccard: 1, status: 'same-env' };
|
|
90
|
+
const a = envVerbs.get(source);
|
|
91
|
+
const b = envVerbs.get(target);
|
|
92
|
+
const overlap = [...a].filter((v) => b.has(v)).sort();
|
|
93
|
+
const union = new Set([...a, ...b]);
|
|
94
|
+
const jaccard = union.size ? Number((overlap.length / union.size).toFixed(3)) : 0;
|
|
95
|
+
const exp = expBy.get(`${source}->${target}`);
|
|
96
|
+
if (overlap.length === 0)
|
|
97
|
+
return { source, target, overlap, jaccard, status: 'no-overlap' };
|
|
98
|
+
if (!exp)
|
|
99
|
+
return { source, target, overlap, jaccard, status: 'overlap-no-evidence' };
|
|
100
|
+
return {
|
|
101
|
+
source, target, overlap, jaccard, status: 'evidence',
|
|
102
|
+
evidence: { score: exp.score, verdict: exp.verdict, runsPerArm: exp.runsPerArm, ...(exp.calibrationDelta !== undefined ? { calibrationDelta: exp.calibrationDelta } : {}) },
|
|
103
|
+
};
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - Cognitive Credit Assignment v0 (upgrade pack §15)
|
|
3
|
+
*
|
|
4
|
+
* The question the pack poses: when performance changes, WHICH cognitive
|
|
5
|
+
* change contributed? v0 answers with the same discipline WM-2 established
|
|
6
|
+
* for observational causal mining - it RANKS co-occurrence, it does not
|
|
7
|
+
* claim causation:
|
|
8
|
+
*
|
|
9
|
+
* For each prediction.confirmed / prediction.failed event in the ledger,
|
|
10
|
+
* look back a window of W events; for every contributor kind (belief
|
|
11
|
+
* revision, skill promotion, memory promotion, exploration, model
|
|
12
|
+
* routing...) count its presence. The kind's association is
|
|
13
|
+
*
|
|
14
|
+
* P(confirmed | kind present in window) - P(confirmed | absent)
|
|
15
|
+
*
|
|
16
|
+
* - an observational lift, exactly the wm-causal semantics, carried over
|
|
17
|
+
* - kinds with support below minSupport report insufficient-evidence
|
|
18
|
+
* instead of a number (small-sample honesty)
|
|
19
|
+
* - the report is labeled nature:'observational' BY CONSTRUCTION; a
|
|
20
|
+
* causal claim would require interventional replay (later work)
|
|
21
|
+
*/
|
|
22
|
+
import type { CognitiveLedger, LedgerEventKind } from './ledger.js';
|
|
23
|
+
export declare const CONTRIBUTOR_KINDS: readonly LedgerEventKind[];
|
|
24
|
+
export interface ContributorAttribution {
|
|
25
|
+
kind: LedgerEventKind;
|
|
26
|
+
/** windows in which the kind appeared */
|
|
27
|
+
presentWindows: number;
|
|
28
|
+
/** prediction.confirmed share when present vs absent - observational lift */
|
|
29
|
+
association: number;
|
|
30
|
+
confirmedWhenPresent: number;
|
|
31
|
+
confirmedWhenAbsent: number;
|
|
32
|
+
absentWindows: number;
|
|
33
|
+
support: number;
|
|
34
|
+
/** true when support < minSupport - no number is trusted */
|
|
35
|
+
insufficientEvidence: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface CreditReport {
|
|
38
|
+
/** by construction - this v0 ranks co-occurrence, it does not claim causation */
|
|
39
|
+
nature: 'observational';
|
|
40
|
+
windowSize: number;
|
|
41
|
+
outcomeEvents: number;
|
|
42
|
+
baselineConfirmedRate: number;
|
|
43
|
+
ranked: ContributorAttribution[];
|
|
44
|
+
}
|
|
45
|
+
export interface CreditOptions {
|
|
46
|
+
/** how many preceding events count as the attribution window */
|
|
47
|
+
windowSize?: number;
|
|
48
|
+
/** minimum present-windows before an association is reported */
|
|
49
|
+
minSupport?: number;
|
|
50
|
+
}
|
|
51
|
+
export declare function assignCredit(ledger: CognitiveLedger, opts?: CreditOptions): CreditReport;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const CONTRIBUTOR_KINDS = [
|
|
2
|
+
'belief.created',
|
|
3
|
+
'belief.revised',
|
|
4
|
+
'exploration.chosen',
|
|
5
|
+
'skill.candidate',
|
|
6
|
+
'skill.promoted',
|
|
7
|
+
'skill.rejected',
|
|
8
|
+
'memory.promoted',
|
|
9
|
+
'memory.contradicted',
|
|
10
|
+
'goal.revised',
|
|
11
|
+
'model.routed',
|
|
12
|
+
'capability.denied',
|
|
13
|
+
'observation.recorded',
|
|
14
|
+
];
|
|
15
|
+
export function assignCredit(ledger, opts = {}) {
|
|
16
|
+
const W = opts.windowSize ?? 5;
|
|
17
|
+
const minSupport = opts.minSupport ?? 3;
|
|
18
|
+
const events = ledger.events();
|
|
19
|
+
const tallies = new Map();
|
|
20
|
+
let outcomeEvents = 0;
|
|
21
|
+
let confirmedTotal = 0;
|
|
22
|
+
for (let i = 0; i < events.length; i++) {
|
|
23
|
+
const e = events[i];
|
|
24
|
+
if (e.kind !== 'prediction.confirmed' && e.kind !== 'prediction.failed')
|
|
25
|
+
continue;
|
|
26
|
+
outcomeEvents++;
|
|
27
|
+
const confirmed = e.kind === 'prediction.confirmed';
|
|
28
|
+
if (confirmed)
|
|
29
|
+
confirmedTotal++;
|
|
30
|
+
const window = events.slice(Math.max(0, i - W), i);
|
|
31
|
+
const kindsPresent = new Set(window.map((w) => w.kind));
|
|
32
|
+
for (const kind of CONTRIBUTOR_KINDS) {
|
|
33
|
+
let t = tallies.get(kind);
|
|
34
|
+
if (!t) {
|
|
35
|
+
t = { presentConfirmed: 0, presentTotal: 0, absentConfirmed: 0, absentTotal: 0 };
|
|
36
|
+
tallies.set(kind, t);
|
|
37
|
+
}
|
|
38
|
+
if (kindsPresent.has(kind)) {
|
|
39
|
+
t.presentTotal++;
|
|
40
|
+
if (confirmed)
|
|
41
|
+
t.presentConfirmed++;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
t.absentTotal++;
|
|
45
|
+
if (confirmed)
|
|
46
|
+
t.absentConfirmed++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const baseline = outcomeEvents > 0 ? confirmedTotal / outcomeEvents : 0;
|
|
51
|
+
const ranked = [];
|
|
52
|
+
for (const [kind, t] of tallies) {
|
|
53
|
+
const support = t.presentTotal;
|
|
54
|
+
if (support === 0)
|
|
55
|
+
continue; // never co-occurred - nothing to say
|
|
56
|
+
const pPresent = t.presentTotal > 0 ? t.presentConfirmed / t.presentTotal : 0;
|
|
57
|
+
const pAbsent = t.absentTotal > 0 ? t.absentConfirmed / t.absentTotal : 0;
|
|
58
|
+
const insufficient = support < minSupport;
|
|
59
|
+
ranked.push({
|
|
60
|
+
kind,
|
|
61
|
+
presentWindows: support,
|
|
62
|
+
absentWindows: t.absentTotal,
|
|
63
|
+
confirmedWhenPresent: t.presentConfirmed,
|
|
64
|
+
confirmedWhenAbsent: t.absentConfirmed,
|
|
65
|
+
association: insufficient ? 0 : Number((pPresent - pAbsent).toFixed(3)),
|
|
66
|
+
support,
|
|
67
|
+
insufficientEvidence: insufficient,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
ranked.sort((a, b) => Math.abs(b.association) - Math.abs(a.association) || b.support - a.support);
|
|
71
|
+
return {
|
|
72
|
+
nature: 'observational',
|
|
73
|
+
windowSize: W,
|
|
74
|
+
outcomeEvents,
|
|
75
|
+
baselineConfirmedRate: Number(baseline.toFixed(3)),
|
|
76
|
+
ranked,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface EvidenceLineage {
|
|
2
|
+
runId: string;
|
|
3
|
+
taskId?: string;
|
|
4
|
+
modelId: string;
|
|
5
|
+
promptVersion: string;
|
|
6
|
+
toolVersions: Record<string, string>;
|
|
7
|
+
skillVersions?: Record<string, string>;
|
|
8
|
+
/** WorldModel.state.version at run start */
|
|
9
|
+
worldModelVersion?: number;
|
|
10
|
+
/** code-world-store's content-sensitive stateHash at run start */
|
|
11
|
+
codeWorldStateHash?: string;
|
|
12
|
+
/** EVAL-IND tie-in: the task set fingerprint + seed (+ split label) */
|
|
13
|
+
datasetHash?: string;
|
|
14
|
+
seed?: string;
|
|
15
|
+
split?: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
}
|
|
18
|
+
/** sha256 over the canonical lineage form (createdAt excluded - the same
|
|
19
|
+
* context re-stamped must keep its identity). */
|
|
20
|
+
export declare function lineageId(lineage: Omit<EvidenceLineage, 'createdAt'> & {
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
}): string;
|
|
23
|
+
export declare const COMPARABLE_AXES: readonly ["modelId", "promptVersion", "toolVersions", "skillVersions", "datasetHash", "seed", "split"];
|
|
24
|
+
export type ComparableAxis = (typeof COMPARABLE_AXES)[number];
|
|
25
|
+
/** Axis-explicit comparability: both lineages must MATCH on every named
|
|
26
|
+
* axis. An axis absent on one side and present on the other does NOT
|
|
27
|
+
* compare (unknown is not equal). Empty axis list compares nothing. */
|
|
28
|
+
export declare function comparableLineage(a: EvidenceLineage, b: EvidenceLineage, axes: readonly ComparableAxis[]): {
|
|
29
|
+
comparable: boolean;
|
|
30
|
+
mismatches: ComparableAxis[];
|
|
31
|
+
};
|
|
32
|
+
/** The run envelope: lineage + one evidence payload (a metric report, an
|
|
33
|
+
* audit verdict, a prediction summary). Replay = lineage + payload. */
|
|
34
|
+
export interface EvidenceEnvelope<T> {
|
|
35
|
+
lineageId: string;
|
|
36
|
+
lineage: EvidenceLineage;
|
|
37
|
+
kind: string;
|
|
38
|
+
payload: T;
|
|
39
|
+
at: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function evidenceEnvelope<T>(lineage: EvidenceLineage, kind: string, payload: T): EvidenceEnvelope<T>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - Evidence Ledger v2 (upgrade pack stage A item 3)
|
|
3
|
+
*
|
|
4
|
+
* One lineage ID to answer the pack's acceptance question - "任何指标都能
|
|
5
|
+
* 回答:谁产生、在哪验证、由谁独立验证、是否可回放" - by binding a run
|
|
6
|
+
* to the FULL cognitive context that produced it:
|
|
7
|
+
*
|
|
8
|
+
* run/task/model/prompt/tool versions/skill versions/world-model
|
|
9
|
+
* revision/code-world stateHash/datasetHash+seed (the EVAL-IND tie-in)
|
|
10
|
+
*
|
|
11
|
+
* Discipline carried over from the pieces it unifies:
|
|
12
|
+
* - lineageId = sha256 over a CANONICAL form (sorted keys, order-
|
|
13
|
+
* independent, content-sensitive - datasetHash's arithmetic)
|
|
14
|
+
* - comparability is AXIS-EXPLICIT, the reportsComparable lesson: two
|
|
15
|
+
* lineages are comparable only on the axes you name, and naming no
|
|
16
|
+
* axes means nothing is comparable
|
|
17
|
+
* - absent context fields are OMITTED from the canonical form (an
|
|
18
|
+
* unversioned prompt hashes differently than a versioned one - the
|
|
19
|
+
* difference is visible, not averaged away)
|
|
20
|
+
*/
|
|
21
|
+
import { createHash } from 'node:crypto';
|
|
22
|
+
/** order-independent canonical JSON: object keys sorted at every depth */
|
|
23
|
+
function canonical(value) {
|
|
24
|
+
if (Array.isArray(value))
|
|
25
|
+
return '[' + value.map(canonical).join(',') + ']';
|
|
26
|
+
if (value && typeof value === 'object') {
|
|
27
|
+
const entries = Object.entries(value)
|
|
28
|
+
.filter(([, v]) => v !== undefined)
|
|
29
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
30
|
+
return '{' + entries.map(([k, v]) => JSON.stringify(k) + ':' + canonical(v)).join(',') + '}';
|
|
31
|
+
}
|
|
32
|
+
return JSON.stringify(value ?? null);
|
|
33
|
+
}
|
|
34
|
+
/** sha256 over the canonical lineage form (createdAt excluded - the same
|
|
35
|
+
* context re-stamped must keep its identity). */
|
|
36
|
+
export function lineageId(lineage) {
|
|
37
|
+
const { createdAt: _drop, ...rest } = lineage;
|
|
38
|
+
void _drop;
|
|
39
|
+
return 'lin-' + createHash('sha256').update(canonical(rest)).digest('hex').slice(0, 16);
|
|
40
|
+
}
|
|
41
|
+
export const COMPARABLE_AXES = ['modelId', 'promptVersion', 'toolVersions', 'skillVersions', 'datasetHash', 'seed', 'split'];
|
|
42
|
+
/** Axis-explicit comparability: both lineages must MATCH on every named
|
|
43
|
+
* axis. An axis absent on one side and present on the other does NOT
|
|
44
|
+
* compare (unknown is not equal). Empty axis list compares nothing. */
|
|
45
|
+
export function comparableLineage(a, b, axes) {
|
|
46
|
+
const mismatches = [];
|
|
47
|
+
for (const axis of axes) {
|
|
48
|
+
const av = a[axis];
|
|
49
|
+
const bv = b[axis];
|
|
50
|
+
if (av === undefined || bv === undefined || canonical(av) !== canonical(bv))
|
|
51
|
+
mismatches.push(axis);
|
|
52
|
+
}
|
|
53
|
+
return { comparable: mismatches.length === 0, mismatches };
|
|
54
|
+
}
|
|
55
|
+
export function evidenceEnvelope(lineage, kind, payload) {
|
|
56
|
+
return { lineageId: lineageId(lineage), lineage, kind, payload, at: new Date().toISOString() };
|
|
57
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -35,4 +35,9 @@ export * from './slice.js';
|
|
|
35
35
|
export * from './mea.js';
|
|
36
36
|
export * from './evalset.js';
|
|
37
37
|
export * from './code-world-model.js';
|
|
38
|
+
export * from './ledger.js';
|
|
39
|
+
export * from './prediction-os.js';
|
|
40
|
+
export * from './credit-assignment.js';
|
|
41
|
+
export * from './learning-targets.js';
|
|
42
|
+
export * from './evidence-ledger.js';
|
|
38
43
|
export * from './code-world-store.js';
|
package/dist/index.js
CHANGED
|
@@ -34,4 +34,9 @@ export * from "./slice.js";
|
|
|
34
34
|
export * from "./mea.js";
|
|
35
35
|
export * from "./evalset.js";
|
|
36
36
|
export * from "./code-world-model.js";
|
|
37
|
+
export * from "./ledger.js";
|
|
38
|
+
export * from "./prediction-os.js";
|
|
39
|
+
export * from "./credit-assignment.js";
|
|
40
|
+
export * from "./learning-targets.js";
|
|
41
|
+
export * from "./evidence-ledger.js";
|
|
37
42
|
export * from "./code-world-store.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - Learning Target Registry (upgrade pack stage C / §11)
|
|
3
|
+
*
|
|
4
|
+
* The pack's Learning OS ask: every learning target (memory / skill /
|
|
5
|
+
* workflow / tool / router / world_model / prompt / adapter / model) must
|
|
6
|
+
* carry a SIX-PART contract - trainer, evaluator, holdout, promotionPolicy,
|
|
7
|
+
* rollback, lineage. This registry makes the contract machine-checked: a
|
|
8
|
+
* registration missing any part is refused WITH THE FIELD NAME (the
|
|
9
|
+
* checklist-that-cannot-rot pattern; the ORDER trap guard is precedent).
|
|
10
|
+
*
|
|
11
|
+
* runCycle() orchestrates the doc's pipeline:
|
|
12
|
+
* trainer -> (policy.requireHoldout ? holdout evaluation : -)
|
|
13
|
+
* -> evidence bar = max(policy.minEvidence, evidenceThreshold(target))
|
|
14
|
+
* -> promote | reject
|
|
15
|
+
* -> Cognitive Ledger mirroring for the kinds the vocabulary has
|
|
16
|
+
*
|
|
17
|
+
* Ledger mapping honesty: only kinds that exist in the vocabulary are
|
|
18
|
+
* emitted (skill.candidate/promoted/rejected, memory.promoted); targets
|
|
19
|
+
* without a vocabulary kind (workflow/router/...) run the same pipeline
|
|
20
|
+
* but mirror nothing - stated, not silently faked.
|
|
21
|
+
*
|
|
22
|
+
* The evidence bar composes with continual.ts's evidenceThreshold: the
|
|
23
|
+
* model target's 0.95 bar is STRICTLY higher than memory's 0.6 - weight
|
|
24
|
+
* changes stay last, not first (the control plane's founding rule).
|
|
25
|
+
*/
|
|
26
|
+
import type { Candidate, EvalResult, LearningDataset, LearningPlan, LearningTarget } from './continual.js';
|
|
27
|
+
import type { CognitiveLedger } from './ledger.js';
|
|
28
|
+
import { type WorkflowCandidate } from './skill-compiler.js';
|
|
29
|
+
export type TargetTrainer = (plan: LearningPlan, dataset: LearningDataset) => Promise<Candidate>;
|
|
30
|
+
export type TargetEvaluator = (candidate: Candidate, holdout: LearningDataset) => Promise<EvalResult>;
|
|
31
|
+
export type TargetRollback = (candidate: Candidate) => Promise<void>;
|
|
32
|
+
export interface PromotionPolicy {
|
|
33
|
+
/** minimum evidence metric before promotion is even considered */
|
|
34
|
+
minEvidence: number;
|
|
35
|
+
/** when true, the holdout set is drawn and the evaluator must pass */
|
|
36
|
+
requireHoldout: boolean;
|
|
37
|
+
/** share of sessions the candidate serves during canary, in (0, 1] */
|
|
38
|
+
canaryShare: number;
|
|
39
|
+
}
|
|
40
|
+
export interface TargetLineage {
|
|
41
|
+
registeredAt: string;
|
|
42
|
+
version: number;
|
|
43
|
+
source: string;
|
|
44
|
+
}
|
|
45
|
+
export interface TargetRegistration {
|
|
46
|
+
target: LearningTarget;
|
|
47
|
+
trainer: TargetTrainer;
|
|
48
|
+
evaluator: TargetEvaluator;
|
|
49
|
+
holdout: () => Promise<LearningDataset>;
|
|
50
|
+
promotionPolicy: PromotionPolicy;
|
|
51
|
+
rollback: TargetRollback;
|
|
52
|
+
lineage: TargetLineage;
|
|
53
|
+
}
|
|
54
|
+
export interface CycleOutcome {
|
|
55
|
+
candidate: Candidate;
|
|
56
|
+
evalResult?: EvalResult;
|
|
57
|
+
decision: 'promote' | 'reject';
|
|
58
|
+
bar: number;
|
|
59
|
+
reason: string;
|
|
60
|
+
}
|
|
61
|
+
export declare const KNOWN_TARGETS: readonly LearningTarget[];
|
|
62
|
+
export declare class LearningTargetRegistry {
|
|
63
|
+
private readonly byTarget;
|
|
64
|
+
/** when set, cycle outcomes mirror into the Cognitive Ledger */
|
|
65
|
+
ledger?: CognitiveLedger;
|
|
66
|
+
register(reg: TargetRegistration): void;
|
|
67
|
+
get(target: LearningTarget): TargetRegistration | undefined;
|
|
68
|
+
list(): LearningTarget[];
|
|
69
|
+
/** The honest gap report: what the pack demands vs what is wired. */
|
|
70
|
+
coverage(): {
|
|
71
|
+
known: number;
|
|
72
|
+
registered: number;
|
|
73
|
+
missing: LearningTarget[];
|
|
74
|
+
};
|
|
75
|
+
/** The full pipeline for one learning plan against one registered target. */
|
|
76
|
+
runCycle(plan: LearningPlan, train: LearningDataset): Promise<CycleOutcome>;
|
|
77
|
+
private emit;
|
|
78
|
+
}
|
|
79
|
+
export interface SkillCandidate extends Candidate {
|
|
80
|
+
workflows: WorkflowCandidate[];
|
|
81
|
+
}
|
|
82
|
+
export declare function registerSkillTarget(registry: LearningTargetRegistry, opts: {
|
|
83
|
+
/** disjoint-from-train holdout source - the caller owns the split */
|
|
84
|
+
holdout: () => Promise<LearningDataset>;
|
|
85
|
+
mining?: {
|
|
86
|
+
minSupport?: number;
|
|
87
|
+
nMin?: number;
|
|
88
|
+
nMax?: number;
|
|
89
|
+
};
|
|
90
|
+
policy?: Partial<PromotionPolicy>;
|
|
91
|
+
lineageSource?: string;
|
|
92
|
+
}): void;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { evidenceThreshold } from "./continual.js";
|
|
2
|
+
import { mineWorkflows } from "./skill-compiler.js";
|
|
3
|
+
const REQUIRED_FIELDS = ['trainer', 'evaluator', 'holdout', 'promotionPolicy', 'rollback', 'lineage'];
|
|
4
|
+
/** Only vocabulary kinds are mirrored - see the module doc. */
|
|
5
|
+
const LEDGER_MAP = {
|
|
6
|
+
skill: { candidate: 'skill.candidate', promoted: 'skill.promoted', rejected: 'skill.rejected' },
|
|
7
|
+
memory: { promoted: 'memory.promoted' },
|
|
8
|
+
};
|
|
9
|
+
export const KNOWN_TARGETS = ['memory', 'skill', 'workflow', 'tool', 'router', 'world_model', 'prompt', 'adapter', 'model'];
|
|
10
|
+
export class LearningTargetRegistry {
|
|
11
|
+
byTarget = new Map();
|
|
12
|
+
/** when set, cycle outcomes mirror into the Cognitive Ledger */
|
|
13
|
+
ledger;
|
|
14
|
+
register(reg) {
|
|
15
|
+
for (const f of REQUIRED_FIELDS) {
|
|
16
|
+
if (reg[f] === undefined) {
|
|
17
|
+
throw new Error(`learning target ${reg.target}: registration missing '${f}' - the six-part contract (trainer/evaluator/holdout/promotionPolicy/rollback/lineage) is non-negotiable`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const { canaryShare } = reg.promotionPolicy;
|
|
21
|
+
if (!(canaryShare > 0 && canaryShare <= 1)) {
|
|
22
|
+
throw new Error(`learning target ${reg.target}: canaryShare must be in (0, 1], got ${canaryShare}`);
|
|
23
|
+
}
|
|
24
|
+
if (this.byTarget.has(reg.target)) {
|
|
25
|
+
throw new Error(`learning target ${reg.target}: already registered - replace deliberately, never shadow`);
|
|
26
|
+
}
|
|
27
|
+
this.byTarget.set(reg.target, reg);
|
|
28
|
+
}
|
|
29
|
+
get(target) {
|
|
30
|
+
return this.byTarget.get(target);
|
|
31
|
+
}
|
|
32
|
+
list() {
|
|
33
|
+
return [...this.byTarget.keys()];
|
|
34
|
+
}
|
|
35
|
+
/** The honest gap report: what the pack demands vs what is wired. */
|
|
36
|
+
coverage() {
|
|
37
|
+
return {
|
|
38
|
+
known: KNOWN_TARGETS.length,
|
|
39
|
+
registered: this.byTarget.size,
|
|
40
|
+
missing: KNOWN_TARGETS.filter((t) => !this.byTarget.has(t)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The full pipeline for one learning plan against one registered target. */
|
|
44
|
+
async runCycle(plan, train) {
|
|
45
|
+
const reg = this.byTarget.get(plan.target);
|
|
46
|
+
if (!reg)
|
|
47
|
+
throw new Error(`learning target ${plan.target} is not registered - register the six-part contract first`);
|
|
48
|
+
const bar = Math.max(reg.promotionPolicy.minEvidence, evidenceThreshold(reg.target));
|
|
49
|
+
let candidate = await reg.trainer(plan, train);
|
|
50
|
+
candidate = { ...candidate, status: 'trained' };
|
|
51
|
+
this.emit(reg.target, 'candidate', candidate.id, `${plan.target} candidate from opportunity ${plan.opportunityId}`);
|
|
52
|
+
let evalResult;
|
|
53
|
+
if (reg.promotionPolicy.requireHoldout) {
|
|
54
|
+
const hold = await reg.holdout();
|
|
55
|
+
evalResult = await reg.evaluator(candidate, hold);
|
|
56
|
+
candidate = { ...candidate, status: 'evaluated', evalResult };
|
|
57
|
+
}
|
|
58
|
+
const evidence = evalResult?.metrics.evidence ?? 0;
|
|
59
|
+
const holdoutPassed = !reg.promotionPolicy.requireHoldout || (evalResult?.pass ?? false);
|
|
60
|
+
const decision = holdoutPassed && evidence >= bar ? 'promote' : 'reject';
|
|
61
|
+
const reason = !holdoutPassed
|
|
62
|
+
? `holdout evaluation failed (pass=${evalResult?.pass})`
|
|
63
|
+
: decision === 'promote'
|
|
64
|
+
? `evidence ${evidence} >= bar ${bar}`
|
|
65
|
+
: `evidence ${evidence} below bar ${bar}`;
|
|
66
|
+
candidate = { ...candidate, status: decision === 'promote' ? 'promoted' : 'rejected' };
|
|
67
|
+
this.emit(reg.target, decision, candidate.id, reason);
|
|
68
|
+
return { candidate, evalResult, decision, bar, reason };
|
|
69
|
+
}
|
|
70
|
+
emit(target, stage, subject, detail) {
|
|
71
|
+
const map = LEDGER_MAP[target];
|
|
72
|
+
const kind = map ? (stage === 'candidate' ? map.candidate : stage === 'promote' ? map.promoted : map.rejected) : undefined;
|
|
73
|
+
if (!kind || !this.ledger)
|
|
74
|
+
return; // no vocabulary kind for this target - mirror nothing, honestly
|
|
75
|
+
try {
|
|
76
|
+
this.ledger.append(kind, subject, { detail });
|
|
77
|
+
}
|
|
78
|
+
catch { /* the ledger must never break the cycle it observes */ }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function containsGram(seq, gram) {
|
|
82
|
+
outer: for (let i = 0; i + gram.length <= seq.length; i++) {
|
|
83
|
+
for (let j = 0; j < gram.length; j++)
|
|
84
|
+
if (seq[i + j] !== gram[j])
|
|
85
|
+
continue outer;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
function successSequence(t) {
|
|
91
|
+
return t.steps.filter((s) => s.outcome === 'success').map((s) => s.action.type);
|
|
92
|
+
}
|
|
93
|
+
export function registerSkillTarget(registry, opts) {
|
|
94
|
+
registry.register({
|
|
95
|
+
target: 'skill',
|
|
96
|
+
trainer: async (plan, dataset) => ({
|
|
97
|
+
id: `skill-${plan.opportunityId}-${Math.random().toString(36).slice(2, 8)}`,
|
|
98
|
+
plan,
|
|
99
|
+
createdAt: new Date().toISOString(),
|
|
100
|
+
status: 'draft',
|
|
101
|
+
workflows: mineWorkflows(dataset.trajectories, opts.mining ?? {}),
|
|
102
|
+
}),
|
|
103
|
+
evaluator: async (candidate, holdout) => {
|
|
104
|
+
const top = candidate.workflows[0];
|
|
105
|
+
const holdoutSuccesses = holdout.trajectories.filter((t) => t.metrics.success);
|
|
106
|
+
if (!top) {
|
|
107
|
+
return { candidateId: candidate.id, pass: false, metrics: { evidence: 0, holdoutSuccesses: holdoutSuccesses.length }, holdoutSize: holdout.trajectories.length };
|
|
108
|
+
}
|
|
109
|
+
const containing = holdoutSuccesses.filter((t) => containsGram(successSequence(t), top.steps)).length;
|
|
110
|
+
const evidence = holdoutSuccesses.length > 0 ? Number((containing / holdoutSuccesses.length).toFixed(3)) : 0;
|
|
111
|
+
const pass = holdoutSuccesses.length >= 2 && evidence >= 0.5;
|
|
112
|
+
return {
|
|
113
|
+
candidateId: candidate.id,
|
|
114
|
+
pass,
|
|
115
|
+
metrics: { evidence, holdoutSuccesses: holdoutSuccesses.length, workflowSupport: top.support },
|
|
116
|
+
holdoutSize: holdout.trajectories.length,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
holdout: opts.holdout,
|
|
120
|
+
promotionPolicy: { minEvidence: 0.5, requireHoldout: true, canaryShare: 0.2, ...opts.policy },
|
|
121
|
+
rollback: async () => undefined, // skill rollback is host-side promotion bookkeeping; v0 records intent via the ledger chain
|
|
122
|
+
lineage: { registeredAt: new Date().toISOString(), version: 1, source: opts.lineageSource ?? 'skill-compiler.mineWorkflows' },
|
|
123
|
+
});
|
|
124
|
+
}
|
package/dist/ledger.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type LedgerEventKind = 'belief.created' | 'belief.revised' | 'prediction.made' | 'prediction.confirmed' | 'prediction.failed' | 'exploration.chosen' | 'observation.recorded' | 'skill.candidate' | 'skill.promoted' | 'skill.rejected' | 'memory.promoted' | 'memory.contradicted' | 'goal.revised' | 'model.routed' | 'capability.denied';
|
|
2
|
+
export interface LedgerEvent {
|
|
3
|
+
/** strictly monotonic per store; never reused */
|
|
4
|
+
readonly seq: number;
|
|
5
|
+
readonly at: string;
|
|
6
|
+
readonly kind: LedgerEventKind;
|
|
7
|
+
/** what changed: belief id / skill id / memory id / goal id / model name */
|
|
8
|
+
readonly subject: string;
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
/** Evidence Ledger v2 lineage linkage */
|
|
11
|
+
readonly runId?: string;
|
|
12
|
+
readonly taskId?: string;
|
|
13
|
+
/** confidence at the time of the event, when applicable */
|
|
14
|
+
readonly confidence?: number;
|
|
15
|
+
/** the event this one answers or revises */
|
|
16
|
+
readonly parentSeq?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface LedgerSummary {
|
|
19
|
+
total: number;
|
|
20
|
+
byKind: Partial<Record<LedgerEventKind, number>>;
|
|
21
|
+
corruptLinesSkipped: number;
|
|
22
|
+
lastSeq: number;
|
|
23
|
+
}
|
|
24
|
+
export interface LedgerAppendInput {
|
|
25
|
+
at?: string;
|
|
26
|
+
detail?: string;
|
|
27
|
+
runId?: string;
|
|
28
|
+
taskId?: string;
|
|
29
|
+
confidence?: number;
|
|
30
|
+
parentSeq?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Pure in-memory append-only ledger. Rebuild from persistence with loadLedger. */
|
|
33
|
+
export declare class CognitiveLedger {
|
|
34
|
+
private readonly eventsBySeq;
|
|
35
|
+
private corruptLinesSkipped;
|
|
36
|
+
append(kind: LedgerEventKind, subject: string, input?: LedgerAppendInput): LedgerEvent;
|
|
37
|
+
/** Rebuild from raw persistence lines (used by loadLedger). */
|
|
38
|
+
ingest(lines: string[]): void;
|
|
39
|
+
events(): readonly LedgerEvent[];
|
|
40
|
+
/** Lineage chain: the event with this seq plus every ancestor via parentSeq. */
|
|
41
|
+
chain(seq: number): LedgerEvent[];
|
|
42
|
+
summary(): LedgerSummary;
|
|
43
|
+
}
|
|
44
|
+
export declare function ledgerPath(home: string): string;
|
|
45
|
+
/** Load the persisted ledger. Absent = empty; corrupt lines are skipped and counted. */
|
|
46
|
+
export declare function loadLedger(home: string): Promise<CognitiveLedger>;
|
|
47
|
+
/** Append one event to the persisted store (one JSON line). */
|
|
48
|
+
export declare function appendLedgerEvent(home: string, evt: LedgerEvent): Promise<void>;
|
package/dist/ledger.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - Cognitive Ledger (v0, 2026-10-05 upgrade pack §16)
|
|
3
|
+
*
|
|
4
|
+
* The append-only record of significant cognitive changes — the data
|
|
5
|
+
* structure Credit Assignment will read: belief.created/revised,
|
|
6
|
+
* prediction.made/failed/confirmed, exploration.chosen, observation.recorded,
|
|
7
|
+
* skill.candidate/promoted/rejected, memory.promoted/contradicted,
|
|
8
|
+
* goal.revised, model.routed, capability.denied.
|
|
9
|
+
*
|
|
10
|
+
* Discipline carried over from the trust stores and multi-agent audit:
|
|
11
|
+
* - append-only: events are frozen at append time, seq is strictly
|
|
12
|
+
* monotonic and never reused; there is no edit API by design
|
|
13
|
+
* - parentSeq links an event to the one it answers (PREDICTION_FAILED
|
|
14
|
+
* points back at its PREDICTION_MADE; BELIEF_REVISED at the failed
|
|
15
|
+
* prediction or the earlier belief) — chain() walks lineage to the root
|
|
16
|
+
* - persistence is one JSON object per line under
|
|
17
|
+
* HMH_HOME/cognitive/ledger.jsonl; a corrupt line is skipped and
|
|
18
|
+
* counted, never a crash (same posture as every cognitive state file)
|
|
19
|
+
* - v0 is honest about scope: it records WHO changed and WHAT changed,
|
|
20
|
+
* with lineage hooks for runId/taskId (Evidence Ledger v2). It does
|
|
21
|
+
* not claim causality — attribution is a later, separate claim.
|
|
22
|
+
*/
|
|
23
|
+
import { appendFile, mkdir, readFile } from 'node:fs/promises';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
/** Pure in-memory append-only ledger. Rebuild from persistence with loadLedger. */
|
|
26
|
+
export class CognitiveLedger {
|
|
27
|
+
eventsBySeq = [];
|
|
28
|
+
corruptLinesSkipped = 0;
|
|
29
|
+
append(kind, subject, input = {}) {
|
|
30
|
+
const seq = this.eventsBySeq.length ? this.eventsBySeq[this.eventsBySeq.length - 1].seq + 1 : 1;
|
|
31
|
+
const evt = Object.freeze({
|
|
32
|
+
seq,
|
|
33
|
+
at: input.at ?? new Date().toISOString(),
|
|
34
|
+
kind,
|
|
35
|
+
subject,
|
|
36
|
+
...(input.detail !== undefined ? { detail: input.detail } : {}),
|
|
37
|
+
...(input.runId !== undefined ? { runId: input.runId } : {}),
|
|
38
|
+
...(input.taskId !== undefined ? { taskId: input.taskId } : {}),
|
|
39
|
+
...(input.confidence !== undefined ? { confidence: input.confidence } : {}),
|
|
40
|
+
...(input.parentSeq !== undefined ? { parentSeq: input.parentSeq } : {}),
|
|
41
|
+
});
|
|
42
|
+
this.eventsBySeq.push(evt);
|
|
43
|
+
return evt;
|
|
44
|
+
}
|
|
45
|
+
/** Rebuild from raw persistence lines (used by loadLedger). */
|
|
46
|
+
ingest(lines) {
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const trimmed = line.trim();
|
|
49
|
+
if (!trimmed)
|
|
50
|
+
continue;
|
|
51
|
+
try {
|
|
52
|
+
const raw = JSON.parse(trimmed);
|
|
53
|
+
if (typeof raw.seq !== 'number' || typeof raw.kind !== 'string' || typeof raw.subject !== 'string') {
|
|
54
|
+
this.corruptLinesSkipped++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const seq = this.eventsBySeq.length ? this.eventsBySeq[this.eventsBySeq.length - 1].seq + 1 : 1;
|
|
58
|
+
this.eventsBySeq.push(Object.freeze({ ...raw, seq, at: raw.at ?? new Date().toISOString() }));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
this.corruptLinesSkipped++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
events() {
|
|
66
|
+
return this.eventsBySeq.slice();
|
|
67
|
+
}
|
|
68
|
+
/** Lineage chain: the event with this seq plus every ancestor via parentSeq. */
|
|
69
|
+
chain(seq) {
|
|
70
|
+
const out = [];
|
|
71
|
+
let cursor = this.eventsBySeq.find((e) => e.seq === seq);
|
|
72
|
+
while (cursor) {
|
|
73
|
+
out.unshift(cursor);
|
|
74
|
+
const parent = cursor.parentSeq;
|
|
75
|
+
cursor = parent === undefined ? undefined : this.eventsBySeq.find((e) => e.seq === parent);
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
summary() {
|
|
80
|
+
const byKind = {};
|
|
81
|
+
for (const e of this.eventsBySeq)
|
|
82
|
+
byKind[e.kind] = (byKind[e.kind] ?? 0) + 1;
|
|
83
|
+
return {
|
|
84
|
+
total: this.eventsBySeq.length,
|
|
85
|
+
byKind,
|
|
86
|
+
corruptLinesSkipped: this.corruptLinesSkipped,
|
|
87
|
+
lastSeq: this.eventsBySeq.length ? this.eventsBySeq[this.eventsBySeq.length - 1].seq : 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function ledgerPath(home) {
|
|
92
|
+
return join(home, 'cognitive', 'ledger.jsonl');
|
|
93
|
+
}
|
|
94
|
+
/** Load the persisted ledger. Absent = empty; corrupt lines are skipped and counted. */
|
|
95
|
+
export async function loadLedger(home) {
|
|
96
|
+
const ledger = new CognitiveLedger();
|
|
97
|
+
let text = '';
|
|
98
|
+
try {
|
|
99
|
+
text = await readFile(ledgerPath(home), 'utf8');
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return ledger; // absent = fresh ledger, never a crash
|
|
103
|
+
}
|
|
104
|
+
ledger.ingest(text.split('\n'));
|
|
105
|
+
return ledger;
|
|
106
|
+
}
|
|
107
|
+
/** Append one event to the persisted store (one JSON line). */
|
|
108
|
+
export async function appendLedgerEvent(home, evt) {
|
|
109
|
+
await mkdir(join(home, 'cognitive'), { recursive: true });
|
|
110
|
+
await appendFile(ledgerPath(home), JSON.stringify(evt) + '\n', 'utf8');
|
|
111
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - Prediction OS unified schema (v0, upgrade pack §10)
|
|
3
|
+
*
|
|
4
|
+
* The pack's first core line: the three prediction families that grew up in
|
|
5
|
+
* separate modules become ONE record shape with ONE aggregate report -
|
|
6
|
+
*
|
|
7
|
+
* Outcome Pred (world-model action success) -> calibration
|
|
8
|
+
* State Delta (WM 2.0 shape predictions) -> delta accuracy
|
|
9
|
+
* Edit Pred (Code WM blast radius) -> edit error
|
|
10
|
+
* |
|
|
11
|
+
* unified prediction -> resolution -> normalized error
|
|
12
|
+
* -> ranked learning signal (worstErrors) for the exploration policy
|
|
13
|
+
* -> Cognitive Ledger mirroring (prediction.made/confirmed/failed
|
|
14
|
+
* chained by parentSeq)
|
|
15
|
+
*
|
|
16
|
+
* Honesty rules:
|
|
17
|
+
* - error is DOMAIN-DEFINED and normalized to [0,1]; the aggregate Brier
|
|
18
|
+
* is the mean of squared normalized errors - for the outcome domain
|
|
19
|
+
* this is the classical binary Brier, for delta/edit it is the same
|
|
20
|
+
* arithmetic on the domain's normalized error (stated, not hidden)
|
|
21
|
+
* - verdict threshold is explicit: error <= CONFIRM_THRESHOLD confirmed,
|
|
22
|
+
* otherwise failed; a resolution is write-once (double-resolve refuses)
|
|
23
|
+
* - worstErrors RANKS by observed error; ranking is not causation
|
|
24
|
+
*/
|
|
25
|
+
import type { CognitiveLedger } from './ledger.js';
|
|
26
|
+
import type { Prediction } from './world-model.js';
|
|
27
|
+
import type { EditDelta, PredictionError } from './code-world-model.js';
|
|
28
|
+
export type PredictionDomain = 'outcome' | 'state-delta' | 'edit';
|
|
29
|
+
/** error at or below this counts as a confirmed prediction */
|
|
30
|
+
export declare const CONFIRM_THRESHOLD = 0.5;
|
|
31
|
+
export interface UnifiedPrediction {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly domain: PredictionDomain;
|
|
34
|
+
/** what the prediction is about: actionType | stateKey | entity id */
|
|
35
|
+
readonly subject: string;
|
|
36
|
+
/** canonical predicted value/shape (domain-specific string) */
|
|
37
|
+
readonly predicted: string;
|
|
38
|
+
readonly confidence: number;
|
|
39
|
+
readonly madeAt: string;
|
|
40
|
+
readonly runId?: string;
|
|
41
|
+
readonly taskId?: string;
|
|
42
|
+
readonly resolvedAt?: string;
|
|
43
|
+
readonly actual?: string;
|
|
44
|
+
/** normalized [0,1], domain-defined */
|
|
45
|
+
readonly error?: number;
|
|
46
|
+
readonly verdict?: 'confirmed' | 'failed';
|
|
47
|
+
}
|
|
48
|
+
export interface DomainStats {
|
|
49
|
+
n: number;
|
|
50
|
+
resolved: number;
|
|
51
|
+
confirmed: number;
|
|
52
|
+
meanConfidence: number;
|
|
53
|
+
meanError: number;
|
|
54
|
+
/** mean of squared normalized errors (binary Brier on the outcome domain) */
|
|
55
|
+
brier: number;
|
|
56
|
+
}
|
|
57
|
+
export interface PredictionOSSummary {
|
|
58
|
+
total: number;
|
|
59
|
+
unresolved: number;
|
|
60
|
+
byDomain: Record<PredictionDomain, DomainStats>;
|
|
61
|
+
}
|
|
62
|
+
export interface RecordInput {
|
|
63
|
+
domain: PredictionDomain;
|
|
64
|
+
subject: string;
|
|
65
|
+
predicted: string;
|
|
66
|
+
confidence: number;
|
|
67
|
+
runId?: string;
|
|
68
|
+
taskId?: string;
|
|
69
|
+
id?: string;
|
|
70
|
+
at?: string;
|
|
71
|
+
}
|
|
72
|
+
export declare class PredictionOS {
|
|
73
|
+
private readonly byId;
|
|
74
|
+
private readonly order;
|
|
75
|
+
/** seq of each prediction's ledger.made event, for parentSeq chaining */
|
|
76
|
+
private readonly madeSeq;
|
|
77
|
+
/** when set, record/resolve mirror into the Cognitive Ledger */
|
|
78
|
+
ledger?: CognitiveLedger;
|
|
79
|
+
record(input: RecordInput): UnifiedPrediction;
|
|
80
|
+
/** Write-once resolution: the second resolve on the same id refuses. */
|
|
81
|
+
resolve(id: string, actual: string, error: number): UnifiedPrediction;
|
|
82
|
+
get(id: string): UnifiedPrediction | undefined;
|
|
83
|
+
unresolved(domain?: PredictionDomain): UnifiedPrediction[];
|
|
84
|
+
/** Ranked learning-signal feed: worst observed errors first. */
|
|
85
|
+
worstErrors(limit?: number, domain?: PredictionDomain): UnifiedPrediction[];
|
|
86
|
+
summary(): PredictionOSSummary;
|
|
87
|
+
}
|
|
88
|
+
/** Outcome family: world-model action-success predictions. */
|
|
89
|
+
export declare function fromOutcome(p: Prediction, runId?: string, taskId?: string): RecordInput & {
|
|
90
|
+
resolved?: {
|
|
91
|
+
actual: string;
|
|
92
|
+
error: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/** State-delta family: WM 2.0 shape predictions resolve hit-or-miss. */
|
|
96
|
+
export declare function fromDelta(actionType: string, predictedShape: string, confidence: number, hit: boolean, runId?: string): RecordInput & {
|
|
97
|
+
resolved?: {
|
|
98
|
+
actual: string;
|
|
99
|
+
error: number;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/** Edit family: Code WM blast-radius predictions scored by Jaccard. */
|
|
103
|
+
export declare function fromEditResolution(edit: EditDelta, err: PredictionError, runId?: string): RecordInput & {
|
|
104
|
+
resolved: {
|
|
105
|
+
actual: string;
|
|
106
|
+
error: number;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
/** Record-and-optionally-resolve an adapted prediction in one call. */
|
|
110
|
+
export declare function ingestAdapted(pos: PredictionOS, adapted: RecordInput & {
|
|
111
|
+
resolved?: {
|
|
112
|
+
actual: string;
|
|
113
|
+
error: number;
|
|
114
|
+
};
|
|
115
|
+
}): UnifiedPrediction;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** error at or below this counts as a confirmed prediction */
|
|
2
|
+
export const CONFIRM_THRESHOLD = 0.5;
|
|
3
|
+
export class PredictionOS {
|
|
4
|
+
byId = new Map();
|
|
5
|
+
order = [];
|
|
6
|
+
/** seq of each prediction's ledger.made event, for parentSeq chaining */
|
|
7
|
+
madeSeq = new Map();
|
|
8
|
+
/** when set, record/resolve mirror into the Cognitive Ledger */
|
|
9
|
+
ledger;
|
|
10
|
+
record(input) {
|
|
11
|
+
const id = input.id ?? `pred-${this.byId.size + 1}-${Math.random().toString(36).slice(2, 8)}`;
|
|
12
|
+
if (this.byId.has(id))
|
|
13
|
+
throw new Error(`prediction ${id} already exists - ids are write-once`);
|
|
14
|
+
const p = Object.freeze({
|
|
15
|
+
id,
|
|
16
|
+
domain: input.domain,
|
|
17
|
+
subject: input.subject,
|
|
18
|
+
predicted: input.predicted,
|
|
19
|
+
confidence: input.confidence,
|
|
20
|
+
madeAt: input.at ?? new Date().toISOString(),
|
|
21
|
+
...(input.runId !== undefined ? { runId: input.runId } : {}),
|
|
22
|
+
...(input.taskId !== undefined ? { taskId: input.taskId } : {}),
|
|
23
|
+
});
|
|
24
|
+
this.byId.set(id, p);
|
|
25
|
+
this.order.push(id);
|
|
26
|
+
if (this.ledger) {
|
|
27
|
+
this.madeSeq.set(id, this.ledger.append('prediction.made', input.subject, {
|
|
28
|
+
detail: `${input.domain}: ${input.predicted}`,
|
|
29
|
+
runId: input.runId,
|
|
30
|
+
taskId: input.taskId,
|
|
31
|
+
confidence: input.confidence,
|
|
32
|
+
}).seq);
|
|
33
|
+
}
|
|
34
|
+
return p;
|
|
35
|
+
}
|
|
36
|
+
/** Write-once resolution: the second resolve on the same id refuses. */
|
|
37
|
+
resolve(id, actual, error) {
|
|
38
|
+
const existing = this.byId.get(id);
|
|
39
|
+
if (!existing)
|
|
40
|
+
throw new Error(`prediction ${id} not found`);
|
|
41
|
+
if (existing.resolvedAt !== undefined)
|
|
42
|
+
throw new Error(`prediction ${id} already resolved - resolutions are write-once`);
|
|
43
|
+
const clamped = Math.max(0, Math.min(1, error));
|
|
44
|
+
const resolved = Object.freeze({
|
|
45
|
+
...existing,
|
|
46
|
+
resolvedAt: new Date().toISOString(),
|
|
47
|
+
actual,
|
|
48
|
+
error: clamped,
|
|
49
|
+
verdict: clamped <= CONFIRM_THRESHOLD ? 'confirmed' : 'failed',
|
|
50
|
+
});
|
|
51
|
+
this.byId.set(id, resolved);
|
|
52
|
+
if (this.ledger) {
|
|
53
|
+
this.ledger.append(resolved.verdict === 'confirmed' ? 'prediction.confirmed' : 'prediction.failed', resolved.subject, {
|
|
54
|
+
detail: `${resolved.domain}: predicted ${resolved.predicted}, actual ${actual}`,
|
|
55
|
+
runId: resolved.runId,
|
|
56
|
+
taskId: resolved.taskId,
|
|
57
|
+
confidence: resolved.confidence,
|
|
58
|
+
...(this.madeSeq.has(id) ? { parentSeq: this.madeSeq.get(id) } : {}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
63
|
+
get(id) {
|
|
64
|
+
return this.byId.get(id);
|
|
65
|
+
}
|
|
66
|
+
unresolved(domain) {
|
|
67
|
+
return this.order
|
|
68
|
+
.map((id) => this.byId.get(id))
|
|
69
|
+
.filter((p) => p.resolvedAt === undefined && (domain === undefined || p.domain === domain));
|
|
70
|
+
}
|
|
71
|
+
/** Ranked learning-signal feed: worst observed errors first. */
|
|
72
|
+
worstErrors(limit = 10, domain) {
|
|
73
|
+
return this.order
|
|
74
|
+
.map((id) => this.byId.get(id))
|
|
75
|
+
.filter((p) => p.error !== undefined && (domain === undefined || p.domain === domain))
|
|
76
|
+
.sort((a, b) => (b.error ?? 0) - (a.error ?? 0))
|
|
77
|
+
.slice(0, limit);
|
|
78
|
+
}
|
|
79
|
+
summary() {
|
|
80
|
+
const domains = ['outcome', 'state-delta', 'edit'];
|
|
81
|
+
const byDomain = {};
|
|
82
|
+
let unresolved = 0;
|
|
83
|
+
for (const d of domains) {
|
|
84
|
+
const ps = this.order.map((id) => this.byId.get(id)).filter((p) => p.domain === d);
|
|
85
|
+
const res = ps.filter((p) => p.error !== undefined);
|
|
86
|
+
byDomain[d] = {
|
|
87
|
+
n: ps.length,
|
|
88
|
+
resolved: res.length,
|
|
89
|
+
confirmed: res.filter((p) => p.verdict === 'confirmed').length,
|
|
90
|
+
meanConfidence: ps.length ? Number((ps.reduce((s, p) => s + p.confidence, 0) / ps.length).toFixed(3)) : 0,
|
|
91
|
+
meanError: res.length ? Number((res.reduce((s, p) => s + (p.error ?? 0), 0) / res.length).toFixed(3)) : 0,
|
|
92
|
+
brier: res.length ? Number((res.reduce((s, p) => s + (p.error ?? 0) ** 2, 0) / res.length).toFixed(3)) : 0,
|
|
93
|
+
};
|
|
94
|
+
unresolved += ps.filter((p) => p.resolvedAt === undefined).length;
|
|
95
|
+
}
|
|
96
|
+
return { total: this.order.length, unresolved, byDomain };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/* ---------------- domain adapters ---------------- */
|
|
100
|
+
/** Outcome family: world-model action-success predictions. */
|
|
101
|
+
export function fromOutcome(p, runId, taskId) {
|
|
102
|
+
const predictedCall = p.confidence > CONFIRM_THRESHOLD ? 'success' : 'failure';
|
|
103
|
+
const input = {
|
|
104
|
+
id: p.id,
|
|
105
|
+
domain: 'outcome',
|
|
106
|
+
subject: p.actionType,
|
|
107
|
+
predicted: predictedCall,
|
|
108
|
+
confidence: p.confidence,
|
|
109
|
+
at: p.createdAt,
|
|
110
|
+
runId,
|
|
111
|
+
taskId,
|
|
112
|
+
};
|
|
113
|
+
if (p.actual === 'success' || p.actual === 'failure') {
|
|
114
|
+
// classical binary error: |confidence - actual(0/1)|
|
|
115
|
+
const actual01 = p.actual === 'success' ? 1 : 0;
|
|
116
|
+
input.resolved = { actual: p.actual, error: p.error ?? Math.abs(p.confidence - actual01) };
|
|
117
|
+
}
|
|
118
|
+
return input;
|
|
119
|
+
}
|
|
120
|
+
/** State-delta family: WM 2.0 shape predictions resolve hit-or-miss. */
|
|
121
|
+
export function fromDelta(actionType, predictedShape, confidence, hit, runId) {
|
|
122
|
+
return {
|
|
123
|
+
domain: 'state-delta',
|
|
124
|
+
subject: actionType,
|
|
125
|
+
predicted: predictedShape,
|
|
126
|
+
confidence,
|
|
127
|
+
runId,
|
|
128
|
+
resolved: { actual: hit ? predictedShape : 'other-shape', error: hit ? 0 : 1 },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Edit family: Code WM blast-radius predictions scored by Jaccard. */
|
|
132
|
+
export function fromEditResolution(edit, err, runId) {
|
|
133
|
+
return {
|
|
134
|
+
domain: 'edit',
|
|
135
|
+
subject: edit.target,
|
|
136
|
+
predicted: `${edit.editKind}(${edit.touchedEntities.length}e/${edit.touchedRelations.length}r)`,
|
|
137
|
+
confidence: 1 - edit.newDiagnosticEstimate,
|
|
138
|
+
runId,
|
|
139
|
+
resolved: {
|
|
140
|
+
actual: `jaccard ${err.jaccard.toFixed(3)} (missed ${err.missed.length}, spurious ${err.spurious.length})`,
|
|
141
|
+
error: Number(Math.max(0, Math.min(1, 1 - err.jaccard)).toFixed(3)),
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** Record-and-optionally-resolve an adapted prediction in one call. */
|
|
146
|
+
export function ingestAdapted(pos, adapted) {
|
|
147
|
+
const { resolved, ...input } = adapted;
|
|
148
|
+
const p = pos.record(input);
|
|
149
|
+
return resolved ? pos.resolve(p.id, resolved.actual, resolved.error) : p;
|
|
150
|
+
}
|
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
|
@@ -150,6 +150,11 @@ export declare class WorldModel {
|
|
|
150
150
|
private deltaHits;
|
|
151
151
|
/** open structured predictions: predictionId -> expected shape (resolved on update) */
|
|
152
152
|
private openDeltaPredictions;
|
|
153
|
+
/** Cognitive Ledger hook (v0, 2026-10-05 pack): when set, significant
|
|
154
|
+
* cognitive changes (belief revisions) are mirrored as ledger events.
|
|
155
|
+
* Optional and side-effect-free by contract — a ledger failure must
|
|
156
|
+
* never break the model it observes. */
|
|
157
|
+
ledger?: (kind: 'belief.revised', subject: string, detail: string, confidence?: number) => void;
|
|
153
158
|
constructor(environmentId: string);
|
|
154
159
|
get worldState(): WorldState;
|
|
155
160
|
/** WM-001/006. Apply a transition: update variables/entities, per-action
|
package/dist/world-model.js
CHANGED
|
@@ -57,6 +57,11 @@ export class WorldModel {
|
|
|
57
57
|
deltaHits = 0;
|
|
58
58
|
/** open structured predictions: predictionId -> expected shape (resolved on update) */
|
|
59
59
|
openDeltaPredictions = new Map();
|
|
60
|
+
/** Cognitive Ledger hook (v0, 2026-10-05 pack): when set, significant
|
|
61
|
+
* cognitive changes (belief revisions) are mirrored as ledger events.
|
|
62
|
+
* Optional and side-effect-free by contract — a ledger failure must
|
|
63
|
+
* never break the model it observes. */
|
|
64
|
+
ledger;
|
|
60
65
|
constructor(environmentId) {
|
|
61
66
|
this.state = {
|
|
62
67
|
environmentId,
|
|
@@ -252,6 +257,10 @@ export class WorldModel {
|
|
|
252
257
|
const belief = this.state.beliefs.find((b) => b.id === `act:${actionType}`);
|
|
253
258
|
if (belief) {
|
|
254
259
|
belief.corrections = [...(belief.corrections ?? []), { pattern, rule, fromCluster: ev.cluster }];
|
|
260
|
+
try {
|
|
261
|
+
this.ledger?.('belief.revised', belief.id, rule, belief.confidence);
|
|
262
|
+
}
|
|
263
|
+
catch { /* the ledger must never break the model it observes */ }
|
|
255
264
|
}
|
|
256
265
|
rulesAdded.push({ pattern, rule });
|
|
257
266
|
}
|
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.28",
|
|
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.28"
|
|
30
|
+
}
|
|
31
|
+
}
|