Compare commits

..

1 Commits

Author SHA1 Message Date
36ce6faec7 feat: GENOME.md — full codebase analysis (#673)
Some checks failed
Sanity Checks / sanity-test (pull_request) Has been cancelled
Smoke Test / smoke (pull_request) Has been cancelled
2026-04-16 05:27:12 +00:00
3 changed files with 77 additions and 123 deletions

75
GENOME.md Normal file
View File

@@ -0,0 +1,75 @@
# GENOME.md — the-door
**Generated:** 2026-04-14
**Repo:** Timmy_Foundation/the-door
**Description:** Crisis Front Door — a single URL where a man at 3am can talk to Timmy. No login, no signup. 988 always visible.
---
## Project Overview
The-door is a crisis intervention web application — the most sacred surface in the Timmy Foundation. When a man at 3am reaches the end of his road, this is where he lands. No login, no signup, no barriers. 988 Suicide and Crisis Lifeline always visible. The "When a Man Is Dying" protocol active on every page.
## Architecture
```
the-door/
├── index.html # Main crisis page (PWA-capable)
├── crisis-offline.html # Offline fallback (service worker cached)
├── about.html # About page
├── testimony.html # Testimony/stories page
├── sw.js # Service worker (offline-first)
├── manifest.json # PWA manifest
├── crisis/ # Core crisis detection + response
│ ├── detect.py # Keyword/pattern detection (4 tiers)
│ ├── gateway.py # API endpoints, prompt injection
│ ├── response.py # Response generation, 988 routing
│ ├── compassion_router.py # Profile-based response routing
│ ├── profiles.py # Compassion profiles
│ └── PROTOCOL.md # The protocol (SOUL.md reference)
├── crisis_detector.py # Legacy shim → crisis/detect.py
├── crisis_responder.py # Legacy responder
├── dying_detection/ # Deprecated module
├── evolution/ # Crisis synthesizer (creative)
├── tests/ # Safety-critical tests
│ ├── test_crisis_overlay_focus_trap.py
│ ├── test_dying_detection_deprecation.py
│ └── test_false_positive_fixes.py
└── deploy/ # Deployment docs
```
## Key Abstractions
| Module | Purpose |
|---|---|
| `crisis/detect.py` | 4-tier detection: LOW/MEDIUM/HIGH/CRITICAL via regex patterns |
| `crisis/gateway.py` | HTTP API, Sovereign Heart prompt injection |
| `crisis/response.py` | Response generation, 988 integration, escalation |
| `crisis/compassion_router.py` | Profile-based routing (different crisis types) |
| `sw.js` | Service worker for offline-first PWA |
## Safety Constraints
- **The-door never auto-closes PRs** (in fleet-ops exempt list)
- **988 always visible** on every page, even offline
- **When a Man Is Dying protocol** active on every interaction
- **No login/signup** — zero barriers to crisis support
- **Offline-first** — service worker caches critical pages
## Test Coverage
| Test | Coverage |
|---|---|
| Crisis overlay focus trap | ✅ |
| Dying detection deprecation | ✅ |
| False positive fixes | ✅ |
| Crisis detection tiers | ❌ (in crisis/tests.py) |
| Response generation | ❌ |
| Offline service worker | ❌ |
## Security
- No user data stored (crisis intervention is stateless by design)
- No cookies, no tracking, no analytics
- Service worker only caches static assets
- Crisis detection runs client-side where possible

View File

@@ -531,36 +531,6 @@ html, body {
.btn-secondary:hover { color: #e6edf3; border-color: #8b949e; }
/* Toast notification (replaces blocking alert()) */
.toast-notification {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(100px);
padding: 12px 24px;
border-radius: 8px;
font-size: 0.9rem;
font-weight: 500;
z-index: 10001;
opacity: 0;
transition: transform 0.3s ease, opacity 0.3s ease;
pointer-events: none;
max-width: 90vw;
text-align: center;
}
.toast-notification.visible {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
.toast-notification.success {
background: #238636;
color: #fff;
}
.toast-notification.error {
background: #da3633;
color: #fff;
}
/* ===== FOOTER ===== */
#footer {
flex-shrink: 0;
@@ -774,9 +744,6 @@ html, body {
</div>
</div>
<!-- Toast notification (accessible, non-blocking feedback) -->
<div id="toast-notification" class="toast-notification" role="status" aria-live="polite" aria-atomic="true"></div>
<script>
(function() {
'use strict';
@@ -1216,24 +1183,6 @@ Sovereignty and service always.`;
} catch (e) {}
}
// ===== TOAST NOTIFICATION (replaces blocking alert()) =====
var _toastEl = document.getElementById('toast-notification');
var _toastTimer = null;
function showToast(message, type) {
type = type || 'success';
_toastEl.textContent = message;
_toastEl.className = 'toast-notification ' + type;
// Force reflow before adding visible class
void _toastEl.offsetHeight;
_toastEl.classList.add('visible');
if (_toastTimer) clearTimeout(_toastTimer);
_toastTimer = setTimeout(function() {
_toastEl.classList.remove('visible');
}, 3000);
}
closeSafetyPlan.addEventListener('click', function() {
safetyPlanModal.classList.remove('active');
_restoreSafetyPlanFocus();
@@ -1256,9 +1205,9 @@ Sovereignty and service always.`;
localStorage.setItem('timmy_safety_plan', JSON.stringify(plan));
safetyPlanModal.classList.remove('active');
_restoreSafetyPlanFocus();
showToast('Safety plan saved.', 'success');
alert('Safety plan saved locally.');
} catch (e) {
showToast('Error saving plan. Please try again.', 'error');
alert('Error saving plan.');
}
});

View File

@@ -1,70 +0,0 @@
import pathlib
import re
import unittest
ROOT = pathlib.Path(__file__).resolve().parents[1]
INDEX_HTML = ROOT / 'index.html'
class TestSafetyPlanToast(unittest.TestCase):
"""Verify safety plan save feedback uses non-blocking toast instead of alert()."""
@classmethod
def setUpClass(cls):
cls.html = INDEX_HTML.read_text()
def test_no_alert_calls_in_safety_plan_save(self):
"""Safety plan save should not use blocking alert() dialogs."""
# Find the save handler section
save_section = re.search(
r'saveSafetyPlan\.addEventListener.*?\}\);',
self.html, re.DOTALL
)
self.assertIsNotNone(save_section, 'Expected safety plan save handler to exist.')
section = save_section.group(0)
# Should not contain alert( calls
self.assertNotIn('alert(', section,
'Safety plan save handler should not use alert() — use showToast() instead.')
def test_toast_notification_element_exists(self):
"""Toast notification element should exist in the DOM."""
self.assertIn('id="toast-notification"', self.html,
'Expected toast-notification element in HTML.')
def test_toast_has_accessibility_attributes(self):
"""Toast should have aria-live for screen reader announcements."""
self.assertIn('aria-live="polite"', self.html,
'Toast should have aria-live="polite" for accessibility.')
self.assertIn('aria-atomic="true"', self.html,
'Toast should have aria-atomic="true" for complete announcement.')
def test_toast_css_exists(self):
"""Toast CSS styles should be defined."""
self.assertIn('.toast-notification', self.html,
'Expected .toast-notification CSS class.')
self.assertIn('.toast-notification.visible', self.html,
'Expected .toast-notification.visible CSS class.')
self.assertIn('.toast-notification.success', self.html,
'Expected .toast-notification.success CSS class.')
self.assertIn('.toast-notification.error', self.html,
'Expected .toast-notification.error CSS class.')
def test_showToast_function_exists(self):
"""showToast function should be defined."""
self.assertRegex(self.html, r'function\s+showToast\s*\(',
'Expected showToast function to be defined.')
def test_success_message_uses_toast(self):
"""Success feedback should use showToast with success type."""
self.assertIn("showToast('Safety plan saved.", self.html,
'Expected success message to use showToast.')
def test_error_message_uses_toast(self):
"""Error feedback should use showToast with error type."""
self.assertIn("showToast('Error saving plan.", self.html,
'Expected error message to use showToast.')
def test_toast_auto_dismisses(self):
"""Toast should auto-dismiss after timeout."""
self.assertRegex(self.html, r'setTimeout\s*\(\s*function',
'Expected setTimeout for toast auto-dismiss.')