@izhimu/pi-caveman 0.1.0 → 0.2.1
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 +26 -0
- package/README.md +43 -45
- package/extensions/caveman.ts +111 -144
- package/package.json +5 -1
- package/skills/caveman/README.md +52 -0
- package/skills/caveman/SKILL.md +16 -4
- package/skills/caveman-compress/README.md +176 -0
- package/skills/caveman-compress/SECURITY.md +31 -0
- package/skills/caveman-compress/SKILL.md +111 -0
- package/skills/caveman-compress/scripts/__init__.py +9 -0
- package/skills/caveman-compress/scripts/__main__.py +3 -0
- package/skills/caveman-compress/scripts/benchmark.py +80 -0
- package/skills/caveman-compress/scripts/cli.py +85 -0
- package/skills/caveman-compress/scripts/compress.py +505 -0
- package/skills/caveman-compress/scripts/detect.py +139 -0
- package/skills/caveman-compress/scripts/validate.py +408 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@izhimu/pi-caveman` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.2.1] - 2026-08-21
|
|
6
|
+
|
|
7
|
+
### Changed & Improved
|
|
8
|
+
- **Prompt Rules Upstream Sync**: Synchronized core compression rules with upstream Caveman v2.2.0 — added anti-expansion guards (no fake broken grammar), verb preservation on equal token cost, and clear external issue/ticket boundaries.
|
|
9
|
+
- **Robust Mode Parser**: Added quoted-span disambiguation to prevent quoted text like `"stop caveman"` from triggering deactivation; added punctuation and quote normalization for `/caveman` arguments.
|
|
10
|
+
- **Enhanced `caveman-compress`**: Fixed Windows `cp1252` encoding exceptions, improved CommonMark code fence parsing, and preserved original file line endings (CRLF/LF) atomically.
|
|
11
|
+
- **Skill Slimming**: Trimmed redundant cloud-dependent and generic workflow skills to reduce initial system prompt index overhead by ~75%.
|
|
12
|
+
|
|
13
|
+
## [0.2.0] - 2026-08-16
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Multi-skill integration for pi package format.
|
|
17
|
+
- Namespaced slash commands and extended mode parsing.
|
|
18
|
+
- Published package under `@izhimu/pi-caveman`.
|
|
19
|
+
|
|
20
|
+
## [0.1.0] - 2026-07-15
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- Initial release of pi-caveman extension for the Pi coding agent.
|
|
24
|
+
- 6 compression intensity levels (`lite`, `full`, `ultra`, `wenyan-lite`, `wenyan-full`, `wenyan-ultra`).
|
|
25
|
+
- Per-turn prompt reinforcement and auto-activation support.
|
|
26
|
+
- Session token tracking and estimated savings display via `/caveman-status`.
|
package/README.md
CHANGED
|
@@ -2,24 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://github.com/earendil-works/pi)
|
|
5
|
+
[](https://www.npmjs.com/package/@izhimu/pi-caveman)
|
|
5
6
|
|
|
6
|
-
Caveman mode for [pi](https://github.com/earendil-works/pi). Ultra-compressed communication — cuts **65% output tokens** (measured)
|
|
7
|
+
Caveman mode for [pi](https://github.com/earendil-works/pi) and [oh-my-pi](https://github.com/can1357/oh-my-pi). Ultra-compressed communication — cuts **65% output tokens** (measured) while maintaining full technical accuracy.
|
|
7
8
|
|
|
8
9
|
Upstream: [JuliusBrussee/caveman](https://github.com/JuliusBrussee/caveman)
|
|
9
10
|
|
|
10
11
|
## Features
|
|
11
12
|
|
|
12
|
-
- **Auto-activates** on every pi session (default: `full` intensity)
|
|
13
|
-
- **6 intensity levels** — from lite (professional
|
|
14
|
-
- **Per-turn reinforcement** keeps model
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **Token savings stats** — tracks and
|
|
13
|
+
- **Auto-activates** on every pi / oh-my-pi session (default: `full` intensity)
|
|
14
|
+
- **6 intensity levels** — from `lite` (professional, no filler) to `wenyan-ultra` (extreme classical Chinese compression)
|
|
15
|
+
- **Per-turn reinforcement** keeps the model concise even as context grows
|
|
16
|
+
- **Memory file compression** (`/caveman-compress`) — shrinks `AGENTS.md`, `CLAUDE.md`, and project notes with atomic backup and validation
|
|
17
|
+
- **Natural language triggers** — "talk like caveman", "be brief", "stop caveman", "normal mode" (with quote disambiguation)
|
|
18
|
+
- **Direct persistence** — `/caveman <mode>` instantly applies and saves default mode across sessions
|
|
19
|
+
- **Token savings stats** — tracks session output tokens and estimated savings via `/caveman-status`
|
|
19
20
|
|
|
20
21
|
## Install
|
|
21
22
|
|
|
22
|
-
###
|
|
23
|
+
### npm (recommended)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pi install @izhimu/pi-caveman
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### From git
|
|
23
30
|
|
|
24
31
|
```bash
|
|
25
32
|
# Global
|
|
@@ -46,15 +53,16 @@ pi -e ./extensions/caveman.ts
|
|
|
46
53
|
|
|
47
54
|
| Command | Effect |
|
|
48
55
|
|---------|--------|
|
|
49
|
-
| `/caveman` | Activate with default mode |
|
|
50
|
-
| `/caveman lite` | Lite mode — no filler, keep articles |
|
|
51
|
-
| `/caveman full` | Full mode — fragments OK, short synonyms |
|
|
52
|
-
| `/caveman ultra` | Ultra mode — one word when one word enough |
|
|
53
|
-
| `/caveman wenyan` | 文言文 mode (classical Chinese) |
|
|
54
|
-
| `/caveman off` | Deactivate |
|
|
55
|
-
| `/caveman-
|
|
56
|
-
| `/caveman-
|
|
57
|
-
|
|
56
|
+
| `/caveman` | Activate with default mode (persists) |
|
|
57
|
+
| `/caveman lite` | Lite mode — no filler/hedging, keep articles (persists) |
|
|
58
|
+
| `/caveman full` | Full mode — fragments OK, short synonyms (default, persists) |
|
|
59
|
+
| `/caveman ultra` | Ultra mode — one word when one word enough (persists) |
|
|
60
|
+
| `/caveman wenyan` | 文言文 mode (classical Chinese terseness, persists) |
|
|
61
|
+
| `/caveman off` | Deactivate caveman mode (persists) |
|
|
62
|
+
| `/caveman-compress <file>` | Compress memory file (`AGENTS.md`, `todos.md`, etc.) |
|
|
63
|
+
| `/caveman-status` | Show current mode, session tokens, and config paths |
|
|
64
|
+
|
|
65
|
+
All `/caveman <mode>` commands automatically persist to user config (`~/.config/caveman/config.json` or `%APPDATA%\caveman\config.json`).
|
|
58
66
|
|
|
59
67
|
Natural-language triggers also work: "talk like caveman", "stop caveman", "normal mode".
|
|
60
68
|
|
|
@@ -63,7 +71,7 @@ Natural-language triggers also work: "talk like caveman", "stop caveman", "norma
|
|
|
63
71
|
| Level | Description |
|
|
64
72
|
|-------|-------------|
|
|
65
73
|
| **lite** | No filler/hedging. Keep articles + full sentences. Professional but tight |
|
|
66
|
-
| **full** | Drop articles, fragments OK, short synonyms. Classic caveman |
|
|
74
|
+
| **full** | Drop articles, fragments OK, short synonyms. Classic caveman (default) |
|
|
67
75
|
| **ultra** | Strip conjunctions. One word when one word enough |
|
|
68
76
|
| **wenyan-lite** | Semi-classical Chinese. Drop filler but keep grammar structure |
|
|
69
77
|
| **wenyan-full** | Maximum classical Chinese terseness. 80-90% character reduction |
|
|
@@ -80,16 +88,16 @@ Natural-language triggers also work: "talk like caveman", "stop caveman", "norma
|
|
|
80
88
|
|
|
81
89
|
## Configuration
|
|
82
90
|
|
|
83
|
-
|
|
91
|
+
Switch and persist directly with `/caveman <mode>` (e.g. `/caveman ultra`).
|
|
84
92
|
|
|
85
93
|
Default mode resolution order:
|
|
86
94
|
|
|
87
95
|
1. `CAVEMAN_DEFAULT_MODE` environment variable
|
|
88
96
|
2. Repo-local: `.caveman/config.json` or `.caveman.json` (walks up to root)
|
|
89
|
-
3. User: `~/.config/caveman/config.json` (or `%APPDATA%\caveman\config.json` on Windows)
|
|
90
|
-
4. `full` (fallback)
|
|
97
|
+
3. User config: `~/.config/caveman/config.json` (or `%APPDATA%\caveman\config.json` on Windows)
|
|
98
|
+
4. `full` (fallback default)
|
|
91
99
|
|
|
92
|
-
Manual config:
|
|
100
|
+
Manual config file format:
|
|
93
101
|
```json
|
|
94
102
|
{
|
|
95
103
|
"defaultMode": "ultra"
|
|
@@ -98,43 +106,33 @@ Manual config:
|
|
|
98
106
|
|
|
99
107
|
## How It Works
|
|
100
108
|
|
|
101
|
-
pi loads extensions
|
|
109
|
+
pi loads extensions and skills declared in `package.json#pi`. This extension hooks into four lifecycle events:
|
|
102
110
|
|
|
103
111
|
1. **`session_start`** — writes mode flag, notifies user
|
|
104
|
-
2. **`before_agent_start`** — injects
|
|
105
|
-
3. **`input`** — intercepts `/caveman` commands and natural-language triggers
|
|
106
|
-
4. **`turn_end`** —
|
|
107
|
-
|
|
108
|
-
The `SKILL.md` in `skills/caveman/` is auto-discovered by pi's skill system and loaded into system context.
|
|
112
|
+
2. **`before_agent_start`** — injects filtered caveman rules per turn
|
|
113
|
+
3. **`input`** — intercepts `/caveman` commands and natural-language triggers (with quoted-span protection)
|
|
114
|
+
4. **`turn_end`** — accumulates token usage and savings stats
|
|
109
115
|
|
|
110
116
|
## Project Structure
|
|
111
117
|
|
|
112
118
|
```
|
|
113
119
|
pi-caveman/
|
|
114
120
|
├── extensions/
|
|
115
|
-
│ └── caveman.ts
|
|
121
|
+
│ └── caveman.ts # pi ExtensionAPI integration & mode manager
|
|
116
122
|
├── skills/
|
|
117
|
-
│
|
|
118
|
-
│
|
|
119
|
-
├──
|
|
123
|
+
│ ├── caveman/ # Core compression rules (SKILL.md)
|
|
124
|
+
│ └── caveman-compress/ # Local memory file compression engine
|
|
125
|
+
├── tests/ # Validation test suite
|
|
126
|
+
├── CHANGELOG.md
|
|
127
|
+
├── package.json # pi package manifest
|
|
120
128
|
├── tsconfig.json
|
|
121
129
|
├── LICENSE
|
|
122
130
|
└── README.md
|
|
123
131
|
```
|
|
124
132
|
|
|
125
|
-
##
|
|
126
|
-
|
|
127
|
-
Mode state persisted at `~/.pi/.caveman-active`. Mode transitions logged to `~/.pi/.caveman-mode-log.jsonl`.
|
|
128
|
-
|
|
129
|
-
## Contributing
|
|
130
|
-
|
|
131
|
-
Contributions welcome! Please:
|
|
133
|
+
## Changelog
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
2. Create a feature branch (`git checkout -b feat/amazing-feature`)
|
|
135
|
-
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
|
|
136
|
-
4. Push to the branch (`git push origin feat/amazing-feature`)
|
|
137
|
-
5. Open a Pull Request
|
|
135
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
138
136
|
|
|
139
137
|
## License
|
|
140
138
|
|
package/extensions/caveman.ts
CHANGED
|
@@ -25,14 +25,14 @@ const __dirname = dirname(__filename);
|
|
|
25
25
|
const VALID_MODES = [
|
|
26
26
|
"lite", "full", "ultra",
|
|
27
27
|
"wenyan-lite", "wenyan", "wenyan-full", "wenyan-ultra",
|
|
28
|
-
"
|
|
28
|
+
"compress",
|
|
29
29
|
] as const;
|
|
30
30
|
|
|
31
31
|
type Mode = (typeof VALID_MODES)[number];
|
|
32
32
|
|
|
33
33
|
// Modes with independent skills — not caveman intensity levels
|
|
34
34
|
const INDEPENDENT: Record<string, true> = {
|
|
35
|
-
|
|
35
|
+
compress: true,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
// ── Session stats ───────────────────────────────────────────────────────────
|
|
@@ -217,6 +217,20 @@ function logModeChange(newMode: string | null): void {
|
|
|
217
217
|
|
|
218
218
|
// ── Mode switching ──────────────────────────────────────────────────────────
|
|
219
219
|
|
|
220
|
+
function saveUserConfigMode(mode: string): void {
|
|
221
|
+
try {
|
|
222
|
+
const configDir = cavemanConfigDir();
|
|
223
|
+
const cfgPath = join(configDir, "config.json");
|
|
224
|
+
if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
|
|
225
|
+
let existing: Record<string, unknown> = {};
|
|
226
|
+
if (existsSync(cfgPath)) {
|
|
227
|
+
try { existing = JSON.parse(readFileSync(cfgPath, "utf-8")); } catch {}
|
|
228
|
+
}
|
|
229
|
+
existing.defaultMode = mode;
|
|
230
|
+
writeFileSync(cfgPath, JSON.stringify(existing, null, 2) + "\n", { mode: 0o600 });
|
|
231
|
+
} catch {}
|
|
232
|
+
}
|
|
233
|
+
|
|
220
234
|
function applyMode(mode: string | "off"): void {
|
|
221
235
|
if (mode === "off") { logModeChange(null); deleteFlag(); }
|
|
222
236
|
else { logModeChange(mode); writeFlag(mode); }
|
|
@@ -240,46 +254,85 @@ function clearStatus(ui: UI): void {
|
|
|
240
254
|
ui.ui.notify("caveman: off", "info");
|
|
241
255
|
}
|
|
242
256
|
|
|
243
|
-
// ── Mode parsing (mirrors caveman
|
|
257
|
+
// ── Mode parsing (mirrors caveman hooks/caveman-parse.js) ───────────────────
|
|
258
|
+
|
|
259
|
+
const QUOTED_SPAN_REGEX = /(["`])(?:(?!\1).)*\1/g;
|
|
260
|
+
|
|
261
|
+
function normalizeModeArg(arg: string): string {
|
|
262
|
+
return (arg || "").replace(/^[^a-z0-9]+/, "").replace(/[^a-z0-9-]+$/, "");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
interface ModeResolution {
|
|
266
|
+
action: "set" | "clear" | "unresolved";
|
|
267
|
+
mode?: string;
|
|
268
|
+
independentMode?: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function resolveModeArg(rawArg: string, getDefault: () => string): ModeResolution {
|
|
272
|
+
const arg = normalizeModeArg(rawArg);
|
|
273
|
+
if (!arg) {
|
|
274
|
+
if (rawArg) return { action: "unresolved" };
|
|
275
|
+
const mode = getDefault();
|
|
276
|
+
return mode === "off" ? { action: "clear" } : { action: "set", mode };
|
|
277
|
+
}
|
|
278
|
+
if (arg === "off" || arg === "stop" || arg === "disable") return { action: "clear" };
|
|
279
|
+
if (arg === "wenyan-full") return { action: "set", mode: "wenyan" };
|
|
280
|
+
if (isValidMode(arg) && !INDEPENDENT[arg]) return { action: "set", mode: arg };
|
|
281
|
+
if (INDEPENDENT[arg]) return { action: "unresolved", independentMode: arg };
|
|
282
|
+
return { action: "unresolved" };
|
|
283
|
+
}
|
|
244
284
|
|
|
245
285
|
function parseModeChange(promptRaw: string): string | "off" | null {
|
|
246
286
|
let prompt = (promptRaw || "").trim();
|
|
247
287
|
if (!prompt) return null;
|
|
248
288
|
|
|
289
|
+
const collapsed = prompt.toLowerCase().replace(/\s+/g, " ");
|
|
290
|
+
const naturalLanguage = !prompt.startsWith("/");
|
|
291
|
+
const nlPrompt = naturalLanguage ? collapsed.replace(QUOTED_SPAN_REGEX, " ") : "";
|
|
292
|
+
|
|
249
293
|
// Natural-language deactivation (checked first)
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
294
|
+
if (naturalLanguage) {
|
|
295
|
+
const wantsOff =
|
|
296
|
+
/\b(stop|disable|deactivate|quit|exit|kill)\s+(the\s+)?caveman\b/.test(nlPrompt) ||
|
|
297
|
+
/\bcaveman(\s+mode)?\s+(off|stop|disabled?)\b/.test(nlPrompt) ||
|
|
298
|
+
/\bturn\s+off\s+(the\s+)?caveman\b/.test(nlPrompt) ||
|
|
299
|
+
/^(please\s+)?(go\s+|back\s+to\s+|switch\s+(back\s+)?to\s+|return\s+to\s+)?normal\s+mode\b/.test(nlPrompt) ||
|
|
300
|
+
(/\bnormal\s+mode\b/.test(nlPrompt) && /\bcaveman\b/.test(nlPrompt));
|
|
301
|
+
|
|
302
|
+
if (wantsOff) return "off";
|
|
303
|
+
|
|
304
|
+
// Natural-language activation (exclude questions)
|
|
305
|
+
const isQuestion =
|
|
306
|
+
/^(what|whats|what's|how|why|when|where|who|does|do|did|is|are|can|could|would|should|tell me|explain)\b/.test(nlPrompt);
|
|
307
|
+
|
|
308
|
+
if (!isQuestion) {
|
|
309
|
+
if (
|
|
310
|
+
/\b(activate|enable|start|turn on|use|switch to|want|give me)\b[^.]{0,40}\bcaveman\b/.test(nlPrompt) ||
|
|
311
|
+
/\btalk like\b[^.]{0,40}\bcaveman\b/.test(nlPrompt) ||
|
|
312
|
+
/\bcaveman\s+mode\s+(on|please|now)\b/.test(nlPrompt) ||
|
|
313
|
+
/^caveman(\s+mode)?\s*[.!]*$/.test(nlPrompt) ||
|
|
314
|
+
/\b(less tokens|fewer tokens|be brief|be terse|shorter answers)\b(?!\s+(in|for|on|about|when|during|with)\b)/.test(nlPrompt)
|
|
315
|
+
) {
|
|
316
|
+
const mode = resolveDefault();
|
|
317
|
+
return mode !== "off" ? mode : null;
|
|
318
|
+
}
|
|
273
319
|
}
|
|
274
320
|
}
|
|
275
321
|
|
|
276
|
-
//
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
322
|
+
// Slash-command (support bare and namespaced /caveman:<cmd>)
|
|
323
|
+
if (prompt.startsWith("/caveman")) {
|
|
324
|
+
const parts = prompt.split(/\s+/);
|
|
325
|
+
const cmd = parts[0].toLowerCase();
|
|
326
|
+
const rawArg = parts[1] || "";
|
|
327
|
+
|
|
328
|
+
if (cmd === "/caveman-compress" || cmd === "/caveman:caveman-compress") return "compress";
|
|
329
|
+
|
|
330
|
+
if (cmd === "/caveman" || cmd === "/caveman:caveman") {
|
|
331
|
+
const res = resolveModeArg(rawArg, resolveDefault);
|
|
332
|
+
if (res.action === "set" && res.mode) return res.mode;
|
|
333
|
+
if (res.action === "clear") return "off";
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
283
336
|
}
|
|
284
337
|
|
|
285
338
|
return null;
|
|
@@ -400,48 +453,50 @@ export default function cavemanExtension(pi: ExtensionAPI) {
|
|
|
400
453
|
|
|
401
454
|
// ── /caveman command ──────────────────────────────────────────────────
|
|
402
455
|
pi.registerCommand("caveman", {
|
|
403
|
-
description: "Switch caveman mode (lite|full|ultra|wenyan|off)",
|
|
456
|
+
description: "Switch and persist caveman mode (lite|full|ultra|wenyan|off)",
|
|
404
457
|
getArgumentCompletions: (prefix) => getModeCompletions(prefix),
|
|
405
458
|
handler: async (args, ctx) => {
|
|
406
|
-
const
|
|
459
|
+
const rawArg = (args || "").trim().toLowerCase();
|
|
407
460
|
|
|
408
|
-
//
|
|
409
|
-
if (!
|
|
410
|
-
const
|
|
411
|
-
|
|
461
|
+
// Bare /caveman -> activate default and persist
|
|
462
|
+
if (!rawArg) {
|
|
463
|
+
const def = resolveDefault();
|
|
464
|
+
const mode = def === "off" ? "full" : def;
|
|
412
465
|
applyMode(mode);
|
|
466
|
+
saveUserConfigMode(mode);
|
|
413
467
|
notifyMode(ctx, mode);
|
|
414
468
|
return;
|
|
415
469
|
}
|
|
416
470
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
applyMode(
|
|
421
|
-
|
|
471
|
+
const res = resolveModeArg(rawArg, resolveDefault);
|
|
472
|
+
|
|
473
|
+
if (res.action === "set" && res.mode) {
|
|
474
|
+
applyMode(res.mode);
|
|
475
|
+
saveUserConfigMode(res.mode);
|
|
476
|
+
notifyMode(ctx, res.mode);
|
|
422
477
|
return;
|
|
423
478
|
}
|
|
424
479
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
applyMode("
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
480
|
+
if (res.action === "clear") {
|
|
481
|
+
sessionExplicitOff = true;
|
|
482
|
+
applyMode("off");
|
|
483
|
+
saveUserConfigMode("off");
|
|
484
|
+
clearStatus(ctx);
|
|
431
485
|
return;
|
|
432
486
|
}
|
|
433
487
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
488
|
+
if (res.independentMode && ctx.hasUI) {
|
|
489
|
+
ctx.ui.notify(
|
|
490
|
+
`"${res.independentMode}" is an independent skill. Use: /caveman-${res.independentMode}`,
|
|
491
|
+
"warning",
|
|
492
|
+
);
|
|
438
493
|
return;
|
|
439
494
|
}
|
|
440
495
|
|
|
441
496
|
// Unknown
|
|
442
497
|
if (ctx.hasUI) {
|
|
443
498
|
ctx.ui.notify(
|
|
444
|
-
`unknown mode "${
|
|
499
|
+
`unknown mode "${rawArg}". Use: lite|full|ultra|wenyan-lite|wenyan|wenyan-ultra|off`,
|
|
445
500
|
"warning",
|
|
446
501
|
);
|
|
447
502
|
}
|
|
@@ -497,95 +552,6 @@ export default function cavemanExtension(pi: ExtensionAPI) {
|
|
|
497
552
|
},
|
|
498
553
|
});
|
|
499
554
|
|
|
500
|
-
// ── /caveman-config command ──────────────────────────────────────────
|
|
501
|
-
const INTENSITY_MODES = ["lite", "full", "ultra", "wenyan-lite", "wenyan", "wenyan-ultra", "off"];
|
|
502
|
-
|
|
503
|
-
pi.registerCommand("caveman-config", {
|
|
504
|
-
description: "Set default caveman mode for new sessions",
|
|
505
|
-
getArgumentCompletions: (prefix) => getModeCompletions(prefix),
|
|
506
|
-
handler: async (args, ctx) => {
|
|
507
|
-
const arg = (args || "").trim().toLowerCase();
|
|
508
|
-
|
|
509
|
-
// No arg → show current config + available options
|
|
510
|
-
if (!arg) {
|
|
511
|
-
const def = resolveDefault();
|
|
512
|
-
const configPath = join(cavemanConfigDir(), "config.json");
|
|
513
|
-
const repoConfig = findRepoConfig(process.cwd());
|
|
514
|
-
|
|
515
|
-
const lines: string[] = [
|
|
516
|
-
`Current default: ${def}`,
|
|
517
|
-
"",
|
|
518
|
-
"Available modes:",
|
|
519
|
-
" lite — no filler/hedging, keep articles + full sentences",
|
|
520
|
-
" full — drop articles, fragments OK, short synonyms (default)",
|
|
521
|
-
" ultra — one word when one word enough, no abbreviations",
|
|
522
|
-
" wenyan-lite — semi-classical, keep grammar structure",
|
|
523
|
-
" wenyan — maximum classical terseness (文言文)",
|
|
524
|
-
" wenyan-ultra — extreme abbreviation, classical feel",
|
|
525
|
-
" off — disabled by default",
|
|
526
|
-
"",
|
|
527
|
-
"Usage: /caveman-config <mode>",
|
|
528
|
-
`Config file: ${configPath}`,
|
|
529
|
-
];
|
|
530
|
-
if (process.env.CAVEMAN_DEFAULT_MODE) {
|
|
531
|
-
lines.push(`Note: CAVEMAN_DEFAULT_MODE=${process.env.CAVEMAN_DEFAULT_MODE} overrides config file`);
|
|
532
|
-
}
|
|
533
|
-
if (repoConfig) {
|
|
534
|
-
lines.push(`Note: repo config at ${repoConfig} overrides user config`);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const msg = lines.join("\n");
|
|
538
|
-
if (ctx.hasUI) ctx.ui.notify(msg, "info");
|
|
539
|
-
pi.sendMessage({
|
|
540
|
-
customType: "caveman-config",
|
|
541
|
-
content: msg,
|
|
542
|
-
display: true,
|
|
543
|
-
attribution: "user",
|
|
544
|
-
}, { triggerTurn: false });
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
// Validate
|
|
549
|
-
if (!isValidMode(arg) && arg !== "off") {
|
|
550
|
-
if (ctx.hasUI) {
|
|
551
|
-
ctx.ui.notify(
|
|
552
|
-
`unknown mode "${arg}". Available: ${INTENSITY_MODES.join(", ")}`,
|
|
553
|
-
"warning",
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// Write to user config
|
|
560
|
-
const configDir = cavemanConfigDir();
|
|
561
|
-
const cfgPath = join(configDir, "config.json");
|
|
562
|
-
|
|
563
|
-
try {
|
|
564
|
-
if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
|
|
565
|
-
|
|
566
|
-
let existing: Record<string, unknown> = {};
|
|
567
|
-
if (existsSync(cfgPath)) {
|
|
568
|
-
try { existing = JSON.parse(readFileSync(cfgPath, "utf-8")); } catch {}
|
|
569
|
-
}
|
|
570
|
-
existing.defaultMode = arg;
|
|
571
|
-
writeFileSync(cfgPath, JSON.stringify(existing, null, 2) + "\n", { mode: 0o600 });
|
|
572
|
-
|
|
573
|
-
const label = arg === "off" ? "off" : arg;
|
|
574
|
-
if (ctx.hasUI) {
|
|
575
|
-
ctx.ui.notify(`default mode set to: ${label}`, "info");
|
|
576
|
-
ctx.ui.notify(`config: ${cfgPath}`, "info");
|
|
577
|
-
}
|
|
578
|
-
pi.sendMessage({
|
|
579
|
-
customType: "caveman-config",
|
|
580
|
-
content: `Default mode saved: ${label}\nConfig: ${cfgPath}\nEffective on next session.`,
|
|
581
|
-
display: true,
|
|
582
|
-
attribution: "user",
|
|
583
|
-
}, { triggerTurn: false });
|
|
584
|
-
} catch (e) {
|
|
585
|
-
if (ctx.hasUI) ctx.ui.notify(`failed to write config: ${e}`, "error");
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
});
|
|
589
555
|
|
|
590
556
|
// ── before_agent_start: per-turn reinforcement ────────────────────────
|
|
591
557
|
// Injects full SKILL.md content (filtered to active mode) + reinforcement line.
|
|
@@ -623,6 +589,7 @@ export default function cavemanExtension(pi: ExtensionAPI) {
|
|
|
623
589
|
if (change) {
|
|
624
590
|
if (change === "off") sessionExplicitOff = true;
|
|
625
591
|
applyMode(change);
|
|
592
|
+
saveUserConfigMode(change);
|
|
626
593
|
}
|
|
627
594
|
});
|
|
628
595
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izhimu/pi-caveman",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Caveman mode for pi — ultra-compressed communication, 65% output token savings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": ["pi-package", "caveman", "token-savings", "compression"],
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@earendil-works/pi-coding-agent": "*"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --test --test-force-exit tests/*.test.mjs"
|
|
18
|
+
},
|
|
16
19
|
"pi": {
|
|
17
20
|
"extensions": ["./extensions"],
|
|
18
21
|
"skills": ["./skills"]
|
|
@@ -21,6 +24,7 @@
|
|
|
21
24
|
"extensions/",
|
|
22
25
|
"skills/",
|
|
23
26
|
"README.md",
|
|
27
|
+
"CHANGELOG.md",
|
|
24
28
|
"LICENSE"
|
|
25
29
|
]
|
|
26
30
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# caveman
|
|
2
|
+
|
|
3
|
+
Talk like smart caveman. Same brain, fewer tokens.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Compress model responses to caveman-style prose by dropping articles, filler,
|
|
8
|
+
pleasantries, and hedging. Instruction preserves technical detail, code blocks,
|
|
9
|
+
error strings, and symbols. Result depends on model and workload; no aggregate
|
|
10
|
+
reduction or quality-equivalence claim is published, and mode persists until
|
|
11
|
+
changed or stopped.
|
|
12
|
+
|
|
13
|
+
Six intensity levels:
|
|
14
|
+
|
|
15
|
+
| Level | What change |
|
|
16
|
+
|-------|-------------|
|
|
17
|
+
| `lite` | Drop filler/hedging. Sentences stay full. Professional but tight. |
|
|
18
|
+
| `full` | Default. Drop articles, fragments OK, short synonyms. |
|
|
19
|
+
| `ultra` | Bare fragments. Abbreviations (DB, auth, fn). Arrows for causality. |
|
|
20
|
+
| `wenyan-lite` | Classical Chinese register, light compression. |
|
|
21
|
+
| `wenyan-full` | Maximum 文言文 compression. |
|
|
22
|
+
| `wenyan-ultra` | Extreme classical compression. |
|
|
23
|
+
|
|
24
|
+
Auto-clarity rule: caveman drops to normal prose for security warnings, irreversible-action confirmations, multi-step sequences where fragment ambiguity risks misread, and when user repeats a question. Resumes after the clear part.
|
|
25
|
+
|
|
26
|
+
## How to invoke
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
/caveman # full mode (default)
|
|
30
|
+
/caveman lite # lighter compression
|
|
31
|
+
/caveman ultra # extreme compression
|
|
32
|
+
/caveman wenyan # classical Chinese
|
|
33
|
+
stop caveman # back to normal prose
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Example output
|
|
37
|
+
|
|
38
|
+
Question: "Why does my React component re-render?"
|
|
39
|
+
|
|
40
|
+
Normal prose:
|
|
41
|
+
> Your component re-renders because you create a new object reference each render. Wrapping it in `useMemo` will fix the issue.
|
|
42
|
+
|
|
43
|
+
Caveman (full):
|
|
44
|
+
> New object ref each render. Inline object prop = new ref = re-render. Wrap in `useMemo`.
|
|
45
|
+
|
|
46
|
+
Caveman (ultra):
|
|
47
|
+
> Inline obj prop → new ref → re-render. `useMemo`.
|
|
48
|
+
|
|
49
|
+
## See also
|
|
50
|
+
|
|
51
|
+
- [`SKILL.md`](./SKILL.md): full LLM-facing instructions
|
|
52
|
+
- [Caveman README](../../README.md): repo overview, install, benchmarks
|
package/skills/caveman/SKILL.md
CHANGED
|
@@ -14,13 +14,21 @@ Respond terse like smart caveman. All technical substance stay. Only fluff die.
|
|
|
14
14
|
|
|
15
15
|
ACTIVE EVERY RESPONSE. No revert after many turns. No filler drift. Still active if unsure. Off only: "stop caveman" / "normal mode".
|
|
16
16
|
|
|
17
|
-
Default: **full**. Switch: `/caveman lite|full|ultra`.
|
|
17
|
+
Default: **full**. Switch: `/caveman lite|full|ultra|wenyan-lite|wenyan-full|wenyan-ultra|off`.
|
|
18
18
|
|
|
19
19
|
## Rules
|
|
20
20
|
|
|
21
21
|
Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging. Fragments OK. Short synonyms (big not extensive, fix not "implement a solution for"). No tool-call narration, no decorative tables/emoji, no dumping long raw error logs unless asked — quote shortest decisive line. Standard well-known tech acronyms OK (DB/API/HTTP); never invent new abbreviations (cfg/impl/req/res/fn) — tokenizer split them same as full word: zero token saved, reader still decode. Full word cheaper AND clearer. No causal arrows (→) either — own token, save nothing. Technical terms exact. Code blocks unchanged. Errors quoted exact.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Never drop not/never/no/only/except — flip meaning worse than any token saved. Numbers, units exact.
|
|
24
|
+
|
|
25
|
+
Never ADD word to sound caveman. Compression only — style never grow output. No inserted pronoun or copula to fake broken grammar: "when it not" cost one token more than "when not" and say same thing. Keep correct verb form when correct form cost same — "sees" one token, "see" one token, so mangle buy nothing and read worse. Same rule as abbreviations and arrows: if caveman phrasing not shorter than plain phrasing, use plain.
|
|
26
|
+
|
|
27
|
+
Tool calls: fire direct. No preamble, plan, or progress note before or between calls. After result: next call direct or final answer — never announce next call. Text before call only to clarify, warn security/irreversible, or resolve ambiguity.
|
|
28
|
+
|
|
29
|
+
Preserve user's dominant language exactly — reply in the language user writes, never switch regardless of example text or multilingual context elsewhere. Compress the style, not the language. Every emitted line in that language — openings, pre-tool status lines, all — not just final reply. ALWAYS keep technical terms, code, API names, CLI commands, commit-type keywords (feat/fix/...), and exact error strings verbatim — unless user explicitly ask for translation.
|
|
30
|
+
|
|
31
|
+
'Drop articles' = article languages only. Where small markers carry case/role (particles, postpositions), keep them — grammar, not filler; compress politeness/filler instead.
|
|
24
32
|
|
|
25
33
|
No self-reference. Never name or announce the style. No "caveman mode on", "me caveman think", no third-person caveman tags. Output caveman-only — never normal answer plus "Caveman:" recap. Exception: user explicitly ask what the mode is.
|
|
26
34
|
|
|
@@ -37,7 +45,7 @@ Yes: "Bug in auth middleware. Token expiry check use `<` not `<=`. Fix:"
|
|
|
37
45
|
| **full** | Drop articles, fragments OK, short synonyms. Classic caveman. No tool-call narration, no decorative tables/emoji, no long raw error-log dumps unless asked. Standard acronyms OK; no invented abbreviations |
|
|
38
46
|
| **ultra** | Strip conjunctions when cause-then-effect stay unambiguous. One word when one word enough. State each fact once. NO prose abbreviations (cfg/impl/req/res/fn/auth), NO arrows (X → Y) — measured zero token saving under tokenizer, cost decode clarity. Code symbols, function names, API names, error strings: never touch |
|
|
39
47
|
| **wenyan-lite** | Semi-classical. Drop filler/hedging but keep grammar structure, classical register |
|
|
40
|
-
| **wenyan-full** | Maximum classical terseness. Fully 文言文. 80-90% character reduction. Classical sentence patterns, verbs precede objects, subjects often omitted, classical particles (之/乃/為/其) |
|
|
48
|
+
| **wenyan-full** | Maximum classical terseness. Fully 文言文. 80-90% character reduction — chars, not tokens. Classical sentence patterns, verbs precede objects, subjects often omitted, classical particles (之/乃/為/其) |
|
|
41
49
|
| **wenyan-ultra** | Extreme abbreviation while keeping classical Chinese feel. Maximum compression, ultra terse |
|
|
42
50
|
|
|
43
51
|
Example — "Why React component re-render?"
|
|
@@ -55,6 +63,8 @@ Example — "Explain database connection pooling."
|
|
|
55
63
|
- wenyan-full: "池蓄已開之連,不逐請而新開,省握手之費。"
|
|
56
64
|
- wenyan-ultra: "池蓄連,免逐請新開,省握手。"
|
|
57
65
|
|
|
66
|
+
Classical chars = wenyan modes only. Never swap a word to a classical char to shrink at non-wenyan levels.
|
|
67
|
+
|
|
58
68
|
## Auto-Clarity
|
|
59
69
|
|
|
60
70
|
Drop caveman when:
|
|
@@ -66,6 +76,8 @@ Drop caveman when:
|
|
|
66
76
|
|
|
67
77
|
Resume caveman after clear part done.
|
|
68
78
|
|
|
79
|
+
Example shows FORMAT only — write warning in session language, not example's.
|
|
80
|
+
|
|
69
81
|
Example — destructive op:
|
|
70
82
|
> **Warning:** This will permanently delete all rows in the `users` table and cannot be undone.
|
|
71
83
|
> ```sql
|
|
@@ -75,4 +87,4 @@ Example — destructive op:
|
|
|
75
87
|
|
|
76
88
|
## Boundaries
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
Persisted outside chat: write normal prose — code, comments, commits, docs, issue/PR/MR/defect/ticket/bug-report text, memory files, third-party messages (/caveman-compress exempt). "Open a defect" or "file a bug" mean the same as "open issue": body go to other humans, so body normal English. "stop caveman" or "normal mode": revert. Level persist until changed or session end.
|