@openclaw/matrix 2026.11.6 → 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 (148) hide show
  1. package/dist/.setup/{approval-handler.runtime-CshxBDs7.mjs → approval-handler.runtime-LBvkygUK.mjs} +3 -3
  2. package/dist/.setup/{channel-OLndtGNE.mjs → channel-CHryi9FS.mjs} +7 -7
  3. package/dist/.setup/{channel.runtime-CFSou_MS.mjs → channel.runtime-DluXWaGb.mjs} +2 -2
  4. package/dist/.setup/{channel.setup-CqcEb6JR.mjs → channel.setup-BDbs0FLq.mjs} +2 -2
  5. package/dist/.setup/{cli-CkMedN4Y.mjs → cli-C7Jmy2x4.mjs} +6 -6
  6. package/dist/.setup/{cli-metadata-DN1E7yCf.mjs → cli-metadata-B0GHIn05.mjs} +1 -1
  7. package/dist/.setup/{client-Rlwtz1hG.mjs → client-mFRVrUt3.mjs} +1 -1
  8. package/dist/.setup/{draft-stream-DbTsJkoL.mjs → draft-stream-bVedfEB3.mjs} +1 -1
  9. package/dist/.setup/{exec-approvals-CiGrN-cV.mjs → exec-approvals-BeYF9-3o.mjs} +2 -2
  10. package/dist/.setup/{messages-DJDczJnC.mjs → messages-BqVczVlt.mjs} +2 -2
  11. package/dist/.setup/{monitor-ZDbuZRVB.mjs → monitor-BsSo3tCv.mjs} +29 -15
  12. package/dist/.setup/{onboarding-DwhMV1fp.mjs → onboarding-CoMpgTiK.mjs} +1 -1
  13. package/dist/.setup/{outbound-7iSmOloX.mjs → outbound-ntm0KOfK.mjs} +2 -2
  14. package/dist/.setup/{profile-update-Fu4u-aSC.mjs → profile-update-gC436enW.mjs} +8 -3
  15. package/dist/.setup/{reaction-events-CBltCP52.mjs → reaction-events-DTThoaJQ.mjs} +3 -3
  16. package/dist/.setup/{room-info-DFDDmkBC.mjs → room-info-CM3MKoh4.mjs} +3 -3
  17. package/dist/.setup/{send-DiS4anyi.mjs → send-DFB7JGg2.mjs} +6 -6
  18. package/dist/.setup/{setup-bootstrap-OfuocnF0.mjs → setup-bootstrap-razh2kSp.mjs} +2 -2
  19. package/dist/.setup/{setup-core-CEQJRnym.mjs → setup-core-BVbxltMM.mjs} +1 -1
  20. package/dist/.setup/setup-plugin-api-CQKySg7F.mjs +2 -0
  21. package/dist/.setup/{thread-bindings-BvoisBZE.mjs → thread-bindings-D5VJEDZV.mjs} +1 -1
  22. package/dist/.setup/{tool-actions-TYBYDIkj.mjs → tool-actions-DexlmVDf.mjs} +9 -9
  23. package/dist/.setup/{verification-BhFA9xF6.mjs → verification-B122bsH2.mjs} +1 -1
  24. package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -1
  25. package/dist/api.js +4 -4
  26. package/dist/channel-plugin-api.js +1 -1
  27. package/dist/cli-metadata.js +1 -1
  28. package/dist/contract-api.js +2 -2
  29. package/dist/index.js +1 -1
  30. package/dist/plugin-entry.handlers.runtime.js +1 -1
  31. package/dist/session-binding-contract-api.js +1 -1
  32. package/dist/setup-entry.js +1 -1
  33. package/dist/setup-plugin-api.js +1 -1
  34. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +45 -1
  35. package/node_modules/@openclaw/fs-safe/README.md +4 -0
  36. package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +2 -2
  37. package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -2
  38. package/node_modules/@openclaw/fs-safe/dist/advanced.js +2 -2
  39. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  40. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  41. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +6 -0
  42. package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -0
  43. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +5 -0
  44. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +13 -0
  45. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.d.ts +3 -0
  46. package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.js +6 -0
  47. package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +1 -1
  48. package/node_modules/@openclaw/fs-safe/dist/errors.js +1 -0
  49. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.d.ts +0 -1
  50. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +1 -11
  51. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +3 -3
  52. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +2 -3
  53. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -3
  54. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +30 -4
  55. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.d.ts +1 -1
  56. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -1
  57. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.d.ts +1 -1
  58. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.js +30 -4
  59. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -1
  60. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +2 -0
  61. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  62. package/node_modules/@openclaw/fs-safe/dist/file-store.js +5 -0
  63. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +2 -0
  64. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +9 -0
  65. package/node_modules/@openclaw/fs-safe/dist/json-store.d.ts +2 -1
  66. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -1
  67. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +1 -1
  68. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
  69. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +19 -13
  70. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.d.ts +2 -0
  71. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +27 -5
  72. package/node_modules/@openclaw/fs-safe/dist/path-prefix.d.ts +1 -0
  73. package/node_modules/@openclaw/fs-safe/dist/path-prefix.js +84 -7
  74. package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +0 -11
  75. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +9 -0
  76. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +61 -0
  77. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -1
  78. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +2 -0
  79. package/node_modules/@openclaw/fs-safe/dist/realpath.js +16 -0
  80. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +2 -1
  81. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +8 -6
  82. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -1
  83. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +20 -13
  84. package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -1
  85. package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +1 -1
  86. package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +18 -9
  87. package/node_modules/@openclaw/fs-safe/dist/root-errors.d.ts +2 -0
  88. package/node_modules/@openclaw/fs-safe/dist/root-errors.js +9 -0
  89. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +4 -1
  90. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.d.ts +1 -1
  91. package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js +35 -16
  92. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.d.ts +6 -2
  93. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +32 -20
  94. package/node_modules/@openclaw/fs-safe/dist/root-path.js +32 -26
  95. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +4 -1
  96. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +2 -1
  97. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  98. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +2 -1
  99. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +5 -4
  100. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +3 -2
  101. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js +8 -9
  102. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +3 -1
  103. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +2 -1
  104. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
  105. package/node_modules/@openclaw/fs-safe/dist/types.d.ts +1 -0
  106. package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +12 -3
  107. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  108. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.d.ts +0 -1
  109. package/node_modules/@openclaw/fs-safe/dist/write-file-handle.js +10 -12
  110. package/node_modules/@openclaw/fs-safe/docs/advanced.md +3 -3
  111. package/node_modules/@openclaw/fs-safe/docs/atomic.md +16 -3
  112. package/node_modules/@openclaw/fs-safe/docs/compiler-qualification.md +1 -1
  113. package/node_modules/@openclaw/fs-safe/docs/contributing.md +27 -18
  114. package/node_modules/@openclaw/fs-safe/docs/errors.md +3 -1
  115. package/node_modules/@openclaw/fs-safe/docs/file-store.md +14 -2
  116. package/node_modules/@openclaw/fs-safe/docs/in-place-write.md +31 -0
  117. package/node_modules/@openclaw/fs-safe/docs/install.md +1 -1
  118. package/node_modules/@openclaw/fs-safe/docs/json-store.md +6 -1
  119. package/node_modules/@openclaw/fs-safe/docs/json.md +5 -1
  120. package/node_modules/@openclaw/fs-safe/docs/path-prefix.md +14 -4
  121. package/node_modules/@openclaw/fs-safe/docs/public-api.md +4 -2
  122. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -1
  123. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +4 -0
  124. package/node_modules/@openclaw/fs-safe/docs/temp.md +9 -1
  125. package/node_modules/@openclaw/fs-safe/docs/types.md +5 -1
  126. package/node_modules/@openclaw/fs-safe/package.json +12 -12
  127. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  128. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  129. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  130. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  131. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  132. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  133. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  134. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  135. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  136. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  137. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  138. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  139. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  140. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  141. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  142. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  143. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  144. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  145. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  146. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  147. package/package.json +5 -5
  148. package/dist/.setup/setup-plugin-api-4hHy1k4x.mjs +0 -2
