farseer-cli 1.16.0 → 1.17.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.
Files changed (48) hide show
  1. package/README.md +328 -0
  2. package/dist/commands/code.js +104 -0
  3. package/dist/commands/code.js.map +7 -0
  4. package/dist/index.js +16 -0
  5. package/dist/index.js.map +2 -2
  6. package/dist/pipeline/service.js +1 -1
  7. package/dist/pipeline/service.js.map +2 -2
  8. package/dist/services/codefirst/api.js +269 -0
  9. package/dist/services/codefirst/api.js.map +7 -0
  10. package/dist/services/codefirst/binaryDisk.js +67 -0
  11. package/dist/services/codefirst/binaryDisk.js.map +7 -0
  12. package/dist/services/codefirst/byteHashes.js +129 -0
  13. package/dist/services/codefirst/byteHashes.js.map +7 -0
  14. package/dist/services/codefirst/documents.js +563 -0
  15. package/dist/services/codefirst/documents.js.map +7 -0
  16. package/dist/services/codefirst/layoutBinaryProjection.js +974 -0
  17. package/dist/services/codefirst/layoutBinaryProjection.js.map +7 -0
  18. package/dist/services/codefirst/layoutCompose.js +593 -0
  19. package/dist/services/codefirst/layoutCompose.js.map +7 -0
  20. package/dist/services/codefirst/layoutCore.js +260 -0
  21. package/dist/services/codefirst/layoutCore.js.map +7 -0
  22. package/dist/services/codefirst/layoutPaths.js +492 -0
  23. package/dist/services/codefirst/layoutPaths.js.map +7 -0
  24. package/dist/services/codefirst/layoutProjection.js +995 -0
  25. package/dist/services/codefirst/layoutProjection.js.map +7 -0
  26. package/dist/services/codefirst/layoutReadback.js +2552 -0
  27. package/dist/services/codefirst/layoutReadback.js.map +7 -0
  28. package/dist/services/codefirst/layoutReadbackPlacement.js +1517 -0
  29. package/dist/services/codefirst/layoutReadbackPlacement.js.map +7 -0
  30. package/dist/services/codefirst/layoutReceipt.js +1592 -0
  31. package/dist/services/codefirst/layoutReceipt.js.map +7 -0
  32. package/dist/services/codefirst/layoutScan.js +882 -0
  33. package/dist/services/codefirst/layoutScan.js.map +7 -0
  34. package/dist/services/codefirst/output.js +179 -0
  35. package/dist/services/codefirst/output.js.map +7 -0
  36. package/dist/services/codefirst/types.js +17 -0
  37. package/dist/services/codefirst/types.js.map +7 -0
  38. package/dist/services/codefirst/workflow.js +581 -0
  39. package/dist/services/codefirst/workflow.js.map +7 -0
  40. package/dist/services/codefirst/workspace.js +310 -0
  41. package/dist/services/codefirst/workspace.js.map +7 -0
  42. package/dist/services/codefirst/workspaceLock.js +148 -0
  43. package/dist/services/codefirst/workspaceLock.js.map +7 -0
  44. package/dist/services/codefirst/workspaceRoot.js +147 -0
  45. package/dist/services/codefirst/workspaceRoot.js.map +7 -0
  46. package/dist/utils/logger.js +9 -3
  47. package/dist/utils/logger.js.map +2 -2
  48. package/package.json +3 -2
