/** * llmindex.io — worker environment loading + cost guardrails * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import { existsSync } from 'node:fs'; import { resolve } from 'node:path'; // Load the repo-root .env when present (worker runs via tsx, no framework loader). for (const candidate of [resolve(process.cwd(), '.env'), resolve(process.cwd(), '../../.env')]) { if (existsSync(candidate)) { try { process.loadEnvFile(candidate); } catch { /* ignore malformed env file lines */ } break; } } /** Hard cap per batch: the worker refuses to start a batch estimated above this. */ export function maxRunCostUsd(): number { const v = Number(process.env.MAX_RUN_COST_USD ?? 50); return Number.isFinite(v) && v > 0 ? v : 50; } export function redisUrl(): string { return process.env.REDIS_URL ?? 'redis://127.0.0.1:6379'; }