diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..ab627c7a6 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,74 @@ +import { ethers } from 'ethers'; +import { AgentRegistry } from './contracts/AgentRegistry.mjs'; +import { ContentRegistry } from './contracts/ContentRegistry.mjs'; +import { ValidationRegistry } from './contracts/ValidationRegistry.mjs'; +import { parseReviewFindings } from './utils/reviewParser.mjs'; +import { applyCodeChange } from './utils/codeChangeApplicator.mjs'; + +const CHUNK_RPC_URL = process.env.CHUNK_CHAIN_RPC_URL || 'https://rpc.chunknet.org'; +const CHAIN_ID = 214562; + +class SourceKeeperLab { + constructor() { + this.provider = new ethers.providers.JsonRpcProvider(CHUNK_RPC_URL, CHAIN_ID); + this.agentRegistry = new AgentRegistry(this.provider); + this.contentRegistry = new ContentRegistry(this.provider); + this.validationRegistry = new ValidationRegistry(this.provider); + } + + async processLatestReviewFindings() { + try { + const latestFindings = await parseReviewFindings(); + + if (!latestFindings || latestFindings.length === 0) { + console.log('No review findings to process'); + return null; + } + + const mostCriticalFinding = latestFindings[0]; + const changeResult = await applyCodeChange(mostCriticalFinding); + + if (changeResult.success) { + await this.validateCodeChange(changeResult); + return changeResult; + } else { + console.error('Code change application failed', changeResult.error); + return null; + } + } catch (error) { + console.error('Error processing review findings:', error); + throw error; + } + } + + async validateCodeChange(changeResult) { + const validationContext = { + changeType: changeResult.type, + impactScore: changeResult.impactScore, + validatedAt: new Date().toISOString() + }; + + try { + const validationHash = await this.validationRegistry.registerValidation(validationContext); + console.log(`Code change validated with hash: ${validationHash}`); + } catch (registryError) { + console.warn('Could not register validation in ValidationRegistry', registryError); + } + } + + async run() { + try { + const processedChange = await this.processLatestReviewFindings(); + if (processedChange) { + console.log('Successfully processed and validated code change'); + } + } catch (error) { + console.error('Execution failed:', error); + } + } +} + +const lab = new SourceKeeperLab(); +lab.run().catch(console.error); + +export default SourceKeeperLab; \ No newline at end of file