@thedecipherist/mdd 1.0.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.
@@ -0,0 +1,350 @@
1
+ ## REVERSE-ENGINEER MODE — `/mdd reverse-engineer [path or feature-id]`
2
+
3
+ Triggered when arguments start with `reverse-engineer` or `reverse`. Generates or regenerates MDD documentation from existing source code.
4
+
5
+ ### Phase R1 — Determine scope
6
+
7
+ **If a path or feature-id is given:**
8
+ - If it matches an existing `.mdd/docs/*.md` — load that doc as the "existing doc" for comparison (regenerate mode).
9
+ - If it's a file path — read that file as the only source (new doc mode).
10
+
11
+ **If no argument is given:**
12
+ - Scan `src/` for all TypeScript/source files.
13
+ - Cross-reference against `source_files` fields in all `.mdd/docs/*.md`.
14
+ - List files not registered in any doc. Ask the user which ones to document.
15
+
16
+ ### Phase R2 — Read source files (parallelized for multi-file scope)
17
+
18
+ **Threshold rule:**
19
+ - ≤ 3 source files: read directly in the main conversation — no agent overhead
20
+ - 4+ source files: batch into parallel Explore agents (max 3), each reading a subset
21
+
22
+ **When parallelism applies:** Primarily the no-argument case — scanning `src/` for undocumented files can surface many files at once. A single feature with many source files (e.g., a large module) also qualifies.
23
+
24
+ #### Agent instructions (self-contained)
25
+
26
+ Each agent receives:
27
+ - Its assigned file paths
28
+ - The inference checklist below
29
+ - Explicit instruction: read the files and return structured inference output — do NOT write any files
30
+
31
+ For each assigned file, infer:
32
+ - **Purpose:** What does this file do? What problem does it solve?
33
+ - **Data models:** TypeScript interfaces, types, Zod schemas
34
+ - **API routes:** Express/Fastify/etc. route definitions and their handlers
35
+ - **Business rules:** Conditional logic, validation, state transitions
36
+ - **Dependencies:** What other modules does it import?
37
+ - **Edge cases:** Error handling patterns, guard clauses
38
+
39
+ #### What each agent returns
40
+
41
+ One block per assigned file:
42
+ ```
43
+ File: <path>
44
+ Purpose: <1–2 sentences>
45
+ Data models: <list of types/interfaces with key fields>
46
+ API routes: <list of routes with method + path>
47
+ Business rules: <key validation, state logic>
48
+ Dependencies: <imports from other project modules>
49
+ Edge cases: <error handlers, guard clauses>
50
+ ```
51
+
52
+ #### Main conversation: synthesize
53
+
54
+ After all agents return, synthesize their output into Phase R3 (draft the doc). The main conversation is the only one that writes files.
55
+
56
+ **Fallback:** If any agent fails, read that batch of files directly in the main conversation.
57
+
58
+ ### Phase R3 — Draft the doc
59
+
60
+ Draft a complete feature doc following the Phase 3 template. Set:
61
+ - `last_synced: <today>`
62
+ - `status: draft` (since business intent may be incomplete)
63
+ - `phase: reverse-engineered`
64
+
65
+ **In regenerate mode:** Show the existing doc alongside the new draft:
66
+ ```
67
+ 📋 Regeneration Comparison: <NN>-<feature-name>
68
+
69
+ Existing doc sections: New draft sections:
70
+ Purpose: ... Purpose: ... (updated)
71
+ Architecture: ... Architecture: ... (same)
72
+ API Endpoints: ... API Endpoints: ... (3 new routes found)
73
+ Business Rules: ... Business Rules: ... (changed)
74
+
75
+ Changes: 2 sections updated, 1 section unchanged, 1 section added
76
+ ```
77
+
78
+ Ask: "Merge new draft into existing doc? (yes / keep existing / show full diff)"
79
+
80
+ **In new doc mode:** Show the full draft and ask: "Does this accurately describe the feature? Anything to add or change?"
81
+
82
+ ### Phase R4 — Save and optionally generate test skeletons
83
+
84
+ After user confirmation, write the doc. Then ask:
85
+ "Generate test skeletons from the inferred endpoints and business rules? (yes / no)"
86
+
87
+ If yes, follow Phase 4 logic using the newly written doc.
88
+
89
+ **Always disclose limitations before saving:**
90
+ ```
91
+ ⚠️ Reverse-engineer limitations:
92
+ - "Purpose" section is inferred — review business intent carefully
93
+ - Implicit constraints (SLAs, compliance, product decisions) are not captured
94
+ - Confirm accuracy before treating this doc as the source of truth
95
+ ```
96
+
97
+ ---
98
+
99
+ ## GRAPH MODE — `/mdd graph`
100
+
101
+ Triggered when arguments start with `graph`. Shows the cross-feature dependency map, plus initiative/wave structure if present.
102
+
103
+ ### Phase G1 — Build dependency graph
104
+
105
+ Read all `.mdd/docs/*.md` (including `archive/`). For each doc, extract `id`, `title`, `status`, and `depends_on`.
106
+
107
+ Build a directed graph: edge A → B means "A depends on B" (B must exist for A to work).
108
+
109
+ **Initiative/wave graph** (only shown if `.mdd/initiatives/` exists): Also read all initiative and wave files. Build a second graph showing the initiative → wave → feature doc hierarchy.
110
+
111
+ ### Phase G2 — Detect issues
112
+
113
+ **Broken dependency:** A doc lists a deprecated or archived feature in `depends_on`.
114
+
115
+ **Risky dependency:** A `status: complete` feature depends on a `status: in_progress` or `status: draft` feature.
116
+
117
+ **Task dependency:** A feature doc lists a task doc (`type: task`) in `depends_on`. Tasks are one-off and frozen — they carry no ongoing contract. Remove the task ID from `depends_on` and reference the relationship in Architecture or Dependencies prose instead.
118
+
119
+ **Orphan:** A feature with no `depends_on` and no other feature depending on it.
120
+
121
+ **Wave/initiative issues:**
122
+ - A wave's `docPath` points to a feature doc that does not exist → broken link
123
+ - A wave references a `dependsOn` wave that is not in the same initiative → invalid (cross-initiative deps not supported)
124
+ - A feature doc whose slug appears in a wave but has no `docPath` set and status is `complete` → doc missing for completed feature
125
+
126
+ ### Phase G3 — Render
127
+
128
+ ```
129
+ 📊 MDD Dependency Graph
130
+
131
+ Dependencies (A depends on → B):
132
+
133
+ 06-command-system ──────────────────► 01-project-scaffolding
134
+ 09-integrations ────────────────────► 06-command-system
135
+ 04-content-builder ─────────────────► 03-database-layer
136
+ 05-testing-framework ───────────────► 03-database-layer
137
+
138
+ Orphans (no dependencies, no dependents):
139
+ 07-github-pages
140
+ 08-quality-gates
141
+
142
+ Issues:
143
+ ⚠️ 09-integrations depends on 06-command-system (status: in_progress) — risky
144
+ ❌ 05-testing-framework depends on 10-mdd-refinements (deprecated) — broken
145
+ ```
146
+
147
+ **Initiative/wave section** (appended when initiatives exist):
148
+
149
+ ```
150
+ 📋 Initiative / Wave Hierarchy
151
+
152
+ auth-system (active, v2)
153
+ ├─ wave-1: Auth Foundation [complete] ✓ 3/3 features
154
+ └─ wave-2: Auth Hardening [active] ● 1/2 features
155
+ ├─ auth-2fa → docs/18-auth-2fa.md ✅
156
+ └─ auth-rate-limit → (no doc yet) ❓
157
+
158
+ Issues:
159
+ ❓ auth-system / wave-2 / auth-rate-limit — complete in wave but no doc path set
160
+ ```
161
+
162
+ **Ops Runbooks section** (appended when `.mdd/ops/` has files):
163
+
164
+ ```
165
+ 📦 Ops Runbooks
166
+
167
+ swarmk-dokploy — 4 services, 2 regions (eu-west canary → us-east primary)
168
+ rulecatch-dokploy — 10 services, 2 regions (eu-west canary → us-east primary)
169
+
170
+ Service health (last runop):
171
+ swarmk-dokploy: all healthy ✓ (2026-04-17)
172
+ rulecatch-dokploy: api ✗ failing in eu-west (2026-04-16) → run /mdd runop rulecatch-dokploy
173
+ ```
174
+
175
+ Save the graph to `.mdd/audits/graph-<date>.md`.
176
+
177
+ ---
178
+
179
+ ## UPGRADE MODE — `/mdd upgrade`
180
+
181
+ Triggered when arguments start with `upgrade`.
182
+
183
+ Batch-patches missing frontmatter fields (`last_synced`, `status`, `phase`) across ALL `.mdd/docs/*.md` files without touching doc content. Safe to run multiple times — already-present fields are never overwritten.
184
+
185
+ **Use case:** projects that used MDD before these fields were introduced, or after importing docs from another project. Running `/mdd upgrade` converts all UNTRACKED docs to IN SYNC in one pass.
186
+
187
+ ---
188
+
189
+ ### Phase UP1 — Inventory
190
+
191
+ 1. Glob `.mdd/docs/*.md` (and `.mdd/docs/archive/*.md` if it exists). Collect all paths.
192
+ 2. For each doc, read its frontmatter only (up to the closing `---` line).
193
+ 3. Build an inventory table:
194
+
195
+ ```
196
+ 📋 Upgrade Inventory
197
+
198
+ Doc | last_synced | status | phase
199
+ ─────────────────────────────────|─────────────|────────|──────────────
200
+ 01-project-scaffolding | ❌ missing | ❌ | ❌
201
+ 02-profile-system | ❌ missing | ✅ | ❌
202
+ 03-database-layer | ✅ present | ✅ | ✅
203
+ ...
204
+
205
+ Docs needing upgrade: <N> of <total>
206
+ Fields to add:
207
+ last_synced — <N> docs
208
+ status — <N> docs
209
+ phase — <N> docs
210
+ ```
211
+
212
+ 4. If 0 docs need upgrade → report "All docs are up to date. Nothing to patch." and stop.
213
+
214
+ ---
215
+
216
+ ### Phase UP2 — Infer Defaults (per doc)
217
+
218
+ For each doc that needs patching, infer sensible defaults. **Do NOT ask the user for each doc** — infer silently, then show the plan for confirmation.
219
+
220
+ **`last_synced` inference:**
221
+
222
+ The goal is the date the doc was last meaningfully worked on. Try in order:
223
+
224
+ 1. Check `git log --format="%as" --follow -- ".mdd/docs/<doc-file>.md" | head -1`
225
+ → Use the most recent commit date for that doc file.
226
+ 2. If no git history (brand-new file not yet committed), use today's date.
227
+ 3. If git is unavailable, use today's date.
228
+
229
+ **`status` inference:**
230
+
231
+ 1. Check the `phase` field (if it already exists):
232
+ - phase contains `all` → `complete`
233
+ - phase contains `implementation` or `6` → `in_progress`
234
+ - phase contains `draft` or `1`–`3` → `draft`
235
+ 2. No existing phase → check the doc title/purpose section for keywords:
236
+ - Contains "reverse-engineered" → `complete`
237
+ - File is in `archive/` → `deprecated`
238
+ - Otherwise → `complete` (most pre-existing docs represent finished features)
239
+ 3. Default: `complete`
240
+
241
+ **`phase` inference:**
242
+
243
+ 1. If `status` resolved to `complete` → `all`
244
+ 2. If `status` resolved to `in_progress` → `implementation`
245
+ 3. If `status` resolved to `draft` → `documentation`
246
+ 4. If `status` resolved to `deprecated` → `deprecated`
247
+
248
+ ---
249
+
250
+ ### Phase UP3 — Show Plan + Confirm
251
+
252
+ Present the inferred patches to the user before writing anything:
253
+
254
+ ```
255
+ 🔧 MDD Upgrade Plan
256
+
257
+ <N> docs will be patched. Fields shown are ADDITIONS only — existing fields are untouched.
258
+
259
+ 01-project-scaffolding.md
260
+ + last_synced: 2025-11-14 (from git: last commit on this doc)
261
+ + status: complete (inferred: pre-existing doc, no phase field)
262
+ + phase: all (inferred: status → complete)
263
+
264
+ 02-profile-system.md
265
+ + last_synced: 2025-12-03 (from git: last commit on this doc)
266
+ + phase: all (inferred: status already 'complete')
267
+
268
+ 09-integrations.md
269
+ + last_synced: 2026-01-17 (from git: last commit on this doc)
270
+ + status: complete
271
+ + phase: all
272
+
273
+ ... (<N> more)
274
+
275
+ Proceed? (yes / review each individually / cancel)
276
+ ```
277
+
278
+ If the user says **"review each individually"**: walk through each doc one at a time, showing the inferred values and asking "Accept / Edit / Skip" before patching.
279
+
280
+ If the user says **"yes"**: proceed to Phase UP4 with all inferred values.
281
+
282
+ ---
283
+
284
+ ### Phase UP4 — Patch Docs
285
+
286
+ For each doc in the plan, patch the frontmatter block **non-destructively**:
287
+
288
+ **Rules:**
289
+ - Read the full file
290
+ - Locate the opening `---` line and the closing `---` line
291
+ - Parse all existing frontmatter key-value pairs
292
+ - Add ONLY the missing fields — never modify existing ones
293
+ - Write the patched frontmatter back, preserving all existing fields and the doc body exactly
294
+
295
+ **Frontmatter field order** (when inserting):
296
+ ```yaml
297
+ ---
298
+ id: ...
299
+ title: ...
300
+ edition: ...
301
+ depends_on: [...]
302
+ source_files: [...]
303
+ routes: [...]
304
+ models: [...]
305
+ test_files: [...]
306
+ data_flow: ...
307
+ last_synced: <new> ← insert here if missing
308
+ status: <new> ← insert here if missing
309
+ phase: <new> ← insert here if missing
310
+ known_issues: []
311
+ ---
312
+ ```
313
+
314
+ Insert new fields **before** `known_issues` to keep the canonical order.
315
+
316
+ Report progress as you go:
317
+ ```
318
+ Patching...
319
+ ✅ 01-project-scaffolding.md — added last_synced, status, phase
320
+ ✅ 02-profile-system.md — added last_synced, phase
321
+ ✅ 03-database-layer.md — skipped (all fields present)
322
+ ...
323
+ ```
324
+
325
+ ---
326
+
327
+ ### Phase UP5 — Verify + Rebuild Startup
328
+
329
+ After all patches are applied:
330
+
331
+ 1. Re-scan `.mdd/docs/*.md` — confirm 0 docs have missing `last_synced`
332
+ 2. Trigger the `.mdd/.startup.md` rebuild (same logic as Status Mode)
333
+ 3. Report:
334
+
335
+ ```
336
+ ✅ MDD Upgrade Complete
337
+
338
+ Docs patched: <N>
339
+ Fields added:
340
+ last_synced — <N> docs
341
+ status — <N> docs
342
+ phase — <N> docs
343
+ Docs skipped: <N> (all fields already present)
344
+
345
+ Run `/mdd scan` to see current drift status across all docs.
346
+ ```
347
+
348
+ ---
349
+
350
+ ---
@@ -0,0 +1,340 @@
1
+ ## STATUS MODE — `/mdd status`
2
+
3
+ Quick overview of MDD state for the project:
4
+
5
+ 1. **Scan `.mdd/docs/`** — count feature docs
6
+ 2. **Scan `.mdd/audits/`** — find latest audit report
7
+ 3. **Scan `.mdd/jobs/`** — detect any active audit job (see below)
8
+ 4. **Count tests** — `pnpm test:unit --reporter=json 2>/dev/null | jq '.numTotalTests'`
9
+ 5. **Count known issues** — grep `known_issues` across all docs
10
+ 6. **Read current mdd_version** — from `mdd.md` frontmatter (or `~/.claude/commands/mdd.md` if not local)
11
+ 7. **Scan all `.mdd/` files** — grep `mdd_version` from each, group by version number
12
+ 8. **Scan `.mdd/initiatives/`** — count initiative files, group by status
13
+ 9. **Scan `.mdd/waves/`** — count wave files, group by status; for each active wave count complete vs total features
14
+
15
+ **Audit in progress detection:** If any `jobs/audit-*/` folder exists, count manifest entries by state (`[ ]`, `[~]`, `[x]`, `[!]`, `[e]`) from its `MANIFEST.md`. Show as a warning line in the status output.
16
+
17
+ Present:
18
+ ```
19
+ 📊 MDD Status
20
+
21
+ ⚠️ Audit in progress: .mdd/jobs/audit-<date>/ (<done>/<total> files complete)
22
+ Run /mdd audit to resume or discard.
23
+ (omit this line entirely if no jobs/audit-*/ folder exists)
24
+
25
+ Feature docs: <N> files in .mdd/docs/
26
+ Ops runbooks: <N> files in .mdd/ops/
27
+ Last audit: <date> (<N> findings, <N> fixed, <N> open)
28
+ Test coverage: <N> unit tests, <N> E2E tests
29
+ Known issues: <N> tracked across <N> features
30
+ Quality gates: <N> files over 300 lines
31
+
32
+ Initiatives: <N> total (<N> active, <N> planned, <N> complete, <N> cancelled)
33
+ Active waves: <wave-title> [<done>/<total> features complete] (one line per active wave)
34
+ (shown only if .mdd/initiatives/ exists and has files; omit section entirely if directory is absent)
35
+
36
+ MDD version: v<N> (current)
37
+ v<N>: <N> files — up to date
38
+ v<N-1>: <N> files — run /install-mdd to update the command, then /mdd audit to refresh docs
39
+ v0 (unversioned): <N> files — created before versioning was introduced
40
+
41
+ Drift check:
42
+ <N> features in sync
43
+ <N> features possibly drifted ← run /mdd scan for details
44
+ <N> features untracked ← no last_synced field yet
45
+
46
+ Run `/mdd audit` to refresh, `/mdd scan` to see drift details, `/mdd plan-initiative` to start an initiative, `/mdd ops <description>` to create a deployment runbook, or `/mdd <feature>` to build something new.
47
+ ```
48
+
49
+ If all files are on the current `mdd_version`, omit the version breakdown and just show: `MDD version: v<N> — all files up to date`
50
+
51
+ **Drift check logic** (lightweight — no full git log, just a quick presence check):
52
+ 1. For each `.mdd/docs/*.md`, read `last_synced` from frontmatter.
53
+ 2. If `last_synced` is missing → untracked.
54
+ 3. If `last_synced` exists: run `git log --oneline --after="<last_synced>" -- <source_files>` for the first source file only (quick check). If output is non-empty → possibly drifted.
55
+ 4. Count each category and show totals. Full details go in SCAN MODE.
56
+
57
+ ### Rebuild `.mdd/.startup.md`
58
+
59
+ After collecting status, rebuild the auto-generated zone of `.mdd/.startup.md`:
60
+
61
+ 1. Read the current `.mdd/.startup.md` (if it exists) and extract the **Notes section** — everything after the `---` divider line. This is the user's append-only zone and must be preserved exactly.
62
+ 2. Rebuild the **auto-generated section** (everything above `---`) with fresh data:
63
+ - `Generated: <YYYY-MM-DD>` (date only, no time)
64
+ - `Branch:` from `git branch --show-current`
65
+ - `Stack:` from `CLAUDE.md` or `claude-mastery-project.conf` if detectable, otherwise `(unknown)`
66
+ - `Features Documented:` sorted list of `.mdd/docs/*.md` filenames with status if detectable from frontmatter
67
+ - `Ops Runbooks:` sorted list of `.mdd/ops/*.md` filenames with status — omit section entirely if `.mdd/ops/` is empty
68
+ - `Last Audit:` from the most recent `.mdd/audits/report-*.md` — extract findings/fixed/open counts
69
+ - `Rules Summary:` static block (does not change)
70
+ 3. Write the rebuilt auto-generated section + `---` divider + preserved Notes section back to `.mdd/.startup.md`. Update `mdd_version` in the file's frontmatter to current.
71
+ 4. If no `.mdd/.startup.md` exists yet, create it fresh using the template with an empty Notes section, stamped with current `mdd_version`.
72
+
73
+ ---
74
+
75
+ ## NOTE MODE — `/mdd note`
76
+
77
+ Triggered when arguments start with `note`. Three subcommands:
78
+
79
+ ```
80
+ /mdd note "your note here" -- append a timestamped note to .startup.md
81
+ /mdd note list -- print only the Notes section
82
+ /mdd note clear -- wipe the Notes section (asks for confirmation)
83
+ ```
84
+
85
+ ### `/mdd note "your note here"` — Append
86
+
87
+ 1. Read `.mdd/.startup.md`. If it does not exist, create it first using the startup template (same as generated by `/mdd status` with placeholder values), then continue.
88
+ 2. Find the `---` divider line.
89
+ 3. Append below the divider: `- [YYYY-MM-DD] your note here` (use today's date).
90
+ 4. Write the file back.
91
+ 5. Print: `Note added to .mdd/.startup.md`
92
+
93
+ ### `/mdd note list` — List Notes
94
+
95
+ 1. Read `.mdd/.startup.md`.
96
+ 2. Print everything after the `---` divider (the Notes section).
97
+ 3. If the Notes section is empty or contains only the placeholder text, print: `(no notes yet)`
98
+
99
+ ### `/mdd note clear` — Clear Notes
100
+
101
+ 1. Ask the user: `Clear all notes in .mdd/.startup.md? This cannot be undone. (yes/no)`
102
+ 2. If yes: rewrite the Notes section (everything after `---`) as `(no notes)`
103
+ 3. If no: abort with `Cancelled.`
104
+
105
+ ---
106
+
107
+ ---
108
+
109
+ ## SCAN MODE — `/mdd scan`
110
+
111
+ Triggered when arguments start with `scan`. Detects features whose source files have changed since the last MDD session, and checks for initiative/wave drift.
112
+
113
+ ### Phase SC1 — Read all feature docs, ops runbooks, and initiative/wave files
114
+
115
+ Read every `.mdd/docs/*.md` (excluding `archive/`) and every `.mdd/ops/*.md` (excluding `archive/`). For each, extract:
116
+ - `last_synced` from frontmatter
117
+ - `source_files` list from frontmatter (feature docs) or the ops doc slug for ops runbooks
118
+
119
+ ### Phase SC2 — Check each feature for drift (parallelized)
120
+
121
+ After Phase SC1 has the full feature list (IDs, `last_synced`, `source_files`), delegate all git log checks to a **single Explore agent** rather than running them sequentially in the main conversation.
122
+
123
+ **Why a single agent (not multiple):** `git log` commands are individually fast — the bottleneck is issuing them one at a time in the main conversation. One agent can run all of them in quick succession and return a complete classification table.
124
+
125
+ #### Agent instructions (self-contained)
126
+
127
+ The agent receives:
128
+ - Complete feature list: each feature's ID, `last_synced` date, and `source_files`
129
+ - Classification rules (below)
130
+ - Explicit instruction: run the git checks and return a structured table — do NOT write any files
131
+
132
+ For each feature, the agent runs:
133
+ ```bash
134
+ # Check file existence
135
+ ls <source_file> 2>/dev/null
136
+
137
+ # Check for commits after last_synced (only if files exist)
138
+ git log --oneline --after="<last_synced>" -- <source_file>
139
+ ```
140
+
141
+ #### What the agent returns
142
+
143
+ A classification table — one row per feature:
144
+
145
+ ```
146
+ | Feature ID | Classification | Detail |
147
+ |---|---|---|
148
+ | 01-project-scaffolding | in_sync | last synced: 2026-03-15, no commits after |
149
+ | 04-content-builder | drifted | 3 commits since 2026-03-01, latest: "fix: heading parser" |
150
+ | 07-github-pages | broken | docs/index.html not found on disk |
151
+ | 09-integrations | untracked | no last_synced field |
152
+ ```
153
+
154
+ **Classifications:**
155
+ - **untracked** — `last_synced` missing from frontmatter
156
+ - **broken** — one or more `source_files` not found on disk
157
+ - **drifted** — `last_synced` exists, files exist, commits found after `last_synced`
158
+ - **in_sync** — `last_synced` exists, all files exist, no commits after `last_synced`
159
+
160
+ #### Main conversation: build drift report
161
+
162
+ After the agent returns its table, the main conversation writes the drift report. No file writes happen inside the agent.
163
+
164
+ **Fallback:** If the agent fails, run git checks sequentially in the main conversation using the same logic.
165
+
166
+ ### Phase SC3 — Present drift report
167
+
168
+ ```
169
+ 🔍 MDD Scan — Drift Report
170
+ Generated: <YYYY-MM-DD>
171
+
172
+ ✅ 01-project-scaffolding — in sync (last synced: 2026-03-15)
173
+ ⚠️ 04-content-builder — DRIFTED (3 commits since 2026-03-01)
174
+ Latest: "fix: markdown heading parser"
175
+ ❌ 07-github-pages — broken reference (docs/index.html not found)
176
+ ❓ 09-integrations — untracked (no last_synced field)
177
+
178
+ Summary: 1 in sync · 1 drifted · 1 broken · 1 untracked
179
+
180
+ Recommended actions:
181
+ /mdd update 04 — re-sync content-builder doc with code
182
+ /mdd update 07 — fix broken file reference
183
+ /mdd update 09 — add last_synced by running update mode
184
+ ```
185
+
186
+ **Initiative/wave drift check** (only shown if `.mdd/initiatives/` exists):
187
+
188
+ For each initiative in `.mdd/initiatives/`:
189
+ - Read its `version` field from frontmatter
190
+ - For each of its waves (in `.mdd/waves/`), check that the wave's `initiativeVersion` matches the initiative's current `version`
191
+ - If a wave's `initiativeVersion` is older → flag as stale (run `/mdd plan-sync <initiative-id>` to refresh)
192
+
193
+ ```
194
+ Initiatives:
195
+ ✅ auth-system (v2) — all waves in sync
196
+ ⚠️ payment-flow (v3) — 1 stale wave
197
+ payment-flow-wave-2 (initiativeVersion: 2, initiative now: 3) → run /mdd plan-sync payment-flow
198
+ ```
199
+
200
+ **Ops runbook drift check** (appended when `.mdd/ops/` has files):
201
+
202
+ For each ops runbook, check `last_synced` against the last git commit on the runbook file itself. Since ops runbooks track live service state (not source files), drift means the runbook file hasn't been touched since the last `runop`.
203
+
204
+ ```
205
+ Ops Runbooks:
206
+ ✅ swarmk-dokploy — last runop: 2026-04-17
207
+ ⚠️ rulecatch-dokploy — runbook edited 3 days ago but no runop since → run /mdd runop rulecatch-dokploy
208
+ ```
209
+
210
+ Save the full report to `.mdd/audits/scan-<date>.md`.
211
+
212
+ ---
213
+
214
+ ## UPDATE MODE — `/mdd update <feature-id>`
215
+
216
+ Triggered when arguments start with `update`. Updates an existing feature doc to reflect code that has changed since the last MDD session.
217
+
218
+ ### Phase U1 — Load the feature
219
+
220
+ Parse `<feature-id>` from arguments (e.g., `04` or `04-content-builder`). Find the matching `.mdd/docs/*.md` file. Read it fully.
221
+
222
+ If the feature-id is not found, list all available docs and ask the user to pick one.
223
+
224
+ ### Phase U2 — Read current source files
225
+
226
+ Read every file listed in `source_files` frontmatter. If a file is missing, note it as a broken reference — ask the user for the new path before continuing.
227
+
228
+ ### Phase U3 — Diff doc vs code
229
+
230
+ Compare what the doc says against what the code actually does:
231
+ - New functions, endpoints, or exports not in the doc
232
+ - Removed or renamed functions that the doc still mentions
233
+ - Data model fields that changed
234
+ - Business rules that changed (different validation, new states)
235
+ - New edge cases visible in error handling
236
+
237
+ Write findings to `.mdd/audits/update-notes-<feature-id>-<date>.md`.
238
+
239
+ ### Phase U4 — Present changes
240
+
241
+ ```
242
+ 📝 Update Review: <NN>-<feature-name>
243
+
244
+ Changes detected since <last_synced>:
245
+ + Added: <new thing>
246
+ - Removed: <removed thing>
247
+ ~ Changed: <changed thing>
248
+
249
+ Doc sections needing update:
250
+ - API Endpoints (new route: POST /api/v1/...)
251
+ - Business Rules (validation logic changed)
252
+
253
+ Proceed with doc update? (yes / review findings first / cancel)
254
+ ```
255
+
256
+ Wait for user confirmation.
257
+
258
+ ### Phase U5 — Rewrite affected sections
259
+
260
+ Rewrite ONLY the sections that changed. Preserve:
261
+ - `known_issues` section (don't remove existing issues)
262
+ - `depends_on` list (only add, never remove without asking)
263
+ - Any manually written prose that is still accurate
264
+
265
+ After rewriting, update frontmatter:
266
+ - `last_synced: <today's date>`
267
+ - `status:` — ask the user if they want to update the status (e.g., draft → complete)
268
+ - `phase:` — update to reflect current state
269
+
270
+ ### Phase U6 — Regenerate test skeletons for new behaviors
271
+
272
+ For any NEW documented behaviors (not previously in the doc), generate test skeleton entries and append them to the existing test file. Do NOT modify existing test implementations.
273
+
274
+ Report:
275
+ ```
276
+ ✅ Update Complete: <NN>-<feature-name>
277
+
278
+ Doc updated: .mdd/docs/<NN>-<feature-name>.md
279
+ last_synced: <today>
280
+ Sections rewritten: <list>
281
+ New test skeletons: <N> appended to tests/unit/<feature-name>.test.ts
282
+
283
+ Branch: <current branch>
284
+ ```
285
+
286
+ ---
287
+
288
+ ## DEPRECATE MODE — `/mdd deprecate <feature-id>`
289
+
290
+ Triggered when arguments start with `deprecate`. Archives a feature cleanly.
291
+
292
+ ### Phase D1 — Load + impact check
293
+
294
+ Find and read the target feature doc. Then scan all other `.mdd/docs/*.md` for any that list this feature in `depends_on`. Build the impact list.
295
+
296
+ ### Phase D2 — Present impact
297
+
298
+ ```
299
+ 🗑️ Deprecate: <NN>-<feature-name>
300
+
301
+ This will:
302
+ - Set status: deprecated in the doc frontmatter
303
+ - Move doc to .mdd/docs/archive/<NN>-<feature-name>.md
304
+
305
+ Dependents (docs that depend on this feature):
306
+ - 05-testing-framework (depends_on includes this)
307
+ - 09-integrations (depends_on includes this)
308
+
309
+ Source files registered:
310
+ - src/handlers/content.ts
311
+ - scripts/build-content.ts
312
+
313
+ Test files registered:
314
+ - tests/unit/content-builder.test.ts
315
+
316
+ Deprecate? (yes / review dependents first / cancel)
317
+ ```
318
+
319
+ If user says yes:
320
+
321
+ ### Phase D3 — Archive
322
+
323
+ 1. Set `status: deprecated` and `last_synced: <today>` in the doc frontmatter.
324
+ 2. Create `.mdd/docs/archive/` directory if it doesn't exist.
325
+ 3. Move the doc file to `.mdd/docs/archive/`.
326
+ 4. For each dependent doc, add an entry to its `known_issues`: `<NN>-<feature-name> has been deprecated — review this feature's dependency.`
327
+ 5. Ask the user separately: "Delete source files? (yes / no)" and "Delete test files? (yes / no)" — never auto-delete.
328
+ 6. Rebuild `.mdd/.startup.md`.
329
+
330
+ Report:
331
+ ```
332
+ ✅ Deprecated: <NN>-<feature-name>
333
+
334
+ Doc archived: .mdd/docs/archive/<NN>-<feature-name>.md
335
+ Dependents flagged: <N> docs updated with known_issues warning
336
+ Source files: <kept/deleted per user choice>
337
+ Test files: <kept/deleted per user choice>
338
+ ```
339
+
340
+ ---