/** * Leaper Agent – File Operations Tool * * Pure Node.js file operations. * Translates the core logic of Python tools/file_operations.py and * tools/file_tools.py. */ export interface ReadOptions { /** Line offset to start reading from (0-based). */ offset?: number; /** Maximum number of lines to return. */ limit?: number; /** Prefix each line with its line number. Default: true. */ showLineNumbers?: boolean; } export interface ReadResult { content: string; totalLines: number; fileSize: number; truncated: boolean; isBinary: boolean; error?: string; } export interface WriteResult { bytesWritten: number; dirsCreated: boolean; error?: string; } export interface PatchResult { success: boolean; /** Textual diff: original oldStr vs newStr. */ diff: string; error?: string; } export interface SearchMatch { path: string; lineNumber: number; content: string; } export interface SearchResult { matches: SearchMatch[]; files: string[]; truncated: boolean; error?: string; } export interface ListEntry { name: string; type: 'file' | 'dir' | 'symlink'; size: number; modifiedAt: string; } export interface ListResult { entries: ListEntry[]; error?: string; } /** * Read a file with optional line pagination and line-number prefixes. * * Binary files are detected by scanning the first 8 KB for null bytes or a * high ratio of non-printable characters. When a binary file is detected the * returned `content` is an empty string and `isBinary` is `true`. */ export declare function readFile(filePath: string, opts?: ReadOptions): Promise; /** * Write `content` to `filePath`, creating intermediate directories as needed. * * The write is performed atomically on most platforms by relying on the OS * write guarantee for the final `writeFile` call. */ export declare function writeFile(filePath: string, content: string): Promise; /** * Perform an exact string replacement inside a file. * * - If `oldStr` is not found the operation fails. * - If `oldStr` appears more than once the operation fails (ambiguous patch). * - On success, the file is rewritten and a simple textual diff is returned. */ export declare function patchReplace(filePath: string, oldStr: string, newStr: string): Promise; /** * Delete a file at `filePath`. */ export declare function deleteFile(filePath: string): Promise<{ success: boolean; error?: string; }>; /** * Move (rename) a file from `src` to `dst`. */ export declare function moveFile(src: string, dst: string): Promise<{ success: boolean; error?: string; }>; /** * Search file contents in `dir` for lines matching `pattern` (regex). * * @param pattern Regular-expression pattern string. * @param dir Root directory to search (recursively). * @param opts.glob Glob-style filter applied to file names. * @param opts.maxMatches Cap on total matches returned. Default: 500. * @param opts.caseInsensitive Whether the regex is case-insensitive. */ export declare function searchContent(pattern: string, dir: string, opts?: { glob?: string; maxMatches?: number; caseInsensitive?: boolean; }): Promise; /** * Search for files matching a glob-style pattern inside `dir`. * * The `pattern` may contain `*` (single path segment) and `**` (any depth) * wildcards. */ export declare function searchFiles(pattern: string, dir: string): Promise<{ files: string[]; error?: string; }>; /** * List the entries of a directory. */ export declare function listDirectory(dirPath: string, opts?: { showHidden?: boolean; }): Promise; /** * Detect whether `buffer` is likely a binary file. * * Scans the first 8 KB for null bytes; also flags the file as binary when * more than 30 % of the scanned bytes are non-printable ASCII (excluding * common whitespace). */ export declare function isBinaryFile(buffer: Buffer): boolean; /** * Expand `~` to the user's home directory and resolve the path to an absolute * form. */ export declare function expandPath(p: string): string; /** * Prefix each line of `content` with a right-justified line number and a tab. * * Format matches the standard `cat -n` style used elsewhere in the codebase: * `" N\t"`. * * @param content String with `\n`-separated lines. * @param startLine 1-based line number for the first line. Default: 1. */ export declare function addLineNumbers(content: string, startLine?: number): string; //# sourceMappingURL=file-operations.d.ts.map