@hmharness/cognitive 0.19.2 → 0.19.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.
- package/dist/analysis.d.ts +28 -0
- package/dist/analysis.js +79 -0
- package/package.json +2 -2
package/dist/analysis.d.ts
CHANGED
|
@@ -45,3 +45,31 @@ export interface BenchReport {
|
|
|
45
45
|
* = the run's own step count +1, so efficiency measures consistency, and
|
|
46
46
|
* honest runs with retries score below clean one-shot runs). */
|
|
47
47
|
export declare function benchFromTrajectories(home: string, environmentId?: string, limit?: number): Promise<BenchReport | null>;
|
|
48
|
+
/** Compact world-model digest for the SYSTEM PROMPT. The model sees which
|
|
49
|
+
* tool types history trusts, which keep failing, and what the diagnosis
|
|
50
|
+
* layer currently suggests — perception feeding action, capped hard so it
|
|
51
|
+
* can never bloat the prompt (max ~500 chars). */
|
|
52
|
+
export declare function buildContextDigest(home: string, maxChars?: number): Promise<string>;
|
|
53
|
+
export interface GoalDriftView {
|
|
54
|
+
trajectoryId: string;
|
|
55
|
+
goalDescription: string;
|
|
56
|
+
driftScore: number;
|
|
57
|
+
signals: string[];
|
|
58
|
+
recommendation: string;
|
|
59
|
+
}
|
|
60
|
+
/** GOAL-005 on live data: for every recorded trajectory that carried a goal,
|
|
61
|
+
* compare its actions against the goal's keywords and report drift. */
|
|
62
|
+
export declare function analyzeGoalDrift(home: string, limit?: number): Promise<GoalDriftView[]>;
|
|
63
|
+
export interface SkillCandidateView {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
procedure: string[];
|
|
67
|
+
evidenceTrajectories: number;
|
|
68
|
+
status: string;
|
|
69
|
+
}
|
|
70
|
+
/** SK-002 on live data: mine repeated successful action runs from the
|
|
71
|
+
* trajectory store into skill CANDIDATES (promotion still requires the
|
|
72
|
+
* benchmark gate — this only surfaces what the history suggests). */
|
|
73
|
+
export declare function skillCandidatesFromHistory(home: string, opts?: {
|
|
74
|
+
minRepeat?: number;
|
|
75
|
+
}): Promise<SkillCandidateView[]>;
|
package/dist/analysis.js
CHANGED
|
@@ -118,3 +118,82 @@ export async function benchFromTrajectories(home, environmentId = 'terminal', li
|
|
|
118
118
|
},
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
+
/* ---- context advisor (blueprint M3: the planner consumes the world model) ---- */
|
|
122
|
+
/** Compact world-model digest for the SYSTEM PROMPT. The model sees which
|
|
123
|
+
* tool types history trusts, which keep failing, and what the diagnosis
|
|
124
|
+
* layer currently suggests — perception feeding action, capped hard so it
|
|
125
|
+
* can never bloat the prompt (max ~500 chars). */
|
|
126
|
+
export async function buildContextDigest(home, maxChars = 500) {
|
|
127
|
+
try {
|
|
128
|
+
const wm = await analyzeWorldModel(home);
|
|
129
|
+
if (wm.stepsReplayed < 3)
|
|
130
|
+
return ''; // too little evidence to advise on
|
|
131
|
+
const lines = [];
|
|
132
|
+
const untrusted = wm.beliefs.filter((b) => b.confidence < 0.5 && b.evidenceCount >= 2);
|
|
133
|
+
if (untrusted.length > 0) {
|
|
134
|
+
lines.push(`Flaky tools historically (verify carefully when using): ${untrusted.slice(0, 3).map((b) => `${b.actionType}(${Math.round(b.confidence * 100)}%)`).join(', ')}.`);
|
|
135
|
+
}
|
|
136
|
+
const trusted = wm.beliefs.filter((b) => b.confidence >= 0.7 && b.evidenceCount >= 3);
|
|
137
|
+
if (trusted.length > 0) {
|
|
138
|
+
lines.push(`Reliable tools: ${trusted.slice(0, 3).map((b) => b.actionType).join(', ')}.`);
|
|
139
|
+
}
|
|
140
|
+
const { opportunities } = await diagnoseOpportunities(home);
|
|
141
|
+
const opp = opportunities[0];
|
|
142
|
+
if (opp)
|
|
143
|
+
lines.push(`Learning focus right now: ${opp.signal.slice(0, 120)}.`);
|
|
144
|
+
const text = lines.join(' ');
|
|
145
|
+
return text.length > maxChars ? text.slice(0, maxChars - 3) + '...' : text;
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return ''; // advising is best-effort; never block context assembly
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** GOAL-005 on live data: for every recorded trajectory that carried a goal,
|
|
152
|
+
* compare its actions against the goal's keywords and report drift. */
|
|
153
|
+
export async function analyzeGoalDrift(home, limit = 100) {
|
|
154
|
+
const { GoalManager } = await import("./goal.js");
|
|
155
|
+
const gm = new GoalManager();
|
|
156
|
+
const trajectories = (await loadTrajectories(home, limit)).filter((t) => t.goal?.description);
|
|
157
|
+
const out = [];
|
|
158
|
+
for (const traj of trajectories) {
|
|
159
|
+
const goal = gm.propose({
|
|
160
|
+
id: traj.goal.id,
|
|
161
|
+
description: traj.goal.description,
|
|
162
|
+
source: 'user',
|
|
163
|
+
priority: 1,
|
|
164
|
+
constraints: [],
|
|
165
|
+
successCriteria: [],
|
|
166
|
+
});
|
|
167
|
+
const transitions = traj.steps.map((s) => ({
|
|
168
|
+
stateBefore: {},
|
|
169
|
+
action: s.action,
|
|
170
|
+
observation: { environmentId: traj.environment.id, timestamp: traj.startedAt, state: null, availableActions: [] },
|
|
171
|
+
outcome: s.outcome,
|
|
172
|
+
}));
|
|
173
|
+
const report = gm.detectDrift(goal, transitions, { sessionId: traj.sessionId, actionsTaken: traj.steps.length });
|
|
174
|
+
out.push({
|
|
175
|
+
trajectoryId: traj.id,
|
|
176
|
+
goalDescription: traj.goal.description,
|
|
177
|
+
driftScore: report.driftScore,
|
|
178
|
+
signals: report.signals,
|
|
179
|
+
recommendation: report.recommendation,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return out.sort((a, b) => b.driftScore - a.driftScore);
|
|
183
|
+
}
|
|
184
|
+
/** SK-002 on live data: mine repeated successful action runs from the
|
|
185
|
+
* trajectory store into skill CANDIDATES (promotion still requires the
|
|
186
|
+
* benchmark gate — this only surfaces what the history suggests). */
|
|
187
|
+
export async function skillCandidatesFromHistory(home, opts) {
|
|
188
|
+
const { SkillCompiler } = await import("./skill-compiler.js");
|
|
189
|
+
const compiler = new SkillCompiler();
|
|
190
|
+
const trajectories = await loadTrajectories(home);
|
|
191
|
+
const candidates = await compiler.compile(trajectories, opts);
|
|
192
|
+
return candidates.map((c) => ({
|
|
193
|
+
id: c.id,
|
|
194
|
+
name: c.name,
|
|
195
|
+
procedure: c.procedure.map((s) => s.ref),
|
|
196
|
+
evidenceTrajectories: c.evidence.length,
|
|
197
|
+
status: c.status,
|
|
198
|
+
}));
|
|
199
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cognitive",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.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.19.
|
|
29
|
+
"@hmharness/kernel": "0.19.3"
|
|
30
30
|
}
|
|
31
31
|
}
|