UNPKG

@ldavis9000aws/mcp-project-memory

Version:

Enhanced memory system for software development projects with persistent context across sessions

209 lines (208 loc) 7.79 kB
/** * This file provides example usage of the Project Memory system. * You can use this to test the functionality or as a reference. */ import { promises as fs } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; // Types for our software development focused memory system import { EntityType, RelationType } from './types.js'; // Define sample project data for testing const projectData = { // Core project entity project: { name: "E-commerce_Platform", entityType: EntityType.Project, observations: [ "Online retail application with React frontend and Node.js backend", "Started on 2023-04-15", "MVP targeted for Q3 2023" ] }, // Component entities components: [ { name: "Frontend_App", entityType: EntityType.Component, observations: [ "React-based SPA with Material UI components", "Uses Redux for state management", "Implements responsive design for mobile and desktop" ] }, { name: "Authentication_Service", entityType: EntityType.Component, observations: [ "Handles user authentication and authorization", "Implements JWT for stateless auth", "Uses bcrypt for password hashing with 12 rounds" ] }, { name: "Product_Catalog", entityType: EntityType.Component, observations: [ "Manages product information and inventory", "Uses MongoDB for flexible schema", "Includes search capabilities with filters" ] } ], // Technology entities technologies: [ { name: "React", entityType: EntityType.Technology, observations: [ "Frontend library version 18.0", "Using functional components and hooks exclusively", "Using React Router for navigation" ] }, { name: "Node.js", entityType: EntityType.Technology, observations: [ "Server runtime version 18 LTS", "Using Express.js framework", "Configured with TypeScript" ] }, { name: "JWT_Auth", entityType: EntityType.Technology, observations: [ "JSON Web Tokens for stateless authentication", "Configured with 15-minute expiration for access tokens", "Using refresh tokens for persistent sessions" ] } ], // Decision entities decisions: [ { name: "MongoDB_Selection", entityType: EntityType.Decision, observations: [ "Selected on 2023-04-20", "Chosen for flexibility with varied product attributes", "Alternatives considered: PostgreSQL, MySQL", "Trade-off: Less rigid schema validation for more flexibility" ] }, { name: "JWT_Implementation", entityType: EntityType.Decision, observations: [ "Selected on 2023-05-01", "Alternatives considered: Session-based auth, OAuth only", "Chosen for stateless operation and horizontal scalability", "Drawback: Requires secure token storage on frontend" ] } ], // Issue entities issues: [ { name: "Token_Refresh_Bug", entityType: EntityType.Issue, observations: [ "Users occasionally logged out during active sessions", "Identified on 2023-06-10", "Root cause: Race condition in refresh token mechanism", "Status: Resolved on 2023-06-15" ] }, { name: "Mobile_Layout_Issue", entityType: EntityType.Issue, observations: [ "Product images overflow containers on small screens", "Identified on 2023-06-20", "Affects iOS Safari specifically", "Status: Open" ] } ], // Relations between entities relations: [ // Project contains components { from: "E-commerce_Platform", to: "Frontend_App", relationType: RelationType.Contains }, { from: "E-commerce_Platform", to: "Authentication_Service", relationType: RelationType.Contains }, { from: "E-commerce_Platform", to: "Product_Catalog", relationType: RelationType.Contains }, // Components use technologies { from: "Frontend_App", to: "React", relationType: RelationType.Uses }, { from: "Authentication_Service", to: "Node.js", relationType: RelationType.Uses }, { from: "Authentication_Service", to: "JWT_Auth", relationType: RelationType.Uses }, { from: "Product_Catalog", to: "Node.js", relationType: RelationType.Uses }, // Components depend on each other { from: "Frontend_App", to: "Authentication_Service", relationType: RelationType.DependsOn }, { from: "Frontend_App", to: "Product_Catalog", relationType: RelationType.DependsOn }, // Issues related to components { from: "Authentication_Service", to: "Token_Refresh_Bug", relationType: RelationType.AffectedBy }, { from: "Frontend_App", to: "Mobile_Layout_Issue", relationType: RelationType.AffectedBy }, // Decisions and implementations { from: "JWT_Implementation", to: "JWT_Auth", relationType: RelationType.LedTo }, { from: "Product_Catalog", to: "MongoDB_Selection", relationType: RelationType.DependsOn } ] }; /** * Generate sample memory data file for testing */ async function generateSampleData() { // Define memory file path const memoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../dist/memory.json'); // Prepare entities with timestamps const now = new Date().toISOString(); // Combine all entities const entities = [ { ...projectData.project, observations: projectData.project.observations.map(content => ({ content, timestamp: now })) }, ...projectData.components.map(component => ({ ...component, observations: component.observations.map(content => ({ content, timestamp: now })) })), ...projectData.technologies.map(tech => ({ ...tech, observations: tech.observations.map(content => ({ content, timestamp: now })) })), ...projectData.decisions.map(decision => ({ ...decision, observations: decision.observations.map(content => ({ content, timestamp: now })) })), ...projectData.issues.map(issue => ({ ...issue, observations: issue.observations.map(content => ({ content, timestamp: now })) })) ]; // Build the knowledge graph const graph = { entities, relations: projectData.relations }; // Write to file await fs.writeFile(memoryPath, JSON.stringify(graph, null, 2)); console.log(`Sample data written to ${memoryPath}`); } // Run the generator if this file is executed directly if (process.argv[1] === fileURLToPath(import.meta.url)) { generateSampleData().catch(console.error); }