import { defineHandler } from '@kb-labs/sdk';
import { buildDependencyGraph, getBuildOrderForPackage, topologicalSort } from '@kb-labs/quality-core/graph';

// src/rest/handlers/build-order-handler.ts
var build_order_handler_default = defineHandler({
  async execute(ctx, input) {
    const packageName = input.query?.packageName;
    const graph = buildDependencyGraph(ctx.cwd);
    let result;
    if (packageName) {
      result = getBuildOrderForPackage(graph, packageName);
    } else {
      result = topologicalSort(graph);
    }
    return {
      layers: result.layers,
      sorted: result.sorted,
      circular: result.circular,
      packageCount: result.sorted.length,
      layerCount: result.layers.length,
      hasCircular: result.circular.length > 0
    };
  }
});

export { build_order_handler_default as default };
//# sourceMappingURL=build-order-handler.js.map
//# sourceMappingURL=build-order-handler.js.map