"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var affected_exports = {};
__export(affected_exports, {
  register: () => register
});
module.exports = __toCommonJS(affected_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var import_ui = require("../ui");
function register(program) {
  program.command("affected [files...]").description("Find test files affected by changed source files").option("--stdin", "Read file list from stdin (one per line)").option("-d, --depth <n>", "Max dependency traversal depth", "5").option("-f, --filter <glob>", "Custom glob to identify test files").option("-j, --json", "Output as JSON").option("-q, --quiet", "Output file paths only").option("-p, --path <path>", "Project path").action(async (files, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(opts.path ?? process.cwd());
    const cg = await KiroGraph.open(target);
    let changedFiles = [...files];
    if (opts.stdin) {
      const lines = fs.readFileSync("/dev/stdin", "utf8").split("\n").map((l) => l.trim()).filter(Boolean);
      changedFiles.push(...lines);
    }
    if (changedFiles.length === 0) {
      console.error("No files provided. Pass files as arguments or use --stdin.");
      cg.close();
      process.exit(1);
    }
    const affected = cg.getAffectedTests(changedFiles, {
      depth: parseInt(opts.depth),
      testPattern: opts.filter
    });
    if (opts.json) {
      console.log(JSON.stringify({ changedFiles, affectedTests: affected }, null, 2));
    } else if (opts.quiet) {
      for (const f of affected) console.log(f);
    } else {
      if (affected.length === 0) {
        console.log(`  ${import_ui.dim}No affected test files found.${import_ui.reset}`);
      } else {
        console.log(`
  ${(0, import_ui.section)("Affected test files")}  ${import_ui.dim}(${affected.length})${import_ui.reset}
`);
        for (const f of affected) console.log(`  ${import_ui.violet}${import_ui.bold}${f}${import_ui.reset}`);
        console.log();
      }
    }
    cg.close();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=affected.js.map
