import { defineCommand } from '@kb-labs/sdk';
import { loadHistory, buildHistoryTable } from '@kb-labs/qa-core';

// src/cli/commands/qa-history.ts
var qa_history_default = defineCommand({
  id: "qa:history",
  description: "Show QA run history",
  handler: {
    async execute(ctx, input) {
      const { ui } = ctx;
      const flags = input.flags ?? input;
      const rootDir = ctx.cwd;
      const history = loadHistory(rootDir);
      if (history.length === 0) {
        if (flags.json) {
          ui?.json?.([]);
          return { exitCode: 0 };
        }
        ui?.success?.("No QA history found. Run qa:save first.", {});
        return { exitCode: 0 };
      }
      const limit = typeof flags.limit === "number" ? flags.limit : 20;
      if (flags.json) {
        ui?.json?.(history.slice(-limit));
        return { exitCode: 0 };
      }
      const sections = buildHistoryTable(history, limit);
      for (const section of sections) {
        ui?.success?.(section.header, {
          title: section.header,
          sections: [{ header: "", items: section.lines }]
        });
      }
      return { exitCode: 0 };
    }
  }
});

export { qa_history_default as default };
//# sourceMappingURL=qa-history.js.map
//# sourceMappingURL=qa-history.js.map