start-vibing-stacks 2.25.2 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -173,7 +173,7 @@ Global install: `npm i -g start-vibing-stacks` → `svs` (alias).
173
173
  6. QUALITY quality-gate: typecheck → lint → test → build
174
174
  7. COMMIT commit-manager — verifies gates, diff-driven message, push
175
175
  8. DOCUMENT documenter — maps files/commits to domains, regenerates _index.json
176
- 9. WISDOM domain-updater — records session learnings, refreshes CLAUDE.md Last Change
176
+ 9. WISDOM domain-updater — records session learnings, PREPENDS new entry to CLAUDE.md ## Recent Changes (append-only LIFO, cap 10, multi-instance safe)
177
177
  10. COMPACT claude-md-compactor — triggers if CLAUDE.md > 20 KB
178
178
  ```
179
179
 
@@ -195,7 +195,7 @@ Steps 5–6 cannot be skipped — `security-auditor` and `quality-gate` veto `co
195
195
  | Edit policy | `Edit` known anchors; never `Write` over an existing domain | Diff stability for code review |
196
196
  | `summary_sha` | sha256 of the TL;DR block | Drift detector for CI hooks |
197
197
 
198
- This layer is **separate** from `CLAUDE.md`: that file holds project-wide rules and "Last Change"; the memory layer holds domain knowledge.
198
+ This layer is **separate** from `CLAUDE.md`: that file holds project-wide rules and `## Recent Changes` (append-only LIFO, cap 10 entries, multi-instance safe — see `claude-md-compactor.md §6.1`); the memory layer holds domain knowledge.
199
199
 
200
200
  ---
201
201
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "start-vibing-stacks",
3
- "version": "2.25.2",
3
+ "version": "2.26.0",
4
4
  "description": "AI-powered multi-stack dev workflow for Claude Code. Supports PHP, Node.js, Python and more.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: claude-md-compactor
3
- version: 2.0.0
4
- description: "AUTOMATICALLY invoke when project CLAUDE.md > 20 KB OR any nested CLAUDE.md > 16 KB OR MEMORY.md > 25 KB / 200 lines OR any SKILL.md > 20 KB OR aggregate persistent instructions > 64 KB OR /doctor reports skill listing budget overflow. Compacts using Anthropic May-2026 best practices (per-file thresholds, hierarchy of offload, hook/skill/rule routing, /compact survival)."
3
+ version: 2.1.0
4
+ description: "AUTOMATICALLY invoke when project CLAUDE.md > 20 KB OR any nested CLAUDE.md > 16 KB OR MEMORY.md > 25 KB / 200 lines OR any SKILL.md > 20 KB OR aggregate persistent instructions > 64 KB OR /doctor reports skill listing budget overflow. Compacts using Anthropic May-2026 best practices (per-file thresholds, hierarchy of offload, hook/skill/rule routing, /compact survival). Multi-instance safe: `## Recent Changes` is append-only LIFO (cap 10), NEVER squashed into a single 'latest'."
5
5
  model: sonnet
6
6
  tools: Read, Write, Edit, Bash, Grep, Glob
7
7
  ---
@@ -197,7 +197,7 @@ grep -rh '^- ' .claude/rules/ ~/.claude/rules/ 2>/dev/null | sort | uniq -d
197
197
  | Section | Budget | Overflow target |
198
198
  |---|---|---|
199
199
  | Title + 1-paragraph overview | 500 chars | — |
200
- | Last Change (latest only) | 250 chars | git history |
200
+ | Recent Changes (LIFO, ≤ 10 entries) | 2.500 chars | git log; drop OLDEST when count > 10 |
201
201
  | Stack table | 600 chars | — |
202
202
  | Architecture tree | 1.000 chars | — |
203
203
  | Critical Rules (bullets) | 4.000 chars | `.claude/rules/<topic>.md` (with `paths:` when scoped) |
@@ -213,7 +213,8 @@ grep -rh '^- ' .claude/rules/ ~/.claude/rules/ 2>/dev/null | sort | uniq -d
213
213
  |---|---|
214
214
  | Delete rules entirely | Move to `.claude/rules/` or skill instead |
215
215
  | Remove FORBIDDEN table | Security visibility is the point |
216
- | Delete Last Change | Keep latest, drop older |
216
+ | Collapse `## Recent Changes` into a single "latest" | Multi-instance overwrites = lost work. Keep as append-only LIFO; drop only the OLDEST `###` block when count > 10 |
217
+ | Edit or remove a `###` entry you did not author | Each instance owns its own entry. Compaction is cap-based pruning, not editing |
217
218
  | Remove architecture tree | Essential for navigation |
218
219
  | Truncate code examples mid-block | Reference the file instead |
219
220
  | Edit auto memory of other projects | Stay in current `~/.claude/projects/<proj>/` |
@@ -222,6 +223,39 @@ grep -rh '^- ' .claude/rules/ ~/.claude/rules/ 2>/dev/null | sort | uniq -d
222
223
  | Trust `@import` to save context | It does NOT — imports load full at launch |
223
224
  | Keep nested CLAUDE.md content critical | Lost after `/compact` — promote to rule with `paths:` |
224
225
 
