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
|
@@ -20,33 +20,34 @@ class CuriosityEngine {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Analyze current knowledge to identify "Gaps" or contradictions.
|
|
23
|
-
* Detects entities with low confidence or competing high-confidence facts.
|
|
23
|
+
* Detects entities with low confidence, unverified status, or competing high-confidence facts.
|
|
24
24
|
*/
|
|
25
25
|
async identifyKnowledgeGaps() {
|
|
26
26
|
console.log('[CuriosityEngine] Analyzing knowledge base for gaps and contradictions...');
|
|
27
27
|
const gaps = [];
|
|
28
|
-
// 1. Find entities with low confidence or unverified
|
|
29
|
-
const weakKnowledge = await this.typedDb
|
|
28
|
+
// 1. Find entities with low confidence or unverified/proposed status
|
|
29
|
+
const weakKnowledge = (await this.typedDb
|
|
30
30
|
.selectFrom(this.knowledgeTable)
|
|
31
31
|
.selectAll()
|
|
32
32
|
.where((eb) => eb.or([
|
|
33
|
-
eb('confidence', '<', 0.
|
|
34
|
-
eb('
|
|
35
|
-
eb
|
|
36
|
-
eb('tags', 'not like', '%"verified"%'),
|
|
37
|
-
eb('confidence', '<', 0.8)
|
|
38
|
-
])
|
|
33
|
+
eb('confidence', '<', 0.4), // Critical low confidence
|
|
34
|
+
eb('status', '=', 'proposed'), // Not yet verified by enough sessions
|
|
35
|
+
eb('status', '=', 'disputed'), // Flagged by contradiction logic
|
|
39
36
|
]))
|
|
40
|
-
.execute();
|
|
37
|
+
.execute());
|
|
41
38
|
for (const item of weakKnowledge) {
|
|
42
|
-
|
|
39
|
+
let type = 'unverified';
|
|
40
|
+
if (item.confidence < 0.4)
|
|
41
|
+
type = 'low_confidence';
|
|
42
|
+
if (item.status === 'disputed')
|
|
43
|
+
type = 'contradiction';
|
|
43
44
|
gaps.push({
|
|
44
45
|
entity: item.entity,
|
|
45
46
|
type,
|
|
46
|
-
details: `Fact "${item.fact}" is ${type}.
|
|
47
|
+
details: `Fact "${item.fact}" is ${type} (Status: ${item.status}, Confidence: ${item.confidence}).`,
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
|
-
// 2. Detect Contradictions: Same entity, multiple high
|
|
50
|
+
// 2. Detect Contradictions: Same entity, multiple facts with high overlap but different claims
|
|
50
51
|
const entities = await this.typedDb
|
|
51
52
|
.selectFrom(this.knowledgeTable)
|
|
52
53
|
.select('entity')
|
|
@@ -54,24 +55,22 @@ class CuriosityEngine {
|
|
|
54
55
|
.having((eb) => eb.fn.count('id'), '>', 1)
|
|
55
56
|
.execute();
|
|
56
57
|
for (const row of entities) {
|
|
57
|
-
const items = await this.typedDb
|
|
58
|
+
const items = (await this.typedDb
|
|
58
59
|
.selectFrom(this.knowledgeTable)
|
|
59
60
|
.selectAll()
|
|
60
61
|
.where('entity', '=', row.entity)
|
|
61
|
-
.where('confidence', '>', 0.
|
|
62
|
-
.execute();
|
|
62
|
+
.where('confidence', '>', 0.5)
|
|
63
|
+
.execute());
|
|
63
64
|
if (items.length > 1) {
|
|
64
|
-
// Semantic check: if they have high similarity but slightly different facts, it's a conflict
|
|
65
65
|
for (let i = 0; i < items.length; i++) {
|
|
66
66
|
for (let j = i + 1; j < items.length; j++) {
|
|
67
67
|
const similarity = (0, similarity_js_1.calculateSimilarity)(items[i].fact, items[j].fact);
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
if (similarity > 0.4 && similarity < 0.95) {
|
|
68
|
+
// Contradiction: Similar enough to be about same topic, but different enough to be conflicting
|
|
69
|
+
if (similarity > 0.35 && similarity < 0.85) {
|
|
71
70
|
gaps.push({
|
|
72
71
|
entity: row.entity,
|
|
73
72
|
type: 'contradiction',
|
|
74
|
-
details: `
|
|
73
|
+
details: `Subtle contradiction: "${items[i].fact}" vs "${items[j].fact}" (Similarity: ${(similarity * 100).toFixed(1)}%)`,
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
}
|
|
@@ -88,31 +87,36 @@ class CuriosityEngine {
|
|
|
88
87
|
async identifyKnowledgeHotspots() {
|
|
89
88
|
const metricsTable = this.config.metricsTable || 'agent_metrics';
|
|
90
89
|
// 1. Find entities with high hit counts in recent metrics
|
|
91
|
-
const topEntities = await this.db
|
|
90
|
+
const topEntities = (await this.db
|
|
92
91
|
.selectFrom(metricsTable)
|
|
93
|
-
.select([
|
|
92
|
+
.select([
|
|
93
|
+
'metric_name as entity',
|
|
94
|
+
(eb) => eb.fn.sum('metric_value').as('references'),
|
|
95
|
+
])
|
|
94
96
|
.where('metric_name', 'like', 'entity_hit_%')
|
|
95
97
|
.groupBy('metric_name')
|
|
96
98
|
.orderBy((eb) => eb.fn.sum('metric_value'), 'desc')
|
|
97
99
|
.limit(10)
|
|
98
|
-
.execute();
|
|
100
|
+
.execute());
|
|
99
101
|
const hotspots = [];
|
|
100
|
-
for (const
|
|
101
|
-
const entityName =
|
|
102
|
-
// 2.
|
|
103
|
-
const
|
|
102
|
+
for (const top of topEntities) {
|
|
103
|
+
const entityName = top.entity.replace('entity_hit_', '');
|
|
104
|
+
// 2. Cross-reference with fact density
|
|
105
|
+
const factCountResult = await this.typedDb
|
|
104
106
|
.selectFrom(this.knowledgeTable)
|
|
105
107
|
.select((eb) => eb.fn.count('id').as('count'))
|
|
106
108
|
.where('entity', '=', entityName)
|
|
107
109
|
.executeTakeFirst();
|
|
108
|
-
const factCount = Number(
|
|
109
|
-
const refs = Number(
|
|
110
|
-
|
|
110
|
+
const factCount = Number(factCountResult?.count || 0);
|
|
111
|
+
const refs = Number(top.references);
|
|
112
|
+
const density = factCount / (refs || 1);
|
|
113
|
+
// 3. Flag as hotspot if high usage but low knowledge
|
|
114
|
+
if (density < 0.2 || factCount < 2) {
|
|
111
115
|
hotspots.push({
|
|
112
116
|
entity: entityName,
|
|
113
117
|
references: refs,
|
|
114
|
-
density:
|
|
115
|
-
gap: `High
|
|
118
|
+
density: Number(density.toFixed(2)),
|
|
119
|
+
gap: `High cognitive overhead (${refs} refs) vs low factual density (${factCount} facts).`,
|
|
116
120
|
});
|
|
117
121
|
}
|
|
118
122
|
}
|
|
@@ -131,21 +135,21 @@ class CuriosityEngine {
|
|
|
131
135
|
return [
|
|
132
136
|
`What are the core attributes and defining characteristics of ${entity}?`,
|
|
133
137
|
`How does ${entity} relate to the broader system architecture?`,
|
|
134
|
-
`What are the primary use cases for ${entity} in the current context
|
|
138
|
+
`What are the primary use cases for ${entity} in the current context?`,
|
|
135
139
|
];
|
|
136
140
|
}
|
|
137
141
|
const questions = [];
|
|
138
|
-
const facts = knowledge.map(k => k.fact);
|
|
142
|
+
const facts = knowledge.map((k) => k.fact);
|
|
139
143
|
// Context-aware questions
|
|
140
144
|
questions.push(`Can we find more supporting evidence for: "${facts[0]}"?`);
|
|
141
|
-
const lowConfidenceItems = knowledge.filter(k => k.confidence < 0.6);
|
|
145
|
+
const lowConfidenceItems = knowledge.filter((k) => k.confidence < 0.6);
|
|
142
146
|
if (lowConfidenceItems.length > 0) {
|
|
143
147
|
questions.push(`Verify the accuracy of recent claims about ${entity}, specifically regarding "${lowConfidenceItems[0].fact}".`);
|
|
144
148
|
}
|
|
145
149
|
// Use tags to generate specific questions
|
|
146
150
|
const allTags = new Set();
|
|
147
|
-
knowledge.forEach(k => {
|
|
148
|
-
const tags = typeof k.tags === 'string' ? JSON.parse(k.tags) :
|
|
151
|
+
knowledge.forEach((k) => {
|
|
152
|
+
const tags = typeof k.tags === 'string' ? JSON.parse(k.tags) : k.tags || [];
|
|
149
153
|
tags.forEach((t) => allTags.add(t));
|
|
150
154
|
});
|
|
151
155
|
if (allTags.has('database')) {
|
|
@@ -165,39 +169,44 @@ class CuriosityEngine {
|
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
171
|
* Generate "Relationship Hypotheses" between high-confidence entities.
|
|
168
|
-
* Suggests that entities with
|
|
172
|
+
* Suggests that entities with multi-tag overlaps might be related.
|
|
169
173
|
*/
|
|
170
174
|
async generateHypotheses() {
|
|
171
175
|
console.log('[CuriosityEngine] Generating relationship hypotheses...');
|
|
172
176
|
// 1. Get high-confidence entities
|
|
173
|
-
const entities = await this.typedDb
|
|
177
|
+
const entities = (await this.typedDb
|
|
174
178
|
.selectFrom(this.knowledgeTable)
|
|
175
179
|
.select(['entity', 'tags'])
|
|
176
|
-
.where('confidence', '>', 0.
|
|
180
|
+
.where('confidence', '>', 0.7)
|
|
177
181
|
.where('tags', 'is not', null)
|
|
178
|
-
.execute();
|
|
182
|
+
.execute());
|
|
179
183
|
const hypotheses = [];
|
|
180
|
-
const
|
|
184
|
+
const entityTagsMap = new Map();
|
|
181
185
|
for (const row of entities) {
|
|
182
|
-
const tags = typeof row.tags === 'string' ? JSON.parse(row.tags) :
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
tagMap.set(tag, []);
|
|
186
|
-
tagMap.get(tag).push(row.entity);
|
|
186
|
+
const tags = typeof row.tags === 'string' ? JSON.parse(row.tags) : row.tags || [];
|
|
187
|
+
if (tags.length > 0) {
|
|
188
|
+
entityTagsMap.set(row.entity, new Set(tags));
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
191
|
+
const entityNames = Array.from(entityTagsMap.keys());
|
|
192
|
+
// 2. Identify entities sharing multiple matching tags (Density check)
|
|
193
|
+
for (let i = 0; i < entityNames.length; i++) {
|
|
194
|
+
for (let j = i + 1; j < entityNames.length; j++) {
|
|
195
|
+
const tagsI = entityTagsMap.get(entityNames[i]);
|
|
196
|
+
const tagsJ = entityTagsMap.get(entityNames[j]);
|
|
197
|
+
// intersection
|
|
198
|
+
const commonTags = [...tagsI].filter((t) => tagsJ.has(t));
|
|
199
|
+
if (commonTags.length >= 2) {
|
|
200
|
+
hypotheses.push(`[HYPOTHESIS] "${entityNames[i]}" and "${entityNames[j]}" share a dense tag set (${commonTags.join(', ')}). Is there a structural coupling?`);
|
|
201
|
+
}
|
|
202
|
+
else if (commonTags.length === 1 &&
|
|
203
|
+
(tagsI.size === 1 || tagsJ.size === 1)) {
|
|
204
|
+
// Specific probe for shared lone-tags
|
|
205
|
+
hypotheses.push(`[HYPOTHESIS] Both "${entityNames[i]}" and "${entityNames[j]}" are uniquely identified by "${commonTags[0]}". Might be aliases or sub-components.`);
|
|
197
206
|
}
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
|
-
return hypotheses.slice(0,
|
|
209
|
+
return hypotheses.slice(0, 10); // Limit to top 10
|
|
201
210
|
}
|
|
202
211
|
/**
|
|
203
212
|
* Propose a research ritual based on identified gaps, hotspots, and hypotheses.
|
|
@@ -217,12 +226,12 @@ class CuriosityEngine {
|
|
|
217
226
|
proposals.push(hypo);
|
|
218
227
|
}
|
|
219
228
|
// Production Hardening: Check for evolutionary density to suggest publication
|
|
220
|
-
const evolutionCountResult = await this.db
|
|
229
|
+
const evolutionCountResult = (await this.db
|
|
221
230
|
.selectFrom(this.config.metricsTable || 'agent_metrics')
|
|
222
231
|
.select((eb) => eb.fn.count('id').as('count'))
|
|
223
232
|
.where('metric_name', '=', 'evolution_applied')
|
|
224
233
|
.where('created_at', '>', new Date(Date.now() - 7 * 24 * 3600000)) // Last 7 days
|
|
225
|
-
.executeTakeFirst();
|
|
234
|
+
.executeTakeFirst());
|
|
226
235
|
const evolutions = Number(evolutionCountResult?.count || 0);
|
|
227
236
|
if (evolutions > 5) {
|
|
228
237
|
proposals.push(`[SOVEREIGN RITUAL] The engine has undergone ${evolutions} structural evolutions this week. Consider a 'Sovereign Publication Ritual' to update the registry.`);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Kysely } from '../../kysely.js';
|
|
2
|
+
import type { AgenticConfig } from '../../types/index.js';
|
|
3
|
+
import type { Cortex } from '../Cortex.js';
|
|
4
|
+
/**
|
|
5
|
+
* EvolutionRitual orchestrates the "Skill Growth" background task.
|
|
6
|
+
* It combines synthesis, domain synching, and global broadcasting
|
|
7
|
+
* into a single high-throughput maintenance cycle.
|
|
8
|
+
*/
|
|
9
|
+
export declare class EvolutionRitual {
|
|
10
|
+
private db;
|
|
11
|
+
private cortex;
|
|
12
|
+
private config;
|
|
13
|
+
constructor(db: Kysely<any>, cortex: Cortex, config?: AgenticConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Execute the full evolution sequence
|
|
16
|
+
*/
|
|
17
|
+
execute(): Promise<{
|
|
18
|
+
synthesized: number;
|
|
19
|
+
broadcasted: number;
|
|
20
|
+
domainsSynced: string[];
|
|
21
|
+
}>;
|
|
22
|
+
private checkDomainMaturity;
|
|
23
|
+
private identifyActiveDomains;
|
|
24
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EvolutionRitual = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* EvolutionRitual orchestrates the "Skill Growth" background task.
|
|
6
|
+
* It combines synthesis, domain synching, and global broadcasting
|
|
7
|
+
* into a single high-throughput maintenance cycle.
|
|
8
|
+
*/
|
|
9
|
+
class EvolutionRitual {
|
|
10
|
+
db;
|
|
11
|
+
cortex;
|
|
12
|
+
config;
|
|
13
|
+
constructor(db, cortex, config = {}) {
|
|
14
|
+
this.db = db;
|
|
15
|
+
this.cortex = cortex;
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Execute the full evolution sequence
|
|
20
|
+
*/
|
|
21
|
+
async execute() {
|
|
22
|
+
console.log('[EvolutionRitual] Initiating seamless skill growth sequence...');
|
|
23
|
+
const results = {
|
|
24
|
+
synthesized: 0,
|
|
25
|
+
broadcasted: 0,
|
|
26
|
+
domainsSynced: [],
|
|
27
|
+
};
|
|
28
|
+
// 1. Parallel Synthesis: Identify and bridge capability gaps
|
|
29
|
+
const newSkills = await this.cortex.skillSynthesizer.discoverAndSynthesize();
|
|
30
|
+
results.synthesized = newSkills.length;
|
|
31
|
+
// 2. High-Throughput Broadcasting: Propagate verified mutations globally
|
|
32
|
+
const broadcastedCount = await this.cortex.hive.broadcastSkills();
|
|
33
|
+
results.broadcasted = broadcastedCount;
|
|
34
|
+
// 3. Domain Synchronization: Identify "mastery" domains and boost global confidence
|
|
35
|
+
const activeDomains = await this.identifyActiveDomains();
|
|
36
|
+
for (const domain of activeDomains) {
|
|
37
|
+
// High Throughput Pass 5: Wholesale Domain Mastery
|
|
38
|
+
const isMature = await this.checkDomainMaturity(domain);
|
|
39
|
+
if (isMature) {
|
|
40
|
+
console.log(`[EvolutionRitual] Domain '${domain}' is MATURE. Applying wholesale stability boost.`);
|
|
41
|
+
await this.cortex.hive.syncDomain(domain, 0.15); // Higher boost for mastery
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await this.cortex.hive.syncDomain(domain, 0.05); // Standard boost
|
|
45
|
+
}
|
|
46
|
+
results.domainsSynced.push(domain);
|
|
47
|
+
}
|
|
48
|
+
console.log(`[EvolutionRitual] Completed: ${results.synthesized} synthesized, ${results.broadcasted} broadcasted, ${results.domainsSynced.length} domains boosted.`);
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
async checkDomainMaturity(domain) {
|
|
52
|
+
const skills = (await this.db
|
|
53
|
+
.selectFrom(this.config.capabilitiesTable || 'agent_capabilities')
|
|
54
|
+
.select(['reliability'])
|
|
55
|
+
.where('name', 'like', `${domain}%`)
|
|
56
|
+
.execute());
|
|
57
|
+
if (skills.length < 3)
|
|
58
|
+
return false; // Need a minimum population for maturity
|
|
59
|
+
const avgReliability = skills.reduce((sum, s) => sum + s.reliability, 0) / skills.length;
|
|
60
|
+
return avgReliability >= 0.95;
|
|
61
|
+
}
|
|
62
|
+
async identifyActiveDomains() {
|
|
63
|
+
// Production Hardening: Entropy-Based Discovery
|
|
64
|
+
// Find domains that are currently "hot" (high density of recent knowledge)
|
|
65
|
+
// This represents areas where the agent is learning fast and needs stabilization.
|
|
66
|
+
const result = await this.db
|
|
67
|
+
.selectFrom(this.config.knowledgeTable || 'agent_knowledge_base')
|
|
68
|
+
.select(['tags', 'confidence'])
|
|
69
|
+
.where('updated_at', '>', new Date(Date.now() - 24 * 60 * 60 * 1000)) // Last 24h
|
|
70
|
+
.execute();
|
|
71
|
+
const domainScores = new Map();
|
|
72
|
+
for (const row of result) {
|
|
73
|
+
const tags = typeof row.tags === 'string' ? JSON.parse(row.tags) : row.tags || [];
|
|
74
|
+
for (const t of tags) {
|
|
75
|
+
if (t === 'hive_mind')
|
|
76
|
+
continue;
|
|
77
|
+
// Score based on confidence density: a mix of volume and high-quality signals
|
|
78
|
+
const current = domainScores.get(t) || 0;
|
|
79
|
+
domainScores.set(t, current + (row.confidence || 0));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Sort by total confidence density (Entropy/Activity proxy)
|
|
83
|
+
// Production Hardening: Only boost domains with significant activity (Threshold: 1.0)
|
|
84
|
+
return Array.from(domainScores.entries())
|
|
85
|
+
.filter(([_, score]) => score >= 1.0)
|
|
86
|
+
.sort((a, b) => b[1] - a[1])
|
|
87
|
+
.slice(0, 3)
|
|
88
|
+
.map(([tag]) => tag);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.EvolutionRitual = EvolutionRitual;
|
|
@@ -17,6 +17,11 @@ export declare class EvolutionaryPilot {
|
|
|
17
17
|
evolved: boolean;
|
|
18
18
|
changes: string[];
|
|
19
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Meta-Meta Evolution: Adjusts the hyperparameters of the SkillSynthesizer
|
|
22
|
+
* based on the systemic success or failure of recently verified skills.
|
|
23
|
+
*/
|
|
24
|
+
private tuneEmergentSkillHyperparameters;
|
|
20
25
|
private calculateZScore;
|
|
21
26
|
private optimizeLatency;
|
|
22
27
|
}
|
|
@@ -23,25 +23,32 @@ class EvolutionaryPilot {
|
|
|
23
23
|
const changes = [];
|
|
24
24
|
let evolved = false;
|
|
25
25
|
// 1. Full-Spectrum Observation
|
|
26
|
-
const metrics = [
|
|
26
|
+
const metrics = [
|
|
27
|
+
'query_latency',
|
|
28
|
+
'success_rate',
|
|
29
|
+
'total_cost',
|
|
30
|
+
'trust_signal',
|
|
31
|
+
];
|
|
27
32
|
const recentMetrics = await this.cortex.metrics.getRecentMetrics(100);
|
|
28
33
|
for (const metricName of metrics) {
|
|
29
34
|
const values = recentMetrics
|
|
30
|
-
.filter(m => m.metricName === metricName)
|
|
31
|
-
.map(m => Number(m.metricValue));
|
|
35
|
+
.filter((m) => m.metricName === metricName)
|
|
36
|
+
.map((m) => Number(m.metricValue));
|
|
32
37
|
if (values.length < 5)
|
|
33
38
|
continue;
|
|
34
39
|
const stats = this.calculateZScore(values);
|
|
35
40
|
console.log(`[EvolutionaryPilot] Baselining ${metricName}: Mean=${stats.mean.toFixed(2)}, StdDev=${stats.stdDev.toFixed(2)}, Current=${stats.current.toFixed(2)}, Z-Score=${stats.zScore.toFixed(2)}`);
|
|
36
41
|
// 2. Trigger Evolution based on metric-specific thresholds
|
|
37
|
-
if (metricName === 'query_latency' &&
|
|
42
|
+
if (metricName === 'query_latency' &&
|
|
43
|
+
(stats.zScore > 2.0 || stats.mean > 1000)) {
|
|
38
44
|
const result = await this.optimizeLatency();
|
|
39
45
|
if (result) {
|
|
40
46
|
changes.push(...result);
|
|
41
47
|
evolved = true;
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
|
-
if (metricName === 'success_rate' &&
|
|
50
|
+
if (metricName === 'success_rate' &&
|
|
51
|
+
(stats.zScore < -1.5 || stats.mean < 0.7)) {
|
|
45
52
|
console.warn(`[EvolutionaryPilot] Success rate collapse detected (${stats.mean.toFixed(2)}). Triggering strategic mutation.`);
|
|
46
53
|
const strategies = await this.cortex.strategy.mutateStrategy();
|
|
47
54
|
changes.push(...strategies);
|
|
@@ -54,7 +61,13 @@ class EvolutionaryPilot {
|
|
|
54
61
|
evolved = true;
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
|
-
// 3.
|
|
64
|
+
// 3. Meta-Meta Evolution Tuning
|
|
65
|
+
const tuned = await this.tuneEmergentSkillHyperparameters(recentMetrics);
|
|
66
|
+
if (tuned) {
|
|
67
|
+
changes.push('Self-tuned emergent skill hyperparameters (Meta-Meta Evolution)');
|
|
68
|
+
evolved = true;
|
|
69
|
+
}
|
|
70
|
+
// 4. Verify: Perform an audit
|
|
58
71
|
const audit = await this.cortex.governor.performAudit();
|
|
59
72
|
if (!audit.healthy) {
|
|
60
73
|
console.warn('[EvolutionaryPilot] Evolution resulted in unhealthy state. Reverting may be required.');
|
|
@@ -62,6 +75,63 @@ class EvolutionaryPilot {
|
|
|
62
75
|
}
|
|
63
76
|
return { evolved, changes };
|
|
64
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Meta-Meta Evolution: Adjusts the hyperparameters of the SkillSynthesizer
|
|
80
|
+
* based on the systemic success or failure of recently verified skills.
|
|
81
|
+
*/
|
|
82
|
+
async tuneEmergentSkillHyperparameters(recentMetrics) {
|
|
83
|
+
console.log(`[EvolutionaryPilot] Running Meta-Meta Evolution tuning...`);
|
|
84
|
+
// Count how many skills are currently blacklisted vs verified
|
|
85
|
+
const blacklisted = await this.cortex.capabilities.getCapabilities('blacklisted');
|
|
86
|
+
const verified = await this.cortex.capabilities.getCapabilities('verified');
|
|
87
|
+
let tuned = false;
|
|
88
|
+
const config = this.config.evolution;
|
|
89
|
+
if (!config)
|
|
90
|
+
return false;
|
|
91
|
+
const totalSynthesized = blacklisted.length + verified.length;
|
|
92
|
+
if (totalSynthesized > 5) {
|
|
93
|
+
const successRate = verified.length / totalSynthesized;
|
|
94
|
+
// If we are succeeding often, increase mutation aggressiveness and allow more sandbox skills
|
|
95
|
+
if (successRate > 0.7) {
|
|
96
|
+
if ((config.mutationAggressiveness || 0) < 0.9) {
|
|
97
|
+
config.mutationAggressiveness = Math.min(1.0, (config.mutationAggressiveness || 0.5) + 0.1);
|
|
98
|
+
console.log(`[EvolutionaryPilot] High skill synthesis success. Increased mutation aggressiveness to ${config.mutationAggressiveness.toFixed(2)}`);
|
|
99
|
+
tuned = true;
|
|
100
|
+
}
|
|
101
|
+
if ((config.maxSandboxSkills || 5) < 15) {
|
|
102
|
+
config.maxSandboxSkills = (config.maxSandboxSkills || 5) + 2;
|
|
103
|
+
console.log(`[EvolutionaryPilot] High skill synthesis success. Increased sandbox capacity to ${config.maxSandboxSkills}`);
|
|
104
|
+
tuned = true;
|
|
105
|
+
}
|
|
106
|
+
// We can afford shorter verification windows
|
|
107
|
+
if ((config.verificationWindow || 20) > 10) {
|
|
108
|
+
config.verificationWindow = Math.max(10, (config.verificationWindow || 20) - 2);
|
|
109
|
+
console.log(`[EvolutionaryPilot] Shortened verification window to ${config.verificationWindow}`);
|
|
110
|
+
tuned = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// If we are failing often, become more conservative
|
|
114
|
+
else if (successRate < 0.3) {
|
|
115
|
+
if ((config.mutationAggressiveness || 0) > 0.1) {
|
|
116
|
+
config.mutationAggressiveness = Math.max(0.1, (config.mutationAggressiveness || 0.5) - 0.1);
|
|
117
|
+
console.log(`[EvolutionaryPilot] Low skill synthesis success. Decreased mutation aggressiveness to ${config.mutationAggressiveness.toFixed(2)}`);
|
|
118
|
+
tuned = true;
|
|
119
|
+
}
|
|
120
|
+
if ((config.maxSandboxSkills || 5) > 2) {
|
|
121
|
+
config.maxSandboxSkills = Math.max(2, (config.maxSandboxSkills || 5) - 1);
|
|
122
|
+
console.log(`[EvolutionaryPilot] Low skill synthesis success. Decreased sandbox capacity to ${config.maxSandboxSkills}`);
|
|
123
|
+
tuned = true;
|
|
124
|
+
}
|
|
125
|
+
// Safety requires longer verification windows
|
|
126
|
+
if ((config.verificationWindow || 20) < 50) {
|
|
127
|
+
config.verificationWindow = Math.min(50, (config.verificationWindow || 20) + 5);
|
|
128
|
+
console.log(`[EvolutionaryPilot] Lengthened verification window to ${config.verificationWindow}`);
|
|
129
|
+
tuned = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return tuned;
|
|
134
|
+
}
|
|
65
135
|
calculateZScore(values) {
|
|
66
136
|
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
67
137
|
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / values.length;
|
|
@@ -74,7 +144,10 @@ class EvolutionaryPilot {
|
|
|
74
144
|
const changes = [];
|
|
75
145
|
console.log(`[EvolutionaryPilot] Triggering latency optimization...`);
|
|
76
146
|
const dialect = this.db.getExecutor().dialect;
|
|
77
|
-
const isSqlite = this.db
|
|
147
|
+
const isSqlite = this.db
|
|
148
|
+
.getExecutor()
|
|
149
|
+
.adapter.constructor.name.toLowerCase()
|
|
150
|
+
.includes('sqlite') ||
|
|
78
151
|
(dialect && dialect.constructor.name.toLowerCase().includes('sqlite'));
|
|
79
152
|
if (isSqlite) {
|
|
80
153
|
await (0, sql_js_1.sql) `PRAGMA optimize`.execute(this.db);
|
|
@@ -46,8 +46,8 @@ export declare class GoalArchitect {
|
|
|
46
46
|
pendingSubGoals: number;
|
|
47
47
|
}>;
|
|
48
48
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
* Identify goals that have "stalled" (no status changes in > 7 days)
|
|
50
|
+
*/
|
|
51
51
|
trackStalledGoals(daysThreshold?: number): Promise<AgentGoal[]>;
|
|
52
52
|
private parseGoal;
|
|
53
53
|
}
|
|
@@ -22,11 +22,11 @@ class GoalArchitect {
|
|
|
22
22
|
*/
|
|
23
23
|
async deconstructGoal(goalId, subGoals) {
|
|
24
24
|
return await this.db.transaction().execute(async (trx) => {
|
|
25
|
-
const goal = await trx
|
|
25
|
+
const goal = (await trx
|
|
26
26
|
.selectFrom(this.goalsTable)
|
|
27
27
|
.selectAll()
|
|
28
28
|
.where('id', '=', goalId)
|
|
29
|
-
.executeTakeFirst();
|
|
29
|
+
.executeTakeFirst());
|
|
30
30
|
if (!goal)
|
|
31
31
|
throw new Error(`Goal ${goalId} not found`);
|
|
32
32
|
console.log(`[GoalArchitect] Deconstructing goal ${goalId}: "${goal.description}" into ${subGoals.length} steps.`);
|
|
@@ -35,7 +35,7 @@ class GoalArchitect {
|
|
|
35
35
|
const basePriority = (goal.priority || 0) + 1;
|
|
36
36
|
for (let i = 0; i < subGoals.length; i++) {
|
|
37
37
|
const desc = subGoals[i];
|
|
38
|
-
const subGoal = await trx
|
|
38
|
+
const subGoal = (await trx
|
|
39
39
|
.insertInto(this.goalsTable)
|
|
40
40
|
.values({
|
|
41
41
|
session_id: goal.session_id,
|
|
@@ -44,10 +44,10 @@ class GoalArchitect {
|
|
|
44
44
|
status: 'pending',
|
|
45
45
|
priority: basePriority + i, // Sequential priority
|
|
46
46
|
created_at: new Date(),
|
|
47
|
-
updated_at: new Date()
|
|
47
|
+
updated_at: new Date(),
|
|
48
48
|
})
|
|
49
49
|
.returningAll()
|
|
50
|
-
.executeTakeFirstOrThrow();
|
|
50
|
+
.executeTakeFirstOrThrow());
|
|
51
51
|
created.push(this.parseGoal(subGoal));
|
|
52
52
|
}
|
|
53
53
|
// Update parent status to in_progress if it was pending
|
|
@@ -91,18 +91,18 @@ class GoalArchitect {
|
|
|
91
91
|
const newMeta = {
|
|
92
92
|
...currentMeta,
|
|
93
93
|
lastStatusChange: Date.now(),
|
|
94
|
-
outcome: outcome || currentMeta.outcome
|
|
94
|
+
outcome: outcome || currentMeta.outcome,
|
|
95
95
|
};
|
|
96
|
-
const updated = await this.db
|
|
96
|
+
const updated = (await this.db
|
|
97
97
|
.updateTable(this.goalsTable)
|
|
98
98
|
.set({
|
|
99
99
|
status,
|
|
100
100
|
metadata: JSON.stringify(newMeta),
|
|
101
|
-
updated_at: new Date()
|
|
101
|
+
updated_at: new Date(),
|
|
102
102
|
})
|
|
103
103
|
.where('id', '=', goalId)
|
|
104
104
|
.returningAll()
|
|
105
|
-
.executeTakeFirstOrThrow();
|
|
105
|
+
.executeTakeFirstOrThrow());
|
|
106
106
|
return this.parseGoal(updated);
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
@@ -118,28 +118,28 @@ class GoalArchitect {
|
|
|
118
118
|
if (subGoals.length === 0) {
|
|
119
119
|
return { canComplete: true, pendingSubGoals: 0 };
|
|
120
120
|
}
|
|
121
|
-
const pending = subGoals.filter(g => g.status !== 'completed' && g.status !== 'failed').length;
|
|
121
|
+
const pending = subGoals.filter((g) => g.status !== 'completed' && g.status !== 'failed').length;
|
|
122
122
|
return {
|
|
123
123
|
canComplete: pending === 0,
|
|
124
|
-
pendingSubGoals: pending
|
|
124
|
+
pendingSubGoals: pending,
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
* Identify goals that have "stalled" (no status changes in > 7 days)
|
|
129
|
+
*/
|
|
130
130
|
async trackStalledGoals(daysThreshold = 7) {
|
|
131
131
|
console.log('[GoalArchitect] Identifying stalled objectives...');
|
|
132
132
|
const thresholdDate = new Date(Date.now() - daysThreshold * 24 * 3600000);
|
|
133
|
-
const stalled = await this.typedDb
|
|
133
|
+
const stalled = (await this.typedDb
|
|
134
134
|
.selectFrom(this.goalsTable)
|
|
135
135
|
.selectAll()
|
|
136
136
|
.where('status', 'in', ['pending', 'in_progress'])
|
|
137
137
|
.where('updated_at', '<', thresholdDate)
|
|
138
|
-
.execute();
|
|
138
|
+
.execute());
|
|
139
139
|
if (stalled.length > 0) {
|
|
140
140
|
console.log(`[GoalArchitect] Identified ${stalled.length} stalled goals.`);
|
|
141
141
|
}
|
|
142
|
-
return stalled.map(g => this.parseGoal(g));
|
|
142
|
+
return stalled.map((g) => this.parseGoal(g));
|
|
143
143
|
}
|
|
144
144
|
parseGoal(g) {
|
|
145
145
|
return {
|
|
@@ -149,9 +149,11 @@ class GoalArchitect {
|
|
|
149
149
|
description: g.description,
|
|
150
150
|
status: g.status,
|
|
151
151
|
priority: g.priority,
|
|
152
|
-
metadata: typeof g.metadata === 'string'
|
|
152
|
+
metadata: typeof g.metadata === 'string'
|
|
153
|
+
? JSON.parse(g.metadata)
|
|
154
|
+
: g.metadata || {},
|
|
153
155
|
createdAt: new Date(g.created_at),
|
|
154
|
-
updatedAt: new Date(g.updated_at)
|
|
156
|
+
updatedAt: new Date(g.updated_at),
|
|
155
157
|
};
|
|
156
158
|
}
|
|
157
159
|
}
|