// @bun
import {
  checkAgent0CapabilitiesStatus,
  installAgent0Capabilities,
  installExternalHarnessCapabilities,
  readAgent0CapabilitiesManifest
} from "./chunk-h857yazx.js";
import"./chunk-7zvmmxnc.js";
import"./chunk-p4n31dgt.js";
import {
  findAgentRootOrFail
} from "./chunk-6fad0ts7.js";
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import"./chunk-px7fts59.js";
import"./chunk-7krp2mgz.js";
import"./chunk-np5wcwfv.js";
import"./chunk-je8v6rhj.js";
import"./chunk-6w0knnta.js";
import"./chunk-w15xmtkn.js";
import"./chunk-3sd5p4qp.js";
import"./chunk-nh2akp42.js";
import"./chunk-kat1bv74.js";
import"./chunk-2a5b6azq.js";
import"./chunk-s8cp3qe6.js";
import"./chunk-fv5teh9w.js";
import"./chunk-8ab2w9a1.js";
import"./chunk-3xrpxgq4.js";
import"./chunk-w346ejn9.js";
import"./chunk-n8gath4k.js";
import"./chunk-v3ens42y.js";
import"./chunk-8839jtgk.js";
import"./chunk-s2akeqpw.js";
import"./chunk-6771vrjp.js";
import"./chunk-g8mm42v1.js";
import"./chunk-0q5d80bn.js";
import"./chunk-300xaact.js";
import"./chunk-b8c41yvb.js";
import"./chunk-jsqe5am4.js";
import"./chunk-m4c14gcg.js";
import"./chunk-gspjbr79.js";
import"./chunk-wesykvkp.js";
import"./chunk-gzj56z73.js";
import"./chunk-dhs2bg35.js";

// src/commands/adk-ai-upgrade.ts
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
async function adkAgent0Upgrade(options = {}) {
  const isJson = options.format === "json";
  const logger = createCliLogger({ format: options.format });
  const projectPath = await findAgentRootOrFail(process.cwd());
  const status = checkAgent0CapabilitiesStatus(projectPath);
  const baseResult = {
    success: true,
    projectPath,
    command: "adk agent0 upgrade",
    currentVersion: status.currentVersion,
    previousVersion: status.state === "missing" ? undefined : status.installedVersion,
    updated: false
  };
  if (status.state === "current") {
    const manifest = readAgent0CapabilitiesManifest(projectPath);
    const result = {
      ...baseResult,
      capabilities: manifest ? {
        root: manifest.capabilitiesRoot,
        manifestPath: status.manifestPath,
        skills: manifest.skills.length,
        playbooks: manifest.playbooks.length
      } : undefined
    };
    if (isJson) {
      logger.info("").result(result);
    } else {
      logger.info(`Agent(0) capabilities are already current (${status.currentVersion}).`, "green");
    }
    return;
  }
  if (!isJson) {
    logger.info("Updating Agent(0) project capabilities...");
    logger.newline();
  }
  let frameIdx = 0;
  const message = "Writing .agent0/capabilities...";
  const spinner = isJson ? null : setInterval(() => {
    logger.stdout(`\r  ${SPINNER_FRAMES[frameIdx++ % SPINNER_FRAMES.length]} ${message}`);
  }, 80);
  const clearSpinner = () => {
    if (!spinner)
      return;
    clearInterval(spinner);
    logger.stdout("\r" + " ".repeat(message.length + 6) + "\r");
  };
  try {
    const installed = await installAgent0Capabilities(projectPath);
    clearSpinner();
    const result = {
      ...baseResult,
      updated: true,
      capabilities: {
        root: installed.capabilitiesRoot,
        manifestPath: installed.manifestPath,
        source: installed.source,
        skills: installed.skills.installed,
        playbooks: installed.playbooks.installed
      }
    };
    if (isJson) {
      logger.info("").result(result);
    } else {
      logger.info(`Agent(0) capabilities updated (${installed.skills.installed} skills, ${installed.playbooks.installed} commands).`, "green");
    }
  } catch (error) {
    clearSpinner();
    const errorMessage = error instanceof Error ? error.message : String(error);
    const result = {
      ...baseResult,
      success: false,
      error: errorMessage
    };
    if (isJson) {
      logger.info("").result(result);
      return;
    }
    logger.error(`Failed to update Agent(0) capabilities: ${errorMessage}`);
  }
}
async function adkUpdate(options = {}) {
  const isJson = options.format === "json";
  const logger = createCliLogger({ format: options.format });
  const projectPath = await findAgentRootOrFail(process.cwd());
  if (!isJson) {
    logger.info("Updating ADK skills & commands...");
    logger.newline();
  }
  let frameIdx = 0;
  const message = "Updating external coding-agent capabilities...";
  const spinner = isJson ? null : setInterval(() => {
    logger.stdout(`\r  ${SPINNER_FRAMES[frameIdx++ % SPINNER_FRAMES.length]} ${message}`);
  }, 80);
  const clearSpinner = () => {
    if (!spinner)
      return;
    clearInterval(spinner);
    logger.stdout("\r" + " ".repeat(message.length + 6) + "\r");
  };
  try {
    const externalHarness = await installExternalHarnessCapabilities({ projectPath });
    clearSpinner();
    const result = {
      success: externalHarness.success,
      projectPath,
      skills: externalHarness.skills,
      commands: externalHarness.commands
    };
    if (isJson) {
      logger.info("").result(result);
      return;
    }
    if (externalHarness.skills.success) {
      logger.info("  ADK skills updated", "green");
    } else {
      logger.warn("  Failed to update ADK skills. Run manually:");
      logger.info(`    > ${externalHarness.skills.command}`, "cyan");
    }
    if (externalHarness.commands.success) {
      logger.info(`  ADK commands updated (${externalHarness.commands.installedCommands} commands)`, "green");
    } else {
      logger.warn("  Failed to update ADK commands.");
    }
    logger.newline();
    if (externalHarness.success) {
      logger.info("All up to date!", "green");
    } else {
      logger.warn("Some updates failed. See warnings above.");
    }
  } catch (error) {
    clearSpinner();
    const message2 = error instanceof Error ? error.message : String(error);
    const result = {
      success: false,
      projectPath,
      error: message2
    };
    if (isJson) {
      logger.info("").result(result);
      return;
    }
    logger.error(`Failed to update ADK skills & commands: ${message2}`);
  }
}
export {
  adkUpdate,
  adkAgent0Upgrade
};
