Skip to main content
Normalized for Mintlify from knowledge-base/neurigraph-memory-architecture/neurigraph-tool-references/02-Multi-Database-Conversation-Memory-System.mdx.

Clean-Room Specification 02: Multi-Database Conversation Memory System (Markdown Memory Bank)

Document Purpose

This specification describes a markdown-file-based persistent memory system for AI coding assistants. The system maintains project context across sessions using a structured set of markdown files stored in the project’s version control. An AI coding model should be able to read this document and produce a functionally identical implementation without any additional references.

1. System Overview

1.1 What This System Does

This system provides persistent project memory for AI assistants that lose context between sessions. It works by maintaining a memory-bank/ directory of structured markdown files that the AI reads at the start of every session and updates as work progresses. The core insight: AI assistant memory resets completely between sessions. The Memory Bank is the sole bridge between sessions — the AI writes its understanding to disk before the session ends, then reads it back at the start of the next session.

1.2 Core Architecture

1.3 Key Design Decisions

  1. Pure markdown files: No database, no binary formats, no special tooling. Every file is plain markdown that humans can read and edit directly.
  2. Version-controlled: The memory-bank/ directory lives in the project’s git repository. Memory changes are committed alongside code changes.
  3. Hierarchical file structure: Files are organized in layers from most stable (project brief) to most volatile (active context). Read order goes bottom-up; update order goes top-down.
  4. Session-boundary persistence: Memory is explicitly read at session start and written at session end (or when triggered). There is no real-time streaming or incremental sync.
  5. AI-driven updates: The AI assistant itself decides what to write, when to write, and how to structure the content. The system provides conventions, not enforcement.
  6. No external dependencies: Works with any AI assistant that can read and write files. No database, no server, no API.

2. File Structure and Hierarchy

2.1 Directory Layout

2.2 File Hierarchy and Reading Order

Files MUST be read in this exact order (most stable → most volatile): Update order is REVERSED: When updating the memory bank, start with the most volatile files (progress, activeContext) and work backwards toward the stable files. Only update stable files when genuinely necessary.

3. Complete File Specifications

3.1 projectBrief.md — Foundation Layer

Purpose: Defines the project’s identity, scope, and core constraints. This is the foundational document that all other files build upon. Template Structure:
Update Rules:
  • Created once at project inception
  • Updated only when fundamental project direction changes
  • Changes here should cascade to all downstream files

3.2 productContext.md — Purpose Layer

Purpose: Captures the business and user perspective. Why does this exist from the user’s point of view? Template Structure:
Update Rules:
  • Updated when understanding of users or market changes
  • Updated when scope shifts significantly
  • Should reference projectBrief.md concepts

3.3 systemPatterns.md — Architecture Layer

Purpose: Documents the system architecture, design patterns, coding conventions, and technical decisions that shape how code is structured. Template Structure:
[ASCII diagram of system components]
src/ ├── controllers/ # HTTP handlers ├── services/ # Business logic ├── repositories/ # Data access ├── models/ # Type definitions └── utils/ # Shared utilities
Update Rules:
  • Updated when new patterns are adopted
  • Updated when architecture changes significantly (≥25% impact)
  • Changes should be reflected in decisionLog.md

3.4 techContext.md — Technology Layer

Purpose: Records the complete technology stack, development setup, and operational details needed to work on the project. Template Structure:
Update Rules:
  • Updated when dependencies change
  • Updated when build/deploy process changes
  • Keep version numbers current

3.5 activeContext.md — Current State Layer

Purpose: Captures the current session’s state — what was just done, what’s in progress, and what’s next. This is the MOST VOLATILE file and should be updated frequently. Template Structure:
Update Rules:
  • Updated at the START of every session (after reading)
  • Updated during work when significant progress occurs
  • Updated at END of every session with final state
  • Should be written as if briefing a new developer who knows nothing about recent work

3.6 progress.md — Tracking Layer

Purpose: Maintains a historical record of what’s been completed, what’s in progress, and what’s planned. Uses checkbox-style task tracking. Template Structure:
Update Rules:
  • Move completed items from “In Progress” to “Completed” with dates
  • Add new items to “In Progress” as work begins
  • Update “Known Issues” as bugs are found or fixed
  • Keep “Upcoming” current with planned work

3.7 decisionLog.md — Decision History

