@timmeck/brain-core 2.36.54 → 2.36.55
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/causal/causal-planner.d.ts +45 -0
- package/dist/causal/causal-planner.js +135 -0
- package/dist/causal/causal-planner.js.map +1 -0
- package/dist/creative/creative-engine.d.ts +81 -0
- package/dist/creative/creative-engine.js +289 -0
- package/dist/creative/creative-engine.js.map +1 -0
- package/dist/creative/index.d.ts +2 -0
- package/dist/creative/index.js +2 -0
- package/dist/creative/index.js.map +1 -0
- package/dist/goals/research-roadmap.d.ts +73 -0
- package/dist/goals/research-roadmap.js +231 -0
- package/dist/goals/research-roadmap.js.map +1 -0
- package/dist/guardrails/guardrail-engine.d.ts +82 -0
- package/dist/guardrails/guardrail-engine.js +279 -0
- package/dist/guardrails/guardrail-engine.js.map +1 -0
- package/dist/guardrails/index.d.ts +2 -0
- package/dist/guardrails/index.js +2 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/anthropic-provider.d.ts +2 -0
- package/dist/llm/anthropic-provider.js +27 -2
- package/dist/llm/anthropic-provider.js.map +1 -1
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/ollama-provider.d.ts +3 -0
- package/dist/llm/ollama-provider.js +28 -6
- package/dist/llm/ollama-provider.js.map +1 -1
- package/dist/llm/provider.d.ts +3 -1
- package/dist/llm/provider.js.map +1 -1
- package/dist/llm/structured-output.d.ts +6 -1
- package/dist/llm/structured-output.js.map +1 -1
- package/dist/mcp/vision-tools.d.ts +64 -0
- package/dist/mcp/vision-tools.js +106 -0
- package/dist/mcp/vision-tools.js.map +1 -0
- package/dist/research/research-orchestrator.d.ts +12 -0
- package/dist/research/research-orchestrator.js +103 -2
- package/dist/research/research-orchestrator.js.map +1 -1
- package/dist/self-modification/self-modification-engine.js +14 -1
- package/dist/self-modification/self-modification-engine.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runRoadmapMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS research_roadmaps (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
title TEXT NOT NULL,
|
|
8
|
+
final_goal_id INTEGER,
|
|
9
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
10
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
11
|
+
);
|
|
12
|
+
CREATE INDEX IF NOT EXISTS idx_roadmaps_status ON research_roadmaps(status);
|
|
13
|
+
`);
|
|
14
|
+
// Add depends_on + roadmap_id to goals table
|
|
15
|
+
const addColumn = (col, type, def) => {
|
|
16
|
+
try {
|
|
17
|
+
db.exec(`ALTER TABLE goals ADD COLUMN ${col} ${type} NOT NULL DEFAULT ${def}`);
|
|
18
|
+
}
|
|
19
|
+
catch { /* already exists */ }
|
|
20
|
+
};
|
|
21
|
+
addColumn('depends_on', 'TEXT', "'[]'");
|
|
22
|
+
addColumn('roadmap_id', 'INTEGER', '0');
|
|
23
|
+
}
|
|
24
|
+
// ── Engine ──────────────────────────────────────────────
|
|
25
|
+
export class ResearchRoadmap {
|
|
26
|
+
db;
|
|
27
|
+
goalEngine;
|
|
28
|
+
log = getLogger();
|
|
29
|
+
ts = null;
|
|
30
|
+
constructor(db, goalEngine) {
|
|
31
|
+
this.db = db;
|
|
32
|
+
this.goalEngine = goalEngine;
|
|
33
|
+
runRoadmapMigration(db);
|
|
34
|
+
}
|
|
35
|
+
setThoughtStream(stream) { this.ts = stream; }
|
|
36
|
+
// ── Roadmap CRUD ──────────────────────────────────────
|
|
37
|
+
/** Create a new research roadmap with a final goal. */
|
|
38
|
+
createRoadmap(title, finalGoalId) {
|
|
39
|
+
const result = this.db.prepare('INSERT INTO research_roadmaps (title, final_goal_id) VALUES (?, ?)').run(title, finalGoalId);
|
|
40
|
+
const id = Number(result.lastInsertRowid);
|
|
41
|
+
// Tag the final goal with roadmap_id
|
|
42
|
+
this.db.prepare('UPDATE goals SET roadmap_id = ? WHERE id = ?').run(id, finalGoalId);
|
|
43
|
+
this.log.info(`[roadmap] Created roadmap #${id}: ${title}`);
|
|
44
|
+
this.ts?.emit('roadmap', 'reflecting', `New roadmap: ${title}`, 'notable');
|
|
45
|
+
return this.getRoadmap(id);
|
|
46
|
+
}
|
|
47
|
+
getRoadmap(id) {
|
|
48
|
+
const row = this.db.prepare('SELECT * FROM research_roadmaps WHERE id = ?').get(id);
|
|
49
|
+
if (!row)
|
|
50
|
+
return null;
|
|
51
|
+
return {
|
|
52
|
+
id: row.id,
|
|
53
|
+
title: row.title,
|
|
54
|
+
finalGoalId: row.final_goal_id,
|
|
55
|
+
status: row.status,
|
|
56
|
+
createdAt: row.created_at,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
listRoadmaps(status) {
|
|
60
|
+
const query = status
|
|
61
|
+
? 'SELECT * FROM research_roadmaps WHERE status = ? ORDER BY id DESC'
|
|
62
|
+
: 'SELECT * FROM research_roadmaps ORDER BY id DESC';
|
|
63
|
+
const rows = (status
|
|
64
|
+
? this.db.prepare(query).all(status)
|
|
65
|
+
: this.db.prepare(query).all());
|
|
66
|
+
return rows.map(r => ({
|
|
67
|
+
id: r.id,
|
|
68
|
+
title: r.title,
|
|
69
|
+
finalGoalId: r.final_goal_id,
|
|
70
|
+
status: r.status,
|
|
71
|
+
createdAt: r.created_at,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
// ── Goal Dependencies ─────────────────────────────────
|
|
75
|
+
/** Check if a goal can start (all dependencies achieved). */
|
|
76
|
+
canStart(goalId) {
|
|
77
|
+
const deps = this.getDependencies(goalId);
|
|
78
|
+
if (deps.length === 0)
|
|
79
|
+
return true;
|
|
80
|
+
for (const depId of deps) {
|
|
81
|
+
const goal = this.goalEngine.getGoal(depId);
|
|
82
|
+
if (!goal || goal.status !== 'achieved')
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
/** Get goals that are ready to start (no unmet dependencies). */
|
|
88
|
+
getReadyGoals() {
|
|
89
|
+
const active = this.goalEngine.listGoals('active');
|
|
90
|
+
return active.filter(g => this.canStart(g.id));
|
|
91
|
+
}
|
|
92
|
+
/** Get dependencies for a goal. */
|
|
93
|
+
getDependencies(goalId) {
|
|
94
|
+
const row = this.db.prepare('SELECT depends_on FROM goals WHERE id = ?').get(goalId);
|
|
95
|
+
if (!row)
|
|
96
|
+
return [];
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(row.depends_on);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Set dependencies for a goal. */
|
|
105
|
+
setDependencies(goalId, deps) {
|
|
106
|
+
this.db.prepare('UPDATE goals SET depends_on = ? WHERE id = ?').run(JSON.stringify(deps), goalId);
|
|
107
|
+
}
|
|
108
|
+
// ── Decompose ──────────────────────────────────────────
|
|
109
|
+
/** Decompose a goal into sub-goals using heuristic rules. */
|
|
110
|
+
decompose(goal, currentCycle) {
|
|
111
|
+
const subGoals = [];
|
|
112
|
+
const baseDeadline = Math.floor(goal.deadlineCycles / 3);
|
|
113
|
+
// Phase 1: Data gathering (baseline)
|
|
114
|
+
subGoals.push({
|
|
115
|
+
title: `Daten sammeln für: ${goal.metricName}`,
|
|
116
|
+
metricName: `${goal.metricName}_data_points`,
|
|
117
|
+
targetValue: 10,
|
|
118
|
+
deadlineCycles: baseDeadline,
|
|
119
|
+
description: `Ausreichend Datenpunkte für ${goal.title} sammeln`,
|
|
120
|
+
type: 'discovery',
|
|
121
|
+
dependsOn: [],
|
|
122
|
+
});
|
|
123
|
+
// Phase 2: Hypothesis generation
|
|
124
|
+
subGoals.push({
|
|
125
|
+
title: `Hypothesen für: ${goal.metricName}`,
|
|
126
|
+
metricName: `${goal.metricName}_hypotheses`,
|
|
127
|
+
targetValue: 3,
|
|
128
|
+
deadlineCycles: baseDeadline * 2,
|
|
129
|
+
description: `Testbare Hypothesen für ${goal.title} aufstellen`,
|
|
130
|
+
type: 'discovery',
|
|
131
|
+
dependsOn: [0], // depends on phase 1
|
|
132
|
+
});
|
|
133
|
+
// Phase 3: Achievement of the actual goal
|
|
134
|
+
subGoals.push({
|
|
135
|
+
title: `Ziel erreichen: ${goal.title}`,
|
|
136
|
+
metricName: goal.metricName,
|
|
137
|
+
targetValue: goal.targetValue,
|
|
138
|
+
deadlineCycles: goal.deadlineCycles,
|
|
139
|
+
description: `${goal.description} — nach Datenbasis und Hypothesen`,
|
|
140
|
+
type: goal.type,
|
|
141
|
+
dependsOn: [1], // depends on phase 2
|
|
142
|
+
});
|
|
143
|
+
// Create a roadmap
|
|
144
|
+
const roadmap = this.createRoadmap(`Roadmap: ${goal.title}`, goal.id);
|
|
145
|
+
// Create sub-goals and resolve dependency indices to IDs
|
|
146
|
+
const createdIds = [];
|
|
147
|
+
for (const sg of subGoals) {
|
|
148
|
+
const resolvedDeps = sg.dependsOn.map(idx => createdIds[idx]).filter(id => id !== undefined);
|
|
149
|
+
const created = this.goalEngine.createGoal(sg.title, sg.metricName, sg.targetValue, sg.deadlineCycles, {
|
|
150
|
+
description: sg.description,
|
|
151
|
+
type: sg.type,
|
|
152
|
+
currentCycle,
|
|
153
|
+
});
|
|
154
|
+
createdIds.push(created.id);
|
|
155
|
+
// Set dependencies and roadmap
|
|
156
|
+
this.setDependencies(created.id, resolvedDeps);
|
|
157
|
+
this.db.prepare('UPDATE goals SET roadmap_id = ? WHERE id = ?').run(roadmap.id, created.id);
|
|
158
|
+
}
|
|
159
|
+
this.log.info(`[roadmap] Decomposed goal #${goal.id} into ${createdIds.length} sub-goals`);
|
|
160
|
+
this.ts?.emit('roadmap', 'reflecting', `Decomposed "${goal.title}" into ${createdIds.length} phases`, 'notable');
|
|
161
|
+
return createdIds.map(id => this.goalEngine.getGoal(id)).filter(g => g !== null);
|
|
162
|
+
}
|
|
163
|
+
// ── DAG Visualization ─────────────────────────────────
|
|
164
|
+
/** Build a DAG representation for dashboard visualization. */
|
|
165
|
+
toDAG(roadmapId) {
|
|
166
|
+
const goals = this.db.prepare('SELECT * FROM goals WHERE roadmap_id = ? ORDER BY id ASC').all(roadmapId);
|
|
167
|
+
const nodes = goals.map(g => {
|
|
168
|
+
const progress = g.target_value > 0
|
|
169
|
+
? Math.min(100, (g.current_value / g.target_value) * 100)
|
|
170
|
+
: 0;
|
|
171
|
+
return {
|
|
172
|
+
id: g.id,
|
|
173
|
+
title: g.title,
|
|
174
|
+
status: g.status,
|
|
175
|
+
metricName: g.metric_name,
|
|
176
|
+
targetValue: g.target_value,
|
|
177
|
+
currentValue: g.current_value,
|
|
178
|
+
progress,
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
const edges = [];
|
|
182
|
+
for (const g of goals) {
|
|
183
|
+
try {
|
|
184
|
+
const deps = JSON.parse(g.depends_on);
|
|
185
|
+
for (const dep of deps) {
|
|
186
|
+
edges.push({ from: dep, to: g.id });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch { /* empty */ }
|
|
190
|
+
}
|
|
191
|
+
return { nodes, edges };
|
|
192
|
+
}
|
|
193
|
+
// ── Progress ───────────────────────────────────────────
|
|
194
|
+
/** Get overall roadmap progress. */
|
|
195
|
+
getProgress(roadmapId) {
|
|
196
|
+
const roadmap = this.getRoadmap(roadmapId);
|
|
197
|
+
if (!roadmap) {
|
|
198
|
+
return {
|
|
199
|
+
roadmapId,
|
|
200
|
+
title: 'Unknown',
|
|
201
|
+
totalGoals: 0,
|
|
202
|
+
completedGoals: 0,
|
|
203
|
+
activeGoals: 0,
|
|
204
|
+
blockedGoals: 0,
|
|
205
|
+
progressPercent: 0,
|
|
206
|
+
status: 'unknown',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const goals = this.db.prepare('SELECT * FROM goals WHERE roadmap_id = ?').all(roadmapId);
|
|
210
|
+
const total = goals.length;
|
|
211
|
+
const completed = goals.filter(g => g.status === 'achieved').length;
|
|
212
|
+
const active = goals.filter(g => g.status === 'active').length;
|
|
213
|
+
const blocked = goals.filter(g => g.status === 'active' && !this.canStart(g.id)).length;
|
|
214
|
+
// Auto-complete roadmap if all goals achieved
|
|
215
|
+
if (total > 0 && completed === total && roadmap.status === 'active') {
|
|
216
|
+
this.db.prepare("UPDATE research_roadmaps SET status = 'completed' WHERE id = ?").run(roadmapId);
|
|
217
|
+
roadmap.status = 'completed';
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
roadmapId,
|
|
221
|
+
title: roadmap.title,
|
|
222
|
+
totalGoals: total,
|
|
223
|
+
completedGoals: completed,
|
|
224
|
+
activeGoals: active,
|
|
225
|
+
blockedGoals: blocked,
|
|
226
|
+
progressPercent: total > 0 ? Math.round((completed / total) * 100) : 0,
|
|
227
|
+
status: roadmap.status,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=research-roadmap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-roadmap.js","sourceRoot":"","sources":["../../src/goals/research-roadmap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAsD/C,2DAA2D;AAE3D,MAAM,UAAU,mBAAmB,CAAC,EAAqB;IACvD,EAAE,CAAC,IAAI,CAAC;;;;;;;;;GASP,CAAC,CAAC;IAEH,6CAA6C;IAC7C,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,GAAW,EAAE,EAAE;QAC3D,IAAI,CAAC;YACH,EAAE,CAAC,IAAI,CAAC,gCAAgC,GAAG,IAAI,IAAI,qBAAqB,GAAG,EAAE,CAAC,CAAC;QACjF,CAAC;QAAC,M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,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,UAAU,EAAE,KAAK;YACjB,cAAc,EAAE,SAAS;YACzB,WAAW,EAAE,MAAM;YACnB,YAAY,EAAE,OAAO;YACrB,eAAe,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACtE,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { ParameterRegistry } from '../metacognition/parameter-registry.js';
|
|
3
|
+
import type { GoalEngine } from '../goals/goal-engine.js';
|
|
4
|
+
import type { ThoughtStream } from '../consciousness/thought-stream.js';
|
|
5
|
+
export interface GuardrailConfig {
|
|
6
|
+
brainName: string;
|
|
7
|
+
/** Minimum fitness improvement to accept a parameter change. Default: 0.01 */
|
|
8
|
+
minFitnessDelta?: number;
|
|
9
|
+
/** Number of declining generations before auto-rollback. Default: 3 */
|
|
10
|
+
declineThreshold?: number;
|
|
11
|
+
/** Max warnings before tripping circuit breaker. Default: 3 */
|
|
12
|
+
maxWarnings?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ValidationResult {
|
|
15
|
+
allowed: boolean;
|
|
16
|
+
reason: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RollbackResult {
|
|
19
|
+
rolledBack: number;
|
|
20
|
+
parameters: Array<{
|
|
21
|
+
param: string;
|
|
22
|
+
from: number;
|
|
23
|
+
to: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export interface HealthWarning {
|
|
27
|
+
category: string;
|
|
28
|
+
message: string;
|
|
29
|
+
severity: 'low' | 'medium' | 'high';
|
|
30
|
+
}
|
|
31
|
+
export interface HealthReport {
|
|
32
|
+
score: number;
|
|
33
|
+
warnings: HealthWarning[];
|
|
34
|
+
circuitBreakerTripped: boolean;
|
|
35
|
+
recommendation: string;
|
|
36
|
+
}
|
|
37
|
+
export interface GuardrailStatus {
|
|
38
|
+
circuitBreakerTripped: boolean;
|
|
39
|
+
circuitBreakerReason: string | null;
|
|
40
|
+
totalRollbacks: number;
|
|
41
|
+
recentChanges: number;
|
|
42
|
+
healthScore: number;
|
|
43
|
+
protectedPaths: string[];
|
|
44
|
+
}
|
|
45
|
+
export declare function runGuardrailMigration(db: Database.Database): void;
|
|
46
|
+
export declare class GuardrailEngine {
|
|
47
|
+
private readonly db;
|
|
48
|
+
private readonly config;
|
|
49
|
+
private readonly log;
|
|
50
|
+
private registry;
|
|
51
|
+
private goalEngine;
|
|
52
|
+
private ts;
|
|
53
|
+
private circuitBreakerTripped;
|
|
54
|
+
private circuitBreakerReason;
|
|
55
|
+
constructor(db: Database.Database, config: GuardrailConfig);
|
|
56
|
+
setParameterRegistry(registry: ParameterRegistry): void;
|
|
57
|
+
setGoalEngine(engine: GoalEngine): void;
|
|
58
|
+
setThoughtStream(stream: ThoughtStream): void;
|
|
59
|
+
/** Check if a parameter change is within safe bounds. */
|
|
60
|
+
validateParameterChange(param: string, oldVal: number, newVal: number): ValidationResult;
|
|
61
|
+
/** Only accept if fitness improved by at least minDelta. */
|
|
62
|
+
checkFitnessDelta(oldFitness: number, newFitness: number, minDelta?: number): boolean;
|
|
63
|
+
/** Check if a file path is protected from self-modification. */
|
|
64
|
+
isProtectedPath(filePath: string): boolean;
|
|
65
|
+
/** Get list of protected path patterns. */
|
|
66
|
+
getProtectedPaths(): string[];
|
|
67
|
+
/** Record a parameter change for audit trail. */
|
|
68
|
+
recordParameterChange(param: string, oldValue: number, newValue: number, fitnessBefore?: number, fitnessAfter?: number, generation?: number, source?: string): void;
|
|
69
|
+
/** Rollback the last N parameter changes. */
|
|
70
|
+
rollbackParameters(steps?: number): RollbackResult;
|
|
71
|
+
/** Check if fitness has been declining for N generations and auto-rollback if so. */
|
|
72
|
+
checkAutoRollback(): RollbackResult | null;
|
|
73
|
+
/** Comprehensive health check. */
|
|
74
|
+
checkHealth(): HealthReport;
|
|
75
|
+
/** Trip the circuit breaker — pauses evolution + selfmod. */
|
|
76
|
+
tripCircuitBreaker(reason: string): void;
|
|
77
|
+
/** Check if circuit breaker is tripped. */
|
|
78
|
+
isCircuitBreakerTripped(): boolean;
|
|
79
|
+
/** Reset circuit breaker (manual action). */
|
|
80
|
+
resetCircuitBreaker(): void;
|
|
81
|
+
getStatus(): GuardrailStatus;
|
|
82
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Protected Paths ──────────────────────────────────────
|
|
3
|
+
const PROTECTED_PATHS = [
|
|
4
|
+
'src/ipc/',
|
|
5
|
+
'src/llm/provider.ts',
|
|
6
|
+
'src/llm/middleware.ts',
|
|
7
|
+
'src/guardrails/',
|
|
8
|
+
'src/db/',
|
|
9
|
+
'migrations/',
|
|
10
|
+
];
|
|
11
|
+
// ── Migration ───────────────────────────────────────────
|
|
12
|
+
export function runGuardrailMigration(db) {
|
|
13
|
+
db.exec(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS parameter_changelog (
|
|
15
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
16
|
+
param TEXT NOT NULL,
|
|
17
|
+
old_value REAL NOT NULL,
|
|
18
|
+
new_value REAL NOT NULL,
|
|
19
|
+
fitness_before REAL,
|
|
20
|
+
fitness_after REAL,
|
|
21
|
+
generation INTEGER,
|
|
22
|
+
source TEXT DEFAULT 'evolution',
|
|
23
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
24
|
+
);
|
|
25
|
+
CREATE INDEX IF NOT EXISTS idx_param_changelog_param ON parameter_changelog(param);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS idx_param_changelog_gen ON parameter_changelog(generation);
|
|
27
|
+
|
|
28
|
+
CREATE TABLE IF NOT EXISTS circuit_breaker_log (
|
|
29
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
+
tripped INTEGER NOT NULL DEFAULT 0,
|
|
31
|
+
reason TEXT,
|
|
32
|
+
warnings TEXT,
|
|
33
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
34
|
+
);
|
|
35
|
+
`);
|
|
36
|
+
}
|
|
37
|
+
// ── Engine ──────────────────────────────────────────────
|
|
38
|
+
export class GuardrailEngine {
|
|
39
|
+
db;
|
|
40
|
+
config;
|
|
41
|
+
log = getLogger();
|
|
42
|
+
registry = null;
|
|
43
|
+
goalEngine = null;
|
|
44
|
+
ts = null;
|
|
45
|
+
circuitBreakerTripped = false;
|
|
46
|
+
circuitBreakerReason = null;
|
|
47
|
+
constructor(db, config) {
|
|
48
|
+
this.db = db;
|
|
49
|
+
this.config = {
|
|
50
|
+
brainName: config.brainName,
|
|
51
|
+
minFitnessDelta: config.minFitnessDelta ?? 0.01,
|
|
52
|
+
declineThreshold: config.declineThreshold ?? 3,
|
|
53
|
+
maxWarnings: config.maxWarnings ?? 3,
|
|
54
|
+
};
|
|
55
|
+
runGuardrailMigration(db);
|
|
56
|
+
}
|
|
57
|
+
setParameterRegistry(registry) { this.registry = registry; }
|
|
58
|
+
setGoalEngine(engine) { this.goalEngine = engine; }
|
|
59
|
+
setThoughtStream(stream) { this.ts = stream; }
|
|
60
|
+
// ── Parameter Validation ────────────────────────────────
|
|
61
|
+
/** Check if a parameter change is within safe bounds. */
|
|
62
|
+
validateParameterChange(param, oldVal, newVal) {
|
|
63
|
+
if (this.circuitBreakerTripped) {
|
|
64
|
+
return { allowed: false, reason: `Circuit breaker tripped: ${this.circuitBreakerReason}` };
|
|
65
|
+
}
|
|
66
|
+
// Reject no-ops
|
|
67
|
+
if (oldVal === newVal) {
|
|
68
|
+
return { allowed: true, reason: 'No change' };
|
|
69
|
+
}
|
|
70
|
+
// Check parameter bounds and change magnitude
|
|
71
|
+
if (this.registry) {
|
|
72
|
+
const params = this.registry.list();
|
|
73
|
+
const [engine, name] = param.split(':');
|
|
74
|
+
const def = params.find(p => p.engine === engine && p.name === name);
|
|
75
|
+
if (def) {
|
|
76
|
+
// Reject out-of-bounds first
|
|
77
|
+
if (newVal < def.min || newVal > def.max) {
|
|
78
|
+
return { allowed: false, reason: `Value ${newVal} out of bounds [${def.min}, ${def.max}]` };
|
|
79
|
+
}
|
|
80
|
+
// Reject extreme jumps (>50% of range in one step)
|
|
81
|
+
const range = def.max - def.min;
|
|
82
|
+
const delta = Math.abs(newVal - oldVal);
|
|
83
|
+
if (range > 0 && delta > range * 0.5) {
|
|
84
|
+
return { allowed: false, reason: `Change too large: ${delta.toFixed(4)} > 50% of range (${range.toFixed(4)})` };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { allowed: true, reason: 'OK' };
|
|
89
|
+
}
|
|
90
|
+
// ── Fitness Delta ──────────────────────────────────────
|
|
91
|
+
/** Only accept if fitness improved by at least minDelta. */
|
|
92
|
+
checkFitnessDelta(oldFitness, newFitness, minDelta) {
|
|
93
|
+
const threshold = minDelta ?? this.config.minFitnessDelta;
|
|
94
|
+
return newFitness - oldFitness >= threshold;
|
|
95
|
+
}
|
|
96
|
+
// ── Protected Paths ─────────────────────────────────────
|
|
97
|
+
/** Check if a file path is protected from self-modification. */
|
|
98
|
+
isProtectedPath(filePath) {
|
|
99
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
100
|
+
return PROTECTED_PATHS.some(p => normalized.includes(p));
|
|
101
|
+
}
|
|
102
|
+
/** Get list of protected path patterns. */
|
|
103
|
+
getProtectedPaths() {
|
|
104
|
+
return [...PROTECTED_PATHS];
|
|
105
|
+
}
|
|
106
|
+
// ── Parameter Changelog ─────────────────────────────────
|
|
107
|
+
/** Record a parameter change for audit trail. */
|
|
108
|
+
recordParameterChange(param, oldValue, newValue, fitnessBefore, fitnessAfter, generation, source = 'evolution') {
|
|
109
|
+
this.db.prepare(`
|
|
110
|
+
INSERT INTO parameter_changelog (param, old_value, new_value, fitness_before, fitness_after, generation, source)
|
|
111
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
112
|
+
`).run(param, oldValue, newValue, fitnessBefore ?? null, fitnessAfter ?? null, generation ?? null, source);
|
|
113
|
+
}
|
|
114
|
+
/** Rollback the last N parameter changes. */
|
|
115
|
+
rollbackParameters(steps = 1) {
|
|
116
|
+
const changes = this.db.prepare('SELECT * FROM parameter_changelog ORDER BY id DESC LIMIT ?').all(steps);
|
|
117
|
+
const result = { rolledBack: 0, parameters: [] };
|
|
118
|
+
for (const change of changes) {
|
|
119
|
+
if (this.registry) {
|
|
120
|
+
const [engine, name] = change.param.split(':');
|
|
121
|
+
if (engine && name) {
|
|
122
|
+
this.registry.set(engine, name, change.old_value, 'guardrail-rollback', 'Auto-rollback');
|
|
123
|
+
result.parameters.push({
|
|
124
|
+
param: change.param,
|
|
125
|
+
from: change.new_value,
|
|
126
|
+
to: change.old_value,
|
|
127
|
+
});
|
|
128
|
+
result.rolledBack++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (result.rolledBack > 0) {
|
|
133
|
+
this.log.info(`[guardrails] Rolled back ${result.rolledBack} parameter changes`);
|
|
134
|
+
this.ts?.emit('guardrails', 'reflecting', `Rolled back ${result.rolledBack} parameter changes`, 'notable');
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
// ── Auto-Rollback Detection ────────────────────────────
|
|
139
|
+
/** Check if fitness has been declining for N generations and auto-rollback if so. */
|
|
140
|
+
checkAutoRollback() {
|
|
141
|
+
const rows = this.db.prepare('SELECT generation, fitness_after FROM parameter_changelog WHERE fitness_after IS NOT NULL AND generation IS NOT NULL ORDER BY id DESC LIMIT ?').all(this.config.declineThreshold + 1);
|
|
142
|
+
if (rows.length < this.config.declineThreshold + 1)
|
|
143
|
+
return null;
|
|
144
|
+
// Check if each generation's fitness is lower than the previous
|
|
145
|
+
let declining = true;
|
|
146
|
+
for (let i = 0; i < rows.length - 1; i++) {
|
|
147
|
+
if (rows[i].fitness_after >= rows[i + 1].fitness_after) {
|
|
148
|
+
declining = false;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (declining) {
|
|
153
|
+
this.log.warn(`[guardrails] Fitness declining for ${this.config.declineThreshold} generations — auto-rollback`);
|
|
154
|
+
this.ts?.emit('guardrails', 'reflecting', `Auto-rollback: fitness declined ${this.config.declineThreshold} generations`, 'notable');
|
|
155
|
+
// Rollback all changes from the declining generations
|
|
156
|
+
return this.rollbackParameters(this.config.declineThreshold);
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
// ── Health Check ───────────────────────────────────────
|
|
161
|
+
/** Comprehensive health check. */
|
|
162
|
+
checkHealth() {
|
|
163
|
+
const warnings = [];
|
|
164
|
+
// 1. Check goal stagnation
|
|
165
|
+
if (this.goalEngine) {
|
|
166
|
+
try {
|
|
167
|
+
const status = this.goalEngine.getStatus();
|
|
168
|
+
if (status.activeGoals > 0 && status.achievedGoals === 0 && status.totalGoals > 5) {
|
|
169
|
+
warnings.push({
|
|
170
|
+
category: 'goals',
|
|
171
|
+
message: `${status.activeGoals} active goals but 0 achieved — progress stagnant`,
|
|
172
|
+
severity: 'medium',
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch { /* engine not available */ }
|
|
177
|
+
}
|
|
178
|
+
// 2. Check fitness trend (last 5 changes)
|
|
179
|
+
try {
|
|
180
|
+
const recent = this.db.prepare('SELECT fitness_after FROM parameter_changelog WHERE fitness_after IS NOT NULL ORDER BY id DESC LIMIT 5').all();
|
|
181
|
+
if (recent.length >= 3) {
|
|
182
|
+
const firstFitness = recent[recent.length - 1].fitness_after;
|
|
183
|
+
const lastFitness = recent[0].fitness_after;
|
|
184
|
+
if (lastFitness < firstFitness * 0.8) {
|
|
185
|
+
warnings.push({
|
|
186
|
+
category: 'fitness',
|
|
187
|
+
message: `Fitness dropped ${((1 - lastFitness / firstFitness) * 100).toFixed(1)}% over last ${recent.length} changes`,
|
|
188
|
+
severity: 'high',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch { /* table empty */ }
|
|
194
|
+
// 3. Check parameter change frequency (too many changes = instability)
|
|
195
|
+
try {
|
|
196
|
+
const recentCount = this.db.prepare("SELECT COUNT(*) as cnt FROM parameter_changelog WHERE created_at > datetime('now', '-1 hour')").get().cnt;
|
|
197
|
+
if (recentCount > 20) {
|
|
198
|
+
warnings.push({
|
|
199
|
+
category: 'stability',
|
|
200
|
+
message: `${recentCount} parameter changes in the last hour — high instability`,
|
|
201
|
+
severity: 'medium',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch { /* empty */ }
|
|
206
|
+
// 4. Check memory/DB size (pragmatic check)
|
|
207
|
+
try {
|
|
208
|
+
const memUsage = process.memoryUsage();
|
|
209
|
+
const heapUsedMB = memUsage.heapUsed / (1024 * 1024);
|
|
210
|
+
if (heapUsedMB > 512) {
|
|
211
|
+
warnings.push({
|
|
212
|
+
category: 'memory',
|
|
213
|
+
message: `Heap usage at ${heapUsedMB.toFixed(0)}MB — consider restart`,
|
|
214
|
+
severity: heapUsedMB > 1024 ? 'high' : 'medium',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch { /* empty */ }
|
|
219
|
+
// Calculate health score
|
|
220
|
+
const severityWeights = { low: 0.1, medium: 0.25, high: 0.4 };
|
|
221
|
+
const penalty = warnings.reduce((sum, w) => sum + severityWeights[w.severity], 0);
|
|
222
|
+
const score = Math.max(0, Math.min(1, 1 - penalty));
|
|
223
|
+
// Trip circuit breaker if too many warnings
|
|
224
|
+
const highWarnings = warnings.filter(w => w.severity === 'high').length;
|
|
225
|
+
if (warnings.length >= this.config.maxWarnings || highWarnings >= 2) {
|
|
226
|
+
if (!this.circuitBreakerTripped) {
|
|
227
|
+
const reason = `Health check: ${warnings.length} warnings (${highWarnings} high)`;
|
|
228
|
+
this.tripCircuitBreaker(reason);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const recommendation = warnings.length === 0
|
|
232
|
+
? 'All systems nominal'
|
|
233
|
+
: warnings.length < this.config.maxWarnings
|
|
234
|
+
? 'Minor issues detected — monitoring'
|
|
235
|
+
: 'Critical issues — autonomous operations paused';
|
|
236
|
+
return {
|
|
237
|
+
score,
|
|
238
|
+
warnings,
|
|
239
|
+
circuitBreakerTripped: this.circuitBreakerTripped,
|
|
240
|
+
recommendation,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// ── Circuit Breaker ────────────────────────────────────
|
|
244
|
+
/** Trip the circuit breaker — pauses evolution + selfmod. */
|
|
245
|
+
tripCircuitBreaker(reason) {
|
|
246
|
+
this.circuitBreakerTripped = true;
|
|
247
|
+
this.circuitBreakerReason = reason;
|
|
248
|
+
this.db.prepare('INSERT INTO circuit_breaker_log (tripped, reason) VALUES (1, ?)').run(reason);
|
|
249
|
+
this.log.warn(`[guardrails] Circuit breaker TRIPPED: ${reason}`);
|
|
250
|
+
this.ts?.emit('guardrails', 'reflecting', `CIRCUIT BREAKER: ${reason}`, 'breakthrough');
|
|
251
|
+
}
|
|
252
|
+
/** Check if circuit breaker is tripped. */
|
|
253
|
+
isCircuitBreakerTripped() {
|
|
254
|
+
return this.circuitBreakerTripped;
|
|
255
|
+
}
|
|
256
|
+
/** Reset circuit breaker (manual action). */
|
|
257
|
+
resetCircuitBreaker() {
|
|
258
|
+
this.circuitBreakerTripped = false;
|
|
259
|
+
this.circuitBreakerReason = null;
|
|
260
|
+
this.db.prepare('INSERT INTO circuit_breaker_log (tripped, reason) VALUES (0, ?)').run('Manual reset');
|
|
261
|
+
this.log.info('[guardrails] Circuit breaker reset');
|
|
262
|
+
this.ts?.emit('guardrails', 'reflecting', 'Circuit breaker reset', 'notable');
|
|
263
|
+
}
|
|
264
|
+
// ── Status ─────────────────────────────────────────────
|
|
265
|
+
getStatus() {
|
|
266
|
+
const totalRollbacks = this.db.prepare("SELECT COUNT(*) as cnt FROM parameter_changelog WHERE source = 'guardrail-rollback'").get().cnt;
|
|
267
|
+
const recentChanges = this.db.prepare("SELECT COUNT(*) as cnt FROM parameter_changelog WHERE created_at > datetime('now', '-1 hour')").get().cnt;
|
|
268
|
+
const health = this.checkHealth();
|
|
269
|
+
return {
|
|
270
|
+
circuitBreakerTripped: this.circuitBreakerTripped,
|
|
271
|
+
circuitBreakerReason: this.circuitBreakerReason,
|
|
272
|
+
totalRollbacks,
|
|
273
|
+
recentChanges,
|
|
274
|
+
healthScore: health.score,
|
|
275
|
+
protectedPaths: this.getProtectedPaths(),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=guardrail-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardrail-engine.js","sourceRoot":"","sources":["../../src/guardrails/guardrail-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAiD/C,4DAA4D;AAE5D,MAAM,eAAe,GAAG;IACtB,UAAU;IACV,qBAAqB;IACrB,uBAAuB;IACvB,iBAAiB;IACjB,SAAS;IACT,aAAa;CACd,CAAC;AAEF,2DAA2D;AAE3D,MAAM,UAAU,qBAAqB,CAAC,EAAqB;IACzD,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;GAsBP,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAE3D,MAAM,OAAO,eAAe;IACT,EAAE,CAAoB;IACtB,MAAM,CAA4B;IAClC,GAAG,GAAG,SAAS,EAAE,CAAC;IAC3B,QAAQ,GAA6B,IAAI,CAAC;IAC1C,UAAU,GAAsB,IAAI,CAAC;IACrC,EAAE,GAAyB,IAAI,CAAC;IAChC,qBAAqB,GAAG,KAAK,CAAC;IAC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