@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.
- package/CHANGELOG.md +26 -0
- package/README.md +36 -44
- package/extensions/caveman.ts +101 -149
- package/package.json +5 -1
- package/skills/caveman/README.md +52 -48
- package/skills/caveman/SKILL.md +3 -1
- package/skills/caveman-compress/README.md +42 -29
- package/skills/caveman-compress/scripts/compress.py +113 -22
- package/skills/caveman-compress/scripts/validate.py +193 -6
- package/skills/cavecrew/README.md +0 -61
- package/skills/cavecrew/SKILL.md +0 -82
- package/skills/caveman-commit/README.md +0 -44
- package/skills/caveman-commit/SKILL.md +0 -65
- package/skills/caveman-discover/SKILL.md +0 -118
- package/skills/caveman-evidence-review/SKILL.md +0 -144
- package/skills/caveman-explore/SKILL.md +0 -42
- package/skills/caveman-explore/package.json +0 -12
- package/skills/caveman-explore/tests/skill-file.test.mjs +0 -44
- package/skills/caveman-help/README.md +0 -38
- package/skills/caveman-help/SKILL.md +0 -63
- package/skills/caveman-learn/CLAUDE.md +0 -32
- package/skills/caveman-learn/README.md +0 -29
- package/skills/caveman-learn/SKILL.md +0 -69
- package/skills/caveman-learn/package.json +0 -12
- package/skills/caveman-learn/tests/skill-file.test.mjs +0 -44
- package/skills/caveman-manage/SKILL.md +0 -114
- package/skills/caveman-optimize/SKILL.md +0 -114
- package/skills/caveman-review/README.md +0 -33
- package/skills/caveman-review/SKILL.md +0 -55
- package/skills/caveman-setup/SKILL.md +0 -224
- package/skills/caveman-stats/README.md +0 -36
- package/skills/caveman-stats/SKILL.md +0 -12
- package/skills/investigate-first/SKILL.md +0 -16
- package/skills/investigate-first/agents/openai.yaml +0 -4
- package/skills/lean-build/SKILL.md +0 -18
- package/skills/lean-build/agents/openai.yaml +0 -4
- package/skills/migration/SKILL.md +0 -17
- package/skills/migration/agents/openai.yaml +0 -4
- package/skills/safe-refactor/SKILL.md +0 -16
- package/skills/safe-refactor/agents/openai.yaml +0 -4
- package/skills/surgical-patch/SKILL.md +0 -16
- package/skills/surgical-patch/agents/openai.yaml +0 -4
- package/skills/verify-and-stop/SKILL.md +0 -16
- 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)
|
|
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
|
|
|
@@ -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-
|
|
62
|
-
| `/caveman-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
111
|
-
3. **`input`** — intercepts `/caveman` commands and natural-language triggers
|
|
112
|
-
4. **`turn_end`** —
|
|
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
|
|
121
|
+
│ └── caveman.ts # pi ExtensionAPI integration & mode manager
|
|
122
122
|
├── skills/
|
|
123
|
-
│
|
|
124
|
-
│
|
|
125
|
-
├──
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
|
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); }
|
|
@@ -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
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
|
459
|
+
const rawArg = (args || "").trim().toLowerCase();
|
|
422
460
|
|
|
423
|
-
//
|
|
424
|
-
if (!
|
|
425
|
-
const
|
|
426
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
applyMode(
|
|
436
|
-
|
|
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
|
-
|
|
441
|
-
|
|
442
|
-
applyMode("
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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 "${
|
|
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.
|
|
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
|
}
|
package/skills/caveman/README.md
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
|
-
# caveman
|
|
2
|
-
|
|
3
|
-
Talk like smart caveman. Same brain, fewer tokens.
|
|
4
|
-
|
|
5
|
-
## What it does
|
|
6
|
-
|
|
7
|
-
Compress
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
|
16
|
-
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
@@ -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.
|