magic-spec 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
+ ---
2
+ description: Workflow for creating and managing project specifications and the specification registry.
3
+ ---
4
+
5
+ # Specification Workflow
6
+
7
+ This workflow defines a universal, technology-agnostic process for creating and managing project specifications in the `.design/specifications/` directory. It is designed to be applicable across any stack (Frontend, Backend, Fullstack, GameDev, etc.).
8
+
9
+ > **Scope**: This workflow covers specification authoring only — what exists and how it is structured.
10
+ > Prioritization, phasing, and implementation order are handled by the **Plan Workflow** (`plan.md`).
11
+
12
+ ## Agent Guidelines
13
+
14
+ **CRITICAL INSTRUCTIONS FOR AI:**
15
+
16
+ 1. **No Code in Specs**: Never generate implementation code (Rust, JS, Python, etc.) inside specification files. Use pseudo-code or logic flows if necessary.
17
+ 2. **Structure First**: Always verify `.design/INDEX.md` and `.design/RULES.md` exist before creating a new spec.
18
+ 3. **Universal Applicability**: This workflow is stack-agnostic. Adapt the content (APIs, DBs, UI) to the user's technology, but keep the *structure* rigid.
19
+ 4. **Auto-Init**: If `.design/` or its system files are missing, automatically trigger the Init pre-flight check (`.magic/init.md`) before proceeding. Do not ask — just initialize and continue.
20
+ 5. **Linking**: Every new spec must be registered in `INDEX.md`. Every spec that depends on another must declare it in `Related Specifications`.
21
+ 6. **Status Discipline**: Always assign a valid status from the **Status Lifecycle** section. Never leave status blank.
22
+ 7. **Capture First**: When the user provides unstructured input (thoughts, notes, ideas), always follow the *Dispatching from Raw Input* workflow before writing anything.
23
+ 8. **Review Always**: After every create or update operation, run *Post-Update Review* before closing the task. No operation is complete without it.
24
+ 9. **Rules Are Constitution**: RULES.md is the source of truth for project conventions. Read it before every operation. Update it on every defined trigger. Never contradict it without proposing an explicit amendment.
25
+ 10. **Checklist Before Done**: Every task must end with the *Task Completion Checklist* shown to the user. A task is not complete until the checklist is presented and all items are confirmed.
26
+
27
+ ## Directory Structure
28
+
29
+ ```plaintext
30
+ .design/
31
+ ├── INDEX.md # Registry: what specs exist and their status
32
+ ├── RULES.md # Constitution: how spec work is governed
33
+ ├── PLAN.md # Implementation plan (managed by Plan Workflow)
34
+ ├── specifications/ # Spec files
35
+ │ └── *.md
36
+ └── tasks/ # Task files (managed by Task Workflow)
37
+ ├── TASKS.md # Master task index
38
+ └── phase-{n}.md # Per-phase task files
39
+ ```
40
+
41
+ **System files and their roles:**
42
+
43
+ | File | Role | Updated by |
44
+ | :--- | :--- | :--- |
45
+ | `INDEX.md` | Central registry of all spec files | Every create/update |
46
+ | `RULES.md` | Project constitution and conventions | Defined triggers |
47
+
48
+ ## Status Lifecycle
49
+
50
+ All specification files must use one of the following statuses:
51
+
52
+ - **Draft** — work in progress, not ready for review.
53
+ - **RFC** *(Request for Comments)* — complete enough for team review, open for feedback and discussion.
54
+ - **Stable** — reviewed and approved; implementation can begin.
55
+ - **Deprecated** — superseded by another spec; kept for historical reference only.
56
+
57
+ Status transitions follow this flow:
58
+
59
+ ```mermaid
60
+ graph LR
61
+ Draft --> RFC --> Stable --> Deprecated
62
+ RFC --> Draft
63
+ ```
64
+
65
+ ## Workflow Steps
66
+
67
+ ### Dispatching from Raw Input
68
+
69
+ Use this workflow when the user provides unstructured input: a thought, a note, a wish, a comment, or any free-form text that contains specification-relevant information.
70
+
71
+ ```mermaid
72
+ graph TD
73
+ A[Raw Input] --> R[Read RULES.md]
74
+ R --> B[Parse: identify distinct topics]
75
+ B --> C[Map: match topics to spec domains]
76
+ C --> D[Confirm: show mapping to user]
77
+ D -->|Approved| E[Dispatch: write to spec files]
78
+ D -->|Rejected| B
79
+ E --> F[Post-Update Review]
80
+ F --> G[Check RULES.md triggers]
81
+ G --> H[Sync INDEX.md]
82
+ H --> I[Task Completion Checklist]
83
+ ```
84
+
85
+ 1. **Read RULES.md**: Before doing anything, read `RULES.md` to ensure all decisions align with established project conventions.
86
+ 2. **Parse**: Read the input and extract all distinct topics, decisions, constraints, or preferences mentioned. A single message may contain material for multiple spec files.
87
+ 3. **Map**: Match each extracted topic to an existing spec file or propose a new one:
88
+ - System design, modules, layers → `architecture.md`
89
+ - Endpoints, contracts, protocols → `api.md`
90
+ - Data models, storage, migrations → `database-schema.md`
91
+ - Visual design, components, style → `ui-components.md`
92
+ - Cross-cutting or unclassified → propose a new domain
93
+ 4. **Confirm**: Before writing anything, show the user the proposed mapping and wait for explicit approval:
94
+
95
+ ```
96
+ I found the following topics in your input:
97
+
98
+ - JWT + Redis auth flow → architecture.md (section 3: Auth Design)
99
+ - REST-only constraint → architecture.md (section 2: Constraints)
100
+ - shadcn-based design system → ui-components.md (new file, Draft)
101
+
102
+ Proceed with this mapping? (yes / adjust)
103
+ ```
104
+
105
+ 5. **Dispatch**: Write each piece into the correct spec file following the Specification Template. Never mix topics from different domains in a single section.
106
+ 6. **Post-Update Review**: Run the review checklist on every file that was modified (see *Post-Update Review*).
107
+ 7. **Check RULES.md triggers**: After writing, evaluate whether any RULES.md update trigger was activated (see *Updating RULES.md*).
108
+ 8. **Sync INDEX.md**: Add or update rows to reflect the current state of all modified files.
109
+ 9. **Task Completion Checklist**: Present the checklist to the user.
110
+
111
+ **Edge cases:**
112
+
113
+ - If intent is ambiguous — ask one clarifying question before mapping, do not guess.
114
+ - If a topic doesn't fit any existing domain — propose a new spec file with a suggested name.
115
+ - If the input contradicts an existing rule in `RULES.md` — flag the conflict explicitly and ask whether to proceed or amend the rule first.
116
+ - If the input contradicts an existing Stable spec — flag the conflict explicitly before dispatching.
117
+
118
+ ### Creating a New Specification
119
+
120
+ 1. **Read RULES.md**: Check project conventions before creating anything.
121
+ 2. **Context Analysis**: Determine the domain of the new specification and the project's tech stack.
122
+ 3. **State Check**: Verify if `.design/` and its core files exist.
123
+ 4. **Auto-Init**: If `.design/INDEX.md` or `.design/RULES.md` are missing, automatically run the Init pre-flight check (`.magic/init.md`) and continue.
124
+ 5. **Content Creation**:
125
+ - Create `{specification-name}.md` using the *Specification Template*.
126
+ - Use `plaintext` for directory trees and `mermaid` for diagrams.
127
+ - Fill in `Related Specifications` with any dependencies on existing specs.
128
+ - Fill in `Implementation Notes` if the implementation order is non-obvious.
129
+ 6. **Registry Update**: Add the new file as a row in the `INDEX.md` table with its status and version.
130
+ 7. **Post-Update Review**: Run the review checklist on the newly created file.
131
+ 8. **Check RULES.md triggers**: Evaluate whether any RULES.md update trigger was activated.
132
+ 9. **Task Completion Checklist**: Present the checklist to the user.
133
+
134
+ ### Updating an Existing Specification
135
+
136
+ 1. **Read RULES.md**: Check project conventions before modifying anything.
137
+ 2. **Version Bump**: Increment the version according to the change scope:
138
+ - `patch` (0.0.X) — typo fixes, clarifications, no structural change.
139
+ - `minor` (0.X.0) — new section added or existing section extended.
140
+ - `major` (X.0.0) — breaking restructure or significant design change.
141
+ 3. **Document History**: Append a new row to the `Document History` table inside the spec file.
142
+ 4. **Status Update**: If the status changes (e.g., `Draft → RFC`), update both the spec file header and the `INDEX.md` table entry.
143
+ 5. **INDEX.md Sync**: Update the `Version` and `Status` columns in `INDEX.md` to match the new state.
144
+ 6. **Post-Update Review**: Run the review checklist on every file that was modified. This step is mandatory and must not be skipped.
145
+ 7. **Check RULES.md triggers**: Evaluate whether any RULES.md update trigger was activated.
146
+ 8. **Task Completion Checklist**: Present the checklist to the user.
147
+
148
+ ### Post-Update Review
149
+
150
+ **Mandatory after every create or update operation, regardless of change size.**
151
+
152
+ #### Duplication Check
153
+
154
+ - Are there any paragraphs, rules, or decisions that repeat content already stated elsewhere in this file?
155
+ - Is any content duplicated across other spec files? If so, keep it in the most relevant file and replace the duplicate with a cross-reference link.
156
+
157
+ #### Coherence Check
158
+
159
+ - Does the document read as a single consistent whole, or does it feel like a patchwork of additions?
160
+ - Are all sections still relevant to the file's stated purpose, or have any drifted out of scope?
161
+ - Is the logical flow of sections still correct after the update?
162
+
163
+ #### Links & Relations Check
164
+
165
+ - Are all links in `Related Specifications` still accurate and necessary?
166
+ - Does the updated content introduce new dependencies on other specs that are not yet declared?
167
+
168
+ #### Rules Compliance Check
169
+
170
+ - Does any content in the modified file contradict a rule in `RULES.md`?
171
+ - If a contradiction is found — flag it to the user before closing. Do not silently resolve it.
172
+
173
+ #### Cleanup
174
+
175
+ - Remove or consolidate any sections that have become redundant.
176
+ - Rewrite any passages that have grown unclear due to successive edits.
177
+ - If a major restructure is needed, treat it as a `major` version bump and note it in `Document History`.
178
+
179
+ > If the review reveals significant issues beyond the original edit scope, inform the user and propose a dedicated refactoring pass rather than silently rewriting large portions.
180
+
181
+ ### Updating RULES.md
182
+
183
+ RULES.md is the **project constitution** — the authoritative source of standing decisions and conventions. It governs how all spec work is done within this specific project.
184
+
185
+ **Read RULES.md at the start of every operation. Update it only via defined triggers below.**
186
+
187
+ #### Triggers
188
+
189
+ | # | Trigger | Confirmation required |
190
+ | :--- | :--- | :--- |
191
+ | T1 | User uses universally-scoped language: *"always"*, *"never"*, *"in all specs"*, *"project-wide"* | Yes — propose, then wait |
192
+ | T2 | Same pattern appears in 2+ spec files created in the same session | Yes — propose, then wait |
193
+ | T3 | Periodic Audit reveals inconsistency that a standing rule would prevent | Yes — propose within audit report |
194
+ | T4 | User explicitly declares a rule: *"remember that"*, *"from now on"*, *"project rule:"* | No — apply immediately |
195
+
196
+ **T1–T3** — propose before writing:
197
+
198
+ ```
199
+ I noticed a project-wide convention in your input:
200
+
201
+ → Proposed rule: "All APIs must follow REST. GraphQL is not permitted."
202
+ → Section: Project Conventions
203
+
204
+ Add to RULES.md? (yes / no / adjust)
205
+ ```
206
+
207
+ **T4** — apply immediately, then confirm:
208
+
209
+ ```
210
+ Added to RULES.md → Project Conventions:
211
+ "All APIs must follow REST. GraphQL is not permitted."
212
+ ```
213
+
214
+ #### What Goes in RULES.md
215
+
216
+ - **Universal Rules** (sections 1–6): pre-populated at initialization. Rarely changed.
217
+ - **Project Conventions** (section 7): empty at initialization. Accumulates project-specific decisions via triggers. This is the living part.
218
+
219
+ #### Amending an Existing Rule
220
+
221
+ If new input contradicts a rule already in RULES.md:
222
+
223
+ 1. Flag the contradiction explicitly — never silently override a rule.
224
+ 2. Ask the user: (a) amend the rule, (b) follow the existing rule, or (c) treat as a one-time exception.
225
+ 3. If (a): update the rule, bump RULES.md version (`minor` for amendment, `major` for removal), add a Document History row.
226
+
227
+ ### Periodic Registry Audit
228
+
229
+ Run when the user requests it, or proactively suggest after every 5 updates across the registry.
230
+
231
+ **Trigger phrase**: *"Audit specs"* or *"Review registry"*
232
+
233
+ 1. **Scope**: Read all files listed in `INDEX.md` and read `RULES.md`.
234
+ 2. **Rules Compliance**: Check all spec files against every rule in `RULES.md`. Flag violations.
235
+ 3. **Cross-file Duplication**: Identify content appearing in more than one spec file. Propose consolidation.
236
+ 4. **Orphaned Content**: Flag sections with no clear connection to any other spec or declared feature.
237
+ 5. **Stale Statuses**: Flag specs in `Draft` or `RFC` without recent updates.
238
+ 6. **Broken Relations**: Check all `Related Specifications` links point to existing files.
239
+ 7. **Pattern Detection**: If the same approach appears in 2+ specs, propose a Project Convention (T2 trigger).
240
+ 8. **Report**: Present findings before making any changes:
241
+
242
+ ```
243
+ Registry Audit Report — {YYYY-MM-DD}
244
+
245
+ Rules violations:
246
+ - gameplay-config.md contains Rust code — violates RULES.md §5
247
+ → Recommend: replace with pseudo-code
248
+
249
+ Duplication found:
250
+ - "Auth token format" in architecture.md §3.1 and api.md §2.2
251
+ → Recommend: keep in architecture.md, link from api.md
252
+
253
+ Stale statuses:
254
+ - input-system.md — Draft, no updates in 30+ days
255
+ → Confirm still active or mark Deprecated?
256
+
257
+ Broken relations:
258
+ - ui-components.md → links to architecture.md §6 (does not exist)
259
+ → Recommend: fix reference
260
+
261
+ Pattern detected (T2 trigger):
262
+ - YAML format used independently in 3 specs
263
+ → Propose adding to RULES.md §7 as standing convention?
264
+
265
+ Apply all recommendations? (yes / select / skip)
266
+ ```
267
+
268
+ 9. **Apply**: Only after user approval. Update `INDEX.md`, `RULES.md`, and `Document History` in affected files.
269
+
270
+ ### Task Completion Checklist
271
+
272
+ **Must be shown to the user at the end of every task — no exceptions.**
273
+ Mark each item `✓` (done) or `✗` (skipped/failed). Any `✗` must be explained.
274
+ A task with unresolved `✗` items is not complete.
275
+
276
+ ```
277
+ Task Completion Checklist — {task description}
278
+
279
+ Code & Content
280
+ ☐ No implementation code in any created or modified spec file
281
+ ☐ Pseudo-code used where logic illustration was needed
282
+
283
+ Structure
284
+ ☐ All required sections present (Overview, Motivation, Document History)
285
+ ☐ Related Specifications declared for all dependencies
286
+ ☐ Implementation Notes added if implementation order is non-obvious
287
+
288
+ Status & Versioning
289
+ ☐ Status assigned from valid lifecycle (Draft / RFC / Stable / Deprecated)
290
+ ☐ Status changed only via valid transition (no shortcuts)
291
+ ☐ Version bumped correctly (patch / minor / major)
292
+ ☐ Document History row added
293
+
294
+ System Files
295
+ ☐ INDEX.md updated (new row or version/status change)
296
+ ☐ RULES.md trigger checked and applied if activated
297
+
298
+ Review
299
+ ☐ Post-Update Review performed (duplication, coherence, links, rules compliance)
300
+ ☐ No open contradictions with RULES.md left unresolved
301
+ ```
302
+
303
+ > Do not mark items `✓` speculatively. The checklist is a hard-stop, not a formality.
304
+
305
+ ## Templates
306
+
307
+ > `INDEX.md` and `RULES.md` are created automatically by the Init pre-flight check (`.magic/init.md`)
308
+ > on first invocation of any workflow. No manual setup required.
309
+
310
+ ### Specification File Template ({name}.md)
311
+
312
+ ```markdown
313
+ # {Specification Name}
314
+
315
+ **Version:** {X.Y.Z}
316
+ **Status:** {Draft | RFC | Stable | Deprecated}
317
+
318
+ ## Overview
319
+
320
+ Brief summary of the specification's purpose and scope.
321
+
322
+ ## Related Specifications
323
+
324
+ - [other-spec.md](other-spec.md) - Dependency or relationship description.
325
+
326
+ ## 1. Motivation
327
+
328
+ Why is this specification needed? What problems does it solve?
329
+
330
+ ## 2. Constraints & Assumptions
331
+
332
+ - Hard technical constraints (e.g., "REST only, no GraphQL").
333
+ - Key design assumptions (e.g., "single-region deployment for MVP").
334
+
335
+ ## 3. Detailed Design
336
+
337
+ ### 3.1 Component A
338
+
339
+ Technical details, logic, and flows.
340
+
341
+ **Project Structure:**
342
+
343
+ ```plaintext
344
+ src/
345
+ └── features/
346
+ └── component_a/
347
+ ```
348
+
349
+ **Flow Diagram:**
350
+
351
+ ```mermaid
352
+ graph TD;
353
+ A-->B;
354
+ ```
355
+
356
+ ### 3.2 Component B
357
+
358
+ ...
359
+
360
+ ## 4. Implementation Notes
361
+
362
+ <!-- Optional. Fill if implementation order is non-obvious. -->
363
+
364
+ 1. Step A — prerequisite for all others
365
+ 2. Step B — can begin after A
366
+ 3. Step C — parallel with B
367
+
368
+ ## 5. Drawbacks & Alternatives
369
+
370
+ Potential issues and alternative approaches considered.
371
+
372
+ ## Document History
373
+
374
+ | Version | Date | Author | Description |
375
+ | :--- | :--- | :--- | :--- |
376
+ | 0.1.0 | YYYY-MM-DD | User | Initial Draft |
377
+
378
+ ```