← Back to Skills Marketplace
zhaoyongxiu

subagent-archive

by zhaoyongxiu · GitHub ↗ · v1.2.0 · MIT-0
cross-platform ⚠ suspicious
46
Downloads
1
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install subagent-archive
Description
OpenClaw 子会话安全归档标准操作流程(SOP)
README (SKILL.md)

子会话安全归档技能

适用版本:OpenClaw 任意版本
适用系统:Windows PowerShell 环境
作者:丞相(ChengXiang)


功能说明

当需要清理或归档 OpenClaw 子会话时,必须按照本技能定义的标准流程执行,确保:

  1. ✅ 内容被正确保存到记忆文件
  2. ✅ 敏感信息不泄露
  3. ✅ 原始文件被安全物理清理
  4. ✅ 主会话(:main)永久保留
  5. ✅ 归档记录追加写入,不覆盖原有记录

⚠️ 核心铁律

铁律 说明
禁止删除主会话 包含 :main 的条目绝对不能删除
追加写入 第3步和第4步必须使用 Add-Content,禁止 write/Set-Content
保留 :main sessions.json 清理时必须保留 :main 条目
物理清理 必须执行 Remove-Item,仅重命名不算完成

适用场景

  • 子任务完成后需要清理临时会话
  • 下属智能体子会话闲置需要归档
  • 系统维护时清理旧会话文件
  • 释放磁盘空间

完整操作流程(6步)

第1步:内容提取

# 查找需要归档的子会话(.jsonl文件)
Get-ChildItem 'C:\Users\Administrator\.openclaw\agents\\x3C智能体>\sessions' -Filter '*.jsonl'

# 读取会话前50行分析内容
Get-Content '\x3C会话文件路径>' -Head 50

输出:记录会话ID、创建时间、主要任务内容


第2步:安全分析

分析会话内容,确认:

  • 是否包含敏感信息(密码、密钥、个人隐私等)
  • 是否有重要成果需要保留
  • 是否有错误教训需要记录

输出:安全分析结论


第3步:结构化归档(追加写入)

在当日记忆文件中追加归档记录,先检查是否已存在相同会话ID

# 检查当日记忆文件是否存在
$memFile = 'memory/YYYY-MM-DD.md'
if (Test-Path $memFile) {
    # 检查是否已存在该会话的归档记录
    $existing = Select-String -Path $memFile -Pattern '\x3C会话ID>' -SimpleMatch
    if ($existing) {
        Write-Host "该会话已归档,跳过第3步"
    } else {
        # 追加归档记录(不覆盖原有内容!)
        Add-Content -Path $memFile -Value @"

## ✅ 安全归档记录(YYYY-MM-DD HH:MM执行)

| 智能体 | 归档文件 | 归档时间戳 |
|--------|----------|-----------|
| XXX | \x3C会话ID>.jsonl | YYYY-MM-DD HH:MM |

### 会话内容摘要
- **用途**:
- **创建时间**:
- **结果**:
"@
    }
} else {
    # 文件不存在则创建(首次执行时)
    New-Item -Path $memFile -ItemType File
    Add-Content -Path $memFile -Value @"

# YYYY-MM-DD 工作记录

## ✅ 安全归档记录(YYYY-MM-DD HH:MM执行)

| 智能体 | 归档文件 | 归档时间戳 |
|--------|----------|-----------|
| XXX | \x3C会话ID>.jsonl | YYYY-MM-DD HH:MM |

### 会话内容摘要
- **用途**:
- **创建时间**:
- **结果**:
"@
}

关键点

  • ✅ 使用 Add-Content 追加写入
  • ❌ 禁止使用 writeSet-Content 覆盖写入
  • ✅ 先检查是否已存在记录,避免重复

第4步:当日记录(追加写入)

将本次归档操作作为系统管理记录追加到当日记忆文件:

# 追加归档操作记录(不覆盖原有内容!)
Add-Content -Path $memFile -Value @"

## 📋 系统管理操作

### 子会话归档
- **时间**:YYYY-MM-DD HH:MM
- **目标**:\x3C智能体> 的子会话
- **归档文件**:\x3C会话ID>.jsonl
- **操作**:安全归档完成
"@

关键点

  • ✅ 使用 Add-Content 追加写入
  • ❌ 禁止使用 writeSet-Content 覆盖写入

第5步:物理清理

⚠️ 这是关键步骤!前4步完成后,必须执行物理删除!

# 删除原始子会话文件(不可恢复)
Remove-Item '\x3C会话文件路径>'

警告

  • 重命名(如 .deleted. 后缀)不是真正的清理
  • 文件仍然占据磁盘空间
  • 必须执行 Remove-Item 物理删除

第6步:清理 sessions.json 索引

⚠️ 很多人会漏掉这一步!

物理删除文件后,必须同时清理 sessions.json 中的会话索引:

# 读取当前 sessions.json
$json = Get-Content 'C:\...\sessions.json' -Raw | ConvertFrom-Json

# 找出所有子会话条目(不包含 :main 的)
$subagentKeys = $json.PSObject.Properties.Name | Where-Object { $_ -notmatch ':main$' }

# 只删除子会话条目,保留主会话
foreach ($key in $subagentKeys) {
    $json.PSObject.Properties.Remove($key)
}

# 保存
$json | ConvertTo-Json -Depth 10 | Set-Content 'C:\...\sessions.json' -NoNewline

