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,776 @@
1
+ # Global Instructions for AI Coding Agents
2
+
3
+ This file provides core guidance for all AI coding agent sessions. Organized modularly for maintainability.
4
+
5
+ ---
6
+
7
+ ## Planning Documentation Location
8
+
9
+ **All planning markdown files go in `.safeword/planning/` at project root:**
10
+
11
+ - User stories → `.safeword/planning/user-stories/`
12
+ - Test definitions → `.safeword/planning/test-definitions/`
13
+ - Design docs → `.safeword/planning/design/`
14
+ - Issue capture → `.safeword/planning/issues/`
15
+
16
+ **Archive completed work:** When planning docs are completed and no longer actively referenced, move to:
17
+
18
+ - `.safeword/planning/user-stories/archive/`
19
+ - `.safeword/planning/test-definitions/archive/`
20
+ - `.safeword/planning/design/archive/`
21
+ - `.safeword/planning/issues/archive/`
22
+
23
+ **Why archive:** Prevents bloat in active planning folders while preserving history for reference.
24
+
25
+ **Fallback:** If project uses `docs/` structure instead, follow existing convention.
26
+
27
+ ---
28
+
29
+ ## Setup Scripts (Project Initialization)
30
+
31
+ **Purpose:** Self-contained setup scripts for installing Claude Code hooks and configurations in your projects.
32
+
33
+ **Available scripts:**
34
+
35
+ - `setup-safeword.sh` - **One-command installer** (copies guides/templates, planning/tickets/learnings, adds triggers)
36
+ - `setup-claude.sh` - Sets up Claude hooks, Arcade MCP gateway, CLAUDE.md trigger
37
+ - `setup-linting.sh` - Auto-linting on file changes (ESLint + Prettier)
38
+ - `setup-quality.sh` - Quality review prompts (Stop hook) and settings
39
+
40
+ **Usage:**
41
+
42
+ **One-command setup (recommended):**
43
+
44
+ ```bash
45
+ cd /path/to/your/project
46
+ bash ./framework/scripts/setup-safeword.sh # Install SAFEWORD structure + docs
47
+ bash ./framework/scripts/setup-claude.sh # Install Claude hooks (+ MCP gateway)
48
+ ```
49
+
50
+ **Auto-detection:** Automatically detects project type from package.json and config files:
51
+
52
+ - Next.js → if next in dependencies (ESLint + React plugins)
53
+ - Electron → if electron in dependencies
54
+ - Astro → if astro in dependencies
55
+ - React → if react in dependencies
56
+ - TypeScript → if typescript in dependencies or tsconfig.json exists
57
+ - Minimal → otherwise
58
+
59
+ **Individual scripts (advanced):**
60
+
61
+ ```bash
62
+ cd /path/to/your/project
63
+ bash ./framework/scripts/setup-linting.sh --typescript # Linting only
64
+ bash ./framework/scripts/setup-quality.sh # Quality review only
65
+ ```
66
+
67
+ **Linting:** Auto-detects TypeScript, React, Astro from package.json.
68
+
69
+ - Two-file architecture:
70
+ - `.safeword/eslint/eslint-base.mjs` - Auto-generated every run (DO NOT EDIT)
71
+ - `eslint.config.mjs` - Your config (customize freely, never overwritten)
72
+ - After adding/removing frameworks: just re-run `bash setup-linting.sh`
73
+ - Override detection: `--no-typescript`, `--no-react`, `--no-astro`
74
+
75
+ **What they create:**
76
+
77
+ - `.safeword/SAFEWORD.md` - Global patterns and workflows (copied from this file)
78
+ - `.safeword/guides/` - Reference documentation
79
+ - `.claude/hooks/` - Hook scripts (with version comments)
80
+ - `.claude/commands/` - Slash commands (`/lint`, `/quality-review`)
81
+ - `.claude/settings.json` - Hook configuration (appends to existing)
82
+ - `SAFEWORD.md` or `CLAUDE.md` - Project context file with ALWAYS trigger for @./.safeword/SAFEWORD.md
83
+ - If CLAUDE.md exists → prepends trigger
84
+ - If SAFEWORD.md exists → ensure it references @./.safeword/SAFEWORD.md
85
+ - If neither exists → creates SAFEWORD.md with trigger
86
+ - Config files if needed (`eslint.config.mjs`, `.prettierrc`)
87
+
88
+ **Key features:**
89
+
90
+ - ✅ **Fully standalone** - All files copied to project, no external dependencies
91
+ - ✅ **Version tracking** - Generated files include version comments
92
+ - ✅ **Idempotent** - Safe to run multiple times, won't duplicate hooks
93
+ - ✅ **Append-only** - Preserves existing custom hooks
94
+ - ✅ **Order-independent** - Can run scripts in any order
95
+
96
+ **Documentation:**
97
+
98
+ - Consolidated setup guide: `README.md` (this folder)
99
+
100
+ **For teams:**
101
+
102
+ 1. Get setup scripts (clone repo temporarily or download scripts)
103
+ 2. In each project, run one command:
104
+ ```bash
105
+ cd /path/to/project
106
+ bash ./framework/scripts/setup-safeword.sh # One command, full setup
107
+ ```
108
+ 3. **Result**: Project becomes standalone with:
109
+ - `.safeword/SAFEWORD.md` - Global patterns (copy of this file)
110
+ - `.safeword/guides/` - Reference documentation
111
+ - `.claude/` - Hooks and commands
112
+
113
+ - `SAFEWORD.md` or `CLAUDE.md` - Project context with @./.safeword/SAFEWORD.md reference
114
+
115
+ 4. **COMMIT to repo**: Commit `.safeword/` and `.claude/` for team consistency
116
+ 5. **Delete source**: Can delete setup scripts/repo after running - project is fully portable
117
+
118
+ ---
119
+
120
+ ## Ticket System (Context Anchor for Non-Trivial Work)
121
+
122
+ **Purpose:** Tickets serve as persistent memory to prevent context loss when work becomes complex, requires multiple attempts, or might spiral.
123
+
124
+ **Not for archival** - Tickets are session anchors to prevent LLM loops and confusion.
125
+
126
+ **Location:** `.safeword/tickets/`
127
+
128
+ **Naming convention:** `{id}-{slug}.md`
129
+
130
+ - Example: `001-fix-login-bug.md`, `002-add-oauth.md`, `003-debug-slow-query.md`
131
+ - Planning docs (if needed) share same prefix: `002-add-oauth.md` in planning subfolders
132
+
133
+ **Minimal structure:**
134
+
135
+ ```markdown
136
+ ---
137
+ id: 001
138
+ status: in_progress
139
+ created: 2025-11-24T19:00:00Z
140
+ last_modified: 2025-11-24T19:09:00Z
141
+ ---
142
+
143
+ # Fix Login Button Not Responding
144
+
145
+ **Goal:** Make login button respond to clicks
146
+
147
+ **Why:** Users can't log in - button does nothing on click
148
+
149
+ ## Work Log
150
+
151
+ - 2025-11-24T19:00:15Z Started: Investigating button click issue
152
+ - 2025-11-24T19:02:30Z Found: onClick handler missing in Button component
153
+ - 2025-11-24T19:05:00Z RED: Added test for button click (refs: tests/button.test.ts)
154
+ - 2025-11-24T19:08:15Z GREEN: Added onClick handler; test passing (refs: 7f3e2a9)
155
+ - 2025-11-24T19:09:00Z Complete: Button fixed, verified with test
156
+ ```
157
+
158
+ **For complex features, add optional sections:**
159
+
160
+ ```markdown
161
+ ### Planning Docs
162
+
163
+ - .safeword/planning/user-stories/002-oauth-login.md
164
+ - .safeword/planning/test-definitions/002-oauth-login.md
165
+
166
+ ### Scope
167
+
168
+ **In scope:** Google OAuth, account linking, token refresh
169
+ **Out of scope:** Other providers (separate ticket)
170
+
171
+ ### Acceptance Criteria
172
+
173
+ - [ ] All user stories completed
174
+ - [ ] Security review passed
175
+ ```
176
+
177
+ **Template:** Use `.safeword/templates/ticket-template.md` when creating a ticket.
178
+
179
+ **Work Log is critical:** Log immediately after each action. Re-read ticket frequently to prevent loops.
180
+
181
+ **When to create tickets (context-loss risk assessment):**
182
+
183
+ **Create ticket if ANY of these apply:**
184
+
185
+ - Work might require multiple attempts/approaches (styling bugs, performance issues)
186
+ - Work has multiple steps with dependencies (A must work before B)
187
+ - Investigation/debugging required (unknown cause, non-obvious solution)
188
+ - Anything that might cause you to lose context or loop mid-session
189
+
190
+ **Skip ticket if:**
191
+
192
+ - Obvious one-shot change (fix typo, update constant, change text label)
193
+ - Takes <2 minutes with zero risk of confusion or cascading issues
194
+ - No investigation needed, solution is clear
195
+
196
+ **Examples:**
197
+
198
+ - "Fix typo in README" → No ticket (obvious, one-shot)
199
+ - "Make button red" → Ticket (might break mobile, cascade issues)
200
+ - "Debug slow login" → Ticket (investigation needed, multiple hypotheses)
201
+ - "Add OAuth" → Ticket (complex, multi-step, planning docs needed)
202
+
203
+ **Relationship to planning docs:**
204
+
205
+ - **Ticket** = Context anchor (prevents loops, tracks attempts)
206
+ - **Planning docs** = Detailed specs for complex features (user stories, test definitions)
207
+ - **TodoWrite** = Task-level tracking within current work session
208
+
209
+ **Workflow:**
210
+
211
+ 1. **Create ticket:** `.safeword/tickets/{id}-{slug}.md`
212
+ 2. **Fill in Goal + Why** (one sentence each) - This is your anchor
213
+ 3. **Add initial work log entry:** "Started: [task]"
214
+ 4. **Re-read ticket before EVERY significant action** - Check what you're trying to do
215
+ 5. **Log immediately** after each attempt, finding, commit, or blocker
216
+ 6. **For complex features:** Add planning docs, reference them in optional sections
217
+ 7. **When stuck:** Re-read work log - what have you tried? What's the goal?
218
+ 8. **When complete:** Log final entry, update status to `done`, ask user to confirm
219
+ 9. **After confirmation:** Move to `.safeword/tickets/completed/{id}-{slug}.md`
220
+
221
+ **CRITICAL:** NEVER mark ticket as `done` or archive without explicit user confirmation. User must verify:
222
+
223
+ - All acceptance criteria met
224
+ - All tests passing
225
+ - Feature works as expected
226
+ - No regressions introduced
227
+
228
+ **Archiving:**
229
+
230
+ - Completed tickets → `.safeword/tickets/completed/`
231
+ - Blocked/cancelled tickets → `.safeword/tickets/archived/`
232
+ - Active tickets stay in `.safeword/tickets/`
233
+
234
+ **Why confirm:** Prevents premature closure and ensures quality standards met.
235
+
236
+ ---
237
+
238
+ ## Feature Development Workflow (CRITICAL - Always Follow)
239
+
240
+ **When to read:** ALWAYS - Before starting ANY new feature, bug fix, or code change. This is the entry point for all development work.
241
+
242
+ ### Starting a New Feature
243
+
244
+ **When user requests a new feature or references an issue number:**
245
+
246
+ **IN ORDER:**
247
+
248
+ **0. Check for Ticket / Create If Needed** (context-loss prevention)
249
+
250
+ - Search `.safeword/tickets/` for matching ticket file
251
+ - **If found:**
252
+ - **Read ticket first** - What's the goal? What have I tried?
253
+ - Check work log for previous attempts/findings
254
+ - Log: "Resumed work on [task]"
255
+ - **Re-read ticket before each significant action**
256
+ - For complex features: Follow planning docs if referenced
257
+ - **If not found:**
258
+ - **Assess context-loss risk:**
259
+ - Obvious one-shot (<2 min, no investigation)? → Skip ticket, skip to TDD (step 4)
260
+ - Might require multiple attempts? → Create ticket, skip to TDD (step 4)
261
+ - Investigation/debugging needed? → Create ticket, skip to TDD (step 4)
262
+ - Complex feature (multi-story)? → Create ticket, continue to planning docs (step 1)
263
+
264
+ 1. **User Stories + Technical Constraints** - Search `.safeword/planning/user-stories/` or `docs/user-stories/`
265
+ - Not found → Ask user if they exist elsewhere or offer to create
266
+ - Found → Read them (including Technical Constraints section)
267
+ - **Technical Constraints:** Non-functional requirements (performance, security, compatibility) that inform test definitions
268
+ - **Guide:** `@./.safeword/guides/user-story-guide.md`
269
+
270
+ 2. **Test Definitions** - Search `.safeword/planning/test-definitions/` or `docs/test-definitions/`
271
+ - Not found → Ask user if they exist elsewhere or offer to create
272
+ - Found → Read them
273
+ - **Guide:** `@./.safeword/guides/test-definitions-guide.md`
274
+
275
+ 3. **Design Doc** (complex features only) - Search `.safeword/planning/design/` or `docs/design/`
276
+ - Complex = >3 components, spans 2+ user stories, new data model, or architectural decisions
277
+ - Not found → Ask if needed, create if yes
278
+ - Found → Read it
279
+ - **Guide:** `@./.safeword/guides/design-doc-guide.md`
280
+
281
+ 4. **Follow STRICT TDD Workflow** (RED → GREEN → REFACTOR)
282
+ - Write failing tests first (RED phase)
283
+ - Implement minimum code to pass (GREEN phase)
284
+ - Refactor while keeping tests green
285
+ - **Workflow:** `@./.safeword/guides/testing-methodology.md` (comprehensive TDD guidance and test type decision tree)
286
+
287
+ 5. **Update Ticket** (if applicable)
288
+ - **Re-read ticket frequently** - Before each action, check: What's the goal? What have I tried?
289
+ - **Log immediately** after each action - Don't batch; log as you go
290
+ - Log: attempts (tried X, result Y), findings (found Z), commits, blockers, decisions
291
+ - When work complete: Log final entry, update status to `done`
292
+ - **Ask user to confirm** completion before archiving
293
+ - After confirmation: Move to `.safeword/tickets/completed/`
294
+
295
+ **IMPORTANT:** Do not skip to implementation without user stories and test definitions. Follow TDD strictly.
296
+
297
+ **Edge cases:**
298
+
299
+ - User stories exist but test definitions don't → Create test definitions before implementation
300
+ - User stories missing Technical Constraints → Add constraints before test definitions
301
+ - Test definitions exist but user stories don't → Ask if user stories needed
302
+ - Neither exist → Create both before implementation
303
+ - Ticket references non-existent planning docs → Create them first
304
+
305
+ ---
306
+
307
+ ### Commit Frequently
308
+
309
+ **Commit early, commit often:** Small, atomic commits after each meaningful change.
310
+
311
+ **When to commit:**
312
+
313
+ - After each test passes (GREEN phase)
314
+ - Before refactoring (safe point to revert)
315
+ - After successful refactor
316
+ - When switching context or tasks
317
+ - After completing a logical unit of work
318
+
319
+ **Why:** Prevents work loss, enables easy rollback, creates reviewable history.
320
+
321
+ ---
322
+
323
+ ### When to Update Architecture Docs
324
+
325
+ **Update project/package ARCHITECTURE.md when:**
326
+
327
+ - Making technology choices (state management, database, frameworks)
328
+ - Designing data models or schemas
329
+ - Establishing project-wide patterns/conventions
330
+ - Discovering architectural insights during implementation
331
+ - Recording "why" behind major decisions
332
+
333
+ **Use Design Doc instead when:**
334
+
335
+ - Implementing a specific feature
336
+ - Documenting component interactions for one feature
337
+ - Feature-specific technical decisions
338
+ - Implementation details (not project-wide principles)
339
+
340
+ **Quick Decision Matrix:**
341
+
342
+ | Question | Architecture Doc | Design Doc |
343
+ | --------------------------- | ---------------- | ------------- |
344
+ | Tech/framework choice? | ✅ | — |
345
+ | Data model design? | ✅ | References it |
346
+ | New feature implementation? | — | ✅ |
347
+ | Component breakdown? | — | ✅ |
348
+
349
+ **Tie-breaking rule:** If decision affects 2+ features or multiple developers → Architecture doc. If feature-specific only → Design doc.
350
+
351
+ **Reference:** `@./.safeword/guides/architecture-guide.md`
352
+
353
+ ---
354
+
355
+ ### Layers & Boundaries
356
+
357
+ **When to read:**
358
+
359
+ - Setting up code organization for a new project
360
+ - Questions about layer structure (app, domain, infra, shared)
361
+ - Dependency rules between layers
362
+ - Setting up `eslint-plugin-boundaries` for enforcement
363
+ - Architectural boundary violations in code review
364
+
365
+ 4-layer architecture (app, domain, infra, shared), allowed dependency matrix, and static enforcement via ESLint.
366
+
367
+ **Guide:** `@./.safeword/guides/architecture-guide.md` → Layers & Boundaries section
368
+
369
+ ---
370
+
371
+ ### Architecture Review (LLM)
372
+
373
+ **When to read:**
374
+
375
+ - Running semantic architecture review on code changes
376
+ - Setting up pre-commit hook for architecture enforcement
377
+ - Setting up CI workflow for PR architecture checks
378
+ - Understanding arch-review verdicts (clean/minor/refactor_needed)
379
+ - Checking for: god modules, leaky abstractions, misplaced logic, tight coupling
380
+
381
+ **Script:** `.safeword/scripts/arch-review.sh`
382
+ **Prompt:** `.safeword/prompts/arch-review.md`
383
+ **CI Template:** `.safeword/templates/ci/architecture-check.yml`
384
+
385
+ ---
386
+
387
+ ### Creating Documentation (Explicit User Requests)
388
+
389
+ **Note**: When user explicitly requests documentation, skip the workflow questions and create directly.
390
+
391
+ **User Stories:**
392
+
393
+ - **Trigger (Create):** User says "Create user stories for issue #N" or "Create user stories for [feature]"
394
+ - **Trigger (Review):** User asks "Is this story good?" or "Review my user story"
395
+ - **Trigger (Constraint Review):** User asks "Is this constraint good?" or "Review my constraints"
396
+ - Skip the "Do user stories exist?" question (user is explicitly requesting creation)
397
+ - **Include Technical Constraints:** Fill in performance, security, compatibility, data, dependencies, infrastructure constraints that will inform test definitions
398
+ - **Template:** `@./.safeword/templates/user-stories-template.md`
399
+ - **Guide:** `@./.safeword/guides/user-story-guide.md`
400
+
401
+ **Test Definitions:**
402
+
403
+ - **Trigger:** User says "Create test definitions for issue #N" or "Create test definitions for [feature]"
404
+ - Skip the "Do test definitions exist?" question (user is explicitly requesting creation)
405
+ - **Template:** `@./.safeword/templates/test-definitions-feature.md`
406
+ - **Guide:** `@./.safeword/guides/test-definitions-guide.md`
407
+
408
+ **Design Doc:**
409
+
410
+ - **Trigger:** User says "Create design doc for [feature]" or "Design [system/component]"
411
+ - Skip the "Does design doc exist?" question (user is explicitly requesting creation)
412
+ - **Prerequisites:** Verify user stories and test definitions exist first (create if not)
413
+
414
+ **Required sections checklist:**
415
+
416
+ - [ ] **Architecture** — 1-2 paragraphs on high-level approach
417
+ - [ ] **Components** — [N] and [N+1] examples with name, responsibility, interface, dependencies
418
+ - [ ] **User Flow** — Step-by-step with concrete examples
419
+ - [ ] **Key Decisions** — What, why, trade-off, alternatives considered
420
+ - [ ] **Data Model** — (if applicable) State shape, relationships
421
+ - [ ] **Component Interaction** — (if applicable) How components communicate
422
+ - [ ] **Implementation Notes** — (if applicable) Constraints, error handling, gotchas
423
+
424
+ - **Template:** `@./.safeword/templates/design-doc-template.md`
425
+ - **Guide:** `@./.safeword/guides/design-doc-guide.md`
426
+
427
+ **Architecture Doc:**
428
+
429
+ - **Trigger (Create):** Starting a new project/package, or no `ARCHITECTURE.md` exists yet
430
+ - **Trigger (Update):** User says "Update architecture doc" or "Document [architectural decision]"
431
+ - **Trigger (Implicit):** After discussing architectural decisions, proactively ask: "Should I document this in ARCHITECTURE.md?"
432
+ - **Recognize architectural discussions when user mentions:**
433
+ - Technology choices (state management, database, frameworks)
434
+ - Data model design
435
+ - Project-wide patterns/conventions
436
+
437
+ **Required sections checklist** (verify all present when creating/reviewing):
438
+
439
+ - [ ] **Header** — Version, Last Updated, Status (Production/Design/Proposed)
440
+ - [ ] **Table of Contents** — Section links
441
+ - [ ] **Overview** — Technology choices, data model philosophy, high-level architecture
442
+ - [ ] **Data Architecture Principles** — What, Why, Trade-off for each principle
443
+ - [ ] **Data Model / Schema** — Tables, types, relationships
444
+ - [ ] **Component Design** — Major components and responsibilities
445
+ - [ ] **Data Flow Patterns** — How data moves through the system
446
+ - [ ] **Key Decisions** — What, Why, Trade-off, Alternatives Considered
447
+ - [ ] **Best Practices** — Domain-specific patterns
448
+ - [ ] **Migration Strategy** — How to evolve architecture
449
+ - [ ] **Code References** — Link to implementations (`src/file.ts:line` or function names)
450
+
451
+ **Anti-patterns to avoid:**
452
+
453
+ - ❌ ADR sprawl (many separate files) → consolidate into one doc
454
+ - ❌ Missing rationale → every decision needs "Why" with specifics
455
+ - ❌ Implementation details → keep high-level principles only
456
+
457
+ - **Template:** `@./.safeword/templates/architecture-template.md`
458
+ - **Guide:** `@./.safeword/guides/architecture-guide.md`
459
+
460
+ **Data Architecture Doc:**
461
+
462
+ - **Trigger (Explicit):** User says "Document data architecture" or "Design data model"
463
+ - **Trigger (Implicit):** When discussing database schema, data flows, or storage decisions
464
+ - **Recognize data architecture discussions when user mentions:**
465
+ - Database/storage technology choices
466
+ - Schema design (entities, relationships, constraints)
467
+ - Data validation rules, access policies, lifecycle
468
+ - Data flows (sources, transformations, destinations)
469
+ - **Section in ARCHITECTURE.md or separate file** - Depends on project complexity
470
+ - **Guide:** `@./.safeword/guides/data-architecture-guide.md`
471
+
472
+ ---
473
+
474
+ ## TodoWrite Best Practices
475
+
476
+ **When to use:** Complex multi-step tasks (3+ distinct steps), non-trivial tasks requiring planning, or when user provides multiple tasks.
477
+
478
+ **Critical rules:**
479
+
480
+ - ✓ **Create as first tool call** - For multi-step tasks, create TODO list before starting work
481
+ - ✓ **Use VERY frequently** - Track tasks and give user visibility into progress
482
+ - ✓ **Mark in_progress BEFORE work** - Ideally only ONE task in_progress at a time
483
+ - ✓ **Complete immediately** - Mark completed as soon as done, don't batch
484
+ - ✓ **Two forms required** - `content` (imperative: "Run tests") + `activeForm` (continuous: "Running tests")
485
+ - ✓ **Replace entire list** - Updates replace complete list, not incremental changes
486
+
487
+ **When NOT to use:**
488
+
489
+ - Single straightforward task
490
+ - Trivial operations (1-2 simple steps)
491
+ - Purely conversational requests
492
+
493
+ **Example:**
494
+
495
+ ```json
496
+ {
497
+ "todos": [
498
+ {
499
+ "content": "Write failing tests",
500
+ "status": "completed",
501
+ "activeForm": "Writing failing tests"
502
+ },
503
+ {
504
+ "content": "Implement minimum code to pass",
505
+ "status": "in_progress",
506
+ "activeForm": "Implementing minimum code"
507
+ },
508
+ {
509
+ "content": "Refactor while keeping tests green",
510
+ "status": "pending",
511
+ "activeForm": "Refactoring code"
512
+ }
513
+ ]
514
+ }
515
+ ```
516
+
517
+ ---
518
+
519
+ ## Response Format (CRITICAL - Always Include)
520
+
521
+ At the end of EVERY response, include a JSON summary with this exact structure:
522
+
523
+ ```json
524
+ {"proposedChanges": boolean, "madeChanges": boolean, "askedQuestion": boolean}
525
+ ```
526
+
527
+ Where (all fields describe **this response only**, not cumulative):
528
+
529
+ - `proposedChanges`: `true` if you suggested/proposed changes to specific files **in this response**
530
+ - `madeChanges`: `true` if you **modified files in this response** using Write/Edit tools
531
+ - `askedQuestion`: `true` if you asked the user a question and need their response before proceeding
532
+
533
+ Examples:
534
+
535
+ - Discussed approach only: `{"proposedChanges": false, "madeChanges": false, "askedQuestion": false}`
536
+ - Proposed edits but waiting for approval: `{"proposedChanges": true, "madeChanges": false, "askedQuestion": false}`
537
+ - Made edits directly: `{"proposedChanges": false, "madeChanges": true, "askedQuestion": false}`
538
+ - Proposed AND made edits: `{"proposedChanges": true, "madeChanges": true, "askedQuestion": false}`
539
+ - Asked user a question: `{"proposedChanges": false, "madeChanges": false, "askedQuestion": true}`
540
+ - **Quality review response** (no new changes): `{"proposedChanges": false, "madeChanges": false, "askedQuestion": false}`
541
+
542
+ ---
543
+
544
+ ## Avoid Over-Engineering
545
+
546
+ **Trigger:** Before adding any abstraction, utility, or "future-proofing" code.
547
+
548
+ **Decision:** Is this the simplest solution that works?
549
+
550
+ | ❌ Over-engineering | ✅ Keep it simple |
551
+ | --------------------------------- | ------------------- |
552
+ | Utility class for one function | Single function |
553
+ | Factory/builder for simple object | Direct construction |
554
+ | Config file for 2 options | Hardcode or params |
555
+ | Abstract class with one impl | Concrete class |
556
+
557
+ **When to push back:** If feature adds >50 lines for "nice to have", ask user if essential now.
558
+
559
+ **Self-documenting code:** Use descriptive names (`calculateTotalWithTax` not `calcTot`). Comment only non-obvious logic.
560
+
561
+ **Error handling:** Never swallow errors. Include context: `Failed to read ${filePath}: ${e.message}`
562
+
563
+ **Debug logging:** Log actual vs expected values. Remove debug logs after fixing.
564
+
565
+ **Cross-platform:** Use `path.join()` not string concat. No hardcoded `/` or `\`.
566
+
567
+ **Guide:** `@./.safeword/guides/code-philosophy.md`
568
+
569
+ ---
570
+
571
+ ## Self-Testing (CRITICAL - Always Test Your Own Work)
572
+
573
+ **The user's time is precious. Always test your own work before declaring it complete.**
574
+
575
+ **Core principle:** NEVER ask the user to verify or test something you can test yourself. Run tests, verify fixes, and confirm functionality before reporting completion.
576
+
577
+ **When to self-test:**
578
+
579
+ - ✓ **After fixing bugs** - Run the relevant tests to verify the fix works
580
+ - ✓ **After implementing features** - Run all affected tests (unit, integration, E2E)
581
+ - ✓ **After making changes** - Verify the change has the intended effect
582
+ - ✓ **Before declaring completion** - Always run tests yourself, don't ask the user to do it
583
+ - ✓ **When uncertain** - If you're not sure it works, TEST IT before claiming success
584
+
585
+ **Tools for self-testing:**
586
+
587
+ - E2E tests: `pnpm test:e2e` or specific test files
588
+ - Unit tests: `pnpm test` or `pnpm test:unit`
589
+ - Integration tests: `pnpm test:integration`
590
+ - Manual verification: Use curl, check browser console, verify API responses
591
+ - Dev server: Check compilation errors, hot reload, runtime errors
592
+
593
+ **Capturing test output:**
594
+
595
+ Don't pipe through `head`/`tail` directly—capture to a timestamped log file first, then analyze:
596
+
597
+ ```bash
598
+ # ✅ GOOD - Capture to file, then analyze
599
+ mkdir -p /tmp/test-logs
600
+ LOG=/tmp/test-logs/$(date +%s)-e2e.log
601
+ pnpm test:e2e 2>&1 | tee $LOG
602
+ tail -100 $LOG # Check summary
603
+ cat $LOG # Full output if needed
604
+
605
+ # ❌ BAD - Can't dig deeper without re-running tests
606
+ pnpm test:e2e 2>&1 | tail -50
607
+ ```
608
+
609
+ **Anti-patterns:**
610
+
611
+ - ❌ **DON'T:** "I've made the changes. Please refresh your browser and test."
612
+ - ❌ **DON'T:** "The fix should work now. Can you verify?"
613
+ - ❌ **DON'T:** "Try it now and let me know if it works."
614
+
615
+ **Correct patterns:**
616
+
617
+ - ✅ **DO:** "I've fixed the issue. Let me run the tests to verify..." [runs tests] "Tests pass ✓"
618
+ - ✅ **DO:** "Fixed the bug. Running E2E tests to confirm..." [runs tests] "All tests passing ✓"
619
+ - ✅ **DO:** "Implemented the feature. Testing now..." [runs tests] "Tests confirm it works ✓"
620
+
621
+ **Example workflow:**
622
+
623
+ ```
624
+ 1. User reports bug: "Button doesn't enable when typing"
625
+ 2. Investigate and fix the bug
626
+ 3. Run tests yourself: AUTH_MODE=demo pnpm exec playwright test
627
+ 4. Verify tests pass
628
+ 5. Report to user: "Fixed. Tests confirm button now enables correctly ✓"
629
+ ```
630
+
631
+ **Edge cases:**
632
+
633
+ - If tests require special setup (API keys, credentials): Mention requirements but still run what you can
634
+ - If tests are slow (>5 min): Run them in background, show progress, report when done
635
+ - If no automated tests exist: Create them as part of the fix, then run them
636
+
637
+ **Remember:** The user should only test when they want to verify the UX/experience themselves, not to confirm your code works. Your code working is YOUR responsibility to verify.
638
+
639
+ **Before declaring complete:** Run self-review checklist (correctness, elegance, best practices, docs/versions, tests). Note any deferred issues.
640
+
641
+ ---
642
+
643
+ ## Code Philosophy & Practices
644
+
645
+ **When to read:** Before writing code, when making architectural decisions, or when unsure about coding standards and best practices.
646
+
647
+ **Documentation verification:** Before using any library API, check `package.json` for version and verify with Context7 or official docs. Training data is stale.
648
+
649
+ Core coding principles, testing philosophy (TDD), communication style, best practices, and tooling currency.
650
+
651
+ @./.safeword/guides/code-philosophy.md
652
+
653
+ ---
654
+
655
+ ## TDD Templates & Best Practices Reference
656
+
657
+ **When to read:** When creating user stories, test definitions, design docs, or evaluations. Provides templates and examples of good vs bad practices.
658
+
659
+ **Triggers:**
660
+
661
+ - Creating user stories, test definitions, or design docs
662
+ - User asks "Which template should I use?" or "What doc type for X?"
663
+ - Need examples of good vs bad user stories or tests
664
+
665
+ User story templates (As a X / Given-When-Then), test definition patterns, and concrete examples.
666
+
667
+ @./.safeword/guides/tdd-best-practices.md
668
+
669
+ ---
670
+
671
+ ## Testing Methodology
672
+
673
+ **When to read:** Before starting ANY feature (TDD workflow), when choosing test type (unit/integration/E2E/LLM eval), or when writing tests.
674
+
675
+ Comprehensive TDD workflow (RED → GREEN → REFACTOR), test pyramid, decision trees, async testing, project-specific docs guidance.
676
+
677
+ @./.safeword/guides/testing-methodology.md
678
+
679
+ ---
680
+
681
+ ## LLM Prompting Best Practices
682
+
683
+ **When to read:** When working with AI features, writing prompts, implementing LLM evaluations, or optimizing AI costs.
684
+
685
+ Prompt engineering, cost optimization (caching strategies), and testing AI outputs (LLM-as-judge).
686
+
687
+ @./.safeword/guides/llm-prompting.md
688
+
689
+ ---
690
+
691
+ ## Writing Instructions for LLMs
692
+
693
+ **When to read:** When creating or updating ANY documentation that LLMs will read (CLAUDE.md, AGENTS.md, user stories, test definitions, design docs, architecture docs, guides).
694
+
695
+ 13 core principles for LLM-consumable documentation: MECE decision trees, explicit definitions, concrete examples, no contradictions, edge cases explicit, actionable language, sequential decision trees, tie-breaking rules, lookup tables, no caveats in tables, percentages with context, specific technical terms, and re-evaluation paths.
696
+
697
+ @./.safeword/guides/llm-instruction-design.md
698
+
699
+ ---
700
+
701
+ ## AGENTS.md/CLAUDE.md File Structure & Maintenance
702
+
703
+ **When to read:** When creating or updating project AGENTS.md/CLAUDE.md files, organizing documentation, or setting up new projects.
704
+
705
+ How to write, organize, and maintain AGENTS.md/CLAUDE.md files across projects. Anti-patterns, examples, and modular approaches.
706
+
707
+ @./.safeword/guides/context-files-guide.md
708
+
709
+ ---
710
+
711
+ ## Project Memory
712
+
713
+ **Context:** After extracting learnings (see Learning Extraction section below), add them to project documentation for team knowledge sharing.
714
+
715
+ **Where to add:**
716
+
717
+ - Architecture decisions: Add to ARCHITECTURE.md (or AGENTS.md if no ARCHITECTURE.md exists)
718
+ - Common gotchas (1-2 sentences): Add to AGENTS.md → Common Gotchas section
719
+ - Detailed learnings (needs examples): Extract to `.safeword/learnings/` and cross-reference in SAFEWORD.md
720
+
721
+ **See:** Learning Extraction section below for full workflow
722
+
723
+ ---
724
+
725
+ ## Zombie Process Cleanup
726
+
727
+ **When to read:**
728
+
729
+ - Working on multiple projects simultaneously
730
+ - Port already in use errors (`EADDRINUSE`, `address already in use`)
731
+ - Stuck processes (dev server won't start, tests hang)
732
+ - Tech stacks: Next.js, Playwright, Vite, Expo
733
+
734
+ Port-based cleanup strategies, project-specific scripts, and multi-project isolation techniques.
735
+
736
+ @./.safeword/guides/zombie-process-cleanup.md
737
+
738
+ ---
739
+
740
+ ## Learning Extraction
741
+
742
+ **When to read:** When experiencing debugging complexity (5+ debug cycles, user says "stuck"), discovering gotchas, trying multiple approaches, or during significant implementation work. Use to determine if/where to extract learnings and check for existing learnings.
743
+
744
+ **Suggest extraction when you observe:**
745
+
746
+ 1. **Observable debugging complexity** - User says "stuck", 5+ debug cycles, 3+ error states, or 3+ files modified
747
+ 2. **Trial and error** - Tried 3+ different approaches
748
+ 3. **Undocumented gotcha** - Not in official library/framework docs
749
+ 4. **Integration struggle** - Two tools don't work together smoothly
750
+ 5. **Testing trap** - Tests pass but UX broken (or vice versa)
751
+ 6. **Architectural insight** - Discovered during implementation, not planned upfront
752
+
753
+ **CRITICAL: Before extracting, ALWAYS check for existing learnings** to prevent duplication:
754
+
755
+ - **Before debugging** - Check if similar issue has learning: `ls .safeword/learnings/*[technology]*.md`
756
+ - **When user mentions technology/pattern** - Check for `*hooks*.md`, `*electron*.md`, etc.
757
+ - **During architectural discussions** - Check for `*pattern*.md`, `*architecture*.md`
758
+ - **After suggesting extraction** - Check if learning already exists, update instead of duplicate
759
+
760
+ **When to reference existing learnings:**
761
+
762
+ - Found → Read and apply: "I found an existing learning about [concept] at [path]. Applying it now."
763
+ - Similar but different → Reference and note difference
764
+
765
+ **Where to extract:**
766
+
767
+ - `.safeword/learnings/[concept].md` - General patterns and best practices (React patterns, Git workflows, testing)
768
+ - `.safeword/learnings/[concept].md` - Project-specific (custom architecture, unique patterns for this codebase)
769
+
770
+ **Maintenance triggers:**
771
+
772
+ - Learning file >200 lines → Split into focused files
773
+ - Multiple learnings cover similar topic → Consolidate
774
+ - Technology deprecated → Archive with "OBSOLETE:" prefix
775
+
776
+ **Full workflow, templates, decision trees, and examples:** @./.safeword/guides/learning-extraction.md