@@ -0,0 +1,492 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var layoutPaths_exports = {};
20
+ __export(layoutPaths_exports, {
21
+ IGNORED_LAYOUT_NAMES: () => IGNORED_LAYOUT_NAMES,
22
+ LayoutPathAllocationError: () => LayoutPathAllocationError,
23
+ LayoutPathAllocator: () => LayoutPathAllocator,
24
+ MAX_LAYOUT_COMPONENT_BYTES: () => MAX_LAYOUT_COMPONENT_BYTES,
25
+ MAX_LAYOUT_PATH_BYTES: () => MAX_LAYOUT_PATH_BYTES,
26
+ RAW_SIDECAR_SUFFIX: () => RAW_SIDECAR_SUFFIX,
27
+ collisionAncestors: () => collisionAncestors,
28
+ decodeLayoutName: () => decodeLayoutName,
29
+ decodeLayoutSegment: () => decodeLayoutSegment,
30
+ encodeLayoutSegment: () => encodeLayoutSegment,
31
+ folderDirectory: () => folderDirectory,
32
+ isIgnoredLayoutName: () => isIgnoredLayoutName,
33
+ isPortableWorkspacePointer: () => isPortableWorkspacePointer,
34
+ isRawSidecarPath: () => isRawSidecarPath,
35
+ isTemporaryLayoutPath: () => isTemporaryLayoutPath,
36
+ layoutCollisionKey: () => layoutCollisionKey,
37
+ layoutNameNeedsOverride: () => layoutNameNeedsOverride,
38
+ normalizeRequiredLayoutChildren: () => normalizeRequiredLayoutChildren,
39
+ parentDirectory: () => parentDirectory,
40
+ parseWorkspacePointer: () => parseWorkspacePointer,
41
+ provesUnrepresentableRequest: () => provesUnrepresentableRequest,
42
+ rawBytesPath: () => rawBytesPath,
43
+ rawSidecarPath: () => rawSidecarPath
44
+ });
45
+ module.exports = __toCommonJS(layoutPaths_exports);
46
+ var import_crypto = require("crypto");
47
+ const MAX_LAYOUT_COMPONENT_BYTES = 200;
48
+ const MAX_LAYOUT_PATH_BYTES = 768;
49
+ const RESERVED_CONTROLS = /* @__PURE__ */ new Set(["_folder.json", "_files.json", ".farseer-codefirst.json"]);
50
+ const IGNORED_LAYOUT_NAMES = /* @__PURE__ */ new Set([
51
+ ".DS_Store",
52
+ "Thumbs.db",
53
+ "desktop.ini",
54
+ "__pycache__",
55
+ ".git"
56
+ ]);
57
+ const APPLE_DOUBLE_PREFIX = "._";
58
+ const RAW_SIDECAR_SUFFIX = ".meta";
59
+ const DEVICE_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i;
60
+ const TEMPORARY_NAME = /\.tmp-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
61
+ const FALLBACK_TOKEN = /~[a-z][a-z0-9_]{0,23}-(?:[0-9]{1,32}|h[0-9a-f]{20})(?=\..*$|$)/;
62
+ const UNSAFE_ASCII = /* @__PURE__ */ new Set(["\\", "/", "<", ">", ":", '"', "|", "?", "*", "~"]);
63
+ function rawSidecarPath(bytes) {
64
+ return `${bytes}${RAW_SIDECAR_SUFFIX}`;
65
+ }
66
+ function rawBytesPath(sidecar) {
67
+ if (!isRawSidecarPath(sidecar)) throw new Error(`Not a raw sidecar path: ${JSON.stringify(sidecar)}`);
68
+ return sidecar.slice(0, -RAW_SIDECAR_SUFFIX.length);
69
+ }
70
+ function isRawSidecarPath(value) {
71
+ return value.length > RAW_SIDECAR_SUFFIX.length && value.endsWith(RAW_SIDECAR_SUFFIX);
72
+ }
73
+ function isPortableWorkspacePointer(value) {
74
+ try {
75
+ parseWorkspacePointer(value);
76
+ return true;
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ function isTemporaryLayoutPath(value) {
82
+ return TEMPORARY_NAME.test(value);
83
+ }
84
+ function isIgnoredLayoutName(name) {
85
+ return IGNORED_LAYOUT_NAMES.has(name) || name.startsWith(APPLE_DOUBLE_PREFIX);
86
+ }
87
+ class LayoutPathAllocationError extends Error {
88
+ constructor(reason, message) {
89
+ super(message);
90
+ this.reason = reason;
91
+ this.name = "LayoutPathAllocationError";
92
+ }
93
+ }
94
+ function byteLength(value) {
95
+ return Buffer.byteLength(value, "utf8");
96
+ }
97
+ function hasUnsafeCharacter(value, includeTilde) {
98
+ return Array.from(value).some((character) => {
99
+ const code = character.codePointAt(0);
100
+ return code <= 31 || code === 127 || UNSAFE_ASCII.has(character) && (includeTilde || character !== "~");
101
+ });
102
+ }
103
+ function escapeCharacter(value) {
104
+ return [...Buffer.from(value, "utf8")].map((byte) => `~${byte.toString(16).toUpperCase().padStart(2, "0")}`).join("");
105
+ }
106
+ function assertUnicode(value) {
107
+ for (let index = 0; index < value.length; index++) {
108
+ const code = value.charCodeAt(index);
109
+ if (code >= 55296 && code <= 56319) {
110
+ const next = value.charCodeAt(++index);
111
+ if (!Number.isInteger(next) || next < 56320 || next > 57343)
112
+ throw new Error("Layout segment contains an unpaired surrogate");
113
+ } else if (code >= 56320 && code <= 57343) {
114
+ throw new Error("Layout segment contains an unpaired surrogate");
115
+ }
116
+ }
117
+ }
118
+ function reservedEscapeIndex(value) {
119
+ const folded = value.toLocaleLowerCase("en-US");
120
+ const temporary = value.match(TEMPORARY_NAME);
121
+ if (temporary?.index !== void 0) return Array.from(value.slice(0, temporary.index)).length;
122
+ if (isRawSidecarPath(folded)) return Array.from(value).length - RAW_SIDECAR_SUFFIX.length;
123
+ return value === "." || value === ".." || RESERVED_CONTROLS.has(folded) || DEVICE_NAME.test(value) || isIgnoredLayoutName(value) ? 0 : void 0;
124
+ }
125
+ function encodeLayoutSegment(value) {
126
+ if (!value) throw new Error("Layout segment must not be empty");
127
+ assertUnicode(value);
128
+ const characters = Array.from(value);
129
+ const reservedIndex = reservedEscapeIndex(value);
130
+ return characters.map((character, index) => {
131
+ const trailing = (character === "." || character === " ") && characters.slice(index + 1).every((part) => part === "." || part === " ");
132
+ return hasUnsafeCharacter(character, true) || trailing || index === reservedIndex ? escapeCharacter(character) : character;
133
+ }).join("");
134
+ }
135
+ function decodeCanonicalSegment(value) {
136
+ const bytes = [];
137
+ for (let index = 0; index < value.length; ) {
138
+ if (value[index] === "~") {
139
+ const escape = value.slice(index + 1, index + 3);
140
+ if (!/^[0-9A-F]{2}$/.test(escape)) throw new Error(`Malformed layout escape in ${JSON.stringify(value)}`);
141
+ bytes.push(Number.parseInt(escape, 16));
142
+ index += 3;
143
+ continue;
144
+ }
145
+ const codePoint = value.codePointAt(index);
146
+ const character = String.fromCodePoint(codePoint);
147
+ bytes.push(...Buffer.from(character, "utf8"));
148
+ index += character.length;
149
+ }
150
+ let decoded;
151
+ try {
152
+ decoded = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));
153
+ } catch {
154
+ throw new Error(`Invalid UTF-8 layout escape in ${JSON.stringify(value)}`);
155
+ }
156
+ if (encodeLayoutSegment(decoded) !== value)
157
+ throw new Error(`Non-canonical layout encoding in ${JSON.stringify(value)}`);
158
+ return decoded;
159
+ }
160
+ function decodeLayoutSegment(value, exactNameOverride) {
161
+ if (!value) throw new Error("Layout segment must not be empty");
162
+ const fallback = value.match(FALLBACK_TOKEN);
163
+ if (!fallback) return decodeCanonicalSegment(value);
164
+ if (exactNameOverride === void 0)
165
+ throw new Error(`Layout fallback ${JSON.stringify(value)} requires an exact name override`);
166
+ const withoutFallback = value.slice(0, fallback.index) + value.slice(fallback.index + fallback[0].length);
167
+ if (withoutFallback) decodeCanonicalSegment(withoutFallback);
168
+ return exactNameOverride;
169
+ }
170
+ function decodeLayoutName(value, role, extension, exactNameOverride) {
171
+ validateExtension(extension);
172
+ const fallback = value.match(FALLBACK_TOKEN);
173
+ if (fallback && !fallback[0].startsWith(`~${role}-`))
174
+ throw new Error(`Layout fallback ${JSON.stringify(value)} does not belong to role ${role}`);
175
+ const physical = fallback ? value.slice(0, fallback.index) + value.slice(fallback.index + fallback[0].length) : value;
176
+ const decoded = physical ? decodeCanonicalSegment(physical) : "";
177
+ if (!decoded.endsWith(extension))
178
+ throw new Error(
179
+ `Layout component ${JSON.stringify(value)} does not use extension ${JSON.stringify(extension)}`
180
+ );
181
+ if (fallback && exactNameOverride === void 0)
182
+ throw new Error(`Layout fallback ${JSON.stringify(value)} requires an exact name override`);
183
+ const filename = decoded.slice(0, decoded.length - extension.length);
184
+ if (!fallback && exactNameOverride !== void 0 && exactNameOverride.normalize("NFC") !== filename.normalize("NFC"))
185
+ return filename;
186
+ return exactNameOverride ?? filename;
187
+ }
188
+ function layoutCollisionKey(value) {
189
+ return value.normalize("NFKC").toUpperCase().normalize("NFC");
190
+ }
191
+ function layoutNameNeedsOverride(value) {
192
+ return value.normalize("NFC") !== value.normalize("NFD");
193
+ }
194
+ function assertEscapeSyntax(component) {
195
+ for (let index = component.indexOf("~"); index >= 0; index = component.indexOf("~", index)) {
196
+ if (/^[0-9A-F]{2}$/.test(component.slice(index + 1, index + 3))) {
197
+ index += 3;
198
+ continue;
199
+ }
200
+ const fallback = component.slice(index).match(new RegExp(`^${FALLBACK_TOKEN.source}`));
201
+ if (!fallback) throw new Error(`Malformed layout escape in ${JSON.stringify(component)}`);
202
+ index += fallback[0].length;
203
+ }
204
+ }
205
+ function assertPortableComponent(component) {
206
+ assertUnicode(component);
207
+ if (!component || component === "." || component === ".." || hasUnsafeCharacter(component, false))
208
+ throw new Error(`Unsafe layout path component: ${JSON.stringify(component)}`);
209
+ if (/[. ]$/.test(component) || DEVICE_NAME.test(component) || TEMPORARY_NAME.test(component))
210
+ throw new Error(`Non-portable layout path component: ${JSON.stringify(component)}`);
211
+ if (byteLength(component) > MAX_LAYOUT_COMPONENT_BYTES)
212
+ throw new Error(
213
+ `Layout path component exceeds ${MAX_LAYOUT_COMPONENT_BYTES} bytes: ${JSON.stringify(component)}`
214
+ );
215
+ assertEscapeSyntax(component);
216
+ }
217
+ function parseWorkspacePointer(value) {
218
+ if (!value || value.startsWith("/") || value.startsWith("\\") || /^[A-Za-z]:/.test(value))
219
+ throw new Error(`Workspace pointer must be relative: ${JSON.stringify(value)}`);
220
+ const components = value.split("/");
221
+ for (const component of components) assertPortableComponent(component);
222
+ if (byteLength(value) > MAX_LAYOUT_PATH_BYTES)
223
+ throw new Error(`Workspace pointer exceeds ${MAX_LAYOUT_PATH_BYTES} bytes: ${JSON.stringify(value)}`);
224
+ return components.join("/");
225
+ }
226
+ function joinLayoutPath(directory, component) {
227
+ return directory ? `${directory}/${component}` : component;
228
+ }
229
+ function fallbackToken(role, identity) {
230
+ if (!/^[a-z][a-z0-9_]{0,23}$/.test(role)) throw new Error(`Invalid layout fallback role: ${role}`);
231
+ if (!identity) throw new Error("A stable identity is required for layout fallback");
232
+ const suffix = /^[0-9]{1,32}$/.test(identity) ? identity : `h${(0, import_crypto.createHash)("sha256").update(identity).digest("hex").slice(0, 20)}`;
233
+ return `~${role}-${suffix}`;
234
+ }
235
+ function validateExtension(extension) {
236
+ if (extension && (!extension.startsWith(".") || hasUnsafeCharacter(extension, true) || extension.includes(" ") || encodeLayoutSegment(`x${extension}`) !== `x${extension}`))
237
+ throw new Error(`Invalid layout extension: ${JSON.stringify(extension)}`);
238
+ }
239
+ function invalidRequest(message) {
240
+ return new LayoutPathAllocationError("invalid-request", message);
241
+ }
242
+ function errorMessage(error) {
243
+ return error instanceof Error ? error.message : String(error);
244
+ }
245
+ function provesUnrepresentableRequest(request, existingClaims) {
246
+ let allocator;
247
+ try {
248
+ allocator = new LayoutPathAllocator([...existingClaims]);
249
+ } catch {
250
+ return false;
251
+ }
252
+ try {
253
+ allocator.allocate(request);
254
+ return false;
255
+ } catch (error) {
256
+ return error instanceof LayoutPathAllocationError && error.reason === "unrepresentable";
257
+ }
258
+ }
259
+ function normalizeRequiredLayoutChildren(request) {
260
+ if (request.requiredChildren === void 0) return [];
261
+ const kind = request.kind ?? (request.role === "directory" ? "directory" : "file");
262
+ if (request.role !== "directory" || kind !== "directory")
263
+ throw invalidRequest("Only directory requests can require layout controls");
264
+ if (!Array.isArray(request.requiredChildren)) throw invalidRequest("Required layout controls must be a list");
265
+ const controls = request.requiredChildren;
266
+ const allowed = /* @__PURE__ */ new Set(["_folder.json"]);
267
+ if (controls.some((control) => typeof control !== "string" || !allowed.has(control)))
268
+ throw invalidRequest("Required layout controls must be reserved leaf names");
269
+ if (new Set(controls).size !== controls.length) throw invalidRequest("Required layout controls must be unique");
270
+ return ["_folder.json"].filter((control) => controls.includes(control));
271
+ }
272
+ function folderDirectory(folderControl) {
273
+ return folderControl.slice(0, -"/_folder.json".length);
274
+ }
275
+ function parentDirectory(file) {
276
+ return file.slice(0, file.lastIndexOf("/"));
277
+ }
278
+ function candidateFits(component, candidate, requiredChildren, companion) {
279
+ return byteLength(component) + byteLength(companion) <= MAX_LAYOUT_COMPONENT_BYTES && byteLength(candidate) + byteLength(companion) <= MAX_LAYOUT_PATH_BYTES && requiredChildren.every((child) => byteLength(joinLayoutPath(candidate, child)) <= MAX_LAYOUT_PATH_BYTES);
280
+ }
281
+ const ROLE_PRIORITY = {
282
+ directory: 0,
283
+ raw: 1,
284
+ attachment: 2,
285
+ document: 3
286
+ };
287
+ function validLayoutKind(value) {
288
+ return value === "file" || value === "directory";
289
+ }
290
+ function validRequestRole(value) {
291
+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(ROLE_PRIORITY, value);
292
+ }
293
+ function validateLayoutPathRequest(request) {
294
+ try {
295
+ if (typeof request.directory !== "string") throw invalidRequest("A layout directory must be a string");
296
+ if (typeof request.name !== "string" || !request.name)
297
+ throw invalidRequest("A semantic name is required for layout allocation");
298
+ if (typeof request.identity !== "string" || !request.identity)
299
+ throw invalidRequest("A stable identity is required for layout allocation");
300
+ if (request.extension !== void 0 && typeof request.extension !== "string")
301
+ throw invalidRequest("A layout extension must be a string");
302
+ if (!validRequestRole(request.role)) throw invalidRequest("Layout request has an invalid role");
303
+ if (request.kind !== void 0 && !validLayoutKind(request.kind))
304
+ throw invalidRequest("Layout request has an invalid kind");
305
+ const kind = request.kind ?? (request.role === "directory" ? "directory" : "file");
306
+ if (request.role === "directory" !== (kind === "directory"))
307
+ throw invalidRequest(`Layout role ${request.role} cannot claim a ${kind}`);
308
+ const requiredChildren = normalizeRequiredLayoutChildren(request);
309
+ const directory = request.directory ? parseWorkspacePointer(request.directory) : "";
310
+ const extension = request.extension ?? "";
311
+ validateExtension(extension);
312
+ return {
313
+ directory,
314
+ extension,
315
+ kind,
316
+ requiredChildren,
317
+ companion: request.role === "raw" ? RAW_SIDECAR_SUFFIX : "",
318
+ ordinaryComponent: encodeLayoutSegment(request.name + extension)
319
+ };
320
+ } catch (error) {
321
+ if (error instanceof LayoutPathAllocationError) throw error;
322
+ throw invalidRequest(errorMessage(error));
323
+ }
324
+ }
325
+ function collisionAncestors(key) {
326
+ const ancestors = [];
327
+ for (let index = key.indexOf("/"); index >= 0; index = key.indexOf("/", index + 1))
328
+ ancestors.push(key.slice(0, index));
329
+ return ancestors;
330
+ }
331
+ class LayoutPathAllocator {
332
+ constructor(existing = []) {
333
+ this.claims = [];
334
+ this.directorySpellings = /* @__PURE__ */ new Map();
335
+ /** Per collision key, the earliest claim with that key; a conflict names the earliest claim. */
336
+ this.firstByKey = /* @__PURE__ */ new Map();
337
+ this.firstFileByKey = /* @__PURE__ */ new Map();
338
+ /** Per collision key, the earliest claim strictly beneath it. */
339
+ this.firstBeneath = /* @__PURE__ */ new Map();
340
+ for (const claim of existing) this.claim(claim);
341
+ }
342
+ claim(claim) {
343
+ if (typeof claim.path !== "string") throw invalidRequest("A layout claim path must be a string");
344
+ if (typeof claim.identity !== "string" || !claim.identity)
345
+ throw invalidRequest("A stable identity is required for a layout claim");
346
+ if (!validLayoutKind(claim.kind)) throw invalidRequest("Layout claim has an invalid kind");
347
+ if (!(validRequestRole(claim.role) || claim.role === "control"))
348
+ throw invalidRequest("Layout claim has an invalid role");
349
+ if (claim.role === "control" && claim.kind !== "file") throw invalidRequest("Layout controls must claim files");
350
+ if (claim.role === "directory" !== (claim.kind === "directory"))
351
+ throw invalidRequest(`Layout role ${claim.role} cannot claim a ${claim.kind}`);
352
+ let normalized;
353
+ try {
354
+ normalized = parseWorkspacePointer(claim.path);
355
+ } catch (error) {
356
+ throw invalidRequest(errorMessage(error));
357
+ }
358
+ const directories = this.directoriesFor(normalized, claim.kind);
359
+ this.assertDirectorySpellings(directories);
360
+ const conflict = this.conflict(normalized, claim.kind);
361
+ if (conflict)
362
+ throw invalidRequest(
363
+ `Layout path ${JSON.stringify(normalized)} conflicts with ${JSON.stringify(conflict.path)}`
364
+ );
365
+ this.record({ ...claim, path: normalized });
366
+ for (const directory of directories)
367
+ if (!this.directorySpellings.has(layoutCollisionKey(directory)))
368
+ this.directorySpellings.set(layoutCollisionKey(directory), directory);
369
+ }
370
+ allocate(request) {
371
+ const { directory, extension, kind, ordinaryComponent, requiredChildren, companion } = validateLayoutPathRequest(request);
372
+ this.assertDirectorySpellings(
373
+ directory ? directory.split("/").map((_, index, all) => all.slice(0, index + 1).join("/")) : []
374
+ );
375
+ const ordinaryPath = joinLayoutPath(directory, ordinaryComponent);
376
+ if (candidateFits(ordinaryComponent, ordinaryPath, requiredChildren, companion) && !this.conflict(ordinaryPath, kind) && !(companion && this.conflict(`${ordinaryPath}${companion}`, "file"))) {
377
+ const nameOverride = layoutNameNeedsOverride(request.name) ? request.name : void 0;
378
+ if (decodeLayoutName(ordinaryComponent, request.role, extension, nameOverride) !== request.name)
379
+ throw new Error(
380
+ `Layout codec did not preserve the semantic name for ${request.role}/${request.identity}`
381
+ );
382
+ const allocated2 = { ...request, path: ordinaryPath, kind, fallback: false, nameOverride };
383
+ this.claim(allocated2);
384
+ this.claimCompanion(allocated2, companion);
385
+ return allocated2;
386
+ }
387
+ const token = fallbackToken(request.role, request.identity);
388
+ const ordinaryStem = extension ? ordinaryComponent.slice(0, ordinaryComponent.length - extension.length) : ordinaryComponent;
389
+ let component = `${ordinaryStem}${token}${extension}`;
390
+ if (byteLength(component) > MAX_LAYOUT_COMPONENT_BYTES) component = `${token}${extension}`;
391
+ const fallbackPath = joinLayoutPath(directory, component);
392
+ if (!candidateFits(component, fallbackPath, requiredChildren, companion))
393
+ throw new LayoutPathAllocationError(
394
+ "unrepresentable",
395
+ `Layout path cannot fit the portable budget for ${request.role}/${request.identity}`
396
+ );
397
+ const conflict = this.conflict(fallbackPath, kind) ?? (companion ? this.conflict(`${fallbackPath}${companion}`, "file") : void 0);
398
+ if (conflict)
399
+ throw new LayoutPathAllocationError(
400
+ "unrepresentable",
401
+ `Stable layout fallback ${JSON.stringify(fallbackPath)} conflicts with ${JSON.stringify(conflict.path)}`
402
+ );
403
+ if (decodeLayoutName(component, request.role, extension, request.name) !== request.name)
404
+ throw new Error(`Layout codec did not preserve the semantic name for ${request.role}/${request.identity}`);
405
+ const allocated = {
406
+ ...request,
407
+ path: fallbackPath,
408
+ kind,
409
+ fallback: true,
410
+ nameOverride: request.name
411
+ };
412
+ this.claim(allocated);
413
+ this.claimCompanion(allocated, companion);
414
+ return allocated;
415
+ }
416
+ snapshot() {
417
+ return this.claims.map((claim) => ({ ...claim }));
418
+ }
419
+ /** A raw allocation owns its sidecar too, so nothing else can take the path beside its bytes. */
420
+ claimCompanion(allocated, companion) {
421
+ if (!companion) return;
422
+ this.claim({
423
+ path: `${allocated.path}${companion}`,
424
+ kind: "file",
425
+ role: "control",
426
+ identity: `${allocated.identity}:sidecar`
427
+ });
428
+ }
429
+ record(claim) {
430
+ const position = this.claims.length;
431
+ this.claims.push(claim);
432
+ const key = layoutCollisionKey(claim.path);
433
+ if (!this.firstByKey.has(key)) this.firstByKey.set(key, position);
434
+ if (claim.kind === "file" && !this.firstFileByKey.has(key)) this.firstFileByKey.set(key, position);
435
+ for (const ancestor of collisionAncestors(key))
436
+ if (!this.firstBeneath.has(ancestor)) this.firstBeneath.set(ancestor, position);
437
+ }
438
+ /**
439
+ * The earliest claim the candidate collides with: the same key, a file claim above it, or, for a
440
+ * file candidate, any claim beneath it.
441
+ */
442
+ conflict(candidate, kind) {
443
+ const key = layoutCollisionKey(candidate);
444
+ const positions = [
445
+ this.firstByKey.get(key),
446
+ ...collisionAncestors(key).map((ancestor) => this.firstFileByKey.get(ancestor)),
447
+ kind === "file" ? this.firstBeneath.get(key) : void 0
448
+ ].filter((position) => position !== void 0);
449
+ return positions.length > 0 ? this.claims[Math.min(...positions)] : void 0;
450
+ }
451
+ directoriesFor(value, kind) {
452
+ const components = value.split("/");
453
+ const length = kind === "directory" ? components.length : components.length - 1;
454
+ return Array.from({ length }, (_, index) => components.slice(0, index + 1).join("/"));
455
+ }
456
+ assertDirectorySpellings(directories) {
457
+ for (const directory of directories) {
458
+ const existing = this.directorySpellings.get(layoutCollisionKey(directory));
459
+ if (existing !== void 0 && existing !== directory)
460
+ throw invalidRequest(
461
+ `Layout directory spelling ${JSON.stringify(directory)} conflicts with ${JSON.stringify(existing)}`
462
+ );
463
+ }
464
+ }
465
+ }
466
+ // Annotate the CommonJS export names for ESM import in node:
467
+ 0 && (module.exports = {
468
+ IGNORED_LAYOUT_NAMES,
469
+ LayoutPathAllocationError,
470
+ LayoutPathAllocator,
471
+ MAX_LAYOUT_COMPONENT_BYTES,
472
+ MAX_LAYOUT_PATH_BYTES,
473
+ RAW_SIDECAR_SUFFIX,
474
+ collisionAncestors,
475
+ decodeLayoutName,
476
+ decodeLayoutSegment,
477
+ encodeLayoutSegment,
478
+ folderDirectory,
479
+ isIgnoredLayoutName,
480
+ isPortableWorkspacePointer,
481
+ isRawSidecarPath,
482
+ isTemporaryLayoutPath,
483
+ layoutCollisionKey,
484
+ layoutNameNeedsOverride,
485
+ normalizeRequiredLayoutChildren,
486
+ parentDirectory,
487
+ parseWorkspacePointer,
488
+ provesUnrepresentableRequest,
489
+ rawBytesPath,
490
+ rawSidecarPath
491
+ });
492
+ //# sourceMappingURL=layoutPaths.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/services/codefirst/layoutPaths.ts"],
4
+ "sourcesContent": ["import { createHash } from 'crypto';\n\n/** 200 bytes leaves room for the 41-byte atomic temp suffix inside a 255-byte filesystem component. */\nexport const MAX_LAYOUT_COMPONENT_BYTES = 200;\nexport const MAX_LAYOUT_PATH_BYTES = 768;\n\nconst RESERVED_CONTROLS = new Set(['_folder.json', '_files.json', '.farseer-codefirst.json']);\n/**\n * Names the scan ignores wherever they appear: operating-system and tool files that are never\n * resources (`isIgnoredLayoutName`). Matched exactly, so a resource can only hide behind one if it\n * were spelled the same, which the allocator prevents by escaping these spellings on write.\n */\nexport const IGNORED_LAYOUT_NAMES: ReadonlySet<string> = new Set([\n '.DS_Store',\n 'Thumbs.db',\n 'desktop.ini',\n '__pycache__',\n '.git',\n]);\n/** AppleDouble files (`._X`): the metadata macOS writes beside a file on a foreign volume. */\nconst APPLE_DOUBLE_PREFIX = '._';\n/** Reserved suffix of the sidecar that carries one raw file's metadata beside its bytes. */\nexport const RAW_SIDECAR_SUFFIX = '.meta';\nconst DEVICE_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\.|$)/i;\nconst TEMPORARY_NAME = /\\.tmp-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\nconst FALLBACK_TOKEN = /~[a-z][a-z0-9_]{0,23}-(?:[0-9]{1,32}|h[0-9a-f]{20})(?=\\..*$|$)/;\nconst UNSAFE_ASCII = new Set(['\\\\', '/', '<', '>', ':', '\"', '|', '?', '*', '~']);\n\n/** The sidecar that describes one raw file: its own path with the reserved suffix appended. */\nexport function rawSidecarPath(bytes: string): string {\n return `${bytes}${RAW_SIDECAR_SUFFIX}`;\n}\n\n/** The bytes one sidecar describes. It throws for a path that is not a sidecar. */\nexport function rawBytesPath(sidecar: string): string {\n if (!isRawSidecarPath(sidecar)) throw new Error(`Not a raw sidecar path: ${JSON.stringify(sidecar)}`);\n return sidecar.slice(0, -RAW_SIDECAR_SUFFIX.length);\n}\n\n/** True for a name or path that claims a sibling's bytes. A bare `.meta` names no sibling. */\nexport function isRawSidecarPath(value: string): boolean {\n return value.length > RAW_SIDECAR_SUFFIX.length && value.endsWith(RAW_SIDECAR_SUFFIX);\n}\n\n/** True when a path can be a managed workspace pointer at all. Local-only names need not be. */\nexport function isPortableWorkspacePointer(value: string): boolean {\n try {\n parseWorkspacePointer(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/** True for a leftover atomic-write temporary, the one local-only name no managed path may carry. */\nexport function isTemporaryLayoutPath(value: string): boolean {\n return TEMPORARY_NAME.test(value);\n}\n\n/** True for one path component the scan ignores: an exact OS or tool name, or an AppleDouble file. */\nexport function isIgnoredLayoutName(name: string): boolean {\n return IGNORED_LAYOUT_NAMES.has(name) || name.startsWith(APPLE_DOUBLE_PREFIX);\n}\n\nexport type LayoutPathRole = 'control' | 'directory' | 'raw' | 'attachment' | 'document';\nexport type LayoutPathKind = 'file' | 'directory';\nexport type LayoutRequiredControl = '_folder.json';\n\nexport interface LayoutPathClaim {\n path: string;\n kind: LayoutPathKind;\n role: LayoutPathRole;\n identity: string;\n}\n\nexport interface LayoutPathRequest {\n directory: string;\n name: string;\n extension?: string;\n kind?: LayoutPathKind;\n role: Exclude<LayoutPathRole, 'control'>;\n identity: string;\n requiredChildren?: readonly LayoutRequiredControl[];\n}\n\nexport interface AllocatedLayoutPath extends LayoutPathClaim {\n fallback: boolean;\n nameOverride?: string;\n}\n\nexport class LayoutPathAllocationError extends Error {\n public constructor(\n public readonly reason: 'invalid-request' | 'unrepresentable',\n message: string,\n ) {\n super(message);\n this.name = 'LayoutPathAllocationError';\n }\n}\n\nfunction byteLength(value: string): number {\n return Buffer.byteLength(value, 'utf8');\n}\n\nfunction hasUnsafeCharacter(value: string, includeTilde: boolean): boolean {\n return Array.from(value).some((character) => {\n const code = character.codePointAt(0)!;\n return code <= 0x1f || code === 0x7f || (UNSAFE_ASCII.has(character) && (includeTilde || character !== '~'));\n });\n}\n\nfunction escapeCharacter(value: string): string {\n return [...Buffer.from(value, 'utf8')]\n .map((byte) => `~${byte.toString(16).toUpperCase().padStart(2, '0')}`)\n .join('');\n}\n\nfunction assertUnicode(value: string): void {\n for (let index = 0; index < value.length; index++) {\n const code = value.charCodeAt(index);\n if (code >= 0xd800 && code <= 0xdbff) {\n const next = value.charCodeAt(++index);\n if (!Number.isInteger(next) || next < 0xdc00 || next > 0xdfff)\n throw new Error('Layout segment contains an unpaired surrogate');\n } else if (code >= 0xdc00 && code <= 0xdfff) {\n throw new Error('Layout segment contains an unpaired surrogate');\n }\n }\n}\n\nfunction reservedEscapeIndex(value: string): number | undefined {\n const folded = value.toLocaleLowerCase('en-US');\n const temporary = value.match(TEMPORARY_NAME);\n if (temporary?.index !== undefined) return Array.from(value.slice(0, temporary.index)).length;\n // The sidecar suffix is reserved, so a raw name that ends in it escapes that separator instead.\n if (isRawSidecarPath(folded)) return Array.from(value).length - RAW_SIDECAR_SUFFIX.length;\n // A name the scan ignores is escaped on write, so no resource file ever hides behind the ignore.\n return value === '.' ||\n value === '..' ||\n RESERVED_CONTROLS.has(folded) ||\n DEVICE_NAME.test(value) ||\n isIgnoredLayoutName(value)\n ? 0\n : undefined;\n}\n\n/** Encode one logical filename component without changing ordinary case or Unicode. */\nexport function encodeLayoutSegment(value: string): string {\n if (!value) throw new Error('Layout segment must not be empty');\n assertUnicode(value);\n const characters = Array.from(value);\n const reservedIndex = reservedEscapeIndex(value);\n return characters\n .map((character, index) => {\n const trailing =\n (character === '.' || character === ' ') &&\n characters.slice(index + 1).every((part) => part === '.' || part === ' ');\n return hasUnsafeCharacter(character, true) || trailing || index === reservedIndex\n ? escapeCharacter(character)\n : character;\n })\n .join('');\n}\n\nfunction decodeCanonicalSegment(value: string): string {\n const bytes: number[] = [];\n for (let index = 0; index < value.length; ) {\n if (value[index] === '~') {\n const escape = value.slice(index + 1, index + 3);\n if (!/^[0-9A-F]{2}$/.test(escape)) throw new Error(`Malformed layout escape in ${JSON.stringify(value)}`);\n bytes.push(Number.parseInt(escape, 16));\n index += 3;\n continue;\n }\n const codePoint = value.codePointAt(index)!;\n const character = String.fromCodePoint(codePoint);\n bytes.push(...Buffer.from(character, 'utf8'));\n index += character.length;\n }\n let decoded: string;\n try {\n decoded = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));\n } catch {\n throw new Error(`Invalid UTF-8 layout escape in ${JSON.stringify(value)}`);\n }\n if (encodeLayoutSegment(decoded) !== value)\n throw new Error(`Non-canonical layout encoding in ${JSON.stringify(value)}`);\n return decoded;\n}\n\n/** Decode one component. Identity fallbacks need the exact semantic name stored in the document. */\nexport function decodeLayoutSegment(value: string, exactNameOverride?: string): string {\n if (!value) throw new Error('Layout segment must not be empty');\n const fallback = value.match(FALLBACK_TOKEN);\n if (!fallback) return decodeCanonicalSegment(value);\n if (exactNameOverride === undefined)\n throw new Error(`Layout fallback ${JSON.stringify(value)} requires an exact name override`);\n const withoutFallback = value.slice(0, fallback.index) + value.slice(fallback.index! + fallback[0].length);\n if (withoutFallback) decodeCanonicalSegment(withoutFallback);\n return exactNameOverride;\n}\n\n/** Decode an allocated component to its semantic name under an explicit role and extension contract. */\nexport function decodeLayoutName(\n value: string,\n role: Exclude<LayoutPathRole, 'control'>,\n extension: string,\n exactNameOverride?: string,\n): string {\n validateExtension(extension);\n const fallback = value.match(FALLBACK_TOKEN);\n if (fallback && !fallback[0].startsWith(`~${role}-`))\n throw new Error(`Layout fallback ${JSON.stringify(value)} does not belong to role ${role}`);\n const physical = fallback\n ? value.slice(0, fallback.index) + value.slice(fallback.index! + fallback[0].length)\n : value;\n const decoded = physical ? decodeCanonicalSegment(physical) : '';\n if (!decoded.endsWith(extension))\n throw new Error(\n `Layout component ${JSON.stringify(value)} does not use extension ${JSON.stringify(extension)}`,\n );\n if (fallback && exactNameOverride === undefined)\n throw new Error(`Layout fallback ${JSON.stringify(value)} requires an exact name override`);\n const filename = decoded.slice(0, decoded.length - extension.length);\n // Without a fallback the override only keeps the exact spelling of a name a filesystem may\n // normalize; a filename that names something else is the author's rename, and it wins.\n if (\n !fallback &&\n exactNameOverride !== undefined &&\n exactNameOverride.normalize('NFC') !== filename.normalize('NFC')\n )\n return filename;\n return exactNameOverride ?? filename;\n}\n\n/** A conservative key for filesystems that fold case or normalize Unicode. */\nexport function layoutCollisionKey(value: string): string {\n return value.normalize('NFKC').toUpperCase().normalize('NFC');\n}\n\n/** True when a filesystem can change the canonical spelling without changing the name. */\nexport function layoutNameNeedsOverride(value: string): boolean {\n return value.normalize('NFC') !== value.normalize('NFD');\n}\n\nfunction assertEscapeSyntax(component: string): void {\n for (let index = component.indexOf('~'); index >= 0; index = component.indexOf('~', index)) {\n if (/^[0-9A-F]{2}$/.test(component.slice(index + 1, index + 3))) {\n index += 3;\n continue;\n }\n const fallback = component.slice(index).match(new RegExp(`^${FALLBACK_TOKEN.source}`));\n if (!fallback) throw new Error(`Malformed layout escape in ${JSON.stringify(component)}`);\n index += fallback[0].length;\n }\n}\n\nfunction assertPortableComponent(component: string): void {\n assertUnicode(component);\n if (!component || component === '.' || component === '..' || hasUnsafeCharacter(component, false))\n throw new Error(`Unsafe layout path component: ${JSON.stringify(component)}`);\n if (/[. ]$/.test(component) || DEVICE_NAME.test(component) || TEMPORARY_NAME.test(component))\n throw new Error(`Non-portable layout path component: ${JSON.stringify(component)}`);\n if (byteLength(component) > MAX_LAYOUT_COMPONENT_BYTES)\n throw new Error(\n `Layout path component exceeds ${MAX_LAYOUT_COMPONENT_BYTES} bytes: ${JSON.stringify(component)}`,\n );\n assertEscapeSyntax(component);\n}\n\n/** Parse a portable workspace-root-relative pointer without consulting the filesystem. */\nexport function parseWorkspacePointer(value: string): string {\n if (!value || value.startsWith('/') || value.startsWith('\\\\') || /^[A-Za-z]:/.test(value))\n throw new Error(`Workspace pointer must be relative: ${JSON.stringify(value)}`);\n const components = value.split('/');\n for (const component of components) assertPortableComponent(component);\n if (byteLength(value) > MAX_LAYOUT_PATH_BYTES)\n throw new Error(`Workspace pointer exceeds ${MAX_LAYOUT_PATH_BYTES} bytes: ${JSON.stringify(value)}`);\n return components.join('/');\n}\n\nfunction joinLayoutPath(directory: string, component: string): string {\n return directory ? `${directory}/${component}` : component;\n}\n\nfunction fallbackToken(role: LayoutPathRole, identity: string): string {\n if (!/^[a-z][a-z0-9_]{0,23}$/.test(role)) throw new Error(`Invalid layout fallback role: ${role}`);\n if (!identity) throw new Error('A stable identity is required for layout fallback');\n const suffix = /^[0-9]{1,32}$/.test(identity)\n ? identity\n : `h${createHash('sha256').update(identity).digest('hex').slice(0, 20)}`;\n return `~${role}-${suffix}`;\n}\n\nfunction validateExtension(extension: string): void {\n if (\n extension &&\n (!extension.startsWith('.') ||\n hasUnsafeCharacter(extension, true) ||\n extension.includes(' ') ||\n encodeLayoutSegment(`x${extension}`) !== `x${extension}`)\n )\n throw new Error(`Invalid layout extension: ${JSON.stringify(extension)}`);\n}\n\nfunction invalidRequest(message: string): LayoutPathAllocationError {\n return new LayoutPathAllocationError('invalid-request', message);\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Replay a stored placement request against its stored claims. A representation-fallback proof is\n * valid only when the allocator still cannot represent the request.\n */\nexport function provesUnrepresentableRequest(\n request: LayoutPathRequest,\n existingClaims: readonly LayoutPathClaim[],\n): boolean {\n let allocator: LayoutPathAllocator;\n try {\n allocator = new LayoutPathAllocator([...existingClaims]);\n } catch {\n return false;\n }\n try {\n allocator.allocate(request);\n return false;\n } catch (error) {\n return error instanceof LayoutPathAllocationError && error.reason === 'unrepresentable';\n }\n}\n\nexport function normalizeRequiredLayoutChildren(\n request: Pick<LayoutPathRequest, 'role' | 'kind' | 'requiredChildren'>,\n): LayoutRequiredControl[] {\n if (request.requiredChildren === undefined) return [];\n const kind = request.kind ?? (request.role === 'directory' ? 'directory' : 'file');\n if (request.role !== 'directory' || kind !== 'directory')\n throw invalidRequest('Only directory requests can require layout controls');\n if (!Array.isArray(request.requiredChildren)) throw invalidRequest('Required layout controls must be a list');\n const controls = request.requiredChildren as readonly unknown[];\n const allowed = new Set<LayoutRequiredControl>(['_folder.json']);\n if (controls.some((control) => typeof control !== 'string' || !allowed.has(control as LayoutRequiredControl)))\n throw invalidRequest('Required layout controls must be reserved leaf names');\n if (new Set(controls).size !== controls.length) throw invalidRequest('Required layout controls must be unique');\n return (['_folder.json'] as const).filter((control) => controls.includes(control));\n}\n\n/** Directory a `_folder.json` control belongs to. */\nexport function folderDirectory(folderControl: string): string {\n return folderControl.slice(0, -'/_folder.json'.length);\n}\n\nexport function parentDirectory(file: string): string {\n return file.slice(0, file.lastIndexOf('/'));\n}\n\nfunction candidateFits(\n component: string,\n candidate: string,\n requiredChildren: readonly LayoutRequiredControl[],\n companion: string,\n): boolean {\n return (\n byteLength(component) + byteLength(companion) <= MAX_LAYOUT_COMPONENT_BYTES &&\n byteLength(candidate) + byteLength(companion) <= MAX_LAYOUT_PATH_BYTES &&\n requiredChildren.every((child) => byteLength(joinLayoutPath(candidate, child)) <= MAX_LAYOUT_PATH_BYTES)\n );\n}\n\nconst ROLE_PRIORITY: Record<Exclude<LayoutPathRole, 'control'>, number> = {\n directory: 0,\n raw: 1,\n attachment: 2,\n document: 3,\n};\n\ninterface ValidatedLayoutPathRequest {\n directory: string;\n extension: string;\n kind: LayoutPathKind;\n ordinaryComponent: string;\n requiredChildren: LayoutRequiredControl[];\n /** The suffix of the control file this allocation also claims: a raw file's sidecar. */\n companion: string;\n}\n\nfunction validLayoutKind(value: unknown): value is LayoutPathKind {\n return value === 'file' || value === 'directory';\n}\n\nfunction validRequestRole(value: unknown): value is LayoutPathRequest['role'] {\n return typeof value === 'string' && Object.prototype.hasOwnProperty.call(ROLE_PRIORITY, value);\n}\n\nfunction validateLayoutPathRequest(request: LayoutPathRequest): ValidatedLayoutPathRequest {\n try {\n if (typeof request.directory !== 'string') throw invalidRequest('A layout directory must be a string');\n if (typeof request.name !== 'string' || !request.name)\n throw invalidRequest('A semantic name is required for layout allocation');\n if (typeof request.identity !== 'string' || !request.identity)\n throw invalidRequest('A stable identity is required for layout allocation');\n if (request.extension !== undefined && typeof request.extension !== 'string')\n throw invalidRequest('A layout extension must be a string');\n if (!validRequestRole(request.role)) throw invalidRequest('Layout request has an invalid role');\n if (request.kind !== undefined && !validLayoutKind(request.kind))\n throw invalidRequest('Layout request has an invalid kind');\n\n const kind = request.kind ?? (request.role === 'directory' ? 'directory' : 'file');\n if ((request.role === 'directory') !== (kind === 'directory'))\n throw invalidRequest(`Layout role ${request.role} cannot claim a ${kind}`);\n const requiredChildren = normalizeRequiredLayoutChildren(request);\n const directory = request.directory ? parseWorkspacePointer(request.directory) : '';\n const extension = request.extension ?? '';\n validateExtension(extension);\n return {\n directory,\n extension,\n kind,\n requiredChildren,\n companion: request.role === 'raw' ? RAW_SIDECAR_SUFFIX : '',\n ordinaryComponent: encodeLayoutSegment(request.name + extension),\n };\n } catch (error) {\n if (error instanceof LayoutPathAllocationError) throw error;\n throw invalidRequest(errorMessage(error));\n }\n}\n\n/** The proper ancestors of a collision key: every prefix that ends right before a `/`. */\nexport function collisionAncestors(key: string): string[] {\n const ancestors: string[] = [];\n for (let index = key.indexOf('/'); index >= 0; index = key.indexOf('/', index + 1))\n ancestors.push(key.slice(0, index));\n return ancestors;\n}\n\nexport class LayoutPathAllocator {\n private readonly claims: LayoutPathClaim[] = [];\n private readonly directorySpellings = new Map<string, string>();\n /** Per collision key, the earliest claim with that key; a conflict names the earliest claim. */\n private readonly firstByKey = new Map<string, number>();\n private readonly firstFileByKey = new Map<string, number>();\n /** Per collision key, the earliest claim strictly beneath it. */\n private readonly firstBeneath = new Map<string, number>();\n\n public constructor(existing: LayoutPathClaim[] = []) {\n for (const claim of existing) this.claim(claim);\n }\n\n public claim(claim: LayoutPathClaim): void {\n if (typeof claim.path !== 'string') throw invalidRequest('A layout claim path must be a string');\n if (typeof claim.identity !== 'string' || !claim.identity)\n throw invalidRequest('A stable identity is required for a layout claim');\n if (!validLayoutKind(claim.kind)) throw invalidRequest('Layout claim has an invalid kind');\n if (!(validRequestRole(claim.role) || claim.role === 'control'))\n throw invalidRequest('Layout claim has an invalid role');\n if (claim.role === 'control' && claim.kind !== 'file') throw invalidRequest('Layout controls must claim files');\n if ((claim.role === 'directory') !== (claim.kind === 'directory'))\n throw invalidRequest(`Layout role ${claim.role} cannot claim a ${claim.kind}`);\n let normalized: string;\n try {\n normalized = parseWorkspacePointer(claim.path);\n } catch (error) {\n throw invalidRequest(errorMessage(error));\n }\n const directories = this.directoriesFor(normalized, claim.kind);\n this.assertDirectorySpellings(directories);\n const conflict = this.conflict(normalized, claim.kind);\n if (conflict)\n throw invalidRequest(\n `Layout path ${JSON.stringify(normalized)} conflicts with ${JSON.stringify(conflict.path)}`,\n );\n this.record({ ...claim, path: normalized });\n for (const directory of directories)\n if (!this.directorySpellings.has(layoutCollisionKey(directory)))\n this.directorySpellings.set(layoutCollisionKey(directory), directory);\n }\n\n public allocate(request: LayoutPathRequest): AllocatedLayoutPath {\n const { directory, extension, kind, ordinaryComponent, requiredChildren, companion } =\n validateLayoutPathRequest(request);\n this.assertDirectorySpellings(\n directory ? directory.split('/').map((_, index, all) => all.slice(0, index + 1).join('/')) : [],\n );\n const ordinaryPath = joinLayoutPath(directory, ordinaryComponent);\n if (\n candidateFits(ordinaryComponent, ordinaryPath, requiredChildren, companion) &&\n !this.conflict(ordinaryPath, kind) &&\n !(companion && this.conflict(`${ordinaryPath}${companion}`, 'file'))\n ) {\n const nameOverride = layoutNameNeedsOverride(request.name) ? request.name : undefined;\n if (decodeLayoutName(ordinaryComponent, request.role, extension, nameOverride) !== request.name)\n throw new Error(\n `Layout codec did not preserve the semantic name for ${request.role}/${request.identity}`,\n );\n const allocated = { ...request, path: ordinaryPath, kind, fallback: false, nameOverride };\n this.claim(allocated);\n this.claimCompanion(allocated, companion);\n return allocated;\n }\n\n const token = fallbackToken(request.role, request.identity);\n const ordinaryStem = extension\n ? ordinaryComponent.slice(0, ordinaryComponent.length - extension.length)\n : ordinaryComponent;\n let component = `${ordinaryStem}${token}${extension}`;\n if (byteLength(component) > MAX_LAYOUT_COMPONENT_BYTES) component = `${token}${extension}`;\n const fallbackPath = joinLayoutPath(directory, component);\n if (!candidateFits(component, fallbackPath, requiredChildren, companion))\n throw new LayoutPathAllocationError(\n 'unrepresentable',\n `Layout path cannot fit the portable budget for ${request.role}/${request.identity}`,\n );\n const conflict =\n this.conflict(fallbackPath, kind) ??\n (companion ? this.conflict(`${fallbackPath}${companion}`, 'file') : undefined);\n if (conflict)\n throw new LayoutPathAllocationError(\n 'unrepresentable',\n `Stable layout fallback ${JSON.stringify(fallbackPath)} conflicts with ${JSON.stringify(conflict.path)}`,\n );\n if (decodeLayoutName(component, request.role, extension, request.name) !== request.name)\n throw new Error(`Layout codec did not preserve the semantic name for ${request.role}/${request.identity}`);\n const allocated = {\n ...request,\n path: fallbackPath,\n kind,\n fallback: true,\n nameOverride: request.name,\n };\n this.claim(allocated);\n this.claimCompanion(allocated, companion);\n return allocated;\n }\n\n public snapshot(): LayoutPathClaim[] {\n return this.claims.map((claim) => ({ ...claim }));\n }\n\n /** A raw allocation owns its sidecar too, so nothing else can take the path beside its bytes. */\n private claimCompanion(allocated: AllocatedLayoutPath, companion: string): void {\n if (!companion) return;\n this.claim({\n path: `${allocated.path}${companion}`,\n kind: 'file',\n role: 'control',\n identity: `${allocated.identity}:sidecar`,\n });\n }\n\n private record(claim: LayoutPathClaim): void {\n const position = this.claims.length;\n this.claims.push(claim);\n const key = layoutCollisionKey(claim.path);\n if (!this.firstByKey.has(key)) this.firstByKey.set(key, position);\n if (claim.kind === 'file' && !this.firstFileByKey.has(key)) this.firstFileByKey.set(key, position);\n for (const ancestor of collisionAncestors(key))\n if (!this.firstBeneath.has(ancestor)) this.firstBeneath.set(ancestor, position);\n }\n\n /**\n * The earliest claim the candidate collides with: the same key, a file claim above it, or, for a\n * file candidate, any claim beneath it.\n */\n private conflict(candidate: string, kind: LayoutPathKind): LayoutPathClaim | undefined {\n const key = layoutCollisionKey(candidate);\n const positions = [\n this.firstByKey.get(key),\n ...collisionAncestors(key).map((ancestor) => this.firstFileByKey.get(ancestor)),\n kind === 'file' ? this.firstBeneath.get(key) : undefined,\n ].filter((position): position is number => position !== undefined);\n return positions.length > 0 ? this.claims[Math.min(...positions)] : undefined;\n }\n\n private directoriesFor(value: string, kind: LayoutPathKind): string[] {\n const components = value.split('/');\n const length = kind === 'directory' ? components.length : components.length - 1;\n return Array.from({ length }, (_, index) => components.slice(0, index + 1).join('/'));\n }\n\n private assertDirectorySpellings(directories: string[]): void {\n for (const directory of directories) {\n const existing = this.directorySpellings.get(layoutCollisionKey(directory));\n if (existing !== undefined && existing !== directory)\n throw invalidRequest(\n `Layout directory spelling ${JSON.stringify(directory)} conflicts with ${JSON.string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