@openclaw/matrix 2026.11.10-beta.3 → 2026.12.1-beta.1

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 (149) hide show
  1. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +57 -0
  2. package/node_modules/@openclaw/fs-safe/README.md +6 -0
  3. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  4. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  5. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +10 -0
  6. package/node_modules/@openclaw/fs-safe/dist/bounded-read.d.ts +1 -1
  7. package/node_modules/@openclaw/fs-safe/dist/bounded-read.js +15 -4
  8. package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +11 -2
  9. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.d.ts +6 -0
  10. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.js +38 -0
  11. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.d.ts +1 -1
  12. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +2 -2
  13. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +13 -8
  14. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +13 -0
  15. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.d.ts +2 -2
  16. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +34 -24
  17. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +7 -2
  18. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +20 -20
  19. package/node_modules/@openclaw/fs-safe/dist/file-observation.d.ts +13 -2
  20. package/node_modules/@openclaw/fs-safe/dist/file-observation.js +8 -4
  21. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -0
  22. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +11 -1
  23. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.d.ts +2 -0
  24. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.js +17 -0
  25. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  26. package/node_modules/@openclaw/fs-safe/dist/file-store.js +12 -16
  27. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +1 -1
  28. package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -4
  29. package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +2 -0
  30. package/node_modules/@openclaw/fs-safe/dist/json-document-store.js +1 -0
  31. package/node_modules/@openclaw/fs-safe/dist/json-store.js +1 -0
  32. package/node_modules/@openclaw/fs-safe/dist/json.d.ts +5 -2
  33. package/node_modules/@openclaw/fs-safe/dist/json.js +6 -2
  34. package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.js +16 -10
  35. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +6 -0
  36. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +4 -0
  37. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.d.ts +20 -0
  38. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.js +18 -0
  39. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +3 -18
  40. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +48 -24
  41. package/node_modules/@openclaw/fs-safe/dist/opened-file-failure.js +19 -7
  42. package/node_modules/@openclaw/fs-safe/dist/output.d.ts +1 -0
  43. package/node_modules/@openclaw/fs-safe/dist/output.js +3 -0
  44. package/node_modules/@openclaw/fs-safe/dist/path-policy.js +4 -1
  45. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +35 -10
  46. package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +9 -2
  47. package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +42 -23
  48. package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +85 -34
  49. package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +3 -0
  50. package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +4 -0
  51. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +1 -0
  52. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +1 -1
  53. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
  54. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.d.ts +24 -0
  55. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.js +151 -0
  56. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.d.ts +1 -0
  57. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -1
  58. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +1 -1
  59. package/node_modules/@openclaw/fs-safe/dist/realpath.js +22 -11
  60. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +1 -0
  61. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +5 -0
  62. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +7 -0
  63. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +75 -2
  64. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -0
  65. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +14 -10
  66. package/node_modules/@openclaw/fs-safe/dist/root-context.js +28 -12
  67. package/node_modules/@openclaw/fs-safe/dist/root-copy.js +1 -0
  68. package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +2 -2
  69. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +4 -0
  70. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +53 -36
  71. package/node_modules/@openclaw/fs-safe/dist/root-file-open-batch-sync.js +3 -1
  72. package/node_modules/@openclaw/fs-safe/dist/root-file.d.ts +2 -1
  73. package/node_modules/@openclaw/fs-safe/dist/root-file.js +24 -13
  74. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +17 -1
  75. package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +4 -2
  76. package/node_modules/@openclaw/fs-safe/dist/root-path.d.ts +1 -1
  77. package/node_modules/@openclaw/fs-safe/dist/root-path.js +2 -1
  78. package/node_modules/@openclaw/fs-safe/dist/root-read-admission.js +31 -9
  79. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +6 -2
  80. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +1 -0
  81. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  82. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.d.ts +1 -0
  83. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +84 -4
  84. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +1 -0
  85. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +2 -0
  86. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +22 -15
  87. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.d.ts +22 -0
  88. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.js +303 -0
  89. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -0
  90. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +9 -1
  91. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.d.ts +8 -0
  92. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.js +37 -3
  93. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.d.ts +14 -0
  94. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.js +155 -0
  95. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +7 -2
  96. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.d.ts +10 -0
  97. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.js +143 -0
  98. package/node_modules/@openclaw/fs-safe/dist/temp-target.js +28 -7
  99. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.d.ts +2 -2
  100. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +34 -18
  101. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
  102. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +13 -3
  103. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +1 -1
  104. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +9 -0
  105. package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +6 -0
  106. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -1
  107. package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +1 -0
  108. package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +1 -0
  109. package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +2 -1
  110. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  111. package/node_modules/@openclaw/fs-safe/docs/advanced.md +6 -1
  112. package/node_modules/@openclaw/fs-safe/docs/atomic.md +64 -0
  113. package/node_modules/@openclaw/fs-safe/docs/contributing.md +69 -0
  114. package/node_modules/@openclaw/fs-safe/docs/file-store.md +2 -0
  115. package/node_modules/@openclaw/fs-safe/docs/json-store.md +2 -0
  116. package/node_modules/@openclaw/fs-safe/docs/json.md +2 -0
  117. package/node_modules/@openclaw/fs-safe/docs/output.md +2 -0
  118. package/node_modules/@openclaw/fs-safe/docs/permissions.md +20 -7
  119. package/node_modules/@openclaw/fs-safe/docs/reading.md +24 -9
  120. package/node_modules/@openclaw/fs-safe/docs/root.md +2 -0
  121. package/node_modules/@openclaw/fs-safe/docs/security-model.md +2 -0
  122. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +12 -7
  123. package/node_modules/@openclaw/fs-safe/docs/staged-file.md +2 -0
  124. package/node_modules/@openclaw/fs-safe/docs/temp-isolation-reference.md +73 -0
  125. package/node_modules/@openclaw/fs-safe/docs/temp.md +65 -0
  126. package/node_modules/@openclaw/fs-safe/docs/testing.md +1 -0
  127. package/node_modules/@openclaw/fs-safe/docs/writing.md +2 -0
  128. package/node_modules/@openclaw/fs-safe/package.json +25 -20
  129. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  130. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  131. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  132. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  133. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  134. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  135. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  136. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  137. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  138. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  139. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  140. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  141. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  142. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  143. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  144. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  145. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  146. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  147. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  148. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  149. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  const active = new AsyncLocalStorage();
