@superbee/core 0.2.0-pre.5 → 0.2.0-pre.51

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 (744) hide show
  1. package/README.md +1378 -0
  2. package/dist/artifact-contract.d.ts +90 -0
  3. package/dist/artifact-contract.d.ts.map +1 -0
  4. package/dist/artifact-contract.js +205 -0
  5. package/dist/artifact-contract.js.map +1 -0
  6. package/dist/backend.d.ts +41 -2
  7. package/dist/backend.d.ts.map +1 -1
  8. package/dist/backend.js +281 -22
  9. package/dist/backend.js.map +1 -1
  10. package/dist/blob-contract.d.ts +82 -0
  11. package/dist/blob-contract.d.ts.map +1 -0
  12. package/dist/blob-contract.js +134 -0
  13. package/dist/blob-contract.js.map +1 -0
  14. package/dist/blob-journal.d.ts +303 -0
  15. package/dist/blob-journal.d.ts.map +1 -0
  16. package/dist/blob-journal.js +541 -0
  17. package/dist/blob-journal.js.map +1 -0
  18. package/dist/body-pages.d.ts +20 -0
  19. package/dist/body-pages.d.ts.map +1 -0
  20. package/dist/body-pages.js +56 -0
  21. package/dist/body-pages.js.map +1 -0
  22. package/dist/body-replace-guards.d.ts +78 -0
  23. package/dist/body-replace-guards.d.ts.map +1 -0
  24. package/dist/body-replace-guards.js +269 -0
  25. package/dist/body-replace-guards.js.map +1 -0
  26. package/dist/bounded-yaml.d.ts +28 -0
  27. package/dist/bounded-yaml.d.ts.map +1 -0
  28. package/dist/bounded-yaml.js +182 -0
  29. package/dist/bounded-yaml.js.map +1 -0
  30. package/dist/builtin-recipes/content.d.ts +93 -0
  31. package/dist/builtin-recipes/content.d.ts.map +1 -0
  32. package/dist/builtin-recipes/content.js +288 -0
  33. package/dist/builtin-recipes/content.js.map +1 -0
  34. package/dist/builtin-recipes/site.d.ts +5 -0
  35. package/dist/builtin-recipes/site.d.ts.map +1 -0
  36. package/dist/builtin-recipes/site.js +83 -0
  37. package/dist/builtin-recipes/site.js.map +1 -0
  38. package/dist/builtin-recipes.d.ts +13 -0
  39. package/dist/builtin-recipes.d.ts.map +1 -0
  40. package/dist/builtin-recipes.js +123 -0
  41. package/dist/builtin-recipes.js.map +1 -0
  42. package/dist/bundle-health/index.d.ts +14 -0
  43. package/dist/bundle-health/index.d.ts.map +1 -0
  44. package/dist/bundle-health/index.js +12 -0
  45. package/dist/bundle-health/index.js.map +1 -0
  46. package/dist/bundle-health/kind-findings.d.ts +44 -0
  47. package/dist/bundle-health/kind-findings.d.ts.map +1 -0
  48. package/dist/bundle-health/kind-findings.js +67 -0
  49. package/dist/bundle-health/kind-findings.js.map +1 -0
  50. package/dist/bundle-health/legacy-page.d.ts +21 -0
  51. package/dist/bundle-health/legacy-page.d.ts.map +1 -0
  52. package/dist/bundle-health/legacy-page.js +25 -0
  53. package/dist/bundle-health/legacy-page.js.map +1 -0
  54. package/dist/bundle-health/report.d.ts +191 -0
  55. package/dist/bundle-health/report.d.ts.map +1 -0
  56. package/dist/bundle-health/report.js +419 -0
  57. package/dist/bundle-health/report.js.map +1 -0
  58. package/dist/bundle-ops.d.ts +9 -3
  59. package/dist/bundle-ops.d.ts.map +1 -1
  60. package/dist/bundle-ops.js +13 -6
  61. package/dist/bundle-ops.js.map +1 -1
  62. package/dist/bundle.d.ts +2 -4
  63. package/dist/bundle.d.ts.map +1 -1
  64. package/dist/bundle.js +3 -12
  65. package/dist/bundle.js.map +1 -1
  66. package/dist/code-point-order.d.ts +8 -0
  67. package/dist/code-point-order.d.ts.map +1 -0
  68. package/dist/code-point-order.js +20 -0
  69. package/dist/code-point-order.js.map +1 -0
  70. package/dist/code-unit-order.d.ts +15 -0
  71. package/dist/code-unit-order.d.ts.map +1 -0
  72. package/dist/code-unit-order.js +17 -0
  73. package/dist/code-unit-order.js.map +1 -0
  74. package/dist/connector-request.d.ts +112 -0
  75. package/dist/connector-request.d.ts.map +1 -0
  76. package/dist/connector-request.js +495 -0
  77. package/dist/connector-request.js.map +1 -0
  78. package/dist/connectors.d.ts +297 -0
  79. package/dist/connectors.d.ts.map +1 -0
  80. package/dist/connectors.js +1233 -0
  81. package/dist/connectors.js.map +1 -0
  82. package/dist/convention-record.d.ts +9 -0
  83. package/dist/convention-record.d.ts.map +1 -0
  84. package/dist/convention-record.js +13 -0
  85. package/dist/convention-record.js.map +1 -0
  86. package/dist/cross-bundle.d.ts +135 -0
  87. package/dist/cross-bundle.d.ts.map +1 -0
  88. package/dist/cross-bundle.js +191 -0
  89. package/dist/cross-bundle.js.map +1 -0
  90. package/dist/dependencies.d.ts +94 -0
  91. package/dist/dependencies.d.ts.map +1 -0
  92. package/dist/dependencies.js +180 -0
  93. package/dist/dependencies.js.map +1 -0
  94. package/dist/document-codec.d.ts +9 -2
  95. package/dist/document-codec.d.ts.map +1 -1
  96. package/dist/document-codec.js +10 -5
  97. package/dist/document-codec.js.map +1 -1
  98. package/dist/document-field-actions.d.ts +31 -1
  99. package/dist/document-field-actions.d.ts.map +1 -1
  100. package/dist/document-field-actions.js +137 -34
  101. package/dist/document-field-actions.js.map +1 -1
  102. package/dist/document-mutation.d.ts +37 -13
  103. package/dist/document-mutation.d.ts.map +1 -1
  104. package/dist/document-mutation.js +161 -62
  105. package/dist/document-mutation.js.map +1 -1
  106. package/dist/document-scan.d.ts +26 -0
  107. package/dist/document-scan.d.ts.map +1 -0
  108. package/dist/document-scan.js +70 -0
  109. package/dist/document-scan.js.map +1 -0
  110. package/dist/document-transfer.d.ts +312 -0
  111. package/dist/document-transfer.d.ts.map +1 -0
  112. package/dist/document-transfer.js +1400 -0
  113. package/dist/document-transfer.js.map +1 -0
  114. package/dist/document-write-policy.d.ts.map +1 -1
  115. package/dist/document-write-policy.js +4 -2
  116. package/dist/document-write-policy.js.map +1 -1
  117. package/dist/domain-model.d.ts +73 -0
  118. package/dist/domain-model.d.ts.map +1 -0
  119. package/dist/domain-model.js +169 -0
  120. package/dist/domain-model.js.map +1 -0
  121. package/dist/engine.d.ts +20 -19
  122. package/dist/engine.d.ts.map +1 -1
  123. package/dist/engine.js +85 -44
  124. package/dist/engine.js.map +1 -1
  125. package/dist/errors.d.ts +37 -1
  126. package/dist/errors.d.ts.map +1 -1
  127. package/dist/errors.js +75 -3
  128. package/dist/errors.js.map +1 -1
  129. package/dist/file-journaled-backend-internal.d.ts +21 -0
  130. package/dist/file-journaled-backend-internal.d.ts.map +1 -0
  131. package/dist/file-journaled-backend-internal.js +12 -0
  132. package/dist/file-journaled-backend-internal.js.map +1 -0
  133. package/dist/file-journaled-backend.d.ts +160 -0
  134. package/dist/file-journaled-backend.d.ts.map +1 -0
  135. package/dist/file-journaled-backend.js +1345 -0
  136. package/dist/file-journaled-backend.js.map +1 -0
  137. package/dist/filesystem-identity.d.ts +106 -17
  138. package/dist/filesystem-identity.d.ts.map +1 -1
  139. package/dist/filesystem-identity.js +513 -51
  140. package/dist/filesystem-identity.js.map +1 -1
  141. package/dist/filesystem-lock.d.ts +16 -2
  142. package/dist/filesystem-lock.d.ts.map +1 -1
  143. package/dist/filesystem-lock.js +402 -27
  144. package/dist/filesystem-lock.js.map +1 -1
  145. package/dist/filesystem-push-role.d.ts +77 -0
  146. package/dist/filesystem-push-role.d.ts.map +1 -0
  147. package/dist/filesystem-push-role.js +165 -0
  148. package/dist/filesystem-push-role.js.map +1 -0
  149. package/dist/filesystem-temp-name.d.ts +9 -0
  150. package/dist/filesystem-temp-name.d.ts.map +1 -0
  151. package/dist/filesystem-temp-name.js +20 -0
  152. package/dist/filesystem-temp-name.js.map +1 -0
  153. package/dist/filesystem.d.ts +6 -0
  154. package/dist/filesystem.d.ts.map +1 -1
  155. package/dist/filesystem.js +2 -1
  156. package/dist/filesystem.js.map +1 -1
  157. package/dist/freshness.d.ts +15 -1
  158. package/dist/freshness.d.ts.map +1 -1
  159. package/dist/freshness.js +29 -16
  160. package/dist/freshness.js.map +1 -1
  161. package/dist/frontmatter-contract.d.ts +14 -0
  162. package/dist/frontmatter-contract.d.ts.map +1 -1
  163. package/dist/frontmatter-contract.js +22 -0
  164. package/dist/frontmatter-contract.js.map +1 -1
  165. package/dist/frontmatter-splitter.d.ts +6 -0
  166. package/dist/frontmatter-splitter.d.ts.map +1 -1
  167. package/dist/frontmatter-splitter.js +8 -0
  168. package/dist/frontmatter-splitter.js.map +1 -1
  169. package/dist/frontmatter.d.ts +16 -7
  170. package/dist/frontmatter.d.ts.map +1 -1
  171. package/dist/frontmatter.js +48 -11
  172. package/dist/frontmatter.js.map +1 -1
  173. package/dist/governed-body-write.d.ts +8 -1
  174. package/dist/governed-body-write.d.ts.map +1 -1
  175. package/dist/governed-body-write.js +22 -8
  176. package/dist/governed-body-write.js.map +1 -1
  177. package/dist/heads-digest.d.ts.map +1 -1
  178. package/dist/heads-digest.js +2 -1
  179. package/dist/heads-digest.js.map +1 -1
  180. package/dist/host-text.d.ts +31 -0
  181. package/dist/host-text.d.ts.map +1 -0
  182. package/dist/host-text.js +77 -0
  183. package/dist/host-text.js.map +1 -0
  184. package/dist/hosted-client/binding.d.ts +7 -0
  185. package/dist/hosted-client/binding.d.ts.map +1 -0
  186. package/dist/hosted-client/binding.js +10 -0
  187. package/dist/hosted-client/binding.js.map +1 -0
  188. package/dist/hosted-client/blob-delivery.d.ts +68 -0
  189. package/dist/hosted-client/blob-delivery.d.ts.map +1 -0
  190. package/dist/hosted-client/blob-delivery.js +170 -0
  191. package/dist/hosted-client/blob-delivery.js.map +1 -0
  192. package/dist/hosted-client/blob-write.d.ts +387 -0
  193. package/dist/hosted-client/blob-write.d.ts.map +1 -0
  194. package/dist/hosted-client/blob-write.js +770 -0
  195. package/dist/hosted-client/blob-write.js.map +1 -0
  196. package/dist/hosted-client/bundle-listing.d.ts +46 -0
  197. package/dist/hosted-client/bundle-listing.d.ts.map +1 -0
  198. package/dist/hosted-client/bundle-listing.js +36 -0
  199. package/dist/hosted-client/bundle-listing.js.map +1 -0
  200. package/dist/hosted-client/client.d.ts +249 -0
  201. package/dist/hosted-client/client.d.ts.map +1 -0
  202. package/dist/hosted-client/client.js +381 -0
  203. package/dist/hosted-client/client.js.map +1 -0
  204. package/dist/hosted-client/directory.d.ts +46 -0
  205. package/dist/hosted-client/directory.d.ts.map +1 -0
  206. package/dist/hosted-client/directory.js +74 -0
  207. package/dist/hosted-client/directory.js.map +1 -0
  208. package/dist/hosted-client/errors.d.ts +26 -0
  209. package/dist/hosted-client/errors.d.ts.map +1 -0
  210. package/dist/hosted-client/errors.js +35 -0
  211. package/dist/hosted-client/errors.js.map +1 -0
  212. package/dist/hosted-client/inbox.d.ts +320 -0
  213. package/dist/hosted-client/inbox.d.ts.map +1 -0
  214. package/dist/hosted-client/inbox.js +379 -0
  215. package/dist/hosted-client/inbox.js.map +1 -0
  216. package/dist/hosted-client/index.d.ts +31 -0
  217. package/dist/hosted-client/index.d.ts.map +1 -0
  218. package/dist/hosted-client/index.js +33 -0
  219. package/dist/hosted-client/index.js.map +1 -0
  220. package/dist/hosted-client/journal.d.ts +103 -0
  221. package/dist/hosted-client/journal.d.ts.map +1 -0
  222. package/dist/hosted-client/journal.js +464 -0
  223. package/dist/hosted-client/journal.js.map +1 -0
  224. package/dist/hosted-client/node.d.ts +74 -0
  225. package/dist/hosted-client/node.d.ts.map +1 -0
  226. package/dist/hosted-client/node.js +219 -0
  227. package/dist/hosted-client/node.js.map +1 -0
  228. package/dist/hosted-client/reference.d.ts +12 -0
  229. package/dist/hosted-client/reference.d.ts.map +1 -0
  230. package/dist/hosted-client/reference.js +29 -0
  231. package/dist/hosted-client/reference.js.map +1 -0
  232. package/dist/hosted-client/view-content.d.ts +184 -0
  233. package/dist/hosted-client/view-content.d.ts.map +1 -0
  234. package/dist/hosted-client/view-content.js +268 -0
  235. package/dist/hosted-client/view-content.js.map +1 -0
  236. package/dist/hosted-client/write.d.ts +219 -0
  237. package/dist/hosted-client/write.d.ts.map +1 -0
  238. package/dist/hosted-client/write.js +419 -0
  239. package/dist/hosted-client/write.js.map +1 -0
  240. package/dist/hosted-transport/answer-rows.d.ts +341 -0
  241. package/dist/hosted-transport/answer-rows.d.ts.map +1 -0
  242. package/dist/hosted-transport/answer-rows.js +594 -0
  243. package/dist/hosted-transport/answer-rows.js.map +1 -0
  244. package/dist/hosted-transport/blob-reads.d.ts +35 -0
  245. package/dist/hosted-transport/blob-reads.d.ts.map +1 -0
  246. package/dist/hosted-transport/blob-reads.js +179 -0
  247. package/dist/hosted-transport/blob-reads.js.map +1 -0
  248. package/dist/hosted-transport/blob-write.d.ts +34 -0
  249. package/dist/hosted-transport/blob-write.d.ts.map +1 -0
  250. package/dist/hosted-transport/blob-write.js +115 -0
  251. package/dist/hosted-transport/blob-write.js.map +1 -0
  252. package/dist/hosted-transport/carrier.d.ts +153 -0
  253. package/dist/hosted-transport/carrier.d.ts.map +1 -0
  254. package/dist/hosted-transport/carrier.js +273 -0
  255. package/dist/hosted-transport/carrier.js.map +1 -0
  256. package/dist/hosted-transport/document-backend.d.ts +74 -0
  257. package/dist/hosted-transport/document-backend.d.ts.map +1 -0
  258. package/dist/hosted-transport/document-backend.js +160 -0
  259. package/dist/hosted-transport/document-backend.js.map +1 -0
  260. package/dist/hosted-transport/history-pages.d.ts +55 -0
  261. package/dist/hosted-transport/history-pages.d.ts.map +1 -0
  262. package/dist/hosted-transport/history-pages.js +69 -0
  263. package/dist/hosted-transport/history-pages.js.map +1 -0
  264. package/dist/hosted-transport/index.d.ts +20 -0
  265. package/dist/hosted-transport/index.d.ts.map +1 -0
  266. package/dist/hosted-transport/index.js +20 -0
  267. package/dist/hosted-transport/index.js.map +1 -0
  268. package/dist/hosted-transport/operations.d.ts +85 -0
  269. package/dist/hosted-transport/operations.d.ts.map +1 -0
  270. package/dist/hosted-transport/operations.js +128 -0
  271. package/dist/hosted-transport/operations.js.map +1 -0
  272. package/dist/hosted-transport/paged-reads.d.ts +87 -0
  273. package/dist/hosted-transport/paged-reads.d.ts.map +1 -0
  274. package/dist/hosted-transport/paged-reads.js +238 -0
  275. package/dist/hosted-transport/paged-reads.js.map +1 -0
  276. package/dist/hosted-transport/port-run.d.ts +41 -0
  277. package/dist/hosted-transport/port-run.d.ts.map +1 -0
  278. package/dist/hosted-transport/port-run.js +92 -0
  279. package/dist/hosted-transport/port-run.js.map +1 -0
  280. package/dist/hosted-transport/read-adapter.d.ts +266 -0
  281. package/dist/hosted-transport/read-adapter.d.ts.map +1 -0
  282. package/dist/hosted-transport/read-adapter.js +570 -0
  283. package/dist/hosted-transport/read-adapter.js.map +1 -0
  284. package/dist/hosted-transport/root-write.d.ts +114 -0
  285. package/dist/hosted-transport/root-write.d.ts.map +1 -0
  286. package/dist/hosted-transport/root-write.js +174 -0
  287. package/dist/hosted-transport/root-write.js.map +1 -0
  288. package/dist/hosted-transport/whole-document-transport.d.ts +216 -0
  289. package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -0
  290. package/dist/hosted-transport/whole-document-transport.js +470 -0
  291. package/dist/hosted-transport/whole-document-transport.js.map +1 -0
  292. package/dist/identity-fold.d.ts +16 -0
  293. package/dist/identity-fold.d.ts.map +1 -0
  294. package/dist/identity-fold.js +24 -0
  295. package/dist/identity-fold.js.map +1 -0
  296. package/dist/index-projection.d.ts +2 -1
  297. package/dist/index-projection.d.ts.map +1 -1
  298. package/dist/index-projection.js +38 -28
  299. package/dist/index-projection.js.map +1 -1
  300. package/dist/index.d.ts +58 -19
  301. package/dist/index.d.ts.map +1 -1
  302. package/dist/index.js +48 -21
  303. package/dist/index.js.map +1 -1
  304. package/dist/indexeddb-backend.d.ts +6 -32
  305. package/dist/indexeddb-backend.d.ts.map +1 -1
  306. package/dist/indexeddb-backend.js +82 -8
  307. package/dist/indexeddb-backend.js.map +1 -1
  308. package/dist/inventory-guard.d.ts +58 -0
  309. package/dist/inventory-guard.d.ts.map +1 -0
  310. package/dist/inventory-guard.js +169 -0
  311. package/dist/inventory-guard.js.map +1 -0
  312. package/dist/journaled-backend.d.ts +86 -8
  313. package/dist/journaled-backend.d.ts.map +1 -1
  314. package/dist/journaled-backend.js +64 -69
  315. package/dist/journaled-backend.js.map +1 -1
  316. package/dist/json-data.d.ts +3 -0
  317. package/dist/json-data.d.ts.map +1 -0
  318. package/dist/json-data.js +19 -0
  319. package/dist/json-data.js.map +1 -0
  320. package/dist/kind-authoring.d.ts +190 -0
  321. package/dist/kind-authoring.d.ts.map +1 -0
  322. package/dist/kind-authoring.js +510 -0
  323. package/dist/kind-authoring.js.map +1 -0
  324. package/dist/kind-changes.d.ts +45 -0
  325. package/dist/kind-changes.d.ts.map +1 -0
  326. package/dist/kind-changes.js +96 -0
  327. package/dist/kind-changes.js.map +1 -0
  328. package/dist/kind-conformance-error.d.ts +15 -0
  329. package/dist/kind-conformance-error.d.ts.map +1 -0
  330. package/dist/kind-conformance-error.js +20 -0
  331. package/dist/kind-conformance-error.js.map +1 -0
  332. package/dist/kind-coverage.d.ts +100 -0
  333. package/dist/kind-coverage.d.ts.map +1 -0
  334. package/dist/kind-coverage.js +185 -0
  335. package/dist/kind-coverage.js.map +1 -0
  336. package/dist/kind-deprecation.d.ts +32 -0
  337. package/dist/kind-deprecation.d.ts.map +1 -0
  338. package/dist/kind-deprecation.js +141 -0
  339. package/dist/kind-deprecation.js.map +1 -0
  340. package/dist/kind-field-mutation.d.ts +4 -0
  341. package/dist/kind-field-mutation.d.ts.map +1 -1
  342. package/dist/kind-field-mutation.js +28 -3
  343. package/dist/kind-field-mutation.js.map +1 -1
  344. package/dist/kind-undeclared-fields.d.ts +70 -0
  345. package/dist/kind-undeclared-fields.d.ts.map +1 -0
  346. package/dist/kind-undeclared-fields.js +121 -0
  347. package/dist/kind-undeclared-fields.js.map +1 -0
  348. package/dist/kinds-load.d.ts.map +1 -1
  349. package/dist/kinds-load.js +8 -5
  350. package/dist/kinds-load.js.map +1 -1
  351. package/dist/kinds.d.ts +117 -6
  352. package/dist/kinds.d.ts.map +1 -1
  353. package/dist/kinds.js +410 -24
  354. package/dist/kinds.js.map +1 -1
  355. package/dist/link-emit.d.ts +29 -0
  356. package/dist/link-emit.d.ts.map +1 -0
  357. package/dist/link-emit.js +39 -0
  358. package/dist/link-emit.js.map +1 -0
  359. package/dist/link-findings.d.ts +130 -0
  360. package/dist/link-findings.d.ts.map +1 -0
  361. package/dist/link-findings.js +261 -0
  362. package/dist/link-findings.js.map +1 -0
  363. package/dist/link-types.d.ts +34 -0
  364. package/dist/link-types.d.ts.map +1 -0
  365. package/dist/link-types.js +79 -0
  366. package/dist/link-types.js.map +1 -0
  367. package/dist/links.d.ts +64 -8
  368. package/dist/links.d.ts.map +1 -1
  369. package/dist/links.js +328 -60
  370. package/dist/links.js.map +1 -1
  371. package/dist/managed-document-metadata.d.ts +2 -0
  372. package/dist/managed-document-metadata.d.ts.map +1 -0
  373. package/dist/managed-document-metadata.js +9 -0
  374. package/dist/managed-document-metadata.js.map +1 -0
  375. package/dist/memory-backend.d.ts +3 -0
  376. package/dist/memory-backend.d.ts.map +1 -1
  377. package/dist/memory-backend.js +46 -4
  378. package/dist/memory-backend.js.map +1 -1
  379. package/dist/okf-actor.d.ts +1 -0
  380. package/dist/okf-actor.d.ts.map +1 -1
  381. package/dist/okf-actor.js +1 -0
  382. package/dist/okf-actor.js.map +1 -1
  383. package/dist/okf-authoring.d.ts +4 -0
  384. package/dist/okf-authoring.d.ts.map +1 -0
  385. package/dist/okf-authoring.js +12 -0
  386. package/dist/okf-authoring.js.map +1 -0
  387. package/dist/okf-standard-fields.d.ts +3 -0
  388. package/dist/okf-standard-fields.d.ts.map +1 -1
  389. package/dist/okf-standard-fields.js +3 -0
  390. package/dist/okf-standard-fields.js.map +1 -1
  391. package/dist/page.d.ts +3 -7
  392. package/dist/page.d.ts.map +1 -1
  393. package/dist/page.js +3 -7
  394. package/dist/page.js.map +1 -1
  395. package/dist/path-fold.d.ts +52 -0
  396. package/dist/path-fold.d.ts.map +1 -0
  397. package/dist/path-fold.js +54 -0
  398. package/dist/path-fold.js.map +1 -0
  399. package/dist/paths.d.ts +46 -0
  400. package/dist/paths.d.ts.map +1 -1
  401. package/dist/paths.js +114 -1
  402. package/dist/paths.js.map +1 -1
  403. package/dist/platform.d.ts +22 -2
  404. package/dist/platform.d.ts.map +1 -1
  405. package/dist/platform.js +16 -0
  406. package/dist/platform.js.map +1 -1
  407. package/dist/portable-export.d.ts +119 -0
  408. package/dist/portable-export.d.ts.map +1 -0
  409. package/dist/portable-export.js +501 -0
  410. package/dist/portable-export.js.map +1 -0
  411. package/dist/portable-frontmatter.d.ts +11 -0
  412. package/dist/portable-frontmatter.d.ts.map +1 -1
  413. package/dist/portable-frontmatter.js +33 -5
  414. package/dist/portable-frontmatter.js.map +1 -1
  415. package/dist/publication-filesystem.d.ts +1 -1
  416. package/dist/publication-filesystem.d.ts.map +1 -1
  417. package/dist/publication-filesystem.js +1 -1
  418. package/dist/publication-filesystem.js.map +1 -1
  419. package/dist/qualified-links.d.ts +67 -0
  420. package/dist/qualified-links.d.ts.map +1 -0
  421. package/dist/qualified-links.js +117 -0
  422. package/dist/qualified-links.js.map +1 -0
  423. package/dist/query-filter.d.ts +16 -4
  424. package/dist/query-filter.d.ts.map +1 -1
  425. package/dist/query-filter.js +44 -2
  426. package/dist/query-filter.js.map +1 -1
  427. package/dist/query-order.d.ts +22 -0
  428. package/dist/query-order.d.ts.map +1 -0
  429. package/dist/query-order.js +43 -0
  430. package/dist/query-order.js.map +1 -0
  431. package/dist/recipe-lifecycle/errors.d.ts +96 -0
  432. package/dist/recipe-lifecycle/errors.d.ts.map +1 -0
  433. package/dist/recipe-lifecycle/errors.js +122 -0
  434. package/dist/recipe-lifecycle/errors.js.map +1 -0
  435. package/dist/recipe-lifecycle/evolution.d.ts +124 -0
  436. package/dist/recipe-lifecycle/evolution.d.ts.map +1 -0
  437. package/dist/recipe-lifecycle/evolution.js +988 -0
  438. package/dist/recipe-lifecycle/evolution.js.map +1 -0
  439. package/dist/recipe-lifecycle/index.d.ts +34 -0
  440. package/dist/recipe-lifecycle/index.d.ts.map +1 -0
  441. package/dist/recipe-lifecycle/index.js +28 -0
  442. package/dist/recipe-lifecycle/index.js.map +1 -0
  443. package/dist/recipe-lifecycle/install.d.ts +161 -0
  444. package/dist/recipe-lifecycle/install.d.ts.map +1 -0
  445. package/dist/recipe-lifecycle/install.js +632 -0
  446. package/dist/recipe-lifecycle/install.js.map +1 -0
  447. package/dist/recipe-lifecycle/legacy-aliases.d.ts +4 -0
  448. package/dist/recipe-lifecycle/legacy-aliases.d.ts.map +1 -0
  449. package/dist/recipe-lifecycle/legacy-aliases.js +22 -0
  450. package/dist/recipe-lifecycle/legacy-aliases.js.map +1 -0
  451. package/dist/recipe-lifecycle/retirement-apply.d.ts +59 -0
  452. package/dist/recipe-lifecycle/retirement-apply.d.ts.map +1 -0
  453. package/dist/recipe-lifecycle/retirement-apply.js +165 -0
  454. package/dist/recipe-lifecycle/retirement-apply.js.map +1 -0
  455. package/dist/recipe-lifecycle/retirement.d.ts +89 -0
  456. package/dist/recipe-lifecycle/retirement.d.ts.map +1 -0
  457. package/dist/recipe-lifecycle/retirement.js +347 -0
  458. package/dist/recipe-lifecycle/retirement.js.map +1 -0
  459. package/dist/recipe-lifecycle/stamp.d.ts +146 -0
  460. package/dist/recipe-lifecycle/stamp.d.ts.map +1 -0
  461. package/dist/recipe-lifecycle/stamp.js +361 -0
  462. package/dist/recipe-lifecycle/stamp.js.map +1 -0
  463. package/dist/recipe-qualify.d.ts +80 -0
  464. package/dist/recipe-qualify.d.ts.map +1 -0
  465. package/dist/recipe-qualify.js +352 -0
  466. package/dist/recipe-qualify.js.map +1 -0
  467. package/dist/recipe-set-preflight.d.ts +139 -0
  468. package/dist/recipe-set-preflight.d.ts.map +1 -0
  469. package/dist/recipe-set-preflight.js +536 -0
  470. package/dist/recipe-set-preflight.js.map +1 -0
  471. package/dist/recipe-sources.d.ts +209 -0
  472. package/dist/recipe-sources.d.ts.map +1 -0
  473. package/dist/recipe-sources.js +607 -0
  474. package/dist/recipe-sources.js.map +1 -0
  475. package/dist/recipes.d.ts +45 -1
  476. package/dist/recipes.d.ts.map +1 -1
  477. package/dist/recipes.js +138 -1
  478. package/dist/recipes.js.map +1 -1
  479. package/dist/record-overlay/apply.d.ts +43 -0
  480. package/dist/record-overlay/apply.d.ts.map +1 -0
  481. package/dist/record-overlay/apply.js +523 -0
  482. package/dist/record-overlay/apply.js.map +1 -0
  483. package/dist/record-overlay/canonical.d.ts +22 -0
  484. package/dist/record-overlay/canonical.d.ts.map +1 -0
  485. package/dist/record-overlay/canonical.js +47 -0
  486. package/dist/record-overlay/canonical.js.map +1 -0
  487. package/dist/record-overlay/digest.d.ts +4 -0
  488. package/dist/record-overlay/digest.d.ts.map +1 -0
  489. package/dist/record-overlay/digest.js +11 -0
  490. package/dist/record-overlay/digest.js.map +1 -0
  491. package/dist/record-overlay/errors.d.ts +44 -0
  492. package/dist/record-overlay/errors.d.ts.map +1 -0
  493. package/dist/record-overlay/errors.js +55 -0
  494. package/dist/record-overlay/errors.js.map +1 -0
  495. package/dist/record-overlay/findings.d.ts +5 -0
  496. package/dist/record-overlay/findings.d.ts.map +1 -0
  497. package/dist/record-overlay/findings.js +86 -0
  498. package/dist/record-overlay/findings.js.map +1 -0
  499. package/dist/record-overlay/index.d.ts +23 -0
  500. package/dist/record-overlay/index.d.ts.map +1 -0
  501. package/dist/record-overlay/index.js +21 -0
  502. package/dist/record-overlay/index.js.map +1 -0
  503. package/dist/record-overlay/plan.d.ts +12 -0
  504. package/dist/record-overlay/plan.d.ts.map +1 -0
  505. package/dist/record-overlay/plan.js +285 -0
  506. package/dist/record-overlay/plan.js.map +1 -0
  507. package/dist/record-overlay/policy.d.ts +74 -0
  508. package/dist/record-overlay/policy.d.ts.map +1 -0
  509. package/dist/record-overlay/policy.js +235 -0
  510. package/dist/record-overlay/policy.js.map +1 -0
  511. package/dist/record-overlay/redact.d.ts +3 -0
  512. package/dist/record-overlay/redact.d.ts.map +1 -0
  513. package/dist/record-overlay/redact.js +27 -0
  514. package/dist/record-overlay/redact.js.map +1 -0
  515. package/dist/record-overlay/signal-kind.d.ts +30 -0
  516. package/dist/record-overlay/signal-kind.d.ts.map +1 -0
  517. package/dist/record-overlay/signal-kind.js +38 -0
  518. package/dist/record-overlay/signal-kind.js.map +1 -0
  519. package/dist/record-overlay/signal-text.d.ts +52 -0
  520. package/dist/record-overlay/signal-text.d.ts.map +1 -0
  521. package/dist/record-overlay/signal-text.js +126 -0
  522. package/dist/record-overlay/signal-text.js.map +1 -0
  523. package/dist/record-overlay/source-index.d.ts +19 -0
  524. package/dist/record-overlay/source-index.d.ts.map +1 -0
  525. package/dist/record-overlay/source-index.js +102 -0
  526. package/dist/record-overlay/source-index.js.map +1 -0
  527. package/dist/record-overlay/types.d.ts +291 -0
  528. package/dist/record-overlay/types.d.ts.map +1 -0
  529. package/dist/record-overlay/types.js +2 -0
  530. package/dist/record-overlay/types.js.map +1 -0
  531. package/dist/relationships.d.ts +47 -0
  532. package/dist/relationships.d.ts.map +1 -0
  533. package/dist/relationships.js +53 -0
  534. package/dist/relationships.js.map +1 -0
  535. package/dist/remote-backend.d.ts +67 -32
  536. package/dist/remote-backend.d.ts.map +1 -1
  537. package/dist/remote-backend.js +171 -39
  538. package/dist/remote-backend.js.map +1 -1
  539. package/dist/remote-document-codec.d.ts +2 -1
  540. package/dist/remote-document-codec.d.ts.map +1 -1
  541. package/dist/remote-document-codec.js +3 -2
  542. package/dist/remote-document-codec.js.map +1 -1
  543. package/dist/remote-error.d.ts +17 -1
  544. package/dist/remote-error.d.ts.map +1 -1
  545. package/dist/remote-error.js +32 -2
  546. package/dist/remote-error.js.map +1 -1
  547. package/dist/remote-operations.d.ts +0 -40
  548. package/dist/remote-operations.d.ts.map +1 -1
  549. package/dist/remote-operations.js +28 -6
  550. package/dist/remote-operations.js.map +1 -1
  551. package/dist/remote-parsers.d.ts +20 -1
  552. package/dist/remote-parsers.d.ts.map +1 -1
  553. package/dist/remote-parsers.js +1 -1
  554. package/dist/remote-parsers.js.map +1 -1
  555. package/dist/remote.d.ts +2 -4
  556. package/dist/remote.d.ts.map +1 -1
  557. package/dist/remote.js +2 -3
  558. package/dist/remote.js.map +1 -1
  559. package/dist/reserved-write.d.ts +9 -0
  560. package/dist/reserved-write.d.ts.map +1 -0
  561. package/dist/reserved-write.js +15 -0
  562. package/dist/reserved-write.js.map +1 -0
  563. package/dist/search/backend-source.d.ts +6 -0
  564. package/dist/search/backend-source.d.ts.map +1 -0
  565. package/dist/search/backend-source.js +57 -0
  566. package/dist/search/backend-source.js.map +1 -0
  567. package/dist/search/contract.d.ts +158 -0
  568. package/dist/search/contract.d.ts.map +1 -0
  569. package/dist/search/contract.js +78 -0
  570. package/dist/search/contract.js.map +1 -0
  571. package/dist/search/errors.d.ts +30 -0
  572. package/dist/search/errors.d.ts.map +1 -0
  573. package/dist/search/errors.js +50 -0
  574. package/dist/search/errors.js.map +1 -0
  575. package/dist/search/identity.d.ts +12 -0
  576. package/dist/search/identity.d.ts.map +1 -0
  577. package/dist/search/identity.js +90 -0
  578. package/dist/search/identity.js.map +1 -0
  579. package/dist/search/index.d.ts +16 -0
  580. package/dist/search/index.d.ts.map +1 -0
  581. package/dist/search/index.js +15 -0
  582. package/dist/search/index.js.map +1 -0
  583. package/dist/search/memory-source.d.ts +36 -0
  584. package/dist/search/memory-source.d.ts.map +1 -0
  585. package/dist/search/memory-source.js +238 -0
  586. package/dist/search/memory-source.js.map +1 -0
  587. package/dist/search/rank.d.ts +29 -0
  588. package/dist/search/rank.d.ts.map +1 -0
  589. package/dist/search/rank.js +132 -0
  590. package/dist/search/rank.js.map +1 -0
  591. package/dist/search/row-text.d.ts +38 -0
  592. package/dist/search/row-text.d.ts.map +1 -0
  593. package/dist/search/row-text.js +88 -0
  594. package/dist/search/row-text.js.map +1 -0
  595. package/dist/search/search.d.ts +28 -0
  596. package/dist/search/search.d.ts.map +1 -0
  597. package/dist/search/search.js +265 -0
  598. package/dist/search/search.js.map +1 -0
  599. package/dist/search/source.d.ts +70 -0
  600. package/dist/search/source.d.ts.map +1 -0
  601. package/dist/search/source.js +2 -0
  602. package/dist/search/source.js.map +1 -0
  603. package/dist/search/text.d.ts +47 -0
  604. package/dist/search/text.d.ts.map +1 -0
  605. package/dist/search/text.js +150 -0
  606. package/dist/search/text.js.map +1 -0
  607. package/dist/sha256.d.ts.map +1 -1
  608. package/dist/sha256.js +3 -2
  609. package/dist/sha256.js.map +1 -1
  610. package/dist/site-capabilities.d.ts +345 -0
  611. package/dist/site-capabilities.d.ts.map +1 -0
  612. package/dist/site-capabilities.js +724 -0
  613. package/dist/site-capabilities.js.map +1 -0
  614. package/dist/site-manifest.d.ts +51 -0
  615. package/dist/site-manifest.d.ts.map +1 -0
  616. package/dist/site-manifest.js +115 -0
  617. package/dist/site-manifest.js.map +1 -0
  618. package/dist/skip-reasons.d.ts +12 -0
  619. package/dist/skip-reasons.d.ts.map +1 -0
  620. package/dist/skip-reasons.js +15 -0
  621. package/dist/skip-reasons.js.map +1 -0
  622. package/dist/source-engine/driver.d.ts +40 -0
  623. package/dist/source-engine/driver.d.ts.map +1 -0
  624. package/dist/source-engine/driver.js +513 -0
  625. package/dist/source-engine/driver.js.map +1 -0
  626. package/dist/source-engine/evidence.d.ts +39 -0
  627. package/dist/source-engine/evidence.d.ts.map +1 -0
  628. package/dist/source-engine/evidence.js +54 -0
  629. package/dist/source-engine/evidence.js.map +1 -0
  630. package/dist/source-engine/guard.d.ts +87 -0
  631. package/dist/source-engine/guard.d.ts.map +1 -0
  632. package/dist/source-engine/guard.js +427 -0
  633. package/dist/source-engine/guard.js.map +1 -0
  634. package/dist/source-engine/index.d.ts +35 -0
  635. package/dist/source-engine/index.d.ts.map +1 -0
  636. package/dist/source-engine/index.js +27 -0
  637. package/dist/source-engine/index.js.map +1 -0
  638. package/dist/source-engine/machine-state.d.ts +87 -0
  639. package/dist/source-engine/machine-state.d.ts.map +1 -0
  640. package/dist/source-engine/machine-state.js +94 -0
  641. package/dist/source-engine/machine-state.js.map +1 -0
  642. package/dist/source-engine/observe.d.ts +10 -0
  643. package/dist/source-engine/observe.d.ts.map +1 -0
  644. package/dist/source-engine/observe.js +276 -0
  645. package/dist/source-engine/observe.js.map +1 -0
  646. package/dist/source-engine/overlay.d.ts +50 -0
  647. package/dist/source-engine/overlay.d.ts.map +1 -0
  648. package/dist/source-engine/overlay.js +114 -0
  649. package/dist/source-engine/overlay.js.map +1 -0
  650. package/dist/source-engine/robots.d.ts +53 -0
  651. package/dist/source-engine/robots.d.ts.map +1 -0
  652. package/dist/source-engine/robots.js +158 -0
  653. package/dist/source-engine/robots.js.map +1 -0
  654. package/dist/source-engine/snapshot.d.ts +104 -0
  655. package/dist/source-engine/snapshot.d.ts.map +1 -0
  656. package/dist/source-engine/snapshot.js +240 -0
  657. package/dist/source-engine/snapshot.js.map +1 -0
  658. package/dist/source-engine/target-consumer.d.ts +12 -0
  659. package/dist/source-engine/target-consumer.d.ts.map +1 -0
  660. package/dist/source-engine/target-consumer.js +15 -0
  661. package/dist/source-engine/target-consumer.js.map +1 -0
  662. package/dist/source-engine/target-descriptor.d.ts +3 -0
  663. package/dist/source-engine/target-descriptor.d.ts.map +1 -0
  664. package/dist/source-engine/target-descriptor.js +26 -0
  665. package/dist/source-engine/target-descriptor.js.map +1 -0
  666. package/dist/source-engine/target.d.ts +82 -0
  667. package/dist/source-engine/target.d.ts.map +1 -0
  668. package/dist/source-engine/target.js +213 -0
  669. package/dist/source-engine/target.js.map +1 -0
  670. package/dist/source-engine/types.d.ts +296 -0
  671. package/dist/source-engine/types.d.ts.map +1 -0
  672. package/dist/source-engine/types.js +2 -0
  673. package/dist/source-engine/types.js.map +1 -0
  674. package/dist/source-harness/conformance.d.ts +16 -0
  675. package/dist/source-harness/conformance.d.ts.map +1 -0
  676. package/dist/source-harness/conformance.js +266 -0
  677. package/dist/source-harness/conformance.js.map +1 -0
  678. package/dist/source-harness/fixture.d.ts +97 -0
  679. package/dist/source-harness/fixture.d.ts.map +1 -0
  680. package/dist/source-harness/fixture.js +276 -0
  681. package/dist/source-harness/fixture.js.map +1 -0
  682. package/dist/source-harness/index.d.ts +22 -0
  683. package/dist/source-harness/index.d.ts.map +1 -0
  684. package/dist/source-harness/index.js +19 -0
  685. package/dist/source-harness/index.js.map +1 -0
  686. package/dist/source-harness/peer.d.ts +74 -0
  687. package/dist/source-harness/peer.d.ts.map +1 -0
  688. package/dist/source-harness/peer.js +106 -0
  689. package/dist/source-harness/peer.js.map +1 -0
  690. package/dist/source-profiles/index.d.ts +31 -0
  691. package/dist/source-profiles/index.d.ts.map +1 -0
  692. package/dist/source-profiles/index.js +206 -0
  693. package/dist/source-profiles/index.js.map +1 -0
  694. package/dist/source-profiles/link-header.d.ts +6 -0
  695. package/dist/source-profiles/link-header.d.ts.map +1 -0
  696. package/dist/source-profiles/link-header.js +131 -0
  697. package/dist/source-profiles/link-header.js.map +1 -0
  698. package/dist/storage-harness/contract.d.ts +109 -0
  699. package/dist/storage-harness/contract.d.ts.map +1 -0
  700. package/dist/storage-harness/contract.js +853 -0
  701. package/dist/storage-harness/contract.js.map +1 -0
  702. package/dist/storage-harness/index.d.ts +39 -0
  703. package/dist/storage-harness/index.d.ts.map +1 -0
  704. package/dist/storage-harness/index.js +55 -0
  705. package/dist/storage-harness/index.js.map +1 -0
  706. package/dist/storage.d.ts +8 -1
  707. package/dist/storage.d.ts.map +1 -1
  708. package/dist/storage.js +6 -1
  709. package/dist/storage.js.map +1 -1
  710. package/dist/string-identity-agreement.d.ts +35 -0
  711. package/dist/string-identity-agreement.d.ts.map +1 -0
  712. package/dist/string-identity-agreement.js +78 -0
  713. package/dist/string-identity-agreement.js.map +1 -0
  714. package/dist/system-documents.d.ts +82 -0
  715. package/dist/system-documents.d.ts.map +1 -0
  716. package/dist/system-documents.js +127 -0
  717. package/dist/system-documents.js.map +1 -0
  718. package/dist/types.d.ts +53 -7
  719. package/dist/types.d.ts.map +1 -1
  720. package/dist/types.js +0 -10
  721. package/dist/types.js.map +1 -1
  722. package/dist/uncertain-write.d.ts +157 -17
  723. package/dist/uncertain-write.d.ts.map +1 -1
  724. package/dist/uncertain-write.js +86 -30
  725. package/dist/uncertain-write.js.map +1 -1
  726. package/dist/validation.d.ts +5 -0
  727. package/dist/validation.d.ts.map +1 -1
  728. package/dist/verification.d.ts +7 -3
  729. package/dist/verification.d.ts.map +1 -1
  730. package/dist/verification.js +49 -13
  731. package/dist/verification.js.map +1 -1
  732. package/dist/versioning.d.ts +9 -4
  733. package/dist/versioning.d.ts.map +1 -1
  734. package/dist/versioning.js +9 -4
  735. package/dist/versioning.js.map +1 -1
  736. package/dist/view-launch-contract.d.ts +14 -0
  737. package/dist/view-launch-contract.d.ts.map +1 -0
  738. package/dist/view-launch-contract.js +23 -0
  739. package/dist/view-launch-contract.js.map +1 -0
  740. package/dist/write-identity.d.ts +5 -0
  741. package/dist/write-identity.d.ts.map +1 -0
  742. package/dist/write-identity.js +9 -0
  743. package/dist/write-identity.js.map +1 -0
  744. package/package.json +167 -6
