@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
@@ -0,0 +1,151 @@
1
+ import fs from "node:fs";
2
+ import { nativeOpenFlags } from "./native-operations.js";
3
+ import { readFileDescriptorBoundedSync } from "./bounded-read.js";
4
+ import { FsSafeError } from "./errors.js";
5
+ import { hasErrorCode } from "./file-cleanup.js";
6
+ import { getFsSafeTestHooks } from "./test-hooks.js";
7
+ import { sleep, sleepSync } from "./timing.js";
8
+ import { getNativeBinding } from "./native.js";
9
+ const non9pDevices = new Set();
10
+ /** Other platforms keep their existing path even when the option is enabled. */
11
+ export function shouldPrepareDrvfsRecovery(enabled, dev) {
12
+ if (enabled !== true)
13
+ return false;
14
+ // Synthetic mount evidence must not inherit observations from the real host.
15
+ if (getFsSafeTestHooks()?.drvfsMountObservation)
16
+ return true;
17
+ if (process.platform !== "linux")
18
+ return false;
19
+ if (dev === undefined)
20
+ return true;
21
+ // Linux 9p allocates anonymous devices (major zero), never block devices.
22
+ if (((dev >> 8n) & 0xfffn) !== 0n || ((dev >> 32n) & 0xfffff000n) !== 0n)
23
+ return false;
24
+ return !non9pDevices.has(dev);
25
+ }
26
+ /** Negative evidence only: a stale/reused device number can only disable recovery. */
27
+ export function mayPrepareDrvfsRecoveryAtFd(parentFd, dev) {
28
+ if (!shouldPrepareDrvfsRecovery(true, dev))
29
+ return false;
30
+ if (getFsSafeTestHooks()?.drvfsMountObservation)
31
+ return true;
32
+ try {
33
+ if (getNativeBinding()?.is9pFilesystem?.(parentFd) === false) {
34
+ non9pDevices.add(dev);
35
+ return false;
36
+ }
37
+ }
38
+ catch { /* Unavailable evidence preserves full recovery-time verification. */ }
39
+ return true;
40
+ }
41
+ /** No sampling or positive cache: the retained directory's exact mount owns admission. */
42
+ export function admitsDrvfsRenameRecoveryAtFd(parentFd) {
43
+ try {
44
+ const hook = getFsSafeTestHooks()?.drvfsMountObservation;
45
+ if (!hook && process.platform !== "linux")
46
+ return false;
47
+ if (!Number.isInteger(parentFd) || parentFd < 0)
48
+ return false;
49
+ const observation = hook ? hook(parentFd) : (() => {
50
+ if (fs.statfsSync("/proc/self/fd", { bigint: true }).type !== 0x9fa0n)
51
+ return undefined;
52
+ // statfs follows this kernel-owned descriptor alias to the retained parent.
53
+ return {
54
+ magic: fs.statfsSync(`/proc/self/fd/${parentFd}`, { bigint: true }).type,
55
+ fdinfo: fs.readFileSync(`/proc/self/fdinfo/${parentFd}`, "utf8"),
56
+ mountinfo: fs.readFileSync("/proc/self/mountinfo", "utf8"),
57
+ };
58
+ })();
59
+ if (!observation || observation.magic !== 0x01021997n)
60
+ return false;
61
+ const ids = [...observation.fdinfo.matchAll(/^mnt_id:\s*(\d+)\s*$/gm)];
62
+ if (ids.length !== 1)
63
+ return false;
64
+ const entries = observation.mountinfo.split("\n").filter(line => line.split(" ")[0] === ids[0][1]);
65
+ if (entries.length !== 1)
66
+ return false;
67
+ const [before, after, extra] = entries[0].split(" - ");
68
+ if (!before || !after || extra !== undefined || before.split(" ").length < 6)
69
+ return false;
70
+ const fields = after.split(" ");
71
+ return fields.length === 3 && fields[0] === "9p" &&
72
+ fields[2].split(",").some(option => option === "aname=drvfs" || option.startsWith("aname=drvfs;"));
73
+ }
74
+ catch {
75
+ return false;
76
+ }
77
+ }
78
+ /** Exact metadata is necessary but cannot exclude inode reuse after the final close. */
79
+ export function assertRecoveredPublication(actual, expected) {
80
+ if (!actual.isFile() || actual.isSymbolicLink() || actual.nlink !== 1n ||
81
+ actual.dev !== expected.dev || actual.ino !== expected.ino || actual.size !== expected.size ||
82
+ actual.mode !== expected.mode || actual.uid !== expected.uid || actual.gid !== expected.gid) {
83
+ throw new FsSafeError("path-mismatch", "published file changed during DrvFS recovery");
84
+ }
85
+ }
86
+ export async function recoverAfterHiddenRename(params) {
87
+ if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
88
+ throw new FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
89
+ }
90
+ await params.closeWriter();
91
+ for (let attempt = 0;; attempt++) {
92
+ let recovered;
93
+ try {
94
+ recovered = await params.reopen();
95
+ }
96
+ catch (error) {
97
+ if (!hasErrorCode(error, "ENOENT") || attempt === 4)
98
+ throw error;
99
+ await sleep(20);
100
+ continue;
101
+ }
102
+ try {
103
+ await params.retain?.(recovered);
104
+ }
105
+ catch (error) {
106
+ await params.dispose?.(recovered).catch(() => undefined);
107
+ throw error;
108
+ }
109
+ return recovered;
110
+ }
111
+ }
112
+ export function recoverAfterHiddenRenameSync(params) {
113
+ if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
114
+ throw new FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
115
+ }
116
+ params.closeWriter();
117
+ for (let attempt = 0;; attempt++) {
118
+ try {
119
+ return params.reopen();
120
+ }
121
+ catch (error) {
122
+ if (!hasErrorCode(error, "ENOENT") || attempt === 4)
123
+ throw error;
124
+ sleepSync(20);
125
+ }
126
+ }
127
+ }
128
+ export function assertRecoveredFile(fd, expected, content) {
129
+ assertRecoveredPublication(fs.fstatSync(fd, { bigint: true }), expected);
130
+ if (content && !readFileDescriptorBoundedSync(fd, content.byteLength).equals(content)) {
131
+ throw new FsSafeError("path-mismatch", "published content changed during DrvFS recovery");
132
+ }
133
+ assertRecoveredPublication(fs.fstatSync(fd, { bigint: true }), expected);
134
+ }
135
+ export function reopenRecoveredNativeFile(binding, parentFd, basename, expected, content) {
136
+ if (!binding.openBeneath || !binding.closeOwnedFd || !binding.stagedFileMatches) {
137
+ throw new FsSafeError("helper-unavailable", "native DrvFS recovery requires descriptor-relative verification");
138
+ }
139
+ const fd = binding.openBeneath(parentFd, basename, nativeOpenFlags(fs.constants.O_RDONLY | fs.constants.O_NONBLOCK)).fd;
140
+ try {
141
+ assertRecoveredFile(fd, expected, content);
142
+ if (!binding.stagedFileMatches(parentFd, basename, fd)) {
143
+ throw new FsSafeError("path-mismatch", "published name changed during DrvFS recovery");
144
+ }
145
+ return fd;
146
+ }
147
+ catch (error) {
148
+ binding.closeOwnedFd(fd);
149
+ throw error;
150
+ }
151
+ }
@@ -11,4 +11,5 @@ export declare function publishCopyStage(params: {
11
11
  onPublicationAttempt?: () => void;
12
12
  onPublished?: (identity: PublishedWriteIdentity) => void;
13
13
  beforeTemporaryUnlink?: () => Promise<void>;
14
+ afterRename?: () => BigIntStats | Promise<BigIntStats>;
14
15
  }): Promise<void>;
