@izhimu/pi-caveman 0.2.1 → 0.4.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 +42 -0
- package/README.md +46 -52
- package/extensions/caveman.ts +393 -239
- package/package.json +33 -6
- package/skills/caveman/README.md +39 -23
- package/skills/caveman/SKILL.md +56 -57
- package/skills/megacave/README.md +11 -0
- package/skills/megacave/SKILL.md +65 -0
- package/skills/ultracave/README.md +13 -0
- package/skills/ultracave/SKILL.md +63 -0
- package/skills/caveman-compress/README.md +0 -176
- package/skills/caveman-compress/SECURITY.md +0 -31
- package/skills/caveman-compress/SKILL.md +0 -111
- package/skills/caveman-compress/scripts/__init__.py +0 -9
- package/skills/caveman-compress/scripts/__main__.py +0 -3
- package/skills/caveman-compress/scripts/benchmark.py +0 -80
- package/skills/caveman-compress/scripts/cli.py +0 -85
- package/skills/caveman-compress/scripts/compress.py +0 -505
- package/skills/caveman-compress/scripts/detect.py +0 -139
- package/skills/caveman-compress/scripts/validate.py +0 -408
|
@@ -1,31 +0,0 @@
|
|
|
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. The subprocess call uses a fixed argument list — no shell interpolation occurs. User file content is passed via stdin, not as a shell argument.
|
|
10
|
-
|
|
11
|
-
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>/`, or `%LOCALAPPDATA%\caveman-compress\backups\<parent-dir-name>\` on Windows). Beyond the target file and that backup location, no files are read or written.
|
|
12
|
-
|
|
13
|
-
### What the skill does NOT do
|
|
14
|
-
|
|
15
|
-
- Does not execute user file content as code
|
|
16
|
-
- Does not make network requests except to Anthropic's API (via SDK or CLI)
|
|
17
|
-
- Does not access files outside the path the user provides
|
|
18
|
-
- Does not use shell=True or string interpolation in subprocess calls
|
|
19
|
-
- Does not collect or transmit any data beyond the file being compressed
|
|
20
|
-
|
|
21
|
-
### Auth behavior
|
|
22
|
-
|
|
23
|
-
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.
|
|
24
|
-
|
|
25
|
-
### File size limit
|
|
26
|
-
|
|
27
|
-
Files larger than 500KB are rejected before any API call is made.
|
|
28
|
-
|
|
29
|
-
### Reporting a vulnerability
|
|
30
|
-
|
|
31
|
-
If you believe you've found a genuine security issue, please open a GitHub issue with the label `security`.
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: caveman-compress
|
|
3
|
-
description: >
|
|
4
|
-
Compress natural language memory files (CLAUDE.md, todos, preferences) into caveman format
|
|
5
|
-
to save input tokens. Preserves all technical substance, code, URLs, and structure.
|
|
6
|
-
Compressed version overwrites the original file. Human-readable backup saved as FILE.original.md.
|
|
7
|
-
Trigger: /caveman-compress FILEPATH or "compress memory file"
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
# Caveman Compress
|
|
11
|
-
|
|
12
|
-
## Purpose
|
|
13
|
-
|
|
14
|
-
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.
|
|
15
|
-
|
|
16
|
-
## Trigger
|
|
17
|
-
|
|
18
|
-
`/caveman-compress <filepath>` or when user asks to compress a memory file.
|
|
19
|
-
|
|
20
|
-
## Process
|
|
21
|
-
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
2. From the directory containing this SKILL.md, run:
|
|
25
|
-
|
|
26
|
-
python3 -m scripts <absolute_filepath>
|
|
27
|
-
|
|
28
|
-
3. The CLI will:
|
|
29
|
-
- detect file type (no tokens)
|
|
30
|
-
- call Claude to compress
|
|
31
|
-
- validate output (no tokens)
|
|
32
|
-
- if errors: cherry-pick fix with Claude (targeted fixes only, no recompression)
|
|
33
|
-
- retry up to 2 times
|
|
34
|
-
- if still failing after 2 retries: report error to user, leave original file untouched
|
|
35
|
-
|
|
36
|
-
4. Return result to user
|
|
37
|
-
|
|
38
|
-
## Compression Rules
|
|
39
|
-
|
|
40
|
-
### Remove
|
|
41
|
-
- Articles: a, an, the
|
|
42
|
-
- Filler: just, really, basically, actually, simply, essentially, generally
|
|
43
|
-
- Pleasantries: "sure", "certainly", "of course", "happy to", "I'd recommend"
|
|
44
|
-
- Hedging: "it might be worth", "you could consider", "it would be good to"
|
|
45
|
-
- Redundant phrasing: "in order to" → "to", "make sure to" → "ensure", "the reason is because" → "because"
|
|
46
|
-
- Connective fluff: "however", "furthermore", "additionally", "in addition"
|
|
47
|
-
|
|
48
|
-
### Preserve EXACTLY (never modify)
|
|
49
|
-
- Code blocks (fenced ``` and indented)
|
|
50
|
-
- Inline code (`backtick content`)
|
|
51
|
-
- URLs and links (full URLs, markdown links)
|
|
52
|
-
- File paths (`/src/components/...`, `./config.yaml`)
|
|
53
|
-
- Commands (`npm install`, `git commit`, `docker build`)
|
|
54
|
-
- Technical terms (library names, API names, protocols, algorithms)
|
|
55
|
-
- Proper nouns (project names, people, companies)
|
|
56
|
-
- Dates, version numbers, numeric values
|
|
57
|
-
- Environment variables (`$HOME`, `NODE_ENV`)
|
|
58
|
-
|
|
59
|
-
### Preserve Structure
|
|
60
|
-
- All markdown headings (keep exact heading text, compress body below)
|
|
61
|
-
- Bullet point hierarchy (keep nesting level)
|
|
62
|
-
- Numbered lists (keep numbering)
|
|
63
|
-
- Tables (compress cell text, keep structure)
|
|
64
|
-
- Frontmatter/YAML headers in markdown files
|
|
65
|
-
|
|
66
|
-
### Compress
|
|
67
|
-
- Use short synonyms: "big" not "extensive", "fix" not "implement a solution for", "use" not "utilize"
|
|
68
|
-
- Fragments OK: "Run tests before commit" not "You should always run tests before committing"
|
|
69
|
-
- Drop "you should", "make sure to", "remember to" — just state the action
|
|
70
|
-
- Merge redundant bullets that say the same thing differently
|
|
71
|
-
- Keep one example where multiple examples show the same pattern
|
|
72
|
-
|
|
73
|
-
CRITICAL RULE:
|
|
74
|
-
Anything inside ``` ... ``` must be copied EXACTLY.
|
|
75
|
-
Do not:
|
|
76
|
-
- remove comments
|
|
77
|
-
- remove spacing
|
|
78
|
-
- reorder lines
|
|
79
|
-
- shorten commands
|
|
80
|
-
- simplify anything
|
|
81
|
-
|
|
82
|
-
Inline code (`...`) must be preserved EXACTLY.
|
|
83
|
-
Do not modify anything inside backticks.
|
|
84
|
-
|
|
85
|
-
If file contains code blocks:
|
|
86
|
-
- Treat code blocks as read-only regions
|
|
87
|
-
- Only compress text outside them
|
|
88
|
-
- Do not merge sections around code
|
|
89
|
-
|
|
90
|
-
## Pattern
|
|
91
|
-
|
|
92
|
-
Original:
|
|
93
|
-
> 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.
|
|
94
|
-
|
|
95
|
-
Compressed:
|
|
96
|
-
> Run tests before push to main. Catch bugs early, prevent broken prod deploys.
|
|
97
|
-
|
|
98
|
-
Original:
|
|
99
|
-
> 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.
|
|
100
|
-
|
|
101
|
-
Compressed:
|
|
102
|
-
> Microservices architecture. API gateway route all requests to services. Auth service manage user sessions + JWT tokens.
|
|
103
|
-
|
|
104
|
-
## Boundaries
|
|
105
|
-
|
|
106
|
-
- ONLY compress natural language files (.md, .txt, .typ, .typst, .tex, extensionless)
|
|
107
|
-
- NEVER modify: .py, .js, .ts, .json, .yaml, .yml, .toml, .env, .lock, .css, .html, .xml, .sql, .sh
|
|
108
|
-
- If file has mixed content (prose + code), compress ONLY the prose sections
|
|
109
|
-
- If unsure whether something is code or prose, leave it unchanged
|
|
110
|
-
- 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
|
|
111
|
-
- Never compress FILE.original.md (skip it)
|
|
@@ -1,80 +0,0 @@
|
|
|
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()
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Caveman Compress CLI
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
caveman <filepath>
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
import sys
|
|
10
|
-
|
|
11
|
-
# Force UTF-8 on stdout/stderr before any code can print. Windows consoles
|
|
12
|
-
# default to cp1252 and crash on the ❌ glyphs in error/validation branches,
|
|
13
|
-
# masking the real error and leaving the user with a half-compressed file.
|
|
14
|
-
for _stream in (sys.stdout, sys.stderr):
|
|
15
|
-
reconfigure = getattr(_stream, "reconfigure", None)
|
|
16
|
-
if callable(reconfigure):
|
|
17
|
-
try:
|
|
18
|
-
reconfigure(encoding="utf-8", errors="replace")
|
|
19
|
-
except Exception:
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
|
-
from pathlib import Path
|
|
23
|
-
|
|
24
|
-
from .compress import backup_dir_for, compress_file
|
|
25
|
-
from .detect import detect_file_type, should_compress
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def print_usage():
|
|
29
|
-
print("Usage: caveman <filepath>")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def main():
|
|
33
|
-
if len(sys.argv) != 2:
|
|
34
|
-
print_usage()
|
|
35
|
-
sys.exit(1)
|
|
36
|
-
|
|
37
|
-
filepath = Path(sys.argv[1])
|
|
38
|
-
|
|
39
|
-
# Check file exists
|
|
40
|
-
if not filepath.exists():
|
|
41
|
-
print(f"❌ File not found: {filepath}")
|
|
42
|
-
sys.exit(1)
|
|
43
|
-
|
|
44
|
-
if not filepath.is_file():
|
|
45
|
-
print(f"❌ Not a file: {filepath}")
|
|
46
|
-
sys.exit(1)
|
|
47
|
-
|
|
48
|
-
filepath = filepath.resolve()
|
|
49
|
-
|
|
50
|
-
# Detect file type
|
|
51
|
-
file_type = detect_file_type(filepath)
|
|
52
|
-
|
|
53
|
-
print(f"Detected: {file_type}")
|
|
54
|
-
|
|
55
|
-
# Check if compressible
|
|
56
|
-
if not should_compress(filepath):
|
|
57
|
-
print("Skipping: file is not natural language (code/config)")
|
|
58
|
-
sys.exit(0)
|
|
59
|
-
|
|
60
|
-
print("Starting caveman compression...\n")
|
|
61
|
-
|
|
62
|
-
try:
|
|
63
|
-
success = compress_file(filepath)
|
|
64
|
-
|
|
65
|
-
if success:
|
|
66
|
-
print("\nCompression completed successfully")
|
|
67
|
-
backup_path = backup_dir_for(filepath) / (filepath.stem + ".original.md")
|
|
68
|
-
print(f"Compressed: {filepath}")
|
|
69
|
-
print(f"Original: {backup_path}")
|
|
70
|
-
sys.exit(0)
|
|
71
|
-
else:
|
|
72
|
-
print("\n❌ Compression failed after retries")
|
|
73
|
-
sys.exit(2)
|
|
74
|
-
|
|
75
|
-
except KeyboardInterrupt:
|
|
76
|
-
print("\nInterrupted by user")
|
|
77
|
-
sys.exit(130)
|
|
78
|
-
|
|
79
|
-
except Exception as e:
|
|
80
|
-
print(f"\n❌ Error: {e}")
|
|
81
|
-
sys.exit(1)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if __name__ == "__main__":
|
|
85
|
-
main()
|