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,195 @@
1
+ # Drift Verification — rules.md ↔ behavior.md Consistency Check
2
+
3
+ Triggered by `/dflow:verify` or `/dflow:verify <bounded-context>`.
4
+
5
+ ## Purpose
6
+
7
+ The A+C structure (`rules.md` as index + `behavior.md` as scenario content) introduces a drift risk — the two files can fall out of sync. This command provides a mechanical verification safety net that developers can run at key moments: before a PR, after a refactor, or when onboarding to an unfamiliar Bounded Context.
8
+
9
+ ## Scope
10
+
11
+ ### This command does (mechanical layer)
12
+
13
+ Three string-matching checks that AI can perform deterministically:
14
+
15
+ 1. **BR-ID forward check**: Every `BR-*` declared in `rules.md` has a corresponding section in `behavior.md`
16
+ 2. **Anchor validity**: If `rules.md` links to `behavior.md#section`, that anchor exists
17
+ 3. **BR-ID reverse check**: Every `BR-*` referenced in `behavior.md` is declared in `rules.md`
18
+
19
+ ### This command does NOT do (semantic layer — explicitly excluded)
20
+
21
+ Semantic verification (LLM reads the one-line summary in `rules.md` vs the Given/When/Then in `behavior.md` and judges whether they contradict) is **out of scope**. Reasons:
22
+ - Mechanical checks already catch most drift (missing IDs, broken links)
23
+ - Semantic judgment costs tokens and requires human review of LLM conclusions
24
+ - Deferred to Wave D — revisit after 10+ verify runs show the type distribution of actual drift
25
+
26
+ ### This command does NOT do (feature-directory aggregation — explicitly excluded)
27
+
28
+ Given the feature directory layout
29
+ (`dflow/specs/features/active/{SPEC-ID}-{slug}/` containing `_index.md` plus
30
+ 0..N `phase-spec-*.md` and 0..N `lightweight-*.md`), a tempting but
31
+ **out-of-scope** extension would be: "make `/dflow:verify` aggregate BR
32
+ state across all phase-spec files in a feature, then cross-check against
33
+ `rules.md`." Don't do that here.
34
+
35
+ Reasons:
36
+ - Feature-level BR aggregation is already maintained by `_index.md`
37
+ Current BR Snapshot, refreshed by `/dflow:new-phase` Step 5, reconciled
38
+ by `/dflow:new-phase` Step 7, and promoted by `/dflow:finish-feature`
39
+ Step 3
40
+ - BC-level current state is already maintained by `rules.md` /
41
+ `behavior.md` / `events.md`, written by the same
42
+ `/dflow:finish-feature` Step 3
43
+ - `/dflow:verify` keeps a small, mechanical scope: just the
44
+ `rules.md` ↔ `behavior.md` correspondence inside one BC, plus the
45
+ events.md bonus check below
46
+ - Cross-feature / cross-phase aggregation would mix `/dflow:verify`'s
47
+ job with `/dflow:finish-feature`'s job and produce false positives
48
+ during in-progress features
49
+
50
+ If a future need arises to add an `_index.md` Current BR Snapshot ↔
51
+ `rules.md` cross-check, that belongs in a future extension,
52
+ not in this command's current scope.
53
+
54
+ ### Anchor coexistence with `dflow:section`
55
+
56
+ `dflow:section` HTML comment anchors and markdown heading anchors serve different purposes:
57
+
58
+ - Markdown heading anchors (e.g., `behavior.md#br-001-rule-name`) remain the primary link target for BR-ID verification.
59
+ - `<!-- dflow:section ... -->` anchors are helper markers for AI/tool section positioning only.
60
+ - `dflow:section` does **not** replace BR-ID markdown anchors, and does **not** change the drift-verification algorithm.
61
+
62
+ So this command still uses BR-ID + markdown auto-id anchors as its primary index; `dflow:section` is auxiliary metadata.
63
+
64
+ ## Usage
65
+
66
+ ```
67
+ /dflow:verify # Verify all Bounded Contexts
68
+ /dflow:verify Expense # Verify a single BC (recommended default)
69
+ ```
70
+
71
+ When verifying all BCs, run each context independently and report per-context results.
72
+
73
+ ## Verification Steps
74
+
75
+ For each Bounded Context:
76
+
77
+ ### Step 1: Locate files
78
+
79
+ - Find `dflow/specs/domain/{context}/rules.md`
80
+ - Find `dflow/specs/domain/{context}/behavior.md`
81
+ - If either is missing, report and stop for that context:
82
+ ```
83
+ ✗ Expense: rules.md exists but behavior.md is missing
84
+ → Create the missing file using the matching template:
85
+ - rules.md → templates/rules.md
86
+ - behavior.md → templates/behavior.md
87
+ Or run the completion flow to populate it from existing completed specs
88
+ ```
89
+
90
+ ### Step 2: Extract BR-IDs from rules.md
91
+
92
+ Scan `rules.md` for all `BR-*` identifiers. Record each ID and any anchor link to `behavior.md`.
93
+
94
+ ### Step 3: Extract BR-IDs from behavior.md
95
+
96
+ Build two sets:
97
+
98
+ - **Primary set (scenario-bound)**: BR-IDs that appear in section headings
99
+ (e.g. `## Amount Validation (BR-001)`) or in the formal `(BR-NNN)` marker
100
+ inside a Given/When/Then scenario block. These represent BR-IDs that have
101
+ a dedicated scenario section.
102
+ - **Supplementary set (body-text mentions)**: BR-IDs that appear only in
103
+ prose / discussion text, outside any Given/When/Then block. These are
104
+ informational references, not equivalent to a scenario section.
105
+
106
+ ### Step 4: Cross-reference
107
+
108
+ Run the three checks using the primary set from Step 3 as the main comparison basis:
109
+
110
+ | Check | Pass condition | Fail message |
111
+ |---|---|---|
112
+ | Forward | Every BR-ID in rules.md has a corresponding scenario section in behavior.md (primary set) | `✗ BR-NNN declared in rules.md but has no scenario section in behavior.md` |
113
+ | Anchor | Every `behavior.md#anchor` in rules.md resolves to an existing heading | `✗ BR-NNN links to behavior.md#section but anchor not found` |
114
+ | Reverse | Every BR-ID formally referenced in behavior.md (primary set) is declared in rules.md | `✗ BR-NNN referenced in behavior.md scenario but not declared in rules.md` |
115
+
116
+ Body-text mentions (supplementary set) do **not** satisfy forward / reverse
117
+ pass conditions on their own. They are reported separately as informational
118
+ signals (see Step 5).
119
+
120
+ ### Step 5: Report
121
+
122
+ Output format:
123
+
124
+ ```
125
+ Verifying {Context} — rules.md ↔ behavior.md consistency
126
+
127
+ ✓ BR-001 → scenario section exists and references BR-001
128
+ ✓ BR-002 → scenario section exists and references BR-002
129
+ ✗ BR-003 → behavior.md has no scenario section for BR-003
130
+ (note: BR-003 appears in body text of another section,
131
+ but that does not satisfy the forward check)
132
+ ℹ BR-005 → body text reference only — no dedicated scenario section;
133
+ confirm this is intentional (e.g. cross-reference to another BR)
134
+
135
+ ✗ BR-010 → formally referenced in a behavior.md scenario but not
136
+ declared in rules.md
137
+
138
+ Summary: 3 passed, 2 issues, 1 informational
139
+
140
+ Issues:
141
+ 1. rules.md declares BR-003, but behavior.md has no corresponding
142
+ scenario section
143
+ → Possible cause: rule was implemented but behavior.md wasn't
144
+ updated in the completion flow; or a body-text mention was
145
+ mistaken for a scenario
146
+ → Action: check the implementation, then either add the scenario
147
+ to behavior.md (preferred) or remove BR-003 from rules.md if
148
+ deprecated
149
+
150
+ 2. behavior.md's {scenario section name} formally references BR-010,
151
+ but rules.md doesn't declare it
152
+ → Possible cause: scenario was added directly to behavior.md
153
+ without updating rules.md
154
+ → Action: add BR-010 to rules.md with a one-line summary, or
155
+ remove the stale scenario reference from behavior.md
156
+ ```
157
+
158
+ ## Core-Specific Notes
159
+
160
+ When verifying a Core context, also check:
161
+ - `events.md` references in `behavior.md`: if a scenario says "And {DomainEvent} is raised", confirm the event is listed in `events.md`
162
+ - This is a **bonus check**, not a blocking failure — report as a warning:
163
+ ```
164
+ ⚠ BR-001 scenario references ExpenseReportSubmitted event,
165
+ but events.md does not list it
166
+ ```
167
+
168
+ ## When to Run
169
+
170
+ Recommended trigger points (not enforced — developer's judgment):
171
+ - Before creating a PR (`/dflow:verify` as a pre-PR sanity check)
172
+ - After a refactor that touched multiple specs or domain docs
173
+ - When onboarding to an unfamiliar Bounded Context (verify before trusting the docs)
174
+ - After running `/dflow:finish-feature` — that command writes BC layer
175
+ updates from the feature's `_index.md` Current BR Snapshot; verify
176
+ catches any anchor / link drift introduced by the merge
177
+
178
+ ## Path Assumptions
179
+
180
+ This command operates entirely within `dflow/specs/domain/{context}/` files
181
+ (`rules.md`, `behavior.md`, and the `events.md` bonus check). It does
182
+ **not** read from `dflow/specs/features/active/{SPEC-ID}-{slug}/` directories
183
+ — the feature directory layout is not part of verify's input. The only effect of feature directory layout on this
184
+ command is ensuring `last-updated` dates in `behavior.md` are bumped at
185
+ `/dflow:finish-feature` time (so verify's mechanical drift guard stays
186
+ useful).
187
+
188
+ ## Interaction with Other Commands
189
+
190
+ - `/dflow:verify` is a **standalone command** — it does not require an active workflow
191
+ - It can be run mid-workflow (e.g., during Step 7 implementation to check you haven't drifted)
192
+ - It can be run after `/dflow:finish-feature` lands — that's the moment
193
+ BC-layer files get rewritten; verify catches mechanical issues from
194
+ the merge
195
+ - If issues are found, the developer decides whether to fix now or defer — the command does not block other workflows
@@ -0,0 +1,314 @@
1
+ # Finish Feature Workflow — Greenfield Clean Architecture
2
+
3
+ Step-by-step guide for when a developer triggers `/dflow:finish-feature` —
4
+ the feature closeout ceremony.
5
+
6
+ This command makes the previously-implicit closeout step (originally a
7
+ sub-step of `new-feature-flow` / `modify-existing-flow`) explicit and
8
+ directly callable. It validates that all phase-specs are completed,
9
+ syncs the feature-level BR Snapshot to the bounded context's system-level
10
+ state, archives the feature directory, and emits a Git-strategy-neutral
11
+ **Integration Summary** for the developer's PR / merge / push step.
12
+
13
+ **Important boundaries**:
14
+ - This command **does not auto-merge** and never pushes or opens a PR on its
15
+ own. Merge strategy follows the team's selected Git policy (`gitflow` /
16
+ `trunk`, recorded in `dflow/specs/shared/_conventions.md` § Git Policy).
17
+ - Closeout is split into two gates so it works offline: a **Local-closeout
18
+ gate** (Steps 1–4: validation, status flip, BC sync, archive + an optional
19
+ commit checkpoint — all doable with no network) and an **Integration / PR
20
+ gate** (Step 5: push / merge / PR — needs network; the AI only runs
21
+ `git push` / `gh pr create` when you explicitly ask).
22
+ - At the archive checkpoint the AI may offer to commit using your Git identity;
23
+ you can always decline. The commit marker mode is read from `_conventions.md`
24
+ § AI Commit Policy. This replaces Dflow's earlier "the AI never commits"
25
+ stance — the AI helps at natural checkpoints, you keep the final say.
26
+ - The BC-layer sync in Step 3 **reuses the existing Step 5.3 mechanism**
27
+ from `new-feature-flow` (Step 8.3) and `modify-existing-flow` (Step
28
+ 5.3) — it does not introduce a new sync flow. Treat it as "lift Step
29
+ 5.3 / 8.3 out of the per-phase checklist and run it once at feature
30
+ closeout, with the `_index.md` Current BR Snapshot as input."
31
+
32
+ **Step Gates** in this flow (stop-and-confirm before proceeding):
33
+ - Step 1 → Step 2 (validation passed → flip status)
34
+ - Step 3 → Step 4 (BC sync done → archive)
35
+ - Step 5 → Step 6 (Integration Summary emitted → optional follow-up reverse-link)
36
+
37
+ All other step transitions are **step-internal**: announce "Step N complete,
38
+ entering Step N+1" and proceed without waiting. See SKILL.md § Workflow
39
+ Transparency for the full transparency protocol and confirmation signals.
40
+
41
+ ## Step 1: Validate Phase Specs and `_index.md`
42
+
43
+ Before producing any closeout prose or Integration Summary text, read
44
+ `dflow/specs/shared/_conventions.md` and apply the `## Prose Language`
45
+ setting. If the setting is missing or not an explicit language tag, ask the
46
+ developer to update `_conventions.md` before continuing.
47
+
48
+ AI runs mechanical checks first. Report `✓` / `✗` for every item; if any
49
+ `✗` appears, **stop here** and ask the developer to address them before
50
+ proceeding (do not flip status, do not archive, do not emit summary).
51
+
52
+ - [ ] Locate the feature directory at `dflow/specs/features/active/{SPEC-ID}-{slug}/`
53
+ - [ ] `_index.md` exists and parses (YAML front matter intact, seven required
54
+ sections present, including the Checkpoint Log)
55
+ - [ ] Every row in `_index.md` Phase Specs table has Status = `completed`
56
+ - [ ] Every phase-spec file referenced in the Phase Specs table exists at
57
+ the path the table claims
58
+ - [ ] Every phase-spec file's frontmatter has `status: completed`
59
+ - [ ] `_index.md` has no obvious open items in Resume Pointer (e.g. "phase-N
60
+ drafting" / "implementation pending" / "TODO" markers)
61
+ - [ ] Current BR Snapshot table is non-empty (or feature is intentionally
62
+ a no-BR feature — confirm with developer if uncertain)
63
+
64
+ If any check fails:
65
+ > "Cannot finish feature `{SPEC-ID}-{slug}` yet — {N} validation issues
66
+ > found:
67
+ > ✗ phase-spec-2026-04-15-foo.md status is still `in-progress`
68
+ > ✗ Phase Specs table row 3 references missing file phase-spec-...
69
+ >
70
+ > Address these (run `/dflow:new-phase` to add missing work, or fix the
71
+ > stale status manually), then re-run `/dflow:finish-feature`."
72
+
73
+ **→ Step Gate: Step 1 → Step 2**
74
+
75
+ If all checks pass:
76
+ > "All {N} phase-specs are completed and `_index.md` is internally
77
+ > consistent. Ready to flip the feature status to `completed`?
78
+ > `/dflow:next` to proceed."
79
+
80
+ Wait for confirmation before entering Step 2.
81
+
82
+ ## Step 2: Flip `_index.md` Status to `completed`
83
+
84
+ Update the feature's `_index.md` Metadata block:
85
+
86
+ ```yaml
87
+ ---
88
+ spec-id: SPEC-{YYYYMMDD}-{NNN}
89
+ slug: {slug}
90
+ status: completed # ← flipped from in-progress
91
+ created: {YYYY-MM-DD}
92
+ branch: feature/{SPEC-ID}-{slug}
93
+ ---
94
+ ```
95
+
96
+ Also update the **Resume Pointer** to reflect closeout:
97
+
98
+ ```
99
+ **Current Progress**: feature completed ({date}); all phase-specs status = completed.
100
+ **Next Action**: integration — push / merge / PR per the selected Git policy.
101
+ ```
102
+
103
+ **→ Transition (step-internal)**: Step 2 complete. Announce "Step 2 complete (status flipped). Entering Step 3: Sync BR Snapshot to BC layer." and continue.
104
+
105
+ ## Step 3: Sync `_index.md` Current BR Snapshot to BC Layer
106
+
107
+ This step **reuses the existing sync mechanism** from `new-feature-flow`
108
+ Step 8.3 / `modify-existing-flow` Step 5.3 (`dflow/specs/domain/{context}/rules.md`
109
+ + `behavior.md` + `events.md` + `context-map.md` updates). The input is
110
+ the feature's `_index.md` Current BR Snapshot table; the output is the
111
+ BC's `rules.md` / `behavior.md` updated to reflect the feature's net
112
+ effect.
113
+
114
+ Before syncing, ensure required BC files exist. If missing, create from templates:
115
+ - `dflow/specs/domain/{context}/rules.md` → `templates/rules.md`
116
+ - `dflow/specs/domain/{context}/behavior.md` → `templates/behavior.md`
117
+ - `dflow/specs/domain/{context}/events.md` → `templates/events.md`
118
+
119
+ For each row in Current BR Snapshot where Status = `active`:
120
+
121
+ - If the BR-ID is **not yet in `rules.md`** → add it (new ADDED rule
122
+ introduced by this feature)
123
+ - If the BR-ID is **already in `rules.md`** but the rule text differs →
124
+ update it (MODIFIED rule, reflect the new text)
125
+ - If the BR-ID was previously in `rules.md` and is now in Current BR
126
+ Snapshot with Status = `removed` → remove the corresponding section in
127
+ `rules.md` (REMOVED rule)
128
+ - For any RENAMED BR-ID → rename the BR-ID in `rules.md` and update
129
+ `glossary.md` if the term itself changed
130
+
131
+ For `behavior.md`:
132
+
133
+ - For every BR-ID still active after this feature, ensure
134
+ `dflow/specs/domain/{context}/behavior.md` has a scenario section (anchor)
135
+ matching the BR-ID; the scenario should include Aggregate state
136
+ transitions and Domain Events as appropriate
137
+ - For REMOVED BR-IDs, delete the corresponding scenario section from
138
+ `behavior.md`
139
+ - Update the BR-ID anchor's `last-updated` date in `behavior.md` to today
140
+
141
+ For `events.md`:
142
+ - Add any new Domain Events introduced by phase-specs in this feature
143
+ - Remove events that were REMOVED across the feature's net delta
144
+ - Update producers / consumers if Aggregate ownership shifted
145
+
146
+ For `context-map.md`:
147
+ - Update if any cross-context interaction was added, changed, or removed
148
+ across the feature
149
+
150
+ This is the **mechanical input that `/dflow:verify` later uses** for the
151
+ rules.md ↔ behavior.md drift check (see `references/drift-verification.md`).
152
+
153
+ Cross-reference each phase-spec's Delta-from-prior-phases section to
154
+ double-check the net result; the Snapshot is the SSOT but the per-phase
155
+ Deltas are the audit trail.
156
+
157
+ > Note: this step does NOT read individual phase-specs to re-derive the BR
158
+ > set — that work was already reconciled by `/dflow:new-phase` Step 7 each
159
+ > time a phase completed. We trust `_index.md` Current BR Snapshot as the
160
+ > feature-level truth here. If the developer finds drift between Snapshot
161
+ > and the phase-specs, fix `_index.md` first, then re-run
162
+ > `/dflow:finish-feature`.
163
+
164
+ Also update `architecture/tech-debt.md` / `models.md` / `glossary.md` as
165
+ discovered during the feature (the same items listed in
166
+ `new-feature-flow.md` Step 8.3) — these may have been touched per phase
167
+ already; this is the closeout sweep.
168
+
169
+ **→ Step Gate: Step 3 → Step 4**
170
+
171
+ > "BC `{context}` synced — `rules.md` updated ({n_added} added,
172
+ > {n_modified} modified, {n_removed} removed), `behavior.md` anchors
173
+ > updated, `events.md` reflects {n_events} new / changed events,
174
+ > `context-map.md` {updated / unchanged}, `last-updated` set to {date}.
175
+ > Ready to archive the feature directory? `/dflow:next` to proceed."
176
+
177
+ Wait for confirmation before entering Step 4.
178
+
179
+ ## Step 4: Archive — `git mv` the Feature Directory
180
+
181
+ AI runs:
182
+
183
+ ```bash
184
+ git mv dflow/specs/features/active/{SPEC-ID}-{slug} \
185
+ dflow/specs/features/completed/{SPEC-ID}-{slug}
186
+ git status # confirm rename detection
187
+ ```
188
+
189
+ `git mv` is mandatory — never use plain `mv` + `git add`. This preserves
190
+ git's directory rename detection so `git log --follow` / `git blame` /
191
+ PR diff quality stays intact across the move. See
192
+ `references/git-integration.md` § "Directory Moves Must Use git mv" for
193
+ the full rule set.
194
+
195
+ After the move, also `git add` any modified files from Step 3 (the
196
+ updated `rules.md`, `behavior.md`, `events.md`, `context-map.md`,
197
+ `glossary.md`, `architecture/tech-debt.md`, etc.) into the same stage.
198
+
199
+ **Closeout commit checkpoint** (completes the offline Local-closeout gate):
200
+
201
+ ```
202
+ ✓ Feature archived to completed/ and closeout files staged
203
+ Commit this closeout now?
204
+ [Y] Yes — the AI commits with your Git identity (marker per _conventions.md § AI Commit Policy)
205
+ [N] No — skip; you commit yourself
206
+ ```
207
+
208
+ Whether you choose Y or N, record one row in the feature `_index.md`
209
+ Checkpoint Log (`closeout | committed ({hash})` or `closeout | skipped`). Only
210
+ write a hash after the commit actually succeeds; if a pre-commit hook rejects it
211
+ or the commit fails, record `failed` and surface the error — never write a fake
212
+ hash.
213
+
214
+ The Local-closeout gate is satisfied **only when the closeout is committed**:
215
+ closeout complete, Checkpoint Log updated, and the working tree clean (no
216
+ uncommitted changes). If you declined the commit (chose N) or it failed,
217
+ Local-closeout is **not** satisfied yet — commit the staged closeout yourself
218
+ before continuing; do not enter the Integration / PR gate with uncommitted
219
+ changes. Once committed, the gate stands on its own offline; integration happens
220
+ in Step 5 when you have network.
221
+
222
+ **→ Transition (step-internal)**: Step 4 complete. Branch on whether the closeout commit landed:
223
+
224
+ - **Closeout commit landed (working tree clean)** → announce "Step 4 complete (feature archived; Local-closeout gate satisfied). Entering Step 5: Integration / PR gate." and continue.
225
+ - **Closeout commit was declined (N) or failed** → **stop here.** Announce "Step 4 complete (feature archived), but the Local-closeout gate is not satisfied yet — the closeout is staged but uncommitted. Commit those changes (or address the failure), then resume to Step 5." Do **not** enter Step 5 with uncommitted closeout changes.
226
+
227
+ ## Step 5: Emit Integration Summary (Git-strategy-neutral)
228
+
229
+ Produce a plain-text summary of what this feature did. The summary is
230
+ **not** a commit message template — it is reference material the
231
+ developer adapts to whichever merge strategy their project uses
232
+ (merge commit, squash, rebase, fast-forward — Dflow stays neutral).
233
+
234
+ The selected Git policy's `Git-principles-{gitflow|trunk}.md` (seeded at init
235
+ under `dflow/specs/shared/`) explains, in its "Integration Commit Message
236
+ Conventions" section, how to format the actual commit / merge message from this
237
+ summary.
238
+
239
+ Format:
240
+
241
+ ```
242
+ == Integration Summary: {SPEC-ID}-{slug} ==
243
+
244
+ Feature Goal: {1-2 sentences from _index.md Goals & Scope}
245
+
246
+ Change Scope:
247
+ - BC: {context-name}
248
+ - Aggregates affected: {Aggregate1}, {Aggregate2}
249
+ - Phase Count: {N} (phase-spec-{date1}-{slug1} ... phase-spec-{dateN}-{slugN})
250
+ - Lightweight Changes: {n_t2} T2 lightweight specs + {n_t3} T3 inline rows
251
+
252
+ Related BR-IDs (post-closeout state):
253
+ - ADDED: BR-NN, BR-NN, ...
254
+ - MODIFIED: BR-NN, BR-NN, ...
255
+ - REMOVED: BR-NN, BR-NN, ...
256
+
257
+ Domain Events Changes:
258
+ - ADDED: {Event1}, {Event2}
259
+ - MODIFIED: {Event3}
260
+ - REMOVED: {Event4}
261
+
262
+ Phase List:
263
+ - phase-1 ({date}): {phase-slug} — {1 line}
264
+ - phase-2 ({date}): {phase-slug} — {1 line}
265
+ - ...
266
+
267
+ Next Steps (developer) — Integration / PR gate (needs network):
268
+ - Per the selected Git policy (`gitflow` / `trunk` in `_conventions.md`), choose
269
+ a merge strategy (merge commit / squash / rebase / fast-forward) and execute
270
+ - Push to remote / open a PR — the AI can run `git push` / `gh pr create` for
271
+ you, but only when you explicitly ask; it never pushes on its own
272
+ ```
273
+
274
+ Print the summary to the conversation; do not write it to a file (it is
275
+ ephemeral closeout output).
276
+
277
+ **→ Step Gate: Step 5 → Step 6**
278
+
279
+ If the feature has `follow-up-of: {原 SPEC-ID}` in its Metadata, prompt
280
+ the developer:
281
+ > "This feature is a follow-up of `{原 SPEC-ID}`. Ready to update the
282
+ > original feature's `_index.md` Follow-up Tracking row to mark this
283
+ > follow-up as `completed`? `/dflow:next` to proceed (or skip if you
284
+ > prefer to do it manually)."
285
+
286
+ If no `follow-up-of` field, skip Step 6 and announce closeout complete:
287
+ > "`/dflow:finish-feature` complete for `{SPEC-ID}-{slug}`. Feature
288
+ > directory is now at `dflow/specs/features/completed/{SPEC-ID}-{slug}/`.
289
+ > If you skipped the closeout commit, commit the staged changes first to
290
+ > finish the Local-closeout gate. Then integration — merge / push / PR —
291
+ > follows the selected Git policy, at your discretion."
292
+
293
+ ## Step 6: Reverse-Update Follow-up Tracking (only if follow-up)
294
+
295
+ For features that were created as follow-ups of an earlier completed
296
+ feature, update the original feature's
297
+ Follow-up Tracking table.
298
+
299
+ 1. Locate `dflow/specs/features/completed/{原 SPEC-ID}-{原 slug}/_index.md`
300
+ 2. Find the Follow-up Tracking section's row for this feature's SPEC-ID
301
+ 3. Flip Status → `completed`
302
+
303
+ ```bash
304
+ # The AI makes the edit and may offer to commit it (Y / N), per the AI commit policy
305
+ ```
306
+
307
+ After the update:
308
+ > "Follow-up Tracking row in `{原 SPEC-ID}-{原 slug}/_index.md` updated
309
+ > to Status = `completed`. Closeout complete."
310
+
311
+ The connection is bidirectional and weakly redundant: the new feature's
312
+ `follow-up-of` field is the authoritative source; the old feature's
313
+ Follow-up Tracking row is a derived index. If they ever disagree, trust
314
+ `follow-up-of`.