import { defineCommand, findRepoRoot } from '@kb-labs/sdk';
import { loadPlan, getCurrentPlanPath, formatCommitMessage } from '@kb-labs/commit-core';

// src/cli/commands/open.ts
var open_default = defineCommand({
  id: "commit:open",
  description: "Show current commit plan",
  handler: {
    async execute(ctx, input) {
      const startTime = Date.now();
      const cwd = await findRepoRoot(ctx.cwd || process.cwd()) ?? process.cwd();
      const scope = input.scope ?? "root";
      const plan = await loadPlan(cwd, scope);
      const planPath = getCurrentPlanPath(cwd, scope);
      const output = {
        hasPlan: plan !== null,
        plan: plan ?? void 0,
        planPath: plan ? planPath : void 0
      };
      if (input.json) {
        ctx.ui?.json?.(output);
      } else {
        if (!plan) {
          ctx.ui?.info?.("No commit plan found. Run `kb commit:generate` to create one.");
        } else {
          const commitsItems = plan.commits.map((commit, i) => {
            const message = formatCommitMessage(commit);
            const breaking = commit.breaking ? " \u26A0\uFE0F  BREAKING" : "";
            return `${i + 1}. ${message} [${commit.files.length} file(s)]${breaking}`;
          });
          const status = plan.gitStatus;
          const statusItems = [
            `Staged: ${status.staged.length} file(s)`,
            `Unstaged: ${status.unstaged.length} file(s)`,
            `Untracked: ${status.untracked.length} file(s)`
          ];
          const sections = [];
          sections.push({
            header: "Commits",
            items: commitsItems
          });
          sections.push({
            header: "Git Status (at generation)",
            items: statusItems
          });
          const summaryItems = [
            `Plan path: ${planPath}`,
            `Created: ${plan.createdAt}`,
            `Total files: ${plan.metadata.totalFiles}`,
            `Total commits: ${plan.metadata.totalCommits}`
          ];
          if (plan.metadata.llmUsed) {
            const generator = plan.metadata.escalated ? "LLM (Phase 2)" : "LLM (Phase 1)";
            summaryItems.push(`Generator: ${generator}`);
          } else {
            summaryItems.push("Generator: Heuristics");
          }
          sections.unshift({
            header: "Summary",
            items: summaryItems
          });
          ctx.ui?.success?.("Current Commit Plan", {
            sections
          });
        }
      }
      return {
        exitCode: 0,
        result: output,
        meta: {
          timing: Date.now() - startTime
        }
      };
    }
  }
});

export { open_default as default };
//# sourceMappingURL=open.js.map
//# sourceMappingURL=open.js.map