@minko-ai/minko 0.1.0 → 0.1.1

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 (189) hide show
  1. package/README.md +577 -2
  2. package/assets/mascot-preview.png +0 -0
  3. package/assets/mascot-preview.txt +46 -0
  4. package/assets/mascot-source.png +0 -0
  5. package/assets/skills/README.md +21 -0
  6. package/assets/skills/brainstorming/LICENSE +21 -0
  7. package/assets/skills/brainstorming/SKILL.md +316 -0
  8. package/assets/skills/buddhist-method/LICENSE +21 -0
  9. package/assets/skills/buddhist-method/SKILL.md +137 -0
  10. package/assets/skills/buddhist-method/references/ariyasacca-debug.md +57 -0
  11. package/assets/skills/buddhist-method/references/extended-principles.md +100 -0
  12. package/assets/skills/code-humanizer/LICENSE +21 -0
  13. package/assets/skills/code-humanizer/SKILL.md +174 -0
  14. package/assets/skills/code-review/LICENSE +21 -0
  15. package/assets/skills/code-review/SKILL.md +232 -0
  16. package/assets/skills/code-review/reference/angular.md +768 -0
  17. package/assets/skills/code-review/reference/architecture-review-guide.md +472 -0
  18. package/assets/skills/code-review/reference/c.md +890 -0
  19. package/assets/skills/code-review/reference/code-quality-universal.md +488 -0
  20. package/assets/skills/code-review/reference/code-review-best-practices.md +136 -0
  21. package/assets/skills/code-review/reference/common-bugs-checklist.md +302 -0
  22. package/assets/skills/code-review/reference/cpp.md +893 -0
  23. package/assets/skills/code-review/reference/cross-cutting/async-concurrency-patterns.md +515 -0
  24. package/assets/skills/code-review/reference/cross-cutting/error-handling-principles.md +492 -0
  25. package/assets/skills/code-review/reference/cross-cutting/n-plus-one-queries.md +309 -0
  26. package/assets/skills/code-review/reference/cross-cutting/sql-injection-prevention.md +308 -0
  27. package/assets/skills/code-review/reference/cross-cutting/xss-prevention.md +264 -0
  28. package/assets/skills/code-review/reference/csharp.md +525 -0
  29. package/assets/skills/code-review/reference/css-less-sass.md +661 -0
  30. package/assets/skills/code-review/reference/dart.md +670 -0
  31. package/assets/skills/code-review/reference/django.md +985 -0
  32. package/assets/skills/code-review/reference/fastapi.md +580 -0
  33. package/assets/skills/code-review/reference/go.md +993 -0
  34. package/assets/skills/code-review/reference/java.md +409 -0
  35. package/assets/skills/code-review/reference/java8.md +586 -0
  36. package/assets/skills/code-review/reference/kotlin.md +1018 -0
  37. package/assets/skills/code-review/reference/nestjs.md +593 -0
  38. package/assets/skills/code-review/reference/performance-review-guide.md +816 -0
  39. package/assets/skills/code-review/reference/php.md +684 -0
  40. package/assets/skills/code-review/reference/python.md +1073 -0
  41. package/assets/skills/code-review/reference/qt.md +757 -0
  42. package/assets/skills/code-review/reference/react.md +871 -0
  43. package/assets/skills/code-review/reference/ruby.md +964 -0
  44. package/assets/skills/code-review/reference/rust.md +846 -0
  45. package/assets/skills/code-review/reference/security-review-guide.md +494 -0
  46. package/assets/skills/code-review/reference/svelte.md +1064 -0
  47. package/assets/skills/code-review/reference/swift.md +936 -0
  48. package/assets/skills/code-review/reference/typescript.md +1016 -0
  49. package/assets/skills/code-review/reference/vue.md +924 -0
  50. package/assets/skills/code-review/reference/zig.md +440 -0
  51. package/assets/skills/cyclomatic-complexity/LICENSE +201 -0
  52. package/assets/skills/cyclomatic-complexity/SKILL.md +69 -0
  53. package/assets/skills/five-whys/LICENSE +21 -0
  54. package/assets/skills/five-whys/SKILL.md +247 -0
  55. package/assets/skills/five-whys/examples/performance-regression.md +161 -0
  56. package/assets/skills/five-whys/examples/production-incident.md +134 -0
  57. package/assets/skills/five-whys/references/software-patterns.md +284 -0
  58. package/assets/skills/five-whys/references/toyota-origins.md +257 -0
  59. package/assets/skills/systematic-debugging/LICENSE +21 -0
  60. package/assets/skills/systematic-debugging/SKILL.md +283 -0
  61. package/assets/skills/test-driven-development/LICENSE +21 -0
  62. package/assets/skills/test-driven-development/SKILL.md +330 -0
  63. package/assets/skills/verification-before-completion/LICENSE +21 -0
  64. package/assets/skills/verification-before-completion/SKILL.md +120 -0
  65. package/assets/skills/vibe-sec/LICENSE +201 -0
  66. package/assets/skills/vibe-sec/SKILL.md +758 -0
  67. package/assets/skills/writing-plans/LICENSE +21 -0
  68. package/assets/skills/writing-plans/SKILL.md +204 -0
  69. package/bin/minko.js +2 -2
  70. package/dist/agent/approvalTokens.js +224 -0
  71. package/dist/agent/branchLock.js +315 -0
  72. package/dist/agent/compact.js +182 -0
  73. package/dist/agent/context.js +183 -0
  74. package/dist/agent/cron.js +326 -0
  75. package/dist/agent/hooks.js +211 -0
  76. package/dist/agent/lanes.js +511 -0
  77. package/dist/agent/loop.js +337 -0
  78. package/dist/agent/memory.js +159 -0
  79. package/dist/agent/permissions.js +71 -0
  80. package/dist/agent/plan.js +118 -0
  81. package/dist/agent/prompt.js +120 -0
  82. package/dist/agent/subagent.js +67 -0
  83. package/dist/agent/tasks.js +449 -0
  84. package/dist/agent/transcript.js +62 -0
  85. package/dist/agent/workerStore.js +172 -0
  86. package/dist/agent/workerTypes.js +1 -0
  87. package/dist/agent/workers.js +503 -0
  88. package/dist/cli/app.js +261 -0
  89. package/dist/cli/argv.js +206 -0
  90. package/dist/cli/commandsCommand.js +12 -0
  91. package/dist/cli/configCommand.js +170 -0
  92. package/dist/cli/doctorCommand.js +112 -0
  93. package/dist/cli/exportCommand.js +85 -0
  94. package/dist/cli/forkCommand.js +24 -0
  95. package/dist/cli/linkCommand.js +272 -0
  96. package/dist/cli/loginCommand.js +69 -0
  97. package/dist/cli/mcpLoginCommand.js +68 -0
  98. package/dist/cli/pluginCommand.js +113 -0
  99. package/dist/cli/powerCommand.js +174 -0
  100. package/dist/cli/promptFooter.js +74 -0
  101. package/dist/cli/relayCommand.js +38 -0
  102. package/dist/cli/sandboxCommand.js +31 -0
  103. package/dist/cli/serveCommand.js +104 -0
  104. package/dist/cli/statusCommand.js +120 -0
  105. package/dist/cli/tui.js +1104 -0
  106. package/dist/commands/registry.js +99 -0
  107. package/dist/config/paths.js +81 -0
  108. package/dist/config/store.js +605 -0
  109. package/dist/index.js +199 -0
  110. package/dist/link/protocol.js +159 -0
  111. package/dist/link/relay.js +184 -0
  112. package/dist/link/server.js +566 -0
  113. package/dist/link/tunnel.js +90 -0
  114. package/dist/lsp/client.js +340 -0
  115. package/dist/lsp/tool.js +177 -0
  116. package/dist/mcp/client.js +469 -0
  117. package/dist/mcp/httpClient.js +191 -0
  118. package/dist/mcp/server.js +206 -0
  119. package/dist/mcp/tools.js +173 -0
  120. package/dist/oauth/device.js +111 -0
  121. package/dist/oauth/store.js +56 -0
  122. package/dist/plugins/loader.js +291 -0
  123. package/dist/plugins/market.js +98 -0
  124. package/dist/providers/anthropic.js +279 -0
  125. package/dist/providers/factory.js +109 -0
  126. package/dist/providers/openai.js +182 -0
  127. package/dist/providers/retry.js +95 -0
  128. package/dist/providers/sse.js +67 -0
  129. package/dist/providers/types.js +10 -0
  130. package/dist/rag/embeddings.js +171 -0
  131. package/dist/rag/index.js +373 -0
  132. package/dist/rag/server.js +167 -0
  133. package/dist/rag/tool.js +148 -0
  134. package/dist/sandbox/index.js +55 -0
  135. package/dist/sdk/server.js +150 -0
  136. package/dist/sdk/session.js +104 -0
  137. package/dist/session/liveness.js +148 -0
  138. package/dist/session/recorder.js +49 -0
  139. package/dist/session/store.js +171 -0
  140. package/dist/skills/index.js +428 -0
  141. package/dist/theme.js +30 -0
  142. package/dist/tools/fs.js +195 -0
  143. package/dist/tools/notebook.js +109 -0
  144. package/dist/tools/registry.js +32 -0
  145. package/dist/tools/search.js +130 -0
  146. package/dist/tools/shell.js +200 -0
  147. package/dist/tools/structured.js +83 -0
  148. package/dist/tools/types.js +1 -0
  149. package/dist/ui/ansi.js +135 -0
  150. package/dist/ui/banner.js +103 -0
  151. package/dist/ui/input.js +49 -0
  152. package/dist/ui/inputModel.js +113 -0
  153. package/dist/ui/keyboard.js +142 -0
  154. package/dist/ui/mascot.js +34 -0
  155. package/dist/ui/mascotData.js +96 -0
  156. package/dist/ui/md.js +183 -0
  157. package/dist/ui/screen.js +49 -0
  158. package/dist/ui/spinner.js +52 -0
  159. package/dist/ui/transcript.js +287 -0
  160. package/dist/util/clipboard.js +53 -0
  161. package/dist/util/errors.js +50 -0
  162. package/dist/util/version.js +12 -0
  163. package/dist/web/fetch.js +168 -0
  164. package/dist/web/search.js +97 -0
  165. package/package.json +45 -36
  166. package/src/agent/loop.ts +0 -159
  167. package/src/agent/prompt.ts +0 -45
  168. package/src/cli/app.ts +0 -396
  169. package/src/cli/argv.ts +0 -139
  170. package/src/cli/configCommand.ts +0 -175
  171. package/src/config/paths.ts +0 -20
  172. package/src/config/store.ts +0 -149
  173. package/src/index.ts +0 -120
  174. package/src/providers/anthropic.ts +0 -215
  175. package/src/providers/openai.ts +0 -158
  176. package/src/providers/sse.ts +0 -57
  177. package/src/providers/types.ts +0 -59
  178. package/src/session/store.ts +0 -125
  179. package/src/theme.ts +0 -41
  180. package/src/tools/fs.ts +0 -143
  181. package/src/tools/registry.ts +0 -19
  182. package/src/tools/shell.ts +0 -120
  183. package/src/tools/types.ts +0 -26
  184. package/src/ui/ansi.ts +0 -110
  185. package/src/ui/banner.ts +0 -39
  186. package/src/ui/input.ts +0 -54
  187. package/src/ui/md.ts +0 -160
  188. package/src/ui/spinner.ts +0 -58
  189. package/src/util/errors.ts +0 -48
