@moldea.ai/cli 12.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/chunks/{composition-DX66KnuP.js → composition-C9TNzN2e.js} +132 -455
- package/dist/chunks/composition-C9TNzN2e.js.map +1 -0
- package/dist/chunks/{composition-8VLm2c-X.js → composition-PoYBx0Mw.js} +1 -1
- package/dist/chunks/{core-composition-Bbpu62TT.js → core-composition-DeWcE7Bf.js} +2 -2
- package/dist/chunks/{core-composition-Bbpu62TT.js.map → core-composition-DeWcE7Bf.js.map} +1 -1
- package/dist/moldea.js +287 -433
- package/dist/moldea.js.map +1 -1
- package/package.json +9 -4
- package/dist/chunks/composition-DX66KnuP.js.map +0 -1
package/dist/moldea.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { A as
|
|
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-C9TNzN2e.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { hasErrorCode } from "jg-exception";
|
|
7
|
+
import { ERRORS, createShutdownSignal, readStdin } from "jg-process";
|
|
8
|
+
import { countUtf8Bytes } from "jg-utilities";
|
|
6
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
14
|
import { createFilesystemRepositoryReader } from "@moldea.ai/repository-fs";
|
|
@@ -67,21 +71,10 @@ var decodeGitOutput = (output) => {
|
|
|
67
71
|
} catch {
|
|
68
72
|
return null;
|
|
69
73
|
}
|
|
70
|
-
if (decodedOutput.includes("\0") || !
|
|
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") || !
|
|
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
|
-
|
|
155
|
-
|
|
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":
|
|
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
|
|
172
|
-
* @param
|
|
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 = (
|
|
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
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
startingDirectoryResult.directory,
|
|
184
|
-
"rev-parse",
|
|
185
|
-
"--is-inside-work-tree"
|
|
186
|
-
],
|
|
187
|
-
maxBufferBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
|
|
188
|
-
...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,
|
|
178
|
+
const gitOptions = {
|
|
179
|
+
maxOutputBytes: MAX_GIT_DISCOVERY_OUTPUT_BYTES,
|
|
180
|
+
timeoutSeconds: 300,
|
|
203
181
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (rootResult.
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
217
|
-
|
|
218
|
-
|
|
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
|
|
285
|
-
var
|
|
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":
|
|
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 (
|
|
312
|
-
const result = await
|
|
313
|
-
|
|
314
|
-
|
|
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(
|
|
322
|
-
|
|
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
|
|
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 = (
|
|
307
|
+
var createGitWorkingTreeIdentityInspector = (runGit = runGitCommand, inspectPath = inspectDirectoryIdentity) => {
|
|
348
308
|
return async (input) => {
|
|
349
|
-
if (!path.isAbsolute(input.repositoryRoot) || input.repositoryRoot.includes("\0") || !
|
|
350
|
-
const discoveredRoot = await queryGitPath(
|
|
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(
|
|
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(
|
|
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");
|
|
@@ -906,25 +866,6 @@ var mapMoldeaCliOperationalError = (error) => {
|
|
|
906
866
|
};
|
|
907
867
|
//#endregion
|
|
908
868
|
//#region src/git-inventory/constants.ts
|
|
909
|
-
var GIT_TRACKED_INVENTORY_ARGUMENTS = [
|
|
910
|
-
"ls-files",
|
|
911
|
-
"--cached",
|
|
912
|
-
"--stage",
|
|
913
|
-
"--full-name",
|
|
914
|
-
"--no-abbrev",
|
|
915
|
-
"--no-recurse-submodules",
|
|
916
|
-
"-z",
|
|
917
|
-
"--"
|
|
918
|
-
];
|
|
919
|
-
var GIT_UNTRACKED_INVENTORY_ARGUMENTS = [
|
|
920
|
-
"ls-files",
|
|
921
|
-
"--others",
|
|
922
|
-
"--exclude-standard",
|
|
923
|
-
"--full-name",
|
|
924
|
-
"--no-recurse-submodules",
|
|
925
|
-
"-z",
|
|
926
|
-
"--"
|
|
927
|
-
];
|
|
928
869
|
var GIT_IGNORED_INVENTORY_ARGUMENTS = [
|
|
929
870
|
"ls-files",
|
|
930
871
|
"--others",
|
|
@@ -935,12 +876,19 @@ var GIT_IGNORED_INVENTORY_ARGUMENTS = [
|
|
|
935
876
|
"-z",
|
|
936
877
|
"--"
|
|
937
878
|
];
|
|
879
|
+
var GIT_INVENTORY_LISTING_SUBCOMMAND = "ls-files";
|
|
938
880
|
var INSTRUCTION_PATHS = Object.freeze([
|
|
939
881
|
"/AGENTS.md",
|
|
940
882
|
"/CLAUDE.md",
|
|
941
883
|
"/.claude/CLAUDE.md",
|
|
942
884
|
"/CLAUDE.local.md"
|
|
943
885
|
].map((path) => parseRepositoryPath(path)));
|
|
886
|
+
var GIT_TRACKED_ENTRY_MODES = [
|
|
887
|
+
"100644",
|
|
888
|
+
"100755",
|
|
889
|
+
"120000",
|
|
890
|
+
"160000"
|
|
891
|
+
];
|
|
944
892
|
//#endregion
|
|
945
893
|
//#region src/git-inventory/content-transformation/constants.ts
|
|
946
894
|
var GIT_CONTENT_TRANSFORMATION_ATTRIBUTES = [
|
|
@@ -1072,20 +1020,20 @@ var createGitContentTransformationParser = (input) => {
|
|
|
1072
1020
|
//#endregion
|
|
1073
1021
|
//#region src/git-inventory/content-transformation/classifier.ts
|
|
1074
1022
|
/** Creates one immutable content-transformation classification failure. */
|
|
1075
|
-
var createClassificationFailure = (errorCode) => Object.freeze({
|
|
1023
|
+
var createClassificationFailure = (errorCode, subcommand) => Object.freeze({
|
|
1076
1024
|
errorCode,
|
|
1077
|
-
kind: "failed"
|
|
1025
|
+
kind: "failed",
|
|
1026
|
+
...subcommand === void 0 ? {} : { subcommand }
|
|
1078
1027
|
});
|
|
1079
1028
|
/** Maps one bounded Git attribute failure to the existing safe inventory contract. */
|
|
1080
|
-
var
|
|
1029
|
+
var mapGitFailure$3 = (reason) => {
|
|
1081
1030
|
switch (reason) {
|
|
1082
1031
|
case "aborted": return "GIT_OPERATION_ABORTED";
|
|
1083
1032
|
case "not-found": return "GIT_NOT_FOUND";
|
|
1084
1033
|
case "access-denied": return "GIT_ACCESS_DENIED";
|
|
1085
1034
|
case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
|
|
1086
|
-
case "output-limit-exceeded":
|
|
1087
|
-
case "
|
|
1088
|
-
case "stderr-limit-exceeded": return "GIT_OUTPUT_INVALID";
|
|
1035
|
+
case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1036
|
+
case "output-invalid": return "GIT_OUTPUT_INVALID";
|
|
1089
1037
|
case "command-failed": return "GIT_COMMAND_FAILED";
|
|
1090
1038
|
}
|
|
1091
1039
|
};
|
|
@@ -1119,11 +1067,11 @@ var createClassification = (filter, ident, workingTreeEncoding) => Object.freeze
|
|
|
1119
1067
|
workingTreeEncoding
|
|
1120
1068
|
});
|
|
1121
1069
|
/**
|
|
1122
|
-
* Creates the effective Git content-transformation classifier around a
|
|
1123
|
-
* @param
|
|
1070
|
+
* Creates the effective Git content-transformation classifier around a Git command boundary.
|
|
1071
|
+
* @param runGit The bounded Git command boundary.
|
|
1124
1072
|
* @returns An all-or-nothing bounded classifier for effective inventory entries.
|
|
1125
1073
|
*/
|
|
1126
|
-
var createGitContentTransformationClassifier = (
|
|
1074
|
+
var createGitContentTransformationClassifier = (runGit = runGitCommand) => {
|
|
1127
1075
|
return async (input) => {
|
|
1128
1076
|
if (input.signal?.aborted) return createClassificationFailure("GIT_OPERATION_ABORTED");
|
|
1129
1077
|
if (!Number.isSafeInteger(input.maxMetadataBytes) || input.maxMetadataBytes < 0) return createClassificationFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
@@ -1135,25 +1083,16 @@ var createGitContentTransformationClassifier = (processExecutor = executeGitStre
|
|
|
1135
1083
|
const paths = input.entries.map((entry) => entry.path);
|
|
1136
1084
|
const stdin = encodePaths(paths);
|
|
1137
1085
|
if (stdin === null) return createClassificationFailure("GIT_OUTPUT_INVALID");
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
input.repositoryRoot,
|
|
1144
|
-
...GIT_CONTENT_TRANSFORMATION_ARGUMENTS
|
|
1145
|
-
],
|
|
1146
|
-
consumeStdout: (chunk) => {
|
|
1147
|
-
consumedStdoutBytes += chunk.byteLength;
|
|
1148
|
-
parser.consume(chunk);
|
|
1149
|
-
},
|
|
1150
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
1151
|
-
maxStdoutBytes: input.maxMetadataBytes,
|
|
1152
|
-
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
1153
|
-
stdin
|
|
1086
|
+
const result = await runGit(GIT_CONTENT_TRANSFORMATION_ARGUMENTS, {
|
|
1087
|
+
cwd: input.repositoryRoot,
|
|
1088
|
+
input: stdin,
|
|
1089
|
+
maxOutputBytes: Math.max(input.maxMetadataBytes, 1),
|
|
1090
|
+
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1154
1091
|
});
|
|
1155
|
-
if (
|
|
1156
|
-
if (
|
|
1092
|
+
if (result.kind === "failed") return createClassificationFailure(mapGitFailure$3(result.reason), result.subcommand);
|
|
1093
|
+
if (result.value.byteLength > input.maxMetadataBytes) return createClassificationFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1094
|
+
const parser = createGitContentTransformationParser({ paths });
|
|
1095
|
+
parser.consume(result.value);
|
|
1157
1096
|
const parserResult = parser.finish();
|
|
1158
1097
|
if (parserResult.kind === "failed" || parserResult.attributes.length !== input.entries.length) return createClassificationFailure("GIT_OUTPUT_INVALID");
|
|
1159
1098
|
const entries = input.entries.map((entry, index) => {
|
|
@@ -1167,7 +1106,7 @@ var createGitContentTransformationClassifier = (processExecutor = executeGitStre
|
|
|
1167
1106
|
if (entries.some((entry) => entry === null)) return createClassificationFailure("GIT_OUTPUT_INVALID");
|
|
1168
1107
|
return Object.freeze({
|
|
1169
1108
|
entries: Object.freeze(entries.filter((entry) => entry !== null)),
|
|
1170
|
-
gitMetadataBytes:
|
|
1109
|
+
gitMetadataBytes: result.value.byteLength,
|
|
1171
1110
|
kind: "classified"
|
|
1172
1111
|
});
|
|
1173
1112
|
};
|
|
@@ -1272,76 +1211,46 @@ var createGitInventoryEntryInspector = (inspectEntry = inspectHostEntry) => {
|
|
|
1272
1211
|
};
|
|
1273
1212
|
var inspectGitInventoryEntry = createGitInventoryEntryInspector();
|
|
1274
1213
|
//#endregion
|
|
1275
|
-
//#region src/git-inventory/entry-type/constants.ts
|
|
1276
|
-
var GIT_SYMLINK_CONFIGURATION_ARGUMENTS = [
|
|
1277
|
-
"config",
|
|
1278
|
-
"--type=bool",
|
|
1279
|
-
"--default=true",
|
|
1280
|
-
"--get",
|
|
1281
|
-
"core.symlinks"
|
|
1282
|
-
];
|
|
1283
|
-
//#endregion
|
|
1284
1214
|
//#region src/git-inventory/entry-type/symlink-configuration.ts
|
|
1215
|
+
var GIT_CONFIG_SUBCOMMAND = "config";
|
|
1285
1216
|
/** Creates one immutable effective symlink configuration failure. */
|
|
1286
|
-
var createConfigurationFailure = (errorCode) => Object.freeze({
|
|
1217
|
+
var createConfigurationFailure = (errorCode, subcommand) => Object.freeze({
|
|
1287
1218
|
errorCode,
|
|
1288
|
-
kind: "failed"
|
|
1219
|
+
kind: "failed",
|
|
1220
|
+
...subcommand === void 0 ? {} : { subcommand }
|
|
1289
1221
|
});
|
|
1290
1222
|
/** Maps one bounded Git configuration failure to the existing safe CLI contract. */
|
|
1291
|
-
var
|
|
1223
|
+
var mapGitFailure$2 = (reason) => {
|
|
1292
1224
|
switch (reason) {
|
|
1293
1225
|
case "aborted": return "GIT_OPERATION_ABORTED";
|
|
1294
1226
|
case "not-found": return "GIT_NOT_FOUND";
|
|
1295
1227
|
case "access-denied": return "GIT_ACCESS_DENIED";
|
|
1296
|
-
case "output-limit-exceeded":
|
|
1297
|
-
case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1228
|
+
case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1298
1229
|
case "repository-not-found":
|
|
1299
|
-
case "
|
|
1230
|
+
case "output-invalid": return "GIT_OUTPUT_INVALID";
|
|
1300
1231
|
case "command-failed": return "GIT_COMMAND_FAILED";
|
|
1301
1232
|
}
|
|
1302
1233
|
};
|
|
1303
|
-
/** Concatenates already bounded Git stdout chunks for strict boolean parsing. */
|
|
1304
|
-
var concatenateChunks$1 = (chunks, byteLength) => {
|
|
1305
|
-
const output = new Uint8Array(byteLength);
|
|
1306
|
-
let offset = 0;
|
|
1307
|
-
for (const chunk of chunks) {
|
|
1308
|
-
output.set(chunk, offset);
|
|
1309
|
-
offset += chunk.byteLength;
|
|
1310
|
-
}
|
|
1311
|
-
return output;
|
|
1312
|
-
};
|
|
1313
1234
|
/**
|
|
1314
|
-
* Creates the bounded effective core.symlinks resolver around a Git
|
|
1315
|
-
* @param
|
|
1235
|
+
* Creates the bounded effective core.symlinks resolver around a typed Git config read.
|
|
1236
|
+
* @param readBoolean The typed Git boolean config read.
|
|
1316
1237
|
* @returns A resolver for the selected repository's effective symlink behavior.
|
|
1317
1238
|
*/
|
|
1318
|
-
var createGitSymlinkConfigurationResolver = (
|
|
1239
|
+
var createGitSymlinkConfigurationResolver = (readBoolean = readConfigBoolean) => {
|
|
1319
1240
|
return async (input) => {
|
|
1320
1241
|
if (input.signal?.aborted) return createConfigurationFailure("GIT_OPERATION_ABORTED");
|
|
1321
1242
|
if (!Number.isSafeInteger(input.maxMetadataBytes) || input.maxMetadataBytes < 0) return createConfigurationFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
arguments: [
|
|
1326
|
-
"-C",
|
|
1327
|
-
input.repositoryRoot,
|
|
1328
|
-
...GIT_SYMLINK_CONFIGURATION_ARGUMENTS
|
|
1329
|
-
],
|
|
1330
|
-
consumeStdout: (chunk) => {
|
|
1331
|
-
stdoutChunks.push(Uint8Array.from(chunk));
|
|
1332
|
-
consumedStdoutBytes += chunk.byteLength;
|
|
1333
|
-
},
|
|
1334
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
1335
|
-
maxStdoutBytes: input.maxMetadataBytes,
|
|
1243
|
+
const result = await readGit(() => readBoolean(input.repositoryRoot, "core.symlinks", true, {
|
|
1244
|
+
maxOutputBytes: Math.max(input.maxMetadataBytes, 1),
|
|
1245
|
+
timeoutSeconds: 300,
|
|
1336
1246
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1337
|
-
});
|
|
1338
|
-
if (
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
if (isEnabled === null) return createConfigurationFailure("GIT_OUTPUT_INVALID");
|
|
1247
|
+
}), input.signal, GIT_CONFIG_SUBCOMMAND);
|
|
1248
|
+
if (result.kind === "failed") return createConfigurationFailure(mapGitFailure$2(result.reason), result.subcommand);
|
|
1249
|
+
const gitMetadataBytes = result.value ? 5 : 6;
|
|
1250
|
+
if (gitMetadataBytes > input.maxMetadataBytes) return createConfigurationFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1342
1251
|
return Object.freeze({
|
|
1343
|
-
gitMetadataBytes
|
|
1344
|
-
isEnabled,
|
|
1252
|
+
gitMetadataBytes,
|
|
1253
|
+
isEnabled: result.value,
|
|
1345
1254
|
kind: "resolved"
|
|
1346
1255
|
});
|
|
1347
1256
|
};
|
|
@@ -1423,6 +1332,61 @@ var createGitInventoryEntryTypeNormalizer = (entryInspector = inspectGitInventor
|
|
|
1423
1332
|
};
|
|
1424
1333
|
};
|
|
1425
1334
|
//#endregion
|
|
1335
|
+
//#region src/git-inventory/link-ancestors/shadower.ts
|
|
1336
|
+
/** Creates one immutable cancellation failure. */
|
|
1337
|
+
var createAbortedFailure = () => Object.freeze({
|
|
1338
|
+
errorCode: "GIT_OPERATION_ABORTED",
|
|
1339
|
+
kind: "failed"
|
|
1340
|
+
});
|
|
1341
|
+
/**
|
|
1342
|
+
* Lists the proper ancestor directories of one Git-relative path, shallowest first. An untracked
|
|
1343
|
+
* directory-boundary record keeps Git's trailing separator, which names the path itself.
|
|
1344
|
+
* @param candidatePath The Git-relative candidate path.
|
|
1345
|
+
* @returns Every directory above the candidate, such as `a` and `a/b` for `a/b/c`.
|
|
1346
|
+
*/
|
|
1347
|
+
var listProperAncestors = (candidatePath) => {
|
|
1348
|
+
const segments = candidatePath.replace(/\/$/u, "").split("/");
|
|
1349
|
+
return segments.slice(0, -1).map((_segment, index) => segments.slice(0, index + 1).join("/"));
|
|
1350
|
+
};
|
|
1351
|
+
/** Determines whether a path sits beneath any recorded link. */
|
|
1352
|
+
var isBeneathLink = (candidatePath, links) => listProperAncestors(candidatePath).some((ancestor) => links.has(ancestor));
|
|
1353
|
+
/**
|
|
1354
|
+
* Creates link-ancestor shadowing around an injectable no-follow entry inspector. Git can list
|
|
1355
|
+
* entries beneath a path the working tree holds as a symlink or junction, such as the files a
|
|
1356
|
+
* Windows junction exposes, while every later read treats that path as a link.
|
|
1357
|
+
* @param inspectEntry The no-follow inspector for one Git-relative path.
|
|
1358
|
+
* @returns A shadower that replaces every candidate beneath a working-tree link with the link.
|
|
1359
|
+
*/
|
|
1360
|
+
var createGitLinkAncestorShadower = (inspectEntry = inspectGitInventoryEntry) => {
|
|
1361
|
+
return async (input) => {
|
|
1362
|
+
if (input.signal?.aborted) return createAbortedFailure();
|
|
1363
|
+
const ancestors = [...new Set(input.candidates.flatMap(({ path }) => listProperAncestors(path)))].sort((left, right) => left.split("/").length - right.split("/").length);
|
|
1364
|
+
const links = /* @__PURE__ */ new Set();
|
|
1365
|
+
for (const ancestor of ancestors) {
|
|
1366
|
+
if (isBeneathLink(ancestor, links)) continue;
|
|
1367
|
+
const inspection = await inspectEntry(input.repositoryRoot, ancestor);
|
|
1368
|
+
if (input.signal?.aborted) return createAbortedFailure();
|
|
1369
|
+
if (inspection.kind === "failed") return inspection;
|
|
1370
|
+
if (inspection.kind === "inspected" && inspection.entryType === "symlink") links.add(ancestor);
|
|
1371
|
+
}
|
|
1372
|
+
if (links.size === 0) return Object.freeze({
|
|
1373
|
+
candidates: input.candidates,
|
|
1374
|
+
kind: "shadowed"
|
|
1375
|
+
});
|
|
1376
|
+
const remainingCandidates = input.candidates.filter(({ path }) => !isBeneathLink(path, links));
|
|
1377
|
+
const remainingPaths = new Set(remainingCandidates.map(({ path }) => path));
|
|
1378
|
+
const linkCandidates = [...links].filter((link) => !remainingPaths.has(link)).map((link) => Object.freeze({
|
|
1379
|
+
kind: "untracked",
|
|
1380
|
+
path: link
|
|
1381
|
+
}));
|
|
1382
|
+
return Object.freeze({
|
|
1383
|
+
candidates: Object.freeze([...remainingCandidates, ...linkCandidates]),
|
|
1384
|
+
kind: "shadowed"
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
};
|
|
1388
|
+
var shadowGitLinkAncestors = createGitLinkAncestorShadower();
|
|
1389
|
+
//#endregion
|
|
1426
1390
|
//#region src/git-inventory/logical-path/normalizer.ts
|
|
1427
1391
|
/** Creates one immutable invalid logical-path result. */
|
|
1428
1392
|
var createLogicalPathFailure = () => Object.freeze({
|
|
@@ -1496,7 +1460,6 @@ var normalizeGitInventoryLogicalPaths = (input) => {
|
|
|
1496
1460
|
};
|
|
1497
1461
|
//#endregion
|
|
1498
1462
|
//#region src/git-inventory/parser.ts
|
|
1499
|
-
var TRACKED_ENTRY_HEADER_PATTERN = /^(100644|100755|120000|160000) (?:[0-9a-f]{40}|[0-9a-f]{64}) ([0-3])$/u;
|
|
1500
1463
|
/** Decodes one complete Git path as strict UTF-8 while preserving an initial BOM scalar. */
|
|
1501
1464
|
var decodeGitPath = (pathBytes) => {
|
|
1502
1465
|
if (pathBytes.byteLength === 0) return null;
|
|
@@ -1509,20 +1472,6 @@ var decodeGitPath = (pathBytes) => {
|
|
|
1509
1472
|
return null;
|
|
1510
1473
|
}
|
|
1511
1474
|
};
|
|
1512
|
-
/** Confirms that one decoded path contains only complete Unicode scalar values. */
|
|
1513
|
-
var hasOnlyUnicodeScalarValues = (path) => {
|
|
1514
|
-
for (let index = 0; index < path.length; index += 1) {
|
|
1515
|
-
const codeUnit = path.charCodeAt(index);
|
|
1516
|
-
if (codeUnit >= 55296 && codeUnit <= 56319) {
|
|
1517
|
-
const trailingCodeUnit = path.charCodeAt(index + 1);
|
|
1518
|
-
if (trailingCodeUnit < 56320 || trailingCodeUnit > 57343) return false;
|
|
1519
|
-
index += 1;
|
|
1520
|
-
continue;
|
|
1521
|
-
}
|
|
1522
|
-
if (codeUnit >= 56320 && codeUnit <= 57343) return false;
|
|
1523
|
-
}
|
|
1524
|
-
return true;
|
|
1525
|
-
};
|
|
1526
1475
|
/** Concatenates one complete record assembled across arbitrary process chunks. */
|
|
1527
1476
|
var concatenateRecord = (fragments, byteLength) => {
|
|
1528
1477
|
const record = new Uint8Array(byteLength);
|
|
@@ -1533,30 +1482,10 @@ var concatenateRecord = (fragments, byteLength) => {
|
|
|
1533
1482
|
}
|
|
1534
1483
|
return record;
|
|
1535
1484
|
};
|
|
1536
|
-
/** Parses one tracked `ls-files --stage` record without normalizing its path. */
|
|
1537
|
-
var parseTrackedCandidate = (record) => {
|
|
1538
|
-
const separatorIndex = record.indexOf(9);
|
|
1539
|
-
if (separatorIndex <= 0 || separatorIndex === record.byteLength - 1) return null;
|
|
1540
|
-
let header;
|
|
1541
|
-
try {
|
|
1542
|
-
header = new TextDecoder("utf-8", { fatal: true }).decode(record.subarray(0, separatorIndex));
|
|
1543
|
-
} catch {
|
|
1544
|
-
return null;
|
|
1545
|
-
}
|
|
1546
|
-
const headerMatch = TRACKED_ENTRY_HEADER_PATTERN.exec(header);
|
|
1547
|
-
const path = decodeGitPath(record.subarray(separatorIndex + 1));
|
|
1548
|
-
if (headerMatch === null || path === null || !hasOnlyUnicodeScalarValues(path)) return null;
|
|
1549
|
-
return Object.freeze({
|
|
1550
|
-
kind: "tracked",
|
|
1551
|
-
mode: headerMatch[1],
|
|
1552
|
-
path,
|
|
1553
|
-
stage: Number(headerMatch[2])
|
|
1554
|
-
});
|
|
1555
|
-
};
|
|
1556
1485
|
/** Parses one untracked `ls-files --others` record without normalizing its path. */
|
|
1557
1486
|
var parseUntrackedCandidate = (record) => {
|
|
1558
1487
|
const path = decodeGitPath(record);
|
|
1559
|
-
if (path === null || !
|
|
1488
|
+
if (path === null || !path.isWellFormed()) return null;
|
|
1560
1489
|
return Object.freeze({
|
|
1561
1490
|
kind: "untracked",
|
|
1562
1491
|
path
|
|
@@ -1617,14 +1546,12 @@ var createGitInventoryParser = (maxEntries, parseCandidate) => {
|
|
|
1617
1546
|
}
|
|
1618
1547
|
};
|
|
1619
1548
|
};
|
|
1620
|
-
/** Creates a strict incremental parser for tracked Git inventory output. */
|
|
1621
|
-
var createTrackedGitInventoryParser = (maxEntries) => createGitInventoryParser(maxEntries, parseTrackedCandidate);
|
|
1622
1549
|
/** Creates a strict incremental parser for untracked Git inventory output. */
|
|
1623
1550
|
var createUntrackedGitInventoryParser = (maxEntries) => createGitInventoryParser(maxEntries, parseUntrackedCandidate);
|
|
1624
1551
|
//#endregion
|
|
1625
1552
|
//#region src/git-inventory/repository-ownership/boundary-inspector.ts
|
|
1626
1553
|
var GIT_CONTROL_SEGMENT = ".git";
|
|
1627
|
-
var
|
|
1554
|
+
var TOP_LEVEL_OUTPUT_OVERHEAD_BYTES = 6;
|
|
1628
1555
|
/** Identifies one safe inspection failure in a filesystem result union. */
|
|
1629
1556
|
var isInspectionFailure = (result) => "kind" in result;
|
|
1630
1557
|
/** Creates one immutable ownership-inspection failure. */
|
|
@@ -1639,16 +1566,15 @@ var mapFilesystemFailure = (error) => {
|
|
|
1639
1566
|
if (errorCode === "ENOENT" || errorCode === "ENOTDIR" || errorCode === "ELOOP") return "GIT_OUTPUT_INVALID";
|
|
1640
1567
|
return "GIT_COMMAND_FAILED";
|
|
1641
1568
|
};
|
|
1642
|
-
/** Maps a
|
|
1643
|
-
var
|
|
1569
|
+
/** Maps a nested-root check failure into the existing safe CLI contract. */
|
|
1570
|
+
var mapGitFailure$1 = (reason) => {
|
|
1644
1571
|
switch (reason) {
|
|
1645
1572
|
case "aborted": return "GIT_OPERATION_ABORTED";
|
|
1646
1573
|
case "not-found": return "GIT_NOT_FOUND";
|
|
1647
1574
|
case "access-denied": return "GIT_ACCESS_DENIED";
|
|
1648
|
-
case "output-limit-exceeded":
|
|
1649
|
-
case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1575
|
+
case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1650
1576
|
case "repository-not-found":
|
|
1651
|
-
case "
|
|
1577
|
+
case "output-invalid": return "GIT_OUTPUT_INVALID";
|
|
1652
1578
|
case "command-failed": return "GIT_COMMAND_FAILED";
|
|
1653
1579
|
}
|
|
1654
1580
|
};
|
|
@@ -1679,56 +1605,37 @@ var inspectPath = async (hostPath, inspectHostPath) => {
|
|
|
1679
1605
|
var hasExactDirectoryName = (encodedNameKeys, segment) => encodedNameKeys.has(Buffer$1.from(segment, "utf8").toString("hex"));
|
|
1680
1606
|
/** Confirms that one directory observation retained its no-follow identity. */
|
|
1681
1607
|
var hasStableDirectoryIdentity = (initialStatistics, revalidatedStatistics) => initialStatistics.isDirectory() && !initialStatistics.isSymbolicLink() && revalidatedStatistics.isDirectory() && !revalidatedStatistics.isSymbolicLink() && initialStatistics.dev === revalidatedStatistics.dev && initialStatistics.ino === revalidatedStatistics.ino;
|
|
1682
|
-
/** Concatenates already bounded Git stdout chunks for strict root parsing. */
|
|
1683
|
-
var concatenateChunks = (chunks, byteLength) => {
|
|
1684
|
-
const output = new Uint8Array(byteLength);
|
|
1685
|
-
let offset = 0;
|
|
1686
|
-
for (const chunk of chunks) {
|
|
1687
|
-
output.set(chunk, offset);
|
|
1688
|
-
offset += chunk.byteLength;
|
|
1689
|
-
}
|
|
1690
|
-
return output;
|
|
1691
|
-
};
|
|
1692
1608
|
/**
|
|
1693
1609
|
* Confirms whether a directory with an exact `.git` marker owns another working tree.
|
|
1694
1610
|
* @param directory The exact no-follow directory being classified.
|
|
1695
1611
|
* @param repositoryRoot The selected repository root.
|
|
1696
1612
|
* @param directoryStatistics The stable no-follow boundary observation.
|
|
1697
|
-
* @param maxMetadataBytes The remaining bounded Git
|
|
1698
|
-
* @param
|
|
1613
|
+
* @param maxMetadataBytes The remaining bounded Git output budget.
|
|
1614
|
+
* @param readRoot The typed Git working-tree root read.
|
|
1699
1615
|
* @param inspectHostPath The no-follow filesystem stat operation.
|
|
1700
1616
|
* @returns A safe ownership classification and the consumed Git metadata bytes.
|
|
1701
1617
|
*/
|
|
1702
|
-
var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics, maxMetadataBytes,
|
|
1618
|
+
var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics, maxMetadataBytes, readRoot, inspectHostPath, signal) => {
|
|
1703
1619
|
if (signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
|
|
1704
1620
|
if (!Number.isSafeInteger(maxMetadataBytes) || maxMetadataBytes < 0) return createInspectionFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
arguments: [
|
|
1709
|
-
"-C",
|
|
1710
|
-
directory,
|
|
1711
|
-
...GIT_REPOSITORY_ROOT_ARGUMENTS
|
|
1712
|
-
],
|
|
1713
|
-
consumeStdout: (chunk) => {
|
|
1714
|
-
stdoutChunks.push(Uint8Array.from(chunk));
|
|
1715
|
-
consumedStdoutBytes += chunk.byteLength;
|
|
1716
|
-
},
|
|
1717
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
1718
|
-
maxStdoutBytes: maxMetadataBytes,
|
|
1621
|
+
const rootResult = await readGit(() => readRoot(directory, {
|
|
1622
|
+
maxOutputBytes: Math.max(maxMetadataBytes, 1),
|
|
1623
|
+
timeoutSeconds: 300,
|
|
1719
1624
|
...signal === void 0 ? {} : { signal }
|
|
1720
|
-
});
|
|
1721
|
-
if (
|
|
1722
|
-
if (
|
|
1723
|
-
const discoveredRoot =
|
|
1724
|
-
|
|
1625
|
+
}), signal);
|
|
1626
|
+
if (rootResult.kind === "failed") return createInspectionFailure(mapGitFailure$1(rootResult.reason));
|
|
1627
|
+
if (rootResult.value === null) return createInspectionFailure("GIT_COMMAND_FAILED");
|
|
1628
|
+
const discoveredRoot = rootResult.value;
|
|
1629
|
+
const gitMetadataBytes = TOP_LEVEL_OUTPUT_OVERHEAD_BYTES + countUtf8Bytes(discoveredRoot);
|
|
1630
|
+
if (gitMetadataBytes > maxMetadataBytes) return createInspectionFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1631
|
+
if (!path.isAbsolute(discoveredRoot)) return createInspectionFailure("GIT_OUTPUT_INVALID");
|
|
1725
1632
|
if (areHostPathsEquivalent(discoveredRoot, directory)) return Object.freeze({
|
|
1726
|
-
gitMetadataBytes
|
|
1633
|
+
gitMetadataBytes,
|
|
1727
1634
|
kind: "validated",
|
|
1728
1635
|
ownership: "nested-repository"
|
|
1729
1636
|
});
|
|
1730
1637
|
if (areHostPathsEquivalent(discoveredRoot, repositoryRoot)) return Object.freeze({
|
|
1731
|
-
gitMetadataBytes
|
|
1638
|
+
gitMetadataBytes,
|
|
1732
1639
|
kind: "validated",
|
|
1733
1640
|
ownership: "selected-repository"
|
|
1734
1641
|
});
|
|
@@ -1737,7 +1644,7 @@ var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics,
|
|
|
1737
1644
|
if (discoveredRootInspection.kind === "failed") return discoveredRootInspection;
|
|
1738
1645
|
if (!discoveredRootInspection.statistics.isDirectory() || discoveredRootInspection.statistics.isSymbolicLink()) return createInspectionFailure("GIT_OUTPUT_INVALID");
|
|
1739
1646
|
if (haveSameHostPathIdentity(discoveredRootInspection.statistics, directoryStatistics)) return Object.freeze({
|
|
1740
|
-
gitMetadataBytes
|
|
1647
|
+
gitMetadataBytes,
|
|
1741
1648
|
kind: "validated",
|
|
1742
1649
|
ownership: "nested-repository"
|
|
1743
1650
|
});
|
|
@@ -1745,7 +1652,7 @@ var validateGitBoundary = async (directory, repositoryRoot, directoryStatistics,
|
|
|
1745
1652
|
if (signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
|
|
1746
1653
|
if (repositoryRootInspection.kind === "failed") return repositoryRootInspection;
|
|
1747
1654
|
if (repositoryRootInspection.statistics.isDirectory() && !repositoryRootInspection.statistics.isSymbolicLink() && haveSameHostPathIdentity(discoveredRootInspection.statistics, repositoryRootInspection.statistics)) return Object.freeze({
|
|
1748
|
-
gitMetadataBytes
|
|
1655
|
+
gitMetadataBytes,
|
|
1749
1656
|
kind: "validated",
|
|
1750
1657
|
ownership: "selected-repository"
|
|
1751
1658
|
});
|
|
@@ -1757,12 +1664,12 @@ var inspectOwnershipPath = async (hostPath) => lstat(hostPath, { bigint: true })
|
|
|
1757
1664
|
var readOwnershipDirectory = async (hostPath) => readdir(hostPath, { encoding: "buffer" });
|
|
1758
1665
|
/**
|
|
1759
1666
|
* Creates nested-repository inspection around injectable filesystem and Git boundaries.
|
|
1760
|
-
* @param
|
|
1667
|
+
* @param readRoot The typed Git working-tree root read.
|
|
1761
1668
|
* @param inspectHostPath The no-follow filesystem stat operation.
|
|
1762
1669
|
* @param readDirectory The raw native-name directory operation.
|
|
1763
1670
|
* @returns An all-or-nothing ownership inspector for untracked candidate paths.
|
|
1764
1671
|
*/
|
|
1765
|
-
var createGitInventoryBoundaryInspector = (
|
|
1672
|
+
var createGitInventoryBoundaryInspector = (readRoot = readTopLevel, inspectHostPath = inspectOwnershipPath, readDirectory = readOwnershipDirectory) => {
|
|
1766
1673
|
return async (input) => {
|
|
1767
1674
|
if (input.signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
|
|
1768
1675
|
const directoryObservations = /* @__PURE__ */ new Map();
|
|
@@ -1820,7 +1727,7 @@ var createGitInventoryBoundaryInspector = (processExecutor = executeGitStreaming
|
|
|
1820
1727
|
if (input.signal?.aborted) return createInspectionFailure("GIT_OPERATION_ABORTED");
|
|
1821
1728
|
if (gitControlInspection.kind === "failed") return gitControlInspection;
|
|
1822
1729
|
if (gitControlInspection.statistics.isSymbolicLink() || !gitControlInspection.statistics.isDirectory() && !gitControlInspection.statistics.isFile()) return createInspectionFailure("GIT_OUTPUT_INVALID");
|
|
1823
|
-
const boundaryValidation = await validateGitBoundary(hostPath, input.repositoryRoot, revalidatedInspection.statistics, input.maxMetadataBytes - gitMetadataBytes,
|
|
1730
|
+
const boundaryValidation = await validateGitBoundary(hostPath, input.repositoryRoot, revalidatedInspection.statistics, input.maxMetadataBytes - gitMetadataBytes, readRoot, inspectHostPath, input.signal);
|
|
1824
1731
|
if (boundaryValidation.kind === "failed") return boundaryValidation;
|
|
1825
1732
|
gitMetadataBytes += boundaryValidation.gitMetadataBytes;
|
|
1826
1733
|
directoryOwnership = boundaryValidation.ownership;
|
|
@@ -1982,23 +1889,48 @@ var createGitInventoryOwnershipFilter = (boundaryInspector = inspectGitInventory
|
|
|
1982
1889
|
};
|
|
1983
1890
|
//#endregion
|
|
1984
1891
|
//#region src/git-inventory/probe.ts
|
|
1985
|
-
|
|
1986
|
-
|
|
1892
|
+
var GIT_INVENTORY_LISTING_READS = Object.freeze({
|
|
1893
|
+
listUntrackedFiles,
|
|
1894
|
+
readIndexEntries,
|
|
1895
|
+
runGit: runGitCommand
|
|
1896
|
+
});
|
|
1897
|
+
/** Maps one normalized Git failure to a safe inventory error. */
|
|
1898
|
+
var mapGitFailure = (reason) => {
|
|
1987
1899
|
switch (reason) {
|
|
1988
1900
|
case "aborted": return "GIT_OPERATION_ABORTED";
|
|
1989
1901
|
case "not-found": return "GIT_NOT_FOUND";
|
|
1990
1902
|
case "repository-not-found": return "GIT_REPOSITORY_NOT_FOUND";
|
|
1991
1903
|
case "access-denied": return "GIT_ACCESS_DENIED";
|
|
1992
|
-
case "
|
|
1993
|
-
case "output-limit-exceeded":
|
|
1994
|
-
case "stdout-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1904
|
+
case "output-invalid": return "GIT_OUTPUT_INVALID";
|
|
1905
|
+
case "output-limit-exceeded": return "RESOURCE_LIMIT_EXCEEDED";
|
|
1995
1906
|
case "command-failed": return "GIT_COMMAND_FAILED";
|
|
1996
1907
|
}
|
|
1997
1908
|
};
|
|
1998
|
-
/**
|
|
1999
|
-
var
|
|
1909
|
+
/** Determines whether one index mode belongs to the version 1 inventory grammar. */
|
|
1910
|
+
var isTrackedEntryMode = (mode) => GIT_TRACKED_ENTRY_MODES.includes(mode);
|
|
1911
|
+
/** Converts index entries into tracked candidates, or null when one has an unsupported mode. */
|
|
1912
|
+
var toTrackedCandidates = (entries) => {
|
|
1913
|
+
const candidates = [];
|
|
1914
|
+
for (const { mode, path, stage } of entries) {
|
|
1915
|
+
if (!isTrackedEntryMode(mode)) return null;
|
|
1916
|
+
candidates.push(Object.freeze({
|
|
1917
|
+
kind: "tracked",
|
|
1918
|
+
mode,
|
|
1919
|
+
path,
|
|
1920
|
+
stage
|
|
1921
|
+
}));
|
|
1922
|
+
}
|
|
1923
|
+
return Object.freeze(candidates);
|
|
1924
|
+
};
|
|
1925
|
+
/** Measures the stdout `ls-files --stage -z` wrote for the index entries. */
|
|
1926
|
+
var measureTrackedOutput = (entries) => entries.reduce((bytes, { path }) => bytes + 75 + countUtf8Bytes(path), 0);
|
|
1927
|
+
/** Measures the stdout `ls-files --others -z` wrote for the untracked paths. */
|
|
1928
|
+
var measureUntrackedOutput = (paths) => paths.reduce((bytes, path) => bytes + countUtf8Bytes(path) + 1, 0);
|
|
1929
|
+
/** Creates one immutable inventory-probe failure, naming the Git subcommand when Git failed. */
|
|
1930
|
+
var createProbeFailure = (errorCode, subcommand) => Object.freeze({
|
|
2000
1931
|
errorCode,
|
|
2001
|
-
kind: "failed"
|
|
1932
|
+
kind: "failed",
|
|
1933
|
+
...subcommand === void 0 ? {} : { subcommand }
|
|
2002
1934
|
});
|
|
2003
1935
|
/** Maps one completed parser result into immutable candidates or a safe failure. */
|
|
2004
1936
|
var resolveParserResult = (parserResult) => {
|
|
@@ -2009,99 +1941,85 @@ var resolveParserResult = (parserResult) => {
|
|
|
2009
1941
|
var isProbeFailure = (result) => !Array.isArray(result);
|
|
2010
1942
|
/**
|
|
2011
1943
|
* Creates the strict normalized Git inventory probe around injectable boundaries.
|
|
2012
|
-
* @param
|
|
1944
|
+
* @param git The typed Git reads and command that list raw candidates.
|
|
2013
1945
|
* @param ownershipFilter The submodule and nested-repository ownership filter.
|
|
2014
1946
|
* @param entryTypeNormalizer The current filesystem and Git mode entry-type normalizer.
|
|
2015
1947
|
* @param contentTransformationClassifier The bounded effective Git attribute classifier.
|
|
2016
1948
|
* @param logicalPathNormalizer The portable repository logical-path normalizer.
|
|
1949
|
+
* @param linkAncestorShadower The step that replaces candidates beneath a working-tree link.
|
|
2017
1950
|
* @returns An all-or-nothing selected-repository entry probe.
|
|
2018
1951
|
*/
|
|
2019
|
-
var createGitInventoryProbe = (
|
|
1952
|
+
var createGitInventoryProbe = (git = GIT_INVENTORY_LISTING_READS, ownershipFilter = createGitInventoryOwnershipFilter(createGitInventoryBoundaryInspector()), entryTypeNormalizer = createGitInventoryEntryTypeNormalizer(inspectGitInventoryEntry, createGitSymlinkConfigurationResolver()), contentTransformationClassifier = createGitContentTransformationClassifier(), logicalPathNormalizer = normalizeGitInventoryLogicalPaths, linkAncestorShadower = shadowGitLinkAncestors) => async (input) => {
|
|
2020
1953
|
if (input.signal?.aborted) return createProbeFailure("GIT_OPERATION_ABORTED");
|
|
2021
|
-
const
|
|
2022
|
-
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
...GIT_TRACKED_INVENTORY_ARGUMENTS,
|
|
2028
|
-
...selectionPathspecs
|
|
2029
|
-
],
|
|
2030
|
-
consumeStdout: (chunk) => trackedParser.consume(chunk),
|
|
2031
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
2032
|
-
maxStdoutBytes: input.maxMetadataBytes,
|
|
2033
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2034
|
-
});
|
|
2035
|
-
if (trackedProcessResult.kind === "failed") return createProbeFailure(mapGitProcessFailure(trackedProcessResult.reason));
|
|
2036
|
-
if (trackedProcessResult.stderr.byteLength > 0) return createProbeFailure("GIT_OUTPUT_INVALID");
|
|
2037
|
-
const trackedCandidates = resolveParserResult(trackedParser.finish());
|
|
2038
|
-
if (isProbeFailure(trackedCandidates)) return trackedCandidates;
|
|
2039
|
-
const untrackedParser = createUntrackedGitInventoryParser(input.maxEntries - trackedCandidates.length);
|
|
2040
|
-
const untrackedProcessResult = await processExecutor({
|
|
2041
|
-
arguments: [
|
|
2042
|
-
"-C",
|
|
2043
|
-
input.repositoryRoot,
|
|
2044
|
-
...GIT_UNTRACKED_INVENTORY_ARGUMENTS,
|
|
2045
|
-
...selectionPathspecs
|
|
2046
|
-
],
|
|
2047
|
-
consumeStdout: (chunk) => untrackedParser.consume(chunk),
|
|
2048
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
2049
|
-
maxStdoutBytes: input.maxMetadataBytes - trackedProcessResult.stdoutBytes,
|
|
1954
|
+
const selectionPaths = (input.selectionPaths ?? []).map((selectionPath) => selectionPath.slice(1));
|
|
1955
|
+
let remainingMetadataBytes = input.maxMetadataBytes;
|
|
1956
|
+
const createReadOptions = () => ({
|
|
1957
|
+
maxOutputBytes: Math.max(remainingMetadataBytes, 1),
|
|
1958
|
+
timeoutSeconds: 300,
|
|
1959
|
+
...selectionPaths.length === 0 ? {} : { paths: selectionPaths },
|
|
2050
1960
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2051
1961
|
});
|
|
2052
|
-
|
|
2053
|
-
if (
|
|
2054
|
-
|
|
2055
|
-
if (
|
|
1962
|
+
const trackedResult = await readGit(() => git.readIndexEntries(input.repositoryRoot, createReadOptions()), input.signal, GIT_INVENTORY_LISTING_SUBCOMMAND);
|
|
1963
|
+
if (trackedResult.kind === "failed") return createProbeFailure(mapGitFailure(trackedResult.reason), trackedResult.subcommand);
|
|
1964
|
+
remainingMetadataBytes -= measureTrackedOutput(trackedResult.value);
|
|
1965
|
+
if (trackedResult.value.length > input.maxEntries || remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1966
|
+
const trackedCandidates = toTrackedCandidates(trackedResult.value);
|
|
1967
|
+
if (trackedCandidates === null) return createProbeFailure("GIT_OUTPUT_INVALID");
|
|
1968
|
+
const untrackedResult = await readGit(() => git.listUntrackedFiles(input.repositoryRoot, createReadOptions()), input.signal, GIT_INVENTORY_LISTING_SUBCOMMAND);
|
|
1969
|
+
if (untrackedResult.kind === "failed") return createProbeFailure(mapGitFailure(untrackedResult.reason), untrackedResult.subcommand);
|
|
1970
|
+
remainingMetadataBytes -= measureUntrackedOutput(untrackedResult.value);
|
|
1971
|
+
if (trackedCandidates.length + untrackedResult.value.length > input.maxEntries || remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1972
|
+
if (untrackedResult.value.some((path) => path.length === 0)) return createProbeFailure("GIT_OUTPUT_INVALID");
|
|
1973
|
+
const untrackedCandidates = Object.freeze(untrackedResult.value.map((path) => Object.freeze({
|
|
1974
|
+
kind: "untracked",
|
|
1975
|
+
path
|
|
1976
|
+
})));
|
|
2056
1977
|
let ignoredCandidates = [];
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
arguments: [
|
|
2062
|
-
"-C",
|
|
2063
|
-
input.repositoryRoot,
|
|
2064
|
-
...GIT_IGNORED_INVENTORY_ARGUMENTS,
|
|
2065
|
-
...selectionPathspecs
|
|
2066
|
-
],
|
|
2067
|
-
consumeStdout: (chunk) => ignoredParser.consume(chunk),
|
|
2068
|
-
maxStderrBytes: MAX_GIT_PROCESS_DIAGNOSTIC_BYTES,
|
|
2069
|
-
maxStdoutBytes: input.maxMetadataBytes - trackedProcessResult.stdoutBytes - untrackedProcessResult.stdoutBytes,
|
|
1978
|
+
if (input.includeIgnored === true && selectionPaths.length > 0) {
|
|
1979
|
+
const ignoredResult = await git.runGit([...GIT_IGNORED_INVENTORY_ARGUMENTS, ...selectionPaths], {
|
|
1980
|
+
cwd: input.repositoryRoot,
|
|
1981
|
+
maxOutputBytes: Math.max(remainingMetadataBytes, 1),
|
|
2070
1982
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2071
1983
|
});
|
|
2072
|
-
if (
|
|
2073
|
-
|
|
1984
|
+
if (ignoredResult.kind === "failed") return createProbeFailure(mapGitFailure(ignoredResult.reason), ignoredResult.subcommand);
|
|
1985
|
+
remainingMetadataBytes -= ignoredResult.value.byteLength;
|
|
1986
|
+
if (remainingMetadataBytes < 0) return createProbeFailure("RESOURCE_LIMIT_EXCEEDED");
|
|
1987
|
+
const ignoredParser = createUntrackedGitInventoryParser(input.maxEntries - trackedCandidates.length - untrackedCandidates.length);
|
|
1988
|
+
ignoredParser.consume(ignoredResult.value);
|
|
2074
1989
|
const parsedIgnoredCandidates = resolveParserResult(ignoredParser.finish());
|
|
2075
1990
|
if (isProbeFailure(parsedIgnoredCandidates)) return parsedIgnoredCandidates;
|
|
2076
1991
|
const untrackedPaths = new Set(untrackedCandidates.map((candidate) => candidate.path));
|
|
2077
1992
|
ignoredCandidates = parsedIgnoredCandidates.filter((candidate) => !untrackedPaths.has(candidate.path));
|
|
2078
|
-
ignoredStdoutBytes = ignoredProcessResult.stdoutBytes;
|
|
2079
1993
|
}
|
|
2080
|
-
const
|
|
1994
|
+
const logicalPathFilterResult = filterGitInventoryCandidateLogicalPaths({ candidates: Object.freeze([
|
|
2081
1995
|
...trackedCandidates,
|
|
2082
1996
|
...untrackedCandidates,
|
|
2083
1997
|
...ignoredCandidates
|
|
2084
|
-
]);
|
|
2085
|
-
const metadataBytesAfterListing = input.maxMetadataBytes - trackedProcessResult.stdoutBytes - untrackedProcessResult.stdoutBytes - ignoredStdoutBytes;
|
|
2086
|
-
const logicalPathFilterResult = filterGitInventoryCandidateLogicalPaths({ candidates });
|
|
1998
|
+
]) });
|
|
2087
1999
|
if (logicalPathFilterResult.kind === "failed") return logicalPathFilterResult;
|
|
2088
|
-
const
|
|
2000
|
+
const shadowResult = await linkAncestorShadower({
|
|
2089
2001
|
candidates: logicalPathFilterResult.candidates,
|
|
2090
|
-
|
|
2002
|
+
repositoryRoot: input.repositoryRoot,
|
|
2003
|
+
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2004
|
+
});
|
|
2005
|
+
if (shadowResult.kind === "failed") return shadowResult;
|
|
2006
|
+
const ownershipResult = await ownershipFilter({
|
|
2007
|
+
candidates: shadowResult.candidates,
|
|
2008
|
+
maxMetadataBytes: remainingMetadataBytes,
|
|
2091
2009
|
repositoryRoot: input.repositoryRoot,
|
|
2092
2010
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2093
2011
|
});
|
|
2094
2012
|
if (ownershipResult.kind === "failed") return ownershipResult;
|
|
2095
2013
|
const entryTypeResult = await entryTypeNormalizer({
|
|
2096
2014
|
candidates: ownershipResult.candidates,
|
|
2097
|
-
maxMetadataBytes:
|
|
2015
|
+
maxMetadataBytes: remainingMetadataBytes - ownershipResult.gitMetadataBytes,
|
|
2098
2016
|
repositoryRoot: input.repositoryRoot,
|
|
2099
2017
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2100
2018
|
});
|
|
2101
2019
|
if (entryTypeResult.kind === "failed") return entryTypeResult;
|
|
2102
2020
|
const contentTransformationResult = await contentTransformationClassifier({
|
|
2103
2021
|
entries: entryTypeResult.entries,
|
|
2104
|
-
maxMetadataBytes:
|
|
2022
|
+
maxMetadataBytes: remainingMetadataBytes - ownershipResult.gitMetadataBytes - entryTypeResult.gitMetadataBytes,
|
|
2105
2023
|
repositoryRoot: input.repositoryRoot,
|
|
2106
2024
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2107
2025
|
});
|
|
@@ -2388,10 +2306,11 @@ var createWorkingTreeInstructionSourceFactory = (filesystemReaderFactory = creat
|
|
|
2388
2306
|
var createWorkingTreeInstructionSource = createWorkingTreeInstructionSourceFactory();
|
|
2389
2307
|
//#endregion
|
|
2390
2308
|
//#region src/working-tree-snapshot/executor.ts
|
|
2391
|
-
/** Creates one immutable terminal snapshot failure. */
|
|
2392
|
-
var createSnapshotFailure = (errorCode) => Object.freeze({
|
|
2309
|
+
/** Creates one immutable terminal snapshot failure, keeping a failed Git inventory subcommand. */
|
|
2310
|
+
var createSnapshotFailure = (errorCode, subcommand) => Object.freeze({
|
|
2393
2311
|
errorCode,
|
|
2394
|
-
kind: "failed"
|
|
2312
|
+
kind: "failed",
|
|
2313
|
+
...subcommand === void 0 ? {} : { subcommand }
|
|
2395
2314
|
});
|
|
2396
2315
|
/** Determines whether a source exception proves that the current reader is unusable. */
|
|
2397
2316
|
var isSnapshotChanged = (error) => error instanceof RepositorySourceException && error.code === "SNAPSHOT_CHANGED";
|
|
@@ -2429,7 +2348,7 @@ var createWorkingTreeSnapshotExecutor = (identityInspector = inspectGitWorkingTr
|
|
|
2429
2348
|
...input.selectionPaths === void 0 ? {} : { selectionPaths: input.selectionPaths },
|
|
2430
2349
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2431
2350
|
});
|
|
2432
|
-
return result.kind === "failed" ? createSnapshotFailure(result.errorCode) : result;
|
|
2351
|
+
return result.kind === "failed" ? createSnapshotFailure(result.errorCode, result.subcommand) : result;
|
|
2433
2352
|
};
|
|
2434
2353
|
const probeInstructions = async () => {
|
|
2435
2354
|
if (input.includeInstructions !== true) return null;
|
|
@@ -2441,7 +2360,7 @@ var createWorkingTreeSnapshotExecutor = (identityInspector = inspectGitWorkingTr
|
|
|
2441
2360
|
selectionPaths: INSTRUCTION_PATHS,
|
|
2442
2361
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2443
2362
|
});
|
|
2444
|
-
return result.kind === "failed" ? createSnapshotFailure(result.errorCode) : result;
|
|
2363
|
+
return result.kind === "failed" ? createSnapshotFailure(result.errorCode, result.subcommand) : result;
|
|
2445
2364
|
};
|
|
2446
2365
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
2447
2366
|
if (input.signal?.aborted) return createSnapshotFailure("GIT_OPERATION_ABORTED");
|
|
@@ -2675,15 +2594,15 @@ var createMoldeaCliContentExecutionResult = (pageResult, cliVersion, isJson, cur
|
|
|
2675
2594
|
//#region src/cli-execution/command-executor.ts
|
|
2676
2595
|
/** Loads isolated Core inspection only for commands that need it. */
|
|
2677
2596
|
var executeLazyCoreInspection = async (input) => {
|
|
2678
|
-
const { executeMoldeaCliCoreInspection } = await import("./chunks/core-composition-
|
|
2597
|
+
const { executeMoldeaCliCoreInspection } = await import("./chunks/core-composition-DeWcE7Bf.js");
|
|
2679
2598
|
return executeMoldeaCliCoreInspection(input);
|
|
2680
2599
|
};
|
|
2681
2600
|
var loadInstalledComposition = async (input) => {
|
|
2682
|
-
const { resolveInstalledMoldeaCliComposition } = await import("./chunks/composition-
|
|
2601
|
+
const { resolveInstalledMoldeaCliComposition } = await import("./chunks/composition-PoYBx0Mw.js");
|
|
2683
2602
|
return resolveInstalledMoldeaCliComposition(input);
|
|
2684
2603
|
};
|
|
2685
2604
|
/** Creates one operational error result without exposing caught failure details. */
|
|
2686
|
-
var createOperationalErrorResult = (code, input) => createMoldeaCliErrorResult(createMoldeaCliOwnedError(code), input.invocation.command, input.packageMetadata.version, input.invocation.options.isJson, MOLDEA_CLI_EXIT_CODES.OperationalError);
|
|
2605
|
+
var createOperationalErrorResult = (code, input, details) => createMoldeaCliErrorResult(createMoldeaCliOwnedError(code, details), input.invocation.command, input.packageMetadata.version, input.invocation.options.isJson, MOLDEA_CLI_EXIT_CODES.OperationalError);
|
|
2687
2606
|
/**
|
|
2688
2607
|
* Creates command dispatch with lazy Core loading and bounded working-tree snapshots.
|
|
2689
2608
|
* @param workingTreeDiscovery The Git working-tree discovery operation.
|
|
@@ -2777,7 +2696,7 @@ var createMoldeaCliCommandExecutor = (workingTreeDiscovery = discoverGitWorkingT
|
|
|
2777
2696
|
...command === MOLDEA_CLI_COMMANDS.Scope ? { selectionPaths: [MOLDEA_MANIFEST_PATH] } : contentPath === null ? {} : { selectionPaths: [contentPath] },
|
|
2778
2697
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
2779
2698
|
});
|
|
2780
|
-
if (snapshotResult.kind === "failed") return createOperationalErrorResult(snapshotResult.errorCode, input);
|
|
2699
|
+
if (snapshotResult.kind === "failed") return createOperationalErrorResult(snapshotResult.errorCode, input, snapshotResult.subcommand === void 0 ? void 0 : { subcommand: snapshotResult.subcommand });
|
|
2781
2700
|
if (command === MOLDEA_CLI_COMMANDS.Validate) return createMoldeaCliValidateExecutionResult(snapshotResult.result, input.packageMetadata.version, options.isJson, options.cursor, options.maxOutputBytes);
|
|
2782
2701
|
if (command === MOLDEA_CLI_COMMANDS.Inspect) return createMoldeaCliInspectExecutionResult(snapshotResult.result, input.packageMetadata.version, options.isJson, options.cursor, options.maxOutputBytes);
|
|
2783
2702
|
if (command === MOLDEA_CLI_COMMANDS.Scope) return createMoldeaCliScopeExecutionResult(snapshotResult.result, input.packageMetadata.version, options.isJson, options.cursor, options.maxOutputBytes);
|
|
@@ -2909,92 +2828,31 @@ var loadMoldeaCliPackageMetadata = async (packageManifestPath, packageEntryResol
|
|
|
2909
2828
|
});
|
|
2910
2829
|
};
|
|
2911
2830
|
//#endregion
|
|
2912
|
-
//#region src/process-signal/session.ts
|
|
2913
|
-
var SIGNAL_EXIT_CODES = Object.freeze({
|
|
2914
|
-
SIGINT: MOLDEA_CLI_EXIT_CODES.Interrupted,
|
|
2915
|
-
SIGTERM: MOLDEA_CLI_EXIT_CODES.Terminated
|
|
2916
|
-
});
|
|
2917
|
-
var PROCESS_SIGNAL_SOURCE = Object.freeze({
|
|
2918
|
-
addListener: (signal, listener) => {
|
|
2919
|
-
process.on(signal, listener);
|
|
2920
|
-
},
|
|
2921
|
-
removeListener: (signal, listener) => {
|
|
2922
|
-
process.off(signal, listener);
|
|
2923
|
-
},
|
|
2924
|
-
closeIpc: () => {
|
|
2925
|
-
if (process.connected) process.disconnect();
|
|
2926
|
-
},
|
|
2927
|
-
hasDisconnectedLauncher: () => typeof process.send === "function" && !process.connected
|
|
2928
|
-
});
|
|
2929
|
-
/**
|
|
2930
|
-
* Creates one process-signal session around an operation-scoped abort controller.
|
|
2931
|
-
* @param signalSource The process-listener boundary.
|
|
2932
|
-
* @returns A session that records the first signal until output completes.
|
|
2933
|
-
*/
|
|
2934
|
-
var createMoldeaCliProcessSignalSession = (signalSource = PROCESS_SIGNAL_SOURCE) => {
|
|
2935
|
-
const controller = new AbortController();
|
|
2936
|
-
let exitCode = null;
|
|
2937
|
-
let isDisposed = false;
|
|
2938
|
-
let isOutputComplete = false;
|
|
2939
|
-
const handleSignal = (signal) => {
|
|
2940
|
-
if (exitCode !== null || isDisposed || isOutputComplete) return;
|
|
2941
|
-
exitCode = SIGNAL_EXIT_CODES[signal];
|
|
2942
|
-
controller.abort();
|
|
2943
|
-
};
|
|
2944
|
-
const handleSigint = () => handleSignal("SIGINT");
|
|
2945
|
-
const handleSigterm = () => handleSignal("SIGTERM");
|
|
2946
|
-
const handleDisconnect = () => handleSignal("SIGTERM");
|
|
2947
|
-
signalSource.addListener("SIGINT", handleSigint);
|
|
2948
|
-
signalSource.addListener("SIGTERM", handleSigterm);
|
|
2949
|
-
signalSource.addListener("disconnect", handleDisconnect);
|
|
2950
|
-
if (signalSource.hasDisconnectedLauncher()) handleDisconnect();
|
|
2951
|
-
return Object.freeze({
|
|
2952
|
-
completeOutput: () => {
|
|
2953
|
-
isOutputComplete = true;
|
|
2954
|
-
},
|
|
2955
|
-
dispose: () => {
|
|
2956
|
-
if (isDisposed) return;
|
|
2957
|
-
isDisposed = true;
|
|
2958
|
-
signalSource.removeListener("SIGINT", handleSigint);
|
|
2959
|
-
signalSource.removeListener("SIGTERM", handleSigterm);
|
|
2960
|
-
signalSource.removeListener("disconnect", handleDisconnect);
|
|
2961
|
-
signalSource.closeIpc();
|
|
2962
|
-
},
|
|
2963
|
-
get exitCode() {
|
|
2964
|
-
return exitCode;
|
|
2965
|
-
},
|
|
2966
|
-
get hasReceivedSignal() {
|
|
2967
|
-
return exitCode !== null;
|
|
2968
|
-
},
|
|
2969
|
-
signal: controller.signal
|
|
2970
|
-
});
|
|
2971
|
-
};
|
|
2972
|
-
//#endregion
|
|
2973
2831
|
//#region src/bin/index.ts
|
|
2974
2832
|
var executableDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
2975
2833
|
var packageManifestPath = path.resolve(executableDirectory, "..", "package.json");
|
|
2976
|
-
var
|
|
2977
|
-
|
|
2834
|
+
var shutdown = createShutdownSignal({
|
|
2835
|
+
disconnect: true,
|
|
2836
|
+
setExitCode: false
|
|
2837
|
+
});
|
|
2838
|
+
/** Reads process stdin without retaining bytes above the requested limit. */
|
|
2978
2839
|
var readProcessStdin = async (maxBytes, signal) => {
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2840
|
+
try {
|
|
2841
|
+
return {
|
|
2842
|
+
bytes: await readStdin({
|
|
2843
|
+
maxBytes,
|
|
2844
|
+
signal
|
|
2845
|
+
}),
|
|
2846
|
+
kind: "completed"
|
|
2847
|
+
};
|
|
2848
|
+
} catch (error) {
|
|
2849
|
+
if (hasErrorCode(error, ERRORS.STDIN_TOO_LARGE)) return { kind: "limit-exceeded" };
|
|
2850
|
+
if (signal?.aborted === true) return {
|
|
2983
2851
|
bytes: /* @__PURE__ */ new Uint8Array(),
|
|
2984
2852
|
kind: "completed"
|
|
2985
2853
|
};
|
|
2986
|
-
|
|
2987
|
-
totalBytes += bytes.byteLength;
|
|
2988
|
-
if (totalBytes > maxBytes) {
|
|
2989
|
-
process.stdin.pause();
|
|
2990
|
-
return { kind: "limit-exceeded" };
|
|
2991
|
-
}
|
|
2992
|
-
chunks.push(bytes);
|
|
2854
|
+
throw error;
|
|
2993
2855
|
}
|
|
2994
|
-
return {
|
|
2995
|
-
bytes: Buffer.concat(chunks, totalBytes),
|
|
2996
|
-
kind: "completed"
|
|
2997
|
-
};
|
|
2998
2856
|
};
|
|
2999
2857
|
/**
|
|
3000
2858
|
* Writes one complete process output string.
|
|
@@ -3022,24 +2880,20 @@ try {
|
|
|
3022
2880
|
invocationDirectory,
|
|
3023
2881
|
packageMetadata,
|
|
3024
2882
|
readStdin: readProcessStdin,
|
|
3025
|
-
signal:
|
|
2883
|
+
signal: shutdown.signal
|
|
3026
2884
|
});
|
|
3027
|
-
if (
|
|
3028
|
-
else {
|
|
2885
|
+
if (shutdown.receivedSignal() === null) {
|
|
3029
2886
|
await writeProcessOutput(process.stdout, executionResult.stdout);
|
|
3030
|
-
if (
|
|
3031
|
-
if (!signalSession.hasReceivedSignal) signalSession.completeOutput();
|
|
3032
|
-
process.exitCode = signalSession.exitCode ?? executionResult.exitCode;
|
|
2887
|
+
if (shutdown.receivedSignal() === null) await writeProcessOutput(process.stderr, executionResult.stderr);
|
|
3033
2888
|
}
|
|
2889
|
+
process.exitCode = shutdown.exitCode() ?? executionResult.exitCode;
|
|
3034
2890
|
} catch {
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
signalSession.completeOutput();
|
|
3039
|
-
process.exitCode = 3;
|
|
3040
|
-
}
|
|
2891
|
+
const signalExitCode = shutdown.exitCode();
|
|
2892
|
+
if (signalExitCode === null) await writeProcessOutput(process.stderr, formatMoldeaCliHumanError(createMoldeaCliOwnedError("INTERNAL_ERROR"))).catch(() => void 0);
|
|
2893
|
+
process.exitCode = signalExitCode ?? 3;
|
|
3041
2894
|
} finally {
|
|
3042
|
-
|
|
2895
|
+
shutdown.dispose();
|
|
2896
|
+
if (process.connected) process.disconnect();
|
|
3043
2897
|
}
|
|
3044
2898
|
//#endregion
|
|
3045
2899
|
|