Purpose: Permanent record of architectural and technical decisions with full rationale. This is an APPEND-ONLY file — entries are never deleted. Template Structure:
Update Rules:
  • New entries appended when architectural decisions are made
  • Existing entries are NEVER deleted (append-only)
  • Mark old entries as “Superseded” when replaced by new decisions
  • Include date and context for every entry

4. Operating Modes

The system defines distinct behavioral modes that control how the AI interacts with the memory bank.

4.1 Plan Mode

When activated: At the start of a new task or when the AI needs to analyze before acting. Workflow:

4.2 Act Mode

When activated: After planning is complete and the user approves the approach. Workflow:

4.3 Extended Modes (Multi-Mode System)

Some implementations support 5 specialized modes: Mode-specific memory updates:
  • Architect mode → Updates systemPatterns.md and productContext.md
  • Code mode → Updates progress.md and activeContext.md
  • Ask mode → Reads only, does not modify memory files
  • Debug mode → Records findings in activeContext.md

5. Memory Update Protocol

5.1 Update Triggers

Memory bank updates are triggered by:
  1. Automatic triggers:
    • Discovering new project patterns (≥25% impact on existing patterns)
    • Completing a significant implementation task
    • Making an architectural or technical decision
    • End of session (if not already updated)
  2. Manual triggers:
    • User explicitly says “update memory bank” or “UMB”
    • User requests documentation refresh
    • User initiates a new session

5.2 Update Procedure

When updating the memory bank, follow this procedure:

5.3 Content Writing Guidelines

When writing memory bank content:
  • Write for a stranger: Assume the reader has no context about recent work
  • Be specific: Include file names, function names, error messages — not vague descriptions
  • Be current: Remove outdated information; don’t accumulate stale state
  • Be concise: Each file should be readable in under 2 minutes
  • Use markdown properly: Headers, bullet points, code blocks for structure
  • Include dates: Especially in progress.md and decisionLog.md

5.4 JSON Escaping Rules

When updating files programmatically (e.g., via MCP tools or file write APIs):
  • Use \\n for newlines in JSON strings (not literal newlines)
  • Use lowercase booleans: true, false
  • Escape quotes inside strings: \"
  • Use forward slashes in file paths: path/to/file (never backslashes)

6. Session Lifecycle

6.1 Session Start Protocol

CRITICAL RULE: The AI MUST read ALL memory bank files at the start of EVERY task. This is non-negotiable.

6.2 Mid-Session Updates

During work, update memory when:
  • A feature or significant task is completed
  • A new decision is made
  • A blocker is encountered or resolved
  • The user switches focus to a different area

6.3 Session End Protocol


7. Initialization System

7.1 New Project Setup

When initializing a memory bank for a new project:

7.2 File Validation

When reading the memory bank, validate:

8. MCP Server Implementation

For AI assistants that support MCP (Model Context Protocol), the memory bank can be exposed as an MCP server with the following tools:

8.1 Tool Definitions

initialize_memory_bank
  • Action: Creates memory-bank/ directory and template files at projectPath
  • Returns: List of created files
list_projects
  • Action: Scans MEMORY_BANK_ROOT for directories containing memory-bank/ subdirectories
memory_bank_read
  • Action: Reads specified file from project’s memory-bank/ directory
  • Security: Path traversal prevention — fileName cannot contain .. or start with /
memory_bank_write
  • Action: Creates a new file in the project’s memory-bank/ directory
  • Security: Same path traversal prevention
memory_bank_update
  • Action: Overwrites an existing file
list_project_files
  • Action: Lists all files in the project’s memory-bank/ directory
validate_project
  • Action: Checks for required and recommended files

8.2 MCP Server Configuration

8.3 Security Model

  • Path traversal prevention: All file operations validate that the resolved path stays within the project’s memory-bank/ directory
  • Per-project isolation: Each project has its own memory-bank/ directory; no cross-project access
  • Read-only option: Some modes (Ask, Debug) can be restricted to read-only access
  • File type restriction: Only .md files are allowed

8.4 Auto-Approve Configuration

For seamless operation, these tools can be configured for auto-approval (no user confirmation needed):
  • memory_bank_read
  • memory_bank_write
  • memory_bank_update
  • list_projects
  • list_project_files

9. Custom Rules System

9.1 Project-Level Rules (.clinerules)

A .clinerules file at the project root contains project-specific instructions for the AI assistant:

9.2 Mode-Specific Rules

For multi-mode systems, separate rule files per mode:

9.3 Rules with Path Scoping

Rules can be scoped to specific file paths using YAML frontmatter:

