@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,378 @@
1
+ ## OPS DOCUMENT MODE — `/mdd ops <description>`
2
+
3
+ Triggered when arguments start with `ops`. If arguments are exactly `ops list` → jump to **Ops List Mode** (Phase OL) instead.
4
+
5
+ ### Phase OP1 — Scope, slug, and collision check
6
+
7
+ **Step 1 — Ask scope first (before anything else):**
8
+
9
+ ```
10
+ Where should this runbook live?
11
+ (a) Project — .mdd/ops/<slug>.md (this project only)
12
+ (b) Global — ~/.claude/ops/<slug>.md (reusable across all projects)
13
+
14
+ Note: Global ops cannot access project-local .env variables or
15
+ project-specific paths. Use ~/.env globals only.
16
+ ```
17
+
18
+ **Step 2 — Derive slug:**
19
+ Strip `ops` from the start of arguments. Use the remainder as the description.
20
+ Derive a slug: lowercase, hyphens, drop filler words (e.g., "deploy swarmk to dokploy" → `swarmk-dokploy`, "update cloudflare dns" → `cloudflare-dns`).
21
+
22
+ **Step 3 — Collision check:**
23
+ - If scope is **project**: check whether `~/.claude/ops/<slug>.md` exists.
24
+ - If global op exists with that slug → **hard stop**:
25
+ *"A global runbook named `<slug>` already exists (`~/.claude/ops/<slug>.md`). Project ops cannot share a name with a global op — use a different name, or run `/mdd runop <slug>` to execute the global one."*
26
+ - If scope is **global**: check whether `~/.claude/ops/` exists, create it if not (`mkdir -p ~/.claude/ops`).
27
+
28
+ **Step 4 — Check target location:**
29
+ - Target path: `.mdd/ops/<slug>.md` (project) or `~/.claude/ops/<slug>.md` (global)
30
+ - **Does not exist** → proceed to Phase OP2 (create)
31
+ - **Exists** → tell the user: *"Runbook `<slug>` already exists. Use `/mdd update-op <slug>` to edit it or `/mdd runop <slug>` to execute it."* Stop.
32
+
33
+ ### Phase OP2 — Ask questions
34
+
35
+ Ask all questions in a single interaction:
36
+
37
+ 1. "What is this deployment? (describe the target — e.g., swarmk API and dashboard to Dokploy US + EU)"
38
+ 2. "What platform? (dokploy / docker-hub / vercel / github-actions / manual / other)"
39
+ 3. "List all services being deployed — for each: name, Docker image name, port (or none), health check command"
40
+ 4. "List your deployment regions — for each: slug, host, platform, deploy order (1 = deploy first / canary)"
41
+ 5. "Deployment strategy: sequential or parallel across regions? What gates between regions? (health_check / manual / none)"
42
+ 6. "What happens if a canary gate fails? (stop / skip_region / rollback) Auto-rollback on failure? (yes/no)"
43
+ 7. "How is deployment triggered? (Dokploy webhook URL as env var, GitHub Actions workflow name, manual command, etc.)"
44
+ 8. "What credentials and API keys does this deployment need? List as env var names only — never values. Where is each stored?"
45
+ 9. "Are any MCP servers required during deployment? (e.g., strictdb-mcp for post-deploy seeding)"
46
+ 10. "What environments does this target? (staging / production / both)"
47
+
48
+ ### Phase OP3 — Write the runbook
49
+
50
+ Create `.mdd/ops/<slug>.md` with full frontmatter and all 7 mandatory sections:
51
+
52
+ ```markdown
53
+ ---
54
+ id: <slug>
55
+ title: <title>
56
+ type: ops
57
+ platform: <platform>
58
+ environments: [<list>]
59
+ deployment_strategy:
60
+ order: sequential
61
+ gate: health_check
62
+ on_gate_failure: stop
63
+ rollback_on_failure: false
64
+ regions:
65
+ - slug: <slug>
66
+ host: <host>
67
+ platform: <platform>
68
+ deploy_order: 1
69
+ role: canary
70
+ - slug: <slug>
71
+ host: <host>
72
+ platform: <platform>
73
+ deploy_order: 2
74
+ role: primary
75
+ services:
76
+ - slug: <name>
77
+ image: <registry/name:tag>
78
+ port: <port or ~>
79
+ health_check: <exact command>
80
+ regions:
81
+ <region-slug>:
82
+ image: <registry/name:tag>
83
+ status: unknown
84
+ last_checked: ~
85
+ status: draft
86
+ last_synced: <YYYY-MM-DD>
87
+ mdd_version: <current>
88
+ known_issues: []
89
+ ---
90
+
91
+ # <title>
92
+
93
+ ## Overview
94
+ <What this deployment does and why — 2-3 sentences>
95
+
96
+ ## Services & Ports
97
+ <Table: service | image | port | health endpoint>
98
+
99
+ ## Environment Targets
100
+ <Which environments, what platforms, any environment-specific notes>
101
+
102
+ ## Webhooks & Triggers
103
+ <How deployment is triggered: Dokploy webhook URL as $ENV_VAR, GitHub Actions workflow, manual command, etc.>
104
+
105
+ ## Credentials & API Keys
106
+ <Table: credential name | env var | where stored>
107
+ **NEVER include actual values — env var names only.**
108
+
109
+ ## MCP Servers
110
+ <Any MCP servers required during deployment, or "(none)">
111
+
112
+ ## Deployment Procedure
113
+ <Ordered steps. Each step MUST have: name, command/action, verification check.>
114
+
115
+ Step 1 (Name):
116
+ Action: <exact command>
117
+ Verify: <command that returns exit 0 on success>
118
+
119
+ Step 2 (Name):
120
+ Action: <exact command>
121
+ Verify: <command that returns exit 0 on success>
122
+
123
+ ## Rollback Plan
124
+ <Specific steps to undo this deployment if it fails. Must be actionable, not "revert the commit".>
125
+ ```
126
+
127
+ ### Phase OP4 — Offer next steps
128
+
129
+ ```
130
+ ✅ Runbook created: .mdd/ops/<slug>.md
131
+
132
+ Next steps:
133
+ /mdd runop <slug> — execute the runbook now
134
+ /mdd update-op <slug> — edit the runbook
135
+ ```
136
+
137
+ ---
138
+
139
+ ## OPS EXECUTE MODE — `/mdd runop <slug>`
140
+
141
+ Triggered when arguments start with `runop`. Executes an existing ops runbook with pre-flight health checks, canary-gated region deployment, and post-flight verification.
142
+
143
+ ### Phase RO1 — Load runbook
144
+
145
+ 1. Parse `<slug>` from arguments — hard stop *"Slug required. Usage: /mdd runop <slug>"* if missing.
146
+ 2. Locate the runbook (project-local first, then global):
147
+ - Check `.mdd/ops/<slug>.md` → found: announce *"Running project runbook: `<slug>`"*
148
+ - Check `~/.claude/ops/<slug>.md` → found: announce *"Running global runbook: `<slug>`"*
149
+ - Neither found → hard stop: *"No runbook found for `<slug>` (checked project and global). Run `/mdd ops <description>` to create one, or `/mdd ops list` to see all available runbooks."*
150
+ 3. Parse all frontmatter fields: regions (sorted by `deploy_order`), services, `deployment_strategy`.
151
+
152
+ ### Phase RO2 — Pre-flight health check (all regions)
153
+
154
+ Run each service's `health_check` for each of its declared regions. Display a status table:
155
+
156
+ ```
157
+ Pre-flight Health Check — <slug>
158
+ ──────────────────────────────────────────────────
159
+ <region-1> <region-2>
160
+ <service> ✓ healthy ✗ failing
161
+ <service> ✓ healthy ✓ healthy
162
+ <service> ? unknown ? unknown
163
+
164
+ (last checked: <date> | <date>)
165
+ ```
166
+
167
+ Write updated `status` and `last_checked` to each `services[].regions.<slug>` entry in frontmatter immediately.
168
+
169
+ For each service that is **not healthy**, ask per region:
170
+ ```
171
+ <service> is <status> in <region>. What do you want to do?
172
+ (a) Redeploy — run this service's deployment steps
173
+ (b) Skip — continue without touching this service in this region
174
+ (c) Abort — stop the entire runop
175
+ ```
176
+
177
+ ### Phase RO3 — Deploy region by region (in deploy_order)
178
+
179
+ For each region in `deploy_order` sequence:
180
+
181
+ **Step A — Deploy services in this region**
182
+ - For each service marked for redeploy in this region:
183
+ - Use `services[].regions.<slug>.image` (falls back to `services[].image` if not set)
184
+ - Walk through the service's steps in the Deployment Procedure section
185
+ - Each step: announce name → run command → run verification check
186
+ - Verification passes → ✓, continue
187
+ - Verification fails → STOP, show exact output, surface Rollback Plan section
188
+ - If `rollback_on_failure: true` → automatically run rollback steps, then stop
189
+
190
+ **Step B — Region gate**
191
+
192
+ Run health checks for all services in this region. Display result:
193
+ ```
194
+ ── <region> (<role>) — gate check ────────────────
195
+ <service> ✓ healthy (<image>)
196
+ <service> ✓ healthy
197
+ Gate: PASSED ✓
198
+ ```
199
+
200
+ If gate is `health_check` and any service is not `healthy`:
201
+ - Apply `on_gate_failure`:
202
+ - `stop` → halt, show what failed, print: *"<next-region> was NOT deployed — <this-region> gate failed."*
203
+ - `skip_region` → log failure, advance to next region
204
+ - `rollback` → run Rollback Plan steps for this region, then stop
205
+ - Write updated status to frontmatter before stopping
206
+
207
+ If gate is `manual` → always pause: *"<region> deployed. Proceed to <next-region>? (yes / abort)"*
208
+
209
+ If gate is `none` → advance immediately.
210
+
211
+ Write updated `status` and `last_checked` for all services in this region to frontmatter.
212
+
213
+ **Step C — Advance**
214
+
215
+ Gate passed → proceed to next region in `deploy_order`. Repeat Steps A–B.
216
+
217
+ ### Phase RO4 — Post-flight health check (all regions)
218
+
219
+ Re-run all service health checks across all regions. Display full cross-region before → after table:
220
+
221
+ ```
222
+ Post-flight Health Check — <slug>
223
+ ──────────────────────────────────────────────────────────────
224
+ <region-1> <region-2>
225
+ <service> ✓ healthy (was ✗) ✓ healthy
226
+ <service> ✓ healthy ✓ healthy
227
+ ```
228
+
229
+ Write final `status` and `last_checked` to all service region entries in frontmatter.
230
+ Any service still failing → append entry to `known_issues` in the doc.
231
+
232
+ ### Phase RO5 — Summary
233
+
234
+ ```
235
+ runop complete — <slug>
236
+
237
+ <region-1> (canary) <region-2> (primary)
238
+ <service> ✓ healthy ✓ healthy
239
+ <service> ✓ healthy ✓ healthy
240
+
241
+ Canary gate: PASSED ✓
242
+ Regions deployed: <N>/<N>
243
+ Steps executed: <N>/<N> ✓
244
+ last_synced: <YYYY-MM-DD>
245
+ ```
246
+
247
+ If canary gate failed and primary was skipped:
248
+ ```
249
+ runop stopped — <slug>
250
+
251
+ <region-1> (canary): ✗ gate FAILED — <service> failing after deploy
252
+ <region-2> (primary): NOT deployed — canary gate must pass first
253
+
254
+ on_gate_failure: stop
255
+ Fix: resolve <service> in <region-1>, then re-run /mdd runop <slug>
256
+ ```
257
+
258
+ ---
259
+
260
+ ## OPS UPDATE MODE — `/mdd update-op <slug>`
261
+
262
+ Triggered when arguments start with `update-op`. Updates an existing ops runbook.
263
+
264
+ ### Phase UO1 — Load
265
+
266
+ 1. Parse `<slug>` — hard stop *"Slug required. Usage: /mdd update-op <slug>"* if missing.
267
+ 2. Locate runbook (project-local first, then global):
268
+ - Check `.mdd/ops/<slug>.md` → found: load it, note scope = project
269
+ - Check `~/.claude/ops/<slug>.md` → found: load it, note scope = global
270
+ - Neither found → hard stop: *"No runbook found for `<slug>`. Run `/mdd ops list` to see all available runbooks."*
271
+
272
+ ### Phase UO2 — Re-ask with current values pre-filled
273
+
274
+ Re-present the Phase OP2 questions with current values shown as defaults. User can accept (press enter) or type a new value. Only changed fields are rewritten.
275
+
276
+ Show a diff summary before writing:
277
+ ```
278
+ Changes detected:
279
+ + regions: eu-central added
280
+ ~ services.api.regions.eu-west.image: old-name:v1 → new-name:v2
281
+ ~ deployment_strategy.on_gate_failure: stop → rollback
282
+ ```
283
+
284
+ Ask: *"Apply these changes? (yes / cancel)"*
285
+
286
+ ### Phase UO3 — Rewrite and update
287
+
288
+ Rewrite only changed sections. Preserve:
289
+ - `known_issues` (never remove existing entries without asking)
290
+ - Service `status` and `last_checked` values (these are live data, not config)
291
+
292
+ Update frontmatter: `last_synced: <today>`, `status: draft` if previously `complete` and structural changes were made.
293
+
294
+ ```
295
+ ✅ Updated: .mdd/ops/<slug>.md
296
+ last_synced: <today>
297
+ Sections rewritten: <list>
298
+ ```
299
+
300
+ ---
301
+
302
+ ## OPS LIST MODE — `/mdd ops list`
303
+
304
+ Triggered when arguments are exactly `ops list`. Lists all ops runbooks — global and project — in a single unified view.
305
+
306
+ ### Phase OL — Scan and display
307
+
308
+ 1. Glob `~/.claude/ops/*.md` — read each, extract `id`, `title`, `platform`, `status`, and the last `last_checked` value across all services.
309
+ 2. Glob `.mdd/ops/*.md` (excluding `archive/`) — same fields.
310
+ 3. Display unified list, grouped by scope:
311
+
312
+ ```
313
+ 📦 Ops Runbooks
314
+
315
+ Global (~/.claude/ops/)
316
+ cloudflare-dns DNS record updates via Cloudflare API last run: 2026-04-10
317
+ docker-hub-login Docker Hub authentication procedure last run: 2026-03-28
318
+ ssl-renewal Let's Encrypt cert renewal (Certbot) last run: never
319
+
320
+ Project (.mdd/ops/)
321
+ rulecatch-dokploy 10 services → eu-west (canary) + us-east last run: 2026-04-18 ✓ all healthy
322
+ swarmk-dokploy 7 services → eu-west (canary) + us-east last run: 2026-04-17 ⚠ api degraded
323
+
324
+ Run /mdd runop <slug> to execute any runbook.
325
+ ```
326
+
327
+ If either directory is empty or missing, omit that section without error. If both are empty:
328
+ ```
329
+ No ops runbooks found.
330
+ Project: /mdd ops <description> (saves to .mdd/ops/)
331
+ Global: /mdd ops <description> (choose "global" when prompted)
332
+ ```
333
+
334
+ ---
335
+
336
+ ## COMMANDS MODE — `/mdd commands`
337
+
338
+ Triggered when arguments start with `commands`. Outputs a reference table of every available MDD mode.
339
+
340
+ ### Phase CM — Render Mode Reference
341
+
342
+ Read the **Step 0b — Detect Mode** block from this file (the loaded prompt). For every bullet point that maps an argument pattern to a mode, extract the trigger word(s) and the mode name. Then render the following table:
343
+
344
+ ```
345
+ 📋 MDD Commands — Mode Reference
346
+
347
+ Command | Description
348
+ -------------------------------------------|------------------------------------------------------------
349
+ /mdd <feature description> | Build Mode — Document, plan, and implement a new feature
350
+ /mdd audit [section] | Audit Mode — Scan code against MDD docs for violations and drift
351
+ /mdd status | Status Mode — Overview of docs, audits, tests, and initiatives
352
+ /mdd scan | Scan Mode — Detect features whose source files have changed since last sync
353
+ /mdd update <feature-id> | Update Mode — Re-sync a feature doc after its code has changed
354
+ /mdd note "text" | Note Mode — Append a timestamped note to .mdd/.startup.md
355
+ /mdd note list | Note Mode — Print the Notes section of .mdd/.startup.md
356
+ /mdd note clear | Note Mode — Wipe all notes (asks for confirmation)
357
+ /mdd deprecate <feature-id> | Deprecate Mode — Archive a feature and flag all dependents
358
+ /mdd reverse-engineer [path|feature-id] | Reverse-Engineer Mode — Generate MDD docs from existing source code
359
+ /mdd graph | Graph Mode — Render the full cross-feature dependency map
360
+ /mdd upgrade | Upgrade Mode — Batch-patch missing frontmatter fields across all docs
361
+ /mdd commands | Commands Mode — Show this reference table
362
+ /mdd plan-initiative | Plan-Initiative Mode — Create a new multi-wave initiative
363
+ /mdd plan-wave <wave-slug> | Plan-Wave Mode — Plan a wave within an existing initiative
364
+ /mdd plan-execute <wave-slug> | Plan-Execute Mode — Run the MDD build flow for every feature in a wave
365
+ /mdd plan-sync | Plan-Sync Mode — Reconcile manual edits to initiative/wave files
366
+ /mdd plan-remove-feature <wave> <feature> | Plan-Remove-Feature Mode — Remove a feature from a wave
367
+ /mdd plan-cancel-initiative <slug> | Plan-Cancel-Initiative Mode — Cancel an initiative and archive its waves
368
+ /mdd ops <description> | Ops Document Mode — Create a runbook (asks: global ~/.claude/ops/ or project .mdd/ops/)
369
+ /mdd ops list | Ops List Mode — Show all runbooks (global and project) with last-run status
370
+ /mdd runop <slug> | Ops Execute Mode — Run a runbook: pre-flight health check, canary-gated deploy, post-flight verify
371
+ /mdd update-op <slug> | Ops Update Mode — Edit an existing runbook (checks project then global)
372
+
373
+ Run /mdd <feature description> to start building, /mdd ops <description> to create a deployment runbook, or /mdd audit to check existing code.
374
+ ```
375
+
376
+ No files are created or modified by this mode.
377
+
378
+ ---