tplove2010

MemoryMesh ๐Ÿง 

No description provided

tplove2010 1 Updated 1mo ago

Resources

8
GitHub

Install

npx skillscat add tplove2010/memorymesh

Install via the SkillsCat registry.

SKILL.md
---
name: memorymesh
description: A lightweight, token-efficient hierarchical memory system for AI agents. Manages session context, daily logs, and long-term memory with local-first processing, semantic indexing, and minimal AI model dependency. Use when agents need persistent memory across sessions, task tracking, decision logging, or user preference storage. Supports automatic memory compaction, versioned upgrades, and cross-agent skill reuse.
---

# MemoryMesh ๐Ÿง 

**Version**: 2.0.2  
**Codename**: "Echo"  
**Architecture**: Hierarchical Local-First Memory System

## What's New in v2.0.2

### ๐Ÿ”ง Bug Fixes
- **Chinese Search Support**: Fixed `mm_query.py --local` to properly handle Chinese queries
  - Added UTF-8 encoding for all file read operations (`encoding='utf-8'`)
  - Added support for Chinese date keywords: "ไปŠๆ—ฅ", "ไปŠๅคฉ", "today"
  - Added Chinese keyword extraction in semantic search (2+ character words)
  - Enhanced error messages with file-specific warnings
  - Improved match type reporting (date match vs content match)

## What's New in v2.0.1

### ๐Ÿ”’ Security Improvements
- **Content Length Limit**: Max 100KB per entry (DoS protection)
- **File Size Limit**: Max 10MB per file (storage protection)
- **Filename Whitelist**: Only allow `tasks.md`, `decisions.md`, `facts.md`, `preferences.md`
- **Sensitive Data Filtering**: Auto-filter passwords, API keys, secrets, tokens, credit cards
  - `password: xxx` โ†’ `[FILTERED_PASSWORD]`
  - `api_key: xxx` โ†’ `[FILTERED_API_KEY]`
  - `secret: xxx` โ†’ `[FILTERED_SECRET]`
  - `token: xxx` โ†’ `[FILTERED_TOKEN]`
  - Credit cards โ†’ `[FILTERED_CARD]`
  - OpenAI keys โ†’ `[FILTERED_SK_KEY]`

### ๐Ÿ› Bug Fixes
- Fixed missing `get_memory_base()` function in `mm_write.py`
- Removed unused `subprocess` import from `mm_query.py`
- Added proper error handling with return codes

## System Overview

MemoryMesh is a three-tier memory architecture designed for token efficiency and local processing priority. It minimizes AI model calls by using deterministic scripts for memory operations.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ TIER 3: Session Cache (Hot) โ”‚
โ”‚ - Active conversation context (~64k tokens) โ”‚
โ”‚ - Runtime-only, volatile โ”‚
โ”‚ - Auto-hydrated from daily logs on session start โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ TIER 2: Daily Chronicle (Warm) โ”‚
โ”‚ - memory/chronicle/YYYY-MM-DD.md โ”‚
โ”‚ - 30-day sliding window, auto-compacted โ”‚
โ”‚ - Structured entries with metadata โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ TIER 1: Core Archive (Cold) โ”‚
โ”‚ - memory/core/ENTITY.md (tasks, decisions, facts) โ”‚
โ”‚ - Indefinite retention, manual curation โ”‚
โ”‚ - Semantic index for fast retrieval โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


## When to Use This Skill

Use MemoryMesh when you need to:
- Persist conversation context across session restarts
- Track tasks, decisions, and user preferences
- Query historical information from previous sessions
- Maintain a searchable knowledge base
- Share memory system across multiple agents

## Quick Start

### 1. Initialize MemoryMesh

