dflow-sdd-ddd 0.7.0 → 0.9.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 (59) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/LICENSE +679 -21
  3. package/README.en.md +5 -4
  4. package/README.md +3 -3
  5. package/bin/dflow.js +3 -2
  6. package/docs/evaluating-dflow.en.md +14 -5
  7. package/docs/evaluating-dflow.md +14 -5
  8. package/docs/using-with-claude-code.en.md +17 -9
  9. package/docs/using-with-claude-code.md +15 -8
  10. package/docs/using-with-codex.en.md +12 -8
  11. package/docs/using-with-codex.md +8 -6
  12. package/lib/init.js +480 -87
  13. package/package.json +2 -2
  14. package/templates/brownfield/references/dflow-feedback-flow.md +251 -0
  15. package/templates/brownfield/references/drift-verification.md +183 -0
  16. package/templates/brownfield/references/finish-feature-flow.md +294 -0
  17. package/templates/brownfield/references/git-integration.md +371 -0
  18. package/templates/brownfield/references/init-project-flow.md +430 -0
  19. package/templates/brownfield/references/modify-existing-flow.md +448 -0
  20. package/templates/brownfield/references/new-feature-flow.md +382 -0
  21. package/templates/brownfield/references/new-phase-flow.md +274 -0
  22. package/templates/brownfield/references/pr-review-checklist.md +179 -0
  23. package/templates/brownfield/scaffolding/AI-AGENT-GUIDE.md +31 -4
  24. package/templates/brownfield/scaffolding/CLAUDE-md-snippet.md +12 -8
  25. package/templates/brownfield/scaffolding/Git-principles-gitflow.md +14 -13
  26. package/templates/brownfield/scaffolding/Git-principles-trunk.md +14 -17
  27. package/templates/brownfield/scaffolding/_conventions.md +1 -1
  28. package/templates/brownfield/scaffolding/_overview.md +3 -3
  29. package/templates/brownfield/templates/_index.md +20 -2
  30. package/templates/brownfield/templates/context-map.md +1 -1
  31. package/templates/brownfield/templates/glossary.md +1 -1
  32. package/templates/brownfield/templates/models.md +1 -1
  33. package/templates/brownfield/templates/rules.md +1 -1
  34. package/templates/brownfield/templates/tech-debt.md +1 -1
  35. package/templates/common/skill/SKILL.md +35 -0
  36. package/templates/greenfield/references/ddd-modeling-guide.md +351 -0
  37. package/templates/greenfield/references/dflow-feedback-flow.md +251 -0
  38. package/templates/greenfield/references/drift-verification.md +195 -0
  39. package/templates/greenfield/references/finish-feature-flow.md +314 -0
  40. package/templates/greenfield/references/git-integration.md +344 -0
  41. package/templates/greenfield/references/init-project-flow.md +464 -0
  42. package/templates/greenfield/references/modify-existing-flow.md +366 -0
  43. package/templates/greenfield/references/new-feature-flow.md +412 -0
  44. package/templates/greenfield/references/new-phase-flow.md +288 -0
  45. package/templates/greenfield/references/pr-review-checklist.md +130 -0
  46. package/templates/greenfield/scaffolding/AI-AGENT-GUIDE.md +31 -4
  47. package/templates/greenfield/scaffolding/CLAUDE-md-snippet.md +15 -13
  48. package/templates/greenfield/scaffolding/Git-principles-gitflow.md +14 -13
  49. package/templates/greenfield/scaffolding/Git-principles-trunk.md +14 -18
  50. package/templates/greenfield/scaffolding/_conventions.md +1 -1
  51. package/templates/greenfield/scaffolding/_overview.md +5 -3
  52. package/templates/greenfield/scaffolding/architecture-decisions-README.md +1 -1
  53. package/templates/greenfield/templates/_index.md +20 -2
  54. package/templates/greenfield/templates/context-map.md +1 -1
  55. package/templates/greenfield/templates/events.md +1 -1
  56. package/templates/greenfield/templates/glossary.md +1 -1
  57. package/templates/greenfield/templates/models.md +1 -1
  58. package/templates/greenfield/templates/rules.md +1 -1
  59. package/templates/greenfield/templates/tech-debt.md +1 -1
