dflow-sdd-ddd 0.7.0 → 0.8.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/docs/evaluating-dflow.en.md +14 -5
  3. package/docs/evaluating-dflow.md +14 -5
  4. package/docs/using-with-claude-code.en.md +17 -9
  5. package/docs/using-with-claude-code.md +15 -8
  6. package/lib/init.js +263 -52
  7. package/package.json +1 -1
  8. package/templates/brownfield/references/dflow-feedback-flow.md +179 -0
  9. package/templates/brownfield/references/drift-verification.md +183 -0
  10. package/templates/brownfield/references/finish-feature-flow.md +259 -0
  11. package/templates/brownfield/references/git-integration.md +312 -0
  12. package/templates/brownfield/references/init-project-flow.md +413 -0
  13. package/templates/brownfield/references/modify-existing-flow.md +444 -0
  14. package/templates/brownfield/references/new-feature-flow.md +367 -0
  15. package/templates/brownfield/references/new-phase-flow.md +259 -0
  16. package/templates/brownfield/references/pr-review-checklist.md +179 -0
  17. package/templates/brownfield/scaffolding/AI-AGENT-GUIDE.md +31 -4
  18. package/templates/brownfield/scaffolding/CLAUDE-md-snippet.md +12 -8
  19. package/templates/brownfield/scaffolding/Git-principles-gitflow.md +1 -1
  20. package/templates/brownfield/scaffolding/Git-principles-trunk.md +1 -1
  21. package/templates/brownfield/scaffolding/_conventions.md +1 -1
  22. package/templates/brownfield/scaffolding/_overview.md +3 -3
  23. package/templates/brownfield/templates/context-map.md +1 -1
  24. package/templates/brownfield/templates/glossary.md +1 -1
  25. package/templates/brownfield/templates/models.md +1 -1
  26. package/templates/brownfield/templates/rules.md +1 -1
  27. package/templates/brownfield/templates/tech-debt.md +1 -1
  28. package/templates/common/skill/SKILL.md +35 -0
  29. package/templates/greenfield/references/ddd-modeling-guide.md +351 -0
  30. package/templates/greenfield/references/dflow-feedback-flow.md +179 -0
  31. package/templates/greenfield/references/drift-verification.md +195 -0
  32. package/templates/greenfield/references/finish-feature-flow.md +280 -0
  33. package/templates/greenfield/references/git-integration.md +285 -0
  34. package/templates/greenfield/references/init-project-flow.md +447 -0
  35. package/templates/greenfield/references/modify-existing-flow.md +362 -0
  36. package/templates/greenfield/references/new-feature-flow.md +397 -0
  37. package/templates/greenfield/references/new-phase-flow.md +273 -0
  38. package/templates/greenfield/references/pr-review-checklist.md +130 -0
  39. package/templates/greenfield/scaffolding/AI-AGENT-GUIDE.md +31 -4
  40. package/templates/greenfield/scaffolding/CLAUDE-md-snippet.md +15 -13
  41. package/templates/greenfield/scaffolding/Git-principles-gitflow.md +1 -1
  42. package/templates/greenfield/scaffolding/Git-principles-trunk.md +1 -1
  43. package/templates/greenfield/scaffolding/_conventions.md +1 -1
  44. package/templates/greenfield/scaffolding/_overview.md +5 -3
  45. package/templates/greenfield/scaffolding/architecture-decisions-README.md +1 -1
  46. package/templates/greenfield/templates/context-map.md +1 -1
  47. package/templates/greenfield/templates/events.md +1 -1
  48. package/templates/greenfield/templates/glossary.md +1 -1
  49. package/templates/greenfield/templates/models.md +1 -1
  50. package/templates/greenfield/templates/rules.md +1 -1
  51. package/templates/greenfield/templates/tech-debt.md +1 -1
