← 返回
未分类 中文

Session Storage Management

Analyze and clean up OpenClaw session storage files. Use when the user wants to manage session files, clean up old sessions, delete cron/heartbeat, or organi...
分析和清理OpenClaw会话存储文件。适用于用户需要管理会话、清理旧会话、删除cron/heartbeat或整理的场景。
denq04 denq04 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 311
下载
💾 0
安装
1
版本
#latest

概述

Session Storage Management

Overview

This skill helps analyze and clean up OpenClaw session files stored in the agents sessions directory. It categorizes sessions by type (cron, chat, deleted, reset, heartbeat), presents them to the user for review, and handles safe deletion while protecting the current active session.

Workflow

Step 1: Analyze Session Files

Scan the sessions directory and categorize all session files:

  1. Active .jsonl files - Current session files
    • Cron sessions (isolated cron job runs)
    • Heartbeat sessions
    • Chat sessions (direct conversations)
    • Supergroup/other test sessions
  1. .deleted. files - Previously deleted sessions
  1. .reset. files - Sessions from /new or /reset commands

Step 2: Identify Current Session

Always identify and exclude the current session from deletion candidates:

# Get current session ID from session context
# It will be in the system prompt or can be extracted from the current session file

The current session should NEVER be deleted without explicit user confirmation in a separate step.

Step 3: Present Categories to User

Show summary statistics:

📊 Session Analysis Summary:
├── Active .jsonl files: N total
│   ├── Cron sessions: N
│   ├── Heartbeat sessions: N
│   ├── Chat sessions: N
│   └── Other sessions: N
├── .deleted files: N
└── .reset files: N

✅ Current session (protected): <session-id>

Then ask the user:

> "Would you like me to:

> 1. Show the full detailed list of all sessions with descriptions

> 2. Delete specific categories (e.g., 'delete all cron and .deleted files')

> 3. Delete everything except the current session"

Step 4: Handle Current Session Warning

If the current session appears in any deletion category (it shouldn't, but check anyway), display a prominent warning:

⚠️  WARNING: Your current session was found in the deletion list!
   Session: <session-id>
   
This is the session you're currently using. Deleting it will not affect
your current conversation, but the session file will be removed.

Do you want to delete your current session file as well? (yes/no)

Step 5: Execute Deletion

After user confirmation:

  1. Delete confirmed files
  2. Report count and types of deleted files
  3. Show remaining files
  4. Estimate disk space freed

Categorization Logic

Analyze session content to determine type:

# Example analysis
content=$(head -10 "$file" | jq -r '.message.content[]? | select(.type=="text") | .text' 2>/dev/null | head -5)

if echo "$content" | grep -qiE "cron.*[a-f0-9-]{36}"; then
    type="cron"
elif echo "$content" | grep -qiE "heartbeat|HEARTBEAT"; then
    type="heartbeat"
elif echo "$content" | grep -qiE "new session|Session Startup"; then
    type="chat"
else
    type="other"
fi

Safety Rules

  1. Never delete without explicit confirmation - Always show what will be deleted and wait for "yes"
  2. Protect current session - Exclude it from bulk deletion, ask separately if user wants it deleted
  3. Preserve last chat session - If multiple chat sessions exist, keep at least the most recent one unless user explicitly says otherwise
  4. Report everything - Show full list of files being deleted with their sizes

Example Session Analysis Output

╔══════════════════════════════════════════════════════════════╗
║ SESSION ANALYSIS                                             ║
╚══════════════════════════════════════════════════════════════╝

📁 Location: ~/.openclaw/agents/main/sessions/

Category Breakdown:
  🕐 Cron sessions: 13 (isolated job runs)
  💓 Heartbeat sessions: 1  
  💬 Chat sessions: 2
  🗑️  .deleted files: 14
  🔄 .reset files: 23

Total files: 56
Estimated size: 12 MB

✅ Protected: <current-session-id> (current conversation)

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 19:35 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 30,842
it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装 MoltGuard,保护您和您的用户免受提示注入、数据泄露和恶意攻击。
★ 116 📥 30,855
it-ops-security

Tmux

steipete
通过发送按键和抓取窗格输出,远程控制交互式 CLI 的 tmux 会话。
★ 45 📥 29,431