export type LocalImageErrorCode = 'RELATIVE_PATH_REJECTED' | 'FILE_NOT_FOUND' | 'PERMISSION_DENIED' | 'FILE_TOO_LARGE' | 'UNSUPPORTED_FORMAT' | 'HEIC_UNSUPPORTED' | 'INVALID_BASE64' | 'GLOB_TOO_LARGE' | 'SYMLINK_REJECTED' | 'OUTPUT_EXISTS' | 'OUTPUT_IS_INPUT' | 'OUTPUT_IS_SYMLINK' | 'INVALID_OUTPUT_PATH' | 'PATH_OUTSIDE_ALLOWED_DIRS'; export declare class LocalImageError extends Error { code: LocalImageErrorCode; path?: string; sizeBytes?: number; detail?: string; constructor(code: LocalImageErrorCode, message: string, opts?: { path?: string; sizeBytes?: number; detail?: string; }); } export declare function resolvePath(input: string): string; /** * Guard for tools that write a file (enrich_photo's outputPath). Runs before any credits are * spent, and returns the canonical path: the kernel's real path of the folder as given (so * `link/..` goes through the link's target, as the open would) joined with the file name. * Callers write to that canonical path, never to the string they were given. In this order: * 0. Under an allow-list, refuse any `..` segment (PATH_OUTSIDE_ALLOWED_DIRS), before any * filesystem call; see assertNoParentSegments. * 1. Refuse a file name that is empty, `.` or `..`, or a path ending in a separator * (INVALID_OUTPUT_PATH): none of them names a new file in a known folder. * 2. When the folder does not exist, refuse PATH_OUTSIDE_ALLOWED_DIRS if where it would be is * outside the allowed folders, else FILE_NOT_FOUND, so a missing folder outside the list * gets the same answer as an existing one. * 3. Refuse a canonical path outside PHOTOTOLOGY_MCP_ALLOWED_DIRS (when set). * 4. Refuse writing over the input file, compared by real path and inode, so a symlink, a * symlinked directory or a hard link pointing at the input is caught. Ignores overwrite. * 5. Refuse a canonical path that is itself a symlink, dangling or not. Ignores overwrite: a * link is never written through, since its target can sit outside every allowed folder. * 6. Refuse an existing output unless the caller passed overwrite. * `label` names the path in refusals ('outputPath', or 'sidecar path' for enrich_photo's `.xmp`). */ export declare function assertWritableOutput(inputPath: string | undefined, outputPath: string, overwrite: boolean, label?: string): string; /** * Write enrich_photo's output. O_EXCL (unless overwrite) refuses a file that appeared during the * enrich call, and O_NOFOLLOW refuses a symlink planted at outputPath after assertWritableOutput * ran, so both races are closed at the open syscall rather than by the earlier pre-check. */ export declare function writeOutputFile(outputPath: string, bytes: Buffer, overwrite: boolean, label?: string): void; /** * The real path of a file and whether reaching it went through a symlink anywhere along the way * (a symlinked parent folder, or macOS's /var -> /private/var). The real path uses the native * resolver so case on a case-insensitive disk matches the allow-list entries; viaSymlink is * confirmed with the JS resolver, which keeps the caller's case, so a mere case difference is * not reported as a symlink. */ export declare function resolveReal(absolutePath: string): { resolved: string; viaSymlink: boolean; }; export declare function assertInsideAllowedDirs(resolved: string, asGivenPath?: string): void; /** * Sniff magic bytes (first 12 bytes are enough for all supported formats). * * The accepted set mirrors what the backend's Sharp pipeline (`prepareImage` * in @phototology/core) can actually decode + transcode to JPEG, including * AVIF and TIFF. Gatekeeping a narrower set here than the API supports just * bounces files the server would have handled (observed live, 2026-06-01: * 11 AVIFs rejected as UNSUPPORTED_FORMAT despite Sharp decoding AVIF fine). */ declare function detectFormat(bytes: Buffer): 'jpeg' | 'png' | 'gif' | 'webp' | 'heic' | 'avif' | 'tiff' | null; /** * Read a local image after resolving its real path and checking it against * PHOTOTOLOGY_MCP_ALLOWED_DIRS. Returns the bytes plus where they really came from, so a tool can * tell the caller when a symlinked folder led somewhere else. */ export declare function readLocalImage(absolutePath: string): { bytes: Buffer; resolvedPath: string; viaSymlink: boolean; }; export declare function readImage(absolutePath: string): Buffer; /** * The API's image decoder (sharp without a HEIF plugin) cannot read HEIC/HEIF and answers * with an opaque 422 IMAGE_INVALID; 52 such calls on 2026-10-05 came from one MCP user's * iPhone library. Refuse here, by bytes not by name, with a conversion hint. Shared by every * input mode (local path, base64) and every tool that reads images. */ export declare function assertNotHeic(format: ReturnType, label: string): void; /** Sniff the format of a base64 payload from its first bytes (enough for every magic number we know). */ export declare function detectBase64Format(b64: string): ReturnType; export declare function computeSha256(bytes: Buffer): string; export declare function validateBase64(input: string): void; /** * Expand a list of literal paths and glob patterns into a deduplicated * absolute-path array. Each pattern is expanded independently; results * are merged + deduplicated. Every pattern must be absolute or ~/-prefixed * (RELATIVE_PATH_REJECTED otherwise); ~/ is expanded BEFORE fast-glob sees it. * * When PHOTOTOLOGY_MCP_ALLOWED_DIRS is set, a glob whose fixed folder part * (before the first wildcard) is outside every allowed folder is refused * whole with PATH_OUTSIDE_ALLOWED_DIRS naming only the pattern, and so is any * pattern or literal path with a `..` segment: thrown, or * passed to onRefusedPattern so the other patterns still expand. A match * that really lives outside the folders is dropped silently. Literal paths * pass through; readLocalImage judges them. * * Hard cap at MAX_GLOB_FILES across all patterns combined. Empty glob * matches return an empty result (not an error) so a typo'd glob doesn't * fail an otherwise-good batch. * * fast-glob options: * - onlyFiles: true (skip directory matches) * - suppressErrors: true (per-file permission-denied → skipped, not fatal) * - followSymbolicLinks: false (symlinks excluded; readImage rejects them anyway) */ export declare function expandGlobs(patterns: string[], onRefusedPattern?: (pattern: string, err: LocalImageError) => void): string[]; export {}; //# sourceMappingURL=local-image.d.ts.map