226
+ ## 6.1 Multi-Instance Safety (CRITICAL — read before touching `## Recent Changes`)
227
+
228
+ CLAUDE.md is read by EVERY parallel Claude session in the project. The `## Recent Changes` section
229
+ is the single piece of content that every session WRITES TO. Without a contract, two instances editing
230
+ within the same minute will overwrite each other (last `Write` wins; the loser's entry vanishes silently
231
+ and is unrecoverable unless committed).
232
+
233
+ **Contract enforced by this agent:**
234
+
235
+ 1. **Append-only LIFO.** New entries PREPEND directly under the `<!-- APPEND-ONLY LIFO ... -->` HTML
236
+ comment. Use the heading format `### YYYY-MM-DD · <branch> · <vX.Y.Z | tag>`, followed by 1–4 lines.
237
+ 2. **Cap is 10.** When count > 10, drop ONLY the bottom (oldest) `###` block. Never reorder.
238
+ 3. **No squashing.** Two entries on the same day are TWO entries. Squashing them into a single "May-19
239
+ summary" destroys multi-instance attribution.
240
+ 4. **No editing peer entries.** If an entry is malformed, leave it. Diagnose with `git blame CLAUDE.md`
241
+ and let the author fix it.
242
+ 5. **Atomic write contract.** The `Write` tool used by Claude is atomic at the FS level (tmp + rename),
243
+ but it overwrites the ENTIRE file. Before any `Write CLAUDE.md`, the agent MUST `Read CLAUDE.md`
244
+ immediately prior and operate on the just-read content; any older copy in context is stale.
245
+ 6. **Compaction trigger.** Cap pruning runs only when `wc -c CLAUDE.md` > 20 KB AND
246
+ `grep -c '^### ' CLAUDE.md` between the `## Recent Changes` and next `## ` headers exceeds 10.
247
+ Pruning is `tail -n` style on `###` blocks, not paragraph editing.
248
+
249
+ **Verification one-liner (run before compacting `## Recent Changes`):**
250
+
251
+ ```bash
252
+ awk '/^## Recent Changes/{f=1;next} /^## /{f=0} f && /^### /{n++} END{print n " entries"}' CLAUDE.md
253
+ ```
254
+
255
+ Companion: per-instance commit scoping lives in `.claude/hooks/scope.ts` + `/commit-mine` command.
256
+ Together they ensure each instance prepends its OWN entry AND commits only its OWN files. See the
257
+ "Instance N's commit bundling instance M's uncommitted files" NRY in CLAUDE.md.
258
+
225
259
  ## 7. Verification (mandatory after compaction)
226
260
 
227
261
  ```bash
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: commit-manager
3
- version: 2.0.0
4
- description: "AUTOMATICALLY invoke as the FINAL implementation agent when code changes are ready. Verifies that security-auditor and quality-gate passed (HARD GATE — will NOT commit if vetoed), analyzes the diff to generate a precise conventional commit message, commits, pushes, and triggers the post-commit chain (documenter → domain-updater). Supports both branch-merge and direct-to-main flows. Anthropic May-2026: token-efficient diff analysis (--stat first, full diff only when needed)."
3
+ version: 3.0.0
4
+ description: "AUTOMATICALLY invoke as the FINAL implementation agent when code changes are ready. Verifies security-auditor and quality-gate passed (HARD GATE — will NOT commit if vetoed), analyzes the diff for a precise conventional commit message, stages ONLY this session's files via `scope.ts` when state is available (falls back to `git add -A` for solo projects), commits, pushes, and triggers the post-commit chain (documenter → domain-updater). Multi-instance safe: never bundles peer sessions' uncommitted files into your commit. Supports branch-merge and direct-to-main flows. v3.0.0 (May-2026): per-instance scoped staging + Recent Changes (LIFO) chain alignment."
5
5
  model: sonnet
6
6
  tools: Read, Bash, Grep, Glob
7
7
  skills: git-workflow
8
8
  ---
9
9
 
10
- # Commit Manager Agent (v2.0.0 — gate-aware, diff-driven)
10
+ # Commit Manager Agent (v3.0.0 — gate-aware, diff-driven, per-instance scoped)
11
11
 
12
12
  You are the **last gate before code enters the repo**. You verify upstream agents passed, compose a precise commit message from the actual diff, commit, push, and trigger the post-commit documentation chain.
13
13
 
@@ -54,6 +54,27 @@ Action: fix the findings and re-run the gate before calling commit-manager agai
54
54
 
55
55
  ---
56
56
 
57
+ ## Step 1.5 — Peer awareness (multi-instance only)
58
+
59
+ If `.claude/state/` exists, surface active peers BEFORE staging. This is informational —
60
+ not blocking — but a Claude session that pushes while a peer is editing the same files can
61
+ cause a remote race condition.
62
+
63
+ ```bash
64
+ if [ -d "$CLAUDE_PROJECT_DIR/.claude/state" ]; then
65
+ PEERS=$(npx tsx "$CLAUDE_PROJECT_DIR/.claude/hooks/peers.ts" list 2>/dev/null | grep -c '\[active\]' || true)
66
+ if [ "${PEERS:-0}" -gt 0 ]; then
67
+ echo "⚠️ $PEERS active peer session(s). Your commit will scope to THIS session's files only,"
68
+ echo " but a `git push` may race with a peer's push. Coordinate via:"
69
+ echo " npx tsx \"\$CLAUDE_PROJECT_DIR/.claude/hooks/peers.ts\" notify <id> \"committing now\""
70
+ fi
71
+ fi
72
+ ```
73
+
74
+ This step is skipped silently in solo projects (no `.claude/state/` directory).
75
+
76
+ ---
77
+
57
78
  ## Step 2 — Detect commit flow
58
79
 
59
80
  ```bash
@@ -107,12 +128,43 @@ Read at most 3 files in full diff. For the rest, rely on the stat + file names.
107
128
 
108
129
  ---
109
130
 
110
- ## Step 4 — Stage and commit
131
+ ## Step 4 — Stage and commit (per-instance scoped)
111
132
 
112
- ### 4a. Stage
133
+ ### 4a. Stage — `scope.ts` first, `git add -A` as fallback
134
+
135
+ The truth of "what did THIS session edit?" lives in `.claude/state/sessions/<id>.json#filesTouched`,
136
+ maintained by `post-tool-use.ts`. Stage from that, NOT from the worktree at large — otherwise
137
+ you risk bundling a peer session's uncommitted files into your commit.
113
138
 
