dflow-sdd-ddd 0.9.0 → 0.10.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 (46) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.en.md +19 -8
  3. package/README.md +12 -5
  4. package/TEMPLATE-COVERAGE.md +0 -1
  5. package/bin/dflow.js +4 -4
  6. package/docs/evaluating-dflow.en.md +11 -7
  7. package/docs/evaluating-dflow.md +9 -4
  8. package/docs/migrating-to-dflow-v1.md +7 -3
  9. package/docs/using-with-claude-code.en.md +40 -23
  10. package/docs/using-with-claude-code.md +34 -23
  11. package/docs/using-with-codex.en.md +125 -42
  12. package/docs/using-with-codex.md +93 -34
  13. package/docs/using-with-github-copilot.en.md +135 -34
  14. package/docs/using-with-github-copilot.md +120 -43
  15. package/lib/init.js +761 -145
  16. package/package.json +2 -2
  17. package/templates/brownfield/references/drift-verification.md +1 -4
  18. package/templates/brownfield/references/finish-feature-flow.md +3 -2
  19. package/templates/brownfield/references/git-integration.md +0 -1
  20. package/templates/brownfield/references/init-project-flow.md +31 -17
  21. package/templates/brownfield/references/modify-existing-flow.md +6 -38
  22. package/templates/brownfield/references/new-feature-flow.md +13 -11
  23. package/templates/brownfield/references/new-phase-flow.md +1 -1
  24. package/templates/brownfield/scaffolding/AI-AGENT-GUIDE.md +253 -2
  25. package/templates/brownfield/scaffolding/CLAUDE-md-snippet.md +5 -8
  26. package/templates/brownfield/scaffolding/_conventions.md +10 -9
  27. package/templates/brownfield/templates/_index.md +1 -1
  28. package/templates/brownfield/templates/lightweight-spec.md +1 -1
  29. package/templates/brownfield/templates/phase-spec.md +1 -1
  30. package/templates/common/skill/SKILL.md +9 -6
  31. package/templates/greenfield/references/drift-verification.md +1 -4
  32. package/templates/greenfield/references/finish-feature-flow.md +3 -2
  33. package/templates/greenfield/references/git-integration.md +0 -1
  34. package/templates/greenfield/references/init-project-flow.md +31 -17
  35. package/templates/greenfield/references/modify-existing-flow.md +5 -7
  36. package/templates/greenfield/references/new-feature-flow.md +14 -12
  37. package/templates/greenfield/references/new-phase-flow.md +1 -1
  38. package/templates/greenfield/scaffolding/AI-AGENT-GUIDE.md +222 -2
  39. package/templates/greenfield/scaffolding/CLAUDE-md-snippet.md +10 -15
  40. package/templates/greenfield/scaffolding/Git-principles-trunk.md +1 -1
  41. package/templates/greenfield/scaffolding/_conventions.md +9 -8
  42. package/templates/greenfield/templates/_index.md +1 -1
  43. package/templates/greenfield/templates/lightweight-spec.md +1 -1
  44. package/templates/greenfield/templates/phase-spec.md +1 -1
  45. package/templates/brownfield/templates/CLAUDE.md +0 -165
  46. package/templates/greenfield/templates/CLAUDE.md +0 -172
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dflow-sdd-ddd",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Spec-first SDD/DDD workflow kit for AI-assisted development",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "homepage": "https://github.com/weilung/dflow-sdd-ddd#readme",
41
41
  "scripts": {
42
- "test": "node test/smoke.mjs"
42
+ "test": "node test/smoke.mjs && node test/registry-parity.mjs && node test/agent-inject.mjs"
43
43
  },
44
44
  "license": "AGPL-3.0-or-later",
