safeword 0.2.3 → 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-3NGQ4NR5.js +0 -129
  184. package/dist/check-3NGQ4NR5.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-ORQHKDT2.js +0 -10
  190. package/dist/chunk-ORQHKDT2.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-Y6QTAW4O.js +0 -166
  197. package/dist/diff-Y6QTAW4O.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-RR4M334C.js +0 -266
  204. package/dist/setup-RR4M334C.js.map +0 -1
  205. package/dist/upgrade-6AR3DHUV.js +0 -134
  206. package/dist/upgrade-6AR3DHUV.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,405 @@
1
+ # Project Context Files (CLAUDE.md, CURSOR.md, AGENTS.md)
2
+
3
+ ## When to Create Context Files
4
+
5
+ Create the file(s) that best match your tooling. It’s okay to have more than one if different tools are used.
6
+
7
+ - `CLAUDE.md` (Claude-specific)
8
+ - Claude/Desktop or Claude Code-specific guidance (hooks, skills, MCP gateways)
9
+ - Prompts, behaviors, and non-obvious conventions for Claude
10
+ - `CURSOR.md` (Cursor-specific)
11
+ - Editor/extension conventions, quick commands, keybindings, gotchas for Cursor
12
+ - `AGENTS.md` (tool-agnostic)
13
+ - Generic “project context” consumed by multiple agents/editors
14
+
15
+ All project context files should:
16
+ - **CRITICAL:** Reference `.safeword/SAFEWORD.md` at the top
17
+ - Architecture decisions with "why" (not just "what")
18
+ - Design philosophy and conventions
19
+ - Common gotchas specific to this codebase
20
+ - Cross-references to subdirectory files
21
+
22
+ **Subdirectory files** (e.g., `tests/AGENTS.md`, `packages/app/CLAUDE.md`) - Create when:
23
+ - >3 unique rules that don't fit in root
24
+ - Working in that directory needs specialized context
25
+ - **Skip if:** Directory is straightforward or already covered in root
26
+
27
+ **Naming convention summary:**
28
+ - `CLAUDE.md` for Claude-specific guidance
29
+ - `CURSOR.md` for Cursor-specific guidance
30
+ - `AGENTS.md` for cross-agent compatibility (tests, docs, most projects)
31
+
32
+ ## SAFEWORD Trigger (Required)
33
+
34
+ **MANDATORY:** Every project-level context file (CLAUDE.md, CURSOR.md, AGENTS.md) must start with a trigger to SAFEWORD:
35
+
36
+ ```markdown
37
+ # Project Name - Developer Context
38
+
39
+ **⚠️ ALWAYS READ FIRST: @./.safeword/SAFEWORD.md**
40
+
41
+ The SAFEWORD.md file contains core development patterns, workflows, and conventions.
42
+ Read it BEFORE working on any task in this project.
43
+
44
+ ---
45
+
46
+ [Rest of project-specific content...]
47
+ ```
48
+
49
+ **Why:** `.safeword/SAFEWORD.md` contains universal workflows (TDD, feature development, etc.) that apply across all projects. Project files should only contain project-specific context.
50
+
51
+ ## Agent Context Auto-Loading Behavior
52
+
53
+ **How Context Loading Works:**
54
+
55
+ 1. Tools typically load a root context file (CLAUDE.md, CURSOR.md, AGENTS.md)
56
+ 2. Subdirectory context files may load when working inside those dirs
57
+ 3. Hierarchical loading (root + subdirectory) is common
58
+
59
+ **Example:**
60
+ ```
61
+ Working in: /project/src/feature/
62
+ Loaded context:
63
+ ✓ /project/CLAUDE.md (Claude-specific guidance)
64
+ ✓ /project/src/feature/AGENTS.md (feature-specific rules)
65
+ ```
66
+
67
+ **Design implication:** Subdirectory files should assume root context is available
68
+ - Use "See root SAFEWORD.md or AGENTS.md for architecture" cross-references
69
+ - Don't duplicate root content in subdirectory files
70
+ - Focus subdirectory files on specialized conventions for that area
71
+
72
+ ```markdown
73
+ ❌ BAD - tests/AGENTS.md duplicates root TDD workflow:
74
+ ## TDD Workflow
75
+ 1. Write failing tests first (RED)
76
+ 2. Implement minimum code (GREEN)
77
+ 3. Refactor while green
78
+
79
+ ✅ GOOD - tests/AGENTS.md references root:
80
+ ## Testing Conventions
81
+ See root AGENTS.md for TDD workflow. This file covers test-specific patterns.
82
+ ```
83
+
84
+ **Reliability note:** Auto-loading works best when you explicitly reference your file in conversation (e.g., "following the guidelines in CLAUDE.md"). Implicit automatic reference can be less reliable.
85
+
86
+ **Deprecated:** `*.local.md` is no longer recommended - use imports instead for better multi-worktree support
87
+
88
+ ## File Structure Pattern
89
+
90
+ ```
91
+ project/
92
+ ├─ SAFEWORD.md # Project context (references guides)
93
+ ├─ CLAUDE.md # Claude-specific context
94
+ ├─ CURSOR.md # Cursor-specific context (optional)
95
+ └─ tests/AGENTS.md # Test conventions (cross-agent)
96
+ ```
97
+
98
+ **Modular Approach (Recommended):**
99
+ ```
100
+ project/
101
+ ├─ AGENTS.md / CLAUDE.md # 50 lines: imports + structure
102
+ ├─ docs/architecture.md # 100 lines: architecture decisions
103
+ └─ docs/conventions.md # 80 lines: coding conventions
104
+ ```
105
+
106
+ Main context file imports modules:
107
+ ```markdown
108
+ @docs/architecture.md
109
+ @docs/conventions.md
110
+ ```
111
+
112
+ ## Content Guidelines
113
+
114
+ **Include:**
115
+ - "Why" over "what" - Explain architectural trade-offs, not features
116
+ - Project-specific conventions - Unique to THIS codebase
117
+ - Domain requirements - Specialized knowledge (game mechanics, industry standards, UX patterns)
118
+ - Concrete examples - Good vs bad patterns
119
+ - Gotchas - Common mistakes developers make HERE
120
+ - Cross-references - Link to subdirectories, don't duplicate
121
+
122
+ **Exclude:**
123
+ - Generic advice ("follow best practices")
124
+ - Feature lists (put in README.md)
125
+ - Setup instructions (put in README.md)
126
+ - Phase tracking (put in ROADMAP.md)
127
+ - API documentation (put in code comments)
128
+
129
+ ## Target Line Counts
130
+
131
+ - Root: 100-200 lines (architecture + philosophy)
132
+ - Subdirectories: 60-100 lines (focused conventions)
133
+ - Total project: <500 lines across all files
134
+ - **With imports:** Main file 50 lines, modules 100-150 lines each
135
+
136
+ **Rule:** If >200 lines, extract to subdirectory or use imports.
137
+
138
+ **File size:** Keep under 50KB for optimal performance (though no hard limit)
139
+
140
+ ## Anti-Patterns to Avoid
141
+
142
+ ❌ **Redundancy between root and subdirectory files** (#1 source of bloat)
143
+ - Don't list all stores in root if packages/web/AGENTS.md covers them
144
+ - Don't document testing patterns in root if tests/AGENTS.md exists
145
+ - Don't repeat gotchas - reference subdirectory for details
146
+ - Each fact stated exactly once, use cross-references elsewhere
147
+
148
+ ❌ **Implementation details in root file**
149
+ - File paths (store.ts:127-137) belong in subdirectory files
150
+ - Specific line numbers change frequently
151
+ - File trees and directory structures
152
+ - Line counts and feature status lists
153
+
154
+ ❌ **Testing sections in non-test files**
155
+ - Testing philosophy → tests/AGENTS.md (always)
156
+ - Test commands → tests/AGENTS.md or README.md
157
+ - Test patterns → tests/AGENTS.md
158
+
159
+ ❌ **User-facing documentation**
160
+ - Setup instructions → README.md
161
+ - Development commands → README.md
162
+ - Feature lists → ROADMAP.md
163
+ - API documentation → Code comments or separate docs
164
+
165
+ ❌ **Generic advice**
166
+ - "Use TypeScript" (not project-specific)
167
+ - "Follow best practices" (too vague)
168
+ - "Write tests" (duh - say WHICH tests for WHAT)
169
+
170
+ ❌ **Meta-commentary**
171
+ - "Last Updated: 2025-01-19"
172
+ - "This file was reduced from 634 → 152 lines"
173
+ - Commit history (that's what git is for)
174
+
175
+ ❌ **Outdated information**
176
+ - Revisit after major architectural changes
177
+ - Remove sections when they no longer apply
178
+ - Update cross-references when files move
179
+
180
+ ## Cross-Reference Pattern
181
+
182
+ **Root file:**
183
+ ```markdown
184
+ **Agents** (`app/src/agents/`) - LLM logic. See `/AGENTS.md`.
185
+ ```
186
+
187
+ **Subdirectory file:**
188
+ ```markdown
189
+ **Context:** Working with AI agents. See root `SAFEWORD.md`/`AGENTS.md` for architecture.
190
+ ```
191
+
192
+ **Import pattern:**
193
+ ```markdown
194
+ # Project Context
195
+
196
+ See @README for project overview and @package.json for available npm commands.
197
+
198
+ ## Architecture
199
+ @docs/architecture.md
200
+
201
+ ## Coding Standards
202
+ @.safeword/guides/llm-prompting.md
203
+
204
+ ## Git Workflow
205
+ Details in @docs/git-workflow.md
206
+ ```
207
+
208
+ **Import features:**
209
+ - **Relative paths:** `@docs/file.md` (relative to AGENTS.md location)
210
+ - **Absolute paths:** `@/path/to/file.md`
211
+ - **Home directory:** `@.safeword/guides/file.md` (personal conventions across all projects)
212
+ - **Recursive imports:** Imported files can import others (max depth: 5 hops)
213
+ - **Inline usage:** Can reference imports in text, not just standalone lines
214
+ - **Code blocks:** Imports ignored inside `` `code spans` `` and code blocks
215
+
216
+ ## Example: Well-Structured Root (AGENTS.md / CLAUDE.md / CURSOR.md)
217
+
218
+ ```markdown
219
+ # Project Name - Developer Context
220
+
221
+ **⚠️ ALWAYS READ FIRST: @./.safeword/SAFEWORD.md**
222
+
223
+ The SAFEWORD.md file contains core development patterns, workflows, and conventions.
224
+ Read it BEFORE working on any task in this project.
225
+
226
+ ---
227
+
228
+ Brief description. Current status.
229
+
230
+ ## Design Philosophy
231
+ 1. **Test-Driven Development (TDD):** Write tests before implementation
232
+ 2. **Core principle:** Why we chose this approach
233
+ 3. **Core principle:** Trade-offs we accepted
234
+
235
+ ## Architecture Decisions
236
+ ### Tech Choice 1
237
+ **Decision:** What we chose
238
+ **Why:** Reduces X, improves Y (specific numbers)
239
+ **Trade-off:** Harder to debug, but worth it for UX
240
+ **Gotcha:** Must do Z or it breaks
241
+
242
+ ## Domain Requirements
243
+
244
+ ### Game Mechanics (Blades in the Dark)
245
+ - Position/effect system (rulebook p.8-12)
246
+ - Fiction-first approach
247
+
248
+ **Key principles:**
249
+ - Position telegraphed before roll
250
+ - Consequences flow from fiction
251
+
252
+ ### Document Editor UX
253
+ - Performance <16ms per keystroke
254
+ - Standard OS text editing conventions
255
+
256
+ **Key principles:**
257
+ - Fast is a feature
258
+ - Don't reinvent native behavior
259
+
260
+ ## Common Gotchas
261
+ 1. **Thing:** Why it breaks (see Design Philosophy → Section)
262
+
263
+ ## File Organization
264
+ **Dir** (`path/`) - Purpose. See `path/AGENTS.md`.
265
+ ```
266
+
267
+ ## Maintenance
268
+
269
+ - Update when architecture changes
270
+ - Remove outdated sections immediately
271
+ - Consolidate if multiple files reference same concept
272
+ - Test: Can new developer understand "why" from reading this?
273
+ - **Use imports** to keep main file under 200 lines
274
+ - Verify loaded context matches intent (check hierarchical loading behavior)
275
+
276
+ ---
277
+
278
+ ## Domain Requirements Section (Optional)
279
+
280
+ **When to add:**
281
+ - Project has specialized domain knowledge (game mechanics, industry standards, UX patterns)
282
+ - Domain concerns are non-obvious from codebase alone
283
+ - You find yourself repeatedly explaining domain rules to AI
284
+
285
+ **When to skip:**
286
+ - Domain is obvious from code structure (REST API patterns)
287
+ - Tech stack IS the domain (generic CRUD app)
288
+ - Simple projects without specialized knowledge
289
+
290
+ **Structure (easy to parse):**
291
+ ```markdown
292
+ ## Domain Requirements
293
+
294
+ ### [Domain Name 1]
295
+ - [Key principle or rule]
296
+ - [Key principle or rule]
297
+ - [Resource reference if applicable]
298
+
299
+ **Key principles:**
300
+ - [Specific guideline with rationale]
301
+ - [Specific guideline with rationale]
302
+
303
+ ### [Domain Name 2]
304
+ - [Key principle or rule]
305
+ - [Key principle or rule]
306
+
307
+ **Key principles:**
308
+ - [Specific guideline with rationale]
309
+ ```
310
+
311
+ **Examples:**
312
+
313
+ ```markdown
314
+ ## Domain Requirements
315
+
316
+ ### Blades in the Dark Mechanics
317
+ - Position/effect system (BITD rulebook p.8-12)
318
+ - Stress and harm tracking (p.13-15)
319
+ - Downtime and long-term projects (p.16-20)
320
+
321
+ **Key principles:**
322
+ - Fiction drives mechanics (not dice → narrative)
323
+ - Position must be telegraphed before roll
324
+ - Effect established collaboratively with player
325
+ - Consequences flow from fiction, not arbitrary
326
+
327
+ ### Document Editor UX
328
+ - Text editing performance (<16ms per keystroke)
329
+ - Undo/redo granularity (word-level, not character)
330
+ - Selection handling (standard OS conventions)
331
+
332
+ **Key principles:**
333
+ - Performance over features (fast is a feature)
334
+ - Native OS behavior (don't reinvent text editing)
335
+ - Accessibility first (screen readers, keyboard nav)
336
+
337
+ ### Conversational AI Patterns
338
+ - GM tone: Collaborative, not dictatorial
339
+ - Player agency: Always offer meaningful choices
340
+ - Emergent narrative: Build on player ideas
341
+
342
+ **Key principles:**
343
+ - Ask questions, don't declare outcomes
344
+ - "Yes, and..." over "No, but..."
345
+ - Telegraph consequences before they happen
346
+ ```
347
+
348
+ **Why this structure:**
349
+ - ✅ **Easy to parse** - Simple markdown hierarchy (##, ###, bullets)
350
+ - ✅ **Scannable** - Domain names as headers, principles as bullets
351
+ - ✅ **Rationale included** - Explains "why" not just "what"
352
+ - ✅ **Resource references** - Links to rulebooks, docs, standards
353
+ - ✅ **Concrete** - Specific guidelines, not vague advice
354
+
355
+ **Integration with auto-quality-review hook:**
356
+ - Hook prompts: "Does it adhere to... domain requirements?"
357
+ - Claude checks CLAUDE.md/AGENTS.md for Domain Requirements section
358
+ - If present → Reviews against documented principles
359
+ - If absent → Infers domain from context as usual
360
+
361
+ ---
362
+
363
+ ## Writing for LLM Comprehension
364
+
365
+ **Critical:** These files are instructions consumed by LLMs.
366
+
367
+ **See:** `@.safeword/guides/llm-instruction-design.md` for 13 core principles for writing LLM-consumable documentation.
368
+
369
+ ### Quality Checklist
370
+
371
+ Before committing:
372
+
373
+ - [ ] All decision logic uses MECE principle (mutually exclusive, collectively exhaustive)
374
+ - [ ] All project-specific terms are defined
375
+ - [ ] No contradictions between sections
376
+ - [ ] Rules have concrete examples
377
+ - [ ] Edge cases explicitly covered
378
+ - [ ] Vague terms replaced with actionable principles
379
+ - [ ] No redundancy (each fact stated once)
380
+ - [ ] File under 200 lines (or uses imports)
381
+
382
+ ---
383
+
384
+ ## Best Practices from Anthropic
385
+
386
+ **Conciseness:**
387
+ - Use short, declarative bullet points (not narrative paragraphs)
388
+ - Trim redundancy (don't explain obvious folder names like "components folder contains components")
389
+ - Don't include commentary or nice-to-have information
390
+ - Files are loaded with every request - keep lean
391
+
392
+ **Effectiveness:**
393
+ - **Treat as living document** - Constantly refine based on what works
394
+ - Periodically review and refactor for clarity
395
+ - At Anthropic, teams use prompt improver to tune instructions
396
+ - Add emphasis ("IMPORTANT", "YOU MUST") for critical rules
397
+ - Explicitly reference your context file in prompts ("following CLAUDE.md guidelines") for better adherence
398
+
399
+ **Token Budget:**
400
+ - Context files are often prepended to prompts - they consume context with each interaction
401
+ - Bloated files cost more tokens and introduce noise
402
+ - Keep under 50KB for optimal performance (though no hard limit)
403
+ - Use imports to modularize instead of monolithic files
404
+
405
+
@@ -0,0 +1,183 @@
1
+ # Data Architecture Documentation Guide
2
+
3
+ **Context:** How to document data architecture decisions, models, and flows for software projects. Applies LLM instruction design principles for clarity and reliability.
4
+
5
+ **See:** `@.safeword/guides/llm-instruction-design.md` for comprehensive framework on writing LLM-consumable documentation.
6
+
7
+ ---
8
+
9
+ ## When to Document Data Architecture
10
+
11
+ **Decision Tree (Answer IN ORDER, stop at first match):**
12
+
13
+ 1. **Project initialization?** → Create `DATA_ARCHITECTURE.md` or `ARCHITECTURE.md` with data section
14
+ 2. **Adding new data store?** (database, cache, file system) → Update architecture doc
15
+ 3. **Changing data model?** (schema, entities, relationships) → Update architecture doc
16
+ 4. **Data flow integration?** (API, ETL, sync) → Update architecture doc
17
+ 5. **Single feature implementation?** → Use design doc (reference architecture doc)
18
+
19
+ **Tie-breaking rule:** If multiple apply, stop at first match (earlier = more general).
20
+
21
+ **Edge cases:**
22
+ - Single feature but adds 3+ entities → Architecture doc (impacts data model)
23
+ - Bug fix changes schema → Architecture doc (schema changes always documented)
24
+ - Feature uses existing data model → Design doc only
25
+
26
+ ---
27
+
28
+ ## Core Principles (Define First, Then Apply)
29
+
30
+ ### 1. Data Quality
31
+
32
+ **What:** Ensure data is accurate, complete, consistent, and timely.
33
+
34
+ **Why:** Poor data quality cascades to business logic bugs, corrupted state, and user-facing errors.
35
+
36
+ **Document:**
37
+ - Validation rules (types, constraints, ranges)
38
+ - Data source of truth (which store is canonical)
39
+ - Quality checkpoints (where validation happens)
40
+
41
+ **Example format:**
42
+ ```markdown
43
+ **[Entity] state** (source of truth: [storage type])
44
+ - `field1`: constraint (e.g., 0-100 integer)
45
+ - `field2[]`: max N entries, validation rule
46
+ **Validation checkpoint:** `validateFunction()` in `file.ts:line`
47
+ ```
48
+
49
+ ### 2. Data Governance
50
+
51
+ **What:** Policies that govern data access, modification, and lifecycle.
52
+
53
+ **Why:** Prevents unauthorized access, conflicting writes, and data loss.
54
+
55
+ **Document:**
56
+ - Who can read/write each data entity
57
+ - When data is created/updated/deleted
58
+ - Conflict resolution strategies
59
+
60
+ **Example format:**
61
+ ```markdown
62
+ **[Entity] state**:
63
+ - Read: [roles with read access]
64
+ - Write: [roles with write access] (via `updateFunction()`)
65
+ - Delete: [strategy] (e.g., soft delete with `deletedAt`)
66
+ - Conflict: [resolution strategy] (e.g., last-write-wins, CRDT merge)
67
+ ```
68
+
69
+ ### 3. Data Accessibility
70
+
71
+ **What:** Ensure data is available when needed, performantly.
72
+
73
+ **Why:** Users expect instant feedback; slow queries degrade UX.
74
+
75
+ **Document:**
76
+ - Access patterns (how data is queried)
77
+ - Performance targets (max query time)
78
+ - Caching strategies
79
+
80
+ **Example format:**
81
+ ```markdown
82
+ **[Entity] list** (accessed on [trigger]):
83
+ - Target: <Nms load time
84
+ - Strategy: [database index/optimization]
85
+ - Cache: [caching approach] or "No cache needed"
86
+ ```
87
+
88
+ ### 4. Living Documentation
89
+
90
+ **What:** Documentation stays current with code, not a one-time artifact.
91
+
92
+ **Why:** Outdated docs are worse than no docs (mislead developers).
93
+
94
+ **Document:**
95
+ - Version/status (Production/Proposed)
96
+ - Last updated date
97
+ - Migration strategy when changing
98
+
99
+ **Example format:**
100
+ ```markdown
101
+ **Version:** X.Y
102
+ **Status:** Production (vX) + Proposed (vY)
103
+ **Last Updated:** YYYY-MM-DD
104
+
105
+ ## Current Schema (vX - Production)
106
+ ## Proposed Schema (vY - Feature Name)
107
+ ## Migration Strategy
108
+ ```
109
+
110
+ ---
111
+
112
+ ## What to Document
113
+
114
+ ### 1. Data Models
115
+
116
+ **Three levels (conceptual → logical → physical):**
117
+
118
+ - **Conceptual**: High-level entities with descriptions (e.g., "User - person with account", "Order - purchase transaction")
119
+ - **Logical**: Attributes, types, relationships, constraints (e.g., `userId: UUID`, `orders: Order[]` 1:N relationship)
120
+ - **Physical**: Storage technology, tables/collections, indexes, WHY this tech (trade-offs) - see Core Principles → Data Quality (lines 41-47) for format
121
+
122
+ ### 2. Data Flows
123
+
124
+ **Document:** Sources → Transformations → Destinations + Error Handling
125
+
126
+ **Include:** Input validation, business logic transformations, persistence steps, UI updates, error handling for each step.
127
+
128
+ **Example format:**
129
+ ```markdown
130
+ **[Flow Name]** (trigger: [user action/event])
131
+ 1. **Input** → Validation (`validateFn()`) | Error: return 400
132
+ 2. **Transform** → Business logic | Error: rollback + notify
133
+ 3. **Persist** → Database write | Error: retry 3x, then fail
134
+ 4. **UI Update** → Optimistic update | Error: revert state
135
+ ```
136
+
137
+ ### 3. Data Policies
138
+
139
+ **Document:** Access control (who reads/writes), validation rules, lifecycle (creation, updates, deletion, purging).
140
+
141
+ ### 4. Data Integration
142
+
143
+ **Document:** External systems (APIs, files, services), sync strategies, conflict resolution, error handling.
144
+
145
+ ---
146
+
147
+ ## Integration with TDD Workflow
148
+
149
+ **See:** `@.safeword/guides/architecture-guide.md` for full TDD workflow integration.
150
+
151
+ **Data-specific triggers for updating architecture doc:**
152
+ - Adding new data entities
153
+ - Changing schema (new fields, relationships)
154
+ - Changing storage technology
155
+ - Discovering performance bottlenecks
156
+
157
+ ---
158
+
159
+ ## Common Mistakes
160
+
161
+ ❌ **No source of truth defined** → Conflicting data in multiple stores
162
+ ❌ **Missing validation rules** → Invalid data written to persistence
163
+ ❌ **No migration strategy** → Breaking changes brick user data
164
+ ❌ **Outdated documentation** → Schema and docs don't match (worse than no docs)
165
+ ❌ **Implementation details in architecture doc** → Save for design docs
166
+ ❌ **Ignoring performance targets** → Slow queries degrade UX
167
+
168
+ ---
169
+
170
+ ## Best Practices Checklist
171
+
172
+ Before finalizing data architecture doc:
173
+
174
+ - [ ] Principles follow What/Why/Document/Example format (4 principles minimum)
175
+ - [ ] All entities defined with descriptions (3+ entities for conceptual model)
176
+ - [ ] Each entity has attributes, types, relationships (logical model complete)
177
+ - [ ] Storage tech documented with WHY + trade-offs (physical model includes rationale)
178
+ - [ ] Each data flow includes error handling (not just happy path)
179
+ - [ ] Validation checkpoints specified with line numbers (where validation happens)
180
+ - [ ] Performance targets use concrete numbers (<Nms, not "fast")
181
+ - [ ] Migration strategy covers both additive and breaking changes
182
+ - [ ] Version and status match codebase (verify with git/deployment)
183
+ - [ ] Cross-referenced from root ARCHITECTURE.md or SAFEWORD.md (link exists)