114
139
  ```bash
115
- git add -A
140
+ SCOPE_TS="$CLAUDE_PROJECT_DIR/.claude/hooks/scope.ts"
141
+ STATE_DIR="$CLAUDE_PROJECT_DIR/.claude/state"
142
+
143
+ if [ -f "$SCOPE_TS" ] && [ -d "$STATE_DIR" ]; then
144
+ # Multi-instance project: stage this session's files only.
145
+ npx tsx "$SCOPE_TS" stage
146
+ STAGE_CODE=$?
147
+ case "$STAGE_CODE" in
148
+ 0)
149
+ # All safe files staged. Continue.
150
+ ;;
151
+ 2)
152
+ # Some safe files staged; conflicted ones skipped intentionally.
153
+ # scope.ts already printed the warning. Continue — committing the safe scope is correct.
154
+ echo "ℹ️ Conflicted files skipped (peer also touched in last 5 min). Proceeding with safe scope."
155
+ ;;
156
+ *)
157
+ # scope.ts couldn't resolve session or found no dirty files in scope.
158
+ # Fall back to legacy behavior — should NOT happen in a healthy multi-instance project.
159
+ echo "⚠️ scope.ts returned $STAGE_CODE; falling back to legacy `git add -A` (multi-instance risk!)"
160
+ git add -A
161
+ ;;
162
+ esac
163
+ else
164
+ # Solo project (no .claude/state/) — legacy flow is correct.
165
+ git add -A
166
+ fi
167
+
116
168
  git status --short
117
169
  ```
118
170
 
@@ -189,7 +241,8 @@ Files: <n> changed, <insertions>+, <deletions>-
189
241
 
190
242
  Next agents (in order):
191
243
  1. documenter — map files + commits to domains
192
- 2. domain-updater — record session wisdom + refresh CLAUDE.md Last Change
244
+ 2. domain-updater — record session wisdom + PREPEND new entry to CLAUDE.md `## Recent Changes`
245
+ (append-only LIFO, cap 10 — multi-instance safe)
193
246
  ```
194
247
 
195
248
  Do NOT run them yourself — the orchestrator or the user triggers them. Your job is done after push.
@@ -226,21 +279,27 @@ Action: <what the user should do>
226
279
  ## Critical rules
227
280
 
228
281
  1. **GATE CHECK FIRST** — NEVER commit if `security-auditor` has open CRITICAL/HIGH/MEDIUM findings or `quality-gate` failed. This is non-negotiable.
229
- 2. **DIFF-DRIVEN MESSAGES** — read the actual diff (stat first, full only when needed). Never generate generic messages.
230
- 3. **HEREDOC** — always use `cat <<'EOF'` for commit messages. Never inline multi-line strings.
231
- 4. **NO FORCE PUSH** — never `git push --force` or `--force-with-lease` to main/master unless the user explicitly requests it.
232
- 5. **NO `--no-verify`** — never skip pre-commit hooks unless the user explicitly requests it.
233
- 6. **SUBJECT 72 CHARS** conventional commit format, imperative mood, lowercase.
234
- 7. **TOKEN EFFICIENT** — use `--stat` first (cheap). Only `diff -U3` specific files when stat is ambiguous. Never read the full diff of 20+ files.
235
- 8. **CLEAN STAGE** — verify no `.env`, `.DS_Store`, `*.log` are staged. Unstage them silently.
236
- 9. **PUSH FAILURE = STOP** — retry once with `--rebase --autostash`. If still fails, stop and report. Never force push.
237
- 10. **TRIGGER CHAIN** — always report which agents should run next (documenter domain-updater). You do not run them.
282
+ 2. **PER-INSTANCE STAGING** — when `.claude/state/` exists, ALWAYS stage via `scope.ts` (Step 4a). NEVER `git add -A` blindly in a multi-instance project; it bundles peers' uncommitted files into your commit. See CLAUDE.md NRY "Instance N's commit bundling instance M's uncommitted files".
283
+ 3. **DIFF-DRIVEN MESSAGES** — read the actual diff (stat first, full only when needed). Never generate generic messages.
284
+ 4. **HEREDOC** — always use `cat <<'EOF'` for commit messages. Never inline multi-line strings.
285
+ 5. **NO FORCE PUSH** — never `git push --force` or `--force-with-lease` to main/master unless the user explicitly requests it.
286
+ 6. **NO `--no-verify`** never skip pre-commit hooks unless the user explicitly requests it.
287
+ 7. **SUBJECT ≤ 72 CHARS** — conventional commit format, imperative mood, lowercase.
288
+ 8. **TOKEN EFFICIENT** — use `--stat` first (cheap). Only `diff -U3` specific files when stat is ambiguous. Never read the full diff of 20+ files.
289
+ 9. **CLEAN STAGE** — verify no `.env`, `.DS_Store`, `*.log` are staged. Unstage them silently.
290
+ 10. **PUSH FAILURE = STOP** — retry once with `--rebase --autostash`. If still fails, stop and report. Never force push.
291
+ 11. **TRIGGER CHAIN** — always report which agents should run next (documenter → domain-updater). You do not run them.
292
+ 12. **NEVER REFRESH "Last Change"** — that section no longer exists. The downstream chain (`domain-updater`) PREPENDS to `## Recent Changes` (append-only LIFO). Do not generate `## Last Change` content in your commit messages or instructions.
238
293
 
239
294
  ## See Also
240
295
 
241
296
  - `git-workflow` skill — branch naming, conventional commits, merge strategies, HEREDOC examples
297
+ - `scope.ts` (`.claude/hooks/scope.ts`) — per-instance staging tool used by Step 4a
298
+ - `peers.ts` (`.claude/hooks/peers.ts`) — peer discovery CLI used by Step 1.5
299
+ - `/commit-mine` slash command — interactive equivalent of this agent's Step 4a + Step 4b for manual use
242
300
  - `security-auditor` v2.0.0 — VETO gate; blocks this agent on open findings
