@lornatang/dsh-caveman 0.1.10 → 0.1.12
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 +12 -0
- package/LICENSE +202 -202
- package/LICENSE-MIT +21 -21
- package/NOTICE +51 -51
- package/README.md +15 -0
- package/README.zh.md +15 -0
- package/cordis.patch.yml +3 -3
- package/examples/caveman-anthropic.patch.yml +14 -14
- package/examples/caveman-auto.patch.yml +15 -15
- package/lib/compression.js +1 -1
- package/lib/index.js +18 -2
- package/lib/mode.js +5 -2
- package/lib/types/index.d.ts +4 -0
- package/lib/types/mode.d.ts +2 -0
- package/package.json +25 -25
- package/presets/cavecrew.patch.yml +54 -54
- package/scripts/benchmark.mjs +79 -79
- package/scripts/caveman-cli.mjs +30 -30
- package/scripts/learn-binary.mjs +82 -82
- package/scripts/learn-checksums.json +7 -7
- package/vendor/caveman/README.md +382 -0
- package/vendor/caveman/src/hooks/README.md +211 -0
- package/vendor/caveman/skills/caveman-learn/CLAUDE.md +0 -32
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Caveman Hooks
|
|
2
|
+
|
|
3
|
+
These hooks are **bundled with the caveman plugin** and activate automatically when the plugin is installed. No manual setup required.
|
|
4
|
+
|
|
5
|
+
If you installed caveman standalone (without the plugin), the unified Node installer at `installer/install.js` wires them into your `settings.json` for you — run `node installer/install.js --only claude` from a clone, or `npx -y github:JuliusBrussee/caveman -- --only claude` for the curl-pipe path.
|
|
6
|
+
|
|
7
|
+
## What's Included
|
|
8
|
+
|
|
9
|
+
### Where the mode lives
|
|
10
|
+
|
|
11
|
+
The mode is **per session**. Each Claude Code window stores its own mode in
|
|
12
|
+
`$CLAUDE_CONFIG_DIR/.caveman-sessions/<session_id>.mode` (default
|
|
13
|
+
`~/.claude/.caveman-sessions/`), keyed by the `session_id` that Claude Code puts
|
|
14
|
+
in every hook payload and in the statusline's stdin JSON.
|
|
15
|
+
|
|
16
|
+
`$CLAUDE_CONFIG_DIR/.caveman-active` still exists as a **last-write-wins
|
|
17
|
+
mirror** of whichever session wrote most recently. It is kept so `cat` still
|
|
18
|
+
answers "is caveman on", and so third-party statusline snippets keep working.
|
|
19
|
+
|
|
20
|
+
Two things worth knowing about the mirror:
|
|
21
|
+
|
|
22
|
+
- It **never** contains the literal string `off`. Deactivation deletes it, just
|
|
23
|
+
as before. `off` is a valid mode name, so an older hook or statusline reading
|
|
24
|
+
`off` from that path would treat it as an active mode and render
|
|
25
|
+
`[CAVEMAN:OFF]` or inject "CAVEMAN MODE ACTIVE (off)".
|
|
26
|
+
- With two windows open it shows the other window's mode half the time. Read the
|
|
27
|
+
per-session file if you need the truth for a specific window.
|
|
28
|
+
|
|
29
|
+
Readers accept both spellings of "off": a missing file (the old meaning) and a
|
|
30
|
+
literal `off` in a session file (the new, durable one).
|
|
31
|
+
|
|
32
|
+
### `caveman-activate.js` — SessionStart hook
|
|
33
|
+
|
|
34
|
+
- Runs on every SessionStart — `source` is `startup`, `resume`, `clear`, `compact` or `fork`
|
|
35
|
+
- Resolves this session's mode and persists it via the symlink-safe `safeWriteFlag` helper
|
|
36
|
+
- Emits the active mode's skill (`skills/caveman`, `skills/ultracave` or `skills/megacave`) as hidden SessionStart context
|
|
37
|
+
- Sweeps session files older than 14 days (`CAVEMAN_SESSION_TTL_MS` overrides), on new sessions only
|
|
38
|
+
- Detects missing statusline config and emits setup nudge (Claude will offer to help)
|
|
39
|
+
|
|
40
|
+
**Why `source` matters.** The hook is registered with no matcher, so it fires
|
|
41
|
+
for every source — deliberately, because compaction is what prunes the ruleset
|
|
42
|
+
out of context and lets the model drift back to verbose prose, so the rules must
|
|
43
|
+
be re-injected afterwards. What it must *not* do on a continuation (`compact`,
|
|
44
|
+
`resume`, `fork`) is re-derive the configured default and overwrite the
|
|
45
|
+
session's mode. Doing that is how an explicit "stop caveman" used to get
|
|
46
|
+
silently undone by the next auto-compaction. `clear` counts as a fresh start,
|
|
47
|
+
since it is an explicit user reset.
|
|
48
|
+
|
|
49
|
+
**Headless sessions start off.** `claude -p` and Agent SDK sessions
|
|
50
|
+
(`CLAUDE_CODE_ENTRYPOINT=sdk-cli`, `sdk-ts`, `sdk-py`) are often tools that
|
|
51
|
+
probe Claude and parse the reply, so they start under the `manual` policy:
|
|
52
|
+
nothing injected until an explicit `/caveman`. Interactive surfaces (terminal,
|
|
53
|
+
VS Code, desktop) are unaffected. Set `CAVEMAN_DEFAULT_MODE=<mode>` in the
|
|
54
|
+
environment to opt a headless run back in.
|
|
55
|
+
|
|
56
|
+
### `caveman-activate.js --subagent` — SubagentStart hook
|
|
57
|
+
|
|
58
|
+
- SessionStart context reaches only the main conversation, so subagents never saw caveman. This hook hands each new subagent **this session's** active skill
|
|
59
|
+
- Injects nothing once the session has stored `off`, so "stop caveman" never leaks into subagents, even if another window turns caveman on
|
|
60
|
+
- A session with no stored mode at all (its SessionStart hook never ran or failed) falls back to the shared mirror, the same as the per-turn reminder its main conversation gets
|
|
61
|
+
- Skips the cavecrew agents (they already talk ultracave), one-shot modes (`commit`/`review`/`compress`), and projects whose repo config says `defaultMode: "off"`
|
|
62
|
+
- Read-only: it never writes mode state, logs, or marker files
|
|
63
|
+
|
|
64
|
+
### `caveman-mode-tracker.js` — UserPromptSubmit hook
|
|
65
|
+
|
|
66
|
+
- Fires on every user prompt, checks for `/caveman`, `/ultracave`, `/megacave` commands and natural-language activation/deactivation phrases ("talk like caveman", "stop caveman", "normal mode")
|
|
67
|
+
- Writes the active mode for **this session** when a caveman command is detected; on deactivation it stores a durable `off` and clears the legacy mirror
|
|
68
|
+
- Emits a small per-turn reinforcement reminder when the session's mode is a prose one (`caveman`/`ultracave`/`megacave`), built from that skill's first line
|
|
69
|
+
- Remembers the displaced prose mode per session, so two windows each running `/caveman-commit` return to their own mode
|
|
70
|
+
- Stores: `caveman`, `ultracave`, `megacave`, `commit`, `review`, `compress`, `off`. Older level names still read correctly: `lite`/`full` → `caveman`, `ultra` → `ultracave`, `wenyan*` → `megacave`
|
|
71
|
+
|
|
72
|
+
### `caveman-statusline.sh` / `caveman-statusline.ps1` — Statusline badge script
|
|
73
|
+
|
|
74
|
+
- Reads the session JSON Claude Code sends on stdin, takes `session_id`, and renders **that window's** mode; falls back to the legacy mirror when there is no usable id
|
|
75
|
+
- Shows `[CAVEMAN]`, `[ULTRACAVE]`, `[MEGACAVE]`, `[CAVEMAN:COMMIT]`, etc. A deactivated session renders nothing at all — never `[CAVEMAN:OFF]`
|
|
76
|
+
- Never blocks: an interactive terminal is not read from, and the stdin read has a 1s ceiling (integer, because macOS ships bash 3.2 and it rejects fractional `read -t`)
|
|
77
|
+
- Shows mode only. The old `⛏` savings suffix is gone: `.caveman-statusline-suffix` is ignored, because a transcript cannot show what caveman saved
|
|
78
|
+
|
|
79
|
+
### `caveman-stats.js --record` — SessionEnd hook
|
|
80
|
+
|
|
81
|
+
- Runs when Claude Code ends a session
|
|
82
|
+
- Reads `session_id` and `transcript_path` from the hook payload on stdin (first complete JSON object, 2s watchdog) and appends one snapshot to `$CLAUDE_CONFIG_DIR/.caveman-history.jsonl`: recorded output and cache-read tokens, turns, and per-mode attribution. No savings figures
|
|
83
|
+
- Writes no stdout and always exits 0, so it never interrupts shutdown
|
|
84
|
+
- Duplicate snapshots are safe: lifetime views (`--all`, `--since`) count only the newest row per `session_id`
|
|
85
|
+
|
|
86
|
+
## Statusline Badge
|
|
87
|
+
|
|
88
|
+
The statusline badge shows which caveman mode is active directly in your Claude Code status bar.
|
|
89
|
+
|
|
90
|
+
**Plugin users:** If you do not already have a `statusLine` configured, Claude will detect that on your first session after install and offer to set it up for you. Accept and you're done.
|
|
91
|
+
|
|
92
|
+
If you already have a custom statusline, caveman does not overwrite it and Claude stays quiet. Add the badge snippet to your existing script instead.
|
|
93
|
+
|
|
94
|
+
**Standalone users:** the unified installer (`installer/install.js`, invoked by the `install.sh` / `install.ps1` shims at the repo root) wires the statusline automatically if you do not already have a custom statusline. If you do, the installer leaves it alone and prints the merge note.
|
|
95
|
+
|
|
96
|
+
**Manual setup:** If you need to configure it yourself, add one of these to `~/.claude/settings.json`:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"statusLine": {
|
|
101
|
+
"type": "command",
|
|
102
|
+
"command": "bash /path/to/caveman-statusline.sh"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"statusLine": {
|
|
110
|
+
"type": "command",
|
|
111
|
+
"command": "powershell -ExecutionPolicy Bypass -File C:\\path\\to\\caveman-statusline.ps1"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Replace the path with the actual script location (e.g. `~/.claude/hooks/` for standalone installs, or the plugin install directory for plugin installs).
|
|
117
|
+
|
|
118
|
+
**Custom statusline:** If you already have a statusline script, add this snippet
|
|
119
|
+
to it. It reads the session id from the JSON Claude Code gives your script on
|
|
120
|
+
stdin, so the badge tracks the window it belongs to. If your script already
|
|
121
|
+
consumed stdin, pass what you read in as `$caveman_payload` instead of
|
|
122
|
+
re-reading it — stdin can only be drained once.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
caveman_cfg="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
|
|
126
|
+
caveman_payload="${caveman_payload:-}"
|
|
127
|
+
if [ -z "$caveman_payload" ] && [ ! -t 0 ]; then
|
|
128
|
+
IFS= read -r -d '' -t 1 caveman_payload
|
|
129
|
+
fi
|
|
130
|
+
caveman_sid=$(printf '%s' "$caveman_payload" \
|
|
131
|
+
| grep -o '"session_id"[[:space:]]*:[[:space:]]*"[^"]*"' \
|
|
132
|
+
| head -1 | sed -e 's/.*:[[:space:]]*"//' -e 's/"$//')
|
|
133
|
+
case "$caveman_sid" in ''|*[!A-Za-z0-9_-]*) caveman_sid="" ;; esac
|
|
134
|
+
|
|
135
|
+
caveman_flag="$caveman_cfg/.caveman-active"
|
|
136
|
+
if [ -n "$caveman_sid" ] && [ -f "$caveman_cfg/.caveman-sessions/$caveman_sid.mode" ]; then
|
|
137
|
+
caveman_flag="$caveman_cfg/.caveman-sessions/$caveman_sid.mode"
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
caveman_text=""
|
|
141
|
+
if [ -f "$caveman_flag" ]; then
|
|
142
|
+
caveman_mode=$(cat "$caveman_flag" 2>/dev/null)
|
|
143
|
+
case "$caveman_mode" in
|
|
144
|
+
caveman|lite|full) caveman_badge="CAVEMAN" ;;
|
|
145
|
+
ultracave|ultra) caveman_badge="ULTRACAVE" ;;
|
|
146
|
+
megacave|wenyan*) caveman_badge="MEGACAVE" ;;
|
|
147
|
+
commit|review|compress) caveman_badge="CAVEMAN:$(echo "$caveman_mode" | tr '[:lower:]' '[:upper:]')" ;;
|
|
148
|
+
*) caveman_badge="" ;; # off or unknown — render nothing
|
|
149
|
+
esac
|
|
150
|
+
[ -n "$caveman_badge" ] && caveman_text=$'\033[38;5;172m['"${caveman_badge}"$']\033[0m'
|
|
151
|
+
fi
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The older one-file version of this snippet reads the legacy mirror, so it shows
|
|
155
|
+
whichever window wrote last and renders the new ids as `[CAVEMAN:CAVEMAN]` or
|
|
156
|
+
`[CAVEMAN:ULTRACAVE]`; re-run the installer to pick up the badge map above. It
|
|
157
|
+
never sees a literal `off` because the legacy mirror is deleted on deactivation.
|
|
158
|
+
|
|
159
|
+
Badge examples:
|
|
160
|
+
- `/caveman` → `[CAVEMAN]`
|
|
161
|
+
- `/ultracave` → `[ULTRACAVE]`
|
|
162
|
+
- `/megacave` → `[MEGACAVE]`
|
|
163
|
+
- `/caveman-commit` → `[CAVEMAN:COMMIT]`
|
|
164
|
+
- `/caveman-review` → `[CAVEMAN:REVIEW]`
|
|
165
|
+
|
|
166
|
+
## How It Works
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
SessionStart hook ──┐ ┌── UserPromptSubmit hook
|
|
170
|
+
(session_id, │ │ (session_id, prompt)
|
|
171
|
+
source) ▼ ▼
|
|
172
|
+
$CLAUDE_CONFIG_DIR/.caveman-sessions/<session_id>.mode
|
|
173
|
+
│ │
|
|
174
|
+
mirrors reads
|
|
175
|
+
▼ ▼
|
|
176
|
+
.caveman-active Statusline script ◀── session JSON on stdin
|
|
177
|
+
(last-write-wins, [CAVEMAN] / [ULTRACAVE] / [MEGACAVE]
|
|
178
|
+
compat only)
|
|
179
|
+
|
|
180
|
+
SessionEnd hook ──(session_id, transcript_path)──▶ caveman-stats.js --record
|
|
181
|
+
──appends──▶ .caveman-history.jsonl
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
SessionStart stdout is injected as hidden system context — Claude sees it, users
|
|
185
|
+
don't. The statusline runs as a separate process. All three surfaces get
|
|
186
|
+
`session_id` from Claude Code, which is what lets each window keep its own mode.
|
|
187
|
+
|
|
188
|
+
Every path here honors `CLAUDE_CONFIG_DIR`. All state writes go through
|
|
189
|
+
`safeWriteFlag()` (symlink-refusing, atomic, `0600`), and every read is
|
|
190
|
+
whitelist-validated — a session id is never interpolated into a path without
|
|
191
|
+
passing `^[A-Za-z0-9_-]{1,128}$` first.
|
|
192
|
+
|
|
193
|
+
## Uninstall
|
|
194
|
+
|
|
195
|
+
If installed via plugin: disable the plugin — hooks deactivate automatically.
|
|
196
|
+
|
|
197
|
+
If installed via the standalone Node installer:
|
|
198
|
+
```bash
|
|
199
|
+
npx -y github:JuliusBrussee/caveman -- --uninstall
|
|
200
|
+
# or, from a clone:
|
|
201
|
+
node installer/install.js --uninstall
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Or manually:
|
|
205
|
+
1. Remove the caveman hook files from `$CLAUDE_CONFIG_DIR/hooks/` (default `~/.claude/hooks/`): `caveman-activate.js`, `caveman-mode-tracker.js`, `caveman-parse.js`, `caveman-stats.js`, `caveman-config.js`, `cavecrew-model-overrides.js`, and `caveman-statusline.{sh,ps1}`.
|
|
206
|
+
2. Remove the SessionStart, SubagentStart, UserPromptSubmit, SessionEnd, and statusLine entries from `$CLAUDE_CONFIG_DIR/settings.json`.
|
|
207
|
+
3. Delete the mode state from `$CLAUDE_CONFIG_DIR`: the `.caveman-sessions/` directory, `.caveman-active`, `.caveman-active.prev`, `.caveman-mode-log.jsonl`, `.caveman-statusline-suffix`, and `.caveman-nudge-shown`.
|
|
208
|
+
|
|
209
|
+
The uninstaller does all of step 3 for you, but deliberately leaves
|
|
210
|
+
`.caveman-history.jsonl` alone — that is your accumulated lifetime savings
|
|
211
|
+
record, not caveman plumbing. Delete it by hand if you want it gone.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# skills/caveman-learn — the Caveman Learn editing skill (Apache-2.0, public)
|
|
2
|
-
|
|
3
|
-
The consent-gated half of `caveman learn`. The analyzer (the Go proxy) **measures**
|
|
4
|
-
where an agent's tokens go and writes a ranked plan; this skill is what an agent
|
|
5
|
-
loads to **act** on that plan — proposing each fix and applying it only with the
|
|
6
|
-
user's per-edit yes. It is the loop-closer the learn spec §10
|
|
7
|
-
describes, plus the new `cavemem_offload` move.
|
|
8
|
-
|
|
9
|
-
## Layout
|
|
10
|
-
- `SKILL.md` — the canonical skill body (frontmatter `name: caveman-learn` + a
|
|
11
|
-
trigger-phrase `description`; body = the read-plan → per-class consent loop). This
|
|
12
|
-
file is the source of truth.
|
|
13
|
-
- `tests/skill-file.test.mjs` — asserts the canonical file is well-formed and honest
|
|
14
|
-
(frontmatter present; the net-token-negative gate, the never-make-the-agent-dumber
|
|
15
|
-
guard, consent-per-edit, and reversibility are all stated; no imperative for
|
|
16
|
-
behavioral findings; no placeholders).
|
|
17
|
-
|
|
18
|
-
## Install path
|
|
19
|
-
`caveman tools skills install caveman-learn` (in `../../cli/src/index.ts`) writes this file
|
|
20
|
-
into a repo's `.claude/skills/caveman-learn/SKILL.md` (Claude Code) or
|
|
21
|
-
`~/.codex/skills/caveman-learn/SKILL.md` (Codex). The CLI **embeds a byte-identical copy**
|
|
22
|
-
(`CAVEMAN_LEARN_SKILL_MD`) because the published CLI ships no sibling assets;
|
|
23
|
-
`../../cli/tests/skills.runtime.mjs` asserts the embedded copy equals this canonical
|
|
24
|
-
file (the drift guard). **Change this file and that constant together.**
|
|
25
|
-
|
|
26
|
-
## Boundary (binding)
|
|
27
|
-
The skill — using the agent's own file tools — is the ONLY thing that edits a user's
|
|
28
|
-
config. `caveman learn apply` stays read-only (it materializes candidates), and
|
|
29
|
-
`caveman mem *` are mechanical store ops. The offload move enforces a net-token-negative
|
|
30
|
-
gate and the never-make-the-agent-dumber guard before any trim.
|
|
31
|
-
|
|
32
|
-
See ../../mem/CLAUDE.md (cavemem) · ../caveman-explore/SKILL.md (the packaging precedent)
|