45
45
  "publishConfig": {
@@ -168,10 +168,7 @@ Recommended trigger points (not enforced — developer's judgment):
168
168
  This command operates entirely within `dflow/specs/domain/{context}/` files
169
169
  (`rules.md` and `behavior.md`). It does **not** read from
170
170
  `dflow/specs/features/active/{SPEC-ID}-{slug}/` directories — the feature
171
- directory layout is not part of verify's input. The only effect of feature directory layout on this command is
172
- ensuring `last-updated` dates in `behavior.md` are bumped at
173
- `/dflow:finish-feature` time (so verify's mechanical drift guard stays
174
- useful).
171
+ directory layout is not part of verify's input.
175
172
 
176
173
  ## Interaction with Other Commands
177
174
 
@@ -34,7 +34,7 @@ state, archives the feature directory, and emits a Git-strategy-neutral
34
34
  - Step 5 → Step 6 (Integration Summary emitted → optional follow-up reverse-link)
35
35
 
36
36
  All other step transitions are **step-internal**: announce "Step N complete,
37
- entering Step N+1" and proceed without waiting. See SKILL.md § Workflow
37
+ entering Step N+1" and proceed without waiting. See AI-AGENT-GUIDE.md § Workflow
38
38
  Transparency for the full transparency protocol and confirmation signals.
39
39
 
40
40
  ## Step 1: Validate Phase Specs and `_index.md`
@@ -124,6 +124,8 @@ For each row in Current BR Snapshot where Status = `active`:
124
124
  `rules.md` (REMOVED rule)
125
125
  - For any RENAMED BR-ID → rename the BR-ID in `rules.md` and update
126
126
  `glossary.md` if the term itself changed
127
+ - For every BR-ID added, modified, or renamed above, set its `Last updated`
128
+ date in `rules.md`'s Rule Index to today
127
129
 
128
130
  For `behavior.md`:
129
131
 
@@ -132,7 +134,6 @@ For `behavior.md`:
132
134
  matching the BR-ID
133
135
  - For REMOVED BR-IDs, delete the corresponding scenario section from
134
136
  `behavior.md`
135
- - Update the BR-ID anchor's `last-updated` date in `behavior.md` to today
136
137
 
137
138
  This is the **mechanical input that `/dflow:verify` later uses** for the
138
139
  rules.md ↔ behavior.md drift check (see `references/drift-verification.md`).
@@ -181,7 +181,6 @@ diff. That breaks:
181
181
  - `git blame` on lines that crossed the rename boundary
182
182
  - PR diff quality (reviewers see two unrelated big-blob changes
183
183
  instead of one rename + small content diff)
184
- - `/dflow:verify` and other tools that walk feature history
185
184
 
186
185
  This is a known weakness of OpenSpec's directory-rename pattern; Dflow
187
186
  deliberately avoids it by mandating `git mv`.
@@ -49,8 +49,8 @@ Report findings plainly:
49
49
  > - `dflow/specs/`: not yet present → greenfield Dflow setup
50
50
  > - `specs/`: present → legacy / other-tool directory; Dflow V1 will not
51
51
  > migrate or modify it
52
- > - `CLAUDE.md`: present → will not overwrite; I'll offer a snippet
53
- > to merge into it"
52
+ > - `CLAUDE.md`: present → I'll append a marked Dflow block (shown in
53
+ > the preview); a merge snippet only if there's a marker conflict"
54
54
 
55
55
  Or:
56
56
 
@@ -162,9 +162,10 @@ Wait for answers.
162
162
  >
163
163
  > If you select any agent, Dflow will create
164
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."
165
+ > tool files stay thin and point back to that guide. Existing user content is
166
+ > never overwritten; Dflow appends a marked Dflow block (shown in the preview)
167
+ > and refreshes it in place on re-run. Merge snippets under
168
+ > `dflow/specs/shared/` are used only if Dflow markers conflict."
168
169
 
169
170
  **→ Transition (step-internal)**: Step 2 complete. Announce
170
171
  > "Step 2 complete (project information captured). Entering Step 3:
@@ -228,16 +229,17 @@ vendored workflow bundle). Compute the destination path:
228
229
  | `scaffolding/Git-principles-trunk.md` | `dflow/specs/shared/Git-principles-trunk.md` |
229
230
  | `scaffolding/AI-AGENT-GUIDE.md` | `dflow/specs/shared/AI-AGENT-GUIDE.md` when at least one AI agent is selected |
230
231
  | 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
+ | marked Dflow block | appended to a selected existing tool file unless it already points to `AI-AGENT-GUIDE.md`; refreshed in place on re-run |
233
+ | fallback merge snippet | `dflow/specs/shared/*-snippet.md` only when the selected tool file has conflicting or malformed Dflow markers |
232
234
 
233
235
  ### 3.3 Present the preview
234
236
 
235
- Present the complete file list as two tables, separating create vs
237
+ Present the complete file list as two tables, separating create / update vs
236
238
  skip, and wait for developer confirmation:
237
239
 
238
240
  > "Based on Step 1 inventory + Step 2 answers, here is what I'll do:
239
241
  >
240
- > **Will create ({N} files):**
242
+ > **Will create / update ({N} files):**
241
243
  >
242
244
  > | Path | Source |
243
245
  > |---|---|
@@ -250,7 +252,7 @@ skip, and wait for developer confirmation:
250
252
  > | `dflow/specs/shared/_overview.md` | optional (you picked it) |
251
253
  > | `dflow/specs/shared/Git-principles-trunk.md` | mandatory (selected Git policy) |
252
254
  > | `dflow/specs/shared/AI-AGENT-GUIDE.md` | selected AI agent guide |
253
- > | `CLAUDE.md` | selected tool shim because repo has no CLAUDE.md |
255
+ > | `CLAUDE.md` | marked Dflow block appended to existing CLAUDE.md (shown in preview) |
254
256
  >
255
257
  > **Will skip ({M} files — already present):**
256
258
  >
@@ -325,11 +327,24 @@ guide.
325
327
  For each selected tool-specific file (`AGENTS.md`, `CLAUDE.md`,
326
328
  `.github/copilot-instructions.md`):
327
329
 
330
+ (checked in this order — the first matching rule wins):
331
+
328
332
  - if the target file does not exist, create a small shim at the target
329
333
  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
334
+ - if the target file contains conflicting or malformed Dflow markers, do not
335
+ edit it; write a fallback merge snippet under `dflow/specs/shared/` and
336
+ report that the developer should merge it manually
337
+ - if the target file already contains a single well-formed Dflow marked block,
338
+ replace that block in place (idempotent refresh) and keep the rest of the
339
+ file unchanged
340
+ - if the target file is an existing whole-file Dflow-generated shim, refresh it
341
+ in place
342
+ - if the target file already points to the guide through the developer's own
343
+ pointer (and has no Dflow marked block), leave it untouched
344
+ - otherwise preserve the existing content and append a marked Dflow block at
345
+ the end of the file, keeping the file's dominant line ending; show that block
346
+ in the preview, and refresh that same block on re-run. If the developer later
347
+ deletes the block, a later `init` / `configure-agents` run appends it again
333
348
 