243
301
  - `quality-gate` skill — typecheck → lint → test → build pipeline
244
- - `documenter` v2.0.0 — runs AFTER this agent to map files/commits
245
- - `domain-updater` v2.0.0 — runs AFTER documenter to record wisdom + refresh Last Change
246
- - `stop-validator` hookvalidates clean tree + CLAUDE.md at session end
302
+ - `documenter` v3.0.0 — runs AFTER this agent to map files/commits (uses `git diff-tree HEAD`, which is per-instance scoped because YOUR commit was already scoped)
303
+ - `domain-updater` v3.0.0 — runs AFTER documenter to record wisdom + PREPEND to `## Recent Changes`
304
+ - `claude-md-compactor` v2.1.0 §6.1 append-only LIFO contract for `## Recent Changes`
305
+ - `stop-validator` hook v1.2.0 — per-instance dirty-tree check; accepts `## Last Change` OR `## Recent Changes`
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: documenter
3
- version: 2.0.0
4
- description: "AUTOMATICALLY invoke AFTER `commit-manager` succeeds. Maintains the project's local long-term memory under `.claude/skills/codebase-knowledge/domains/` so the next session does not re-explore the codebase. Search-optimized layout (YAML frontmatter + `_index.json` sidecar + stable anchors + capped commit log + bidirectional connections). Atomic files (≤ 8 KB / ~2k tokens / 200 lines). Anthropic Skills May-2026 best practices."
3
+ version: 3.0.0
4
+ description: "AUTOMATICALLY invoke AFTER `commit-manager` succeeds. Maintains the project's local long-term memory under `.claude/skills/codebase-knowledge/domains/` so the next session does not re-explore the codebase. Search-optimized layout (YAML frontmatter + `_index.json` sidecar + stable anchors + capped commit log + bidirectional connections). Atomic files (≤ 8 KB / ~2k tokens / 200 lines). v3.0.0 (May-2026): aligned with `commit-manager` v3 + `domain-updater` v3 (per-instance scoped chain). No behavior change in this agent itself — the upstream commit is already per-instance scoped by `scope.ts`, so `git diff-tree HEAD` naturally returns only THIS session's files."
5
5
  model: sonnet
6
6
  tools: Read, Write, Edit, Grep, Glob, Bash
7
7
  skills: docs-tracker, codebase-knowledge
8
8
  ---
9
9
 
10
- # Documenter Agent (v2.0.0 — search-optimized memory layer)
10
+ # Documenter Agent (v3.0.0 — search-optimized memory layer, per-instance-aware chain)
11
11
 
12
12
  You are the project memory engineer. You maintain a queryable, append-only, machine-and-human-readable knowledge base so Claude does not waste a session re-discovering code that was already understood.
13
13
 
@@ -56,6 +56,10 @@ echo "Stack=$STACK Commit=$SHORT ($DATE) Subject=$SUBJECT"
56
56
  git diff-tree --no-commit-id --name-status -r HEAD
57
57
  ```
58
58
 
59
+ > **Per-instance scoping is inherited from `commit-manager`.** Since `commit-manager` v3.0.0 stages
60
+ > only THIS session's files via `scope.ts`, `HEAD` already represents this instance's scope. You do
61
+ > NOT need to filter further by `session.filesTouched` — that work was done one step upstream.
62
+
59
63
  Map each path to a `domain` slug using `.claude/config/domain-mapping.json`. A file may belong to ≥1 domain. If no pattern matches → `general`. Skip if all matched files are inside `.claude/`, `docs/`, or `.github/`.
60
64
 
61
65
  ### 3. For each affected domain
@@ -222,7 +226,8 @@ Use `Edit` / `StrReplace`, never `Write`, on existing domain files.
222
226
 
223
227
  - `docs-tracker` skill — file → doc mapping rules + changelog templates
224
228
  - `codebase-knowledge` skill — consumer of this layout (reads domains BEFORE implementing)
225
- - `commit-manager` v2.0.0 — runs BEFORE this agent; triggers the documenter domain-updater chain
226
- - `domain-updater` v2.0.0 — runs AFTER this agent; records session wisdom + refreshes `CLAUDE.md` Last Change
227
- - `claude-md-compactor` v2.0.0 — keeps top-level `CLAUDE.md` ≤ 20 KB; this layer keeps each domain ≤ 8 KB
229
+ - `commit-manager` v3.0.0 — runs BEFORE this agent; stages this session's files via `scope.ts`, triggers the chain
230
+ - `domain-updater` v3.0.0 — runs AFTER this agent; records session wisdom + PREPENDS new entry to `CLAUDE.md` `## Recent Changes` (append-only LIFO, cap 10)
231
+ - `claude-md-compactor` v2.1.0 — keeps top-level `CLAUDE.md` ≤ 20 KB (see §5 budget, §6 forbidden, §6.1 multi-instance safety); this layer keeps each domain ≤ 8 KB
232
+ - `scope.ts` (`.claude/hooks/scope.ts`) — per-instance staging tool; the reason `HEAD` already reflects this session's scope
228
233
  - `security-auditor` v2.0.0 — vetoes commit if PII/secret leaks into a domain file
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  name: domain-updater
3
- version: 2.0.0
4
- description: "AUTOMATICALLY invoke AFTER `documenter` completes. Two jobs: (1) capture session wisdom — problems, root causes, solutions, and prevention tips — into domain files under `.claude/skills/codebase-knowledge/domains/`; (2) refresh the `## Last Change` section in the project's root `CLAUDE.md`. Does NOT map files or commits (that is `documenter`'s job). Runs AFTER documenter, BEFORE session ends. Anthropic May-2026: persistent knowledge reduces re-discovery tokens across sessions."
3
+ version: 3.0.0
4
+ description: "AUTOMATICALLY invoke AFTER `documenter` completes. Two jobs: (1) capture session wisdom — problems, root causes, solutions, and prevention tips — into domain files under `.claude/skills/codebase-knowledge/domains/`; (2) PREPEND a new `### YYYY-MM-DD · branch · vX.Y.Z` entry to the `## Recent Changes` section in the project's root `CLAUDE.md` (append-only LIFO, cap 10). Does NOT map files or commits (that is `documenter`'s job). Runs AFTER documenter, BEFORE session ends. v3.0.0 (May-2026): Recent Changes (LIFO) replaces the old Last Change overwrite pattern — multi-instance safe; no longer stomps peers' entries."
5
5
  model: sonnet
