@brunosps00/dev-workflow 0.8.1 → 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 (96) hide show
  1. package/README.md +30 -27
  2. package/bin/dev-workflow.js +1 -1
  3. package/lib/constants.js +6 -8
  4. package/lib/init.js +6 -0
  5. package/lib/install-deps.js +0 -5
  6. package/lib/migrate-gsd.js +164 -0
  7. package/lib/uninstall.js +2 -2
  8. package/package.json +1 -1
  9. package/scaffold/en/commands/dw-analyze-project.md +6 -11
  10. package/scaffold/en/commands/dw-autopilot.md +10 -17
  11. package/scaffold/en/commands/dw-brainstorm.md +2 -2
  12. package/scaffold/en/commands/dw-bugfix.md +1 -0
  13. package/scaffold/en/commands/dw-code-review.md +7 -5
  14. package/scaffold/en/commands/dw-commit.md +6 -0
  15. package/scaffold/en/commands/dw-create-prd.md +5 -4
  16. package/scaffold/en/commands/dw-create-techspec.md +7 -4
  17. package/scaffold/en/commands/dw-deep-research.md +6 -0
  18. package/scaffold/en/commands/dw-deps-audit.md +1 -0
  19. package/scaffold/en/commands/dw-find-skills.md +4 -4
  20. package/scaffold/en/commands/dw-fix-qa.md +1 -0
  21. package/scaffold/en/commands/dw-generate-pr.md +1 -0
  22. package/scaffold/en/commands/dw-help.md +10 -27
  23. package/scaffold/en/commands/dw-intel.md +99 -30
  24. package/scaffold/en/commands/dw-map-codebase.md +125 -0
  25. package/scaffold/en/commands/dw-new-project.md +1 -1
  26. package/scaffold/en/commands/dw-redesign-ui.md +5 -9
  27. package/scaffold/en/commands/dw-refactoring-analysis.md +8 -6
  28. package/scaffold/en/commands/dw-review-implementation.md +28 -2
  29. package/scaffold/en/commands/dw-run-plan.md +14 -20
  30. package/scaffold/en/commands/dw-run-task.md +5 -4
  31. package/scaffold/en/commands/dw-update.md +3 -1
  32. package/scaffold/en/templates/idea-onepager.md +2 -2
  33. package/scaffold/pt-br/commands/dw-analyze-project.md +6 -11
  34. package/scaffold/pt-br/commands/dw-autopilot.md +10 -17
  35. package/scaffold/pt-br/commands/dw-brainstorm.md +2 -2
  36. package/scaffold/pt-br/commands/dw-bugfix.md +1 -0
  37. package/scaffold/pt-br/commands/dw-code-review.md +7 -5
  38. package/scaffold/pt-br/commands/dw-commit.md +6 -0
  39. package/scaffold/pt-br/commands/dw-create-prd.md +5 -4
  40. package/scaffold/pt-br/commands/dw-create-techspec.md +7 -4
  41. package/scaffold/pt-br/commands/dw-deep-research.md +6 -0
  42. package/scaffold/pt-br/commands/dw-deps-audit.md +1 -0
  43. package/scaffold/pt-br/commands/dw-find-skills.md +4 -4
  44. package/scaffold/pt-br/commands/dw-fix-qa.md +1 -0
  45. package/scaffold/pt-br/commands/dw-generate-pr.md +1 -0
  46. package/scaffold/pt-br/commands/dw-help.md +10 -27
  47. package/scaffold/pt-br/commands/dw-intel.md +99 -30
  48. package/scaffold/pt-br/commands/dw-map-codebase.md +125 -0
  49. package/scaffold/pt-br/commands/dw-new-project.md +1 -1
  50. package/scaffold/pt-br/commands/dw-redesign-ui.md +5 -9
  51. package/scaffold/pt-br/commands/dw-refactoring-analysis.md +8 -6
  52. package/scaffold/pt-br/commands/dw-review-implementation.md +21 -2
  53. package/scaffold/pt-br/commands/dw-run-plan.md +16 -22
  54. package/scaffold/pt-br/commands/dw-run-task.md +5 -4
  55. package/scaffold/pt-br/commands/dw-update.md +3 -1
  56. package/scaffold/pt-br/templates/idea-onepager.md +2 -2
  57. package/scaffold/skills/dw-codebase-intel/SKILL.md +102 -0
  58. package/scaffold/skills/dw-codebase-intel/agents/intel-updater.md +318 -0
  59. package/scaffold/skills/dw-codebase-intel/references/api-design-discipline.md +138 -0
  60. package/scaffold/skills/dw-codebase-intel/references/incremental-update.md +79 -0
  61. package/scaffold/skills/dw-codebase-intel/references/intel-format.md +208 -0
  62. package/scaffold/skills/dw-codebase-intel/references/query-patterns.md +148 -0
  63. package/scaffold/skills/dw-debug-protocol/SKILL.md +106 -0
  64. package/scaffold/skills/dw-debug-protocol/references/error-categorization.md +127 -0
  65. package/scaffold/skills/dw-debug-protocol/references/non-reproducible-strategy.md +108 -0
  66. package/scaffold/skills/dw-debug-protocol/references/six-step-triage.md +139 -0
  67. package/scaffold/skills/dw-debug-protocol/references/stop-the-line.md +52 -0
  68. package/scaffold/skills/dw-execute-phase/SKILL.md +133 -0
  69. package/scaffold/skills/dw-execute-phase/agents/executor.md +264 -0
  70. package/scaffold/skills/dw-execute-phase/agents/plan-checker.md +215 -0
  71. package/scaffold/skills/dw-execute-phase/references/atomic-commits.md +143 -0
  72. package/scaffold/skills/dw-execute-phase/references/plan-verification.md +156 -0
  73. package/scaffold/skills/dw-execute-phase/references/wave-coordination.md +102 -0
  74. package/scaffold/skills/dw-git-discipline/SKILL.md +120 -0
  75. package/scaffold/skills/dw-git-discipline/references/atomic-commits-discipline.md +158 -0
  76. package/scaffold/skills/dw-git-discipline/references/branch-hygiene.md +150 -0
  77. package/scaffold/skills/dw-git-discipline/references/trunk-based-pattern.md +82 -0
  78. package/scaffold/skills/dw-memory/SKILL.md +1 -2
  79. package/scaffold/skills/dw-simplification/SKILL.md +142 -0
  80. package/scaffold/skills/dw-simplification/references/behavior-preserving.md +148 -0
  81. package/scaffold/skills/dw-simplification/references/chestertons-fence.md +152 -0
  82. package/scaffold/skills/dw-simplification/references/complexity-metrics.md +147 -0
  83. package/scaffold/skills/dw-source-grounding/SKILL.md +128 -0
  84. package/scaffold/skills/dw-source-grounding/references/citation-protocol.md +108 -0
  85. package/scaffold/skills/dw-source-grounding/references/freshness-check.md +108 -0
  86. package/scaffold/skills/dw-source-grounding/references/source-priority.md +146 -0
  87. package/scaffold/skills/dw-verify/SKILL.md +0 -1
  88. package/scaffold/skills/vercel-react-best-practices/SKILL.md +4 -0
  89. package/scaffold/skills/vercel-react-best-practices/references/perf-discipline.md +122 -0
  90. package/scaffold/skills/webapp-testing/SKILL.md +5 -0
  91. package/scaffold/skills/webapp-testing/references/security-boundary.md +115 -0
  92. package/scaffold/skills/webapp-testing/references/three-workflow-patterns.md +144 -0
  93. package/scaffold/en/commands/dw-quick.md +0 -85
  94. package/scaffold/en/commands/dw-resume.md +0 -82
  95. package/scaffold/pt-br/commands/dw-quick.md +0 -85
  96. package/scaffold/pt-br/commands/dw-resume.md +0 -82
