safeword 0.2.2 → 0.2.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 (235) hide show
  1. package/.claude/commands/arch-review.md +32 -0
  2. package/.claude/commands/lint.md +6 -0
  3. package/.claude/commands/quality-review.md +13 -0
  4. package/.claude/commands/setup-linting.md +6 -0
  5. package/.claude/hooks/auto-lint.sh +6 -0
  6. package/.claude/hooks/auto-quality-review.sh +170 -0
  7. package/.claude/hooks/check-linting-sync.sh +17 -0
  8. package/.claude/hooks/inject-timestamp.sh +6 -0
  9. package/.claude/hooks/question-protocol.sh +12 -0
  10. package/.claude/hooks/run-linters.sh +8 -0
  11. package/.claude/hooks/run-quality-review.sh +76 -0
  12. package/.claude/hooks/version-check.sh +10 -0
  13. package/.claude/mcp/README.md +96 -0
  14. package/.claude/mcp/arcade.sample.json +9 -0
  15. package/.claude/mcp/context7.sample.json +7 -0
  16. package/.claude/mcp/playwright.sample.json +7 -0
  17. package/.claude/settings.json +62 -0
  18. package/.claude/skills/quality-reviewer/SKILL.md +190 -0
  19. package/.claude/skills/safeword-quality-reviewer/SKILL.md +13 -0
  20. package/.env.arcade.example +4 -0
  21. package/.env.example +11 -0
  22. package/.gitmodules +4 -0
  23. package/.safeword/SAFEWORD.md +33 -0
  24. package/.safeword/eslint/eslint-base.mjs +101 -0
  25. package/.safeword/guides/architecture-guide.md +404 -0
  26. package/.safeword/guides/code-philosophy.md +174 -0
  27. package/.safeword/guides/context-files-guide.md +405 -0
  28. package/.safeword/guides/data-architecture-guide.md +183 -0
  29. package/.safeword/guides/design-doc-guide.md +165 -0
  30. package/.safeword/guides/learning-extraction.md +515 -0
  31. package/.safeword/guides/llm-instruction-design.md +239 -0
  32. package/.safeword/guides/llm-prompting.md +95 -0
  33. package/.safeword/guides/tdd-best-practices.md +570 -0
  34. package/.safeword/guides/test-definitions-guide.md +243 -0
  35. package/.safeword/guides/testing-methodology.md +573 -0
  36. package/.safeword/guides/user-story-guide.md +237 -0
  37. package/.safeword/guides/zombie-process-cleanup.md +214 -0
  38. package/{templates → .safeword}/hooks/agents-md-check.sh +0 -0
  39. package/{templates → .safeword}/hooks/post-tool.sh +0 -0
  40. package/{templates → .safeword}/hooks/pre-commit.sh +0 -0
  41. package/.safeword/planning/002-user-story-quality-evaluation.md +1840 -0
  42. package/.safeword/planning/003-langsmith-eval-setup-prompt.md +363 -0
  43. package/.safeword/planning/004-llm-eval-test-cases.md +3226 -0
  44. package/.safeword/planning/005-architecture-enforcement-system.md +169 -0
  45. package/.safeword/planning/006-reactive-fix-prevention-research.md +135 -0
  46. package/.safeword/planning/011-cli-ux-vision.md +330 -0
  47. package/.safeword/planning/012-project-structure-cleanup.md +154 -0
  48. package/.safeword/planning/README.md +39 -0
  49. package/.safeword/planning/automation-plan-v2.md +1225 -0
  50. package/.safeword/planning/automation-plan-v3.md +1291 -0
  51. package/.safeword/planning/automation-plan.md +3058 -0
  52. package/.safeword/planning/design/005-cli-implementation.md +343 -0
  53. package/.safeword/planning/design/013-cli-self-contained-templates.md +596 -0
  54. package/.safeword/planning/design/013a-eslint-plugin-suite.md +256 -0
  55. package/.safeword/planning/design/013b-implementation-snippets.md +385 -0
  56. package/.safeword/planning/design/013c-config-isolation-strategy.md +242 -0
  57. package/.safeword/planning/design/code-philosophy-improvements.md +60 -0
  58. package/.safeword/planning/mcp-analysis.md +545 -0
  59. package/.safeword/planning/phase2-subagents-vs-skills-analysis.md +451 -0
  60. package/.safeword/planning/settings-improvements.md +970 -0
  61. package/.safeword/planning/test-definitions/005-cli-implementation.md +1301 -0
  62. package/.safeword/planning/test-definitions/cli-self-contained-templates.md +205 -0
  63. package/.safeword/planning/user-stories/001-guides-review-user-stories.md +1381 -0
  64. package/.safeword/planning/user-stories/003-reactive-fix-prevention.md +132 -0
  65. package/.safeword/planning/user-stories/004-technical-constraints.md +86 -0
  66. package/.safeword/planning/user-stories/005-cli-implementation.md +311 -0
  67. package/.safeword/planning/user-stories/cli-self-contained-templates.md +172 -0
  68. package/.safeword/planning/versioned-distribution.md +740 -0
  69. package/.safeword/prompts/arch-review.md +43 -0
  70. package/.safeword/prompts/quality-review.md +11 -0
  71. package/.safeword/scripts/arch-review.sh +235 -0
  72. package/.safeword/scripts/check-linting-sync.sh +58 -0
  73. package/.safeword/scripts/setup-linting.sh +559 -0
  74. package/.safeword/templates/architecture-template.md +136 -0
  75. package/.safeword/templates/ci/architecture-check.yml +79 -0
  76. package/.safeword/templates/design-doc-template.md +127 -0
  77. package/.safeword/templates/test-definitions-feature.md +100 -0
  78. package/.safeword/templates/ticket-template.md +74 -0
  79. package/.safeword/templates/user-stories-template.md +82 -0
  80. package/.safeword/tickets/001-guides-review-user-stories.md +83 -0
  81. package/.safeword/tickets/002-architecture-enforcement.md +211 -0
  82. package/.safeword/tickets/003-reactive-fix-prevention.md +57 -0
  83. package/.safeword/tickets/004-technical-constraints-in-user-stories.md +39 -0
  84. package/.safeword/tickets/005-cli-implementation.md +248 -0
  85. package/.safeword/tickets/006-flesh-out-skills.md +43 -0
  86. package/.safeword/tickets/007-flesh-out-questioning.md +44 -0
  87. package/.safeword/tickets/008-upgrade-questioning.md +58 -0
  88. package/.safeword/tickets/009-naming-conventions.md +41 -0
  89. package/.safeword/tickets/010-safeword-md-cleanup.md +34 -0
  90. package/.safeword/tickets/011-cursor-setup.md +86 -0
  91. package/.safeword/tickets/README.md +73 -0
  92. package/.safeword/version +1 -0
  93. package/AGENTS.md +59 -0
  94. package/CLAUDE.md +12 -0
  95. package/README.md +347 -0
  96. package/docs/001-cli-implementation-plan.md +856 -0
  97. package/docs/elite-dx-implementation-plan.md +1034 -0
  98. package/framework/README.md +131 -0
  99. package/framework/mcp/README.md +96 -0
  100. package/framework/mcp/arcade.sample.json +8 -0
  101. package/framework/mcp/context7.sample.json +6 -0
  102. package/framework/mcp/playwright.sample.json +6 -0
  103. package/framework/scripts/arch-review.sh +235 -0
  104. package/framework/scripts/check-linting-sync.sh +58 -0
  105. package/framework/scripts/load-env.sh +49 -0
  106. package/framework/scripts/setup-claude.sh +223 -0
  107. package/framework/scripts/setup-linting.sh +559 -0
  108. package/framework/scripts/setup-quality.sh +477 -0
  109. package/framework/scripts/setup-safeword.sh +550 -0
  110. package/framework/templates/ci/architecture-check.yml +78 -0
  111. package/learnings/ai-sdk-v5-breaking-changes.md +178 -0
  112. package/learnings/e2e-test-zombie-processes.md +231 -0
  113. package/learnings/milkdown-crepe-editor-property.md +96 -0
  114. package/learnings/prosemirror-fragment-traversal.md +119 -0
  115. package/package.json +19 -43
  116. package/packages/cli/AGENTS.md +1 -0
  117. package/packages/cli/ARCHITECTURE.md +279 -0
  118. package/packages/cli/package.json +51 -0
  119. package/packages/cli/src/cli.ts +63 -0
  120. package/packages/cli/src/commands/check.ts +166 -0
  121. package/packages/cli/src/commands/diff.ts +209 -0
  122. package/packages/cli/src/commands/reset.ts +190 -0
  123. package/packages/cli/src/commands/setup.ts +325 -0
  124. package/packages/cli/src/commands/upgrade.ts +163 -0
  125. package/packages/cli/src/index.ts +3 -0
  126. package/packages/cli/src/templates/config.ts +58 -0
  127. package/packages/cli/src/templates/content.ts +18 -0
  128. package/packages/cli/src/templates/index.ts +12 -0
  129. package/packages/cli/src/utils/agents-md.ts +66 -0
  130. package/packages/cli/src/utils/fs.ts +179 -0
  131. package/packages/cli/src/utils/git.ts +124 -0
  132. package/packages/cli/src/utils/hooks.ts +29 -0
  133. package/packages/cli/src/utils/output.ts +60 -0
  134. package/packages/cli/src/utils/project-detector.test.ts +185 -0
  135. package/packages/cli/src/utils/project-detector.ts +44 -0
  136. package/packages/cli/src/utils/version.ts +28 -0
  137. package/packages/cli/src/version.ts +6 -0
  138. package/packages/cli/templates/SAFEWORD.md +776 -0
  139. package/packages/cli/templates/doc-templates/architecture-template.md +136 -0
  140. package/packages/cli/templates/doc-templates/design-doc-template.md +134 -0
  141. package/packages/cli/templates/doc-templates/test-definitions-feature.md +131 -0
  142. package/packages/cli/templates/doc-templates/ticket-template.md +82 -0
  143. package/packages/cli/templates/doc-templates/user-stories-template.md +92 -0
  144. package/packages/cli/templates/guides/architecture-guide.md +423 -0
  145. package/packages/cli/templates/guides/code-philosophy.md +195 -0
  146. package/packages/cli/templates/guides/context-files-guide.md +457 -0
  147. package/packages/cli/templates/guides/data-architecture-guide.md +200 -0
  148. package/packages/cli/templates/guides/design-doc-guide.md +171 -0
  149. package/packages/cli/templates/guides/learning-extraction.md +552 -0
  150. package/packages/cli/templates/guides/llm-instruction-design.md +248 -0
  151. package/packages/cli/templates/guides/llm-prompting.md +102 -0
  152. package/packages/cli/templates/guides/tdd-best-practices.md +615 -0
  153. package/packages/cli/templates/guides/test-definitions-guide.md +334 -0
  154. package/packages/cli/templates/guides/testing-methodology.md +618 -0
  155. package/packages/cli/templates/guides/user-story-guide.md +256 -0
  156. package/packages/cli/templates/guides/zombie-process-cleanup.md +219 -0
  157. package/packages/cli/templates/hooks/agents-md-check.sh +27 -0
  158. package/packages/cli/templates/hooks/post-tool.sh +4 -0
  159. package/packages/cli/templates/hooks/pre-commit.sh +10 -0
  160. package/packages/cli/templates/prompts/arch-review.md +43 -0
  161. package/packages/cli/templates/prompts/quality-review.md +10 -0
  162. package/packages/cli/templates/skills/safeword-quality-reviewer/SKILL.md +207 -0
  163. package/packages/cli/tests/commands/check.test.ts +129 -0
  164. package/packages/cli/tests/commands/cli.test.ts +89 -0
  165. package/packages/cli/tests/commands/diff.test.ts +115 -0
  166. package/packages/cli/tests/commands/reset.test.ts +310 -0
  167. package/packages/cli/tests/commands/self-healing.test.ts +170 -0
  168. package/packages/cli/tests/commands/setup-blocking.test.ts +71 -0
  169. package/packages/cli/tests/commands/setup-core.test.ts +135 -0
  170. package/packages/cli/tests/commands/setup-git.test.ts +139 -0
  171. package/packages/cli/tests/commands/setup-hooks.test.ts +334 -0
  172. package/packages/cli/tests/commands/setup-linting.test.ts +189 -0
  173. package/packages/cli/tests/commands/setup-noninteractive.test.ts +80 -0
  174. package/packages/cli/tests/commands/setup-templates.test.ts +181 -0
  175. package/packages/cli/tests/commands/upgrade.test.ts +215 -0
  176. package/packages/cli/tests/helpers.ts +243 -0
  177. package/packages/cli/tests/npm-package.test.ts +83 -0
  178. package/packages/cli/tests/technical-constraints.test.ts +96 -0
  179. package/packages/cli/tsconfig.json +25 -0
  180. package/packages/cli/tsup.config.ts +11 -0
  181. package/packages/cli/vitest.config.ts +23 -0
  182. package/promptfoo.yaml +3270 -0
  183. package/dist/check-M73LGONJ.js +0 -129
  184. package/dist/check-M73LGONJ.js.map +0 -1
  185. package/dist/chunk-2XWIUEQK.js +0 -190
  186. package/dist/chunk-2XWIUEQK.js.map +0 -1
  187. package/dist/chunk-GZRQL3SX.js +0 -146
  188. package/dist/chunk-GZRQL3SX.js.map +0 -1
  189. package/dist/chunk-V5G6BGOK.js +0 -26
  190. package/dist/chunk-V5G6BGOK.js.map +0 -1
  191. package/dist/chunk-W66Z3C5H.js +0 -21
  192. package/dist/chunk-W66Z3C5H.js.map +0 -1
  193. package/dist/cli.d.ts +0 -1
  194. package/dist/cli.js +0 -34
  195. package/dist/cli.js.map +0 -1
  196. package/dist/diff-FSFDCBL5.js +0 -166
  197. package/dist/diff-FSFDCBL5.js.map +0 -1
  198. package/dist/index.d.ts +0 -11
  199. package/dist/index.js +0 -7
  200. package/dist/index.js.map +0 -1
  201. package/dist/reset-3ACTIYYE.js +0 -143
  202. package/dist/reset-3ACTIYYE.js.map +0 -1
  203. package/dist/setup-MKVVQTVA.js +0 -266
  204. package/dist/setup-MKVVQTVA.js.map +0 -1
  205. package/dist/upgrade-FQOL6AF5.js +0 -134
  206. package/dist/upgrade-FQOL6AF5.js.map +0 -1
  207. /package/{templates → framework}/SAFEWORD.md +0 -0
  208. /package/{templates → framework}/guides/architecture-guide.md +0 -0
  209. /package/{templates → framework}/guides/code-philosophy.md +0 -0
  210. /package/{templates → framework}/guides/context-files-guide.md +0 -0
  211. /package/{templates → framework}/guides/data-architecture-guide.md +0 -0
  212. /package/{templates → framework}/guides/design-doc-guide.md +0 -0
  213. /package/{templates → framework}/guides/learning-extraction.md +0 -0
  214. /package/{templates → framework}/guides/llm-instruction-design.md +0 -0
  215. /package/{templates → framework}/guides/llm-prompting.md +0 -0
  216. /package/{templates → framework}/guides/tdd-best-practices.md +0 -0
  217. /package/{templates → framework}/guides/test-definitions-guide.md +0 -0
  218. /package/{templates → framework}/guides/testing-methodology.md +0 -0
  219. /package/{templates → framework}/guides/user-story-guide.md +0 -0
  220. /package/{templates → framework}/guides/zombie-process-cleanup.md +0 -0
  221. /package/{templates → framework}/prompts/arch-review.md +0 -0
  222. /package/{templates → framework}/prompts/quality-review.md +0 -0
  223. /package/{templates/skills/safeword-quality-reviewer → framework/skills/quality-reviewer}/SKILL.md +0 -0
  224. /package/{templates/doc-templates → framework/templates}/architecture-template.md +0 -0
  225. /package/{templates/doc-templates → framework/templates}/design-doc-template.md +0 -0
  226. /package/{templates/doc-templates → framework/templates}/test-definitions-feature.md +0 -0
  227. /package/{templates/doc-templates → framework/templates}/ticket-template.md +0 -0
  228. /package/{templates/doc-templates → framework/templates}/user-stories-template.md +0 -0
  229. /package/{templates → packages/cli/templates}/commands/arch-review.md +0 -0
  230. /package/{templates → packages/cli/templates}/commands/lint.md +0 -0
  231. /package/{templates → packages/cli/templates}/commands/quality-review.md +0 -0
  232. /package/{templates → packages/cli/templates}/hooks/inject-timestamp.sh +0 -0
  233. /package/{templates → packages/cli/templates}/lib/common.sh +0 -0
  234. /package/{templates → packages/cli/templates}/lib/jq-fallback.sh +0 -0
  235. /package/{templates → packages/cli/templates}/markdownlint.jsonc +0 -0
