Skip to content

Commit bf2b655

Browse files
committed
new web
1 parent 03da311 commit bf2b655

File tree

11 files changed

+1184
-1
lines changed

11 files changed

+1184
-1
lines changed

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/logo.jpg

2.83 KB
Loading

docs/ARCHITECTURE.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## MindCore Architecture (Expanded)
2+
3+
This document complements `COMPANION_LOOP.md` with deeper implementation detail.
4+
5+
### High-Level Layers
6+
7+
1. Capture Layer (Trackers / Sensors)
8+
- Desktop activity trackers (apps, files, web, clipboard, emotion, speech, system, etc.)
9+
- Each tracker produces raw events: `{source, type, ts, metadata, summary?, tags?}`
10+
2. Ingestion Layer
11+
- HTTP (`/api/events/`) & Socket.IO event ingestion into Background Daemon
12+
- Backpressure queue (bounded) feeding proactive engine heuristics
13+
3. Normalization & Memory Layer
14+
- Raw events → lightweight `Memory` (summary + embedding + tags)
15+
- Selected enriched events → `Episode` (details, salience, artifacts)
16+
- Vector index (FAISS / in‑memory) for episodic retrieval
17+
4. Enrichment Jobs
18+
- Periodic or on-demand: daily & weekly summaries, entity+relationship extraction, emotion aggregation
19+
- PII redaction pre-index; optional payload encryption
20+
5. Conversational Orchestrator
21+
- Dialogue state (history + scratchpad), mood model, personality and safety guard
22+
- Two-pass (plan → answer) + retrieval augmented prompt assembly
23+
6. Proactive Engagement Engine
24+
- Time triggers, focus & anomaly heuristics, comfort policy & sensitivity modulation
25+
- Emits check-ins (Socket.IO) → persists as memories
26+
7. Privacy, Consent & Transparency
27+
- Per-sensor consent log (auditable) with current effective status
28+
- Pause listening control, forget endpoints, transparency daily snapshot
29+
- Redaction (regex-based) + optional encryption hooks + local-first stance
30+
31+
### Data Flow Diagram (Narrative)
32+
33+
Tracker Event → (optional local pre-filter) → HTTP / Socket.IO → Ingest endpoint →
34+
Consent Check → (if allowed) → Persist `Memory` + enqueue for Proactive Engine →
35+
Heuristics may trigger Check-in → (LLM refine + safety) → Emit & store.
36+
37+
Batch jobs (daily/weekly/entity/emotion) scan Episodes → produce new enriched Episodes.
38+
39+
Chat request → Dialogue state update → Vector search (Memories/Episodes) → Plan → Answer → Safety self-check → Reflection Episode.
40+
41+
### Backpressure Strategy
42+
43+
The event queue in the Proactive Engine is bounded (`max_event_queue`). When full:
44+
45+
- Drop oldest (FIFO) before enqueueing new event (bounded memory, freshness prioritized)
46+
- Metrics placeholder for future adaptive tuning
47+
48+
### Consent & Permission Model
49+
50+
- `consent_log` table records every grant/revoke: `{sensor, granted, ts, reason}`
51+
- Current effective consent = last row per sensor.
52+
- Ingest rejects (silently accepts but does not persist) events whose `source` lacks consent.
53+
- API: `/api/permissions` (list), `/api/permissions/{sensor}` (update)
54+
55+
### Sensitivity Profile & Comfort Policy
56+
57+
- Sensitivity adjusts proactive engagement frequency.
58+
- Profile fields: `engagement_level (low|medium|high)`, `max_checkins_override`, `min_minutes_between_checkins_override`.
59+
- Applied dynamically to ComfortPolicy without restart.
60+
61+
### Encryption
62+
63+
- Passphrase-derived key (PBKDF2, 200k iters) for field encryption.
64+
- Envelopes: v2 (AES-GCM) default; legacy v1 (Fernet) supported for backwards compatibility.
65+
- Env flag `MINDCORE_ENCRYPT_SUMMARY` enables summary encryption; details are encrypted by default when a passphrase is provided.
66+
- Locked mode: API endpoints `/controls/unlock` and `/controls/lock` control in-memory passphrase. Without unlocking, encrypted fields are not decrypted in responses.
67+
68+
### Future Enhancements (Roadmap)
69+
70+
- Streaming STT health & latency metrics
71+
- Adaptive retention (salience + decay)
72+
- User feedback loop for memory relevance scoring
73+
- Differential privacy noise injection for analytics exports (if any remote mode is added)

docs/COMPANION_LOOP.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# MindCore Companion Loop and Memory Taxonomy
2+
3+
## Companion Loop
4+
5+
Observe → Interpret → Store → Decide → Engage → Learn
6+
7+
- Observe: Desktop trackers, STT, perception feed events into the daemon.
8+
- Interpret: Orchestrator classifies, summarizes, tags, embeds.
9+
- Store: Persist to DB + update vector store.
10+
- Decide: Trigger policies (check-ins, nudges, reminders) based on context.
11+
- Engage: Chat/notifications via UI, Socket.IO.
12+
- Learn: Update profiles, weights, and heuristics from outcomes.
13+
14+
```mermaid
15+
design
16+
flowchart LR
17+
A["Observe\n(trackers, stt, vision)"] --> B["Interpret\n(summarize, tag, embed)"]
18+
B --> C["Store\n(sqlite + faiss)"]
19+
C --> D["Decide\n(policies, triggers)"]
20+
D --> E["Engage\n(chat, notifications)"]
21+
E --> F["Learn\n(adapt personalization)"]
22+
F --> B
23+
```
24+
25+
## Memory Taxonomy
26+
27+
- Episodic: time-stamped moments, e.g., "Edited Thesis.docx at 23:14" (source, summary, tags, embedding)
28+
- Semantic: consolidated knowledge, e.g., "User prefers VS Code for Python"
29+
- Emotional: mood states inferred from voice/vision, time-bounded
30+
- Relational: entities and relationships, e.g., people, apps, projects
31+
- Temporal anchors: routines, streaks, recurrence patterns
32+
33+
Schema notes
34+
35+
- Base fields: id, ts, source, summary, tags[], embedding[]
36+
- Type-specific fields: kind (episodic|semantic|emotional|relational|temporal), payload json
37+
- Derived indices: by time, by entity, by routine pattern
38+
39+
## Event → Memory Mapping
40+
41+
- Tracker events normalized to {source, type, summary, tags}
42+
- Orchestrator enriches with context windows and emits memory candidates
43+
- Deduplication windows (e.g., 5–10 minutes) collapse repetitive events
44+
45+
## Decision Policies (initial)
46+
47+
- Fatigue checks: prolonged focus → break suggestion
48+
- Mood check-ins: sustained negative affect → gentle outreach
49+
- Routine helpers: recurring time/app → suggest next step

docs/Mindcore_README.md

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
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

Comments
 (0)