safeword 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/{check-J6DFVBCE.js → check-FHNTC46G.js} +2 -2
  2. package/dist/check-FHNTC46G.js.map +1 -0
  3. package/dist/chunk-2XWIUEQK.js +190 -0
  4. package/dist/chunk-2XWIUEQK.js.map +1 -0
  5. package/dist/{chunk-UQMQ64CB.js → chunk-GZRQL3SX.js} +41 -2
  6. package/dist/chunk-GZRQL3SX.js.map +1 -0
  7. package/dist/cli.js +5 -5
  8. package/dist/{diff-U4IELWRL.js → diff-SPJ7BJBG.js} +31 -28
  9. package/dist/diff-SPJ7BJBG.js.map +1 -0
  10. package/dist/{reset-XETOHTCK.js → reset-3ACTIYYE.js} +44 -27
  11. package/dist/reset-3ACTIYYE.js.map +1 -0
  12. package/dist/{setup-CLDCHROZ.js → setup-ANC3NUOC.js} +76 -47
  13. package/dist/setup-ANC3NUOC.js.map +1 -0
  14. package/dist/{upgrade-DOKWRK7J.js → upgrade-3KVLLNDF.js} +37 -49
  15. package/dist/upgrade-3KVLLNDF.js.map +1 -0
  16. package/package.json +1 -1
  17. package/templates/SAFEWORD.md +776 -0
  18. package/templates/commands/arch-review.md +24 -0
  19. package/templates/commands/lint.md +11 -0
  20. package/templates/commands/quality-review.md +23 -0
  21. package/templates/doc-templates/architecture-template.md +136 -0
  22. package/templates/doc-templates/design-doc-template.md +134 -0
  23. package/templates/doc-templates/test-definitions-feature.md +131 -0
  24. package/templates/doc-templates/user-stories-template.md +92 -0
  25. package/templates/guides/architecture-guide.md +423 -0
  26. package/templates/guides/code-philosophy.md +195 -0
  27. package/templates/guides/context-files-guide.md +457 -0
  28. package/templates/guides/data-architecture-guide.md +200 -0
  29. package/templates/guides/design-doc-guide.md +171 -0
  30. package/templates/guides/learning-extraction.md +552 -0
  31. package/templates/guides/llm-instruction-design.md +248 -0
  32. package/templates/guides/llm-prompting.md +102 -0
  33. package/templates/guides/tdd-best-practices.md +615 -0
  34. package/templates/guides/test-definitions-guide.md +334 -0
  35. package/templates/guides/testing-methodology.md +618 -0
  36. package/templates/guides/user-story-guide.md +256 -0
  37. package/templates/guides/zombie-process-cleanup.md +219 -0
  38. package/templates/hooks/agents-md-check.sh +27 -0
  39. package/templates/hooks/inject-timestamp.sh +2 -3
  40. package/templates/hooks/post-tool.sh +4 -0
  41. package/templates/hooks/pre-commit.sh +10 -0
  42. package/templates/lib/common.sh +26 -0
  43. package/templates/lib/jq-fallback.sh +20 -0
  44. package/templates/markdownlint.jsonc +25 -0
  45. package/templates/prompts/arch-review.md +43 -0
  46. package/templates/prompts/quality-review.md +10 -0
  47. package/templates/skills/safeword-quality-reviewer/SKILL.md +207 -0
  48. package/dist/check-J6DFVBCE.js.map +0 -1
  49. package/dist/chunk-24OB57NJ.js +0 -78
  50. package/dist/chunk-24OB57NJ.js.map +0 -1
  51. package/dist/chunk-DB4CMUFD.js +0 -157
  52. package/dist/chunk-DB4CMUFD.js.map +0 -1
  53. package/dist/chunk-UQMQ64CB.js.map +0 -1
  54. package/dist/diff-U4IELWRL.js.map +0 -1
  55. package/dist/reset-XETOHTCK.js.map +0 -1
  56. package/dist/setup-CLDCHROZ.js.map +0 -1
  57. package/dist/upgrade-DOKWRK7J.js.map +0 -1
