noormme 1.0.6 → 1.2.0
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 +92 -63
- package/dist/cjs/agentic/ActionJournal.js +13 -9
- package/dist/cjs/agentic/CapabilityManager.d.ts +9 -4
- package/dist/cjs/agentic/CapabilityManager.js +113 -17
- package/dist/cjs/agentic/CognitiveRepository.js +19 -9
- package/dist/cjs/agentic/ContextBuffer.js +24 -12
- package/dist/cjs/agentic/Cortex.d.ts +8 -1
- package/dist/cjs/agentic/Cortex.js +30 -7
- package/dist/cjs/agentic/EpisodicMemory.js +7 -5
- package/dist/cjs/agentic/PersonaManager.js +16 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +31 -12
- package/dist/cjs/agentic/ResourceMonitor.js +4 -4
- package/dist/cjs/agentic/SessionCompressor.js +22 -14
- package/dist/cjs/agentic/SessionManager.js +36 -18
- package/dist/cjs/agentic/VectorIndexer.js +22 -18
- package/dist/cjs/agentic/improvement/AblationEngine.js +22 -15
- package/dist/cjs/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/cjs/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/cjs/agentic/improvement/CortexJanitor.d.ts +1 -1
- package/dist/cjs/agentic/improvement/CortexJanitor.js +64 -27
- package/dist/cjs/agentic/improvement/CuriosityEngine.d.ts +2 -2
- package/dist/cjs/agentic/improvement/CuriosityEngine.js +68 -59
- package/dist/cjs/agentic/improvement/EvolutionRitual.d.ts +24 -0
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +91 -0
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +80 -7
- package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/cjs/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +1 -1
- package/dist/cjs/agentic/improvement/GovernanceManager.js +85 -49
- package/dist/cjs/agentic/improvement/HiveLink.d.ts +9 -0
- package/dist/cjs/agentic/improvement/HiveLink.js +120 -26
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +101 -47
- package/dist/cjs/agentic/improvement/RecursiveReasoner.d.ts +7 -1
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +106 -22
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +34 -22
- package/dist/cjs/agentic/improvement/RuleEngine.js +22 -17
- package/dist/cjs/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/cjs/agentic/improvement/SkillSynthesizer.d.ts +48 -0
- package/dist/cjs/agentic/improvement/SkillSynthesizer.js +288 -0
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +1 -1
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +129 -55
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/cjs/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +13 -4
- package/dist/cjs/cache/cache-manager.js +7 -4
- package/dist/cjs/cli/commands/analyze.js +5 -4
- package/dist/cjs/cli/commands/generate.js +81 -44
- package/dist/cjs/cli/commands/init.js +7 -3
- package/dist/cjs/cli/commands/inspect.js +139 -36
- package/dist/cjs/cli/commands/migrate.js +5 -4
- package/dist/cjs/cli/commands/optimize.js +4 -4
- package/dist/cjs/cli/commands/status.js +9 -7
- package/dist/cjs/cli/commands/watch.js +7 -6
- package/dist/cjs/cli/index.js +2 -2
- package/dist/cjs/cli/ui/spinner.d.ts +15 -0
- package/dist/cjs/cli/ui/spinner.js +76 -0
- package/dist/cjs/dialect/database-introspector.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/cjs/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/cjs/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/cjs/edge-runtime/edge-config.js +21 -19
- package/dist/cjs/errors/NoormError.js +22 -20
- package/dist/cjs/helpers/agent-schema.js +3 -0
- package/dist/cjs/helpers/postgresql.js +7 -4
- package/dist/cjs/helpers/schema-evolution.js +31 -6
- package/dist/cjs/index.d.ts +18 -16
- package/dist/cjs/logging/logger.js +8 -4
- package/dist/cjs/migration/data_migrator.js +12 -11
- package/dist/cjs/migration/database_migration_manager.js +17 -13
- package/dist/cjs/migration/schema_differ.js +22 -14
- package/dist/cjs/migration/schema_introspector.js +8 -8
- package/dist/cjs/migration/type_mapper.js +68 -67
- package/dist/cjs/noormme.js +54 -37
- package/dist/cjs/performance/index.js +5 -5
- package/dist/cjs/performance/query-optimizer.js +26 -21
- package/dist/cjs/performance/services/cache-service.js +26 -16
- package/dist/cjs/performance/services/connection-factory.js +28 -23
- package/dist/cjs/performance/services/metrics-collector.js +41 -36
- package/dist/cjs/performance/utils/query-parser.js +15 -16
- package/dist/cjs/relationships/relationship-engine.js +10 -8
- package/dist/cjs/repository/repository-factory.js +97 -38
- package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/cjs/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/cjs/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/cjs/schema/core/discovery/view-discovery.js +5 -4
- package/dist/cjs/schema/core/factories/discovery-factory.js +4 -4
- package/dist/cjs/schema/core/utils/name-generator.js +14 -5
- package/dist/cjs/schema/core/utils/type-mapper.js +24 -24
- package/dist/cjs/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/cjs/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/cjs/schema/test/basic-schema-test.js +11 -9
- package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/cjs/schema/test/discovery-factory.test.js +2 -2
- package/dist/cjs/schema/test/error-handling.test.js +8 -6
- package/dist/cjs/schema/test/integration.test.js +24 -18
- package/dist/cjs/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/cjs/schema/test/simple-schema-test.js +9 -9
- package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/cjs/schema/test/test-runner.js +3 -3
- package/dist/cjs/sqlite-migration/index.d.ts +2 -2
- package/dist/cjs/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/cjs/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/cjs/testing/test-utils.js +36 -34
- package/dist/cjs/types/index.d.ts +61 -4
- package/dist/cjs/types/index.js +6 -3
- package/dist/cjs/types/type-generator.js +46 -42
- package/dist/cjs/util/safe-sql-helpers.js +1 -1
- package/dist/cjs/util/security-validator.js +20 -9
- package/dist/cjs/utils/errorHelpers.js +20 -10
- package/dist/cjs/watch/schema-watcher.js +22 -23
- package/dist/esm/agentic/ActionJournal.js +13 -9
- package/dist/esm/agentic/CapabilityManager.d.ts +9 -4
- package/dist/esm/agentic/CapabilityManager.js +113 -17
- package/dist/esm/agentic/CognitiveRepository.js +19 -9
- package/dist/esm/agentic/ContextBuffer.js +24 -12
- package/dist/esm/agentic/Cortex.d.ts +8 -1
- package/dist/esm/agentic/Cortex.js +30 -7
- package/dist/esm/agentic/EpisodicMemory.js +7 -5
- package/dist/esm/agentic/PersonaManager.js +16 -8
- package/dist/esm/agentic/PolicyEnforcer.js +31 -12
- package/dist/esm/agentic/ResourceMonitor.js +4 -4
- package/dist/esm/agentic/SessionCompressor.js +22 -14
- package/dist/esm/agentic/SessionManager.js +36 -18
- package/dist/esm/agentic/VectorIndexer.js +22 -18
- package/dist/esm/agentic/improvement/AblationEngine.js +22 -15
- package/dist/esm/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/esm/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/esm/agentic/improvement/CortexJanitor.d.ts +1 -1
- package/dist/esm/agentic/improvement/CortexJanitor.js +64 -27
- package/dist/esm/agentic/improvement/CuriosityEngine.d.ts +2 -2
- package/dist/esm/agentic/improvement/CuriosityEngine.js +68 -59
- package/dist/esm/agentic/improvement/EvolutionRitual.d.ts +24 -0
- package/dist/esm/agentic/improvement/EvolutionRitual.js +88 -0
- package/dist/esm/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +80 -7
- package/dist/esm/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/esm/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +1 -1
- package/dist/esm/agentic/improvement/GovernanceManager.js +85 -49
- package/dist/esm/agentic/improvement/HiveLink.d.ts +9 -0
- package/dist/esm/agentic/improvement/HiveLink.js +120 -26
- package/dist/esm/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +101 -47
- package/dist/esm/agentic/improvement/RecursiveReasoner.d.ts +7 -1
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +106 -22
- package/dist/esm/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +34 -22
- package/dist/esm/agentic/improvement/RuleEngine.js +22 -17
- package/dist/esm/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/esm/agentic/improvement/SkillSynthesizer.d.ts +48 -0
- package/dist/esm/agentic/improvement/SkillSynthesizer.js +285 -0
- package/dist/esm/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +1 -1
- package/dist/esm/agentic/improvement/StrategicPlanner.js +129 -55
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/esm/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/esm/agentic/telemetry/ResearchAlchemist.js +13 -4
- package/dist/esm/cache/cache-manager.js +7 -4
- package/dist/esm/cli/commands/analyze.js +5 -4
- package/dist/esm/cli/commands/generate.js +82 -45
- package/dist/esm/cli/commands/init.js +8 -4
- package/dist/esm/cli/commands/inspect.js +140 -37
- package/dist/esm/cli/commands/migrate.js +5 -4
- package/dist/esm/cli/commands/optimize.js +4 -4
- package/dist/esm/cli/commands/status.js +9 -7
- package/dist/esm/cli/commands/watch.js +7 -6
- package/dist/esm/cli/index.js +2 -2
- package/dist/esm/cli/ui/spinner.d.ts +15 -0
- package/dist/esm/cli/ui/spinner.js +70 -0
- package/dist/esm/dialect/database-introspector.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/esm/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/esm/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/esm/dynamic/dynamic.js +1 -1
- package/dist/esm/edge-runtime/edge-config.js +21 -19
- package/dist/esm/errors/NoormError.js +22 -20
- package/dist/esm/helpers/agent-schema.js +3 -0
- package/dist/esm/helpers/postgresql.js +7 -4
- package/dist/esm/helpers/schema-evolution.js +31 -6
- package/dist/esm/index.d.ts +18 -16
- package/dist/esm/index.js +2 -2
- package/dist/esm/logging/logger.js +8 -4
- package/dist/esm/migration/data_migrator.js +12 -11
- package/dist/esm/migration/database_migration_manager.js +18 -14
- package/dist/esm/migration/schema_differ.js +22 -14
- package/dist/esm/migration/schema_introspector.js +8 -8
- package/dist/esm/migration/type_mapper.js +68 -67
- package/dist/esm/noormme.js +54 -37
- package/dist/esm/performance/index.js +5 -5
- package/dist/esm/performance/query-optimizer.js +26 -21
- package/dist/esm/performance/services/cache-service.js +26 -16
- package/dist/esm/performance/services/connection-factory.js +28 -23
- package/dist/esm/performance/services/metrics-collector.js +41 -36
- package/dist/esm/performance/utils/query-parser.js +15 -16
- package/dist/esm/raw-builder/sql.js +1 -1
- package/dist/esm/relationships/relationship-engine.js +10 -8
- package/dist/esm/repository/repository-factory.js +98 -39
- package/dist/esm/schema/builders/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/builders/create-index-builder.js +2 -2
- package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/esm/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/esm/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/esm/schema/core/discovery/view-discovery.js +5 -4
- package/dist/esm/schema/core/factories/discovery-factory.js +4 -4
- package/dist/esm/schema/core/utils/name-generator.js +14 -5
- package/dist/esm/schema/core/utils/type-mapper.js +24 -24
- package/dist/esm/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/esm/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/esm/schema/test/basic-schema-test.js +11 -9
- package/dist/esm/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/esm/schema/test/discovery-factory.test.js +2 -2
- package/dist/esm/schema/test/error-handling.test.js +8 -6
- package/dist/esm/schema/test/integration.test.js +24 -18
- package/dist/esm/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/esm/schema/test/simple-schema-test.js +9 -9
- package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/esm/schema/test/test-runner.js +3 -3
- package/dist/esm/sqlite-migration/index.d.ts +2 -2
- package/dist/esm/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/esm/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/esm/testing/test-utils.js +36 -34
- package/dist/esm/types/index.d.ts +61 -4
- package/dist/esm/types/index.js +6 -3
- package/dist/esm/types/type-generator.js +46 -42
- package/dist/esm/util/safe-sql-helpers.js +1 -1
- package/dist/esm/util/security-validator.js +20 -9
- package/dist/esm/utils/errorHelpers.js +21 -11
- package/dist/esm/watch/schema-watcher.js +22 -23
- package/package.json +40 -44
|
@@ -36,7 +36,7 @@ class SessionManager {
|
|
|
36
36
|
status: 'active',
|
|
37
37
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
38
38
|
created_at: new Date(),
|
|
39
|
-
updated_at: new Date()
|
|
39
|
+
updated_at: new Date(),
|
|
40
40
|
})
|
|
41
41
|
.returningAll()
|
|
42
42
|
.executeTakeFirstOrThrow();
|
|
@@ -71,11 +71,23 @@ class SessionManager {
|
|
|
71
71
|
async deleteSession(id) {
|
|
72
72
|
await this.db.transaction().execute(async (trx) => {
|
|
73
73
|
// Delete associated data first
|
|
74
|
-
await trx
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
await trx
|
|
75
|
+
.deleteFrom(this.messagesTable)
|
|
76
|
+
.where('session_id', '=', id)
|
|
77
|
+
.execute();
|
|
78
|
+
await trx
|
|
79
|
+
.deleteFrom(this.goalsTable)
|
|
80
|
+
.where('session_id', '=', id)
|
|
81
|
+
.execute();
|
|
82
|
+
await trx
|
|
83
|
+
.deleteFrom(this.memoriesTable)
|
|
84
|
+
.where('session_id', '=', id)
|
|
85
|
+
.execute();
|
|
77
86
|
// Delete the session itself
|
|
78
|
-
await trx
|
|
87
|
+
await trx
|
|
88
|
+
.deleteFrom(this.sessionsTable)
|
|
89
|
+
.where('id', '=', id)
|
|
90
|
+
.execute();
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
/**
|
|
@@ -90,7 +102,7 @@ class SessionManager {
|
|
|
90
102
|
role,
|
|
91
103
|
content,
|
|
92
104
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
93
|
-
created_at: new Date()
|
|
105
|
+
created_at: new Date(),
|
|
94
106
|
})
|
|
95
107
|
.returningAll()
|
|
96
108
|
.executeTakeFirstOrThrow();
|
|
@@ -114,7 +126,7 @@ class SessionManager {
|
|
|
114
126
|
.orderBy('created_at', 'asc')
|
|
115
127
|
.limit(limit)
|
|
116
128
|
.execute();
|
|
117
|
-
return messages.map(m => this.parseMessage(m));
|
|
129
|
+
return messages.map((m) => this.parseMessage(m));
|
|
118
130
|
}
|
|
119
131
|
/**
|
|
120
132
|
* Set or update a goal for a session
|
|
@@ -135,7 +147,7 @@ class SessionManager {
|
|
|
135
147
|
status,
|
|
136
148
|
priority,
|
|
137
149
|
metadata: metadata ? JSON.stringify(metadata) : existing.metadata,
|
|
138
|
-
updated_at: new Date()
|
|
150
|
+
updated_at: new Date(),
|
|
139
151
|
})
|
|
140
152
|
.where('id', '=', existing.id)
|
|
141
153
|
.returningAll()
|
|
@@ -152,7 +164,7 @@ class SessionManager {
|
|
|
152
164
|
priority,
|
|
153
165
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
154
166
|
created_at: new Date(),
|
|
155
|
-
updated_at: new Date()
|
|
167
|
+
updated_at: new Date(),
|
|
156
168
|
})
|
|
157
169
|
.returningAll()
|
|
158
170
|
.executeTakeFirstOrThrow();
|
|
@@ -177,7 +189,7 @@ class SessionManager {
|
|
|
177
189
|
query = query.where('status', '=', status);
|
|
178
190
|
}
|
|
179
191
|
const goals = await query.execute();
|
|
180
|
-
return goals.map(g => this.parseGoal(g));
|
|
192
|
+
return goals.map((g) => this.parseGoal(g));
|
|
181
193
|
}
|
|
182
194
|
/**
|
|
183
195
|
* Clear message history for a session.
|
|
@@ -200,12 +212,12 @@ class SessionManager {
|
|
|
200
212
|
.executeTakeFirstOrThrow();
|
|
201
213
|
const metadata = typeof message.metadata === 'string'
|
|
202
214
|
? JSON.parse(message.metadata)
|
|
203
|
-
:
|
|
215
|
+
: message.metadata || {};
|
|
204
216
|
const updatedMetadata = { ...metadata, anchor: true };
|
|
205
217
|
const updated = await this.typedDb
|
|
206
218
|
.updateTable(this.messagesTable)
|
|
207
219
|
.set({
|
|
208
|
-
metadata: JSON.stringify(updatedMetadata)
|
|
220
|
+
metadata: JSON.stringify(updatedMetadata),
|
|
209
221
|
})
|
|
210
222
|
.where('id', '=', messageId)
|
|
211
223
|
.returningAll()
|
|
@@ -217,9 +229,11 @@ class SessionManager {
|
|
|
217
229
|
id: session.id,
|
|
218
230
|
name: session.name,
|
|
219
231
|
status: session.status,
|
|
220
|
-
metadata: typeof session.metadata === 'string'
|
|
232
|
+
metadata: typeof session.metadata === 'string'
|
|
233
|
+
? JSON.parse(session.metadata)
|
|
234
|
+
: session.metadata || {},
|
|
221
235
|
createdAt: new Date(session.created_at),
|
|
222
|
-
updatedAt: new Date(session.updated_at)
|
|
236
|
+
updatedAt: new Date(session.updated_at),
|
|
223
237
|
};
|
|
224
238
|
}
|
|
225
239
|
parseMessage(message) {
|
|
@@ -228,8 +242,10 @@ class SessionManager {
|
|
|
228
242
|
sessionId: message.session_id,
|
|
229
243
|
role: message.role,
|
|
230
244
|
content: message.content,
|
|
231
|
-
metadata: typeof message.metadata === 'string'
|
|
232
|
-
|
|
245
|
+
metadata: typeof message.metadata === 'string'
|
|
246
|
+
? JSON.parse(message.metadata)
|
|
247
|
+
: message.metadata || {},
|
|
248
|
+
createdAt: new Date(message.created_at),
|
|
233
249
|
};
|
|
234
250
|
}
|
|
235
251
|
parseGoal(goal) {
|
|
@@ -240,9 +256,11 @@ class SessionManager {
|
|
|
240
256
|
description: goal.description,
|
|
241
257
|
status: goal.status,
|
|
242
258
|
priority: goal.priority,
|
|
243
|
-
metadata: typeof goal.metadata === 'string'
|
|
259
|
+
metadata: typeof goal.metadata === 'string'
|
|
260
|
+
? JSON.parse(goal.metadata)
|
|
261
|
+
: goal.metadata || {},
|
|
244
262
|
createdAt: new Date(goal.created_at),
|
|
245
|
-
updatedAt: new Date(goal.updated_at)
|
|
263
|
+
updatedAt: new Date(goal.updated_at),
|
|
246
264
|
};
|
|
247
265
|
}
|
|
248
266
|
}
|
|
@@ -28,7 +28,7 @@ class VectorIndexer {
|
|
|
28
28
|
embedding: JSON.stringify(embedding),
|
|
29
29
|
session_id: sessionId || null,
|
|
30
30
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
31
|
-
created_at: new Date()
|
|
31
|
+
created_at: new Date(),
|
|
32
32
|
})
|
|
33
33
|
.returningAll()
|
|
34
34
|
.executeTakeFirstOrThrow();
|
|
@@ -38,19 +38,19 @@ class VectorIndexer {
|
|
|
38
38
|
* Batch add memories
|
|
39
39
|
*/
|
|
40
40
|
async addMemories(items) {
|
|
41
|
-
const values = items.map(item => ({
|
|
41
|
+
const values = items.map((item) => ({
|
|
42
42
|
content: item.content,
|
|
43
43
|
embedding: JSON.stringify(item.embedding),
|
|
44
44
|
session_id: item.sessionId || null,
|
|
45
45
|
metadata: item.metadata ? JSON.stringify(item.metadata) : null,
|
|
46
|
-
created_at: new Date()
|
|
46
|
+
created_at: new Date(),
|
|
47
47
|
}));
|
|
48
48
|
const memories = await this.typedDb
|
|
49
49
|
.insertInto(this.memoriesTable)
|
|
50
50
|
.values(values)
|
|
51
51
|
.returningAll()
|
|
52
52
|
.execute();
|
|
53
|
-
return memories.map(m => this.parseMemory(m));
|
|
53
|
+
return memories.map((m) => this.parseMemory(m));
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Search for similar memories using Hybrid Search (Vector + Keyword)
|
|
@@ -69,7 +69,7 @@ class VectorIndexer {
|
|
|
69
69
|
query = query.where('session_id', '=', sessionId);
|
|
70
70
|
}
|
|
71
71
|
const results = await query.execute();
|
|
72
|
-
vectorResults = results.map(m => this.parseMemory(m));
|
|
72
|
+
vectorResults = results.map((m) => this.parseMemory(m));
|
|
73
73
|
}
|
|
74
74
|
else if (this.config.provider === 'sqlite-vss') {
|
|
75
75
|
try {
|
|
@@ -94,15 +94,17 @@ class VectorIndexer {
|
|
|
94
94
|
query = query.orderBy('created_at', 'desc').limit(1000);
|
|
95
95
|
}
|
|
96
96
|
const allMemories = await query.execute();
|
|
97
|
-
const scored = allMemories.map(mem => {
|
|
98
|
-
const vec = typeof mem.embedding === 'string'
|
|
97
|
+
const scored = allMemories.map((mem) => {
|
|
98
|
+
const vec = typeof mem.embedding === 'string'
|
|
99
|
+
? JSON.parse(mem.embedding)
|
|
100
|
+
: mem.embedding || [];
|
|
99
101
|
const score = this.cosineSimilarity(embedding, vec);
|
|
100
102
|
return { memory: mem, score };
|
|
101
103
|
});
|
|
102
104
|
vectorResults = scored
|
|
103
105
|
.sort((a, b) => b.score - a.score)
|
|
104
106
|
.slice(0, limit)
|
|
105
|
-
.map(item => this.parseMemory(item.memory));
|
|
107
|
+
.map((item) => this.parseMemory(item.memory));
|
|
106
108
|
}
|
|
107
109
|
// Keyword Search (Hybrid component)
|
|
108
110
|
let keywordResults = [];
|
|
@@ -112,19 +114,17 @@ class VectorIndexer {
|
|
|
112
114
|
// Merge and fuse using Reciprocal Rank Fusion (RRF)
|
|
113
115
|
const fused = this.mergeWithRRF(vectorResults, keywordResults, limit);
|
|
114
116
|
// Final filtering and confidence assessment
|
|
115
|
-
const finalResults = fused.filter(m => {
|
|
117
|
+
const finalResults = fused.filter((m) => {
|
|
116
118
|
const vec = m.embedding || [];
|
|
117
119
|
const score = this.cosineSimilarity(embedding, vec);
|
|
118
120
|
// Even with RRF, we keep a safety floor for semantic relevance
|
|
119
|
-
return score >=
|
|
121
|
+
return score >= minScore * 0.8;
|
|
120
122
|
});
|
|
121
123
|
return finalResults.slice(0, limit);
|
|
122
124
|
}
|
|
123
125
|
async keywordSearch(keyword, options) {
|
|
124
126
|
const { limit, sessionId } = options;
|
|
125
|
-
let query = this.typedDb
|
|
126
|
-
.selectFrom(this.memoriesTable)
|
|
127
|
-
.selectAll();
|
|
127
|
+
let query = this.typedDb.selectFrom(this.memoriesTable).selectAll();
|
|
128
128
|
// Production Hardening: Use native FTS where available
|
|
129
129
|
if (this.config.provider === 'sqlite-vss') {
|
|
130
130
|
// Check for virtual FTS table (convention: table_name_fts)
|
|
@@ -147,7 +147,7 @@ class VectorIndexer {
|
|
|
147
147
|
query = query.where('session_id', '=', sessionId);
|
|
148
148
|
}
|
|
149
149
|
const results = await query.limit(limit).execute();
|
|
150
|
-
return results.map(r => this.parseMemory(r));
|
|
150
|
+
return results.map((r) => this.parseMemory(r));
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
* Reciprocal Rank Fusion (RRF)
|
|
@@ -172,7 +172,7 @@ class VectorIndexer {
|
|
|
172
172
|
// Sort by fused score
|
|
173
173
|
return Object.values(scores)
|
|
174
174
|
.sort((a, b) => b.score - a.score)
|
|
175
|
-
.map(s => s.memory);
|
|
175
|
+
.map((s) => s.memory);
|
|
176
176
|
}
|
|
177
177
|
mergeResults(vector, keyword) {
|
|
178
178
|
const seen = new Set();
|
|
@@ -203,9 +203,13 @@ class VectorIndexer {
|
|
|
203
203
|
id: m.id,
|
|
204
204
|
sessionId: m.session_id,
|
|
205
205
|
content: m.content,
|
|
206
|
-
embedding: typeof m.embedding === 'string'
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
embedding: typeof m.embedding === 'string'
|
|
207
|
+
? JSON.parse(m.embedding)
|
|
208
|
+
: m.embedding || [],
|
|
209
|
+
metadata: typeof m.metadata === 'string'
|
|
210
|
+
? JSON.parse(m.metadata)
|
|
211
|
+
: m.metadata || {},
|
|
212
|
+
createdAt: new Date(m.created_at),
|
|
209
213
|
};
|
|
210
214
|
}
|
|
211
215
|
}
|
|
@@ -34,11 +34,11 @@ class AblationEngine {
|
|
|
34
34
|
// 1. Prune Knowledge (with dependency check)
|
|
35
35
|
const knowledgeToPrune = await trx
|
|
36
36
|
.selectFrom(this.knowledgeTable)
|
|
37
|
-
.
|
|
37
|
+
.selectAll()
|
|
38
38
|
.where((eb) => eb.or([
|
|
39
39
|
eb('metadata', 'not like', '%"priority": "high"%'),
|
|
40
40
|
eb('metadata', 'not like', '%"priority":"high"%'),
|
|
41
|
-
eb('metadata', 'is', null)
|
|
41
|
+
eb('metadata', 'is', null),
|
|
42
42
|
]))
|
|
43
43
|
.where('updated_at', '<', cutoff)
|
|
44
44
|
// Exclude items that are linked
|
|
@@ -46,7 +46,7 @@ class AblationEngine {
|
|
|
46
46
|
.where('id', 'not in', (eb) => eb.selectFrom(this.linksTable).select('target_id'))
|
|
47
47
|
.execute();
|
|
48
48
|
if (knowledgeToPrune.length > 0) {
|
|
49
|
-
const candidates = knowledgeToPrune.map(k => this.cortex.knowledge['parseKnowledge'](k));
|
|
49
|
+
const candidates = knowledgeToPrune.map((k) => this.cortex.knowledge['parseKnowledge'](k));
|
|
50
50
|
const idsToDelete = [];
|
|
51
51
|
for (const item of candidates) {
|
|
52
52
|
const fitness = this.cortex.knowledge.calculateFitness(item);
|
|
@@ -69,7 +69,7 @@ class AblationEngine {
|
|
|
69
69
|
.where('created_at', '<', cutoff)
|
|
70
70
|
.where((eb) => eb.or([
|
|
71
71
|
eb('metadata', 'not like', '%"anchor":true%'),
|
|
72
|
-
eb('metadata', 'is', null)
|
|
72
|
+
eb('metadata', 'is', null),
|
|
73
73
|
]))
|
|
74
74
|
.executeTakeFirst();
|
|
75
75
|
totalPruned += Number(memoriesResult.numDeletedRows || 0);
|
|
@@ -88,7 +88,7 @@ class AblationEngine {
|
|
|
88
88
|
const baseline = await this.cortex.metrics.getAverageMetric('success_rate');
|
|
89
89
|
const stats = await this.cortex.metrics.getMetricStats('success_rate');
|
|
90
90
|
// If current average is significantly lower than overall average
|
|
91
|
-
if (stats.count > 10 && stats.avg <
|
|
91
|
+
if (stats.count > 10 && stats.avg < baseline * 0.8) {
|
|
92
92
|
console.warn(`[AblationEngine] PERFORMANCE DEGRADATION DETECTED (Avg: ${stats.avg}, Baseline: ${baseline}). Triggering mass recovery.`);
|
|
93
93
|
const ablatedItems = await this.typedDb
|
|
94
94
|
.selectFrom(this.knowledgeTable)
|
|
@@ -112,16 +112,21 @@ class AblationEngine {
|
|
|
112
112
|
async testAblation(id) {
|
|
113
113
|
console.log(`[AblationEngine] Conducting ablation test on item ${id}`);
|
|
114
114
|
return await this.db.transaction().execute(async (trx) => {
|
|
115
|
-
const item = await trx
|
|
115
|
+
const item = (await trx
|
|
116
116
|
.selectFrom(this.knowledgeTable)
|
|
117
117
|
.selectAll()
|
|
118
118
|
.where('id', '=', id)
|
|
119
|
-
.executeTakeFirst();
|
|
119
|
+
.executeTakeFirst());
|
|
120
120
|
if (!item)
|
|
121
121
|
return false;
|
|
122
|
-
const metadata = typeof item.metadata === 'string'
|
|
122
|
+
const metadata = typeof item.metadata === 'string'
|
|
123
|
+
? JSON.parse(item.metadata)
|
|
124
|
+
: item.metadata || {};
|
|
123
125
|
// 1. Record the experiment in reflections
|
|
124
|
-
await this.cortex.reflections.reflect(item.source_session_id || 'system', 'success', `Ablation experiment initiated for item ${id}`, [
|
|
126
|
+
await this.cortex.reflections.reflect(item.source_session_id || 'system', 'success', `Ablation experiment initiated for item ${id}`, [
|
|
127
|
+
`Temporary confidence reduction to evaluate reasoning impact.`,
|
|
128
|
+
`Original confidence: ${item.confidence}`,
|
|
129
|
+
]);
|
|
125
130
|
// 2. Perform the ablation
|
|
126
131
|
await trx
|
|
127
132
|
.updateTable(this.knowledgeTable)
|
|
@@ -130,9 +135,9 @@ class AblationEngine {
|
|
|
130
135
|
...metadata,
|
|
131
136
|
ablation_test: true,
|
|
132
137
|
original_confidence: item.confidence,
|
|
133
|
-
ablated_at: new Date()
|
|
138
|
+
ablated_at: new Date(),
|
|
134
139
|
}),
|
|
135
|
-
confidence: 0
|
|
140
|
+
confidence: 0,
|
|
136
141
|
})
|
|
137
142
|
.where('id', '=', id)
|
|
138
143
|
.execute();
|
|
@@ -144,14 +149,16 @@ class AblationEngine {
|
|
|
144
149
|
*/
|
|
145
150
|
async recoverAblatedItem(id) {
|
|
146
151
|
return await this.db.transaction().execute(async (trx) => {
|
|
147
|
-
const item = await trx
|
|
152
|
+
const item = (await trx
|
|
148
153
|
.selectFrom(this.knowledgeTable)
|
|
149
154
|
.selectAll()
|
|
150
155
|
.where('id', '=', id)
|
|
151
|
-
.executeTakeFirst();
|
|
156
|
+
.executeTakeFirst());
|
|
152
157
|
if (!item)
|
|
153
158
|
return false;
|
|
154
|
-
const metadata = typeof item.metadata === 'string'
|
|
159
|
+
const metadata = typeof item.metadata === 'string'
|
|
160
|
+
? JSON.parse(item.metadata)
|
|
161
|
+
: item.metadata || {};
|
|
155
162
|
if (!metadata.ablation_test)
|
|
156
163
|
return false;
|
|
157
164
|
const originalConfidence = metadata.original_confidence ?? 0.5;
|
|
@@ -163,7 +170,7 @@ class AblationEngine {
|
|
|
163
170
|
.set({
|
|
164
171
|
confidence: originalConfidence,
|
|
165
172
|
metadata: JSON.stringify(metadata),
|
|
166
|
-
updated_at: new Date()
|
|
173
|
+
updated_at: new Date(),
|
|
167
174
|
})
|
|
168
175
|
.where('id', '=', id)
|
|
169
176
|
.execute();
|
|
@@ -22,13 +22,15 @@ class ActionRefiner {
|
|
|
22
22
|
async refineActions() {
|
|
23
23
|
const recommendations = [];
|
|
24
24
|
// 1. Find tools with high failure rates
|
|
25
|
-
const failureStats = await this.db
|
|
25
|
+
const failureStats = (await this.db
|
|
26
26
|
.selectFrom(this.actionsTable)
|
|
27
27
|
.select('tool_name')
|
|
28
28
|
.select((eb) => eb.fn.count('id').as('total'))
|
|
29
|
-
.select((eb) => eb.fn
|
|
29
|
+
.select((eb) => eb.fn
|
|
30
|
+
.sum(eb.case().when('status', '=', 'failure').then(1).else(0).end())
|
|
31
|
+
.as('failures'))
|
|
30
32
|
.groupBy('tool_name')
|
|
31
|
-
.execute();
|
|
33
|
+
.execute());
|
|
32
34
|
for (const stat of failureStats) {
|
|
33
35
|
const failures = Number(stat.failures || 0);
|
|
34
36
|
const total = Number(stat.total || 1);
|
|
@@ -40,7 +42,7 @@ class ActionRefiner {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
// 2. Discover missing capabilities based on error patterns
|
|
43
|
-
const missingCapabilities = await this.db
|
|
45
|
+
const missingCapabilities = (await this.db
|
|
44
46
|
.selectFrom(this.actionsTable)
|
|
45
47
|
.select('tool_name')
|
|
46
48
|
.where('status', '=', 'failure')
|
|
@@ -48,10 +50,10 @@ class ActionRefiner {
|
|
|
48
50
|
eb('error', 'like', '%permission denied%'),
|
|
49
51
|
eb('error', 'like', '%unknown tool%'),
|
|
50
52
|
eb('error', 'like', '%missing capability%'),
|
|
51
|
-
eb('error', 'like', '%not authorized%')
|
|
53
|
+
eb('error', 'like', '%not authorized%'),
|
|
52
54
|
]))
|
|
53
55
|
.groupBy('tool_name')
|
|
54
|
-
.execute();
|
|
56
|
+
.execute());
|
|
55
57
|
for (const row of missingCapabilities) {
|
|
56
58
|
recommendations.push(`Detected repeated access/existence failures for tool '${row.tool_name}'. Proposing capability expansion.`);
|
|
57
59
|
await this.proposeCapabilityUpdate(row.tool_name);
|
|
@@ -63,14 +65,14 @@ class ActionRefiner {
|
|
|
63
65
|
*/
|
|
64
66
|
async proposeReflectionRule(toolName) {
|
|
65
67
|
const existing = await this.cortex.rules.getActiveRules('agent_actions', 'insert');
|
|
66
|
-
const hasRule = existing.some(r => r.metadata?.targetTool === toolName);
|
|
68
|
+
const hasRule = existing.some((r) => r.metadata?.targetTool === toolName);
|
|
67
69
|
if (!hasRule) {
|
|
68
70
|
console.log(`[ActionRefiner] Proposing reflection rule for tool: ${toolName}`);
|
|
69
71
|
await this.cortex.rules.defineRule('agent_actions', 'insert', 'audit', {
|
|
70
72
|
metadata: {
|
|
71
73
|
targetTool: toolName,
|
|
72
|
-
reason: 'High failure rate detected by ActionRefiner'
|
|
73
|
-
}
|
|
74
|
+
reason: 'High failure rate detected by ActionRefiner',
|
|
75
|
+
},
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -81,7 +83,7 @@ class ActionRefiner {
|
|
|
81
83
|
console.log(`[ActionRefiner] Proposing capability expansion for tool: ${toolName}`);
|
|
82
84
|
await this.cortex.reflections.reflect('system', 'failure', `Architectural Gap: Missing Capability for '${toolName}'`, [
|
|
83
85
|
`Identified repeated failures using tool '${toolName}'.`,
|
|
84
|
-
`Resolution: Inspect permission sets and ensure the tool is correctly registered in the CapabilityManager
|
|
86
|
+
`Resolution: Inspect permission sets and ensure the tool is correctly registered in the CapabilityManager.`,
|
|
85
87
|
]);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -20,11 +20,11 @@ class ConflictResolver {
|
|
|
20
20
|
*/
|
|
21
21
|
async auditRuleConflicts() {
|
|
22
22
|
console.log('[ConflictResolver] Auditing cognitive rules for conflicts and overlaps...');
|
|
23
|
-
const rules = await this.db
|
|
23
|
+
const rules = (await this.db
|
|
24
24
|
.selectFrom(this.rulesTable)
|
|
25
25
|
.selectAll()
|
|
26
26
|
.where('is_enabled', '=', true)
|
|
27
|
-
.execute();
|
|
27
|
+
.execute());
|
|
28
28
|
const conflicts = [];
|
|
29
29
|
// 1. Direct Conflicts: Same Table + Same Operation
|
|
30
30
|
const seen = new Map();
|
|
@@ -75,18 +75,18 @@ class ConflictResolver {
|
|
|
75
75
|
*/
|
|
76
76
|
async resolveConflict(tableName, operation) {
|
|
77
77
|
console.log(`[ConflictResolver] Resolving conflict for ${tableName}:${operation}`);
|
|
78
|
-
const rules = await this.db
|
|
78
|
+
const rules = (await this.db
|
|
79
79
|
.selectFrom(this.rulesTable)
|
|
80
80
|
.selectAll()
|
|
81
81
|
.where('table_name', '=', tableName)
|
|
82
82
|
.where('operation', '=', operation)
|
|
83
83
|
.where('is_enabled', '=', true)
|
|
84
84
|
.orderBy('created_at', 'desc')
|
|
85
|
-
.execute();
|
|
85
|
+
.execute());
|
|
86
86
|
if (rules.length <= 1)
|
|
87
87
|
return;
|
|
88
88
|
// Keep the first (newest) one, disable the rest
|
|
89
|
-
const toDisable = rules.slice(1).map(r => r.id);
|
|
89
|
+
const toDisable = rules.slice(1).map((r) => r.id);
|
|
90
90
|
await this.db
|
|
91
91
|
.updateTable(this.rulesTable)
|
|
92
92
|
.set({ is_enabled: false })
|
|
@@ -30,7 +30,7 @@ export declare class CortexJanitor {
|
|
|
30
30
|
pruneMetrics(daysToKeep?: number): Promise<number>;
|
|
31
31
|
/**
|
|
32
32
|
* Autonomous Indexing: Detects common query patterns and suggests missing indexes.
|
|
33
|
-
* Production Hardening: Uses introspection and usage patterns.
|
|
33
|
+
* Production Hardening: Uses introspection and usage patterns from metrics.
|
|
34
34
|
*/
|
|
35
35
|
autonomousIndexing(): Promise<string[]>;
|
|
36
36
|
/**
|
|
@@ -45,7 +45,10 @@ class CortexJanitor {
|
|
|
45
45
|
.executeTakeFirst();
|
|
46
46
|
const deletedCount = Number(result.numDeletedRows || 0);
|
|
47
47
|
if (deletedCount > 0) {
|
|
48
|
-
await this.logRitual('optimization', 'success', {
|
|
48
|
+
await this.logRitual('optimization', 'success', {
|
|
49
|
+
action: 'clean_orphans',
|
|
50
|
+
deletedCount,
|
|
51
|
+
});
|
|
49
52
|
}
|
|
50
53
|
return deletedCount;
|
|
51
54
|
}
|
|
@@ -62,7 +65,10 @@ class CortexJanitor {
|
|
|
62
65
|
.executeTakeFirst();
|
|
63
66
|
const count = Number(result.numUpdatedRows || 0);
|
|
64
67
|
if (count > 0) {
|
|
65
|
-
await this.logRitual('optimization', 'success', {
|
|
68
|
+
await this.logRitual('optimization', 'success', {
|
|
69
|
+
action: 'archive_sessions',
|
|
70
|
+
count,
|
|
71
|
+
});
|
|
66
72
|
}
|
|
67
73
|
return count;
|
|
68
74
|
}
|
|
@@ -77,45 +83,74 @@ class CortexJanitor {
|
|
|
77
83
|
.executeTakeFirst();
|
|
78
84
|
const count = Number(result.numDeletedRows || 0);
|
|
79
85
|
if (count > 0) {
|
|
80
|
-
await this.logRitual('pruning', 'success', {
|
|
86
|
+
await this.logRitual('pruning', 'success', {
|
|
87
|
+
action: 'prune_metrics',
|
|
88
|
+
count,
|
|
89
|
+
});
|
|
81
90
|
}
|
|
82
91
|
return count;
|
|
83
92
|
}
|
|
84
93
|
/**
|
|
85
94
|
* Autonomous Indexing: Detects common query patterns and suggests missing indexes.
|
|
86
|
-
* Production Hardening: Uses introspection and usage patterns.
|
|
95
|
+
* Production Hardening: Uses introspection and usage patterns from metrics.
|
|
87
96
|
*/
|
|
88
97
|
async autonomousIndexing() {
|
|
89
98
|
console.log('[CortexJanitor] Analyzing query patterns for autonomous indexing...');
|
|
90
99
|
const applied = [];
|
|
91
|
-
// 1.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
// 1. Structural Heuristics: Core Identity Indexes
|
|
101
|
+
const coreIdentityTables = [
|
|
102
|
+
{ table: this.knowledgeTable, col: 'entity' },
|
|
103
|
+
{ table: this.config.memoriesTable || 'agent_memories', col: 'entity' },
|
|
104
|
+
{
|
|
105
|
+
table: this.config.messagesTable || 'agent_messages',
|
|
106
|
+
col: 'session_id',
|
|
107
|
+
},
|
|
97
108
|
];
|
|
98
|
-
for (const
|
|
109
|
+
for (const target of coreIdentityTables) {
|
|
99
110
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await (0, sql_js_1.sql) `CREATE INDEX IF NOT EXISTS ${sql_js_1.sql.raw(indexName)} ON ${sql_js_1.sql.table(table)}(entity)`.execute(this.db);
|
|
104
|
-
applied.push(`Ensured index ${indexName} exists`);
|
|
105
|
-
}
|
|
106
|
-
// Heuristic: Index status and confidence for high-volume filtering
|
|
107
|
-
if (table === this.knowledgeTable) {
|
|
108
|
-
const indexName = `idx_${table}_status_conf`;
|
|
109
|
-
await (0, sql_js_1.sql) `CREATE INDEX IF NOT EXISTS ${sql_js_1.sql.raw(indexName)} ON ${sql_js_1.sql.table(table)}(status, confidence)`.execute(this.db);
|
|
110
|
-
applied.push(`Ensured index ${indexName} exists`);
|
|
111
|
-
}
|
|
111
|
+
const indexName = `idx_${target.table}_${target.col}_v2`;
|
|
112
|
+
await (0, sql_js_1.sql) `CREATE INDEX IF NOT EXISTS ${sql_js_1.sql.raw(indexName)} ON ${sql_js_1.sql.table(target.table)}(${sql_js_1.sql.raw(target.col)})`.execute(this.db);
|
|
113
|
+
applied.push(`Standardized identity index: ${indexName}`);
|
|
112
114
|
}
|
|
113
115
|
catch (err) {
|
|
114
|
-
console.warn(`[CortexJanitor]
|
|
116
|
+
console.warn(`[CortexJanitor] Identity indexing failed for ${target.table}:`, err);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 2. Data-Driven Heuristics: Hotspot Injection
|
|
120
|
+
// We look for tables mentioned in slow-query metrics recently
|
|
121
|
+
const slowQueries = await this.db
|
|
122
|
+
.selectFrom(this.metricsTable)
|
|
123
|
+
.select('metadata')
|
|
124
|
+
.where('metric_name', '=', 'query_latency')
|
|
125
|
+
.where('metric_value', '>', 300) // Slower than 300ms
|
|
126
|
+
.limit(50)
|
|
127
|
+
.execute();
|
|
128
|
+
const tablesToRemoveFriction = new Set();
|
|
129
|
+
for (const q of slowQueries) {
|
|
130
|
+
try {
|
|
131
|
+
const meta = typeof q.metadata === 'string'
|
|
132
|
+
? JSON.parse(q.metadata)
|
|
133
|
+
: q.metadata || {};
|
|
134
|
+
if (meta.table)
|
|
135
|
+
tablesToRemoveFriction.add(meta.table);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
/* ignore */
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const table of tablesToRemoveFriction) {
|
|
142
|
+
// Hotspot logic: if it's high-traffic knowledge, index the status/confidence pair for promoting/demoting
|
|
143
|
+
if (table === this.knowledgeTable) {
|
|
144
|
+
const indexName = `idx_${table}_hotspot_lifecycle`;
|
|
145
|
+
await (0, sql_js_1.sql) `CREATE INDEX IF NOT EXISTS ${sql_js_1.sql.raw(indexName)} ON ${sql_js_1.sql.table(table)}(status, confidence)`.execute(this.db);
|
|
146
|
+
applied.push(`Injected hotspot index for lifecycle: ${indexName}`);
|
|
115
147
|
}
|
|
116
148
|
}
|
|
117
149
|
if (applied.length > 0) {
|
|
118
|
-
await this.logRitual('optimization', 'success', {
|
|
150
|
+
await this.logRitual('optimization', 'success', {
|
|
151
|
+
action: 'autonomous_indexing',
|
|
152
|
+
applied_count: applied.length,
|
|
153
|
+
});
|
|
119
154
|
}
|
|
120
155
|
return applied;
|
|
121
156
|
}
|
|
@@ -133,7 +168,9 @@ class CortexJanitor {
|
|
|
133
168
|
else if (dialect.includes('postgres')) {
|
|
134
169
|
await (0, sql_js_1.sql) `ANALYZE`.execute(this.db);
|
|
135
170
|
}
|
|
136
|
-
await this.logRitual('optimization', 'success', {
|
|
171
|
+
await this.logRitual('optimization', 'success', {
|
|
172
|
+
action: 'db_maintenance',
|
|
173
|
+
});
|
|
137
174
|
}
|
|
138
175
|
async logRitual(type, status, metadata) {
|
|
139
176
|
try {
|
|
@@ -144,7 +181,7 @@ class CortexJanitor {
|
|
|
144
181
|
type,
|
|
145
182
|
status,
|
|
146
183
|
last_run: new Date(),
|
|
147
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
184
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
148
185
|
})
|
|
149
186
|
.execute();
|
|
150
187
|
}
|
|
@@ -12,7 +12,7 @@ export declare class CuriosityEngine {
|
|
|
12
12
|
private get typedDb();
|
|
13
13
|
/**
|
|
14
14
|
* Analyze current knowledge to identify "Gaps" or contradictions.
|
|
15
|
-
* Detects entities with low confidence or competing high-confidence facts.
|
|
15
|
+
* Detects entities with low confidence, unverified status, or competing high-confidence facts.
|
|
16
16
|
*/
|
|
17
17
|
identifyKnowledgeGaps(): Promise<{
|
|
18
18
|
entity: string;
|
|
@@ -36,7 +36,7 @@ export declare class CuriosityEngine {
|
|
|
36
36
|
suggestQuestions(entity: string): Promise<string[]>;
|
|
37
37
|
/**
|
|
38
38
|
* Generate "Relationship Hypotheses" between high-confidence entities.
|
|
39
|
-
* Suggests that entities with
|
|
39
|
+
* Suggests that entities with multi-tag overlaps might be related.
|
|
40
40
|
*/
|
|
41
41
|
generateHypotheses(): Promise<string[]>;
|
|
42
42
|
/**
|