Context Doctor
Diagnose and visualize how the context window budget is allocated.
Quick Start
Run the visualization script:
CODEBLOCK0
The script auto-detects:
- - Workspace path (
~/.openclaw/workspace or OPENCLAW_WORKSPACE env) - OpenClaw version (via
openclaw --version) - Installed skills (system + workspace)
- Bootstrap file sizes and status
Output Sections
1. Workspace Files
Shows each bootstrap file with:
- - Status: ✓ OK / ✗ MISSING / ⚠ TRUNCATED (symlink target missing = MISSING)
- Characters & Tokens: Raw size and estimated token count (chars/4)
- Visual bar: Proportional to file size
2. Installed Skills
Lists all discovered SKILL.md files from system and workspace skill directories.
Skills are loaded on-demand, not in bootstrap — shown for awareness only.
3. Token Budget
Breaks down bootstrap overhead:
- - System Prompt (framework)
- Workspace Files (from scan)
- Skills List (metadata descriptions)
- Tool Schemas + Summaries
Shows total bootstrap % vs free conversation space.
Diagnostic Signals
| Signal | Meaning | Action |
|---|
| 🔴 TRUNCATED | File exceeded max chars, silently cut | Reduce file size or split content |
| 🟡 MISSING |
File not found or broken symlink | Check path, fix symlink target |
| 🟢 Bootstrap <10% | Healthy | No action needed |
| 🟠 Bootstrap >15% | Heavy | Review workspace files for bloat |
Image Output (for chat / sharing)
Generate a PNG image directly — no terminal screenshot needed:
CODEBLOCK1
The script renders a colored terminal-style image via Rich SVG export.
Requires: rich (pip3 install rich) + one of: rsvg-convert (brew install librsvg) or cairosvg (pip3 install cairosvg).
Agent workflow: When a user asks about context health in chat, run with --png and send the image directly. The output path is printed to stdout on success.
上下文医生
诊断并可视化上下文窗口预算的分配情况。
快速开始
运行可视化脚本:
bash
python3 scripts/context-doctor.py
该脚本会自动检测:
- - 工作区路径(~/.openclaw/workspace 或 OPENCLAW_WORKSPACE 环境变量)
- OpenClaw 版本(通过 openclaw --version)
- 已安装的技能(系统 + 工作区)
- 引导文件大小和状态
输出部分
1. 工作区文件
显示每个引导文件及其:
- - 状态:✓ 正常 / ✗ 缺失 / ⚠ 截断(符号链接目标缺失 = 缺失)
- 字符数与令牌数:原始大小和预估令牌数(字符数/4)
- 可视化条:与文件大小成比例
2. 已安装技能
列出从系统和工作区技能目录中发现的所有 SKILL.md 文件。
技能是按需加载的,不在引导文件中——仅作展示参考。
3. 令牌预算
分解引导开销:
- - 系统提示(框架)
- 工作区文件(来自扫描)
- 技能列表(元数据描述)
- 工具架构 + 摘要
显示引导总占比与自由对话空间。
诊断信号
| 信号 | 含义 | 操作 |
|---|
| 🔴 截断 | 文件超出最大字符数,被静默截断 | 减小文件大小或拆分内容 |
| 🟡 缺失 |
文件未找到或符号链接损坏 | 检查路径,修复符号链接目标 |
| 🟢 引导 <10% | 健康 | 无需操作 |
| 🟠 引导 >15% | 过重 | 检查工作区文件是否存在臃肿 |
图像输出(用于聊天/分享)
直接生成 PNG 图像——无需终端截图:
bash
python3 scripts/context-doctor.py --png /tmp/context-doctor.png
该脚本通过 Rich SVG 导出渲染彩色终端风格图像。
需要:rich(pip3 install rich)+ 以下之一:rsvg-convert(brew install librsvg)或 cairosvg(pip3 install cairosvg)。
智能体工作流:当用户在聊天中询问上下文健康状况时,使用 --png 参数运行并将图像直接发送。成功时输出路径会打印到标准输出。