/**
 * Machine-readable output helper for interactive prompts
 *
 * Provides utilities for outputting prompt configurations as JSON
 * instead of rendering interactive UI, enabling AI agents and scripts
 * to interact with the CLI programmatically.
 *
 * Design notes:
 * - Stateless functions for easy unit testing
 * - Designed for future extraction as standalone npm package
 * - Supports both explicit --json flag and automatic non-TTY detection
 *
 * Exit code conventions:
 * - EXIT_SUCCESS (0): Command completed successfully
 * - EXIT_ERROR (1): Command failed with an error
 * - EXIT_NEEDS_INPUT (2): Command needs additional input (prompt required)
 */
/**
 * Exit code for successful command completion
 */
export declare const EXIT_SUCCESS = 0;
/**
 * Exit code for command failure/error
 */
export declare const EXIT_ERROR = 1;
/**
 * Exit code when command needs additional input (prompt required)
 * Use this exit code when outputting a prompt in JSON mode to signal
 * to scripts/agents that the command didn't fail, but needs more input.
 */
export declare const EXIT_NEEDS_INPUT = 2;
/**
 * Choice item for list/checkbox prompts
 */
export interface PromptChoice {
    /** Display text shown to user */
    name: string;
    /** Actual value returned when selected */
    value: string;
    /** Optional: indicates if choice is disabled */
    disabled?: boolean;
    /** Optional: full CLI command to run for this choice (for AI agents) */
    command?: string;
}
/**
 * Form field configuration for multi-field prompts
 */
export interface FormField {
    /** Type of field: input, list, checkbox, confirm, editor, multiline */
    type: 'input' | 'list' | 'checkbox' | 'confirm' | 'editor' | 'multiline';
    /** Field name */
    name: string;
    /** User-facing message */
    message: string;
    /** Available choices (for list/checkbox types) */
    choices?: PromptChoice[];
    /** Default value if applicable */
    default?: string | boolean | string[];
}
/**
 * Prompt configuration for JSON output
 */
export interface PromptConfig {
    /** Type of prompt: list (single select), checkbox (multi select), confirm, input, editor, multiline (inline multi-line), or form (multi-field) */
    type: 'list' | 'checkbox' | 'confirm' | 'input' | 'editor' | 'multiline' | 'form';
    /** Field name for the prompt answer (not used for form type) */
    name?: string;
    /** User-facing prompt message (not used for form type) */
    message?: string;
    /** Available choices (for list/checkbox types) */
    choices?: PromptChoice[];
    /** Default value if applicable */
    default?: string | boolean | string[];
    /** Fields for form type prompts */
    fields?: FormField[];
    /** Optional context data for complex prompts */
    context?: Record<string, unknown>;
}
/**
 * Metadata included with all JSON outputs
 */
export interface OutputMetadata {
    /** Command that was invoked (e.g., "work spawn") */
    command: string;
    /** Flags that were passed to the command */
    flags: Record<string, unknown>;
    /** Timestamp of the output */
    timestamp?: string;
    /** Resolved PR mode after flag precedence ('create-pr' | 'no-pr') */
    resolvedPRMode?: string;
    /** Source of the resolved PR mode (e.g., 'flag --create-pr', 'workspace config', 'interactive prompt') */
    prModeSource?: string;
    /** Warning message when PR creation is disabled for code-modifying actions */
    prWarning?: string;
    /** External issue context propagated by work start confirmation flow */
    externalIssue?: {
        source: string | null;
        key: string | null;
        id: string | null;
        url: string | null;
    };
    /** Resolved mirror-to-PMO behavior for --from-issue flow */
    mirrorToPmo?: boolean | null;
    /** Source used to resolve mirror-to-PMO behavior */
    mirrorToPmoSource?: string | null;
    /** How the external issue source was resolved (flag, active-source, interactive) */
    sourceResolution?: {
        method: string;
        provider: string;
    };
}
/**
 * JSON output when a prompt would be shown
 */
