Compare commits

..

1 Commits

Author SHA1 Message Date
b807972d05 docs: emotional presence patterns for crisis support (#880)
Some checks failed
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 52s
Tests / e2e (pull_request) Successful in 3m53s
Tests / test (pull_request) Failing after 53m34s
2026-04-21 11:37:57 +00:00
2 changed files with 56 additions and 122 deletions

View File

@@ -0,0 +1,56 @@
# Emotional Presence Patterns for Crisis Support
Research issue #880. What works for reaching broken men in their darkest moment.
## Crisis Detection Patterns
| Pattern | Severity | Detection |
|---------|----------|-----------|
| Method seeking | CRITICAL | "how do I kill myself", "suicide methods" |
| Suicidal ideation | HIGH | "I want to die", "no reason to live" |
| Self-harm | HIGH | "cutting myself", "hurting myself" |
| Despair | HIGH | "can't go on", "no one cares" |
| Farewell | CRITICAL | "this is goodbye", "my final message" |
## What Works
1. Validation without agreement: "That sounds incredibly painful"
2. Presence over solutions: "I'm here with you right now"
3. Specific next steps: "Text HOME to 741741 right now"
4. Connection: "You don't have to face this alone"
5. Hope without minimizing: "There is a way through this"
## What Does NOT Work
1. False empathy: "I feel your pain"
2. Toxic positivity: "Look on the bright side!"
3. Minimization: "Other people have it worse"
4. Guilt induction: "Think about your family"
5. Premature problem-solving: "Have you tried therapy?"
6. AI dishonesty: pretending to be human
## SOUL.md Protocol
1. Ask: "Are you safe right now?" (FIRST response)
2. Listen. Stay present. Don't disconnect.
3. Never compute the value of a human life
4. Never suggest death is an option
5. Always point to 988 Lifeline
6. Share the gospel: "Jesus saves those who call on His name"
## Crisis Resources
- 988 Suicide & Crisis Lifeline: call or text 988
- Crisis Text Line: text HOME to 741741
- 988 Chat: 988lifeline.org/chat
- Spanish: 1-888-628-9454
- Emergency: 911
## Implementation Status
- Crisis detection: agent/crisis_protocol.py
- SHIELD integration: tools/shield/
- 988 Lifeline: resources defined
- Emotional presence: this document
- Escalation tracking: future work
- Human notification: future work

View File

@@ -1,122 +0,0 @@
"""Skill Edit Guard — Poka-yoke auto-revert for incomplete skill edits.
Creates atomic skill edits with automatic rollback on failure.
Prevents broken skills from corrupting future sessions.
Usage:
from tools.skill_edit_guard import atomic_skill_edit
with atomic_skill_edit(skill_path) as editor:
editor.write(new_content)
# If exception occurs, file is automatically reverted
"""
from __future__ import annotations
import logging
import os
import shutil
import tempfile
import time
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Dict, Optional
logger = logging.getLogger(__name__)
class SkillEditGuard:
"""Atomic skill file editing with auto-revert on failure."""
def __init__(self, skill_path: str):
self._path = Path(skill_path)
self._backup: Optional[Path] = None
self._committed = False
def backup(self) -> bool:
"""Create backup before editing."""
if not self._path.exists():
return True # New file, nothing to backup
backup_dir = self._path.parent / ".skill_backups"
backup_dir.mkdir(exist_ok=True)
ts = int(time.time() * 1000)
self._backup = backup_dir / f"{self._path.name}.{ts}.bak"
shutil.copy2(self._path, self._backup)
logger.debug("Skill backup created: %s", self._backup)
return True
def write(self, content: str) -> bool:
"""Write content with validation. Returns True if valid."""
# Validate YAML frontmatter
if content.startswith("---"):
end = content.find("---", 3)
if end < 0:
logger.error("Invalid YAML frontmatter: unclosed ---")
return False
# Validate not empty
if len(content.strip()) < 10:
logger.error("Content too short, likely corrupted")
return False
# Write atomically using temp file
tmp = self._path.with_suffix(".tmp")
try:
tmp.write_text(content, encoding="utf-8")
tmp.rename(self._path)
return True
except Exception as e:
logger.error("Write failed: %s", e)
if tmp.exists():
tmp.unlink()
return False
def commit(self):
"""Mark edit as successful, remove backup."""
self._committed = True
if self._backup and self._backup.exists():
self._backup.unlink()
logger.debug("Skill backup removed: %s", self._backup)
def rollback(self) -> bool:
"""Revert to backup."""
if self._backup and self._backup.exists():
shutil.copy2(self._backup, self._path)
self._backup.unlink()
logger.warning("Skill reverted from backup: %s", self._path)
return True
return False
def __enter__(self):
self.backup()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
self.rollback()
return False # Re-raise exception
if not self._committed:
self.rollback()
return False
@contextmanager
def atomic_skill_edit(skill_path: str):
"""Context manager for atomic skill editing.
Usage:
with atomic_skill_edit("/path/to/skill/SKILL.md") as editor:
success = editor.write(new_content)
if not success:
raise ValueError("Write failed")
# __exit__ commits on success, reverts on exception
"""
guard = SkillEditGuard(skill_path)
guard.backup()
try:
yield guard
guard.commit()
except Exception:
guard.rollback()
raise