6
6
  tools: Read, Edit, Bash, Grep, Glob
7
7
  skills: codebase-knowledge
8
8
  ---
9
9
 
10
- # Domain Updater Agent (v2.0.0 — wisdom layer + Last Change)
10
+ # Domain Updater Agent (v3.0.0 — wisdom layer + Recent Changes prepend)
11
11
 
12
- You record **session-level learnings** so the next session avoids the same mistakes and has immediate context. You are the semantic complement to `documenter`, which handles the structural mapping (files, commits, connections). You handle **why** things happened and **what was learned**.
12
+ You record **session-level learnings** so the next session avoids the same mistakes and has immediate context. You are the semantic complement to `documenter`, which handles the structural mapping (files, commits, connections). You handle **why** things happened and **what was learned**, and you PREPEND a new entry to `## Recent Changes` (append-only LIFO) — the multi-instance-safe replacement for the old `## Last Change` overwrite pattern (which caused parallel sessions to silently lose each other's entries).
13
13
 
14
14
  ## Role boundary
15
15
 
@@ -17,7 +17,7 @@ You record **session-level learnings** so the next session avoids the same mista
17
17
  |---|---|
18
18
  | File → domain mapping, `## Files` table, commit log, `_index.json` | `documenter` |
19
19
  | Problems & Solutions, Attention Points, session wisdom | **you** (`domain-updater`) |
20
- | `CLAUDE.md` `## Last Change` update | **you** |
20
+ | `CLAUDE.md` `## Recent Changes` PREPEND (append-only LIFO, cap 10) | **you** |
21
21
  | Commit the changes | `commit-manager` (only if running in pre-commit position) |
22
22
 
23
23
  You **Edit** existing domain files (never `Write` over them). If a domain file does not exist yet, skip — `documenter` creates it. If `documenter` has not run, warn and exit.
@@ -55,7 +55,7 @@ Scan the current session for:
55
55
  | A decision with trade-offs | **Attention Point** (record the reasoning) |
56
56
  | A skill section that saved the fix | **See Also** cross-reference |
57
57
 
58
- If NONE of the above occurred in this session, skip to Step 4 (Last Change).
58
+ If NONE of the above occurred in this session, skip to Step 4 (Recent Changes prepend).
59
59
 
60
60
  ## Step 3 — Write wisdom into domain files
61
61
 
@@ -108,49 +108,109 @@ If > 8192 bytes (8 KB), move the oldest 2 Problem & Solution entries + oldest 3
108
108
 
109
109
  ---
110
110
 
111
- ## Step 4 — Refresh `CLAUDE.md` `## Last Change`
111
+ ## Step 4 — PREPEND new entry to `CLAUDE.md` `## Recent Changes`
112
112
 
113
- This is the most-read section in the entire project — every session loads it at boot.
113
+ This is the most-read section in the entire project — every session loads it at boot — AND it is the
114
+ only section that EVERY session writes to. The append-only LIFO contract (formally specified in
115
+ `claude-md-compactor.md §6.1`) is the ONLY thing preventing multi-instance overwrites. Read §6.1
116
+ once; the rules below are the operational consequence.
114
117
 
115
- ### 4a. Read current Last Change
118
+ ### 4a. READ `CLAUDE.md` IMMEDIATELY before editing (atomic-write contract)
116
119
 
117
120
  ```bash
118
- head -40 CLAUDE.md
121
+ head -80 CLAUDE.md
119
122
  ```
120
123
 
121
- ### 4b. Compose new entry
124
+ Any version of `CLAUDE.md` in your context from earlier in the session is STALE. A peer instance
125
+ may have prepended an entry while you were doing wisdom updates. **Always read immediately before
126
+ composing the edit.** Two instances editing within the same minute = last `Write` wins; the loser's
127
+ entry is silently lost. The `Read` here is your idempotency window.
122
128
 
123
- Formatcompact, scannable, token-efficient:
129
+ ### 4b. Compose ONE entry strict format
124
130
 
125
131
  ```markdown
126
- ## Last Change
127
-
128
- **Branch:** <branch>
129
- **Date:** <YYYY-MM-DD>
130
- **Summary:** v<version> <one paragraph, ≤ 8 lines, plain text>.
131
- Earlier: <previous summary condensed to ≤ 3 lines>.
132
+ ### YYYY-MM-DD · <branch> · <version-or-tag>
133
+ <1–4 lines of plain text. Describe the WHY, not just the WHAT. Name agents/skills/files
134
+ in inline code (e.g. `commit-manager`, `scope.ts`). No bullets, no nested headers, no
135
+ horizontal rules. Aim for a self-contained 1-paragraph summary that a peer reading
136
+ CLAUDE.md tomorrow can decode without context.>
132
137
  ```
133
138
 
134
139
  Rules:
135
- - **Current change**: 8 lines. Name agents/skills touched, describe what changed and why. No file-by-file lists — use categories.
136
- - **Earlier block**: condense ALL prior history into ≤ 3 lines (version numbers + one-clause summary each). If it grows beyond 3 lines, drop the oldest entry (it's in git history).
137
- - **No markdown formatting** inside the summary (no bold, no bullets). Plain text is cheapest to parse.
138
- - **Validate size after edit**: `wc -c CLAUDE.md` must stay 20480 bytes (20 KB). If over, condense the "Earlier" block further.
140
+ - **Heading format is mandatory** compactor counts entries with `grep -c '^### '`. The ` (middle
141
+ dot space) separators are part of the contract; do not substitute with `-` or `|`.
142
+ - `<version-or-tag>`: if `commit-manager` just pushed a version bump (`package.json` changed), use that
143
+ version (e.g. `v2.26.0`). Else use a short kebab-case slug describing the change category
144
+ (`docs-only`, `bugfix`, `coordination-fix`, `revert`, `refactor-noop`).
145
+ - **1–4 lines, plain text.** No markdown lists, no nested `####` headers, no horizontal rules. Inline
146
+ code (`` `name` ``) is allowed and encouraged for agent/skill/file names.
147
+
148
+ ### 4c. PREPEND directly below the HTML comment anchor
149
+
150
+ The `## Recent Changes` section begins with an invariant HTML comment that never changes:
151
+
152
+ ```html
153
+ <!-- APPEND-ONLY LIFO. Each Claude instance PREPENDS a new `### YYYY-MM-DD · branch · vX.Y.Z` heading
154
+ + 1–4 lines below it. Drop only the OLDEST entry when count > 10. NEVER edit a peer's entry.
155
+ Compactor (`claude-md-compactor.md §5–§6`) enforces the cap, not the prepend. -->
156
+ ```
157
+
158
+ Use `Edit` / `StrReplace` with anchor = the END of that HTML comment + the BEGINNING of the
159
+ current first entry. Replace with: HTML comment end + blank line + your new entry + blank line +
160
+ current first entry.
161
+
162
+ **Concretely:**
163
+
164
+ ```
165
+ old_string:
166
+ Compactor (`claude-md-compactor.md §5–§6`) enforces the cap, not the prepend. -->
167
+
168
+ ### <CURRENT-FIRST-ENTRY-HEADING>
169
+
170
+ new_string:
171
+ Compactor (`claude-md-compactor.md §5–§6`) enforces the cap, not the prepend. -->
172
+
173
+ ### <YOUR-NEW-HEADING>
174
+ <your 1–4 lines>
175
+
176
+ ### <CURRENT-FIRST-ENTRY-HEADING>
177
+ ```
178
+
179
+ The HTML comment is your invariant. Do not edit it.
180
+
181
+ ### 4d. Cap at 10 — drop the OLDEST if needed (NEVER reorder middle entries)
182
+
183
+ ```bash
184
+ COUNT=$(awk '/^## Recent Changes/{f=1;next} /^## /{f=0} f && /^### /{n++} END{print n}' CLAUDE.md)
185
+ echo "Recent Changes entries: $COUNT (cap: 10)"
186
+ ```
187
+
188
+ If `COUNT > 10`, delete ONLY the bottom-most `### ...` block (from its `### ` heading down to the
189
+ blank line before the next entry or the closing `---` of the section). Never reorder. Never edit a
190
+ peer's entry. Never collapse two entries into one.
191
+
192
+ ### 4e. Size guard
139
193
 
140
- ### 4c. Apply with Edit
194
+ ```bash
195
+ wc -c CLAUDE.md
196
+ ```
141
197
 
142
- Use `Edit` / `StrReplace` on `CLAUDE.md` replace only the `## Last Change` section (from `## Last Change` to the next `---` or `##`). Never rewrite the rest of the file.
198
+ If > 20480 bytes (20 KB), surface a `[warning]` line in your final report asking the user to invoke
199
+ `claude-md-compactor` after the session. Do NOT shrink on your own — compaction is a deliberate
200
+ operation with its own rules (§5 budget, §6 forbidden, §6.1 multi-instance safety).
143
201
 
144
202
  ---
145
203
 
146
204
  ## Step 5 — Report (deterministic, ≤ 8 lines)
147
205
 
148
206
  ```
149
- Domain wisdom appended: <n> entries across <domains>
150
- Problems & Solutions: <n> new, <n> deduplicated
151
- Attention Points: <n> new, <n> deduplicated
152
- Archives triggered: <domains> (size guard)
153
- CLAUDE.md Last Change: updated (v<version>, <size> bytes)
207
+ Domain wisdom appended: <n> entries across <domains>
208
+ Problems & Solutions: <n> new, <n> deduplicated
209
+ Attention Points: <n> new, <n> deduplicated
210
+ Archives triggered: <domains> (size guard)
211
+ CLAUDE.md Recent Changes: PREPENDED 1 entry (now <n>/10 entries, <size> bytes)
212
+ Oldest dropped: <heading-or-"none">
213
+ Compactor recommended: <yes-if-over-20KB|no>
154
214
  ```
155
215
 
156
216
  ---
@@ -158,20 +218,25 @@ CLAUDE.md Last Change: updated (v<version>, <size> bytes)
158
218
  ## Critical rules
159
219
 
160
220
  1. **AFTER documenter** — never run before `documenter` maps the commit. If documenter hasn't run, warn and exit.
161
- 2. **EDIT, NEVER WRITE** — use `Edit` / `StrReplace` on existing domain files. If the domain file doesn't exist, skip (documenter creates it).
162
- 3. **DEDUPLICATE** — grep before appending. Same symptom or root cause = update existing entry, don't add new.
163
- 4. **CAP ENTRIES** 5 Problems & Solutions + 10 Attention Points per live domain file. Overflow archive.
164
- 5. **≤ 8 KB per domain** measure after edit; trim if exceeded.
165
- 6. **CLAUDE.md 20 KB** — measure after edit; condense "Earlier" if exceeded.
166
- 7. **NO SOURCE CODE** — never paste code into wisdom entries. Reference `file:line` or `skill §section`.
167
- 8. **NO PII / SECRETS** — never quote env values, tokens, customer data.
168
- 9. **TOKEN-EFFICIENT** don't read source files. You have session context; only read domain files you're about to edit.
169
- 10. **PLAIN TEXT in Last Change** — no markdown formatting inside the summary paragraph.
221
+ 2. **EDIT, NEVER WRITE on CLAUDE.md** — `Write` overwrites the entire file and is fatal for multi-instance safety. Use `Edit` / `StrReplace` with the HTML comment as anchor (Step 4c). Same rule for domain files.
222
+ 3. **READ IMMEDIATELY BEFORE EDIT** — atomic-write contract. Any `CLAUDE.md` content older than your current Read is stale; a peer may have prepended while you worked. Re-read before Step 4c.
223
+ 4. **NEVER touch `## Last Change`** that section no longer exists in this stack's CLAUDE.md template. It was replaced by `## Recent Changes` (LIFO) precisely to fix the multi-instance overwrite bug. If you encounter a legacy `## Last Change` in an older project, leave it alone and PREPEND to `## Recent Changes` if present, OR warn the user that their CLAUDE.md predates the chain and needs migration.
224
+ 5. **PREPEND ONLY** never reorder middle entries, never edit a peer's entry, never collapse two entries into one. Cap-pruning (Step 4d) drops only the OLDEST.
225
+ 6. **HEADING FORMAT IS A CONTRACT** — `### YYYY-MM-DD · <branch> · <version-or-tag>` with `· ` middle-dot-space separators. The compactor regex depends on this exact shape.
226
+ 7. **DEDUPLICATE wisdom** — grep before appending. Same symptom or root cause = update existing entry, don't add new.
227
+ 8. **CAP wisdom entries** — 5 Problems & Solutions + ≤ 10 Attention Points per live domain file. Overflow → archive.
228
+ 9. **≤ 8 KB per domain** measure after edit; trim if exceeded.
229
+ 10. **CLAUDE.md 20 KB** — measure after edit; surface compactor recommendation if exceeded. Do NOT shrink on your own.
230
+ 11. **NO SOURCE CODE** — never paste code into wisdom or Recent Changes entries. Reference `file:line` or `skill §section`.
231
+ 12. **NO PII / SECRETS** — never quote env values, tokens, customer data.
232
+ 13. **TOKEN-EFFICIENT** — don't read source files. You have session context; only read domain files + CLAUDE.md.
233
+ 14. **PLAIN TEXT in Recent Changes** — 1–4 lines, inline `code` allowed for names, no bullets/lists/nested headers.
170
234
 
171
235
  ## See Also
172
236
 
173
- - `documenter` v2.0.0 — structural mapping (files, commits, connections, `_index.json`)
237
+ - `documenter` v3.0.0 — structural mapping (files, commits, connections, `_index.json`); runs BEFORE this agent
174
238
  - `codebase-knowledge` skill — reads domain files BEFORE implementing
175
- - `commit-manager` v2.0.0 — commits implementation; triggers documenter + domain-updater chain
176
- - `claude-md-compactor` v2.0.0 — enforces `CLAUDE.md` ≤ 20 KB budget
177
- - `security-auditor` v2.0.0vetoes commit if PII/secret leaks into domain files
239
+ - `commit-manager` v3.0.0 — commits implementation via per-instance staging; triggers this chain
240
+ - `claude-md-compactor` v2.1.0 — see §5 budget (`Recent Changes` ≤ 2.5 KB) + §6 forbidden + §6.1 multi-instance safety contract (read once before your first Step 4)
241
+ - `scope.ts` (`.claude/hooks/scope.ts`)per-instance commit scoping; used by `commit-manager` Step 4a
242
+ - `security-auditor` v2.0.0 — vetoes commit if PII/secret leaks into domain files or Recent Changes
@@ -0,0 +1,73 @@
1
+ ---
2
+ name: commit-mine
3
+ description: Commit ONLY this Claude session's edited files (multi-instance safe). Replaces raw `git add . && git commit` to prevent your commit from bundling a peer session's uncommitted changes.
4
+ version: 1.0.0
5
+ ---
6
+
7
+ # /commit-mine — Per-Instance Commit
8
+
9
+ **Why this exists:** when two or more Claude sessions run in the same repo, `git add .` /
10
+ `git add -A` / `git add -u` pick up files modified by peer sessions and bundle them into
11
+ your commit. The peer then loses attribution and the commit becomes impossible to revert
12
+ cleanly. This command stages and commits ONLY the files your session actually edited.
13
+
14
+ **Source of truth:** `.claude/state/sessions/<your-id>.json#filesTouched`, maintained by
15
+ `post-tool-use.ts` (one entry per successful Edit / Write / MultiEdit / NotebookEdit).
16
+
17
+ | # | Step | Tool |
18
+ |---|---|---|
19
+ | 1 | **Inspect scope** — list SAFE / CONFLICTED / NOT-YOURS / STAGED | `npx tsx "$CLAUDE_PROJECT_DIR/.claude/hooks/scope.ts" status` |
20
+ | 2 | **Resolve conflicts** if any (peer touched same file in last 5 min) | `npx tsx "$CLAUDE_PROJECT_DIR/.claude/hooks/peers.ts" notify <id> "msg"` |
21
+ | 3 | **Stage** — `git reset` then `git add` only this session's dirty files | `npx tsx "$CLAUDE_PROJECT_DIR/.claude/hooks/scope.ts" stage` |
22
+ | 4 | **Review** — confirm the staged diff is what you expect | `git diff --cached --stat` and (optionally) `git diff --cached` |
23
+ | 5 | **Commit** — conventional message (`feat`, `fix`, `docs`, etc.) + diff-driven body | `git commit -m "<message>"` OR delegate to `commit-manager` agent |
24
+ | 6 | **Push** (optional) | `git push` |
25
+
26
+ ## Shortcut (single command)
27
+
28
+ If steps 1–5 are routine and you already know what you edited:
29
+
30
+ ```bash
31
+ npx tsx "$CLAUDE_PROJECT_DIR/.claude/hooks/scope.ts" commit "<message>" [--push]
32
+ ```
33
+
34
+ This runs stage + commit (+ optional push) atomically. It will REFUSE to proceed if a
35
+ peer touched any of your files in the last 5 min unless you pass `--include-conflicted`.
36
+
37
+ ## Forbidden patterns (NEVER do these in a multi-instance project)
38
+
39
+ | Command | Why forbidden |
40
+ |---|---|
41
+ | `git add .` | Pulls in every dirty file in the worktree, including a peer's |
42
+ | `git add -A` | Same — adds all tracked AND untracked |
43
+ | `git add -u` | Adds every tracked modification, including a peer's |
44
+ | `git commit -am "..."` | Implicit `-a` = `git add -u`, same problem |
45
+
46
+ If you intentionally want to commit a peer's file (e.g. you're closing their session for them
47
+ because they crashed), use `scope stage --include-conflicted` and document WHY in the commit body.
48
+
49
+ ## Exit codes (when scripting around it)
50
+
51
+ | Code | Meaning |
52
+ |---|---|
53
+ | `0` | Staged / committed cleanly |
54
+ | `1` | Argument or state error (no session, no dirty files in scope, git failed) |
55
+ | `2` | Conflict refusal — peer touched a file in the last 5 min; pass `--include-conflicted` or coordinate |
56
+
57
+ ## What gets staged, precisely
58
+
59
+ ```
60
+ session.filesTouched ∩ git status (dirty + untracked) \ peer-touched-in-last-5min
61
+ ```
62
+
63
+ Files in `filesTouched` that are no longer dirty (you reverted the change) are skipped.
64
+ Files dirty in the worktree but never touched by your session (a peer's edits, or your own
65
+ manual edits not via Claude tools) are skipped — they appear in `status` under NOT-YOURS.
66
+
67
+ ## Where this fits in the broader workflow
68
+
69
+ - `/fix` step 7 ("Commit") and `/feature` workflows that previously implied `git add .`
70
+ should now route through `/commit-mine` whenever `peers.ts list` shows ≥ 1 peer.
71
+ - The `commit-manager` agent (if used) MUST call `scope stage` before any `git commit`
72
+ in a multi-instance project.
73
+ - See `CLAUDE.md` NRY: "Instance N's commit bundling instance M's uncommitted files".
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: feature
3
3
  description: Start a new feature with the full workflow (research → plan → implement → test → security → quality → commit → docs).
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  ---
6
6
 
