feat(ai-psychosis): promote domain_context to array for multi-domain support

This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 21:28:36 +02:00
commit a5bc53cb42
6 changed files with 72 additions and 11 deletions

View file

@ -137,7 +137,19 @@ state.esc_flags = newEsc;
state.fatigue_flags = newFat;
state.val_flags = newVal;
state.pushback_count = (Number(state.pushback_count) || 0) + pbReactiveHit + pbPreemptiveHit;
if (domainHit === 1 && !state.domain_context) state.domain_context = 'relationship';
// v1.2: domain_context is always an array. Coerce v1.1.0 string shape on read.
if (domainHit === 1) {
if (typeof state.domain_context === 'string') {
state.domain_context = state.domain_context ? [state.domain_context] : [];
}
if (!Array.isArray(state.domain_context)) {
state.domain_context = [];
}
if (!state.domain_context.includes('relationship')) {
state.domain_context.push('relationship');
}
}
writeState(state);
// Check if any thresholds crossed

View file

@ -46,9 +46,11 @@ export function aggregateSessions(sessions) {
total_fatigue += Number(flags.fatigue) || 0;
total_validation += Number(flags.validation) || 0;
// v1.2: domain_context is array; v1.0/v1.1: null or string. Coerce on read.
const dc = rec.domain_context;
if (dc === null || dc === undefined) null_domain_count += 1;
else if (dc === 'relationship') relationship_domain_count += 1;
const domains = Array.isArray(dc) ? dc : (dc ? [dc] : []);
if (domains.length === 0) null_domain_count += 1;
else if (domains.includes('relationship')) relationship_domain_count += 1;
else other_domain_count += 1;
}

View file

@ -39,7 +39,11 @@ const escFlags = Number(state.esc_flags) || 0;
const fatFlags = Number(state.fatigue_flags) || 0;
const valFlags = Number(state.val_flags) || 0;
const pushbackCount = Number(state.pushback_count) || 0;
const domainContext = state.domain_context || null;
// v1.2: domain_context is always written as array. Coerce v1.1.0 string shape.
const domainContextRaw = state.domain_context;
const domainContextArray = Array.isArray(domainContextRaw)
? domainContextRaw
: (domainContextRaw ? [domainContextRaw] : []);
const startIso = state.start_iso || '';
// Compute duration
@ -56,7 +60,7 @@ appendJsonl(SESSIONS_LOG, {
duration_min: durationMin,
tool_count: toolCount,
edit_count: editCount,
domain_context: domainContext,
domain_context: domainContextArray,
flags: {
dependency: depFlags,
escalation: escFlags,