"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var context_exports = {};
__export(context_exports, {
  register: () => register
});
module.exports = __toCommonJS(context_exports);
var import_ui = require("../ui");
function register(program) {
  program.command("context <task>").description("Build relevant code context for a task").option("--max-nodes <n>", "Max symbols to include", "20").option("--no-code", "Exclude code snippets").option("--format <fmt>", "Output format: markdown, json", "markdown").action(async (task, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const { trackCliToolSaving } = await Promise.resolve().then(() => require("./utils.js"));
    const cwd = process.cwd();
    const cg = await KiroGraph.open(cwd);
    const ctx = await cg.buildContext(task, {
      maxNodes: parseInt(opts.maxNodes),
      includeCode: opts.code
    });
    let output;
    if (opts.format === "json") {
      output = JSON.stringify({
        task: ctx.task,
        summary: ctx.summary,
        entryPoints: ctx.entryPoints.map((n) => ({ kind: n.kind, name: n.name, file: n.filePath, line: n.startLine })),
        relatedNodes: ctx.relatedNodes.map((n) => ({ kind: n.kind, name: n.name, file: n.filePath, line: n.startLine })),
        codeSnippets: Object.fromEntries(ctx.codeSnippets)
      }, null, 2);
      console.log(output);
    } else {
      const lines = [];
      lines.push(`
  ${(0, import_ui.section)("Context:")} ${import_ui.violet}${import_ui.bold}${ctx.task}${import_ui.reset}
`);
      lines.push(`  ${import_ui.dim}${ctx.summary}${import_ui.reset}`);
      if (ctx.entryPoints.length > 0) {
        lines.push(`
  ${(0, import_ui.section)("Entry Points")}
`);
        for (const n of ctx.entryPoints) {
          lines.push(`  ${import_ui.violet}${import_ui.bold}${n.name}${import_ui.reset}  ${import_ui.dim}${n.kind}  ${n.filePath}:${n.startLine}${import_ui.reset}`);
          if (ctx.codeSnippets.has(n.id)) {
            lines.push(`
  ${import_ui.dim}\`\`\`${import_ui.reset}`);
            for (const line of (ctx.codeSnippets.get(n.id) ?? "").split("\n")) {
              lines.push(`  ${line}`);
            }
            lines.push(`  ${import_ui.dim}\`\`\`${import_ui.reset}
`);
          }
        }
      }
      if (ctx.relatedNodes.length > 0) {
        lines.push(`
  ${(0, import_ui.section)("Related Symbols")}
`);
        for (const n of ctx.relatedNodes) {
          lines.push(`  ${import_ui.dim}\xB7${import_ui.reset} ${import_ui.violet}${n.name}${import_ui.reset}  ${import_ui.dim}${n.kind}  ${n.filePath}:${n.startLine}${import_ui.reset}`);
        }
        lines.push("");
      }
      output = lines.join("\n");
      console.log(output);
    }
    trackCliToolSaving(cwd, "kirograph_context", output, { maxNodes: parseInt(opts.maxNodes) });
    cg.close();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=context.js.map
