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
|
@@ -19,7 +19,7 @@ export class RitualOrchestrator {
|
|
|
19
19
|
*/
|
|
20
20
|
async scheduleRitual(name, type, frequency, definition, metadata) {
|
|
21
21
|
const nextRun = this.calculateNextRun(frequency);
|
|
22
|
-
const ritual = await this.db
|
|
22
|
+
const ritual = (await this.db
|
|
23
23
|
.insertInto(this.ritualsTable)
|
|
24
24
|
.values({
|
|
25
25
|
name,
|
|
@@ -28,10 +28,10 @@ export class RitualOrchestrator {
|
|
|
28
28
|
definition,
|
|
29
29
|
next_run: nextRun,
|
|
30
30
|
status: 'pending',
|
|
31
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
31
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
32
32
|
})
|
|
33
33
|
.returningAll()
|
|
34
|
-
.executeTakeFirstOrThrow();
|
|
34
|
+
.executeTakeFirstOrThrow());
|
|
35
35
|
return this.parseRitual(ritual);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -40,41 +40,47 @@ export class RitualOrchestrator {
|
|
|
40
40
|
async runPendingRituals() {
|
|
41
41
|
const now = new Date();
|
|
42
42
|
const lockTimeout = new Date(now.getTime() + 600000); // 10 min lock by default
|
|
43
|
-
|
|
44
|
-
const
|
|
43
|
+
const pending = await this.db.transaction().execute(async (trx) => {
|
|
44
|
+
const due = (await trx
|
|
45
45
|
.selectFrom(this.ritualsTable)
|
|
46
46
|
.selectAll()
|
|
47
47
|
.where('next_run', '<=', now)
|
|
48
48
|
.where('status', 'in', ['pending', 'success', 'failure'])
|
|
49
49
|
.where((eb) => eb.or([
|
|
50
50
|
eb('locked_until', '<=', now),
|
|
51
|
-
eb('locked_until', 'is', null)
|
|
51
|
+
eb('locked_until', 'is', null),
|
|
52
52
|
]))
|
|
53
|
-
.execute();
|
|
54
|
-
if (
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
for (const ritual of pending) {
|
|
53
|
+
.execute());
|
|
54
|
+
if (due.length === 0)
|
|
55
|
+
return [];
|
|
56
|
+
for (const ritual of due) {
|
|
58
57
|
// Production Hardening: Distributed Lock
|
|
59
58
|
await trx
|
|
60
59
|
.updateTable(this.ritualsTable)
|
|
61
60
|
.set({ locked_until: lockTimeout })
|
|
62
61
|
.where('id', '=', ritual.id)
|
|
63
62
|
.execute();
|
|
64
|
-
// Execute out-of-transaction to avoid long-held locks if sub-tasks are slow
|
|
65
|
-
// but we await it here for the summary count.
|
|
66
|
-
// In a highly parallel system, this might be sent to a worker queue.
|
|
67
|
-
await this.executeRitual(ritual);
|
|
68
63
|
}
|
|
69
|
-
return
|
|
64
|
+
return due;
|
|
70
65
|
});
|
|
66
|
+
if (pending.length === 0)
|
|
67
|
+
return 0;
|
|
68
|
+
console.log(`[RitualOrchestrator] Found ${pending.length} pending rituals due. Locking for execution...`);
|
|
69
|
+
for (const ritual of pending) {
|
|
70
|
+
// Execute out-of-transaction to avoid long-held locks if sub-tasks are slow
|
|
71
|
+
await this.executeRitual(ritual);
|
|
72
|
+
}
|
|
73
|
+
return pending.length;
|
|
71
74
|
}
|
|
72
75
|
/**
|
|
73
76
|
* Execute a specific ritual
|
|
74
77
|
*/
|
|
75
78
|
async executeRitual(ritual) {
|
|
76
79
|
console.log(`[RitualOrchestrator] Executing ritual: ${ritual.name} (${ritual.type})`);
|
|
77
|
-
const ritualMetadata = {
|
|
80
|
+
const ritualMetadata = {
|
|
81
|
+
...ritual.metadata,
|
|
82
|
+
startedAt: new Date(),
|
|
83
|
+
};
|
|
78
84
|
let success = false;
|
|
79
85
|
try {
|
|
80
86
|
switch (ritual.type) {
|
|
@@ -85,15 +91,15 @@ export class RitualOrchestrator {
|
|
|
85
91
|
.select('id')
|
|
86
92
|
.where('status', '=', 'active')
|
|
87
93
|
.execute();
|
|
88
|
-
const compressionThreshold =
|
|
94
|
+
const compressionThreshold = this.config.contextWindowSize || 20;
|
|
89
95
|
let compressedCount = 0;
|
|
90
96
|
for (const session of activeSessions) {
|
|
91
97
|
const messagesTable = this.config.messagesTable || 'agent_messages';
|
|
92
|
-
const countResult = await this.db
|
|
98
|
+
const countResult = (await this.db
|
|
93
99
|
.selectFrom(messagesTable)
|
|
94
100
|
.select((eb) => eb.fn.countAll().as('count'))
|
|
95
101
|
.where('session_id', '=', session.id)
|
|
96
|
-
.executeTakeFirst();
|
|
102
|
+
.executeTakeFirst());
|
|
97
103
|
const count = Number(countResult?.count || 0);
|
|
98
104
|
if (count > compressionThreshold) {
|
|
99
105
|
await this.cortex.compressor.semanticPruning(session.id);
|
|
@@ -115,6 +121,12 @@ export class RitualOrchestrator {
|
|
|
115
121
|
ritualMetadata.prunedZombies = prunedZombies;
|
|
116
122
|
ritualMetadata.orphansCleaned = orphans;
|
|
117
123
|
break;
|
|
124
|
+
case 'evolution':
|
|
125
|
+
const evolutionResults = await this.cortex.evolutionRitual.execute();
|
|
126
|
+
ritualMetadata.synthesized = evolutionResults.synthesized;
|
|
127
|
+
ritualMetadata.broadcasted = evolutionResults.broadcasted;
|
|
128
|
+
ritualMetadata.domainsBoosted = evolutionResults.domainsSynced;
|
|
129
|
+
break;
|
|
118
130
|
}
|
|
119
131
|
success = true;
|
|
120
132
|
}
|
|
@@ -134,7 +146,7 @@ export class RitualOrchestrator {
|
|
|
134
146
|
last_run: new Date(),
|
|
135
147
|
next_run: nextRun,
|
|
136
148
|
locked_until: null, // Unlock
|
|
137
|
-
metadata: JSON.stringify(ritualMetadata)
|
|
149
|
+
metadata: JSON.stringify(ritualMetadata),
|
|
138
150
|
})
|
|
139
151
|
.where('id', '=', ritual.id)
|
|
140
152
|
.execute();
|
|
@@ -168,7 +180,7 @@ export class RitualOrchestrator {
|
|
|
168
180
|
lastRun: r.last_run ? new Date(r.last_run) : undefined,
|
|
169
181
|
nextRun: r.next_run ? new Date(r.next_run) : undefined,
|
|
170
182
|
lockedUntil: r.locked_until ? new Date(r.locked_until) : undefined,
|
|
171
|
-
metadata: typeof r.metadata === 'string' ? JSON.parse(r.metadata) : r.metadata
|
|
183
|
+
metadata: typeof r.metadata === 'string' ? JSON.parse(r.metadata) : r.metadata,
|
|
172
184
|
};
|
|
173
185
|
}
|
|
174
186
|
}
|
|
@@ -20,7 +20,7 @@ export class RuleEngine {
|
|
|
20
20
|
*/
|
|
21
21
|
async defineRule(tableName, operation, action, options = {}) {
|
|
22
22
|
return await this.db.transaction().execute(async (trx) => {
|
|
23
|
-
const rule = await trx
|
|
23
|
+
const rule = (await trx
|
|
24
24
|
.insertInto(this.rulesTable)
|
|
25
25
|
.values({
|
|
26
26
|
table_name: tableName,
|
|
@@ -31,10 +31,10 @@ export class RuleEngine {
|
|
|
31
31
|
script: options.script || null,
|
|
32
32
|
is_enabled: true,
|
|
33
33
|
metadata: options.metadata ? JSON.stringify(options.metadata) : null,
|
|
34
|
-
created_at: new Date()
|
|
34
|
+
created_at: new Date(),
|
|
35
35
|
})
|
|
36
36
|
.returningAll()
|
|
37
|
-
.executeTakeFirstOrThrow();
|
|
37
|
+
.executeTakeFirstOrThrow());
|
|
38
38
|
return this.parseRule(rule);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -51,7 +51,7 @@ export class RuleEngine {
|
|
|
51
51
|
return {
|
|
52
52
|
action: rule.action,
|
|
53
53
|
ruleId: rule.id,
|
|
54
|
-
reason: `Matched rule ${rule.id} (${rule.action})
|
|
54
|
+
reason: `Matched rule ${rule.id} (${rule.action})`,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -80,13 +80,10 @@ export class RuleEngine {
|
|
|
80
80
|
.selectFrom(this.rulesTable)
|
|
81
81
|
.selectAll()
|
|
82
82
|
.where('table_name', '=', tableName)
|
|
83
|
-
.where((eb) => eb.or([
|
|
84
|
-
eb('operation', '=', operation),
|
|
85
|
-
eb('operation', '=', 'all')
|
|
86
|
-
]))
|
|
83
|
+
.where((eb) => eb.or([eb('operation', '=', operation), eb('operation', '=', 'all')]))
|
|
87
84
|
.where('is_enabled', '=', true)
|
|
88
85
|
.execute();
|
|
89
|
-
return list.map(r => this.parseRule(r));
|
|
86
|
+
return list.map((r) => this.parseRule(r));
|
|
90
87
|
}
|
|
91
88
|
evaluateCondition(condition, data) {
|
|
92
89
|
// Simple condition parser: "key op value"
|
|
@@ -105,12 +102,18 @@ export class RuleEngine {
|
|
|
105
102
|
if (compareValue === 'false')
|
|
106
103
|
compareValue = false;
|
|
107
104
|
switch (op) {
|
|
108
|
-
case '==':
|
|
109
|
-
|
|
110
|
-
case '
|
|
111
|
-
|
|
112
|
-
case '
|
|
113
|
-
|
|
105
|
+
case '==':
|
|
106
|
+
return val == compareValue;
|
|
107
|
+
case '!=':
|
|
108
|
+
return val != compareValue;
|
|
109
|
+
case '>':
|
|
110
|
+
return val > compareValue;
|
|
111
|
+
case '<':
|
|
112
|
+
return val < compareValue;
|
|
113
|
+
case 'includes':
|
|
114
|
+
return String(val).includes(String(compareValue));
|
|
115
|
+
default:
|
|
116
|
+
return false;
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
parseRule(r) {
|
|
@@ -122,8 +125,10 @@ export class RuleEngine {
|
|
|
122
125
|
action: r.action,
|
|
123
126
|
priority: r.priority,
|
|
124
127
|
isEnabled: !!r.is_enabled,
|
|
125
|
-
metadata: typeof r.metadata === 'string'
|
|
126
|
-
|
|
128
|
+
metadata: typeof r.metadata === 'string'
|
|
129
|
+
? JSON.parse(r.metadata)
|
|
130
|
+
: r.metadata || {},
|
|
131
|
+
createdAt: new Date(r.created_at),
|
|
127
132
|
};
|
|
128
133
|
}
|
|
129
134
|
}
|
|
@@ -19,7 +19,8 @@ export class SelfEvolution {
|
|
|
19
19
|
this.config = config;
|
|
20
20
|
this.evolution = new SchemaEvolutionHelper(db);
|
|
21
21
|
this.typeGenerator = new TypeGenerator(config.introspection);
|
|
22
|
-
this.snapshotsTable =
|
|
22
|
+
this.snapshotsTable =
|
|
23
|
+
config.agentic?.metadata?.snapshotsTable || 'agent_snapshots';
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Ensure core agentic tables have telemetry columns like 'accessed_at'
|
|
@@ -30,13 +31,16 @@ export class SelfEvolution {
|
|
|
30
31
|
this.config.agentic?.messagesTable || 'agent_messages',
|
|
31
32
|
this.config.agentic?.memoriesTable || 'agent_memories',
|
|
32
33
|
this.config.agentic?.goalsTable || 'agent_goals',
|
|
33
|
-
this.config.agentic?.knowledgeTable || 'agent_knowledge_base'
|
|
34
|
+
this.config.agentic?.knowledgeTable || 'agent_knowledge_base',
|
|
34
35
|
];
|
|
35
36
|
for (const table of tables) {
|
|
36
37
|
try {
|
|
37
38
|
const introspector = this.db.introspection;
|
|
38
|
-
const tableInfo = await introspector
|
|
39
|
-
|
|
39
|
+
const tableInfo = await introspector
|
|
40
|
+
.getTables()
|
|
41
|
+
.then((ts) => ts.find((t) => t.name === table));
|
|
42
|
+
if (tableInfo &&
|
|
43
|
+
!tableInfo.columns.some((c) => c.name === 'accessed_at')) {
|
|
40
44
|
console.log(`[SelfEvolution] Adding 'accessed_at' column to ${table}`);
|
|
41
45
|
await sql `ALTER TABLE ${sql.table(table)} ADD COLUMN accessed_at TIMESTAMP`.execute(this.db);
|
|
42
46
|
}
|
|
@@ -107,9 +111,9 @@ export class SelfEvolution {
|
|
|
107
111
|
...options.metadata,
|
|
108
112
|
ddl,
|
|
109
113
|
is_auto: true,
|
|
110
|
-
timestamp: Date.now()
|
|
114
|
+
timestamp: Date.now(),
|
|
111
115
|
}),
|
|
112
|
-
created_at: new Date()
|
|
116
|
+
created_at: new Date(),
|
|
113
117
|
})
|
|
114
118
|
.execute();
|
|
115
119
|
// 2. Regenerate types
|
|
@@ -123,13 +127,13 @@ export class SelfEvolution {
|
|
|
123
127
|
const introspector = this.db.introspection;
|
|
124
128
|
const tables = await introspector.getTables();
|
|
125
129
|
const schemaInfo = {
|
|
126
|
-
tables: tables.map(t => ({
|
|
130
|
+
tables: tables.map((t) => ({
|
|
127
131
|
name: t.name,
|
|
128
132
|
columns: t.columns || [],
|
|
129
133
|
indexes: t.indexes || [],
|
|
130
|
-
foreignKeys: t.foreignKeys || []
|
|
134
|
+
foreignKeys: t.foreignKeys || [],
|
|
131
135
|
})),
|
|
132
|
-
relationships: []
|
|
136
|
+
relationships: [],
|
|
133
137
|
};
|
|
134
138
|
const generated = this.typeGenerator.generateTypes(schemaInfo);
|
|
135
139
|
if (this.config.agentic?.metadata?.typesOutputPath) {
|
|
@@ -153,12 +157,12 @@ export class SelfEvolution {
|
|
|
153
157
|
if (ctx.includes('slow') || ctx.includes('latency')) {
|
|
154
158
|
// Suggest index for metrics if they seem slow
|
|
155
159
|
if (ctx.includes('metrics')) {
|
|
156
|
-
await this.evolve(
|
|
160
|
+
await this.evolve('CREATE INDEX IF NOT EXISTS idx_metrics_fast_lookup ON agent_metrics(metric_name, created_at)');
|
|
157
161
|
return true;
|
|
158
162
|
}
|
|
159
163
|
// Suggest index for memories if semantic search is mentioned
|
|
160
164
|
if (ctx.includes('search') || ctx.includes('memory')) {
|
|
161
|
-
await this.evolve(
|
|
165
|
+
await this.evolve('CREATE INDEX IF NOT EXISTS idx_memories_session_time ON agent_memories(session_id, created_at)');
|
|
162
166
|
return true;
|
|
163
167
|
}
|
|
164
168
|
}
|
|
@@ -168,16 +172,16 @@ export class SelfEvolution {
|
|
|
168
172
|
* Get history of evolutions
|
|
169
173
|
*/
|
|
170
174
|
async getEvolutionHistory(limit = 10) {
|
|
171
|
-
const list = await this.db
|
|
175
|
+
const list = (await this.db
|
|
172
176
|
.selectFrom(this.snapshotsTable)
|
|
173
177
|
.selectAll()
|
|
174
178
|
.orderBy('created_at', 'desc')
|
|
175
179
|
.limit(limit)
|
|
176
|
-
.execute();
|
|
177
|
-
return list.map(s => ({
|
|
180
|
+
.execute());
|
|
181
|
+
return list.map((s) => ({
|
|
178
182
|
...s,
|
|
179
183
|
metadata: typeof s.metadata === 'string' ? JSON.parse(s.metadata) : s.metadata,
|
|
180
|
-
createdAt: new Date(s.createdAt)
|
|
184
|
+
createdAt: new Date(s.createdAt),
|
|
181
185
|
}));
|
|
182
186
|
}
|
|
183
187
|
/**
|
|
@@ -185,14 +189,16 @@ export class SelfEvolution {
|
|
|
185
189
|
*/
|
|
186
190
|
async rollbackToSnapshot(name) {
|
|
187
191
|
console.log(`[SelfEvolution] Initiating structural rollback to: ${name}`);
|
|
188
|
-
const snapshot = await this.db
|
|
192
|
+
const snapshot = (await this.db
|
|
189
193
|
.selectFrom(this.snapshotsTable)
|
|
190
194
|
.selectAll()
|
|
191
195
|
.where('name', '=', name)
|
|
192
|
-
.executeTakeFirst();
|
|
196
|
+
.executeTakeFirst());
|
|
193
197
|
if (!snapshot)
|
|
194
198
|
throw new Error(`Snapshot ${name} not found.`);
|
|
195
|
-
const metadata = typeof snapshot.metadata === 'string'
|
|
199
|
+
const metadata = typeof snapshot.metadata === 'string'
|
|
200
|
+
? JSON.parse(snapshot.metadata)
|
|
201
|
+
: snapshot.metadata || {};
|
|
196
202
|
if (metadata.ddl) {
|
|
197
203
|
const inverse = this.invertDDL(metadata.ddl);
|
|
198
204
|
if (inverse) {
|
|
@@ -23,11 +23,11 @@ export class SelfTestRegistry {
|
|
|
23
23
|
name,
|
|
24
24
|
script,
|
|
25
25
|
expected_outcome: expectedOutcome,
|
|
26
|
-
created_at: new Date()
|
|
26
|
+
created_at: new Date(),
|
|
27
27
|
})
|
|
28
28
|
.onConflict((oc) => oc.column('name').doUpdateSet({
|
|
29
29
|
script,
|
|
30
|
-
expected_outcome: expectedOutcome
|
|
30
|
+
expected_outcome: expectedOutcome,
|
|
31
31
|
}))
|
|
32
32
|
.execute();
|
|
33
33
|
}
|
|
@@ -35,10 +35,10 @@ export class SelfTestRegistry {
|
|
|
35
35
|
* Run all registered probes
|
|
36
36
|
*/
|
|
37
37
|
async runAllProbes() {
|
|
38
|
-
const probes = await this.db
|
|
38
|
+
const probes = (await this.db
|
|
39
39
|
.selectFrom('agent_logic_probes')
|
|
40
40
|
.selectAll()
|
|
41
|
-
.execute();
|
|
41
|
+
.execute());
|
|
42
42
|
const results = [];
|
|
43
43
|
for (const probe of probes) {
|
|
44
44
|
console.log(`[SelfTestRegistry] Running probe: ${probe.name}`);
|
|
@@ -59,9 +59,9 @@ export class SelfTestRegistry {
|
|
|
59
59
|
this.config.memoriesTable || 'agent_memories',
|
|
60
60
|
this.config.knowledgeTable || 'agent_knowledge_base',
|
|
61
61
|
this.config.actionsTable || 'agent_actions',
|
|
62
|
-
this.config.metricsTable || 'agent_metrics'
|
|
62
|
+
this.config.metricsTable || 'agent_metrics',
|
|
63
63
|
];
|
|
64
|
-
const missing = requiredSubsets.filter(req => !tables.some(t => t.name === req));
|
|
64
|
+
const missing = requiredSubsets.filter((req) => !tables.some((t) => t.name === req));
|
|
65
65
|
success = missing.length === 0;
|
|
66
66
|
break;
|
|
67
67
|
case 'check_memory_integrity':
|
|
@@ -94,47 +94,50 @@ export class SelfTestRegistry {
|
|
|
94
94
|
const orphanedKnowledge = await this.db
|
|
95
95
|
.selectFrom(knowledgeTable)
|
|
96
96
|
.where('source_session_id', 'is not', null)
|
|
97
|
-
.where((eb) => eb.not(eb.exists(eb
|
|
97
|
+
.where((eb) => eb.not(eb.exists(eb
|
|
98
|
+
.selectFrom(sessionsTbl)
|
|
98
99
|
.select('id')
|
|
99
100
|
.whereRef(`${knowledgeTable}.source_session_id`, '=', `${sessionsTbl}.id`))))
|
|
100
101
|
.execute();
|
|
101
102
|
const orphanedActions = await this.db
|
|
102
103
|
.selectFrom(actionsTable)
|
|
103
|
-
.where((eb) => eb.not(eb.exists(eb
|
|
104
|
+
.where((eb) => eb.not(eb.exists(eb
|
|
105
|
+
.selectFrom(sessionsTbl)
|
|
104
106
|
.select('id')
|
|
105
107
|
.whereRef(`${actionsTable}.session_id`, '=', `${sessionsTbl}.id`))))
|
|
106
108
|
.execute();
|
|
107
|
-
success =
|
|
109
|
+
success =
|
|
110
|
+
orphanedKnowledge.length === 0 && orphanedActions.length === 0;
|
|
108
111
|
break;
|
|
109
112
|
case 'check_performance_drift':
|
|
110
113
|
// Real check: Compare last 10 queries average with historical baseline
|
|
111
114
|
const metricsTbl = this.config.metricsTable || 'agent_metrics';
|
|
112
|
-
const recentMetrics = await this.db
|
|
115
|
+
const recentMetrics = (await this.db
|
|
113
116
|
.selectFrom(metricsTbl)
|
|
114
117
|
.select('execution_time')
|
|
115
118
|
.orderBy('created_at', 'desc')
|
|
116
119
|
.limit(20)
|
|
117
|
-
.execute();
|
|
120
|
+
.execute());
|
|
118
121
|
if (recentMetrics.length < 5) {
|
|
119
122
|
success = true; // Not enough data to determine drift
|
|
120
123
|
}
|
|
121
124
|
else {
|
|
122
125
|
const avgRecent = recentMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / recentMetrics.length;
|
|
123
126
|
// Baseline: Avg of previous 100 metrics excluding the most recent 20
|
|
124
|
-
const baselineMetrics = await this.db
|
|
127
|
+
const baselineMetrics = (await this.db
|
|
125
128
|
.selectFrom(metricsTbl)
|
|
126
129
|
.select('execution_time')
|
|
127
130
|
.orderBy('created_at', 'desc')
|
|
128
131
|
.offset(20)
|
|
129
132
|
.limit(100)
|
|
130
|
-
.execute();
|
|
133
|
+
.execute());
|
|
131
134
|
if (baselineMetrics.length === 0) {
|
|
132
135
|
success = avgRecent < 500; // Fallback threshold (500ms)
|
|
133
136
|
}
|
|
134
137
|
else {
|
|
135
138
|
const avgBaseline = baselineMetrics.reduce((sum, m) => sum + (m.execution_time || 0), 0) / baselineMetrics.length;
|
|
136
139
|
// Fail if recent performance is > 50% worse than baseline
|
|
137
|
-
success = avgRecent <
|
|
140
|
+
success = avgRecent < avgBaseline * 1.5;
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
break;
|
|
@@ -151,7 +154,7 @@ export class SelfTestRegistry {
|
|
|
151
154
|
.updateTable('agent_logic_probes')
|
|
152
155
|
.set({
|
|
153
156
|
last_run: new Date(),
|
|
154
|
-
last_status: success ? 'pass' : 'fail'
|
|
157
|
+
last_status: success ? 'pass' : 'fail',
|
|
155
158
|
})
|
|
156
159
|
.where('id', '=', probe.id)
|
|
157
160
|
.execute();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Kysely } from '../../kysely.js';
|
|
2
|
+
import type { AgenticConfig, AgentCapability, SkillSynthesisStrategy, SynthesisContext } from '../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../Cortex.js';
|
|
4
|
+
/**
|
|
5
|
+
* High-Throughput Tiered AI Synthesis Strategy.
|
|
6
|
+
* Orchestrates multiple model tiers for cost-effective ultra-scale evolution.
|
|
7
|
+
*/
|
|
8
|
+
declare class AISynthesisStrategy implements SkillSynthesisStrategy {
|
|
9
|
+
private cortex;
|
|
10
|
+
private synthesizer;
|
|
11
|
+
name: string;
|
|
12
|
+
constructor(cortex: Cortex, synthesizer: SkillSynthesizer);
|
|
13
|
+
synthesize(context: SynthesisContext): Promise<{
|
|
14
|
+
mutatedDescription: any;
|
|
15
|
+
mutatedMetadata: any;
|
|
16
|
+
version: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Batch Synthesis using FAST model (Pass 6)
|
|
20
|
+
*/
|
|
21
|
+
synthesizeBatch(contexts: SynthesisContext[]): Promise<{
|
|
22
|
+
tool: string;
|
|
23
|
+
mutation: any;
|
|
24
|
+
}[]>;
|
|
25
|
+
private buildMutationPrompt;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* SkillSynthesizer implements Pass 6 Ultra-Scale Orchestration.
|
|
29
|
+
*/
|
|
30
|
+
export declare class SkillSynthesizer {
|
|
31
|
+
private db;
|
|
32
|
+
private cortex;
|
|
33
|
+
private config;
|
|
34
|
+
private evolutionConfig;
|
|
35
|
+
private actionsTable;
|
|
36
|
+
strategy: AISynthesisStrategy;
|
|
37
|
+
totalTokensConsumed: number;
|
|
38
|
+
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Pass 6: Predictive Pre-warming Hook
|
|
41
|
+
* Called by CapabilityManager when an experimental skill nears promotion.
|
|
42
|
+
*/
|
|
43
|
+
preWarmSkill(name: string): Promise<void>;
|
|
44
|
+
discoverAndSynthesize(): Promise<AgentCapability[]>;
|
|
45
|
+
private registerMutation;
|
|
46
|
+
private pruneSandboxIfNeeded;
|
|
47
|
+
}
|
|
48
|
+
export {};
|