/** * Raw-layer configuration. * * The row config in cordis.patch.yml is the first-boot seed. Keeping the * parser here (rather than in the five-bundle Settings store) lets the raw * recorder stay an optional, self-contained row: disabling the row stops all * capture, and changing its config changes the recorder without touching * Mnemon or the existing memory bundles. */ import { join, resolve } from 'node:path'; import { dshHome } from "../store.js"; function asRecord(value) { if (value === null || typeof value !== 'object' || Array.isArray(value)) return {}; return value; } function bool(value, fallback) { return typeof value === 'boolean' ? value : fallback; } function integer(value, fallback, min, max) { if (typeof value !== 'number' || !Number.isFinite(value)) return fallback; return Math.min(max, Math.max(min, Math.trunc(value))); } /** Parse one raw-row config defensively; every field is optional. */ export function rawMemorySettingsFromConfig(config) { const source = asRecord(config); const rawDir = typeof source.rawDir === 'string' ? source.rawDir.trim() : ''; return { enabled: bool(source.rawEnabled, true), captureAssistant: bool(source.rawCaptureAssistant, true), dir: rawDir === '' ? join(dshHome(), 'brain', 'raw') : resolve(rawDir), retentionDays: integer(source.rawRetentionDays, 90, 1, 3650), maxBytesPerSession: integer(source.rawMaxBytesPerSession, 20_000_000, 100_000, 1_000_000_000), maxTextChars: integer(source.rawMaxTextChars, 16_000, 1_000, 200_000), maxSearchResults: integer(source.rawMaxSearchResults, 10, 1, 50), maxReadRecords: integer(source.rawMaxReadRecords, 50, 1, 500), }; }