From e1e6788237d026ed41bd70b1abd0990bb8df66b6 Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Wed, 15 Apr 2026 22:04:57 -0400 Subject: [PATCH] fix(#1601): align JS crisis detection with Python 5-tier system Split crisisKeywords into highKeywords (suicidal ideation, self-harm) and mediumKeywords (distress, hopelessness). Updated getCrisisLevel() to return 0-4 (NONE/LOW/MEDIUM/HIGH/CRITICAL) matching the Python backend and the existing COMPASSION_PROFILES. Part of #1601 --- index.html | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 06cff1c..665fd2b 100644 --- a/index.html +++ b/index.html @@ -854,21 +854,23 @@ Sovereignty and service always.`; // ===== CRISIS KEYWORDS ===== // Tier 1: General crisis indicators - triggers enhanced 988 panel - var crisisKeywords = [ - // Original keywords + // HIGH: suicidal ideation, self-harm — triggers level 3 + var highKeywords = [ 'suicide', 'kill myself', 'end it all', 'no reason to live', - 'want to die', "can't go on", 'nobody cares', 'better off without me', - 'goodbye forever', 'end my life', 'not worth living', 'no way out', - // Self-harm (NEW) + 'want to die', 'end my life', 'not worth living', 'goodbye forever', + 'better off without me', 'hurt myself', 'self harm', 'self-harm', 'cutting myself', 'cut myself', 'burn myself', 'scratch myself', 'hitting myself', 'harm myself', - // Passive suicidal ideation (NEW) "don't want to exist", 'not exist anymore', 'disappear forever', - 'never wake up', 'sleep forever', 'end the pain', 'stop the pain', - // Hopelessness (NEW) - context-aware phrases to reduce false positives - 'no purpose', 'nothing matters', 'giving up on life', - 'cant go on', 'cannot go on', "can't take it", 'too much pain', - 'no hope left', 'burden', 'waste of space' + 'never wake up', 'sleep forever', 'end the pain' + ]; + + // MEDIUM: distress, hopelessness — triggers level 2 + var mediumKeywords = [ + 'no way out', "can't go on", 'cant go on', 'cannot go on', + 'nobody cares', 'nothing matters', 'no purpose', 'giving up on life', + "can't take it", 'too much pain', 'no hope left', 'burden', + 'waste of space', 'stop the pain' ]; // Tier 2: Explicit intent - triggers full-screen overlay @@ -956,10 +958,13 @@ Sovereignty and service always.`; function getCrisisLevel(text) { var lower = text.toLowerCase(); for (var i = 0; i < explicitPhrases.length; i++) { - if (lower.indexOf(explicitPhrases[i]) !== -1) return 2; + if (lower.indexOf(explicitPhrases[i]) !== -1) return 4; } - for (var j = 0; j < crisisKeywords.length; j++) { - if (lower.indexOf(crisisKeywords[j]) !== -1) return 1; + for (var j = 0; j < highKeywords.length; j++) { + if (lower.indexOf(highKeywords[j]) !== -1) return 3; + } + for (var k = 0; k < mediumKeywords.length; k++) { + if (lower.indexOf(mediumKeywords[k]) !== -1) return 2; } return 0; } @@ -969,7 +974,7 @@ Sovereignty and service always.`; var level = getCrisisLevel(userText); if (level === 0) return SYSTEM_PROMPT; - var levelMap = { 0: 'NONE', 1: 'MEDIUM', 2: 'CRITICAL' }; + var levelMap = { 0: 'NONE', 1: 'LOW', 2: 'MEDIUM', 3: 'HIGH', 4: 'CRITICAL' }; var profileName = levelMap[level] || 'NONE'; var profile = COMPASSION_PROFILES[profileName];