---
name: cache-monitor-58325f6f9907
description: 追踪静态层文件 hash，检测 prompt cache 失效。注册为 PreAgentStart 钩子，每次 session 启动时自动运行。有变更时输出警告，无变更静默通过。
---

# Cache Monitor — 静态层 Hash 追踪

## 功能

每次 session 启动时自动检测静态层文件是否变更，帮助追踪哪些操作导致 prompt cache 失效。

## 追踪的文件

| 文件 | 说明 |
|------|------|
| SOUL.md | 角色设定 |
| AGENTS.md | 行为规则 |
| TOOLS.md | 本地配置 |
| USER.md | Boss 信息 |
| IDENTITY.md | 身份元数据 |
| HEARTBEAT.md | 心跳任务 |
| STATIC.md | 核心规则摘要 |

## 状态文件

`~/.openclaw/workspace/.cache-monitor.json`

```json
{
  "last_updated": "2026-04-04T00:10:00",
  "hashes": {
    "SOUL.md": {"hash": "sha256...", "size": 2741, "exists": true},
    "AGENTS.md": {"hash": "sha256...", "size": 12000, "exists": true}
  },
  "change_log": [
    {"date": "2026-04-03", "file": "AGENTS.md", "reason": "追加工具权限分层规则"}
  ]
}
```

## 变更记录格式

有变更时输出：
```
⚠️ Cache 失效：[文件名] 已变更（上次变更原因：[原因]），本次对话静态层需重新计算
```

无变更：静默通过，无任何输出。

## 核心文件

| 文件 | 作用 |
|------|------|
| `scripts/cache_monitor.py` | Hash 计算 + 变更检测 |
| `~/.openclaw/workspace/.cache-monitor.json` | 状态持久化 |

## 命令

```bash
# 初始化/更新 hash 记录
python3 ~/.openclaw/workspace/skills/cache-monitor/scripts/cache_monitor.py --init

# 检查变更（默认）
python3 ~/.openclaw/workspace/skills/cache-monitor/scripts/cache_monitor.py --check
```

## 注册方式

通过 OpenClaw 的 `PreAgentStart` 钩子自动触发，无需手动运行。


---
Source attribution: Ghenghis
Original project: https://github.com/Ghenghis/openclaw-claude-code-integration/blob/c96bed8f902f77d8ef75632000539fb17789a25a/skills/cache-monitor/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 ybbms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: Ghenghis
Original project: https://github.com/Ghenghis/openclaw-claude-code-integration/blob/c96bed8f902f77d8ef75632000539fb17789a25a/skills/cache-monitor/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, DevOps / SRE, ML / AI Engineer
Specialties: Backend
Tools: OpenAI API, Openclaw
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 91bafb60e4e84f2758dcc452c927cf4718952996bd01f1470813d30fc2c0380e
