work in progress.

This commit is contained in:
2026-01-14 18:35:57 +01:00
parent dbd534d860
commit 7871ef1b1e
11 changed files with 1029 additions and 2 deletions

View File

@@ -260,3 +260,56 @@ ALTER TABLE user_facts ADD COLUMN IF NOT EXISTS temporal_relevance VARCHAR(20);
ALTER TABLE user_facts ADD COLUMN IF NOT EXISTS expiry_date TIMESTAMPTZ;
ALTER TABLE user_facts ADD COLUMN IF NOT EXISTS extracted_from_message_id BIGINT;
ALTER TABLE user_facts ADD COLUMN IF NOT EXISTS extraction_context TEXT;
-- =====================================================
-- ATTACHMENT TRACKING TABLES
-- =====================================================
-- User attachment profiles (tracks attachment patterns per user)
CREATE TABLE IF NOT EXISTS user_attachment_profiles (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
guild_id BIGINT, -- NULL = global profile
primary_style VARCHAR(20) DEFAULT 'unknown', -- secure, anxious, avoidant, disorganized, unknown
style_confidence FLOAT DEFAULT 0.0, -- 0.0 to 1.0
current_state VARCHAR(20) DEFAULT 'regulated', -- regulated, activated, mixed
state_intensity FLOAT DEFAULT 0.0, -- 0.0 to 1.0
anxious_indicators INTEGER DEFAULT 0, -- running count of anxious pattern matches
avoidant_indicators INTEGER DEFAULT 0, -- running count of avoidant pattern matches
secure_indicators INTEGER DEFAULT 0, -- running count of secure pattern matches
disorganized_indicators INTEGER DEFAULT 0, -- running count of disorganized pattern matches
last_activation_at TIMESTAMPTZ, -- when attachment system was last activated
activation_count INTEGER DEFAULT 0, -- total activations
activation_triggers JSONB DEFAULT '[]', -- learned triggers that activate attachment
effective_responses JSONB DEFAULT '[]', -- response styles that helped regulate
ineffective_responses JSONB DEFAULT '[]', -- response styles that didn't help
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(user_id, guild_id)
);
CREATE INDEX IF NOT EXISTS ix_user_attachment_profiles_user_id ON user_attachment_profiles(user_id);
CREATE INDEX IF NOT EXISTS ix_user_attachment_profiles_guild_id ON user_attachment_profiles(guild_id);
CREATE INDEX IF NOT EXISTS ix_user_attachment_profiles_primary_style ON user_attachment_profiles(primary_style);
-- Attachment events (logs attachment-related events for learning)
CREATE TABLE IF NOT EXISTS attachment_events (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
guild_id BIGINT,
event_type VARCHAR(50) NOT NULL, -- activation, regulation, escalation, etc.
detected_style VARCHAR(20), -- anxious, avoidant, disorganized, mixed
intensity FLOAT DEFAULT 0.0, -- 0.0 to 1.0
trigger_message TEXT, -- the message that triggered the event (truncated)
trigger_indicators JSONB DEFAULT '[]', -- patterns that matched
response_style VARCHAR(50), -- how Bartender responded
outcome VARCHAR(20), -- helpful, neutral, unhelpful (set after follow-up)
notes TEXT, -- any additional context
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS ix_attachment_events_user_id ON attachment_events(user_id);
CREATE INDEX IF NOT EXISTS ix_attachment_events_guild_id ON attachment_events(guild_id);
CREATE INDEX IF NOT EXISTS ix_attachment_events_event_type ON attachment_events(event_type);
CREATE INDEX IF NOT EXISTS ix_attachment_events_created_at ON attachment_events(created_at);