/**
 * Single place to interpret optional feature flags (env → typed booleans).
 * See docs/mcp-tools.md and GitHub #79.
 */
import { z } from "zod";
/** `1`, `true`, `yes` (case-insensitive) → true; unset or other → false. */
function envTruthy(v) {
    if (v === undefined)
        return false;
    const t = v.trim().toLowerCase();
    return t === "1" || t === "true" || t === "yes";
}
const rawOptionalFlagsSchema = z.object({
    ENABLE_GRPC: z.string().optional(),
    ENABLE_GRPC_REFLECTION: z.string().optional(),
    CLAWQL_EXTERNAL_INGEST: z.string().optional(),
    CLAWQL_ENABLE_CACHE: z.string().optional(),
    CLAWQL_ENABLE_SCHEDULE: z.string().optional(),
    CLAWQL_ENABLE_NOTIFY: z.string().optional(),
    CLAWQL_ENABLE_VISION: z.string().optional(),
    CLAWQL_ENABLE_AUDIT: z.string().optional(),
    CLAWQL_ENABLE_ONYX: z.string().optional(),
    CLAWQL_ENABLE_OUROBOROS: z.string().optional(),
});
function rawToFlags(raw) {
    return {
        enableGrpc: envTruthy(raw.ENABLE_GRPC),
        enableGrpcReflection: envTruthy(raw.ENABLE_GRPC_REFLECTION),
        externalIngestPreview: raw.CLAWQL_EXTERNAL_INGEST?.trim() === "1",
        enableCache: envTruthy(raw.CLAWQL_ENABLE_CACHE),
        enableSchedule: envTruthy(raw.CLAWQL_ENABLE_SCHEDULE),
        enableNotify: envTruthy(raw.CLAWQL_ENABLE_NOTIFY),
        enableVision: envTruthy(raw.CLAWQL_ENABLE_VISION),
        enableAudit: envTruthy(raw.CLAWQL_ENABLE_AUDIT),
        enableOnyxKnowledge: envTruthy(raw.CLAWQL_ENABLE_ONYX),
        enableOuroboros: envTruthy(raw.CLAWQL_ENABLE_OUROBOROS),
    };
}
/**
 * Parsed optional tool flags from the given env (default `process.env`).
 */
export function getClawqlOptionalToolFlags(env = process.env) {
    const raw = rawOptionalFlagsSchema.parse(env);
    return rawToFlags(raw);
}