3
3
  export function recordFileObservationFailure(error, kind) {
4
- const failures = active.getStore();
4
+ const failures = active.getStore()?.failures;
5
5
  if (!failures)
6
6
  return;
7
7
  let kinds = failures.get(error);
@@ -10,13 +10,17 @@ export function recordFileObservationFailure(error, kind) {
10
10
  kinds.add(kind);
11
11
  }
12
12
  export function isFileObservationFailure(error, kind) {
13
- return active.getStore()?.get(error)?.has(kind) === true;
13
+ return active.getStore()?.failures.get(error)?.has(kind) === true;
14
+ }
15
+ export async function observedFilePublicationPending(filePath, identity) {
16
+ return await active.getStore()?.publicationPending?.(filePath, identity) ?? false;
14
17
  }
15
18
  // Each Root observation owns its receipts, including nested and concurrent reads.
16
- export function fileObservation() {
19
+ export function fileObservation(options = {}) {
17
20
  const failures = new Map();
21
+ const context = { failures, ...options };
18
22
  return {
19
- run(operation) { return active.run(failures, operation); },
23
+ run(operation) { return active.run(context, operation); },
20
24
  has(error, kind) { return failures.get(error)?.has(kind) === true; },
21
25
  };
22
26
  }
@@ -3,6 +3,7 @@ export declare function writeFileSyncAtomic(params: {
3
3
  filePath: string;
4
4
  content: string | Uint8Array;
5
5
  privateMode: boolean;
6
+ allowDrvfsRenameRecovery?: boolean;
6
7
  durable: boolean;
7
8
  dirMode: number | "preserve";
8
9
  mode: number;
@@ -15,6 +15,7 @@ import { AtomicTempOwner } from "./replace-file-temp-owner.js";
15
15
  import { errorCauseOptions } from "./root-errors.js";
16
16
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
17
17
  import { getFsSafeTestHooks } from "./test-hooks.js";
18
+ import { hasErrorCode } from "./file-cleanup.js";
18
19
  function verifyStoreFile(fd, expected, filePath) {
19
20
  const assertFile = (stat, allowUnknown = false) => {
20
21
  const unknown = allowUnknown && process.platform === "win32" && (stat.dev === 0n || stat.ino === 0n);
@@ -103,11 +104,20 @@ export function writeFileSyncAtomic(params) {
103
104
  fs.fsyncSync(temp.file.fd);
104
105
  verifyStoreFile(temp.file.fd, owner.identity, tempPath);
105
106
  assertSyncStoreDirectoryReceipt(parentGuard);
107
+ if (params.allowDrvfsRenameRecovery === true)
108
+ runSync(owner.prepareRecovery(params.content, parentGuard.dir));
106
109
  fs.renameSync(tempPath, filePath);
107
110
  owner.markRenamed();
108
111
  assertSyncStoreDirectoryReceipt(parentGuard);
109
112
  try {
110
- verifyStoreFile(temp.file.fd, owner.identity, filePath);
113
+ try {
114
+ verifyStoreFile(temp.file.fd, owner.identity, filePath);
115
+ }
116
+ catch (error) {
117
+ if (!owner.canRecoverHiddenRename || !hasErrorCode(error, "ENOENT"))
118
+ throw error;
119
+ runSync(owner.assertPublished(filePath));
120
+ }
111
121
  }
112
122
  catch (error) {
113
123
  if (error instanceof FsSafeError) {
@@ -0,0 +1,2 @@
1
+ import type { FileStoreWriteOptions } from "./file-store.js";
2
+ export declare function snapshotWriteOptions(options?: FileStoreWriteOptions, durabilityFirst?: boolean): FileStoreWriteOptions | undefined;
@@ -0,0 +1,17 @@
1
+ export function snapshotWriteOptions(options, durabilityFirst = true) {
2
+ if (options == null)
3
+ return undefined;
4
+ return durabilityFirst ? {
5
+ maxBytes: options.maxBytes,
6
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
7
+ durable: options.durable,
8
+ dirMode: options.dirMode,
9
+ mode: options.mode,
10
+ } : {
11
+ maxBytes: options.maxBytes,
12
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
13
+ dirMode: options.dirMode,
14
+ mode: options.mode,
15
+ durable: options.durable,
16
+ };
17
+ }
@@ -7,13 +7,14 @@ import { type OpenResult, type ReadResult, type Root, type RootReadOptions } fro
7
7
  export type FileStoreOptions = {
8
8
  rootDir: string;
9
9
  private?: boolean;
10
+ allowDrvfsRenameRecovery?: boolean;
10
11
  /** Default for writes, streams, and copies; true syncs file and parent where supported. */
11
12
  durable?: boolean;
12
13
  dirMode?: DirectoryMode;
13
14
  mode?: number;
14
15
  maxBytes?: number;
15
16
  };
16
- export type FileStoreWriteOptions = Partial<Pick<FileStoreOptions, "dirMode" | "mode" | "maxBytes"> & {
17
+ export type FileStoreWriteOptions = Partial<Pick<FileStoreOptions, "dirMode" | "mode" | "maxBytes" | "allowDrvfsRenameRecovery"> & {
17
18
  /** Override store durability; defaults to the store option, then true. */
18
19
  durable: boolean;
19
20
  tempPrefix: string;
@@ -1,3 +1,4 @@
1
+ import { snapshotWriteOptions } from "./file-store-write-options.js";
1
2
  import syncFs from "node:fs";
2
3
  import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
3
4
  import { normalizeMaxBytes } from "./byte-budget.js";
@@ -15,21 +16,6 @@ import { DEFAULT_ROOT_MAX_BYTES } from "./root-impl.js";
15
16
  import { matchRootFileOpenFailure, openRootFileSync } from "./root-file.js";
16
17
  import { writeSecretFileAtomic } from "./secret-file.js";
17
18
  import { assertNoWindowsPathAlias, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
18
- function snapshotWriteOptions(options, durabilityFirst = true) {
19
- if (options == null)
20
- return undefined;
21
- return durabilityFirst ? {
22
- maxBytes: options.maxBytes,
23
- durable: options.durable,
24
- dirMode: options.dirMode,
25
- mode: options.mode,
26
- } : {
27
- maxBytes: options.maxBytes,
28
- dirMode: options.dirMode,
29
- mode: options.mode,
30
- durable: options.durable,
31
- };
32
- }
33
19
  function isNotFound(error) {
34
20
  return error instanceof FsSafeError ? error.code === "not-found" : isNotFoundPathError(error);
35
21
  }
@@ -72,6 +58,7 @@ async function copyIntoRoot(params) {
72
58
  await ensureParentInRoot(scopedRoot, relativePath, params.dirMode);
73
59
  await scopedRoot.copyIn(literalStoreRootPath(relativePath), params.sourcePath, {
74
60
  durable: params.durable,
61
+ allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
75
62
  maxBytes: params.maxBytes,
76
63
  mkdir: false,
77
64
  mode: params.mode,
@@ -84,6 +71,7 @@ export function fileStore(options) {
84
71
  const rootDir = resolvePathPreservingWindowsRoot(rootDirInput);
85
72
  assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
86
73
  const privateMode = options.private ?? false;
74
+ const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery;
87
75
  const dirMode = options.dirMode ?? 0o700;
88
76
  if (privateMode)
89
77
  rejectPrivateDirectoryPreservation(dirMode);
@@ -103,6 +91,7 @@ export function fileStore(options) {
103
91
  rootDir,
104
92
  filePath: destination,
105
93
  content,
94
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
106
95
  durable: writeOptions?.durable ?? durable,
107
96
  dirMode: writeOptions?.dirMode ?? dirMode,
108
97
  mode: writeOptions?.mode ?? mode,
@@ -122,6 +111,7 @@ export function fileStore(options) {
122
111
  mkdir: false,
123
112
  mode: writeMode,
124
113
  durable: writeDurable,
114
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
125
115
  });
126
116
  return destination;
127
117
  }
@@ -151,6 +141,7 @@ export function fileStore(options) {
151
141
  filePath: destination,
152
142
  content: Buffer.concat(chunks),
153
143
  durable: writeDurable,
144
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
154
145
  dirMode: writeDirMode,
155
146
  mode: writeMode,
156
147
  });
@@ -170,6 +161,7 @@ export function fileStore(options) {
170
161
  relativePath,
171
162
  sourcePath: staged.path,
172
163
  durable: writeDurable,
164
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
173
165
  maxBytes: limit,
174
166
  mode: writeMode,
175
167
  tempPrefix: writeOptions?.tempPrefix,
@@ -187,6 +179,7 @@ export function fileStore(options) {
187
179
  const policy = writeOptions == null
188
180
  ? undefined
189
181
  : {
182
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery,
190
183
  maxBytes: configuredLimit,
191
184
  durable: writeOptions?.durable,
192
185
  dirMode: writeOptions?.dirMode,
@@ -203,6 +196,7 @@ export function fileStore(options) {
203
196
  relativePath,
204
197
  sourcePath,
205
198
  durable: writeOptions?.durable ?? durable,
199
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
206
200
  dirMode: writeOptions?.dirMode ?? dirMode,
207
201
  maxBytes: configuredLimit,
208
202
  mode: writeOptions?.mode ?? mode,
@@ -276,7 +270,7 @@ export function fileStore(options) {
276
270
  readRequired: async () => await (await openRoot()).readJson(literalStoreRootPath(relativePath)),
277
271
  write: async (value, options) => {
278
272
  const json = stringifyJsonDocument(value, null, 2);
279
- await write(relativePath, options?.trailingNewline === false ? json : `${json}\n`, { durable: options?.durable });
273
+ await write(relativePath, options?.trailingNewline === false ? json : `${json}\n`, { durable: options?.durable, allowDrvfsRenameRecovery: options?.allowDrvfsRenameRecovery });
280
274
  },
281
275
  }, jsonOptions);
282
276
  },
@@ -291,6 +285,7 @@ export function fileStoreSync(options) {
291
285
  const rootDir = resolvePathPreservingWindowsRoot(rootDirInput);
292
286
  assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
293
287
  const privateMode = options.private ?? false;
288
+ const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery;
294
289
  const dirMode = options.dirMode ?? 0o700;
295
290
  if (privateMode)
296
291
  rejectPrivateDirectoryPreservation(dirMode);
@@ -307,6 +302,7 @@ export function fileStoreSync(options) {
307
302
  filePath: destination,
308
303
  content,
309
304
  privateMode,
305
+ allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
310
306
  durable: writeOptions?.durable ?? durable,
311
307
  dirMode: writeOptions?.dirMode ?? dirMode,
312
308
  mode: writeOptions?.mode ?? mode,
@@ -5,7 +5,7 @@ export const GUEST_FILESYSTEM_CREATE_STAGING_PYTHON = [
5
5
  " # also rewrite the destination immediately after publication.",
6
6
  " prefix = '.openclaw-create-'",
7
7
  " for _ in range(128):",
8
- " candidate = prefix + secrets.token_hex(6)",
8
+ " candidate = prefix + os.urandom(6).hex()",
9
9
  " try:",
10
10
  " os.mkdir(candidate, 0o700, dir_fd=parent_fd)",
11
11
  " except FileExistsError:",
@@ -13,7 +13,6 @@ export const GUEST_FILESYSTEM_PYTHON = [
13
13
  "import errno",
14
14
  "import json",
15
15
  "import os",
16
- "import secrets",
17
16
  "import stat",
18
17
  "import sys",
19
18
  "",
@@ -72,7 +71,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
72
71
  "def create_temp_file(parent_fd):",
73
72
  " prefix = '.openclaw-write-'",
74
73
  " for _ in range(128):",
75
- " candidate = prefix + secrets.token_hex(6)",
74
+ " candidate = prefix + os.urandom(6).hex()",
76
75
  " try:",
77
76
  " fd = os.open(candidate, WRITE_FLAGS, 0o600, dir_fd=parent_fd)",
78
77
  " return candidate, fd",
@@ -83,7 +82,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
83
82
  "def create_temp_dir(parent_fd, mode):",
84
83
  " prefix = '.openclaw-move-'",
85
84
  " for _ in range(128):",
86
- " candidate = prefix + secrets.token_hex(6)",
85
+ " candidate = prefix + os.urandom(6).hex()",
87
86
  " try:",
88
87
  " os.mkdir(candidate, mode, dir_fd=parent_fd)",
89
88
  " return candidate",
@@ -152,7 +151,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
152
151
  " temp_name = None",
153
152
  " try:",
154
153
  " for _ in range(128):",
155
- " candidate = prefix + secrets.token_hex(6)",
154
+ " candidate = prefix + os.urandom(6).hex()",
156
155
  " try:",
157
156
  " copy_regular_file(src_parent_fd, src_basename, dst_parent_fd, candidate)",
158
157
  " temp_name = candidate",
@@ -4,6 +4,7 @@ export type JsonStoreLockOptions = Partial<FsSafeLockConfig & {
4
4
  managerKey: string;
5
5
  }>;
6
6
  export type JsonFileStoreOptions = {
7
+ allowDrvfsRenameRecovery?: boolean;
7
8
  /** Overrides the parent store's durability for every JSON mutation. */
8
9
  durable?: boolean;
9
10
  trailingNewline?: boolean;
@@ -27,6 +28,7 @@ export type JsonStoreAdapter<T> = {
27
28
  write(value: T, options?: {
28
29
  trailingNewline?: boolean;
29
30
  durable?: boolean;
31
+ allowDrvfsRenameRecovery?: boolean;
30
32
  }): Promise<void>;
31
33
  };
32
34
  export declare function createJsonStore<T>(adapter: JsonStoreAdapter<T>, options?: JsonFileStoreOptions): JsonStore<T>;
@@ -39,6 +39,7 @@ export function createJsonStore(adapter, options = {}) {
39
39
  return {
40
40
  trailingNewline: options.trailingNewline ?? true,
41
41
  durable: options.durable,
42
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
42
43
  };
43
44
  }
44
45
  async function withSerializedMutation(run) {
@@ -9,6 +9,7 @@ export function jsonStore(options) {
9
9
  return fileStore({
10
10
  rootDir: path.dirname(filePath),
11
11
  private: true,
12
+ allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
12
13
  mode: options.mode,
13
14
  dirMode: options.dirMode,
14
15
  }).json(path.basename(filePath), options);
@@ -5,7 +5,10 @@ export type ReadJsonOptions = {
5
5
  maxBytes?: number;
6
6
  };
7
7
  export declare function tryReadJsonSync<T = unknown>(pathname: string, options?: ReadJsonOptions): T | null;
8
- export declare function writeJsonSync(pathname: string, data: unknown): void;
8
+ export type WriteJsonSyncOptions = {
9
+ allowDrvfsRenameRecovery?: boolean;
10
+ };
11
+ export declare function writeJsonSync(pathname: string, data: unknown, options?: WriteJsonSyncOptions): void;
9
12
  export declare class JsonFileReadError extends Error {
10
13
  readonly filePath: string;
11
14
  readonly reason: "read" | "parse";
@@ -45,5 +48,5 @@ export declare function tryReadJson<T>(filePath: string, options?: ReadJsonOptio
45
48
  export declare function readJson<T>(filePath: string, options?: ReadJsonOptions): Promise<T>;
46
49
  export declare function readJsonIfExists<T>(filePath: string, options?: ReadJsonOptions): Promise<T | null>;
47
50
  export declare function readJsonSync<T = unknown>(filePath: string, options?: ReadJsonOptions): T;
48
- export type WriteJsonOptions = Pick<WriteTextAtomicOptions, "dirMode" | "durable" | "mode" | "trailingNewline">;
51
+ export type WriteJsonOptions = Pick<WriteTextAtomicOptions, "dirMode" | "durable" | "mode" | "trailingNewline" | "allowDrvfsRenameRecovery">;
49
52
  export declare function writeJson(filePath: string, value: unknown, options?: WriteJsonOptions): Promise<void>;
@@ -88,7 +88,8 @@ export function tryReadJsonSync(pathname, options = {}) {
88
88
  return null;
89
89
  }
90
90
  }
91
- export function writeJsonSync(pathname, data) {
91
+ export function writeJsonSync(pathname, data, options) {
92
+ const allowDrvfsRenameRecovery = options?.allowDrvfsRenameRecovery === true;
92
93
  const filePath = admitStandalonePublicationPath(pathname);
93
94
  // Keep literal parent segments so staging follows the same symlinks as the target.
94
95
  const tmpPath = path.format({ ...path.parse(filePath), base: `.fs-safe-${randomUUID()}.tmp` });
@@ -107,10 +108,12 @@ export function writeJsonSync(pathname, data) {
107
108
  runSync(owner.assertCurrent());
108
109
  trySetSecureMode(temp.file.fd);
109
110
  fsSync.fsyncSync(temp.file.fd);
111
+ if (allowDrvfsRenameRecovery)
112
+ runSync(owner.prepareRecovery(payload, path.dirname(filePath)));
110
113
  renameJsonFileWithFallback(owner, filePath);
111
114
  owner.markRenamed();
112
115
  runSync(owner.assertPublished(filePath));
113
- trySetSecureMode(temp.file.fd);
116
+ trySetSecureMode(owner.fd);
114
117
  runSync(syncDirectoryBestEffort(io, path.dirname(filePath)));
115
118
  runSync(owner.assertPublished(filePath));
116
119
  }
@@ -300,6 +303,7 @@ export async function writeJson(filePath, value, options) {
300
303
  mode: options?.mode,
301
304
  dirMode: options?.dirMode,
302
305
  trailingNewline: options?.trailingNewline,
306
+ allowDrvfsRenameRecovery: options?.allowDrvfsRenameRecovery,
303
307
  durable: options?.durable,
304
308
  });
305
309
  }
@@ -6,7 +6,7 @@ import { recordFileOpenFailure, recordPreOpenFileChange } from "./opened-file-fa
6
6
  import { assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isSymlinkOpenError, } from "./path.js";
7
7
  import { resolveReadOpenFlags } from "./read-open-flags.js";
8
8
  import { fileNotFoundError, hardlinkedPathNotAllowedError } from "./root-errors.js";
9
- import { inspectFileIdentitySync } from "./strict-file-identity.js";
9
+ import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
10
10
  import { getFsSafeTestHooks } from "./test-hooks.js";
11
11
  const OPEN_READ_FLAGS = resolveReadOpenFlags();
12
12
  const OPEN_READ_FOLLOW_FLAGS = resolveReadOpenFlags({ followSymlinks: true });
@@ -20,8 +20,7 @@ export async function openLocalFileDescriptor(filePath, options) {
20
20
  // Reject directories before opening so we never surface EISDIR to callers (e.g. tool
21
21
  // results that get sent to messaging channels). See openclaw/openclaw#31186.
22
22
  try {
23
- preOpenStat = inspectFileIdentitySync(() => {
24
- const stat = fsSync.lstatSync(filePath, { bigint: true });
23
+ const inspect = (stat) => {
25
24
  observedBeforeOpen = true;
26
25
  if (stat.isSymbolicLink() && options?.symlinks !== "follow-within-root") {
27
26
  throw new FsSafeError("symlink", "symlink not allowed");
@@ -30,7 +29,10 @@ export async function openLocalFileDescriptor(filePath, options) {
30
29
  throw new FsSafeError("not-file", "not a file");
31
30
  }
32
31
  return stat;
33
- });
32
+ };
33
+ preOpenStat = process.platform === "win32"
34
+ ? inspectFileIdentitySync(() => inspect(fsSync.lstatSync(filePath, { bigint: true })))
35
+ : await inspectFileIdentity(async () => inspect(await fs.lstat(filePath, { bigint: true })));
34
36
  }
35
37
  catch (err) {
36
38
  if (err instanceof FsSafeError || observedBeforeOpen) {
@@ -67,15 +69,19 @@ export async function openLocalFileDescriptor(filePath, options) {
67
69
  let openedIdentity;
68
70
  let identity;
69
71
  try {
70
- identity = inspectFileIdentitySync(() => {
71
- openedIdentity = fsSync.fstatSync(handle.fd, { bigint: true });
72
- if (!openedIdentity.isFile())
72
+ const inspect = (stat) => {
73
+ openedIdentity = stat;
74
+ if (!stat.isFile())
73
75
  throw new FsSafeError("not-file", "not a file");
74
- return openedIdentity;
75
- }, preOpenStat && !preOpenStat.isSymbolicLink() ? preOpenStat : undefined);
76
+ return stat;
77
+ };
78
+ const expected = preOpenStat && !preOpenStat.isSymbolicLink() ? preOpenStat : undefined;
79
+ identity = process.platform === "win32"
80
+ ? inspectFileIdentitySync(() => inspect(fsSync.fstatSync(handle.fd, { bigint: true })), expected)
81
+ : await inspectFileIdentity(async () => inspect(await handle.stat({ bigint: true })), expected);
76
82
  }
77
83
  catch (error) {
78
- if (openedIdentity && [0n, 1n].includes(openedIdentity.nlink)) {
84
+ if (openedIdentity && [0n, 1n, 2n].includes(openedIdentity.nlink)) {
79
85
  await recordPreOpenFileChange(error, handle, filePath, preOpenStat, openedIdentity);
80
86
  }
81
87
  throw error;
@@ -219,6 +219,10 @@ export interface NativeBinding {
219
219
  path?: string;
220
220
  errno?: number;
221
221
  };
222
+ canonicalizePathAsync?(path: string, ordinary: boolean): Promise<{
223
+ path?: string;
224
+ errno?: number;
225
+ }>;
222
226
  /** Internal Windows normalized name resolution after a denied DOS-name query. */
223
227
  resolveWindowsCanonicalPath?(path: string): string | null;
224
228
  /** Internal immutable primary-token membership, cached across Workers. */
@@ -305,6 +309,8 @@ export interface NativeBinding {
305
309
  /** Local filesystem admission for one-way cooperative entry publication. */
306
310
  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;
307
311
  entryPublicationFilesystem?(parentFd: number): string;
312
+ /** Internal negative-only DrvFS preparation probe; never grants recovery. */
313
+ is9pFilesystem?(parentFd: number): boolean;
308
314
  publishRetainedEntryNoReplace?(sourceParentFd: number, sourceBasename: string, sourceFd: number, targetParentFd: number, targetBasename: string): NativePublicationTransition;
309
315
  renameNoReplace?(...args: NativeTwoPathArgs): void;
310
316
  /** Linux auto-mode fallback through already-admitted direct-child parents. */
@@ -60,6 +60,7 @@ import { assertNativeCapabilities, getNativeBinding } from "./native.js";
60
60
  import { captureNativeFdClose } from "./native-binding.js";
61
61
  import { cachedNoReplaceUnavailable } from "./native-noreplace.js";
62
62
  import { isFsSafeNativeRequired } from "./native-config.js";
63
+ import { writeSidecarAtParent } from "./sidecar-lock-write.js";
63
64
  import { copyLinkAtParent } from "./copy-link.js";
64
65
  const writeCapabilities = ["openBeneath", "mkdirBeneath", "renameNoReplace", "renameReplace"];
65
66
  const posixWriteCapabilities = [...writeCapabilities, "createStagedFile", "stagedFileMatches", "removeStagedFile", "renameReplaceAsync", "renameNoReplaceAsync"];
@@ -142,6 +143,9 @@ export async function runPinnedWriteNative(binding, params, fallback) {
142
143
  }
143
144
  }
144
145
  }
146
+ if (params.input.kind === "buffer" && params.input.sidecar) {
147
+ return await writeSidecarAtParent(params, verificationGuard, { fd: parentFd, binding });
148
+ }
145
149
  if (windows) {
146
150
  // The Windows leaf owns both directories after admission.
147
151
  windowsOwnsDirectories = true;
@@ -1,3 +1,23 @@
1
+ import type { StagedFileReceipt } from "./staged-file-types.js";
1
2
  import type { NativeBinding } from "./native-binding.js";
2
3
  /** Exact nonprivate stage facts from one fresh named/retained observation. */
3
4
  export declare function nativeStagedFileMode(binding: NativeBinding, parentFd: number, name: string, fd: number, expectedMode?: number): number | undefined;
5
+ export type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile" | "renameReplaceAsync" | "renameNoReplaceAsync">>;
6
+ export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
7
+ export declare function assertStagedFileBasename(name: string, portable: boolean): void;
8
+ type StagedPermissionPolicy = "private-creation" | "mode-only";
9
+ export type NativeStageOwner = Readonly<{
10
+ binding: NativeStagingBinding;
11
+ parentFd: number;
12
+ closeParentFd: (fd: number) => void;
13
+ directory: StagedFileReceipt["directory"];
14
+ portableNames?: boolean;
15
+ mode: number;
16
+ sync?: boolean;
17
+ allowDrvfsRenameRecovery?: boolean;
18
+ strictFileSync?: boolean;
19
+ assertBeforeMutation?: () => void;
20
+ permissionPolicy?: StagedPermissionPolicy;
21
+ name?: string;
22
+ }>;
23
+ export {};
@@ -14,3 +14,21 @@ export function nativeStagedFileMode(binding, parentFd, name, fd, expectedMode)
14
14
  }
15
15
  return mode;
16
16
  }
17
+ export function assertNativeStaging(binding) {
18
+ if ([
19
+ binding.closeOwnedFd,
20
+ binding.createStagedFile,
21
+ binding.stagedFileMatches,
22
+ binding.removeStagedFile,
23
+ binding.renameReplaceAsync,
24
+ binding.renameNoReplaceAsync,
25
+ ].some((fn) => typeof fn !== "function")) {
26
+ throw new FsSafeError("helper-unavailable", "native retained-directory staging is unavailable");
27
+ }
28
+ }
29
+ export function assertStagedFileBasename(name, portable) {
30
+ if (!name || name === "." || name === ".." || name.includes("/") || name.includes("\0") ||
31
+ (portable && /[\\:\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(name))) {
32
+ throw new FsSafeError("invalid-path", "publication requires one direct-child basename");
33
+ }
34
+ }
@@ -2,25 +2,10 @@ import type { DirectoryReceipt } from "./directory-durability.js";
2
2
  import { type BigIntStats, type Stats } from "node:fs";
3
3
  import type { AnyAsyncDirectoryGuard } from "./directory-guard.js";
4
4
  import type { FileIdentityStat } from "./file-identity.js";
5
- import { type NativeBinding } from "./native-binding.js";
5
+ import { type NativeStagingBinding, type NativeStageOwner } from "./native-staged-file-metadata.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" | "renameReplaceAsync" | "renameNoReplaceAsync">>;
9
- export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
10
- type StagedPermissionPolicy = "private-creation" | "mode-only";
11
- type NativeStageOwner = Readonly<{
12
- binding: NativeStagingBinding;
13
- parentFd: number;
14
- closeParentFd: (fd: number) => void;
15
- directory: StagedFileReceipt["directory"];
16
- portableNames?: boolean;
17
- mode: number;
18
- sync?: boolean;
19
- strictFileSync?: boolean;
20
- assertBeforeMutation?: () => void;
21
- permissionPolicy?: StagedPermissionPolicy;
22
- name?: string;
23
- }>;
8
+ export { assertNativeStaging, type NativeStagingBinding } from "./native-staged-file-metadata.js";
24
9
  declare class NativeStagedFile implements StagedFile {
25
10
  #private;
26
11
  constructor(owner: NativeStageOwner);
@@ -39,7 +24,7 @@ export declare const writeNativeStage: typeof NativeStagedFile.write;
39
24
  export declare function stageFileInDirectory(options: {
40
25
  directory: string | DirectoryReceipt<Stats | BigIntStats>;
41
26
  content: string | Uint8Array;
27
+ allowDrvfsRenameRecovery?: boolean;
42
28
  /** Published mode; the unpublished stage stays at 0600. Defaults to 0600. */
43
29
  mode?: number;
44
30
  }): Promise<StagedFile>;
45
- export {};