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