@@ -15,6 +15,15 @@
15
15
  * entirely between two probes of one observation can be traversed by the operating system
16
16
  * during a listing or open, but its bytes can never be returned as EXACT, because the leaf
17
17
  * witness at the post-walk must match the entry the requested path reaches.
18
+ * - A bulk read runs its observations inside one {@link ObservationPass}: the same protocol per
19
+ * path, but a directory's listing is taken once and reused while the directory's change
20
+ * witness proves its entry set unchanged, and every EXACT verdict that used a reused listing has
21
+ * its post-walk repeated at the end of the pass without trusting timestamps. Listing the parent
22
+ * per observation would make a pass over a directory of N documents read O(N²) directory
23
+ * entries. The speedup assumes local disks, whose directory times advance on every entry change;
24
+ * on Linux any other filesystem type lists per use, and elsewhere a mount whose times can lie
25
+ * (network or FUSE attribute caches, settable Windows directory times) is covered by the
26
+ * end-of-pass re-verification, short of an inode number reused within the pass.
18
27
  * - Mutations hold one cross-process lock keyed by a pure fold of the root and `rel`, decide
19
28
  * inside it, create directories one segment at a time with a spelling check, and publish a
20
29
  * first-created leaf with `link` so the host's own equivalence refuses a second spelling the
