function parseBoolean(value, fallback) {
    if (value == null || value === '')
        return fallback;
    return ['1', 'true', 'yes', 'on'].includes(value.toLowerCase());
}
function parseInteger(value, fallback) {
    const parsed = Number.parseInt(value ?? '', 10);
    return Number.isFinite(parsed) ? parsed : fallback;
}
function parseFloatNumber(value, fallback) {
    const parsed = Number.parseFloat(value ?? '');
    return Number.isFinite(parsed) ? parsed : fallback;
}
function clampInteger(value, min, max) {
    if (!Number.isFinite(value))
        return min;
    return Math.max(min, Math.min(max, Math.floor(value)));
}
// Investor-ready default: Synapse is available out of the box, but with small
// safe limits so it does not spawn an unbounded workforce or create runaway disk
// pressure. Operators can still disable it with SYNAPSE_ENABLED=0.
export const SynapseConfig = {
    enabled: parseBoolean(process.env.SYNAPSE_ENABLED, true),
    maxOpsPerTeam: clampInteger(parseInteger(process.env.SYNAPSE_MAX_OPERATIVES_PER_TEAM, 3), 1, 5),
    defaultBudgetUsd: parseFloatNumber(process.env.SYNAPSE_DEFAULT_BUDGET_USD, 10),
    sortieIntervalMs: parseInteger(process.env.SYNAPSE_SORTIE_INTERVAL_MS, 60_000),
    compactionBudgetTokens: parseInteger(process.env.SYNAPSE_COMPACTION_BUDGET_TOKENS, 25_000),
    echoEnabled: parseBoolean(process.env.SYNAPSE_ECHO_ENABLED, true),
    echoMinSimilarity: parseFloatNumber(process.env.SYNAPSE_ECHO_MIN_SIMILARITY, 0.7),
    ledgerEnabled: parseBoolean(process.env.SYNAPSE_LEDGER_ENABLED, true),
    ledgerCommitIntervalMs: parseInteger(process.env.SYNAPSE_LEDGER_COMMIT_INTERVAL_MS, 120_000),
    watchdogEnabled: parseBoolean(process.env.SYNAPSE_WATCHDOG_ENABLED, true),
    watchdogPatrolIntervalMs: parseInteger(process.env.SYNAPSE_WATCHDOG_PATROL_INTERVAL_MS, 180_000),
    watchdogStallMs: parseInteger(process.env.SYNAPSE_WATCHDOG_STALL_MS, 300_000),
    watchdogZombieMs: parseInteger(process.env.SYNAPSE_WATCHDOG_ZOMBIE_MS, 900_000),
};
