@massu/core 1.13.1 → 1.14.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.
@@ -1,232 +0,0 @@
1
- ---
2
- name: massu-command-improve
3
- description: "When user wants to improve a specific command's quality score, says 'improve this command', 'fix command issues', or after command-health shows weak commands"
4
- allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
- ---
6
- name: massu-command-improve
7
-
8
- # Massu Command Improve: Score-Driven Prompt Optimization
9
-
10
- ## Purpose
11
-
12
- Read accumulated command quality scores from `.claude/metrics/command-scores.jsonl`, identify consistently failing checks, propose **one targeted prompt edit at a time** to the command file, and wait for explicit user approval before applying.
13
-
14
- **This is the manual-approval counterpart to autonomous autoresearch.** Scoring is automated; improvements require human judgment.
15
-
16
- ---
17
-
18
- ## ARGUMENTS
19
-
20
- ```
21
- /massu-command-improve # Auto-pick weakest command
22
- /massu-command-improve massu-debug # Target specific command
23
- ```
24
-
25
- **Arguments from $ARGUMENTS**: {{ARGUMENTS}}
26
-
27
- ---
28
-
29
- ## NON-NEGOTIABLE RULES
30
-
31
- 1. **ONE change per iteration** — never batch multiple edits. Single-variable perturbation only.
32
- 2. **ALWAYS show the exact diff** — user must see before/after text.
33
- 3. **NEVER apply without approval** — wait for explicit "yes", "approved", "apply it", etc.
34
- 4. **ALWAYS create backup** — save original section to `.claude/metrics/backups/[command]-v[N].md.bak` before editing.
35
- 5. **ALWAYS log the change** — append to `.claude/metrics/command-changelog.jsonl` after applying.
36
- 6. **Target the weakest check** — don't guess what to improve; let the data decide.
37
-
38
- ---
39
-
40
- ## EXECUTION STEPS
41
-
42
- ### Step 1: Load Score Data
43
-
44
- Read `.claude/metrics/command-scores.jsonl`. If empty or missing:
45
- ```
46
- No command scores recorded yet.
47
- Scores accumulate automatically as you use instrumented commands:
48
- massu-article-review, massu-create-plan, massu-loop, massu-plan, massu-debug
49
-
50
- Run these commands normally and come back when you have 5+ scored runs.
51
- ```
52
-
53
- ### Step 2: Analyze Weaknesses
54
-
55
- For each command in the data:
56
-
57
- 1. Parse all JSONL lines for that command
58
- 2. Extract individual check pass/fail counts across all runs
59
- 3. Calculate per-check pass rate (e.g., `root_cause_identified`: 7/10 = 70%)
60
- 4. Identify the **single weakest check** (lowest pass rate)
61
- 5. Calculate overall command pass rate (average across all checks)
62
-
63
- If `$ARGUMENTS` specifies a command, use that. Otherwise, auto-select the command with the lowest overall pass rate.
64
-
65
- **Minimum data requirement**: At least 3 scored runs for the target command. If fewer:
66
- ```
67
- [command] has only [N] scored runs. Need at least 3 for reliable analysis.
68
- Keep using the command normally — scores accumulate automatically.
69
- ```
70
-
71
- ### Step 3: Diagnose the Failing Check
72
-
73
- Read the target command file (`.claude/commands/[command].md`).
74
-
75
- For the weakest check, analyze WHY it might be failing:
76
-
77
- | Check Pattern | Likely Prompt Cause |
78
- |--------------|---------------------|
79
- | Check passes < 50% | The command doesn't mention this requirement at all, or buries it |
80
- | Check passes 50-70% | The requirement exists but is vague or easy to skip |
81
- | Check passes 70-85% | The requirement exists but lacks a concrete example or enforcement |
82
- | Check passes > 85% | Healthy — move to next weakest check |
83
-
84
- ### Step 4: Propose ONE Edit
85
-
86
- Design a single, targeted prompt edit that addresses the weakest check. The edit should be one of:
87
-
88
- | Edit Type | When to Use | Example |
89
- |-----------|-------------|---------|
90
- | **Add explicit rule** | Check requirement is missing from prompt | "Your debug report MUST include a specific root cause statement, not 'probably' or 'might be'" |
91
- | **Add worked example** | Check exists but is vague | Add a before/after example of what good looks like |
92
- | **Promote to NON-NEGOTIABLE** | Check exists but is buried | Move the requirement higher in the file, add to the rules table |
93
- | **Add enforcement step** | Check exists but is easy to skip | Add a numbered step to START NOW that explicitly requires this check |
94
- | **Add banned pattern** | Check fails because of a specific anti-pattern | "NEVER produce a debug report without [X]" |
95
-
96
- ### Step 5: Present to User
97
-
98
- Display:
99
-
100
- ```
101
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
102
- COMMAND IMPROVE — [command]
103
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
104
-
105
- DATA SUMMARY
106
- Scored runs: [N]
107
- Overall rate: [X]%
108
- Date range: [earliest] — [latest]
109
-
110
- WEAKEST CHECK
111
- Name: [check_name]
112
- Pass rate: [X/N] ([Y]%)
113
- Diagnosis: [why it's failing]
114
-
115
- PROPOSED EDIT
116
- Type: [Add rule / Add example / Promote / Add step / Ban pattern]
117
- Target section: [which section of the command file]
118
-
119
- --- BEFORE ---
120
- [exact text being replaced or location of insertion]
121
-
122
- --- AFTER ---
123
- [exact new text]
124
-
125
- --- END DIFF ---
126
-
127
- RATIONALE
128
- This targets [check_name] by [explanation of why this change should help].
129
-
130
- APPROVE?
131
- Reply "yes" to apply, "skip" to move to next check, or "no" to stop.
132
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
133
- ```
134
-
135
- ### Step 6: Wait for Approval
136
-
137
- **STOP HERE. Do NOT proceed without explicit user approval.**
138
-
139
- - **"yes" / "approved" / "apply it"** → proceed to Step 7
140
- - **"skip"** → move to next weakest check on the same command, or next command
141
- - **"no" / "stop"** → end the session, log the rejection
142
-
143
- ### Step 7: Apply Change
144
-
145
- 1. **Create backup**:
146
- - Check `.claude/metrics/backups/` exists (create if not)
147
- - Count existing backups for this command to determine version number
148
- - Save the ORIGINAL section (not whole file) to `.claude/metrics/backups/[command]-v[N].md.bak`
149
-
150
- 2. **Apply the edit** using the Edit tool
151
-
152
- 3. **Log the change** — append to `.claude/metrics/command-changelog.jsonl`:
153
- ```json
154
- {"command":"[command]","timestamp":"ISO8601","action":"applied","target_check":"[check_name]","check_pass_rate_before":"[X/N]","edit_type":"[type]","edit_summary":"[1-line description]","backup_file":"[path]"}
155
- ```
156
-
157
- 4. **Confirm to user**:
158
- ```
159
- Applied. Backup saved to [path].
160
-
161
- Next time you run /[command], the scoring will capture whether this
162
- change improved [check_name]. Check /massu-command-health after 3+ runs.
163
- ```
164
-
165
- ### Step 8: Continue or Stop
166
-
167
- After applying (or skipping), offer to continue:
168
- - If there are more weak checks on the same command (pass rate < 85%), offer to address the next one
169
- - If the current command is healthy, offer to move to the next weakest command
170
- - If all commands are above 85%, report "All commands healthy"
171
-
172
- **Remember: ONE change at a time.** Even if 3 checks are weak, propose and apply them individually so you can measure each improvement's effect.
173
-
174
- ---
175
-
176
- ## REJECTION LOGGING
177
-
178
- If the user rejects a proposal, log it so future runs don't re-propose the same thing:
179
-
180
- ```json
181
- {"command":"[command]","timestamp":"ISO8601","action":"rejected","target_check":"[check_name]","edit_type":"[type]","edit_summary":"[1-line description]","rejection_reason":"[user's reason if given, or 'no reason provided']"}
182
- ```
183
-
184
- Before proposing an edit, check the changelog for recent rejections of the same check+type combination. If found, try a DIFFERENT edit type for the same check.
185
-
186
- ---
187
-
188
- ## MEASURING IMPROVEMENT
189
-
190
- After applying a change, the improvement is measured passively:
191
-
192
- 1. User continues using the command normally
193
- 2. Silent scoring appends new data to `command-scores.jsonl`
194
- 3. Next time `/massu-command-health` or `/massu-bearings` runs, the trend shows whether the check improved
195
- 4. Next time `/massu-command-improve` runs, it uses the updated data — if the check improved, it moves to the next weakest
196
-
197
- The feedback loop:
198
- ```
199
- Score → Diagnose → Propose → Approve → Apply → Score again → ...
200
- ```
201
-
202
- ---
203
-
204
- ## EDGE CASES
205
-
206
- - **No JSONL file**: Tell user to use instrumented commands first
207
- - **< 3 runs for target command**: Tell user to accumulate more data
208
- - **All checks > 85%**: "All commands healthy — no improvements needed"
209
- - **User specifies unknown command**: List the 5 instrumented commands
210
- - **Changelog shows same check was improved before**: Note this in the proposal ("Previously improved on [date] — may need a different approach")
211
-
212
- ---
213
-
214
- ## START NOW
215
-
216
- 1. Read `.claude/metrics/command-scores.jsonl`
217
- 2. If `$ARGUMENTS` specifies a command, target that; otherwise auto-pick weakest
218
- 3. Analyze per-check pass rates
219
- 4. Identify weakest check
220
- 5. Read the command file
221
- 6. Diagnose why the check fails
222
- 7. Propose ONE targeted edit with exact diff
223
- 8. **WAIT for user approval**
224
- 9. If approved: backup → apply → log → confirm
225
- 10. Offer to continue with next weak check
226
-
227
- ---
228
-
229
- ## Related Commands
230
-
231
- - `/massu-autoresearch [command]` — Autonomous version. Runs the optimize loop unattended with git-based accept/reject. Use for overnight runs.
232
- - `/massu-command-health` — Read-only dashboard. Shows scores, trends, and weakest checks.
@@ -1,187 +0,0 @@
1
- ---
2
- name: massu-infra-audit
3
- description: "When user asks about .claude/ infrastructure health, says 'audit infra', 'check claude setup', or needs to verify references, staleness, and format compliance"
4
- allowed-tools: Bash(*), Read(*), Grep(*), Glob(*)
5
- ---
6
- name: massu-infra-audit
7
-
8
- # Massu Infrastructure Audit: .claude/ Directory Health Check
9
-
10
- ## Objective
11
-
12
- Verify the health of the `.claude/` directory infrastructure: dead references, staleness, conflicts, format consistency, and memory health. Designed for periodic execution to catch drift before it causes problems.
13
-
14
- ---
15
-
16
- ## AUDIT PHASES (8 Checks)
17
-
18
- | Phase | Check | Pass Criteria |
19
- |-------|-------|---------------|
20
- | 1 | **Dead References in CLAUDE.md** | All file paths referenced in CLAUDE.md exist |
21
- | 2 | **Script References** | All scripts referenced by commands/patterns exist |
22
- | 3 | **Command Format Consistency** | All commands have valid YAML frontmatter (name, description, allowed-tools) |
23
- | 4 | **Cross-Reference Integrity** | Commands reference patterns that exist; patterns reference files that exist |
24
- | 5 | **Line Count Accuracy** | Line counts in CLAUDE.md Load Instructions match actual file line counts |
25
- | 6 | **Memory Health** | MEMORY.md under 200-line limit; topic files organized |
26
- | 7 | **Archive Bloat** | Session state archive size and count assessment |
27
- | 8 | **Orphan Detection** | Files in .claude/ not referenced from CLAUDE.md or any command |
28
-
29
- ---
30
-
31
- ## EXECUTION PROTOCOL
32
-
33
- ### Phase 1: Dead References in CLAUDE.md
34
-
35
- ```bash
36
- # Extract all relative file paths from CLAUDE.md and verify each exists
37
- grep -oE '\[.*?\]\((protocols|patterns|commands|incidents|reference|session-state)/[^)]+\)' .claude/CLAUDE.md \
38
- | grep -oE '(protocols|patterns|commands|incidents|reference|session-state)/[^)]+' \
39
- | sort -u \
40
- | while read path; do
41
- [ -f ".claude/$path" ] && echo "OK: $path" || echo "MISSING: $path"
42
- done
43
- ```
44
-
45
- **FAIL** if any path is MISSING.
46
-
47
- ### Phase 2: Script References
48
-
49
- ```bash
50
- # Find all script references across .claude/ files
51
- grep -roh 'scripts/[a-zA-Z0-9_-]*\.\(sh\|ts\)' .claude/ | sort -u | while read script; do
52
- [ -f "$script" ] && echo "OK: $script" || echo "MISSING: $script"
53
- done
54
- ```
55
-
56
- **FAIL** if any script is MISSING.
57
-
58
- ### Phase 3: Command Format Consistency
59
-
60
- ```bash
61
- # For each command file, verify YAML frontmatter has required fields
62
- for f in .claude/commands/massu-*.md; do
63
- name=$(basename "$f" .md)
64
- has_name=$(head -10 "$f" | grep -c "^name:")
65
- has_desc=$(head -10 "$f" | grep -c "^description:")
66
- has_tools=$(head -10 "$f" | grep -c "^allowed-tools:")
67
- if [ "$has_name" -eq 0 ] || [ "$has_desc" -eq 0 ] || [ "$has_tools" -eq 0 ]; then
68
- echo "INVALID: $name (name:$has_name desc:$has_desc tools:$has_tools)"
69
- else
70
- echo "OK: $name"
71
- fi
72
- done
73
- ```
74
-
75
- **FAIL** if any command has missing required fields.
76
-
77
- ### Phase 4: Cross-Reference Integrity
78
-
79
- ```bash
80
- # Find pattern/protocol references in commands and verify they exist
81
- grep -roh 'patterns/[a-zA-Z0-9_-]*\.md\|protocols/[a-zA-Z0-9_-]*\.md' .claude/commands/ \
82
- | sort -u \
83
- | while read ref; do
84
- [ -f ".claude/$ref" ] && echo "OK: $ref" || echo "BROKEN: $ref"
85
- done
86
- ```
87
-
88
- **FAIL** if any cross-reference is BROKEN.
89
-
90
- ### Phase 5: Line Count Accuracy
91
-
92
- Read CLAUDE.md Load Instructions table. For each entry with a line count:
93
-
94
- ```bash
95
- # Compare claimed vs actual line counts
96
- # Flag if delta > 20 lines (significant drift)
97
- wc -l .claude/patterns/*.md .claude/protocols/*.md .claude/reference/*.md 2>/dev/null
98
- ```
99
-
100
- Compare to claimed counts in CLAUDE.md. **WARN** if any delta > 20 lines.
101
-
102
- ### Phase 6: Memory Health
103
-
104
- ```bash
105
- # Check memory directory
106
- MEMORY_DIR="$HOME/.claude/projects/$(pwd | tr '/' '-')/memory"
107
- echo "=== Memory Files ==="
108
- ls -la "$MEMORY_DIR/"
109
- echo "=== MEMORY.md line count ==="
110
- wc -l "$MEMORY_DIR/MEMORY.md"
111
- echo "=== Total memory size ==="
112
- du -sh "$MEMORY_DIR/"
113
- ```
114
-
115
- **WARN** if MEMORY.md exceeds 180 lines (approaching 200 limit).
116
-
117
- ### Phase 7: Archive Bloat Assessment
118
-
119
- ```bash
120
- echo "=== Archive Stats ==="
121
- echo "File count: $(ls .claude/session-state/archive/ | wc -l)"
122
- echo "Total size: $(du -sh .claude/session-state/archive/)"
123
- echo "=== Age distribution ==="
124
- echo "Last 7 days: $(find .claude/session-state/archive/ -mtime -7 | wc -l)"
125
- echo "7-30 days: $(find .claude/session-state/archive/ -mtime +7 -mtime -30 | wc -l)"
126
- echo "30+ days: $(find .claude/session-state/archive/ -mtime +30 | wc -l)"
127
- ```
128
-
129
- **INFO** only — no pass/fail, but flag if > 500 files or > 5MB.
130
-
131
- ### Phase 8: Orphan Detection
132
-
133
- ```bash
134
- # List all non-archive .claude/ files
135
- # For each, check if referenced from CLAUDE.md or any command
136
- find .claude/ -name "*.md" -not -path "*/archive/*" -not -path "*/session-state/*" | while read f; do
137
- basename=$(basename "$f")
138
- refs=$(grep -rl "$basename" .claude/CLAUDE.md .claude/commands/ .claude/patterns/ .claude/protocols/ 2>/dev/null | wc -l)
139
- if [ "$refs" -eq 0 ]; then
140
- echo "ORPHAN?: $f (0 incoming references)"
141
- fi
142
- done
143
- ```
144
-
145
- **INFO** only — orphans may be intentional (specialized tools).
146
-
147
- ---
148
-
149
- ## OUTPUT FORMAT
150
-
151
- ```markdown
152
- ## Massu Infrastructure Audit Report
153
- Date: YYYY-MM-DD
154
-
155
- ### Results Summary
156
- | Phase | Check | Status | Details |
157
- |-------|-------|--------|---------|
158
- | 1 | Dead References | PASS/FAIL | [count] issues |
159
- | 2 | Script References | PASS/FAIL | [count] issues |
160
- | 3 | Command Format | PASS/FAIL | [count] issues |
161
- | 4 | Cross-References | PASS/FAIL | [count] issues |
162
- | 5 | Line Counts | PASS/WARN | [count] stale |
163
- | 6 | Memory Health | PASS/WARN | [lines] / 200 limit |
164
- | 7 | Archive Bloat | INFO | [count] files, [size] |
165
- | 8 | Orphan Detection | INFO | [count] potential orphans |
166
-
167
- ### Overall: PASS / WARN / FAIL
168
- [Summary of action items if any]
169
- ```
170
-
171
- ---
172
-
173
- ## PASS CRITERIA
174
-
175
- - **PASS**: Phases 1-4 all pass, Phase 6 under limits
176
- - **WARN**: Phases 5, 7, 8 have non-critical findings
177
- - **FAIL**: Any of Phases 1-4 have failures (broken references, missing files, invalid format)
178
-
179
- ---
180
-
181
- ## WHEN TO RUN
182
-
183
- - After editing CLAUDE.md or any command file
184
- - After adding/removing pattern or protocol files
185
- - After memory cleanup or reorganization
186
- - Weekly as part of `/massu-codebase-audit`
187
- - After any `.claude/` directory restructuring