@moldea.ai/cli 11.1.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/moldea.js CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { A as hasOnlyUnicodeScalarValues$1, C as formatMoldeaCliJsonError, D as createMoldeaCliOwnedError, E as formatMoldeaCliJsonValidateResult, F as encodeMoldeaCliCursor, I as MoldeaCliOutputPageException, L as MOLDEA_CLI_COMMANDS, M as createMoldeaCliOutputPage, N as calculateMoldeaCliJsonDigest, O as MOLDEA_CLI_GIT_WORKING_TREE_SOURCE, P as decodeMoldeaCliCursor, S as formatMoldeaCliJsonContentResult, T as formatMoldeaCliJsonScopeResult, _ as formatMoldeaCliHumanError, a as require_semver, b as formatMoldeaCliHumanValidateResult, c as executeGitStreamingProcess, d as createMoldeaCliDiagnosticRecord, f as createMoldeaCliInspectProjection, g as formatMoldeaCliHumanContentResult, h as formatMoldeaCliHumanCompositionResult, j as isRepositoryDirectoryInputValid, k as parseMoldeaCliArguments, l as executeGitProcess, m as formatMoldeaCliHelp, o as MoldeaCliCompositionException, p as createMoldeaCliValidateProjection, s as createGitVersionPreflight, u as MAX_GIT_PROCESS_DIAGNOSTIC_BYTES, v as formatMoldeaCliHumanInspectResult, w as formatMoldeaCliJsonInspectResult, x as formatMoldeaCliJsonCompositionResult, y as formatMoldeaCliHumanScopeResult } from "./chunks/composition-P7DOCYEA.js";
2
+ import { A as createMoldeaCliOutputPage, C as formatMoldeaCliJsonInspectResult, D as MOLDEA_CLI_GIT_WORKING_TREE_SOURCE, E as createMoldeaCliOwnedError, F as MOLDEA_CLI_COMMANDS, M as decodeMoldeaCliCursor, N as encodeMoldeaCliCursor, O as parseMoldeaCliArguments, P as MoldeaCliOutputPageException, S as formatMoldeaCliJsonError, T as formatMoldeaCliJsonValidateResult, _ as formatMoldeaCliHumanInspectResult, a as require_semver, b as formatMoldeaCliJsonCompositionResult, c as runGitCommand, d as createMoldeaCliInspectProjection, f as createMoldeaCliValidateProjection, g as formatMoldeaCliHumanError, h as formatMoldeaCliHumanContentResult, j as calculateMoldeaCliJsonDigest, k as isRepositoryDirectoryInputValid, l as readGit, m as formatMoldeaCliHumanCompositionResult, o as MoldeaCliCompositionException, p as formatMoldeaCliHelp, s as createGitVersionPreflight, u as createMoldeaCliDiagnosticRecord, v as formatMoldeaCliHumanScopeResult, w as formatMoldeaCliJsonScopeResult, x as formatMoldeaCliJsonContentResult, y as formatMoldeaCliHumanValidateResult } from "./chunks/composition-cVui-wF_.js";
3
3
  import path from "node:path";
4
4
  import process from "node:process";
5
5
  import { fileURLToPath } from "node:url";
6
- import { REPOSITORY_ROOT, RepositorySourceException, createRepositoryComparison, isRepositoryPath, parseRepositoryPath } from "@moldea.ai/repository";
6
+ import { hasErrorCode } from "jg-exception";
7
+ import { ERRORS, createShutdownSignal, readStdin } from "jg-process";
8
+ import { countUtf8Bytes } from "jg-utilities";
9
+ import { REPOSITORY_LINK_TEXT_MAX_BYTES, REPOSITORY_ROOT, RepositorySourceException, createRepositoryComparison, isRepositoryPath, parseRepositoryPath } from "@moldea.ai/repository";
7
10
  import { lstat, readFile, readdir, stat } from "node:fs/promises";
11
+ import { listUntrackedFiles, readConfigBoolean, readIndexEntries, readTopLevel } from "jg-git-commands";
8
12
  import { CoreConfigurationException, CoreOperationException, createCore } from "@moldea.ai/core";
9
13
  import { Buffer as Buffer$1 } from "node:buffer";
10
- import { createFilesystemRepositoryLinkResolver, createFilesystemRepositoryReader } from "@moldea.ai/repository-fs";
14
+ import { createFilesystemRepositoryReader } from "@moldea.ai/repository-fs";
11
15
  //#region src/cli-execution/constants.ts
12
16
  var MOLDEA_CLI_EXIT_CODES = {
13
17
  Interrupted: 130,
@@ -67,21 +71,10 @@ var decodeGitOutput = (output) => {
67
71
  } catch {
68
72
  return null;
69
73
  }
70
- if (decodedOutput.includes("\0") || !hasOnlyUnicodeScalarValues$1(decodedOutput)) return null;
74
+ if (decodedOutput.includes("\0") || !decodedOutput.isWellFormed()) return null;
71
75
  return decodedOutput;
72
76
  };
73
77
  /**
74
- * Parses Git's canonical boolean output.
75
- * @param output The raw bounded Git stdout bytes.
76
- * @returns The parsed boolean, or null when the output is not canonical.
77
- */
78
- var parseGitBooleanOutput = (output) => {
79
- const decodedOutput = decodeGitOutput(output);
80
- if (decodedOutput === "true\n" || decodedOutput === "true\r\n") return true;
81
- if (decodedOutput === "false\n" || decodedOutput === "false\r\n") return false;
82
- return null;
83
- };
84
- /**
85
78
  * Parses one nonempty path returned by Git.
86
79
  * @param output The raw bounded Git stdout bytes.
87
80
  * @returns The exact relative or absolute path, or null when the output is invalid.
@@ -130,7 +123,7 @@ var mapFilesystemFailure$3 = (error) => {
130
123
  * @returns A safe inspector that resolves and verifies the selected directory.
131
124
  */