@@ -0,0 +1,397 @@
1
+ # New Feature Workflow — Greenfield Clean Architecture
2
+
3
+ Step-by-step guide for adding a new feature with full DDD and Clean Architecture.
4
+
5
+ Triggered by `/dflow:new-feature` (or natural language implying a new-feature task — see SKILL.md § Workflow Transparency for the auto-trigger safety net behavior).
6
+
7
+ **Step Gates** in this flow (stop-and-confirm before proceeding):
8
+ - Step 3 → Step 3.5 (Aggregate / VO / Events identified → confirm slug + directory + branch names)
9
+ - Step 4 → Step 5 (spec written → plan implementation)
10
+ - Step 6 → Step 7 (branch ready → start implementation)
11
+ - Step 7 → Step 8 (implementation done → completion)
12
+
13
+ All other step transitions are **step-internal**: announce "Step N complete, entering Step N+1" and proceed without waiting. See SKILL.md § Workflow Transparency for the full transparency protocol and confirmation signals.
14
+
15
+ **Ceremony**: this flow always defaults to **T1 Heavy** — the first phase of a brand-new feature is by definition a full SDD cycle. Tier judgement (T1 / T2 / T3) only applies to `/dflow:modify-existing` (see `references/modify-existing-flow.md` and SKILL.md § Ceremony Scaling).
16
+
17
+ ## Step 1: Intake — Understand the Request
18
+
19
+ Before producing any spec prose, read `dflow/specs/shared/_conventions.md`
20
+ and apply the `## Prose Language` setting. If the setting is missing or not
21
+ an explicit language tag, ask the developer to update `_conventions.md`
22
+ before continuing.
23
+
24
+ Ask naturally:
25
+ 1. **What's the feature?** Plain-language description.
26
+ 2. **Who needs it?** Stakeholder or user role.
27
+ 3. **Why now?** Priority and urgency.
28
+
29
+ Check existing assets:
30
+ - Search `dflow/specs/domain/` for related concepts
31
+ - Search `dflow/specs/features/` for related features
32
+ - Check `dflow/specs/domain/glossary.md` and `context-map.md`
33
+
34
+ **→ Transition (step-internal)**: Step 1 complete. Announce "Step 1 complete (intake). Entering Step 2: Identify the Bounded Context." and continue.
35
+
36
+ ## Step 2: Identify the Bounded Context
37
+
38
+ Check `dflow/specs/domain/context-map.md`:
39
+
40
+ ```
41
+ "This feature involves [concepts]. It seems to belong in the
42
+ [Context] bounded context. Does that match your understanding?"
43
+ ```
44
+
45
+ If new context needed → use context-definition template.
46
+
47
+ If it crosses contexts:
48
+ ```
49
+ "This touches both [Context A] and [Context B]. We need to decide:
50
+ - Which context OWNS the operation?
51
+ - How does the other context get notified? (Domain Event? Query?)
52
+ - Do we need an Anti-Corruption Layer?"
53
+ ```
54
+
55
+ **→ Transition (step-internal)**: Step 2 complete. Announce "Step 2 complete (BC identified). Entering Step 3: Domain Modeling." and continue.
56
+
57
+ ## Step 3: Domain Modeling
58
+
59
+ This is where the Greenfield Clean Architecture workflow diverges
60
+ significantly from the Brownfield edition.
61
+ Read `references/ddd-modeling-guide.md` for detailed patterns.
62
+
63
+ Walk through:
64
+
65
+ ### Aggregate Identification
66
+ ```
67
+ "What must be consistent in a single transaction?
68
+ Those things form an Aggregate. Everything else is eventually consistent."
69
+ ```
70
+
71
+ - What are the invariants?
72
+ - What is the Aggregate Root?
73
+ - What entities belong inside this Aggregate?
74
+ - What Value Objects can we extract?
75
+
76
+ ### Domain Events
77
+ ```
78
+ "After this happens, what else in the system needs to know?"
79
+ ```
80
+
81
+ - What events does this feature produce?
82
+ - What events does it consume?
83
+ - Are handlers in the same context (synchronous) or cross-context (async)?
84
+
85
+ ### Interface Definitions
86
+ ```
87
+ "What external data does the domain need to make decisions?"
88
+ ```
89
+
90
+ - Repository interfaces for persistence
91
+ - Service interfaces for external systems
92
+ - Define in Domain layer, implement in Infrastructure
93
+
94
+ If foundational domain docs are missing, create them from templates before writing content:
95
+ - `dflow/specs/domain/glossary.md` → `templates/glossary.md`
96
+ - `dflow/specs/domain/{context}/models.md` → `templates/models.md`
97
+ - `dflow/specs/domain/{context}/rules.md` → `templates/rules.md`
98
+ - `dflow/specs/domain/{context}/behavior.md` → `templates/behavior.md` — at this step create only the skeleton + one section anchor per `BR-*`; the Given/When/Then scenarios are merged in later at Step 8.3 (finish-feature), not now
99
+ - `dflow/specs/domain/{context}/events.md` (when Domain Events are involved) → `templates/events.md`
100
+ - `dflow/specs/domain/context-map.md` (when cross-context relationships are involved) → `templates/context-map.md`
101
+
102
+ **→ Step Gate: Step 3 → Step 3.5**
103
+
104
+ Announce to developer:
105
+ > "Aggregate / VO / Events identified. Before I create any files, let me confirm the SPEC-ID, slug, directory name, and branch name with you (Step 3.5). `/dflow:next` to proceed."
106
+
107
+ Wait for confirmation before entering Step 3.5.
108
+
109
+ ## Step 3.5: Slug Confirmation
110
+
111
+ AI proposes the SPEC-ID, slug, feature directory path, and branch name in
112
+ one message and asks the developer to confirm before any directory or
113
+ branch is created. Slug follows the language of the discussion (中文 or
114
+ English — both are valid; see `references/git-integration.md` for the slug
115
+ language rule).
116
+
117
+ Before confirming, surface the path-encoding caveat: a non-ASCII (e.g. 中文)
118
+ slug yields non-ASCII feature-directory and branch paths. These work on common
119
+ Git hosts but a handful of CI runners / toolchains mishandle them. If the
120
+ project's pipeline is unknown, offer an ASCII slug as an alternative. See
121
+ `references/git-integration.md` for the full risk note.
122
+
123
+ Example (中文 discussion):
124
+
125
+ > 「依我們的討論:
126
+ > - SPEC-ID: `SPEC-20260424-001`
127
+ > - slug: `報表調整`(跟隨中文討論)
128
+ > - feature 目錄: `dflow/specs/features/active/SPEC-20260424-001-報表調整/`
129
+ > - git branch: `feature/SPEC-20260424-001-報表調整`
130
+ >
131
+ > 這樣可以嗎?或你想改 slug?」
132
+
133
+ Example (English discussion):
134
+
135
+ > "Per our discussion:
136
+ > - SPEC-ID: `SPEC-20260424-002`
137
+ > - slug: `submit-expense-report` (English following our discussion)
138
+ > - feature directory: `dflow/specs/features/active/SPEC-20260424-002-submit-expense-report/`
139
+ > - git branch: `feature/SPEC-20260424-002-submit-expense-report`
140
+ >
141
+ > Sound good? Or would you prefer a different slug?"
142
+
143
+ Wait for explicit confirmation. The slug agreed here is reused for:
144
+ - The feature directory name
145
+ - The first phase-spec filename (`phase-spec-{date}-{slug}.md`)
146
+ - The git branch (Step 6)
147
+
148
+ If the developer asks to change the slug, re-propose and re-confirm.
149
+
150
+ **→ Transition (step-internal)**: Step 3.5 complete. Announce "Step 3.5 complete (slug confirmed). Entering Step 4: Write the Spec." and continue.
151
+
152
+ ## Step 4: Write the Spec
153
+
154
+ Create the **feature directory** + **`_index.md`** + **first phase-spec**:
155
+
156
+ ```
157
+ dflow/specs/features/active/{SPEC-ID}-{slug}/
158
+ ├── _index.md
159
+ └── phase-spec-{YYYY-MM-DD}-{slug}.md
160
+ ```
161
+
162
+ 1. **Create the directory**: `dflow/specs/features/active/{SPEC-ID}-{slug}/`
163
+ 2. **Create `_index.md`** using `templates/_index.md`:
164
+ - Metadata: fill `spec-id`, `slug`, `status: in-progress`, `created`, `branch`
165
+ - Goals & Scope: 1-3 sentences capturing what / for whom / boundary; mention
166
+ the BC and Aggregate(s) involved
167
+ - Phase Specs: one row for the first phase
168
+ (`| 1 | {date} | {slug} | in-progress | [phase-spec-{date}-{slug}.md](./phase-spec-{date}-{slug}.md) |`)
169
+ - Current BR Snapshot: initialise from the first phase's planned BRs
170
+ (will be refreshed when the phase-spec finalises)
171
+ - Lightweight Changes: empty table at start
172
+ - Resume Pointer: "phase-1 in progress: drafting phase-spec." / "Next Action: finish phase-spec, then implement Domain layer."
173
+ 3. **Create the first phase-spec** at `phase-spec-{YYYY-MM-DD}-{slug}.md`
174
+ using `templates/phase-spec.md`. The "Delta from prior phases" section
175
+ is filled with "首 phase,無前置 Delta" (first phase has nothing to
176
+ delta against).
177
+ 4. **If this feature introduces a new Aggregate**, also create an
178
+ `aggregate-design.md` from `templates/aggregate-design.md` **inside this
179
+ feature directory** as the per-Aggregate design worksheet. It is a working
180
+ artifact scoped to the feature; the Aggregate's durable, long-lived catalog
181
+ entry still lives in `dflow/specs/domain/{context}/models.md`.
182
+ `aggregate-design.md` complements `models.md`, it does not replace it.
183
+
184
+ Key additions compared to Brownfield edition:
185
+ - **Aggregate State Transitions**: Document how Aggregate state changes
186
+ - **Domain Events**: List events produced and expected handlers
187
+ - **CQRS Split**: Identify which parts are Commands (write) vs Queries (read)
188
+
189
+ ### Behavior Specification
190
+ ```gherkin
191
+ Scenario: Submit expense report
192
+ Given an expense report in Draft status with 3 line items totaling 5,000 TWD
193
+ When the employee submits the report
194
+ Then the report status changes to Submitted
195
+ And a ExpenseReportSubmitted event is raised
196
+ And the report can no longer be modified
197
+ ```
198
+
199
+ **→ Step Gate: Step 4 → Step 5**
200
+
201
+ Announce to developer:
202
+ > "Spec is drafted — behavior scenarios, Aggregate state transitions, Domain Events, and CQRS split are captured. Ready to plan the layer-by-layer implementation (Domain → Application → Infrastructure → Presentation)? `/dflow:next` or reply 'OK' to continue, or tell me if the spec needs another iteration first."
203
+
204
+ Wait for confirmation (`/dflow:next`, verbal OK, or implicit — see SKILL.md § Confirmation Signals) before entering Step 5.
205
+
206
+ ## Step 5: Plan the Implementation (Layer by Layer)
207
+
208
+ ### Domain Layer (implement first)
209
+ ```
210
+ 1. Create/update Aggregate Root with state-changing methods
211
+ 2. Create Value Objects with validation in constructors
212
+ 3. Define Domain Events (record types)
213
+ 4. Define Repository interface
214
+ 5. Write Domain unit tests
215
+ ```
216
+
217
+ ### Application Layer (implement second)
218
+ ```
219
+ 1. Create Command + CommandHandler (for writes)
220
+ 2. Create Query + QueryHandler (for reads)
221
+ 3. Create CommandValidator (FluentValidation)
222
+ 4. Create Domain Event handlers (if needed)
223
+ 5. Define DTOs for input/output
224
+ ```
225
+
226
+ ### Infrastructure Layer (implement third)
227
+ ```
228
+ 1. ORM / persistence configuration (mapping configuration, NOT Domain attributes/annotations)
229
+ 2. Repository implementation
230
+ 3. External service adapters
231
+ 4. Migration script
232
+ ```
233
+
234
+ ### Presentation Layer (implement last)
235
+ ```
236
+ 1. API endpoint (Controller or Minimal API)
237
+ 2. Request/Response models
238
+ 3. Swagger documentation
239
+ ```
240
+
241
+ ### Generate Implementation Tasks List
242
+
243
+ After the layer-by-layer plan is agreed, AI generates a concrete task list and writes it into the spec's `Implementation Tasks` section (see `templates/phase-spec.md`). Each task follows `[LAYER]-[NUMBER]:description` and maps to Clean Architecture layers:
244
+
245
+ - `DOMAIN` — Aggregate / Entity / VO / Domain Event / Domain Service / Repository Interface
246
+ - `APP` — Command/Query / Handler / Validator / DTO / Event Handler
247
+ - `INFRA` — EF Configuration / Repository Impl / external adapter / Migration
248
+ - `API` — Controller / Minimal API / Request/Response / Swagger
249
+ - `TEST` — Tests per layer
250
+
251
+ Recommended authoring order mirrors implementation order: `DOMAIN → APP → INFRA → API` (with `TEST` interleaved).
252
+
253
+ Example seed (replace with feature-specific tasks):
254
+
255
+ ```markdown
256
+ - [ ] DOMAIN-1:ExpenseReport aggregate with Submit() state transition
257
+ - [ ] DOMAIN-2:ExpenseReportSubmitted domain event
258
+ - [ ] APP-1:SubmitExpenseReportCommand + Handler
259
+ - [ ] INFRA-1:EF config + ExpenseReportRepository
260
+ - [ ] API-1:POST /expense-reports/{id}/submit endpoint
261
+ - [ ] TEST-1:Aggregate invariants + handler unit tests
262
+ ```
263
+
264
+ The list becomes the execution punch-list for Step 7 and the completion checklist in Step 8.
265
+
266
+ **→ Transition (step-internal)**: Step 5 complete. Announce "Step 5 complete (layer-by-layer plan + task list ready). Entering Step 6: Git Branch." and continue.
267
+
268
+ ## Step 6: Git Branch
269
+
270
+ ```
271
+ Branch naming: feature/{SPEC-ID}-{slug}
272
+ Examples:
273
+ feature/SPEC-20260424-002-submit-expense-report (English slug)
274
+ feature/SPEC-20260424-001-報表調整 (Chinese slug)
275
+ ```
276
+
277
+ The slug **must match the slug agreed in Step 3.5** (which is also the
278
+ feature directory name). The SPEC-ID + slug links the branch to its
279
+ feature directory and `_index.md`.
280
+
281
+ **→ Step Gate: Step 6 → Step 7**
282
+
283
+ Announce to developer:
284
+ > "Branch `feature/{SPEC-ID}-{description}` is created. Ready to start layer-by-layer implementation (Domain first)? `/dflow:next` to proceed, or discuss layer order / scope first."
285
+
286
+ Wait for confirmation before entering Step 7.
287
+
288
+ ## Step 7: Implementation Checklist
289
+
290
+ During implementation, continuously verify:
291
+
292
+ **Domain Layer**
293
+ - [ ] Aggregate protects all invariants
294
+ - [ ] State changes only through methods (no public setters)
295
+ - [ ] Value Objects are immutable with validation
296
+ - [ ] Domain Events raised for significant state changes
297
+ - [ ] Zero external dependencies (check the Domain package/module manifest)
298
+ - [ ] Unit tests cover invariants and business rules
299
+
300
+ **Application Layer**
301
+ - [ ] No business logic in handlers (only orchestration)
302
+ - [ ] Command/Query separation maintained
303
+ - [ ] Validation in Validator, not Handler
304
+ - [ ] DTOs map to/from Domain objects (no Domain objects in API)
305
+
306
+ **Infrastructure Layer**
307
+ - [ ] EF Config in Fluent API (no attributes on Domain entities)
308
+ - [ ] Repository implements Domain interface correctly
309
+ - [ ] No business logic in queries
310
+
311
+ **Presentation Layer**
312
+ - [ ] Controller is thin (parse → dispatch → respond)
313
+ - [ ] No domain objects exposed to API consumers
314
+ - [ ] Proper HTTP status codes
315
+
316
+ **→ Step Gate: Step 7 → Step 8**
317
+
318
+ Announce to developer:
319
+ > "Implementation appears complete across all four layers. Ready to run the completion checklist (verify against spec, update domain docs + context-map, ensure test coverage, archive the spec)? `/dflow:next` to proceed."
320
+
321
+ Wait for confirmation before entering Step 8. This step gate is where the completion checklist is triggered — do not skip.
322
+
323
+ ## Step 8: Completion
324
+
325
+ Triggered by the Step 7 → Step 8 Step Gate. AI runs the completion checklist in the order below; do **not** skip a section.
326
+
327
+ ### 8.1 Verification — AI runs independently
328
+
329
+ AI reports `✓` / `✗` for every item before touching docs. Items marked *(post-8.3)* are re-verified after the documentation merge in 8.3 lands:
330
+
331
+ - [ ] `Implementation Tasks` section: all tasks checked, or unchecked items explicitly labelled as follow-up (linked to spec / tech-debt entry)
332
+ - [ ] Every `Given/When/Then` scenario in the spec is covered by implementation or tests
333
+ - [ ] Every `BR-*` business rule is covered by implementation or tests
334
+ - [ ] Every `EC-*` edge case is handled
335
+ - [ ] Every Domain Event listed in the spec is raised in the implementation
336
+ - [ ] Domain layer/package has **no** external package-manager dependencies beyond the language/runtime baseline
337
+ - [ ] Aggregate invariants still hold after the change (all state changes go through methods, no public setters)
338
+ - [ ] ORM / persistence mapping is kept outside Domain entities (no persistence attributes/annotations on Domain entities)
339
+ - [ ] *(post-8.3)* `dflow/specs/domain/{context}/behavior.md` contains a section anchor for every `BR-*` introduced by this spec (mechanical input for `/dflow:verify`)
340
+ - [ ] *(post-8.3)* `dflow/specs/domain/{context}/behavior.md` `last-updated` is later than this spec's `created` date (mechanical drift guard)
341
+
342
+ If any item fails, report the gap and pause — don't proceed to 8.2.
343
+
344
+ ### 8.2 Verification — needs developer confirmation
345
+
346
+ AI lists findings one at a time and waits for the developer to confirm each:
347
+
348
+ - [ ] Does the implementation faithfully express the **intent** of each BR? (AI lists BR → impl location; developer judges fit)
349
+ - [ ] Are the edge case handling decisions appropriate? (AI lists EC → handling; developer judges)
350
+ - [ ] Are Domain Event payloads and handler placements (same-context sync vs cross-context async) correct? (AI lists; developer confirms)
351
+ - [ ] Did we miss any tech debt worth recording?
352
+ - [ ] Do the scenarios merged into `behavior.md` (incl. Aggregate transitions + Events) faithfully express the intended behavior? (AI lists merged anchors; developer judges)
353
+ - [ ] Should the `Implementation Tasks` section in the spec be collapsed / removed now that it's complete? (team convention — developer decides)
354
+
355
+ Ask these one-by-one; do not dump all six at once.
356
+
357
+ ### 8.3 Documentation updates
358
+
359
+ - [ ] `dflow/specs/domain/glossary.md` — new terms added
360
+ - [ ] `dflow/specs/domain/{context}/models.md` — model definitions updated
361
+ - [ ] `dflow/specs/domain/{context}/rules.md` — business rules updated
362
+ - [ ] `dflow/specs/domain/{context}/behavior.md` — merge completed spec's Given/When/Then scenarios (incl. Aggregate transitions + Events) into consolidated behavior. Sub-steps:
363
+ - Promote any Activity 3 (Spec Writing) draft sections (from B3 mid-sync) to formal sections
364
+ - Update the corresponding `rules.md` anchor's `last-updated` date (B4)
365
+ - [ ] `behavior.md` draft cleanup — if the spec was abandoned mid-way, keep the `## 提案中變更` section's history or explicitly REMOVE it
366
+ - [ ] `dflow/specs/domain/{context}/events.md` — Domain Events updated
367
+ - [ ] `dflow/specs/domain/context-map.md` — updated if cross-context interaction was added or changed
368
+ - [ ] `dflow/specs/architecture/tech-debt.md` — tech debt discovered during implementation recorded
369
+
370
+ ### 8.4 Archival
371
+
372
+ For a single-phase feature, this is the closeout point. For a multi-phase
373
+ feature, the developer typically reaches this point at the end of the
374
+ final phase — at which time `/dflow:finish-feature` is the recommended
375
+ trigger (it bundles steps 8.1 / 8.2 verification, BC sync, and archival
376
+ into one explicit ceremony). Either path is acceptable; pick the one
377
+ that matches the developer's habit.
378
+
379
+ - [ ] `_index.md` `status` field changed to `completed`
380
+ - [ ] All `phase-spec-*.md` files in the feature directory have `status:
381
+ completed` in their frontmatter
382
+ - [ ] **Whole feature directory** moved from `dflow/specs/features/active/`
383
+ to `dflow/specs/features/completed/` using `git mv` (preserves rename
384
+ tracking — see `references/git-integration.md` § "Directory Moves
385
+ Must Use git mv"):
386
+ ```
387
+ git mv dflow/specs/features/active/{SPEC-ID}-{slug} \
388
+ dflow/specs/features/completed/{SPEC-ID}-{slug}
389
+ ```
390
+
391
+ > **Recommended path for multi-phase features**: instead of doing
392
+ > 8.1–8.4 manually at the end of every phase, run `/dflow:finish-feature`
393
+ > once the feature's last phase is complete. It executes the same checks
394
+ > + BC sync + `git mv` + emits an Integration Summary. See
395
+ > `references/finish-feature-flow.md`.
396
+
397
+ Only announce "feature complete" after 8.4 is done.
@@ -0,0 +1,273 @@
1
+ # New Phase Workflow — Greenfield Clean Architecture
2
+
3
+ Step-by-step guide for when a developer triggers `/dflow:new-phase` —
4
+ adding a new phase-spec to an **active** feature directory.
5
+
6
+ A phase-spec captures one full "Kickoff → Domain → Design → Build → Verify"
7
+ cycle. A feature can have N phase-specs over its lifetime; together they
8
+ build up the feature in iterations. The `_index.md` dashboard aggregates
9
+ their state.
10
+
11
+ **Distinction from `/dflow:new-feature`**: this command does NOT create a
12
+ branch and does NOT create a feature directory. Both must already exist
13
+ (produced by the original `/dflow:new-feature` invocation). This command
14
+ adds a new phase to an in-progress feature only.
15
+
16
+ **Step Gates** in this flow (stop-and-confirm before proceeding):
17
+ - Step 3 → Step 4 (phase scope confirmed → write the phase-spec)
18
+ - Step 4 → Step 5 (phase-spec drafted → refresh `_index.md`)
19
+ - Step 5 → Step 6 (`_index.md` refreshed → start implementation)
20
+ - Step 6 → Step 7 (implementation done → complete the phase)
21
+
22
+ All other step transitions are **step-internal**: announce "Step N complete,
23
+ entering Step N+1" and proceed without waiting. See SKILL.md § Workflow
24
+ Transparency for the full transparency protocol and confirmation signals.
25
+
26
+ ## Step 1: Read Active Feature Context
27
+
28
+ Before producing any spec prose, read `dflow/specs/shared/_conventions.md`
29
+ and apply the `## Prose Language` setting. If the setting is missing or not
30
+ an explicit language tag, ask the developer to update `_conventions.md`
31
+ before continuing.
32
+
33
+ AI must locate the target feature and load its current state:
34
+
35
+ 1. **Identify the target feature**
36
+ - If the developer is on a `feature/{SPEC-ID}-{slug}` branch → infer the
37
+ feature directory at `dflow/specs/features/active/{SPEC-ID}-{slug}/`
38
+ - Otherwise → ask the developer which feature this phase is for
39
+
40
+ 2. **Refuse if the feature is in `completed/`**
41
+
42
+ `/dflow:new-phase` strictly applies to **active features only**. If the
43
+ target feature directory is found at `dflow/specs/features/completed/...`
44
+ instead of `dflow/specs/features/active/...`, refuse with:
45
+
46
+ ```
47
+ "Feature `{SPEC-ID}-{slug}` is in completed/ — completed features are
48
+ frozen history and cannot accept new phases.
49
+
50
+ If you need to extend this feature's behavior, run /dflow:modify-existing
51
+ and choose the 'follow-up' branch — that creates a new follow-up feature
52
+ with a fresh SPEC-ID and a `follow-up-of: {SPEC-ID}` link back to this
53
+ one."
54
+ ```
55
+
56
+ Do NOT offer to `git mv` the feature back to `active/` — that breaks the
57
+ completed = frozen-history semantic and produces confusing dir-rename
58
+ history. The follow-up path is the only correct route.
59
+
60
+ 3. **Load context for the new phase**
61
+ - Read the feature's `_index.md` — Metadata, Goals & Scope, Phase Specs,
62
+ Current BR Snapshot, Resume Pointer
63
+ - Read the most recent phase-spec to understand where the prior phase
64
+ left off (its Business Rules and Delta-from-prior-phases sections in
65
+ particular)
66
+ - Cross-reference the bounded context's `dflow/specs/domain/{context}/rules.md`
67
+ and `behavior.md` if the new phase is likely to touch system-level
68
+ state (BC-level current state lives there, not in `_index.md`)
69
+
70
+ Share what you found:
71
+
72
+ > "OK — `{SPEC-ID}-{slug}` has {N} prior phases in BC `{context}`. The
73
+ > most recent (phase-{N}) ended with {一句話 from Resume Pointer}. Current BR
74
+ > Snapshot has {count} active BRs. Ready to scope the new phase."
75
+
76
+ **→ Transition (step-internal)**: Step 1 complete. Announce "Step 1 complete (active feature context loaded). Entering Step 2: Confirm Phase Scope." and continue.
77
+
78
+ ## Step 2: Confirm the Phase Scope
79
+
80
+ Walk the developer through what the new phase covers:
81
+
82
+ 1. **What does this phase add or change?** Plain-language description.
83
+ 2. **Which BRs are touched?** Compare against the current BR Snapshot. New
84
+ BRs (ADDED), changed BRs (MODIFIED), removed BRs (REMOVED), renamed
85
+ (RENAMED). Items not mentioned stay UNCHANGED implicitly.
86
+ 3. **Any Aggregate / Domain concepts introduced or changed?** New
87
+ Aggregates, Value Objects, Domain Events, or invariants?
88
+ 4. **Cross-context impact?** Does this phase introduce / change Domain
89
+ Events that other contexts consume? (If yes, plan for `context-map.md`
90
+ updates at finish-feature time.)
91
+ 5. **Data structure impact?** New tables, columns, indices, EF
92
+ configuration changes?
93
+ 6. **Why now?** Priority — informs sequencing relative to other phases.
94
+
95
+ This is also the moment to ask: "Should this be its own follow-up feature
96
+ instead of a phase here?" — useful when the scope drift suggests a
97
+ separate concern (different Aggregate, different BC, etc.).
98
+
99
+ **→ Transition (step-internal)**: Step 2 complete. Announce "Step 2 complete (phase scope agreed). Entering Step 3: Phase Slug Confirmation." and continue.
100
+
101
+ ## Step 3: Phase Slug Confirmation
102
+
103
+ AI proposes the new phase-spec filename and asks the developer to confirm
104
+ before any file is written.
105
+
106
+ > "Proposed phase-spec for `{SPEC-ID}-{slug}`:
107
+ >
108
+ > phase-spec-{YYYY-MM-DD}-{phase-slug}.md
109
+ >
110
+ > Phase slug follows our discussion language (中文/英文皆可). Do you want
111
+ > to keep `{phase-slug}`, or use a different slug?"
112
+
113
+ Slug rules (matches the feature-level slug rule):
114
+ - Follows the language the developer / AI discuss the phase in (no forced
115
+ translation)
116
+ - Keep it short (2–4 words / 2–6 中文字)
117
+ - Avoid characters that would break filesystems on the developer's
118
+ platform (slashes, colons, etc.)
119
+
120
+ Wait for the developer to confirm before proceeding.
121
+
122
+ **→ Step Gate: Step 3 → Step 4**
123
+
124
+ Announce to developer:
125
+ > "Phase slug confirmed as `{phase-slug}`. Ready to draft the phase-spec
126
+ > (`phase-spec-{date}-{phase-slug}.md`) — I'll cover problem / domain
127
+ > modeling / behavior (with Aggregate transitions + Events) / business
128
+ > rules / Delta-from-prior-phases / edge cases / layer-by-layer
129
+ > implementation plan? `/dflow:next` to proceed, or adjust the scope
130
+ > first."
131
+
132
+ Wait for confirmation before entering Step 4.
133
+
134
+ ## Step 4: Write the Phase Spec
135
+
136
+ Create the file at:
137
+
138
+ ```
139
+ dflow/specs/features/active/{SPEC-ID}-{slug}/phase-spec-{YYYY-MM-DD}-{phase-slug}.md
140
+ ```
141
+
142
+ Use the `templates/phase-spec.md` template and set the phase-spec
143
+ frontmatter `status` to `in-progress`. Phase-2-onward specs **must** fill
144
+ in the **Delta from prior phases** section (the first phase typically has
145
+ just "首 phase,無前置 Delta"; this is phase 2+, so the section is required).
146
+
147
+ Walk the developer through each section, in the same way `new-feature-flow`
148
+ Step 4 does — Behavior (with Aggregate state transitions and Domain
149
+ Events) / Business Rules / Delta / Edge Cases / Domain Events / layer-by-
150
+ layer implementation plan — but only list NEW or MODIFIED BRs in Business Rules;
151
+ UNCHANGED BRs from prior phases stay in the Current BR Snapshot table on
152
+ `_index.md` and are NOT re-copied here. The Delta section uses the same
153
+ ADDED / MODIFIED / REMOVED / RENAMED + optional UNCHANGED format defined
154
+ in `references/modify-existing-flow.md` (Aggregate state transitions and
155
+ Domain Events go in the Given/When/Then within each Delta entry).
156
+
157
+ After the spec body is drafted, generate the `Implementation Tasks` section
158
+ (format `[LAYER]-[NUMBER]:description` with Core layer tags
159
+ DOMAIN / APP / INFRA / API / TEST — see `new-feature-flow.md` Step 5 for
160
+ the detailed list, recommended order: DOMAIN → APP → INFRA → API).
161
+
162
+ **→ Step Gate: Step 4 → Step 5**
163
+
164
+ Announce to developer:
165
+ > "Phase-spec drafted at
166
+ > `dflow/specs/features/active/{SPEC-ID}-{slug}/phase-spec-{date}-{phase-slug}.md`.
167
+ > Ready to refresh `_index.md` (add Phase Specs row, regenerate Current BR
168
+ > Snapshot from the Delta)? `/dflow:next` to proceed."
169
+
170
+ Wait for confirmation before entering Step 5.
171
+
172
+ ## Step 5: Refresh `_index.md`
173
+
174
+ Update the feature's `_index.md`:
175
+
176
+ 1. **Phase Specs table** — add a new row for this phase:
177
+ ```
178
+ | {N+1} | {YYYY-MM-DD} | {phase-slug} | in-progress | [phase-spec-{date}-{phase-slug}.md](./phase-spec-{date}-{phase-slug}.md) |
179
+ ```
180
+
181
+ 2. **Current BR Snapshot table** — regenerate to reflect the new phase's
182
+ Delta:
183
+ - **ADDED** entries → new rows (First Seen = `phase-{N+1}`, Last Updated =
184
+ `phase-{N+1}`, Status = `active`)
185
+ - **MODIFIED** entries → update Current Rule + bump Last Updated to `phase-{N+1}`
186
+ - **REMOVED** entries → flip Status to `removed`, bump Last Updated to
187
+ `phase-{N+1}` (do NOT delete the row — keep the audit trail)
188
+ - **RENAMED** entries → update BR-ID / Current Rule as appropriate; bump
189
+ Last Updated
190
+
191
+ 3. **Resume Pointer** — update to "phase-{N+1} in progress:
192
+ {one-line about what's actively being worked on}" and "Next Action:
193
+ implement DOMAIN-1 / write Aggregate ... / etc."
194
+
195
+ The Snapshot is the feature-level CURRENT STATE, not history. Do not let
196
+ it grow into a cumulative log; the per-phase Delta sections are the
197
+ historical audit trail. The bounded context's `rules.md` / `behavior.md`
198
+ remain the system-level current state and are NOT updated here — that
199
+ synchronisation happens at `/dflow:finish-feature`.
200
+
201
+ After the refresh, summarize for the developer:
202
+ > "Phase-spec ready, `_index.md` refreshed. Snapshot now shows
203
+ > {n_active} active BRs ({n_added} added in this phase, {n_modified}
204
+ > modified, {n_removed} removed). Ready to enter Step 6 —
205
+ > follow the phase-spec's Implementation Tasks list (DOMAIN → APP → INFRA → API)?
206
+ > `/dflow:next` to proceed, or adjust the plan first."
207
+
208
+ **→ Step Gate: Step 5 → Step 6**
209
+
210
+ Wait for confirmation before entering Step 6.
211
+
212
+ ## Step 6: Implement and Verify the Phase
213
+
214
+ Follow the phase-spec's `Implementation Tasks` in the recommended layer order:
215
+ DOMAIN → APP → INFRA → API, with TEST tasks interleaved where they prove the
216
+ layer behavior.
217
+
218
+ During implementation, continuously verify:
219
+
220
+ - [ ] `Implementation Tasks` are checked off as they complete, or unchecked
221
+ items are explicitly labelled as follow-up
222
+ - [ ] Every ADDED / MODIFIED / REMOVED / RENAMED Delta entry is covered by
223
+ implementation or tests
224
+ - [ ] Every affected `BR-*` business rule is covered by implementation or tests
225
+ - [ ] Every affected Given/When/Then scenario is covered by implementation or tests
226
+ - [ ] New or changed Domain Events are raised in the implementation
227
+ - [ ] Aggregate invariants still hold after the change
228
+ - [ ] Domain layer remains framework-pure; EF configuration stays in Infrastructure
229
+ - [ ] No business logic leaks into Application handlers, Infrastructure queries,
230
+ or Presentation controllers
231
+ - [ ] Test failures have been resolved or explicitly recorded as follow-up
232
+
233
+ If implementation changes the agreed Delta, update the phase-spec before
234
+ continuing. Do not let code and spec diverge silently.
235
+
236
+ **→ Step Gate: Step 6 → Step 7**
237
+
238
+ Announce to developer:
239
+ > "Phase implementation appears complete and verified against the phase-spec.
240
+ > Ready to mark this phase completed and update `_index.md`? `/dflow:next`
241
+ > to proceed."
242
+
243
+ Wait for confirmation before entering Step 7.
244
+
245
+ ## Step 7: Complete the Phase
246
+
247
+ Update the feature artifacts:
248
+
249
+ 1. **Phase spec status** — change this phase-spec's frontmatter `status`
250
+ from `in-progress` to `completed`.
251
+ 2. **Implementation Tasks** — keep completed tasks checked. If any task is not
252
+ done, mark it explicitly as follow-up and link to the relevant future
253
+ phase, issue, or tech-debt entry.
254
+ 3. **Phase Specs table** — update this phase's `_index.md` row from
255
+ `in-progress` to `completed`.
256
+ 4. **Current BR Snapshot** — reconcile the snapshot against the implemented
257
+ Delta. If implementation changed the Delta, update the phase-spec first,
258
+ then regenerate the snapshot.
259
+ 5. **Resume Pointer** — update to one of:
260
+ - "phase-{N+1} completed; next action: run `/dflow:new-phase` for the next
261
+ slice"
262
+ - "phase-{N+1} completed; next action: run `/dflow:finish-feature` if the
263
+ feature is ready to wrap up"
264
+
265
+ The bounded context's `rules.md` / `behavior.md` / `events.md` and the
266
+ feature directory move to `completed/` remain `/dflow:finish-feature`
267
+ responsibilities. Do not sync BC-level current state or archive the whole
268
+ feature from `/dflow:new-phase`.
269
+
270
+ After completion, summarize for the developer:
271
+ > "Phase {N+1} is implemented and marked completed. `_index.md` is refreshed.
272
+ > If another slice is needed, run `/dflow:new-phase`; if the feature is done,
273
+ > run `/dflow:finish-feature`."