/**
 * Constitution Schema
 *
 * Zod schema for autofix constitution files that govern
 * which patterns can be auto-applied and under what conditions.
 *
 * @module autofix/constitution.schema
 */
import { z } from "zod";
/**
 * Risk tolerance levels for autofix operations
 */
export const RiskToleranceSchema = z.enum([
    "conservative", // Only auto-apply patterns marked safeToAutoApply with low risk
    "moderate", // Auto-apply safe patterns and low/medium risk
    "aggressive", // Auto-apply all patterns
]);
/**
 * Severity levels
 */
export const SeveritySchema = z.enum([
    "info",
    "low",
    "medium",
    "high",
    "critical",
]);
/**
 * Conditions for pattern approval
 */
export const PatternConditionsSchema = z.object({
    /** Only allow in specific directories */
    allowedPaths: z.array(z.string()).optional(),
    /** Exclude from specific directories */
    excludedPaths: z.array(z.string()).optional(),
    /** Maximum lines changed per fix */
    maxLinesChanged: z.number().positive().optional(),
    /** Only if severity at or above this level */
    minSeverity: SeveritySchema.optional(),
}).optional();
/**
 * Pattern approval configuration
 */
export const PatternApprovalSchema = z.object({
    /** Pattern ID from FIX_PATTERNS */
    patternId: z.string().min(1),
    /** Whether this pattern can be auto-applied */
    autoApprove: z.boolean(),
    /** Required reviewer if not auto-approved */
    requiredReviewer: z.string().optional(),
    /** Additional conditions for auto-approval */
    conditions: PatternConditionsSchema,
});
/**
 * PR creation rules
 */
export const PRRulesSchema = z.object({
    /** Require human approval before merge */
    requireApproval: z.boolean().default(true),
    /** Minimum number of approvers */
    minApprovers: z.number().min(0).default(1),
    /** Required labels on all autofix PRs */
    requiredLabels: z.array(z.string()).default(["autofix", "security"]),
    /** Assignees for autofix PRs */
    defaultAssignees: z.array(z.string()).default([]),
    /** Reviewers for autofix PRs */
    defaultReviewers: z.array(z.string()).default([]),
    /** Title prefix for autofix commits */
    commitPrefix: z.string().default("fix(security):"),
    /** Include Co-Authored-By in commits */
    includeCoAuthor: z.boolean().default(true),
    /** Maximum PRs to create in a single run */
    maxPRsPerRun: z.number().min(1).default(10),
    /** Group fixes by this strategy */
    groupBy: z.enum(["severity", "file", "pattern", "single"]).default("severity"),
});
/**
 * Directory-level restrictions
 */
export const DirectoryRulesSchema = z.object({
    /** Never auto-fix in these directories */
    neverAutofix: z.array(z.string()).default([
        "node_modules",
        "vendor",
        ".git",
        "dist",
        "build",
    ]),
    /** Always require review in these directories */
    requireReview: z.array(z.string()).default([
        "src/auth",
        "src/security",
        "src/crypto",
    ]),
    /** Skip scanning these directories entirely */
    ignore: z.array(z.string()).default([]),
});
/**
 * Safety constraints
 */
export const SafetyConstraintsSchema = z.object({
    /** Require clean git working tree before applying fixes */
    requireCleanWorkingTree: z.boolean().default(true),
    /** Create backup branch before applying fixes */
    createBackupBranch: z.boolean().default(true),
    /** Run tests after applying fixes */
    runTestsAfterFix: z.boolean().default(true),
    /** Test command to run */
    testCommand: z.string().default("npm test"),
    /** Revert fix if tests fail */
    revertOnTestFailure: z.boolean().default(true),
    /** Maximum total files to modify in one run */
    maxFilesPerRun: z.number().min(1).default(20),
    /** Dry run by default (require explicit --apply) */
    dryRunDefault: z.boolean().default(true),
});
/**
 * Full constitution configuration
 */
export const ConstitutionSchema = z.object({
    /** Version of the constitution schema */
    version: z.literal("1.0"),
    /** Organization name */
    organization: z.string().optional(),
    /** Overall risk tolerance */
    riskTolerance: RiskToleranceSchema.default("conservative"),
    /** Pattern-specific approvals */
    patterns: z.array(PatternApprovalSchema).default([]),
    /** PR creation rules */
    prRules: PRRulesSchema.default({}),
    /** Directory restrictions */
    directories: DirectoryRulesSchema.default({}),
    /** Safety constraints */
    safety: SafetyConstraintsSchema.default({}),
    /** Custom metadata to include in PRs */
    metadata: z.record(z.string(), z.string()).optional(),
});
/**
 * Default constitution with conservative settings
 */
export const DEFAULT_CONSTITUTION = ConstitutionSchema.parse({
    version: "1.0",
});
//# sourceMappingURL=constitution.schema.js.map