farseer-cli 1.18.0 → 1.20.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 (262) hide show
  1. package/README.md +33 -10
  2. package/dist/commands/app.js +42 -3
  3. package/dist/commands/app.js.map +1 -2
  4. package/dist/commands/apps.js.map +0 -1
  5. package/dist/commands/cells.js +120 -85
  6. package/dist/commands/cells.js.map +1 -2
  7. package/dist/commands/code.js.map +0 -1
  8. package/dist/commands/config.js.map +0 -1
  9. package/dist/commands/dashboards.js +246 -12
  10. package/dist/commands/dashboards.js.map +1 -2
  11. package/dist/commands/diff.js.map +0 -1
  12. package/dist/commands/dimensions.js +52 -27
  13. package/dist/commands/dimensions.js.map +1 -2
  14. package/dist/commands/docs.js +82 -0
  15. package/dist/commands/docs.js.map +6 -0
  16. package/dist/commands/files.js +49 -0
  17. package/dist/commands/files.js.map +2 -3
  18. package/dist/commands/folders.js +76 -0
  19. package/dist/commands/folders.js.map +6 -0
  20. package/dist/commands/formula.js +38 -30
  21. package/dist/commands/formula.js.map +1 -2
  22. package/dist/commands/install.js +32 -30
  23. package/dist/commands/install.js.map +2 -3
  24. package/dist/commands/list.js.map +0 -1
  25. package/dist/commands/login.js +3 -3
  26. package/dist/commands/login.js.map +1 -2
  27. package/dist/commands/logout.js.map +0 -1
  28. package/dist/commands/mcp-server.js.map +0 -1
  29. package/dist/commands/model.js +30 -5
  30. package/dist/commands/model.js.map +2 -3
  31. package/dist/commands/pipeline.js.map +0 -1
  32. package/dist/commands/pull.js +1 -1
  33. package/dist/commands/pull.js.map +1 -2
  34. package/dist/commands/push.js +6 -4
  35. package/dist/commands/push.js.map +1 -2
  36. package/dist/commands/refresh.js.map +0 -1
  37. package/dist/commands/run.js.map +0 -1
  38. package/dist/commands/sheets.js +289 -52
  39. package/dist/commands/sheets.js.map +1 -2
  40. package/dist/commands/skills.js +157 -0
  41. package/dist/commands/skills.js.map +6 -0
  42. package/dist/commands/status.js.map +0 -1
  43. package/dist/commands/tool.js.map +0 -1
  44. package/dist/commands/variables.js +246 -82
  45. package/dist/commands/variables.js.map +1 -2
  46. package/dist/commands/whoami.js.map +0 -1
  47. package/dist/index.js +117 -23
  48. package/dist/index.js.map +1 -2
  49. package/dist/mcp/index.js.map +0 -1
  50. package/dist/mcp/prompts/workflows.js.map +0 -1
  51. package/dist/mcp/resources/documentation.js +19 -12
  52. package/dist/mcp/resources/documentation.js.map +1 -2
  53. package/dist/mcp/server.js.map +0 -1
  54. package/dist/mcp/skills.js.map +0 -1
  55. package/dist/mcp/tools/appTools.js +1 -7
  56. package/dist/mcp/tools/appTools.js.map +1 -2
  57. package/dist/mcp/tools/authTools.js +1 -1
  58. package/dist/mcp/tools/authTools.js.map +1 -2
  59. package/dist/mcp/tools/cellTools.js +6 -19
  60. package/dist/mcp/tools/cellTools.js.map +1 -2
  61. package/dist/mcp/tools/dashboardTools.js +30 -412
  62. package/dist/mcp/tools/dashboardTools.js.map +2 -3
  63. package/dist/mcp/tools/dataTools.js +15 -146
  64. package/dist/mcp/tools/dataTools.js.map +1 -2
  65. package/dist/mcp/tools/folderTools.js +12 -78
  66. package/dist/mcp/tools/folderTools.js.map +1 -2
  67. package/dist/mcp/tools/modelTools.js +23 -372
  68. package/dist/mcp/tools/modelTools.js.map +1 -2
  69. package/dist/mcp/tools/pipelineContract.js +5 -1
  70. package/dist/mcp/tools/pipelineContract.js.map +1 -2
  71. package/dist/mcp/tools/pipelineTools.js.map +0 -1
  72. package/dist/mcp/tools/runTools.js +8 -69
  73. package/dist/mcp/tools/runTools.js.map +1 -2
  74. package/dist/mcp/tools/sheetTools.js +14 -264
  75. package/dist/mcp/tools/sheetTools.js.map +1 -2
  76. package/dist/mcp/tools/syncTools.js +7 -3
  77. package/dist/mcp/tools/syncTools.js.map +1 -2
  78. package/dist/mcp/utils/helpers.js.map +0 -1
  79. package/dist/mcp/utils/launchPin.js.map +0 -1
  80. package/dist/mcp/utils/operationResponse.js +41 -0
  81. package/dist/mcp/utils/operationResponse.js.map +6 -0
  82. package/dist/mcp/utils/registerTool.js.map +0 -1
  83. package/dist/mcp/utils/session.js.map +0 -1
  84. package/dist/mcp/utils/tenantPin.js.map +0 -1
  85. package/dist/operations/cells.js +444 -0
  86. package/dist/operations/cells.js.map +6 -0
  87. package/dist/operations/dashboards.js +357 -0
  88. package/dist/operations/dashboards.js.map +6 -0
  89. package/dist/operations/data.js +206 -0
  90. package/dist/operations/data.js.map +6 -0
  91. package/dist/operations/errors.js +64 -0
  92. package/dist/operations/errors.js.map +6 -0
  93. package/dist/operations/exportModel.js +59 -0
  94. package/dist/operations/exportModel.js.map +6 -0
  95. package/dist/operations/folderPath.js +128 -0
  96. package/dist/operations/folderPath.js.map +6 -0
  97. package/dist/operations/folders.js +80 -0
  98. package/dist/operations/folders.js.map +6 -0
  99. package/dist/operations/install.js +109 -0
  100. package/dist/operations/install.js.map +6 -0
  101. package/dist/operations/model.js +271 -0
  102. package/dist/operations/model.js.map +6 -0
  103. package/dist/operations/sheets.js +428 -0
  104. package/dist/operations/sheets.js.map +6 -0
  105. package/dist/pipeline/compatibility.js.map +0 -1
  106. package/dist/pipeline/connect.js.map +0 -1
  107. package/dist/pipeline/create.js.map +0 -1
  108. package/dist/pipeline/errors.js.map +0 -1
  109. package/dist/pipeline/failStep.js +43 -0
  110. package/dist/pipeline/failStep.js.map +6 -0
  111. package/dist/pipeline/generated-reference.json +25 -13
  112. package/dist/pipeline/guide.js.map +0 -1
  113. package/dist/pipeline/init.js.map +0 -1
  114. package/dist/pipeline/operations.js.map +0 -1
  115. package/dist/pipeline/query.js.map +0 -1
  116. package/dist/pipeline/queryDownloads.js.map +0 -1
  117. package/dist/pipeline/queryWorker.js +3 -1
  118. package/dist/pipeline/queryWorker.js.map +1 -2
  119. package/dist/pipeline/readiness.js.map +0 -1
  120. package/dist/pipeline/reference.js.map +0 -1
  121. package/dist/pipeline/requests.js +3 -32
  122. package/dist/pipeline/requests.js.map +1 -2
  123. package/dist/pipeline/runArguments.js.map +0 -1
  124. package/dist/pipeline/runtime.js.map +0 -1
  125. package/dist/pipeline/service.js +46 -2
  126. package/dist/pipeline/service.js.map +1 -2
  127. package/dist/services/appSyncService.js +59 -9
  128. package/dist/services/appSyncService.js.map +1 -2
  129. package/dist/services/apps.js +10 -0
  130. package/dist/services/apps.js.map +1 -2
  131. package/dist/services/authErrors.js.map +0 -1
  132. package/dist/services/codefirst/api.js +38 -5
  133. package/dist/services/codefirst/api.js.map +1 -2
  134. package/dist/services/codefirst/binaryDisk.js.map +0 -1
  135. package/dist/services/codefirst/byteHashes.js +5 -0
  136. package/dist/services/codefirst/byteHashes.js.map +1 -2
  137. package/dist/services/codefirst/documents.js +41 -15
  138. package/dist/services/codefirst/documents.js.map +1 -2
  139. package/dist/services/codefirst/layoutBinaryProjection.js +24 -13
  140. package/dist/services/codefirst/layoutBinaryProjection.js.map +1 -2
  141. package/dist/services/codefirst/layoutCompose.js +44 -38
  142. package/dist/services/codefirst/layoutCompose.js.map +1 -2
  143. package/dist/services/codefirst/layoutCore.js +14 -1
  144. package/dist/services/codefirst/layoutCore.js.map +1 -2
  145. package/dist/services/codefirst/layoutPaths.js +80 -4
  146. package/dist/services/codefirst/layoutPaths.js.map +1 -2
  147. package/dist/services/codefirst/layoutProjection.js +73 -39
  148. package/dist/services/codefirst/layoutProjection.js.map +1 -2
  149. package/dist/services/codefirst/layoutReadback.js +357 -130
  150. package/dist/services/codefirst/layoutReadback.js.map +2 -3
  151. package/dist/services/codefirst/layoutReadbackPlacement.js +94 -57
  152. package/dist/services/codefirst/layoutReadbackPlacement.js.map +2 -3
  153. package/dist/services/codefirst/layoutReceipt.js +283 -243
  154. package/dist/services/codefirst/layoutReceipt.js.map +2 -3
  155. package/dist/services/codefirst/layoutScan.js +208 -110
  156. package/dist/services/codefirst/layoutScan.js.map +1 -2
  157. package/dist/services/codefirst/output.js +76 -10
  158. package/dist/services/codefirst/output.js.map +1 -2
  159. package/dist/services/codefirst/types.js.map +0 -1
  160. package/dist/services/codefirst/workflow.js +65 -29
  161. package/dist/services/codefirst/workflow.js.map +2 -3
  162. package/dist/services/codefirst/workspace.js.map +0 -1
  163. package/dist/services/codefirst/workspaceLock.js.map +0 -1
  164. package/dist/services/codefirst/workspaceRoot.js +2 -1
  165. package/dist/services/codefirst/workspaceRoot.js.map +1 -2
  166. package/dist/services/configService.js.map +0 -1
  167. package/dist/services/credentials.js.map +0 -1
  168. package/dist/services/farseerService.js +31 -7
  169. package/dist/services/farseerService.js.map +1 -2
  170. package/dist/services/httpError.js.map +0 -1
  171. package/dist/services/modelExport.js.map +0 -1
  172. package/dist/services/organisation.js.map +0 -1
  173. package/dist/services/preflight.js.map +0 -1
  174. package/dist/services/realms.js.map +0 -1
  175. package/dist/services/syncService.js +3 -3
  176. package/dist/services/syncService.js.map +1 -2
  177. package/dist/skills/bundled.js +106 -0
  178. package/dist/skills/bundled.js.map +6 -0
  179. package/dist/skills/install.js +257 -0
  180. package/dist/skills/install.js.map +6 -0
  181. package/dist/skills/pipeline.js +10 -18
  182. package/dist/skills/pipeline.js.map +1 -2
  183. package/dist/utils/agentSandbox.js +1 -1
  184. package/dist/utils/agentSandbox.js.map +0 -1
  185. package/dist/utils/cliOptions.js.map +0 -1
  186. package/dist/utils/constants.js.map +0 -1
  187. package/dist/utils/entityResolver.js +72 -25
  188. package/dist/utils/entityResolver.js.map +1 -2
  189. package/dist/utils/errorFormatter.js +72 -11
  190. package/dist/utils/errorFormatter.js.map +1 -2
  191. package/dist/utils/fileLogger.js.map +0 -1
  192. package/dist/utils/fileValidation.js.map +0 -1
  193. package/dist/utils/folderMatch.js.map +0 -1
  194. package/dist/utils/formulaFilters.js +11 -2
  195. package/dist/utils/formulaFilters.js.map +1 -2
  196. package/dist/utils/helpers.js.map +0 -1
  197. package/dist/utils/logger.js.map +0 -1
  198. package/dist/utils/nameResolver.js.map +0 -1
  199. package/dist/utils/operationCli.js +102 -0
  200. package/dist/utils/operationCli.js.map +6 -0
  201. package/dist/utils/packageManager.js.map +0 -1
  202. package/dist/utils/syncReporting.js.map +0 -1
  203. package/dist/utils/syncScope.js.map +0 -1
  204. package/dist/utils/updateCheck.js.map +0 -1
  205. package/dist/utils/variableValues.js.map +0 -1
  206. package/dist/utils/workspace.js.map +0 -1
  207. package/docs/cli-guide.md +182 -2
  208. package/docs/import-workflows.md +14 -14
  209. package/docs/new-app-template.md +1 -1
  210. package/docs/pipeline-client-guide.md +1 -1
  211. package/docs/pipeline-reference.md +304 -9
  212. package/docs/troubleshooting.md +18 -0
  213. package/package.json +2 -2
  214. package/skills/farseer-analysis/SKILL.md +132 -0
  215. package/skills/farseer-app-dev/SKILL.md +131 -0
  216. package/skills/farseer-app-dev/assignments.md +185 -0
  217. package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
  218. package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
  219. package/skills/farseer-app-dev/working-patterns.md +876 -0
  220. package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
  221. package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
  222. package/skills/farseer-author-import-job/SKILL.md +114 -0
  223. package/skills/farseer-author-import-job/cell-writes.md +530 -0
  224. package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
  225. package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
  226. package/skills/farseer-build-model/SKILL.md +122 -0
  227. package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
  228. package/skills/farseer-build-model/naming-conventions.md +435 -0
  229. package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
  230. package/skills/farseer-build-pipeline/SKILL.md +190 -0
  231. package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
  232. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
  233. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
  234. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
  235. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
  236. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
  237. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
  238. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
  239. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
  240. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
  241. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
  242. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
  243. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
  244. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
  245. package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
  246. package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
  247. package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
  248. package/skills/farseer-dashboards/SKILL.md +40 -0
  249. package/skills/farseer-formulas/SKILL.md +165 -0
  250. package/skills/farseer-help-center/SKILL.md +66 -0
  251. package/skills/farseer-model/SKILL.md +119 -0
  252. package/skills/farseer-modify-model/SKILL.md +158 -0
  253. package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
  254. package/skills/farseer-optimize-model/SKILL.md +314 -0
  255. package/skills/farseer-optimize-model/stats-dump.ts +139 -0
  256. package/skills/farseer-pnl/SKILL.md +220 -0
  257. package/skills/farseer-review-model/SKILL.md +172 -0
  258. package/skills/farseer-run-apps/SKILL.md +102 -0
  259. package/skills/pipeline-authoring/SKILL.md +7 -5
  260. package/skills/pipeline-authoring/practices.md +21 -8
  261. package/dist/services/agentApprovalFetch.js +0 -86
  262. package/dist/services/agentApprovalFetch.js.map +0 -7