334
349
  ### 4.4 Directory-only entries
335
350
 
@@ -354,7 +369,7 @@ Summarise what actually happened and point at the next command.
354
369
  ```
355
370
  Init complete. Summary:
356
371
 
357
- Created ({N} files):
372
+ Created / Updated ({N} files):
358
373
  ✓ dflow/specs/features/active/.gitkeep
359
374
  ✓ dflow/specs/features/completed/.gitkeep
360
375
  ✓ dflow/specs/features/backlog/.gitkeep
@@ -363,7 +378,7 @@ Init complete. Summary:
363
378
  ✓ dflow/specs/migration/tech-debt.md
364
379
  ✓ dflow/specs/shared/_overview.md
365
380
  ✓ dflow/specs/shared/Git-principles-trunk.md
366
- ✓ CLAUDE.md (seeded from scaffolding snippet)
381
+ ✓ CLAUDE.md (marked Dflow block appended)
367
382
 
368
383
  Skipped ({M} files already present):
369
384
  - (none this run)
@@ -412,9 +427,8 @@ Remind the developer to review files that have `{placeholder}` tokens
412
427
  still in them:
413
428
 
414
429
  > "A few files still have `{placeholder}` tokens that need your input:
415
- > - `dflow/specs/shared/_overview.md`: `{業務領域}`, `{團隊}`,
416
- > `{使用者規模}`
417
- > - `CLAUDE.md`: `{業務領域}`
430
+ > - `dflow/specs/shared/_overview.md`: the Business Domain and Technical
431
+ > Architecture fields (e.g. primary domain, stakeholders, user scale, stack)
418
432
  >
419
433
  > These are fine to leave for now; fill them in during your next
420
434
  > review pass."
@@ -1,15 +1,15 @@
1
1
  # Modify Existing Feature Workflow
2
2
 
3
- Step-by-step guide for when a developer triggers `/dflow:modify-existing` or `/dflow:bug-fix` (or natural language implying a modification task — see SKILL.md § Workflow Transparency for the auto-trigger safety net).
3
+ Step-by-step guide for when a developer triggers `/dflow:modify-existing` or `/dflow:bug-fix` (or natural language implying a modification task — see AI-AGENT-GUIDE.md § Workflow Transparency for the auto-trigger safety net).
4
4
 
5
5
  **Step Gates** in this flow (stop-and-confirm before proceeding):
6
6
  - Step 2 → Step 3 (baseline captured → analyze business logic embedded in delivery/entrypoint code: presentation/UI layer, controllers, handlers, jobs, message consumers, data pipelines, or stored procedures)
7
7
  - Step 4 → Step 5 (extraction decision → start implementation)
8
8
  - Step 5 → Step 6 (implementation done → update artifacts)
9
9
 
10
- 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.
10
+ All other step transitions are **step-internal**: announce "Step N complete, entering Step N+1" and proceed without waiting. See AI-AGENT-GUIDE.md § Workflow Transparency for the full transparency protocol and confirmation signals.
11
11
 
12
- **Ceremony adjustment when triggered by `/dflow:bug-fix`**: treat as lightweight — use the Lightweight Spec Template at the end of this file instead of the full spec, and Step 4 (extraction) may default to "defer and record in tech-debt.md" unless the bug itself is in extractable logic. T2 still generates a concise `Implementation Tasks` checklist (see Step 4).
12
+ **Ceremony adjustment when triggered by `/dflow:bug-fix`**: treat as lightweight — use the Lightweight Spec Template (see `templates/lightweight-spec.md`) instead of the full spec, and Step 4 (extraction) may default to "defer and record in tech-debt.md" unless the bug itself is in extractable logic. T2 still generates a concise `Implementation Tasks` checklist (see Step 4).
13
13
 
14
14
  ## Mindset
15
15
 
@@ -31,7 +31,7 @@ This step has two parallel concerns:
31
31
 
32
32
  **Part A — Determine the Ceremony Tier (T1 / T2 / T3)**
33
33
 
34
- Dflow runs three ceremony tiers (full table in SKILL.md § Ceremony Scaling).
34
+ Dflow runs three ceremony tiers (full table in AI-AGENT-GUIDE.md § Ceremony Scaling).
35
35
  For a modification, AI judges which tier fits before deciding what to
36
36
  produce:
37
37
 
@@ -141,7 +141,7 @@ add a row:
141
141
  | {新 SPEC-ID} | {新 slug} | {today} | in-progress |
142
142
  ```
143
143
 
