@openclaw/matrix 2026.11.6 → 2026.11.8

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 (168) hide show
  1. package/dist/.setup/{approval-handler.runtime-CshxBDs7.mjs → approval-handler.runtime-CKiMSdnX.mjs} +3 -3
  2. package/dist/.setup/{channel-OLndtGNE.mjs → channel-CZJeLUuu.mjs} +8 -8
  3. package/dist/.setup/{channel.runtime-CFSou_MS.mjs → channel.runtime-hpiGNile.mjs} +5 -5
  4. package/dist/.setup/{channel.setup-CqcEb6JR.mjs → channel.setup-Dc4G7kdF.mjs} +6 -2
  5. package/dist/.setup/{cli-CkMedN4Y.mjs → cli-DnLr6VVE.mjs} +8 -8
  6. package/dist/.setup/{cli-doctor-BVstkgJE.mjs → cli-doctor-DRM-8rZg.mjs} +1 -1
  7. package/dist/.setup/{cli-metadata-DN1E7yCf.mjs → cli-metadata-C9wZ_TOY.mjs} +1 -1
  8. package/dist/.setup/{client-Bk_tBqNp.mjs → client-CnPiPhTg.mjs} +4 -4
  9. package/dist/.setup/{client-Rlwtz1hG.mjs → client-CsgjDjyA.mjs} +2 -2
  10. package/dist/.setup/{client-bootstrap-Bhhri97J.mjs → client-bootstrap-CRN75TtW.mjs} +1 -1
  11. package/dist/.setup/{create-client-CzUtZgYF.mjs → create-client-C5bd0RUQ.mjs} +4 -4
  12. package/dist/.setup/{credentials-kT20jk_u.mjs → credentials-Byq2Kcqg.mjs} +1 -1
  13. package/dist/.setup/{crypto-runtime-BI9Pc344.mjs → crypto-runtime-EdW32JgS.mjs} +2 -2
  14. package/dist/.setup/{crypto-state-store-BZLlwkv_.mjs → crypto-state-store-m13QToc7.mjs} +2 -1
  15. package/dist/.setup/{crypto-store-ownership-CiQ1l_O7.mjs → crypto-store-ownership-CVeppnSH.mjs} +1 -1
  16. package/dist/.setup/{crypto-unsafe-state-doctor-CmF1X1dZ.mjs → crypto-unsafe-state-doctor-C_vhqxOm.mjs} +3 -3
  17. package/dist/.setup/{directory-live-DmkH9hcp.mjs → directory-live-Brv_PC6z.mjs} +1 -1
  18. package/dist/.setup/{draft-stream-DbTsJkoL.mjs → draft-stream-BAf9CYmE.mjs} +1 -1
  19. package/dist/.setup/{exec-approvals-CiGrN-cV.mjs → exec-approvals-ClD4sAHY.mjs} +2 -2
  20. package/dist/.setup/{file-sync-store-BpS12yaK.mjs → file-sync-store-Dilb8bVT.mjs} +2 -2
  21. package/dist/.setup/{idb-persistence-BTOsltD9.mjs → idb-persistence-COLTtrm_.mjs} +2 -2
  22. package/dist/.setup/{messages-DJDczJnC.mjs → messages-zsGFORuZ.mjs} +2 -2
  23. package/dist/.setup/{monitor-ZDbuZRVB.mjs → monitor-CdT6CsWk.mjs} +32 -18
  24. package/dist/.setup/{onboarding-DwhMV1fp.mjs → onboarding-FJiJ-X6s.mjs} +3 -3
  25. package/dist/.setup/{outbound-7iSmOloX.mjs → outbound-yjH1XHCr.mjs} +2 -2
  26. package/dist/.setup/{profile-update-Fu4u-aSC.mjs → profile-update-uRiRQTtX.mjs} +9 -4
  27. package/dist/.setup/{reaction-events-CBltCP52.mjs → reaction-events-DYJrx8eq.mjs} +3 -3
  28. package/dist/.setup/{resolve-targets-CWW9zTYp.mjs → resolve-targets-DwRQnBpN.mjs} +1 -1
  29. package/dist/.setup/{retired-state-JGUEBE72.mjs → retired-state-DohpBmxW.mjs} +1 -37
  30. package/dist/.setup/{room-info-DFDDmkBC.mjs → room-info-B6-Yo6I5.mjs} +3 -3
  31. package/dist/.setup/{sdk-ByFgA6Il.mjs → sdk-CPgBCtd2.mjs} +5 -5
  32. package/dist/.setup/{send-DiS4anyi.mjs → send-CCT72yQb.mjs} +7 -7
  33. package/dist/.setup/{setup-bootstrap-OfuocnF0.mjs → setup-bootstrap-CB0idLzk.mjs} +2 -2
  34. package/dist/.setup/{setup-core-CEQJRnym.mjs → setup-core-5sswwYZt.mjs} +1 -1
  35. package/dist/.setup/setup-plugin-api-BU7RNSl9.mjs +2 -0
  36. package/dist/.setup/sqlite-state-7WEloajv.mjs +37 -0
  37. package/dist/.setup/{startup-verification-UkaoSldm.mjs → startup-verification-zrBugJBv.mjs} +3 -2
  38. package/dist/.setup/{storage-C3N6YZIn.mjs → storage-BjNHtYwT.mjs} +4 -3
  39. package/dist/.setup/{sync-cache-state-BKVaKRzQ.mjs → sync-cache-state-CovS1oSw.mjs} +2 -1
  40. package/dist/.setup/{thread-bindings-BvoisBZE.mjs → thread-bindings-DZvpe83d.mjs} +4 -3
  41. package/dist/.setup/{tool-actions-TYBYDIkj.mjs → tool-actions-Dd8WTKXA.mjs} +10 -10
  42. package/dist/.setup/{verification-BhFA9xF6.mjs → verification-BKVxSiIq.mjs} +1 -1
  43. package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -1
  44. package/dist/api.js +4 -4
  45. package/dist/channel-plugin-api.js +1 -1
  46. package/dist/cli-metadata.js +1 -1
  47. package/dist/contract-api.js +2 -2
  48. package/dist/doctor-contract-api.js +6 -5
  49. package/dist/index.js +1 -1
  50. package/dist/plugin-entry.handlers.runtime.js +2 -2
  51. package/dist/session-binding-contract-api.js +1 -1
  52. package/dist/setup-entry.js +1 -1
  53. package/dist/setup-plugin-api.js +1 -1
  54. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +45 -1
  55. package/node_modules/@openclaw/fs-safe/README.md +4 -0
  56. package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +2 -2
  57. package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -2
  58. package/node_modules/@openclaw/fs-safe/dist/advanced.js +2 -2
  59. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  60. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  61. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +6 -0
  62. package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -0
  63. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +5 -0
  64. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +13 -0
  65. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.d.ts +3 -0
  66. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.js +6 -0
  67. package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +1 -1
  68. package/node_modules/@openclaw/fs-safe/dist/errors.js +1 -0
  69. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.d.ts +0 -1
  70. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +1 -11
  71. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +3 -3
  72. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +2 -3
  73. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -3
  74. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +30 -4
  75. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.d.ts +1 -1
  76. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -1
  77. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.d.ts +1 -1
  78. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.js +30 -4
  79. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -1
  80. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +2 -0
  81. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  82. package/node_modules/@openclaw/fs-safe/dist/file-store.js +5 -0
  83. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +2 -0
  84. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +9 -0
  85. package/node_modules/@openclaw/fs-safe/dist/json-store.d.ts +2 -1
  86. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -1
  87. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +1 -1
  88. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
  89. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +19 -13
  90. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.d.ts +2 -0
  91. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +27 -5
  92. package/node_modules/@openclaw/fs-safe/dist/path-prefix.d.ts +1 -0
  93. package/node_modules/@openclaw/fs-safe/dist/path-prefix.js +84 -7
  94. package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +0 -11
  95. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +9 -0
  96. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +61 -0
  97. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -1
  98. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +2 -0
  99. package/node_modules/@openclaw/fs-safe/dist/realpath.js +16 -0
  100. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +2 -1
  101. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +8 -6
  102. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -1
  103. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +20 -13
  104. package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -1
  105. package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +1 -1
  106. package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +18 -9
  107. package/node_modules/@openclaw/fs-safe/dist/root-errors.d.ts +2 -0
  108. package/node_modules/@openclaw/fs-safe/dist/root-errors.js +9 -0
  109. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +4 -1
  110. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.d.ts +1 -1
  111. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js +35 -16
  112. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.d.ts +6 -2
  113. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +32 -20
  114. package/node_modules/@openclaw/fs-safe/dist/root-path.js +32 -26
  115. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +4 -1
  116. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +2 -1
  117. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  118. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +2 -1
  119. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +5 -4
  120. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +3 -2
  121. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js +8 -9
  122. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +3 -1
  123. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +2 -1
  124. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
  125. package/node_modules/@openclaw/fs-safe/dist/types.d.ts +1 -0
  126. package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +12 -3
  127. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  128. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.d.ts +0 -1
  129. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.js +10 -12
  130. package/node_modules/@openclaw/fs-safe/docs/advanced.md +3 -3
  131. package/node_modules/@openclaw/fs-safe/docs/atomic.md +16 -3
  132. package/node_modules/@openclaw/fs-safe/docs/compiler-qualification.md +1 -1
  133. package/node_modules/@openclaw/fs-safe/docs/contributing.md +27 -18
  134. package/node_modules/@openclaw/fs-safe/docs/errors.md +3 -1
  135. package/node_modules/@openclaw/fs-safe/docs/file-store.md +14 -2
  136. package/node_modules/@openclaw/fs-safe/docs/in-place-write.md +31 -0
  137. package/node_modules/@openclaw/fs-safe/docs/install.md +1 -1
  138. package/node_modules/@openclaw/fs-safe/docs/json-store.md +6 -1
  139. package/node_modules/@openclaw/fs-safe/docs/json.md +5 -1
  140. package/node_modules/@openclaw/fs-safe/docs/path-prefix.md +14 -4
  141. package/node_modules/@openclaw/fs-safe/docs/public-api.md +4 -2
  142. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -1
  143. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +4 -0
  144. package/node_modules/@openclaw/fs-safe/docs/temp.md +9 -1
  145. package/node_modules/@openclaw/fs-safe/docs/types.md +5 -1
  146. package/node_modules/@openclaw/fs-safe/package.json +12 -12
  147. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  148. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  149. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  150. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  151. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  152. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  153. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  154. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  155. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  156. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  157. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  158. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  159. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  160. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  161. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  162. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  163. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  164. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  165. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  166. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  167. package/package.json +5 -5
  168. package/dist/.setup/setup-plugin-api-4hHy1k4x.mjs +0 -2
