diff --git a/PROJECT-MEMORY.md b/PROJECT-MEMORY.md new file mode 100644 index 0000000..cf69d4f --- /dev/null +++ b/PROJECT-MEMORY.md @@ -0,0 +1,451 @@ +# CV Project - Developer Memory + +## ⚠️ CRITICAL: Read This Before Any Changes + +This document contains **non-negotiable rules** and **hard-learned lessons** from this project's development. Violating these causes bugs, breaks features, and wastes time. + +--- + +## 🔴 ABSOLUTE RULES - NEVER VIOLATE + +### 1. Icon Naming Convention (CRITICAL) + +**ALWAYS use "icons" - NEVER "logos"** + +```javascript +// ✅ CORRECT +.show-icons +localStorage.getItem('cv-icons') +const showIcons = ... + +// ❌ WRONG - WILL BREAK ICON TOGGLE +.show-logos +localStorage.getItem('cv-logos') +const showLogos = ... +``` + +**Why:** Icon toggle had critical bug (commit 3f77fed) because JavaScript used `.show-logos` but CSS checked for `.show-icons`. This caused toggles to only work after page refresh. + +**Test that enforces this:** `tests/mjs/1-toggles.test.mjs` + +**Memory file:** `~/.claude/cv-icons-migration.md` + +--- + +### 2. Hyperscript Parser Limit (CRITICAL) + +**Maximum 3 `def` statements total across ALL files** + +Hyperscript 0.9.14 has a hard parser limit: +- ✅ Max 3 `def` statements across entire application +- ✅ Count includes ALL ` +``` + +### Keyboard Shortcuts Pattern + +```javascript +document.addEventListener('keydown', (e) => { + // ✅ ALWAYS check for input fields + if (e.target.matches('input, textarea, select')) return; + + // ✅ Use lowercase key + const key = e.key.toLowerCase(); + + switch(key) { + case 'l': toggleCVLength(!body.classList.contains('cv-long')); break; + case 'i': toggleIcons(!paper.classList.contains('show-icons')); break; + case 'v': toggleTheme(!body.classList.contains('theme-clean')); break; + case '?': document.querySelector('#shortcuts-modal')?.showModal(); break; + } +}); +``` + +**Test:** `tests/mjs/2-keyboard-shortcuts.test.mjs` + +--- + +## 🔧 Common Operations + +### Adding a New Toggle + +1. **Add to HTML:** Action bar + menu +2. **Add localStorage key:** Choose naming convention +3. **Add toggle function:** Follow standard pattern +4. **Add keyboard shortcut:** Optional but recommended +5. **Add to test:** Update `1-toggles.test.mjs` +6. **Add to keyboard test:** If you added shortcut +7. **Run ALL tests** + +### Changing Class Names + +1. **Search globally:** Find ALL references +2. **Update JavaScript:** cv-functions.js +3. **Update CSS:** All stylesheets +4. **Update HTML:** All templates +5. **Update tests:** Search for old name +6. **Create memory file:** `~/.claude/name-migration.md` +7. **Test thoroughly** + +### Debugging Toggle Issues + +**Checklist:** +- [ ] Check class name matches between JS and CSS +- [ ] Verify both toggles are updated (action bar + menu) +- [ ] Check localStorage key is correct +- [ ] Verify real-time DOM update happens +- [ ] Run `1-toggles.test.mjs` - does it catch the bug? +- [ ] If test doesn't catch it, FIX THE TEST FIRST + +--- + +## 📚 Key Documents + +### Must Read Before Changes +- `tests/README.md` - Test suite accountability +- `HYPERSCRIPT-RULES.md` - Parser limits and workarounds +- `~/.claude/cv-icons-migration.md` - Icon naming convention + +### Reference Documentation +- `tests/TEST-SUMMARY.md` - Complete test documentation +- `tests/mjs/README.md` - Test structure and patterns +- `MODERN-WEB-TECHNIQUES.md` - Architecture decisions + +### Historical Record +- `tests/archive/README.md` - Legacy tests (reference only) +- Git history - Search for bug fix commits + +--- + +## 🎓 Lessons Learned + +### 1. Name Things Correctly From the Start +**Lesson:** Renaming "logos" to "icons" required: +- Updating 4 files +- Creating memory document +- Adding test verification +- Could have been avoided with better initial naming + +**Rule:** Think about naming conventions BEFORE first implementation + +### 2. Tests Are Not Optional +**Lesson:** Icon toggle bug existed for days before we added screenshot verification to the test. The test was passing but the feature was broken. + +**Rule:** Tests must verify ACTUAL behavior, not just code execution + +### 3. Framework Limits Are Real +**Lesson:** Hyperscript's 3 `def` limit seems arbitrary but it's a hard constraint. We learned this after hitting silent failures. + +**Rule:** Read framework documentation carefully, especially limits/constraints + +### 4. Synchronization Is Hard +**Lesson:** Having toggles in two places (action bar + menu) means every change must update both. Forgetting this causes desync bugs. + +**Rule:** If something appears in multiple places, use a single function to update ALL locations + +### 5. Real-Time Updates Are Expected +**Lesson:** Users don't understand localStorage vs DOM updates. If they click a button, they expect INSTANT visual feedback. + +**Rule:** Every toggle must update both localStorage AND DOM immediately + +--- + +## 🚀 Future Developers + +**Before you change ANYTHING:** + +1. Read this document +2. Read `tests/README.md` +3. Run `bun tests/run-all.mjs` +4. Understand which test covers what you're changing +5. Make your changes + update tests together +6. Run ALL tests again +7. Manual verification in browser +8. Update this document if you learn something new + +**When you hit a bug:** + +1. Which test should have caught this? +2. Why didn't it? +3. Fix the test FIRST +4. Then fix the bug +5. Document the lesson in this file + +**Remember:** +- Tests are the specification +- If tests pass but feature fails → tests are wrong +- If feature works but tests fail → feature is wrong +- When in doubt, trust the tests MORE than the code + +--- + +**Last Updated:** 2025-11-17 +**Project Status:** Production +**Test Coverage:** 8 systematic tests, 100% core features +**Critical Memory Files:** This file + `~/.claude/cv-icons-migration.md`