S239 Technical Reference — Vitto Memory System V2
Documentation for Vitto
S239 Technical Reference — Vitto Memory System V2
Session: 239 | Date: 2026-03-19 | Branch: session-238-239 (shared concurrent) Spec:
docs/superpowers/specs/2026-03-19-vitto-memory-system-v2-design.mdPlan:docs/superpowers/plans/2026-03-19-vitto-memory-system-v2.md
1. Architecture Overview
Dual-System Design
| System | Purpose | Where It Lives |
|---|---|---|
| Soul | Identity, personality, consciousness | Existing: MoodDefinitionService, IdentitySynthesisService, Character/Values/Trust pages |
| Brain | Knowledge storage and retrieval | New: 4-scope memory hierarchy with admission, recall, conflict resolution |
Memory Scope Hierarchy
Organization (company-wide rules, policies)
└─ Space (team/workspace context)
└─ Universe (per-project knowledge)
└─ User (personal preferences, conversation history)
Conflict Resolution Rules:
- Preferences: User > Universe > Space > Organization (user knows best)
- Policies: Organization > Space > Universe > User (compliance wins)
- Detection: Tag-based (
policy,compliance,mandatory) +overridable: booleanfield
Schema Changes
vitto-memories collection — new fields:
{
scope: 'organization' | 'space' | 'universe' | 'user', // NEW
scopeId: string, // NEW — maps to orgId/spaceId/universeId/userId
status: 'active' | 'quarantine' | 'archived' | 'rejected', // NEW
prospectiveQuestions: string[], // NEW — generated by ProspectiveIndexerPlugin
history: MemoryVersion[], // NEW — version history for audit/revert
}
2. New Backend Services
All services live in APIs/backend-vitto-api/src/app/mind/.
Core Services (mind/services/)
| Service | File | Purpose | Dependencies |
|---|---|---|---|
DopamineRouterService |
services/dopamine-router.service.ts |
Fast/slow route decision with hot cache | None (pure computation) |
MemoryAdmissionService |
services/memory-admission.service.ts |
5-factor scoring gate for memory storage | None (pure computation) |
ConversationGenomeService |
services/conversation-genome.service.ts |
Compress conversation history into structured genome | None (heuristic v1) |
WindowManagerService |
services/window-manager.service.ts |
Sliding window for in-session context management | None (pure computation) |
ToonSerializerService |
services/toon-serializer.service.ts |
Token-Optimized Object Notation serializer | None (pure computation) |
SoulCompressorService |
services/soul-compressor.service.ts |
Compress soul config to ~150-token brief | ToonSerializerService |
MemoryExportService |
services/memory-export.service.ts |
Generate markdown exports for docs-angular | None (pure computation) |
Enhanced Services
| Service | File | Changes |
|---|---|---|
VittoMemoryRecallService |
memory/vitto-memory-recall.service.ts |
Added scopeAwareRecall() — parallel multi-scope queries with conflict resolution |
MemoryConflictResolverService |
conflict/memory-conflict-resolver.service.ts |
Added resolve() with full ConflictReport output |
Deprecated Services
| Service | Replaced By | Status |
|---|---|---|
DopamineRouterService (recall/) |
DopamineRouterService (services/) |
@deprecated JSDoc added |
SoulCompressionService |
SoulCompressorService |
@deprecated JSDoc added |
3. Cognitive Plugin System
Interface
APIs/backend-vitto-api/src/app/mind/plugins/
├── cognitive-plugin.types.ts # Plugin interface + BaseCognitivePlugin
├── cognitive-plugin-registry.service.ts # Registry with lifecycle execution
├── index.ts # Barrel exports
└── built-in/
├── prospective-indexer.plugin.ts # Future-question enrichment
└── on-demand-recall.plugin.ts # Dynamic memory injection
Lifecycle Hooks
Message arrives
→ onBeforeContextAssembly() // Modify what gets assembled (sequential, context-chaining)
→ Context assembled
→ onBeforeResponse() // Last-chance memory injection (sequential)
→ LLM responds
→ onAfterResponse() // Extract learnings (parallel, fire-and-forget)
→ onMemoryAdmission() // Gate what gets stored (AND-gate: any reject = reject)
→ onMemoryConsolidation() // Influence merge/prune (sequential)
Built-in Plugins
| Plugin | Hook | Priority | Behavior |
|---|---|---|---|
ProspectiveIndexerPlugin |
onMemoryAdmission |
40 | Generates 3-5 future questions per memory. Uses LLM (cheap model) with heuristic fallback. Never rejects — only enriches. |
OnDemandRecallPlugin |
onBeforeContextAssembly |
80 | Injects relevant memories via recall function. 200ms timeout (fast) / 2000ms (slow). Graceful degradation on failure. |
4. Intelligence Innovations
DopamineRouterService (Fast/Slow Recall)
Scoring formula: score = (novelty × 0.4) + (complexity × 0.3) + (valence × 0.2) + explicitRecallBonus
| Score | Route | Token Budget | Behavior |
|---|---|---|---|
| < 0.5 | Fast | 500 tokens | Hot cache → single vector search → user scope only |
| ≥ 0.5 | Slow | 2000 tokens | Full multi-scope recall → knowledge graph → cross-session search |
Hot Cache: In-memory Map, 5-min TTL, 1000 entries max (LRU), invalidated on memory write.
MemoryAdmissionService (5-Factor Gate)
| Factor | Weight | Measures |
|---|---|---|
| Future Utility | 0.30 | Will this be useful later? (keyword: "prefer", "always", "I am") |
| Factual Confidence | 0.20 | Is this reliable? (direct statement vs inferred) |
| Semantic Novelty | 0.25 | Do we already know this? (Jaccard overlap with last 50) |
| Temporal Relevance | 0.15 | Is this still relevant? (timeless facts vs past events) |
| Content Type Prior | 0.10 | Inherent value by type (corrections=1.0, greetings=0.1) |
Thresholds: ≥0.6 admit | 0.35-0.6 quarantine | <0.35 reject
ConversationGenomeService (Virtual Context)
Compresses N messages into structured genome:
{
topics: string[], // Key discussion topics
decisions: string[], // Decisions made during conversation
facts: string[], // Facts established
artifacts: string[], // Code, files, URLs mentioned
summary: string, // 2-3 sentence overview
tokenCount: number, // ~1K tokens vs ~10K raw
}
Heuristic v1: Keyword extraction, no LLM calls. LLM v2 planned (recompile every 5 messages with cheap model).
TOON Serialization
// JSON (38 tokens):
{"user":{"name":"Paco","role":"executive","preferences":{"tone":"casual"}}}
// TOON (18 tokens):
u{n:Paco|r:executive|p{t:casual}}
40-60% token reduction. 23-key abbreviation map. Roundtrip-safe (serialize/deserialize).
5. Frontend Components
All in libs/libs-ai/vitto-hub/src/lib/components/.
| Component | Selector | Location |
|---|---|---|
MemoryScopeFilterComponent |
app-memory-scope-filter |
memory-manager/memory-scope-filter/ |
MemoryVersionHistoryComponent |
ggo-memory-version-history |
memory-manager/memory-version-history/ |
MemoryQuarantineComponent |
ggo-memory-quarantine |
memory-quarantine/ |
GenomeViewerComponent |
ggo-genome-viewer |
memory/genome-viewer/ |
Frontend Types (@libs-ai/vitto-core)
export type MemoryScope = 'organization' | 'space' | 'universe' | 'user';
export type MemoryStatus = 'active' | 'quarantined' | 'archived';
export interface MemoryEntry { /* scope, scopeId, status, prospectiveQuestions, history */ }
export interface ConversationGenome { /* topics, decisions, facts, artifacts, summary */ }
export interface RouteDecision { /* route, score, reasoning, tokenBudget, cacheable */ }
export interface AdmissionScore { /* totalScore, factors, decision, reasoning */ }
export interface MemoryExportResult { /* files, totalMemories, stats */ }
6. MongoDB Vector Search Indexes
| Index | Cluster | Database.Collection | Dimensions | Filter Fields |
|---|---|---|---|---|
vitto_memories_vector |
vitto.urgh5aw.mongodb.net |
vitto-mind.vitto-memories |
1536 | userId, scope, status |
agent_embeddings |
gograbspace.dgajj2t.mongodb.net |
ai-memory.agent_embeddings |
1536 | agentId, sessionNumber |
episodes_vector |
gograbspace.dgajj2t.mongodb.net |
ai-mcp-dev.episodes |
1536 | agentId |
chat_message_embeddings_vector |
gograbspace.dgajj2t.mongodb.net |
ai-agents.chat_message_embeddings |
1536 | userId, sessionId, channelId |
golden_embeddings |
gograbspace.dgajj2t.mongodb.net |
ai-memory.golden_embeddings |
1536 | (pre-existing) |
New collection: chat_message_embeddings — flat (one doc per message) replaces nested chat_sessions.messages[].embedding.
7. Test Coverage
File: APIs/backend-vitto-api/src/app/mind/__tests__/memory-pipeline-e2e.spec.ts
| Suite | Tests | Covers |
|---|---|---|
| Full Pipeline | 5 | End-to-end: admission → routing → recall → export |
| In-Session Continuity | 9 | Novelty detection, repeated queries, explicit recall |
| Conflict Resolution | 9 | Preference vs policy, scope precedence, merge |
| TOON Serialization | 9 | Roundtrip, compression ratio, soul config |
| Export Pipeline | 15 | Multi-scope, frontmatter, filtering, packaging |
| Admission Edge Cases | 9 | Overlap detection, corrections, thresholds |
| Cognitive Plugin Registry | 8 | Registration, priority, AND-gate, error isolation |
| Performance Benchmarks | 5 | <5ms admission, <10ms routing, <10ms conflict |
| Total | 70 |
Plus per-service unit tests: ~200+ additional tests across individual spec files.
8. MCP Intelligence Captured
Decisions Logged (5)
| ID | Type | Question | Confidence |
|---|---|---|---|
dev_..._rccoy4k |
architecture | Memory system architecture design | 0.94 |
dev_..._7vu89il |
architecture | In-session memory continuity | 0.92 |
dev_..._hntklwa |
infrastructure | MongoDB vector search setup | 0.96 |
dev_..._47oxxvd |
pattern | Cognitive plugin system design | 0.93 |
dev_..._ptrdcy7 |
implementation | TOON serializer + soul compression | 0.91 |
Conventions Added (4)
- Soul/Brain separation — Soul is NOT a memory scope; Brain uses 4-scope hierarchy
- Cognitive plugins required — All memory innovations must be CognitivePlugins, not hardcoded
- Flat embedding collections — Never nest embeddings in parent documents
- Quarantine tier mandatory — Gated memories go to quarantine, never permanently deleted
Lessons Reflected (10)
See intelligence({ action: "recall", situation: "memory architecture" }) for full list.
9. Known Issues & Future Work
Issues to Address
| Issue | Severity | Notes |
|---|---|---|
scoreContentTypePrior entity detection unreachable |
Low | Content is lowercased but regex expects PascalCase. Fix in next session. |
| Old DopamineRouterService still registered in module | Low | Both old (3-route) and new (2-route) coexist. Consolidate when ready. |
| Genome not yet wired into live agent loop | High | ConversationGenomeService exists but not called from agent-loop.service.ts |
Planned Tasks (from spec)
| Task | Priority | Estimate |
|---|---|---|
| Wire genome into agent-loop.service.ts | High | 1 session |
| Redis hot cache for DopamineRouter | High | 1 session |
| LLM-powered genome recompile v2 | Medium | 1 session |
| UserPreferenceLearningPlugin | Medium | 1 session |
| Cross-channel UserGenomeService | Medium | 1 session |
| Matryoshka 256-dim embedding migration | Low | 1 session |
| Prompt caching optimization | Low | 1 session |
| Data migration script (scope backfill) | Medium | 0.5 session |
10. File Inventory
New Files Created
APIs/backend-vitto-api/src/app/mind/
├── services/
│ ├── dopamine-router.service.ts # Fast/slow route decision
│ ├── dopamine-router.service.spec.ts # 40+ tests
│ ├── memory-admission.service.ts # 5-factor admission gate
│ ├── memory-admission.service.spec.ts # 60 tests
│ ├── conversation-genome.service.ts # Conversation compression
│ ├── window-manager.service.ts # Sliding window context
│ ├── toon-serializer.service.ts # TOON format
│ ├── toon-serializer.service.spec.ts # 48 tests
│ ├── soul-compressor.service.ts # Soul → 150-token brief
│ ├── soul-compressor.service.spec.ts # 42 tests
│ └── memory-export.service.ts # Markdown export
│ └── memory-export.service.spec.ts # 45 tests
├── plugins/
│ ├── cognitive-plugin.types.ts # Plugin interface
│ ├── cognitive-plugin-registry.service.ts # Registry + execution
│ ├── index.ts # Barrel
│ └── built-in/
│ ├── prospective-indexer.plugin.ts # Future questions
│ └── on-demand-recall.plugin.ts # Dynamic injection
├── conflict/
│ └── __tests__/
│ └── memory-conflict-resolver.service.spec.ts # 25 tests
└── __tests__/
└── memory-pipeline-e2e.spec.ts # 70 E2E tests
libs/libs-ai/vitto-hub/src/lib/components/
├── memory-manager/
│ ├── memory-scope-filter/ # Scope pill filter
│ ├── memory-version-history/ # Edit timeline + revert
│ └── genome-viewer/ # Genome visualization
├── memory-quarantine/ # Quarantine review dashboard
└── memory/
└── genome-viewer/ # Standalone genome viewer
libs/libs-ai/vitto-core/src/lib/models/
└── memory-v2.models.ts # Frontend types
APIs/backend-ai-api/src/app/agents/schemas/
└── chat-message-embedding.schema.ts # Flat embedding collection
Modified Files
APIs/backend-vitto-api/src/app/mind/
├── mind.module.ts # Registered all V2 services
├── memory/vitto-memory.types.ts # Added MemoryScope, MemoryStatus
├── memory/vitto-memory-recall.service.ts # Added scopeAwareRecall()
├── conflict/memory-conflict-resolver.service.ts # Added resolve()
├── recall/dopamine-router.service.ts # @deprecated
└── soul-compression.service.ts # @deprecated
libs/libs-ai/vitto-hub/src/lib/components/
├── index.ts # Added V2 component exports
└── memory-manager/memory-manager.component.ts # Integrated V2 components
libs/libs-ai/vitto-core/src/index.ts # Added V2 type exports
docs/english/Plans/
└── S239-vector-search-index-handoff.md # Cowork agent handoff
Generated: 2026-03-19 | Session 239 | Claude Code on gspace1