import { Buffer } from 'node:buffer';

declare const AGENTS: {
    npm: {
        agent: string;
        run: (args: string[]) => string;
        install: string;
        frozen: string;
        global: string;
        add: string;
        upgrade: string;
        'upgrade-interactive': null;
        execute: string;
        uninstall: string;
        global_uninstall: string;
    };
    yarn: {
        agent: string;
        run: string;
        install: string;
        frozen: string;
        global: string;
        add: string;
        upgrade: string;
        'upgrade-interactive': string;
        execute: string;
        uninstall: string;
        global_uninstall: string;
    };
    'yarn@berry': {
        frozen: string;
        upgrade: string;
        'upgrade-interactive': string;
        execute: string;
        global: string;
        global_uninstall: string;
        agent: string;
        run: string;
        install: string;
        add: string;
        uninstall: string;
    };
    pnpm: {
        agent: string;
        run: string;
        install: string;
        frozen: string;
        global: string;
        add: string;
        upgrade: string;
        'upgrade-interactive': string;
        execute: string;
        uninstall: string;
        global_uninstall: string;
    };
    'pnpm@6': {
        run: (args: string[]) => string;
        agent: string;
        install: string;
        frozen: string;
        global: string;
        add: string;
        upgrade: string;
        'upgrade-interactive': string;
        execute: string;
        uninstall: string;
        global_uninstall: string;
    };
    bun: {
        agent: string;
        run: string;
        install: string;
        frozen: string;
        global: string;
        add: string;
        upgrade: string;
        'upgrade-interactive': string;
        execute: string;
        uninstall: string;
        global_uninstall: string;
    };
};
type Agent = keyof typeof AGENTS;
type Command = keyof typeof AGENTS.npm;
declare const agents: ("npm" | "pnpm" | "yarn" | "yarn@berry" | "pnpm@6" | "bun")[];
declare const LOCKS: Record<string, Agent>;
declare const INSTALL_PAGE: Record<Agent, string>;

interface Config {
    defaultAgent: Agent | 'prompt';
    globalAgent: Agent;
}
declare function getConfig(): Promise<Config>;
declare function getDefaultAgent(programmatic?: boolean): Promise<"npm" | "pnpm" | "yarn" | "yarn@berry" | "pnpm@6" | "bun" | "prompt">;
declare function getGlobalAgent(): Promise<"npm" | "pnpm" | "yarn" | "yarn@berry" | "pnpm@6" | "bun">;

interface DetectOptions {
    autoInstall?: boolean;
    programmatic?: boolean;
    cwd?: string;
}
declare function detect({ autoInstall, programmatic, cwd }?: DetectOptions): Promise<"npm" | "pnpm" | "yarn" | "yarn@berry" | "pnpm@6" | "bun" | null>;

interface RunnerContext {
    programmatic?: boolean;
    hasLock?: boolean;
    cwd?: string;
}
type Runner = (agent: Agent, args: string[], ctx?: RunnerContext) => Promise<string | undefined> | string | undefined;
declare function runCli(fn: Runner, options?: DetectOptions & {
    args?: string[];
}): Promise<void>;
declare function getCliCommand(fn: Runner, args: string[], options?: DetectOptions, cwd?: string): Promise<string | undefined>;
declare function run(fn: Runner, args: string[], options?: DetectOptions): Promise<void>;

declare class UnsupportedCommand extends Error {
    constructor({ agent, command }: {
        agent: Agent;
        command: Command;
    });
}
declare function getCommand(agent: Agent, command: Command, args?: string[]): string;
declare const parseNi: Runner;
declare const parseNr: Runner;
declare const parseNu: Runner;
declare const parseNun: Runner;
declare const parseNlx: Runner;
declare const parseNa: Runner;

declare const CLI_TEMP_DIR: string;
declare function remove<T>(arr: T[], v: T): T[];
declare function exclude<T>(arr: T[], v: T): T[];
declare function cmdExists(cmd: string): boolean;
declare function getVoltaPrefix(): string;
/**
 * Write file safely avoiding conflicts
 */
declare function writeFileSafe(path: string, data?: string | Buffer): Promise<boolean>;

export { AGENTS, type Agent, CLI_TEMP_DIR, type Command, type DetectOptions, INSTALL_PAGE, LOCKS, type Runner, type RunnerContext, UnsupportedCommand, agents, cmdExists, detect, exclude, getCliCommand, getCommand, getConfig, getDefaultAgent, getGlobalAgent, getVoltaPrefix, parseNa, parseNi, parseNlx, parseNr, parseNu, parseNun, remove, run, runCli, writeFileSafe };
