"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 surprising_exports = {};
__export(surprising_exports, {
  register: () => register
});
module.exports = __toCommonJS(surprising_exports);
var path = __toESM(require("path"));
var import_ui = require("../ui");
function register(program) {
  program.command("surprising [projectPath]").description("Find non-obvious cross-file connections between distant symbols").option("--limit <n>", "Max results (default: 20)", "20").option("--format <fmt>", "Output format: table | json", "table").action(async (projectPath, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(projectPath ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const limit = Math.max(1, Math.min(100, parseInt(opts.limit) || 20));
    const connections = cg.findSurprisingConnections(limit);
    cg.close();
    if (connections.length === 0) {
      console.log(`
  ${import_ui.dim}No surprising cross-file connections found.${import_ui.reset}
`);
      return;
    }
    if (opts.format === "json") {
      console.log(JSON.stringify(connections.map((c) => ({
        source: { name: c.source.name, kind: c.source.kind, file: c.source.filePath },
        target: { name: c.target.name, kind: c.target.kind, file: c.target.filePath },
        kind: c.kind,
        score: c.score
      })), null, 2));
      return;
    }
    console.log();
    console.log(`  ${import_ui.violet}${import_ui.bold}Surprising Connections${import_ui.reset}  ${import_ui.dim}non-obvious cross-file links${import_ui.reset}
`);
    for (let i = 0; i < connections.length; i++) {
      const c = connections[i];
      const rank = String(i + 1).padStart(2);
      const score = c.score.toFixed(2);
      console.log(`  ${import_ui.dim}${rank}.${import_ui.reset} ${import_ui.violet}${import_ui.bold}${c.source.name}${import_ui.reset}  ${import_ui.dim}${c.source.kind}${import_ui.reset}  ${import_ui.dim}\u2500[${c.kind}]\u2192${import_ui.reset}  ${import_ui.violet}${import_ui.bold}${c.target.name}${import_ui.reset}  ${import_ui.dim}${c.target.kind}${import_ui.reset}  ${import_ui.dim}score: ${score}${import_ui.reset}`);
      console.log(`      ${import_ui.dim}${c.source.filePath}${import_ui.reset}`);
      console.log(`      ${import_ui.dim}${c.target.filePath}${import_ui.reset}`);
    }
    console.log(`
  ${import_ui.dim}${connections.length} result(s) \u2014 score = path distance \xD7 edge weight${import_ui.reset}
`);
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=surprising.js.map
