Memory Compression System v3.0
Integrated memory management and extreme context compression for OpenClaw. Combines the best features of memory management and extreme compression into a single, streamlined skill with automatic scheduling.
Quick Start
CODEBLOCK0
Features
1. Integrated Memory Management
- - Automatic compression: Every 6 hours (00:00, 06:00, 12:00, 18:00 UTC)
- Smart cleanup: Daily cleanup of old files
- Search functionality: Unified search across all memory files
- Backup system: Automatic backups before compression
2. Three Compression Formats
- - Base64 Compact (B64C): Universal compatibility, ~40% reduction
- Custom Binary (CBIN): Optimized binary, ~70% reduction
- Ultra Compact (UCMP): Extreme compression, ~85% reduction, target ~150 tokens
3. Automated Scheduling
- - Single cron job: No overlapping schedules
- Configurable: Adjust frequency and timing
- Reliable: Built-in error recovery and logging
- Efficient: Minimal resource usage
4. Search & Retrieval
- - Unified search: Across all memory formats
- Fast indexing: Real-time search updates
- Context aware: Understands compressed formats
- Export options: Search results in multiple formats
5. ClawHub Ready
- - Standard structure: Compatible with ClawHub
- Easy installation: One-command setup
- Health checks: Built-in monitoring
- Documentation: Comprehensive guides
Installation
Via ClawHub (Recommended)
CODEBLOCK1
Manual Installation
CODEBLOCK2
Usage
Basic Operations
CODEBLOCK3
Compression Operations
CODEBLOCK4
Search Operations
CODEBLOCK5
Management Operations
CODEBLOCK6
Configuration
Main Configuration File
Edit
config/default.conf:
CODEBLOCK7
Environment Variables
CODEBLOCK8
Compression Formats
Format 1: Base64 Compact (B64C)
CODEBLOCK9
Features:
- - Human readable
- Easy debugging
- Universal compatibility
- CRC32 integrity check
Format 2: Custom Binary (CBIN)
CODEBLOCK10
Features:
- - Optimized binary format
- Shared string dictionary
- Huffman encoding
- CRC16 integrity check
Format 3: Ultra Compact (UCMP)
Target: ~150 tokens for complete context
Features:
- - Extreme compression (~85% reduction)
- 3-letter abbreviations
- Bit packing
- Delta encoding
- String interning
Automatic Scheduling
Compression Schedule
- - Every 6 hours: 00:00, 06:00, 12:00, 18:00 UTC
- Operations:
1. Backup current memory
2. Compress with optimal format
3. Update search index
4. Cleanup old files
5. Log results
Cleanup Schedule
- - Daily at 04:00 UTC
- Operations:
1. Remove files older than RETENTION_DAYS
2. Archive logs
3. Optimize search index
4. Update statistics
Health Check Schedule
- - Integrated with OpenClaw health checks
- Operations:
1. Check compression status
2. Verify file integrity
3. Monitor resource usage
4. Report issues
Search System
Search Index
- - Real-time updates: Index updates after each compression
- Multiple formats: Searches across all compression formats
- Fast retrieval: Optimized for speed
- Context aware: Understands compressed content
Search Features
CODEBLOCK11
Search Index Structure
CODEBLOCK12
Error Handling & Recovery
Automatic Recovery
- - Backup system: Automatic backups before operations
- Transaction logs: All operations logged
- Rollback capability: Automatic rollback on failure
- Error notifications: Alerts for critical issues
Manual Recovery
CODEBLOCK13
Common Issues & Solutions
Issue: Compression fails
Solution: Check disk space and run INLINECODE1
Issue: Search not working
Solution: Rebuild index with INLINECODE2
Issue: Cron job not running
Solution: Check with INLINECODE3
Issue: Performance degradation
Solution: Run INLINECODE4
Monitoring & Logging
Log Files
- -
logs/compression.log: Compression operations - INLINECODE6 : Search operations
- INLINECODE7 : Error messages
- INLINECODE8 : Performance metrics
- INLINECODE9 : Cron job execution
Status Monitoring
CODEBLOCK14
Alert System
- - Email alerts: For critical errors (if configured)
- Telegram notifications: For important events
- Log monitoring: Automatic log analysis
- Performance alerts: For resource issues
Testing
Test Suite
CODEBLOCK15
Test Coverage
- - Unit tests: Format encoding/decoding
- Integration tests: Full system integration
- Performance tests: Speed and memory usage
- Error tests: Failure scenarios
- Cron tests: Automatic scheduling
Manual Testing
CODEBLOCK16
Performance
Compression Performance
- - Base64: < 50ms for 10KB
- Binary: < 100ms for 10KB
- Ultra: < 200ms for 10KB
- Target ratio: 75-90% reduction
Search Performance
- - Indexing: < 100ms per file
- Search: < 50ms for 1000 files
- Memory: < 10MB for index
- Updates: Real-time
Resource Usage
- - CPU: Minimal impact
- Memory: < 50MB peak
- Disk: Configurable retention
- Network: Local only
Updates & Maintenance
Update Procedure
CODEBLOCK17
Backup Recommendations
- - Regular backups: Weekly backups of
data/ directory - Export search index: Monthly export of search index
- Archive logs: Monthly log archiving
- Configuration backup: Backup
config/ after changes
Version History
- - 3.0.0: Integrated memory-compression-system (current)
- 2.0.0: Extreme context compression skill
- 1.0.0: Memory manager skill
Contributing
Development Setup
CODEBLOCK18
Code Standards
- - Bash scripts: Follow Google Bash Style Guide
- JavaScript: Follow Standard JS style
- Documentation: Keep SKILL.md updated
- Testing: Add tests for new features
Pull Request Process
- 1. Fork the repository
- Create feature branch
- Add tests for new functionality
- Update documentation
- Submit pull request
Support
Documentation
- - SKILL.md: This file
- README.md: User documentation
- examples/: Usage examples
- test/: Test examples
Troubleshooting
- 1. Check
logs/ directory - Run INLINECODE13
- Review INLINECODE14
- Contact maintainer if needed
Community
- - ClawHub: Skill repository
- Discord: OpenClaw community
- GitHub: Issue tracker
- Documentation: OpenClaw docs
License
MIT License - See LICENSE file for details.
Note: This skill is designed for OpenClaw context optimization. Always maintain backups of important data and test in a safe environment before production use.
记忆压缩系统 v3.0
集成记忆管理与极致上下文压缩,专为OpenClaw设计。将记忆管理与极致压缩的最佳功能整合为一个精简、自动调度的单一技能。
快速开始
bash
安装技能
openclaw skill install memory-compression-system
启用自动压缩(每6小时运行一次)
scripts/enable.sh
检查状态
scripts/status.sh
手动压缩
scripts/compress.sh --format ultra
搜索记忆
scripts/search.sh 关键词
功能特性
1. 集成记忆管理
- - 自动压缩:每6小时一次(UTC时间00:00、06:00、12:00、18:00)
- 智能清理:每日清理旧文件
- 搜索功能:跨所有记忆文件的统一搜索
- 备份系统:压缩前自动备份
2. 三种压缩格式
- - Base64紧凑格式(B64C):通用兼容性,约40%压缩率
- 自定义二进制格式(CBIN):优化二进制,约70%压缩率
- 超紧凑格式(UCMP):极致压缩,约85%压缩率,目标约150个token
3. 自动调度
- - 单一cron任务:无重叠调度
- 可配置:调整频率和时间
- 可靠:内置错误恢复和日志记录
- 高效:资源占用最小化
4. 搜索与检索
- - 统一搜索:跨所有记忆格式
- 快速索引:实时搜索更新
- 上下文感知:理解压缩格式
- 导出选项:多种格式的搜索结果
5. ClawHub就绪
- - 标准结构:兼容ClawHub
- 简易安装:一键设置
- 健康检查:内置监控
- 文档完善:全面指南
安装
通过ClawHub安装(推荐)
bash
openclaw skill search memory-compression-system
openclaw skill install memory-compression-system
手动安装
bash
cd /home/node/.openclaw/workspace/skills
git clone [仓库地址] memory-compression-system
cd memory-compression-system
scripts/install.sh
使用方法
基本操作
bash
启用自动压缩
scripts/enable.sh
禁用自动压缩
scripts/disable.sh
检查系统状态
scripts/status.sh
运行健康检查
scripts/health.sh
压缩操作
bash
自动选择格式压缩
scripts/compress.sh
压缩为特定格式
scripts/compress.sh --format base64
scripts/compress.sh --format binary
scripts/compress.sh --format ultra
解压文件
scripts/decompress.sh [文件名]
列出压缩文件
scripts/list.sh
搜索操作
bash
跨所有记忆搜索
scripts/search.sh 关键词
带筛选条件的搜索
scripts/search.sh 关键词 --format ultra --date 2026-02-15
导出搜索结果
scripts/search.sh 关键词 --export json
查看搜索历史
scripts/search-history.sh
管理操作
bash
清理旧文件
scripts/cleanup.sh --days 30
备份系统
scripts/backup.sh
从备份恢复
scripts/restore.sh [备份文件]
查看日志
scripts/logs.sh
性能指标
scripts/metrics.sh
配置
主配置文件
编辑 config/default.conf:
bash
压缩设置
COMPRESSION_ENABLED=true
DEFAULT_FORMAT=ultra
RETENTION_DAYS=30
MAX
COMPRESSEDFILES=100
Cron调度(UTC时间)
CRON_SCHEDULE=0
/6 # 每6小时
CLEANUP_SCHEDULE=0 4
* # 每日04:00
搜索设置
SEARCH_ENABLED=true
SEARCH
INDEXAUTO_UPDATE=true
SEARCH
HISTORYSIZE=1000
性能设置
MAX
MEMORYMB=100
MAX
PROCESSINGTIME_SEC=300
环境变量
bash
export MEMORY
COMPRESSIONDEBUG=1 # 启用调试模式
export MEMORY
COMPRESSIONQUIET=0 # 禁用静默模式
export MEMORY
COMPRESSIONTEST=0 # 启用测试模式
压缩格式
格式1:Base64紧凑格式(B64C)
VERSION:3.0
FORMAT:B64C
TIMESTAMP:2026-02-15T14:55:00Z
SIZE:1024
CHECKSUM:crc32
DATA:
特性:
- - 人类可读
- 易于调试
- 通用兼容性
- CRC32完整性校验
格式2:自定义二进制格式(CBIN)
[Magic:CBIN][Version:3][Flags:1][Size:4][Dictionary:var][Data:var][Checksum:2]
特性:
- - 优化的二进制格式
- 共享字符串字典
- 霍夫曼编码
- CRC16完整性校验
格式3:超紧凑格式(UCMP)
目标:完整上下文约150个token
特性:
- - 极致压缩(约85%压缩率)
- 3字母缩写
- 位打包
- 增量编码
- 字符串驻留
自动调度
压缩调度
- - 每6小时:UTC时间00:00、06:00、12:00、18:00
- 操作:
1. 备份当前记忆
2. 使用最优格式压缩
3. 更新搜索索引
4. 清理旧文件
5. 记录结果
清理调度
1. 删除超过保留天数的文件
2. 归档日志
3. 优化搜索索引
4. 更新统计信息
健康检查调度
1. 检查压缩状态
2. 验证文件完整性
3. 监控资源使用
4. 报告问题
搜索系统
搜索索引
- - 实时更新:每次压缩后更新索引
- 多种格式:跨所有压缩格式搜索
- 快速检索:针对速度优化
- 上下文感知:理解压缩内容
搜索功能
bash
基本搜索
scripts/search.sh 压缩
高级搜索
scripts/search.sh 压缩比 --format ultra --after 2026-02-01
导出结果
scripts/search.sh 测试 --export csv --output results.csv
搜索历史
scripts/search.sh --history
搜索索引结构
json
{
version: 3.0,
last_updated: 2026-02-15T18:00:00Z,
files: [
{
filename: memory
20260215180000.ultra,
format: ultra,
size: 256,
original_size: 1024,
ratio: 0.25,
keywords: [压缩, 记忆, 测试],
timestamp: 2026-02-15T18:00:00Z
}
]
}
错误处理与恢复
自动恢复
- - 备份系统:操作前自动备份
- 事务日志:所有操作均记录
- 回滚能力:失败时自动回滚
- 错误通知:关键问题警报
手动恢复
bash
检查错误日志
scripts/logs.sh --error
从备份恢复
scripts/restore.sh latest
修复搜索索引
scripts/repair-index.sh
重置系统
scripts/reset.sh --safe
常见问题与解决方案
问题:压缩失败
解决方案:检查磁盘空间并运行 scripts/repair.sh
问题:搜索无法工作
解决方案:使用 scripts/rebuild-index.sh 重建索引
问题:Cron任务未运行
解决方案:使用 scripts/status.sh --cron 检查
问题:性能下降
解决方案:运行 scripts/cleanup.sh --aggressive
监控与日志
日志文件
- - logs/compression.log:压缩操作
- logs/search.log:搜索操作
- logs/error.log:错误信息
- logs/performance.log:性能指标
- logs/cron.log:Cron任务执行
状态监控
bash
基本状态
scripts/status