144
- This update is **part of the same change set** (the developer commits
144
+ This update is **part of the same change set** (offer to commit
145
145
  both at once; commit message should mention "Add follow-up reference to
146
146
  `{新 SPEC-ID}`"). The reverse link is a derived index — the new
147
147
  feature's `follow-up-of` field is the authoritative source.
@@ -152,8 +152,6 @@ phase's content).
152
152
 
153
153
  ## Step 2: Document Current Behavior (if no spec exists)
154
154
 
155
- ## Step 2: Document Current Behavior (if no spec exists)
156
-
157
155
  This is critical. Before changing anything, capture what currently exists:
158
156
 
159
157
  ```
@@ -360,7 +358,7 @@ Items marked *(post-6.3)* are re-verified after the documentation merge in 6.3 l
360
358
  - [ ] Extracted logic (if Step 4 decided "extract now") lives under `src/Domain/` as framework-pure code
361
359
  - [ ] `Implementation Tasks` section (`phase-spec.md` or `lightweight-spec.md`): all tasks checked, or unchecked items explicitly labelled as follow-up
362
360
  - [ ] *(post-6.3)* `dflow/specs/domain/{context}/behavior.md` has a section anchor for every `BR-*` in ADDED / MODIFIED entries; REMOVED entries' anchors have been deleted (mechanical input for `/dflow:verify`)
363
- - [ ] *(post-6.3)* `dflow/specs/domain/{context}/behavior.md` `last-updated` is later than this spec's `created` date (mechanical drift guard)
361
+ - [ ] *(post-6.3)* every ADDED / MODIFIED / RENAMED BR's `Last updated` in `dflow/specs/domain/{context}/rules.md` is later than this spec's `created` date (mechanical drift guard)
364
362
 
365
363
  If any item fails, report the gap and pause — don't proceed to 6.2.
366
364
 
@@ -416,33 +414,3 @@ new follow-up directory; that happens at `/dflow:finish-feature` time.
416
414
 
417
415
  Only announce "change complete" after the appropriate archival step
418
416
  above (or the Step 6.3 docs sweep) is done.
419
-
420
- ## Lightweight Spec Template (for bug fixes)
421
-
422
- For small bug fixes, a lightweight spec is enough:
423
-
424
- ```markdown
425
- ---
426
- id: BUG-042
427
- title: Fix rounding inconsistency in expense calculation
428
- status: in-progress
429
- bounded-context: Expense
430
- created: 2025-02-12
431
- ---
432
-
433
- ## Problem
434
- Entrypoint A uses Math.Round(amount, 0, MidpointRounding.AwayFromZero) (四捨五入)
435
- Entrypoint B uses Math.Floor(amount) (無條件捨去)
436
- They should both use the same rounding rule.
437
-
438
- ## Expected Behavior
439
- Given an expense amount of 123.5 TWD
440
- When displayed or returned by any entrypoint
441
- Then it should show 124 (四捨五入 per accounting standard)
442
-
443
- ## Root Cause
444
- Duplicated calculation logic — recorded in tech-debt.md
445
-
446
- ## Fix
447
- Extract rounding to Money.Round() in Domain layer, both pages call it.
448
- ```
@@ -1,6 +1,6 @@
1
1
  # New Feature Workflow
2
2
 
3
- Step-by-step guide for when a developer triggers `/dflow:new-feature` (or natural language implying a new-feature task — see SKILL.md § Workflow Transparency for the auto-trigger safety net behavior).
3
+ Step-by-step guide for when a developer triggers `/dflow:new-feature` (or natural language implying a new-feature task — see AI-AGENT-GUIDE.md § Workflow Transparency for the auto-trigger safety net behavior).
4
4
 
5
5
  **Step Gates** in this flow (stop-and-confirm before proceeding):
6
6
  - Step 3 → Step 3.5 (domain concepts captured → confirm slug + directory + branch names)
@@ -8,9 +8,9 @@ Step-by-step guide for when a developer triggers `/dflow:new-feature` (or natura
8
8
  - Step 6 → Step 7 (branch ready → start implementation)
9
9
  - Step 7 → Step 8 (implementation done → completion)
10
10
 
11
- 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.
11
+ All other step transitions are **step-internal**: announce "Step N complete, entering Step N+1" and proceed without waiting. See AI-AGENT-GUIDE.md § Workflow Transparency for the full transparency protocol and confirmation signals.
12
12
 
13
- **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).
13
+ **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 AI-AGENT-GUIDE.md § Ceremony Scaling).
14
14
 
15
15
  ## Step 1: Intake — Understand the Request
16
16
 
@@ -188,7 +188,7 @@ Specifically ask about:
188
188
  Announce to developer:
189
189
  > "Spec is drafted — behavior scenarios, business rules, and edge cases are captured. Ready to plan the implementation (Domain layer design, interfaces, thin delivery/entrypoint code — presentation/UI layer, controllers, handlers, jobs, message consumers, data pipelines, or stored procedures)? `/dflow:next` or reply 'OK' to continue, or tell me if the spec needs another iteration first."
190
190
 
191
- Wait for confirmation (`/dflow:next`, verbal OK, or implicit — see SKILL.md § Confirmation Signals) before entering Step 5.
191
+ Wait for confirmation (`/dflow:next`, verbal OK, or implicit — see AI-AGENT-GUIDE.md § Confirmation Signals) before entering Step 5.
192
192
 
193
193
  ## Step 5: Plan the Implementation
194
194
 
@@ -325,7 +325,7 @@ AI reports `✓` / `✗` for every item before touching docs. Items marked *(pos
325
325
  - [ ] Every `EC-*` edge case is handled
326
326
  - [ ] Domain layer has **no** delivery-framework references (grep `src/Domain/`)
327
327
  - [ ] *(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`)
328
- - [ ] *(post-8.3)* `dflow/specs/domain/{context}/behavior.md` `last-updated` is later than this spec's `created` date (mechanical drift guard)
328
+ - [ ] *(post-8.3)* `dflow/specs/domain/{context}/rules.md` `last-updated` is later than this spec's `created` date (mechanical drift guard)
329
329
 
330
330
  If any item fails, report the gap and pause — don't proceed to 8.2.
331
331
 
@@ -354,12 +354,14 @@ Ask these one-by-one; do not dump all five at once.
354
354
 
355
355
  ### 8.4 Archival
356
356
 
357
- For a single-phase feature, this is the closeout point. For a multi-phase
358
- feature, the developer typically reaches this point at the end of the
359
- final phase — at which time `/dflow:finish-feature` is the recommended
360
- trigger (it bundles steps 8.1 / 8.2 verification, BC sync, and archival
361
- into one explicit ceremony). Either path is acceptable; pick the one
362
- that matches the developer's habit.
357
+ For a single-phase feature, this is the closeout point. If the feature has
358
+ later phases still ahead, this phase is complete but the feature is not —
359
+ don't archive yet; run `/dflow:new-phase` to start the next phase, not
360
+ `/dflow:finish-feature` yet. For a multi-phase feature, the developer
361
+ typically reaches this point at the end of the final phase — at which time
362
+ `/dflow:finish-feature` is the recommended trigger (it bundles steps 8.1 /
363
+ 8.2 verification, BC sync, and archival into one explicit ceremony). Either
364
+ path is acceptable; pick the one that matches the developer's habit.
363
365
 
364
366
  - [ ] `_index.md` `status` field changed to `completed`
365
367
  - [ ] All `phase-spec-*.md` files in the feature directory have `status:
@@ -20,7 +20,7 @@ adds a new phase to an in-progress feature only.
20
20
  - Step 6 → Step 7 (implementation done → complete the phase)
21
21
 
22
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
23
+ entering Step N+1" and proceed without waiting. See AI-AGENT-GUIDE.md § Workflow
24
24
  Transparency for the full transparency protocol and confirmation signals.
25
25
 
26
26
  ## Step 1: Read Active Feature Context
@@ -13,6 +13,42 @@ This project uses Dflow for spec-first AI-assisted development.
13
13
  | Migration / legacy context | {migration-context} |
14
14
  | Prose language | {prose-language} |
15
15
 
16
+ ## Why This Matters
17
+
18
+ This project has business logic embedded in delivery/entrypoint code
19
+ (presentation/UI layer, controllers, handlers, jobs, message consumers, data
20
+ pipelines, or stored procedures), direct SQL in entrypoints, and duplicated
21
+ calculations across multiple flows. Every feature developed without specs makes
22
+ the target architecture harder to reach; every spec written and every domain
23
+ concept extracted makes it easier to reach.
24
+
25
+ Your role is not to lecture — it's to ask the right questions at the right time
26
+ so developers naturally produce three assets with every change:
27
+
28
+ 1. **Spec documents** — future requirements documentation
29
+ 2. **Domain layer code** — portable to a cleaner future architecture
30
+ 3. **Tech debt records** — migration guide entries
31
+
32
+ ## Scope: When Brownfield Applies
33
+
34
+ Dflow Brownfield is designed for existing systems where:
35
+
36
+ - **Business rules and domain concepts** can be extracted and re-expressed as
37
+ portable code (entities, value objects, services, repository interfaces)
38
+ - **Business logic is currently embedded in delivery/entrypoint code** —
39
+ presentation/UI layer, controllers, handlers, jobs, message consumers, data
40
+ pipelines, or stored procedures — making changes risky and slow
41
+ - The team wants to **gradually move toward a cleaner architecture** without a
42
+ full rewrite
43
+
44
+ It is **not** a fit for:
45
+
46
+ - Pure infrastructure scripts (deployment, monitoring) without a stable domain
47
+ model
48
+ - Data pipelines or batch jobs that are purely transformational with no
49
+ business-rule complexity
50
+ - Greenfield projects (use the Greenfield track instead)
51
+
16
52
  ## Before Editing Code
17
53
 
18
54
  Do not jump from a request directly to code. First identify the matching
@@ -28,7 +64,7 @@ are not available in the current AI tool:
28
64
  | `/dflow:bug-fix` | A defect can be described with expected vs actual behavior. |
29
65
  | `/dflow:new-phase` | An active feature needs another implementation slice. |
30
66
  | `/dflow:finish-feature` | Implementation is complete and needs drift closure. |
31
- | `/dflow:verify` | Specs, domain docs, implementation, and tests need consistency checks. |
67
+ | `/dflow:verify` | A bounded context's domain docs (`rules.md` ↔ `behavior.md`) need a consistency / drift check. |
32
68
  | `/dflow:pr-review` | A change is ready for SDD/DDD review. |
33
69
  | `/dflow:report-dflow-feedback` | You found a Dflow issue or improvement and want a sanitized upstream feedback draft. |
34
70
  | `/dflow:status` | You need the current workflow state, current step, completed work, in-progress work, remaining work, pending decision, and next valid action. |
@@ -45,7 +81,7 @@ Machine-readable source for rendering tool-specific thin wrappers:
45
81
  | bug-fix | /dflow:bug-fix | Investigate a defect described by expected vs actual behavior. | expected vs actual | workflow |
46
82
  | new-phase | /dflow:new-phase | Add another implementation slice to an active feature. | feature id or phase goal | workflow |
47
83
  | finish-feature | /dflow:finish-feature | Close implementation with drift checks and archived feature state. | feature id | workflow |
48
- | verify | /dflow:verify | Check specs, domain docs, implementation, and tests for consistency. | area or feature id | workflow |
84
+ | verify | /dflow:verify | Check a bounded context's domain docs (`rules.md` ↔ `behavior.md`) for consistency. | bounded context or all | workflow |
49
85
  | pr-review | /dflow:pr-review | Review a ready change for SDD/DDD alignment. | change or branch | workflow |
50
86
  | report-dflow-feedback | /dflow:report-dflow-feedback | Draft sanitized upstream feedback about Dflow. | issue or improvement | workflow |
51
87
  | status | /dflow:status | Report current workflow state and next valid action. | - | control |
@@ -53,6 +89,27 @@ Machine-readable source for rendering tool-specific thin wrappers:
53
89
  | cancel | /dflow:cancel | Abort the active workflow and return to free conversation. | - | control |
54
90
  <!-- dflow-command-registry:end -->
55
91
 
92
+ ## Routing Non-Command Input
93
+
94
+ Not every developer message maps to a `/dflow:*` workflow. Route non-command
95
+ input like this (supporting files live in the workflow bundle at
96
+ `dflow/specs/shared/dflow-workflows/`):
97
+
98
+ - **"Quick question about..." / "How does X work?"** → check
99
+ `dflow/specs/domain/` first and answer from the documented domain knowledge.
100
+ If no spec exists yet, suggest documenting the answer as domain knowledge.
101
+ - **"What should I work on next?" / sprint planning** → review
102
+ `dflow/specs/features/backlog/` and suggest work based on migration value.
103
+ - **"I'm creating a branch"** → read `references/git-integration.md`; verify
104
+ branch naming and ensure a spec exists before coding starts.
105
+ - **"Dflow seems wrong" / "this template is confusing"** (or you notice Dflow
106
+ guidance drift) → suggest `/dflow:report-dflow-feedback`; never submit
107
+ anything upstream automatically.
108
+ - **Anything else code-related** → assess whether it touches business logic. If
109
+ it does, use the auto-trigger safety net (suggest the matching `/dflow:*`
110
+ command and wait for confirmation — see § Workflow Transparency); if not, help
111
+ directly with no ceremony.
112
+
56
113
  ## Status / Control Commands
57
114
 
58
115
  `/dflow:status` reports active workflow state. Include these fields: workflow,
@@ -71,6 +128,67 @@ workflow was cancelled.
71
128
  When no workflow is active, `/dflow:next` and `/dflow:cancel` must report that
72
129
  there is no active workflow to advance or cancel.
73
130
 
131
+ ## Workflow Transparency
132
+
133
+ Dflow uses a hybrid interaction design: `/dflow:*` commands are the primary
134
+ entry, natural-language auto-trigger is a safety net, and tiered transparency
135
+ keeps the developer aware of where they are in a workflow.
136
+
137
+ ### Auto-Trigger Safety Net
138
+
139
+ When natural language implies a development task, detect the intent — but do
140
+ **not** auto-enter a workflow. Instead:
141
+
142
+ 1. State your judgment clearly:
143
+ > "I think this is a new-feature task."
144
+ 2. Offer the developer three options:
145
+ - Type `/dflow:new-feature` to start explicitly
146
+ - Reply "OK" / "繼續" to confirm this workflow
147
+ - Or correct the workflow (e.g., "no, this is a bug fix")
148
+ 3. Wait for confirmation before entering any workflow.
149
+
150
+ This addresses three failure modes of pure auto-trigger: missed triggers, wrong
151
+ workflow selection, and invisible state.
152
+
153
+ ### Three-Tier Transparency
154
+
155
+ During an active workflow, communicate at three levels — no more, no less:
156
+
157
+ | Level | Trigger point | AI behavior |
158
+ |---|---|---|
159
+ | **Flow entry (must confirm)** | After judging the workflow from NL | Stop and wait for confirmation (command, "OK", or implicit) |
160
+ | **Step gate (notify + optional confirm)** | Before major milestones | Announce the transition; if the developer provides next-step input, treat it as implicit confirmation |
161
+ | **Step-internal (notify only)** | Step N → Step N+1 | Announce "Step N complete, entering Step N+1" — do not wait |
162
+
163
+ The specific step-gate positions for each workflow live in that flow's own file
164
+ (`dflow/specs/shared/dflow-workflows/references/<flow>.md`), which is the source
165
+ of truth for its gate sequence.
166
+
167
+ ### Confirmation Signals (NL ↔ Command Equivalence)
168
+
169
+ Any of these count as "proceed to next step" — accept whichever the developer
170
+ uses:
171
+
172
+ - **Command**: `/dflow:next`
173
+ - **Verbal (English)**: OK / yes / continue / go ahead / sounds good / proceed
174
+ - **Verbal (Chinese)**: 好 / 對 / 繼續 / 可以 / 沒問題
175
+ - **Implicit**: the developer provides the information needed for the next step
176
+ (e.g., the AI asks "Which Bounded Context?" and the developer answers with the
177
+ Bounded Context name → implicit confirmation)
178
+
179
+ The implicit-confirmation rule matters — do not turn every transition into a
180
+ ceremony where the developer must say "OK" before every sentence.
181
+
182
+ ### Completion Checklist Skip Guard
183
+
184
+ Completion checklists and their step ordering live in the flow files and run at
185
+ the gate each flow specifies (the feature-level completion gate in
186
+ `new-feature-flow` / `modify-existing-flow`, the phase-level gate in
187
+ `new-phase-flow`). Do not run a checklist opportunistically. But if the
188
+ developer skips the gate and commits directly, use the auto-trigger safety net
189
+ to prompt — "It looks like you're wrapping up — should I run the Step N
190
+ completion checklist?" — before giving commit guidance.
191
+
74
192
  ## Source of Truth
75
193
 
76
194
  Dflow-owned project documents live under `dflow/specs/`.
@@ -85,6 +203,38 @@ Dflow-owned project documents live under `dflow/specs/`.
85
203
  | Completed feature snapshots | `dflow/specs/features/completed/` |
86
204
  | Technical debt | `dflow/specs/architecture/tech-debt.md` or `dflow/specs/migration/tech-debt.md` |
87
205
 
206
+ ### Project Structure
207
+
208
+ The `dflow/specs/` layout Dflow seeds and maintains (Brownfield track):
209
+
210
+ ```
211
+ dflow/specs/
212
+ ├── shared/ # Project-level governance docs (seeded by npx dflow-sdd-ddd init)
213
+ │ ├── _overview.md # System status & migration strategy
214
+ │ └── _conventions.md # Spec writing conventions
215
+ ├── domain/ # Domain knowledge (DDD preparation)
216
+ │ ├── glossary.md # Ubiquitous Language
217
+ │ └── {bounded-context}/ # e.g., expense/, hr/, leave/
218
+ │ ├── context.md # Context boundary & responsibilities
219
+ │ ├── models.md # Entity, VO, Aggregate definitions
220
+ │ ├── rules.md # Business rules index (BR-ID + one-line)
221
+ │ └── behavior.md # Consolidated behavior (Given/When/Then)
222
+ ├── features/
223
+ │ ├── active/ # Currently in development
224
+ │ │ └── {SPEC-ID}-{slug}/ # One feature = one directory
225
+ │ │ ├── _index.md # Feature dashboard + BR Snapshot + Resume Pointer
226
+ │ │ ├── phase-spec-YYYY-MM-DD-{slug}.md # T1: 0..N phase specs
227
+ │ │ └── lightweight-YYYY-MM-DD-{slug}.md # T2: 0..N lightweight specs
228
+ │ │ # (or BUG-{NUMBER}-{slug}.md)
229
+ │ ├── completed/ # Done (whole feature directory archived here)
230
+ │ └── backlog/ # Planned
231
+ │ #
232
+ │ # SPEC-ID format: SPEC-YYYYMMDD-NNN; slug follows discussion language (中文 / 英文 both OK).
233
+ │ # T3 trivial changes have NO independent file — just a row in _index.md Lightweight Changes.
234
+ └── migration/
235
+ └── tech-debt.md # Issues to fix in the target system
236
+ ```
237
+
88
238
  ## Core Rules
89
239
 
90
240
  1. Spec before code: meaningful behavior changes need a spec or lightweight bug spec before implementation.
@@ -93,6 +243,107 @@ Dflow-owned project documents live under `dflow/specs/`.
93
243
  4. Check drift before calling work complete.
94
244
  5. Follow `dflow/specs/shared/_conventions.md`, especially `## Prose Language`.
95
245
 
246
+ ## Ceremony Scaling
247
+
248
+ Not everything needs full ceremony — match effort to impact. Dflow uses three
249
+ tiers — **T1 Heavy / T2 Light / T3 Trivial** — chosen by the AI per change.
250
+ `/dflow:new-feature` and `/dflow:new-phase` always default to T1 (no judgement
251
+ needed). The criteria below apply when `/dflow:modify-existing` or
252
+ `/dflow:bug-fix` decides which tier fits a modification.
253
+
254
+ | Tier | Scenario | Output | Command / Trigger |
255
+ |---|---|---|---|
256
+ | **T1 Heavy** | New feature, new phase, architectural change, new BR | Independent `phase-spec-YYYY-MM-DD-{slug}.md` placed in the feature directory + `_index.md` Phase Specs row + refresh BR Snapshot | `/dflow:new-feature` / `/dflow:new-phase` |
257
+ | **T2 Light** | Bug fix, UI input validation tweak, flow branch change — has BR Delta | Independent `lightweight-{YYYY-MM-DD}-{slug}.md` (or `BUG-{NUMBER}-{slug}.md`) inside the feature directory + `_index.md` Lightweight Changes row (outbound link) + refresh BR Snapshot | `/dflow:bug-fix` or `/dflow:modify-existing` (lightweight branch) |
258
+ | **T3 Trivial** | Button colour, copy/text fix, typo, formatting, pure comments — **no BR change, no Domain concept change, no data structure change** | **Inline row in `_index.md` Lightweight Changes only** (no independent spec file) | `/dflow:modify-existing` (`_index-only` branch) |
259
+
260
+ **T3 criteria** (the AI must satisfy **all four** before classifying T3):
261
+
262
+ 1. No BR-ID change (no ADDED / MODIFIED / REMOVED / RENAMED business rule)
263
+ 2. No Domain concept added or changed (Aggregate / Entity / VO / Event)
264
+ 3. No data structure change (table, column, relation, index)
265
+ 4. Only changes UI surface (colour, text, layout), pure comments, or pure formatting
266
+
267
+ If any criterion fails → drop to T2; if Domain / BR / data structure is touched → escalate to T1.
268
+
269
+ **Below T3 — Dflow doesn't track at all**: pure typo fixes, commit-message
270
+ typos, pure formatting commits (e.g. `prettier` / `dotnet format` auto-runs).
271
+ You can `git commit` directly without writing even a T3 inline row.
272
+
273
+ **Lightweight spec** = Problem + Expected behavior + 1–2 Given/When/Then. The
274
+ instantiated file is placed inside the feature directory (see
275
+ `templates/lightweight-spec.md`).
276
+
277
+ ## Behavior Source of Truth (rules.md + behavior.md)
278
+
279
+ Each Bounded Context has two complementary files that together describe the
280
+ system's current behavior:
281
+
282
+ - **`rules.md`** — declarative index: lists each BR-ID with a one-line summary.
283
+ Quick lookup, easy to scan.
284
+ - **`behavior.md`** — scenario-level detail: the full Given/When/Then scenarios
285
+ for each BR-ID. This is the consolidated source of truth for "what does the
286
+ system actually do right now?"
287
+
288
+ `dflow/specs/features/completed/` is a historical archive (individual change
289
+ records). `behavior.md` is the **merged current state** — when a feature is
290
+ completed, the AI merges its scenarios into `behavior.md`; when behavior is
291
+ modified, the AI updates the corresponding section to reflect the new behavior
292
+ (git preserves history). See the `behavior.md` template in the workflow bundle
293
+ at `dflow/specs/shared/dflow-workflows/templates/behavior.md`.
294
+
295
+ ## Guiding Questions by Activity
296
+
297
+ SDD has five conceptual activities (Understanding / Domain Analysis / Spec
298
+ Writing / Implementation Planning / Tech Debt Awareness) that the AI walks the
299
+ developer through inside a workflow. They cut across workflow steps — Activity 2
300
+ (Domain Analysis) might span Step 2 and Step 3 of new-feature-flow, for example.
301
+
302
+ When a developer starts working, guide them with these questions in order. Don't
303
+ dump all questions at once — ask naturally as the conversation progresses.
304
+
305
+ **Activity markers in the phase-spec template**: each section in
306
+ `templates/phase-spec.md` carries an HTML comment (e.g.,
307
+ `<!-- Fill timing: Activity 2: Domain Analysis -->`) indicating the activity in
308
+ which that section should be filled. These markers align with the activities
309
+ below and are used by `/dflow:status` and the completion checklist to track
310
+ progress. When guiding a developer, fill sections in activity order; do not jump
311
+ ahead to Activity 4 (Implementation Planning) before Activity 3 (Spec Writing)
312
+ is agreed. The `Implementation Tasks` section at the end of the template is
313
+ produced by the AI at the end of Activity 4 — see new-feature-flow.md Step 5 /
314
+ new-phase-flow.md Step 4 / modify-existing-flow.md Step 4.
315
+
316
+ Note: the phase-spec template HTML comments cover Activity 1–4; Activity 5 (Tech
317
+ Debt Awareness) is a closeout-time concern handled when updating `tech-debt.md`
318
+ during the completion checklist, not via template section markers.
319
+
320
+ ### Activity 1: Understanding (What & Why)
321
+ - What problem does this solve? Who asked for it?
322
+ - What's the expected behavior from the user's perspective?
323
+ - Are there existing specs or domain docs related to this?
324
+
325
+ ### Activity 2: Domain Analysis (Where does it live?)
326
+ - Which Bounded Context does this belong to? (Check dflow/specs/domain/)
327
+ - What domain concepts are involved? (Entities, Value Objects, Services)
328
+ - Are there new terms? → Update glossary.md
329
+ - Are there new or changed business rules? → Document in rules.md
330
+
331
+ ### Activity 3: Spec Writing (Document before coding)
332
+ - Write the spec using the template (see `templates/phase-spec.md`)
333
+ - Define Given/When/Then scenarios for key behaviors
334
+ - Identify edge cases and business rule interactions
335
+
336
+ ### Activity 4: Implementation Planning (How to build it)
337
+ - Can the business logic live in `src/Domain/` as framework-pure code?
338
+ - What interfaces are needed? (Repository, external services)
339
+ - How thin can the delivery/entrypoint code be? (Ideally: parse input → call Domain → return or display result)
340
+
341
+ ### Activity 5: Tech Debt Awareness (What did we find?)
342
+ - Did we discover scattered business logic? → Record in tech-debt.md
343
+ - Are there duplicated calculations? → Record
344
+ - Direct SQL in delivery/entrypoint code? → Record
345
+ - Magic numbers or undocumented statuses? → Record and add to glossary
346
+
96
347
  ## Pre-V1 Artifacts Detection
97
348
 
98
349
  When working in a project that adopted Dflow before `dflow-sdd-ddd@0.1.0`,