@@ -2,9 +2,10 @@ import { t as runtime_doctor_migrations_exports } from "./.setup/runtime-doctor-
2
2
  import { i as normalizeMatrixStoredCredentials, n as isMatrixCredentialRevocation, r as matrixCredentialsStoreKey, t as MATRIX_CREDENTIALS_NAMESPACE } from "./.setup/credentials-state-B3cuUFwZ.mjs";
3
3
  import { i as resolveMatrixCredentialsDir } from "./.setup/storage-paths-B51JM-pC.mjs";
4
4
  import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./.setup/doctor-contract-BANpMUbP.mjs";
5
- import { a as describeRetiredMatrixState, o as resolveMatrixSqliteStateEnv, t as RETIRED_MATRIX_STATE_FILENAMES } from "./.setup/retired-state-JGUEBE72.mjs";
5
+ import { a as describeRetiredMatrixState, t as RETIRED_MATRIX_STATE_FILENAMES } from "./.setup/retired-state-DohpBmxW.mjs";
6
+ import { t as resolveMatrixSqliteStateEnv } from "./.setup/sqlite-state-7WEloajv.mjs";
6
7
  import { t as walkMatrixStateFiles } from "./.setup/state-layout-walk-BQMgMykU.mjs";
7
- import { i as readLegacyMatrixSyncCacheState, n as hasMatrixSyncCacheStateInStore, r as openMatrixSyncCacheStoreOptions, s as writeMatrixSyncCacheStateToStore } from "./.setup/sync-cache-state-BKVaKRzQ.mjs";
8
+ import { i as readLegacyMatrixSyncCacheState, n as hasMatrixSyncCacheStateInStore, r as openMatrixSyncCacheStoreOptions, s as writeMatrixSyncCacheStateToStore } from "./.setup/sync-cache-state-CovS1oSw.mjs";
8
9
  import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
9
10
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
10
11
  import { createHash } from "node:crypto";
