← 返回 Skills 市场
subagent-archive
作者
zhaoyongxiu
· GitHub ↗
· v1.2.0
· MIT-0
46
总下载
1
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install subagent-archive
功能描述
OpenClaw 子会话安全归档标准操作流程(SOP)
使用说明 (SKILL.md)
子会话安全归档技能
适用版本:OpenClaw 任意版本
适用系统:Windows PowerShell 环境
作者:丞相(ChengXiang)
功能说明
当需要清理或归档 OpenClaw 子会话时,必须按照本技能定义的标准流程执行,确保:
- ✅ 内容被正确保存到记忆文件
- ✅ 敏感信息不泄露
- ✅ 原始文件被安全物理清理
- ✅ 主会话(
:main)永久保留 - ✅ 归档记录追加写入,不覆盖原有记录
⚠️ 核心铁律
| 铁律 | 说明 |
|---|---|
| 禁止删除主会话 | 包含 :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追加写入 - ❌ 禁止使用
write或Set-Content覆盖写入 - ✅ 先检查是否已存在记录,避免重复
第4步:当日记录(追加写入)
将本次归档操作作为系统管理记录追加到当日记忆文件:
# 追加归档操作记录(不覆盖原有内容!)
Add-Content -Path $memFile -Value @"
## 📋 系统管理操作
### 子会话归档
- **时间**:YYYY-MM-DD HH:MM
- **目标**:\x3C智能体> 的子会话
- **归档文件**:\x3C会话ID>.jsonl
- **操作**:安全归档完成
"@
关键点:
- ✅ 使用
Add-Content追加写入 - ❌ 禁止使用
write或Set-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步标准流程 |
安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install subagent-archive - 安装完成后,直接呼叫该 Skill 的名称或使用
/subagent-archive触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.2.0
- Added initial SKILL.md documentation file with placeholder content.
- Bumped version to 1.2.0.
元数据
常见问题
subagent-archive 是什么?
OpenClaw 子会话安全归档标准操作流程(SOP). 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 46 次。
如何安装 subagent-archive?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install subagent-archive」即可一键安装,无需额外配置。
subagent-archive 是免费的吗?
是的,subagent-archive 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
subagent-archive 支持哪些平台?
subagent-archive 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 subagent-archive?
由 zhaoyongxiu(@zhaoyongxiu)开发并维护,当前版本 v1.2.0。
推荐 Skills