@moldea.ai/cli 9.0.0 → 10.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/README.md +11 -7
- package/dist/adapter-registry.js +28 -0
- package/dist/adapter-registry.js.map +1 -0
- package/dist/chunks/composition-B1VCddjs.js +3 -0
- package/dist/chunks/{semver-BzaJzKRS.js → composition-DIN3r5rw.js} +1085 -2
- package/dist/chunks/composition-DIN3r5rw.js.map +1 -0
- package/dist/chunks/core-composition-CWyDX8h6.js +130 -0
- package/dist/chunks/core-composition-CWyDX8h6.js.map +1 -0
- package/dist/moldea.js +35 -937
- package/dist/moldea.js.map +1 -1
- package/package.json +16 -13
- package/dist/chunks/composition-Ck3cXQUk.js +0 -142
- package/dist/chunks/composition-Ck3cXQUk.js.map +0 -1
- package/dist/chunks/core-composition-CgaKOyog.js +0 -3
- package/dist/chunks/core-composition-CttwXtDG.js +0 -92
- package/dist/chunks/core-composition-CttwXtDG.js.map +0 -1
- package/dist/chunks/semver-BzaJzKRS.js.map +0 -1
|
@@ -1,10 +1,942 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process$1 from "node:process";
|
|
3
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
3
4
|
import { execFile, spawn } from "node:child_process";
|
|
4
5
|
import { TextDecoder as TextDecoder$1 } from "node:util";
|
|
6
|
+
import { SUPPORTED_REPOSITORY_FORMAT_VERSIONS } from "@moldea.ai/core";
|
|
5
7
|
//#region \0rolldown/runtime.js
|
|
6
8
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
7
9
|
//#endregion
|
|
10
|
+
//#region src/command-line/constants.ts
|
|
11
|
+
var MOLDEA_CLI_COMMANDS = {
|
|
12
|
+
Composition: "composition",
|
|
13
|
+
Content: "content",
|
|
14
|
+
Inspect: "inspect",
|
|
15
|
+
Scope: "scope",
|
|
16
|
+
Validate: "validate"
|
|
17
|
+
};
|
|
18
|
+
var MOLDEA_CLI_OPTIONS = {
|
|
19
|
+
Help: "--help",
|
|
20
|
+
Json: "--json",
|
|
21
|
+
Cursor: "--cursor",
|
|
22
|
+
MaxDiagnostics: "--max-diagnostics",
|
|
23
|
+
MaxEntries: "--max-entries",
|
|
24
|
+
MaxEvidence: "--max-evidence",
|
|
25
|
+
MaxFileBytes: "--max-file-bytes",
|
|
26
|
+
MaxManifestBytes: "--max-manifest-bytes",
|
|
27
|
+
MaxOutputBytes: "--max-output-bytes",
|
|
28
|
+
MaxTotalBytes: "--max-total-bytes",
|
|
29
|
+
NoColor: "--no-color",
|
|
30
|
+
Path: "--path",
|
|
31
|
+
PathsStdin: "--paths-stdin",
|
|
32
|
+
Repository: "--repository",
|
|
33
|
+
Version: "--version"
|
|
34
|
+
};
|
|
35
|
+
var DEFAULT_MOLDEA_CLI_RESOURCE_LIMITS = Object.freeze({
|
|
36
|
+
maxDiagnostics: 1e4,
|
|
37
|
+
maxEntries: 1e5,
|
|
38
|
+
maxEvidence: 1e4,
|
|
39
|
+
maxFileBytes: 8388608,
|
|
40
|
+
maxManifestBytes: 2097152,
|
|
41
|
+
maxTotalBytes: 134217728
|
|
42
|
+
});
|
|
43
|
+
var MOLDEA_CLI_DEFAULT_OUTPUT_BYTES = 65536;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/output-page/exception.ts
|
|
46
|
+
/** Represents a safe pagination or output-budget failure owned by the CLI. */
|
|
47
|
+
var MoldeaCliOutputPageException = class extends Error {
|
|
48
|
+
code;
|
|
49
|
+
/** Creates one output-page failure with a stable public code. */
|
|
50
|
+
constructor(code) {
|
|
51
|
+
super(code);
|
|
52
|
+
this.code = code;
|
|
53
|
+
this.name = "MoldeaCliOutputPageException";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/json-serialization/serializer.ts
|
|
58
|
+
/** Compares strings by Unicode code point rather than UTF-16 code unit. */
|
|
59
|
+
var compareUnicodeCodePoints = (left, right) => {
|
|
60
|
+
const leftCodePoints = [...left];
|
|
61
|
+
const rightCodePoints = [...right];
|
|
62
|
+
const sharedLength = Math.min(leftCodePoints.length, rightCodePoints.length);
|
|
63
|
+
for (let index = 0; index < sharedLength; index += 1) {
|
|
64
|
+
const leftCodePoint = leftCodePoints[index]?.codePointAt(0);
|
|
65
|
+
const rightCodePoint = rightCodePoints[index]?.codePointAt(0);
|
|
66
|
+
if (leftCodePoint === void 0 || rightCodePoint === void 0) throw new TypeError("The JSON object key could not be compared.");
|
|
67
|
+
if (leftCodePoint !== rightCodePoint) return leftCodePoint - rightCodePoint;
|
|
68
|
+
}
|
|
69
|
+
return leftCodePoints.length - rightCodePoints.length;
|
|
70
|
+
};
|
|
71
|
+
/** Serializes one validated JSON value with recursively sorted object keys. */
|
|
72
|
+
var serializeJsonValue = (value, ancestors) => {
|
|
73
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
74
|
+
if (typeof value === "number") {
|
|
75
|
+
if (!Number.isFinite(value)) throw new TypeError("The JSON number must be finite.");
|
|
76
|
+
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
77
|
+
}
|
|
78
|
+
if (typeof value !== "object") throw new TypeError("The value is not supported by the CLI JSON contract.");
|
|
79
|
+
if (ancestors.has(value)) throw new TypeError("The CLI JSON value must not contain a cycle.");
|
|
80
|
+
ancestors.add(value);
|
|
81
|
+
try {
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
const serializedEntries = [];
|
|
84
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
85
|
+
if (!Object.hasOwn(value, index)) throw new TypeError("The CLI JSON array must not contain empty slots.");
|
|
86
|
+
serializedEntries.push(serializeJsonValue(value[index], ancestors));
|
|
87
|
+
}
|
|
88
|
+
return `[${serializedEntries.join(",")}]`;
|
|
89
|
+
}
|
|
90
|
+
const prototype = Object.getPrototypeOf(value);
|
|
91
|
+
if (prototype !== Object.prototype && prototype !== null) throw new TypeError("The CLI JSON object must be a plain record.");
|
|
92
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw new TypeError("The CLI JSON object must not contain symbol keys.");
|
|
93
|
+
const record = value;
|
|
94
|
+
return `{${Object.keys(record).sort(compareUnicodeCodePoints).map((key) => `${JSON.stringify(key)}:${serializeJsonValue(record[key], ancestors)}`).join(",")}}`;
|
|
95
|
+
} finally {
|
|
96
|
+
ancestors.delete(value);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Serializes one CLI JSON value with exact recursive Unicode code-point key ordering.
|
|
101
|
+
* @param value The closed JSON value to serialize.
|
|
102
|
+
* @returns Compact deterministic JSON without a trailing line feed.
|
|
103
|
+
* @throws
|
|
104
|
+
* - If the value contains unsupported, non-finite, symbolic, class-backed, or cyclic data
|
|
105
|
+
*/
|
|
106
|
+
var serializeJsonDeterministically = (value) => {
|
|
107
|
+
return serializeJsonValue(value, /* @__PURE__ */ new Set());
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/output-page/cursor.ts
|
|
111
|
+
var SHA256_PATTERN = /^sha256:[0-9a-f]{64}$/u;
|
|
112
|
+
var BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/u;
|
|
113
|
+
var CURSOR_DOCUMENT_KEYS = Object.freeze([
|
|
114
|
+
"checksum",
|
|
115
|
+
"command",
|
|
116
|
+
"filtersDigest",
|
|
117
|
+
"lastKey",
|
|
118
|
+
"snapshotDigest",
|
|
119
|
+
"sourceCursor",
|
|
120
|
+
"version"
|
|
121
|
+
]);
|
|
122
|
+
/** Calculates one stable SHA-256 identifier for deterministic JSON text. */
|
|
123
|
+
var calculateMoldeaCliJsonDigest = (value) => {
|
|
124
|
+
return `sha256:${createHash("sha256").update(serializeJsonDeterministically(value), "utf8").digest("hex")}`;
|
|
125
|
+
};
|
|
126
|
+
/** Calculates the checksum for one cursor payload without its checksum field. */
|
|
127
|
+
var calculateCursorChecksum = (payload) => {
|
|
128
|
+
return calculateMoldeaCliJsonDigest(payload);
|
|
129
|
+
};
|
|
130
|
+
/** Compares fixed-format checksums without data-dependent early termination. */
|
|
131
|
+
var areChecksumsEqual = (left, right) => {
|
|
132
|
+
const leftBytes = Buffer.from(left, "utf8");
|
|
133
|
+
const rightBytes = Buffer.from(right, "utf8");
|
|
134
|
+
return leftBytes.length === rightBytes.length && timingSafeEqual(leftBytes, rightBytes);
|
|
135
|
+
};
|
|
136
|
+
/** Determines whether an unknown value is one strict cursor document. */
|
|
137
|
+
var isCursorDocument = (value) => {
|
|
138
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
139
|
+
const record = value;
|
|
140
|
+
const keys = Object.keys(record).sort();
|
|
141
|
+
return keys.length === CURSOR_DOCUMENT_KEYS.length && keys.every((key, index) => key === CURSOR_DOCUMENT_KEYS[index]) && record["version"] === 2 && (record["command"] === "content" || record["command"] === "inspect" || record["command"] === "scope" || record["command"] === "validate") && typeof record["filtersDigest"] === "string" && SHA256_PATTERN.test(record["filtersDigest"]) && typeof record["lastKey"] === "string" && record["lastKey"].length > 0 && (record["sourceCursor"] === null || typeof record["sourceCursor"] === "string") && typeof record["snapshotDigest"] === "string" && SHA256_PATTERN.test(record["snapshotDigest"]) && typeof record["checksum"] === "string" && SHA256_PATTERN.test(record["checksum"]);
|
|
142
|
+
};
|
|
143
|
+
/** Encodes one command-, filter-, and snapshot-bound continuation cursor. */
|
|
144
|
+
var encodeMoldeaCliCursor = (command, filters, snapshotDigest, lastKey, sourceCursor = null) => {
|
|
145
|
+
const payload = {
|
|
146
|
+
command,
|
|
147
|
+
filtersDigest: calculateMoldeaCliJsonDigest(filters),
|
|
148
|
+
lastKey,
|
|
149
|
+
sourceCursor,
|
|
150
|
+
snapshotDigest,
|
|
151
|
+
version: 2
|
|
152
|
+
};
|
|
153
|
+
const document = {
|
|
154
|
+
...payload,
|
|
155
|
+
checksum: calculateCursorChecksum(payload)
|
|
156
|
+
};
|
|
157
|
+
return Buffer.from(serializeJsonDeterministically(document), "utf8").toString("base64url");
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Decodes and validates one opaque continuation cursor.
|
|
161
|
+
* @param input The current command state and untrusted cursor.
|
|
162
|
+
* @returns The validated last composite record key.
|
|
163
|
+
* @throws
|
|
164
|
+
* - CURSOR_INVALID: The continuation cursor is invalid for this request.
|
|
165
|
+
* - CURSOR_SNAPSHOT_CHANGED: The continuation cursor belongs to a different repository snapshot.
|
|
166
|
+
*/
|
|
167
|
+
var decodeMoldeaCliCursor = (input) => {
|
|
168
|
+
let decoded;
|
|
169
|
+
try {
|
|
170
|
+
if (!BASE64URL_PATTERN.test(input.cursor)) throw new TypeError("The cursor is not canonical base64url.");
|
|
171
|
+
const bytes = Buffer.from(input.cursor, "base64url");
|
|
172
|
+
if (bytes.toString("base64url") !== input.cursor) throw new TypeError("The cursor is not canonical base64url.");
|
|
173
|
+
const text = bytes.toString("utf8");
|
|
174
|
+
decoded = JSON.parse(text);
|
|
175
|
+
} catch {
|
|
176
|
+
throw new MoldeaCliOutputPageException("CURSOR_INVALID");
|
|
177
|
+
}
|
|
178
|
+
if (!isCursorDocument(decoded)) throw new MoldeaCliOutputPageException("CURSOR_INVALID");
|
|
179
|
+
const { checksum, ...payload } = decoded;
|
|
180
|
+
if (!areChecksumsEqual(checksum, calculateCursorChecksum(payload)) || decoded.command !== input.command || decoded.filtersDigest !== calculateMoldeaCliJsonDigest(input.filters)) throw new MoldeaCliOutputPageException("CURSOR_INVALID");
|
|
181
|
+
if (input.snapshotDigest !== void 0 && decoded.snapshotDigest !== input.snapshotDigest) throw new MoldeaCliOutputPageException("CURSOR_SNAPSHOT_CHANGED");
|
|
182
|
+
return Object.freeze({
|
|
183
|
+
lastKey: decoded.lastKey,
|
|
184
|
+
snapshotDigest: decoded.snapshotDigest,
|
|
185
|
+
sourceCursor: decoded.sourceCursor
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/output-page/page.ts
|
|
190
|
+
/** Ensures records have unique keys in strict ascending order. */
|
|
191
|
+
var assertRecordOrder = (records) => {
|
|
192
|
+
for (let index = 0; index < records.length; index += 1) {
|
|
193
|
+
const key = records[index]?.key;
|
|
194
|
+
const previousKey = records[index - 1]?.key;
|
|
195
|
+
if (key === void 0 || key.length === 0 || previousKey !== void 0 && key <= previousKey) throw new TypeError("Output records must have unique keys in ascending order.");
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Selects the largest exact serialized output page that fits its byte budget.
|
|
200
|
+
* @param input Ordered records, continuation state, and an exact final-document measurement.
|
|
201
|
+
* @returns A frozen record page with a snapshot-bound continuation cursor when needed.
|
|
202
|
+
* @throws
|
|
203
|
+
* - CURSOR_INVALID: The continuation cursor is invalid for this request.
|
|
204
|
+
* - CURSOR_SNAPSHOT_CHANGED: The continuation cursor belongs to a different repository snapshot.
|
|
205
|
+
* - OUTPUT_BUDGET_TOO_SMALL: The output byte budget cannot contain the next complete result.
|
|
206
|
+
*/
|
|
207
|
+
var createMoldeaCliOutputPage = (input) => {
|
|
208
|
+
assertRecordOrder(input.records);
|
|
209
|
+
const cursorState = input.cursor === null ? null : decodeMoldeaCliCursor({
|
|
210
|
+
command: input.command,
|
|
211
|
+
cursor: input.cursor,
|
|
212
|
+
filters: input.filters,
|
|
213
|
+
snapshotDigest: input.snapshotDigest
|
|
214
|
+
});
|
|
215
|
+
const startIndex = cursorState === null ? 0 : cursorState.sourceCursor !== null ? 0 : input.records.findIndex(({ key }) => key === cursorState.lastKey) + 1;
|
|
216
|
+
if (cursorState !== null && cursorState.sourceCursor === null && startIndex === 0) throw new MoldeaCliOutputPageException("CURSOR_INVALID");
|
|
217
|
+
const emptyRecords = Object.freeze([]);
|
|
218
|
+
const emptyPage = Object.freeze({
|
|
219
|
+
cursor: null,
|
|
220
|
+
records: emptyRecords
|
|
221
|
+
});
|
|
222
|
+
if (startIndex === input.records.length) {
|
|
223
|
+
if (input.measure(emptyPage, 2) > input.maxOutputBytes) throw new MoldeaCliOutputPageException("OUTPUT_BUDGET_TOO_SMALL");
|
|
224
|
+
return emptyPage;
|
|
225
|
+
}
|
|
226
|
+
const selectedRecords = [];
|
|
227
|
+
let selectedCursor = null;
|
|
228
|
+
let serializedRecordsUtf8Bytes = 2;
|
|
229
|
+
for (let endIndex = startIndex + 1; endIndex <= input.records.length; endIndex += 1) {
|
|
230
|
+
const record = input.records[endIndex - 1];
|
|
231
|
+
if (record === void 0) throw new TypeError("An output page record is missing.");
|
|
232
|
+
const serializedRecordUtf8Bytes = Buffer.byteLength(serializeJsonDeterministically(record), "utf8");
|
|
233
|
+
serializedRecordsUtf8Bytes += serializedRecordUtf8Bytes + (endIndex > startIndex + 1 ? 1 : 0);
|
|
234
|
+
selectedRecords.push(record);
|
|
235
|
+
const sourceCursor = input.sourceCursorForRecord?.(record) ?? null;
|
|
236
|
+
const cursor = (input.sourceCursorForRecord === void 0 ? endIndex < input.records.length : sourceCursor !== null) ? encodeMoldeaCliCursor(input.command, input.filters, input.snapshotDigest, record.key, sourceCursor) : null;
|
|
237
|
+
const candidate = Object.freeze({
|
|
238
|
+
cursor,
|
|
239
|
+
records: selectedRecords
|
|
240
|
+
});
|
|
241
|
+
if (input.measure(candidate, serializedRecordsUtf8Bytes) > input.maxOutputBytes) {
|
|
242
|
+
selectedRecords.pop();
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
selectedCursor = cursor;
|
|
246
|
+
}
|
|
247
|
+
if (selectedRecords.length === 0) throw new MoldeaCliOutputPageException("OUTPUT_BUDGET_TOO_SMALL");
|
|
248
|
+
return Object.freeze({
|
|
249
|
+
cursor: selectedCursor,
|
|
250
|
+
records: Object.freeze([...selectedRecords])
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/command-line/validations.ts
|
|
255
|
+
var POSITIVE_INTEGER_PATTERN = /^\d+$/u;
|
|
256
|
+
/**
|
|
257
|
+
* Determines whether text contains only Unicode scalar values.
|
|
258
|
+
* @param text The text to validate.
|
|
259
|
+
* @returns Whether the text contains no unpaired UTF-16 surrogate.
|
|
260
|
+
*/
|
|
261
|
+
var hasOnlyUnicodeScalarValues = (text) => {
|
|
262
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
263
|
+
const codeUnit = text.charCodeAt(index);
|
|
264
|
+
if (codeUnit >= 55296 && codeUnit <= 56319) {
|
|
265
|
+
if (index + 1 >= text.length) return false;
|
|
266
|
+
const trailingCodeUnit = text.charCodeAt(index + 1);
|
|
267
|
+
if (trailingCodeUnit < 56320 || trailingCodeUnit > 57343) return false;
|
|
268
|
+
index += 1;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (codeUnit >= 56320 && codeUnit <= 57343) return false;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Parses one strict base-10 positive safe integer option value.
|
|
277
|
+
* @param input The untrusted command-line token.
|
|
278
|
+
* @returns The parsed integer, or null when the token is invalid.
|
|
279
|
+
*/
|
|
280
|
+
var parsePositiveSafeInteger = (input) => {
|
|
281
|
+
if (!POSITIVE_INTEGER_PATTERN.test(input)) return null;
|
|
282
|
+
const parsedInteger = Number(input);
|
|
283
|
+
return Number.isSafeInteger(parsedInteger) && parsedInteger > 0 ? parsedInteger : null;
|
|
284
|
+
};
|
|
285
|
+
/** Parses one output byte budget inside the schema 6 transport bounds. */
|
|
286
|
+
var parseMoldeaCliOutputByteLimit = (input) => {
|
|
287
|
+
const parsed = parsePositiveSafeInteger(input);
|
|
288
|
+
return parsed !== null && parsed >= 4096 && parsed <= 1048576 ? parsed : null;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Validates the cross-limit ordering required by the CLI composition.
|
|
292
|
+
* @param limits The effective resource limits.
|
|
293
|
+
* @returns Whether manifest, file, and total byte limits are consistently ordered.
|
|
294
|
+
*/
|
|
295
|
+
var areMoldeaCliResourceLimitsConsistent = (limits) => {
|
|
296
|
+
return limits.maxManifestBytes <= limits.maxFileBytes && limits.maxFileBytes <= limits.maxTotalBytes;
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Determines whether one repository option is safe scalar host-path text.
|
|
300
|
+
* @param input The untrusted command-line token.
|
|
301
|
+
* @returns Whether the token is non-empty scalar text without NUL.
|
|
302
|
+
*/
|
|
303
|
+
var isRepositoryDirectoryInputValid = (input) => {
|
|
304
|
+
return input.length > 0 && !input.includes("\0") && hasOnlyUnicodeScalarValues(input);
|
|
305
|
+
};
|
|
306
|
+
/** Determines whether one opaque cursor token is bounded safe scalar text. */
|
|
307
|
+
var isMoldeaCliCursorInputValid = (input) => {
|
|
308
|
+
return input.length > 0 && input.length <= 16384 && !input.includes("\0") && hasOnlyUnicodeScalarValues(input);
|
|
309
|
+
};
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/command-line/parser.ts
|
|
312
|
+
var COMMAND_NAMES = new Set(Object.values(MOLDEA_CLI_COMMANDS));
|
|
313
|
+
var RESOURCE_OPTION_FIELDS = {
|
|
314
|
+
[MOLDEA_CLI_OPTIONS.MaxDiagnostics]: "maxDiagnostics",
|
|
315
|
+
[MOLDEA_CLI_OPTIONS.MaxEntries]: "maxEntries",
|
|
316
|
+
[MOLDEA_CLI_OPTIONS.MaxEvidence]: "maxEvidence",
|
|
317
|
+
[MOLDEA_CLI_OPTIONS.MaxFileBytes]: "maxFileBytes",
|
|
318
|
+
[MOLDEA_CLI_OPTIONS.MaxManifestBytes]: "maxManifestBytes",
|
|
319
|
+
[MOLDEA_CLI_OPTIONS.MaxTotalBytes]: "maxTotalBytes"
|
|
320
|
+
};
|
|
321
|
+
var createArgumentError = (code, command, isJson) => ({
|
|
322
|
+
code,
|
|
323
|
+
command,
|
|
324
|
+
isJson,
|
|
325
|
+
kind: "error"
|
|
326
|
+
});
|
|
327
|
+
var isMoldeaCliCommand = (input) => {
|
|
328
|
+
return input !== void 0 && COMMAND_NAMES.has(input);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Parses the complete schema 6 command grammar without mutating caller arguments.
|
|
332
|
+
* @param commandLineArguments The process arguments after the executable path.
|
|
333
|
+
* @returns A normalized command, informational request, or safe invocation error.
|
|
334
|
+
*/
|
|
335
|
+
var parseMoldeaCliArguments = (commandLineArguments) => {
|
|
336
|
+
const isJson = commandLineArguments.includes(MOLDEA_CLI_OPTIONS.Json);
|
|
337
|
+
if (commandLineArguments.length === 0) return {
|
|
338
|
+
command: null,
|
|
339
|
+
kind: "help"
|
|
340
|
+
};
|
|
341
|
+
const firstArgument = commandLineArguments[0];
|
|
342
|
+
if (firstArgument === MOLDEA_CLI_OPTIONS.Help) return commandLineArguments.length === 1 ? {
|
|
343
|
+
command: null,
|
|
344
|
+
kind: "help"
|
|
345
|
+
} : createArgumentError("INVALID_ARGUMENT", null, isJson);
|
|
346
|
+
if (firstArgument === MOLDEA_CLI_OPTIONS.Version) return commandLineArguments.length === 1 ? { kind: "version" } : createArgumentError("INVALID_ARGUMENT", null, isJson);
|
|
347
|
+
const command = isMoldeaCliCommand(firstArgument) ? firstArgument : null;
|
|
348
|
+
if (command === null) return createArgumentError("INVALID_ARGUMENT", null, isJson);
|
|
349
|
+
if (commandLineArguments.length === 2 && commandLineArguments[1] === MOLDEA_CLI_OPTIONS.Help) return {
|
|
350
|
+
command,
|
|
351
|
+
kind: "help"
|
|
352
|
+
};
|
|
353
|
+
const seenOptions = /* @__PURE__ */ new Set();
|
|
354
|
+
const resourceLimits = { ...DEFAULT_MOLDEA_CLI_RESOURCE_LIMITS };
|
|
355
|
+
let isColorDisabled = false;
|
|
356
|
+
let cursor = null;
|
|
357
|
+
let maxOutputBytes = MOLDEA_CLI_DEFAULT_OUTPUT_BYTES;
|
|
358
|
+
let path = null;
|
|
359
|
+
let pathsInput = "none";
|
|
360
|
+
let repositoryDirectory = null;
|
|
361
|
+
for (let index = 1; index < commandLineArguments.length; index += 1) {
|
|
362
|
+
const option = commandLineArguments[index];
|
|
363
|
+
if (option === void 0 || seenOptions.has(option)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
364
|
+
seenOptions.add(option);
|
|
365
|
+
if (option === MOLDEA_CLI_OPTIONS.Json) continue;
|
|
366
|
+
if (option === MOLDEA_CLI_OPTIONS.NoColor) {
|
|
367
|
+
isColorDisabled = true;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (option === MOLDEA_CLI_OPTIONS.PathsStdin) {
|
|
371
|
+
pathsInput = "stdin";
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (option === MOLDEA_CLI_OPTIONS.Help || option === MOLDEA_CLI_OPTIONS.Version) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
375
|
+
const resourceField = RESOURCE_OPTION_FIELDS[option];
|
|
376
|
+
const isRepositoryOption = option === MOLDEA_CLI_OPTIONS.Repository;
|
|
377
|
+
const isCursorOption = option === MOLDEA_CLI_OPTIONS.Cursor;
|
|
378
|
+
const isOutputLimitOption = option === MOLDEA_CLI_OPTIONS.MaxOutputBytes;
|
|
379
|
+
const isPathOption = option === MOLDEA_CLI_OPTIONS.Path;
|
|
380
|
+
if (resourceField === void 0 && !isRepositoryOption && !isCursorOption && !isOutputLimitOption && !isPathOption) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
381
|
+
if (command === MOLDEA_CLI_COMMANDS.Composition) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
382
|
+
const optionValue = commandLineArguments[index + 1];
|
|
383
|
+
if (optionValue === void 0 || optionValue.startsWith("--")) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
384
|
+
index += 1;
|
|
385
|
+
if (isCursorOption) {
|
|
386
|
+
if (!isMoldeaCliCursorInputValid(optionValue)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
387
|
+
cursor = optionValue;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (isOutputLimitOption) {
|
|
391
|
+
const parsedOutputLimit = parseMoldeaCliOutputByteLimit(optionValue);
|
|
392
|
+
if (parsedOutputLimit === null) return createArgumentError("RESOURCE_LIMIT_CONFIGURATION_INVALID", command, isJson);
|
|
393
|
+
maxOutputBytes = parsedOutputLimit;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (isPathOption) {
|
|
397
|
+
if (!isRepositoryDirectoryInputValid(optionValue)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
398
|
+
path = optionValue;
|
|
399
|
+
pathsInput = "path";
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (isRepositoryOption) {
|
|
403
|
+
if (!isRepositoryDirectoryInputValid(optionValue)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
404
|
+
repositoryDirectory = optionValue;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const parsedLimit = parsePositiveSafeInteger(optionValue);
|
|
408
|
+
if (parsedLimit === null || resourceField === void 0) return createArgumentError("RESOURCE_LIMIT_CONFIGURATION_INVALID", command, isJson);
|
|
409
|
+
resourceLimits[resourceField] = parsedLimit;
|
|
410
|
+
}
|
|
411
|
+
if (!areMoldeaCliResourceLimitsConsistent(resourceLimits)) return createArgumentError("RESOURCE_LIMIT_CONFIGURATION_INVALID", command, isJson);
|
|
412
|
+
const isScope = command === MOLDEA_CLI_COMMANDS.Scope;
|
|
413
|
+
const isContent = command === MOLDEA_CLI_COMMANDS.Content;
|
|
414
|
+
const hasPathInput = path !== null;
|
|
415
|
+
const hasStdinInput = seenOptions.has(MOLDEA_CLI_OPTIONS.PathsStdin);
|
|
416
|
+
if ((hasPathInput || hasStdinInput) && !isScope && !isContent) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
417
|
+
if (isScope && hasPathInput === hasStdinInput) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
418
|
+
if (isContent && (!hasPathInput || hasStdinInput)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
419
|
+
if (isScope && seenOptions.has(MOLDEA_CLI_OPTIONS.MaxEvidence)) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
420
|
+
if (isContent && [
|
|
421
|
+
MOLDEA_CLI_OPTIONS.MaxDiagnostics,
|
|
422
|
+
MOLDEA_CLI_OPTIONS.MaxEvidence,
|
|
423
|
+
MOLDEA_CLI_OPTIONS.MaxManifestBytes
|
|
424
|
+
].some((option) => seenOptions.has(option))) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
425
|
+
if (!isJson && (cursor !== null || seenOptions.has(MOLDEA_CLI_OPTIONS.MaxOutputBytes))) return createArgumentError("INVALID_ARGUMENT", command, isJson);
|
|
426
|
+
const options = {
|
|
427
|
+
cursor,
|
|
428
|
+
isColorDisabled,
|
|
429
|
+
isJson,
|
|
430
|
+
maxOutputBytes,
|
|
431
|
+
path,
|
|
432
|
+
pathsInput,
|
|
433
|
+
repositoryDirectory,
|
|
434
|
+
resourceLimits: Object.freeze({ ...resourceLimits })
|
|
435
|
+
};
|
|
436
|
+
return {
|
|
437
|
+
invocation: Object.freeze({
|
|
438
|
+
command,
|
|
439
|
+
options: Object.freeze(options)
|
|
440
|
+
}),
|
|
441
|
+
kind: "command"
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/presentation/constants.ts
|
|
446
|
+
var MOLDEA_CLI_ERROR_DEFINITIONS = Object.freeze({
|
|
447
|
+
COMPOSITION_STATE_INVALID: Object.freeze({
|
|
448
|
+
message: "The installed composition state is invalid.",
|
|
449
|
+
retryable: false,
|
|
450
|
+
source: "cli"
|
|
451
|
+
}),
|
|
452
|
+
CONTENT_INVALID: Object.freeze({
|
|
453
|
+
message: "The requested canonical asset is not valid moldea text.",
|
|
454
|
+
retryable: false,
|
|
455
|
+
source: "cli"
|
|
456
|
+
}),
|
|
457
|
+
CONTENT_PATH_INVALID: Object.freeze({
|
|
458
|
+
message: "The content path must identify one canonical moldea text asset.",
|
|
459
|
+
retryable: false,
|
|
460
|
+
source: "cli"
|
|
461
|
+
}),
|
|
462
|
+
CURSOR_INVALID: Object.freeze({
|
|
463
|
+
message: "The continuation cursor is invalid for this request.",
|
|
464
|
+
retryable: false,
|
|
465
|
+
source: "cli"
|
|
466
|
+
}),
|
|
467
|
+
CURSOR_SNAPSHOT_CHANGED: Object.freeze({
|
|
468
|
+
message: "The continuation cursor belongs to a different repository snapshot.",
|
|
469
|
+
retryable: true,
|
|
470
|
+
source: "cli"
|
|
471
|
+
}),
|
|
472
|
+
GIT_ACCESS_DENIED: Object.freeze({
|
|
473
|
+
message: "Git access was denied.",
|
|
474
|
+
retryable: true,
|
|
475
|
+
source: "git"
|
|
476
|
+
}),
|
|
477
|
+
GIT_COMMAND_FAILED: Object.freeze({
|
|
478
|
+
message: "The Git command failed.",
|
|
479
|
+
retryable: true,
|
|
480
|
+
source: "git"
|
|
481
|
+
}),
|
|
482
|
+
GIT_CONTENT_TRANSFORM_UNSUPPORTED: Object.freeze({
|
|
483
|
+
message: "The requested file uses an unsupported Git content transformation.",
|
|
484
|
+
retryable: false,
|
|
485
|
+
source: "git"
|
|
486
|
+
}),
|
|
487
|
+
GIT_NOT_FOUND: Object.freeze({
|
|
488
|
+
message: "The Git executable is unavailable.",
|
|
489
|
+
retryable: false,
|
|
490
|
+
source: "git"
|
|
491
|
+
}),
|
|
492
|
+
GIT_OPERATION_ABORTED: Object.freeze({
|
|
493
|
+
message: "The Git operation was aborted.",
|
|
494
|
+
retryable: true,
|
|
495
|
+
source: "git"
|
|
496
|
+
}),
|
|
497
|
+
GIT_OUTPUT_INVALID: Object.freeze({
|
|
498
|
+
message: "Git returned invalid output.",
|
|
499
|
+
retryable: false,
|
|
500
|
+
source: "git"
|
|
501
|
+
}),
|
|
502
|
+
GIT_REPOSITORY_NOT_FOUND: Object.freeze({
|
|
503
|
+
message: "The selected path is not inside a Git repository.",
|
|
504
|
+
retryable: false,
|
|
505
|
+
source: "git"
|
|
506
|
+
}),
|
|
507
|
+
GIT_SPARSE_CHECKOUT_UNSUPPORTED: Object.freeze({
|
|
508
|
+
message: "Sparse Git checkouts are unsupported.",
|
|
509
|
+
retryable: false,
|
|
510
|
+
source: "git"
|
|
511
|
+
}),
|
|
512
|
+
GIT_VERSION_INVALID: Object.freeze({
|
|
513
|
+
message: "The Git version output is invalid.",
|
|
514
|
+
retryable: false,
|
|
515
|
+
source: "git"
|
|
516
|
+
}),
|
|
517
|
+
GIT_VERSION_UNSUPPORTED: Object.freeze({
|
|
518
|
+
message: "The installed Git version is unsupported.",
|
|
519
|
+
retryable: false,
|
|
520
|
+
source: "git"
|
|
521
|
+
}),
|
|
522
|
+
GIT_WORK_TREE_REQUIRED: Object.freeze({
|
|
523
|
+
message: "A usable Git working tree is required.",
|
|
524
|
+
retryable: false,
|
|
525
|
+
source: "git"
|
|
526
|
+
}),
|
|
527
|
+
INTERNAL_ERROR: Object.freeze({
|
|
528
|
+
message: "The command could not be completed.",
|
|
529
|
+
retryable: false,
|
|
530
|
+
source: "cli"
|
|
531
|
+
}),
|
|
532
|
+
INVALID_ARGUMENT: Object.freeze({
|
|
533
|
+
message: "The command invocation is invalid.",
|
|
534
|
+
retryable: false,
|
|
535
|
+
source: "cli"
|
|
536
|
+
}),
|
|
537
|
+
OUTPUT_BUDGET_TOO_SMALL: Object.freeze({
|
|
538
|
+
message: "The output byte budget cannot contain the next complete result.",
|
|
539
|
+
retryable: false,
|
|
540
|
+
source: "cli"
|
|
541
|
+
}),
|
|
542
|
+
PATH_INPUT_INVALID: Object.freeze({
|
|
543
|
+
message: "The scope path input is invalid. Use leading-slash repository-logical paths and NUL-delimited UTF-8 on stdin.",
|
|
544
|
+
retryable: false,
|
|
545
|
+
source: "cli"
|
|
546
|
+
}),
|
|
547
|
+
RESOURCE_LIMIT_CONFIGURATION_INVALID: Object.freeze({
|
|
548
|
+
message: "The resource-limit configuration is invalid.",
|
|
549
|
+
retryable: false,
|
|
550
|
+
source: "cli"
|
|
551
|
+
}),
|
|
552
|
+
RESOURCE_LIMIT_EXCEEDED: Object.freeze({
|
|
553
|
+
message: "A resource limit was exceeded.",
|
|
554
|
+
retryable: false,
|
|
555
|
+
source: "cli"
|
|
556
|
+
}),
|
|
557
|
+
WORKING_TREE_UNSTABLE: Object.freeze({
|
|
558
|
+
message: "The working tree did not remain stable.",
|
|
559
|
+
retryable: true,
|
|
560
|
+
source: "cli"
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
var MOLDEA_CLI_GIT_WORKING_TREE_SOURCE = Object.freeze({ kind: "git-working-tree" });
|
|
564
|
+
var MOLDEA_CLI_TOP_LEVEL_HELP = `Usage: moldea <command> [options]
|
|
565
|
+
|
|
566
|
+
Commands:
|
|
567
|
+
validate Validate the current moldea project.
|
|
568
|
+
inspect Inspect content-free project metadata.
|
|
569
|
+
scope Match changed paths to declared moldea relationships.
|
|
570
|
+
content Read one canonical moldea asset explicitly.
|
|
571
|
+
composition Report the installed CLI composition state.
|
|
572
|
+
|
|
573
|
+
Global options:
|
|
574
|
+
--help Show top-level help.
|
|
575
|
+
--version Show the CLI version.
|
|
576
|
+
|
|
577
|
+
Run "moldea <command> --help" for command-specific options.
|
|
578
|
+
`;
|
|
579
|
+
var REPOSITORY_OPTIONS_HELP = ` --repository <path> Select a Git working-tree directory.
|
|
580
|
+
--json Emit one machine-readable JSON result.
|
|
581
|
+
--no-color Disable ANSI styling in human output.
|
|
582
|
+
`;
|
|
583
|
+
var BASE_RESOURCE_OPTIONS_HELP = ` --max-entries <integer> Override the repository entry limit.
|
|
584
|
+
--max-file-bytes <integer> Override the per-file byte limit.
|
|
585
|
+
--max-total-bytes <integer> Override the total cached-byte limit.
|
|
586
|
+
`;
|
|
587
|
+
var INSPECTION_RESOURCE_OPTIONS_HELP = `${BASE_RESOURCE_OPTIONS_HELP} --max-manifest-bytes <integer> Override the manifest byte limit.
|
|
588
|
+
--max-diagnostics <integer> Override the diagnostic count limit.
|
|
589
|
+
`;
|
|
590
|
+
var PAGINATION_OPTIONS_HELP = ` --max-output-bytes <integer> Bound JSON output from 4096 to 1048576 bytes.
|
|
591
|
+
--cursor <opaque-cursor> Continue a prior JSON result page.
|
|
592
|
+
`;
|
|
593
|
+
var COMPLETE_INSPECTION_OPTIONS_HELP = `${REPOSITORY_OPTIONS_HELP}${INSPECTION_RESOURCE_OPTIONS_HELP} --max-evidence <integer> Override the adapter evidence count limit.
|
|
594
|
+
${PAGINATION_OPTIONS_HELP}`;
|
|
595
|
+
var SCOPE_OPTIONS_HELP = `${REPOSITORY_OPTIONS_HELP}${INSPECTION_RESOURCE_OPTIONS_HELP}${PAGINATION_OPTIONS_HELP}`;
|
|
596
|
+
var CONTENT_OPTIONS_HELP = `${REPOSITORY_OPTIONS_HELP}${BASE_RESOURCE_OPTIONS_HELP}${PAGINATION_OPTIONS_HELP}`;
|
|
597
|
+
var MOLDEA_CLI_COMMAND_HELP = {
|
|
598
|
+
[MOLDEA_CLI_COMMANDS.Composition]: `Usage: moldea composition [options]
|
|
599
|
+
|
|
600
|
+
Report the installed CLI composition state.
|
|
601
|
+
|
|
602
|
+
Options:
|
|
603
|
+
--json Emit one machine-readable JSON result.
|
|
604
|
+
--no-color Disable ANSI styling in human output.
|
|
605
|
+
--help Show this help.
|
|
606
|
+
`,
|
|
607
|
+
[MOLDEA_CLI_COMMANDS.Inspect]: `Usage: moldea inspect [options]
|
|
608
|
+
|
|
609
|
+
Inspect content-free metadata for the current moldea project.
|
|
610
|
+
|
|
611
|
+
Options:
|
|
612
|
+
${COMPLETE_INSPECTION_OPTIONS_HELP} --help Show this help.
|
|
613
|
+
`,
|
|
614
|
+
[MOLDEA_CLI_COMMANDS.Scope]: `Usage: moldea scope (--path <logical-path> | --paths-stdin) [options]
|
|
615
|
+
|
|
616
|
+
Match changed repository paths to declared moldea relationships. The stdin form accepts NUL-delimited UTF-8 logical paths.
|
|
617
|
+
|
|
618
|
+
Options:
|
|
619
|
+
${SCOPE_OPTIONS_HELP} --path <logical-path> Match one repository-logical path.
|
|
620
|
+
--paths-stdin Read NUL-delimited paths from stdin.
|
|
621
|
+
--help Show this help.
|
|
622
|
+
`,
|
|
623
|
+
[MOLDEA_CLI_COMMANDS.Content]: `Usage: moldea content --path <canonical-logical-path> [options]
|
|
624
|
+
|
|
625
|
+
Read one canonical moldea text asset in bounded Unicode-safe chunks.
|
|
626
|
+
|
|
627
|
+
Options:
|
|
628
|
+
${CONTENT_OPTIONS_HELP} --path <canonical-logical-path> Select exactly one canonical moldea file.
|
|
629
|
+
--help Show this help.
|
|
630
|
+
`,
|
|
631
|
+
[MOLDEA_CLI_COMMANDS.Validate]: `Usage: moldea validate [options]
|
|
632
|
+
|
|
633
|
+
Validate the current moldea project.
|
|
634
|
+
|
|
635
|
+
Options:
|
|
636
|
+
${COMPLETE_INSPECTION_OPTIONS_HELP} --help Show this help.
|
|
637
|
+
`
|
|
638
|
+
};
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/presentation/errors.ts
|
|
641
|
+
var EMPTY_ERROR_DETAILS = Object.freeze({});
|
|
642
|
+
/**
|
|
643
|
+
* Creates one immutable safe error from a CLI- or Git-owned definition.
|
|
644
|
+
* @param code The stable executable-owned error code.
|
|
645
|
+
* @returns The complete safe error object.
|
|
646
|
+
*/
|
|
647
|
+
var createMoldeaCliOwnedError = (code) => {
|
|
648
|
+
const definition = MOLDEA_CLI_ERROR_DEFINITIONS[code];
|
|
649
|
+
return Object.freeze({
|
|
650
|
+
code,
|
|
651
|
+
details: EMPTY_ERROR_DETAILS,
|
|
652
|
+
message: definition.message,
|
|
653
|
+
path: null,
|
|
654
|
+
retryable: definition.retryable,
|
|
655
|
+
source: definition.source
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/json-output-contract/document.ts
|
|
660
|
+
/** Creates one strict schema 6 JSON envelope. */
|
|
661
|
+
var createMoldeaCliJsonEnvelope = (input) => Object.freeze({
|
|
662
|
+
cliVersion: input.cliVersion,
|
|
663
|
+
command: input.command,
|
|
664
|
+
error: input.error,
|
|
665
|
+
result: input.result,
|
|
666
|
+
schemaVersion: 6,
|
|
667
|
+
status: input.status
|
|
668
|
+
});
|
|
669
|
+
/** Serializes one schema 6 envelope with its required trailing line feed. */
|
|
670
|
+
var serializeMoldeaCliJsonEnvelope = (input) => `${serializeJsonDeterministically(createMoldeaCliJsonEnvelope(input))}\n`;
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/presentation/formatters.ts
|
|
673
|
+
var DIAGNOSTIC_ENTITY_KEYS = [
|
|
674
|
+
"agentId",
|
|
675
|
+
"capabilityKind",
|
|
676
|
+
"capabilityId",
|
|
677
|
+
"decisionId",
|
|
678
|
+
"variableId",
|
|
679
|
+
"adapterId"
|
|
680
|
+
];
|
|
681
|
+
/** Formats one diagnostic entity in the canonical Core field order. */
|
|
682
|
+
var formatMoldeaCliHumanDiagnosticEntity = (entity) => DIAGNOSTIC_ENTITY_KEYS.flatMap((key) => {
|
|
683
|
+
const identifier = entity[key];
|
|
684
|
+
return identifier === void 0 ? [] : [`${key}=${identifier}`];
|
|
685
|
+
}).join(", ");
|
|
686
|
+
/** Formats one projected diagnostic without exposing omitted arbitrary details. */
|
|
687
|
+
var formatMoldeaCliHumanDiagnostic = (diagnostic) => {
|
|
688
|
+
const location = diagnostic.path === null ? "" : diagnostic.range === null ? ` ${diagnostic.path}` : ` ${diagnostic.path}:${diagnostic.range.start.line}:${diagnostic.range.start.column}`;
|
|
689
|
+
const lines = [`${diagnostic.source}:${diagnostic.code}${location} ${diagnostic.message}`];
|
|
690
|
+
if (diagnostic.pointer !== null) lines.push(` pointer: ${diagnostic.pointer}`);
|
|
691
|
+
if (diagnostic.entity !== null) lines.push(` entity: ${formatMoldeaCliHumanDiagnosticEntity(diagnostic.entity)}`);
|
|
692
|
+
if (diagnostic.severity === "warning") {
|
|
693
|
+
lines.push(` unverified relationship: ${diagnostic.details.relationship}`);
|
|
694
|
+
lines.push(` reason: ${diagnostic.details.reason.replaceAll("-", " ")}`);
|
|
695
|
+
if (diagnostic.details.reason === "version-dependent-behavior") {
|
|
696
|
+
lines.push(` package: ${diagnostic.details.packageName}`);
|
|
697
|
+
lines.push(` declared range: ${diagnostic.details.declaredRange ?? "unavailable"}`);
|
|
698
|
+
lines.push(` behavior boundary: ${diagnostic.details.boundaryVersion}`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return lines.join("\n");
|
|
702
|
+
};
|
|
703
|
+
/** Creates shared human status lines for one completed repository command. */
|
|
704
|
+
var createMoldeaCliHumanStatusLines = (isValid, formatVersion, warningCount = 0) => {
|
|
705
|
+
const lines = [`The moldea project is ${isValid ? warningCount > 0 ? "valid with warnings" : "valid" : "invalid"}.`];
|
|
706
|
+
if (formatVersion !== null) lines.push(`Repository format: ${formatVersion}`);
|
|
707
|
+
return lines;
|
|
708
|
+
};
|
|
709
|
+
/** Formats one count label with correct singular or plural grammar. */
|
|
710
|
+
var formatMoldeaCliHumanCount = (count, singularLabel, pluralLabel) => `${count === 1 ? singularLabel : pluralLabel}: ${count}`;
|
|
711
|
+
/** Formats top-level or command-specific help with its required trailing line feed. */
|
|
712
|
+
var formatMoldeaCliHelp = (command) => {
|
|
713
|
+
return command === null ? MOLDEA_CLI_TOP_LEVEL_HELP : MOLDEA_CLI_COMMAND_HELP[command];
|
|
714
|
+
};
|
|
715
|
+
/** Formats one safe CLI error for human stderr output. */
|
|
716
|
+
var formatMoldeaCliHumanError = (error) => `${error.source}:${error.code} ${error.message}\n`;
|
|
717
|
+
/** Formats any strict schema 6 JSON envelope. */
|
|
718
|
+
var formatMoldeaCliJsonResult = (command, result, error, status, cliVersion) => serializeMoldeaCliJsonEnvelope({
|
|
719
|
+
cliVersion,
|
|
720
|
+
command,
|
|
721
|
+
error,
|
|
722
|
+
result,
|
|
723
|
+
status
|
|
724
|
+
});
|
|
725
|
+
/** Formats one safe schema 6 JSON error envelope. */
|
|
726
|
+
var formatMoldeaCliJsonError = (error, command, cliVersion) => formatMoldeaCliJsonResult(command, null, error, "error", cliVersion);
|
|
727
|
+
/** Formats one valid composition result for human stdout. */
|
|
728
|
+
var formatMoldeaCliHumanCompositionResult = (result, cliVersion) => {
|
|
729
|
+
return `${[
|
|
730
|
+
"The installed CLI composition state is valid.",
|
|
731
|
+
`CLI version: ${cliVersion}`,
|
|
732
|
+
`Supported Node.js: ${result.supportedNodeRange}`,
|
|
733
|
+
`JSON output schema: 6`,
|
|
734
|
+
`Minimum Git: ${result.minimumGitVersion}`,
|
|
735
|
+
`Repository formats: ${result.repositoryFormatVersions.join(", ")}`,
|
|
736
|
+
"Packages:",
|
|
737
|
+
...result.packages.map(({ name, version }) => ` ${name}: ${version}`),
|
|
738
|
+
"Adapters:",
|
|
739
|
+
...result.adapters.map(({ id, repositoryFormatVersions }) => ` ${id}: repository formats ${repositoryFormatVersions.join(", ")}`)
|
|
740
|
+
].join("\n")}\n`;
|
|
741
|
+
};
|
|
742
|
+
/** Formats one composition result in the strict schema 6 envelope. */
|
|
743
|
+
var formatMoldeaCliJsonCompositionResult = (result, cliVersion) => formatMoldeaCliJsonResult(MOLDEA_CLI_COMMANDS.Composition, result, null, "valid", cliVersion);
|
|
744
|
+
/** Formats one completed validation result for human stdout. */
|
|
745
|
+
var formatMoldeaCliHumanValidateResult = (result) => {
|
|
746
|
+
const lines = createMoldeaCliHumanStatusLines(result.valid, result.formatVersion, result.warningCount);
|
|
747
|
+
lines.push(`Runtime inspection: ${result.runtimeInspection}`);
|
|
748
|
+
for (const diagnostic of result.page.records) lines.push(formatMoldeaCliHumanDiagnostic(diagnostic));
|
|
749
|
+
lines.push(formatMoldeaCliHumanCount(result.diagnosticCount, "Diagnostic", "Diagnostics"));
|
|
750
|
+
lines.push(formatMoldeaCliHumanCount(result.errorCount, "Error", "Errors"));
|
|
751
|
+
lines.push(formatMoldeaCliHumanCount(result.warningCount, "Warning", "Warnings"));
|
|
752
|
+
if (result.page.cursor !== null) lines.push("Additional diagnostics are available through JSON pagination.");
|
|
753
|
+
return `${lines.join("\n")}\n`;
|
|
754
|
+
};
|
|
755
|
+
/** Formats one validation result in the strict schema 6 envelope. */
|
|
756
|
+
var formatMoldeaCliJsonValidateResult = (result, cliVersion) => formatMoldeaCliJsonResult(MOLDEA_CLI_COMMANDS.Validate, result, null, result.valid ? "valid" : "invalid", cliVersion);
|
|
757
|
+
/** Formats one completed metadata inspection for human stdout. */
|
|
758
|
+
var formatMoldeaCliHumanInspectResult = (result) => {
|
|
759
|
+
const lines = createMoldeaCliHumanStatusLines(result.valid, result.formatVersion, result.counts.warnings);
|
|
760
|
+
lines.push(`Runtime inspection: ${result.runtimeInspection}`);
|
|
761
|
+
for (const [label, count] of Object.entries(result.counts)) lines.push(`${label}: ${count}`);
|
|
762
|
+
return `${lines.join("\n")}\n`;
|
|
763
|
+
};
|
|
764
|
+
/** Formats one metadata inspection in the strict schema 6 envelope. */
|
|
765
|
+
var formatMoldeaCliJsonInspectResult = (result, cliVersion) => formatMoldeaCliJsonResult(MOLDEA_CLI_COMMANDS.Inspect, result, null, result.valid ? "valid" : "invalid", cliVersion);
|
|
766
|
+
/** Formats one changed-path scope result for human stdout. */
|
|
767
|
+
var formatMoldeaCliHumanScopeResult = (result) => {
|
|
768
|
+
return `${[
|
|
769
|
+
`The moldea scope result is ${result.valid ? "valid" : "invalid"}.`,
|
|
770
|
+
`Relevant: ${result.relevant ? "yes" : "no"}`,
|
|
771
|
+
...Object.entries(result.counts).map(([label, count]) => `${label}: ${count}`)
|
|
772
|
+
].join("\n")}\n`;
|
|
773
|
+
};
|
|
774
|
+
/** Formats one changed-path scope result in the strict schema 6 envelope. */
|
|
775
|
+
var formatMoldeaCliJsonScopeResult = (result, cliVersion) => formatMoldeaCliJsonResult(MOLDEA_CLI_COMMANDS.Scope, result, null, result.valid ? "valid" : "invalid", cliVersion);
|
|
776
|
+
/** Formats one explicit canonical content chunk for human stdout. */
|
|
777
|
+
var formatMoldeaCliHumanContentResult = (result) => {
|
|
778
|
+
return `${[
|
|
779
|
+
`Path: ${result.asset.path}`,
|
|
780
|
+
`Content identity: ${result.asset.contentIdentity ?? "unavailable"}`,
|
|
781
|
+
`Bytes: ${result.chunk.byteStart}-${result.chunk.byteEnd} of ${result.asset.totalBytes}`,
|
|
782
|
+
result.cursor === null ? "Cursor: none" : `Cursor: ${result.cursor}`,
|
|
783
|
+
...result.cursor === null ? [] : ["Continue this asset by passing the cursor to a JSON content request."],
|
|
784
|
+
"",
|
|
785
|
+
result.chunk.content
|
|
786
|
+
].join("\n")}\n`;
|
|
787
|
+
};
|
|
788
|
+
/** Formats one explicit canonical content chunk in the strict schema 6 envelope. */
|
|
789
|
+
var formatMoldeaCliJsonContentResult = (result, cliVersion) => formatMoldeaCliJsonResult(MOLDEA_CLI_COMMANDS.Content, result, null, "valid", cliVersion);
|
|
790
|
+
//#endregion
|
|
791
|
+
//#region src/presentation/transformers.ts
|
|
792
|
+
/** Rejects a Core validation result whose completion fields contradict its validity. */
|
|
793
|
+
var assertProjectValidationInvariant = (validation) => {
|
|
794
|
+
const observedErrorCount = validation.diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
795
|
+
if (!(Number.isSafeInteger(validation.errorCount) && Number.isSafeInteger(validation.warningCount) && validation.errorCount === observedErrorCount && validation.warningCount === validation.diagnostics.length - observedErrorCount && validation.valid === (validation.summary !== null && validation.errorCount === 0) && (validation.valid || validation.errorCount > 0))) throw new TypeError("The Core validation result is internally inconsistent.");
|
|
796
|
+
};
|
|
797
|
+
/** Creates one stable composite record key. */
|
|
798
|
+
var createRecordKey = (kind, ...parts) => JSON.stringify([kind, ...parts]);
|
|
799
|
+
/** Projects one diagnostic without retaining arbitrary detail payloads. */
|
|
800
|
+
var createMoldeaCliDiagnosticRecord = (diagnostic, occurrence = 0) => {
|
|
801
|
+
const record = {
|
|
802
|
+
code: diagnostic.code,
|
|
803
|
+
entity: diagnostic.entity,
|
|
804
|
+
key: createRecordKey("diagnostic", diagnostic.source, diagnostic.severity, diagnostic.code, diagnostic.path, diagnostic.pointer, diagnostic.severity === "warning" ? diagnostic.details : null, occurrence),
|
|
805
|
+
kind: "diagnostic",
|
|
806
|
+
message: diagnostic.message,
|
|
807
|
+
path: diagnostic.path,
|
|
808
|
+
pointer: diagnostic.pointer,
|
|
809
|
+
range: diagnostic.range,
|
|
810
|
+
source: diagnostic.source
|
|
811
|
+
};
|
|
812
|
+
if (diagnostic.severity === "warning") {
|
|
813
|
+
const details = diagnostic.details.reason === "version-dependent-behavior" ? Object.freeze({
|
|
814
|
+
boundaryVersion: diagnostic.details.boundaryVersion,
|
|
815
|
+
declaredRange: diagnostic.details.declaredRange,
|
|
816
|
+
packageName: diagnostic.details.packageName,
|
|
817
|
+
reason: diagnostic.details.reason,
|
|
818
|
+
relationship: diagnostic.details.relationship
|
|
819
|
+
}) : Object.freeze({
|
|
820
|
+
reason: diagnostic.details.reason,
|
|
821
|
+
relationship: diagnostic.details.relationship
|
|
822
|
+
});
|
|
823
|
+
return Object.freeze({
|
|
824
|
+
...record,
|
|
825
|
+
details,
|
|
826
|
+
severity: "warning"
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
return Object.freeze({
|
|
830
|
+
...record,
|
|
831
|
+
severity: "error"
|
|
832
|
+
});
|
|
833
|
+
};
|
|
834
|
+
/** Projects one bounded Core inspection item through the schema 6 allowlist. */
|
|
835
|
+
var createInspectRecord = (item, index) => {
|
|
836
|
+
const order = index.toString().padStart(6, "0");
|
|
837
|
+
if (item.kind === "agent") {
|
|
838
|
+
const record = {
|
|
839
|
+
agentId: item.agent.agentId,
|
|
840
|
+
key: createRecordKey(order, "agent", item.agent.agentId, item.agent.runtimeId),
|
|
841
|
+
kind: "agent",
|
|
842
|
+
runtimeId: item.agent.runtimeId
|
|
843
|
+
};
|
|
844
|
+
return Object.freeze(record);
|
|
845
|
+
}
|
|
846
|
+
if (item.kind === "diagnostic") return Object.freeze({
|
|
847
|
+
...createMoldeaCliDiagnosticRecord(item.diagnostic, index),
|
|
848
|
+
key: createRecordKey(order, "diagnostic", item.diagnostic.source, item.diagnostic.severity, item.diagnostic.code, item.diagnostic.severity === "warning" ? item.diagnostic.details : null)
|
|
849
|
+
});
|
|
850
|
+
if (item.kind === "evidence") {
|
|
851
|
+
const evidence = item.evidence;
|
|
852
|
+
const record = {
|
|
853
|
+
agentId: evidence.agentId,
|
|
854
|
+
capabilityId: evidence.capabilityId,
|
|
855
|
+
capabilityKind: evidence.capabilityKind,
|
|
856
|
+
evidenceKind: evidence.kind,
|
|
857
|
+
key: createRecordKey(order, "evidence", evidence.source, evidence.kind, evidence.agentId, evidence.capabilityKind, evidence.capabilityId, evidence.runtimeName),
|
|
858
|
+
kind: "evidence",
|
|
859
|
+
references: Object.freeze(evidence.references.map((reference) => Object.freeze({
|
|
860
|
+
path: reference.path,
|
|
861
|
+
symbol: reference.symbol ?? null
|
|
862
|
+
}))),
|
|
863
|
+
runtimeName: evidence.runtimeName,
|
|
864
|
+
source: evidence.source
|
|
865
|
+
};
|
|
866
|
+
return Object.freeze(record);
|
|
867
|
+
}
|
|
868
|
+
const metadata = item.metadata;
|
|
869
|
+
const record = {
|
|
870
|
+
agentId: metadata.agentId,
|
|
871
|
+
byteLength: metadata.byteLength,
|
|
872
|
+
canonicalDigest: metadata.canonicalDigest,
|
|
873
|
+
decisionId: metadata.decisionId,
|
|
874
|
+
digest: metadata.digest,
|
|
875
|
+
key: createRecordKey(order, "metadata", metadata.path, metadata.kind, metadata.agentId),
|
|
876
|
+
kind: "metadata",
|
|
877
|
+
metadataKind: metadata.kind,
|
|
878
|
+
path: metadata.path,
|
|
879
|
+
scalarLength: metadata.scalarLength
|
|
880
|
+
};
|
|
881
|
+
return Object.freeze(record);
|
|
882
|
+
};
|
|
883
|
+
/** Creates content-free validation metadata and ordered diagnostic records. */
|
|
884
|
+
var createMoldeaCliValidateProjection = (validation) => {
|
|
885
|
+
assertProjectValidationInvariant(validation);
|
|
886
|
+
const diagnostics = Object.freeze(validation.diagnostics.map((diagnostic, index) => createMoldeaCliDiagnosticRecord(diagnostic, index)).sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0));
|
|
887
|
+
const snapshotDigest = calculateMoldeaCliJsonDigest({
|
|
888
|
+
diagnostics,
|
|
889
|
+
errorCount: validation.errorCount,
|
|
890
|
+
formatVersion: validation.formatVersion,
|
|
891
|
+
summary: validation.summary,
|
|
892
|
+
runtimeInspection: validation.runtimeInspection,
|
|
893
|
+
valid: validation.valid,
|
|
894
|
+
warningCount: validation.warningCount
|
|
895
|
+
});
|
|
896
|
+
return Object.freeze({
|
|
897
|
+
diagnostics,
|
|
898
|
+
errorCount: validation.errorCount,
|
|
899
|
+
formatVersion: validation.formatVersion,
|
|
900
|
+
snapshotDigest,
|
|
901
|
+
source: MOLDEA_CLI_GIT_WORKING_TREE_SOURCE,
|
|
902
|
+
runtimeInspection: validation.runtimeInspection,
|
|
903
|
+
valid: validation.valid,
|
|
904
|
+
warningCount: validation.warningCount
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
/** Projects one bounded Core page through the content-free schema 6 allowlist. */
|
|
908
|
+
var createMoldeaCliInspectProjection = (inspection) => {
|
|
909
|
+
const project = inspection.summary === null ? null : Object.freeze({
|
|
910
|
+
manifest: Object.freeze({
|
|
911
|
+
digest: inspection.summary.manifestDigest,
|
|
912
|
+
path: inspection.summary.manifestPath
|
|
913
|
+
}),
|
|
914
|
+
project: Object.freeze({
|
|
915
|
+
digest: inspection.summary.projectDigest,
|
|
916
|
+
path: inspection.summary.projectPath
|
|
917
|
+
})
|
|
918
|
+
});
|
|
919
|
+
const records = Object.freeze(inspection.page.records.map(({ item }, index) => createInspectRecord(item, index)));
|
|
920
|
+
const sourceCursors = new Map(inspection.page.records.map((record, index) => {
|
|
921
|
+
const projected = records[index];
|
|
922
|
+
if (projected === void 0) throw new TypeError("A projected inspection record is missing.");
|
|
923
|
+
return [projected.key, record.nextCursor];
|
|
924
|
+
}));
|
|
925
|
+
const snapshotDigest = inspection.inspectionDigest;
|
|
926
|
+
return Object.freeze({
|
|
927
|
+
counts: inspection.counts,
|
|
928
|
+
formatVersion: inspection.formatVersion,
|
|
929
|
+
getSourceCursor: (record) => sourceCursors.get(record.key) ?? null,
|
|
930
|
+
project,
|
|
931
|
+
records,
|
|
932
|
+
snapshotDigest,
|
|
933
|
+
source: MOLDEA_CLI_GIT_WORKING_TREE_SOURCE,
|
|
934
|
+
runtimeInspection: inspection.runtimeInspection,
|
|
935
|
+
valid: inspection.valid,
|
|
936
|
+
view: inspection.view
|
|
937
|
+
});
|
|
938
|
+
};
|
|
939
|
+
//#endregion
|
|
8
940
|
//#region src/git-process/constants.ts
|
|
9
941
|
var GIT_PROCESS_GLOBAL_ARGUMENTS = [
|
|
10
942
|
"--no-pager",
|
|
@@ -392,6 +1324,17 @@ var createGitVersionPreflight = (processExecutor = executeGitProcess) => async (
|
|
|
392
1324
|
});
|
|
393
1325
|
};
|
|
394
1326
|
//#endregion
|
|
1327
|
+
//#region src/composition/exception.ts
|
|
1328
|
+
/** Represents an inconsistent installed executable composition. */
|
|
1329
|
+
var MoldeaCliCompositionException = class extends Error {
|
|
1330
|
+
code = "COMPOSITION_STATE_INVALID";
|
|
1331
|
+
/** Uses the canonical CLI-owned composition failure message. */
|
|
1332
|
+
constructor() {
|
|
1333
|
+
super(createMoldeaCliOwnedError("COMPOSITION_STATE_INVALID").message);
|
|
1334
|
+
this.name = "MoldeaCliCompositionException";
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
//#endregion
|
|
395
1338
|
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js
|
|
396
1339
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
397
1340
|
module.exports = {
|
|
@@ -1785,6 +2728,146 @@ var require_semver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1785
2728
|
};
|
|
1786
2729
|
}));
|
|
1787
2730
|
//#endregion
|
|
1788
|
-
|
|
2731
|
+
//#region src/composition/constants.ts
|
|
2732
|
+
var import_semver = require_semver();
|
|
2733
|
+
var MOLDEA_CLI_FOUNDATIONAL_PACKAGE_NAMES = Object.freeze([
|
|
2734
|
+
"@moldea.ai/core",
|
|
2735
|
+
"@moldea.ai/repository",
|
|
2736
|
+
"@moldea.ai/repository-fs"
|
|
2737
|
+
]);
|
|
2738
|
+
var MOLDEA_CLI_ADAPTER_PACKAGE_PREFIX = "@moldea.ai/adapter-";
|
|
2739
|
+
var MOLDEA_CLI_CUSTOM_ADAPTER_ID = "custom";
|
|
2740
|
+
var MOLDEA_CLI_FIRST_CLASS_PACKAGE_RANGES = Object.freeze({
|
|
2741
|
+
"@moldea.ai/adapter-anthropic": "^6.0.0",
|
|
2742
|
+
"@moldea.ai/adapter-claude-agent-sdk": "^5.0.0",
|
|
2743
|
+
"@moldea.ai/adapter-cloudflare-agents": "^5.0.0",
|
|
2744
|
+
"@moldea.ai/adapter-eve": "^5.0.0",
|
|
2745
|
+
"@moldea.ai/adapter-google-genai": "^5.0.0",
|
|
2746
|
+
"@moldea.ai/adapter-langchain": "^5.0.0",
|
|
2747
|
+
"@moldea.ai/adapter-langgraph": "^5.0.0",
|
|
2748
|
+
"@moldea.ai/adapter-openai": "^6.0.0",
|
|
2749
|
+
"@moldea.ai/adapter-openai-agents-sdk": "^5.0.0",
|
|
2750
|
+
"@moldea.ai/adapter-vercel-ai-sdk": "^5.0.0",
|
|
2751
|
+
"@moldea.ai/core": "^6.0.0",
|
|
2752
|
+
"@moldea.ai/repository": "^2.0.0",
|
|
2753
|
+
"@moldea.ai/repository-fs": "^2.0.3"
|
|
2754
|
+
});
|
|
2755
|
+
//#endregion
|
|
2756
|
+
//#region src/composition/validations.ts
|
|
2757
|
+
var ADAPTER_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
2758
|
+
var hasExactStringSet = (left, right) => {
|
|
2759
|
+
if (left.length !== right.length || new Set(left).size !== left.length || new Set(right).size !== right.length) return false;
|
|
2760
|
+
const rightValues = new Set(right);
|
|
2761
|
+
return left.every((entry) => rightValues.has(entry));
|
|
2762
|
+
};
|
|
2763
|
+
var hasUniquePositiveIntegers = (entries) => entries.length > 0 && entries.every((entry) => Number.isSafeInteger(entry) && entry > 0) && new Set(entries).size === entries.length;
|
|
2764
|
+
var createActiveAdapterMap = (adapters, coreRepositoryFormatVersions) => {
|
|
2765
|
+
const adapterMap = /* @__PURE__ */ new Map();
|
|
2766
|
+
for (const adapter of adapters) {
|
|
2767
|
+
if (adapterMap.has(adapter.id) || adapter.id === "custom" || !ADAPTER_ID_PATTERN.test(adapter.id) || !hasUniquePositiveIntegers(adapter.supportedRepositoryFormatVersions) || adapter.supportedRepositoryFormatVersions.some((version) => !coreRepositoryFormatVersions.includes(version))) return null;
|
|
2768
|
+
adapterMap.set(adapter.id, adapter);
|
|
2769
|
+
}
|
|
2770
|
+
return adapterMap;
|
|
2771
|
+
};
|
|
2772
|
+
/**
|
|
2773
|
+
* Verifies the installed package manifest and actual executable adapter composition.
|
|
2774
|
+
* @param input The installed package, Core, adapter, Git, and JSON-schema state.
|
|
2775
|
+
* @returns Whether every runtime composition invariant is satisfied.
|
|
2776
|
+
*/
|
|
2777
|
+
var isMoldeaCliCompositionStateValid = (input) => {
|
|
2778
|
+
const { dependencies, installedPackageVersions, supportedNodeRange, version } = input.packageMetadata;
|
|
2779
|
+
if ((0, import_semver.valid)(version) === null || supportedNodeRange === null || (0, import_semver.validRange)(supportedNodeRange) === null || (0, import_semver.valid)(input.minimumGitVersion) === null || input.outputSchemaVersion !== 6 || dependencies === null || installedPackageVersions === null || !hasUniquePositiveIntegers(input.coreSupportedRepositoryFormatVersions)) return false;
|
|
2780
|
+
const activeAdapterMap = createActiveAdapterMap(input.activeAdapters, input.coreSupportedRepositoryFormatVersions);
|
|
2781
|
+
if (activeAdapterMap === null) return false;
|
|
2782
|
+
const expectedPackageNames = [...MOLDEA_CLI_FOUNDATIONAL_PACKAGE_NAMES, ...[...activeAdapterMap.keys()].map((adapterId) => `${MOLDEA_CLI_ADAPTER_PACKAGE_PREFIX}${adapterId}`)];
|
|
2783
|
+
const declaredPackageNames = Object.keys(dependencies).filter((packageName) => packageName.startsWith("@moldea.ai/"));
|
|
2784
|
+
const resolvedPackageNames = Object.keys(installedPackageVersions);
|
|
2785
|
+
if (!hasExactStringSet(declaredPackageNames, expectedPackageNames) || !hasExactStringSet(resolvedPackageNames, expectedPackageNames)) return false;
|
|
2786
|
+
return expectedPackageNames.every((packageName) => {
|
|
2787
|
+
const resolvedVersion = installedPackageVersions[packageName];
|
|
2788
|
+
const declaredRange = dependencies[packageName];
|
|
2789
|
+
const supportedRange = MOLDEA_CLI_FIRST_CLASS_PACKAGE_RANGES[packageName];
|
|
2790
|
+
return resolvedVersion !== void 0 && (0, import_semver.valid)(resolvedVersion) !== null && supportedRange !== void 0 && (declaredRange === supportedRange || declaredRange === `workspace:${supportedRange}`) && (0, import_semver.satisfies)(resolvedVersion, supportedRange);
|
|
2791
|
+
});
|
|
2792
|
+
};
|
|
2793
|
+
//#endregion
|
|
2794
|
+
//#region src/composition/transformers.ts
|
|
2795
|
+
var compareIdentifiers = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
2796
|
+
/** Recursively freezes a composition result without retaining mutable input ownership. */
|
|
2797
|
+
var freezeCompositionValue = (value) => {
|
|
2798
|
+
const pendingValues = [value];
|
|
2799
|
+
const visitedValues = /* @__PURE__ */ new Set();
|
|
2800
|
+
while (pendingValues.length > 0) {
|
|
2801
|
+
const currentValue = pendingValues.pop();
|
|
2802
|
+
if (currentValue === void 0 || visitedValues.has(currentValue)) continue;
|
|
2803
|
+
visitedValues.add(currentValue);
|
|
2804
|
+
for (const nestedValue of Object.values(currentValue)) if (typeof nestedValue === "object" && nestedValue !== null) pendingValues.push(nestedValue);
|
|
2805
|
+
Object.freeze(currentValue);
|
|
2806
|
+
}
|
|
2807
|
+
return value;
|
|
2808
|
+
};
|
|
2809
|
+
/**
|
|
2810
|
+
* Creates the compact immutable composition result from validated installed state.
|
|
2811
|
+
* @param input The already validated installed and executable composition.
|
|
2812
|
+
* @returns A deeply immutable composition result in deterministic report order.
|
|
2813
|
+
*/
|
|
2814
|
+
var createMoldeaCliCompositionResult = (input) => {
|
|
2815
|
+
const adapters = [{
|
|
2816
|
+
id: MOLDEA_CLI_CUSTOM_ADAPTER_ID,
|
|
2817
|
+
repositoryFormatVersions: [...input.coreSupportedRepositoryFormatVersions].sort((left, right) => left - right)
|
|
2818
|
+
}, ...input.activeAdapters.map((adapter) => ({
|
|
2819
|
+
id: adapter.id,
|
|
2820
|
+
repositoryFormatVersions: [...adapter.supportedRepositoryFormatVersions].sort((left, right) => left - right)
|
|
2821
|
+
}))].sort((left, right) => compareIdentifiers(left.id, right.id));
|
|
2822
|
+
const packages = Object.entries(input.packageMetadata.installedPackageVersions ?? {}).map(([name, version]) => ({
|
|
2823
|
+
name,
|
|
2824
|
+
version
|
|
2825
|
+
})).sort((left, right) => compareIdentifiers(left.name, right.name));
|
|
2826
|
+
return freezeCompositionValue({
|
|
2827
|
+
adapters,
|
|
2828
|
+
minimumGitVersion: input.minimumGitVersion,
|
|
2829
|
+
packages,
|
|
2830
|
+
repositoryFormatVersions: [...input.coreSupportedRepositoryFormatVersions].sort((left, right) => left - right),
|
|
2831
|
+
supportedNodeRange: input.packageMetadata.supportedNodeRange ?? ""
|
|
2832
|
+
});
|
|
2833
|
+
};
|
|
2834
|
+
//#endregion
|
|
2835
|
+
//#region src/composition/composition.ts
|
|
2836
|
+
var INVALID_COMPOSITION_RESOLUTION = Object.freeze({ kind: "invalid" });
|
|
2837
|
+
var EXPECTED_ADAPTERS = Object.keys(MOLDEA_CLI_FIRST_CLASS_PACKAGE_RANGES).filter((name) => name.startsWith(MOLDEA_CLI_ADAPTER_PACKAGE_PREFIX)).map((name) => ({
|
|
2838
|
+
id: name.slice(MOLDEA_CLI_ADAPTER_PACKAGE_PREFIX.length),
|
|
2839
|
+
supportedRepositoryFormatVersions: SUPPORTED_REPOSITORY_FORMAT_VERSIONS
|
|
2840
|
+
}));
|
|
2841
|
+
/**
|
|
2842
|
+
* Resolves one explicit runtime composition without emitting a partial composition result.
|
|
2843
|
+
* @param input The installed and actual runtime state to compare.
|
|
2844
|
+
* @returns A valid immutable result or the single invalid-state outcome.
|
|
2845
|
+
*/
|
|
2846
|
+
var resolveMoldeaCliComposition = (input) => {
|
|
2847
|
+
try {
|
|
2848
|
+
if (!isMoldeaCliCompositionStateValid(input)) return INVALID_COMPOSITION_RESOLUTION;
|
|
2849
|
+
return Object.freeze({
|
|
2850
|
+
kind: "valid",
|
|
2851
|
+
result: createMoldeaCliCompositionResult(input)
|
|
2852
|
+
});
|
|
2853
|
+
} catch {
|
|
2854
|
+
return INVALID_COMPOSITION_RESOLUTION;
|
|
2855
|
+
}
|
|
2856
|
+
};
|
|
2857
|
+
/**
|
|
2858
|
+
* Checks installed package metadata and supplied worker-validated adapter identities.
|
|
2859
|
+
* Without identities, this is only the manifest preflight before repository discovery.
|
|
2860
|
+
* @param input The installed package metadata and optional actual executable identities.
|
|
2861
|
+
* @returns A valid immutable result or the single invalid-state outcome.
|
|
2862
|
+
*/
|
|
2863
|
+
var resolveInstalledMoldeaCliComposition = (input) => resolveMoldeaCliComposition({
|
|
2864
|
+
activeAdapters: input.activeAdapters ?? EXPECTED_ADAPTERS,
|
|
2865
|
+
coreSupportedRepositoryFormatVersions: SUPPORTED_REPOSITORY_FORMAT_VERSIONS,
|
|
2866
|
+
minimumGitVersion: MINIMUM_GIT_VERSION,
|
|
2867
|
+
outputSchemaVersion: 6,
|
|
2868
|
+
packageMetadata: input.packageMetadata
|
|
2869
|
+
});
|
|
2870
|
+
//#endregion
|
|
2871
|
+
export { hasOnlyUnicodeScalarValues as A, formatMoldeaCliJsonError as C, createMoldeaCliOwnedError as D, formatMoldeaCliJsonValidateResult as E, encodeMoldeaCliCursor as F, MoldeaCliOutputPageException as I, MOLDEA_CLI_COMMANDS as L, createMoldeaCliOutputPage as M, calculateMoldeaCliJsonDigest as N, MOLDEA_CLI_GIT_WORKING_TREE_SOURCE as O, decodeMoldeaCliCursor as P, formatMoldeaCliJsonContentResult as S, formatMoldeaCliJsonScopeResult as T, formatMoldeaCliHumanError as _, require_semver as a, formatMoldeaCliHumanValidateResult as b, executeGitStreamingProcess as c, createMoldeaCliDiagnosticRecord as d, createMoldeaCliInspectProjection as f, formatMoldeaCliHumanContentResult as g, formatMoldeaCliHumanCompositionResult as h, isMoldeaCliCompositionStateValid as i, isRepositoryDirectoryInputValid as j, parseMoldeaCliArguments as k, executeGitProcess as l, formatMoldeaCliHelp as m, resolveMoldeaCliComposition as n, MoldeaCliCompositionException as o, createMoldeaCliValidateProjection as p, createMoldeaCliCompositionResult as r, createGitVersionPreflight as s, resolveInstalledMoldeaCliComposition as t, MAX_GIT_PROCESS_DIAGNOSTIC_BYTES as u, formatMoldeaCliHumanInspectResult as v, formatMoldeaCliJsonInspectResult as w, formatMoldeaCliJsonCompositionResult as x, formatMoldeaCliHumanScopeResult as y };
|
|
1789
2872
|
|
|
1790
|
-
//# sourceMappingURL=
|
|
2873
|
+
//# sourceMappingURL=composition-DIN3r5rw.js.map
|