# Memory Layer: Source of Truth (v1.0)
## Purpose of This Document
This document defines the **memory layer** for the local-canvas project.
It exists to:
- Prevent over-engineering
- Serve as the authoritative reference for how memory works
- Make explicit what is *in scope* vs *out of scope*
- Anchor future extensions without rewriting fundamentals
If behavior is unclear, **this document wins**.
---
## Core Principle
**Memory is project state, not AI cognition.**
The system does not "remember" things the way a chatbot does.
It **persists, versions, and structures documents** so intelligence can be layered on later.
---
## Architectural Foundations
### Three-Layer Memory Model┌─────────────────────────────────────┐ │ CONTENT MEMORY (project.db) │ │ • Versioned AI artifacts │ │ • Immutable, never lost │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ AGENT MEMORY (agent.db) │ │ • Task coordination │ │ • Rebuildable if lost │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ RUNTIME MEMORY (in-memory) │ │ • Current execution state │ │ • Ephemeral, not persisted │ └─────────────────────────────────────┘
### Database Separation
| Database | Scope | Purpose | Durability |
|----------|-------|---------|------------|
| `app.db` | Global | Project discovery and defaults | Persistent |
| `project.db` | Per-project | Content and AI artifacts | **Permanent** |
| `agent.db` | Per-project | Agent coordination state | **Rebuildable** |
---
## On-Disk Project Layout (Canonical)
/ project.json # Project identity (UUID, name, created_at) project.db # Content memory (schema below) agent.db # Agent coordination memory (optional for MVP) draft.md # Content file
### `project.json`
```json
{
"project_id": "uuid-v4",
"name": "Project Name",
"created_at": "2026-01-19T03:00:00Z"
}
This file allows a project to be recognized even without databases.
Tracks known projects.
projects_index
- project_id TEXT PRIMARY KEY # Matches project.json UUID
- name TEXT NOT NULL
- last_known_path TEXT NOT NULL # Updated if project moves
- last_opened_at DATETIME
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
Rule: No document content in global database.
Single-row table describing the project.
project_meta
- id TEXT PRIMARY KEY # UUID, matches project.json
- name TEXT NOT NULL
- created_at DATETIME NOT NULL
- updated_at DATETIME
Tracks files belonging to the project.
files
- id INTEGER PRIMARY KEY
- path TEXT UNIQUE NOT NULL # Relative to project root
- created_at DATETIME NOT NULL
- last_modified INTEGER # For external change detection
The core of content memory.
file_versions
- id INTEGER PRIMARY KEY
- file_id INTEGER NOT NULL
- version_number INTEGER NOT NULL
- content TEXT NOT NULL
- save_type TEXT CHECK(save_type IN ('manual', 'autosave'))
- created_at DATETIME NOT NULL
- FOREIGN KEY(file_id) REFERENCES files(id)
- UNIQUE(file_id, version_number)
AI-generated content linked to specific versions.
version_artifacts
- id INTEGER PRIMARY KEY
- file_version_id INTEGER NOT NULL
- artifact_type TEXT NOT NULL # 'summary', 'outline', 'analysis', etc.
- content TEXT NOT NULL
- created_at DATETIME NOT NULL
- FOREIGN KEY(file_version_id) REFERENCES file_versions(id) ON DELETE CASCADE
Tracks agent execution state (rebuildable).
agent_tasks
- id TEXT PRIMARY KEY # UUID or unique identifier
- project_id TEXT NOT NULL # Matches project.json UUID
- file_version_id INTEGER # Target version (nullable)
- agent_type TEXT NOT NULL # 'summarize', 'analyze', 'embed'
- priority INTEGER DEFAULT 0 # 0=low, 1=normal, 2=high, 3=user_action
- status TEXT DEFAULT 'pending' # 'pending', 'running', 'completed', 'failed'
- resource_estimate TEXT # JSON: {"ram_mb": 512, "gpu_seconds": 30}
- created_at DATETIME
- started_at DATETIME
- completed_at DATETIME
- error TEXT
Note: agent.db is rebuildable. It can be cleared and reconstructed without data loss.
- Write editor buffer to disk (
.mdfile) - Insert new
file_versionsrow - Increment
version_number - Represents intentional checkpoint
- Out of scope for MVP
- Will be added later as rolling/throttled versions
- ✅ Read from
file_versionstable - ✅ Write to
version_artifactstable - ✅ Use local/LAN Ollama only (
localhost:11434or LAN IP)
- ❌ Write directly to disk files
- ❌ Modify
file_versionscontent - ❌ Use external AI services (OpenAI, Anthropic, etc.)
- ❌ Store state outside defined tables
Agents must:
- Check system resources (CPU, RAM, GPU) before running
- Respect concurrent execution limits
- Yield immediately to user interactions
- Queue tasks when resources limited
- Same
file_version_id+agent_type→ same output - Agents track completion to prevent duplicate work
- Failed tasks can be retried without side effects
A feature may extend the memory layer only if:
- Builds on existing tables - No schema-breaking changes
- Maintains data integrity - Never invalidates persisted data
- Respects separation - Agent state stays in
agent.db, content inproject.db - Remains local-first - No external dependencies introduced
If a feature violates these, it belongs in docs/future-extensions.md.
All implementations must pass:
- Offline test - Works with zero internet connectivity
- Portability test - Project folder can be moved/zipped without breaking
- Separation test - Agent state can be rebuilt without content loss
- Resource test - Never assumes infinite CPU/RAM/GPU
The memory layer is:
- Deterministic - Same input → same stored output
- Auditable - All changes versioned and traceable
- Boring by design - No cleverness, just persistence
- Foundation for intelligence - AI builds upon, doesn't replace
All higher-level understanding depends on this layer being correct and stable.
This document is the source of truth for the memory layer.
Refer to docs/agent-architecture.md for agent-specific details.