@@ -0,0 +1,61 @@
1
+ import path from "node:path";
2
+ import { inspectAtomicIdentity } from "./atomic-io.js";
3
+ import { FsSafeError } from "./errors.js";
4
+ import { hasErrorCode } from "./file-cleanup.js";
5
+ import { applyDirectoryMode } from "./replace-file-descriptor.js";
6
+ /** Retain numeric compatibility; preservation distinguishes exclusive creation from EEXIST. */
7
+ export function* prepareDirectoryMode(io, params) {
8
+ if (params.mode !== "preserve") {
9
+ params.mutation?.assert();
10
+ yield* io.mkdir(params.dirPath, params.mode);
11
+ yield* applyDirectoryMode(io, params);
12
+ return;
13
+ }
14
+ const inspect = function* (expected) {
15
+ const observed = inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), expected, false, stat => {
16
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
17
+ throw new FsSafeError("not-file", `Atomic replace parent must be a real directory: ${params.dirPath}`);
18
+ }
19
+ });
20
+ return (io.asynchronous ? yield observed : observed);
21
+ };
22
+ let expectedIdentity;
23
+ let created = false;
24
+ try {
25
+ expectedIdentity = yield* inspect();
26
+ }
27
+ catch (error) {
28
+ if (!hasErrorCode(error, "ENOENT"))
29
+ throw error;
30
+ if (!io.asynchronous && !io.fchmodSync && process.platform !== "win32") {
31
+ throw new TypeError("fileSystem.fchmodSync is required to finalize a created directory with dirMode: preserve");
32
+ }
33
+ const parent = path.dirname(params.dirPath);
34
+ if (parent === params.dirPath)
35
+ throw error;
36
+ yield* prepareDirectoryMode(io, { ...params, dirPath: parent });
37
+ params.mutation?.assert();
38
+ try {
39
+ yield* io.mkdirExclusive(params.dirPath, 0o700);
40
+ created = true;
41
+ }
42
+ catch (mkdirError) {
43
+ if (!hasErrorCode(mkdirError, "EEXIST"))
44
+ throw mkdirError;
45
+ }
46
+ expectedIdentity = yield* inspect();
47
+ }
48
+ yield* applyDirectoryMode(io, {
49
+ ...params,
50
+ mode: created ? 0o700 : "preserve",
51
+ expectedIdentity,
52
+ // A successfully created directory must finish at 0700 even for best-effort callers.
53
+ ignoreChmodError: created ? false : params.ignoreChmodError,
54
+ });
55
+ if (created && process.platform !== "win32") {
56
+ const finalized = yield* inspect(expectedIdentity);
57
+ if ((finalized.mode & 4095n) !== 448n) {
58
+ throw new FsSafeError("path-mismatch", "created directory mode could not be finalized");
59
+ }
60
+ }
61
+ }
@@ -130,7 +130,8 @@ function throwTempWorkspaceOpenFailure(failure) {
130
130
  function tempWorkspaceSettings(options) {
131
131
  const rootDir = options.rootDir;
132
132
  assertNoWindowsPathAlias(rootDir, "filesystem", "temp workspace root uses a Windows filesystem namespace alias");
133
- const dirMode = options.dirMode ?? 0o700;
133
+ const requestedDirMode = options.dirMode;
134
+ const dirMode = requestedDirMode === "preserve" ? 0o700 : requestedDirMode ?? 0o700;
134
135
  validateTempWorkspaceDirMode(dirMode);
135
136
  const mode = options.mode ?? 0o600;
136
137
  const cleanupSafety = resolveTempWorkspaceCleanupSafety(options.cleanupSafety);
@@ -1,3 +1,5 @@
1
1
  export declare const realpathSync: ((input: string) => string) & {
2
2
  native: (input: string) => string;
3
3
  };
4
+ /** Async on Node; retain runtime-specific native canonicalization guarantees. */
5
+ export declare function realpathNative(input: string): Promise<string>;
@@ -1,4 +1,5 @@
1
1
  import fs from "node:fs";
2
+ import asyncFs from "node:fs/promises";
2
3
  import { platform } from "node:os";
3
4
  import { getSystemErrorName } from "node:util";
4
5
  import { FsSafeError } from "./errors.js";
@@ -73,3 +74,18 @@ function resolve(input, native) {
73
74
  export const realpathSync = Object.assign((input) => resolve(input, false), {
74
75
  native: (input) => resolve(input, true),
75
76
  });
77
+ /** Async on Node; retain runtime-specific native canonicalization guarantees. */
78
+ export async function realpathNative(input) {
79
+ if (bunPosix)
80
+ return realpathSync.native(input);
81
+ try {
82
+ return await asyncFs.realpath(input);
83
+ }
84
+ catch (error) {
85
+ if (process.platform !== "win32" || error.code !== "EPERM" ||
86
+ error.syscall !== "realpath")
87
+ throw error;
88
+ // AppContainer DOS-name translation still belongs to the native sync owner.
89
+ return realpathSync.native(input);
90
+ }
91
+ }
@@ -4,7 +4,8 @@ import { type AtomicFile, type AtomicIo, type Procedure } from "./atomic-io.js";
4
4
  export declare function syncDirectoryBestEffort(io: AtomicIo, dirPath: string): Procedure<void>;
5
5
  export declare function applyDirectoryMode(io: AtomicIo, params: {
6
6
  dirPath: string;
7
- mode: number;
7
+ mode: number | "preserve";
8
+ expectedIdentity?: BigIntStats;
8
9
  ignoreChmodError?: boolean;
9
10
  mutation?: AtomicMutation;
10
11
  }): Procedure<void>;
@@ -46,9 +46,9 @@ async function pinDirectoryForMode(params) {
46
46
  if (process.platform === "win32") {
47
47
  return;
48
48
  }
49
- const expected = params.fsModule === fs
49
+ const expected = params.expectedIdentity ?? (params.fsModule === fs
50
50
  ? inspectFileIdentitySync(() => assertDirectory(syncFs.lstatSync(params.dirPath, { bigint: true }), params.dirPath))
51
- : await inspectFileIdentity(async () => assertDirectory(await params.fsModule.lstat(params.dirPath, { bigint: true }), params.dirPath));
51
+ : await inspectFileIdentity(async () => assertDirectory(await params.fsModule.lstat(params.dirPath, { bigint: true }), params.dirPath)));
52
52
  const handle = await params.fsModule.open(params.dirPath, directoryOpenFlags());
53
53
  try {
54
54
  const owner = ownDirectoryMode({
@@ -86,7 +86,7 @@ export function* applyDirectoryMode(io, params) {
86
86
  }));
87
87
  let primary;
88
88
  try {
89
- if (owner)
89
+ if (owner && params.mode !== "preserve")
90
90
  yield* wait(owner.apply(params.mode));
91
91
  }
92
92
  catch (error) {
@@ -107,13 +107,15 @@ export function* applyDirectoryMode(io, params) {
107
107
  if (process.platform === "win32")
108
108
  return;
109
109
  const admit = (stat) => assertDirectory(stat, params.dirPath);
110
- const expected = inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), undefined, false, admit);
110
+ const expected = params.expectedIdentity ?? inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), undefined, false, admit);
111
111
  const file = yield* io.open(params.dirPath, directoryOpenFlags());
112
112
  let primary;
113
113
  try {
114
114
  inspectAtomicIdentity(io, () => file.statExact(), expected, false, admit);
115
- params.mutation?.assert();
116
- file.chmod(params.mode & 0o7777);
115
+ if (params.mode !== "preserve") {
116
+ params.mutation?.assert();
117
+ file.chmod(params.mode & 0o7777);
118
+ }
117
119
  }
118
120
  catch (error) {
119
121
  primary = { error };
@@ -1,4 +1,5 @@
1
1
  import type syncFs from "node:fs";
2
+ import type { DirectoryMode } from "./directory-mode-options.js";
2
3
  import type fs from "node:fs/promises";
3
4
  import type { RenameIdentityPolicy } from "./pinned-write-types.js";
4
5
  import type { AtomicMutationOptions } from "./replace-file-mutation.js";
@@ -12,7 +13,7 @@ export type ReplaceFileAtomicSyncFileSystem = Pick<typeof syncFs, "mkdirSync" |
12
13
  export type ReplaceFileAtomicBaseOptions = AtomicMutationOptions & {
13
14
  filePath: string;
14
15
  content: string | Uint8Array;
15
- dirMode?: number;
16
+ dirMode?: DirectoryMode;
16
17
  mode?: number;
17
18
  /** Inherit only rwx bits from an existing non-symlink regular file. */
18
19
  preserveExistingMode?: boolean;
@@ -4,7 +4,8 @@ import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
6
6
  import { assertDestinationHardlinkPolicy, copyFallbackReplace } from "./replace-file-copy-fallback.js";
7
- import { applyDirectoryMode, syncDirectoryBestEffort, writeTempFile } from "./replace-file-descriptor.js";
7
+ import { syncDirectoryBestEffort, writeTempFile } from "./replace-file-descriptor.js";
8
+ import { prepareDirectoryMode } from "./prepare-directory-mode.js";
8
9
  import { inheritedRegularFileMode } from "./replace-file-mode.js";
9
10
  import { atomicExpectedContentHash, validateRenameIdentity, withAtomicRenameIdentityLock, withAtomicRenameIdentityLockSync, } from "./replace-file-rename-policy.js";
10
11
  import { AtomicTempOwner } from "./replace-file-temp-owner.js";
@@ -109,10 +110,14 @@ export async function replaceFileAtomicWithDirectorySync(options, syncParent) {
109
110
  const fsModule = options.fileSystem?.promises ?? fs;
110
111
  const dir = path.dirname(filePath);
111
112
  mutation.assert();
112
- await fsModule.mkdir(fsModule === fs ? recursiveMkdirPath(dir) : dir, {
113
- recursive: true,
114
- mode: options.dirMode ?? 0o700,
115
- });
113
+ const dirMode = options.dirMode ?? 0o700;
114
+ if (dirMode === "preserve") {
115
+ await runAsync(prepareDirectoryMode(AtomicIo.async(fsModule), { dirPath: dir, mode: "preserve", mutation }));
116
+ }
117
+ else
118
+ await fsModule.mkdir(fsModule === fs ? recursiveMkdirPath(dir) : dir, {
119
+ recursive: true, mode: dirMode,
120
+ });
116
121
  mutation.assert();
117
122
  return await withAtomicRenameIdentityLock(filePath, () => replaceAsync(options, filePath, renameIdentity, mutation, syncParent));
118
123
  });
@@ -132,10 +137,14 @@ export function replaceFileAtomicSync(options) {
132
137
  const fsModule = options.fileSystem ?? syncFs;
133
138
  const dir = path.dirname(filePath);
134
139
  mutation.assert();
135
- fsModule.mkdirSync(fsModule === syncFs ? recursiveMkdirPath(dir) : dir, {
136
- recursive: true,
137
- mode: options.dirMode ?? 0o700,
138
- });
140
+ const dirMode = options.dirMode ?? 0o700;
141
+ if (dirMode === "preserve") {
142
+ runSync(prepareDirectoryMode(AtomicIo.sync(fsModule, fsModule.fchmodSync), { dirPath: dir, mode: "preserve", mutation }));
143
+ }
144
+ else
145
+ fsModule.mkdirSync(fsModule === syncFs ? recursiveMkdirPath(dir) : dir, {
146
+ recursive: true, mode: dirMode,
147
+ });
139
148
  mutation.assert();
140
149
  return withAtomicRenameIdentityLockSync(filePath, () => replaceSync(options, filePath, renameIdentity, mutation));
141
150
  }
@@ -151,7 +160,7 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
151
160
  const syncOptions = options;
152
161
  io.fchmodSync = syncOptions.fileSystem?.fchmodSync ?? (syncOptions.fileSystem === undefined ? syncFs.fchmodSync : undefined);
153
162
  if (!io.fchmodSync && (options.mode !== undefined || options.preserveExistingMode === true ||
154
- (process.platform !== "win32" && options.dirMode !== undefined))) {
163
+ (process.platform !== "win32" && typeof options.dirMode === "number"))) {
155
164
  throw new TypeError("fileSystem.fchmodSync is required when mode, dirMode, or preserveExistingMode is specified");
156
165
  }
157
166
  }
@@ -159,9 +168,7 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
159
168
  const tempOwner = new AtomicTempOwner(tempPath, io);
160
169
  let originalFailure;
161
170
  try {
162
- mutation.assert();
163
- yield* io.mkdir(dir, dirMode);
164
- yield* applyDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation });
171
+ yield* prepareDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation });
165
172
  tempOwner.start();
