UNPKG

cortexweaver

Version:

CortexWeaver is a command-line interface (CLI) tool that orchestrates a swarm of specialized AI agents, powered by Claude Code and Gemini CLI, to assist in software development. It transforms a high-level project plan (plan.md) into a series of coordinate

146 lines (128 loc) 6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ContractTemplates = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const api_templates_1 = require("./api-templates"); const schema_templates_1 = require("./schema-templates"); /** * ContractTemplates handles the creation of formal contract directories and structure */ class ContractTemplates { static async createContractsDirectory(projectRoot) { const contractsPath = path.join(projectRoot, 'contracts'); // Create main contracts directory structure const contractDirs = [ contractsPath, path.join(contractsPath, 'api'), path.join(contractsPath, 'schemas'), path.join(contractsPath, 'schemas', 'models'), path.join(contractsPath, 'schemas', 'properties'), path.join(contractsPath, 'schemas', 'properties', 'invariants'), path.join(contractsPath, 'examples') ]; contractDirs.forEach(dir => { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } }); // Create templates in the appropriate directories await api_templates_1.ApiTemplates.createOpenApiTemplate(path.join(contractsPath, 'api')); await schema_templates_1.SchemaTemplates.createJsonSchemaTemplates(path.join(contractsPath, 'schemas')); // Create contracts README const contractsReadmePath = path.join(contractsPath, 'README.md'); if (!fs.existsSync(contractsReadmePath)) { const contractsReadmeContent = `# CortexWeaver Contracts This directory contains formal specifications that define the behavior of your application. These contracts serve as the source of truth for all AI agents in the CortexWeaver ecosystem. ## Directory Structure \`\`\` contracts/ ├── README.md # This file ├── api/ # OpenAPI specifications │ └── openapi.yaml # Main API specification ├── schemas/ # JSON Schema definitions │ ├── models/ # Data model schemas │ │ └── user.schema.json # Example user schema │ ├── properties/ # Property-based test definitions │ │ └── invariants/ # Behavioral invariants │ │ └── auth.properties.ts │ └── examples/ # Example data for testing │ └── user-examples.json \`\`\` ## Specification-Driven Development (SDD) CortexWeaver follows SDD principles where: 1. **Contracts come first** - Define behavior before implementation 2. **Agents verify compliance** - Multiple AI agents validate against contracts 3. **Tests derive from contracts** - Property-based tests ensure invariants 4. **Implementation follows contracts** - Code must satisfy specifications ## Contract Types ### OpenAPI Specifications (\`/api/\`) - Define REST API endpoints, request/response schemas - Specify authentication, error handling, status codes - Document all public interfaces ### JSON Schemas (\`/schemas/models/\`) - Define data structures and validation rules - Specify required fields, types, constraints - Enable automatic validation and documentation ### Property Invariants (\`/schemas/properties/\`) - Define behavioral contracts and business rules - Specify system invariants that must always hold - Enable property-based testing and verification ### Examples (\`/examples/\`) - Provide sample data for testing and documentation - Include both valid and invalid examples - Support automated testing and validation ## Agent Integration CortexWeaver agents use these contracts as follows: - **Architect Agent**: Designs system based on contract specifications - **Coder Agent**: Implements code that satisfies contracts - **Property Tester**: Verifies implementation against invariants - **Quality Gatekeeper**: Ensures contract compliance - **Formalizer**: Converts requirements into formal contracts ## Best Practices 1. **Keep contracts updated** - Sync with implementation changes 2. **Use examples extensively** - Provide comprehensive test data 3. **Define clear invariants** - Specify what must always be true 4. **Version your contracts** - Track changes over time 5. **Validate early and often** - Test against contracts continuously --- *Generated by CortexWeaver CLI*`; fs.writeFileSync(contractsReadmePath, contractsReadmeContent); } } } exports.ContractTemplates = ContractTemplates; //# sourceMappingURL=contract-templates.js.map