@openclaw/matrix 2026.11.5 → 2026.11.7

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 (159) hide show
  1. package/dist/.setup/{approval-handler.runtime-Ca12_7Qa.mjs → approval-handler.runtime-LBvkygUK.mjs} +3 -3
  2. package/dist/.setup/{channel-FfaEmyIU.mjs → channel-CHryi9FS.mjs} +8 -8
  3. package/dist/.setup/{channel.runtime-CkkHG8zy.mjs → channel.runtime-DluXWaGb.mjs} +5 -5
  4. package/dist/.setup/{channel.setup-B00zzOOL.mjs → channel.setup-BDbs0FLq.mjs} +2 -2
  5. package/dist/.setup/{cli-dz9hd2dR.mjs → cli-C7Jmy2x4.mjs} +15 -40
  6. package/dist/.setup/cli-doctor-BVstkgJE.mjs +36 -0
  7. package/dist/.setup/{cli-metadata-CwUhA9CY.mjs → cli-metadata-B0GHIn05.mjs} +1 -1
  8. package/dist/.setup/{client-D1bsidwU.mjs → client-Bk_tBqNp.mjs} +2 -2
  9. package/dist/.setup/{client-bootstrap-CTT0VF6v.mjs → client-bootstrap-Bhhri97J.mjs} +1 -1
  10. package/dist/.setup/{client-CFPYqaYK.mjs → client-mFRVrUt3.mjs} +2 -2
  11. package/dist/.setup/{create-client-Ccf5wyS3.mjs → create-client-CzUtZgYF.mjs} +2 -2
  12. package/dist/.setup/{crypto-runtime-DZNytKX5.mjs → crypto-runtime-BI9Pc344.mjs} +1 -1
  13. package/dist/.setup/{crypto-unsafe-state-doctor-Dh1dtuSz.mjs → crypto-unsafe-state-doctor-CmF1X1dZ.mjs} +3 -4
  14. package/dist/.setup/{directory-live-ufzRheWx.mjs → directory-live-DmkH9hcp.mjs} +1 -1
  15. package/dist/.setup/{draft-stream-BPjjKSoI.mjs → draft-stream-bVedfEB3.mjs} +1 -1
  16. package/dist/.setup/{exec-approvals-BwEOyI1-.mjs → exec-approvals-BeYF9-3o.mjs} +2 -2
  17. package/dist/.setup/{messages-DpJ9naJa.mjs → messages-BqVczVlt.mjs} +2 -2
  18. package/dist/.setup/{monitor-vpzawYrB.mjs → monitor-BsSo3tCv.mjs} +31 -17
  19. package/dist/.setup/{onboarding-BK-V2ZLT.mjs → onboarding-CoMpgTiK.mjs} +3 -3
  20. package/dist/.setup/{outbound-DydCDuvM.mjs → outbound-ntm0KOfK.mjs} +2 -2
  21. package/dist/.setup/{profile-update-RLsY-gu6.mjs → profile-update-gC436enW.mjs} +9 -4
  22. package/dist/.setup/{reaction-events-lcgVF3M5.mjs → reaction-events-DTThoaJQ.mjs} +3 -3
  23. package/dist/.setup/{resolve-targets-DYW8ULZS.mjs → resolve-targets-CWW9zTYp.mjs} +1 -1
  24. package/dist/.setup/{room-info-Dhc4efkA.mjs → room-info-CM3MKoh4.mjs} +3 -3
  25. package/dist/.setup/{sdk-DPXiQ3jr.mjs → sdk-ByFgA6Il.mjs} +4 -3
  26. package/dist/.setup/{send-HHAbKARg.mjs → send-DFB7JGg2.mjs} +7 -7
  27. package/dist/.setup/{setup-bootstrap-DaT2j28V.mjs → setup-bootstrap-razh2kSp.mjs} +2 -2
  28. package/dist/.setup/{setup-core-DcqQbLZv.mjs → setup-core-BVbxltMM.mjs} +1 -1
  29. package/dist/.setup/setup-plugin-api-CQKySg7F.mjs +2 -0
  30. package/dist/.setup/{thread-bindings-891JsKXF.mjs → thread-bindings-D5VJEDZV.mjs} +1 -1
  31. package/dist/.setup/{tool-actions-8mXdq9OV.mjs → tool-actions-DexlmVDf.mjs} +10 -10
  32. package/dist/.setup/{verification-CcZIVL8P.mjs → verification-B122bsH2.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/doctor-contract-api.js +7 -3
  39. package/dist/index.js +1 -1
  40. package/dist/plugin-entry.handlers.runtime.js +2 -2
  41. package/dist/session-binding-contract-api.js +1 -1
  42. package/dist/setup-entry.js +1 -1
  43. package/dist/setup-plugin-api.js +1 -1
  44. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +45 -1
  45. package/node_modules/@openclaw/fs-safe/README.md +4 -0
  46. package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +2 -2
  47. package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -2
  48. package/node_modules/@openclaw/fs-safe/dist/advanced.js +2 -2
  49. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  50. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  51. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +6 -0
  52. package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -0
  53. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +5 -0
  54. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +13 -0
  55. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.d.ts +3 -0
  56. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.js +6 -0
  57. package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +1 -1
  58. package/node_modules/@openclaw/fs-safe/dist/errors.js +1 -0
  59. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.d.ts +0 -1
  60. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +1 -11
  61. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +3 -3
  62. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +2 -3
  63. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -3
  64. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +30 -4
  65. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.d.ts +1 -1
  66. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -1
  67. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.d.ts +1 -1
  68. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.js +30 -4
  69. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -1
  70. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +2 -0
  71. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  72. package/node_modules/@openclaw/fs-safe/dist/file-store.js +5 -0
  73. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +2 -0
  74. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +9 -0
  75. package/node_modules/@openclaw/fs-safe/dist/json-store.d.ts +2 -1
  76. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -1
  77. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +1 -1
  78. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
  79. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +19 -13
  80. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.d.ts +2 -0
  81. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +27 -5
  82. package/node_modules/@openclaw/fs-safe/dist/path-prefix.d.ts +1 -0
  83. package/node_modules/@openclaw/fs-safe/dist/path-prefix.js +84 -7
  84. package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +0 -11
  85. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +9 -0
  86. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +61 -0
  87. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -1
  88. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +2 -0
  89. package/node_modules/@openclaw/fs-safe/dist/realpath.js +16 -0
  90. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +2 -1
  91. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +8 -6
  92. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -1
  93. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +20 -13
  94. package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -1
  95. package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +1 -1
  96. package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +18 -9
  97. package/node_modules/@openclaw/fs-safe/dist/root-errors.d.ts +2 -0
  98. package/node_modules/@openclaw/fs-safe/dist/root-errors.js +9 -0
  99. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +4 -1
  100. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.d.ts +1 -1
  101. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js +35 -16
  102. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.d.ts +6 -2
  103. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +32 -20
  104. package/node_modules/@openclaw/fs-safe/dist/root-path.js +32 -26
  105. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +4 -1
  106. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +2 -1
  107. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  108. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +2 -1
  109. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +5 -4
  110. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +3 -2
  111. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js +8 -9
  112. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +3 -1
  113. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +2 -1
  114. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
  115. package/node_modules/@openclaw/fs-safe/dist/types.d.ts +1 -0
  116. package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +12 -3
  117. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  118. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.d.ts +0 -1
  119. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.js +10 -12
  120. package/node_modules/@openclaw/fs-safe/docs/advanced.md +3 -3
  121. package/node_modules/@openclaw/fs-safe/docs/atomic.md +16 -3
  122. package/node_modules/@openclaw/fs-safe/docs/compiler-qualification.md +1 -1
  123. package/node_modules/@openclaw/fs-safe/docs/contributing.md +27 -18
  124. package/node_modules/@openclaw/fs-safe/docs/errors.md +3 -1
  125. package/node_modules/@openclaw/fs-safe/docs/file-store.md +14 -2
  126. package/node_modules/@openclaw/fs-safe/docs/in-place-write.md +31 -0
  127. package/node_modules/@openclaw/fs-safe/docs/install.md +1 -1
  128. package/node_modules/@openclaw/fs-safe/docs/json-store.md +6 -1
  129. package/node_modules/@openclaw/fs-safe/docs/json.md +5 -1
  130. package/node_modules/@openclaw/fs-safe/docs/path-prefix.md +14 -4
  131. package/node_modules/@openclaw/fs-safe/docs/public-api.md +4 -2
  132. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -1
  133. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +4 -0
  134. package/node_modules/@openclaw/fs-safe/docs/temp.md +9 -1
  135. package/node_modules/@openclaw/fs-safe/docs/types.md +5 -1
  136. package/node_modules/@openclaw/fs-safe/package.json +12 -12
  137. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  138. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  139. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  140. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  141. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  142. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  143. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  144. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  145. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  146. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  147. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  148. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  149. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  150. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  151. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  152. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  153. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  154. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  155. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  156. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  157. package/openclaw.plugin.json +6 -0
  158. package/package.json +5 -5
  159. package/dist/.setup/setup-plugin-api-Cg4TelGZ.mjs +0 -2
@@ -53,7 +53,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
53
53
  import fs from "node:fs";
54
54
  import path from "node:path";
55
55
  import { inspectDirectoryIdentitySync } from "./directory-guard.js";
56
- import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
56
+ import { finalizeCreatedDirectoryModeSync, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
57
57
  import { FsSafeError } from "./errors.js";
58
58
  import { getNativeBinding } from "./native.js";
59
59
  import { captureNativeFdClose } from "./native-binding.js";
@@ -67,9 +67,9 @@ import { isSafePathSegment } from "./safe-path-segment.js";
67
67
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
68
68
  import { getFsSafeTestHooks } from "./test-hooks.js";
69
69
  import { pathForWindowsFilesystem } from "./windows-path-alias.js";
70
- export function tryMkdirNativeParents(root, relativePath) {
70
+ export function tryMkdirNativeParents(root, relativePath, mode) {
71
71
  try {
72
- return mkdirOrdinaryNativeParents(root, relativePath);
72
+ return mkdirOrdinaryNativeParents(root, relativePath, mode);
73
73
  }
74
74
  catch (error) {
75
75
  if (hasNodeErrorCode(error, "ENOTDIR"))
@@ -77,7 +77,7 @@ export function tryMkdirNativeParents(root, relativePath) {
77
77
  throw error;
78
78
  }
79
79
  }
80
- function mkdirOrdinaryNativeParents(root, relativePath) {
80
+ function mkdirOrdinaryNativeParents(root, relativePath, mode) {
81
81
  if (getFsSafeTestHooks()?.beforeRootFallbackMutation)
82
82
  return false;
83
83
  const segments = relativePath.split(path.sep === "\\" ? /[\\/]/ : "/");
@@ -102,7 +102,7 @@ function mkdirOrdinaryNativeParents(root, relativePath) {
102
102
  catch (error) {
103
103
  // Reuse this exact Root snapshot and failed parent observation without an
104
104
  // intervening await. All opened ancestors still receive fresh native fences.
105
- return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat) : false;
105
+ return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat, mode) : false;
106
106
  }
107
107
  try {
108
108
  if (realpathSync.native(pathForWindowsFilesystem(parentPath)) !== parentPath)
@@ -111,12 +111,12 @@ function mkdirOrdinaryNativeParents(root, relativePath) {
111
111
  catch {
112
112
  return false;
113
113
  }
114
- return mkdirExistingParent(root, segments, parentIdentity);
114
+ return mkdirExistingParent(root, segments, parentIdentity, mode);
115
115
  }
116
116
  /** Ordinary missing suffixes need no policy callbacks or repeated path resolution. */
117
- function mkdirMissingParents(root, segments, rootStat) {
117
+ function mkdirMissingParents(root, segments, rootStat, mode) {
118
118
  const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
119
- if (!binding?.openBeneath || !binding.mkdirOpenChildBeneath)
119
+ if (!binding?.openBeneath || !binding.mkdirChildBeneath || (!binding.mkdirOpenChildBeneath && mode === undefined))
120
120
  return false;
121
121
  let parentDepth = segments.length - 2;
122
122
  let parentPath;
@@ -156,7 +156,7 @@ function mkdirMissingParents(root, segments, rootStat) {
156
156
  if (errors.length)
157
157
  throw new AggregateError(errors, "mkdir directory close failed");
158
158
  } }, false);
159
- const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
159
+ const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
160
160
  (fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
161
161
  let current = rootOwner.fd;
162
162
  if (parentDepth > 0) {
@@ -172,12 +172,21 @@ function mkdirMissingParents(root, segments, rootStat) {
172
172
  };
173
173
  assertCurrent();
174
174
  for (const segment of segments.slice(parentDepth)) {
175
- const child = binding.mkdirOpenChildBeneath(current, segment, 0o777, flags);
175
+ const child = binding.mkdirOpenChildBeneath
176
+ ? binding.mkdirOpenChildBeneath(current, segment, mode ?? 0o777, flags)
177
+ : {
178
+ created: binding.mkdirChildBeneath(current, segment, mode ?? 0o777),
179
+ fd: binding.openBeneath(current, segment, flags).fd,
180
+ };
176
181
  parentPath = path.join(parentPath, segment);
177
182
  directories.push({ fd: child.fd, pathname: parentPath });
178
183
  // Retain every ancestor until the complete suffix is admitted. The
179
184
  // post-create fence also precedes the next synchronous child mutation.
180
185
  assertCurrent();
186
+ if (mode !== undefined && child.created) {
187
+ finalizeCreatedDirectoryModeSync(child, mode);
188
+ assertCurrent();
189
+ }
181
190
  current = child.fd;
182
191
  }
183
192
  return true;
@@ -196,7 +205,7 @@ function mkdirMissingParents(root, segments, rootStat) {
196
205
  throw error;
197
206
  }
198
207
  }
199
- function mkdirExistingParent(root, segments, parentIdentity) {
208
+ function mkdirExistingParent(root, segments, parentIdentity, mode) {
200
209
  const env_2 = { stack: [], error: void 0, hasError: false };
201
210
  try {
202
211
  const target = path.join(root.rootReal, ...segments);
@@ -209,7 +218,7 @@ function mkdirExistingParent(root, segments, parentIdentity) {
209
218
  rootPath: root.rootReal, rootIdentity: root.rootIdentity,
210
219
  }), false);
211
220
  verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
212
- const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
221
+ const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
213
222
  (fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
214
223
  const close = captureNativeFdClose(binding);
215
224
  const parent = binding.openBeneath(rootOwner.fd, segments.slice(0, -1).join("/"), flags).fd;
@@ -219,14 +228,24 @@ function mkdirExistingParent(root, segments, parentIdentity) {
219
228
  assertRootIdentityCurrentSync(root);
220
229
  const name = segments.at(-1);
221
230
  const child = binding.mkdirOpenChildBeneath
222
- ? binding.mkdirOpenChildBeneath(parent, name, 0o777, flags).fd
223
- : (binding.mkdirChildBeneath(parent, name, 0o777), binding.openBeneath(parent, name, flags).fd);
224
- const childOwner = __addDisposableResource(env_2, { [Symbol.dispose]() { close(child); } }, false);
231
+ ? binding.mkdirOpenChildBeneath(parent, name, mode ?? 0o777, flags)
232
+ : {
233
+ created: binding.mkdirChildBeneath(parent, name, mode ?? 0o777),
234
+ fd: binding.openBeneath(parent, name, flags).fd,
235
+ };
236
+ const childOwner = __addDisposableResource(env_2, { [Symbol.dispose]() { close(child.fd); } }, false);
225
237
  assertRootIdentityCurrentSync(root);
226
- verifyMkdirDirectory(binding, child, target);
238
+ verifyMkdirDirectory(binding, child.fd, target);
227
239
  inspectDirectoryIdentitySync(parentPath, parentIdentity);
228
240
  verifyMkdirDirectory(binding, parent, parentPath);
229
241
  verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
242
+ if (mode !== undefined && child.created) {
243
+ finalizeCreatedDirectoryModeSync(child, mode);
244
+ verifyMkdirDirectory(binding, child.fd, target);
245
+ verifyMkdirDirectory(binding, parent, parentPath);
246
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
247
+ assertRootIdentityCurrentSync(root);
248
+ }
230
249
  return true;
231
250
  }
232
251
  catch (e_2) {
@@ -1,12 +1,16 @@
1
+ import { runAsync, runSync, type Procedure } from "./atomic-io.js";
1
2
  import { type RootBoundaryIdentity } from "./root-boundary.js";
3
+ export declare const synchronousRootTraversal: boolean;
4
+ export declare const runRootTraversal: typeof runAsync | typeof runSync;
2
5
  export declare function absolutePathWithRawSegments(candidate: string): string;
3
6
  export declare function rawPathRelativeToCanonicalRoot(candidate: string, rootCanonicalPath: string, options?: {
4
7
  rejectSymlinks?: boolean;
5
8
  rejectFinalSymlink?: boolean;
6
9
  rootIdentity?: RootBoundaryIdentity;
7
- }): string | undefined;
10
+ }, synchronous?: boolean): Procedure<string | undefined>;
8
11
  export declare function resolvePathViaExistingAncestor(targetPath: string): Promise<string>;
9
12
  export declare function resolvePathViaExistingAncestorSync(targetPath: string): string;
10
13
  export type RootPathMetadataMode = "native" | "ordinary";
11
14
  export declare function resolveExistingAncestor(targetPath: string, mode: RootPathMetadataMode, preserveRawSegments?: boolean, remainingHops?: number): string;
12
- export declare function resolveSymlinkHopPath(symlinkPath: string, mode: RootPathMetadataMode, rejectUnresolved?: boolean, remainingHops?: number): string;
15
+ export declare function resolveExistingAncestorProcedure(targetPath: string, mode: RootPathMetadataMode, synchronous: boolean, preserveRawSegments?: boolean, remainingHops?: number): Procedure<string>;
16
+ export declare function resolveSymlinkHopPath(symlinkPath: string, mode: RootPathMetadataMode, rejectUnresolved?: boolean, remainingHops?: number, synchronous?: boolean): Procedure<string>;
@@ -1,12 +1,18 @@
1
1
  import fs from "node:fs";
2
+ import asyncFs from "node:fs/promises";
2
3
  import path from "node:path";
4
+ import { runAsync, runSync, wait } from "./atomic-io.js";
3
5
  import { FsSafeError } from "./errors.js";
4
6
  import { formatErrorDetail } from "./error-detail.js";
5
7
  import { isNotFoundPathError, isPathInside, isSymlinkOpenError } from "./path.js";
6
- import { realpathSync } from "./realpath.js";
8
+ import { realpathNative, realpathSync } from "./realpath.js";
7
9
  import { assertNoWindowsPathAlias, isForeignWindowsShareOrDevicePath, pathForWindowsFilesystem, resolvePathFromBasePreservingWindowsRoot, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
8
10
  import { admitPathInsideRoot } from "./root-boundary.js";
9
11
  import { errorCauseOptions } from "./root-errors.js";
12
+ // Windows native realpath denies delete sharing. Preserve read/publication
13
+ // scheduling until canonicalization can safely overlap replacement.
14
+ export const synchronousRootTraversal = process.platform === "win32";
15
+ export const runRootTraversal = synchronousRootTraversal ? runSync : runAsync;
10
16
  export function absolutePathWithRawSegments(candidate) {
11
17
  if (path.sep !== "\\") {
12
18
  if (path.isAbsolute(candidate))
@@ -24,7 +30,7 @@ export function absolutePathWithRawSegments(candidate) {
24
30
  const base = drive ? path.resolve(drive) : process.cwd();
25
31
  return `${base}${base.endsWith(path.sep) ? "" : path.sep}${raw.slice(drive.length)}`;
26
32
  }
27
- export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, options = {}) {
33
+ export function* rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, options = {}, synchronous = true) {
28
34
  assertNoWindowsPathAlias(candidate);
29
35
  assertNoWindowsPathAlias(rootCanonicalPath);
30
36
  const absolute = absolutePathWithRawSegments(candidate);
@@ -43,7 +49,7 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
43
49
  let isSymlink = false;
44
50
  try {
45
51
  const operationPath = pathForWindowsFilesystem(prefix);
46
- const stat = fs.lstatSync(operationPath);
52
+ const stat = synchronous ? fs.lstatSync(operationPath) : yield* wait(asyncFs.lstat(operationPath));
47
53
  isSymlink = stat.isSymbolicLink();
48
54
  // Check the original leaf before canonicalization can erase an entry alias.
49
55
  if (isSymlink && options.rejectFinalSymlink && index === finalComponentIndex) {
@@ -52,10 +58,11 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
52
58
  if (!isSymlink && !stat.isDirectory() && index < segments.length - 1)
53
59
  return undefined;
54
60
  traversedSymlink ||= isSymlink;
55
- canonical = realpathSync.native(operationPath);
61
+ canonical = synchronous ? realpathSync.native(operationPath) : yield* wait(realpathNative(operationPath));
56
62
  assertNoWindowsPathAlias(canonical);
57
63
  if (isSymlink && index < segments.length - 1 &&
58
- !fs.statSync(pathForWindowsFilesystem(canonical)).isDirectory())
64
+ !(synchronous ? fs.statSync(pathForWindowsFilesystem(canonical))
65
+ : yield* wait(asyncFs.stat(pathForWindowsFilesystem(canonical)))).isDirectory())
59
66
  return undefined;
60
67
  if (isSymlink && !isPathInside(rootCanonicalPath, canonical) && !isPathInside(canonical, rootCanonicalPath)) {
61
68
  throw new FsSafeError("outside-workspace", `symlink prefix resolves outside the root ancestry: ${formatErrorDetail(candidate)}`);
@@ -84,9 +91,10 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
84
91
  }
85
92
  return undefined;
86
93
  }
87
- function pathExists(targetPath) {
94
+ function* pathExists(targetPath, synchronous) {
88
95
  try {
89
- return fs.lstatSync(pathForWindowsFilesystem(targetPath), { throwIfNoEntry: false }) !== undefined;
96
+ return (synchronous ? fs.lstatSync(pathForWindowsFilesystem(targetPath), { throwIfNoEntry: false })
97
+ : yield* wait(asyncFs.lstat(pathForWindowsFilesystem(targetPath)))) !== undefined;
90
98
  }
91
99
  catch (error) {
92
100
  if (isNotFoundPathError(error)) {
@@ -96,17 +104,20 @@ function pathExists(targetPath) {
96
104
  }
97
105
  }
98
106
  export async function resolvePathViaExistingAncestor(targetPath) {
99
- return resolveExistingAncestor(targetPath, "native");
107
+ return runRootTraversal(resolveExistingAncestorProcedure(targetPath, "native", synchronousRootTraversal));
100
108
  }
101
- function pathExistsSync(targetPath) {
109
+ function* ordinaryExists(targetPath) {
102
110
  return fs.existsSync(pathForWindowsFilesystem(targetPath));
103
111
  }
104
112
  export function resolvePathViaExistingAncestorSync(targetPath) {
105
113
  return resolveExistingAncestor(targetPath, "ordinary");
106
114
  }
107
115
  export function resolveExistingAncestor(targetPath, mode, preserveRawSegments = false, remainingHops = 64) {
108
- const exists = mode === "native" || preserveRawSegments ? pathExists : pathExistsSync;
109
- const canonicalize = realpathSync.native;
116
+ return runSync(resolveExistingAncestorProcedure(targetPath, mode, true, preserveRawSegments, remainingHops));
117
+ }
118
+ export function* resolveExistingAncestorProcedure(targetPath, mode, synchronous, preserveRawSegments = false, remainingHops = 64) {
119
+ const exists = (pathname) => mode === "native" || preserveRawSegments
120
+ ? pathExists(pathname, synchronous) : ordinaryExists(pathname);
110
121
  assertNoWindowsPathAlias(targetPath);
111
122
  const normalized = resolvePathPreservingWindowsRoot(targetPath);
112
123
  assertNoWindowsPathAlias(normalized);
@@ -114,22 +125,23 @@ export function resolveExistingAncestor(targetPath, mode, preserveRawSegments =
114
125
  let cursor = candidate;
115
126
  const filesystemRoot = path.parse(candidate).root;
116
127
  while (cursor !== filesystemRoot &&
117
- !exists(cursor)) {
128
+ !(yield* exists(cursor))) {
118
129
  cursor = path.dirname(cursor);
119
130
  }
120
- if (!exists(cursor)) {
131
+ if (!(yield* exists(cursor))) {
121
132
  return normalized;
122
133
  }
123
134
  let rawResolvedAncestor;
124
135
  try {
125
- rawResolvedAncestor = canonicalize(pathForWindowsFilesystem(cursor));
136
+ rawResolvedAncestor = synchronous ? realpathSync.native(pathForWindowsFilesystem(cursor))
137
+ : yield* wait(realpathNative(pathForWindowsFilesystem(cursor)));
126
138
  }
127
139
  catch (error) {
128
140
  if (!preserveRawSegments)
129
141
  return normalized;
130
142
  if (!isNotFoundPathError(error))
131
143
  throw error;
132
- rawResolvedAncestor = resolveSymlinkHopPath(cursor, mode, false, remainingHops);
144
+ rawResolvedAncestor = yield* resolveSymlinkHopPath(cursor, mode, false, remainingHops, synchronous);
133
145
  }
134
146
  assertNoWindowsPathAlias(rawResolvedAncestor);
135
147
  const resolvedAncestor = resolvePathPreservingWindowsRoot(rawResolvedAncestor);
@@ -145,10 +157,10 @@ export function resolveExistingAncestor(targetPath, mode, preserveRawSegments =
145
157
  assertNoWindowsPathAlias(resolved);
146
158
  return resolved;
147
159
  }
148
- export function resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remainingHops = 64) {
160
+ export function* resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remainingHops = 64, synchronous = true) {
149
161
  try {
150
- const canonicalize = realpathSync.native;
151
- const rawRealPath = canonicalize(symlinkPath);
162
+ const rawRealPath = synchronous ? realpathSync.native(symlinkPath)
163
+ : yield* wait(realpathNative(symlinkPath));
152
164
  assertNoWindowsPathAlias(rawRealPath, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
153
165
  const realPath = resolvePathPreservingWindowsRoot(rawRealPath);
154
166
  assertNoWindowsPathAlias(realPath, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
@@ -162,14 +174,14 @@ export function resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remai
162
174
  throw error;
163
175
  if (remainingHops <= 0)
164
176
  throw new FsSafeError("symlink", "too many unresolved symlink hops");
165
- const linkTarget = fs.readlinkSync(symlinkPath);
177
+ const linkTarget = synchronous ? fs.readlinkSync(symlinkPath) : yield* wait(asyncFs.readlink(symlinkPath));
166
178
  assertNoWindowsPathAlias(linkTarget, "filesystem", "symlink target uses a Windows filesystem namespace alias");
167
179
  const linkDir = resolvePathPreservingWindowsRoot(path.dirname(symlinkPath));
168
180
  // Keep parent segments until the kernel has resolved the existing prefix.
169
181
  const targetPath = path.isAbsolute(linkTarget) ? linkTarget
170
182
  : path.parse(linkTarget).root ? resolvePathFromBasePreservingWindowsRoot(linkDir, linkTarget)
171
183
  : `${linkDir}${path.sep}${linkTarget}`;
172
- const resolved = resolveExistingAncestor(targetPath, mode, true, remainingHops - 1);
184
+ const resolved = yield* resolveExistingAncestorProcedure(targetPath, mode, synchronous, true, remainingHops - 1);
173
185
  assertNoWindowsPathAlias(resolved, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
174
186
  return resolved;
175
187
  }
@@ -1,11 +1,13 @@
1
1
  import fs, {} from "node:fs";
2
+ import asyncFs from "node:fs/promises";
2
3
  import path from "node:path";
4
+ import { runSync, wait } from "./atomic-io.js";
3
5
  import { shortPath } from "./error-detail.js";
4
6
  import { pathEscapeError, sanitizeRootPathError, symlinkEscapeError } from "./root-path-errors.js";
5
7
  import { FsSafeError } from "./errors.js";
6
8
  import { isNativeDirectoryObservationGuard } from "./native-directory-observation.js";
7
9
  import { assertNoNulPathInput, isNotFoundPathError, isPathRelativeEscape, } from "./path.js";
8
- import { absolutePathWithRawSegments, rawPathRelativeToCanonicalRoot, resolveExistingAncestor, resolveSymlinkHopPath, } from "./root-path-existing.js";
10
+ import { absolutePathWithRawSegments, rawPathRelativeToCanonicalRoot, resolveExistingAncestorProcedure, resolveSymlinkHopPath, runRootTraversal, synchronousRootTraversal, } from "./root-path-existing.js";
9
11
  import { admitPathInsideRoot, } from "./root-boundary.js";
10
12
  import { RootPathObservationError, captureRootPathObservedDirectory, createRootPathTraversalObservation, inspectRootPathTraversalEntry, } from "./root-path-observation.js";
11
13
  import { assertNoDriveRelativePathSegments } from "./safe-path-segment.js";
@@ -23,36 +25,38 @@ export const ROOT_PATH_ALIAS_POLICIES = {
23
25
  }),
24
26
  };
25
27
  export async function resolveRootPath(params) {
26
- return resolveRootPathInternal(params);
28
+ return runRootTraversal(resolveRootPathInternal(params));
27
29
  }
28
30
  export async function resolveRootPathWithCanonicalRootObservation(params, observeRoot) {
29
- return resolveRootPathInternal(params, { observeRoot });
31
+ return runRootTraversal(resolveRootPathInternal(params, { observeRoot }));
30
32
  }
31
33
  export async function resolveRootPathWithObservation(params, request) {
32
34
  const observation = { request };
33
- const resolved = resolveRootPathInternal(params, { observation });
35
+ const resolved = synchronousRootTraversal
36
+ ? runSync(resolveRootPathInternal(params, { observation }))
37
+ : await runRootTraversal(resolveRootPathInternal(params, { observation }));
34
38
  return observation.receipt ? { resolved, receipt: observation.receipt } : { resolved };
35
39
  }
36
40
  // Removal receipts are separate from metadata observations and canonical-root
37
- // callbacks; the public resolver's options and result remain unchanged.
41
+ // callbacks; retain their synchronous admission and mutation-fence owner.
38
42
  export async function resolveRootPathForRemoval(params, receipts) {
39
- return resolveRootPathInternal(params, { removalReceipts: receipts });
43
+ return runSync(resolveRootPathInternal(params, { removalReceipts: receipts }, true));
40
44
  }
41
45
  export function resolveRootPathSync(params) {
42
- return resolveRootPathInternal(params, { mode: "ordinary" });
46
+ return runSync(resolveRootPathInternal(params, { mode: "ordinary" }, true));
43
47
  }
44
48
  export function resolveRootPathSyncWithCanonicalRootObservation(params, observeRoot) {
45
- return resolveRootPathInternal(params, { mode: "ordinary", observeRoot });
49
+ return runSync(resolveRootPathInternal(params, { mode: "ordinary", observeRoot }, true));
46
50
  }
47
- function resolveRootPathInternal(params, options = {}) {
51
+ function* resolveRootPathInternal(params, options = {}, synchronous = synchronousRootTraversal) {
48
52
  try {
49
- return traverseRootPath(params, options);
53
+ return yield* traverseRootPath(params, options, synchronous);
50
54
  }
51
55
  catch (error) {
52
56
  throw sanitizeRootPathError(error);
53
57
  }
54
58
  }
55
- function prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath) {
59
+ function* prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath, synchronous) {
56
60
  let raw = rawAbsolutePath;
57
61
  let trustedAbsolutePath = false;
58
62
  // Even a metadata lookup on a foreign share contacts that host, including the
@@ -68,7 +72,7 @@ function prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath,
68
72
  else {
69
73
  const canonical = admitRawPathInsideRoot(rootCanonicalPath, raw, params.rootIdentity);
70
74
  const relative = canonical?.relativePath
71
- ?? rawPathRelativeToCanonicalRoot(raw, rootCanonicalPath, params);
75
+ ?? (yield* rawPathRelativeToCanonicalRoot(raw, rootCanonicalPath, params, synchronous));
72
76
  if (relative === undefined) {
73
77
  throw pathEscapeError({ rootPath, absolutePath: raw, boundaryLabel: params.boundaryLabel });
74
78
  }
@@ -249,27 +253,28 @@ function assertDirectoryBeforeMoreSegments(stat, pathname, isLast) {
249
253
  throw Object.assign(new Error(`Path component is not a directory: ${pathname}`), { code: "ENOTDIR" });
250
254
  }
251
255
  }
252
- function assertResolvedLinkDirectory(pathname, isLast) {
256
+ function* assertResolvedLinkDirectory(pathname, isLast, synchronous) {
253
257
  if (isLast)
254
258
  return;
255
- const stat = fs.statSync(pathForWindowsFilesystem(pathname));
259
+ const stat = synchronous ? fs.statSync(pathForWindowsFilesystem(pathname))
260
+ : yield* wait(asyncFs.stat(pathForWindowsFilesystem(pathname)));
256
261
  assertDirectoryBeforeMoreSegments(stat, pathname, isLast);
257
262
  }
258
- // Both public APIs use kernel canonicalization and synchronous metadata; only
259
- // ancestor existence differs. Promise wrappers preserve asynchronous rejection.
260
- function traverseRootPath(params, { mode = "native", observation: observationOutput, observeRoot, removalReceipts }) {
263
+ // Both drivers share containment policy. Observation receipts and platform-specific
264
+ // native guards retain their existing synchronous owners.
265
+ function* traverseRootPath(params, { mode = "native", observation: observationOutput, observeRoot, removalReceipts }, synchronous) {
261
266
  const input = captureValidRootPathInputs(params);
262
267
  const rawAbsolutePath = absolutePathWithRawSegments(input.absolutePath);
263
268
  const rootPath = resolvePathPreservingWindowsRoot(input.rootPath);
264
269
  const absolutePath = resolvePathPreservingWindowsRoot(rawAbsolutePath);
265
270
  const rootCanonicalPath = input.rootCanonicalPath
266
271
  ? resolvePathPreservingWindowsRoot(input.rootCanonicalPath)
267
- : resolveExistingAncestor(rootPath, mode);
272
+ : yield* resolveExistingAncestorProcedure(rootPath, mode, synchronous);
268
273
  assertNoWindowsPathAlias(rootPath);
269
274
  assertNoWindowsPathAlias(absolutePath);
270
275
  assertNoWindowsPathAlias(rootCanonicalPath);
271
276
  observeRoot?.(rootCanonicalPath);
272
- const context = createLexicalTraversalContext(prepareRootTraversal(input, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath));
277
+ const context = createLexicalTraversalContext(yield* prepareRootTraversal(input, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath, synchronous));
273
278
  const { state } = context;
274
279
  const observation = createLexicalTraversalObservation(context, observationOutput?.request);
275
280
  for (let idx = 0; idx < state.segments.length; idx += 1) {
@@ -306,7 +311,8 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
306
311
  }
307
312
  stat = isNativeDirectoryObservationGuard(observed)
308
313
  ? undefined
309
- : observed?.stat ?? fs.lstatSync(state.lexicalCursor);
314
+ : observed?.stat ?? (synchronous ? fs.lstatSync(state.lexicalCursor)
315
+ : yield* wait(asyncFs.lstat(state.lexicalCursor)));
310
316
  }
311
317
  }
312
318
  catch (error) {
@@ -369,12 +375,12 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
369
375
  }
370
376
  if (observation?.enabled)
371
377
  disableLexicalTraversalObservation(context, observation);
372
- const linkCanonical = resolveSymlinkHopPath(state.lexicalCursor, mode, context.resolveParams.rejectUnresolvedSymlinks);
378
+ const linkCanonical = yield* resolveSymlinkHopPath(state.lexicalCursor, mode, context.resolveParams.rejectUnresolvedSymlinks, 64, synchronous);
373
379
  applyResolvedSymlinkHop(context, linkCanonical);
374
380
  if (context.resolveParams.rejectSymlinks === true) {
375
381
  throw new FsSafeError("symlink", "symlink path component not allowed");
376
382
  }
377
- assertResolvedLinkDirectory(linkCanonical, isLast);
383
+ yield* assertResolvedLinkDirectory(linkCanonical, isLast, synchronous);
378
384
  }
379
385
  const completeObservation = observation?.enabled === true && observation.directoryGuard !== undefined &&
380
386
  observation.targetPath === state.canonicalCursor && observation.target !== undefined;
@@ -382,7 +388,7 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
382
388
  ? isNativeDirectoryObservationGuard(observation.target)
383
389
  ? "directory"
384
390
  : toResolvedKind(observation.target.stat)
385
- : getPathKindSync(state.canonicalCursor, state.preserveFinalSymlink);
391
+ : yield* getPathKind(state.canonicalCursor, state.preserveFinalSymlink, synchronous);
386
392
  if (completeObservation && observationOutput) {
387
393
  observationOutput.receipt = {
388
394
  kind: observation.request.kind,
@@ -395,12 +401,12 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
395
401
  }
396
402
  return finalizeLexicalResolution(context, kind);
397
403
  }
398
- function getPathKindSync(absolutePath, preserveFinalSymlink) {
404
+ function* getPathKind(absolutePath, preserveFinalSymlink, synchronous) {
399
405
  try {
400
406
  const operationPath = pathForWindowsFilesystem(absolutePath);
401
407
  const stat = preserveFinalSymlink
402
- ? fs.lstatSync(operationPath)
403
- : fs.statSync(operationPath);
408
+ ? synchronous ? fs.lstatSync(operationPath) : yield* wait(asyncFs.lstat(operationPath))
409
+ : synchronous ? fs.statSync(operationPath) : yield* wait(asyncFs.stat(operationPath));
404
410
  return toResolvedKind(stat);
405
411
  }
406
412
  catch (error) {
@@ -8,7 +8,7 @@ import { assertNoPathAliasEscape } from "./path-policy.js";
8
8
  import { preparePinnedWriteMutationAdmission, snapshotPinnedMutationPolicy, } from "./pinned-mutation-admission.js";
9
9
  import { admitPathInsideRoot, sameNormalizedPathSpelling } from "./root-boundary.js";
10
10
  import { resolvePathInRoot } from "./root-context.js";
11
- import { errorCauseOptions, hardlinkedPathNotAllowedError, outsideWorkspaceError } from "./root-errors.js";
11
+ import { errorCauseOptions, hardlinkedPathNotAllowedError, outsideWorkspaceError, pathTraversalPermissionError } from "./root-errors.js";
12
12
  import { inheritWriteTargetMode } from "./root-write-mode.js";
13
13
  import { mutationSymlinkResolution, } from "./root-symlink-policy.js";
14
14
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
@@ -179,6 +179,9 @@ export async function resolveGuardedWritePathInRoot(root, params) {
179
179
  });
180
180
  }
181
181
  catch (error) {
182
+ const permissionError = pathTraversalPermissionError(error, resolvedPath.resolved);
183
+ if (permissionError)
184
+ throw permissionError;
182
185
  throw new FsSafeError("path-alias", "path alias escape blocked", errorCauseOptions(error));
183
186
  }
184
187
  }
@@ -1,4 +1,5 @@
1
1
  import { type BigIntStats } from "node:fs";
2
+ import { type DirectoryMode } from "./directory-mode-options.js";
2
3
  import { type AsyncDirectoryGuard } from "./directory-guard.js";
3
4
  import { type SecretFileReadOptions } from "./secret-read-policy.js";
4
5
  export declare const PRIVATE_SECRET_DIR_MODE = 448;
@@ -10,7 +11,7 @@ type SecretFileWriteParams = {
10
11
  filePath: string;
11
12
  content: string | Uint8Array;
12
13
  mode?: number;
13
- dirMode?: number;
14
+ dirMode?: DirectoryMode;
14
15
  durable?: boolean;
15
16
  };
16
17
  type SecretFileCreateParams = Omit<SecretFileWriteParams, "durable"> & {
@@ -1,6 +1,7 @@
1
1
  import fs, {} from "node:fs";
2
2
  import fsp from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
4
5
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
5
6
  import { canonicalPathFromExistingAncestor } from "./absolute-path.js";
6
7
  import { readFileDescriptorBoundedSync } from "./bounded-read.js";
@@ -238,6 +239,7 @@ export async function prepareSecretFileWrite(params) {
238
239
  assertNoWindowsPathAlias(filePath, "filesystem", "private secret path uses a Windows filesystem namespace alias");
239
240
  const mode = params.mode ?? PRIVATE_SECRET_FILE_MODE;
240
241
  const dirMode = params.dirMode ?? PRIVATE_SECRET_DIR_MODE;
242
+ rejectPrivateDirectoryPreservation(dirMode);
241
243
  const resolvedRoot = resolvePathPreservingWindowsRoot(rootDir);
242
244
  const resolvedFile = path.resolve(filePath);
243
245
  assertNoWindowsPathAlias(resolvedRoot, "filesystem", "private secret root uses a Windows filesystem namespace alias");
@@ -1,3 +1,4 @@
1
+ import type { DirectoryMode } from "./directory-mode-options.js";
1
2
  export type WriteSiblingTempFileOptions<T> = {
2
3
  dir: string;
3
4
  writeTemp: (tempPath: string) => Promise<T>;
@@ -5,7 +6,7 @@ export type WriteSiblingTempFileOptions<T> = {
5
6
  producerIsolation?: "private-directory";
6
7
  resolveFinalPath: (result: T) => string;
7
8
  tempPrefix?: string;
8
- dirMode?: number;
9
+ dirMode?: DirectoryMode;
9
10
  chmodDir?: boolean;
10
11
  /** Final file mode; omitted preserves the producer's mode. Applied through the retained descriptor. */
11
12
  mode?: number;
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { assertAsyncDirectoryGuard, createAsyncDirectoryGuard } from "./directory-guard.js";
5
5
  import { fitFileNameToPortableComponent, sanitizeUntrustedFileName } from "./filename.js";
6
- import { applyDirectoryMode } from "./replace-file-descriptor.js";
6
+ import { prepareDirectoryMode } from "./prepare-directory-mode.js";
7
7
  import { AtomicIo, runAsync } from "./atomic-io.js";
8
8
  import { realpathSync } from "./realpath.js";
9
9
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
@@ -34,14 +34,15 @@ export async function writeSiblingTempFile(options) {
34
34
  const mode = options.mode;
35
35
  const syncTempFile = options.syncTempFile === true;
36
36
  const syncParentDir = options.syncParentDir === true;
37
- await fs.mkdir(recursiveMkdirPath(dir), { recursive: true, mode: dirMode });
38
- if (chmodDir) {
39
- await runAsync(applyDirectoryMode(AtomicIo.async(fs), {
37
+ if (dirMode === "preserve" || chmodDir) {
38
+ await runAsync(prepareDirectoryMode(AtomicIo.async(fs), {
40
39
  dirPath: dir,
41
40
  mode: dirMode,
42
41
  ignoreChmodError: true,
43
42
  }));
44
43
  }
44
+ else
45
+ await fs.mkdir(recursiveMkdirPath(dir), { recursive: true, mode: dirMode });
45
46
  return await writeCallbackSibling({
46
47
  tempDir: dir,
47
48
  tempName: buildTempName(tempPrefix),
@@ -1,4 +1,5 @@
1
- import type { SidecarLockReclaimParams, SidecarLockRetryOptions } from "./sidecar-lock-types.js";
1
+ import type { SidecarLockSnapshot } from "./sidecar-lock-reclaim.js";
2
+ import type { SidecarLockRetryOptions } from "./sidecar-lock-types.js";
2
3
  export declare function validateSidecarLockRetryOptions(retry: SidecarLockRetryOptions): void;
3
4
  export declare function validateSidecarLockTimeoutMs(timeoutMs: number | undefined): void;
4
5
  export declare function validateSidecarLockStaleMs(staleMs: number | undefined): void;
@@ -11,4 +12,4 @@ export declare function sidecarLockRetryDelay(retry: SidecarLockRetryOptions, ti
11
12
  export declare const maxTransientLockDenials = 8;
12
13
  export declare function isTransientLockFileDenial(error: unknown, lockPath: string): boolean;
13
14
  export declare function sidecarLockPayloadCreatedAtMs(payload: unknown): number | null;
14
- export declare function defaultSidecarLockShouldReclaim(params: Pick<SidecarLockReclaimParams, "lockPath" | "payload" | "staleMs" | "nowMs">): Promise<boolean>;
15
+ export declare function defaultSidecarLockShouldReclaim(snapshot: SidecarLockSnapshot, staleMs: number, nowMs: number): boolean;
@@ -1,4 +1,3 @@
1
- import fsSync from "node:fs";
2
1
  const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
3
2
  function assertFiniteNonNegative(value, label) {
4
3
  if (!Number.isFinite(value) || value < 0) {
@@ -100,14 +99,14 @@ export function sidecarLockPayloadCreatedAtMs(payload) {
100
99
  const createdAtMs = Date.parse(createdAt);
101
100
  return Number.isFinite(createdAtMs) ? createdAtMs : null;
102
101
  }
103
- export async function defaultSidecarLockShouldReclaim(params) {
104
- const createdAtMs = sidecarLockPayloadCreatedAtMs(params.payload);
102
+ export function defaultSidecarLockShouldReclaim(snapshot, staleMs, nowMs) {
103
+ const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
105
104
  if (createdAtMs !== null)
106
- return params.nowMs - createdAtMs > params.staleMs;
107
- try {
108
- return params.nowMs - fsSync.statSync(params.lockPath).mtimeMs > params.staleMs;
109
- }
110
- catch {
105
+ return nowMs - createdAtMs > staleMs;
106
+ if (!snapshot.stat)
111
107
  return true;
112
- }
108
+ // A released pathname may already name another owner; age only the admitted record.
109
+ const mtimeMs = "mtimeNs" in snapshot.stat
110
+ ? Number(snapshot.stat.mtimeNs) / 1e6 : snapshot.stat.mtimeMs;
111
+ return nowMs - mtimeMs > staleMs;
113
112
  }
@@ -97,12 +97,14 @@ export async function handleStaleSidecarAdmission(params) {
97
97
  return;
98
98
  throw error;
99
99
  }
100
- const shouldReclaim = staleOptions.shouldReclaim ?? defaultSidecarLockShouldReclaim;
100
+ const shouldReclaim = staleOptions.shouldReclaim;
101
101
  let reclaim;
102
102
  try {
103
103
  reclaim = await admission.run(async () => {
104
104
  assertUnheld();
105
105
  try {
106
+ if (!shouldReclaim)
107
+ return defaultSidecarLockShouldReclaim(snapshot, params.staleMs, Date.now());
106
108
  return await Reflect.apply(shouldReclaim, undefined, [{
107
109
  lockPath,
108
110
  normalizedTargetPath,
@@ -1,11 +1,12 @@
1
1
  import type { ExactFileIdentity } from "./exact-identity.js";
2
+ import type { DirectoryMode } from "./directory-mode-options.js";
2
3
  import type { FileStore, FileStoreSync } from "./file-store.js";
3
4
  import type { TempPathIdentityReceipt } from "./temp-cleanup.js";
4
5
  import type { TempWorkspaceCleanupResult, TempWorkspaceCleanupSafety } from "./temp-workspace-owner.js";
5
6
  export type TempWorkspaceOptions = {
6
7
  rootDir: string;
7
8
  prefix: string;
8
- dirMode?: number;
9
+ dirMode?: DirectoryMode;
9
10
  mode?: number;
10
11
  cleanupSafety?: TempWorkspaceCleanupSafety;
11
12
  };
@@ -1,7 +1,8 @@
1
1
  import { type ReplaceFileAtomicOptions } from "./replace-file.js";
2
+ import type { DirectoryMode } from "./directory-mode-options.js";
2
3
  export type WriteTextAtomicOptions = Pick<ReplaceFileAtomicOptions, "beforeRename" | "tempPrefix"> & {
3
4
  mode?: number;
4
- dirMode?: number;
5
+ dirMode?: DirectoryMode;
5
6
  trailingNewline?: boolean;
6
7
  /** Defaults to true; false skips file and parent fsync without changing replacement. */
7
8
  durable?: boolean;