166
173
  tempOwner.adopt(yield* writeTempFile(io, {
167
174
  tempPath,
@@ -6,7 +6,7 @@ import { FsSafeError } from "./errors.js";
6
6
  import { assertNoNulPathInput, assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isPathInside, } from "./path.js";
7
7
  import { ROOT_PATH_ALIAS_POLICIES, resolveRootPath } from "./root-path.js";
8
8
  import { admitPathInsideRoot } from "./root-boundary.js";
9
- import { errorCauseOptions, outsideWorkspaceError, rootPathChangedError } from "./root-errors.js";
9
+ import { errorCauseOptions, outsideWorkspaceError, pathTraversalPermissionError, rootPathChangedError } from "./root-errors.js";
10
10
  import { isDriveRelativePath } from "./safe-path-segment.js";
11
11
  import { realpathSync } from "./realpath.js";
12
12
  import { inspectFileIdentity } from "./strict-file-identity.js";
@@ -205,6 +205,9 @@ export async function resolvePathInRoot(root, relativePath, options) {
205
205
  }
206
206
  }
207
207
  catch (error) {
208
+ const permissionError = pathTraversalPermissionError(error, rawAbsolutePath);
209
+ if (permissionError)
210
+ throw permissionError;
208
211
  if (error instanceof FsSafeError && error.code === "symlink") {
209
212
  throw error;
210
213
  }
@@ -32,7 +32,7 @@ export type MissingWritableFileInRoot = {
32
32
  };
33
33
  export declare function isNativeCreateCollision(error: unknown): boolean;
34
34
  /** Admit only an ordinary direct child; aliases keep the full resolver. */
35
- export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string): boolean;
35
+ export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string, mode?: number): boolean;
36
36
  export declare function tryMkdirRootNative(params: Creation): Promise<boolean>;
37
37
  export declare function verifyMkdirDirectory(binding: NativeBinding, fd: number, pathname: string): void;
38
38
  export declare function ensureNativeRootCurrent(root: RootContext): void;
@@ -56,7 +56,7 @@ import { randomUUID } from "node:crypto";
56
56
  import fsAsync from "node:fs/promises";
57
57
  import path from "node:path";
58
58
  import { assertSyncDirectoryGuard, inspectDirectoryIdentitySync } from "./directory-guard.js";
59
- import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
59
+ import { finalizeCreatedDirectoryModeSync, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
60
60
  import { assertDarwinCreationAcl, assertPrivateDirectory } from "./creation-boundary.js";
61
61
  import { assertMutationNotDenied } from "./deny-mutations.js";
62
62
  import { FsSafeError } from "./errors.js";
@@ -295,7 +295,7 @@ async function withNativeDirectory(params, operation, discard) {
295
295
  }
296
296
  }
297
297
  /** Admit only an ordinary direct child; aliases keep the full resolver. */
298
- export function tryMkdirNativeDirectChild(root, relativePath) {
298
+ export function tryMkdirNativeDirectChild(root, relativePath, mode) {
299
299
  if (!isSafePathSegment(relativePath, { allowDotPrefix: true }) || relativePath.endsWith(".") ||
300
300
  getFsSafeTestHooks()?.beforeRootFallbackMutation)
301
301
  return false;
@@ -311,7 +311,7 @@ export function tryMkdirNativeDirectChild(root, relativePath) {
311
311
  return false;
312
312
  }
313
313
  try {
314
- mkdirNativeRootChild({ root, target });
314
+ mkdirNativeRootChild({ root, target }, mode);
315
315
  return true;
316
316
  }
317
317
  catch (error) {
@@ -420,7 +420,7 @@ function ensureNativeRootCurrentLegacy(root, binding) {
420
420
  __disposeResources(env_4);
421
421
  }
422
422
  }
423
- function mkdirNativeRootChild(params) {
423
+ function mkdirNativeRootChild(params, mode) {
424
424
  const env_5 = { stack: [], error: void 0, hasError: false };
425
425
  try {
426
426
  const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
@@ -430,19 +430,28 @@ function mkdirNativeRootChild(params) {
430
430
  rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
431
431
  }), false);
432
432
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
433
- const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
433
+ const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
434
434
  (fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
435
435
  const name = path.basename(params.target);
436
436
  // The admitted Root is already this operation's immediate parent. Retain
437
437
  // both handles through the same fresh pathname and canonical identity fences.
438
438
  const child = binding.mkdirOpenChildBeneath
439
- ? binding.mkdirOpenChildBeneath(rootOwner.fd, name, 0o777, flags).fd
440
- : (binding.mkdirChildBeneath(rootOwner.fd, name, 0o777), binding.openBeneath(rootOwner.fd, name, flags).fd);
439
+ ? binding.mkdirOpenChildBeneath(rootOwner.fd, name, mode ?? 0o777, flags)
440
+ : {
441
+ created: binding.mkdirChildBeneath(rootOwner.fd, name, mode ?? 0o777),
442
+ fd: binding.openBeneath(rootOwner.fd, name, flags).fd,
443
+ };
441
444
  const close = captureNativeFdClose(binding);
442
- const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child); } }, false);
445
+ const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child.fd); } }, false);
443
446
  assertRootIdentityCurrentSync(params.root);
