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,344 @@
1
+ # Git Integration with SDD/DDD — Greenfield Clean Architecture
2
+
3
+ Same minimal Git coupling as the Brownfield edition. Key difference: gate
4
+ checks validate Clean Architecture layer rules instead of brownfield
5
+ delivery/entrypoint extraction checks. Dflow remains agnostic about the
6
+ project's Git *branching strategy* (Git Flow, GitHub Flow, trunk-based,
7
+ etc.) — it only prescribes the feature-branch-per-feature convention
8
+ that SDD traceability depends on.
9
+
10
+ > Dflow does not pick `gitflow` vs `trunk` for you, but it now requires you to
11
+ > record one at `dflow init` so the runtime branch gate and finish-stage merge
12
+ > guidance can adapt. The selected policy's `Git-principles-{gitflow|trunk}.md`
13
+ > is seeded under `dflow/specs/shared/`.
14
+
15
+ ## Branch-to-Workflow Mapping
16
+
17
+ Dflow only requires that every SDD feature / bug-fix lives on its own branch
18
+ that links back to a spec. The *base branch* that feature branches are cut
19
+ from (e.g. `main`, `develop`, `trunk`) is a project-level decision that Dflow
20
+ does not mandate.
21
+
22
+ ```
23
+ main (or your project's base branch)
24
+ │
25
+ ├─ feature/{SPEC-ID}-{slug} ← Full SDD + DDD workflow
26
+ │ Gate: spec + Aggregate design before first commit
27
+ │
28
+ └─ bugfix/{BUG-ID}-{slug} ← Lightweight SDD workflow
29
+ Gate: lightweight spec with layer identification
30
+ ```
31
+
32
+ > If your project adopts Git Flow / GitHub Flow / trunk-based, the choice of
33
+ > base branch (and whether you use `develop`, `release/*`, or a single `main`)
34
+ > is up to the project. Dflow does not decide this.
35
+
36
+ ## Branch Naming Convention
37
+
38
+ ```
39
+ feature/{SPEC-ID}-{slug}
40
+ bugfix/{BUG-ID}-{slug}
41
+ ```
42
+
43
+ Examples:
44
+
45
+ ```
46
+ feature/EXP-001-expense-submission-aggregate
47
+ feature/HR-003-leave-approval-workflow
48
+ bugfix/BUG-042-money-rounding
49
+ ```
50
+
51
+ The SPEC-ID / BUG-ID prefix links the branch to its spec document. This is
52
+ the traceability chain:
53
+
54
+ ```
55
+ Git Branch → Spec Document → Domain Concepts → Code Implementation → Tests
56
+ ```
57
+
58
+ ### Slug Language
59
+
60
+ The branch slug follows the language the developer / AI discuss the
61
+ feature in. **Both Chinese and English slugs are valid**; Dflow does not
62
+ force translation in either direction. The same slug is reused for the
63
+ feature directory name and the first phase-spec filename, so consistency
64
+ across branch / dir / phase-spec is automatic.
65
+
66
+ Examples:
67
+
68
+ ```
69
+ feature/SPEC-20260421-001-報表調整 (Chinese discussion)
70
+ feature/SPEC-20260421-002-submit-expense-report (English discussion)
71
+ feature/SPEC-20260423-003-訂單折扣-匯率擴充 (Chinese, hyphenated)
72
+ bugfix/BUG-051-money-rounding (English)
73
+ ```
74
+
75
+ Empirical note: an Obts production team has run Dflow with Chinese
76
+ branch / directory / PR titles in 2026-Q1–Q2 without encountering
77
+ encoding issues on common Git hosts (GitHub, Azure DevOps), CI runners,
78
+ or PR review bots. Other Git platforms may still need spot-checking;
79
+ when in doubt, run a smoke test on the project's CI pipeline with one
80
+ representative Chinese-slug branch before adopting it widely.
81
+
82
+ Slug-shape guidance (regardless of language):
83
+ - Keep it short (2–4 words / 2–6 中文字 plus separators)
84
+ - Avoid characters that break filesystems on contributors' platforms
85
+ (forward slash, backslash, colon, asterisk, question mark, double
86
+ quote, angle brackets, pipe)
87
+ - Avoid leading dots, trailing spaces
88
+ - Lowercase ASCII / 繁體中文 are both fine; mixed-case is OK but be
89
+ consistent within a project
90
+
91
+ ## Feature Branch per Feature (Required)
92
+
93
+ This is the one non-negotiable Git coupling Dflow enforces:
94
+
95
+ - **Every SDD feature must have its own feature branch.** Branch name must
96
+ match its SPEC-ID so that `git log`, PR titles, and spec documents can be
97
+ traced back to one another.
98
+ - **Every bug-fix (SDD-tracked) must have its own bugfix branch** following
99
+ the same pattern.
100
+ - Commits that span multiple specs (accidentally or deliberately) are
101
+ discouraged; if you notice work on a new spec emerging mid-branch, stop
102
+ and create a new branch off the correct base.
103
+
104
+ This requirement is independent of the branching strategy — whether you
105
+ branch off `develop`, `main`, or something else, the feature-per-branch
106
+ convention stays.
107
+
108
+ ## Commit Checkpoints, Branch Gate & AI Commits
109
+
110
+ Dflow actively helps keep the Git trace aligned with the workflow — the AI
111
+ reminds, can do the work, and leaves policy to the team.
112
+
113
+ ### Branch gate
114
+
115
+ Before implementation starts (and before the first commit), the AI checks
116
+ whether the current branch is the feature / bugfix branch this work belongs to.
117
+ Both Git policies (`gitflow` / `trunk`, per `dflow/specs/shared/_conventions.md`
118
+ § Git Policy) use a feature branch, so:
119
+
120
+ - **Already on the matching `feature/{SPEC-ID}-{slug}` (or
121
+ `bugfix/{BUG-ID}-{slug}`) branch** — e.g. continuing an active feature with
122
+ `new-phase`, `modify-existing`, or `bug-fix` — the gate is satisfied; nothing
123
+ is created or switched.
124
+ - **Not on this work's feature / bugfix branch** (you are on the base branch the
125
+ project cuts features from — `main` / `develop` / `trunk`, or whatever your
126
+ policy uses — or on an unrelated branch) — the AI offers to create and switch
127
+ to the correct branch, switch to an existing matching one, or override and
128
+ stay (recorded in the feature `_index.md` Checkpoint Log; three consecutive
129
+ overrides → the AI suggests re-running `dflow init`, never changing the
130
+ setting on its own).
131
+
132
+ Dflow does not need to identify your base branch to evaluate the gate — it only
133
+ checks whether you are on the right feature branch. The base branch matters only
134
+ when a new branch is actually created, and which base to cut from is your
135
+ project's decision (GitFlow → `develop`, Trunk / GitHub Flow → `main`).
136
+
137
+ ### Commit checkpoints
138
+
139
+ At lifecycle milestones the AI offers a commit checkpoint, folded into the
140
+ existing Step Gate prompt (it does not add a separate question):
141
+
142
+ ```
143
+ ✓ {milestone} complete
144
+ Commit here?
145
+ [Y] Yes — the AI commits with your Git identity (marker per _conventions.md § AI Commit Policy)
146
+ [N] No — skip this checkpoint
147
+ ```
148
+
149
+ Tier sets how many checkpoints a change has: T1 three (spec / implementation /
150
+ closeout), T2 two (spec+implementation merged / closeout), T3 a single commit.
151
+ Whether you choose Y or N, the AI records one row in the feature `_index.md`
152
+ Checkpoint Log. A commit hash is written only after the commit succeeds; a hook
153
+ rejection or failed commit is recorded as `failed` (never a fake hash). After
154
+ several consecutive skips in a project the AI mentions you can turn checkpoints
155
+ off in config — it does not turn them off for you.
156
+
157
+ ### AI commits
158
+
159
+ The AI may commit at these checkpoints using your Git identity; you can always
160
+ decline. How AI commits are marked is the `## AI Commit Policy` setting in
161
+ `_conventions.md` (`none` / `co-authored-by` / `prefix`), chosen once at init.
162
+ This is a deliberate reversal of Dflow's earlier "the AI never commits" stance:
163
+ the AI helps at natural break points, while merge / push / PR still follow the
164
+ team's policy and your explicit go-ahead.
165
+
166
+ ## Directory Moves Must Use `git mv`
167
+
168
+ When you rename or move a directory or file that is tracked in Dflow
169
+ (feature directories, spec files, domain knowledge files, reference
170
+ files), **always use `git mv` instead of a plain `mv` + `git add`**.
171
+
172
+ ### Why this is non-negotiable in Dflow
173
+
174
+ Dflow is intentionally tightly coupled to Git for the feature-branch /
175
+ feature-directory pairing (one feature = one branch = one directory).
176
+ This coupling means feature lifecycle events trigger directory moves,
177
+ and rename history is what makes the spec auditable across time.
178
+
179
+ A plain `mv` followed by `git add` shows up as `delete + add` in git's
180
+ diff. That breaks:
181
+ - `git log --follow {path}` (won't trace history across the move)
182
+ - `git blame` on lines that crossed the rename boundary
183
+ - PR diff quality (reviewers see two unrelated big-blob changes
184
+ instead of one rename + small content diff)
185
+ - `/dflow:verify` and other tools that walk feature history
186
+
187
+ This is a known weakness of OpenSpec's directory-rename pattern; Dflow
188
+ deliberately avoids it by mandating `git mv`.
189
+
190
+ ### Where `git mv` is required
191
+
192
+ All of the following situations require `git mv`:
193
+
194
+ ```bash
195
+ # 1. /dflow:finish-feature: archive an entire feature directory
196
+ git mv dflow/specs/features/active/{SPEC-ID}-{slug} \
197
+ dflow/specs/features/completed/{SPEC-ID}-{slug}
198
+
199
+ # 2. Slug correction (rare — done right after Step 3.5 if the developer
200
+ # realises the agreed slug needs a tweak)
201
+ git mv dflow/specs/features/active/{SPEC-ID}-{old-slug} \
202
+ dflow/specs/features/active/{SPEC-ID}-{new-slug}
203
+
204
+ # 3. Phase-spec rename inside a feature directory
205
+ # (e.g. fixing a wrong date in the filename)
206
+ git mv dflow/specs/features/active/{SPEC-ID}-{slug}/phase-spec-2026-04-23-foo.md \
207
+ dflow/specs/features/active/{SPEC-ID}-{slug}/phase-spec-2026-04-24-foo.md
208
+
209
+ # 4. Lightweight-spec rename inside a feature directory
210
+ git mv dflow/specs/features/active/{SPEC-ID}-{slug}/lightweight-2026-04-15-old.md \
211
+ dflow/specs/features/active/{SPEC-ID}-{slug}/lightweight-2026-04-15-new.md
212
+ ```
213
+
214
+ ### Commit-message hint for renames
215
+
216
+ When the rename is the primary action (not a rename + many edits),
217
+ prefer a commit message that calls it out:
218
+
219
+ ```
220
+ [SPEC-ID] git mv {SPEC-ID}-{slug}: active/ → completed/
221
+ ```
222
+
223
+ If the rename is bundled with content edits (e.g. archival commit also
224
+ updates `rules.md`), one commit is fine — git's rename detection still
225
+ holds via similarity index.
226
+
227
+ ### What NOT to do
228
+
229
+ ```bash
230
+ # ❌ Wrong: produces delete + add, loses rename detection
231
+ mv dflow/specs/features/active/{SPEC-ID}-{slug} dflow/specs/features/completed/
232
+ git add -A
233
+ ```
234
+
235
+ ```bash
236
+ # ❌ Also wrong: deleting the source then later adding the destination
237
+ # in a separate commit prevents git rename detection across commits.
238
+ git rm -r dflow/specs/features/active/{SPEC-ID}-{slug}
239
+ # ... commit ...
240
+ # ... later, add the destination: rename trail is now broken
241
+ ```
242
+
243
+ ### Verifying a rename took
244
+
245
+ After `git mv`, run `git status` — a successful rename shows:
246
+
247
+ ```
248
+ Changes to be committed:
249
+ renamed: dflow/specs/features/active/{SPEC-ID}-{slug}/_index.md ->
250
+ dflow/specs/features/completed/{SPEC-ID}-{slug}/_index.md
251
+ ...
252
+ ```
253
+
254
+ If you see `deleted` + `new file` instead, the rename detection failed
255
+ — investigate before committing (most often, the file was edited
256
+ heavily enough that git's similarity index dropped below the rename
257
+ threshold; consider using `git mv` for the move, then making content
258
+ edits in a follow-up commit).
259
+
260
+ ### CI / hook automation (future)
261
+
262
+ A pre-commit hook can refuse commits where `dflow/specs/features/active/` or
263
+ `dflow/specs/features/completed/` show paired `D` + `A` instead of `R` for
264
+ the same feature directory. Not part of Dflow today, but compatible
265
+ with the rule.
266
+
267
+ ## Gate Checks by Branch Type
268
+
269
+ ### feature/ — Before Creating
270
+ - [ ] Feature directory exists at `dflow/specs/features/active/{SPEC-ID}-{slug}/`
271
+ with `_index.md` and at least one phase-spec inside
272
+ - [ ] `_index.md` status: `in-progress`
273
+ - [ ] Bounded Context identified
274
+ - [ ] Aggregate design documented (which Aggregate, what invariants)
275
+ - [ ] Domain Events identified
276
+ - [ ] At least one Given/When/Then scenario in the first phase-spec
277
+
278
+ ### feature/ — Before Merging (Pre-PR / Pre-Integration)
279
+ - [ ] `_index.md` status: completed
280
+ - [ ] All `phase-spec-*.md` in the feature directory have `status: completed`
281
+ - [ ] `_index.md` Current BR Snapshot has been synced to BC layer
282
+ (`rules.md` / `behavior.md` / `events.md` / `context-map.md`) —
283
+ typically by `/dflow:finish-feature`
284
+ - [ ] Whole feature directory ready to `git mv` to `dflow/specs/features/completed/`
285
+ (or already moved if `/dflow:finish-feature` ran)
286
+ - [ ] Domain layer: zero external dependencies
287
+ - [ ] No business logic outside Domain layer
288
+ - [ ] Domain Events documented in events.md
289
+ - [ ] Glossary, models, rules updated
290
+ - [ ] Domain unit tests pass
291
+ - [ ] No ORM/serialization attributes on Domain entities
292
+
293
+ ### bugfix/ — Before Creating
294
+ - [ ] Lightweight spec exists or is created during this session
295
+ - [ ] Root cause is documented
296
+ - [ ] Fix approach is noted (which layer the fix belongs in)
297
+
298
+ ### bugfix/ — Before Merging (Pre-PR / Pre-Integration)
299
+ - [ ] Spec has the fix documented
300
+ - [ ] Tech debt recorded if the underlying issue is broader (record in
301
+ `dflow/specs/architecture/tech-debt.md` if the bug reveals a systemic issue)
302
+ - [ ] Fix is in the correct architectural layer (Domain / Application /
303
+ Infrastructure / Presentation) — no business logic leaked outside
304
+ Domain
305
+
306
+ > The exact merge strategy (merge commit, squash, rebase, fast-forward)
307
+ > follows the team's selected Git policy. See the seeded
308
+ > `Git-principles-{gitflow|trunk}.md` under `dflow/specs/shared/` for that
309
+ > policy's integration commit conventions.
310
+
311
+ ## Commit Message Convention
312
+
313
+ ```
314
+ [SPEC-ID] Short description
315
+
316
+ [EXP-001] Define ExpenseReport Aggregate with submission invariants
317
+ [EXP-001] Add CreateExpenseReport command and handler
318
+ [EXP-001] Implement persistence configuration for ExpenseReport
319
+ [BUG-042] Fix rounding in Money value object
320
+ ```
321
+
322
+ ## Daily Development Flow
323
+
324
+ ```
325
+ 1. Start: Check spec → Create if missing → Design Aggregate → Create branch
326
+ 2. Implement: Domain first → Application → Infrastructure → Presentation
327
+ 3. Test: Domain unit tests → Application tests → Integration tests
328
+ 4. Review: Layer compliance → Spec compliance → Architecture score
329
+ 5. Before PR/merge: Run through merge checklist → Update docs
330
+ 6. After merge: Confirm artifacts updated → Move spec to completed/
331
+ ```
332
+
333
+ ## Integration with CI/CD (Future Enhancement)
334
+
335
+ These checks could eventually be automated in CI:
336
+ - Verify Domain project has zero external package-manager dependencies (beyond allowed list)
337
+ - Verify no ORM/serialization attributes on Domain entities
338
+ - Verify spec file exists for any branch with feature/ or bugfix/ prefix
339
+ - Verify glossary.md / rules.md / events.md updated when Domain/ files change
340
+ - Lint commit messages for spec ID format
341
+
342
+ For now, the AI handles these checks conversationally during development.
343
+
344
+ <!-- R8b verified: no Chinese structural terms in scope; per F-17 Path A. -->