@timmeck/brain-core 2.36.64 → 2.36.66
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/README.md +6 -2
- package/command-center.html +59 -2
- package/dist/dashboard/command-center-server.d.ts +1 -0
- package/dist/dashboard/command-center-server.js +13 -1
- package/dist/dashboard/command-center-server.js.map +1 -1
- package/dist/dream/consolidator.js +2 -2
- package/dist/dream/dream-engine.d.ts +4 -0
- package/dist/dream/dream-engine.js +28 -3
- package/dist/dream/dream-engine.js.map +1 -1
- package/dist/dream/types.d.ts +5 -5
- package/dist/governance/engine-registry.d.ts +61 -0
- package/dist/governance/engine-registry.js +301 -0
- package/dist/governance/engine-registry.js.map +1 -0
- package/dist/governance/governance-layer.d.ts +75 -0
- package/dist/governance/governance-layer.js +231 -0
- package/dist/governance/governance-layer.js.map +1 -0
- package/dist/governance/index.d.ts +8 -0
- package/dist/governance/index.js +5 -0
- package/dist/governance/index.js.map +1 -0
- package/dist/governance/loop-detector.d.ts +46 -0
- package/dist/governance/loop-detector.js +266 -0
- package/dist/governance/loop-detector.js.map +1 -0
- package/dist/governance/runtime-influence-tracker.d.ts +50 -0
- package/dist/governance/runtime-influence-tracker.js +163 -0
- package/dist/governance/runtime-influence-tracker.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/prediction/prediction-engine.js +1 -1
- package/dist/research/research-orchestrator.d.ts +12 -0
- package/dist/research/research-orchestrator.js +122 -0
- package/dist/research/research-orchestrator.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runEngineRegistryMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS engine_registry (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
reads_json TEXT NOT NULL DEFAULT '[]',
|
|
8
|
+
writes_json TEXT NOT NULL DEFAULT '[]',
|
|
9
|
+
emits_json TEXT NOT NULL DEFAULT '[]',
|
|
10
|
+
subscribes_json TEXT NOT NULL DEFAULT '[]',
|
|
11
|
+
frequency TEXT NOT NULL DEFAULT 'every_cycle',
|
|
12
|
+
frequency_n INTEGER NOT NULL DEFAULT 1,
|
|
13
|
+
risk_class TEXT NOT NULL DEFAULT 'low',
|
|
14
|
+
expected_effects_json TEXT NOT NULL DEFAULT '[]',
|
|
15
|
+
invariants_json TEXT NOT NULL DEFAULT '[]',
|
|
16
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
17
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
18
|
+
);
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
// ── Registry ────────────────────────────────────────────
|
|
22
|
+
export class EngineRegistry {
|
|
23
|
+
db;
|
|
24
|
+
cache = new Map();
|
|
25
|
+
log = getLogger();
|
|
26
|
+
constructor(db) {
|
|
27
|
+
this.db = db;
|
|
28
|
+
runEngineRegistryMigration(db);
|
|
29
|
+
this.loadAll();
|
|
30
|
+
}
|
|
31
|
+
/** Register or update an engine profile. */
|
|
32
|
+
register(profile) {
|
|
33
|
+
this.db.prepare(`
|
|
34
|
+
INSERT INTO engine_registry (id, reads_json, writes_json, emits_json, subscribes_json, frequency, frequency_n, risk_class, expected_effects_json, invariants_json, enabled, updated_at)
|
|
35
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))
|
|
36
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
37
|
+
reads_json = excluded.reads_json,
|
|
38
|
+
writes_json = excluded.writes_json,
|
|
39
|
+
emits_json = excluded.emits_json,
|
|
40
|
+
subscribes_json = excluded.subscribes_json,
|
|
41
|
+
frequency = excluded.frequency,
|
|
42
|
+
frequency_n = excluded.frequency_n,
|
|
43
|
+
risk_class = excluded.risk_class,
|
|
44
|
+
expected_effects_json = excluded.expected_effects_json,
|
|
45
|
+
invariants_json = excluded.invariants_json,
|
|
46
|
+
enabled = excluded.enabled,
|
|
47
|
+
updated_at = datetime('now')
|
|
48
|
+
`).run(profile.id, JSON.stringify(profile.reads), JSON.stringify(profile.writes), JSON.stringify(profile.emits), JSON.stringify(profile.subscribes), profile.frequency, profile.frequencyN, profile.riskClass, JSON.stringify(profile.expectedEffects), JSON.stringify(profile.invariants), profile.enabled ? 1 : 0);
|
|
49
|
+
this.cache.set(profile.id, { ...profile });
|
|
50
|
+
this.log.debug(`[engine-registry] Registered: ${profile.id} (risk=${profile.riskClass})`);
|
|
51
|
+
}
|
|
52
|
+
/** Get a single engine profile. */
|
|
53
|
+
get(id) {
|
|
54
|
+
return this.cache.get(id);
|
|
55
|
+
}
|
|
56
|
+
/** List all registered engine profiles. */
|
|
57
|
+
list() {
|
|
58
|
+
return [...this.cache.values()];
|
|
59
|
+
}
|
|
60
|
+
/** List only enabled engine profiles. */
|
|
61
|
+
listEnabled() {
|
|
62
|
+
return [...this.cache.values()].filter(p => p.enabled);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build a dependency graph: engine → engines it depends on.
|
|
66
|
+
* Engine A depends on Engine B if A.reads intersects B.writes.
|
|
67
|
+
*/
|
|
68
|
+
getDependencyGraph() {
|
|
69
|
+
const graph = new Map();
|
|
70
|
+
const profiles = this.list();
|
|
71
|
+
for (const consumer of profiles) {
|
|
72
|
+
const deps = [];
|
|
73
|
+
for (const producer of profiles) {
|
|
74
|
+
if (producer.id === consumer.id)
|
|
75
|
+
continue;
|
|
76
|
+
// Consumer reads what producer writes
|
|
77
|
+
const overlap = consumer.reads.some(r => producer.writes.includes(r));
|
|
78
|
+
if (overlap)
|
|
79
|
+
deps.push(producer.id);
|
|
80
|
+
}
|
|
81
|
+
graph.set(consumer.id, deps);
|
|
82
|
+
}
|
|
83
|
+
return graph;
|
|
84
|
+
}
|
|
85
|
+
/** Get reverse dependencies: engine → engines that depend on it. */
|
|
86
|
+
getReverseDependencyGraph() {
|
|
87
|
+
const forward = this.getDependencyGraph();
|
|
88
|
+
const reverse = new Map();
|
|
89
|
+
for (const id of this.cache.keys()) {
|
|
90
|
+
reverse.set(id, []);
|
|
91
|
+
}
|
|
92
|
+
for (const [consumer, deps] of forward) {
|
|
93
|
+
for (const dep of deps) {
|
|
94
|
+
const arr = reverse.get(dep);
|
|
95
|
+
if (arr)
|
|
96
|
+
arr.push(consumer);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return reverse;
|
|
100
|
+
}
|
|
101
|
+
/** Enable an engine. */
|
|
102
|
+
enable(id) {
|
|
103
|
+
const profile = this.cache.get(id);
|
|
104
|
+
if (!profile)
|
|
105
|
+
return;
|
|
106
|
+
profile.enabled = true;
|
|
107
|
+
this.db.prepare('UPDATE engine_registry SET enabled = 1, updated_at = datetime(\'now\') WHERE id = ?').run(id);
|
|
108
|
+
this.log.info(`[engine-registry] Enabled: ${id}`);
|
|
109
|
+
}
|
|
110
|
+
/** Disable an engine. */
|
|
111
|
+
disable(id) {
|
|
112
|
+
const profile = this.cache.get(id);
|
|
113
|
+
if (!profile)
|
|
114
|
+
return;
|
|
115
|
+
profile.enabled = false;
|
|
116
|
+
this.db.prepare('UPDATE engine_registry SET enabled = 0, updated_at = datetime(\'now\') WHERE id = ?').run(id);
|
|
117
|
+
this.log.info(`[engine-registry] Disabled: ${id}`);
|
|
118
|
+
}
|
|
119
|
+
/** Get overall status. */
|
|
120
|
+
getStatus() {
|
|
121
|
+
const profiles = this.list();
|
|
122
|
+
const enabled = profiles.filter(p => p.enabled).length;
|
|
123
|
+
const risk = { low: 0, medium: 0, high: 0 };
|
|
124
|
+
for (const p of profiles) {
|
|
125
|
+
risk[p.riskClass] = (risk[p.riskClass] || 0) + 1;
|
|
126
|
+
}
|
|
127
|
+
let edgeCount = 0;
|
|
128
|
+
for (const deps of this.getDependencyGraph().values()) {
|
|
129
|
+
edgeCount += deps.length;
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
totalEngines: profiles.length,
|
|
133
|
+
enabledEngines: enabled,
|
|
134
|
+
disabledEngines: profiles.length - enabled,
|
|
135
|
+
riskDistribution: risk,
|
|
136
|
+
dependencyEdges: edgeCount,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Find engines by risk class. */
|
|
140
|
+
getByRisk(riskClass) {
|
|
141
|
+
return this.list().filter(p => p.riskClass === riskClass);
|
|
142
|
+
}
|
|
143
|
+
/** Find engines that write to a specific resource. */
|
|
144
|
+
findWriters(resource) {
|
|
145
|
+
return this.list().filter(p => p.writes.includes(resource));
|
|
146
|
+
}
|
|
147
|
+
/** Find engines that read from a specific resource. */
|
|
148
|
+
findReaders(resource) {
|
|
149
|
+
return this.list().filter(p => p.reads.includes(resource));
|
|
150
|
+
}
|
|
151
|
+
// ── Private ─────────────────────────────────────────────
|
|
152
|
+
loadAll() {
|
|
153
|
+
const rows = this.db.prepare('SELECT * FROM engine_registry').all();
|
|
154
|
+
for (const row of rows) {
|
|
155
|
+
this.cache.set(row.id, {
|
|
156
|
+
id: row.id,
|
|
157
|
+
reads: JSON.parse(row.reads_json),
|
|
158
|
+
writes: JSON.parse(row.writes_json),
|
|
159
|
+
emits: JSON.parse(row.emits_json),
|
|
160
|
+
subscribes: JSON.parse(row.subscribes_json),
|
|
161
|
+
frequency: row.frequency,
|
|
162
|
+
frequencyN: row.frequency_n,
|
|
163
|
+
riskClass: row.risk_class,
|
|
164
|
+
expectedEffects: JSON.parse(row.expected_effects_json),
|
|
165
|
+
invariants: JSON.parse(row.invariants_json),
|
|
166
|
+
enabled: row.enabled === 1,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// ── Default Engine Profiles ─────────────────────────────
|
|
172
|
+
export function getDefaultEngineProfiles() {
|
|
173
|
+
return [
|
|
174
|
+
{
|
|
175
|
+
id: 'self_observer', reads: ['journal_entries', 'engine_metrics'], writes: ['self_observations', 'self_insights'],
|
|
176
|
+
emits: ['self_observer:reflecting'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
177
|
+
riskClass: 'low', expectedEffects: ['self-awareness improvement'], invariants: ['observations always non-negative'], enabled: true,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: 'adaptive_strategy', reads: ['strategies', 'experiment_results'], writes: ['strategies'],
|
|
181
|
+
emits: ['strategy:adapting'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
182
|
+
riskClass: 'medium', expectedEffects: ['strategy optimization'], invariants: ['at least one active strategy'], enabled: true,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: 'experiment_engine', reads: ['experiments', 'hypotheses'], writes: ['experiments', 'experiment_conclusions'],
|
|
186
|
+
emits: ['experiment:running'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
187
|
+
riskClass: 'medium', expectedEffects: ['hypothesis validation'], invariants: ['experiment count >= 0'], enabled: true,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: 'cross_domain', reads: ['insights', 'anomalies'], writes: ['cross_domain_correlations'],
|
|
191
|
+
emits: ['cross_domain:correlating'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
192
|
+
riskClass: 'low', expectedEffects: ['cross-domain correlation discovery'], invariants: [], enabled: true,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: 'knowledge_distiller', reads: ['insights', 'journal_entries', 'hypotheses'], writes: ['principles', 'anti_patterns', 'knowledge_strategies'],
|
|
196
|
+
emits: ['distiller:distilling'], subscribes: [], frequency: 'every_N', frequencyN: 5,
|
|
197
|
+
riskClass: 'low', expectedEffects: ['knowledge consolidation'], invariants: ['principles count non-decreasing'], enabled: true,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: 'anomaly_detective', reads: ['engine_metrics', 'insights'], writes: ['anomalies'],
|
|
201
|
+
emits: ['anomaly:detected'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
202
|
+
riskClass: 'low', expectedEffects: ['anomaly detection'], invariants: [], enabled: true,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: 'hypothesis_engine', reads: ['observations', 'insights'], writes: ['hypotheses'],
|
|
206
|
+
emits: ['hypothesis:testing'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
207
|
+
riskClass: 'low', expectedEffects: ['hypothesis generation and validation'], invariants: ['confidence in [0,1]'], enabled: true,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
id: 'causal_graph', reads: ['causal_events'], writes: ['causal_edges'],
|
|
211
|
+
emits: ['causal:discovering'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
212
|
+
riskClass: 'low', expectedEffects: ['causal relationship discovery'], invariants: ['edge strength in [0,1]'], enabled: true,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: 'prediction_engine', reads: ['engine_metrics', 'causal_edges'], writes: ['predictions'],
|
|
216
|
+
emits: ['prediction:forecasting'], subscribes: [], frequency: 'every_N', frequencyN: 3,
|
|
217
|
+
riskClass: 'medium', expectedEffects: ['metric forecasting', 'prediction accuracy improvement'], invariants: ['predictions have confidence'], enabled: true,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: 'dream_engine', reads: ['insights', 'synapses', 'journal_entries'], writes: ['dream_history', 'synapses'],
|
|
221
|
+
emits: ['dream:consolidating'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
222
|
+
riskClass: 'medium', expectedEffects: ['memory consolidation', 'synapse pruning'], invariants: ['synapse count stable after prune'], enabled: true,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: 'attention_engine', reads: ['engine_metrics', 'thoughts'], writes: ['attention_scores', 'context_switches'],
|
|
226
|
+
emits: ['attention:focusing'], subscribes: [], frequency: 'every_cycle', frequencyN: 1,
|
|
227
|
+
riskClass: 'low', expectedEffects: ['focus prioritization'], invariants: ['total weight = 1.0'], enabled: true,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: 'curiosity_engine', reads: ['knowledge_gaps', 'insights'], writes: ['knowledge_gaps', 'exploration_records'],
|
|
231
|
+
emits: ['curiosity:exploring'], subscribes: [], frequency: 'every_N', frequencyN: 5,
|
|
232
|
+
riskClass: 'low', expectedEffects: ['knowledge gap identification', 'exploration'], invariants: [], enabled: true,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: 'emergence_engine', reads: ['insights', 'synapses', 'causal_edges'], writes: ['emergence_events'],
|
|
236
|
+
emits: ['emergence:detecting'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
237
|
+
riskClass: 'low', expectedEffects: ['emergent pattern detection'], invariants: [], enabled: true,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: 'meta_cognition', reads: ['engine_metrics', 'engine_report_cards'], writes: ['engine_report_cards', 'frequency_adjustments'],
|
|
241
|
+
emits: ['metacognition:evaluating'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
242
|
+
riskClass: 'medium', expectedEffects: ['engine frequency optimization', 'performance grading'], invariants: ['grades in A-F range'], enabled: true,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: 'evolution_engine', reads: ['parameter_registry', 'engine_report_cards'], writes: ['evolution_individuals', 'evolution_generations', 'parameter_registry'],
|
|
246
|
+
emits: ['evolution:reflecting'], subscribes: [], frequency: 'every_N', frequencyN: 20,
|
|
247
|
+
riskClass: 'high', expectedEffects: ['parameter optimization', 'fitness improvement'], invariants: ['fitness >= 0', 'parameters within bounds'], enabled: true,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: 'narrative_engine', reads: ['journal_entries', 'insights', 'predictions'], writes: ['narratives', 'contradictions'],
|
|
251
|
+
emits: ['narrative:synthesizing'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
252
|
+
riskClass: 'low', expectedEffects: ['narrative coherence', 'contradiction detection'], invariants: [], enabled: true,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
id: 'reasoning_engine', reads: ['hypotheses', 'causal_edges', 'principles'], writes: ['inference_chains', 'abductive_explanations'],
|
|
256
|
+
emits: ['reasoning:inferring'], subscribes: [], frequency: 'every_N', frequencyN: 5,
|
|
257
|
+
riskClass: 'low', expectedEffects: ['logical inference', 'abductive reasoning'], invariants: [], enabled: true,
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
id: 'creative_engine', reads: ['principles', 'hypotheses', 'knowledge_distiller'], writes: ['creative_insights'],
|
|
261
|
+
emits: ['creative:pollinating'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
262
|
+
riskClass: 'low', expectedEffects: ['cross-domain idea generation', 'analogy discovery'], invariants: ['novelty_score in [0,1]'], enabled: true,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'action_bridge', reads: ['action_queue'], writes: ['action_queue', 'action_outcomes'],
|
|
266
|
+
emits: ['action:executing'], subscribes: [], frequency: 'every_N', frequencyN: 5,
|
|
267
|
+
riskClass: 'high', expectedEffects: ['autonomous action execution'], invariants: ['risk-assessed before execution'], enabled: true,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: 'content_forge', reads: ['creative_insights'], writes: ['content_pieces', 'content_engagement'],
|
|
271
|
+
emits: ['content:generating'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
272
|
+
riskClass: 'medium', expectedEffects: ['content generation from insights'], invariants: [], enabled: true,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
id: 'code_forge', reads: ['code_health_scans'], writes: ['code_patterns', 'code_products'],
|
|
276
|
+
emits: ['codeforge:extracting'], subscribes: [], frequency: 'every_N', frequencyN: 15,
|
|
277
|
+
riskClass: 'medium', expectedEffects: ['code pattern extraction'], invariants: [], enabled: true,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: 'strategy_forge', reads: ['principles', 'knowledge_distiller'], writes: ['strategies', 'strategy_rules'],
|
|
281
|
+
emits: ['strategy:executing'], subscribes: [], frequency: 'every_N', frequencyN: 20,
|
|
282
|
+
riskClass: 'high', expectedEffects: ['strategy creation and execution'], invariants: ['rule confidence in [0,1]'], enabled: true,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
id: 'guardrail_engine', reads: ['parameter_registry', 'goals'], writes: ['guardrail_changelog', 'health_reports'],
|
|
286
|
+
emits: ['guardrails:checking'], subscribes: [], frequency: 'every_N', frequencyN: 50,
|
|
287
|
+
riskClass: 'low', expectedEffects: ['parameter bounds enforcement', 'circuit breaker protection'], invariants: ['circuit breaker state consistent'], enabled: true,
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
id: 'debate_engine', reads: ['principles', 'hypotheses', 'journal_entries'], writes: ['debates'],
|
|
291
|
+
emits: ['debate:starting'], subscribes: [], frequency: 'every_N', frequencyN: 10,
|
|
292
|
+
riskClass: 'low', expectedEffects: ['multi-perspective analysis'], invariants: [], enabled: true,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'signal_router', reads: ['hypotheses', 'anomalies'], writes: ['cross_brain_signals'],
|
|
296
|
+
emits: ['signal:emitting'], subscribes: ['trade_signal', 'engagement_signal', 'research_insight'], frequency: 'every_N', frequencyN: 10,
|
|
297
|
+
riskClass: 'medium', expectedEffects: ['cross-brain signal propagation'], invariants: ['confidence in [0,1]'], enabled: true,
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=engine-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-registry.js","sourceRoot":"","sources":["../../src/governance/engine-registry.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA0B/C,2DAA2D;AAE3D,MAAM,UAAU,0BAA0B,CAAC,EAAqB;IAC9D,EAAE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iB,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;YAChF,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,4BAA4B,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI;SACjG;QACD;YACE,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,YAAY,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,qBAAqB,CAAC;YACxF,KAAK,EAAE,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,cAAc,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;YACvI,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,gCAAgC,CAAC,EAAE,UAAU,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,IAAI;SAC7H;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GovernanceLayer — Active engine control with throttle, cooldown, isolate, escalate, restore.
|
|
3
|
+
* Responds to LoopDetector findings and MetaCognition grades.
|
|
4
|
+
*/
|
|
5
|
+
import type Database from 'better-sqlite3';
|
|
6
|
+
import type { LoopDetector } from './loop-detector.js';
|
|
7
|
+
import type { EngineRegistry } from './engine-registry.js';
|
|
8
|
+
export type GovernanceActionType = 'throttle' | 'cooldown' | 'isolate' | 'escalate' | 'restore';
|
|
9
|
+
export interface GovernanceAction {
|
|
10
|
+
id: number;
|
|
11
|
+
engine: string;
|
|
12
|
+
actionType: GovernanceActionType;
|
|
13
|
+
reason: string;
|
|
14
|
+
source: string;
|
|
15
|
+
expiresAt: string | null;
|
|
16
|
+
active: boolean;
|
|
17
|
+
cycle: number;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GovernanceDecision {
|
|
21
|
+
engine: string;
|
|
22
|
+
action: GovernanceActionType;
|
|
23
|
+
reason: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GovernanceLayerStatus {
|
|
26
|
+
totalActions: number;
|
|
27
|
+
activeActions: number;
|
|
28
|
+
byType: Record<GovernanceActionType, number>;
|
|
29
|
+
throttledEngines: string[];
|
|
30
|
+
isolatedEngines: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare function runGovernanceMigration(db: Database.Database): void;
|
|
33
|
+
export declare class GovernanceLayer {
|
|
34
|
+
private db;
|
|
35
|
+
private log;
|
|
36
|
+
private loopDetector;
|
|
37
|
+
private engineRegistry;
|
|
38
|
+
private metaCognitionLayer;
|
|
39
|
+
private journalWriter;
|
|
40
|
+
constructor(db: Database.Database);
|
|
41
|
+
setLoopDetector(detector: LoopDetector): void;
|
|
42
|
+
setEngineRegistry(registry: EngineRegistry): void;
|
|
43
|
+
setMetaCognitionLayer(layer: {
|
|
44
|
+
evaluate: (windowCycles?: number) => Array<{
|
|
45
|
+
engine: string;
|
|
46
|
+
grade: string;
|
|
47
|
+
combined_score: number;
|
|
48
|
+
}>;
|
|
49
|
+
}): void;
|
|
50
|
+
setJournalWriter(writer: {
|
|
51
|
+
write: (entry: Record<string, unknown>) => void;
|
|
52
|
+
}): void;
|
|
53
|
+
/** Check if an engine should run this cycle. Respects throttle/cooldown/isolate. */
|
|
54
|
+
shouldRun(engineId: string, cycle: number): boolean;
|
|
55
|
+
/** Apply throttle — engine runs at reduced frequency. */
|
|
56
|
+
throttle(engineId: string, reason: string, cycle?: number, source?: string): void;
|
|
57
|
+
/** Apply cooldown — engine pauses for N cycles. */
|
|
58
|
+
cooldown(engineId: string, reason: string, cyclesToCool?: number, cycle?: number, source?: string): void;
|
|
59
|
+
/** Isolate — engine completely stopped, manual restore required. */
|
|
60
|
+
isolate(engineId: string, reason: string, cycle?: number, source?: string): void;
|
|
61
|
+
/** Escalate — log to journal + notification, no runtime change. */
|
|
62
|
+
escalate(engineId: string, reason: string, cycle?: number, source?: string): void;
|
|
63
|
+
/** Restore — re-enable an engine, clear active actions. */
|
|
64
|
+
restore(engineId: string, reason: string, cycle?: number, source?: string): void;
|
|
65
|
+
/** Periodic auto-governance review. */
|
|
66
|
+
review(cycle: number): GovernanceDecision[];
|
|
67
|
+
/** Get action history. */
|
|
68
|
+
getHistory(limit?: number): GovernanceAction[];
|
|
69
|
+
/** Get active actions for a specific engine. */
|
|
70
|
+
getActiveActions(engineId?: string): GovernanceAction[];
|
|
71
|
+
/** Get status summary. */
|
|
72
|
+
getStatus(): GovernanceLayerStatus;
|
|
73
|
+
private recordAction;
|
|
74
|
+
private rowToAction;
|
|
75
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runGovernanceMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS governance_actions (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
engine TEXT NOT NULL,
|
|
8
|
+
action_type TEXT NOT NULL,
|
|
9
|
+
reason TEXT NOT NULL,
|
|
10
|
+
source TEXT NOT NULL DEFAULT 'auto',
|
|
11
|
+
expires_at TEXT,
|
|
12
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
13
|
+
cycle INTEGER NOT NULL,
|
|
14
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
15
|
+
);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_governance_actions_engine ON governance_actions(engine, active);
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
// ── GovernanceLayer ─────────────────────────────────────
|
|
20
|
+
export class GovernanceLayer {
|
|
21
|
+
db;
|
|
22
|
+
log = getLogger();
|
|
23
|
+
loopDetector = null;
|
|
24
|
+
engineRegistry = null;
|
|
25
|
+
metaCognitionLayer = null;
|
|
26
|
+
journalWriter = null;
|
|
27
|
+
constructor(db) {
|
|
28
|
+
this.db = db;
|
|
29
|
+
runGovernanceMigration(db);
|
|
30
|
+
}
|
|
31
|
+
setLoopDetector(detector) { this.loopDetector = detector; }
|
|
32
|
+
setEngineRegistry(registry) { this.engineRegistry = registry; }
|
|
33
|
+
setMetaCognitionLayer(layer) { this.metaCognitionLayer = layer; }
|
|
34
|
+
setJournalWriter(writer) { this.journalWriter = writer; }
|
|
35
|
+
/** Check if an engine should run this cycle. Respects throttle/cooldown/isolate. */
|
|
36
|
+
shouldRun(engineId, cycle) {
|
|
37
|
+
// Check for active isolate
|
|
38
|
+
const isolated = this.db.prepare("SELECT id FROM governance_actions WHERE engine = ? AND action_type = 'isolate' AND active = 1 LIMIT 1").get(engineId);
|
|
39
|
+
if (isolated)
|
|
40
|
+
return false;
|
|
41
|
+
// Check for active cooldown (with expiry check)
|
|
42
|
+
const cooldown = this.db.prepare("SELECT id, expires_at FROM governance_actions WHERE engine = ? AND action_type = 'cooldown' AND active = 1 LIMIT 1").get(engineId);
|
|
43
|
+
if (cooldown) {
|
|
44
|
+
if (cooldown.expires_at) {
|
|
45
|
+
const now = new Date().toISOString();
|
|
46
|
+
if (now < cooldown.expires_at)
|
|
47
|
+
return false;
|
|
48
|
+
// Expired → auto-restore
|
|
49
|
+
this.db.prepare('UPDATE governance_actions SET active = 0 WHERE id = ?').run(cooldown.id);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Check for throttle (skip every Nth cycle)
|
|
56
|
+
const throttle = this.db.prepare("SELECT id FROM governance_actions WHERE engine = ? AND action_type = 'throttle' AND active = 1 LIMIT 1").get(engineId);
|
|
57
|
+
if (throttle && cycle % 2 !== 0)
|
|
58
|
+
return false; // throttle = skip odd cycles
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
/** Apply throttle — engine runs at reduced frequency. */
|
|
62
|
+
throttle(engineId, reason, cycle = 0, source = 'auto') {
|
|
63
|
+
this.recordAction(engineId, 'throttle', reason, source, null, cycle);
|
|
64
|
+
}
|
|
65
|
+
/** Apply cooldown — engine pauses for N cycles. */
|
|
66
|
+
cooldown(engineId, reason, cyclesToCool = 10, cycle = 0, source = 'auto') {
|
|
67
|
+
const expiresAt = new Date(Date.now() + cyclesToCool * 60_000).toISOString(); // ~1min per cycle
|
|
68
|
+
this.recordAction(engineId, 'cooldown', reason, source, expiresAt, cycle);
|
|
69
|
+
}
|
|
70
|
+
/** Isolate — engine completely stopped, manual restore required. */
|
|
71
|
+
isolate(engineId, reason, cycle = 0, source = 'auto') {
|
|
72
|
+
this.recordAction(engineId, 'isolate', reason, source, null, cycle);
|
|
73
|
+
if (this.engineRegistry)
|
|
74
|
+
this.engineRegistry.disable(engineId);
|
|
75
|
+
}
|
|
76
|
+
/** Escalate — log to journal + notification, no runtime change. */
|
|
77
|
+
escalate(engineId, reason, cycle = 0, source = 'auto') {
|
|
78
|
+
this.recordAction(engineId, 'escalate', reason, source, null, cycle);
|
|
79
|
+
if (this.journalWriter) {
|
|
80
|
+
this.journalWriter.write({
|
|
81
|
+
title: `Governance Escalation: ${engineId}`,
|
|
82
|
+
content: reason,
|
|
83
|
+
type: 'insight',
|
|
84
|
+
significance: 'critical',
|
|
85
|
+
tags: ['governance', 'escalation', engineId],
|
|
86
|
+
references: [],
|
|
87
|
+
data: { engine: engineId, source },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Restore — re-enable an engine, clear active actions. */
|
|
92
|
+
restore(engineId, reason, cycle = 0, source = 'auto') {
|
|
93
|
+
this.db.prepare('UPDATE governance_actions SET active = 0 WHERE engine = ? AND active = 1').run(engineId);
|
|
94
|
+
this.recordAction(engineId, 'restore', reason, source, null, cycle);
|
|
95
|
+
if (this.engineRegistry)
|
|
96
|
+
this.engineRegistry.enable(engineId);
|
|
97
|
+
this.log.info(`[governance] Restored: ${engineId} — ${reason}`);
|
|
98
|
+
}
|
|
99
|
+
/** Periodic auto-governance review. */
|
|
100
|
+
review(cycle) {
|
|
101
|
+
const decisions = [];
|
|
102
|
+
// 1. LoopDetector findings
|
|
103
|
+
if (this.loopDetector) {
|
|
104
|
+
const active = this.loopDetector.getActive();
|
|
105
|
+
for (const detection of active) {
|
|
106
|
+
for (const engine of detection.enginesInvolved) {
|
|
107
|
+
switch (detection.loopType) {
|
|
108
|
+
case 'retrigger_spiral':
|
|
109
|
+
decisions.push({ engine, action: 'throttle', reason: detection.description });
|
|
110
|
+
this.throttle(engine, detection.description, cycle);
|
|
111
|
+
break;
|
|
112
|
+
case 'stagnation':
|
|
113
|
+
decisions.push({ engine, action: 'cooldown', reason: detection.description });
|
|
114
|
+
this.cooldown(engine, detection.description, 10, cycle);
|
|
115
|
+
break;
|
|
116
|
+
case 'kpi_gaming':
|
|
117
|
+
decisions.push({ engine, action: 'escalate', reason: detection.description });
|
|
118
|
+
this.escalate(engine, detection.description, cycle);
|
|
119
|
+
break;
|
|
120
|
+
case 'epistemic_drift':
|
|
121
|
+
decisions.push({ engine, action: 'isolate', reason: detection.description });
|
|
122
|
+
this.isolate(engine, detection.description, cycle);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// 2. MetaCognition Grade F 3× in a row → cooldown
|
|
129
|
+
if (this.metaCognitionLayer) {
|
|
130
|
+
try {
|
|
131
|
+
const fEngines = this.db.prepare(`
|
|
132
|
+
SELECT engine, COUNT(*) as f_count FROM engine_report_cards
|
|
133
|
+
WHERE grade = 'F' AND rowid > (SELECT MAX(rowid) - 30 FROM engine_report_cards)
|
|
134
|
+
GROUP BY engine HAVING f_count >= 3
|
|
135
|
+
`).all();
|
|
136
|
+
for (const { engine, f_count } of fEngines) {
|
|
137
|
+
// Check if already has active action
|
|
138
|
+
const existing = this.db.prepare('SELECT id FROM governance_actions WHERE engine = ? AND active = 1 LIMIT 1').get(engine);
|
|
139
|
+
if (!existing) {
|
|
140
|
+
decisions.push({ engine, action: 'cooldown', reason: `Grade F ${f_count}× in recent evaluations` });
|
|
141
|
+
this.cooldown(engine, `Grade F ${f_count}× in recent evaluations`, 15, cycle);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// engine_report_cards may not exist
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// 3. Expire old cooldowns
|
|
150
|
+
const expired = this.db.prepare("SELECT DISTINCT engine FROM governance_actions WHERE action_type = 'cooldown' AND active = 1 AND expires_at IS NOT NULL AND expires_at < datetime('now')").all();
|
|
151
|
+
for (const { engine } of expired) {
|
|
152
|
+
decisions.push({ engine, action: 'restore', reason: 'Cooldown expired' });
|
|
153
|
+
this.restore(engine, 'Cooldown expired', cycle);
|
|
154
|
+
}
|
|
155
|
+
// 4. Multiple throttles → escalate to isolate
|
|
156
|
+
try {
|
|
157
|
+
const multiThrottle = this.db.prepare(`
|
|
158
|
+
SELECT engine, COUNT(*) as t_count FROM governance_actions
|
|
159
|
+
WHERE action_type = 'throttle' AND cycle > ? - 50
|
|
160
|
+
GROUP BY engine HAVING t_count >= 3
|
|
161
|
+
`).all(cycle);
|
|
162
|
+
for (const { engine, t_count } of multiThrottle) {
|
|
163
|
+
const isIsolated = this.db.prepare("SELECT id FROM governance_actions WHERE engine = ? AND action_type = 'isolate' AND active = 1 LIMIT 1").get(engine);
|
|
164
|
+
if (!isIsolated) {
|
|
165
|
+
decisions.push({ engine, action: 'isolate', reason: `${t_count} throttles in recent cycles — escalating` });
|
|
166
|
+
this.isolate(engine, `${t_count} throttles in recent cycles — escalating to isolate`, cycle);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch { /* ignore */ }
|
|
171
|
+
if (decisions.length > 0) {
|
|
172
|
+
this.log.info(`[governance] Review cycle ${cycle}: ${decisions.length} decisions`);
|
|
173
|
+
}
|
|
174
|
+
return decisions;
|
|
175
|
+
}
|
|
176
|
+
/** Get action history. */
|
|
177
|
+
getHistory(limit = 50) {
|
|
178
|
+
const rows = this.db.prepare('SELECT * FROM governance_actions ORDER BY id DESC LIMIT ?').all(limit);
|
|
179
|
+
return rows.map(r => this.rowToAction(r));
|
|
180
|
+
}
|
|
181
|
+
/** Get active actions for a specific engine. */
|
|
182
|
+
getActiveActions(engineId) {
|
|
183
|
+
const sql = engineId
|
|
184
|
+
? 'SELECT * FROM governance_actions WHERE active = 1 AND engine = ? ORDER BY id DESC'
|
|
185
|
+
: 'SELECT * FROM governance_actions WHERE active = 1 ORDER BY id DESC';
|
|
186
|
+
const rows = (engineId
|
|
187
|
+
? this.db.prepare(sql).all(engineId)
|
|
188
|
+
: this.db.prepare(sql).all());
|
|
189
|
+
return rows.map(r => this.rowToAction(r));
|
|
190
|
+
}
|
|
191
|
+
/** Get status summary. */
|
|
192
|
+
getStatus() {
|
|
193
|
+
const total = this.db.prepare('SELECT COUNT(*) as c FROM governance_actions').get().c;
|
|
194
|
+
const active = this.db.prepare('SELECT COUNT(*) as c FROM governance_actions WHERE active = 1').get().c;
|
|
195
|
+
const byTypeRows = this.db.prepare('SELECT action_type, COUNT(*) as c FROM governance_actions WHERE active = 1 GROUP BY action_type').all();
|
|
196
|
+
const byType = { throttle: 0, cooldown: 0, isolate: 0, escalate: 0, restore: 0 };
|
|
197
|
+
for (const r of byTypeRows)
|
|
198
|
+
byType[r.action_type] = r.c;
|
|
199
|
+
const throttled = this.db.prepare("SELECT DISTINCT engine FROM governance_actions WHERE action_type = 'throttle' AND active = 1").all();
|
|
200
|
+
const isolated = this.db.prepare("SELECT DISTINCT engine FROM governance_actions WHERE action_type = 'isolate' AND active = 1").all();
|
|
201
|
+
return {
|
|
202
|
+
totalActions: total,
|
|
203
|
+
activeActions: active,
|
|
204
|
+
byType: byType,
|
|
205
|
+
throttledEngines: throttled.map(r => r.engine),
|
|
206
|
+
isolatedEngines: isolated.map(r => r.engine),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// ── Private ─────────────────────────────────────────────
|
|
210
|
+
recordAction(engine, actionType, reason, source, expiresAt, cycle) {
|
|
211
|
+
this.db.prepare(`
|
|
212
|
+
INSERT INTO governance_actions (engine, action_type, reason, source, expires_at, active, cycle)
|
|
213
|
+
VALUES (?, ?, ?, ?, ?, 1, ?)
|
|
214
|
+
`).run(engine, actionType, reason, source, expiresAt, cycle);
|
|
215
|
+
this.log.info(`[governance] ${actionType} → ${engine}: ${reason}`);
|
|
216
|
+
}
|
|
217
|
+
rowToAction(row) {
|
|
218
|
+
return {
|
|
219
|
+
id: row.id,
|
|
220
|
+
engine: row.engine,
|
|
221
|
+
actionType: row.action_type,
|
|
222
|
+
reason: row.reason,
|
|
223
|
+
source: row.source,
|
|
224
|
+
expiresAt: row.expires_at,
|
|
225
|
+
active: row.active === 1,
|
|
226
|
+
cycle: row.cycle,
|
|
227
|
+
createdAt: row.created_at,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=governance-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance-layer.js","sourceRoot":"","sources":["../../src/governance/governance-layer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAkC/C,2DAA2D;AAE3D,MAAM,UAAU,sBAAsB,CAAC,EAAqB;IAC1D,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;GAaP,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAE3D,MAAM,OAAO,eAAe;IAClB,EAAE,CAAoB;IACtB,GAAG,GAAG,SAAS,EAAE,CAAC;IAClB,YAAY,GAAwB,IAAI,CAAC;IACzC,cAAc,GAA0B,IAAI,CAAC;IAC7C,kBAAkB,GAAqH,IAAI,CAAC;IAC5I,aAAa,GAA+D,IAAI,CAAC;IAEzF,YAAY,EAAqB;QAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,sBAAs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