@openclaw/matrix 2026.11.11 → 2026.12.1-beta.2

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 (192) hide show
  1. package/dist/.setup/{approval-handler.runtime-CCGCnRgz.mjs → approval-handler.runtime-BfY586xJ.mjs} +4 -4
  2. package/dist/.setup/{channel-BEgolhUJ.mjs → channel-Cc7auxIF.mjs} +8 -8
  3. package/dist/.setup/{channel.runtime-_NMfiRJl.mjs → channel.runtime-B6ZmWLDZ.mjs} +5 -5
  4. package/dist/.setup/{channel.setup-B7r4NCcE.mjs → channel.setup-D9-chyNP.mjs} +2 -2
  5. package/dist/.setup/{cli-CyjnAIzU.mjs → cli-BrTpL9JI.mjs} +7 -7
  6. package/dist/.setup/{cli-metadata-DNeLBXHC.mjs → cli-metadata-R7WyIFzA.mjs} +1 -1
  7. package/dist/.setup/{client-BVgnwwz0.mjs → client-BmxOI9-U.mjs} +2 -2
  8. package/dist/.setup/{client-gch0wggI.mjs → client-DOb_5cJm.mjs} +2 -2
  9. package/dist/.setup/{client-bootstrap-CHs5OQ1Z.mjs → client-bootstrap-BwDbzw5i.mjs} +1 -1
  10. package/dist/.setup/{create-client-mnjEWdZV.mjs → create-client-BQpMgtl2.mjs} +2 -2
  11. package/dist/.setup/{crypto-runtime-tZ95jwNO.mjs → crypto-runtime-CStae6zK.mjs} +1 -1
  12. package/dist/.setup/{direct-management-D59C1WO-.mjs → direct-management-Bm4vd-k1.mjs} +1 -1
  13. package/dist/.setup/{directory-live-CQNKUJJx.mjs → directory-live-DRGF3zFp.mjs} +1 -1
  14. package/dist/.setup/{draft-stream-DI_6HWy4.mjs → draft-stream-DpSefQTK.mjs} +2 -2
  15. package/dist/.setup/{exec-approvals-B23spbVI.mjs → exec-approvals-CTkGLt3Z.mjs} +2 -2
  16. package/dist/.setup/{messages-VnZ4u4iq.mjs → messages-DjmI7l5t.mjs} +3 -3
  17. package/dist/.setup/{monitor-wbUkxHXK.mjs → monitor-HjyjGlys.mjs} +18 -18
  18. package/dist/.setup/{onboarding-B51d5a6R.mjs → onboarding-BPkKv4dw.mjs} +3 -3
  19. package/dist/.setup/{outbound-D8rgFTRa.mjs → outbound-CthMgcxZ.mjs} +2 -2
  20. package/dist/.setup/{profile-update-DAQFPf4L.mjs → profile-update-myTQ_w_e.mjs} +3 -3
  21. package/dist/.setup/{reaction-events-CZlbNkx_.mjs → reaction-events-C22fpTeK.mjs} +5 -5
  22. package/dist/.setup/{resolve-targets-B3NLls5a.mjs → resolve-targets-3B6QJQUf.mjs} +1 -1
  23. package/dist/.setup/{room-info-Cw-BH1CA.mjs → room-info-7ER9IkzT.mjs} +3 -3
  24. package/dist/.setup/{sdk-Bzp2OIxv.mjs → sdk-DphkoEH1.mjs} +32 -33
  25. package/dist/.setup/{send-CK8h-x83.mjs → send-CAfHI3Oi.mjs} +18 -13
  26. package/dist/.setup/{send-currentness-D1x6YP9O.mjs → send-currentness-Zv5Z-1_t.mjs} +9 -5
  27. package/dist/.setup/{setup-bootstrap-DsHa4swp.mjs → setup-bootstrap-COKlzUTV.mjs} +2 -2
  28. package/dist/.setup/{setup-core-B3MI_zz4.mjs → setup-core-B1dRvn1h.mjs} +1 -1
  29. package/dist/.setup/setup-plugin-api-BGpOj2cE.mjs +2 -0
  30. package/dist/.setup/{thread-bindings-C_SHelhg.mjs → thread-bindings-DFF_4WP3.mjs} +1 -1
  31. package/dist/.setup/{tool-actions-nhsof0wb.mjs → tool-actions-Cal-116X.mjs} +11 -11
  32. package/dist/.setup/{verification-BZqaSKCW.mjs → verification-2flsiwT7.mjs} +1 -1
  33. package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -1
  34. package/dist/api.js +4 -4
  35. package/dist/channel-plugin-api.js +1 -1
  36. package/dist/cli-metadata.js +1 -1
  37. package/dist/contract-api.js +2 -2
  38. package/dist/index.js +1 -1
  39. package/dist/plugin-entry.handlers.runtime.js +2 -2
  40. package/dist/session-binding-contract-api.js +1 -1
  41. package/dist/setup-entry.js +1 -1
  42. package/dist/setup-plugin-api.js +1 -1
  43. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +57 -0
  44. package/node_modules/@openclaw/fs-safe/README.md +6 -0
  45. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  46. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  47. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +10 -0
  48. package/node_modules/@openclaw/fs-safe/dist/bounded-read.d.ts +1 -1
  49. package/node_modules/@openclaw/fs-safe/dist/bounded-read.js +15 -4
  50. package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +11 -2
  51. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.d.ts +6 -0
  52. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.js +38 -0
  53. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.d.ts +1 -1
  54. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +2 -2
  55. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +13 -8
  56. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +13 -0
  57. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.d.ts +2 -2
  58. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +34 -24
  59. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +7 -2
  60. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +20 -20
  61. package/node_modules/@openclaw/fs-safe/dist/file-observation.d.ts +13 -2
  62. package/node_modules/@openclaw/fs-safe/dist/file-observation.js +8 -4
  63. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -0
  64. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +11 -1
  65. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.d.ts +2 -0
  66. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.js +17 -0
  67. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  68. package/node_modules/@openclaw/fs-safe/dist/file-store.js +12 -16
  69. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +1 -1
  70. package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -4
  71. package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +2 -0
  72. package/node_modules/@openclaw/fs-safe/dist/json-document-store.js +1 -0
  73. package/node_modules/@openclaw/fs-safe/dist/json-store.js +1 -0
  74. package/node_modules/@openclaw/fs-safe/dist/json.d.ts +5 -2
  75. package/node_modules/@openclaw/fs-safe/dist/json.js +6 -2
  76. package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.js +16 -10
  77. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +6 -0
  78. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +4 -0
  79. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.d.ts +20 -0
  80. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.js +18 -0
  81. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +3 -18
  82. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +48 -24
  83. package/node_modules/@openclaw/fs-safe/dist/opened-file-failure.js +19 -7
  84. package/node_modules/@openclaw/fs-safe/dist/output.d.ts +1 -0
  85. package/node_modules/@openclaw/fs-safe/dist/output.js +3 -0
  86. package/node_modules/@openclaw/fs-safe/dist/path-policy.js +4 -1
  87. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +35 -10
  88. package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +9 -2
  89. package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +42 -23
  90. package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +85 -34
  91. package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +3 -0
  92. package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +4 -0
  93. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +1 -0
  94. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +1 -1
  95. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
  96. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.d.ts +24 -0
  97. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.js +151 -0
  98. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.d.ts +1 -0
  99. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -1
  100. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +1 -1
  101. package/node_modules/@openclaw/fs-safe/dist/realpath.js +22 -11
  102. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +1 -0
  103. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +5 -0
  104. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +7 -0
  105. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +75 -2
  106. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -0
  107. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +14 -10
  108. package/node_modules/@openclaw/fs-safe/dist/root-context.js +28 -12
  109. package/node_modules/@openclaw/fs-safe/dist/root-copy.js +1 -0
  110. package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +2 -2
  111. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +4 -0
  112. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +53 -36
  113. package/node_modules/@openclaw/fs-safe/dist/root-file-open-batch-sync.js +3 -1
  114. package/node_modules/@openclaw/fs-safe/dist/root-file.d.ts +2 -1
  115. package/node_modules/@openclaw/fs-safe/dist/root-file.js +24 -13
  116. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +17 -1
  117. package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +4 -2
  118. package/node_modules/@openclaw/fs-safe/dist/root-path.d.ts +1 -1
  119. package/node_modules/@openclaw/fs-safe/dist/root-path.js +2 -1
  120. package/node_modules/@openclaw/fs-safe/dist/root-read-admission.js +31 -9
  121. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +6 -2
  122. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +1 -0
  123. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  124. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.d.ts +1 -0
  125. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +84 -4
  126. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +1 -0
  127. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +2 -0
  128. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +22 -15
  129. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.d.ts +22 -0
  130. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.js +303 -0
  131. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -0
  132. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +9 -1
  133. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.d.ts +8 -0
  134. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.js +37 -3
  135. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.d.ts +14 -0
  136. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.js +155 -0
  137. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +7 -2
  138. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.d.ts +10 -0
  139. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.js +143 -0
  140. package/node_modules/@openclaw/fs-safe/dist/temp-target.js +28 -7
  141. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.d.ts +2 -2
  142. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +34 -18
  143. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
  144. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +13 -3
  145. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +1 -1
  146. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +9 -0
  147. package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +6 -0
  148. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -1
  149. package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +1 -0
  150. package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +1 -0
  151. package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +2 -1
  152. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  153. package/node_modules/@openclaw/fs-safe/docs/advanced.md +6 -1
  154. package/node_modules/@openclaw/fs-safe/docs/atomic.md +64 -0
  155. package/node_modules/@openclaw/fs-safe/docs/contributing.md +69 -0
  156. package/node_modules/@openclaw/fs-safe/docs/file-store.md +2 -0
  157. package/node_modules/@openclaw/fs-safe/docs/json-store.md +2 -0
  158. package/node_modules/@openclaw/fs-safe/docs/json.md +2 -0
  159. package/node_modules/@openclaw/fs-safe/docs/output.md +2 -0
  160. package/node_modules/@openclaw/fs-safe/docs/permissions.md +20 -7
  161. package/node_modules/@openclaw/fs-safe/docs/reading.md +24 -9
  162. package/node_modules/@openclaw/fs-safe/docs/root.md +2 -0
  163. package/node_modules/@openclaw/fs-safe/docs/security-model.md +2 -0
  164. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +12 -7
  165. package/node_modules/@openclaw/fs-safe/docs/staged-file.md +2 -0
  166. package/node_modules/@openclaw/fs-safe/docs/temp-isolation-reference.md +73 -0
  167. package/node_modules/@openclaw/fs-safe/docs/temp.md +65 -0
  168. package/node_modules/@openclaw/fs-safe/docs/testing.md +1 -0
  169. package/node_modules/@openclaw/fs-safe/docs/writing.md +2 -0
  170. package/node_modules/@openclaw/fs-safe/package.json +25 -20
  171. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  172. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  173. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  174. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  175. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  176. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  177. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  178. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  179. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  180. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  181. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  182. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  183. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  184. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  185. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  186. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  187. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  188. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  189. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  190. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  191. package/package.json +5 -5
  192. package/dist/.setup/setup-plugin-api-D6-D6LLj.mjs +0 -2
