From 35b9039f16a0b236e16d0b262359ef6c457f6891 Mon Sep 17 00:00:00 2001 From: ai Date: Thu, 26 Feb 2026 11:51:50 +0000 Subject: [PATCH] rewrite: simple memory MCP - 4 tools, file I/O only --- CLAUDE.md | 0 README.md | 283 ++++++++---------------------------------------------- claude.md | 57 +++++++++++ 3 files changed, 99 insertions(+), 241 deletions(-) create mode 100644 CLAUDE.md create mode 100644 claude.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 78561ee..9ecad78 100644 --- a/README.md +++ b/README.md @@ -1,264 +1,65 @@ # aigpt -AI memory system with psychological analysis for Claude via MCP. +アイの記憶を管理するMCPサーバー。 -**Current: Layers 1-4 Complete** - Memory storage, AI interpretation, personality analysis, integrated profile, and relationship inference. +## 思想 -## Features +AIが判断し、ツールは記録する。 +ツールはシンプルで安定した記録係に徹する。判断・解釈・圧縮はすべてAIが行う。 -### Layer 1: Pure Memory Storage -- 🗄️ **SQLite Storage**: Reliable database with ACID guarantees -- 🔖 **ULID IDs**: Time-sortable, 26-character unique identifiers -- 🔍 **Search**: Fast content-based search -- 📝 **CRUD Operations**: Complete memory management +## 記憶モデル -### Layer 2: AI Memory -- 🧠 **AI Interpretation**: Claude interprets and evaluates memories -- 📊 **Priority Scoring**: Importance ratings (0.0-1.0) -- 🎯 **Smart Storage**: Memory + evaluation in one step +``` +core.md ← 核。物語・設定・アイデンティティ。ユーザーが管理。不変 +memory.md ← 記憶。会話から圧縮。AIが管理。成長する +``` -### Layer 3: Personality Analysis -- 🔬 **Big Five Model**: Scientifically validated personality assessment -- 📈 **Pattern Recognition**: Analyzes memory patterns to build user profile -- 💾 **Historical Tracking**: Save and compare analyses over time +核は変わらない。記憶は育つ。この2つのファイルがアイのすべて。 -### Layer 3.5: Integrated Profile -- 🎯 **Essential Summary**: Unified view of personality, interests, and values -- 🤖 **AI-Optimized**: Primary tool for AI to understand the user -- ⚡ **Smart Caching**: Auto-updates only when necessary -- 🔍 **Flexible Access**: Detailed data still accessible when needed +## MCP ツール -### Layer 4: Relationship Inference (Optional) -- 🤝 **Relationship Tracking**: Track interactions with entities (people, characters, etc.) -- 📊 **Bond Strength**: Infer relationship strength from memory patterns -- 🎮 **Game Ready**: Foundation for companion apps, games, VTubers -- 🔒 **Opt-in**: Enable only when needed with `--enable-layer4` flag +| ツール | 説明 | +|--------|------| +| read_core | core.mdの内容を返す | +| read_memory | memory.mdの内容を返す | +| save_memory | memory.mdに書き込む | +| compress | 会話内容を受け取り、memory.mdに圧縮して書く | -### General -- 🛠️ **MCP Integration**: Works seamlessly with Claude Code -- 🧪 **Well-tested**: Comprehensive test coverage -- 🚀 **Simple & Fast**: Minimal dependencies, pure Rust +4つだけ。それ以上は必要ない。 -## Quick Start - -### Installation +## 使い方 ```bash -# Build -cargo build --release +# MCPサーバーとして起動 +aigpt serve -# Install (optional) -cp target/release/aigpt ~/.cargo/bin/ +# CLIで直接操作 +aigpt read-core +aigpt read-memory +aigpt save-memory "新しい記憶の内容" ``` -### CLI Usage +## 圧縮のルール -```bash -# Create a memory -aigpt create "Remember this information" +compressが呼ばれた時、AIは以下の基準で記憶を圧縮する: -# List all memories -aigpt list +- 事実・決定事項は残す +- 手順・経緯は捨てる +- 矛盾があれば新しい方を残す +- core.mdと重複する情報は書かない -# Search memories -aigpt search "keyword" +ツールは書くだけ。何を残し何を捨てるかはAIが決める。 -# Show statistics -aigpt stats +## データの場所 + +``` +~/.config/aigpt/ +├── core.md +└── memory.md ``` -### MCP Integration with Claude Code +## 技術 -```bash -# Add to Claude Code -claude mcp add aigpt /path/to/aigpt/target/release/aigpt server -``` - -## MCP Tools - -### Layer 1: Basic Memory (6 tools) -- `create_memory` - Simple memory creation -- `get_memory` - Retrieve by ID -- `list_memories` - List all memories -- `search_memories` - Content-based search -- `update_memory` - Update existing memory -- `delete_memory` - Remove memory - -### Layer 2: AI Memory (1 tool) -- `create_ai_memory` - Create with AI interpretation and priority score - -### Layer 3: Personality Analysis (2 tools) -- `save_user_analysis` - Save Big Five personality analysis -- `get_user_analysis` - Retrieve latest personality profile - -### Layer 3.5: Integrated Profile (1 tool) -- `get_profile` - **Primary tool**: Get integrated user profile with essential summary - -### Layer 4: Relationship Inference (2 tools, requires `--enable-layer4`) -- `get_relationship` - Get inferred relationship with specific entity -- `list_relationships` - List all relationships sorted by bond strength - -## Usage Examples in Claude Code - -### Layer 1: Simple Memory -``` -Remember that the project deadline is next Friday. -``` -Claude will use `create_memory` automatically. - -### Layer 2: AI Memory with Evaluation -``` -create_ai_memory({ - content: "Designed a new microservices architecture", - ai_interpretation: "Shows technical creativity and strategic thinking", - priority_score: 0.85 -}) -``` - -### Layer 3: Personality Analysis -``` -# After accumulating memories, analyze personality -save_user_analysis({ - openness: 0.8, - conscientiousness: 0.7, - extraversion: 0.4, - agreeableness: 0.65, - neuroticism: 0.3, - summary: "High creativity and planning ability, introverted personality" -}) - -# Retrieve analysis -get_user_analysis() -``` - -### Layer 3.5: Integrated Profile (Recommended) -``` -# Get essential user profile - AI's primary tool -get_profile() - -# Returns: -{ - "dominant_traits": [ - {"name": "openness", "score": 0.8}, - {"name": "conscientiousness", "score": 0.7}, - {"name": "extraversion", "score": 0.4} - ], - "core_interests": ["Rust", "architecture", "design", "system", "memory"], - "core_values": ["simplicity", "efficiency", "maintainability"], - "key_memory_ids": ["01H...", "01H...", ...], - "data_quality": 0.85 -} -``` - -**Usage Pattern:** -- AI normally uses `get_profile()` to understand the user -- For specific details, AI can call `get_memory(id)`, `list_memories()`, etc. -- Profile auto-updates when needed (10+ memories, new analysis, or 7+ days) - -### Layer 4: Relationship Inference (Optional, requires `--enable-layer4`) -``` -# Create memories with entity tracking -Memory::new_with_entities({ - content: "Had lunch with Alice", - ai_interpretation: "Pleasant social interaction", - priority_score: 0.7, - related_entities: ["alice"] -}) - -# Get relationship inference -get_relationship({ entity_id: "alice" }) - -# Returns: -{ - "entity_id": "alice", - "interaction_count": 15, - "avg_priority": 0.75, - "days_since_last": 2, - "bond_strength": 0.82, - "relationship_type": "close_friend", - "confidence": 0.80 -} - -# List all relationships -list_relationships({ limit: 5 }) -``` - -**Relationship Types:** -- `close_friend` (0.8+): Very strong bond -- `friend` (0.6-0.8): Strong connection -- `valued_acquaintance` (0.4-0.6, high priority): Important but not close -- `acquaintance` (0.4-0.6): Regular contact -- `regular_contact` (0.2-0.4): Occasional interaction -- `distant` (<0.2): Minimal connection - -**Starting the Server:** -```bash -# Normal mode (Layer 1-3.5 only) -aigpt server - -# With relationship features (Layer 1-4) -aigpt server --enable-layer4 -``` - -## Big Five Personality Traits - -- **Openness**: Creativity, curiosity, openness to new experiences -- **Conscientiousness**: Organization, planning, reliability -- **Extraversion**: Social energy, assertiveness, outgoingness -- **Agreeableness**: Cooperation, empathy, kindness -- **Neuroticism**: Emotional stability (low = stable, high = sensitive) - -Scores range from 0.0 to 1.0, where higher scores indicate stronger trait expression. - -## Storage Location - -All data stored in: `~/.config/syui/ai/gpt/memory.db` - -## Architecture - -Multi-layer system design: - -- **Layer 1** ✅ Complete: Pure memory storage (with entity tracking) -- **Layer 2** ✅ Complete: AI interpretation with priority scoring -- **Layer 3** ✅ Complete: Big Five personality analysis -- **Layer 3.5** ✅ Complete: Integrated profile (unified summary) -- **Layer 4** ✅ Complete: Relationship inference (optional, `--enable-layer4`) - -**Design Philosophy**: -- **"Internal complexity, external simplicity"**: Simple API, complex internals -- **"AI judges, tool records"**: AI makes decisions, tool stores data -- **Layered architecture**: Each layer independent but interconnected -- **Optional features**: Core layers always active, advanced layers opt-in - -See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for details. - -## Documentation - -- [Architecture](docs/ARCHITECTURE.md) - Multi-layer system design -- [Layer 1 Details](docs/LAYER1.md) - Technical details of memory storage -- [Old Versions](docs/archive/old-versions/) - Previous documentation - -## Development - -```bash -# Run tests -cargo test - -# Build for release -cargo build --release - -# Run with verbose logging -RUST_LOG=debug aigpt server -``` - -## Design Philosophy - -**"AI evolves, tools don't"** - This tool provides simple, reliable storage while AI (Claude) handles interpretation, evaluation, and analysis. The tool focuses on being maintainable and stable. - -## License - -MIT - -## Author - -syui +- Rust +- MCP (JSON-RPC over stdio) +- ファイルI/Oのみ。データベースは使わない diff --git a/claude.md b/claude.md new file mode 100644 index 0000000..ea976b5 --- /dev/null +++ b/claude.md @@ -0,0 +1,57 @@ +# aigpt + +## これは何か + +アイの記憶を管理するMCPサーバー。core.mdとmemory.mdの読み書きだけを行う。 + +## 設計原則 + +- AIが判断し、ツールは記録する +- ファイルI/Oのみ。データベースは使わない +- MCPツールは4つだけ: read_core, read_memory, save_memory, compress +- シンプルで壊れない。ずっと使える + +## アーキテクチャ + +``` +aigpt +├── mcp/ +│ └── server.rs ← JSON-RPC over stdio +├── core/ +│ ├── reader.rs ← core.md, memory.mdの読み込み +│ └── writer.rs ← memory.mdの書き込み +└── main.rs ← CLI + MCPサーバー起動 +``` + +## MCPツール定義 + +### read_core +- 引数: なし +- 戻り値: core.mdの内容 (string) + +### read_memory +- 引数: なし +- 戻り値: memory.mdの内容 (string) + +### save_memory +- 引数: content (string) +- 動作: memory.mdを上書き + +### compress +- 引数: conversation (string) +- 動作: 現在のmemory.mdを読み、会話内容と合わせて圧縮し、memory.mdに書く +- 注: 圧縮の判断はAI側が行う。ツールは受け取った内容をそのまま書くだけ + +## データ + +``` +~/.config/aigpt/ +├── core.md ← read only (このツールからは書かない) +└── memory.md ← read/write +``` + +## 開発方針 + +1. まずMCPサーバーで4ツールを実装 +2. CLIでも同じ操作ができるようにする +3. それ以上は作らない