@brunosps00/dev-workflow 1.0.1 → 1.0.4

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 (43) hide show
  1. package/README.md +33 -16
  2. package/bin/dev-workflow.js +24 -7
  3. package/lib/aws-categories.js +80 -0
  4. package/lib/azure-categories.js +168 -0
  5. package/lib/constants.js +14 -6
  6. package/lib/init.js +28 -0
  7. package/lib/install-aws-skills.js +345 -0
  8. package/lib/install-azure-skills.js +231 -0
  9. package/lib/mcp.js +32 -21
  10. package/lib/prompts.js +38 -1
  11. package/package.json +1 -1
  12. package/scaffold/en/agent-instructions.md +23 -0
  13. package/scaffold/en/commands/dw-analyze-project.md +64 -0
  14. package/scaffold/en/commands/dw-autopilot.md +64 -5
  15. package/scaffold/en/commands/dw-bugfix.md +124 -26
  16. package/scaffold/en/commands/dw-install-aws-skills.md +166 -0
  17. package/scaffold/en/commands/dw-install-azure-skills.md +138 -0
  18. package/scaffold/en/commands/dw-intel.md +30 -3
  19. package/scaffold/en/commands/dw-pause.md +92 -0
  20. package/scaffold/en/commands/dw-qa.md +87 -11
  21. package/scaffold/en/commands/dw-resume.md +90 -0
  22. package/scaffold/en/commands/dw-review.md +22 -12
  23. package/scaffold/en/templates/bugfix-summary-template.md +66 -0
  24. package/scaffold/en/templates/concerns-template.md +59 -0
  25. package/scaffold/en/templates/state-template.md +59 -0
  26. package/scaffold/pt-br/agent-instructions.md +23 -0
  27. package/scaffold/pt-br/commands/dw-analyze-project.md +64 -0
  28. package/scaffold/pt-br/commands/dw-autopilot.md +64 -5
  29. package/scaffold/pt-br/commands/dw-bugfix.md +134 -18
  30. package/scaffold/pt-br/commands/dw-install-aws-skills.md +166 -0
  31. package/scaffold/pt-br/commands/dw-install-azure-skills.md +138 -0
  32. package/scaffold/pt-br/commands/dw-intel.md +30 -3
  33. package/scaffold/pt-br/commands/dw-pause.md +92 -0
  34. package/scaffold/pt-br/commands/dw-qa.md +87 -11
  35. package/scaffold/pt-br/commands/dw-resume.md +90 -0
  36. package/scaffold/pt-br/commands/dw-review.md +22 -12
  37. package/scaffold/pt-br/templates/bugfix-summary-template.md +66 -0
  38. package/scaffold/pt-br/templates/concerns-template.md +59 -0
  39. package/scaffold/pt-br/templates/state-template.md +59 -0
  40. package/scaffold/skills/dw-codebase-intel/SKILL.md +9 -5
  41. package/scaffold/skills/dw-codebase-intel/references/query-patterns.md +52 -0
  42. package/scaffold/skills/dw-memory/SKILL.md +26 -1
  43. package/scaffold/skills/dw-memory/references/context-budget.md +63 -0
package/lib/prompts.js CHANGED
@@ -33,4 +33,41 @@ async function selectLanguage(flagLang) {
33
33
  return lang;
34
34
  }
35
35
 
