Skip to content

Commit 6aca16f

Browse files
authored
Merge pull request #244 from AppSprout-dev/docs/update-readme-architecture
docs: update README, CLAUDE.md, and ARCHITECTURE.md for v0.22+
2 parents 808c9e8 + 29e4c8d commit 6aca16f

3 files changed

Lines changed: 103 additions & 34 deletions

File tree

ARCHITECTURE.md

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,31 +128,47 @@ Raw Event → Size Filter → Pattern Blacklist → Frequency Dedup → Content
128128

129129
### Layer 2 — Encoding (Compression & Linking)
130130

131-
Triggered by `RawMemoryCreated` event:
132-
1. LLM compresses raw content → summary + concepts (structured output)
133-
2. Generate embedding via embedding provider
134-
3. Find similar memories via embedding + FTS
135-
4. Create association links with strength weights
136-
5. Emit `MemoryEncoded` event
131+
Triggered by `RawMemoryCreated` event. MCP-sourced memories are processed first (priority queue by source).
132+
133+
1. Atomic claim via `ClaimRawForEncoding` (prevents duplicate encoding across processes)
134+
2. LLM compresses raw content → summary + concepts (structured output, enforced vocabulary)
135+
3. Post-process concepts: strip metadata, normalize casing, deduplicate
136+
4. Generate embedding via embedding provider
137+
5. Deduplication check: if cosine similarity > threshold, boost existing memory instead
138+
6. Find similar memories via embedding + FTS, create association links
139+
7. Emit `MemoryEncoded` event
137140

138141
### Layer 3 — Consolidation (Sleep Cycle)
139142

140-
Runs every 6 hours (or on-demand). **Budget-constrained**: max 100 memories per cycle.
143+
Runs periodically (configurable, default 1h) or on-demand. **Budget-constrained**: max 100 memories per cycle.
141144

142145
Operations in order:
143-
1. **Decay**: `new_salience = salience * decay_rate^(hours_since_access)`
146+
1. **Decay**: `new_salience = salience * decay_rate^(hours_since_access)` with recency protection
144147
2. **State transitions**: active → fading (< 0.3) → archived (< 0.1) → deleted (> 90 days)
145148
3. **Strengthen**: Recently accessed memories get salience boost
146149
4. **Prune associations**: Weaken/remove low-strength, never-activated links
147150
5. **Merge** (max 5 per cycle): Cluster highly-related memories → LLM creates gist memory
151+
6. **Archive never-recalled noise**: Non-MCP memories with 0 access after 30 days → archived
152+
7. **Pattern extraction**: Identify recurring themes, deduplicate near-identical patterns
153+
8. **Abstraction dedup**: Archive zombie abstractions with near-zero confidence
148154

149155
### Layer 4 — Retrieval (Associative Recall)
150156

151157
```
152-
Query → [Parse + Embed] → Entry Points (FTS top 3 + Embedding top 3) → Spread Activation (3 hops) → Rank → Top 7 → [Optional: LLM Synthesis]
158+
Query → [Parse + Embed] → Entry Points (FTS + Embedding) → Spread Activation (3 hops) → Rank → Filter → Diversity (MMR) → [Optional: LLM Synthesis]
153159
```
154160

155-
Spread activation follows strongest association links, with activation decaying per hop. Every accessed memory gets strengthened (access_count++, last_accessed updated).
161+
Ranking considers multiple signals:
162+
- **Activation score** from spread activation traversal
163+
- **Recency bonus** (exponential decay from last access)
164+
- **Source weight** (MCP: 1.0, terminal: 0.8, filesystem: 0.5 -- configurable)
165+
- **Feedback adjustment** (memories rated helpful get boosted, irrelevant get penalized)
166+
- **Pattern evidence boost** (+0.1 for memories supporting matched patterns, +0.05 for abstraction sources)
167+
- **Significance multiplier** (critical/important memories from structured concept extraction)
168+
169+
Suppressed memories (accumulated negative feedback) are filtered out by default. Every accessed memory gets strengthened (access_count++, last_accessed updated).
170+
171+
The `recall` tool supports `explain: true` to surface score breakdowns, `include_associations: true` to show the knowledge graph, and `format: "json"` for structured output.
156172

