/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ /** * Tree-sitter based shell command parser. * * Provides accurate shell syntax parsing for: * - Command substitution detection ($(), ``, <()) * - Pipeline and command list splitting (&&, ||, ;, |) * - Command name extraction from complex commands * * Falls back gracefully to regex parsing if tree-sitter fails to initialize. */ import type { Tree } from 'web-tree-sitter'; /** * Get the initialization error, if any. * Useful for debugging why tree-sitter failed to load. */ export declare function getInitializationError(): Error | null; /** * Initialize the tree-sitter parser with bash language support. * Returns true if initialization succeeded, false otherwise. * Safe to call multiple times - will return cached result. */ export declare function initializeParser(): Promise; /** * Check if the tree-sitter parser is available. */ export declare function isParserAvailable(): boolean; /** * Parse a shell command string and return the syntax tree. * Returns null if parser is not available. */ export declare function parseShellCommand(command: string): Tree | null; /** * Extract all command names from a parsed shell command tree. * This handles pipelines, command lists (&&, ||, ;), and subshells. */ export declare function extractCommandNames(tree: Tree): string[]; /** * Parsed command detail containing the command name and full text. */ export interface ParsedCommandDetail { name: string; text: string; } /** * Result of parsing command details. */ export interface CommandParseResult { details: ParsedCommandDetail[]; hasError: boolean; } /** * Collect all command details from a tree by walking the entire AST. * This includes commands inside command substitutions ($(), ``), process substitutions (<(), >()), * function bodies, subshells, and any other nested contexts. * * This is essential for security - we need to validate ALL commands that will execute, * not just top-level commands. */ export declare function collectCommandDetails(tree: Tree, source: string): ParsedCommandDetail[]; /** * Parse a shell command and extract all command details including nested commands. * Returns null if parsing fails or tree-sitter is not available. */ export declare function parseCommandDetails(command: string): CommandParseResult | null; /** * Check if a command contains command substitution patterns. * Uses tree-sitter AST to accurately detect: * - $() command substitution * - `` backtick substitution * - <() process substitution */ export declare function hasCommandSubstitution(tree: Tree): boolean; /** * Options for splitCommandsWithTree function. */ export interface SplitCommandsTreeOptions { /** * Whether to split on pipe operators (|). * Default: true (split pipes for security checks). * Set to false for command instrumentation where pipelines should stay intact. */ splitOnPipes?: boolean; } /** * Split a command string into individual commands respecting shell syntax. * Handles &&, ||, ;. Pipe splitting is controlled by options. * @param tree The parsed tree-sitter tree * @param options Optional settings for split behavior */ export declare function splitCommandsWithTree(tree: Tree, options?: SplitCommandsTreeOptions): string[]; /** * Reset the parser state (primarily for testing). */ export declare function resetParser(): void;