```bash
# Run initialization (one-time setup)
python ~/.openclaw/skills/memorymesh/scripts/mm_init.py

# This creates:
# ~/.openclaw/workspace/memory/
# โ”œโ”€โ”€ chronicle/          # Daily logs
# โ”œโ”€โ”€ core/               # Long-term archive
# โ”‚   โ”œโ”€โ”€ tasks.md
# โ”‚   โ”œโ”€โ”€ decisions.md
# โ”‚   โ”œโ”€โ”€ facts.md
# โ”‚   โ””โ”€โ”€ entities/       # Per-entity files
# โ””โ”€โ”€ index/              # Semantic indices
#     โ”œโ”€โ”€ keywords.json
#     โ””โ”€โ”€ vectors/        # Optional vector cache

2. Write Memory (Deterministic Script)

# Add to daily chronicle
python scripts/mm_write.py \
  --tier chronicle \
  --content "User asked about Shenzhen high school entrance exam" \
  --tags "education,shenzhen,exam"

# Add to core archive
python scripts/mm_write.py \
  --tier core \
  --file tasks.md \
  --content "Task-20260412-001: Research Shenzhen exam policies" \
  --priority high

3. Query Memory (Local-First)

# Local grep search (no AI, instant)
python scripts/mm_query.py --local "shenzhen exam"

# Semantic search (uses embeddings only for core archive)
python scripts/mm_query.py --semantic "education policies" --limit 10

Architecture Deep Dive

Tier 3: Session Cache

Purpose: Maintain conversation continuity within a session

Implementation:

  • Stored in runtime memory (not persisted)
  • Hydrated from today's chronicle on session start
  • Auto-summarized when exceeding token budget

Access Pattern:

# On session start, agent loads:
1. memory/core/tasks.md (active tasks)
2. memory/chronicle/$(date +%Y-%m-%d).md (today's context)

Tier 2: Daily Chronicle

Purpose: Capture session history with structured metadata

Format:

# Chronicle: 2026-04-12

## Entry: 2026-04-12T18:07:00+08:00
**Type**: conversation
**Tags**: shenzhen, education, exam
**Session**: 9494e22b-6c57-4a9b-acb5-7d5f088adc16

**Summary**: User asked about Shenzhen high school entrance exam policies.
Agent explained memory system limitations and offered to help.

**Key Points**:
- Topic: Shenzhen zhongkao (ไธญ่€ƒ)
- User expectation: Memory of previous discussion
- Issue identified: Cross-session memory gap

**Decisions**:
- [ ] Design improved memory system (assigned)

Compaction Rules:

  • Trigger: File size > 50KB OR age > 7 days
  • Action: Summarize entries, move details to core archive
  • Preserve: Task states, decisions, unresolved items

Tier 1: Core Archive

Purpose: Long-term storage for high-value information

Files:

File Content Update Frequency
tasks.md Active and completed tasks Per task change
decisions.md Key decisions with rationale Per decision
facts.md Verified facts about user/domain As discovered
entities/*.md Per-entity files (people, projects) As needed

Schema for tasks.md:

## Task Registry

### Active

#### T-20260412-001: Memory System Optimization
**Status**: ๐Ÿ”„ In Progress  
**Priority**: High  
**Created**: 2026-04-12  
**Due**: 2026-04-13  

**Description**: Design and implement token-efficient memory system  
**Acceptance Criteria**:
- [ ] Architecture document
- [ ] Core scripts implemented
- [ ] Skill packaging complete
- [ ] GitHub repository created

**Related**: T-20260327-001 (Polymarket audit)

### Completed

#### T-20260410-001: Example completed task
**Status**: โœ… Done  
**Completed**: 2026-04-10  
**Outcome**: [summary]

Token Efficiency Design

Principle: Local Processing First

Operation Local AI Model Token Savings
Write chronicle โœ… Bash script โŒ ~500 tokens/op
Grep search โœ… ripgrep โŒ ~1000 tokens/query
File listing โœ… ls/find โŒ ~200 tokens
Archive compaction โœ… Python โŒ (summarize only) ~2000 tokens/file
Semantic indexing โœ… Local embeddings โŒ (API only) ~500 tokens/doc

Key Optimizations

  1. Deterministic Scripts: All CRUD operations use local scripts
  2. Lazy Loading: Core archive files loaded on-demand
  3. Semantic Index: Pre-computed keyword index for fast filtering
  4. Incremental Updates: Only changed entries trigger re-indexing
  5. Compression: Old chronicles gzip-compressed after 30 days

Script Reference

All scripts in scripts/ are designed for local execution without AI model calls.

mm_write.py

usage: mm_write.py [-h] --tier {chronicle,core} --content CONTENT
                   [--file FILE] [--tags TAGS] [--priority {low,medium,high}]

Write entry to memory system

options:
  -h, --help            show this help message and exit
  --tier {chronicle,core}
                        Target memory tier
  --content CONTENT     Entry content (plaintext or markdown)
  --file FILE           Target file for core tier (default: auto)
  --tags TAGS           Comma-separated tags
  --priority {low,medium,high}
                        Entry priority (core tier only)

mm_query.py

usage: mm_query.py [-h] [--local QUERY] [--semantic QUERY] [--limit N]
                   [--since DATE] [--tags TAGS]

Query memory system

options:
  -h, --help            show this help message and exit
  --local QUERY         Local grep search (fast, no tokens)
  --semantic QUERY      Semantic search (uses embeddings)
  --limit N             Max results (default: 10)
  --since DATE          Filter entries after date (YYYY-MM-DD)
  --tags TAGS           Filter by tags (comma-separated)

mm_compact.py

usage: mm_compact.py [-h] [--dry-run] [--force]

Compact old chronicles and archive completed tasks

options:
  -h, --help   show this help message and exit
  --dry-run    Preview changes without applying
  --force      Skip confirmation prompts

mm_migrate.py

usage: mm_migrate.py [-h] --from-version VERSION --to-version VERSION

Migrate memory schema between versions

options:
  -h, --help           show this help message and exit
  --from-version VERSION
                       Current schema version
  --to-version VERSION
                       Target schema version

Integration with Agents

For Skill Users (Other Agents)

When an agent uses MemoryMesh:

  1. On Session Start:

    # Auto-loaded by OpenClaw AGENTS.md rules
    # No action needed - context hydrated automatically
  2. During Conversation:

    # To remember something important:
    exec("python ~/.openclaw/skills/memorymesh/scripts/mm_write.py \
          --tier core --file facts.md \
          --content 'User prefers concise answers'")
  3. To Recall Information:

    # Local search (preferred):
    result = exec("python scripts/mm_query.py --local 'shenzhen exam'")
    
    # If no results, try semantic:
    result = exec("python scripts/mm_query.py --semantic 'education'")

For Memory System Developers

To extend MemoryMesh:

  1. Add New Core Files: Create in memory/core/ following existing schema
  2. Custom Scripts: Add to scripts/ with mm_ prefix
  3. Schema Migrations: Use mm_migrate.py pattern for upgrades
  4. Version Bumping: Update version in:
    • SKILL.md frontmatter
    • scripts/mm_version.py
    • Git tag

Version History

Version Codename Date Changes
2.0.2 Echo 2026-04-12 Chinese search fix, UTF-8 encoding, Chinese date keywords
2.0.1 Echo 2026-04-12 Security enhancement, content limits, sensitive data filtering
2.0.0 Echo 2026-04-12 Complete rewrite, local-first architecture, skill packaging
1.0.0 Genesis 2026-03-28 Initial memory system (flat structure)

Migration from Legacy System

If upgrading from MemoryMesh 1.x:

# Run migration script
python scripts/mm_migrate.py --from-version 1.0.0 --to-version 2.0.0

# This will:
# 1. Backup existing memory/ to memory/.backup-v1/
# 2. Create new directory structure
# 3. Migrate MEMORY.md โ†’ core/tasks.md, core/decisions.md
# 4. Migrate memory/*.md โ†’ chronicle/
# 5. Generate semantic index

GitHub Repository Structure

memorymesh/
โ”œโ”€โ”€ README.md              # User-facing documentation
โ”œโ”€โ”€ LICENSE                # MIT License
โ”œโ”€โ”€ SKILL.md               # This file (for OpenClaw)
โ”œโ”€โ”€ CHANGELOG.md           # Version history
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ mm_init.py
โ”‚   โ”œโ”€โ”€ mm_write.py
โ”‚   โ”œโ”€โ”€ mm_query.py
โ”‚   โ”œโ”€โ”€ mm_compact.py
โ”‚   โ”œโ”€โ”€ mm_migrate.py
โ”‚   โ””โ”€โ”€ mm_version.py
โ”œโ”€โ”€ references/
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md    # Detailed technical spec
โ”‚   โ”œโ”€โ”€ API.md             # Script API reference
โ”‚   โ””โ”€โ”€ SCHEMA.md          # Data schemas
โ””โ”€โ”€ examples/
    โ””โ”€โ”€ demo_session.md    # Example memory files

License

MIT License - See LICENSE file for details.


**ๆ“ไฝœๆญฅ้ชค**๏ผš
1. ่ฎฟ้—ฎ https://github.com/tplove2010/memorymesh/edit/main/SKILL.md
2. ๅ…จ้€‰ๅ†…ๅฎน๏ผŒ็ฒ˜่ดดไธŠ้ข็š„ๅฎŒๆ•ดๅ†…ๅฎน
3. ๆไบคๆ›ดๆ”น๏ผŒCommit message: `docs: Update SKILL.md to v2.0.2`