var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
  if (typeof require !== "undefined") return require.apply(this, arguments);
  throw Error('Dynamic require of "' + x + '" is not supported');
});

// src/index.ts
import {
  ToolRegistry,
  ToolName,
  calculateOverallScore,
  calculateTokenBudget
} from "@aiready/core";
import "@aiready/pattern-detect";
import "@aiready/context-analyzer";
import "@aiready/consistency";
import "@aiready/ai-signal-clarity";
import "@aiready/agent-grounding";
import "@aiready/testability";
import "@aiready/doc-drift";
import "@aiready/deps";
import "@aiready/change-amplification";
var TOOL_PACKAGE_MAP = {
  [ToolName.PatternDetect]: "@aiready/pattern-detect",
  [ToolName.ContextAnalyzer]: "@aiready/context-analyzer",
  [ToolName.NamingConsistency]: "@aiready/consistency",
  [ToolName.AiSignalClarity]: "@aiready/ai-signal-clarity",
  [ToolName.AgentGrounding]: "@aiready/agent-grounding",
  [ToolName.TestabilityIndex]: "@aiready/testability",
  [ToolName.DocDrift]: "@aiready/doc-drift",
  [ToolName.DependencyHealth]: "@aiready/deps",
  [ToolName.ChangeAmplification]: "@aiready/change-amplification",
  // Aliases handled by registry
  patterns: "@aiready/pattern-detect",
  duplicates: "@aiready/pattern-detect",
  context: "@aiready/context-analyzer",
  fragmentation: "@aiready/context-analyzer",
  consistency: "@aiready/consistency",
  "naming-consistency": "@aiready/consistency",
  "ai-signal": "@aiready/ai-signal-clarity",
  "ai-signal-clarity": "@aiready/ai-signal-clarity",
  grounding: "@aiready/agent-grounding",
  "agent-grounding": "@aiready/agent-grounding",
  testability: "@aiready/testability",
  "testability-index": "@aiready/testability",
  "doc-drift": "@aiready/doc-drift",
  "deps-health": "@aiready/deps",
  "dependency-health": "@aiready/deps",
  "change-amp": "@aiready/change-amplification",
  "change-amplification": "@aiready/change-amplification"
};
async function analyzeUnified(options) {
  const startTime = Date.now();
  const requestedTools = options.tools || [
    "patterns",
    "context",
    "consistency"
  ];
  const result = {
    summary: {
      totalIssues: 0,
      totalFiles: 0,
      toolsRun: [],
      executionTime: 0
    }
  };
  for (const toolName of requestedTools) {
    let provider = ToolRegistry.find(toolName);
    if (!provider) {
      const packageName = TOOL_PACKAGE_MAP[toolName] || (toolName.startsWith("@aiready/") ? toolName : `@aiready/${toolName}`);
      try {
        await import(packageName);
        provider = ToolRegistry.find(toolName);
        if (provider) {
          console.log(
            `\u2705 Successfully loaded tool provider: ${toolName} from ${packageName}`
          );
        } else {
          console.log(
            `\u26A0\uFE0F Loaded ${packageName} but provider ${toolName} still not found in registry.`
          );
        }
      } catch (err) {
        console.log(
          `\u274C Failed to dynamically load tool ${toolName} (${packageName}):`,
          err.message
        );
      }
    }
    if (!provider) {
      console.warn(
        `\u26A0\uFE0F  Warning: Tool provider for '${toolName}' not found. Skipping.`
      );
      continue;
    }
    try {
      const output = await provider.analyze({
        ...options,
        onProgress: (processed, total, message) => {
          if (options.progressCallback) {
            options.progressCallback({
              tool: provider.id,
              processed,
              total,
              message
            });
          }
        }
      });
      if (options.progressCallback) {
        options.progressCallback({ tool: provider.id, data: output });
      }
      result[provider.id] = output;
      result.summary.toolsRun.push(provider.id);
      const toolFiles = output.summary?.totalFiles || output.summary?.filesAnalyzed || 0;
      if (toolFiles > result.summary.totalFiles) {
        result.summary.totalFiles = toolFiles;
      }
      const issueCount = output.results.reduce(
        (sum, file) => sum + (file.issues?.length || 0),
        0
      );
      result.summary.totalIssues += issueCount;
      if (provider.alias && Array.isArray(provider.alias)) {
        for (const alias of provider.alias) {
          if (!result[alias]) {
            result[alias] = output;
          }
        }
      }
      const camelCaseId = provider.id.replace(
        /-([a-z])/g,
        (g) => g[1].toUpperCase()
      );
      if (camelCaseId !== provider.id && !result[camelCaseId]) {
        result[camelCaseId] = output;
      }
    } catch (err) {
      console.error(`\u274C Error running tool '${provider.id}':`, err);
    }
  }
  result.summary.executionTime = Date.now() - startTime;
  return result;
}
async function scoreUnified(results, options) {
  const toolScores = /* @__PURE__ */ new Map();
  for (const toolId of results.summary.toolsRun) {
    const provider = ToolRegistry.get(toolId);
    if (!provider) continue;
    const output = results[toolId];
    if (!output) continue;
    try {
      const toolScore = provider.score(output, options);
      if (!toolScore.tokenBudget) {
        if (toolId === ToolName.PatternDetect && output.duplicates) {
          const wastedTokens = output.duplicates.reduce(
            (sum, d) => sum + (d.tokenCost || 0),
            0
          );
          toolScore.tokenBudget = calculateTokenBudget({
            totalContextTokens: wastedTokens * 2,
            wastedTokens: {
              duplication: wastedTokens,
              fragmentation: 0,
              chattiness: 0
            }
          });
        } else if (toolId === ToolName.ContextAnalyzer && output.summary) {
          toolScore.tokenBudget = calculateTokenBudget({
            totalContextTokens: output.summary.totalTokens,
            wastedTokens: {
              duplication: 0,
              fragmentation: output.summary.totalPotentialSavings || 0,
              chattiness: 0
            }
          });
        }
      }
      toolScores.set(toolId, toolScore);
    } catch (err) {
      console.error(`\u274C Error scoring tool '${toolId}':`, err);
    }
  }
  if (toolScores.size === 0) {
    return {
      overall: 0,
      rating: "Critical",
      timestamp: (/* @__PURE__ */ new Date()).toISOString(),
      toolsUsed: [],
      breakdown: [],
      calculation: {
        formula: "0 / 0 = 0",
        weights: {},
        normalized: "0 / 0 = 0"
      }
    };
  }
  return calculateOverallScore(toolScores, options, void 0);
}
function generateUnifiedSummary(result) {
  const { summary } = result;
  let output = `\u{1F680} AIReady Analysis Complete

`;
  output += `\u{1F4CA} Summary:
`;
  output += `   Tools run: ${summary.toolsRun.join(", ")}
`;
  output += `   Total issues found: ${summary.totalIssues}
`;
  output += `   Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s

`;
  for (const provider of ToolRegistry.getAll()) {
    const toolResult = result[provider.id];
    if (toolResult) {
      const issueCount = toolResult.results.reduce(
        (sum, r) => sum + (r.issues?.length || 0),
        0
      );
      output += `\u2022 ${provider.id}: ${issueCount} issues
`;
    }
  }
  return output;
}

export {
  __require,
  analyzeUnified,
  scoreUnified,
  generateUnifiedSummary
};