157173
### Layer 5 — Episoding (Temporal Clustering)
158174

@@ -195,7 +211,7 @@ Runs periodically (default every 2 hours). Builds hierarchical knowledge:
195211
- **Level 2 — Principles**: Generalizations across patterns
196212
- **Level 3 — Axioms**: Fundamental truths with high confidence
197213

198-
Abstractions are grounded in evidence. Those that lose supporting evidence are demoted or archived.
214+
Abstractions are grounded in evidence via `verifyGrounding()`. Young abstractions (< 7 days) have a confidence floor of 0.5 to prevent premature demotion. Frequently accessed abstractions (> 5 recalls) resist decay. Demotion is graduated: 0.9x for moderate evidence loss, 0.7x for significant, 0.5x for near-total (softened from 0.3x).
199215

200216
### Layer 9 — Reactor (Event-Driven Rules)
201217

@@ -236,6 +252,7 @@ GET /abstractions Hierarchical abstractions
236252
GET /projects Project summaries
237253
238254
GET /llm/usage LLM token usage by agent
255+
GET /tool/usage MCP tool call analytics
239256
240257
GET /graph Association graph for D3.js visualization
241258
@@ -265,6 +282,7 @@ Served at `http://localhost:9999/`. Features:
265282
- Query tester with score explanations
266283
- System health (LLM status, store health, watcher status)
267284
- LLM usage monitoring (per-agent token consumption and cost)
285+
- MCP tool usage analytics (call frequency, latency, error rates)
268286
- Memory source tags (hoverable, showing origin: filesystem, terminal, clipboard, MCP, consolidation)
269287
- 5 themes: Midnight, Ember, Nord, Slate, Parchment (persists in localStorage)
270288
- Agent SDK dashboard: evolution state, principles, strategies, session timeline, chat
@@ -442,6 +460,47 @@ CREATE TABLE llm_usage (
442460
latency_ms INTEGER NOT NULL DEFAULT 0,
443461
success INTEGER NOT NULL DEFAULT 1
444462
);
463+
464+
-- MCP tool usage tracking
465+
CREATE TABLE tool_usage (
466+
id INTEGER PRIMARY KEY AUTOINCREMENT,
467+
timestamp TEXT NOT NULL,
468+
tool_name TEXT NOT NULL,
469+
session_id TEXT NOT NULL DEFAULT '',
470+
project TEXT NOT NULL DEFAULT '',
471+
latency_ms INTEGER NOT NULL DEFAULT 0,
472+
success INTEGER NOT NULL DEFAULT 1,
473+
error_message TEXT NOT NULL DEFAULT '',
474+
query_text TEXT NOT NULL DEFAULT '',
475+
result_count INTEGER NOT NULL DEFAULT 0,
476+
memory_type TEXT NOT NULL DEFAULT '',
477+
rating TEXT NOT NULL DEFAULT '',
478+
response_size INTEGER NOT NULL DEFAULT 0
479+
);
480+
481+
-- Memory amendment audit trail
482+
CREATE TABLE memory_amendments (
483+
id INTEGER PRIMARY KEY AUTOINCREMENT,
484+
memory_id TEXT NOT NULL,
485+
old_content TEXT NOT NULL,
486+
old_summary TEXT NOT NULL,
487+
new_content TEXT NOT NULL,
488+
new_summary TEXT NOT NULL,
489+
amended_at TEXT NOT NULL,
490+
source TEXT NOT NULL DEFAULT 'mcp'
491+
);
492+
493+
-- Runtime watcher exclusions (managed via MCP tools)
494+
CREATE TABLE runtime_exclusions (
495+
id INTEGER PRIMARY KEY AUTOINCREMENT,
496+
pattern TEXT NOT NULL UNIQUE,
497+
source TEXT NOT NULL DEFAULT 'mcp',
498+
created_at TEXT NOT NULL
499+
);
500+
501+
-- Additional columns on memories table (added via migrations):
502+
-- feedback_score INTEGER DEFAULT 0 — accumulated feedback (helpful=+1, irrelevant=-1)
503+
-- recall_suppressed INTEGER DEFAULT 0 — auto-suppressed when feedback_score <= -3
445504
```
446505

447506
---
@@ -493,7 +552,7 @@ mnemonic/
493552
│ │ ├── server.go # Static file serving (go:embed)
494553
│ │ └── static/index.html # Dashboard (D3.js graph, live feed, query tester)
495554
│ ├── ingest/ # Project ingestion engine
496-
│ ├── mcp/server.go # MCP server (13 tools for Claude Code)
555+
│ ├── mcp/server.go # MCP server (19 tools for Claude Code)
497556
│ ├── backup/ # Export/import logic
498557
│ ├── daemon/ # Service management (macOS LaunchAgent + Linux systemd)
499558
│ ├── config/config.go # Configuration loading
@@ -513,7 +572,7 @@ mnemonic/
513572

514573
## Build History
515574

516-
All original build phases are **complete**. Current focus is SDK features, dashboard polish, and recall quality.
575+
All original build phases are **complete**. Current focus is memory quality, retrieval intelligence, and training a bespoke local LLM (Mnemonic-LM).
517576

518577
### Completed
519578

@@ -531,12 +590,9 @@ All original build phases are **complete**. Current focus is SDK features, dashb
531590

532591
- **Multi-modal memory** (images, audio) — text-only for v1
533592
- **Cross-device sync** — single machine for v1
534-
- **User preference learning** — needs feedback data from v1
535593
- **Advanced consolidation** (hierarchical memory, schema learning)
536594
- **Database encryption** — air-gapped assumption covers v1
537-
- **Local model fine-tuning** — LM Studio handles v1
538595
- **Native macOS menu bar widget** — web dashboard covers v1, native UI later
539-
- ~~**MCP server integration**~~**Done.** 13 MCP tools implemented (`internal/mcp/server.go`)
540596

541597
---
542598

CLAUDE.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal/
3434
reactor/ Event-driven rule engine
3535
api/ REST API server + routes
3636
web/ Embedded dashboard (single-page app, D3.js charts)
37-
mcp/ MCP server (13 tools for Claude Code)
37+
mcp/ MCP server (19 tools for Claude Code)
3838
store/ Store interface + SQLite implementation
3939
llm/ LLM provider interface + implementations (LM Studio, Gemini/cloud API)
4040
ingest/ Project ingestion engine
@@ -107,23 +107,29 @@ See [GitHub Issues](https://github.com/appsprout-dev/mnemonic/issues) for tracke
107107

108108
## MCP Tools Available
109109

110-
You have 13 tools via the `mnemonic` MCP server:
110+
You have 19 tools via the `mnemonic` MCP server:
111111

112112
| Tool | When to Use |
113113
|------|-------------|
114-
| `remember` | Store decisions, errors, insights, learnings |
115-
| `recall` | Search for relevant memories before starting work |
114+
| `remember` | Store decisions, errors, insights, learnings (returns raw ID + salience) |
115+
| `recall` | Semantic search with spread activation (`explain`, `include_associations`, `format`, `synthesize` params) |
116116
| `forget` | Archive irrelevant memories |
117-
| `status` | Check memory system health and stats |
117+
| `amend` | Update a memory's content in place (preserves associations, history, salience) |
118+
| `check_memory` | Inspect a memory's encoding status, concepts, and associations |
119+
| `status` | System health, encoding pipeline status, source distribution |
118120
| `recall_project` | Get project-specific context and patterns |
119121
| `recall_timeline` | See what happened in a time range |
122+
| `recall_session` | Retrieve all memories from a specific MCP session |
123+
| `list_sessions` | List recent sessions with time range and memory count |
120124
| `session_summary` | Summarize current/recent session |
121125
| `get_patterns` | View discovered recurring patterns |
122126
| `get_insights` | View metacognition observations and abstractions |
123-
| `feedback` | Report recall quality (helps system learn) |
127+
| `feedback` | Report recall quality (drives ranking, can auto-suppress noisy memories) |
124128
| `audit_encodings` | Review recent encoding quality and suggest improvements |
125129
| `coach_local_llm` | Write coaching guidance to improve local LLM prompts |
126130
| `ingest_project` | Bulk-ingest a project directory into memory |
131+
| `exclude_path` | Add a watcher exclusion pattern at runtime |
132+
| `list_exclusions` | List all runtime watcher exclusion patterns |
127133

128134
### At Session Start
129135

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A local-first semantic memory daemon that watches your work, learns from it, and
1313
- **Autonomous** — Watches your filesystem, terminal, and clipboard. Encodes memories without you lifting a finger.
1414
- **Biological** — Memories consolidate, decay, form patterns, and become principles. It doesn't just store — it *processes*.
1515
- **Local-first** — Air-gapped, SQLite-backed, never phones home. Your data stays on your machine.
16-
- **13 MCP tools** — Drop-in memory layer for Claude Code and other AI agents.
16+
- **19 MCP tools** — Drop-in memory layer for Claude Code and other AI agents.
1717
- **Self-updating** — Built-in update mechanism checks GitHub Releases and applies updates in-place.
1818
- **Cross-platform** — macOS, Linux, and Windows. Daemon management via launchd, systemd, or Windows Services.
1919

@@ -42,7 +42,7 @@ Or [build from source](#development) (requires Go 1.23+).
4242
**Configure and run:**
4343

4444
```bash
45-
cp config.yaml ~/.mnemonic/config.yaml
45+
cp config.example.yaml ~/.mnemonic/config.yaml
4646
# Edit ~/.mnemonic/config.yaml — set llm.endpoint, llm.chat_model, llm.embedding_model
4747
# For local LLM: see docs/setup-lmstudio.md
4848
# For Gemini: set endpoint to Gemini API URL and export LLM_API_KEY
@@ -72,6 +72,7 @@ Open `http://127.0.0.1:9999` for the embedded web UI:
7272
- **Explore** — Browse episodes, memories, patterns, and abstractions
7373
- **Timeline** — Chronological view with date range filters and type/tag filtering
7474
- **LLM** — Per-agent token consumption, cost tracking, and usage charts
75+
- **Tools** — MCP tool usage analytics: call frequency, latency, error rates
7576
- **SDK** — Agent evolution dashboard: principles, strategies, session timeline, chat interface
7677
- **Activity drawer** — Slide-out panel with live event feed and metacognition insights
7778
- **Themes** — 5 dashboard themes: Midnight, Ember, Nord, Slate, Parchment
@@ -87,8 +88,8 @@ Mnemonic implements a cognitive pipeline inspired by neuroscience — 8 agents p
8788
1. **Perception** — Watch filesystem, terminal, clipboard, MCP events. Pre-filter with heuristics.
8889
2. **Encoding** — LLM-powered compression into memories. Extract concepts, generate embeddings, create association links.
8990
3. **Episoding** — Cluster memories into temporal episodes with LLM synthesis.
90-
4. **Consolidation** — Sleep cycle (every 6h). Decay salience, merge related memories, extract recurring patterns.
91-
5. **Retrieval** — Spread activation: embed query, find entry points (FTS + embedding), traverse association graph 3 hops, LLM synthesis with tool-use.
91+
4. **Consolidation** — Sleep cycle. Decay salience, merge related memories, extract patterns, archive never-recalled watcher noise.
92+
5. **Retrieval** — Spread activation: embed query, find entry points (FTS + embedding), traverse association graph 3 hops, rank by feedback history + source weight + pattern evidence, optional LLM synthesis.
9293
6. **Metacognition** — Self-reflection. Audit memory quality, analyze feedback, re-embed orphaned memories.
9394
7. **Dreaming** — Replay memories, strengthen associations, cross-pollinate across projects, generate insights.
9495
8. **Abstraction** — Build hierarchical knowledge: patterns (level 1) → principles (level 2) → axioms (level 3).
@@ -97,15 +98,15 @@ Mnemonic implements a cognitive pipeline inspired by neuroscience — 8 agents p
9798