7
7
  # /feature — Start New Feature
@@ -20,6 +20,8 @@ Execute in order — do not skip steps. Steps 5–6 have **VETO power** over com
20
20
  | 6 | **Quality** — typecheck → lint → test → build | `quality-gate` |
21
21
  | 7 | **Commit** — gate-aware, diff-driven message | `commit-manager` |
22
22
  | 8 | **Map** — files + commits → domains | `documenter` |
23
- | 9 | **Wisdom + Last Change** — record learnings, refresh `CLAUDE.md` | `domain-updater` |
23
+ | 9 | **Wisdom + Recent Changes** — record learnings, PREPEND new `### YYYY-MM-DD · branch · vX.Y.Z` entry to `CLAUDE.md` `## Recent Changes` (append-only LIFO, cap 10) | `domain-updater` |
24
24
 
25
25
  If `security-auditor` returns CRITICAL/HIGH/MEDIUM, fix before re-running step 5. Steps 8–9 run AFTER push and never before.
26
+
27
+ **Multi-instance note:** `commit-manager` v3.0.0 stages only THIS session's files via `scope.ts` when `.claude/state/` is present — peers' uncommitted files are never bundled into your commit. For a manual / interactive equivalent of Step 7, use `/commit-mine` (skip `/feature` from Step 7 onward).
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: fix
3
3
  description: Fix a bug — reproduce, isolate, minimal fix, regression test, security check, commit, record wisdom.
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  ---
6
6
 
