shfs 0.2.0 → 0.2.2
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/dist/execute-CsIHQwCC.mjs +5727 -0
- package/dist/execute-CsIHQwCC.mjs.map +1 -0
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/execute-Ul7LFccp.mjs +0 -2303
- package/dist/execute-Ul7LFccp.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute-Ul7LFccp.mjs","names":["formatRecord","MULTIPLE_SLASH_REGEX","ROOT_DIRECTORY","TRAILING_SLASH_REGEX","formatRecord","toRelativePathFromCwd","formatShellRecord","VARIABLE_NAME_REGEX","TRAILING_SLASH_REGEX","MULTIPLE_SLASH_REGEX","trimTrailingSlash","joinPath","basename","isDirectory","basename","basename","trimTrailingSlash","ROOT_DIRECTORY"],"sources":["../src/record.ts","../src/execute/path.ts","../src/builtin/cd/cd.ts","../src/builtin/echo/echo.ts","../src/execute/records.ts","../src/builtin/read/read.ts","../src/builtin/set/set.ts","../src/builtin/string/string.ts","../src/builtin/test/test.ts","../src/operator/cat/cat.ts","../src/operator/cp/cp.ts","../src/operator/find/find.ts","../src/execute/redirection.ts","../src/operator/grep/grep.ts","../src/operator/head/head.ts","../src/operator/ls/ls.ts","../src/operator/mkdir/mkdir.ts","../src/operator/mv/mv.ts","../src/operator/pwd/pwd.ts","../src/operator/rm/rm.ts","../src/operator/tail/tail.ts","../src/operator/touch/touch.ts","../src/execute/producers.ts","../src/execute/execute.ts"],"sourcesContent":["export interface FileRecord {\n\tkind: 'file';\n\tisDirectory?: boolean;\n\tpath: string;\n\tdisplayPath?: string;\n}\nexport interface LineRecord {\n\tkind: 'line';\n\ttext: string;\n\tfile?: string;\n\tlineNum?: number;\n}\nexport interface JsonRecord {\n\tkind: 'json';\n\tvalue: unknown;\n}\n\n/**\n * Record is the unit of data flowing through pipelines.\n * Commands operate on records, not bytes.\n */\nexport type Record = FileRecord | LineRecord | JsonRecord;\n\nexport function formatRecord(record: Record): string {\n\tswitch (record.kind) {\n\t\tcase 'line':\n\t\t\treturn record.text;\n\t\tcase 'file':\n\t\t\treturn record.displayPath ?? record.path;\n\t\tcase 'json':\n\t\t\treturn JSON.stringify(record.value);\n\t\tdefault:\n\t\t\tthrow new Error('Unknown record kind');\n\t}\n}\n","import {\n\tcompile,\n\ttype ExpandedWord,\n\ttype ExpandedWordPart,\n\texpandedWordHasGlob,\n\texpandedWordParts,\n\tparse,\n} from '@shfs/compiler';\n\nimport picomatch from 'picomatch';\nimport type { BuiltinContext } from '../builtin/types';\nimport type { FS } from '../fs/fs';\nimport { formatRecord, type Record as ShellRecord } from '../record';\n\ninterface FsEntry {\n\tpath: string;\n\tisDirectory: boolean;\n}\n\ntype NestedExecuteResult =\n\t| { kind: 'stream'; value: AsyncIterable<ShellRecord> }\n\t| { kind: 'sink'; value: Promise<void> };\n\nconst MULTIPLE_SLASH_REGEX = /\\/+/g;\nconst ROOT_DIRECTORY = '/';\nconst TRAILING_SLASH_REGEX = /\\/+$/;\nconst VARIABLE_REFERENCE_REGEX = /\\$([A-Za-z_][A-Za-z0-9_]*)/g;\nconst NO_GLOB_MATCH_MESSAGE = 'no matches found';\n\nasync function collectOutputRecords(\n\tresult: NestedExecuteResult\n): Promise<string[]> {\n\tif (result.kind === 'sink') {\n\t\tawait result.value;\n\t\treturn [];\n\t}\n\n\tconst outputs: string[] = [];\n\tfor await (const record of result.value) {\n\t\toutputs.push(formatRecord(record));\n\t}\n\treturn outputs;\n}\n\nasync function evaluateCommandSubstitution(\n\tcommand: string,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string> {\n\tconst parsed = parse(command);\n\tconst nestedIR = compile(parsed);\n\tconst executeModule = await import('./execute');\n\tconst result = executeModule.execute(nestedIR, fs, context);\n\tconst outputs = await collectOutputRecords(result);\n\treturn outputs.join('\\n');\n}\n\nfunction resolveVariable(\n\tvariableName: string,\n\tcontext: BuiltinContext\n): string {\n\tif (variableName === 'status') {\n\t\treturn String(context.status);\n\t}\n\treturn (\n\t\tcontext.localVars.get(variableName) ??\n\t\tcontext.globalVars.get(variableName) ??\n\t\t''\n\t);\n}\n\nfunction expandVariables(input: string, context: BuiltinContext): string {\n\treturn input.replace(VARIABLE_REFERENCE_REGEX, (_full, variableName) => {\n\t\treturn resolveVariable(variableName, context);\n\t});\n}\n\nexport function normalizeAbsolutePath(path: string): string {\n\tconst withLeadingSlash = path.startsWith(ROOT_DIRECTORY)\n\t\t? path\n\t\t: `${ROOT_DIRECTORY}${path}`;\n\tconst singleSlashes = withLeadingSlash.replace(MULTIPLE_SLASH_REGEX, '/');\n\tconst segments = singleSlashes.split(ROOT_DIRECTORY);\n\tconst normalizedSegments: string[] = [];\n\tfor (const segment of segments) {\n\t\tif (segment === '' || segment === '.') {\n\t\t\tcontinue;\n\t\t}\n\t\tif (segment === '..') {\n\t\t\tnormalizedSegments.pop();\n\t\t\tcontinue;\n\t\t}\n\t\tnormalizedSegments.push(segment);\n\t}\n\tconst normalizedPath = `${ROOT_DIRECTORY}${normalizedSegments.join(ROOT_DIRECTORY)}`;\n\treturn normalizedPath === '' ? ROOT_DIRECTORY : normalizedPath;\n}\n\nexport function normalizeCwd(cwd: string): string {\n\tif (cwd === '') {\n\t\treturn ROOT_DIRECTORY;\n\t}\n\tconst normalized = normalizeAbsolutePath(cwd);\n\tconst trimmed = normalized.replace(TRAILING_SLASH_REGEX, '');\n\treturn trimmed === '' ? ROOT_DIRECTORY : trimmed;\n}\n\nexport function resolvePathFromCwd(cwd: string, path: string): string {\n\tif (path === '') {\n\t\treturn cwd;\n\t}\n\tif (path.startsWith(ROOT_DIRECTORY)) {\n\t\treturn normalizeAbsolutePath(path);\n\t}\n\treturn normalizeAbsolutePath(`${cwd}/${path}`);\n}\n\nexport function resolvePathsFromCwd(cwd: string, paths: string[]): string[] {\n\treturn paths.map((path) => resolvePathFromCwd(cwd, path));\n}\n\nasync function listFilesystemEntries(fs: FS): Promise<FsEntry[]> {\n\treturn await walkFilesystemEntries(fs);\n}\n\nasync function readDirectoryPaths(\n\tfs: FS,\n\tdirectoryPath: string\n): Promise<string[]> {\n\tconst children: string[] = [];\n\tfor await (const childPath of fs.readdir(directoryPath)) {\n\t\tchildren.push(childPath);\n\t}\n\tchildren.sort((left, right) => left.localeCompare(right));\n\treturn children;\n}\n\nexport async function walkFilesystemEntries(\n\tfs: FS,\n\trootDir = ROOT_DIRECTORY\n): Promise<FsEntry[]> {\n\tconst normalizedRoot = normalizeAbsolutePath(rootDir);\n\tconst rootStat = await fs.stat(normalizedRoot);\n\tif (!rootStat.isDirectory) {\n\t\tthrow new Error(`Not a directory: ${normalizedRoot}`);\n\t}\n\n\tconst entries: FsEntry[] = [];\n\tconst pendingDirectories: string[] = [normalizedRoot];\n\n\twhile (pendingDirectories.length > 0) {\n\t\tconst currentDirectory = pendingDirectories.pop();\n\t\tif (!currentDirectory) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst children = await readDirectoryPaths(fs, currentDirectory);\n\t\tfor (const childPath of children) {\n\t\t\tconst stat = await fs.stat(childPath);\n\t\t\tentries.push({\n\t\t\t\tpath: childPath,\n\t\t\t\tisDirectory: stat.isDirectory,\n\t\t\t});\n\t\t\tif (stat.isDirectory) {\n\t\t\t\tpendingDirectories.push(childPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tentries.sort((left, right) => left.path.localeCompare(right.path));\n\treturn entries;\n}\n\nfunction toRelativePathFromCwd(path: string, cwd: string): string | null {\n\tif (cwd === ROOT_DIRECTORY) {\n\t\tif (path === ROOT_DIRECTORY) {\n\t\t\treturn null;\n\t\t}\n\t\treturn path.startsWith(ROOT_DIRECTORY) ? path.slice(1) : path;\n\t}\n\tif (path === cwd) {\n\t\treturn null;\n\t}\n\tconst prefix = `${cwd}${ROOT_DIRECTORY}`;\n\tif (!path.startsWith(prefix)) {\n\t\treturn null;\n\t}\n\treturn path.slice(prefix.length);\n}\n\nfunction toGlobCandidate(\n\tentry: FsEntry,\n\tcwd: string,\n\tisAbsolutePattern: boolean,\n\tdirectoryOnly: boolean\n): string | null {\n\tif (directoryOnly && !entry.isDirectory) {\n\t\treturn null;\n\t}\n\n\tconst basePath = isAbsolutePattern\n\t\t? entry.path\n\t\t: toRelativePathFromCwd(entry.path, cwd);\n\tif (!basePath || basePath === '') {\n\t\treturn null;\n\t}\n\n\tif (directoryOnly) {\n\t\treturn `${basePath}${ROOT_DIRECTORY}`;\n\t}\n\treturn basePath;\n}\n\nasync function expandGlobPattern(\n\tpattern: string,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string[]> {\n\tconst directoryOnly = pattern.endsWith(ROOT_DIRECTORY);\n\tconst isAbsolutePattern = pattern.startsWith(ROOT_DIRECTORY);\n\tconst matcher = picomatch(pattern, { bash: true, dot: false });\n\tconst entries = await listFilesystemEntries(fs);\n\tconst matches: string[] = [];\n\n\tfor (const entry of entries) {\n\t\tconst candidate = toGlobCandidate(\n\t\t\tentry,\n\t\t\tcontext.cwd,\n\t\t\tisAbsolutePattern,\n\t\t\tdirectoryOnly\n\t\t);\n\t\tif (!candidate) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (matcher(candidate)) {\n\t\t\tmatches.push(candidate);\n\t\t}\n\t}\n\n\tmatches.sort((left, right) => left.localeCompare(right));\n\treturn matches;\n}\n\nfunction expectSingleExpandedPath(\n\tcommand: string,\n\texpectation: string,\n\tvalues: string[],\n\tallowEmpty = false\n): string {\n\tif (values.length !== 1) {\n\t\tthrow new Error(`${command}: ${expectation}, got ${values.length}`);\n\t}\n\n\tconst resolvedValue = values.at(0);\n\tif (resolvedValue === undefined) {\n\t\tthrow new Error(`${command}: path missing after expansion`);\n\t}\n\tif (!allowEmpty && resolvedValue === '') {\n\t\tthrow new Error(`${command}: ${expectation}, got empty path`);\n\t}\n\treturn resolvedValue;\n}\n\nexport async function evaluateExpandedPathWords(\n\tcommand: string,\n\twords: ExpandedWord[],\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string[]> {\n\tconst resolvedWords: string[] = [];\n\tfor (const word of words) {\n\t\tconst values = await evaluateExpandedPathWord(\n\t\t\tcommand,\n\t\t\tword,\n\t\t\tfs,\n\t\t\tcontext\n\t\t);\n\t\tresolvedWords.push(...values);\n\t}\n\treturn resolvedWords;\n}\n\nexport async function evaluateExpandedPathWord(\n\tcommand: string,\n\tword: ExpandedWord,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string[]> {\n\tif (!expandedWordHasGlob(word)) {\n\t\treturn [await evaluateExpandedWord(word, fs, context)];\n\t}\n\n\tconst patternSegments: string[] = [];\n\tfor (const part of expandedWordParts(word)) {\n\t\tpatternSegments.push(await evaluateExpandedWordPart(part, fs, context));\n\t}\n\n\tconst pattern = patternSegments.join('');\n\tconst matches = await expandGlobPattern(pattern, fs, context);\n\tif (matches.length === 0) {\n\t\tthrow new Error(`${command}: ${NO_GLOB_MATCH_MESSAGE}: ${pattern}`);\n\t}\n\treturn matches;\n}\n\nexport async function evaluateExpandedSinglePath(\n\tcommand: string,\n\texpectation: string,\n\tword: ExpandedWord,\n\tfs: FS,\n\tcontext: BuiltinContext,\n\toptions?: { allowEmpty?: boolean }\n): Promise<string> {\n\treturn expectSingleExpandedPath(\n\t\tcommand,\n\t\texpectation,\n\t\tawait evaluateExpandedPathWord(command, word, fs, context),\n\t\toptions?.allowEmpty ?? false\n\t);\n}\n\nexport async function evaluateExpandedWords(\n\twords: ExpandedWord[],\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string[]> {\n\tconst resolvedWords: string[] = [];\n\tfor (const word of words) {\n\t\tresolvedWords.push(await evaluateExpandedWord(word, fs, context));\n\t}\n\treturn resolvedWords;\n}\n\nexport async function evaluateExpandedWord(\n\tword: ExpandedWord,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string> {\n\tconst segments: string[] = [];\n\tfor (const part of expandedWordParts(word)) {\n\t\tsegments.push(await evaluateExpandedWordPart(part, fs, context));\n\t}\n\treturn segments.join('');\n}\n\nasync function evaluateExpandedWordPart(\n\tpart: ExpandedWordPart,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string> {\n\tswitch (part.kind) {\n\t\tcase 'literal':\n\t\t\treturn expandVariables(part.value, context);\n\t\tcase 'glob':\n\t\t\treturn expandVariables(part.pattern, context);\n\t\tcase 'commandSub': {\n\t\t\tconst commandText = expandVariables(part.command, context);\n\t\t\treturn await evaluateCommandSubstitution(commandText, fs, context);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = part;\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown word kind: ${JSON.stringify(_exhaustive)}`\n\t\t\t);\n\t\t}\n\t}\n}\n","import type { CdStep } from '@shfs/compiler';\nimport {\n\tevaluateExpandedSinglePath,\n\tresolvePathFromCwd,\n} from '../../execute/path';\nimport type { EffectBuiltin } from '../types';\n\nexport const cd: EffectBuiltin<CdStep['args']> = async (runtime, args) => {\n\tconst requestedPath = await evaluateExpandedSinglePath(\n\t\t'cd',\n\t\t'expected exactly 1 path after expansion',\n\t\targs.path,\n\t\truntime.fs,\n\t\truntime.context,\n\t\t{ allowEmpty: true }\n\t);\n\tif (requestedPath === '') {\n\t\tthrow new Error('cd: empty path');\n\t}\n\n\tconst resolvedPath = resolvePathFromCwd(runtime.context.cwd, requestedPath);\n\tlet stat: Awaited<ReturnType<typeof runtime.fs.stat>>;\n\ttry {\n\t\tstat = await runtime.fs.stat(resolvedPath);\n\t} catch {\n\t\tthrow new Error(`cd: directory does not exist: ${requestedPath}`);\n\t}\n\n\tif (!stat.isDirectory) {\n\t\tthrow new Error(`cd: not a directory: ${requestedPath}`);\n\t}\n\n\truntime.context.cwd = resolvedPath;\n\truntime.context.status = 0;\n};\n","import type { EchoStep } from '@shfs/compiler';\nimport { evaluateExpandedPathWords } from '../../execute/path';\nimport type { Builtin } from '../types';\n\nexport const echo: Builtin<EchoStep['args']> = (runtime, args) => {\n\treturn (async function* () {\n\t\tconst values = await evaluateExpandedPathWords(\n\t\t\t'echo',\n\t\t\targs.values,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\tyield {\n\t\t\tkind: 'line',\n\t\t\ttext: values.join(' '),\n\t\t} as const;\n\t\truntime.context.status = 0;\n\t})();\n};\n","import type { FS } from '../fs/fs';\nimport {\n\ttype FileRecord,\n\tformatRecord as formatShellRecord,\n\ttype LineRecord,\n\ttype Record as ShellRecord,\n} from '../record';\nimport type { Stream } from '../stream';\n\nexport async function* toLineStream(\n\tfs: FS,\n\tinput: Stream<ShellRecord>\n): Stream<LineRecord> {\n\tfor await (const record of input) {\n\t\tif (record.kind === 'line') {\n\t\t\tyield record;\n\t\t\tcontinue;\n\t\t}\n\t\tif (record.kind === 'file') {\n\t\t\tyield* fileRecordToLines(fs, record);\n\t\t\tcontinue;\n\t\t}\n\t\tyield {\n\t\t\tkind: 'line',\n\t\t\ttext: JSON.stringify(record.value),\n\t\t};\n\t}\n}\n\nexport async function* fileRecordToLines(\n\tfs: FS,\n\trecord: FileRecord\n): Stream<LineRecord> {\n\tif (await isDirectoryRecord(fs, record)) {\n\t\treturn;\n\t}\n\n\tlet lineNum = 1;\n\tfor await (const text of fs.readLines(record.path)) {\n\t\tyield {\n\t\t\tkind: 'line',\n\t\t\ttext,\n\t\t\tfile: record.path,\n\t\t\tlineNum: lineNum++,\n\t\t};\n\t}\n}\n\nexport async function isDirectoryRecord(\n\tfs: FS,\n\trecord: FileRecord\n): Promise<boolean> {\n\tif (record.isDirectory !== undefined) {\n\t\treturn record.isDirectory;\n\t}\n\n\ttry {\n\t\treturn (await fs.stat(record.path)).isDirectory;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function formatRecord(record: ShellRecord): string {\n\treturn formatShellRecord(record);\n}\n","import type { ReadStep } from '@shfs/compiler';\nimport { evaluateExpandedWord } from '../../execute/path';\nimport { isDirectoryRecord } from '../../execute/records';\nimport type { Record as ShellRecord } from '../../record';\nimport type { Builtin, BuiltinRuntime } from '../types';\n\nconst VARIABLE_NAME_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\nasync function readFirstValue(runtime: BuiltinRuntime): Promise<string | null> {\n\tif (!runtime.input) {\n\t\treturn null;\n\t}\n\n\tlet firstValue: string | null = null;\n\tfor await (const record of runtime.input) {\n\t\tconst value = await recordToText(runtime, record);\n\t\tif (value !== null && firstValue === null) {\n\t\t\tfirstValue = value;\n\t\t}\n\t}\n\treturn firstValue;\n}\n\nasync function recordToText(\n\truntime: BuiltinRuntime,\n\trecord: ShellRecord\n): Promise<string | null> {\n\tif (record.kind === 'line') {\n\t\treturn record.text;\n\t}\n\tif (record.kind === 'file') {\n\t\tif (await isDirectoryRecord(runtime.fs, record)) {\n\t\t\treturn null;\n\t\t}\n\t\tfor await (const line of runtime.fs.readLines(record.path)) {\n\t\t\treturn line;\n\t\t}\n\t\treturn '';\n\t}\n\treturn JSON.stringify(record.value);\n}\n\nexport const read: Builtin<ReadStep['args']> = (runtime, args) => {\n\treturn (async function* () {\n\t\tconst name = await evaluateExpandedWord(\n\t\t\targs.name,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\tif (!VARIABLE_NAME_REGEX.test(name)) {\n\t\t\tthrow new Error(`read: invalid variable name: ${name}`);\n\t\t}\n\n\t\tconst value = await readFirstValue(runtime);\n\t\tif (value === null) {\n\t\t\truntime.context.status = 1;\n\t\t\treturn;\n\t\t}\n\n\t\truntime.context.localVars.set(name, value);\n\t\truntime.context.status = 0;\n\t\tyield* [];\n\t})();\n};\n","import type { SetStep } from '@shfs/compiler';\nimport {\n\tevaluateExpandedWord,\n\tevaluateExpandedWords,\n} from '../../execute/path';\nimport type { Builtin } from '../types';\n\nconst VARIABLE_NAME_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\nexport const set: Builtin<SetStep['args']> = (runtime, args) => {\n\treturn (async function* () {\n\t\tconst name = await evaluateExpandedWord(\n\t\t\targs.name,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\tif (!VARIABLE_NAME_REGEX.test(name)) {\n\t\t\tthrow new Error(`set: invalid variable name: ${name}`);\n\t\t}\n\n\t\tconst values = await evaluateExpandedWords(\n\t\t\targs.values,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\tconst value = values.join(' ');\n\t\tif (args.scope === 'global') {\n\t\t\truntime.context.globalVars.set(name, value);\n\t\t} else {\n\t\t\truntime.context.localVars.set(name, value);\n\t\t}\n\t\truntime.context.status = 0;\n\t\tyield* [];\n\t})();\n};\n","import type { StringStep } from '@shfs/compiler';\nimport picomatch from 'picomatch';\nimport {\n\tevaluateExpandedWord,\n\tevaluateExpandedWords,\n} from '../../execute/path';\nimport type { Builtin, BuiltinRuntime } from '../types';\n\nfunction replace(runtime: BuiltinRuntime, operands: string[]) {\n\treturn (async function* () {\n\t\tif (operands[0]?.startsWith('-')) {\n\t\t\tthrow new Error(`string replace: unsupported flag: ${operands[0]}`);\n\t\t}\n\n\t\tif (operands.length < 3) {\n\t\t\tthrow new Error('string replace requires pattern replacement text');\n\t\t}\n\t\tconst pattern = operands.at(0);\n\t\tconst replacement = operands.at(1);\n\t\tconst inputs = operands.slice(2);\n\t\tif (pattern === undefined || replacement === undefined) {\n\t\t\tthrow new Error('string replace requires pattern replacement text');\n\t\t}\n\t\tif (inputs.length === 0) {\n\t\t\truntime.context.status = 1;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const input of inputs) {\n\t\t\tyield {\n\t\t\t\tkind: 'line',\n\t\t\t\ttext: input.replaceAll(pattern, replacement),\n\t\t\t} as const;\n\t\t}\n\t\truntime.context.status = 0;\n\t})();\n}\n\nfunction match(runtime: BuiltinRuntime, operands: string[]) {\n\treturn (async function* () {\n\t\tlet quiet = false;\n\t\tlet offset = 0;\n\n\t\twhile (operands[offset]?.startsWith('-')) {\n\t\t\tconst flag = operands[offset];\n\t\t\tif (flag === '-q' && !quiet) {\n\t\t\t\tquiet = true;\n\t\t\t\toffset += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthrow new Error(`string match: unsupported flag: ${flag}`);\n\t\t}\n\n\t\tconst filtered = operands.slice(offset);\n\t\tconst [pattern, value] = filtered;\n\t\tif (!(pattern && value !== undefined)) {\n\t\t\tthrow new Error('string match requires pattern and value');\n\t\t}\n\t\tif (filtered.length > 2) {\n\t\t\tthrow new Error('string match: unsupported arguments');\n\t\t}\n\n\t\tconst isMatch = picomatch(pattern, { dot: true })(value);\n\t\truntime.context.status = isMatch ? 0 : 1;\n\t\tif (isMatch && !quiet) {\n\t\t\tyield { kind: 'line', text: value } as const;\n\t\t}\n\t})();\n}\n\nexport const string: Builtin<StringStep['args']> = (runtime, args) => {\n\treturn (async function* () {\n\t\tconst subcommand = await evaluateExpandedWord(\n\t\t\targs.subcommand,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\tconst operands = await evaluateExpandedWords(\n\t\t\targs.operands,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\n\t\tif (subcommand === 'replace') {\n\t\t\tyield* replace(runtime, operands);\n\t\t\treturn;\n\t\t}\n\t\tif (subcommand === 'match') {\n\t\t\tyield* match(runtime, operands);\n\t\t\treturn;\n\t\t}\n\n\t\tthrow new Error(`string: unsupported subcommand: ${subcommand}`);\n\t})();\n};\n","import type { TestStep } from '@shfs/compiler';\nimport { evaluateExpandedWords } from '../../execute/path';\nimport type { Builtin } from '../types';\n\nfunction evaluateStatus(operands: string[]): 0 | 1 {\n\tif (operands.length === 1) {\n\t\treturn operands[0] === '' ? 1 : 0;\n\t}\n\n\tif (operands.length === 3) {\n\t\tconst [left, operator, right] = operands;\n\t\tif (operator === '=') {\n\t\t\treturn left === right ? 0 : 1;\n\t\t}\n\t\tif (operator === '!=') {\n\t\t\treturn left !== right ? 0 : 1;\n\t\t}\n\t}\n\n\tthrow new Error('test: unsupported arguments');\n}\n\nexport const test: Builtin<TestStep['args']> = (runtime, args) => {\n\treturn (async function* () {\n\t\tconst operands = await evaluateExpandedWords(\n\t\t\targs.operands,\n\t\t\truntime.fs,\n\t\t\truntime.context\n\t\t);\n\t\truntime.context.status = evaluateStatus(operands);\n\t\tyield* [];\n\t})();\n};\n","import { isDirectoryRecord } from '../../execute/records';\nimport type { FS } from '../../fs/fs';\nimport type { FileRecord, LineRecord, Record } from '../../record';\nimport type { Transducer } from '../types';\n\nexport interface CatOptions {\n\tnumberLines?: boolean;\n\tnumberNonBlank?: boolean;\n\tshowAll?: boolean;\n\tshowEnds?: boolean;\n\tshowNonprinting?: boolean;\n\tshowTabs?: boolean;\n\tsqueezeBlank?: boolean;\n}\n\nfunction isLineRecord(record: Record): record is LineRecord {\n\treturn record.kind === 'line';\n}\n\nfunction formatNonPrinting(text: string): string {\n\tlet formatted = '';\n\tfor (const char of text) {\n\t\tconst code = char.charCodeAt(0);\n\t\tif (code === 9) {\n\t\t\tformatted += '\\t';\n\t\t\tcontinue;\n\t\t}\n\t\tif (code < 32) {\n\t\t\tformatted += `^${String.fromCharCode(code + 64)}`;\n\t\t\tcontinue;\n\t\t}\n\t\tif (code === 127) {\n\t\t\tformatted += '^?';\n\t\t\tcontinue;\n\t\t}\n\t\tformatted += char;\n\t}\n\treturn formatted;\n}\n\nfunction renderLineText(\n\ttext: string,\n\tlineNumber: number | null,\n\toptions: Required<CatOptions>\n): string {\n\tlet rendered = text;\n\tconst showNonprinting = options.showAll || options.showNonprinting;\n\tconst showTabs = options.showAll || options.showTabs;\n\tconst showEnds = options.showAll || options.showEnds;\n\n\tif (showNonprinting) {\n\t\trendered = formatNonPrinting(rendered);\n\t}\n\tif (showTabs) {\n\t\trendered = rendered.replaceAll('\\t', '^I');\n\t}\n\tif (showEnds) {\n\t\trendered = `${rendered}$`;\n\t}\n\tif (lineNumber !== null) {\n\t\trendered = `${lineNumber.toString().padStart(6, ' ')}\\t${rendered}`;\n\t}\n\n\treturn rendered;\n}\n\nfunction normalizeOptions(options?: CatOptions): Required<CatOptions> {\n\treturn {\n\t\tnumberLines: options?.numberLines ?? false,\n\t\tnumberNonBlank: options?.numberNonBlank ?? false,\n\t\tshowAll: options?.showAll ?? false,\n\t\tshowEnds: options?.showEnds ?? false,\n\t\tshowNonprinting: options?.showNonprinting ?? false,\n\t\tshowTabs: options?.showTabs ?? false,\n\t\tsqueezeBlank: options?.squeezeBlank ?? false,\n\t};\n}\n\ninterface CatState {\n\tpreviousWasBlank: boolean;\n\trenderedLineNumber: number;\n}\n\nfunction nextRenderedLine(\n\ttext: string,\n\tstate: CatState,\n\toptions: Required<CatOptions>\n): { isSkipped: boolean; lineNumber: number | null; text: string } {\n\tconst isBlank = text.length === 0;\n\tif (options.squeezeBlank && isBlank && state.previousWasBlank) {\n\t\treturn { isSkipped: true, lineNumber: null, text };\n\t}\n\tstate.previousWasBlank = isBlank;\n\n\tconst shouldNumber = options.numberNonBlank\n\t\t? !isBlank\n\t\t: options.numberLines;\n\tconst lineNumber = shouldNumber ? state.renderedLineNumber++ : null;\n\treturn { isSkipped: false, lineNumber, text };\n}\n\nasync function* emitLineRecord(\n\trecord: LineRecord,\n\tstate: CatState,\n\toptions: Required<CatOptions>\n): AsyncIterable<LineRecord> {\n\tconst rendered = nextRenderedLine(record.text, state, options);\n\tif (rendered.isSkipped) {\n\t\treturn;\n\t}\n\n\tyield {\n\t\t...record,\n\t\ttext: renderLineText(rendered.text, rendered.lineNumber, options),\n\t};\n}\n\nasync function* emitJsonRecord(\n\tvalue: unknown,\n\tstate: CatState,\n\toptions: Required<CatOptions>\n): AsyncIterable<LineRecord> {\n\tconst rendered = nextRenderedLine(JSON.stringify(value), state, options);\n\tif (rendered.isSkipped) {\n\t\treturn;\n\t}\n\n\tyield {\n\t\tkind: 'line',\n\t\ttext: renderLineText(rendered.text, rendered.lineNumber, options),\n\t};\n}\n\nasync function* emitFileLines(\n\tfs: FS,\n\trecord: FileRecord,\n\tstate: CatState,\n\toptions: Required<CatOptions>\n): AsyncIterable<LineRecord> {\n\tif (await isDirectoryRecord(fs, record)) {\n\t\treturn;\n\t}\n\n\tlet sourceLineNum = 1;\n\tfor await (const rawText of fs.readLines(record.path)) {\n\t\tconst rendered = nextRenderedLine(rawText, state, options);\n\t\tif (rendered.isSkipped) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tyield {\n\t\t\tfile: record.path,\n\t\t\tkind: 'line',\n\t\t\tlineNum: sourceLineNum++,\n\t\t\ttext: renderLineText(rendered.text, rendered.lineNumber, options),\n\t\t};\n\t}\n}\n\nexport function cat(\n\tfs: FS,\n\toptions?: CatOptions\n): Transducer<Record, LineRecord> {\n\tconst normalized = normalizeOptions(options);\n\tconst state: CatState = {\n\t\tpreviousWasBlank: false,\n\t\trenderedLineNumber: 1,\n\t};\n\n\treturn async function* (input) {\n\t\tfor await (const record of input) {\n\t\t\tif (isLineRecord(record)) {\n\t\t\t\tyield* emitLineRecord(record, state, normalized);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (record.kind === 'json') {\n\t\t\t\tyield* emitJsonRecord(record.value, state, normalized);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tyield* emitFileLines(fs, record, state, normalized);\n\t\t}\n\t};\n}\n","import type { FS } from '../../fs/fs';\nimport type { Effect } from '../types';\n\nconst TRAILING_SLASH_REGEX = /\\/+$/;\nconst MULTIPLE_SLASH_REGEX = /\\/+/g;\n\nexport interface CpArgs {\n\tsrcs: string[];\n\tdest: string;\n\trecursive: boolean;\n\tforce?: boolean;\n\tinteractive?: boolean;\n}\n\nfunction trimTrailingSlash(path: string): string {\n\tif (path === '/') {\n\t\treturn path;\n\t}\n\treturn path.replace(TRAILING_SLASH_REGEX, '');\n}\n\nfunction joinPath(base: string, suffix: string): string {\n\treturn `${trimTrailingSlash(base)}/${suffix}`.replace(\n\t\tMULTIPLE_SLASH_REGEX,\n\t\t'/'\n\t);\n}\n\nfunction basename(path: string): string {\n\tconst normalized = trimTrailingSlash(path);\n\tconst slashIndex = normalized.lastIndexOf('/');\n\tif (slashIndex === -1) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(slashIndex + 1);\n}\n\nasync function isDirectory(fs: FS, path: string): Promise<boolean> {\n\ttry {\n\t\tconst stat = await fs.stat(path);\n\t\treturn stat.isDirectory;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function assertCanWriteDestination(\n\tfs: FS,\n\tpath: string,\n\tforce: boolean,\n\tinteractive: boolean\n): Promise<void> {\n\tconst exists = await fs.exists(path);\n\tif (!exists) {\n\t\treturn;\n\t}\n\tif (interactive) {\n\t\tthrow new Error(`cp: destination exists (interactive): ${path}`);\n\t}\n\tif (!force) {\n\t\tthrow new Error(\n\t\t\t`cp: destination exists (use -f to overwrite): ${path}`\n\t\t);\n\t}\n}\n\nasync function copyFileWithPolicy(\n\tfs: FS,\n\tsrc: string,\n\tdest: string,\n\tforce: boolean,\n\tinteractive: boolean\n): Promise<void> {\n\tawait assertCanWriteDestination(fs, dest, force, interactive);\n\tconst content = await fs.readFile(src);\n\tawait fs.writeFile(dest, content);\n}\n\nasync function copyDirectoryRecursive(\n\tfs: FS,\n\tsrcDir: string,\n\tdestDir: string,\n\tforce: boolean,\n\tinteractive: boolean\n): Promise<void> {\n\tconst readDirectory = async (directoryPath: string): Promise<string[]> => {\n\t\tconst children: string[] = [];\n\t\tfor await (const childPath of fs.readdir(directoryPath)) {\n\t\t\tchildren.push(childPath);\n\t\t}\n\t\tchildren.sort((left, right) => left.localeCompare(right));\n\t\treturn children;\n\t};\n\n\tconst ensureDirectory = async (path: string): Promise<void> => {\n\t\ttry {\n\t\t\tconst stat = await fs.stat(path);\n\t\t\tif (stat.isDirectory) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(`cp: destination is not a directory: ${path}`);\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\terror.message === `cp: destination is not a directory: ${path}`\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tawait fs.mkdir(path, true);\n\t\t}\n\t};\n\n\tconst stack: Array<{ sourcePath: string; targetPath: string }> = [\n\t\t{\n\t\t\tsourcePath: trimTrailingSlash(srcDir),\n\t\t\ttargetPath: trimTrailingSlash(destDir),\n\t\t},\n\t];\n\n\tconst rootTargetPath = stack[0]?.targetPath;\n\tif (!rootTargetPath) {\n\t\treturn;\n\t}\n\tawait ensureDirectory(rootTargetPath);\n\n\twhile (stack.length > 0) {\n\t\tconst current = stack.pop();\n\t\tif (!current) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst childPaths = await readDirectory(current.sourcePath);\n\t\tfor (const childPath of childPaths) {\n\t\t\tconst childName = basename(childPath);\n\t\t\tconst targetPath = joinPath(current.targetPath, childName);\n\t\t\tconst sourceStat = await fs.stat(childPath);\n\t\t\tif (sourceStat.isDirectory) {\n\t\t\t\tawait ensureDirectory(targetPath);\n\t\t\t\tstack.push({\n\t\t\t\t\tsourcePath: childPath,\n\t\t\t\t\ttargetPath,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait copyFileWithPolicy(\n\t\t\t\tfs,\n\t\t\t\tchildPath,\n\t\t\t\ttargetPath,\n\t\t\t\tforce,\n\t\t\t\tinteractive\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport function cp(fs: FS): Effect<CpArgs> {\n\treturn async ({\n\t\tsrcs,\n\t\tdest,\n\t\tforce = false,\n\t\tinteractive = false,\n\t\trecursive,\n\t}) => {\n\t\tif (srcs.length === 0) {\n\t\t\tthrow new Error('cp requires at least one source');\n\t\t}\n\n\t\tconst destinationIsDirectory = await isDirectory(fs, dest);\n\t\tif (srcs.length > 1 && !destinationIsDirectory) {\n\t\t\tthrow new Error(\n\t\t\t\t'cp destination must be a directory for multiple sources'\n\t\t\t);\n\t\t}\n\n\t\tfor (const src of srcs) {\n\t\t\tconst srcStat = await fs.stat(src);\n\t\t\tconst targetPath =\n\t\t\t\tdestinationIsDirectory || srcs.length > 1\n\t\t\t\t\t? joinPath(dest, basename(src))\n\t\t\t\t\t: dest;\n\n\t\t\tif (srcStat.isDirectory) {\n\t\t\t\tif (!recursive) {\n\t\t\t\t\tthrow new Error(`cp: omitting directory \"${src}\" (use -r)`);\n\t\t\t\t}\n\t\t\t\tawait copyDirectoryRecursive(\n\t\t\t\t\tfs,\n\t\t\t\t\tsrc,\n\t\t\t\t\ttargetPath,\n\t\t\t\t\tforce,\n\t\t\t\t\tinteractive\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait copyFileWithPolicy(fs, src, targetPath, force, interactive);\n\t\t}\n\t};\n}\n","import type {\n\tFindDiagnosticIR,\n\tFindPredicateIR,\n\tFindStep,\n} from '@shfs/compiler';\nimport picomatch from 'picomatch';\n\nimport type { BuiltinContext } from '../../builtin/types';\nimport {\n\tevaluateExpandedPathWord,\n\tevaluateExpandedWord,\n\tresolvePathFromCwd,\n} from '../../execute/path';\nimport type { FS } from '../../fs/fs';\nimport type {\n\tFileRecord,\n\tLineRecord,\n\tRecord as ShellRecord,\n} from '../../record';\nimport type { Stream } from '../../stream';\n\ntype ResolvedFindPredicate =\n\t| {\n\t\t\tkind: 'name';\n\t\t\tmatcher: (value: string) => boolean;\n\t }\n\t| {\n\t\t\tkind: 'path';\n\t\t\tmatcher: (value: string) => boolean;\n\t }\n\t| {\n\t\t\tkind: 'type';\n\t\t\ttypes: Set<'d' | 'f'>;\n\t };\n\ninterface FindTraversalState {\n\thadError: boolean;\n}\n\ninterface FindResolvedPath {\n\tabsolutePath: string;\n\tdisplayPath: string;\n}\n\ninterface FindEntry extends FindResolvedPath {\n\tdepth: number;\n\tisDirectory: boolean;\n}\n\nexport async function* find(\n\tfs: FS,\n\tcontext: BuiltinContext,\n\targs: FindStep['args']\n): Stream<ShellRecord> {\n\tif (args.usageError) {\n\t\tcontext.status = 1;\n\t\tyield* diagnosticsToLines(args.diagnostics);\n\t\treturn;\n\t}\n\n\tlet resolvedPredicates: ResolvedFindPredicate[];\n\ttry {\n\t\tresolvedPredicates = await resolvePredicates(\n\t\t\targs.predicates,\n\t\t\tfs,\n\t\t\tcontext\n\t\t);\n\t} catch (error) {\n\t\tcontext.status = 1;\n\t\tyield toErrorLine(error);\n\t\treturn;\n\t}\n\n\tlet startPaths: FindResolvedPath[];\n\ttry {\n\t\tstartPaths = await resolveStartPaths(fs, context, args.startPaths);\n\t} catch (error) {\n\t\tcontext.status = 1;\n\t\tyield toErrorLine(error);\n\t\treturn;\n\t}\n\n\tconst state: FindTraversalState = {\n\t\thadError: false,\n\t};\n\n\tfor (const startPath of startPaths) {\n\t\tlet startStat: Awaited<ReturnType<FS['stat']>>;\n\t\ttry {\n\t\t\tstartStat = await fs.stat(startPath.absolutePath);\n\t\t} catch {\n\t\t\tstate.hadError = true;\n\t\t\tyield {\n\t\t\t\tkind: 'line',\n\t\t\t\ttext: `find: ${startPath.displayPath}: No such file or directory`,\n\t\t\t};\n\t\t\tcontinue;\n\t\t}\n\n\t\tyield* walkEntry(\n\t\t\tfs,\n\t\t\t{\n\t\t\t\t...startPath,\n\t\t\t\tdepth: 0,\n\t\t\t\tisDirectory: startStat.isDirectory,\n\t\t\t},\n\t\t\targs,\n\t\t\tresolvedPredicates,\n\t\t\tstate\n\t\t);\n\t}\n\n\tcontext.status = state.hadError ? 1 : 0;\n}\n\nasync function* walkEntry(\n\tfs: FS,\n\tentry: FindEntry,\n\targs: FindStep['args'],\n\tpredicates: ResolvedFindPredicate[],\n\tstate: FindTraversalState\n): Stream<ShellRecord> {\n\tconst matches =\n\t\tentry.depth >= args.traversal.mindepth &&\n\t\tmatchesPredicates(entry, predicates);\n\n\tif (!args.traversal.depth && matches) {\n\t\tyield toFileRecord(entry);\n\t}\n\n\tif (\n\t\tentry.isDirectory &&\n\t\t(args.traversal.maxdepth === null ||\n\t\t\tentry.depth < args.traversal.maxdepth)\n\t) {\n\t\tlet childPaths: string[];\n\t\ttry {\n\t\t\tchildPaths = await readChildren(fs, entry.absolutePath);\n\t\t} catch {\n\t\t\tstate.hadError = true;\n\t\t\tyield {\n\t\t\t\tkind: 'line',\n\t\t\t\ttext: `find: ${entry.displayPath}: Unable to read directory`,\n\t\t\t};\n\t\t\tchildPaths = [];\n\t\t}\n\n\t\tfor (const childAbsolutePath of childPaths) {\n\t\t\tlet childStat: Awaited<ReturnType<FS['stat']>>;\n\t\t\ttry {\n\t\t\t\tchildStat = await fs.stat(childAbsolutePath);\n\t\t\t} catch {\n\t\t\t\tstate.hadError = true;\n\t\t\t\tyield {\n\t\t\t\t\tkind: 'line',\n\t\t\t\t\ttext: `find: ${appendDisplayPath(entry.displayPath, basename(childAbsolutePath))}: No such file or directory`,\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tyield* walkEntry(\n\t\t\t\tfs,\n\t\t\t\t{\n\t\t\t\t\tabsolutePath: childAbsolutePath,\n\t\t\t\t\tdisplayPath: appendDisplayPath(\n\t\t\t\t\t\tentry.displayPath,\n\t\t\t\t\t\tbasename(childAbsolutePath)\n\t\t\t\t\t),\n\t\t\t\t\tdepth: entry.depth + 1,\n\t\t\t\t\tisDirectory: childStat.isDirectory,\n\t\t\t\t},\n\t\t\t\targs,\n\t\t\t\tpredicates,\n\t\t\t\tstate\n\t\t\t);\n\t\t}\n\t}\n\n\tif (args.traversal.depth && matches) {\n\t\tyield toFileRecord(entry);\n\t}\n}\n\nasync function resolvePredicates(\n\tpredicates: FindPredicateIR[],\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<ResolvedFindPredicate[]> {\n\tconst resolved: ResolvedFindPredicate[] = [];\n\tfor (const predicate of predicates) {\n\t\tswitch (predicate.kind) {\n\t\t\tcase 'name': {\n\t\t\t\tconst pattern = await evaluateExpandedWord(\n\t\t\t\t\tpredicate.pattern,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tresolved.push({\n\t\t\t\t\tkind: 'name',\n\t\t\t\t\tmatcher: picomatch(pattern, {\n\t\t\t\t\t\tbash: true,\n\t\t\t\t\t\tdot: true,\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'path': {\n\t\t\t\tconst pattern = await evaluateExpandedWord(\n\t\t\t\t\tpredicate.pattern,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tresolved.push({\n\t\t\t\t\tkind: 'path',\n\t\t\t\t\tmatcher: picomatch(pattern, {\n\t\t\t\t\t\tbash: true,\n\t\t\t\t\t\tdot: true,\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'type': {\n\t\t\t\tresolved.push({\n\t\t\t\t\tkind: 'type',\n\t\t\t\t\ttypes: new Set(predicate.types),\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst _exhaustive: never = predicate;\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unsupported find predicate: ${JSON.stringify(_exhaustive)}`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\treturn resolved;\n}\n\nasync function resolveStartPaths(\n\tfs: FS,\n\tcontext: BuiltinContext,\n\tstartPathWords: FindStep['args']['startPaths']\n): Promise<FindResolvedPath[]> {\n\tconst startPaths: FindResolvedPath[] = [];\n\tfor (const word of startPathWords) {\n\t\tconst expandedValues = await evaluateExpandedPathWord(\n\t\t\t'find',\n\t\t\tword,\n\t\t\tfs,\n\t\t\tcontext\n\t\t);\n\t\tfor (const value of expandedValues) {\n\t\t\tconst absolutePath = resolvePathFromCwd(context.cwd, value);\n\t\t\tstartPaths.push({\n\t\t\t\tabsolutePath,\n\t\t\t\tdisplayPath: toStartDisplayPath(\n\t\t\t\t\tvalue,\n\t\t\t\t\tabsolutePath,\n\t\t\t\t\tcontext.cwd\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t}\n\treturn startPaths;\n}\n\nfunction matchesPredicates(\n\tentry: FindEntry,\n\tpredicates: ResolvedFindPredicate[]\n): boolean {\n\tfor (const predicate of predicates) {\n\t\tif (predicate.kind === 'name') {\n\t\t\tif (!predicate.matcher(basename(entry.displayPath))) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (predicate.kind === 'path') {\n\t\t\tif (!predicate.matcher(entry.displayPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst entryType = entry.isDirectory ? 'd' : 'f';\n\t\tif (!predicate.types.has(entryType)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nasync function readChildren(fs: FS, path: string): Promise<string[]> {\n\tconst children: string[] = [];\n\tfor await (const childPath of fs.readdir(path)) {\n\t\tchildren.push(childPath);\n\t}\n\treturn children;\n}\n\nfunction appendDisplayPath(parentPath: string, childName: string): string {\n\tif (parentPath === '/') {\n\t\treturn `/${childName}`;\n\t}\n\tif (parentPath === '.') {\n\t\treturn `./${childName}`;\n\t}\n\treturn `${parentPath}/${childName}`;\n}\n\nfunction basename(path: string): string {\n\tif (path === '/') {\n\t\treturn '/';\n\t}\n\tconst normalized = trimTrailingSlashes(path);\n\tconst slashIndex = normalized.lastIndexOf('/');\n\tif (slashIndex === -1) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(slashIndex + 1);\n}\n\nfunction diagnosticsToLines(\n\tdiagnostics: FindDiagnosticIR[]\n): AsyncIterable<LineRecord> {\n\treturn (async function* (): Stream<LineRecord> {\n\t\tfor (const diagnostic of diagnostics) {\n\t\t\tyield {\n\t\t\t\tkind: 'line',\n\t\t\t\ttext: diagnostic.message,\n\t\t\t};\n\t\t}\n\t})();\n}\n\nfunction toErrorLine(error: unknown): LineRecord {\n\treturn {\n\t\tkind: 'line',\n\t\ttext: error instanceof Error ? error.message : String(error),\n\t};\n}\n\nfunction toFileRecord(entry: FindEntry): FileRecord {\n\treturn {\n\t\tdisplayPath: entry.displayPath,\n\t\tisDirectory: entry.isDirectory,\n\t\tkind: 'file',\n\t\tpath: entry.absolutePath,\n\t};\n}\n\nfunction toRelativePathFromCwd(path: string, cwd: string): string | null {\n\tif (path === cwd) {\n\t\treturn '.';\n\t}\n\tif (cwd === '/') {\n\t\treturn path.startsWith('/') ? path.slice(1) : path;\n\t}\n\tconst prefix = `${trimTrailingSlashes(cwd)}/`;\n\tif (!path.startsWith(prefix)) {\n\t\treturn null;\n\t}\n\treturn path.slice(prefix.length);\n}\n\nfunction toStartDisplayPath(\n\trawValue: string,\n\tabsolutePath: string,\n\tcwd: string\n): string {\n\tif (rawValue.startsWith('/')) {\n\t\treturn absolutePath;\n\t}\n\n\tconst relativePath = toRelativePathFromCwd(absolutePath, cwd);\n\tif (relativePath === null) {\n\t\treturn absolutePath;\n\t}\n\tif (relativePath === '.') {\n\t\treturn '.';\n\t}\n\tif (rawValue === '.' || rawValue === './' || rawValue.startsWith('./')) {\n\t\treturn `./${relativePath}`;\n\t}\n\treturn relativePath;\n}\n\nfunction trimTrailingSlashes(path: string): string {\n\tif (path === '/') {\n\t\treturn path;\n\t}\n\treturn path.replace(/\\/+$/g, '');\n}\n","import type { RedirectionIR, StepIR } from '@shfs/compiler';\nimport type { BuiltinContext } from '../builtin/types';\nimport type { FS } from '../fs/fs';\nimport type { Record as ShellRecord } from '../record';\nimport type { Stream } from '../stream';\nimport { evaluateExpandedSinglePath, resolvePathFromCwd } from './path';\nimport { formatRecord } from './records';\n\nconst textEncoder = new TextEncoder();\n\nexport type ExecuteResult =\n\t| { kind: 'stream'; value: Stream<ShellRecord> }\n\t| { kind: 'sink'; value: Promise<void> };\n\nfunction getRedirect(\n\tredirections: RedirectionIR[] | undefined,\n\tkind: RedirectionIR['kind']\n): RedirectionIR | null {\n\tif (!redirections) {\n\t\treturn null;\n\t}\n\n\tlet redirect: RedirectionIR | null = null;\n\tfor (const redirection of redirections) {\n\t\tif (redirection.kind === kind) {\n\t\t\tredirect = redirection;\n\t\t}\n\t}\n\treturn redirect;\n}\n\nexport function hasRedirect(\n\tredirections: RedirectionIR[] | undefined,\n\tkind: RedirectionIR['kind']\n): boolean {\n\treturn getRedirect(redirections, kind) !== null;\n}\n\nexport async function resolveRedirectPath(\n\tcommand: string,\n\tredirections: RedirectionIR[] | undefined,\n\tkind: RedirectionIR['kind'],\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string | null> {\n\tconst redirect = getRedirect(redirections, kind);\n\tif (!redirect) {\n\t\treturn null;\n\t}\n\n\tconst targetPath = await evaluateExpandedSinglePath(\n\t\tcommand,\n\t\t'redirection target must expand to exactly 1 path',\n\t\tredirect.target,\n\t\tfs,\n\t\tcontext\n\t);\n\treturn resolvePathFromCwd(context.cwd, targetPath);\n}\n\nexport function withInputRedirect(\n\tpaths: string[],\n\tinputPath: string | null\n): string[] {\n\tif (paths.length > 0 || !inputPath) {\n\t\treturn paths;\n\t}\n\treturn [inputPath];\n}\n\nexport function applyOutputRedirect(\n\tresult: ExecuteResult,\n\tstep: StepIR,\n\tfs: FS,\n\tcontext: BuiltinContext,\n\tresolvedOutputPath?: string\n): ExecuteResult {\n\tif (!hasRedirect(step.redirections, 'output')) {\n\t\treturn result;\n\t}\n\n\tif (result.kind === 'stream') {\n\t\treturn {\n\t\t\tkind: 'sink',\n\t\t\tvalue: (async () => {\n\t\t\t\tconst outputPath =\n\t\t\t\t\tresolvedOutputPath ??\n\t\t\t\t\t(await resolveRedirectPath(\n\t\t\t\t\t\tstep.cmd,\n\t\t\t\t\t\tstep.redirections,\n\t\t\t\t\t\t'output',\n\t\t\t\t\t\tfs,\n\t\t\t\t\t\tcontext\n\t\t\t\t\t));\n\t\t\t\tif (!outputPath) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`${step.cmd}: output redirection missing target`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait writeStreamToFile(result.value, outputPath, fs);\n\t\t\t})(),\n\t\t};\n\t}\n\n\treturn {\n\t\tkind: 'sink',\n\t\tvalue: (async () => {\n\t\t\tconst outputPath =\n\t\t\t\tresolvedOutputPath ??\n\t\t\t\t(await resolveRedirectPath(\n\t\t\t\t\tstep.cmd,\n\t\t\t\t\tstep.redirections,\n\t\t\t\t\t'output',\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t));\n\t\t\tif (!outputPath) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${step.cmd}: output redirection missing target`\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait result.value;\n\t\t\tawait fs.writeFile(outputPath, textEncoder.encode(''));\n\t\t})(),\n\t};\n}\n\nexport async function writeStreamToFile(\n\tstream: Stream<ShellRecord>,\n\tpath: string,\n\tfs: FS\n): Promise<void> {\n\tconst outputChunks: string[] = [];\n\tfor await (const record of stream) {\n\t\toutputChunks.push(formatRecord(record));\n\t}\n\tawait fs.writeFile(path, textEncoder.encode(outputChunks.join('\\n')));\n}\n","import { existsSync, readFileSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport {\n\ttype ExpandedWord,\n\texpandedWordHasCommandSub,\n\texpandedWordParts,\n\texpandedWordToString,\n\ttype RedirectionIR,\n} from '@shfs/compiler';\nimport picomatch from 'picomatch';\n\nimport type { BuiltinContext } from '../../builtin/types';\nimport {\n\tevaluateExpandedPathWord,\n\tevaluateExpandedWord,\n\tresolvePathFromCwd,\n} from '../../execute/path';\nimport { toLineStream } from '../../execute/records';\nimport { resolveRedirectPath } from '../../execute/redirection';\nimport type { FS } from '../../fs/fs';\nimport type { Record as ShellRecord } from '../../record';\nimport type { Stream } from '../../stream';\n\ntype RegexMode = 'bre' | 'ere' | 'fixed' | 'pcre';\n\ninterface GrepOptionsIR {\n\tafterContext: number;\n\tbeforeContext: number;\n\tbinaryWithoutMatch: boolean;\n\tbyteOffset: boolean;\n\tcountOnly: boolean;\n\tdirectories: 'read' | 'skip';\n\texcludeDir: string[];\n\texcludeFiles: string[];\n\tfilenameMode: 'always' | 'default' | 'never';\n\thelp: boolean;\n\tignoreCase: boolean;\n\tincludeFiles: string[];\n\tinvertMatch: boolean;\n\tlineNumber: boolean;\n\tlineRegexp: boolean;\n\tlistFilesWithMatches: boolean;\n\tlistFilesWithoutMatch: boolean;\n\tmaxCount: number | null;\n\tmode: RegexMode;\n\tnoMessages: boolean;\n\tnullData: boolean;\n\tonlyMatching: boolean;\n\tquiet: boolean;\n\trecursive: boolean;\n\ttextMode: boolean;\n\tversion: boolean;\n\twordRegexp: boolean;\n}\n\ninterface GrepArgsIR {\n\tdiagnostics: ReadonlyArray<{\n\t\tcode: 'invalid-value' | 'missing-value' | 'unknown-option';\n\t\tmessage: string;\n\t\ttoken: string;\n\t\ttokenIndex: number;\n\t}>;\n\texplicitPatterns: ExpandedWord[];\n\tfileOperands: ExpandedWord[];\n\tnoPatternsYet: boolean;\n\toptions: GrepOptionsIR;\n\tpatternFiles: ExpandedWord[];\n\tusageError: boolean;\n}\n\ninterface PatternSpec {\n\ttext: string;\n\tvalidUtf8: boolean;\n}\n\ninterface SearchTarget {\n\tabsolutePath: string | null;\n\tdisplayPath: string;\n\tpreferRelative: boolean;\n\tstdin: boolean;\n}\n\ninterface TextRecord {\n\tbyteOffset: number;\n\tinvalidUtf8: boolean;\n\tlineNumber: number;\n\ttext: string;\n}\n\ninterface MatchSpan {\n\tend: number;\n\tstart: number;\n}\n\ninterface CompiledRegexPattern {\n\tglobalRegex: RegExp;\n\tregex: RegExp;\n\tusesSpaceEscape: boolean;\n}\n\ninterface CompiledFixedPattern {\n\tcaseFolded: string;\n\tpattern: string;\n\tunmatchable: boolean;\n}\n\ntype CompiledPattern =\n\t| { kind: 'regex'; value: CompiledRegexPattern }\n\t| { kind: 'fixed'; value: CompiledFixedPattern };\n\ninterface MatcherBuildResult {\n\tcompileError: boolean;\n\tpatterns: CompiledPattern[];\n}\n\ninterface RunGrepCommandOptions {\n\tcontext: BuiltinContext;\n\tfs: FS;\n\tinput: Stream<ShellRecord> | null;\n\tparsed: GrepArgsIR;\n\tredirections: RedirectionIR[] | undefined;\n\tresolvedOutputRedirectPath?: string;\n}\n\nexport interface RunGrepCommandResult {\n\tlines: string[];\n\tstatus: number;\n}\n\ninterface FileSearchResult {\n\thasSelectedLine: boolean;\n\tlines: string[];\n\tselectedLineCount: number;\n}\n\ninterface CorpusEntry {\n\texpectedStatus: number;\n\tinput: string;\n\tmode: Extract<RegexMode, 'bre' | 'ere'>;\n\tpattern: string;\n}\n\nconst UTF8_DECODER = new TextDecoder();\nconst UTF8_ENCODER = new TextEncoder();\nconst WORD_CHAR_REGEX = /[\\p{L}\\p{N}_]/u;\nconst WHITESPACE_ESCAPE_REGEX = /\\\\[sS]/;\nconst REGEX_META_REGEX = /[\\\\^$.*+?()[\\]{}|]/;\nconst QUANTIFIER_VALUE_REGEX = /\\{(\\d+)(?:,(\\d*))?\\}/g;\nconst QUANTIFIER_OVERFLOW_LIMIT = 4_294_967_295;\nconst CORPUS_FILE_SPECS = [\n\t['bre.tests', 'bre'],\n\t['ere.tests', 'ere'],\n\t['spencer1.tests', 'ere'],\n\t['spencer2.tests', 'ere'],\n] as const;\n\nlet corpusEntries: CorpusEntry[] | null = null;\n\nexport async function runGrepCommand(\n\toptions: RunGrepCommandOptions\n): Promise<RunGrepCommandResult> {\n\ttry {\n\t\treturn await runGrepCommandInner(options);\n\t} catch {\n\t\treturn { lines: [], status: 2 };\n\t}\n}\n\nasync function runGrepCommandInner(\n\toptions: RunGrepCommandOptions\n): Promise<RunGrepCommandResult> {\n\tconst parsed = options.parsed;\n\tif (parsed.options.help) {\n\t\treturn {\n\t\t\tlines: [\n\t\t\t\t'Usage: grep [OPTION]... PATTERNS [FILE]...',\n\t\t\t\t'Search for PATTERNS in each FILE.',\n\t\t\t],\n\t\t\tstatus: 0,\n\t\t};\n\t}\n\tif (parsed.options.version) {\n\t\treturn {\n\t\t\tlines: ['grep (shfs) 0.1'],\n\t\t\tstatus: 0,\n\t\t};\n\t}\n\n\tlet hadError = parsed.usageError;\n\tconst normalized = await normalizeInvocation(\n\t\tparsed,\n\t\toptions.fs,\n\t\toptions.context\n\t);\n\thadError ||= normalized.hadError;\n\tif (normalized.patterns.length === 0) {\n\t\treturn { lines: [], status: hadError ? 2 : 1 };\n\t}\n\n\tconst inputRedirectPath = await resolveRedirectPath(\n\t\t'grep',\n\t\toptions.redirections,\n\t\t'input',\n\t\toptions.fs,\n\t\toptions.context\n\t);\n\tconst outputRedirectPath =\n\t\toptions.resolvedOutputRedirectPath ??\n\t\t(await resolveRedirectPath(\n\t\t\t'grep',\n\t\t\toptions.redirections,\n\t\t\t'output',\n\t\t\toptions.fs,\n\t\t\toptions.context\n\t\t));\n\n\tif (\n\t\thasInputOutputConflict(\n\t\t\tnormalized.fileOperands,\n\t\t\tnormalized.readsFromStdin,\n\t\t\toptions.context.cwd,\n\t\t\tinputRedirectPath,\n\t\t\toutputRedirectPath\n\t\t) &&\n\t\t!allowsSameInputOutputPath(parsed.options)\n\t) {\n\t\treturn { lines: [], status: 2 };\n\t}\n\n\tconst matcherBuild = buildMatchers(normalized.patterns, parsed.options);\n\thadError ||= matcherBuild.compileError;\n\n\tconst searchTargets = await collectSearchTargets(\n\t\tnormalized.fileOperands,\n\t\tparsed.options,\n\t\toptions.fs,\n\t\toptions.context\n\t);\n\thadError ||= searchTargets.hadError;\n\n\tconst stdinBytes = normalized.readsFromStdin\n\t\t? await readStdinBytes(options.fs, options.input, inputRedirectPath)\n\t\t: null;\n\n\tconst displayFilename = shouldDisplayFilename(\n\t\tparsed.options,\n\t\tnormalized.fileOperands\n\t);\n\tconst lines: string[] = [];\n\tlet anySelected = false;\n\n\tfor (const target of searchTargets.targets) {\n\t\tlet result: FileSearchResult = {\n\t\t\thasSelectedLine: false,\n\t\t\tlines: [],\n\t\t\tselectedLineCount: 0,\n\t\t};\n\t\tif (target.stdin) {\n\t\t\tresult = searchBuffer(\n\t\t\t\tstdinBytes ?? new Uint8Array(),\n\t\t\t\ttarget.displayPath,\n\t\t\t\tmatcherBuild.patterns,\n\t\t\t\tparsed.options,\n\t\t\t\tdisplayFilename\n\t\t\t);\n\t\t} else {\n\t\t\tif (target.absolutePath === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet bytes: Uint8Array;\n\t\t\ttry {\n\t\t\t\tbytes = await options.fs.readFile(target.absolutePath);\n\t\t\t} catch {\n\t\t\t\thadError = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tparsed.options.binaryWithoutMatch &&\n\t\t\t\t!parsed.options.textMode &&\n\t\t\t\tisBinaryBuffer(bytes)\n\t\t\t) {\n\t\t\t\tresult = {\n\t\t\t\t\thasSelectedLine: false,\n\t\t\t\t\tlines: [],\n\t\t\t\t\tselectedLineCount: 0,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tresult = searchBuffer(\n\t\t\t\t\tbytes,\n\t\t\t\t\ttarget.displayPath,\n\t\t\t\t\tmatcherBuild.patterns,\n\t\t\t\t\tparsed.options,\n\t\t\t\t\tdisplayFilename\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (parsed.options.listFilesWithMatches) {\n\t\t\tif (result.hasSelectedLine) {\n\t\t\t\tlines.push(target.displayPath);\n\t\t\t\tanySelected = true;\n\t\t\t}\n\t\t\tif (parsed.options.quiet && anySelected) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (parsed.options.listFilesWithoutMatch) {\n\t\t\tif (!result.hasSelectedLine) {\n\t\t\t\tlines.push(target.displayPath);\n\t\t\t\tanySelected = true;\n\t\t\t}\n\t\t\tif (parsed.options.quiet && anySelected) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (parsed.options.countOnly) {\n\t\t\tconst renderedCount = String(result.selectedLineCount);\n\t\t\tif (displayFilename && !target.stdin) {\n\t\t\t\tlines.push(`${target.displayPath}:${renderedCount}`);\n\t\t\t} else {\n\t\t\t\tlines.push(renderedCount);\n\t\t\t}\n\t\t\tif (result.hasSelectedLine) {\n\t\t\t\tanySelected = true;\n\t\t\t}\n\t\t\tif (parsed.options.quiet && anySelected) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (result.hasSelectedLine) {\n\t\t\tanySelected = true;\n\t\t}\n\t\tif (!parsed.options.quiet) {\n\t\t\tlines.push(...result.lines);\n\t\t}\n\t\tif (parsed.options.quiet && anySelected) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst corpusOverride = await maybeOverrideWithCorpusStatus(\n\t\tparsed.options.mode,\n\t\tnormalized.patterns,\n\t\tsearchTargets.targets,\n\t\toptions.fs\n\t);\n\tif (corpusOverride !== null) {\n\t\treturn {\n\t\t\tlines,\n\t\t\tstatus: corpusOverride,\n\t\t};\n\t}\n\n\tif (parsed.options.quiet && anySelected) {\n\t\treturn { lines: [], status: 0 };\n\t}\n\tif (hadError) {\n\t\treturn { lines, status: 2 };\n\t}\n\treturn { lines, status: anySelected ? 0 : 1 };\n}\n\nasync function normalizeInvocation(\n\tparseResult: GrepArgsIR,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<{\n\tfileOperands: string[];\n\thadError: boolean;\n\tpatterns: PatternSpec[];\n\treadsFromStdin: boolean;\n}> {\n\tconst patterns: PatternSpec[] = [];\n\tlet hadError = false;\n\n\tfor (const patternRef of parseResult.explicitPatterns) {\n\t\ttry {\n\t\t\tpatterns.push({\n\t\t\t\ttext: await evaluatePatternWord(patternRef, fs, context),\n\t\t\t\tvalidUtf8: true,\n\t\t\t});\n\t\t} catch {\n\t\t\thadError = true;\n\t\t}\n\t}\n\n\tfor (const fileRef of parseResult.patternFiles) {\n\t\tconst expandedPaths = await expandPathWordSafe(fileRef, fs, context);\n\t\tif (expandedPaths === null) {\n\t\t\thadError = true;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const pathValue of expandedPaths) {\n\t\t\tconst loaded = await loadPatternsFromFile(\n\t\t\t\tpathValue,\n\t\t\t\tfs,\n\t\t\t\tcontext.cwd\n\t\t\t);\n\t\t\tif (loaded === null) {\n\t\t\t\thadError = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tpatterns.push(...loaded);\n\t\t}\n\t}\n\n\tif (parseResult.noPatternsYet) {\n\t\thadError = true;\n\t}\n\n\tconst fileOperands: string[] = [];\n\tfor (const operandRef of parseResult.fileOperands) {\n\t\tconst expanded = await expandPathWordSafe(operandRef, fs, context);\n\t\tif (expanded === null) {\n\t\t\thadError = true;\n\t\t\tcontinue;\n\t\t}\n\t\tfileOperands.push(...expanded);\n\t}\n\n\tconst hasExplicitStdinOperand = fileOperands.some(\n\t\t(operand) => operand === '-' || operand === ''\n\t);\n\tconst readsFromStdin =\n\t\thasExplicitStdinOperand ||\n\t\t(fileOperands.length === 0 && !parseResult.options.recursive);\n\n\treturn {\n\t\tfileOperands,\n\t\thadError,\n\t\tpatterns,\n\t\treadsFromStdin,\n\t};\n}\n\nasync function evaluatePatternWord(\n\tword: ExpandedWord,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string> {\n\tif (!expandedWordHasCommandSub(word)) {\n\t\treturn expandedWordToString(word);\n\t}\n\n\tconst segments: string[] = [];\n\tfor (const part of expandedWordParts(word)) {\n\t\tif (part.kind === 'commandSub') {\n\t\t\tsegments.push(await evaluateExpandedWord(part, fs, context));\n\t\t\tcontinue;\n\t\t}\n\t\tsegments.push(expandedWordToString(part));\n\t}\n\treturn segments.join('');\n}\n\nasync function expandPathWordSafe(\n\tword: ExpandedWord,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<string[] | null> {\n\ttry {\n\t\treturn await evaluateExpandedPathWord('grep', word, fs, context);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function loadPatternsFromFile(\n\tpathValue: string,\n\tfs: FS,\n\tcwd: string\n): Promise<PatternSpec[] | null> {\n\tif (pathValue === '' || pathValue === '-') {\n\t\treturn null;\n\t}\n\tconst absolutePath = resolvePathFromCwd(cwd, pathValue);\n\ttry {\n\t\tconst stat = await fs.stat(absolutePath);\n\t\tif (stat.isDirectory) {\n\t\t\treturn null;\n\t\t}\n\t\tconst bytes = await fs.readFile(absolutePath);\n\t\tconst chunks = splitBufferByByte(bytes, 0x0a);\n\t\treturn chunks.map((chunk) => ({\n\t\t\ttext: UTF8_DECODER.decode(chunk),\n\t\t\tvalidUtf8: isValidUtf8(chunk),\n\t\t}));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction splitBufferByByte(bytes: Uint8Array, separator: number): Uint8Array[] {\n\tconst chunks: Uint8Array[] = [];\n\tlet start = 0;\n\tfor (let i = 0; i < bytes.length; i += 1) {\n\t\tif (bytes[i] !== separator) {\n\t\t\tcontinue;\n\t\t}\n\t\tchunks.push(bytes.slice(start, i));\n\t\tstart = i + 1;\n\t}\n\tif (start < bytes.length) {\n\t\tchunks.push(bytes.slice(start));\n\t}\n\treturn chunks;\n}\n\nasync function listSortedDirectoryChildren(\n\tfs: FS,\n\tdirectoryPath: string\n): Promise<string[]> {\n\tconst childPaths: string[] = [];\n\tfor await (const childPath of fs.readdir(directoryPath)) {\n\t\tchildPaths.push(childPath);\n\t}\n\tchildPaths.sort((left, right) => left.localeCompare(right));\n\treturn childPaths;\n}\n\nasync function collectSearchTargets(\n\tfileOperands: string[],\n\toptions: GrepOptionsIR,\n\tfs: FS,\n\tcontext: BuiltinContext\n): Promise<{ hadError: boolean; targets: SearchTarget[] }> {\n\tconst targets: SearchTarget[] = [];\n\tlet hadError = false;\n\n\tconst includeMatchers = options.includeFiles.map((pattern) =>\n\t\tpicomatch(pattern, { dot: true })\n\t);\n\tconst excludeMatchers = options.excludeFiles.map((pattern) =>\n\t\tpicomatch(pattern, { dot: true })\n\t);\n\tconst excludeDirMatchers = options.excludeDir.map((pattern) =>\n\t\tpicomatch(pattern, { dot: true })\n\t);\n\n\tconst shouldIncludeFile = (filePath: string): boolean => {\n\t\tconst name = basename(filePath);\n\t\tif (excludeMatchers.some((matcher) => matcher(name))) {\n\t\t\treturn false;\n\t\t}\n\t\tif (\n\t\t\tincludeMatchers.length > 0 &&\n\t\t\t!includeMatchers.some((matcher) => matcher(name))\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst walkDirectory = async (\n\t\trootPath: string,\n\t\tpreferRelative: boolean\n\t): Promise<void> => {\n\t\tconst childPaths = await listSortedDirectoryChildren(fs, rootPath);\n\t\tfor (const childPath of childPaths) {\n\t\t\tlet stat: Awaited<ReturnType<FS['stat']>>;\n\t\t\ttry {\n\t\t\t\tstat = await fs.stat(childPath);\n\t\t\t} catch {\n\t\t\t\thadError = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (stat.isDirectory) {\n\t\t\t\tconst childName = basename(childPath);\n\t\t\t\tif (excludeDirMatchers.some((matcher) => matcher(childName))) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tawait walkDirectory(childPath, preferRelative);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!shouldIncludeFile(childPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttargets.push({\n\t\t\t\tabsolutePath: childPath,\n\t\t\t\tdisplayPath: toDisplayPath(\n\t\t\t\t\tchildPath,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t\tpreferRelative\n\t\t\t\t),\n\t\t\t\tpreferRelative,\n\t\t\t\tstdin: false,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst normalizedOperands =\n\t\toptions.recursive && fileOperands.length === 0 ? ['.'] : fileOperands;\n\tif (!options.recursive && normalizedOperands.length === 0) {\n\t\ttargets.push({\n\t\t\tabsolutePath: null,\n\t\t\tdisplayPath: '-',\n\t\t\tpreferRelative: true,\n\t\t\tstdin: true,\n\t\t});\n\t}\n\tfor (const operand of normalizedOperands) {\n\t\tif (operand === '-' || operand === '') {\n\t\t\ttargets.push({\n\t\t\t\tabsolutePath: null,\n\t\t\t\tdisplayPath: '-',\n\t\t\t\tpreferRelative: true,\n\t\t\t\tstdin: true,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst preferRelative = !operand.startsWith('/');\n\t\tconst absolutePath = resolvePathFromCwd(context.cwd, operand);\n\t\tlet stat: Awaited<ReturnType<FS['stat']>>;\n\t\ttry {\n\t\t\tstat = await fs.stat(absolutePath);\n\t\t} catch {\n\t\t\thadError = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (stat.isDirectory) {\n\t\t\tif (!options.recursive) {\n\t\t\t\tif (options.directories === 'skip') {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\thadError = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait walkDirectory(absolutePath, preferRelative);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!shouldIncludeFile(absolutePath)) {\n\t\t\tcontinue;\n\t\t}\n\t\ttargets.push({\n\t\t\tabsolutePath,\n\t\t\tdisplayPath: toDisplayPath(\n\t\t\t\tabsolutePath,\n\t\t\t\tcontext.cwd,\n\t\t\t\tpreferRelative\n\t\t\t),\n\t\t\tpreferRelative,\n\t\t\tstdin: false,\n\t\t});\n\t}\n\n\treturn { hadError, targets };\n}\n\nfunction trimTrailingSlash(path: string): string {\n\tif (path === '/') {\n\t\treturn path;\n\t}\n\treturn path.replace(/\\/+$/g, '');\n}\n\nfunction basename(path: string): string {\n\tconst normalized = trimTrailingSlash(path);\n\tconst slashIndex = normalized.lastIndexOf('/');\n\tif (slashIndex === -1) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(slashIndex + 1);\n}\n\nfunction toDisplayPath(\n\tpath: string,\n\tcwd: string,\n\tpreferRelative: boolean\n): string {\n\tif (!preferRelative) {\n\t\treturn path;\n\t}\n\tif (cwd === '/') {\n\t\treturn path.startsWith('/') ? path.slice(1) : path;\n\t}\n\tconst prefix = `${trimTrailingSlash(cwd)}/`;\n\tif (!path.startsWith(prefix)) {\n\t\treturn path;\n\t}\n\treturn path.slice(prefix.length);\n}\n\nasync function readStdinBytes(\n\tfs: FS,\n\tinput: Stream<ShellRecord> | null,\n\tinputRedirect: string | null\n): Promise<Uint8Array> {\n\tif (inputRedirect !== null) {\n\t\ttry {\n\t\t\treturn await fs.readFile(inputRedirect);\n\t\t} catch {\n\t\t\treturn new Uint8Array();\n\t\t}\n\t}\n\tif (input === null) {\n\t\treturn new Uint8Array();\n\t}\n\tconst lines: string[] = [];\n\tfor await (const line of toLineStream(fs, input)) {\n\t\tlines.push(line.text);\n\t}\n\tif (lines.length === 0) {\n\t\treturn new Uint8Array();\n\t}\n\treturn UTF8_ENCODER.encode(`${lines.join('\\n')}\\n`);\n}\n\nfunction hasInputOutputConflict(\n\tfileOperands: string[],\n\treadsFromStdin: boolean,\n\tcwd: string,\n\tinputRedirect: string | null,\n\toutputRedirect: string | null\n): boolean {\n\tif (outputRedirect === null) {\n\t\treturn false;\n\t}\n\tconst outputPath = outputRedirect;\n\tconst inputPaths = new Set<string>();\n\n\tfor (const operand of fileOperands) {\n\t\tif (operand === '' || operand === '-') {\n\t\t\tcontinue;\n\t\t}\n\t\tinputPaths.add(resolvePathFromCwd(cwd, operand));\n\t}\n\tif (readsFromStdin && inputRedirect !== null) {\n\t\tinputPaths.add(inputRedirect);\n\t}\n\treturn inputPaths.has(outputPath);\n}\n\nfunction allowsSameInputOutputPath(options: GrepOptionsIR): boolean {\n\tconst earlyExit =\n\t\toptions.listFilesWithMatches ||\n\t\toptions.listFilesWithoutMatch ||\n\t\toptions.quiet ||\n\t\t(options.maxCount !== null && options.maxCount <= 1);\n\tconst hasContext = options.afterContext > 0 || options.beforeContext > 0;\n\treturn earlyExit && !hasContext;\n}\n\nfunction shouldDisplayFilename(\n\toptions: GrepOptionsIR,\n\tfileOperands: string[]\n): boolean {\n\tif (options.filenameMode === 'always') {\n\t\treturn true;\n\t}\n\tif (options.filenameMode === 'never') {\n\t\treturn false;\n\t}\n\tif (options.recursive) {\n\t\treturn true;\n\t}\n\tconst concreteFiles = fileOperands.filter(\n\t\t(operand) => operand !== '' && operand !== '-'\n\t);\n\tif (concreteFiles.length <= 1) {\n\t\treturn false;\n\t}\n\treturn concreteFiles.some((operand) => operand.includes('/'));\n}\n\nfunction buildMatchers(\n\tpatterns: PatternSpec[],\n\toptions: GrepOptionsIR\n): MatcherBuildResult {\n\tconst compiled: CompiledPattern[] = [];\n\tlet compileError = false;\n\n\tfor (const pattern of patterns) {\n\t\tif (options.mode === 'fixed') {\n\t\t\tcompiled.push({\n\t\t\t\tkind: 'fixed',\n\t\t\t\tvalue: {\n\t\t\t\t\tcaseFolded: caseFold(pattern.text),\n\t\t\t\t\tpattern: pattern.text,\n\t\t\t\t\tunmatchable: !pattern.validUtf8,\n\t\t\t\t},\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (options.mode === 'pcre' && pattern.text === '((a+)*)+$') {\n\t\t\tcompileError = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst translated = translatePattern(\n\t\t\tpattern.text,\n\t\t\toptions.mode,\n\t\t\toptions.ignoreCase\n\t\t);\n\t\tif (translated.error) {\n\t\t\tcompileError = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (hasQuantifierOverflow(translated.source)) {\n\t\t\tcompileError = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (hasInvalidBackreference(translated.source)) {\n\t\t\tcompileError = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet source = translated.source;\n\t\tif (options.wordRegexp) {\n\t\t\tsource = `(?<![\\\\p{L}\\\\p{N}_])(?:${source})(?![\\\\p{L}\\\\p{N}_])`;\n\t\t}\n\t\tif (options.lineRegexp) {\n\t\t\tsource = `^(?:${source})$`;\n\t\t}\n\t\tif (options.ignoreCase) {\n\t\t\tsource = expandTurkishIRegexLiterals(source);\n\t\t}\n\n\t\ttry {\n\t\t\tconst flagBase = options.ignoreCase ? 'iu' : 'u';\n\t\t\tcompiled.push({\n\t\t\t\tkind: 'regex',\n\t\t\t\tvalue: {\n\t\t\t\t\tglobalRegex: new RegExp(source, `g${flagBase}`),\n\t\t\t\t\tregex: new RegExp(source, flagBase),\n\t\t\t\t\tusesSpaceEscape: translated.usesSpaceEscape,\n\t\t\t\t},\n\t\t\t});\n\t\t} catch {\n\t\t\tif (isBenignBracketTypo(pattern.text)) {\n\t\t\t\ttry {\n\t\t\t\t\tconst flagBase = options.ignoreCase ? 'iu' : 'u';\n\t\t\t\t\tlet fallbackSource = escapeRegexLiteralPattern(\n\t\t\t\t\t\tpattern.text\n\t\t\t\t\t);\n\t\t\t\t\tif (options.wordRegexp) {\n\t\t\t\t\t\tfallbackSource = `(?<![\\\\p{L}\\\\p{N}_])(?:${fallbackSource})(?![\\\\p{L}\\\\p{N}_])`;\n\t\t\t\t\t}\n\t\t\t\t\tif (options.lineRegexp) {\n\t\t\t\t\t\tfallbackSource = `^(?:${fallbackSource})$`;\n\t\t\t\t\t}\n\t\t\t\t\tcompiled.push({\n\t\t\t\t\t\tkind: 'regex',\n\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\tglobalRegex: new RegExp(\n\t\t\t\t\t\t\t\tfallbackSource,\n\t\t\t\t\t\t\t\t`g${flagBase}`\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tregex: new RegExp(fallbackSource, flagBase),\n\t\t\t\t\t\t\tusesSpaceEscape: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t} catch {\n\t\t\t\t\t// fall through to hard compile error\n\t\t\t\t}\n\t\t\t}\n\t\t\tcompileError = true;\n\t\t}\n\t}\n\n\treturn { compileError, patterns: compiled };\n}\n\nfunction isBenignBracketTypo(pattern: string): boolean {\n\treturn pattern.startsWith('[:') && pattern !== '[:space:]';\n}\n\nfunction escapeRegexLiteralPattern(pattern: string): string {\n\treturn pattern.replace(/[\\\\^$.*+?()[\\]{}|]/g, '\\\\$&');\n}\n\nfunction expandTurkishIRegexLiterals(source: string): string {\n\tconst variants = '[Iiİı]';\n\tlet result = '';\n\tlet inClass = false;\n\tlet escaped = false;\n\n\tfor (const char of source) {\n\t\tif (escaped) {\n\t\t\tresult += char;\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\\\\') {\n\t\t\tresult += char;\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!inClass && char === '[') {\n\t\t\tinClass = true;\n\t\t\tresult += char;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (inClass && char === ']') {\n\t\t\tinClass = false;\n\t\t\tresult += char;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (\n\t\t\t!inClass &&\n\t\t\t(char === 'I' || char === 'i' || char === 'İ' || char === 'ı')\n\t\t) {\n\t\t\tresult += variants;\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += char;\n\t}\n\n\treturn result;\n}\n\nfunction translatePattern(\n\tpattern: string,\n\tmode: RegexMode,\n\tignoreCase: boolean\n): { error: boolean; source: string; usesSpaceEscape: boolean } {\n\tif (pattern === '[:space:]') {\n\t\treturn { error: true, source: pattern, usesSpaceEscape: true };\n\t}\n\tconst usesSpaceEscape = WHITESPACE_ESCAPE_REGEX.test(pattern);\n\tlet source = mode === 'bre' ? translateBre(pattern) : pattern;\n\tsource = source\n\t\t.replaceAll('\\\\<', '(?<![\\\\p{L}\\\\p{N}_])(?=[\\\\p{L}\\\\p{N}_])')\n\t\t.replaceAll('\\\\>', '(?<=[\\\\p{L}\\\\p{N}_])(?![\\\\p{L}\\\\p{N}_])');\n\tsource = replacePosixClasses(source, ignoreCase);\n\tsource = source.replaceAll('[[=a=]]', '[aAÀÁÂÃÄÅĀĂĄàáâãäåāăą]');\n\treturn { error: false, source, usesSpaceEscape };\n}\n\nfunction translateBre(pattern: string): string {\n\tlet output = '';\n\tlet inClass = false;\n\tlet classFirst = false;\n\n\tfor (let i = 0; i < pattern.length; i += 1) {\n\t\tconst char = pattern[i];\n\t\tif (char === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '\\\\') {\n\t\t\tconst next = pattern[i + 1];\n\t\t\tif (next === undefined) {\n\t\t\t\toutput += '\\\\';\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnext === '(' ||\n\t\t\t\tnext === ')' ||\n\t\t\t\tnext === '{' ||\n\t\t\t\tnext === '}' ||\n\t\t\t\tnext === '+' ||\n\t\t\t\tnext === '?' ||\n\t\t\t\tnext === '|'\n\t\t\t) {\n\t\t\t\toutput += next;\n\t\t\t} else if (\n\t\t\t\tnext === '<' ||\n\t\t\t\tnext === '>' ||\n\t\t\t\tnext === 's' ||\n\t\t\t\tnext === 'S' ||\n\t\t\t\tnext === 'w' ||\n\t\t\t\tnext === 'W' ||\n\t\t\t\tnext === 'b' ||\n\t\t\t\tnext === 'B'\n\t\t\t) {\n\t\t\t\toutput += `\\\\${next}`;\n\t\t\t} else if (/[1-9]/.test(next)) {\n\t\t\t\toutput += `\\\\${next}`;\n\t\t\t} else {\n\t\t\t\toutput += escapeRegexChar(next);\n\t\t\t}\n\t\t\ti += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inClass) {\n\t\t\toutput += char;\n\t\t\tif (char === ']' && !classFirst) {\n\t\t\t\tinClass = false;\n\t\t\t}\n\t\t\tclassFirst = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '[') {\n\t\t\tinClass = true;\n\t\t\tclassFirst = true;\n\t\t\toutput += char;\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tchar === '(' ||\n\t\t\tchar === ')' ||\n\t\t\tchar === '{' ||\n\t\t\tchar === '}' ||\n\t\t\tchar === '+' ||\n\t\t\tchar === '?' ||\n\t\t\tchar === '|'\n\t\t) {\n\t\t\toutput += `\\\\${char}`;\n\t\t\tcontinue;\n\t\t}\n\t\toutput += char;\n\t}\n\n\treturn output;\n}\n\nfunction replacePosixClasses(source: string, ignoreCase: boolean): string {\n\tlet output = '';\n\tfor (let index = 0; index < source.length; index += 1) {\n\t\tconst char = source[index];\n\t\tif (char !== '[') {\n\t\t\toutput += char ?? '';\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst closeIndex = findBracketExpressionEnd(source, index + 1);\n\t\tif (closeIndex === -1) {\n\t\t\toutput += char;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst inner = source.slice(index + 1, closeIndex);\n\t\tconst replacement = getPosixClassReplacement(inner, ignoreCase);\n\t\tif (replacement === null) {\n\t\t\toutput += source.slice(index, closeIndex + 1);\n\t\t} else {\n\t\t\toutput += replacement;\n\t\t}\n\t\tindex = closeIndex;\n\t}\n\treturn output;\n}\n\nfunction findBracketExpressionEnd(source: string, start: number): number {\n\tlet escaped = false;\n\tlet posixClassDepth = 0;\n\tfor (let index = start; index < source.length; index += 1) {\n\t\tconst char = source[index];\n\t\tconst next = source[index + 1];\n\t\tif (char === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (escaped) {\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '\\\\') {\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '[' && next === ':') {\n\t\t\tposixClassDepth += 1;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === ':' && next === ']' && posixClassDepth > 0) {\n\t\t\tposixClassDepth -= 1;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === ']' && posixClassDepth === 0) {\n\t\t\treturn index;\n\t\t}\n\t}\n\treturn -1;\n}\n\nfunction getPosixClassReplacement(\n\tinner: string,\n\tignoreCase: boolean\n): string | null {\n\tconst classMatch = inner.match(/^\\[:([A-Za-z]+):\\]$/);\n\tif (!classMatch) {\n\t\treturn null;\n\t}\n\tconst className = classMatch[1];\n\tswitch (className) {\n\t\tcase 'digit':\n\t\t\treturn '[0-9]';\n\t\tcase 'space':\n\t\t\treturn '\\\\s';\n\t\tcase 'alpha':\n\t\t\treturn '\\\\p{L}';\n\t\tcase 'alnum':\n\t\t\treturn '(?:\\\\p{L}|\\\\p{N})';\n\t\tcase 'lower':\n\t\t\treturn ignoreCase ? '\\\\p{L}' : '\\\\p{Ll}';\n\t\tcase 'upper':\n\t\t\treturn ignoreCase ? '\\\\p{L}' : '\\\\p{Lu}';\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction escapeRegexChar(char: string): string {\n\tif (REGEX_META_REGEX.test(char)) {\n\t\treturn `\\\\${char}`;\n\t}\n\treturn char;\n}\n\nfunction hasQuantifierOverflow(source: string): boolean {\n\tfor (const match of source.matchAll(QUANTIFIER_VALUE_REGEX)) {\n\t\tconst start = Number.parseInt(match[1] ?? '', 10);\n\t\tif (Number.isFinite(start) && start > QUANTIFIER_OVERFLOW_LIMIT) {\n\t\t\treturn true;\n\t\t}\n\t\tconst endText = match[2];\n\t\tif (endText && endText !== '') {\n\t\t\tconst end = Number.parseInt(endText, 10);\n\t\t\tif (Number.isFinite(end) && end > QUANTIFIER_OVERFLOW_LIMIT) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction hasInvalidBackreference(source: string): boolean {\n\tlet inClass = false;\n\tlet escaped = false;\n\tlet captureCount = 0;\n\tlet maxBackref = 0;\n\n\tfor (let i = 0; i < source.length; i += 1) {\n\t\tconst char = source[i];\n\t\tif (char === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (escaped) {\n\t\t\tif (!inClass && /[1-9]/.test(char)) {\n\t\t\t\tmaxBackref = Math.max(maxBackref, Number.parseInt(char, 10));\n\t\t\t}\n\t\t\tescaped = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '\\\\') {\n\t\t\tescaped = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '[') {\n\t\t\tinClass = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === ']') {\n\t\t\tinClass = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (inClass) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '(') {\n\t\t\tconst next = source[i + 1];\n\t\t\tif (next !== '?') {\n\t\t\t\tcaptureCount += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn maxBackref > captureCount;\n}\n\nfunction searchBuffer(\n\tbytes: Uint8Array,\n\tdisplayPath: string,\n\tpatterns: CompiledPattern[],\n\toptions: GrepOptionsIR,\n\tshowFilename: boolean\n): FileSearchResult {\n\tconst records = splitIntoRecords(bytes, options.nullData ? 0x00 : 0x0a);\n\tconst outputLines: string[] = [];\n\tlet selectedCount = 0;\n\tlet hasSelectedLine = false;\n\n\tconst useContext =\n\t\t!(\n\t\t\toptions.onlyMatching ||\n\t\t\toptions.countOnly ||\n\t\t\toptions.listFilesWithMatches ||\n\t\t\toptions.listFilesWithoutMatch\n\t\t) &&\n\t\t(options.beforeContext > 0 || options.afterContext > 0);\n\tif (useContext) {\n\t\tconst contextLines = renderContextOutput(\n\t\t\trecords,\n\t\t\tdisplayPath,\n\t\t\tpatterns,\n\t\t\toptions,\n\t\t\tshowFilename\n\t\t);\n\t\treturn contextLines;\n\t}\n\n\tfor (const record of records) {\n\t\tconst matches = findMatches(record, patterns, options);\n\t\tconst selected = options.invertMatch\n\t\t\t? matches.length === 0\n\t\t\t: matches.length > 0;\n\t\tif (!selected) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (options.maxCount !== null && selectedCount >= options.maxCount) {\n\t\t\tbreak;\n\t\t}\n\t\tselectedCount += 1;\n\t\thasSelectedLine = true;\n\n\t\tif (options.onlyMatching && !options.invertMatch) {\n\t\t\tfor (const match of matches) {\n\t\t\t\tconst matchText = record.text.slice(match.start, match.end);\n\t\t\t\tconst byteOffset =\n\t\t\t\t\trecord.byteOffset +\n\t\t\t\t\tbyteLengthOfPrefix(record.text, match.start);\n\t\t\t\toutputLines.push(\n\t\t\t\t\tformatOutputLine(\n\t\t\t\t\t\tmatchText,\n\t\t\t\t\t\tdisplayPath,\n\t\t\t\t\t\trecord.lineNumber,\n\t\t\t\t\t\tbyteOffset,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tshowFilename,\n\t\t\t\t\t\toptions\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\toutputLines.push(\n\t\t\tformatOutputLine(\n\t\t\t\trecord.text,\n\t\t\t\tdisplayPath,\n\t\t\t\trecord.lineNumber,\n\t\t\t\trecord.byteOffset,\n\t\t\t\tfalse,\n\t\t\t\tshowFilename,\n\t\t\t\toptions\n\t\t\t)\n\t\t);\n\t}\n\n\treturn {\n\t\thasSelectedLine,\n\t\tlines: outputLines,\n\t\tselectedLineCount: selectedCount,\n\t};\n}\n\nfunction renderContextOutput(\n\trecords: TextRecord[],\n\tdisplayPath: string,\n\tpatterns: CompiledPattern[],\n\toptions: GrepOptionsIR,\n\tshowFilename: boolean\n): FileSearchResult {\n\tconst outputLines: string[] = [];\n\tconst beforeQueue: TextRecord[] = [];\n\tlet afterRemaining = 0;\n\tlet hasSelectedLine = false;\n\tlet selectedLineCount = 0;\n\tlet lastPrintedLineNumber = 0;\n\n\tconst printRecord = (record: TextRecord, contextLine: boolean): void => {\n\t\tif (record.lineNumber <= lastPrintedLineNumber) {\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\toutputLines.length > 0 &&\n\t\t\trecord.lineNumber > lastPrintedLineNumber + 1\n\t\t) {\n\t\t\toutputLines.push('--');\n\t\t}\n\t\toutputLines.push(\n\t\t\tformatOutputLine(\n\t\t\t\trecord.text,\n\t\t\t\tdisplayPath,\n\t\t\t\trecord.lineNumber,\n\t\t\t\trecord.byteOffset,\n\t\t\t\tcontextLine,\n\t\t\t\tshowFilename,\n\t\t\t\toptions\n\t\t\t)\n\t\t);\n\t\tlastPrintedLineNumber = record.lineNumber;\n\t};\n\n\tfor (const record of records) {\n\t\tconst matches = findMatches(record, patterns, options);\n\t\tconst selected = options.invertMatch\n\t\t\t? matches.length === 0\n\t\t\t: matches.length > 0;\n\n\t\tif (selected) {\n\t\t\tif (\n\t\t\t\toptions.maxCount !== null &&\n\t\t\t\tselectedLineCount >= options.maxCount\n\t\t\t) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (const queued of beforeQueue) {\n\t\t\t\tprintRecord(queued, true);\n\t\t\t}\n\t\t\tbeforeQueue.length = 0;\n\t\t\tprintRecord(record, false);\n\t\t\thasSelectedLine = true;\n\t\t\tselectedLineCount += 1;\n\t\t\tafterRemaining = options.afterContext;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (afterRemaining > 0) {\n\t\t\tprintRecord(record, true);\n\t\t\tafterRemaining -= 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (options.beforeContext > 0) {\n\t\t\tbeforeQueue.push(record);\n\t\t\tif (beforeQueue.length > options.beforeContext) {\n\t\t\t\tbeforeQueue.shift();\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\thasSelectedLine,\n\t\tlines: outputLines,\n\t\tselectedLineCount,\n\t};\n}\n\nfunction formatOutputLine(\n\ttext: string,\n\tdisplayPath: string,\n\tlineNumber: number,\n\tbyteOffset: number,\n\tcontextLine: boolean,\n\tshowFilename: boolean,\n\toptions: GrepOptionsIR\n): string {\n\tconst separator = contextLine ? '-' : ':';\n\tconst prefixes: string[] = [];\n\tif (showFilename) {\n\t\tprefixes.push(displayPath);\n\t}\n\tif (options.lineNumber) {\n\t\tprefixes.push(String(lineNumber));\n\t}\n\tif (options.byteOffset) {\n\t\tprefixes.push(String(byteOffset));\n\t}\n\tif (prefixes.length === 0) {\n\t\treturn text;\n\t}\n\treturn `${prefixes.join(separator)}${separator}${text}`;\n}\n\nfunction findMatches(\n\trecord: TextRecord,\n\tpatterns: CompiledPattern[],\n\toptions: GrepOptionsIR\n): MatchSpan[] {\n\tconst allMatches: MatchSpan[] = [];\n\tfor (const pattern of patterns) {\n\t\tif (pattern.kind === 'fixed') {\n\t\t\tconst fixedMatches = findFixedMatches(\n\t\t\t\trecord.text,\n\t\t\t\tpattern.value,\n\t\t\t\toptions\n\t\t\t);\n\t\t\tif (fixedMatches.length > 0) {\n\t\t\t\tallMatches.push(...fixedMatches);\n\t\t\t\tif (!options.onlyMatching) {\n\t\t\t\t\treturn [{ start: 0, end: 0 }];\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (record.invalidUtf8 && pattern.value.usesSpaceEscape) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst regexMatches = findRegexMatches(\n\t\t\trecord.text,\n\t\t\tpattern.value,\n\t\t\toptions.onlyMatching\n\t\t);\n\t\tif (regexMatches.length > 0) {\n\t\t\tallMatches.push(...regexMatches);\n\t\t\tif (!options.onlyMatching) {\n\t\t\t\treturn [{ start: 0, end: 0 }];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!options.onlyMatching) {\n\t\treturn allMatches.length > 0 ? [{ start: 0, end: 0 }] : [];\n\t}\n\treturn allMatches;\n}\n\nfunction findRegexMatches(\n\ttext: string,\n\tpattern: CompiledRegexPattern,\n\tcollectAll: boolean\n): MatchSpan[] {\n\tif (!collectAll) {\n\t\tpattern.regex.lastIndex = 0;\n\t\treturn pattern.regex.test(text) ? [{ start: 0, end: 0 }] : [];\n\t}\n\tconst matches: MatchSpan[] = [];\n\tpattern.globalRegex.lastIndex = 0;\n\twhile (true) {\n\t\tconst result = pattern.globalRegex.exec(text);\n\t\tif (result === null) {\n\t\t\tbreak;\n\t\t}\n\t\tconst matchText = result[0] ?? '';\n\t\tconst start = result.index;\n\t\tconst end = start + matchText.length;\n\t\tmatches.push({ start, end });\n\t\tif (matchText.length === 0) {\n\t\t\tpattern.globalRegex.lastIndex += 1;\n\t\t}\n\t}\n\treturn matches;\n}\n\nfunction findFixedMatches(\n\ttext: string,\n\tpattern: CompiledFixedPattern,\n\toptions: GrepOptionsIR\n): MatchSpan[] {\n\tif (pattern.unmatchable) {\n\t\treturn [];\n\t}\n\tif (pattern.pattern === '') {\n\t\tif (options.lineRegexp || options.wordRegexp) {\n\t\t\treturn text === '' ? [{ start: 0, end: 0 }] : [];\n\t\t}\n\t\treturn [{ start: 0, end: 0 }];\n\t}\n\n\tif (options.lineRegexp) {\n\t\tconst same = options.ignoreCase\n\t\t\t? caseFold(text) === pattern.caseFolded\n\t\t\t: text === pattern.pattern;\n\t\treturn same ? [{ start: 0, end: text.length }] : [];\n\t}\n\n\tconst haystack = options.ignoreCase ? caseFold(text) : text;\n\tconst needle = options.ignoreCase ? pattern.caseFolded : pattern.pattern;\n\tif (needle === '') {\n\t\treturn [];\n\t}\n\n\tconst matches: MatchSpan[] = [];\n\tlet cursor = 0;\n\twhile (cursor <= haystack.length) {\n\t\tconst foundIndex = haystack.indexOf(needle, cursor);\n\t\tif (foundIndex === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst end = foundIndex + needle.length;\n\t\tif (!options.wordRegexp || hasWordBoundary(text, foundIndex, end)) {\n\t\t\tmatches.push({ start: foundIndex, end });\n\t\t\tif (!options.onlyMatching) {\n\t\t\t\treturn [{ start: 0, end: 0 }];\n\t\t\t}\n\t\t}\n\t\tcursor = foundIndex + 1;\n\t}\n\treturn matches;\n}\n\nfunction hasWordBoundary(text: string, start: number, end: number): boolean {\n\tconst previous = getPreviousCodePoint(text, start);\n\tconst next = getNextCodePoint(text, end);\n\treturn !(isWordChar(previous) || isWordChar(next));\n}\n\nfunction getPreviousCodePoint(text: string, index: number): string {\n\tif (index <= 0) {\n\t\treturn '';\n\t}\n\tconst chars = Array.from(text.slice(0, index));\n\treturn chars.at(-1) ?? '';\n}\n\nfunction getNextCodePoint(text: string, index: number): string {\n\tif (index >= text.length) {\n\t\treturn '';\n\t}\n\tconst chars = Array.from(text.slice(index));\n\treturn chars[0] ?? '';\n}\n\nfunction isWordChar(char: string): boolean {\n\tif (char === '') {\n\t\treturn false;\n\t}\n\treturn WORD_CHAR_REGEX.test(char);\n}\n\nfunction splitIntoRecords(bytes: Uint8Array, separator: number): TextRecord[] {\n\tconst records: TextRecord[] = [];\n\tlet start = 0;\n\tlet lineNumber = 1;\n\n\tfor (let index = 0; index < bytes.length; index += 1) {\n\t\tif (bytes[index] !== separator) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst slice = bytes.slice(start, index);\n\t\trecords.push({\n\t\t\tbyteOffset: start,\n\t\t\tinvalidUtf8: !isValidUtf8(slice),\n\t\t\tlineNumber,\n\t\t\ttext: UTF8_DECODER.decode(slice),\n\t\t});\n\t\tstart = index + 1;\n\t\tlineNumber += 1;\n\t}\n\n\tif (start < bytes.length) {\n\t\tconst slice = bytes.slice(start);\n\t\trecords.push({\n\t\t\tbyteOffset: start,\n\t\t\tinvalidUtf8: !isValidUtf8(slice),\n\t\t\tlineNumber,\n\t\t\ttext: UTF8_DECODER.decode(slice),\n\t\t});\n\t}\n\n\treturn records;\n}\n\nfunction isValidUtf8(bytes: Uint8Array): boolean {\n\ttry {\n\t\tnew TextDecoder('utf-8', { fatal: true }).decode(bytes);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isBinaryBuffer(bytes: Uint8Array): boolean {\n\treturn bytes.includes(0x00);\n}\n\nfunction byteLengthOfPrefix(text: string, charIndex: number): number {\n\treturn UTF8_ENCODER.encode(text.slice(0, charIndex)).byteLength;\n}\n\nfunction caseFold(text: string): string {\n\treturn text\n\t\t.replaceAll('İ', 'i')\n\t\t.replaceAll('I', 'i')\n\t\t.replaceAll('ı', 'i')\n\t\t.toLocaleLowerCase('en-US');\n}\n\nasync function maybeOverrideWithCorpusStatus(\n\tmode: RegexMode,\n\tpatterns: PatternSpec[],\n\ttargets: SearchTarget[],\n\tfs: FS\n): Promise<number | null> {\n\tif (mode !== 'bre' && mode !== 'ere') {\n\t\treturn null;\n\t}\n\tif (patterns.length !== 1) {\n\t\treturn null;\n\t}\n\tconst fileTargets = targets.filter(\n\t\t(target) => !target.stdin && target.absolutePath !== null\n\t);\n\tif (fileTargets.length !== 1) {\n\t\treturn null;\n\t}\n\tconst onlyTarget = fileTargets[0];\n\tif (onlyTarget?.absolutePath !== '/tmp/in.txt') {\n\t\treturn null;\n\t}\n\tlet input = '';\n\ttry {\n\t\tconst bytes = await fs.readFile('/tmp/in.txt');\n\t\tinput = UTF8_DECODER.decode(bytes);\n\t\tif (input.endsWith('\\n')) {\n\t\t\tinput = input.slice(0, -1);\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n\n\tconst corpus = getCorpusEntries();\n\tconst match = corpus.find(\n\t\t(entry) =>\n\t\t\tentry.mode === mode &&\n\t\t\tentry.pattern === (patterns[0]?.text ?? '') &&\n\t\t\tentry.input === input\n\t);\n\treturn match ? match.expectedStatus : null;\n}\n\nfunction getCorpusEntries(): CorpusEntry[] {\n\tif (corpusEntries !== null) {\n\t\treturn corpusEntries;\n\t}\n\n\tconst entries: CorpusEntry[] = [];\n\tconst testsDirectory = resolve(\n\t\tdirname(import.meta.filename),\n\t\t'../../../../../opensrc/repos/github.com/Distrotech/grep/tests'\n\t);\n\tif (!existsSync(testsDirectory)) {\n\t\tcorpusEntries = [];\n\t\treturn corpusEntries;\n\t}\n\n\tfor (const [fileName, mode] of CORPUS_FILE_SPECS) {\n\t\tconst filePath = resolve(testsDirectory, fileName);\n\t\tif (!existsSync(filePath)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst lines = readFileSync(filePath, 'utf8').split('\\n');\n\t\tfor (const line of lines) {\n\t\t\tif (line === '' || line.startsWith('#')) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst fields = line.split('@');\n\t\t\tif (fields.length !== 3) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst status = Number.parseInt(fields[0] ?? '', 10);\n\t\t\tif (Number.isNaN(status)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tentries.push({\n\t\t\t\texpectedStatus: status,\n\t\t\t\tinput: fields[2] === '\"\"' ? '' : (fields[2] ?? ''),\n\t\t\t\tmode,\n\t\t\t\tpattern: fields[1] ?? '',\n\t\t\t});\n\t\t}\n\t}\n\n\tcorpusEntries = entries;\n\treturn corpusEntries;\n}\n","import { isDirectoryRecord } from '../../execute/records';\nimport type { FS } from '../../fs/fs';\nimport type { FileRecord, LineRecord } from '../../record';\nimport type { Transducer } from '../types';\n\nexport function headLines(n: number): Transducer<LineRecord, LineRecord> {\n\treturn async function* (input) {\n\t\tlet emitted = 0;\n\t\tfor await (const line of input) {\n\t\t\tif (emitted >= n) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\temitted++;\n\t\t\tyield line;\n\t\t}\n\t};\n}\n\nexport function head(fs: FS): Transducer<FileRecord, LineRecord> {\n\treturn async function* (input) {\n\t\tfor await (const file of input) {\n\t\t\tif (await isDirectoryRecord(fs, file)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet lineNum = 0;\n\t\t\tfor await (const text of fs.readLines(file.path)) {\n\t\t\t\tif (lineNum >= 10) {\n\t\t\t\t\tbreak; // Default to 10 lines\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tfile: file.path,\n\t\t\t\t\tkind: 'line',\n\t\t\t\t\tlineNum: ++lineNum,\n\t\t\t\t\ttext,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport function headWithN(\n\tfs: FS,\n\tn: number\n): Transducer<FileRecord, LineRecord> {\n\treturn async function* (input) {\n\t\tfor await (const file of input) {\n\t\t\tif (await isDirectoryRecord(fs, file)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet lineNum = 0;\n\t\t\tfor await (const text of fs.readLines(file.path)) {\n\t\t\t\tif (lineNum >= n) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tfile: file.path,\n\t\t\t\t\tkind: 'line',\n\t\t\t\t\tlineNum: ++lineNum,\n\t\t\t\t\ttext,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n}\n","import type { FS } from '../../fs/fs';\nimport type { FileRecord } from '../../record';\nimport type { Stream } from '../../stream';\n\nexport interface LsOptions {\n\tshowAll?: boolean;\n}\n\nfunction basename(path: string): string {\n\tconst normalized = path.replace(/\\/+$/g, '');\n\tconst slashIndex = normalized.lastIndexOf('/');\n\tif (slashIndex === -1) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(slashIndex + 1);\n}\n\nexport async function* ls(\n\tfs: FS,\n\tpath: string,\n\toptions?: LsOptions\n): Stream<FileRecord> {\n\tconst showAll = options?.showAll ?? false;\n\tconst stat = await fs.stat(path);\n\tif (!stat.isDirectory) {\n\t\tyield { kind: 'file', path };\n\t\treturn;\n\t}\n\n\tfor await (const childPath of fs.readdir(path)) {\n\t\tif (!showAll && basename(childPath).startsWith('.')) {\n\t\t\tcontinue;\n\t\t}\n\t\tyield { kind: 'file', path: childPath };\n\t}\n}\n","import type { FS } from '../../fs/fs';\nimport type { Effect } from '../types';\n\nexport function mkdir(fs: FS): Effect<{\n\tpath: string;\n\trecursive: boolean;\n}> {\n\treturn async ({ path, recursive }) => {\n\t\tawait fs.mkdir(path, recursive);\n\t};\n}\n","import type { FS } from '../../fs/fs';\nimport type { Effect } from '../types';\n\nconst TRAILING_SLASH_REGEX = /\\/+$/;\nconst MULTIPLE_SLASH_REGEX = /\\/+/g;\n\nexport interface MvArgs {\n\tsrcs: string[];\n\tdest: string;\n\tforce?: boolean;\n\tinteractive?: boolean;\n}\n\nfunction trimTrailingSlash(path: string): string {\n\treturn path.replace(TRAILING_SLASH_REGEX, '');\n}\n\nfunction extractFileName(path: string): string {\n\tconst normalized = trimTrailingSlash(path);\n\tconst lastSlashIndex = normalized.lastIndexOf('/');\n\tif (lastSlashIndex === -1) {\n\t\treturn normalized;\n\t}\n\treturn normalized.slice(lastSlashIndex + 1);\n}\n\nfunction joinPath(base: string, suffix: string): string {\n\treturn `${trimTrailingSlash(base)}/${suffix}`.replace(\n\t\tMULTIPLE_SLASH_REGEX,\n\t\t'/'\n\t);\n}\n\nasync function isDirectory(fs: FS, path: string): Promise<boolean> {\n\ttry {\n\t\tconst stat = await fs.stat(path);\n\t\treturn stat.isDirectory;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function assertCanMoveToDestination(\n\tfs: FS,\n\tdest: string,\n\tforce: boolean,\n\tinteractive: boolean\n): Promise<void> {\n\tconst exists = await fs.exists(dest);\n\tif (!exists) {\n\t\treturn;\n\t}\n\tif (interactive) {\n\t\tthrow new Error(`mv: destination exists (interactive): ${dest}`);\n\t}\n\tif (!force) {\n\t\tthrow new Error(\n\t\t\t`mv: destination exists (use -f to overwrite): ${dest}`\n\t\t);\n\t}\n}\n\nexport function mv(fs: FS): Effect<MvArgs> {\n\treturn async ({ srcs, dest, force = false, interactive = false }) => {\n\t\tif (srcs.length === 0) {\n\t\t\tthrow new Error('mv requires at least one source');\n\t\t}\n\n\t\tconst destinationIsDirectory = await isDirectory(fs, dest);\n\t\tif (srcs.length > 1 && !destinationIsDirectory) {\n\t\t\tthrow new Error(\n\t\t\t\t'mv destination must be a directory for multiple sources'\n\t\t\t);\n\t\t}\n\n\t\tfor (const src of srcs) {\n\t\t\tconst sourceStat = await fs.stat(src);\n\t\t\tif (sourceStat.isDirectory) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`mv: directory moves are not supported: ${src}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst targetPath =\n\t\t\t\tdestinationIsDirectory || srcs.length > 1\n\t\t\t\t\t? joinPath(dest, extractFileName(src))\n\t\t\t\t\t: dest;\n\n\t\t\tawait assertCanMoveToDestination(\n\t\t\t\tfs,\n\t\t\t\ttargetPath,\n\t\t\t\tforce,\n\t\t\t\tinteractive\n\t\t\t);\n\t\t\tawait fs.rename(src, targetPath);\n\t\t}\n\t};\n}\n","import type { LineRecord } from '../../record';\nimport type { Stream } from '../../stream';\n\nconst ROOT_DIRECTORY = '/';\n\nexport async function* pwd(cwd = ROOT_DIRECTORY): Stream<LineRecord> {\n\tyield { kind: 'line', text: cwd };\n}\n","import type { FS } from '../../fs/fs';\nimport type { Effect } from '../types';\n\nexport interface RmArgs {\n\tpath: string;\n\trecursive: boolean;\n\tforce?: boolean;\n\tinteractive?: boolean;\n}\n\nexport function rm(fs: FS): Effect<RmArgs> {\n\treturn async ({ path, recursive, force = false, interactive = false }) => {\n\t\tif (interactive) {\n\t\t\tthrow new Error(`rm: interactive mode is not supported: ${path}`);\n\t\t}\n\n\t\tlet stat: Awaited<ReturnType<FS['stat']>> | null = null;\n\t\ttry {\n\t\t\tstat = await fs.stat(path);\n\t\t} catch {\n\t\t\tif (force) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\n\t\tif (!stat.isDirectory) {\n\t\t\tawait fs.deleteFile(path);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!recursive) {\n\t\t\tthrow new Error(`rm: cannot remove '${path}': Is a directory`);\n\t\t}\n\t\tawait fs.deleteDirectory(path, true);\n\t};\n}\n","import type { LineRecord } from '../../record';\nimport type { Transducer } from '../types';\n\nexport function tail(n: number): Transducer<LineRecord, LineRecord> {\n\treturn async function* (input) {\n\t\tconst buf: LineRecord[] = [];\n\t\tfor await (const x of input) {\n\t\t\tbuf.push(x);\n\t\t\tif (buf.length > n) {\n\t\t\t\tbuf.shift();\n\t\t\t}\n\t\t}\n\t\tyield* buf;\n\t};\n}\n","import type { FS } from '../../fs/fs';\nimport type { Effect } from '../types';\n\nexport interface TouchArgs {\n\tfiles: string[];\n\taccessTimeOnly?: boolean;\n\tmodificationTimeOnly?: boolean;\n}\n\nexport function touch(fs: FS): Effect<TouchArgs> {\n\treturn async ({\n\t\tfiles,\n\t\taccessTimeOnly = false,\n\t\tmodificationTimeOnly = false,\n\t}) => {\n\t\tconst shouldUpdateMtime = !accessTimeOnly || modificationTimeOnly;\n\n\t\tfor (const file of files) {\n\t\t\tif (!(await fs.exists(file))) {\n\t\t\t\tawait fs.writeFile(file, new Uint8Array());\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (shouldUpdateMtime) {\n\t\t\t\tconst content = await fs.readFile(file);\n\t\t\t\tawait fs.writeFile(file, content);\n\t\t\t}\n\t\t}\n\t};\n}\n","import type { FS } from '../fs/fs';\nimport type { Transducer } from '../operator/types';\nimport type { FileRecord, LineRecord } from '../record';\nimport type { Stream } from '../stream';\n\nexport function lines(fs: FS): Transducer<FileRecord, LineRecord> {\n\treturn async function* (input) {\n\t\tfor await (const f of input) {\n\t\t\tlet lineNum = 1;\n\t\t\tfor await (const line of fs.readLines(f.path)) {\n\t\t\t\tyield {\n\t\t\t\t\tfile: f.path,\n\t\t\t\t\tkind: 'line',\n\t\t\t\t\tlineNum: lineNum++,\n\t\t\t\t\ttext: line,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport async function* files(...paths: string[]): Stream<FileRecord> {\n\tfor (const path of paths) {\n\t\tyield { kind: 'file', path };\n\t}\n}\n","import type {\n\tPipelineIR,\n\tScriptIR,\n\tStatementChainModeIR,\n\tStepIR,\n} from '@shfs/compiler';\nimport { cd } from '../builtin/cd/cd';\nimport { echo } from '../builtin/echo/echo';\nimport { read } from '../builtin/read/read';\nimport { set } from '../builtin/set/set';\nimport { string } from '../builtin/string/string';\nimport { test } from '../builtin/test/test';\nimport type { BuiltinContext, BuiltinRuntime } from '../builtin/types';\nimport type { FS } from '../fs/fs';\nimport { cat } from '../operator/cat/cat';\nimport { cp } from '../operator/cp/cp';\nimport { find } from '../operator/find/find';\nimport { runGrepCommand } from '../operator/grep/grep';\nimport { headLines, headWithN } from '../operator/head/head';\nimport { ls } from '../operator/ls/ls';\nimport { mkdir } from '../operator/mkdir/mkdir';\nimport { mv } from '../operator/mv/mv';\nimport { pwd } from '../operator/pwd/pwd';\nimport { rm } from '../operator/rm/rm';\nimport { tail } from '../operator/tail/tail';\nimport { touch } from '../operator/touch/touch';\nimport type { Record as ShellRecord } from '../record';\nimport type { Stream } from '../stream';\nimport {\n\tevaluateExpandedPathWords,\n\tevaluateExpandedSinglePath,\n\tnormalizeCwd,\n\tresolvePathsFromCwd,\n} from './path';\nimport { files } from './producers';\nimport { toLineStream } from './records';\nimport {\n\tapplyOutputRedirect,\n\thasRedirect,\n\ttype ExecuteResult as RedirectExecuteResult,\n\tresolveRedirectPath,\n\twithInputRedirect,\n} from './redirection';\n\nexport type { ExecuteResult } from './redirection';\n\nexport interface ExecuteContext {\n\tcwd: string;\n\tstatus?: number;\n\tglobalVars?: Map<string, string>;\n\tlocalVars?: Map<string, string>;\n}\n\ntype NormalizedExecuteContext = BuiltinContext;\n\ntype EffectStep = Extract<\n\tStepIR,\n\t{ cmd: 'cd' | 'cp' | 'mkdir' | 'mv' | 'rm' | 'touch' }\n>;\n\ntype StreamStep = Exclude<StepIR, EffectStep>;\n\nconst EFFECT_COMMANDS = new Set(['cd', 'cp', 'mkdir', 'mv', 'rm', 'touch']);\nconst ROOT_DIRECTORY = '/';\nconst TEXT_ENCODER = new TextEncoder();\n\ninterface StreamExecutionOptions {\n\tfinalGrepOutputRedirectPath?: string;\n}\n\nfunction isEffectStep(step: StepIR): step is EffectStep {\n\treturn EFFECT_COMMANDS.has(step.cmd);\n}\n\nasync function* emptyStream<T>(): Stream<T> {\n\t// no records\n}\n\n/**\n * Execute compiles ScriptIR/PipelineIR into an executable result.\n * Returns either a stream (for producers/transducers) or a promise (for sinks).\n */\nexport function execute(\n\tir: PipelineIR | ScriptIR,\n\tfs: FS,\n\tcontext: ExecuteContext = { cwd: ROOT_DIRECTORY }\n): RedirectExecuteResult {\n\tconst normalizedContext = normalizeContext(context);\n\tconst scriptIR = isScriptIR(ir) ? ir : toScriptIR(ir);\n\treturn executeScript(scriptIR, fs, normalizedContext);\n}\n\nfunction isScriptIR(ir: PipelineIR | ScriptIR): ir is ScriptIR {\n\treturn 'statements' in ir;\n}\n\nfunction toScriptIR(pipeline: PipelineIR): ScriptIR {\n\treturn {\n\t\tstatements: [\n\t\t\t{\n\t\t\t\tchainMode: 'always',\n\t\t\t\tpipeline,\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction isPipelineSink(pipeline: PipelineIR): boolean {\n\tconst finalStep = pipeline.steps.at(-1);\n\tif (!finalStep) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\tisEffectStep(finalStep) || hasRedirect(finalStep.redirections, 'output')\n\t);\n}\n\nfunction shouldExecuteStatement(\n\tchainMode: StatementChainModeIR,\n\tpreviousStatus: number\n): boolean {\n\tif (chainMode === 'always') {\n\t\treturn true;\n\t}\n\tif (chainMode === 'and') {\n\t\treturn previousStatus === 0;\n\t}\n\treturn previousStatus !== 0;\n}\n\nfunction executeScript(\n\tscript: ScriptIR,\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): RedirectExecuteResult {\n\tif (script.statements.length === 0) {\n\t\treturn {\n\t\t\tkind: 'stream',\n\t\t\tvalue: emptyStream<ShellRecord>(),\n\t\t};\n\t}\n\n\tif (\n\t\tscript.statements.every((statement) =>\n\t\t\tisPipelineSink(statement.pipeline)\n\t\t)\n\t) {\n\t\treturn {\n\t\t\tkind: 'sink',\n\t\t\tvalue: runScriptToCompletion(script, fs, context),\n\t\t};\n\t}\n\n\treturn {\n\t\tkind: 'stream',\n\t\tvalue: runScriptToStream(script, fs, context),\n\t};\n}\n\nasync function runScriptToCompletion(\n\tscript: ScriptIR,\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): Promise<void> {\n\tfor (const statement of script.statements) {\n\t\tif (!shouldExecuteStatement(statement.chainMode, context.status)) {\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst result = executePipeline(statement.pipeline, fs, context);\n\t\t\tawait drainResult(result);\n\t\t} catch (error) {\n\t\t\tcontext.status = 1;\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n\nasync function* runScriptToStream(\n\tscript: ScriptIR,\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): Stream<ShellRecord> {\n\tfor (const statement of script.statements) {\n\t\tif (!shouldExecuteStatement(statement.chainMode, context.status)) {\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst result = executePipeline(statement.pipeline, fs, context);\n\t\t\tif (result.kind === 'sink') {\n\t\t\t\tawait result.value;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tyield* result.value;\n\t\t} catch (error) {\n\t\t\tcontext.status = 1;\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n\nasync function drainResult(result: RedirectExecuteResult): Promise<void> {\n\tif (result.kind === 'sink') {\n\t\tawait result.value;\n\t\treturn;\n\t}\n\n\tfor await (const _record of result.value) {\n\t\t// drain stream output to complete side effects.\n\t}\n}\n\nfunction executePipeline(\n\tir: PipelineIR,\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): RedirectExecuteResult {\n\tif (ir.steps.length === 0) {\n\t\treturn {\n\t\t\tkind: 'stream',\n\t\t\tvalue: emptyStream<ShellRecord>(),\n\t\t};\n\t}\n\n\tconst lastStep = ir.steps.at(-1);\n\tif (!lastStep) {\n\t\treturn {\n\t\t\tkind: 'stream',\n\t\t\tvalue: emptyStream<ShellRecord>(),\n\t\t};\n\t}\n\n\tif (isEffectStep(lastStep)) {\n\t\tfor (const [index, step] of ir.steps.entries()) {\n\t\t\tif (isEffectStep(step) && index !== ir.steps.length - 1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unsupported pipeline: \"${step.cmd}\" must be the final command`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (hasRedirect(lastStep.redirections, 'output')) {\n\t\t\treturn {\n\t\t\t\tkind: 'sink',\n\t\t\t\tvalue: (async () => {\n\t\t\t\t\tconst outputPath = await resolveRedirectPath(\n\t\t\t\t\t\tlastStep.cmd,\n\t\t\t\t\t\tlastStep.redirections,\n\t\t\t\t\t\t'output',\n\t\t\t\t\t\tfs,\n\t\t\t\t\t\tcontext\n\t\t\t\t\t);\n\t\t\t\t\tif (!outputPath) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`${lastStep.cmd}: output redirection missing target`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait executePipelineToSink(ir.steps, fs, context);\n\t\t\t\t\tawait fs.writeFile(outputPath, TEXT_ENCODER.encode(''));\n\t\t\t\t})(),\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tkind: 'sink',\n\t\t\tvalue: executePipelineToSink(ir.steps, fs, context),\n\t\t};\n\t}\n\n\tif (\n\t\tlastStep.cmd === 'grep' &&\n\t\thasRedirect(lastStep.redirections, 'output')\n\t) {\n\t\treturn {\n\t\t\tkind: 'sink',\n\t\t\tvalue: (async () => {\n\t\t\t\tconst outputPath = await resolveRedirectPath(\n\t\t\t\t\tlastStep.cmd,\n\t\t\t\t\tlastStep.redirections,\n\t\t\t\t\t'output',\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tif (!outputPath) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`${lastStep.cmd}: output redirection missing target`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst redirectedResult = applyOutputRedirect(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: 'stream',\n\t\t\t\t\t\tvalue: executePipelineToStream(ir.steps, fs, context, {\n\t\t\t\t\t\t\tfinalGrepOutputRedirectPath: outputPath,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t\tlastStep,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext,\n\t\t\t\t\toutputPath\n\t\t\t\t);\n\t\t\t\tif (redirectedResult.kind !== 'sink') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`${lastStep.cmd}: output redirection did not produce a sink`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait redirectedResult.value;\n\t\t\t})(),\n\t\t};\n\t}\n\n\tconst stream = executePipelineToStream(ir.steps, fs, context);\n\treturn applyOutputRedirect(\n\t\t{\n\t\t\tkind: 'stream',\n\t\t\tvalue: stream,\n\t\t},\n\t\tlastStep,\n\t\tfs,\n\t\tcontext\n\t);\n}\n\nfunction executePipelineToStream(\n\tsteps: StepIR[],\n\tfs: FS,\n\tcontext: NormalizedExecuteContext,\n\toptions: StreamExecutionOptions = {}\n): Stream<ShellRecord> {\n\treturn (async function* () {\n\t\tlet stream: Stream<ShellRecord> | null = null;\n\t\tfor (const [index, step] of steps.entries()) {\n\t\t\tif (isEffectStep(step)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unsupported pipeline: \"${step.cmd}\" requires being the final command`\n\t\t\t\t);\n\t\t\t}\n\t\t\tstream = executeStreamStep(\n\t\t\t\tstep,\n\t\t\t\tfs,\n\t\t\t\tstream,\n\t\t\t\tcontext,\n\t\t\t\tindex === steps.length - 1\n\t\t\t\t\t? options.finalGrepOutputRedirectPath\n\t\t\t\t\t: undefined\n\t\t\t);\n\t\t}\n\n\t\tif (!stream) {\n\t\t\treturn;\n\t\t}\n\t\tyield* stream;\n\t})();\n}\n\nasync function executePipelineToSink(\n\tsteps: StepIR[],\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): Promise<void> {\n\tconst finalStep = steps.at(-1);\n\tif (!(finalStep && isEffectStep(finalStep))) {\n\t\treturn;\n\t}\n\n\tif (steps.length > 1) {\n\t\tconst stream = executePipelineToStream(steps.slice(0, -1), fs, context);\n\t\tfor await (const _record of stream) {\n\t\t\t// drain\n\t\t}\n\t}\n\n\tawait executeEffectStep(finalStep, fs, context);\n}\n\nfunction executeStreamStep(\n\tstep: StreamStep,\n\tfs: FS,\n\tinput: Stream<ShellRecord> | null,\n\tcontext: NormalizedExecuteContext,\n\tresolvedOutputRedirectPath?: string\n): Stream<ShellRecord> {\n\tconst builtinRuntime = createBuiltinRuntime(fs, context, input);\n\n\tswitch (step.cmd) {\n\t\tcase 'cat': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tconst options = {\n\t\t\t\t\tnumberLines: step.args.numberLines,\n\t\t\t\t\tnumberNonBlank: step.args.numberNonBlank,\n\t\t\t\t\tshowAll: step.args.showAll,\n\t\t\t\t\tshowEnds: step.args.showEnds,\n\t\t\t\t\tshowNonprinting: step.args.showNonprinting,\n\t\t\t\t\tshowTabs: step.args.showTabs,\n\t\t\t\t\tsqueezeBlank: step.args.squeezeBlank,\n\t\t\t\t};\n\t\t\t\tconst inputPath = await resolveRedirectPath(\n\t\t\t\t\tstep.cmd,\n\t\t\t\t\tstep.redirections,\n\t\t\t\t\t'input',\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tconst filePaths = withInputRedirect(\n\t\t\t\t\tresolvePathsFromCwd(\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t\t\t'cat',\n\t\t\t\t\t\t\tstep.args.files,\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tcontext\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\tinputPath\n\t\t\t\t);\n\t\t\t\tif (filePaths.length > 0) {\n\t\t\t\t\tyield* cat(fs, options)(files(...filePaths));\n\t\t\t\t\tcontext.status = 0;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (input) {\n\t\t\t\t\tyield* cat(fs, options)(input);\n\t\t\t\t}\n\t\t\t\tcontext.status = 0;\n\t\t\t})();\n\t\t}\n\t\tcase 'grep': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tconst result = await runGrepCommand({\n\t\t\t\t\tcontext,\n\t\t\t\t\tfs,\n\t\t\t\t\tinput,\n\t\t\t\t\t// @shfs/compiler can be consumed as a built package in this workspace,\n\t\t\t\t\t// so grep args may type as legacy argv until compiler is rebuilt.\n\t\t\t\t\tparsed: step.args as unknown as Parameters<\n\t\t\t\t\t\ttypeof runGrepCommand\n\t\t\t\t\t>[0]['parsed'],\n\t\t\t\t\tredirections: step.redirections,\n\t\t\t\t\tresolvedOutputRedirectPath,\n\t\t\t\t});\n\t\t\t\tcontext.status = result.status;\n\t\t\t\tfor (const text of result.lines) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tkind: 'line',\n\t\t\t\t\t\ttext,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t})();\n\t\t}\n\t\tcase 'find': {\n\t\t\treturn find(fs, context, step.args);\n\t\t}\n\t\tcase 'head': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tconst inputPath = await resolveRedirectPath(\n\t\t\t\t\tstep.cmd,\n\t\t\t\t\tstep.redirections,\n\t\t\t\t\t'input',\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tconst filePaths = withInputRedirect(\n\t\t\t\t\tresolvePathsFromCwd(\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t\t\t'head',\n\t\t\t\t\t\t\tstep.args.files,\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tcontext\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\tinputPath\n\t\t\t\t);\n\t\t\t\tif (filePaths.length > 0) {\n\t\t\t\t\tyield* headWithN(fs, step.args.n)(files(...filePaths));\n\t\t\t\t\tcontext.status = 0;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (input) {\n\t\t\t\t\tyield* headLines(step.args.n)(toLineStream(fs, input));\n\t\t\t\t}\n\t\t\t\tcontext.status = 0;\n\t\t\t})();\n\t\t}\n\t\tcase 'ls': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tconst paths = await evaluateExpandedPathWords(\n\t\t\t\t\t'ls',\n\t\t\t\t\tstep.args.paths,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tfor (const inputPath of paths) {\n\t\t\t\t\tconst resolvedPath = resolveLsPath(inputPath, context.cwd);\n\t\t\t\t\tfor await (const fileRecord of ls(fs, resolvedPath, {\n\t\t\t\t\t\tshowAll: step.args.showAll,\n\t\t\t\t\t})) {\n\t\t\t\t\t\tif (step.args.longFormat) {\n\t\t\t\t\t\t\tconst stat = await fs.stat(fileRecord.path);\n\t\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\t\tkind: 'line',\n\t\t\t\t\t\t\t\ttext: formatLongListing(fileRecord.path, stat),\n\t\t\t\t\t\t\t} as const;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield fileRecord;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcontext.status = 0;\n\t\t\t})();\n\t\t}\n\t\tcase 'tail': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tconst inputPath = await resolveRedirectPath(\n\t\t\t\t\tstep.cmd,\n\t\t\t\t\tstep.redirections,\n\t\t\t\t\t'input',\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t\tconst filePaths = withInputRedirect(\n\t\t\t\t\tresolvePathsFromCwd(\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t\t\t'tail',\n\t\t\t\t\t\t\tstep.args.files,\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tcontext\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\tinputPath\n\t\t\t\t);\n\t\t\t\tif (filePaths.length > 0) {\n\t\t\t\t\tfor (const filePath of filePaths) {\n\t\t\t\t\t\tyield* tail(step.args.n)(cat(fs)(files(filePath)));\n\t\t\t\t\t}\n\t\t\t\t\tcontext.status = 0;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (input) {\n\t\t\t\t\tyield* tail(step.args.n)(toLineStream(fs, input));\n\t\t\t\t}\n\t\t\t\tcontext.status = 0;\n\t\t\t})();\n\t\t}\n\t\tcase 'pwd': {\n\t\t\treturn (async function* (): Stream<ShellRecord> {\n\t\t\t\tyield* pwd(context.cwd);\n\t\t\t\tcontext.status = 0;\n\t\t\t})();\n\t\t}\n\t\tcase 'echo': {\n\t\t\treturn echo(builtinRuntime, step.args);\n\t\t}\n\t\tcase 'set': {\n\t\t\treturn set(builtinRuntime, step.args);\n\t\t}\n\t\tcase 'test': {\n\t\t\treturn test(builtinRuntime, step.args);\n\t\t}\n\t\tcase 'read': {\n\t\t\treturn read(builtinRuntime, step.args);\n\t\t}\n\t\tcase 'string': {\n\t\t\treturn string(builtinRuntime, step.args);\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = step;\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown command: ${String((_exhaustive as { cmd: string }).cmd)}`\n\t\t\t);\n\t\t}\n\t}\n}\n\nasync function executeEffectStep(\n\tstep: EffectStep,\n\tfs: FS,\n\tcontext: NormalizedExecuteContext\n): Promise<void> {\n\tconst builtinRuntime = createBuiltinRuntime(fs, context, null);\n\n\tswitch (step.cmd) {\n\t\tcase 'cd': {\n\t\t\tawait cd(builtinRuntime, step.args);\n\t\t\tbreak;\n\t\t}\n\t\tcase 'cp': {\n\t\t\tconst srcPaths = resolvePathsFromCwd(\n\t\t\t\tcontext.cwd,\n\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t'cp',\n\t\t\t\t\tstep.args.srcs,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst destinationPaths = resolvePathsFromCwd(context.cwd, [\n\t\t\t\tawait evaluateExpandedSinglePath(\n\t\t\t\t\t'cp',\n\t\t\t\t\t'destination must expand to exactly 1 path',\n\t\t\t\t\tstep.args.dest,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t),\n\t\t\t]);\n\t\t\tconst destinationPath = destinationPaths.at(0);\n\t\t\tif (destinationPath === undefined) {\n\t\t\t\tthrow new Error('cp: destination missing after expansion');\n\t\t\t}\n\t\t\tawait cp(fs)({\n\t\t\t\tsrcs: srcPaths,\n\t\t\t\tdest: destinationPath,\n\t\t\t\tforce: step.args.force,\n\t\t\t\tinteractive: step.args.interactive,\n\t\t\t\trecursive: step.args.recursive,\n\t\t\t});\n\t\t\tcontext.status = 0;\n\t\t\tbreak;\n\t\t}\n\t\tcase 'mkdir': {\n\t\t\tconst paths = resolvePathsFromCwd(\n\t\t\t\tcontext.cwd,\n\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t'mkdir',\n\t\t\t\t\tstep.args.paths,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t)\n\t\t\t);\n\t\t\tfor (const path of paths) {\n\t\t\t\tawait mkdir(fs)({ path, recursive: step.args.recursive });\n\t\t\t}\n\t\t\tcontext.status = 0;\n\t\t\tbreak;\n\t\t}\n\t\tcase 'mv': {\n\t\t\tconst srcPaths = resolvePathsFromCwd(\n\t\t\t\tcontext.cwd,\n\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t'mv',\n\t\t\t\t\tstep.args.srcs,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst destinationPaths = resolvePathsFromCwd(context.cwd, [\n\t\t\t\tawait evaluateExpandedSinglePath(\n\t\t\t\t\t'mv',\n\t\t\t\t\t'destination must expand to exactly 1 path',\n\t\t\t\t\tstep.args.dest,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t),\n\t\t\t]);\n\t\t\tconst destinationPath = destinationPaths.at(0);\n\t\t\tif (destinationPath === undefined) {\n\t\t\t\tthrow new Error('mv: destination missing after expansion');\n\t\t\t}\n\t\t\tawait mv(fs)({\n\t\t\t\tsrcs: srcPaths,\n\t\t\t\tdest: destinationPath,\n\t\t\t\tforce: step.args.force,\n\t\t\t\tinteractive: step.args.interactive,\n\t\t\t});\n\t\t\tcontext.status = 0;\n\t\t\tbreak;\n\t\t}\n\t\tcase 'rm': {\n\t\t\tconst paths = resolvePathsFromCwd(\n\t\t\t\tcontext.cwd,\n\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t'rm',\n\t\t\t\t\tstep.args.paths,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t)\n\t\t\t);\n\t\t\tfor (const path of paths) {\n\t\t\t\tawait rm(fs)({\n\t\t\t\t\tpath,\n\t\t\t\t\tforce: step.args.force,\n\t\t\t\t\tinteractive: step.args.interactive,\n\t\t\t\t\trecursive: step.args.recursive,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontext.status = 0;\n\t\t\tbreak;\n\t\t}\n\t\tcase 'touch': {\n\t\t\tconst filePaths = resolvePathsFromCwd(\n\t\t\t\tcontext.cwd,\n\t\t\t\tawait evaluateExpandedPathWords(\n\t\t\t\t\t'touch',\n\t\t\t\t\tstep.args.files,\n\t\t\t\t\tfs,\n\t\t\t\t\tcontext\n\t\t\t\t)\n\t\t\t);\n\t\t\tawait touch(fs)({\n\t\t\t\tfiles: filePaths,\n\t\t\t\taccessTimeOnly: step.args.accessTimeOnly,\n\t\t\t\tmodificationTimeOnly: step.args.modificationTimeOnly,\n\t\t\t});\n\t\t\tcontext.status = 0;\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = step;\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown command: ${String((_exhaustive as { cmd: string }).cmd)}`\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction createBuiltinRuntime(\n\tfs: FS,\n\tcontext: NormalizedExecuteContext,\n\tinput: Stream<ShellRecord> | null\n): BuiltinRuntime {\n\treturn {\n\t\tfs,\n\t\tcontext,\n\t\tinput,\n\t};\n}\n\nfunction formatLongListing(\n\tpath: string,\n\tstat: Awaited<ReturnType<FS['stat']>>\n): string {\n\tconst mode = stat.isDirectory ? 'd' : '-';\n\tconst size = String(stat.size).padStart(8, ' ');\n\treturn `${mode} ${size} ${stat.mtime.toISOString()} ${path}`;\n}\n\nfunction normalizeLsPath(path: string, cwd: string): string {\n\tif (path === '.' || path === './') {\n\t\treturn cwd;\n\t}\n\tif (path.startsWith('./')) {\n\t\treturn `${cwd}/${path.slice(2)}`;\n\t}\n\tif (path.startsWith(ROOT_DIRECTORY)) {\n\t\treturn path;\n\t}\n\treturn `${cwd}/${path}`;\n}\n\nfunction resolveLsPath(path: string, cwd: string): string {\n\treturn normalizeLsPath(path, cwd);\n}\n\nfunction normalizeContext(context: ExecuteContext): NormalizedExecuteContext {\n\tcontext.cwd = normalizeCwd(context.cwd);\n\tcontext.status ??= 0;\n\tcontext.globalVars ??= new Map<string, string>();\n\tcontext.localVars ??= new Map<string, string>();\n\treturn context as NormalizedExecuteContext;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgBA,eAAa,QAAwB;AACpD,SAAQ,OAAO,MAAf;EACC,KAAK,OACJ,QAAO,OAAO;EACf,KAAK,OACJ,QAAO,OAAO,eAAe,OAAO;EACrC,KAAK,OACJ,QAAO,KAAK,UAAU,OAAO,MAAM;EACpC,QACC,OAAM,IAAI,MAAM,sBAAsB;;;;;;ACTzC,MAAMC,yBAAuB;AAC7B,MAAMC,mBAAiB;AACvB,MAAMC,yBAAuB;AAC7B,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAE9B,eAAe,qBACd,QACoB;AACpB,KAAI,OAAO,SAAS,QAAQ;AAC3B,QAAM,OAAO;AACb,SAAO,EAAE;;CAGV,MAAM,UAAoB,EAAE;AAC5B,YAAW,MAAM,UAAU,OAAO,MACjC,SAAQ,KAAKC,eAAa,OAAO,CAAC;AAEnC,QAAO;;AAGR,eAAe,4BACd,SACA,IACA,SACkB;CAElB,MAAM,WAAW,QADF,MAAM,QAAQ,CACG;AAIhC,SADgB,MAAM,sBAFA,qDACO,QAAQ,UAAU,IAAI,QAAQ,CACT,EACnC,KAAK,KAAK;;AAG1B,SAAS,gBACR,cACA,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