@j0hanz/filesystem-mcp 2.1.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- package/dist/cli.d.ts +1 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +29 -34
- package/dist/cli.js.map +1 -1
- package/dist/core/concurrency.d.ts +4 -7
- package/dist/core/concurrency.d.ts.map +1 -1
- package/dist/core/concurrency.js +4 -12
- package/dist/core/concurrency.js.map +1 -1
- package/dist/core/cursor.d.ts +11 -0
- package/dist/core/cursor.d.ts.map +1 -1
- package/dist/core/cursor.js +18 -20
- package/dist/core/cursor.js.map +1 -1
- package/dist/core/fmt.d.ts +2 -1
- package/dist/core/fmt.d.ts.map +1 -1
- package/dist/core/fmt.js +8 -15
- package/dist/core/fmt.js.map +1 -1
- package/dist/core/fs.d.ts +0 -14
- package/dist/core/fs.d.ts.map +1 -1
- package/dist/core/fs.js +1 -0
- package/dist/core/fs.js.map +1 -1
- package/dist/core/glob.d.ts +4 -16
- package/dist/core/glob.d.ts.map +1 -1
- package/dist/core/glob.js +16 -33
- package/dist/core/glob.js.map +1 -1
- package/dist/core/input-required.d.ts +10 -2
- package/dist/core/input-required.d.ts.map +1 -1
- package/dist/core/input-required.js +10 -0
- package/dist/core/input-required.js.map +1 -1
- package/dist/core/observability.d.ts.map +1 -1
- package/dist/core/observability.js +2 -1
- package/dist/core/observability.js.map +1 -1
- package/dist/core/path-completer.d.ts.map +1 -1
- package/dist/core/path-completer.js +4 -27
- package/dist/core/path-completer.js.map +1 -1
- package/dist/core/path-utils.d.ts +1 -1
- package/dist/core/path-utils.d.ts.map +1 -1
- package/dist/core/path-utils.js +2 -2
- package/dist/core/path-utils.js.map +1 -1
- package/dist/core/path.d.ts +7 -9
- package/dist/core/path.d.ts.map +1 -1
- package/dist/core/path.js +24 -42
- package/dist/core/path.js.map +1 -1
- package/dist/core/primitives.d.ts +7 -0
- package/dist/core/primitives.d.ts.map +1 -1
- package/dist/core/primitives.js +15 -8
- package/dist/core/primitives.js.map +1 -1
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +6 -23
- package/dist/core/read.js.map +1 -1
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +19 -74
- package/dist/core/schema.js.map +1 -1
- package/dist/core/search.d.ts +4 -11
- package/dist/core/search.d.ts.map +1 -1
- package/dist/core/search.js +11 -18
- package/dist/core/search.js.map +1 -1
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +6 -17
- package/dist/core/store.js.map +1 -1
- package/dist/core/util.d.ts.map +1 -1
- package/dist/core/util.js +2 -11
- package/dist/core/util.js.map +1 -1
- package/dist/index.js +15 -42
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +11 -11
- package/dist/instructions.js.map +1 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +17 -25
- package/dist/prompts.js.map +1 -1
- package/dist/resources.d.ts +4 -4
- package/dist/resources.d.ts.map +1 -1
- package/dist/resources.js +7 -17
- package/dist/resources.js.map +1 -1
- package/dist/server.d.ts +1 -12
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +15 -30
- package/dist/server.js.map +1 -1
- package/dist/tools/define.d.ts.map +1 -1
- package/dist/tools/define.js +39 -65
- package/dist/tools/define.js.map +1 -1
- package/dist/tools/delete.d.ts +2 -0
- package/dist/tools/delete.d.ts.map +1 -0
- package/dist/tools/{delete-file.js → delete.js} +35 -40
- package/dist/tools/delete.js.map +1 -0
- package/dist/tools/find-files.d.ts +2 -0
- package/dist/tools/find-files.d.ts.map +1 -0
- package/dist/tools/{search-files.js → find-files.js} +14 -19
- package/dist/tools/find-files.js.map +1 -0
- package/dist/tools/index.d.ts +6 -6
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +15 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/list-roots.d.ts +2 -0
- package/dist/tools/list-roots.d.ts.map +1 -0
- package/dist/tools/{roots.js → list-roots.js} +2 -2
- package/dist/tools/list-roots.js.map +1 -0
- package/dist/tools/list.d.ts.map +1 -1
- package/dist/tools/list.js +29 -37
- package/dist/tools/list.js.map +1 -1
- package/dist/tools/move.d.ts.map +1 -1
- package/dist/tools/move.js +5 -7
- package/dist/tools/move.js.map +1 -1
- package/dist/tools/progress.d.ts +1 -1
- package/dist/tools/progress.d.ts.map +1 -1
- package/dist/tools/progress.js.map +1 -1
- package/dist/tools/read.d.ts +1 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +37 -43
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/replace-text.d.ts +2 -0
- package/dist/tools/replace-text.d.ts.map +1 -0
- package/dist/tools/{replace-in-files.js → replace-text.js} +9 -23
- package/dist/tools/replace-text.js.map +1 -0
- package/dist/tools/search-text.d.ts +2 -0
- package/dist/tools/search-text.d.ts.map +1 -0
- package/dist/tools/{search-content.js → search-text.js} +10 -37
- package/dist/tools/search-text.js.map +1 -0
- package/dist/tools/stat.d.ts +1 -1
- package/dist/tools/stat.d.ts.map +1 -1
- package/dist/tools/stat.js +10 -38
- package/dist/tools/stat.js.map +1 -1
- package/dist/transport/http-policy.d.ts +18 -15
- package/dist/transport/http-policy.d.ts.map +1 -1
- package/dist/transport/http-policy.js +29 -39
- package/dist/transport/http-policy.js.map +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +29 -39
- package/dist/transport/http.js.map +1 -1
- package/package.json +4 -7
- package/dist/tools/delete-file.d.ts +0 -2
- package/dist/tools/delete-file.d.ts.map +0 -1
- package/dist/tools/delete-file.js.map +0 -1
- package/dist/tools/replace-in-files.d.ts +0 -2
- package/dist/tools/replace-in-files.d.ts.map +0 -1
- package/dist/tools/replace-in-files.js.map +0 -1
- package/dist/tools/roots.d.ts +0 -2
- package/dist/tools/roots.d.ts.map +0 -1
- package/dist/tools/roots.js.map +0 -1
- package/dist/tools/search-content.d.ts +0 -2
- package/dist/tools/search-content.d.ts.map +0 -1
- package/dist/tools/search-content.js.map +0 -1
- package/dist/tools/search-files.d.ts +0 -2
- package/dist/tools/search-files.d.ts.map +0 -1
- package/dist/tools/search-files.js.map +0 -1
package/dist/core/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/core/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,SAAS,EACT,SAAS,EACT,OAAO,EACP,SAAS,EACT,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,UAAU,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAqB7C,qFAAqF;AACrF,KAAK,UAAU,YAAY,CACzB,cA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AAkB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,CAAC;YACvF,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAE9B,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,eAAe,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,8BAA8B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzE,wEAAwE;QACxE,kEAAkE;QAClE,0BAA0B;QAC1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readlink, realpath, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, isAbsolute, join, parse, relative, resolve } from 'node:path';\n\nimport { timedSignal, withAbort } from './concurrency.js';\nimport { cli } from './config.js';\nimport {\n ERRNO_MAP,\n ErrorCode,\n FsError,\n isFsError,\n isNodeError,\n isNotFoundErrno,\n rethrowIfAborted,\n SKIPPABLE_ERRNOS,\n SKIPPABLE_FS_CODES,\n} from './errors.js';\nimport { Logger } from './observability.js';\nimport { findProjectRoot, isUnsafeCwdPath, resolveConfiguredDirs } from './path-discovery.js';\nimport {\n getReservedDeviceNameForPath,\n isPathWithinDirectories,\n isSamePath,\n isWindowsDriveRelativePath,\n normalizeAllowedDirectory,\n normalizePath,\n} from './path-utils.js';\nimport { parseTrueEnvFlag, toPosixPath } from './primitives.js';\nimport { SensitiveMatcher } from './sensitive.js';\nimport { ROOTS_TIMEOUT_MS } from './util.js';\n\n// Allowed-directory assembly and the PathGuard that enforces it. The\n// sensitive-file denylist lives in sensitive.ts, and the character-level\n// primitives (IS_WINDOWS, isAlpha, isSlash, toPosixPath) live in\n// primitives.ts.\ndeclare const ValidatedPathBrand: unique symbol;\nexport type ValidatedPath = string & { readonly [ValidatedPathBrand]: true };\n\nexport interface ValidatedPathDetails {\n requestedPath: string;\n resolvedPath: string;\n isSymlink: boolean;\n}\n\nexport interface ServerOptions {\n allowCwd?: boolean;\n cliAllowedDirs?: string[];\n readOnly?: boolean;\n}\n\n/** True when `normalizedRoot` really resolves inside `bounds` (FS_ROOT_BOUNDARY). */\nasync function isRootWithin(\n normalizedRoot: string,\n bounds: readonly string[],\n label: string,\n signal?: AbortSignal,\n): Promise<boolean> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalizedRoot), signal);\n return isPathWithinDirectories(normalizePath(realPath), bounds);\n } catch (error) {\n rethrowIfAborted(error);\n if (isNotFoundErrno(error)) {\n return false;\n }\n Logger.warn(`${label}: realpath failed unexpectedly`, {\n root: normalizedRoot,\n error: String(error),\n });\n return false;\n }\n}\n\nasync function filterRootsWithin(\n roots: readonly string[],\n bounds: readonly string[],\n label: string,\n signal?: AbortSignal,\n): Promise<string[]> {\n const normalizedBounds = normalizeAllowedDirectories(bounds);\n const normalizedRoots = roots.map(normalizePath);\n if (normalizedRoots.length === 0) {\n return [];\n }\n\n const results = await Promise.all(\n normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, label, signal)),\n );\n\n return normalizedRoots.filter((_, i) => results[i]);\n}\n\n/** `path.relative` with forward slashes, so displayed paths match across platforms. */\nexport function toPosixRelative(from: string, to: string): string {\n return toPosixPath(relative(from, to));\n}\n\n// ---------------------------------------------------------------------------\n// Resolver pipeline\n// ---------------------------------------------------------------------------\n\nexport function normalizeAllowedDirectories(dirs: readonly string[]): string[] {\n const normalized: string[] = [];\n for (const dir of dirs) {\n const entry = normalizeAllowedDirectory(dir);\n if (entry.length > 0) {\n normalized.push(entry);\n }\n }\n return [...new Set(normalized)];\n}\n\nexport async function resolveRealPath(\n normalized: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalized), signal);\n return normalizeAllowedDirectory(realPath);\n } catch (error) {\n rethrowIfAborted(error);\n // Only suppress ENOENT — the path genuinely does not exist.\n // EACCES, EIO, and other unexpected errors are rethrown so callers\n // cannot silently operate with a narrowed allowed-directory set.\n if (isNotFoundErrno(error)) {\n return null;\n }\n throw error;\n }\n}\n\nasync function expandAllowedDirectories(\n primaryDirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const realPaths = await Promise.all(primaryDirs.map((dir) => resolveRealPath(dir, signal)));\n\n const expanded: string[] = [];\n for (let i = 0; i < primaryDirs.length; i++) {\n const primary = primaryDirs[i];\n if (!primary) {\n continue;\n }\n\n expanded.push(primary);\n\n const real = realPaths[i];\n if (real && !isSamePath(real, primary)) {\n expanded.push(real);\n }\n }\n\n return [...new Set(expanded)];\n}\n\nexport async function resolveAllowedDirectoriesState(\n dirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const primary = normalizeAllowedDirectories(dirs);\n return expandAllowedDirectories(primary, signal);\n}\n\n// ---------------------------------------------------------------------------\n// Windows helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Accepted risk: validation methods resolve/verify a path (symlinks, boundaries,\n * sensitivity) and then return a plain string; the actual fs operation happens\n * afterward as a separate syscall (classic TOCTOU). A symlink swapped in that\n * exact window could redirect the follow-up operation. This is mitigated by\n * re-validating the resolved real path (not just the requested path) and by\n * walking ancestors to catch escapes before the target exists, but it is not\n * eliminated — doing so would require fd-based operations (open with\n * O_NOFOLLOW / operate on the resolved fd) throughout core/fs.ts. Acceptable\n * tradeoff for a local, single-user filesystem server today.\n */\nexport class PathGuard {\n private allowedDirectoriesState: string[] | undefined;\n private readonly sensitive = new SensitiveMatcher();\n /**\n * Directories added by an accepted access grant (R8) — from the tool\n * executor's grant round-trip, or from a client's declared workspace roots on\n * the legacy stdio leg. Held separately from the configured baseline because\n * `recomputeAllowedDirectories` rebuilds that baseline from CLI args and env\n * on every call: anything merged into it would be recomputed away.\n *\n * These are NOT filtered against the baseline. A granted directory is\n * out-of-baseline by definition, so a baseline filter dropped every one while\n * `applyGrant` still reported success — the whole round-trip prompted the\n * user and then changed nothing. FS_ROOT_BOUNDARY and the unsafe-path denylist\n * remain the limits, both checked in `applyGrant` — the only writer of this\n * field — so the recompute can rebuild from it without re-filtering.\n */\n private grantedDirectories: string[] = [];\n private rootBoundaries: string[] = [];\n\n // ponytail: one mutex per PathGuard. If per-session grant throughput ever\n // matters, split into per-grant-dir locks; a single lock is correct for the\n // stdio + InMemoryEventStore single-process model.\n #mutex = Promise.resolve();\n\n private readonly options: ServerOptions | undefined;\n\n constructor(options?: ServerOptions) {\n this.options = options;\n }\n\n initialize(expanded: readonly string[]): void {\n this.allowedDirectoriesState = normalizeAllowedDirectories(expanded);\n }\n\n isInitialized(): boolean {\n return this.allowedDirectoriesState !== undefined;\n }\n\n /**\n * Run `fn` as the next holder of the guard's single mutation lock. Every\n * change to the allowed set goes through this so concurrent grants cannot\n * interleave their read-`await`-write and lose a grant (GRANT-1).\n */\n private async runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n const result = this.#mutex.then(fn, fn);\n this.#mutex = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n }\n\n getAllowedDirectories(): string[] {\n if (!this.allowedDirectoriesState) {\n return [];\n }\n return [...this.allowedDirectoriesState];\n }\n\n isSensitive(filePath: string): boolean {\n return this.sensitive.isSensitive(filePath);\n }\n\n /**\n * True when `entryPath` is both within the guard's allowed directories and\n * not sensitive, checking the requested AND resolved paths. EVERY entry is\n * realpath-resolved via validateExistingPathDetailed: a symlinked ancestor\n * directory pointing outside the sandbox would otherwise pass the lexical\n * containment check (fs.glob follows symlinks and yields external entries as\n * non-symlink dirents). validateExistingPathDetailed re-checks containment on\n * the real path against this.allowedDirectoriesState (the guard's full\n * allowed set — a superset of the single-root `bounds` callers pass) and\n * re-checks sensitivity on the resolved target, throwing ACCESS_DENIED for\n * escapes/sensitive, which the catch below turns into a filter. Skippable\n * errno/fs errors return false (the entry is filtered, not fatal). The\n * accepted TOCTOU window is documented at the class docstring above.\n */\n async isEntryAccessible(entryPath: string): Promise<boolean> {\n const isSensitive = (requestedPath: string, resolvedPath: string): boolean =>\n this.isSensitive(requestedPath) || this.isSensitive(resolvedPath);\n try {\n const validated = await this.validateExistingPathDetailed(entryPath);\n return !isSensitive(validated.requestedPath, validated.resolvedPath);\n } catch (error) {\n if (isFsError(error)) {\n if (SKIPPABLE_FS_CODES.has(error.code)) return false;\n throw error;\n }\n if (isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code))\n return false;\n throw error;\n }\n }\n\n async validateExistingPath(requestedPath: string): Promise<ValidatedPath> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n return details.resolvedPath as ValidatedPath;\n }\n\n /** True when a normalized path equals its own filesystem root (`C:\\`, `/`). */\n private isFilesystemRoot(normalizedPath: string): boolean {\n return isSamePath(normalizedPath, parse(normalizedPath).root);\n }\n\n /**\n * True when a grant must never admit `targetDir` — a bare filesystem root, or\n * an unsafe path (home, /etc, C:\\Windows, ...). Checked on the lexical path\n * AND on the one it resolves to: `expandAllowedDirectories` pushes each root's\n * realpath into the allowed set, so a lexical-only check let a symlink or\n * junction aliasing $HOME/C:\\Windows in under an innocuous name — and the\n * confirmation prompt showed the alias, not the target. A target that cannot\n * be resolved is judged lexically; it does not exist to escape into.\n */\n private async isUnsafeGrantTarget(targetDir: string): Promise<boolean> {\n const isRefused = (dir: string): boolean => this.isFilesystemRoot(dir) || isUnsafeCwdPath(dir);\n const normalized = normalizePath(targetDir);\n if (isRefused(normalized)) return true;\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(normalized));\n } catch {\n return false;\n }\n return !isSamePath(resolved, normalized) && isRefused(resolved);\n }\n\n /** Walk up from a blocked path to the closest existing ancestor directory. */\n private async resolveGrantTargetDir(blockedPath: string): Promise<string> {\n let targetDir = blockedPath;\n for (;;) {\n const parent = dirname(targetDir);\n try {\n // An existing directory is the grant target; an existing file grants\n // its parent directory.\n return (await stat(targetDir)).isDirectory() ? targetDir : parent;\n } catch {\n // Missing — keep walking up.\n }\n if (parent === targetDir) return targetDir;\n targetDir = parent;\n }\n }\n\n /**\n * Pre-check (no mutation, no callback): given the paths a tool is about to\n * operate on, return the sorted, de-duplicated grant-target directories for\n * those that are outside the allowed roots AND grantable (within FS_ROOT_BOUNDARY\n * when it is configured). A path whose nearest existing ancestor escapes the\n * boundary is NOT grantable and is omitted — the operation will fail with\n * ACCESS_DENIED for it rather than prompt. The caller returns an\n * `input_required` result carrying exactly this set (R7), and on retry applies\n * each accepted grant via {@link applyGrant} (R8). `requestState` binds this\n * set so a grant accepted for X cannot authorize Y (R9).\n */\n async precheckAccess(paths: readonly string[]): Promise<string[]> {\n if (!this.allowedDirectoriesState || paths.length === 0) {\n return [];\n }\n const allowedDirs = this.allowedDirectoriesState;\n const grantDirs: string[] = [];\n for (const requested of paths) {\n if (!requested) {\n continue;\n }\n const normalized = normalizePath(requested);\n if (isPathWithinDirectories(normalized, allowedDirs)) {\n continue;\n }\n const targetDir = normalizePath(await this.resolveGrantTargetDir(normalized));\n // Never offer a grant into a bare filesystem root or an unsafe path (home,\n // /etc, C:\\Windows, ...). Without FS_ROOT_BOUNDARY, isWithinBoundary returns\n // true for everything, so this is the one guard that still rejects roots a\n // misleading grant could reach. Mirrors the check gating --allow-cwd.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n continue;\n }\n if (grantDirs.includes(targetDir)) {\n continue;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n continue;\n }\n grantDirs.push(targetDir);\n }\n return grantDirs.sort();\n }\n\n /**\n * Apply an accepted access grant: enforce FS_ROOT_BOUNDARY again (a TOCTOU\n * re-check against the boundary resolved at config time), then extend the\n * allowed roots for the remainder of the session (R8, A4). Returns false when\n * the boundary or the unsafe-path denylist blocks the grant, AND when the\n * recompute did not actually admit the directory — the return value now\n * reports what the guard's allowed set really holds, not merely that the\n * pre-checks passed. The caller leaves a refused path to fail with\n * ACCESS_DENIED during the operation. Idempotent: re-granting an already\n * allowed directory is a no-op via the dedup in `initialize`.\n */\n async applyGrant(targetDir: string): Promise<boolean> {\n // Defense-in-depth: even a tampered/accepted grant cannot extend roots into\n // an unsafe path. The precheckAccess guard already refuses to offer these;\n // this catches a grant that arrived by another route — the legacy stdio\n // `roots/list` seeding, which has no confirmation round-trip at all.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n return false;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n return false;\n }\n // Read + write under the mutation lock so a concurrent grant cannot\n // interleave and lose this grant (GRANT-1). runExclusive is not reentrant:\n // nothing in this body may take the lock again.\n return this.runExclusive(async () => {\n const previous = this.grantedDirectories;\n this.grantedDirectories = [...previous, normalizePath(targetDir)];\n try {\n await this.recomputeAllowedDirectories();\n } catch (error) {\n // A failed recompute leaves the guard with its previous, consistent view.\n this.grantedDirectories = previous;\n throw error;\n }\n // Verify rather than assume: a boundary that no longer covers this\n // directory would drop it in the recompute above, and reporting success\n // for a grant that did not land is exactly the failure this replaces.\n if (isPathWithinDirectories(normalizePath(targetDir), this.getAllowedDirectories())) {\n return true;\n }\n this.grantedDirectories = previous;\n await this.recomputeAllowedDirectories();\n return false;\n });\n }\n\n // The guard already realpath-resolved FS_ROOT_BOUNDARY into rootBoundaries\n // during recomputeAllowedDirectories. Reuse that single source of truth so\n // grant paths check the same boundary the rest of the guard enforces,\n // instead of re-reading the env and re-resolving each entry.\n private async isWithinBoundary(targetDir: string): Promise<boolean> {\n if (this.rootBoundaries.length === 0) {\n return true;\n }\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(targetDir));\n } catch {\n resolved = normalizePath(targetDir);\n }\n return isPathWithinDirectories(resolved, this.rootBoundaries);\n }\n\n private validateAccessAndSensitivity(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n const result = this.validateAccess(requestedPath);\n this.assertNotSensitiveFile(requestedPath, requestedPath);\n this.assertNotSensitiveFile(result.normalizedRequested, requestedPath);\n return result;\n }\n\n // Synchronous since the access-grant round-trip moved to the executor's\n // pre-check: validateAccess only does lexical containment math and throws,\n // no async I/O remains. Callers still `await` it for uniform control-flow;\n // awaiting a non-thenable returns it unchanged.\n private validateAccess(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n if (!this.allowedDirectoriesState) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'PathGuard not initialized. Call initialize() first.',\n requestedPath,\n );\n }\n if (isWindowsDriveRelativePath(requestedPath)) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n requestedPath,\n );\n }\n const reservedDevice = getReservedDeviceNameForPath(requestedPath);\n if (reservedDevice) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n `Reserved Windows device name not allowed: ${reservedDevice}.`,\n requestedPath,\n );\n }\n\n const normalizedRequested = normalizePath(requestedPath);\n const allowedDirs = this.allowedDirectoriesState;\n\n const accessDeniedHint =\n allowedDirs.length > 0\n ? `Allowed: ${allowedDirs.join(', ')}`\n : 'No allowed directories configured.';\n\n if (!isPathWithinDirectories(normalizedRequested, allowedDirs)) {\n // Out of root. The access-grant `input_required` round-trip is driven by\n // the executor's pre-check (precheckAccess) BEFORE the operation runs, so\n // by the time validation reaches here any grantable out-of-root path has\n // already been accepted and added to the allowed set. A path still out of\n // root here was either declined, ungrantable (outside FS_ROOT_BOUNDARY), or\n // never pre-checked — fail closed.\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n return {\n normalizedRequested,\n allowedDirs: this.allowedDirectoriesState,\n accessDeniedHint,\n };\n }\n\n private async handleRealpathError(\n error: unknown,\n normalizedRequested: string,\n allowedDirs: string[],\n accessDeniedHint: string,\n requestedPath: string,\n ): Promise<never> {\n if (isNotFoundErrno(error)) {\n // Resolve the nearest existing ancestor to detect out-of-sandbox symlinks.\n // e.g. if `link -> C:\\external` and path is `link\\nonexistent.txt`, the\n // ancestor resolves outside allowed dirs → ACCESS_DENIED, not NOT_FOUND.\n try {\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n } catch (ancestorErr) {\n // Rethrow any FsError — collapsing e.g. UNKNOWN to NOT_FOUND would mask\n // incomplete sandbox checks and make bugs invisible to callers.\n if (isFsError(ancestorErr)) {\n throw ancestorErr;\n }\n }\n\n throw new FsError(ErrorCode.NOT_FOUND, 'Path not found', requestedPath, error);\n }\n\n const mapped =\n isNodeError(error) && error.code !== undefined ? ERRNO_MAP[error.code] : undefined;\n throw new FsError(\n mapped ?? ErrorCode.UNKNOWN,\n 'Cannot access path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n async validateExistingPathDetailed(requestedPath: string): Promise<ValidatedPathDetails> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n let realPath: string;\n try {\n realPath = await realpath(normalizedRequested);\n } catch (error) {\n realPath = await this.handleRealpathError(\n error,\n normalizedRequested,\n allowedDirs,\n accessDeniedHint,\n requestedPath,\n );\n }\n\n const normalizedReal = normalizePath(realPath);\n\n if (!isPathWithinDirectories(normalizedReal, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Re-check the resolved real path: a symlink inside an allowed root may\n // point at a sensitive file (e.g. link -> .env). The early check above only\n // sees the requested/normalized path, not the symlink target.\n this.assertNotSensitiveFile(normalizedReal, requestedPath);\n\n return {\n requestedPath: normalizedRequested,\n resolvedPath: normalizedReal,\n isSymlink: !isSamePath(normalizedRequested, normalizedReal),\n };\n }\n\n async validateExistingDirectory(requestedPath: string): Promise<string> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n\n let stats: Stats;\n try {\n stats = await stat(details.resolvedPath);\n } catch (error) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot access directory',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n if (!stats.isDirectory()) {\n throw new FsError(ErrorCode.NOT_DIRECTORY, 'Not a directory', requestedPath);\n }\n\n return details.resolvedPath;\n }\n\n resolvePathOrRoot(pathValue: string | undefined): string {\n if (pathValue && pathValue.trim().length > 0) {\n return pathValue;\n }\n const roots = this.getAllowedDirectories();\n if (roots.length === 0) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'No roots configured. Use the roots tool or --allow-cwd.',\n );\n }\n if (roots.length > 1) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Multiple roots configured. Provide an explicit path.',\n );\n }\n const root = roots[0];\n if (!root) {\n throw new FsError(ErrorCode.ACCESS_DENIED, 'Workspace root is unexpectedly undefined');\n }\n return root;\n }\n\n isAllowedRoot(normalizedPath: string): boolean {\n // isSamePath case-folds on case-insensitive filesystems (win + darwin),\n // matching the containment checks used everywhere else in the guard. The\n // previous IS_WINDOWS-only fold left darwin doing exact-case compares here\n // while isPathInsideDirectory folded — a root matched case-insensitively\n // everywhere else was missed.\n return this.getAllowedDirectories().some((dir) => isSamePath(dir, normalizedPath));\n }\n\n // Checks ONLY the sensitive-file denylist. Root containment and symlink\n // resolution must be verified separately (e.g. via validateExistingPath).\n private assertNotSensitiveFile(checkPath: string, requestedPath: string): void {\n if (this.isSensitive(checkPath)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Sensitive file blocked. Set ALLOW_SENSITIVE=1 to override.',\n requestedPath,\n );\n }\n }\n\n private throwAccessDenied(requestedPath: string, hint?: string): never {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n hint ? `Outside allowed directories. ${hint}` : 'Outside allowed directories.',\n requestedPath,\n );\n }\n private async resolveNearestExistingAncestor(\n requestedPath: string,\n currentPath: string,\n ): Promise<{ realAncestor: string; resolvedTarget: string }> {\n const missingSegments: string[] = [];\n let current = currentPath;\n for (;;) {\n try {\n const realAncestor = normalizePath(await realpath(current));\n const resolvedTarget =\n missingSegments.length === 0\n ? realAncestor\n : normalizePath(join(realAncestor, ...missingSegments.reverse()));\n return { realAncestor, resolvedTarget };\n } catch (error) {\n try {\n const stats = await lstat(current);\n if (stats.isSymbolicLink()) {\n const target = await readlink(current);\n const resolvedTarget = isAbsolute(target) ? target : resolve(dirname(current), target);\n const normalizedTarget = normalizePath(resolvedTarget);\n const allowedDirs = this.getAllowedDirectories();\n if (!isPathWithinDirectories(normalizedTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath);\n }\n }\n } catch (lstatErr) {\n if (isFsError(lstatErr) && lstatErr.code === ErrorCode.ACCESS_DENIED) {\n throw lstatErr;\n }\n // ENOENT is expected during ancestor walk — the entry simply doesn't exist.\n // Any other error (EACCES, EIO, ELOOP) is unexpected; fail safe.\n if (!isNodeError(lstatErr) || lstatErr.code !== 'ENOENT') {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot probe symlink ancestor',\n requestedPath,\n lstatErr instanceof Error ? lstatErr : undefined,\n );\n }\n }\n const parent = dirname(current);\n if (parent === current) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot resolve path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n missingSegments.push(basename(current));\n current = parent;\n }\n }\n }\n\n async validatePathForWrite(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n // Re-check the resolved target: a symlink inside an allowed root may point\n // at a sensitive file. Writing through such a link must be blocked too.\n this.assertNotSensitiveFile(resolvedTarget, requestedPath);\n return resolvedTarget as ValidatedPath;\n }\n\n async validatePathForDelete(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n // A workspace root is refused here, before the parent-containment check\n // below reaches for a parent that is out-of-root by construction and\n // reports \"Outside allowed directories\" for the one directory the caller\n // can see IS allowed. delete-file.ts keeps its own root check for the\n // nested-root case, where the parent is itself an allowed root and this\n // path is never taken.\n if (this.isAllowedRoot(normalizedRequested)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Deleting a workspace root directory is not allowed',\n requestedPath,\n );\n }\n\n const parent = dirname(normalizedRequested);\n let realParent: string;\n try {\n realParent = await realpath(parent);\n } catch (error) {\n throw new FsError(\n ErrorCode.NOT_FOUND,\n 'Parent directory not found',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n const normalizedRealParent = normalizePath(realParent);\n\n if (!isPathWithinDirectories(normalizedRealParent, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Resolve the final component when it exists. For deletion, we ONLY\n // block if the real target is outside the sandbox IF the target is\n // NOT a symlink. Deleting a symlink is safe even if it points outside.\n try {\n const stats = await lstat(normalizedRequested);\n if (stats.isSymbolicLink()) {\n // Symlink: check link sensitivity but don't resolve target.\n // The parent check above ensures the link itself is in an allowed root.\n this.assertNotSensitiveFile(normalizedRequested, requestedPath);\n return normalizedRequested as ValidatedPath;\n }\n\n // Not a symlink: resolve to catch path escapes (e.g. /allowed/dir/../../etc)\n // and block sensitive files.\n const realTarget = normalizePath(await realpath(normalizedRequested));\n if (!isPathWithinDirectories(realTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n this.assertNotSensitiveFile(realTarget, requestedPath);\n return realTarget as ValidatedPath;\n } catch (error) {\n // A denial raised inside this block (out-of-root real target, or a\n // sensitive file reached through a symlinked parent) must propagate.\n // Only a probe failure — ENOENT and friends — falls through to the\n // parent check, which is sufficient for a path that does not exist.\n if (isFsError(error)) {\n throw error;\n }\n }\n return normalizedRequested as ValidatedPath;\n }\n\n async recomputeAllowedDirectories(): Promise<void> {\n const cliAllowedDirs = normalizeAllowedDirectories(this.options?.cliAllowedDirs ?? []);\n\n // Parse allowed directories from environment variable\n const allowMissing =\n cli.allowMissingRoots ??\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n const envAllowedDirs = await resolveConfiguredDirs('FS_ALLOWED_DIRS', { allowMissing });\n\n // Parse FS_ROOT_BOUNDARY (the --root-boundary flag beats the env var)\n const boundaries = await resolveConfiguredDirs('FS_ROOT_BOUNDARY', {\n resolveReal: true,\n ...(cli.rootBoundary !== undefined ? { rawValue: cli.rootBoundary } : {}),\n });\n\n const allowCwd = Boolean(this.options?.allowCwd);\n const allowCwdDirs: string[] = [];\n if (allowCwd) {\n let cwd = normalizePath(process.cwd());\n const walkCwd =\n cli.allowCwdWalk ?? parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n if (walkCwd) {\n cwd = await findProjectRoot(cwd, [...boundaries, homedir()]);\n }\n if (isUnsafeCwdPath(cwd)) {\n Logger.emit(\n 'warning',\n `Skipped adding unsafe current working directory to allowed list: ${cwd}`,\n );\n } else {\n allowCwdDirs.push(cwd);\n }\n }\n\n const baseline = [...cliAllowedDirs, ...envAllowedDirs, ...allowCwdDirs];\n\n const signal = timedSignal(undefined, ROOTS_TIMEOUT_MS);\n // FS_ROOT_BOUNDARY is the only filter grants answer to (see\n // `grantedDirectories`); without one they pass through as accepted.\n const grantsToInclude =\n boundaries.length > 0\n ? await filterRootsWithin(this.grantedDirectories, boundaries, 'grantBoundary', signal)\n : this.grantedDirectories;\n\n const combined = [...baseline, ...grantsToInclude];\n const nextState = await resolveAllowedDirectoriesState(combined, signal);\n // Commit boundaries and the allowed set together, after every await has\n // resolved, so a rejecting recompute leaves the guard's previous,\n // consistent view intact.\n this.rootBoundaries = boundaries;\n this.init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;QAED,MAAM,QAAQ,GAAG,CAAC,GAAG,cAAc,EAAE,GAAG,cAAc,EAAE,GAAG,YAAY,CAAC,CAAC;QAEzE,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACrD,4DAA4D;QAC5D,oEAAoE;QACpE,MAAM,eAAe,GACnB,UAAU,CAAC,MAAM,GAAG,CAAC;YACnB,CAAC,CAAC,MAAM,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,EAAE,MAAM,CAAC;YACtE,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC;QAE9B,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,eAAe,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,MAAM,8BAA8B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzE,wEAAwE;QACxE,kEAAkE;QAClE,0BAA0B;QAC1B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import type { Stats } from 'node:fs';\nimport { lstat, readlink, realpath, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';\n\nimport { withAbort } from './concurrency.js';\nimport { cli } from './config.js';\nimport {\n ERRNO_MAP,\n ErrorCode,\n FsError,\n isFsError,\n isNodeError,\n isNotFoundErrno,\n rethrowIfAborted,\n SKIPPABLE_ERRNOS,\n SKIPPABLE_FS_CODES,\n} from './errors.js';\nimport { Logger } from './observability.js';\nimport { findProjectRoot, isUnsafeCwdPath, resolveConfiguredDirs } from './path-discovery.js';\nimport {\n getReservedDeviceNameForPath,\n isPathWithinDirectories,\n isSamePath,\n isWindowsDriveRelativePath,\n normalizeAllowedDirectory,\n normalizePath,\n} from './path-utils.js';\nimport { parseTrueEnvFlag, toPosixPath } from './primitives.js';\nimport { SensitiveMatcher } from './sensitive.js';\nimport { ROOTS_TIMEOUT_MS } from './util.js';\n\n// Allowed-directory assembly and the PathGuard that enforces it. The\n// sensitive-file denylist lives in sensitive.ts, and the character-level\n// primitives (IS_WINDOWS, isAlpha, isSlash, toPosixPath) live in\n// primitives.ts.\ndeclare const ValidatedPathBrand: unique symbol;\nexport type ValidatedPath = string & { readonly [ValidatedPathBrand]: true };\n\nexport interface ValidatedPathDetails {\n requestedPath: string;\n resolvedPath: string;\n isSymlink: boolean;\n}\n\nexport interface ServerOptions {\n allowCwd?: boolean;\n cliAllowedDirs?: string[];\n readOnly?: boolean;\n}\n\n/** True when `normalizedRoot` really resolves inside `bounds` (FS_ROOT_BOUNDARY). */\nasync function isRootWithin(\n normalizedRoot: string,\n bounds: readonly string[],\n signal?: AbortSignal,\n): Promise<boolean> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalizedRoot), signal);\n return isPathWithinDirectories(normalizePath(realPath), bounds);\n } catch (error) {\n rethrowIfAborted(error);\n if (isNotFoundErrno(error)) {\n return false;\n }\n Logger.warn('grantBoundary: realpath failed unexpectedly', {\n root: normalizedRoot,\n error: String(error),\n });\n return false;\n }\n}\n\nasync function filterRootsWithin(\n roots: readonly string[],\n bounds: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const normalizedBounds = normalizeAllowedDirectories(bounds);\n const normalizedRoots = roots.map(normalizePath);\n\n const results = await Promise.all(\n normalizedRoots.map((root) => isRootWithin(root, normalizedBounds, signal)),\n );\n\n return normalizedRoots.filter((_, i) => results[i]);\n}\n\n/** `path.relative` with forward slashes, so displayed paths match across platforms. */\nexport function toPosixRelative(from: string, to: string): string {\n return toPosixPath(relative(from, to));\n}\n\n// ---------------------------------------------------------------------------\n// Resolver pipeline\n// ---------------------------------------------------------------------------\n\nexport function normalizeAllowedDirectories(dirs: readonly string[]): string[] {\n const normalized: string[] = [];\n for (const dir of dirs) {\n const entry = normalizeAllowedDirectory(dir);\n if (entry.length > 0) {\n normalized.push(entry);\n }\n }\n return [...new Set(normalized)];\n}\n\nexport async function resolveRealPath(\n normalized: string,\n signal?: AbortSignal,\n): Promise<string | null> {\n try {\n signal?.throwIfAborted();\n const realPath = await withAbort(realpath(normalized), signal);\n return normalizeAllowedDirectory(realPath);\n } catch (error) {\n rethrowIfAborted(error);\n // Only suppress ENOENT — the path genuinely does not exist.\n // EACCES, EIO, and other unexpected errors are rethrown so callers\n // cannot silently operate with a narrowed allowed-directory set.\n if (isNotFoundErrno(error)) {\n return null;\n }\n throw error;\n }\n}\n\nexport async function resolveAllowedDirectoriesState(\n dirs: readonly string[],\n signal?: AbortSignal,\n): Promise<string[]> {\n const primary = normalizeAllowedDirectories(dirs);\n const reals = await Promise.all(primary.map((dir) => resolveRealPath(dir, signal)));\n return [\n ...new Set(\n primary.flatMap((dir, i) => {\n const real = reals[i];\n return real && !isSamePath(real, dir) ? [dir, real] : [dir];\n }),\n ),\n ];\n}\n\n// ---------------------------------------------------------------------------\n// Windows helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Accepted risk: validation methods resolve/verify a path (symlinks, boundaries,\n * sensitivity) and then return a plain string; the actual fs operation happens\n * afterward as a separate syscall (classic TOCTOU). A symlink swapped in that\n * exact window could redirect the follow-up operation. This is mitigated by\n * re-validating the resolved real path (not just the requested path) and by\n * walking ancestors to catch escapes before the target exists, but it is not\n * eliminated — doing so would require fd-based operations (open with\n * O_NOFOLLOW / operate on the resolved fd) throughout core/fs.ts. Acceptable\n * tradeoff for a local, single-user filesystem server today.\n */\nexport class PathGuard {\n private allowedDirectoriesState: string[] | undefined;\n private readonly sensitive = new SensitiveMatcher();\n /**\n * Directories added by an accepted access grant (R8) — from the tool\n * executor's grant round-trip, or from a client's declared workspace roots on\n * the legacy stdio leg. Held separately from the configured baseline because\n * `recomputeAllowedDirectories` rebuilds that baseline from CLI args and env\n * on every call: anything merged into it would be recomputed away.\n *\n * These are NOT filtered against the baseline. A granted directory is\n * out-of-baseline by definition, so a baseline filter dropped every one while\n * `applyGrant` still reported success — the whole round-trip prompted the\n * user and then changed nothing. FS_ROOT_BOUNDARY and the unsafe-path denylist\n * remain the limits, both checked in `applyGrant` — the only writer of this\n * field — so the recompute can rebuild from it without re-filtering.\n */\n private grantedDirectories: string[] = [];\n private rootBoundaries: string[] = [];\n\n // ponytail: one mutex per PathGuard. If per-session grant throughput ever\n // matters, split into per-grant-dir locks; a single lock is correct for the\n // stdio + InMemoryEventStore single-process model.\n #mutex = Promise.resolve();\n\n private readonly options: ServerOptions | undefined;\n\n constructor(options?: ServerOptions) {\n this.options = options;\n }\n\n initialize(expanded: readonly string[]): void {\n this.allowedDirectoriesState = normalizeAllowedDirectories(expanded);\n }\n\n isInitialized(): boolean {\n return this.allowedDirectoriesState !== undefined;\n }\n\n /**\n * Run `fn` as the next holder of the guard's single mutation lock. Every\n * change to the allowed set goes through this so concurrent grants cannot\n * interleave their read-`await`-write and lose a grant (GRANT-1).\n */\n private async runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n const result = this.#mutex.then(fn, fn);\n this.#mutex = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n }\n\n getAllowedDirectories(): string[] {\n if (!this.allowedDirectoriesState) {\n return [];\n }\n return [...this.allowedDirectoriesState];\n }\n\n isSensitive(filePath: string): boolean {\n return this.sensitive.isSensitive(filePath);\n }\n\n /**\n * True when `entryPath` is both within the guard's allowed directories and\n * not sensitive, checking the requested AND resolved paths. EVERY entry is\n * realpath-resolved via validateExistingPathDetailed: a symlinked ancestor\n * directory pointing outside the sandbox would otherwise pass the lexical\n * containment check (fs.glob follows symlinks and yields external entries as\n * non-symlink dirents). validateExistingPathDetailed re-checks containment on\n * the real path against this.allowedDirectoriesState (the guard's full\n * allowed set — a superset of the single-root `bounds` callers pass) and\n * re-checks sensitivity on the resolved target, throwing ACCESS_DENIED for\n * escapes/sensitive, which the catch below turns into a filter. Skippable\n * errno/fs errors return false (the entry is filtered, not fatal). The\n * accepted TOCTOU window is documented at the class docstring above.\n */\n async isEntryAccessible(entryPath: string): Promise<boolean> {\n const isSensitive = (requestedPath: string, resolvedPath: string): boolean =>\n this.isSensitive(requestedPath) || this.isSensitive(resolvedPath);\n try {\n const validated = await this.validateExistingPathDetailed(entryPath);\n return !isSensitive(validated.requestedPath, validated.resolvedPath);\n } catch (error) {\n if (isFsError(error)) {\n if (SKIPPABLE_FS_CODES.has(error.code)) return false;\n throw error;\n }\n if (isNodeError(error) && error.code !== undefined && SKIPPABLE_ERRNOS.has(error.code))\n return false;\n throw error;\n }\n }\n\n async validateExistingPath(requestedPath: string): Promise<ValidatedPath> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n return details.resolvedPath as ValidatedPath;\n }\n\n /**\n * True when a grant must never admit `targetDir` — an unsafe path (home,\n * /etc, C:\\Windows, ...). Checked on the lexical path AND on the one it\n * resolves to: `resolveAllowedDirectoriesState` pushes each root's realpath\n * into the allowed set, so a lexical-only check let a symlink or junction\n * aliasing $HOME/C:\\Windows in under an innocuous name — and the confirmation\n * prompt showed the alias, not the target. A target that cannot be resolved\n * is judged lexically; it does not exist to escape into.\n */\n private async isUnsafeGrantTarget(targetDir: string): Promise<boolean> {\n const normalized = normalizePath(targetDir);\n if (isUnsafeCwdPath(normalized)) return true;\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(normalized));\n } catch {\n return false;\n }\n return !isSamePath(resolved, normalized) && isUnsafeCwdPath(resolved);\n }\n\n /** Walk up from a blocked path to the closest existing ancestor directory. */\n private async resolveGrantTargetDir(blockedPath: string): Promise<string> {\n let targetDir = blockedPath;\n for (;;) {\n const parent = dirname(targetDir);\n try {\n // An existing directory is the grant target; an existing file grants\n // its parent directory.\n return (await stat(targetDir)).isDirectory() ? targetDir : parent;\n } catch {\n // Missing — keep walking up.\n }\n if (parent === targetDir) return targetDir;\n targetDir = parent;\n }\n }\n\n /**\n * Pre-check (no mutation, no callback): given the paths a tool is about to\n * operate on, return the sorted, de-duplicated grant-target directories for\n * those that are outside the allowed roots AND grantable (within FS_ROOT_BOUNDARY\n * when it is configured). A path whose nearest existing ancestor escapes the\n * boundary is NOT grantable and is omitted — the operation will fail with\n * ACCESS_DENIED for it rather than prompt. The caller returns an\n * `input_required` result carrying exactly this set (R7), and on retry applies\n * each accepted grant via {@link applyGrant} (R8). `requestState` binds this\n * set so a grant accepted for X cannot authorize Y (R9).\n */\n async precheckAccess(paths: readonly string[]): Promise<string[]> {\n if (!this.allowedDirectoriesState || paths.length === 0) {\n return [];\n }\n const allowedDirs = this.allowedDirectoriesState;\n const grantDirs: string[] = [];\n for (const requested of paths) {\n if (!requested) {\n continue;\n }\n const normalized = normalizePath(requested);\n if (isPathWithinDirectories(normalized, allowedDirs)) {\n continue;\n }\n const targetDir = normalizePath(await this.resolveGrantTargetDir(normalized));\n // Never offer a grant into a bare filesystem root or an unsafe path (home,\n // /etc, C:\\Windows, ...). Without FS_ROOT_BOUNDARY, isWithinBoundary returns\n // true for everything, so this is the one guard that still rejects roots a\n // misleading grant could reach. Mirrors the check gating --allow-cwd.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n continue;\n }\n if (grantDirs.includes(targetDir)) {\n continue;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n continue;\n }\n grantDirs.push(targetDir);\n }\n return grantDirs.sort();\n }\n\n /**\n * Apply an accepted access grant: enforce FS_ROOT_BOUNDARY again (a TOCTOU\n * re-check against the boundary resolved at config time), then extend the\n * allowed roots for the remainder of the session (R8, A4). Returns false when\n * the boundary or the unsafe-path denylist blocks the grant, AND when the\n * recompute did not actually admit the directory — the return value now\n * reports what the guard's allowed set really holds, not merely that the\n * pre-checks passed. The caller leaves a refused path to fail with\n * ACCESS_DENIED during the operation. Idempotent: re-granting an already\n * allowed directory is a no-op via the dedup in `initialize`.\n */\n async applyGrant(targetDir: string): Promise<boolean> {\n // Defense-in-depth: even a tampered/accepted grant cannot extend roots into\n // an unsafe path. The precheckAccess guard already refuses to offer these;\n // this catches a grant that arrived by another route — the legacy stdio\n // `roots/list` seeding, which has no confirmation round-trip at all.\n if (await this.isUnsafeGrantTarget(targetDir)) {\n return false;\n }\n if (!(await this.isWithinBoundary(targetDir))) {\n return false;\n }\n // Read + write under the mutation lock so a concurrent grant cannot\n // interleave and lose this grant (GRANT-1). runExclusive is not reentrant:\n // nothing in this body may take the lock again.\n return this.runExclusive(async () => {\n const previous = this.grantedDirectories;\n this.grantedDirectories = [...previous, normalizePath(targetDir)];\n try {\n await this.recomputeAllowedDirectories();\n } catch (error) {\n // A failed recompute leaves the guard with its previous, consistent view.\n this.grantedDirectories = previous;\n throw error;\n }\n // Verify rather than assume: a boundary that no longer covers this\n // directory would drop it in the recompute above, and reporting success\n // for a grant that did not land is exactly the failure this replaces.\n if (isPathWithinDirectories(normalizePath(targetDir), this.getAllowedDirectories())) {\n return true;\n }\n this.grantedDirectories = previous;\n await this.recomputeAllowedDirectories();\n return false;\n });\n }\n\n // The guard already realpath-resolved FS_ROOT_BOUNDARY into rootBoundaries\n // during recomputeAllowedDirectories. Reuse that single source of truth so\n // grant paths check the same boundary the rest of the guard enforces,\n // instead of re-reading the env and re-resolving each entry.\n private async isWithinBoundary(targetDir: string): Promise<boolean> {\n if (this.rootBoundaries.length === 0) {\n return true;\n }\n let resolved: string;\n try {\n resolved = normalizePath(await realpath(targetDir));\n } catch {\n resolved = normalizePath(targetDir);\n }\n return isPathWithinDirectories(resolved, this.rootBoundaries);\n }\n\n private validateAccessAndSensitivity(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n const result = this.validateAccess(requestedPath);\n this.assertNotSensitiveFile(requestedPath, requestedPath);\n this.assertNotSensitiveFile(result.normalizedRequested, requestedPath);\n return result;\n }\n\n // Synchronous since the access-grant round-trip moved to the executor's\n // pre-check: validateAccess only does lexical containment math and throws,\n // no async I/O remains. Callers still `await` it for uniform control-flow;\n // awaiting a non-thenable returns it unchanged.\n private validateAccess(requestedPath: string): {\n normalizedRequested: string;\n allowedDirs: string[];\n accessDeniedHint: string;\n } {\n if (!this.allowedDirectoriesState) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'PathGuard not initialized. Call initialize() first.',\n requestedPath,\n );\n }\n if (isWindowsDriveRelativePath(requestedPath)) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Drive-relative paths are not allowed. Use C:\\\\path or C:/path instead of C:path.',\n requestedPath,\n );\n }\n const reservedDevice = getReservedDeviceNameForPath(requestedPath);\n if (reservedDevice) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n `Reserved Windows device name not allowed: ${reservedDevice}.`,\n requestedPath,\n );\n }\n\n const normalizedRequested = normalizePath(requestedPath);\n const allowedDirs = this.allowedDirectoriesState;\n\n const accessDeniedHint =\n allowedDirs.length > 0\n ? `Allowed: ${allowedDirs.join(', ')}`\n : 'No allowed directories configured.';\n\n if (!isPathWithinDirectories(normalizedRequested, allowedDirs)) {\n // Out of root. The access-grant `input_required` round-trip is driven by\n // the executor's pre-check (precheckAccess) BEFORE the operation runs, so\n // by the time validation reaches here any grantable out-of-root path has\n // already been accepted and added to the allowed set. A path still out of\n // root here was either declined, ungrantable (outside FS_ROOT_BOUNDARY), or\n // never pre-checked — fail closed.\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n return {\n normalizedRequested,\n allowedDirs: this.allowedDirectoriesState,\n accessDeniedHint,\n };\n }\n\n private async handleRealpathError(\n error: unknown,\n normalizedRequested: string,\n allowedDirs: string[],\n accessDeniedHint: string,\n requestedPath: string,\n ): Promise<never> {\n if (isNotFoundErrno(error)) {\n // Resolve the nearest existing ancestor to detect out-of-sandbox symlinks.\n // e.g. if `link -> C:\\external` and path is `link\\nonexistent.txt`, the\n // ancestor resolves outside allowed dirs → ACCESS_DENIED, not NOT_FOUND.\n try {\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n } catch (ancestorErr) {\n // Rethrow any FsError — collapsing e.g. UNKNOWN to NOT_FOUND would mask\n // incomplete sandbox checks and make bugs invisible to callers.\n if (isFsError(ancestorErr)) {\n throw ancestorErr;\n }\n }\n\n throw new FsError(ErrorCode.NOT_FOUND, 'Path not found', requestedPath, error);\n }\n\n const mapped =\n isNodeError(error) && error.code !== undefined ? ERRNO_MAP[error.code] : undefined;\n throw new FsError(\n mapped ?? ErrorCode.UNKNOWN,\n 'Cannot access path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n async validateExistingPathDetailed(requestedPath: string): Promise<ValidatedPathDetails> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n let realPath: string;\n try {\n realPath = await realpath(normalizedRequested);\n } catch (error) {\n realPath = await this.handleRealpathError(\n error,\n normalizedRequested,\n allowedDirs,\n accessDeniedHint,\n requestedPath,\n );\n }\n\n const normalizedReal = normalizePath(realPath);\n\n if (!isPathWithinDirectories(normalizedReal, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Re-check the resolved real path: a symlink inside an allowed root may\n // point at a sensitive file (e.g. link -> .env). The early check above only\n // sees the requested/normalized path, not the symlink target.\n this.assertNotSensitiveFile(normalizedReal, requestedPath);\n\n return {\n requestedPath: normalizedRequested,\n resolvedPath: normalizedReal,\n isSymlink: !isSamePath(normalizedRequested, normalizedReal),\n };\n }\n\n async validateExistingDirectory(requestedPath: string): Promise<string> {\n const details = await this.validateExistingPathDetailed(requestedPath);\n\n let stats: Stats;\n try {\n stats = await stat(details.resolvedPath);\n } catch (error) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot access directory',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n\n if (!stats.isDirectory()) {\n throw new FsError(ErrorCode.NOT_DIRECTORY, 'Not a directory', requestedPath);\n }\n\n return details.resolvedPath;\n }\n\n resolvePathOrRoot(pathValue: string | undefined): string {\n if (pathValue && pathValue.trim().length > 0) {\n return pathValue;\n }\n const roots = this.getAllowedDirectories();\n if (roots.length === 0) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'No roots configured. Use the roots tool or --allow-cwd.',\n );\n }\n if (roots.length > 1) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'Multiple roots configured. Provide an explicit path.',\n );\n }\n const root = roots[0];\n if (!root) {\n throw new FsError(ErrorCode.ACCESS_DENIED, 'Workspace root is unexpectedly undefined');\n }\n return root;\n }\n\n isAllowedRoot(normalizedPath: string): boolean {\n // isSamePath case-folds on case-insensitive filesystems (win + darwin),\n // matching the containment checks used everywhere else in the guard. The\n // previous IS_WINDOWS-only fold left darwin doing exact-case compares here\n // while isPathInsideDirectory folded — a root matched case-insensitively\n // everywhere else was missed.\n return this.getAllowedDirectories().some((dir) => isSamePath(dir, normalizedPath));\n }\n\n // Checks ONLY the sensitive-file denylist. Root containment and symlink\n // resolution must be verified separately (e.g. via validateExistingPath).\n private assertNotSensitiveFile(checkPath: string, requestedPath: string): void {\n if (this.isSensitive(checkPath)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Sensitive file blocked. Set ALLOW_SENSITIVE=1 to override.',\n requestedPath,\n );\n }\n }\n\n private throwAccessDenied(requestedPath: string, hint?: string): never {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n hint ? `Outside allowed directories. ${hint}` : 'Outside allowed directories.',\n requestedPath,\n );\n }\n private async resolveNearestExistingAncestor(\n requestedPath: string,\n currentPath: string,\n ): Promise<{ realAncestor: string; resolvedTarget: string }> {\n const missingSegments: string[] = [];\n let current = currentPath;\n for (;;) {\n try {\n const realAncestor = normalizePath(await realpath(current));\n const resolvedTarget =\n missingSegments.length === 0\n ? realAncestor\n : normalizePath(join(realAncestor, ...missingSegments.reverse()));\n return { realAncestor, resolvedTarget };\n } catch (error) {\n try {\n const stats = await lstat(current);\n if (stats.isSymbolicLink()) {\n const target = await readlink(current);\n const resolvedTarget = isAbsolute(target) ? target : resolve(dirname(current), target);\n const normalizedTarget = normalizePath(resolvedTarget);\n const allowedDirs = this.getAllowedDirectories();\n if (!isPathWithinDirectories(normalizedTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath);\n }\n }\n } catch (lstatErr) {\n if (isFsError(lstatErr) && lstatErr.code === ErrorCode.ACCESS_DENIED) {\n throw lstatErr;\n }\n // ENOENT is expected during ancestor walk — the entry simply doesn't exist.\n // Any other error (EACCES, EIO, ELOOP) is unexpected; fail safe.\n if (!isNodeError(lstatErr) || lstatErr.code !== 'ENOENT') {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot probe symlink ancestor',\n requestedPath,\n lstatErr instanceof Error ? lstatErr : undefined,\n );\n }\n }\n const parent = dirname(current);\n if (parent === current) {\n throw new FsError(\n ErrorCode.UNKNOWN,\n 'Cannot resolve path',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n missingSegments.push(basename(current));\n current = parent;\n }\n }\n }\n\n async validatePathForWrite(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n const { realAncestor, resolvedTarget } = await this.resolveNearestExistingAncestor(\n requestedPath,\n normalizedRequested,\n );\n if (\n !isPathWithinDirectories(realAncestor, allowedDirs) ||\n !isPathWithinDirectories(resolvedTarget, allowedDirs)\n ) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n // Re-check the resolved target: a symlink inside an allowed root may point\n // at a sensitive file. Writing through such a link must be blocked too.\n this.assertNotSensitiveFile(resolvedTarget, requestedPath);\n return resolvedTarget as ValidatedPath;\n }\n\n async validatePathForDelete(requestedPath: string): Promise<ValidatedPath> {\n const { normalizedRequested, allowedDirs, accessDeniedHint } =\n this.validateAccessAndSensitivity(requestedPath);\n\n // A workspace root is refused here, before the parent-containment check\n // below reaches for a parent that is out-of-root by construction and\n // reports \"Outside allowed directories\" for the one directory the caller\n // can see IS allowed. delete-file.ts keeps its own root check for the\n // nested-root case, where the parent is itself an allowed root and this\n // path is never taken.\n if (this.isAllowedRoot(normalizedRequested)) {\n throw new FsError(\n ErrorCode.ACCESS_DENIED,\n 'Deleting a workspace root directory is not allowed',\n requestedPath,\n );\n }\n\n const parent = dirname(normalizedRequested);\n let realParent: string;\n try {\n realParent = await realpath(parent);\n } catch (error) {\n throw new FsError(\n ErrorCode.NOT_FOUND,\n 'Parent directory not found',\n requestedPath,\n error instanceof Error ? error : undefined,\n );\n }\n const normalizedRealParent = normalizePath(realParent);\n\n if (!isPathWithinDirectories(normalizedRealParent, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n\n // Resolve the final component when it exists. For deletion, we ONLY\n // block if the real target is outside the sandbox IF the target is\n // NOT a symlink. Deleting a symlink is safe even if it points outside.\n try {\n const stats = await lstat(normalizedRequested);\n if (stats.isSymbolicLink()) {\n // Symlink: check link sensitivity but don't resolve target.\n // The parent check above ensures the link itself is in an allowed root.\n this.assertNotSensitiveFile(normalizedRequested, requestedPath);\n return normalizedRequested as ValidatedPath;\n }\n\n // Not a symlink: resolve to catch path escapes (e.g. /allowed/dir/../../etc)\n // and block sensitive files.\n const realTarget = normalizePath(await realpath(normalizedRequested));\n if (!isPathWithinDirectories(realTarget, allowedDirs)) {\n this.throwAccessDenied(requestedPath, accessDeniedHint);\n }\n this.assertNotSensitiveFile(realTarget, requestedPath);\n return realTarget as ValidatedPath;\n } catch (error) {\n // A denial raised inside this block (out-of-root real target, or a\n // sensitive file reached through a symlinked parent) must propagate.\n // Only a probe failure — ENOENT and friends — falls through to the\n // parent check, which is sufficient for a path that does not exist.\n if (isFsError(error)) {\n throw error;\n }\n }\n return normalizedRequested as ValidatedPath;\n }\n\n async recomputeAllowedDirectories(): Promise<void> {\n const cliAllowedDirs = normalizeAllowedDirectories(this.options?.cliAllowedDirs ?? []);\n\n // Parse allowed directories from environment variable\n const allowMissing =\n cli.allowMissingRoots ??\n parseTrueEnvFlag(process.env['FS_ALLOW_MISSING_ROOTS'], 'FS_ALLOW_MISSING_ROOTS');\n const envAllowedDirs = await resolveConfiguredDirs('FS_ALLOWED_DIRS', { allowMissing });\n\n // Parse FS_ROOT_BOUNDARY (the --root-boundary flag beats the env var)\n const boundaries = await resolveConfiguredDirs('FS_ROOT_BOUNDARY', {\n resolveReal: true,\n ...(cli.rootBoundary !== undefined ? { rawValue: cli.rootBoundary } : {}),\n });\n\n const allowCwd = Boolean(this.options?.allowCwd);\n const allowCwdDirs: string[] = [];\n if (allowCwd) {\n let cwd = normalizePath(process.cwd());\n const walkCwd =\n cli.allowCwdWalk ?? parseTrueEnvFlag(process.env['FS_ALLOW_CWD_WALK'], 'FS_ALLOW_CWD_WALK');\n if (walkCwd) {\n cwd = await findProjectRoot(cwd, [...boundaries, homedir()]);\n }\n if (isUnsafeCwdPath(cwd)) {\n Logger.emit(\n 'warning',\n `Skipped adding unsafe current working directory to allowed list: ${cwd}`,\n );\n } else {\n allowCwdDirs.push(cwd);\n }\n }\n\n const baseline = [...cliAllowedDirs, ...envAllowedDirs, ...allowCwdDirs];\n\n const signal = AbortSignal.timeout(ROOTS_TIMEOUT_MS);\n // FS_ROOT_BOUNDARY is the only filter grants answer to (see\n // `grantedDirectories`); without one they pass through as accepted.\n const grantsToInclude =\n boundaries.length > 0\n ? await filterRootsWithin(this.grantedDirectories, boundaries, signal)\n : this.grantedDirectories;\n\n const combined = [...baseline, ...grantsToInclude];\n const nextState = await resolveAllowedDirectoriesState(combined, signal);\n // Commit boundaries and the allowed set together, after every await has\n // resolved, so a rejecting recompute leaves the guard's previous,\n // consistent view intact.\n this.rootBoundaries = boundaries;\n this.initialize(nextState);\n }\n}\n"]}
|
|
@@ -12,6 +12,13 @@ export interface DirentLike {
|
|
|
12
12
|
isSymbolicLink(): boolean;
|
|
13
13
|
}
|
|
14
14
|
export declare function resolveEntryType(dirent: DirentLike): EntryType;
|
|
15
|
+
/**
|
|
16
|
+
* Warn once per (setting, value) that a configured value was rejected, and say
|
|
17
|
+
* what was used instead. console.error, not Logger: this module stays
|
|
18
|
+
* dependency-free to avoid import cycles, and a startup misconfiguration is
|
|
19
|
+
* worth printing even when the operator asked for errors only.
|
|
20
|
+
*/
|
|
21
|
+
export declare function warnInvalidSetting(name: string, value: string, expected: string, fallback: string | number | boolean): void;
|
|
15
22
|
/**
|
|
16
23
|
* Parse a boolean env flag: `true`/`1` enable, `false`/`0`/empty disable.
|
|
17
24
|
* Any other value warns once per var (when `name` is given) and reads as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/core/primitives.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,2EAA2E;AAC3E,eAAO,MAAM,WAAW,oDAAqD,CAAC;AAC9E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,4FAA4F;AAC5F,MAAM,WAAW,UAAU;IACzB,WAAW,IAAI,OAAO,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC;IAClB,cAAc,IAAI,OAAO,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAK9D;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/core/primitives.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,2EAA2E;AAC3E,eAAO,MAAM,WAAW,oDAAqD,CAAC;AAC9E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,4FAA4F;AAC5F,MAAM,WAAW,UAAU;IACzB,WAAW,IAAI,OAAO,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC;IAClB,cAAc,IAAI,OAAO,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAK9D;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAClC,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAQlF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAM9D;AAID,eAAO,MAAM,UAAU,SAA+B,CAAC;AAEvD,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,OAAqC,CAAC;AAE7E,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,OACoB,CAAC;AAE5D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAqC,CAAC"}
|
package/dist/core/primitives.js
CHANGED
|
@@ -14,7 +14,20 @@ export function resolveEntryType(dirent) {
|
|
|
14
14
|
return 'symlink';
|
|
15
15
|
return 'other';
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const warnedSettings = new Set();
|
|
18
|
+
/**
|
|
19
|
+
* Warn once per (setting, value) that a configured value was rejected, and say
|
|
20
|
+
* what was used instead. console.error, not Logger: this module stays
|
|
21
|
+
* dependency-free to avoid import cycles, and a startup misconfiguration is
|
|
22
|
+
* worth printing even when the operator asked for errors only.
|
|
23
|
+
*/
|
|
24
|
+
export function warnInvalidSetting(name, value, expected, fallback) {
|
|
25
|
+
const key = `${name}:${value}`;
|
|
26
|
+
if (warnedSettings.has(key))
|
|
27
|
+
return;
|
|
28
|
+
warnedSettings.add(key);
|
|
29
|
+
console.error(`[warning] Invalid ${name} value: ${value} (must be ${expected}). Using default: ${String(fallback)}`);
|
|
30
|
+
}
|
|
18
31
|
/**
|
|
19
32
|
* Parse a boolean env flag: `true`/`1` enable, `false`/`0`/empty disable.
|
|
20
33
|
* Any other value warns once per var (when `name` is given) and reads as
|
|
@@ -27,13 +40,7 @@ export function parseTrueEnvFlag(value, name) {
|
|
|
27
40
|
if (trimmed === 'true' || trimmed === '1')
|
|
28
41
|
return true;
|
|
29
42
|
if (name && trimmed !== '' && trimmed !== 'false' && trimmed !== '0') {
|
|
30
|
-
|
|
31
|
-
if (!warnedFlagValues.has(key)) {
|
|
32
|
-
warnedFlagValues.add(key);
|
|
33
|
-
// console.error, not Logger: this module stays dependency-free to avoid
|
|
34
|
-
// import cycles (same precedent as parseLogLevel in observability.ts).
|
|
35
|
-
console.error(`[warning] Invalid ${name} value: ${value} (must be "true" or "1"). Using default: false`);
|
|
36
|
-
}
|
|
43
|
+
warnInvalidSetting(name, value, '"true" or "1"', false);
|
|
37
44
|
}
|
|
38
45
|
return false;
|
|
39
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/core/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;GAGG;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AAU9E,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,IAAI,MAAM,CAAC,WAAW,EAAE;QAAE,OAAO,WAAW,CAAC;IAC7C,IAAI,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,MAAM,CAAC;IACnC,IAAI,MAAM,CAAC,cAAc,EA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,CAAC","sourcesContent":["import { delimiter } from 'node:path';\n\n/**\n * Minimal shared primitives with no intra-package dependencies.\n * Kept separate to avoid import cycles between observability.ts and util.ts.\n */\n\n/** The four filesystem entry types; published as the `FileType` schema. */\nexport const ENTRY_TYPES = ['file', 'directory', 'symlink', 'other'] as const;\nexport type EntryType = (typeof ENTRY_TYPES)[number];\n\n/** The three predicates both `Dirent` and `Stats` expose - all `resolveEntryType` needs. */\nexport interface DirentLike {\n isDirectory(): boolean;\n isFile(): boolean;\n isSymbolicLink(): boolean;\n}\n\nexport function resolveEntryType(dirent: DirentLike): EntryType {\n if (dirent.isDirectory()) return 'directory';\n if (dirent.isFile()) return 'file';\n if (dirent.isSymbolicLink()) return 'symlink';\n return 'other';\n}\n\nconst warnedSettings = new Set<string>();\n\n/**\n * Warn once per (setting, value) that a configured value was rejected, and say\n * what was used instead. console.error, not Logger: this module stays\n * dependency-free to avoid import cycles, and a startup misconfiguration is\n * worth printing even when the operator asked for errors only.\n */\nexport function warnInvalidSetting(\n name: string,\n value: string,\n expected: string,\n fallback: string | number | boolean,\n): void {\n const key = `${name}:${value}`;\n if (warnedSettings.has(key)) return;\n warnedSettings.add(key);\n console.error(\n `[warning] Invalid ${name} value: ${value} (must be ${expected}). Using default: ${String(fallback)}`,\n );\n}\n\n/**\n * Parse a boolean env flag: `true`/`1` enable, `false`/`0`/empty disable.\n * Any other value warns once per var (when `name` is given) and reads as\n * false, so a typo like `FS_ALLOW_SENSITIVE=yes` is never silent.\n */\nexport function parseTrueEnvFlag(value: string | undefined, name?: string): boolean {\n if (value === undefined) return false;\n const trimmed = value.trim().toLowerCase();\n if (trimmed === 'true' || trimmed === '1') return true;\n if (name && trimmed !== '' && trimmed !== 'false' && trimmed !== '0') {\n warnInvalidSetting(name, value, '\"true\" or \"1\"', false);\n }\n return false;\n}\n\nexport function escapeRegexLiteral(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function splitDirList(val: string | undefined): string[] {\n if (!val) return [];\n return val\n .split(delimiter)\n .map((p) => p.trim())\n .filter((p) => p.length > 0);\n}\n\n// ─── Path primitives (moved from path.ts to break the path↔sensitive cycle) ──\n\nexport const IS_WINDOWS = process.platform === 'win32';\n\nexport const isSlash = (code: number): boolean => code === 47 || code === 92;\n\nexport const isAlpha = (code: number): boolean =>\n (code >= 65 && code <= 90) || (code >= 97 && code <= 122);\n\nexport const toPosixPath = (value: string): string => value.replaceAll('\\\\', '/');\n"]}
|
package/dist/core/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAwC,OAAO,EAAa,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAwC,OAAO,EAAa,MAAM,aAAa,CAAC;AA4DvF,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,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,EACrB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,KAAG,MAI5C,CAAC;AA8ZF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAIpE;AAED,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,cAAc,CAAC,CAWzB;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,QAAQ,GAAG,SAAS,GACzB,OAAO,CAAC,cAAc,CAAC,CAEzB"}
|
package/dist/core/read.js
CHANGED
|
@@ -59,12 +59,6 @@ import { Logger } from './observability.js';
|
|
|
59
59
|
import { getMaxTextFileSize } from './util.js';
|
|
60
60
|
const STREAM_CHUNK_SIZE = 64 * 1024;
|
|
61
61
|
const READ_ONLY_FILE_FLAG = 'r';
|
|
62
|
-
function assertPositiveIntegerOption(name, value, message) {
|
|
63
|
-
if (value === undefined ||
|
|
64
|
-
(typeof value === 'number' && Number.isSafeInteger(value) && value >= 1))
|
|
65
|
-
return;
|
|
66
|
-
throw new FsError(ErrorCode.INVALID_INPUT, message ?? `${name} must be a positive integer`);
|
|
67
|
-
}
|
|
68
62
|
async function openReadableFileHandle(filePath, signal) {
|
|
69
63
|
const handlePromise = fsOpen(filePath, READ_ONLY_FILE_FLAG);
|
|
70
64
|
if (!signal)
|
|
@@ -123,31 +117,20 @@ function buildBaseOptions(spec) {
|
|
|
123
117
|
...(spec.signal ? { signal: spec.signal } : {}),
|
|
124
118
|
};
|
|
125
119
|
}
|
|
126
|
-
function normalizeRangeSpec(spec, base) {
|
|
127
|
-
assertPositiveIntegerOption('start', spec.start, 'start must be at least 1');
|
|
128
|
-
if (spec.end !== undefined) {
|
|
129
|
-
assertPositiveIntegerOption('end', spec.end, 'end must be at least 1');
|
|
130
|
-
if (spec.end < spec.start) {
|
|
131
|
-
throw new FsError(ErrorCode.INVALID_INPUT, 'end must be greater than or equal to start (default: 1)');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
...base,
|
|
136
|
-
kind: 'range',
|
|
137
|
-
start: spec.start,
|
|
138
|
-
...(spec.end !== undefined ? { end: spec.end } : {}),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
120
|
export function normalizeSpec(spec) {
|
|
142
121
|
const base = buildBaseOptions(spec);
|
|
143
122
|
spec.signal?.throwIfAborted();
|
|
144
123
|
switch (spec.kind) {
|
|
145
124
|
case 'head':
|
|
146
125
|
case 'tail':
|
|
147
|
-
assertPositiveIntegerOption('lines', spec.lines, 'lines must be at least 1');
|
|
148
126
|
return { ...base, kind: spec.kind, lines: spec.lines };
|
|
149
127
|
case 'range':
|
|
150
|
-
return
|
|
128
|
+
return {
|
|
129
|
+
...base,
|
|
130
|
+
kind: 'range',
|
|
131
|
+
start: spec.start,
|
|
132
|
+
...(spec.end !== undefined ? { end: spec.end } : {}),
|
|
133
|
+
};
|
|
151
134
|
case 'full':
|
|
152
135
|
return { ...base, kind: 'full' };
|
|
153
136
|
default: {
|
package/dist/core/read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,yBAAyB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M,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;QAE9B,OAAO,MAAM,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;CACvE;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,SAAiB,EACjB,KAAY,EACZ,IAA0B;IAE1B,OAAO,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["// File reading pipeline split out of fs.ts. fs.ts imports from here; never the reverse.\nimport type { Stats } from 'node:fs';\nimport { open as fsOpen } from 'node:fs/promises';\nimport type { FileHandle } from 'node:fs/promises';\nimport { StringDecoder } from 'node:string_decoder';\n\nimport { withAbort } from './concurrency.js';\nimport { ErrorCode, formatUnknownErrorMessage, FsError, isFsError } from './errors.js';\nimport { isBinarySample, isKnownBinaryExtension, MIME_SAMPLE_SIZE } from './mime.js';\nimport { Logger } from './observability.js';\nimport { getMaxTextFileSize } from './util.js';\n\nconst STREAM_CHUNK_SIZE = 64 * 1024;\n\nconst READ_ONLY_FILE_FLAG = 'r';\n\nfunction assertPositiveIntegerOption(name: string, value: unknown, message?: string): void {\n if (\n value === undefined ||\n (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1)\n )\n return;\n throw new FsError(ErrorCode.INVALID_INPUT, message ?? `${name} must be a positive integer`);\n}\n\nasync function openReadableFileHandle(filePath: string, signal?: AbortSignal): Promise<FileHandle> {\n const handlePromise = fsOpen(filePath, READ_ONLY_FILE_FLAG);\n if (!signal) return handlePromise;\n try {\n return await withAbort(handlePromise, signal);\n } catch (error) {\n void handlePromise\n .then((handle) => {\n void handle.close().catch((closeErr: unknown) => {\n Logger.warn(\n `Failed to close file handle for ${filePath} after abort: ${formatUnknownErrorMessage(closeErr)}`,\n );\n });\n })\n .catch(() => {\n /* ignore open error */\n });\n throw error;\n }\n}\n\nasync function readProbe(handle: FileHandle, signal?: AbortSignal): Promise<Buffer> {\n const buffer = Buffer.allocUnsafe(MIME_SAMPLE_SIZE);\n const { bytesRead } = await withAbort(handle.read(buffer, 0, MIME_SAMPLE_SIZE, 0), signal);\n\n if (bytesRead === 0) {\n return Buffer.alloc(0);\n }\n\n return buffer.subarray(0, bytesRead);\n}\n\nasync function isProbablyBinary(\n filePath: string,\n existingHandle?: FileHandle,\n signal?: AbortSignal,\n): Promise<boolean> {\n if (isKnownBinaryExtension(filePath)) {\n return true;\n }\n\n if (existingHandle) {\n const slice = await readProbe(existingHandle, signal);\n return isBinarySample(slice);\n }\n\n await using handle = await openReadableFileHandle(filePath, signal);\n const slice = await readProbe(handle, signal);\n return isBinarySample(slice);\n}\n\nexport type ReadSpec =\n | { kind: 'full'; signal?: AbortSignal }\n | { kind: 'head'; lines: number; signal?: AbortSignal }\n | { kind: 'tail'; lines: number; signal?: AbortSignal }\n | { kind: 'range'; start: number; end?: number; signal?: AbortSignal };\n\ninterface NormalizedBase {\n maxSize: number;\n signal?: AbortSignal;\n}\n\ntype NormalizedSpec =\n | (NormalizedBase & { kind: 'full' })\n | (NormalizedBase & { kind: 'head'; lines: number })\n | (NormalizedBase & { kind: 'tail'; lines: number })\n | (NormalizedBase & { kind: 'range'; start: number; end?: number });\n\ninterface PartialReadResult {\n content: string;\n linesRead: number;\n hasMoreLines: boolean;\n}\n\nexport interface ReadFileResult {\n path: string;\n content: string;\n totalLines?: number;\n readMode: ReadSpec['kind'];\n head?: number;\n tail?: number;\n startLine?: number;\n endLine?: number;\n linesRead?: number;\n hasMoreLines?: boolean;\n}\n\nfunction buildBaseOptions(spec: ReadSpec): NormalizedBase {\n return {\n maxSize: getMaxTextFileSize(),\n ...(spec.signal ? { signal: spec.signal } : {}),\n };\n}\n\nfunction normalizeRangeSpec(\n spec: Extract<ReadSpec, { kind: 'range' }>,\n base: NormalizedBase,\n): NormalizedSpec {\n assertPositiveIntegerOption('start', spec.start, 'start must be at least 1');\n if (spec.end !== undefined) {\n assertPositiveIntegerOption('end', spec.end, 'end must be at least 1');\n if (spec.end < spec.start) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n 'end must be greater than or equal to start (default: 1)',\n );\n }\n }\n return {\n ...base,\n kind: 'range',\n start: spec.start,\n ...(spec.end !== undefined ? { end: spec.end } : {}),\n };\n}\n\nexport function normalizeSpec(spec: ReadSpec): NormalizedSpec {\n const base = buildBaseOptions(spec);\n spec.signal?.throwIfAborted();\n\n switch (spec.kind) {\n case 'head':\n case 'tail':\n assertPositiveIntegerOption('lines', spec.lines, 'lines must be at least 1');\n return { ...base, kind: spec.kind, lines: spec.lines };\n case 'range':\n return normalizeRangeSpec(spec, base);\n case 'full':\n return { ...base, kind: 'full' };\n default: {\n const _exhaustive: never = spec;\n return _exhaustive;\n }\n }\n}\n\nexport function createTooLargeError(\n bytesRead: number,\n maxSize: number,\n requestedPath: string,\n): FsError {\n return new FsError(\n ErrorCode.TOO_LARGE,\n `File exceeds size limit (${bytesRead} > ${maxSize} bytes)`,\n requestedPath,\n );\n}\n\nexport async function readFileBufferWithLimit(\n handle: FileHandle,\n maxSize: number,\n requestedPath: string,\n signal?: AbortSignal,\n): Promise<Buffer> {\n const stream = handle.createReadStream({\n start: 0,\n highWaterMark: STREAM_CHUNK_SIZE,\n autoClose: false,\n emitClose: false,\n signal,\n });\n\n const chunks: Buffer[] = [];\n let totalSize = 0;\n\n try {\n for await (const chunk of stream) {\n const buffer = chunk as Buffer;\n totalSize += buffer.length;\n\n if (totalSize > maxSize) {\n stream.destroy();\n throw createTooLargeError(totalSize, maxSize, requestedPath);\n }\n\n chunks.push(buffer);\n }\n } finally {\n if (!stream.destroyed) {\n stream.on('error', (_err: unknown) => {\n /* suppress post-destroy error event */\n });\n stream.destroy();\n }\n }\n\n return Buffer.concat(chunks, totalSize);\n}\n\nexport const countLines = (content: string): number => {\n if (content.length === 0) return 0;\n const trimmed = content.endsWith('\\n') ? content.slice(0, -1) : content;\n return trimmed.split('\\n').length;\n};\n\nasync function peekHasMore(iterator: AsyncIterator<string>): Promise<boolean> {\n try {\n const { done } = await iterator.next();\n return !done;\n } catch (error) {\n // The peek only asks \"is there another line\", and the caller keeps nothing\n // it returns. An over-long line past the requested range still answers yes\n // — failing the whole read over a line outside it would reject e.g. lines\n // 1-2 of a file whose line 3 is one 50 KB blob.\n if (isFsError(error) && error.code === ErrorCode.TOO_LARGE) return true;\n throw error;\n }\n}\n\nconst LF = 0x0a;\n\nfunction stripCarriageReturn(line: string): string {\n return line.endsWith('\\r') ? line.slice(0, -1) : line;\n}\n\n/**\n * Line iterator bounded by bytes rather than by the decoded string, so a file\n * that is one enormous line cannot be materialized before the size check runs.\n * `handle.readLines` decodes the whole line first and can OOM on such a file.\n *\n * Yields lines from `startLine` onward, 1-indexed. Lines before `startLine` are\n * counted and discarded without accumulating, so an over-long line the caller\n * skipped past does not fail the read. Line endings match `readLines`: split on\n * `\\n`, with a preceding `\\r` stripped, so CRLF input decodes identically.\n */\nasync function* readLinesBounded(\n handle: FileHandle,\n options: NormalizedBase,\n filePath: string,\n startLine: number,\n): AsyncGenerator<string, void, undefined> {\n const stream = handle.createReadStream({\n start: 0,\n highWaterMark: STREAM_CHUNK_SIZE,\n autoClose: false,\n emitClose: false,\n ...(options.signal ? { signal: options.signal } : {}),\n });\n\n const decoder = new StringDecoder('utf-8');\n let pending = '';\n let pendingBytes = 0;\n let lineNumber = 0;\n\n const tooLong = (bytes: number): FsError =>\n new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (single line ${bytes} > ${options.maxSize} bytes). Use a narrower range or head.`,\n filePath,\n );\n\n try {\n for await (const chunk of stream) {\n const buffer = chunk as Buffer;\n let offset = 0;\n\n // Search loop: each iteration finds the next LF and advances offset past\n // it. Written as while-with-assignment so the re-search is visible, rather\n // than buried in a for \"increment\" slot that re-runs indexOf.\n let nl = buffer.indexOf(LF, offset);\n while (nl !== -1) {\n const segment = buffer.subarray(offset, nl);\n const lineBytes = pendingBytes + segment.length;\n lineNumber++;\n // Decode even when skipping: the decoder carries multi-byte\n // continuation state into the first line the caller keeps.\n const decoded = decoder.write(segment);\n if (lineNumber >= startLine) {\n if (lineBytes > options.maxSize) throw tooLong(lineBytes);\n yield stripCarriageReturn(pending + decoded);\n }\n pending = '';\n pendingBytes = 0;\n offset = nl + 1;\n nl = buffer.indexOf(LF, offset);\n }\n\n const rest = buffer.subarray(offset);\n pendingBytes += rest.length;\n if (lineNumber + 1 < startLine) {\n decoder.write(rest); // still skipping; drop the text, keep decoder state\n } else {\n if (pendingBytes > options.maxSize) throw tooLong(pendingBytes);\n pending += decoder.write(rest);\n }\n }\n\n // Trailing line with no final newline. A file ending in `\\n` leaves\n // pendingBytes at 0 and emits nothing, matching readLines.\n if (pendingBytes > 0) {\n lineNumber++;\n if (lineNumber >= startLine) {\n if (pendingBytes > options.maxSize) throw tooLong(pendingBytes);\n yield pending + decoder.end();\n }\n }\n } finally {\n if (!stream.destroyed) {\n stream.on('error', (_err: unknown) => {\n /* suppress post-destroy error event */\n });\n stream.destroy();\n }\n }\n}\n\nasync function readRangeContent(\n handle: FileHandle,\n startLine: number,\n endLine: number | undefined,\n options: NormalizedBase,\n filePath: string,\n): Promise<PartialReadResult> {\n options.signal?.throwIfAborted();\n\n const lines: string[] = [];\n let lineNumber = startLine - 1;\n let estimatedBytes = 0;\n const newlineBytes = Buffer.byteLength('\\n', 'utf-8');\n const stopAt = endLine ?? Number.POSITIVE_INFINITY;\n\n let hasMoreLines = false;\n\n // Byte-bounded: an over-long line throws TOO_LARGE while still a partial\n // buffer, before it can be decoded into one huge string.\n const iterator = readLinesBounded(handle, options, filePath, startLine)[Symbol.asyncIterator]();\n\n try {\n for (;;) {\n const { value: line, done } = await iterator.next();\n if (done) {\n break;\n }\n lineNumber++;\n\n if (lineNumber > stopAt) {\n hasMoreLines = true;\n break;\n }\n\n lines.push(line);\n\n estimatedBytes += Buffer.byteLength(line, 'utf-8') + newlineBytes;\n if (estimatedBytes > options.maxSize) {\n hasMoreLines = await peekHasMore(iterator);\n break;\n }\n\n if (lineNumber === stopAt) {\n hasMoreLines = await peekHasMore(iterator);\n break;\n }\n }\n } finally {\n await iterator.return();\n }\n\n return {\n content: lines.join('\\n'),\n linesRead: lines.length,\n hasMoreLines,\n };\n}\n\nasync function readTailContent(\n handle: FileHandle,\n tail: number,\n options: NormalizedBase,\n filePath: string,\n): Promise<PartialReadResult> {\n options.signal?.throwIfAborted();\n\n const stats = await handle.stat();\n const fileSize = stats.size;\n if (fileSize === 0) {\n return {\n content: '',\n linesRead: 0,\n hasMoreLines: false,\n };\n }\n\n const encoding = 'utf-8';\n // Accumulate raw bytes from the end: decoding a chunk ending mid-codepoint\n // corrupts the trailing UTF-8 sequence into U+FFFD. 0x0A is single-byte and\n // never part of a multibyte sequence, so count newlines on the raw buffer and\n // decode the whole bounded buffer once at the end.\n let position = fileSize;\n const chunks: Buffer[] = [];\n let totalLen = 0;\n let newlines = 0;\n let stoppedByLimit = false;\n\n while (position > 0) {\n options.signal?.throwIfAborted();\n const chunkSize = Math.min(position, STREAM_CHUNK_SIZE);\n const buffer = Buffer.allocUnsafe(chunkSize);\n const { bytesRead } = await handle.read(buffer, 0, chunkSize, position - chunkSize);\n if (bytesRead < chunkSize) {\n // The file shrank under us. Bytes from `position` on are still a\n // contiguous suffix, so keep those and stop — splicing this short chunk in\n // would leave a hole (and, with an alloc'd buffer, NULs) mid-content.\n // `position` stays put, so the result is reported as having more lines.\n break;\n }\n position -= chunkSize;\n\n for (const byte of buffer) {\n if (byte === 0x0a) newlines++;\n }\n\n chunks.unshift(buffer);\n totalLen += chunkSize;\n\n // One newline more than `tail`: the oldest segment in the buffer starts\n // mid-line whenever we stop before the file start, and gets dropped below.\n if (newlines > tail) break;\n if (totalLen > options.maxSize) {\n stoppedByLimit = true;\n break;\n }\n }\n\n const allBytes = Buffer.concat(chunks, totalLen);\n let lines = allBytes.toString(encoding).split('\\n');\n\n // A trailing newline produces a spurious empty final segment; drop it.\n if (lines.length > 0 && lines[lines.length - 1] === '') {\n lines = lines.slice(0, -1);\n }\n // Normalize CRLF.\n lines = lines.map((l) => (l.endsWith('\\r') ? l.slice(0, -1) : l));\n\n // We stopped before the file start, so the first segment is the tail of a\n // line whose beginning was never read. Drop it instead of reporting a\n // fragment as a complete line.\n if (position > 0 && lines.length > 0) {\n lines = lines.slice(1);\n }\n\n if (stoppedByLimit && lines.length < tail) {\n throw new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (${totalLen} > ${options.maxSize} bytes, could not collect ${tail} lines). Use a narrower tail or head.`,\n filePath,\n );\n }\n\n let hasMoreLines = stoppedByLimit || position > 0;\n if (lines.length > tail) {\n hasMoreLines = true;\n lines = lines.slice(lines.length - tail);\n }\n\n const content = lines.join('\\n');\n return {\n content,\n linesRead: lines.length,\n hasMoreLines,\n };\n}\n\nasync function readFullContent(\n handle: FileHandle,\n maxSize: number,\n requestedPath: string,\n signal?: AbortSignal,\n): Promise<{ content: string; totalLines: number }> {\n const buffer = await readFileBufferWithLimit(handle, maxSize, requestedPath, signal);\n const content = buffer.toString('utf-8');\n return { content, totalLines: countLines(content) };\n}\n\nasync function assertNotBinary(\n validPath: string,\n filePath: string,\n handle: FileHandle,\n normalized: NormalizedBase,\n): Promise<void> {\n normalized.signal?.throwIfAborted();\n const isBinary = await isProbablyBinary(validPath, handle, normalized.signal);\n if (!isBinary) return;\n throw new FsError(ErrorCode.INVALID_INPUT, 'Binary file detected.', filePath);\n}\n\nfunction assertSizeWithinLimit(size: number, maxSize: number, filePath: string): void {\n if (size <= maxSize) return;\n throw new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (${size} > ${maxSize} bytes). Use head to preview.`,\n filePath,\n );\n}\n\ninterface ReadModeContext {\n handle: FileHandle;\n validPath: string;\n filePath: string;\n stats: Stats;\n spec: NormalizedSpec;\n}\n\nasync function readHead(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'head' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readRangeContent(\n context.handle,\n 1,\n spec.lines,\n spec,\n context.filePath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'head',\n head: spec.lines,\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readRange(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'range' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readRangeContent(\n context.handle,\n spec.start,\n spec.end,\n spec,\n context.filePath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'range',\n startLine: spec.start,\n ...(spec.end !== undefined ? { endLine: spec.end } : {}),\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readFull(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'full' }>,\n): Promise<ReadFileResult> {\n assertSizeWithinLimit(context.stats.size, spec.maxSize, context.filePath);\n const { content, totalLines } = await readFullContent(\n context.handle,\n spec.maxSize,\n context.filePath,\n spec.signal,\n );\n\n return {\n path: context.validPath,\n content,\n totalLines,\n readMode: 'full',\n linesRead: totalLines,\n hasMoreLines: false,\n };\n}\n\nasync function readTail(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'tail' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readTailContent(\n context.handle,\n spec.lines,\n spec,\n context.validPath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'tail',\n tail: spec.lines,\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readByMode(context: ReadModeContext): Promise<ReadFileResult> {\n switch (context.spec.kind) {\n case 'head':\n return readHead(context, context.spec);\n case 'range':\n return readRange(context, context.spec);\n case 'full':\n return readFull(context, context.spec);\n case 'tail':\n return readTail(context, context.spec);\n default: {\n const _exhaustive: never = context.spec;\n return _exhaustive;\n }\n }\n}\n\nexport function assertFileStats(filePath: string, stats: Stats): void {\n if (!stats.isFile()) {\n throw new FsError(ErrorCode.NOT_FILE, 'Not a regular file', filePath);\n }\n}\n\nexport async function readNormalized(\n filePath: string,\n validPath: string,\n stats: Stats,\n spec: NormalizedSpec,\n): Promise<ReadFileResult> {\n spec.signal?.throwIfAborted();\n\n assertFileStats(filePath, stats);\n\n await using handle = await openReadableFileHandle(validPath, spec.signal);\n\n await assertNotBinary(validPath, filePath, handle, spec);\n spec.signal?.throwIfAborted();\n\n return await readByMode({ handle, validPath, filePath, stats, spec });\n}\n\nexport async function readFileWithStats(\n filePath: string,\n validPath: string,\n stats: Stats,\n spec: ReadSpec | undefined,\n): Promise<ReadFileResult> {\n return readNormalized(filePath, validPath, stats, normalizeSpec(spec ?? { kind: 'full' }));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEpC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,KAAK,UAAU,sBAAsB,CAAC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eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;QAE9B,OAAO,MAAM,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;CACvE;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,SAAiB,EACjB,KAAY,EACZ,IAA0B;IAE1B,OAAO,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["// File reading pipeline split out of fs.ts. fs.ts imports from here; never the reverse.\nimport type { Stats } from 'node:fs';\nimport { open as fsOpen } from 'node:fs/promises';\nimport type { FileHandle } from 'node:fs/promises';\nimport { StringDecoder } from 'node:string_decoder';\n\nimport { withAbort } from './concurrency.js';\nimport { ErrorCode, formatUnknownErrorMessage, FsError, isFsError } from './errors.js';\nimport { isBinarySample, isKnownBinaryExtension, MIME_SAMPLE_SIZE } from './mime.js';\nimport { Logger } from './observability.js';\nimport { getMaxTextFileSize } from './util.js';\n\nconst STREAM_CHUNK_SIZE = 64 * 1024;\n\nconst READ_ONLY_FILE_FLAG = 'r';\n\nasync function openReadableFileHandle(filePath: string, signal?: AbortSignal): Promise<FileHandle> {\n const handlePromise = fsOpen(filePath, READ_ONLY_FILE_FLAG);\n if (!signal) return handlePromise;\n try {\n return await withAbort(handlePromise, signal);\n } catch (error) {\n void handlePromise\n .then((handle) => {\n void handle.close().catch((closeErr: unknown) => {\n Logger.warn(\n `Failed to close file handle for ${filePath} after abort: ${formatUnknownErrorMessage(closeErr)}`,\n );\n });\n })\n .catch(() => {\n /* ignore open error */\n });\n throw error;\n }\n}\n\nasync function readProbe(handle: FileHandle, signal?: AbortSignal): Promise<Buffer> {\n const buffer = Buffer.allocUnsafe(MIME_SAMPLE_SIZE);\n const { bytesRead } = await withAbort(handle.read(buffer, 0, MIME_SAMPLE_SIZE, 0), signal);\n\n if (bytesRead === 0) {\n return Buffer.alloc(0);\n }\n\n return buffer.subarray(0, bytesRead);\n}\n\nasync function isProbablyBinary(\n filePath: string,\n existingHandle?: FileHandle,\n signal?: AbortSignal,\n): Promise<boolean> {\n if (isKnownBinaryExtension(filePath)) {\n return true;\n }\n\n if (existingHandle) {\n const slice = await readProbe(existingHandle, signal);\n return isBinarySample(slice);\n }\n\n await using handle = await openReadableFileHandle(filePath, signal);\n const slice = await readProbe(handle, signal);\n return isBinarySample(slice);\n}\n\nexport type ReadSpec =\n | { kind: 'full'; signal?: AbortSignal }\n | { kind: 'head'; lines: number; signal?: AbortSignal }\n | { kind: 'tail'; lines: number; signal?: AbortSignal }\n | { kind: 'range'; start: number; end?: number; signal?: AbortSignal };\n\ninterface NormalizedBase {\n maxSize: number;\n signal?: AbortSignal;\n}\n\ntype NormalizedSpec =\n | (NormalizedBase & { kind: 'full' })\n | (NormalizedBase & { kind: 'head'; lines: number })\n | (NormalizedBase & { kind: 'tail'; lines: number })\n | (NormalizedBase & { kind: 'range'; start: number; end?: number });\n\ninterface PartialReadResult {\n content: string;\n linesRead: number;\n hasMoreLines: boolean;\n}\n\nexport interface ReadFileResult {\n path: string;\n content: string;\n totalLines?: number;\n readMode: ReadSpec['kind'];\n head?: number;\n tail?: number;\n startLine?: number;\n endLine?: number;\n linesRead?: number;\n hasMoreLines?: boolean;\n}\n\nfunction buildBaseOptions(spec: ReadSpec): NormalizedBase {\n return {\n maxSize: getMaxTextFileSize(),\n ...(spec.signal ? { signal: spec.signal } : {}),\n };\n}\n\nexport function normalizeSpec(spec: ReadSpec): NormalizedSpec {\n const base = buildBaseOptions(spec);\n spec.signal?.throwIfAborted();\n\n switch (spec.kind) {\n case 'head':\n case 'tail':\n return { ...base, kind: spec.kind, lines: spec.lines };\n case 'range':\n return {\n ...base,\n kind: 'range',\n start: spec.start,\n ...(spec.end !== undefined ? { end: spec.end } : {}),\n };\n case 'full':\n return { ...base, kind: 'full' };\n default: {\n const _exhaustive: never = spec;\n return _exhaustive;\n }\n }\n}\n\nexport function createTooLargeError(\n bytesRead: number,\n maxSize: number,\n requestedPath: string,\n): FsError {\n return new FsError(\n ErrorCode.TOO_LARGE,\n `File exceeds size limit (${bytesRead} > ${maxSize} bytes)`,\n requestedPath,\n );\n}\n\nexport async function readFileBufferWithLimit(\n handle: FileHandle,\n maxSize: number,\n requestedPath: string,\n signal?: AbortSignal,\n): Promise<Buffer> {\n const stream = handle.createReadStream({\n start: 0,\n highWaterMark: STREAM_CHUNK_SIZE,\n autoClose: false,\n emitClose: false,\n signal,\n });\n\n const chunks: Buffer[] = [];\n let totalSize = 0;\n\n try {\n for await (const chunk of stream) {\n const buffer = chunk as Buffer;\n totalSize += buffer.length;\n\n if (totalSize > maxSize) {\n stream.destroy();\n throw createTooLargeError(totalSize, maxSize, requestedPath);\n }\n\n chunks.push(buffer);\n }\n } finally {\n if (!stream.destroyed) {\n stream.on('error', (_err: unknown) => {\n /* suppress post-destroy error event */\n });\n stream.destroy();\n }\n }\n\n return Buffer.concat(chunks, totalSize);\n}\n\nexport const countLines = (content: string): number => {\n if (content.length === 0) return 0;\n const trimmed = content.endsWith('\\n') ? content.slice(0, -1) : content;\n return trimmed.split('\\n').length;\n};\n\nasync function peekHasMore(iterator: AsyncIterator<string>): Promise<boolean> {\n try {\n const { done } = await iterator.next();\n return !done;\n } catch (error) {\n // The peek only asks \"is there another line\", and the caller keeps nothing\n // it returns. An over-long line past the requested range still answers yes\n // — failing the whole read over a line outside it would reject e.g. lines\n // 1-2 of a file whose line 3 is one 50 KB blob.\n if (isFsError(error) && error.code === ErrorCode.TOO_LARGE) return true;\n throw error;\n }\n}\n\nconst LF = 0x0a;\n\nfunction stripCarriageReturn(line: string): string {\n return line.endsWith('\\r') ? line.slice(0, -1) : line;\n}\n\n/**\n * Line iterator bounded by bytes rather than by the decoded string, so a file\n * that is one enormous line cannot be materialized before the size check runs.\n * `handle.readLines` decodes the whole line first and can OOM on such a file.\n *\n * Yields lines from `startLine` onward, 1-indexed. Lines before `startLine` are\n * counted and discarded without accumulating, so an over-long line the caller\n * skipped past does not fail the read. Line endings match `readLines`: split on\n * `\\n`, with a preceding `\\r` stripped, so CRLF input decodes identically.\n */\nasync function* readLinesBounded(\n handle: FileHandle,\n options: NormalizedBase,\n filePath: string,\n startLine: number,\n): AsyncGenerator<string, void, undefined> {\n const stream = handle.createReadStream({\n start: 0,\n highWaterMark: STREAM_CHUNK_SIZE,\n autoClose: false,\n emitClose: false,\n ...(options.signal ? { signal: options.signal } : {}),\n });\n\n const decoder = new StringDecoder('utf-8');\n let pending = '';\n let pendingBytes = 0;\n let lineNumber = 0;\n\n const tooLong = (bytes: number): FsError =>\n new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (single line ${bytes} > ${options.maxSize} bytes). Use a narrower range or head.`,\n filePath,\n );\n\n try {\n for await (const chunk of stream) {\n const buffer = chunk as Buffer;\n let offset = 0;\n\n // Search loop: each iteration finds the next LF and advances offset past\n // it. Written as while-with-assignment so the re-search is visible, rather\n // than buried in a for \"increment\" slot that re-runs indexOf.\n let nl = buffer.indexOf(LF, offset);\n while (nl !== -1) {\n const segment = buffer.subarray(offset, nl);\n const lineBytes = pendingBytes + segment.length;\n lineNumber++;\n // Decode even when skipping: the decoder carries multi-byte\n // continuation state into the first line the caller keeps.\n const decoded = decoder.write(segment);\n if (lineNumber >= startLine) {\n if (lineBytes > options.maxSize) throw tooLong(lineBytes);\n yield stripCarriageReturn(pending + decoded);\n }\n pending = '';\n pendingBytes = 0;\n offset = nl + 1;\n nl = buffer.indexOf(LF, offset);\n }\n\n const rest = buffer.subarray(offset);\n pendingBytes += rest.length;\n if (lineNumber + 1 < startLine) {\n decoder.write(rest); // still skipping; drop the text, keep decoder state\n } else {\n if (pendingBytes > options.maxSize) throw tooLong(pendingBytes);\n pending += decoder.write(rest);\n }\n }\n\n // Trailing line with no final newline. A file ending in `\\n` leaves\n // pendingBytes at 0 and emits nothing, matching readLines.\n if (pendingBytes > 0) {\n lineNumber++;\n if (lineNumber >= startLine) {\n if (pendingBytes > options.maxSize) throw tooLong(pendingBytes);\n yield pending + decoder.end();\n }\n }\n } finally {\n if (!stream.destroyed) {\n stream.on('error', (_err: unknown) => {\n /* suppress post-destroy error event */\n });\n stream.destroy();\n }\n }\n}\n\nasync function readRangeContent(\n handle: FileHandle,\n startLine: number,\n endLine: number | undefined,\n options: NormalizedBase,\n filePath: string,\n): Promise<PartialReadResult> {\n options.signal?.throwIfAborted();\n\n const lines: string[] = [];\n let lineNumber = startLine - 1;\n let estimatedBytes = 0;\n const newlineBytes = Buffer.byteLength('\\n', 'utf-8');\n const stopAt = endLine ?? Number.POSITIVE_INFINITY;\n\n let hasMoreLines = false;\n\n // Byte-bounded: an over-long line throws TOO_LARGE while still a partial\n // buffer, before it can be decoded into one huge string.\n const iterator = readLinesBounded(handle, options, filePath, startLine)[Symbol.asyncIterator]();\n\n try {\n for (;;) {\n const { value: line, done } = await iterator.next();\n if (done) {\n break;\n }\n lineNumber++;\n\n if (lineNumber > stopAt) {\n hasMoreLines = true;\n break;\n }\n\n lines.push(line);\n\n estimatedBytes += Buffer.byteLength(line, 'utf-8') + newlineBytes;\n if (estimatedBytes > options.maxSize) {\n hasMoreLines = await peekHasMore(iterator);\n break;\n }\n\n if (lineNumber === stopAt) {\n hasMoreLines = await peekHasMore(iterator);\n break;\n }\n }\n } finally {\n await iterator.return();\n }\n\n return {\n content: lines.join('\\n'),\n linesRead: lines.length,\n hasMoreLines,\n };\n}\n\nasync function readTailContent(\n handle: FileHandle,\n tail: number,\n options: NormalizedBase,\n filePath: string,\n): Promise<PartialReadResult> {\n options.signal?.throwIfAborted();\n\n const stats = await handle.stat();\n const fileSize = stats.size;\n if (fileSize === 0) {\n return {\n content: '',\n linesRead: 0,\n hasMoreLines: false,\n };\n }\n\n const encoding = 'utf-8';\n // Accumulate raw bytes from the end: decoding a chunk ending mid-codepoint\n // corrupts the trailing UTF-8 sequence into U+FFFD. 0x0A is single-byte and\n // never part of a multibyte sequence, so count newlines on the raw buffer and\n // decode the whole bounded buffer once at the end.\n let position = fileSize;\n const chunks: Buffer[] = [];\n let totalLen = 0;\n let newlines = 0;\n let stoppedByLimit = false;\n\n while (position > 0) {\n options.signal?.throwIfAborted();\n const chunkSize = Math.min(position, STREAM_CHUNK_SIZE);\n const buffer = Buffer.allocUnsafe(chunkSize);\n const { bytesRead } = await handle.read(buffer, 0, chunkSize, position - chunkSize);\n if (bytesRead < chunkSize) {\n // The file shrank under us. Bytes from `position` on are still a\n // contiguous suffix, so keep those and stop — splicing this short chunk in\n // would leave a hole (and, with an alloc'd buffer, NULs) mid-content.\n // `position` stays put, so the result is reported as having more lines.\n break;\n }\n position -= chunkSize;\n\n for (const byte of buffer) {\n if (byte === 0x0a) newlines++;\n }\n\n chunks.unshift(buffer);\n totalLen += chunkSize;\n\n // One newline more than `tail`: the oldest segment in the buffer starts\n // mid-line whenever we stop before the file start, and gets dropped below.\n if (newlines > tail) break;\n if (totalLen > options.maxSize) {\n stoppedByLimit = true;\n break;\n }\n }\n\n const allBytes = Buffer.concat(chunks, totalLen);\n let lines = allBytes.toString(encoding).split('\\n');\n\n // A trailing newline produces a spurious empty final segment; drop it.\n if (lines.length > 0 && lines[lines.length - 1] === '') {\n lines = lines.slice(0, -1);\n }\n // Normalize CRLF.\n lines = lines.map((l) => (l.endsWith('\\r') ? l.slice(0, -1) : l));\n\n // We stopped before the file start, so the first segment is the tail of a\n // line whose beginning was never read. Drop it instead of reporting a\n // fragment as a complete line.\n if (position > 0 && lines.length > 0) {\n lines = lines.slice(1);\n }\n\n if (stoppedByLimit && lines.length < tail) {\n throw new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (${totalLen} > ${options.maxSize} bytes, could not collect ${tail} lines). Use a narrower tail or head.`,\n filePath,\n );\n }\n\n let hasMoreLines = stoppedByLimit || position > 0;\n if (lines.length > tail) {\n hasMoreLines = true;\n lines = lines.slice(lines.length - tail);\n }\n\n const content = lines.join('\\n');\n return {\n content,\n linesRead: lines.length,\n hasMoreLines,\n };\n}\n\nasync function readFullContent(\n handle: FileHandle,\n maxSize: number,\n requestedPath: string,\n signal?: AbortSignal,\n): Promise<{ content: string; totalLines: number }> {\n const buffer = await readFileBufferWithLimit(handle, maxSize, requestedPath, signal);\n const content = buffer.toString('utf-8');\n return { content, totalLines: countLines(content) };\n}\n\nasync function assertNotBinary(\n validPath: string,\n filePath: string,\n handle: FileHandle,\n normalized: NormalizedBase,\n): Promise<void> {\n normalized.signal?.throwIfAborted();\n const isBinary = await isProbablyBinary(validPath, handle, normalized.signal);\n if (!isBinary) return;\n throw new FsError(ErrorCode.INVALID_INPUT, 'Binary file detected.', filePath);\n}\n\nfunction assertSizeWithinLimit(size: number, maxSize: number, filePath: string): void {\n if (size <= maxSize) return;\n throw new FsError(\n ErrorCode.TOO_LARGE,\n `File too large (${size} > ${maxSize} bytes). Use head to preview.`,\n filePath,\n );\n}\n\ninterface ReadModeContext {\n handle: FileHandle;\n validPath: string;\n filePath: string;\n stats: Stats;\n spec: NormalizedSpec;\n}\n\nasync function readHead(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'head' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readRangeContent(\n context.handle,\n 1,\n spec.lines,\n spec,\n context.filePath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'head',\n head: spec.lines,\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readRange(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'range' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readRangeContent(\n context.handle,\n spec.start,\n spec.end,\n spec,\n context.filePath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'range',\n startLine: spec.start,\n ...(spec.end !== undefined ? { endLine: spec.end } : {}),\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readFull(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'full' }>,\n): Promise<ReadFileResult> {\n assertSizeWithinLimit(context.stats.size, spec.maxSize, context.filePath);\n const { content, totalLines } = await readFullContent(\n context.handle,\n spec.maxSize,\n context.filePath,\n spec.signal,\n );\n\n return {\n path: context.validPath,\n content,\n totalLines,\n readMode: 'full',\n linesRead: totalLines,\n hasMoreLines: false,\n };\n}\n\nasync function readTail(\n context: ReadModeContext,\n spec: Extract<NormalizedSpec, { kind: 'tail' }>,\n): Promise<ReadFileResult> {\n const { content, linesRead, hasMoreLines } = await readTailContent(\n context.handle,\n spec.lines,\n spec,\n context.validPath,\n );\n\n return {\n path: context.validPath,\n content,\n readMode: 'tail',\n tail: spec.lines,\n linesRead,\n hasMoreLines,\n };\n}\n\nasync function readByMode(context: ReadModeContext): Promise<ReadFileResult> {\n switch (context.spec.kind) {\n case 'head':\n return readHead(context, context.spec);\n case 'range':\n return readRange(context, context.spec);\n case 'full':\n return readFull(context, context.spec);\n case 'tail':\n return readTail(context, context.spec);\n default: {\n const _exhaustive: never = context.spec;\n return _exhaustive;\n }\n }\n}\n\nexport function assertFileStats(filePath: string, stats: Stats): void {\n if (!stats.isFile()) {\n throw new FsError(ErrorCode.NOT_FILE, 'Not a regular file', filePath);\n }\n}\n\nexport async function readNormalized(\n filePath: string,\n validPath: string,\n stats: Stats,\n spec: NormalizedSpec,\n): Promise<ReadFileResult> {\n spec.signal?.throwIfAborted();\n\n assertFileStats(filePath, stats);\n\n await using handle = await openReadableFileHandle(validPath, spec.signal);\n\n await assertNotBinary(validPath, filePath, handle, spec);\n spec.signal?.throwIfAborted();\n\n return await readByMode({ handle, validPath, filePath, stats, spec });\n}\n\nexport async function readFileWithStats(\n filePath: string,\n validPath: string,\n stats: Stats,\n spec: ReadSpec | undefined,\n): Promise<ReadFileResult> {\n return readNormalized(filePath, validPath, stats, normalizeSpec(spec ?? { kind: 'full' }));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAY5B,eAAO,MAAM,WAAW,kBAMtB,CAAC;AAIH,eAAO,MAAM,SAAS,aAG2D,CAAC;AAElF,eAAO,MAAM,SAAS,UAEoB,CAAC;AAE3C,eAAO,MAAM,WAAW,UAEe,CAAC;AAExC,QAAA,MAAM,UAAU,oDAAc,CAAC;AAC/B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,eAAO,MAAM,QAAQ;;;;;EAAqB,CAAC;AAE3C,QAAA,MAAM,UAAU,sDAAa,CAAC;AAC9B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,eAAO,MAAM,QAAQ;;;;;;EAAqB,CAAC;AAM3C,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,OAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAY5B,eAAO,MAAM,WAAW,kBAMtB,CAAC;AAIH,eAAO,MAAM,SAAS,aAG2D,CAAC;AAElF,eAAO,MAAM,SAAS,UAEoB,CAAC;AAE3C,eAAO,MAAM,WAAW,UAEe,CAAC;AAExC,QAAA,MAAM,UAAU,oDAAc,CAAC;AAC/B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,eAAO,MAAM,QAAQ;;;;;EAAqB,CAAC;AAE3C,QAAA,MAAM,UAAU,sDAAa,CAAC;AAC9B,MAAM,MAAM,QAAQ,GAAG,CA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