// ─────────────────────────────────────────────────────────────────────────────
// Nexus Prime Licensing — Tool-to-Tier Classification
//
// Every MCP tool is assigned a minimum PlanTier. Free-tier tools map to the
// AUTONOMOUS_TOOL_SET from mcp.ts. Higher tiers unlock progressively more
// powerful features.
// ─────────────────────────────────────────────────────────────────────────────
/**
 * Tier rank for comparison: free < pro < team < enterprise.
 */
export const TIER_RANK = {
    free: 0,
    pro: 1,
    team: 2,
    enterprise: 3,
};
// ── Free tier: core workflow (28 tools from AUTONOMOUS_TOOL_SET) ────────────
const FREE_TOOLS = new Set([
    'nexus_session_bootstrap',
    'nexus_orchestrate',
    'nexus_plan_execution',
    'nexus_recall_memory',
    'nexus_memory_stats',
    'nexus_temporal_query',
    'nexus_store_memory',
    'nexus_search',
    'nexus_describe_tool',
    'nexus_optimize_tokens',
    'nexus_mindkit_check',
    'nexus_ghost_pass',
    'nexus_spawn_workers',
    'nexus_token_report',
    'nexus_session_dna',
    'nexus_list_skills',
    'nexus_list_workflows',
    'nexus_list_hooks',
    'nexus_list_automations',
    'nexus_list_specialists',
    'nexus_list_crews',
    'nexus_federation_status',
    'nexus_run_status',
    'nexus_runtime_health',
    'nexus_doctor',
    'nexus_autofix',
    'nexus_memory_hygiene',
    'nexus_operative_journal',
    'nexus_selection_ledger',
    // License management is always free
    'nexus_license_usage',
]);
// ── Team tier: Synapse multi-agent hiring (16 tools) ───────────────────────
const TEAM_TOOLS = new Set([
    'nexus_synapse_mandate',
    'nexus_synapse_hire',
    'nexus_synapse_operatives',
    'nexus_synapse_operatives_update',
    'nexus_synapse_heartbeat',
    'nexus_synapse_approval_resolve',
    'nexus_synapse_assign_mission',
    'nexus_synapse_sortie_start',
    'nexus_synapse_sortie_end',
    'nexus_synapse_field_report',
    'nexus_synapse_cost_report',
    'nexus_synapse_request_approval',
    'nexus_synapse_echo',
    'nexus_synapse_mission_progress',
    'nexus_synapse_striketeam_status',
    'nexus_synapse_health',
]);
// ── Enterprise tier: Architects structured work management (10 tools) ──────
const ENTERPRISE_TOOLS = new Set([
    'nexus_architects_blueprint_create',
    'nexus_architects_worklist_get',
    'nexus_architects_workitem_claim',
    'nexus_architects_workitem_complete',
    'nexus_architects_relay_send',
    'nexus_architects_relay_inbox',
    'nexus_architects_sentinel_report',
    'nexus_architects_convergence_run',
    'nexus_architects_dispatch_status',
    'nexus_architects_ward_escalations',
]);
// ── Everything else is Pro ─────────────────────────────────────────────────
/**
 * Returns the minimum tier required to use a given MCP tool.
 * Unknown tools default to 'pro' (conservative: require explicit free-listing).
 */
export function getToolTier(toolName) {
    if (FREE_TOOLS.has(toolName))
        return 'free';
    if (TEAM_TOOLS.has(toolName))
        return 'team';
    if (ENTERPRISE_TOOLS.has(toolName))
        return 'enterprise';
    return 'pro'; // all remaining core tools: RAG, Darwin, patterns, etc.
}
/**
 * Returns true if the given tool is accessible at the given tier.
 */
export function isToolAllowed(toolName, userTier) {
    const required = getToolTier(toolName);
    return TIER_RANK[userTier] >= TIER_RANK[required];
}
/**
 * Returns the tier label for display (capitalized).
 */
export function tierLabel(tier) {
    return tier.charAt(0).toUpperCase() + tier.slice(1);
}