9899
**Reactor** — Event-driven rule engine. Fires condition → action chains in response to system events.
99100

100-
**Feedback loop** — Helpful recalls strengthen associations and boost salience. Irrelevant results weaken them. The system learns from usage.
101+
**Feedback loop** — Helpful recalls strengthen associations, boost salience, and inform future ranking. Irrelevant results weaken associations and can auto-suppress noisy memories. Feedback scores directly influence retrieval ranking, and patterns discovered from your usage boost evidence memories.
101102

102103
All agents communicate via an event bus — none call each other directly.
103104

104105
For the full deep dive, see [ARCHITECTURE.md](ARCHITECTURE.md).
105106

106107
## MCP Integration
107108

108-
Mnemonic exposes 13 tools via the [Model Context Protocol](https://modelcontextprotocol.io/) for Claude Code and other AI agents:
109+
Mnemonic exposes 19 tools via the [Model Context Protocol](https://modelcontextprotocol.io/) for Claude Code and other AI agents:
109110

110111
**Claude Code config** (`~/.claude/settings.local.json`):
111112

@@ -124,19 +125,25 @@ Mnemonic exposes 13 tools via the [Model Context Protocol](https://modelcontextp
124125

125126
| Tool | Purpose |
126127
| ---- | ------- |
127-
| `remember` | Store decisions, errors, insights, learnings |
128-
| `recall` | Semantic search with spread activation |
128+
| `remember` | Store decisions, errors, insights, learnings (returns salience + encoding status) |
129+
| `recall` | Semantic search with spread activation, feedback-informed ranking, optional synthesis |
129130
| `forget` | Archive a memory |
130-
| `status` | System health and stats |
131+
| `amend` | Update a memory's content in place (preserves associations and history) |
132+
| `check_memory` | Inspect encoding status, concepts, associations for a specific memory |
133+
| `status` | System health, pipeline status, source distribution |
131134
| `recall_project` | Project-scoped context and patterns |
132135
| `recall_timeline` | Chronological retrieval within a time range |
136+
| `recall_session` | Retrieve all memories from a specific session |
137+
| `list_sessions` | List recent MCP sessions with metadata |
133138
| `session_summary` | Summarize current/recent session |
134139
| `get_patterns` | View discovered recurring patterns |
135140
| `get_insights` | View metacognition observations and abstractions |
136-
| `feedback` | Report recall quality (trains retrieval) |
141+
| `feedback` | Report recall quality (drives ranking, can auto-suppress noisy memories) |
137142
| `audit_encodings` | Review encoding quality |
138143
| `coach_local_llm` | Write coaching guidance for local LLM prompts |
139144
| `ingest_project` | Bulk-ingest a project directory |
145+
| `exclude_path` | Add a watcher exclusion pattern at runtime |
146+
| `list_exclusions` | List all runtime watcher exclusions |
140147

141148
See [CLAUDE.md](CLAUDE.md) for Claude Code usage guidelines.
142149

@@ -178,7 +185,7 @@ All settings live in `config.yaml`. Key sections:
178185
- **perception** — Watch directories, shell, clipboard; heuristic thresholds; project identity
179186
- **encoding** — Concept extraction, similarity search, contextual encoding
180187
- **consolidation** — Decay rate, salience thresholds, pattern extraction
181-
- **retrieval** — Spread activation hops, decay, synthesis tokens
188+
- **retrieval** — Spread activation hops, decay, synthesis tokens, source weights, feedback weight
182189
- **metacognition** — Reflection interval, feedback processing
183190
- **episoding** — Episode window, minimum events
184191
- **dreaming** — Replay interval, association boost, noise pruning
@@ -211,7 +218,7 @@ internal/
211218
agent/ 8 cognitive agents + orchestrator + reactor
212219
api/ HTTP + WebSocket server
213220
web/ Embedded dashboard (single-page app)
214-
mcp/ MCP server (13 tools)
221+
mcp/ MCP server (19 tools)
215222
store/ Store interface + SQLite (FTS5 + vector search)
216223
llm/ LLM provider interface (LM Studio, Gemini, cloud APIs)
217224
ingest/ Project ingestion engine

0 commit comments

Comments
 (0)