farseer-cli 1.15.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 (55) 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/commands/model.js +14 -4
  5. package/dist/commands/model.js.map +2 -2
  6. package/dist/index.js +16 -0
  7. package/dist/index.js.map +2 -2
  8. package/dist/pipeline/generated-reference.json +30 -30
  9. package/dist/pipeline/service.js +2 -2
  10. package/dist/pipeline/service.js.map +2 -2
  11. package/dist/services/codefirst/api.js +269 -0
  12. package/dist/services/codefirst/api.js.map +7 -0
  13. package/dist/services/codefirst/binaryDisk.js +67 -0
  14. package/dist/services/codefirst/binaryDisk.js.map +7 -0
  15. package/dist/services/codefirst/byteHashes.js +129 -0
  16. package/dist/services/codefirst/byteHashes.js.map +7 -0
  17. package/dist/services/codefirst/documents.js +563 -0
  18. package/dist/services/codefirst/documents.js.map +7 -0
  19. package/dist/services/codefirst/layoutBinaryProjection.js +974 -0
  20. package/dist/services/codefirst/layoutBinaryProjection.js.map +7 -0
  21. package/dist/services/codefirst/layoutCompose.js +593 -0
  22. package/dist/services/codefirst/layoutCompose.js.map +7 -0
  23. package/dist/services/codefirst/layoutCore.js +260 -0
  24. package/dist/services/codefirst/layoutCore.js.map +7 -0
  25. package/dist/services/codefirst/layoutPaths.js +492 -0
  26. package/dist/services/codefirst/layoutPaths.js.map +7 -0
  27. package/dist/services/codefirst/layoutProjection.js +995 -0
  28. package/dist/services/codefirst/layoutProjection.js.map +7 -0
  29. package/dist/services/codefirst/layoutReadback.js +2552 -0
  30. package/dist/services/codefirst/layoutReadback.js.map +7 -0
  31. package/dist/services/codefirst/layoutReadbackPlacement.js +1517 -0
  32. package/dist/services/codefirst/layoutReadbackPlacement.js.map +7 -0
  33. package/dist/services/codefirst/layoutReceipt.js +1592 -0
  34. package/dist/services/codefirst/layoutReceipt.js.map +7 -0
  35. package/dist/services/codefirst/layoutScan.js +882 -0
  36. package/dist/services/codefirst/layoutScan.js.map +7 -0
  37. package/dist/services/codefirst/output.js +179 -0
  38. package/dist/services/codefirst/output.js.map +7 -0
  39. package/dist/services/codefirst/types.js +17 -0
  40. package/dist/services/codefirst/types.js.map +7 -0
  41. package/dist/services/codefirst/workflow.js +581 -0
  42. package/dist/services/codefirst/workflow.js.map +7 -0
  43. package/dist/services/codefirst/workspace.js +310 -0
  44. package/dist/services/codefirst/workspace.js.map +7 -0
  45. package/dist/services/codefirst/workspaceLock.js +148 -0
  46. package/dist/services/codefirst/workspaceLock.js.map +7 -0
  47. package/dist/services/codefirst/workspaceRoot.js +147 -0
  48. package/dist/services/codefirst/workspaceRoot.js.map +7 -0
  49. package/dist/utils/logger.js +9 -3
  50. package/dist/utils/logger.js.map +2 -2
  51. package/docs/pipeline-client-guide.md +2 -2
  52. package/docs/pipeline-reference.md +156 -99
  53. package/package.json +3 -2
  54. package/skills/pipeline-authoring/SKILL.md +10 -8
  55. package/skills/pipeline-authoring/practices.md +39 -25
