"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GovernanceScopePolicy = void 0;
const IntentClassifier_1 = require("./IntentClassifier");
const GovernancePolicyStore_1 = require("./GovernancePolicyStore");
class GovernanceScopePolicy {
    policyStore;
    constructor() {
        this.policyStore = new GovernancePolicyStore_1.GovernancePolicyStore();
    }
    decide(task, input, project = 'default') {
        const normalized = input.toLowerCase();
        const policy = this.policyStore.load(project);
        const projectScope = /secret|token|password|credential|api\s*key/i.test(normalized)
            ? 'sensitive'
            : task.intent === IntentClassifier_1.TaskIntent.ENGINEERING_BUILD
                ? 'engineering'
                : task.intent === IntentClassifier_1.TaskIntent.RESEARCH_ANALYSIS
                    ? 'research'
                    : 'general';
        const policyScope = policy?.scopes?.[projectScope];
        if (policyScope) {
            return {
                projectScope,
                allowedCapabilities: policyScope.allowedCapabilities,
                deniedCapabilities: policyScope.deniedCapabilities,
                rationale: `Escopo ${projectScope} carregado de governance-policy.json.`
            };
        }
        if (projectScope === 'sensitive') {
            return {
                projectScope: 'sensitive',
                allowedCapabilities: ['analysis', 'review', 'synthesis', 'orchestration'],
                deniedCapabilities: ['release', 'deploy', 'destructive-write'],
                rationale: 'Entrada sensível: liberar apenas capacidades de leitura, revisão e síntese.'
            };
        }
        if (projectScope === 'engineering') {
            return {
                projectScope: 'engineering',
                allowedCapabilities: ['orchestration', 'build', 'review', 'qa', 'synthesis'],
                deniedCapabilities: ['release'],
                rationale: 'Escopo de engenharia: build e review liberados, release segue protegido.'
            };
        }
        if (projectScope === 'research') {
            return {
                projectScope: 'research',
                allowedCapabilities: ['analysis', 'review', 'synthesis'],
                deniedCapabilities: ['build', 'release', 'destructive-write'],
                rationale: 'Escopo de research: execução restrita a análise e síntese.'
            };
        }
        return {
            projectScope: 'general',
            allowedCapabilities: ['orchestration', 'analysis', 'synthesis'],
            deniedCapabilities: ['release', 'destructive-write'],
            rationale: 'Escopo geral conservador por padrão.'
        };
    }
    filterCapabilities(capabilities, scope) {
        const denied = capabilities.filter((cap) => scope.deniedCapabilities.includes(cap));
        const allowed = capabilities.filter((cap) => scope.allowedCapabilities.includes(cap));
        return { allowed, denied };
    }
}
exports.GovernanceScopePolicy = GovernanceScopePolicy;
