|
| 1 | + |
| 2 | +# Mindcore — AI Companion Platform (Developer Guide) |
| 3 | + |
| 4 | +> **Purpose:** Mindcore is a local‑first AI companion that observes your desktop (apps, files, screen, mic/cam with consent), remembers your life as a private timeline, and chats with you using that memory. This README gives junior developers a clear picture of the architecture, how modules connect, and how to run/contribute to the MVP. |
| 5 | +
|
| 6 | +--- |
| 7 | + |
| 8 | +## 1) Big Picture |
| 9 | + |
| 10 | +**Goal:** Build a _local_ AI best‑friend that can see context, remember, and talk naturally—without shipping your life to the cloud. |
| 11 | + |
| 12 | +**Principles** |
| 13 | +- **Local‑first & private:** data stays on your machine; encryption at rest; all sensors are opt‑in. |
| 14 | +- **Modular:** each capability is a package; the app is assembled from small parts. |
| 15 | +- **Event‑driven:** everything emits/consumes typed events (e.g., `activity.screen`, `memory.write`). |
| 16 | +- **Composable memory:** timeline ➜ summaries ➜ embeddings ➜ retrieval for LLM. |
| 17 | +- **Pluggable skills:** simple “skills”/plugins react to triggers and act through an SDK. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 2) System Overview (Layers) |
| 22 | + |
| 23 | +``` |
| 24 | ++-------------------+ +-------------------------------+ |
| 25 | +| Desktop UI | <----> | Background Daemon (API/BUS) | |
| 26 | +| (Tauri/Electron) | | Orchestrates all modules | |
| 27 | ++-------------------+ +-------------------------------+ |
| 28 | + ^ ^ |
| 29 | + | | |
| 30 | + v v |
| 31 | ++------------------+ +--------------------------+ |
| 32 | +| Conversation & | <events> | Memory Store | |
| 33 | +| LLM Orchestrator | ---------> | (SQLite + vector index) | |
| 34 | ++------------------+ +--------------------------+ |
| 35 | + ^ ^ |
| 36 | + | | |
| 37 | + v v |
| 38 | ++------------------+ +--------------------------+ |
| 39 | +| NLU / Context | <events> | Sensors & Perception | |
| 40 | +| Engine | <--------- | (STT, TTS, Face, Activity, |
| 41 | ++------------------+ | Screen/Keyboard, etc.) | |
| 42 | + +--------------------------+ |
| 43 | +``` |
| 44 | + |
| 45 | +**Key idea:** Sensors create **events** ➜ Memory writes timeline ➜ Context + LLM retrieve relevant moments ➜ Companion replies via UI/TTS. The **Background Daemon** provides a local API and a lightweight event bus to connect everything. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 3) Monorepo Structure |
| 50 | + |
| 51 | +``` |
| 52 | +mindcore/ |
| 53 | +├─ apps/ |
| 54 | +│ ├─ desktop-ui/ # Chat, settings, permissions (Tauri/Electron + React) |
| 55 | +│ ├─ background-daemon/ # Local API, event bus, orchestrator (FastAPI/Node) |
| 56 | +│ └─ recorder/ # Native capture for screen/keyboard/audio/video |
| 57 | +│ |
| 58 | +├─ packages/ |
| 59 | +│ ├─ context-engine/ # State, persona, routines, reminders |
| 60 | +│ ├─ llm-orchestrator/ # Tool routing, retrieval, prompt I/O, safety |
| 61 | +│ ├─ nlu/ # Intents/entities, sentiment, topic detection |
| 62 | +│ ├─ stt/ # Speech-to-text providers |
| 63 | +│ ├─ tts/ # Text-to-speech providers |
| 64 | +│ ├─ perception/ # Face/emotion; mic/cam feature extraction |
| 65 | +│ ├─ desktop-activity/ # App/file/window/screen tracking |
| 66 | +│ ├─ avatar-engine/ # 2D/3D character + lipsync hooks |
| 67 | +│ ├─ memory-store/ # SQLite timeline + embeddings (sqlite-vec / qdrant) |
| 68 | +│ ├─ privacy/ # Encryption, redaction, consent gates |
| 69 | +│ ├─ integrations/ # Spotify/Discord/Calendar… (one subpkg per service) |
| 70 | +│ ├─ plugin-api/ # Skill contract + loader |
| 71 | +│ └─ sdk/ # Typed client to call packages via the daemon |
| 72 | +│ |
| 73 | +├─ resources/ |
| 74 | +│ ├─ schemas/ # JSONSchema for events/memory |
| 75 | +│ ├─ prompts/ # Prompt templates, eval sets |
| 76 | +│ └─ models/ # Local models/checkpoints (git-lfs or .gitignored) |
| 77 | +│ |
| 78 | +├─ infra/ |
| 79 | +│ ├─ scripts/ # Dev scripts / dataset builders |
| 80 | +│ ├─ docker/ # Optional local vector DB, etc. |
| 81 | +│ └─ ci/ # Lint/Test/Build pipelines |
| 82 | +│ |
| 83 | +├─ tests/ # Cross-package integration tests |
| 84 | +├─ docs/ # MkDocs/Docusaurus site (user + dev docs) |
| 85 | +└─ examples/ # Minimal demos (hello companion) |
| 86 | +``` |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## 4) How Modules Connect |
| 91 | + |
| 92 | +### Communication |
| 93 | +- **Local REST/gRPC** exposed by `apps/background-daemon`. |
| 94 | +- **In‑process event bus** (simple pub/sub) for high‑frequency events. |
| 95 | +- **`packages/sdk`** provides a single, typed client for all modules. |
| 96 | + |
| 97 | +### Core Data Flow |
| 98 | +1. **Sensors** emit events (e.g., `activity.windowChanged`, `audio.transcript`). |
| 99 | +2. **privacy** filters/redacts per user settings. |
| 100 | +3. **memory-store** writes compact timeline entries and creates embeddings. |
| 101 | +4. **context-engine** maintains current context: “what’s happening now?” |
| 102 | +5. **llm-orchestrator** retrieves relevant memories ➜ builds prompts ➜ calls LLM. |
| 103 | +6. **desktop-ui** presents replies; **tts** can speak; **avatar-engine** animates. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## 5) Event & Memory Schemas (simplified) |
| 108 | + |
| 109 | +**Event: screen activity** |
| 110 | +```json |
| 111 | +{ |
| 112 | + "$schema": "resources/schemas/activity.screen.json", |
| 113 | + "type": "activity.screen", |
| 114 | + "ts": "2025-09-07T18:32:12Z", |
| 115 | + "app": "code", |
| 116 | + "window": "main.py — VS Code", |
| 117 | + "screenshot_path": "file:///.../shots/2025-09-07/183212.png", |
| 118 | + "text_hash": "sha256:..." |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +**Memory item** |
| 123 | +```json |
| 124 | +{ |
| 125 | + "$schema": "resources/schemas/memory.item.json", |
| 126 | + "id": "mem_01H8...", |
| 127 | + "ts": "2025-09-07T18:32:13Z", |
| 128 | + "source_event": "activity.screen", |
| 129 | + "summary": "Editing main.py in VS Code on Mindcore repo", |
| 130 | + "tags": ["coding", "vs-code", "mindcore"], |
| 131 | + "embedding": [0.021, -0.14, ...] |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +**Conversation tool call (example)** |
| 136 | +```json |
| 137 | +{ |
| 138 | + "tool": "memory.search", |
| 139 | + "query": "last time I worked on the context engine", |
| 140 | + "k": 8, |
| 141 | + "filters": {"tags": ["context-engine"]} |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## 6) Running the MVP (Local) |
| 148 | + |
| 149 | +### Prereqs |
| 150 | +- **Python 3.11+**, **Node 20+**, **pnpm**, **uv** (or pip), **SQLite 3.44+**. |
| 151 | +- macOS/Windows: grant screen/mic/camera permissions when prompted. |
| 152 | + |
| 153 | +### Quick Start |
| 154 | +```bash |
| 155 | +# 1) install workspaces |
| 156 | +pnpm i --filter "./apps/**" --filter "./packages/**" |
| 157 | + |
| 158 | +# 2) Python deps |
| 159 | +uv pip install -r apps/background-daemon/requirements.txt |
| 160 | +uv pip install -r packages/*/requirements.txt |
| 161 | + |
| 162 | +# 3) dev: start memory and daemon |
| 163 | +just dev # or: make dev |
| 164 | +# …spawns background-daemon and hot-reloads packages |
| 165 | + |
| 166 | +# 4) run UI |
| 167 | +pnpm --filter desktop-ui dev |
| 168 | +``` |
| 169 | + |
| 170 | +**First Run Checklist** |
| 171 | +- Open **Desktop UI → Settings → Permissions** and toggle which sensors are allowed. |
| 172 | +- Create a test conversation; verify that memories appear in the Timeline tab. |
| 173 | +- Try voice chat: STT ➜ LLM ➜ TTS. |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## 7) Building a Skill (Plugin) |
| 178 | + |
| 179 | +**Skill contract (`packages/plugin-api`)** |
| 180 | +```json |
| 181 | +{ |
| 182 | + "name": "daily_checkin", |
| 183 | + "triggers": ["time:08:00", "event:emotion.low"], |
| 184 | + "inputs_schema": { "type": "object", "properties": { "mood": {"type":"string"} } }, |
| 185 | + "handler": "python:skills.daily_checkin:run" |
| 186 | +} |
| 187 | +``` |
| 188 | + |
| 189 | +**Register the skill** |
| 190 | +```ts |
| 191 | +// apps/background-daemon/register.ts |
| 192 | +import { registerSkill } from "@mindcore/plugin-api"; |
| 193 | +import { dailyCheckin } from "@mindcore/skills/daily_checkin"; |
| 194 | +registerSkill(dailyCheckin); |
| 195 | +``` |
| 196 | + |
| 197 | +**Skill handler (pseudo)** |
| 198 | +```python |
| 199 | +def run(ctx, inputs): |
| 200 | + last_sleep = ctx.memory.search("sleep hours last night", k=3) |
| 201 | + prompt = f"User reports mood {inputs['mood']}. Prior sleep: {last_sleep}" |
| 202 | + reply = ctx.llm.chat(prompt) |
| 203 | + ctx.ui.notify(reply) |
| 204 | +``` |
| 205 | + |
| 206 | +--- |
| 207 | + |
| 208 | +## 8) Privacy Model (MUST READ) |
| 209 | + |
| 210 | +- **Opt‑in sensors**: all off by default; granular toggles. |
| 211 | +- **Encryption at rest**: AES‑GCM; keys in OS keychain. |
| 212 | +- **Redaction**: credit cards, SSNs, faces in screenshots can be auto‑blurred. |
| 213 | +- **Local‑only**: no cloud sync by default; optional backups are explicit. |
| 214 | +- **Safe mode**: “Do not record” quick toggle + app/website blacklists. |
| 215 | +- **Data export/delete**: one‑click “Wipe all memory” and per‑tag deletions. |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +## 9) Coding Conventions |
| 220 | + |
| 221 | +- **Type‑safe boundaries**: pydantic (py) / zod (ts) with shared JSONSchemas. |
| 222 | +- **Linters**: black/ruff (py), eslint/prettier (ts). |
| 223 | +- **Commits**: conventional commits (`feat:`, `fix:`, `docs:`…). |
| 224 | +- **Tests**: unit inside each package; integration in `/tests` with a simulated user. |
| 225 | +- **Docs**: every package has a `README.md` with its public API. |
| 226 | + |
| 227 | +--- |
| 228 | + |
| 229 | +## 10) Roadmap (MVP ➜ Alpha) |
| 230 | + |
| 231 | +**MVP (Weeks 1–4)** |
| 232 | +- Desktop activity tracker → Memory store |
| 233 | +- STT/TTS + basic chat in UI |
| 234 | +- Retrieval‑augmented LLM with simple context rules |
| 235 | +- Permissions panel + “Do not record” |
| 236 | + |
| 237 | +**Alpha (Weeks 5–8)** |
| 238 | +- Face presence + emotion signal |
| 239 | +- Skills: daily check‑in, study timer, “nudge to break” |
| 240 | +- Avatar with basic lipsync |
| 241 | +- Data export + wipe |
| 242 | + |
| 243 | +**Beta (Weeks 9–12)** |
| 244 | +- Plugin marketplace (local registry) |
| 245 | +- More integrations (Calendar, Discord, Spotify) |
| 246 | +- Learning loop (personalization) |
| 247 | +- Optional encrypted backup |
| 248 | + |
| 249 | +--- |
| 250 | + |
| 251 | +## 11) Glossary |
| 252 | + |
| 253 | +- **Event**: a single fact about something that happened (e.g., window changed). |
| 254 | +- **Memory**: a summarized, searchable record derived from events. |
| 255 | +- **Context**: the current situation estimate used to guide the assistant. |
| 256 | +- **Skill**: a plugin that reacts to triggers and produces helpful actions. |
| 257 | + |
| 258 | +--- |
| 259 | + |
| 260 | +## 12) Where to Start as a New Dev |
| 261 | + |
| 262 | +1. **Run the quick start** and verify events → memories in the UI. |
| 263 | +2. Pick one package (e.g., `desktop-activity`) and read its README. |
| 264 | +3. Implement one **small skill** (e.g., “hydration nudge”) to learn the SDK. |
| 265 | +4. Add an integration test proving your skill writes a memory and shows a UI prompt. |
| 266 | + |
| 267 | +> When in doubt: _make an event, write a memory, retrieve it for a good reply._ |
0 commit comments