@@ -31,6 +31,10 @@ const FLAT_ROOTS = {
31
31
  dataset: "definitions/datasets",
32
32
  export_configuration: "definitions/exports"
33
33
  };
34
+ const FIXED_PATHS = {
35
+ settings: "definitions/settings.json",
36
+ global_locks: "definitions/global_locks.json"
37
+ };
34
38
  function sameBinarySelector(left, right) {
35
39
  if (left.slot !== right.slot) return false;
36
40
  if (left.slot === "file-entry" && right.slot === "file-entry") return left.sidecar === right.sidecar;
@@ -54,14 +58,12 @@ function sourceFor(documentKey, document) {
54
58
  function semanticPath(document) {
55
59
  const value = document;
56
60
  if (document.kind === "folder") {
57
- if (!Array.isArray(value.path) || value.path.some((part) => typeof part !== "string" || !part))
58
- return void 0;
59
- return value.path;
61
+ const path = (0, import_layoutPaths.folderPathSegments)(value.path);
62
+ return path && typeof path.at(-1) === "string" ? path : void 0;
60
63
  }
61
64
  if (["variable", "dimension_table", "sheet", "dashboard", "remote_job", "file"].includes(document.kind)) {
62
- const folder = value.folder === null ? [] : value.folder;
63
- if (typeof value.name !== "string" || !value.name || !Array.isArray(folder) || folder.some((part) => typeof part !== "string" || !part))
64
- return void 0;
65
+ const folder = (0, import_layoutPaths.itemFolderPath)(value.folder);
66
+ if (typeof value.name !== "string" || !value.name || !folder) return void 0;
65
67
  return [...folder, value.name];
66
68
  }
67
69
  return void 0;
@@ -97,17 +99,21 @@ function requiresIdentityReallocation(candidate) {
97
99
  }
98
100
  function selectedHeadDamage(input, diagnostics) {
99
101
  if (!input.head) return /* @__PURE__ */ new Map();
102
+ const proof = input.headProof;
100
103
  try {
101
104
  const authoritative = input.headDocuments;
102
105
  if (!authoritative) throw new Error("Selected Head was not validated");
103
- const damage = extractAuthoritativeDamageEvidence(input.head, authoritative);
106
+ const damage = proof?.damage ?? extractAuthoritativeDamageEvidence(input.head, authoritative);
107
+ if (proof) proof.damage = damage;
104
108
  if (input.documents.length !== input.documentKeys.length || new Set(input.documentKeys).size !== input.documentKeys.length)
105
109
  throw new Error("Selected documents are missing, duplicated or misaligned");
106
110
  for (const [index, document] of input.documents.entries()) {
107
111
  const documentKey = input.documentKeys[index];
112
+ if (proof?.matched.get(documentKey) === document) continue;
108
113
  const expected = authoritative.get(documentKey);
109
114
  if (!expected || (0, import_layoutCore.canonicalFragmentHash)({ documentKey, document }) !== (0, import_layoutCore.canonicalFragmentHash)({ documentKey, document: expected }))
110
115
  throw new Error(`Selected document does not match Head: ${documentKey}`);
116
+ proof?.matched.set(documentKey, document);
111
117
  }
112
118
  return damage;
113
119
  } catch (error) {
@@ -145,9 +151,13 @@ function groupOwner(document) {
145
151
  return { kind: owner.kind, dangling: owner.dangling };
146
152
  return void 0;
147
153
  }
154
+ function markerId(value) {
155
+ const marker = (0, import_layoutCore.object)(value);
156
+ return typeof marker?.dangling === "string" ? marker.dangling : typeof marker?.hidden === "string" ? marker.hidden : void 0;
157
+ }
148
158
  function hasExplicitDamageShape(document) {
149
159
  const value = document;
150
- if (document.kind === "folder") return value.path === null && typeof (0, import_layoutCore.object)(value.parent)?.dangling === "string";
160
+ if (document.kind === "folder") return value.path === null && markerId(value.parent) !== void 0;
151
161
  if (document.kind === "share") return typeof (0, import_layoutCore.object)(value.owner)?.dangling === "string";
152
162
  return ["variable", "dimension_table", "sheet", "dashboard", "remote_job", "file"].includes(document.kind) && typeof (0, import_layoutCore.object)(value.folder)?.dangling === "string";
153
163
  }
@@ -257,6 +267,24 @@ function planAuthoritativePlacement(input) {
257
267
  ...rawObservationsBySource.keys(),
258
268
  ...input.currentBinary.attachmentObservations.map((observation) => (0, import_layoutCore.sourceIdentityKey)(observation.source))
259
269
  ]);
270
+ let insertionEvidence;
271
+ const signatureKey = (document) => JSON.stringify([document.kind, placementSignature(document)]);
272
+ const indexInsertionEvidence = () => {
273
+ const keyedSignatures = /* @__PURE__ */ new Set();
274
+ const keyed = (source, document) => {
275
+ if (document && (source.type === "transient" || source.type === "resource" && "key" in source.resource))
276
+ keyedSignatures.add(signatureKey(document));
277
+ };
278
+ for (const mapping of input.currentGrouped.sources)
279
+ keyed(mapping.source, input.currentGrouped.documents[mapping.documentIndex]);
280
+ for (const mapping of input.currentBinary.rawSources)
281
+ keyed(mapping.source, input.currentBinary.rawDocuments[mapping.documentIndex]);
282
+ return {
283
+ keyedSignatures,
284
+ routeSources: new Set(input.groupedRoutes.map((route) => (0, import_layoutCore.sourceIdentityKey)(route.source))),
285
+ trackedRoutes: new Set(input.scan.tracked.map((tracked) => tracked.route))
286
+ };
287
+ };
260
288
  const normalized = [];
261
289
  const usedIndexes = /* @__PURE__ */ new Set();
262
290
  const usedKeys = /* @__PURE__ */ new Set();
@@ -352,19 +380,9 @@ function planAuthoritativePlacement(input) {
352
380
  }
353
381
  } else {
354
382
  const key = (0, import_layoutCore.sourceIdentityKey)(source);
355
- const semanticAssociation = document.kind !== "share" && [
356
- ...input.currentGrouped.sources.map((mapping) => ({
357
- document: input.currentGrouped.documents[mapping.documentIndex],
358
- source: mapping.source
359
- })),
360
- ...input.currentBinary.rawSources.map((mapping) => ({
361
- document: input.currentBinary.rawDocuments[mapping.documentIndex],
362
- source: mapping.source
363
- }))
364
- ].some(
365
- (current2) => (current2.source.type === "transient" || current2.source.type === "resource" && "key" in current2.source.resource) && current2.document?.kind === document.kind && placementSignature(current2.document) === placementSignature(document)
366
- );
367
- const priorAssociation = input.groupedRoutes.some((route) => (0, import_layoutCore.sourceIdentityKey)(route.source) === key) || currentSourceKeys.has(key) || (0, import_layoutCore.own)(input.canonicalBaseline, intent.documentKey) || input.scan.tracked.some((tracked) => tracked.route === intent.documentKey);
383
+ const evidence = insertionEvidence ??= indexInsertionEvidence();
384
+ const semanticAssociation = document.kind !== "share" && evidence.keyedSignatures.has(signatureKey(document));
385
+ const priorAssociation = evidence.routeSources.has(key) || currentSourceKeys.has(key) || (0, import_layoutCore.own)(input.canonicalBaseline, intent.documentKey) || evidence.trackedRoutes.has(intent.documentKey);
368
386
  if (semanticAssociation || priorAssociation && !intent.reinsert) {
369
387
  diagnostics.push(
370
388
  (0, import_layoutCore.diagnostic)("invalid-insertion-authority", intent.documentKey, "A prior source association exists")
@@ -500,7 +518,7 @@ function planAuthoritativePlacement(input) {
500
518
  }
501
519
  };
502
520
  const reserveControl = (path, identity) => {
503
- const existing = allocator.snapshot().filter((claim) => claim.path === path);
521
+ const existing = allocator.claimsAt(path);
504
522
  if (existing.length > 0) {
505
523
  if (existing.length === 1 && existing[0].kind === "file" && existing[0].role === "control") return true;
506
524
  diagnostics.push(
@@ -511,7 +529,8 @@ function planAuthoritativePlacement(input) {
511
529
  return claimFixed({ path, kind: "file", role: "control", identity });
512
530
  };
513
531
  const resolveParent = (path, childKey) => {
514
- if (path.length === 0) return { type: "normal", directory: "tree" };
532
+ if (path.length === 0 || path.length === 1 && (0, import_layoutPaths.anchorId)(path[0]) !== void 0)
533
+ return { type: "normal", directory: (0, import_layoutPaths.folderRootDirectory)(path) };
515
534
  const key = (0, import_layoutCore.canonicalFragmentHash)([...path]);
516
535
  const planned = plannedFolders.get(key);
517
536
  if (planned) return planned;
@@ -579,7 +598,7 @@ function planAuthoritativePlacement(input) {
579
598
  );
580
599
  return void 0;
581
600
  }
582
- const before = allocator.snapshot();
601
+ const before = allocator.size;
583
602
  try {
584
603
  const allocated = allocator.allocate(request);
585
604
  if (forbidden(allocated.path)) {
@@ -612,7 +631,7 @@ function planAuthoritativePlacement(input) {
612
631
  reason: "representation-fallback",
613
632
  sourceKey: (0, import_layoutCore.sourceIdentityKey)(candidate.source),
614
633
  request,
615
- existingClaims: before
634
+ existingClaims: allocator.snapshot(before)
616
635
  };
617
636
  return { file: path, slot };
618
637
  }
@@ -696,7 +715,7 @@ function planAuthoritativePlacement(input) {
696
715
  } else if (parent?.type === "normal") {
697
716
  const request = {
698
717
  directory: parent.directory,
699
- name: path.at(-1),
718
+ name: (0, import_layoutPaths.lastPathName)(path),
700
719
  role: "directory",
701
720
  identity: identityValue(candidate.source),
702
721
  requiredChildren: ["_folder.json"]
@@ -771,7 +790,7 @@ function planAuthoritativePlacement(input) {
771
790
  try {
772
791
  allocated = allocator.allocate({
773
792
  directory: bucket.path,
774
- name: path.at(-1),
793
+ name: (0, import_layoutPaths.lastPathName)(path),
775
794
  role: "raw",
776
795
  identity: identityValue(candidate.source)
777
796
  });
@@ -886,11 +905,11 @@ function planAuthoritativePlacement(input) {
886
905
  }
887
906
  const request = {
888
907
  directory: parent.directory,
889
- name: path.at(-1),
908
+ name: (0, import_layoutPaths.lastPathName)(path),
890
909
  role: "raw",
891
910
  identity: identityValue(candidate.source)
892
911
  };
893
- const before = allocator.snapshot();
912
+ const before = allocator.size;
894
913
  try {
895
914
  const allocated = allocator.allocate(request);
896
915
  allocations.push({ source: candidate.source, path: allocated });
@@ -904,7 +923,10 @@ function planAuthoritativePlacement(input) {
904
923
  };
905
924
  } catch (error) {
906
925
  if (error instanceof import_layoutPaths.LayoutPathAllocationError && error.reason === "unrepresentable")
907
- destination = allocateDetachedRaw(candidate, void 0, { request, claims: before });
926
+ destination = allocateDetachedRaw(candidate, void 0, {
927
+ request,
928
+ claims: allocator.snapshot(before)
929
+ });
908
930
  else
909
931
  diagnostics.push(
910
932
  (0, import_layoutCore.diagnostic)("invalid-layout-request", candidate.documentKey, error.message)
@@ -950,15 +972,15 @@ function planAuthoritativePlacement(input) {
950
972
  candidate,
951
973
  request: {
952
974
  directory: parent.directory,
953
- name: path.at(-1),
975
+ name: (0, import_layoutPaths.lastPathName)(path),
954
976
  extension: ".json",
955
977
  role: "document",
956
978
  identity: identityValue(candidate.source)
957
979
  },
958
980
  slot: document.kind === "dimension_table" ? "table-definition" : "document"
959
981
  });
960
- } else if (document.kind === "settings") {
961
- const path = "definitions/settings.json";
982
+ } else if (FIXED_PATHS[document.kind]) {
983
+ const path = FIXED_PATHS[document.kind];
962
984
  if (claimFixed({
963
985
  path,
964
986
  kind: "file",
@@ -1037,8 +1059,8 @@ function planAuthoritativePlacement(input) {
1037
1059
  let destination = tableDestinations.get(id);
1038
1060
  if (!destination) {
1039
1061
  const tableSource = `resource/dimension_table/id/${id}`;
1040
- const table = input.currentGrouped.sources.filter(
1041
- (mapping) => (0, import_layoutCore.sourceIdentityKey)(mapping.source) === tableSource && mapping.selector.slot === "table-definition"
1062
+ const table = (groupedBySource.get(tableSource) ?? []).filter(
1063
+ (mapping) => mapping.selector.slot === "table-definition"
1042
1064
  );
1043
1065
  const file = table.length === 1 ? table[0].selector.file : candidate.current?.codec === "grouped" ? candidate.current.mapping.selector.file : void 0;
1044
1066
  if (file) destination = { file, slot: "member-set" };
@@ -1107,7 +1129,11 @@ function planAuthoritativePlacement(input) {
1107
1129
  ...candidate.current.mapping.selector,
1108
1130
  identity: { id: identityValue(candidate.source) }
1109
1131
  });
1110
- } else pendingShareGroups.set(key, [...pendingShareGroups.get(key) ?? [], candidate]);
1132
+ } else {
1133
+ const pending = pendingShareGroups.get(key);
1134
+ if (pending) pending.push(candidate);
1135
+ else pendingShareGroups.set(key, [candidate]);
1136
+ }
1111
1137
  }
1112
1138
  for (const [key, candidates] of [...pendingShareGroups].sort(([left], [right]) => left.localeCompare(right))) {
1113
1139
  const owner = groupOwner(candidates[0].document);
@@ -1284,7 +1310,9 @@ function planAuthoritativePlacement(input) {
1284
1310
  );
1285
1311
  groupedTargetKeys.add(key);
1286
1312
  const fileKey = (0, import_layoutPaths.layoutCollisionKey)(selector.file);
1287
- groupedFileOwners.set(fileKey, [...groupedFileOwners.get(fileKey) ?? [], correspondence]);
1313
+ const fileOwners = groupedFileOwners.get(fileKey);
1314
+ if (fileOwners) fileOwners.push(correspondence);
1315
+ else groupedFileOwners.set(fileKey, [correspondence]);
1288
1316
  }
1289
1317
  for (const owners of groupedFileOwners.values()) {
1290
1318
  if (owners.length < 2) continue;
@@ -1410,43 +1438,51 @@ function validateRenderedIdentity(document, source) {
1410
1438
  if (resourceId(document.id) !== source.resource.id)
1411
1439
  throw new Error(`Head document identity does not match its key: ${source.resource.kind}/${source.resource.id}`);
1412
1440
  }
1413
- function exactDangling(value) {
1441
+ function exactMarker(value) {
1414
1442
  const marker = (0, import_layoutCore.object)(value);
1415
1443
  if (!marker || Object.keys(marker).length !== 1) return void 0;
1416
- return resourceId(marker.dangling);
1444
+ return resourceId(marker.dangling) ?? resourceId(marker.hidden);
1417
1445
  }
1418
- function validPath(value) {
1419
- return Array.isArray(value) && value.every((part) => typeof part === "string");
1446
+ function diagnosticsByResource(diagnostics) {
1447
+ const byResource = /* @__PURE__ */ new Map();
1448
+ for (const diagnostic2 of diagnostics) {
1449
+ if (typeof diagnostic2.kind !== "string" || typeof diagnostic2.id !== "string") continue;
1450
+ const key = JSON.stringify([diagnostic2.kind, diagnostic2.id]);
1451
+ const list = byResource.get(key);
1452
+ if (list) list.push(diagnostic2);
1453
+ else byResource.set(key, [diagnostic2]);
1454
+ }
1455
+ return (kind, id) => byResource.get(JSON.stringify([kind, id])) ?? [];
1420
1456
  }
1421
- function nullLocationCode(diagnostics, kind, id) {
1457
+ function nullLocationCode(diagnosticsOf, kind, id) {
1422
1458
  const codes = [
1423
1459
  ...new Set(
1424
- diagnostics.filter((diagnostic2) => diagnostic2.kind === kind && diagnostic2.id === id).map((diagnostic2) => diagnostic2.code).filter((code) => NULL_LOCATION_CODES.has(code))
1460
+ diagnosticsOf(kind, id).map((diagnostic2) => diagnostic2.code).filter((code) => NULL_LOCATION_CODES.has(code))
1425
1461
  )
1426
1462
  ];
1427
1463
  if (codes.length > 1) throw new Error(`Head has conflicting placement diagnostics for ${kind}/${id}`);
1428
1464
  return codes[0];
1429
1465
  }
1430
- function groupedCause(document, source, diagnostics) {
1466
+ function groupedCause(document, source, diagnosticsOf) {
1431
1467
  const value = document;
1432
1468
  const folder = value.folder;
1433
1469
  if (folder === null) {
1434
- const code = nullLocationCode(diagnostics, source.resource.kind, source.resource.id);
1470
+ const code = nullLocationCode(diagnosticsOf, source.resource.kind, source.resource.id);
1435
1471
  return code ? { type: "null-location", code } : void 0;
1436
1472
  }
1437
- if (validPath(folder)) return void 0;
1438
- const folderId = exactDangling(folder);
1473
+ if ((0, import_layoutPaths.itemFolderPath)(folder)) return void 0;
1474
+ const folderId = exactMarker(folder);
1439
1475
  if (folderId) return { type: "dangling-folder", folderId };
1440
1476
  throw new Error(`Head has an invalid folder location for ${source.resource.kind}/${source.resource.id}`);
1441
1477
  }
1442
1478
  function folderCause(document, source) {
1443
1479
  const value = document;
1444
- if (validPath(value.path)) return void 0;
1480
+ if ((0, import_layoutPaths.folderPathSegments)(value.path)) return void 0;
1445
1481
  if (value.path !== null)
1446
1482
  throw new Error(`Head has an invalid folder path for ${source.resource.kind}/${source.resource.id}`);
1447
1483
  if (typeof value.name !== "string")
1448
1484
  throw new Error(`Head has an invalid damaged folder name for ${source.resource.kind}/${source.resource.id}`);
1449
- const parentId = exactDangling(value.parent);
1485
+ const parentId = exactMarker(value.parent);
1450
1486
  if (!parentId)
1451
1487
  throw new Error(`Head has an invalid damaged folder parent for ${source.resource.kind}/${source.resource.id}`);
1452
1488
  return { type: "dangling-folder-parent", parentId };
@@ -1460,19 +1496,19 @@ function shareOwner(value) {
1460
1496
  if (id === void 0 === (dangling === void 0)) throw new Error("Head has an invalid share owner");
1461
1497
  return id ? { kind: owner.kind, id } : { kind: owner.kind, dangling };
1462
1498
  }
1463
- function shareCause(document, source, diagnostics) {
1499
+ function shareCause(document, source, diagnosticsOf) {
1464
1500
  const owner = shareOwner(document.owner);
1465
- if ("dangling" in owner) return { type: "damaged-share-owner", owner };
1466
- const damaged = diagnostics.some(
1467
- (diagnostic2) => diagnostic2.kind === source.resource.kind && diagnostic2.id === source.resource.id && diagnostic2.code === "share-owner-damaged"
1501
+ if ((0, import_layoutProjection.isMarkerOwner)(owner)) return { type: "damaged-share-owner", owner };
1502
+ const damaged = diagnosticsOf(source.resource.kind, source.resource.id).some(
1503
+ (diagnostic2) => diagnostic2.code === "share-owner-damaged"
1468
1504
  );
1469
1505
  return damaged ? { type: "damaged-share-owner", owner, code: "share-owner-damaged" } : void 0;
1470
1506
  }
1471
- function causeFor(document, source, diagnostics) {
1507
+ function causeFor(document, source, diagnosticsOf) {
1472
1508
  if (document.kind === "folder") return folderCause(document, source);
1473
- if (document.kind === "share") return shareCause(document, source, diagnostics);
1509
+ if (document.kind === "share") return shareCause(document, source, diagnosticsOf);
1474
1510
  if (document.kind === "file" || import_layoutCore.TREE_DOCUMENT_KINDS.has(document.kind))
1475
- return groupedCause(document, source, diagnostics);
1511
+ return groupedCause(document, source, diagnosticsOf);
1476
1512
  return void 0;
1477
1513
  }
1478
1514
  function locationHash(document) {
@@ -1493,10 +1529,11 @@ function extractAuthoritativeDamageEvidence(head, documents) {
1493
1529
  for (const hash of Object.values(head.manifest))
1494
1530
  if (typeof hash !== "string" || !import_layoutCore.SHA256.test(hash)) throw new Error("Head manifest has an invalid hash");
1495
1531
  const evidence = /* @__PURE__ */ new Map();
1532
+ const diagnosticsOf = diagnosticsByResource(head.diagnostics);
1496
1533
  for (const [documentKey, document] of documents) {
1497
1534
  const source = resourceFromKey(documentKey);
1498
1535
  validateRenderedIdentity(document, source);
1499
- const cause = causeFor(document, source, head.diagnostics);
1536
+ const cause = causeFor(document, source, diagnosticsOf);
1500
1537
  if (!cause) continue;
1501
1538
  evidence.set(documentKey, {
1502
1539
  documentKey,