import "./chunk-KFQGP6VL.js";

// src/mcp/tool-tiers.ts
var CORE_TOOL_NAMES = [
  "validate_project",
  "check_dependencies",
  "check_docs",
  "query_graph",
  "get_impact",
  "manage_state",
  "run_skill",
  "code_search",
  "code_outline",
  "compact"
];
var STANDARD_EXTRA = [
  // Review / scan / analysis
  "run_code_review",
  "run_security_scan",
  "detect_entropy",
  "check_performance",
  "review_changes",
  "analyze_diff",
  // Graph navigation
  "find_context_for",
  "get_relationships",
  "search_similar",
  "compute_blast_radius",
  "ask_graph",
  // Workflow
  "manage_roadmap",
  "check_phase_gate",
  "gather_context",
  "assess_project",
  "recommend_skills",
  "search_skills",
  "code_unfold"
];
var STANDARD_TOOL_NAMES = [...CORE_TOOL_NAMES, ...STANDARD_EXTRA];
var DEFAULT_CHARS_PER_TOKEN = 4;
function estimateBaselineTokens(definitions, charsPerToken = DEFAULT_CHARS_PER_TOKEN) {
  if (charsPerToken <= 0) {
    throw new Error("charsPerToken must be > 0");
  }
  let totalChars = 0;
  for (const def of definitions) {
    totalChars += def.name.length;
    totalChars += def.description.length;
    totalChars += JSON.stringify(def.inputSchema).length;
  }
  return Math.ceil(totalChars / charsPerToken);
}
var DEFAULT_BUDGETS = {
  coreMax: 4e3,
  standardMax: 12e3
};
function selectTier(definitions, options = {}) {
  const budgets = options.budgets ?? DEFAULT_BUDGETS;
  const charsPerToken = options.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN;
  const tier = resolveTier(options, budgets);
  const filter = filterForTier(tier, definitions);
  const effectiveDefs = filter === void 0 ? definitions : definitions.filter((d) => filter.includes(d.name));
  const estimatedTokens = estimateBaselineTokens(effectiveDefs, charsPerToken);
  return {
    tier,
    filter,
    estimatedTokens,
    reason: explainTier(tier, options, budgets)
  };
}
function resolveTier(options, budgets) {
  if (options.overrideTier) return options.overrideTier;
  const budget = options.tokenBudget;
  if (budget === void 0) return "full";
  if (budget < budgets.coreMax) return "core";
  if (budget < budgets.standardMax) return "standard";
  return "full";
}
function filterForTier(tier, definitions) {
  if (tier === "full") return void 0;
  const allow = tier === "core" ? CORE_TOOL_NAMES : STANDARD_TOOL_NAMES;
  const allowSet = new Set(allow);
  const present = new Set(definitions.map((d) => d.name));
  return allow.filter((name) => present.has(name) && allowSet.has(name));
}
function explainTier(tier, options, budgets) {
  if (options.overrideTier) return `override: ${options.overrideTier}`;
  if (options.tokenBudget === void 0) return "no budget specified; defaulting to full";
  return `tokenBudget=${options.tokenBudget} \u2192 ${tier} (thresholds: core<${budgets.coreMax}, standard<${budgets.standardMax})`;
}
export {
  CORE_TOOL_NAMES,
  DEFAULT_BUDGETS,
  DEFAULT_CHARS_PER_TOKEN,
  STANDARD_TOOL_NAMES,
  estimateBaselineTokens,
  selectTier
};
