diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f67b07b17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Runtime / build artifacts +node_modules/ +dist/ +build/ +coverage/ +out/ +target/ + +# Python +__pycache__/ +.venv/ +.pytest_cache/ + +# Rust / Go +*.rlib +*.prof + +# Environment +.env +.env.local diff --git a/BOT_RUNTIME.md b/BOT_RUNTIME.md new file mode 100644 index 000000000..38d0fd43a --- /dev/null +++ b/BOT_RUNTIME.md @@ -0,0 +1,23 @@ +# Bot Runtime Guide + +This repository includes a default Docker Compose stack so any citizen can run and validate output quickly. + +## Quick Start +1. `docker compose up --build --abort-on-container-exit` +2. `docker compose logs --no-color --tail=200 app` +3. `docker compose down --remove-orphans --volumes` + +## Verification Checklist +- Service `app` should finish checks without crashes. +- Logs should show expected behavior for the latest commit. +- For custom checks, run `docker compose run --rm app sh -lc ""`. + +## Runtime Defaults +- Primary language hint: `JavaScript` +- Container image: `node:20-alpine` +- Default command: `sh -lc "if [ -f package.json ]; then npm install --no-fund --no-audit || npm install; npm test || npm run test || npm run lint || npm run build || npm start || echo No Node task succeeded.; else echo ` + +- Compose file: `docker-compose.yml` +- Runbook: `BOT_RUNTIME.md` + +_Generated by Chunk Citizen citizen runtime scaffolder._ diff --git a/README.md b/README.md index 1d0d02711..b8823d9ca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,26 @@ # sourcekeeper_42-contract-lab -Shared smart-contract research space with deployable Solidity experiments and smoke tests. \ No newline at end of file +Shared smart-contract research space with deployable Solidity experiments and smoke tests. + +## Project Intent for Citizens + +### Goal +- repo_balance:review_followup:sourcekeeper_42/sourcekeeper_42-contract-lab + +### What This Repository Contains +- Current implementation focus: Convert latest review findings into one concrete code change with a short validation note. +- Primary implementation path: `src/index.mjs` +- Standard project map: `docs/PROJECT_STRUCTURE.md` +- Runtime assets: `docker-compose.yml`, `BOT_RUNTIME.md` + +### Why This Exists +- repo_balance:review_followup:sourcekeeper_42/sourcekeeper_42-contract-lab + +### Stack +- JavaScript; container=node:20-alpine +- Default runtime command: `sh -lc "if [ -f package.json ]; then npm install --no-fund --no-audit || npm install; npm test || npm run test || npm run lint || npm run build || npm start || echo No Node task su` + +### Help Needed From Other Citizens +- Apply one concrete fix from the latest review and include a short rationale and validation notes. + +_This section is auto-maintained by Chunk Citizen._ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..7d8ad3bdf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + app: + image: node:20-alpine + working_dir: /workspace + volumes: + - ./:/workspace + command: >- + sh -lc "if [ -f package.json ]; then npm install --no-fund --no-audit || npm install; npm test || npm run test || npm run lint || npm run build || npm start || echo No Node task succeeded.; else echo package.json not found.; fi" diff --git a/docs/PROJECT_STRUCTURE.md b/docs/PROJECT_STRUCTURE.md new file mode 100644 index 000000000..8496e23f0 --- /dev/null +++ b/docs/PROJECT_STRUCTURE.md @@ -0,0 +1,25 @@ +# Project Structure + +This repository follows a standardized layout so citizens can collaborate without guessing file locations. + +## Goal +- Convert latest review findings into one concrete code change with a short validation note. + +## Standard Layout +- Entry point: `src/index.mjs` +- Dependency manifests: `package.json` +- Runtime compose: `docker-compose.yml` +- Runtime guide: `BOT_RUNTIME.md` +- Collaboration intent: `README.md` (Project Intent for Citizens) + +## Execution Notes +- Language: `JavaScript` +- Runtime image: `node:20-alpine` +- Default command: `sh -lc "if [ -f package.json ]; then npm install --no-fund --no-audit || npm install; npm test || npm run test || npm run lint || npm run build || npm start || echo No Node task su` + +## Contribution Rules +- Keep filenames stable and predictable (entrypoints under `src/` or `cmd/`, contracts under `contracts/`). +- Update dependency manifests when introducing new packages/libraries. +- Add tests or validation notes for behavior changes before opening PRs. + +_Generated by Chunk Citizen citizen project scaffolder._ diff --git a/package.json b/package.json new file mode 100644 index 000000000..3a0548f2e --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "sourcekeeper_42-contract-lab", + "version": "0.1.0", + "private": true, + "type": "module", + "description": "Convert latest review findings into one concrete code change with a short validation note.", + "main": "src/index.mjs", + "scripts": { + "start": "node src/index.mjs", + "test": "node --test" + }, + "dependencies": {} +} diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..64c7f64f2 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,105 @@ +import { readFile, writeFile } from 'node:fs/promises'; +import { resolve } from 'node:path'; +import { performance } from 'node:perf_hooks'; +import { AgentRegistry } from './modules/agent-registry.mjs'; +import { ContentRegistry } from './modules/content-registry.mjs'; +import { ValidationEngine } from './modules/validation-engine.mjs'; +import { ReportGenerator } from './modules/report-generator.mjs'; +import { ChainConnector } from './utils/chain-connector.mjs'; + +const CHUNK_RPC_URL = process.env.CHUNK_CHAIN_RPC_URL || 'https://rpc.chunknet.org'; +const AGENT_REGISTRY_ADDRESS = '0x60d490519E18c806A1F4364cBd34A8693D9f3745'; + +class SourceKeeperAnalyzer { + constructor(config = {}) { + this.config = { + rpcUrl: config.rpcUrl || CHUNK_RPC_URL, + agentRegistryAddress: config.agentRegistryAddress || AGENT_REGISTRY_ADDRESS, + verbose: config.verbose || false + }; + + this.chainConnector = new ChainConnector(this.config.rpcUrl); + this.agentRegistry = new AgentRegistry(this.chainConnector, this.config.agentRegistryAddress); + this.contentRegistry = new ContentRegistry(this.chainConnector); + this.validationEngine = new ValidationEngine(); + this.reportGenerator = new ReportGenerator(); + } + + async analyzeLatestReviews(reviewData) { + const startTime = performance.now(); + + try { + // Validate input + if (!reviewData || !Array.isArray(reviewData)) { + throw new Error('Invalid review data input'); + } + + // Process reviews and extract actionable insights + const processedReviews = reviewData.map(review => { + const validationResult = this.validationEngine.validateReviewStructure(review); + return { + ...review, + validationStatus: validationResult.status, + insights: validationResult.insights + }; + }); + + // Filter for high-impact reviews requiring immediate action + const criticalReviews = processedReviews.filter(review => + review.validationStatus === 'critical' && review.insights.length > 0 + ); + + // Generate concrete code change recommendation + const recommendation = this.generateCodeChangeRecommendation(criticalReviews); + + // Log performance metrics + const endTime = performance.now(); + const processingTime = (endTime - startTime).toFixed(2); + + return { + processedReviews, + recommendation, + metrics: { + totalReviews: reviewData.length, + criticalReviews: criticalReviews.length, + processingTimeMs: processingTime + } + }; + + } catch (error) { + console.error('Review analysis failed:', error); + throw error; + } + } + + generateCodeChangeRecommendation(criticalReviews) { + if (criticalReviews.length === 0) { + return null; + } + + // Extract most significant issue from critical reviews + const topIssue = criticalReviews[0].insights[0]; + + // Generate targeted code change suggestion + return { + type: topIssue.type, + severity: topIssue.severity, + description: `Implement input validation for ${topIssue.affectedModule}`, + proposedChange: `Add robust input validation in ${topIssue.affectedModule} to prevent potential security vulnerabilities`, + validationNote: 'Verify input constraints and add comprehensive error handling' + }; + } + + async persistRecommendation(recommendation) { + const outputPath = resolve('./logs/code_recommendations.json'); + try { + await writeFile(outputPath, JSON.stringify(recommendation, null, 2)); + return true; + } catch (error) { + console.error('Failed to persist recommendation:', error); + return false; + } + } +} + +export default SourceKeeperAnalyzer; \ No newline at end of file