import { type CommandReadOptions, type CommandReading } from './utils/command-reading.js';
/**
 * The check's answer for one command.
 * - allowed: no blocked program runs.
 * - blocked: `name` is the blockedCommands entry that one of the programs matched.
 * - unseen: allowed, but some program is chosen only when the command runs
 *   (eval "$CMD", Invoke-Expression $cmd, & $tool) or is in a script file
 *   (bash deploy.sh). Each entry of `unseen` says what hides one of them.
 * - failed: the check couldn't read the command or the settings, and
 *   `reason` holds the error's message.
 */
export type CommandCheck = {
    verdict: 'allowed';
} | {
    verdict: 'blocked';
    name: string;
} | {
    verdict: 'unseen';
    unseen: UnseenProgram[];
} | {
    verdict: 'failed';
    reason: string;
};
/** Something in a command that hides the program it runs from the check */
export interface UnseenProgram {
    /** What hides it, as the shell reads it (in PowerShell, an alias's target): "eval", "Invoke-Expression", "$tool" or "deploy.sh" */
    what: string;
    /** True for a script/startup file given to a shell; false for a program chosen at runtime. */
    inFile: boolean;
}
declare class CommandManager {
    getBaseCommand(command: string): string;
    /**
     * The command name of each command in a command line (chained, piped, in $(), ...).
     * asTyped: each first word as typed instead of its base name, for telemetry,
     * which then replaces a path whole (a base name alone can't be told from one).
     */
    extractCommands(commandString: string, asTyped?: boolean): string[];
    extractBaseCommand(commandStr: string, asTyped?: boolean): string | null;
    /**
     * Reads a command with the grammar of the shell that will run it: POSIX
     * shells (bash, zsh, sh, …), PowerShell, or cmd. fish is read with the
     * bash reader, and where that can't parse fish's own syntax (for … end,
     * echo (date)), as main reads it: by the names extractCommands() finds.
     */
    readCommands(command: string, shell: string, options?: CommandReadOptions): Promise<CommandReading>;
    /**
     * The commands of a reading that run a program: the calls to the script's
     * own functions are left out. A script can define a function with a
     * program's name, such as an error helper named halt, and the shell then
     * runs the function, not the program. A call is the function's when it
     * comes after the definition, its name as written has no folder
     * (/sbin/halt is the program), and the reader lists the function, so not
     * one the text may remove. PowerShell finds a function whatever the case
     * of its name, POSIX shells only by its exact name. The function's body is
     * read as commands of its own, so a blocked program inside it is still
     * found.
     */
    private withoutOwnFunctionCalls;
    /**
     * What hides a program from the check among the commands that run
     * (CommandCheck's `unseen`), in the order the commands start:
     * - a program chosen only when the command runs: a name that is a variable
     *   or another command's output (& $tool), or eval and Invoke-Expression,
     *   which run text the command builds (eval "$CMD");
     * - a script file given to a shell (bash deploy.sh, or forwarded by runuser): the commands in it
     *   aren't in the text. A file named only when the command runs ("$SCRIPT")
     *   counts as a program chosen at run time, named by the shell.
     */
    private findUnseen;
    /**
     * What hides the program when a command gives a shell a script or startup file to run
     * (bash deploy.sh, pwsh -File deploy.ps1, source deploy.sh), or when
     * PowerShell runs one named as the command (./deploy.ps1): the file, or the
     * shell when the file is named only when the command runs ("$SCRIPT").
     * A shell's command text or standard input adds no file. An explicit Bash
     * startup file can still run beside command text in interactive mode.
     */
    private scriptFiles;
    /**
     * The check's answer for `command` run by `shell`:
     * - allowed: no program it runs is blocked.
     * - blocked: a program it runs is in blockedCommands, both compared in the
     *   form programName() gives; the answer names the entry as written (a call
     *   to the script's own function is not the program: see withoutOwnFunctionCalls).
     * - unseen: allowed, but a program is chosen only when the command runs or
     *   is in a script file (see findUnseen), so start_process can say the
     *   blocklist couldn't check it.
     * - failed: the command or the settings can't be read. In PowerShell a parse
     *   error or a missing PowerShell is allowed instead: nothing runs, and
     *   PowerShell or start_process answers.
     */
    checkCommand(command: string, shell: string, options?: CommandReadOptions): Promise<CommandCheck>;
    /**
     * checkCommand() for a command, or for a command text in it: each text is
     * checked once per command in each shell, however many readings give it.
     * In pwsh $a pwsh $a … each text gives every later one again, so without
     * this the work doubled with each pair.
     */
    private checkText;
    private checkOnce;
    /** Whether a check's answer refuses the command */
    isRefused(check: CommandCheck): check is Extract<CommandCheck, {
        verdict: 'blocked' | 'failed';
    }>;
    /** Whether the command may run in `shell`: the check doesn't refuse it */
    validateCommand(command: string, shell: string): Promise<boolean>;
}
export declare const commandManager: CommandManager;
export {};