10. AI System Prompt Specification

10.1 Core Instructions

The following system prompt instructions are CRITICAL for correct behavior:

11. Behavioral Test Specifications

11.1 Initialization Tests

Test: Create memory bank for new project
  • Input: Initialize memory bank at /project/
  • Expected: memory-bank/ directory created with 7 template files
  • Each file has at least one markdown header and placeholder content
Test: Initialize with project brief
  • Input: Initialize with brief “A REST API for managing todo items”
  • Expected: projectBrief.md populated with provided content; other files have derived initial content
Test: Detect existing memory bank
  • Input: Project already has memory-bank/ with files
  • Expected: Files are read, not overwritten

11.2 Read Operation Tests

Test: Read all files in order
  • Setup: Memory bank with all 7 files
  • Input: Session start
  • Expected: All files read in hierarchical order (1→7)
Test: Handle missing optional files
  • Setup: Memory bank with only projectBrief.md, activeContext.md, progress.md
  • Expected: Required files read successfully; missing optional files noted but not blocking
Test: Handle empty memory bank
  • Setup: Empty memory-bank/ directory
  • Expected: Offer to initialize with templates

11.3 Write Operation Tests

Test: Update activeContext.md
  • Input: Update with current session state
  • Expected: File overwritten with new content; old content replaced
Test: Append to decisionLog.md
  • Setup: Decision log with 2 existing entries
  • Input: Add new decision
  • Expected: New entry appended AFTER existing entries; old entries preserved
Test: Update progress.md checkboxes
  • Setup: Task “Feature X” in “In Progress”
  • Input: Mark “Feature X” as complete
  • Expected: Task moved to “Completed” section with checkbox checked and date added

11.4 Security Tests

Test: Path traversal prevention
  • Input: Read file with name ../../etc/passwd
  • Expected: Rejected — path resolves outside memory-bank/ directory
Test: File type restriction
  • Input: Write file named script.sh to memory bank
  • Expected: Rejected — only .md files allowed
Test: Project isolation
  • Input: Read file from different project’s memory bank
  • Expected: Rejected — can only access current project’s files

11.5 Session Lifecycle Tests

Test: Full session lifecycle
Test: Mid-session update trigger
  • Trigger: User says “update memory bank”
  • Expected: All changed files updated in reverse hierarchy order

12. Multi-Project Support

12.1 Project Detection

When multiple projects exist under MEMORY_BANK_ROOT:
The system should:
  1. Scan for directories containing memory-bank/ subdirectories
  2. Present available projects to the user
  3. Allow project selection
  4. Load the selected project’s memory bank

12.2 Project Switching

When switching between projects:
  1. Save current project’s memory state (update all changed files)
  2. Confirm project switch with user
  3. Load new project’s memory bank in full
  4. Present new project’s current state

13. Context Window Management

13.1 Token Budget

Memory bank content consumes context window tokens. Guidelines:
  • Total context window: ~200K tokens (model dependent)
  • Memory bank budget: Keep under 5,000 tokens total across all files
  • Per-file target: 500-1,000 tokens (~200-400 words)
  • activeContext.md: Most token-intensive — keep focused on CURRENT state only

13.2 Content Hygiene

To prevent memory files from growing unbounded:
  • activeContext.md: Replace entirely each session (not append)
  • progress.md: Archive completed items to a separate archive/ directory after milestones
  • decisionLog.md: This grows indefinitely but each entry is small (~100 tokens)
  • All files: Remove verbose explanations; prefer bullet points and specific references

14. Implementation Checklist

To build a functionally identical system:
  1. Directory structure: Create memory-bank/ in project root with 7 template files
  2. File templates: Each file pre-populated with headers and placeholder sections per Section 3
  3. Read protocol: Implement hierarchical read order (Layer 1→7) at session start
  4. Write protocol: Implement reverse-order updates (Layer 7→1) on triggers
  5. System prompt: Include the full instruction set from Section 10
  6. Update triggers: Detect ≥25% impact changes, completion events, manual “UMB” command
  7. Initialization: Auto-detect codebase and pre-populate techContext/systemPatterns from project analysis
  8. MCP tools (if applicable): Implement 7 tools per Section 8
  9. Security: Path traversal prevention, file type restriction, project isolation
  10. Custom rules: Support .clinerules file and mode-specific rule files
  11. Multi-project: Scan for and list available projects under root directory
Total system is pure markdown files + AI system prompt instructions. No database, no server (unless MCP), no special runtime.