@hmharness/cognitive 0.19.8 → 0.19.9
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/governance.d.ts +54 -0
- package/dist/governance.js +97 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CognitiveTrajectory } from './index.js';
|
|
2
|
+
export interface ReplayStepView {
|
|
3
|
+
step: number;
|
|
4
|
+
actionType: string;
|
|
5
|
+
args: Record<string, unknown>;
|
|
6
|
+
reason?: string;
|
|
7
|
+
prediction?: {
|
|
8
|
+
claim: string;
|
|
9
|
+
confidence: number;
|
|
10
|
+
};
|
|
11
|
+
outcome: 'success' | 'failure' | 'unknown';
|
|
12
|
+
durationMs?: number;
|
|
13
|
+
evidence: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ReplayView {
|
|
16
|
+
trajectoryId: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
environmentId: string;
|
|
19
|
+
goal?: string;
|
|
20
|
+
startedAt: string;
|
|
21
|
+
steps: ReplayStepView[];
|
|
22
|
+
metrics: CognitiveTrajectory['metrics'];
|
|
23
|
+
}
|
|
24
|
+
export declare function listTrajectoryIds(home: string, limit?: number): Promise<Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
startedAt: string;
|
|
27
|
+
actions: number;
|
|
28
|
+
success: boolean;
|
|
29
|
+
environmentId: string;
|
|
30
|
+
}>>;
|
|
31
|
+
export declare function replayTrajectory(home: string, trajectoryId: string): Promise<ReplayView | null>;
|
|
32
|
+
export interface CognitiveExport {
|
|
33
|
+
exportedAt: string;
|
|
34
|
+
home: string;
|
|
35
|
+
trajectoryCount: number;
|
|
36
|
+
memoryLineCount: number;
|
|
37
|
+
auditLineCount: number;
|
|
38
|
+
trajectories: CognitiveTrajectory[];
|
|
39
|
+
memoryJsonl: string;
|
|
40
|
+
evolutionAuditJsonl: string;
|
|
41
|
+
multiAgentJsonl: string;
|
|
42
|
+
}
|
|
43
|
+
/** §18 data governance: full-fidelity single-file export (verbatim jsonl). */
|
|
44
|
+
export declare function exportCognitiveState(home: string, outFile?: string): Promise<{
|
|
45
|
+
file: string;
|
|
46
|
+
export: CognitiveExport;
|
|
47
|
+
}>;
|
|
48
|
+
/** §18 data governance: delete ONLY the cognitive store; the confirmation
|
|
49
|
+
* token must be exactly 'purge-cognitive' (no wildcard accepts). */
|
|
50
|
+
export declare function purgeCognitiveState(home: string, confirm: string): Promise<{
|
|
51
|
+
ok: boolean;
|
|
52
|
+
removed: string[];
|
|
53
|
+
error?: string;
|
|
54
|
+
}>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/cognitive - trajectory replay + data governance
|
|
3
|
+
* (blueprint RD-010 replay UI backend; §18 可回放/可导出/可删除)
|
|
4
|
+
*
|
|
5
|
+
* replayTrajectory: one recorded run as an inspectable step list (action,
|
|
6
|
+
* prediction, outcome, duration) — the dashboard's replay viewer backend.
|
|
7
|
+
*
|
|
8
|
+
* exportCognitiveState: single-file bundle of trajectories + memory + audit
|
|
9
|
+
* (data governance: the user can ALWAYS take their data out, verbatim).
|
|
10
|
+
*
|
|
11
|
+
* purgeCognitiveState: deletes the cognitive store (trajectories/memory/
|
|
12
|
+
* evolution audit/multi-agent log) after an explicit confirmation token —
|
|
13
|
+
* the deletion side of governance; nothing else (sessions, insights,
|
|
14
|
+
* evolution skills) is touched.
|
|
15
|
+
*/
|
|
16
|
+
import { readFile, writeFile, rm, readdir } from 'node:fs/promises';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { loadTrajectories } from "./analysis.js";
|
|
19
|
+
export async function listTrajectoryIds(home, limit = 50) {
|
|
20
|
+
const all = await loadTrajectories(home, 500);
|
|
21
|
+
return all
|
|
22
|
+
.slice(-limit)
|
|
23
|
+
.reverse()
|
|
24
|
+
.map((t) => ({ id: t.id, startedAt: t.startedAt, actions: t.metrics.actions, success: t.metrics.success, environmentId: t.environment.id }));
|
|
25
|
+
}
|
|
26
|
+
export async function replayTrajectory(home, trajectoryId) {
|
|
27
|
+
const all = await loadTrajectories(home, 500);
|
|
28
|
+
const traj = all.find((t) => t.id === trajectoryId)
|
|
29
|
+
?? (trajectoryId === 'latest' ? all[all.length - 1] : undefined);
|
|
30
|
+
if (!traj)
|
|
31
|
+
return null;
|
|
32
|
+
return {
|
|
33
|
+
trajectoryId: traj.id,
|
|
34
|
+
sessionId: traj.sessionId,
|
|
35
|
+
environmentId: traj.environment.id,
|
|
36
|
+
goal: traj.goal?.description,
|
|
37
|
+
startedAt: traj.startedAt,
|
|
38
|
+
steps: traj.steps.map((s) => ({
|
|
39
|
+
step: s.step,
|
|
40
|
+
actionType: s.action.type,
|
|
41
|
+
args: s.action.args,
|
|
42
|
+
reason: s.action.reason,
|
|
43
|
+
prediction: s.prediction,
|
|
44
|
+
outcome: s.outcome,
|
|
45
|
+
durationMs: s.durationMs,
|
|
46
|
+
evidence: s.evidence,
|
|
47
|
+
})),
|
|
48
|
+
metrics: traj.metrics,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** §18 data governance: full-fidelity single-file export (verbatim jsonl). */
|
|
52
|
+
export async function exportCognitiveState(home, outFile) {
|
|
53
|
+
const read = async (p) => {
|
|
54
|
+
try {
|
|
55
|
+
return await readFile(p, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const exp = {
|
|
62
|
+
exportedAt: new Date().toISOString(),
|
|
63
|
+
home,
|
|
64
|
+
trajectoryCount: 0,
|
|
65
|
+
memoryLineCount: 0,
|
|
66
|
+
auditLineCount: 0,
|
|
67
|
+
trajectories: await loadTrajectories(home, 10_000),
|
|
68
|
+
memoryJsonl: await read(join(home, 'cognitive', 'memory', 'memory.jsonl')),
|
|
69
|
+
evolutionAuditJsonl: await read(join(home, 'cognitive', 'evolution', 'audit.jsonl')),
|
|
70
|
+
multiAgentJsonl: await read(join(home, 'cognitive', 'multi-agent.jsonl')),
|
|
71
|
+
};
|
|
72
|
+
exp.trajectoryCount = exp.trajectories.length;
|
|
73
|
+
exp.memoryLineCount = exp.memoryJsonl.split('\n').filter((l) => l.trim()).length;
|
|
74
|
+
exp.auditLineCount = exp.evolutionAuditJsonl.split('\n').filter((l) => l.trim()).length;
|
|
75
|
+
const file = outFile ?? join(home, `cognitive-export-${Date.now().toString(36)}.json`);
|
|
76
|
+
await writeFile(file, JSON.stringify(exp, null, 1), 'utf8');
|
|
77
|
+
return { file, export: exp };
|
|
78
|
+
}
|
|
79
|
+
/** §18 data governance: delete ONLY the cognitive store; the confirmation
|
|
80
|
+
* token must be exactly 'purge-cognitive' (no wildcard accepts). */
|
|
81
|
+
export async function purgeCognitiveState(home, confirm) {
|
|
82
|
+
if (confirm !== 'purge-cognitive') {
|
|
83
|
+
return { ok: false, removed: [], error: "refusing: pass confirm='purge-cognitive' explicitly" };
|
|
84
|
+
}
|
|
85
|
+
const removed = [];
|
|
86
|
+
for (const dir of ['trajectories', 'memory', 'evolution']) {
|
|
87
|
+
const p = join(home, 'cognitive', dir);
|
|
88
|
+
await rm(p, { recursive: true, force: true }).catch(() => undefined);
|
|
89
|
+
removed.push(`cognitive/${dir}`);
|
|
90
|
+
}
|
|
91
|
+
const ma = join(home, 'cognitive', 'multi-agent.jsonl');
|
|
92
|
+
await rm(ma, { force: true }).catch(() => undefined);
|
|
93
|
+
removed.push('cognitive/multi-agent.jsonl');
|
|
94
|
+
// keep the cognitive/ dir itself (status/audit will recreate on demand)
|
|
95
|
+
void readdir;
|
|
96
|
+
return { ok: true, removed };
|
|
97
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/cognitive",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.9",
|
|
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.9"
|
|
30
30
|
}
|
|
31
31
|
}
|