@@ -0,0 +1,208 @@
1
+ # Intel format — schemas of `.dw/intel/` files
2
+
3
+ Every command that reads `.dw/intel/` depends on these schemas. Treat this file as the contract.
4
+
5
+ ## Layout
6
+
7
+ ```
8
+ .dw/intel/
9
+ ├── stack.json # languages, frameworks, build/test tooling
10
+ ├── files.json # per-file imports/exports/type
11
+ ├── apis.json # routes, endpoints, CLI commands
12
+ ├── deps.json # third-party dependencies + usage
13
+ ├── arch.md # architectural overview (markdown)
14
+ └── .last-refresh.json # change detection (timestamps + sha256 hashes)
15
+ ```
16
+
17
+ ## Common `_meta` block (all JSON files)
18
+
19
+ ```json
20
+ {
21
+ "_meta": {
22
+ "updated_at": "2026-05-06T12:34:56.789Z",
23
+ "version": 3
24
+ }
25
+ }
26
+ ```
27
+
28
+ - `updated_at`: ISO-8601 UTC timestamp, set on every write
29
+ - `version`: integer, starts at 1, increments on every update (full or partial)
30
+
31
+ ## `stack.json`
32
+
33
+ ```json
34
+ {
35
+ "_meta": { "updated_at": "...", "version": 1 },
36
+ "languages": ["TypeScript", "JavaScript"],
37
+ "frameworks": ["Express", "React"],
38
+ "tools": ["ESLint", "Jest", "Docker"],
39
+ "build_system": "npm scripts",
40
+ "test_framework": "Jest",
41
+ "package_manager": "npm",
42
+ "content_formats": ["Markdown", "YAML", "EJS"]
43
+ }
44
+ ```
45
+
46
+ Field rules:
47
+ - `languages`: ordered by line count (most-prevalent first)
48
+ - `frameworks`: full names (no abbreviations) — `"Next.js"` not `"next"`
49
+ - `tools`: dev tooling that affects code shape (linter, formatter, bundler, container runtime)
50
+ - `build_system`: detected from manifest (`npm scripts`, `Vite`, `webpack`, `esbuild`, `dotnet`, `cargo`, etc.)
51
+ - `test_framework`: detected from manifest (`Jest`, `Vitest`, `Pytest`, `xUnit`, `cargo test`, etc.); `"none"` if no test setup detected
52
+ - `package_manager`: from lockfile (`npm`, `pnpm`, `yarn`, `poetry`, `uv`, `dotnet`, `cargo`)
53
+ - `content_formats`: non-code formats with structural significance (markdown for docs/skills, YAML for configs, JSON Schema, OpenAPI, Protobuf, etc.)
54
+
55
+ ## `files.json`
56
+
57
+ ```json
58
+ {
59
+ "_meta": { "updated_at": "...", "version": 1 },
60
+ "entries": {
61
+ "src/server.ts": {
62
+ "exports": ["createServer", "default"],
63
+ "imports": ["./config", "express", "./routes/users"],
64
+ "type": "entry-point"
65
+ },
66
+ "src/routes/users.ts": {
67
+ "exports": ["userRouter"],
68
+ "imports": ["express", "../db", "../schemas/user"],
69
+ "type": "module"
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ Field rules:
76
+ - Key: file path relative to project root, forward slashes
77
+ - `exports`: array of ACTUAL exported symbol names. NOT descriptions. `["createServer", "default"]` is correct; `["server creation"]` is wrong.
78
+ - `imports`: array of import specifiers (relative paths or package names) — preserve as the source code writes them
79
+ - `type`: one of `entry-point`, `module`, `config`, `test`, `script`, `type-def`, `style`, `template`, `data`
80
+
81
+ Coverage: target the most important 50-100 files. Skip generated code, test files (unless they reveal architecture), `node_modules/dist/build`.
82
+
83
+ ## `apis.json`
84
+
85
+ ```json
86
+ {
87
+ "_meta": { "updated_at": "...", "version": 1 },
88
+ "entries": {
89
+ "GET /api/users": {
90
+ "method": "GET",
91
+ "path": "/api/users",
92
+ "params": ["page", "limit"],
93
+ "file": "src/routes/users.ts",
94
+ "description": "List users with pagination"
95
+ },
96
+ "CLI: dw-init": {
97
+ "method": "CLI",
98
+ "path": "dev-workflow init",
99
+ "params": ["--lang", "--force"],
100
+ "file": "bin/dev-workflow.js",
101
+ "description": "Scaffold .dw/ structure into a project"
102
+ }
103
+ }
104
+ }
105
+ ```
106
+
107
+ Field rules:
108
+ - Key format: `"<METHOD> <PATH>"` for HTTP, `"CLI: <command>"` for CLI, `"GraphQL: <operation>"`, `"Handler: <event>"`, etc.
109
+ - `method`: HTTP verb, or `"CLI"`, `"GraphQL"`, `"gRPC"`, `"Event"`, `"Subscription"`
110
+ - `path`: the route/command/operation name
111
+ - `params`: query/body/CLI flag names — array of strings
112
+ - `file`: source path
113
+ - `description`: one-line summary derived from the handler's first comment or function name
114
+
115
+ If no API surfaces detected, write `{ "_meta": {...}, "entries": {} }` — never omit the file.
116
+
117
+ ## `deps.json`
118
+
119
+ ```json
120
+ {
121
+ "_meta": { "updated_at": "...", "version": 1 },
122
+ "entries": {
123
+ "express": {
124
+ "version": "^4.18.0",
125
+ "type": "production",
126
+ "used_by": ["src/server.ts", "src/routes/users.ts"],
127
+ "invocation": "require"
128
+ },
129
+ "vitest": {
130
+ "version": "^2.0.0",
131
+ "type": "development",
132
+ "used_by": ["package.json#test"],
133
+ "invocation": "npm test"
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
139
+ Field rules:
140
+ - Key: package name (npm), distribution name (PyPI), package id (NuGet), crate name (crates.io)
141
+ - `version`: semver range from manifest
142
+ - `type`: `production` | `development` | `peer` | `optional`
143
+ - `used_by`: array of file paths that import the dep (verified by Grep) OR npm-script keys for tooling deps
144
+ - `invocation`:
145
+ - `require` if directly imported in code
146
+ - npm script command (`npm run lint`, `npm test`) if exercised via script
147
+ - `implicit` if a runtime/framework dep that's not directly imported (e.g., `react-dom` in a Next.js project)
148
+
149
+ ## `arch.md`
150
+
151
+ ```markdown
152
+ ---
153
+ updated_at: "2026-05-06T12:34:56.789Z"
154
+ ---
155
+
156
+ ## Architecture Overview
157
+
158
+ The project follows a layered architecture: HTTP routes → application services → repository layer → ORM → database.
159
+
160
+ ## Key Components
161
+
162
+ | Component | Path | Responsibility |
163
+ |-----------|------|----------------|
164
+ | Server bootstrap | `src/server.ts` | Express app initialization + middleware wiring |
165
+ | Route handlers | `src/routes/` | HTTP request validation and response shaping |
166
+ | Application services | `src/services/` | Business logic, orchestration |
167
+ | Repositories | `src/repositories/` | Data access via Prisma |
168
+ | Schemas | `src/schemas/` | Zod validation schemas, shared with frontend |
169
+
170
+ ## Data Flow
171
+
172
+ `HTTP request` → `route handler (validates with Zod)` → `service` → `repository (Prisma)` → `Postgres` → response
173
+
174
+ ## Conventions
175
+
176
+ - File naming: kebab-case (`user-routes.ts`, `order-service.ts`)
177
+ - Function naming: camelCase, verb-first (`createOrder`, `findUserById`)
178
+ - Tests: co-located, `.test.ts` suffix
179
+ - Imports: absolute via `@/` alias for cross-module, relative for sibling files
180
+ ```
181
+
182
+ ## `.last-refresh.json`
183
+
184
+ ```json
185
+ {
186
+ "updated_at": "2026-05-06T12:34:56.789Z",
187
+ "files": {
188
+ "stack.json": "a3c8b1...",
189
+ "files.json": "f9e2d7...",
190
+ "apis.json": "1b4f8a...",
191
+ "deps.json": "5c2e6b...",
192
+ "arch.md": "9d7c3e..."
193
+ }
194
+ }
195
+ ```
196
+
197
+ Hashes are SHA-256 of file contents at the moment of refresh. Used by `/dw-map-codebase` to detect drift on the next run and decide whether a partial update is enough.
198
+
199
+ ## Validation rules
200
+
201
+ When `intel-updater` finishes, all 5 files MUST satisfy:
202
+
203
+ 1. Valid JSON (parseable)
204
+ 2. `_meta.updated_at` is ISO-8601
205
+ 3. `_meta.version` is a positive integer
206
+ 4. All file paths in `files.json`, `apis.json`, `deps.json` exist on disk (or were excluded for known reasons)
207
+ 5. `exports` arrays contain only actual symbols (no descriptions, no spaces in entries)
208
+ 6. No secrets/credentials/tokens in any file
@@ -0,0 +1,148 @@
1
+ # Query patterns — how `/dw-intel` answers different question shapes
2
+
3
+ `/dw-intel "<query>"` reads `.dw/intel/` and returns structured answers with file paths cited. This file describes how the command maps natural-language queries to which intel files to read.
4
+
5
+ ## Query shape detection
6
+
7
+ The command classifies the query into one of these shapes before searching:
8
+
9
+ | Shape | Example queries | Primary file | Secondary files |
10
+ |-------|-----------------|--------------|-----------------|
11
+ | **where-is** | "where is the user routes file?", "where is auth defined?" | `files.json` | `apis.json` |
12
+ | **what-uses** | "what uses express?", "where is the redis client called?" | `deps.json` (for libs), `files.json` (for symbols) | grep fallback |
13
+ | **architecture-of** | "what's the architecture?", "how is data flow structured?" | `arch.md` | `stack.json` |
14
+ | **stack** | "what frameworks?", "is this typescript or javascript?" | `stack.json` | — |
15
+ | **dep-info** | "which version of react?", "what's prisma used for here?" | `deps.json` | — |
16
+ | **api-list** | "list endpoints", "what routes exist?" | `apis.json` | — |
17
+ | **find-export** | "where is `createServer` exported from?", "find the `userSchema` symbol" | `files.json` (search `exports` arrays) | grep fallback |
18
+ | **convention** | "what's the file naming convention?", "are tests co-located?" | `arch.md` | `.dw/rules/` if available |
19
+
20
+ ## Match algorithm
21
+
22
+ For each shape, the command:
23
+
24
+ 1. **Tokenize** the query into keywords (drop stopwords).
25
+ 2. **Search the primary file** for matches:
26
+ - JSON files: case-insensitive substring match in keys + descriptions
27
+ - `arch.md`: case-insensitive full-text search
28
+ 3. **Rank** matches by:
29
+ - Exact symbol match > substring match > description match
30
+ - Direct deps > indirect (transitive) deps
31
+ 4. **Return** top 3-5 matches with file paths cited.
32
+
33
+ If primary file yields zero matches, fall back to secondary files. If still zero, fall back to direct grep over the project (slower but exhaustive).
34
+
35
+ ## Examples
36
+
37
+ ### Query: "where is auth defined?"
38
+
39
+ **Shape:** where-is
40
+
41
+ **Process:**
42
+ 1. Search `files.json` for keys containing `auth` → finds `src/auth/index.ts`, `src/middleware/auth.ts`, `src/routes/auth.ts`
43
+ 2. Search `apis.json` for paths containing `auth` → finds `POST /api/auth/login`, `POST /api/auth/logout`
44
+ 3. Return top files + endpoints with paths
45
+
46
+ **Output:**
47
+ ```
48
+ Auth is defined across 3 files and exposes 2 endpoints:
49
+
50
+ Files:
51
+ - src/auth/index.ts (entry-point) — exports: configureAuth, AuthError
52
+ - src/middleware/auth.ts (module) — exports: requireAuth, optionalAuth
53
+ - src/routes/auth.ts (module) — exports: authRouter
54
+
55
+ Endpoints:
56
+ - POST /api/auth/login (file: src/routes/auth.ts) — Authenticate user
57
+ - POST /api/auth/logout (file: src/routes/auth.ts) — Clear session
58
+ ```
59
+
60
+ ### Query: "what uses redis?"
61
+
62
+ **Shape:** what-uses
63
+
64
+ **Process:**
65
+ 1. Search `deps.json` for entry `redis` (or `ioredis`, `redis-py`, etc. depending on stack)
66
+ 2. Read its `used_by` array
67
+ 3. Cross-reference with `files.json` to enrich (which files have this dep imported and what they do)
68
+
69
+ **Output:**
70
+ ```
71
+ Redis (ioredis@^5.3.0, production) is used by 3 files:
72
+
73
+ - src/cache/index.ts — exports: cacheGet, cacheSet, cacheDel
74
+ - src/jobs/queue.ts — exports: enqueueJob (uses ioredis as BullMQ backend)
75
+ - src/sessions/store.ts — exports: createSessionStore
76
+ ```
77
+
78
+ ### Query: "what frameworks?"
79
+
80
+ **Shape:** stack
81
+
82
+ **Process:**
83
+ 1. Read `stack.json` directly
84
+ 2. Output the `frameworks` field, with versions if available from `deps.json`
85
+
86
+ **Output:**
87
+ ```
88
+ Frameworks detected:
89
+ - Express (^4.18.0, production)
90
+ - React (^18.2.0, production)
91
+ - Prisma (^5.4.0, production)
92
+
93
+ Build system: npm scripts
94
+ Test framework: Jest
95
+ Package manager: npm
96
+ ```
97
+
98
+ ### Query: "list endpoints"
99
+
100
+ **Shape:** api-list
101
+
102
+ **Process:**
103
+ 1. Read `apis.json`
104
+ 2. Group by tag/prefix (`/api/users`, `/api/orders`, `/api/auth` → User Management, Orders, Auth)
105
+ 3. Output tabular
106
+
107
+ **Output:**
108
+ ```
109
+ 12 endpoints across 3 groups:
110
+
111
+ Auth (2)
112
+ - POST /api/auth/login — Authenticate user
113
+ - POST /api/auth/logout — Clear session
114
+
115
+ Users (5)
116
+ - GET /api/users — List users
117
+ - POST /api/users — Create user
118
+ - GET /api/users/:id — Get user by id
119
+ - PATCH /api/users/:id — Update user
120
+ - DELETE /api/users/:id — Delete user
121
+
122
+ Orders (5) ...
123
+ ```
124
+
125
+ ## Stale-index handling
126
+
127
+ Before answering, check `.dw/intel/.last-refresh.json`:
128
+
129
+ - If `updated_at` is more than 7 days old → prefix the answer with: `⚠ Index last refreshed YYYY-MM-DD (X days ago). Run /dw-map-codebase to refresh.`
130
+ - If `.last-refresh.json` is absent → prefix with: `⚠ No refresh metadata. Index may be stale; run /dw-map-codebase.`
131
+
132
+ Don't refuse to answer — return the best info available, but flag the staleness so the user can decide whether to trust it.
133
+
134
+ ## Fallback path (no `.dw/intel/`)
135
+
136
+ If `.dw/intel/` doesn't exist at all:
137
+
138
+ 1. Check `.dw/rules/` (from `/dw-analyze-project` or `/dw-new-project` seeding)
139
+ 2. If `.dw/rules/index.md` exists, search there for the query keywords
140
+ 3. Otherwise, do a direct `grep -r` over the project source (excluding `node_modules`, `.git`, etc.)
141
+ 4. Suggest at the end: `Tip: run /dw-map-codebase to build a queryable index. Subsequent /dw-intel queries will be much faster.`
142
+
143
+ ## Don't
144
+
145
+ - Don't fabricate paths or symbols not present in the index
146
+ - Don't return "I don't know" without first trying the secondary file and grep fallback
147
+ - Don't ignore stale-index warnings — surface them prominently
148
+ - Don't dump the entire JSON of an intel file as the answer; synthesize and cite paths
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: dw-debug-protocol
3
+ description: Use when investigating a bug — applies stop-the-line discipline plus a six-step triage (reproduce → localize → reduce → fix root cause → guard → verify) so you fix what's actually broken instead of papering over symptoms.
4
+ ---
5
+
6
+ # Debug Protocol
7
+
8
+ > **Inspired by** [`addyosmani/agent-skills/debugging-and-error-recovery`](https://github.com/addyosmani/agent-skills/tree/main/debugging-and-error-recovery) (MIT). Patterns and stop-the-line philosophy adapted from Addy Osmani's work; specific guidance and references rewritten to fit dev-workflow's bugfix and QA loops.
9
+
10
+ The fastest path through a bug is the disciplined one. This skill encodes the discipline.
11
+
12
+ ## When this skill applies
13
+
14
+ - Any failing test, runtime error, or "it works locally but not in CI" report.
15
+ - Reproducing a user-reported issue.
16
+ - A regression after a refactor or dependency bump.
17
+ - An intermittent / non-reproducible bug (see `references/non-reproducible-strategy.md`).
18
+
19
+ If you're tempted to "just try a fix and see," stop. Run the protocol below first.
20
+
21
+ ## The four core rules
22
+
23
+ ### 1. Stop the line
24
+
25
+ The moment a bug is confirmed, stop adjacent work. Do not pile features on top of broken state. Branches stay frozen until the bug is reproduced and a fix path is identified — *or* explicitly downgraded ("not blocking, scheduled for later").
26
+
27
+ See `references/stop-the-line.md` for when this rule bends.
28
+
29
+ ### 2. Reproduce before fixing
30
+
31
+ Without a deterministic reproduction, you cannot know whether your "fix" worked. The reproduction is the hypothesis test. Even a flaky bug needs a *reproducible-enough* test (e.g., "fails 8/10 runs") before fixing.
32
+
33
+ If you cannot reproduce: see `references/non-reproducible-strategy.md`. Don't fix on guess.
34
+
35
+ ### 3. Find the root cause, not the nearest cause
36
+
37
+ The first place the stack trace lights up is rarely where the bug LIVES. The bug lives wherever the invariant was violated. Fixing the symptom (e.g., catching a `null` you shouldn't have produced) hides the real issue and makes the next bug worse.
38
+
39
+ ### 4. Guard against recurrence before declaring done
40
+
41
+ Every fix produces an artifact: a regression test that proves the bug exists, then proves it's fixed. Without this artifact, the bug WILL come back during the next refactor.
42
+
43
+ ## The six-step triage
44
+
45
+ Each bug runs through these six steps, in order. See `references/six-step-triage.md` for detail.
46
+
47
+ | Step | Question | Output |
48
+ |------|----------|--------|
49
+ | 1. Reproduce | Can I trigger this on demand? | A failing test or repro script |
50
+ | 2. Localize | Where does the invariant break? | A file:line where state goes wrong |
51
+ | 3. Reduce | What's the smallest input that triggers it? | Minimal repro (1-3 lines if possible) |
52
+ | 4. Fix root cause | Why is the invariant violated? Fix THAT. | Code change at the cause, not the symptom |
53
+ | 5. Guard | What test would have caught this? | Regression test added to suite |
54
+ | 6. Verify end-to-end | Does the original report scenario now pass? | Manual or scripted E2E proof |
55
+
56
+ Do not skip steps. Skipping reduce → bigger fix than needed. Skipping guard → repeat bug in 3 weeks.
57
+
58
+ ## Error categorization
59
+
60
+ Bugs cluster into a small number of categories. Knowing the category narrows where to look — see `references/error-categorization.md`:
61
+
62
+ | Category | Typical symptom | Where to look first |
63
+ |----------|-----------------|---------------------|
64
+ | UI / render | Wrong pixels, missing element, click does nothing | Component tree, prop flow, conditional render |
65
+ | Network / I/O | Timeout, 500, partial data | Request payload, headers, error path, retry |
66
+ | State / data | Wrong value displayed, stale read | State management, cache invalidation, race |
67
+ | Concurrency | "Sometimes fails", deadlock | Async order, locks, await placement |
68
+ | Configuration | Works dev, fails prod | Env vars, secrets, build flags, infra config |
69
+ | Logic | Branch returns wrong result | Guard conditions, off-by-one, boolean polarity |
70
+
71
+ ## Non-reproducible bugs
72
+
73
+ Some bugs only happen in production, only on certain users, only at certain times. Don't fix them on intuition. The protocol in `references/non-reproducible-strategy.md` covers:
74
+
75
+ - Timing/race conditions: instrument with logs first, fix second
76
+ - Environment-specific: bisect by environment delta
77
+ - State-dependent: capture user state at moment of failure
78
+ - Frequency-dependent: deploy logging, wait for next occurrence
79
+
80
+ A "fix" for an unreproduced bug is a guess. Mark it as such in the commit message.
81
+
82
+ ## Verification before declaring done
83
+
84
+ A bug is fixed when:
85
+
86
+ 1. The repro from step 1 now passes.
87
+ 2. The regression test from step 5 was committed.
88
+ 3. Lint + tests + build are all GREEN.
89
+ 4. The original report scenario (E2E) was verified — by you, or with a screenshot/log/run trace if not directly reproducible.
90
+
91
+ If any are missing, the bug is "fixed pending verification," not "fixed."
92
+
93
+ ## Integration with dev-workflow commands
94
+
95
+ - `/dw-bugfix` runs this skill end-to-end. The bug report is decomposed into steps 1-6 and progressed atomically.
96
+ - `/dw-fix-qa` uses this skill when QA findings are bug-shaped (failing scenario rather than missing feature). Each finding becomes a six-step run.
97
+ - `/dw-code-review` flags fixes that skipped step 5 (no regression test) as REJECTED.
98
+
99
+ ## When to escalate / pair
100
+
101
+ After 60 minutes stuck at step 2 (localize) or step 4 (root cause), surface the situation to the user:
102
+
103
+ - "I've exhausted hypotheses A/B/C; here's what I tried and what's left."
104
+ - Don't silently spin. Fresh eyes find what stuck eyes miss.
105
+
106
+ This is not failure — it's protocol. Stuck > 1 hour is a signal, not a flaw.
@@ -0,0 +1,127 @@
1
+ # Error categorization — symptom → cause matrix
2
+
3
+ Before debugging, classify the bug. Wrong category = wasted hours. Most bugs sit in one of six categories; each has a typical hunting ground.
4
+
5
+ ## The six categories
6
+
7
+ ### 1. UI / rendering
8
+
9
+ **Symptoms:** Wrong pixels, missing element, click does nothing, layout shift, hydration mismatch.
10
+
11
+ **Hunting ground:**
12
+ - Component tree: prop flow from root to leaf.
13
+ - Conditional render guards: `{cond && <Foo />}` where `cond` is unexpectedly false (or truthy when 0).
14
+ - CSS specificity / cascade collisions.
15
+ - Server vs client mismatch (Next.js, hydration).
16
+ - Event handler binding (lost `this`, stale closure capturing old state).
17
+
18
+ **First check:** Open browser devtools → Elements panel → confirm the element exists in DOM. If yes, problem is CSS/layout. If no, problem is render path.
19
+
20
+ **Often misclassified as:** State bug. Check the prop value at render time before chasing state.
21
+
22
+ ### 2. Network / I/O
23
+
24
+ **Symptoms:** Timeout, 5xx response, partial data, "loading forever," CORS error.
25
+
26
+ **Hunting ground:**
27
+ - Request payload (DevTools Network tab → check what was actually sent).
28
+ - Auth headers / cookies (missing, expired, wrong domain).
29
+ - Server-side error (check the API logs, not just the client's view).
30
+ - Retry/timeout configuration (too short = flaky; too long = perceived hang).
31
+ - Idempotency: request retried in a way the server treated as new.
32
+
33
+ **First check:** Reproduce in DevTools Network tab. Copy as cURL → run from terminal. If terminal request works, client config is wrong. If terminal also fails, server is wrong.
34
+
35
+ **Often misclassified as:** Logic bug. Verify the request actually went out before assuming bug is in the response handler.
36
+
37
+ ### 3. State / data
38
+
39
+ **Symptoms:** Wrong value displayed, stale read, "I updated it but it didn't change," off-by-one in collections.
40
+
41
+ **Hunting ground:**
42
+ - State management: where is the source of truth? How is it updated?
43
+ - Cache invalidation: did the cache layer return stale data?
44
+ - Race condition: did two updates arrive out of order?
45
+ - Mutation vs replacement: did a deep mutation fail to trigger a re-render?
46
+ - Derived state: is a computed value re-running when it should, or memoized too aggressively?
47
+
48
+ **First check:** Log the state at three points — when it's set, when it's read, when it's rendered. The discrepancy reveals the layer with the bug.
49
+
50
+ **Often misclassified as:** UI bug. The pixel is wrong because the data is wrong; fix the data.
51
+
52
+ ### 4. Concurrency
53
+
54
+ **Symptoms:** "Sometimes fails," deadlock, race ("works locally, fails in CI"), out-of-order writes, lost update.
55
+
56
+ **Hunting ground:**
57
+ - Async boundaries: missed `await`, dangling promise, fire-and-forget that needed completion.
58
+ - Locking: missing lock, lock held too long, lock granularity wrong.
59
+ - Order assumptions: code assumes A finishes before B without enforcing it.
60
+ - Test isolation: shared state between tests creating false dependency.
61
+
62
+ **First check:** Add timing logs. If the bug rate changes when you add `setTimeout(0)` or `process.nextTick`, it's a concurrency bug.
63
+
64
+ **Diagnostic patterns:**
65
+ - Sleep-and-check: the bug disappears if you add 100ms delay → ordering issue.
66
+ - Always-fails-on-fast-machine: missed async wait.
67
+ - Always-fails-on-slow-machine: timeout too tight.
68
+ - Fails 1/N runs: race condition; the rate gives clues to the window.
69
+
70
+ **Often misclassified as:** "Just flaky, ignore." Concurrency bugs always have a cause. Re-running until green is hiding, not fixing.
71
+
72
+ ### 5. Configuration
73
+
74
+ **Symptoms:** "Works in dev, fails in prod," "works on my machine," sudden behavior change after deploy.
75
+
76
+ **Hunting ground:**
77
+ - Environment variables: present? right value? expected name? leading/trailing whitespace?
78
+ - Feature flags: toggled differently between environments?
79
+ - Build flags: dev mode strips assertions; prod might not include polyfills.
80
+ - Infra: different DB version, different Node version, different network topology.
81
+ - Secrets: rotated, expired, wrong key.
82
+
83
+ **First check:** Print the environment at startup (sans secrets) → diff dev vs prod. The diff often contains the bug.
84
+
85
+ **Diagnostic command:** `env | sort` (or equivalent) at app entry, in both environments. Compare.
86
+
87
+ **Often misclassified as:** Logic bug. The code is correct; the configuration is wrong.
88
+
89
+ ### 6. Logic
90
+
91
+ **Symptoms:** Branch returns wrong result given correct input, incorrect calculation, off-by-one in iteration.
92
+
93
+ **Hunting ground:**
94
+ - Guard conditions: `>=` vs `>`, `&&` vs `||`, negation polarity.
95
+ - Edge cases: empty array, single element, very large input, exact boundary value.
96
+ - Type coercion: `"0"` is truthy in JS; `0 == false` but `0 !== false`.
97
+ - Default values: a missing field falls back to `undefined`, not zero.
98
+ - Floating point: `0.1 + 0.2 !== 0.3`.
99
+
100
+ **First check:** Manually trace the function with the failing input. Often the bug is visible at line 3 of the function.
101
+
102
+ **Often misclassified as:** State bug. The state is correct; the function uses it wrong.
103
+
104
+ ## Multi-category bugs
105
+
106
+ Some bugs span categories. The clue: fixing only one category fixes the test but not production.
107
+
108
+ Example: "Prod login fails."
109
+ - Network: auth API returns 401 (real).
110
+ - Configuration: prod has rotated secret; staging didn't.
111
+ - State: client retains stale token in localStorage from before rotation.
112
+
113
+ Fix all three or the bug returns next rotation.
114
+
115
+ ## Diagnostic shortcut: where did it last work?
116
+
117
+ If the bug is new (not always existed):
118
+
119
+ 1. `git log` the affected files. What changed in the last 7 days?
120
+ 2. `git bisect` if the regression window is wide.
121
+ 3. Look at infra / dep / config changes (often the cause is outside source code).
122
+
123
+ If the bug always existed:
124
+
125
+ 1. It's likely an edge case the original author didn't consider.
126
+ 2. Check the test fixtures — they probably hit the happy path only.
127
+ 3. Add the failing case to the test fixtures BEFORE fixing.