@@ -291,7 +292,7 @@ const matrixReplayGuardIngressMigration = {
291
292
  //#endregion
292
293
  //#region extensions/matrix/doctor-contract-api.ts
293
294
  const registerRecoveryCli = async (params) => {
294
- const { registerMatrixDoctorCommands } = await import("./.setup/cli-doctor-BVstkgJE.mjs");
295
+ const { registerMatrixDoctorCommands } = await import("./.setup/cli-doctor-DRM-8rZg.mjs");
295
296
  registerMatrixDoctorCommands(params);
296
297
  };
297
298
  const MATRIX_SYNC_CACHE_FILENAME = "bot-storage.json";
@@ -359,12 +360,12 @@ const stateMigrations = [
359
360
  id: "matrix-crypto-unsafe-state",
360
361
  label: "Matrix crypto unsafe final state",
361
362
  async detectLegacyState(params) {
362
- const { listMatrixCryptoUnsafeState } = await import("./.setup/crypto-unsafe-state-doctor-CmF1X1dZ.mjs").then((n) => n.t);
363
+ const { listMatrixCryptoUnsafeState } = await import("./.setup/crypto-unsafe-state-doctor-C_vhqxOm.mjs").then((n) => n.t);
363
364
  const roots = await listMatrixCryptoUnsafeState(params.stateDir, { openKeyedStoreV2: params.context.openPluginStateKeyedStore });
364
365
  return roots.length > 0 ? { preview: roots.map((root) => `Matrix crypto store is blocked after unsafe final save: ${root}. Run openclaw matrix doctor inspect; recovery is never automatic.`) } : null;
365
366
  },
366
367
  async migrateLegacyState(params) {
367
- const { listMatrixCryptoUnsafeState } = await import("./.setup/crypto-unsafe-state-doctor-CmF1X1dZ.mjs").then((n) => n.t);
368
+ const { listMatrixCryptoUnsafeState } = await import("./.setup/crypto-unsafe-state-doctor-C_vhqxOm.mjs").then((n) => n.t);
368
369
  return {
369
370
  changes: [],
370
371
  warnings: (await listMatrixCryptoUnsafeState(params.stateDir, { openKeyedStoreV2: params.context.openPluginStateKeyedStore })).map((root) => `Matrix crypto store remains blocked: ${root}. Inspect with openclaw matrix doctor inspect; explicit recovery may roll back keys.`)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as registerMatrixCliMetadata } from "./.setup/cli-metadata-DN1E7yCf.mjs";
1
+ import { n as registerMatrixCliMetadata } from "./.setup/cli-metadata-C9wZ_TOY.mjs";
2
2
  import { a as setMatrixRuntimeLifecycle } from "./.setup/runtime-1kn1P6io.mjs";
3
3
  import "./runtime-setter-api.js";
4
4
  import { registerMatrixSubagentHooks } from "./subagent-hooks-api.js";
@@ -1,9 +1,9 @@
1
- import { l as resolveMatrixAuthContext } from "./.setup/client-Bk_tBqNp.mjs";
1
+ import { l as resolveMatrixAuthContext } from "./.setup/client-CnPiPhTg.mjs";
2
2
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
3
3
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4
4
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  //#region extensions/matrix/src/plugin-entry.runtime.ts
6
- const loadMatrixVerificationRuntime = createLazyRuntimeModule(() => import("./.setup/verification-BhFA9xF6.mjs").then((n) => n.y));
6
+ const loadMatrixVerificationRuntime = createLazyRuntimeModule(() => import("./.setup/verification-BKVxSiIq.mjs").then((n) => n.y));
7
7
  function sendError(respond, err) {
8
8
  respond(false, { error: formatErrorMessage(err) });
9
9
  }
@@ -1,3 +1,3 @@
1
1
  import { i as setMatrixRuntime } from "./.setup/runtime-1kn1P6io.mjs";
2
- import { t as createMatrixThreadBindingManager } from "./.setup/thread-bindings-BvoisBZE.mjs";
2
+ import { t as createMatrixThreadBindingManager } from "./.setup/thread-bindings-DZvpe83d.mjs";
3
3
  export { createMatrixThreadBindingManager, setMatrixRuntime };
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
  var setup_entry_default = defineBundledChannelSetupEntry({
5
5
  importMetaUrl: import.meta.url,
6
6
  plugin: {
7
- specifier: fileURLToPath(new URL(".setup/setup-plugin-api-4hHy1k4x.mjs", import.meta.url).href),
7
+ specifier: fileURLToPath(new URL(".setup/setup-plugin-api-BU7RNSl9.mjs", import.meta.url).href),
8
8
  exportName: "matrixSetupPlugin"
9
9
  },
10
10
  secrets: {
@@ -1 +1 @@
1
- export { n as matrixSetupPlugin } from "./.setup/channel.setup-CqcEb6JR.mjs";
1
+ export { n as matrixSetupPlugin } from "./.setup/channel.setup-Dc4G7kdF.mjs";
@@ -1,6 +1,50 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.27.1 - 2026-10-31
4
+
5
+ **Highlights:** Native POSIX staged file creation, atomic publication, small-buffer writes, path-prefix canonicalization, and awaited root-path traversal no longer block the JavaScript thread, so slow storage cannot stall the event loop. ([#1052](https://github.com/openclaw/fs-safe/pull/1052), [#1053](https://github.com/openclaw/fs-safe/pull/1053), [#1054](https://github.com/openclaw/fs-safe/pull/1054))
6
+
7
+ ### Features
8
+
9
+ - **Path prefixes:** add `resolvePathPrefix` for asynchronous component traversal and make `resolveAbsolutePathForRead` use asynchronous Node canonicalization, keeping filesystem waits off the JavaScript thread while preserving physical symlink and missing-suffix semantics. ([#1053](https://github.com/openclaw/fs-safe/pull/1053))
10
+
11
+ ### Fixes
12
+
13
+ - **Root traversal:** keep awaited POSIX root-path metadata and canonicalization off the JavaScript thread so slow component lookups do not stall the event loop; preserve synchronous APIs, identity fences, and Windows publication behavior. ([#1054](https://github.com/openclaw/fs-safe/pull/1054))
14
+ - **Async writes:** keep native POSIX staged creation, atomic publication, and small-buffer writes off the JavaScript thread so slow storage does not stall the event loop. ([#1052](https://github.com/openclaw/fs-safe/pull/1052))
15
+
16
+ ## 0.27.0 - 2026-10-30
17
+
18
+ **Highlights:** Use `dirMode: "preserve"` for shared workspaces to keep verified existing write parents unchanged while creating new directories at `0700`. ([#1050](https://github.com/openclaw/fs-safe/pull/1050))
19
+
20
+ ### Features
21
+
22
+ - **Directory modes:** add `dirMode: "preserve"` to keep verified existing write parents unchanged while creating new directories at `0700`. Thanks @rbartoli for the OpenClaw PR motivated by [openclaw/openclaw#184867](https://github.com/openclaw/openclaw/issues/184867). ([#1050](https://github.com/openclaw/fs-safe/pull/1050))
23
+
24
+ ## 0.26.15 - 2026-10-30
25
+
26
+ **Highlights:** Awaited authority checks for borrowed-handle overwrites, so callers can move currentness checks off the main thread. ([#1049](https://github.com/openclaw/fs-safe/pull/1049))
27
+
28
+ ### Features
29
+
30
+ - **In-place writes:** add `overwriteFileHandleWithAuthority` for awaited authority preparation followed by a synchronous final assertion before writing a borrowed handle. Existing `overwriteFileHandle` behavior is unchanged. ([#1049](https://github.com/openclaw/fs-safe/pull/1049))
31
+
32
+ ### Performance
33
+
34
+ - **Watch hint admission:** reduce repeated admission of unrelated canonical parents within a batch while retaining per-hint identity checks and conservative alias reconciliation. Thanks @wr-web for reporting [openclaw#186752](https://github.com/openclaw/openclaw/issues/186752) and @DonnieFi for [#1046](https://github.com/openclaw/fs-safe/pull/1046).
35
+
36
+ ## 0.26.14 - 2026-10-30
37
+
38
+ **Highlights:** Clearer errors for denied Root traversal and reliable async file-lock contention. ([#1044](https://github.com/openclaw/fs-safe/pull/1044), [#1045](https://github.com/openclaw/fs-safe/pull/1045))
39
+
40
+ ### Fixes
41
+
42
+ - **Root errors:** report denied path traversal as operational `permission-denied`, preserving the original errno and path instead of implying a path-alias violation. Thanks @LiuwqGit for [openclaw/openclaw#184115](https://github.com/openclaw/openclaw/issues/184115). ([#1044](https://github.com/openclaw/fs-safe/pull/1044))
43
+ - **File lock contention:** use the admitted record's timestamp for async stale detection so ordinary owner release and re-creation do not trigger spurious `path-mismatch` failures. ([#1045](https://github.com/openclaw/fs-safe/pull/1045))
44
+
45
+ ### Security
46
+
47
+ - **Archive dependencies:** update zstd to 0.14.3, zstd-safe to 8.2.0, and zstd-sys to 2.1.2 for native and WASM archive builds, retaining the custom WASM allocator and allocation-failure checks. ([#1039](https://github.com/openclaw/fs-safe/pull/1039))
4
48
 
5
49
  ## 0.26.13 - 2026-10-24
6
50
 
@@ -221,6 +221,10 @@ mutation authority, and publication receipts. Retained lifecycles have separate
221
221
  contracts: [staged files](docs/staged-file.md), [entry publication](docs/entry-publication.md),
222
222
  and [staged symlinks](docs/staged-symlink.md).
223
223
 
224
+ For a shared parent, pass `dirMode: "preserve"`: verified existing directories
225
+ keep their permissions without chmod, while directories created by the write
226
+ finish at `0o700`. Omission retains the existing parent-tightening default.
227
+
224
228
  ## External outputs
225
229
 
226
230
  Use `writeExternalFileWithinRoot()` when a browser download, renderer, media
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { assertDirectoryGuard, captureDirectoryGuard, } from "./directory-guard.js";
5
5
  import { FsSafeError } from "./errors.js";
6
6
  import { pathExists } from "./fs.js";
7
- import { realpathSync } from "./realpath.js";
7
+ import { realpathNative, realpathSync } from "./realpath.js";
8
8
  import { resolveRootPath } from "./root-path.js";
9
9
  import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
10
10
  function resolveSymlinkPolicy(policy) {
@@ -263,7 +263,7 @@ export async function resolveAbsolutePathForRead(filePath, options = {}) {
263
263
  const normalized = assertAbsolutePathInput(filePath);
264
264
  let canonicalPath;
265
265
  try {
266
- canonicalPath = realpathSync.native(pathForWindowsFilesystem(normalized));
266
+ canonicalPath = await realpathNative(pathForWindowsFilesystem(normalized));
267
267
  assertNoWindowsPathAlias(canonicalPath);
268
268
  }
269
269
  catch (err) {
@@ -3,9 +3,9 @@ export { createAsyncLock } from "./async-lock.js";
3
3
  export { createDirectory, createDirectorySync, createFileSync, type CreateDirectoryOptions, type CreateFileOptions, type OwnedFileDescriptorSync, } from "./create.js";
4
4
  export { copyFileHandle, copyFileDescriptorSync, type CopyFileHandleOptions } from "./file-handle-transfer.js";
5
5
  export { sameFileContentsSync, type SameFileContentsOptions } from "./file-contents.js";
6
- export { overwriteFileHandle, type OverwriteFileHandleOptions } from "./overwrite-file-handle.js";
6
+ export { overwriteFileHandle, overwriteFileHandleWithAuthority, type OverwriteFileHandleOptions } from "./overwrite-file-handle.js";
7
7
  export { probePathCaseInsensitiveSync, type ProbePathCaseOptions } from "./path-case.js";
8
- export { resolvePathPrefixSync, type ResolvedPathPrefix } from "./path-prefix.js";
8
+ export { resolvePathPrefix, resolvePathPrefixSync, type ResolvedPathPrefix } from "./path-prefix.js";
9
9
  export { probePathSuffixAliasesSync, type ProbePathSuffixAliasesOptions } from "./path-suffix-aliases.js";
10
10
  export { readDirectoryIdentity, assertDirectoryIdentitySync, type DirectoryIdentity, } from "./directory-guard.js";
11
11
  export { stageFileInDirectory, } from "./native-staged-file.js";
@@ -6,9 +6,9 @@ export { createAsyncLock } from "./async-lock.js";
6
6
  export { createDirectory, createDirectorySync, createFileSync, } from "./create.js";
7
7
  export { copyFileHandle, copyFileDescriptorSync } from "./file-handle-transfer.js";
8
8
  export { sameFileContentsSync } from "./file-contents.js";
9
- export { overwriteFileHandle } from "./overwrite-file-handle.js";
9
+ export { overwriteFileHandle, overwriteFileHandleWithAuthority } from "./overwrite-file-handle.js";
10
10
  export { probePathCaseInsensitiveSync } from "./path-case.js";
11
- export { resolvePathPrefixSync } from "./path-prefix.js";
11
+ export { resolvePathPrefix, resolvePathPrefixSync } from "./path-prefix.js";
12
12
  export { probePathSuffixAliasesSync } from "./path-suffix-aliases.js";
13
13
  export { readDirectoryIdentity, assertDirectoryIdentitySync, } from "./directory-guard.js";
14
14
  export { stageFileInDirectory, } from "./native-staged-file.js";
@@ -22,6 +22,7 @@ export declare class AtomicIo {
22
22
  lstat(pathname: string): Procedure<Stats>;
23
23
  lstatExact(pathname: string, synchronousBuiltin?: boolean): BigIntStats | Promise<BigIntStats>;
24
24
  mkdir(directory: string, mode: number): Procedure<void>;
25
+ mkdirExclusive(directory: string, mode: number): Procedure<void>;
25
26
  rename(source: string, destination: string): Procedure<void>;
26
27
  remove(pathname: string): Procedure<void>;
27
28
  unlink(pathname: string): Procedure<void>;
@@ -115,6 +115,12 @@ export class AtomicIo {
115
115
  this.syncFs.mkdirSync(pathname, { recursive: true, mode });
116
116
  }
117
117
  }
118
+ *mkdirExclusive(directory, mode) {
119
+ if (this.asyncFs)
120
+ yield* wait(this.asyncFs.mkdir(directory, { recursive: false, mode }));
121
+ else
122
+ this.syncFs.mkdirSync(directory, { recursive: false, mode });
123
+ }
118
124
  *rename(source, destination) {
119
125
  if (this.asyncFs)
120
126
  yield* wait(this.asyncFs.rename(source, destination));
@@ -1,5 +1,6 @@
1
1
  export { replaceFileAtomic, replaceFileAtomicSync, type ReplaceFileAtomicFileSystem, type ReplaceFileAtomicOptions, type ReplaceFileAtomicResult, type ReplaceFileAtomicDestinationState, type ReplaceFileAtomicSyncFileSystem, type ReplaceFileAtomicSyncOptions, } from "./replace-file.js";
2
2
  export type { RenameIdentityPolicy } from "./pinned-write-types.js";
3
+ export type { DirectoryMode } from "./directory-mode-options.js";
3
4
  export type { ReplaceFileAtomicRestoreCleanup, ReplaceFileAtomicRestoreFailureDetails, ReplaceFileCopyFallbackRestorePolicy, ReplaceFileDestinationHardlinkPolicy, } from "./replace-file-copy-fallback.js";
4
5
  export { writeTextAtomic, type WriteTextAtomicOptions } from "./text-atomic.js";
5
6
  export { replaceDirectoryAtomic, type ReplaceDirectoryAtomicOptions } from "./replace-directory.js";
@@ -10,6 +10,11 @@ export type DirectoryModeOwner = {
10
10
  close(): Promise<void>;
11
11
  };
12
12
  export declare function assertOwnedDirectory(expected: Stats | BigIntStats, actual: Stats | BigIntStats): void;
13
+ /** The caller retains a verified native mkdir receipt and owns the descriptor lifetime. */
14
+ export declare function finalizeCreatedDirectoryModeSync(child: {
15
+ fd: number;
16
+ created: boolean;
17
+ }, mode: number | undefined): void;
13
18
  /** Serializes use and close: even a queued path-based fd operation retains its descriptor. */
14
19
  export declare function ownDirectoryMode(params: {
15
20
  inspect: () => Promise<number>;
@@ -14,6 +14,19 @@ export function assertOwnedDirectory(expected, actual) {
14
14
  throw new FsSafeError("path-mismatch", "directory changed before its mode could be applied");
15
15
  }
16
16
  }
17
+ /** The caller retains a verified native mkdir receipt and owns the descriptor lifetime. */
18
+ export function finalizeCreatedDirectoryModeSync(child, mode) {
19
+ if (mode === undefined || !child.created || process.platform === "win32")
20
+ return;
21
+ const expected = inspectFileIdentitySync(() => fsSync.fstatSync(child.fd, { bigint: true }));
22
+ assertOwnedDirectory(expected, expected);
23
+ fsSync.fchmodSync(child.fd, mode & 0o7777);
24
+ const finalized = inspectFileIdentitySync(() => fsSync.fstatSync(child.fd, { bigint: true }), expected);
25
+ assertOwnedDirectory(expected, finalized);
26
+ if ((finalized.mode & 4095n) !== BigInt(mode & 0o7777)) {
27
+ throw new FsSafeError("path-mismatch", "created directory mode could not be finalized");
28
+ }
29
+ }
17
30
  /** Serializes use and close: even a queued path-based fd operation retains its descriptor. */
18
31
  export function ownDirectoryMode(params) {
19
32
  let pending = Promise.resolve();
@@ -0,0 +1,3 @@
1
+ /** Preserve verified existing directories; finalize exclusively created directories at 0700. */
2
+ export type DirectoryMode = number | "preserve";
3
+ export declare function rejectPrivateDirectoryPreservation(mode: DirectoryMode | undefined): asserts mode is number | undefined;
@@ -0,0 +1,6 @@
1
+ import { FsSafeError } from "./errors.js";
2
+ export function rejectPrivateDirectoryPreservation(mode) {
3
+ if (mode === "preserve") {
4
+ throw new FsSafeError("invalid-path", "Private directories require an explicit numeric dirMode; preservation is not supported.");
5
+ }
6
+ }
@@ -1,7 +1,7 @@
1
1
  export type FsSafeErrorCode = (typeof OPERATIONAL_CODE_VALUES)[number] | "already-exists" | "denied-path" | "device-path" | "hardlink" | "invalid-path" | "insecure-permissions" | "not-file" | "not-owned" | "outside-workspace" | "path-alias" | "path-mismatch" | "secret-exists" | "store-reentrant-update" | "symlink" | "too-large";
2
2
  export type FsSafeErrorCategory = "policy" | "operational";
3
3
  export type FsSafeErrorDetails = Readonly<Record<string, unknown>>;
4
- declare const OPERATIONAL_CODE_VALUES: readonly ["helper-failed", "helper-unavailable", "not-empty", "not-found", "not-removable", "permission-unverified", "read-failed", "timeout", "unsupported-platform"];
4
+ declare const OPERATIONAL_CODE_VALUES: readonly ["helper-failed", "helper-unavailable", "not-empty", "not-found", "not-removable", "permission-denied", "permission-unverified", "read-failed", "timeout", "unsupported-platform"];
5
5
  export declare function categorizeFsSafeError(code: FsSafeErrorCode): FsSafeErrorCategory;
6
6
  export declare class FsSafeError extends Error {
7
7
  readonly code: FsSafeErrorCode;
@@ -4,6 +4,7 @@ const OPERATIONAL_CODE_VALUES = [
4
4
  "not-empty",
5
5
  "not-found",
6
6
  "not-removable",
7
+ "permission-denied",
7
8
  "permission-unverified",
8
9
  "read-failed",
9
10
  "timeout",
@@ -12,6 +12,5 @@ export type SyncHeldLock = {
12
12
  export declare function foreignSyncHeldLock(route: "raw" | "root", target: string): object | undefined;
13
13
  export declare function getSyncHeldLocks(): Map<string, SyncHeldLock>;
14
14
  export declare function getSyncLockAdmissions(): Map<string, object>;
15
- export declare function defaultSyncShouldReclaim(snapshot: SidecarLockSnapshot, staleMs: number, nowMs: number): boolean;
16
15
  export declare function syncReclaimGuardExists(reclaimGuardPath: string): boolean;
17
16
  export declare function ensureSyncLockExitCleanupRegistered(cleanup: () => void, lockPath: string, normalizedTargetPath: string): void;
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { sidecarLockPayloadCreatedAtMs, sidecarLockTimeout } from "./sidecar-lock-policy.js";
2
+ import { sidecarLockTimeout } from "./sidecar-lock-policy.js";
3
3
  import { ensureSidecarLockCleanupRegistered } from "./sidecar-lock-registration.js";
4
4
  const SYNC_HELD_LOCKS_KEY = Symbol.for("fsSafe.syncSidecarLocks");
5
5
  const SYNC_ADMISSIONS_KEY = Symbol.for("fsSafe.syncSidecarLockAdmissions");
@@ -26,16 +26,6 @@ export function getSyncLockAdmissions() {
26
26
  }
27
27
  return globalWithState[SYNC_ADMISSIONS_KEY];
28
28
  }
29
- export function defaultSyncShouldReclaim(snapshot, staleMs, nowMs) {
30
- const createdAtMs = sidecarLockPayloadCreatedAtMs(snapshot.payload);
31
- if (createdAtMs !== null)
32
- return nowMs - createdAtMs > staleMs;
33
- if (!snapshot.stat)
34
- return true;
35
- const mtimeMs = "mtimeNs" in snapshot.stat
36
- ? Number(snapshot.stat.mtimeNs) / 1e6 : snapshot.stat.mtimeMs;
37
- return nowMs - mtimeMs > staleMs;
38
- }
39
29
  export function syncReclaimGuardExists(reclaimGuardPath) {
40
30
  try {
41
31
  return fs.lstatSync(reclaimGuardPath, { throwIfNoEntry: false }) !== undefined;
@@ -2,8 +2,8 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { FsSafeError } from "./errors.js";
4
4
  import { captureRootSyncAcquireOptions } from "./file-lock-sync-root-options.js";
5
- import { defaultSyncShouldReclaim, foreignSyncHeldLock } from "./file-lock-sync-admission.js";
6
- import { isTransientLockFileDenial, sidecarLockStale } from "./sidecar-lock-policy.js";
5
+ import { foreignSyncHeldLock } from "./file-lock-sync-admission.js";
6
+ import { defaultSidecarLockShouldReclaim, isTransientLockFileDenial, sidecarLockStale } from "./sidecar-lock-policy.js";
7
7
  import { serializeSidecarLockPayload, } from "./sidecar-lock-reclaim.js";
8
8
  import { createSuppressedError } from "./suppressed-error.js";
9
9
  import { SyncLockAcquisition } from "./file-lock-sync-acquisition.js";
@@ -287,7 +287,7 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
287
287
  }
288
288
  }
289
289
  else {
290
- reclaim = defaultSyncShouldReclaim(snapshot, options.staleMs, nowMs);
290
+ reclaim = defaultSidecarLockShouldReclaim(snapshot, options.staleMs, nowMs);
291
291
  }
292
292
  if (reclaim) {
293
293
  if (options.staleRecovery === "remove-if-unchanged" &&
@@ -1,8 +1,7 @@
1
1
  import fs from "node:fs";
2
- import { defaultSyncShouldReclaim } from "./file-lock-sync-admission.js";
3
2
  import { parseSidecarLockSnapshot, readSidecarLockRawSnapshotSync, removeSidecarLockIfUnchangedSync, } from "./sidecar-lock-reclaim.js";
4
3
  import { assertSynchronousCallbackResult } from "./mutation-authority.js";
5
- import { sidecarLockStale } from "./sidecar-lock-policy.js";
4
+ import { defaultSidecarLockShouldReclaim, sidecarLockStale } from "./sidecar-lock-policy.js";
6
5
  /** Handle one exclusive-create conflict without surrendering canonical admission. */
7
6
  export function handleSyncStaleAdmission(acquisition, params) {
8
7
  const holderChanged = {};
@@ -109,7 +108,7 @@ export function handleSyncStaleAdmission(acquisition, params) {
109
108
  nowMs,
110
109
  heldByThisProcess: false,
111
110
  }])
112
- : defaultSyncShouldReclaim(snapshot, params.staleMs, nowMs);
111
+ : defaultSidecarLockShouldReclaim(snapshot, params.staleMs, nowMs);
113
112
  assertSynchronousCallbackResult(reclaim, "shouldReclaim");
114
113
  }
115
114
  finally {
@@ -3,10 +3,10 @@ import { ensureSyncStoreDirectory, type SyncStoreDirectoryReceipt } from "./file
3
3
  import { type Root } from "./root.js";
4
4
  import { prepareSecretFileWrite } from "./secret-file.js";
5
5
  export type SyncParentGuard = SyncStoreDirectoryReceipt;
6
- export declare function ensureParentInRoot(scopedRoot: Root, relativePath: string, mode: number): Promise<void>;
6
+ export declare function ensureParentInRoot(scopedRoot: Root, relativePath: string, mode: number | "preserve"): Promise<void>;
7
7
  export declare function openWritableStoreRoot(params: {
8
8
  rootDir: string;
9
- dirMode: number;
9
+ dirMode: number | "preserve";
10
10
  maxBytes?: number;
11
11
  }): Promise<Root>;
12
12
  export declare function openPrivateStoreLockRoot(params: Parameters<typeof prepareSecretFileWrite>[0]): Promise<Root>;
@@ -21,7 +21,7 @@ export declare function writeStreamToTempSource(params: {
21
21
  export declare function ensureParentSync(params: {
22
22
  rootDir: string;
23
23
  filePath: string;
24
- mode: number;
24
+ mode: number | "preserve";
25
25
  }): SyncParentGuard;
26
26
  export declare function ensureStoreDirectorySync(params: Parameters<typeof ensureSyncStoreDirectory>[0]): SyncParentGuard;
27
27
  export declare function literalStoreRootPath(relativePath: string): string;
@@ -11,6 +11,13 @@ import { rootFromDirectoryGuard } from "./root-impl.js";
11
11
  import { prepareSecretFileWrite } from "./secret-file.js";
12
12
  import { resolveSecureTempRoot } from "./secure-temp-dir.js";
13
13
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
14
+ import { AtomicIo, runAsync } from "./atomic-io.js";
15
+ import { prepareDirectoryMode } from "./prepare-directory-mode.js";
16
+ import { mkdirPathComponentsWithGuards } from "./guarded-mkdir.js";
17
+ import { rootHandleContext } from "./root-handle-context.js";
18
+ import { isFsSafeNativeRequired } from "./native-config.js";
19
+ import { tryMkdirNativeDirectChild } from "./root-create-native.js";
20
+ import { tryMkdirNativeParents } from "./root-mkdir-native.js";
14
21
  import { readRegularFile } from "./regular-file.js";
15
22
  import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
16
23
  import { errorCauseOptions } from "./root-errors.js";
@@ -20,13 +27,32 @@ export async function ensureParentInRoot(scopedRoot, relativePath, mode) {
20
27
  if (parent === ".") {
21
28
  return;
22
29
  }
23
- await scopedRoot.mkdir(parent);
24
- await chmodDirectoryInRootBestEffort(scopedRoot, parent, mode).catch(() => undefined);
30
+ if (mode === "preserve") {
31
+ const context = rootHandleContext(scopedRoot);
32
+ const relativeParent = path.posix.dirname(relativePath);
33
+ if (isFsSafeNativeRequired() && (tryMkdirNativeDirectChild(context, relativeParent, 0o700) ||
34
+ tryMkdirNativeParents(context, relativeParent, 0o700)))
35
+ return;
36
+ await mkdirPathComponentsWithGuards({
37
+ rootReal: context.rootReal, rootIdentity: context.rootIdentity,
38
+ targetPath: path.join(context.rootReal, parent),
39
+ mode: 0o700, finalizeCreatedMode: true, rejectSymlinks: true,
40
+ });
41
+ }
42
+ else {
43
+ await scopedRoot.mkdir(parent);
44
+ await chmodDirectoryInRootBestEffort(scopedRoot, parent, mode).catch(() => undefined);
45
+ }
25
46
  }
26
47
  export async function openWritableStoreRoot(params) {
27
48
  assertNoWindowsPathAlias(params.rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
28
- await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
29
- await fs.chmod(params.rootDir, params.dirMode).catch(() => undefined);
49
+ if (params.dirMode === "preserve") {
50
+ await runAsync(prepareDirectoryMode(AtomicIo.async(fs), { dirPath: params.rootDir, mode: "preserve" }));
51
+ }
52
+ else {
53
+ await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
54
+ await fs.chmod(params.rootDir, params.dirMode).catch(() => undefined);
55
+ }
30
56
  return await root(params.rootDir, { hardlinks: "reject", maxBytes: params.maxBytes });
31
57
  }
32
58
  export async function openPrivateStoreLockRoot(params) {
@@ -6,6 +6,6 @@ export type FileStorePruneOptions = {
6
6
  };
7
7
  export declare function pruneExpiredStoreEntries(params: {
8
8
  rootDir: string;
9
- dirMode: number;
9
+ dirMode: number | "preserve";
10
10
  options: FileStorePruneOptions;
11
11
  }): Promise<void>;
@@ -6,6 +6,8 @@ import { literalStoreRootPath } from "./file-store-boundary.js";
6
6
  import { isPathInside } from "./path.js";
7
7
  import { realpathSync } from "./realpath.js";
8
8
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
9
+ import { AtomicIo, runAsync } from "./atomic-io.js";
10
+ import { prepareDirectoryMode } from "./prepare-directory-mode.js";
9
11
  import { root } from "./root.js";
10
12
  import { nonrecursiveRemovalKind } from "./root-remove.js";
11
13
  import { getFsSafeTestHooks } from "./test-hooks.js";
@@ -17,7 +19,11 @@ export async function pruneExpiredStoreEntries(params) {
17
19
  const recursive = params.options.recursive ?? false;
18
20
  const maxDepth = params.options.maxDepth;
19
21
  const pruneEmptyDirs = (recursive || maxDepth !== undefined) && (params.options.pruneEmptyDirs ?? false);
20
- await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
22
+ if (params.dirMode === "preserve") {
23
+ await runAsync(prepareDirectoryMode(AtomicIo.async(fs), { dirPath: params.rootDir, mode: "preserve" }));
24
+ }
25
+ else
26
+ await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
21
27
  const rootReal = realpathSync.native(params.rootDir);
22
28
  const scopedRoot = await root(rootReal);
23
29
  const rootGuard = {
@@ -8,7 +8,7 @@ export type SyncStoreDirectoryReceipt = Readonly<{
8
8
  export declare function ensureSyncStoreDirectory(params: {
9
9
  rootDir: string;
10
10
  targetDir: string;
11
- mode: number;
11
+ mode: number | "preserve";
12
12
  messagePrefix: StoreMessagePrefix;
13
13
  }): SyncStoreDirectoryReceipt;
14
14
  export declare function assertSyncStoreDirectoryReceipt(receipt: SyncStoreDirectoryReceipt): void;
@@ -4,6 +4,9 @@ import { FsSafeError } from "./errors.js";
4
4
  import { isPathInside, isPathRelativeEscape } from "./path.js";
5
5
  import { realpathSync } from "./realpath.js";
6
6
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
7
+ import { AtomicIo, runSync } from "./atomic-io.js";
8
+ import { prepareDirectoryMode } from "./prepare-directory-mode.js";
9
+ import { applyDirectoryMode } from "./replace-file-descriptor.js";
7
10
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
8
11
  import { createSuppressedError } from "./suppressed-error.js";
9
12
  import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
@@ -212,6 +215,14 @@ class StoreDirectoryChain {
212
215
  throw changedStoreDirectory(this.messagePrefix, error);
213
216
  }
214
217
  }
218
+ preserveMode() {
219
+ const receipt = this.receipts.at(-1);
220
+ this.assertEdge();
221
+ runSync(applyDirectoryMode(AtomicIo.sync(fs), {
222
+ dirPath: pathForWindowsFilesystem(receipt.dir), mode: "preserve", expectedIdentity: receipt.stat,
223
+ }));
224
+ this.assertEdge();
225
+ }
215
226
  finalizeMode(mode) {
216
227
  const receipt = this.receipts.at(-1);
217
228
  const requestedMode = BigInt(mode & 0o7777);
@@ -274,9 +285,18 @@ export function ensureSyncStoreDirectory(params) {
274
285
  if (isPathRelativeEscape(relative)) {
275
286
  throw new FsSafeError("outside-workspace", "file path escapes store root");
276
287
  }
277
- fs.mkdirSync(recursiveMkdirPath(pathForWindowsFilesystem(rootDir)), { recursive: true, mode: params.mode });
288
+ const preserve = (directory) => runSync(prepareDirectoryMode(AtomicIo.sync(fs, fs.fchmodSync), {
289
+ dirPath: pathForWindowsFilesystem(directory), mode: "preserve",
290
+ }));
291
+ if (params.mode === "preserve")
292
+ preserve(rootDir);
293
+ else
294
+ fs.mkdirSync(recursiveMkdirPath(pathForWindowsFilesystem(rootDir)), { recursive: true, mode: params.mode });
278
295
  const chain = new StoreDirectoryChain(rootDir, params.messagePrefix);
279
- chain.finalizeMode(params.mode);
296
+ if (params.mode === "preserve")
297
+ chain.preserveMode();
298
+ else
299
+ chain.finalizeMode(params.mode);
280
300
  let current = rootDir;
281
301
  for (const segment of relative.split(path.sep).filter(Boolean)) {
282
302
  current = path.join(current, segment);
@@ -286,10 +306,16 @@ export function ensureSyncStoreDirectory(params) {
286
306
  catch (error) {
287
307
  if (error.code !== "ENOENT")
288
308
  throw error;
289
- fs.mkdirSync(pathForWindowsFilesystem(current), { mode: params.mode });
309
+ if (params.mode === "preserve")
310
+ preserve(current);
311
+ else
312
+ fs.mkdirSync(pathForWindowsFilesystem(current), { mode: params.mode });
290
313
  chain.observe(current);
291
314
  }
292
- chain.finalizeMode(params.mode);
315
+ if (params.mode === "preserve")
316
+ chain.preserveMode();
317
+ else
318
+ chain.finalizeMode(params.mode);
293
319
  }
294
320
  return chain.finish(dir);
295
321
  }
@@ -4,6 +4,6 @@ export declare function writeFileSyncAtomic(params: {
4
4
  content: string | Uint8Array;
5
5
  privateMode: boolean;
6
6
  durable: boolean;
7
- dirMode: number;
7
+ dirMode: number | "preserve";
8
8
  mode: number;
9
9
  }): string;
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import fs, {} from "node:fs";
3
3
  import path from "node:path";
4
+ import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
4
5
  import { syncDirectorySync } from "./directory-durability.js";
5
6
  import { createDirectoryReceiptFromIdentity } from "./directory-receipt.js";
6
7
  import { FsSafeError } from "./errors.js";
@@ -50,6 +51,7 @@ export function writeFileSyncAtomic(params) {
50
51
  }
51
52
  let parentGuard;
52
53
  if (params.privateMode) {
54
+ rejectPrivateDirectoryPreservation(params.dirMode);
53
55
  parentGuard = ensureStoreDirectorySync({
54
56
  rootDir: params.rootDir,
55
57
  targetDir: path.dirname(filePath),
@@ -1,3 +1,4 @@
1
+ import { type DirectoryMode } from "./directory-mode-options.js";
1
2
  import type { Readable } from "node:stream";
2
3
  import { type FileStorePruneOptions } from "./file-store-prune.js";
3
4
  export type { FileStorePruneOptions } from "./file-store-prune.js";
@@ -8,7 +9,7 @@ export type FileStoreOptions = {
8
9
  private?: boolean;
9
10
  /** Default for writes, streams, and copies; true syncs file and parent where supported. */
10
11
  durable?: boolean;
11
- dirMode?: number;
12
+ dirMode?: DirectoryMode;
12
13
  mode?: number;
13
14
  maxBytes?: number;
14
15
  };
@@ -1,4 +1,5 @@
1
1
  import syncFs from "node:fs";
2
+ import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
2
3
  import { normalizeMaxBytes } from "./byte-budget.js";
3
4
  import { readFileDescriptorBoundedSync } from "./bounded-read.js";
4
5
  import { FsSafeError } from "./errors.js";
@@ -84,6 +85,8 @@ export function fileStore(options) {
84
85
  assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
85
86
  const privateMode = options.private ?? false;
86
87
  const dirMode = options.dirMode ?? 0o700;
88
+ if (privateMode)
89
+ rejectPrivateDirectoryPreservation(dirMode);
87
90
  const mode = options.mode ?? 0o600;
88
91
  const durable = options.durable ?? true;
89
92
  const maxBytes = normalizeMaxBytes(options.maxBytes);
@@ -289,6 +292,8 @@ export function fileStoreSync(options) {
289
292
  assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
290
293
  const privateMode = options.private ?? false;
291
294
  const dirMode = options.dirMode ?? 0o700;
295
+ if (privateMode)
296
+ rejectPrivateDirectoryPreservation(dirMode);
292
297
  const mode = options.mode ?? 0o600;
293
298
  const durable = options.durable ?? true;
294
299
  const maxBytes = normalizeMaxBytes(options.maxBytes);