444
- verifyMkdirDirectory(binding, child, params.target);
447
+ verifyMkdirDirectory(binding, child.fd, params.target);
445
448
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
449
+ if (mode !== undefined && child.created) {
450
+ finalizeCreatedDirectoryModeSync(child, mode);
451
+ verifyMkdirDirectory(binding, child.fd, params.target);
452
+ verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
453
+ assertRootIdentityCurrentSync(params.root);
454
+ }
446
455
  }
447
456
  catch (e_5) {
448
457
  env_5.error = e_5;
@@ -1,6 +1,8 @@
1
1
  import { FsSafeError, type FsSafeErrorDetails } from "./errors.js";
2
2
  export declare function fileNotFoundError(cause?: unknown, details?: FsSafeErrorDetails): FsSafeError;
3
3
  export declare function outsideWorkspaceError(): FsSafeError;
4
+ /** Classify raw traversal denials without disguising an established policy failure. */
5
+ export declare function pathTraversalPermissionError(error: unknown, targetPath: string): FsSafeError | undefined;
4
6
  export declare function rootPathChangedError(cause?: Error): FsSafeError;
5
7
  export declare function directoryComponentNotDirectoryError(cause?: unknown): FsSafeError;
6
8
  export declare function hardlinkedPathNotAllowedError(): FsSafeError;
@@ -15,6 +15,15 @@ export function fileNotFoundError(cause, details) {
15
15
  export function outsideWorkspaceError() {
16
16
  return new FsSafeError("outside-workspace", "file is outside workspace root");
17
17
  }
18
+ /** Classify raw traversal denials without disguising an established policy failure. */
19
+ export function pathTraversalPermissionError(error, targetPath) {
20
+ if (error instanceof FsSafeError)
21
+ return error.code === "permission-denied" ? error : undefined;
22
+ if (!hasNodeErrorCode(error, "EACCES") && !hasNodeErrorCode(error, "EPERM"))
23
+ return;
24
+ const deniedPath = isNodeError(error) && typeof error.path === "string" ? error.path : targetPath;
25
+ return new FsSafeError("permission-denied", `permission denied while resolving ${deniedPath}`, errorCauseOptions(error));
26
+ }
18
27
  export function rootPathChangedError(cause) {
19
28
  return new FsSafeError("path-mismatch", "root path changed during operation", { cause });
20
29
  }
@@ -90,7 +90,7 @@ import { listDirectoryPath, openRootDirectoryListing } from "./root-directory-li
90
90
  import { statResolvedPathInRoot } from "./root-path-stat.js";
91
91
  import { entriesInRoot } from "./root-entries.js";
92
92
  import { assertRootIdentityCurrent, assertRootIdentityCurrentSync, assertValidRootDestinationPath, assertValidRootRelativePath, createRootObservationGuard, ensureTrailingSep, expandRelativePathWithHome, resolvePathInRoot, resolveRootContext, rootRelativeReadPath, } from "./root-context.js";
93
- import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, } from "./root-errors.js";
93
+ import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, pathTraversalPermissionError, } from "./root-errors.js";
94
94
  import { getFsSafeTestHooks } from "./test-hooks.js";
95
95
  import { stringifyJsonDocument } from "./json-stringify.js";
96
96
  import { walkRoot } from "./root-walk.js";
@@ -1078,6 +1078,9 @@ async function resolvePinnedRootPathInRoot(root, params) {
1078
1078
  resolved = await (params.removalReceipts ? resolveRootPathForRemoval(resolution, params.removalReceipts) : resolveRootPath(resolution));
1079
1079
  }
1080
1080
  catch (err) {
1081
+ const permissionError = pathTraversalPermissionError(err, params.relativePath);
1082
+ if (permissionError)
1083
+ throw permissionError;
1081
1084
  if (err instanceof FsSafeError && err.code === "symlink")
1082
1085
  throw err;
1083
1086
  throw new FsSafeError("path-alias", "path alias escape blocked", { cause: err });
@@ -1,2 +1,2 @@
1
1
  import { type RootContext } from "./root-context.js";
2
- export declare function tryMkdirNativeParents(root: RootContext, relativePath: string): boolean;
2
+ export declare function tryMkdirNativeParents(root: RootContext, relativePath: string, mode?: number): boolean;
@@ -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>;