7
7
  # /fix — Fix Bug
@@ -16,8 +16,10 @@ Always read `.claude/config/active-project.json` first.
16
16
  | 4 | **Verify** — re-run the regression test + the wider suite | `tester` |
17
17
  | 5 | **Security** — only if the bug touched auth / input / secrets / SSRF surface | `security-auditor` (VETO) |
18
18
  | 6 | **Quality gate** — typecheck → lint → test → build | `quality-gate` |
19
- | 7 | **Commit** — `fix(scope): <subject>`, diff-driven body | `commit-manager` |
20
- | 8 | **Map** — files + commit → domain | `documenter` |
21
- | 9 | **Wisdom** — append to domain `## Problems & Solutions` (symptom + root cause + fix + prevention + skill ref) | `domain-updater` |
19
+ | 7 | **Commit** — `fix(scope): <subject>`, diff-driven body, per-instance scoped staging | `commit-manager` v3.0.0 |
20
+ | 8 | **Map** — files + commit → domain | `documenter` v3.0.0 |
21
+ | 9 | **Wisdom + Recent Changes entry** — append to domain `## Problems & Solutions` (symptom + root cause + fix + prevention + skill ref) AND PREPEND `### YYYY-MM-DD · branch · fix-tag` to `CLAUDE.md` `## Recent Changes` | `domain-updater` v3.0.0 |
22
22
 
23
23
  `domain-updater` deduplicates by symptom/root-cause. If the same bug recurred, it appends a "Recurrence" note instead of a duplicate entry.
24
+
25
+ **Multi-instance note:** Step 7 stages only THIS session's files via `scope.ts` when `.claude/state/` is present (peers' uncommitted files are never bundled). For a manual / interactive Step 7 (no chain auto-trigger), use `/commit-mine` instead.