@@ -0,0 +1,552 @@
1
+ # Learning Extraction Process
2
+
3
+ Extract reusable knowledge from debugging sessions and implementation discoveries. Ensures insights compound across sessions.
4
+
5
+ **LLM Instruction Design:** Learnings are documentation that LLMs read and follow. Apply best practices from `@.safeword/guides/llm-instruction-design.md` when writing learning files (concrete examples, explicit definitions, MECE principles).
6
+
7
+ ---
8
+
9
+ ## When to Extract (Recognition Triggers)
10
+
11
+ **Note:** LLMs cannot sense time. Use observable signals instead of duration.
12
+
13
+ Extract after experiencing ANY of these:
14
+
15
+ 1. **Observable debugging complexity** - Any of these signals:
16
+ - User says "still debugging", "been stuck on this", "tried many things"
17
+ - 5+ debug cycles (Read → Edit → Bash pattern repeated)
18
+ - 3+ different error states encountered
19
+ - Modified 3+ files while debugging same issue
20
+ 2. **Trial and error** - Tried 3+ different approaches before finding the right one
21
+ 3. **Undocumented gotcha** - Not in official library/framework docs
22
+ 4. **Integration struggle** - Two tools that don't work together smoothly
23
+ 5. **Testing trap** - Tests pass but UX is broken (or vice versa)
24
+ 6. **Architectural insight** - Discovered during implementation, not planned upfront
25
+
26
+ **Key question:** "Would this save time on future work in this codebase (or any codebase)?"
27
+
28
+ ---
29
+
30
+ ## File Locations
31
+
32
+ **Global learnings** (`.safeword/learnings/[concept].md`):
33
+
34
+ - **Why**: Applies to ALL your projects (React patterns, Git workflows)
35
+ - **Scope**: Personal directory (not shared)
36
+ - **Use case**: Generic programming knowledge
37
+
38
+ **Project learnings** (`./.safeword/learnings/[concept].md`):
39
+
40
+ - **Why**: Specific to THIS codebase (custom architecture, unique patterns)
41
+ - **Scope**: Shared via git (team knowledge base)
42
+ - **Use case**: Project-specific gotchas
43
+
44
+ **Historical archives** (`./.safeword/learnings/archive/[bug-fix].md`):
45
+
46
+ - **Why**: One-time debugging narratives (not forward-looking)
47
+ - **Scope**: Shared via git (learning history)
48
+ - **Use case**: Reference when similar bugs occur
49
+
50
+ **Cascading Precedence** (both Claude Code and SAFEWORD.md):
51
+
52
+ 1. Explicit user instruction (highest priority)
53
+ 2. Project `./.safeword/learnings/` (project-specific)
54
+ 3. Global `.safeword/learnings/` (personal defaults)
55
+ 4. Project `./SAFEWORD.md` → Common Gotchas (inline reference)
56
+
57
+ ---
58
+
59
+ ## Using Existing Learnings
60
+
61
+ **CRITICAL**: Before extracting new learnings, ALWAYS check if similar learnings already exist. This prevents duplication and keeps knowledge organized.
62
+
63
+ ### When to Check for Existing Learnings
64
+
65
+ **Check PROACTIVELY in these situations:**
66
+
67
+ 1. **Before debugging** - Check if similar issue has learning already
68
+
69
+ ```bash
70
+ ls .safeword/learnings/*[technology]*.md
71
+ ls ./learnings/*[pattern]*.md
72
+ ```
73
+
74
+ 2. **When user mentions technology/pattern** - Check for relevant learnings
75
+ - User says "React hooks" → Check for `*hooks*.md`
76
+ - User says "Electron IPC" → Check for `*electron*.md` or `*ipc*.md`
77
+ - User says "state management" → Check for `*state*.md`
78
+
79
+ 3. **During architectural discussions** - Check for pattern learnings
80
+ - Discussing patterns → Check for `*pattern*.md` or `*architecture*.md`
81
+
82
+ 4. **After suggesting extraction** - Check if learning already exists
83
+ - If found → Suggest updating existing learning instead of creating duplicate
84
+ - If not found → Proceed with extraction
85
+
86
+ ### How to Check
87
+
88
+ ```bash
89
+ # Global learnings (all projects)
90
+ ls .safeword/learnings/
91
+
92
+ # Search global learnings by keyword
93
+ ls .safeword/learnings/*keyword*.md
94
+
95
+ # Project learnings (current project)
96
+ ls ./.safeword/learnings/
97
+
98
+ # Search project learnings by keyword
99
+ ls ./.safeword/learnings/*keyword*.md
100
+ ```
101
+
102
+ ### When to Reference Existing Learnings
103
+
104
+ **Found existing learning** → Read and apply it:
105
+
106
+ ```
107
+ "I found an existing learning about [concept] at [path]. Let me read it and apply to your case..."
108
+ [Read the file]
109
+ "Based on the learning, here's how to handle this: [specific guidance from learning]"
110
+ ```
111
+
112
+ **No existing learning** → Proceed normally (no message needed)
113
+
114
+ **Similar but different** → Reference and note difference:
115
+
116
+ ```
117
+ "This is similar to the [existing learning] at [path], but differs in [specific way].
118
+ The existing learning covers [X], but your case involves [Y]."
119
+ ```
120
+
121
+ ### Example Workflow
122
+
123
+ **Scenario 1: Found relevant learning**
124
+
125
+ ```
126
+ User: "I'm getting an async state update error with React hooks"
127
+ → Check: ls .safeword/learnings/*react*.md *hooks*.md *async*.md
128
+ → Found: react-hooks-async.md
129
+ → Read: [file contents]
130
+ → Apply: "I found a learning about async React hooks. It mentions you should use useEffect
131
+ for side effects, not setState directly in callbacks. Applying this to your case..."
132
+ ```
133
+
134
+ **Scenario 2: No existing learning**
135
+
136
+ ```
137
+ User: "IndexedDB quota is behaving strangely in Safari"
138
+ → Check: ls .safeword/learnings/*indexeddb*.md *safari*.md *quota*.md
139
+ → Not found
140
+ → Proceed: Continue debugging normally, suggest extraction if triggers match
141
+ ```
142
+
143
+ **Scenario 3: Update existing learning**
144
+
145
+ ```
146
+ User: Debugging for 6 cycles, discovers new IndexedDB quirk
147
+ → Suggest extraction
148
+ → Check: ls .safeword/learnings/*indexeddb*.md
149
+ → Found: indexeddb-quota-api.md
150
+ → Suggest: "I found an existing learning about IndexedDB quota. Should I update it with
151
+ this new discovery instead of creating a separate learning?"
152
+ ```
153
+
154
+ ### Benefits of Checking Existing Learnings
155
+
156
+ ✅ **Prevents duplication** - One learning per concept, easier to find
157
+ ✅ **Compounds knowledge** - Update existing learnings with new discoveries
158
+ ✅ **Faster problem solving** - Apply known patterns immediately
159
+ ✅ **Better organization** - Learnings directory stays clean and navigable
160
+
161
+ ---
162
+
163
+ ## Decision Tree
164
+
165
+ ```
166
+ Just learned something valuable
167
+
168
+ ├─ Forward-looking? (useful on FUTURE work, not just this bug)
169
+ │ ├─ YES → Continue
170
+ │ └─ NO → .safeword/learnings/archive/[bug-fix].md (optional)
171
+
172
+ ├─ Applies to ALL projects or just THIS one?
173
+ │ │
174
+ │ ├─ ALL PROJECTS
175
+ │ │ └─ Extract to: .safeword/learnings/[concept].md
176
+ │ │ Examples: "React hooks gotchas", "Electron IPC patterns"
177
+ │ │
178
+ │ └─ THIS PROJECT ONLY
179
+ │ │
180
+ │ ├─ Architectural? (why we chose X over Y)
181
+ │ │ └─ YES → Add to: SAFEWORD.md "Architecture Decisions"
182
+ │ │
183
+ │ ├─ Short gotcha? (1-2 sentences + code snippet)
184
+ │ │ └─ YES → Add to: SAFEWORD.md "Common Gotchas"
185
+ │ │
186
+ │ └─ Needs examples/explanation?
187
+ │ └─ YES → Extract to: ./.safeword/learnings/[concept].md
188
+ │ Then cross-reference in SAFEWORD.md
189
+ ```
190
+
191
+ ---
192
+
193
+ ## Templates
194
+
195
+ ### Forward-Looking Learning (.safeword/learnings/)
196
+
197
+ **Use when:** Pattern applies to 2+ features/files, needs explanation
198
+
199
+ **Structure:**
200
+
201
+ ```markdown
202
+ # [Concept Name]
203
+
204
+ **Principle:** One-sentence summary
205
+
206
+ ## The Gotcha
207
+
208
+ What breaks if you don't know this:
209
+
210
+ ❌ **Bad:** [Anti-pattern]
211
+ ✅ **Good:** [Correct pattern]
212
+
213
+ **Why it matters:** [User impact or technical consequence]
214
+
215
+ ## Examples
216
+
217
+ [2-3 concrete before/after code examples]
218
+
219
+ ## Testing Trap (if applicable)
220
+
221
+ [How tests might pass while UX is broken]
222
+
223
+ ## Reference
224
+
225
+ See `.safeword/learnings/archive/[investigation].md` for full debugging narrative.
226
+ ```
227
+
228
+ ### Debugging Narrative (.safeword/learnings/archive/)
229
+
230
+ **Use when:** One-time bug fix, historical record
231
+
232
+ **Structure:**
233
+
234
+ ````markdown
235
+ # [Issue Title]
236
+
237
+ **Date:** YYYY-MM-DD
238
+ **Root Cause:** One-sentence explanation
239
+
240
+ ## Problem
241
+
242
+ Expected: [What should happen]
243
+ Actual: [What happened]
244
+
245
+ ## Investigation
246
+
247
+ 1. [Hypothesis] → [Outcome]
248
+ 2. [Hypothesis] → [Outcome]
249
+ 3. [Discovery] → [Fix]
250
+
251
+ ## Solution
252
+
253
+ ```diff
254
+ - Old broken code
255
+ + New fixed code
256
+ ```
257
+ ````
258
+
259
+ ## Lesson
260
+
261
+ [One-sentence takeaway]
262
+
263
+ ````
264
+
265
+ ---
266
+
267
+ ## SAFEWORD.md Integration
268
+
269
+ **CRITICAL**: ALWAYS cross-reference in SAFEWORD.md after creating learning file.
270
+
271
+ After extracting to `.safeword/learnings/`, add cross-reference in SAFEWORD.md:
272
+
273
+ ```markdown
274
+ ## Common Gotchas
275
+
276
+ Project-specific gotchas in `.safeword/learnings/`:
277
+
278
+ - **Persistent UI Placement** - Controls in LayoutBar (always visible), not EditorTabBar (conditional) → `.safeword/learnings/persistent-ui.md`
279
+ - **Electron Renderer Context** - Renderer = browser, not Node.js; use `split(/[/\\]/)` for paths → `.safeword/learnings/electron-contexts.md`
280
+
281
+ **Additional gotchas:**
282
+ - Tab state timing: Add tab first (trigger render), wait 50ms, load content
283
+ - File validation: Whitelist extensions before operations
284
+ ````
285
+
286
+ **Pattern:** Bold name + one-sentence summary + optional link
287
+
288
+ ---
289
+
290
+ ## Examples: What Goes Where
291
+
292
+ ### ✅ Global (.safeword/learnings/)
293
+
294
+ **Learning:** "React useState updates are async - use useEffect for side effects"
295
+
296
+ **Why global:** Applies to ANY React project
297
+
298
+ **File:** `.safeword/learnings/react-state-async.md`
299
+
300
+ ---
301
+
302
+ ### ✅ Project Architecture (SAFEWORD.md)
303
+
304
+ **Learning:** "Why Zustand over Redux?"
305
+
306
+ **Why SAFEWORD.md:** Architectural decision unique to this project
307
+
308
+ **Location:** `SAFEWORD.md` → Architecture Decisions section
309
+
310
+ ```markdown
311
+ ### Why Zustand over Redux/MobX?
312
+
313
+ **Decision:** Zustand for all UI state
314
+
315
+ **Why:**
316
+
317
+ - Single-user desktop app = simple state
318
+ - 1KB vs Redux's 10KB+ boilerplate
319
+ - Hooks-based, TypeScript-first
320
+
321
+ **Trade-off:** No time-travel debugging, but not needed
322
+
323
+ **Gotcha:** NEVER import stores in store definitions (circular deps)
324
+ ```
325
+
326
+ ---
327
+
328
+ ### ✅ Project Learning (.safeword/learnings/)
329
+
330
+ **Learning:** "UI controls must be in persistent areas, not conditional components"
331
+
332
+ **Why learnings/:** Applies to multiple features (layout, toolbar, status) in THIS project
333
+
334
+ **File:** `.safeword/learnings/persistent-ui.md`
335
+
336
+ **Cross-ref:** Link from `SAFEWORD.md` → Common Gotchas
337
+
338
+ ---
339
+
340
+ ### ❌ Archive (.safeword/learnings/archive/)
341
+
342
+ **Learning:** "Electron tests failed because forgot to build"
343
+
344
+ **Why archive:** One-time gotcha - after learning once, don't need full narrative
345
+
346
+ **File:** `.safeword/learnings/archive/electron-build-forgotten.md`
347
+
348
+ **Note:** Short gotcha goes in SAFEWORD.md: "Electron tests use built files - run `npm run build` first"
349
+
350
+ ---
351
+
352
+ ## When Claude Should Suggest Extraction
353
+
354
+ **High confidence - Suggest IMMEDIATELY DURING debugging:**
355
+
356
+ - Observable debugging complexity (5+ debug cycles, 3+ error states, user says "stuck")
357
+ - Just discovered gotcha not in official docs
358
+ - Just found anti-pattern (violated best practice)
359
+ - Say: "I notice this pattern could save time on future work. Should I extract a learning after we fix this?"
360
+
361
+ **Medium confidence - Ask AFTER completing task:**
362
+
363
+ - "I noticed [pattern X] during implementation - should I document this as a learning?"
364
+
365
+ **Low confidence - Don't suggest:**
366
+
367
+ - Simple fix (1 debug cycle, typo, user says "quick fix")
368
+ - Well-documented in official library docs
369
+ - One-off implementation detail
370
+
371
+ ---
372
+
373
+ ## Iteration & Refinement
374
+
375
+ **Living Documentation**: This process evolves with your needs.
376
+
377
+ **Review Cycle**:
378
+
379
+ 1. **Monthly**: Review existing learnings for relevance
380
+ 2. **Quarterly**: Archive obsolete learnings (technology changed, pattern no longer used)
381
+ 3. **Per feature**: After major features, assess if new learnings emerged
382
+
383
+ **Test the Process**:
384
+
385
+ - Did extracting this learning actually help on the next feature?
386
+ - Are learnings being referenced in future conversations?
387
+ - Are the examples clear and actionable?
388
+
389
+ **Remove When**:
390
+
391
+ - Technology deprecated (e.g., "Webpack 4 gotchas" when using Vite)
392
+ - Pattern no longer used (e.g., class components → functional components)
393
+ - Merged into official documentation (library now documents the gotcha)
394
+
395
+ **Refactor When**:
396
+
397
+ - Multiple learnings cover similar topics → consolidate
398
+ - Learning file >200 lines → split into focused topics
399
+ - Examples are outdated → update or remove
400
+ - Wording is unclear → simplify
401
+
402
+ **Feedback Loop**:
403
+
404
+ - After suggesting extraction: Note if user accepted or declined
405
+ - After user accepts: Monitor if learning is referenced in future sessions
406
+ - Adjust suggestion threshold based on acceptance rate (if <30% accepted, raise the bar)
407
+
408
+ ---
409
+
410
+ ## Workflow Integration
411
+
412
+ ### During Development
413
+
414
+ 1. **Recognize trigger** - Spent 45 min debugging race condition
415
+ 2. **Assess scope** - Forward-looking? (YES) Global or project? (Project)
416
+ 3. **Choose location** - Needs examples → `.safeword/learnings/race-conditions.md`
417
+ 4. **Extract** - Use template, write before/after examples
418
+ 5. **Cross-reference** - Add to SAFEWORD.md Common Gotchas
419
+
420
+ ### After Completing Feature
421
+
422
+ 1. **Review** - Did we learn anything reusable?
423
+ 2. **Extract** - If threshold met (>30min debug, non-obvious pattern)
424
+ 3. **Update** - Add SAFEWORD.md cross-reference if needed
425
+ 4. **Commit** - Include learning in commit message
426
+
427
+ ---
428
+
429
+ ## Anti-Patterns (Don't Extract)
430
+
431
+ ❌ **Well-documented in official docs**
432
+
433
+ - "React useState is async" → Already in React docs
434
+
435
+ ❌ **One-line fixes without context**
436
+
437
+ - "Changed `==` to `===`" → Trivial
438
+
439
+ ❌ **Implementation without principle**
440
+
441
+ - "File X uses pattern Y" → No reusable insight
442
+
443
+ ❌ **Opinions without justification**
444
+
445
+ - "Prefer tabs over spaces" → Not a gotcha
446
+
447
+ ❌ **Debugging steps without lesson**
448
+
449
+ - "Tried 5 things, #4 worked" → What's the takeaway?
450
+
451
+ ❌ **Extracting mid-debugging**
452
+
453
+ - Wait until fix is confirmed and working
454
+ - Premature extraction leads to incorrect learnings
455
+
456
+ ❌ **Forgetting to delete old code comments after extraction**
457
+
458
+ - Learning file should REPLACE inline code comments
459
+ - Keep code clean by removing debugging notes after documenting
460
+
461
+ ❌ **Keeping obsolete learnings**
462
+
463
+ - Remove when technology deprecated or pattern no longer used
464
+ - Archive instead of delete (move to archive/ with "OBSOLETE:" prefix)
465
+ - Update SAFEWORD.md references to point to replacement learning
466
+ - Example: "React class components gotchas" → OBSOLETE when project migrates to hooks
467
+
468
+ ---
469
+
470
+ ## Quick Reference
471
+
472
+ | Situation | Location | Example |
473
+ | --------------------- | ---------------------------------------- | -------------------------------- |
474
+ | Universal principle | `.safeword/learnings/` | React hooks, Electron patterns |
475
+ | Architecture decision | `SAFEWORD.md` → Architecture | Why Zustand? Why Electron-only? |
476
+ | Short gotcha | `SAFEWORD.md` → Gotchas | "Validate paths before file ops" |
477
+ | Detailed gotcha | `.safeword/learnings/` + SAFEWORD.md ref | Persistent UI, race conditions |
478
+ | One-time bug | `.safeword/learnings/archive/` | Forgot to build before testing |
479
+
480
+ ---
481
+
482
+ ## Directory Structure
483
+
484
+ ```
485
+ # Global learnings (all projects)
486
+ .safeword/learnings/
487
+ ├── react-state-async.md
488
+ ├── electron-ipc-patterns.md
489
+ └── typescript-strict-mode.md
490
+
491
+ # Project learnings (this project)
492
+ ./.safeword/learnings/
493
+ ├── persistent-ui.md
494
+ ├── electron-contexts.md
495
+ ├── milkdown-trailing-newlines.md
496
+ └── archive/
497
+ ├── electron-build-forgotten.md
498
+ └── test-grep-compatibility.md
499
+ ```
500
+
501
+ **File Size Guidelines**:
502
+
503
+ - Forward-looking learning: 50-150 lines (includes 2-3 examples)
504
+ - Debugging narrative: 30-100 lines (problem → investigation → solution)
505
+ - If >200 lines: Split into multiple focused learnings
506
+
507
+ **When to Split**:
508
+
509
+ ```
510
+ # TOO BIG (250 lines covering 3 separate concepts)
511
+ .safeword/learnings/electron-gotchas.md
512
+
513
+ # BETTER (3 focused files)
514
+ .safeword/learnings/electron-renderer-context.md (80 lines)
515
+ .safeword/learnings/electron-ipc-patterns.md (60 lines)
516
+ .safeword/learnings/electron-path-validation.md (50 lines)
517
+ ```
518
+
519
+ ---
520
+
521
+ ## Summary
522
+
523
+ This is a **living process** - iterate and refine based on what works.
524
+
525
+ **Core Principle**: Extract knowledge that **compounds over time**. Each learning should save time on 2+ future features.
526
+
527
+ **Decision Framework**:
528
+
529
+ 1. **Forward-looking?** → Extract (helps future work)
530
+ 2. **Global or project?** → Choose directory
531
+ 3. **Architectural or gotcha?** → Choose SAFEWORD.md or separate file
532
+ 4. **ALWAYS cross-reference** → Update SAFEWORD.md
533
+
534
+ **Continuous Improvement**:
535
+
536
+ - Monthly: Review existing learnings for relevance
537
+ - Quarterly: Archive obsolete learnings
538
+ - Per feature: Assess if new learnings emerged
539
+ - Test: Did extracting this actually help on the next feature?
540
+
541
+ **When in Doubt**:
542
+
543
+ - Extract more rather than less (can archive later)
544
+ - Prefer separate file over inline comments (keeps code clean)
545
+ - Update immediately while fresh (don't defer to "later")
546
+
547
+ **Maintenance**:
548
+
549
+ - Remove when technology deprecated or pattern no longer used
550
+ - Refactor when multiple learnings cover similar topics (consolidate)
551
+ - Split when learning file >200 lines (focus on single concept)
552
+ - Update SAFEWORD.md references when learnings move or merge