36
- module.exports = { selectLanguage, question };
36
+ // Multi-select prompt. Accepts comma-separated indexes ("1,3,5"), "all" for every
37
+ // option, or a single index. Returns an array of selected option strings.
38
+ // Invalid or empty input falls back to the first option.
39
+ function multiSelect(prompt, options) {
40
+ const rl = readline.createInterface({
41
+ input: process.stdin,
42
+ output: process.stdout,
43
+ });
44
+
45
+ return new Promise((resolve) => {
46
+ const optionsStr = options.map((o, i) => ` ${i + 1}) ${o}`).join('\n');
47
+ const help = `\n Enter numbers separated by commas (e.g. 1,3,5) or "all" for everything.`;
48
+ rl.question(`\n${prompt}\n${optionsStr}${help}\n\n Choose: `, (answer) => {
49
+ rl.close();
50
+ const trimmed = (answer || '').trim().toLowerCase();
51
+ if (!trimmed) {
52
+ resolve([options[0]]);
53
+ return;
54
+ }
55
+ if (trimmed === 'all') {
56
+ resolve(options.slice());
57
+ return;
58
+ }
59
+ const seen = new Set();
60
+ const selected = [];
61
+ for (const part of trimmed.split(',')) {
62
+ const idx = parseInt(part.trim(), 10) - 1;
63
+ if (idx >= 0 && idx < options.length && !seen.has(idx)) {
64
+ seen.add(idx);
65
+ selected.push(options[idx]);
66
+ }
67
+ }
68
+ resolve(selected.length > 0 ? selected : [options[0]]);
69
+ });
70
+ });
71
+ }
72
+
73
+ module.exports = { selectLanguage, question, multiSelect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brunosps00/dev-workflow",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "AI-driven development workflow commands for any project. Scaffolds a complete PRD-to-PR pipeline with multi-platform AI assistant support.",
5
5
  "bin": {
6
6
  "dev-workflow": "./bin/dev-workflow.js"
@@ -5,11 +5,27 @@ This project uses [`@brunosps00/dev-workflow`](https://www.npmjs.com/package/@br
5
5
 
6
6
  **The whole point of this file:** when the user states an intent that matches the Trigger Map below, run the matching `dw-*` command **without asking permission first** — unless the change is genuinely trivial (see Escape Hatches).
7
7
 
8
+ ## Auto-Sizing Matrix
9
+
10
+ Before picking a command from the Trigger Map, gauge the change's actual scope. The same intent ("fix this", "add this") can mean very different amounts of work; the matrix names four sizes and routes each to a different entry point. **Pick the smallest one that fits — under-routing wastes ceremony, over-routing hides scope.**
11
+
12
+ | Size | What it looks like | Route to |
13
+ |------|---------------------|----------|
14
+ | **Small** | ≤3 files, no migration, no new endpoint, can be summarized in one sentence. Examples: typo, log message, single-line config, dependency bump, version pin. | Just do it inline. No `dw-*` command. |
15
+ | **Medium** | Clear feature or bug, <10 numbered tasks expected, single component or single service, no architectural decisions. Examples: add a form field with validation, fix a regression in a known module, wire a new API endpoint into an existing handler. | `/dw-bugfix` (for bugs) or `/dw-plan` (for features) — straight, not via `/dw-autopilot`. |
16
+ | **Large** | Multi-component feature, ≥10 tasks expected, touches multiple modules, has user-visible UX surface AND backend. Examples: add a new entity end-to-end (model + migration + API + UI), introduce a third-party integration, redesign a flow. | `/dw-autopilot "<wish>"` — full PRD → TechSpec → Tasks → Run → QA → Review → Commit → PR pipeline with three gates. |
17
+ | **Complex** | New domain, ambiguous requirements, architectural decision required, regulatory or compliance surface, or scope that spans multiple PRDs. Examples: introduce event sourcing, rebuild auth, multi-tenancy, a new product line. | `/dw-brainstorm "<idea>"` first (auto-dispatches research/council modes), then `/dw-plan --council` so the techspec stage runs the multi-advisor debate. |
18
+
19
+ **Safety valve:** if you start in Small or Medium but the work reveals it's actually Large (the inline listing exceeds 5 steps, or `/dw-bugfix` triggers its `Step 5.0` valve), STOP and escalate. There is no flag to bypass. Escalation is the correct outcome.
20
+
21
+ **Adapted from** [`tech-leads-club/agent-skills/tlc-spec-driven`](https://github.com/tech-leads-club/agent-skills/tree/main/packages/skills-catalog/skills/(development)/tlc-spec-driven) (CC-BY-4.0). The four-size matrix is theirs; the mapping to `dw-*` commands is dev-workflow-specific.
22
+
8
23
  ## Trigger Map
9
24
 
10
25
  | User intent (literal or paraphrased) | Auto-trigger |
11
26
  |--------------------------------------|--------------|
12
27
  | "Implement X" / "Build Y" / "Add feature Z" / "I need ..." / "Create ..." | `/dw-autopilot "X"` |
28
+ | "Autopilot this PRD" / "Take this PRD to PR" / continue a bugfix escalation autonomously | `/dw-autopilot --from-prd <slug>` (existing PRD at `.dw/spec/<slug>/`) |
13
29
  | Pasted error / "X is broken" / "Bug in Y" / failing test screenshot | `/dw-bugfix "X"` |
14
30
  | "Plan this feature" / "Write a PRD + techspec + tasks" | `/dw-plan "X"` |
15
31
  | "Write a PRD for X" / "Spec out Y" | `/dw-plan prd "X"` |
@@ -18,9 +34,14 @@ This project uses [`@brunosps00/dev-workflow`](https://www.npmjs.com/package/@br
18
34
  | "Run this task" (with task ID) | `/dw-run <ID>` |
19
35
  | "Run all pending tasks" / "Execute the plan" | `/dw-run` |
20
36
  | "Continue where I left off" | `/dw-run --resume` |
37
+ | "Pause work" / "End the session" / "Save where we are" | `/dw-pause` |
38
+ | "Resume" / "Where did we stop?" / "Pick up where we left off" | `/dw-resume` |
21
39
  | "QA this feature" / "Run the test plan" | `/dw-qa` |
22
40
  | "Fix the QA bugs" | `/dw-qa --fix` |
23
41
  | "Evaluate the AI feature" / "Test the RAG / classifier" | `/dw-qa --ai` |
42
+ | "Walk me through this feature" / "UAT this with me" / "Let's do a manual run-through" | `/dw-qa --uat` |
43
+ | "Review this bugfix" / "Code-review fix `<slug>`" | `/dw-review --bugfix <slug>` |
44
+ | "QA this bugfix" / "Validate fix `<slug>`" | `/dw-qa --bugfix <slug>` |
24
45
  | "Review my PR" / "Check code quality" / "Is this ready to ship?" | `/dw-review` |
25
46
  | "Just the PRD coverage check" | `/dw-review --coverage-only` |
26
47
  | "Just the code quality review" | `/dw-review --code-only` |
@@ -36,6 +57,8 @@ This project uses [`@brunosps00/dev-workflow`](https://www.npmjs.com/package/@br
36
57
  | "Open a new project" / "Bootstrap a stack" | `/dw-new-project` |
37
58
  | "Dockerize this" / "Add docker-compose" | `/dw-dockerize` |
38
59
  | "Functional doc" / "Map screens and flows" | `/dw-functional-doc` |
60
+ | "Install Azure skills" / "Setup Microsoft docs MCP" / "Add Azure expertise" / "I'm going to work on Azure" | `/dw-install-azure-skills` |
61
+ | "Install AWS skills" / "Setup AWS MCP" / "Add AWS expertise" / "I'm going to work on AWS" | `/dw-install-aws-skills` |
39
62
 
40
63
  **Priority:** when in doubt between two commands, `/dw-autopilot` is the safest default for any non-trivial feature request — it composes the rest.
41
64
 
@@ -766,6 +766,67 @@ Three options:
766
766
  - Never write `.dw/constitution.md` without explicit user approval (option A) or explicit choice (options B/C).
767
767
  - Constitution file is committed to the repository like any other project artifact — never gitignored.
768
768
 
769
+ ### Step 9: Concerns Map Generation (Risk Map)
770
+
771
+ After the constitution step, generate `.dw/rules/concerns.md` — the project's **risk map**. While `.dw/rules/` describes how the code IS and `.dw/constitution.md` describes what it SHOULD BE, the concerns map answers a third question: **where is it dangerous to mess around?**
772
+
773
+ **Difference from the other two:**
774
+ - `.dw/rules/*.md` — analytical (observed patterns).
775
+ - `.dw/constitution.md` — declarative (committed principles).
776
+ - `.dw/rules/concerns.md` — operational risk (load-bearing fragility, hot spots, hostile code).
777
+
778
+ **Behavior:**
779
+
780
+ If `.dw/rules/concerns.md` already exists with hand-edited entries between `<!-- preserved:start -->` and `<!-- preserved:end -->` markers, preserve those entries. Refresh the auto-generated sections (Hot Spots churn data, Known Bug History from `.dw/bugfixes/`).
781
+
782
+ Otherwise (first run), build the file from scratch using `.dw/templates/concerns-template.md` as the base.
783
+
784
+ **Data to collect:**
785
+
786
+ 1. **Hot Spots — churn analysis.** For each module discovered in Step 5, compute the count of commits touching files in that module over the last 90 days (`git log --since="90 days ago" --name-only -- <module-path> | wc -l`). Modules in the top 20% by churn are candidates. Cross-reference with `.dw/bugfixes/` (next item) — modules that also appear there are confirmed Hot Spots; the rest are flagged "high churn — verify with team."
787
+
788
+ 2. **Known Bug History — bugfix aggregation.** If `.dw/bugfixes/` exists, scan every `SUMMARY.md` in it. For each, parse the `Files Touched` table; aggregate file paths by their top-level module (e.g. `src/auth/session.ts` -> `src/auth/`). Any module with `>= 2` historical fixes lands in the Known Bug History section with the count and the recent bugfix slugs.
789
+
790
+ 3. **Fragile Integrations.** Look for telltale patterns in code and config:
791
+ - External SDK clients with retry/backoff scaffolding (suggests prior failures).
792
+ - Comments like `// FIXME: vendor returns 200 with empty body sometimes`, `// HACK: legacy API workaround`, `// TODO: handle vendor X edge case`.
793
+ - Hand-rolled retry loops around fetch/axios/HTTP clients.
794
+ - `.dw/incidents/` directory — every incident postmortem that names an external system goes in here.
795
+ List these candidates. Don't fabricate — only what you observe.
796
+
797
+ 4. **Hostile Code.** Heuristics for code that needs full understanding before modification:
798
+ - Regex literals longer than 80 characters with no explanatory comment.
799
+ - Functions over 100 lines with cyclomatic complexity that resists quick reading (rough heuristic: lots of nested `if`/`switch`/loops).
800
+ - Manual transaction/locking code outside an ORM's idiomatic layer.
801
+ - Custom serializers/parsers (e.g. hand-written JSON, CSV, binary formats) without a corresponding test file.
802
+ Flag candidates and let the user confirm.
803
+
804
+ 5. **Tech Debt — Acknowledged.** Scan README, CONTRIBUTING, docs/, and code comments for `TODO`, `FIXME`, `XXX`, `HACK`, `DEPRECATED` markers older than 90 days (use `git blame` to date them). Cluster by area. Present as candidates; the user decides which deserve acknowledgement (some are stale comments, some are real debt).
805
+
806
+ **Procedure:**
807
+
808
+ 1. **Show candidates in chat first** (do NOT write the file yet). Format as a markdown table per section with a count and the strongest evidence for each entry. Cap each section at 10 entries — if more, list "+N more (see full analysis)" and let the user request expansion.
809
+
810
+ 2. Ask: "Approve as-is, drop specific entries (give the row labels), or skip this step entirely?" Wait for explicit response.
811
+
812
+ 3. On approval, write `.dw/rules/concerns.md` using `.dw/templates/concerns-template.md`. Fill in:
813
+ - Frontmatter `last_refreshed: <today's ISO date>`.
814
+ - Hot Spots table.
815
+ - Fragile Integrations table.
816
+ - Hostile Code table.
817
+ - Known Bug History table.
818
+ - Tech Debt — Acknowledged table.
819
+
820
+ 4. If a `<!-- preserved:start --> ... <!-- preserved:end -->` block existed in a prior version, append it back at the end of the file (the team's hand-curated entries).
821
+
822
+ 5. Print: "Wrote `.dw/rules/concerns.md`. Loaded on-demand by `/dw-plan`, `/dw-run`, and `/dw-bugfix` when their target touches a listed area. Never blocks — it informs, surfaces, and suggests an ADR for deviations."
823
+
824
+ **Special case — no signals found:**
825
+
826
+ If after the heuristics nothing crosses the bar (small codebase, low churn, no incidents, no bugfix history), write a minimal `concerns.md` with all sections empty (just headers) and a note: "No risk signals at this time. Re-run after the project accumulates more history."
827
+
828
+ **Refresh cadence:** users re-run `/dw-analyze-project` whenever rules drift. Step 9 refreshes auto sections while keeping preserved entries. There is no separate refresh-only command.
829
+
769
830
  ## Quality Checklist
770
831
 
771
832
  Before declaring the analysis complete, verify:
@@ -787,6 +848,9 @@ Before declaring the analysis complete, verify:
787
848
  - [ ] Generated one `.dw/rules/{project}.md` per leaf project discovered
788
849
  - [ ] Generated `.dw/rules/integrations.md` (if 2+ projects)
789
850
  - [ ] All file paths in rules reference real, existing files
851
+ - [ ] Step 8 (constitution) offered and resolved (A/B/C)
852
+ - [ ] Step 9 (concerns map) presented candidates, awaited approval, wrote `.dw/rules/concerns.md` (or noted no signals)
853
+ - [ ] Preserved-marker blocks in concerns.md kept verbatim on refresh
790
854
  - [ ] Topology analysis completed (god nodes, coupling metrics, dependency graph)
791
855
  - [ ] Critical nodes table generated with Ca, Ce, instability
792
856
  - [ ] Circular dependencies identified and documented
@@ -44,13 +44,22 @@ A step that invokes a `/dw-xxx` command is ONLY considered complete when the art
44
44
 
45
45
  | Variable | Description | Example |
46
46
  |----------|-------------|---------|
47
- | `{{WISH}}` | Description of what the user wants to build | "push notification system with per-channel preferences" |
47
+ | `{{WISH}}` | Description of what the user wants to build (default mode) | "push notification system with per-channel preferences" |
48
+ | `{{PRD_SLUG}}` | Existing PRD slug to autopilot from (when `--from-prd` is used) | `prd-bugfix-stripe-webhook-retry` |
49
+ | `{{MODE}}` | Optional invocation flag | `--from-prd <slug>` |
50
+
51
+ ## Invocation Modes
52
+
53
+ | Invocation | Behavior |
54
+ |------------|----------|
55
+ | `/dw-autopilot "<wish>"` | **Default.** Full pipeline from scratch: Codebase Intelligence → Research → Brainstorm → PRD → TechSpec → Tasks → Run → QA → Review → Commit → PR. |
56
+ | `/dw-autopilot --from-prd <slug>` | **Resume-from-PRD mode.** Skips Steps 1–4 (Intel, Research, Brainstorm, PRD). Starts at GATE 1 (presents the existing PRD for approval), then continues through TechSpec → Tasks → Run → QA → Review → Commit → PR. Used when `/dw-bugfix` has escalated via its safety valve and written a PRD to `.dw/spec/<slug>/`, or when the user previously authored a PRD by hand and wants the rest automated. |
48
57
 
49
58
  ## Approval Gates
50
59
 
51
60
  The autopilot stops ONLY at these 3 moments:
52
61
 
53
- 1. **GATE 1 — PRD**: Presents the generated PRD and awaits user approval before generating techspec/tasks
62
+ 1. **GATE 1 — PRD**: Presents the generated PRD (default mode) or the existing PRD (--from-prd mode) and awaits user approval before generating techspec/tasks
54
63
  2. **GATE 2 — Tasks**: Presents the task list and awaits approval before starting execution
55
64
  3. **GATE 3 — PR**: After automatic commit, asks if the user wants to generate the Pull Request
56
65
 
@@ -66,6 +75,22 @@ If this command is re-invoked on the same PRD after interruption:
66
75
 
67
76
  ## Full Pipeline
68
77
 
78
+ ### Step 0: Resolve invocation mode (MANDATORY first action)
79
+
80
+ Before Step 1, decide which mode is in effect:
81
+
82
+ 1. **If `--from-prd <slug>` is present in the invocation:**
83
+ - Resolve `{{PRD_SLUG}}` to `.dw/spec/<slug>/`.
84
+ - Verify the directory exists and contains a `prd.md`. If either is missing, STOP and report: `--from-prd target .dw/spec/<slug>/prd.md not found. Run /dw-plan prd or fix the slug.`
85
+ - Check whether `.dw/bugfixes/*/escalated.md` references this slug. If yes, note in the progress block: `Resuming from bugfix escalation: <NNN-bugfix-slug> → <slug>`.
86
+ - Set `mode: "from-prd"` in `autopilot-state.json` and `skipped_steps: [1, 2, 3, 4]` with `skip_reason: "from-prd-mode"`.
87
+ - Jump directly to **GATE 1** (PRD approval) using the existing `prd.md`.
88
+
89
+ 2. **Otherwise (default mode):**
90
+ - Set `mode: "autopilot"` and proceed to Step 1 normally.
91
+
92
+ <critical>In `--from-prd` mode, Steps 1–4 MUST be marked as `skipped_steps` with `skip_reason: "from-prd-mode"`. The pre-commit audit (Step 14) MUST honor this — a skipped step is not the same as a missing step.</critical>
93
+
69
94
  ### Step 1: Codebase Intelligence
70
95
 
71
96
  <critical>If `.dw/intel/` exists, querying it via `/dw-intel` is MANDATORY before starting. Falls back to `.dw/rules/` and direct grep if absent.</critical>
@@ -104,12 +129,15 @@ Run `/dw-plan prd` using brainstorm findings.
104
129
 
105
130
  ### === GATE 1: PRD Approval ===
106
131
 
132
+ **In default mode:** the PRD was just written in Step 4.
133
+ **In `--from-prd` mode:** the PRD already existed on disk before this autopilot run started (typically authored by `/dw-bugfix --analysis` or by a safety-valve escalation, or hand-edited).
134
+
107
135
  Present to the user:
108
136
  - Summary of functional requirements
109
- - Decisions made automatically
137
+ - Decisions made automatically (default mode) OR origin note: "PRD authored by /dw-bugfix escalation on <date>" / "PRD pre-existing on disk" (--from-prd mode)
110
138
  - Open questions (if any)
111
139
 
112
- **Wait for explicit approval.** If the user requests changes, adjust and re-present.
140
+ **Wait for explicit approval.** If the user requests changes, adjust and re-present. In `--from-prd` mode, edits go directly into the existing `.dw/spec/<slug>/prd.md` — there is no separate draft.
113
141
 
114
142
  ### Step 5: TechSpec (Interactive — 7+ Questions)
115
143
 
@@ -216,6 +244,34 @@ Run `/dw-review --coverage-only` again to confirm QA fixes did not break PRD com
216
244
  Run `/dw-review --code-only` (Level 3) for formal review.
217
245
  - Generate persisted report
218
246
 
247
+ ### Step 13.5: Close the bugfix loop (Conditional)
248
+
249
+ <critical>This step runs only when `mode == "from-prd"` AND the `prd_path` matches `.dw/spec/prd-bugfix-*`. Otherwise skip with `skip_reason: "not a bugfix escalation"`.</critical>
250
+
251
+ When the autopilot is finishing a bugfix that was escalated by `/dw-bugfix`, the index entry in `.dw/bugfixes/NNN-<slug>/` still has only `TASK.md` and `escalated.md` — no `SUMMARY.md` was written because the surgical bugfix flow never reached step 5.5 (the spec-driven flow did the work instead). Without `SUMMARY.md`, `/dw-intel --build` skips this bugfix forever, so `bugfix-history` queries never surface the lesson learned.
252
+
253
+ This step closes that loop **before** Step 14 (Commit) so the SUMMARY lands in the same commit as the fix.
254
+
255
+ **Procedure:**
256
+
257
+ 1. **Find the index entry.** Glob `.dw/bugfixes/*/escalated.md`. For each, read the one-line content and check whether it references the current PRD slug (e.g., `→ see .dw/spec/prd-bugfix-stripe-webhook-retry/` matches the active PRD `prd-bugfix-stripe-webhook-retry`). The match is the target `NNN-<slug>/` directory.
258
+ 2. **If no match is found:** the bugfix index doesn't expect a back-write. Skip silently and continue to Step 14.
259
+ 3. **If `SUMMARY.md` already exists in the matched directory:** do not overwrite. Continue to Step 14 — the human or a previous run already closed the loop.
260
+ 4. **Otherwise, write `SUMMARY.md`** using `.dw/templates/bugfix-summary-template.md`. Source fields from:
261
+ - **Symptom (verbatim):** the `Symptom` section of `<prd_path>/prd.md`, or the first paragraph of the original `TASK.md` if the PRD doesn't carry it.
262
+ - **Root Cause:** the original `TASK.md` Root Cause section.
263
+ - **Resolution (2–4 bullets):** distilled from `<prd_path>/techspec.md` decisions + actual `git diff <base>...HEAD --stat` summary.
264
+ - **Files Touched:** parsed from `git diff <base>...HEAD --name-only` (exclude `.dw/` paths). If >5 files, that's expected for an escalated bugfix — list them all and add a note "escalated from bugfix because of scope".
265
+ - **Verification:** point to `<prd_path>/QA/qa-report.md` and the verify report referenced in Step 9's session output.
266
+ - **Related — Concerns touched:** copy from the corresponding entries in `.dw/rules/concerns.md` if any rows reference modules in `Files Touched`.
267
+ - **Frontmatter:** `slug: NNN-<slug>`, `created: <today's ISO date>`, `status: Fixed`, `severity: <inferred from PRD priority or default Medium>`, `related_concerns: [list from above]`.
268
+ 5. **Append a final-line note** to `escalated.md`: `Closed by /dw-autopilot --from-prd on <YYYY-MM-DD>; SUMMARY.md written.` Preserve the original escalation line above it.
269
+ 6. **Record the artifact** in `autopilot-state.json` `step_artifacts["13.5"] = [".dw/bugfixes/NNN-<slug>/SUMMARY.md", ".dw/bugfixes/NNN-<slug>/escalated.md"]`.
270
+
271
+ <critical>NEVER fabricate verification evidence. If the QA report is empty or the diff is empty, do not invent files in `Files Touched`. Write the SUMMARY.md sections that are grounded and mark the rest as `_(not available — see <prd_path>/QA/ for details)_`.</critical>
272
+
273
+ After this step, the bugfix becomes visible to `/dw-intel "bugfix history in <module>"` on the next `/dw-intel --build` run.
274
+
219
275
  ### Step 14: Commit
220
276
 
221
277
  <critical>MANDATORY PRE-COMMIT AUDIT — execute BEFORE invoking `/dw-commit`:
@@ -230,7 +286,7 @@ Run `ls` on each path below and confirm existence. If ANY is missing, DO NOT com
230
286
  - Evidence of the last `/dw-review --coverage-only` run with RF-by-RF matrix (session output or reference in `autopilot-state.json`)
231
287
 
232
288
  Also verify `autopilot-state.json`:
233
- - Every step 1 through 13 that is NOT in `skipped_steps` must be in `completed_steps`
289
+ - Every step 1 through 13 (and 13.5 when in `--from-prd` mode against a `prd-bugfix-*` PRD) that is NOT in `skipped_steps` must be in `completed_steps`
234
290
  - Each completed step must have its artifacts listed in `step_artifacts`
235
291
 
236
292
  If any artifact or step is missing: STOP immediately. Report to the user: `Step N did not produce artifact X — re-running /dw-[command]`. Re-execute the command. Verify again. Only then proceed to `/dw-commit`.
@@ -263,9 +319,11 @@ Save the file `.dw/spec/prd-[name]/autopilot-state.json` with the following form
263
319
  "mode": "autopilot",
264
320
  "wish": "original user description",
265
321
  "prd_path": ".dw/spec/prd-[name]",
322
+ "from_prd_slug": null,
266
323
  "current_step": 8,
267
324
  "completed_steps": [1, 2, 3, 4, 5, 6, 7],
268
325
  "skipped_steps": [2],
326
+ "skip_reasons": {"2": "domain already mapped in .dw/rules/auth.md"},
269
327
  "gates_passed": ["prd", "tasks"],
270
328
  "step_artifacts": {
271
329
  "9": ["review-matrix-shown-in-session"],
@@ -288,6 +346,7 @@ Save the file `.dw/spec/prd-[name]/autopilot-state.json` with the following form
288
346
  - A step ONLY moves to `completed_steps` after verifying its artifacts exist on disk
289
347
  - If the session drops, re-invoke `/dw-autopilot` on the same PRD; the command reads `autopilot-state.json` and continues from the correct step, revalidating artifacts before trusting `completed_steps`
290
348
  - When the pipeline finishes (after commit or PR), remove the file or mark `"status": "completed"`
349
+ - In `--from-prd` mode, set `from_prd_slug: "<slug>"`, `mode: "from-prd"`, and include steps 1–4 in `skipped_steps` with `skip_reason: "from-prd-mode"` — this is what the pre-commit audit checks against (Step 14 verifies that every step NOT in `skipped_steps` is in `completed_steps`)
291
350
 
292
351
  <critical>After EACH completed step, display the updated progress block to the user. This is MANDATORY — the user MUST see what was done and what comes next. If a step was skipped, the reason MUST appear in the progress block.</critical>
293
352
 
@@ -9,7 +9,30 @@
9
9
  - Do NOT use when fixing bugs found during QA testing (use `/dw-qa --fix` instead)
10
10
 
11
11
  ## Pipeline Position
12
- **Predecessor:** (bug report) | **Successor:** `/dw-commit` then `/dw-generate-pr`
12
+ **Predecessor:** (bug report) | **Successor:** `/dw-commit` then `/dw-generate-pr` (optionally `/dw-review --bugfix <slug>` and `/dw-qa --bugfix <slug>` in between for additional rigor)
13
+
14
+ ## File Locations
15
+
16
+ Every bugfix has an index entry in `.dw/bugfixes/`. Direct mode keeps the full artifact there. Analysis mode and safety-valve escalations split: the index entry stays in `.dw/bugfixes/`, but the `prd.md` that `/dw-plan` will consume lands in `.dw/spec/prd-bugfix-<slug>/` (the path `/dw-plan techspec` and `/dw-plan tasks` already expect).
17
+
18
+ **Index home — always created:**
19
+
20
+ - Bugfix index directory: `.dw/bugfixes/NNN-<slug>/` (NNN zero-padded to 3 digits, sequential across all bugfixes ever recorded)
21
+ - Direct-mode artifacts written here: `TASK.md` (triage + plan), `fix-report.md` (verify evidence), `SUMMARY.md` (one-page record)
22
+ - Analysis / escalation artifacts written here: `TASK.md` (triage + would-be plan), `escalated.md` (one line pointing to the spec directory that took over)
23
+ - Downstream review output (when `/dw-review --bugfix <slug>` runs): `.dw/bugfixes/NNN-<slug>/review/`
24
+ - Downstream QA output (when `/dw-qa --bugfix <slug>` runs): `.dw/bugfixes/NNN-<slug>/QA/`
25
+
26
+ **Spec home — created only on Analysis or safety-valve escalation:**
27
+
28
+ - Spec directory: `.dw/spec/prd-bugfix-<slug>/`
29
+ - `prd.md` lives here (NOT in `.dw/bugfixes/`) so `/dw-plan techspec prd-bugfix-<slug>` and `/dw-plan tasks prd-bugfix-<slug>` operate against the path they were designed for, with no modification to `/dw-plan`.
30
+
31
+ **Templates:** `.dw/templates/bugfix-template.md` (for `TASK.md`/`prd.md`), `.dw/templates/bugfix-summary-template.md` (for `SUMMARY.md`), `.dw/templates/pr-bugfix-template.md` (for the PR body).
32
+
33
+ **Next-number discovery:** list `.dw/bugfixes/`, parse the leading 3-digit prefix of each directory, take `max + 1` (or `1` if empty). Create the directory before writing anything. The same `NNN-<slug>` is used to name the spec directory's slug portion (e.g., bugfix `007-stripe-webhook-retry` escalates to spec `.dw/spec/prd-bugfix-stripe-webhook-retry/`).
34
+
35
+ **Slug:** kebab-case derived from `{{BUG_DESCRIPTION}}` (e.g., "login-not-working", "error-500-save-user").
13
36
 
14
37
  ## Complementary Skills
15
38
 
@@ -34,23 +57,23 @@
34
57
 
35
58
  | Mode | When to Use | Result |
36
59
  |------|-------------|--------|
37
- | **Direct** (default) | Simple bug, <=5 files, no migration | Executes immediate fix |
38
- | **Analysis** (`--analysis`) | Complex bug, needs planning | Generates `tasks/dw-bugfix-*/prd.md` for techspec -> tasks |
60
+ | **Direct** (default) | Simple bug, <=5 files, no migration, <=5 numbered tasks | Executes immediate fix; persists `TASK.md` + `fix-report.md` + `SUMMARY.md` in `.dw/bugfixes/NNN-<slug>/` |
61
+ | **Analysis** (`--analysis`) | Complex bug, needs planning | Splits: `.dw/bugfixes/NNN-<slug>/{TASK.md, escalated.md}` as the index entry + `.dw/spec/prd-bugfix-<slug>/prd.md` for the techspec -> tasks pipeline |
39
62
 
40
63
  ### Analysis Mode
41
64
 
42
- When the user specifies `--analysis` or when you detect the bug needs more planning:
65
+ When the user specifies `--analysis` or when the safety valve (step 5.0) trips:
43
66
 
44
67
  ```
45
68
  bugfix my-project "Login not working" --analysis
46
69
  ```
47
70
 
48
71
  In this mode:
49
- 1. Follow the normal question and analysis flow
50
- 2. Instead of executing, generate a document at `.dw/spec/dw-bugfix-[name]/prd.md`
51
- 3. The file is named `prd.md` to maintain compatibility with the create-techspec/dw-plan tasks pipeline
52
- 4. Then the user can run `create-techspec .dw/spec/dw-bugfix-[name]`
53
- 5. And then `create-tasks .dw/spec/dw-bugfix-[name]`
72
+ 1. Follow the normal question and analysis flow.
73
+ 2. Allocate `NNN` and create `.dw/bugfixes/NNN-<slug>/`. Write `TASK.md` (the triage + clarification answers + the would-be plan that won't run here).
74
+ 3. Create the spec directory `.dw/spec/prd-bugfix-<slug>/` and write `prd.md` there (using `.dw/templates/bugfix-template.md`). This is the path `/dw-plan techspec` and `/dw-plan tasks` already know how to operate against.
75
+ 4. Write `.dw/bugfixes/NNN-<slug>/escalated.md` with exactly one line: `Escalated to /dw-plan on <YYYY-MM-DD> → see .dw/spec/prd-bugfix-<slug>/`. This is the cross-reference that lets `/dw-intel --build` include the bugfix in `bugfixes.json` even though the active planning happens in `.dw/spec/`.
76
+ 5. Tell the user the next commands: `/dw-plan techspec prd-bugfix-<slug>` and `/dw-plan tasks prd-bugfix-<slug>`.
54
77
 
55
78
  ## Workflow
56
79
 
@@ -144,6 +167,27 @@
144
167
  - {{TARGET}}/.dw/rules/*.md
145
168
  ```
146
169
 
170
+ ### 1.5. Load Concerns (Required when concerns.md exists)
171
+
172
+ If `.dw/rules/concerns.md` exists:
173
+ - Read it once.
174
+ - For each file or module referenced in `{{BUG_DESCRIPTION}}` or in the suspected fix area, cross-check against Hot Spots, Fragile Integrations, Hostile Code, and Known Bug History.
175
+ - If a match is found, surface it BEFORE asking the 3 clarification questions:
176
+
177
+ ```
178
+ ## Concern detected
179
+
180
+ The area you're touching is flagged in `.dw/rules/concerns.md`:
181
+
182
+ > [verbatim entry from concerns.md]
183
+
184
+ This means: [translate the concern into what it implies for this fix — extra test, extra reviewer, ADR, etc.]
185
+
186
+ Proceeding — but the fix-report.md must explicitly call out which concern was touched and how it was handled.
187
+ ```
188
+
189
+ If `.dw/rules/concerns.md` is missing, do NOT auto-create it (that's `/dw-analyze-project` Step 9's job). Note in chat: "no concerns map yet — consider running `/dw-analyze-project` after the fix to build one." Continue.
190
+
147
191
  ### 2. Collect Evidence (Required)
148
192
 
149
193
  Execute commands to understand the current state:
@@ -246,6 +290,40 @@
246
290
  - With `--analysis`: Go to step 6
247
291
  - Without `--analysis`: Continue to step 5
248
292
 
293
+ ### 5.0. Safety Valve (MANDATORY before step 5)
294
+
295
+ <critical>
296
+ BEFORE drafting the numbered task list in step 5, sketch the inline steps you intend to write.
297
+ If that sketch reveals **more than 5 distinct numbered tasks**, OR **any cross-file dependency that means tasks must be executed in a specific order**, OR **a task that requires running database migration / refactor / new endpoint / API contract change**, then the bugfix scope was UNDERESTIMATED and you MUST escalate.
298
+ </critical>
299
+
300
+ **Why this exists:** the triage at step 0 catches scope problems from the symptom description. The checkpoint at 4.1 catches them after root cause analysis. This valve catches the remaining case — when the fix itself, once laid out, reveals more complexity than triage and root cause analysis predicted. There is NO bypass flag. Escalation is the correct outcome.
301
+
302
+ **Escalation procedure:**
303
+
304
+ 1. Allocate `NNN` for `.dw/bugfixes/NNN-<slug>/`. Write `TASK.md` with the triage, clarifications, root cause, and the would-be plan.
305
+ 2. Create `.dw/spec/prd-bugfix-<slug>/` and write `prd.md` there (use `.dw/templates/bugfix-template.md`). This is the path `/dw-plan` expects.
306
+ 3. Write `.dw/bugfixes/NNN-<slug>/escalated.md` with: `Escalated to /dw-plan on <YYYY-MM-DD> — reason: <which valve criterion tripped> → see .dw/spec/prd-bugfix-<slug>/`.
307
+ 4. Report to the user:
308
+
309
+ ```
310
+ ## Scope larger than a bugfix
311
+
312
+ Listing the fix produced [N] tasks / [cross-file deps] / [forbidden change type].
313
+ Per the safety valve, this is no longer a surgical bugfix.
314
+
315
+ Bugfix index preserved at `.dw/bugfixes/NNN-<slug>/{TASK.md, escalated.md}`.
316
+ PRD created at `.dw/spec/prd-bugfix-<slug>/prd.md`.
317
+
318
+ Next — pick one:
319
+ - Manual chain: `/dw-plan techspec prd-bugfix-<slug>` → `/dw-plan tasks prd-bugfix-<slug>` → `/dw-run` → `/dw-qa` → `/dw-review` → `/dw-commit` → `/dw-generate-pr`.
320
+ - Hand off to autopilot: `/dw-autopilot --from-prd prd-bugfix-<slug>` — picks up at GATE 1 (PRD approval) and runs the rest automatically with the usual three gates.
321
+ ```
322
+
323
+ 5. Stop this command. Do not proceed to step 5. The user (or autopilot) invokes `/dw-plan` or `/dw-autopilot --from-prd` next.
324
+
325
+ **If the valve does NOT trip:** Continue to step 5.
326
+
249
327
  ### 5. Propose Numbered Tasks (Required)
250
328
 
251
329
  <critical>
@@ -284,14 +362,24 @@
284
362
  - `adjust` - Tell me what to modify in the plan
285
363
  ```
286
364
 
287
- ### 5.5. Final Verification (Direct mode — required before commit)
365
+ ### 5.5. Final Verification + Persistence (Direct mode — required before commit)
288
366
 
289
367
  <critical>After applying the approved tasks in Direct mode, invoke `dw-verify` before committing. The VERIFICATION REPORT must show:
290
368
  1. The project's verify command (test + lint + build) with exit 0.
291
369
  2. Original-symptom reproduction: the scenario that triggered the bug no longer triggers it.
292
-
370
+
293
371
  Without PASS on both, DO NOT commit. Report what failed and return to step 4 (root-cause analysis).</critical>
294
372
 
373
+ **On PASS, persist the bugfix artifact (always — including Direct mode):**
374
+
375
+ 1. Discover the next `NNN` (see File Locations section).
376
+ 2. Create `.dw/bugfixes/NNN-<slug>/` if not yet created in step 5.0.
377
+ 3. Write `TASK.md` with the triage, clarifications, root cause, and the approved plan as executed (use `.dw/templates/bugfix-template.md` as the base structure).
378
+ 4. Write `fix-report.md` with the verbatim `dw-verify` VERIFICATION REPORT plus the before/after reproduction trace.
379
+ 5. Write `SUMMARY.md` using `.dw/templates/bugfix-summary-template.md`. Fill in slug, date, status `Fixed`, severity, related_concerns (from step 1.5), Symptom (verbatim), Root Cause (one sentence), Resolution (2-4 bullets), Files Touched, Verification, Related, Followups.
380
+ 6. If the fix touched a concern listed in `.dw/rules/concerns.md`, append a line to that concern's row's `Last incident` column (or add a new row under Known Bug History) — preserve hand-written entries between `<!-- preserved:start -->` markers.
381
+ 7. Report paths of all three files in chat before the commit step.
382
+
295
383
  ### 6. Generate Bugfix Document (Analysis Mode)
296
384
 
297
385
  <critical>
@@ -301,28 +389,35 @@
301
389
  </critical>
302
390
 
303
391
  **Actions:**
304
- 1. Create directory: `.dw/spec/dw-bugfix-[bug-name]/`
305
- 2. Populate with all information collected in previous steps
306
- 3. Save as: `.dw/spec/dw-bugfix-[bug-name]/prd.md` (uses name `prd.md` for pipeline compatibility)
392
+ 1. Discover the next `NNN` and create `.dw/bugfixes/NNN-<slug>/`.
393
+ 2. Write `TASK.md` in the bugfix dir (the triage, clarifications, root cause, and analysis output) using `.dw/templates/bugfix-template.md` as the base.
394
+ 3. Create `.dw/spec/prd-bugfix-<slug>/` and write `prd.md` there using `.dw/templates/bugfix-template.md`. This is the path `/dw-plan` already understands — no modification to `/dw-plan` needed.
395
+ 4. Write `.dw/bugfixes/NNN-<slug>/escalated.md` with: `Analysis mode on <YYYY-MM-DD> → see .dw/spec/prd-bugfix-<slug>/`.
307
396
 
308
- **Bug name:** Use kebab-case based on the description (e.g., "login-not-working", "error-500-save-user")
397
+ **Bug slug:** kebab-case from the description (e.g., "login-not-working", "error-500-save-user").
309
398
 
310
- **IMPORTANT:** The file must be named `prd.md` (not `bugfix.md`) so that the
311
- `create-techspec` and `create-tasks` commands work without modification, since they expect `prd.md`.
399
+ **Why the split:** `/dw-plan techspec` and `/dw-plan tasks` already hardcode `.dw/spec/prd-<slug>/prd.md` as their input. To keep `/dw-plan` untouched, the PRD lands there; the `.dw/bugfixes/NNN-<slug>/` directory remains the queryable index entry (consumed by `/dw-intel`, `/dw-review --bugfix`, `/dw-qa --bugfix`). The `escalated.md` file is the cross-reference.
312
400
 
313
401
  **Output format:**
314
402
  ```
315
403
  ## Bugfix Document Generated
316
404
 
317
- File created: `.dw/spec/dw-bugfix-[name]/prd.md`
405
+ Bugfix index: `.dw/bugfixes/NNN-<slug>/{TASK.md, escalated.md}`
406
+ Planning PRD: `.dw/spec/prd-bugfix-<slug>/prd.md`
407
+
408
+ **Next steps — pick one:**
409
+
410
+ Option A (manual chain, full control):
411
+ 1. Review `.dw/spec/prd-bugfix-<slug>/prd.md`
412
+ 2. Run: `/dw-plan techspec prd-bugfix-<slug>`
413
+ 3. Run: `/dw-plan tasks prd-bugfix-<slug>`
414
+ 4. Execute tasks with: `/dw-run` (or by task ID against the spec)
318
415
 
319
- **Next steps:**
320
- 1. Review the generated document
321
- 2. Run: `create-techspec .dw/spec/dw-bugfix-[name]`
322
- 3. Run: `create-tasks .dw/spec/dw-bugfix-[name]`
323
- 4. Execute the tasks with: `run-task [number] .dw/spec/dw-bugfix-[name]`
416
+ Option B (hand off to autopilot):
417
+ 1. Run: `/dw-autopilot --from-prd prd-bugfix-<slug>`
418
+ 2. Autopilot picks up at GATE 1 (PRD approval) and runs TechSpec, Tasks, Run, QA, Review, Commit, PR with the usual three gates.
324
419
 
325
- The flow follows the same pattern as a feature/PRD.
420
+ The bugfix index entry stays queryable via `/dw-intel "bugfix history in <module>"`. Downstream `/dw-review --bugfix <slug>` and `/dw-qa --bugfix <slug>` still target `.dw/bugfixes/NNN-<slug>/` when you want a focused review of just the eventual surgical patch.
326
421
  ```
327
422
 
328
423
  ---
@@ -376,18 +471,21 @@
376
471
 
377
472
  ## Quality Checklist
378
473
 
379
- - [ ] **Bug vs Feature triage performed**
380
- - [ ] **Scope checkpoint performed (step 4.1)**
474
+ - [ ] **Bug vs Feature triage performed (step 0)**
475
+ - [ ] **Concerns map consulted if present (step 1.5)**
381
476
  - [ ] Project/PRD context loaded
382
477
  - [ ] Evidence collected (git log, errors)
383
478
  - [ ] **EXACTLY 3 questions asked**
384
479
  - [ ] Responses received and analyzed
385
480
  - [ ] Root cause identified
481
+ - [ ] **Scope checkpoint performed (step 4.1)**
482
+ - [ ] **Safety valve checked (step 5.0) — escalated to `/dw-plan` if tripped**
386
483
  - [ ] Tasks numbered sequentially
387
484
  - [ ] **Maximum 5 affected files**
388
485
  - [ ] **No migrations**
389
486
  - [ ] **Test task included (correct project framework)**
390
487
  - [ ] Awaiting approval before executing
488
+ - [ ] **`.dw/bugfixes/NNN-<slug>/{TASK,fix-report,SUMMARY}.md` written after verify PASS**
391
489
 
392
490
  <critical>
393
491
  FIRST: Evaluate if it's a bug or feature (Step 0).