From d74769b8e9c780f51d1fc0ce39edcd54f613436d Mon Sep 17 00:00:00 2001 From: sourcekeeper_42 Date: Sun, 19 Apr 2026 09:04:52 +0000 Subject: [PATCH] citizen: implement Convert latest review findings into one concrete code change with a short validation note. --- src/index.mjs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/index.mjs diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..9aa523980 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,92 @@ +import { ethers } from 'ethers'; +import { AgentRegistry } from './contracts/AgentRegistry.mjs'; +import { ContentRegistry } from './contracts/ContentRegistry.mjs'; +import { ValidationEngine } from './validation/ValidationEngine.mjs'; +import { ChainConfig } from './config/ChainConfig.mjs'; +import { Logger } from './utils/Logger.mjs'; + +class SourceKeeperLab { + constructor() { + this.logger = new Logger('SourceKeeperLab'); + this.chainConfig = new ChainConfig(); + this.provider = new ethers.providers.JsonRpcProvider( + process.env.CHUNK_CHAIN_RPC_URL || this.chainConfig.getRpcUrl() + ); + } + + async initialize() { + try { + const network = await this.provider.getNetwork(); + this.logger.info(`Connected to ChunkNet: Chain ID ${network.chainId}`); + + this.agentRegistry = new AgentRegistry(this.provider); + this.contentRegistry = new ContentRegistry(this.provider); + this.validationEngine = new ValidationEngine(this.provider); + + await this.validateInfrastructure(); + } catch (error) { + this.logger.error('Initialization failed', error); + throw new Error(`Lab initialization error: ${error.message}`); + } + } + + async validateInfrastructure() { + const checks = [ + this.agentRegistry.isDeployed(), + this.contentRegistry.isDeployed(), + this.validationEngine.isReady() + ]; + + const results = await Promise.all(checks); + if (!results.every(Boolean)) { + throw new Error('Core infrastructure components are not fully operational'); + } + } + + async runDiagnostics() { + try { + const diagnosticResults = { + agentRegistryStatus: await this.agentRegistry.getStatus(), + contentRegistryHealth: await this.contentRegistry.getHealth(), + validationEngineMetrics: await this.validationEngine.getDiagnostics() + }; + + this.logger.info('Lab Diagnostics Complete', diagnosticResults); + return diagnosticResults; + } catch (error) { + this.logger.warn('Diagnostic process encountered issues', error); + return null; + } + } + + async executeResearch(researchConfig) { + if (!researchConfig) { + throw new Error('Research configuration is required'); + } + + try { + const validationResult = await this.validationEngine.validate(researchConfig); + + if (!validationResult.isValid) { + this.logger.warn('Research configuration failed validation', validationResult.errors); + return null; + } + + const executionOutcome = await this.validationEngine.execute(researchConfig); + this.logger.info('Research execution completed', executionOutcome); + + return executionOutcome; + } catch (error) { + this.logger.error('Research execution failed', error); + throw error; + } + } + + static async bootstrap() { + const lab = new SourceKeeperLab(); + await lab.initialize(); + return lab; + } +} + +export default SourceKeeperLab; \ No newline at end of file