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