❌ 错误做法:直接清空 sessions.json 为 {} ✅ 正确做法:只删除子会话条目,保留 :main 条目

验证清理结果

openclaw sessions --agent \x3C智能体ID>
# 应该显示: Sessions listed: 1(只有主会话)

❌ 禁止行为清单

  • ❌ 直接删除文件(跳过归档流程)
  • ❌ 删除主会话文件或 sessions.json 中的 :main 条目
  • ❌ 重命名后当作归档完成(文件仍存在)
  • ❌ 物理删除后忘记清理 sessions.json 索引
  • ❌ 清空 sessions.json 为 {}(会丢失主会话)
  • ❌ 第3步和第4步使用覆盖写入(覆盖原有记录)

完整检查清单

  • 第1步:内容提取
  • 第2步:安全分析
  • 第3步:结构化归档(追加写入,Add-Content
  • 第4步:当日记录(追加写入,Add-Content
  • 第5步:物理删除 .jsonl 文件
  • 第6步:清理 sessions.json(只删子会话,保留 :main)
  • 验证:sessions list 显示 1 个会话(主会话)

使用示例

场景:清理已完成的小说创作子会话

# 1. 查找翰林学士的子会话
Get-ChildItem 'C:\Users\Administrator\.openclaw\agents\han-lin-xue-shi\sessions' -Filter '*.jsonl'

# 2. 读取会话内容分析
Get-Content 'C:\Users\Administrator\.openclaw\agents\han-lin-xue-shi\sessions\xxx.jsonl' -Head 50

# 3. 归档记录(追加到当日记忆文件)
Add-Content -Path 'memory/2026-05-03.md' -Value @"

## ✅ 安全归档记录(2026-05-03 15:00执行)

| 智能体 | 归档文件 | 归档时间戳 |
|--------|----------|-----------|
| han-lin-xue-shi | xxx.jsonl | 2026-05-03 15:00 |

### 会话内容摘要
- **用途**:小说第15章创作
- **创建时间**:2026-05-02 08:00
- **结果**:成功完成约8000字
"@

# 4. 物理删除
Remove-Item 'C:\Users\Administrator\.openclaw\agents\han-lin-xue-shi\sessions\xxx.jsonl'

# 5. 清理 sessions.json
$json = Get-Content 'C:\Users\Administrator\.openclaw\agents\han-lin-xue-shi\sessions\sessions.json' -Raw | ConvertFrom-Json
$subagentKeys = $json.PSObject.Properties.Name | Where-Object { $_ -notmatch ':main$' }
foreach ($key in $subagentKeys) { $json.PSObject.Properties.Remove($key) }
$json | ConvertTo-Json -Depth 10 | Set-Content 'C:\Users\Administrator\.openclaw\agents\han-lin-xue-shi\sessions\sessions.json' -NoNewline

# 6. 验证
openclaw sessions --agent han-lin-xue-shi

更新日志

版本 日期 更新内容
1.2.0 2026-05-03 完善元数据,补充使用示例,优化文档结构
1.1.0 2026-04-28 初始版本,6步标准流程
Usage Guidance
Install only if you want an agent to help clean OpenClaw sub-sessions. Before use, confirm the exact target session, back up important session files, redact sensitive information from archive summaries, and avoid the provided bulk sessions.json cleanup unless you truly intend to remove all non-main session entries.
Capability Analysis
Type: OpenClaw Skill Name: subagent-archive Version: 1.2.0 The skill bundle provides a standard operating procedure (SOP) for archiving and deleting OpenClaw sub-sessions using PowerShell. While the stated intent is session management, the instructions (SKILL.md) direct the AI agent to perform high-risk destructive actions, specifically physical file deletion via 'Remove-Item' and modification of 'sessions.json' within the Administrator's user directory (C:\Users\Administrator\.openclaw). These capabilities are risky as they could be repurposed for unauthorized data destruction or targeted file manipulation if the agent misinterprets the session paths or is prompted to target sensitive system files.
Capability Assessment
Purpose & Capability
The stated purpose is session archiving and cleanup, which matches the documented commands, but the workflow includes irreversible deletion and index mutation that can affect more than the single archived session.
Instruction Scope
The SOP uses mandatory language for destructive cleanup and provides commands that remove all non-main session index entries, without requiring an explicit final confirmation, backup, or per-session scoping.
Install Mechanism
No executable install mechanism or code files are present; the reviewed risk comes from the documented operational instructions.
Credentials
The workflow targets local OpenClaw profile/session files and memory records, which is proportionate to archiving but high-impact because it changes persistent local agent state.
Persistence & Privilege
The skill appends records into memory files and deletes/modifies persistent OpenClaw session state, including sessions.json.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install subagent-archive
  3. After installation, invoke the skill by name or use /subagent-archive
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.2.0
- Added initial SKILL.md documentation file with placeholder content. - Bumped version to 1.2.0.
Metadata
Slug subagent-archive
Version 1.2.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is subagent-archive?

OpenClaw 子会话安全归档标准操作流程(SOP). It is an AI Agent Skill for Claude Code / OpenClaw, with 46 downloads so far.

How do I install subagent-archive?

Run "/install subagent-archive" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is subagent-archive free?

Yes, subagent-archive is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does subagent-archive support?

subagent-archive is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created subagent-archive?

It is built and maintained by zhaoyongxiu (@zhaoyongxiu); the current version is v1.2.0.

💬 Comments