# Project: DSCons ERP Mem0 Knowledge Base Overhaul

## Architecture
- **Mem0 Local Service Architecture**:
  - Windows Background Service running on `http://127.0.0.1:8765/sse`
  - Storage: Embedded Qdrant at `C:\Users\Admin\.gemini\antigravity\mem0_data\qdrant`, collection `antigravity_memories`
  - Embedder: `PureVectorEmbedder` (768-dim hash of words + 3-grams, cosine similarity)
- **Data Flow**:
  1. Survey & Scope Mapping (Completed): 480 points analyzed → 31 obsolete DSCons UUIDs identified; 449 non-DSCons points preserved; 27 atomic facts designed across 5 domains.
  2. Selective Cleanup (M1): Execute deletion of the 31 obsolete UUIDs via `mem0_delete`, verifying count drops from 480 to 449.
  3. Memory Ingestion (M2): Ingest 27 atomic invariant facts with domain prefixes, anti-patterns, and bilingual keywords via `mem0_add`.
  4. Dual-Track E2E Testing & Acceptance Gate (M3): Execute automated verification test suite checking 8 queries, verifying top-1 scores ≥ 0.55 and 0% contamination.

## Feature Inventory
| # | Feature | Description | Milestone | Source |
|---|---------|-------------|-----------|--------|
| 1 | Service Health Verification | Confirm Mem0 service is active and responsive on port 8765 | M1 | survey |
| 2 | Exact 31-UUID Selective Purge | Delete exactly the 31 obsolete DSCons records via `mem0_delete` | M1 | survey |
| 3 | Strict Zero-Wipe Preservation | Verify all 449 non-DSCons records (FreeExile, VoLamWeb, Dev preferences) remain intact | M1 | survey |
| 4 | Root Standards Ingestion | Ingest 5 atomic facts for AGENTS.md, GEMINI.md, 7 Core Laws, MCP Matrix | M2 | survey |
| 5 | Backend & DB Standards Ingestion | Ingest 5 atomic facts for Clean Architecture, Decimal(18,4), Double-entry ledger, /v1/erp, Teardown | M2 | survey |
| 6 | Frontend Standards Ingestion | Ingest 5 atomic facts for Dark Slate, Inter/JetBrains Mono, Bloomberg density, Zero Occlusion, Cache buster | M2 | survey |
| 7 | AEC Business Standards Ingestion | Ingest 7 atomic facts for 4 Pillars Định Sơn MST 0202111150, Norms 2026, Larsen VL=0, MR/T ratio, TK 621, CAD byte decoding, Renovation | M2 | survey |
| 8 | Testing & Workflow Standards Ingestion | Ingest 5 atomic facts for TDD >=80%, Deep Matrix D1-D6, 6-Phase verification, Eval harness EDD | M2 | survey |
| 9 | E2E Test Suite Automation | Automated test harness executing 8 verification queries with scorecard output | M3 | survey |
| 10 | Mandatory Query Verification | Verify "DSCons rule", "frontend theme", "backend architecture" return new facts with score >= 0.55 | M3 | survey |
| 11 | Zero-Contamination Audit | Verify zero FreeExile contamination, zero legacy log remnants, and forensic cleanliness | M3 | survey |

## Milestones
| # | Name | Scope | Dependencies | Status |
|---|------|-------|-------------|--------|
| M1 | Selective Cleanup | Delete 31 obsolete DSCons records in Mem0; preserve 449 non-DSCons records | None | DONE |
| M2 | Memory Ingestion | Ingest 27 atomic invariant facts across 5 core domains via `mem0_add` | M1 | DONE |
| M3 | Final Milestone: E2E Verification & Audit Gate | Execute 8-query verification test suite; verify scores and zero-contamination; Forensic Audit | M2 | DONE |

## Interface Contracts
### M1 Selective Cleanup ↔ M2 Memory Ingestion
- Input: List of 31 obsolete UUIDs from Explorer 1 handoff.
- Post-condition: `mem0_status` developer_memories_count == 449.
- Pre-condition for M2: Database is clean of legacy DSCons records before adding new facts.

### M2 Memory Ingestion ↔ M3 E2E Verification
- Input: 27 structured facts catalog from Explorer 3 handoff (`metadata={"project": "DSCons"}`).
- Post-condition: `mem0_status` developer_memories_count == 476 (449 + 27).
- Pre-condition for M3: All 27 facts present in Mem0.

### E2E Testing Track ↔ Implementation Track
- Interface signal: `TEST_READY.md` published by E2E Testing Track.
- Test runner: `python tests/test_mem0_verification.py` returning exit code 0.

## Code Layout
- Agent coordination: `c:\Projects\DSCons\.agents\teamwork\`
- Test script: `c:\Projects\DSCons\tests\test_mem0_verification.py`
- Test documentation: `c:\Projects\DSCons\TEST_INFRA.md`, `c:\Projects\DSCons\TEST_READY.md`