@@ -55,7 +55,8 @@ export async function publishCopyStage(params) {
55
55
  if (fs.lstatSync(temporaryPath, { throwIfNoEntry: false })) {
56
56
  throw new FsSafeError("path-mismatch", "renamed copy stage still exists");
57
57
  }
58
- const target = fs.lstatSync(targetPath, { bigint: true });
58
+ const observed = params.afterRename?.();
59
+ const target = observed instanceof Promise ? await observed : observed ?? fs.lstatSync(targetPath, { bigint: true });
59
60
  if (!target.isFile() || target.isSymbolicLink() || target.nlink !== 1n ||
60
61
  !sameFileIdentityForCleanup(target, identity)) {
61
62
  throw new FsSafeError("path-mismatch", "renamed copy target changed after publication");
@@ -1,5 +1,5 @@
1
1
  export declare const realpathSync: ((input: string) => string) & {
2
2
  native: (input: string) => string;
3
3
  };
4
- /** Async on Node; retain runtime-specific native canonicalization guarantees. */
4
+ /** POSIX async canonicalization retains Bun's native path and record-lock semantics. */
5
5
  export declare function realpathNative(input: string): Promise<string>;
@@ -8,6 +8,15 @@ import { getFsSafeNativeConfig } from "./native-config.js";
8
8
  import { isWindowsAppContainer } from "./windows-appcontainer.js";
9
9
  const runtimePlatform = process.versions.bun ? platform() : undefined;
10
10
  const bunPosix = runtimePlatform === "darwin" || runtimePlatform === "linux" ? runtimePlatform : undefined;
11
+ function nativeResult(input, result) {
12
+ if (result.path !== undefined)
13
+ return result.path;
14
+ const errno = -(result.errno);
15
+ const code = getSystemErrorName(errno);
16
+ throw Object.assign(new Error(`${code}: realpath '${input}'`), {
17
+ code, errno, syscall: "realpath", path: input,
18
+ });
19
+ }
11
20
  function resolve(input, native) {
12
21
  if (native && process.platform === "win32") {
13
22
  try {
@@ -54,14 +63,7 @@ function resolve(input, native) {
54
63
  const binding = getNativeBinding();
55
64
  if (binding?.canonicalizePath) {
56
65
  // Ordinary resolution normalizes both the input and each expanded symlink.
57
- const result = binding.canonicalizePath(input, !native);
58
- if (result.path !== undefined)
59
- return result.path;
60
- const errno = -(result.errno);
61
- const code = getSystemErrorName(errno);
62
- throw Object.assign(new Error(`${code}: realpath '${input}'`), {
63
- code, errno, syscall: "realpath", path: input,
64
- });
66
+ return nativeResult(input, binding.canonicalizePath(input, !native));
65
67
  }
66
68
  if (getFsSafeNativeConfig().mode === "require") {
67
69
  throw new FsSafeError("helper-unavailable", "native fs-safe canonicalization is unavailable");
@@ -74,10 +76,19 @@ function resolve(input, native) {
74
76
  export const realpathSync = Object.assign((input) => resolve(input, false), {
75
77
  native: (input) => resolve(input, true),
76
78
  });
77
- /** Async on Node; retain runtime-specific native canonicalization guarantees. */
79
+ /** POSIX async canonicalization retains Bun's native path and record-lock semantics. */
78
80
  export async function realpathNative(input) {
79
- if (bunPosix)
80
- return realpathSync.native(input);
81
+ if (bunPosix) {
82
+ if (input.includes("\0")) {
83
+ throw Object.assign(new TypeError("realpath input must not contain null bytes"), { code: "ERR_INVALID_ARG_VALUE" });
84
+ }
85
+ const binding = getNativeBinding();
86
+ if (binding?.canonicalizePathAsync)
87
+ return nativeResult(input, await binding.canonicalizePathAsync(input, false));
88
+ if (binding?.canonicalizePath || getFsSafeNativeConfig().mode === "require") {
89
+ throw new FsSafeError("helper-unavailable", "native fs-safe canonicalization is unavailable");
90
+ }
91
+ }
81
92
  try {
82
93
  return await asyncFs.realpath(input);
83
94
  }
@@ -6,6 +6,7 @@ export declare function applyDirectoryMode(io: AtomicIo, params: {
6
6
  dirPath: string;
7
7
  mode: number | "preserve";
8
8
  expectedIdentity?: BigIntStats;
9
+ allowDrvfsRenameRecovery?: boolean;
9
10
  ignoreChmodError?: boolean;
10
11
  mutation?: AtomicMutation;
11
12
  }): Procedure<void>;
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
3
3
  import { FsSafeError } from "./errors.js";
4
4
  import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
5
5
  import { ownDirectoryMode } from "./directory-mode-node.js";
6
+ import { mayPrepareDrvfsRecoveryAtFd } from "./publication-recovery.js";
6
7
  import { inspectAtomicIdentity, wait } from "./atomic-io.js";
7
8
  function parentCloseFailure(primary, closeError) {
8
9
  return primary ? new AggregateError([primary.error, closeError], "Atomic parent preparation and close failed") : closeError;
@@ -66,6 +67,8 @@ async function pinDirectoryForMode(params) {
66
67
  ignoreChmodError: params.ignoreChmodError,
67
68
  });
68
69
  await owner.verify();
70
+ if (params.allowDrvfsRenameRecovery)
71
+ mayPrepareDrvfsRecoveryAtFd(handle.fd, expected.dev);
69
72
  return owner;
70
73
  }
71
74
  catch (error) {
@@ -112,6 +115,8 @@ export function* applyDirectoryMode(io, params) {
112
115
  let primary;
113
116
  try {
114
117
  inspectAtomicIdentity(io, () => file.statExact(), expected, false, admit);
118
+ if (params.allowDrvfsRenameRecovery)
119
+ mayPrepareDrvfsRecoveryAtFd(file.fd, expected.dev);
115
120
  if (params.mode !== "preserve") {
116
121
  params.mutation?.assert();
117
122
  file.chmod(params.mode & 0o7777);
@@ -10,11 +10,18 @@ export declare class AtomicTempOwner {
10
10
  private resource;
11
11
  private recordedIdentity;
12
12
  private exists;
13
+ private recoveryParent?;
14
+ private recoveryIdentity?;
15
+ private recoveryContent?;
16
+ private recovered;
13
17
  private readonly unregister;
14
18
  constructor(pathname: string, io: AtomicIo);
15
19
  start(): void;
16
20
  readonly onIdentity: (identity: BigIntStats) => void;
17
21
  get identity(): BigIntStats;
22
+ get canRecoverHiddenRename(): boolean;
23
+ get fd(): number;
24
+ prepareRecovery(content: string | Uint8Array, directory?: string, filesystemChecked?: boolean): Procedure<void>;
18
25
  markRenamed(): void;
19
26
  private takeResource;
20
27
  adopt(temp: {
@@ -9,6 +9,8 @@ import { sameFileIdentityForCleanup, sha256Hex } from "./file-identity.js";
9
9
  import { withAsyncDirectoryGuards } from "./guarded-mutation.js";
10
10
  import { inspectAtomicIdentity, wait } from "./atomic-io.js";
11
11
  import { registerTempPathForExit } from "./temp-cleanup.js";
12
+ import { admitsDrvfsRenameRecoveryAtFd, assertRecoveredPublication, shouldPrepareDrvfsRecovery } from "./publication-recovery.js";
13
+ import { retainDrvfsParent } from "./drvfs-parent.js";
12
14
  const PUBLISHED_READ_FLAGS = resolveReadOpenFlags();
13
15
  function describeFailure(error) {
14
16
  try {
@@ -72,6 +74,10 @@ export class AtomicTempOwner {
72
74
  resource;
73
75
  recordedIdentity;
74
76
  exists = false;
77
+ recoveryParent;
78
+ recoveryIdentity;
79
+ recoveryContent;
80
+ recovered = false;
75
81
  unregister;
76
82
  constructor(pathname, io) {
77
83
  this.pathname = pathname;
@@ -90,6 +96,24 @@ export class AtomicTempOwner {
90
96
  throw new Error("Atomic temp owner has no identity");
91
97
  return this.recordedIdentity;
92
98
  }
99
+ get canRecoverHiddenRename() {
100
+ return this.recoveryParent !== undefined;
101
+ }
102
+ get fd() {
103
+ if (!this.resource)
104
+ throw new Error("Atomic temp owner has no descriptor");
105
+ return this.resource.fd;
106
+ }
107
+ *prepareRecovery(content, directory = path.dirname(this.pathname), filesystemChecked = false) {
108
+ if (!shouldPrepareDrvfsRecovery(true))
109
+ return;
110
+ this.recoveryParent = retainDrvfsParent(directory, this.identity.dev, filesystemChecked);
111
+ if (!this.recoveryParent)
112
+ return;
113
+ const observed = this.resource.statExact();
114
+ this.recoveryIdentity = (this.io.asynchronous ? yield observed : observed);
115
+ this.recoveryContent = Buffer.from(content);
116
+ }
93
117
  markRenamed() {
94
118
  this.exists = false;
95
119
  this.unregister();
@@ -110,10 +134,13 @@ export class AtomicTempOwner {
110
134
  *assertCurrent(pathname = this.pathname) {
111
135
  const openedInspection = this.inspectOwned(() => this.resource.statExact(), pathname, false, this.identity);
112
136
  const opened = (this.io.asynchronous ? (yield openedInspection) : openedInspection);
137
+ if (this.recovered)
138
+ assertRecoveredPublication(opened, this.recoveryIdentity);
113
139
  try {
114
140
  const currentInspection = this.inspectOwned(() => this.io.lstatExact(pathname), pathname, true, opened);
115
- if (this.io.asynchronous)
116
- yield currentInspection;
141
+ const current = (this.io.asynchronous ? yield currentInspection : currentInspection);
142
+ if (this.recovered)
143
+ assertRecoveredPublication(current, this.recoveryIdentity);
117
144
  }
118
145
  catch (error) {
119
146
  if (hasErrorCode(error, "ENOENT")) {
@@ -129,6 +156,45 @@ export class AtomicTempOwner {
129
156
  identityCurrent = true;
130
157
  }
131
158
  catch (error) {
159
+ if (this.recoveryParent && (hasErrorCode(error, "ENOENT") ||
160
+ (error instanceof FsSafeError && hasErrorCode(error.cause, "ENOENT")))) {
161
+ this.recoveryParent.assertCurrent();
162
+ if (!admitsDrvfsRenameRecoveryAtFd(this.recoveryParent.fd))
163
+ throw error;
164
+ const previous = this.takeResource();
165
+ const closing = previous.close();
166
+ if (this.io.asynchronous)
167
+ yield closing;
168
+ for (let attempt = 0;; attempt++) {
169
+ try {
170
+ this.recoveryParent.assertCurrent();
171
+ this.resource = yield* this.io.open(pathname, PUBLISHED_READ_FLAGS);
172
+ yield* this.assertCurrent(pathname);
173
+ const observed = this.resource.statExact();
174
+ const stat = (this.io.asynchronous ? yield observed : observed);
175
+ assertRecoveredPublication(stat, this.recoveryIdentity);
176
+ if (!Buffer.from(yield* this.resource.readFileBounded(this.recoveryContent.byteLength)).equals(this.recoveryContent)) {
177
+ throw new FsSafeError("path-mismatch", "published content changed during DrvFS recovery");
178
+ }
179
+ yield* this.assertCurrent(pathname);
180
+ this.recoveryParent.assertCurrent();
181
+ this.recovered = true;
182
+ onVerified?.(this.identity);
183
+ return;
184
+ }
185
+ catch (recoveryError) {
186
+ const failed = this.takeResource();
187
+ if (failed) {
188
+ const settled = failed.close();
189
+ if (this.io.asynchronous)
190
+ yield settled;
191
+ }
192
+ if (!hasErrorCode(recoveryError, "ENOENT") || attempt === 4)
193
+ throw recoveryError;
194
+ yield* this.io.delay(20);
195
+ }
196
+ }
197
+ }
132
198
  if (!(error instanceof FsSafeError) || !hasErrorCode(error, "path-mismatch") || !expectedHash) {
133
199
  throw error;
134
200
  }
@@ -223,6 +289,13 @@ export class AtomicTempOwner {
223
289
  catch (closeError) {
224
290
  deferredFailure = closeFailure(closeError, params, deferredFailure);
225
291
  }
292
+ try {
293
+ this.recoveryParent?.close();
294
+ }
295
+ catch (error) {
296
+ deferredFailure ??= { error };
297
+ }
298
+ this.recoveryParent = undefined;
226
299
  if (deferredFailure)
227
300
  throw deferredFailure.error;
228
301
  }
@@ -26,6 +26,8 @@ export type ReplaceFileAtomicBaseOptions = AtomicMutationOptions & {
26
26
  destinationHardlinks?: ReplaceFileDestinationHardlinkPolicy;
27
27
  /** Strict by default; locked content verification is an explicit FUSE compatibility policy. */
28
28
  renameIdentity?: RenameIdentityPolicy;
29
+ /** Opt in to close-all recovery only on a verified DrvFS mount; identity reuse remains possible. */
30
+ allowDrvfsRenameRecovery?: boolean;
29
31
  syncTempFile?: boolean;
30
32
  syncParentDir?: boolean;
31
33
  throwOnCleanupError?: boolean;
@@ -102,10 +102,11 @@ export async function replaceFileAtomicWithDirectorySync(options, syncParent) {
102
102
  const filePath = validateReplaceFilePath(options.filePath);
103
103
  validateRestoreOptions(options);
104
104
  const renameIdentity = options.renameIdentity;
105
+ const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery === true;
105
106
  validateRenameIdentity(renameIdentity);
106
107
  return await serializePathWrite(path.resolve(filePath), async () => {
107
108
  if (renameIdentity !== "verify-content-with-lock") {
108
- return await replaceAsync(options, filePath, renameIdentity, mutation, syncParent);
109
+ return await replaceAsync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery, syncParent);
109
110
  }
110
111
  const fsModule = options.fileSystem?.promises ?? fs;
111
112
  const dir = path.dirname(filePath);
@@ -119,20 +120,21 @@ export async function replaceFileAtomicWithDirectorySync(options, syncParent) {
119
120
  recursive: true, mode: dirMode,
120
121
  });
121
122
  mutation.assert();
122
- return await withAtomicRenameIdentityLock(filePath, () => replaceAsync(options, filePath, renameIdentity, mutation, syncParent));
123
+ return await withAtomicRenameIdentityLock(filePath, () => replaceAsync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery, syncParent));
123
124
  });
124
125
  }
125
- function replaceAsync(options, filePath, renameIdentity, mutation, syncParent) {
126
- return runAsync(replace(AtomicIo.async(options.fileSystem?.promises ?? fs), options, filePath, renameIdentity, mutation, syncParent));
126
+ function replaceAsync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery, syncParent) {
127
+ return runAsync(replace(AtomicIo.async(options.fileSystem?.promises ?? fs), options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery, syncParent));
127
128
  }
128
129
  export function replaceFileAtomicSync(options) {
129
130
  const mutation = new AtomicMutation(options);
130
131
  const filePath = validateReplaceFilePath(options.filePath);
131
132
  validateRestoreOptions(options);
132
133
  const renameIdentity = options.renameIdentity;
134
+ const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery === true;
133
135
  validateRenameIdentity(renameIdentity);
134
136
  if (renameIdentity !== "verify-content-with-lock") {
135
- return replaceSync(options, filePath, renameIdentity, mutation);
137
+ return replaceSync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery);
136
138
  }
137
139
  const fsModule = options.fileSystem ?? syncFs;
138
140
  const dir = path.dirname(filePath);
@@ -146,12 +148,12 @@ export function replaceFileAtomicSync(options) {
146
148
  recursive: true, mode: dirMode,
147
149
  });
148
150
  mutation.assert();
149
- return withAtomicRenameIdentityLockSync(filePath, () => replaceSync(options, filePath, renameIdentity, mutation));
151
+ return withAtomicRenameIdentityLockSync(filePath, () => replaceSync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery));
150
152
  }
151
- function replaceSync(options, filePath, renameIdentity, mutation) {
152
- return runSync(replace(AtomicIo.sync(options.fileSystem ?? syncFs), options, filePath, renameIdentity, mutation));
153
+ function replaceSync(options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery) {
154
+ return runSync(replace(AtomicIo.sync(options.fileSystem ?? syncFs), options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery));
153
155
  }
154
- function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
156
+ function* replace(io, options, filePath, renameIdentity, mutation, allowDrvfsRenameRecovery, syncParent) {
155
157
  const dir = path.dirname(filePath);
156
158
  const dirMode = options.dirMode ?? 0o700;
157
159
  const mode = yield* resolveMode(io, options, filePath);
@@ -168,7 +170,7 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
168
170
  const tempOwner = new AtomicTempOwner(tempPath, io);
169
171
  let originalFailure;
170
172
  try {
171
- yield* prepareDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation });
173
+ yield* prepareDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation, allowDrvfsRenameRecovery });
172
174
  tempOwner.start();
173
175
  tempOwner.adopt(yield* writeTempFile(io, {
174
176
  tempPath,
@@ -191,6 +193,8 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
191
193
  yield* assertDestinationHardlinkPolicy(io, filePath, options.destinationHardlinks);
192
194
  yield* tempOwner.assertCurrent();
193
195
  }
196
+ if (allowDrvfsRenameRecovery)
197
+ yield* tempOwner.prepareRecovery(options.content, dir, true);
194
198
  const result = yield* renameWithRetry(io, tempOwner, filePath, options, mutation);
195
199
  if (result.method === "rename") {
196
200
  tempOwner.markRenamed();
@@ -1,14 +1,16 @@
1
1
  import fs, {} from "node:fs";
2
+ import asyncFs from "node:fs/promises";
2
3
  import os from "node:os";
3
4
  import path from "node:path";
4
- import { extendDirectoryObservationGuard, inspectDirectoryIdentitySync, inspectDirectoryObservationSync, } from "./directory-guard.js";
5
+ import { extendDirectoryObservationGuard, inspectDirectoryIdentitySync, inspectDirectoryIdentity, inspectDirectoryObservationSync, } from "./directory-guard.js";
5
6
  import { FsSafeError } from "./errors.js";
6
7
  import { assertNoNulPathInput, assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isPathInside, } from "./path.js";
7
8
  import { ROOT_PATH_ALIAS_POLICIES, resolveRootPath } from "./root-path.js";
8
9
  import { admitPathInsideRoot } from "./root-boundary.js";
9
10
  import { errorCauseOptions, outsideWorkspaceError, pathTraversalPermissionError, rootPathChangedError } from "./root-errors.js";
10
11
  import { isDriveRelativePath } from "./safe-path-segment.js";
11
- import { realpathSync } from "./realpath.js";
12
+ import { realpathNative, realpathSync } from "./realpath.js";
13
+ import { absolutePathWithRawSegments } from "./root-path-existing.js";
12
14
  import { inspectFileIdentity } from "./strict-file-identity.js";
13
15
  import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathFromBasePreservingWindowsRoot, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
14
16
  export const ensureTrailingSep = (value) => value.endsWith(path.sep) ? value : value + path.sep;
@@ -34,21 +36,24 @@ export async function expandRelativePathWithHome(relativePath) {
34
36
  }
35
37
  const rawHome = process.env.HOME || process.env.USERPROFILE || os.homedir();
36
38
  assertNoWindowsPathAlias(rawHome, "filesystem", "home path uses a Windows filesystem namespace alias");
37
- if (cachedHomePath?.raw !== rawHome) {
39
+ let home = cachedHomePath?.raw === rawHome ? cachedHomePath.real : undefined;
40
+ if (home === undefined) {
38
41
  let realHome = rawHome;
39
42
  try {
40
- realHome = realpathSync.native(pathForWindowsFilesystem(rawHome));
43
+ const homePath = pathForWindowsFilesystem(rawHome);
44
+ realHome = process.platform === "win32" ? realpathSync.native(homePath) : await realpathNative(homePath);
41
45
  }
42
46
  catch {
43
47
  // If the home dir cannot be canonicalized, keep lexical expansion behavior.
44
48
  }
45
49
  cachedHomePath = { raw: rawHome, real: realHome };
50
+ home = realHome;
46
51
  }
47
52
  if (homeOnly) {
48
- assertNoWindowsPathAlias(cachedHomePath.real, "filesystem", "home path uses a Windows filesystem namespace alias");
49
- return cachedHomePath.real;
53
+ assertNoWindowsPathAlias(home, "filesystem", "home path uses a Windows filesystem namespace alias");
54
+ return home;
50
55
  }
51
- const expanded = `${ensureTrailingSep(cachedHomePath.real)}${relativePath.slice(2)}`;
56
+ const expanded = `${ensureTrailingSep(home)}${relativePath.slice(2)}`;
52
57
  assertNoWindowsPathAlias(expanded, "filesystem", "expanded path uses a Windows filesystem namespace alias");
53
58
  return expanded;
54
59
  }
@@ -61,14 +66,17 @@ export async function resolveRootContext(rootDir) {
61
66
  let rootStat;
62
67
  let rootIdentity;
63
68
  try {
64
- rootReal = realpathSync.native(pathForWindowsFilesystem(rootDir));
69
+ const rootPath = pathForWindowsFilesystem(absolutePathWithRawSegments(rootDir));
70
+ rootReal = process.platform === "win32" ? realpathSync.native(rootPath) : await realpathNative(rootPath);
65
71
  assertNoWindowsPathAlias(rootReal, "filesystem", "canonical root path uses a Windows filesystem namespace alias");
66
- rootStat = await inspectFileIdentity(() => {
67
- const stat = fs.statSync(rootReal, { bigint: true });
72
+ const inspect = (stat) => {
68
73
  if (!stat.isDirectory())
69
74
  throw new FsSafeError("invalid-path", "root dir is not a directory");
70
75
  return stat;
71
- });
76
+ };
77
+ rootStat = await inspectFileIdentity(() => process.platform === "win32"
78
+ ? inspect(fs.statSync(rootReal, { bigint: true }))
79
+ : asyncFs.stat(rootReal, { bigint: true }).then(inspect));
72
80
  rootIdentity = { dev: rootStat.dev, ino: rootStat.ino };
73
81
  }
74
82
  catch (err) {
@@ -128,7 +136,15 @@ export function assertRootIdentityCurrentSync(root, observe) {
128
136
  }
129
137
  }
130
138
  export async function assertRootIdentityCurrent(root, observe) {
131
- assertRootIdentityCurrentSync(root, observe);
139
+ if (process.platform === "win32")
140
+ return assertRootIdentityCurrentSync(root, observe);
141
+ try {
142
+ const stat = await inspectDirectoryIdentity(root.rootReal, { dev: root.rootIdentity.dev, ino: root.rootIdentity.ino });
143
+ observe?.(stat);
144
+ }
145
+ catch (error) {
146
+ throw rootPathChangedError(error instanceof Error ? error : undefined);
147
+ }
132
148
  }
133
149
  /**
134
150
  * Observe the current Root with an exact, operation-local receipt.
@@ -101,6 +101,7 @@ async function copyInputInRoot(root, params, input, mode, verifyAdmission = inpu
101
101
  const observer = createCopyPublicationObserver(pinned.targetPath, params.onDestinationPublished);
102
102
  try {
103
103
  await runPinnedWriteHelper({
104
+ allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
104
105
  rootPath: pinned.rootReal, relativeParentPath: pinned.relativeParentPath, basename: pinned.basename,
105
106
  mkdir: params.mkdir !== false, mode: pinned.mode, overwrite: params.overwrite !== false,
106
107
  rejectFinalSymlink: params.mutationSymlinks !== undefined, maxBytes: params.maxBytes,
@@ -1,7 +1,7 @@
1
1
  import { normalizeMaxBytes } from "./byte-budget.js";
2
2
  import { FsSafeError } from "./errors.js";
3
3
  import { MutationAuthorityError } from "./mutation-authority.js";
4
- // Lock records need exclusive creation, not private-before-visible publication.
4
+ // Lock records require complete exclusive publication.
5
5
  // Keep this composition hook off the public Root options and package exports.
6
6
  const exclusiveSidecarCreate = Symbol("exclusiveSidecarCreate");
7
7
  export const sidecarExclusiveCreate = Object.freeze({ [exclusiveSidecarCreate]: true });
@@ -48,7 +48,7 @@ export function rootWriteInput(params) {
48
48
  const data = params.data;
49
49
  if (typeof data === "string" || Buffer.isBuffer(data)) {
50
50
  return {
51
- kind: "buffer", data, encoding: params.encoding,
51
+ kind: "buffer", data, encoding: params.encoding, sidecar: params[exclusiveSidecarCreate],
52
52
  stageBeforePublish: params[exclusiveSidecarCreate] ? false : params.atomic === true ? true : undefined,
53
53
  };
54
54
  }
@@ -14,7 +14,11 @@ export type CanonicalRootObservation = {
14
14
  error: unknown;
15
15
  };
16
16
  export declare function observeCanonicalRoot(ioFs: RootFileAdmissionFs, rootPath: string): CanonicalRootObservation;
17
+ export declare function observeCanonicalRootAsync(rootPath: string): Promise<CanonicalRootObservation>;
17
18
  export declare function createRootFileFinalAdmission(ioFs: RootFileAdmissionFs, root: Extract<CanonicalRootObservation, {
18
19
  ok: true;
19
20
  }>, boundaryLabel: string, rejectHardlinks?: boolean): PinnedOpenSyncFinalAdmission;
21
+ export declare function createRootFileFinalAdmissionAsync(root: Extract<CanonicalRootObservation, {
22
+ ok: true;
23
+ }>, boundaryLabel: string, rejectHardlinks: boolean): (params: Parameters<PinnedOpenSyncFinalAdmission>[0]) => Promise<string>;
20
24
  export {};