export interface PromptJsonOutput {
    /** Output type discriminator */
    type: 'prompt';
    /** Prompt configuration, or null if no prompt needed */
    prompt: PromptConfig | null;
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * JSON output for successful command execution (no prompt needed)
 */
export interface SuccessJsonOutput {
    /** Output type discriminator */
    type: 'success';
    /** Always null when success output */
    prompt: null;
    /** Indicates successful execution */
    success: true;
    /** Command-specific result data */
    result: Record<string, unknown>;
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * JSON output for error conditions
 */
export interface ErrorJsonOutput {
    /** Output type discriminator */
    type: 'error';
    /** Error details */
    error: {
        /** Machine-readable error code (e.g., "NO_TICKETS_AVAILABLE") */
        code: string;
        /** Human-readable error message */
        message: string;
    };
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * JSON output for dry-run validation (what would happen)
 */
export interface DryRunJsonOutput {
    /** Indicates this is a dry-run result */
    type: 'dry-run';
    /** Whether the inputs are valid */
    valid: boolean;
    /** What would be created if valid */
    wouldCreate?: {
        type: string;
        [key: string]: unknown;
    };
    /** Validation errors if invalid */
    errors?: Array<{
        field: string;
        error: string;
    }>;
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * JSON output for confirmation needed (two-step execute protocol)
 * Used when all required flags are provided but --yes is not set.
 * Agent should review the plan and re-run with --yes to execute.
 */
export interface ConfirmationNeededJsonOutput {
    /** Output type discriminator */
    type: 'confirmation_needed';
    /** Plan of what will happen if confirmed */
    plan: Record<string, unknown>;
    /** The full command to run to confirm and execute */
    confirm_command: string;
    /** Human-readable message */
    message: string;
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * JSON output for execution result (after successful spawn/start)
 */
export interface ExecutionResultJsonOutput {
    /** Output type discriminator */
    type: 'execution_result';
    /** Execution results */
    result: {
        executions: Array<{
            workId: string;
            ticketId: string;
            agent: string;
            sessionId?: string;
            containerId?: string;
            status: string;
        }>;
        successCount: number;
        failCount: number;
    };
    /** Command metadata */
    metadata: OutputMetadata;
}
/**
 * Union type for all JSON output types
 */
export type JsonOutput = PromptJsonOutput | SuccessJsonOutput | ErrorJsonOutput | DryRunJsonOutput | ConfirmationNeededJsonOutput | ExecutionResultJsonOutput;
/**
 * All valid JSON envelope type discriminators.
 * Used for contract tests and schema validation.
 */
export declare const JSON_ENVELOPE_TYPES: readonly ["prompt", "success", "error", "dry-run", "confirmation_needed", "execution_result"];
export type JsonEnvelopeType = typeof JSON_ENVELOPE_TYPES[number];
/**
 * Required fields per envelope type for contract validation.
 * Tests use this to verify no fields are accidentally removed.
 */
export declare const JSON_ENVELOPE_REQUIRED_FIELDS: Record<JsonEnvelopeType, string[]>;
/**
 * Validate that a parsed JSON object conforms to the machine-mode envelope schema.
 *
 * Returns an array of validation errors (empty = valid).
 * Useful for contract tests and runtime validation of JSON output.
 *
 * @param obj - Parsed JSON object to validate
 * @returns Array of validation error strings (empty if valid)
 */
export declare function validateJsonEnvelope(obj: unknown): string[];
/**
 * Flags interface for JSON mode detection
 */
export interface JsonFlags {
    json?: boolean;
    machine?: boolean;
}
/**
 * Flags interface for machine-readable output mode detection
 * --json and --machine/-m both trigger JSON output mode
 */
export interface MachineOutputFlags {
    /** JSON output flag */
    json?: boolean;
    /** Machine output flag (-m shorthand) */
    machine?: boolean;
}
/**
 * Check if the current environment is non-TTY (piped input or output)
 *
 * Uses the "either" strategy: returns true if EITHER stdin OR stdout is non-TTY.
 * This covers the primary use case of scripts/agents calling prlt as a subprocess,
 * where both stdin and stdout are typically non-TTY.
 *
 * Returns true if:
 * - stdin is not a TTY (e.g., piped input)
 * - stdout is not a TTY (e.g., piped output)
 * - PRLT_JSON=1 environment variable is set (overrides TTY detection)
 *
 * Returns false if:
 * - PRLT_FORCE_TEXT=1 is set (forces text output in non-TTY environments, useful for testing)
 *
 * @returns true if either stdin or stdout is not a TTY, or PRLT_JSON=1 is set
 */
export declare function isNonTTY(): boolean;
/**
 * Determine if JSON output mode is active (for AI agents)
 *
 * Returns true if:
 * - The --json flag is set (or -m/--machine aliases)
 * - The PRLT_JSON=1 environment variable is set
 * - Either stdin or stdout is non-TTY (piped input/output)
 *
 * @param flags - Command flags object
 * @returns true if JSON mode should be used
 */
export declare function shouldOutputJson(flags: JsonFlags): boolean;
/**
 * Alias for shouldOutputJson - clearer name for agent-focused code
 */
export declare const isAgentMode: typeof shouldOutputJson;
/**
 * Determine if machine-readable output mode is active (for AI agents/scripts)
 *
 * Returns true if:
 * - The --json flag is set (or -m/--machine aliases)
 * - The PRLT_JSON=1 environment variable is set
 * - Either stdin or stdout is non-TTY (piped input/output)
 *
 * @param flags - Command flags object
 * @returns true if machine-readable output mode should be used
 */
export declare function isMachineOutput(flags: MachineOutputFlags): boolean;
/**
 * Create metadata object for JSON output
 *
 * @param command - Command name (e.g., "work spawn")
 * @param flags - Flags passed to the command
 * @returns Metadata object
 */
export declare function createMetadata(command: string, flags: Record<string, unknown>): OutputMetadata;
/**
 * Output a prompt configuration as JSON and exit
 *
 * Use this when a command would normally show an interactive prompt.
 * Outputs the prompt config so agents can understand what input is needed,
 * then exits with EXIT_NEEDS_INPUT (2) to signal the command needs more input.
 *
 * @param config - Prompt configuration
 * @param metadata - Command metadata
 */
export declare function outputPromptAsJson(config: PromptConfig, metadata: OutputMetadata): never;
/**
 * Output success result as JSON and exit
 *
 * Use this when all required data was provided via flags
 * and no prompt is needed. Exits with EXIT_SUCCESS (0) to signal
 * successful command completion.
 *
 * @param result - Command-specific result data
 * @param metadata - Command metadata
 */
export declare function outputSuccessAsJson(result: Record<string, unknown>, metadata: OutputMetadata): never;
/**
 * Output error as JSON and exit
 *
 * Use this when an error occurs and --json flag is active.
 * Provides structured error output for programmatic handling,
 * then exits with EXIT_ERROR (1).
 *
 * @param code - Machine-readable error code (e.g., "NO_TICKETS_AVAILABLE")
 * @param message - Human-readable error message
 * @param metadata - Command metadata
 */
export declare function outputErrorAsJson(code: string, message: string, metadata: OutputMetadata): never;
/**
 * Convert inquirer choices to PromptChoice format
 *
 * Handles both simple string choices and object choices,
 * filtering out Separator instances.
 *
 * @param choices - Inquirer choices array
 * @returns Array of PromptChoice objects
 */
export declare function normalizeChoices(choices: Array<string | {
    name: string;
    value: string;
    disabled?: boolean | string;
    command?: string;
} | unknown>): PromptChoice[];
/**
 * Build a prompt config object from inquirer prompt options
 *
 * @param type - Prompt type
 * @param name - Field name
 * @param message - User-facing message
 * @param choices - Optional choices array
 * @param defaultValue - Optional default value
 * @returns PromptConfig object
 */
export declare function buildPromptConfig(type: 'list' | 'checkbox' | 'confirm' | 'input' | 'editor' | 'multiline', name: string, message: string, choices?: Array<string | {
    name: string;
    value: string;
    disabled?: boolean | string;
    command?: string;
} | unknown>, defaultValue?: string | boolean | string[]): PromptConfig;
/**
 * Build a form prompt config with multiple fields
 *
 * @param fields - Array of form field configurations
 * @returns PromptConfig object with type 'form'
 */
export declare function buildFormPromptConfig(fields: FormField[]): PromptConfig;
/**
 * Output a successful dry-run result as JSON and exit
 *
 * Use this when --dry-run is set and all validation passes.
 * Shows what would be created without actually creating it.
 *
 * @param entityType - Type of entity that would be created (e.g., "ticket", "project")
 * @param wouldCreate - Data about what would be created
 * @param metadata - Command metadata
 */
export declare function outputDryRunSuccessAsJson(entityType: string, wouldCreate: Record<string, unknown>, metadata: OutputMetadata): never;
/**
 * Output a dry-run validation failure as JSON and exit
 *
 * Use this when --dry-run is set and validation fails.
 * Shows the validation errors without attempting to create.
 *
 * @param errors - Array of validation errors
 * @param metadata - Command metadata
 */
export declare function outputDryRunErrorsAsJson(errors: Array<{
    field: string;
    error: string;
}>, metadata: OutputMetadata): never;
/**
 * Output a confirmation needed response as JSON and exit
 *
 * Use this in non-TTY mode when all required flags are provided but --yes is not set.
 * This allows agents to preview what will happen before confirming execution.
 *
 * @param plan - Details of what will happen if confirmed
 * @param confirmCommand - The full command to run with --yes to execute
 * @param message - Human-readable message explaining the confirmation
 * @param metadata - Command metadata
 */
export declare function outputConfirmationNeededAsJson(plan: Record<string, unknown>, confirmCommand: string, message: string, metadata: OutputMetadata): never;
/**
 * Output execution result as JSON (non-exiting version)
 *
 * Use this after execution completes in non-TTY mode to provide structured
 * results. Unlike other output functions, this does NOT exit - caller should
 * handle cleanup and exit.
 *
 * @param executions - Array of execution results
 * @param successCount - Number of successful executions
 * @param failCount - Number of failed executions
 * @param metadata - Command metadata
 */
export declare function outputExecutionResultAsJson(executions: Array<{
    workId: string;
    ticketId: string;
    agent: string;
    sessionId?: string;
    containerId?: string;
    status: string;
}>, successCount: number, failCount: number, metadata: OutputMetadata): void;
