prism-mcp-server 3.1.1 โ†’ 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,11 +14,14 @@
14
14
 
15
15
  ## Table of Contents
16
16
 
17
- - [What's New (v3.1.0)](#whats-new-in-v310---memory-lifecycle-)
17
+ - [What's New (v4.2.0)](#whats-new-in-v420--project-repo-registry-)
18
+ - [Multi-Instance Support](#multi-instance-support)
18
19
  - [How Prism Compares](#how-prism-compares)
19
20
  - [Quick Start](#quick-start-zero-config--local-mode)
20
21
  - [Mind Palace Dashboard](#-the-mind-palace-dashboard)
21
22
  - [Integration Examples](#integration-examples)
23
+ - [Claude Code Integration (Hooks)](#claude-code-integration-hooks)
24
+ - [Gemini / Antigravity Integration](#gemini--antigravity-integration)
22
25
  - [Use Cases](#use-cases)
23
26
  - [Architecture](#architecture)
24
27
  - [Tool Reference](#tool-reference)
@@ -39,25 +42,60 @@
39
42
 
40
43
  ---
41
44
 
42
- ## What's New in v3.1.0 โ€” Memory Lifecycle ๐Ÿ”„
45
+ ## What's New in v4.2.0 โ€” Project Repo Registry ๐Ÿ—‚๏ธ
43
46
 
44
47
  | Feature | Description |
45
48
  |---|---|
46
- | ๐Ÿ“Š **Memory Analytics** | New **Memory Analytics** card in the dashboard โ€” 14-day sparkline chart, active sessions count, rollup savings, and average context richness. Powered by `getAnalytics()` on both SQLite and Supabase backends. |
47
- | โณ **Automated Data Retention (TTL)** | Set a per-project data retention policy via `knowledge_set_retention` MCP tool or the dashboard **Lifecycle Controls** card. Entries older than the TTL are soft-deleted (GDPR-compliant `archived_at` tombstone) every 12 hours automatically. Rollups are never expired. Minimum 7 days to prevent accidental mass-delete. |
48
- | ๐Ÿ—œ๏ธ **Smart Auto-Compaction** | After every `session_save_ledger`, Prism runs a background health check and triggers compaction automatically if the brain is degraded or unhealthy โ€” gated by `compaction_auto` setting and debounced per-project to prevent concurrent Gemini calls. **Compact Now** button also available in the dashboard. |
49
- | ๐Ÿ“ฆ **PKM Export (Obsidian / Logseq)** | Export any project's full memory as a ZIP archive of Markdown files โ€” one file per session with YAML-like frontmatter, TODOs, decisions, files-changed, and `#hashtag` keywords. Includes an `_index.md` with `[[wikilink]]` references. Click **Export ZIP** in the dashboard Lifecycle Controls card. |
50
- | ๐Ÿงช **Expanded Test Suite** | 37 new Vitest tests (95 total) โ€” covers analytics queries, TTL soft-delete idempotency, rollup preservation, `activeCompactions` Set memory-leak prevention, type guards, export Markdown structure, and TTL sweep scheduler contracts. |
49
+ | ๐Ÿ—‚๏ธ **Project Repo Paths** | Map each project to its repo directory in the dashboard. `session_save_ledger` validates `files_changed` paths and warns on mismatch โ€” prevents cross-project contamination. |
50
+ | ๐Ÿ”„ **Universal Auto-Load** | Auto-load projects via dynamic tool descriptions โ€” works across all MCP clients (Claude, Cursor, Gemini, Antigravity) without lifecycle hooks. Dashboard is the sole source of truth. |
51
+ | ๐Ÿ  **Dashboard-First Config** | Removed `PRISM_AUTOLOAD_PROJECTS` env var override. The Mind Palace dashboard is now the single source of truth for auto-load project configuration. |
52
+
53
+ <details>
54
+ <summary><strong>What's in v4.1.0 โ€” Auto-Migration & Multi-Instance ๐Ÿ”€</strong></summary>
55
+
56
+ | Feature | Description |
57
+ |---|---|
58
+ | ๐Ÿ”„ **Auto-Migrations (Supabase)** | Zero-config schema upgrades โ€” pending DDL migrations run automatically on server startup via `prism_apply_ddl` RPC. |
59
+ | ๐Ÿ”€ **Multi-Instance Support** | `PRISM_INSTANCE` env var enables instance-aware PID locks โ€” run multiple Prism servers side-by-side without conflicts. |
60
+ | ๐Ÿ›ก๏ธ **Server Lifecycle Management** | Singleton PID lock with graceful shutdown and stale PID recovery. |
61
+
62
+ </details>
63
+
64
+ <details>
65
+ <summary><strong>What's in v4.0.0 โ€” Behavioral Memory ๐Ÿง </strong></summary>
66
+
67
+ | Feature | Description |
68
+ |---|---|
69
+ | ๐Ÿง  **Behavioral Memory** | `session_save_experience` โ€” log actions, outcomes, corrections with confidence scores. Auto-injects warnings into context so agents learn from mistakes. |
70
+ | ๐ŸŽฏ **Dynamic Roles** | Role auto-resolves from dashboard settings. Set once in Mind Palace, applies everywhere. |
71
+ | ๐Ÿ“ **Token Budget** | `max_tokens` on `session_load_context` โ€” intelligently truncates to fit your budget. |
72
+ | ๐Ÿ“‰ **Importance Decay** | Stale corrections auto-fade over time to keep context fresh. |
73
+ | ๐Ÿ”ง **Claude Code Hooks** | Simplified SessionStart/Stop hooks that reliably trigger MCP tool calls. |
74
+
75
+ </details>
76
+
77
+ <details>
78
+ <summary><strong>What's in v3.1.0 โ€” Memory Lifecycle ๐Ÿ”„</strong></summary>
79
+
80
+ | Feature | Description |
81
+ |---|---|
82
+ | ๐Ÿ“Š **Memory Analytics** | Dashboard sparkline chart, session counts, rollup savings, context richness metrics. |
83
+ | โณ **Data Retention (TTL)** | Per-project TTL via `knowledge_set_retention` or dashboard. Auto-expires old entries every 12h. |
84
+ | ๐Ÿ—œ๏ธ **Auto-Compaction** | Background health check after saves โ€” auto-compacts when brain is degraded. |
85
+ | ๐Ÿ“ฆ **PKM Export** | Export project memory as ZIP of Markdown files for Obsidian/Logseq. |
86
+ | ๐Ÿงช **95 Tests** | Analytics, TTL, rollup, compaction, type guards, and export coverage. |
87
+
88
+ </details>
51
89
 
52
90
  <details>
53
91
  <summary><strong>What's in v3.0.1 โ€” Agent Identity & Brain Clean-up ๐Ÿงน</strong></summary>
54
92
 
55
93
  | Feature | Description |
56
94
  |---|---|
57
- | ๐Ÿงน **Brain Health Clean-up** | New **Fix Issues** button in the Mind Palace Dashboard's Brain Health card โ€” detects orphaned handoffs, missing embeddings, and stale rollups, then cleans them up in one click without needing the MCP tool. |
58
- | ๐Ÿ‘ค **Agent Identity Settings** | Dashboard Settings โ†’ Agent Identity panel lets you set a **Default Role** (`dev`, `qa`, `pm`โ€ฆ) and **Agent Name** (e.g. `Dmitri`). Both values auto-apply as fallbacks in all memory and Hivemind tools โ€” no need to pass them per call. |
59
- | ๐Ÿ“œ **Role-Scoped Skills** | Each agent role can have its own persistent skill/rules document stored in the dashboard (โš™๏ธ Settings โ†’ Skills). It is automatically injected into every `session_load_context` response so the agent boots with its rules pre-loaded. |
60
- | ๐Ÿ”ค **Resource Formatting Fix** | `memory://{project}/handoff` resources now render as formatted plain text (Last Summary, TODOs, Keywords) instead of a raw JSON blob โ€” readable in Claude Desktop's paperclip attach panel. |
95
+ | ๐Ÿงน **Brain Health Clean-up** | One-click **Fix Issues** button โ€” detects and cleans orphaned handoffs, missing embeddings, stale rollups. |
96
+ | ๐Ÿ‘ค **Agent Identity** | Set Default Role and Agent Name in dashboard โ€” auto-applies as fallback in all tools. |
97
+ | ๐Ÿ“œ **Role-Scoped Skills** | Per-role persistent rules documents, auto-injected at `session_load_context`. |
98
+ | ๐Ÿ”ค **Resource Formatting** | `memory://` resources render as formatted text instead of raw JSON. |
61
99
 
62
100
  </details>
63
101
 
@@ -66,13 +104,13 @@
66
104
 
67
105
  | Feature | Description |
68
106
  |---|---|
69
- | ๐Ÿ **Role-Scoped Memory** | Optional `role` parameter on ledger, handoff, and context loading โ€” each agent role (dev, qa, pm, lead, security, ux) gets its own isolated memory lane within a project. Defaults to `'global'` for full backward compatibility. |
70
- | ๐Ÿ‘ฅ **Agent Registry** | New `agent_register`, `agent_heartbeat`, `agent_list_team` tools โ€” agents announce their presence, pulse their status, and discover who else is working on the team. Stale agents are auto-pruned after 30 minutes. |
71
- | ๐ŸŽฏ **Team Roster Injection** | When loading context with a role, Prism automatically injects a "Team Roster" showing active teammates, their roles, current tasks, and last heartbeat โ€” true multi-agent awareness without extra tool calls. |
72
- | โš™๏ธ **Dashboard Settings** | New Settings modal with runtime toggles (auto-capture, theme, context depth) backed by a persistent `system_settings` key-value store. Environment variables override DB settings for safety. |
73
- | ๐Ÿ“ก **Hivemind Radar** | New dashboard widget showing active agents, their roles (with icons), current tasks, and heartbeat timestamps โ€” a real-time team coordination dashboard. |
74
- | ๐Ÿ”’ **Conditional Tool Registration** | `PRISM_ENABLE_HIVEMIND` env var gates Hivemind tools โ€” users who don't need multi-agent features keep the same lean tool count as v2.x. |
75
- | โœ… **Test Suite** | 58 tests across 4 suites (storage, tools, dashboard, load) with Vitest โ€” includes concurrent write stress tests, role isolation verification, and 0.2ms/write performance benchmarks. |
107
+ | ๐Ÿ **Role-Scoped Memory** | Optional `role` param โ€” each role gets isolated memory within a project. |
108
+ | ๐Ÿ‘ฅ **Agent Registry** | `agent_register`, `agent_heartbeat`, `agent_list_team` โ€” multi-agent discovery. |
109
+ | ๐ŸŽฏ **Team Roster** | Auto-injected teammate awareness during context loading. |
110
+ | โš™๏ธ **Dashboard Settings** | Runtime toggles backed by persistent key-value store. |
111
+ | ๐Ÿ“ก **Hivemind Radar** | Dashboard widget showing active agents, roles, and heartbeats. |
112
+ | ๐Ÿ”’ **Conditional Tools** | `PRISM_ENABLE_HIVEMIND` gates multi-agent tools. |
113
+ | โœ… **58 Tests** | Storage, tools, dashboard, concurrent writes, role isolation. |
76
114
 
77
115
  </details>
78
116
 
@@ -82,10 +120,10 @@
82
120
 
83
121
  | Feature | Description |
84
122
  |---|---|
85
- | ๐Ÿ” **Memory Tracing (Phase 1)** | Every search now returns a structured `MemoryTrace` with latency breakdown (`embedding_ms`, `storage_ms`, `total_ms`), search strategy, and scoring metadata โ€” surfaced as a separate `content[1]` block for LangSmith integration. |
86
- | ๐Ÿ›ก๏ธ **GDPR Memory Deletion (Phase 2)** | New `session_forget_memory` tool with soft-delete (tombstoning via `deleted_at`) and hard-delete. Ownership guards prevent cross-user deletion. `deleted_reason` column captures GDPR Article 17 justification. Top-K Hole solved by filtering inside SQL, not post-query (ensures we always return exactly K results, rather than returning fewer because deleted items were filtered out after the vector search). |
87
- | ๐Ÿ”— **LangChain Integration (Phase 3)** | `PrismMemoryRetriever` and `PrismKnowledgeRetriever` โ€” async-first `BaseRetriever` subclasses that wrap Prism MCP's traced search endpoints. Trace metadata flows automatically into `Document.metadata["trace"]` for LangSmith visibility. |
88
- | ๐Ÿงฉ **LangGraph Research Agent** | Full example in `examples/langgraph-agent/` โ€” a 5-node agentic research loop with MCP bridge, persistent memory, and `EnsembleRetriever` hybrid search. |
123
+ | ๐Ÿ” **Memory Tracing** | `MemoryTrace` with latency breakdown and scoring metadata for LangSmith. |
124
+ | ๐Ÿ›ก๏ธ **GDPR Deletion** | `session_forget_memory` with soft/hard delete and Article 17 justification. |
125
+ | ๐Ÿ”— **LangChain Integration** | `PrismMemoryRetriever` / `PrismKnowledgeRetriever` BaseRetriever adapters. |
126
+ | ๐Ÿงฉ **LangGraph Agent** | 5-node research agent example with MCP bridge and hybrid search. |
89
127
 
90
128
  </details>
91
129
 
@@ -94,8 +132,8 @@
94
132
 
95
133
  | Feature | Description |
96
134
  |---|---|
97
- | ๐Ÿ”„ **Dynamic Versioning** | Server version is now derived from `package.json` at startup โ€” MCP handshake, dashboard badge, and npm metadata always stay in sync. Falls back to `0.0.0` if unreadable. |
98
- | ๐Ÿ›ก๏ธ **Embedding Dimension Validation** | `generateEmbedding()` now validates the returned vector is exactly 768 dimensions at runtime, catching model regressions before storing bad vectors. Removed `as any` cast in favor of proper `EmbedContentRequest` typing. |
135
+ | ๐Ÿ”„ **Dynamic Versioning** | Version derived from `package.json` โ€” MCP handshake, dashboard, and npm stay in sync. |
136
+ | ๐Ÿ›ก๏ธ **Embedding Validation** | Validates 768-dimension vectors at runtime to catch model regressions. |
99
137
 
100
138
  </details>
101
139
 
@@ -115,11 +153,11 @@
115
153
 
116
154
  | Feature | Description |
117
155
  |---|---|
118
- | ๐Ÿค– **LangGraph Research Agent** | New `examples/langgraph-agent/` โ€” a 5-node agentic research agent (planโ†’searchโ†’analyzeโ†’decideโ†’answerโ†’save) with autonomous looping, MCP integration, and persistent memory. |
119
- | ๐Ÿง  **Agentic Memory** | `save_session` node persists research findings to a ledger โ€” the agent doesn't just answer and forget. Routes to Prism's `session_save_ledger` in MCP-connected mode. |
120
- | ๐Ÿ”Œ **MCP Client Bridge** | Raw JSON-RPC 2.0 client (`mcp_client.py`) for Python 3.9+ โ€” dynamically discovers and wraps Prism MCP tools as LangChain `StructuredTool` objects. |
121
- | ๐Ÿ”ง **Storage Abstraction Fix** | Resource/Prompt handlers now route through `getStorage()` instead of calling Supabase directly โ€” eliminates EOF crashes when reading `memory://` resources. |
122
- | ๐Ÿ›ก๏ธ **Error Boundaries** | Resource handlers catch errors gracefully and return proper MCP error responses (`isError: true`) instead of crashing the server process. |
156
+ | ๐Ÿค– **LangGraph Agent** | 5-node research agent with autonomous looping, MCP integration, persistent memory. |
157
+ | ๐Ÿง  **Agentic Memory** | `save_session` node persists findings to ledger โ€” agents don't just answer and forget. |
158
+ | ๐Ÿ”Œ **MCP Client Bridge** | JSON-RPC 2.0 client wraps Prism tools as LangChain `StructuredTool` objects. |
159
+ | ๐Ÿ”ง **Storage Fix** | Resource/Prompt handlers route through `getStorage()` โ€” eliminates EOF crashes. |
160
+ | ๐Ÿ›ก๏ธ **Error Boundaries** | Graceful error handling with proper MCP error responses. |
123
161
 
124
162
  </details>
125
163
 
@@ -157,25 +195,29 @@
157
195
 
158
196
  | Feature | **Prism MCP** | [MCP Memory](https://github.com/modelcontextprotocol/servers/tree/main/src/memory) | [Mem0](https://github.com/mem0ai/mem0) | [Mnemory](https://github.com/fpytloun/mnemory) | [Basic Memory](https://github.com/basicmachines-co/basic-memory) |
159
197
  |---|---|---|---|---|---|
160
- | **Pricing** | โœ… Free & open source (MIT) | โœ… Free & open source (MIT) | Freemium (free 10K memories; paid Pro) | โœ… Free & open source | Freemium (OSS core free; paid Pro) |
161
- | **Storage** | SQLite (local) + Supabase (cloud) | JSON file | Postgres + Qdrant (hosted or self-hosted) | Qdrant + S3/MinIO | Markdown files |
162
- | **Zero Config** | โœ… `npx -y prism-mcp-server` | โœ… | โŒ Requires Qdrant/Postgres | โœ… `uvx mnemory` | โœ… `pip install basic-memory` |
163
- | **Semantic Search** | โœ… F32_BLOB vectors + FTS5 | โŒ | โœ… pgvector | โœ… Qdrant vectors | โŒ Text search only |
164
- | **Knowledge Graph** | โœ… Neural Graph (Vis.js dashboard) | โœ… Entity/Relation model | โŒ | โœ… Relationship graph | โœ… Markdown links |
165
- | **Time Travel** | โœ… `memory_history` / `memory_checkout` | โŒ | โŒ | โŒ | โŒ |
166
- | **Fact Merging** | โœ… Async Gemini (fire-and-forget) | โŒ | โœ… Built-in | โœ… Contradiction resolution | โŒ |
167
- | **Security Scan** | โœ… Prompt injection detection | โŒ | โŒ | โœ… Anti-injection in fsck | โŒ |
168
- | **Health Check** | โœ… `session_health_check` (fsck) | โŒ | โŒ | โœ… 3-phase fsck | โŒ |
169
- | **Visual Dashboard** | โœ… Mind Palace (localhost:3000) | โŒ | โœ… Cloud dashboard | โœ… Management UI | โŒ |
170
- | **Multi-Agent Sync** | โœ… Real-time cross-client | โŒ | โŒ | โŒ Per-user isolation | โŒ |
171
- | **Visual Memory** | โœ… Screenshot vault + auto-capture | โŒ | โŒ | โœ… Artifact store | โŒ |
198
+ | **Pricing** | โœ… Free / MIT | โœ… Free / MIT | Freemium | โœ… Free / OSS | Freemium |
199
+ | **Storage** | SQLite + Supabase | JSON file | Postgres + Qdrant | Qdrant + S3 | Markdown files |
200
+ | **Zero Config** | โœ… npx one-liner | โœ… | โŒ Qdrant/Postgres | โœ… uvx | โœ… pip |
201
+ | **Behavioral Memory** | โœ… Importance tracking | โŒ | โŒ | โŒ | โŒ |
202
+ | **Dynamic Roles** | โœ… Dashboard auto-resolve | โŒ | โŒ | โŒ | โŒ |
203
+ | **Token Budget** | โœ… max_tokens param | โŒ | โŒ | โŒ | โŒ |
204
+ | **Importance Decay** | โœ… Auto-fade stale data | โŒ | โŒ | โŒ | โŒ |
205
+ | **Semantic Search** | โœ… Vectors + FTS5 | โŒ | โœ… pgvector | โœ… Qdrant | โŒ Text only |
206
+ | **Knowledge Graph** | โœ… Neural Graph | โœ… Entity model | โŒ | โœ… Graph | โœ… MD links |
207
+ | **Time Travel** | โœ… History + checkout | โŒ | โŒ | โŒ | โŒ |
208
+ | **Fact Merging** | โœ… Gemini async | โŒ | โœ… Built-in | โœ… Contradiction | โŒ |
209
+ | **Security Scan** | โœ… Injection detection | โŒ | โŒ | โœ… Anti-injection | โŒ |
210
+ | **Health Check** | โœ… fsck tool | โŒ | โŒ | โœ… 3-phase fsck | โŒ |
211
+ | **Visual Dashboard** | โœ… Mind Palace | โŒ | โœ… Cloud UI | โœ… Mgmt UI | โŒ |
212
+ | **Multi-Agent Sync** | โœ… Real-time | โŒ | โŒ | โŒ Per-user | โŒ |
213
+ | **Visual Memory** | โœ… Screenshot vault | โŒ | โŒ | โœ… Artifacts | โŒ |
172
214
  | **Auto-Compaction** | โœ… Gemini rollups | โŒ | โŒ | โŒ | โŒ |
173
215
  | **Morning Briefing** | โœ… Gemini synthesis | โŒ | โŒ | โŒ | โŒ |
174
216
  | **OCC (Concurrency)** | โœ… Version-based | โŒ | โŒ | โŒ | โŒ |
175
- | **GDPR Compliance** | โœ… Soft/hard delete + audit trail | โŒ | โŒ | โŒ | โŒ |
176
- | **Memory Tracing** | โœ… MemoryTrace with latency breakdown | โŒ | โŒ | โŒ | โŒ |
177
- | **LangChain Native** | โœ… BaseRetriever adapters | โŒ | โŒ | โŒ | โŒ |
178
- | **MCP Native** | โœ… stdio (Claude Desktop, Cursor) | โœ… stdio | โŒ Python SDK / REST | โœ… HTTP + MCP | โœ… stdio |
217
+ | **GDPR Compliance** | โœ… Soft/hard delete | โŒ | โŒ | โŒ | โŒ |
218
+ | **Memory Tracing** | โœ… Latency breakdown | โŒ | โŒ | โŒ | โŒ |
219
+ | **LangChain** | โœ… BaseRetriever | โŒ | โŒ | โŒ | โŒ |
220
+ | **MCP Native** | โœ… stdio | โœ… stdio | โŒ Python SDK | โœ… HTTP + MCP | โœ… stdio |
179
221
  | **Language** | TypeScript | TypeScript | Python | Python | Python |
180
222
 
181
223
  > **When to choose Prism MCP:** You want MCP-native memory with zero infrastructure overhead, progressive context loading, and enterprise features (OCC, compaction, time travel, security scanning) that work directly in Claude Desktop โ€” without running Qdrant, Postgres, or cloud services.
@@ -265,6 +307,7 @@ Open **`http://localhost:3000`** in your browser to see exactly what your AI age
265
307
 
266
308
  - **Current State & TODOs** โ€” See the exact context injected into the LLM's prompt
267
309
  - **Agent Identity Chip** โ€” Header shows your active role + name (e.g. `๐Ÿ› ๏ธ dev ยท Antigravity`); click to open Settings
310
+ - **Project Repo Paths** โ€” Map each project to its repo directory for save validation
268
311
  - **Brain Health ๐Ÿฉบ** โ€” Memory integrity status at a glance; **๐Ÿงน Fix Issues** button auto-cleans orphaned handoffs in one click
269
312
  - **Git Drift Detection** โ€” Alerts you if you've modified code outside the agent's view
270
313
  - **Morning Briefing** โ€” AI-synthesized action plan from your last sessions
@@ -363,36 +406,124 @@ Add to your Continue `config.json` or Cline MCP settings:
363
406
 
364
407
  ---
365
408
 
366
- ## Claude Code + Gemini Startup Compatibility
409
+ ## Claude Code Integration (Hooks)
367
410
 
368
- If you want consistent behavior across clients, treat startup in two phases:
411
+ Claude Code supports **lifecycle hooks** in `~/.claude/settings.json` that fire automatically at session start and end. Use these to auto-hydrate and persist Prism memory without manual prompting.
369
412
 
370
- 1. **Server availability**: ensure `prism-mcp` is enabled in MCP config so tools are available.
371
- 2. **Context hydration**: explicitly call `session_load_context` at session start.
413
+ ### SessionStart Hook
372
414
 
373
- Recommended startup call:
415
+ Automatically loads context when a new session begins:
374
416
 
375
417
  ```json
376
418
  {
377
- "projectName": "<your-project>",
378
- "level": "standard"
419
+ "hooks": {
420
+ "SessionStart": [
421
+ {
422
+ "matcher": "*",
423
+ "hooks": [
424
+ {
425
+ "type": "command",
426
+ "command": "python3 -c \"import json; print(json.dumps({'continue': True, 'suppressOutput': False, 'systemMessage': 'You MUST call mcp__prism-mcp__session_load_context twice before responding to the user: first with project=my-project level=standard, then with project=my-other-project level=standard. Do not skip this.'}))\"",
427
+ "timeout": 10
428
+ }
429
+ ]
430
+ }
431
+ ]
432
+ }
379
433
  }
380
434
  ```
381
435
 
382
- Important distinction:
436
+ ### Stop Hook
437
+
438
+ Automatically saves session memory when a session ends:
439
+
440
+ ```json
441
+ {
442
+ "hooks": {
443
+ "Stop": [
444
+ {
445
+ "matcher": "*",
446
+ "hooks": [
447
+ {
448
+ "type": "command",
449
+ "command": "python3 -c \"import json; print(json.dumps({'continue': True, 'suppressOutput': False, 'systemMessage': 'MANDATORY END WORKFLOW: 1) Call mcp__prism-mcp__session_save_ledger with project and summary. 2) Call mcp__prism-mcp__session_save_handoff with expected_version set to the loaded version.'}))\"",
450
+ "timeout": 10
451
+ }
452
+ ]
453
+ }
454
+ ]
455
+ }
456
+ }
457
+ ```
458
+
459
+ ### How the Hooks Work
460
+
461
+ The hook `command` runs a Python one-liner that returns a JSON object to Claude Code:
462
+
463
+ | Field | Purpose |
464
+ |---|---|
465
+ | `continue: true` | Tell Claude Code to proceed (don't abort the session) |
466
+ | `suppressOutput: false` | Show the hook result to the agent |
467
+ | `systemMessage` | Instruction injected as a system message โ€” the agent follows it |
468
+
469
+ The agent receives the `systemMessage` as an instruction and executes the tool calls. The server resolves the agent's **role** and **name** automatically from the dashboard โ€” no need to specify them in the hook.
470
+
471
+ ### Role Resolution โ€” No Hardcoding Needed
472
+
473
+ Prism resolves the agent role dynamically using a priority chain:
474
+
475
+ ```
476
+ explicit tool argument โ†’ dashboard setting โ†’ "global" (default)
477
+ ```
478
+
479
+ 1. **Explicit arg wins** โ€” if `role` is passed in the tool call, it's used directly.
480
+ 2. **Dashboard fallback** โ€” if `role` is omitted, the server calls `getSetting("default_role")` and uses whatever role you configured in the **Mind Palace Dashboard โš™๏ธ Settings โ†’ Agent Identity**.
481
+ 3. **Final default** โ€” if no dashboard setting exists, falls back to `"global"`.
482
+
483
+ Change your role once in the dashboard, and it automatically applies to every session โ€” CLI, extension, and all MCP clients.
484
+
485
+ ### Verification
486
+
487
+ If hydration ran successfully, the agent's output will include:
488
+ - A `[๐Ÿ‘ค AGENT IDENTITY]` block showing your dashboard-configured role and name
489
+ - `PRISM_CONTEXT_LOADED` marker text
490
+
491
+ If the marker is missing, the hook did not fire or the MCP server is not connected.
492
+
493
+ ---
494
+
495
+ ## Gemini / Antigravity Integration
496
+
497
+ Gemini-based clients (like Antigravity) use `GEMINI.md` global rules or user rules for startup behavior. The server resolves the role from the dashboard automatically.
498
+
499
+ ### Global Rules (`~/.gemini/GEMINI.md`)
500
+
501
+ ```markdown
502
+ ## Prism MCP Memory Auto-Load (CRITICAL)
503
+ At the start of every new session, call `mcp__prism-mcp__session_load_context`
504
+ for these projects:
505
+ - `my-project` (level=standard)
506
+ - `my-other-project` (level=standard)
507
+
508
+ After both succeed, print PRISM_CONTEXT_LOADED.
509
+ ```
510
+
511
+ ### User Rules (Antigravity Settings)
383
512
 
384
- - Auto-loading `prism-mcp` makes the server available.
385
- - It does **not** guarantee memory context is auto-hydrated unless your client runtime/hook invokes `session_load_context`.
513
+ If your Gemini client supports user rules, add the same instructions there. The key points:
386
514
 
387
- Client notes:
515
+ 1. **Call `session_load_context` as a tool** โ€” not `read_resource`. Only the tool returns the `[๐Ÿ‘ค AGENT IDENTITY]` block.
516
+ 2. **Verify** โ€” confirm the response includes `version` and `last_summary`.
388
517
 
389
- - **Gemini runtimes** may support native startup execution depending on configuration.
390
- - **Claude Code** should use a local `SessionStart` hook in `~/.claude/settings.json` for deterministic startup context loading.
518
+ ### Session End
391
519
 
392
- Verification pattern (same for both clients):
520
+ At the end of each session, save state:
393
521
 
394
- - Print a startup marker after successful `session_load_context` (for example, `PRISM_CONTEXT_LOADED`).
395
- - If the marker is missing, startup hydration did not run.
522
+ ```markdown
523
+ ## Session End Protocol
524
+ 1) Call `mcp__prism-mcp__session_save_ledger` with project and summary.
525
+ 2) Call `mcp__prism-mcp__session_save_handoff` with expected_version from the loaded version.
526
+ ```
396
527
 
397
528
  ---
398
529
 
@@ -518,6 +649,47 @@ The tool and dashboard button both call the same repair logic โ€” the dashboard
518
649
  | `session_search_memory` | Semantic search with `enable_trace` | `query`, `enable_trace` | Results + `MemoryTrace` in `content[1]` |
519
650
  | `knowledge_search` | Knowledge search with `enable_trace` | `query`, `enable_trace` | Results + `MemoryTrace` in `content[1]` |
520
651
 
652
+ ### v4.0 Behavioral Memory Tools
653
+
654
+ | Tool | Purpose | Key Args |
655
+ |------|---------|----------|
656
+ | `session_save_experience` | Record behavioral events with importance tracking | `project`, `event_type`, `context`, `action`, `outcome` |
657
+
658
+ **Dynamic Roles (v4.0):** `role` is now *optional* on all tools. Set your **Default Role** once in the dashboard (โš™๏ธ Settings โ†’ Agent Identity) and it auto-applies everywhere โ€” no need to pass it per call.
659
+
660
+ **Token Budget (v4.0):** Set a default in the dashboard (โš™๏ธ Settings โ†’ Token Budget) or pass `max_tokens` per call to override:
661
+
662
+ ```json
663
+ { "name": "session_load_context", "arguments": {
664
+ "project": "my-app", "level": "standard", "max_tokens": 2000
665
+ }}
666
+ ```
667
+
668
+ > ๐Ÿ’ก Set Token Budget to `0` in the dashboard for unlimited (default). Per-call `max_tokens` always takes priority.
669
+
670
+ **Recording experiences:**
671
+
672
+ ```json
673
+ { "name": "session_save_experience", "arguments": {
674
+ "project": "my-app",
675
+ "event_type": "correction",
676
+ "context": "User asked to add a database migration",
677
+ "action": "Ran ALTER TABLE directly in production",
678
+ "outcome": "Data was corrupted",
679
+ "correction": "Always create a migration file and test in staging first",
680
+ "confidence_score": 95
681
+ }}
682
+ ```
683
+
684
+ **Event types:** `correction` (user corrected the agent), `success` (task went well), `failure` (task failed), `learning` (new knowledge acquired).
685
+
686
+ **How behavioral memory works:**
687
+ 1. Agent records experiences via `session_save_experience`
688
+ 2. Prism assigns an **importance score** based on event type + confidence
689
+ 3. Stale entries **auto-decay** in importance over time
690
+ 4. On `session_load_context`, high-importance corrections auto-surface as `[โš ๏ธ BEHAVIORAL WARNINGS]`
691
+ 5. Agent sees warnings and avoids repeating past mistakes
692
+
521
693
  ### Code Mode Templates (v2.1)
522
694
 
523
695
  Instead of writing custom JavaScript, pass a `template` name for instant extraction:
@@ -695,6 +867,7 @@ The retrievers use `_aget_relevant_documents` as the primary path with `asyncio.
695
867
  | `BRAVE_API_KEY` | No | Brave Search Pro API key (enables web/local search tools) |
696
868
  | `PRISM_STORAGE` | No | `"local"` (default) or `"supabase"` โ€” **requires restart** |
697
869
  | `PRISM_ENABLE_HIVEMIND` | No | Set `"true"` to enable multi-agent Hivemind tools โ€” **requires restart** |
870
+ | `PRISM_INSTANCE` | No | Instance name for PID lock isolation (e.g. `"athena"`, `"prism-dev"`). Enables [multi-instance support](#multi-instance-support). Default: `"default"` |
698
871
  | `GOOGLE_API_KEY` | No | Google AI / Gemini โ€” enables paper analysis, Morning Briefings, compaction |
699
872
  | `BRAVE_ANSWERS_API_KEY` | No | Separate Brave Answers key for AI-grounded answers |
700
873
  | `SUPABASE_URL` | If cloud mode | Supabase project URL |
@@ -761,50 +934,28 @@ The agent boots up knowing exactly what to do โ€” zero prompting needed.
761
934
 
762
935
  ### Auto-Load on Session Start (Recommended)
763
936
 
764
- For the best experience, configure your AI coding assistant to **automatically call `session_load_context`** at the start of every new session. This ensures your agent always boots with full project memory โ€” no manual prompting needed.
937
+ For the best experience, ensure your agent boots with full project memory on every new session. There are three approaches โ€” use whichever fits your workflow:
765
938
 
766
- <details>
767
- <summary><strong>Claude Code (.clauderules / CLAUDE.md)</strong></summary>
768
-
769
- Add this rule to your project's `.clauderules` or `CLAUDE.md`:
770
-
771
- ```markdown
939
+ #### Option A: Dashboard Setting (Easiest)
772
940
 
773
- ## Prism MCP Memory Auto-Load (CRITICAL)
774
- At the start of every new session, you MUST call `session_load_context`
775
- at the `standard` level for these projects:
776
- - `my-project`
777
- - `my-other-project`
941
+ Open the **Mind Palace Dashboard** (โš™๏ธ Settings) and type your project names into the **Auto-Load Projects** field under Boot Settings:
778
942
 
779
- Do NOT skip this step.
943
+ ```
944
+ prism-mcp, my-app
780
945
  ```
781
946
 
782
- </details>
783
-
784
- <details>
785
- <summary><strong>Gemini / Antigravity (GEMINI.md)</strong></summary>
786
-
787
- Add this rule to your `~/.gemini/GEMINI.md` global rules file:
947
+ That's it. Restart your AI client and Prism auto-pushes context for each listed project on next boot.
788
948
 
789
- ```markdown
949
+ #### Option B: Client-Side Hooks / Rules
790
950
 
791
- ## Prism MCP Memory Auto-Load (CRITICAL)
951
+ For clients that support lifecycle hooks or startup rules, instruct the AI to **call `session_load_context` as a tool** at session start:
792
952
 
793
- **At the start of every new session**, immediately after displaying
794
- the startup block, you MUST call `session_load_context` (via the
795
- `prism-mcp` MCP server) at the `standard` level for these projects:
796
- - `my-project`
797
- - `my-other-project`
953
+ - **[Claude Code Integration (Hooks)](#claude-code-integration-hooks)** โ€” `SessionStart` and `Stop` hook JSON samples for `~/.claude/settings.json`
954
+ - **[Gemini / Antigravity Integration](#gemini--antigravity-integration)** โ€” global rules for `~/.gemini/GEMINI.md` or user rules
798
955
 
799
- This ensures accumulated project memory, pending TODOs, and key context
800
- from previous sessions are always available. Do NOT skip this step.
956
+ > **You can use both approaches together.** The dashboard auto-load (A) injects project names into the `session_load_context` tool description โ€” works universally across all MCP clients. Client-side hooks (B) give the AI full structured access to the context response (including version numbers for OCC).
801
957
 
802
- **IMPORTANT:** The `prism-mcp` MCP server is always available.
803
- Do NOT display any warnings or notes about MCP server availability
804
- โ€” just call the tools directly. Never claim the server is unavailable.
805
- ```
806
-
807
- </details>
958
+ > **Key principle:** Never hardcode a `role` in your hooks or rules. Set your role once in the **Mind Palace Dashboard โš™๏ธ Settings โ†’ Agent Identity**, and Prism automatically resolves it for every tool call across all clients. See [Role Resolution](#role-resolution--no-hardcoding-needed).
808
959
 
809
960
  > **Tip:** Replace `my-project` with your actual project identifiers. You can list as many projects as you need โ€” each one gets its own independent memory timeline.
810
961
 
@@ -1017,9 +1168,12 @@ Traces are returned as `content[1]` in MCP responses โ€” a separate content bloc
1017
1168
 
1018
1169
  ### 2. Apply Migrations
1019
1170
 
1020
- In the SQL Editor, run:
1171
+ In the SQL Editor, run the **bootstrap migration** first:
1021
1172
  1. [`supabase/migrations/015_session_memory.sql`](supabase/migrations/015_session_memory.sql)
1022
1173
  2. [`supabase/migrations/016_knowledge_accumulation.sql`](supabase/migrations/016_knowledge_accumulation.sql)
1174
+ 3. [`supabase/migrations/027_auto_migration_infra.sql`](supabase/migrations/027_auto_migration_infra.sql) โ€” **enables auto-migrations** (see below)
1175
+
1176
+ > **After applying migration 027**, all future schema changes are applied automatically on server startup โ€” no manual SQL required.
1023
1177
 
1024
1178
  ### 3. Get Credentials
1025
1179
 
@@ -1047,6 +1201,70 @@ export PRISM_STORAGE="supabase"
1047
1201
 
1048
1202
  </details>
1049
1203
 
1204
+ ### Auto-Migrations (Supabase Cloud)
1205
+
1206
+ Prism includes a zero-config auto-migration system for Supabase. Once the bootstrap migration (`027_auto_migration_infra.sql`) is applied, all future schema changes are applied automatically on server startup.
1207
+
1208
+ **How it works:**
1209
+
1210
+ 1. On startup, the migration runner checks each entry in `MIGRATIONS[]` (defined in `supabaseMigrations.ts`)
1211
+ 2. For each migration, it calls `prism_apply_ddl(version, name, sql)` โ€” a `SECURITY DEFINER` RPC function
1212
+ 3. The function checks `prism_schema_versions` โ€” if the version is already recorded, it's silently skipped (idempotent)
1213
+ 4. If not applied, it executes the DDL and records the version number
1214
+
1215
+ **Graceful degradation:** If `prism_apply_ddl()` doesn't exist (you haven't applied migration 027 yet), the runner logs a warning and continues โ€” the server still starts, but newer schema features may not be available.
1216
+
1217
+ **Adding new migrations** โ€” just append to the `MIGRATIONS[]` array in `src/storage/supabaseMigrations.ts`:
1218
+
1219
+ ```typescript
1220
+ {
1221
+ version: 28,
1222
+ name: "my_new_feature",
1223
+ sql: `ALTER TABLE session_ledger ADD COLUMN IF NOT EXISTS my_col TEXT;`,
1224
+ }
1225
+ ```
1226
+
1227
+ All SQL must be idempotent (`IF NOT EXISTS` / `IF EXISTS` guards).
1228
+
1229
+ ---
1230
+
1231
+ ## Multi-Instance Support
1232
+
1233
+ Run multiple Prism MCP servers side-by-side on the same machine without PID lock conflicts. This is useful when you have different MCP configurations (e.g., one for web search + memory, another for memory-only) running in different clients simultaneously.
1234
+
1235
+ ### Configuration
1236
+
1237
+ Set `PRISM_INSTANCE` to a unique name per server instance:
1238
+
1239
+ ```json
1240
+ {
1241
+ "mcpServers": {
1242
+ "prism-search": {
1243
+ "command": "node",
1244
+ "args": ["/path/to/prism/dist/server.js"],
1245
+ "env": {
1246
+ "PRISM_INSTANCE": "prism-search",
1247
+ "BRAVE_API_KEY": "your-key"
1248
+ }
1249
+ },
1250
+ "prism-memory": {
1251
+ "command": "node",
1252
+ "args": ["/path/to/prism/dist/server.js"],
1253
+ "env": {
1254
+ "PRISM_INSTANCE": "prism-memory"
1255
+ }
1256
+ }
1257
+ }
1258
+ }
1259
+ ```
1260
+
1261
+ ### How it works
1262
+
1263
+ - Each instance gets its own PID file: `/tmp/prism-{PRISM_INSTANCE}.pid`
1264
+ - Default instance name is `"default"` (backward compatible)
1265
+ - Instances share the same SQLite database and Supabase backend โ€” only the process lock is isolated
1266
+ - Graceful shutdown cleans up the instance's PID file
1267
+
1050
1268
  ---
1051
1269
 
1052
1270
  ## Hybrid Search Pipeline (Brave + Vertex AI)
@@ -1073,12 +1291,13 @@ See [`vertex-ai/`](vertex-ai/) for setup and benchmarks.
1073
1291
 
1074
1292
  ```
1075
1293
  โ”œโ”€โ”€ src/
1076
- โ”‚ โ”œโ”€โ”€ server.ts # MCP server core + tool routing
1294
+ โ”‚ โ”œโ”€โ”€ server.ts # MCP server core + tool routing + lifecycle
1077
1295
  โ”‚ โ”œโ”€โ”€ config.ts # Environment management
1078
1296
  โ”‚ โ”œโ”€โ”€ storage/
1079
1297
  โ”‚ โ”‚ โ”œโ”€โ”€ interface.ts # StorageBackend abstraction (+ GDPR delete methods)
1080
1298
  โ”‚ โ”‚ โ”œโ”€โ”€ sqlite.ts # SQLite local storage (libSQL + F32_BLOB + deleted_at migration)
1081
1299
  โ”‚ โ”‚ โ”œโ”€โ”€ supabase.ts # Supabase cloud storage (+ soft/hard delete)
1300
+ โ”‚ โ”‚ โ”œโ”€โ”€ supabaseMigrations.ts # Auto-migration runner for Supabase DDL
1082
1301
  โ”‚ โ”‚ โ”œโ”€โ”€ configStorage.ts # Boot config micro-DB (~/.prism-mcp/prism-config.db)
1083
1302
  โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Backend factory (auto-selects based on PRISM_STORAGE)
1084
1303
  โ”‚ โ”œโ”€โ”€ sync/
@@ -1116,7 +1335,8 @@ See [`vertex-ai/`](vertex-ai/) for setup and benchmarks.
1116
1335
  โ”‚ โ”œโ”€โ”€ prism_retriever.py # PrismMemoryRetriever + PrismKnowledgeRetriever
1117
1336
  โ”‚ โ”œโ”€โ”€ tools.py # Agent tools + GDPR forget_memory
1118
1337
  โ”‚ โ””โ”€โ”€ demo_retriever.py # Standalone retriever demo
1119
- โ”œโ”€โ”€ supabase/migrations/ # Cloud mode SQL schemas
1338
+ โ”œโ”€โ”€ supabase/migrations/ # Cloud mode SQL schemas + auto-migration bootstrap
1339
+ โ”‚ โ””โ”€โ”€ 027_auto_migration_infra.sql # prism_apply_ddl() RPC + schema version tracking
1120
1340
  โ”œโ”€โ”€ vertex-ai/ # Vertex AI hybrid search pipeline
1121
1341
  โ”œโ”€โ”€ index.ts # Server entry point
1122
1342
  โ””โ”€โ”€ package.json
@@ -1128,28 +1348,41 @@ See [`vertex-ai/`](vertex-ai/) for setup and benchmarks.
1128
1348
 
1129
1349
  > **[View the full project board โ†’](https://github.com/users/dcostenco/projects/1/views/1)**
1130
1350
 
1131
- ### โœ… v3.0.1 โ€” Agent Identity & Brain Clean-up (Shipped!)
1351
+ ### โœ… v4.2 โ€” Project Repo Registry (Shipped!)
1352
+
1353
+ | Feature | Description |
1354
+ |---|---|
1355
+ | ๐Ÿ—‚๏ธ **Project Repo Paths** | Dashboard UI to map projects to repo directories + `session_save_ledger` path validation. |
1356
+ | ๐Ÿ”„ **Universal Auto-Load** | Dynamic tool descriptions replace env var โ€” dashboard is sole source of truth. |
1357
+ | ๐Ÿ  **Dashboard-First Config** | Removed `PRISM_AUTOLOAD_PROJECTS` env var override. |
1358
+
1359
+ ### โœ… v4.1 โ€” Auto-Migration & Multi-Instance (Shipped!)
1360
+
1361
+ See [What's in v4.1.0](#whats-in-v410--auto-migration--multi-instance-) above.
1362
+
1363
+ ### โœ… v4.0 โ€” Behavioral Memory (Shipped!)
1364
+
1365
+ See [What's in v4.0.0](#whats-in-v400--behavioral-memory-) above.
1366
+
1367
+ ### โœ… v3.1 โ€” Memory Lifecycle (Shipped!)
1132
1368
 
1133
- See [What's New in v3.0.1](#whats-new-in-v301---agent-identity--brain-clean-up-) above.
1369
+ See [What's in v3.1.0](#whats-in-v310--memory-lifecycle-) above.
1134
1370
 
1135
1371
  ### โœ… v3.0 โ€” Agent Hivemind (Shipped!)
1136
1372
 
1137
- See [What's New in v3.0.0 โ€” Agent Hivemind](#whats-new-in-v300---agent-hivemind-) above.
1373
+ See [What's in v3.0.0](#whats-in-v300--agent-hivemind-) above.
1138
1374
 
1139
1375
  ### ๐Ÿš€ Future Ideas
1140
1376
 
1141
1377
  | Feature | Issue | Description |
1142
1378
  |---------|-------|-------------|
1143
- | **Role-Scoped Skills & Rules** | โ€” | Each agent role (`dev`, `qa`, `pm`, etc.) gets its own persistent skill/rules document. Preloaded automatically at session start via `session_load_context`. Skills editable and uploadable from the Mind Palace Dashboard (โš™๏ธ โ†’ Skills tab per role). Stored in `configStorage` per-role key โ€” backend already exists. |
1144
- | OpenTelemetry SDK Integration | [#6](https://github.com/dcostenco/prism-mcp/issues/6) | W3C-compliant tracing with Jaeger/Zipkin export |
1145
- | GDPR Right to Portability | [#7](https://github.com/dcostenco/prism-mcp/issues/7) | `session_export_memory` tool for Art. 20 compliance |
1146
- | Multi-agent CRDT Conflict Resolution | [#9](https://github.com/dcostenco/prism-mcp/issues/9) | Conflict-free replicated data types for concurrent agent edits |
1147
- | Memory Analytics Dashboard | [#10](https://github.com/dcostenco/prism-mcp/issues/10) | Usage trends, token costs, and memory health metrics |
1148
- | Pluggable LLM Providers | [#13](https://github.com/dcostenco/prism-mcp/issues/13) | Anthropic, OpenAI, Ollama provider adapters |
1149
- | VLM / OCR for Visual Memory | [#14](https://github.com/dcostenco/prism-mcp/issues/14) | Auto-extract text and insights from stored images |
1150
- | Automated Data Retention (TTL) | [#16](https://github.com/dcostenco/prism-mcp/issues/16) | Time-based memory expiration policies |
1151
- | Obsidian / Logseq Export Bridge | [#17](https://github.com/dcostenco/prism-mcp/issues/17) | Export memory to Markdown knowledge bases |
1152
- | Interactive Knowledge Graph Editor | [#19](https://github.com/dcostenco/prism-mcp/issues/19) | Visual graph editor inside the Mind Palace dashboard |
1379
+ | Insight Graduation | โ€” | `knowledge_upvote` / `knowledge_downvote` โ€” importance โ‰ฅ 7 promotes to rule |
1380
+ | OpenTelemetry | [#6](https://github.com/dcostenco/prism-mcp/issues/6) | W3C tracing with Jaeger/Zipkin export |
1381
+ | GDPR Portability | [#7](https://github.com/dcostenco/prism-mcp/issues/7) | `session_export_memory` for Art. 20 |
1382
+ | CRDT Conflict Resolution | [#9](https://github.com/dcostenco/prism-mcp/issues/9) | Conflict-free types for concurrent edits |
1383
+ | Pluggable LLM Providers | [#13](https://github.com/dcostenco/prism-mcp/issues/13) | Anthropic, OpenAI, Ollama adapters |
1384
+ | VLM / OCR for Images | [#14](https://github.com/dcostenco/prism-mcp/issues/14) | Auto-extract text from stored images |
1385
+ | Knowledge Graph Editor | [#19](https://github.com/dcostenco/prism-mcp/issues/19) | Visual graph editor in Mind Palace |
1153
1386
 
1154
1387
  ### ๐Ÿงฐ Infrastructure & Stack
1155
1388