@lornatang/dsh-caveman 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +51 -0
- package/README.md +218 -0
- package/README.zh.md +218 -0
- package/cordis.patch.yml +3 -0
- package/examples/caveman-anthropic.patch.yml +14 -0
- package/examples/caveman-auto.patch.yml +15 -0
- package/lib/attribution.js +24 -0
- package/lib/blocks.js +80 -0
- package/lib/cavecrew-git.js +83 -0
- package/lib/cavecrew.js +67 -0
- package/lib/compression.js +434 -0
- package/lib/index.js +127 -0
- package/lib/memory.js +35 -0
- package/lib/mode.js +71 -0
- package/lib/native.js +357 -0
- package/lib/runtime.js +199 -0
- package/lib/skills.js +75 -0
- package/lib/stats.js +189 -0
- package/lib/types/attribution.d.ts +8 -0
- package/lib/types/blocks.d.ts +12 -0
- package/lib/types/cavecrew-git.d.ts +5 -0
- package/lib/types/cavecrew.d.ts +10 -0
- package/lib/types/compression.d.ts +50 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/memory.d.ts +3 -0
- package/lib/types/mode.d.ts +33 -0
- package/lib/types/native.d.ts +43 -0
- package/lib/types/runtime.d.ts +23 -0
- package/lib/types/skills.d.ts +3 -0
- package/lib/types/stats.d.ts +6 -0
- package/package.json +129 -0
- package/presets/cavecrew.patch.yml +54 -0
- package/scripts/benchmark.mjs +79 -0
- package/scripts/caveman-cli.mjs +30 -0
- package/scripts/learn-binary.mjs +82 -0
- package/scripts/learn-checksums.json +29 -0
- package/vendor/caveman/LICENSE +202 -0
- package/vendor/caveman/LICENSE-MIT +21 -0
- package/vendor/caveman/NOTICE +49 -0
- package/vendor/caveman/agents/cavecrew-builder.md +46 -0
- package/vendor/caveman/agents/cavecrew-investigator.md +56 -0
- package/vendor/caveman/agents/cavecrew-reviewer.md +47 -0
- package/vendor/caveman/skills/activation-rule.mjs +43 -0
- package/vendor/caveman/skills/cavecrew/README.md +67 -0
- package/vendor/caveman/skills/cavecrew/SKILL.md +78 -0
- package/vendor/caveman/skills/caveman/README.md +68 -0
- package/vendor/caveman/skills/caveman/SKILL.md +89 -0
- package/vendor/caveman/skills/caveman-commit/README.md +44 -0
- package/vendor/caveman/skills/caveman-commit/SKILL.md +63 -0
- package/vendor/caveman/skills/caveman-compress/README.md +262 -0
- package/vendor/caveman/skills/caveman-compress/SECURITY.md +55 -0
- package/vendor/caveman/skills/caveman-compress/SKILL.md +114 -0
- package/vendor/caveman/skills/caveman-compress/scripts/__init__.py +9 -0
- package/vendor/caveman/skills/caveman-compress/scripts/__main__.py +3 -0
- package/vendor/caveman/skills/caveman-compress/scripts/benchmark.py +80 -0
- package/vendor/caveman/skills/caveman-compress/scripts/cli.py +94 -0
- package/vendor/caveman/skills/caveman-compress/scripts/compress.py +1331 -0
- package/vendor/caveman/skills/caveman-compress/scripts/detect.py +192 -0
- package/vendor/caveman/skills/caveman-compress/scripts/validate.py +440 -0
- package/vendor/caveman/skills/caveman-discover/SKILL.md +115 -0
- package/vendor/caveman/skills/caveman-evidence-review/SKILL.md +142 -0
- package/vendor/caveman/skills/caveman-explore/SKILL.md +42 -0
- package/vendor/caveman/skills/caveman-explore/package.json +12 -0
- package/vendor/caveman/skills/caveman-explore/tests/skill-file.test.mjs +44 -0
- package/vendor/caveman/skills/caveman-help/README.md +39 -0
- package/vendor/caveman/skills/caveman-help/SKILL.md +62 -0
- package/vendor/caveman/skills/caveman-learn/CLAUDE.md +32 -0
- package/vendor/caveman/skills/caveman-learn/README.md +38 -0
- package/vendor/caveman/skills/caveman-learn/SKILL.md +185 -0
- package/vendor/caveman/skills/caveman-learn/package.json +12 -0
- package/vendor/caveman/skills/caveman-learn/tests/index.js +1 -0
- package/vendor/caveman/skills/caveman-learn/tests/skill-file.test.mjs +54 -0
- package/vendor/caveman/skills/caveman-manage/SKILL.md +112 -0
- package/vendor/caveman/skills/caveman-optimize/SKILL.md +111 -0
- package/vendor/caveman/skills/caveman-review/README.md +33 -0
- package/vendor/caveman/skills/caveman-review/SKILL.md +53 -0
- package/vendor/caveman/skills/caveman-setup/SKILL.md +222 -0
- package/vendor/caveman/skills/caveman-stats/README.md +48 -0
- package/vendor/caveman/skills/caveman-stats/SKILL.md +17 -0
- package/vendor/caveman/skills/compile.mjs +298 -0
- package/vendor/caveman/skills/engine-mcp-tools.json +10 -0
- package/vendor/caveman/skills/generated/aider/pack.json +163 -0
- package/vendor/caveman/skills/generated/claude/pack.json +163 -0
- package/vendor/caveman/skills/generated/codex/pack.json +163 -0
- package/vendor/caveman/skills/generated/gemini/pack.json +163 -0
- package/vendor/caveman/skills/generated/hermes/pack.json +163 -0
- package/vendor/caveman/skills/generated/opencode/pack.json +163 -0
- package/vendor/caveman/skills/investigate-first/SKILL.md +16 -0
- package/vendor/caveman/skills/investigate-first/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/lean-build/SKILL.md +18 -0
- package/vendor/caveman/skills/lean-build/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/megacave/README.md +11 -0
- package/vendor/caveman/skills/megacave/SKILL.md +65 -0
- package/vendor/caveman/skills/migration/SKILL.md +17 -0
- package/vendor/caveman/skills/migration/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/native/native-core.md +16 -0
- package/vendor/caveman/skills/registry.json +283 -0
- package/vendor/caveman/skills/safe-refactor/SKILL.md +16 -0
- package/vendor/caveman/skills/safe-refactor/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/surgical-patch/SKILL.md +16 -0
- package/vendor/caveman/skills/surgical-patch/agents/openai.yaml +4 -0
- package/vendor/caveman/skills/ultracave/README.md +13 -0
- package/vendor/caveman/skills/ultracave/SKILL.md +63 -0
- package/vendor/caveman/skills/verbs-gate.mjs +213 -0
- package/vendor/caveman/skills/verify-and-stop/SKILL.md +16 -0
- package/vendor/caveman/skills/verify-and-stop/agents/openai.yaml +4 -0
- package/vendor/caveman/src/hooks/caveman-config.js +921 -0
- package/vendor/caveman/src/hooks/caveman-parse.js +342 -0
- package/vendor/caveman/src/hooks/package.json +3 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://em-content.zobj.net/source/apple/391/rock_1faa8.png" width="80" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">caveman-compress</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>shrink memory file. save token every session.</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
A Claude Code skill that compresses project memory files (`CLAUDE.md`, todos,
|
|
14
|
+
preferences) into caveman format, reducing repeated input size.
|
|
15
|
+
|
|
16
|
+
Claude loads `CLAUDE.md` on every session start, so large files add repeated
|
|
17
|
+
input tokens. Caveman shortens supported natural-language files.
|
|
18
|
+
|
|
19
|
+
## What It Do
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
/caveman-compress CLAUDE.md
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
CLAUDE.md ← compressed (Claude reads smaller file each session)
|
|
27
|
+
CLAUDE.original.md ← human-readable backup (you edit this)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Original remains in data directory rather than next to live file, so skill
|
|
31
|
+
auto-loaders do not read it twice. Path is
|
|
32
|
+
`$XDG_DATA_HOME/caveman-compress/backups/<parent-dir-name>-<hash>/` on macOS and
|
|
33
|
+
Linux, or `%LOCALAPPDATA%\caveman-compress\backups\<parent-dir-name>-<hash>\` on
|
|
34
|
+
Windows. `<hash>` keys the file's full parent path, so `~/.claude/CLAUDE.md` and
|
|
35
|
+
`some-repo/.claude/CLAUDE.md` keep separate backups.
|
|
36
|
+
|
|
37
|
+
To edit and re-compress, restore first — the skill refuses to run while a backup
|
|
38
|
+
exists, so that it never captures already-compressed text as the new "original":
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
FILE=path/to/the/file/you/compressed
|
|
42
|
+
cp "$BACKUP" "$FILE" # restore the uncompressed original
|
|
43
|
+
mv "$BACKUP" "$BACKUP.kept" # move it aside (do not just delete it)
|
|
44
|
+
# change $FILE, then run the skill again
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Benchmarks
|
|
48
|
+
|
|
49
|
+
The five fixture pairs in [`tests/caveman-compress/`](../../tests/caveman-compress/),
|
|
50
|
+
counted with tiktoken o200k. Reproduce with
|
|
51
|
+
`uv run --with tiktoken python skills/caveman-compress/scripts/benchmark.py`.
|
|
52
|
+
|
|
53
|
+
| File | Original | Compressed | Saved |
|
|
54
|
+
|------|----------:|----------:|------:|
|
|
55
|
+
| `claude-md-preferences.md` | 827 | 421 | 49.1% |
|
|
56
|
+
| `claude-md-project.md` | 1628 | 1117 | 31.4% |
|
|
57
|
+
| `mixed-with-code.md` | 1432 | 1106 | 22.8% |
|
|
58
|
+
| `project-notes.md` | 1431 | 846 | 40.9% |
|
|
59
|
+
| `todo-list.md` | 880 | 648 | 26.4% |
|
|
60
|
+
| Total | 6198 | 4138 | 33.2% |
|
|
61
|
+
|
|
62
|
+
All fixture validations passed: headings, code blocks, URLs, and file paths were
|
|
63
|
+
preserved exactly.
|
|
64
|
+
|
|
65
|
+
## Before / After
|
|
66
|
+
|
|
67
|
+
<table>
|
|
68
|
+
<tr>
|
|
69
|
+
<td width="50%">
|
|
70
|
+
|
|
71
|
+
### Original (827 tokens)
|
|
72
|
+
|
|
73
|
+
> "I strongly prefer TypeScript with strict mode enabled for all new code. Please don't use `any` type unless there's genuinely no way around it, and if you do, leave a comment explaining the reasoning. I find that taking the time to properly type things catches a lot of bugs before they ever make it to runtime."
|
|
74
|
+
|
|
75
|
+
</td>
|
|
76
|
+
<td width="50%">
|
|
77
|
+
|
|
78
|
+
### <img src="../../docs/assets/dancing-rock.svg" width="20" height="20" alt="rock"/> Caveman (421 tokens)
|
|
79
|
+
|
|
80
|
+
> "Prefer TypeScript strict mode always. No `any` unless unavoidable; comment why if used. Proper types catch bugs early."
|
|
81
|
+
|
|
82
|
+
</td>
|
|
83
|
+
</tr>
|
|
84
|
+
</table>
|
|
85
|
+
|
|
86
|
+
This fixture produced 49.1% fewer counted tokens. Structural validation passed;
|
|
87
|
+
result does not prove semantic equivalence on other files or models.
|
|
88
|
+
|
|
89
|
+
## Security
|
|
90
|
+
|
|
91
|
+
`caveman-compress` is flagged as Snyk High Risk due to subprocess and file I/O
|
|
92
|
+
patterns detected by static analysis. See [SECURITY.md](./SECURITY.md) for why
|
|
93
|
+
these operations exist and how paths are constrained.
|
|
94
|
+
|
|
95
|
+
## Install
|
|
96
|
+
|
|
97
|
+
Compress is built into the `caveman` plugin. Install `caveman` once, then use `/caveman-compress`.
|
|
98
|
+
|
|
99
|
+
If you need local files, the compress skill lives at:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
skills/caveman-compress/
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Requires Python 3.10 or newer.
|
|
106
|
+
|
|
107
|
+
### Provider / model
|
|
108
|
+
|
|
109
|
+
Default path uses Claude: `ANTHROPIC_API_KEY` + Anthropic SDK when set, else `claude --print`.
|
|
110
|
+
|
|
111
|
+
To use your existing Codex CLI login, install [Codex CLI](https://learn.chatgpt.com/docs/cli)
|
|
112
|
+
and sign in with ChatGPT:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
codex login
|
|
116
|
+
export CAVEMAN_COMPRESS_PROVIDER=codex
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
ChatGPT login uses your plan's Codex allowance; a saved API-key login uses API
|
|
120
|
+
billing. Neither `OPENAI_API_KEY` nor `ANTHROPIC_API_KEY` is required. User CLI
|
|
121
|
+
configuration, including custom providers and configured models, is ignored.
|
|
122
|
+
|
|
123
|
+
Optional: set `CAVEMAN_COMPRESS_MODEL` to a model available in your Codex account:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
export CAVEMAN_COMPRESS_MODEL=your-codex-model
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`CAVEMAN_MODEL` is the fallback; otherwise Codex uses its built-in default.
|
|
130
|
+
Requires CLI 0.166.0 or newer, with isolation verified on 0.166.0. Unsupported
|
|
131
|
+
controls fail the call without weaker settings or switching providers.
|
|
132
|
+
|
|
133
|
+
Runs `codex exec` in an empty temporary directory, including outside Git repos.
|
|
134
|
+
The prompt goes through stdin; `--output-last-message` supplies the answer.
|
|
135
|
+
Commands and other tool surfaces are disabled; a custom profile denies all
|
|
136
|
+
sandboxed filesystem and network access. Raw failure diagnostics are withheld.
|
|
137
|
+
See [security details and limits](./SECURITY.md#auth-behavior).
|
|
138
|
+
|
|
139
|
+
To use opencode instead (any model opencode can reach, free ones included):
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
export CAVEMAN_COMPRESS_PROVIDER=opencode
|
|
143
|
+
export CAVEMAN_COMPRESS_MODEL=opencode/big-pickle # any id from `opencode models`
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
To use a local model (or any OpenAI-compatible server) instead:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
export CAVEMAN_COMPRESS_PROVIDER=openai-compat
|
|
150
|
+
export CAVEMAN_COMPRESS_MODEL=qwen3:8b # required
|
|
151
|
+
export CAVEMAN_COMPRESS_ENDPOINT=http://localhost:11434/v1 # default (Ollama)
|
|
152
|
+
# export CAVEMAN_COMPRESS_API_KEY=... # optional, sent as Bearer token
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Common endpoints: Ollama `http://localhost:11434/v1`, LM Studio `http://localhost:1234/v1`, llama.cpp server `http://localhost:8080/v1`, vLLM `http://localhost:8000/v1`. Nothing leaves your machine with a local server. A non-local `http://` endpoint sends the file in plaintext; use `https://` for remote servers. Small local models get it wrong more often; when they do, validation fails and your file stays untouched.
|
|
156
|
+
|
|
157
|
+
`CAVEMAN_MODEL` is the fallback when `CAVEMAN_COMPRESS_MODEL` is unset. On the Claude path the model also applies to `claude --print`. The opencode path needs opencode 2.x (it uses `opencode run --standalone`).
|
|
158
|
+
|
|
159
|
+
## Usage
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
/caveman-compress <filepath>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Examples:
|
|
166
|
+
```
|
|
167
|
+
/caveman-compress CLAUDE.md
|
|
168
|
+
/caveman-compress docs/preferences.md
|
|
169
|
+
/caveman-compress todos.md
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### What files work
|
|
173
|
+
|
|
174
|
+
| Type | Compress? |
|
|
175
|
+
|------|-----------|
|
|
176
|
+
| `.md`, `.mdc`, `.txt`, `.rst`, `.typ`, `.typst`, `.tex` | Yes |
|
|
177
|
+
| Extensionless natural language | Yes |
|
|
178
|
+
| `.py`, `.js`, `.ts`, `.json`, `.yaml` | ❌ Skip (code/config) |
|
|
179
|
+
| `*.original.md` | ❌ Skip (backup files) |
|
|
180
|
+
|
|
181
|
+
## How It Work
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
/caveman-compress CLAUDE.md
|
|
185
|
+
↓
|
|
186
|
+
basic checks: file exists, under 500KB, not a sensitive filename
|
|
187
|
+
↓
|
|
188
|
+
acquire cross-session lock on the file (waits up to 15 min if another run holds it, then errors)
|
|
189
|
+
↓
|
|
190
|
+
detect file type (no tokens)
|
|
191
|
+
↓
|
|
192
|
+
refuse if text holds a key or token (no tokens, nothing sent)
|
|
193
|
+
↓
|
|
194
|
+
configured provider compresses (tokens: one call)
|
|
195
|
+
↓
|
|
196
|
+
validate output (no tokens)
|
|
197
|
+
checks: headings, code blocks, URLs, file paths, bullets
|
|
198
|
+
↓
|
|
199
|
+
if errors: configured provider fixes cherry-picked issues only (tokens: targeted fix)
|
|
200
|
+
does NOT recompress; only patches broken parts
|
|
201
|
+
↓
|
|
202
|
+
validate again (one fix call at most)
|
|
203
|
+
↓
|
|
204
|
+
compressed text → same path as input
|
|
205
|
+
original → backup dir, as <name>.original.md
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Only two things use tokens: initial compression + targeted fix if validation fails. Everything else is local Python.
|
|
209
|
+
|
|
210
|
+
## What Is Preserved
|
|
211
|
+
|
|
212
|
+
Caveman compress natural language. It never touch:
|
|
213
|
+
|
|
214
|
+
- Code blocks (` ``` ` fenced or indented)
|
|
215
|
+
- Inline code (`` `backtick content` ``)
|
|
216
|
+
- URLs and links
|
|
217
|
+
- File paths (`/src/components/...`)
|
|
218
|
+
- Commands (`npm install`, `git commit`)
|
|
219
|
+
- Technical terms, library names, API names
|
|
220
|
+
- Headings (exact text preserved)
|
|
221
|
+
- Tables (structure preserved, cell text compressed)
|
|
222
|
+
- Dates, version numbers, numeric values
|
|
223
|
+
- Anything you wrap in `<!-- nocompress -->` ... `<!-- /nocompress -->`
|
|
224
|
+
- HTML comments that start a line (`<!-- ... -->`)
|
|
225
|
+
|
|
226
|
+
File that say `generated by` on line 1 get skipped. Generator overwrite it anyway.
|
|
227
|
+
|
|
228
|
+
Want a part left exactly as written (an `<example>` block, a prompt template)? Wrap it. Each tag go on its own line. Model never change what inside; it come back byte for byte. Model can still read it if first try need fixing, so not hiding place for secrets. Forget the closing tag and compress stop before touching file.
|
|
229
|
+
|
|
230
|
+
```markdown
|
|
231
|
+
<!-- nocompress -->
|
|
232
|
+
<example>
|
|
233
|
+
Reply in this exact format.
|
|
234
|
+
</example>
|
|
235
|
+
<!-- /nocompress -->
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Why This Matter
|
|
239
|
+
|
|
240
|
+
`CLAUDE.md` loads on every session start. A 1,000-token project memory file adds
|
|
241
|
+
1,000 input tokens each time project opens, or 100,000 across 100 sessions.
|
|
242
|
+
|
|
243
|
+
Caveman reduced counted tokens by 33.2% in total on the five listed fixtures
|
|
244
|
+
(22.8% to 49.1% per file). Validators confirmed headings, code blocks, URLs,
|
|
245
|
+
and file paths. They did not establish general semantic or task-quality
|
|
246
|
+
equivalence.
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
┌────────────────────────────────────────────┐
|
|
250
|
+
│ TOKEN SAVINGS, ALL FIVE ███ 33.2% │
|
|
251
|
+
│ FIXTURES IN TABLE 5 │
|
|
252
|
+
│ STRUCTURAL VALIDATION passed on all │
|
|
253
|
+
│ SETUP TIME █ 1x │
|
|
254
|
+
└────────────────────────────────────────────┘
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Part of Caveman
|
|
258
|
+
|
|
259
|
+
This skill is part of the [caveman](https://github.com/JuliusBrussee/caveman) toolkit.
|
|
260
|
+
|
|
261
|
+
- `caveman`: ask Claude to answer in shorter prose
|
|
262
|
+
- `caveman-compress`: shorten supported project-memory files with backups and validation
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
## Snyk High Risk Rating
|
|
4
|
+
|
|
5
|
+
`caveman-compress` receives a Snyk High Risk rating due to static analysis heuristics. This document explains what the skill does and does not do.
|
|
6
|
+
|
|
7
|
+
### What triggers the rating
|
|
8
|
+
|
|
9
|
+
1. **subprocess usage**: The skill calls the `claude` CLI via `subprocess.run()` as a fallback when `ANTHROPIC_API_KEY` is not set. It can also call `opencode run` when `CAVEMAN_COMPRESS_PROVIDER=opencode`. Subprocess calls use fixed argument lists — no shell interpolation occurs. Claude receives user file content via stdin; opencode receives the generated prompt through a temporary `--file` attachment that is deleted after the call.
|
|
10
|
+
|
|
11
|
+
The file being compressed is untrusted input, and opencode 2.x lets its agents use every tool that is not explicitly denied: shell, file edits, web search and fetch, MCP tools from your opencode config, subagents. Compression needs none of them. Compress therefore runs `opencode run --standalone --agent caveman-compress` with `OPENCODE_CONFIG_CONTENT` denying every permission (`"*": "deny"`) both globally and for that agent, and never passes `--auto`. The dedicated agent matters because opencode applies a per-agent rule after the global one, so an `agent.build.permission` allow in your own config would otherwise re-enable a tool. `--standalone` matters because the shared opencode background service does not read the caller's environment, so the deny rule only binds a private server. Checked on opencode 2.0.22: the model is offered no tools and the prompt attachment is still read. Unlike the Claude path (`--strict-mcp-config`), compress does not switch off the MCP servers in your opencode config: their tools are denied, but opencode may still start them.
|
|
12
|
+
|
|
13
|
+
2. **File read/write**: The skill reads the file the user explicitly points it at, compresses it, and writes the result back to the same path. A `.original.md` backup is saved to an out-of-tree data dir (`$XDG_DATA_HOME/caveman-compress/backups/<parent-dir-name>-<hash>/`, or `%LOCALAPPDATA%\caveman-compress\backups\<parent-dir-name>-<hash>\` on Windows, where `<hash>` keys the file's full parent path so two projects' same-named files never share a backup). The opencode provider writes a temporary prompt attachment in the OS temp directory and deletes it after the subprocess exits. Beyond the target file, that backup location, and the temporary attachment, no files are read or written.
|
|
14
|
+
|
|
15
|
+
### What the skill does NOT do
|
|
16
|
+
|
|
17
|
+
- Does not execute user file content as code
|
|
18
|
+
- Does not make network requests except through the configured LLM provider CLI, SDK, or (for `openai-compat`) the one configured HTTP endpoint
|
|
19
|
+
- Does not read unrelated files outside the path the user provides
|
|
20
|
+
- Does not use shell=True or string interpolation in subprocess calls
|
|
21
|
+
- Does not collect or transmit any data beyond the file being compressed
|
|
22
|
+
|
|
23
|
+
### Auth behavior
|
|
24
|
+
|
|
25
|
+
Codex uses saved login but ignores user configuration and project instructions.
|
|
26
|
+
It disables commands, hooks, plugins, apps, image reads, subagents, code mode,
|
|
27
|
+
skill search/install, goals, memories, browser/computer use, artifacts, workspace
|
|
28
|
+
dependencies, and web search. Input arrives through stdin in an empty temporary
|
|
29
|
+
directory; the final-message file is deleted with that directory after the call.
|
|
30
|
+
|
|
31
|
+
Its permission profile denies sandboxed filesystem and network access, with no
|
|
32
|
+
exceptions. Do not add `--sandbox`: it overrides the profile. CLI parent-process
|
|
33
|
+
I/O, including authentication, is outside this sandbox. Managed configuration
|
|
34
|
+
remains authoritative; administrator-provided integrations are not isolated by
|
|
35
|
+
these controls. See [Codex permissions](https://learn.chatgpt.com/docs/permissions).
|
|
36
|
+
Verified on macOS with CLI 0.166.0, a local dummy model endpoint, and filesystem
|
|
37
|
+
canaries. Rejected controls never trigger a retry with weaker settings.
|
|
38
|
+
|
|
39
|
+
Default path uses Claude. If `ANTHROPIC_API_KEY` is set, the skill uses the Anthropic Python SDK directly (no subprocess). If not set, it falls back to the `claude` CLI, which uses the user's existing Claude desktop authentication.
|
|
40
|
+
|
|
41
|
+
Set `CAVEMAN_COMPRESS_PROVIDER=opencode` to use `opencode run` instead. Set `CAVEMAN_COMPRESS_MODEL=provider/model` for compress-specific model selection. `CAVEMAN_MODEL` is the fallback when `CAVEMAN_COMPRESS_MODEL` is unset.
|
|
42
|
+
|
|
43
|
+
Set `CAVEMAN_COMPRESS_PROVIDER=openai-compat` to POST the prompt with Python's standard-library `urllib` (no subprocess, no extra dependency) to `$CAVEMAN_COMPRESS_ENDPOINT/chat/completions`, default `http://localhost:11434/v1` (Ollama). Other local servers: LM Studio `http://localhost:1234/v1`, llama.cpp `http://localhost:8080/v1`, vLLM `http://localhost:8000/v1`. `CAVEMAN_COMPRESS_API_KEY`, if set, is sent as a Bearer token. A non-local `http://` endpoint sends the file and that key in plaintext; use `https://` for anything off the machine.
|
|
44
|
+
|
|
45
|
+
### File size limit
|
|
46
|
+
|
|
47
|
+
Files larger than 500KB are rejected before any API call is made.
|
|
48
|
+
|
|
49
|
+
### Snyk W007 ("insecure credential handling")
|
|
50
|
+
|
|
51
|
+
W007 fires on the rule that code blocks, commands, and exact error strings stay verbatim. See [Scanner warnings](../../SECURITY.md#scanner-warnings) in the repository SECURITY.md.
|
|
52
|
+
|
|
53
|
+
### Reporting a vulnerability
|
|
54
|
+
|
|
55
|
+
If you believe you've found a genuine security issue, please open a GitHub issue with the label `security`.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: caveman-compress
|
|
3
|
+
description: >
|
|
4
|
+
Compress a memory file such as CLAUDE.md or a todo list into caveman format
|
|
5
|
+
to save input tokens, keeping a readable backup. Sends the file's text to the
|
|
6
|
+
configured model provider. Trigger: /caveman-compress.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Caveman Compress
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
|
|
13
|
+
> **Data leaves the machine.** Compression sends the file's full text to the model provider that `scripts/compress.py` is configured for: the `claude` CLI, the Anthropic API, or an OpenAI-compatible endpoint. Files whose names look like secrets (`.env`, `credentials`, `secrets`, `.netrc`, …) are refused before they are read, and a file whose text holds a credential (a private key block, or a cloud, Git host or model API token) is refused before anything is sent. Don't compress a file the provider shouldn't see.
|
|
14
|
+
|
|
15
|
+
Compress natural language files (CLAUDE.md, todos, preferences) into caveman-speak to reduce input tokens. Compressed version overwrites original. Human-readable backup saved as `<filename>.original.md`, but NOT beside the source file — it lives in an out-of-tree data dir (`$XDG_DATA_HOME/caveman-compress/backups/<parent-dir-name>/`, or `%LOCALAPPDATA%\caveman-compress\backups\<parent-dir-name>\` on Windows) so skill auto-loaders don't re-ingest it as a live file.
|
|
16
|
+
|
|
17
|
+
## Trigger
|
|
18
|
+
|
|
19
|
+
`/caveman-compress <filepath>` or when user asks to compress a memory file.
|
|
20
|
+
|
|
21
|
+
**Requires an explicit filepath.** If the user pastes raw text instead of naming a file, do NOT improvise an inline compression — ask them for the filepath to compress, or offer to save the pasted text to a file first. Writing your own reasoning/commentary about the request into the compressed output (e.g. "User passed text directly, not a filepath...") is the exact failure this guards against — never let that leak into a saved file.
|
|
22
|
+
|
|
23
|
+
## Process
|
|
24
|
+
|
|
25
|
+
1. The compression scripts live in `scripts/` (adjacent to this SKILL.md). If the path is not immediately available, search for `scripts/__main__.py` next to this SKILL.md.
|
|
26
|
+
|
|
27
|
+
2. From the directory containing this SKILL.md, run:
|
|
28
|
+
|
|
29
|
+
python3 -m scripts <absolute_filepath>
|
|
30
|
+
|
|
31
|
+
3. The CLI will:
|
|
32
|
+
- detect file type (no tokens)
|
|
33
|
+
- call Claude to compress
|
|
34
|
+
- validate output (no tokens)
|
|
35
|
+
- if errors: cherry-pick fix with Claude (targeted fixes only, no recompression)
|
|
36
|
+
- retry up to 2 times
|
|
37
|
+
- if still failing after 2 retries: report error to user, leave original file untouched
|
|
38
|
+
|
|
39
|
+
4. Return result to user
|
|
40
|
+
|
|
41
|
+
## Compression Rules
|
|
42
|
+
|
|
43
|
+
### Remove
|
|
44
|
+
- Articles: a, an, the
|
|
45
|
+
- Filler: just, really, basically, actually, simply, essentially, generally
|
|
46
|
+
- Pleasantries: "sure", "certainly", "of course", "happy to", "I'd recommend"
|
|
47
|
+
- Hedging: "it might be worth", "you could consider", "it would be good to"
|
|
48
|
+
- Redundant phrasing: "in order to" → "to", "make sure to" → "ensure", "the reason is because" → "because"
|
|
49
|
+
- Connective fluff: "however", "furthermore", "additionally", "in addition"
|
|
50
|
+
|
|
51
|
+
### Preserve EXACTLY (never modify)
|
|
52
|
+
- Code blocks (fenced ``` and indented)
|
|
53
|
+
- Inline code (`backtick content`)
|
|
54
|
+
- URLs and links (full URLs, markdown links)
|
|
55
|
+
- File paths (`/src/components/...`, `./config.yaml`)
|
|
56
|
+
- Commands (`npm install`, `git commit`, `docker build`)
|
|
57
|
+
- Technical terms (library names, API names, protocols, algorithms)
|
|
58
|
+
- Proper nouns (project names, people, companies)
|
|
59
|
+
- Dates, version numbers, numeric values
|
|
60
|
+
- Environment variables (`$HOME`, `NODE_ENV`)
|
|
61
|
+
|
|
62
|
+
### Preserve Structure
|
|
63
|
+
- All markdown headings (keep exact heading text, compress body below)
|
|
64
|
+
- Bullet point hierarchy (keep nesting level)
|
|
65
|
+
- Numbered lists (keep numbering)
|
|
66
|
+
- Tables (compress cell text, keep structure)
|
|
67
|
+
- Frontmatter/YAML headers in markdown files
|
|
68
|
+
|
|
69
|
+
### Compress
|
|
70
|
+
- Use short synonyms: "big" not "extensive", "fix" not "implement a solution for", "use" not "utilize"
|
|
71
|
+
- Fragments OK: "Run tests before commit" not "You should always run tests before committing"
|
|
72
|
+
- Drop "you should", "make sure to", "remember to" — just state the action
|
|
73
|
+
- Merge redundant bullets that say the same thing differently
|
|
74
|
+
- Keep one example where multiple examples show the same pattern
|
|
75
|
+
|
|
76
|
+
CRITICAL RULE:
|
|
77
|
+
Anything inside ``` ... ``` must be copied EXACTLY.
|
|
78
|
+
Do not:
|
|
79
|
+
- remove comments
|
|
80
|
+
- remove spacing
|
|
81
|
+
- reorder lines
|
|
82
|
+
- shorten commands
|
|
83
|
+
- simplify anything
|
|
84
|
+
|
|
85
|
+
Inline code (`...`) must be preserved EXACTLY.
|
|
86
|
+
Do not modify anything inside backticks.
|
|
87
|
+
|
|
88
|
+
If file contains code blocks:
|
|
89
|
+
- Treat code blocks as read-only regions
|
|
90
|
+
- Only compress text outside them
|
|
91
|
+
- Do not merge sections around code
|
|
92
|
+
|
|
93
|
+
## Pattern
|
|
94
|
+
|
|
95
|
+
Original:
|
|
96
|
+
> 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.
|
|
97
|
+
|
|
98
|
+
Compressed:
|
|
99
|
+
> Run tests before push to main. Catch bugs early, prevent broken prod deploys.
|
|
100
|
+
|
|
101
|
+
Original:
|
|
102
|
+
> 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.
|
|
103
|
+
|
|
104
|
+
Compressed:
|
|
105
|
+
> Microservices architecture. API gateway route all requests to services. Auth service manage user sessions + JWT tokens.
|
|
106
|
+
|
|
107
|
+
## Boundaries
|
|
108
|
+
|
|
109
|
+
- ONLY compress natural language files (.md, .txt, .typ, .typst, .tex, extensionless)
|
|
110
|
+
- NEVER modify: .py, .js, .ts, .json, .yaml, .yml, .toml, .env, .lock, .css, .html, .xml, .sql, .sh
|
|
111
|
+
- If file has mixed content (prose + code), compress ONLY the prose sections
|
|
112
|
+
- If unsure whether something is code or prose, leave it unchanged
|
|
113
|
+
- Original file is backed up as FILE.original.md before overwriting — in the out-of-tree backup data dir (see Purpose), not beside the source file
|
|
114
|
+
- Never compress FILE.original.md (skip it)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
# Support both direct execution and module import
|
|
6
|
+
try:
|
|
7
|
+
from .validate import validate
|
|
8
|
+
except ImportError:
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).parent))
|
|
10
|
+
from validate import validate
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import tiktoken
|
|
14
|
+
_enc = tiktoken.get_encoding("o200k_base")
|
|
15
|
+
except ImportError:
|
|
16
|
+
_enc = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def count_tokens(text):
|
|
20
|
+
if _enc is None:
|
|
21
|
+
return len(text.split()) # fallback: word count
|
|
22
|
+
return len(_enc.encode(text))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def benchmark_pair(orig_path: Path, comp_path: Path):
|
|
26
|
+
orig_text = orig_path.read_text(encoding="utf-8", errors="ignore")
|
|
27
|
+
comp_text = comp_path.read_text(encoding="utf-8", errors="ignore")
|
|
28
|
+
|
|
29
|
+
orig_tokens = count_tokens(orig_text)
|
|
30
|
+
comp_tokens = count_tokens(comp_text)
|
|
31
|
+
saved = 100 * (orig_tokens - comp_tokens) / orig_tokens if orig_tokens > 0 else 0.0
|
|
32
|
+
result = validate(orig_path, comp_path)
|
|
33
|
+
|
|
34
|
+
return (comp_path.name, orig_tokens, comp_tokens, saved, result.is_valid)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def print_table(rows):
|
|
38
|
+
print("\n| File | Original | Compressed | Saved % | Valid |")
|
|
39
|
+
print("|------|----------|------------|---------|-------|")
|
|
40
|
+
for r in rows:
|
|
41
|
+
print(f"| {r[0]} | {r[1]} | {r[2]} | {r[3]:.1f}% | {'✅' if r[4] else '❌'} |")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main():
|
|
45
|
+
# Direct file pair: python3 benchmark.py original.md compressed.md
|
|
46
|
+
if len(sys.argv) == 3:
|
|
47
|
+
orig = Path(sys.argv[1]).resolve()
|
|
48
|
+
comp = Path(sys.argv[2]).resolve()
|
|
49
|
+
if not orig.exists():
|
|
50
|
+
print(f"❌ Not found: {orig}")
|
|
51
|
+
sys.exit(1)
|
|
52
|
+
if not comp.exists():
|
|
53
|
+
print(f"❌ Not found: {comp}")
|
|
54
|
+
sys.exit(1)
|
|
55
|
+
print_table([benchmark_pair(orig, comp)])
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
# Glob mode: repo_root/tests/caveman-compress/
|
|
59
|
+
# __file__ lives at <repo_root>/skills/caveman-compress/scripts/benchmark.py
|
|
60
|
+
# Walk up four dirs: scripts → caveman-compress → skills → repo_root.
|
|
61
|
+
tests_dir = Path(__file__).resolve().parents[3] / "tests" / "caveman-compress"
|
|
62
|
+
if not tests_dir.exists():
|
|
63
|
+
print(f"❌ Tests dir not found: {tests_dir}")
|
|
64
|
+
sys.exit(1)
|
|
65
|
+
|
|
66
|
+
rows = []
|
|
67
|
+
for orig in sorted(tests_dir.glob("*.original.md")):
|
|
68
|
+
comp = orig.with_name(orig.stem.removesuffix(".original") + ".md")
|
|
69
|
+
if comp.exists():
|
|
70
|
+
rows.append(benchmark_pair(orig, comp))
|
|
71
|
+
|
|
72
|
+
if not rows:
|
|
73
|
+
print("No compressed file pairs found.")
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
print_table(rows)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
main()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Caveman Compress CLI
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
caveman <filepath>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
# Force UTF-8 on stdout/stderr before any code can print. Windows consoles
|
|
13
|
+
# default to cp1252 and crash on the ❌ glyphs in error/validation branches,
|
|
14
|
+
# masking the real error and leaving the user with a half-compressed file.
|
|
15
|
+
for _stream in (sys.stdout, sys.stderr):
|
|
16
|
+
reconfigure = getattr(_stream, "reconfigure", None)
|
|
17
|
+
if callable(reconfigure):
|
|
18
|
+
try:
|
|
19
|
+
reconfigure(encoding="utf-8", errors="replace")
|
|
20
|
+
except Exception:
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
# Direct script execution has no package context. Resolve imports relative to
|
|
26
|
+
# this installed skill, independent of the caller's working directory.
|
|
27
|
+
if __package__ in (None, ""):
|
|
28
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
29
|
+
__package__ = "scripts"
|
|
30
|
+
|
|
31
|
+
from .compress import backup_dir_for, compress_file, is_sensitive_path
|
|
32
|
+
from .detect import detect_file_type, should_compress
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def main():
|
|
36
|
+
parser = argparse.ArgumentParser(description="Compress a natural-language file with validation and an original backup.")
|
|
37
|
+
parser.add_argument("filepath", type=Path, help="path to the file to compress")
|
|
38
|
+
filepath = parser.parse_args().filepath
|
|
39
|
+
|
|
40
|
+
# Check file exists
|
|
41
|
+
if not filepath.exists():
|
|
42
|
+
print(f"❌ File not found: {filepath}")
|
|
43
|
+
sys.exit(1)
|
|
44
|
+
|
|
45
|
+
if not filepath.is_file():
|
|
46
|
+
print(f"❌ Not a file: {filepath}")
|
|
47
|
+
sys.exit(1)
|
|
48
|
+
|
|
49
|
+
filepath = filepath.resolve()
|
|
50
|
+
|
|
51
|
+
# Refuse before detect_file_type(), which reads extensionless files to sniff them.
|
|
52
|
+
if is_sensitive_path(filepath):
|
|
53
|
+
print(f"❌ Refusing to compress {filepath}: filename looks sensitive "
|
|
54
|
+
"(credentials, keys, secrets, or known private paths). "
|
|
55
|
+
"Rename the file if this is a false positive.")
|
|
56
|
+
sys.exit(1)
|
|
57
|
+
|
|
58
|
+
# Detect file type
|
|
59
|
+
file_type = detect_file_type(filepath)
|
|
60
|
+
|
|
61
|
+
print(f"Detected: {file_type}")
|
|
62
|
+
|
|
63
|
+
# Check if compressible
|
|
64
|
+
if not should_compress(filepath):
|
|
65
|
+
print("Skipping: file is not natural language (code/config)")
|
|
66
|
+
sys.exit(0)
|
|
67
|
+
|
|
68
|
+
print("Starting caveman compression...\n")
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
success = compress_file(filepath)
|
|
72
|
+
|
|
73
|
+
if success:
|
|
74
|
+
print("\nCompression completed successfully")
|
|
75
|
+
backup_path = backup_dir_for(filepath) / (filepath.stem + ".original.md")
|
|
76
|
+
print(f"Compressed: {filepath}")
|
|
77
|
+
print(f"Original: {backup_path}")
|
|
78
|
+
sys.exit(0)
|
|
79
|
+
else:
|
|
80
|
+
# Also reached when no attempt ran (backup exists, empty file, ...).
|
|
81
|
+
print("\n❌ Compression did not complete (see above). Original file is untouched.")
|
|
82
|
+
sys.exit(2)
|
|
83
|
+
|
|
84
|
+
except KeyboardInterrupt:
|
|
85
|
+
print("\nInterrupted by user")
|
|
86
|
+
sys.exit(130)
|
|
87
|
+
|
|
88
|
+
except Exception as e:
|
|
89
|
+
print(f"\n❌ Error: {e}")
|
|
90
|
+
sys.exit(1)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
main()
|