import { CommandResult } from './command-results'; /** * A callback function that executes a command and returns a Promise of CommandResult. * Similar to a lambda in Ruby, this is a first-class function that can be passed * as an argument and stored as a variable. */ export type CommandHandler = (args: string[]) => Promise; /** * A no-op handler that returns an empty string. Used as the default handler * for CommandNodes that don't specify a handler. */ export declare const NoopHandler: CommandHandler; /** Base interface for command segments */ export declare abstract class BaseSegment { readonly type: 'word' | 'argument' | 'null'; readonly name: string; readonly description?: string | undefined; constructor(type: 'word' | 'argument' | 'null', name: string, description?: string | undefined); toString(): string; } /** Represents a null segment for empty stack operations */ export declare class NullSegment extends BaseSegment { constructor(); } /** Represents a segment in a command path - either a word or argument */ export type CommandSegment = WordSegment | ArgumentSegment | NullSegment; /** Represents a literal word in a command path */ export declare class WordSegment extends BaseSegment { constructor(name: string, description?: string); } /** Represents an argument that can be passed to a command, and its value*/ export declare class ArgumentSegment extends BaseSegment { value?: string | undefined; readonly valid?: (() => boolean) | undefined; constructor(name: string, description?: string, value?: string | undefined, valid?: (() => boolean) | undefined); } export declare const cloneCommandSegment: (segment: CommandSegment) => CommandSegment; export declare const cloneCommandSegments: (segments: CommandSegment[]) => CommandSegment[]; /** Defines a complete command with its path and behavior */ export declare class CommandNode { private readonly _segments; private readonly _description?; private readonly _handler; constructor(segments: CommandSegment[], description?: string, handler?: CommandHandler); get segments(): CommandSegment[]; get description(): string | undefined; get handler(): CommandHandler; get hasArguments(): boolean; get fullPath(): string[]; get fullPath_s(): string; equals(other: CommandNode): boolean; } /** * Used to store user-defined commands. */ export declare class CommandRegistry { private _commands; get commands(): CommandNode[]; /** * Registers a new command composed of ordered segments. * * Each segment describes either a literal word or an argument placeholder. The resulting * path must be unique across the registry once argument placeholders are normalized. * * @param segments Ordered command path definition. * @param description Human-readable summary surfaced by help and search results. * @param handler Async handler executed when the command is submitted; defaults to `NoopHandler`. * @throws {Error} If the segment list is empty or the path collides with an existing command. */ addCommand(segments: CommandSegment[], description: string, handler?: CommandHandler): void; /** * Removes a command that exactly matches the provided path. * * @param path The command path to remove. * @returns True if a command was removed; otherwise false. */ removeCommand(path: string[]): boolean; /** * Retrieves a command from the registry for the given path. * * @param path The path of the command. * @returns The command node or undefined if not found. */ getCommand(path: string[]): CommandNode | undefined; commandExistsForPath(path: string[]): boolean; /** * Gets possible matches for a given path. * * @param path The path to get completions for. * @returns An array of completion strings. */ getCompletionNames(path: string[]): string[]; /** * Returns completion segments whose names start with the given prefix. * Matching is case-insensitive. */ getMatchingCompletions(path: string[], prefix: string): CommandSegment[]; /** * Returns a single completion when prefix matching is unambiguous. * Returns undefined for ambiguous or no-match prefixes. */ getUniqueCompletion(path: string[], prefix: string): CommandSegment | undefined; /** * Gets an array of segments reachable from a given path * * @param path The path to get completions for. * @returns An array of completion strings. */ getCompletions(path: string[]): CommandSegment[]; hasNextSegment(path: string[]): boolean; }