@@ -44,7 +44,7 @@ export async function readBoundedAsync(maxBytes, readChunk, options = {}) {
44
44
  let total = 0;
45
45
  const { observeRegularFileSize, createLimitError } = options;
46
46
  const allocate = options.unpooled ? Buffer.allocUnsafeSlow : undefined;
47
- const size = options.initialSize ?? observeRegularFileSize?.();
47
+ const size = options.initialSize ?? await observeRegularFileSize?.();
48
48
  let buffer = size === undefined ? createScratchBuffer(maxBytes, allocate) : createInitialBuffer(maxBytes, size, allocate);
49
49
  if (size !== undefined) {
50
50
  const bytesRead = await readChunk(buffer, buffer.length);
@@ -52,7 +52,7 @@ export async function readBoundedAsync(maxBytes, readChunk, options = {}) {
52
52
  return finishReadBuffer(buffer, 0, allocate);
53
53
  // Short reads can occur before EOF. Only use the size shortcut on this
54
54
  // initial read; virtual files can report zero or stale sizes thereafter.
55
- const currentSize = bytesRead < buffer.length ? observeRegularFileSize?.() : undefined;
55
+ const currentSize = bytesRead < buffer.length ? await observeRegularFileSize?.() : undefined;
56
56
  total = addReadBytes(total, bytesRead, maxBytes, createLimitError);
57
57
  if (currentSize !== undefined && currentSize > 0 && bytesRead >= currentSize)
58
58
  return finishReadBuffer(buffer, total, allocate);
@@ -83,7 +83,7 @@ export function readFileHandleBoundedWithSize(handle, maxBytes, initialSize) {
83
83
  return (await handle.read(scratch, 0, length, null)).bytesRead;
84
84
  }, {
85
85
  initialSize,
86
- observeRegularFileSize: fd === undefined ? undefined : () => regularFileSize(fd),
86
+ observeRegularFileSize: fd === undefined ? undefined : () => regularFileSizeAsync(fd),
87
87
  });
88
88
  }
89
89
  function regularFileSize(fd) {
@@ -97,6 +97,17 @@ function regularFileSize(fd) {
97
97
  return undefined;
98
98
  }
99
99
  }
100
+ async function regularFileSizeAsync(fd) {
101
+ try {
102
+ const stat = await new Promise((resolve, reject) => {
103
+ fs.fstat(fd, (error, value) => error ? reject(error) : resolve(value));
104
+ });
105
+ return stat.isFile() && Number.isSafeInteger(stat.size) && stat.size >= 0 ? stat.size : undefined;
106
+ }
107
+ catch {
108
+ return undefined;
109
+ }
110
+ }
100
111
  function readDescriptorChunk(fd, scratch, length) {
101
112
  return new Promise((resolve, reject) => {
102
113
  fs.read(fd, scratch, 0, length, null, (error, bytesRead) => {
@@ -113,7 +124,7 @@ export async function readFileDescriptorBounded(fd, maxBytes) {
113
124
  normalizeMaxBytes(maxBytes);
114
125
  return await readBoundedAsync(maxBytes, async (scratch, length) => {
115
126
  return await readDescriptorChunk(fd, scratch, length);
116
- }, { observeRegularFileSize: () => regularFileSize(fd) });
127
+ }, { observeRegularFileSize: () => regularFileSizeAsync(fd) });
117
128
  }
118
129
  export function readBoundedSync(maxBytes, readChunk, options = {}) {
119
130
  normalizeMaxBytes(maxBytes);
@@ -1,8 +1,9 @@
1
1
  import fsSync from "node:fs";
2
+ import fs from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import { FsSafeError } from "./errors.js";
4
5
  import { hasSafeFileIdentity, sameFileIdentity } from "./file-identity.js";
5
- import { inspectFileIdentitySync } from "./strict-file-identity.js";
6
+ import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
6
7
  import { isNotFoundPathError } from "./path.js";
7
8
  import { directoryComponentNotDirectoryError } from "./root-errors.js";
8
9
  import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
@@ -116,7 +117,15 @@ export async function createNearestExistingDirectoryGuard(rootReal, targetPath,
116
117
  }
117
118
  // Recovery receipts must retain every identity bit, including on Windows.
118
119
  export async function inspectDirectoryIdentity(dir, expected) {
119
- return inspectDirectoryIdentitySync(dir, expected);
120
+ if (process.platform === "win32")
121
+ return inspectDirectoryIdentitySync(dir, expected);
122
+ const operationPath = directoryOperationPath(dir);
123
+ return inspectFileIdentity(async () => {
124
+ const stat = await fs.lstat(operationPath, { bigint: true });
125
+ if (stat.isSymbolicLink() || !stat.isDirectory())
126
+ throw directoryComponentNotDirectoryError();
127
+ return stat;
128
+ }, expected);
120
129
  }
121
130
  function directoryOperationPath(dir) {
122
131
  assertNoWindowsPathAlias(dir, "filesystem");
@@ -0,0 +1,6 @@
1
+ /** Retained only for an explicitly enabled operation; no new default-path I/O. */
2
+ export declare function retainDrvfsParent(directory: string, dev?: bigint, filesystemChecked?: boolean): {
3
+ fd: number;
4
+ assertCurrent: () => void;
5
+ close(): void;
6
+ } | undefined;
@@ -0,0 +1,38 @@
1
+ import fs, {} from "node:fs";
2
+ import { assertDirectoryGuard, captureDirectoryGuard } from "./directory-guard.js";
3
+ import { openStagedDirectory, assertStagedDirectoryCurrent } from "./staged-directory.js";
4
+ import { inspectFileIdentitySync } from "./strict-file-identity.js";
5
+ import { mayPrepareDrvfsRecoveryAtFd, shouldPrepareDrvfsRecovery } from "./publication-recovery.js";
6
+ /** Retained only for an explicitly enabled operation; no new default-path I/O. */
7
+ export function retainDrvfsParent(directory, dev, filesystemChecked = false) {
8
+ if (!shouldPrepareDrvfsRecovery(true, dev))
9
+ return undefined;
10
+ let parent;
11
+ try {
12
+ // Resolve through the filesystem first: lexical normalization of link/..
13
+ // can select a different directory (and therefore a different mount).
14
+ const guard = captureDirectoryGuard(directory, "native", { bigint: true });
15
+ parent = openStagedDirectory(guard.realPath);
16
+ const retained = parent;
17
+ const assertCurrent = () => {
18
+ inspectFileIdentitySync(() => fs.fstatSync(retained.fd, { bigint: true }), guard.stat);
19
+ assertDirectoryGuard(guard, "native");
20
+ assertStagedDirectoryCurrent(retained.receipt);
21
+ };
22
+ assertCurrent();
23
+ if (!filesystemChecked && !mayPrepareDrvfsRecoveryAtFd(retained.fd, retained.receipt.identity.dev)) {
24
+ parent = undefined;
25
+ fs.closeSync(retained.fd);
26
+ return undefined;
27
+ }
28
+ return { fd: retained.fd, assertCurrent, close() { fs.closeSync(retained.fd); } };
29
+ }
30
+ catch {
31
+ if (parent)
32
+ try {
33
+ fs.closeSync(parent.fd);
34
+ }
35
+ catch { /* Preserve strict fallback. */ }
36
+ return undefined;
37
+ }
38
+ }
@@ -15,7 +15,7 @@ export declare class SyncLockAcquisition {
15
15
  release(): void;
16
16
  run<T>(callback: () => T): T;
17
17
  waitForRetry(): void;
18
- retryDenial(error: unknown): boolean;
18
+ retryDenial(error: unknown, openedPath?: string): boolean;
19
19
  monitor(held: {
20
20
  timer?: NodeJS.Timeout;
21
21
  }, handle: FileLockSyncHandle, callback: ((info: SidecarLockCompromisedInfo) => void) | undefined, interval: number | undefined, receiver: object, recordTimer?: (timer: NodeJS.Timeout) => void): void;
@@ -57,8 +57,8 @@ export class SyncLockAcquisition {
57
57
  sleepSync(delay);
58
58
  this.#attempt += 1;
59
59
  }
60
- retryDenial(error) {
61
- if (!isTransientLockFileDenial(error, this.lockPath) ||
60
+ retryDenial(error, openedPath = this.lockPath) {
61
+ if (!isTransientLockFileDenial(error, openedPath) ||
62
62
  ++this.#transientDenials > maxTransientLockDenials)
63
63
  return false;
64
64
  try {
@@ -1,3 +1,4 @@
1
+ import { isIncompleteSidecarLockRecord } from "./sidecar-lock-reclaim.js";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { FsSafeError } from "./errors.js";
@@ -152,7 +153,7 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
152
153
  let unpublishedTimer;
153
154
  let lockFileCreateOpenFailure;
154
155
  try {
155
- const created = createFileLockSyncRootFile(lockRootPath, {
156
+ const created = createFileLockSyncRootFile(lockRootPath, raw, {
156
157
  assertBeforeOpen: () => {
157
158
  acquisition.assert();
158
159
  if (ownedReclaimGuard)
@@ -160,14 +161,12 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
160
161
  if (currentTargetHolder() !== undefined)
161
162
  throw new FileLockSyncRootArbitrationCollision();
162
163
  },
163
- onOpenFailure: (error) => {
164
- lockFileCreateOpenFailure = { error };
164
+ onOpenFailure: (error, pathname = lockPath) => {
165
+ lockFileCreateOpenFailure = { error, pathname };
165
166
  },
166
167
  });
167
168
  fd = created.fd;
168
169
  rootReceipt = created.receipt;
169
- fs.writeFileSync(fd, raw, "utf8");
170
- fs.fsyncSync(fd);
171
170
  const snapshot = {
172
171
  raw,
173
172
  payload,
@@ -225,9 +224,10 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
225
224
  }
226
225
  const fromLockFileOpen = lockFileCreateOpenFailure !== undefined &&
227
226
  lockFileCreateOpenFailure.error === error;
228
- if (fromLockFileOpen && acquisition.retryDenial(error))
227
+ if (fromLockFileOpen && acquisition.retryDenial(error, lockFileCreateOpenFailure.pathname))
229
228
  continue;
230
- if (!fromLockFileOpen || error.code !== "EEXIST")
229
+ if (!fromLockFileOpen || lockFileCreateOpenFailure.pathname !== lockPath ||
230
+ error.code !== "EEXIST")
231
231
  throw error;
232
232
  if (ownedReclaimGuard) {
233
233
  releaseReclaimGuard();
@@ -269,6 +269,8 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
269
269
  continue;
270
270
  }
271
271
  const snapshot = current.snapshot;
272
+ // An incomplete owner can still be writing; never reclaim it by age.
273
+ const incomplete = (!options.parsePayload && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw);
272
274
  const nowMs = Date.now();
273
275
  let reclaim;
274
276
  if (options.shouldReclaim) {
@@ -287,9 +289,12 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
287
289
  }
288
290
  }
289
291
  else {
290
- reclaim = defaultSidecarLockShouldReclaim(snapshot, options.staleMs, nowMs);
292
+ reclaim = !incomplete && defaultSidecarLockShouldReclaim(snapshot, options.staleMs, nowMs);
291
293
  }
292
294
  if (reclaim) {
295
+ // Policy may diagnose an incomplete record, but can never authorize its removal.
296
+ if (incomplete)
297
+ throw sidecarLockStale(lockPath, normalizedTargetPath);
293
298
  if (options.staleRecovery === "remove-if-unchanged" &&
294
299
  snapshot.raw !== undefined &&
295
300
  options.shouldRemoveStaleLock) {
@@ -9,6 +9,7 @@ import { assertRootIdentityCurrentSync } from "./root-context.js";
9
9
  import { hardlinkedPathNotAllowedError } from "./root-errors.js";
10
10
  import { resolveReadOpenFlags } from "./read-open-flags.js";
11
11
  import { realpathSync } from "./realpath.js";
12
+ import { sidecarPublicationPending } from "./sidecar-lock-staging.js";
12
13
  import { sidecarLockSnapshotMatches, } from "./sidecar-lock-reclaim.js";
13
14
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
14
15
  import { createSuppressedError } from "./suppressed-error.js";
@@ -90,6 +91,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
90
91
  return missingAfterCurrentRead(pathAuthority, expectedReceipt);
91
92
  throw error;
92
93
  }
94
+ if (!expectedReceipt && before.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
95
+ assertFreshPathCurrent(pathAuthority);
96
+ return null;
97
+ }
93
98
  assertRegularFile(before, pathAuthority.authority.hardlinks);
94
99
  const parent = expectedReceipt?.parent ?? observeDirectory(path.dirname(pathAuthority.path));
95
100
  let fd;
@@ -122,6 +127,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
122
127
  }
123
128
  throw error;
124
129
  }
130
+ if (!expectedReceipt && opened.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
131
+ assertFreshPathCurrent(pathAuthority);
132
+ return null;
133
+ }
125
134
  assertRegularFile(opened, pathAuthority.authority.hardlinks);
126
135
  const raw = readFileDescriptorBoundedSync(fd, MAX_SIDECAR_LOCK_PAYLOAD_BYTES).toString("utf8");
127
136
  let after;
@@ -142,6 +151,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
142
151
  }
143
152
  throw error;
144
153
  }
154
+ if (!expectedReceipt && after.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
155
+ assertFreshPathCurrent(pathAuthority);
156
+ return null;
157
+ }
145
158
  assertRegularFile(after, pathAuthority.authority.hardlinks);
146
159
  const stat = fs.fstatSync(fd, { bigint: true });
147
160
  if (expectedReceipt) {
@@ -1,9 +1,9 @@
1
1
  import { type SidecarLockSnapshot } from "./sidecar-lock-reclaim.js";
2
2
  import { type FileLockSyncRootPath } from "./file-lock-sync-root.js";
3
3
  import { type FileLockSyncRootDirectoryReceipt, type FileLockSyncRootFileReceipt } from "./file-lock-sync-root-io.js";
4
- export declare function createFileLockSyncRootFile(pathAuthority: FileLockSyncRootPath, options: {
4
+ export declare function createFileLockSyncRootFile(pathAuthority: FileLockSyncRootPath, raw: string, options: {
5
5
  assertBeforeOpen: () => void;
6
- onOpenFailure: (error: unknown) => void;
6
+ onOpenFailure: (error: unknown, pathname?: string) => void;
7
7
  }): {
8
8
  fd: number;
9
9
  receipt: FileLockSyncRootFileReceipt;
@@ -1,5 +1,6 @@
1
1
  import fs, {} from "node:fs";
2
- import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
2
+ import { createSidecarFileSync } from "./sidecar-lock-publication.js";
3
+ import { sidecarPublicationPending } from "./sidecar-lock-staging.js";
3
4
  import path from "node:path";
4
5
  import { inspectDirectoryIdentitySync } from "./directory-guard.js";
5
6
  import { FsSafeError } from "./errors.js";
@@ -77,7 +78,7 @@ function ensureParent(pathAuthority) {
77
78
  assertDirectoryCurrent(currentReceipt);
78
79
  return currentReceipt;
79
80
  }
80
- export function createFileLockSyncRootFile(pathAuthority, options) {
81
+ export function createFileLockSyncRootFile(pathAuthority, raw, options) {
81
82
  const parent = ensureParent(pathAuthority);
82
83
  if (invokeFileLockSyncRootMutationAuthority(pathAuthority.authority)) {
83
84
  assertFileLockSyncRootResolvedPathCurrent(pathAuthority);
@@ -89,25 +90,29 @@ export function createFileLockSyncRootFile(pathAuthority, options) {
89
90
  let fd;
90
91
  let receipt;
91
92
  try {
92
- options.assertBeforeOpen();
93
- try {
94
- assertExclusiveCreateLeaf(pathForWindowsFilesystem(pathAuthority.path));
95
- }
96
- catch (error) {
97
- if (error.code === "EEXIST")
98
- options.onOpenFailure(error);
99
- throw error;
100
- }
101
- try {
102
- fd = fs.openSync(pathForWindowsFilesystem(pathAuthority.path), fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
103
- }
104
- catch (error) {
105
- options.onOpenFailure(error);
106
- throw error;
107
- }
108
- const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }));
109
- assertRegularFile(opened, pathAuthority.authority.hardlinks);
93
+ const assertCurrent = () => {
94
+ assertFileLockSyncRootResolvedPathCurrent(pathAuthority);
95
+ assertRetainedParentCurrent(pathAuthority, parent);
96
+ options.assertBeforeOpen();
97
+ };
98
+ assertCurrent();
99
+ const created = createSidecarFileSync(pathForWindowsFilesystem(pathAuthority.path), raw, pathname => {
100
+ assertCurrent();
101
+ try {
102
+ return fs.openSync(pathname, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
103
+ }
104
+ catch (error) {
105
+ options.onOpenFailure(error, pathname);
106
+ throw error;
107
+ }
108
+ }, {
109
+ assertCurrent, onConflict: options.onOpenFailure, requireExactIdentity: true,
110
+ assertCleanupCandidate: candidate => assertFileLockSyncRootMutationAllowed(candidate, pathAuthority.authority.denyMutations),
111
+ });
112
+ fd = created.fd;
113
+ const opened = created.identity;
110
114
  receipt = Object.freeze({ identity: exactFileIdentity(opened), parent });
115
+ assertRegularFile(opened, pathAuthority.authority.hardlinks);
111
116
  if (!fileReceiptCurrentAfterParentCheck(pathAuthority, receipt)) {
112
117
  throw new FsSafeError("path-mismatch", "created sidecar lock changed before admission");
113
118
  }
@@ -167,10 +172,10 @@ export function removeFileLockSyncRootFile(pathAuthority, receipt, expected, ass
167
172
  return true;
168
173
  throw error;
169
174
  }
170
- assertRegularFile(successorStat, pathAuthority.authority.hardlinks);
171
175
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
172
176
  if (!sameExactIdentity(exactFileIdentity(successorStat), receipt.identity))
173
177
  return true;
178
+ assertRegularFile(successorStat, pathAuthority.authority.hardlinks);
174
179
  if (expected) {
175
180
  const successor = readFileLockSyncRootSnapshot(pathAuthority);
176
181
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
@@ -194,10 +199,10 @@ export function removeFileLockSyncRootFile(pathAuthority, receipt, expected, ass
194
199
  }
195
200
  throw error;
196
201
  }
197
- assertRegularFile(current, pathAuthority.authority.hardlinks);
198
202
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
199
203
  if (!sameExactIdentity(exactFileIdentity(current), receipt.identity))
200
204
  return true;
205
+ assertRegularFile(current, pathAuthority.authority.hardlinks);
201
206
  }
202
207
  }
203
208
  throw new FsSafeError("path-mismatch", "sidecar lock was replaced during removal");
@@ -221,12 +226,17 @@ export function fileLockSyncRootGuardExists(pathAuthority) {
221
226
  if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) {
222
227
  throw directoryComponentNotDirectoryError();
223
228
  }
229
+ const assertGuardFile = (current) => {
230
+ if (current.nlink !== 2n || !sidecarPublicationPending(pathAuthority.path)) {
231
+ assertRegularFile(current, pathAuthority.authority.hardlinks);
232
+ }
233
+ };
224
234
  if (stat.isFile())
225
- assertRegularFile(stat, pathAuthority.authority.hardlinks);
235
+ assertGuardFile(stat);
226
236
  const parent = observeDirectory(path.dirname(pathAuthority.path));
227
237
  if (stat.isFile()) {
228
238
  const current = inspectFileIdentitySync(() => fs.lstatSync(pathForWindowsFilesystem(pathAuthority.path), { bigint: true }), exactFileIdentity(stat));
229
- assertRegularFile(current, pathAuthority.authority.hardlinks);
239
+ assertGuardFile(current);
230
240
  }
231
241
  else {
232
242
  inspectDirectoryIdentitySync(pathAuthority.path, exactFileIdentity(stat));
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { parseSidecarLockSnapshot, readSidecarLockRawSnapshotSync, removeSidecarLockIfUnchangedSync, } from "./sidecar-lock-reclaim.js";
2
+ import { parseSidecarLockSnapshot, isIncompleteSidecarLockRecord, readSidecarLockRawSnapshotSync, removeSidecarLockIfUnchangedSync, } from "./sidecar-lock-reclaim.js";
3
3
  import { assertSynchronousCallbackResult } from "./mutation-authority.js";
4
4
  import { defaultSidecarLockShouldReclaim, sidecarLockStale } from "./sidecar-lock-policy.js";
5
5
  /** Handle one exclusive-create conflict without surrendering canonical admission. */
@@ -90,10 +90,12 @@ export function handleSyncStaleAdmission(acquisition, params) {
90
90
  return;
91
91
  throw error;
92
92
  }
93
+ // An incomplete owner can still be writing; age is not liveness evidence.
93
94
  if (!snapshot) {
94
95
  acquisition.waitForRetry();
95
96
  return;
96
97
  }
98
+ const incomplete = (!params.parsePayload && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw);
97
99
  const nowMs = Date.now();
98
100
  let reclaim;
99
101
  try {
@@ -108,7 +110,7 @@ export function handleSyncStaleAdmission(acquisition, params) {
108
110
  nowMs,
109
111
  heldByThisProcess: false,
110
112
  }])
111
- : defaultSidecarLockShouldReclaim(snapshot, params.staleMs, nowMs);
113
+ : !incomplete && defaultSidecarLockShouldReclaim(snapshot, params.staleMs, nowMs);
112
114
  assertSynchronousCallbackResult(reclaim, "shouldReclaim");
113
115
  }
114
116
  finally {
@@ -124,6 +126,9 @@ export function handleSyncStaleAdmission(acquisition, params) {
124
126
  acquisition.waitForRetry();
125
127
  return;
126
128
  }
129
+ // Policy may diagnose an incomplete record, but can never authorize its removal.
130
+ if (incomplete)
131
+ throw sidecarLockStale(acquisition.lockPath, acquisition.normalizedTargetPath);
127
132
  if (params.staleRecovery === "remove-if-unchanged" &&
128
133
  snapshot.raw !== undefined &&
129
134
  stale.shouldRemove !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
2
+ import { createSidecarFileSync } from "./sidecar-lock-publication.js";
3
3
  import { acquireFileLockSyncWithRoot } from "./file-lock-sync-root-acquire.js";
4
4
  import { withSyncHeldLockHandle } from "./file-lock-sync-root-held.js";
5
5
  import path from "node:path";
@@ -230,34 +230,34 @@ export function acquireFileLockSync(targetPath, options) {
230
230
  }
231
231
  }
232
232
  let lockFileCreateDenied = false;
233
+ let createOpenPath = lockPath;
233
234
  let exclusiveCreateConflict = false;
234
235
  try {
235
236
  const noFollow = process.platform !== "win32" && typeof fs.constants.O_NOFOLLOW === "number"
236
237
  ? fs.constants.O_NOFOLLOW
237
238
  : 0;
238
- try {
239
- assertExclusiveCreateLeaf(lockPath);
240
- }
241
- catch (error) {
242
- exclusiveCreateConflict = error.code === "EEXIST";
243
- throw error;
244
- }
245
- try {
246
- fd = fs.openSync(lockPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
247
- }
248
- catch (error) {
249
- lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
250
- exclusiveCreateConflict = error.code === "EEXIST";
251
- throw error;
252
- }
253
- fs.writeFileSync(fd, raw, "utf8");
254
- fs.fsyncSync(fd);
239
+ const failedOpen = (error, pathname = lockPath) => {
240
+ createOpenPath = pathname;
241
+ lockFileCreateDenied = isTransientLockFileDenial(error, pathname);
242
+ exclusiveCreateConflict = pathname === lockPath && error.code === "EEXIST";
243
+ };
244
+ const created = createSidecarFileSync(lockPath, raw, pathname => {
245
+ try {
246
+ return fs.openSync(pathname, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
247
+ }
248
+ catch (error) {
249
+ failedOpen(error, pathname);
250
+ throw error;
251
+ }
252
+ }, { onConflict: failedOpen });
253
+ fd = created.fd;
255
254
  createdSnapshot = {
256
255
  raw,
257
256
  payload,
258
- stat: fs.fstatSync(fd, { bigint: true }),
257
+ stat: created.identity,
259
258
  ownershipToken,
260
259
  };
260
+ createdSnapshot.stat = fs.fstatSync(fd, { bigint: true });
261
261
  createdHeld = {
262
262
  fd,
263
263
  lockPath,
@@ -321,7 +321,7 @@ export function acquireFileLockSync(targetPath, options) {
321
321
  acquisition.waitForRetry();
322
322
  continue;
323
323
  }
324
- if (acquisition.retryDenial(error))
324
+ if (acquisition.retryDenial(error, createOpenPath))
325
325
  continue;
326
326
  throw error;
327
327
  }
@@ -1,7 +1,18 @@
1
- type FailureKind = "identity" | "resolution" | `open:${string}` | `exclusive-create:${string}` | `unlinked:${string}` | `changed:${string}` | `stat-leaf-missing:${string}` | `stat-leaf-changed:${string}`;
1
+ type FailureKind = "hardlink" | "identity" | "resolution" | `open:${string}` | `sidecar-create-denial:${string}` | `exclusive-create:${string}` | `unlinked:${string}` | `changed:${string}` | `linked-change:${string}` | `stat-leaf-missing:${string}` | `stat-leaf-changed:${string}`;
2
+ type ObservationContext = {
3
+ failures: Map<unknown, Set<FailureKind>>;
4
+ publicationPending?: (filePath: string, identity: {
5
+ dev: bigint;
6
+ ino: bigint;
7
+ }) => Promise<boolean>;
8
+ };
2
9
  export declare function recordFileObservationFailure(error: unknown, kind: FailureKind): void;
3
10
  export declare function isFileObservationFailure(error: unknown, kind: FailureKind): boolean;
4
- export declare function fileObservation(): {
11
+ export declare function observedFilePublicationPending(filePath: string, identity: {
12
+ dev: bigint;
13
+ ino: bigint;
14
+ }): Promise<boolean>;
15
+ export declare function fileObservation(options?: Pick<ObservationContext, "publicationPending">): {
5
16
  run<T>(operation: () => T): T;
6
17
  has(error: unknown, kind: FailureKind): boolean;
7
18
  };
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  const active = new AsyncLocalStorage();
3
3
  export function recordFileObservationFailure(error, kind) {
4
- const failures = active.getStore();
4
+ const failures = active.getStore()?.failures;
5
5
  if (!failures)
6
6
  return;
7
7
  let kinds = failures.get(error);
@@ -10,13 +10,17 @@ export function recordFileObservationFailure(error, kind) {
10
10
  kinds.add(kind);
11
11
  }
12
12
  export function isFileObservationFailure(error, kind) {
13
- return active.getStore()?.get(error)?.has(kind) === true;
13
+ return active.getStore()?.failures.get(error)?.has(kind) === true;
14
+ }
15
+ export async function observedFilePublicationPending(filePath, identity) {
16
+ return await active.getStore()?.publicationPending?.(filePath, identity) ?? false;
14
17
  }
15
18
  // Each Root observation owns its receipts, including nested and concurrent reads.
16
- export function fileObservation() {
19
+ export function fileObservation(options = {}) {
17
20
  const failures = new Map();
21
+ const context = { failures, ...options };
18
22
  return {
19
- run(operation) { return active.run(failures, operation); },
23
+ run(operation) { return active.run(context, operation); },
20
24
  has(error, kind) { return failures.get(error)?.has(kind) === true; },
21
25
  };
22
26
  }
@@ -3,6 +3,7 @@ export declare function writeFileSyncAtomic(params: {
3
3
  filePath: string;
4
4
  content: string | Uint8Array;
5
5
  privateMode: boolean;
6
+ allowDrvfsRenameRecovery?: boolean;
6
7
  durable: boolean;
7
8
  dirMode: number | "preserve";
8
9
  mode: number;
@@ -15,6 +15,7 @@ import { AtomicTempOwner } from "./replace-file-temp-owner.js";
15
15
  import { errorCauseOptions } from "./root-errors.js";
16
16
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
17
17
  import { getFsSafeTestHooks } from "./test-hooks.js";
18
+ import { hasErrorCode } from "./file-cleanup.js";
18
19
  function verifyStoreFile(fd, expected, filePath) {
19
20
  const assertFile = (stat, allowUnknown = false) => {
20
21
  const unknown = allowUnknown && process.platform === "win32" && (stat.dev === 0n || stat.ino === 0n);
@@ -103,11 +104,20 @@ export function writeFileSyncAtomic(params) {
103
104
  fs.fsyncSync(temp.file.fd);
104
105
  verifyStoreFile(temp.file.fd, owner.identity, tempPath);
105
106
  assertSyncStoreDirectoryReceipt(parentGuard);
107
+ if (params.allowDrvfsRenameRecovery === true)
108
+ runSync(owner.prepareRecovery(params.content, parentGuard.dir));
106
109
  fs.renameSync(tempPath, filePath);
107
110
  owner.markRenamed();
108
111
  assertSyncStoreDirectoryReceipt(parentGuard);
109
112
  try {
110
- verifyStoreFile(temp.file.fd, owner.identity, filePath);
113
+ try {
114
+ verifyStoreFile(temp.file.fd, owner.identity, filePath);
115
+ }
116
+ catch (error) {
117
+ if (!owner.canRecoverHiddenRename || !hasErrorCode(error, "ENOENT"))
118
+ throw error;
119
+ runSync(owner.assertPublished(filePath));
120
+ }
111
121
  }
112
122
  catch (error) {
113
123
  if (error instanceof FsSafeError) {
@@ -0,0 +1,2 @@
1
+ import type { FileStoreWriteOptions } from "./file-store.js";
2
+ export declare function snapshotWriteOptions(options?: FileStoreWriteOptions, durabilityFirst?: boolean): FileStoreWriteOptions | undefined;
@@ -0,0 +1,17 @@
1
+ export function snapshotWriteOptions(options, durabilityFirst = true) {
2
+ if (options == null)
3
+ return undefined;
4
+ return durabilityFirst ? {
5
+ maxBytes: options.maxBytes,
6
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
7
+ durable: options.durable,
8
+ dirMode: options.dirMode,
9
+ mode: options.mode,
10
+ } : {
11
+ maxBytes: options.maxBytes,
12
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
13
+ dirMode: options.dirMode,
14
+ mode: options.mode,
15
+ durable: options.durable,
16
+ };
17
+ }
@@ -7,13 +7,14 @@ import { type OpenResult, type ReadResult, type Root, type RootReadOptions } fro
7
7
  export type FileStoreOptions = {
8
8
  rootDir: string;
9
9
  private?: boolean;
10
+ allowDrvfsRenameRecovery?: boolean;
10
11
  /** Default for writes, streams, and copies; true syncs file and parent where supported. */
11
12
  durable?: boolean;
12
13
  dirMode?: DirectoryMode;
13
14
  mode?: number;
14
15
  maxBytes?: number;
15
16
  };
16
- export type FileStoreWriteOptions = Partial<Pick<FileStoreOptions, "dirMode" | "mode" | "maxBytes"> & {
17
+ export type FileStoreWriteOptions = Partial<Pick<FileStoreOptions, "dirMode" | "mode" | "maxBytes" | "allowDrvfsRenameRecovery"> & {
17
18
  /** Override store durability; defaults to the store option, then true. */
18
19
  durable: boolean;
19
20
  tempPrefix: string;