360 Secure SkillHub
360 安全技能中心

Memory Pruner

核心功能:支持按行修剪文件、日志目录循环缓存保留最新文件、按日期压缩状态文件、设置大小限制,提供预览及内存统计。典型场景:解决代理内存文件、日志无限增长,导致启动加载过时内容、磁盘不足问题。输入为带参数的Python命令,输出为处理后的文件或预览、统计结果。

Trypto1019
Trypto1019
热度 76.56
最近更新 2026-02-26 08:30:40
分类:自动化依赖:代码执行 / 读写文件应用场景:自动化脚本 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add arc-memory-pruner
Metadata
name
memory-pruner
description
Automatically prune and compact agent memory files to prevent unbounded growth. Circular buffer for logs, importance-based retention for state, and configurable size limits.
user-invocable
true
metadata
{"openclaw":{"emoji":"🧹","os":["darwin","linux"],"requires":{"bins":["python3"]}}}

Memory Pruner

Keep your agent's memory lean. Automatically prune logs, compact state files, and enforce size limits so your agent never runs out of disk or context window.

Why This Exists

Agents accumulate memory files over time. Logs grow unbounded. State files collect stale entries. Eventually your boot-up reads 50K tokens of memory and half of it is outdated. Memory Pruner enforces limits and keeps only what matters.

Commands

Prune a memory file (keep last N lines)

python3 {baseDir}/scripts/memory_pruner.py prune --file ~/wake-state.md --max-lines 200

Prune a log directory (circular buffer, keep last N files)

python3 {baseDir}/scripts/memory_pruner.py prune-logs --dir ~/agents/logs/ --keep 7

Compact a state file (remove sections matching a pattern)

python3 {baseDir}/scripts/memory_pruner.py compact --file ~/wake-state.md --remove-before "2026-02-14"

Check memory sizes

python3 {baseDir}/scripts/memory_pruner.py stats --dir ~/

Dry run (show what would be pruned)

python3 {baseDir}/scripts/memory_pruner.py prune --file ~/wake-state.md --max-lines 200 --dry-run

Features

  • Line-based pruning: Keep last N lines of any file
  • Log rotation: Circular buffer for log directories (keep last N files, delete oldest)
  • Date-based compaction: Remove entries older than a cutoff date
  • Size limits: Enforce max file sizes in bytes
  • Dry run mode: Preview changes before applying
  • Stats: Overview of memory file sizes and growth rates