@@ -44,10 +53,15 @@
44
53
  */
45
54
  import { promises as fs } from "node:fs";
46
55
  import path from "node:path";
47
- import { createHash, randomUUID } from "node:crypto";
56
+ import { createHash } from "node:crypto";
57
+ import { execFile } from "node:child_process";
58
+ import { promisify } from "node:util";
48
59
  import { ConcurrentReplacementError, FilesystemIdentityAliasError, InvalidInputError } from "./errors.js";
49
- import { acquireFilesystemIdentityLock } from "./filesystem-lock.js";
60
+ import { acquireFilesystemIdentityLock, filesystemMutationLockRoot, filesystemRelationshipCache } from "./filesystem-lock.js";
50
61
  import { captureFilesystemHostPolicy } from "./filesystem-host.js";
62
+ import { foldSegment } from "./identity-fold.js";
63
+ import { identityTempName } from "./filesystem-temp-name.js";
64
+ export { foldSegment };
51
65
  /**
52
66
  * A host can transiently deny replacement while another process is closing a read handle or a
53
67
  * scanner holds the destination. An in-place rename retry cannot remain bound to the complete
@@ -116,18 +130,6 @@ function relSegments(rel) {
116
130
  return segments;
117
131
  }
118
132
  // ── identity key ──────────────────────────────────────────────────────────────
119
- /**
120
- * NFKD, then Unicode FULL case folding applied as lower-upper-lower (locale-independent). A plain
121
- * lower-case fold misses the pairs a case-insensitive host equates through full case mapping
122
- * (ß/ss, ẞ/SS, final sigma ς/σ, iota-subscript ᾈ/ἀι and its family): two such spellings would get
123
- * different keys, both first-creation writers would realize ABSENT, and the second rename would
124
- * silently replace the first document. The round trip through upper case expands every such
125
- * pair to a common form, so the fold is a superset of every supported host's equivalence;
126
- * over-folding (dotless ı with i) only adds serialization, never removes exclusion.
127
- */
128
- export function foldSegment(segment) {
129
- return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
130
- }
131
133
  /** The physical path of the longest existing ancestor of `resolved`, plus the absent remainder. */
