safeword 0.6.4 → 0.6.6

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