@openclaw/feishu 2026.10.6 → 2026.10.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 (132) hide show
  1. package/dist/.setup/{channel-DykAJJhn.mjs → channel-C6xKXhoV.mjs} +2 -2
  2. package/dist/.setup/{channel.runtime-CC15v8AP.mjs → channel.runtime-u62eAaRZ.mjs} +1 -1
  3. package/dist/.setup/{monitor-Cy9ofY1Q.mjs → monitor-BkQxhpUk.mjs} +1 -1
  4. package/dist/.setup/{monitor.account-UbN1RhlP.mjs → monitor.account-lTPltlCL.mjs} +19 -30
  5. package/dist/.setup/{setup-api-CRjDSHmn.mjs → setup-api-DfO9XC1M.mjs} +1 -1
  6. package/dist/.source-module-urls/6579f1b33dd01f8f0aaea28311ed6df1a635f9ad1e6fa86dcba53bca46407e55.json +1 -0
  7. package/dist/api.js +1 -1
  8. package/dist/channel-plugin-api.js +1 -1
  9. package/dist/setup-api.js +1 -1
  10. package/dist/setup-entry.js +1 -1
  11. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +48 -0
  12. package/node_modules/@openclaw/fs-safe/README.md +14 -4
  13. package/node_modules/@openclaw/fs-safe/dist/archive-merge.js +28 -3
  14. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  15. package/node_modules/@openclaw/fs-safe/dist/archive-read.js +11 -5
  16. package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.js +4 -2
  17. package/node_modules/@openclaw/fs-safe/dist/archive.js +2 -2
  18. package/node_modules/@openclaw/fs-safe/dist/clone-metadata.js +1 -1
  19. package/node_modules/@openclaw/fs-safe/dist/copy-file-input.d.ts +2 -0
  20. package/node_modules/@openclaw/fs-safe/dist/copy-file-input.js +4 -3
  21. package/node_modules/@openclaw/fs-safe/dist/copy-link.d.ts +26 -0
  22. package/node_modules/@openclaw/fs-safe/dist/copy-link.js +169 -0
  23. package/node_modules/@openclaw/fs-safe/dist/copy-metadata.d.ts +9 -0
  24. package/node_modules/@openclaw/fs-safe/dist/copy-metadata.js +39 -0
  25. package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.js +1 -1
  26. package/node_modules/@openclaw/fs-safe/dist/copy-tree-portable.js +3 -6
  27. package/node_modules/@openclaw/fs-safe/dist/copy.js +3 -3
  28. package/node_modules/@openclaw/fs-safe/dist/darwin-acl.d.ts +12 -0
  29. package/node_modules/@openclaw/fs-safe/dist/darwin-acl.js +29 -0
  30. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +3 -0
  31. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +27 -2
  32. package/node_modules/@openclaw/fs-safe/dist/entry-publication.js +1 -1
  33. package/node_modules/@openclaw/fs-safe/dist/file-handle-transfer.js +4 -2
  34. package/node_modules/@openclaw/fs-safe/dist/file-hash.js +4 -3
  35. package/node_modules/@openclaw/fs-safe/dist/file-lock.d.ts +1 -0
  36. package/node_modules/@openclaw/fs-safe/dist/file-lock.js +1 -0
  37. package/node_modules/@openclaw/fs-safe/dist/file-write-lease.d.ts +9 -0
  38. package/node_modules/@openclaw/fs-safe/dist/file-write-lease.js +42 -0
  39. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +3 -0
  40. package/node_modules/@openclaw/fs-safe/dist/hardlink-fallback.d.ts +1 -0
  41. package/node_modules/@openclaw/fs-safe/dist/hardlink-fallback.js +5 -0
  42. package/node_modules/@openclaw/fs-safe/dist/json-durable-queue-ownership.js +16 -3
  43. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +57 -18
  44. package/node_modules/@openclaw/fs-safe/dist/native-directory-observation.js +1 -1
  45. package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.d.ts +1 -1
  46. package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.js +2 -0
  47. package/node_modules/@openclaw/fs-safe/dist/native-operations.js +1 -1
  48. package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.d.ts +1 -1
  49. package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.js +2 -0
  50. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.d.ts +1 -1
  51. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.js +19 -1
  52. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.d.ts +4 -1
  53. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +18 -0
  54. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.d.ts +1 -1
  55. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.js +3 -0
  56. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
  57. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +3 -0
  58. package/node_modules/@openclaw/fs-safe/dist/native.d.ts +5 -3
  59. package/node_modules/@openclaw/fs-safe/dist/native.js +25 -6
  60. package/node_modules/@openclaw/fs-safe/dist/opened-realpath.js +9 -1
  61. package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +4 -1
  62. package/node_modules/@openclaw/fs-safe/dist/permissions-public.d.ts +1 -0
  63. package/node_modules/@openclaw/fs-safe/dist/permissions-public.js +1 -0
  64. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +36 -47
  65. package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +2 -0
  66. package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +3 -0
  67. package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +2 -1
  68. package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +5 -3
  69. package/node_modules/@openclaw/fs-safe/dist/pipe.d.ts +9 -0
  70. package/node_modules/@openclaw/fs-safe/dist/pipe.js +26 -0
  71. package/node_modules/@openclaw/fs-safe/dist/private-producer-handoff.js +2 -5
  72. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +92 -10
  73. package/node_modules/@openclaw/fs-safe/dist/publish-file.d.ts +1 -1
  74. package/node_modules/@openclaw/fs-safe/dist/publish-file.js +12 -11
  75. package/node_modules/@openclaw/fs-safe/dist/root-copy.d.ts +18 -0
  76. package/node_modules/@openclaw/fs-safe/dist/root-copy.js +128 -0
  77. package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +12 -4
  78. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +6 -92
  79. package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +1 -1
  80. package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +2 -0
  81. package/node_modules/@openclaw/fs-safe/dist/root-remove-native.js +8 -1
  82. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +1 -1
  83. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-retained.js +1 -1
  84. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-target.js +8 -1
  85. package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +1 -0
  86. package/node_modules/@openclaw/fs-safe/dist/test-hooks.js +1 -0
  87. package/node_modules/@openclaw/fs-safe/dist/watch-native.js +2 -2
  88. package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.cs +11 -5
  89. package/node_modules/@openclaw/fs-safe/dist/windows-security-command.js +9 -1
  90. package/node_modules/@openclaw/fs-safe/dist/windows-test-hooks.d.ts +16 -0
  91. package/node_modules/@openclaw/fs-safe/dist/windows-test-hooks.js +51 -0
  92. package/node_modules/@openclaw/fs-safe/docs/archive.md +16 -0
  93. package/node_modules/@openclaw/fs-safe/docs/contributing.md +35 -5
  94. package/node_modules/@openclaw/fs-safe/docs/copy.md +22 -0
  95. package/node_modules/@openclaw/fs-safe/docs/durability.md +4 -2
  96. package/node_modules/@openclaw/fs-safe/docs/errors.md +8 -0
  97. package/node_modules/@openclaw/fs-safe/docs/guest.md +2 -0
  98. package/node_modules/@openclaw/fs-safe/docs/install.md +13 -5
  99. package/node_modules/@openclaw/fs-safe/docs/migrating-to-0.5.md +5 -5
  100. package/node_modules/@openclaw/fs-safe/docs/native-helper.md +15 -5
  101. package/node_modules/@openclaw/fs-safe/docs/native.md +51 -2
  102. package/node_modules/@openclaw/fs-safe/docs/pipe.md +81 -0
  103. package/node_modules/@openclaw/fs-safe/docs/platform-capabilities.md +63 -0
  104. package/node_modules/@openclaw/fs-safe/docs/quickstart.md +23 -3
  105. package/node_modules/@openclaw/fs-safe/docs/reading.md +7 -1
  106. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -5
  107. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +31 -13
  108. package/node_modules/@openclaw/fs-safe/docs/store.md +11 -0
  109. package/node_modules/@openclaw/fs-safe/docs/types.md +45 -80
  110. package/node_modules/@openclaw/fs-safe/docs/writing.md +121 -14
  111. package/node_modules/@openclaw/fs-safe/package.json +18 -10
  112. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  113. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  114. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  115. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  116. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  117. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +29 -0
  118. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  119. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +29 -0
  120. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  121. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  122. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  123. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  124. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  125. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  126. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  127. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  128. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  129. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +29 -0
  130. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  131. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  132. package/package.json +5 -5
