用途
caveman-compress 用于把自然语言文件(如 CLAUDE.md、todos、preferences)压缩成 caveman-speak 形式,以降低输入 token 数量。压缩后的版本会覆盖原文件,同时保存一份人类可读的备份,文件名为 <filename>.original.md。备份不会放在源文件旁边,而是存放在树外数据目录中:$XDG_DATA_HOME/caveman-compress/backups/<parent-dir-name>/,Windows 上为 %LOCALAPPDATA%\caveman-compress\backups<parent-dir-name>\。这样设计是为了避免技能自动加载器把它当成真实文件重新读取。
触发方式
- 输入 /caveman-compress <filepath>
- 或用户要求压缩记忆文件时触发
使用方式
压缩脚本位于与本 SKILL.md 相邻的 scripts/ 目录。如果路径不可直接获得,可在本 SKILL.md 旁查找 scripts/main.py。
在包含本 SKILL.md 的目录下运行:
python3 -m scripts <absolute_filepath>
CLI 会执行以下流程:
- 检测文件类型(不消耗 token)
- 调用 Claude 进行压缩
- 校验输出(不消耗 token)
- 如果出错:用 Claude 定点修复(仅做定向修复,不重新压缩),最多重试 2 次
- 若 2 次重试后仍失败:向用户报告错误,保留原文件不变
- 向用户返回结果
压缩规则
删除:
- 冠词:a、an、the
- 填充词:just、really、basically、actually、simply、essentially、generally
- 客套话:"sure"、"certainly"、"of course"、"happy to"、"I'd recommend"
- 模糊措辞:"it might be worth"、"you could consider"、"it would be good to"
- 冗余表达:"in order to" → "to","make sure to" → "ensure","the reason is because" → "because"
- 连接性废话:"however"、"furthermore"、"additionally"、"in addition"
严格保留(永不修改):
- 代码块(围栏 ``` 与缩进块)
- 行内代码(反引号内容)
- URL 与链接(完整 URL、markdown 链接)
- 文件路径(/src/components/...、./config.yaml)
- 命令(npm install、git commit、docker build)
- 技术术语(库名、API 名、协议、算法)
- 专有名词(项目名、人名、公司名)
- 日期、版本号、数值
- 环境变量($HOME、NODE_ENV)
保留结构:
- 所有 markdown 标题(保留精确标题文本,压缩其下方正文)
- 项目符号层级(保留嵌套层级)
- 编号列表(保留编号)
- 表格(压缩单元格文本,保留结构)
- markdown 文件中的 Frontmatter/YAML 头部
压缩方式:
- 使用短同义词:用 "big" 而非 "extensive",用 "fix" 而非 "implement a solution for",用 "use" 而非 "utilize"
- 允许片段:"Run tests before commit" 而非 "You should always run tests before committing"
- 去掉 "you should"、"make sure to"、"remember to"——直接陈述动作
- 合并以不同措辞表达同一内容的冗余项目符号
- 多个示例展示同一模式时,只保留一个示例
关键规则:... 内的任何内容必须原样复制,不得删除注释、删除空格、重排行、缩短命令或简化任何内容。行内代码(...)必须原样保留,不得修改反引号内的任何内容。
如果文件包含代码块:
- 将代码块视为只读区域
- 只压缩其外部的文本
- 不要合并代码块周围的段落
示例:
原文:
You should always make sure to run the test suite before pushing any changes to the main branch. This is important because it helps catch bugs early and prevents broken builds from being deployed to production.
压缩后:
Run tests before push to main. Catch bugs early, prevent broken prod deploys.
原文:
The application uses a microservices architecture with the following components. The API gateway handles all incoming requests and routes them to the appropriate service. The authentication service is responsible for managing user sessions and JWT tokens.
压缩后:
Microservices architecture. API gateway route all requests to services. Auth service manage user sessions + JWT tokens.
边界限制
- 仅压缩自然语言文件(.md、.txt、.typ、.typst、.tex、无扩展名)
- 绝不修改:.py、.js、.ts、.json、.yaml、.yml、.toml、.env、.lock、.css、.html、.xml、.sql、.sh
- 如果文件内容混合(散文 + 代码),仅压缩散文部分
- 如果不确定内容是代码还是散文,保持不变
- 原文件在覆盖前会备份为 FILE.original.md,存放在树外备份数据目录(见「用途」),而非源文件旁
- 绝不压缩 FILE.original.md(跳过它)