Compare commits

...

1 Commits

Author SHA1 Message Date
Timmy
2dea8f1f59 fix(#1601): MemPalace regression + crisis logic alignment
Some checks failed
Review Approval Gate / verify-review (pull_request) Failing after 8s
CI / test (pull_request) Failing after 1m4s
CI / validate (pull_request) Failing after 1m2s
1. MemPalace: Removed mock MCP connectMemPalace() that overwrote
   the real Fleet API version. Only the port-7771 polling version
   remains. connectMemPalace definitions: 2 -> 1.

2. Crisis detection: Added JS crisis keyword detection aligned
   with CRISIS_PROTOCOL from multi_user_bridge.py:
   - detectCrisis(text): checks for 25 crisis keywords
   - showCrisisResponse(): immediate response with 988 Lifeline,
     Crisis Text Line, grounding exercise
   - Called from sendChatMessage() before normal processing

Fixes #1601
2026-04-17 01:39:35 -04:00

110
app.js
View File

@@ -2143,6 +2143,48 @@ function setupControls() {
});
}
// ═══ Crisis Detection (#1601) ═══════════════════════════════════
// Aligns with CRISIS_PROTOCOL in multi_user_bridge.py.
// Detects crisis signals in user input and provides immediate response.
const CRISIS_KEYWORDS = [
'suicide', 'suicidal', 'kill myself', 'end my life', 'end it all',
'want to die', 'wanna die', 'don\'t want to live', 'no reason to live',
'self-harm', 'self harm', 'hurt myself', 'cutting myself',
'hopeless', 'no hope', 'give up', 'can\'t go on', 'cant go on',
'tired of living', 'better off dead', 'nobody cares', 'no one would miss',
'overdose', 'jump off', 'hang myself', 'gun to my head',
];
function detectCrisis(text) {
const lower = text.toLowerCase();
return CRISIS_KEYWORDS.some(kw => lower.includes(kw));
}
function showCrisisResponse() {
// Immediate crisis response — matches multi_user_bridge.py CRISIS_PROTOCOL
const steps = [
'Are you safe right now?',
'988 Suicide & Crisis Lifeline — call or text 988 (US)',
'Crisis Text Line — text HOME to 741741',
'Grounding: Name 5 things you see, 4 you can touch, 3 you hear, 2 you smell, 1 you taste',
];
const container = document.getElementById('chat-messages');
const div = document.createElement('div');
div.className = 'chat-msg chat-msg-timmy';
div.style.cssText = 'background: #1a0808; border: 1px solid #f44336; padding: 12px; border-radius: 4px; margin: 8px 0;';
div.innerHTML = `
<div style="color: #f44336; font-weight: bold; margin-bottom: 8px;">⚠ You are not alone</div>
${steps.map((s, i) => `<div style="margin: 4px 0; color: #ddd;">${i + 1}. ${s}</div>`).join('')}
<div style="margin-top: 8px; color: #aaa; font-size: 11px;">
I'm here. I'm not going anywhere. You matter.
</div>
`;
container.appendChild(div);
container.scrollTop = container.scrollHeight;
}
function sendChatMessage(overrideText = null) {
// Mine chat message to MemPalace
if (overrideText) {
@@ -2151,6 +2193,16 @@ function sendChatMessage(overrideText = null) {
const input = document.getElementById('chat-input');
const text = overrideText || input.value.trim();
if (!text) return;
// Crisis detection — aligns with CRISIS_PROTOCOL in multi_user_bridge.py
if (detectCrisis(text)) {
addChatMessage('user', text);
showCrisisResponse();
if (!overrideText) input.value = '';
input.blur();
return;
}
addChatMessage('user', text);
if (!overrideText) input.value = '';
setTimeout(() => {
@@ -3903,65 +3955,9 @@ init().then(() => {
navigator.serviceWorker.register('/service-worker.js');
}
// Initialize MemPalace memory system
function connectMemPalace() {
try {
// Initialize MemPalace MCP server
console.log('Initializing MemPalace memory system...');
// Actual MCP server connection
const statusEl = document.getElementById('mem-palace-status');
if (statusEl) {
statusEl.textContent = 'MemPalace ACTIVE';
statusEl.style.color = '#4af0c0';
statusEl.style.textShadow = '0 0 10px #4af0c0';
}
// Initialize MCP server connection
if (window.Claude && window.Claude.mcp) {
window.Claude.mcp.add('mempalace', {
init: () => {
return { status: 'active', version: '3.0.0' };
},
search: (query) => {
return new Promise((query) => {
setTimeout(() => {
resolve([
{
id: '1',
content: 'MemPalace: Palace architecture, AAAK compression, knowledge graph',
score: 0.95
},
{
id: '2',
content: 'AAAK compression: 30x lossless compression for AI agents',
score: 0.88
}
]);
}, 500);
});
}
});
}
// Initialize memory stats tracking
document.getElementById('compression-ratio').textContent = '0x';
document.getElementById('docs-mined').textContent = '0';
document.getElementById('aaak-size').textContent = '0B';
} catch (err) {
console.error('Failed to initialize MemPalace:', err);
const statusEl = document.getElementById('mem-palace-status');
if (statusEl) {
statusEl.textContent = 'MemPalace ERROR';
statusEl.style.color = '#ff4466';
statusEl.style.textShadow = '0 0 10px #ff4466';
}
}
}
// Initialize MemPalace — Fleet API polling at line 2772
// Initialize MemPalace
const mempalace = {
status: { compression: 0, docs: 0, aak: '0B' },
mineChat: () => {
try {
const messages = Array.from(document.querySelectorAll('.chat-msg')).map(m => m.innerText);