132
134
  async function existingAnchor(resolved) {
133
135
  const tail = [];
@@ -154,12 +156,74 @@ async function existingAnchor(resolved) {
154
156
  * and identical for every case or normalization spelling of any segment. It depends on nothing
155
157
  * else: not the environment, the clock, the process, or the host name.
156
158
  */
157
- export async function identityKey(root, rel) {
158
- const foldedRel = relSegments(rel).map(foldSegment).join("/");
159
+ async function foldedPhysicalRoot(root) {
159
160
  const { anchor, tail } = await existingAnchor(path.resolve(root));
160
161
  const anchorSegments = anchor.split(path.sep).filter((segment, index) => index === 0 || segment !== "");
161
- const foldedRoot = [...anchorSegments, ...tail].map(foldSegment).join("/");
162
- return createHash("sha256").update(`superbee-identity/v1\0${foldedRoot}\0${foldedRel}`).digest("hex");
162
+ return [...anchorSegments, ...tail].map(foldRootSegment).join("/");
163
+ }
164
+ /**
165
+ * The bundle root's own segments fold with compatibility decomposition, which is wider than
166
+ * {@link foldSegment}. Every released build derives the root key this way, and processes on
167
+ * different builds exclude each other only while they derive the same root key. A wider root
168
+ * fold can only make two differently spelled roots share one lock.
169
+ */
170
+ function foldRootSegment(segment) {
171
+ return segment.normalize("NFKD").toLowerCase().toUpperCase().toLowerCase();
172
+ }
173
+ export async function identityKey(root, rel) {
174
+ const foldedRel = relSegments(rel).map(foldSegment).join("/");
175
+ return createHash("sha256").update(`superbee-identity/v1\0${await foldedPhysicalRoot(root)}\0${foldedRel}`).digest("hex");
176
+ }
177
+ /** Same root key before/after directory creation; physical replacement is a separate witness. */
178
+ export async function filesystemRootMutationKey(root) {
179
+ return createHash("sha256").update(`superbee-root-mutation/v1\0${await foldedPhysicalRoot(root)}`).digest("hex");
180
+ }
181
+ /** Existing physical-root/ancestor witnesses supplement the stable coordination pathname. */
182
+ export async function filesystemRootWitness(port, root) {
183
+ const physical = await fs.realpath(root);
184
+ const witnesses = [];
185
+ let current = physical;
186
+ for (;;) {
187
+ const witness = await port.probe(current);
188
+ if (!witness || witness.kind !== "directory")
189
+ throw new InvalidInputError("Inventory guard root identity is unavailable.");
190
+ witnesses.push([current, witness.dev, witness.ino]);
191
+ const parent = path.dirname(current);
192
+ if (parent === current)
193
+ break;
194
+ current = parent;
195
+ }
196
+ return createHash("sha256").update(JSON.stringify(witnesses)).digest("hex");
197
+ }
198
+ const rootMutationQueues = new Map();
199
+ /** Internal per-backend root coordinator; never re-exported by a public entrypoint. */
200
+ export function createFilesystemMutationCoordinator(_port, root, hostPolicy) {
201
+ const policy = captureFilesystemHostPolicy(hostPolicy);
202
+ let lockRoot;
203
+ const namespace = () => lockRoot ??= filesystemMutationLockRoot(root, policy);
204
+ return Object.freeze({
205
+ namespace,
206
+ async run(body) {
207
+ const key = await filesystemRootMutationKey(root);
208
+ const lockRoot = namespace();
209
+ const queueKey = `${lockRoot}:${key}`;
210
+ const previous = rootMutationQueues.get(queueKey) ?? Promise.resolve();
211
+ const run = previous.then(async () => {
212
+ const release = await acquireFilesystemIdentityLock(key, root, { portableRoot: root, lockRoot, hostPolicy: policy });
213
+ try {
214
+ return await body();
215
+ }
216
+ finally {
217
+ await release();
218
+ }
219
+ });
220
+ const settled = run.then(() => { }, () => { });
221
+ rootMutationQueues.set(queueKey, settled);
222
+ void settled.then(() => { if (rootMutationQueues.get(queueKey) === settled)
223
+ rootMutationQueues.delete(queueKey); });
224
+ return run;
225
+ },
226
+ });
163
227
  }
164
228
  // ── pure decisions ────────────────────────────────────────────────────────────
165
229
  function sameWitness(a, b) {
@@ -218,6 +282,39 @@ async function probeSegment(port, candidate, rel, segment) {
218
282
  function hasExact(listing, segment) {
219
283
  return listing.some((entry) => entry.name === segment);
220
284
  }
285
+ /** The one listed spelling other than `segment` that folds to it, for the refusal message only. */
286
+ function existingSpelling(names, segment) {
287
+ const folded = foldSegment(segment);
288
+ const matches = [...names].filter((name) => name !== segment && foldSegment(name) === folded);
289
+ return matches.length === 1 ? matches[0] : undefined;
290
+ }
291
+ /** "folder" or "file" for the entry an alias spelling reaches; position decides when its kind is unknown. */
292
+ function entryNoun(kind, leaf) {
293
+ if (kind === undefined)
294
+ return leaf ? "file" : "folder";
295
+ return kind === "directory" ? "folder" : "file";
296
+ }
297
+ function aliasRefusal(rel, segments, index, names, kind) {
298
+ const segment = segments[index];
299
+ return new FilesystemIdentityAliasError(rel, segment, existingSpelling(names, segment), entryNoun(kind, index === segments.length - 1), index);
300
+ }
301
+ /** {@link aliasRefusal} from a listing with kinds: the folded match's own kind names it. */
302
+ function aliasRefusalFromListing(rel, index, listing, leaf) {
303
+ const segment = relSegments(rel)[index];
304
+ const existing = existingSpelling(listing.map((entry) => entry.name), segment);
305
+ const kind = existing === undefined ? undefined : listing.find((entry) => entry.name === existing)?.kind;
306
+ return new FilesystemIdentityAliasError(rel, segment, existing, entryNoun(kind, leaf), index);
307
+ }
308
+ function listingView(names) {
309
+ return { has: (name) => names.has(name), names: () => names };
310
+ }
311
+ /** One fresh `entries` call per use: the single-read protocol. */
312
+ function freshListings(port) {
313
+ return async (dir) => {
314
+ const listing = await port.entries(dir);
315
+ return listing === null ? null : { has: (name) => hasExact(listing, name), names: () => listing.map((entry) => entry.name) };
316
+ };
317
+ }
221
318
  /**
222
319
  * M-REALIZE: per segment, root to leaf, it must exist and the parent listing must carry its exact
223
320
  * spelling. A listing-only alias decision is sound here because the identity lock is held: no
@@ -235,7 +332,7 @@ async function walkExact(port, rootResolved, segments, rel) {
235
332
  if (listing === null)
236
333
  return { state: "absent", depth: index };
237
334
  if (!hasExact(listing, segment))
238
- throw new FilesystemIdentityAliasError(rel, segment);
335
+ throw aliasRefusal(rel, segments, index, listing.map((entry) => entry.name), probed.kind);
239
336
  if (index === segments.length - 1)
240
337
  return { state: "exact", leaf: probed };
241
338
  if (probed.kind !== "directory")
@@ -246,7 +343,12 @@ async function walkExact(port, rootResolved, segments, rel) {
246
343
  }
247
344
  // ── observation ───────────────────────────────────────────────────────────────
248
345
  const MAX_RESTARTS = 3;
249
- /** O-PROBE: walk `rel` root to leaf recording each segment's witness; `null` when any segment is absent. */
346
+ /**
347
+ * O-PROBE: walk `rel` root to leaf recording each segment's witness. `complete` is false when a
348
+ * segment is absent or a non-leaf segment is not a directory; `recorded` then holds every segment
349
+ * that exists (the non-directory included), which the caller still confirms so an alias spelling of an existing
350
+ * directory prefix is refused rather than reported as absent.
351
+ */
250
352
  async function recordWalk(port, rootResolved, segments, rel) {
251
353
  const recorded = [];
252
354
  let parent = rootResolved;
@@ -255,13 +357,13 @@ async function recordWalk(port, rootResolved, segments, rel) {
255
357
  const candidate = path.join(parent, segment);
256
358
  const probed = await probeSegment(port, candidate, rel, segment);
257
359
  if (probed === null)
258
- return null;
259
- if (index < segments.length - 1 && probed.kind !== "directory")
260
- return null;
360
+ return { recorded, complete: false };
261
361
  recorded.push(probed);
362
+ if (index < segments.length - 1 && probed.kind !== "directory")
363
+ return { recorded, complete: false };
262
364
  parent = candidate;
263
365
  }
264
- return recorded;
366
+ return { recorded, complete: true };
265
367
  }
266
368
  /**
267
369
  * One listing walk under the confirmed-witness rule. Every DIRECTORY segment is probed and
@@ -276,25 +378,27 @@ async function recordWalk(port, rootResolved, segments, rel) {
276
378
  * (`handle` given) applies that leaf table against the handle's inode, probing the leaf
277
379
  * unconditionally.
278
380
  */
279
- async function confirmedWalk(port, rootResolved, segments, rel, recorded, handle) {
381
+ async function confirmedWalk(port, rootResolved, segments, rel, recorded, handle, listings = freshListings(port), stopAt = segments.length) {
280
382
  let parent = rootResolved;
281
- for (let index = 0; index < segments.length; index++) {
383
+ for (let index = 0; index < stopAt; index++) {
282
384
  const segment = segments[index];
283
385
  const candidate = path.join(parent, segment);
284
- const listing = await port.entries(parent);
386
+ const listing = await listings(parent);
285
387
  if (listing === null)
286
388
  return "absent";
287
- const listed = hasExact(listing, segment);
389
+ const listed = listing.has(segment);
288
390
  if (handle !== null && index === segments.length - 1) {
289
- const verdict = classifyLeaf({ listed, probe: await probeSegment(port, candidate, rel, segment), handle });
391
+ const probe = await probeSegment(port, candidate, rel, segment);
392
+ const verdict = classifyLeaf({ listed, probe, handle });
290
393
  if (verdict === "aliased")
291
- throw new FilesystemIdentityAliasError(rel, segment);
394
+ throw aliasRefusal(rel, segments, index, listing.names(), probe?.kind);
292
395
  return verdict === "replaced" ? "restart" : verdict;
293
396
  }
294
397
  if (index < segments.length - 1 || !listed) {
295
- const verdict = confirmAlias(listed, await probeSegment(port, candidate, rel, segment), recorded[index]);
398
+ const probe = await probeSegment(port, candidate, rel, segment);
399
+ const verdict = confirmAlias(listed, probe, recorded[index]);
296
400
  if (verdict === "aliased")
297
- throw new FilesystemIdentityAliasError(rel, segment);
401
+ throw aliasRefusal(rel, segments, index, listing.names(), probe?.kind);
298
402
  if (verdict !== "continue")
299
403
  return verdict;
300
404
  }
@@ -302,6 +406,39 @@ async function confirmedWalk(port, rootResolved, segments, rel, recorded, handle
302
406
  }
303
407
  return "continue";
304
408
  }
409
+ /**
410
+ * An incomplete O-PROBE is ABSENT only once the segments that did exist are confirmed under their
411
+ * exact spelling. Without this, `Concepts/new.md` beside an existing `concepts/` would read as
412
+ * absent while every mutation of it refuses the alias, so a caller that treats absence as
413
+ * "may be created later" would promise a write that can never succeed.
414
+ *
415
+ * Parent listings come from a per-port witnessed cache, so batches of absent probes do not list a
416
+ * large directory once each. Only ABSENT may rest on a reused listing: a refusal or restart reached
417
+ * through one is re-decided with fresh listings. Where a directory witness can lie (network
418
+ * attribute caches, settable Windows directory times), an absent verdict can therefore miss a
419
+ * directory renamed to another case within the cache's life; writes still refuse it.
420
+ */
421
+ async function confirmPrefix(port, rootResolved, segments, rel, recorded) {
422
+ if (recorded.length === 0)
423
+ return "absent";
424
+ let kept = prefixListings.get(port);
425
+ if (kept === undefined)
426
+ prefixListings.set(port, (kept = new Map()));
427
+ const cached = witnessedListings(port, kept, Date.now, PREFIX_LISTING_CAPACITY);
428
+ let verdict;
429
+ try {
430
+ verdict = await confirmedWalk(port, rootResolved, segments, rel, recorded, null, cached.source, recorded.length);
431
+ }
432
+ catch (error) {
433
+ if (!cached.reused())
434
+ throw error;
435
+ kept.clear();
436
+ verdict = await confirmedWalk(port, rootResolved, segments, rel, recorded, null, freshListings(port), recorded.length);
437
+ }
438
+ if (verdict === "restart" && cached.reused())
439
+ kept.clear();
440
+ return verdict === "restart" ? "restart" : "absent";
441
+ }
305
442
  function countRestart(restarts, rel) {
306
443
  if (restarts >= MAX_RESTARTS)
307
444
  throw new ConcurrentReplacementError(rel, restarts + 1);
@@ -315,14 +452,23 @@ function countRestart(restarts, rel) {
315
452
  * from O-PROBE, bounded; the handle is closed before any restart opens another.
316
453
  */
317
454
  export async function observeExact(port, root, rel, read) {
455
+ return observeWith(port, path.resolve(root), rel, read, freshListings(port));
456
+ }
457
+ /** The observation protocol of {@link observeExact}, with the parent listings drawn from `listings`. */
458
+ async function observeWith(port, rootResolved, rel, read, listings, onExact) {
318
459
  const segments = relSegments(rel);
319
- const rootResolved = path.resolve(root);
320
460
  const target = path.join(rootResolved, ...segments);
321
461
  for (let restarts = 0;;) {
322
- const recorded = await recordWalk(port, rootResolved, segments, rel);
323
- if (recorded === null)
324
- return { state: "absent" };
325
- const verified = await confirmedWalk(port, rootResolved, segments, rel, recorded, null);
462
+ const walk = await recordWalk(port, rootResolved, segments, rel);
463
+ if (!walk.complete) {
464
+ const prefix = await confirmPrefix(port, rootResolved, segments, rel, walk.recorded);
465
+ if (prefix === "absent")
466
+ return { state: "absent" };
467
+ restarts = countRestart(restarts, rel);
468
+ continue;
469
+ }
470
+ const recorded = walk.recorded;
471
+ const verified = await confirmedWalk(port, rootResolved, segments, rel, recorded, null, listings);
326
472
  if (verified === "absent")
327
473
  return { state: "absent" };
328
474
  if (verified === "restart") {
@@ -350,13 +496,15 @@ export async function observeExact(port, root, rel, read) {
350
496
  value = await read(opened.handle, target);
351
497
  if (value === null)
352
498
  return { state: "absent" };
353
- verdict = await confirmedWalk(port, rootResolved, segments, rel, recorded, opened);
499
+ verdict = await confirmedWalk(port, rootResolved, segments, rel, recorded, opened, listings);
354
500
  }
355
501
  finally {
356
502
  await port.close(opened.handle);
357
503
  }
358
- if (verdict === "exact")
504
+ if (verdict === "exact") {
505
+ onExact?.(recorded, { dev: opened.dev, ino: opened.ino });
359
506
  return { state: "exact", value };
507
+ }
360
508
  if (verdict === "absent")
361
509
  return { state: "absent" };
362
510
  restarts = countRestart(restarts, rel);
@@ -370,9 +518,15 @@ export async function probeExact(port, root, rel) {
370
518
  const segments = relSegments(rel);
371
519
  const rootResolved = path.resolve(root);
372
520
  for (let restarts = 0;;) {
373
- const recorded = await recordWalk(port, rootResolved, segments, rel);
374
- if (recorded === null)
375
- return { state: "absent" };
521
+ const walk = await recordWalk(port, rootResolved, segments, rel);
522
+ if (!walk.complete) {
523
+ const prefix = await confirmPrefix(port, rootResolved, segments, rel, walk.recorded);
524
+ if (prefix === "absent")
525
+ return { state: "absent" };
526
+ restarts = countRestart(restarts, rel);
527
+ continue;
528
+ }
529
+ const recorded = walk.recorded;
376
530
  const leaf = recorded[recorded.length - 1];
377
531
  const verified = await confirmedWalk(port, rootResolved, segments, rel, recorded, null);
378
532
  const verdict = verified === "continue" ? await confirmedWalk(port, rootResolved, segments, rel, recorded, leaf) : verified;
@@ -383,6 +537,183 @@ export async function probeExact(port, root, rel) {
383
537
  restarts = countRestart(restarts, rel);
384
538
  }
385
539
  }
540
+ // ── observation pass ──────────────────────────────────────────────────────────
541
+ /**
542
+ * How long a directory's modification and status-change times must have been still before a
543
+ * listing of it may be reused. A change that lands in the same timestamp tick as the directory's
544
+ * previous change leaves both times unchanged, so a witness is only a change detector once the
545
+ * clock has moved past that tick. Three seconds covers the coarsest supported granularity (FAT's
546
+ * two-second mtime) plus margin; finer clocks (APFS, ext4, NTFS) are covered with room to spare.
547
+ * A time in the future (clock skew) is never settled.
548
+ */
549
+ const SETTLED_AFTER_NS = 3000000000n;
550
+ /**
551
+ * Whether a directory witness can detect change at all. Some volumes report times that never
552
+ * move: macOS gives an exFAT volume's root directory mtime and ctime 0 forever. A time at or
553
+ * before the epoch is never a real modification of a bundle directory, so such a witness is
554
+ * treated as absent and its listing is neither kept nor reused.
555
+ */
556
+ export function witnessCanDetectChange(witness) {
557
+ return witness.mtimeNs > 0n && witness.ctimeNs > 0n;
558
+ }
559
+ function witnessKey(witness) {
560
+ return `${witness.dev}:${witness.ino}:${witness.mtimeNs}:${witness.ctimeNs}`;
561
+ }
562
+ /**
563
+ * A listing source that keeps each directory's listing while its settled change witness is
564
+ * unchanged (see {@link openObservationPass} for why a settled witness is a change detector on
565
+ * local disks). `reused()` says whether any listing it returned came from `kept`. A port without
566
+ * directory witnesses lists afresh on every use.
567
+ */
568
+ function witnessedListings(port, kept, now, capacity = Infinity) {
569
+ let reused = false;
570
+ const portWitness = port.directoryWitness?.bind(port);
571
+ if (portWitness === undefined)
572
+ return { source: freshListings(port), reused: () => false };
573
+ const witnessOf = async (dir) => {
574
+ const witness = await portWitness(dir);
575
+ return witness !== null && witnessCanDetectChange(witness) ? witness : null;
576
+ };
577
+ const settled = (witness) => {
578
+ const nowNs = BigInt(Math.floor(now())) * 1000000n;
579
+ const latest = witness.mtimeNs > witness.ctimeNs ? witness.mtimeNs : witness.ctimeNs;
580
+ return nowNs - latest >= SETTLED_AFTER_NS;
581
+ };
582
+ const source = async (dir) => {
583
+ const keep = kept.get(dir);
584
+ if (keep !== undefined) {
585
+ const current = await witnessOf(dir);
586
+ if (current !== null && witnessKey(current) === keep.witness) {
587
+ reused = true;
588
+ return listingView(keep.names);
589
+ }
590
+ kept.delete(dir);
591
+ }
592
+ const before = await witnessOf(dir);
593
+ const listing = await port.entries(dir);
594
+ if (listing === null)
595
+ return null;
596
+ const names = new Set(listing.map((entry) => entry.name));
597
+ const after = await witnessOf(dir);
598
+ if (before !== null && after !== null && witnessKey(before) === witnessKey(after) && settled(after)) {
599
+ kept.delete(dir);
600
+ kept.set(dir, { witness: witnessKey(after), names });
601
+ while (kept.size > capacity)
602
+ kept.delete(kept.keys().next().value);
603
+ }
604
+ return listingView(names);
605
+ };
606
+ return { source, reused: () => reused };
607
+ }
608
+ /**
609
+ * Prefix-confirmation listings kept per port, so a run of absent probes under one directory (a
610
+ * batch of `exists` calls) lists each parent once rather than once per probe. Bounded; entries
611
+ * are only ever reused under an unchanged settled witness.
612
+ */
613
+ const prefixListings = new WeakMap();
614
+ const PREFIX_LISTING_CAPACITY = 64;
615
+ /**
616
+ * Open an {@link ObservationPass} over `(port, root)`.
617
+ *
618
+ * Every observation runs the exact single-read protocol of {@link observeExact} — recorded walk,
619
+ * confirmed pre-walk, open, read, confirmed post-walk with the handle still open, bounded
620
+ * restarts — and differs only in where a walk's parent listing comes from. The first time a
621
+ * directory is needed the pass takes `witness, entries, witness`; when the two witnesses agree and
622
+ * the directory's times have settled, that listing is kept. Each later use re-takes the witness
623
+ * (one `stat`, constant cost) and reuses the kept listing only if the witness is unchanged;
624
+ * otherwise it lists afresh exactly as a single read would.
625
+ *
626
+ * Two independent arguments make a reused listing safe:
627
+ *
628
+ * 1. Timestamps (the fast path is right in the moment). Where a directory's times advance on every
629
+ * entry change — local APFS, HFS+, ext4, XFS, btrfs, NTFS, FAT — an unchanged settled witness
630
+ * means the entry set is the kept listing at the moment of use, so every verdict is the one a
631
+ * single read reaches against the same state.
632
+ * 2. Re-verification (no timestamps trusted). Where the witness can lie — attribute caches on
633
+ * network and FUSE mounts, settable directory times on Windows, a clock stepped backwards — an
634
+ * observation that used a reused listing may be wrong in the moment, so its verdict is not
635
+ * trusted: a refusal or absence reached through a reused listing is re-taken at once by
636
+ * {@link observeExact}, and `finish` repeats the post-walk of every EXACT verdict that used one
637
+ * against fresh listings (one per directory) and fresh probes. Each segment must still be
638
+ * listed under its exact spelling and reach the inode recorded for it, the leaf the inode the
639
+ * bytes were read from; anything else is returned for a fresh single read. Since published
640
+ * bytes are immutable per inode, a verdict that passes is a state of this identity at `finish`.
641
+ * What this cannot see is the read file being deleted and its inode NUMBER reused by a new file
642
+ * under the same spelling within the pass, because the handle is closed by then.
643
+ *
644
+ * On Linux, a mount whose filesystem type is not a known local one (NFS, SMB, FUSE, 9p, ...) gets
645
+ * no directory witness at all, so it lists exactly as single reads do.
646
+ */
647
+ export function openObservationPass(port, root, now = Date.now) {
648
+ const rootResolved = path.resolve(root);
649
+ const kept = new Map();
650
+ const reusedVerdicts = [];
651
+ /** Listings for one observation; `reused()` says whether any came from the kept set. */
652
+ const listingsFor = () => witnessedListings(port, kept, now);
653
+ return {
654
+ async observe(rel, read) {
655
+ const listings = listingsFor();
656
+ let exact;
657
+ let observed;
658
+ try {
659
+ observed = await observeWith(port, rootResolved, rel, read, listings.source, (recorded, handle) => {
660
+ exact = { rel, segments: relSegments(rel), recorded, handle };
661
+ });
662
+ }
663
+ catch (error) {
664
+ if (!listings.reused())
665
+ throw error;
666
+ return observeExact(port, rootResolved, rel, read);
667
+ }
668
+ if (!listings.reused())
669
+ return observed;
670
+ if (observed.state === "absent")
671
+ return observeExact(port, rootResolved, rel, read);
672
+ if (exact !== undefined)
673
+ reusedVerdicts.push(exact);
674
+ return observed;
675
+ },
676
+ async finish() {
677
+ const retry = new Set();
678
+ const endListings = new Map();
679
+ const listedAtEnd = async (dir) => {
680
+ if (!endListings.has(dir)) {
681
+ const listing = await port.entries(dir);
682
+ endListings.set(dir, listing === null ? null : new Set(listing.map((entry) => entry.name)));
683
+ }
684
+ return endListings.get(dir);
685
+ };
686
+ try {
687
+ for (const verdict of reusedVerdicts) {
688
+ if (!(await holdsAtEnd(port, rootResolved, verdict, listedAtEnd)))
689
+ retry.add(verdict.rel);
690
+ }
691
+ }
692
+ finally {
693
+ kept.clear();
694
+ reusedVerdicts.length = 0;
695
+ }
696
+ return [...retry];
697
+ },
698
+ };
699
+ }
700
+ /** The post-walk of one EXACT verdict, repeated against end-of-pass listings and fresh probes. */
701
+ async function holdsAtEnd(port, rootResolved, verdict, listedAtEnd) {
702
+ let parent = rootResolved;
703
+ for (let index = 0; index < verdict.segments.length; index++) {
704
+ const segment = verdict.segments[index];
705
+ const listing = await listedAtEnd(parent);
706
+ if (listing === null || !listing.has(segment))
707
+ return false;
708
+ const candidate = path.join(parent, segment);
709
+ const probed = await port.probe(candidate);
710
+ const expected = index === verdict.segments.length - 1 ? verdict.handle : verdict.recorded[index];
711
+ if (probed === null || probed.kind === "symlink" || !sameWitness(probed, expected))
712
+ return false;
713
+ parent = candidate;
714
+ }
715
+ return true;
716
+ }
386
717
  // ── mutation ──────────────────────────────────────────────────────────────────
387
718
  /**
388
719
  * Roots (resolved) whose filesystem refused a hard link. Learned lazily on the first creation
@@ -449,7 +780,7 @@ async function readWhole(port, target) {
449
780
  await port.close(opened.handle);
450
781
  }
451
782
  }
452
- async function mkdirExact(port, parent, segment, isTail, rel) {
783
+ async function mkdirExact(port, parent, segment, isTail, rel, index = -1) {
453
784
  const outcome = await port.mkdir(path.join(parent, segment));
454
785
  if (outcome === "created")
455
786
  return;
@@ -460,8 +791,9 @@ async function mkdirExact(port, parent, segment, isTail, rel) {
460
791
  throw new FilesystemSymlinkEntryError(rel, segment);
461
792
  }
462
793
  const verdict = classifyMkdir(outcome, listing, segment, isTail);
463
- if (verdict === "aliased")
464
- throw new FilesystemIdentityAliasError(rel, segment);
794
+ if (verdict === "aliased") {
795
+ throw aliasRefusalFromListing(rel, index, listing, false);
796
+ }
465
797
  if (verdict === "shape-mismatch")
466
798
  throw new FilesystemShapeMismatchError(rel, segment);
467
799
  }
@@ -490,8 +822,9 @@ async function ensureExactDirectories(port, rootResolved, segments, existingDept
490
822
  }
491
823
  }
492
824
  let parent = path.join(rootResolved, ...segments.slice(0, existingDepth));
493
- for (const segment of segments.slice(existingDepth, -1)) {
494
- await mkdirExact(port, parent, segment, false, rel);
825
+ for (let index = existingDepth; index < segments.length - 1; index++) {
826
+ const segment = segments[index];
827
+ await mkdirExact(port, parent, segment, false, rel, index);
495
828
  parent = path.join(parent, segment);
496
829
  }
497
830
  }
@@ -521,7 +854,7 @@ async function createExactLeaf(port, tmp, target, rel, leaf, rootResolved) {
521
854
  const listing = (await port.entries(path.dirname(target))) ?? [];
522
855
  if (hasExact(listing, leaf))
523
856
  throw new ConcurrentReplacementError(rel, 1);
524
- throw new FilesystemIdentityAliasError(rel, leaf);
857
+ throw aliasRefusalFromListing(rel, relSegments(rel).length - 1, listing, true);
525
858
  }
526
859
  /**
527
860
  * Mutate `(root, rel)` inside its identity lock: claim the key, realize the exact state, and let
@@ -550,13 +883,13 @@ export async function mutateExact(port, root, rel, body) {
550
883
  async replace(bytes) {
551
884
  await ensureExactDirectories(port, rootResolved, segments, existingDepth, rel);
552
885
  const dir = path.dirname(target);
553
- // Unique per call, not per process: one process can issue two writes to the same
554
- // target within a millisecond, and the second's temp file must not clobber the first's.
555
- const tmpName = `.${leaf}.${process.pid}.${Date.now()}.${randomUUID()}.tmp`;
886
+ const tmpName = identityTempName(leaf);
556
887
  const tmp = path.join(dir, tmpName);
557
888
  await port.writeTemp(dir, tmpName, bytes);
558
889
  try {
559
890
  if (realized.state === "exact") {
891
+ // Best effort: a replacement that cannot carry the old permission bits still lands.
892
+ await port.copyMode?.(target, tmp).catch(() => { });
560
893
  // Replace: the target exists under our exact spelling, so any writer of an
561
894
  // equated spelling is refused at its own M-REALIZE; an atomic rename is safe.
562
895
  await replaceExistingLeaf(port, tmp, target, rel);
@@ -594,9 +927,105 @@ function kindOf(stats) {
594
927
  return "file";
595
928
  return "other";
596
929
  }
930
+ /**
931
+ * Linux filesystem types (`statfs` magic numbers) whose directory times are kept by the local
932
+ * kernel and advance on every entry change. Anything else on Linux — NFS, SMB/CIFS, FUSE, 9p,
933
+ * Ceph, and every type not named here — gets no directory witness, so an observation pass lists it
934
+ * exactly as single reads do. Other platforms expose no stable type through Node, so their
935
+ * witnesses are offered and the pass's end-of-pass re-verification is what covers a remote mount.
936
+ */
937
+ const LOCAL_LINUX_FILESYSTEMS = new Set([
938
+ 0xef53, // ext2/3/4
939
+ 0x58465342, // xfs
940
+ 0x9123683e, // btrfs
941
+ 0x01021994, // tmpfs
942
+ 0x858458f6, // ramfs
943
+ 0x794c7630, // overlayfs
944
+ 0x2fc12fc1, // zfs
945
+ 0xf2f52010, // f2fs
946
+ 0xca451a4e, // bcachefs
947
+ 0x4d44, // vfat
948
+ 0x2011bab0, // exfat
949
+ 0x7366746e, // ntfs3
950
+ 0x482b, // hfsplus
951
+ ]);
952
+ /** Whether a directory witness may be offered on `platform` for a filesystem of `filesystemType`. */
953
+ export function directoryWitnessTrusted(platform, filesystemType) {
954
+ if (platform !== "linux")
955
+ return true;
956
+ return filesystemType !== null && LOCAL_LINUX_FILESYSTEMS.has(filesystemType);
957
+ }
958
+ /** Whether `dir`'s filesystem may offer directory witnesses, asked once per device per port. */
959
+ function witnessTrust() {
960
+ const devices = new Map();
961
+ return (dev, dir) => {
962
+ if (process.platform !== "linux")
963
+ return Promise.resolve(true);
964
+ let trusted = devices.get(dev);
965
+ if (trusted === undefined) {
966
+ trusted = fs.statfs(dir).then((info) => directoryWitnessTrusted("linux", Number(info.type)), () => false);
967
+ devices.set(dev, trusted);
968
+ }
969
+ return trusted;
970
+ };
971
+ }
972
+ // Persistent reuse needs a reliable independent ctime, beyond directory enumeration semantics.
973
+ const CONTENT_LINUX_FILESYSTEMS = new Set([
974
+ 0xef53, // ext2/3/4
975
+ 0x58465342, // xfs
976
+ 0x9123683e, // btrfs
977
+ 0x01021994, // tmpfs
978
+ 0x858458f6, // ramfs
979
+ 0x2fc12fc1, // zfs
980
+ 0xf2f52010, // f2fs
981
+ 0xca451a4e, // bcachefs
982
+ ]);
983
+ const DARWIN_DATA_VOLUME = "/System/Volumes/Data";
984
+ const runFile = promisify(execFile);
985
+ async function darwinDataVolumeDevice() {
986
+ try {
987
+ const before = await fs.lstat(DARWIN_DATA_VOLUME, { bigint: true });
988
+ if (!before.isDirectory())
989
+ return;
990
+ const { stdout } = await runFile("/usr/sbin/diskutil", ["info", "-plist", DARWIN_DATA_VOLUME], {
991
+ timeout: 2_000,
992
+ maxBuffer: 64 * 1024,
993
+ });
994
+ // Darwin's numeric statfs type is not a stable filesystem name. Only this OS-managed
995
+ // volume is qualified; a secondary or unreadable volume uses the body scan.
996
+ if (!/<key>FilesystemType<\/key>\s*<string>apfs<\/string>/.test(stdout) ||
997
+ !/<key>MountPoint<\/key>\s*<string>\/System\/Volumes\/Data<\/string>/.test(stdout))
998
+ return;
999
+ const after = await fs.lstat(DARWIN_DATA_VOLUME, { bigint: true });
1000
+ if (after.isDirectory() && before.dev === after.dev && before.ino === after.ino)
1001
+ return after.dev;
1002
+ }
1003
+ catch {
1004
+ // A device whose filesystem cannot be identified is unsuitable for persistent reuse.
1005
+ }
1006
+ }
1007
+ function contentWitnessTrust() {
1008
+ let darwin;
1009
+ const linux = new Map();
1010
+ return async (dev, handle) => {
1011
+ if (process.platform === "darwin")
1012
+ return (await (darwin ??= darwinDataVolumeDevice())) === dev;
1013
+ if (process.platform !== "linux")
1014
+ return false;
1015
+ let trusted = linux.get(dev);
1016
+ if (trusted === undefined) {
1017
+ // The descriptor identifies the file's mount even for a separately mounted leaf.
1018
+ trusted = fs.statfs(`/proc/self/fd/${handle.fd}`).then(info => CONTENT_LINUX_FILESYSTEMS.has(Number(info.type)), () => false);
1019
+ linux.set(dev, trusted);
1020
+ }
1021
+ return trusted;
1022
+ };
1023
+ }
597
1024
  /** The one production binding: `node:fs`, the temp-file convention, and the identity lock. */
598
1025
  export function createNodeFilesystemIdentityPort(hostPolicy) {
599
1026
  const policy = captureFilesystemHostPolicy(hostPolicy);
1027
+ const witnessTrustedOn = witnessTrust();
1028
+ const contentWitnessTrustedOn = contentWitnessTrust();
600
1029
  return Object.freeze({
601
1030
  isTransientOpenError: policy.isTransientOpenError,
602
1031
  isReplacementConflict: policy.isReplacementConflict,
@@ -623,6 +1052,20 @@ export function createNodeFilesystemIdentityPort(hostPolicy) {
623
1052
  throw err;
624
1053
  }
625
1054
  },
1055
+ async directoryWitness(dir) {
1056
+ let stats;
1057
+ try {
1058
+ stats = await fs.stat(dir, { bigint: true });
1059
+ }
1060
+ catch (err) {
1061
+ if (isAbsentPathError(err))
1062
+ return null;
1063
+ throw err;
1064
+ }
1065
+ if (!(await witnessTrustedOn(stats.dev, dir)))
1066
+ return null;
1067
+ return { dev: stats.dev, ino: stats.ino, mtimeNs: stats.mtimeNs, ctimeNs: stats.ctimeNs };
1068
+ },
626
1069
  async open(target) {
627
1070
  const handle = await fs.open(target, "r");
628
1071
  try {
@@ -637,6 +1080,22 @@ export function createNodeFilesystemIdentityPort(hostPolicy) {
637
1080
  readAll(handle) {
638
1081
  return handle.readFile();
639
1082
  },
1083
+ async contentStamp(handle) {
1084
+ const file = handle;
1085
+ const stat = await file.stat({ bigint: true });
1086
+ if (!stat.isFile() || stat.ctimeNs <= 0n || !(await contentWitnessTrustedOn(stat.dev, file)))
1087
+ return undefined;
1088
+ const latest = stat.mtimeNs > stat.ctimeNs ? stat.mtimeNs : stat.ctimeNs;
1089
+ return {
1090
+ value: [stat.dev, stat.ino, stat.birthtimeNs, stat.ctimeNs, stat.mtimeNs, stat.size].join(":"),
1091
+ settled: BigInt(Date.now()) * 1000000n - latest >= SETTLED_AFTER_NS,
1092
+ };
1093
+ },
1094
+ relationshipCache(root, key) {
1095
+ if (!policy.enforcePrivateMode || process.getuid === undefined)
1096
+ return undefined;
1097
+ return filesystemRelationshipCache(root, policy, key);
1098
+ },
640
1099
  close(handle) {
641
1100
  return handle.close();
642
1101
  },
@@ -674,6 +1133,9 @@ export function createNodeFilesystemIdentityPort(hostPolicy) {
674
1133
  async rename(from, to) {
675
1134
  await fs.rename(from, to);
676
1135
  },
1136
+ async copyMode(from, to) {
1137
+ await fs.chmod(to, (await fs.lstat(from)).mode & 0o777);
1138
+ },
677
1139
  async unlink(target) {
678
1140
  await fs.unlink(target);
679
1141
  },