@@ -0,0 +1,430 @@
1
+ # Init Project Flow — Brownfield Track
2
+
3
+ Internal flow spec for `npx dflow-sdd-ddd init` after the CLI selects the
4
+ Brownfield track. It also serves as the manual reference for environments
5
+ where Node.js/npm is unavailable.
6
+
7
+ This is not a skill slash command. Do not describe or invoke it as one.
8
+
9
+ This is a **one-time project bootstrap** flow. It sets up the `dflow/specs/`
10
+ directory structure, seeds project-level governance files from the packaged
11
+ `scaffolding/` template set, and points the developer at `/dflow:new-feature`
12
+ as the natural next command.
13
+
14
+ The V1 CLI clean cut does not migrate or dual-read a legacy root `specs/`
15
+ directory. If root `specs/` exists, warn that new Dflow files will be created
16
+ under `dflow/specs/`.
17
+
18
+ **Confirmations** in this flow:
19
+ - Step 2 → Step 3: information collected → present file-list preview
20
+ - Step 3 → Step 4: file-list confirmed → write
21
+
22
+ In the CLI, use ordinary yes/no confirmation. In the manual AI fallback,
23
+ ask for explicit confirmation in natural language; do not require
24
+ the workflow next command for init.
25
+
26
+ **Ceremony**: this flow is **meta-level** — it sets up the infrastructure
27
+ that subsequent T1 / T2 / T3 work will live in. It does not itself produce
28
+ a SPEC-ID, feature directory, or branch. It does not count against Ceremony
29
+ Scaling.
30
+
31
+ ---
32
+
33
+ ## Step 1: Current-State Inventory
34
+
35
+ The CLI inspects the project root before prompting.
36
+
37
+ **Read** (using the Read / Glob / LS tools):
38
+ - Is there a `.git` directory? → repo exists
39
+ - Is there an existing non-empty `dflow/specs/` directory? → Dflow already initialized; abort
40
+ - Is there an empty `dflow/specs/` directory? → continue with existing-file protection
41
+ - Is there an existing root `specs/` directory? → legacy / other-tool warning only; do not read, copy, move, or rewrite it
42
+ - Is there an existing `CLAUDE.md` at the repo root? → project already
43
+ has AI-collab rules
44
+
45
+ Report findings plainly:
46
+
47
+ > "Repo inventory:
48
+ > - `.git`: present
49
+ > - `dflow/specs/`: not yet present → greenfield Dflow setup
50
+ > - `specs/`: present → legacy / other-tool directory; Dflow V1 will not
51
+ > migrate or modify it
52
+ > - `CLAUDE.md`: present → will not overwrite; I'll offer a snippet
53
+ > to merge into it"
54
+
55
+ Or:
56
+
57
+ > "Repo inventory:
58
+ > - `dflow/specs/`: already contains files
59
+ > - `CLAUDE.md`: not present
60
+ >
61
+ > Dflow already appears initialized here. I will stop rather than risk
62
+ > mixing bootstrap versions."
63
+
64
+ Classify the scenario:
65
+ - **Greenfield**: no `dflow/specs/` at all → create full baseline
66
+ - **Empty Dflow namespace**: `dflow/specs/` exists but contains no files → continue
67
+ - **Already initialized**: non-empty `dflow/specs/` exists → abort cleanly
68
+
69
+ **→ Transition (step-internal)**: Step 1 complete. Announce
70
+ > "Step 1 complete (current-state inventory). Entering Step 2: Project
71
+ > Information."
72
+
73
+ and continue.
74
+
75
+ ---
76
+
77
+ ## Step 2: Project Information (track-specific intake)
78
+
79
+ Ask these questions naturally — not as a checklist dump. Skip any
80
+ question where Step 1 already gave a confident answer.
81
+
82
+ ### Q1. Project type
83
+
84
+ > "Is this project greenfield (fresh start with Dflow) or brownfield
85
+ > (existing code, now adopting Dflow)?"
86
+
87
+ Used to seed `_overview.md`'s "現有問題" section (brownfield typically
88
+ has backlog issues to document).
89
+
90
+ ### Q2. Tech stack confirmation
91
+
92
+ > "Confirm the tech stack so I populate the right scaffolding
93
+ > variables: current presentation framework or entrypoint stack?
94
+ > language? database / ORM / persistence approach?"
95
+
96
+ Used to substitute `{Framework}` / `{Framework version}` / `{Language}` /
97
+ `{ORM / persistence}` / `{ORM version}` placeholders in `_overview.md`.
98
+
99
+ ### Q3. Migration plan
100
+
101
+ > "Is there an existing plan to migrate this Brownfield project to
102
+ > a target architecture?"
103
+
104
+ If yes → `_overview.md` "Target Architecture Strategy" section is emphasised and
105
+ `migration/tech-debt.md` is prioritised. If no → the scaffolding still
106
+ mentions the principles (Migration Awareness / Domain Extraction /
107
+ Dual-Track Parallel / Pragmatic First) but framed as forward-option.
108
+
109
+ ### Q4. Project prose language
110
+
111
+ > "Project prose language for generated spec content? Choose an explicit
112
+ > language tag: `zh-TW`, `en`, `ja-JP`, or another BCP-47 tag."
113
+
114
+ Used to write `dflow/specs/shared/_conventions.md` under `## Prose
115
+ Language`. This value is required. Do not accept `any`, `skip`, `later`,
116
+ blank input, or prose descriptions such as "Traditional Chinese". Dflow
117
+ templates keep canonical English structural language; this setting controls
118
+ free prose inside generated spec sections.
119
+
120
+ ### Q5. Git policy (mandatory — pick one)
121
+
122
+ > "Which Git policy does the team follow? This drives the runtime branch gate
123
+ > and the finish-stage merge guidance, so it is required:
124
+ >
125
+ > 1. GitFlow — long-lived develop / release branches
126
+ > 2. Trunk / GitHub Flow — short-lived feature branches (lightest; the
127
+ > default for most GitHub / GitLab teams)"
128
+
129
+ Required — do not accept a skip. Both policies use feature branches; the choice
130
+ only changes finish-stage merge guidance. The selected policy seeds exactly one
131
+ `dflow/specs/shared/Git-principles-{gitflow|trunk}.md` (**mandatory, not
132
+ optional**) and is recorded in `_conventions.md` under `## Git Policy`.
133
+
134
+ ### Q6. AI commit marker (mandatory — default None)
135
+
136
+ > "How should AI-made commits be marked? The AI offers to commit at lifecycle
137
+ > checkpoints (you can always decline); this sets how those commits are tagged:
138
+ >
139
+ > 1. None (default) — AI commits look like any other commit
140
+ > 2. Co-Authored-By trailer (`dflow-ai <noreply@dflow.local>`) — filterable
141
+ > 3. `[ai-assisted]` commit-subject prefix — visible at a glance"
142
+
143
+ Recorded in `_conventions.md` under `## AI Commit Policy`; the runtime does not
144
+ re-ask.
145
+
146
+ ### Q7. Optional starter files (multi-select)
147
+
148
+ > "Besides the mandatory baseline, which optional starter files do you want me
149
+ > to seed?
150
+ >
151
+ > - [ ] `dflow/specs/shared/_overview.md` — system overview template"
152
+
153
+ Wait for answers.
154
+
155
+ ### Q8. AI coding agents (multi-select)
156
+
157
+ > "Which AI coding agents should Dflow configure?
158
+ >
159
+ > - [ ] `AGENTS.md` — Codex / Copilot coding agent
160
+ > - [ ] `CLAUDE.md` — Claude Code
161
+ > - [ ] `.github/copilot-instructions.md` — GitHub Copilot
162
+ >
163
+ > If you select any agent, Dflow will create
164
+ > `dflow/specs/shared/AI-AGENT-GUIDE.md` as the canonical guide. Root-level
165
+ > tool files stay thin and point back to that guide. Existing tool files are
166
+ > never overwritten; Dflow writes merge snippets under `dflow/specs/shared/`
167
+ > instead."
168
+
169
+ **→ Transition (step-internal)**: Step 2 complete. Announce
170
+ > "Step 2 complete (project information captured). Entering Step 3:
171
+ > File-list preview."
172
+
173
+ and continue.
174
+
175
+ ---
176
+
177
+ ## Step 3: File-list Preview
178
+
179
+ Compute the full list of files that will be created / skipped, based on
180
+ Step 1 (current state) + Step 2 (developer choices).
181
+
182
+ ### 3.1 Mandatory baseline (Brownfield track)
183
+
184
+ These files / directories are **always part of the baseline** — they
185
+ are what every Dflow-adopting Brownfield project is expected to have
186
+ before `/dflow:new-feature` runs cleanly:
187
+
188
+ ```
189
+ dflow/specs/
190
+ ├── features/
191
+ │ ├── active/ # directory (empty)
192
+ │ ├── completed/ # directory (empty)
193
+ │ └── backlog/ # directory (empty)
194
+ ├── domain/
195
+ │ └── glossary.md # ← templates/glossary.md
196
+ ├── shared/
197
+ │ └── _conventions.md # ← scaffolding/_conventions.md (mandatory)
198
+ └── migration/
199
+ └── tech-debt.md # ← templates/tech-debt.md
200
+ ```
201
+
202
+ Key Brownfield-track notes:
203
+ - `dflow/specs/migration/tech-debt.md` (not `dflow/specs/architecture/tech-debt.md`)
204
+ — Brownfield projects use `migration/` as the cross-cutting directory
205
+ for migration-era concerns. The Greenfield track uses `architecture/`
206
+ instead; this split is an F-05 decision from R7 review.
207
+ - **`behavior.md` is NOT generated here.** Per F-05, per-context
208
+ `behavior.md` files are created by `/dflow:new-feature` Step 8.3
209
+ (completion flow) or by the P007a baseline-capture flow at the moment
210
+ the first bounded context is established. Creating empty
211
+ `behavior.md` files here would create stale placeholders.
212
+ - `domain/context-map.md` is **not** mandatory in the Brownfield track
213
+ (contexts emerge organically during domain extraction; the Greenfield
214
+ track makes this file mandatory because BCs are usually planned
215
+ up-front).
216
+
217
+ ### 3.2 Optional files (from Step 2 Q7)
218
+
219
+ Use the packaged scaffolding templates listed below; their project-local
220
+ outputs are under `dflow/specs/shared/` (the scaffolding root, not the
221
+ vendored workflow bundle). Compute the destination path:
222
+
223
+ | Scaffolding source | Destination in project |
224
+ |---|---|
225
+ | `scaffolding/_overview.md` | `dflow/specs/shared/_overview.md` |
226
+ | `scaffolding/_conventions.md` | `dflow/specs/shared/_conventions.md` (mandatory baseline) |
227
+ | `scaffolding/Git-principles-gitflow.md` | `dflow/specs/shared/Git-principles-gitflow.md` |
228
+ | `scaffolding/Git-principles-trunk.md` | `dflow/specs/shared/Git-principles-trunk.md` |
229
+ | `scaffolding/AI-AGENT-GUIDE.md` | `dflow/specs/shared/AI-AGENT-GUIDE.md` when at least one AI agent is selected |
230
+ | generated tool shim | `AGENTS.md`, `CLAUDE.md`, or `.github/copilot-instructions.md` when selected and missing |
231
+ | generated merge snippet | `dflow/specs/shared/*-snippet.md` when the selected tool file already exists |
232
+
233
+ ### 3.3 Present the preview
234
+
235
+ Present the complete file list as two tables, separating create vs
236
+ skip, and wait for developer confirmation:
237
+
238
+ > "Based on Step 1 inventory + Step 2 answers, here is what I'll do:
239
+ >
240
+ > **Will create ({N} files):**
241
+ >
242
+ > | Path | Source |
243
+ > |---|---|
244
+ > | `dflow/specs/features/active/.gitkeep` | (directory placeholder) |
245
+ > | `dflow/specs/features/completed/.gitkeep` | (directory placeholder) |
246
+ > | `dflow/specs/features/backlog/.gitkeep` | (directory placeholder) |
247
+ > | `dflow/specs/domain/glossary.md` | `templates/glossary.md` (mandatory baseline) |
248
+ > | `dflow/specs/shared/_conventions.md` | `scaffolding/_conventions.md` (mandatory baseline) |
249
+ > | `dflow/specs/migration/tech-debt.md` | `templates/tech-debt.md` (mandatory baseline) |
250
+ > | `dflow/specs/shared/_overview.md` | optional (you picked it) |
251
+ > | `dflow/specs/shared/Git-principles-trunk.md` | mandatory (selected Git policy) |
252
+ > | `dflow/specs/shared/AI-AGENT-GUIDE.md` | selected AI agent guide |
253
+ > | `CLAUDE.md` | selected tool shim because repo has no CLAUDE.md |
254
+ >
255
+ > **Will skip ({M} files — already present):**
256
+ >
257
+ > | Path | Reason |
258
+ > |---|---|
259
+ > | `dflow/specs/domain/glossary.md` | already exists (47 lines) |
260
+ >
261
+ > **Not creating** (per F-05 decision):
262
+ > - No `dflow/specs/domain/{context}/behavior.md` files. These are created
263
+ > later by `/dflow:new-feature` Step 8.3 or P007a when the first
264
+ > bounded context is established.
265
+ > - No `dflow/specs/domain/context-map.md`. Brownfield track treats BCs as
266
+ > emergent from domain extraction; this file becomes relevant later,
267
+ > typically when 2+ contexts coexist.
268
+ >
269
+ > Looks good? Reply 'yes' to proceed with the writes, or tell me what to
270
+ > adjust."
271
+
272
+ **→ Step Gate: Step 3 → Step 4**
273
+
274
+ Wait for explicit confirmation. If the developer asks to change the
275
+ selection, go back to the relevant Step 2 question (Q5–Q8) and re-run Step 3.
276
+
277
+ ---
278
+
279
+ ## Step 4: Write Files (placeholder fill-in + existing-file protection)
280
+
281
+ Execute the write plan agreed in Step 3. Use the Write tool (or
282
+ mkdir-equivalent for directories).
283
+
284
+ ### 4.1 Existing-file protection (strict)
285
+
286
+ Before every single write, re-check: does the target path already
287
+ exist? If yes, **skip** — do not overwrite. Announce the skip:
288
+
289
+ > "Skipped `dflow/specs/domain/glossary.md` — already exists (unchanged)."
290
+
291
+ Only overwrite if the developer said explicitly "overwrite X" in
292
+ Step 2 (rare; usually a conscious reset during early adoption).
293
+
294
+ ### 4.2 Placeholder substitution
295
+
296
+ When writing from `scaffolding/` sources, substitute the placeholders
297
+ captured in Step 2:
298
+
299
+ | Placeholder | Substitution source |
300
+ |---|---|
301
+ | `{YYYY-MM-DD}` | Today's date (ISO format) |
302
+ | `{System Name}` / `{系統名稱}` | From Step 2 or repo folder name |
303
+ | `{業務領域}` | From Step 2 Q1 / Q2 context |
304
+ | `{Language}` | From Step 2 Q2 |
305
+ | `{Framework}` | From Step 2 Q2 |
306
+ | `{Framework version}` | From Step 2 Q2 |
307
+ | `{ORM / persistence}` | From Step 2 Q2 |
308
+ | `{ORM version}` | From Step 2 Q2 |
309
+ | `{prose-language}` | From Step 2 Q4 |
310
+
311
+ For placeholders the developer did not provide, keep the `{placeholder}`
312
+ token in the emitted file and add a one-line TODO comment so they
313
+ notice:
314
+
315
+ ```markdown
316
+ <!-- TODO: fill in 業務領域 on next review -->
317
+ ```
318
+
319
+ ### 4.3 Special case — AI agent instruction files
320
+
321
+ If the developer selected any AI coding agent in Q8, create
322
+ `dflow/specs/shared/AI-AGENT-GUIDE.md` as the canonical Dflow project
323
+ guide.
324
+
325
+ For each selected tool-specific file (`AGENTS.md`, `CLAUDE.md`,
326
+ `.github/copilot-instructions.md`):
327
+
328
+ - if the target file does not exist, create a small shim at the target
329
+ path that points to `dflow/specs/shared/AI-AGENT-GUIDE.md`
330
+ - if the target file already exists, do not overwrite it; write a merge
331
+ snippet under `dflow/specs/shared/` and report that the developer
332
+ should merge it manually
333
+
334
+ ### 4.4 Directory-only entries
335
+
336
+ For directories that Git otherwise wouldn't track (empty `active/` /
337
+ `completed/` / `backlog/`), seed a `.gitkeep` file so the directory
338
+ persists across clones.
339
+
340
+ **→ Transition (step-internal)**: Step 4 complete. Announce
341
+ > "Step 4 complete (files written). Entering Step 5: Results + next
342
+ > steps."
343
+
344
+ and continue.
345
+
346
+ ---
347
+
348
+ ## Step 5: Results Report + Next-step Recommendation
349
+
350
+ Summarise what actually happened and point at the next command.
351
+
352
+ ### 5.1 Summary report
353
+
354
+ ```
355
+ Init complete. Summary:
356
+
357
+ Created ({N} files):
358
+ ✓ dflow/specs/features/active/.gitkeep
359
+ ✓ dflow/specs/features/completed/.gitkeep
360
+ ✓ dflow/specs/features/backlog/.gitkeep
361
+ ✓ dflow/specs/domain/glossary.md
362
+ ✓ dflow/specs/shared/_conventions.md
363
+ ✓ dflow/specs/migration/tech-debt.md
364
+ ✓ dflow/specs/shared/_overview.md
365
+ ✓ dflow/specs/shared/Git-principles-trunk.md
366
+ ✓ CLAUDE.md (seeded from scaffolding snippet)
367
+
368
+ Skipped ({M} files already present):
369
+ - (none this run)
370
+
371
+ Deferred (not created here by design):
372
+ - dflow/specs/domain/{context}/behavior.md — created by /dflow:new-feature
373
+ Step 8.3 or P007a baseline capture
374
+ - dflow/specs/domain/context-map.md — created organically when you have
375
+ ≥2 bounded contexts
376
+ ```
377
+
378
+ ### 5.2 Next-step recommendation
379
+
380
+ Tailor the recommendation to the Step 1 scenario:
381
+
382
+ **Greenfield**:
383
+
384
+ > "Structure is ready. Recommended next step:
385
+ > - Run `/dflow:new-feature` to start your first feature
386
+ > (this will create `dflow/specs/features/active/{SPEC-ID}-{slug}/` and
387
+ > walk you through spec → domain concepts → implementation plan)"
388
+
389
+ **Brownfield**:
390
+
391
+ > "Structure is ready. Recommended next step:
392
+ > - First, open `dflow/specs/shared/_overview.md` and fill in the 'Current
393
+ > System State' and 'Known Issues' sections — this gives Dflow
394
+ > context when you triage existing behavior later.
395
+ > - Then run `/dflow:modify-existing` to work from an incoming change
396
+ > request (most common Brownfield entry), or `/dflow:new-feature`
397
+ > for a fresh piece of work.
398
+ > - When you touch a domain concept for the first time, the completion
399
+ > flow will prompt you to baseline it into
400
+ > `dflow/specs/domain/{context}/` — don't try to pre-fill everything
401
+ > up front."
402
+
403
+ **Already fully set up (Step 1 showed nothing to do)**:
404
+
405
+ > "Your project already has a complete Dflow layout — nothing to do.
406
+ > If you were expecting changes, let me know which file you wanted
407
+ > refreshed and I'll skip the safety-net."
408
+
409
+ ### 5.3 Optional: review project-level files
410
+
411
+ Remind the developer to review files that have `{placeholder}` tokens
412
+ still in them:
413
+
414
+ > "A few files still have `{placeholder}` tokens that need your input:
415
+ > - `dflow/specs/shared/_overview.md`: `{業務領域}`, `{團隊}`,
416
+ > `{使用者規模}`
417
+ > - `CLAUDE.md`: `{業務領域}`
418
+ >
419
+ > These are fine to leave for now; fill them in during your next
420
+ > review pass."
421
+
422
+ ---
423
+
424
+ ## Notes & references
425
+
426
+ - Scaffolding templates: packaged in the Dflow tarball; project-local
427
+ outputs land under `dflow/specs/shared/`
428
+ - `_index.md` feature template: `dflow/specs/shared/dflow-workflows/templates/_index.md`
429
+ (used by `/dflow:new-feature`, NOT by this flow)
430
+ - Git integration rules: `dflow/specs/shared/dflow-workflows/references/git-integration.md`