Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

1.4 KB
Raw Blame
import { Command } from 'commander';
import { getCliLogger } from '../cli-logger.ts';
import { collectReportBundle } from '../report-bundle.ts';
import { defaultBugReportZipPath } from './bug-report-bundle.ts';
import { revealBundle } from './bug-report-reveal.ts';

export function bugReportCommand(): Command {
  return new Command('bug-report')
    .description('Generate a diagnostic bundle for bug reporting')
    .option('--reveal', 'Reveal the bundle in your file manager (default: true)', true)
    .option('--no-reveal', 'Do not reveal the bundle in your file manager')
    .action(async (opts: { reveal: boolean }) => {
      try {
        const { zipPath, summary } = await collectReportBundle({
          level: 'standard',
          projectDir: process.cwd(),
          redact: true,
          outputPath: defaultBugReportZipPath(),
          logger: getCliLogger(),
        });

        process.stdout.write(`${zipPath}\n`);

        if (summary.redactedLineCount > 0) {
          process.stderr.write(
            `ok bug-report: ${summary.redactedLineCount} line(s) auto-redacted across ${summary.redactions.length} file(s)\n`,
          );
        }

        if (opts.reveal) revealBundle(zipPath);
      } catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        process.stderr.write(`ok bug-report: failed — ${msg}\n`);
        process.exitCode = 1;
      }
    });
}