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