@timmeck/brain-core 2.36.106 → 2.36.108
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/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/research/research-orchestrator.d.ts +2 -1
- package/dist/research/research-orchestrator.js +78 -43
- package/dist/research/research-orchestrator.js.map +1 -1
- package/dist/self-model/stage3-run-log.d.ts +52 -0
- package/dist/self-model/stage3-run-log.js +88 -0
- package/dist/self-model/stage3-run-log.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-3 Run Log — Observability for Self-Model execution stages.
|
|
3
|
+
*
|
|
4
|
+
* Every Stage-3 sub-step (operationalize, diagnose, improve, evolve)
|
|
5
|
+
* gets individually tracked with timing, success/failure, and error details.
|
|
6
|
+
*
|
|
7
|
+
* P0 fix: no more swallowed errors in catch blocks.
|
|
8
|
+
*/
|
|
9
|
+
import type Database from 'better-sqlite3';
|
|
10
|
+
export declare function runStage3RunLogMigration(db: Database.Database): void;
|
|
11
|
+
export type Stage3StageName = 'operationalize' | 'diagnose' | 'improve' | 'evolve';
|
|
12
|
+
export interface Stage3RunEntry {
|
|
13
|
+
cycle: number;
|
|
14
|
+
stage: Stage3StageName;
|
|
15
|
+
status: 'success' | 'failure' | 'skipped';
|
|
16
|
+
duration_ms: number;
|
|
17
|
+
result?: Record<string, unknown>;
|
|
18
|
+
error_message?: string;
|
|
19
|
+
error_stack?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Stage3Summary {
|
|
22
|
+
total_runs: number;
|
|
23
|
+
successes: number;
|
|
24
|
+
failures: number;
|
|
25
|
+
by_stage: Record<string, {
|
|
26
|
+
runs: number;
|
|
27
|
+
failures: number;
|
|
28
|
+
avg_duration_ms: number;
|
|
29
|
+
}>;
|
|
30
|
+
recent_failures: Array<{
|
|
31
|
+
cycle: number;
|
|
32
|
+
stage: string;
|
|
33
|
+
error_message: string;
|
|
34
|
+
created_at: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export declare class Stage3RunLog {
|
|
38
|
+
private db;
|
|
39
|
+
constructor(db: Database.Database);
|
|
40
|
+
/** Record a stage execution result. */
|
|
41
|
+
record(entry: Stage3RunEntry): void;
|
|
42
|
+
/**
|
|
43
|
+
* Run a stage with full instrumentation.
|
|
44
|
+
* Returns the result or undefined on failure. Never throws.
|
|
45
|
+
*/
|
|
46
|
+
runStage<T>(cycle: number, stage: Stage3StageName, fn: () => T, log: {
|
|
47
|
+
warn: (msg: string) => void;
|
|
48
|
+
info: (msg: string) => void;
|
|
49
|
+
}): T | undefined;
|
|
50
|
+
/** Get summary of all Stage-3 runs. */
|
|
51
|
+
getSummary(): Stage3Summary;
|
|
52
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// ── Migration ────────────────────────────────────────
|
|
2
|
+
export function runStage3RunLogMigration(db) {
|
|
3
|
+
db.exec(`
|
|
4
|
+
CREATE TABLE IF NOT EXISTS stage3_run_log (
|
|
5
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
6
|
+
cycle INTEGER NOT NULL,
|
|
7
|
+
stage TEXT NOT NULL,
|
|
8
|
+
status TEXT NOT NULL,
|
|
9
|
+
duration_ms INTEGER NOT NULL,
|
|
10
|
+
result_json TEXT,
|
|
11
|
+
error_message TEXT,
|
|
12
|
+
error_stack TEXT,
|
|
13
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
14
|
+
);
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_s3rl_cycle ON stage3_run_log(cycle);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_s3rl_stage ON stage3_run_log(stage);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_s3rl_status ON stage3_run_log(status);
|
|
18
|
+
`);
|
|
19
|
+
}
|
|
20
|
+
// ── Engine ───────────────────────────────────────────
|
|
21
|
+
export class Stage3RunLog {
|
|
22
|
+
db;
|
|
23
|
+
constructor(db) {
|
|
24
|
+
this.db = db;
|
|
25
|
+
runStage3RunLogMigration(db);
|
|
26
|
+
}
|
|
27
|
+
/** Record a stage execution result. */
|
|
28
|
+
record(entry) {
|
|
29
|
+
this.db.prepare(`
|
|
30
|
+
INSERT INTO stage3_run_log (cycle, stage, status, duration_ms, result_json, error_message, error_stack)
|
|
31
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
32
|
+
`).run(entry.cycle, entry.stage, entry.status, entry.duration_ms, entry.result ? JSON.stringify(entry.result) : null, entry.error_message ?? null, entry.error_stack ?? null);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Run a stage with full instrumentation.
|
|
36
|
+
* Returns the result or undefined on failure. Never throws.
|
|
37
|
+
*/
|
|
38
|
+
runStage(cycle, stage, fn, log) {
|
|
39
|
+
const start = Date.now();
|
|
40
|
+
try {
|
|
41
|
+
const result = fn();
|
|
42
|
+
const duration = Date.now() - start;
|
|
43
|
+
this.record({
|
|
44
|
+
cycle, stage, status: 'success', duration_ms: duration,
|
|
45
|
+
result: typeof result === 'object' && result !== null ? result : { value: result },
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
const duration = Date.now() - start;
|
|
51
|
+
const error = err;
|
|
52
|
+
const message = error.message || String(err);
|
|
53
|
+
const stack = error.stack?.substring(0, 500) || '';
|
|
54
|
+
// Log at WARN level — never silently swallow
|
|
55
|
+
log.warn(`[stage3] ${stage} FAILED in cycle ${cycle} (${duration}ms): ${message}`);
|
|
56
|
+
this.record({
|
|
57
|
+
cycle, stage, status: 'failure', duration_ms: duration,
|
|
58
|
+
error_message: message, error_stack: stack,
|
|
59
|
+
});
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Get summary of all Stage-3 runs. */
|
|
64
|
+
getSummary() {
|
|
65
|
+
const total = this.db.prepare('SELECT count(*) as c FROM stage3_run_log').get().c;
|
|
66
|
+
const successes = this.db.prepare("SELECT count(*) as c FROM stage3_run_log WHERE status = 'success'").get().c;
|
|
67
|
+
const failures = total - successes;
|
|
68
|
+
const byStageRows = this.db.prepare(`
|
|
69
|
+
SELECT stage,
|
|
70
|
+
count(*) as runs,
|
|
71
|
+
sum(case when status = 'failure' then 1 else 0 end) as failures,
|
|
72
|
+
avg(duration_ms) as avg_duration_ms
|
|
73
|
+
FROM stage3_run_log
|
|
74
|
+
GROUP BY stage
|
|
75
|
+
`).all();
|
|
76
|
+
const by_stage = {};
|
|
77
|
+
for (const row of byStageRows) {
|
|
78
|
+
by_stage[row.stage] = { runs: row.runs, failures: row.failures, avg_duration_ms: Math.round(row.avg_duration_ms) };
|
|
79
|
+
}
|
|
80
|
+
const recent_failures = this.db.prepare(`
|
|
81
|
+
SELECT cycle, stage, error_message, created_at
|
|
82
|
+
FROM stage3_run_log WHERE status = 'failure'
|
|
83
|
+
ORDER BY created_at DESC LIMIT 10
|
|
84
|
+
`).all();
|
|
85
|
+
return { total_runs: total, successes, failures, by_stage, recent_failures };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=stage3-run-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage3-run-log.js","sourceRoot":"","sources":["../../src/self-model/stage3-run-log.ts"],"names":[],"mappings":"AAUA,wDAAwD;AAExD,MAAM,UAAU,wBAAwB,CAAC,EAAqB;IAC5D,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;GAeP,CAAC,CAAC;AACL,CAAC;AAwBD,wDAAwD;AAExD,MAAM,OAAO,YAAY;IACf,EAAE,CAAoB;IAE9B,YAAY,EAAqB;QAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,wBAAwB,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,uCAAuC;IACvC,MAA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