@@ -0,0 +1,882 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var layoutScan_exports = {};
30
+ __export(layoutScan_exports, {
31
+ captureLayoutWorkspace: () => captureLayoutWorkspace,
32
+ captureLayoutWorkspaceSeed: () => captureLayoutWorkspaceSeed,
33
+ hashLayoutPath: () => hashLayoutPath,
34
+ loadLayoutByteEvidence: () => loadLayoutByteEvidence,
35
+ probeLayoutPath: () => probeLayoutPath,
36
+ resolveLayoutPath: () => resolveLayoutPath,
37
+ sameValue: () => sameValue,
38
+ scanLayout: () => scanLayout,
39
+ stateText: () => stateText
40
+ });
41
+ module.exports = __toCommonJS(layoutScan_exports);
42
+ var fs = __toESM(require("fs"));
43
+ var path = __toESM(require("path"));
44
+ var import_byteHashes = require("./byteHashes");
45
+ var import_documents = require("./documents");
46
+ var import_layoutCore = require("./layoutCore");
47
+ var import_layoutPaths = require("./layoutPaths");
48
+ var import_workspace = require("./workspace");
49
+ const FOLDER_CONTROL = "_folder.json";
50
+ const RETIRED_MANIFEST = "_files.json";
51
+ function pointerTarget(value, artifact, addDiagnostic) {
52
+ const target = (0, import_layoutCore.isObject)(value) && typeof value.file === "string" ? value.file : void 0;
53
+ if (target === void 0) return void 0;
54
+ try {
55
+ return (0, import_layoutPaths.parseWorkspacePointer)(target);
56
+ } catch (error) {
57
+ addDiagnostic("unsafe-pointer", artifact.path, error.message);
58
+ return void 0;
59
+ }
60
+ }
61
+ function addSharePointerToArtifact(artifact, value, field, present, addDiagnostic) {
62
+ const target = pointerTarget(value, artifact, addDiagnostic);
63
+ if (target === void 0) return;
64
+ if (!/^access\/shares\/[^/]+\.json$/.test(target)) {
65
+ addDiagnostic("invalid-share-pointer", artifact.path, `Share pointer is outside access/shares`, target);
66
+ return;
67
+ }
68
+ (artifact.pointers ??= []).push({ kind: "share", field, path: target, present: present(target) });
69
+ }
70
+ function decodeArtifactName(artifact, component, role, extension, value, addDiagnostic) {
71
+ const override = (0, import_layoutCore.isObject)(value) && typeof value.name === "string" ? value.name : void 0;
72
+ try {
73
+ artifact.decodedName = (0, import_layoutPaths.decodeLayoutName)(component, role, extension, override);
74
+ if (override !== void 0 && artifact.decodedName !== override) artifact.ignoredNameOverride = override;
75
+ } catch (error) {
76
+ addDiagnostic("invalid-layout-name", artifact.path, error.message);
77
+ }
78
+ }
79
+ function buildRawArtifact(sidecar, value, present, sharePresent, addDiagnostic) {
80
+ const bytes = (0, import_layoutPaths.rawBytesPath)(sidecar);
81
+ const artifact = {
82
+ path: bytes,
83
+ kind: "file",
84
+ role: "raw",
85
+ present,
86
+ source: sidecar,
87
+ json: value
88
+ };
89
+ decodeArtifactName(artifact, bytes.slice(bytes.lastIndexOf("/") + 1), "raw", "", value, addDiagnostic);
90
+ if ((0, import_layoutCore.isObject)(value)) addSharePointerToArtifact(artifact, value.shares, "shares", sharePresent, addDiagnostic);
91
+ return artifact;
92
+ }
93
+ function finalizeScanResult(artifacts, tracked, opaqueDirectories, localOnlyFiles, diagnostics, unmanageableDirectories = []) {
94
+ const uniqueDiagnostics = /* @__PURE__ */ new Map();
95
+ for (const diagnostic of diagnostics)
96
+ uniqueDiagnostics.set(`${diagnostic.code}\0${diagnostic.path}\0${diagnostic.relatedPath ?? ""}`, diagnostic);
97
+ artifacts.sort((left, right) => (0, import_layoutCore.compareText)(left.path, right.path) || (0, import_layoutCore.compareText)(left.role, right.role));
98
+ tracked.sort((left, right) => (0, import_layoutCore.compareText)(left.route, right.route));
99
+ const unmanageable = [...unmanageableDirectories].sort(import_layoutCore.compareText);
100
+ return {
101
+ artifacts,
102
+ tracked,
103
+ opaqueDirectories: [...opaqueDirectories].sort(import_layoutCore.compareText),
104
+ localOnlyFiles: [...localOnlyFiles].sort(import_layoutCore.compareText),
105
+ ...unmanageable.length > 0 ? { unmanageableDirectories: unmanageable } : {},
106
+ diagnostics: [...uniqueDiagnostics.values()].sort(
107
+ (left, right) => (0, import_layoutCore.compareText)(left.path, right.path) || (0, import_layoutCore.compareText)(left.code, right.code)
108
+ )
109
+ };
110
+ }
111
+ function physicalLayoutClaims(scan) {
112
+ const claims = /* @__PURE__ */ new Map();
113
+ const add = (claim) => claims.set(`${claim.kind}\0${claim.path}`, claim);
114
+ const addDirectories = (relative, includeLeaf) => {
115
+ const parts = relative.split("/");
116
+ const length = includeLeaf ? parts.length : parts.length - 1;
117
+ for (let index = 1; index <= length; index++) {
118
+ const directory = parts.slice(0, index).join("/");
119
+ add({ path: directory, kind: "directory", role: "directory", identity: `physical:${directory}` });
120
+ }
121
+ };
122
+ const addFile = (relative, role) => {
123
+ addDirectories(relative, false);
124
+ add({ path: relative, kind: "file", role, identity: `physical:${relative}` });
125
+ };
126
+ for (const artifact of scan.artifacts) {
127
+ if (!artifact.present) continue;
128
+ const role = artifact.role === "raw" ? "raw" : artifact.role === "attachment" ? "attachment" : ["folder-control", "raw-metadata"].includes(artifact.role) ? "control" : "document";
129
+ addFile(artifact.path, role);
130
+ }
131
+ for (const relative of scan.localOnlyFiles) addFile(relative, "document");
132
+ for (const directory of scan.opaqueDirectories) {
133
+ addDirectories(directory, true);
134
+ }
135
+ return [...claims.values()];
136
+ }
137
+ function scanLayout(input) {
138
+ const root = path.resolve(input.root);
139
+ const artifacts = [];
140
+ const diagnostics = [];
141
+ const opaqueDirectories = /* @__PURE__ */ new Set();
142
+ const unmanageableDirectories = /* @__PURE__ */ new Set();
143
+ const localOnlyFiles = /* @__PURE__ */ new Set();
144
+ const occupants = /* @__PURE__ */ new Map();
145
+ const firstOccupiedBeneath = /* @__PURE__ */ new Map();
146
+ const occupiedOrder = /* @__PURE__ */ new Map();
147
+ const claims = /* @__PURE__ */ new Map();
148
+ const allocator = new import_layoutPaths.LayoutPathAllocator();
149
+ const pendingAttachments = [];
150
+ const trackedMarkerDirectories = /* @__PURE__ */ new Set();
151
+ const trackedPaths = new Set(
152
+ input.tracked.flatMap(
153
+ (item) => item.path.split("/").map((_, index, parts) => parts.slice(0, index + 1).join("/"))
154
+ )
155
+ );
156
+ const addDiagnostic = (code, relative, message, relatedPath) => {
157
+ diagnostics.push({ code, path: relative, message, ...relatedPath ? { relatedPath } : {} });
158
+ };
159
+ const rootFailure = () => ({
160
+ artifacts: [],
161
+ tracked: input.tracked.map((tracked2) => ({
162
+ route: tracked2.route,
163
+ path: tracked2.path,
164
+ status: "missing-subtree"
165
+ })).sort((left, right) => (0, import_layoutCore.compareText)(left.route, right.route)),
166
+ opaqueDirectories: [],
167
+ localOnlyFiles: [],
168
+ diagnostics
169
+ });
170
+ let rootStat;
171
+ try {
172
+ rootStat = fs.lstatSync(root);
173
+ } catch (error) {
174
+ if (error.code === "ENOENT") return rootFailure();
175
+ addDiagnostic("filesystem-error", ".", `Cannot inspect workspace root`);
176
+ return rootFailure();
177
+ }
178
+ if (rootStat.isSymbolicLink()) {
179
+ addDiagnostic("symlink", ".", `Workspace root is a symlink`);
180
+ return rootFailure();
181
+ }
182
+ if (!rootStat.isDirectory()) {
183
+ addDiagnostic("path-role-overlap", ".", `Workspace root is not a directory`);
184
+ return rootFailure();
185
+ }
186
+ const absolute = (relative) => {
187
+ const resolved = path.resolve(root, ...relative.split("/"));
188
+ const fromRoot = path.relative(root, resolved);
189
+ if (fromRoot === ".." || fromRoot.startsWith(`..${path.sep}`) || path.isAbsolute(fromRoot))
190
+ throw new Error(`Path escapes workspace root: ${relative}`);
191
+ return resolved;
192
+ };
193
+ const lstat = (relative) => {
194
+ try {
195
+ return fs.lstatSync(absolute(relative));
196
+ } catch (error) {
197
+ if (error.code === "ENOENT") return void 0;
198
+ addDiagnostic("filesystem-error", relative, `Cannot inspect ${relative}`);
199
+ return void 0;
200
+ }
201
+ };
202
+ const recordOccupant = (occupant) => {
203
+ const key = (0, import_layoutPaths.layoutCollisionKey)(occupant.path);
204
+ const group = occupants.get(key);
205
+ if (group) {
206
+ group.push(occupant);
207
+ return;
208
+ }
209
+ occupants.set(key, [occupant]);
210
+ occupiedOrder.set(key, occupiedOrder.size);
211
+ for (const ancestor of (0, import_layoutPaths.collisionAncestors)(key))
212
+ if (!firstOccupiedBeneath.has(ancestor)) firstOccupiedBeneath.set(ancestor, key);
213
+ };
214
+ const physicalEntries = (directory) => {
215
+ const stat = lstat(directory);
216
+ if (!stat) return void 0;
217
+ if (stat.isSymbolicLink()) {
218
+ addDiagnostic("symlink", directory, `Managed path is a symlink: ${directory}`);
219
+ return void 0;
220
+ }
221
+ if (!stat.isDirectory()) {
222
+ addDiagnostic("path-role-overlap", directory, `Expected a directory: ${directory}`);
223
+ return void 0;
224
+ }
225
+ claim(directory, "directory", "directory", `directory:${directory}`);
226
+ let entries;
227
+ try {
228
+ entries = fs.readdirSync(absolute(directory), { withFileTypes: true });
229
+ } catch {
230
+ addDiagnostic("filesystem-error", directory, `Cannot read directory ${directory}`);
231
+ return void 0;
232
+ }
233
+ entries = entries.filter(
234
+ (entry) => !(0, import_layoutPaths.isIgnoredLayoutName)(entry.name) || trackedPaths.has(`${directory}/${entry.name}`)
235
+ );
236
+ entries.sort((left, right) => (0, import_layoutCore.compareText)(left.name, right.name));
237
+ for (const entry of entries) {
238
+ const relative = `${directory}/${entry.name}`;
239
+ recordOccupant({
240
+ path: relative,
241
+ kind: entry.isSymbolicLink() ? "symlink" : entry.isDirectory() ? "directory" : "file"
242
+ });
243
+ }
244
+ return entries;
245
+ };
246
+ const claim = (relative, kind, role, source) => {
247
+ let normalized;
248
+ try {
249
+ normalized = (0, import_layoutPaths.parseWorkspacePointer)(relative);
250
+ } catch (error) {
251
+ addDiagnostic("unsafe-managed-path", relative, error.message);
252
+ return false;
253
+ }
254
+ const key = (0, import_layoutPaths.layoutCollisionKey)(normalized);
255
+ const previous = claims.get(key);
256
+ if (previous) {
257
+ if (previous.path === normalized && previous.role === role && role === "directory") return true;
258
+ addDiagnostic(
259
+ "duplicate-claim",
260
+ normalized,
261
+ `Path is claimed as both ${previous.role} and ${role}`,
262
+ previous.source
263
+ );
264
+ return false;
265
+ }
266
+ const beneath = kind === "file" ? firstOccupiedBeneath.get(key) : void 0;
267
+ const aliases = [
268
+ {
269
+ key,
270
+ occupant: occupants.get(key)?.find((item) => item.path !== normalized || item.kind !== kind && item.kind !== "symlink")
271
+ },
272
+ ...(0, import_layoutPaths.collisionAncestors)(key).map((ancestor) => ({
273
+ key: ancestor,
274
+ occupant: occupants.get(ancestor)?.find((item) => item.kind === "file" || item.kind === "symlink")
275
+ })),
276
+ ...beneath ? [{ key: beneath, occupant: occupants.get(beneath)[0] }] : []
277
+ ].filter((alias) => alias.occupant !== void 0);
278
+ if (aliases.length > 0) {
279
+ const { occupant } = aliases.reduce(
280
+ (first, alias) => occupiedOrder.get(alias.key) < occupiedOrder.get(first.key) ? alias : first
281
+ );
282
+ addDiagnostic(
283
+ "path-alias",
284
+ normalized,
285
+ `Managed claim conflicts with local ${occupant.kind}`,
286
+ occupant.path
287
+ );
288
+ return false;
289
+ }
290
+ try {
291
+ allocator.claim({ path: normalized, kind, role, identity: source });
292
+ } catch (error) {
293
+ addDiagnostic("path-role-overlap", normalized, error.message);
294
+ return false;
295
+ }
296
+ claims.set(key, { path: normalized, role, source });
297
+ return true;
298
+ };
299
+ const parseJson = (relative) => {
300
+ try {
301
+ return JSON.parse(fs.readFileSync(absolute(relative), "utf8"));
302
+ } catch {
303
+ addDiagnostic("malformed-json", relative, `Invalid JSON in ${relative}`);
304
+ return void 0;
305
+ }
306
+ };
307
+ const probe = (relative) => {
308
+ let current = "";
309
+ const parts = relative.split("/");
310
+ for (let index = 0; index < parts.length; index++) {
311
+ current = current ? `${current}/${parts[index]}` : parts[index];
312
+ const stat = lstat(current);
313
+ if (!stat) return { present: false, symlink: false, missingAncestor: current };
314
+ if (stat.isSymbolicLink()) return { present: true, symlink: true, symlinkPath: current };
315
+ if (index < parts.length - 1 && !stat.isDirectory())
316
+ return { present: false, symlink: false, missingAncestor: current };
317
+ }
318
+ return { present: true, symlink: false };
319
+ };
320
+ const addSharePointer = (artifact, value, field) => {
321
+ addSharePointerToArtifact(artifact, value, field, (target) => probe(target).present, addDiagnostic);
322
+ };
323
+ const addAttachmentPointer = (artifact, value, field) => {
324
+ const target = pointerTarget(value, artifact, addDiagnostic);
325
+ if (target !== void 0) pendingAttachments.push({ owner: artifact, field, path: target });
326
+ };
327
+ const decodeSuppliedName = (artifact, component, role, extension, value) => {
328
+ decodeArtifactName(artifact, component, role, extension, value, addDiagnostic);
329
+ };
330
+ const readArtifact = (relative, role) => {
331
+ claim(
332
+ relative,
333
+ "file",
334
+ role === "folder-control" || role === "raw-metadata" ? "control" : "document",
335
+ relative
336
+ );
337
+ const json = parseJson(relative);
338
+ const artifact = { path: relative, kind: "file", role, present: true, json };
339
+ artifacts.push(artifact);
340
+ return artifact;
341
+ };
342
+ const inspectSymlink = (relative) => {
343
+ addDiagnostic("symlink", relative, `Managed path is a symlink: ${relative}`);
344
+ };
345
+ const retiredManifest = (name, relative) => {
346
+ if ((0, import_layoutPaths.layoutCollisionKey)(name) !== (0, import_layoutPaths.layoutCollisionKey)(RETIRED_MANIFEST)) return false;
347
+ addDiagnostic("retired-file-manifest", relative, `delete it and run farseer code pull --force`);
348
+ return true;
349
+ };
350
+ const scanSidecar = (sidecarPath) => {
351
+ const artifact = readArtifact(sidecarPath, "raw-metadata");
352
+ const value = artifact.json;
353
+ if (!(0, import_layoutCore.isObject)(value)) {
354
+ addDiagnostic("malformed-control", sidecarPath, `Invalid raw sidecar in ${sidecarPath}`);
355
+ return;
356
+ }
357
+ const bytes = (0, import_layoutPaths.rawBytesPath)(sidecarPath);
358
+ const state = probe(bytes);
359
+ if (state.symlink) inspectSymlink(bytes);
360
+ const isFile = state.present && !state.symlink && !!lstat(bytes)?.isFile();
361
+ if (state.present && !state.symlink && !isFile)
362
+ addDiagnostic("path-role-overlap", bytes, `Raw sidecar target is not a file`);
363
+ claim(bytes, "file", "raw", sidecarPath);
364
+ artifacts.push(buildRawArtifact(sidecarPath, value, isFile, (target) => probe(target).present, addDiagnostic));
365
+ localOnlyFiles.delete(bytes);
366
+ };
367
+ const sidecarNames = (entries) => {
368
+ const claimed = /* @__PURE__ */ new Map();
369
+ for (const entry of entries)
370
+ if (entry.isFile() && (0, import_layoutPaths.isRawSidecarPath)(entry.name))
371
+ claimed.set(entry.name.slice(0, -import_layoutPaths.RAW_SIDECAR_SUFFIX.length), entry.name);
372
+ return claimed;
373
+ };
374
+ const scanManagedDirectory = (directory) => {
375
+ const entries = physicalEntries(directory);
376
+ if (!entries) return;
377
+ const names = new Map(entries.map((entry) => [entry.name, entry]));
378
+ for (const entry of entries) if (entry.isSymbolicLink()) inspectSymlink(`${directory}/${entry.name}`);
379
+ const markerPath = `${directory}/${FOLDER_CONTROL}`;
380
+ const marker = names.get(FOLDER_CONTROL);
381
+ if (marker && !marker.isFile()) addDiagnostic("path-role-overlap", markerPath, `Folder control is not a file`);
382
+ if (marker?.isFile()) {
383
+ const markerArtifact = readArtifact(markerPath, "folder-control");
384
+ if (!(0, import_layoutCore.isObject)(markerArtifact.json))
385
+ addDiagnostic("malformed-control", markerPath, `Invalid folder control in ${markerPath}`);
386
+ decodeSuppliedName(markerArtifact, directory.split("/").at(-1), "directory", "", markerArtifact.json);
387
+ if ((0, import_layoutCore.isObject)(markerArtifact.json)) addSharePointer(markerArtifact, markerArtifact.json.shares, "shares");
388
+ }
389
+ const sidecars = sidecarNames(entries);
390
+ for (const [, sidecar] of [...sidecars].sort(([left], [right]) => (0, import_layoutCore.compareText)(left, right)))
391
+ scanSidecar(`${directory}/${sidecar}`);
392
+ for (const entry of entries) {
393
+ const relative = `${directory}/${entry.name}`;
394
+ if (entry.isSymbolicLink() || entry.name === FOLDER_CONTROL) continue;
395
+ if (retiredManifest(entry.name, relative)) continue;
396
+ if (entry.isFile() && ((0, import_layoutPaths.isRawSidecarPath)(entry.name) || sidecars.has(entry.name))) continue;
397
+ if (entry.isDirectory()) {
398
+ const nestedMarker = lstat(`${relative}/_folder.json`);
399
+ if (!(0, import_layoutPaths.isPortableWorkspacePointer)(relative)) {
400
+ if (nestedMarker) unmanageableDirectories.add(relative);
401
+ opaqueDirectories.add(relative);
402
+ } else if (nestedMarker || trackedMarkerDirectories.has(relative)) scanManagedDirectory(relative);
403
+ else opaqueDirectories.add(relative);
404
+ continue;
405
+ }
406
+ if (!entry.isFile()) continue;
407
+ if (!entry.name.endsWith(".json")) {
408
+ localOnlyFiles.add(relative);
409
+ continue;
410
+ }
411
+ const artifact = readArtifact(relative, "document");
412
+ if (!(0, import_layoutCore.isObject)(artifact.json) || typeof artifact.json.kind !== "string" || !import_layoutCore.TREE_DOCUMENT_KINDS.has(artifact.json.kind))
413
+ addDiagnostic("unknown-json", relative, `Unknown item JSON in ${relative}`);
414
+ decodeSuppliedName(artifact, entry.name, "document", ".json", artifact.json);
415
+ if ((0, import_layoutCore.isObject)(artifact.json)) {
416
+ addSharePointer(artifact, artifact.json.shares, "shares");
417
+ if (artifact.json.kind === "remote_job") addAttachmentPointer(artifact, artifact.json.icon, "icon");
418
+ }
419
+ }
420
+ };
421
+ const scanFlatJsonDirectory = (directory, role, options = {}) => {
422
+ const entries = physicalEntries(directory);
423
+ if (!entries) return;
424
+ for (const entry of entries) {
425
+ const relative = `${directory}/${entry.name}`;
426
+ if (entry.isSymbolicLink()) {
427
+ inspectSymlink(relative);
428
+ continue;
429
+ }
430
+ if (entry.isDirectory()) {
431
+ opaqueDirectories.add(relative);
432
+ continue;
433
+ }
434
+ if (!entry.isFile()) continue;
435
+ if (retiredManifest(entry.name, relative)) continue;
436
+ if (!entry.name.endsWith(".json")) {
437
+ localOnlyFiles.add(relative);
438
+ continue;
439
+ }
440
+ const artifact = readArtifact(relative, role);
441
+ if (options.namesSupplySemanticName)
442
+ decodeSuppliedName(artifact, entry.name, "document", ".json", artifact.json);
443
+ if ((0, import_layoutCore.isObject)(artifact.json)) {
444
+ addSharePointer(artifact, artifact.json.shares, "shares");
445
+ if (options.attachmentField)
446
+ addAttachmentPointer(artifact, artifact.json[options.attachmentField], options.attachmentField);
447
+ if (role === "detached-document" && artifact.json.kind === "remote_job")
448
+ addAttachmentPointer(artifact, artifact.json.icon, "icon");
449
+ }
450
+ }
451
+ };
452
+ const scanDeclaredRoot = (rootDirectory, declared, exactFiles = {}) => {
453
+ const entries = physicalEntries(rootDirectory);
454
+ if (!entries) return;
455
+ for (const entry of entries) {
456
+ const relative = `${rootDirectory}/${entry.name}`;
457
+ if (entry.isSymbolicLink()) {
458
+ inspectSymlink(relative);
459
+ continue;
460
+ }
461
+ if (entry.isDirectory()) {
462
+ if (Object.prototype.hasOwnProperty.call(declared, entry.name)) declared[entry.name]();
463
+ else opaqueDirectories.add(relative);
464
+ continue;
465
+ }
466
+ if (!entry.isFile()) continue;
467
+ if (retiredManifest(entry.name, relative)) continue;
468
+ const role = Object.prototype.hasOwnProperty.call(exactFiles, entry.name) ? exactFiles[entry.name] : void 0;
469
+ if (role) readArtifact(relative, role);
470
+ else if (entry.name.endsWith(".json"))
471
+ addDiagnostic("unknown-json", relative, `JSON is not valid in ${rootDirectory}`);
472
+ else localOnlyFiles.add(relative);
473
+ }
474
+ };
475
+ const tracked = input.tracked.map((item) => {
476
+ try {
477
+ (0, import_layoutPaths.parseWorkspacePointer)(item.path);
478
+ } catch (error) {
479
+ addDiagnostic("unsafe-tracked-path", item.path, error.message);
480
+ return { route: item.route, path: item.path, status: "missing-leaf" };
481
+ }
482
+ if (item.role === "folder-control" && item.path.endsWith("/_folder.json"))
483
+ trackedMarkerDirectories.add((0, import_layoutPaths.folderDirectory)(item.path));
484
+ const state = probe(item.path);
485
+ if (state.symlink) inspectSymlink(state.symlinkPath ?? item.path);
486
+ if (state.present) {
487
+ const stat = state.symlink ? void 0 : lstat(item.path);
488
+ if (stat && (item.kind === "file" && !stat.isFile() || item.kind === "directory" && !stat.isDirectory()))
489
+ addDiagnostic("path-role-overlap", item.path, `Tracked path has the wrong physical kind`);
490
+ return { route: item.route, path: item.path, status: "present" };
491
+ }
492
+ const final = state.missingAncestor === item.path;
493
+ return {
494
+ route: item.route,
495
+ path: item.path,
496
+ status: final ? "missing-leaf" : "missing-subtree",
497
+ ...final || state.missingAncestor === void 0 ? {} : { missingAncestor: state.missingAncestor }
498
+ };
499
+ });
500
+ let rootEntries = [];
501
+ try {
502
+ rootEntries = fs.readdirSync(root, { withFileTypes: true });
503
+ } catch {
504
+ rootEntries = [];
505
+ }
506
+ for (const entry of rootEntries.sort((left, right) => (0, import_layoutCore.compareText)(left.name, right.name)))
507
+ if (entry.isFile()) retiredManifest(entry.name, entry.name);
508
+ const treeEntries = physicalEntries("tree");
509
+ for (const entry of treeEntries ?? []) {
510
+ const relative = `tree/${entry.name}`;
511
+ if (entry.isSymbolicLink()) {
512
+ inspectSymlink(relative);
513
+ continue;
514
+ }
515
+ if (entry.isDirectory()) {
516
+ const marker = lstat(`${relative}/_folder.json`);
517
+ if (!(0, import_layoutPaths.isPortableWorkspacePointer)(relative)) {
518
+ if (marker) unmanageableDirectories.add(relative);
519
+ opaqueDirectories.add(relative);
520
+ } else if (marker || trackedMarkerDirectories.has(relative)) scanManagedDirectory(relative);
521
+ else opaqueDirectories.add(relative);
522
+ } else if (entry.isFile() && retiredManifest(entry.name, relative)) continue;
523
+ else if (entry.isFile() && entry.name.endsWith(".json"))
524
+ addDiagnostic("unknown-json", relative, `Only managed folder directories are valid under tree`);
525
+ else if (entry.isFile()) localOnlyFiles.add(relative);
526
+ }
527
+ scanDeclaredRoot("access", {
528
+ shares: () => scanFlatJsonDirectory("access/shares", "share-group"),
529
+ groups: () => scanFlatJsonDirectory("access/groups", "user-group", { namesSupplySemanticName: true }),
530
+ labels: () => scanFlatJsonDirectory("access/labels", "label", { namesSupplySemanticName: true }),
531
+ grants: () => {
532
+ const entries = physicalEntries("access/grants");
533
+ for (const entry of entries ?? []) {
534
+ const relative = `access/grants/${entry.name}`;
535
+ if (entry.isSymbolicLink()) inspectSymlink(relative);
536
+ else if (entry.isDirectory()) scanFlatJsonDirectory(relative, "user-grant");
537
+ else if (entry.isFile() && retiredManifest(entry.name, relative)) continue;
538
+ else if (entry.isFile() && entry.name.endsWith(".json"))
539
+ addDiagnostic("unknown-json", relative, `Grant JSON requires a principal-kind directory`);
540
+ else if (entry.isFile()) localOnlyFiles.add(relative);
541
+ }
542
+ }
543
+ });
544
+ scanDeclaredRoot(
545
+ "definitions",
546
+ {
547
+ datasets: () => scanFlatJsonDirectory("definitions/datasets", "dataset", { namesSupplySemanticName: true }),
548
+ exports: () => scanFlatJsonDirectory("definitions/exports", "export", {
549
+ namesSupplySemanticName: true,
550
+ attachmentField: "template"
551
+ })
552
+ },
553
+ { "settings.json": "settings" }
554
+ );
555
+ scanDeclaredRoot("detached", {
556
+ ...Object.fromEntries(
557
+ [...import_layoutCore.ITEM_KINDS].map((kind) => [kind, () => scanFlatJsonDirectory(`detached/${kind}`, "detached-document")])
558
+ ),
559
+ files: () => {
560
+ const entries = physicalEntries("detached/files");
561
+ for (const entry of entries ?? []) {
562
+ const bucket = `detached/files/${entry.name}`;
563
+ if (entry.isSymbolicLink()) inspectSymlink(bucket);
564
+ else if (!entry.isDirectory())
565
+ addDiagnostic("path-role-overlap", bucket, `Detached file entry must be an identity directory`);
566
+ else {
567
+ const bucketEntries = physicalEntries(bucket) ?? [];
568
+ const sidecars = sidecarNames(bucketEntries);
569
+ if (sidecars.size === 0)
570
+ addDiagnostic("missing-raw-sidecar", bucket, `Detached file bucket has no raw sidecar`);
571
+ else if (sidecars.size > 1)
572
+ addDiagnostic("detached-file-count", bucket, `Detached file bucket must hold one raw file`);
573
+ for (const [, sidecar] of [...sidecars].sort(([left], [right]) => (0, import_layoutCore.compareText)(left, right)))
574
+ scanSidecar(`${bucket}/${sidecar}`);
575
+ for (const candidate of bucketEntries) {
576
+ const relative = `${bucket}/${candidate.name}`;
577
+ if (candidate.isSymbolicLink()) inspectSymlink(relative);
578
+ else if (retiredManifest(candidate.name, relative)) continue;
579
+ else if (candidate.isFile() && ((0, import_layoutPaths.isRawSidecarPath)(candidate.name) || sidecars.has(candidate.name)))
580
+ continue;
581
+ else if (candidate.isDirectory()) opaqueDirectories.add(relative);
582
+ else if (candidate.isFile() && candidate.name.endsWith(".json"))
583
+ addDiagnostic("unknown-json", relative, `Unclaimed JSON in detached file bucket`);
584
+ else if (candidate.isFile()) localOnlyFiles.add(relative);
585
+ }
586
+ }
587
+ }
588
+ }
589
+ });
590
+ for (const pending of pendingAttachments.sort((left, right) => (0, import_layoutCore.compareText)(left.path, right.path))) {
591
+ if (!attachmentTargetValid(pending.owner, pending.path, opaqueDirectories, addDiagnostic)) continue;
592
+ const state = probe(pending.path);
593
+ if (state.symlink) inspectSymlink(state.symlinkPath ?? pending.path);
594
+ const stat = state.present && !state.symlink ? lstat(pending.path) : void 0;
595
+ if (stat && !stat.isFile()) addDiagnostic("path-role-overlap", pending.path, `Attachment target is not a file`);
596
+ claim(pending.path, "file", "attachment", `${pending.owner.path}:${pending.field}`);
597
+ const present = !!stat?.isFile();
598
+ (pending.owner.pointers ??= []).push({
599
+ kind: "attachment",
600
+ field: pending.field,
601
+ path: pending.path,
602
+ present
603
+ });
604
+ artifacts.push({
605
+ path: pending.path,
606
+ kind: "file",
607
+ role: "attachment",
608
+ present,
609
+ source: pending.owner.path
610
+ });
611
+ localOnlyFiles.delete(pending.path);
612
+ }
613
+ for (const markerDirectory of trackedMarkerDirectories) {
614
+ const markerPath = `${markerDirectory}/_folder.json`;
615
+ if (probe(markerPath).present || !probe(markerDirectory).present) continue;
616
+ const retained = artifacts.some(
617
+ (artifact) => artifact.present && artifact.path.startsWith(`${markerDirectory}/`) && !["raw-metadata", "attachment"].includes(artifact.role)
618
+ ) || tracked.some(
619
+ (item) => item.status === "present" && item.path !== markerPath && !["raw-metadata", "attachment"].includes(
620
+ input.tracked.find((trackedPath) => trackedPath.route === item.route)?.role ?? ""
621
+ ) && item.path.startsWith(`${markerDirectory}/`)
622
+ );
623
+ if (retained && !diagnostics.some(
624
+ (diagnostic) => diagnostic.code === "missing-folder-marker" && diagnostic.path === markerPath
625
+ ))
626
+ addDiagnostic("missing-folder-marker", markerPath, `Folder marker is missing with managed descendants`);
627
+ }
628
+ return finalizeScanResult(
629
+ artifacts,
630
+ tracked,
631
+ opaqueDirectories,
632
+ localOnlyFiles,
633
+ diagnostics,
634
+ unmanageableDirectories
635
+ );
636
+ }
637
+ function sourceMatchesOwner(source, value) {
638
+ if (source.type !== "resource" || !(0, import_layoutCore.isObject)(value) || value.kind !== source.resource.kind) return false;
639
+ if ("id" in source.resource) return value.id === source.resource.id;
640
+ return value.key === source.resource.key;
641
+ }
642
+ function attachmentTargetValid(owner, target, opaqueDirectories, addDiagnostic) {
643
+ if (!/^(tree|access|definitions|detached)\//.test(target)) {
644
+ addDiagnostic("attachment-out-of-scope", owner.path, `Attachment is outside the adapter roots`, target);
645
+ return false;
646
+ }
647
+ if (target.endsWith(".json")) {
648
+ addDiagnostic("attachment-json", owner.path, `Attachment must not claim JSON`, target);
649
+ return false;
650
+ }
651
+ for (const opaque of opaqueDirectories) {
652
+ if (target === opaque || target.startsWith(`${opaque}/`)) {
653
+ addDiagnostic("attachment-opaque", owner.path, `Attachment is inside an opaque directory`, opaque);
654
+ return false;
655
+ }
656
+ }
657
+ return true;
658
+ }
659
+ function walkLayoutPath(root, relative) {
660
+ const parsed = (0, import_layoutPaths.parseWorkspacePointer)(relative);
661
+ const absoluteRoot = path.resolve(root);
662
+ try {
663
+ if (fs.lstatSync(absoluteRoot).isSymbolicLink())
664
+ return { fact: { path: parsed, state: "symlink" }, rootSymlink: true };
665
+ } catch (error) {
666
+ if (error.code !== "ENOENT") throw error;
667
+ }
668
+ let current = absoluteRoot;
669
+ const components = parsed.split("/");
670
+ for (const [index, component] of components.entries()) {
671
+ current = path.join(current, component);
672
+ const prefix = components.slice(0, index + 1).join("/");
673
+ let stat;
674
+ try {
675
+ stat = fs.lstatSync(current);
676
+ } catch (error) {
677
+ if (error.code === "ENOENT")
678
+ return { fact: { path: parsed, state: "absent", missingAncestor: prefix }, rootSymlink: false };
679
+ throw error;
680
+ }
681
+ if (stat.isSymbolicLink()) return { fact: { path: parsed, state: "symlink" }, rootSymlink: false };
682
+ if (index === components.length - 1)
683
+ return { fact: { path: parsed, state: stat.isDirectory() ? "directory" : "file" }, rootSymlink: false };
684
+ if (!stat.isDirectory())
685
+ return { fact: { path: parsed, state: "absent", missingAncestor: prefix }, rootSymlink: false };
686
+ }
687
+ throw new Error(`Unable to inspect layout path: ${relative}`);
688
+ }
689
+ function resolveLayoutPath(root, relative) {
690
+ const parsed = (0, import_layoutPaths.parseWorkspacePointer)(relative);
691
+ const absoluteRoot = path.resolve(root);
692
+ const resolved = path.resolve(absoluteRoot, ...parsed.split("/"));
693
+ const fromRoot = path.relative(absoluteRoot, resolved);
694
+ if (fromRoot === ".." || fromRoot.startsWith(`..${path.sep}`) || path.isAbsolute(fromRoot))
695
+ throw new Error(`Path escapes workspace root: ${relative}`);
696
+ const walk = walkLayoutPath(root, relative);
697
+ if (walk.fact.state === "symlink")
698
+ throw new Error(walk.rootSymlink ? `Refusing symlink root: ${absoluteRoot}` : `Refusing symlink: ${relative}`);
699
+ return resolved;
700
+ }
701
+ function probeLayoutPath(root, relative) {
702
+ return walkLayoutPath(root, relative).fact;
703
+ }
704
+ function hashLayoutPath(root, relative) {
705
+ try {
706
+ const content = (0, import_byteHashes.hashWorkspaceFile)(root, relative, resolveLayoutPath(root, relative));
707
+ return content ? { path: relative, state: "present", content } : { path: relative, state: "absent" };
708
+ } catch (error) {
709
+ return { path: relative, state: "unreadable", message: error.message };
710
+ }
711
+ }
712
+ function rawStableSources(scan) {
713
+ const sources = /* @__PURE__ */ new Map();
714
+ for (const artifact of scan.artifacts) {
715
+ if (artifact.role !== "raw") continue;
716
+ const value = (0, import_layoutCore.object)(artifact.json);
717
+ const source = value && (0, import_layoutCore.sourceFromValue)({ ...value, kind: "file" });
718
+ if (source) sources.set((0, import_layoutCore.sourceIdentityKey)(source), artifact);
719
+ }
720
+ return sources;
721
+ }
722
+ function currentOwnerArtifacts(scan) {
723
+ const owners = /* @__PURE__ */ new Map();
724
+ for (const artifact of scan.artifacts) {
725
+ const value = (0, import_layoutCore.object)(artifact.json);
726
+ if (!value || !(0, import_layoutCore.attachmentField)(value)) continue;
727
+ const source = (0, import_layoutCore.sourceFromValue)(value);
728
+ if (source) owners.set((0, import_layoutCore.sourceIdentityKey)(source), artifact);
729
+ }
730
+ return owners;
731
+ }
732
+ function loadLayoutByteEvidence(input) {
733
+ const diagnostics = [];
734
+ const facts = /* @__PURE__ */ new Map();
735
+ const probe = (relative) => {
736
+ if (facts.has(relative)) return facts.get(relative);
737
+ const fact = hashLayoutPath(input.root, relative);
738
+ facts.set(relative, fact);
739
+ if (fact.state === "unreadable")
740
+ diagnostics.push((0, import_layoutCore.diagnostic)("unreadable-byte-path", relative, fact.message));
741
+ return fact;
742
+ };
743
+ for (const artifact of input.scan.artifacts)
744
+ if (artifact.role === "raw" || artifact.role === "attachment") probe(artifact.path);
745
+ const currentRaw = rawStableSources(input.scan);
746
+ for (const route of input.evidence.binaryRoutes) {
747
+ if (route.selector.slot !== "file-entry" || !route.bytes) continue;
748
+ const selector = route.selector;
749
+ const current = route.source.type === "resource" ? currentRaw.get((0, import_layoutCore.sourceIdentityKey)(route.source)) : void 0;
750
+ if (current && (current.path === route.bytes || facts.get(current.path)?.state !== "absent")) continue;
751
+ const currentExact = input.scan.artifacts.some(
752
+ (artifact) => artifact.role === "raw" && artifact.source === selector.sidecar
753
+ );
754
+ if (route.source.type === "transient" && currentExact) continue;
755
+ probe(route.bytes);
756
+ }
757
+ const currentOwners = currentOwnerArtifacts(input.scan);
758
+ for (const route of input.evidence.binaryRoutes) {
759
+ if (route.selector.slot !== "owner-attachment" || route.source.type !== "resource" || !route.contributor || !route.bytes)
760
+ continue;
761
+ const owner = currentOwners.get((0, import_layoutCore.sourceIdentityKey)(route.source));
762
+ if (!owner) continue;
763
+ const value = (0, import_layoutCore.object)(owner.json);
764
+ const field = route.selector.field;
765
+ const authored = value?.[field];
766
+ const currentPointer = (0, import_layoutCore.attachmentPointer)(authored);
767
+ if (authored === null) continue;
768
+ if (typeof currentPointer === "string") {
769
+ const replacement = probe(currentPointer);
770
+ if (replacement.state === "present") continue;
771
+ }
772
+ probe(route.bytes);
773
+ }
774
+ return {
775
+ facts: [...facts.values()].sort((left, right) => (0, import_layoutCore.compareText)(left.path, right.path)),
776
+ diagnostics
777
+ };
778
+ }
779
+ function readExactText(file) {
780
+ const descriptor = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
781
+ try {
782
+ if (!fs.fstatSync(descriptor).isFile()) throw new Error(`Expected regular file: ${file}`);
783
+ return fs.readFileSync(descriptor, "utf8");
784
+ } finally {
785
+ fs.closeSync(descriptor);
786
+ }
787
+ }
788
+ function stateText(root) {
789
+ return readExactText((0, import_workspace.workspacePath)(root, import_workspace.STATE_FILE));
790
+ }
791
+ function evidence(state) {
792
+ if (!state.layout) throw new Error("Layout state is missing");
793
+ return {
794
+ groupedRoutes: state.layout.evidence.groupedRoutes,
795
+ binaryRoutes: state.layout.evidence.binaryRoutes,
796
+ groupedSubmissionProofs: [],
797
+ binarySubmissionProofs: [],
798
+ derivedSourceProofs: state.layout.evidence.derivedSourceProofs,
799
+ rawNavigationRoutes: state.layout.evidence.rawNavigationRoutes,
800
+ canonicalBaseline: state.baseline,
801
+ detachedFileProofs: state.layout.evidence.detachedFileProofs,
802
+ detachedDocumentProofs: state.layout.evidence.detachedDocumentProofs
803
+ };
804
+ }
805
+ function managedJsonText(root, scan) {
806
+ const result = {};
807
+ for (const artifact of scan.artifacts) {
808
+ if (!artifact.present || ["raw", "attachment"].includes(artifact.role) || artifact.json === void 0) continue;
809
+ if (Object.prototype.hasOwnProperty.call(result, artifact.path))
810
+ throw new Error(`Duplicate managed JSON artifact: ${artifact.path}`);
811
+ const text = readExactText(resolveLayoutPath(root, artifact.path));
812
+ let parsed;
813
+ try {
814
+ parsed = JSON.parse(text);
815
+ } catch {
816
+ throw new Error(`Managed JSON changed after scanning: ${artifact.path}`);
817
+ }
818
+ if (JSON.stringify(parsed) !== JSON.stringify(artifact.json))
819
+ throw new Error(`Managed JSON changed after scanning: ${artifact.path}`);
820
+ result[artifact.path] = text;
821
+ }
822
+ return result;
823
+ }
824
+ function completeByteFacts(root, scan, inputEvidence) {
825
+ const loaded = loadLayoutByteEvidence({ root, scan, evidence: inputEvidence });
826
+ const facts = new Map(loaded.facts.map((fact) => [fact.path, fact]));
827
+ const paths = new Set(
828
+ scan.artifacts.filter((artifact) => artifact.role === "raw" || artifact.role === "attachment").map((artifact) => artifact.path)
829
+ );
830
+ for (const route of inputEvidence.binaryRoutes) if (route.bytes) paths.add(route.bytes);
831
+ for (const relative of paths) if (!facts.has(relative)) facts.set(relative, hashLayoutPath(root, relative));
832
+ return [...paths].sort(import_layoutCore.compareText).map((relative) => facts.get(relative));
833
+ }
834
+ function normalizedRequiredPaths(paths) {
835
+ const result = /* @__PURE__ */ new Set();
836
+ for (const relative of paths) result.add((0, import_layoutPaths.parseWorkspacePointer)(relative));
837
+ return [...result].sort(import_layoutCore.compareText);
838
+ }
839
+ function sameValue(left, right) {
840
+ return JSON.stringify(left) === JSON.stringify(right);
841
+ }
842
+ function capture(root, requiredPaths) {
843
+ const beforeStateText = stateText(root);
844
+ const state = (0, import_documents.peekState)(beforeStateText);
845
+ if (!state.layout) throw new Error("Layout state is missing");
846
+ const tracked = state.layout.tracked;
847
+ const firstScan = scanLayout({ root, tracked });
848
+ const inputEvidence = evidence(state);
849
+ const jsonText = managedJsonText(root, firstScan);
850
+ const byteFacts = completeByteFacts(root, firstScan, inputEvidence);
851
+ const pathFacts = requiredPaths === void 0 ? void 0 : normalizedRequiredPaths(requiredPaths).map((relative) => probeLayoutPath(root, relative));
852
+ const secondScan = scanLayout({ root, tracked });
853
+ if (!sameValue(firstScan, secondScan)) throw new Error("Layout changed while capturing the workspace");
854
+ const afterStateText = stateText(root);
855
+ if (beforeStateText !== afterStateText) throw new Error("Layout state changed while capturing the workspace");
856
+ const seed = {
857
+ scan: firstScan,
858
+ jsonText,
859
+ byteFacts,
860
+ stateText: beforeStateText
861
+ };
862
+ return pathFacts === void 0 ? { snapshot: seed } : { snapshot: { ...seed, pathFacts } };
863
+ }
864
+ function captureLayoutWorkspaceSeed(root) {
865
+ return capture(root);
866
+ }
867
+ function captureLayoutWorkspace(root, requiredPaths) {
868
+ return capture(root, requiredPaths);
869
+ }
870
+ // Annotate the CommonJS export names for ESM import in node:
871
+ 0 && (module.exports = {
872
+ captureLayoutWorkspace,
873
+ captureLayoutWorkspaceSeed,
874
+ hashLayoutPath,
875
+ loadLayoutByteEvidence,
876
+ probeLayoutPath,
877
+ resolveLayoutPath,
878
+ sameValue,
879
+ scanLayout,
880
+ stateText
881
+ });
882
+ //# sourceMappingURL=layoutScan.js.map