132
125
  var createGitStartingDirectoryInspector = (inspectPath = stat) => async (input) => {
133
- if (!path.isAbsolute(input.invocationDirectory) || input.invocationDirectory.includes("\0") || !hasOnlyUnicodeScalarValues$1(input.invocationDirectory) || input.repositoryDirectory !== null && !isRepositoryDirectoryInputValid(input.repositoryDirectory)) return Object.freeze({
126
+ if (!path.isAbsolute(input.invocationDirectory) || input.invocationDirectory.includes("\0") || !input.invocationDirectory.isWellFormed() || input.repositoryDirectory !== null && !isRepositoryDirectoryInputValid(input.repositoryDirectory)) return Object.freeze({
134
127
  errorCode: "GIT_REPOSITORY_NOT_FOUND",
135
128
  kind: "failed"
136
129
  });
@@ -151,14 +144,19 @@ var createGitStartingDirectoryInspector = (inspectPath = stat) => async (input)
151
144
  var inspectGitStartingDirectory = createGitStartingDirectoryInspector();
152
145
  //#endregion
153
146
  //#region src/git-working-tree/discovery.ts
154
- /** Maps a normalized Git process failure to a safe discovery error. */
155
- var mapGitProcessFailure$5 = (reason) => {
147
+ var GIT_DISCOVERY_READS = Object.freeze({
148
+ readConfigBoolean,
149
+ readTopLevel
150
+ });
151
+ /** Maps a normalized Git failure to a safe discovery error. */
152
+ var mapGitFailure$5 = (reason) => {
156
153
  switch (reason) {
157
154
  case "aborted": return "GIT_OPERATION_ABORTED";
158
155
  case "not-found": return "GIT_NOT_FOUND";
159
156
  case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
160
157
  case "access-denied": return "GIT_ACCESS_DENIED";
161
- case "output-limit-exceeded": return "GIT_OUTPUT_INVALID";
158
+ case "output-limit-exceeded":
159
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
162
160
  case "command-failed": return "GIT_COMMAND_FAILED";
163
161
  }
164
162
  };
@@ -168,69 +166,35 @@ var createDiscoveryFailure = (errorCode) => Object.freeze({
168
166
  kind: "failed"
169
167
  });
170
168
  /**
171
- * Creates Git working-tree discovery around injectable process and filesystem boundaries.
172
- * @param processExecutor The normalized Git subprocess executor.
169
+ * Creates Git working-tree discovery around injectable Git and filesystem boundaries.
170
+ * @param git The typed Git reads.
173
171
  * @param startingDirectoryInspector The safe directory inspection boundary.
174
172
  * @param gitVersionPreflight The Git version prerequisite check.
175
173
  * @returns A working-tree discovery operation.
176
174
  */
177
- var createGitWorkingTreeDiscovery = (processExecutor = executeGitProcess, startingDirectoryInspector = inspectGitStartingDirectory, gitVersionPreflight = createGitVersionPreflight(processExecutor)) => async (input) => {
175
+ var createGitWorkingTreeDiscovery = (git = GIT_DISCOVERY_READS, startingDirectoryInspector = inspectGitStartingDirectory, gitVersionPreflight = createGitVersionPreflight()) => async (input) => {
178
176
  const startingDirectoryResult = await startingDirectoryInspector(input);
179
177
  if (startingDirectoryResult.kind === "failed") return createDiscoveryFailure(startingDirectoryResult.errorCode);
180
- const workTreeResult = await processExecutor({
181
- arguments: [
182
- "-C",
183
- startingDirectoryResult.directory,
184
- "rev-parse",
185
- "--is-inside-work-tree"
186
- ],
187
- maxBufferBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
178
+ const gitOptions = {
179
+ maxOutputBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
180
+ timeoutSeconds: 300,
188
181
  ...input.signal === void 0 ? {} : { signal: input.signal }
189
- });
190
- if (workTreeResult.kind === "failed") return createDiscoveryFailure(mapGitProcessFailure$5(workTreeResult.reason));
191
- if (workTreeResult.stderr.byteLength > 0) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
192
- const isInsideWorkTree = parseGitBooleanOutput(workTreeResult.stdout);
193
- if (isInsideWorkTree === null) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
194
- if (!isInsideWorkTree) return createDiscoveryFailure("GIT_WORK_TREE_REQUIRED");
195
- const rootResult = await processExecutor({
196
- arguments: [
197
- "-C",
198
- startingDirectoryResult.directory,
199
- "rev-parse",
200
- "--show-toplevel"
201
- ],
202
- maxBufferBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
203
- ...input.signal === void 0 ? {} : { signal: input.signal }
204
- });
205
- if (rootResult.kind === "failed") return createDiscoveryFailure(mapGitProcessFailure$5(rootResult.reason));
206
- if (rootResult.stderr.byteLength > 0) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
207
- const repositoryRoot = parseGitAbsolutePathOutput(rootResult.stdout);
208
- if (repositoryRoot === null) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
182
+ };
183
+ const rootResult = await readGit(() => git.readTopLevel(startingDirectoryResult.directory, gitOptions), input.signal);
184
+ if (rootResult.kind === "failed") return createDiscoveryFailure(mapGitFailure$5(rootResult.reason));
185
+ if (rootResult.value === null) return createDiscoveryFailure("GIT_WORK_TREE_REQUIRED");
186
+ const repositoryRoot = rootResult.value;
187
+ if (!path.isAbsolute(repositoryRoot)) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
209
188
  const rootDirectoryResult = await startingDirectoryInspector({
210
189
  invocationDirectory: startingDirectoryResult.directory,
211
190
  repositoryDirectory: repositoryRoot
212
191
  });
213
192
  if (rootDirectoryResult.kind === "failed") return createDiscoveryFailure(rootDirectoryResult.errorCode);
214
- const versionResult = await gitVersionPreflight(input.signal);
193
+ const versionResult = await gitVersionPreflight(rootDirectoryResult.directory, input.signal);
215
194
  if (versionResult.kind === "failed") return createDiscoveryFailure(versionResult.errorCode);
216
- const sparseCheckoutResult = await processExecutor({
217
- arguments: [
218
- "-C",
219
- rootDirectoryResult.directory,
220
- "config",
221
- "--type=bool",
222
- "--default=false",
223
- "--get",
224
- "core.sparseCheckout"
225
- ],
226
- maxBufferBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
227
- ...input.signal === void 0 ? {} : { signal: input.signal }
228
- });
229
- if (sparseCheckoutResult.kind === "failed") return createDiscoveryFailure(mapGitProcessFailure$5(sparseCheckoutResult.reason));
230
- if (sparseCheckoutResult.stderr.byteLength > 0) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
231
- const isSparseCheckout = parseGitBooleanOutput(sparseCheckoutResult.stdout);
232
- if (isSparseCheckout === null) return createDiscoveryFailure("GIT_OUTPUT_INVALID");
233
- if (isSparseCheckout) return createDiscoveryFailure("GIT_SPARSE_CHECKOUT_UNSUPPORTED");
195
+ const sparseCheckoutResult = await readGit(() => git.readConfigBoolean(rootDirectoryResult.directory, "core.sparseCheckout", false, gitOptions), input.signal);
196
+ if (sparseCheckoutResult.kind === "failed") return createDiscoveryFailure(mapGitFailure$5(sparseCheckoutResult.reason));
197
+ if (sparseCheckoutResult.value) return createDiscoveryFailure("GIT_SPARSE_CHECKOUT_UNSUPPORTED");
234
198
  return Object.freeze({
235
199
  kind: "discovered",
236
200
  repositoryRoot
@@ -281,14 +245,15 @@ var createInspectionFailure$2 = (errorCode) => Object.freeze({
281
245
  errorCode,
282
246
  kind: "failed"
283
247
  });
284
- /** Maps one normalized Git process failure to the discovery error contract. */
285
- var mapGitProcessFailure$4 = (reason) => {
248
+ /** Maps one normalized Git failure to the discovery error contract. */
249
+ var mapGitFailure$4 = (reason) => {
286
250
  switch (reason) {
287
251
  case "aborted": return "GIT_OPERATION_ABORTED";
288
252
  case "not-found": return "GIT_NOT_FOUND";
289
253
  case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
290
254
  case "access-denied": return "GIT_ACCESS_DENIED";
291
- case "output-limit-exceeded": return "GIT_OUTPUT_INVALID";
255
+ case "output-limit-exceeded":
256
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
292
257
  case "command-failed": return "GIT_COMMAND_FAILED";
293
258
  }
294
259
  };
@@ -308,19 +273,14 @@ var mapFilesystemFailure$2 = (error) => {
308
273
  return "GIT_COMMAND_FAILED";
309
274
  };
310
275
  /** Executes one bounded Git identity-path query. */
311
- var queryGitPath = async (processExecutor, repositoryRoot, arguments_, isAbsoluteRequired, signal) => {
312
- const result = await processExecutor({
313
- arguments: [
314
- "-C",
315
- repositoryRoot,
316
- ...arguments_
317
- ],
318
- maxBufferBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
276
+ var queryGitPath = async (runGit, repositoryRoot, arguments_, isAbsoluteRequired, signal) => {
277
+ const result = await runGit(arguments_, {
278
+ cwd: repositoryRoot,
279
+ maxOutputBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
319
280
  ...signal === void 0 ? {} : { signal }
320
281
  });
321
- if (result.kind === "failed") return createInspectionFailure$2(mapGitProcessFailure$4(result.reason));
322
- if (result.stderr.byteLength > 0) return createInspectionFailure$2("GIT_OUTPUT_INVALID");
323
- return (isAbsoluteRequired ? parseGitAbsolutePathOutput(result.stdout) : parseGitPathOutput(result.stdout)) ?? createInspectionFailure$2("GIT_OUTPUT_INVALID");
282
+ if (result.kind === "failed") return createInspectionFailure$2(mapGitFailure$4(result.reason));
283
+ return (isAbsoluteRequired ? parseGitAbsolutePathOutput(result.value) : parseGitPathOutput(result.value)) ?? createInspectionFailure$2("GIT_OUTPUT_INVALID");
324
284
  };
325
285
  /** Captures one directory path and stable filesystem identity. */
326
286
  var captureLocation = async (inspectPath, hostPath, invalidTypeCode) => {
@@ -340,14 +300,14 @@ var captureLocation = async (inspectPath, hostPath, invalidTypeCode) => {
340
300
  var isInspectionFailure$1 = (result) => typeof result === "object" && "kind" in result && result.kind === "failed";
341
301
  /**
342
302
  * Creates a bounded working-tree identity inspector around Git and filesystem boundaries.
343
- * @param processExecutor The sanitized bounded Git process executor.
303
+ * @param runGit The bounded Git command boundary.
344
304
  * @param inspectPath The followed directory identity operation.
345
305
  * @returns An inspector that captures one private immutable identity.
346
306
  */
347
- var createGitWorkingTreeIdentityInspector = (processExecutor = executeGitProcess, inspectPath = inspectDirectoryIdentity) => {
307
+ var createGitWorkingTreeIdentityInspector = (runGit = runGitCommand, inspectPath = inspectDirectoryIdentity) => {
348
308
  return async (input) => {
349
- if (!path.isAbsolute(input.repositoryRoot) || input.repositoryRoot.includes("\0") || !hasOnlyUnicodeScalarValues$1(input.repositoryRoot)) return createInspectionFailure$2("GIT_OUTPUT_INVALID");
350
- const discoveredRoot = await queryGitPath(processExecutor, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.RepositoryRoot, true, input.signal);
309
+ if (!path.isAbsolute(input.repositoryRoot) || input.repositoryRoot.includes("\0") || !input.repositoryRoot.isWellFormed()) return createInspectionFailure$2("GIT_OUTPUT_INVALID");
310
+ const discoveredRoot = await queryGitPath(runGit, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.RepositoryRoot, true, input.signal);
351
311
  if (isInspectionFailure$1(discoveredRoot)) return discoveredRoot;
352
312
  const repositoryRoot = await captureLocation(inspectPath, discoveredRoot, "GIT_WORK_TREE_REQUIRED");
353
313
  if (input.signal?.aborted) return createInspectionFailure$2("GIT_OPERATION_ABORTED");
@@ -358,9 +318,9 @@ var createGitWorkingTreeIdentityInspector = (processExecutor = executeGitProcess
358
318
  if (isInspectionFailure$1(selectedRepositoryRoot)) return selectedRepositoryRoot;
359
319
  if (!haveSameHostPathIdentity(repositoryRoot, selectedRepositoryRoot)) return Object.freeze({ kind: "mismatched" });
360
320
  }
361
- const gitDirectoryPath = await queryGitPath(processExecutor, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.GitDirectory, true, input.signal);
321
+ const gitDirectoryPath = await queryGitPath(runGit, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.GitDirectory, true, input.signal);
362
322
  if (isInspectionFailure$1(gitDirectoryPath)) return gitDirectoryPath;
363
- const commonDirectoryOutput = await queryGitPath(processExecutor, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.CommonDirectory, false, input.signal);
323
+ const commonDirectoryOutput = await queryGitPath(runGit, input.repositoryRoot, GIT_WORKING_TREE_IDENTITY_ARGUMENTS.CommonDirectory, false, input.signal);
364
324
  if (isInspectionFailure$1(commonDirectoryOutput)) return commonDirectoryOutput;
365
325
  const commonDirectoryPath = path.isAbsolute(commonDirectoryOutput) ? commonDirectoryOutput : path.resolve(input.repositoryRoot, commonDirectoryOutput);
366
326
  const gitDirectory = await captureLocation(inspectPath, gitDirectoryPath, "GIT_OUTPUT_INVALID");
@@ -767,6 +727,25 @@ var GitContentTransformationGuardRepositoryReader = class {
767
727
  throw new GitContentTransformUnsupportedException(parsedPath);
768
728
  }
769
729
  /**
730
+ * Reads a link's stored text unchanged, because Git applies no content transformation to links.
731
+ * @param path The validated repository path of the symlink entry.
732
+ * @param options Optional cancellation controls.
733
+ * @returns A promise resolving to the text, or `null` past 4096 UTF-8 bytes or for invalid UTF-8.
734
+ * @throws
735
+ * - INVALID_REPOSITORY_PATH: The repository path is invalid.
736
+ * - ENTRY_NOT_FOUND: The requested repository entry was not found.
737
+ * - ENTRY_NOT_LINK: The requested repository entry is not a symlink.
738
+ * - ACCESS_DENIED: Access to the repository source was denied.
739
+ * - SOURCE_UNAVAILABLE: The repository source is unavailable.
740
+ * - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
741
+ * - INVALID_SOURCE_DATA: The repository source returned invalid data.
742
+ * - RESOURCE_LIMIT_EXCEEDED: A repository reading resource limit was exceeded.
743
+ * - ABORTED: The repository operation was aborted.
744
+ */
745
+ readLinkText(path, options) {
746
+ return this.#reader.readLinkText(path, options);
747
+ }
748
+ /**
770
749
  * Recursively lists entries without changing the underlying logical inventory.
771
750
  * @param options Optional prefix and cancellation controls.
772
751
  * @returns The underlying async iterable of detached repository entries.
@@ -816,6 +795,7 @@ var REPOSITORY_SOURCE_ERROR_MESSAGES = Object.freeze({
816
795
  ENTRY_NOT_DIRECTORY: "The requested repository entry is not a directory.",
817
796
  ENTRY_NOT_FILE: "The requested repository entry is not a file.",
818
797
  ENTRY_NOT_FOUND: "The requested repository entry was not found.",
798
+ ENTRY_NOT_LINK: "The requested repository entry is not a symlink.",
819
799
  INVALID_PAGE_REQUEST: "The repository page request is invalid.",
820
800
  INVALID_SOURCE_DATA: "The repository source returned invalid data.",
821
801
  PROVIDER_INCOMPLETE: "The repository provider could not expose a complete result.",
@@ -886,25 +866,6 @@ var mapMoldeaCliOperationalError = (error) => {
886
866
  };
887
867
  //#endregion
888
868
  //#region src/git-inventory/constants.ts
889
- var GIT_TRACKED_INVENTORY_ARGUMENTS = [
890
- "ls-files",
891
- "--cached",
892
- "--stage",
893
- "--full-name",
894
- "--no-abbrev",
895
- "--no-recurse-submodules",
896
- "-z",
897
- "--"
898
- ];
899
- var GIT_UNTRACKED_INVENTORY_ARGUMENTS = [
900
- "ls-files",
901
- "--others",
902
- "--exclude-standard",
903
- "--full-name",
904
- "--no-recurse-submodules",
905
- "-z",
906
- "--"
907
- ];
908
869
  var GIT_IGNORED_INVENTORY_ARGUMENTS = [
909
870
  "ls-files",
910
871
  "--others",
@@ -921,6 +882,12 @@ var INSTRUCTION_PATHS = Object.freeze([
921
882
  "/.claude/CLAUDE.md",
922
883
  "/CLAUDE.local.md"
923
884
  ].map((path) => parseRepositoryPath(path)));
885
+ var GIT_TRACKED_ENTRY_MODES = [
886
+ "100644",
887
+ "100755",
888
+ "120000",
889
+ "160000"
890
+ ];
924
891
  //#endregion
925
892
  //#region src/git-inventory/content-transformation/constants.ts
926
893
  var GIT_CONTENT_TRANSFORMATION_ATTRIBUTES = [
@@ -1057,15 +1024,14 @@ var createClassificationFailure = (errorCode) => Object.freeze({
1057
1024
  kind: "failed"
1058
1025
  });
1059
1026
  /** Maps one bounded Git attribute failure to the existing safe inventory contract. */
1060
- var mapGitProcessFailure$3 = (reason) => {
1027
+ var mapGitFailure$3 = (reason) => {
1061
1028
  switch (reason) {
1062
1029
  case "aborted": return "GIT_OPERATION_ABORTED";
1063
1030
  case "not-found": return "GIT_NOT_FOUND";
1064
1031
  case "access-denied": return "GIT_ACCESS_DENIED";
1065
1032
  case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
1066
- case "output-limit-exceeded":
1067
- case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1068
- case "stderr-limit-exceeded": return "GIT_OUTPUT_INVALID";
1033
+ case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1034
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
1069
1035
  case "command-failed": return "GIT_COMMAND_FAILED";
1070
1036
  }
1071
1037
  };
@@ -1099,11 +1065,11 @@ var createClassification = (filter, ident, workingTreeEncoding) => Object.freeze
1099
1065
  workingTreeEncoding
1100
1066
  });
1101
1067
  /**
1102
- * Creates the effective Git content-transformation classifier around a process boundary.
1103
- * @param processExecutor The sanitized streamed Git process executor.
1068
+ * Creates the effective Git content-transformation classifier around a Git command boundary.
1069
+ * @param runGit The bounded Git command boundary.
1104
1070
  * @returns An all-or-nothing bounded classifier for effective inventory entries.
1105
1071
  */
1106
- var createGitContentTransformationClassifier = (processExecutor = executeGitStreamingProcess) => {
1072
+ var createGitContentTransformationClassifier = (runGit = runGitCommand) => {
1107
1073
  return async (input) => {
1108
1074
  if (input.signal?.aborted) return createClassificationFailure("GIT_OPERATION_ABORTED");
1109
1075
  if (!Number.isSafeInteger(input.maxMetadataBytes) || input.maxMetadataBytes < 0) return createClassificationFailure("RESOURCE_LIMIT_EXCEEDED");
@@ -1115,25 +1081,16 @@ var createGitContentTransformationClassifier = (processExecutor = executeGitStre
1115
1081
  const paths = input.entries.map((entry) => entry.path);
1116
1082
  const stdin = encodePaths(paths);
1117
1083
  if (stdin === null) return createClassificationFailure("GIT_OUTPUT_INVALID");
1118
- const parser = createGitContentTransformationParser({ paths });
1119
- let consumedStdoutBytes = 0;
1120
- const processResult = await processExecutor({
1121
- arguments: [
1122
- "-C",
1123
- input.repositoryRoot,
1124
- ...GIT_CONTENT_TRANSFORMATION_ARGUMENTS
1125
- ],
1126
- consumeStdout: (chunk) => {
1127
- consumedStdoutBytes += chunk.byteLength;
1128
- parser.consume(chunk);
1129
- },
1130
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
1131
- maxStdoutBytes: input.maxMetadataBytes,
1132
- ...input.signal === void 0 ? {} : { signal: input.signal },
1133
- stdin
1084
+ const result = await runGit(GIT_CONTENT_TRANSFORMATION_ARGUMENTS, {
1085
+ cwd: input.repositoryRoot,
1086
+ input: stdin,
1087
+ maxOutputBytes: Math.max(input.maxMetadataBytes, 1),
1088
+ ...input.signal === void 0 ? {} : { signal: input.signal }
1134
1089
  });
1135
- if (processResult.kind === "failed") return createClassificationFailure(mapGitProcessFailure$3(processResult.reason));
1136
- if (processResult.stderr.byteLength > 0 || processResult.stdoutBytes !== consumedStdoutBytes || processResult.stdoutBytes > input.maxMetadataBytes) return createClassificationFailure("GIT_OUTPUT_INVALID");
1090
+ if (result.kind === "failed") return createClassificationFailure(mapGitFailure$3(result.reason));
1091
+ if (result.value.byteLength > input.maxMetadataBytes) return createClassificationFailure("RESOURCE_LIMIT_EXCEEDED");
1092
+ const parser = createGitContentTransformationParser({ paths });
1093
+ parser.consume(result.value);
1137
1094
  const parserResult = parser.finish();
1138
1095
  if (parserResult.kind === "failed" || parserResult.attributes.length !== input.entries.length) return createClassificationFailure("GIT_OUTPUT_INVALID");
1139
1096
  const entries = input.entries.map((entry, index) => {
@@ -1147,7 +1104,7 @@ var createGitContentTransformationClassifier = (processExecutor = executeGitStre
1147
1104
  if (entries.some((entry) => entry === null)) return createClassificationFailure("GIT_OUTPUT_INVALID");
1148
1105
  return Object.freeze({
1149
1106
  entries: Object.freeze(entries.filter((entry) => entry !== null)),
1150
- gitMetadataBytes: processResult.stdoutBytes,
1107
+ gitMetadataBytes: result.value.byteLength,
1151
1108
  kind: "classified"
1152
1109
  });
1153
1110
  };
@@ -1252,15 +1209,6 @@ var createGitInventoryEntryInspector = (inspectEntry = inspectHostEntry) => {
1252
1209
  };
1253
1210
  var inspectGitInventoryEntry = createGitInventoryEntryInspector();
1254
1211
  //#endregion
1255
- //#region src/git-inventory/entry-type/constants.ts
1256
- var GIT_SYMLINK_CONFIGURATION_ARGUMENTS = [
1257
- "config",
1258
- "--type=bool",
1259
- "--default=true",
1260
- "--get",
1261
- "core.symlinks"
1262
- ];
1263
- //#endregion
1264
1212
  //#region src/git-inventory/entry-type/symlink-configuration.ts
1265
1213
  /** Creates one immutable effective symlink configuration failure. */
1266
1214
  var createConfigurationFailure = (errorCode) => Object.freeze({
@@ -1268,60 +1216,37 @@ var createConfigurationFailure = (errorCode) => Object.freeze({
1268
1216
  kind: "failed"
1269
1217
  });
1270
1218
  /** Maps one bounded Git configuration failure to the existing safe CLI contract. */
1271
- var mapGitProcessFailure$2 = (reason) => {
1219
+ var mapGitFailure$2 = (reason) => {
1272
1220
  switch (reason) {
1273
1221
  case "aborted": return "GIT_OPERATION_ABORTED";
1274
1222
  case "not-found": return "GIT_NOT_FOUND";
1275
1223
  case "access-denied": return "GIT_ACCESS_DENIED";
1276
- case "output-limit-exceeded":
1277
- case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1224
+ case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1278
1225
  case "repository-not-found":
1279
- case "stderr-limit-exceeded": return "GIT_OUTPUT_INVALID";
1226
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
1280
1227
  case "command-failed": return "GIT_COMMAND_FAILED";
1281
1228
  }
1282
1229
  };
1283
- /** Concatenates already bounded Git stdout chunks for strict boolean parsing. */
1284
- var concatenateChunks$1 = (chunks, byteLength) => {
1285
- const output = new Uint8Array(byteLength);
1286
- let offset = 0;
1287
- for (const chunk of chunks) {
1288
- output.set(chunk, offset);
1289
- offset += chunk.byteLength;
1290
- }
1291
- return output;
1292
- };
1293
1230
  /**
1294
- * Creates the bounded effective core.symlinks resolver around a Git process boundary.
1295
- * @param processExecutor The sanitized streamed Git process executor.
1231
+ * Creates the bounded effective core.symlinks resolver around a typed Git config read.
1232
+ * @param readBoolean The typed Git boolean config read.
1296
1233
  * @returns A resolver for the selected repository's effective symlink behavior.
1297
1234
  */
1298
- var createGitSymlinkConfigurationResolver = (processExecutor = executeGitStreamingProcess) => {
1235
+ var createGitSymlinkConfigurationResolver = (readBoolean = readConfigBoolean) => {
1299
1236
  return async (input) => {
1300
1237
  if (input.signal?.aborted) return createConfigurationFailure("GIT_OPERATION_ABORTED");
1301
1238
  if (!Number.isSafeInteger(input.maxMetadataBytes) || input.maxMetadataBytes < 0) return createConfigurationFailure("RESOURCE_LIMIT_EXCEEDED");
1302
- const stdoutChunks = [];
1303
- let consumedStdoutBytes = 0;
1304
- const processResult = await processExecutor({
1305
- arguments: [
1306
- "-C",
1307
- input.repositoryRoot,
1308
- ...GIT_SYMLINK_CONFIGURATION_ARGUMENTS
1309
- ],
1310
- consumeStdout: (chunk) => {
1311
- stdoutChunks.push(Uint8Array.from(chunk));
1312
- consumedStdoutBytes += chunk.byteLength;
1313
- },
1314
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
1315
- maxStdoutBytes: input.maxMetadataBytes,
1239
+ const result = await readGit(() => readBoolean(input.repositoryRoot, "core.symlinks", true, {
1240
+ maxOutputBytes: Math.max(input.maxMetadataBytes, 1),
1241
+ timeoutSeconds: 300,
1316
1242
  ...input.signal === void 0 ? {} : { signal: input.signal }
1317
- });
1318
- if (processResult.kind === "failed") return createConfigurationFailure(mapGitProcessFailure$2(processResult.reason));
1319
- if (processResult.stderr.byteLength > 0 || processResult.stdoutBytes !== consumedStdoutBytes || processResult.stdoutBytes > input.maxMetadataBytes) return createConfigurationFailure("GIT_OUTPUT_INVALID");
1320
- const isEnabled = parseGitBooleanOutput(concatenateChunks$1(stdoutChunks, consumedStdoutBytes));
1321
- if (isEnabled === null) return createConfigurationFailure("GIT_OUTPUT_INVALID");
1243
+ }), input.signal);
1244
+ if (result.kind === "failed") return createConfigurationFailure(mapGitFailure$2(result.reason));
1245
+ const gitMetadataBytes = result.value ? 5 : 6;
1246
+ if (gitMetadataBytes > input.maxMetadataBytes) return createConfigurationFailure("RESOURCE_LIMIT_EXCEEDED");
1322
1247
  return Object.freeze({
1323
- gitMetadataBytes: processResult.stdoutBytes,
1324
- isEnabled,
1248
+ gitMetadataBytes,
1249
+ isEnabled: result.value,
1325
1250
  kind: "resolved"
1326
1251
  });
1327
1252
  };
@@ -1476,7 +1401,6 @@ var normalizeGitInventoryLogicalPaths = (input) => {
1476
1401
  };
1477
1402
  //#endregion
1478
1403
  //#region src/git-inventory/parser.ts
1479
- var TRACKED_ENTRY_HEADER_PATTERN = /^(100644|100755|120000|160000) (?:[0-9a-f]{40}|[0-9a-f]{64}) ([0-3])$/u;
1480
1404
  /** Decodes one complete Git path as strict UTF-8 while preserving an initial BOM scalar. */
1481
1405
  var decodeGitPath = (pathBytes) => {
1482
1406
  if (pathBytes.byteLength === 0) return null;
@@ -1489,20 +1413,6 @@ var decodeGitPath = (pathBytes) => {
1489
1413
  return null;
1490
1414
  }
1491
1415
  };
1492
- /** Confirms that one decoded path contains only complete Unicode scalar values. */
1493
- var hasOnlyUnicodeScalarValues = (path) => {
1494
- for (let index = 0; index < path.length; index += 1) {
1495
- const codeUnit = path.charCodeAt(index);
1496
- if (codeUnit >= 55296 && codeUnit <= 56319) {
1497
- const trailingCodeUnit = path.charCodeAt(index + 1);
1498
- if (trailingCodeUnit < 56320 || trailingCodeUnit > 57343) return false;
1499
- index += 1;
1500
- continue;
1501
- }
1502
- if (codeUnit >= 56320 && codeUnit <= 57343) return false;
1503
- }
1504
- return true;
1505
- };
1506
1416
  /** Concatenates one complete record assembled across arbitrary process chunks. */
1507
1417
  var concatenateRecord = (fragments, byteLength) => {
1508
1418
  const record = new Uint8Array(byteLength);
@@ -1513,30 +1423,10 @@ var concatenateRecord = (fragments, byteLength) => {
1513
1423
  }
1514
1424
  return record;
1515
1425
  };
1516
- /** Parses one tracked `ls-files --stage` record without normalizing its path. */
1517
- var parseTrackedCandidate = (record) => {
1518
- const separatorIndex = record.indexOf(9);
1519
- if (separatorIndex <= 0 || separatorIndex === record.byteLength - 1) return null;
1520
- let header;
1521
- try {
1522
- header = new TextDecoder("utf-8", { fatal: true }).decode(record.subarray(0, separatorIndex));
1523
- } catch {
1524
- return null;
1525
- }
1526
- const headerMatch = TRACKED_ENTRY_HEADER_PATTERN.exec(header);
1527
- const path = decodeGitPath(record.subarray(separatorIndex + 1));
1528
- if (headerMatch === null || path === null || !hasOnlyUnicodeScalarValues(path)) return null;
1529
- return Object.freeze({
1530
- kind: "tracked",
1531
- mode: headerMatch[1],
1532
- path,
1533
- stage: Number(headerMatch[2])
1534
- });
1535
- };
1536
1426
  /** Parses one untracked `ls-files --others` record without normalizing its path. */
1537
1427
  var parseUntrackedCandidate = (record) => {
1538
1428
  const path = decodeGitPath(record);
1539
- if (path === null || !hasOnlyUnicodeScalarValues(path)) return null;
1429
+ if (path === null || !path.isWellFormed()) return null;
1540
1430
  return Object.freeze({
1541
1431
  kind: "untracked",
1542
1432
  path
@@ -1597,14 +1487,12 @@ var createGitInventoryParser = (maxEntries, parseCandidate) => {
1597
1487
  }
1598
1488
  };
1599
1489
  };
1600
- /** Creates a strict incremental parser for tracked Git inventory output. */
1601
- var createTrackedGitInventoryParser = (maxEntries) => createGitInventoryParser(maxEntries, parseTrackedCandidate);
1602
1490
  /** Creates a strict incremental parser for untracked Git inventory output. */
1603
1491
  var createUntrackedGitInventoryParser = (maxEntries) => createGitInventoryParser(maxEntries, parseUntrackedCandidate);
1604
1492
  //#endregion
1605
1493
  //#region src/git-inventory/repository-ownership/boundary-inspector.ts
1606
1494
  var GIT_CONTROL_SEGMENT = ".git";
1607
- var GIT_REPOSITORY_ROOT_ARGUMENTS = ["rev-parse", "--show-toplevel"];
1495
+ var TOP_LEVEL_OUTPUT_OVERHEAD_BYTES = 6;
1608
1496
  /** Identifies one safe inspection failure in a filesystem result union. */
1609
1497
  var isInspectionFailure = (result) => "kind" in result;
1610
1498
  /** Creates one immutable ownership-inspection failure. */
@@ -1619,16 +1507,15 @@ var mapFilesystemFailure = (error) => {
1619
1507
  if (errorCode === "ENOENT" || errorCode === "ENOTDIR" || errorCode === "ELOOP") return "GIT_OUTPUT_INVALID";
1620
1508
  return "GIT_COMMAND_FAILED";
1621
1509
  };
1622
- /** Maps a streamed nested-root check failure into the existing safe CLI contract. */
1623
- var mapGitProcessFailure$1 = (reason) => {
1510
+ /** Maps a nested-root check failure into the existing safe CLI contract. */
1511
+ var mapGitFailure$1 = (reason) => {
1624
1512
  switch (reason) {
1625
1513
  case "aborted": return "GIT_OPERATION_ABORTED";
1626
1514
  case "not-found": return "GIT_NOT_FOUND";
1627
1515
  case "access-denied": return "GIT_ACCESS_DENIED";
1628
- case "output-limit-exceeded":
1629
- case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1516
+ case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1630
1517
  case "repository-not-found":
1631
- case "stderr-limit-exceeded": return "GIT_OUTPUT_INVALID";
1518
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
1632
1519
  case "command-failed": return "GIT_COMMAND_FAILED";
1633
1520
  }
1634
1521
  };
@@ -1659,56 +1546,37 @@ var inspectPath = async (hostPath, inspectHostPath) => {
1659
1546
  var hasExactDirectoryName = (encodedNameKeys, segment) => encodedNameKeys.has(Buffer$1.from(segment, "utf8").toString("hex"));
1660
1547
  /** Confirms that one directory observation retained its no-follow identity. */
1661
1548
  var hasStableDirectoryIdentity = (initialStatistics, revalidatedStatistics) => initialStatistics.isDirectory() && !initialStatistics.isSymbolicLink() && revalidatedStatistics.isDirectory() && !revalidatedStatistics.isSymbolicLink() && initialStatistics.dev === revalidatedStatistics.dev && initialStatistics.ino === revalidatedStatistics.ino;
1662
- /** Concatenates already bounded Git stdout chunks for strict root parsing. */
1663
- var concatenateChunks = (chunks, byteLength) => {
1664
- const output = new Uint8Array(byteLength);
1665
- let offset = 0;
1666
- for (const chunk of chunks) {
1667
- output.set(chunk, offset);
1668
- offset += chunk.byteLength;
1669
- }
1670
- return output;
1671
- };
1672
1549
  /**
1673
1550
  * Confirms whether a directory with an exact `.git` marker owns another working tree.
1674
1551
  * @param directory The exact no-follow directory being classified.
1675
1552
  * @param repositoryRoot The selected repository root.
1676
1553
  * @param directoryStatistics The stable no-follow boundary observation.
1677
- * @param maxMetadataBytes The remaining bounded Git stdout budget.
1678
- * @param processExecutor The sanitized streamed Git boundary.
1554
+ * @param maxMetadataBytes The remaining bounded Git output budget.
1555
+ * @param readRoot The typed Git working-tree root read.
1679
1556
  * @param inspectHostPath The no-follow filesystem stat operation.
1680
1557
  * @returns A safe ownership classification and the consumed Git metadata bytes.
1681
1558
  */
1682
- var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics, maxMetadataBytes, processExecutor, inspectHostPath, signal) => {
1559
+ var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics, maxMetadataBytes, readRoot, inspectHostPath, signal) => {
1683
1560
  if (signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
1684
1561
  if (!Number.isSafeInteger(maxMetadataBytes) || maxMetadataBytes < 0) return createInspectionFailure("RESOURCE_LIMIT_EXCEEDED");
1685
- const stdoutChunks = [];
1686
- let consumedStdoutBytes = 0;
1687
- const processResult = await processExecutor({
1688
- arguments: [
1689
- "-C",
1690
- directory,
1691
- ...GIT_REPOSITORY_ROOT_ARGUMENTS
1692
- ],
1693
- consumeStdout: (chunk) => {
1694
- stdoutChunks.push(Uint8Array.from(chunk));
1695
- consumedStdoutBytes += chunk.byteLength;
1696
- },
1697
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
1698
- maxStdoutBytes: maxMetadataBytes,
1562
+ const rootResult = await readGit(() => readRoot(directory, {
1563
+ maxOutputBytes: Math.max(maxMetadataBytes, 1),
1564
+ timeoutSeconds: 300,
1699
1565
  ...signal === void 0 ? {} : { signal }
1700
- });
1701
- if (processResult.kind === "failed") return createInspectionFailure(mapGitProcessFailure$1(processResult.reason));
1702
- if (processResult.stderr.byteLength > 0 || processResult.stdoutBytes !== consumedStdoutBytes) return createInspectionFailure("GIT_OUTPUT_INVALID");
1703
- const discoveredRoot = parseGitAbsolutePathOutput(concatenateChunks(stdoutChunks, consumedStdoutBytes));
1704
- if (discoveredRoot === null) return createInspectionFailure("GIT_OUTPUT_INVALID");
1566
+ }), signal);
1567
+ if (rootResult.kind === "failed") return createInspectionFailure(mapGitFailure$1(rootResult.reason));
1568
+ if (rootResult.value === null) return createInspectionFailure("GIT_COMMAND_FAILED");
1569
+ const discoveredRoot = rootResult.value;
1570
+ const gitMetadataBytes = TOP_LEVEL_OUTPUT_OVERHEAD_BYTES + countUtf8Bytes(discoveredRoot);
1571
+ if (gitMetadataBytes > maxMetadataBytes) return createInspectionFailure("RESOURCE_LIMIT_EXCEEDED");
1572
+ if (!path.isAbsolute(discoveredRoot)) return createInspectionFailure("GIT_OUTPUT_INVALID");
1705
1573
  if (areHostPathsEquivalent(discoveredRoot, directory)) return Object.freeze({
1706
- gitMetadataBytes: processResult.stdoutBytes,
1574
+ gitMetadataBytes,
1707
1575
  kind: "validated",
1708
1576
  ownership: "nested-repository"
1709
1577
  });
1710
1578
  if (areHostPathsEquivalent(discoveredRoot, repositoryRoot)) return Object.freeze({
1711
- gitMetadataBytes: processResult.stdoutBytes,
1579
+ gitMetadataBytes,
1712
1580
  kind: "validated",
1713
1581
  ownership: "selected-repository"
1714
1582
  });
@@ -1717,7 +1585,7 @@ var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics,
1717
1585
  if (discoveredRootInspection.kind === "failed") return discoveredRootInspection;
1718
1586
  if (!discoveredRootInspection.statistics.isDirectory() || discoveredRootInspection.statistics.isSymbolicLink()) return createInspectionFailure("GIT_OUTPUT_INVALID");
1719
1587
  if (haveSameHostPathIdentity(discoveredRootInspection.statistics, directoryStatistics)) return Object.freeze({
1720
- gitMetadataBytes: processResult.stdoutBytes,
1588
+ gitMetadataBytes,
1721
1589
  kind: "validated",
1722
1590
  ownership: "nested-repository"
1723
1591
  });
@@ -1725,7 +1593,7 @@ var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics,
1725
1593
  if (signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
1726
1594
  if (repositoryRootInspection.kind === "failed") return repositoryRootInspection;
1727
1595
  if (repositoryRootInspection.statistics.isDirectory() && !repositoryRootInspection.statistics.isSymbolicLink() && haveSameHostPathIdentity(discoveredRootInspection.statistics, repositoryRootInspection.statistics)) return Object.freeze({
1728
- gitMetadataBytes: processResult.stdoutBytes,
1596
+ gitMetadataBytes,
1729
1597
  kind: "validated",
1730
1598
  ownership: "selected-repository"
1731
1599
  });
@@ -1737,12 +1605,12 @@ var inspectOwnershipPath = async (hostPath) => lstat(hostPath, { bigint: true })
1737
1605
  var readOwnershipDirectory = async (hostPath) => readdir(hostPath, { encoding: "buffer" });
1738
1606
  /**
1739
1607
  * Creates nested-repository inspection around injectable filesystem and Git boundaries.
1740
- * @param processExecutor The sanitized bounded Git process executor.
1608
+ * @param readRoot The typed Git working-tree root read.
1741
1609
  * @param inspectHostPath The no-follow filesystem stat operation.
1742
1610
  * @param readDirectory The raw native-name directory operation.
1743
1611
  * @returns An all-or-nothing ownership inspector for untracked candidate paths.
1744
1612
  */
1745
- var createGitInventoryBoundaryInspector = (processExecutor = executeGitStreamingProcess, inspectHostPath = inspectOwnershipPath, readDirectory = readOwnershipDirectory) => {
1613
+ var createGitInventoryBoundaryInspector = (readRoot = readTopLevel, inspectHostPath = inspectOwnershipPath, readDirectory = readOwnershipDirectory) => {
1746
1614
  return async (input) => {
1747
1615
  if (input.signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
1748
1616
  const directoryObservations = /* @__PURE__ */ new Map();
@@ -1800,7 +1668,7 @@ var createGitInventoryBoundaryInspector = (processExecutor = executeGitStreaming
1800
1668
  if (input.signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
1801
1669
  if (gitControlInspection.kind === "failed") return gitControlInspection;
1802
1670
  if (gitControlInspection.statistics.isSymbolicLink() || !gitControlInspection.statistics.isDirectory() && !gitControlInspection.statistics.isFile()) return createInspectionFailure("GIT_OUTPUT_INVALID");
1803
- const boundaryValidation = await validateGitBoundary(hostPath, input.repositoryRoot, revalidatedInspection.statistics, input.maxMetadataBytes - gitMetadataBytes, processExecutor, inspectHostPath, input.signal);
1671
+ const boundaryValidation = await validateGitBoundary(hostPath, input.repositoryRoot, revalidatedInspection.statistics, input.maxMetadataBytes - gitMetadataBytes, readRoot, inspectHostPath, input.signal);
1804
1672
  if (boundaryValidation.kind === "failed") return boundaryValidation;
1805
1673
  gitMetadataBytes += boundaryValidation.gitMetadataBytes;
1806
1674
  directoryOwnership = boundaryValidation.ownership;
@@ -1962,19 +1830,43 @@ var createGitInventoryOwnershipFilter = (boundaryInspector = inspectGitInventory
1962
1830
  };
1963
1831
  //#endregion
1964
1832
  //#region src/git-inventory/probe.ts
1965
- /** Maps one normalized streamed Git failure to a safe inventory error. */
1966
- var mapGitProcessFailure = (reason) => {
1833
+ var GIT_INVENTORY_LISTING_READS = Object.freeze({
1834
+ listUntrackedFiles,
1835
+ readIndexEntries,
1836
+ runGit: runGitCommand
1837
+ });
1838
+ /** Maps one normalized Git failure to a safe inventory error. */
1839
+ var mapGitFailure = (reason) => {
1967
1840
  switch (reason) {
1968
1841
  case "aborted": return "GIT_OPERATION_ABORTED";
1969
1842
  case "not-found": return "GIT_NOT_FOUND";
1970
1843
  case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
1971
1844
  case "access-denied": return "GIT_ACCESS_DENIED";
1972
- case "stderr-limit-exceeded": return "GIT_OUTPUT_INVALID";
1973
- case "output-limit-exceeded":
1974
- case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1845
+ case "output-invalid": return "GIT_OUTPUT_INVALID";
1846
+ case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
1975
1847
  case "command-failed": return "GIT_COMMAND_FAILED";
1976
1848
  }
1977
1849
  };
1850
+ /** Determines whether one index mode belongs to the version 1 inventory grammar. */
1851
+ var isTrackedEntryMode = (mode) => GIT_TRACKED_ENTRY_MODES.includes(mode);
1852
+ /** Converts index entries into tracked candidates, or null when one has an unsupported mode. */
1853
+ var toTrackedCandidates = (entries) => {
1854
+ const candidates = [];
1855
+ for (const { mode, path, stage } of entries) {
1856
+ if (!isTrackedEntryMode(mode)) return null;
1857
+ candidates.push(Object.freeze({
1858
+ kind: "tracked",
1859
+ mode,
1860
+ path,
1861
+ stage
1862
+ }));
1863
+ }
1864
+ return Object.freeze(candidates);
1865
+ };
1866
+ /** Measures the stdout `ls-files --stage -z` wrote for the index entries. */
1867
+ var measureTrackedOutput = (entries) => entries.reduce((bytes, { path }) => bytes + 75 + countUtf8Bytes(path), 0);
1868
+ /** Measures the stdout `ls-files --others -z` wrote for the untracked paths. */
1869
+ var measureUntrackedOutput = (paths) => paths.reduce((bytes, path) => bytes + countUtf8Bytes(path) + 1, 0);
1978
1870
  /** Creates one immutable inventory-probe failure. */
1979
1871
  var createProbeFailure = (errorCode) => Object.freeze({
1980
1872
  errorCode,
@@ -1989,99 +1881,78 @@ var resolveParserResult = (parserResult) => {
1989
1881
  var isProbeFailure = (result) => !Array.isArray(result);
1990
1882
  /**
1991
1883
  * Creates the strict normalized Git inventory probe around injectable boundaries.
1992
- * @param processExecutor The bounded incremental Git process executor.
1884
+ * @param git The typed Git reads and command that list raw candidates.
1993
1885
  * @param ownershipFilter The submodule and nested-repository ownership filter.
1994
1886
  * @param entryTypeNormalizer The current filesystem and Git mode entry-type normalizer.
1995
1887
  * @param contentTransformationClassifier The bounded effective Git attribute classifier.
1996
1888
  * @param logicalPathNormalizer The portable repository logical-path normalizer.
1997
1889
  * @returns An all-or-nothing selected-repository entry probe.
1998
1890
  */
1999
- var createGitInventoryProbe = (processExecutor = executeGitStreamingProcess, ownershipFilter = createGitInventoryOwnershipFilter(createGitInventoryBoundaryInspector(processExecutor)), entryTypeNormalizer = createGitInventoryEntryTypeNormalizer(inspectGitInventoryEntry, createGitSymlinkConfigurationResolver(processExecutor)), contentTransformationClassifier = createGitContentTransformationClassifier(processExecutor), logicalPathNormalizer = normalizeGitInventoryLogicalPaths) => async (input) => {
1891
+ var createGitInventoryProbe = (git = GIT_INVENTORY_LISTING_READS, ownershipFilter = createGitInventoryOwnershipFilter(createGitInventoryBoundaryInspector()), entryTypeNormalizer = createGitInventoryEntryTypeNormalizer(inspectGitInventoryEntry, createGitSymlinkConfigurationResolver()), contentTransformationClassifier = createGitContentTransformationClassifier(), logicalPathNormalizer = normalizeGitInventoryLogicalPaths) => async (input) => {
2000
1892
  if (input.signal?.aborted) return createProbeFailure("GIT_OPERATION_ABORTED");
2001
- const selectionPathspecs = (input.selectionPaths ?? []).map((selectionPath) => `:(top,literal)${selectionPath.slice(1)}`);
2002
- const trackedParser = createTrackedGitInventoryParser(input.maxEntries);
2003
- const trackedProcessResult = await processExecutor({
2004
- arguments: [
2005
- "-C",
2006
- input.repositoryRoot,
2007
- ...GIT_TRACKED_INVENTORY_ARGUMENTS,
2008
- ...selectionPathspecs
2009
- ],
2010
- consumeStdout: (chunk) => trackedParser.consume(chunk),
2011
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
2012
- maxStdoutBytes: input.maxMetadataBytes,
2013
- ...input.signal === void 0 ? {} : { signal: input.signal }
2014
- });
2015
- if (trackedProcessResult.kind === "failed") return createProbeFailure(mapGitProcessFailure(trackedProcessResult.reason));
2016
- if (trackedProcessResult.stderr.byteLength > 0) return createProbeFailure("GIT_OUTPUT_INVALID");
2017
- const trackedCandidates = resolveParserResult(trackedParser.finish());
2018
- if (isProbeFailure(trackedCandidates)) return trackedCandidates;
2019
- const untrackedParser = createUntrackedGitInventoryParser(input.maxEntries - trackedCandidates.length);
2020
- const untrackedProcessResult = await processExecutor({
2021
- arguments: [
2022
- "-C",
2023
- input.repositoryRoot,
2024
- ...GIT_UNTRACKED_INVENTORY_ARGUMENTS,
2025
- ...selectionPathspecs
2026
- ],
2027
- consumeStdout: (chunk) => untrackedParser.consume(chunk),
2028
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
2029
- maxStdoutBytes: input.maxMetadataBytes - trackedProcessResult.stdoutBytes,
1893
+ const selectionPaths = (input.selectionPaths ?? []).map((selectionPath) => selectionPath.slice(1));
1894
+ let remainingMetadataBytes = input.maxMetadataBytes;
1895
+ const createReadOptions = () => ({
1896
+ maxOutputBytes: Math.max(remainingMetadataBytes, 1),
1897
+ timeoutSeconds: 300,
1898
+ ...selectionPaths.length === 0 ? {} : { paths: selectionPaths },
2030
1899
  ...input.signal === void 0 ? {} : { signal: input.signal }
2031
1900
  });
2032
- if (untrackedProcessResult.kind === "failed") return createProbeFailure(mapGitProcessFailure(untrackedProcessResult.reason));
2033
- if (untrackedProcessResult.stderr.byteLength > 0) return createProbeFailure("GIT_OUTPUT_INVALID");
2034
- const untrackedCandidates = resolveParserResult(untrackedParser.finish());
2035
- if (isProbeFailure(untrackedCandidates)) return untrackedCandidates;
1901
+ const trackedResult = await readGit(() => git.readIndexEntries(input.repositoryRoot, createReadOptions()), input.signal);
1902
+ if (trackedResult.kind === "failed") return createProbeFailure(mapGitFailure(trackedResult.reason));
1903
+ remainingMetadataBytes -= measureTrackedOutput(trackedResult.value);
1904
+ if (trackedResult.value.length > input.maxEntries || remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
1905
+ const trackedCandidates = toTrackedCandidates(trackedResult.value);
1906
+ if (trackedCandidates === null) return createProbeFailure("GIT_OUTPUT_INVALID");
1907
+ const untrackedResult = await readGit(() => git.listUntrackedFiles(input.repositoryRoot, createReadOptions()), input.signal);
1908
+ if (untrackedResult.kind === "failed") return createProbeFailure(mapGitFailure(untrackedResult.reason));
1909
+ remainingMetadataBytes -= measureUntrackedOutput(untrackedResult.value);
1910
+ if (trackedCandidates.length + untrackedResult.value.length > input.maxEntries || remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
1911
+ if (untrackedResult.value.some((path) => path.length === 0)) return createProbeFailure("GIT_OUTPUT_INVALID");
1912
+ const untrackedCandidates = Object.freeze(untrackedResult.value.map((path) => Object.freeze({
1913
+ kind: "untracked",
1914
+ path
1915
+ })));
2036
1916
  let ignoredCandidates = [];
2037
- let ignoredStdoutBytes = 0;
2038
- if (input.includeIgnored === true && selectionPathspecs.length > 0) {
2039
- const ignoredParser = createUntrackedGitInventoryParser(input.maxEntries - trackedCandidates.length - untrackedCandidates.length);
2040
- const ignoredProcessResult = await processExecutor({
2041
- arguments: [
2042
- "-C",
2043
- input.repositoryRoot,
2044
- ...GIT_IGNORED_INVENTORY_ARGUMENTS,
2045
- ...selectionPathspecs
2046
- ],
2047
- consumeStdout: (chunk) => ignoredParser.consume(chunk),
2048
- maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
2049
- maxStdoutBytes: input.maxMetadataBytes - trackedProcessResult.stdoutBytes - untrackedProcessResult.stdoutBytes,
1917
+ if (input.includeIgnored === true && selectionPaths.length > 0) {
1918
+ const ignoredResult = await git.runGit([...GIT_IGNORED_INVENTORY_ARGUMENTS, ...selectionPaths], {
1919
+ cwd: input.repositoryRoot,
1920
+ maxOutputBytes: Math.max(remainingMetadataBytes, 1),
2050
1921
  ...input.signal === void 0 ? {} : { signal: input.signal }
2051
1922
  });
2052
- if (ignoredProcessResult.kind === "failed") return createProbeFailure(mapGitProcessFailure(ignoredProcessResult.reason));
2053
- if (ignoredProcessResult.stderr.byteLength > 0) return createProbeFailure("GIT_OUTPUT_INVALID");
1923
+ if (ignoredResult.kind === "failed") return createProbeFailure(mapGitFailure(ignoredResult.reason));
1924
+ remainingMetadataBytes -= ignoredResult.value.byteLength;
1925
+ if (remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
1926
+ const ignoredParser = createUntrackedGitInventoryParser(input.maxEntries - trackedCandidates.length - untrackedCandidates.length);
1927
+ ignoredParser.consume(ignoredResult.value);
2054
1928
  const parsedIgnoredCandidates = resolveParserResult(ignoredParser.finish());
2055
1929
  if (isProbeFailure(parsedIgnoredCandidates)) return parsedIgnoredCandidates;
2056
1930
  const untrackedPaths = new Set(untrackedCandidates.map((candidate) => candidate.path));
2057
1931
  ignoredCandidates = parsedIgnoredCandidates.filter((candidate) => !untrackedPaths.has(candidate.path));
2058
- ignoredStdoutBytes = ignoredProcessResult.stdoutBytes;
2059
1932
  }
2060
- const candidates = Object.freeze([
1933
+ const logicalPathFilterResult = filterGitInventoryCandidateLogicalPaths({ candidates: Object.freeze([
2061
1934
  ...trackedCandidates,
2062
1935
  ...untrackedCandidates,
2063
1936
  ...ignoredCandidates
2064
- ]);
2065
- const metadataBytesAfterListing = input.maxMetadataBytes - trackedProcessResult.stdoutBytes - untrackedProcessResult.stdoutBytes - ignoredStdoutBytes;
2066
- const logicalPathFilterResult = filterGitInventoryCandidateLogicalPaths({ candidates });
1937
+ ]) });
2067
1938
  if (logicalPathFilterResult.kind === "failed") return logicalPathFilterResult;
2068
1939
  const ownershipResult = await ownershipFilter({
2069
1940
  candidates: logicalPathFilterResult.candidates,
2070
- maxMetadataBytes: metadataBytesAfterListing,
1941
+ maxMetadataBytes: remainingMetadataBytes,
2071
1942
  repositoryRoot: input.repositoryRoot,
2072
1943
  ...input.signal === void 0 ? {} : { signal: input.signal }
2073
1944
  });
2074
1945
  if (ownershipResult.kind === "failed") return ownershipResult;
2075
1946
  const entryTypeResult = await entryTypeNormalizer({
2076
1947
  candidates: ownershipResult.candidates,
2077
- maxMetadataBytes: metadataBytesAfterListing - ownershipResult.gitMetadataBytes,
1948
+ maxMetadataBytes: remainingMetadataBytes - ownershipResult.gitMetadataBytes,
2078
1949
  repositoryRoot: input.repositoryRoot,
2079
1950
  ...input.signal === void 0 ? {} : { signal: input.signal }
2080
1951
  });
2081
1952
  if (entryTypeResult.kind === "failed") return entryTypeResult;
2082
1953
  const contentTransformationResult = await contentTransformationClassifier({
2083
1954
  entries: entryTypeResult.entries,
2084
- maxMetadataBytes: metadataBytesAfterListing - ownershipResult.gitMetadataBytes - entryTypeResult.gitMetadataBytes,
1955
+ maxMetadataBytes: remainingMetadataBytes - ownershipResult.gitMetadataBytes - entryTypeResult.gitMetadataBytes,
2085
1956
  repositoryRoot: input.repositoryRoot,
2086
1957
  ...input.signal === void 0 ? {} : { signal: input.signal }
2087
1958
  });
@@ -2118,6 +1989,10 @@ var areGitInventoriesEqual = (left, right) => left.length === right.length && le
2118
1989
  });
2119
1990
  //#endregion
2120
1991
  //#region src/repository-symlink-overlay/reader.ts
1992
+ var decoder = new TextDecoder("utf-8", {
1993
+ fatal: true,
1994
+ ignoreBOM: true
1995
+ });
2121
1996
  /** Throws the common cancellation contract for wrapper-owned operations. */
2122
1997
  var throwIfAborted = (signal, operation, path) => {
2123
1998
  if (!signal?.aborted) return;
@@ -2212,6 +2087,47 @@ var GitSymlinkOverlayRepositoryReader = class {
2212
2087
  });
2213
2088
  }
2214
2089
  /**
2090
+ * Reads a link's stored text. A Git link checked out as a plain file holds exactly the text Git
2091
+ * stored, so its bounded bytes are that text; other paths read the underlying reader.
2092
+ * @param path The validated repository path of the symlink entry.
2093
+ * @param options Optional cancellation controls.
2094
+ * @returns A promise resolving to the text, or `null` past 4096 UTF-8 bytes or for invalid UTF-8.
2095
+ * @throws
2096
+ * - INVALID_REPOSITORY_PATH: The repository path is invalid.
2097
+ * - ENTRY_NOT_FOUND: The requested repository entry was not found.
2098
+ * - ENTRY_NOT_LINK: The requested repository entry is not a symlink.
2099
+ * - ACCESS_DENIED: Access to the repository source was denied.
2100
+ * - SOURCE_UNAVAILABLE: The repository source is unavailable.
2101
+ * - SNAPSHOT_CHANGED: The repository snapshot changed during the operation.
2102
+ * - INVALID_SOURCE_DATA: The repository source returned invalid data.
2103
+ * - RESOURCE_LIMIT_EXCEEDED: A repository reading resource limit was exceeded.
2104
+ * - ABORTED: The repository operation was aborted.
2105
+ */
2106
+ async readLinkText(path, options) {
2107
+ const parsedPath = parseRepositoryPath(path);
2108
+ if (!this.#overlayPaths.has(parsedPath)) return this.#reader.readLinkText(parsedPath, options);
2109
+ throwIfAborted(options?.signal, "read-link-text", parsedPath);
2110
+ const entry = await this.#reader.getEntry(parsedPath, options);
2111
+ validateOverlayEntry(entry, "read-link-text", parsedPath);
2112
+ throwIfAborted(options?.signal, "read-link-text", parsedPath);
2113
+ const byteLength = entry?.byteLength ?? null;
2114
+ if (byteLength === null) throw createInvalidOverlayException("read-link-text", parsedPath);
2115
+ if (byteLength > REPOSITORY_LINK_TEXT_MAX_BYTES) return null;
2116
+ if (byteLength === 0) return "";
2117
+ const page = await this.#reader.readFilePage(parsedPath, {
2118
+ maxBytes: byteLength,
2119
+ offset: 0,
2120
+ ...options?.signal === void 0 ? {} : { signal: options.signal }
2121
+ });
2122
+ throwIfAborted(options?.signal, "read-link-text", parsedPath);
2123
+ if (!page.isComplete || page.totalBytes !== byteLength || page.bytes.byteLength !== byteLength) throw createInvalidOverlayException("read-link-text", parsedPath);
2124
+ try {
2125
+ return decoder.decode(page.bytes);
2126
+ } catch {
2127
+ return null;
2128
+ }
2129
+ }
2130
+ /**
2215
2131
  * Recursively lists descendants while replacing configured host files with logical symlinks.
2216
2132
  * @param options Optional prefix and cancellation controls.
2217
2133
  * @returns An async iterable of detached logical entries.
@@ -2274,34 +2190,6 @@ var createGitSymlinkOverlayRepositoryReader = (reader, symlinkPaths) => {
2274
2190
  return Object.freeze(new GitSymlinkOverlayRepositoryReader(reader, overlayPaths));
2275
2191
  };
2276
2192
  //#endregion
2277
- //#region src/repository-symlink-overlay/link-resolver.ts
2278
- /**
2279
- * Wraps a link resolver so Git symlinks materialized as host files resolve as unsafe. Their host
2280
- * bytes are link text Git wrote, not a link the filesystem can follow, so they are never read.
2281
- * @param resolver The resolver bound to the underlying filesystem reader.
2282
- * @param symlinkPaths The logical paths whose host files represent Git symlinks.
2283
- * @returns A frozen resolver that shares the underlying resolver's snapshot.
2284
- * @throws
2285
- * - INVALID_REPOSITORY_PATH: The repository path is invalid.
2286
- */
2287
- var createGitSymlinkOverlayLinkResolver = (resolver, symlinkPaths) => {
2288
- const overlayPaths = new Set(symlinkPaths.map((symlinkPath) => parseRepositoryPath(symlinkPath)));
2289
- return Object.freeze({
2290
- snapshot: resolver.snapshot,
2291
- resolveLink: async (path, options) => overlayPaths.has(parseRepositoryPath(path)) ? { state: "unsafe" } : resolver.resolveLink(path, options),
2292
- readLinkTargetPage: async (path, options) => {
2293
- const parsedPath = parseRepositoryPath(path);
2294
- if (overlayPaths.has(parsedPath)) throw new RepositorySourceException({
2295
- code: "ENTRY_NOT_FILE",
2296
- operation: "read-file-page",
2297
- path: parsedPath,
2298
- retryable: false
2299
- });
2300
- return resolver.readLinkTargetPage(parsedPath, options);
2301
- }
2302
- });
2303
- };
2304
- //#endregion
2305
2193
  //#region src/repository-reader/factory.ts
2306
2194
  /** Composes the filesystem, Git symlink overlay, and content-transformation guard layers. */
2307
2195
  var composeWorkingTreeReader = async (input, filesystemReaderFactory, symlinkOverlayFactory, contentTransformationGuardFactory) => {
@@ -2314,7 +2202,7 @@ var composeWorkingTreeReader = async (input, filesystemReaderFactory, symlinkOve
2314
2202
  if (entry.contentTransformation.isGuarded) paths.push(entry.path);
2315
2203
  return paths;
2316
2204
  }, []));
2317
- const filesystemReader = await filesystemReaderFactory({
2205
+ return contentTransformationGuardFactory(symlinkOverlayFactory(await filesystemReaderFactory({
2318
2206
  limits: Object.freeze({
2319
2207
  maxCachedBytes: input.resourceLimits.maxTotalBytes,
2320
2208
  maxDirectoryEntries: input.resourceLimits.maxEntries,
@@ -2328,12 +2216,7 @@ var composeWorkingTreeReader = async (input, filesystemReaderFactory, symlinkOve
2328
2216
  paths: selectedPaths
2329
2217
  }),
2330
2218
  ...input.signal === void 0 ? {} : { signal: input.signal }
2331
- });
2332
- return {
2333
- filesystemReader,
2334
- reader: contentTransformationGuardFactory(symlinkOverlayFactory(filesystemReader, symlinkOverlayPaths), guardedPaths),
2335
- symlinkOverlayPaths
2336
- };
2219
+ }), symlinkOverlayPaths), guardedPaths);
2337
2220
  };
2338
2221
  /**
2339
2222
  * Creates the private working-tree reader factory around injectable composition boundaries.
@@ -2342,24 +2225,17 @@ var composeWorkingTreeReader = async (input, filesystemReaderFactory, symlinkOve
2342
2225
  * @param contentTransformationGuardFactory The guarded logical regular-file reader factory.
2343
2226
  * @returns A factory that composes one coherent selected working-tree reader.
2344
2227
  */
2345
- var createWorkingTreeRepositoryReaderFactory = (filesystemReaderFactory = createFilesystemRepositoryReader, symlinkOverlayFactory = createGitSymlinkOverlayRepositoryReader, contentTransformationGuardFactory = createGitContentTransformationGuardRepositoryReader) => async (input) => (await composeWorkingTreeReader(input, filesystemReaderFactory, symlinkOverlayFactory, contentTransformationGuardFactory)).reader;
2228
+ var createWorkingTreeRepositoryReaderFactory = (filesystemReaderFactory = createFilesystemRepositoryReader, symlinkOverlayFactory = createGitSymlinkOverlayRepositoryReader, contentTransformationGuardFactory = createGitContentTransformationGuardRepositoryReader) => (input) => composeWorkingTreeReader(input, filesystemReaderFactory, symlinkOverlayFactory, contentTransformationGuardFactory);
2346
2229
  var createWorkingTreeRepositoryReader = createWorkingTreeRepositoryReaderFactory();
2347
2230
  /**
2348
2231
  * Creates the instruction-source factory: an exact-path reader for the probed instruction
2349
- * entries, with the same layers as the repository reader, and Repository FS's link resolver bound
2350
- * to its filesystem reader so that Git-materialized links resolve as unsafe.
2232
+ * entries, with the same layers as the repository reader.
2351
2233
  * @param filesystemReaderFactory The exact-path filesystem snapshot factory.
2352
2234
  * @param symlinkOverlayFactory The logical Git symlink overlay factory.
2353
2235
  * @param contentTransformationGuardFactory The guarded logical regular-file reader factory.
2354
- * @returns A factory that composes one coherent instruction source.
2236
+ * @returns A factory that composes one coherent instruction reader.
2355
2237
  */
2356
- var createWorkingTreeInstructionSourceFactory = (filesystemReaderFactory = createFilesystemRepositoryReader, symlinkOverlayFactory = createGitSymlinkOverlayRepositoryReader, contentTransformationGuardFactory = createGitContentTransformationGuardRepositoryReader) => async (input) => {
2357
- const composed = await composeWorkingTreeReader(input, filesystemReaderFactory, symlinkOverlayFactory, contentTransformationGuardFactory);
2358
- return Object.freeze({
2359
- linkResolver: createGitSymlinkOverlayLinkResolver(createFilesystemRepositoryLinkResolver(composed.filesystemReader), composed.symlinkOverlayPaths),
2360
- reader: composed.reader
2361
- });
2362
- };
2238
+ var createWorkingTreeInstructionSourceFactory = (filesystemReaderFactory = createFilesystemRepositoryReader, symlinkOverlayFactory = createGitSymlinkOverlayRepositoryReader, contentTransformationGuardFactory = createGitContentTransformationGuardRepositoryReader) => (input) => composeWorkingTreeReader(input, filesystemReaderFactory, symlinkOverlayFactory, contentTransformationGuardFactory);
2363
2239
  var createWorkingTreeInstructionSource = createWorkingTreeInstructionSourceFactory();
2364
2240
  //#endregion
2365
2241
  //#region src/working-tree-snapshot/executor.ts
@@ -2650,11 +2526,11 @@ var createMoldeaCliContentExecutionResult = (pageResult, cliVersion, isJson, cur
2650
2526
  //#region src/cli-execution/command-executor.ts
2651
2527
  /** Loads isolated Core inspection only for commands that need it. */
2652
2528
  var executeLazyCoreInspection = async (input) => {
2653
- const { executeMoldeaCliCoreInspection } = await import("./chunks/core-composition-BH3Wj5Lq.js");
2529
+ const { executeMoldeaCliCoreInspection } = await import("./chunks/core-composition-ZEZSTBMA.js");
2654
2530
  return executeMoldeaCliCoreInspection(input);
2655
2531
  };
2656
2532
  var loadInstalledComposition = async (input) => {
2657
- const { resolveInstalledMoldeaCliComposition } = await import("./chunks/composition-bB23wZlW.js");
2533
+ const { resolveInstalledMoldeaCliComposition } = await import("./chunks/composition-C2m6SpCI.js");
2658
2534
  return resolveInstalledMoldeaCliComposition(input);
2659
2535
  };
2660
2536
  /** Creates one operational error result without exposing caught failure details. */
@@ -2884,92 +2760,31 @@ var loadMoldeaCliPackageMetadata = async (packageManifestPath, packageEntryResol
2884
2760
  });
2885
2761
  };
2886
2762
  //#endregion
2887
- //#region src/process-signal/session.ts
2888
- var SIGNAL_EXIT_CODES = Object.freeze({
2889
- SIGINT: MOLDEA_CLI_EXIT_CODES.Interrupted,
2890
- SIGTERM: MOLDEA_CLI_EXIT_CODES.Terminated
2891
- });
2892
- var PROCESS_SIGNAL_SOURCE = Object.freeze({
2893
- addListener: (signal, listener) => {
2894
- process.on(signal, listener);
2895
- },
2896
- removeListener: (signal, listener) => {
2897
- process.off(signal, listener);
2898
- },
2899
- closeIpc: () => {
2900
- if (process.connected) process.disconnect();
2901
- },
2902
- hasDisconnectedLauncher: () => typeof process.send === "function" && !process.connected
2903
- });
2904
- /**
2905
- * Creates one process-signal session around an operation-scoped abort controller.
2906
- * @param signalSource The process-listener boundary.
2907
- * @returns A session that records the first signal until output completes.
2908
- */
2909
- var createMoldeaCliProcessSignalSession = (signalSource = PROCESS_SIGNAL_SOURCE) => {
2910
- const controller = new AbortController();
2911
- let exitCode = null;
2912
- let isDisposed = false;
2913
- let isOutputComplete = false;
2914
- const handleSignal = (signal) => {
2915
- if (exitCode !== null || isDisposed || isOutputComplete) return;
2916
- exitCode = SIGNAL_EXIT_CODES[signal];
2917
- controller.abort();
2918
- };
2919
- const handleSigint = () => handleSignal("SIGINT");
2920
- const handleSigterm = () => handleSignal("SIGTERM");
2921
- const handleDisconnect = () => handleSignal("SIGTERM");
2922
- signalSource.addListener("SIGINT", handleSigint);
2923
- signalSource.addListener("SIGTERM", handleSigterm);
2924
- signalSource.addListener("disconnect", handleDisconnect);
2925
- if (signalSource.hasDisconnectedLauncher()) handleDisconnect();
2926
- return Object.freeze({
2927
- completeOutput: () => {
2928
- isOutputComplete = true;
2929
- },
2930
- dispose: () => {
2931
- if (isDisposed) return;
2932
- isDisposed = true;
2933
- signalSource.removeListener("SIGINT", handleSigint);
2934
- signalSource.removeListener("SIGTERM", handleSigterm);
2935
- signalSource.removeListener("disconnect", handleDisconnect);
2936
- signalSource.closeIpc();
2937
- },
2938
- get exitCode() {
2939
- return exitCode;
2940
- },
2941
- get hasReceivedSignal() {
2942
- return exitCode !== null;
2943
- },
2944
- signal: controller.signal
2945
- });
2946
- };
2947
- //#endregion
2948
2763
  //#region src/bin/index.ts
2949
2764
  var executableDirectory = path.dirname(fileURLToPath(import.meta.url));
2950
2765
  var packageManifestPath = path.resolve(executableDirectory, "..", "package.json");
2951
- var signalSession = createMoldeaCliProcessSignalSession();
2952
- /** Reads process stdin incrementally without retaining bytes above the requested limit. */
2766
+ var shutdown = createShutdownSignal({
2767
+ disconnect: true,
2768
+ setExitCode: false
2769
+ });
2770
+ /** Reads process stdin without retaining bytes above the requested limit. */
2953
2771
  var readProcessStdin = async (maxBytes, signal) => {
2954
- const chunks = [];
2955
- let totalBytes = 0;
2956
- for await (const chunk of process.stdin) {
2957
- if (signal?.aborted) return {
2772
+ try {
2773
+ return {
2774
+ bytes: await readStdin({
2775
+ maxBytes,
2776
+ signal
2777
+ }),
2778
+ kind: "completed"
2779
+ };
2780
+ } catch (error) {
2781
+ if (hasErrorCode(error, ERRORS.STDIN_TOO_LARGE)) return { kind: "limit-exceeded" };
2782
+ if (signal?.aborted === true) return {
2958
2783
  bytes: /* @__PURE__ */ new Uint8Array(),
2959
2784
  kind: "completed"
2960
2785
  };
2961
- const bytes = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : new Uint8Array(chunk);
2962
- totalBytes += bytes.byteLength;
2963
- if (totalBytes > maxBytes) {
2964
- process.stdin.pause();
2965
- return { kind: "limit-exceeded" };
2966
- }
2967
- chunks.push(bytes);
2786
+ throw error;
2968
2787
  }
2969
- return {
2970
- bytes: Buffer.concat(chunks, totalBytes),
2971
- kind: "completed"
2972
- };
2973
2788
  };
2974
2789
  /**
2975
2790
  * Writes one complete process output string.
@@ -2997,24 +2812,20 @@ try {
2997
2812
  invocationDirectory,
2998
2813
  packageMetadata,
2999
2814
  readStdin: readProcessStdin,
3000
- signal: signalSession.signal
2815
+ signal: shutdown.signal
3001
2816
  });
3002
- if (signalSession.hasReceivedSignal) process.exitCode = signalSession.exitCode;
3003
- else {
2817
+ if (shutdown.receivedSignal() === null) {
3004
2818
  await writeProcessOutput(process.stdout, executionResult.stdout);
3005
- if (!signalSession.hasReceivedSignal) await writeProcessOutput(process.stderr, executionResult.stderr);
3006
- if (!signalSession.hasReceivedSignal) signalSession.completeOutput();
3007
- process.exitCode = signalSession.exitCode ?? executionResult.exitCode;
2819
+ if (shutdown.receivedSignal() === null) await writeProcessOutput(process.stderr, executionResult.stderr);
3008
2820
  }
2821
+ process.exitCode = shutdown.exitCode() ?? executionResult.exitCode;
3009
2822
  } catch {
3010
- if (signalSession.hasReceivedSignal) process.exitCode = signalSession.exitCode;
3011
- else {
3012
- await writeProcessOutput(process.stderr, formatMoldeaCliHumanError(createMoldeaCliOwnedError("INTERNAL_ERROR"))).catch(() => void 0);
3013
- signalSession.completeOutput();
3014
- process.exitCode = 3;
3015
- }
2823
+ const signalExitCode = shutdown.exitCode();
2824
+ if (signalExitCode === null) await writeProcessOutput(process.stderr, formatMoldeaCliHumanError(createMoldeaCliOwnedError("INTERNAL_ERROR"))).catch(() => void 0);
2825
+ process.exitCode = signalExitCode ?? 3;
3016
2826
  } finally {
3017
- signalSession.dispose();
2827
+ shutdown.dispose();
2828
+ if (process.connected) process.disconnect();
3018
2829
  }
3019
2830
  //#endregion
3020
2831