// src/lib/crossSpawn.ts
import crossSpawn from "cross-spawn";
function spawn(command, args, options) {
  return crossSpawn(command, args, options);
}

// src/actions/skills/passthrough.ts
var NPX_SKILLS_PATTERN = /(?<=\[[\d;]*m|\W|^)npx(?:\s+-y)?\s+skills(?=\W|$)/g;
var rewriteSkillsRefs = (text) => text.replaceAll(NPX_SKILLS_PATTERN, "xy skills");
var runSkills = (subcommand, args, options = {}) => {
  const stdio = options.interactive ? "inherit" : ["inherit", "pipe", "pipe"];
  return new Promise((resolve) => {
    const child = spawn("npx", ["-y", "skills", subcommand, ...args], {
      env: { FORCE_COLOR: "3", ...process.env },
      stdio
    });
    if (!options.interactive) {
      child.stdout?.setEncoding("utf8");
      child.stderr?.setEncoding("utf8");
      child.stdout?.on("data", (chunk) => {
        process.stdout.write(rewriteSkillsRefs(chunk));
      });
      child.stderr?.on("data", (chunk) => {
        process.stderr.write(rewriteSkillsRefs(chunk));
      });
    }
    child.on("error", () => resolve(1));
    child.on("close", (code) => resolve(code ?? 1));
  });
};
var argvAfterSkillsSubcommand = (canonicalName, aliases = []) => {
  const argv = process.argv;
  const skillsIdx = argv.indexOf("skills");
  if (skillsIdx === -1) return [];
  const names = /* @__PURE__ */ new Set([canonicalName, ...aliases]);
  for (let i = skillsIdx + 1; i < argv.length; i++) {
    const token = argv[i];
    if (token !== void 0 && names.has(token)) {
      return argv.slice(i + 1);
    }
  }
  return [];
};
export {
  argvAfterSkillsSubcommand,
  rewriteSkillsRefs,
  runSkills
};
//# sourceMappingURL=passthrough.mjs.map
