/**
 * Fission Guard Type Definitions
 *
 * Types for the FissionGuardService — prevents agents from creating
 * unbounded sub-tasks. Implements 6 guardrails: maxDepth, maxTasks,
 * rate limit, branching factor, TTL, and budget gate.
 *
 * @module services/fission/fission-guard.types
 */
/** All valid FissionViolationType values. */
export const FISSION_VIOLATION_TYPES = [
    'max_depth',
    'max_tasks',
    'rate_limit',
    'branching_factor',
    'ttl_exceeded',
    'budget_exceeded',
];
/**
 * Default fission guard configuration.
 * Values match CEO requirements from the implementation checklist.
 */
export const DEFAULT_FISSION_CONFIG = {
    maxDepth: 3,
    maxTasksPerMission: 50,
    hardMaxTasksPerMission: 200,
    rateLimitWindowMs: 600_000, // 10 minutes
    rateLimitMaxCreations: 5,
    maxBranchingFactor: 5,
    defaultTtlMs: 86_400_000, // 24 hours
    maxTtlMs: 604_800_000, // 7 days
    budgetThresholdUsd: 10.0,
    budgetGateEnabled: true,
    maxViolationHistory: 500,
};
// ---------------------------------------------------------------------------
// Type Guards
// ---------------------------------------------------------------------------
/**
 * Checks whether a string is a valid FissionViolationType.
 *
 * @param value - The string to check
 * @returns True if value is a valid FissionViolationType
 */
export function isValidViolationType(value) {
    return FISSION_VIOLATION_TYPES.includes(value);
}
/**
 * Validates that an unknown value conforms to GuardResult.
 *
 * @param value - Unknown value to validate
 * @returns True if value is a valid GuardResult
 */
export function isGuardResult(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    if (typeof obj.allowed !== 'boolean')
        return false;
    if (obj.reason !== undefined && typeof obj.reason !== 'string')
        return false;
    if (obj.violationType !== undefined) {
        if (typeof obj.violationType !== 'string')
            return false;
        if (!isValidViolationType(obj.violationType))
            return false;
    }
    return true;
}
/**
 * Validates that an unknown value conforms to FissionViolation.
 *
 * @param value - Unknown value to validate
 * @returns True if value is a valid FissionViolation
 */
export function isFissionViolation(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.id === 'string' &&
        typeof obj.violationType === 'string' &&
        isValidViolationType(obj.violationType) &&
        typeof obj.agentId === 'string' &&
        typeof obj.parentWorkItemId === 'string' &&
        typeof obj.reason === 'string' &&
        typeof obj.currentValue === 'number' &&
        typeof obj.configuredLimit === 'number' &&
        typeof obj.violatedAt === 'string');
}
/**
 * Validates that an unknown value conforms to FissionGuardConfig.
 *
 * @param value - Unknown value to validate
 * @returns True if value is a valid FissionGuardConfig
 */
export function isValidFissionGuardConfig(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.maxDepth === 'number' && obj.maxDepth > 0 &&
        typeof obj.maxTasksPerMission === 'number' && obj.maxTasksPerMission > 0 &&
        typeof obj.hardMaxTasksPerMission === 'number' && obj.hardMaxTasksPerMission > 0 &&
        typeof obj.rateLimitWindowMs === 'number' && obj.rateLimitWindowMs > 0 &&
        typeof obj.rateLimitMaxCreations === 'number' && obj.rateLimitMaxCreations > 0 &&
        typeof obj.maxBranchingFactor === 'number' && obj.maxBranchingFactor > 0 &&
        typeof obj.defaultTtlMs === 'number' && obj.defaultTtlMs > 0 &&
        typeof obj.maxTtlMs === 'number' && obj.maxTtlMs > 0 &&
        typeof obj.budgetThresholdUsd === 'number' && obj.budgetThresholdUsd >= 0 &&
        typeof obj.budgetGateEnabled === 'boolean' &&
        typeof obj.maxViolationHistory === 'number' && obj.maxViolationHistory > 0);
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
/**
 * Creates a GuardResult indicating the action is allowed.
 *
 * @returns A GuardResult with allowed=true
 */
export function createAllowedResult() {
    return { allowed: true };
}
/**
 * Creates a GuardResult indicating the action is blocked.
 *
 * @param violationType - Which guardrail was violated
 * @param reason - Human-readable explanation
 * @returns A GuardResult with allowed=false
 */
export function createBlockedResult(violationType, reason) {
    return { allowed: false, reason, violationType };
}
//# sourceMappingURL=fission-guard.types.js.map