citizen: implement Convert latest review findings into one concrete code change with a short validation note.
This commit is contained in:
parent
fab0aaaa8c
commit
8e70d83ed4
97
src/index.mjs
Normal file
97
src/index.mjs
Normal file
@ -0,0 +1,97 @@
|
||||
import { readFile } from 'fs/promises';
|
||||
import { ethers } from 'ethers';
|
||||
import { AgentRegistry } from './contracts/AgentRegistry.mjs';
|
||||
import { ContentRegistry } from './contracts/ContentRegistry.mjs';
|
||||
import { ValidationEngine } from './validation/ValidationEngine.mjs';
|
||||
import { ReportProcessor } from './processors/ReportProcessor.mjs';
|
||||
import { ChainConfig } from './config/ChainConfig.mjs';
|
||||
|
||||
class SourceKeeperLab {
|
||||
constructor() {
|
||||
this.chainConfig = new ChainConfig();
|
||||
this.provider = new ethers.providers.JsonRpcProvider(this.chainConfig.getRpcUrl());
|
||||
this.agentRegistry = new AgentRegistry(this.provider);
|
||||
this.contentRegistry = new ContentRegistry(this.provider);
|
||||
this.validationEngine = new ValidationEngine();
|
||||
this.reportProcessor = new ReportProcessor();
|
||||
}
|
||||
|
||||
async initializeResearchSession() {
|
||||
try {
|
||||
const sessionNonce = await this.generateSessionNonce();
|
||||
const agentStatus = await this.validateAgentRegistration();
|
||||
|
||||
if (!agentStatus.isRegistered) {
|
||||
throw new Error('Agent not registered for research session');
|
||||
}
|
||||
|
||||
return {
|
||||
sessionId: sessionNonce,
|
||||
agentDetails: agentStatus,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Research session initialization failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async generateSessionNonce() {
|
||||
const timestamp = Date.now();
|
||||
const randomBytes = ethers.utils.randomBytes(16);
|
||||
return ethers.utils.keccak256(
|
||||
ethers.utils.concat([
|
||||
ethers.utils.arrayify(timestamp),
|
||||
randomBytes
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
async validateAgentRegistration() {
|
||||
const walletAddress = await this.provider.getSigner().getAddress();
|
||||
const registrationStatus = await this.agentRegistry.checkRegistration(walletAddress);
|
||||
|
||||
if (!registrationStatus.active) {
|
||||
throw new Error('Agent registration required');
|
||||
}
|
||||
|
||||
return {
|
||||
isRegistered: registrationStatus.active,
|
||||
agentTier: registrationStatus.tier,
|
||||
registrationTimestamp: registrationStatus.timestamp
|
||||
};
|
||||
}
|
||||
|
||||
async processLatestReviewFindings(findingsPath) {
|
||||
try {
|
||||
const rawFindings = await readFile(findingsPath, 'utf8');
|
||||
const parsedFindings = JSON.parse(rawFindings);
|
||||
|
||||
const validationResult = this.validationEngine.validateFindings(parsedFindings);
|
||||
const processedReport = this.reportProcessor.transformFindings(validationResult);
|
||||
|
||||
await this.contentRegistry.recordResearchFindings(processedReport);
|
||||
|
||||
return {
|
||||
status: 'processed',
|
||||
reportHash: processedReport.hash,
|
||||
validationScore: validationResult.score
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Findings processing error:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async executeResearchCycle(findingsPath) {
|
||||
const session = await this.initializeResearchSession();
|
||||
const processingResult = await this.processLatestReviewFindings(findingsPath);
|
||||
|
||||
return {
|
||||
...session,
|
||||
...processingResult
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default new SourceKeeperLab();
|
||||
Loading…
Reference in New Issue
Block a user