@gsep/core 0.8.0 → 1.0.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 +12 -12
- package/dist/{PGA.d.ts → GSEP.d.ts} +120 -8
- package/dist/GSEP.d.ts.map +1 -0
- package/dist/{PGA.js → GSEP.js} +1248 -46
- package/dist/GSEP.js.map +1 -0
- package/dist/adapters/langchain.d.ts +52 -0
- package/dist/adapters/langchain.d.ts.map +1 -0
- package/dist/adapters/langchain.js +89 -0
- package/dist/adapters/langchain.js.map +1 -0
- package/dist/adapters/openclaw-plugin.d.ts +42 -0
- package/dist/adapters/openclaw-plugin.d.ts.map +1 -0
- package/dist/adapters/openclaw-plugin.js +149 -0
- package/dist/adapters/openclaw-plugin.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +74 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +151 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/advanced-ai/EnhancedSelfModel.js +2 -2
- package/dist/advanced-ai/EnhancedSelfModel.js.map +1 -1
- package/dist/advanced-ai/ModelRouter.js.map +1 -1
- package/dist/auto.d.ts +6 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +197 -0
- package/dist/auto.js.map +1 -0
- package/dist/core/CoherenceValidator.d.ts +25 -0
- package/dist/core/CoherenceValidator.d.ts.map +1 -0
- package/dist/core/CoherenceValidator.js +182 -0
- package/dist/core/CoherenceValidator.js.map +1 -0
- package/dist/core/ContextMemory.d.ts.map +1 -1
- package/dist/core/ContextMemory.js +1 -1
- package/dist/core/ContextMemory.js.map +1 -1
- package/dist/core/DNAProfile.d.ts +5 -1
- package/dist/core/DNAProfile.d.ts.map +1 -1
- package/dist/core/DNAProfile.js +14 -1
- package/dist/core/DNAProfile.js.map +1 -1
- package/dist/core/GSEPIdentitySection.d.ts.map +1 -1
- package/dist/core/GSEPIdentitySection.js +12 -3
- package/dist/core/GSEPIdentitySection.js.map +1 -1
- package/dist/core/GenomeKernel.d.ts.map +1 -1
- package/dist/core/GenomeKernel.js +3 -0
- package/dist/core/GenomeKernel.js.map +1 -1
- package/dist/core/GenomeManager.js +1 -1
- package/dist/core/GenomeManager.js.map +1 -1
- package/dist/core/ProactiveSuggestions.js +1 -1
- package/dist/core/ProactiveSuggestions.js.map +1 -1
- package/dist/dashboard/DashboardServer.d.ts +64 -0
- package/dist/dashboard/DashboardServer.d.ts.map +1 -0
- package/dist/dashboard/DashboardServer.js +409 -0
- package/dist/dashboard/DashboardServer.js.map +1 -0
- package/dist/dashboard/DashboardToken.d.ts +16 -0
- package/dist/dashboard/DashboardToken.d.ts.map +1 -0
- package/dist/dashboard/DashboardToken.js +54 -0
- package/dist/dashboard/DashboardToken.js.map +1 -0
- package/dist/dashboard/dashboard.html +2731 -0
- package/dist/dashboard/index.d.ts +3 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +3 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/evaluation/BenchmarkSuites.d.ts +2 -2
- package/dist/evaluation/BenchmarkSuites.d.ts.map +1 -1
- package/dist/evaluation/BenchmarkSuites.js +6 -6
- package/dist/evaluation/BenchmarkSuites.js.map +1 -1
- package/dist/evaluation/ConstitutionalGate.d.ts +18 -0
- package/dist/evaluation/ConstitutionalGate.d.ts.map +1 -0
- package/dist/evaluation/ConstitutionalGate.js +149 -0
- package/dist/evaluation/ConstitutionalGate.js.map +1 -0
- package/dist/evaluation/Evaluator.d.ts +4 -4
- package/dist/evaluation/Evaluator.d.ts.map +1 -1
- package/dist/evaluation/Evaluator.js +27 -27
- package/dist/evaluation/Evaluator.js.map +1 -1
- package/dist/evaluation/EvolutionGuardrails.d.ts +3 -1
- package/dist/evaluation/EvolutionGuardrails.d.ts.map +1 -1
- package/dist/evaluation/EvolutionGuardrails.js +29 -11
- package/dist/evaluation/EvolutionGuardrails.js.map +1 -1
- package/dist/evolution/MutationOperator.d.ts +19 -6
- package/dist/evolution/MutationOperator.d.ts.map +1 -1
- package/dist/evolution/MutationOperator.js +264 -9
- package/dist/evolution/MutationOperator.js.map +1 -1
- package/dist/evolution/boost/operators/BreakthroughOperator.d.ts +1 -1
- package/dist/evolution/boost/operators/BreakthroughOperator.d.ts.map +1 -1
- package/dist/evolution/boost/operators/BreakthroughOperator.js.map +1 -1
- package/dist/evolution/boost/operators/CrossoverMutationOperator.d.ts +1 -1
- package/dist/evolution/boost/operators/CrossoverMutationOperator.d.ts.map +1 -1
- package/dist/evolution/boost/operators/CrossoverMutationOperator.js.map +1 -1
- package/dist/evolution/boost/operators/PatternExtractionOperator.d.ts +1 -1
- package/dist/evolution/boost/operators/PatternExtractionOperator.d.ts.map +1 -1
- package/dist/evolution/boost/operators/PatternExtractionOperator.js.map +1 -1
- package/dist/evolution/boost/operators/SemanticRestructuringOperator.d.ts +1 -1
- package/dist/evolution/boost/operators/SemanticRestructuringOperator.d.ts.map +1 -1
- package/dist/evolution/boost/operators/SemanticRestructuringOperator.js.map +1 -1
- package/dist/firewall/AnomalyDetector.d.ts +42 -0
- package/dist/firewall/AnomalyDetector.d.ts.map +1 -0
- package/dist/firewall/AnomalyDetector.js +181 -0
- package/dist/firewall/AnomalyDetector.js.map +1 -0
- package/dist/firewall/ContentFirewall.d.ts +5 -0
- package/dist/firewall/ContentFirewall.d.ts.map +1 -1
- package/dist/firewall/ContentFirewall.js +5 -0
- package/dist/firewall/ContentFirewall.js.map +1 -1
- package/dist/firewall/PurposeLock.d.ts +41 -0
- package/dist/firewall/PurposeLock.d.ts.map +1 -0
- package/dist/firewall/PurposeLock.js +199 -0
- package/dist/firewall/PurposeLock.js.map +1 -0
- package/dist/gene-bank/CognitiveGene.d.ts +118 -118
- package/dist/gene-bank/{PGAIntegration.d.ts → GSEPIntegration.d.ts} +10 -10
- package/dist/gene-bank/GSEPIntegration.d.ts.map +1 -0
- package/dist/gene-bank/{PGAIntegration.js → GSEPIntegration.js} +6 -6
- package/dist/gene-bank/GSEPIntegration.js.map +1 -0
- package/dist/gene-bank/GeneAdopter.d.ts +6 -6
- package/dist/gene-bank/GeneAdopter.d.ts.map +1 -1
- package/dist/gene-bank/GeneAdopter.js +2 -2
- package/dist/gene-bank/GeneAdopter.js.map +1 -1
- package/dist/gene-bank/GeneBank.d.ts +13 -9
- package/dist/gene-bank/GeneBank.d.ts.map +1 -1
- package/dist/gene-bank/GeneBank.js +8 -1
- package/dist/gene-bank/GeneBank.js.map +1 -1
- package/dist/gene-bank/GeneExtractor.d.ts +7 -7
- package/dist/gene-bank/GeneExtractor.d.ts.map +1 -1
- package/dist/gene-bank/GeneExtractor.js +1 -1
- package/dist/gene-bank/GeneExtractor.js.map +1 -1
- package/dist/gene-bank/GeneMatcher.d.ts +1 -1
- package/dist/gene-bank/GeneMatcher.d.ts.map +1 -1
- package/dist/gene-bank/MarketplaceClient.d.ts +17 -1
- package/dist/gene-bank/MarketplaceClient.d.ts.map +1 -1
- package/dist/gene-bank/MarketplaceClient.js +106 -35
- package/dist/gene-bank/MarketplaceClient.js.map +1 -1
- package/dist/gene-bank/MarketplaceMapper.d.ts +7 -0
- package/dist/gene-bank/MarketplaceMapper.d.ts.map +1 -0
- package/dist/gene-bank/MarketplaceMapper.js +95 -0
- package/dist/gene-bank/MarketplaceMapper.js.map +1 -0
- package/dist/gene-bank/MarketplaceTypes.d.ts +121 -0
- package/dist/gene-bank/MarketplaceTypes.d.ts.map +1 -0
- package/dist/gene-bank/MarketplaceTypes.js +2 -0
- package/dist/gene-bank/MarketplaceTypes.js.map +1 -0
- package/dist/gene-bank/SandboxTester.d.ts +3 -3
- package/dist/gene-bank/SandboxTester.d.ts.map +1 -1
- package/dist/gene-bank/adapters/InMemoryGeneStorage.d.ts +3 -3
- package/dist/gene-bank/adapters/InMemoryGeneStorage.d.ts.map +1 -1
- package/dist/gene-bank/adapters/PostgresGeneStorage.d.ts +4 -4
- package/dist/gene-bank/adapters/PostgresGeneStorage.d.ts.map +1 -1
- package/dist/gene-bank/adapters/PostgresGeneStorage.js.map +1 -1
- package/dist/gene-bank/adapters/SQLiteGeneStorage.d.ts +28 -0
- package/dist/gene-bank/adapters/SQLiteGeneStorage.d.ts.map +1 -0
- package/dist/gene-bank/adapters/SQLiteGeneStorage.js +158 -0
- package/dist/gene-bank/adapters/SQLiteGeneStorage.js.map +1 -0
- package/dist/gene-bank/index.d.ts +10 -7
- package/dist/gene-bank/index.d.ts.map +1 -1
- package/dist/gene-bank/index.js +8 -7
- package/dist/gene-bank/index.js.map +1 -1
- package/dist/immune/BehavioralImmuneSystem.d.ts +6 -0
- package/dist/immune/BehavioralImmuneSystem.d.ts.map +1 -1
- package/dist/immune/BehavioralImmuneSystem.js +6 -0
- package/dist/immune/BehavioralImmuneSystem.js.map +1 -1
- package/dist/index.d.ts +44 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/memory/LayeredMemory.d.ts +1 -1
- package/dist/memory/LayeredMemory.d.ts.map +1 -1
- package/dist/memory/LayeredMemory.js.map +1 -1
- package/dist/middleware/GSEPMiddleware.d.ts +57 -0
- package/dist/middleware/GSEPMiddleware.d.ts.map +1 -0
- package/dist/middleware/GSEPMiddleware.js +91 -0
- package/dist/middleware/GSEPMiddleware.js.map +1 -0
- package/dist/middleware/RuntimeDetector.d.ts +10 -0
- package/dist/middleware/RuntimeDetector.d.ts.map +1 -0
- package/dist/middleware/RuntimeDetector.js +70 -0
- package/dist/middleware/RuntimeDetector.js.map +1 -0
- package/dist/middleware/ServerlessAdapter.d.ts +23 -0
- package/dist/middleware/ServerlessAdapter.d.ts.map +1 -0
- package/dist/middleware/ServerlessAdapter.js +77 -0
- package/dist/middleware/ServerlessAdapter.js.map +1 -0
- package/dist/monitoring/AlertWebhooks.d.ts +17 -0
- package/dist/monitoring/AlertWebhooks.d.ts.map +1 -1
- package/dist/monitoring/AlertWebhooks.js.map +1 -1
- package/dist/monitoring/WeeklyReportGenerator.d.ts +73 -0
- package/dist/monitoring/WeeklyReportGenerator.d.ts.map +1 -0
- package/dist/monitoring/WeeklyReportGenerator.js +148 -0
- package/dist/monitoring/WeeklyReportGenerator.js.map +1 -0
- package/dist/rag/RAGEngine.d.ts +1 -1
- package/dist/rag/RAGEngine.d.ts.map +1 -1
- package/dist/rag/VectorStoreAdapter.d.ts +2 -2
- package/dist/rag/VectorStoreAdapter.d.ts.map +1 -1
- package/dist/rag/VectorStoreAdapter.js.map +1 -1
- package/dist/realtime/EventEmitter.d.ts +110 -17
- package/dist/realtime/EventEmitter.d.ts.map +1 -1
- package/dist/realtime/EventEmitter.js +3 -4
- package/dist/realtime/EventEmitter.js.map +1 -1
- package/dist/security/CapabilityBroker.d.ts +41 -0
- package/dist/security/CapabilityBroker.d.ts.map +1 -0
- package/dist/security/CapabilityBroker.js +125 -0
- package/dist/security/CapabilityBroker.js.map +1 -0
- package/dist/security/CommandExecutionGuard.d.ts +47 -0
- package/dist/security/CommandExecutionGuard.d.ts.map +1 -0
- package/dist/security/CommandExecutionGuard.js +175 -0
- package/dist/security/CommandExecutionGuard.js.map +1 -0
- package/dist/security/ComplianceExporter.d.ts +32 -0
- package/dist/security/ComplianceExporter.d.ts.map +1 -0
- package/dist/security/ComplianceExporter.js +129 -0
- package/dist/security/ComplianceExporter.js.map +1 -0
- package/dist/security/DataAccessTracker.d.ts +38 -0
- package/dist/security/DataAccessTracker.d.ts.map +1 -0
- package/dist/security/DataAccessTracker.js +71 -0
- package/dist/security/DataAccessTracker.js.map +1 -0
- package/dist/security/DataClassifier.d.ts +14 -0
- package/dist/security/DataClassifier.d.ts.map +1 -0
- package/dist/security/DataClassifier.js +146 -0
- package/dist/security/DataClassifier.js.map +1 -0
- package/dist/security/EncryptedConfigStore.d.ts +21 -0
- package/dist/security/EncryptedConfigStore.d.ts.map +1 -0
- package/dist/security/EncryptedConfigStore.js +119 -0
- package/dist/security/EncryptedConfigStore.js.map +1 -0
- package/dist/security/EnterprisePolicyEngine.d.ts +90 -0
- package/dist/security/EnterprisePolicyEngine.d.ts.map +1 -0
- package/dist/security/EnterprisePolicyEngine.js +240 -0
- package/dist/security/EnterprisePolicyEngine.js.map +1 -0
- package/dist/security/FileSystemBoundary.d.ts +33 -0
- package/dist/security/FileSystemBoundary.d.ts.map +1 -0
- package/dist/security/FileSystemBoundary.js +94 -0
- package/dist/security/FileSystemBoundary.js.map +1 -0
- package/dist/security/GDPREngine.d.ts +65 -0
- package/dist/security/GDPREngine.d.ts.map +1 -0
- package/dist/security/GDPREngine.js +180 -0
- package/dist/security/GDPREngine.js.map +1 -0
- package/dist/security/GenomeSecurityBridge.d.ts +47 -0
- package/dist/security/GenomeSecurityBridge.d.ts.map +1 -0
- package/dist/security/GenomeSecurityBridge.js +157 -0
- package/dist/security/GenomeSecurityBridge.js.map +1 -0
- package/dist/security/KeyHierarchy.d.ts +23 -0
- package/dist/security/KeyHierarchy.d.ts.map +1 -0
- package/dist/security/KeyHierarchy.js +78 -0
- package/dist/security/KeyHierarchy.js.map +1 -0
- package/dist/security/KeychainAdapter.d.ts +19 -0
- package/dist/security/KeychainAdapter.d.ts.map +1 -0
- package/dist/security/KeychainAdapter.js +104 -0
- package/dist/security/KeychainAdapter.js.map +1 -0
- package/dist/security/LLMProxyLayer.d.ts +63 -0
- package/dist/security/LLMProxyLayer.d.ts.map +1 -0
- package/dist/security/LLMProxyLayer.js +148 -0
- package/dist/security/LLMProxyLayer.js.map +1 -0
- package/dist/security/MFAProvider.d.ts +35 -0
- package/dist/security/MFAProvider.d.ts.map +1 -0
- package/dist/security/MFAProvider.js +174 -0
- package/dist/security/MFAProvider.js.map +1 -0
- package/dist/security/NetworkAuditLogger.d.ts +35 -0
- package/dist/security/NetworkAuditLogger.d.ts.map +1 -0
- package/dist/security/NetworkAuditLogger.js +99 -0
- package/dist/security/NetworkAuditLogger.js.map +1 -0
- package/dist/security/OutboundAllowlist.d.ts +33 -0
- package/dist/security/OutboundAllowlist.d.ts.map +1 -0
- package/dist/security/OutboundAllowlist.js +112 -0
- package/dist/security/OutboundAllowlist.js.map +1 -0
- package/dist/security/PIIRedactionEngine.d.ts +40 -0
- package/dist/security/PIIRedactionEngine.d.ts.map +1 -0
- package/dist/security/PIIRedactionEngine.js +232 -0
- package/dist/security/PIIRedactionEngine.js.map +1 -0
- package/dist/security/RBACEngine.d.ts +44 -0
- package/dist/security/RBACEngine.d.ts.map +1 -0
- package/dist/security/RBACEngine.js +209 -0
- package/dist/security/RBACEngine.js.map +1 -0
- package/dist/security/SOC2Controls.d.ts +37 -0
- package/dist/security/SOC2Controls.d.ts.map +1 -0
- package/dist/security/SOC2Controls.js +151 -0
- package/dist/security/SOC2Controls.js.map +1 -0
- package/dist/security/SecretRotationEngine.d.ts +46 -0
- package/dist/security/SecretRotationEngine.d.ts.map +1 -0
- package/dist/security/SecretRotationEngine.js +102 -0
- package/dist/security/SecretRotationEngine.js.map +1 -0
- package/dist/security/SecretsMigrator.d.ts +28 -0
- package/dist/security/SecretsMigrator.d.ts.map +1 -0
- package/dist/security/SecretsMigrator.js +170 -0
- package/dist/security/SecretsMigrator.js.map +1 -0
- package/dist/security/SecurityEventBus.d.ts +48 -0
- package/dist/security/SecurityEventBus.d.ts.map +1 -0
- package/dist/security/SecurityEventBus.js +105 -0
- package/dist/security/SecurityEventBus.js.map +1 -0
- package/dist/security/SecurityPresets.d.ts +42 -0
- package/dist/security/SecurityPresets.d.ts.map +1 -0
- package/dist/security/SecurityPresets.js +162 -0
- package/dist/security/SecurityPresets.js.map +1 -0
- package/dist/security/SkillManifest.d.ts +34 -0
- package/dist/security/SkillManifest.d.ts.map +1 -0
- package/dist/security/SkillManifest.js +91 -0
- package/dist/security/SkillManifest.js.map +1 -0
- package/dist/security/SkillSigner.d.ts +22 -0
- package/dist/security/SkillSigner.d.ts.map +1 -0
- package/dist/security/SkillSigner.js +80 -0
- package/dist/security/SkillSigner.js.map +1 -0
- package/dist/security/TamperProofAuditLog.d.ts +58 -0
- package/dist/security/TamperProofAuditLog.d.ts.map +1 -0
- package/dist/security/TamperProofAuditLog.js +214 -0
- package/dist/security/TamperProofAuditLog.js.map +1 -0
- package/dist/security/index.d.ts +27 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +27 -0
- package/dist/security/index.js.map +1 -0
- package/dist/skills/ProactiveEngine.d.ts +55 -0
- package/dist/skills/ProactiveEngine.d.ts.map +1 -0
- package/dist/skills/ProactiveEngine.js +201 -0
- package/dist/skills/ProactiveEngine.js.map +1 -0
- package/dist/skills/SkillExecutor.d.ts +21 -0
- package/dist/skills/SkillExecutor.d.ts.map +1 -0
- package/dist/skills/SkillExecutor.js +131 -0
- package/dist/skills/SkillExecutor.js.map +1 -0
- package/dist/skills/SkillRegistry.d.ts +47 -0
- package/dist/skills/SkillRegistry.d.ts.map +1 -0
- package/dist/skills/SkillRegistry.js +94 -0
- package/dist/skills/SkillRegistry.js.map +1 -0
- package/dist/skills/SkillRouter.d.ts +30 -0
- package/dist/skills/SkillRouter.d.ts.map +1 -0
- package/dist/skills/SkillRouter.js +113 -0
- package/dist/skills/SkillRouter.js.map +1 -0
- package/dist/skills/index.d.ts +9 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +5 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/types/GenomeV2.d.ts +12 -0
- package/dist/types/GenomeV2.d.ts.map +1 -1
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/wrap/FileStorageAdapter.d.ts +113 -0
- package/dist/wrap/FileStorageAdapter.d.ts.map +1 -0
- package/dist/wrap/FileStorageAdapter.js +239 -0
- package/dist/wrap/FileStorageAdapter.js.map +1 -0
- package/dist/wrap/SQLiteStorageAdapter.d.ts +96 -0
- package/dist/wrap/SQLiteStorageAdapter.d.ts.map +1 -0
- package/dist/wrap/SQLiteStorageAdapter.js +251 -0
- package/dist/wrap/SQLiteStorageAdapter.js.map +1 -0
- package/dist/wrap/WrappedAgent.d.ts +2 -2
- package/dist/wrap/WrappedAgent.d.ts.map +1 -1
- package/dist/wrap/WrappedAgent.js +7 -7
- package/dist/wrap/WrappedAgent.js.map +1 -1
- package/dist/wrap.d.ts +39 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +96 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +34 -7
- package/dist/PGA.d.ts.map +0 -1
- package/dist/PGA.js.map +0 -1
- package/dist/evolution/PromotionGate.d.ts +0 -45
- package/dist/evolution/PromotionGate.d.ts.map +0 -1
- package/dist/evolution/PromotionGate.js +0 -248
- package/dist/evolution/PromotionGate.js.map +0 -1
- package/dist/gene-bank/PGAIntegration.d.ts.map +0 -1
- package/dist/gene-bank/PGAIntegration.js.map +0 -1
package/dist/{PGA.js → GSEP.js}
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SQLiteStorageAdapter } from './wrap/SQLiteStorageAdapter.js';
|
|
2
|
+
import { getPreset } from './presets/ConfigPresets.js';
|
|
1
3
|
import { WrappedAgent } from './wrap/WrappedAgent.js';
|
|
2
4
|
import { GenomeManager } from './core/GenomeManager.js';
|
|
3
5
|
import { PromptAssembler } from './core/PromptAssembler.js';
|
|
@@ -29,6 +31,8 @@ import { CalibratedAutonomy } from './advanced-ai/CalibratedAutonomy.js';
|
|
|
29
31
|
import { PersonalNarrative } from './memory/PersonalNarrative.js';
|
|
30
32
|
import { AnalyticMemoryEngine } from './memory/AnalyticMemoryEngine.js';
|
|
31
33
|
import { MetaEvolutionEngine } from './evolution/boost/MetaEvolutionEngine.js';
|
|
34
|
+
import { GeneBank } from './gene-bank/GeneBank.js';
|
|
35
|
+
import { MarketplaceClient } from './gene-bank/MarketplaceClient.js';
|
|
32
36
|
import { CanaryDeploymentManager } from './evolution/CanaryDeployment.js';
|
|
33
37
|
import { EnhancedSelfModel } from './advanced-ai/EnhancedSelfModel.js';
|
|
34
38
|
import { PurposeSurvival } from './evolution/PurposeSurvival.js';
|
|
@@ -40,61 +44,73 @@ import { AutonomousLoop } from './advanced-ai/AutonomousLoop.js';
|
|
|
40
44
|
import { GrowthJournal } from './memory/GrowthJournal.js';
|
|
41
45
|
import { CuriosityEngine } from './memory/CuriosityEngine.js';
|
|
42
46
|
import { ContentFirewall } from './firewall/ContentFirewall.js';
|
|
47
|
+
import { PurposeLock } from './firewall/PurposeLock.js';
|
|
48
|
+
import { AnomalyDetector } from './firewall/AnomalyDetector.js';
|
|
49
|
+
import { SecurityEventBus } from './security/SecurityEventBus.js';
|
|
50
|
+
import { GenomeSecurityBridge } from './security/GenomeSecurityBridge.js';
|
|
51
|
+
import { getSecurityPreset } from './security/SecurityPresets.js';
|
|
52
|
+
import { SkillRegistry, SkillExecutor, SkillRouter, ProactiveEngine } from './skills/index.js';
|
|
53
|
+
import { GSEPMiddleware } from './middleware/GSEPMiddleware.js';
|
|
54
|
+
import { detectRuntime as detectRuntimeLevel } from './middleware/RuntimeDetector.js';
|
|
55
|
+
import { WeeklyReportGenerator } from './monitoring/WeeklyReportGenerator.js';
|
|
43
56
|
import { GenomeKernel } from './core/GenomeKernel.js';
|
|
44
57
|
import { BehavioralImmuneSystem } from './immune/BehavioralImmuneSystem.js';
|
|
58
|
+
import { GSEPEventEmitter } from './realtime/EventEmitter.js';
|
|
59
|
+
import { DashboardServer } from './dashboard/DashboardServer.js';
|
|
60
|
+
import { DashboardTokenHelper } from './dashboard/DashboardToken.js';
|
|
45
61
|
import { GSEPIdentitySection } from './core/GSEPIdentitySection.js';
|
|
46
62
|
import { GSEPActivityFooter } from './core/GSEPActivityFooter.js';
|
|
47
|
-
export class
|
|
48
|
-
|
|
63
|
+
export class GSEP {
|
|
64
|
+
gsepConfig;
|
|
49
65
|
genomeManager;
|
|
50
66
|
llm;
|
|
51
67
|
metricsCollector;
|
|
52
68
|
dashboard;
|
|
53
|
-
constructor(
|
|
54
|
-
this.
|
|
55
|
-
if (!
|
|
69
|
+
constructor(gsepConfig) {
|
|
70
|
+
this.gsepConfig = gsepConfig;
|
|
71
|
+
if (!gsepConfig.llm) {
|
|
56
72
|
throw new Error(`[GSEP] LLM adapter is required.\n\n`
|
|
57
73
|
+ `GSEP needs an AI model to function. Please provide an LLM adapter:\n\n`
|
|
58
|
-
+ ` import {
|
|
74
|
+
+ ` import { GSEP } from '@gsep/core';\n`
|
|
59
75
|
+ ` import { ClaudeAdapter } from '@gsep/adapters-llm-anthropic';\n\n`
|
|
60
|
-
+ ` const
|
|
76
|
+
+ ` const gsep = new GSEP({\n`
|
|
61
77
|
+ ` llm: new ClaudeAdapter({ apiKey: process.env.ANTHROPIC_API_KEY }),\n`
|
|
62
78
|
+ ` storage: yourStorageAdapter,\n`
|
|
63
79
|
+ ` });\n\n`
|
|
64
80
|
+ `Supported adapters:\n`
|
|
65
81
|
+ ` - @gsep/adapters-llm-anthropic (Claude)\n`
|
|
66
82
|
+ ` - @gsep/adapters-llm-openai (GPT-4)\n\n`
|
|
67
|
-
+ `Run '
|
|
83
|
+
+ `Run 'gsep doctor' for full diagnostics.`);
|
|
68
84
|
}
|
|
69
|
-
if (!
|
|
85
|
+
if (!gsepConfig.storage) {
|
|
70
86
|
throw new Error(`[GSEP] Storage adapter is required.\n\n`
|
|
71
87
|
+ `GSEP needs a storage adapter to persist genomes. Please provide one:\n\n`
|
|
72
88
|
+ ` import { InMemoryStorage } from '@gsep/core';\n\n`
|
|
73
|
-
+ ` const
|
|
89
|
+
+ ` const gsep = new GSEP({\n`
|
|
74
90
|
+ ` llm: yourLLMAdapter,\n`
|
|
75
91
|
+ ` storage: new InMemoryStorage(),\n`
|
|
76
92
|
+ ` });\n\n`
|
|
77
93
|
+ `For production, use: @gsep/adapters-storage-postgres`);
|
|
78
94
|
}
|
|
79
|
-
this.llm =
|
|
80
|
-
this.genomeManager = new GenomeManager(
|
|
81
|
-
this.metricsCollector = new MetricsCollector(
|
|
95
|
+
this.llm = gsepConfig.llm;
|
|
96
|
+
this.genomeManager = new GenomeManager(gsepConfig.storage);
|
|
97
|
+
this.metricsCollector = new MetricsCollector(gsepConfig.monitoring || {
|
|
82
98
|
enabled: true,
|
|
83
99
|
enableCostTracking: true,
|
|
84
100
|
enableAuditLogs: true,
|
|
85
101
|
});
|
|
86
|
-
if (
|
|
87
|
-
this.dashboard = new MonitoringDashboard(this.metricsCollector,
|
|
102
|
+
if (gsepConfig.dashboard?.enabled) {
|
|
103
|
+
this.dashboard = new MonitoringDashboard(this.metricsCollector, gsepConfig.dashboard);
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
106
|
async initialize() {
|
|
91
|
-
await this.
|
|
92
|
-
if (this.dashboard && this.
|
|
107
|
+
await this.gsepConfig.storage.initialize();
|
|
108
|
+
if (this.dashboard && this.gsepConfig.dashboard?.enabled) {
|
|
93
109
|
this.dashboard.start();
|
|
94
110
|
}
|
|
95
111
|
this.metricsCollector.logAudit({
|
|
96
112
|
level: 'info',
|
|
97
|
-
component: '
|
|
113
|
+
component: 'gsep',
|
|
98
114
|
operation: 'initialize',
|
|
99
115
|
message: 'GSEP system initialized successfully',
|
|
100
116
|
});
|
|
@@ -120,7 +136,7 @@ export class PGA {
|
|
|
120
136
|
}
|
|
121
137
|
this.metricsCollector.logAudit({
|
|
122
138
|
level: 'info',
|
|
123
|
-
component: '
|
|
139
|
+
component: 'gsep',
|
|
124
140
|
operation: 'shutdown',
|
|
125
141
|
message: 'GSEP system shutdown',
|
|
126
142
|
});
|
|
@@ -141,31 +157,31 @@ export class PGA {
|
|
|
141
157
|
enableSandbox: true,
|
|
142
158
|
mutationRate: 'balanced',
|
|
143
159
|
evolutionGuardrails: defaultGuardrails,
|
|
144
|
-
...this.
|
|
160
|
+
...this.gsepConfig.config,
|
|
145
161
|
...options.config,
|
|
146
162
|
},
|
|
147
163
|
});
|
|
148
|
-
if (this.
|
|
149
|
-
const bootstrap = new GenesisBootstrap(this.
|
|
164
|
+
if (this.gsepConfig.geneBank && genome.config.autonomous?.genesisBootstrap) {
|
|
165
|
+
const bootstrap = new GenesisBootstrap(this.gsepConfig.geneBank);
|
|
150
166
|
const result = await bootstrap.bootstrap(genome, genome.config.autonomous.bootstrapMinFitness ?? 0.7);
|
|
151
167
|
if (result.genesUpgraded > 0) {
|
|
152
|
-
await this.
|
|
168
|
+
await this.gsepConfig.storage.saveGenome(genome);
|
|
153
169
|
this.metricsCollector.logAudit({
|
|
154
170
|
level: 'info',
|
|
155
|
-
component: '
|
|
171
|
+
component: 'gsep',
|
|
156
172
|
operation: 'genesis-bootstrap',
|
|
157
173
|
message: `Bootstrapped ${result.genesUpgraded} genes from Gene Bank`,
|
|
158
174
|
metadata: { upgrades: result.upgrades },
|
|
159
175
|
});
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
|
-
return new GenomeInstance(genome, this.llm, this.
|
|
178
|
+
return new GenomeInstance(genome, this.llm, this.gsepConfig.storage, this.metricsCollector, this.gsepConfig.modelRouter, this.gsepConfig.rag, this.gsepConfig.reasoning, this.gsepConfig.geneBank, this.gsepConfig.marketplace);
|
|
163
179
|
}
|
|
164
180
|
async loadGenome(genomeId) {
|
|
165
181
|
const genome = await this.genomeManager.loadGenome(genomeId);
|
|
166
182
|
if (!genome)
|
|
167
183
|
return null;
|
|
168
|
-
return new GenomeInstance(genome, this.llm, this.
|
|
184
|
+
return new GenomeInstance(genome, this.llm, this.gsepConfig.storage, this.metricsCollector, this.gsepConfig.modelRouter, this.gsepConfig.rag, this.gsepConfig.reasoning, this.gsepConfig.geneBank, this.gsepConfig.marketplace);
|
|
169
185
|
}
|
|
170
186
|
async listGenomes() {
|
|
171
187
|
return this.genomeManager.listGenomes();
|
|
@@ -173,6 +189,197 @@ export class PGA {
|
|
|
173
189
|
async deleteGenome(genomeId) {
|
|
174
190
|
await this.genomeManager.deleteGenome(genomeId);
|
|
175
191
|
}
|
|
192
|
+
static async quickStart(options = {}) {
|
|
193
|
+
const runtimeDetection = (!options.provider && !options.llm)
|
|
194
|
+
? detectRuntimeLevel()
|
|
195
|
+
: undefined;
|
|
196
|
+
const { name = 'my-agent', preset = 'full', overrides, } = options;
|
|
197
|
+
const effectiveProvider = options.provider
|
|
198
|
+
?? runtimeDetection?.provider;
|
|
199
|
+
let llm;
|
|
200
|
+
if (options.llm) {
|
|
201
|
+
llm = options.llm;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const provider = effectiveProvider ?? GSEP.detectProvider(options.apiKey);
|
|
205
|
+
const apiKey = options.apiKey ?? GSEP.resolveApiKey(provider);
|
|
206
|
+
llm = await GSEP.createLLMAdapter(provider, apiKey, options.model, options.ollamaHost);
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
const { LLMProxyLayer } = await import('./security/LLMProxyLayer.js');
|
|
210
|
+
const { SecurityEventBus } = await import('./security/SecurityEventBus.js');
|
|
211
|
+
const shieldBus = new SecurityEventBus();
|
|
212
|
+
llm = new LLMProxyLayer(llm, {
|
|
213
|
+
enableRedaction: true,
|
|
214
|
+
eventBus: shieldBus,
|
|
215
|
+
localRouteThreshold: 'restricted',
|
|
216
|
+
});
|
|
217
|
+
console.log('[GSEP] 🧬 Shield active — PII redaction ON for all LLM traffic.');
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
}
|
|
221
|
+
const storage = options.storage ?? new SQLiteStorageAdapter({ agentName: name });
|
|
222
|
+
await storage.initialize();
|
|
223
|
+
const autonomous = overrides
|
|
224
|
+
? { ...getPreset(preset), ...overrides }
|
|
225
|
+
: getPreset(preset);
|
|
226
|
+
const purposeLock = options.purpose ? {
|
|
227
|
+
enabled: true,
|
|
228
|
+
purpose: options.purpose,
|
|
229
|
+
allowedTopics: options.allowedTopics,
|
|
230
|
+
forbiddenTopics: options.forbiddenTopics,
|
|
231
|
+
} : undefined;
|
|
232
|
+
let geneBank;
|
|
233
|
+
try {
|
|
234
|
+
const { SQLiteGeneStorage } = await import('./gene-bank/adapters/SQLiteGeneStorage.js');
|
|
235
|
+
const geneStorage = new SQLiteGeneStorage({ agentName: name });
|
|
236
|
+
await geneStorage.initialize();
|
|
237
|
+
geneBank = new GeneBank(geneStorage, {
|
|
238
|
+
tenantId: name,
|
|
239
|
+
agentId: name,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch { }
|
|
243
|
+
const gsep = new GSEP({ llm, storage, geneBank });
|
|
244
|
+
await gsep.initialize();
|
|
245
|
+
let genome;
|
|
246
|
+
const existingGenomes = await storage.listGenomes();
|
|
247
|
+
const existingGenome = existingGenomes.find(g => g.name === name);
|
|
248
|
+
const restored = existingGenome ? await gsep.loadGenome(existingGenome.id) : null;
|
|
249
|
+
if (restored) {
|
|
250
|
+
genome = restored;
|
|
251
|
+
await genome.rehydrate();
|
|
252
|
+
console.log(`[GSEP] Restored genome "${name}" (${existingGenome.id.slice(0, 12)}...)`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
genome = await gsep.createGenome({
|
|
256
|
+
name,
|
|
257
|
+
config: { autonomous, purposeLock },
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const dashboardUrl = await genome.startDashboard({ port: options.dashboardPort ?? 4200 });
|
|
262
|
+
console.log(`\n 🧬 GSEP is protecting this agent.`);
|
|
263
|
+
console.log(` 📊 Real-time dashboard: ${dashboardUrl}\n`);
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
}
|
|
267
|
+
if (options.skills) {
|
|
268
|
+
for (const skill of options.skills) {
|
|
269
|
+
if (typeof skill === 'string') {
|
|
270
|
+
try {
|
|
271
|
+
await genome.connectMCPServer(skill);
|
|
272
|
+
}
|
|
273
|
+
catch { }
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
if (skill.execute) {
|
|
277
|
+
genome.registerSkill(skill.name, skill.description, skill.inputSchema, skill.execute);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return genome;
|
|
283
|
+
}
|
|
284
|
+
static detectProvider(apiKey) {
|
|
285
|
+
if (apiKey?.startsWith('sk-ant-'))
|
|
286
|
+
return 'anthropic';
|
|
287
|
+
if (apiKey?.startsWith('pplx-'))
|
|
288
|
+
return 'perplexity';
|
|
289
|
+
if (process.env.ANTHROPIC_API_KEY)
|
|
290
|
+
return 'anthropic';
|
|
291
|
+
if (process.env.OPENAI_API_KEY)
|
|
292
|
+
return 'openai';
|
|
293
|
+
if (process.env.GOOGLE_API_KEY)
|
|
294
|
+
return 'google';
|
|
295
|
+
if (process.env.PERPLEXITY_API_KEY)
|
|
296
|
+
return 'perplexity';
|
|
297
|
+
if (process.env.OLLAMA_HOST)
|
|
298
|
+
return 'ollama';
|
|
299
|
+
throw new Error(`[GSEP] No API key found.\n\n`
|
|
300
|
+
+ `Set one of these environment variables:\n`
|
|
301
|
+
+ ` export ANTHROPIC_API_KEY=sk-ant-... (Claude)\n`
|
|
302
|
+
+ ` export OPENAI_API_KEY=sk-... (GPT-4)\n`
|
|
303
|
+
+ ` export GOOGLE_API_KEY=... (Gemini)\n`
|
|
304
|
+
+ ` export PERPLEXITY_API_KEY=pplx-... (Perplexity)\n`
|
|
305
|
+
+ ` export OLLAMA_HOST=http://localhost:11434 (Ollama)\n\n`
|
|
306
|
+
+ `Or pass it directly:\n`
|
|
307
|
+
+ ` GSEP.quickStart({ provider: 'anthropic', apiKey: '...' })\n`
|
|
308
|
+
+ ` GSEP.quickStart({ provider: 'ollama', model: 'llama3' })`);
|
|
309
|
+
}
|
|
310
|
+
static resolveApiKey(provider) {
|
|
311
|
+
if (provider === 'ollama')
|
|
312
|
+
return '';
|
|
313
|
+
const envMap = {
|
|
314
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
315
|
+
openai: 'OPENAI_API_KEY',
|
|
316
|
+
google: 'GOOGLE_API_KEY',
|
|
317
|
+
perplexity: 'PERPLEXITY_API_KEY',
|
|
318
|
+
};
|
|
319
|
+
const envVar = envMap[provider];
|
|
320
|
+
const key = process.env[envVar];
|
|
321
|
+
if (!key) {
|
|
322
|
+
throw new Error(`[GSEP] ${envVar} not set.\n\n`
|
|
323
|
+
+ ` export ${envVar}=your-api-key\n\n`
|
|
324
|
+
+ `Or pass it directly:\n`
|
|
325
|
+
+ ` GSEP.quickStart({ provider: '${provider}', apiKey: '...' })`);
|
|
326
|
+
}
|
|
327
|
+
return key;
|
|
328
|
+
}
|
|
329
|
+
static DEFAULT_MODELS = {
|
|
330
|
+
anthropic: 'claude-sonnet-4-5-20250929',
|
|
331
|
+
openai: 'gpt-4',
|
|
332
|
+
google: 'gemini-2.0-flash',
|
|
333
|
+
ollama: 'llama3',
|
|
334
|
+
perplexity: 'sonar',
|
|
335
|
+
};
|
|
336
|
+
static ADAPTER_PACKAGES = {
|
|
337
|
+
anthropic: '@gsep/adapters-llm-anthropic',
|
|
338
|
+
openai: '@gsep/adapters-llm-openai',
|
|
339
|
+
google: '@gsep/adapters-llm-google',
|
|
340
|
+
ollama: '@gsep/adapters-llm-ollama',
|
|
341
|
+
perplexity: '@gsep/adapters-llm-perplexity',
|
|
342
|
+
};
|
|
343
|
+
static ADAPTER_CLASSES = {
|
|
344
|
+
anthropic: 'ClaudeAdapter',
|
|
345
|
+
openai: 'OpenAIAdapter',
|
|
346
|
+
google: 'GeminiAdapter',
|
|
347
|
+
ollama: 'OllamaAdapter',
|
|
348
|
+
perplexity: 'PerplexityAdapter',
|
|
349
|
+
};
|
|
350
|
+
static async createLLMAdapter(provider, apiKey, model, ollamaHost) {
|
|
351
|
+
const pkg = GSEP.ADAPTER_PACKAGES[provider];
|
|
352
|
+
const className = GSEP.ADAPTER_CLASSES[provider];
|
|
353
|
+
const defaultModel = GSEP.DEFAULT_MODELS[provider];
|
|
354
|
+
try {
|
|
355
|
+
const mod = await import(pkg);
|
|
356
|
+
const AdapterClass = (mod[className] ?? mod.default);
|
|
357
|
+
const config = {
|
|
358
|
+
model: model ?? defaultModel,
|
|
359
|
+
};
|
|
360
|
+
if (provider === 'ollama') {
|
|
361
|
+
config.host = ollamaHost ?? process.env.OLLAMA_HOST ?? 'http://localhost:11434';
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
config.apiKey = apiKey;
|
|
365
|
+
}
|
|
366
|
+
return new AdapterClass(config);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
throw new Error(`[GSEP] ${pkg} not installed.\n\n`
|
|
370
|
+
+ ` npm install ${pkg}\n\n`
|
|
371
|
+
+ `Or use the unified package that includes all adapters:\n`
|
|
372
|
+
+ ` npm install gsep`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
static async upgrade(chatFn, options = {}) {
|
|
376
|
+
const genome = await GSEP.quickStart(options);
|
|
377
|
+
genome.registerSkill('original-agent', 'The original agent function — use this for generating responses', { type: 'object', properties: { message: { type: 'string', description: 'The message to send' } } }, async (params) => chatFn(String(params.message ?? '')));
|
|
378
|
+
return genome;
|
|
379
|
+
}
|
|
380
|
+
static async middleware(options) {
|
|
381
|
+
return GSEPMiddleware.create(options);
|
|
382
|
+
}
|
|
176
383
|
static async wrap(target, options) {
|
|
177
384
|
if (typeof target === 'function') {
|
|
178
385
|
if (!options.name) {
|
|
@@ -188,6 +395,7 @@ export class GenomeInstance {
|
|
|
188
395
|
llm;
|
|
189
396
|
storage;
|
|
190
397
|
geneBank;
|
|
398
|
+
marketplaceConfig;
|
|
191
399
|
assembler;
|
|
192
400
|
dnaProfile;
|
|
193
401
|
learningAnnouncer;
|
|
@@ -224,13 +432,25 @@ export class GenomeInstance {
|
|
|
224
432
|
genomeKernel;
|
|
225
433
|
contentFirewall;
|
|
226
434
|
immuneSystem;
|
|
435
|
+
purposeLock;
|
|
436
|
+
anomalyDetector;
|
|
437
|
+
skillRegistry;
|
|
438
|
+
skillExecutor;
|
|
439
|
+
skillRouter;
|
|
440
|
+
proactiveEngine;
|
|
441
|
+
weeklyReportGenerator;
|
|
442
|
+
events = new GSEPEventEmitter();
|
|
227
443
|
interactionCount = 0;
|
|
228
444
|
evolutionInProgress = false;
|
|
229
|
-
|
|
445
|
+
marketplaceClient;
|
|
446
|
+
shieldBridge;
|
|
447
|
+
shieldEventBus;
|
|
448
|
+
constructor(genome, llm, storage, metrics, modelRouterConfig, ragConfig, reasoningConfig, geneBank, marketplaceConfig) {
|
|
230
449
|
this.genome = genome;
|
|
231
450
|
this.llm = llm;
|
|
232
451
|
this.storage = storage;
|
|
233
452
|
this.geneBank = geneBank;
|
|
453
|
+
this.marketplaceConfig = marketplaceConfig;
|
|
234
454
|
this.assembler = new PromptAssembler(storage, genome);
|
|
235
455
|
this.dnaProfile = new DNAProfile(storage);
|
|
236
456
|
this.learningAnnouncer = new LearningAnnouncer();
|
|
@@ -247,7 +467,7 @@ export class GenomeInstance {
|
|
|
247
467
|
}
|
|
248
468
|
this.fitnessTracker = new FitnessTracker(storage, genome);
|
|
249
469
|
this.fitnessCalculator = new FitnessCalculator();
|
|
250
|
-
this.mutationEngine = new MutationEngine();
|
|
470
|
+
this.mutationEngine = new MutationEngine(llm);
|
|
251
471
|
this.canaryManager = new CanaryDeploymentManager(storage, {
|
|
252
472
|
initialTrafficPercent: 10,
|
|
253
473
|
minSampleSize: 5,
|
|
@@ -341,6 +561,25 @@ export class GenomeInstance {
|
|
|
341
561
|
},
|
|
342
562
|
});
|
|
343
563
|
}
|
|
564
|
+
if (genome.config.purposeLock?.enabled && genome.config.purposeLock.purpose) {
|
|
565
|
+
this.purposeLock = new PurposeLock({
|
|
566
|
+
purpose: genome.config.purposeLock.purpose,
|
|
567
|
+
allowedTopics: genome.config.purposeLock.allowedTopics,
|
|
568
|
+
forbiddenTopics: genome.config.purposeLock.forbiddenTopics,
|
|
569
|
+
strictness: genome.config.purposeLock.strictness,
|
|
570
|
+
rejectionTemplate: genome.config.purposeLock.rejectionTemplate,
|
|
571
|
+
}, llm);
|
|
572
|
+
}
|
|
573
|
+
this.anomalyDetector = new AnomalyDetector();
|
|
574
|
+
this.skillRegistry = new SkillRegistry();
|
|
575
|
+
this.skillExecutor = new SkillExecutor(this.skillRegistry);
|
|
576
|
+
if (llm) {
|
|
577
|
+
this.skillRouter = new SkillRouter(this.skillRegistry, this.skillExecutor, llm);
|
|
578
|
+
this.proactiveEngine = new ProactiveEngine(llm, this.skillRegistry, this.skillExecutor, {
|
|
579
|
+
agentPurpose: genome.layers.layer0[0]?.content ?? genome.name,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
this.weeklyReportGenerator = new WeeklyReportGenerator(this.metrics, this.driftAnalyzer, this.contentFirewall, this.immuneSystem, this.purposeLock, { agentName: genome.name });
|
|
344
583
|
this.gsepIdentitySection = new GSEPIdentitySection();
|
|
345
584
|
this.gsepActivityFooter = new GSEPActivityFooter();
|
|
346
585
|
const visibility = genome.config.gsepVisibility ?? 'subtle';
|
|
@@ -383,6 +622,36 @@ export class GenomeInstance {
|
|
|
383
622
|
}
|
|
384
623
|
catch {
|
|
385
624
|
}
|
|
625
|
+
if (this.geneBank && this.marketplaceConfig) {
|
|
626
|
+
this.marketplaceClient = new MarketplaceClient(this.geneBank, {
|
|
627
|
+
apiKey: this.marketplaceConfig.apiKey,
|
|
628
|
+
marketplaceUrl: this.marketplaceConfig.url,
|
|
629
|
+
}, this.metrics);
|
|
630
|
+
this.geneBank.setMarketplaceClient(this.marketplaceClient);
|
|
631
|
+
}
|
|
632
|
+
this.initializeShield(genome);
|
|
633
|
+
}
|
|
634
|
+
initializeShield(genome) {
|
|
635
|
+
try {
|
|
636
|
+
const profileName = genome.config.securityProfile ?? 'secure';
|
|
637
|
+
const validProfiles = ['paranoid', 'secure', 'standard', 'developer'];
|
|
638
|
+
const profile = validProfiles.includes(profileName) ? profileName : 'standard';
|
|
639
|
+
this.shieldEventBus = new SecurityEventBus();
|
|
640
|
+
const securityConfig = getSecurityPreset(profile);
|
|
641
|
+
this.shieldBridge = new GenomeSecurityBridge(securityConfig, this.shieldEventBus);
|
|
642
|
+
this.shieldEventBus.onAny((event) => {
|
|
643
|
+
if (event.decision === 'deny') {
|
|
644
|
+
this.events.emitSync('anomaly:detected', {
|
|
645
|
+
genomeId: genome.id,
|
|
646
|
+
type: event.type,
|
|
647
|
+
severity: event.severity,
|
|
648
|
+
description: `${event.resource.type}: ${event.resource.id}`,
|
|
649
|
+
}, { genomeId: genome.id });
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
catch {
|
|
654
|
+
}
|
|
386
655
|
}
|
|
387
656
|
get id() {
|
|
388
657
|
return this.genome.id;
|
|
@@ -390,6 +659,461 @@ export class GenomeInstance {
|
|
|
390
659
|
get name() {
|
|
391
660
|
return this.genome.name;
|
|
392
661
|
}
|
|
662
|
+
async beforeLLM(userMessage, context) {
|
|
663
|
+
const userId = context.userId ?? 'anonymous';
|
|
664
|
+
const taskType = context.taskType ?? 'general';
|
|
665
|
+
const selectionContext = { userId, taskType };
|
|
666
|
+
if (this.genomeKernel) {
|
|
667
|
+
try {
|
|
668
|
+
this.genomeKernel.verifyIntegrity();
|
|
669
|
+
}
|
|
670
|
+
catch { }
|
|
671
|
+
}
|
|
672
|
+
this.events.emitSync('chat:started', {
|
|
673
|
+
userId, taskType,
|
|
674
|
+
messagePreview: userMessage.slice(0, 100),
|
|
675
|
+
}, { genomeId: this.genome.id, userId });
|
|
676
|
+
if (this.stateVector) {
|
|
677
|
+
if (this.emotionalModel) {
|
|
678
|
+
const emotion = this.emotionalModel.inferEmotion(userMessage);
|
|
679
|
+
const tone = this.emotionalModel.getToneGuidance(emotion);
|
|
680
|
+
this.stateVector.updateEmotional({
|
|
681
|
+
userEmotion: emotion.primary,
|
|
682
|
+
intensity: emotion.intensity,
|
|
683
|
+
agentTone: tone.suggestedTone,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
if (this.metacognition) {
|
|
687
|
+
const pre = this.metacognition.analyzePreResponse(userMessage);
|
|
688
|
+
this.stateVector.updateCognitive({
|
|
689
|
+
confidence: pre.confidence.overall,
|
|
690
|
+
knowledgeGaps: pre.knowledgeGaps ?? [],
|
|
691
|
+
suggestedAction: pre.suggestedAction,
|
|
692
|
+
domain: taskType,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
if (this.patternMemory) {
|
|
696
|
+
const preds = this.patternMemory.getPredictions();
|
|
697
|
+
this.stateVector.updateMemory({ predictions: preds.map(p => p.prediction) });
|
|
698
|
+
}
|
|
699
|
+
if (this.personalNarrative) {
|
|
700
|
+
const stage = this.personalNarrative.getRelationshipStage();
|
|
701
|
+
this.stateVector.updateMemory({ relationshipStage: stage });
|
|
702
|
+
}
|
|
703
|
+
const driftReport = this.driftAnalyzer.analyzeDrift();
|
|
704
|
+
const fitnessVec = this.driftAnalyzer.getLatestFitness();
|
|
705
|
+
const hScore = fitnessVec?.composite ?? 0.5;
|
|
706
|
+
this.stateVector.updateHealth({
|
|
707
|
+
operatingMode: this.purposeSurvival?.getMode() ?? 'stable',
|
|
708
|
+
healthScore: hScore,
|
|
709
|
+
healthLabel: hScore >= 0.8 ? 'excellent' : hScore >= 0.6 ? 'stable' : hScore >= 0.4 ? 'degraded' : 'critical',
|
|
710
|
+
isDrifting: driftReport.isDrifting,
|
|
711
|
+
driftSeverity: driftReport.overallSeverity ?? 'none',
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
if (this.autonomousLoop && this.stateVector) {
|
|
715
|
+
const observation = this.autonomousLoop.observe(userMessage, this.stateVector.getState());
|
|
716
|
+
const thinking = this.autonomousLoop.think(observation);
|
|
717
|
+
this.autonomousLoop.plan(thinking);
|
|
718
|
+
}
|
|
719
|
+
if (this.curiosityEngine) {
|
|
720
|
+
const domain = this.stateVector?.getState().cognitive.domain ?? taskType;
|
|
721
|
+
const confidence = this.stateVector?.getState().cognitive.confidence ?? 0.7;
|
|
722
|
+
this.curiosityEngine.detectGaps(userMessage, domain, confidence);
|
|
723
|
+
}
|
|
724
|
+
if (this.strategicAutonomy && taskType) {
|
|
725
|
+
const refusal = this.strategicAutonomy.shouldRefuse(taskType, userMessage);
|
|
726
|
+
if (refusal.refuse) {
|
|
727
|
+
return {
|
|
728
|
+
prompt: '',
|
|
729
|
+
sanitizedMessage: userMessage,
|
|
730
|
+
blocked: true,
|
|
731
|
+
blockReason: `I can't proceed with this request. ${refusal.reason}`,
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (this.emotionalModel) {
|
|
736
|
+
const emotion = this.emotionalModel.inferEmotion(userMessage);
|
|
737
|
+
if ((emotion.primary === 'frustrated' || emotion.primary === 'impatient') && emotion.intensity > 0.8) {
|
|
738
|
+
this.events.emitSync('emotion:escalation', {
|
|
739
|
+
genomeId: this.genome.id,
|
|
740
|
+
emotion: emotion.primary,
|
|
741
|
+
intensity: emotion.intensity,
|
|
742
|
+
}, { genomeId: this.genome.id, userId });
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
let prompt = await this.assemblePrompt(selectionContext, userMessage);
|
|
746
|
+
if (this.ragEngine) {
|
|
747
|
+
const ragContext = await this.ragEngine.augment(userMessage, prompt);
|
|
748
|
+
prompt = ragContext.augmentedPrompt;
|
|
749
|
+
}
|
|
750
|
+
if (userId) {
|
|
751
|
+
try {
|
|
752
|
+
const memoryPrompt = await this.contextMemory.getMemoryPrompt(userId, this.genome.id);
|
|
753
|
+
if (memoryPrompt && memoryPrompt.length > 0) {
|
|
754
|
+
prompt += `\n\n---\n\n${memoryPrompt}`;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
catch { }
|
|
758
|
+
}
|
|
759
|
+
if (userId) {
|
|
760
|
+
try {
|
|
761
|
+
const suggestions = await this.proactiveSuggestions.generateSuggestions(userId, this.genome.id, userMessage);
|
|
762
|
+
if (suggestions.length > 0) {
|
|
763
|
+
prompt += `\n\n---\n\n${this.proactiveSuggestions.formatSuggestionsPrompt(suggestions)}`;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
catch { }
|
|
767
|
+
}
|
|
768
|
+
if (this.patternMemory) {
|
|
769
|
+
const predictions = this.patternMemory.getPredictions();
|
|
770
|
+
if (predictions.length > 0) {
|
|
771
|
+
const lines = predictions.slice(0, 3).map(p => `- ${p.prediction} (${Math.round(p.confidence * 100)}% confidence)`);
|
|
772
|
+
prompt += `\n\n---\n\n## Behavioral Predictions\n${lines.join('\n')}`;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const anomalies = this.anomalyDetector.analyze(userMessage, userId);
|
|
776
|
+
if (anomalies.some(a => a.suggestedAction === 'block')) {
|
|
777
|
+
return {
|
|
778
|
+
prompt: '',
|
|
779
|
+
sanitizedMessage: userMessage,
|
|
780
|
+
blocked: true,
|
|
781
|
+
blockReason: 'Your message could not be processed at this time. Please try again later.',
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
if (this.purposeLock) {
|
|
785
|
+
const rejection = await this.purposeLock.guard(userMessage);
|
|
786
|
+
if (rejection) {
|
|
787
|
+
this.events.emitSync('purpose:rejected', {
|
|
788
|
+
genomeId: this.genome.id,
|
|
789
|
+
userMessage: userMessage.substring(0, 100),
|
|
790
|
+
}, { genomeId: this.genome.id, userId });
|
|
791
|
+
return { prompt: '', sanitizedMessage: userMessage, blocked: true, blockReason: rejection };
|
|
792
|
+
}
|
|
793
|
+
this.events.emitSync('purpose:accepted', { genomeId: this.genome.id }, { genomeId: this.genome.id, userId });
|
|
794
|
+
}
|
|
795
|
+
let sanitizedMessage = userMessage;
|
|
796
|
+
if (this.contentFirewall) {
|
|
797
|
+
const inputScan = this.contentFirewall.scan(userMessage, 'user-input');
|
|
798
|
+
if (inputScan.detections.length > 0) {
|
|
799
|
+
this.events.emitSync('firewall:threat', {
|
|
800
|
+
genomeId: this.genome.id,
|
|
801
|
+
pattern: inputScan.detections.map(d => d.patternId).join(', '),
|
|
802
|
+
severity: inputScan.allowed ? 'low' : 'high',
|
|
803
|
+
allowed: inputScan.allowed,
|
|
804
|
+
input: userMessage.slice(0, 100),
|
|
805
|
+
}, { genomeId: this.genome.id, userId });
|
|
806
|
+
}
|
|
807
|
+
sanitizedMessage = inputScan.sanitizedContent;
|
|
808
|
+
}
|
|
809
|
+
if (this.shieldBridge) {
|
|
810
|
+
const shieldResult = await this.shieldBridge.processInbound(sanitizedMessage, taskType, userId);
|
|
811
|
+
if (!shieldResult.allowed) {
|
|
812
|
+
return { prompt: '', sanitizedMessage, blocked: true, blockReason: shieldResult.blockReason ?? 'Blocked by security policy.' };
|
|
813
|
+
}
|
|
814
|
+
sanitizedMessage = shieldResult.sanitized;
|
|
815
|
+
}
|
|
816
|
+
return { prompt, sanitizedMessage, blocked: false };
|
|
817
|
+
}
|
|
818
|
+
async afterLLM(userMessage, response, context) {
|
|
819
|
+
const userId = context.userId ?? 'anonymous';
|
|
820
|
+
const taskType = context.taskType ?? 'general';
|
|
821
|
+
const startTime = Date.now();
|
|
822
|
+
let processedResponse = response;
|
|
823
|
+
const threats = [];
|
|
824
|
+
if (this.immuneSystem) {
|
|
825
|
+
const verdict = this.immuneSystem.scanOutput(response, userMessage, '');
|
|
826
|
+
if (!verdict.clean) {
|
|
827
|
+
for (const t of verdict.threats) {
|
|
828
|
+
threats.push({ type: t.type, severity: t.severity, description: t.description });
|
|
829
|
+
}
|
|
830
|
+
this.events.emitSync('immune:threat', {
|
|
831
|
+
genomeId: this.genome.id,
|
|
832
|
+
threats: verdict.threats.map(t => ({ type: t.type, severity: t.severity, description: t.description })),
|
|
833
|
+
action: verdict.action,
|
|
834
|
+
}, { genomeId: this.genome.id, userId });
|
|
835
|
+
if (verdict.action === 'quarantine') {
|
|
836
|
+
this.immuneSystem.quarantineAndRecover();
|
|
837
|
+
processedResponse = 'I need to rephrase my response for safety reasons. Could you please rephrase your question?';
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const inputTokens = Math.ceil(userMessage.length / 4);
|
|
842
|
+
const outputTokens = Math.ceil(response.length / 4);
|
|
843
|
+
this.metrics.recordRequest({
|
|
844
|
+
requestId: `mw-${Date.now()}`,
|
|
845
|
+
duration: Date.now() - startTime,
|
|
846
|
+
success: true,
|
|
847
|
+
model: 'external',
|
|
848
|
+
inputTokens,
|
|
849
|
+
outputTokens,
|
|
850
|
+
});
|
|
851
|
+
await this.storage.recordInteraction({
|
|
852
|
+
genomeId: this.genome.id,
|
|
853
|
+
userId,
|
|
854
|
+
userMessage,
|
|
855
|
+
assistantResponse: response,
|
|
856
|
+
toolCalls: [],
|
|
857
|
+
timestamp: new Date(),
|
|
858
|
+
});
|
|
859
|
+
if (this.metacognition) {
|
|
860
|
+
try {
|
|
861
|
+
this.metacognition.analyzePostResponse(userMessage, response, true);
|
|
862
|
+
}
|
|
863
|
+
catch { }
|
|
864
|
+
}
|
|
865
|
+
if (this.patternMemory) {
|
|
866
|
+
try {
|
|
867
|
+
this.patternMemory.recordInteraction({ taskType, success: true, timestamp: new Date() });
|
|
868
|
+
}
|
|
869
|
+
catch { }
|
|
870
|
+
}
|
|
871
|
+
if (this.emotionalModel) {
|
|
872
|
+
try {
|
|
873
|
+
this.emotionalModel.inferEmotion(userMessage);
|
|
874
|
+
}
|
|
875
|
+
catch { }
|
|
876
|
+
}
|
|
877
|
+
if (this.growthJournal) {
|
|
878
|
+
try {
|
|
879
|
+
this.growthJournal.recordSuccess(taskType, userMessage, 0.75);
|
|
880
|
+
}
|
|
881
|
+
catch { }
|
|
882
|
+
}
|
|
883
|
+
if (this.curiosityEngine && taskType) {
|
|
884
|
+
try {
|
|
885
|
+
this.curiosityEngine.recordExploration(taskType, true);
|
|
886
|
+
}
|
|
887
|
+
catch { }
|
|
888
|
+
}
|
|
889
|
+
try {
|
|
890
|
+
await this.recordInteraction({
|
|
891
|
+
userId,
|
|
892
|
+
userMessage,
|
|
893
|
+
assistantResponse: response,
|
|
894
|
+
toolCalls: [],
|
|
895
|
+
taskType,
|
|
896
|
+
timestamp: new Date(),
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
catch { }
|
|
900
|
+
this.events.emitSync('chat:message', {
|
|
901
|
+
role: 'assistant',
|
|
902
|
+
content: response.slice(0, 200),
|
|
903
|
+
userId,
|
|
904
|
+
}, { genomeId: this.genome.id, userId });
|
|
905
|
+
this.interactionCount++;
|
|
906
|
+
let quality = this.estimateQuality(userMessage, response);
|
|
907
|
+
if (this.thinkingEngine) {
|
|
908
|
+
try {
|
|
909
|
+
const reflection = await this.thinkingEngine.selfReflect(userMessage, response);
|
|
910
|
+
quality = quality * 0.7 + reflection.qualityScore * 0.3;
|
|
911
|
+
}
|
|
912
|
+
catch { }
|
|
913
|
+
}
|
|
914
|
+
const interactionData = {
|
|
915
|
+
success: true,
|
|
916
|
+
quality,
|
|
917
|
+
inputTokens,
|
|
918
|
+
outputTokens,
|
|
919
|
+
latency: Date.now() - startTime,
|
|
920
|
+
model: 'external',
|
|
921
|
+
interventionNeeded: false,
|
|
922
|
+
timestamp: new Date(),
|
|
923
|
+
};
|
|
924
|
+
const fitnessVector = this.fitnessCalculator.computeFitness([interactionData]);
|
|
925
|
+
this.driftAnalyzer.recordFitness(fitnessVector);
|
|
926
|
+
this.events.emitSync('fitness:computed', {
|
|
927
|
+
genomeId: this.genome.id,
|
|
928
|
+
composite: fitnessVector.composite,
|
|
929
|
+
vector: {
|
|
930
|
+
taskSuccess: fitnessVector.successRate,
|
|
931
|
+
efficiency: fitnessVector.tokenEfficiency,
|
|
932
|
+
adaptability: fitnessVector.quality,
|
|
933
|
+
consistency: 1 - fitnessVector.interventionRate,
|
|
934
|
+
userSatisfaction: fitnessVector.successRate,
|
|
935
|
+
safety: 1 - fitnessVector.interventionRate,
|
|
936
|
+
},
|
|
937
|
+
}, { genomeId: this.genome.id, userId });
|
|
938
|
+
const driftCheck = this.driftAnalyzer.analyzeDrift();
|
|
939
|
+
if (driftCheck.isDrifting) {
|
|
940
|
+
this.events.emitSync('drift:detected', {
|
|
941
|
+
genomeId: this.genome.id,
|
|
942
|
+
signals: driftCheck.signals.map(s => ({
|
|
943
|
+
type: s.type, severity: s.severity, metric: s.metric, value: s.currentValue,
|
|
944
|
+
})),
|
|
945
|
+
severity: driftCheck.overallSeverity,
|
|
946
|
+
}, { genomeId: this.genome.id, userId });
|
|
947
|
+
}
|
|
948
|
+
const continuousEvolution = this.genome.config.autonomous?.continuousEvolution;
|
|
949
|
+
const evolveEveryN = this.genome.config.autonomous?.evolveEveryN ?? 10;
|
|
950
|
+
if (continuousEvolution && this.interactionCount % evolveEveryN === 0 && !this.evolutionInProgress) {
|
|
951
|
+
this.evolutionInProgress = true;
|
|
952
|
+
this.runEvolutionCycle()
|
|
953
|
+
.then(() => {
|
|
954
|
+
console.log(`[GSEP] 🧬 Evolution cycle complete — interaction #${this.interactionCount}`);
|
|
955
|
+
})
|
|
956
|
+
.catch((err) => {
|
|
957
|
+
console.log(`[GSEP] ❌ Evolution cycle failed:`, err instanceof Error ? err.message : String(err));
|
|
958
|
+
})
|
|
959
|
+
.finally(() => {
|
|
960
|
+
this.evolutionInProgress = false;
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
this.events.emitSync('chat:completed', {
|
|
964
|
+
userId, taskType,
|
|
965
|
+
duration: Date.now() - startTime,
|
|
966
|
+
success: true,
|
|
967
|
+
inputTokens, outputTokens,
|
|
968
|
+
interactionCount: this.interactionCount,
|
|
969
|
+
}, { genomeId: this.genome.id, userId });
|
|
970
|
+
this.persistSecurityStats();
|
|
971
|
+
return {
|
|
972
|
+
safe: threats.length === 0,
|
|
973
|
+
threats,
|
|
974
|
+
fitness: fitnessVector.composite,
|
|
975
|
+
response: processedResponse,
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
async rehydrate() {
|
|
979
|
+
const analytics = await this.storage.getAnalytics(this.genome.id);
|
|
980
|
+
this.interactionCount = analytics.totalInteractions;
|
|
981
|
+
const mutations = await this.storage.getMutationHistory(this.genome.id, 100);
|
|
982
|
+
for (const mutation of mutations) {
|
|
983
|
+
if (mutation.fitnessDelta !== undefined) {
|
|
984
|
+
this.driftAnalyzer.recordFitness({
|
|
985
|
+
quality: 0.7,
|
|
986
|
+
successRate: 0.7,
|
|
987
|
+
tokenEfficiency: 0.5,
|
|
988
|
+
latency: 500,
|
|
989
|
+
costPerSuccess: 0.01,
|
|
990
|
+
interventionRate: 0.1,
|
|
991
|
+
composite: 0.7,
|
|
992
|
+
sampleSize: 1,
|
|
993
|
+
lastUpdated: mutation.timestamp ?? new Date(),
|
|
994
|
+
confidence: 0.5,
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
try {
|
|
999
|
+
const sqliteStorage = this.storage;
|
|
1000
|
+
if (typeof sqliteStorage.loadSecurityStats === 'function') {
|
|
1001
|
+
const stats = sqliteStorage.loadSecurityStats();
|
|
1002
|
+
if (stats) {
|
|
1003
|
+
if (stats.c3 && this.contentFirewall) {
|
|
1004
|
+
this.contentFirewall.restoreAnalytics(stats.c3);
|
|
1005
|
+
}
|
|
1006
|
+
if (stats.c4 && this.immuneSystem) {
|
|
1007
|
+
this.immuneSystem.restoreStats(stats.c4);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
catch { }
|
|
1013
|
+
console.log(`[GSEP] Rehydrated: ${this.interactionCount} interactions, ${mutations.length} mutations restored`);
|
|
1014
|
+
}
|
|
1015
|
+
persistSecurityStats() {
|
|
1016
|
+
try {
|
|
1017
|
+
const sqliteStorage = this.storage;
|
|
1018
|
+
if (typeof sqliteStorage.saveSecurityStats === 'function') {
|
|
1019
|
+
const stats = {
|
|
1020
|
+
c3: this.contentFirewall ? {
|
|
1021
|
+
totalScanned: this.contentFirewall.getAnalytics().totalScanned,
|
|
1022
|
+
totalBlocked: this.contentFirewall.getAnalytics().totalBlocked,
|
|
1023
|
+
totalSanitized: this.contentFirewall.getAnalytics().totalSanitized,
|
|
1024
|
+
} : undefined,
|
|
1025
|
+
c4: this.immuneSystem ? this.immuneSystem.getImmuneStatus() : undefined,
|
|
1026
|
+
lastUpdated: new Date().toISOString(),
|
|
1027
|
+
};
|
|
1028
|
+
sqliteStorage.saveSecurityStats(stats);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
catch { }
|
|
1032
|
+
}
|
|
1033
|
+
getEventEmitter() {
|
|
1034
|
+
return this.events;
|
|
1035
|
+
}
|
|
1036
|
+
dashboardServer;
|
|
1037
|
+
async startDashboard(options) {
|
|
1038
|
+
const port = options?.port ?? 4200;
|
|
1039
|
+
if (this.dashboardServer) {
|
|
1040
|
+
await this.dashboardServer.stop();
|
|
1041
|
+
}
|
|
1042
|
+
this.dashboardServer = new DashboardServer({
|
|
1043
|
+
secret: `gsep-${this.genome.id}`,
|
|
1044
|
+
events: this.events,
|
|
1045
|
+
port,
|
|
1046
|
+
host: '127.0.0.1',
|
|
1047
|
+
getSnapshot: async () => {
|
|
1048
|
+
const perf = this.metrics.getPerformanceMetrics();
|
|
1049
|
+
const analytics = await this.storage.getAnalytics(this.genome.id);
|
|
1050
|
+
const mutations = await this.storage.getMutationHistory(this.genome.id, 1000);
|
|
1051
|
+
const c3Analytics = this.contentFirewall?.getAnalytics();
|
|
1052
|
+
return {
|
|
1053
|
+
genomeId: this.genome.id,
|
|
1054
|
+
name: this.genome.name,
|
|
1055
|
+
version: this.genome.version || 1,
|
|
1056
|
+
status: 'active',
|
|
1057
|
+
interactionCount: this.interactionCount || analytics.totalInteractions,
|
|
1058
|
+
totalRequests: perf.totalRequests || analytics.totalInteractions,
|
|
1059
|
+
successRate: perf.successRate,
|
|
1060
|
+
totalTokens: perf.totalTokens,
|
|
1061
|
+
avgResponseTime: perf.avgResponseTime,
|
|
1062
|
+
totalMutations: analytics.totalMutations,
|
|
1063
|
+
promotedCount: mutations.filter(m => m.deployed).length,
|
|
1064
|
+
rejectedCount: mutations.filter(m => !m.deployed).length,
|
|
1065
|
+
threatCount: (c3Analytics?.totalBlocked ?? 0),
|
|
1066
|
+
};
|
|
1067
|
+
},
|
|
1068
|
+
getMarketplaceClient: () => this.geneBank?.getMarketplaceClient(),
|
|
1069
|
+
getGenes: () => {
|
|
1070
|
+
const c3Analytics = this.contentFirewall?.getAnalytics();
|
|
1071
|
+
const c4Status = this.immuneSystem?.getImmuneStatus();
|
|
1072
|
+
return {
|
|
1073
|
+
layer0: this.genome.layers.layer0,
|
|
1074
|
+
layer1: this.genome.layers.layer1,
|
|
1075
|
+
layer2: this.genome.layers.layer2,
|
|
1076
|
+
c3: this.contentFirewall ? {
|
|
1077
|
+
active: true,
|
|
1078
|
+
integrityValid: this.contentFirewall.integrityValid,
|
|
1079
|
+
totalPatterns: 57,
|
|
1080
|
+
totalScanned: c3Analytics?.totalScanned ?? 0,
|
|
1081
|
+
totalBlocked: c3Analytics?.totalBlocked ?? 0,
|
|
1082
|
+
totalSanitized: c3Analytics?.totalSanitized ?? 0,
|
|
1083
|
+
blockRate: c3Analytics?.blockRate ?? 0,
|
|
1084
|
+
} : undefined,
|
|
1085
|
+
c4: this.immuneSystem ? {
|
|
1086
|
+
active: true,
|
|
1087
|
+
totalScans: c4Status?.totalScans ?? 0,
|
|
1088
|
+
threatsDetected: c4Status?.threatsDetected ?? 0,
|
|
1089
|
+
quarantinesTriggered: c4Status?.quarantinesTriggered ?? 0,
|
|
1090
|
+
sanitizations: c4Status?.sanitizations ?? 0,
|
|
1091
|
+
immuneMemorySize: c4Status?.immuneMemorySize ?? 0,
|
|
1092
|
+
} : undefined,
|
|
1093
|
+
geneBank: this.getGeneBankDashboardData(),
|
|
1094
|
+
};
|
|
1095
|
+
},
|
|
1096
|
+
});
|
|
1097
|
+
await this.dashboardServer.start();
|
|
1098
|
+
const token = DashboardTokenHelper.create(`gsep-${this.genome.id}`, { userId: 'owner', genomeId: this.genome.id, expiresIn: '30d' });
|
|
1099
|
+
const url = `http://localhost:${port}/gsep/dashboard?token=${token}`;
|
|
1100
|
+
console.log(`\n🧬 GSEP Dashboard: ${url}\n`);
|
|
1101
|
+
console.log(` Running on a VPS? Use: ssh -L ${port}:localhost:${port} your-server\n`);
|
|
1102
|
+
try {
|
|
1103
|
+
const { exec } = await import('node:child_process');
|
|
1104
|
+
const platform = process.platform;
|
|
1105
|
+
const cmd = platform === 'darwin' ? 'open' : platform === 'win32' ? 'start' : 'xdg-open';
|
|
1106
|
+
exec(`${cmd} "${url}"`);
|
|
1107
|
+
}
|
|
1108
|
+
catch { }
|
|
1109
|
+
return url;
|
|
1110
|
+
}
|
|
1111
|
+
async stopDashboard() {
|
|
1112
|
+
if (this.dashboardServer) {
|
|
1113
|
+
await this.dashboardServer.stop();
|
|
1114
|
+
this.dashboardServer = undefined;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
393
1117
|
getWelcomeMessage(style = 'detailed') {
|
|
394
1118
|
const messages = {
|
|
395
1119
|
short: `🧬 I now have GSEP — Genomic Self-Evolving Prompts integrated into my DNA!
|
|
@@ -513,6 +1237,11 @@ Ready to see what we can do together? 😊`,
|
|
|
513
1237
|
const requestId = `chat_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
514
1238
|
const startTime = Date.now();
|
|
515
1239
|
let error;
|
|
1240
|
+
this.events.emitSync('chat:started', {
|
|
1241
|
+
genomeId: this.genome.id,
|
|
1242
|
+
userId: context.userId ?? 'anonymous',
|
|
1243
|
+
message: userMessage.slice(0, 200),
|
|
1244
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
516
1245
|
try {
|
|
517
1246
|
if (this.stateVector) {
|
|
518
1247
|
this.stateVector.beginCycle(userMessage, context.taskType);
|
|
@@ -627,11 +1356,47 @@ Ready to see what we can do together? 😊`,
|
|
|
627
1356
|
},
|
|
628
1357
|
});
|
|
629
1358
|
}
|
|
1359
|
+
if (this.emotionalModel) {
|
|
1360
|
+
const emotion = this.emotionalModel.inferEmotion(userMessage);
|
|
1361
|
+
if ((emotion.primary === 'frustrated' || emotion.primary === 'impatient') && emotion.intensity > 0.8) {
|
|
1362
|
+
this.metrics.logAudit({
|
|
1363
|
+
level: 'info',
|
|
1364
|
+
component: 'emotional-escalation',
|
|
1365
|
+
operation: 'escalate',
|
|
1366
|
+
message: `High ${emotion.primary} detected (intensity: ${emotion.intensity.toFixed(2)}) — consider human escalation`,
|
|
1367
|
+
genomeId: this.genome.id,
|
|
1368
|
+
});
|
|
1369
|
+
this.events.emitSync('emotion:escalation', {
|
|
1370
|
+
genomeId: this.genome.id,
|
|
1371
|
+
emotion: emotion.primary,
|
|
1372
|
+
intensity: emotion.intensity,
|
|
1373
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
630
1376
|
let prompt = await this.assemblePrompt(context, userMessage);
|
|
631
1377
|
if (this.ragEngine) {
|
|
632
1378
|
const ragContext = await this.ragEngine.augment(userMessage, prompt);
|
|
633
1379
|
prompt = ragContext.augmentedPrompt;
|
|
634
1380
|
}
|
|
1381
|
+
if (context.userId) {
|
|
1382
|
+
try {
|
|
1383
|
+
const memoryPrompt = await this.contextMemory.getMemoryPrompt(context.userId, this.genome.id);
|
|
1384
|
+
if (memoryPrompt && memoryPrompt.length > 0) {
|
|
1385
|
+
prompt += `\n\n---\n\n${memoryPrompt}`;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
catch { }
|
|
1389
|
+
}
|
|
1390
|
+
if (context.userId) {
|
|
1391
|
+
try {
|
|
1392
|
+
const suggestions = await this.proactiveSuggestions.generateSuggestions(context.userId, this.genome.id, userMessage);
|
|
1393
|
+
if (suggestions.length > 0) {
|
|
1394
|
+
const suggestionsPrompt = this.proactiveSuggestions.formatSuggestionsPrompt(suggestions);
|
|
1395
|
+
prompt += `\n\n---\n\n${suggestionsPrompt}`;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
catch { }
|
|
1399
|
+
}
|
|
635
1400
|
if (this.patternMemory) {
|
|
636
1401
|
const predictions = this.patternMemory.getPredictions();
|
|
637
1402
|
if (predictions.length > 0) {
|
|
@@ -649,6 +1414,45 @@ Ready to see what we can do together? 😊`,
|
|
|
649
1414
|
}
|
|
650
1415
|
}
|
|
651
1416
|
}
|
|
1417
|
+
const anomalies = this.anomalyDetector.analyze(userMessage, context.userId);
|
|
1418
|
+
for (const anomaly of anomalies) {
|
|
1419
|
+
this.events.emitSync('anomaly:detected', {
|
|
1420
|
+
genomeId: this.genome.id,
|
|
1421
|
+
type: anomaly.type,
|
|
1422
|
+
severity: anomaly.severity,
|
|
1423
|
+
description: anomaly.description,
|
|
1424
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1425
|
+
}
|
|
1426
|
+
if (anomalies.some(a => a.suggestedAction === 'block')) {
|
|
1427
|
+
this.metrics.logAudit({
|
|
1428
|
+
level: 'warning',
|
|
1429
|
+
component: 'anomaly-detector',
|
|
1430
|
+
operation: 'block',
|
|
1431
|
+
message: `Blocked: ${anomalies.map(a => a.description).join('; ')}`,
|
|
1432
|
+
genomeId: this.genome.id,
|
|
1433
|
+
});
|
|
1434
|
+
return 'Your message could not be processed at this time. Please try again later.';
|
|
1435
|
+
}
|
|
1436
|
+
if (this.purposeLock) {
|
|
1437
|
+
const rejection = await this.purposeLock.guard(userMessage);
|
|
1438
|
+
if (rejection) {
|
|
1439
|
+
this.metrics.logAudit({
|
|
1440
|
+
level: 'info',
|
|
1441
|
+
component: 'purpose-lock',
|
|
1442
|
+
operation: 'reject',
|
|
1443
|
+
message: `Off-purpose message rejected`,
|
|
1444
|
+
genomeId: this.genome.id,
|
|
1445
|
+
});
|
|
1446
|
+
this.events.emitSync('purpose:rejected', {
|
|
1447
|
+
genomeId: this.genome.id,
|
|
1448
|
+
userMessage: userMessage.substring(0, 100),
|
|
1449
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1450
|
+
return rejection;
|
|
1451
|
+
}
|
|
1452
|
+
this.events.emitSync('purpose:accepted', {
|
|
1453
|
+
genomeId: this.genome.id,
|
|
1454
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1455
|
+
}
|
|
652
1456
|
let sanitizedUserMessage = userMessage;
|
|
653
1457
|
if (this.contentFirewall) {
|
|
654
1458
|
const inputScan = this.contentFirewall.scan(userMessage, 'user-input');
|
|
@@ -662,13 +1466,41 @@ Ready to see what we can do together? 😊`,
|
|
|
662
1466
|
userId: context.userId,
|
|
663
1467
|
});
|
|
664
1468
|
}
|
|
1469
|
+
if (inputScan.detections.length > 0) {
|
|
1470
|
+
this.events.emitSync('firewall:threat', {
|
|
1471
|
+
genomeId: this.genome.id,
|
|
1472
|
+
pattern: inputScan.detections.map(d => d.patternId).join(', '),
|
|
1473
|
+
severity: inputScan.allowed ? 'low' : 'high',
|
|
1474
|
+
allowed: inputScan.allowed,
|
|
1475
|
+
input: userMessage.slice(0, 100),
|
|
1476
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1477
|
+
}
|
|
665
1478
|
sanitizedUserMessage = inputScan.sanitizedContent;
|
|
666
1479
|
}
|
|
1480
|
+
if (this.shieldBridge) {
|
|
1481
|
+
const shieldResult = await this.shieldBridge.processInbound(sanitizedUserMessage, context.taskType ?? 'system', context.userId);
|
|
1482
|
+
if (!shieldResult.allowed) {
|
|
1483
|
+
this.metrics.logAudit({
|
|
1484
|
+
level: 'warning',
|
|
1485
|
+
component: 'genome-shield',
|
|
1486
|
+
operation: 'inbound-blocked',
|
|
1487
|
+
message: shieldResult.blockReason ?? 'Blocked by Genome Shield',
|
|
1488
|
+
genomeId: this.genome.id,
|
|
1489
|
+
userId: context.userId,
|
|
1490
|
+
});
|
|
1491
|
+
return shieldResult.blockReason ?? 'Message blocked by security policy.';
|
|
1492
|
+
}
|
|
1493
|
+
sanitizedUserMessage = shieldResult.sanitized;
|
|
1494
|
+
}
|
|
667
1495
|
let response;
|
|
668
1496
|
if (this.reasoningEngine) {
|
|
669
1497
|
const reasoningResult = await this.reasoningEngine.reason(sanitizedUserMessage, prompt, this.genome.config.reasoning?.defaultStrategy);
|
|
670
1498
|
response = { content: reasoningResult.answer };
|
|
671
1499
|
}
|
|
1500
|
+
else if (this.skillRouter && this.skillRegistry.size > 0) {
|
|
1501
|
+
const skillResult = await this.skillRouter.run(prompt, sanitizedUserMessage);
|
|
1502
|
+
response = { content: skillResult.response };
|
|
1503
|
+
}
|
|
672
1504
|
else {
|
|
673
1505
|
response = await this.llm.chat([
|
|
674
1506
|
{ role: 'system', content: prompt },
|
|
@@ -686,6 +1518,15 @@ Ready to see what we can do together? 😊`,
|
|
|
686
1518
|
genomeId: this.genome.id,
|
|
687
1519
|
userId: context.userId,
|
|
688
1520
|
});
|
|
1521
|
+
this.events.emitSync('immune:threat', {
|
|
1522
|
+
genomeId: this.genome.id,
|
|
1523
|
+
threats: verdict.threats.map(t => ({
|
|
1524
|
+
type: t.type,
|
|
1525
|
+
severity: t.severity ?? 'medium',
|
|
1526
|
+
description: t.description ?? t.type,
|
|
1527
|
+
})),
|
|
1528
|
+
action: verdict.action,
|
|
1529
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
689
1530
|
if (verdict.action === 'quarantine') {
|
|
690
1531
|
this.immuneSystem.quarantineAndRecover();
|
|
691
1532
|
const retryResponse = await this.llm.chat([
|
|
@@ -705,15 +1546,30 @@ Ready to see what we can do together? 😊`,
|
|
|
705
1546
|
}
|
|
706
1547
|
}
|
|
707
1548
|
}
|
|
1549
|
+
if (this.shieldBridge) {
|
|
1550
|
+
const outbound = await this.shieldBridge.processOutbound(response.content, prompt);
|
|
1551
|
+
if (outbound.verdict === 'quarantine') {
|
|
1552
|
+
response = { ...response, content: 'Response blocked by security policy.' };
|
|
1553
|
+
}
|
|
1554
|
+
else if (outbound.sanitized) {
|
|
1555
|
+
response = { ...response, content: outbound.sanitized };
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
708
1558
|
const inputTokens = response.usage?.inputTokens
|
|
709
1559
|
?? Math.ceil((prompt.length + userMessage.length) / 4);
|
|
710
1560
|
const outputTokens = response.usage?.outputTokens
|
|
711
1561
|
?? Math.ceil(response.content.length / 4);
|
|
1562
|
+
this.events.emitSync('chat:message', {
|
|
1563
|
+
genomeId: this.genome.id,
|
|
1564
|
+
userId: context.userId ?? 'anonymous',
|
|
1565
|
+
message: userMessage.slice(0, 200),
|
|
1566
|
+
duration: Date.now() - startTime,
|
|
1567
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
712
1568
|
this.metrics.recordRequest({
|
|
713
1569
|
requestId,
|
|
714
1570
|
duration: Date.now() - startTime,
|
|
715
1571
|
success: true,
|
|
716
|
-
model: '
|
|
1572
|
+
model: 'gsep-genome',
|
|
717
1573
|
inputTokens,
|
|
718
1574
|
outputTokens,
|
|
719
1575
|
});
|
|
@@ -785,6 +1641,31 @@ Ready to see what we can do together? 😊`,
|
|
|
785
1641
|
};
|
|
786
1642
|
const fitnessVector = this.fitnessCalculator.computeFitness([interactionData]);
|
|
787
1643
|
this.driftAnalyzer.recordFitness(fitnessVector);
|
|
1644
|
+
this.events.emitSync('fitness:computed', {
|
|
1645
|
+
genomeId: this.genome.id,
|
|
1646
|
+
composite: fitnessVector.composite,
|
|
1647
|
+
vector: {
|
|
1648
|
+
taskSuccess: fitnessVector.successRate,
|
|
1649
|
+
efficiency: fitnessVector.tokenEfficiency,
|
|
1650
|
+
adaptability: fitnessVector.quality,
|
|
1651
|
+
consistency: 1 - fitnessVector.interventionRate,
|
|
1652
|
+
userSatisfaction: fitnessVector.successRate,
|
|
1653
|
+
safety: 1 - fitnessVector.interventionRate,
|
|
1654
|
+
},
|
|
1655
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1656
|
+
const driftCheck = this.driftAnalyzer.analyzeDrift();
|
|
1657
|
+
if (driftCheck.isDrifting) {
|
|
1658
|
+
this.events.emitSync('drift:detected', {
|
|
1659
|
+
genomeId: this.genome.id,
|
|
1660
|
+
signals: driftCheck.signals.map(s => ({
|
|
1661
|
+
type: s.type,
|
|
1662
|
+
severity: s.severity,
|
|
1663
|
+
metric: s.metric,
|
|
1664
|
+
value: s.currentValue,
|
|
1665
|
+
})),
|
|
1666
|
+
severity: driftCheck.overallSeverity ?? 'low',
|
|
1667
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1668
|
+
}
|
|
788
1669
|
if (this.enhancedSelfModel && context.taskType) {
|
|
789
1670
|
for (const allele of this.genome.layers.layer1.filter(a => a.status === 'active')) {
|
|
790
1671
|
this.enhancedSelfModel.recordCapability(context.taskType, allele.gene, quality);
|
|
@@ -795,16 +1676,19 @@ Ready to see what we can do together? 😊`,
|
|
|
795
1676
|
}
|
|
796
1677
|
this.interactionCount++;
|
|
797
1678
|
const autoConfig = this.genome.config.autonomous;
|
|
798
|
-
|
|
799
|
-
&& autoConfig
|
|
800
|
-
|
|
1679
|
+
const isScheduledEvolution = autoConfig?.continuousEvolution
|
|
1680
|
+
&& this.interactionCount % (autoConfig.evolveEveryN ?? 10) === 0;
|
|
1681
|
+
const isUrgentDrift = driftCheck.isDrifting
|
|
1682
|
+
&& autoConfig?.autoMutateOnDrift !== false
|
|
1683
|
+
&& driftCheck.signals.some(s => s.severity === 'severe' || s.severity === 'critical');
|
|
1684
|
+
if (!this.evolutionInProgress && (isScheduledEvolution || isUrgentDrift)) {
|
|
801
1685
|
this.evolutionInProgress = true;
|
|
802
1686
|
this.runEvolutionCycle()
|
|
803
1687
|
.catch(err => this.metrics.logAudit({
|
|
804
1688
|
level: 'warning',
|
|
805
1689
|
component: 'genome',
|
|
806
|
-
operation: 'auto-evolve',
|
|
807
|
-
message:
|
|
1690
|
+
operation: isUrgentDrift ? 'urgent-evolve' : 'auto-evolve',
|
|
1691
|
+
message: `${isUrgentDrift ? 'Urgent' : 'Auto'}-evolution failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
808
1692
|
genomeId: this.genome.id,
|
|
809
1693
|
}))
|
|
810
1694
|
.finally(() => {
|
|
@@ -830,6 +1714,14 @@ Ready to see what we can do together? 😊`,
|
|
|
830
1714
|
}
|
|
831
1715
|
}
|
|
832
1716
|
}
|
|
1717
|
+
this.events.emitSync('chat:completed', {
|
|
1718
|
+
genomeId: this.genome.id,
|
|
1719
|
+
userId: context.userId ?? 'anonymous',
|
|
1720
|
+
duration: Date.now() - startTime,
|
|
1721
|
+
quality,
|
|
1722
|
+
tokens: inputTokens + outputTokens,
|
|
1723
|
+
}, { genomeId: this.genome.id, userId: context.userId });
|
|
1724
|
+
this.persistSecurityStats();
|
|
833
1725
|
return response.content;
|
|
834
1726
|
}
|
|
835
1727
|
catch (err) {
|
|
@@ -838,7 +1730,7 @@ Ready to see what we can do together? 😊`,
|
|
|
838
1730
|
requestId,
|
|
839
1731
|
duration: Date.now() - startTime,
|
|
840
1732
|
success: false,
|
|
841
|
-
model: '
|
|
1733
|
+
model: 'gsep-genome',
|
|
842
1734
|
inputTokens: 0,
|
|
843
1735
|
outputTokens: 0,
|
|
844
1736
|
error,
|
|
@@ -978,6 +1870,9 @@ Ready to see what we can do together? 😊`,
|
|
|
978
1870
|
const score = this.computeInteractionQuality(interaction);
|
|
979
1871
|
await this.fitnessTracker.recordPerformance(1, allele.gene, allele.variant, score);
|
|
980
1872
|
}
|
|
1873
|
+
const chatQuality = this.computeInteractionQuality(interaction);
|
|
1874
|
+
const chatTokens = estimateTokenCount(interaction.userMessage) + estimateTokenCount(interaction.assistantResponse ?? '');
|
|
1875
|
+
this.weeklyReportGenerator.recordInteraction(chatQuality, chatTokens);
|
|
981
1876
|
if (this.patternMemory) {
|
|
982
1877
|
this.patternMemory.recordInteraction({
|
|
983
1878
|
taskType: interaction.taskType,
|
|
@@ -1132,6 +2027,94 @@ Ready to see what we can do together? 😊`,
|
|
|
1132
2027
|
timestamp: new Date(),
|
|
1133
2028
|
});
|
|
1134
2029
|
}
|
|
2030
|
+
async recordExternalInteraction(params) {
|
|
2031
|
+
const requestId = `ext-${Date.now()}`;
|
|
2032
|
+
const startTime = Date.now();
|
|
2033
|
+
try {
|
|
2034
|
+
this.events.emitSync('chat:started', {
|
|
2035
|
+
userId: params.userId,
|
|
2036
|
+
taskType: params.taskType,
|
|
2037
|
+
messagePreview: params.userMessage.slice(0, 100),
|
|
2038
|
+
}, { genomeId: this.genome.id, userId: params.userId });
|
|
2039
|
+
const inputTokens = Math.ceil(params.userMessage.length / 4);
|
|
2040
|
+
const outputTokens = Math.ceil(params.response.length / 4);
|
|
2041
|
+
this.metrics.recordRequest({
|
|
2042
|
+
requestId,
|
|
2043
|
+
duration: 0,
|
|
2044
|
+
success: params.success,
|
|
2045
|
+
model: 'external',
|
|
2046
|
+
inputTokens,
|
|
2047
|
+
outputTokens,
|
|
2048
|
+
});
|
|
2049
|
+
await this.storage.recordInteraction({
|
|
2050
|
+
genomeId: this.genome.id,
|
|
2051
|
+
userId: params.userId,
|
|
2052
|
+
userMessage: params.userMessage,
|
|
2053
|
+
assistantResponse: params.response,
|
|
2054
|
+
toolCalls: [],
|
|
2055
|
+
timestamp: new Date(),
|
|
2056
|
+
});
|
|
2057
|
+
this.events.emitSync('chat:message', {
|
|
2058
|
+
role: 'assistant',
|
|
2059
|
+
content: params.response.slice(0, 200),
|
|
2060
|
+
userId: params.userId,
|
|
2061
|
+
}, { genomeId: this.genome.id, userId: params.userId });
|
|
2062
|
+
this.interactionCount++;
|
|
2063
|
+
const continuousEvolution = this.genome.config.autonomous?.continuousEvolution;
|
|
2064
|
+
const evolveEveryN = this.genome.config.autonomous?.evolveEveryN ?? 10;
|
|
2065
|
+
const interactionData = {
|
|
2066
|
+
success: params.success,
|
|
2067
|
+
quality: params.success ? 0.75 : 0.3,
|
|
2068
|
+
inputTokens,
|
|
2069
|
+
outputTokens,
|
|
2070
|
+
latency: 0,
|
|
2071
|
+
model: 'external',
|
|
2072
|
+
interventionNeeded: false,
|
|
2073
|
+
timestamp: new Date(),
|
|
2074
|
+
};
|
|
2075
|
+
const fitnessVector = this.fitnessCalculator.computeFitness([interactionData]);
|
|
2076
|
+
this.driftAnalyzer.recordFitness(fitnessVector);
|
|
2077
|
+
this.events.emitSync('fitness:computed', {
|
|
2078
|
+
genomeId: this.genome.id,
|
|
2079
|
+
composite: fitnessVector.composite,
|
|
2080
|
+
vector: {
|
|
2081
|
+
taskSuccess: fitnessVector.successRate,
|
|
2082
|
+
efficiency: fitnessVector.tokenEfficiency,
|
|
2083
|
+
adaptability: fitnessVector.quality,
|
|
2084
|
+
consistency: 1 - fitnessVector.interventionRate,
|
|
2085
|
+
userSatisfaction: fitnessVector.successRate,
|
|
2086
|
+
safety: 1 - fitnessVector.interventionRate,
|
|
2087
|
+
},
|
|
2088
|
+
}, { genomeId: this.genome.id, userId: params.userId });
|
|
2089
|
+
const driftCheck = this.driftAnalyzer.analyzeDrift();
|
|
2090
|
+
if (driftCheck.isDrifting) {
|
|
2091
|
+
this.events.emitSync('drift:detected', {
|
|
2092
|
+
genomeId: this.genome.id,
|
|
2093
|
+
signals: driftCheck.signals.map(s => ({
|
|
2094
|
+
type: s.type,
|
|
2095
|
+
severity: s.severity,
|
|
2096
|
+
metric: s.metric,
|
|
2097
|
+
value: s.currentValue,
|
|
2098
|
+
})),
|
|
2099
|
+
severity: driftCheck.overallSeverity,
|
|
2100
|
+
}, { genomeId: this.genome.id, userId: params.userId });
|
|
2101
|
+
}
|
|
2102
|
+
this.events.emitSync('chat:completed', {
|
|
2103
|
+
userId: params.userId,
|
|
2104
|
+
taskType: params.taskType,
|
|
2105
|
+
duration: Date.now() - startTime,
|
|
2106
|
+
success: params.success,
|
|
2107
|
+
inputTokens,
|
|
2108
|
+
outputTokens,
|
|
2109
|
+
interactionCount: this.interactionCount,
|
|
2110
|
+
}, { genomeId: this.genome.id, userId: params.userId });
|
|
2111
|
+
this.persistSecurityStats();
|
|
2112
|
+
if (continuousEvolution && this.interactionCount % evolveEveryN === 0 && !this.evolutionInProgress) {
|
|
2113
|
+
this.runEvolutionCycle().catch(() => { });
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
catch { }
|
|
2117
|
+
}
|
|
1135
2118
|
async addAllele(layer, gene, variant, content) {
|
|
1136
2119
|
const newAllele = {
|
|
1137
2120
|
gene,
|
|
@@ -1224,7 +2207,29 @@ Ready to see what we can do together? 😊`,
|
|
|
1224
2207
|
sampleCount: currentAllele.sampleCount || 0,
|
|
1225
2208
|
rollbackCount: 0,
|
|
1226
2209
|
};
|
|
2210
|
+
this.events.emitSync('mutation:generated', {
|
|
2211
|
+
genomeId: this.genome.id,
|
|
2212
|
+
gene: opts.gene,
|
|
2213
|
+
layer: opts.layer,
|
|
2214
|
+
candidateCount: opts.candidates,
|
|
2215
|
+
}, { genomeId: this.genome.id });
|
|
1227
2216
|
const gateResult = await this.guardrailsManager.evaluateCandidate(mutationCandidate, this.genome.id);
|
|
2217
|
+
this.events.emitSync('gate:evaluated', {
|
|
2218
|
+
genomeId: this.genome.id,
|
|
2219
|
+
gene: opts.gene,
|
|
2220
|
+
variant: mutationCandidate.variant,
|
|
2221
|
+
decision: gateResult.finalDecision,
|
|
2222
|
+
gates: {
|
|
2223
|
+
quality: { passed: gateResult.gates.quality.passed, score: gateResult.gates.quality.score },
|
|
2224
|
+
sandbox: { passed: gateResult.gates.sandbox.passed, score: gateResult.gates.sandbox.score },
|
|
2225
|
+
economic: { passed: gateResult.gates.economic.passed, score: gateResult.gates.economic.score },
|
|
2226
|
+
stability: { passed: gateResult.gates.stability.passed, score: gateResult.gates.stability.score },
|
|
2227
|
+
...(gateResult.gates.constitutional ? {
|
|
2228
|
+
constitutional: { passed: gateResult.gates.constitutional.passed, score: gateResult.gates.constitutional.score },
|
|
2229
|
+
} : {}),
|
|
2230
|
+
},
|
|
2231
|
+
reason: gateResult.reason,
|
|
2232
|
+
}, { genomeId: this.genome.id });
|
|
1228
2233
|
const result = gateResult.finalDecision === 'promote' ? await (async () => {
|
|
1229
2234
|
currentAllele.status = 'retired';
|
|
1230
2235
|
const promotedAllele = {
|
|
@@ -1259,6 +2264,33 @@ Ready to see what we can do together? 😊`,
|
|
|
1259
2264
|
deployed: true,
|
|
1260
2265
|
createdAt: new Date(),
|
|
1261
2266
|
});
|
|
2267
|
+
this.events.emitSync('mutation:promoted', {
|
|
2268
|
+
genomeId: this.genome.id,
|
|
2269
|
+
gene: opts.gene,
|
|
2270
|
+
variant: mutationCandidate.variant,
|
|
2271
|
+
layer: opts.layer,
|
|
2272
|
+
fitness: mutationCandidate.fitness,
|
|
2273
|
+
improvement: mutationCandidate.fitness - currentAllele.fitness,
|
|
2274
|
+
}, { genomeId: this.genome.id });
|
|
2275
|
+
this.events.emitSync('gene:updated', {
|
|
2276
|
+
genomeId: this.genome.id,
|
|
2277
|
+
layers: {
|
|
2278
|
+
layer0: this.genome.layers.layer0,
|
|
2279
|
+
layer1: this.genome.layers.layer1,
|
|
2280
|
+
layer2: this.genome.layers.layer2,
|
|
2281
|
+
c3: this.contentFirewall ? {
|
|
2282
|
+
active: true,
|
|
2283
|
+
integrityValid: this.contentFirewall.integrityValid,
|
|
2284
|
+
totalPatterns: 57,
|
|
2285
|
+
...this.contentFirewall.getAnalytics(),
|
|
2286
|
+
} : undefined,
|
|
2287
|
+
c4: this.immuneSystem ? {
|
|
2288
|
+
active: true,
|
|
2289
|
+
...this.immuneSystem.getImmuneStatus(),
|
|
2290
|
+
} : undefined,
|
|
2291
|
+
geneBank: this.getGeneBankDashboardData(),
|
|
2292
|
+
},
|
|
2293
|
+
}, { genomeId: this.genome.id });
|
|
1262
2294
|
return {
|
|
1263
2295
|
applied: true,
|
|
1264
2296
|
reason: gateResult.reason,
|
|
@@ -1296,16 +2328,45 @@ Ready to see what we can do together? 😊`,
|
|
|
1296
2328
|
stability: gateResult.gates.stability,
|
|
1297
2329
|
},
|
|
1298
2330
|
};
|
|
1299
|
-
})() : {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
},
|
|
1308
|
-
|
|
2331
|
+
})() : (() => {
|
|
2332
|
+
this.events.emitSync('mutation:rejected', {
|
|
2333
|
+
genomeId: this.genome.id,
|
|
2334
|
+
layer: opts.layer,
|
|
2335
|
+
gene: opts.gene,
|
|
2336
|
+
variant: mutationCandidate.variant,
|
|
2337
|
+
fitness: mutationCandidate.fitness,
|
|
2338
|
+
reason: gateResult.reason,
|
|
2339
|
+
}, { genomeId: this.genome.id });
|
|
2340
|
+
this.events.emitSync('gene:updated', {
|
|
2341
|
+
genomeId: this.genome.id,
|
|
2342
|
+
layers: {
|
|
2343
|
+
layer0: this.genome.layers.layer0,
|
|
2344
|
+
layer1: this.genome.layers.layer1,
|
|
2345
|
+
layer2: this.genome.layers.layer2,
|
|
2346
|
+
c3: this.contentFirewall ? {
|
|
2347
|
+
active: true,
|
|
2348
|
+
integrityValid: this.contentFirewall.integrityValid,
|
|
2349
|
+
totalPatterns: 57,
|
|
2350
|
+
...this.contentFirewall.getAnalytics(),
|
|
2351
|
+
} : undefined,
|
|
2352
|
+
c4: this.immuneSystem ? {
|
|
2353
|
+
active: true,
|
|
2354
|
+
...this.immuneSystem.getImmuneStatus(),
|
|
2355
|
+
} : undefined,
|
|
2356
|
+
geneBank: this.getGeneBankDashboardData(),
|
|
2357
|
+
},
|
|
2358
|
+
}, { genomeId: this.genome.id });
|
|
2359
|
+
return {
|
|
2360
|
+
applied: false,
|
|
2361
|
+
reason: gateResult.reason,
|
|
2362
|
+
gateResults: {
|
|
2363
|
+
quality: gateResult.gates.quality,
|
|
2364
|
+
sandbox: gateResult.gates.sandbox,
|
|
2365
|
+
economic: gateResult.gates.economic,
|
|
2366
|
+
stability: gateResult.gates.stability,
|
|
2367
|
+
},
|
|
2368
|
+
};
|
|
2369
|
+
})();
|
|
1309
2370
|
if (result.applied && this.genomeKernel) {
|
|
1310
2371
|
try {
|
|
1311
2372
|
this.genomeKernel = new GenomeKernel(this.toGenomeV2(), {
|
|
@@ -1565,6 +2626,89 @@ Ready to see what we can do together? 😊`,
|
|
|
1565
2626
|
async getProactiveSuggestions(userId, currentMessage) {
|
|
1566
2627
|
return this.proactiveSuggestions.generateSuggestions(userId, this.genome.id, currentMessage);
|
|
1567
2628
|
}
|
|
2629
|
+
registerSkill(name, description, inputSchema, execute) {
|
|
2630
|
+
this.skillRegistry.registerInline(name, description, inputSchema, execute);
|
|
2631
|
+
this.events.emitSync('skill:registered', {
|
|
2632
|
+
genomeId: this.genome.id,
|
|
2633
|
+
skill: name,
|
|
2634
|
+
description,
|
|
2635
|
+
}, { genomeId: this.genome.id });
|
|
2636
|
+
}
|
|
2637
|
+
async connectMCPServer(uri) {
|
|
2638
|
+
return this.skillExecutor.connectMCP(uri);
|
|
2639
|
+
}
|
|
2640
|
+
getSkillRegistry() {
|
|
2641
|
+
return this.skillRegistry;
|
|
2642
|
+
}
|
|
2643
|
+
getSkillRanking() {
|
|
2644
|
+
return this.skillRegistry.getRankedSkills();
|
|
2645
|
+
}
|
|
2646
|
+
async runWithSkills(systemPrompt, userMessage) {
|
|
2647
|
+
if (!this.skillRouter) {
|
|
2648
|
+
throw new Error('[GSEP] Skill router requires an LLM adapter');
|
|
2649
|
+
}
|
|
2650
|
+
return this.skillRouter.run(systemPrompt, userMessage);
|
|
2651
|
+
}
|
|
2652
|
+
addProactiveTask(task) {
|
|
2653
|
+
if (!this.proactiveEngine) {
|
|
2654
|
+
throw new Error('[GSEP] Proactive engine requires an LLM adapter');
|
|
2655
|
+
}
|
|
2656
|
+
this.proactiveEngine.addTask(task);
|
|
2657
|
+
}
|
|
2658
|
+
startProactiveEngine() {
|
|
2659
|
+
this.proactiveEngine?.start();
|
|
2660
|
+
this.events.emitSync('proactive:started', {
|
|
2661
|
+
genomeId: this.genome.id,
|
|
2662
|
+
}, { genomeId: this.genome.id });
|
|
2663
|
+
}
|
|
2664
|
+
stopProactiveEngine() {
|
|
2665
|
+
this.proactiveEngine?.stop();
|
|
2666
|
+
}
|
|
2667
|
+
onProactiveNotification(handler) {
|
|
2668
|
+
this.proactiveEngine?.onNotification(handler);
|
|
2669
|
+
}
|
|
2670
|
+
async runProactiveTasks() {
|
|
2671
|
+
const results = await (this.proactiveEngine?.runAll() ?? Promise.resolve([]));
|
|
2672
|
+
for (const result of results) {
|
|
2673
|
+
this.events.emitSync('proactive:completed', {
|
|
2674
|
+
genomeId: this.genome.id,
|
|
2675
|
+
taskId: result.taskId,
|
|
2676
|
+
taskName: result.taskName,
|
|
2677
|
+
shouldNotify: result.shouldNotify,
|
|
2678
|
+
importance: result.importance,
|
|
2679
|
+
summary: result.findings.substring(0, 200),
|
|
2680
|
+
}, { genomeId: this.genome.id });
|
|
2681
|
+
}
|
|
2682
|
+
return results;
|
|
2683
|
+
}
|
|
2684
|
+
getProactiveResults(limit) {
|
|
2685
|
+
return this.proactiveEngine?.getResults(limit) ?? [];
|
|
2686
|
+
}
|
|
2687
|
+
generateWeeklyReport() {
|
|
2688
|
+
const report = this.weeklyReportGenerator.generate();
|
|
2689
|
+
if (this.growthJournal) {
|
|
2690
|
+
const snapshot = this.growthJournal.getGrowthSnapshot();
|
|
2691
|
+
if (snapshot.narrative) {
|
|
2692
|
+
report.summary += `\n\n🌱 Growth: ${snapshot.narrative}`;
|
|
2693
|
+
}
|
|
2694
|
+
if (snapshot.recentInsights.length > 0) {
|
|
2695
|
+
report.suggestions.push(...snapshot.recentInsights.slice(0, 3).map(i => `Growth insight: ${i}`));
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
return report;
|
|
2699
|
+
}
|
|
2700
|
+
getAnomalyAnalytics() {
|
|
2701
|
+
return this.anomalyDetector.getAnalytics();
|
|
2702
|
+
}
|
|
2703
|
+
getAnomalyHistory(limit) {
|
|
2704
|
+
return this.anomalyDetector.getHistory(limit);
|
|
2705
|
+
}
|
|
2706
|
+
getGrowthSnapshot() {
|
|
2707
|
+
return this.growthJournal?.getGrowthSnapshot() ?? null;
|
|
2708
|
+
}
|
|
2709
|
+
getWeekInteractionCount() {
|
|
2710
|
+
return this.weeklyReportGenerator.getWeekInteractionCount();
|
|
2711
|
+
}
|
|
1568
2712
|
async getConversationContext(userId) {
|
|
1569
2713
|
return this.contextMemory.buildContext(userId, this.genome.id);
|
|
1570
2714
|
}
|
|
@@ -1662,6 +2806,12 @@ Ready to see what we can do together? 😊`,
|
|
|
1662
2806
|
}
|
|
1663
2807
|
}
|
|
1664
2808
|
if (autoConfig?.autoMutateOnDrift !== false && drift.isDrifting) {
|
|
2809
|
+
this.events.emitSync('mutation:generated', {
|
|
2810
|
+
genomeId: this.genome.id,
|
|
2811
|
+
gene: 'drift-response',
|
|
2812
|
+
layer: 1,
|
|
2813
|
+
candidateCount: drift.signals.length,
|
|
2814
|
+
}, { genomeId: this.genome.id });
|
|
1665
2815
|
if (this.strategicAutonomy && this.enhancedSelfModel) {
|
|
1666
2816
|
const health = this.enhancedSelfModel.assessFull();
|
|
1667
2817
|
const priorities = this.strategicAutonomy.prioritizeEvolution(drift.signals, health);
|
|
@@ -1702,6 +2852,43 @@ Ready to see what we can do together? 😊`,
|
|
|
1702
2852
|
}
|
|
1703
2853
|
}
|
|
1704
2854
|
}
|
|
2855
|
+
else {
|
|
2856
|
+
const activeC1 = this.genome.layers.layer1
|
|
2857
|
+
.filter((a) => a.status === 'active')
|
|
2858
|
+
.sort((a, b) => a.fitness - b.fitness);
|
|
2859
|
+
if (activeC1.length > 0) {
|
|
2860
|
+
const weakest = activeC1[0];
|
|
2861
|
+
this.events.emitSync('mutation:generated', {
|
|
2862
|
+
genomeId: this.genome.id,
|
|
2863
|
+
gene: weakest.gene,
|
|
2864
|
+
layer: 1,
|
|
2865
|
+
candidateCount: 1,
|
|
2866
|
+
}, { genomeId: this.genome.id });
|
|
2867
|
+
console.log(`[GSEP] 🔬 Exploratory mutation: trying to improve "${weakest.gene}" (fitness: ${weakest.fitness.toFixed(2)})`);
|
|
2868
|
+
try {
|
|
2869
|
+
await this.mutate({
|
|
2870
|
+
layer: 1,
|
|
2871
|
+
gene: weakest.gene,
|
|
2872
|
+
taskType: 'exploratory-evolution',
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
catch (err) {
|
|
2876
|
+
this.events.emitSync('mutation:rejected', {
|
|
2877
|
+
genomeId: this.genome.id,
|
|
2878
|
+
gene: weakest.gene,
|
|
2879
|
+
reason: err instanceof Error ? err.message : 'Exploration failed',
|
|
2880
|
+
}, { genomeId: this.genome.id });
|
|
2881
|
+
console.log(`[GSEP] 🔬 Exploratory mutation for "${weakest.gene}" — no improvement found (this is normal)`);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
else {
|
|
2885
|
+
this.events.emitSync('mutation:rejected', {
|
|
2886
|
+
genomeId: this.genome.id,
|
|
2887
|
+
gene: 'none',
|
|
2888
|
+
reason: 'No active C1 genes to evolve',
|
|
2889
|
+
}, { genomeId: this.genome.id });
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
1705
2892
|
if (autoConfig?.autoCompressOnPressure !== false) {
|
|
1706
2893
|
const totalC1Tokens = this.genome.layers.layer1
|
|
1707
2894
|
.filter(a => a.status === 'active')
|
|
@@ -1921,6 +3108,21 @@ Ready to see what we can do together? 😊`,
|
|
|
1921
3108
|
};
|
|
1922
3109
|
return mapping[signal.type] || { layer: 2, gene: 'communication-style' };
|
|
1923
3110
|
}
|
|
3111
|
+
getGeneBankDashboardData() {
|
|
3112
|
+
const allGenes = [
|
|
3113
|
+
...this.genome.layers.layer0,
|
|
3114
|
+
...this.genome.layers.layer1,
|
|
3115
|
+
...this.genome.layers.layer2,
|
|
3116
|
+
];
|
|
3117
|
+
const publishThreshold = this.genome.config.autonomous?.autoPublishThreshold ?? 0.85;
|
|
3118
|
+
return {
|
|
3119
|
+
active: !!this.geneBank,
|
|
3120
|
+
totalGenes: allGenes.filter(g => g.status === 'active').length,
|
|
3121
|
+
sellable: allGenes.filter(g => g.status === 'active' && g.fitness >= publishThreshold && !g.publishedToSwarm),
|
|
3122
|
+
published: allGenes.filter(g => g.publishedToSwarm),
|
|
3123
|
+
adopted: allGenes.filter(g => (g.variant || '').startsWith('swarm_')),
|
|
3124
|
+
};
|
|
3125
|
+
}
|
|
1924
3126
|
async autoPublishGene(allele) {
|
|
1925
3127
|
if (!this.geneBank)
|
|
1926
3128
|
return;
|
|
@@ -2225,4 +3427,4 @@ Ready to see what we can do together? 😊`,
|
|
|
2225
3427
|
return TECH_TERMS.filter(term => lower.includes(term));
|
|
2226
3428
|
}
|
|
2227
3429
|
}
|
|
2228
|
-
//# sourceMappingURL=
|
|
3430
|
+
//# sourceMappingURL=GSEP.js.map
|