@izhimu/pi-caveman 0.2.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +36 -44
  3. package/extensions/caveman.ts +101 -149
  4. package/package.json +5 -1
  5. package/skills/caveman/README.md +52 -48
  6. package/skills/caveman/SKILL.md +3 -1
  7. package/skills/caveman-compress/README.md +42 -29
  8. package/skills/caveman-compress/scripts/compress.py +113 -22
  9. package/skills/caveman-compress/scripts/validate.py +193 -6
  10. package/skills/cavecrew/README.md +0 -61
  11. package/skills/cavecrew/SKILL.md +0 -82
  12. package/skills/caveman-commit/README.md +0 -44
  13. package/skills/caveman-commit/SKILL.md +0 -65
  14. package/skills/caveman-discover/SKILL.md +0 -118
  15. package/skills/caveman-evidence-review/SKILL.md +0 -144
  16. package/skills/caveman-explore/SKILL.md +0 -42
  17. package/skills/caveman-explore/package.json +0 -12
  18. package/skills/caveman-explore/tests/skill-file.test.mjs +0 -44
  19. package/skills/caveman-help/README.md +0 -38
  20. package/skills/caveman-help/SKILL.md +0 -63
  21. package/skills/caveman-learn/CLAUDE.md +0 -32
  22. package/skills/caveman-learn/README.md +0 -29
  23. package/skills/caveman-learn/SKILL.md +0 -69
  24. package/skills/caveman-learn/package.json +0 -12
  25. package/skills/caveman-learn/tests/skill-file.test.mjs +0 -44
  26. package/skills/caveman-manage/SKILL.md +0 -114
  27. package/skills/caveman-optimize/SKILL.md +0 -114
  28. package/skills/caveman-review/README.md +0 -33
  29. package/skills/caveman-review/SKILL.md +0 -55
  30. package/skills/caveman-setup/SKILL.md +0 -224
  31. package/skills/caveman-stats/README.md +0 -36
  32. package/skills/caveman-stats/SKILL.md +0 -12
  33. package/skills/investigate-first/SKILL.md +0 -16
  34. package/skills/investigate-first/agents/openai.yaml +0 -4
  35. package/skills/lean-build/SKILL.md +0 -18
  36. package/skills/lean-build/agents/openai.yaml +0 -4
  37. package/skills/migration/SKILL.md +0 -17
  38. package/skills/migration/agents/openai.yaml +0 -4
  39. package/skills/safe-refactor/SKILL.md +0 -16
  40. package/skills/safe-refactor/agents/openai.yaml +0 -4
  41. package/skills/surgical-patch/SKILL.md +0 -16
  42. package/skills/surgical-patch/agents/openai.yaml +0 -4
  43. package/skills/verify-and-stop/SKILL.md +0 -16
  44. package/skills/verify-and-stop/agents/openai.yaml +0 -4
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,20 +2,21 @@
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
4
  [![pi extension](https://img.shields.io/badge/pi-extension-green.svg)](https://github.com/earendil-works/pi)
5
+ [![npm version](https://img.shields.io/npm/v/@izhimu/pi-caveman.svg)](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), full technical accuracy.
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 but tight) to wenyan-ultra (classical Chinese extreme compression)
14
- - **Per-turn reinforcement** keeps model in caveman mode even after context compression
15
- - **Natural language triggers** — "talk like caveman", "be brief", "stop caveman"
16
- - **Status bar** shows current mode with color-coded indicator
17
- - **Configurable** via env var, repo-local, or user-global config
18
- - **Token savings stats** — tracks and displays estimated savings per session
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
 
@@ -52,15 +53,16 @@ pi -e ./extensions/caveman.ts
52
53
 
53
54
  | Command | Effect |
54
55
  |---------|--------|
55
- | `/caveman` | Activate with default mode |
56
- | `/caveman lite` | Lite mode — no filler, keep articles |
57
- | `/caveman full` | Full mode — fragments OK, short synonyms |
58
- | `/caveman ultra` | Ultra mode — one word when one word enough |
59
- | `/caveman wenyan` | 文言文 mode (classical Chinese) |
60
- | `/caveman off` | Deactivate |
61
- | `/caveman-config` | Show/set default mode |
62
- | `/caveman-off` | Convenience alias for `/caveman off` |
63
- | `/caveman-status` | Show current mode and config |
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`).
64
66
 
65
67
  Natural-language triggers also work: "talk like caveman", "stop caveman", "normal mode".
66
68
 
@@ -69,7 +71,7 @@ Natural-language triggers also work: "talk like caveman", "stop caveman", "norma
69
71
  | Level | Description |
70
72
  |-------|-------------|
71
73
  | **lite** | No filler/hedging. Keep articles + full sentences. Professional but tight |
72
- | **full** | Drop articles, fragments OK, short synonyms. Classic caveman |
74
+ | **full** | Drop articles, fragments OK, short synonyms. Classic caveman (default) |
73
75
  | **ultra** | Strip conjunctions. One word when one word enough |
74
76
  | **wenyan-lite** | Semi-classical Chinese. Drop filler but keep grammar structure |
75
77
  | **wenyan-full** | Maximum classical Chinese terseness. 80-90% character reduction |
@@ -86,16 +88,16 @@ Natural-language triggers also work: "talk like caveman", "stop caveman", "norma
86
88
 
87
89
  ## Configuration
88
90
 
89
- Quickest way: `/caveman-config ultra` — writes user config, shows all available modes.
91
+ Switch and persist directly with `/caveman <mode>` (e.g. `/caveman ultra`).
90
92
 
91
93
  Default mode resolution order:
92
94
 
93
95
  1. `CAVEMAN_DEFAULT_MODE` environment variable
94
96
  2. Repo-local: `.caveman/config.json` or `.caveman.json` (walks up to root)
95
- 3. User: `~/.config/caveman/config.json` (or `%APPDATA%\caveman\config.json` on Windows)
96
- 4. `full` (fallback)
97
+ 3. User config: `~/.config/caveman/config.json` (or `%APPDATA%\caveman\config.json` on Windows)
98
+ 4. `full` (fallback default)
97
99
 
98
- Manual config:
100
+ Manual config file format:
99
101
  ```json
100
102
  {
101
103
  "defaultMode": "ultra"
@@ -104,43 +106,33 @@ Manual config:
104
106
 
105
107
  ## How It Works
106
108
 
107
- pi loads extensions from `~/.pi/agent/extensions/` and `.pi/extensions/`. This extension hooks into four lifecycle events:
109
+ pi loads extensions and skills declared in `package.json#pi`. This extension hooks into four lifecycle events:
108
110
 
109
111
  1. **`session_start`** — writes mode flag, notifies user
110
- 2. **`before_agent_start`** — injects reinforcement line per turn
111
- 3. **`input`** — intercepts `/caveman` commands and natural-language triggers
112
- 4. **`turn_end`** — updates status bar with savings stats
113
-
114
- 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
115
115
 
116
116
  ## Project Structure
117
117
 
118
118
  ```
119
119
  pi-caveman/
120
120
  ├── extensions/
121
- │ └── caveman.ts # pi ExtensionAPI integration
121
+ │ └── caveman.ts # pi ExtensionAPI integration & mode manager
122
122
  ├── skills/
123
- │ └── caveman/
124
- │ └── SKILL.md # Caveman behavior rules
125
- ├── package.json # pi package manifest
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
126
128
  ├── tsconfig.json
127
129
  ├── LICENSE
128
130
  └── README.md
129
131
  ```
130
132
 
131
- ## Flag File
132
-
133
- Mode state persisted at `~/.pi/.caveman-active`. Mode transitions logged to `~/.pi/.caveman-mode-log.jsonl`.
134
-
135
- ## Contributing
136
-
137
- Contributions welcome! Please:
133
+ ## Changelog
138
134
 
139
- 1. Fork the repository
140
- 2. Create a feature branch (`git checkout -b feat/amazing-feature`)
141
- 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
142
- 4. Push to the branch (`git push origin feat/amazing-feature`)
143
- 5. Open a Pull Request
135
+ See [CHANGELOG.md](./CHANGELOG.md) for release history.
144
136
 
145
137
  ## License
146
138
 
@@ -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
- "commit", "review", "compress",
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
- commit: true, review: true, compress: true,
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); }
@@ -242,58 +256,82 @@ function clearStatus(ui: UI): void {
242
256
 
243
257
  // ── Mode parsing (mirrors caveman hooks/caveman-parse.js) ───────────────────
244
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
+ }
284
+
245
285
  function parseModeChange(promptRaw: string): string | "off" | null {
246
286
  let prompt = (promptRaw || "").trim();
247
287
  if (!prompt) return null;
248
288
 
249
- prompt = prompt.toLowerCase().replace(/\s+/g, " ");
289
+ const collapsed = prompt.toLowerCase().replace(/\s+/g, " ");
290
+ const naturalLanguage = !prompt.startsWith("/");
291
+ const nlPrompt = naturalLanguage ? collapsed.replace(QUOTED_SPAN_REGEX, " ") : "";
250
292
 
251
293
  // Natural-language deactivation (checked first)
252
- const wantsOff =
253
- /\b(stop|disable|deactivate|quit|exit|kill)\s+(the\s+)?caveman\b/.test(prompt) ||
254
- /\bcaveman(\s+mode)?\s+(off|stop|disabled?)\b/.test(prompt) ||
255
- /\bturn\s+off\s+(the\s+)?caveman\b/.test(prompt) ||
256
- /^(please\s+)?(go\s+|back\s+to\s+|switch\s+(back\s+)?to\s+|return\s+to\s+)?normal\s+mode\b/.test(prompt) ||
257
- (/\bnormal\s+mode\b/.test(prompt) && /\bcaveman\b/.test(prompt));
258
-
259
- if (wantsOff) return "off";
260
-
261
- // Natural-language activation (exclude questions)
262
- const isQuestion =
263
- /^(what|whats|what's|how|why|when|where|who|does|do|did|is|are|can|could|would|should|tell me|explain)\b/.test(prompt);
264
-
265
- if (!isQuestion) {
266
- if (
267
- /\b(activate|enable|start|turn on|use|switch to|want|give me)\b[^.]{0,40}\bcaveman\b/.test(prompt) ||
268
- /\btalk like\b[^.]{0,40}\bcaveman\b/.test(prompt) ||
269
- /\bcaveman\s+mode\s+(on|please|now)\b/.test(prompt) ||
270
- /^caveman(\s+mode)?\s*[.!]*$/.test(prompt) ||
271
- /\b(less tokens|fewer tokens|be brief|be terse|shorter answers)\b(?!\s+(in|for|on|about|when|during|with)\b)/.test(prompt)
272
- ) {
273
- const mode = resolveDefault();
274
- return mode !== "off" ? mode : null;
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
+ }
275
319
  }
276
320
  }
277
321
 
278
322
  // Slash-command (support bare and namespaced /caveman:<cmd>)
279
323
  if (prompt.startsWith("/caveman")) {
280
324
  const parts = prompt.split(/\s+/);
281
- const cmd = parts[0];
282
- const arg = parts[1] || "";
325
+ const cmd = parts[0].toLowerCase();
326
+ const rawArg = parts[1] || "";
283
327
 
284
- if (cmd === "/caveman-commit" || cmd === "/caveman:caveman-commit") return "commit";
285
- if (cmd === "/caveman-review" || cmd === "/caveman:caveman-review") return "review";
286
328
  if (cmd === "/caveman-compress" || cmd === "/caveman:caveman-compress") return "compress";
287
329
 
288
330
  if (cmd === "/caveman" || cmd === "/caveman:caveman") {
289
- if (!arg) {
290
- const mode = resolveDefault();
291
- return mode === "off" ? "off" : mode;
292
- }
293
- if (arg === "off" || arg === "stop" || arg === "disable") return "off";
294
- if (arg === "wenyan-full") return "wenyan";
295
- if (isValidMode(arg) && !INDEPENDENT[arg]) return arg;
296
- return null; // unknown arg — don't silently overwrite
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;
297
335
  }
298
336
  }
299
337
 
@@ -415,48 +453,50 @@ export default function cavemanExtension(pi: ExtensionAPI) {
415
453
 
416
454
  // ── /caveman command ──────────────────────────────────────────────────
417
455
  pi.registerCommand("caveman", {
418
- description: "Switch caveman mode (lite|full|ultra|wenyan|off)",
456
+ description: "Switch and persist caveman mode (lite|full|ultra|wenyan|off)",
419
457
  getArgumentCompletions: (prefix) => getModeCompletions(prefix),
420
458
  handler: async (args, ctx) => {
421
- const arg = (args || "").trim().toLowerCase();
459
+ const rawArg = (args || "").trim().toLowerCase();
422
460
 
423
- // No arg → activate default
424
- if (!arg) {
425
- const mode = resolveDefault();
426
- if (mode === "off") { deleteFlag(); return; }
461
+ // Bare /caveman -> activate default and persist
462
+ if (!rawArg) {
463
+ const def = resolveDefault();
464
+ const mode = def === "off" ? "full" : def;
427
465
  applyMode(mode);
466
+ saveUserConfigMode(mode);
428
467
  notifyMode(ctx, mode);
429
468
  return;
430
469
  }
431
470
 
432
- // Off
433
- if (arg === "off" || arg === "stop" || arg === "disable") {
434
- sessionExplicitOff = true;
435
- applyMode("off");
436
- clearStatus(ctx);
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);
437
477
  return;
438
478
  }
439
479
 
440
- // Wenyan alias
441
- if (arg === "wenyan-full") {
442
- applyMode("wenyan");
443
- if (ctx.hasUI) {
444
- ctx.ui.notify("caveman: wenyan-full", "info");
445
- }
480
+ if (res.action === "clear") {
481
+ sessionExplicitOff = true;
482
+ applyMode("off");
483
+ saveUserConfigMode("off");
484
+ clearStatus(ctx);
446
485
  return;
447
486
  }
448
487
 
449
- // Valid mode
450
- if (isValidMode(arg) && !INDEPENDENT[arg]) {
451
- applyMode(arg);
452
- notifyMode(ctx, arg);
488
+ if (res.independentMode && ctx.hasUI) {
489
+ ctx.ui.notify(
490
+ `"${res.independentMode}" is an independent skill. Use: /caveman-${res.independentMode}`,
491
+ "warning",
492
+ );
453
493
  return;
454
494
  }
455
495
 
456
496
  // Unknown
457
497
  if (ctx.hasUI) {
458
498
  ctx.ui.notify(
459
- `unknown mode "${arg}". Use: lite|full|ultra|wenyan-lite|wenyan|wenyan-ultra|off`,
499
+ `unknown mode "${rawArg}". Use: lite|full|ultra|wenyan-lite|wenyan|wenyan-ultra|off`,
460
500
  "warning",
461
501
  );
462
502
  }
@@ -512,95 +552,6 @@ export default function cavemanExtension(pi: ExtensionAPI) {
512
552
  },
513
553
  });
514
554
 
515
- // ── /caveman-config command ──────────────────────────────────────────
516
- const INTENSITY_MODES = ["lite", "full", "ultra", "wenyan-lite", "wenyan", "wenyan-ultra", "off"];
517
-
518
- pi.registerCommand("caveman-config", {
519
- description: "Set default caveman mode for new sessions",
520
- getArgumentCompletions: (prefix) => getModeCompletions(prefix),
521
- handler: async (args, ctx) => {
522
- const arg = (args || "").trim().toLowerCase();
523
-
524
- // No arg → show current config + available options
525
- if (!arg) {
526
- const def = resolveDefault();
527
- const configPath = join(cavemanConfigDir(), "config.json");
528
- const repoConfig = findRepoConfig(process.cwd());
529
-
530
- const lines: string[] = [
531
- `Current default: ${def}`,
532
- "",
533
- "Available modes:",
534
- " lite — no filler/hedging, keep articles + full sentences",
535
- " full — drop articles, fragments OK, short synonyms (default)",
536
- " ultra — one word when one word enough, no abbreviations",
537
- " wenyan-lite — semi-classical, keep grammar structure",
538
- " wenyan — maximum classical terseness (文言文)",
539
- " wenyan-ultra — extreme abbreviation, classical feel",
540
- " off — disabled by default",
541
- "",
542
- "Usage: /caveman-config <mode>",
543
- `Config file: ${configPath}`,
544
- ];
545
- if (process.env.CAVEMAN_DEFAULT_MODE) {
546
- lines.push(`Note: CAVEMAN_DEFAULT_MODE=${process.env.CAVEMAN_DEFAULT_MODE} overrides config file`);
547
- }
548
- if (repoConfig) {
549
- lines.push(`Note: repo config at ${repoConfig} overrides user config`);
550
- }
551
-
552
- const msg = lines.join("\n");
553
- if (ctx.hasUI) ctx.ui.notify(msg, "info");
554
- pi.sendMessage({
555
- customType: "caveman-config",
556
- content: msg,
557
- display: true,
558
- attribution: "user",
559
- }, { triggerTurn: false });
560
- return;
561
- }
562
-
563
- // Validate
564
- if (!isValidMode(arg) && arg !== "off") {
565
- if (ctx.hasUI) {
566
- ctx.ui.notify(
567
- `unknown mode "${arg}". Available: ${INTENSITY_MODES.join(", ")}`,
568
- "warning",
569
- );
570
- }
571
- return;
572
- }
573
-
574
- // Write to user config
575
- const configDir = cavemanConfigDir();
576
- const cfgPath = join(configDir, "config.json");
577
-
578
- try {
579
- if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
580
-
581
- let existing: Record<string, unknown> = {};
582
- if (existsSync(cfgPath)) {
583
- try { existing = JSON.parse(readFileSync(cfgPath, "utf-8")); } catch {}
584
- }
585
- existing.defaultMode = arg;
586
- writeFileSync(cfgPath, JSON.stringify(existing, null, 2) + "\n", { mode: 0o600 });
587
-
588
- const label = arg === "off" ? "off" : arg;
589
- if (ctx.hasUI) {
590
- ctx.ui.notify(`default mode set to: ${label}`, "info");
591
- ctx.ui.notify(`config: ${cfgPath}`, "info");
592
- }
593
- pi.sendMessage({
594
- customType: "caveman-config",
595
- content: `Default mode saved: ${label}\nConfig: ${cfgPath}\nEffective on next session.`,
596
- display: true,
597
- attribution: "user",
598
- }, { triggerTurn: false });
599
- } catch (e) {
600
- if (ctx.hasUI) ctx.ui.notify(`failed to write config: ${e}`, "error");
601
- }
602
- },
603
- });
604
555
 
605
556
  // ── before_agent_start: per-turn reinforcement ────────────────────────
606
557
  // Injects full SKILL.md content (filtered to active mode) + reinforcement line.
@@ -638,6 +589,7 @@ export default function cavemanExtension(pi: ExtensionAPI) {
638
589
  if (change) {
639
590
  if (change === "off") sessionExplicitOff = true;
640
591
  applyMode(change);
592
+ saveUserConfigMode(change);
641
593
  }
642
594
  });
643
595
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izhimu/pi-caveman",
3
- "version": "0.2.0",
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
  }
@@ -1,48 +1,52 @@
1
- # caveman
2
-
3
- Talk like smart caveman. Same brain, fewer tokens.
4
-
5
- ## What it does
6
-
7
- Compress every model response to caveman-style prose. Drops articles, filler, pleasantries, and hedging. Keeps every technical detail, code block, error string, and symbol exact. Cuts 65% of output tokens (measured) with full accuracy preserved. Mode persists for the whole session until changed or stopped.
8
-
9
- Six intensity levels:
10
-
11
- | Level | What change |
12
- |-------|-------------|
13
- | `lite` | Drop filler/hedging. Sentences stay full. Professional but tight. |
14
- | `full` | Default. Drop articles, fragments OK, short synonyms. |
15
- | `ultra` | Bare fragments. Abbreviations (DB, auth, fn). Arrows for causality. |
16
- | `wenyan-lite` | Classical Chinese register, light compression. |
17
- | `wenyan-full` | Maximum 文言文. 80-90% character reduction. |
18
- | `wenyan-ultra` | Extreme classical compression. |
19
-
20
- 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.
21
-
22
- ## How to invoke
23
-
24
- ```
25
- /caveman # full mode (default)
26
- /caveman lite # lighter compression
27
- /caveman ultra # extreme compression
28
- /caveman wenyan # classical Chinese
29
- stop caveman # back to normal prose
30
- ```
31
-
32
- ## Example output
33
-
34
- Question: "Why does my React component re-render?"
35
-
36
- Normal prose:
37
- > Your component re-renders because you create a new object reference each render. Wrapping it in `useMemo` will fix the issue.
38
-
39
- Caveman (full):
40
- > New object ref each render. Inline object prop = new ref = re-render. Wrap in `useMemo`.
41
-
42
- Caveman (ultra):
43
- > Inline obj prop → new ref → re-render. `useMemo`.
44
-
45
- ## See also
46
-
47
- - [`SKILL.md`](./SKILL.md) — full LLM-facing instructions
48
- - [Caveman README](../../README.md) — repo overview, install, benchmarks
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
@@ -22,6 +22,8 @@ Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleas
22
22
 
23
23
  Never drop not/never/no/only/except — flip meaning worse than any token saved. Numbers, units exact.
24
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
+
25
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.
26
28
 
27
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.
@@ -85,4 +87,4 @@ Example — destructive op:
85
87
 
86
88
  ## Boundaries
87
89
 
88
- Persisted outside chat: write normal prose — code, comments, commits, docs, issue/PR/MR text, memory files, third-party messages (/caveman-compress exempt). "stop caveman" or "normal mode": revert. Level persist until changed or session end.
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.