@smthrs/std 1.0.0-rc.8 → 1.0.0-rc.9
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/CHANGELOG.md +10 -0
- package/README.md +3 -1
- package/dist/cjs/PortableSearch.d.ts +13 -1
- package/dist/cjs/PortableSearch.d.ts.map +1 -1
- package/dist/cjs/PortableSearch.js +8 -1
- package/dist/cjs/PortableSearch.js.map +2 -2
- package/dist/cjs/RemoteSearch.d.ts +54 -0
- package/dist/cjs/RemoteSearch.d.ts.map +1 -0
- package/dist/cjs/RemoteSearch.js +134 -0
- package/dist/cjs/RemoteSearch.js.map +7 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/cjs/internal/EnvelopePrecheck.js +21 -5
- package/dist/cjs/internal/EnvelopePrecheck.js.map +2 -2
- package/dist/cjs/internal/RemoteTree.d.ts +60 -0
- package/dist/cjs/internal/RemoteTree.d.ts.map +1 -0
- package/dist/cjs/internal/RemoteTree.js +123 -0
- package/dist/cjs/internal/RemoteTree.js.map +7 -0
- package/dist/cjs/internal/Tar.d.ts +23 -0
- package/dist/cjs/internal/Tar.d.ts.map +1 -0
- package/dist/cjs/internal/Tar.js +86 -0
- package/dist/cjs/internal/Tar.js.map +7 -0
- package/dist/esm/PortableSearch.d.ts +13 -1
- package/dist/esm/PortableSearch.d.ts.map +1 -1
- package/dist/esm/PortableSearch.js +16 -0
- package/dist/esm/PortableSearch.js.map +1 -1
- package/dist/esm/RemoteSearch.d.ts +54 -0
- package/dist/esm/RemoteSearch.d.ts.map +1 -0
- package/dist/esm/RemoteSearch.js +162 -0
- package/dist/esm/RemoteSearch.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/esm/internal/EnvelopePrecheck.js +29 -5
- package/dist/esm/internal/EnvelopePrecheck.js.map +1 -1
- package/dist/esm/internal/RemoteTree.d.ts +60 -0
- package/dist/esm/internal/RemoteTree.d.ts.map +1 -0
- package/dist/esm/internal/RemoteTree.js +132 -0
- package/dist/esm/internal/RemoteTree.js.map +1 -0
- package/dist/esm/internal/Tar.d.ts +23 -0
- package/dist/esm/internal/Tar.d.ts.map +1 -0
- package/dist/esm/internal/Tar.js +97 -0
- package/dist/esm/internal/Tar.js.map +1 -0
- package/docs/api.md +28 -4
- package/docs/concepts/effects-and-capabilities.md +3 -1
- package/docs/guides/bind-the-standard-flows.md +3 -1
- package/docs/guides/run-a-shell-command.md +4 -1
- package/docs/troubleshooting.md +8 -0
- package/package.json +16 -6
- package/src/PortableSearch.ts +20 -0
- package/src/RemoteSearch.ts +199 -0
- package/src/index.ts +3 -0
- package/src/internal/EnvelopePrecheck.ts +29 -5
- package/src/internal/RemoteTree.ts +159 -0
- package/src/internal/Tar.ts +95 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PortableSearch.js","sourceRoot":"","sources":["../../src/PortableSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC5D,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,IAAI,MAAM,oBAA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A;AACH,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,QAA4D,EAAiB,EAAE,CAClG,MAAM,CAAC,IAAI,CAAC;IACV,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACtD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;CACvD,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyE,KAAK,CAAC,MAAM,CACrG,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAqC,EAAE,IAAI,CAAC,CACtE,CAAA","sourcesContent":["/**\n * The in-process implementation of the ripgrep search contract.\n *\n * @since 1.0.0\n */\n\nimport * as Path from \"@smthrs/kernel/Path\"\nimport { type Context, Effect, Layer, Stream } from \"effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Grouping from \"./internal/Grouping.ts\"\nimport * as LinearRegex from \"./internal/LinearRegex.ts\"\nimport { escapeRegex } from \"./internal/SearchContract.ts\"\nimport { notice, truncateBytes } from \"./internal/Text.ts\"\nimport * as Walk from \"./internal/Walk.ts\"\nimport * as Search from \"./Search.ts\"\nimport * as Contract from \"./SearchContract.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * Narrows a walk to the files a search reports.\n *\n * A root that names one file is that file: `rg` searches a path given on the\n * command line whatever `-g` says, and follows it even when it is a symlink.\n * Everything a walk found is filtered by the globs first and probed for\n * symlinks second, so the probe runs over the far smaller included set.\n */\nconst candidates = (\n fileSystem: FileSystem.FileSystem,\n path: Path.Path,\n walked: Walk.Walked,\n root: string,\n globs: ReadonlyArray<string>\n): Effect.Effect<ReadonlyArray<string>> =>\n Effect.gen(function*() {\n if (walked.explicitFile) return walked.files\n const included = walked.files.filter((file) =>\n Contract.includedByGlobs(globs, Walk.relativeForPattern(path, root, file), path.basename(file))\n )\n const links = yield* Walk.symbolicLinks(fileSystem, included)\n return included.filter((_, index) => links[index] !== true)\n })\n\nconst preview = (line: string): string => {\n let head = \"\"\n let length = 0\n for (const character of line) {\n if (length++ === 500) break\n head += character\n }\n return truncateBytes(head, 500, { keep: \"head\" }).text\n}\n\nconst grep = (\n input: Search.GrepInput\n): Effect.Effect<Search.GrepOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs(input.globs, relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const insensitive = input.ignoreCase || (input.smartCase && !/[A-Z]/.test(input.pattern))\n const regex = LinearRegex.compile(\n input.fixedStrings ? escapeRegex(input.pattern) : input.pattern,\n insensitive\n )\n const shownMatches: Array<Search.GrepMatch> = []\n const shownFiles: Array<string> = []\n let total = 0\n let filesSearched = 0\n let skippedBinary = 0\n\n const included = yield* candidates(fileSystem, path, walked, input.root, input.globs)\n for (const file of included) {\n // Count every admitted file, including unreadable files and binaries.\n filesSearched++\n const remaining = input.filesWithMatches ? 0 : input.limit - shownMatches.length\n const matched: Array<number> = []\n const selected = new Map<number, Search.GrepLine>()\n const recent = new Map<number, Search.GrepLine>()\n let count = 0\n let lineNumber = 0\n let through = 0\n const scanLine = (text: string) =>\n Effect.gen(function*() {\n lineNumber++\n let matches = false\n if (input.maxCount === undefined || count < input.maxCount) {\n const evaluation = regex.test(text)\n let step = evaluation.next()\n while (!step.done) {\n yield* Effect.yieldNow\n step = evaluation.next()\n }\n matches = step.value\n }\n if (matches) count++\n if (remaining <= 0) return\n // The first overflow hit is a boundary: context nearest to it must\n // not migrate to the last retained hit when the limit is applied.\n const retain = matches && matched.length < remaining + 1\n const awaiting = matched.length < remaining + 1\n if (retain || lineNumber <= through || (awaiting && input.beforeContext > 0)) {\n const row: Search.GrepLine = {\n file,\n line: lineNumber,\n text: preview(text),\n kind: retain ? \"match\" : \"context\"\n }\n if (retain) {\n matched.push(lineNumber)\n for (const [number, context] of recent) selected.set(number, context)\n through = lineNumber + input.afterContext\n }\n if (retain || lineNumber <= through) selected.set(lineNumber, row)\n if (awaiting && input.beforeContext > 0) recent.set(lineNumber, row)\n }\n recent.delete(lineNumber - input.beforeContext)\n if (matched.length >= remaining + 1) recent.clear()\n })\n // Split only on LF (stripping a preceding CR), just like sourceLines.\n // Stream.splitLines also treats a standalone CR as a delimiter.\n const decoder = new TextDecoder()\n let fragments: Array<string> = []\n const consume = (chunk: string) =>\n Effect.gen(function*() {\n let from = 0\n let newline = chunk.indexOf(\"\\n\")\n while (newline >= 0) {\n fragments.push(chunk.slice(from, newline))\n const line = fragments.join(\"\")\n fragments = []\n yield* scanLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line)\n from = newline + 1\n newline = chunk.indexOf(\"\\n\", from)\n }\n if (from < chunk.length) fragments.push(chunk.slice(from))\n })\n const scanned = yield* Effect.gen(function*() {\n let started = false\n // A guarded disk host can safely expose atomic reads while refusing\n // open streaming handles. Retry through that same filesystem service\n // only before any bytes arrive, so a failed partial stream is never\n // combined with a second reading of a file that may have changed.\n yield* fileSystem.stream(file).pipe(\n Stream.catch((error) => started ? Stream.fail(error) : Stream.fromEffect(fileSystem.readFile(file))),\n Stream.runForEach((bytes) => {\n started = true\n if (bytes.includes(0)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"binary_file\",\n message: `Cannot search binary file: ${file}`,\n path: file\n })\n )\n }\n return consume(decoder.decode(bytes, { stream: true }))\n })\n )\n yield* consume(decoder.decode())\n if (fragments.length > 0) yield* scanLine(fragments.join(\"\"))\n return true\n }).pipe(Effect.catch((error) => {\n if (error instanceof StdError.StdError) {\n if (walked.explicitFile) return Effect.fail(error)\n skippedBinary++\n }\n return Effect.succeed(false)\n }))\n if (!scanned || count === 0) continue\n total += input.filesWithMatches ? 1 : count\n if (input.filesWithMatches) {\n if (shownFiles.length < input.limit) shownFiles.push(file)\n continue\n }\n if (matched.length === 0) continue\n const grouped = Grouping.group([...selected.values()].sort((left, right) => left.line - right.line))\n .slice(0, remaining)\n // Source is needed only for returned symbols, and is released before\n // moving to the next file. Overflow files never load symbol source.\n const contents = new Map<string, ReadonlyArray<string>>()\n if (input.symbols) {\n const source = yield* fileSystem.readFileString(file).pipe(Effect.orElseSucceed(() => undefined))\n if (source !== undefined) contents.set(file, Grouping.sourceLines(source))\n }\n shownMatches.push(...Grouping.annotate(grouped, contents))\n }\n\n const truncated = total > input.limit\n const unsatisfiable = total > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: input.globs,\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n matches: shownMatches,\n files: shownFiles,\n filesSearched,\n skippedBinary,\n truncated,\n ...(truncated\n ? { notice: notice(input.filesWithMatches ? \"files\" : \"matches\", input.limit, total) }\n : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\nconst glob = (\n input: Search.GlobInput\n): Effect.Effect<Search.GlobOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs([input.pattern], relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const included = yield* candidates(fileSystem, path, walked, input.root, [input.pattern])\n const matching = [...included].sort()\n const paths = matching.slice(0, input.limit)\n const unsatisfiable = matching.length > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: [input.pattern],\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n paths,\n total: matching.length,\n truncated: matching.length > input.limit,\n ...(matching.length > input.limit ? { notice: notice(\"entries\", paths.length, matching.length) } : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\n/**\n * Captures filesystem and path services in the portable peer.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (services: Context.Context<FileSystem.FileSystem | Path.Path>): Search.Search =>\n Search.make({\n grep: (input) => Effect.provide(grep(input), services),\n glob: (input) => Effect.provide(glob(input), services)\n })\n\n/**\n * Provides the in-process peer.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layer: Layer.Layer<Search.Search, never, FileSystem.FileSystem | Path.Path> = Layer.effect(\n Search.Search,\n Effect.map(Effect.context<FileSystem.FileSystem | Path.Path>(), make)\n)\n"]}
|
|
1
|
+
{"version":3,"file":"PortableSearch.js","sourceRoot":"","sources":["../../src/PortableSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC5D,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CACjB,UAAiC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U,CAAC,UAAU,CAAA;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;IAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC5F,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,QAA4D,EAAiB,EAAE,CAClG,MAAM,CAAC,IAAI,CAAC;IACV,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACtD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;CACvD,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyE,KAAK,CAAC,MAAM,CACrG,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAqC,EAAE,IAAI,CAAC,CACtE,CAAA","sourcesContent":["/**\n * The in-process implementation of the ripgrep search contract.\n *\n * @since 1.0.0\n */\n\nimport * as Path from \"@smthrs/kernel/Path\"\nimport { type Context, Effect, Layer, Stream } from \"effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Grouping from \"./internal/Grouping.ts\"\nimport * as LinearRegex from \"./internal/LinearRegex.ts\"\nimport { escapeRegex } from \"./internal/SearchContract.ts\"\nimport { notice, truncateBytes } from \"./internal/Text.ts\"\nimport * as Walk from \"./internal/Walk.ts\"\nimport * as Search from \"./Search.ts\"\nimport * as Contract from \"./SearchContract.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * Narrows a walk to the files a search reports.\n *\n * A root that names one file is that file: `rg` searches a path given on the\n * command line whatever `-g` says, and follows it even when it is a symlink.\n * Everything a walk found is filtered by the globs first and probed for\n * symlinks second, so the probe runs over the far smaller included set.\n */\nconst candidates = (\n fileSystem: FileSystem.FileSystem,\n path: Path.Path,\n walked: Walk.Walked,\n root: string,\n globs: ReadonlyArray<string>\n): Effect.Effect<ReadonlyArray<string>> =>\n Effect.gen(function*() {\n if (walked.explicitFile) return walked.files\n const included = walked.files.filter((file) =>\n Contract.includedByGlobs(globs, Walk.relativeForPattern(path, root, file), path.basename(file))\n )\n const links = yield* Walk.symbolicLinks(fileSystem, included)\n return included.filter((_, index) => links[index] !== true)\n })\n\nconst preview = (line: string): string => {\n let head = \"\"\n let length = 0\n for (const character of line) {\n if (length++ === 500) break\n head += character\n }\n return truncateBytes(head, 500, { keep: \"head\" }).text\n}\n\nconst grep = (\n input: Search.GrepInput\n): Effect.Effect<Search.GrepOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs(input.globs, relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const insensitive = input.ignoreCase || (input.smartCase && !/[A-Z]/.test(input.pattern))\n const regex = LinearRegex.compile(\n input.fixedStrings ? escapeRegex(input.pattern) : input.pattern,\n insensitive\n )\n const shownMatches: Array<Search.GrepMatch> = []\n const shownFiles: Array<string> = []\n let total = 0\n let filesSearched = 0\n let skippedBinary = 0\n\n const included = yield* candidates(fileSystem, path, walked, input.root, input.globs)\n for (const file of included) {\n // Count every admitted file, including unreadable files and binaries.\n filesSearched++\n const remaining = input.filesWithMatches ? 0 : input.limit - shownMatches.length\n const matched: Array<number> = []\n const selected = new Map<number, Search.GrepLine>()\n const recent = new Map<number, Search.GrepLine>()\n let count = 0\n let lineNumber = 0\n let through = 0\n const scanLine = (text: string) =>\n Effect.gen(function*() {\n lineNumber++\n let matches = false\n if (input.maxCount === undefined || count < input.maxCount) {\n const evaluation = regex.test(text)\n let step = evaluation.next()\n while (!step.done) {\n yield* Effect.yieldNow\n step = evaluation.next()\n }\n matches = step.value\n }\n if (matches) count++\n if (remaining <= 0) return\n // The first overflow hit is a boundary: context nearest to it must\n // not migrate to the last retained hit when the limit is applied.\n const retain = matches && matched.length < remaining + 1\n const awaiting = matched.length < remaining + 1\n if (retain || lineNumber <= through || (awaiting && input.beforeContext > 0)) {\n const row: Search.GrepLine = {\n file,\n line: lineNumber,\n text: preview(text),\n kind: retain ? \"match\" : \"context\"\n }\n if (retain) {\n matched.push(lineNumber)\n for (const [number, context] of recent) selected.set(number, context)\n through = lineNumber + input.afterContext\n }\n if (retain || lineNumber <= through) selected.set(lineNumber, row)\n if (awaiting && input.beforeContext > 0) recent.set(lineNumber, row)\n }\n recent.delete(lineNumber - input.beforeContext)\n if (matched.length >= remaining + 1) recent.clear()\n })\n // Split only on LF (stripping a preceding CR), just like sourceLines.\n // Stream.splitLines also treats a standalone CR as a delimiter.\n const decoder = new TextDecoder()\n let fragments: Array<string> = []\n const consume = (chunk: string) =>\n Effect.gen(function*() {\n let from = 0\n let newline = chunk.indexOf(\"\\n\")\n while (newline >= 0) {\n fragments.push(chunk.slice(from, newline))\n const line = fragments.join(\"\")\n fragments = []\n yield* scanLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line)\n from = newline + 1\n newline = chunk.indexOf(\"\\n\", from)\n }\n if (from < chunk.length) fragments.push(chunk.slice(from))\n })\n const scanned = yield* Effect.gen(function*() {\n let started = false\n // A guarded disk host can safely expose atomic reads while refusing\n // open streaming handles. Retry through that same filesystem service\n // only before any bytes arrive, so a failed partial stream is never\n // combined with a second reading of a file that may have changed.\n yield* fileSystem.stream(file).pipe(\n Stream.catch((error) => started ? Stream.fail(error) : Stream.fromEffect(fileSystem.readFile(file))),\n Stream.runForEach((bytes) => {\n started = true\n if (bytes.includes(0)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"binary_file\",\n message: `Cannot search binary file: ${file}`,\n path: file\n })\n )\n }\n return consume(decoder.decode(bytes, { stream: true }))\n })\n )\n yield* consume(decoder.decode())\n if (fragments.length > 0) yield* scanLine(fragments.join(\"\"))\n return true\n }).pipe(Effect.catch((error) => {\n if (error instanceof StdError.StdError) {\n if (walked.explicitFile) return Effect.fail(error)\n skippedBinary++\n }\n return Effect.succeed(false)\n }))\n if (!scanned || count === 0) continue\n total += input.filesWithMatches ? 1 : count\n if (input.filesWithMatches) {\n if (shownFiles.length < input.limit) shownFiles.push(file)\n continue\n }\n if (matched.length === 0) continue\n const grouped = Grouping.group([...selected.values()].sort((left, right) => left.line - right.line))\n .slice(0, remaining)\n // Source is needed only for returned symbols, and is released before\n // moving to the next file. Overflow files never load symbol source.\n const contents = new Map<string, ReadonlyArray<string>>()\n if (input.symbols) {\n const source = yield* fileSystem.readFileString(file).pipe(Effect.orElseSucceed(() => undefined))\n if (source !== undefined) contents.set(file, Grouping.sourceLines(source))\n }\n shownMatches.push(...Grouping.annotate(grouped, contents))\n }\n\n const truncated = total > input.limit\n const unsatisfiable = total > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: input.globs,\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n matches: shownMatches,\n files: shownFiles,\n filesSearched,\n skippedBinary,\n truncated,\n ...(truncated\n ? { notice: notice(input.filesWithMatches ? \"files\" : \"matches\", input.limit, total) }\n : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\nconst glob = (\n input: Search.GlobInput\n): Effect.Effect<Search.GlobOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs([input.pattern], relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const included = yield* candidates(fileSystem, path, walked, input.root, [input.pattern])\n const matching = [...included].sort()\n const paths = matching.slice(0, input.limit)\n const unsatisfiable = matching.length > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: [input.pattern],\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n paths,\n total: matching.length,\n truncated: matching.length > input.limit,\n ...(matching.length > input.limit ? { notice: notice(\"entries\", paths.length, matching.length) } : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\n/**\n * The files this peer's `grep` reads for `input`, in the order it reads\n * them: the walk under `input.root` with its `.gitignore` rules and\n * `input.globs` applied and symbolic links left out, or the root itself when\n * it names one file. A peer that has to bring a tree's bytes to this process\n * before it can search them (`RemoteSearch`) fetches exactly these.\n *\n * @category queries\n * @since 1.0.0-rc.8\n */\nexport const searched = (\n input: Pick<Search.GrepInput, \"root\" | \"hidden\" | \"noIgnore\" | \"globs\">\n): Effect.Effect<ReadonlyArray<string>, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore)\n return yield* candidates(fileSystem, path, walked, input.root, input.globs)\n })\n\n/**\n * Captures filesystem and path services in the portable peer.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (services: Context.Context<FileSystem.FileSystem | Path.Path>): Search.Search =>\n Search.make({\n grep: (input) => Effect.provide(grep(input), services),\n glob: (input) => Effect.provide(glob(input), services)\n })\n\n/**\n * Provides the in-process peer.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layer: Layer.Layer<Search.Search, never, FileSystem.FileSystem | Path.Path> = Layer.effect(\n Search.Search,\n Effect.map(Effect.context<FileSystem.FileSystem | Path.Path>(), make)\n)\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The search contract for a tree on another machine, in two round trips.
|
|
3
|
+
*
|
|
4
|
+
* `PortableSearch` asks `FileSystem` one question per directory, per entry
|
|
5
|
+
* and per file. On a machine reached through a transport, such as a
|
|
6
|
+
* benchmark's task container behind `docker exec`, every question is a
|
|
7
|
+
* process start, so one `grep` over a 6,000-file repository is some 20,000 of
|
|
8
|
+
* them. This peer asks the machine's own shell twice instead. `find` lists
|
|
9
|
+
* the tree under the root, leaving out the directories every walk skips, and
|
|
10
|
+
* `tar` returns its `.gitignore` files with the listing. The in-process peer
|
|
11
|
+
* then decides which files the search reads, a second `tar` returns exactly
|
|
12
|
+
* those, and `PortableSearch` answers over that copy. Every result, notice,
|
|
13
|
+
* and refusal is therefore the in-process peer's own: this module decides
|
|
14
|
+
* only where the bytes come from.
|
|
15
|
+
*
|
|
16
|
+
* It runs through the machine's own `ChildProcessSpawner`, the one
|
|
17
|
+
* `Sandbox.hostContext` serves beside the machine's `FileSystem`. The machine
|
|
18
|
+
* needs `sh`, `find`, `xargs`, `tar`, `head`, and `base64`; GNU, BusyBox, and
|
|
19
|
+
* BSD userlands all have them. Output crosses as base64, so a transport whose
|
|
20
|
+
* channel carries only text returns it intact. A search reads at most
|
|
21
|
+
* {@link maxBytes} of file content and refuses beyond that, naming the root
|
|
22
|
+
* to narrow.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0-rc.8
|
|
25
|
+
*/
|
|
26
|
+
import type * as ChildProcessSpawner from "@smthrs/kernel/ChildProcessSpawner";
|
|
27
|
+
import * as Path from "@smthrs/kernel/Path";
|
|
28
|
+
import { Context } from "effect";
|
|
29
|
+
import * as Search from "./Search.ts";
|
|
30
|
+
/**
|
|
31
|
+
* The most file content one search brings back from the machine.
|
|
32
|
+
*
|
|
33
|
+
* The copy is held in memory while the in-process peer reads it, so the
|
|
34
|
+
* bound is on this process's memory rather than on the search: a root that
|
|
35
|
+
* holds more is refused with `response_too_large` and a narrower root or
|
|
36
|
+
* globs answer it.
|
|
37
|
+
*
|
|
38
|
+
* @category constants
|
|
39
|
+
* @since 1.0.0-rc.8
|
|
40
|
+
*/
|
|
41
|
+
export declare const maxBytes: number;
|
|
42
|
+
/**
|
|
43
|
+
* Builds the peer over a machine's spawner and its `Path`, which resolves a
|
|
44
|
+
* relative root where the machine's file operations do. `maxBytes` lowers
|
|
45
|
+
* the bound on the file content one search brings back; the default is
|
|
46
|
+
* {@link maxBytes}.
|
|
47
|
+
*
|
|
48
|
+
* @category constructors
|
|
49
|
+
* @since 1.0.0-rc.8
|
|
50
|
+
*/
|
|
51
|
+
export declare const make: (services: Context.Context<ChildProcessSpawner.ChildProcessSpawner | Path.Path>, options?: {
|
|
52
|
+
readonly maxBytes?: number | undefined;
|
|
53
|
+
}) => Search.Search;
|
|
54
|
+
//# sourceMappingURL=RemoteSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteSearch.d.ts","sourceRoot":"","sources":["../../src/RemoteSearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,KAAK,mBAAmB,MAAM,oCAAoC,CAAA;AAC9E,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAU,MAAM,QAAQ,CAAA;AASxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,QAAoB,CAAA;AA+FzC;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI,GACf,UAAU,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,EAC9E,UAAU;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,KACnD,MAAM,CAAC,MAwCT,CAAA"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The search contract for a tree on another machine, in two round trips.
|
|
3
|
+
*
|
|
4
|
+
* `PortableSearch` asks `FileSystem` one question per directory, per entry
|
|
5
|
+
* and per file. On a machine reached through a transport, such as a
|
|
6
|
+
* benchmark's task container behind `docker exec`, every question is a
|
|
7
|
+
* process start, so one `grep` over a 6,000-file repository is some 20,000 of
|
|
8
|
+
* them. This peer asks the machine's own shell twice instead. `find` lists
|
|
9
|
+
* the tree under the root, leaving out the directories every walk skips, and
|
|
10
|
+
* `tar` returns its `.gitignore` files with the listing. The in-process peer
|
|
11
|
+
* then decides which files the search reads, a second `tar` returns exactly
|
|
12
|
+
* those, and `PortableSearch` answers over that copy. Every result, notice,
|
|
13
|
+
* and refusal is therefore the in-process peer's own: this module decides
|
|
14
|
+
* only where the bytes come from.
|
|
15
|
+
*
|
|
16
|
+
* It runs through the machine's own `ChildProcessSpawner`, the one
|
|
17
|
+
* `Sandbox.hostContext` serves beside the machine's `FileSystem`. The machine
|
|
18
|
+
* needs `sh`, `find`, `xargs`, `tar`, `head`, and `base64`; GNU, BusyBox, and
|
|
19
|
+
* BSD userlands all have them. Output crosses as base64, so a transport whose
|
|
20
|
+
* channel carries only text returns it intact. A search reads at most
|
|
21
|
+
* {@link maxBytes} of file content and refuses beyond that, naming the root
|
|
22
|
+
* to narrow.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0-rc.8
|
|
25
|
+
*/
|
|
26
|
+
import * as Path from "@smthrs/kernel/Path";
|
|
27
|
+
import { Context, Effect } from "effect";
|
|
28
|
+
import * as Base64 from "effect/encoding/Base64";
|
|
29
|
+
import * as FileSystem from "effect/FileSystem";
|
|
30
|
+
import * as Result from "effect/Result";
|
|
31
|
+
import * as Exec from "./internal/Exec.js";
|
|
32
|
+
import * as Prune from "./internal/Prune.js";
|
|
33
|
+
import * as RemoteTree from "./internal/RemoteTree.js";
|
|
34
|
+
import * as Tar from "./internal/Tar.js";
|
|
35
|
+
import * as PortableSearch from "./PortableSearch.js";
|
|
36
|
+
import * as Search from "./Search.js";
|
|
37
|
+
import * as StdError from "./StdError.js";
|
|
38
|
+
/**
|
|
39
|
+
* The most file content one search brings back from the machine.
|
|
40
|
+
*
|
|
41
|
+
* The copy is held in memory while the in-process peer reads it, so the
|
|
42
|
+
* bound is on this process's memory rather than on the search: a root that
|
|
43
|
+
* holds more is refused with `response_too_large` and a narrower root or
|
|
44
|
+
* globs answer it.
|
|
45
|
+
*
|
|
46
|
+
* @category constants
|
|
47
|
+
* @since 1.0.0-rc.8
|
|
48
|
+
*/
|
|
49
|
+
export const maxBytes = 256 * 1024 * 1024;
|
|
50
|
+
/** The most a listing, with its `.gitignore` files, may take. */
|
|
51
|
+
const maxListingBytes = 64 * 1024 * 1024;
|
|
52
|
+
const quoted = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
53
|
+
const pruned = `\\( ${Prune.repositoryDirectories.map((name) => `-name ${quoted(name)}`).join(" -o ")} \\) -prune`;
|
|
54
|
+
/** The refusal for a machine without one of the tools a search runs. */
|
|
55
|
+
const missing = (tool) => `searching this machine needs ${tool}, which it does not have`;
|
|
56
|
+
const requireTools = `for t in find xargs tar head; do command -v "$t" >/dev/null || { ` +
|
|
57
|
+
`echo "${missing("$t")}" >&2; exit 3; }; done`;
|
|
58
|
+
/**
|
|
59
|
+
* `$1` is the root, `$2` the byte bound, and `$3` is `1` to send the
|
|
60
|
+
* `.gitignore` files after the listing. Records are NUL-terminated `<kind><path>`;
|
|
61
|
+
* an `E` record ends the listing, and a tar stream of the ignore files follows.
|
|
62
|
+
*/
|
|
63
|
+
const listing = [
|
|
64
|
+
"set -f",
|
|
65
|
+
requireTools,
|
|
66
|
+
"r=$1",
|
|
67
|
+
"{",
|
|
68
|
+
" if [ -d \"$r\" ]; then if [ -r \"$r\" ] && [ -x \"$r\" ]; then printf 'd%s\\0' \"$r\"; else printf 'u%s\\0' \"$r\"; fi",
|
|
69
|
+
" elif [ -f \"$r\" ]; then printf 'f%s\\0' \"$r\"",
|
|
70
|
+
" elif [ -e \"$r\" ]; then printf 'o%s\\0' \"$r\"",
|
|
71
|
+
" fi",
|
|
72
|
+
// No `-exec … {} +` inside parentheses: BusyBox `find` never runs one there.
|
|
73
|
+
` find -H "$r" -mindepth 1 ${pruned} -o -type d -exec printf 'd%s\\0' {} + ` +
|
|
74
|
+
`-o -type f -exec printf 'f%s\\0' {} + ` +
|
|
75
|
+
`-o -type l -exec sh -c 'for p do if [ -d "$p" ]; then k=D; elif [ -f "$p" ]; then k=F; else k=L; fi; ` +
|
|
76
|
+
`printf "%s%s\\0" "$k" "$p"; done' sh {} + -o -exec printf 'o%s\\0' {} + 2>/dev/null`,
|
|
77
|
+
" printf 'E\\0'",
|
|
78
|
+
` if [ "$3" = 1 ]; then find -H "$r" -mindepth 1 ${pruned} -o -type f -name .gitignore -print0 2>/dev/null | ` +
|
|
79
|
+
"(cd / && COPYFILE_DISABLE=1 xargs -0 -r tar -cf - -- 2>/dev/null); fi",
|
|
80
|
+
"} | head -c \"$2\" | base64"
|
|
81
|
+
].join("\n");
|
|
82
|
+
/** `$1` is the byte bound; standard input is the NUL-terminated absolute paths to send. */
|
|
83
|
+
const fetching = [
|
|
84
|
+
requireTools,
|
|
85
|
+
"cd / && COPYFILE_DISABLE=1 xargs -0 -r tar -chf - -- 2>/dev/null | head -c \"$1\" | base64"
|
|
86
|
+
].join("\n");
|
|
87
|
+
const failed = (root, reason) => new StdError.StdError({
|
|
88
|
+
code: "command_failed",
|
|
89
|
+
message: `Could not search ${root} on this machine: ${reason}`,
|
|
90
|
+
path: root
|
|
91
|
+
});
|
|
92
|
+
const tooLarge = (root, bound) => new StdError.StdError({
|
|
93
|
+
code: "response_too_large",
|
|
94
|
+
message: `The files under ${root} come to more than ${bound} bytes; narrow the root or the globs`,
|
|
95
|
+
path: root
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Reads the program from the first line of standard input, as base64, and
|
|
99
|
+
* runs it with the arguments and the rest of standard input. A program in
|
|
100
|
+
* the argv would be quoted once by the spawner and again by the transport,
|
|
101
|
+
* and a sealed host refuses to start a command line past 4,096 characters;
|
|
102
|
+
* this line stays short whatever the program says.
|
|
103
|
+
*/
|
|
104
|
+
const bootstrap = `command -v base64 >/dev/null || { echo "${missing("base64")}" >&2; exit 3; }; ` +
|
|
105
|
+
"IFS= read -r p && p=$(printf %s \"$p\" | base64 -d) && exec sh -c \"$p\" sh \"$@\"";
|
|
106
|
+
/**
|
|
107
|
+
* Runs one script on the machine and decodes the base64 it prints, refusing
|
|
108
|
+
* output that reached `bound`: `head` cut it, so it is not the whole answer.
|
|
109
|
+
*/
|
|
110
|
+
const run = (root, script, args, bound, stdin = "") => Effect.gen(function* () {
|
|
111
|
+
const result = yield* Exec.exec("sh", {
|
|
112
|
+
args: ["-c", bootstrap, "sh", ...args],
|
|
113
|
+
stdin: `${Base64.encode(new TextEncoder().encode(script))}\n${stdin}`
|
|
114
|
+
}).pipe(Effect.mapError((error) => failed(root, error.message)));
|
|
115
|
+
if (result.exitCode !== 0) {
|
|
116
|
+
return yield* Effect.fail(failed(root, result.stderr.trim() || `exit ${result.exitCode}`));
|
|
117
|
+
}
|
|
118
|
+
const decoded = Base64.decode(result.stdout.replaceAll(/\s/g, ""));
|
|
119
|
+
if (Result.isFailure(decoded))
|
|
120
|
+
return yield* Effect.fail(failed(root, "the machine answered with invalid base64"));
|
|
121
|
+
if (decoded.success.length >= bound)
|
|
122
|
+
return yield* Effect.fail(tooLarge(root, bound - 1));
|
|
123
|
+
return decoded.success;
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* Builds the peer over a machine's spawner and its `Path`, which resolves a
|
|
127
|
+
* relative root where the machine's file operations do. `maxBytes` lowers
|
|
128
|
+
* the bound on the file content one search brings back; the default is
|
|
129
|
+
* {@link maxBytes}.
|
|
130
|
+
*
|
|
131
|
+
* @category constructors
|
|
132
|
+
* @since 1.0.0-rc.8
|
|
133
|
+
*/
|
|
134
|
+
export const make = (services, options) => {
|
|
135
|
+
const path = Context.get(services, Path.Path);
|
|
136
|
+
const contentBound = (options?.maxBytes ?? maxBytes) + 1;
|
|
137
|
+
const copy = (tree) => Context.make(FileSystem.FileSystem, RemoteTree.fileSystem(tree, path)).pipe(Context.add(Path.Path, path));
|
|
138
|
+
const listed = (root, noIgnore) => {
|
|
139
|
+
const resolved = path.resolve(root);
|
|
140
|
+
const bound = maxListingBytes + 1;
|
|
141
|
+
return Effect.flatMap(run(root, listing, [resolved, String(bound), noIgnore === true ? "0" : "1"], bound), (bytes) => {
|
|
142
|
+
const tree = RemoteTree.parse(bytes, resolved, path);
|
|
143
|
+
return tree === undefined ? Effect.fail(failed(root, "the listing came back malformed")) : Effect.succeed(tree);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
return Search.make({
|
|
147
|
+
grep: (input) => Effect.gen(function* () {
|
|
148
|
+
const tree = yield* listed(input.root, input.noIgnore);
|
|
149
|
+
const read = yield* PortableSearch.searched(input).pipe(Effect.provide(copy(tree)));
|
|
150
|
+
const files = [...new Set(read.map((file) => path.resolve(file)))];
|
|
151
|
+
const bytes = files.length === 0 ? new Uint8Array() : yield* run(input.root, fetching, [String(contentBound)], contentBound, files.map((file) => `${file}\0`).join(""));
|
|
152
|
+
// `tar` ends every archive it writes, even one whose files it could not read.
|
|
153
|
+
const members = files.length === 0 || bytes.length > 0 ? Tar.files(bytes) : undefined;
|
|
154
|
+
if (members === undefined)
|
|
155
|
+
return yield* Effect.fail(failed(input.root, "the files came back malformed"));
|
|
156
|
+
const contents = new Map([...tree.contents, ...RemoteTree.absolute(members)]);
|
|
157
|
+
return yield* PortableSearch.make(copy({ ...tree, contents })).grep(input);
|
|
158
|
+
}).pipe(Effect.provide(services)),
|
|
159
|
+
glob: (input) => Effect.flatMap(listed(input.root, input.noIgnore), (tree) => PortableSearch.make(copy(tree)).glob(input)).pipe(Effect.provide(services))
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=RemoteSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteSearch.js","sourceRoot":"","sources":["../../src/RemoteSearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAChD,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,UAAU,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAA;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;AAEzC,iEAAiE;AACjE,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAExC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAA;AAE/E,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,q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,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACrF,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,+BAA+B,CAAC,CAAC,CAAA;YACzG,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;YAC7E,OAAO,KAAK,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC5E,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CACd,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAC5G,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CACzB;KACJ,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["/**\n * The search contract for a tree on another machine, in two round trips.\n *\n * `PortableSearch` asks `FileSystem` one question per directory, per entry\n * and per file. On a machine reached through a transport, such as a\n * benchmark's task container behind `docker exec`, every question is a\n * process start, so one `grep` over a 6,000-file repository is some 20,000 of\n * them. This peer asks the machine's own shell twice instead. `find` lists\n * the tree under the root, leaving out the directories every walk skips, and\n * `tar` returns its `.gitignore` files with the listing. The in-process peer\n * then decides which files the search reads, a second `tar` returns exactly\n * those, and `PortableSearch` answers over that copy. Every result, notice,\n * and refusal is therefore the in-process peer's own: this module decides\n * only where the bytes come from.\n *\n * It runs through the machine's own `ChildProcessSpawner`, the one\n * `Sandbox.hostContext` serves beside the machine's `FileSystem`. The machine\n * needs `sh`, `find`, `xargs`, `tar`, `head`, and `base64`; GNU, BusyBox, and\n * BSD userlands all have them. Output crosses as base64, so a transport whose\n * channel carries only text returns it intact. A search reads at most\n * {@link maxBytes} of file content and refuses beyond that, naming the root\n * to narrow.\n *\n * @since 1.0.0-rc.8\n */\n\nimport type * as ChildProcessSpawner from \"@smthrs/kernel/ChildProcessSpawner\"\nimport * as Path from \"@smthrs/kernel/Path\"\nimport { Context, Effect } from \"effect\"\nimport * as Base64 from \"effect/encoding/Base64\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Result from \"effect/Result\"\nimport * as Exec from \"./internal/Exec.ts\"\nimport * as Prune from \"./internal/Prune.ts\"\nimport * as RemoteTree from \"./internal/RemoteTree.ts\"\nimport * as Tar from \"./internal/Tar.ts\"\nimport * as PortableSearch from \"./PortableSearch.ts\"\nimport * as Search from \"./Search.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * The most file content one search brings back from the machine.\n *\n * The copy is held in memory while the in-process peer reads it, so the\n * bound is on this process's memory rather than on the search: a root that\n * holds more is refused with `response_too_large` and a narrower root or\n * globs answer it.\n *\n * @category constants\n * @since 1.0.0-rc.8\n */\nexport const maxBytes = 256 * 1024 * 1024\n\n/** The most a listing, with its `.gitignore` files, may take. */\nconst maxListingBytes = 64 * 1024 * 1024\n\nconst quoted = (value: string): string => `'${value.replaceAll(\"'\", `'\\\\''`)}'`\n\nconst pruned = `\\\\( ${Prune.repositoryDirectories.map((name) => `-name ${quoted(name)}`).join(\" -o \")} \\\\) -prune`\n\n/** The refusal for a machine without one of the tools a search runs. */\nconst missing = (tool: string) => `searching this machine needs ${tool}, which it does not have`\n\nconst requireTools = `for t in find xargs tar head; do command -v \"$t\" >/dev/null || { ` +\n `echo \"${missing(\"$t\")}\" >&2; exit 3; }; done`\n\n/**\n * `$1` is the root, `$2` the byte bound, and `$3` is `1` to send the\n * `.gitignore` files after the listing. Records are NUL-terminated `<kind><path>`;\n * an `E` record ends the listing, and a tar stream of the ignore files follows.\n */\nconst listing = [\n \"set -f\",\n requireTools,\n \"r=$1\",\n \"{\",\n \" if [ -d \\\"$r\\\" ]; then if [ -r \\\"$r\\\" ] && [ -x \\\"$r\\\" ]; then printf 'd%s\\\\0' \\\"$r\\\"; else printf 'u%s\\\\0' \\\"$r\\\"; fi\",\n \" elif [ -f \\\"$r\\\" ]; then printf 'f%s\\\\0' \\\"$r\\\"\",\n \" elif [ -e \\\"$r\\\" ]; then printf 'o%s\\\\0' \\\"$r\\\"\",\n \" fi\",\n // No `-exec … {} +` inside parentheses: BusyBox `find` never runs one there.\n ` find -H \"$r\" -mindepth 1 ${pruned} -o -type d -exec printf 'd%s\\\\0' {} + ` +\n `-o -type f -exec printf 'f%s\\\\0' {} + ` +\n `-o -type l -exec sh -c 'for p do if [ -d \"$p\" ]; then k=D; elif [ -f \"$p\" ]; then k=F; else k=L; fi; ` +\n `printf \"%s%s\\\\0\" \"$k\" \"$p\"; done' sh {} + -o -exec printf 'o%s\\\\0' {} + 2>/dev/null`,\n \" printf 'E\\\\0'\",\n ` if [ \"$3\" = 1 ]; then find -H \"$r\" -mindepth 1 ${pruned} -o -type f -name .gitignore -print0 2>/dev/null | ` +\n \"(cd / && COPYFILE_DISABLE=1 xargs -0 -r tar -cf - -- 2>/dev/null); fi\",\n \"} | head -c \\\"$2\\\" | base64\"\n].join(\"\\n\")\n\n/** `$1` is the byte bound; standard input is the NUL-terminated absolute paths to send. */\nconst fetching = [\n requireTools,\n \"cd / && COPYFILE_DISABLE=1 xargs -0 -r tar -chf - -- 2>/dev/null | head -c \\\"$1\\\" | base64\"\n].join(\"\\n\")\n\nconst failed = (root: string, reason: string): StdError.StdError =>\n new StdError.StdError({\n code: \"command_failed\",\n message: `Could not search ${root} on this machine: ${reason}`,\n path: root\n })\n\nconst tooLarge = (root: string, bound: number): StdError.StdError =>\n new StdError.StdError({\n code: \"response_too_large\",\n message: `The files under ${root} come to more than ${bound} bytes; narrow the root or the globs`,\n path: root\n })\n\n/**\n * Reads the program from the first line of standard input, as base64, and\n * runs it with the arguments and the rest of standard input. A program in\n * the argv would be quoted once by the spawner and again by the transport,\n * and a sealed host refuses to start a command line past 4,096 characters;\n * this line stays short whatever the program says.\n */\nconst bootstrap = `command -v base64 >/dev/null || { echo \"${missing(\"base64\")}\" >&2; exit 3; }; ` +\n \"IFS= read -r p && p=$(printf %s \\\"$p\\\" | base64 -d) && exec sh -c \\\"$p\\\" sh \\\"$@\\\"\"\n\n/**\n * Runs one script on the machine and decodes the base64 it prints, refusing\n * output that reached `bound`: `head` cut it, so it is not the whole answer.\n */\nconst run = (\n root: string,\n script: string,\n args: ReadonlyArray<string>,\n bound: number,\n stdin = \"\"\n): Effect.Effect<Uint8Array, StdError.StdError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function*() {\n const result = yield* Exec.exec(\"sh\", {\n args: [\"-c\", bootstrap, \"sh\", ...args],\n stdin: `${Base64.encode(new TextEncoder().encode(script))}\\n${stdin}`\n }).pipe(Effect.mapError((error) => failed(root, error.message)))\n if (result.exitCode !== 0) {\n return yield* Effect.fail(failed(root, result.stderr.trim() || `exit ${result.exitCode}`))\n }\n const decoded = Base64.decode(result.stdout.replaceAll(/\\s/g, \"\"))\n if (Result.isFailure(decoded)) return yield* Effect.fail(failed(root, \"the machine answered with invalid base64\"))\n if (decoded.success.length >= bound) return yield* Effect.fail(tooLarge(root, bound - 1))\n return decoded.success\n })\n\n/**\n * Builds the peer over a machine's spawner and its `Path`, which resolves a\n * relative root where the machine's file operations do. `maxBytes` lowers\n * the bound on the file content one search brings back; the default is\n * {@link maxBytes}.\n *\n * @category constructors\n * @since 1.0.0-rc.8\n */\nexport const make = (\n services: Context.Context<ChildProcessSpawner.ChildProcessSpawner | Path.Path>,\n options?: { readonly maxBytes?: number | undefined }\n): Search.Search => {\n const path = Context.get(services, Path.Path)\n const contentBound = (options?.maxBytes ?? maxBytes) + 1\n const copy = (tree: RemoteTree.Tree) =>\n Context.make(FileSystem.FileSystem, RemoteTree.fileSystem(tree, path)).pipe(Context.add(Path.Path, path))\n const listed = (root: string, noIgnore: boolean | undefined) => {\n const resolved = path.resolve(root)\n const bound = maxListingBytes + 1\n return Effect.flatMap(\n run(root, listing, [resolved, String(bound), noIgnore === true ? \"0\" : \"1\"], bound),\n (bytes) => {\n const tree = RemoteTree.parse(bytes, resolved, path)\n return tree === undefined ? Effect.fail(failed(root, \"the listing came back malformed\")) : Effect.succeed(tree)\n }\n )\n }\n return Search.make({\n grep: (input) =>\n Effect.gen(function*() {\n const tree = yield* listed(input.root, input.noIgnore)\n const read = yield* PortableSearch.searched(input).pipe(Effect.provide(copy(tree)))\n const files = [...new Set(read.map((file) => path.resolve(file)))]\n const bytes = files.length === 0 ? new Uint8Array() : yield* run(\n input.root,\n fetching,\n [String(contentBound)],\n contentBound,\n files.map((file) => `${file}\\0`).join(\"\")\n )\n // `tar` ends every archive it writes, even one whose files it could not read.\n const members = files.length === 0 || bytes.length > 0 ? Tar.files(bytes) : undefined\n if (members === undefined) return yield* Effect.fail(failed(input.root, \"the files came back malformed\"))\n const contents = new Map([...tree.contents, ...RemoteTree.absolute(members)])\n return yield* PortableSearch.make(copy({ ...tree, contents })).grep(input)\n }).pipe(Effect.provide(services)),\n glob: (input) =>\n Effect.flatMap(listed(input.root, input.noIgnore), (tree) => PortableSearch.make(copy(tree)).glob(input)).pipe(\n Effect.provide(services)\n )\n })\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export * as SearchConformance from "./SearchConformance.ts";
|
|
|
44
44
|
export * as PortableSearch from "./PortableSearch.ts";
|
|
45
45
|
/** @category layers @since 1.0.0 */
|
|
46
46
|
export * as NativeSearch from "./NativeSearch.ts";
|
|
47
|
+
/** @category layers @since 1.0.0-rc.8 */
|
|
48
|
+
export * as RemoteSearch from "./RemoteSearch.ts";
|
|
47
49
|
/**
|
|
48
50
|
* @category flows
|
|
49
51
|
* @since 1.0.0
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,sCAAsC;AACtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,sCAAsC;AACtC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,yCAAyC;AACzC,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D,oCAAoC;AACpC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,oCAAoC;AACpC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,sCAAsC;AACtC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;;GAGG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAEvD,sCAAsC;AACtC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C,yCAAyC;AACzC,OAAO,KAAK,QAAQ,MAAM,eA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AK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,mCAAmC;AACnC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,mCAAmC;AACnC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,sCAAsC;AACtC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,sCAAsC;AACtC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,oCAAoC;AACpC,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D,mCAAmC;AACnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -44,6 +44,8 @@ export * as SearchConformance from "./SearchConformance.js";
|
|
|
44
44
|
export * as PortableSearch from "./PortableSearch.js";
|
|
45
45
|
/** @category layers @since 1.0.0 */
|
|
46
46
|
export * as NativeSearch from "./NativeSearch.js";
|
|
47
|
+
/** @category layers @since 1.0.0-rc.8 */
|
|
48
|
+
export * as RemoteSearch from "./RemoteSearch.js";
|
|
47
49
|
/**
|
|
48
50
|
* @category flows
|
|
49
51
|
* @since 1.0.0
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW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;AAEzC;;;GAGG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,mCAAmC;AACnC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,mCAAmC;AACnC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,sCAAsC;AACtC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,sCAAsC;AACtC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,oCAAoC;AACpC,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D,mCAAmC;AACnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA","sourcesContent":["/**\n * `@smthrs/std`: the standard coding tools expressed as flows, the host\n * services they bind, and the one error they share.\n *\n * @since 1.0.0\n */\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Read from \"./Read.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Write from \"./Write.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Edit from \"./Edit.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Ls from \"./Ls.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Glob from \"./Glob.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Grep from \"./Grep.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Search from \"./Search.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as SearchContract from \"./SearchContract.ts\"\n\n/** @category conformance @since 1.0.0 */\nexport * as SearchConformance from \"./SearchConformance.ts\"\n\n/** @category layers @since 1.0.0 */\nexport * as PortableSearch from \"./PortableSearch.ts\"\n\n/** @category layers @since 1.0.0 */\nexport * as NativeSearch from \"./NativeSearch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Bash from \"./Bash.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Container from \"./Container.ts\"\n\n/**\n * @category measurement\n * @since 1.0.0\n */\nexport * as TreeFingerprint from \"./TreeFingerprint.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Checkpoints from \"./Checkpoints.ts\"\n\n/** @category conversions @since 1.0.0 */\nexport * as Relocate from \"./Relocate.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as TestRun from \"./TestRun.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as TestRunner from \"./TestRunner.ts\"\n\n/**\n * @category classification\n * @since 1.0.0\n */\nexport * as Probe from \"./Probe.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as ApplyPatch from \"./ApplyPatch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as ShellCommand from \"./ShellCommand.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as UpdatePlan from \"./UpdatePlan.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Fetch from \"./Fetch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as HttpPost from \"./HttpPost.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Explore from \"./Explore.ts\"\n\n/** @category flows @since 1.0.0 */\nexport * as WebFetch from \"./WebFetch.ts\"\n/** @category flows @since 1.0.0 */\nexport * as WebSearch from \"./WebSearch.ts\"\n/** @category services @since 1.0.0 */\nexport * as ExaWebSearch from \"./ExaWebSearch.ts\"\n/** @category services @since 1.0.0 */\nexport * as LanguageServer from \"./LanguageServer.ts\"\n/** @category layers @since 1.0.0 */\nexport * as NodeLanguageServer from \"./NodeLanguageServer.ts\"\n/** @category flows @since 1.0.0 */\nexport * as Lsp from \"./Lsp.ts\"\n\n/**\n * @category registries\n * @since 1.0.0\n */\nexport * as Manifest from \"./Manifest.ts\"\n\n/**\n * @category errors\n * @since 1.0.0\n */\nexport * as StdError from \"./StdError.ts\"\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,sCAAsC;AACtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,sCAAsC;AACtC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,yCAAyC;AACzC,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D,oCAAoC;AACpC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,oCAAoC;AACpC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD,yCAAyC;AACzC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;;GAGG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,sCAAsC;AACtC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;;GAGG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AAEvD,sCAAsC;AACtC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C,yCAAyC;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,sCAAsC;AACtC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;GAGG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;GAGG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,mCAAmC;AACnC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,mCAAmC;AACnC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,sCAAsC;AACtC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,sCAAsC;AACtC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,oCAAoC;AACpC,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D,mCAAmC;AACnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;GAGG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA","sourcesContent":["/**\n * `@smthrs/std`: the standard coding tools expressed as flows, the host\n * services they bind, and the one error they share.\n *\n * @since 1.0.0\n */\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Read from \"./Read.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Write from \"./Write.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Edit from \"./Edit.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Ls from \"./Ls.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Glob from \"./Glob.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Grep from \"./Grep.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Search from \"./Search.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as SearchContract from \"./SearchContract.ts\"\n\n/** @category conformance @since 1.0.0 */\nexport * as SearchConformance from \"./SearchConformance.ts\"\n\n/** @category layers @since 1.0.0 */\nexport * as PortableSearch from \"./PortableSearch.ts\"\n\n/** @category layers @since 1.0.0 */\nexport * as NativeSearch from \"./NativeSearch.ts\"\n\n/** @category layers @since 1.0.0-rc.8 */\nexport * as RemoteSearch from \"./RemoteSearch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Bash from \"./Bash.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Container from \"./Container.ts\"\n\n/**\n * @category measurement\n * @since 1.0.0\n */\nexport * as TreeFingerprint from \"./TreeFingerprint.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as Checkpoints from \"./Checkpoints.ts\"\n\n/** @category conversions @since 1.0.0 */\nexport * as Relocate from \"./Relocate.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as TestRun from \"./TestRun.ts\"\n\n/** @category services @since 1.0.0 */\nexport * as TestRunner from \"./TestRunner.ts\"\n\n/**\n * @category classification\n * @since 1.0.0\n */\nexport * as Probe from \"./Probe.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as ApplyPatch from \"./ApplyPatch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as ShellCommand from \"./ShellCommand.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as UpdatePlan from \"./UpdatePlan.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Fetch from \"./Fetch.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as HttpPost from \"./HttpPost.ts\"\n\n/**\n * @category flows\n * @since 1.0.0\n */\nexport * as Explore from \"./Explore.ts\"\n\n/** @category flows @since 1.0.0 */\nexport * as WebFetch from \"./WebFetch.ts\"\n/** @category flows @since 1.0.0 */\nexport * as WebSearch from \"./WebSearch.ts\"\n/** @category services @since 1.0.0 */\nexport * as ExaWebSearch from \"./ExaWebSearch.ts\"\n/** @category services @since 1.0.0 */\nexport * as LanguageServer from \"./LanguageServer.ts\"\n/** @category layers @since 1.0.0 */\nexport * as NodeLanguageServer from \"./NodeLanguageServer.ts\"\n/** @category flows @since 1.0.0 */\nexport * as Lsp from \"./Lsp.ts\"\n\n/**\n * @category registries\n * @since 1.0.0\n */\nexport * as Manifest from \"./Manifest.ts\"\n\n/**\n * @category errors\n * @since 1.0.0\n */\nexport * as StdError from \"./StdError.ts\"\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvelopePrecheck.d.ts","sourceRoot":"","sources":["../../../src/internal/EnvelopePrecheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAG1C;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACvC;AAED;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;
|
|
1
|
+
{"version":3,"file":"EnvelopePrecheck.d.ts","sourceRoot":"","sources":["../../../src/internal/EnvelopePrecheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAG1C;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACvC;AAED;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AA0VD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,KAAG,aAAa,CAAC,aAAa,CAClE,CAAA;AAmB9B;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,QAAQ,EACf,MAAM,MAAM,EACZ,MAAM,IAAI,CAAC,IAAI,KACd,QAAQ,CAAC,QAAQ,GAAG,SAgDtB,CAAA"}
|
|
@@ -76,6 +76,9 @@ const reservedWords = new Set([
|
|
|
76
76
|
const writeCommands = new Set(["chmod", "chown", "mkdir", "rm", "rmdir", "tee", "touch", "truncate", "unlink"]);
|
|
77
77
|
const destinationCommands = new Set(["cp", "install", "mv"]);
|
|
78
78
|
const prefixWrappers = new Set(["env", "nice", "time", "sudo", "nohup", "xargs", "command", "exec"]);
|
|
79
|
+
// A shell runs the argument of its `-c` flag as shell text of its own.
|
|
80
|
+
const shells = new Set(["ash", "bash", "dash", "fish", "ksh", "mksh", "sh", "zsh"]);
|
|
81
|
+
const commandFlag = /^-[A-Za-z]*c[A-Za-z]*$/;
|
|
79
82
|
// The end of a `$(` body that starts at `from`: the index of its closing
|
|
80
83
|
// parenthesis, skipping quoted spans and nested parentheses. An unclosed body
|
|
81
84
|
// runs to the end of the text, which is how a fail-closed scan must read it.
|
|
@@ -269,7 +272,7 @@ const isPathToken = (path, token) => token === "." ||
|
|
|
269
272
|
path.isAbsolute(token) ||
|
|
270
273
|
/^[A-Za-z]:[\\/]/.test(token) ||
|
|
271
274
|
token.includes("/");
|
|
272
|
-
const segmentReferences = (path, tokens) => {
|
|
275
|
+
const segmentReferences = (path, tokens, nesting) => {
|
|
273
276
|
// The word after a redirection operator is its target, never the command.
|
|
274
277
|
const isTarget = (index) => index > 0 && isRedirection(tokens[index - 1]);
|
|
275
278
|
const isWord = (index) => !tokens[index].operator && !isTarget(index);
|
|
@@ -289,10 +292,26 @@ const segmentReferences = (path, tokens) => {
|
|
|
289
292
|
commandIndex = mutatingIndex;
|
|
290
293
|
}
|
|
291
294
|
const command = commandIndex === -1 ? "" : name(commandIndex);
|
|
295
|
+
// Shell text handed to `eval` or to a shell's `-c` flag is a command, not a
|
|
296
|
+
// path: reading `sh -c 'rm /work/target'` as one quoted word let a delete
|
|
297
|
+
// pass as a read of a file named `rm /work/target`.
|
|
298
|
+
const scripts = new Set();
|
|
299
|
+
if (command === "eval") {
|
|
300
|
+
for (let index = commandIndex + 1; index < tokens.length; index++)
|
|
301
|
+
if (isWord(index))
|
|
302
|
+
scripts.add(index);
|
|
303
|
+
}
|
|
304
|
+
else if (shells.has(command)) {
|
|
305
|
+
const flag = tokens.findIndex((token, index) => index > commandIndex && isWord(index) && commandFlag.test(token.text));
|
|
306
|
+
if (flag !== -1 && flag + 1 < tokens.length && isWord(flag + 1))
|
|
307
|
+
scripts.add(flag + 1);
|
|
308
|
+
}
|
|
292
309
|
const candidates = [];
|
|
293
310
|
for (let index = 0; index < tokens.length; index++) {
|
|
294
311
|
const token = tokens[index];
|
|
295
|
-
if (index === commandIndex ||
|
|
312
|
+
if (index === commandIndex || scripts.has(index) || token.operator)
|
|
313
|
+
continue;
|
|
314
|
+
if (!isTarget(index) && token.text.startsWith("-"))
|
|
296
315
|
continue;
|
|
297
316
|
if (isTarget(index) && textRedirections.has(tokens[index - 1].text))
|
|
298
317
|
continue;
|
|
@@ -303,7 +322,9 @@ const segmentReferences = (path, tokens) => {
|
|
|
303
322
|
const destinationIndex = destinationCommands.has(command)
|
|
304
323
|
? candidates.filter(({ index }) => !isTarget(index)).at(-1)?.index
|
|
305
324
|
: undefined;
|
|
306
|
-
|
|
325
|
+
const script = [...scripts].map((index) => tokens[index].text).join(" ");
|
|
326
|
+
const nested = script === "" ? [] : references(path, script, nesting + 1);
|
|
327
|
+
const named = candidates.map(({ index, value }) => {
|
|
307
328
|
const access = isTarget(index)
|
|
308
329
|
? writeRedirections.has(tokens[index - 1].text) ? "write" : "read"
|
|
309
330
|
: writeCommands.has(command) || destinationIndex === index
|
|
@@ -311,21 +332,24 @@ const segmentReferences = (path, tokens) => {
|
|
|
311
332
|
: "read";
|
|
312
333
|
return { access, value };
|
|
313
334
|
});
|
|
335
|
+
return [...named, ...nested];
|
|
314
336
|
};
|
|
315
337
|
const references = (path, command, nesting) => {
|
|
338
|
+
if (nesting > maxNesting)
|
|
339
|
+
throw tooDeep();
|
|
316
340
|
const { substitutions, tokens } = lex(command, nesting);
|
|
317
341
|
const found = [];
|
|
318
342
|
let segment = [];
|
|
319
343
|
for (const token of tokens) {
|
|
320
344
|
if (token.operator && commandSeparators.has(token.text)) {
|
|
321
|
-
found.push(...segmentReferences(path, segment));
|
|
345
|
+
found.push(...segmentReferences(path, segment, nesting));
|
|
322
346
|
segment = [];
|
|
323
347
|
}
|
|
324
348
|
else {
|
|
325
349
|
segment.push(token);
|
|
326
350
|
}
|
|
327
351
|
}
|
|
328
|
-
found.push(...segmentReferences(path, segment));
|
|
352
|
+
found.push(...segmentReferences(path, segment, nesting));
|
|
329
353
|
// A substitution runs its body as a command; its paths count like any other.
|
|
330
354
|
for (const body of substitutions)
|
|
331
355
|
found.push(...references(path, body, nesting + 1));
|