@@ -0,0 +1,69 @@
1
+ ---
2
+ name: cyclomatic-complexity
3
+ description: Refactor code to reduce cyclomatic complexity so it stays readable, maintainable, and aligned with the long-term vision of the codebase, not just optimized for AI comprehension. Use whenever the user asks to refactor, simplify, clean up, or review code quality; mentions complexity, maintainability, readability, spaghetti code, deeply nested logic, or god functions; or asks to check AI-generated code before merging. Also use proactively after writing any nontrivial function with heavy branching.
4
+ ---
5
+
6
+ # Cyclomatic Complexity
7
+
8
+ Purpose: AI-written code often works but branches like a jungle. This skill: measure complexity, refactor hotspots, keep code human-maintainable.
9
+
10
+ ## Measure first
11
+
12
+ CC = decision points + 1. Decision points: `if`, `else if`, `case`, loops, `catch`, ternary, `&&`, `||` in conditions.
13
+
14
+ Project linter config wins. If eslintrc, radon config, sonar config, or similar sets a complexity threshold, use that. No config: use defaults below.
15
+
16
+ Thresholds:
17
+ - 1-5: fine, leave alone
18
+ - 6-10: watch, refactor if touching anyway
19
+ - 11-15: refactor now
20
+ - 15+: must split, no debate
21
+
22
+ Prefer real tools over eyeballing when environment allows:
23
+ - Python: `radon cc -s -a <path>`
24
+ - JS/TS: eslint `complexity` rule
25
+ - Go: `gocyclo`
26
+ - Polyglot: `lizard <path>`
27
+
28
+ No tool available: count manually, per function, show the count.
29
+
30
+ ## Refactor tactics, in order of preference
31
+
32
+ 1. **Guard clauses.** Invert conditions, return early, kill nesting.
33
+ 2. **Extract function.** Each extracted piece gets a name that says what, not how. Names are documentation.
34
+ 3. **Lookup table / map** instead of if-else or switch chains.
35
+ 4. **Named predicates.** `if (isEligibleForRefund(order))` beats a 4-clause boolean soup.
36
+ 5. **Polymorphism / strategy** for switch-on-type. Only when the switch appears in 2+ places.
37
+ 6. **Flatten loops.** Extract loop body, use continue instead of nested if.
38
+
39
+ ## Hard rules
40
+
41
+ - Preserve behavior. Run tests before and after. No tests: say so, suggest adding, refactor conservatively.
42
+ - Don't game the metric. A dense one-liner hiding 6 branches is worse than the honest if-chain it replaced. Complexity should move into well-named units, not disappear into cleverness.
43
+ - Don't break public APIs or exported signatures without asking.
44
+ - Small functions with clear names > few functions with comments explaining sections.
45
+ - One responsibility per function. If the name needs "and", split.
46
+
47
+ ## Workflow
48
+
49
+ 1. Measure all touched functions, rank by CC descending.
50
+ 2. Report hotspots with numbers before touching anything.
51
+ 3. Refactor worst first, one function at a time.
52
+ 4. Re-measure. Show before/after table: function, CC before, CC after.
53
+ 5. Verify: tests pass, behavior unchanged, diff reviewable.
54
+
55
+ ## Output format
56
+
57
+ End every refactor with:
58
+
59
+ ```
60
+ ## Complexity report
61
+ | Function | Before | After |
62
+ |----------|--------|-------|
63
+ | parseOrder | 14 | 4 |
64
+
65
+ Extracted: validateHeader, resolveDiscount
66
+ Behavior verified: <how>
67
+ ```
68
+
69
+ Keep prose minimal. Numbers and diffs do the talking.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,247 @@
1
+ ---
2
+ name: five-whys
3
+ description: This skill should be used when the user asks to "find the root cause", "找根因", "为什么会出现这个问题", "why did this happen", "debug this issue", "排查问题", "analyze this bug", "分析这个bug", "what's causing this", "问题出在哪", "dig deeper", "深挖原因", or needs to systematically trace a problem back to its fundamental cause rather than just addressing symptoms.
4
+ version: 0.1.0
5
+ ---
6
+
7
+ # 5-Whys Root Cause Analysis
8
+
9
+ A systematic technique for drilling down through symptoms to uncover the true root cause of a problem by repeatedly asking "Why?" until the fundamental issue is revealed.
10
+
11
+ ## When to Use This Skill
12
+
13
+ - Bug investigation where the obvious fix didn't work
14
+ - Production incidents requiring post-mortem analysis
15
+ - Performance problems with unclear origins
16
+ - Recurring issues that keep coming back after "fixes"
17
+ - System failures requiring prevention, not just recovery
18
+ - Any situation where treating symptoms isn't enough
19
+
20
+ ## Core Process
21
+
22
+ ### Phase 1: Define the Problem Clearly
23
+
24
+ State the problem as a specific, observable fact:
25
+
26
+ **Good problem statements:**
27
+ - "The API response time increased from 50ms to 500ms"
28
+ - "Users are seeing 500 errors on the checkout page"
29
+ - "The nightly job failed at 3:00 AM"
30
+
31
+ **Poor problem statements:**
32
+ - "The system is slow" (too vague)
33
+ - "Something is broken" (not specific)
34
+ - "Users are unhappy" (symptom, not problem)
35
+
36
+ **Problem Statement Template:**
37
+ ```
38
+ What: [Specific observable behavior]
39
+ When: [Time/conditions when it occurs]
40
+ Where: [Component/system affected]
41
+ Impact: [Measurable consequence]
42
+ ```
43
+
44
+ ### Phase 2: Ask "Why?" Iteratively
45
+
46
+ For each answer, ask "Why does that happen?" until reaching an actionable root cause:
47
+
48
+ **The 5-Whys Chain:**
49
+ ```
50
+ Problem: [Statement]
51
+ ↓
52
+ Why 1: [First-level cause]
53
+ ↓
54
+ Why 2: [Deeper cause]
55
+ ↓
56
+ Why 3: [Even deeper]
57
+ ↓
58
+ Why 4: [Approaching root]
59
+ ↓
60
+ Why 5: [Root cause - actionable]
61
+ ```
62
+
63
+ **Quality Checks for Each "Why":**
64
+ - Is this answer factual and verifiable?
65
+ - Does this explain the previous level?
66
+ - Is there evidence supporting this?
67
+ - Could there be multiple causes at this level?
68
+
69
+ ### Phase 3: Identify the Root Cause
70
+
71
+ A true root cause has these characteristics:
72
+
73
+ | Characteristic | Test |
74
+ |----------------|------|
75
+ | **Actionable** | Can we do something about it? |
76
+ | **Preventable** | Would fixing this prevent recurrence? |
77
+ | **Fundamental** | Asking "why" again yields nothing actionable |
78
+ | **Verifiable** | Can we prove this is the cause? |
79
+
80
+ **Stop Conditions:**
81
+ - Reached a process/policy that can be changed
82
+ - Found a missing control or check
83
+ - Identified a knowledge/training gap
84
+ - Discovered a design flaw
85
+ - Hit a resource constraint decision
86
+
87
+ ### Phase 4: Validate the Chain
88
+
89
+ Work backwards through the chain:
90
+
91
+ ```
92
+ If [Root Cause] is fixed
93
+ → Then [Why 4] wouldn't happen
94
+ → Then [Why 3] wouldn't happen
95
+ → Then [Why 2] wouldn't happen
96
+ → Then [Why 1] wouldn't happen
97
+ → Then [Problem] wouldn't occur
98
+ ```
99
+
100
+ If the chain breaks at any point, revisit that level.
101
+
102
+ ### Phase 5: Define Countermeasures
103
+
104
+ For the root cause, define:
105
+
106
+ 1. **Immediate fix** - Stop the bleeding
107
+ 2. **Preventive measure** - Ensure it never happens again
108
+ 3. **Detection mechanism** - Catch it early if prevention fails
109
+
110
+ ## Output Format
111
+
112
+ ```markdown
113
+ ## 5-Whys Analysis: [Problem Title]
114
+
115
+ ### Problem Statement
116
+ **What:** [Specific behavior]
117
+ **When:** [Time/conditions]
118
+ **Where:** [Component]
119
+ **Impact:** [Consequence]
120
+
121
+ ### Why Chain
122
+
123
+ | Level | Question | Answer | Evidence |
124
+ |-------|----------|--------|----------|
125
+ | Why 1 | Why did [problem] occur? | [Answer] | [Evidence] |
126
+ | Why 2 | Why did [Why 1 answer]? | [Answer] | [Evidence] |
127
+ | Why 3 | Why did [Why 2 answer]? | [Answer] | [Evidence] |
128
+ | Why 4 | Why did [Why 3 answer]? | [Answer] | [Evidence] |
129
+ | Why 5 | Why did [Why 4 answer]? | [Answer] | [Evidence] |
130
+
131
+ ### Root Cause
132
+ **Identified cause:** [Statement]
133
+ **Type:** [Process/Design/Knowledge/Resource]
134
+ **Confidence:** [High/Medium/Low]
135
+
136
+ ### Validation
137
+ - [Root cause fixed] → [Why 4 prevented] ✓
138
+ - [Why 4 prevented] → [Why 3 prevented] ✓
139
+ - ... chain validates ...
140
+
141
+ ### Countermeasures
142
+ | Type | Action | Owner | Timeline |
143
+ |------|--------|-------|----------|
144
+ | Immediate | [Action] | [Who] | [When] |
145
+ | Preventive | [Action] | [Who] | [When] |
146
+ | Detection | [Action] | [Who] | [When] |
147
+ ```
148
+
149
+ ## Common Pitfalls
150
+
151
+ ### Pitfall 1: Stopping Too Early
152
+
153
+ **Symptom:** Root cause is still a symptom
154
+ ```
155
+ Problem: Server crashed
156
+ Why 1: Out of memory
157
+ → "Fix: Add more memory" ❌ (Treating symptom)
158
+
159
+ Continue:
160
+ Why 2: Memory leak in service X
161
+ Why 3: Connection pool not releasing connections
162
+ Why 4: Exception handler not closing connections
163
+ Why 5: No finally block in database code
164
+ → Fix: Add proper resource cleanup ✓
165
+ ```
166
+
167
+ ### Pitfall 2: Blame Instead of Cause
168
+
169
+ **Wrong:** "Why? → Developer made a mistake"
170
+ **Right:** "Why? → No code review caught the issue"
171
+ **Even better:** "Why? → No automated test for this case"
172
+
173
+ **Rule:** Focus on process and systems, not individuals.
174
+
175
+ ### Pitfall 3: Single Thread When Multiple Causes Exist
176
+
177
+ Sometimes problems have multiple contributing factors:
178
+
179
+ ```
180
+ Problem: Deployment failed
181
+ ↓
182
+ Why 1: Database migration timed out
183
+ ├─→ Branch A: Why did migration take so long?
184
+ │ └─→ Table lock held too long
185
+ │ └─→ Long-running query
186
+ │ └─→ Missing index
187
+ │
188
+ └─→ Branch B: Why is timeout so short?
189
+ └─→ Default timeout used
190
+ └─→ No deployment-specific config
191
+ ```
192
+
193
+ ### Pitfall 4: Unverified Assumptions
194
+
195
+ Each "why" should be supported by evidence:
196
+
197
+ | Level | Answer | Evidence Required |
198
+ |-------|--------|------------------|
199
+ | Why 1 | "Service crashed" | Logs showing crash |
200
+ | Why 2 | "OOM killed" | dmesg/system logs |
201
+ | Why 3 | "Memory leak" | Heap dump analysis |
202
+ | Why 4 | "Unclosed streams" | Code inspection |
203
+ | Why 5 | "Missing finally" | Git blame |
204
+
205
+ ## Integration with Other Tools
206
+
207
+ | Tool | When to Combine |
208
+ |------|-----------------|
209
+ | **First Principles** | When questioning if the problem definition itself is right |
210
+ | **Hypothesis Testing** | When evidence for a "why" is uncertain |
211
+ | **Pre-mortem** | After fixing, to prevent similar issues |
212
+ | **Trade-off Analysis** | When choosing between countermeasures |
213
+
214
+ ## Boundaries
215
+
216
+ **Will:**
217
+ - Systematically trace problems to root causes
218
+ - Ensure each level is evidence-based
219
+ - Identify actionable countermeasures
220
+ - Handle multi-branch cause trees
221
+
222
+ **Will Not:**
223
+ - Stop at blame ("human error")
224
+ - Accept vague answers without evidence
225
+ - Guarantee exactly 5 levels (might be 3, might be 7)
226
+ - Replace detailed debugging when code inspection is needed
227
+
228
+ ## Quick Reference
229
+
230
+ **The 5-Whys Checklist:**
231
+ - [ ] Problem stated specifically and measurably
232
+ - [ ] Each "why" is factual, not assumed
233
+ - [ ] Evidence supports each level
234
+ - [ ] Root cause is actionable and preventable
235
+ - [ ] Chain validates when traced backwards
236
+ - [ ] Countermeasures address root cause, not symptoms
237
+ - [ ] Process/system focus, not blame
238
+
239
+ ## Additional Resources
240
+
241
+ ### Reference Files
242
+ - **`references/toyota-origins.md`** - History and principles from Toyota Production System
243
+ - **`references/software-patterns.md`** - Common root cause patterns in software
244
+
245
+ ### Example Files
246
+ - **`examples/production-incident.md`** - Complete analysis of a production outage
247
+ - **`examples/performance-regression.md`** - Tracing a performance degradation
@@ -0,0 +1,161 @@
1
+ # Example: Performance Regression - API Latency Increase
2
+
3
+ A 5-Whys analysis tracing a performance degradation to its root cause.
4
+
5
+ ---
6
+
7
+ ## 5-Whys Analysis: Search API Latency Regression
8
+
9
+ ### Problem Statement
10
+
11
+ | Field | Details |
12
+ |-------|---------|
13
+ | **What** | Search API p99 latency increased from 200ms to 800ms |
14
+ | **When** | First observed 2024-02-01, after v2.3.0 deployment |
15
+ | **Where** | search-service, all regions |
16
+ | **Duration** | Ongoing until fix deployed |
17
+ | **Impact** | User complaints, 15% drop in search usage |
18
+
19
+ ### Detection Timeline
20
+
21
+ ```
22
+ Feb 1, 10:00 - v2.3.0 deployed to production
23
+ Feb 1, 14:00 - Latency alert fires (p99 > 500ms)
24
+ Feb 1, 14:30 - Investigation begins
25
+ Feb 2, 09:00 - Root cause identified
26
+ Feb 2, 15:00 - Fix deployed, latency returns to normal
27
+ ```
28
+
29
+ ---
30
+
31
+ ### Why Chain
32
+
33
+ | Level | Question | Answer | Evidence |
34
+ |-------|----------|--------|----------|
35
+ | **Why 1** | Why did search API latency increase 4x? | Database queries taking longer | Query timing metrics showed DB time 600ms vs 100ms before |
36
+ | **Why 2** | Why are database queries slower? | Full table scan on products table | EXPLAIN ANALYZE showed Seq Scan instead of Index Scan |
37
+ | **Why 3** | Why is a full table scan happening? | Query predicate changed, doesn't use index | Query plan shows index on `category_id` not being used |
38
+ | **Why 4** | Why doesn't the new query use the index? | New filter uses `LOWER(category_name)` instead of `category_id` | Code diff in v2.3.0 shows the change |
39
+ | **Why 5** | Why was this change made without index? | Developer assumed existing index covered it; no query review | PR #1847 shows no query plan check |
40
+
41
+ ---
42
+
43
+ ### Deeper Investigation
44
+
45
+ **Why was there no query review in PR #1847?**
46
+
47
+ | Level | Question | Answer |
48
+ |-------|----------|--------|
49
+ | Why 5a | Why no query review? | Team doesn't have query review checklist |
50
+ | Why 5b | Why no checklist? | Performance wasn't seen as critical for search |
51
+ | Why 5c | Why wasn't it seen as critical? | No SLO defined for search latency |
52
+
53
+ **Second Root Cause:** No performance SLO → No review process → Regression shipped
54
+
55
+ ---
56
+
57
+ ### Root Causes
58
+
59
+ **Primary Root Cause:**
60
+ Query changed to use `LOWER(category_name)` for case-insensitive search, but no functional index exists for that expression.
61
+
62
+ **Category:** Design Gap + Process Gap
63
+
64
+ **Secondary Root Cause:**
65
+ No query performance review in PR process due to missing latency SLOs.
66
+
67
+ **Category:** Process Gap
68
+
69
+ ---
70
+
71
+ ### Validation
72
+
73
+ | Test | Result |
74
+ |------|--------|
75
+ | Add index on `LOWER(category_name)` | Query drops to 80ms ✓ |
76
+ | Deploy to staging with index | p99 returns to 180ms ✓ |
77
+ | Remove index, revert to `category_id` filter | Also fixes issue ✓ |
78
+
79
+ **Chosen Fix:** Add functional index (preserves case-insensitive feature)
80
+
81
+ ```sql
82
+ CREATE INDEX idx_products_category_name_lower
83
+ ON products (LOWER(category_name));
84
+ ```
85
+
86
+ ---
87
+
88
+ ### Why Wasn't This Caught Earlier?
89
+
90
+ | Stage | Should Have Caught? | Why It Didn't |
91
+ |-------|---------------------|---------------|
92
+ | **Code Review** | Maybe | Reviewer didn't check query plan |
93
+ | **Unit Tests** | No | Tests don't measure performance |
94
+ | **Integration Tests** | Maybe | Test data too small (100 rows vs 10M in prod) |
95
+ | **Staging** | Maybe | Staging has 1M rows, might have caught it |
96
+ | **Canary Deploy** | Yes | But canary wasn't enabled for this service |
97
+
98
+ ---
99
+
100
+ ### Countermeasures
101
+
102
+ | Priority | Type | Action | Owner | Status |
103
+ |----------|------|--------|-------|--------|
104
+ | **P0** | Immediate | Add functional index | @dba-team | ✅ Done |
105
+ | **P1** | Prevention | Query review checklist for PRs | @tech-lead | ✅ Done |
106
+ | **P1** | Prevention | Enable canary deployments | @sre-team | 🔄 In progress |
107
+ | **P2** | Detection | Query latency alert per endpoint | @sre-team | 📋 Planned |
108
+ | **P2** | Process | Define search latency SLO (p99 < 300ms) | @product | 📋 Planned |
109
+ | **P3** | Testing | Add performance test with prod-like data volume | @qa-team | 📋 Backlog |
110
+
111
+ ---
112
+
113
+ ### Query Review Checklist (Created)
114
+
115
+ For any PR that modifies database queries:
116
+
117
+ - [ ] Run `EXPLAIN ANALYZE` on new/modified queries
118
+ - [ ] Verify index usage (no Seq Scan on large tables)
119
+ - [ ] Check estimated rows vs actual rows
120
+ - [ ] Test with production-like data volume
121
+ - [ ] Document expected query performance
122
+
123
+ ---
124
+
125
+ ### Lessons Learned
126
+
127
+ 1. **Case-insensitive search needs functional indexes**
128
+ - `WHERE LOWER(col) = 'value'` won't use index on `col`
129
+ - Must create index on `LOWER(col)`
130
+
131
+ 2. **Test data volume matters**
132
+ - 100 rows: any query is fast
133
+ - 10M rows: missing index is catastrophic
134
+
135
+ 3. **Canary deployments are essential**
136
+ - Would have caught 4x latency increase with 1% traffic
137
+
138
+ 4. **SLOs drive process**
139
+ - Without latency SLO, no one prioritized performance review
140
+
141
+ ---
142
+
143
+ ### 30-Day Follow-up
144
+
145
+ - [ ] Search p99 consistently < 300ms
146
+ - [ ] Query review checklist being used in PRs
147
+ - [ ] Canary deployment enabled and tested
148
+ - [ ] Performance tests added to CI pipeline
149
+
150
+ ---
151
+
152
+ ## Analysis Quality Assessment
153
+
154
+ | Criteria | Met? | Notes |
155
+ |----------|------|-------|
156
+ | Problem specific | ✓ | Exact metric, timeframe, deployment |
157
+ | Evidence-based | ✓ | Query plans, metrics, code diffs |
158
+ | Multi-level causes | ✓ | Technical + process root causes |
159
+ | Actionable | ✓ | Index + checklist + canary |
160
+ | Preventable | ✓ | Process changes prevent recurrence |
161
+ | No blame | ✓ | Focus on missing process/tools |
@@ -0,0 +1,134 @@
1
+ # Example: Production Incident - Payment Service Outage
2
+
3
+ A complete 5-Whys analysis of a production payment service failure.
4
+
5
+ ---
6
+
7
+ ## 5-Whys Analysis: Payment Service Outage (2024-01-15)
8
+
9
+ ### Problem Statement
10
+
11
+ | Field | Details |
12
+ |-------|---------|
13
+ | **What** | Payment API returning 503 errors, all transactions failing |
14
+ | **When** | 2024-01-15, 14:23 UTC, during peak traffic |
15
+ | **Where** | payment-service in production (us-east-1) |
16
+ | **Duration** | 47 minutes |
17
+ | **Impact** | ~$150,000 in failed transactions, 12,000 affected users |
18
+
19
+ ### Timeline
20
+
21
+ ```
22
+ 14:23 - First 503 errors appear in monitoring
23
+ 14:25 - Alert fires: payment-service error rate > 5%
24
+ 14:28 - On-call engineer begins investigation
25
+ 14:35 - Identified: all DB connections exhausted
26
+ 14:42 - Attempted restart, problem persists
27
+ 14:55 - Root cause identified: connection leak
28
+ 15:02 - Hotfix deployed
29
+ 15:10 - Service fully recovered
30
+ ```
31
+
32
+ ---
33
+
34
+ ### Why Chain
35
+
36
+ | Level | Question | Answer | Evidence |
37
+ |-------|----------|--------|----------|
38
+ | **Why 1** | Why did the payment API return 503 errors? | Database connection pool was exhausted (0/100 available) | Connection pool metrics showed 100/100 in use |
39
+ | **Why 2** | Why was the connection pool exhausted? | Connections were being acquired but not released | Connection age histogram showed connections held for hours |
40
+ | **Why 3** | Why were connections not being released? | Exception thrown before connection.close() in refund handler | Stack trace in logs showed exception at line 142 |
41
+ | **Why 4** | Why did the exception prevent connection close? | No try-finally block; close() only in happy path | Code inspection of RefundHandler.java |
42
+ | **Why 5** | Why was there no try-finally block? | Code copied from old service that used auto-commit (no explicit close needed) | Git blame showed copy-paste from legacy service |
43
+
44
+ ---
45
+
46
+ ### Root Cause
47
+
48
+ **Identified Cause:** Connection handling code was copied from a legacy service that used auto-commit mode (where connections auto-close). The new service uses manual transactions, requiring explicit close(), but the code pattern wasn't updated.
49
+
50
+ **Category:** Design Gap (incorrect pattern application)
51
+
52
+ **Confidence:** High (reproduced in staging)
53
+
54
+ ---
55
+
56
+ ### Multi-Branch Analysis
57
+
58
+ The outage had a contributing factor that made it worse:
59
+
60
+ ```
61
+ Primary Branch (Root Cause):
62
+ Connection leak in refund handler
63
+ ↓
64
+ Pool exhausted
65
+
66
+ Contributing Branch (Made it worse):
67
+ Why wasn't this caught earlier?
68
+ ↓
69
+ Why 1: No connection pool monitoring alert
70
+ ↓
71
+ Why 2: Monitoring dashboard existed but no alert threshold
72
+ ↓
73
+ Why 3: Alert was in backlog, not prioritized
74
+ ↓
75
+ Why 4: No SLO defined for connection pool utilization
76
+ ```
77
+
78
+ ---
79
+
80
+ ### Validation
81
+
82
+ Testing the causal chain backwards:
83
+
84
+ | If... | Then... | Validates? |
85
+ |-------|---------|------------|
86
+ | Try-finally added to RefundHandler | Connections always released | ✓ Tested in staging |
87
+ | Connections always released | Pool never exhausts | ✓ Load test confirmed |
88
+ | Pool never exhausts | No 503 errors from DB | ✓ Verified |
89
+ | No 503 errors | Payment service stays healthy | ✓ |
90
+
91
+ ---
92
+
93
+ ### Countermeasures
94
+
95
+ | Priority | Type | Action | Owner | Status |
96
+ |----------|------|--------|-------|--------|
97
+ | **P0** | Immediate | Add try-finally to RefundHandler | @dev-alice | ✅ Done |
98
+ | **P0** | Immediate | Audit all DB handlers for same pattern | @dev-bob | ✅ Done (found 2 more) |
99
+ | **P1** | Prevention | Add connection pool alert at 80% | @sre-carol | ✅ Done |
100
+ | **P1** | Prevention | Linter rule: require try-finally for DB connections | @dev-alice | 🔄 In progress |
101
+ | **P2** | Detection | Connection age histogram alert (>5min) | @sre-carol | 📋 Planned |
102
+ | **P2** | Process | Code review checklist: resource cleanup | @tech-lead | 📋 Planned |
103
+
104
+ ---
105
+
106
+ ### Lessons Learned
107
+
108
+ 1. **Code copying is risky** - Patterns from one context may not apply in another
109
+ 2. **Resource cleanup needs defense in depth** - Linting + review + monitoring
110
+ 3. **Monitoring without alerts is incomplete** - Dashboards don't page on-call
111
+ 4. **Connection pools need visibility** - Should be first-class metric
112
+
113
+ ---
114
+
115
+ ### Follow-up Verification
116
+
117
+ **30-day check:**
118
+ - [ ] No connection pool exhaustion incidents
119
+ - [ ] Linter rule catching violations in PRs
120
+ - [ ] Connection age alerts working (tested with chaos engineering)
121
+
122
+ ---
123
+
124
+ ## Analysis Quality Assessment
125
+
126
+ | Criteria | Met? | Notes |
127
+ |----------|------|-------|
128
+ | Problem specific and measurable | ✓ | Exact error, time, impact quantified |
129
+ | Each "why" has evidence | ✓ | Logs, metrics, code inspection |
130
+ | Root cause is actionable | ✓ | Code change fixes it |
131
+ | Root cause is preventable | ✓ | Linter + review prevents recurrence |
132
+ | Chain validates backwards | ✓ | Tested in staging |
133
+ | No blame, only process | ✓ | Focused on missing patterns/tools |
134
+ | Countermeasures assigned | ✓ | Owners and timelines set |