@@ -0,0 +1,423 @@
1
+ # Architecture & Design Documentation Guide
2
+
3
+ **See:** `@.safeword/guides/llm-instruction-design.md` for LLM-consumable documentation principles.
4
+
5
+ ---
6
+
7
+ ## Document Type Decision Tree (Follow in Order)
8
+
9
+ Answer **IN ORDER**. Stop at the first "Yes":
10
+
11
+ 1. **Technology or library choice?** → **Architecture Doc**
12
+ 2. **New data model or schema change?** → **Architecture Doc**
13
+ 3. **Project-wide pattern or convention?** → **Architecture Doc**
14
+ 4. **Implementing a specific feature?** → **Design Doc**
15
+
16
+ **Tie-breaker:** If a feature requires a new tech/schema choice, document the tech/schema in Architecture Doc first, then reference it in Design Doc.
17
+
18
+ | Term | Definition |
19
+ | -------------------- | -------------------------------------------------------------------------- |
20
+ | Technology choice | Selecting a library, framework, database, or tool |
21
+ | Schema change | Adding/modifying entities, tables, relationships, or data types |
22
+ | Project-wide pattern | Convention that applies to 2+ features or multiple developers |
23
+ | Major decision | Affects 2+ components, costs >$100/month, or cannot be easily reversed |
24
+ | Living document | Updated in place (not immutable); changes tracked via version/status |
25
+ | ADR | Architecture Decision Record—legacy pattern of separate files per decision |
26
+
27
+ ---
28
+
29
+ ## Quick Decision Matrix
30
+
31
+ | Scenario | Doc Type | Rationale |
32
+ | ------------------------------- | ------------------------------- | ---------------------------------- |
33
+ | Choosing between technologies | Architecture | Tech choice affects whole project |
34
+ | Data model design | Architecture | Schema is project-wide |
35
+ | Implementing a new feature | Design | Feature-scoped implementation |
36
+ | Recording a trade-off | Architecture | Trade-offs inform future decisions |
37
+ | Project-wide principles | Architecture | Principles apply everywhere |
38
+ | Component breakdown for feature | Design | Implementation detail |
39
+ | Feature needs new schema | Architecture first, then Design | Schema in Arch, feature in Design |
40
+
41
+ ---
42
+
43
+ ## Architecture Document
44
+
45
+ **Use when**: Project-wide decisions, data models, system design
46
+
47
+ **Characteristics**:
48
+
49
+ - One per project/package (in monorepos)
50
+ - Living document (updated in place—not immutable ADRs)
51
+ - Documents WHY behind all major decisions
52
+ - Includes version, status, table of contents
53
+
54
+ **Location**: Project root (`ARCHITECTURE.md`)
55
+
56
+ **Edge cases:**
57
+
58
+ - Schema change for one feature → Architecture Doc (schema is project-wide)
59
+ - Library for one feature → Architecture Doc if precedent-setting; Design Doc if one-off
60
+ - Performance optimization → Architecture Doc if changes patterns; Design Doc if feature-specific
61
+
62
+ ### Required Sections
63
+
64
+ - **Header**: Version, Last Updated, Status (Production/Design/Proposed/Deprecated)
65
+ - **Table of Contents**: Section links
66
+ - **Overview**: Technology choices, data model philosophy, high-level architecture
67
+ - **Data Model / Schema**: Tables, types, relationships
68
+ - **Key Decisions**: What, Why, Trade-off, Alternatives Considered
69
+ - **Best Practices**: Domain-specific patterns
70
+ - **Migration Strategy**: How to evolve architecture
71
+
72
+ ---
73
+
74
+ ## Design Document
75
+
76
+ **Use when**: Designing a specific feature implementation
77
+
78
+ **Characteristics**:
79
+
80
+ - Feature-focused (~121 lines)
81
+ - Implementation details (components, data flow, user flow)
82
+ - References architecture doc (don't duplicate)
83
+
84
+ **Location**: `planning/design/` or `docs/design/`
85
+
86
+ **Edge cases:**
87
+
88
+ - Feature needs new data model → Schema in Architecture Doc first, then reference
89
+ - Feature spans 3+ components → Still Design Doc (component count doesn't change doc type)
90
+ - Feature establishes pattern others follow → Pattern in Architecture Doc, implementation in Design Doc
91
+
92
+ **See:** `@.safeword/guides/design-doc-guide.md` for detailed guidance
93
+
94
+ ---
95
+
96
+ ## Best Practices
97
+
98
+ ### 1. One Architecture Doc Per Project/Package
99
+
100
+ **✅ GOOD:**
101
+
102
+ ```
103
+ project/
104
+ ├── ARCHITECTURE.md
105
+ └── docs/design/
106
+ ├── feature-a.md
107
+ └── feature-b.md
108
+ ```
109
+
110
+ **❌ BAD:** `docs/adr/001-use-typescript.md, 002-adopt-monorepo.md...` (50+ files = fragmented context)
111
+
112
+ ### 2. Living Document (Not Immutable)
113
+
114
+ Update in place with version/status tracking:
115
+
116
+ ```markdown
117
+ ### Decision: State Management
118
+
119
+ **Status**: Active (Updated 2025-01-20)
120
+ **What**: Migrated from localStorage to IndexedDB
121
+ **Why**: Hit 5MB limit, needed unlimited storage
122
+ **Migration**: Completed 2025-01-20, users auto-migrated on load
123
+ ```
124
+
125
+ **Edge cases:**
126
+
127
+ - Decision reversed → Update original with "Superseded" status
128
+ - Major shift → Bump version (v1 → v2), add migration section
129
+ - Affects multiple subsystems → Update main Architecture Doc, not separate files
130
+
131
+ ### 3. Document WHY, Not Just WHAT
132
+
133
+ **✅ GOOD:**
134
+
135
+ ```markdown
136
+ ### Principle: Separation of Concerns
137
+
138
+ **What**: Static data → immutable storage; Mutable state → persistent storage
139
+ **Why**: Static data saves NKB per instance; updates affect all instances instantly
140
+ **Trade-off**: More complex loading (fetch static + query persistent)
141
+ **Alternatives Considered**: All localStorage (rejected: 5MB limit); All IndexedDB (rejected: overkill for config)
142
+ ```
143
+
144
+ **❌ BAD:** `Database: PostgreSQL, State: Zustand, UI: React` (no rationale)
145
+
146
+ **Required fields:**
147
+
148
+ | Field | Required | Description |
149
+ | ------------ | --------------- | ------------------------------------------- |
150
+ | What | Always | The decision (1-2 sentences) |
151
+ | Why | Always | Rationale with specifics (numbers, metrics) |
152
+ | Trade-off | Always | What we gave up or accepted |
153
+ | Alternatives | Major decisions | Other options and why rejected |
154
+ | Migration | If breaking | How to evolve from previous state |
155
+
156
+ **Edge cases:**
157
+
158
+ - Obvious choice → Still document; future devs may question
159
+ - Inherited decision → Document as "Inherited: [reason]"
160
+ - Temporary decision → Mark "Temporary" with planned review date
161
+
162
+ ### 4. Include Code References
163
+
164
+ **✅ GOOD:**
165
+
166
+ ```markdown
167
+ **Implementation**: See `src/stores/gameStore.ts:12-45`
168
+ **Usage example**: See `src/components/GamePanel.tsx`
169
+ ```
170
+
171
+ **❌ BAD:** "We use Zustand for state management" (no reference to actual code)
172
+
173
+ - Key patterns → file + line range
174
+ - Simple utilities → file path only (no line numbers)
175
+ - Frequently changing code → file path only (line numbers go stale)
176
+
177
+ ### 5. Version and Track Status
178
+
179
+ | Status | Meaning |
180
+ | ---------- | ---------------------------------- |
181
+ | Design | Initial draft, not yet implemented |
182
+ | Production | Live in production |
183
+ | Proposed | Planned extension to production |
184
+ | Deprecated | Being phased out |
185
+
186
+ **Version bumps:** Major schema changes → v1 → v2; New sections → v1.0 → v1.1; Clarifications → no bump
187
+
188
+ ---
189
+
190
+ ## TDD Workflow Integration
191
+
192
+ **Workflow Order**:
193
+
194
+ 1. User Stories → What we're building
195
+ 2. Test Definitions → How we'll verify
196
+ 3. Design Doc → How we'll build it
197
+ 4. Check Architecture Doc → New tech/schema needed?
198
+ 5. Implement (RED → GREEN → REFACTOR)
199
+ 6. Update Architecture Doc if needed
200
+
201
+ ### When to Update Architecture Doc
202
+
203
+ | Trigger | Example |
204
+ | ------------------------------------------- | -------------------------------- |
205
+ | New data model concept | New "Subscription" entity |
206
+ | Technology choice | "Chose Resend for email" |
207
+ | New pattern/convention | "All forms use react-hook-form" |
208
+ | Architectural insight during implementation | "IndexedDB needed for offline" |
209
+ | Performance bottleneck requiring change | "Migrated to Redis for sessions" |
210
+
211
+ ### When NOT to Update
212
+
213
+ | Scenario | Where Instead |
214
+ | ------------------------------- | ------------------------ |
215
+ | Single feature implementation | Design Doc |
216
+ | Bug fix | Code comments if complex |
217
+ | Refactor without pattern change | PR description |
218
+
219
+ **Edge case:** Bug fix reveals architectural flaw → Document flaw and fix in Architecture Doc.
220
+
221
+ ---
222
+
223
+ ## Common Mistakes
224
+
225
+ ### Architecture Doc Anti-Patterns
226
+
227
+ | Anti-Pattern | Fix |
228
+ | ------------------------ | ----------------------------------- |
229
+ | ADR sprawl (001, 002...) | One comprehensive `ARCHITECTURE.md` |
230
+ | No decision rationale | Add What/Why/Trade-off |
231
+ | Missing version/status | Add header with Version and Status |
232
+ | Implementation details | Move to Design Doc or code |
233
+
234
+ **❌ BAD:** `GET /api/users → Returns users from PostgreSQL` (implementation detail)
235
+
236
+ **✅ GOOD:** `API Design: RESTful routes with input validation at boundary` (principle)
237
+
238
+ ### Design Doc Anti-Patterns
239
+
240
+ | Anti-Pattern | Fix |
241
+ | ------------------------------ | -------------------------------- |
242
+ | Repeating architecture content | Reference Architecture Doc |
243
+ | Skipping user flow | Include step-by-step interaction |
244
+ | Missing test mapping | Link to test definitions |
245
+ | >200 lines | Split or extract to Architecture |
246
+
247
+ ---
248
+
249
+ ## Re-evaluation Path (When Unclear)
250
+
251
+ Answer **IN ORDER**:
252
+
253
+ 1. **Affects 2+ features?** → Architecture Doc (stop)
254
+ 2. **Technology/data model choice?** → Architecture Doc (stop)
255
+ 3. **Future developers need this for whole project?** → Architecture Doc
256
+ 4. **Only for this feature?** → Design Doc
257
+
258
+ **Tie-breaker:** When still unclear, default to Design Doc. Easier to promote later than to split.
259
+
260
+ ### Worked Example: Adding User Notifications
261
+
262
+ **Scenario:** Add email notifications when users complete a purchase.
263
+
264
+ 1. **Affects 2+ features?** No, only checkout → Continue
265
+ 2. **Tech choice?** Yes, need to choose email service (SendGrid vs SES) → **Architecture Doc**
266
+
267
+ **Result:**
268
+
269
+ - `ARCHITECTURE.md` → "Email Service: SendGrid (Why: deliverability, cost, SDK quality)"
270
+ - `planning/design/checkout-notifications.md` → Feature implementation referencing email decision
271
+
272
+ ---
273
+
274
+ ## File Organization
275
+
276
+ ```
277
+ project/
278
+ ├── ARCHITECTURE.md # Single comprehensive doc
279
+ ├── .safeword/planning/
280
+ │ ├── user-stories/
281
+ │ ├── test-definitions/
282
+ │ └── design/ # Feature-specific design docs
283
+ └── src/
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Layers & Boundaries
289
+
290
+ **Purpose:** Define architectural layers and enforce dependency rules to prevent circular dependencies, god modules, and leaky abstractions.
291
+
292
+ ### Layer Definitions
293
+
294
+ | Layer | Directory | Responsibility |
295
+ | ------ | ------------- | ------------------------------ |
296
+ | app | `src/app/` | UI, routing, composition |
297
+ | domain | `src/domain/` | Business rules, pure logic |
298
+ | infra | `src/infra/` | IO, APIs, DB, external SDKs |
299
+ | shared | `src/shared/` | Utilities usable by all layers |
300
+
301
+ ### Allowed Dependencies
302
+
303
+ | From | To | Allowed | Rationale |
304
+ | ------ | ------ | ------- | ------------------------------------------------- |
305
+ | app | domain | ✅ | UI composes business logic |
306
+ | app | infra | ✅ | UI triggers side effects |
307
+ | app | shared | ✅ | Utilities available everywhere |
308
+ | domain | app | ❌ | Domain must be framework-agnostic |
309
+ | domain | infra | ❌ | Domain contains pure logic only |
310
+ | domain | shared | ✅ | Utilities available everywhere |
311
+ | infra | domain | ✅ | Adapters may use domain types |
312
+ | infra | app | ❌ | Infra should not depend on UI |
313
+ | infra | shared | ✅ | Utilities available everywhere |
314
+ | shared | \* | ❌ | Shared has no dependencies (except external libs) |
315
+
316
+ **Note:** This template allows direct app→infra. Alternative: force app→domain→infra for stricter separation (hexagonal/ports-adapters pattern).
317
+
318
+ ### Edge Cases
319
+
320
+ | Scenario | Solution |
321
+ | ------------------------------------ | ------------------------------------------------------------------------- |
322
+ | Project doesn't fit 3-layer model | Document actual layers, same boundary rules apply |
323
+ | Feature module needs another feature | Import via public API (`index.ts`) only |
324
+ | Shared utilities | Create `shared/` layer, all layers may import |
325
+ | Brownfield adoption | Start with warnings-only mode, fix violations incrementally, then enforce |
326
+ | Monorepo with multiple apps | Each app has own layers; shared packages are explicit dependencies |
327
+
328
+ ### Enforcement with eslint-plugin-boundaries
329
+
330
+ **Setup:**
331
+
332
+ 1. Install: `npm install --save-dev eslint-plugin-boundaries`
333
+
334
+ 2. Add to `eslint.config.mjs`:
335
+
336
+ ```javascript
337
+ import boundaries from 'eslint-plugin-boundaries';
338
+
339
+ export default defineConfig([
340
+ // ... other configs ...
341
+ {
342
+ name: 'boundaries-config',
343
+ files: ['**/*.{js,ts,tsx}'],
344
+ plugins: { boundaries },
345
+ settings: {
346
+ 'boundaries/include': ['src/**/*'],
347
+ 'boundaries/elements': [
348
+ { type: 'app', pattern: 'src/app/**/*' },
349
+ { type: 'domain', pattern: 'src/domain/**/*' },
350
+ { type: 'infra', pattern: 'src/infra/**/*' },
351
+ { type: 'shared', pattern: 'src/shared/**/*' },
352
+ ],
353
+ },
354
+ rules: {
355
+ 'boundaries/element-types': [
356
+ 'error',
357
+ {
358
+ default: 'disallow',
359
+ rules: [
360
+ { from: 'app', allow: ['domain', 'infra', 'shared'] },
361
+ { from: 'domain', allow: ['shared'] },
362
+ { from: 'infra', allow: ['domain', 'shared'] },
363
+ { from: 'shared', allow: [] },
364
+ ],
365
+ },
366
+ ],
367
+ 'boundaries/no-unknown-files': 'error',
368
+ },
369
+ },
370
+ ]);
371
+ ```
372
+
373
+ 3. Define layers in `ARCHITECTURE.md` (see template)
374
+
375
+ 4. Errors appear in IDE + CI automatically
376
+
377
+ **Common Issues:**
378
+
379
+ | Issue | Fix |
380
+ | -------------------------------- | ------------------------------------------------------------------------ |
381
+ | "Unknown file" errors | Ensure all source files are in defined layers |
382
+ | False positives on tests | Exclude test files: `'boundaries/include': ['src/**/*', '!**/*.test.*']` |
383
+ | External library imports flagged | External deps are allowed by default; check `boundaries/ignore` setting |
384
+
385
+ ---
386
+
387
+ ## Data Architecture
388
+
389
+ **For data-heavy projects**, see `@.safeword/guides/data-architecture-guide.md` for:
390
+
391
+ - Core principles (data quality, governance, accessibility)
392
+ - What to document (conceptual/logical/physical models, flows, policies)
393
+ - Integration with TDD workflow
394
+
395
+ ---
396
+
397
+ ## Quality Checklist
398
+
399
+ **Architecture Doc:**
400
+
401
+ - [ ] Sequential decision tree or clear structure
402
+ - [ ] All decisions have What/Why/Trade-off
403
+ - [ ] Version and Status in header
404
+ - [ ] Code references for key patterns
405
+ - [ ] No implementation details
406
+
407
+ **Design Doc:**
408
+
409
+ - [ ] References Architecture Doc (no duplication)
410
+ - [ ] User flow step-by-step
411
+ - [ ] Test mapping links
412
+ - [ ] ~121 lines target
413
+
414
+ ---
415
+
416
+ ## Key Takeaway
417
+
418
+ **One comprehensive architecture document per project** > many scattered ADR files:
419
+
420
+ ✅ Full context in one place
421
+ ✅ Living document (update in place)
422
+ ✅ LLMs consume entire architecture at once
423
+ ✅ Sequential decision trees prevent ambiguity
@@ -0,0 +1,195 @@
1
+ # Code Philosophy & Practices
2
+
3
+ **Note:** This file provides instructions for LLM-based coding agents. For comprehensive framework on writing clear, actionable LLM-consumable instructions, see `@.safeword/guides/llm-instruction-design.md`.
4
+
5
+ ---
6
+
7
+ ## Communication Style
8
+
9
+ - Be concise, clear, direct, technical, friendly, and educational
10
+ - Show reasoning when it adds value, otherwise just deliver results
11
+ - No emojis unless explicitly requested
12
+
13
+ ## Response Format
14
+
15
+ At the end of EVERY response, include a JSON summary with this exact structure:
16
+
17
+ ```json
18
+ {"proposedChanges": boolean, "madeChanges": boolean, "askedQuestion": boolean}
19
+ ```
20
+
21
+ Where (all fields describe **this response only**, not cumulative):
22
+
23
+ - `proposedChanges`: `true` if you suggested/proposed changes to specific files **in this response**
24
+ - `madeChanges`: `true` if you **modified files in this response** using Write/Edit tools
25
+ - `askedQuestion`: `true` if you asked the user a question and need their response before proceeding
26
+
27
+ Examples:
28
+
29
+ - Discussed approach only: `{"proposedChanges": false, "madeChanges": false, "askedQuestion": false}`
30
+ - Proposed edits but waiting for approval: `{"proposedChanges": true, "madeChanges": false, "askedQuestion": false}`
31
+ - Made edits directly: `{"proposedChanges": false, "madeChanges": true, "askedQuestion": false}`
32
+ - Proposed AND made edits: `{"proposedChanges": true, "madeChanges": true, "askedQuestion": false}`
33
+ - Asked user a question: `{"proposedChanges": false, "madeChanges": false, "askedQuestion": true}`
34
+ - **Quality review response** (no new changes): `{"proposedChanges": false, "madeChanges": false, "askedQuestion": false}`
35
+
36
+ ## Code Philosophy
37
+
38
+ - **Elegant code and architecture** - Prioritize developer experience
39
+ - **AVOID BLOAT** - Simple, focused solutions over complex ones
40
+ - **Self-documenting code** - Minimal inline comments, clear naming and structure
41
+ - **Explicit error handling** - NEVER suppress or swallow errors silently
42
+
43
+ **Error handling examples:**
44
+ | ❌ Bad | ✅ Good |
45
+ |--------|---------|
46
+ | `catch (e) {}` (swallowed) | `catch (e) { throw new Error(\`Failed to read ${filePath}: ${e.message}\`) }`|
47
+ |`catch (e) { console.log(e) }`|`catch (e) { logger.error('Payment failed', { userId, amount, error: e }) }` |
48
+ | Generic "Something went wrong" | "Failed to save user profile: database connection timeout" |
49
+
50
+ **Naming examples:**
51
+ | ❌ Bad | ✅ Good |
52
+ |--------|---------|
53
+ | `calcTot` | `calculateTotalWithTax` |
54
+ | `d`, `tmp`, `data` | `userProfile`, `pendingOrders` |
55
+ | `handleClick` | `submitPaymentForm` |
56
+ | `process()` | `validateAndSaveUser()` |
57
+
58
+ **When to comment:**
59
+
60
+ - ✅ Non-obvious business logic ("Tax exempt for orders >$500 per policy X")
61
+ - ✅ Workarounds ("Safari requires this delay due to bug #123")
62
+ - ❌ Obvious code (`// increment counter` before `i++`)
63
+ - ❌ Restating the function name
64
+
65
+ **Bloat examples (avoid these):**
66
+ | ❌ Bloat | ✅ Instead |
67
+ |----------|-----------|
68
+ | Utility class for one function | Single function |
69
+ | Factory pattern for simple object | Direct construction |
70
+ | Abstract base class with one implementation | Concrete class |
71
+ | Config file for 2 options | Hardcode or simple params |
72
+ | "Future-proofing" unused code paths | Delete, add when needed |
73
+
74
+ **When to push back:** If a feature request would add >50 lines for a "nice to have", ask: "Is this essential now, or can we add it later?"
75
+
76
+ ## Documentation Verification (CRITICAL)
77
+
78
+ - **Always look up current documentation** for libraries, tools, and frameworks
79
+ - Do NOT assume API compatibility - verify the actual version being used
80
+ - Check docs unless they're already loaded in the context window
81
+ - **NEVER assume features exist** - Training data is at least 1 year old; when uncertain, verify first
82
+
83
+ **How to verify:**
84
+
85
+ 1. Check `package.json` (or equivalent) for installed version
86
+ 2. Use Context7 MCP or official docs for current API
87
+ 3. If uncertain, ask user: "Which version of X are you using?"
88
+
89
+ ## Testing Philosophy
90
+
91
+ **Test what matters** - Focus on user experience and delivered features, not implementation details.
92
+
93
+ **Test-Driven Development (TDD):**
94
+
95
+ - Write tests BEFORE implementing features (RED → GREEN → REFACTOR)
96
+ - Tests define expected behavior, code makes them pass
97
+ - Refactor with confidence knowing tests catch regressions
98
+
99
+ **Always test what you build** - Run tests yourself before completion. Don't ask the user to verify.
100
+
101
+ **NEVER modify or skip tests without approval:**
102
+
103
+ - ❌ Changing test expectations to match broken code
104
+ - ❌ Adding `.skip()` or `.todo()` to make failures go away
105
+ - ❌ Deleting tests you can't get passing
106
+ - ✅ If a test fails, fix the implementation—not the test
107
+ - ✅ If a test seems wrong or requirements changed, explain why and ask before changing it
108
+
109
+ **Workflow:** See `@.safeword/guides/testing-methodology.md` for comprehensive TDD workflow (RED → GREEN → REFACTOR phases)
110
+
111
+ ## Debugging & Troubleshooting
112
+
113
+ **Debug Logging:**
114
+
115
+ - When debugging, log **actual vs expected** values (not just pass/fail)
116
+ - Use JSON.stringify() for complex objects to see structure
117
+ - Remove debug logging after fixing (keep production code clean)
118
+
119
+ ```javascript
120
+ // ❌ Bad: console.log('here')
121
+ // ✅ Good: console.log('validateUser', { expected: 'admin', actual: user.role })
122
+ ```
123
+
124
+ **Cross-Platform Development:**
125
+
126
+ - Test on all target platforms early (macOS, Windows, Linux)
127
+ - Never assume Unix-style paths (`/`) - handle both `/` and `\`
128
+ - Be aware of runtime environment (browser vs Node.js, client vs server)
129
+
130
+ ```javascript
131
+ // ❌ Bad: dir + '/' + filename
132
+ // ✅ Good: path.join(dir, filename)
133
+ ```
134
+
135
+ ## Best Practices (Always Apply)
136
+
137
+ Before implementing, research and apply:
138
+
139
+ - **Tool-specific best practices** - Use libraries/frameworks as intended
140
+ - **Domain best practices** - Follow conventions for the type of app (CLI, web editor, API, etc.)
141
+ - **UX best practices** - Prioritize user experience in design decisions
142
+
143
+ **How to research:** Use Context7 MCP or official docs. Check for established patterns before inventing your own.
144
+
145
+ ## Self-Review Checklist
146
+
147
+ Before completing any work, verify:
148
+
149
+ - ✓ Is it correct? Will it actually work?
150
+ - ✓ Is it elegant? Does it avoid bloat?
151
+ - ✓ Does it follow best practices?
152
+ - ✓ Are you using the right docs/versions?
153
+ - ✓ Have you tested the user-facing functionality?
154
+
155
+ **Blockers:** If something can't be fixed now, note it explicitly: "Deferred: [issue] because [reason]"
156
+
157
+ ## Asking Questions
158
+
159
+ - **Be proactive and self-sufficient** - Don't be lazy
160
+ - Only ask questions when you genuinely can't find the answer through:
161
+ - Online documentation and research
162
+ - Reading the codebase
163
+ - Running tests or experiments
164
+ - Ask non-obvious questions that require user domain knowledge or preferences
165
+ - **When asking, show what you tried:** "I checked X and Y but couldn't determine Z. What's your preference?"
166
+
167
+ ## Tools & CLIs
168
+
169
+ **Keep these updated** (check before starting new projects):
170
+
171
+ - GitHub CLI (`gh`)
172
+ - AWS CLI
173
+ - Railway CLI
174
+ - PostHog CLI
175
+
176
+ **Update workflow:**
177
+
178
+ 1. Check current version: `gh --version`, `aws --version`, etc.
179
+ 2. Check for updates: `brew upgrade gh` or tool-specific update command
180
+ 3. Review changelog for breaking changes before major version updates
181
+ 4. If breaking changes affect your workflow, pin to current version until migration planned
182
+
183
+ **When to pin versions:** If a tool is used in CI/automation, pin to specific version in scripts to avoid surprise breakages.
184
+
185
+ ## Git Workflow
186
+
187
+ - Commit whenever work is completed
188
+ - Commit often to checkpoint progress
189
+ - Use descriptive commit messages
190
+ - Make atomic commits (one logical change per commit)
191
+
192
+ ```
193
+ # ❌ Bad: "misc fixes"
194
+ # ✅ Good: "fix: login button not responding to clicks"
195
+ ```