Swarm Janitor
Enterprise-grade cleanup tool for OpenClaw subagent management.
What It Does
Automatically identifies and cleans up orphaned subagent sessions while preserving important work through SuperMemory archival.
Core Functions
- - Scan: Analyze session directory for orphaned/abandoned subagents
- Archive: Save transcripts to SuperMemory before deletion
- Clean: Safely remove orphaned sessions freeing disk space
- Report: Generate detailed cleanup reports
Safety First
This skill implements multiple safety layers:
- - ✅ Never deletes active sessions — checks process status
- ✅ Dry-run mode — preview changes before executing
- ✅ SuperMemory backup — transcripts archived before deletion
- ✅ Configurable retention — customize age thresholds
- ✅ Detailed logging — full audit trail of all actions
Quick Start
CODEBLOCK0
Installation
- 1. Copy this skill to your OpenClaw workspace:
CODEBLOCK1
- 2. Configure retention policy (optional):
CODEBLOCK2
- 3. Run first scan:
CODEBLOCK3
Usage Patterns
Daily Maintenance (Cron)
CODEBLOCK4
Manual Cleanup
CODEBLOCK5
Emergency Cleanup
CODEBLOCK6
Configuration
See references/config.yaml for:
- - Retention policies
- Archive destinations
- Safety thresholds
- Logging options
How It Works
- 1. Discovery: Scans INLINECODE0
- Analysis: Determines session age, activity status, size
- Classification: Identifies orphaned vs active sessions
- Archival: Saves transcripts to SuperMemory (if enabled)
- Cleanup: Safely removes orphaned session files
- Reporting: Generates summary of actions taken
Safety Mechanisms
| Check | Description |
|---|
| Process Check | Verifies no active process owns the session |
| Age Verification |
Only processes sessions older than threshold |
| Size Limits | Warns on unusually large deletions |
| Dry-Run Default | Preview mode is default — explicit action required |
| Backup First | Archives to SuperMemory before any deletion |
Troubleshooting
Q: It says "permission denied"
A: Ensure you have write access to the sessions directory
Q: Sessions not being detected
A: Check the path in config.yaml matches your OpenClaw installation
Q: SuperMemory archive failing
A: Verify SuperMemory skill is configured with valid API key
Enterprise Features
- - Audit Logging: All actions logged with timestamps
- Configurable Policies: YAML-based configuration
- Metrics Export: JSON/CSV output for monitoring
- Dry-Run Mode: Test changes before applying
- Retention Policies: Age-based and count-based rules
License
MIT - Created by OpenClawdad (Redclay) for the OpenClaw community.
Swarm Janitor
面向OpenClaw子代理管理的企业级清理工具。
功能概述
自动识别并清理孤立子代理会话,同时通过SuperMemory归档保留重要工作。
核心功能
- - 扫描:分析会话目录中的孤立/遗弃子代理
- 归档:删除前将记录保存至SuperMemory
- 清理:安全移除孤立会话以释放磁盘空间
- 报告:生成详细的清理报告
安全优先
本工具实现多层安全机制:
- - ✅ 绝不删除活跃会话 — 检查进程状态
- ✅ 试运行模式 — 执行前预览变更
- ✅ SuperMemory备份 — 删除前归档记录
- ✅ 可配置保留策略 — 自定义时间阈值
- ✅ 详细日志记录 — 完整操作审计追踪
快速开始
bash
预览待清理内容(试运行)
python3 scripts/swarm_janitor.py --dry-run
将旧会话归档至SuperMemory后清理
python3 scripts/swarm_janitor.py --archive --clean
自定义保留期限(7天替代默认3天)
python3 scripts/swarm_janitor.py --retention-days 7 --clean
安装指南
- 1. 将本工具复制到OpenClaw工作区:
bash
cp -r skills/swarm-janitor ~/.openclaw/workspace/skills/
- 2. 配置保留策略(可选):
bash
# 编辑配置文件自定义设置
nano references/config.yaml
- 3. 执行首次扫描:
bash
python3 ~/.openclaw/workspace/skills/swarm-janitor/scripts/swarm_janitor.py --dry-run
使用模式
日常维护(Cron定时任务)
cron
每天凌晨3点运行,归档超过3天的会话
0 3
* python3 ~/.openclaw/workspace/skills/swarm-janitor/scripts/swarm_janitor.py --archive --clean --retention-days 3 >> /var/log/swarm-janitor.log 2>&1
手动清理
bash
查看将被删除的内容
python3 scripts/swarm_janitor.py --dry-run --verbose
将记录归档至SuperMemory
python3 scripts/swarm_janitor.py --archive
不归档直接清理(不推荐)
python3 scripts/swarm_janitor.py --clean --no-archive
生成完整报告
python3 scripts/swarm_janitor.py --report --output json
紧急清理
bash
激进清理,保留期限设为1天
python3 scripts/swarm_janitor.py --clean --retention-days 1 --force
配置说明
详见 references/config.yaml:
工作原理
- 1. 发现:扫描 ~/.openclaw/agents/main/sessions/
- 分析:判断会话时长、活动状态、大小
- 分类:识别孤立会话与活跃会话
- 归档:将记录保存至SuperMemory(如启用)
- 清理:安全移除孤立会话文件
- 报告:生成操作摘要
安全机制
仅处理超过阈值的会话 |
| 大小限制 | 对异常大文件删除发出警告 |
| 默认试运行 | 预览模式为默认设置,需显式确认操作 |
| 先备份后删除 | 删除前先归档至SuperMemory |
故障排除
问:提示权限不足
答:确保您对会话目录拥有写入权限
问:无法检测到会话
答:检查config.yaml中的路径是否与您的OpenClaw安装目录匹配
问:SuperMemory归档失败
答:确认SuperMemory工具已配置有效的API密钥
企业级特性
- - 审计日志:所有操作均记录时间戳
- 可配置策略:基于YAML的配置管理
- 指标导出:支持JSON/CSV格式输出用于监控
- 试运行模式:应用前测试变更效果
- 保留策略:基于时长和数量的规则
许可证
MIT - 由OpenClawdad (Redclay) 为OpenClaw社区创建