@@ -124,6 +124,8 @@ export interface NativeWindowsDirectoryReceipt {
124
124
  }
125
125
  export interface NativeDarwinAclFacts {
126
126
  state: "absent" | "empty" | "present";
127
+ inheritsToFiles?: boolean;
128
+ inheritsToDirectories?: boolean;
127
129
  }
128
130
  type NativeTwoPathArgs = [
129
131
  sourceRootFd: number,
@@ -132,6 +134,37 @@ type NativeTwoPathArgs = [
132
134
  targetRelPath: string
133
135
  ];
134
136
  export interface NativeBinding {
137
+ readCopyMetadata?(fd: number): Buffer;
138
+ restoreCopyMetadata?(fd: number, snapshot: Buffer): void;
139
+ restoreCopyFileTimes?(fd: number, atimeNs: bigint, mtimeNs: bigint): void;
140
+ copyLinkExclusive?(sourceParent: number, sourceName: string, parent: number, name: string, dev: bigint, ino: bigint, preserveMetadata: boolean, mode: number): {
141
+ dev: bigint;
142
+ ino: bigint;
143
+ };
144
+ publishCopyLink?(parent: number, name: string, destination: string, dev: bigint, ino: bigint): void;
145
+ removeCopyLink?(parent: number, name: string, dev: bigint, ino: bigint): void;
146
+ createCopySymlink?(parent: number, name: string, target: Buffer, mode: number, atimeNs?: bigint, mtimeNs?: bigint): {
147
+ dev: bigint;
148
+ ino: bigint;
149
+ errorCode?: string;
150
+ errorMessage?: string;
151
+ };
152
+ tryAcquireWriteLease?(fd: number): boolean;
153
+ isFileWriteLeaseHeld?(fd: number): boolean;
154
+ releaseFileWriteLease?(fd: number): void;
155
+ holdWindowsSharingLock?(path: string): {
156
+ close(): void;
157
+ };
158
+ setWindowsFileAttributes?(path: string, attrs: {
159
+ readOnly?: boolean;
160
+ hidden?: boolean;
161
+ system?: boolean;
162
+ }): void;
163
+ readWindowsFileExtents?(path: string): {
164
+ vcn: bigint;
165
+ lcn: bigint;
166
+ clusters: bigint;
167
+ }[];
135
168
  rootRemovalStat?(parent: number, name: string): NativeRootRemovalEntry;
136
169
  rootRemovalUnlink?(parent: number, name: string, dev: bigint, ino: bigint, directory: boolean): void;
137
170
  openRootRemovalDirectory?(parent: number, name: string, dev: bigint, ino: bigint): NativeRootRemovalDirectory;
@@ -169,6 +202,11 @@ export interface NativeBinding {
169
202
  };
170
203
  /** Internal: consumes only a descriptor returned by this binding. */
171
204
  closeOwnedFd(fd: number): void;
205
+ createPipe?(): {
206
+ reader: number;
207
+ writer: number;
208
+ atomicCloseOnExec: boolean;
209
+ };
172
210
  /** Internal Darwin-only synchronous inspection; the caller retains its fd. */
173
211
  inspectDarwinAcl?(fd: number, inheritanceTarget?: "file" | "directory"): NativeDarwinAclFacts;
174
212
  /** POSIX system canonicalization; confinement and identity policy stay with callers. */
@@ -183,18 +221,18 @@ export interface NativeBinding {
183
221
  /** Linux/Windows byte transfer; callers retain both admitted descriptors until settlement. */
184
222
  copyFileContents?(sourceFd: number, targetFd: number, signal?: AbortSignal): Promise<void>;
185
223
  /** Internal: same private, immutable input ownership as the ZIP buffer reader. */
186
- openTarBufferNative(buffer: Buffer, kind: string, limits: TarMeterLimits, signal?: AbortSignal): Promise<{
224
+ openTarBufferNative?(buffer: Buffer, kind: string, limits: TarMeterLimits, signal?: AbortSignal): Promise<{
187
225
  readonly entries: NativeArchiveEntry[];
188
226
  readEntry(index: number, maxBytes: number, signal?: AbortSignal): Promise<Buffer>;
189
227
  }>;
190
228
  /** Internal: input remains private, unpooled and immutable until the reader is released. */
191
- openZipBufferNative(buffer: Buffer, limits: TarMeterLimits, signal?: AbortSignal): Promise<{
229
+ openZipBufferNative?(buffer: Buffer, limits: TarMeterLimits, signal?: AbortSignal): Promise<{
192
230
  readonly entries: NativeArchiveEntry[];
193
231
  readEntry(index: number, maxBytes: number, signal?: AbortSignal): Promise<Buffer>;
194
232
  }>;
195
- readCloneFileMetadata(paths: string[]): Promise<(Buffer | null)[]>;
196
- probeTreeClone(parentFd: number): "apfs" | "btrfs" | "refs" | "xfs" | "zfs" | null;
197
- cloneTree(sourceFd: number | null, parentFd: number, basename: string, concurrency: number, signal?: AbortSignal): Promise<void>;
233
+ readCloneFileMetadata?(paths: string[]): Promise<(Buffer | null)[]>;
234
+ probeTreeClone?(parentFd: number): "apfs" | "btrfs" | "refs" | "xfs" | "zfs" | null;
235
+ cloneTree?(sourceFd: number | null, parentFd: number, basename: string, concurrency: number, signal?: AbortSignal): Promise<void>;
198
236
  openStagedSymlink?(parentFd: number, basename: string): number;
199
237
  stagedSymlinkTarget?(parentFd: number, basename: string, linkFd: number): string;
200
238
  stagedSymlinkMatches?(parentFd: number, basename: string, linkFd: number): boolean;
@@ -205,28 +243,28 @@ export interface NativeBinding {
205
243
  removeStagedFile?(parentFd: number, basename: string, fileFd: number): "removed" | "name-absent" | "preserved";
206
244
  copyFileExclusive?(sourceFd: number, parentFd: number, basename: string, clone: CopyCloneMode, maxBytes: number | undefined, signal: AbortSignal | undefined): Promise<NativeFileCopyResult>;
207
245
  copyFileExclusiveSync?(sourceFd: number, parentFd: number, basename: string, clone: CopyCloneMode, maxBytes: number | undefined): NativeFileCopyResult;
208
- cloneFileExclusive(sourceFd: number, targetRootFd: number, targetRelPath: string): number;
209
- copyFileRangeExclusive(sourceFd: number, targetRootFd: number, targetRelPath: string): Promise<NativeCopyResult>;
210
- createPrivateDirectory(path: string): void;
246
+ cloneFileExclusive?(sourceFd: number, targetRootFd: number, targetRelPath: string): number;
247
+ copyFileRangeExclusive?(sourceFd: number, targetRootFd: number, targetRelPath: string): Promise<NativeCopyResult>;
248
+ createPrivateDirectory?(path: string): void;
211
249
  /** Internal Windows creation receipts use full FILE_ID_INFO, never Node's projection. */
212
250
  inspectWindowsDirectory?(path: string, requirePrivate: boolean): NativeWindowsDirectoryReceipt;
213
251
  createPrivateDirectoryWithParentIdentity?(path: string, expectedParentIdentity: string): NativeWindowsDirectoryReceipt;
214
252
  /** Protects an already-private borrowed Node file; descriptor ownership stays with Node. */
215
253
  protectPrivateWindowsFile?(fd: number, path: string, expectedParentIdentity: string): NativeWindowsDirectoryReceipt;
216
254
  verifyPrivateWindowsFile?(fd: number, path: string, expectedFileIdentity: string, expectedParentIdentity: string, expectedLinks: number): void;
217
- extractArchiveNative(path: string, kind: string, rootFd: number, plan: NativeArchivePlanEntry[], limits: TarMeterLimits, signal: AbortSignal): Promise<void>;
218
- fstatIdentity(fd: number): NativeFileIdentity;
219
- inspectArchiveNative(path: string, kind: string, limits: TarMeterLimits, signal: AbortSignal): Promise<NativeArchiveEntry[]>;
220
- linkBeneath(...args: NativeTwoPathArgs): void;
255
+ extractArchiveNative?(path: string, kind: string, rootFd: number, plan: NativeArchivePlanEntry[], limits: TarMeterLimits, signal: AbortSignal): Promise<void>;
256
+ fstatIdentity?(fd: number): NativeFileIdentity;
257
+ inspectArchiveNative?(path: string, kind: string, limits: TarMeterLimits, signal: AbortSignal): Promise<NativeArchiveEntry[]>;
258
+ linkBeneath?(...args: NativeTwoPathArgs): void;
221
259
  /** Direct-child mkdir; true is receipt provenance only, never cleanup ownership. */
222
260
  mkdirChildBeneath?(parentFd: number, basename: string, mode: number): boolean;
223
261
  mkdirOpenChildBeneath?(parentFd: number, basename: string, mode: number, flags: number): {
224
262
  fd: number;
225
263
  created: boolean;
226
264
  };
227
- mkdirBeneath(rootFd: number, relPath: string, mode: number): void;
228
- openBeneath(rootFd: number, relPath: string, flags: number): NativeOpenBeneathResult;
229
- readOwnerAndDacl(path: string): NativeWindowsSecurityFacts;
265
+ mkdirBeneath?(rootFd: number, relPath: string, mode: number): void;
266
+ openBeneath?(rootFd: number, relPath: string, flags: number): NativeOpenBeneathResult;
267
+ readOwnerAndDacl?(path: string): NativeWindowsSecurityFacts;
230
268
  /** Internal Windows-only inspection of the exact borrowed Node descriptor. */
231
269
  inspectWindowsSecureFileHandle?(fd: number): NativeWindowsDescriptorSecurityFacts;
232
270
  ownedTreeRemovalAvailable?(parentFd: number): boolean;
@@ -236,13 +274,14 @@ export interface NativeBinding {
236
274
  retainWindowsEntryPublication?(sourcePath: string, name: string, sourceDev: bigint, sourceIno: bigint, targetPath: string, targetName: string, targetDev: bigint, targetIno: bigint, dev: bigint, ino: bigint, kind: "file" | "directory" | "symlink"): NativeWindowsEntryPublication;
237
275
  entryPublicationFilesystem?(parentFd: number): string;
238
276
  publishRetainedEntryNoReplace?(sourceParentFd: number, sourceBasename: string, sourceFd: number, targetParentFd: number, targetBasename: string): NativePublicationTransition;
239
- renameNoReplace(...args: NativeTwoPathArgs): void;
277
+ renameNoReplace?(...args: NativeTwoPathArgs): void;
240
278
  /** Linux auto-mode fallback through already-admitted direct-child parents. */
241
279
  moveNoReplaceFallback?(...args: [...paths: NativeTwoPathArgs, expectedSourceDev: bigint, expectedSourceIno: bigint]): void;
242
280
  /** Identity-fenced retained-directory rename capability. */
243
281
  renameNoReplaceWithIdentity?(...args: [...paths: NativeTwoPathArgs, expectedSourceDev: bigint, expectedSourceIno: bigint]): void;
244
- renameReplace(...args: NativeTwoPathArgs): void;
245
- sha256File(fd: number, maxBytes?: number, signal?: AbortSignal): Promise<NativeFileHash>;
282
+ renameReplace?(...args: NativeTwoPathArgs): void;
283
+ sha256File?(fd: number, maxBytes?: number, signal?: AbortSignal): Promise<NativeFileHash>;
246
284
  }
285
+ export type CapableNativeBinding<K extends keyof NativeBinding> = NativeBinding & Required<Pick<NativeBinding, K>>;
247
286
  export declare function captureNativeFdClose(binding: NativeBinding): (fd: number) => void;
248
287
  export {};
@@ -5,7 +5,7 @@ import { inspectFileIdentitySync } from "./strict-file-identity.js";
5
5
  export function getNativeDirectoryObservationBackend(enabled = true) {
6
6
  if (!enabled)
7
7
  return undefined;
8
- const binding = getNativeBinding();
8
+ const binding = getNativeBinding("observeDirectory");
9
9
  return binding && typeof binding.observeDirectory === "function"
10
10
  ? binding
11
11
  : undefined;
@@ -1,3 +1,3 @@
1
1
  import type { BigIntStats } from "node:fs";
2
2
  import type { NativeBinding } from "./native-binding.js";
3
- export declare function nativeMoveNoReplace(binding: NativeBinding, paths: Parameters<NativeBinding["renameNoReplace"]>, expected: BigIntStats | undefined, allowFallback: boolean, operation?: string): "link-unlink" | undefined;
3
+ export declare function nativeMoveNoReplace(binding: NativeBinding, paths: Parameters<NonNullable<NativeBinding["renameNoReplace"]>>, expected: BigIntStats | undefined, allowFallback: boolean, operation?: string): "link-unlink" | undefined;
@@ -1,4 +1,5 @@
1
1
  import { FsSafeError } from "./errors.js";
2
+ import { assertNativeCapabilities } from "./native.js";
2
3
  import { cachedNoReplaceUnavailable, noReplaceUnavailable, rememberNoReplaceUnavailable, } from "./native-noreplace.js";
3
4
  function fallbackError(error, operation) {
4
5
  const code = error?.code;
@@ -24,6 +25,7 @@ function fallbackError(error, operation) {
24
25
  return error;
25
26
  }
26
27
  export function nativeMoveNoReplace(binding, paths, expected, allowFallback, operation = "move") {
28
+ assertNativeCapabilities(binding, "renameNoReplace");
27
29
  const [sourceFd, source, targetFd, target] = paths;
28
30
  let unavailable = cachedNoReplaceUnavailable(binding, sourceFd, operation);
29
31
  if (!unavailable) {
@@ -32,7 +32,7 @@ export function removeNativeCreatedFileIfStillPinned(params) {
32
32
  }
33
33
  }
34
34
  export async function createNativeExclusiveFile(targetPath, mode) {
35
- const binding = getNativeBinding();
35
+ const binding = getNativeBinding("openBeneath");
36
36
  if (!binding) {
37
37
  return undefined;
38
38
  }
@@ -1,7 +1,7 @@
1
1
  import { type BigIntStats, type Stats } from "node:fs";
2
2
  import type { FileHandle } from "node:fs/promises";
3
3
  import type { FileIdentityStat } from "./file-identity.js";
4
- import type { NativeBinding } from "./native.js";
4
+ import { type NativeBinding } from "./native.js";
5
5
  import { describeStagedDirectory } from "./staged-directory.js";
6
6
  type RootIdentity = Pick<FileIdentityStat, "dev" | "ino">;
7
7
  export type NativeRootAdmission = {
@@ -5,6 +5,7 @@ import { inspectDirectoryIdentity, inspectDirectoryIdentitySync } from "./direct
5
5
  import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
6
6
  import { inspectNativeDirectoryObservation } from "./native-directory-observation.js";
7
7
  import { FsSafeError } from "./errors.js";
8
+ import { assertNativeCapabilities } from "./native.js";
8
9
  import { captureNativeFdClose } from "./native-binding.js";
9
10
  import { realpathSync } from "./realpath.js";
10
11
  import { describeStagedDirectory, exactIdentityMatches } from "./staged-directory.js";
@@ -22,6 +23,7 @@ function assertParentAdmissionAvailable(binding) {
22
23
  throw unavailable("native parent directory admission is unavailable");
23
24
  }
24
25
  captureNativeFdClose(binding);
26
+ assertNativeCapabilities(binding, "openBeneath");
25
27
  }
26
28
  export async function openNativeRootAdmission(binding, params) {
27
29
  assertParentAdmissionAvailable(binding);
@@ -1,6 +1,6 @@
1
1
  import type { FileHandle } from "node:fs/promises";
2
2
  import { type AnyAsyncDirectoryGuard } from "./directory-guard.js";
3
3
  import type { FileIdentityStat } from "./file-identity.js";
4
- import type { NativeBinding } from "./native.js";
4
+ import { type NativeBinding } from "./native.js";
5
5
  import type { PinnedWriteParams } from "./pinned-write-types.js";
6
6
  export declare function runPinnedWriteWindows(binding: NativeBinding, params: PinnedWriteParams, root: FileHandle, parentFd: number, parentGuard: AnyAsyncDirectoryGuard): Promise<FileIdentityStat>;
@@ -8,6 +8,8 @@ import { assertSyncDirectoryGuard } from "./directory-guard.js";
8
8
  import { FsSafeError } from "./errors.js";
9
9
  import { nativeOpenFlags, removeNativeCreatedFileIfStillPinned, } from "./native-operations.js";
10
10
  import { writePinnedInput } from "./pinned-write-input.js";
11
+ import { assertNativeCopyCompleted, createNativeCopyFile } from "./copy-file-input.js";
12
+ import { assertNativeCapabilities } from "./native.js";
11
13
  import { captureNativeFdClose } from "./native-binding.js";
12
14
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
13
15
  import { assertFinalSymlinkRejected } from "./root-symlink-policy.js";
@@ -15,6 +17,7 @@ import { classifyNativeRenameFailure } from "./native-rename-outcome.js";
15
17
  import { cleanupPinnedFilePath } from "./file-cleanup.js";
16
18
  import { createStagedFileReceipt, settleStagedFile } from "./staged-file-settlement.js";
17
19
  import { exactIdentityMatches } from "./staged-directory.js";
20
+ import { restoreCopyMetadata } from "./copy-metadata.js";
18
21
  import { inspectNativeDirectoryObservation } from "./native-directory-observation.js";
19
22
  function closeWriteFd(closeFd, fd) {
20
23
  if (fd === undefined)
@@ -50,6 +53,7 @@ function assertNamedParentCurrent(binding, guard, identity) {
50
53
  assertSyncDirectoryGuard({ ...guard, stat: identity });
51
54
  }
52
55
  export async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuard) {
56
+ assertNativeCapabilities(binding, "openBeneath", "renameNoReplace", "renameReplace", "fstatIdentity");
53
57
  const closeFd = captureNativeFdClose(binding);
54
58
  const parentPath = parentGuard.realPath;
55
59
  let tempFd;
@@ -78,6 +82,9 @@ export async function runPinnedWriteWindows(binding, params, root, parentFd, par
78
82
  try {
79
83
  tempName = `.fs-safe-${randomUUID()}.tmp`;
80
84
  params.assertBeforeMutation?.();
85
+ const copied = params.input.kind === "file" && !params.private
86
+ ? await createNativeCopyFile(binding, params.input, parentFd, tempName, params.maxBytes)
87
+ : undefined;
81
88
  if (params.private) {
82
89
  const parentIdentity = fsSync.fstatSync(parentFd, { bigint: true });
83
90
  privateHandle = await createFileHandle(path.join(parentPath, tempName), {
@@ -91,16 +98,24 @@ export async function runPinnedWriteWindows(binding, params, root, parentFd, par
91
98
  });
92
99
  tempFd = privateHandle.fd;
93
100
  }
101
+ else if (copied) {
102
+ tempFd = copied.fd;
103
+ }
94
104
  else {
95
105
  tempFd = binding.openBeneath(parentFd, tempName, nativeOpenFlags(fsSync.constants.O_WRONLY | fsSync.constants.O_CREAT | fsSync.constants.O_EXCL)).fd;
96
106
  }
97
107
  const verificationIdentity = inspectFileIdentitySync(() => fsSync.fstatSync(tempFd, { bigint: true }));
98
108
  tempIdentity = verificationIdentity;
109
+ if (params.input.kind === "file")
110
+ assertNativeCopyCompleted(params.input, copied);
99
111
  // Creation is requested at 0600 in the binding, but a restrictive umask
100
112
  // can remove owner access. Keep the unpublished inode private and
101
113
  // reopenable until the published name has been identity-fenced.
102
114
  fsSync.fchmodSync(tempFd, 0o600);
103
- await writePinnedInput(tempFd, params.input, params.maxBytes, params.assertBeforeMutation);
115
+ if (!copied)
116
+ await writePinnedInput(tempFd, params.input, params.maxBytes, params.assertBeforeMutation);
117
+ if (params.input.kind === "file")
118
+ restoreCopyMetadata(tempFd, params.input.metadata);
104
119
  if (params.sync !== false) {
105
120
  if (params.strictFileSync)
106
121
  fsSync.fsyncSync(tempFd);
@@ -132,6 +147,9 @@ export async function runPinnedWriteWindows(binding, params, root, parentFd, par
132
147
  }
133
148
  assertFinalSymlinkRejected(path.join(parentPath, params.basename), params.rejectFinalSymlink);
134
149
  }
150
+ // The authority callback itself may have cancelled an otherwise completed copy.
151
+ if (params.input.kind === "file")
152
+ params.input.signal?.throwIfAborted();
135
153
  try {
136
154
  if (params.overwrite === false) {
137
155
  binding.renameNoReplace(parentFd, tempName, parentFd, params.basename);
@@ -1,4 +1,7 @@
1
1
  import type { FileIdentityStat } from "./file-identity.js";
2
- import type { NativeBinding } from "./native.js";
2
+ import { type NativeBinding } from "./native.js";
3
3
  import type { PinnedWriteParams } from "./pinned-write-types.js";
4
+ type PinnedWriteCapabilitiesInput = Pick<PinnedWriteParams, "input" | "private" | "verifyPosixMode">;
5
+ export declare function getPinnedWriteNativeBinding(params: PinnedWriteCapabilitiesInput): NativeBinding | undefined;
4
6
  export declare function runPinnedWriteNative(binding: NativeBinding, params: PinnedWriteParams, fallback: (input: PinnedWriteParams["input"]) => Promise<FileIdentityStat>): Promise<FileIdentityStat>;
7
+ export {};
@@ -56,12 +56,27 @@ import { runPinnedWriteWindows } from "./native-pinned-write-windows.js";
56
56
  import { capturePolicyAwareNativeParent } from "./native-policy-parent.js";
57
57
  import { openNativeParentAdmission, openNativeRootAdmission } from "./native-parent-admission.js";
58
58
  import { assertNativeStaging, writeNativeStage } from "./native-staged-file.js";
59
+ import { assertNativeCapabilities, getNativeBinding } from "./native.js";
59
60
  import { captureNativeFdClose } from "./native-binding.js";
60
61
  import { cachedNoReplaceUnavailable } from "./native-noreplace.js";
61
62
  import { isFsSafeNativeRequired } from "./native-config.js";
63
+ import { copyLinkAtParent } from "./copy-link.js";
64
+ const writeCapabilities = ["openBeneath", "mkdirBeneath", "renameNoReplace", "renameReplace"];
65
+ const posixWriteCapabilities = [...writeCapabilities, "createStagedFile", "stagedFileMatches", "removeStagedFile"];
66
+ function pinnedWriteCapabilities(params) {
67
+ const windows = process.platform === "win32";
68
+ const capabilities = windows ? [...writeCapabilities, "fstatIdentity"] : posixWriteCapabilities;
69
+ const nativeCopy = params.input.kind === "file" && !params.private &&
70
+ (windows || !params.verifyPosixMode);
71
+ return nativeCopy ? [...capabilities, "copyFileExclusive"] : capabilities;
72
+ }
73
+ export function getPinnedWriteNativeBinding(params) {
74
+ return getNativeBinding(...pinnedWriteCapabilities(params));
75
+ }
62
76
  export async function runPinnedWriteNative(binding, params, fallback) {
63
77
  const env_1 = { stack: [], error: void 0, hasError: false };
64
78
  try {
79
+ assertNativeCapabilities(binding, ...pinnedWriteCapabilities(params));
65
80
  const closeFd = captureNativeFdClose(binding);
66
81
  const windows = process.platform === "win32";
67
82
  if (!windows) {
@@ -112,6 +127,9 @@ export async function runPinnedWriteNative(binding, params, fallback) {
112
127
  parentPathStat = admitted.guard.stat;
113
128
  }
114
129
  const verificationGuard = { dir: parentPath, realPath: parentPath, stat: parentPathStat };
130
+ if (params.input.kind === "link") {
131
+ return await copyLinkAtParent(params, params.input, verificationGuard, { binding, fd: parentFd });
132
+ }
115
133
  if (params.overwrite === false) {
116
134
  try {
117
135
  fsSync.lstatSync(path.join(parentPath, params.basename));
@@ -1,6 +1,6 @@
1
1
  import { type BigIntStats } from "node:fs";
2
2
  import { type AsyncDirectoryGuard } from "./directory-guard.js";
3
- import type { NativeBinding } from "./native.js";
3
+ import { type NativeBinding } from "./native.js";
4
4
  import type { NativeRootAdmission } from "./native-parent-admission.js";
5
5
  import type { PinnedWriteParams } from "./pinned-write-types.js";
6
6
  import { describeStagedDirectory, type PolicyStagedDirectory } from "./staged-directory.js";
@@ -54,6 +54,7 @@ import fsSync, {} from "node:fs";
54
54
  import path from "node:path";
55
55
  import { inspectDirectoryIdentity, inspectDirectoryIdentitySync, } from "./directory-guard.js";
56
56
  import { FsSafeError } from "./errors.js";
57
+ import { assertNativeCapabilities } from "./native.js";
57
58
  import { captureNativeFdClose } from "./native-binding.js";
58
59
  import { NativePolicyDirectoryMismatch } from "./native-policy-directory-observation.js";
59
60
  import { assertWindowsPolicyParentCurrent, closeWindowsPolicyParentAfterFailure, openWindowsPolicyParent, windowsParentObservation, } from "./native-policy-parent-windows.js";
@@ -76,6 +77,7 @@ function mkdirPosixPolicyChild(binding, parentFd, basename) {
76
77
  if (typeof created === "boolean")
77
78
  return created;
78
79
  }
80
+ assertNativeCapabilities(binding, "mkdirBeneath");
79
81
  binding.mkdirBeneath(parentFd, basename, 0o777);
80
82
  return false;
81
83
  }
@@ -122,6 +124,7 @@ function tryDescribePolicyPosixParent(binding, fd, pathname) {
122
124
  export async function capturePolicyAwareNativeParent(binding, params, rootAdmission, windows, directoryFlags, fuseChildCreation = false) {
123
125
  const env_1 = { stack: [], error: void 0, hasError: false };
124
126
  try {
127
+ assertNativeCapabilities(binding, "openBeneath");
125
128
  const rootFd = rootAdmission.root.fd;
126
129
  const closeFd = captureNativeFdClose(binding);
127
130
  const observationDisposers = windows ? undefined : new Map();
@@ -5,7 +5,7 @@ import type { FileIdentityStat } from "./file-identity.js";
5
5
  import { type NativeBinding } from "./native-binding.js";
6
6
  import type { PinnedWriteInput, PinnedWriteParams } from "./pinned-write-types.js";
7
7
  import type { PublishedFileReceipt, StagedFile, StagedFileCleanupReceipt, StagedFileReceipt } from "./staged-file-types.js";
8
- export type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile">>;
8
+ export type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile" | "renameReplace" | "renameNoReplace">>;
9
9
  export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
10
10
  type StagedPermissionPolicy = "private-creation" | "mode-only";
11
11
  type NativeStageOwner = Readonly<{
@@ -67,6 +67,7 @@ import { classifyNativeRenameFailure } from "./native-rename-outcome.js";
67
67
  import { createStagedFileReceipt, stagedFailure } from "./staged-file-settlement.js";
68
68
  import { noReplaceUnavailable, rememberNoReplaceUnavailable } from "./native-noreplace.js";
69
69
  import { isFsSafeNativeRequired } from "./native-config.js";
70
+ import { restoreCopyMetadata } from "./copy-metadata.js";
70
71
  export function assertNativeStaging(binding) {
71
72
  if ([
72
73
  binding.closeOwnedFd,
@@ -299,6 +300,8 @@ class NativeStagedFile {
299
300
  } : this.#assertBeforeMutation;
300
301
  if (!copied)
301
302
  await writePinnedInput(fd, input, maxBytes, assertBeforeMutation);
303
+ if (input.kind === "file")
304
+ restoreCopyMetadata(fd, input.metadata);
302
305
  if (this.#verifyMode)
303
306
  this.#assertStagePermissions(fd);
304
307
  if (this.#owner.sync !== false) {
@@ -1,4 +1,4 @@
1
- import { type NativeBinding } from "./native-binding.js";
1
+ import { type NativeBinding, type CapableNativeBinding } from "./native-binding.js";
2
2
  export type { NativeBinding } from "./native-binding.js";
3
3
  export declare function __loadBundledNativeForTest(): NativeBinding;
4
4
  export declare function __nativeLoaderDetectorsForTest(): {
@@ -7,7 +7,9 @@ export declare function __nativeLoaderDetectorsForTest(): {
7
7
  elfInterpreter: boolean | undefined;
8
8
  };
9
9
  export declare function __nativeTargetForTest(platform: NodeJS.Platform, arch: string, musl?: boolean): string | undefined;
10
- export declare function getNativeBinding(): NativeBinding | undefined;
11
- export declare function requireNativeBinding(): NativeBinding;
10
+ export declare function selectNativeBinding<K extends keyof NativeBinding>(native: NativeBinding | undefined, ...capabilities: K[]): CapableNativeBinding<K> | undefined;
11
+ export declare function assertNativeCapabilities<K extends keyof NativeBinding>(native: NativeBinding, ...capabilities: K[]): asserts native is CapableNativeBinding<K>;
12
+ export declare function getNativeBinding<K extends keyof NativeBinding = never>(...capabilities: K[]): CapableNativeBinding<K> | undefined;
13
+ export declare function requireNativeBinding<K extends keyof NativeBinding = never>(...capabilities: K[]): CapableNativeBinding<K>;
12
14
  export declare function __setNativeLoaderForTest(loader: () => NativeBinding): void;
13
15
  export declare function __resetNativeLoaderForTest(): void;
@@ -127,12 +127,14 @@ function isMusl() {
127
127
  return false;
128
128
  }
129
129
  function targetFor(platform, arch, musl) {
130
- if (platform === "win32" && arch === "x64")
131
- return "win32-x64-msvc";
130
+ if (platform === "win32" && (arch === "x64" || arch === "arm64"))
131
+ return `win32-${arch}-msvc`;
132
132
  if (platform === "darwin" && arch === "x64")
133
133
  return "darwin-x64";
134
134
  if (platform === "darwin" && arch === "arm64")
135
135
  return "darwin-arm64";
136
+ if (platform === "freebsd" && (arch === "x64" || arch === "arm64"))
137
+ return `freebsd-${arch}`;
136
138
  if (platform === "linux" && (arch === "x64" || arch === "arm64")) {
137
139
  return `linux-${arch}-${musl ? "musl" : "gnu"}`;
138
140
  }
@@ -166,7 +168,24 @@ export function __nativeLoaderDetectorsForTest() {
166
168
  export function __nativeTargetForTest(platform, arch, musl = false) {
167
169
  return targetFor(platform, arch, musl);
168
170
  }
169
- export function getNativeBinding() {
171
+ export function selectNativeBinding(native, ...capabilities) {
172
+ if (!native)
173
+ return undefined;
174
+ const missing = capabilities.filter((name) => typeof native[name] !== "function");
175
+ if (missing.length === 0)
176
+ return native;
177
+ if (getFsSafeNativeConfig().mode === "require") {
178
+ throw new FsSafeError("helper-unavailable", `native fs-safe capabilities unavailable: ${missing.join(", ")}`);
179
+ }
180
+ return undefined;
181
+ }
182
+ export function assertNativeCapabilities(native, ...capabilities) {
183
+ const missing = capabilities.filter((name) => typeof native[name] !== "function");
184
+ if (missing.length) {
185
+ throw new FsSafeError("helper-unavailable", `native fs-safe capabilities unavailable: ${missing.join(", ")}`);
186
+ }
187
+ }
188
+ export function getNativeBinding(...capabilities) {
170
189
  const { mode } = getFsSafeNativeConfig();
171
190
  if (mode === "off")
172
191
  return undefined;
@@ -182,7 +201,7 @@ export function getNativeBinding() {
182
201
  }
183
202
  }
184
203
  if (binding)
185
- return binding;
204
+ return selectNativeBinding(binding, ...capabilities);
186
205
  if (mode === "require") {
187
206
  throw new FsSafeError("helper-unavailable", "native fs-safe helper is unavailable", {
188
207
  cause: loadError,
@@ -190,8 +209,8 @@ export function getNativeBinding() {
190
209
  }
191
210
  return undefined;
192
211
  }
193
- export function requireNativeBinding() {
194
- const native = getNativeBinding();
212
+ export function requireNativeBinding(...capabilities) {
213
+ const native = getNativeBinding(...capabilities);
195
214
  if (!native) {
196
215
  throw new FsSafeError("helper-unavailable", "native fs-safe helper is unavailable", {
197
216
  cause: loadError,
@@ -26,7 +26,15 @@ export async function resolveOpenedFileRealPathForFd(fd, handleStat, ioPath) {
26
26
  : [];
27
27
  for (const fdPath of fdCandidates) {
28
28
  try {
29
- const fdRealPath = realpathSync.native(fdPath);
29
+ // Linux procfs already reports the descriptor's physical pathname. Keep
30
+ // the fresh identity check without walking that canonical path again.
31
+ const fdLink = fdPath.startsWith("/proc/") ? fsSync.readlinkSync(fdPath) : undefined;
32
+ // The deletion suffix can also name a live entry or a symlink. Preserve
33
+ // canonicalization for that ambiguous spelling, including literal names.
34
+ const fdRealPath = fdLink !== undefined && !fdLink.endsWith(" (deleted)")
35
+ ? fdLink : realpathSync.native(fdPath);
36
+ if (!path.isAbsolute(fdRealPath))
37
+ continue;
30
38
  const fdRealStat = statOptions ? fsSync.statSync(fdRealPath, statOptions) : fsSync.statSync(fdRealPath);
31
39
  if (sameFileIdentity(handleStat, fdRealStat)) {
32
40
  return { realPath: fdRealPath, stat: fdRealStat };
@@ -1,3 +1,4 @@
1
+ import fs from "node:fs";
1
2
  import { FsSafeError } from "./errors.js";
2
3
  import { assertSynchronousCallbackResult } from "./mutation-authority.js";
3
4
  import { readFileWindowFully } from "./positional-read.js";
@@ -10,7 +11,9 @@ export async function overwriteFileHandle(handle, data, options = {}) {
10
11
  const beforeWrite = options.beforeWrite;
11
12
  const payload = data.subarray(0, data.byteLength);
12
13
  const payloadBytes = payload.byteLength;
13
- const stat = await handle.stat();
14
+ const fd = handle.fd;
15
+ // Keep FileHandle's closed-handle error while avoiding a metadata I/O hop.
16
+ const stat = fd < 0 ? await handle.stat() : fs.fstatSync(fd);
14
17
  if (!stat.isFile()) {
15
18
  throw new FsSafeError("not-file", "overwrite handle must be a regular file");
16
19
  }
@@ -3,3 +3,4 @@ export type { PermissionCommandFailure } from "./permission-exec.js";
3
3
  export { createPrivateDirectory, type CreatePrivateDirectoryOptions, } from "./private-directory.js";
4
4
  export { readOwnerAndDacl, type OwnerAndDaclResult, type WindowsAccessControlEntry, type WindowsAceFlags, } from "./owner-dacl.js";
5
5
  export { readOwnerAndDaclBatch } from "./owner-dacl-batch.js";
6
+ export { inspectDarwinAcl, type DarwinAclInspection } from "./darwin-acl.js";
@@ -2,3 +2,4 @@ export { formatOctal, formatPermissionDetail, formatPermissionRemediation, inspe
2
2
  export { createPrivateDirectory, } from "./private-directory.js";
3
3
  export { readOwnerAndDacl, } from "./owner-dacl.js";
4
4
  export { readOwnerAndDaclBatch } from "./owner-dacl-batch.js";
5
+ export { inspectDarwinAcl } from "./darwin-acl.js";